id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
|---|---|---|---|---|---|---|---|---|---|---|---|
22,500
|
docker/libnetwork
|
netutils/utils.go
|
NetworkRange
|
func NetworkRange(network *net.IPNet) (net.IP, net.IP) {
if network == nil {
return nil, nil
}
firstIP := network.IP.Mask(network.Mask)
lastIP := types.GetIPCopy(firstIP)
for i := 0; i < len(firstIP); i++ {
lastIP[i] = firstIP[i] | ^network.Mask[i]
}
if network.IP.To4() != nil {
firstIP = firstIP.To4()
lastIP = lastIP.To4()
}
return firstIP, lastIP
}
|
go
|
func NetworkRange(network *net.IPNet) (net.IP, net.IP) {
if network == nil {
return nil, nil
}
firstIP := network.IP.Mask(network.Mask)
lastIP := types.GetIPCopy(firstIP)
for i := 0; i < len(firstIP); i++ {
lastIP[i] = firstIP[i] | ^network.Mask[i]
}
if network.IP.To4() != nil {
firstIP = firstIP.To4()
lastIP = lastIP.To4()
}
return firstIP, lastIP
}
|
[
"func",
"NetworkRange",
"(",
"network",
"*",
"net",
".",
"IPNet",
")",
"(",
"net",
".",
"IP",
",",
"net",
".",
"IP",
")",
"{",
"if",
"network",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"firstIP",
":=",
"network",
".",
"IP",
".",
"Mask",
"(",
"network",
".",
"Mask",
")",
"\n",
"lastIP",
":=",
"types",
".",
"GetIPCopy",
"(",
"firstIP",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"firstIP",
")",
";",
"i",
"++",
"{",
"lastIP",
"[",
"i",
"]",
"=",
"firstIP",
"[",
"i",
"]",
"|",
"^",
"network",
".",
"Mask",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"if",
"network",
".",
"IP",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"firstIP",
"=",
"firstIP",
".",
"To4",
"(",
")",
"\n",
"lastIP",
"=",
"lastIP",
".",
"To4",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"firstIP",
",",
"lastIP",
"\n",
"}"
] |
// NetworkRange calculates the first and last IP addresses in an IPNet
|
[
"NetworkRange",
"calculates",
"the",
"first",
"and",
"last",
"IP",
"addresses",
"in",
"an",
"IPNet"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netutils/utils.go#L48-L65
|
22,501
|
docker/libnetwork
|
netutils/utils.go
|
GetIfaceAddr
|
func GetIfaceAddr(name string) (net.Addr, []net.Addr, error) {
iface, err := net.InterfaceByName(name)
if err != nil {
return nil, nil, err
}
addrs, err := iface.Addrs()
if err != nil {
return nil, nil, err
}
var addrs4 []net.Addr
var addrs6 []net.Addr
for _, addr := range addrs {
ip := (addr.(*net.IPNet)).IP
if ip4 := ip.To4(); ip4 != nil {
addrs4 = append(addrs4, addr)
} else if ip6 := ip.To16(); len(ip6) == net.IPv6len {
addrs6 = append(addrs6, addr)
}
}
switch {
case len(addrs4) == 0:
return nil, nil, fmt.Errorf("Interface %v has no IPv4 addresses", name)
case len(addrs4) > 1:
fmt.Printf("Interface %v has more than 1 IPv4 address. Defaulting to using %v\n",
name, (addrs4[0].(*net.IPNet)).IP)
}
return addrs4[0], addrs6, nil
}
|
go
|
func GetIfaceAddr(name string) (net.Addr, []net.Addr, error) {
iface, err := net.InterfaceByName(name)
if err != nil {
return nil, nil, err
}
addrs, err := iface.Addrs()
if err != nil {
return nil, nil, err
}
var addrs4 []net.Addr
var addrs6 []net.Addr
for _, addr := range addrs {
ip := (addr.(*net.IPNet)).IP
if ip4 := ip.To4(); ip4 != nil {
addrs4 = append(addrs4, addr)
} else if ip6 := ip.To16(); len(ip6) == net.IPv6len {
addrs6 = append(addrs6, addr)
}
}
switch {
case len(addrs4) == 0:
return nil, nil, fmt.Errorf("Interface %v has no IPv4 addresses", name)
case len(addrs4) > 1:
fmt.Printf("Interface %v has more than 1 IPv4 address. Defaulting to using %v\n",
name, (addrs4[0].(*net.IPNet)).IP)
}
return addrs4[0], addrs6, nil
}
|
[
"func",
"GetIfaceAddr",
"(",
"name",
"string",
")",
"(",
"net",
".",
"Addr",
",",
"[",
"]",
"net",
".",
"Addr",
",",
"error",
")",
"{",
"iface",
",",
"err",
":=",
"net",
".",
"InterfaceByName",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"addrs",
",",
"err",
":=",
"iface",
".",
"Addrs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"addrs4",
"[",
"]",
"net",
".",
"Addr",
"\n",
"var",
"addrs6",
"[",
"]",
"net",
".",
"Addr",
"\n",
"for",
"_",
",",
"addr",
":=",
"range",
"addrs",
"{",
"ip",
":=",
"(",
"addr",
".",
"(",
"*",
"net",
".",
"IPNet",
")",
")",
".",
"IP",
"\n",
"if",
"ip4",
":=",
"ip",
".",
"To4",
"(",
")",
";",
"ip4",
"!=",
"nil",
"{",
"addrs4",
"=",
"append",
"(",
"addrs4",
",",
"addr",
")",
"\n",
"}",
"else",
"if",
"ip6",
":=",
"ip",
".",
"To16",
"(",
")",
";",
"len",
"(",
"ip6",
")",
"==",
"net",
".",
"IPv6len",
"{",
"addrs6",
"=",
"append",
"(",
"addrs6",
",",
"addr",
")",
"\n",
"}",
"\n",
"}",
"\n",
"switch",
"{",
"case",
"len",
"(",
"addrs4",
")",
"==",
"0",
":",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"case",
"len",
"(",
"addrs4",
")",
">",
"1",
":",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"name",
",",
"(",
"addrs4",
"[",
"0",
"]",
".",
"(",
"*",
"net",
".",
"IPNet",
")",
")",
".",
"IP",
")",
"\n",
"}",
"\n",
"return",
"addrs4",
"[",
"0",
"]",
",",
"addrs6",
",",
"nil",
"\n",
"}"
] |
// GetIfaceAddr returns the first IPv4 address and slice of IPv6 addresses for the specified network interface
|
[
"GetIfaceAddr",
"returns",
"the",
"first",
"IPv4",
"address",
"and",
"slice",
"of",
"IPv6",
"addresses",
"for",
"the",
"specified",
"network",
"interface"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netutils/utils.go#L68-L95
|
22,502
|
docker/libnetwork
|
netutils/utils.go
|
GenerateRandomName
|
func GenerateRandomName(prefix string, size int) (string, error) {
id := make([]byte, 32)
if _, err := io.ReadFull(rand.Reader, id); err != nil {
return "", err
}
return prefix + hex.EncodeToString(id)[:size], nil
}
|
go
|
func GenerateRandomName(prefix string, size int) (string, error) {
id := make([]byte, 32)
if _, err := io.ReadFull(rand.Reader, id); err != nil {
return "", err
}
return prefix + hex.EncodeToString(id)[:size], nil
}
|
[
"func",
"GenerateRandomName",
"(",
"prefix",
"string",
",",
"size",
"int",
")",
"(",
"string",
",",
"error",
")",
"{",
"id",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"32",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"rand",
".",
"Reader",
",",
"id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"prefix",
"+",
"hex",
".",
"EncodeToString",
"(",
"id",
")",
"[",
":",
"size",
"]",
",",
"nil",
"\n",
"}"
] |
// GenerateRandomName returns a new name joined with a prefix. This size
// specified is used to truncate the randomly generated value
|
[
"GenerateRandomName",
"returns",
"a",
"new",
"name",
"joined",
"with",
"a",
"prefix",
".",
"This",
"size",
"specified",
"is",
"used",
"to",
"truncate",
"the",
"randomly",
"generated",
"value"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netutils/utils.go#L129-L135
|
22,503
|
docker/libnetwork
|
netutils/utils.go
|
ReverseIP
|
func ReverseIP(IP string) string {
var reverseIP []string
if net.ParseIP(IP).To4() != nil {
reverseIP = strings.Split(IP, ".")
l := len(reverseIP)
for i, j := 0, l-1; i < l/2; i, j = i+1, j-1 {
reverseIP[i], reverseIP[j] = reverseIP[j], reverseIP[i]
}
} else {
reverseIP = strings.Split(IP, ":")
// Reversed IPv6 is represented in dotted decimal instead of the typical
// colon hex notation
for key := range reverseIP {
if len(reverseIP[key]) == 0 { // expand the compressed 0s
reverseIP[key] = strings.Repeat("0000", 8-strings.Count(IP, ":"))
} else if len(reverseIP[key]) < 4 { // 0-padding needed
reverseIP[key] = strings.Repeat("0", 4-len(reverseIP[key])) + reverseIP[key]
}
}
reverseIP = strings.Split(strings.Join(reverseIP, ""), "")
l := len(reverseIP)
for i, j := 0, l-1; i < l/2; i, j = i+1, j-1 {
reverseIP[i], reverseIP[j] = reverseIP[j], reverseIP[i]
}
}
return strings.Join(reverseIP, ".")
}
|
go
|
func ReverseIP(IP string) string {
var reverseIP []string
if net.ParseIP(IP).To4() != nil {
reverseIP = strings.Split(IP, ".")
l := len(reverseIP)
for i, j := 0, l-1; i < l/2; i, j = i+1, j-1 {
reverseIP[i], reverseIP[j] = reverseIP[j], reverseIP[i]
}
} else {
reverseIP = strings.Split(IP, ":")
// Reversed IPv6 is represented in dotted decimal instead of the typical
// colon hex notation
for key := range reverseIP {
if len(reverseIP[key]) == 0 { // expand the compressed 0s
reverseIP[key] = strings.Repeat("0000", 8-strings.Count(IP, ":"))
} else if len(reverseIP[key]) < 4 { // 0-padding needed
reverseIP[key] = strings.Repeat("0", 4-len(reverseIP[key])) + reverseIP[key]
}
}
reverseIP = strings.Split(strings.Join(reverseIP, ""), "")
l := len(reverseIP)
for i, j := 0, l-1; i < l/2; i, j = i+1, j-1 {
reverseIP[i], reverseIP[j] = reverseIP[j], reverseIP[i]
}
}
return strings.Join(reverseIP, ".")
}
|
[
"func",
"ReverseIP",
"(",
"IP",
"string",
")",
"string",
"{",
"var",
"reverseIP",
"[",
"]",
"string",
"\n\n",
"if",
"net",
".",
"ParseIP",
"(",
"IP",
")",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"reverseIP",
"=",
"strings",
".",
"Split",
"(",
"IP",
",",
"\"",
"\"",
")",
"\n",
"l",
":=",
"len",
"(",
"reverseIP",
")",
"\n",
"for",
"i",
",",
"j",
":=",
"0",
",",
"l",
"-",
"1",
";",
"i",
"<",
"l",
"/",
"2",
";",
"i",
",",
"j",
"=",
"i",
"+",
"1",
",",
"j",
"-",
"1",
"{",
"reverseIP",
"[",
"i",
"]",
",",
"reverseIP",
"[",
"j",
"]",
"=",
"reverseIP",
"[",
"j",
"]",
",",
"reverseIP",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"else",
"{",
"reverseIP",
"=",
"strings",
".",
"Split",
"(",
"IP",
",",
"\"",
"\"",
")",
"\n\n",
"// Reversed IPv6 is represented in dotted decimal instead of the typical",
"// colon hex notation",
"for",
"key",
":=",
"range",
"reverseIP",
"{",
"if",
"len",
"(",
"reverseIP",
"[",
"key",
"]",
")",
"==",
"0",
"{",
"// expand the compressed 0s",
"reverseIP",
"[",
"key",
"]",
"=",
"strings",
".",
"Repeat",
"(",
"\"",
"\"",
",",
"8",
"-",
"strings",
".",
"Count",
"(",
"IP",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"reverseIP",
"[",
"key",
"]",
")",
"<",
"4",
"{",
"// 0-padding needed",
"reverseIP",
"[",
"key",
"]",
"=",
"strings",
".",
"Repeat",
"(",
"\"",
"\"",
",",
"4",
"-",
"len",
"(",
"reverseIP",
"[",
"key",
"]",
")",
")",
"+",
"reverseIP",
"[",
"key",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"reverseIP",
"=",
"strings",
".",
"Split",
"(",
"strings",
".",
"Join",
"(",
"reverseIP",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n\n",
"l",
":=",
"len",
"(",
"reverseIP",
")",
"\n",
"for",
"i",
",",
"j",
":=",
"0",
",",
"l",
"-",
"1",
";",
"i",
"<",
"l",
"/",
"2",
";",
"i",
",",
"j",
"=",
"i",
"+",
"1",
",",
"j",
"-",
"1",
"{",
"reverseIP",
"[",
"i",
"]",
",",
"reverseIP",
"[",
"j",
"]",
"=",
"reverseIP",
"[",
"j",
"]",
",",
"reverseIP",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"reverseIP",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// ReverseIP accepts a V4 or V6 IP string in the canonical form and returns a reversed IP in
// the dotted decimal form . This is used to setup the IP to service name mapping in the optimal
// way for the DNS PTR queries.
|
[
"ReverseIP",
"accepts",
"a",
"V4",
"or",
"V6",
"IP",
"string",
"in",
"the",
"canonical",
"form",
"and",
"returns",
"a",
"reversed",
"IP",
"in",
"the",
"dotted",
"decimal",
"form",
".",
"This",
"is",
"used",
"to",
"setup",
"the",
"IP",
"to",
"service",
"name",
"mapping",
"in",
"the",
"optimal",
"way",
"for",
"the",
"DNS",
"PTR",
"queries",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netutils/utils.go#L140-L171
|
22,504
|
docker/libnetwork
|
ipvs/netlink.go
|
assembleService
|
func assembleService(attrs []syscall.NetlinkRouteAttr) (*Service, error) {
var s Service
for _, attr := range attrs {
attrType := int(attr.Attr.Type)
switch attrType {
case ipvsSvcAttrAddressFamily:
s.AddressFamily = native.Uint16(attr.Value)
case ipvsSvcAttrProtocol:
s.Protocol = native.Uint16(attr.Value)
case ipvsSvcAttrAddress:
ip, err := parseIP(attr.Value, s.AddressFamily)
if err != nil {
return nil, err
}
s.Address = ip
case ipvsSvcAttrPort:
s.Port = binary.BigEndian.Uint16(attr.Value)
case ipvsSvcAttrFWMark:
s.FWMark = native.Uint32(attr.Value)
case ipvsSvcAttrSchedName:
s.SchedName = nl.BytesToString(attr.Value)
case ipvsSvcAttrFlags:
s.Flags = native.Uint32(attr.Value)
case ipvsSvcAttrTimeout:
s.Timeout = native.Uint32(attr.Value)
case ipvsSvcAttrNetmask:
s.Netmask = native.Uint32(attr.Value)
case ipvsSvcAttrStats:
stats, err := assembleStats(attr.Value)
if err != nil {
return nil, err
}
s.Stats = stats
}
}
return &s, nil
}
|
go
|
func assembleService(attrs []syscall.NetlinkRouteAttr) (*Service, error) {
var s Service
for _, attr := range attrs {
attrType := int(attr.Attr.Type)
switch attrType {
case ipvsSvcAttrAddressFamily:
s.AddressFamily = native.Uint16(attr.Value)
case ipvsSvcAttrProtocol:
s.Protocol = native.Uint16(attr.Value)
case ipvsSvcAttrAddress:
ip, err := parseIP(attr.Value, s.AddressFamily)
if err != nil {
return nil, err
}
s.Address = ip
case ipvsSvcAttrPort:
s.Port = binary.BigEndian.Uint16(attr.Value)
case ipvsSvcAttrFWMark:
s.FWMark = native.Uint32(attr.Value)
case ipvsSvcAttrSchedName:
s.SchedName = nl.BytesToString(attr.Value)
case ipvsSvcAttrFlags:
s.Flags = native.Uint32(attr.Value)
case ipvsSvcAttrTimeout:
s.Timeout = native.Uint32(attr.Value)
case ipvsSvcAttrNetmask:
s.Netmask = native.Uint32(attr.Value)
case ipvsSvcAttrStats:
stats, err := assembleStats(attr.Value)
if err != nil {
return nil, err
}
s.Stats = stats
}
}
return &s, nil
}
|
[
"func",
"assembleService",
"(",
"attrs",
"[",
"]",
"syscall",
".",
"NetlinkRouteAttr",
")",
"(",
"*",
"Service",
",",
"error",
")",
"{",
"var",
"s",
"Service",
"\n\n",
"for",
"_",
",",
"attr",
":=",
"range",
"attrs",
"{",
"attrType",
":=",
"int",
"(",
"attr",
".",
"Attr",
".",
"Type",
")",
"\n\n",
"switch",
"attrType",
"{",
"case",
"ipvsSvcAttrAddressFamily",
":",
"s",
".",
"AddressFamily",
"=",
"native",
".",
"Uint16",
"(",
"attr",
".",
"Value",
")",
"\n",
"case",
"ipvsSvcAttrProtocol",
":",
"s",
".",
"Protocol",
"=",
"native",
".",
"Uint16",
"(",
"attr",
".",
"Value",
")",
"\n",
"case",
"ipvsSvcAttrAddress",
":",
"ip",
",",
"err",
":=",
"parseIP",
"(",
"attr",
".",
"Value",
",",
"s",
".",
"AddressFamily",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"s",
".",
"Address",
"=",
"ip",
"\n",
"case",
"ipvsSvcAttrPort",
":",
"s",
".",
"Port",
"=",
"binary",
".",
"BigEndian",
".",
"Uint16",
"(",
"attr",
".",
"Value",
")",
"\n",
"case",
"ipvsSvcAttrFWMark",
":",
"s",
".",
"FWMark",
"=",
"native",
".",
"Uint32",
"(",
"attr",
".",
"Value",
")",
"\n",
"case",
"ipvsSvcAttrSchedName",
":",
"s",
".",
"SchedName",
"=",
"nl",
".",
"BytesToString",
"(",
"attr",
".",
"Value",
")",
"\n",
"case",
"ipvsSvcAttrFlags",
":",
"s",
".",
"Flags",
"=",
"native",
".",
"Uint32",
"(",
"attr",
".",
"Value",
")",
"\n",
"case",
"ipvsSvcAttrTimeout",
":",
"s",
".",
"Timeout",
"=",
"native",
".",
"Uint32",
"(",
"attr",
".",
"Value",
")",
"\n",
"case",
"ipvsSvcAttrNetmask",
":",
"s",
".",
"Netmask",
"=",
"native",
".",
"Uint32",
"(",
"attr",
".",
"Value",
")",
"\n",
"case",
"ipvsSvcAttrStats",
":",
"stats",
",",
"err",
":=",
"assembleStats",
"(",
"attr",
".",
"Value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"s",
".",
"Stats",
"=",
"stats",
"\n",
"}",
"\n\n",
"}",
"\n",
"return",
"&",
"s",
",",
"nil",
"\n",
"}"
] |
// assembleService assembles a services back from a hain of netlink attributes
|
[
"assembleService",
"assembles",
"a",
"services",
"back",
"from",
"a",
"hain",
"of",
"netlink",
"attributes"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/netlink.go#L315-L357
|
22,505
|
docker/libnetwork
|
ipvs/netlink.go
|
parseService
|
func (i *Handle) parseService(msg []byte) (*Service, error) {
var s *Service
//Remove General header for this message and parse the NetLink message
hdr := deserializeGenlMsg(msg)
NetLinkAttrs, err := nl.ParseRouteAttr(msg[hdr.Len():])
if err != nil {
return nil, err
}
if len(NetLinkAttrs) == 0 {
return nil, fmt.Errorf("error no valid netlink message found while parsing service record")
}
//Now Parse and get IPVS related attributes messages packed in this message.
ipvsAttrs, err := nl.ParseRouteAttr(NetLinkAttrs[0].Value)
if err != nil {
return nil, err
}
//Assemble all the IPVS related attribute messages and create a service record
s, err = assembleService(ipvsAttrs)
if err != nil {
return nil, err
}
return s, nil
}
|
go
|
func (i *Handle) parseService(msg []byte) (*Service, error) {
var s *Service
//Remove General header for this message and parse the NetLink message
hdr := deserializeGenlMsg(msg)
NetLinkAttrs, err := nl.ParseRouteAttr(msg[hdr.Len():])
if err != nil {
return nil, err
}
if len(NetLinkAttrs) == 0 {
return nil, fmt.Errorf("error no valid netlink message found while parsing service record")
}
//Now Parse and get IPVS related attributes messages packed in this message.
ipvsAttrs, err := nl.ParseRouteAttr(NetLinkAttrs[0].Value)
if err != nil {
return nil, err
}
//Assemble all the IPVS related attribute messages and create a service record
s, err = assembleService(ipvsAttrs)
if err != nil {
return nil, err
}
return s, nil
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"parseService",
"(",
"msg",
"[",
"]",
"byte",
")",
"(",
"*",
"Service",
",",
"error",
")",
"{",
"var",
"s",
"*",
"Service",
"\n\n",
"//Remove General header for this message and parse the NetLink message",
"hdr",
":=",
"deserializeGenlMsg",
"(",
"msg",
")",
"\n",
"NetLinkAttrs",
",",
"err",
":=",
"nl",
".",
"ParseRouteAttr",
"(",
"msg",
"[",
"hdr",
".",
"Len",
"(",
")",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"NetLinkAttrs",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"//Now Parse and get IPVS related attributes messages packed in this message.",
"ipvsAttrs",
",",
"err",
":=",
"nl",
".",
"ParseRouteAttr",
"(",
"NetLinkAttrs",
"[",
"0",
"]",
".",
"Value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"//Assemble all the IPVS related attribute messages and create a service record",
"s",
",",
"err",
"=",
"assembleService",
"(",
"ipvsAttrs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"s",
",",
"nil",
"\n",
"}"
] |
// parseService given a ipvs netlink response this function will respond with a valid service entry, an error otherwise
|
[
"parseService",
"given",
"a",
"ipvs",
"netlink",
"response",
"this",
"function",
"will",
"respond",
"with",
"a",
"valid",
"service",
"entry",
"an",
"error",
"otherwise"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/netlink.go#L360-L387
|
22,506
|
docker/libnetwork
|
ipvs/netlink.go
|
doCmdWithoutAttr
|
func (i *Handle) doCmdWithoutAttr(cmd uint8) ([][]byte, error) {
req := newIPVSRequest(cmd)
req.Seq = atomic.AddUint32(&i.seq, 1)
return execute(i.sock, req, 0)
}
|
go
|
func (i *Handle) doCmdWithoutAttr(cmd uint8) ([][]byte, error) {
req := newIPVSRequest(cmd)
req.Seq = atomic.AddUint32(&i.seq, 1)
return execute(i.sock, req, 0)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"doCmdWithoutAttr",
"(",
"cmd",
"uint8",
")",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"req",
":=",
"newIPVSRequest",
"(",
"cmd",
")",
"\n",
"req",
".",
"Seq",
"=",
"atomic",
".",
"AddUint32",
"(",
"&",
"i",
".",
"seq",
",",
"1",
")",
"\n",
"return",
"execute",
"(",
"i",
".",
"sock",
",",
"req",
",",
"0",
")",
"\n",
"}"
] |
// doCmdWithoutAttr a simple wrapper of netlink socket execute command
|
[
"doCmdWithoutAttr",
"a",
"simple",
"wrapper",
"of",
"netlink",
"socket",
"execute",
"command"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/netlink.go#L410-L414
|
22,507
|
docker/libnetwork
|
ipvs/netlink.go
|
parseDestination
|
func (i *Handle) parseDestination(msg []byte) (*Destination, error) {
var dst *Destination
//Remove General header for this message
hdr := deserializeGenlMsg(msg)
NetLinkAttrs, err := nl.ParseRouteAttr(msg[hdr.Len():])
if err != nil {
return nil, err
}
if len(NetLinkAttrs) == 0 {
return nil, fmt.Errorf("error no valid netlink message found while parsing destination record")
}
//Now Parse and get IPVS related attributes messages packed in this message.
ipvsAttrs, err := nl.ParseRouteAttr(NetLinkAttrs[0].Value)
if err != nil {
return nil, err
}
//Assemble netlink attributes and create a Destination record
dst, err = assembleDestination(ipvsAttrs)
if err != nil {
return nil, err
}
return dst, nil
}
|
go
|
func (i *Handle) parseDestination(msg []byte) (*Destination, error) {
var dst *Destination
//Remove General header for this message
hdr := deserializeGenlMsg(msg)
NetLinkAttrs, err := nl.ParseRouteAttr(msg[hdr.Len():])
if err != nil {
return nil, err
}
if len(NetLinkAttrs) == 0 {
return nil, fmt.Errorf("error no valid netlink message found while parsing destination record")
}
//Now Parse and get IPVS related attributes messages packed in this message.
ipvsAttrs, err := nl.ParseRouteAttr(NetLinkAttrs[0].Value)
if err != nil {
return nil, err
}
//Assemble netlink attributes and create a Destination record
dst, err = assembleDestination(ipvsAttrs)
if err != nil {
return nil, err
}
return dst, nil
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"parseDestination",
"(",
"msg",
"[",
"]",
"byte",
")",
"(",
"*",
"Destination",
",",
"error",
")",
"{",
"var",
"dst",
"*",
"Destination",
"\n\n",
"//Remove General header for this message",
"hdr",
":=",
"deserializeGenlMsg",
"(",
"msg",
")",
"\n",
"NetLinkAttrs",
",",
"err",
":=",
"nl",
".",
"ParseRouteAttr",
"(",
"msg",
"[",
"hdr",
".",
"Len",
"(",
")",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"NetLinkAttrs",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"//Now Parse and get IPVS related attributes messages packed in this message.",
"ipvsAttrs",
",",
"err",
":=",
"nl",
".",
"ParseRouteAttr",
"(",
"NetLinkAttrs",
"[",
"0",
"]",
".",
"Value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"//Assemble netlink attributes and create a Destination record",
"dst",
",",
"err",
"=",
"assembleDestination",
"(",
"ipvsAttrs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"dst",
",",
"nil",
"\n",
"}"
] |
// parseDestination given a ipvs netlink response this function will respond with a valid destination entry, an error otherwise
|
[
"parseDestination",
"given",
"a",
"ipvs",
"netlink",
"response",
"this",
"function",
"will",
"respond",
"with",
"a",
"valid",
"destination",
"entry",
"an",
"error",
"otherwise"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/netlink.go#L459-L485
|
22,508
|
docker/libnetwork
|
ipvs/netlink.go
|
parseConfig
|
func (i *Handle) parseConfig(msg []byte) (*Config, error) {
var c Config
//Remove General header for this message
hdr := deserializeGenlMsg(msg)
attrs, err := nl.ParseRouteAttr(msg[hdr.Len():])
if err != nil {
return nil, err
}
for _, attr := range attrs {
attrType := int(attr.Attr.Type)
switch attrType {
case ipvsCmdAttrTimeoutTCP:
c.TimeoutTCP = time.Duration(native.Uint32(attr.Value)) * time.Second
case ipvsCmdAttrTimeoutTCPFin:
c.TimeoutTCPFin = time.Duration(native.Uint32(attr.Value)) * time.Second
case ipvsCmdAttrTimeoutUDP:
c.TimeoutUDP = time.Duration(native.Uint32(attr.Value)) * time.Second
}
}
return &c, nil
}
|
go
|
func (i *Handle) parseConfig(msg []byte) (*Config, error) {
var c Config
//Remove General header for this message
hdr := deserializeGenlMsg(msg)
attrs, err := nl.ParseRouteAttr(msg[hdr.Len():])
if err != nil {
return nil, err
}
for _, attr := range attrs {
attrType := int(attr.Attr.Type)
switch attrType {
case ipvsCmdAttrTimeoutTCP:
c.TimeoutTCP = time.Duration(native.Uint32(attr.Value)) * time.Second
case ipvsCmdAttrTimeoutTCPFin:
c.TimeoutTCPFin = time.Duration(native.Uint32(attr.Value)) * time.Second
case ipvsCmdAttrTimeoutUDP:
c.TimeoutUDP = time.Duration(native.Uint32(attr.Value)) * time.Second
}
}
return &c, nil
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"parseConfig",
"(",
"msg",
"[",
"]",
"byte",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"var",
"c",
"Config",
"\n\n",
"//Remove General header for this message",
"hdr",
":=",
"deserializeGenlMsg",
"(",
"msg",
")",
"\n",
"attrs",
",",
"err",
":=",
"nl",
".",
"ParseRouteAttr",
"(",
"msg",
"[",
"hdr",
".",
"Len",
"(",
")",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"attr",
":=",
"range",
"attrs",
"{",
"attrType",
":=",
"int",
"(",
"attr",
".",
"Attr",
".",
"Type",
")",
"\n",
"switch",
"attrType",
"{",
"case",
"ipvsCmdAttrTimeoutTCP",
":",
"c",
".",
"TimeoutTCP",
"=",
"time",
".",
"Duration",
"(",
"native",
".",
"Uint32",
"(",
"attr",
".",
"Value",
")",
")",
"*",
"time",
".",
"Second",
"\n",
"case",
"ipvsCmdAttrTimeoutTCPFin",
":",
"c",
".",
"TimeoutTCPFin",
"=",
"time",
".",
"Duration",
"(",
"native",
".",
"Uint32",
"(",
"attr",
".",
"Value",
")",
")",
"*",
"time",
".",
"Second",
"\n",
"case",
"ipvsCmdAttrTimeoutUDP",
":",
"c",
".",
"TimeoutUDP",
"=",
"time",
".",
"Duration",
"(",
"native",
".",
"Uint32",
"(",
"attr",
".",
"Value",
")",
")",
"*",
"time",
".",
"Second",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"c",
",",
"nil",
"\n",
"}"
] |
// parseConfig given a ipvs netlink response this function will respond with a valid config entry, an error otherwise
|
[
"parseConfig",
"given",
"a",
"ipvs",
"netlink",
"response",
"this",
"function",
"will",
"respond",
"with",
"a",
"valid",
"config",
"entry",
"an",
"error",
"otherwise"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/netlink.go#L508-L531
|
22,509
|
docker/libnetwork
|
ipvs/netlink.go
|
doGetConfigCmd
|
func (i *Handle) doGetConfigCmd() (*Config, error) {
msg, err := i.doCmdWithoutAttr(ipvsCmdGetConfig)
if err != nil {
return nil, err
}
res, err := i.parseConfig(msg[0])
if err != nil {
return res, err
}
return res, nil
}
|
go
|
func (i *Handle) doGetConfigCmd() (*Config, error) {
msg, err := i.doCmdWithoutAttr(ipvsCmdGetConfig)
if err != nil {
return nil, err
}
res, err := i.parseConfig(msg[0])
if err != nil {
return res, err
}
return res, nil
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"doGetConfigCmd",
"(",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"msg",
",",
"err",
":=",
"i",
".",
"doCmdWithoutAttr",
"(",
"ipvsCmdGetConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"i",
".",
"parseConfig",
"(",
"msg",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"res",
",",
"err",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// doGetConfigCmd a wrapper function to be used by GetConfig
|
[
"doGetConfigCmd",
"a",
"wrapper",
"function",
"to",
"be",
"used",
"by",
"GetConfig"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/netlink.go#L534-L545
|
22,510
|
docker/libnetwork
|
ipvs/netlink.go
|
doSetConfigCmd
|
func (i *Handle) doSetConfigCmd(c *Config) error {
req := newIPVSRequest(ipvsCmdSetConfig)
req.Seq = atomic.AddUint32(&i.seq, 1)
req.AddData(nl.NewRtAttr(ipvsCmdAttrTimeoutTCP, nl.Uint32Attr(uint32(c.TimeoutTCP.Seconds()))))
req.AddData(nl.NewRtAttr(ipvsCmdAttrTimeoutTCPFin, nl.Uint32Attr(uint32(c.TimeoutTCPFin.Seconds()))))
req.AddData(nl.NewRtAttr(ipvsCmdAttrTimeoutUDP, nl.Uint32Attr(uint32(c.TimeoutUDP.Seconds()))))
_, err := execute(i.sock, req, 0)
return err
}
|
go
|
func (i *Handle) doSetConfigCmd(c *Config) error {
req := newIPVSRequest(ipvsCmdSetConfig)
req.Seq = atomic.AddUint32(&i.seq, 1)
req.AddData(nl.NewRtAttr(ipvsCmdAttrTimeoutTCP, nl.Uint32Attr(uint32(c.TimeoutTCP.Seconds()))))
req.AddData(nl.NewRtAttr(ipvsCmdAttrTimeoutTCPFin, nl.Uint32Attr(uint32(c.TimeoutTCPFin.Seconds()))))
req.AddData(nl.NewRtAttr(ipvsCmdAttrTimeoutUDP, nl.Uint32Attr(uint32(c.TimeoutUDP.Seconds()))))
_, err := execute(i.sock, req, 0)
return err
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"doSetConfigCmd",
"(",
"c",
"*",
"Config",
")",
"error",
"{",
"req",
":=",
"newIPVSRequest",
"(",
"ipvsCmdSetConfig",
")",
"\n",
"req",
".",
"Seq",
"=",
"atomic",
".",
"AddUint32",
"(",
"&",
"i",
".",
"seq",
",",
"1",
")",
"\n\n",
"req",
".",
"AddData",
"(",
"nl",
".",
"NewRtAttr",
"(",
"ipvsCmdAttrTimeoutTCP",
",",
"nl",
".",
"Uint32Attr",
"(",
"uint32",
"(",
"c",
".",
"TimeoutTCP",
".",
"Seconds",
"(",
")",
")",
")",
")",
")",
"\n",
"req",
".",
"AddData",
"(",
"nl",
".",
"NewRtAttr",
"(",
"ipvsCmdAttrTimeoutTCPFin",
",",
"nl",
".",
"Uint32Attr",
"(",
"uint32",
"(",
"c",
".",
"TimeoutTCPFin",
".",
"Seconds",
"(",
")",
")",
")",
")",
")",
"\n",
"req",
".",
"AddData",
"(",
"nl",
".",
"NewRtAttr",
"(",
"ipvsCmdAttrTimeoutUDP",
",",
"nl",
".",
"Uint32Attr",
"(",
"uint32",
"(",
"c",
".",
"TimeoutUDP",
".",
"Seconds",
"(",
")",
")",
")",
")",
")",
"\n\n",
"_",
",",
"err",
":=",
"execute",
"(",
"i",
".",
"sock",
",",
"req",
",",
"0",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// doSetConfigCmd a wrapper function to be used by SetConfig
|
[
"doSetConfigCmd",
"a",
"wrapper",
"function",
"to",
"be",
"used",
"by",
"SetConfig"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/netlink.go#L548-L559
|
22,511
|
docker/libnetwork
|
drivers/bridge/setup_device.go
|
setupDeviceUp
|
func setupDeviceUp(config *networkConfiguration, i *bridgeInterface) error {
err := i.nlh.LinkSetUp(i.Link)
if err != nil {
return fmt.Errorf("Failed to set link up for %s: %v", config.BridgeName, err)
}
// Attempt to update the bridge interface to refresh the flags status,
// ignoring any failure to do so.
if lnk, err := i.nlh.LinkByName(config.BridgeName); err == nil {
i.Link = lnk
} else {
logrus.Warnf("Failed to retrieve link for interface (%s): %v", config.BridgeName, err)
}
return nil
}
|
go
|
func setupDeviceUp(config *networkConfiguration, i *bridgeInterface) error {
err := i.nlh.LinkSetUp(i.Link)
if err != nil {
return fmt.Errorf("Failed to set link up for %s: %v", config.BridgeName, err)
}
// Attempt to update the bridge interface to refresh the flags status,
// ignoring any failure to do so.
if lnk, err := i.nlh.LinkByName(config.BridgeName); err == nil {
i.Link = lnk
} else {
logrus.Warnf("Failed to retrieve link for interface (%s): %v", config.BridgeName, err)
}
return nil
}
|
[
"func",
"setupDeviceUp",
"(",
"config",
"*",
"networkConfiguration",
",",
"i",
"*",
"bridgeInterface",
")",
"error",
"{",
"err",
":=",
"i",
".",
"nlh",
".",
"LinkSetUp",
"(",
"i",
".",
"Link",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"config",
".",
"BridgeName",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Attempt to update the bridge interface to refresh the flags status,",
"// ignoring any failure to do so.",
"if",
"lnk",
",",
"err",
":=",
"i",
".",
"nlh",
".",
"LinkByName",
"(",
"config",
".",
"BridgeName",
")",
";",
"err",
"==",
"nil",
"{",
"i",
".",
"Link",
"=",
"lnk",
"\n",
"}",
"else",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"config",
".",
"BridgeName",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// SetupDeviceUp ups the given bridge interface.
|
[
"SetupDeviceUp",
"ups",
"the",
"given",
"bridge",
"interface",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/setup_device.go#L54-L68
|
22,512
|
docker/libnetwork
|
portallocator/portallocator.go
|
Error
|
func (e ErrPortAlreadyAllocated) Error() string {
return fmt.Sprintf("Bind for %s:%d failed: port is already allocated", e.ip, e.port)
}
|
go
|
func (e ErrPortAlreadyAllocated) Error() string {
return fmt.Sprintf("Bind for %s:%d failed: port is already allocated", e.ip, e.port)
}
|
[
"func",
"(",
"e",
"ErrPortAlreadyAllocated",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"ip",
",",
"e",
".",
"port",
")",
"\n",
"}"
] |
// Error is the implementation of error.Error interface
|
[
"Error",
"is",
"the",
"implementation",
"of",
"error",
".",
"Error",
"interface"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portallocator/portallocator.go#L59-L61
|
22,513
|
docker/libnetwork
|
portallocator/portallocator.go
|
RequestPort
|
func (p *PortAllocator) RequestPort(ip net.IP, proto string, port int) (int, error) {
return p.RequestPortInRange(ip, proto, port, port)
}
|
go
|
func (p *PortAllocator) RequestPort(ip net.IP, proto string, port int) (int, error) {
return p.RequestPortInRange(ip, proto, port, port)
}
|
[
"func",
"(",
"p",
"*",
"PortAllocator",
")",
"RequestPort",
"(",
"ip",
"net",
".",
"IP",
",",
"proto",
"string",
",",
"port",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"p",
".",
"RequestPortInRange",
"(",
"ip",
",",
"proto",
",",
"port",
",",
"port",
")",
"\n",
"}"
] |
// RequestPort requests new port from global ports pool for specified ip and proto.
// If port is 0 it returns first free port. Otherwise it checks port availability
// in proto's pool and returns that port or error if port is already busy.
|
[
"RequestPort",
"requests",
"new",
"port",
"from",
"global",
"ports",
"pool",
"for",
"specified",
"ip",
"and",
"proto",
".",
"If",
"port",
"is",
"0",
"it",
"returns",
"first",
"free",
"port",
".",
"Otherwise",
"it",
"checks",
"port",
"availability",
"in",
"proto",
"s",
"pool",
"and",
"returns",
"that",
"port",
"or",
"error",
"if",
"port",
"is",
"already",
"busy",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portallocator/portallocator.go#L110-L112
|
22,514
|
docker/libnetwork
|
portallocator/portallocator.go
|
ReleasePort
|
func (p *PortAllocator) ReleasePort(ip net.IP, proto string, port int) error {
p.mutex.Lock()
defer p.mutex.Unlock()
if ip == nil {
ip = defaultIP
}
protomap, ok := p.ipMap[ip.String()]
if !ok {
return nil
}
delete(protomap[proto].p, port)
return nil
}
|
go
|
func (p *PortAllocator) ReleasePort(ip net.IP, proto string, port int) error {
p.mutex.Lock()
defer p.mutex.Unlock()
if ip == nil {
ip = defaultIP
}
protomap, ok := p.ipMap[ip.String()]
if !ok {
return nil
}
delete(protomap[proto].p, port)
return nil
}
|
[
"func",
"(",
"p",
"*",
"PortAllocator",
")",
"ReleasePort",
"(",
"ip",
"net",
".",
"IP",
",",
"proto",
"string",
",",
"port",
"int",
")",
"error",
"{",
"p",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"ip",
"==",
"nil",
"{",
"ip",
"=",
"defaultIP",
"\n",
"}",
"\n",
"protomap",
",",
"ok",
":=",
"p",
".",
"ipMap",
"[",
"ip",
".",
"String",
"(",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"delete",
"(",
"protomap",
"[",
"proto",
"]",
".",
"p",
",",
"port",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ReleasePort releases port from global ports pool for specified ip and proto.
|
[
"ReleasePort",
"releases",
"port",
"from",
"global",
"ports",
"pool",
"for",
"specified",
"ip",
"and",
"proto",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portallocator/portallocator.go#L158-L171
|
22,515
|
docker/libnetwork
|
portallocator/portallocator.go
|
ReleaseAll
|
func (p *PortAllocator) ReleaseAll() error {
p.mutex.Lock()
p.ipMap = ipMapping{}
p.mutex.Unlock()
return nil
}
|
go
|
func (p *PortAllocator) ReleaseAll() error {
p.mutex.Lock()
p.ipMap = ipMapping{}
p.mutex.Unlock()
return nil
}
|
[
"func",
"(",
"p",
"*",
"PortAllocator",
")",
"ReleaseAll",
"(",
")",
"error",
"{",
"p",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"p",
".",
"ipMap",
"=",
"ipMapping",
"{",
"}",
"\n",
"p",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ReleaseAll releases all ports for all ips.
|
[
"ReleaseAll",
"releases",
"all",
"ports",
"for",
"all",
"ips",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portallocator/portallocator.go#L186-L191
|
22,516
|
docker/libnetwork
|
drivers/macvlan/macvlan_setup.go
|
createMacVlan
|
func createMacVlan(containerIfName, parent, macvlanMode string) (string, error) {
// Set the macvlan mode. Default is bridge mode
mode, err := setMacVlanMode(macvlanMode)
if err != nil {
return "", fmt.Errorf("Unsupported %s macvlan mode: %v", macvlanMode, 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", macvlanType, parent, err)
}
// Create a macvlan link
macvlan := &netlink.Macvlan{
LinkAttrs: netlink.LinkAttrs{
Name: containerIfName,
ParentIndex: parentLink.Attrs().Index,
},
Mode: mode,
}
if err := ns.NlHandle().LinkAdd(macvlan); 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", macvlanType, err)
}
return macvlan.Attrs().Name, nil
}
|
go
|
func createMacVlan(containerIfName, parent, macvlanMode string) (string, error) {
// Set the macvlan mode. Default is bridge mode
mode, err := setMacVlanMode(macvlanMode)
if err != nil {
return "", fmt.Errorf("Unsupported %s macvlan mode: %v", macvlanMode, 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", macvlanType, parent, err)
}
// Create a macvlan link
macvlan := &netlink.Macvlan{
LinkAttrs: netlink.LinkAttrs{
Name: containerIfName,
ParentIndex: parentLink.Attrs().Index,
},
Mode: mode,
}
if err := ns.NlHandle().LinkAdd(macvlan); 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", macvlanType, err)
}
return macvlan.Attrs().Name, nil
}
|
[
"func",
"createMacVlan",
"(",
"containerIfName",
",",
"parent",
",",
"macvlanMode",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Set the macvlan mode. Default is bridge mode",
"mode",
",",
"err",
":=",
"setMacVlanMode",
"(",
"macvlanMode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"macvlanMode",
",",
"err",
")",
"\n",
"}",
"\n",
"// verify the Docker host interface acting as the macvlan parent iface exists",
"if",
"!",
"parentExists",
"(",
"parent",
")",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"parent",
")",
"\n",
"}",
"\n",
"// Get the link for the master index (Example: the docker host eth iface)",
"parentLink",
",",
"err",
":=",
"ns",
".",
"NlHandle",
"(",
")",
".",
"LinkByName",
"(",
"parent",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"macvlanType",
",",
"parent",
",",
"err",
")",
"\n",
"}",
"\n",
"// Create a macvlan link",
"macvlan",
":=",
"&",
"netlink",
".",
"Macvlan",
"{",
"LinkAttrs",
":",
"netlink",
".",
"LinkAttrs",
"{",
"Name",
":",
"containerIfName",
",",
"ParentIndex",
":",
"parentLink",
".",
"Attrs",
"(",
")",
".",
"Index",
",",
"}",
",",
"Mode",
":",
"mode",
",",
"}",
"\n",
"if",
"err",
":=",
"ns",
".",
"NlHandle",
"(",
")",
".",
"LinkAdd",
"(",
"macvlan",
")",
";",
"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",
"(",
"\"",
"\"",
",",
"macvlanType",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"macvlan",
".",
"Attrs",
"(",
")",
".",
"Name",
",",
"nil",
"\n",
"}"
] |
// Create the macvlan slave specifying the source name
|
[
"Create",
"the",
"macvlan",
"slave",
"specifying",
"the",
"source",
"name"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/macvlan/macvlan_setup.go#L20-L49
|
22,517
|
docker/libnetwork
|
drivers/macvlan/macvlan_setup.go
|
setMacVlanMode
|
func setMacVlanMode(mode string) (netlink.MacvlanMode, error) {
switch mode {
case modePrivate:
return netlink.MACVLAN_MODE_PRIVATE, nil
case modeVepa:
return netlink.MACVLAN_MODE_VEPA, nil
case modeBridge:
return netlink.MACVLAN_MODE_BRIDGE, nil
case modePassthru:
return netlink.MACVLAN_MODE_PASSTHRU, nil
default:
return 0, fmt.Errorf("unknown macvlan mode: %s", mode)
}
}
|
go
|
func setMacVlanMode(mode string) (netlink.MacvlanMode, error) {
switch mode {
case modePrivate:
return netlink.MACVLAN_MODE_PRIVATE, nil
case modeVepa:
return netlink.MACVLAN_MODE_VEPA, nil
case modeBridge:
return netlink.MACVLAN_MODE_BRIDGE, nil
case modePassthru:
return netlink.MACVLAN_MODE_PASSTHRU, nil
default:
return 0, fmt.Errorf("unknown macvlan mode: %s", mode)
}
}
|
[
"func",
"setMacVlanMode",
"(",
"mode",
"string",
")",
"(",
"netlink",
".",
"MacvlanMode",
",",
"error",
")",
"{",
"switch",
"mode",
"{",
"case",
"modePrivate",
":",
"return",
"netlink",
".",
"MACVLAN_MODE_PRIVATE",
",",
"nil",
"\n",
"case",
"modeVepa",
":",
"return",
"netlink",
".",
"MACVLAN_MODE_VEPA",
",",
"nil",
"\n",
"case",
"modeBridge",
":",
"return",
"netlink",
".",
"MACVLAN_MODE_BRIDGE",
",",
"nil",
"\n",
"case",
"modePassthru",
":",
"return",
"netlink",
".",
"MACVLAN_MODE_PASSTHRU",
",",
"nil",
"\n",
"default",
":",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"mode",
")",
"\n",
"}",
"\n",
"}"
] |
// setMacVlanMode setter for one of the four macvlan port types
|
[
"setMacVlanMode",
"setter",
"for",
"one",
"of",
"the",
"four",
"macvlan",
"port",
"types"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/macvlan/macvlan_setup.go#L52-L65
|
22,518
|
docker/libnetwork
|
drivers/macvlan/macvlan_setup.go
|
delVlanLink
|
func delVlanLink(linkName string) error {
if strings.Contains(linkName, ".") {
_, _, err := parseVlan(linkName)
if err != nil {
return err
}
// delete the vlan subinterface
vlanLink, err := ns.NlHandle().LinkByName(linkName)
if err != nil {
return fmt.Errorf("failed to find interface %s on the Docker host : %v", linkName, err)
}
// verify a parent interface isn't being deleted
if vlanLink.Attrs().ParentIndex == 0 {
return fmt.Errorf("interface %s does not appear to be a slave device: %v", linkName, err)
}
// delete the macvlan slave device
if err := ns.NlHandle().LinkDel(vlanLink); err != nil {
return fmt.Errorf("failed to delete %s link: %v", linkName, err)
}
logrus.Debugf("Deleted a vlan tagged netlink subinterface: %s", linkName)
}
// if the subinterface doesn't parse to iface.vlan_id leave the interface in
// place since it could be a user specified name not created by the driver.
return nil
}
|
go
|
func delVlanLink(linkName string) error {
if strings.Contains(linkName, ".") {
_, _, err := parseVlan(linkName)
if err != nil {
return err
}
// delete the vlan subinterface
vlanLink, err := ns.NlHandle().LinkByName(linkName)
if err != nil {
return fmt.Errorf("failed to find interface %s on the Docker host : %v", linkName, err)
}
// verify a parent interface isn't being deleted
if vlanLink.Attrs().ParentIndex == 0 {
return fmt.Errorf("interface %s does not appear to be a slave device: %v", linkName, err)
}
// delete the macvlan slave device
if err := ns.NlHandle().LinkDel(vlanLink); err != nil {
return fmt.Errorf("failed to delete %s link: %v", linkName, err)
}
logrus.Debugf("Deleted a vlan tagged netlink subinterface: %s", linkName)
}
// if the subinterface doesn't parse to iface.vlan_id leave the interface in
// place since it could be a user specified name not created by the driver.
return nil
}
|
[
"func",
"delVlanLink",
"(",
"linkName",
"string",
")",
"error",
"{",
"if",
"strings",
".",
"Contains",
"(",
"linkName",
",",
"\"",
"\"",
")",
"{",
"_",
",",
"_",
",",
"err",
":=",
"parseVlan",
"(",
"linkName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// delete the vlan subinterface",
"vlanLink",
",",
"err",
":=",
"ns",
".",
"NlHandle",
"(",
")",
".",
"LinkByName",
"(",
"linkName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"linkName",
",",
"err",
")",
"\n",
"}",
"\n",
"// verify a parent interface isn't being deleted",
"if",
"vlanLink",
".",
"Attrs",
"(",
")",
".",
"ParentIndex",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"linkName",
",",
"err",
")",
"\n",
"}",
"\n",
"// delete the macvlan slave device",
"if",
"err",
":=",
"ns",
".",
"NlHandle",
"(",
")",
".",
"LinkDel",
"(",
"vlanLink",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"linkName",
",",
"err",
")",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"linkName",
")",
"\n",
"}",
"\n",
"// if the subinterface doesn't parse to iface.vlan_id leave the interface in",
"// place since it could be a user specified name not created by the driver.",
"return",
"nil",
"\n",
"}"
] |
// delVlanLink verifies only sub-interfaces with a vlan id get deleted
|
[
"delVlanLink",
"verifies",
"only",
"sub",
"-",
"interfaces",
"with",
"a",
"vlan",
"id",
"get",
"deleted"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/macvlan/macvlan_setup.go#L116-L140
|
22,519
|
docker/libnetwork
|
resolvconf/resolvconf.go
|
GetSpecific
|
func GetSpecific(path string) (*File, error) {
resolv, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
hash, err := ioutils.HashData(bytes.NewReader(resolv))
if err != nil {
return nil, err
}
return &File{Content: resolv, Hash: hash}, nil
}
|
go
|
func GetSpecific(path string) (*File, error) {
resolv, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
hash, err := ioutils.HashData(bytes.NewReader(resolv))
if err != nil {
return nil, err
}
return &File{Content: resolv, Hash: hash}, nil
}
|
[
"func",
"GetSpecific",
"(",
"path",
"string",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"resolv",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hash",
",",
"err",
":=",
"ioutils",
".",
"HashData",
"(",
"bytes",
".",
"NewReader",
"(",
"resolv",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"File",
"{",
"Content",
":",
"resolv",
",",
"Hash",
":",
"hash",
"}",
",",
"nil",
"\n",
"}"
] |
// GetSpecific returns the contents of the user specified resolv.conf file and its hash
|
[
"GetSpecific",
"returns",
"the",
"contents",
"of",
"the",
"user",
"specified",
"resolv",
".",
"conf",
"file",
"and",
"its",
"hash"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/resolvconf/resolvconf.go#L62-L72
|
22,520
|
docker/libnetwork
|
resolvconf/resolvconf.go
|
GetLastModified
|
func GetLastModified() *File {
lastModified.Lock()
defer lastModified.Unlock()
return &File{Content: lastModified.contents, Hash: lastModified.sha256}
}
|
go
|
func GetLastModified() *File {
lastModified.Lock()
defer lastModified.Unlock()
return &File{Content: lastModified.contents, Hash: lastModified.sha256}
}
|
[
"func",
"GetLastModified",
"(",
")",
"*",
"File",
"{",
"lastModified",
".",
"Lock",
"(",
")",
"\n",
"defer",
"lastModified",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"&",
"File",
"{",
"Content",
":",
"lastModified",
".",
"contents",
",",
"Hash",
":",
"lastModified",
".",
"sha256",
"}",
"\n",
"}"
] |
// GetLastModified retrieves the last used contents and hash of the host resolv.conf.
// Used by containers updating on restart
|
[
"GetLastModified",
"retrieves",
"the",
"last",
"used",
"contents",
"and",
"hash",
"of",
"the",
"host",
"resolv",
".",
"conf",
".",
"Used",
"by",
"containers",
"updating",
"on",
"restart"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/resolvconf/resolvconf.go#L100-L105
|
22,521
|
docker/libnetwork
|
resolvconf/resolvconf.go
|
getLines
|
func getLines(input []byte, commentMarker []byte) [][]byte {
lines := bytes.Split(input, []byte("\n"))
var output [][]byte
for _, currentLine := range lines {
var commentIndex = bytes.Index(currentLine, commentMarker)
if commentIndex == -1 {
output = append(output, currentLine)
} else {
output = append(output, currentLine[:commentIndex])
}
}
return output
}
|
go
|
func getLines(input []byte, commentMarker []byte) [][]byte {
lines := bytes.Split(input, []byte("\n"))
var output [][]byte
for _, currentLine := range lines {
var commentIndex = bytes.Index(currentLine, commentMarker)
if commentIndex == -1 {
output = append(output, currentLine)
} else {
output = append(output, currentLine[:commentIndex])
}
}
return output
}
|
[
"func",
"getLines",
"(",
"input",
"[",
"]",
"byte",
",",
"commentMarker",
"[",
"]",
"byte",
")",
"[",
"]",
"[",
"]",
"byte",
"{",
"lines",
":=",
"bytes",
".",
"Split",
"(",
"input",
",",
"[",
"]",
"byte",
"(",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"var",
"output",
"[",
"]",
"[",
"]",
"byte",
"\n",
"for",
"_",
",",
"currentLine",
":=",
"range",
"lines",
"{",
"var",
"commentIndex",
"=",
"bytes",
".",
"Index",
"(",
"currentLine",
",",
"commentMarker",
")",
"\n",
"if",
"commentIndex",
"==",
"-",
"1",
"{",
"output",
"=",
"append",
"(",
"output",
",",
"currentLine",
")",
"\n",
"}",
"else",
"{",
"output",
"=",
"append",
"(",
"output",
",",
"currentLine",
"[",
":",
"commentIndex",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"output",
"\n",
"}"
] |
// getLines parses input into lines and strips away comments.
|
[
"getLines",
"parses",
"input",
"into",
"lines",
"and",
"strips",
"away",
"comments",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/resolvconf/resolvconf.go#L139-L151
|
22,522
|
docker/libnetwork
|
resolvconf/resolvconf.go
|
Build
|
func Build(path string, dns, dnsSearch, dnsOptions []string) (*File, error) {
content := bytes.NewBuffer(nil)
if len(dnsSearch) > 0 {
if searchString := strings.Join(dnsSearch, " "); strings.Trim(searchString, " ") != "." {
if _, err := content.WriteString("search " + searchString + "\n"); err != nil {
return nil, err
}
}
}
for _, dns := range dns {
if _, err := content.WriteString("nameserver " + dns + "\n"); err != nil {
return nil, err
}
}
if len(dnsOptions) > 0 {
if optsString := strings.Join(dnsOptions, " "); strings.Trim(optsString, " ") != "" {
if _, err := content.WriteString("options " + optsString + "\n"); err != nil {
return nil, err
}
}
}
hash, err := ioutils.HashData(bytes.NewReader(content.Bytes()))
if err != nil {
return nil, err
}
return &File{Content: content.Bytes(), Hash: hash}, ioutil.WriteFile(path, content.Bytes(), 0644)
}
|
go
|
func Build(path string, dns, dnsSearch, dnsOptions []string) (*File, error) {
content := bytes.NewBuffer(nil)
if len(dnsSearch) > 0 {
if searchString := strings.Join(dnsSearch, " "); strings.Trim(searchString, " ") != "." {
if _, err := content.WriteString("search " + searchString + "\n"); err != nil {
return nil, err
}
}
}
for _, dns := range dns {
if _, err := content.WriteString("nameserver " + dns + "\n"); err != nil {
return nil, err
}
}
if len(dnsOptions) > 0 {
if optsString := strings.Join(dnsOptions, " "); strings.Trim(optsString, " ") != "" {
if _, err := content.WriteString("options " + optsString + "\n"); err != nil {
return nil, err
}
}
}
hash, err := ioutils.HashData(bytes.NewReader(content.Bytes()))
if err != nil {
return nil, err
}
return &File{Content: content.Bytes(), Hash: hash}, ioutil.WriteFile(path, content.Bytes(), 0644)
}
|
[
"func",
"Build",
"(",
"path",
"string",
",",
"dns",
",",
"dnsSearch",
",",
"dnsOptions",
"[",
"]",
"string",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"content",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"if",
"len",
"(",
"dnsSearch",
")",
">",
"0",
"{",
"if",
"searchString",
":=",
"strings",
".",
"Join",
"(",
"dnsSearch",
",",
"\"",
"\"",
")",
";",
"strings",
".",
"Trim",
"(",
"searchString",
",",
"\"",
"\"",
")",
"!=",
"\"",
"\"",
"{",
"if",
"_",
",",
"err",
":=",
"content",
".",
"WriteString",
"(",
"\"",
"\"",
"+",
"searchString",
"+",
"\"",
"\\n",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"dns",
":=",
"range",
"dns",
"{",
"if",
"_",
",",
"err",
":=",
"content",
".",
"WriteString",
"(",
"\"",
"\"",
"+",
"dns",
"+",
"\"",
"\\n",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"dnsOptions",
")",
">",
"0",
"{",
"if",
"optsString",
":=",
"strings",
".",
"Join",
"(",
"dnsOptions",
",",
"\"",
"\"",
")",
";",
"strings",
".",
"Trim",
"(",
"optsString",
",",
"\"",
"\"",
")",
"!=",
"\"",
"\"",
"{",
"if",
"_",
",",
"err",
":=",
"content",
".",
"WriteString",
"(",
"\"",
"\"",
"+",
"optsString",
"+",
"\"",
"\\n",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"hash",
",",
"err",
":=",
"ioutils",
".",
"HashData",
"(",
"bytes",
".",
"NewReader",
"(",
"content",
".",
"Bytes",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"File",
"{",
"Content",
":",
"content",
".",
"Bytes",
"(",
")",
",",
"Hash",
":",
"hash",
"}",
",",
"ioutil",
".",
"WriteFile",
"(",
"path",
",",
"content",
".",
"Bytes",
"(",
")",
",",
"0644",
")",
"\n",
"}"
] |
// Build writes a configuration file to path containing a "nameserver" entry
// for every element in dns, a "search" entry for every element in
// dnsSearch, and an "options" entry for every element in dnsOptions.
|
[
"Build",
"writes",
"a",
"configuration",
"file",
"to",
"path",
"containing",
"a",
"nameserver",
"entry",
"for",
"every",
"element",
"in",
"dns",
"a",
"search",
"entry",
"for",
"every",
"element",
"in",
"dnsSearch",
"and",
"an",
"options",
"entry",
"for",
"every",
"element",
"in",
"dnsOptions",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/resolvconf/resolvconf.go#L223-L251
|
22,523
|
docker/libnetwork
|
ipam/allocator.go
|
NewAllocator
|
func NewAllocator(lcDs, glDs datastore.DataStore) (*Allocator, error) {
a := &Allocator{}
// Load predefined subnet pools
a.predefined = map[string][]*net.IPNet{
localAddressSpace: ipamutils.GetLocalScopeDefaultNetworks(),
globalAddressSpace: ipamutils.GetGlobalScopeDefaultNetworks(),
}
// Initialize asIndices map
a.predefinedStartIndices = make(map[string]int)
// Initialize bitseq map
a.addresses = make(map[SubnetKey]*bitseq.Handle)
// Initialize address spaces
a.addrSpaces = make(map[string]*addrSpace)
for _, aspc := range []struct {
as string
ds datastore.DataStore
}{
{localAddressSpace, lcDs},
{globalAddressSpace, glDs},
} {
a.initializeAddressSpace(aspc.as, aspc.ds)
}
return a, nil
}
|
go
|
func NewAllocator(lcDs, glDs datastore.DataStore) (*Allocator, error) {
a := &Allocator{}
// Load predefined subnet pools
a.predefined = map[string][]*net.IPNet{
localAddressSpace: ipamutils.GetLocalScopeDefaultNetworks(),
globalAddressSpace: ipamutils.GetGlobalScopeDefaultNetworks(),
}
// Initialize asIndices map
a.predefinedStartIndices = make(map[string]int)
// Initialize bitseq map
a.addresses = make(map[SubnetKey]*bitseq.Handle)
// Initialize address spaces
a.addrSpaces = make(map[string]*addrSpace)
for _, aspc := range []struct {
as string
ds datastore.DataStore
}{
{localAddressSpace, lcDs},
{globalAddressSpace, glDs},
} {
a.initializeAddressSpace(aspc.as, aspc.ds)
}
return a, nil
}
|
[
"func",
"NewAllocator",
"(",
"lcDs",
",",
"glDs",
"datastore",
".",
"DataStore",
")",
"(",
"*",
"Allocator",
",",
"error",
")",
"{",
"a",
":=",
"&",
"Allocator",
"{",
"}",
"\n\n",
"// Load predefined subnet pools",
"a",
".",
"predefined",
"=",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"net",
".",
"IPNet",
"{",
"localAddressSpace",
":",
"ipamutils",
".",
"GetLocalScopeDefaultNetworks",
"(",
")",
",",
"globalAddressSpace",
":",
"ipamutils",
".",
"GetGlobalScopeDefaultNetworks",
"(",
")",
",",
"}",
"\n\n",
"// Initialize asIndices map",
"a",
".",
"predefinedStartIndices",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n\n",
"// Initialize bitseq map",
"a",
".",
"addresses",
"=",
"make",
"(",
"map",
"[",
"SubnetKey",
"]",
"*",
"bitseq",
".",
"Handle",
")",
"\n\n",
"// Initialize address spaces",
"a",
".",
"addrSpaces",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"addrSpace",
")",
"\n",
"for",
"_",
",",
"aspc",
":=",
"range",
"[",
"]",
"struct",
"{",
"as",
"string",
"\n",
"ds",
"datastore",
".",
"DataStore",
"\n",
"}",
"{",
"{",
"localAddressSpace",
",",
"lcDs",
"}",
",",
"{",
"globalAddressSpace",
",",
"glDs",
"}",
",",
"}",
"{",
"a",
".",
"initializeAddressSpace",
"(",
"aspc",
".",
"as",
",",
"aspc",
".",
"ds",
")",
"\n",
"}",
"\n\n",
"return",
"a",
",",
"nil",
"\n",
"}"
] |
// NewAllocator returns an instance of libnetwork ipam
|
[
"NewAllocator",
"returns",
"an",
"instance",
"of",
"libnetwork",
"ipam"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/allocator.go#L44-L73
|
22,524
|
docker/libnetwork
|
ipam/allocator.go
|
checkConsistency
|
func (a *Allocator) checkConsistency(as string) {
var sKeyList []SubnetKey
// Retrieve this address space's configuration and bitmasks from the datastore
a.refresh(as)
a.Lock()
aSpace, ok := a.addrSpaces[as]
a.Unlock()
if !ok {
return
}
a.updateBitMasks(aSpace)
aSpace.Lock()
for sk, pd := range aSpace.subnets {
if pd.Range != nil {
continue
}
sKeyList = append(sKeyList, sk)
}
aSpace.Unlock()
for _, sk := range sKeyList {
a.Lock()
bm := a.addresses[sk]
a.Unlock()
if err := bm.CheckConsistency(); err != nil {
logrus.Warnf("Error while running consistency check for %s: %v", sk, err)
}
}
}
|
go
|
func (a *Allocator) checkConsistency(as string) {
var sKeyList []SubnetKey
// Retrieve this address space's configuration and bitmasks from the datastore
a.refresh(as)
a.Lock()
aSpace, ok := a.addrSpaces[as]
a.Unlock()
if !ok {
return
}
a.updateBitMasks(aSpace)
aSpace.Lock()
for sk, pd := range aSpace.subnets {
if pd.Range != nil {
continue
}
sKeyList = append(sKeyList, sk)
}
aSpace.Unlock()
for _, sk := range sKeyList {
a.Lock()
bm := a.addresses[sk]
a.Unlock()
if err := bm.CheckConsistency(); err != nil {
logrus.Warnf("Error while running consistency check for %s: %v", sk, err)
}
}
}
|
[
"func",
"(",
"a",
"*",
"Allocator",
")",
"checkConsistency",
"(",
"as",
"string",
")",
"{",
"var",
"sKeyList",
"[",
"]",
"SubnetKey",
"\n\n",
"// Retrieve this address space's configuration and bitmasks from the datastore",
"a",
".",
"refresh",
"(",
"as",
")",
"\n",
"a",
".",
"Lock",
"(",
")",
"\n",
"aSpace",
",",
"ok",
":=",
"a",
".",
"addrSpaces",
"[",
"as",
"]",
"\n",
"a",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"a",
".",
"updateBitMasks",
"(",
"aSpace",
")",
"\n\n",
"aSpace",
".",
"Lock",
"(",
")",
"\n",
"for",
"sk",
",",
"pd",
":=",
"range",
"aSpace",
".",
"subnets",
"{",
"if",
"pd",
".",
"Range",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"sKeyList",
"=",
"append",
"(",
"sKeyList",
",",
"sk",
")",
"\n",
"}",
"\n",
"aSpace",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"sk",
":=",
"range",
"sKeyList",
"{",
"a",
".",
"Lock",
"(",
")",
"\n",
"bm",
":=",
"a",
".",
"addresses",
"[",
"sk",
"]",
"\n",
"a",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
":=",
"bm",
".",
"CheckConsistency",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"sk",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Checks for and fixes damaged bitmask.
|
[
"Checks",
"for",
"and",
"fixes",
"damaged",
"bitmask",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/allocator.go#L118-L148
|
22,525
|
docker/libnetwork
|
ipam/allocator.go
|
DiscoverNew
|
func (a *Allocator) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
if dType != discoverapi.DatastoreConfig {
return nil
}
dsc, ok := data.(discoverapi.DatastoreConfigData)
if !ok {
return types.InternalErrorf("incorrect data in datastore update notification: %v", data)
}
ds, err := datastore.NewDataStoreFromConfig(dsc)
if err != nil {
return err
}
return a.initializeAddressSpace(globalAddressSpace, ds)
}
|
go
|
func (a *Allocator) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error {
if dType != discoverapi.DatastoreConfig {
return nil
}
dsc, ok := data.(discoverapi.DatastoreConfigData)
if !ok {
return types.InternalErrorf("incorrect data in datastore update notification: %v", data)
}
ds, err := datastore.NewDataStoreFromConfig(dsc)
if err != nil {
return err
}
return a.initializeAddressSpace(globalAddressSpace, ds)
}
|
[
"func",
"(",
"a",
"*",
"Allocator",
")",
"DiscoverNew",
"(",
"dType",
"discoverapi",
".",
"DiscoveryType",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"dType",
"!=",
"discoverapi",
".",
"DatastoreConfig",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"dsc",
",",
"ok",
":=",
"data",
".",
"(",
"discoverapi",
".",
"DatastoreConfigData",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"types",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"data",
")",
"\n",
"}",
"\n\n",
"ds",
",",
"err",
":=",
"datastore",
".",
"NewDataStoreFromConfig",
"(",
"dsc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"a",
".",
"initializeAddressSpace",
"(",
"globalAddressSpace",
",",
"ds",
")",
"\n",
"}"
] |
// DiscoverNew informs the allocator about a new global scope datastore
|
[
"DiscoverNew",
"informs",
"the",
"allocator",
"about",
"a",
"new",
"global",
"scope",
"datastore"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/allocator.go#L178-L194
|
22,526
|
docker/libnetwork
|
ipam/allocator.go
|
RequestPool
|
func (a *Allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
logrus.Debugf("RequestPool(%s, %s, %s, %v, %t)", addressSpace, pool, subPool, options, v6)
k, nw, ipr, err := a.parsePoolRequest(addressSpace, pool, subPool, v6)
if err != nil {
return "", nil, nil, types.InternalErrorf("failed to parse pool request for address space %q pool %q subpool %q: %v", addressSpace, pool, subPool, err)
}
pdf := k == nil
retry:
if pdf {
if nw, err = a.getPredefinedPool(addressSpace, v6); err != nil {
return "", nil, nil, err
}
k = &SubnetKey{AddressSpace: addressSpace, Subnet: nw.String()}
}
if err := a.refresh(addressSpace); err != nil {
return "", nil, nil, err
}
aSpace, err := a.getAddrSpace(addressSpace)
if err != nil {
return "", nil, nil, err
}
insert, err := aSpace.updatePoolDBOnAdd(*k, nw, ipr, pdf)
if err != nil {
if _, ok := err.(types.MaskableError); ok {
logrus.Debugf("Retrying predefined pool search: %v", err)
goto retry
}
return "", nil, nil, err
}
if err := a.writeToStore(aSpace); err != nil {
if _, ok := err.(types.RetryError); !ok {
return "", nil, nil, types.InternalErrorf("pool configuration failed because of %s", err.Error())
}
goto retry
}
return k.String(), nw, nil, insert()
}
|
go
|
func (a *Allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
logrus.Debugf("RequestPool(%s, %s, %s, %v, %t)", addressSpace, pool, subPool, options, v6)
k, nw, ipr, err := a.parsePoolRequest(addressSpace, pool, subPool, v6)
if err != nil {
return "", nil, nil, types.InternalErrorf("failed to parse pool request for address space %q pool %q subpool %q: %v", addressSpace, pool, subPool, err)
}
pdf := k == nil
retry:
if pdf {
if nw, err = a.getPredefinedPool(addressSpace, v6); err != nil {
return "", nil, nil, err
}
k = &SubnetKey{AddressSpace: addressSpace, Subnet: nw.String()}
}
if err := a.refresh(addressSpace); err != nil {
return "", nil, nil, err
}
aSpace, err := a.getAddrSpace(addressSpace)
if err != nil {
return "", nil, nil, err
}
insert, err := aSpace.updatePoolDBOnAdd(*k, nw, ipr, pdf)
if err != nil {
if _, ok := err.(types.MaskableError); ok {
logrus.Debugf("Retrying predefined pool search: %v", err)
goto retry
}
return "", nil, nil, err
}
if err := a.writeToStore(aSpace); err != nil {
if _, ok := err.(types.RetryError); !ok {
return "", nil, nil, types.InternalErrorf("pool configuration failed because of %s", err.Error())
}
goto retry
}
return k.String(), nw, nil, insert()
}
|
[
"func",
"(",
"a",
"*",
"Allocator",
")",
"RequestPool",
"(",
"addressSpace",
",",
"pool",
",",
"subPool",
"string",
",",
"options",
"map",
"[",
"string",
"]",
"string",
",",
"v6",
"bool",
")",
"(",
"string",
",",
"*",
"net",
".",
"IPNet",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"addressSpace",
",",
"pool",
",",
"subPool",
",",
"options",
",",
"v6",
")",
"\n\n",
"k",
",",
"nw",
",",
"ipr",
",",
"err",
":=",
"a",
".",
"parsePoolRequest",
"(",
"addressSpace",
",",
"pool",
",",
"subPool",
",",
"v6",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"types",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"addressSpace",
",",
"pool",
",",
"subPool",
",",
"err",
")",
"\n",
"}",
"\n\n",
"pdf",
":=",
"k",
"==",
"nil",
"\n\n",
"retry",
":",
"if",
"pdf",
"{",
"if",
"nw",
",",
"err",
"=",
"a",
".",
"getPredefinedPool",
"(",
"addressSpace",
",",
"v6",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"k",
"=",
"&",
"SubnetKey",
"{",
"AddressSpace",
":",
"addressSpace",
",",
"Subnet",
":",
"nw",
".",
"String",
"(",
")",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"a",
".",
"refresh",
"(",
"addressSpace",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"aSpace",
",",
"err",
":=",
"a",
".",
"getAddrSpace",
"(",
"addressSpace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"insert",
",",
"err",
":=",
"aSpace",
".",
"updatePoolDBOnAdd",
"(",
"*",
"k",
",",
"nw",
",",
"ipr",
",",
"pdf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"types",
".",
"MaskableError",
")",
";",
"ok",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"goto",
"retry",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"a",
".",
"writeToStore",
"(",
"aSpace",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"types",
".",
"RetryError",
")",
";",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"types",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"goto",
"retry",
"\n",
"}",
"\n\n",
"return",
"k",
".",
"String",
"(",
")",
",",
"nw",
",",
"nil",
",",
"insert",
"(",
")",
"\n",
"}"
] |
// RequestPool returns an address pool along with its unique id.
// addressSpace must be a valid address space name and must not be the empty string.
// If pool is the empty string then the default predefined pool for addressSpace will be used, otherwise pool must be a valid IP address and length in CIDR notation.
// If subPool is not empty, it must be a valid IP address and length in CIDR notation which is a sub-range of pool.
// subPool must be empty if pool is empty.
|
[
"RequestPool",
"returns",
"an",
"address",
"pool",
"along",
"with",
"its",
"unique",
"id",
".",
"addressSpace",
"must",
"be",
"a",
"valid",
"address",
"space",
"name",
"and",
"must",
"not",
"be",
"the",
"empty",
"string",
".",
"If",
"pool",
"is",
"the",
"empty",
"string",
"then",
"the",
"default",
"predefined",
"pool",
"for",
"addressSpace",
"will",
"be",
"used",
"otherwise",
"pool",
"must",
"be",
"a",
"valid",
"IP",
"address",
"and",
"length",
"in",
"CIDR",
"notation",
".",
"If",
"subPool",
"is",
"not",
"empty",
"it",
"must",
"be",
"a",
"valid",
"IP",
"address",
"and",
"length",
"in",
"CIDR",
"notation",
"which",
"is",
"a",
"sub",
"-",
"range",
"of",
"pool",
".",
"subPool",
"must",
"be",
"empty",
"if",
"pool",
"is",
"empty",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/allocator.go#L211-L256
|
22,527
|
docker/libnetwork
|
ipam/allocator.go
|
ReleasePool
|
func (a *Allocator) ReleasePool(poolID string) error {
logrus.Debugf("ReleasePool(%s)", poolID)
k := SubnetKey{}
if err := k.FromString(poolID); err != nil {
return types.BadRequestErrorf("invalid pool id: %s", poolID)
}
retry:
if err := a.refresh(k.AddressSpace); err != nil {
return err
}
aSpace, err := a.getAddrSpace(k.AddressSpace)
if err != nil {
return err
}
remove, err := aSpace.updatePoolDBOnRemoval(k)
if err != nil {
return err
}
if err = a.writeToStore(aSpace); err != nil {
if _, ok := err.(types.RetryError); !ok {
return types.InternalErrorf("pool (%s) removal failed because of %v", poolID, err)
}
goto retry
}
return remove()
}
|
go
|
func (a *Allocator) ReleasePool(poolID string) error {
logrus.Debugf("ReleasePool(%s)", poolID)
k := SubnetKey{}
if err := k.FromString(poolID); err != nil {
return types.BadRequestErrorf("invalid pool id: %s", poolID)
}
retry:
if err := a.refresh(k.AddressSpace); err != nil {
return err
}
aSpace, err := a.getAddrSpace(k.AddressSpace)
if err != nil {
return err
}
remove, err := aSpace.updatePoolDBOnRemoval(k)
if err != nil {
return err
}
if err = a.writeToStore(aSpace); err != nil {
if _, ok := err.(types.RetryError); !ok {
return types.InternalErrorf("pool (%s) removal failed because of %v", poolID, err)
}
goto retry
}
return remove()
}
|
[
"func",
"(",
"a",
"*",
"Allocator",
")",
"ReleasePool",
"(",
"poolID",
"string",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"poolID",
")",
"\n",
"k",
":=",
"SubnetKey",
"{",
"}",
"\n",
"if",
"err",
":=",
"k",
".",
"FromString",
"(",
"poolID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
",",
"poolID",
")",
"\n",
"}",
"\n\n",
"retry",
":",
"if",
"err",
":=",
"a",
".",
"refresh",
"(",
"k",
".",
"AddressSpace",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"aSpace",
",",
"err",
":=",
"a",
".",
"getAddrSpace",
"(",
"k",
".",
"AddressSpace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"remove",
",",
"err",
":=",
"aSpace",
".",
"updatePoolDBOnRemoval",
"(",
"k",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"a",
".",
"writeToStore",
"(",
"aSpace",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"types",
".",
"RetryError",
")",
";",
"!",
"ok",
"{",
"return",
"types",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"poolID",
",",
"err",
")",
"\n",
"}",
"\n",
"goto",
"retry",
"\n",
"}",
"\n\n",
"return",
"remove",
"(",
")",
"\n",
"}"
] |
// ReleasePool releases the address pool identified by the passed id
|
[
"ReleasePool",
"releases",
"the",
"address",
"pool",
"identified",
"by",
"the",
"passed",
"id"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/allocator.go#L259-L289
|
22,528
|
docker/libnetwork
|
ipam/allocator.go
|
getAddrSpace
|
func (a *Allocator) getAddrSpace(as string) (*addrSpace, error) {
a.Lock()
defer a.Unlock()
aSpace, ok := a.addrSpaces[as]
if !ok {
return nil, types.BadRequestErrorf("cannot find address space %s (most likely the backing datastore is not configured)", as)
}
return aSpace, nil
}
|
go
|
func (a *Allocator) getAddrSpace(as string) (*addrSpace, error) {
a.Lock()
defer a.Unlock()
aSpace, ok := a.addrSpaces[as]
if !ok {
return nil, types.BadRequestErrorf("cannot find address space %s (most likely the backing datastore is not configured)", as)
}
return aSpace, nil
}
|
[
"func",
"(",
"a",
"*",
"Allocator",
")",
"getAddrSpace",
"(",
"as",
"string",
")",
"(",
"*",
"addrSpace",
",",
"error",
")",
"{",
"a",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"Unlock",
"(",
")",
"\n",
"aSpace",
",",
"ok",
":=",
"a",
".",
"addrSpaces",
"[",
"as",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
",",
"as",
")",
"\n",
"}",
"\n",
"return",
"aSpace",
",",
"nil",
"\n",
"}"
] |
// Given the address space, returns the local or global PoolConfig based on whether the
// address space is local or global. AddressSpace locality is registered with IPAM out of band.
|
[
"Given",
"the",
"address",
"space",
"returns",
"the",
"local",
"or",
"global",
"PoolConfig",
"based",
"on",
"whether",
"the",
"address",
"space",
"is",
"local",
"or",
"global",
".",
"AddressSpace",
"locality",
"is",
"registered",
"with",
"IPAM",
"out",
"of",
"band",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/allocator.go#L293-L301
|
22,529
|
docker/libnetwork
|
ipam/allocator.go
|
parsePoolRequest
|
func (a *Allocator) parsePoolRequest(addressSpace, pool, subPool string, v6 bool) (*SubnetKey, *net.IPNet, *AddressRange, error) {
var (
nw *net.IPNet
ipr *AddressRange
err error
)
if addressSpace == "" {
return nil, nil, nil, ipamapi.ErrInvalidAddressSpace
}
if pool == "" && subPool != "" {
return nil, nil, nil, ipamapi.ErrInvalidSubPool
}
if pool == "" {
return nil, nil, nil, nil
}
if _, nw, err = net.ParseCIDR(pool); err != nil {
return nil, nil, nil, ipamapi.ErrInvalidPool
}
if subPool != "" {
if ipr, err = getAddressRange(subPool, nw); err != nil {
return nil, nil, nil, err
}
}
return &SubnetKey{AddressSpace: addressSpace, Subnet: nw.String(), ChildSubnet: subPool}, nw, ipr, nil
}
|
go
|
func (a *Allocator) parsePoolRequest(addressSpace, pool, subPool string, v6 bool) (*SubnetKey, *net.IPNet, *AddressRange, error) {
var (
nw *net.IPNet
ipr *AddressRange
err error
)
if addressSpace == "" {
return nil, nil, nil, ipamapi.ErrInvalidAddressSpace
}
if pool == "" && subPool != "" {
return nil, nil, nil, ipamapi.ErrInvalidSubPool
}
if pool == "" {
return nil, nil, nil, nil
}
if _, nw, err = net.ParseCIDR(pool); err != nil {
return nil, nil, nil, ipamapi.ErrInvalidPool
}
if subPool != "" {
if ipr, err = getAddressRange(subPool, nw); err != nil {
return nil, nil, nil, err
}
}
return &SubnetKey{AddressSpace: addressSpace, Subnet: nw.String(), ChildSubnet: subPool}, nw, ipr, nil
}
|
[
"func",
"(",
"a",
"*",
"Allocator",
")",
"parsePoolRequest",
"(",
"addressSpace",
",",
"pool",
",",
"subPool",
"string",
",",
"v6",
"bool",
")",
"(",
"*",
"SubnetKey",
",",
"*",
"net",
".",
"IPNet",
",",
"*",
"AddressRange",
",",
"error",
")",
"{",
"var",
"(",
"nw",
"*",
"net",
".",
"IPNet",
"\n",
"ipr",
"*",
"AddressRange",
"\n",
"err",
"error",
"\n",
")",
"\n\n",
"if",
"addressSpace",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"ipamapi",
".",
"ErrInvalidAddressSpace",
"\n",
"}",
"\n\n",
"if",
"pool",
"==",
"\"",
"\"",
"&&",
"subPool",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"ipamapi",
".",
"ErrInvalidSubPool",
"\n",
"}",
"\n\n",
"if",
"pool",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"nw",
",",
"err",
"=",
"net",
".",
"ParseCIDR",
"(",
"pool",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"ipamapi",
".",
"ErrInvalidPool",
"\n",
"}",
"\n\n",
"if",
"subPool",
"!=",
"\"",
"\"",
"{",
"if",
"ipr",
",",
"err",
"=",
"getAddressRange",
"(",
"subPool",
",",
"nw",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"SubnetKey",
"{",
"AddressSpace",
":",
"addressSpace",
",",
"Subnet",
":",
"nw",
".",
"String",
"(",
")",
",",
"ChildSubnet",
":",
"subPool",
"}",
",",
"nw",
",",
"ipr",
",",
"nil",
"\n",
"}"
] |
// parsePoolRequest parses and validates a request to create a new pool under addressSpace and returns
// a SubnetKey, network and range describing the request.
|
[
"parsePoolRequest",
"parses",
"and",
"validates",
"a",
"request",
"to",
"create",
"a",
"new",
"pool",
"under",
"addressSpace",
"and",
"returns",
"a",
"SubnetKey",
"network",
"and",
"range",
"describing",
"the",
"request",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/allocator.go#L305-L335
|
22,530
|
docker/libnetwork
|
ipam/allocator.go
|
RequestAddress
|
func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[string]string) (*net.IPNet, map[string]string, error) {
logrus.Debugf("RequestAddress(%s, %v, %v)", poolID, prefAddress, opts)
k := SubnetKey{}
if err := k.FromString(poolID); err != nil {
return nil, nil, types.BadRequestErrorf("invalid pool id: %s", poolID)
}
if err := a.refresh(k.AddressSpace); err != nil {
return nil, nil, err
}
aSpace, err := a.getAddrSpace(k.AddressSpace)
if err != nil {
return nil, nil, err
}
aSpace.Lock()
p, ok := aSpace.subnets[k]
if !ok {
aSpace.Unlock()
return nil, nil, types.NotFoundErrorf("cannot find address pool for poolID:%s", poolID)
}
if prefAddress != nil && !p.Pool.Contains(prefAddress) {
aSpace.Unlock()
return nil, nil, ipamapi.ErrIPOutOfRange
}
c := p
for c.Range != nil {
k = c.ParentKey
c = aSpace.subnets[k]
}
aSpace.Unlock()
bm, err := a.retrieveBitmask(k, c.Pool)
if err != nil {
return nil, nil, types.InternalErrorf("could not find bitmask in datastore for %s on address %v request from pool %s: %v",
k.String(), prefAddress, poolID, err)
}
// In order to request for a serial ip address allocation, callers can pass in the option to request
// IP allocation serially or first available IP in the subnet
var serial bool
if opts != nil {
if val, ok := opts[ipamapi.AllocSerialPrefix]; ok {
serial = (val == "true")
}
}
ip, err := a.getAddress(p.Pool, bm, prefAddress, p.Range, serial)
if err != nil {
return nil, nil, err
}
return &net.IPNet{IP: ip, Mask: p.Pool.Mask}, nil, nil
}
|
go
|
func (a *Allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[string]string) (*net.IPNet, map[string]string, error) {
logrus.Debugf("RequestAddress(%s, %v, %v)", poolID, prefAddress, opts)
k := SubnetKey{}
if err := k.FromString(poolID); err != nil {
return nil, nil, types.BadRequestErrorf("invalid pool id: %s", poolID)
}
if err := a.refresh(k.AddressSpace); err != nil {
return nil, nil, err
}
aSpace, err := a.getAddrSpace(k.AddressSpace)
if err != nil {
return nil, nil, err
}
aSpace.Lock()
p, ok := aSpace.subnets[k]
if !ok {
aSpace.Unlock()
return nil, nil, types.NotFoundErrorf("cannot find address pool for poolID:%s", poolID)
}
if prefAddress != nil && !p.Pool.Contains(prefAddress) {
aSpace.Unlock()
return nil, nil, ipamapi.ErrIPOutOfRange
}
c := p
for c.Range != nil {
k = c.ParentKey
c = aSpace.subnets[k]
}
aSpace.Unlock()
bm, err := a.retrieveBitmask(k, c.Pool)
if err != nil {
return nil, nil, types.InternalErrorf("could not find bitmask in datastore for %s on address %v request from pool %s: %v",
k.String(), prefAddress, poolID, err)
}
// In order to request for a serial ip address allocation, callers can pass in the option to request
// IP allocation serially or first available IP in the subnet
var serial bool
if opts != nil {
if val, ok := opts[ipamapi.AllocSerialPrefix]; ok {
serial = (val == "true")
}
}
ip, err := a.getAddress(p.Pool, bm, prefAddress, p.Range, serial)
if err != nil {
return nil, nil, err
}
return &net.IPNet{IP: ip, Mask: p.Pool.Mask}, nil, nil
}
|
[
"func",
"(",
"a",
"*",
"Allocator",
")",
"RequestAddress",
"(",
"poolID",
"string",
",",
"prefAddress",
"net",
".",
"IP",
",",
"opts",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"*",
"net",
".",
"IPNet",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"poolID",
",",
"prefAddress",
",",
"opts",
")",
"\n",
"k",
":=",
"SubnetKey",
"{",
"}",
"\n",
"if",
"err",
":=",
"k",
".",
"FromString",
"(",
"poolID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
",",
"poolID",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"a",
".",
"refresh",
"(",
"k",
".",
"AddressSpace",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"aSpace",
",",
"err",
":=",
"a",
".",
"getAddrSpace",
"(",
"k",
".",
"AddressSpace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"aSpace",
".",
"Lock",
"(",
")",
"\n",
"p",
",",
"ok",
":=",
"aSpace",
".",
"subnets",
"[",
"k",
"]",
"\n",
"if",
"!",
"ok",
"{",
"aSpace",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"types",
".",
"NotFoundErrorf",
"(",
"\"",
"\"",
",",
"poolID",
")",
"\n",
"}",
"\n\n",
"if",
"prefAddress",
"!=",
"nil",
"&&",
"!",
"p",
".",
"Pool",
".",
"Contains",
"(",
"prefAddress",
")",
"{",
"aSpace",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"ipamapi",
".",
"ErrIPOutOfRange",
"\n",
"}",
"\n\n",
"c",
":=",
"p",
"\n",
"for",
"c",
".",
"Range",
"!=",
"nil",
"{",
"k",
"=",
"c",
".",
"ParentKey",
"\n",
"c",
"=",
"aSpace",
".",
"subnets",
"[",
"k",
"]",
"\n",
"}",
"\n",
"aSpace",
".",
"Unlock",
"(",
")",
"\n\n",
"bm",
",",
"err",
":=",
"a",
".",
"retrieveBitmask",
"(",
"k",
",",
"c",
".",
"Pool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"types",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"k",
".",
"String",
"(",
")",
",",
"prefAddress",
",",
"poolID",
",",
"err",
")",
"\n",
"}",
"\n",
"// In order to request for a serial ip address allocation, callers can pass in the option to request",
"// IP allocation serially or first available IP in the subnet",
"var",
"serial",
"bool",
"\n",
"if",
"opts",
"!=",
"nil",
"{",
"if",
"val",
",",
"ok",
":=",
"opts",
"[",
"ipamapi",
".",
"AllocSerialPrefix",
"]",
";",
"ok",
"{",
"serial",
"=",
"(",
"val",
"==",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ip",
",",
"err",
":=",
"a",
".",
"getAddress",
"(",
"p",
".",
"Pool",
",",
"bm",
",",
"prefAddress",
",",
"p",
".",
"Range",
",",
"serial",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"ip",
",",
"Mask",
":",
"p",
".",
"Pool",
".",
"Mask",
"}",
",",
"nil",
",",
"nil",
"\n",
"}"
] |
// RequestAddress returns an address from the specified pool ID
|
[
"RequestAddress",
"returns",
"an",
"address",
"from",
"the",
"specified",
"pool",
"ID"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/allocator.go#L451-L505
|
22,531
|
docker/libnetwork
|
ipam/allocator.go
|
ReleaseAddress
|
func (a *Allocator) ReleaseAddress(poolID string, address net.IP) error {
logrus.Debugf("ReleaseAddress(%s, %v)", poolID, address)
k := SubnetKey{}
if err := k.FromString(poolID); err != nil {
return types.BadRequestErrorf("invalid pool id: %s", poolID)
}
if err := a.refresh(k.AddressSpace); err != nil {
return err
}
aSpace, err := a.getAddrSpace(k.AddressSpace)
if err != nil {
return err
}
aSpace.Lock()
p, ok := aSpace.subnets[k]
if !ok {
aSpace.Unlock()
return types.NotFoundErrorf("cannot find address pool for poolID:%s", poolID)
}
if address == nil {
aSpace.Unlock()
return types.BadRequestErrorf("invalid address: nil")
}
if !p.Pool.Contains(address) {
aSpace.Unlock()
return ipamapi.ErrIPOutOfRange
}
c := p
for c.Range != nil {
k = c.ParentKey
c = aSpace.subnets[k]
}
aSpace.Unlock()
mask := p.Pool.Mask
h, err := types.GetHostPartIP(address, mask)
if err != nil {
return types.InternalErrorf("failed to release address %s: %v", address.String(), err)
}
bm, err := a.retrieveBitmask(k, c.Pool)
if err != nil {
return types.InternalErrorf("could not find bitmask in datastore for %s on address %v release from pool %s: %v",
k.String(), address, poolID, err)
}
defer logrus.Debugf("Released address PoolID:%s, Address:%v Sequence:%s", poolID, address, bm.String())
return bm.Unset(ipToUint64(h))
}
|
go
|
func (a *Allocator) ReleaseAddress(poolID string, address net.IP) error {
logrus.Debugf("ReleaseAddress(%s, %v)", poolID, address)
k := SubnetKey{}
if err := k.FromString(poolID); err != nil {
return types.BadRequestErrorf("invalid pool id: %s", poolID)
}
if err := a.refresh(k.AddressSpace); err != nil {
return err
}
aSpace, err := a.getAddrSpace(k.AddressSpace)
if err != nil {
return err
}
aSpace.Lock()
p, ok := aSpace.subnets[k]
if !ok {
aSpace.Unlock()
return types.NotFoundErrorf("cannot find address pool for poolID:%s", poolID)
}
if address == nil {
aSpace.Unlock()
return types.BadRequestErrorf("invalid address: nil")
}
if !p.Pool.Contains(address) {
aSpace.Unlock()
return ipamapi.ErrIPOutOfRange
}
c := p
for c.Range != nil {
k = c.ParentKey
c = aSpace.subnets[k]
}
aSpace.Unlock()
mask := p.Pool.Mask
h, err := types.GetHostPartIP(address, mask)
if err != nil {
return types.InternalErrorf("failed to release address %s: %v", address.String(), err)
}
bm, err := a.retrieveBitmask(k, c.Pool)
if err != nil {
return types.InternalErrorf("could not find bitmask in datastore for %s on address %v release from pool %s: %v",
k.String(), address, poolID, err)
}
defer logrus.Debugf("Released address PoolID:%s, Address:%v Sequence:%s", poolID, address, bm.String())
return bm.Unset(ipToUint64(h))
}
|
[
"func",
"(",
"a",
"*",
"Allocator",
")",
"ReleaseAddress",
"(",
"poolID",
"string",
",",
"address",
"net",
".",
"IP",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"poolID",
",",
"address",
")",
"\n",
"k",
":=",
"SubnetKey",
"{",
"}",
"\n",
"if",
"err",
":=",
"k",
".",
"FromString",
"(",
"poolID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
",",
"poolID",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"a",
".",
"refresh",
"(",
"k",
".",
"AddressSpace",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"aSpace",
",",
"err",
":=",
"a",
".",
"getAddrSpace",
"(",
"k",
".",
"AddressSpace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"aSpace",
".",
"Lock",
"(",
")",
"\n",
"p",
",",
"ok",
":=",
"aSpace",
".",
"subnets",
"[",
"k",
"]",
"\n",
"if",
"!",
"ok",
"{",
"aSpace",
".",
"Unlock",
"(",
")",
"\n",
"return",
"types",
".",
"NotFoundErrorf",
"(",
"\"",
"\"",
",",
"poolID",
")",
"\n",
"}",
"\n\n",
"if",
"address",
"==",
"nil",
"{",
"aSpace",
".",
"Unlock",
"(",
")",
"\n",
"return",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"p",
".",
"Pool",
".",
"Contains",
"(",
"address",
")",
"{",
"aSpace",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ipamapi",
".",
"ErrIPOutOfRange",
"\n",
"}",
"\n\n",
"c",
":=",
"p",
"\n",
"for",
"c",
".",
"Range",
"!=",
"nil",
"{",
"k",
"=",
"c",
".",
"ParentKey",
"\n",
"c",
"=",
"aSpace",
".",
"subnets",
"[",
"k",
"]",
"\n",
"}",
"\n",
"aSpace",
".",
"Unlock",
"(",
")",
"\n\n",
"mask",
":=",
"p",
".",
"Pool",
".",
"Mask",
"\n\n",
"h",
",",
"err",
":=",
"types",
".",
"GetHostPartIP",
"(",
"address",
",",
"mask",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"types",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"address",
".",
"String",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"bm",
",",
"err",
":=",
"a",
".",
"retrieveBitmask",
"(",
"k",
",",
"c",
".",
"Pool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"types",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"k",
".",
"String",
"(",
")",
",",
"address",
",",
"poolID",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"poolID",
",",
"address",
",",
"bm",
".",
"String",
"(",
")",
")",
"\n\n",
"return",
"bm",
".",
"Unset",
"(",
"ipToUint64",
"(",
"h",
")",
")",
"\n",
"}"
] |
// ReleaseAddress releases the address from the specified pool ID
|
[
"ReleaseAddress",
"releases",
"the",
"address",
"from",
"the",
"specified",
"pool",
"ID"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/allocator.go#L508-L563
|
22,532
|
docker/libnetwork
|
ipam/allocator.go
|
DumpDatabase
|
func (a *Allocator) DumpDatabase() string {
a.Lock()
aspaces := make(map[string]*addrSpace, len(a.addrSpaces))
orderedAS := make([]string, 0, len(a.addrSpaces))
for as, aSpace := range a.addrSpaces {
orderedAS = append(orderedAS, as)
aspaces[as] = aSpace
}
a.Unlock()
sort.Strings(orderedAS)
var s string
for _, as := range orderedAS {
aSpace := aspaces[as]
s = fmt.Sprintf("\n\n%s Config", as)
aSpace.Lock()
for k, config := range aSpace.subnets {
s += fmt.Sprintf("\n%v: %v", k, config)
if config.Range == nil {
a.retrieveBitmask(k, config.Pool)
}
}
aSpace.Unlock()
}
s = fmt.Sprintf("%s\n\nBitmasks", s)
for k, bm := range a.addresses {
s += fmt.Sprintf("\n%s: %s", k, bm)
}
return s
}
|
go
|
func (a *Allocator) DumpDatabase() string {
a.Lock()
aspaces := make(map[string]*addrSpace, len(a.addrSpaces))
orderedAS := make([]string, 0, len(a.addrSpaces))
for as, aSpace := range a.addrSpaces {
orderedAS = append(orderedAS, as)
aspaces[as] = aSpace
}
a.Unlock()
sort.Strings(orderedAS)
var s string
for _, as := range orderedAS {
aSpace := aspaces[as]
s = fmt.Sprintf("\n\n%s Config", as)
aSpace.Lock()
for k, config := range aSpace.subnets {
s += fmt.Sprintf("\n%v: %v", k, config)
if config.Range == nil {
a.retrieveBitmask(k, config.Pool)
}
}
aSpace.Unlock()
}
s = fmt.Sprintf("%s\n\nBitmasks", s)
for k, bm := range a.addresses {
s += fmt.Sprintf("\n%s: %s", k, bm)
}
return s
}
|
[
"func",
"(",
"a",
"*",
"Allocator",
")",
"DumpDatabase",
"(",
")",
"string",
"{",
"a",
".",
"Lock",
"(",
")",
"\n",
"aspaces",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"addrSpace",
",",
"len",
"(",
"a",
".",
"addrSpaces",
")",
")",
"\n",
"orderedAS",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"a",
".",
"addrSpaces",
")",
")",
"\n",
"for",
"as",
",",
"aSpace",
":=",
"range",
"a",
".",
"addrSpaces",
"{",
"orderedAS",
"=",
"append",
"(",
"orderedAS",
",",
"as",
")",
"\n",
"aspaces",
"[",
"as",
"]",
"=",
"aSpace",
"\n",
"}",
"\n",
"a",
".",
"Unlock",
"(",
")",
"\n\n",
"sort",
".",
"Strings",
"(",
"orderedAS",
")",
"\n\n",
"var",
"s",
"string",
"\n",
"for",
"_",
",",
"as",
":=",
"range",
"orderedAS",
"{",
"aSpace",
":=",
"aspaces",
"[",
"as",
"]",
"\n",
"s",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"as",
")",
"\n",
"aSpace",
".",
"Lock",
"(",
")",
"\n",
"for",
"k",
",",
"config",
":=",
"range",
"aSpace",
".",
"subnets",
"{",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"k",
",",
"config",
")",
"\n",
"if",
"config",
".",
"Range",
"==",
"nil",
"{",
"a",
".",
"retrieveBitmask",
"(",
"k",
",",
"config",
".",
"Pool",
")",
"\n",
"}",
"\n",
"}",
"\n",
"aSpace",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n\n",
"s",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"s",
")",
"\n",
"for",
"k",
",",
"bm",
":=",
"range",
"a",
".",
"addresses",
"{",
"s",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"k",
",",
"bm",
")",
"\n",
"}",
"\n\n",
"return",
"s",
"\n",
"}"
] |
// DumpDatabase dumps the internal info
|
[
"DumpDatabase",
"dumps",
"the",
"internal",
"info"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/allocator.go#L605-L637
|
22,533
|
docker/libnetwork
|
service_linux.go
|
populateLoadBalancers
|
func (sb *sandbox) populateLoadBalancers(ep *endpoint) {
// This is an interface less endpoint. Nothing to do.
if ep.Iface() == nil {
return
}
n := ep.getNetwork()
eIP := ep.Iface().Address()
if n.ingress {
if err := addRedirectRules(sb.Key(), eIP, ep.ingressPorts); err != nil {
logrus.Errorf("Failed to add redirect rules for ep %s (%.7s): %v", ep.Name(), ep.ID(), err)
}
}
}
|
go
|
func (sb *sandbox) populateLoadBalancers(ep *endpoint) {
// This is an interface less endpoint. Nothing to do.
if ep.Iface() == nil {
return
}
n := ep.getNetwork()
eIP := ep.Iface().Address()
if n.ingress {
if err := addRedirectRules(sb.Key(), eIP, ep.ingressPorts); err != nil {
logrus.Errorf("Failed to add redirect rules for ep %s (%.7s): %v", ep.Name(), ep.ID(), err)
}
}
}
|
[
"func",
"(",
"sb",
"*",
"sandbox",
")",
"populateLoadBalancers",
"(",
"ep",
"*",
"endpoint",
")",
"{",
"// This is an interface less endpoint. Nothing to do.",
"if",
"ep",
".",
"Iface",
"(",
")",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"n",
":=",
"ep",
".",
"getNetwork",
"(",
")",
"\n",
"eIP",
":=",
"ep",
".",
"Iface",
"(",
")",
".",
"Address",
"(",
")",
"\n\n",
"if",
"n",
".",
"ingress",
"{",
"if",
"err",
":=",
"addRedirectRules",
"(",
"sb",
".",
"Key",
"(",
")",
",",
"eIP",
",",
"ep",
".",
"ingressPorts",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ep",
".",
"Name",
"(",
")",
",",
"ep",
".",
"ID",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Populate all loadbalancers on the network that the passed endpoint
// belongs to, into this sandbox.
|
[
"Populate",
"all",
"loadbalancers",
"on",
"the",
"network",
"that",
"the",
"passed",
"endpoint",
"belongs",
"to",
"into",
"this",
"sandbox",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/service_linux.go#L35-L49
|
22,534
|
docker/libnetwork
|
service_linux.go
|
invokeFWMarker
|
func invokeFWMarker(path string, vip net.IP, fwMark uint32, ingressPorts []*PortConfig, eIP *net.IPNet, isDelete bool, lbMode string) error {
var ingressPortsFile string
if len(ingressPorts) != 0 {
var err error
ingressPortsFile, err = writePortsToFile(ingressPorts)
if err != nil {
return err
}
defer os.Remove(ingressPortsFile)
}
addDelOpt := "-A"
if isDelete {
addDelOpt = "-D"
}
cmd := &exec.Cmd{
Path: reexec.Self(),
Args: append([]string{"fwmarker"}, path, vip.String(), fmt.Sprintf("%d", fwMark), addDelOpt, ingressPortsFile, eIP.String(), lbMode),
Stdout: os.Stdout,
Stderr: os.Stderr,
}
if err := cmd.Run(); err != nil {
return fmt.Errorf("reexec failed: %v", err)
}
return nil
}
|
go
|
func invokeFWMarker(path string, vip net.IP, fwMark uint32, ingressPorts []*PortConfig, eIP *net.IPNet, isDelete bool, lbMode string) error {
var ingressPortsFile string
if len(ingressPorts) != 0 {
var err error
ingressPortsFile, err = writePortsToFile(ingressPorts)
if err != nil {
return err
}
defer os.Remove(ingressPortsFile)
}
addDelOpt := "-A"
if isDelete {
addDelOpt = "-D"
}
cmd := &exec.Cmd{
Path: reexec.Self(),
Args: append([]string{"fwmarker"}, path, vip.String(), fmt.Sprintf("%d", fwMark), addDelOpt, ingressPortsFile, eIP.String(), lbMode),
Stdout: os.Stdout,
Stderr: os.Stderr,
}
if err := cmd.Run(); err != nil {
return fmt.Errorf("reexec failed: %v", err)
}
return nil
}
|
[
"func",
"invokeFWMarker",
"(",
"path",
"string",
",",
"vip",
"net",
".",
"IP",
",",
"fwMark",
"uint32",
",",
"ingressPorts",
"[",
"]",
"*",
"PortConfig",
",",
"eIP",
"*",
"net",
".",
"IPNet",
",",
"isDelete",
"bool",
",",
"lbMode",
"string",
")",
"error",
"{",
"var",
"ingressPortsFile",
"string",
"\n\n",
"if",
"len",
"(",
"ingressPorts",
")",
"!=",
"0",
"{",
"var",
"err",
"error",
"\n",
"ingressPortsFile",
",",
"err",
"=",
"writePortsToFile",
"(",
"ingressPorts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"defer",
"os",
".",
"Remove",
"(",
"ingressPortsFile",
")",
"\n",
"}",
"\n\n",
"addDelOpt",
":=",
"\"",
"\"",
"\n",
"if",
"isDelete",
"{",
"addDelOpt",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"cmd",
":=",
"&",
"exec",
".",
"Cmd",
"{",
"Path",
":",
"reexec",
".",
"Self",
"(",
")",
",",
"Args",
":",
"append",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"path",
",",
"vip",
".",
"String",
"(",
")",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"fwMark",
")",
",",
"addDelOpt",
",",
"ingressPortsFile",
",",
"eIP",
".",
"String",
"(",
")",
",",
"lbMode",
")",
",",
"Stdout",
":",
"os",
".",
"Stdout",
",",
"Stderr",
":",
"os",
".",
"Stderr",
",",
"}",
"\n\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Invoke fwmarker reexec routine to mark vip destined packets with
// the passed firewall mark.
|
[
"Invoke",
"fwmarker",
"reexec",
"routine",
"to",
"mark",
"vip",
"destined",
"packets",
"with",
"the",
"passed",
"firewall",
"mark",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/service_linux.go#L575-L605
|
22,535
|
docker/libnetwork
|
drivers/windows/windows.go
|
IsBuiltinLocalDriver
|
func IsBuiltinLocalDriver(networkType string) bool {
if "l2bridge" == networkType || "l2tunnel" == networkType || "nat" == networkType || "ics" == networkType || "transparent" == networkType {
return true
}
return false
}
|
go
|
func IsBuiltinLocalDriver(networkType string) bool {
if "l2bridge" == networkType || "l2tunnel" == networkType || "nat" == networkType || "ics" == networkType || "transparent" == networkType {
return true
}
return false
}
|
[
"func",
"IsBuiltinLocalDriver",
"(",
"networkType",
"string",
")",
"bool",
"{",
"if",
"\"",
"\"",
"==",
"networkType",
"||",
"\"",
"\"",
"==",
"networkType",
"||",
"\"",
"\"",
"==",
"networkType",
"||",
"\"",
"\"",
"==",
"networkType",
"||",
"\"",
"\"",
"==",
"networkType",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// IsBuiltinLocalDriver validates if network-type is a builtin local-scoped driver
|
[
"IsBuiltinLocalDriver",
"validates",
"if",
"network",
"-",
"type",
"is",
"a",
"builtin",
"local",
"-",
"scoped",
"driver"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/windows.go#L113-L119
|
22,536
|
docker/libnetwork
|
drivers/windows/windows.go
|
newDriver
|
func newDriver(networkType string) *driver {
return &driver{name: networkType, networks: map[string]*hnsNetwork{}}
}
|
go
|
func newDriver(networkType string) *driver {
return &driver{name: networkType, networks: map[string]*hnsNetwork{}}
}
|
[
"func",
"newDriver",
"(",
"networkType",
"string",
")",
"*",
"driver",
"{",
"return",
"&",
"driver",
"{",
"name",
":",
"networkType",
",",
"networks",
":",
"map",
"[",
"string",
"]",
"*",
"hnsNetwork",
"{",
"}",
"}",
"\n",
"}"
] |
// New constructs a new bridge driver
|
[
"New",
"constructs",
"a",
"new",
"bridge",
"driver"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/windows.go#L122-L124
|
22,537
|
docker/libnetwork
|
drivers/windows/windows.go
|
GetInit
|
func GetInit(networkType string) func(dc driverapi.DriverCallback, config map[string]interface{}) error {
return func(dc driverapi.DriverCallback, config map[string]interface{}) error {
if !IsBuiltinLocalDriver(networkType) {
return types.BadRequestErrorf("Network type not supported: %s", networkType)
}
d := newDriver(networkType)
err := d.initStore(config)
if err != nil {
return err
}
return dc.RegisterDriver(networkType, d, driverapi.Capability{
DataScope: datastore.LocalScope,
ConnectivityScope: datastore.LocalScope,
})
}
}
|
go
|
func GetInit(networkType string) func(dc driverapi.DriverCallback, config map[string]interface{}) error {
return func(dc driverapi.DriverCallback, config map[string]interface{}) error {
if !IsBuiltinLocalDriver(networkType) {
return types.BadRequestErrorf("Network type not supported: %s", networkType)
}
d := newDriver(networkType)
err := d.initStore(config)
if err != nil {
return err
}
return dc.RegisterDriver(networkType, d, driverapi.Capability{
DataScope: datastore.LocalScope,
ConnectivityScope: datastore.LocalScope,
})
}
}
|
[
"func",
"GetInit",
"(",
"networkType",
"string",
")",
"func",
"(",
"dc",
"driverapi",
".",
"DriverCallback",
",",
"config",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"func",
"(",
"dc",
"driverapi",
".",
"DriverCallback",
",",
"config",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"!",
"IsBuiltinLocalDriver",
"(",
"networkType",
")",
"{",
"return",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
",",
"networkType",
")",
"\n",
"}",
"\n\n",
"d",
":=",
"newDriver",
"(",
"networkType",
")",
"\n\n",
"err",
":=",
"d",
".",
"initStore",
"(",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"dc",
".",
"RegisterDriver",
"(",
"networkType",
",",
"d",
",",
"driverapi",
".",
"Capability",
"{",
"DataScope",
":",
"datastore",
".",
"LocalScope",
",",
"ConnectivityScope",
":",
"datastore",
".",
"LocalScope",
",",
"}",
")",
"\n",
"}",
"\n",
"}"
] |
// GetInit returns an initializer for the given network type
|
[
"GetInit",
"returns",
"an",
"initializer",
"for",
"the",
"given",
"network",
"type"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/windows.go#L127-L145
|
22,538
|
docker/libnetwork
|
drivers/windows/windows.go
|
ConvertPortBindings
|
func ConvertPortBindings(portBindings []types.PortBinding) ([]json.RawMessage, error) {
var pbs []json.RawMessage
// Enumerate through the port bindings specified by the user and convert
// them into the internal structure matching the JSON blob that can be
// understood by the HCS.
for _, elem := range portBindings {
proto := strings.ToUpper(elem.Proto.String())
if proto != "TCP" && proto != "UDP" {
return nil, fmt.Errorf("invalid protocol %s", elem.Proto.String())
}
if elem.HostPort != elem.HostPortEnd {
return nil, fmt.Errorf("Windows does not support more than one host port in NAT settings")
}
if len(elem.HostIP) != 0 {
return nil, fmt.Errorf("Windows does not support host IP addresses in NAT settings")
}
encodedPolicy, err := json.Marshal(hcsshim.NatPolicy{
Type: "NAT",
ExternalPort: elem.HostPort,
InternalPort: elem.Port,
Protocol: elem.Proto.String(),
})
if err != nil {
return nil, err
}
pbs = append(pbs, encodedPolicy)
}
return pbs, nil
}
|
go
|
func ConvertPortBindings(portBindings []types.PortBinding) ([]json.RawMessage, error) {
var pbs []json.RawMessage
// Enumerate through the port bindings specified by the user and convert
// them into the internal structure matching the JSON blob that can be
// understood by the HCS.
for _, elem := range portBindings {
proto := strings.ToUpper(elem.Proto.String())
if proto != "TCP" && proto != "UDP" {
return nil, fmt.Errorf("invalid protocol %s", elem.Proto.String())
}
if elem.HostPort != elem.HostPortEnd {
return nil, fmt.Errorf("Windows does not support more than one host port in NAT settings")
}
if len(elem.HostIP) != 0 {
return nil, fmt.Errorf("Windows does not support host IP addresses in NAT settings")
}
encodedPolicy, err := json.Marshal(hcsshim.NatPolicy{
Type: "NAT",
ExternalPort: elem.HostPort,
InternalPort: elem.Port,
Protocol: elem.Proto.String(),
})
if err != nil {
return nil, err
}
pbs = append(pbs, encodedPolicy)
}
return pbs, nil
}
|
[
"func",
"ConvertPortBindings",
"(",
"portBindings",
"[",
"]",
"types",
".",
"PortBinding",
")",
"(",
"[",
"]",
"json",
".",
"RawMessage",
",",
"error",
")",
"{",
"var",
"pbs",
"[",
"]",
"json",
".",
"RawMessage",
"\n\n",
"// Enumerate through the port bindings specified by the user and convert",
"// them into the internal structure matching the JSON blob that can be",
"// understood by the HCS.",
"for",
"_",
",",
"elem",
":=",
"range",
"portBindings",
"{",
"proto",
":=",
"strings",
".",
"ToUpper",
"(",
"elem",
".",
"Proto",
".",
"String",
"(",
")",
")",
"\n",
"if",
"proto",
"!=",
"\"",
"\"",
"&&",
"proto",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"elem",
".",
"Proto",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"elem",
".",
"HostPort",
"!=",
"elem",
".",
"HostPortEnd",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"elem",
".",
"HostIP",
")",
"!=",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"encodedPolicy",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"hcsshim",
".",
"NatPolicy",
"{",
"Type",
":",
"\"",
"\"",
",",
"ExternalPort",
":",
"elem",
".",
"HostPort",
",",
"InternalPort",
":",
"elem",
".",
"Port",
",",
"Protocol",
":",
"elem",
".",
"Proto",
".",
"String",
"(",
")",
",",
"}",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"pbs",
"=",
"append",
"(",
"pbs",
",",
"encodedPolicy",
")",
"\n",
"}",
"\n",
"return",
"pbs",
",",
"nil",
"\n",
"}"
] |
// ConvertPortBindings converts PortBindings to JSON for HNS request
|
[
"ConvertPortBindings",
"converts",
"PortBindings",
"to",
"JSON",
"for",
"HNS",
"request"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/windows.go#L449-L482
|
22,539
|
docker/libnetwork
|
drivers/windows/windows.go
|
ParsePortBindingPolicies
|
func ParsePortBindingPolicies(policies []json.RawMessage) ([]types.PortBinding, error) {
var bindings []types.PortBinding
hcsPolicy := &hcsshim.NatPolicy{}
for _, elem := range policies {
if err := json.Unmarshal([]byte(elem), &hcsPolicy); err != nil || hcsPolicy.Type != "NAT" {
continue
}
binding := types.PortBinding{
HostPort: hcsPolicy.ExternalPort,
HostPortEnd: hcsPolicy.ExternalPort,
Port: hcsPolicy.InternalPort,
Proto: types.ParseProtocol(hcsPolicy.Protocol),
HostIP: net.IPv4(0, 0, 0, 0),
}
bindings = append(bindings, binding)
}
return bindings, nil
}
|
go
|
func ParsePortBindingPolicies(policies []json.RawMessage) ([]types.PortBinding, error) {
var bindings []types.PortBinding
hcsPolicy := &hcsshim.NatPolicy{}
for _, elem := range policies {
if err := json.Unmarshal([]byte(elem), &hcsPolicy); err != nil || hcsPolicy.Type != "NAT" {
continue
}
binding := types.PortBinding{
HostPort: hcsPolicy.ExternalPort,
HostPortEnd: hcsPolicy.ExternalPort,
Port: hcsPolicy.InternalPort,
Proto: types.ParseProtocol(hcsPolicy.Protocol),
HostIP: net.IPv4(0, 0, 0, 0),
}
bindings = append(bindings, binding)
}
return bindings, nil
}
|
[
"func",
"ParsePortBindingPolicies",
"(",
"policies",
"[",
"]",
"json",
".",
"RawMessage",
")",
"(",
"[",
"]",
"types",
".",
"PortBinding",
",",
"error",
")",
"{",
"var",
"bindings",
"[",
"]",
"types",
".",
"PortBinding",
"\n",
"hcsPolicy",
":=",
"&",
"hcsshim",
".",
"NatPolicy",
"{",
"}",
"\n\n",
"for",
"_",
",",
"elem",
":=",
"range",
"policies",
"{",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"elem",
")",
",",
"&",
"hcsPolicy",
")",
";",
"err",
"!=",
"nil",
"||",
"hcsPolicy",
".",
"Type",
"!=",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n\n",
"binding",
":=",
"types",
".",
"PortBinding",
"{",
"HostPort",
":",
"hcsPolicy",
".",
"ExternalPort",
",",
"HostPortEnd",
":",
"hcsPolicy",
".",
"ExternalPort",
",",
"Port",
":",
"hcsPolicy",
".",
"InternalPort",
",",
"Proto",
":",
"types",
".",
"ParseProtocol",
"(",
"hcsPolicy",
".",
"Protocol",
")",
",",
"HostIP",
":",
"net",
".",
"IPv4",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
",",
"}",
"\n\n",
"bindings",
"=",
"append",
"(",
"bindings",
",",
"binding",
")",
"\n",
"}",
"\n\n",
"return",
"bindings",
",",
"nil",
"\n",
"}"
] |
// ParsePortBindingPolicies parses HNS endpoint response message to PortBindings
|
[
"ParsePortBindingPolicies",
"parses",
"HNS",
"endpoint",
"response",
"message",
"to",
"PortBindings"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/windows.go#L485-L507
|
22,540
|
docker/libnetwork
|
drivers/windows/windows.go
|
ParseEndpointConnectivity
|
func ParseEndpointConnectivity(epOptions map[string]interface{}) (*EndpointConnectivity, error) {
if epOptions == nil {
return nil, nil
}
ec := &EndpointConnectivity{}
if opt, ok := epOptions[netlabel.PortMap]; ok {
if bs, ok := opt.([]types.PortBinding); ok {
ec.PortBindings = bs
} else {
return nil, fmt.Errorf("Invalid endpoint configuration")
}
}
if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
if ports, ok := opt.([]types.TransportPort); ok {
ec.ExposedPorts = ports
} else {
return nil, fmt.Errorf("Invalid endpoint configuration")
}
}
return ec, nil
}
|
go
|
func ParseEndpointConnectivity(epOptions map[string]interface{}) (*EndpointConnectivity, error) {
if epOptions == nil {
return nil, nil
}
ec := &EndpointConnectivity{}
if opt, ok := epOptions[netlabel.PortMap]; ok {
if bs, ok := opt.([]types.PortBinding); ok {
ec.PortBindings = bs
} else {
return nil, fmt.Errorf("Invalid endpoint configuration")
}
}
if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
if ports, ok := opt.([]types.TransportPort); ok {
ec.ExposedPorts = ports
} else {
return nil, fmt.Errorf("Invalid endpoint configuration")
}
}
return ec, nil
}
|
[
"func",
"ParseEndpointConnectivity",
"(",
"epOptions",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"EndpointConnectivity",
",",
"error",
")",
"{",
"if",
"epOptions",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"ec",
":=",
"&",
"EndpointConnectivity",
"{",
"}",
"\n\n",
"if",
"opt",
",",
"ok",
":=",
"epOptions",
"[",
"netlabel",
".",
"PortMap",
"]",
";",
"ok",
"{",
"if",
"bs",
",",
"ok",
":=",
"opt",
".",
"(",
"[",
"]",
"types",
".",
"PortBinding",
")",
";",
"ok",
"{",
"ec",
".",
"PortBindings",
"=",
"bs",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"opt",
",",
"ok",
":=",
"epOptions",
"[",
"netlabel",
".",
"ExposedPorts",
"]",
";",
"ok",
"{",
"if",
"ports",
",",
"ok",
":=",
"opt",
".",
"(",
"[",
"]",
"types",
".",
"TransportPort",
")",
";",
"ok",
"{",
"ec",
".",
"ExposedPorts",
"=",
"ports",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ec",
",",
"nil",
"\n",
"}"
] |
// ParseEndpointConnectivity parses options passed to CreateEndpoint, specifically port bindings, and store in a endpointConnectivity object.
|
[
"ParseEndpointConnectivity",
"parses",
"options",
"passed",
"to",
"CreateEndpoint",
"specifically",
"port",
"bindings",
"and",
"store",
"in",
"a",
"endpointConnectivity",
"object",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/windows.go#L560-L583
|
22,541
|
docker/libnetwork
|
service_common.go
|
cleanupServiceDiscovery
|
func (c *controller) cleanupServiceDiscovery(cleanupNID string) {
c.Lock()
defer c.Unlock()
if cleanupNID == "" {
logrus.Debugf("cleanupServiceDiscovery for all networks")
c.svcRecords = make(map[string]svcInfo)
return
}
logrus.Debugf("cleanupServiceDiscovery for network:%s", cleanupNID)
delete(c.svcRecords, cleanupNID)
}
|
go
|
func (c *controller) cleanupServiceDiscovery(cleanupNID string) {
c.Lock()
defer c.Unlock()
if cleanupNID == "" {
logrus.Debugf("cleanupServiceDiscovery for all networks")
c.svcRecords = make(map[string]svcInfo)
return
}
logrus.Debugf("cleanupServiceDiscovery for network:%s", cleanupNID)
delete(c.svcRecords, cleanupNID)
}
|
[
"func",
"(",
"c",
"*",
"controller",
")",
"cleanupServiceDiscovery",
"(",
"cleanupNID",
"string",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"if",
"cleanupNID",
"==",
"\"",
"\"",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"c",
".",
"svcRecords",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"svcInfo",
")",
"\n",
"return",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"cleanupNID",
")",
"\n",
"delete",
"(",
"c",
".",
"svcRecords",
",",
"cleanupNID",
")",
"\n",
"}"
] |
// cleanupServiceDiscovery when the network is being deleted, erase all the associated service discovery records
|
[
"cleanupServiceDiscovery",
"when",
"the",
"network",
"is",
"being",
"deleted",
"erase",
"all",
"the",
"associated",
"service",
"discovery",
"records"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/service_common.go#L167-L177
|
22,542
|
docker/libnetwork
|
drivers/bridge/setup_bridgenetfiltering.go
|
getKernelBoolParam
|
func getKernelBoolParam(path string) (bool, error) {
enabled := false
line, err := ioutil.ReadFile(path)
if err != nil {
return false, err
}
if len(line) > 0 {
enabled = line[0] == '1'
}
return enabled, err
}
|
go
|
func getKernelBoolParam(path string) (bool, error) {
enabled := false
line, err := ioutil.ReadFile(path)
if err != nil {
return false, err
}
if len(line) > 0 {
enabled = line[0] == '1'
}
return enabled, err
}
|
[
"func",
"getKernelBoolParam",
"(",
"path",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"enabled",
":=",
"false",
"\n",
"line",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"line",
")",
">",
"0",
"{",
"enabled",
"=",
"line",
"[",
"0",
"]",
"==",
"'1'",
"\n",
"}",
"\n",
"return",
"enabled",
",",
"err",
"\n",
"}"
] |
//Gets the value of the kernel parameters located at the given path
|
[
"Gets",
"the",
"value",
"of",
"the",
"kernel",
"parameters",
"located",
"at",
"the",
"given",
"path"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/setup_bridgenetfiltering.go#L123-L133
|
22,543
|
docker/libnetwork
|
drivers/bridge/setup_bridgenetfiltering.go
|
setKernelBoolParam
|
func setKernelBoolParam(path string, on bool) error {
value := byte('0')
if on {
value = byte('1')
}
return ioutil.WriteFile(path, []byte{value, '\n'}, 0644)
}
|
go
|
func setKernelBoolParam(path string, on bool) error {
value := byte('0')
if on {
value = byte('1')
}
return ioutil.WriteFile(path, []byte{value, '\n'}, 0644)
}
|
[
"func",
"setKernelBoolParam",
"(",
"path",
"string",
",",
"on",
"bool",
")",
"error",
"{",
"value",
":=",
"byte",
"(",
"'0'",
")",
"\n",
"if",
"on",
"{",
"value",
"=",
"byte",
"(",
"'1'",
")",
"\n",
"}",
"\n",
"return",
"ioutil",
".",
"WriteFile",
"(",
"path",
",",
"[",
"]",
"byte",
"{",
"value",
",",
"'\\n'",
"}",
",",
"0644",
")",
"\n",
"}"
] |
//Sets the value of the kernel parameter located at the given path
|
[
"Sets",
"the",
"value",
"of",
"the",
"kernel",
"parameter",
"located",
"at",
"the",
"given",
"path"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/setup_bridgenetfiltering.go#L136-L142
|
22,544
|
docker/libnetwork
|
drivers/bridge/setup_bridgenetfiltering.go
|
isPacketForwardingEnabled
|
func isPacketForwardingEnabled(ipVer ipVersion, iface string) (bool, error) {
switch ipVer {
case ipv4, ipv6:
return getKernelBoolParam(getForwardingKernelParam(ipVer, iface))
case ipvboth:
enabled, err := getKernelBoolParam(getForwardingKernelParam(ipv4, ""))
if err != nil || !enabled {
return enabled, err
}
return getKernelBoolParam(getForwardingKernelParam(ipv6, iface))
default:
return true, nil
}
}
|
go
|
func isPacketForwardingEnabled(ipVer ipVersion, iface string) (bool, error) {
switch ipVer {
case ipv4, ipv6:
return getKernelBoolParam(getForwardingKernelParam(ipVer, iface))
case ipvboth:
enabled, err := getKernelBoolParam(getForwardingKernelParam(ipv4, ""))
if err != nil || !enabled {
return enabled, err
}
return getKernelBoolParam(getForwardingKernelParam(ipv6, iface))
default:
return true, nil
}
}
|
[
"func",
"isPacketForwardingEnabled",
"(",
"ipVer",
"ipVersion",
",",
"iface",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"switch",
"ipVer",
"{",
"case",
"ipv4",
",",
"ipv6",
":",
"return",
"getKernelBoolParam",
"(",
"getForwardingKernelParam",
"(",
"ipVer",
",",
"iface",
")",
")",
"\n",
"case",
"ipvboth",
":",
"enabled",
",",
"err",
":=",
"getKernelBoolParam",
"(",
"getForwardingKernelParam",
"(",
"ipv4",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"!",
"enabled",
"{",
"return",
"enabled",
",",
"err",
"\n",
"}",
"\n",
"return",
"getKernelBoolParam",
"(",
"getForwardingKernelParam",
"(",
"ipv6",
",",
"iface",
")",
")",
"\n",
"default",
":",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"}"
] |
//Checks to see if packet forwarding is enabled
|
[
"Checks",
"to",
"see",
"if",
"packet",
"forwarding",
"is",
"enabled"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/setup_bridgenetfiltering.go#L145-L158
|
22,545
|
docker/libnetwork
|
endpoint.go
|
isServiceEnabled
|
func (ep *endpoint) isServiceEnabled() bool {
ep.Lock()
defer ep.Unlock()
return ep.serviceEnabled
}
|
go
|
func (ep *endpoint) isServiceEnabled() bool {
ep.Lock()
defer ep.Unlock()
return ep.serviceEnabled
}
|
[
"func",
"(",
"ep",
"*",
"endpoint",
")",
"isServiceEnabled",
"(",
")",
"bool",
"{",
"ep",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ep",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ep",
".",
"serviceEnabled",
"\n",
"}"
] |
// isServiceEnabled check if service is enabled on the endpoint
|
[
"isServiceEnabled",
"check",
"if",
"service",
"is",
"enabled",
"on",
"the",
"endpoint"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/endpoint.go#L314-L318
|
22,546
|
docker/libnetwork
|
endpoint.go
|
enableService
|
func (ep *endpoint) enableService() {
ep.Lock()
defer ep.Unlock()
ep.serviceEnabled = true
}
|
go
|
func (ep *endpoint) enableService() {
ep.Lock()
defer ep.Unlock()
ep.serviceEnabled = true
}
|
[
"func",
"(",
"ep",
"*",
"endpoint",
")",
"enableService",
"(",
")",
"{",
"ep",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ep",
".",
"Unlock",
"(",
")",
"\n",
"ep",
".",
"serviceEnabled",
"=",
"true",
"\n",
"}"
] |
// enableService sets service enabled on the endpoint
|
[
"enableService",
"sets",
"service",
"enabled",
"on",
"the",
"endpoint"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/endpoint.go#L321-L325
|
22,547
|
docker/libnetwork
|
endpoint.go
|
disableService
|
func (ep *endpoint) disableService() {
ep.Lock()
defer ep.Unlock()
ep.serviceEnabled = false
}
|
go
|
func (ep *endpoint) disableService() {
ep.Lock()
defer ep.Unlock()
ep.serviceEnabled = false
}
|
[
"func",
"(",
"ep",
"*",
"endpoint",
")",
"disableService",
"(",
")",
"{",
"ep",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ep",
".",
"Unlock",
"(",
")",
"\n",
"ep",
".",
"serviceEnabled",
"=",
"false",
"\n",
"}"
] |
// disableService disables service on the endpoint
|
[
"disableService",
"disables",
"service",
"on",
"the",
"endpoint"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/endpoint.go#L328-L332
|
22,548
|
docker/libnetwork
|
endpoint.go
|
EndpointOptionGeneric
|
func EndpointOptionGeneric(generic map[string]interface{}) EndpointOption {
return func(ep *endpoint) {
for k, v := range generic {
ep.generic[k] = v
}
}
}
|
go
|
func EndpointOptionGeneric(generic map[string]interface{}) EndpointOption {
return func(ep *endpoint) {
for k, v := range generic {
ep.generic[k] = v
}
}
}
|
[
"func",
"EndpointOptionGeneric",
"(",
"generic",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"EndpointOption",
"{",
"return",
"func",
"(",
"ep",
"*",
"endpoint",
")",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"generic",
"{",
"ep",
".",
"generic",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// EndpointOptionGeneric function returns an option setter for a Generic option defined
// in a Dictionary of Key-Value pair
|
[
"EndpointOptionGeneric",
"function",
"returns",
"an",
"option",
"setter",
"for",
"a",
"Generic",
"option",
"defined",
"in",
"a",
"Dictionary",
"of",
"Key",
"-",
"Value",
"pair"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/endpoint.go#L928-L934
|
22,549
|
docker/libnetwork
|
endpoint.go
|
CreateOptionIpam
|
func CreateOptionIpam(ipV4, ipV6 net.IP, llIPs []net.IP, ipamOptions map[string]string) EndpointOption {
return func(ep *endpoint) {
ep.prefAddress = ipV4
ep.prefAddressV6 = ipV6
if len(llIPs) != 0 {
for _, ip := range llIPs {
nw := &net.IPNet{IP: ip, Mask: linkLocalMask}
if ip.To4() == nil {
nw.Mask = linkLocalMaskIPv6
}
ep.iface.llAddrs = append(ep.iface.llAddrs, nw)
}
}
ep.ipamOptions = ipamOptions
}
}
|
go
|
func CreateOptionIpam(ipV4, ipV6 net.IP, llIPs []net.IP, ipamOptions map[string]string) EndpointOption {
return func(ep *endpoint) {
ep.prefAddress = ipV4
ep.prefAddressV6 = ipV6
if len(llIPs) != 0 {
for _, ip := range llIPs {
nw := &net.IPNet{IP: ip, Mask: linkLocalMask}
if ip.To4() == nil {
nw.Mask = linkLocalMaskIPv6
}
ep.iface.llAddrs = append(ep.iface.llAddrs, nw)
}
}
ep.ipamOptions = ipamOptions
}
}
|
[
"func",
"CreateOptionIpam",
"(",
"ipV4",
",",
"ipV6",
"net",
".",
"IP",
",",
"llIPs",
"[",
"]",
"net",
".",
"IP",
",",
"ipamOptions",
"map",
"[",
"string",
"]",
"string",
")",
"EndpointOption",
"{",
"return",
"func",
"(",
"ep",
"*",
"endpoint",
")",
"{",
"ep",
".",
"prefAddress",
"=",
"ipV4",
"\n",
"ep",
".",
"prefAddressV6",
"=",
"ipV6",
"\n",
"if",
"len",
"(",
"llIPs",
")",
"!=",
"0",
"{",
"for",
"_",
",",
"ip",
":=",
"range",
"llIPs",
"{",
"nw",
":=",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"ip",
",",
"Mask",
":",
"linkLocalMask",
"}",
"\n",
"if",
"ip",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"nw",
".",
"Mask",
"=",
"linkLocalMaskIPv6",
"\n",
"}",
"\n",
"ep",
".",
"iface",
".",
"llAddrs",
"=",
"append",
"(",
"ep",
".",
"iface",
".",
"llAddrs",
",",
"nw",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ep",
".",
"ipamOptions",
"=",
"ipamOptions",
"\n",
"}",
"\n",
"}"
] |
// CreateOptionIpam function returns an option setter for the ipam configuration for this endpoint
|
[
"CreateOptionIpam",
"function",
"returns",
"an",
"option",
"setter",
"for",
"the",
"ipam",
"configuration",
"for",
"this",
"endpoint"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/endpoint.go#L942-L957
|
22,550
|
docker/libnetwork
|
endpoint.go
|
CreateOptionDNS
|
func CreateOptionDNS(dns []string) EndpointOption {
return func(ep *endpoint) {
ep.generic[netlabel.DNSServers] = dns
}
}
|
go
|
func CreateOptionDNS(dns []string) EndpointOption {
return func(ep *endpoint) {
ep.generic[netlabel.DNSServers] = dns
}
}
|
[
"func",
"CreateOptionDNS",
"(",
"dns",
"[",
"]",
"string",
")",
"EndpointOption",
"{",
"return",
"func",
"(",
"ep",
"*",
"endpoint",
")",
"{",
"ep",
".",
"generic",
"[",
"netlabel",
".",
"DNSServers",
"]",
"=",
"dns",
"\n",
"}",
"\n",
"}"
] |
// CreateOptionDNS function returns an option setter for dns entry option to
// be passed to container Create method.
|
[
"CreateOptionDNS",
"function",
"returns",
"an",
"option",
"setter",
"for",
"dns",
"entry",
"option",
"to",
"be",
"passed",
"to",
"container",
"Create",
"method",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/endpoint.go#L985-L989
|
22,551
|
docker/libnetwork
|
endpoint.go
|
CreateOptionAlias
|
func CreateOptionAlias(name string, alias string) EndpointOption {
return func(ep *endpoint) {
if ep.aliases == nil {
ep.aliases = make(map[string]string)
}
ep.aliases[alias] = name
}
}
|
go
|
func CreateOptionAlias(name string, alias string) EndpointOption {
return func(ep *endpoint) {
if ep.aliases == nil {
ep.aliases = make(map[string]string)
}
ep.aliases[alias] = name
}
}
|
[
"func",
"CreateOptionAlias",
"(",
"name",
"string",
",",
"alias",
"string",
")",
"EndpointOption",
"{",
"return",
"func",
"(",
"ep",
"*",
"endpoint",
")",
"{",
"if",
"ep",
".",
"aliases",
"==",
"nil",
"{",
"ep",
".",
"aliases",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"ep",
".",
"aliases",
"[",
"alias",
"]",
"=",
"name",
"\n",
"}",
"\n",
"}"
] |
// CreateOptionAlias function returns an option setter for setting endpoint alias
|
[
"CreateOptionAlias",
"function",
"returns",
"an",
"option",
"setter",
"for",
"setting",
"endpoint",
"alias"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/endpoint.go#L1008-L1015
|
22,552
|
docker/libnetwork
|
endpoint.go
|
CreateOptionService
|
func CreateOptionService(name, id string, vip net.IP, ingressPorts []*PortConfig, aliases []string) EndpointOption {
return func(ep *endpoint) {
ep.svcName = name
ep.svcID = id
ep.virtualIP = vip
ep.ingressPorts = ingressPorts
ep.svcAliases = aliases
}
}
|
go
|
func CreateOptionService(name, id string, vip net.IP, ingressPorts []*PortConfig, aliases []string) EndpointOption {
return func(ep *endpoint) {
ep.svcName = name
ep.svcID = id
ep.virtualIP = vip
ep.ingressPorts = ingressPorts
ep.svcAliases = aliases
}
}
|
[
"func",
"CreateOptionService",
"(",
"name",
",",
"id",
"string",
",",
"vip",
"net",
".",
"IP",
",",
"ingressPorts",
"[",
"]",
"*",
"PortConfig",
",",
"aliases",
"[",
"]",
"string",
")",
"EndpointOption",
"{",
"return",
"func",
"(",
"ep",
"*",
"endpoint",
")",
"{",
"ep",
".",
"svcName",
"=",
"name",
"\n",
"ep",
".",
"svcID",
"=",
"id",
"\n",
"ep",
".",
"virtualIP",
"=",
"vip",
"\n",
"ep",
".",
"ingressPorts",
"=",
"ingressPorts",
"\n",
"ep",
".",
"svcAliases",
"=",
"aliases",
"\n",
"}",
"\n",
"}"
] |
// CreateOptionService function returns an option setter for setting service binding configuration
|
[
"CreateOptionService",
"function",
"returns",
"an",
"option",
"setter",
"for",
"setting",
"service",
"binding",
"configuration"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/endpoint.go#L1018-L1026
|
22,553
|
docker/libnetwork
|
endpoint.go
|
CreateOptionMyAlias
|
func CreateOptionMyAlias(alias string) EndpointOption {
return func(ep *endpoint) {
ep.myAliases = append(ep.myAliases, alias)
}
}
|
go
|
func CreateOptionMyAlias(alias string) EndpointOption {
return func(ep *endpoint) {
ep.myAliases = append(ep.myAliases, alias)
}
}
|
[
"func",
"CreateOptionMyAlias",
"(",
"alias",
"string",
")",
"EndpointOption",
"{",
"return",
"func",
"(",
"ep",
"*",
"endpoint",
")",
"{",
"ep",
".",
"myAliases",
"=",
"append",
"(",
"ep",
".",
"myAliases",
",",
"alias",
")",
"\n",
"}",
"\n",
"}"
] |
// CreateOptionMyAlias function returns an option setter for setting endpoint's self alias
|
[
"CreateOptionMyAlias",
"function",
"returns",
"an",
"option",
"setter",
"for",
"setting",
"endpoint",
"s",
"self",
"alias"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/endpoint.go#L1029-L1033
|
22,554
|
docker/libnetwork
|
iptables/conntrack.go
|
DeleteConntrackEntries
|
func DeleteConntrackEntries(nlh *netlink.Handle, ipv4List []net.IP, ipv6List []net.IP) (uint, uint, error) {
if !IsConntrackProgrammable(nlh) {
return 0, 0, ErrConntrackNotConfigurable
}
var totalIPv4FlowPurged uint
for _, ipAddress := range ipv4List {
flowPurged, err := purgeConntrackState(nlh, syscall.AF_INET, ipAddress)
if err != nil {
logrus.Warnf("Failed to delete conntrack state for %s: %v", ipAddress, err)
continue
}
totalIPv4FlowPurged += flowPurged
}
var totalIPv6FlowPurged uint
for _, ipAddress := range ipv6List {
flowPurged, err := purgeConntrackState(nlh, syscall.AF_INET6, ipAddress)
if err != nil {
logrus.Warnf("Failed to delete conntrack state for %s: %v", ipAddress, err)
continue
}
totalIPv6FlowPurged += flowPurged
}
logrus.Debugf("DeleteConntrackEntries purged ipv4:%d, ipv6:%d", totalIPv4FlowPurged, totalIPv6FlowPurged)
return totalIPv4FlowPurged, totalIPv6FlowPurged, nil
}
|
go
|
func DeleteConntrackEntries(nlh *netlink.Handle, ipv4List []net.IP, ipv6List []net.IP) (uint, uint, error) {
if !IsConntrackProgrammable(nlh) {
return 0, 0, ErrConntrackNotConfigurable
}
var totalIPv4FlowPurged uint
for _, ipAddress := range ipv4List {
flowPurged, err := purgeConntrackState(nlh, syscall.AF_INET, ipAddress)
if err != nil {
logrus.Warnf("Failed to delete conntrack state for %s: %v", ipAddress, err)
continue
}
totalIPv4FlowPurged += flowPurged
}
var totalIPv6FlowPurged uint
for _, ipAddress := range ipv6List {
flowPurged, err := purgeConntrackState(nlh, syscall.AF_INET6, ipAddress)
if err != nil {
logrus.Warnf("Failed to delete conntrack state for %s: %v", ipAddress, err)
continue
}
totalIPv6FlowPurged += flowPurged
}
logrus.Debugf("DeleteConntrackEntries purged ipv4:%d, ipv6:%d", totalIPv4FlowPurged, totalIPv6FlowPurged)
return totalIPv4FlowPurged, totalIPv6FlowPurged, nil
}
|
[
"func",
"DeleteConntrackEntries",
"(",
"nlh",
"*",
"netlink",
".",
"Handle",
",",
"ipv4List",
"[",
"]",
"net",
".",
"IP",
",",
"ipv6List",
"[",
"]",
"net",
".",
"IP",
")",
"(",
"uint",
",",
"uint",
",",
"error",
")",
"{",
"if",
"!",
"IsConntrackProgrammable",
"(",
"nlh",
")",
"{",
"return",
"0",
",",
"0",
",",
"ErrConntrackNotConfigurable",
"\n",
"}",
"\n\n",
"var",
"totalIPv4FlowPurged",
"uint",
"\n",
"for",
"_",
",",
"ipAddress",
":=",
"range",
"ipv4List",
"{",
"flowPurged",
",",
"err",
":=",
"purgeConntrackState",
"(",
"nlh",
",",
"syscall",
".",
"AF_INET",
",",
"ipAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"ipAddress",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"totalIPv4FlowPurged",
"+=",
"flowPurged",
"\n",
"}",
"\n\n",
"var",
"totalIPv6FlowPurged",
"uint",
"\n",
"for",
"_",
",",
"ipAddress",
":=",
"range",
"ipv6List",
"{",
"flowPurged",
",",
"err",
":=",
"purgeConntrackState",
"(",
"nlh",
",",
"syscall",
".",
"AF_INET6",
",",
"ipAddress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"ipAddress",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"totalIPv6FlowPurged",
"+=",
"flowPurged",
"\n",
"}",
"\n\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"totalIPv4FlowPurged",
",",
"totalIPv6FlowPurged",
")",
"\n",
"return",
"totalIPv4FlowPurged",
",",
"totalIPv6FlowPurged",
",",
"nil",
"\n",
"}"
] |
// DeleteConntrackEntries deletes all the conntrack connections on the host for the specified IP
// Returns the number of flows deleted for IPv4, IPv6 else error
|
[
"DeleteConntrackEntries",
"deletes",
"all",
"the",
"conntrack",
"connections",
"on",
"the",
"host",
"for",
"the",
"specified",
"IP",
"Returns",
"the",
"number",
"of",
"flows",
"deleted",
"for",
"IPv4",
"IPv6",
"else",
"error"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/conntrack.go#L24-L51
|
22,555
|
docker/libnetwork
|
client/service.go
|
CmdServicePublish
|
func (cli *NetworkCli) CmdServicePublish(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "publish", "SERVICE[.NETWORK]", "Publish a new service on a network", false)
flAlias := opts.NewListOpts(netutils.ValidateAlias)
cmd.Var(&flAlias, []string{"-alias"}, "Add alias to self")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
sc := serviceCreate{Name: sn, Network: nn, MyAliases: flAlias.GetAll()}
obj, _, err := readBody(cli.call("POST", "/services", sc, nil))
if err != nil {
return err
}
var replyID string
err = json.Unmarshal(obj, &replyID)
if err != nil {
return err
}
fmt.Fprintf(cli.out, "%s\n", replyID)
return nil
}
|
go
|
func (cli *NetworkCli) CmdServicePublish(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "publish", "SERVICE[.NETWORK]", "Publish a new service on a network", false)
flAlias := opts.NewListOpts(netutils.ValidateAlias)
cmd.Var(&flAlias, []string{"-alias"}, "Add alias to self")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
sc := serviceCreate{Name: sn, Network: nn, MyAliases: flAlias.GetAll()}
obj, _, err := readBody(cli.call("POST", "/services", sc, nil))
if err != nil {
return err
}
var replyID string
err = json.Unmarshal(obj, &replyID)
if err != nil {
return err
}
fmt.Fprintf(cli.out, "%s\n", replyID)
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServicePublish",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
")",
"\n",
"flAlias",
":=",
"opts",
".",
"NewListOpts",
"(",
"netutils",
".",
"ValidateAlias",
")",
"\n",
"cmd",
".",
"Var",
"(",
"&",
"flAlias",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Exact",
",",
"1",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"sn",
",",
"nn",
":=",
"parseServiceName",
"(",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"sc",
":=",
"serviceCreate",
"{",
"Name",
":",
"sn",
",",
"Network",
":",
"nn",
",",
"MyAliases",
":",
"flAlias",
".",
"GetAll",
"(",
")",
"}",
"\n",
"obj",
",",
"_",
",",
"err",
":=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"sc",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"replyID",
"string",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"obj",
",",
"&",
"replyID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"out",
",",
"\"",
"\\n",
"\"",
",",
"replyID",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CmdServicePublish handles service create UI
|
[
"CmdServicePublish",
"handles",
"service",
"create",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L165-L190
|
22,556
|
docker/libnetwork
|
client/service.go
|
CmdServiceUnpublish
|
func (cli *NetworkCli) CmdServiceUnpublish(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "unpublish", "SERVICE[.NETWORK]", "Removes a service", false)
force := cmd.Bool([]string{"f", "-force"}, false, "force unpublish service")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
sd := serviceDelete{Name: sn, Force: *force}
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID, sd, nil))
return err
}
|
go
|
func (cli *NetworkCli) CmdServiceUnpublish(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "unpublish", "SERVICE[.NETWORK]", "Removes a service", false)
force := cmd.Bool([]string{"f", "-force"}, false, "force unpublish service")
cmd.Require(flag.Exact, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
sd := serviceDelete{Name: sn, Force: *force}
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID, sd, nil))
return err
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServiceUnpublish",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
")",
"\n",
"force",
":=",
"cmd",
".",
"Bool",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"false",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Exact",
",",
"1",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"sn",
",",
"nn",
":=",
"parseServiceName",
"(",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"serviceID",
",",
"err",
":=",
"lookupServiceID",
"(",
"cli",
",",
"nn",
",",
"sn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"sd",
":=",
"serviceDelete",
"{",
"Name",
":",
"sn",
",",
"Force",
":",
"*",
"force",
"}",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"serviceID",
",",
"sd",
",",
"nil",
")",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// CmdServiceUnpublish handles service delete UI
|
[
"CmdServiceUnpublish",
"handles",
"service",
"delete",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L193-L212
|
22,557
|
docker/libnetwork
|
client/service.go
|
CmdServiceLs
|
func (cli *NetworkCli) CmdServiceLs(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "ls", "SERVICE", "Lists all the services on a network", false)
flNetwork := cmd.String([]string{"net", "-network"}, "", "Only show the services that are published on the specified network")
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs")
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Do not truncate the output")
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
var obj []byte
if *flNetwork == "" {
obj, _, err = readBody(cli.call("GET", "/services", nil, nil))
} else {
obj, _, err = readBody(cli.call("GET", "/services?network="+*flNetwork, nil, nil))
}
if err != nil {
return err
}
var serviceResources []serviceResource
err = json.Unmarshal(obj, &serviceResources)
if err != nil {
fmt.Println(err)
return err
}
wr := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
// unless quiet (-q) is specified, print field titles
if !*quiet {
fmt.Fprintln(wr, "SERVICE ID\tNAME\tNETWORK\tCONTAINER\tSANDBOX")
}
for _, sr := range serviceResources {
ID := sr.ID
bkID, sbID, err := getBackendID(cli, ID)
if err != nil {
return err
}
if !*noTrunc {
ID = stringid.TruncateID(ID)
bkID = stringid.TruncateID(bkID)
sbID = stringid.TruncateID(sbID)
}
if !*quiet {
fmt.Fprintf(wr, "%s\t%s\t%s\t%s\t%s\n", ID, sr.Name, sr.Network, bkID, sbID)
} else {
fmt.Fprintln(wr, ID)
}
}
wr.Flush()
return nil
}
|
go
|
func (cli *NetworkCli) CmdServiceLs(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "ls", "SERVICE", "Lists all the services on a network", false)
flNetwork := cmd.String([]string{"net", "-network"}, "", "Only show the services that are published on the specified network")
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only display numeric IDs")
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Do not truncate the output")
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
var obj []byte
if *flNetwork == "" {
obj, _, err = readBody(cli.call("GET", "/services", nil, nil))
} else {
obj, _, err = readBody(cli.call("GET", "/services?network="+*flNetwork, nil, nil))
}
if err != nil {
return err
}
var serviceResources []serviceResource
err = json.Unmarshal(obj, &serviceResources)
if err != nil {
fmt.Println(err)
return err
}
wr := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
// unless quiet (-q) is specified, print field titles
if !*quiet {
fmt.Fprintln(wr, "SERVICE ID\tNAME\tNETWORK\tCONTAINER\tSANDBOX")
}
for _, sr := range serviceResources {
ID := sr.ID
bkID, sbID, err := getBackendID(cli, ID)
if err != nil {
return err
}
if !*noTrunc {
ID = stringid.TruncateID(ID)
bkID = stringid.TruncateID(bkID)
sbID = stringid.TruncateID(sbID)
}
if !*quiet {
fmt.Fprintf(wr, "%s\t%s\t%s\t%s\t%s\n", ID, sr.Name, sr.Network, bkID, sbID)
} else {
fmt.Fprintln(wr, ID)
}
}
wr.Flush()
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServiceLs",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
")",
"\n",
"flNetwork",
":=",
"cmd",
".",
"String",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"quiet",
":=",
"cmd",
".",
"Bool",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"false",
",",
"\"",
"\"",
")",
"\n",
"noTrunc",
":=",
"cmd",
".",
"Bool",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"false",
",",
"\"",
"\"",
")",
"\n\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"obj",
"[",
"]",
"byte",
"\n",
"if",
"*",
"flNetwork",
"==",
"\"",
"\"",
"{",
"obj",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"}",
"else",
"{",
"obj",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"*",
"flNetwork",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"serviceResources",
"[",
"]",
"serviceResource",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"obj",
",",
"&",
"serviceResources",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"wr",
":=",
"tabwriter",
".",
"NewWriter",
"(",
"cli",
".",
"out",
",",
"20",
",",
"1",
",",
"3",
",",
"' '",
",",
"0",
")",
"\n",
"// unless quiet (-q) is specified, print field titles",
"if",
"!",
"*",
"quiet",
"{",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"\"",
"\\t",
"\\t",
"\\t",
"\\t",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"sr",
":=",
"range",
"serviceResources",
"{",
"ID",
":=",
"sr",
".",
"ID",
"\n",
"bkID",
",",
"sbID",
",",
"err",
":=",
"getBackendID",
"(",
"cli",
",",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"*",
"noTrunc",
"{",
"ID",
"=",
"stringid",
".",
"TruncateID",
"(",
"ID",
")",
"\n",
"bkID",
"=",
"stringid",
".",
"TruncateID",
"(",
"bkID",
")",
"\n",
"sbID",
"=",
"stringid",
".",
"TruncateID",
"(",
"sbID",
")",
"\n",
"}",
"\n",
"if",
"!",
"*",
"quiet",
"{",
"fmt",
".",
"Fprintf",
"(",
"wr",
",",
"\"",
"\\t",
"\\t",
"\\t",
"\\t",
"\\n",
"\"",
",",
"ID",
",",
"sr",
".",
"Name",
",",
"sr",
".",
"Network",
",",
"bkID",
",",
"sbID",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintln",
"(",
"wr",
",",
"ID",
")",
"\n",
"}",
"\n",
"}",
"\n",
"wr",
".",
"Flush",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// CmdServiceLs handles service list UI
|
[
"CmdServiceLs",
"handles",
"service",
"list",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L215-L269
|
22,558
|
docker/libnetwork
|
client/service.go
|
CmdServiceInfo
|
func (cli *NetworkCli) CmdServiceInfo(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "info", "SERVICE[.NETWORK]", "Displays detailed information about a service", false)
cmd.Require(flag.Min, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
obj, _, err := readBody(cli.call("GET", "/services/"+serviceID, nil, nil))
if err != nil {
return err
}
sr := &serviceResource{}
if err := json.NewDecoder(bytes.NewReader(obj)).Decode(sr); err != nil {
return err
}
fmt.Fprintf(cli.out, "Service Id: %s\n", sr.ID)
fmt.Fprintf(cli.out, "\tName: %s\n", sr.Name)
fmt.Fprintf(cli.out, "\tNetwork: %s\n", sr.Network)
return nil
}
|
go
|
func (cli *NetworkCli) CmdServiceInfo(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "info", "SERVICE[.NETWORK]", "Displays detailed information about a service", false)
cmd.Require(flag.Min, 1)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(0))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
obj, _, err := readBody(cli.call("GET", "/services/"+serviceID, nil, nil))
if err != nil {
return err
}
sr := &serviceResource{}
if err := json.NewDecoder(bytes.NewReader(obj)).Decode(sr); err != nil {
return err
}
fmt.Fprintf(cli.out, "Service Id: %s\n", sr.ID)
fmt.Fprintf(cli.out, "\tName: %s\n", sr.Name)
fmt.Fprintf(cli.out, "\tNetwork: %s\n", sr.Network)
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServiceInfo",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Min",
",",
"1",
")",
"\n\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"sn",
",",
"nn",
":=",
"parseServiceName",
"(",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"serviceID",
",",
"err",
":=",
"lookupServiceID",
"(",
"cli",
",",
"nn",
",",
"sn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"obj",
",",
"_",
",",
"err",
":=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"serviceID",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"sr",
":=",
"&",
"serviceResource",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"bytes",
".",
"NewReader",
"(",
"obj",
")",
")",
".",
"Decode",
"(",
"sr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"out",
",",
"\"",
"\\n",
"\"",
",",
"sr",
".",
"ID",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"sr",
".",
"Name",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"sr",
".",
"Network",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// CmdServiceInfo handles service info UI
|
[
"CmdServiceInfo",
"handles",
"service",
"info",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L294-L324
|
22,559
|
docker/libnetwork
|
client/service.go
|
CmdServiceAttach
|
func (cli *NetworkCli) CmdServiceAttach(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "attach", "CONTAINER SERVICE[.NETWORK]", "Sets a container as a service backend", false)
flAlias := opts.NewListOpts(netutils.ValidateAlias)
cmd.Var(&flAlias, []string{"-alias"}, "Add alias for another container")
cmd.Require(flag.Min, 2)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
containerID, err := lookupContainerID(cli, cmd.Arg(0))
if err != nil {
return err
}
sandboxID, err := lookupSandboxID(cli, containerID)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(1))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
nc := serviceAttach{SandboxID: sandboxID, Aliases: flAlias.GetAll()}
_, _, err = readBody(cli.call("POST", "/services/"+serviceID+"/backend", nc, nil))
return err
}
|
go
|
func (cli *NetworkCli) CmdServiceAttach(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "attach", "CONTAINER SERVICE[.NETWORK]", "Sets a container as a service backend", false)
flAlias := opts.NewListOpts(netutils.ValidateAlias)
cmd.Var(&flAlias, []string{"-alias"}, "Add alias for another container")
cmd.Require(flag.Min, 2)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
containerID, err := lookupContainerID(cli, cmd.Arg(0))
if err != nil {
return err
}
sandboxID, err := lookupSandboxID(cli, containerID)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(1))
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
nc := serviceAttach{SandboxID: sandboxID, Aliases: flAlias.GetAll()}
_, _, err = readBody(cli.call("POST", "/services/"+serviceID+"/backend", nc, nil))
return err
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServiceAttach",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
")",
"\n",
"flAlias",
":=",
"opts",
".",
"NewListOpts",
"(",
"netutils",
".",
"ValidateAlias",
")",
"\n",
"cmd",
".",
"Var",
"(",
"&",
"flAlias",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Min",
",",
"2",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"containerID",
",",
"err",
":=",
"lookupContainerID",
"(",
"cli",
",",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"sandboxID",
",",
"err",
":=",
"lookupSandboxID",
"(",
"cli",
",",
"containerID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"sn",
",",
"nn",
":=",
"parseServiceName",
"(",
"cmd",
".",
"Arg",
"(",
"1",
")",
")",
"\n",
"serviceID",
",",
"err",
":=",
"lookupServiceID",
"(",
"cli",
",",
"nn",
",",
"sn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"nc",
":=",
"serviceAttach",
"{",
"SandboxID",
":",
"sandboxID",
",",
"Aliases",
":",
"flAlias",
".",
"GetAll",
"(",
")",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"serviceID",
"+",
"\"",
"\"",
",",
"nc",
",",
"nil",
")",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// CmdServiceAttach handles service attach UI
|
[
"CmdServiceAttach",
"handles",
"service",
"attach",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L327-L358
|
22,560
|
docker/libnetwork
|
client/service.go
|
CmdServiceDetach
|
func (cli *NetworkCli) CmdServiceDetach(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "detach", "CONTAINER SERVICE", "Removes a container from service backend", false)
cmd.Require(flag.Min, 2)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(1))
containerID, err := lookupContainerID(cli, cmd.Arg(0))
if err != nil {
return err
}
sandboxID, err := lookupSandboxID(cli, containerID)
if err != nil {
return err
}
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID+"/backend/"+sandboxID, nil, nil))
if err != nil {
return err
}
return nil
}
|
go
|
func (cli *NetworkCli) CmdServiceDetach(chain string, args ...string) error {
cmd := cli.Subcmd(chain, "detach", "CONTAINER SERVICE", "Removes a container from service backend", false)
cmd.Require(flag.Min, 2)
err := cmd.ParseFlags(args, true)
if err != nil {
return err
}
sn, nn := parseServiceName(cmd.Arg(1))
containerID, err := lookupContainerID(cli, cmd.Arg(0))
if err != nil {
return err
}
sandboxID, err := lookupSandboxID(cli, containerID)
if err != nil {
return err
}
serviceID, err := lookupServiceID(cli, nn, sn)
if err != nil {
return err
}
_, _, err = readBody(cli.call("DELETE", "/services/"+serviceID+"/backend/"+sandboxID, nil, nil))
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"cli",
"*",
"NetworkCli",
")",
"CmdServiceDetach",
"(",
"chain",
"string",
",",
"args",
"...",
"string",
")",
"error",
"{",
"cmd",
":=",
"cli",
".",
"Subcmd",
"(",
"chain",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
")",
"\n",
"cmd",
".",
"Require",
"(",
"flag",
".",
"Min",
",",
"2",
")",
"\n",
"err",
":=",
"cmd",
".",
"ParseFlags",
"(",
"args",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"sn",
",",
"nn",
":=",
"parseServiceName",
"(",
"cmd",
".",
"Arg",
"(",
"1",
")",
")",
"\n",
"containerID",
",",
"err",
":=",
"lookupContainerID",
"(",
"cli",
",",
"cmd",
".",
"Arg",
"(",
"0",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"sandboxID",
",",
"err",
":=",
"lookupSandboxID",
"(",
"cli",
",",
"containerID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"serviceID",
",",
"err",
":=",
"lookupServiceID",
"(",
"cli",
",",
"nn",
",",
"sn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"_",
",",
"err",
"=",
"readBody",
"(",
"cli",
".",
"call",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"serviceID",
"+",
"\"",
"\"",
"+",
"sandboxID",
",",
"nil",
",",
"nil",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// CmdServiceDetach handles service detach UI
|
[
"CmdServiceDetach",
"handles",
"service",
"detach",
"UI"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/service.go#L361-L390
|
22,561
|
docker/libnetwork
|
ipam/store.go
|
SetValue
|
func (aSpace *addrSpace) SetValue(value []byte) error {
rc := &addrSpace{subnets: make(map[SubnetKey]*PoolData)}
if err := json.Unmarshal(value, rc); err != nil {
return err
}
aSpace.subnets = rc.subnets
return nil
}
|
go
|
func (aSpace *addrSpace) SetValue(value []byte) error {
rc := &addrSpace{subnets: make(map[SubnetKey]*PoolData)}
if err := json.Unmarshal(value, rc); err != nil {
return err
}
aSpace.subnets = rc.subnets
return nil
}
|
[
"func",
"(",
"aSpace",
"*",
"addrSpace",
")",
"SetValue",
"(",
"value",
"[",
"]",
"byte",
")",
"error",
"{",
"rc",
":=",
"&",
"addrSpace",
"{",
"subnets",
":",
"make",
"(",
"map",
"[",
"SubnetKey",
"]",
"*",
"PoolData",
")",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"value",
",",
"rc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"aSpace",
".",
"subnets",
"=",
"rc",
".",
"subnets",
"\n",
"return",
"nil",
"\n",
"}"
] |
// SetValue unmarshalls the data from the KV store.
|
[
"SetValue",
"unmarshalls",
"the",
"data",
"from",
"the",
"KV",
"store",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/store.go#L36-L43
|
22,562
|
docker/libnetwork
|
ipvs/ipvs.go
|
New
|
func New(path string) (*Handle, error) {
setup()
n := netns.None()
if path != "" {
var err error
n, err = netns.GetFromPath(path)
if err != nil {
return nil, err
}
}
defer n.Close()
sock, err := nl.GetNetlinkSocketAt(n, netns.None(), syscall.NETLINK_GENERIC)
if err != nil {
return nil, err
}
// Add operation timeout to avoid deadlocks
tv := syscall.NsecToTimeval(netlinkSendSocketTimeout.Nanoseconds())
if err := sock.SetSendTimeout(&tv); err != nil {
return nil, err
}
tv = syscall.NsecToTimeval(netlinkRecvSocketsTimeout.Nanoseconds())
if err := sock.SetReceiveTimeout(&tv); err != nil {
return nil, err
}
return &Handle{sock: sock}, nil
}
|
go
|
func New(path string) (*Handle, error) {
setup()
n := netns.None()
if path != "" {
var err error
n, err = netns.GetFromPath(path)
if err != nil {
return nil, err
}
}
defer n.Close()
sock, err := nl.GetNetlinkSocketAt(n, netns.None(), syscall.NETLINK_GENERIC)
if err != nil {
return nil, err
}
// Add operation timeout to avoid deadlocks
tv := syscall.NsecToTimeval(netlinkSendSocketTimeout.Nanoseconds())
if err := sock.SetSendTimeout(&tv); err != nil {
return nil, err
}
tv = syscall.NsecToTimeval(netlinkRecvSocketsTimeout.Nanoseconds())
if err := sock.SetReceiveTimeout(&tv); err != nil {
return nil, err
}
return &Handle{sock: sock}, nil
}
|
[
"func",
"New",
"(",
"path",
"string",
")",
"(",
"*",
"Handle",
",",
"error",
")",
"{",
"setup",
"(",
")",
"\n\n",
"n",
":=",
"netns",
".",
"None",
"(",
")",
"\n",
"if",
"path",
"!=",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"n",
",",
"err",
"=",
"netns",
".",
"GetFromPath",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"defer",
"n",
".",
"Close",
"(",
")",
"\n\n",
"sock",
",",
"err",
":=",
"nl",
".",
"GetNetlinkSocketAt",
"(",
"n",
",",
"netns",
".",
"None",
"(",
")",
",",
"syscall",
".",
"NETLINK_GENERIC",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Add operation timeout to avoid deadlocks",
"tv",
":=",
"syscall",
".",
"NsecToTimeval",
"(",
"netlinkSendSocketTimeout",
".",
"Nanoseconds",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"sock",
".",
"SetSendTimeout",
"(",
"&",
"tv",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tv",
"=",
"syscall",
".",
"NsecToTimeval",
"(",
"netlinkRecvSocketsTimeout",
".",
"Nanoseconds",
"(",
")",
")",
"\n",
"if",
"err",
":=",
"sock",
".",
"SetReceiveTimeout",
"(",
"&",
"tv",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"Handle",
"{",
"sock",
":",
"sock",
"}",
",",
"nil",
"\n",
"}"
] |
// New provides a new ipvs handle in the namespace pointed to by the
// passed path. It will return a valid handle or an error in case an
// error occurred while creating the handle.
|
[
"New",
"provides",
"a",
"new",
"ipvs",
"handle",
"in",
"the",
"namespace",
"pointed",
"to",
"by",
"the",
"passed",
"path",
".",
"It",
"will",
"return",
"a",
"valid",
"handle",
"or",
"an",
"error",
"in",
"case",
"an",
"error",
"occurred",
"while",
"creating",
"the",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L88-L116
|
22,563
|
docker/libnetwork
|
ipvs/ipvs.go
|
NewService
|
func (i *Handle) NewService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdNewService)
}
|
go
|
func (i *Handle) NewService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdNewService)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"NewService",
"(",
"s",
"*",
"Service",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"nil",
",",
"ipvsCmdNewService",
")",
"\n",
"}"
] |
// NewService creates a new ipvs service in the passed handle.
|
[
"NewService",
"creates",
"a",
"new",
"ipvs",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L127-L129
|
22,564
|
docker/libnetwork
|
ipvs/ipvs.go
|
IsServicePresent
|
func (i *Handle) IsServicePresent(s *Service) bool {
return nil == i.doCmd(s, nil, ipvsCmdGetService)
}
|
go
|
func (i *Handle) IsServicePresent(s *Service) bool {
return nil == i.doCmd(s, nil, ipvsCmdGetService)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"IsServicePresent",
"(",
"s",
"*",
"Service",
")",
"bool",
"{",
"return",
"nil",
"==",
"i",
".",
"doCmd",
"(",
"s",
",",
"nil",
",",
"ipvsCmdGetService",
")",
"\n",
"}"
] |
// IsServicePresent queries for the ipvs service in the passed handle.
|
[
"IsServicePresent",
"queries",
"for",
"the",
"ipvs",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L132-L134
|
22,565
|
docker/libnetwork
|
ipvs/ipvs.go
|
UpdateService
|
func (i *Handle) UpdateService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdSetService)
}
|
go
|
func (i *Handle) UpdateService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdSetService)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"UpdateService",
"(",
"s",
"*",
"Service",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"nil",
",",
"ipvsCmdSetService",
")",
"\n",
"}"
] |
// UpdateService updates an already existing service in the passed
// handle.
|
[
"UpdateService",
"updates",
"an",
"already",
"existing",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L138-L140
|
22,566
|
docker/libnetwork
|
ipvs/ipvs.go
|
DelService
|
func (i *Handle) DelService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdDelService)
}
|
go
|
func (i *Handle) DelService(s *Service) error {
return i.doCmd(s, nil, ipvsCmdDelService)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"DelService",
"(",
"s",
"*",
"Service",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"nil",
",",
"ipvsCmdDelService",
")",
"\n",
"}"
] |
// DelService deletes an already existing service in the passed
// handle.
|
[
"DelService",
"deletes",
"an",
"already",
"existing",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L144-L146
|
22,567
|
docker/libnetwork
|
ipvs/ipvs.go
|
Flush
|
func (i *Handle) Flush() error {
_, err := i.doCmdWithoutAttr(ipvsCmdFlush)
return err
}
|
go
|
func (i *Handle) Flush() error {
_, err := i.doCmdWithoutAttr(ipvsCmdFlush)
return err
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"Flush",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"i",
".",
"doCmdWithoutAttr",
"(",
"ipvsCmdFlush",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Flush deletes all existing services in the passed
// handle.
|
[
"Flush",
"deletes",
"all",
"existing",
"services",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L150-L153
|
22,568
|
docker/libnetwork
|
ipvs/ipvs.go
|
NewDestination
|
func (i *Handle) NewDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdNewDest)
}
|
go
|
func (i *Handle) NewDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdNewDest)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"NewDestination",
"(",
"s",
"*",
"Service",
",",
"d",
"*",
"Destination",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"d",
",",
"ipvsCmdNewDest",
")",
"\n",
"}"
] |
// NewDestination creates a new real server in the passed ipvs
// service which should already be existing in the passed handle.
|
[
"NewDestination",
"creates",
"a",
"new",
"real",
"server",
"in",
"the",
"passed",
"ipvs",
"service",
"which",
"should",
"already",
"be",
"existing",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L157-L159
|
22,569
|
docker/libnetwork
|
ipvs/ipvs.go
|
UpdateDestination
|
func (i *Handle) UpdateDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdSetDest)
}
|
go
|
func (i *Handle) UpdateDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdSetDest)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"UpdateDestination",
"(",
"s",
"*",
"Service",
",",
"d",
"*",
"Destination",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"d",
",",
"ipvsCmdSetDest",
")",
"\n",
"}"
] |
// UpdateDestination updates an already existing real server in the
// passed ipvs service in the passed handle.
|
[
"UpdateDestination",
"updates",
"an",
"already",
"existing",
"real",
"server",
"in",
"the",
"passed",
"ipvs",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L163-L165
|
22,570
|
docker/libnetwork
|
ipvs/ipvs.go
|
DelDestination
|
func (i *Handle) DelDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdDelDest)
}
|
go
|
func (i *Handle) DelDestination(s *Service, d *Destination) error {
return i.doCmd(s, d, ipvsCmdDelDest)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"DelDestination",
"(",
"s",
"*",
"Service",
",",
"d",
"*",
"Destination",
")",
"error",
"{",
"return",
"i",
".",
"doCmd",
"(",
"s",
",",
"d",
",",
"ipvsCmdDelDest",
")",
"\n",
"}"
] |
// DelDestination deletes an already existing real server in the
// passed ipvs service in the passed handle.
|
[
"DelDestination",
"deletes",
"an",
"already",
"existing",
"real",
"server",
"in",
"the",
"passed",
"ipvs",
"service",
"in",
"the",
"passed",
"handle",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L169-L171
|
22,571
|
docker/libnetwork
|
ipvs/ipvs.go
|
GetDestinations
|
func (i *Handle) GetDestinations(s *Service) ([]*Destination, error) {
return i.doGetDestinationsCmd(s, nil)
}
|
go
|
func (i *Handle) GetDestinations(s *Service) ([]*Destination, error) {
return i.doGetDestinationsCmd(s, nil)
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"GetDestinations",
"(",
"s",
"*",
"Service",
")",
"(",
"[",
"]",
"*",
"Destination",
",",
"error",
")",
"{",
"return",
"i",
".",
"doGetDestinationsCmd",
"(",
"s",
",",
"nil",
")",
"\n",
"}"
] |
// GetDestinations returns an array of Destinations configured for this Service
|
[
"GetDestinations",
"returns",
"an",
"array",
"of",
"Destinations",
"configured",
"for",
"this",
"Service"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L179-L181
|
22,572
|
docker/libnetwork
|
ipvs/ipvs.go
|
GetService
|
func (i *Handle) GetService(s *Service) (*Service, error) {
res, err := i.doGetServicesCmd(s)
if err != nil {
return nil, err
}
// We are looking for exactly one service otherwise error out
if len(res) != 1 {
return nil, fmt.Errorf("Expected only one service obtained=%d", len(res))
}
return res[0], nil
}
|
go
|
func (i *Handle) GetService(s *Service) (*Service, error) {
res, err := i.doGetServicesCmd(s)
if err != nil {
return nil, err
}
// We are looking for exactly one service otherwise error out
if len(res) != 1 {
return nil, fmt.Errorf("Expected only one service obtained=%d", len(res))
}
return res[0], nil
}
|
[
"func",
"(",
"i",
"*",
"Handle",
")",
"GetService",
"(",
"s",
"*",
"Service",
")",
"(",
"*",
"Service",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"i",
".",
"doGetServicesCmd",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// We are looking for exactly one service otherwise error out",
"if",
"len",
"(",
"res",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"res",
")",
")",
"\n",
"}",
"\n\n",
"return",
"res",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] |
// GetService gets details of a specific IPVS services, useful in updating statisics etc.,
|
[
"GetService",
"gets",
"details",
"of",
"a",
"specific",
"IPVS",
"services",
"useful",
"in",
"updating",
"statisics",
"etc",
"."
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipvs/ipvs.go#L184-L197
|
22,573
|
docker/libnetwork
|
portmapper/mapper.go
|
NewWithPortAllocator
|
func NewWithPortAllocator(allocator *portallocator.PortAllocator, proxyPath string) *PortMapper {
return &PortMapper{
currentMappings: make(map[string]*mapping),
Allocator: allocator,
proxyPath: proxyPath,
}
}
|
go
|
func NewWithPortAllocator(allocator *portallocator.PortAllocator, proxyPath string) *PortMapper {
return &PortMapper{
currentMappings: make(map[string]*mapping),
Allocator: allocator,
proxyPath: proxyPath,
}
}
|
[
"func",
"NewWithPortAllocator",
"(",
"allocator",
"*",
"portallocator",
".",
"PortAllocator",
",",
"proxyPath",
"string",
")",
"*",
"PortMapper",
"{",
"return",
"&",
"PortMapper",
"{",
"currentMappings",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"mapping",
")",
",",
"Allocator",
":",
"allocator",
",",
"proxyPath",
":",
"proxyPath",
",",
"}",
"\n",
"}"
] |
// NewWithPortAllocator returns a new instance of PortMapper which will use the specified PortAllocator
|
[
"NewWithPortAllocator",
"returns",
"a",
"new",
"instance",
"of",
"PortMapper",
"which",
"will",
"use",
"the",
"specified",
"PortAllocator"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portmapper/mapper.go#L39-L45
|
22,574
|
docker/libnetwork
|
portmapper/mapper.go
|
Map
|
func (pm *PortMapper) Map(container net.Addr, hostIP net.IP, hostPort int, useProxy bool) (host net.Addr, err error) {
return pm.MapRange(container, hostIP, hostPort, hostPort, useProxy)
}
|
go
|
func (pm *PortMapper) Map(container net.Addr, hostIP net.IP, hostPort int, useProxy bool) (host net.Addr, err error) {
return pm.MapRange(container, hostIP, hostPort, hostPort, useProxy)
}
|
[
"func",
"(",
"pm",
"*",
"PortMapper",
")",
"Map",
"(",
"container",
"net",
".",
"Addr",
",",
"hostIP",
"net",
".",
"IP",
",",
"hostPort",
"int",
",",
"useProxy",
"bool",
")",
"(",
"host",
"net",
".",
"Addr",
",",
"err",
"error",
")",
"{",
"return",
"pm",
".",
"MapRange",
"(",
"container",
",",
"hostIP",
",",
"hostPort",
",",
"hostPort",
",",
"useProxy",
")",
"\n",
"}"
] |
// Map maps the specified container transport address to the host's network address and transport port
|
[
"Map",
"maps",
"the",
"specified",
"container",
"transport",
"address",
"to",
"the",
"host",
"s",
"network",
"address",
"and",
"transport",
"port"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portmapper/mapper.go#L48-L50
|
22,575
|
docker/libnetwork
|
portmapper/mapper.go
|
Unmap
|
func (pm *PortMapper) Unmap(host net.Addr) error {
pm.lock.Lock()
defer pm.lock.Unlock()
key := getKey(host)
data, exists := pm.currentMappings[key]
if !exists {
return ErrPortNotMapped
}
if data.userlandProxy != nil {
data.userlandProxy.Stop()
}
delete(pm.currentMappings, key)
containerIP, containerPort := getIPAndPort(data.container)
hostIP, hostPort := getIPAndPort(data.host)
if err := pm.DeleteForwardingTableEntry(data.proto, hostIP, hostPort, containerIP.String(), containerPort); err != nil {
logrus.Errorf("Error on iptables delete: %s", err)
}
switch a := host.(type) {
case *net.TCPAddr:
return pm.Allocator.ReleasePort(a.IP, "tcp", a.Port)
case *net.UDPAddr:
return pm.Allocator.ReleasePort(a.IP, "udp", a.Port)
case *sctp.SCTPAddr:
if len(a.IP) == 0 {
return ErrSCTPAddrNoIP
}
return pm.Allocator.ReleasePort(a.IP[0], "sctp", a.Port)
}
return ErrUnknownBackendAddressType
}
|
go
|
func (pm *PortMapper) Unmap(host net.Addr) error {
pm.lock.Lock()
defer pm.lock.Unlock()
key := getKey(host)
data, exists := pm.currentMappings[key]
if !exists {
return ErrPortNotMapped
}
if data.userlandProxy != nil {
data.userlandProxy.Stop()
}
delete(pm.currentMappings, key)
containerIP, containerPort := getIPAndPort(data.container)
hostIP, hostPort := getIPAndPort(data.host)
if err := pm.DeleteForwardingTableEntry(data.proto, hostIP, hostPort, containerIP.String(), containerPort); err != nil {
logrus.Errorf("Error on iptables delete: %s", err)
}
switch a := host.(type) {
case *net.TCPAddr:
return pm.Allocator.ReleasePort(a.IP, "tcp", a.Port)
case *net.UDPAddr:
return pm.Allocator.ReleasePort(a.IP, "udp", a.Port)
case *sctp.SCTPAddr:
if len(a.IP) == 0 {
return ErrSCTPAddrNoIP
}
return pm.Allocator.ReleasePort(a.IP[0], "sctp", a.Port)
}
return ErrUnknownBackendAddressType
}
|
[
"func",
"(",
"pm",
"*",
"PortMapper",
")",
"Unmap",
"(",
"host",
"net",
".",
"Addr",
")",
"error",
"{",
"pm",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pm",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"key",
":=",
"getKey",
"(",
"host",
")",
"\n",
"data",
",",
"exists",
":=",
"pm",
".",
"currentMappings",
"[",
"key",
"]",
"\n",
"if",
"!",
"exists",
"{",
"return",
"ErrPortNotMapped",
"\n",
"}",
"\n\n",
"if",
"data",
".",
"userlandProxy",
"!=",
"nil",
"{",
"data",
".",
"userlandProxy",
".",
"Stop",
"(",
")",
"\n",
"}",
"\n\n",
"delete",
"(",
"pm",
".",
"currentMappings",
",",
"key",
")",
"\n\n",
"containerIP",
",",
"containerPort",
":=",
"getIPAndPort",
"(",
"data",
".",
"container",
")",
"\n",
"hostIP",
",",
"hostPort",
":=",
"getIPAndPort",
"(",
"data",
".",
"host",
")",
"\n",
"if",
"err",
":=",
"pm",
".",
"DeleteForwardingTableEntry",
"(",
"data",
".",
"proto",
",",
"hostIP",
",",
"hostPort",
",",
"containerIP",
".",
"String",
"(",
")",
",",
"containerPort",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"switch",
"a",
":=",
"host",
".",
"(",
"type",
")",
"{",
"case",
"*",
"net",
".",
"TCPAddr",
":",
"return",
"pm",
".",
"Allocator",
".",
"ReleasePort",
"(",
"a",
".",
"IP",
",",
"\"",
"\"",
",",
"a",
".",
"Port",
")",
"\n",
"case",
"*",
"net",
".",
"UDPAddr",
":",
"return",
"pm",
".",
"Allocator",
".",
"ReleasePort",
"(",
"a",
".",
"IP",
",",
"\"",
"\"",
",",
"a",
".",
"Port",
")",
"\n",
"case",
"*",
"sctp",
".",
"SCTPAddr",
":",
"if",
"len",
"(",
"a",
".",
"IP",
")",
"==",
"0",
"{",
"return",
"ErrSCTPAddrNoIP",
"\n",
"}",
"\n",
"return",
"pm",
".",
"Allocator",
".",
"ReleasePort",
"(",
"a",
".",
"IP",
"[",
"0",
"]",
",",
"\"",
"\"",
",",
"a",
".",
"Port",
")",
"\n",
"}",
"\n",
"return",
"ErrUnknownBackendAddressType",
"\n",
"}"
] |
// Unmap removes stored mapping for the specified host transport address
|
[
"Unmap",
"removes",
"stored",
"mapping",
"for",
"the",
"specified",
"host",
"transport",
"address"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portmapper/mapper.go#L185-L219
|
22,576
|
docker/libnetwork
|
portmapper/mapper.go
|
ReMapAll
|
func (pm *PortMapper) ReMapAll() {
pm.lock.Lock()
defer pm.lock.Unlock()
logrus.Debugln("Re-applying all port mappings.")
for _, data := range pm.currentMappings {
containerIP, containerPort := getIPAndPort(data.container)
hostIP, hostPort := getIPAndPort(data.host)
if err := pm.AppendForwardingTableEntry(data.proto, hostIP, hostPort, containerIP.String(), containerPort); err != nil {
logrus.Errorf("Error on iptables add: %s", err)
}
}
}
|
go
|
func (pm *PortMapper) ReMapAll() {
pm.lock.Lock()
defer pm.lock.Unlock()
logrus.Debugln("Re-applying all port mappings.")
for _, data := range pm.currentMappings {
containerIP, containerPort := getIPAndPort(data.container)
hostIP, hostPort := getIPAndPort(data.host)
if err := pm.AppendForwardingTableEntry(data.proto, hostIP, hostPort, containerIP.String(), containerPort); err != nil {
logrus.Errorf("Error on iptables add: %s", err)
}
}
}
|
[
"func",
"(",
"pm",
"*",
"PortMapper",
")",
"ReMapAll",
"(",
")",
"{",
"pm",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pm",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"logrus",
".",
"Debugln",
"(",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"data",
":=",
"range",
"pm",
".",
"currentMappings",
"{",
"containerIP",
",",
"containerPort",
":=",
"getIPAndPort",
"(",
"data",
".",
"container",
")",
"\n",
"hostIP",
",",
"hostPort",
":=",
"getIPAndPort",
"(",
"data",
".",
"host",
")",
"\n",
"if",
"err",
":=",
"pm",
".",
"AppendForwardingTableEntry",
"(",
"data",
".",
"proto",
",",
"hostIP",
",",
"hostPort",
",",
"containerIP",
".",
"String",
"(",
")",
",",
"containerPort",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
//ReMapAll will re-apply all port mappings
|
[
"ReMapAll",
"will",
"re",
"-",
"apply",
"all",
"port",
"mappings"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/portmapper/mapper.go#L222-L233
|
22,577
|
docker/libnetwork
|
datastore/mock_store.go
|
Get
|
func (s *MockStore) Get(key string) (*store.KVPair, error) {
mData := s.db[key]
if mData == nil {
return nil, nil
}
return &store.KVPair{Value: mData.Data, LastIndex: mData.Index}, nil
}
|
go
|
func (s *MockStore) Get(key string) (*store.KVPair, error) {
mData := s.db[key]
if mData == nil {
return nil, nil
}
return &store.KVPair{Value: mData.Data, LastIndex: mData.Index}, nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"*",
"store",
".",
"KVPair",
",",
"error",
")",
"{",
"mData",
":=",
"s",
".",
"db",
"[",
"key",
"]",
"\n",
"if",
"mData",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"store",
".",
"KVPair",
"{",
"Value",
":",
"mData",
".",
"Data",
",",
"LastIndex",
":",
"mData",
".",
"Index",
"}",
",",
"nil",
"\n\n",
"}"
] |
// Get the value at "key", returns the last modified index
// to use in conjunction to CAS calls
|
[
"Get",
"the",
"value",
"at",
"key",
"returns",
"the",
"last",
"modified",
"index",
"to",
"use",
"in",
"conjunction",
"to",
"CAS",
"calls"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L34-L41
|
22,578
|
docker/libnetwork
|
datastore/mock_store.go
|
Put
|
func (s *MockStore) Put(key string, value []byte, options *store.WriteOptions) error {
mData := s.db[key]
if mData == nil {
mData = &MockData{value, 0}
}
mData.Index = mData.Index + 1
s.db[key] = mData
return nil
}
|
go
|
func (s *MockStore) Put(key string, value []byte, options *store.WriteOptions) error {
mData := s.db[key]
if mData == nil {
mData = &MockData{value, 0}
}
mData.Index = mData.Index + 1
s.db[key] = mData
return nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"Put",
"(",
"key",
"string",
",",
"value",
"[",
"]",
"byte",
",",
"options",
"*",
"store",
".",
"WriteOptions",
")",
"error",
"{",
"mData",
":=",
"s",
".",
"db",
"[",
"key",
"]",
"\n",
"if",
"mData",
"==",
"nil",
"{",
"mData",
"=",
"&",
"MockData",
"{",
"value",
",",
"0",
"}",
"\n",
"}",
"\n",
"mData",
".",
"Index",
"=",
"mData",
".",
"Index",
"+",
"1",
"\n",
"s",
".",
"db",
"[",
"key",
"]",
"=",
"mData",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Put a value at "key"
|
[
"Put",
"a",
"value",
"at",
"key"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L44-L52
|
22,579
|
docker/libnetwork
|
datastore/mock_store.go
|
Delete
|
func (s *MockStore) Delete(key string) error {
delete(s.db, key)
return nil
}
|
go
|
func (s *MockStore) Delete(key string) error {
delete(s.db, key)
return nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"Delete",
"(",
"key",
"string",
")",
"error",
"{",
"delete",
"(",
"s",
".",
"db",
",",
"key",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Delete a value at "key"
|
[
"Delete",
"a",
"value",
"at",
"key"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L55-L58
|
22,580
|
docker/libnetwork
|
datastore/mock_store.go
|
Exists
|
func (s *MockStore) Exists(key string) (bool, error) {
_, ok := s.db[key]
return ok, nil
}
|
go
|
func (s *MockStore) Exists(key string) (bool, error) {
_, ok := s.db[key]
return ok, nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"Exists",
"(",
"key",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"_",
",",
"ok",
":=",
"s",
".",
"db",
"[",
"key",
"]",
"\n",
"return",
"ok",
",",
"nil",
"\n",
"}"
] |
// Exists checks that the key exists inside the store
|
[
"Exists",
"checks",
"that",
"the",
"key",
"exists",
"inside",
"the",
"store"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L61-L64
|
22,581
|
docker/libnetwork
|
datastore/mock_store.go
|
List
|
func (s *MockStore) List(prefix string) ([]*store.KVPair, error) {
return nil, ErrNotImplemented
}
|
go
|
func (s *MockStore) List(prefix string) ([]*store.KVPair, error) {
return nil, ErrNotImplemented
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"List",
"(",
"prefix",
"string",
")",
"(",
"[",
"]",
"*",
"store",
".",
"KVPair",
",",
"error",
")",
"{",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}"
] |
// List gets a range of values at "directory"
|
[
"List",
"gets",
"a",
"range",
"of",
"values",
"at",
"directory"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L67-L69
|
22,582
|
docker/libnetwork
|
datastore/mock_store.go
|
DeleteTree
|
func (s *MockStore) DeleteTree(prefix string) error {
delete(s.db, prefix)
return nil
}
|
go
|
func (s *MockStore) DeleteTree(prefix string) error {
delete(s.db, prefix)
return nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"DeleteTree",
"(",
"prefix",
"string",
")",
"error",
"{",
"delete",
"(",
"s",
".",
"db",
",",
"prefix",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// DeleteTree deletes a range of values at "directory"
|
[
"DeleteTree",
"deletes",
"a",
"range",
"of",
"values",
"at",
"directory"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L72-L75
|
22,583
|
docker/libnetwork
|
datastore/mock_store.go
|
Watch
|
func (s *MockStore) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error) {
return nil, ErrNotImplemented
}
|
go
|
func (s *MockStore) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error) {
return nil, ErrNotImplemented
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"Watch",
"(",
"key",
"string",
",",
"stopCh",
"<-",
"chan",
"struct",
"{",
"}",
")",
"(",
"<-",
"chan",
"*",
"store",
".",
"KVPair",
",",
"error",
")",
"{",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}"
] |
// Watch a single key for modifications
|
[
"Watch",
"a",
"single",
"key",
"for",
"modifications"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L78-L80
|
22,584
|
docker/libnetwork
|
datastore/mock_store.go
|
WatchTree
|
func (s *MockStore) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error) {
return nil, ErrNotImplemented
}
|
go
|
func (s *MockStore) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error) {
return nil, ErrNotImplemented
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"WatchTree",
"(",
"prefix",
"string",
",",
"stopCh",
"<-",
"chan",
"struct",
"{",
"}",
")",
"(",
"<-",
"chan",
"[",
"]",
"*",
"store",
".",
"KVPair",
",",
"error",
")",
"{",
"return",
"nil",
",",
"ErrNotImplemented",
"\n",
"}"
] |
// WatchTree triggers a watch on a range of values at "directory"
|
[
"WatchTree",
"triggers",
"a",
"watch",
"on",
"a",
"range",
"of",
"values",
"at",
"directory"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L83-L85
|
22,585
|
docker/libnetwork
|
datastore/mock_store.go
|
AtomicPut
|
func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error) {
mData := s.db[key]
if previous == nil {
if mData != nil {
return false, nil, types.BadRequestErrorf("atomic put failed because key exists")
} // Else OK.
} else {
if mData == nil {
return false, nil, types.BadRequestErrorf("atomic put failed because key exists")
}
if mData != nil && mData.Index != previous.LastIndex {
return false, nil, types.BadRequestErrorf("atomic put failed due to mismatched Index")
} // Else OK.
}
err := s.Put(key, newValue, nil)
if err != nil {
return false, nil, err
}
return true, &store.KVPair{Key: key, Value: newValue, LastIndex: s.db[key].Index}, nil
}
|
go
|
func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error) {
mData := s.db[key]
if previous == nil {
if mData != nil {
return false, nil, types.BadRequestErrorf("atomic put failed because key exists")
} // Else OK.
} else {
if mData == nil {
return false, nil, types.BadRequestErrorf("atomic put failed because key exists")
}
if mData != nil && mData.Index != previous.LastIndex {
return false, nil, types.BadRequestErrorf("atomic put failed due to mismatched Index")
} // Else OK.
}
err := s.Put(key, newValue, nil)
if err != nil {
return false, nil, err
}
return true, &store.KVPair{Key: key, Value: newValue, LastIndex: s.db[key].Index}, nil
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"AtomicPut",
"(",
"key",
"string",
",",
"newValue",
"[",
"]",
"byte",
",",
"previous",
"*",
"store",
".",
"KVPair",
",",
"options",
"*",
"store",
".",
"WriteOptions",
")",
"(",
"bool",
",",
"*",
"store",
".",
"KVPair",
",",
"error",
")",
"{",
"mData",
":=",
"s",
".",
"db",
"[",
"key",
"]",
"\n\n",
"if",
"previous",
"==",
"nil",
"{",
"if",
"mData",
"!=",
"nil",
"{",
"return",
"false",
",",
"nil",
",",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"// Else OK.",
"\n",
"}",
"else",
"{",
"if",
"mData",
"==",
"nil",
"{",
"return",
"false",
",",
"nil",
",",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"mData",
"!=",
"nil",
"&&",
"mData",
".",
"Index",
"!=",
"previous",
".",
"LastIndex",
"{",
"return",
"false",
",",
"nil",
",",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"// Else OK.",
"\n",
"}",
"\n",
"err",
":=",
"s",
".",
"Put",
"(",
"key",
",",
"newValue",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"true",
",",
"&",
"store",
".",
"KVPair",
"{",
"Key",
":",
"key",
",",
"Value",
":",
"newValue",
",",
"LastIndex",
":",
"s",
".",
"db",
"[",
"key",
"]",
".",
"Index",
"}",
",",
"nil",
"\n",
"}"
] |
// AtomicPut put a value at "key" if the key has not been
// modified in the meantime, throws an error if this is the case
|
[
"AtomicPut",
"put",
"a",
"value",
"at",
"key",
"if",
"the",
"key",
"has",
"not",
"been",
"modified",
"in",
"the",
"meantime",
"throws",
"an",
"error",
"if",
"this",
"is",
"the",
"case"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L94-L114
|
22,586
|
docker/libnetwork
|
datastore/mock_store.go
|
AtomicDelete
|
func (s *MockStore) AtomicDelete(key string, previous *store.KVPair) (bool, error) {
mData := s.db[key]
if mData != nil && mData.Index != previous.LastIndex {
return false, types.BadRequestErrorf("atomic delete failed due to mismatched Index")
}
return true, s.Delete(key)
}
|
go
|
func (s *MockStore) AtomicDelete(key string, previous *store.KVPair) (bool, error) {
mData := s.db[key]
if mData != nil && mData.Index != previous.LastIndex {
return false, types.BadRequestErrorf("atomic delete failed due to mismatched Index")
}
return true, s.Delete(key)
}
|
[
"func",
"(",
"s",
"*",
"MockStore",
")",
"AtomicDelete",
"(",
"key",
"string",
",",
"previous",
"*",
"store",
".",
"KVPair",
")",
"(",
"bool",
",",
"error",
")",
"{",
"mData",
":=",
"s",
".",
"db",
"[",
"key",
"]",
"\n",
"if",
"mData",
"!=",
"nil",
"&&",
"mData",
".",
"Index",
"!=",
"previous",
".",
"LastIndex",
"{",
"return",
"false",
",",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"true",
",",
"s",
".",
"Delete",
"(",
"key",
")",
"\n",
"}"
] |
// AtomicDelete deletes a value at "key" if the key has not
// been modified in the meantime, throws an error if this is the case
|
[
"AtomicDelete",
"deletes",
"a",
"value",
"at",
"key",
"if",
"the",
"key",
"has",
"not",
"been",
"modified",
"in",
"the",
"meantime",
"throws",
"an",
"error",
"if",
"this",
"is",
"the",
"case"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/datastore/mock_store.go#L118-L124
|
22,587
|
docker/libnetwork
|
resolver.go
|
NewResolver
|
func NewResolver(address string, proxyDNS bool, resolverKey string, backend DNSBackend) Resolver {
return &resolver{
backend: backend,
proxyDNS: proxyDNS,
listenAddress: address,
resolverKey: resolverKey,
err: fmt.Errorf("setup not done yet"),
startCh: make(chan struct{}, 1),
}
}
|
go
|
func NewResolver(address string, proxyDNS bool, resolverKey string, backend DNSBackend) Resolver {
return &resolver{
backend: backend,
proxyDNS: proxyDNS,
listenAddress: address,
resolverKey: resolverKey,
err: fmt.Errorf("setup not done yet"),
startCh: make(chan struct{}, 1),
}
}
|
[
"func",
"NewResolver",
"(",
"address",
"string",
",",
"proxyDNS",
"bool",
",",
"resolverKey",
"string",
",",
"backend",
"DNSBackend",
")",
"Resolver",
"{",
"return",
"&",
"resolver",
"{",
"backend",
":",
"backend",
",",
"proxyDNS",
":",
"proxyDNS",
",",
"listenAddress",
":",
"address",
",",
"resolverKey",
":",
"resolverKey",
",",
"err",
":",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
",",
"startCh",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"1",
")",
",",
"}",
"\n",
"}"
] |
// NewResolver creates a new instance of the Resolver
|
[
"NewResolver",
"creates",
"a",
"new",
"instance",
"of",
"the",
"Resolver"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/resolver.go#L102-L111
|
22,588
|
docker/libnetwork
|
ipam/utils.go
|
generateAddress
|
func generateAddress(ordinal uint64, network *net.IPNet) net.IP {
var address [16]byte
// Get network portion of IP
if getAddressVersion(network.IP) == v4 {
copy(address[:], network.IP.To4())
} else {
copy(address[:], network.IP)
}
end := len(network.Mask)
addIntToIP(address[:end], ordinal)
return net.IP(address[:end])
}
|
go
|
func generateAddress(ordinal uint64, network *net.IPNet) net.IP {
var address [16]byte
// Get network portion of IP
if getAddressVersion(network.IP) == v4 {
copy(address[:], network.IP.To4())
} else {
copy(address[:], network.IP)
}
end := len(network.Mask)
addIntToIP(address[:end], ordinal)
return net.IP(address[:end])
}
|
[
"func",
"generateAddress",
"(",
"ordinal",
"uint64",
",",
"network",
"*",
"net",
".",
"IPNet",
")",
"net",
".",
"IP",
"{",
"var",
"address",
"[",
"16",
"]",
"byte",
"\n\n",
"// Get network portion of IP",
"if",
"getAddressVersion",
"(",
"network",
".",
"IP",
")",
"==",
"v4",
"{",
"copy",
"(",
"address",
"[",
":",
"]",
",",
"network",
".",
"IP",
".",
"To4",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"copy",
"(",
"address",
"[",
":",
"]",
",",
"network",
".",
"IP",
")",
"\n",
"}",
"\n\n",
"end",
":=",
"len",
"(",
"network",
".",
"Mask",
")",
"\n",
"addIntToIP",
"(",
"address",
"[",
":",
"end",
"]",
",",
"ordinal",
")",
"\n\n",
"return",
"net",
".",
"IP",
"(",
"address",
"[",
":",
"end",
"]",
")",
"\n",
"}"
] |
// It generates the ip address in the passed subnet specified by
// the passed host address ordinal
|
[
"It",
"generates",
"the",
"ip",
"address",
"in",
"the",
"passed",
"subnet",
"specified",
"by",
"the",
"passed",
"host",
"address",
"ordinal"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/utils.go#L41-L55
|
22,589
|
docker/libnetwork
|
ipam/utils.go
|
addIntToIP
|
func addIntToIP(array []byte, ordinal uint64) {
for i := len(array) - 1; i >= 0; i-- {
array[i] |= (byte)(ordinal & 0xff)
ordinal >>= 8
}
}
|
go
|
func addIntToIP(array []byte, ordinal uint64) {
for i := len(array) - 1; i >= 0; i-- {
array[i] |= (byte)(ordinal & 0xff)
ordinal >>= 8
}
}
|
[
"func",
"addIntToIP",
"(",
"array",
"[",
"]",
"byte",
",",
"ordinal",
"uint64",
")",
"{",
"for",
"i",
":=",
"len",
"(",
"array",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"array",
"[",
"i",
"]",
"|=",
"(",
"byte",
")",
"(",
"ordinal",
"&",
"0xff",
")",
"\n",
"ordinal",
">>=",
"8",
"\n",
"}",
"\n",
"}"
] |
// Adds the ordinal IP to the current array
// 192.168.0.0 + 53 => 192.168.0.53
|
[
"Adds",
"the",
"ordinal",
"IP",
"to",
"the",
"current",
"array",
"192",
".",
"168",
".",
"0",
".",
"0",
"+",
"53",
"=",
">",
"192",
".",
"168",
".",
"0",
".",
"53"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/utils.go#L66-L71
|
22,590
|
docker/libnetwork
|
ipam/utils.go
|
ipToUint64
|
func ipToUint64(ip []byte) (value uint64) {
cip := types.GetMinimalIP(ip)
for i := 0; i < len(cip); i++ {
j := len(cip) - 1 - i
value += uint64(cip[i]) << uint(j*8)
}
return value
}
|
go
|
func ipToUint64(ip []byte) (value uint64) {
cip := types.GetMinimalIP(ip)
for i := 0; i < len(cip); i++ {
j := len(cip) - 1 - i
value += uint64(cip[i]) << uint(j*8)
}
return value
}
|
[
"func",
"ipToUint64",
"(",
"ip",
"[",
"]",
"byte",
")",
"(",
"value",
"uint64",
")",
"{",
"cip",
":=",
"types",
".",
"GetMinimalIP",
"(",
"ip",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"cip",
")",
";",
"i",
"++",
"{",
"j",
":=",
"len",
"(",
"cip",
")",
"-",
"1",
"-",
"i",
"\n",
"value",
"+=",
"uint64",
"(",
"cip",
"[",
"i",
"]",
")",
"<<",
"uint",
"(",
"j",
"*",
"8",
")",
"\n",
"}",
"\n",
"return",
"value",
"\n",
"}"
] |
// Convert an ordinal to the respective IP address
|
[
"Convert",
"an",
"ordinal",
"to",
"the",
"respective",
"IP",
"address"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/utils.go#L74-L81
|
22,591
|
docker/libnetwork
|
netlabel/labels.go
|
Key
|
func Key(label string) (key string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
key = kv[0]
}
return
}
|
go
|
func Key(label string) (key string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
key = kv[0]
}
return
}
|
[
"func",
"Key",
"(",
"label",
"string",
")",
"(",
"key",
"string",
")",
"{",
"if",
"kv",
":=",
"strings",
".",
"SplitN",
"(",
"label",
",",
"\"",
"\"",
",",
"2",
")",
";",
"len",
"(",
"kv",
")",
">",
"0",
"{",
"key",
"=",
"kv",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Key extracts the key portion of the label
|
[
"Key",
"extracts",
"the",
"key",
"portion",
"of",
"the",
"label"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netlabel/labels.go#L105-L110
|
22,592
|
docker/libnetwork
|
netlabel/labels.go
|
Value
|
func Value(label string) (value string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 1 {
value = kv[1]
}
return
}
|
go
|
func Value(label string) (value string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 1 {
value = kv[1]
}
return
}
|
[
"func",
"Value",
"(",
"label",
"string",
")",
"(",
"value",
"string",
")",
"{",
"if",
"kv",
":=",
"strings",
".",
"SplitN",
"(",
"label",
",",
"\"",
"\"",
",",
"2",
")",
";",
"len",
"(",
"kv",
")",
">",
"1",
"{",
"value",
"=",
"kv",
"[",
"1",
"]",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Value extracts the value portion of the label
|
[
"Value",
"extracts",
"the",
"value",
"portion",
"of",
"the",
"label"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/netlabel/labels.go#L113-L118
|
22,593
|
docker/libnetwork
|
ipams/windowsipam/windowsipam.go
|
GetInit
|
func GetInit(ipamName string) func(ic ipamapi.Callback, l, g interface{}) error {
return func(ic ipamapi.Callback, l, g interface{}) error {
return ic.RegisterIpamDriver(ipamName, &allocator{})
}
}
|
go
|
func GetInit(ipamName string) func(ic ipamapi.Callback, l, g interface{}) error {
return func(ic ipamapi.Callback, l, g interface{}) error {
return ic.RegisterIpamDriver(ipamName, &allocator{})
}
}
|
[
"func",
"GetInit",
"(",
"ipamName",
"string",
")",
"func",
"(",
"ic",
"ipamapi",
".",
"Callback",
",",
"l",
",",
"g",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"func",
"(",
"ic",
"ipamapi",
".",
"Callback",
",",
"l",
",",
"g",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"ic",
".",
"RegisterIpamDriver",
"(",
"ipamName",
",",
"&",
"allocator",
"{",
"}",
")",
"\n",
"}",
"\n",
"}"
] |
// GetInit registers the built-in ipam service with libnetwork
|
[
"GetInit",
"registers",
"the",
"built",
"-",
"in",
"ipam",
"service",
"with",
"libnetwork"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/windowsipam/windowsipam.go#L28-L32
|
22,594
|
docker/libnetwork
|
ipams/windowsipam/windowsipam.go
|
RequestPool
|
func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
logrus.Debugf("RequestPool(%s, %s, %s, %v, %t)", addressSpace, pool, subPool, options, v6)
if subPool != "" || v6 {
return "", nil, nil, types.InternalErrorf("This request is not supported by null ipam driver")
}
var ipNet *net.IPNet
var err error
if pool != "" {
_, ipNet, err = net.ParseCIDR(pool)
if err != nil {
return "", nil, nil, err
}
} else {
ipNet = defaultPool
}
return ipNet.String(), ipNet, nil, nil
}
|
go
|
func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
logrus.Debugf("RequestPool(%s, %s, %s, %v, %t)", addressSpace, pool, subPool, options, v6)
if subPool != "" || v6 {
return "", nil, nil, types.InternalErrorf("This request is not supported by null ipam driver")
}
var ipNet *net.IPNet
var err error
if pool != "" {
_, ipNet, err = net.ParseCIDR(pool)
if err != nil {
return "", nil, nil, err
}
} else {
ipNet = defaultPool
}
return ipNet.String(), ipNet, nil, nil
}
|
[
"func",
"(",
"a",
"*",
"allocator",
")",
"RequestPool",
"(",
"addressSpace",
",",
"pool",
",",
"subPool",
"string",
",",
"options",
"map",
"[",
"string",
"]",
"string",
",",
"v6",
"bool",
")",
"(",
"string",
",",
"*",
"net",
".",
"IPNet",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"addressSpace",
",",
"pool",
",",
"subPool",
",",
"options",
",",
"v6",
")",
"\n",
"if",
"subPool",
"!=",
"\"",
"\"",
"||",
"v6",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"types",
".",
"InternalErrorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"ipNet",
"*",
"net",
".",
"IPNet",
"\n",
"var",
"err",
"error",
"\n\n",
"if",
"pool",
"!=",
"\"",
"\"",
"{",
"_",
",",
"ipNet",
",",
"err",
"=",
"net",
".",
"ParseCIDR",
"(",
"pool",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"ipNet",
"=",
"defaultPool",
"\n",
"}",
"\n\n",
"return",
"ipNet",
".",
"String",
"(",
")",
",",
"ipNet",
",",
"nil",
",",
"nil",
"\n",
"}"
] |
// RequestPool returns an address pool along with its unique id. This is a null ipam driver. It allocates the
// subnet user asked and does not validate anything. Doesn't support subpool allocation
|
[
"RequestPool",
"returns",
"an",
"address",
"pool",
"along",
"with",
"its",
"unique",
"id",
".",
"This",
"is",
"a",
"null",
"ipam",
"driver",
".",
"It",
"allocates",
"the",
"subnet",
"user",
"asked",
"and",
"does",
"not",
"validate",
"anything",
".",
"Doesn",
"t",
"support",
"subpool",
"allocation"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/windowsipam/windowsipam.go#L40-L59
|
22,595
|
docker/libnetwork
|
ipams/windowsipam/windowsipam.go
|
ReleasePool
|
func (a *allocator) ReleasePool(poolID string) error {
logrus.Debugf("ReleasePool(%s)", poolID)
return nil
}
|
go
|
func (a *allocator) ReleasePool(poolID string) error {
logrus.Debugf("ReleasePool(%s)", poolID)
return nil
}
|
[
"func",
"(",
"a",
"*",
"allocator",
")",
"ReleasePool",
"(",
"poolID",
"string",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"poolID",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ReleasePool releases the address pool - always succeeds
|
[
"ReleasePool",
"releases",
"the",
"address",
"pool",
"-",
"always",
"succeeds"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/windowsipam/windowsipam.go#L62-L65
|
22,596
|
docker/libnetwork
|
ipams/windowsipam/windowsipam.go
|
ReleaseAddress
|
func (a *allocator) ReleaseAddress(poolID string, address net.IP) error {
logrus.Debugf("ReleaseAddress(%s, %v)", poolID, address)
return nil
}
|
go
|
func (a *allocator) ReleaseAddress(poolID string, address net.IP) error {
logrus.Debugf("ReleaseAddress(%s, %v)", poolID, address)
return nil
}
|
[
"func",
"(",
"a",
"*",
"allocator",
")",
"ReleaseAddress",
"(",
"poolID",
"string",
",",
"address",
"net",
".",
"IP",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"poolID",
",",
"address",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ReleaseAddress releases the address - always succeeds
|
[
"ReleaseAddress",
"releases",
"the",
"address",
"-",
"always",
"succeeds"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/windowsipam/windowsipam.go#L85-L88
|
22,597
|
docker/libnetwork
|
ipams/remote/api/api.go
|
ToCapability
|
func (capRes GetCapabilityResponse) ToCapability() *ipamapi.Capability {
return &ipamapi.Capability{
RequiresMACAddress: capRes.RequiresMACAddress,
RequiresRequestReplay: capRes.RequiresRequestReplay,
}
}
|
go
|
func (capRes GetCapabilityResponse) ToCapability() *ipamapi.Capability {
return &ipamapi.Capability{
RequiresMACAddress: capRes.RequiresMACAddress,
RequiresRequestReplay: capRes.RequiresRequestReplay,
}
}
|
[
"func",
"(",
"capRes",
"GetCapabilityResponse",
")",
"ToCapability",
"(",
")",
"*",
"ipamapi",
".",
"Capability",
"{",
"return",
"&",
"ipamapi",
".",
"Capability",
"{",
"RequiresMACAddress",
":",
"capRes",
".",
"RequiresMACAddress",
",",
"RequiresRequestReplay",
":",
"capRes",
".",
"RequiresRequestReplay",
",",
"}",
"\n",
"}"
] |
// ToCapability converts the capability response into the internal ipam driver capability structure
|
[
"ToCapability",
"converts",
"the",
"capability",
"response",
"into",
"the",
"internal",
"ipam",
"driver",
"capability",
"structure"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/api/api.go#L30-L35
|
22,598
|
docker/libnetwork
|
driverapi/driverapi.go
|
IsValidType
|
func IsValidType(objType ObjectType) bool {
switch objType {
case EndpointObject:
fallthrough
case NetworkObject:
fallthrough
case OpaqueObject:
return true
}
return false
}
|
go
|
func IsValidType(objType ObjectType) bool {
switch objType {
case EndpointObject:
fallthrough
case NetworkObject:
fallthrough
case OpaqueObject:
return true
}
return false
}
|
[
"func",
"IsValidType",
"(",
"objType",
"ObjectType",
")",
"bool",
"{",
"switch",
"objType",
"{",
"case",
"EndpointObject",
":",
"fallthrough",
"\n",
"case",
"NetworkObject",
":",
"fallthrough",
"\n",
"case",
"OpaqueObject",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// IsValidType validates the passed in type against the valid object types
|
[
"IsValidType",
"validates",
"the",
"passed",
"in",
"type",
"against",
"the",
"valid",
"object",
"types"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/driverapi/driverapi.go#L203-L213
|
22,599
|
docker/libnetwork
|
network.go
|
Validate
|
func (c *IpamConf) Validate() error {
if c.Gateway != "" && nil == net.ParseIP(c.Gateway) {
return types.BadRequestErrorf("invalid gateway address %s in Ipam configuration", c.Gateway)
}
return nil
}
|
go
|
func (c *IpamConf) Validate() error {
if c.Gateway != "" && nil == net.ParseIP(c.Gateway) {
return types.BadRequestErrorf("invalid gateway address %s in Ipam configuration", c.Gateway)
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"IpamConf",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"c",
".",
"Gateway",
"!=",
"\"",
"\"",
"&&",
"nil",
"==",
"net",
".",
"ParseIP",
"(",
"c",
".",
"Gateway",
")",
"{",
"return",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
",",
"c",
".",
"Gateway",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate checks whether the configuration is valid
|
[
"Validate",
"checks",
"whether",
"the",
"configuration",
"is",
"valid"
] |
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
|
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/network.go#L146-L151
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.