Commit Graph

71 Commits

Author SHA1 Message Date
Kir Kolyshkin 555b817630 libnetwork/types: rename RegexError to ErrInvalidName
... and add a deprecated alias so backward compatibility is still
preserved (and users can gradually switch to the new name).

Done because this is now also reported by staticcheck
(in addition to revive) linter.

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 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 56c6a9ac07 libnetwork: fix rexec env check for rootlessnetns
For some unknown reason the podman container image sets the
_CONTAINERS_USERNS_CONFIGURED env to an empty value. I don't know what
the purpose of this is but is will trigger the check here which is wrong
when the container is privileged.

To fix this check that the value is set to done like it is by the reexec
logic. Also make sure the lock dir uses the same condition to stay
consistent.

Fixes containers/podman#22791

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-05-27 15:18:43 +02:00
openshift-merge-bot[bot] 0fb7fdabe0 Merge pull request #1998 from Luap99/rootlessnetns-info
libnetwork: add option to return rootless-netns ips
2024-05-16 18:50:24 +00:00
Paul Holzinger bed6a2dd43 libnetwork: add option to return rootless-netns ips
When using the bridge network mode as rootless we use the rootless netns
logic, for podman this looks like just as using bridge as root. The
issue is however due the extra namespace we block certain address there.
This can be seen best with pasta but actually effects other cases too.
The podman logic tries to use any host ip address for
host.containers.internal but we must make sure to exculde all these
address in the rootless netns as they are not actually the hostns as
thus cause great confusion.

For the --network pasta case I already fixed this by returning the ips on
the pasta.Setup2() call in 83573fa60c.
For the bridge mode this more complicated due several layers of function
calls. I decided to implement this as extra function call on the interface
to return the ips as this makes the usage in podman the easiest. And I
also didn't want to break the API as we only have to fix this in podman
not buildah.

It is needed to address #22653 but it needs podman changes as well to
use this new function.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-05-16 15:24:52 +02:00
Paul Holzinger 8dad68ced6 libnetwork/cni: remove dnsname dependency from tests
Skip or remove tests that need dnsname in order to function.
As of fedora 40 dnsname is no longer packaged so our CI VM cannot use
it.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-05-15 18:23:29 +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
Giuseppe Scrivano c6a7a1cd2a libnetwork: use fileutils.(Le|E)xists
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-10 12:23:07 +02:00
Paul Holzinger 4a7a8a3496 lint: enable ginkgolinter
This linter creates better assertions in ginkgo tests.
Fixes were made with `ginkgolinter -fix ./...`.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-18 11:51:54 +01:00
Dan Čermák 95730e30c3 Gate CNI support behind the `cni` build tag
- add cni build tag to libnetwork/cni
- split libnetwork/network into multiple files so that cni support can be made
  optionally available
- add -cni build targets to Makefile and build for amd64 with and without cni
- add a simple upgrade mechanism if the user never set the network backend explicitly
- add cni build tag to .golangci.yml to prevent false positives

See also https://issues.redhat.com/browse/RUN-1943

Signed-off-by: Dan Čermák <dcermak@suse.com>
2024-01-30 09:18:31 +01:00
Oleksandr Redko 63869c6bf3 chore: replace 'interface{}' with 'any' for consistency
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-08 21:26:34 +02:00
Oleksandr Redko 0e202b45a1 Refactor map init with short declaration syntax
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-06 19:28:43 +02: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
openshift-merge-bot[bot] ce424557dd Merge pull request #1781 from alexandear/fix-typos-across-repo
Fix typos across repo; extend codespell config
2024-01-04 11:12:20 +00:00
Oleksandr Redko 3cc2a76ae9 Fix typos across repo; extend codespell config
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-03 23:38:47 +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
Paul Holzinger 9ebf5859ff libnetwork/{netavark,cni}: accept containers.conf
Just pass down the full containers.conf as this is needed by
rootlessnetns code, also remove the now duplicated fields and read the
options directly from the config struct.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-12-05 15:28:20 +01:00
Paul Holzinger 27584f37d9 libnetwork/{netavark,cni}: add iptables to $PATH
The old rootlessnetns logic overwrote PATH for the current process to
make sure /usr/sbin (where iptables is normally installed) is in $PATH.

Now instead of adding it for the current process we can just always set
it for the cni/iptables exec only.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-12-05 15:28:20 +01:00
Paul Holzinger 45b61c15d1 libnetwork/cni: integrate rootlessnetns
Call directly into the rootlessnetns code.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-12-05 14:06:25 +01:00
Paul Holzinger 80f1e50c0c libnetwork/cni: ignore ENOENT while reading networks
At this point we already read the config file but here we have to get
timestamp here so we can hit another ENOENT if it was removed in the
meantime. Just ignore this and do not log an error as this is normal
behavior when another process is deleting a network in parallel.

Fixes containers/podman#20173

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-09-27 15:51:46 +02:00
Daniel J Walsh 914d952b30 Split up util package into pkg/password, pkg/detach, pkg/version
Fixes: https://github.com/containers/common/issues/1654

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-09-19 16:02:16 -04:00
Valentin Rothberg 057a58e388 fix typo
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-09-04 08:19:27 +02:00
Valentin Rothberg de32d5a9f7 linters: enable dupword
Mostly monkey work to fix comments but there was also an error message.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-09-01 11:51:25 +02:00
Doug Rabson e57cd8cc6c libnetwork/cni: use 'ifconfig -j' on FreeBSD if it is supported
This allows us to use a single jail for containers with networking since
CNI can initialise the network without needing a separate jail to own
the network namespace.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2023-08-17 07:54:34 +01:00
Valentin Rothberg c3c4acc667 make validate: fix unused argument reports
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-06-16 17:08:25 +02:00
Toshiki Sonoda 32716085ac libnetwork: add NetworkInfo() for get network information
NetworkInfo() return the network binary path, package version,
program version and DNS information.

Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
2023-05-16 14:20:45 +09:00
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
Daniel J Walsh 1e0cff1b9d Don't use lockfile.Locker, it is deprecated
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-02-06 15:00:30 -05:00
Paul Holzinger 4add344e52 libnetwork/cni: mkdir network config dir
Commit 2fae6d9fd6 caused a regression, previously the lockfile
package create the config directory. Now this is no longer the case
so we have to create it explicitly.

Note that netavark already did this so no change is needed there.

This was reported by the RHEL QE team.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-01-17 14:56:47 +01:00
Paul Holzinger 2fae6d9fd6 libnetwork: change lock path to tmpfs for root
The default /etc/containers/networks location might not be writeable,
while this breaks podman network create it does not need to break all
podman commands since the lock is created on libpod initialization.

ref https://github.com/containers/common/pull/1270

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-01-05 16:46:42 +01:00
Paul Holzinger 70d14082ea pkg/netns: UnmountNS() accept netns path as string
I want to switch podman over to only using strings for the netns path.
So we no longer pass this interface around. Buildah doesn't use this so
we only need to fix it in Podman. I have a WIP PR[1] for that.

[1] https://github.com/containers/podman/pull/16756

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-12-07 14:53:47 +01: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
OpenShift Merge Robot fe43935658 Merge pull request #1250 from ygalblum/network_ignore
Libnetwork: Add IgnoreIfExists flag to network create method
2022-12-06 06:07:49 -05:00
OpenShift Merge Robot 6f6214464b Merge pull request #1256 from Luap99/cni-ipam-none
libnetwork/cni: fix panic with ipam driver none
2022-12-06 03:38:42 -05:00
Paul Holzinger 81fd874f80 libnetwork/cni: fix panic with ipam driver none
When creating macvlan or ipvlan network configs with the none ipam
driver we would always cause a segfault because of a nil pointer
dereference.

Add a test for both to prevent a regression.

Fixes containers/podman#16620

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-12-05 17:55:03 +01:00
Daniel J Walsh ad04f58f7a Vendor in latest containers/(storage, image)
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-12-05 10:04:10 -05:00
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
Valentin Rothberg e17483b871 bump to golangci-lint v1.50.0
Used `go fmt` rules to migrate away from deprecated functions, for
instance `gofmt -w -s -r 'ioutil.TempDir(a, b) -> os.MkdirTemp(a, b)'`

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-10-17 15:03:07 +02:00
Matthew Heon 8bfe4fc505 Use an alternative CNI lock for read-only config dirs
When the configuration directory is on a read-only filesystem,
there's no risk of concurrency issues as there's no possibility
of changing anything. As such, while it prevents the use of our
default lock location, it also removes any need for a lock at
all.

Making the lock entirely optional is a lot of code, so instead of
doing that let's just put it in our temporary files directory,
where it can't hurt anything.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2022-08-17 14:59:25 -04: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
Paul Holzinger 707b428450 libnetwork/cni: add isolate option
Add the isolate option to cni. This uses the ingress policy from the firewall
plugin.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-07-07 16:26:11 +02:00
Doug Rabson 6080aacb34 Build libnetwork/cni on FreeBSD
This is enough to get basic CNI networking working on FreeBSD

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-05-14 10:55:32 +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
Kir Kolyshkin a4c0ca652a libnetwork/cni: use unix pkg to get file time
This removes the questionable Sys().(*syscall.Stat_t) typecast.
OTOH we have to handle EINTR, so it's a tad more complicated than it
should be.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-04-09 17:53:46 -07:00
Kir Kolyshkin b951b72412 Gofumpt the code
gofumpt is a stricter version of gofmt, basically making the code more
readable, and fixing the gocritic's octalLiterar warnings like this one:

	pkg/util/util_supported.go:26:17: octalLiteral: use new octal literal style, 0o722 (gocritic)
		return (perm & 0722) == 0700
			       ^

Generated by gofumpt -w .

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-04-09 16:50:11 -07:00
Kir Kolyshkin 4393468343 *_test.go: fix or suppress errcheck warnings
Where we can check the error, do it. Where we can not, ignore it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-04-09 15:18:22 -07:00