Commit Graph

181 Commits

Author SHA1 Message Date
A. Wilcox
6b783209a8 tree-wide: basename -> path_extract_filename 2025-06-06 19:06:48 +09:00
Daan De Meyer
baa3fadfb7 network: Clean up includes
Split out of #37344.
2025-05-22 02:15:43 +09:00
Daan De Meyer
1cf40697e3 tree-wide: Sort includes
This was done by running a locally built clang-format with
https://github.com/llvm/llvm-project/pull/137617 and
https://github.com/llvm/llvm-project/pull/137840 applied on all .c
and .h files.
2025-04-30 09:30:51 +02:00
Yu Watanabe
bdf4f200fd network: update comment as hashmap_free_with_destructor() does not exist anymore 2025-04-18 09:16:44 +09:00
Yu Watanabe
67bdb6bee0 network/netdev: remove support of netdevsim
netdevsim device creation by networkd was deprecated by
59a9ef1022 (v246), and it does not work
since kernel v5.2:
e05b2d141f

Now our baseline for the kernel is v5.4. Let's completely kill the
feature.
2025-04-12 09:23:27 +09:00
Beniamino Galvani
f7996e2a33 network: add support for HSR netdev
Add support for creating HSR/PRP interfaces. HSR (High-availability Seamless
Redundancy) and PRP (Parallel Redundancy Protocol) are two protocols that
provide seamless failover against failure of any single network component. They
are both implemented by the "hsr" kernel driver.
2025-04-05 05:23:53 +09:00
Yu Watanabe
efb158a11b network/netdev: fix typo
Follow-up for 09db410606.
2024-11-18 12:53:21 +09:00
Yu Watanabe
422b7c857c network/netdev: do not try to update if not supported
Some netdevs cannot update there properties after created.
Let's skip requests in that case.
2024-11-14 10:17:19 +09:00
Yu Watanabe
f264cd2037 network/netdev: fix counter handling if request is cancelled
Follow-up for 1003093604.

If a netdev is detached for some reasons, then previously the request
was simply cancelled, and the underlying interface never enter the
configured state, as the 'stacked_netdevs_created' flag never set.

This makes the counter decremented manually by the function, and set the
flag. So, the underlying interface can eter the configured state.
2024-11-14 10:17:19 +09:00
Yu Watanabe
259125d53d network/netdev: always queue request of creating netdev then process it later
After PR #34909, networkd tries to update an existing netdev interface if
possible. But, when .netdev files are loaded on start, we have not
enumerate interfaces, so we do not know if the corresponding interface
exists or not. Let's delay processing request a bit.
2024-11-14 10:17:19 +09:00
Yu Watanabe
b0d2ce8342 network/netdev: enter ready state only when it is created by us
Follow-up for PR #34909.

This fixes an issue that network interfaces cannot join a master netdev,
like bond or bridge, when the corresponding .netdev is reloaded.

With PR #34909, networkd supports reloading .netdev files. However,
When a .netdev file is modified and reloaded, ifindex is copied from
the old NetDev object to the new one. Thus, even if the interface is
successfully updated, netdev_set_ifindex_impl() will return 0 and
netdev_enter_ready() will never called. If the netdev is a kind of
master netdev, then port interfaces cannot join the master netdev,
as REQUEST_TYPE_SET_LINK_MASTER requires that the master netdev is
in the ready state.
2024-11-14 10:17:19 +09:00
Yu Watanabe
09db410606 network/netdev: do not update MAC address if netdev is already running
Follow-up for 17c5337f7b.

Older kernels (older than v6.5) refuse RTM_NEWLINK messages with IFLA_ADDRESS
attribute when the netdev already exists and is running, even if the MAC
address is unchanged.

So, let's not set IFLA_ADDRESS or IFLA_MTU if they are unchanged, and
set the attributes only when we can update them.
2024-11-14 10:15:44 +09:00
Yu Watanabe
ab6d427547 network/netdev: set interface name only when creating a new netdev
Otherwise, the kernel older than v6.2 will refuse the netlink message.
2024-11-14 10:01:42 +09:00
Yu Watanabe
b8b0c1a065 network: update tunnel or vxlan interface if the local address is changed
If a tunnel or vxlan is configured with Local=dhcp4 or so, then the
local address needs to be changed when it is changed.

Fixes #24854.
2024-10-31 18:41:44 +09:00
Yu Watanabe
b3ae4e8622 network/netdev: replace old NetDev object with newer one on reload
Then, when a .netdev file of a stacked netdev is modified, the netdev
can be reconfigured with the updated setting by something like the
following way:
```
ip link del vlan99
networkctl reload
```

Note, removing the vlan interface in the above example may not be necessary,
e.g. when only VLAN flags, egress mapping, or ingress mapping are updated.
But, it is necessary when VLAN ID is updated.

Closes #9627.
Closes #27177.
Closes #34907.
Replaces #22557.
2024-10-31 05:30:40 +09:00
Yu Watanabe
890bd7225a network/netdev: reconfigure netdev if possible
Some netdev configs can be modified after the interface is created.
Let's allow to reconfigure existing interfaces.
2024-10-31 05:30:40 +09:00
Yu Watanabe
933d88f756 network/netdev: move calls of netdev_attach() and netdev_request_to_create() to netdev_load()
No functional change, preparation for later commits.
2024-10-31 05:30:40 +09:00
Yu Watanabe
5251cb8254 network/netdev: do not try to update several parameters if the interface already exists (#34937)
split-out of #34909.
2024-10-31 04:04:33 +09:00
Yu Watanabe
17c5337f7b network/netdev: introduce netdev_can_set_mac/mtu() helper functions
Several netdevs cannot set IFLA_ADDRESS or IFLA_MTU attribute on update.
Currently, the vtable field is unused, as we do not support updating
existing netdevs. Preparation for later commits.
2024-10-31 01:06:25 +09:00
Yu Watanabe
173c9f639b network: drop no-op cleanup
- network_load() is always called with an empty OrderedHashmap, renamed the output
  parameter to 'ret'.
- When netdev_load() is called on startup, the hashmap is NULL. When it is
  called on reloading, the hashmap is not cleaned up.

Hence, then these cleanups are always no-op. Let's drop them.
2024-10-31 00:58:42 +09:00
Yu Watanabe
d16083557b network/netdev: update state file when NetDev object assignment is changed 2024-10-31 00:52:28 +09:00
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