-
Notifications
You must be signed in to change notification settings - Fork 18.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libnet/d/bridge: don't parse the MacAddress netlabel #47818
libnet/d/bridge: don't parse the MacAddress netlabel #47818
Conversation
Libnet's method `(*Network).createEndpoint()` is already parsing this netlabel to set the field `ep.iface.mac`. Later on, this same method invoke the driver's method `CreateEndpoint` with an `InterfaceInfo` arg and an `options` arg (an opaque map of driver otps). The `InterfaceInfo` interface contains a `MacAddress()` method that returns `ep.iface.mac`. And the opaque map may contain the key `netlabel.MacAddress`. Prior to this change, the bridge driver was calling `MacAddress()`. If no value was returned, it'd fall back to the option set in the `options` map, or generate a MAC address based on the IP address. However, the expected type of the `options` value is a `net.HardwareAddr`. This is what's set by the daemon when handing over the endpoint config to libnet controller. If the value is a string, as is the case if the MAC address is provided through `EndpointsSettings.DriverOpts`, it produces an error. As such, the opaque option and the `MacAddress()` are necessarily the same -- either nothing or a `net.HardwareAddr`. No need to keep both. Moreover, the struct `endpointConfiguration` was only used to store that netlabel value. Drop it too. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
858f131
to
6fbae5f
Compare
Where is (It was confusing a bit that |
First, the Lines 843 to 849 in cd08d37
Then, Lines 1170 to 1174 in cd08d37
Then, driver's Line 1115 in cd08d37
Finally, the bridge driver initializes moby/libnetwork/drivers/bridge/bridge_linux.go Line 1072 in cd08d37
Now, if you're wondering what happens when $ docker run --rm -it --network=name=testnet,driver-opt=com.docker.network.endpoint.macaddress=60:3e:5f:35:9a:e4 nicolaka/netshoot ip -brief link show
docker: Error response from daemon: failed to create endpoint inspiring_galileo on network testnet: trying to create an endpoint with an invalid endpoint configuration. |
- What I did
Libnet's method
(*Network).createEndpoint()
is already parsing this netlabel to set the fieldep.iface.mac
. Later on, this same method invoke the driver's methodCreateEndpoint
with anInterfaceInfo
arg and anoptions
arg (an opaque map of driver opts).The
InterfaceInfo
interface contains aMacAddress()
method that returnsep.iface.mac
. And the opaque map may contain the keynetlabel.MacAddress
.Prior to this change, the bridge driver was calling
MacAddress()
. If no value was returned, it'd fall back to the option set in theoptions
map, or generate a MAC address based on the IP address.However, the expected type of the
options
value is anet.HardwareAddr
. This is what's set by the daemon when handing over the endpoint config to libnet controller. If the value is a string, as is the case if the MAC address is provided throughEndpointsSettings.DriverOpts
, it produces an error.As such, the opaque option and the
MacAddress()
are necessarily the same -- either nothing or anet.HardwareAddr
. No need to keep both.Moreover, the struct
endpointConfiguration
was only used to store that netlabel value. Drop it too.- How I did it
Careful static code analysis.
- How to verify it
CI and tests.
Or manually:
- A picture of a cute animal (not mandatory but encouraged)