repo stringlengths 5 67 | sha stringlengths 40 40 | path stringlengths 4 234 | url stringlengths 85 339 | language stringclasses 6 values | split stringclasses 3 values | doc stringlengths 3 51.2k | sign stringlengths 5 8.01k | problem stringlengths 13 51.2k | output stringlengths 0 3.87M |
|---|---|---|---|---|---|---|---|---|---|
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/iptables.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L103-L122 | go | train | // execute generates the list of iptRules for this iptTemplateExecuter. | func (te *iptTemplateExecuter) execute() ([]*iptRule, error) | // execute generates the list of iptRules for this iptTemplateExecuter.
func (te *iptTemplateExecuter) execute() ([]*iptRule, error) | {
rules := make([]*iptRule, 0, len(te.templates))
for _, t := range te.templates {
w := new(bytes.Buffer)
if err := t.Template.Execute(w, te.data); err != nil {
return nil, err
}
af := seesaw.IPv6
if te.data.ServiceVIP.To4() != nil {
af = seesaw.IPv4
}
rule := &iptRule{
af,
t.action,
w.String(),
}
rules = append(rules, rule)
}
return rules, nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/iptables.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L132-L162 | go | train | // initIPTRuleTemplates initialises the iptRuleTemplates. | func initIPTRuleTemplates() | // initIPTRuleTemplates initialises the iptRuleTemplates.
func initIPTRuleTemplates() | {
// Allow traffic for VIP services.
svcRules = append(svcRules, newIPTRuleTemplate(iptAppend,
"INPUT -p {{.Proto}} -d {{.ServiceVIP}}{{with .Port}} --dport {{.}}{{end}} -j ACCEPT"))
// Mark packets for firemark based VIPs.
fwmRule := "PREROUTING -t mangle -p {{.Proto}} -d {{.ServiceVIP}}" +
"{{with .Port}} --dport {{.}}{{end}} -j MARK --set-mark {{.FWM}}"
fwmRules = append(fwmRules, newIPTRuleTemplate(iptAppend, fwmRule))
// Enable conntrack for NAT connections.
natConntrack := "PREROUTING -t raw -p {{.Proto}} -d {{.ServiceVIP}}" +
"{{with .Port}} --dport {{.}}{{end}} -j ACCEPT"
natRules = append(natRules, newIPTRuleTemplate(iptInsert, natConntrack))
// Rewrite source address for NAT'd packets so backend reply traffic comes
// back to the load balancer.
natPostrouting := "POSTROUTING -t nat -m ipvs -p {{.Proto}}{{with .Port}} --vport {{.}}{{end}} " +
"--vaddr {{.ServiceVIP}} -j SNAT --to-source {{.ClusterVIP}} --random"
natRules = append(natRules, newIPTRuleTemplate(iptAppend, natPostrouting))
// Allow ICMP traffic to this VIP.
vipRulesEnd = append(vipRulesEnd, newIPTRuleTemplate(iptAppend,
"INPUT -p icmp -d {{.ServiceVIP}} -j ACCEPT"))
vipRulesEnd = append(vipRulesEnd, newIPTRuleTemplate(iptAppend,
"INPUT -p ipv6-icmp -d {{.ServiceVIP}} -j ACCEPT"))
// Block all other traffic to this VIP.
vipRulesEnd = append(vipRulesEnd, newIPTRuleTemplate(iptAppend,
"INPUT -d {{.ServiceVIP}} -j REJECT"))
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/iptables.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L166-L207 | go | train | // iptablesRunOutput runs the Linux ip(6?)tables command with the specified
// arguments and returns the output. | func iptablesRunOutput(af seesaw.AF, argsStr string) (string, error) | // iptablesRunOutput runs the Linux ip(6?)tables command with the specified
// arguments and returns the output.
func iptablesRunOutput(af seesaw.AF, argsStr string) (string, error) | {
var cmd string
switch af {
case seesaw.IPv4:
cmd = ipt4Cmd
case seesaw.IPv6:
cmd = ipt6Cmd
default:
return "", fmt.Errorf("iptablesRunOutput: Unsupported address family: %v", af)
}
var out []byte
var err error
log.Infof("%s %s", cmd, argsStr)
args := strings.Split(argsStr, " ")
failed := false
for tries := 1; !failed && tries <= iptMaxTries; tries++ {
proc := exec.Command(cmd, args...)
iptMutex.Lock()
out, err = proc.Output()
iptMutex.Unlock()
if err == nil {
break
}
// If someone else is running iptables, our command will fail with a
// resource error, so retry. Also retry if we can't determine the exit
// status at all.
switch status := proc.ProcessState.Sys().(type) {
case syscall.WaitStatus:
if status.ExitStatus() != iptResourceError {
failed = true
}
}
log.Infof("'%s %s' try %d of %d failed: %v (%v)", cmd, argsStr, tries, iptMaxTries, err, out)
}
if err != nil {
msg := fmt.Sprintf("iptablesRunOutput: '%s %s': %v", cmd, argsStr, err)
log.Infof(msg)
return "", fmt.Errorf(msg)
}
return string(out), nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/iptables.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L210-L213 | go | train | // iptablesRun runs the Linux ip(6?)tables command with the specified arguments. | func iptablesRun(af seesaw.AF, argsStr string) error | // iptablesRun runs the Linux ip(6?)tables command with the specified arguments.
func iptablesRun(af seesaw.AF, argsStr string) error | {
_, err := iptablesRunOutput(af, argsStr)
return err
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/iptables.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L216-L239 | go | train | // iptablesInit initialises the iptables rules for a Seesaw Node. | func iptablesInit(clusterVIP seesaw.Host) error | // iptablesInit initialises the iptables rules for a Seesaw Node.
func iptablesInit(clusterVIP seesaw.Host) error | {
if err := iptablesFlush(); err != nil {
return err
}
for _, af := range seesaw.AFs() {
// Allow connections to port 10257 for all VIPs.
if err := iptablesRun(af, "-I INPUT -p tcp --dport 10257 -j ACCEPT"); err != nil {
return err
}
// conntrack is only required for NAT. Disable it for everything else.
if err := iptablesRun(af, "-t raw -A PREROUTING -j NOTRACK"); err != nil {
return err
}
if err := iptablesRun(af, "-t raw -A OUTPUT -j NOTRACK"); err != nil {
return err
}
}
// Enable conntrack for incoming traffic on the seesaw cluster IPv4 VIP. This
// is required for NAT return traffic.
return iptablesRun(seesaw.IPv4,
fmt.Sprintf("-t raw -I PREROUTING -d %v/32 -j ACCEPT", clusterVIP.IPv4Addr))
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/iptables.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L242-L256 | go | train | // iptablesFlush removes all IPv4 and IPv6 iptables rules. | func iptablesFlush() error | // iptablesFlush removes all IPv4 and IPv6 iptables rules.
func iptablesFlush() error | {
for _, af := range seesaw.AFs() {
for _, table := range []string{"filter", "mangle", "raw"} {
if err := iptablesRun(af, fmt.Sprintf("--flush -t %v", table)); err != nil {
return err
}
}
}
// NAT is IPv4-only until linux kernel version 3.7.
// TODO(angusc): Support IPv6 NAT.
if err := iptablesRun(seesaw.IPv4, "--flush -t nat"); err != nil {
return err
}
return nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/iptables.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L259-L313 | go | train | // iptablesRules returns the list of iptRules for a Vserver. | func iptablesRules(v *seesaw.Vserver, clusterVIP seesaw.Host, af seesaw.AF) ([]*iptRule, error) | // iptablesRules returns the list of iptRules for a Vserver.
func iptablesRules(v *seesaw.Vserver, clusterVIP seesaw.Host, af seesaw.AF) ([]*iptRule, error) | {
var clusterIP, serviceIP net.IP
switch af {
case seesaw.IPv4:
clusterIP = clusterVIP.IPv4Addr
serviceIP = v.IPv4Addr
case seesaw.IPv6:
clusterIP = clusterVIP.IPv6Addr
serviceIP = v.IPv6Addr
}
if clusterIP == nil {
return nil, fmt.Errorf("Seesaw Cluster VIP does not have an %s address", af)
}
if serviceIP == nil {
return nil, fmt.Errorf("Service VIP does not have an %s address", af)
}
executers := make([]*iptTemplateExecuter, 0)
vipData := &iptTemplateData{
ClusterVIP: clusterIP,
ServiceVIP: serviceIP,
}
executers = append(executers, &iptTemplateExecuter{vipRulesBegin, vipData})
for _, ve := range v.Entries {
svcData := &iptTemplateData{
ClusterVIP: clusterIP,
ServiceVIP: serviceIP,
FWM: v.FWM[af],
Port: ve.Port,
Proto: ve.Proto,
}
executers = append(executers, newIPTTemplateExecuter(svcRules, svcData))
if v.FWM[af] > 0 {
executers = append(executers, newIPTTemplateExecuter(fwmRules, svcData))
}
if ve.Mode == seesaw.LBModeNAT {
executers = append(executers, newIPTTemplateExecuter(natRules, svcData))
}
}
executers = append(executers, &iptTemplateExecuter{vipRulesEnd, vipData})
allRules := make([]*iptRule, 0)
for _, ex := range executers {
rules, err := ex.execute()
if err != nil {
return nil, err
}
allRules = append(allRules, rules...)
}
return allRules, nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/iptables.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/iptables.go#L317-L328 | go | train | // iptablesAddRules installs the iptables rules for a given Vserver and Seesaw
// Cluster VIP. | func iptablesAddRules(v *seesaw.Vserver, clusterVIP seesaw.Host, af seesaw.AF) error | // iptablesAddRules installs the iptables rules for a given Vserver and Seesaw
// Cluster VIP.
func iptablesAddRules(v *seesaw.Vserver, clusterVIP seesaw.Host, af seesaw.AF) error | {
rules, err := iptablesRules(v, clusterVIP, af)
if err != nil {
return err
}
for _, r := range rules {
if err := iptablesRun(r.AF, string(r.action)+" "+r.rule); err != nil {
return err
}
}
return nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L34-L43 | go | train | // initIPVS initialises the IPVS sub-component. | func initIPVS() | // initIPVS initialises the IPVS sub-component.
func initIPVS() | {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
log.Infof("Initialising IPVS...")
if err := ipvs.Init(); err != nil {
// TODO(jsing): modprobe ip_vs and try again.
log.Fatalf("IPVS initialisation failed: %v", err)
}
log.Infof("IPVS version %s", ipvs.Version())
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L46-L50 | go | train | // IPVSFlush flushes all services and destinations from the IPVS table. | func (ncc *SeesawNCC) IPVSFlush(in int, out *int) error | // IPVSFlush flushes all services and destinations from the IPVS table.
func (ncc *SeesawNCC) IPVSFlush(in int, out *int) error | {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.Flush()
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L53-L65 | go | train | // IPVSGetServices gets the currently configured services from the IPVS table. | func (ncc *SeesawNCC) IPVSGetServices(in int, s *ncctypes.IPVSServices) error | // IPVSGetServices gets the currently configured services from the IPVS table.
func (ncc *SeesawNCC) IPVSGetServices(in int, s *ncctypes.IPVSServices) error | {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
svcs, err := ipvs.GetServices()
if err != nil {
return err
}
s.Services = nil
for _, svc := range svcs {
s.Services = append(s.Services, svc)
}
return nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L69-L78 | go | train | // IPVSGetService gets the currently configured service from the IPVS table,
// which matches the specified service. | func (ncc *SeesawNCC) IPVSGetService(si *ipvs.Service, s *ncctypes.IPVSServices) error | // IPVSGetService gets the currently configured service from the IPVS table,
// which matches the specified service.
func (ncc *SeesawNCC) IPVSGetService(si *ipvs.Service, s *ncctypes.IPVSServices) error | {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
so, err := ipvs.GetService(si)
if err != nil {
return err
}
s.Services = []*ipvs.Service{so}
return nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L81-L85 | go | train | // IPVSAddService adds the specified service to the IPVS table. | func (ncc *SeesawNCC) IPVSAddService(svc *ipvs.Service, out *int) error | // IPVSAddService adds the specified service to the IPVS table.
func (ncc *SeesawNCC) IPVSAddService(svc *ipvs.Service, out *int) error | {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.AddService(*svc)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L88-L92 | go | train | // IPVSUpdateService updates the specified service in the IPVS table. | func (ncc *SeesawNCC) IPVSUpdateService(svc *ipvs.Service, out *int) error | // IPVSUpdateService updates the specified service in the IPVS table.
func (ncc *SeesawNCC) IPVSUpdateService(svc *ipvs.Service, out *int) error | {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.UpdateService(*svc)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L95-L99 | go | train | // IPVSDeleteService deletes the specified service from the IPVS table. | func (ncc *SeesawNCC) IPVSDeleteService(svc *ipvs.Service, out *int) error | // IPVSDeleteService deletes the specified service from the IPVS table.
func (ncc *SeesawNCC) IPVSDeleteService(svc *ipvs.Service, out *int) error | {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.DeleteService(*svc)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L102-L106 | go | train | // IPVSAddDestination adds the specified destination to the IPVS table. | func (ncc *SeesawNCC) IPVSAddDestination(dst *ncctypes.IPVSDestination, out *int) error | // IPVSAddDestination adds the specified destination to the IPVS table.
func (ncc *SeesawNCC) IPVSAddDestination(dst *ncctypes.IPVSDestination, out *int) error | {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.AddDestination(*dst.Service, *dst.Destination)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L109-L113 | go | train | // IPVSUpdateDestination updates the specified destination in the IPVS table. | func (ncc *SeesawNCC) IPVSUpdateDestination(dst *ncctypes.IPVSDestination, out *int) error | // IPVSUpdateDestination updates the specified destination in the IPVS table.
func (ncc *SeesawNCC) IPVSUpdateDestination(dst *ncctypes.IPVSDestination, out *int) error | {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.UpdateDestination(*dst.Service, *dst.Destination)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ncc/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ncc/ipvs.go#L116-L120 | go | train | // IPVSDeleteDestination deletes the specified destination from the IPVS table. | func (ncc *SeesawNCC) IPVSDeleteDestination(dst *ncctypes.IPVSDestination, out *int) error | // IPVSDeleteDestination deletes the specified destination from the IPVS table.
func (ncc *SeesawNCC) IPVSDeleteDestination(dst *ncctypes.IPVSDestination, out *int) error | {
ipvsMutex.Lock()
defer ipvsMutex.Unlock()
return ipvs.DeleteDestination(*dst.Service, *dst.Destination)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L38-L43 | go | train | // Copy deep copies from the given Seesaw Node. | func (n *Node) Copy(c *Node) | // Copy deep copies from the given Seesaw Node.
func (n *Node) Copy(c *Node) | {
n.State = c.State
n.Priority = c.Priority
n.Host.Copy(&c.Host)
n.VserversEnabled = c.VserversEnabled
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L46-L50 | go | train | // Clone creates an identical copy of the given Seesaw Node. | func (n *Node) Clone() *Node | // Clone creates an identical copy of the given Seesaw Node.
func (n *Node) Clone() *Node | {
var c Node
c.Copy(n)
return &c
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L75-L81 | go | train | // Copy deep copies from the given Seesaw Host. | func (h *Host) Copy(c *Host) | // Copy deep copies from the given Seesaw Host.
func (h *Host) Copy(c *Host) | {
h.Hostname = c.Hostname
h.IPv4Addr = copyIP(c.IPv4Addr)
h.IPv4Mask = copyIPMask(c.IPv4Mask)
h.IPv6Addr = copyIP(c.IPv6Addr)
h.IPv6Mask = copyIPMask(c.IPv6Mask)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L84-L88 | go | train | // Clone creates an identical copy of the given Seesaw Host. | func (h *Host) Clone() *Host | // Clone creates an identical copy of the given Seesaw Host.
func (h *Host) Clone() *Host | {
var c Host
c.Copy(h)
return &c
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L91-L93 | go | train | // Equal returns whether two hosts are equal. | func (h *Host) Equal(other *Host) bool | // Equal returns whether two hosts are equal.
func (h *Host) Equal(other *Host) bool | {
return reflect.DeepEqual(h, other)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L96-L98 | go | train | // IPv4Net returns a net.IPNet for the host's IPv4 address. | func (h *Host) IPv4Net() *net.IPNet | // IPv4Net returns a net.IPNet for the host's IPv4 address.
func (h *Host) IPv4Net() *net.IPNet | {
return &net.IPNet{IP: h.IPv4Addr, Mask: h.IPv4Mask}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L101-L103 | go | train | // IPv6Net returns a net.IPNet for the host's IPv6 address. | func (h *Host) IPv6Net() *net.IPNet | // IPv6Net returns a net.IPNet for the host's IPv6 address.
func (h *Host) IPv6Net() *net.IPNet | {
return &net.IPNet{IP: h.IPv6Addr, Mask: h.IPv6Mask}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L106-L111 | go | train | // IPv4Printable returns a printable representation of the host's IPv4 address. | func (h *Host) IPv4Printable() string | // IPv4Printable returns a printable representation of the host's IPv4 address.
func (h *Host) IPv4Printable() string | {
if h.IPv4Addr == nil {
return "<not configured>"
}
return h.IPv4Net().String()
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L114-L119 | go | train | // IPv6Printable returns a printable representation of the host's IPv4 address. | func (h *Host) IPv6Printable() string | // IPv6Printable returns a printable representation of the host's IPv4 address.
func (h *Host) IPv6Printable() string | {
if h.IPv6Addr == nil {
return "<not configured>"
}
return h.IPv6Net().String()
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L122-L127 | go | train | // Copy deep copies from the given Seesaw Backend. | func (b *Backend) Copy(c *Backend) | // Copy deep copies from the given Seesaw Backend.
func (b *Backend) Copy(c *Backend) | {
b.Enabled = c.Enabled
b.InService = c.InService
b.Weight = c.Weight
b.Host.Copy(&c.Host)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L130-L134 | go | train | // Clone creates an identical copy of the given Seesaw Backend. | func (b *Backend) Clone() *Backend | // Clone creates an identical copy of the given Seesaw Backend.
func (b *Backend) Clone() *Backend | {
var c Backend
c.Copy(b)
return &c
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L142-L148 | go | train | // Copy deep copies from the given Seesaw HAConfig. | func (h *HAConfig) Copy(c *HAConfig) | // Copy deep copies from the given Seesaw HAConfig.
func (h *HAConfig) Copy(c *HAConfig) | {
h.Enabled = c.Enabled
h.LocalAddr = copyIP(c.LocalAddr)
h.RemoteAddr = copyIP(c.RemoteAddr)
h.Priority = c.Priority
h.VRID = c.VRID
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L151-L155 | go | train | // Clone creates an identical copy of the given Seesaw HAConfig. | func (h *HAConfig) Clone() *HAConfig | // Clone creates an identical copy of the given Seesaw HAConfig.
func (h *HAConfig) Clone() *HAConfig | {
var c HAConfig
c.Copy(h)
return &c
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L158-L164 | go | train | // Equal reports whether this HAConfig is equal to the given HAConfig. | func (h *HAConfig) Equal(other *HAConfig) bool | // Equal reports whether this HAConfig is equal to the given HAConfig.
func (h *HAConfig) Equal(other *HAConfig) bool | {
return h.Enabled == other.Enabled &&
h.LocalAddr.Equal(other.LocalAddr) &&
h.RemoteAddr.Equal(other.RemoteAddr) &&
h.Priority == other.Priority &&
h.VRID == other.VRID
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L167-L170 | go | train | // String returns the string representation of an HAConfig. | func (h HAConfig) String() string | // String returns the string representation of an HAConfig.
func (h HAConfig) String() string | {
return fmt.Sprintf("Enabled: %v, LocalAddr: %v, RemoteAddr: %v, Priority: %d, VRID: %d",
h.Enabled, h.LocalAddr, h.RemoteAddr, h.Priority, h.VRID)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L173-L189 | go | train | // String returns the string representation of an HAState. | func (h HAState) String() string | // String returns the string representation of an HAState.
func (h HAState) String() string | {
switch h {
case HAUnknown:
return "Unknown"
case HABackup:
return "Backup"
case HADisabled:
return "Disabled"
case HAError:
return "Error"
case HAMaster:
return "Master"
case HAShutdown:
return "Shutdown"
}
return "(invalid)"
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L192-L195 | go | train | // Equal reports whether this VLAN is equal to the given VLAN. | func (v *VLAN) Equal(other *VLAN) bool | // Equal reports whether this VLAN is equal to the given VLAN.
func (v *VLAN) Equal(other *VLAN) bool | {
// Exclude backend and VIP counters from comparison.
return v.ID == other.ID && v.Host.Equal(&other.Host)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L203-L205 | go | train | // String returns the string representation of a VLAN. | func (v *VLAN) String() string | // String returns the string representation of a VLAN.
func (v *VLAN) String() string | {
return fmt.Sprintf("{ID=%d, Host=%s, IPv4=%s, IPv6=%s}", v.ID, v.Hostname, v.IPv4Printable(), v.IPv6Printable())
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L218-L220 | go | train | // String returns the string representation of a ServiceKey. | func (sk ServiceKey) String() string | // String returns the string representation of a ServiceKey.
func (sk ServiceKey) String() string | {
return fmt.Sprintf("%s %s %d", sk.AF, sk.Proto, sk.Port)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L244-L252 | go | train | // IP returns the destination IP address for a given address family. | func (d *Destination) IP(af AF) net.IP | // IP returns the destination IP address for a given address family.
func (d *Destination) IP(af AF) net.IP | {
switch af {
case IPv4:
return d.Backend.IPv4Addr
case IPv6:
return d.Backend.IPv6Addr
}
return nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L262-L264 | go | train | // copyIP creates a copy of an IP. | func copyIP(src net.IP) net.IP | // copyIP creates a copy of an IP.
func copyIP(src net.IP) net.IP | {
return net.IP(copyBytes(src))
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L267-L269 | go | train | // copyIPMask creates a copy of an IPMask. | func copyIPMask(src net.IPMask) net.IPMask | // copyIPMask creates a copy of an IPMask.
func copyIPMask(src net.IPMask) net.IPMask | {
return net.IPMask(copyBytes(src))
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L272-L279 | go | train | // copyBytes creates a copy of a byte slice. | func copyBytes(src []byte) []byte | // copyBytes creates a copy of a byte slice.
func copyBytes(src []byte) []byte | {
if src == nil {
return nil
}
dst := make([]byte, len(src))
copy(dst, src)
return dst
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L282-L284 | go | train | // IsAnycast reports whether an IP address is an anycast address. | func IsAnycast(ip net.IP) bool | // IsAnycast reports whether an IP address is an anycast address.
func IsAnycast(ip net.IP) bool | {
return netIPv4Anycast.Contains(ip) || netIPv6Anycast.Contains(ip)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/seesaw/util.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/seesaw/util.go#L287-L294 | go | train | // InSubnets reports whether an IP address is in one of a map of subnets. | func InSubnets(ip net.IP, subnets map[string]*net.IPNet) bool | // InSubnets reports whether an IP address is in one of a map of subnets.
func InSubnets(ip net.IP, subnets map[string]*net.IPNet) bool | {
for _, subnet := range subnets {
if subnet.Contains(ip) {
return true
}
}
return false
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L86-L117 | go | train | // NewEngine returns an initialised Engine struct. | func NewEngine(cfg *config.EngineConfig) *Engine | // NewEngine returns an initialised Engine struct.
func NewEngine(cfg *config.EngineConfig) *Engine | {
if cfg == nil {
defaultCfg := config.DefaultEngineConfig()
cfg = &defaultCfg
}
// TODO(jsing): Validate node, peer and cluster IP configuration.
engine := &Engine{
config: cfg,
fwmAlloc: newMarkAllocator(fwmAllocBase, fwmAllocSize),
ncc: ncclient.NewNCC(cfg.NCCSocket),
overrides: make(map[string]seesaw.Override),
overrideChan: make(chan seesaw.Override),
vlans: make(map[uint16]*seesaw.VLAN),
vservers: make(map[string]*vserver),
shutdown: make(chan bool),
shutdownARP: make(chan bool),
shutdownIPC: make(chan bool),
shutdownRPC: make(chan bool),
vserverSnapshots: make(map[string]*seesaw.Vserver),
vserverChan: make(chan *seesaw.Vserver, 1000),
}
engine.bgpManager = newBGPManager(engine, cfg.BGPUpdateInterval)
engine.haManager = newHAManager(engine, cfg.HAStateTimeout)
engine.hcManager = newHealthcheckManager(engine)
engine.syncClient = newSyncClient(engine)
engine.syncServer = newSyncServer(engine)
return engine
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L120-L144 | go | train | // Run starts the Engine. | func (e *Engine) Run() | // Run starts the Engine.
func (e *Engine) Run() | {
log.Infof("Seesaw Engine starting for %s", e.config.ClusterName)
e.initNetwork()
n, err := config.NewNotifier(e.config)
if err != nil {
log.Fatalf("config.NewNotifier() failed: %v", err)
}
e.notifier = n
if e.config.AnycastEnabled {
go e.bgpManager.run()
}
go e.hcManager.run()
go e.syncClient.run()
go e.syncServer.run()
go e.syncRPC()
go e.engineIPC()
go e.gratuitousARP()
e.manager()
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L152-L156 | go | train | // haStatus returns the current HA status from the engine. | func (e *Engine) haStatus() seesaw.HAStatus | // haStatus returns the current HA status from the engine.
func (e *Engine) haStatus() seesaw.HAStatus | {
e.haManager.statusLock.RLock()
defer e.haManager.statusLock.RUnlock()
return e.haManager.status
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L164-L166 | go | train | // setHAState tells the engine what its current HAState should be. | func (e *Engine) setHAState(state seesaw.HAState) | // setHAState tells the engine what its current HAState should be.
func (e *Engine) setHAState(state seesaw.HAState) | {
e.haManager.stateChan <- state
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L169-L171 | go | train | // setHAStatus tells the engine what the current HA status is. | func (e *Engine) setHAStatus(status seesaw.HAStatus) | // setHAStatus tells the engine what the current HA status is.
func (e *Engine) setHAStatus(status seesaw.HAStatus) | {
e.haManager.statusChan <- status
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L174-L187 | go | train | // haConfig returns the HAConfig for an engine. | func (e *Engine) haConfig() (*seesaw.HAConfig, error) | // haConfig returns the HAConfig for an engine.
func (e *Engine) haConfig() (*seesaw.HAConfig, error) | {
n, err := e.thisNode()
if err != nil {
return nil, err
}
// TODO(jsing): This does not allow for IPv6-only operation.
return &seesaw.HAConfig{
Enabled: n.State != seesaw.HADisabled,
LocalAddr: e.config.Node.IPv4Addr,
RemoteAddr: e.config.VRRPDestIP,
Priority: n.Priority,
VRID: e.config.VRID,
}, nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L190-L206 | go | train | // thisNode returns the Node for the machine on which this engine is running. | func (e *Engine) thisNode() (*seesaw.Node, error) | // thisNode returns the Node for the machine on which this engine is running.
func (e *Engine) thisNode() (*seesaw.Node, error) | {
e.clusterLock.RLock()
c := e.cluster
e.clusterLock.RUnlock()
if c == nil {
return nil, fmt.Errorf("cluster configuration not loaded")
}
// TODO(jsing): This does not allow for IPv6-only operation.
ip := e.config.Node.IPv4Addr
for _, n := range c.Nodes {
if ip.Equal(n.IPv4Addr) {
return n, nil
}
}
return nil, fmt.Errorf("node %v not configured", ip)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L209-L226 | go | train | // engineIPC starts an RPC server to handle IPC via a Unix Domain socket. | func (e *Engine) engineIPC() | // engineIPC starts an RPC server to handle IPC via a Unix Domain socket.
func (e *Engine) engineIPC() | {
if err := server.RemoveUnixSocket(e.config.SocketPath); err != nil {
log.Fatalf("Failed to remove socket: %v", err)
}
ln, err := net.Listen("unix", e.config.SocketPath)
if err != nil {
log.Fatalf("Listen failed: %v", err)
}
defer os.Remove(e.config.SocketPath)
seesawIPC := rpc.NewServer()
seesawIPC.Register(&SeesawEngine{e})
go server.RPCAccept(ln, seesawIPC)
<-e.shutdownIPC
ln.Close()
e.shutdownIPC <- true
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L229-L245 | go | train | // syncRPC starts a server to handle synchronisation RPCs via a TCP socket. | func (e *Engine) syncRPC() | // syncRPC starts a server to handle synchronisation RPCs via a TCP socket.
func (e *Engine) syncRPC() | {
// TODO(jsing): Make this default to IPv6, if configured.
addr := &net.TCPAddr{
IP: e.config.Node.IPv4Addr,
Port: e.config.SyncPort,
}
ln, err := net.ListenTCP("tcp", addr)
if err != nil {
log.Fatalf("Listen failed: %v", err)
}
go e.syncServer.serve(ln)
<-e.shutdownRPC
ln.Close()
e.shutdownRPC <- true
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L248-L280 | go | train | // initNetwork initialises the network configuration for load balancing. | func (e *Engine) initNetwork() | // initNetwork initialises the network configuration for load balancing.
func (e *Engine) initNetwork() | {
if err := e.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer e.ncc.Close()
if e.config.AnycastEnabled {
if err := e.ncc.BGPWithdrawAll(); err != nil {
log.Fatalf("Failed to withdraw all BGP advertisements: %v", err)
}
}
if err := e.ncc.IPVSFlush(); err != nil {
log.Fatalf("Failed to flush IPVS table: %v", err)
}
lbCfg := &ncctypes.LBConfig{
ClusterVIP: e.config.ClusterVIP,
DummyInterface: e.config.DummyInterface,
NodeInterface: e.config.NodeInterface,
Node: e.config.Node,
RoutingTableID: e.config.RoutingTableID,
VRID: e.config.VRID,
}
e.lbInterface = e.ncc.NewLBInterface(e.config.LBInterface, lbCfg)
if err := e.lbInterface.Init(); err != nil {
log.Fatalf("Failed to initialise LB interface: %v", err)
}
if e.config.AnycastEnabled {
e.initAnycast()
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L283-L309 | go | train | // initAnycast initialises the anycast configuration. | func (e *Engine) initAnycast() | // initAnycast initialises the anycast configuration.
func (e *Engine) initAnycast() | {
if err := e.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer e.ncc.Close()
vips := make([]*seesaw.VIP, 0)
if e.config.ClusterVIP.IPv4Addr != nil {
for _, ip := range e.config.ServiceAnycastIPv4 {
vips = append(vips, seesaw.NewVIP(ip, nil))
}
}
if e.config.ClusterVIP.IPv6Addr != nil {
for _, ip := range e.config.ServiceAnycastIPv6 {
vips = append(vips, seesaw.NewVIP(ip, nil))
}
}
for _, vip := range vips {
if err := e.lbInterface.AddVIP(vip); err != nil {
log.Fatalf("Failed to add VIP %v: %v", vip, err)
}
log.Infof("Advertising BGP route for %v", vip)
if err := e.ncc.BGPAdvertiseVIP(vip.IP.IP()); err != nil {
log.Fatalf("Failed to advertise VIP %v: %v", vip, err)
}
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L313-L344 | go | train | // gratuitousARP sends gratuitous ARP messages at regular intervals, if this
// node is the HA master. | func (e *Engine) gratuitousARP() | // gratuitousARP sends gratuitous ARP messages at regular intervals, if this
// node is the HA master.
func (e *Engine) gratuitousARP() | {
arpTicker := time.NewTicker(e.config.GratuitousARPInterval)
var announced bool
for {
select {
case <-arpTicker.C:
if e.haManager.state() != seesaw.HAMaster {
if announced {
log.Infof("Stopping gratuitous ARPs for %s", e.config.ClusterVIP.IPv4Addr)
announced = false
}
continue
}
if !announced {
log.Infof("Starting gratuitous ARPs for %s via %s every %s",
e.config.ClusterVIP.IPv4Addr, e.config.LBInterface, e.config.GratuitousARPInterval)
announced = true
}
if err := e.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer e.ncc.Close()
if err := e.ncc.ARPSendGratuitous(e.config.LBInterface, e.config.ClusterVIP.IPv4Addr); err != nil {
log.Fatalf("Failed to send gratuitous ARP: %v", err)
}
case <-e.shutdownARP:
e.shutdownARP <- true
return
}
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L348-L444 | go | train | // manager is responsible for managing and co-ordinating various parts of the
// seesaw engine. | func (e *Engine) manager() | // manager is responsible for managing and co-ordinating various parts of the
// seesaw engine.
func (e *Engine) manager() | {
for {
select {
case n := <-e.notifier.C:
log.Infof("Received cluster config notification; %v", &n)
e.syncServer.notify(&SyncNote{Type: SNTConfigUpdate})
e.clusterLock.Lock()
e.cluster = n.Cluster
e.clusterLock.Unlock()
if n.MetadataOnly {
log.Infof("Only metadata changes found, processing complete.")
continue
}
if ha, err := e.haConfig(); err != nil {
log.Errorf("Manager failed to determine haConfig: %v", err)
} else if ha.Enabled {
e.haManager.enable()
} else {
e.haManager.disable()
}
node, err := e.thisNode()
if err != nil {
log.Errorf("Manager failed to identify local node: %v", err)
continue
}
if !node.VserversEnabled {
e.shutdownVservers()
e.deleteVLANs()
continue
}
// Process new cluster configuration.
e.updateVLANs()
// TODO(jsing): Ensure this does not block.
e.updateVservers()
case state := <-e.haManager.stateChan:
log.Infof("Received HA state notification %v", state)
e.haManager.setState(state)
case status := <-e.haManager.statusChan:
log.Infof("Received HA status notification (%v)", status.State)
e.haManager.setStatus(status)
case <-e.haManager.timer():
log.Infof("Timed out waiting for HAState")
e.haManager.setState(seesaw.HAUnknown)
case svs := <-e.vserverChan:
if _, ok := e.vservers[svs.Name]; !ok {
log.Infof("Received vserver snapshot for unconfigured vserver %s, ignoring", svs.Name)
break
}
log.V(1).Infof("Updating vserver snapshot for %s", svs.Name)
e.vserverLock.Lock()
e.vserverSnapshots[svs.Name] = svs
e.vserverLock.Unlock()
case override := <-e.overrideChan:
sn := &SyncNote{Type: SNTOverride}
switch o := override.(type) {
case *seesaw.BackendOverride:
sn.BackendOverride = o
case *seesaw.DestinationOverride:
sn.DestinationOverride = o
case *seesaw.VserverOverride:
sn.VserverOverride = o
}
e.syncServer.notify(sn)
e.handleOverride(override)
case <-e.shutdown:
log.Info("Shutting down engine...")
// Tell other components to shutdown and then wait for
// them to do so.
e.shutdownIPC <- true
e.shutdownRPC <- true
<-e.shutdownIPC
<-e.shutdownRPC
e.syncClient.disable()
e.shutdownVservers()
e.hcManager.shutdown()
e.deleteVLANs()
log.Info("Shutdown complete")
return
}
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L448-L480 | go | train | // updateVservers processes a list of vserver configurations then stops
// deleted vservers, spawns new vservers and updates the existing vservers. | func (e *Engine) updateVservers() | // updateVservers processes a list of vserver configurations then stops
// deleted vservers, spawns new vservers and updates the existing vservers.
func (e *Engine) updateVservers() | {
e.clusterLock.RLock()
cluster := e.cluster
e.clusterLock.RUnlock()
// Delete vservers that no longer exist in the new configuration.
for name, vserver := range e.vservers {
if cluster.Vservers[name] == nil {
log.Infof("Stopping unconfigured vserver %s", name)
vserver.stop()
<-vserver.stopped
delete(e.vservers, name)
e.vserverLock.Lock()
delete(e.vserverSnapshots, name)
e.vserverLock.Unlock()
}
}
// Spawn new vservers and provide current configurations.
for _, config := range cluster.Vservers {
if e.vservers[config.Name] == nil {
vserver := newVserver(e)
go vserver.run()
e.vservers[config.Name] = vserver
}
}
for _, override := range e.overrides {
e.distributeOverride(override)
}
for _, config := range cluster.Vservers {
e.vservers[config.Name].updateConfig(config)
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L483-L494 | go | train | // shutdownVservers shuts down all running vservers. | func (e *Engine) shutdownVservers() | // shutdownVservers shuts down all running vservers.
func (e *Engine) shutdownVservers() | {
for _, v := range e.vservers {
v.stop()
}
for name, v := range e.vservers {
<-v.stopped
delete(e.vservers, name)
}
e.vserverLock.Lock()
e.vserverSnapshots = make(map[string]*seesaw.Vserver)
e.vserverLock.Unlock()
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L498-L544 | go | train | // updateVLANs creates and destroys VLAN interfaces for the load balancer per
// the cluster configuration. | func (e *Engine) updateVLANs() | // updateVLANs creates and destroys VLAN interfaces for the load balancer per
// the cluster configuration.
func (e *Engine) updateVLANs() | {
e.clusterLock.RLock()
cluster := e.cluster
e.clusterLock.RUnlock()
add := make([]*seesaw.VLAN, 0)
remove := make([]*seesaw.VLAN, 0)
e.vlanLock.Lock()
defer e.vlanLock.Unlock()
for key, vlan := range e.vlans {
if cluster.VLANs[key] == nil {
remove = append(remove, vlan)
} else if !vlan.Equal(cluster.VLANs[key]) {
// TODO(angusc): This will break any VIPs that are currently configured
// on the VLAN interface. Fix!
remove = append(remove, vlan)
add = append(add, cluster.VLANs[key])
}
}
for key, vlan := range cluster.VLANs {
if e.vlans[key] == nil {
add = append(add, vlan)
}
}
if err := e.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer e.ncc.Close()
for _, vlan := range remove {
log.Infof("Removing VLAN interface %v", vlan)
if err := e.lbInterface.DeleteVLAN(vlan); err != nil {
log.Fatalf("Failed to remove VLAN interface %v: %v", vlan, err)
}
}
for _, vlan := range add {
log.Infof("Adding VLAN interface %v", vlan)
if err := e.lbInterface.AddVLAN(vlan); err != nil {
log.Fatalf("Failed to add VLAN interface %v: %v", vlan, err)
}
}
e.vlans = cluster.VLANs
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L548-L563 | go | train | // deleteVLANs removes all the VLAN interfaces that have been created by this
// engine. | func (e *Engine) deleteVLANs() | // deleteVLANs removes all the VLAN interfaces that have been created by this
// engine.
func (e *Engine) deleteVLANs() | {
if err := e.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer e.ncc.Close()
e.vlanLock.Lock()
defer e.vlanLock.Unlock()
for k, v := range e.vlans {
if err := e.lbInterface.DeleteVLAN(v); err != nil {
log.Fatalf("Failed to remove VLAN interface %v: %v", v, err)
}
delete(e.vlans, k)
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L566-L572 | go | train | // handleOverride handles an incoming Override. | func (e *Engine) handleOverride(o seesaw.Override) | // handleOverride handles an incoming Override.
func (e *Engine) handleOverride(o seesaw.Override) | {
e.overrides[o.Target()] = o
e.distributeOverride(o)
if o.State() == seesaw.OverrideDefault {
delete(e.overrides, o.Target())
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L575-L592 | go | train | // distributeOverride distributes an Override to the appropriate vservers. | func (e *Engine) distributeOverride(o seesaw.Override) | // distributeOverride distributes an Override to the appropriate vservers.
func (e *Engine) distributeOverride(o seesaw.Override) | {
// Send VserverOverrides and DestinationOverrides to the appropriate vserver.
// Send BackendOverrides to all vservers.
switch override := o.(type) {
case *seesaw.VserverOverride:
if vserver, ok := e.vservers[override.VserverName]; ok {
vserver.queueOverride(o)
}
case *seesaw.DestinationOverride:
if vserver, ok := e.vservers[override.VserverName]; ok {
vserver.queueOverride(o)
}
case *seesaw.BackendOverride:
for _, vserver := range e.vservers {
vserver.queueOverride(o)
}
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L596-L609 | go | train | // becomeMaster performs the necessary actions for the Seesaw Engine to
// become the master node. | func (e *Engine) becomeMaster() | // becomeMaster performs the necessary actions for the Seesaw Engine to
// become the master node.
func (e *Engine) becomeMaster() | {
if err := e.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer e.ncc.Close()
e.syncClient.disable()
e.hcManager.enable()
e.notifier.SetSource(config.SourceServer)
if err := e.lbInterface.Up(); err != nil {
log.Fatalf("Failed to bring LB interface up: %v", err)
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L613-L631 | go | train | // becomeBackup performs the neccesary actions for the Seesaw Engine to
// stop being the master node and become the backup node. | func (e *Engine) becomeBackup() | // becomeBackup performs the neccesary actions for the Seesaw Engine to
// stop being the master node and become the backup node.
func (e *Engine) becomeBackup() | {
if err := e.ncc.Dial(); err != nil {
log.Fatalf("Failed to connect to NCC: %v", err)
}
defer e.ncc.Close()
e.syncClient.enable()
e.hcManager.disable()
e.notifier.SetSource(config.SourcePeer)
if err := e.lbInterface.Down(); err != nil {
log.Fatalf("Failed to bring LB interface down: %v", err)
}
// TODO(jsing): Once peer synchronisation is implemented, make this
// a time-based expiration that commences once communication with the
// peer is lost.
e.hcManager.expire()
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L641-L649 | go | train | // newMarkAllocator returns a mark allocator initialised with the specified
// base and size. | func newMarkAllocator(base, size int) *markAllocator | // newMarkAllocator returns a mark allocator initialised with the specified
// base and size.
func newMarkAllocator(base, size int) *markAllocator | {
ma := &markAllocator{
marks: make([]uint32, 0, size),
}
for i := 0; i < size; i++ {
ma.put(uint32(base + i))
}
return ma
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L652-L661 | go | train | // get returns the next available mark from the mark allocator. | func (ma *markAllocator) get() (uint32, error) | // get returns the next available mark from the mark allocator.
func (ma *markAllocator) get() (uint32, error) | {
ma.lock.Lock()
defer ma.lock.Unlock()
if len(ma.marks) == 0 {
return 0, errors.New("allocator exhausted")
}
mark := ma.marks[0]
ma.marks = ma.marks[1:]
return mark, nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | engine/core.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/engine/core.go#L664-L668 | go | train | // put returns the specified mark to the mark allocator. | func (ma *markAllocator) put(mark uint32) | // put returns the specified mark to the mark allocator.
func (ma *markAllocator) put(mark uint32) | {
ma.lock.Lock()
defer ma.lock.Unlock()
ma.marks = append(ma.marks, mark)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ecu/auth.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/auth.go#L36-L38 | go | train | // authenticate attempts to validate the given authentication token. | func (e *ECU) authenticate(ctx *ipc.Context) (*ipc.Context, error) | // authenticate attempts to validate the given authentication token.
func (e *ECU) authenticate(ctx *ipc.Context) (*ipc.Context, error) | {
return nil, errors.New("unimplemented")
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ecu/auth.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ecu/auth.go#L43-L61 | go | train | // authConnect attempts to authenticate the user using the given context. If
// authentication succeeds an authenticated IPC connection to the Seesaw
// Engine is returned. | func (e *ECU) authConnect(ctx *ipc.Context) (*conn.Seesaw, error) | // authConnect attempts to authenticate the user using the given context. If
// authentication succeeds an authenticated IPC connection to the Seesaw
// Engine is returned.
func (e *ECU) authConnect(ctx *ipc.Context) (*conn.Seesaw, error) | {
if ctx == nil {
return nil, errors.New("context is nil")
}
authCtx, err := e.authenticate(ctx)
if err != nil {
return nil, fmt.Errorf("authentication failed: %v", err)
}
seesawConn, err := conn.NewSeesawIPC(authCtx)
if err != nil {
return nil, fmt.Errorf("failed to connect to engine: %v", err)
}
if err := seesawConn.Dial(e.cfg.EngineSocket); err != nil {
return nil, fmt.Errorf("failed to connect to engine: %v", err)
}
return seesawConn, nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | binaries/seesaw_cli/main.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_cli/main.go#L93-L103 | go | train | // commandChain builds a command chain from the given command slice. | func commandChain(chain []*cli.Command, args []string) string | // commandChain builds a command chain from the given command slice.
func commandChain(chain []*cli.Command, args []string) string | {
s := make([]string, 0)
for _, c := range chain {
s = append(s, c.Command)
}
s = append(s, args...)
if len(s) > 0 && len(args) == 0 {
s = append(s, "")
}
return strings.Join(s, " ")
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | binaries/seesaw_cli/main.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_cli/main.go#L107-L143 | go | train | // autoComplete attempts to complete the user's input when certain
// characters are typed. | func autoComplete(line string, pos int, key rune) (string, int, bool) | // autoComplete attempts to complete the user's input when certain
// characters are typed.
func autoComplete(line string, pos int, key rune) (string, int, bool) | {
switch key {
case 0x01: // Ctrl-A
return line, 0, true
case 0x03: // Ctrl-C
exit()
case 0x05: // Ctrl-E
return line, len(line), true
case 0x09: // Ctrl-I (Tab)
_, _, chain, args := cli.FindCommand(string(line))
line := commandChain(chain, args)
return line, len(line), true
case 0x15: // Ctrl-U
return "", 0, true
case 0x1a: // Ctrl-Z
suspend()
case '?':
cmd, subcmds, chain, args := cli.FindCommand(string(line[0:pos]))
if cmd == nil {
term.Write([]byte(prompt))
term.Write([]byte(line))
term.Write([]byte("?\n"))
}
if subcmds != nil {
for _, c := range *subcmds {
term.Write([]byte(" " + c.Command))
term.Write([]byte("\n"))
}
} else if cmd == nil {
term.Write([]byte("Unknown command.\n"))
}
line := commandChain(chain, args)
return line, len(line), true
}
return "", 0, false
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | binaries/seesaw_cli/main.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/binaries/seesaw_cli/main.go#L146-L191 | go | train | // interactive invokes the interactive CLI interface. | func interactive() | // interactive invokes the interactive CLI interface.
func interactive() | {
status, err := seesawConn.ClusterStatus()
if err != nil {
fatalf("Failed to get cluster status: %v", err)
}
fmt.Printf("\nSeesaw CLI - Engine version %d\n\n", status.Version)
u, err := user.Current()
if err != nil {
fatalf("Failed to get current user: %v", err)
}
ha, err := seesawConn.HAStatus()
if err != nil {
fatalf("Failed to get HA status: %v", err)
}
if ha.State != seesaw.HAMaster {
fmt.Println("WARNING: This seesaw is not currently the master.")
}
prompt = fmt.Sprintf("%s@%s> ", u.Username, status.Site)
// Setup signal handler before we switch to a raw terminal.
sigc := make(chan os.Signal, 3)
signal.Notify(sigc, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
go func() {
<-sigc
exit()
}()
terminalInit()
for {
cmdline, err := term.ReadLine()
if err != nil {
break
}
cmdline = strings.TrimSpace(cmdline)
if cmdline == "" {
continue
}
if err := seesawCLI.Execute(cmdline); err != nil {
fmt.Println(err)
}
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L81-L102 | go | train | // newIPVSService converts a service to its IPVS representation. | func newIPVSService(svc *Service) *ipvsService | // newIPVSService converts a service to its IPVS representation.
func newIPVSService(svc *Service) *ipvsService | {
ipvsSvc := &ipvsService{
Address: svc.Address,
Protocol: svc.Protocol,
Port: svc.Port,
FirewallMark: svc.FirewallMark,
Scheduler: svc.Scheduler,
Flags: svc.Flags,
Timeout: svc.Timeout,
PersistenceEngine: svc.PersistenceEngine,
}
if ip4 := svc.Address.To4(); ip4 != nil {
ipvsSvc.AddrFamily = syscall.AF_INET
ipvsSvc.Netmask = 0xffffffff
} else {
ipvsSvc.AddrFamily = syscall.AF_INET6
ipvsSvc.Netmask = 128
}
return ipvsSvc
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L105-L114 | go | train | // newIPVSDestination converts a destination to its IPVS representation. | func newIPVSDestination(dst *Destination) *ipvsDestination | // newIPVSDestination converts a destination to its IPVS representation.
func newIPVSDestination(dst *Destination) *ipvsDestination | {
return &ipvsDestination{
Address: dst.Address,
Port: dst.Port,
Flags: dst.Flags,
Weight: uint32(dst.Weight),
UpperThreshold: dst.UpperThreshold,
LowerThreshold: dst.LowerThreshold,
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L118-L147 | go | train | // toService converts a service entry from its IPVS representation to the Go
// equivalent Service structure. | func (ipvsSvc ipvsService) toService() *Service | // toService converts a service entry from its IPVS representation to the Go
// equivalent Service structure.
func (ipvsSvc ipvsService) toService() *Service | {
svc := &Service{
Address: ipvsSvc.Address,
Protocol: ipvsSvc.Protocol,
Port: ipvsSvc.Port,
FirewallMark: ipvsSvc.FirewallMark,
Scheduler: ipvsSvc.Scheduler,
Flags: ipvsSvc.Flags,
Timeout: ipvsSvc.Timeout,
PersistenceEngine: ipvsSvc.PersistenceEngine,
Statistics: &ServiceStats{},
}
// Various callers of this package expect that a service will always
// have a non-nil address (all zero bytes if non-existent). At some
// point we may want to revisit this and return a nil address instead.
if svc.Address == nil {
if ipvsSvc.AddrFamily == syscall.AF_INET {
svc.Address = net.IPv4zero
} else {
svc.Address = net.IPv6zero
}
}
if ipvsSvc.Stats != nil {
*svc.Statistics = *ipvsSvc.Stats
}
return svc
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L151-L171 | go | train | // toDestination converts a destination entry from its IPVS representation
// to the Go equivalent Destination structure. | func (ipvsDst ipvsDestination) toDestination() *Destination | // toDestination converts a destination entry from its IPVS representation
// to the Go equivalent Destination structure.
func (ipvsDst ipvsDestination) toDestination() *Destination | {
dst := &Destination{
Address: ipvsDst.Address,
Port: ipvsDst.Port,
Weight: int32(ipvsDst.Weight), // TODO(jsing): uint32?
Flags: ipvsDst.Flags,
LowerThreshold: ipvsDst.LowerThreshold,
UpperThreshold: ipvsDst.UpperThreshold,
Statistics: &DestinationStats{},
}
if ipvsDst.Stats != nil {
*dst.Statistics = *ipvsDst.Stats
}
dst.Statistics.ActiveConns = ipvsDst.ActiveConns
dst.Statistics.InactiveConns = ipvsDst.InactiveConns
dst.Statistics.PersistConns = ipvsDst.PersistConns
return dst
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L177-L185 | go | train | // String returns the name for the given protocol value. | func (proto IPProto) String() string | // String returns the name for the given protocol value.
func (proto IPProto) String() string | {
switch proto {
case syscall.IPPROTO_TCP:
return "TCP"
case syscall.IPPROTO_UDP:
return "UDP"
}
return fmt.Sprintf("IP(%d)", proto)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L203-L211 | go | train | // Bytes returns the netlink representation of the service flags. | func (f ServiceFlags) Bytes() []byte | // Bytes returns the netlink representation of the service flags.
func (f ServiceFlags) Bytes() []byte | {
x := make([]byte, 8)
var b [4]byte
*(*uint32)(unsafe.Pointer(&b)) = uint32(f)
copy(x[:4], b[:])
*(*uint32)(unsafe.Pointer(&b)) = ^uint32(0)
copy(x[4:], b[:])
return x
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L214-L218 | go | train | // SetBytes sets the service flags from its netlink representation. | func (f *ServiceFlags) SetBytes(x []byte) | // SetBytes sets the service flags from its netlink representation.
func (f *ServiceFlags) SetBytes(x []byte) | {
var b [4]byte
copy(b[:], x)
*f = ServiceFlags(*(*uint32)(unsafe.Pointer(&b)))
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L241-L250 | go | train | // Equal returns true if two Services are the same. | func (svc Service) Equal(other Service) bool | // Equal returns true if two Services are the same.
func (svc Service) Equal(other Service) bool | {
return svc.Address.Equal(other.Address) &&
svc.Protocol == other.Protocol &&
svc.Port == other.Port &&
svc.FirewallMark == other.FirewallMark &&
svc.Scheduler == other.Scheduler &&
svc.Flags == other.Flags &&
svc.Timeout == other.Timeout &&
svc.PersistenceEngine == other.PersistenceEngine
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L253-L262 | go | train | // String returns a string representation of a Service. | func (svc Service) String() string | // String returns a string representation of a Service.
func (svc Service) String() string | {
switch {
case svc.FirewallMark > 0:
return fmt.Sprintf("FWM %d (%s)", svc.FirewallMark, svc.Scheduler)
case svc.Address.To4() == nil:
return fmt.Sprintf("%v [%v]:%d (%s)", svc.Protocol, svc.Address, svc.Port, svc.Scheduler)
default:
return fmt.Sprintf("%v %v:%d (%s)", svc.Protocol, svc.Address, svc.Port, svc.Scheduler)
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L288-L295 | go | train | // Equal returns true if two Destinations are the same. | func (dest Destination) Equal(other Destination) bool | // Equal returns true if two Destinations are the same.
func (dest Destination) Equal(other Destination) bool | {
return dest.Address.Equal(other.Address) &&
dest.Port == other.Port &&
dest.Weight == other.Weight &&
dest.Flags == other.Flags &&
dest.LowerThreshold == other.LowerThreshold &&
dest.UpperThreshold == other.UpperThreshold
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L298-L304 | go | train | // String returns a string representation of a Destination. | func (dest Destination) String() string | // String returns a string representation of a Destination.
func (dest Destination) String() string | {
addr := dest.Address.String()
if dest.Address.To4() == nil {
addr = fmt.Sprintf("[%s]", addr)
}
return fmt.Sprintf("%s:%d", addr, dest.Port)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L356-L364 | go | train | // Init intialises IPVS. | func Init() error | // Init intialises IPVS.
func Init() error | {
var err error
family, err = netlink.Family(familyName)
if err != nil {
return err
}
return netlink.SendMessageUnmarshal(C.IPVS_CMD_GET_INFO, family, 0, &info)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L367-L374 | go | train | // Version returns the version number for IPVS. | func Version() IPVSVersion | // Version returns the version number for IPVS.
func Version() IPVSVersion | {
v := uint(info.Version)
return IPVSVersion{
Major: (v >> 16) & 0xff,
Minor: (v >> 8) & 0xff,
Patch: v & 0xff,
}
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L383-L394 | go | train | // AddService adds the specified service to the IPVS table. Any destinations
// associated with the given service will also be added. | func AddService(svc Service) error | // AddService adds the specified service to the IPVS table. Any destinations
// associated with the given service will also be added.
func AddService(svc Service) error | {
ic := &ipvsCommand{Service: newIPVSService(&svc)}
if err := netlink.SendMessageMarshalled(C.IPVS_CMD_NEW_SERVICE, family, 0, ic); err != nil {
return err
}
for _, dst := range svc.Destinations {
if err := AddDestination(svc, *dst); err != nil {
return err
}
}
return nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L397-L400 | go | train | // UpdateService updates the specified service in the IPVS table. | func UpdateService(svc Service) error | // UpdateService updates the specified service in the IPVS table.
func UpdateService(svc Service) error | {
ic := &ipvsCommand{Service: newIPVSService(&svc)}
return netlink.SendMessageMarshalled(C.IPVS_CMD_SET_SERVICE, family, 0, ic)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L403-L406 | go | train | // DeleteService deletes the specified service from the IPVS table. | func DeleteService(svc Service) error | // DeleteService deletes the specified service from the IPVS table.
func DeleteService(svc Service) error | {
ic := &ipvsCommand{Service: newIPVSService(&svc)}
return netlink.SendMessageMarshalled(C.IPVS_CMD_DEL_SERVICE, family, 0, ic)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L409-L415 | go | train | // AddDestination adds the specified destination to the IPVS table. | func AddDestination(svc Service, dst Destination) error | // AddDestination adds the specified destination to the IPVS table.
func AddDestination(svc Service, dst Destination) error | {
ic := &ipvsCommand{
Service: newIPVSService(&svc),
Destination: newIPVSDestination(&dst),
}
return netlink.SendMessageMarshalled(C.IPVS_CMD_NEW_DEST, family, 0, ic)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L418-L424 | go | train | // UpdateDestination updates the specified destination in the IPVS table. | func UpdateDestination(svc Service, dst Destination) error | // UpdateDestination updates the specified destination in the IPVS table.
func UpdateDestination(svc Service, dst Destination) error | {
ic := &ipvsCommand{
Service: newIPVSService(&svc),
Destination: newIPVSDestination(&dst),
}
return netlink.SendMessageMarshalled(C.IPVS_CMD_SET_DEST, family, 0, ic)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L427-L433 | go | train | // DeleteDestination deletes the specified destination from the IPVS table. | func DeleteDestination(svc Service, dst Destination) error | // DeleteDestination deletes the specified destination from the IPVS table.
func DeleteDestination(svc Service, dst Destination) error | {
ic := &ipvsCommand{
Service: newIPVSService(&svc),
Destination: newIPVSDestination(&dst),
}
return netlink.SendMessageMarshalled(C.IPVS_CMD_DEL_DEST, family, 0, ic)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L437-L465 | go | train | // destinations returns a list of destinations that are currently
// configured in the kernel IPVS table for the specified service. | func destinations(svc *Service) ([]*Destination, error) | // destinations returns a list of destinations that are currently
// configured in the kernel IPVS table for the specified service.
func destinations(svc *Service) ([]*Destination, error) | {
msg, err := netlink.NewMessage(C.IPVS_CMD_GET_DEST, family, netlink.MFDump)
if err != nil {
return nil, err
}
defer msg.Free()
ic := &ipvsCommand{Service: newIPVSService(svc)}
if err := msg.Marshal(ic); err != nil {
return nil, err
}
var dsts []*Destination
cb := func(msg *netlink.Message, arg interface{}) error {
ic := &ipvsCommand{}
if err := msg.Unmarshal(ic); err != nil {
return fmt.Errorf("failed to unmarshal service: %v", err)
}
if ic.Destination == nil {
return errors.New("no destination in unmarshalled message")
}
dsts = append(dsts, ic.Destination.toDestination())
return nil
}
if err := msg.SendCallback(cb, nil); err != nil {
return nil, err
}
return dsts, nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L470-L514 | go | train | // services returns a list of services that are currently configured in the
// kernel IPVS table. If a specific service is given, an exact match will be
// attempted and a single service will be returned if it is found. | func services(svc *Service) ([]*Service, error) | // services returns a list of services that are currently configured in the
// kernel IPVS table. If a specific service is given, an exact match will be
// attempted and a single service will be returned if it is found.
func services(svc *Service) ([]*Service, error) | {
var flags int
if svc == nil {
flags = netlink.MFDump
}
msg, err := netlink.NewMessage(C.IPVS_CMD_GET_SERVICE, family, flags)
if err != nil {
return nil, err
}
defer msg.Free()
if svc != nil {
ic := &ipvsCommand{Service: newIPVSService(svc)}
if err := msg.Marshal(ic); err != nil {
return nil, err
}
}
var svcs []*Service
cb := func(msg *netlink.Message, arg interface{}) error {
ic := &ipvsCommand{}
if err := msg.Unmarshal(ic); err != nil {
return fmt.Errorf("failed to unmarshal service: %v", err)
}
if ic.Service == nil {
return errors.New("no service in unmarshalled message")
}
svcs = append(svcs, ic.Service.toService())
return nil
}
if err := msg.SendCallback(cb, nil); err != nil {
return nil, err
}
for _, svc := range svcs {
dsts, err := destinations(svc)
if err != nil {
return nil, err
}
svc.Destinations = dsts
}
return svcs, nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | ipvs/ipvs.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/ipvs/ipvs.go#L518-L527 | go | train | // GetService returns the service entry that is currently configured in the
// kernel IPVS table, which matches the specified service. | func GetService(svc *Service) (*Service, error) | // GetService returns the service entry that is currently configured in the
// kernel IPVS table, which matches the specified service.
func GetService(svc *Service) (*Service, error) | {
svcs, err := services(svc)
if err != nil {
return nil, err
}
if len(svcs) == 0 {
return nil, errors.New("no service found")
}
return svcs[0], nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/conn/ipc.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L45-L52 | go | train | // Dial establishes a connection to the Seesaw Engine. | func (c *engineIPC) Dial(addr string) error | // Dial establishes a connection to the Seesaw Engine.
func (c *engineIPC) Dial(addr string) error | {
client, err := rpc.Dial("unix", addr)
if err != nil {
return fmt.Errorf("Dial failed: %v", err)
}
c.client = client
return nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/conn/ipc.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L55-L64 | go | train | // Close closes an existing connection to the Seesaw Engine. | func (c *engineIPC) Close() error | // Close closes an existing connection to the Seesaw Engine.
func (c *engineIPC) Close() error | {
if c.client == nil {
return fmt.Errorf("No client to close")
}
if err := c.client.Close(); err != nil {
return fmt.Errorf("Close failed: %v", err)
}
c.client = nil
return nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/conn/ipc.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L85-L91 | go | train | // HAStatus requests the HA status of the Seesaw Node. | func (c *engineIPC) HAStatus() (*seesaw.HAStatus, error) | // HAStatus requests the HA status of the Seesaw Node.
func (c *engineIPC) HAStatus() (*seesaw.HAStatus, error) | {
var ha seesaw.HAStatus
if err := c.client.Call("SeesawEngine.HAStatus", c.ctx, &ha); err != nil {
return nil, err
}
return &ha, nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/conn/ipc.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L96-L102 | go | train | // ConfigSource requests the configuration source be changed to the
// specified source. An empty string results in the source remaining
// unchanged. The current configuration source is returned. | func (c *engineIPC) ConfigSource(source string) (string, error) | // ConfigSource requests the configuration source be changed to the
// specified source. An empty string results in the source remaining
// unchanged. The current configuration source is returned.
func (c *engineIPC) ConfigSource(source string) (string, error) | {
cs := &ipc.ConfigSource{c.ctx, source}
if err := c.client.Call("SeesawEngine.ConfigSource", cs, &source); err != nil {
return "", err
}
return source, nil
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/conn/ipc.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L105-L107 | go | train | // ConfigReload requests the configuration to be reloaded. | func (c *engineIPC) ConfigReload() error | // ConfigReload requests the configuration to be reloaded.
func (c *engineIPC) ConfigReload() error | {
return c.client.Call("SeesawEngine.ConfigReload", c.ctx, nil)
} |
google/seesaw | 34716af0775ecb1fad239a726390d63d6b0742dd | common/conn/ipc.go | https://github.com/google/seesaw/blob/34716af0775ecb1fad239a726390d63d6b0742dd/common/conn/ipc.go#L111-L117 | go | train | // BGPNeighbors requests a list of all BGP neighbors that this seesaw is
// peering with. | func (c *engineIPC) BGPNeighbors() ([]*quagga.Neighbor, error) | // BGPNeighbors requests a list of all BGP neighbors that this seesaw is
// peering with.
func (c *engineIPC) BGPNeighbors() ([]*quagga.Neighbor, error) | {
var bn quagga.Neighbors
if err := c.client.Call("SeesawEngine.BGPNeighbors", c.ctx, &bn); err != nil {
return nil, err
}
return bn.Neighbors, nil
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.