21 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
17de27ffc2 daemon: gofumpt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-01-24 17:16:05 +01:00
Sebastiaan van Stijn
1b5b00c98c fix grammar: user defined / user specified -> user-(defined|specified)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-01-19 13:43:06 +01:00
Sebastiaan van Stijn
10faa629fe libnetwork/drivers/macvlan, ipvlan: assorted minor cleanups
- Inline some vars and align between drivers
- Remove nested if's where possible
- Use `WithError` for some logs, and use the context if available
- Scope variables locally where only used locally and, the reverse,
  make it clear where a (function-)global variable is used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-20 08:52:09 +02:00
Sebastiaan van Stijn
65296cd0e7 libnetwork/drivers/macvlan, ipvlan: un-embed mutexes
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-20 08:14:44 +02:00
Sebastiaan van Stijn
a2f4f09f91 libnetwork/drivers/macvlan, ipvlan: remove unused sync.Once
Both were added as part of the initial implementation in commit [moby@ea30113]
([libnetwork@1d6f2c5]), but never used.

[moby@ea30113]: ea30113303
[libnetwork@1d6f2c5]: 1d6f2c59c4

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-20 08:14:44 +02:00
Sebastiaan van Stijn
5276dd8e9a libnetwork/drivers/ipvlan: remove ifaceGateway utility
This utility was only called with two constant values;

    const (
        defaultV4RouteCidr = "0.0.0.0/0"
        defaultV6RouteCidr = "::/0"
    )

However;

- calling it would always execute a `net.ParseCIDR`
- verify if it would produce an error (which would be very unlikely)
- it used a `staticRoute` struct that was ONLY used for this function
- and immediately deconstructed into its components
- furthermore, the `NextHop` field would be discarded by jinfo.AddStaticRoute,
  which only used the third argument for `routeType == types.NEXTHOP`

This patch:

- removes the `ifaceGateway` and associated `staticRoute` and consts
- defines two package-level vars for `defaultV4Net` and `defaultV6Net`,
  which can be reused (no need to parse / construct them for every join)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-20 08:14:44 +02:00
Sebastiaan van Stijn
d481c09fa7 libnetwork/drivers/macvlan, ipvlan: make driver.leave a stub
These drivers did not do anything meaningful in the `Leave` method; they
would check if the network and/or endpoint were missing, in which case
they produced an error, but the network and endpoint (if present) would
not be used, so it was only validation.

Such validation could still be relevant elsewhere, but looking at where
this method is called; the `Driver.Leave()` is called in two places, both
of which don't handle the error, other than logging it as a warning / error;

It's called by `Endpoint.sbJoin()`, as part of the rollback;
d5c838dc5e/daemon/libnetwork/endpoint.go (L539-L545)

And `Endpoint.sbLeave()`, which also discards the error;
d5c838dc5e/daemon/libnetwork/endpoint.go (L772-L776)

Based on he above, this code looks to be redundant, so replacing it with
a stub; returning `nil`.

As replacing the code removed the use of network.getEndpoint, which was effectively
a copy of network.endpoint (which didn't have error handling), I merged the two
methods, and removed custom error-handling elsewhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-20 08:14:44 +02:00
Sebastiaan van Stijn
aec6e7f7b6 libnetwork/drivers/macvlan, ipvlan: remove networkTable, endpointTable
These types were just a straight map[string]XXX, with no methods or other
properties attached.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-20 08:14:44 +02:00
Sebastiaan van Stijn
bf7277f8fe libnetwork/drivers/macvlan, ipvlan: remove getSubnetforIPv6, getSubnetforIPv4
These methods were just wrappers around getSubnetforIP; let's peel away the
abstraction and call it directly; we're already checking for n.config.Ipv4Subnet
and n.config.Ipv6Subnets on the call-site, so may as well just pass it in.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-20 08:14:34 +02:00
Sebastiaan van Stijn
a294445345 ibnetwork/drivers/macvlan, ipvlan: align and fix potential panic
There were some missing checks whether ep.addr, ep.addrv6 were nil,
which could panic in getSubnetForIP.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-19 13:35:25 +02:00
Sebastiaan van Stijn
17425cff08 libnetwork/drivers/macvlan, ipvlan: driver.Join: don't fetch endpoint twice
The function was fetching a reference to the endpoint twice; while this
did give the option for an early return, in practice it didn't mean much,
because it could still fail if the endpoint was removed in between.

This code still has a race condition, because while a reference to the
endpoint is retrieved while acquiring a lock, the result is mutated without.
This probably needs to either have some accessor, or the function should
keep a lock for the whole operation (possibly switching to an RWMutex).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-19 13:17:56 +02:00
Rob Murray
aa78f19066 ipvlan-l2: do not allocate a gateway address from IPAM
When ipvlan in "l2" mode is given no '--gateway' option, an
address is allocated from IPAM and a default route is set up
via that gateway. But, the gateway address is not assigned to
anything in the Docker ipvlan network - it must be external,
and IPAM shouldn't try to guess it.

So ...

- always disable IPAM gateway address allocation for ipvlan-l2
  - tell libnet to assume the endpoint has a gateway instead
- update the Join code to allow for no configured gateway
- always disable 'docker_gwbridge' connection for ipvlan
  networks, so it's not hooked up when there is no gateway
  address.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-09-12 14:29:15 +01:00
Sebastiaan van Stijn
4b230a4909 internal/testutils: merge with internal/testutil
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-08 10:08:35 +02:00
Albin Kerouanton
6e512cc292 libnet/d/ipvlan: Register: remove unused config param
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-09-03 11:23:07 +02:00
Albin Kerouanton
4d2a293ff3 libnet/drvapi: make NetworkAllocate optional
This method is only used by the cnmallocator to allocate Swarm-scoped
network resources. Its only concrete implementation is in the ovmanager.
Other network drivers are implementing it too to adhere to the
driverapi.Driver interface, but they all return a 'not implemented'
error.

Extract this method into a separate interface, and add a dedicated
RegisterNetworkAllocator to the driver registry. Update the cnmallocator
to load 'network allocators' instead of 'drivers'.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-09-02 21:55:03 +02:00
Albin Kerouanton
cbd04b6f08 libnet/cnmallocator: use a list of local netdrivers
The cnmallocator package has a map of supported network drivers which
are registered using a pkg-local driver registry. This registry is then
used to load drivers, and if they have a 'local' DataScope, they aren't
used for anything. Drivers with a 'global' DataScope are called to
allocate cluster-wide network resources.

Instantiating builtin network drivers may have unintended side-effects
(e.g. the bridge driver registers a callback that should run when
firewalld is reloaded), so libnetwork has dummy '*manager' drivers that
do nothing but carry the same Capability than the original driver they
masquerade.

Put 'local drivers' (e.g. those with DataScope 'local') into a separate
list that just contains drivers' name, and don't register them into the
cnmallocator's driver registry.

Remove all the dummy '*manager' drivers as they're not needed anymore.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-09-02 21:53:50 +02:00
Matthieu MOREL
96f8c6395e chore: enable use-any rule from revive
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-08-08 17:07:07 +02:00
Sebastiaan van Stijn
1205a15db1 libnetwork/types: define RouteType type
Define a `RouteType` type, type the related consts, and update the
`JoinInfo.AddStaticRoute` signature in the interface.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-01 22:33:10 +02:00
Derek McGowan
f74e5d48b3 Create github.com/moby/moby/v2 module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-31 10:13:29 -07:00
Cory Snider
844023f794 libnetwork/driverapi: make EventNotify optional
Overlay is the only driver which makes use of the EventNotify facility,
yet all other driver implementations are forced to provide a stub
implementation. Move the EventNotify and DecodeTableEntry methods into a
new optional TableWatcher interface and remove the stubs from all the
other drivers.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-07-22 11:51:14 -04:00
Derek McGowan
7a720df61f Move libnetwork to daemon/libnetwork
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-14 09:25:23 -07:00