Commit Graph

232 Commits

Author SHA1 Message Date
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 a3bb9efe8a libnetwork/cni: add dhcp ipam driver test case
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-17 16:59:37 +01:00
Paul Holzinger 6838f583e7 libnetwork/cni: add support for arbitrary ipam plugins
When we parse CNI config files to convert them into a native Network
struct we should not error unless there is something broken.
The goal is to allow all cni configs to still function but podman
inspect will not be able to show all informations such as subnets about
this network.

Because this is a valid use case we only log this at info level.

Fixes containers/podman#12990
Fixes containers/podman#13124

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-17 16:59:28 +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
Aditya R 8968d3fa1c netavark: warn only if network has DNSEnabled and aardvark binary is not found
Move generic warning to netavark/run and warns user if one or more
network has `DNSEnabled` and `aardvark-dns` binary is not set

Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-04 11:03:24 +05:30
Aditya R d4c4a151e1 libnetwork: Fix warning when aarvark-dns is not found
Use appropriate variable when producing warning for missing
aardvark-dns. Current output variable will always be empty when
aarvark-dns is missing.

Closes: https://github.com/containers/podman/issues/13412

Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-03 21:29:35 +05:30
Paul Holzinger db0b5b1811 cni: macvlan allow internal networks
When we have the host-local ipam plugin we can support internal for
macvlan networks. In this case we just do not add the default route.
Since we cannot control this for dhcp we do not support internal there.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-02-25 14:41:56 +01: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 f146736795 set DefaultSubnetPools for network backend
In commit 60766b5e5e I forgot to add the field here, without this the
config field from containers.conf is not used in backend.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-02-16 18:15:34 +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 4ae6102976 libnetwork: fix NextNetwork() to support arbitrary CIDR
NextSubnet() has to work for more than a, b, c class networks. We also
have to increment arbitrary subnets when we add support for a new config
field where users can specify this.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-02-14 16:23:21 +01:00
Paul Holzinger 06c826f06e remove coverprofile from git history
This file should not be tracked in git. To prevent coverprofile from
being added in the future we also add it to gitignore.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-02-14 14:28:49 +01:00
Paul Holzinger fb094a3e59 cni: do not add default route for internal networks
Since a internal network has no connectivity to the outside we should
not add a default route. Also make sure to not add the default route
more than once for ipv4/ipv6.

Ref containers/podman#13153

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-02-07 17:27:57 +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 16febcdabe netavark: use aardvark-dns path from containers.conf
We need to use the configured path from containers.conf for the
aardvark-dns binary location.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-25 16:06:56 +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
Daniel J Walsh 3e33e53044 Run codespell on code
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-01-21 07:47:02 -05:00
Aditya R efe9d6bce1 libnetwork: support rootless network with netavark and relay runRoot with tmpfs
* Tells netavark if invocation is for `rootful` or `rootless`
  containers.
* Pass `tmpfs` based runRoot to netavark so it can write/read configs
  from there.

Signed-off-by: Aditya R <arajan@redhat.com>
2022-01-19 22:50:17 +05:30
Paul Holzinger 995cdaae8f netavark: use globally shared network config dir
Since the network namespace is shared for all rootful libpod instances
we also need to make sure to use the same network config dir and run dir
to ensure that we do not use the same subnet or ip for more than one
container.

Also update the documentation about the network_config_dir field.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-17 15:36:03 +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 774087c6a7 libnetwork: only validate static ip when ipam is host-local
If the dhcp ipam driver is used podman does not know any subnets so we
cannot verify if the given static ip is in the subnet.

Fixes containers/podman#12762

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-10 16:29:38 +01:00
Paul Holzinger 55acbe7f30 libnetwork: use atomic write for the backend file
It is possible that two processes write at the same time and this could
lead to an invalid value in the file.

I think this fixes a race condition which was observed in the buildah
integration tests.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-07 17:43:19 +01:00
Paul Holzinger c0ddc35864 libnetwork: add method to get the default network name
While we can store the default network name outside this network
interface it can become out of sync with the interface.

In buildah it can be useful to get the name from the interface.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-05 22:08:38 +01:00
Paul Holzinger 641e6dff04 libnetwork: netavark fix mac address marshal
The HardwareAddr type must bbe the actual value and not a pointer
otherwise the marshal logic will not use this function. Added a test to
confirm that this works.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-05 18:27:14 +01:00
Paul Holzinger 588325c4ae libnetwork: netavark use runrooot for ipam db
We should not use XDG_RUNTIME_DIR for the ipam db. This directory is
shared but we need the ipam db per storage. We can use the runroot for
this. It should be a tmpfs to reset the ipam assignments after a reboot.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-04 15:46:23 +01:00
Paul Holzinger 8893b57c6e libnetwork: remove unneeded Lockfile argument
If the caller can decide the lockfile path it is just more likely that
there is a lock missmatch due different lock names. We should always
just use the config dir and use a lock with a static name.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-04 15:46:23 +01:00
Paul Holzinger 25af87fbcc libnetwork: add function to get the default network backend
When the network backend is unset in the config we have to to figure out
if we need CNI or netavark. New installs should use netavark while
existing installs should continue to use CNI to prevent breaking
systems.

We use the following conditions to determine what backend to use:
1. read ${graphroot}/defaultNetworkBackend
2. find netavark binary (if not installed use CNI)
3. check containers, images and CNI networks and if there are some
   we have an existing install and should continue to use CNI

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-04 15:46:12 +01:00
ye.sijun f49c05b158 fix typo
Signed-off-by: ye.sijun <junnplus@gmail.com>
2022-01-03 20:15:46 +08:00
Daniel J Walsh c0aaea1296 Fix darwin builds
[NO NEW TEST NEEDED] Cross compile should be enough.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-12-23 04:32:56 -05: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