Commit Graph

232 Commits

Author SHA1 Message Date
Gregor Eichelberger 915849685c Return error on missing host-gateway IP
Signed-off-by: Gregor Eichelberger <gregor.eichelberger@tuwien.ac.at>
2023-07-19 09:14:53 +02:00
Paul Holzinger 4f12d22515 libnetwork: correctly assign free names
If no name is given we have to set a free one, however the logic was
broken since the beginning due some copy paste. This function as the
name suggests must return all network names so we know to not reuse an
existing one.

I just found this by accident no user ever reported this in almost two
years. This likely means no one uses the automatic names and everybody
set's their own name on the cli instead.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-07-13 14:00:59 +02:00
Gregor Eichelberger 556564667a Add HostGateway constant
Signed-off-by: Gregor Eichelberger <gregor.eichelberger@tuwien.ac.at>
2023-07-10 10:06:30 +02:00
Gregor Eichelberger 5cb0d3d121 libnetwork: Add support for host-gateway
This change adds support for the special IP designator `host-gateway` to
the etchosts package.

The first part of fixing https://github.com/containers/podman/issues/14390

Signed-off-by: Gregor Eichelberger <gregor.eichelberger@tuwien.ac.at>
2023-07-06 23:36:05 +02:00
Paul Holzinger 82214a5cba libnetwork/slirp4netns: add Pdeathsig option
Buildah needs this option to ensure the child is killed when buildah is
killed.
Also remove the unused ContainerPID option which is not needed and
unused.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-22 12:30:27 +02:00
Paul Holzinger 86b6495ba7 libnetwork/slirp4netns: Setup() return Result struct
We need to know if ipv6 is enabled in order to create a proper
resolv.conf file. To not return to many arguments create a common struct
for them.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-21 18:39:06 +02:00
Paul Holzinger d7c76067fd libnetwork/slirp4netns: split out const
The cross tests needs at least one empty file in the package in order to
work and we need to linux build tag om slirp4netns as it depends on linux
only code.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-21 18:39:05 +02:00
Paul Holzinger e834ca3816 libnetwork/slirp4netns: remove name stutter
The package is named slirp4netns, no need to repeat that name a bunch of
times.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-21 18:39:05 +02:00
Paul Holzinger 6a6518a910 libnetwork/slirp4netns: return slirp4netns pid
Some callers cannot use the pipe convention, i.e. rootless netns code.
In this case we do not pass down the pipe and just keep track of the pid
and kill it when we are done.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-21 18:39:05 +02:00
Paul Holzinger 73acb5720f add slirp4netns package
Import code from podman/libpod/networking_slirp4netns.go.

This code should live here so we can share it with buildah later.
The code here was heaviliy modified in order to compile because we
cannot use the Container struct here. This should make the code better
separated from the libpod internals and allows it to be used by other
callers, i.e. buildah.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-21 18:39:05 +02: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
Black-Hole1 ab16e8d843 refactor(hosts): export hostContainersInternal variable
Because we need to use the value of this variable in podman, exporting this variable means we don't have to hardcode this string in podman. This will make the code easier to maintain.

Signed-off-by: Black-Hole1 <bh@bugs.cc>
2023-06-20 14:58:22 +08:00
OpenShift Merge Robot e434ff1645 Merge pull request #1511 from vrothberg/golangci-lint
bump golangci-lint to v1.53.3 and address new reports
2023-06-17 03:56:21 -04:00
Valentin Rothberg b0978ef10c make validate: fix redefs of built-ins
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-06-16 17:08:25 +02:00
Valentin Rothberg 3ddaa0afa6 make validate: fix redundant if/else reports
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-06-16 17:08:25 +02: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
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
Paul Holzinger 5740341369 libnetwork/netavark: fix ipam allocation for custom lease range
LeaseRange allows to set a custom start and end ip for our allocator.
However in this case the allocator ignored that fact the the first ip
(network ip) and the last ip (broadcast address only valid for ipv4)
cannot be used. These ips are special and should never be assigned.

Interestingly the kernel allows to assign the broadcast address to a
interface so it would appear to be working and no error was reported.
Only the attempts to make a connection failed.

Fixes containers/podman#18906

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-16 15:02:05 +02:00
OpenShift Merge Robot 66e4e3a160 Merge pull request #1506 from Luap99/pasta
libnetwork: add pasta package to start pasta
2023-06-15 06:12:43 -04:00
Paul Holzinger b4b40c82f6 libnetwork/pasta: BinaryName should be pasta
pasta is a symlink to passt but we should really use pasta, just in case
that changes in the future.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-15 10:28:37 +02:00
Paul Holzinger 9f5b17cce5 libnetwork/pasta: use options from containers.conf
Read pasta_options from containers.conf and set the arguments based on
that. The options that were set on the cli will appended after that so
it allows some form of overwrites.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-15 10:27:48 +02:00
Paul Holzinger 43befeae4d libnetwork/pasta: fix possible panic in error cast
exec.Command().Output() can fail for several errors, i.e. maybe it was
not able to execute at all. We only get a error from type
`exec.ExitError` when the command exited > 0. For all other cases this
cast was unsafe and would cause a panic with a nil deref.

First check the error type correctly with errors.As() then return the
stderr and exit code. Otherwise just return the wrapped error as is.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-15 10:27:10 +02:00
Paul Holzinger 7f9a0dd858 libnetwork: add pasta package to start pasta
Mostly copied from podman/libpod/networking_pasta_linux.go, this should
be moved to common so that we can use it in buildah as well.

I changed the function parameter to accept a single struct with all
options so that we can extend it when needed without breaking the API
The Container type is libpod/podman specific and not available here so
we only use the values we really need here.
Also I removed "pasta" from the function and constant name as this will
now be used as pasta.Setup() so it would be redundant.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-15 10:23:24 +02:00
Paul Holzinger fe4bcb14bf libnetwork/util: export GetLocalIP()
I want to use this function in both podman and buildah, move it to the
util package as it is not specific to etchosts and export it.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-14 14:16:58 +02:00
Paul Holzinger f28b52d2ee libnetwork: handle id filter better
By default we should do a standard prefix match.
See https://github.com/containers/podman/issues/18471 for context.

Also use the c/storage regex package to only compile the regex when
needed.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-06-12 17:00:40 +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
OpenShift Merge Robot a30cf2ef44 Merge pull request #1440 from Cydox/static-routes-pull
Static Routes
2023-05-24 15:44:00 -04: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
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
Paul Holzinger db6c317591 libnetwork/netavark: pass plugin directories to nv
Netavark needs to get the actual list of directories from podman because
users can set them in contianers.conf.

Note that this change requires a netavark with
https://github.com/containers/netavark/pull/509
To allow better backwards compat we only pass the new argument when we
need. Also added the missing ipvlan driver to the supported driver list.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-04-04 18:20:18 +02:00
Paul Holzinger 13dbce596d libnetwork/netavark: add plugin tests
The the plugin integration with the testplugin.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-04-04 18:20:18 +02:00
Paul Holzinger 8ff1bd975e libnetwork/netavark: add test plugin
Add a custom plugin that can be used in the netavark unit tests to check
if the integration works as expected.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-04-04 18:20:18 +02:00
Paul Holzinger 7966ad46e4 pkg/config: add netavark_plugin_dirs fields
Add config field to specify the location for the netavark plugins.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-04-04 18:20:12 +02: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
Chris Evich fcebc34cdc Cirrus: Update CI VM images to F37
Thanks to @Luap99 for the test fix.

Signed-off-by: Chris Evich <cevich@redhat.com>
2023-03-15 14:11:03 -04: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
Paul Holzinger 4e52d1e241 fix netavark IgnoreIfExists config test flake
We cannot compare network with Expect().To(Equal()), the internal
time.Time is not equal after parsing from file. There is some internal
field offset that can be different but the date is still the same. Other
tests have the same problem and to circumvent this we use EqualNetwork()
there. Do the same here.

Fixes #1335

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-02-20 15:13:09 +01: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
OpenShift Merge Robot 449059198d Merge pull request #1292 from baude/adddhcpmacvlanback
Enable DHCP macvlan
2023-01-26 14:41:50 -05:00
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
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
Daniel J Walsh b9ee165a91 Compile regex on demand not in init
Should speed up app startup time a little since the compile
happens for all users of the library. Compile only on use.

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-01-12 16:03:02 -05: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
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
OpenShift Merge Robot 8d21bf2114 Merge pull request #1193 from vrothberg/bump-golangci
bump to golangci-lint v1.50.0
2022-10-17 10:23:28 -04:00
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
Aditya R 2fb7b760ff libnetwork: add DNSServers to NetworkOptions
Netavark now accets `dns_servers` for each container which allows
containers to use custom DNS servers as resolvers instead of falling
back to host's resolver.

Following field allows callers to libnetwork to pass newly added field
to `netavark` and `aarvark-dns`

Actual feature implemented
* https://github.com/containers/aardvark-dns/pull/240
* https://github.com/containers/netavark/pull/452

[NO NEW TESTS NEEDED]
[NO TESTS NEEDED]

Signed-off-by: Aditya R <arajan@redhat.com>
2022-10-17 15:42:35 +05:30
Paul Holzinger dca0b52b53 libnetwork/types: add correct swagger types
Both MAC and IP addresses are strings when serialized to JSON or
deserialized from JSON. By default swagger will show a byte array which
is wrong so we have to manually overwrite these fields.

Required for https://github.com/containers/podman/issues/13342
However we still have to update our swagger version to at least 0.30 in
podman to make it work.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-09-14 12:47:59 +02:00
Daniel J Walsh f8f4db6239 Ignore additionalstore images when deciding to use netavark or CNI
We are using CNI for systems that have run podman system reset, if
storage is setup with additional stores.  This change will ignore
additional store images and will use netarvark on clean systems.

[NO NEW TESTS NEEDED]

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2124887

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-08 13:29:42 -04: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
openshift-ci[bot] 1c9d898c0d Merge pull request #1088 from cdoern/prune
move prune filter parsing to common
2022-07-16 07:56:36 +00:00
Charlie Doern 6d2ab8ad6c move prune filter parsing to common
there was some eerily similar code in c/common and in podman for
creating filter functions for various types. Move some of it here
and add support for the label!= filter in libnetwork only. Libimage already supports it.

after this merges, will file a PR with the fix for containers within podman as well

see containers/podman#14182

Signed-off-by: Charlie Doern <cdoern@redhat.com>
2022-07-15 09:56:02 -04:00
openshift-ci[bot] 765893536d Merge pull request #1077 from saschagrunert/errors
Switch to golang native error wrapping
2022-07-12 11:21:37 +00: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
Dominique Martinet 2e8943d3f7 add network dns_bind_port setting and set NETAVARK_DNS_PORT from it
This commit allows using aardvark with an alternate port as per
implementation in containers/netavark#323

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
2022-07-08 09:45:15 +09:00
Dominique Martinet 06b9bdd684 libnetwork/network/interface.go: fix typo in private function name
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
2022-07-08 08:07:37 +09: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
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
Paul Holzinger 0d0a246be5 resolvconf: add option to keep orig resolv content
Even when a custom nameserver is set by the caller they may wish to
still keep the original nameserver too. This is needed by podman/buildah
when they only want to add the slirp4netns dns ip at the beginning for
example.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-05-23 16:09:10 +02:00
Paul Holzinger 18dde50aa4 libnetwork: add new resolvconf package
both buildah and podman currently use a slightly different resolvconf lib,
to prevent duplication and having to fix bugs twice they should both use
this new package instead.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-05-23 16:09:03 +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
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
Doug Rabson 71784ae373 Build libnetwork/network on FreeBSD
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-05-12 18:13:24 +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
Daniel J Walsh af1f3558c7 Change rootfull->rootful
[NO NEW TESTS NEEDED] Just a docs change.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-04-25 13:50:12 -04:00
Jason T. Greene 77d8f70039 Deprecate MachineEnabled and replace with API
machine.IsPodmanMachine replaces MachineEnabled
machine.MachineHostType informs the type unknown, qemu, wsl, etc
machine.IsGvProxyBased used to make specific determinations re gvproxy

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2022-04-23 12:32:54 -05:00
Paul Holzinger 67db7a92fb libnetwork/etchosts: add GetBaseHostFile()
Add helper function to convert the base_hosts_file config value to a
actual path. It is important to use securejoin to make sure that
containers cannot point to a file on the hosts via a symlink.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-04-21 11:48:55 +02:00
Paul Holzinger ecddbf9779 libnetwork/etchosts: add GetNetworkHostEntries()
Add function to get all host entries from a given network status.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-04-21 11:48:55 +02:00
Paul Holzinger ce62c07f22 add host_containers_internal_ip to containers.conf
Set the ip for the host.containers.internal entry in the containers /etc/hosts
file. This can be set to "none" to disable adding this entry. By default it
will automatically choose the host ip.

Also add a function to get the correct host.containers.internal ip. This
should be used by podman and buildah and then passed to the New()
function.

Ref https://github.com/containers/podman/issues/13224

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-04-21 11:48:36 +02:00
Paul Holzinger a3b0ae033e add base_hosts_file field to containers.conf
base_hosts_file can be used to overwrite the default base host file
/etc/hosts which is used to copy hosts entries from this file into the
containers /etc/hosts file. As special value "image" can be used to copy
the entries from the image hosts file or "none" to not use a base file
at all. IF the value is empty we should use /etc/hosts as default.

Ref https://github.com/containers/podman/issues/13277
Ref https://github.com/containers/podman/issues/13748

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-04-21 11:39:56 +02:00
Paul Holzinger 41cbde0eb2 add new etchosts package
Add a new libnetwork/etchosts package to manage reading/writing hosts files.
This package exports four functions New(), Add(), AddIfExists() and Remove().
See the godoc comments on the functions.

Both podman and buildah should use this functions to make sure files are
generated identical.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-04-21 11:39:55 +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 2c5c3f9343 libnetwork/netavark:: suppress errcheck warn
This one:

	libnetwork/netavark/ipam_test.go:45:22: Error return value is not checked (errcheck)
			networkInterface = libpodNet.(*netavarkNetwork)
					   ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-04-09 17:57:03 -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
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
Sascha Grunert a6b63a5c47 Switch to ginkgo/v2
Update ginkgo to the next major version which has been released a while
ago.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-03-30 10:03:17 +02:00
Paul Holzinger 25888378b2 libnetwork/cni: split option paring into separate function
The gocyclo linter is complaining that the cyclomatic complexity is to
high for `(*cniNetwork).createCNIConfigListFromNetwork()`. Split out
option parsing to a new funtion should reduce the complexity.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-29 18:46:30 +02: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
Paul Holzinger 76fca332db libnetwork/cni: fix CNIResultToStatus conversion logic
When we read the cni result we should loop over the interfaces and then
the ips. If we only loop over ips we will miss interfaces that have no
ips assigned. We also only care about interfaces created in the netns.

This is required for ipam driver none case, see the test case.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-29 18:46:29 +02:00
Paul Holzinger e2dabcc352 libnetwork/cni: 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 cni ipam plugin will be added to teh
config. This means that the interfaces are created but no extra ip
addresses are assigned.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-29 18:46:29 +02:00
Paul Holzinger ccfee7c36c libnetwork/cni: allow no ipam plugin
Parse no ipam plugin and display it as ipam driver none.
Also set the ipam driver field for unsupported plugins.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-03-29 18:46:28 +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 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