// SetupDevice create a new bridge interface/ func setupDevice(config *networkConfiguration, i *bridgeInterface) error { // We only attempt to create the bridge when the requested device name is // the default one. if config.BridgeName != DefaultBridgeName && !config.AllowNonDefaultBridge { return NonDefaultBridgeExistError(config.BridgeName) } // Set the bridgeInterface netlink.Bridge. i.Link = &netlink.Bridge{ LinkAttrs: netlink.LinkAttrs{ Name: config.BridgeName, }, } // Only set the bridge's MAC address if the kernel version is > 3.3, as it // was not supported before that. kv, err := kernel.GetKernelVersion() if err == nil && (kv.Kernel >= 3 && kv.Major >= 3) { i.Link.Attrs().HardwareAddr = netutils.GenerateRandomMAC() log.Debugf("Setting bridge mac address to %s", i.Link.Attrs().HardwareAddr) } // Call out to netlink to create the device. if err = netlink.LinkAdd(i.Link); err != nil { return types.InternalErrorf("Failed to program bridge link: %s", err.Error()) } return nil }
// SetupDevice create a new bridge interface/ func setupDevice(config *networkConfiguration, i *bridgeInterface) error { var setMac bool // We only attempt to create the bridge when the requested device name is // the default one. if config.BridgeName != DefaultBridgeName && !config.AllowNonDefaultBridge { return NonDefaultBridgeExistError(config.BridgeName) } // Set the bridgeInterface netlink.Bridge. i.Link = &netlink.Bridge{ LinkAttrs: netlink.LinkAttrs{ Name: config.BridgeName, }, } // Only set the bridge's MAC address if the kernel version is > 3.3, as it // was not supported before that. kv, err := kernel.GetKernelVersion() if err == nil && (kv.Kernel >= 3 && kv.Major >= 3) { setMac = true } return bri.CreateBridge(config.BridgeName, setMac) }
func (daemon *Daemon) CmdInfo(job *engine.Job) engine.Status { images, _ := daemon.Graph().Map() var imgcount int if images == nil { imgcount = 0 } else { imgcount = len(images) } kernelVersion := "<unknown>" if kv, err := kernel.GetKernelVersion(); err == nil { kernelVersion = kv.String() } operatingSystem := "<unknown>" if s, err := operatingsystem.GetOperatingSystem(); err == nil { operatingSystem = s } if inContainer, err := operatingsystem.IsContainerized(); err != nil { utils.Errorf("Could not determine if daemon is containerized: %v", err) operatingSystem += " (error determining if containerized)" } else if inContainer { operatingSystem += " (containerized)" } // if we still have the original dockerinit binary from before we copied it locally, let's return the path to that, since that's more intuitive (the copied path is trivial to derive by hand given VERSION) initPath := utils.DockerInitPath("") if initPath == "" { // if that fails, we'll just return the path from the daemon initPath = daemon.SystemInitPath() } cjob := job.Eng.Job("subscribers_count") env, _ := cjob.Stdout.AddEnv() if err := cjob.Run(); err != nil { return job.Error(err) } v := &engine.Env{} v.SetInt("Containers", len(daemon.List())) v.SetInt("Images", imgcount) v.Set("Driver", daemon.GraphDriver().String()) v.SetJson("DriverStatus", daemon.GraphDriver().Status()) v.SetBool("MemoryLimit", daemon.SystemConfig().MemoryLimit) v.SetBool("SwapLimit", daemon.SystemConfig().SwapLimit) v.SetBool("IPv4Forwarding", !daemon.SystemConfig().IPv4ForwardingDisabled) v.SetBool("Debug", os.Getenv("DEBUG") != "") v.SetInt("NFd", utils.GetTotalUsedFds()) v.SetInt("NGoroutines", runtime.NumGoroutine()) v.Set("ExecutionDriver", daemon.ExecutionDriver().Name()) v.SetInt("NEventsListener", env.GetInt("count")) v.Set("KernelVersion", kernelVersion) v.Set("OperatingSystem", operatingSystem) v.Set("IndexServerAddress", registry.IndexServerAddress()) v.Set("InitSha1", dockerversion.INITSHA1) v.Set("InitPath", initPath) v.SetList("Sockets", daemon.Sockets) if _, err := v.WriteTo(job.Stdout); err != nil { return job.Error(err) } return engine.StatusOK }
// CreateNetwork the network for the specified driver type func (d *driver) CreateNetwork(nid string, option map[string]interface{}, 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", macvlanType, err) } // ensure Kernel version is >= v3.9 for macvlan support if kv.Kernel < macvlanKernelVer || (kv.Kernel == macvlanKernelVer && kv.Major < macvlanMajorVer) { return fmt.Errorf("kernel version failed to meet the minimum macvlan kernel requirement of %d.%d, found %d.%d.%d", macvlanKernelVer, macvlanMajorVer, kv.Kernel, kv.Major, kv.Minor) } // parse and validate the config and bind to networkConfiguration config, err := parseNetworkOptions(nid, option) if err != nil { return err } config.ID = nid err = config.processIPAM(nid, ipV4Data, ipV6Data) if err != nil { return err } // verify the macvlan mode from -o macvlan_mode option switch config.MacvlanMode { case "", modeBridge: // default to macvlan bridge mode if -o macvlan_mode is empty config.MacvlanMode = modeBridge case modeOpt: config.MacvlanMode = modeOpt case modePassthru: config.MacvlanMode = modePassthru case modeVepa: config.MacvlanMode = modeVepa default: return fmt.Errorf("requested macvlan mode '%s' is not valid, 'bridge' mode is the macvlan driver default", config.MacvlanMode) } // loopback is not a valid parent link if config.Parent == "lo" { return fmt.Errorf("loopback interface is not a valid %s parent link", macvlanType) } // if parent interface not specified, create a dummy type link to use named dummy+net_id if config.Parent == "" { config.Parent = getDummyName(stringid.TruncateID(config.ID)) // empty parent and --internal are handled the same. Set here to update k/v config.Internal = true } err = d.createNetwork(config) if err != nil { return err } // update persistent db, rollback on fail err = d.storeUpdate(config) if err != nil { d.deleteNetwork(config.ID) logrus.Debugf("encoutered an error rolling back a network create for %s : %v", config.ID, err) return err } return nil }
// Init returns the a native diff driver for overlay filesystem. // If overlay filesystem is not supported on the host, graphdriver.ErrNotSupported is returned as error. // If a overlay filesystem is not supported over a existing filesystem then error graphdriver.ErrIncompatibleFS is returned. func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) { opts, err := parseOptions(options) if err != nil { return nil, err } if err := supportsOverlay(); err != nil { return nil, graphdriver.ErrNotSupported } // require kernel 4.0.0 to ensure multiple lower dirs are supported v, err := kernel.GetKernelVersion() if err != nil { return nil, err } if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: 4, Major: 0, Minor: 0}) < 0 { if !opts.overrideKernelCheck { return nil, graphdriver.ErrNotSupported } logrus.Warnf("Using pre-4.0.0 kernel for overlay2, mount failures may require kernel update") } fsMagic, err := graphdriver.GetFSMagic(home) if err != nil { return nil, err } if fsName, ok := graphdriver.FsNames[fsMagic]; ok { backingFs = fsName } // check if they are running over btrfs, aufs, zfs, overlay, or ecryptfs switch fsMagic { case graphdriver.FsMagicBtrfs, graphdriver.FsMagicAufs, graphdriver.FsMagicZfs, graphdriver.FsMagicOverlay, graphdriver.FsMagicEcryptfs: logrus.Errorf("'overlay2' is not supported over %s", backingFs) return nil, graphdriver.ErrIncompatibleFS } rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps) if err != nil { return nil, err } // Create the driver home dir if err := idtools.MkdirAllAs(path.Join(home, linkDir), 0700, rootUID, rootGID); err != nil && !os.IsExist(err) { return nil, err } if err := mount.MakePrivate(home); err != nil { return nil, err } d := &Driver{ home: home, uidMaps: uidMaps, gidMaps: gidMaps, ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicOverlay)), } return d, nil }
// 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 < ipvlanMajorVer) { return fmt.Errorf("kernel version failed to meet the minimum ipvlan kernel requirement of %d.%d, found %d.%d.%d", ipvlanKernelVer, ipvlanMajorVer, kv.Kernel, kv.Major, kv.Minor) } // reject a null v4 network if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" { return fmt.Errorf("ipv4 pool is empty") } // parse and validate the config and bind to networkConfiguration config, err := parseNetworkOptions(nid, option) if err != nil { return err } config.ID = nid err = config.processIPAM(nid, ipV4Data, ipV6Data) if err != nil { return err } // verify the ipvlan mode from -o ipvlan_mode option switch config.IpvlanMode { case "", modeL2: // default to ipvlan L2 mode if -o ipvlan_mode is empty config.IpvlanMode = modeL2 case modeL3: config.IpvlanMode = modeL3 default: return fmt.Errorf("requested ipvlan mode '%s' is not valid, 'l2' mode is the ipvlan driver default", config.IpvlanMode) } // loopback is not a valid parent link if config.Parent == "lo" { return fmt.Errorf("loopback interface is not a valid %s parent link", ipvlanType) } // if parent interface not specified, create a dummy type link to use named dummy+net_id if config.Parent == "" { config.Parent = getDummyName(stringid.TruncateID(config.ID)) // empty parent and --internal are handled the same. Set here to update k/v config.Internal = true } err = d.createNetwork(config) if err != nil { return err } // update persistent db, rollback on fail err = d.storeUpdate(config) if err != nil { d.deleteNetwork(config.ID) logrus.Debugf("encoutered an error rolling back a network create for %s : %v", config.ID, err) return err } return nil }
func createBridgeIface(name string) error { kv, err := kernel.GetKernelVersion() // only set the bridge's mac address if the kernel version is > 3.3 // before that it was not supported setBridgeMacAddr := err == nil && (kv.Kernel >= 3 && kv.Major >= 3) log.Debugf("setting bridge mac address = %v", setBridgeMacAddr) return netlink.CreateBridge(name, setBridgeMacAddr) }
func checkKernelVersion(k, major, minor int) bool { if v, err := kernel.GetKernelVersion(); err != nil { logrus.Warnf("%s", err) } else { if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: k, Major: major, Minor: minor}) < 0 { return false } } return true }
func checkKernelMajorVersionGreaterOrEqualThen(kernelVersion int, majorVersion int) bool { kv, err := kernel.GetKernelVersion() if err != nil { return false } if kv.Kernel < kernelVersion || (kv.Kernel == kernelVersion && kv.Major < majorVersion) { return false } return true }
func ipvlanKernelSupport() bool { const ipvlanKernelVer = 4 // minimum ipvlan kernel support const ipvlanMajorVer = 2 // minimum ipvlan major kernel support kv, err := kernel.GetKernelVersion() if err != nil { return false } // ensure Kernel version is >= v4.2 for ipvlan support if kv.Kernel < ipvlanKernelVer || (kv.Kernel == ipvlanKernelVer && kv.Major < ipvlanMajorVer) { return false } return true }
func macvlanKernelSupport() bool { const macvlanKernelVer = 3 // minimum macvlan kernel support const macvlanMajorVer = 9 // minimum macvlan major kernel support kv, err := kernel.GetKernelVersion() if err != nil { return false } // ensure Kernel version is >= v3.9 for macvlan support if kv.Kernel < macvlanKernelVer || (kv.Kernel == macvlanKernelVer && kv.Major < macvlanMajorVer) { return false } return true }
// DockerUserAgent is the User-Agent the Docker client uses to identify itself. // It is populated from version information of different components. func DockerUserAgent() string { httpVersion := make([]useragent.VersionInfo, 0, 6) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "docker", Version: Version}) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "go", Version: runtime.Version()}) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "git-commit", Version: GitCommit}) if kernelVersion, err := kernel.GetKernelVersion(); err == nil { httpVersion = append(httpVersion, useragent.VersionInfo{Name: "kernel", Version: kernelVersion.String()}) } httpVersion = append(httpVersion, useragent.VersionInfo{Name: "os", Version: runtime.GOOS}) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "arch", Version: runtime.GOARCH}) return useragent.AppendVersions("", httpVersion...) }
func init() { httpVersion := make([]useragent.VersionInfo, 0, 6) httpVersion = append(httpVersion, useragent.VersionInfo{"docker", dockerversion.VERSION}) httpVersion = append(httpVersion, useragent.VersionInfo{"go", runtime.Version()}) httpVersion = append(httpVersion, useragent.VersionInfo{"git-commit", dockerversion.GITCOMMIT}) if kernelVersion, err := kernel.GetKernelVersion(); err == nil { httpVersion = append(httpVersion, useragent.VersionInfo{"kernel", kernelVersion.String()}) } httpVersion = append(httpVersion, useragent.VersionInfo{"os", runtime.GOOS}) httpVersion = append(httpVersion, useragent.VersionInfo{"arch", runtime.GOARCH}) dockerUserAgent = useragent.AppendVersions("", httpVersion...) }
// GET /info func getInfo(c *context, w http.ResponseWriter, r *http.Request) { info := apitypes.Info{ Images: len(c.cluster.Images().Filter(cluster.ImageFilterOptions{})), DriverStatus: c.statusHandler.Status(), NEventsListener: c.eventsHandler.Size(), Debug: c.debug, MemoryLimit: true, SwapLimit: true, CPUCfsPeriod: true, CPUCfsQuota: true, CPUShares: true, CPUSet: true, IPv4Forwarding: true, BridgeNfIptables: true, BridgeNfIP6tables: true, OomKillDisable: true, OperatingSystem: runtime.GOOS, Architecture: runtime.GOARCH, NCPU: int(c.cluster.TotalCpus()), MemTotal: c.cluster.TotalMemory(), HTTPProxy: os.Getenv("http_proxy"), HTTPSProxy: os.Getenv("https_proxy"), NoProxy: os.Getenv("no_proxy"), SystemTime: time.Now().Format(time.RFC3339Nano), ExperimentalBuild: experimental.ENABLED, } if kernelVersion, err := kernel.GetKernelVersion(); err == nil { info.KernelVersion = kernelVersion.String() } for _, c := range c.cluster.Containers() { info.Containers++ if c.Info.State.Paused { info.ContainersPaused++ } else if c.Info.State.Running { info.ContainersRunning++ } else { info.ContainersStopped++ } } if hostname, err := os.Hostname(); err == nil { info.Name = hostname } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(info) }
func (s *Server) getVersion(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { v := &types.Version{ Version: dockerversion.VERSION, ApiVersion: api.APIVERSION, GitCommit: dockerversion.GITCOMMIT, GoVersion: runtime.Version(), Os: runtime.GOOS, Arch: runtime.GOARCH, } if kernelVersion, err := kernel.GetKernelVersion(); err == nil { v.KernelVersion = kernelVersion.String() } return writeJSON(w, http.StatusOK, v) }
func checkKernel() error { // Check for unsupported kernel versions // FIXME: it would be cleaner to not test for specific versions, but rather // test for specific functionalities. // Unfortunately we can't test for the feature "does not cause a kernel panic" // without actually causing a kernel panic, so we need this workaround until // the circumstances of pre-3.10 crashes are clearer. // For details see https://github.com/docker/docker/issues/407 if !checkKernelVersion(3, 10, 0) { v, _ := kernel.GetKernelVersion() if os.Getenv("DOCKER_NOWARN_KERNEL_VERSION") == "" { logrus.Warnf("Your Linux kernel version %s can be unstable running docker. Please upgrade your kernel to 3.10.0.", v.String()) } } return nil }
// builtins jobs independent of any subsystem func dockerVersion(job *engine.Job) engine.Status { v := &engine.Env{} v.SetJson("Version", dockerversion.VERSION) v.SetJson("ApiVersion", api.APIVERSION) v.Set("GitCommit", dockerversion.GITCOMMIT) v.Set("GoVersion", runtime.Version()) v.Set("Os", runtime.GOOS) v.Set("Arch", runtime.GOARCH) if kernelVersion, err := kernel.GetKernelVersion(); err == nil { v.Set("KernelVersion", kernelVersion.String()) } if _, err := v.WriteTo(job.Stdout); err != nil { return job.Error(err) } return engine.StatusOK }
func init() { httpVersion := make([]useragent.VersionInfo, 0, 6) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "docker", Version: dockerversion.Version}) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "go", Version: runtime.Version()}) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "git-commit", Version: dockerversion.GitCommit}) if kernelVersion, err := kernel.GetKernelVersion(); err == nil { httpVersion = append(httpVersion, useragent.VersionInfo{Name: "kernel", Version: kernelVersion.String()}) } httpVersion = append(httpVersion, useragent.VersionInfo{Name: "os", Version: runtime.GOOS}) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "arch", Version: runtime.GOARCH}) dockerUserAgent = useragent.AppendVersions("", httpVersion...) if runtime.GOOS != "linux" { V2Only = true } }
// SystemVersion returns version information about the daemon. func (daemon *Daemon) SystemVersion() types.Version { v := types.Version{ Version: dockerversion.Version, GitCommit: dockerversion.GitCommit, GoVersion: runtime.Version(), Os: runtime.GOOS, Arch: runtime.GOARCH, BuildTime: dockerversion.BuildTime, Experimental: utils.ExperimentalBuild(), } if kernelVersion, err := kernel.GetKernelVersion(); err == nil { v.KernelVersion = kernelVersion.String() } return v }
func HTTPRequestFactory(metaHeaders map[string][]string) *utils.HTTPRequestFactory { // FIXME: this replicates the 'info' job. httpVersion := make([]utils.VersionInfo, 0, 4) httpVersion = append(httpVersion, &simpleVersionInfo{"docker", dockerversion.VERSION}) httpVersion = append(httpVersion, &simpleVersionInfo{"go", runtime.Version()}) httpVersion = append(httpVersion, &simpleVersionInfo{"git-commit", dockerversion.GITCOMMIT}) if kernelVersion, err := kernel.GetKernelVersion(); err == nil { httpVersion = append(httpVersion, &simpleVersionInfo{"kernel", kernelVersion.String()}) } httpVersion = append(httpVersion, &simpleVersionInfo{"os", runtime.GOOS}) httpVersion = append(httpVersion, &simpleVersionInfo{"arch", runtime.GOARCH}) ud := utils.NewHTTPUserAgentDecorator(httpVersion...) md := &utils.HTTPMetaHeadersDecorator{ Headers: metaHeaders, } factory := utils.NewHTTPRequestFactory(ud, md) return factory }
func checkKernel(k, major, minor int) error { leastVersionInfo := kernel.VersionInfo{ Kernel: k, Major: major, Minor: minor, } if v, err := kernel.GetKernelVersion(); err != nil { return err } else { if kernel.CompareKernelVersion(*v, leastVersionInfo) < 0 { msg := fmt.Sprintf("Your Linux kernel(%d.%d.%d) is too old to support Hyper daemon(%d.%d.%d+)", v.Kernel, v.Major, v.Minor, k, major, minor) return fmt.Errorf(msg) } return nil } }
func checkSystem() error { // check OS version for compatibility, ensure running in global zone var err error var id C.zoneid_t if id, err = C.getzoneid(); err != nil { return fmt.Errorf("Exiting. Error getting zone id: %+v", err) } if int(id) != 0 { return fmt.Errorf("Exiting because the Docker daemon is not running in the global zone") } v, err := kernel.GetKernelVersion() if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: 5, Major: 12, Minor: 0}) < 0 { return fmt.Errorf("Your Solaris kernel version: %s doesn't support Docker. Please upgrade to 5.12.0", v.String()) } return err }
func checkKernel() error { // Check for unsupported kernel versions // FIXME: it would be cleaner to not test for specific versions, but rather // test for specific functionalities. // Unfortunately we can't test for the feature "does not cause a kernel panic" // without actually causing a kernel panic, so we need this workaround until // the circumstances of pre-3.10 crashes are clearer. // For details see https://github.com/docker/docker/issues/407 // Docker 1.11 and above doesn't actually run on kernels older than 3.4, // due to containerd-shim usage of PR_SET_CHILD_SUBREAPER (introduced in 3.4). if !kernel.CheckKernelVersion(3, 10, 0) { v, _ := kernel.GetKernelVersion() if os.Getenv("DOCKER_NOWARN_KERNEL_VERSION") == "" { logrus.Fatalf("Your Linux kernel version %s is not supported for running docker. Please upgrade your kernel to 3.10.0 or newer.", v.String()) } } return nil }
// GET /version func getVersion(c *context, w http.ResponseWriter, r *http.Request) { version := apitypes.Version{ Version: "swarm/" + version.VERSION, APIVersion: APIVERSION, GoVersion: runtime.Version(), GitCommit: version.GITCOMMIT, Os: runtime.GOOS, Arch: runtime.GOARCH, Experimental: experimental.ENABLED, BuildTime: version.BUILDTIME, } if kernelVersion, err := kernel.GetKernelVersion(); err == nil { version.KernelVersion = kernelVersion.String() } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(version) }
func checkKernel() error { // Check for unsupported kernel versions // FIXME: it would be cleaner to not test for specific versions, but rather // test for specific functionalities. // Unfortunately we can't test for the feature "does not cause a kernel panic" // without actually causing a kernel panic, so we need this workaround until // the circumstances of pre-3.10 crashes are clearer. // For details see https://github.com/docker/docker/issues/407 if k, err := kernel.GetKernelVersion(); err != nil { logrus.Warnf("%s", err) } else { if kernel.CompareKernelVersion(k, &kernel.KernelVersionInfo{Kernel: 3, Major: 10, Minor: 0}) < 0 { if os.Getenv("DOCKER_NOWARN_KERNEL_VERSION") == "" { logrus.Warnf("You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.10.0.", k.String()) } } } return nil }
// DockerUserAgent is the User-Agent the Docker client uses to identify itself. // In accordance with RFC 7231 (5.5.3) is of the form: // [docker client's UA] UpstreamClient([upstream client's UA]) func DockerUserAgent(ctx context.Context) string { httpVersion := make([]useragent.VersionInfo, 0, 6) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "docker", Version: Version}) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "go", Version: runtime.Version()}) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "git-commit", Version: GitCommit}) if kernelVersion, err := kernel.GetKernelVersion(); err == nil { httpVersion = append(httpVersion, useragent.VersionInfo{Name: "kernel", Version: kernelVersion.String()}) } httpVersion = append(httpVersion, useragent.VersionInfo{Name: "os", Version: runtime.GOOS}) httpVersion = append(httpVersion, useragent.VersionInfo{Name: "arch", Version: runtime.GOARCH}) dockerUA := useragent.AppendVersions("", httpVersion...) upstreamUA := getUserAgentFromContext(ctx) if len(upstreamUA) > 0 { ret := insertUpstreamUserAgent(upstreamUA, dockerUA) return ret } return dockerUA }
func (s *Server) getVersion(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { v := &types.Version{ Version: dockerversion.VERSION, ApiVersion: api.Version, GitCommit: dockerversion.GITCOMMIT, GoVersion: runtime.Version(), Os: runtime.GOOS, Arch: runtime.GOARCH, } if version.GreaterThanOrEqualTo("1.19") { v.Experimental = utils.ExperimentalBuild() } if kernelVersion, err := kernel.GetKernelVersion(); err == nil { v.KernelVersion = kernelVersion.String() } return writeJSON(w, http.StatusOK, v) }
func HTTPRequestFactory(metaHeaders map[string][]string) *requestdecorator.RequestFactory { // FIXME: this replicates the 'info' job. httpVersion := make([]requestdecorator.UAVersionInfo, 0, 4) httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("docker", dockerversion.VERSION)) httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("go", runtime.Version())) httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("git-commit", dockerversion.GITCOMMIT)) if kernelVersion, err := kernel.GetKernelVersion(); err == nil { httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("kernel", kernelVersion.String())) } httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("os", runtime.GOOS)) httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("arch", runtime.GOARCH)) uad := &requestdecorator.UserAgentDecorator{ Versions: httpVersion, } mhd := &requestdecorator.MetaHeadersDecorator{ Headers: metaHeaders, } factory := requestdecorator.NewRequestFactory(uad, mhd) return factory }
// SystemVersion returns version information about the daemon. func (daemon *Daemon) SystemVersion() types.Version { v := types.Version{ Version: dockerversion.Version, GitCommit: dockerversion.GitCommit, GoVersion: runtime.Version(), Os: runtime.GOOS, Arch: runtime.GOARCH, BuildTime: dockerversion.BuildTime, Experimental: utils.ExperimentalBuild(), } kernelVersion := "<unknown>" if kv, err := kernel.GetKernelVersion(); err != nil { logrus.Warnf("Could not get kernel version: %v", err) } else { kernelVersion = kv.String() } v.KernelVersion = kernelVersion return v }
// SetupDevice create a new bridge interface/ func setupDevice(config *networkConfiguration, i *bridgeInterface) error { var setMac bool // We only attempt to create the bridge when the requested device name is // the default one. if config.BridgeName != DefaultBridgeName && !config.AllowNonDefaultBridge { return NonDefaultBridgeExistError(config.BridgeName) } // Set the bridgeInterface netlink.Bridge. i.Link = &netlink.Bridge{ LinkAttrs: netlink.LinkAttrs{ Name: config.BridgeName, }, } // Only set the bridge's MAC address if the kernel version is > 3.3, as it // was not supported before that. kv, err := kernel.GetKernelVersion() if err != nil { logrus.Errorf("Failed to check kernel versions: %v. Will not assign a MAC address to the bridge interface", err) } else { setMac = kv.Kernel > 3 || (kv.Kernel == 3 && kv.Major >= 3) } if err = netlink.LinkAdd(i.Link); err != nil { logrus.Debugf("Failed to create bridge %s via netlink. Trying ioctl", config.BridgeName) return ioctlCreateBridge(config.BridgeName, setMac) } if setMac { hwAddr := netutils.GenerateRandomMAC() if err = netlink.LinkSetHardwareAddr(i.Link, hwAddr); err != nil { return fmt.Errorf("failed to set bridge mac-address %s : %s", hwAddr, err.Error()) } logrus.Debugf("Setting bridge mac address to %s", hwAddr) logrus.Debugf("call recieved to bridge driver, PLUMgrid") } return err }