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
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L211-L224
go
train
// CopyTo deep copies the pool data to the destination pooldata
func (p *PoolData) CopyTo(dstP *PoolData) error
// CopyTo deep copies the pool data to the destination pooldata func (p *PoolData) CopyTo(dstP *PoolData) error
{ dstP.ParentKey = p.ParentKey dstP.Pool = types.GetIPNetCopy(p.Pool) if p.Range != nil { dstP.Range = &AddressRange{} dstP.Range.Sub = types.GetIPNetCopy(p.Range.Sub) dstP.Range.Start = p.Range.Start dstP.Range.End = p.Range.End } dstP.RefCount = p.RefCount return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L261-L304
go
train
// updatePoolDBOnAdd returns a closure which will add the subnet k to the address space when executed.
func (aSpace *addrSpace) updatePoolDBOnAdd(k SubnetKey, nw *net.IPNet, ipr *AddressRange, pdf bool) (func() error, error)
// updatePoolDBOnAdd returns a closure which will add the subnet k to the address space when executed. func (aSpace *addrSpace) updatePoolDBOnAdd(k SubnetKey, nw *net.IPNet, ipr *AddressRange, pdf bool) (func() error, error)
{ aSpace.Lock() defer aSpace.Unlock() // Check if already allocated if _, ok := aSpace.subnets[k]; ok { if pdf { return nil, types.InternalMaskableErrorf("predefined pool %s is already reserved", nw) } // This means the same pool is already allocated. updatePoolDBOnAdd is called when there // is request for a pool/subpool. It should ensure there is no overlap with existing pools return nil, ipamapi.ErrPoolOverlap } // If master pool, check for overlap if ipr == nil { if aSpace.contains(k.AddressSpace, nw) { return nil, ipamapi.ErrPoolOverlap } // This is a new master pool, add it along with corresponding bitmask aSpace.subnets[k] = &PoolData{Pool: nw, RefCount: 1} return func() error { return aSpace.alloc.insertBitMask(k, nw) }, nil } // This is a new non-master pool (subPool) p := &PoolData{ ParentKey: SubnetKey{AddressSpace: k.AddressSpace, Subnet: k.Subnet}, Pool: nw, Range: ipr, RefCount: 1, } aSpace.subnets[k] = p // Look for parent pool pp, ok := aSpace.subnets[p.ParentKey] if ok { aSpace.incRefCount(pp, 1) return func() error { return nil }, nil } // Parent pool does not exist, add it along with corresponding bitmask aSpace.subnets[p.ParentKey] = &PoolData{Pool: nw, RefCount: 1} return func() error { return aSpace.alloc.insertBitMask(p.ParentKey, nw) }, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipam/structures.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L348-L357
go
train
// Checks whether the passed subnet is a superset or subset of any of the subset in this config db
func (aSpace *addrSpace) contains(space string, nw *net.IPNet) bool
// Checks whether the passed subnet is a superset or subset of any of the subset in this config db func (aSpace *addrSpace) contains(space string, nw *net.IPNet) bool
{ for k, v := range aSpace.subnets { if space == k.AddressSpace && k.ChildSubnet == "" { if nw.Contains(v.Pool.IP) || v.Pool.Contains(nw.IP) { return true } } } return false }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
cmd/proxy/stub_proxy.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/cmd/proxy/stub_proxy.go#L26-L31
go
train
// NewStubProxy creates a new StubProxy
func NewStubProxy(frontendAddr, backendAddr net.Addr) (Proxy, error)
// NewStubProxy creates a new StubProxy func NewStubProxy(frontendAddr, backendAddr net.Addr) (Proxy, error)
{ return &StubProxy{ frontendAddr: frontendAddr, backendAddr: backendAddr, }, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
netutils/utils_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netutils/utils_linux.go#L25-L39
go
train
// CheckRouteOverlaps checks whether the passed network overlaps with any existing routes
func CheckRouteOverlaps(toCheck *net.IPNet) error
// CheckRouteOverlaps checks whether the passed network overlaps with any existing routes func CheckRouteOverlaps(toCheck *net.IPNet) error
{ if networkGetRoutesFct == nil { networkGetRoutesFct = ns.NlHandle().RouteList } networks, err := networkGetRoutesFct(nil, netlink.FAMILY_V4) if err != nil { return err } for _, network := range networks { if network.Dst != nil && NetworkOverlaps(toCheck, network.Dst) { return ErrNetworkOverlaps } } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
netutils/utils_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netutils/utils_linux.go#L44-L63
go
train
// GenerateIfaceName returns an interface name using the passed in // prefix and the length of random bytes. The api ensures that the // there are is no interface which exists with that name.
func GenerateIfaceName(nlh *netlink.Handle, prefix string, len int) (string, error)
// GenerateIfaceName returns an interface name using the passed in // prefix and the length of random bytes. The api ensures that the // there are is no interface which exists with that name. func GenerateIfaceName(nlh *netlink.Handle, prefix string, len int) (string, error)
{ linkByName := netlink.LinkByName if nlh != nil { linkByName = nlh.LinkByName } for i := 0; i < 3; i++ { name, err := GenerateRandomName(prefix, len) if err != nil { continue } _, err = linkByName(name) if err != nil { if strings.Contains(err.Error(), "not found") { return name, nil } return "", err } } return "", types.InternalErrorf("could not generate interface name") }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
netutils/utils_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netutils/utils_linux.go#L71-L108
go
train
// ElectInterfaceAddresses looks for an interface on the OS with the // specified name and returns returns all its IPv4 and IPv6 addresses in CIDR notation. // If a failure in retrieving the addresses or no IPv4 address is found, an error is returned. // If the interface does not exist, it chooses from a predefined // list the first IPv4 address which does not conflict with other // interfaces on the system.
func ElectInterfaceAddresses(name string) ([]*net.IPNet, []*net.IPNet, error)
// ElectInterfaceAddresses looks for an interface on the OS with the // specified name and returns returns all its IPv4 and IPv6 addresses in CIDR notation. // If a failure in retrieving the addresses or no IPv4 address is found, an error is returned. // If the interface does not exist, it chooses from a predefined // list the first IPv4 address which does not conflict with other // interfaces on the system. func ElectInterfaceAddresses(name string) ([]*net.IPNet, []*net.IPNet, error)
{ var ( v4Nets []*net.IPNet v6Nets []*net.IPNet ) defer osl.InitOSContext()() link, _ := ns.NlHandle().LinkByName(name) if link != nil { v4addr, err := ns.NlHandle().AddrList(link, netlink.FAMILY_V4) if err != nil { return nil, nil, err } v6addr, err := ns.NlHandle().AddrList(link, netlink.FAMILY_V6) if err != nil { return nil, nil, err } for _, nlAddr := range v4addr { v4Nets = append(v4Nets, nlAddr.IPNet) } for _, nlAddr := range v6addr { v6Nets = append(v6Nets, nlAddr.IPNet) } } if link == nil || len(v4Nets) == 0 { // Choose from predefined local scope networks v4Net, err := FindAvailableNetwork(ipamutils.PredefinedLocalScopeDefaultNetworks) if err != nil { return nil, nil, errors.Wrapf(err, "PredefinedLocalScopeDefaultNetworks List: %+v", ipamutils.PredefinedLocalScopeDefaultNetworks) } v4Nets = append(v4Nets, v4Net) } return v4Nets, v6Nets, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
netutils/utils_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netutils/utils_linux.go#L112-L128
go
train
// FindAvailableNetwork returns a network from the passed list which does not // overlap with existing interfaces in the system
func FindAvailableNetwork(list []*net.IPNet) (*net.IPNet, error)
// FindAvailableNetwork returns a network from the passed list which does not // overlap with existing interfaces in the system func FindAvailableNetwork(list []*net.IPNet) (*net.IPNet, error)
{ // We don't check for an error here, because we don't really care if we // can't read /etc/resolv.conf. So instead we skip the append if resolvConf // is nil. It either doesn't exist, or we can't read it for some reason. var nameservers []string if rc, err := resolvconf.Get(); err == nil { nameservers = resolvconf.GetNameserversAsCIDR(rc.Content) } for _, nw := range list { if err := CheckNameserverOverlaps(nameservers, nw); err == nil { if err := CheckRouteOverlaps(nw); err == nil { return nw, nil } } } return nil, fmt.Errorf("no available network") }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/namespace_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/namespace_linux.go#L138-L154
go
train
// GC triggers garbage collection of namespace path right away // and waits for it.
func GC()
// GC triggers garbage collection of namespace path right away // and waits for it. func GC()
{ gpmLock.Lock() if len(garbagePathMap) == 0 { // No need for GC if map is empty gpmLock.Unlock() return } gpmLock.Unlock() // if content exists in the garbage paths // we can trigger GC to run, providing a // channel to be notified on completion waitGC := make(chan struct{}) gpmChan <- waitGC // wait for GC completion <-waitGC }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/namespace_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/namespace_linux.go#L158-L198
go
train
// GenerateKey generates a sandbox key based on the passed // container id.
func GenerateKey(containerID string) string
// GenerateKey generates a sandbox key based on the passed // container id. func GenerateKey(containerID string) string
{ maxLen := 12 // Read sandbox key from host for overlay if strings.HasPrefix(containerID, "-") { var ( index int indexStr string tmpkey string ) dir, err := ioutil.ReadDir(basePath()) if err != nil { return "" } for _, v := range dir { id := v.Name() if strings.HasSuffix(id, containerID[:maxLen-1]) { indexStr = strings.TrimSuffix(id, containerID[:maxLen-1]) tmpindex, err := strconv.Atoi(indexStr) if err != nil { return "" } if tmpindex > index { index = tmpindex tmpkey = id } } } containerID = tmpkey if containerID == "" { return "" } } if len(containerID) < maxLen { maxLen = len(containerID) } return basePath() + "/" + containerID[:maxLen] }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/namespace_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/namespace_linux.go#L202-L246
go
train
// NewSandbox provides a new sandbox instance created in an os specific way // provided a key which uniquely identifies the sandbox
func NewSandbox(key string, osCreate, isRestore bool) (Sandbox, error)
// NewSandbox provides a new sandbox instance created in an os specific way // provided a key which uniquely identifies the sandbox func NewSandbox(key string, osCreate, isRestore bool) (Sandbox, error)
{ if !isRestore { err := createNetworkNamespace(key, osCreate) if err != nil { return nil, err } } else { once.Do(createBasePath) } n := &networkNamespace{path: key, isDefault: !osCreate, nextIfIndex: make(map[string]int)} sboxNs, err := netns.GetFromPath(n.path) if err != nil { return nil, fmt.Errorf("failed get network namespace %q: %v", n.path, err) } defer sboxNs.Close() n.nlHandle, err = netlink.NewHandleAt(sboxNs, syscall.NETLINK_ROUTE) if err != nil { return nil, fmt.Errorf("failed to create a netlink handle: %v", err) } err = n.nlHandle.SetSocketTimeout(ns.NetlinkSocketsTimeout) if err != nil { logrus.Warnf("Failed to set the timeout on the sandbox netlink handle sockets: %v", err) } // In live-restore mode, IPV6 entries are getting cleaned up due to below code // We should retain IPV6 configurations in live-restore mode when Docker Daemon // comes back. It should work as it is on other cases // As starting point, disable IPv6 on all interfaces if !isRestore && !n.isDefault { err = setIPv6(n.path, "all", false) if err != nil { logrus.Warnf("Failed to disable IPv6 on all interfaces on network namespace %q: %v", n.path, err) } } if err = n.loopbackUp(); err != nil { n.nlHandle.Delete() return nil, err } return n, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/namespace_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/namespace_linux.go#L261-L299
go
train
// GetSandboxForExternalKey returns sandbox object for the supplied path
func GetSandboxForExternalKey(basePath string, key string) (Sandbox, error)
// GetSandboxForExternalKey returns sandbox object for the supplied path func GetSandboxForExternalKey(basePath string, key string) (Sandbox, error)
{ if err := createNamespaceFile(key); err != nil { return nil, err } if err := mountNetworkNamespace(basePath, key); err != nil { return nil, err } n := &networkNamespace{path: key, nextIfIndex: make(map[string]int)} sboxNs, err := netns.GetFromPath(n.path) if err != nil { return nil, fmt.Errorf("failed get network namespace %q: %v", n.path, err) } defer sboxNs.Close() n.nlHandle, err = netlink.NewHandleAt(sboxNs, syscall.NETLINK_ROUTE) if err != nil { return nil, fmt.Errorf("failed to create a netlink handle: %v", err) } err = n.nlHandle.SetSocketTimeout(ns.NetlinkSocketsTimeout) if err != nil { logrus.Warnf("Failed to set the timeout on the sandbox netlink handle sockets: %v", err) } // As starting point, disable IPv6 on all interfaces err = setIPv6(n.path, "all", false) if err != nil { logrus.Warnf("Failed to disable IPv6 on all interfaces on network namespace %q: %v", n.path, err) } if err = n.loopbackUp(); err != nil { n.nlHandle.Delete() return nil, err } return n, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/namespace_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/namespace_linux.go#L425-L431
go
train
// InitOSContext initializes OS context while configuring network resources
func InitOSContext() func()
// InitOSContext initializes OS context while configuring network resources func InitOSContext() func()
{ runtime.LockOSThread() if err := ns.SetNamespace(); err != nil { logrus.Error(err) } return runtime.UnlockOSThread }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/namespace_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/namespace_linux.go#L488-L587
go
train
// Restore restore the network namespace
func (n *networkNamespace) Restore(ifsopt map[string][]IfaceOption, routes []*types.StaticRoute, gw net.IP, gw6 net.IP) error
// Restore restore the network namespace func (n *networkNamespace) Restore(ifsopt map[string][]IfaceOption, routes []*types.StaticRoute, gw net.IP, gw6 net.IP) error
{ // restore interfaces for name, opts := range ifsopt { if !strings.Contains(name, "+") { return fmt.Errorf("wrong iface name in restore osl sandbox interface: %s", name) } seps := strings.Split(name, "+") srcName := seps[0] dstPrefix := seps[1] i := &nwIface{srcName: srcName, dstName: dstPrefix, ns: n} i.processInterfaceOptions(opts...) if i.master != "" { i.dstMaster = n.findDst(i.master, true) if i.dstMaster == "" { return fmt.Errorf("could not find an appropriate master %q for %q", i.master, i.srcName) } } if n.isDefault { i.dstName = i.srcName } else { links, err := n.nlHandle.LinkList() if err != nil { return fmt.Errorf("failed to retrieve list of links in network namespace %q during restore", n.path) } // due to the docker network connect/disconnect, so the dstName should // restore from the namespace for _, link := range links { addrs, err := n.nlHandle.AddrList(link, netlink.FAMILY_V4) if err != nil { return err } ifaceName := link.Attrs().Name if strings.HasPrefix(ifaceName, "vxlan") { if i.dstName == "vxlan" { i.dstName = ifaceName break } } // find the interface name by ip if i.address != nil { for _, addr := range addrs { if addr.IPNet.String() == i.address.String() { i.dstName = ifaceName break } continue } if i.dstName == ifaceName { break } } // This is to find the interface name of the pair in overlay sandbox if strings.HasPrefix(ifaceName, "veth") { if i.master != "" && i.dstName == "veth" { i.dstName = ifaceName } } } var index int indexStr := strings.TrimPrefix(i.dstName, dstPrefix) if indexStr != "" { index, err = strconv.Atoi(indexStr) if err != nil { return err } } index++ n.Lock() if index > n.nextIfIndex[dstPrefix] { n.nextIfIndex[dstPrefix] = index } n.iFaces = append(n.iFaces, i) n.Unlock() } } // restore routes for _, r := range routes { n.Lock() n.staticRoutes = append(n.staticRoutes, r) n.Unlock() } // restore gateway if len(gw) > 0 { n.Lock() n.gw = gw n.Unlock() } if len(gw6) > 0 { n.Lock() n.gwv6 = gw6 n.Unlock() } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/namespace_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/namespace_linux.go#L590-L615
go
train
// Checks whether IPv6 needs to be enabled/disabled on the loopback interface
func (n *networkNamespace) checkLoV6()
// Checks whether IPv6 needs to be enabled/disabled on the loopback interface func (n *networkNamespace) checkLoV6()
{ var ( enable = false action = "disable" ) n.Lock() for _, iface := range n.iFaces { if iface.AddressIPv6() != nil { enable = true action = "enable" break } } n.Unlock() if n.loV6Enabled == enable { return } if err := setIPv6(n.path, "lo", enable); err != nil { logrus.Warnf("Failed to %s IPv6 on loopback interface on network namespace %q: %v", action, n.path, err) } n.loV6Enabled = enable }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/namespace_linux.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/namespace_linux.go#L680-L687
go
train
// ApplyOSTweaks applies linux configs on the sandbox
func (n *networkNamespace) ApplyOSTweaks(types []SandboxType)
// ApplyOSTweaks applies linux configs on the sandbox func (n *networkNamespace) ApplyOSTweaks(types []SandboxType)
{ for _, t := range types { switch t { case SandboxTypeLoadBalancer: kernel.ApplyOSTweaks(loadBalancerConfig) } } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
networkdb/watch.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/networkdb/watch.go#L46-L90
go
train
// Watch creates a watcher with filters for a particular table or // network or key or any combination of the tuple. If any of the // filter is an empty string it acts as a wildcard for that // field. Watch returns a channel of events, where the events will be // sent.
func (nDB *NetworkDB) Watch(tname, nid, key string) (*events.Channel, func())
// Watch creates a watcher with filters for a particular table or // network or key or any combination of the tuple. If any of the // filter is an empty string it acts as a wildcard for that // field. Watch returns a channel of events, where the events will be // sent. func (nDB *NetworkDB) Watch(tname, nid, key string) (*events.Channel, func())
{ var matcher events.Matcher if tname != "" || nid != "" || key != "" { matcher = events.MatcherFunc(func(ev events.Event) bool { var evt event switch ev := ev.(type) { case CreateEvent: evt = event(ev) case UpdateEvent: evt = event(ev) case DeleteEvent: evt = event(ev) } if tname != "" && evt.Table != tname { return false } if nid != "" && evt.NetworkID != nid { return false } if key != "" && evt.Key != key { return false } return true }) } ch := events.NewChannel(0) sink := events.Sink(events.NewQueue(ch)) if matcher != nil { sink = events.NewFilter(sink, matcher) } nDB.broadcaster.Add(sink) return ch, func() { nDB.broadcaster.Remove(sink) ch.Close() sink.Close() } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/overlay/encryption.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/encryption.go#L448-L509
go
train
// updateKeys allows to add a new key and/or change the primary key and/or prune an existing key // The primary key is the key used in transmission and will go in first position in the list.
func (d *driver) updateKeys(newKey, primary, pruneKey *key) error
// updateKeys allows to add a new key and/or change the primary key and/or prune an existing key // The primary key is the key used in transmission and will go in first position in the list. func (d *driver) updateKeys(newKey, primary, pruneKey *key) error
{ logrus.Debugf("Updating Keys. New: %v, Primary: %v, Pruned: %v", newKey, primary, pruneKey) logrus.Debugf("Current: %v", d.keys) var ( newIdx = -1 priIdx = -1 delIdx = -1 lIP = net.ParseIP(d.bindAddress) aIP = net.ParseIP(d.advertiseAddress) ) d.Lock() defer d.Unlock() // add new if newKey != nil { d.keys = append(d.keys, newKey) newIdx += len(d.keys) } for i, k := range d.keys { if primary != nil && k.tag == primary.tag { priIdx = i } if pruneKey != nil && k.tag == pruneKey.tag { delIdx = i } } if (newKey != nil && newIdx == -1) || (primary != nil && priIdx == -1) || (pruneKey != nil && delIdx == -1) { return types.BadRequestErrorf("cannot find proper key indices while processing key update:"+ "(newIdx,priIdx,delIdx):(%d, %d, %d)", newIdx, priIdx, delIdx) } if priIdx != -1 && priIdx == delIdx { return types.BadRequestErrorf("attempting to both make a key (index %d) primary and delete it", priIdx) } d.secMapWalk(func(rIPs string, spis []*spi) ([]*spi, bool) { rIP := net.ParseIP(rIPs) return updateNodeKey(lIP, aIP, rIP, spis, d.keys, newIdx, priIdx, delIdx), false }) // swap primary if priIdx != -1 { d.keys[0], d.keys[priIdx] = d.keys[priIdx], d.keys[0] } // prune if delIdx != -1 { if delIdx == 0 { delIdx = priIdx } d.keys = append(d.keys[:delIdx], d.keys[delIdx+1:]...) } logrus.Debugf("Updated: %v", d.keys) return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/overlay/encryption.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/encryption.go#L518-L595
go
train
/******************************************************** * Steady state: rSA0, rSA1, rSA2, fSA1, fSP1 * Rotation --> -rSA0, +rSA3, +fSA2, +fSP2/-fSP1, -fSA1 * Steady state: rSA1, rSA2, rSA3, fSA2, fSP2 *********************************************************/ // Spis and keys are sorted in such away the one in position 0 is the primary
func updateNodeKey(lIP, aIP, rIP net.IP, idxs []*spi, curKeys []*key, newIdx, priIdx, delIdx int) []*spi
/******************************************************** * Steady state: rSA0, rSA1, rSA2, fSA1, fSP1 * Rotation --> -rSA0, +rSA3, +fSA2, +fSP2/-fSP1, -fSA1 * Steady state: rSA1, rSA2, rSA3, fSA2, fSP2 *********************************************************/ // Spis and keys are sorted in such away the one in position 0 is the primary func updateNodeKey(lIP, aIP, rIP net.IP, idxs []*spi, curKeys []*key, newIdx, priIdx, delIdx int) []*spi
{ logrus.Debugf("Updating keys for node: %s (%d,%d,%d)", rIP, newIdx, priIdx, delIdx) spis := idxs logrus.Debugf("Current: %v", spis) // add new if newIdx != -1 { spis = append(spis, &spi{ forward: buildSPI(aIP, rIP, curKeys[newIdx].tag), reverse: buildSPI(rIP, aIP, curKeys[newIdx].tag), }) } if delIdx != -1 { // -rSA0 programSA(lIP, rIP, spis[delIdx], nil, reverse, false) } if newIdx > -1 { // +rSA2 programSA(lIP, rIP, spis[newIdx], curKeys[newIdx], reverse, true) } if priIdx > 0 { // +fSA2 fSA2, _, _ := programSA(lIP, rIP, spis[priIdx], curKeys[priIdx], forward, true) // +fSP2, -fSP1 s := types.GetMinimalIP(fSA2.Src) d := types.GetMinimalIP(fSA2.Dst) fullMask := net.CIDRMask(8*len(s), 8*len(s)) fSP1 := &netlink.XfrmPolicy{ Src: &net.IPNet{IP: s, Mask: fullMask}, Dst: &net.IPNet{IP: d, Mask: fullMask}, Dir: netlink.XFRM_DIR_OUT, Proto: 17, DstPort: 4789, Mark: &spMark, Tmpls: []netlink.XfrmPolicyTmpl{ { Src: fSA2.Src, Dst: fSA2.Dst, Proto: netlink.XFRM_PROTO_ESP, Mode: netlink.XFRM_MODE_TRANSPORT, Spi: fSA2.Spi, Reqid: r, }, }, } logrus.Debugf("Updating fSP{%s}", fSP1) if err := ns.NlHandle().XfrmPolicyUpdate(fSP1); err != nil { logrus.Warnf("Failed to update fSP{%s}: %v", fSP1, err) } // -fSA1 programSA(lIP, rIP, spis[0], nil, forward, false) } // swap if priIdx > 0 { swp := spis[0] spis[0] = spis[priIdx] spis[priIdx] = swp } // prune if delIdx != -1 { if delIdx == 0 { delIdx = priIdx } spis = append(spis[:delIdx], spis[delIdx+1:]...) } logrus.Debugf("Updated: %v", spis) return spis }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
cmd/proxy/tcp_proxy.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/cmd/proxy/tcp_proxy.go#L19-L31
go
train
// NewTCPProxy creates a new TCPProxy.
func NewTCPProxy(frontendAddr, backendAddr *net.TCPAddr) (*TCPProxy, error)
// NewTCPProxy creates a new TCPProxy. func NewTCPProxy(frontendAddr, backendAddr *net.TCPAddr) (*TCPProxy, error)
{ listener, err := net.ListenTCP("tcp", frontendAddr) if err != nil { return nil, err } // If the port in frontendAddr was 0 then ListenTCP will have a picked // a port to listen on, hence the call to Addr to get that actual port: return &TCPProxy{ listener: listener, frontendAddr: listener.Addr().(*net.TCPAddr), backendAddr: backendAddr, }, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
cmd/proxy/tcp_proxy.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/cmd/proxy/tcp_proxy.go#L69-L80
go
train
// Run starts forwarding the traffic using TCP.
func (proxy *TCPProxy) Run()
// Run starts forwarding the traffic using TCP. func (proxy *TCPProxy) Run()
{ quit := make(chan bool) defer close(quit) for { client, err := proxy.listener.Accept() if err != nil { log.Printf("Stopping proxy on tcp/%v for tcp/%v (%s)", proxy.frontendAddr, proxy.backendAddr, err) return } go proxy.clientLoop(client.(*net.TCPConn), quit) } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
bitseq/store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/store.go#L12-L16
go
train
// Key provides the Key to be used in KV Store
func (h *Handle) Key() []string
// Key provides the Key to be used in KV Store func (h *Handle) Key() []string
{ h.Lock() defer h.Unlock() return []string{h.app, h.id} }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
bitseq/store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/store.go#L19-L23
go
train
// KeyPrefix returns the immediate parent key that can be used for tree walk
func (h *Handle) KeyPrefix() []string
// KeyPrefix returns the immediate parent key that can be used for tree walk func (h *Handle) KeyPrefix() []string
{ h.Lock() defer h.Unlock() return []string{h.app} }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
bitseq/store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/store.go#L26-L32
go
train
// Value marshals the data to be stored in the KV store
func (h *Handle) Value() []byte
// Value marshals the data to be stored in the KV store func (h *Handle) Value() []byte
{ b, err := json.Marshal(h) if err != nil { return nil } return b }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
bitseq/store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/store.go#L35-L37
go
train
// SetValue unmarshals the data from the KV store
func (h *Handle) SetValue(value []byte) error
// SetValue unmarshals the data from the KV store func (h *Handle) SetValue(value []byte) error
{ return json.Unmarshal(value, h) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
bitseq/store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/store.go#L40-L44
go
train
// Index returns the latest DB Index as seen by this object
func (h *Handle) Index() uint64
// Index returns the latest DB Index as seen by this object func (h *Handle) Index() uint64
{ h.Lock() defer h.Unlock() return h.dbIndex }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
bitseq/store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/store.go#L47-L52
go
train
// SetIndex method allows the datastore to store the latest DB Index into this object
func (h *Handle) SetIndex(index uint64)
// SetIndex method allows the datastore to store the latest DB Index into this object func (h *Handle) SetIndex(index uint64)
{ h.Lock() h.dbIndex = index h.dbExists = true h.Unlock() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
bitseq/store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/store.go#L55-L59
go
train
// Exists method is true if this object has been stored in the DB.
func (h *Handle) Exists() bool
// Exists method is true if this object has been stored in the DB. func (h *Handle) Exists() bool
{ h.Lock() defer h.Unlock() return h.dbExists }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
bitseq/store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/store.go#L62-L70
go
train
// New method returns a handle based on the receiver handle
func (h *Handle) New() datastore.KVObject
// New method returns a handle based on the receiver handle func (h *Handle) New() datastore.KVObject
{ h.Lock() defer h.Unlock() return &Handle{ app: h.app, store: h.store, } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
bitseq/store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/store.go#L73-L94
go
train
// CopyTo deep copies the handle into the passed destination object
func (h *Handle) CopyTo(o datastore.KVObject) error
// CopyTo deep copies the handle into the passed destination object func (h *Handle) CopyTo(o datastore.KVObject) error
{ h.Lock() defer h.Unlock() dstH := o.(*Handle) if h == dstH { return nil } dstH.Lock() dstH.bits = h.bits dstH.unselected = h.unselected dstH.head = h.head.getCopy() dstH.app = h.app dstH.id = h.id dstH.dbIndex = h.dbIndex dstH.dbExists = h.dbExists dstH.store = h.store dstH.curr = h.curr dstH.Unlock() return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
bitseq/store.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/bitseq/store.go#L102-L107
go
train
// DataScope method returns the storage scope of the datastore
func (h *Handle) DataScope() string
// DataScope method returns the storage scope of the datastore func (h *Handle) DataScope() string
{ h.Lock() defer h.Unlock() return h.store.Scope() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_setup.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_setup.go#L20-L49
go
train
// createIPVlan Create the ipvlan slave specifying the source name
func createIPVlan(containerIfName, parent, ipvlanMode string) (string, error)
// createIPVlan Create the ipvlan slave specifying the source name func createIPVlan(containerIfName, parent, ipvlanMode string) (string, error)
{ // Set the ipvlan mode. Default is bridge mode mode, err := setIPVlanMode(ipvlanMode) if err != nil { return "", fmt.Errorf("Unsupported %s ipvlan mode: %v", ipvlanMode, err) } // verify the Docker host interface acting as the macvlan parent iface exists if !parentExists(parent) { return "", fmt.Errorf("the requested parent interface %s was not found on the Docker host", parent) } // Get the link for the master index (Example: the docker host eth iface) parentLink, err := ns.NlHandle().LinkByName(parent) if err != nil { return "", fmt.Errorf("error occurred looking up the %s parent iface %s error: %s", ipvlanType, parent, err) } // Create an ipvlan link ipvlan := &netlink.IPVlan{ LinkAttrs: netlink.LinkAttrs{ Name: containerIfName, ParentIndex: parentLink.Attrs().Index, }, Mode: mode, } if err := ns.NlHandle().LinkAdd(ipvlan); err != nil { // If a user creates a macvlan and ipvlan on same parent, only one slave iface can be active at a time. return "", fmt.Errorf("failed to create the %s port: %v", ipvlanType, err) } return ipvlan.Attrs().Name, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_setup.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_setup.go#L52-L61
go
train
// setIPVlanMode setter for one of the two ipvlan port types
func setIPVlanMode(mode string) (netlink.IPVlanMode, error)
// setIPVlanMode setter for one of the two ipvlan port types func setIPVlanMode(mode string) (netlink.IPVlanMode, error)
{ switch mode { case modeL2: return netlink.IPVLAN_MODE_L2, nil case modeL3: return netlink.IPVLAN_MODE_L3, nil default: return 0, fmt.Errorf("Unknown ipvlan mode: %s", mode) } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_setup.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_setup.go#L64-L71
go
train
// parentExists check if the specified interface exists in the default namespace
func parentExists(ifaceStr string) bool
// parentExists check if the specified interface exists in the default namespace func parentExists(ifaceStr string) bool
{ _, err := ns.NlHandle().LinkByName(ifaceStr) if err != nil { return false } return true }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_setup.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_setup.go#L74-L109
go
train
// createVlanLink parses sub-interfaces and vlan id for creation
func createVlanLink(parentName string) error
// createVlanLink parses sub-interfaces and vlan id for creation func createVlanLink(parentName string) error
{ if strings.Contains(parentName, ".") { parent, vidInt, err := parseVlan(parentName) if err != nil { return err } // VLAN identifier or VID is a 12-bit field specifying the VLAN to which the frame belongs if vidInt > 4094 || vidInt < 1 { return fmt.Errorf("vlan id must be between 1-4094, received: %d", vidInt) } // get the parent link to attach a vlan subinterface parentLink, err := ns.NlHandle().LinkByName(parent) if err != nil { return fmt.Errorf("failed to find master interface %s on the Docker host: %v", parent, err) } vlanLink := &netlink.Vlan{ LinkAttrs: netlink.LinkAttrs{ Name: parentName, ParentIndex: parentLink.Attrs().Index, }, VlanId: vidInt, } // create the subinterface if err := ns.NlHandle().LinkAdd(vlanLink); err != nil { return fmt.Errorf("failed to create %s vlan link: %v", vlanLink.Name, err) } // Bring the new netlink iface up if err := ns.NlHandle().LinkSetUp(vlanLink); err != nil { return fmt.Errorf("failed to enable %s the ipvlan parent link %v", vlanLink.Name, err) } logrus.Debugf("Added a vlan tagged netlink subinterface: %s with a vlan id: %d", parentName, vidInt) return nil } return fmt.Errorf("invalid subinterface vlan name %s, example formatting is eth0.10", parentName) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_setup.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_setup.go#L139-L157
go
train
// parseVlan parses and verifies a slave interface name: -o parent=eth0.10
func parseVlan(linkName string) (string, int, error)
// parseVlan parses and verifies a slave interface name: -o parent=eth0.10 func parseVlan(linkName string) (string, int, error)
{ // parse -o parent=eth0.10 splitName := strings.Split(linkName, ".") if len(splitName) != 2 { return "", 0, fmt.Errorf("required interface name format is: name.vlan_id, ex. eth0.10 for vlan 10, instead received %s", linkName) } parent, vidStr := splitName[0], splitName[1] // validate type and convert vlan id to int vidInt, err := strconv.Atoi(vidStr) if err != nil { return "", 0, fmt.Errorf("unable to parse a valid vlan id from: %s (ex. eth0.10 for vlan 10)", vidStr) } // Check if the interface exists if !parentExists(parent) { return "", 0, fmt.Errorf("-o parent interface was not found on the host: %s", parent) } return parent, vidInt, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_setup.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_setup.go#L160-L180
go
train
// createDummyLink creates a dummy0 parent link
func createDummyLink(dummyName, truncNetID string) error
// createDummyLink creates a dummy0 parent link func createDummyLink(dummyName, truncNetID string) error
{ // create a parent interface since one was not specified parent := &netlink.Dummy{ LinkAttrs: netlink.LinkAttrs{ Name: dummyName, }, } if err := ns.NlHandle().LinkAdd(parent); err != nil { return err } parentDummyLink, err := ns.NlHandle().LinkByName(dummyName) if err != nil { return fmt.Errorf("error occurred looking up the %s parent iface %s error: %s", ipvlanType, dummyName, err) } // bring the new netlink iface up if err := ns.NlHandle().LinkSetUp(parentDummyLink); err != nil { return fmt.Errorf("failed to enable %s the ipvlan parent link: %v", dummyName, err) } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_setup.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_setup.go#L183-L200
go
train
// delDummyLink deletes the link type dummy used when -o parent is not passed
func delDummyLink(linkName string) error
// delDummyLink deletes the link type dummy used when -o parent is not passed func delDummyLink(linkName string) error
{ // delete the vlan subinterface dummyLink, err := ns.NlHandle().LinkByName(linkName) if err != nil { return fmt.Errorf("failed to find link %s on the Docker host : %v", linkName, err) } // verify a parent interface is being deleted if dummyLink.Attrs().ParentIndex != 0 { return fmt.Errorf("link %s is not a parent dummy interface", linkName) } // delete the ipvlan dummy device if err := ns.NlHandle().LinkDel(dummyLink); err != nil { return fmt.Errorf("failed to delete the dummy %s link: %v", linkName, err) } logrus.Debugf("Deleted a dummy parent link: %s", linkName) return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L156-L164
go
train
// DefaultScopes returns a map of default scopes and its config for clients to use.
func DefaultScopes(dataDir string) map[string]*ScopeCfg
// DefaultScopes returns a map of default scopes and its config for clients to use. func DefaultScopes(dataDir string) map[string]*ScopeCfg
{ if dataDir != "" { defaultScopes[LocalScope].Client.Address = dataDir + "/network/files/local-kv.db" return defaultScopes } defaultScopes[LocalScope].Client.Address = defaultPrefix + "/local-kv.db" return defaultScopes }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L167-L175
go
train
// IsValid checks if the scope config has valid configuration.
func (cfg *ScopeCfg) IsValid() bool
// IsValid checks if the scope config has valid configuration. func (cfg *ScopeCfg) IsValid() bool
{ if cfg == nil || strings.TrimSpace(cfg.Client.Provider) == "" || strings.TrimSpace(cfg.Client.Address) == "" { return false } return true }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L178-L182
go
train
//Key provides convenient method to create a Key
func Key(key ...string) string
//Key provides convenient method to create a Key func Key(key ...string) string
{ keychain := append(rootChain, key...) str := strings.Join(keychain, "/") return str + "/" }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L185-L193
go
train
//ParseKey provides convenient method to unpack the key to complement the Key function
func ParseKey(key string) ([]string, error)
//ParseKey provides convenient method to unpack the key to complement the Key function func ParseKey(key string) ([]string, error)
{ chain := strings.Split(strings.Trim(key, "/"), "/") // The key must at least be equal to the rootChain in order to be considered as valid if len(chain) <= len(rootChain) || !reflect.DeepEqual(chain[0:len(rootChain)], rootChain) { return nil, types.BadRequestErrorf("invalid Key : %s", key) } return chain[len(rootChain):], nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L196-L237
go
train
// newClient used to connect to KV Store
func newClient(scope string, kv string, addr string, config *store.Config, cached bool) (DataStore, error)
// newClient used to connect to KV Store func newClient(scope string, kv string, addr string, config *store.Config, cached bool) (DataStore, error)
{ if cached && scope != LocalScope { return nil, fmt.Errorf("caching supported only for scope %s", LocalScope) } sequential := false if scope == LocalScope { sequential = true } if config == nil { config = &store.Config{} } var addrs []string if kv == string(store.BOLTDB) { // Parse file path addrs = strings.Split(addr, ",") } else { // Parse URI parts := strings.SplitN(addr, "/", 2) addrs = strings.Split(parts[0], ",") // Add the custom prefix to the root chain if len(parts) == 2 { rootChain = append([]string{parts[1]}, defaultRootChain...) } } store, err := libkv.NewStore(store.Backend(kv), addrs, config) if err != nil { return nil, err } ds := &datastore{scope: scope, store: store, active: true, watchCh: make(chan struct{}), sequential: sequential} if cached { ds.cache = newCache(ds) } return ds, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L240-L256
go
train
// NewDataStore creates a new instance of LibKV data store
func NewDataStore(scope string, cfg *ScopeCfg) (DataStore, error)
// NewDataStore creates a new instance of LibKV data store func NewDataStore(scope string, cfg *ScopeCfg) (DataStore, error)
{ if cfg == nil || cfg.Client.Provider == "" || cfg.Client.Address == "" { c, ok := defaultScopes[scope] if !ok || c.Client.Provider == "" || c.Client.Address == "" { return nil, fmt.Errorf("unexpected scope %s without configuration passed", scope) } cfg = c } var cached bool if scope == LocalScope { cached = true } return newClient(scope, cfg.Client.Provider, cfg.Client.Address, cfg.Client.Config, cached) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L259-L284
go
train
// NewDataStoreFromConfig creates a new instance of LibKV data store starting from the datastore config data
func NewDataStoreFromConfig(dsc discoverapi.DatastoreConfigData) (DataStore, error)
// NewDataStoreFromConfig creates a new instance of LibKV data store starting from the datastore config data func NewDataStoreFromConfig(dsc discoverapi.DatastoreConfigData) (DataStore, error)
{ var ( ok bool sCfgP *store.Config ) sCfgP, ok = dsc.Config.(*store.Config) if !ok && dsc.Config != nil { return nil, fmt.Errorf("cannot parse store configuration: %v", dsc.Config) } scopeCfg := &ScopeCfg{ Client: ScopeClientCfg{ Address: dsc.Address, Provider: dsc.Provider, Config: sCfgP, }, } ds, err := NewDataStore(dsc.Scope, scopeCfg) if err != nil { return nil, fmt.Errorf("failed to construct datastore client from datastore configuration %v: %v", dsc, err) } return ds, err }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L384-L433
go
train
// PutObjectAtomic adds a new Record based on an object into the datastore
func (ds *datastore) PutObjectAtomic(kvObject KVObject) error
// PutObjectAtomic adds a new Record based on an object into the datastore func (ds *datastore) PutObjectAtomic(kvObject KVObject) error
{ var ( previous *store.KVPair pair *store.KVPair err error ) if ds.sequential { ds.Lock() defer ds.Unlock() } if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") } kvObjValue := kvObject.Value() if kvObjValue == nil { return types.BadRequestErrorf("invalid KV Object with a nil Value for key %s", Key(kvObject.Key()...)) } if kvObject.Skip() { goto add_cache } if kvObject.Exists() { previous = &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()} } else { previous = nil } _, pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous, nil) if err != nil { if err == store.ErrKeyExists { return ErrKeyModified } return err } kvObject.SetIndex(pair.LastIndex) add_cache: if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. return ds.cache.add(kvObject, kvObject.Skip()) } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L436-L462
go
train
// PutObject adds a new Record based on an object into the datastore
func (ds *datastore) PutObject(kvObject KVObject) error
// PutObject adds a new Record based on an object into the datastore func (ds *datastore) PutObject(kvObject KVObject) error
{ if ds.sequential { ds.Lock() defer ds.Unlock() } if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") } if kvObject.Skip() { goto add_cache } if err := ds.putObjectWithKey(kvObject, kvObject.Key()...); err != nil { return err } add_cache: if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. return ds.cache.add(kvObject, kvObject.Skip()) } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L474-L497
go
train
// GetObject returns a record matching the key
func (ds *datastore) GetObject(key string, o KVObject) error
// GetObject returns a record matching the key func (ds *datastore) GetObject(key string, o KVObject) error
{ if ds.sequential { ds.Lock() defer ds.Unlock() } if ds.cache != nil { return ds.cache.get(key, o) } kvPair, err := ds.store.Get(key) if err != nil { return err } if err := o.SetValue(kvPair.Value); err != nil { return err } // Make sure the object has a correct view of the DB index in // case we need to modify it and update the DB. o.SetIndex(kvPair.LastIndex) return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L586-L604
go
train
// DeleteObject unconditionally deletes a record from the store
func (ds *datastore) DeleteObject(kvObject KVObject) error
// DeleteObject unconditionally deletes a record from the store func (ds *datastore) DeleteObject(kvObject KVObject) error
{ if ds.sequential { ds.Lock() defer ds.Unlock() } // cleanup the cache first if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. ds.cache.del(kvObject, kvObject.Skip()) } if kvObject.Skip() { return nil } return ds.store.Delete(Key(kvObject.Key()...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L607-L639
go
train
// DeleteObjectAtomic performs atomic delete on a record
func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error
// DeleteObjectAtomic performs atomic delete on a record func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error
{ if ds.sequential { ds.Lock() defer ds.Unlock() } if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") } previous := &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()} if kvObject.Skip() { goto del_cache } if _, err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil { if err == store.ErrKeyExists { return ErrKeyModified } return err } del_cache: // cleanup the cache only if AtomicDelete went through successfully if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. return ds.cache.del(kvObject, kvObject.Skip()) } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
datastore/datastore.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/datastore.go#L642-L660
go
train
// DeleteTree unconditionally deletes a record from the store
func (ds *datastore) DeleteTree(kvObject KVObject) error
// DeleteTree unconditionally deletes a record from the store func (ds *datastore) DeleteTree(kvObject KVObject) error
{ if ds.sequential { ds.Lock() defer ds.Unlock() } // cleanup the cache first if ds.cache != nil { // If persistent store is skipped, sequencing needs to // happen in cache. ds.cache.del(kvObject, kvObject.Skip()) } if kvObject.Skip() { return nil } return ds.store.DeleteTree(Key(kvObject.KeyPrefix()...)) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/remote/driver.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L33-L63
go
train
// Init makes sure a remote driver is registered when a network driver // plugin is activated.
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error
// Init makes sure a remote driver is registered when a network driver // plugin is activated. func Init(dc driverapi.DriverCallback, config map[string]interface{}) error
{ newPluginHandler := func(name string, client *plugins.Client) { // negotiate driver capability with client d := newDriver(name, client) c, err := d.(*driver).getCapabilities() if err != nil { logrus.Errorf("error getting capability for %s due to %v", name, err) return } if err = dc.RegisterDriver(name, d, *c); err != nil { logrus.Errorf("error registering driver for %s due to %v", name, err) } } // Unit test code is unaware of a true PluginStore. So we fall back to v1 plugins. handleFunc := plugins.Handle if pg := dc.GetPluginGetter(); pg != nil { handleFunc = pg.Handle activePlugins := pg.GetAllManagedPluginsByCap(driverapi.NetworkPluginEndpointType) for _, ap := range activePlugins { client, err := getPluginClient(ap) if err != nil { return err } newPluginHandler(ap.Name(), client) } } handleFunc(driverapi.NetworkPluginEndpointType, newPluginHandler) return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/remote/driver.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L88-L116
go
train
// Get capability from client
func (d *driver) getCapabilities() (*driverapi.Capability, error)
// Get capability from client func (d *driver) getCapabilities() (*driverapi.Capability, error)
{ var capResp api.GetCapabilityResponse if err := d.call("GetCapabilities", nil, &capResp); err != nil { return nil, err } c := &driverapi.Capability{} switch capResp.Scope { case "global": c.DataScope = datastore.GlobalScope case "local": c.DataScope = datastore.LocalScope default: return nil, fmt.Errorf("invalid capability: expecting 'local' or 'global', got %s", capResp.Scope) } switch capResp.ConnectivityScope { case "global": c.ConnectivityScope = datastore.GlobalScope case "local": c.ConnectivityScope = datastore.LocalScope case "": c.ConnectivityScope = c.DataScope default: return nil, fmt.Errorf("invalid capability: expecting 'local' or 'global', got %s", capResp.Scope) } return c, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/remote/driver.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L260-L314
go
train
// Join method is invoked when a Sandbox is attached to an endpoint.
func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error
// Join method is invoked when a Sandbox is attached to an endpoint. func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error
{ join := &api.JoinRequest{ NetworkID: nid, EndpointID: eid, SandboxKey: sboxKey, Options: options, } var ( res api.JoinResponse err error ) if err = d.call("Join", join, &res); err != nil { return err } ifaceName := res.InterfaceName if iface := jinfo.InterfaceName(); iface != nil && ifaceName != nil { if err := iface.SetNames(ifaceName.SrcName, ifaceName.DstPrefix); err != nil { return errorWithRollback(fmt.Sprintf("failed to set interface name: %s", err), d.Leave(nid, eid)) } } var addr net.IP if res.Gateway != "" { if addr = net.ParseIP(res.Gateway); addr == nil { return fmt.Errorf(`unable to parse Gateway "%s"`, res.Gateway) } if jinfo.SetGateway(addr) != nil { return errorWithRollback(fmt.Sprintf("failed to set gateway: %v", addr), d.Leave(nid, eid)) } } if res.GatewayIPv6 != "" { if addr = net.ParseIP(res.GatewayIPv6); addr == nil { return fmt.Errorf(`unable to parse GatewayIPv6 "%s"`, res.GatewayIPv6) } if jinfo.SetGatewayIPv6(addr) != nil { return errorWithRollback(fmt.Sprintf("failed to set gateway IPv6: %v", addr), d.Leave(nid, eid)) } } if len(res.StaticRoutes) > 0 { routes, err := parseStaticRoutes(res) if err != nil { return err } for _, route := range routes { if jinfo.AddStaticRoute(route.Destination, route.RouteType, route.NextHop) != nil { return errorWithRollback(fmt.Sprintf("failed to set static route: %v", route), d.Leave(nid, eid)) } } } if res.DisableGatewayService { jinfo.DisableGatewayService() } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/remote/driver.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L317-L323
go
train
// Leave method is invoked when a Sandbox detaches from an endpoint.
func (d *driver) Leave(nid, eid string) error
// Leave method is invoked when a Sandbox detaches from an endpoint. func (d *driver) Leave(nid, eid string) error
{ leave := &api.LeaveRequest{ NetworkID: nid, EndpointID: eid, } return d.call("Leave", leave, &api.LeaveResponse{}) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/remote/driver.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L326-L338
go
train
// ProgramExternalConnectivity is invoked to program the rules to allow external connectivity for the endpoint.
func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error
// ProgramExternalConnectivity is invoked to program the rules to allow external connectivity for the endpoint. func (d *driver) ProgramExternalConnectivity(nid, eid string, options map[string]interface{}) error
{ data := &api.ProgramExternalConnectivityRequest{ NetworkID: nid, EndpointID: eid, Options: options, } err := d.call("ProgramExternalConnectivity", data, &api.ProgramExternalConnectivityResponse{}) if err != nil && plugins.IsNotFound(err) { // It is not mandatory yet to support this method return nil } return err }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/remote/driver.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L341-L352
go
train
// RevokeExternalConnectivity method is invoked to remove any external connectivity programming related to the endpoint.
func (d *driver) RevokeExternalConnectivity(nid, eid string) error
// RevokeExternalConnectivity method is invoked to remove any external connectivity programming related to the endpoint. func (d *driver) RevokeExternalConnectivity(nid, eid string) error
{ data := &api.RevokeExternalConnectivityRequest{ NetworkID: nid, EndpointID: eid, } err := d.call("RevokeExternalConnectivity", data, &api.RevokeExternalConnectivityResponse{}) if err != nil && plugins.IsNotFound(err) { // It is not mandatory yet to support this method return nil } return err }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/remote/driver.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L363-L372
go
train
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error
{ if dType != discoverapi.NodeDiscovery { return nil } notif := &api.DiscoveryNotification{ DiscoveryType: dType, DiscoveryData: data, } return d.call("DiscoverNew", notif, &api.DiscoveryResponse{}) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/remote/driver.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/remote/driver.go#L411-L436
go
train
// parseInterfaces validates all the parameters of an Interface and returns them.
func parseInterface(r api.CreateEndpointResponse) (*api.Interface, error)
// parseInterfaces validates all the parameters of an Interface and returns them. func parseInterface(r api.CreateEndpointResponse) (*api.Interface, error)
{ var outIf *api.Interface inIf := r.Interface if inIf != nil { var err error outIf = &api.Interface{} if inIf.Address != "" { if outIf.Address, err = types.ParseCIDR(inIf.Address); err != nil { return nil, err } } if inIf.AddressIPv6 != "" { if outIf.AddressIPv6, err = types.ParseCIDR(inIf.AddressIPv6); err != nil { return nil, err } } if inIf.MacAddress != "" { if outIf.MacAddress, err = net.ParseMAC(inIf.MacAddress); err != nil { return nil, err } } } return outIf, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
cmd/proxy/udp_proxy.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/cmd/proxy/udp_proxy.go#L57-L68
go
train
// NewUDPProxy creates a new UDPProxy.
func NewUDPProxy(frontendAddr, backendAddr *net.UDPAddr) (*UDPProxy, error)
// NewUDPProxy creates a new UDPProxy. func NewUDPProxy(frontendAddr, backendAddr *net.UDPAddr) (*UDPProxy, error)
{ listener, err := net.ListenUDP("udp", frontendAddr) if err != nil { return nil, err } return &UDPProxy{ listener: listener, frontendAddr: listener.LocalAddr().(*net.UDPAddr), backendAddr: backendAddr, connTrackTable: make(connTrackMap), }, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
cmd/proxy/udp_proxy.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/cmd/proxy/udp_proxy.go#L145-L152
go
train
// Close stops forwarding the traffic.
func (proxy *UDPProxy) Close()
// Close stops forwarding the traffic. func (proxy *UDPProxy) Close()
{ proxy.listener.Close() proxy.connTrackLock.Lock() defer proxy.connTrackLock.Unlock() for _, conn := range proxy.connTrackTable { conn.Close() } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/sandbox_freebsd.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/sandbox_freebsd.go#L7-L14
go
train
// GenerateKey generates a sandbox key based on the passed // container id.
func GenerateKey(containerID string) string
// GenerateKey generates a sandbox key based on the passed // container id. func GenerateKey(containerID string) string
{ maxLen := 12 if len(containerID) < maxLen { maxLen = len(containerID) } return containerID[:maxLen] }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
osl/sandbox_freebsd.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/sandbox_freebsd.go#L18-L20
go
train
// NewSandbox provides a new sandbox instance created in an os specific way // provided a key which uniquely identifies the sandbox
func NewSandbox(key string, osCreate, isRestore bool) (Sandbox, error)
// NewSandbox provides a new sandbox instance created in an os specific way // provided a key which uniquely identifies the sandbox func NewSandbox(key string, osCreate, isRestore bool) (Sandbox, error)
{ return nil, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
agent.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/agent.go#L241-L259
go
train
// For a given subsystem getKeys sorts the keys by lamport time and returns // slice of keys and lamport time which can used as a unique tag for the keys
func (c *controller) getKeys(subsys string) ([][]byte, []uint64)
// For a given subsystem getKeys sorts the keys by lamport time and returns // slice of keys and lamport time which can used as a unique tag for the keys func (c *controller) getKeys(subsys string) ([][]byte, []uint64)
{ c.Lock() defer c.Unlock() sort.Sort(ByTime(c.keys)) keys := [][]byte{} tags := []uint64{} for _, key := range c.keys { if key.Subsystem == subsys { keys = append(keys, key.Key) tags = append(tags, key.LamportTime) } } keys[0], keys[1] = keys[1], keys[0] tags[0], tags[1] = tags[1], tags[0] return keys, tags }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
agent.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/agent.go#L263-L274
go
train
// getPrimaryKeyTag returns the primary key for a given subsystem from the // list of sorted key and the associated tag
func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error)
// getPrimaryKeyTag returns the primary key for a given subsystem from the // list of sorted key and the associated tag func (c *controller) getPrimaryKeyTag(subsys string) ([]byte, uint64, error)
{ c.Lock() defer c.Unlock() sort.Sort(ByTime(c.keys)) keys := []*types.EncryptionKey{} for _, key := range c.keys { if key.Subsystem == subsys { keys = append(keys, key) } } return keys[1].Key, keys[1].LamportTime, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_joinleave.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_joinleave.go#L27-L124
go
train
// Join method is invoked when a Sandbox is attached to an endpoint.
func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error
// Join method is invoked when a Sandbox is attached to an endpoint. func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error
{ defer osl.InitOSContext()() n, err := d.getNetwork(nid) if err != nil { return err } endpoint := n.endpoint(eid) if endpoint == nil { return fmt.Errorf("could not find endpoint with id %s", eid) } // generate a name for the iface that will be renamed to eth0 in the sbox containerIfName, err := netutils.GenerateIfaceName(ns.NlHandle(), vethPrefix, vethLen) if err != nil { return fmt.Errorf("error generating an interface name: %v", err) } // create the netlink ipvlan interface vethName, err := createIPVlan(containerIfName, n.config.Parent, n.config.IpvlanMode) if err != nil { return err } // bind the generated iface name to the endpoint endpoint.srcName = vethName ep := n.endpoint(eid) if ep == nil { return fmt.Errorf("could not find endpoint with id %s", eid) } if n.config.IpvlanMode == modeL3 { // disable gateway services to add a default gw using dev eth0 only jinfo.DisableGatewayService() defaultRoute, err := ifaceGateway(defaultV4RouteCidr) if err != nil { return err } if err := jinfo.AddStaticRoute(defaultRoute.Destination, defaultRoute.RouteType, defaultRoute.NextHop); err != nil { return fmt.Errorf("failed to set an ipvlan l3 mode ipv4 default gateway: %v", err) } logrus.Debugf("Ipvlan Endpoint Joined with IPv4_Addr: %s, Ipvlan_Mode: %s, Parent: %s", ep.addr.IP.String(), n.config.IpvlanMode, n.config.Parent) // If the endpoint has a v6 address, set a v6 default route if ep.addrv6 != nil { default6Route, err := ifaceGateway(defaultV6RouteCidr) if err != nil { return err } if err = jinfo.AddStaticRoute(default6Route.Destination, default6Route.RouteType, default6Route.NextHop); err != nil { return fmt.Errorf("failed to set an ipvlan l3 mode ipv6 default gateway: %v", err) } logrus.Debugf("Ipvlan Endpoint Joined with IPv6_Addr: %s, Ipvlan_Mode: %s, Parent: %s", ep.addrv6.IP.String(), n.config.IpvlanMode, n.config.Parent) } } if n.config.IpvlanMode == modeL2 { // parse and correlate the endpoint v4 address with the available v4 subnets if len(n.config.Ipv4Subnets) > 0 { s := n.getSubnetforIPv4(ep.addr) if s == nil { return fmt.Errorf("could not find a valid ipv4 subnet for endpoint %s", eid) } v4gw, _, err := net.ParseCIDR(s.GwIP) if err != nil { return fmt.Errorf("gateway %s is not a valid ipv4 address: %v", s.GwIP, err) } err = jinfo.SetGateway(v4gw) if err != nil { return err } logrus.Debugf("Ipvlan Endpoint Joined with IPv4_Addr: %s, Gateway: %s, Ipvlan_Mode: %s, Parent: %s", ep.addr.IP.String(), v4gw.String(), n.config.IpvlanMode, n.config.Parent) } // parse and correlate the endpoint v6 address with the available v6 subnets if len(n.config.Ipv6Subnets) > 0 { s := n.getSubnetforIPv6(ep.addrv6) if s == nil { return fmt.Errorf("could not find a valid ipv6 subnet for endpoint %s", eid) } v6gw, _, err := net.ParseCIDR(s.GwIP) if err != nil { return fmt.Errorf("gateway %s is not a valid ipv6 address: %v", s.GwIP, err) } err = jinfo.SetGatewayIPv6(v6gw) if err != nil { return err } logrus.Debugf("Ipvlan Endpoint Joined with IPv6_Addr: %s, Gateway: %s, Ipvlan_Mode: %s, Parent: %s", ep.addrv6.IP.String(), v6gw.String(), n.config.IpvlanMode, n.config.Parent) } } iNames := jinfo.InterfaceName() err = iNames.SetNames(vethName, containerVethPrefix) if err != nil { return err } if err = d.storeUpdate(ep); err != nil { return fmt.Errorf("failed to save ipvlan endpoint %.7s to store: %v", ep.id, err) } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_joinleave.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_joinleave.go#L127-L142
go
train
// Leave method is invoked when a Sandbox detaches from an endpoint.
func (d *driver) Leave(nid, eid string) error
// Leave method is invoked when a Sandbox detaches from an endpoint. func (d *driver) Leave(nid, eid string) error
{ defer osl.InitOSContext()() network, err := d.getNetwork(nid) if err != nil { return err } endpoint, err := network.getEndpoint(eid) if err != nil { return err } if endpoint == nil { return fmt.Errorf("could not find endpoint with id %s", eid) } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_joinleave.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_joinleave.go#L145-L157
go
train
// ifaceGateway returns a static route for either v4/v6 to be set to the container eth0
func ifaceGateway(dfNet string) (*staticRoute, error)
// ifaceGateway returns a static route for either v4/v6 to be set to the container eth0 func ifaceGateway(dfNet string) (*staticRoute, error)
{ nh, dst, err := net.ParseCIDR(dfNet) if err != nil { return nil, fmt.Errorf("unable to parse default route %v", err) } defaultRoute := &staticRoute{ Destination: dst, RouteType: types.CONNECTED, NextHop: nh, } return defaultRoute, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_joinleave.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_joinleave.go#L160-L178
go
train
// getSubnetforIPv4 returns the ipv4 subnet to which the given IP belongs
func (n *network) getSubnetforIPv4(ip *net.IPNet) *ipv4Subnet
// getSubnetforIPv4 returns the ipv4 subnet to which the given IP belongs func (n *network) getSubnetforIPv4(ip *net.IPNet) *ipv4Subnet
{ for _, s := range n.config.Ipv4Subnets { _, snet, err := net.ParseCIDR(s.SubnetIP) if err != nil { return nil } // first check if the mask lengths are the same i, _ := snet.Mask.Size() j, _ := ip.Mask.Size() if i != j { continue } if snet.Contains(ip.IP) { return s } } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_joinleave.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_joinleave.go#L181-L199
go
train
// getSubnetforIPv6 returns the ipv6 subnet to which the given IP belongs
func (n *network) getSubnetforIPv6(ip *net.IPNet) *ipv6Subnet
// getSubnetforIPv6 returns the ipv6 subnet to which the given IP belongs func (n *network) getSubnetforIPv6(ip *net.IPNet) *ipv6Subnet
{ for _, s := range n.config.Ipv6Subnets { _, snet, err := net.ParseCIDR(s.SubnetIP) if err != nil { return nil } // first check if the mask lengths are the same i, _ := snet.Mask.Size() j, _ := ip.Mask.Size() if i != j { continue } if snet.Contains(ip.IP) { return s } } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L345-L376
go
train
// sortFlags returns the flags as a slice in lexicographical sorted order.
func sortFlags(flags map[string]*Flag) []*Flag
// sortFlags returns the flags as a slice in lexicographical sorted order. func sortFlags(flags map[string]*Flag) []*Flag
{ var list flagSlice // The sorted list is based on the first name, when flag map might use the other names. nameMap := make(map[string]string) for n, f := range flags { fName := strings.TrimPrefix(f.Names[0], "#") nameMap[fName] = n if len(f.Names) == 1 { list = append(list, fName) continue } found := false for _, name := range list { if name == fName { found = true break } } if !found { list = append(list, fName) } } sort.Sort(list) result := make([]*Flag, len(list)) for i, name := range list { result[i] = flags[nameMap[name]] } return result }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L384-L389
go
train
// Out returns the destination for usage and error messages.
func (fs *FlagSet) Out() io.Writer
// Out returns the destination for usage and error messages. func (fs *FlagSet) Out() io.Writer
{ if fs.output == nil { return os.Stderr } return fs.output }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L413-L417
go
train
// Visit visits the flags in lexicographical order, calling fn for each. // It visits only those flags that have been set.
func (fs *FlagSet) Visit(fn func(*Flag))
// Visit visits the flags in lexicographical order, calling fn for each. // It visits only those flags that have been set. func (fs *FlagSet) Visit(fn func(*Flag))
{ for _, flag := range sortFlags(fs.actual) { fn(flag) } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L431-L433
go
train
// IsSet indicates whether the specified flag is set in the given FlagSet
func (fs *FlagSet) IsSet(name string) bool
// IsSet indicates whether the specified flag is set in the given FlagSet func (fs *FlagSet) IsSet(name string) bool
{ return fs.actual[name] != nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L464-L466
go
train
// Require adds a requirement about the number of arguments for the FlagSet. // The first parameter can be Exact, Max, or Min to respectively specify the exact, // the maximum, or the minimal number of arguments required. // The actual check is done in FlagSet.CheckArgs().
func (fs *FlagSet) Require(nArgRequirementType nArgRequirementType, nArg int)
// Require adds a requirement about the number of arguments for the FlagSet. // The first parameter can be Exact, Max, or Min to respectively specify the exact, // the maximum, or the minimal number of arguments required. // The actual check is done in FlagSet.CheckArgs(). func (fs *FlagSet) Require(nArgRequirementType nArgRequirementType, nArg int)
{ fs.nArgRequirements = append(fs.nArgRequirements, nArgRequirement{nArgRequirementType, nArg}) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L471-L500
go
train
// CheckArgs uses the requirements set by FlagSet.Require() to validate // the number of arguments. If the requirements are not met, // an error message string is returned.
func (fs *FlagSet) CheckArgs() (message string)
// CheckArgs uses the requirements set by FlagSet.Require() to validate // the number of arguments. If the requirements are not met, // an error message string is returned. func (fs *FlagSet) CheckArgs() (message string)
{ for _, req := range fs.nArgRequirements { var arguments string if req.N == 1 { arguments = "1 argument" } else { arguments = fmt.Sprintf("%d arguments", req.N) } str := func(kind string) string { return fmt.Sprintf("%q requires %s%s", fs.name, kind, arguments) } switch req.Type { case Exact: if fs.NArg() != req.N { return str("") } case Max: if fs.NArg() > req.N { return str("a maximum of ") } case Min: if fs.NArg() < req.N { return str("a minimum of ") } } } return "" }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L503-L516
go
train
// Set sets the value of the named flag.
func (fs *FlagSet) Set(name, value string) error
// Set sets the value of the named flag. func (fs *FlagSet) Set(name, value string) error
{ flag, ok := fs.formal[name] if !ok { return fmt.Errorf("no such flag -%v", name) } if err := flag.Value.Set(value); err != nil { return err } if fs.actual == nil { fs.actual = make(map[string]*Flag) } fs.actual[name] = flag return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L539-L580
go
train
// PrintDefaults prints, to standard error unless configured // otherwise, the default values of all defined flags in the set.
func (fs *FlagSet) PrintDefaults()
// PrintDefaults prints, to standard error unless configured // otherwise, the default values of all defined flags in the set. func (fs *FlagSet) PrintDefaults()
{ writer := tabwriter.NewWriter(fs.Out(), 20, 1, 3, ' ', 0) home := homedir.Get() // Don't substitute when HOME is / if runtime.GOOS != "windows" && home == "/" { home = "" } // Add a blank line between cmd description and list of options if fs.FlagCount() > 0 { fmt.Fprintln(writer, "") } fs.VisitAll(func(flag *Flag) { names := []string{} for _, name := range flag.Names { if name[0] != '#' { names = append(names, name) } } if len(names) > 0 && len(flag.Usage) > 0 { val := flag.DefValue if home != "" && strings.HasPrefix(val, home) { val = homedir.GetShortcutString() + val[len(home):] } if isZeroValue(val) { format := " -%s" fmt.Fprintf(writer, format, strings.Join(names, ", -")) } else { format := " -%s=%s" fmt.Fprintf(writer, format, strings.Join(names, ", -"), val) } for _, line := range strings.Split(flag.Usage, "\n") { fmt.Fprintln(writer, "\t", line) } } }) writer.Flush() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L588-L595
go
train
// defaultUsage is the default function to print a usage message.
func defaultUsage(fs *FlagSet)
// defaultUsage is the default function to print a usage message. func defaultUsage(fs *FlagSet)
{ if fs.name == "" { fmt.Fprintf(fs.Out(), "Usage:\n") } else { fmt.Fprintf(fs.Out(), "Usage of %s:\n", fs.name) } fs.PrintDefaults() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L618-L629
go
train
// FlagCountUndeprecated returns the number of undeprecated flags that have been defined.
func (fs *FlagSet) FlagCountUndeprecated() int
// FlagCountUndeprecated returns the number of undeprecated flags that have been defined. func (fs *FlagSet) FlagCountUndeprecated() int
{ count := 0 for _, flag := range sortFlags(fs.formal) { for _, name := range flag.Names { if name[0] != '#' { count++ break } } } return count }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L639-L644
go
train
// Arg returns the i'th argument. Arg(0) is the first remaining argument // after flags have been processed.
func (fs *FlagSet) Arg(i int) string
// Arg returns the i'th argument. Arg(0) is the first remaining argument // after flags have been processed. func (fs *FlagSet) Arg(i int) string
{ if i < 0 || i >= len(fs.args) { return "" } return fs.args[i] }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L666-L668
go
train
// BoolVar defines a bool flag with specified name, default value, and usage string. // The argument p points to a bool variable in which to store the value of the flag.
func (fs *FlagSet) BoolVar(p *bool, names []string, value bool, usage string)
// BoolVar defines a bool flag with specified name, default value, and usage string. // The argument p points to a bool variable in which to store the value of the flag. func (fs *FlagSet) BoolVar(p *bool, names []string, value bool, usage string)
{ fs.Var(newBoolValue(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L678-L682
go
train
// Bool defines a bool flag with specified name, default value, and usage string. // The return value is the address of a bool variable that stores the value of the flag.
func (fs *FlagSet) Bool(names []string, value bool, usage string) *bool
// Bool defines a bool flag with specified name, default value, and usage string. // The return value is the address of a bool variable that stores the value of the flag. func (fs *FlagSet) Bool(names []string, value bool, usage string) *bool
{ p := new(bool) fs.BoolVar(p, names, value, usage) return p }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L686-L688
go
train
// Bool defines a bool flag with specified name, default value, and usage string. // The return value is the address of a bool variable that stores the value of the flag.
func Bool(names []string, value bool, usage string) *bool
// Bool defines a bool flag with specified name, default value, and usage string. // The return value is the address of a bool variable that stores the value of the flag. func Bool(names []string, value bool, usage string) *bool
{ return CommandLine.Bool(names, value, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L692-L694
go
train
// IntVar defines an int flag with specified name, default value, and usage string. // The argument p points to an int variable in which to store the value of the flag.
func (fs *FlagSet) IntVar(p *int, names []string, value int, usage string)
// IntVar defines an int flag with specified name, default value, and usage string. // The argument p points to an int variable in which to store the value of the flag. func (fs *FlagSet) IntVar(p *int, names []string, value int, usage string)
{ fs.Var(newIntValue(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L704-L708
go
train
// Int defines an int flag with specified name, default value, and usage string. // The return value is the address of an int variable that stores the value of the flag.
func (fs *FlagSet) Int(names []string, value int, usage string) *int
// Int defines an int flag with specified name, default value, and usage string. // The return value is the address of an int variable that stores the value of the flag. func (fs *FlagSet) Int(names []string, value int, usage string) *int
{ p := new(int) fs.IntVar(p, names, value, usage) return p }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L712-L714
go
train
// Int defines an int flag with specified name, default value, and usage string. // The return value is the address of an int variable that stores the value of the flag.
func Int(names []string, value int, usage string) *int
// Int defines an int flag with specified name, default value, and usage string. // The return value is the address of an int variable that stores the value of the flag. func Int(names []string, value int, usage string) *int
{ return CommandLine.Int(names, value, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L718-L720
go
train
// Int64Var defines an int64 flag with specified name, default value, and usage string. // The argument p points to an int64 variable in which to store the value of the flag.
func (fs *FlagSet) Int64Var(p *int64, names []string, value int64, usage string)
// Int64Var defines an int64 flag with specified name, default value, and usage string. // The argument p points to an int64 variable in which to store the value of the flag. func (fs *FlagSet) Int64Var(p *int64, names []string, value int64, usage string)
{ fs.Var(newInt64Value(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L730-L734
go
train
// Int64 defines an int64 flag with specified name, default value, and usage string. // The return value is the address of an int64 variable that stores the value of the flag.
func (fs *FlagSet) Int64(names []string, value int64, usage string) *int64
// Int64 defines an int64 flag with specified name, default value, and usage string. // The return value is the address of an int64 variable that stores the value of the flag. func (fs *FlagSet) Int64(names []string, value int64, usage string) *int64
{ p := new(int64) fs.Int64Var(p, names, value, usage) return p }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L738-L740
go
train
// Int64 defines an int64 flag with specified name, default value, and usage string. // The return value is the address of an int64 variable that stores the value of the flag.
func Int64(names []string, value int64, usage string) *int64
// Int64 defines an int64 flag with specified name, default value, and usage string. // The return value is the address of an int64 variable that stores the value of the flag. func Int64(names []string, value int64, usage string) *int64
{ return CommandLine.Int64(names, value, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L744-L746
go
train
// UintVar defines a uint flag with specified name, default value, and usage string. // The argument p points to a uint variable in which to store the value of the flag.
func (fs *FlagSet) UintVar(p *uint, names []string, value uint, usage string)
// UintVar defines a uint flag with specified name, default value, and usage string. // The argument p points to a uint variable in which to store the value of the flag. func (fs *FlagSet) UintVar(p *uint, names []string, value uint, usage string)
{ fs.Var(newUintValue(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L756-L760
go
train
// Uint defines a uint flag with specified name, default value, and usage string. // The return value is the address of a uint variable that stores the value of the flag.
func (fs *FlagSet) Uint(names []string, value uint, usage string) *uint
// Uint defines a uint flag with specified name, default value, and usage string. // The return value is the address of a uint variable that stores the value of the flag. func (fs *FlagSet) Uint(names []string, value uint, usage string) *uint
{ p := new(uint) fs.UintVar(p, names, value, usage) return p }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L764-L766
go
train
// Uint defines a uint flag with specified name, default value, and usage string. // The return value is the address of a uint variable that stores the value of the flag.
func Uint(names []string, value uint, usage string) *uint
// Uint defines a uint flag with specified name, default value, and usage string. // The return value is the address of a uint variable that stores the value of the flag. func Uint(names []string, value uint, usage string) *uint
{ return CommandLine.Uint(names, value, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L770-L772
go
train
// Uint64Var defines a uint64 flag with specified name, default value, and usage string. // The argument p points to a uint64 variable in which to store the value of the flag.
func (fs *FlagSet) Uint64Var(p *uint64, names []string, value uint64, usage string)
// Uint64Var defines a uint64 flag with specified name, default value, and usage string. // The argument p points to a uint64 variable in which to store the value of the flag. func (fs *FlagSet) Uint64Var(p *uint64, names []string, value uint64, usage string)
{ fs.Var(newUint64Value(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L782-L786
go
train
// Uint64 defines a uint64 flag with specified name, default value, and usage string. // The return value is the address of a uint64 variable that stores the value of the flag.
func (fs *FlagSet) Uint64(names []string, value uint64, usage string) *uint64
// Uint64 defines a uint64 flag with specified name, default value, and usage string. // The return value is the address of a uint64 variable that stores the value of the flag. func (fs *FlagSet) Uint64(names []string, value uint64, usage string) *uint64
{ p := new(uint64) fs.Uint64Var(p, names, value, usage) return p }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L790-L792
go
train
// Uint64 defines a uint64 flag with specified name, default value, and usage string. // The return value is the address of a uint64 variable that stores the value of the flag.
func Uint64(names []string, value uint64, usage string) *uint64
// Uint64 defines a uint64 flag with specified name, default value, and usage string. // The return value is the address of a uint64 variable that stores the value of the flag. func Uint64(names []string, value uint64, usage string) *uint64
{ return CommandLine.Uint64(names, value, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L796-L798
go
train
// Uint16Var defines a uint16 flag with specified name, default value, and usage string. // The argument p points to a uint16 variable in which to store the value of the flag.
func (fs *FlagSet) Uint16Var(p *uint16, names []string, value uint16, usage string)
// Uint16Var defines a uint16 flag with specified name, default value, and usage string. // The argument p points to a uint16 variable in which to store the value of the flag. func (fs *FlagSet) Uint16Var(p *uint16, names []string, value uint16, usage string)
{ fs.Var(newUint16Value(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L802-L804
go
train
// Uint16Var defines a uint16 flag with specified name, default value, and usage string. // The argument p points to a uint16 variable in which to store the value of the flag.
func Uint16Var(p *uint16, names []string, value uint16, usage string)
// Uint16Var defines a uint16 flag with specified name, default value, and usage string. // The argument p points to a uint16 variable in which to store the value of the flag. func Uint16Var(p *uint16, names []string, value uint16, usage string)
{ CommandLine.Var(newUint16Value(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L808-L812
go
train
// Uint16 defines a uint16 flag with specified name, default value, and usage string. // The return value is the address of a uint16 variable that stores the value of the flag.
func (fs *FlagSet) Uint16(names []string, value uint16, usage string) *uint16
// Uint16 defines a uint16 flag with specified name, default value, and usage string. // The return value is the address of a uint16 variable that stores the value of the flag. func (fs *FlagSet) Uint16(names []string, value uint16, usage string) *uint16
{ p := new(uint16) fs.Uint16Var(p, names, value, usage) return p }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L816-L818
go
train
// Uint16 defines a uint16 flag with specified name, default value, and usage string. // The return value is the address of a uint16 variable that stores the value of the flag.
func Uint16(names []string, value uint16, usage string) *uint16
// Uint16 defines a uint16 flag with specified name, default value, and usage string. // The return value is the address of a uint16 variable that stores the value of the flag. func Uint16(names []string, value uint16, usage string) *uint16
{ return CommandLine.Uint16(names, value, usage) }