repo
stringlengths
5
67
sha
stringlengths
40
40
path
stringlengths
4
234
url
stringlengths
85
339
language
stringclasses
6 values
split
stringclasses
3 values
doc
stringlengths
3
51.2k
sign
stringlengths
5
8.01k
problem
stringlengths
13
51.2k
output
stringlengths
0
3.87M
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L822-L824
go
train
// StringVar defines a string flag with specified name, default value, and usage string. // The argument p points to a string variable in which to store the value of the flag.
func (fs *FlagSet) StringVar(p *string, names []string, value string, usage string)
// StringVar defines a string flag with specified name, default value, and usage string. // The argument p points to a string variable in which to store the value of the flag. func (fs *FlagSet) StringVar(p *string, names []string, value string, usage string)
{ fs.Var(newStringValue(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L828-L830
go
train
// StringVar defines a string flag with specified name, default value, and usage string. // The argument p points to a string variable in which to store the value of the flag.
func StringVar(p *string, names []string, value string, usage string)
// StringVar defines a string flag with specified name, default value, and usage string. // The argument p points to a string variable in which to store the value of the flag. func StringVar(p *string, names []string, value string, usage string)
{ CommandLine.Var(newStringValue(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L834-L838
go
train
// String defines a string flag with specified name, default value, and usage string. // The return value is the address of a string variable that stores the value of the flag.
func (fs *FlagSet) String(names []string, value string, usage string) *string
// String defines a string flag with specified name, default value, and usage string. // The return value is the address of a string variable that stores the value of the flag. func (fs *FlagSet) String(names []string, value string, usage string) *string
{ p := new(string) fs.StringVar(p, names, value, usage) return p }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L842-L844
go
train
// String defines a string flag with specified name, default value, and usage string. // The return value is the address of a string variable that stores the value of the flag.
func String(names []string, value string, usage string) *string
// String defines a string flag with specified name, default value, and usage string. // The return value is the address of a string variable that stores the value of the flag. func String(names []string, value string, usage string) *string
{ return CommandLine.String(names, value, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L848-L850
go
train
// Float64Var defines a float64 flag with specified name, default value, and usage string. // The argument p points to a float64 variable in which to store the value of the flag.
func (fs *FlagSet) Float64Var(p *float64, names []string, value float64, usage string)
// Float64Var defines a float64 flag with specified name, default value, and usage string. // The argument p points to a float64 variable in which to store the value of the flag. func (fs *FlagSet) Float64Var(p *float64, names []string, value float64, usage string)
{ fs.Var(newFloat64Value(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L860-L864
go
train
// Float64 defines a float64 flag with specified name, default value, and usage string. // The return value is the address of a float64 variable that stores the value of the flag.
func (fs *FlagSet) Float64(names []string, value float64, usage string) *float64
// Float64 defines a float64 flag with specified name, default value, and usage string. // The return value is the address of a float64 variable that stores the value of the flag. func (fs *FlagSet) Float64(names []string, value float64, usage string) *float64
{ p := new(float64) fs.Float64Var(p, names, value, usage) return p }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L868-L870
go
train
// Float64 defines a float64 flag with specified name, default value, and usage string. // The return value is the address of a float64 variable that stores the value of the flag.
func Float64(names []string, value float64, usage string) *float64
// Float64 defines a float64 flag with specified name, default value, and usage string. // The return value is the address of a float64 variable that stores the value of the flag. func Float64(names []string, value float64, usage string) *float64
{ return CommandLine.Float64(names, value, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L874-L876
go
train
// DurationVar defines a time.Duration flag with specified name, default value, and usage string. // The argument p points to a time.Duration variable in which to store the value of the flag.
func (fs *FlagSet) DurationVar(p *time.Duration, names []string, value time.Duration, usage string)
// DurationVar defines a time.Duration flag with specified name, default value, and usage string. // The argument p points to a time.Duration variable in which to store the value of the flag. func (fs *FlagSet) DurationVar(p *time.Duration, names []string, value time.Duration, usage string)
{ fs.Var(newDurationValue(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L880-L882
go
train
// DurationVar defines a time.Duration flag with specified name, default value, and usage string. // The argument p points to a time.Duration variable in which to store the value of the flag.
func DurationVar(p *time.Duration, names []string, value time.Duration, usage string)
// DurationVar defines a time.Duration flag with specified name, default value, and usage string. // The argument p points to a time.Duration variable in which to store the value of the flag. func DurationVar(p *time.Duration, names []string, value time.Duration, usage string)
{ CommandLine.Var(newDurationValue(value, p), names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L886-L890
go
train
// Duration defines a time.Duration flag with specified name, default value, and usage string. // The return value is the address of a time.Duration variable that stores the value of the flag.
func (fs *FlagSet) Duration(names []string, value time.Duration, usage string) *time.Duration
// Duration defines a time.Duration flag with specified name, default value, and usage string. // The return value is the address of a time.Duration variable that stores the value of the flag. func (fs *FlagSet) Duration(names []string, value time.Duration, usage string) *time.Duration
{ p := new(time.Duration) fs.DurationVar(p, names, value, usage) return p }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L894-L896
go
train
// Duration defines a time.Duration flag with specified name, default value, and usage string. // The return value is the address of a time.Duration variable that stores the value of the flag.
func Duration(names []string, value time.Duration, usage string) *time.Duration
// Duration defines a time.Duration flag with specified name, default value, and usage string. // The return value is the address of a time.Duration variable that stores the value of the flag. func Duration(names []string, value time.Duration, usage string) *time.Duration
{ return CommandLine.Duration(names, value, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L904-L925
go
train
// Var defines a flag with the specified name and usage string. The type and // value of the flag are represented by the first argument, of type Value, which // typically holds a user-defined implementation of Value. For instance, the // caller could create a flag that turns a comma-separated string into a slice // of ...
func (fs *FlagSet) Var(value Value, names []string, usage string)
// Var defines a flag with the specified name and usage string. The type and // value of the flag are represented by the first argument, of type Value, which // typically holds a user-defined implementation of Value. For instance, the // caller could create a flag that turns a comma-separated string into a slice // of ...
{ // Remember the default value as a string; it won't change. flag := &Flag{names, usage, value, value.String()} for _, name := range names { name = strings.TrimPrefix(name, "#") _, alreadythere := fs.formal[name] if alreadythere { var msg string if fs.name == "" { msg = fmt.Sprintf("flag redefined:...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L933-L935
go
train
// Var defines a flag with the specified name and usage string. The type and // value of the flag are represented by the first argument, of type Value, which // typically holds a user-defined implementation of Value. For instance, the // caller could create a flag that turns a comma-separated string into a slice // of ...
func Var(value Value, names []string, usage string)
// Var defines a flag with the specified name and usage string. The type and // value of the flag are represented by the first argument, of type Value, which // typically holds a user-defined implementation of Value. For instance, the // caller could create a flag that turns a comma-separated string into a slice // of ...
{ CommandLine.Var(value, names, usage) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L939-L948
go
train
// failf prints to standard error a formatted error and usage message and // returns the error.
func (fs *FlagSet) failf(format string, a ...interface{}) error
// failf prints to standard error a formatted error and usage message and // returns the error. func (fs *FlagSet) failf(format string, a ...interface{}) error
{ err := fmt.Errorf(format, a...) fmt.Fprintln(fs.Out(), err) if os.Args[0] == fs.name { fmt.Fprintf(fs.Out(), "See '%s --help'.\n", os.Args[0]) } else { fmt.Fprintf(fs.Out(), "See '%s %s --help'.\n", os.Args[0], fs.name) } return err }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L952-L960
go
train
// usage calls the Usage method for the flag set, or the usage function if // the flag set is CommandLine.
func (fs *FlagSet) usage()
// usage calls the Usage method for the flag set, or the usage function if // the flag set is CommandLine. func (fs *FlagSet) usage()
{ if fs == CommandLine { Usage() } else if fs.Usage == nil { defaultUsage(fs) } else { fs.Usage() } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L997-L1079
go
train
// parseOne parses one flag. It reports whether a flag was seen.
func (fs *FlagSet) parseOne() (bool, string, error)
// parseOne parses one flag. It reports whether a flag was seen. func (fs *FlagSet) parseOne() (bool, string, error)
{ if len(fs.args) == 0 { return false, "", nil } s := fs.args[0] if len(s) == 0 || s[0] != '-' || len(s) == 1 { return false, "", nil } if s[1] == '-' && len(s) == 2 { // "--" terminates the flags fs.args = fs.args[1:] return false, "", nil } name := s[1:] if len(name) == 0 || name[0] == '=' { retur...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L1085-L1127
go
train
// Parse parses flag definitions from the argument list, which should not // include the command name. Must be called after all flags in the FlagSet // are defined and before flags are accessed by the program. // The return value will be ErrHelp if -help was set but not defined.
func (fs *FlagSet) Parse(arguments []string) error
// Parse parses flag definitions from the argument list, which should not // include the command name. Must be called after all flags in the FlagSet // are defined and before flags are accessed by the program. // The return value will be ErrHelp if -help was set but not defined. func (fs *FlagSet) Parse(arguments []st...
{ fs.parsed = true fs.args = arguments for { seen, name, err := fs.parseOne() if seen { continue } if err == nil { break } if err == ErrRetry { if len(name) > 1 { err = nil for _, letter := range strings.Split(name, "") { fs.args = append([]string{"-" + letter}, fs.args...) se...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L1134-L1154
go
train
// ParseFlags is a utility function that adds a help flag if withHelp is true, // calls fs.Parse(args) and prints a relevant error message if there are // incorrect number of arguments. It returns error only if error handling is // set to ContinueOnError and parsing fails. If error handling is set to // ExitOnError, it...
func (fs *FlagSet) ParseFlags(args []string, withHelp bool) error
// ParseFlags is a utility function that adds a help flag if withHelp is true, // calls fs.Parse(args) and prints a relevant error message if there are // incorrect number of arguments. It returns error only if error handling is // set to ContinueOnError and parsing fails. If error handling is set to // ExitOnError, it...
{ var help *bool if withHelp { help = fs.Bool([]string{"#help", "-help"}, false, "Print usage") } if err := fs.Parse(args); err != nil { return err } if help != nil && *help { fs.SetOutput(os.Stdout) fs.Usage() os.Exit(0) } if str := fs.CheckArgs(); str != "" { fs.SetOutput(os.Stderr) fs.ReportEr...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L1158-L1167
go
train
// ReportError is a utility method that prints a user-friendly message // containing the error that occurred during parsing and a suggestion to get help
func (fs *FlagSet) ReportError(str string, withHelp bool)
// ReportError is a utility method that prints a user-friendly message // containing the error that occurred during parsing and a suggestion to get help func (fs *FlagSet) ReportError(str string, withHelp bool)
{ if withHelp { if os.Args[0] == fs.Name() { str += ".\nSee '" + os.Args[0] + " --help'" } else { str += ".\nSee '" + os.Args[0] + " " + fs.Name() + " --help'" } } fmt.Fprintf(fs.Out(), "%s: %s.\n", os.Args[0], str) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L1193-L1199
go
train
// NewFlagSet returns a new, empty flag set with the specified name and // error handling property.
func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet
// NewFlagSet returns a new, empty flag set with the specified name and // error handling property. func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet
{ f := &FlagSet{ name: name, errorHandling: errorHandling, } return f }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L1204-L1207
go
train
// Init sets the name and error handling property for a flag set. // By default, the zero FlagSet uses an empty name and the // ContinueOnError error handling policy.
func (fs *FlagSet) Init(name string, errorHandling ErrorHandling)
// Init sets the name and error handling property for a flag set. // By default, the zero FlagSet uses an empty name and the // ContinueOnError error handling policy. func (fs *FlagSet) Init(name string, errorHandling ErrorHandling)
{ fs.name = name fs.errorHandling = errorHandling }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L1229-L1237
go
train
// Name returns the name of a mergeVal. // If the original value had a name, return the original name, // otherwise, return the key assigned to this mergeVal.
func (v mergeVal) Name() string
// Name returns the name of a mergeVal. // If the original value had a name, return the original name, // otherwise, return the key assigned to this mergeVal. func (v mergeVal) Name() string
{ type namedValue interface { Name() string } if nVal, ok := v.Value.(namedValue); ok { return nVal.Name() } return v.key }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/mflag/flag.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/mflag/flag.go#L1242-L1275
go
train
// Merge is an helper function that merges n FlagSets into a single dest FlagSet // In case of name collision between the flagsets it will apply // the destination FlagSet's errorHandling behavior.
func Merge(dest *FlagSet, flagsets ...*FlagSet) error
// Merge is an helper function that merges n FlagSets into a single dest FlagSet // In case of name collision between the flagsets it will apply // the destination FlagSet's errorHandling behavior. func Merge(dest *FlagSet, flagsets ...*FlagSet) error
{ for _, fset := range flagsets { if fset.formal == nil { continue } for k, f := range fset.formal { if _, ok := dest.formal[k]; ok { var err error if fset.name == "" { err = fmt.Errorf("flag redefined: %s", k) } else { err = fmt.Errorf("%s flag redefined: %s", fset.name, k) } ...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
sandbox_dns_unix.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/sandbox_dns_unix.go#L351-L405
go
train
// Embedded DNS server has to be enabled for this sandbox. Rebuild the container's // resolv.conf by doing the following // - Add only the embedded server's IP to container's resolv.conf // - If the embedded server needs any resolv.conf options add it to the current list
func (sb *sandbox) rebuildDNS() error
// Embedded DNS server has to be enabled for this sandbox. Rebuild the container's // resolv.conf by doing the following // - Add only the embedded server's IP to container's resolv.conf // - If the embedded server needs any resolv.conf options add it to the current list func (sb *sandbox) rebuildDNS() error
{ currRC, err := resolvconf.GetSpecific(sb.config.resolvConfPath) if err != nil { return err } if len(sb.extDNS) == 0 { sb.setExternalResolvers(currRC.Content, types.IPv4, false) } var ( dnsList = []string{sb.resolver.NameServer()} dnsOptionsList = resolvconf.GetOptions(currRC.Content) dnsSearc...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/client.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/client.go#L25-L31
go
train
// NewNetworkCli is a convenient function to create a NetworkCli object
func NewNetworkCli(out, err io.Writer, call CallFunc) *NetworkCli
// NewNetworkCli is a convenient function to create a NetworkCli object func NewNetworkCli(out, err io.Writer, call CallFunc) *NetworkCli
{ return &NetworkCli{ out: out, err: err, call: call, } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/client.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/client.go#L34-L48
go
train
// getMethod is Borrowed from Docker UI which uses reflection to identify the UI Handler
func (cli *NetworkCli) getMethod(args ...string) (func(string, ...string) error, bool)
// getMethod is Borrowed from Docker UI which uses reflection to identify the UI Handler func (cli *NetworkCli) getMethod(args ...string) (func(string, ...string) error, bool)
{ camelArgs := make([]string, len(args)) for i, s := range args { if len(s) == 0 { return nil, false } camelArgs[i] = strings.ToUpper(s[:1]) + strings.ToLower(s[1:]) } methodName := "Cmd" + strings.Join(camelArgs, "") method := reflect.ValueOf(cli).MethodByName(methodName) if !method.IsValid() { retur...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/client.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/client.go#L52-L74
go
train
// Cmd is borrowed from Docker UI and acts as the entry point for network UI commands. // network UI commands are designed to be invoked from multiple parent chains
func (cli *NetworkCli) Cmd(chain string, args ...string) error
// Cmd is borrowed from Docker UI and acts as the entry point for network UI commands. // network UI commands are designed to be invoked from multiple parent chains func (cli *NetworkCli) Cmd(chain string, args ...string) error
{ if len(args) > 2 { method, exists := cli.getMethod(args[:3]...) if exists { return method(chain+" "+args[0]+" "+args[1], args[3:]...) } } if len(args) > 1 { method, exists := cli.getMethod(args[:2]...) if exists { return method(chain+" "+args[0], args[2:]...) } } if len(args) > 0 { method, e...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
client/client.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/client/client.go#L77-L101
go
train
// Subcmd is borrowed from Docker UI and performs the same function of configuring the subCmds
func (cli *NetworkCli) Subcmd(chain, name, signature, description string, exitOnError bool) *flag.FlagSet
// Subcmd is borrowed from Docker UI and performs the same function of configuring the subCmds func (cli *NetworkCli) Subcmd(chain, name, signature, description string, exitOnError bool) *flag.FlagSet
{ var errorHandling flag.ErrorHandling if exitOnError { errorHandling = flag.ExitOnError } else { errorHandling = flag.ContinueOnError } flags := flag.NewFlagSet(name, errorHandling) flags.Usage = func() { flags.ShortUsage() flags.PrintDefaults() } flags.ShortUsage = func() { options := "" if signa...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
etchosts/etchosts.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/etchosts/etchosts.go#L22-L25
go
train
// WriteTo writes record to file and returns bytes written or error
func (r Record) WriteTo(w io.Writer) (int64, error)
// WriteTo writes record to file and returns bytes written or error func (r Record) WriteTo(w io.Writer) (int64, error)
{ n, err := fmt.Fprintf(w, "%s\t%s\n", r.IP, r.Hosts) return int64(n), err }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
etchosts/etchosts.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/etchosts/etchosts.go#L63-L68
go
train
// Drop drops the path string from the path cache
func Drop(path string)
// Drop drops the path string from the path cache func Drop(path string)
{ pathMutex.Lock() defer pathMutex.Unlock() delete(pathMap, path) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
etchosts/etchosts.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/etchosts/etchosts.go#L74-L112
go
train
// Build function // path is path to host file string required // IP, hostname, and domainname set main record leave empty for no master record // extraContent is an array of extra host records.
func Build(path, IP, hostname, domainname string, extraContent []Record) error
// Build function // path is path to host file string required // IP, hostname, and domainname set main record leave empty for no master record // extraContent is an array of extra host records. func Build(path, IP, hostname, domainname string, extraContent []Record) error
{ defer pathLock(path)() content := bytes.NewBuffer(nil) if IP != "" { //set main record var mainRec Record mainRec.IP = IP // User might have provided a FQDN in hostname or split it across hostname // and domainname. We want the FQDN and the bare hostname. fqdn := hostname if domainname != "" { ...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
etchosts/etchosts.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/etchosts/etchosts.go#L115-L128
go
train
// Add adds an arbitrary number of Records to an already existing /etc/hosts file
func Add(path string, recs []Record) error
// Add adds an arbitrary number of Records to an already existing /etc/hosts file func Add(path string, recs []Record) error
{ defer pathLock(path)() if len(recs) == 0 { return nil } b, err := mergeRecords(path, recs) if err != nil { return err } return ioutil.WriteFile(path, b, 0644) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
etchosts/etchosts.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/etchosts/etchosts.go#L153-L193
go
train
// Delete deletes an arbitrary number of Records already existing in /etc/hosts file
func Delete(path string, recs []Record) error
// Delete deletes an arbitrary number of Records already existing in /etc/hosts file func Delete(path string, recs []Record) error
{ defer pathLock(path)() if len(recs) == 0 { return nil } old, err := os.Open(path) if err != nil { return err } var buf bytes.Buffer s := bufio.NewScanner(old) eol := []byte{'\n'} loop: for s.Scan() { b := s.Bytes() if len(b) == 0 { continue } if b[0] == '#' { buf.Write(b) buf.Write...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
etchosts/etchosts.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/etchosts/etchosts.go#L199-L208
go
train
// Update all IP addresses where hostname matches. // path is path to host file // IP is new IP address // hostname is hostname to search for to replace IP
func Update(path, IP, hostname string) error
// Update all IP addresses where hostname matches. // path is path to host file // IP is new IP address // hostname is hostname to search for to replace IP func Update(path, IP, hostname string) error
{ defer pathLock(path)() old, err := ioutil.ReadFile(path) if err != nil { return err } var re = regexp.MustCompile(fmt.Sprintf("(\\S*)(\\t%s)(\\s|\\.)", regexp.QuoteMeta(hostname))) return ioutil.WriteFile(path, re.ReplaceAll(old, []byte(IP+"$2"+"$3")), 0644) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/overlay/overlay.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/overlay.go#L59-L108
go
train
// Init registers a new instance of overlay driver
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error
// Init registers a new instance of overlay driver func Init(dc driverapi.DriverCallback, config map[string]interface{}) error
{ c := driverapi.Capability{ DataScope: datastore.GlobalScope, ConnectivityScope: datastore.GlobalScope, } d := &driver{ networks: networkTable{}, peerDb: peerNetworkMap{ mp: map[string]*peerMap{}, }, secMap: &encrMap{nodes: map[string][]*spi{}}, config: config, peerOpCh: make(chan *p...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/overlay/overlay.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/overlay.go#L111-L160
go
train
// Endpoints are stored in the local store. Restore them and reconstruct the overlay sandbox
func (d *driver) restoreEndpoints() error
// Endpoints are stored in the local store. Restore them and reconstruct the overlay sandbox func (d *driver) restoreEndpoints() error
{ if d.localStore == nil { logrus.Warn("Cannot restore overlay endpoints because local datastore is missing") return nil } kvol, err := d.localStore.List(datastore.Key(overlayEndpointPrefix), &endpoint{}) if err != nil && err != datastore.ErrKeyNotFound { return fmt.Errorf("failed to read overlay endpoint fr...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/overlay/overlay.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/overlay.go#L163-L178
go
train
// Fini cleans up the driver resources
func Fini(drv driverapi.Driver)
// Fini cleans up the driver resources func Fini(drv driverapi.Driver)
{ d := drv.(*driver) // Notify the peer go routine to return if d.peerOpCancel != nil { d.peerOpCancel() } if d.exitCh != nil { waitCh := make(chan struct{}) d.exitCh <- waitCh <-waitCh } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/overlay/overlay.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/overlay.go#L319-L386
go
train
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster
func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error
// DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error
{ var err error switch dType { case discoverapi.NodeDiscovery: nodeData, ok := data.(discoverapi.NodeDiscoveryData) if !ok || nodeData.Address == "" { return fmt.Errorf("invalid discovery data") } d.nodeJoin(nodeData.Address, nodeData.BindAddress, nodeData.Self) case discoverapi.DatastoreConfig: if d....
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/host/host.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/host/host.go#L20-L26
go
train
// Init registers a new instance of host driver
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error
// Init registers a new instance of host driver func Init(dc driverapi.DriverCallback, config map[string]interface{}) error
{ c := driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, } return dc.RegisterDriver(networkType, &driver{}, c) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/host/host.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/host/host.go#L73-L75
go
train
// Join method is invoked when a Sandbox is attached to an endpoint.
func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error
// Join method is invoked when a Sandbox is attached to an endpoint. func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error
{ return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/bridge/interface.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/interface.go#L31-L48
go
train
// newInterface creates a new bridge interface structure. It attempts to find // an already existing device identified by the configuration BridgeName field, // or the default bridge name when unspecified, but doesn't attempt to create // one when missing
func newInterface(nlh *netlink.Handle, config *networkConfiguration) (*bridgeInterface, error)
// newInterface creates a new bridge interface structure. It attempts to find // an already existing device identified by the configuration BridgeName field, // or the default bridge name when unspecified, but doesn't attempt to create // one when missing func newInterface(nlh *netlink.Handle, config *networkConfigurat...
{ var err error i := &bridgeInterface{nlh: nlh} // Initialize the bridge name to the default if unspecified. if config.BridgeName == "" { config.BridgeName = DefaultBridgeName } // Attempt to find an existing bridge named with the specified name. i.Link, err = nlh.LinkByName(config.BridgeName) if err != ni...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/bridge/interface.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/interface.go#L56-L71
go
train
// addresses returns all IPv4 addresses and all IPv6 addresses for the bridge interface.
func (i *bridgeInterface) addresses() ([]netlink.Addr, []netlink.Addr, error)
// addresses returns all IPv4 addresses and all IPv6 addresses for the bridge interface. func (i *bridgeInterface) addresses() ([]netlink.Addr, []netlink.Addr, error)
{ v4addr, err := i.nlh.AddrList(i.Link, netlink.FAMILY_V4) if err != nil { return nil, nil, fmt.Errorf("Failed to retrieve V4 addresses: %v", err) } v6addr, err := i.nlh.AddrList(i.Link, netlink.FAMILY_V6) if err != nil { return nil, nil, fmt.Errorf("Failed to retrieve V6 addresses: %v", err) } if len(v4a...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/server.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L25-L27
go
train
// ServeHTTP TODO
func (h httpHandlerCustom) ServeHTTP(w http.ResponseWriter, r *http.Request)
// ServeHTTP TODO func (h httpHandlerCustom) ServeHTTP(w http.ResponseWriter, r *http.Request)
{ h.F(h.ctx, w, r) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/server.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L55-L60
go
train
// Init initialize the mux for the http handling and register the base hooks
func (s *Server) Init()
// Init initialize the mux for the http handling and register the base hooks func (s *Server) Init()
{ s.mux = http.NewServeMux() // Register local handlers s.RegisterHandler(s, diagPaths2Func) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/server.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L63-L73
go
train
// RegisterHandler allows to register new handlers to the mux and to a specific path
func (s *Server) RegisterHandler(ctx interface{}, hdlrs map[string]HTTPHandlerFunc)
// RegisterHandler allows to register new handlers to the mux and to a specific path func (s *Server) RegisterHandler(ctx interface{}, hdlrs map[string]HTTPHandlerFunc)
{ s.Lock() defer s.Unlock() for path, fun := range hdlrs { if _, ok := s.registeredHanders[path]; ok { continue } s.mux.Handle(path, httpHandlerCustom{ctx, fun}) s.registeredHanders[path] = true } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/server.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L82-L104
go
train
// EnableDiagnostic opens a TCP socket to debug the passed network DB
func (s *Server) EnableDiagnostic(ip string, port int)
// EnableDiagnostic opens a TCP socket to debug the passed network DB func (s *Server) EnableDiagnostic(ip string, port int)
{ s.Lock() defer s.Unlock() s.port = port if s.enable == 1 { logrus.Info("The server is already up and running") return } logrus.Infof("Starting the diagnostic server listening on %d for commands", port) srv := &http.Server{Addr: fmt.Sprintf("%s:%d", ip, port), Handler: s} s.srv = srv s.enable = 1 go ...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/server.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L107-L115
go
train
// DisableDiagnostic stop the dubug and closes the tcp socket
func (s *Server) DisableDiagnostic()
// DisableDiagnostic stop the dubug and closes the tcp socket func (s *Server) DisableDiagnostic()
{ s.Lock() defer s.Unlock() s.srv.Shutdown(context.Background()) s.srv = nil s.enable = 0 logrus.Info("Disabling the diagnostic server") }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/server.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L118-L122
go
train
// IsDiagnosticEnabled returns true when the debug is enabled
func (s *Server) IsDiagnosticEnabled() bool
// IsDiagnosticEnabled returns true when the debug is enabled func (s *Server) IsDiagnosticEnabled() bool
{ s.Lock() defer s.Unlock() return s.enable == 1 }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/server.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L183-L187
go
train
// DebugHTTPForm helper to print the form url parameters
func DebugHTTPForm(r *http.Request)
// DebugHTTPForm helper to print the form url parameters func DebugHTTPForm(r *http.Request)
{ for k, v := range r.Form { logrus.Debugf("Form[%q] = %q\n", k, v) } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/server.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L196-L204
go
train
// ParseHTTPFormOptions easily parse the JSON printing options
func ParseHTTPFormOptions(r *http.Request) (bool, *JSONOutput)
// ParseHTTPFormOptions easily parse the JSON printing options func ParseHTTPFormOptions(r *http.Request) (bool, *JSONOutput)
{ _, unsafe := r.Form["unsafe"] v, json := r.Form["json"] var pretty bool if len(v) > 0 { pretty = v[0] == "pretty" } return unsafe, &JSONOutput{enable: json, prettyPrint: pretty} }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/server.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/server.go#L207-L227
go
train
// HTTPReply helper function that takes care of sending the message out
func HTTPReply(w http.ResponseWriter, r *HTTPResult, j *JSONOutput) (int, error)
// HTTPReply helper function that takes care of sending the message out func HTTPReply(w http.ResponseWriter, r *HTTPResult, j *JSONOutput) (int, error)
{ var response []byte if j.enable { w.Header().Set("Content-Type", "application/json") var err error if j.prettyPrint { response, err = json.MarshalIndent(r, "", " ") if err != nil { response, _ = json.MarshalIndent(FailCommand(err), "", " ") } } else { response, err = json.Marshal(r) if...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipams/remote/remote.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L34-L66
go
train
// Init registers a remote ipam when its plugin is activated
func Init(cb ipamapi.Callback, l, g interface{}) error
// Init registers a remote ipam when its plugin is activated func Init(cb ipamapi.Callback, l, g interface{}) error
{ newPluginHandler := func(name string, client *plugins.Client) { a := newAllocator(name, client) if cps, err := a.(*allocator).getCapabilities(); err == nil { if err := cb.RegisterIpamDriverWithCapabilities(name, a, cps); err != nil { logrus.Errorf("error registering remote ipam driver %s due to %v", nam...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipams/remote/remote.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L111-L117
go
train
// GetDefaultAddressSpaces returns the local and global default address spaces
func (a *allocator) GetDefaultAddressSpaces() (string, string, error)
// GetDefaultAddressSpaces returns the local and global default address spaces func (a *allocator) GetDefaultAddressSpaces() (string, string, error)
{ res := &api.GetAddressSpacesResponse{} if err := a.call("GetDefaultAddressSpaces", nil, res); err != nil { return "", "", err } return res.LocalDefaultAddressSpace, res.GlobalDefaultAddressSpace, nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipams/remote/remote.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L120-L128
go
train
// RequestPool requests an address pool in the specified address space
func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error)
// RequestPool requests an address pool in the specified address space func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error)
{ req := &api.RequestPoolRequest{AddressSpace: addressSpace, Pool: pool, SubPool: subPool, Options: options, V6: v6} res := &api.RequestPoolResponse{} if err := a.call("RequestPool", req, res); err != nil { return "", nil, nil, err } retPool, err := types.ParseCIDR(res.Pool) return res.PoolID, retPool, res.Dat...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipams/remote/remote.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L131-L135
go
train
// ReleasePool removes an address pool from the specified address space
func (a *allocator) ReleasePool(poolID string) error
// ReleasePool removes an address pool from the specified address space func (a *allocator) ReleasePool(poolID string) error
{ req := &api.ReleasePoolRequest{PoolID: poolID} res := &api.ReleasePoolResponse{} return a.call("ReleasePool", req, res) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipams/remote/remote.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L138-L158
go
train
// RequestAddress requests an address from the address pool
func (a *allocator) RequestAddress(poolID string, address net.IP, options map[string]string) (*net.IPNet, map[string]string, error)
// RequestAddress requests an address from the address pool func (a *allocator) RequestAddress(poolID string, address net.IP, options map[string]string) (*net.IPNet, map[string]string, error)
{ var ( prefAddress string retAddress *net.IPNet err error ) if address != nil { prefAddress = address.String() } req := &api.RequestAddressRequest{PoolID: poolID, Address: prefAddress, Options: options} res := &api.RequestAddressResponse{} if err := a.call("RequestAddress", req, res); err != n...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
ipams/remote/remote.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipams/remote/remote.go#L161-L169
go
train
// ReleaseAddress releases the address from the specified address pool
func (a *allocator) ReleaseAddress(poolID string, address net.IP) error
// ReleaseAddress releases the address from the specified address pool func (a *allocator) ReleaseAddress(poolID string, address net.IP) error
{ var relAddress string if address != nil { relAddress = address.String() } req := &api.ReleaseAddressRequest{PoolID: poolID, Address: relAddress} res := &api.ReleaseAddressResponse{} return a.call("ReleaseAddress", req, res) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/types.go#L19-L24
go
train
// FailCommand creates a failure message with error
func FailCommand(err error) *HTTPResult
// FailCommand creates a failure message with error func FailCommand(err error) *HTTPResult
{ return &HTTPResult{ Message: "FAIL", Details: &ErrorCmd{Error: err.Error()}, } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
diagnostic/types.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/diagnostic/types.go#L27-L32
go
train
// WrongCommand creates a wrong command response
func WrongCommand(message, usage string) *HTTPResult
// WrongCommand creates a wrong command response func WrongCommand(message, usage string) *HTTPResult
{ return &HTTPResult{ Message: message, Details: &UsageCmd{Usage: usage}, } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
cmd/proxy/main.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/cmd/proxy/main.go#L35-L61
go
train
// parseHostContainerAddrs parses the flags passed on reexec to create the TCP/UDP/SCTP // net.Addrs to map the host and container ports
func parseHostContainerAddrs() (host net.Addr, container net.Addr)
// parseHostContainerAddrs parses the flags passed on reexec to create the TCP/UDP/SCTP // net.Addrs to map the host and container ports func parseHostContainerAddrs() (host net.Addr, container net.Addr)
{ var ( proto = flag.String("proto", "tcp", "proxy protocol") hostIP = flag.String("host-ip", "", "host ip") hostPort = flag.Int("host-port", -1, "host port") containerIP = flag.String("container-ip", "", "container ip") containerPort = flag.Int("container-port", -1, "container port") ...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/bridge/bridge.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L159-L170
go
train
// Init registers a new instance of bridge driver
func Init(dc driverapi.DriverCallback, config map[string]interface{}) error
// Init registers a new instance of bridge driver func Init(dc driverapi.DriverCallback, config map[string]interface{}) error
{ d := newDriver() if err := d.configure(config); err != nil { return err } c := driverapi.Capability{ DataScope: datastore.LocalScope, ConnectivityScope: datastore.LocalScope, } return dc.RegisterDriver(networkType, d, c) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/bridge/bridge.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L174-L196
go
train
// Validate performs a static validation on the network configuration parameters. // Whatever can be assessed a priori before attempting any programming.
func (c *networkConfiguration) Validate() error
// Validate performs a static validation on the network configuration parameters. // Whatever can be assessed a priori before attempting any programming. func (c *networkConfiguration) Validate() error
{ if c.Mtu < 0 { return ErrInvalidMtu(c.Mtu) } // If bridge v4 subnet is specified if c.AddressIPv4 != nil { // If default gw is specified, it must be part of bridge subnet if c.DefaultGatewayIPv4 != nil { if !c.AddressIPv4.Contains(c.DefaultGatewayIPv4) { return &ErrInvalidGateway{} } } } //...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/bridge/bridge.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L199-L222
go
train
// Conflicts check if two NetworkConfiguration objects overlap
func (c *networkConfiguration) Conflicts(o *networkConfiguration) error
// Conflicts check if two NetworkConfiguration objects overlap func (c *networkConfiguration) Conflicts(o *networkConfiguration) error
{ if o == nil { return errors.New("same configuration") } // Also empty, because only one network with empty name is allowed if c.BridgeName == o.BridgeName { return errors.New("networks have same bridge name") } // They must be in different subnets if (c.AddressIPv4 != nil && o.AddressIPv4 != nil) && (...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/bridge/bridge.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L306-L317
go
train
// Install/Removes the iptables rules needed to isolate this network // from each of the other networks
func (n *bridgeNetwork) isolateNetwork(others []*bridgeNetwork, enable bool) error
// Install/Removes the iptables rules needed to isolate this network // from each of the other networks func (n *bridgeNetwork) isolateNetwork(others []*bridgeNetwork, enable bool) error
{ n.Lock() thisConfig := n.config n.Unlock() if thisConfig.Internal { return nil } // Install the rules to isolate this network against each of the other networks return setINC(thisConfig.BridgeName, enable) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/bridge/bridge.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L509-L518
go
train
// Returns the non link-local IPv6 subnet for the containers attached to this bridge if found, nil otherwise
func getV6Network(config *networkConfiguration, i *bridgeInterface) *net.IPNet
// Returns the non link-local IPv6 subnet for the containers attached to this bridge if found, nil otherwise func getV6Network(config *networkConfiguration, i *bridgeInterface) *net.IPNet
{ if config.AddressIPv6 != nil { return config.AddressIPv6 } if i.bridgeIPv6 != nil && i.bridgeIPv6.IP != nil && !i.bridgeIPv6.IP.IsLinkLocalUnicast() { return i.bridgeIPv6 } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/bridge/bridge.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L548-L592
go
train
// Create a new network using bridge plugin
func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error
// Create a new network using bridge plugin func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error
{ if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" { return types.BadRequestErrorf("ipv4 pool is empty") } // Sanity checks d.Lock() if _, ok := d.networks[id]; ok { d.Unlock() return types.ForbiddenErrorf("network %s exists", id) } d.Unlock() // Parse and validate the config. It should...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/bridge/bridge.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L1180-L1223
go
train
// Join method is invoked when a Sandbox is attached to an endpoint.
func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error
// Join method is invoked when a Sandbox is attached to an endpoint. func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error
{ defer osl.InitOSContext()() network, err := d.getNetwork(nid) if err != nil { return err } endpoint, err := network.getEndpoint(eid) if err != nil { return err } if endpoint == nil { return EndpointNotFoundError(eid) } endpoint.containerConfig, err = parseContainerOptions(options) if err != nil ...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/bridge/bridge.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/bridge/bridge.go#L1226-L1250
go
train
// Leave method is invoked when a Sandbox detaches from an endpoint.
func (d *driver) Leave(nid, eid string) error
// Leave method is invoked when a Sandbox detaches from an endpoint. func (d *driver) Leave(nid, eid string) error
{ defer osl.InitOSContext()() network, err := d.getNetwork(nid) if err != nil { return types.InternalMaskableErrorf("%s", err) } endpoint, err := network.getEndpoint(eid) if err != nil { return err } if endpoint == nil { return EndpointNotFoundError(eid) } if !network.config.EnableICC { if err = ...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
service.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/service.go#L67-L69
go
train
// assignIPToEndpoint inserts the mapping between the IP and the endpoint identifier // returns true if the mapping was not present, false otherwise // returns also the number of endpoints associated to the IP
func (s *service) assignIPToEndpoint(ip, eID string) (bool, int)
// assignIPToEndpoint inserts the mapping between the IP and the endpoint identifier // returns true if the mapping was not present, false otherwise // returns also the number of endpoints associated to the IP func (s *service) assignIPToEndpoint(ip, eID string) (bool, int)
{ return s.ipToEndpoint.Insert(ip, eID) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
service.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/service.go#L74-L76
go
train
// removeIPToEndpoint removes the mapping between the IP and the endpoint identifier // returns true if the mapping was deleted, false otherwise // returns also the number of endpoints associated to the IP
func (s *service) removeIPToEndpoint(ip, eID string) (bool, int)
// removeIPToEndpoint removes the mapping between the IP and the endpoint identifier // returns true if the mapping was deleted, false otherwise // returns also the number of endpoints associated to the IP func (s *service) removeIPToEndpoint(ip, eID string) (bool, int)
{ return s.ipToEndpoint.Remove(ip, eID) }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
options/options.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/options/options.go#L58-L88
go
train
// GenerateFromModel takes the generic options, and tries to build a new // instance of the model's type by matching keys from the generic options to // fields in the model. // // The return value is of the same type than the model (including a potential // pointer qualifier).
func GenerateFromModel(options Generic, model interface{}) (interface{}, error)
// GenerateFromModel takes the generic options, and tries to build a new // instance of the model's type by matching keys from the generic options to // fields in the model. // // The return value is of the same type than the model (including a potential // pointer qualifier). func GenerateFromModel(options Generic, mo...
{ modType := reflect.TypeOf(model) // If the model is of pointer type, we need to dereference for New. resType := reflect.TypeOf(model) if modType.Kind() == reflect.Ptr { resType = resType.Elem() } // Populate the result structure with the generic layout content. res := reflect.New(resType) for name, value...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L189-L256
go
train
// New creates a new instance of network controller.
func New(cfgOptions ...config.Option) (NetworkController, error)
// New creates a new instance of network controller. func New(cfgOptions ...config.Option) (NetworkController, error)
{ c := &controller{ id: stringid.GenerateRandomID(), cfg: config.ParseConfigOptions(cfgOptions...), sandboxes: sandboxTable{}, svcRecords: make(map[string]svcInfo), serviceBindings: make(map[serviceKey]*service), agentInitDone: make(chan struct{}), networkLock...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L285-L309
go
train
// libnetwork side of agent depends on the keys. On the first receipt of // keys setup the agent. For subsequent key set handle the key change
func (c *controller) SetKeys(keys []*types.EncryptionKey) error
// libnetwork side of agent depends on the keys. On the first receipt of // keys setup the agent. For subsequent key set handle the key change func (c *controller) SetKeys(keys []*types.EncryptionKey) error
{ subsysKeys := make(map[string]int) for _, key := range keys { if key.Subsystem != subsysGossip && key.Subsystem != subsysIPSec { return fmt.Errorf("key received for unrecognized subsystem") } subsysKeys[key.Subsystem]++ } for s, count := range subsysKeys { if count != keyringSize { return fmt.Er...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L367-L375
go
train
// AgentInitWait waits for agent initialization to be completed in the controller.
func (c *controller) AgentInitWait()
// AgentInitWait waits for agent initialization to be completed in the controller. func (c *controller) AgentInitWait()
{ c.Lock() agentInitDone := c.agentInitDone c.Unlock() if agentInitDone != nil { <-agentInitDone } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L378-L385
go
train
// AgentStopWait waits for the Agent stop to be completed in the controller
func (c *controller) AgentStopWait()
// AgentStopWait waits for the Agent stop to be completed in the controller func (c *controller) AgentStopWait()
{ c.Lock() agentStopDone := c.agentStopDone c.Unlock() if agentStopDone != nil { <-agentStopDone } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L388-L397
go
train
// agentOperationStart marks the start of an Agent Init or Agent Stop
func (c *controller) agentOperationStart()
// agentOperationStart marks the start of an Agent Init or Agent Stop func (c *controller) agentOperationStart()
{ c.Lock() if c.agentInitDone == nil { c.agentInitDone = make(chan struct{}) } if c.agentStopDone == nil { c.agentStopDone = make(chan struct{}) } c.Unlock() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L400-L407
go
train
// agentInitComplete notifies the successful completion of the Agent initialization
func (c *controller) agentInitComplete()
// agentInitComplete notifies the successful completion of the Agent initialization func (c *controller) agentInitComplete()
{ c.Lock() if c.agentInitDone != nil { close(c.agentInitDone) c.agentInitDone = nil } c.Unlock() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L410-L417
go
train
// agentStopComplete notifies the successful completion of the Agent stop
func (c *controller) agentStopComplete()
// agentStopComplete notifies the successful completion of the Agent stop func (c *controller) agentStopComplete()
{ c.Lock() if c.agentStopDone != nil { close(c.agentStopDone) c.agentStopDone = nil } c.Unlock() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L708-L908
go
train
// NewNetwork creates a new network of the specified network type. The options // are network specific and modeled in a generic way.
func (c *controller) NewNetwork(networkType, name string, id string, options ...NetworkOption) (Network, error)
// NewNetwork creates a new network of the specified network type. The options // are network specific and modeled in a generic way. func (c *controller) NewNetwork(networkType, name string, id string, options ...NetworkOption) (Network, error)
{ if id != "" { c.networkLocker.Lock(id) defer c.networkLocker.Unlock(id) if _, err := c.NetworkByID(id); err == nil { return nil, NetworkNameError(id) } } if !config.IsValidName(name) { return nil, ErrInvalidName(name) } if id == "" { id = stringid.GenerateRandomID() } defaultIpam := default...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1070-L1190
go
train
// NewSandbox creates a new sandbox for the passed container id
func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error)
// NewSandbox creates a new sandbox for the passed container id func (c *controller) NewSandbox(containerID string, options ...SandboxOption) (Sandbox, error)
{ if containerID == "" { return nil, types.BadRequestErrorf("invalid container ID") } var sb *sandbox c.Lock() for _, s := range c.sandboxes { if s.containerID == containerID { // If not a stub, then we already have a complete sandbox. if !s.isStub { sbID := s.ID() c.Unlock() return nil, ty...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1231-L1248
go
train
// SandboxDestroy destroys a sandbox given a container ID
func (c *controller) SandboxDestroy(id string) error
// SandboxDestroy destroys a sandbox given a container ID func (c *controller) SandboxDestroy(id string) error
{ var sb *sandbox c.Lock() for _, s := range c.sandboxes { if s.containerID == id { sb = s break } } c.Unlock() // It is not an error if sandbox is not available if sb == nil { return nil } return sb.Delete() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1251-L1259
go
train
// SandboxContainerWalker returns a Sandbox Walker function which looks for an existing Sandbox with the passed containerID
func SandboxContainerWalker(out *Sandbox, containerID string) SandboxWalker
// SandboxContainerWalker returns a Sandbox Walker function which looks for an existing Sandbox with the passed containerID func SandboxContainerWalker(out *Sandbox, containerID string) SandboxWalker
{ return func(sb Sandbox) bool { if sb.ContainerID() == containerID { *out = sb return true } return false } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1262-L1270
go
train
// SandboxKeyWalker returns a Sandbox Walker function which looks for an existing Sandbox with the passed key
func SandboxKeyWalker(out *Sandbox, key string) SandboxWalker
// SandboxKeyWalker returns a Sandbox Walker function which looks for an existing Sandbox with the passed key func SandboxKeyWalker(out *Sandbox, key string) SandboxWalker
{ return func(sb Sandbox) bool { if sb.Key() == key { *out = sb return true } return false } }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1335-L1341
go
train
// StartDiagnostic start the network dias mode
func (c *controller) StartDiagnostic(port int)
// StartDiagnostic start the network dias mode func (c *controller) StartDiagnostic(port int)
{ c.Lock() if !c.DiagnosticServer.IsDiagnosticEnabled() { c.DiagnosticServer.EnableDiagnostic("127.0.0.1", port) } c.Unlock() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1344-L1350
go
train
// StopDiagnostic start the network dias mode
func (c *controller) StopDiagnostic()
// StopDiagnostic start the network dias mode func (c *controller) StopDiagnostic()
{ c.Lock() if c.DiagnosticServer.IsDiagnosticEnabled() { c.DiagnosticServer.DisableDiagnostic() } c.Unlock() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
controller.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/controller.go#L1353-L1357
go
train
// IsDiagnosticEnabled returns true if the dias is enabled
func (c *controller) IsDiagnosticEnabled() bool
// IsDiagnosticEnabled returns true if the dias is enabled func (c *controller) IsDiagnosticEnabled() bool
{ c.Lock() defer c.Unlock() return c.DiagnosticServer.IsDiagnosticEnabled() }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/overlay/ov_network.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/ov_network.go#L374-L412
go
train
// to be called while holding network lock
func (n *network) destroySandbox()
// to be called while holding network lock func (n *network) destroySandbox()
{ if n.sbox != nil { for _, iface := range n.sbox.Info().Interfaces() { if err := iface.Remove(); err != nil { logrus.Debugf("Remove interface %s failed: %v", iface.SrcName(), err) } } for _, s := range n.subnets { if hostMode { if err := removeFilters(n.id[:12], s.brName); err != nil { l...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/overlay/ov_network.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/ov_network.go#L662-L680
go
train
// Must be called with the network lock
func (n *network) initSubnetSandbox(s *subnet, restore bool) error
// Must be called with the network lock func (n *network) initSubnetSandbox(s *subnet, restore bool) error
{ brName := n.generateBridgeName(s) vxlanName := n.generateVxlanName(s) if restore { if err := n.restoreSubnetSandbox(s, brName, vxlanName); err != nil { return err } } else { if err := n.setupSubnetSandbox(s, brName, vxlanName); err != nil { return err } } s.vxlanName = vxlanName s.brName = brN...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/overlay/ov_network.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/overlay/ov_network.go#L863-L871
go
train
// Restore a network from the store to the driver if it is present. // Must be called with the driver locked!
func (d *driver) restoreNetworkFromStore(nid string) *network
// Restore a network from the store to the driver if it is present. // Must be called with the driver locked! func (d *driver) restoreNetworkFromStore(nid string) *network
{ n := d.getNetworkFromStore(nid) if n != nil { n.driver = d n.endpoints = endpointTable{} d.networks[nid] = n } return n }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_network.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L18-L76
go
train
// CreateNetwork the network for the specified driver type
func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error
// CreateNetwork the network for the specified driver type func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error
{ defer osl.InitOSContext()() kv, err := kernel.GetKernelVersion() if err != nil { return fmt.Errorf("Failed to check kernel version for %s driver support: %v", ipvlanType, err) } // ensure Kernel version is >= v4.2 for ipvlan support if kv.Kernel < ipvlanKernelVer || (kv.Kernel == ipvlanKernelVer && kv.Major ...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_network.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L79-L121
go
train
// createNetwork is used by new network callbacks and persistent network cache
func (d *driver) createNetwork(config *configuration) error
// createNetwork is used by new network callbacks and persistent network cache func (d *driver) createNetwork(config *configuration) error
{ networkList := d.getNetworks() for _, nw := range networkList { if config.Parent == nw.config.Parent { return fmt.Errorf("network %s is already using parent interface %s", getDummyName(stringid.TruncateID(nw.config.ID)), config.Parent) } } if !parentExists(config.Parent) { // if the --internal flag ...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_network.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L124-L170
go
train
// DeleteNetwork the network for the specified driver type
func (d *driver) DeleteNetwork(nid string) error
// DeleteNetwork the network for the specified driver type func (d *driver) DeleteNetwork(nid string) error
{ defer osl.InitOSContext()() n := d.network(nid) if n == nil { return fmt.Errorf("network id %s not found", nid) } // if the driver created the slave interface, delete it, otherwise leave it if ok := n.config.CreatedSlaveLink; ok { // if the interface exists, only delete if it matches iface.vlan or dummy.ne...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_network.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L173-L191
go
train
// parseNetworkOptions parse docker network options
func parseNetworkOptions(id string, option options.Generic) (*configuration, error)
// parseNetworkOptions parse docker network options func parseNetworkOptions(id string, option options.Generic) (*configuration, error)
{ var ( err error config = &configuration{} ) // parse generic labels first if genData, ok := option[netlabel.GenericData]; ok && genData != nil { if config, err = parseNetworkGenericOptions(genData); err != nil { return nil, err } } // setting the parent to "" will trigger an isolated network dumm...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_network.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L194-L214
go
train
// parseNetworkGenericOptions parse generic driver docker network options
func parseNetworkGenericOptions(data interface{}) (*configuration, error)
// parseNetworkGenericOptions parse generic driver docker network options func parseNetworkGenericOptions(data interface{}) (*configuration, error)
{ var ( err error config *configuration ) switch opt := data.(type) { case *configuration: config = opt case map[string]string: config = &configuration{} err = config.fromOptions(opt) case options.Generic: var opaqueConfig interface{} if opaqueConfig, err = options.GenerateFromModel(opt, config)...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_network.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L217-L229
go
train
// fromOptions binds the generic options to networkConfiguration to cache
func (config *configuration) fromOptions(labels map[string]string) error
// fromOptions binds the generic options to networkConfiguration to cache func (config *configuration) fromOptions(labels map[string]string) error
{ for label, value := range labels { switch label { case parentOpt: // parse driver option '-o parent' config.Parent = value case driverModeOpt: // parse driver option '-o ipvlan_mode' config.IpvlanMode = value } } return nil }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
drivers/ipvlan/ipvlan_network.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_network.go#L232-L252
go
train
// processIPAM parses v4 and v6 IP information and binds it to the network configuration
func (config *configuration) processIPAM(id string, ipamV4Data, ipamV6Data []driverapi.IPAMData) error
// processIPAM parses v4 and v6 IP information and binds it to the network configuration func (config *configuration) processIPAM(id string, ipamV4Data, ipamV6Data []driverapi.IPAMData) error
{ if len(ipamV4Data) > 0 { for _, ipd := range ipamV4Data { s := &ipv4Subnet{ SubnetIP: ipd.Pool.String(), GwIP: ipd.Gateway.String(), } config.Ipv4Subnets = append(config.Ipv4Subnets, s) } } if len(ipamV6Data) > 0 { for _, ipd := range ipamV6Data { s := &ipv6Subnet{ SubnetIP: ipd....
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
hostdiscovery/hostdiscovery.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/hostdiscovery/hostdiscovery.go#L33-L35
go
train
// NewHostDiscovery function creates a host discovery object
func NewHostDiscovery(watcher discovery.Watcher) HostDiscovery
// NewHostDiscovery function creates a host discovery object func NewHostDiscovery(watcher discovery.Watcher) HostDiscovery
{ return &hostDiscovery{watcher: watcher, nodes: mapset.NewSet(), stopChan: make(chan struct{})} }
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
driverapi/ipamdata.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/driverapi/ipamdata.go#L12-L29
go
train
// MarshalJSON encodes IPAMData into json message
func (i *IPAMData) MarshalJSON() ([]byte, error)
// MarshalJSON encodes IPAMData into json message func (i *IPAMData) MarshalJSON() ([]byte, error)
{ m := map[string]interface{}{} m["AddressSpace"] = i.AddressSpace if i.Pool != nil { m["Pool"] = i.Pool.String() } if i.Gateway != nil { m["Gateway"] = i.Gateway.String() } if i.AuxAddresses != nil { am := make(map[string]string, len(i.AuxAddresses)) for k, v := range i.AuxAddresses { am[k] = v.Stri...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
driverapi/ipamdata.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/driverapi/ipamdata.go#L32-L65
go
train
// UnmarshalJSON decodes a json message into IPAMData
func (i *IPAMData) UnmarshalJSON(data []byte) error
// UnmarshalJSON decodes a json message into IPAMData func (i *IPAMData) UnmarshalJSON(data []byte) error
{ var ( m map[string]interface{} err error ) if err := json.Unmarshal(data, &m); err != nil { return err } i.AddressSpace = m["AddressSpace"].(string) if v, ok := m["Pool"]; ok { if i.Pool, err = types.ParseCIDR(v.(string)); err != nil { return err } } if v, ok := m["Gateway"]; ok { if i.Gatew...
docker/libnetwork
9ff9b57c344df5cd47443ad9e65702ec85c5aeb0
driverapi/ipamdata.go
https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/driverapi/ipamdata.go#L68-L94
go
train
// Validate checks whether the IPAMData structure contains congruent data
func (i *IPAMData) Validate() error
// Validate checks whether the IPAMData structure contains congruent data func (i *IPAMData) Validate() error
{ var isV6 bool if i.Pool == nil { return types.BadRequestErrorf("invalid pool") } if i.Gateway == nil { return types.BadRequestErrorf("invalid gateway address") } isV6 = i.IsV6() if isV6 && i.Gateway.IP.To4() != nil || !isV6 && i.Gateway.IP.To4() == nil { return types.BadRequestErrorf("incongruent ip ver...