@@ -19,18 +19,18 @@ import (
1919// ContainerInspect returns low-level information about a
2020// container. Returns an error if the container cannot be found, or if
2121// there is an error getting the data.
22- func (daemon * Daemon ) ContainerInspect (ctx context.Context , name string , options backend.ContainerInspectOptions ) (* containertypes.InspectResponse , error ) {
22+ func (daemon * Daemon ) ContainerInspect (ctx context.Context , name string , options backend.ContainerInspectOptions ) (_ * containertypes.InspectResponse , desiredMACAddress string , _ error ) {
2323 ctr , err := daemon .GetContainer (name )
2424 if err != nil {
25- return nil , err
25+ return nil , "" , err
2626 }
2727
2828 ctr .Lock ()
2929
30- base , err := daemon .getInspectData (& daemon .config ().Config , ctr )
30+ base , desiredMACAddress , err := daemon .getInspectData (& daemon .config ().Config , ctr )
3131 if err != nil {
3232 ctr .Unlock ()
33- return nil , err
33+ return nil , "" , err
3434 }
3535
3636 // TODO(thaJeztah): do we need a deep copy here? Otherwise we could use maps.Clone (see https://github.com/moby/moby/commit/7917a36cc787ada58987320e67cc6d96858f3b55)
@@ -61,7 +61,7 @@ func (daemon *Daemon) ContainerInspect(ctx context.Context, name string, options
6161 if options .Size {
6262 sizeRw , sizeRootFs , err := daemon .imageService .GetContainerLayerSize (ctx , base .ID )
6363 if err != nil {
64- return nil , err
64+ return nil , "" , err
6565 }
6666 base .SizeRw = & sizeRw
6767 base .SizeRootFs = & sizeRootFs
@@ -80,10 +80,10 @@ func (daemon *Daemon) ContainerInspect(ctx context.Context, name string, options
8080 base .NetworkSettings = networkSettings
8181 base .ImageManifestDescriptor = imageManifest
8282
83- return base , nil
83+ return base , desiredMACAddress , nil
8484}
8585
86- func (daemon * Daemon ) getInspectData (daemonCfg * config.Config , ctr * container.Container ) (* containertypes.InspectResponse , error ) {
86+ func (daemon * Daemon ) getInspectData (daemonCfg * config.Config , ctr * container.Container ) (_ * containertypes.InspectResponse , desiredMACAddress string , _ error ) {
8787 // make a copy to play with
8888 hostConfig := * ctr .HostConfig
8989
@@ -101,13 +101,14 @@ func (daemon *Daemon) getInspectData(daemonCfg *config.Config, ctr *container.Co
101101 // Config.MacAddress field for older API versions (< 1.44). We set it here
102102 // unconditionally, to keep backward compatibility with clients that use
103103 // unversioned API endpoints.
104- // if ctr.Config != nil {
105- // if nwm := hostConfig.NetworkMode; nwm.IsBridge() || nwm.IsUserDefined() {
106- // if epConf, ok := ctr.NetworkSettings.Networks[nwm.NetworkName()]; ok {
107- // ctr.Config.MacAddress = epConf.DesiredMacAddress //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
108- // }
109- // }
110- // }
104+ var macAddress string
105+ if ctr .Config != nil {
106+ if nwm := hostConfig .NetworkMode ; nwm .IsBridge () || nwm .IsUserDefined () {
107+ if epConf , ok := ctr .NetworkSettings .Networks [nwm .NetworkName ()]; ok {
108+ macAddress = epConf .DesiredMacAddress
109+ }
110+ }
111+ }
111112
112113 var containerHealth * containertypes.Health
113114 if ctr .State .Health != nil {
@@ -163,31 +164,31 @@ func (daemon *Daemon) getInspectData(daemonCfg *config.Config, ctr *container.Co
163164 }
164165
165166 // Additional information only applies to graphDrivers, so we're done.
166- return inspectResponse , nil
167+ return inspectResponse , macAddress , nil
167168 }
168169
169170 inspectResponse .GraphDriver = & storage.DriverData {
170171 Name : ctr .Driver ,
171172 }
172173 if ctr .RWLayer == nil {
173174 if ctr .State .Dead {
174- return inspectResponse , nil
175+ return inspectResponse , "" , nil
175176 }
176- return nil , errdefs .System (errors .New ("RWLayer of container " + ctr .ID + " is unexpectedly nil" ))
177+ return nil , "" , errdefs .System (errors .New ("RWLayer of container " + ctr .ID + " is unexpectedly nil" ))
177178 }
178179
179180 graphDriverData , err := ctr .RWLayer .Metadata ()
180181 if err != nil {
181182 if ctr .State .Dead {
182183 // container is marked as Dead, and its graphDriver metadata may
183184 // have been removed; we can ignore errors.
184- return inspectResponse , nil
185+ return inspectResponse , "" , nil
185186 }
186- return nil , errdefs .System (err )
187+ return nil , "" , errdefs .System (err )
187188 }
188189
189190 inspectResponse .GraphDriver .Data = graphDriverData
190- return inspectResponse , nil
191+ return inspectResponse , macAddress , nil
191192}
192193
193194// ContainerExecInspect returns low-level information about the exec
0 commit comments