Commit Graph

49 Commits

Author SHA1 Message Date
Kir Kolyshkin 14c831e003 libnetwork/netavark: simplify isMacVlan init
This fixes the following staticcheck warning:

> libnetwork/netavark/config.go:297:2: QF1007: could merge conditional assignment into variable declaration (staticcheck)
> 	isMacVlan := true
> 	^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-26 09:36:14 -07:00
Paul Holzinger b0fc9a6550 libnetwork/netavark: allow same bridge name with different vlan
When a vlan is used there should be no bridge name conflict check. It is
totally valid to have the same bridge with different vlans in two
configs and that is the intended use case.

Fixes #2095

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-01-30 19:28:24 +01:00
Paul Holzinger 6dfd732abc libnetwork/netavark: do not create config dir in init
Podman creates/initializes the network backend for every command. However
most commands will not need it so we should keep the required actions we
do to a minimum.

In this case the config directory /etc/containers/networks by default as
root may not exists and then we try to create it which can fail, i.e.
when /etc is read only[1].

The code here are a bit more changes then I would have liked but we must
make sure the default in memory network always exists and do not create
the directory there.

[1] https://github.com/containers/common/pull/2265

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-12-09 14:18:30 +01:00
Michael Zimmermann 336b85849c libnetwork: support `mode` option for bridge
L2 will be used to allow using existing bridges which netavark will
neither create nor delete.

Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
2024-11-25 18:10:36 +01:00
Paul Holzinger 805e7ae406 update golangci-lint to 1.60.3
Contains fixes for new linters, removed depracted and removed linters
from the config.

Most notably because we use go 1.22 now we can get rid of the copy for
loop vars[1]. Also as of the go 1..2 we can use the new int range syntax
in for loops the new intrange linter checks that.

[1] https://go.dev/blog/loopvar-preview

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-09-03 15:57:02 +02:00
Paul Holzinger 80e2634dee libnetwork/netavark: accept metric option for mac/ipvlan
This option is also supported by netavark for macvlan and ipvlan
networks.

Fixes #2051

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-06-25 11:32:01 +02:00
Paul Holzinger 7e485a635f Replace golang.org/x/exp/slices with slices from std
Use "slices" from the standard library, this package was added in go
1.21 so we can use it now.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-04-22 14:12:47 +02:00
Paul Holzinger d4ce3d5274 libnetwork/netavark: remove ipam bucket on network rm
This is good to prevent any leaks but more important here there is a
bug because we cache the last assigned ip. However when a network is
removed the recreated with a different LeaseRange that ip might be very
well outside the expected range and the logic seems to handle this
correctly. I could fix it there but deleting the full bucket seems best
as it avoid other issues and leaking the bucket forever.

Fixes containers/podman#22034

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-04-03 18:19:57 +02:00
Paul Holzinger d240865a45 lint: update golangci-lint to v1.56.2
Adds a couple of new linters with many new warnings:
- perfsprint (fixed in code, excluded for tests)
- revive (fix the problems, disabled the dot import check as we use it
  for ginkgo)
- inamedparam (disabled because it is opinionated)
- testifylint (great linter but we have like 1000+ issues that I have no
  time fixing now)

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-05 18:10:32 +01:00
Oleksandr Redko 4dbd58b735 Refactor: replace raw loops with funcs from slices and maps
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-05 00:11:15 +02:00
Oleksandr Redko ba4c7c98bb chore: remove outdated build constraints
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-03 22:56:00 +02:00
André Cirne 5f5ea095f6 Add support for vrf option on netavark
Signed-off-by: André Cirne <dumahk21@gmail.com>
2023-09-28 09:13:44 +01:00
OpenShift Merge Robot c203306ccc Merge pull request #1513 from yassi-github/netavark-strict-isolation
libnetwork/netavark: add isolate option 'strict'
2023-06-20 09:29:00 -04:00
Saigusa Yasushi adbdd59591 libnetwork/netavark: add isolate option 'strict'
The strict isolate refuses to communicate with non-isolate and isolate.

Signed-off-by: Saigusa Yasushi <56156402+yassi-github@users.noreply.github.com>
2023-06-20 22:03:51 +09:00
Valentin Rothberg 5981c1b952 make validate: fix comment formatting reports
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-06-16 17:08:25 +02:00
Paul Holzinger e9c74cfce1 netavark: add bclim option for macvlan
see https://github.com/containers/netavark/pull/698

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-05-25 10:28:38 +02:00
Jan Hendrik Farr 97e2561e60 add static routes
Signed-off-by: Jan Hendrik Farr <github@jfarr.cc>
2023-05-24 10:11:08 +00:00
Paul Holzinger 7052cdf26a libnetwork/netavark: add plugin support
Users can now suplly custom network drivers which will execute the
netavark plugin to create the network. Netavark will execute the pluign
to setup/teardown the netns.
see https://github.com/containers/netavark/pull/509

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-04-04 18:17:50 +02:00
Paul Holzinger 510b51d2f6 libnetwork/netavark: error messages should start lower case
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-04-03 18:45:43 +02:00
Paul Holzinger 5a91ce3d7f libnetwork/netavark: combine ipvlan macvlan code
Remove the code duplication and share some code between the ipvlan and
macvlan config creation.

Also fixes a problem with the macvlan dhcp selection, we have to set the
driver to dhcp if it is unset and no subnets are given.
Ipvlan does not support DHCP because the interfaces share the same mac
address.

Added tests for both the mcvlan dhcp selection and the ipvlan creation.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-03-31 15:27:17 +02:00
Michael Zimmermann 7634eea101 libnetwork: enable ipvlan support for netavark
Signed-off-by: Michael Zimmermann <sigmaepsilon92@gmail.com>
2023-03-31 14:35:46 +02:00
Aditya R 6faa28dcf3 netavark,NetworkUpdate: NetworkUpdateOptions must be IP addresses
We enforced NetworkDNSServers to be IP addresses and we follow this
enfore rule while a user is creating network, see comment
https://github.com/containers/common/pull/1237#pullrequestreview-1188001727
and PR https://github.com/containers/common/pull/1237

Following check was missed in `NetworkUpdateOptions` hence add this
check now.

Signed-off-by: Aditya R <arajan@redhat.com>
2023-03-10 19:41:18 +05:30
T K Chandra Hasan a34e72b144 Closes #15830 Support docker-specific network create options via CLI
Signed-off-by: T K Chandra Hasan <t.k.chandra.hasan@ibm.com>
2023-02-10 21:51:48 +05:30
Brent Baude cca00f477e Enable DHCP macvlan
With progress on netavark-dhcp-proxy, we can begin to macvlan with dhcp
back into the fold for netavark.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-01-17 08:15:31 -06:00
Aditya R a1673511b8 libnetwork: extend API to support NetworkUpdate
New features in netavark/aardvark allows users to update network dns
servers and all the containers attached to those networks uses updated
resolvers.

Following PR adds support in `libnetwork` to support

* Add support for higher level `NetworkUpdate` API
* Add support for `Update` exec call which can invoke netavark with a
  new update option added here: https://github.com/containers/netavark/pull/503

Signed-off-by: Aditya R <arajan@redhat.com>
2022-12-07 07:53:02 +05:30
Ygal Blum f7978269e7 Libnetwork: Add NetworkCreateOptions to the NetworkCreate method
For now, only add IgnoreIfExists flag.
Having this flag is very useful when using scripts or systemd unit files

Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
2022-12-05 15:57:15 +02:00
Aditya R f1cb293c6e libnetwork, Network: add field NetworkDNSServers for network scoped dns
libnetwork must allow to pass network_dns_servers so aardvark and
netavark can consume it and enabled network scoped dns.

Feature implemented at netavark and aardvark end
* Netavark: https://github.com/containers/netavark/pull/497

Signed-off-by: Aditya R <arajan@redhat.com>
2022-11-21 21:29:14 +05:30
Matthew Heon 6a357c2a24 Add support for route metric in network configs
All the gruntwork is done by Netavark, so all that's needed it to
know the key exists and verify that it parses as a uint.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2022-11-10 16:09:15 -05:00
Paul Holzinger 13a70914f3 libnetwork/netavark: disable dns for macvlan
This is not supported in netavark so we should set to false by default
to make sure podman inspect will show the correct info.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-10-25 16:14:19 +02:00
Sascha Grunert 426d69c00f Switch to golang native error wrapping
`github.com/pkg/errors` is deprecated since quite some time so we now
use the native error wrapping for more idiomatic golang.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-12 10:54:07 +02:00
Paul Holzinger 9b0fcab189 libnetwork: add constants for network options
Duplicating strings is evil and can result in typos, lets expose the
options as constants.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-07-07 16:56:16 +02:00
cdoern 358905c1be libnetwork/netavark: add isolate option
depends on containers/netavark#275

Signed-off-by: cdoern <cdoern@redhat.com>
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-07-07 16:40:30 +02:00
Doug Rabson 4ae0047591 Build libnetwork/netavark on FreeBSD
This only gets the libnetwork part to build - I have not tried to
get the rest of netavark to build on FreeBSD.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-05-14 10:55:36 +01:00
Paul Holzinger cc110440e4 enable unparam, exportloopref and revive linters
unparam and exportloopref already work without changes.
For revive I had to silence many naming issues. I decided to silence them
instead of changing the name because I didn't want to break any code.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-05-06 13:32:35 +02:00
Kir Kolyshkin 82bf88ed0c libnetwork: rm nolint:golint hints
Those were added by commit 4fcb18dca, but are apparently no longer
needed.

Reported-by: Paul Holzinger <pholzing@redhat.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-04-11 15:03:50 -07:00
Paul Holzinger 82616479ae libnetwork: ipam driver none disable dns
When we create a network with the ipam driver none we should disabled
dns automatically. Since we mange no ips we cannot provide name
resolution anyway.

This fixes a problem I spotted when adding test to the podman CI.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-31 16:39:23 +02:00
Kir Kolyshkin a263ddda2d Fix typos found by codespell
Brought to you by

	make codespell

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-03-30 11:13:44 -07:00
Paul Holzinger cc5a65ab0f libnetwork/netavark: allow network create with no ipam driver
Network create now uses the ipam driver. This allows the user to
configure the ipam driver manually instead of choosing a fixed default.
If the ipam driver is `none` no ips will be assigned to this container.
This means that only the interfaces are created.

This will require a patch in netavark since it rejects the config when
no static ips are provided.

Ref containers/podman#13521

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-29 18:46:29 +02:00
OpenShift Merge Robot 490b31cd90 Merge pull request #968 from vrothberg/go1.18
go fmt: use go 1.18 conditional-build syntax
2022-03-18 12:00:40 +01:00
Valentin Rothberg 095aded91c go fmt: use go 1.18 conditional-build syntax
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-18 11:04:40 +01:00
Paul Holzinger 111b33c197 libnetwork: export "driver" as constant
It is better to use a global const than having to type "driver" at every
place.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-17 14:11:34 +01:00
Nalin Dahyabhai f9fd35395d libnetwork/netavark.netavarkNetwork.networkCreate(): close the file
If we have to write a new configuration file, close the file handle when
we finish writing to it, instead of just letting it pass out of scope.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-03-15 16:12:12 -04:00
Paul Holzinger a8296384fb netavark: macvlan allow internal networks
When internal is used the default route will not be added,
see https://github.com/containers/netavark/pull/246

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-02-25 14:41:51 +01:00
Paul Holzinger 60766b5e5e libnetwork: create pick subnets from subnet pool
When we create a bridge network and no subnet is given we will a free
one automatically. The current logic just took the first free /24
network after 10.89.0.0. Now we will instead use the default subnet pool
from containers.conf. The default value is still the same but users can
change it if they want. This also fixes a problem where podman network
create could pick a public ipv4 network when all 10.0.0.0/8 networks
were already used. Now it will error if no free subnet is found in the
subnet pools.

Fixes #930

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-02-15 15:30:42 +01:00
Paul Holzinger ff12fff79f netavark: add support for dns with internal
netavark + aardvark support this when we add a gateway ip to the config
so that aardvark can use this address to bind on it.
We only add the gateway when not internal or when dns is enabled. If
internal without dns we do not need the gw address.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-02-04 14:27:26 +01:00
Paul Holzinger 6dc28b6260 libnetwork fix subnet validation for macvlan
When we create a macvlan network we should not check if the subnet is
already in use on the host since this is expected for macvlan networks.
Only bridge networks should use this check.

Fixes containers/podman#12971

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-24 16:40:38 +01:00
Paul Holzinger f18244b9a1 libnetwork: netavark allow mtu option for macvlan
We have to support the mtu option for netavark since it is also
supported by CNI.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-10 16:55:19 +01:00
Paul Holzinger 4fcb18dca7 libnetwork: fix lint errors
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-12-17 14:24:21 +01:00
Paul Holzinger 002673d22f add libnetwork package
Copy the libpod/network packages from podman to here so we can use the
same code in buildah as well.

This is mostly a one to one copy only the import paths have been changed
and some errors were added.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-12-16 19:07:38 +01:00