id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c26500
return IPv4 } return IPv6 }
c26501
ok := modeNames[lbm]; ok { return name } return "(unknown)" }
c26502
ok := schedulerNames[lbs]; ok { return name } return "(unknown)" }
c26503
os.NewSyscallError("failed to set mark", err) } return nil }
c26504
syscall.SO_SNDTIMEO} { if err := syscall.SetsockoptTimeval(fd, syscall.SOL_SOCKET, opt, &tv); err != nil { return os.NewSyscallError("setsockopt", err) } } return nil }
c26505
make(chan seesaw.Override, 5), notify: make(chan *checkNotification, 20), update: make(chan *config.Vserver, 1), quit: make(chan bool, 1), stopped: make(chan bool, 1), } }
c26506
fmt.Sprintf("Unconfigured vserver %+v", *v) }
c26507
ip, Protocol: ipvs.IPProto(svc.proto), Port: svc.port, Scheduler: svc.ventry.Scheduler.String(), FirewallMark: svc.fwm, Flags: flags, Timeout: uint32(svc.ventry.Persistence), } }
c26508
other.ventry.LThreshold && s.ventry.UThreshold == other.ventry.UThreshold }
c26509
:= strconv.Itoa(int(s.port)) return fmt.Sprintf("%v/%v", net.JoinHostPort(ip, port), s.proto) }
c26510
dst.service.port, Weight: dst.weight, Flags: flags, LowerThreshold: uint32(dst.service.ventry.LThreshold), UpperThreshold: uint32(dst.service.ventry.UThreshold), } }
c26511
d.ipvsDst.Equal(*other.ipvsDst) }
c26512
strconv.Itoa(int(d.service.port)) return fmt.Sprintf("%v/%v", net.JoinHostPort(ip, port), d.service.proto) }
c26513
fmt.Sprintf("%v/%v", d.service.vserver.String(), d.String()) }
c26514
vip, backendIP: bip, servicePort: port, serviceProtocol: proto, healthcheckMode: h.Mode, healthcheckType: h.Type, healthcheckPort: h.Port, name: h.Name, } }
c26515
c.backendIP, c.servicePort, c.serviceProtocol, c.healthcheckMode, c.healthcheckType, c.healthcheckPort, c.name) }
c26516
{ return &check{ key: key, vserver: v, healthcheck: h, } }
c26517
seesaw.NewIP(ip), ventry: entry, vserver: v, dests: make(map[destinationKey]*destination, 0), stats: &seesaw.ServiceStats{}, } svc.ipvsSvc = svc.ipvsService() svcs[svc.serviceKey] = svc } } return svcs }
c26518
%v", v, err) } v.fwm[af] = mark } svc := &service{ serviceKey: serviceKey{ af: af, fwm: v.fwm[af], }, ip: seesaw.NewIP(ip), ventry: ventry, vserver: v, stats: &seesaw.ServiceStats{}, } svc.ipvsSvc = svc.ipvsService() svcs[svc.serviceKey] = svc } return svcs }
c26519
newDestinationKey(ip), service: svc, backend: backend, weight: backend.Weight, } dst.ipvsDst = dst.ipvsDestination() dst.stats = &seesaw.DestinationStats{} dsts[dst.destinationKey] = dst } return dsts }
c26520
v, hc) checks[key] = c dest.checks = append(dest.checks, c) c.dests = append(c.dests, dest) } } } else { for _, hc := range svc.ventry.Healthchecks { key := newCheckKey(svc.ip, dest.ip, svc.port, svc.proto, hc) c := newCheck(key, v, hc) checks[key] = c dest.checks ...
c26521
v.config.Name} if v.enabled { vc.checks = v.checks } return vc }
c26522
} // Something changed - export a new vserver snapshot. // The goroutine that drains v.engine.vserverChan also does a blocking write // to each vserver's vserver.notify channel, which is drained by each // vserver's goroutine (i.e., this one). So we need a timeout to avoid a // deadlock. timeout := time.A...
c26523
also requires updating iptables, but // v.configUpdate() handles this case) // // TODO(angusc): Add support for finer-grained updates to ncc so we can // avoid re-initialising the vserver in these cases. reInit := false switch { case config.UseFWM != v.config.UseFWM: reInit = true case len(config.E...
c26524
oldDst, ok := oldSvc.dests[dstK]; ok { *dst.stats = *oldDst.stats } } } } v.services = newSvcs v.checks = v.expandChecks() if v.enabled { v.configureVIPs() } return }
c26525
} log.Infof("%v: service %v: adding new destination: %v", v, svc, newDest) svc.dests[destKey] = newDest } for destKey, dest := range svc.dests { if newDests[destKey] == nil { // Destination no longer exists if dest.active { dest.healthy = false svc.updateState() } log.Infof("%...
c26526
// TODO(baptr): Once service contains seesaw.VIP, move check and // unconfigureVIP here. }
c26527
n.status.State) check.description = n.description check.status = n.status if transition { log.Infof("%v: healthcheck %s - %v (%s)", v, n.description, n.status.State, n.status.Message) for _, d := range check.dests { d.updateState() } } }
c26528
- nothing to do return } // TODO(angusc): handle backend and destination overrides. default: return } if v.config != nil { v.handleConfigUpdate(v.config) } }
c26529
return false case os == seesaw.OverrideDisable: return false case os == seesaw.OverrideEnable: return true } return config.Enabled }
c26530
v.enabled, ConfigEnabled: v.config.Enabled, Warnings: v.config.Warnings, } for _, ve := range v.config.Entries { sv.Entries = append(sv.Entries, ve.Snapshot()) } sv.FWM[seesaw.IPv4] = v.fwm[seesaw.IPv4] sv.FWM[seesaw.IPv6] = v.fwm[seesaw.IPv6] for _, s := range v.services { ss := s.snapshot() ...
c26531
{ case d.service.active && d.healthy: // The service is already active. Bringing up the dest will have no effect // on the service or vserver state. d.up() case d.service.active != d.healthy || d.service.healthy != d.healthy: // The service may need to be brought up or down. d.service.updateState() } }
c26532
if err := ncc.IPVSAddDestination(d.service.ipvsSvc, d.ipvsDst); err != nil { log.Fatalf("%v: failed to add destination %v: %v", d.service.vserver, d, err) } }
c26533
if err := ncc.IPVSDeleteDestination(d.service.ipvsSvc, d.ipvsDst); err != nil { log.Fatalf("%v: failed to delete destination %v: %v", d.service.vserver, d, err) } }
c26534
= *dest if !d.healthy { return } if !d.backend.Enabled { log.Infof("%v: %v disabling destination %v", d.service.vserver, d.service, d) d.healthy = false d.service.updateState() return } if !updateIPVS { return } log.Infof("%v: %v updating IPVS destination %v", d.service.vserver, d.service, d) n...
c26535
d.backend.Enabled, Weight: d.weight, Healthy: d.healthy, Active: d.active, } }
c26536
oldHealth = "healthy" } if healthy { newHealth = "healthy" } log.Infof("%v: %v: %d/%d destinations are healthy, service was %v, now %v", s.vserver, s, numHealthyDests, numBackends, oldHealth, newHealth) s.healthy = healthy vserverActive := s.vserver.active[s.ip] switch { case vserverActive && s.healthy:...
c26537
continue } switch { case !d.healthy && d.active: d.down() case d.healthy && !d.active: d.up() } } }
c26538
:= ncc.IPVSAddService(s.ipvsSvc); err != nil { log.Fatalf("%v: failed to add service %v: %v", s.vserver, s, err) } // Update destinations *after* the IPVS service exists. s.updateDests() }
c26539
destinations *before* the IPVS service is removed. s.updateDests() if err := ncc.IPVSDeleteService(s.ipvsSvc); err != nil { log.Fatalf("%v: failed to delete service %v: %v", s.vserver, s, err) } }
c26540
service", s.vserver, s) ncc := s.vserver.ncc if err := ncc.Dial(); err != nil { log.Fatalf("%v: failed to connect to NCC: %v", s.vserver, err) } defer ncc.Close() if err := ncc.IPVSUpdateService(s.ipvsSvc); err != nil { log.Fatalf("%v: failed to update service %v: %v", s.vserver, s, err) } }
c26541
for _, d := range s.dests { if d.ipvsDst.Address.Equal(ipvsDst.Address) && d.ipvsDst.Port == ipvsDst.Port { d.stats.DestinationStats = ipvsDst.Statistics found = true break } } if !found { log.Warningf("%v: got statistics for unknown destination %v", s.vserver, ipvsDst) } } }
c26542
s.ventry.HighWatermark, } for _, d := range s.dests { sd := d.snapshot() ss.Destinations[sd.Backend.Hostname] = sd } numBackends := 0 numHealthyDests := 0 for _, d := range s.dests { if d.backend.InService { numBackends++ } if d.healthy { numHealthyDests++ } } if numBackends > 0 { ss.Curre...
c26543
healthy && !seesaw.IsAnycast(ip.IP()) { break } } if v.active[ip] == healthy { v.updateServices(ip) return } switch { case !healthy && v.active[ip]: v.down(ip) case healthy && !v.active[ip]: v.up(ip) } }
c26544
if !v.active[ip] { if s.active { s.down() } continue } switch { case !s.healthy && s.active: s.down() case s.healthy && !s.active: s.up() } } }
c26545
for non-anycast clusters further // upstream. if v.engine.config.AnycastEnabled { log.Infof("%v: advertising BGP route for %v", v, ip) if err := ncc.BGPAdvertiseVIP(nip); err != nil { log.Fatalf("%v: failed to advertise VIP %v: %v", v, ip, err) } } else { log.Warningf("%v: %v is an anycast VIP, b...
c26546
v.down(s.ip) } if s.active { s.down() } } }
c26547
v.engine.lbInterface.DeleteVIP(vip); err != nil { log.Fatalf("%v: failed to remove VIP %v: %v", v, ip, err) } if err := v.engine.lbInterface.DeleteVserver(v.lbVservers[ip], ip.AF()); err != nil { log.Fatalf("%v: failed to delete Vserver: %v", v, err) } delete(v.lbVservers, ip) } // TODO(jsing): Should ...
c26548
if vip.Type == seesaw.AnycastVIP { continue } // TODO(jsing): Create a ncc.LBVserver that only encapsulates // the necessary state, rather than storing a full vserver // snapshot. lbVserver := v.snapshot() lbVserver.Services = nil lbVserver.Warnings = nil if err := v.engine.lbInterface.AddVserver(...
c26549
v.engine.lbInterface.DeleteVserver(v.lbVservers[vip.IP], vip.IP.AF()); err != nil { log.Fatalf("%v: failed to delete Vserver: %v", v, err) } delete(v.lbVservers, vip.IP) } delete(v.vips, *vip) }
c26550
need to support VLAN // interfaces and dedicated VIP subnets. for vip := range v.vips { v.unconfigureVIP(&vip) } }
c26551
{ return nil, err } req.Header.Add("Connection", "close") resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("received HTTP status %s", resp.Status) } if ct := resp.Header.Get("Content-Type"); ct != contentT...
c26552
return binary.BigEndian.Uint16(b[:]) }
c26553
return *(*uint16)(unsafe.Pointer(&b)) }
c26554
return binary.BigEndian.Uint32(b[:]) }
c26555
return *(*uint32)(unsafe.Pointer(&b)) }
c26556
return binary.BigEndian.Uint64(b[:]) }
c26557
return *(*uint64)(unsafe.Pointer(&b)) }
c26558
maxAttrID = fp.attr } if fp == nil && fv.Kind() == reflect.Struct { attrID, err := structMaxAttrID(fv) if err != nil { return 0, err } if attrID > maxAttrID { maxAttrID = attrID } } } return maxAttrID, nil }
c26559
fmt.Sprintf("%s: %s", e.msg, strings.ToLower(nle)) }
c26560
family := C.genl_ctrl_resolve(s.nls, cn) if family < 0 { return -1, errors.New("failed to resolve family name") } return int(family), nil }
c26561
fmt.Errorf("Invalid interface name %q", iface.Name) } return nil }
c26562
out, err = ipRunOutput("-6 addr show dev %s scope global", iface.Name) for _, line := range strings.Split(out, "\n") { if match := ipv6AddrRegexp.FindStringSubmatch(line); match != nil { ipv6Addrs[match[1]] = iface } } } if err := ifaceFastDown(pIface); err != nil { return err } for addr, iface := ...
c26563
address %s", iface.Name, iface.HardwareAddr) }
c26564
return ifaceAddIPv4Addr(iface, ip, mask) } return ifaceAddIPv6Addr(iface, ip, mask) }
c26565
i++ { brd[i] |= ^mask[i] } prefixLen, _ := mask.Size() return ipRunIface(iface, "addr add %s/%d brd %s dev %s", ip, prefixLen, brd, iface.Name) }
c26566
{ prefixLen, _ := mask.Size() return ipRunIface(iface, "addr add %s/%d dev %s", ip, prefixLen, iface.Name) }
c26567
nil { if err := ifaceAddIPv4Addr(vlanIface, vlan.IPv4Addr, vlan.IPv4Mask); err != nil { return fmt.Errorf("Failed to add %v to VLAN interface %q", vlan.IPv4Addr, name) } } if vlan.IPv6Addr != nil { if err := ifaceAddIPv6Addr(vlanIface, vlan.IPv6Addr, vlan.IPv6Mask); err != nil { return fmt.Errorf("Failed...
c26568
:= net.InterfaceByName(name) if err != nil { return fmt.Errorf("Failed to find VLAN interface %q: %v", name, err) } return ipRunIface(vlanIface, "link del dev %s", vlanIface.Name) }
c26569
if err := ipRunIface(vlanIface, "link del dev %s", vlanIface.Name); err != nil { return fmt.Errorf("Failed to remove %s from %s: %v", vlanIface.Name, iface.Name, err) } } return nil }
c26570
nil, err } if dr := routeDefaultIPv4Regexp.FindStringSubmatch(out); dr != nil { return net.ParseIP(dr[1]).To4(), nil } return nil, fmt.Errorf("Default route not found") }
c26571
if vip.To4() != nil { af = seesaw.IPv4 } return ipRunAF(af, "route flush table %s %s", table, vip) }
c26572
err != nil { return err } return ipRunAF(af, "route add table local local %s dev %s src %s", vip, iface.Name, src) }
c26573
*gateway = make(net.IP, len(ip)) copy(*gateway, ip) } return nil }
c26574
discovery for the seesaw VIP works fine without policy routing // anyway. // // TODO(angusc): Figure out how whether we can get rid of this. if family == seesaw.IPv4 { ipRunAF(family, "rule del to %s", clusterVIP) ipRunAF(family, "rule del from %s", clusterVIP) if err := ipRunAF(family, "rule add from all to...
c26575
iface.Interface() if err != nil { return err } log.Infof("Bringing down LB interface %s", netIface.Name) return ifaceDown(netIface) }
c26576
!nodeNet.Contains(iface.ClusterVIP.IPv4Addr) { return fmt.Errorf("Node network %s does not contain cluster VIP %s", nodeNet, iface.ClusterVIP.IPv4Addr) } gateway, err := routeDefaultIPv4() if err != nil { return fmt.Errorf("Failed to get IPv4 default route: %v", err) } if err := ifaceUp(netIface); err != ni...
c26577
return iptablesAddRules(lbVserver.Vserver, lbVserver.Iface.ClusterVIP, lbVserver.AF) }
c26578
return iptablesDeleteRules(lbVserver.Vserver, lbVserver.Iface.ClusterVIP, lbVserver.AF) }
c26579
{ return err } return routeLocal(iface, vip.IP.IP(), vip.Iface.Node) case seesaw.AnycastVIP, seesaw.DedicatedVIP: dummyIface, err := net.InterfaceByName(vip.Iface.DummyInterface) if err != nil { return fmt.Errorf("Failed to find dummy interface: %v", err) } prefixLen := net.IPv6len * 8 if vip.IP.I...
c26580
mask := net.CIDRMask(prefixLen, prefixLen) log.Infof("Removing VIP %s from %s", vip.IP.IP(), dummyIface.Name) if err = ifaceDelIPAddr(dummyIface, vip.IP.IP(), mask); err != nil { return fmt.Errorf("Failed to delete VIP %s: %v", vip.VIP, err) } // Workaround for kernel bug(?). The route should have been ...
c26581
!= nil { return err } return ifaceAddVLAN(netIface, vlan.VLAN) }
c26582
err != nil { return err } return ifaceDelVLAN(netIface, vlan.VLAN) }
c26583
i, iface := range allIfaces { if strings.HasPrefix(iface.Name, prefix) { ifaces = append(ifaces, &allIfaces[i]) } } return ifaces, nil }
c26584
:= range ifaces { if network, _ := findNetwork(iface, ip); network != nil { return iface, network, nil } } return nil, nil, fmt.Errorf("Failed to find IP %v on any interface", ip) }
c26585
{ ipStr := addr.String() ipAddr, ipNet, err := net.ParseCIDR(ipStr) if err != nil { return nil, fmt.Errorf("Failed to parse interface address %q - %v: %v", iface.Name, ipStr, err) } if ipAddr.Equal(ip) { return ipNet, nil } } return nil, fmt.Errorf("Failed to find IP %v on interface %q", ip, iface....
c26586
shutdown: make(chan bool, 1), started: make(chan bool, 1), stopped: make(chan bool, 1), termTimeout: 5 * time.Second, } }
c26587
= strings.Fields(args) }
c26588
must be between -20 and 19", priority) } svc.priority = priority return nil }
c26589
:= strconv.Atoi(u.Gid) if err != nil { return err } svc.uid = uint32(uid) svc.gid = uint32(gid) return nil }
c26590
svc.name, svc.failures, delay) select { case <-time.After(delay): case <-svc.shutdown: goto done } } svc.restarts++ svc.lastRestart = time.Now() svc.runOnce() select { case <-time.After(restartDelay): case <-svc.shutdown: goto done } } done: svc.done <- true }
c26591
} logLink := path.Join(logDir, name+".log") os.Remove(logLink) os.Symlink(logName, logLink) fmt.Fprintf(f, "Log file for %s (stdout/stderr)\n", name) fmt.Fprintf(f, "Created at: %s\n", t.Format("2006/01/02 15:04:05")) return f, nil }
c26592
log.Warningf("Service %s - log sink failed: %v", svc.name, err) } f.Close() r.Close() }
c26593
return nil } return svc.process.Signal(sig) }
c26594
} svc.shutdown <- true svc.signal(syscall.SIGTERM) select { case <-svc.done: case <-time.After(svc.termTimeout): svc.signal(syscall.SIGKILL) <-svc.done } log.Infof("Service %s stopped", svc.name) svc.stopped <- true }
c26595
buf.Write(m.senderHardwareAddress) buf.Write(m.senderProtocolAddress) buf.Write(m.targetHardwareAddress) buf.Write(m.targetProtocolAddress) return buf.Bytes(), nil }
c26596
0x0800, // IPv4 hwLen, // 48-bit MAC Address net.IPv4len, // 32-bit IPv4 Address opARPReply, // ARP Reply }, mac, ip.To4(), ethernetBroadcast, net.IPv4bcast, } return m, nil }
c26597
iface.Index, Pkttype: 0, // syscall.PACKET_HOST Hatype: m.hardwareType, Halen: m.hardwareAddressLength, } target := ethernetBroadcast if m.opcode == opARPReply { target = m.targetHardwareAddress } for i := 0; i < len(target); i++ { ll.Addr[i] = target[i] } b, err := m.bytes() if err != nil { ...
c26598
arp.IP, iface.HardwareAddr, iface.Name) m, err := gratuitousARPReply(arp.IP, iface.HardwareAddr) if err != nil { return err } return sendARP(iface, m) }
c26599
return fmt.Sprintf("(unknown %d)", rc) }