Commit Graph
160 Commits
Author SHA1 Message Date
Yu Watanabe 1003093604 network/netdev: skip processing netdev if it is already detached
No functional change, as currently networkd detaches NetDev objects only
on stop (or invalid .netdev file is loaded).
Preparation for later commits.
2024-10-30 03:07:32 +09:00
Yu Watanabe 3252a1f274 network/netdev: split out netdev_attach_name_full()
No functional change, preparation for later commits.
2024-10-30 03:07:32 +09:00
Mike Yuan cd7d732dc5 path-lookup: move NETWORK_DIRS to network-util.h 2024-10-06 19:27:11 +02:00
Yu Watanabe 25da422bd1 network: log loaded .network and .netdev files 2024-09-18 02:35:28 +09:00
Yu Watanabe c60cd572bd network/netdev: add attach(), detach(), set_ifindex(), and get_ifindex() to netdev vtable
Currently no vtable sets these functions, but will be used later.
2024-09-10 19:30:17 +09:00
Yu Watanabe 5dc20e1acd network/netdev: split out netdev_set_ifindex_internal() and _impl()
No functional change, just refactoring and preparation for later
commits.
2024-09-10 19:30:13 +09:00
Yu Watanabe bfacb8fe1d network/netdev: split out netdev_attach() and netdev_attach_name() from netdev_load_one()
No functional change, just refactoring and preparation for later
commits.
2024-09-10 19:29:05 +09:00
Yu Watanabe 0dc71b9584 network/netdev: use hashmap_remove_value() on detaching NetDev from manager
Then, it is not necessary to free NetDev.ifname when a conflicting
.netdev file is already loaded.

This also split out netdev_detach_name() and netdev_detach_impl().

No functional change, just refactoring.
2024-09-10 19:29:05 +09:00
Yu Watanabe bc0d3f3842 network/netdev: downgrade log level in netdev_set_ifindex()
This also makes netdev_enter_failed() called on caller side.

No functional change, just refactoring.
2024-09-10 19:29:05 +09:00
Yu Watanabe 5d7de25052 network/netdev: check family of received NEWLINK message
For safety. No functional change, just refactoring and preparation for
later commits.
2024-09-10 19:28:56 +09:00
Yu Watanabe 1788c34628 network/netdev: also check ifindex, iftype, and kind when assigning NetDev to Link
Even when a NetDev object with the same name found, its iftype or kind
may be different. For safety, let's also check them.
2024-09-10 16:38:06 +09:00
Mike Yuan 2cf9b1a0ee network: store netdev drop-in paths and dump into state file 2024-09-09 23:20:41 +02:00
Yu Watanabe 4e494e6aac tree-wise: several cleanups for logging
- drop unnecessary SYNTHETIC_ERRNO() when the logger does not propagate
  error code,
- drop unnecessary '%m' in error message when the error code is
  specified with SYNTHETIC_ERRNO(),
- add missing full stop at the end of log message,
- use RET_GATHER(),
- add missing ", ignoring.",
- upeercase the first letter, etc., etc...
2024-05-01 04:41:06 +09:00
Frantisek Sumsal edda10f2ae tree-wide: make sure net/if.h is included before any linux/ header
The linux/ headers include linux/libc-compat.h that makes sure the
linux/ headers won't redeclare symbols already declared by net/if.h, but
glibc's net/if.h doesn't do that, so if the include order is reversed
we'll end up with a bunch of errors about redeclared stuff:

[3/519] Compiling C object test-network-tables.p/src_network_test-network-tables.c.o
FAILED: test-network-tables.p/src_network_test-network-tables.c.o
cc -Itest-network-tables.p -I. -I.. -Isrc/basic -I../src/basic -Isrc/fundamental -I../src/fundamental -Isrc/systemd -I../src/systemd -I../src/libsystemd/sd-bus -I../src/libsystemd/sd-device -I../src/libsystemd/sd-event -I../src/libsystemd/sd-hwdb -I../src/libsystemd/sd-id128 -I../src/libsystemd/sd-journal -I../src/libsystemd/sd-netlink -I../src/libsystemd/sd-network -I../src/libsystemd/sd-resolve -Isrc/shared -I../src/shared -Isrc/libsystemd-network -I../src/libsystemd-network -Isrc/network -I../src/network -I../src/network/netdev -I../src/network/tc -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -Wno-missing-field-initializers -Wno-unused-parameter -Wno-nonnull-compare -Warray-bounds -Warray-bounds=2 -Wdate-time -Wendif-labels -Werror=format=2 -Werror=format-signedness -Werror=implicit-function-declaration -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Werror=missing-declarations -Werror=missing-prototypes -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=shift-overflow=2 -Werror=strict-flex-arrays -Werror=undef -Wfloat-equal -Wimplicit-fallthrough=5 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2 -Wstrict-prototypes -Wsuggest-attribute=noreturn -Wunused-function -Wwrite-strings -Wzero-length-bounds -fdiagnostics-show-option -fno-common -fstack-protector -fstack-protector-strong -fstrict-flex-arrays --param=ssp-buffer-size=4 -Wno-unused-result -Werror=shadow -fno-strict-aliasing -fstrict-flex-arrays=1 -fvisibility=hidden -fno-omit-frame-pointer -include config.h -pthread -DTEST_CODE=1 -MD -MQ test-network-tables.p/src_network_test-network-tables.c.o -MF test-network-tables.p/src_network_test-network-tables.c.o.d -o test-network-tables.p/src_network_test-network-tables.c.o -c ../src/network/test-network-tables.c
In file included from ../src/basic/linux/if_bonding.h:47,
                 from ../src/network/netdev/bond.h:5,
                 from ../src/network/test-network-tables.c:3:
../src/basic/linux/if.h:111:41: error: redeclaration of enumerator ‘IFF_UP’
  111 | #define IFF_UP                          IFF_UP
      |                                         ^~~~~~
../src/basic/linux/if.h:84:9: note: previous definition of ‘IFF_UP’ with type ‘enum net_device_flags’
   84 |         IFF_UP                          = 1<<0,  /* sysfs */
      |         ^~~~~~
../src/basic/linux/if.h:112:41: error: redeclaration of enumerator ‘IFF_BROADCAST’
  112 | #define IFF_BROADCAST                   IFF_BROADCAST
      |                                         ^~~~~~~~~~~~~
...

This also drops remaining workarounds from the last time this issue was
brought up (6f270e6bd8) since they shouldn't be needed anymore if the
order of the includes is the "correct" one. I also added a comment to
each affected include when this is inevitably encountered again in the
future.

Resolves: #32160
2024-04-09 21:19:15 +02:00
Yu Watanabe f475584ebf network/netdev: call done() per netdev kind before freeing netdev name or so
Otherwise, log_netdev_xyz() does not provide netdev name if it is called
in done(). It is hard to debug.

This should not change any effective behavior, at least with the current
implementation of done() per netdev kind.
2024-01-04 20:34:14 +08:00
Yu Watanabe 4f6ae86629 network: do not try to create netdev from tests
Prompted by #30029.
2023-11-16 02:32:12 +09:00
Yu Watanabe d256945fd0 network/queue: free assigned userdata only when a new request is queued 2023-07-29 23:27:19 +09:00
Daan De Meyer 947f59ba2b conf-parser: Add root argument to config_parse_many() 2023-05-12 17:52:32 +02:00
David Tardon 995340074e tree-wide: use ASSERT_PTR more 2022-09-13 08:13:27 +02:00
Yu Watanabe af7a86b8a6 network/tuntap: save tun or tap file descriptor in fd store 2022-08-16 21:57:35 +09:00
Richard Phibel ead3a3fc87 config-parser: Add list of drop-in files as return argument of config_parse_many
This will be used to save the list of drop-in files for each partition
2022-08-12 12:48:29 +02:00
Yu Watanabe e33232d405 network: also check SR-IOV PF port and other VF ports before configuring
When a PF port becomes down (this can happens e.g. the PF port is joining
a bond interface), some drivers make its VF ports also become down, and
may cause failures in configuring VF ports.

Similary, when a VF port become down, some drivers make its PF port and
other VF ports down.

Let's configure SR-IOV ports (both PF and VFs) after all link-layer
settings of all ports being applied.

Fixes #23315.
2022-08-05 21:49:27 +09:00
Yu Watanabe 00117f8811 network: split out link_is_ready_to_create_stacked_netdev()
Preparation for later commits.
2022-08-05 21:49:27 +09:00
Yu Watanabe 61ec7beaf5 network: always log error in network_load_one() and netdev_load_one() 2022-04-05 02:02:42 +09:00
Yu Watanabe ec4954d934 network: rename netdev kind virtual-wlan -> wlan
The Kind= setting in [Match] section of .network files takes "wlan".
This makes the same setting in .netdev files matches the one in .network
files.
2022-03-28 23:53:12 +09:00
Yu Watanabe de010b0b2e strv: make iterator in STRV_FOREACH() declaread in the loop
This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
2022-03-19 08:33:33 +09:00
Yu Watanabe 09d09207de network: re-design request queue
This makes Request object takes hash, compare, free, and process functions.

With this change, the logic in networkd-queue.c can be mostly
independent of the type of the request or the object (e.g. Address) assigned
to the request, and it becomes simpler.
2022-03-11 14:20:31 +09:00
Yu Watanabe 80d62d4f1a network: introduce request_call_netlink_async()
In most netlink handlers, we do the following,
1. decrease the message counter,
2. check the link state,
3. error handling,
4. update link state via e.g. link_check_ready().

The first two steps are mostly common, hence let's extract it.

Moreover, this is not only extracting the common logic, but provide a
strong advantage; `request_call_netlink_async()` assigns the relevant
Request object to the userdata of the netlink slot, and the request object
has full information about the message we sent. Hence, in the future,
netlink handler can print more detailed error message. E.g. when
an address is failed to configure, then currently we only show an
address is failed to configure, but with this commit, potentially we can
show which address is failed explicitly.

This does not change such error handling yet. But let's do that later.
2022-03-11 14:20:31 +09:00
Yu Watanabe ff51134c93 network: make request_process_address() and friends take Link and corresponding object
This also renames e.g. request_process_address() -> address_process_request().

Also, this drops type checks such as `assert(req->type == REQUEST_TYPE_ADDRESS)`,
as in the later commits, the function of processing request, e.g.
`address_process_request()`, will be assigned to the Request object when
it is created. And the request type will be used to distinguish and to
avoid deduplicating requests which do not have any assigned objects,
like REQUEST_TYPE_DHCP4_CLIENT. Hence, the type checks in process functions
are mostly not necessary and redundant.

This is mostly cleanups and preparation for later commits, and should
not change any behavior.
2022-03-11 14:16:41 +09:00
Yu Watanabe 54ff39f7ae network: make address_configure() and friends take Request object
This should not change any behavior.
Just a preparation for a later commit which introduces
request_call_netlink_async().
2022-03-11 10:40:59 +09:00
Yu Watanabe 3d24b0ddd8 network: netdev: drop unused creation type NETDEV_CREATE_AFTER_CONFIGURED 2022-02-27 09:36:48 +09:00
Yu Watanabe eae0d010f7 network: netdev: use netdev_is_stacked() at one more place 2022-02-26 15:01:50 +09:00
Yu Watanabe b93ce59e51 network: drop unused flag and counter 2022-02-26 05:49:52 +09:00
Yu Watanabe b4d6ae63ba network: split netdev_create() into two 2022-02-26 05:49:52 +09:00
Yu Watanabe c2b19b8f70 network/netdev: drop unused argument 2022-02-26 05:49:52 +09:00
Yu Watanabe fef805b9fa network/netdev: do not assign value on failure 2022-02-26 05:49:52 +09:00
Yu Watanabe 047b9991a4 network: create stacked netdevs after the underlying link is activated
Otherwise, the activation policy for the netdevs are ignored.

Fixes #22593.
2022-02-24 08:37:26 +09:00
Yu Watanabe dedf2d0054 network: add support to create wlan virtual interface
Closes #18977.
2022-02-15 23:24:55 +09:00
Yu Watanabe 1d4312d5f9 network: netdev: add flag to skip kind check
It will be used in later commit.
2022-02-15 16:06:43 +09:00
Yu Watanabe 5d4a925af0 network: netdev: use request queue to create independent netdevs 2022-02-15 16:06:37 +09:00
Yu Watanabe efa7b8adde network: netdev: increment reference counter on request
Otherwise, it may be freed on reload.
2022-02-15 15:54:02 +09:00
Yu Watanabe d708bc6e4f network: netdev: make netdev_is_ready_to_create() return negative errno on fatal error 2022-02-15 15:54:02 +09:00
Yu Watanabe 709055dabb network: rename REQUEST_TYPE_STACKED_NETDEV -> REQUEST_TYPE_NETDEV_STACKED 2022-02-15 15:54:02 +09:00
Zbigniew Jędrzejewski-Szmek 0c50cb50bd network: split out netdev_create_message(), simplify logging 2022-01-05 11:41:29 +01:00
Zbigniew Jędrzejewski-Szmek 5b80ecea55 network: replace detailed netlink append messages with a single generic message
This commit is the first in the series, and they generally follow the same
idea: we had very detailed logging for message append operations which would
only fail either with some type error or intrinsic limit (and then they would
fail everywhere, so this would be noticed during development or in CI), or they
would fail with ENOMEM, in which case the exact location is not very interesting
since this is not repeatable.

I am in general in favour of detailed logging messages, because it helps with
diagnosis of errors, but I think case is an exception. Despite not being very
useful, those messages required a lot of effort, because they were customized
for each and every append operation. In fact some of the messages contained copy
errors. The text of the messages (since they are generally unique) also added up
to a considerable size.

This removes the log messages after each sd_netlink_message_append_*() in
fill_message_create() with a single line in netdev_create(). As described
above, we are just appending fields to a message, so those calls would almost
never fail.

A forgotten 'return' was added in one place.

$ size build/systemd-networkd{.0,}
   text	   data	    bss	    dec	    hex	filename
1878634	 394016	     36	2272686	 22adae	build/systemd-networkd.0
1842450	 394080	     36	2236566	 222096	build/systemd-networkd

… so we save 30k too.
2022-01-05 11:36:04 +01:00
Yu Watanabe 562729d744 network/netdev: introduce .is_ready_to_create() entry in netdev vtable 2021-12-12 13:41:39 +09:00
Yu Watanabe bb916f350a network: call link_check_ready() when all stacked netdevs are created
Follow-up for 879377cad5.

Otherwise, the underlying interface may stuck in configuring state.
2021-12-08 18:40:13 +09:00
Yu Watanabe 543240f593 network/netdev: drop spurious state from the condition to create stacked netdevs
Stacked netdevs are requested when the underlying interface is in
configuring state.
2021-12-07 15:58:25 +09:00
Yu Watanabe f7144e7b0f network/netdev: create stacked netdevs after all set-link operations are finished
E.g. setting MAC address must be done before creating VLAN interface.
2021-12-07 15:58:25 +09:00
Yu Watanabe 45aa0e841b network,udev: do not adjust local assignment bit of specified MAC address
People often assigns the MAC address of the enslaved interface to e.g.
bridge interface. So, the local assignment bit should not be adjusted.

Fixes #21649.
2021-12-07 15:01:04 +09:00