Commit Graph

493 Commits

Author SHA1 Message Date
Yu Watanabe
04b7949ecf network: use hash ops with destructor 2025-01-23 18:22:47 +09:00
Yu Watanabe
848cdf56dc udev,network: drop unnecessary check for result of sd_listen_fds_with_names() 2025-01-19 23:54:41 +09:00
Yu Watanabe
7bbe9ad796 network: introduce system wide default setting for DHCPv4 client ID
Typically, the same client identifier setting is used for all
interfaces. Hence, better to provide the system-wide setting to specify
the client identifier.
2024-12-30 10:27:39 +09:00
Mike Yuan
22583a002e networkd-sysctl: rename functions to match our typical prefixes 2024-12-18 16:36:24 +01:00
Yu Watanabe
00b363bb81 network: drop outdated comment
All Route objects are managed by Manager since
8d01e44c1f.
2024-12-11 11:21:14 +09:00
Yu Watanabe
80a89d1ad5 network: rename KeepConfiguration=dhcp -> dynamic
KeepConfiguration=dhcp keeps not only DHCP configurations but
also SLAAC or IPV4LL. Let's rename the value to 'dynamic'.
2024-11-14 10:23:09 +09:00
Yu Watanabe
c321d332e3 network: introduce manager_serialize()/deserialize()
Currently, only configuration sources and providers of addresses and
routes are serialized/deserialized.
This should mostly not change behavior, as dynamic (except for DHCPv4)
configurations will be dropped before stopping networkd, and for DHCPv4
protocol, we have already had another logic to handle DHCPv4
configurations.
Preparation for later commits.
2024-11-14 10:21:55 +09:00
Yu Watanabe
df69f29728 network: reconfigure interface more gracefully (#35035)
split-out of #34989.
2024-11-06 17:57:56 +09:00
Yu Watanabe
c0323de6ca network: use path_is_network_fs_harder()
Closes #32426.
2024-11-06 04:58:59 +09:00
Yu Watanabe
2b07a3211b network: several cleanups for link_reconfigure()
Effectively no functional changes, just refactoring and preparation for
later changes.

- convert boolean flag 'force' to LinkReconfigurationFlag enum,
- merge link_reconfigure() and reconfigure_handler_on_bus_method_reload() as
  link_reconfigure_full(),
- Rename ReconfigureData -> LinkReconfigurationData,
- make Reconfigure() DBus message wait for reconfiguration being
  started before sending reply.
2024-11-06 02:05:00 +09:00
Yu Watanabe
6119221afa network: add more debugging logs
This also fixes the position of the logging "Enumeration completed.",
and downgrade its log level.
2024-11-05 02:55:15 +09:00
Yu Watanabe
9c402e3ae2 network: check if interface is initialized after enumeration completed
We enumerate interfaces at first, then enumerate other configurations
like addresses and so on. If we are running on a container, previously
we started to configure the enumerated interfaces before enumerating other
configurations.
Let's configure interfaces after all configurations are enumerated.
2024-11-05 02:55:15 +09:00
Yu Watanabe
ae65974883 network: remove unexpected netlink socket from service manager 2024-11-05 02:55:15 +09:00
Yu Watanabe
49e5013432 network: free DHCP client and friends in link_free()
No functional change, at least now. Preparation for later commits.

But we are planning to extend KeepConfiguration= and also keep
addresses and so on assigned by other dynamic configuration protocol
like DHCPv6 or NDisc.
However, when link_free_engines() is called here, acquired addresses so
on by NDisc will be removed, even if link_stop_engines() handles
restarting networkd or KeepConfiguration= gracefully.
So, let's not free engines here, but free them later in link_free().
It is not necessary to be called here anyway.
2024-11-03 09:14:36 +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
e725a91ab7 network: several cleanups for reloading .network files (#34933)
split-out of #34909.
2024-10-31 04:04:10 +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
db68e99046 network: process queued remove requests before networkd is stopped
This makes networkd process all queued remove requests when a
terminating or restarting signal is received. Otherwise, e.g. DHCPv4
address will not be removed on stop, especially when
KeepConfiguration=no.

Fixes a bug introduced by 85a6f300c1 and
its subsequent commits.

Fixes #34837.

Co-authored-by: Will Fancher <elvishjerricco@gmail.com>
2024-10-31 00:34:44 +09:00
Yu Watanabe
4d6ad22f8d network: drop unnecessary BPF related objects from Manager when disabled 2024-09-17 15:00:06 +09:00
Yu Watanabe
099ee34ca1 network/sysctl-monitor: do not allocate sysctl_shadow when eBPF is not supported
When eBPF is disabled, the hashmap will be never used. Let's not
allocate it.
2024-09-17 14:53:29 +09:00
Yu Watanabe
a2fbe9f3f9 network/sysctl-monitor: fix use-after-free
Previously, manager_free() did not assign NULL to Manager.sysctl_shadow,
hence sysctl_clear_link_shadows() called by link_free() will causes
use-after-free. To fix the issue, this makes Manager.sysctl_shadow will be
set to NULL after it is freed,

Fixes a bug introduced by 6d9ef22acd.
2024-09-16 15:12:47 +09:00
Matteo Croce
64e03ca8bf minor fixups for #32212
Fix minor post merge comments
2024-09-13 07:23:07 +02:00
Matteo Croce
6d9ef22acd emit a warning in networkd if managed sysctls are changed
Monitor the sysctl set by networkd for writes, if a sysctl is
overwritten with a different value than the one we set, emit a warning.
Writes are detected with an eBPF program attached as BPF_CGROUP_SYSCTL
which reports the sysctl writes only in net/.

The eBPF program only reports sysctl writes from a different cgroup than networkd.
To do this, it uses the `bpf_current_task_under_cgroup_proto()` helper,
which will be available allowed in BPF_CGROUP_SYSCTL from kernel 6.12[1].

Loading a BPF_CGROUP_SYSCTL program requires the CAP_SYS_ADMIN capability,
so drop it just after the program load, whether it loads successfully or not.

Writes are logged but permitted, in future the functionality can be
extended to also deny writes to managed sysctls.

[1] https://lore.kernel.org/bpf/20240819162805.78235-3-technoboy85@gmail.com/
2024-09-11 23:07:00 +02:00
Matteo Croce
64629617b6 store the sysctls set by networkd
networkd set several sysctl to set the network configuration. Save their
value so we can check is other processes change them.
2024-09-11 23:01:25 +02:00
Yu Watanabe
36ca0164ab network/netdev: allow to register the same NetDev object with multiple names
Preparation for later commits.
2024-09-10 19:30:17 +09:00
Yu Watanabe
021d39d3d1 network: log and enter failed state in link_reconfigure()
No functional change, just refactoring.
2024-08-21 07:29:30 +09:00
Yu Watanabe
489671d225 network/address-label: allow to configure IPv6 address label in networkd.conf
Closes #23159.
2024-08-20 20:50:56 +09:00
Yu Watanabe
418f2dc755 network: introduce network- and protocol-independent default for UseDomains=
Follow-up for fb57300743.

Prompted by #32273.
2024-04-20 12:01:53 +09:00
Yu Watanabe
7a169cb40f network: introduce link_get_use_domains()
No functional change, just refactoring.
2024-04-19 10:23:00 +09:00
Yu Watanabe
fb6f98ae63 network: open persistent directory without O_PATH
Addresses https://github.com/systemd/systemd/pull/31811#discussion_r1557549629.
2024-04-10 04:59:43 +09:00
Yu Watanabe
a3ed665a29 network/dhcp-server: introduce PersistLeases= setting
Requested at https://github.com/systemd/systemd/pull/31772#issuecomment-2000053357.
2024-03-27 13:21:15 +00:00
Mike Yuan
b377a7cce9 daemon-util: introduce notify_reloading helper
Prompted by #31951
2024-03-26 12:52:33 +00:00
Yu Watanabe
013359ac65 network: pin file descriptor of persistent storage
This also drop the support of /run/systemd/netif/persistent-storage-ready,
as the file is anyway removed when networkd is stopped.
Let's use $SYSTEMD_NETWORK_PERSISTENT_STORAGE_READY=1 instead on testing.
2024-03-16 01:12:05 +09:00
Mike Yuan
9c16c8a177 networkd-manager: drop spurious return
Follow-up for f90eb08627
2024-03-13 21:44:33 +09:00
Yu Watanabe
f90eb08627 network/varlink: introduce io.systemd.Network.SetPersistentStorage method
And make the networkd use state directory.

Currently, the state directory and the method are not used, but will be used later.
2024-03-12 01:57:11 +09:00
Yu Watanabe
3976c43092 network: introduce per-interface IP forwarding settings
This deprecates IPForward= setting, which unconditionally controled
the global setting, even though it is a setting in .network file.

Instead, this introduces new IPv4Forwarding= and IPv6Forwarding=
settings both in .network and networkd.conf.
If these settings are specified in a .network file, then the
per-interface forwarding setting will be configured.
If specified in networkd.conf, then the global IP forwarding setting will
be configured.

Closes #30648.
2024-02-22 19:24:12 +00:00
Yu Watanabe
1e869a5de9 network: make Reload bus method synchronous
Prompted by https://github.com/systemd/systemd/pull/30085#discussion_r1401534107.

Note, like Reconfigure bus method, even reconfiguration for an interface is
triggered by Reload method, the method only wait for the link enters
configuring state (or unmanaged state if no matching .network file exists).
Users still need to invoke systemd-networkd-wait-online if it is
necessary to wait for the interface enters configured state after Reload
medhod.
2024-02-09 14:25:54 +09:00
Yu Watanabe
85a6f300c1 network/queue: introduce RemoveRequest and relevant functions
This is similar to Request, but will be used on removing configuration
(e.g. address, route, and so on).

By using another queue for removing configuration, then we can avoid to
fill the reply callback buffer in sd-netlink by remove message calls.

Follow-up for 4e6a35e2b2.
2024-01-12 09:36:00 +09:00
Lennart Poettering
2a1ffd3e3a bus-polkit: port polkit_registry to use value destructors in hash_ops 2024-01-03 11:53:52 +01:00
Yu Watanabe
fb53ee0a64 tree-wide: use device_in_subsystem() and device_is_devtype() 2023-12-23 03:52:21 +09:00
Luca Boccassi
12b6b3cfd9 Merge pull request #30550 from yuwata/network-nexthop-cleanups-3
network: several cleanups for nexthop (part3)
2023-12-22 10:44:39 +01:00
Lennart Poettering
c5c74d85d3 networkd: add basic Varlink interface
Let's get networkd onto Varlink. This only adds the most basic of
operations.

I'd love to see networkd do Varlink for all its basic operations so that
networkctl can use that, and work correctly before D-Bus is up. Right
now, many of networkctls calls simply don't work before D-Bus, and I'd
like to see that improved.
2023-12-22 11:54:43 +09:00
Yu Watanabe
e36d8e4858 network: merge two post event sources
No functional change, just refactoring.
2023-12-21 04:27:52 +09:00
Yu Watanabe
2e1113b7d0 network: split out manager_clean_all() from manager_dirty_handler()
And rename manager_dirty_handler() to manager_post_handler().

No functional change, just refactoring.
2023-12-21 04:27:09 +09:00
Yu Watanabe
fb126bb168 network/nexthop: cache requested nexthop IDs 2023-12-21 04:22:46 +09:00
Yu Watanabe
352eba2e49 network/nexthop: manage all nexthops by manager
The kernel manages nexthops by their IDs. Previously networkd manages
nexthops in three ways:
- by the corresponding link, if a nexthop has ifindex,
- by the manager, if a nexthop does not have ifindex,
- by the manager with their IDs.

This unifies the three managements of nexthops into one, and use the
same way as the kernel uses.

This is the one for nexthop already done by
aa9626ee3b for neighbor.
2023-12-14 18:58:26 +09:00
Yu Watanabe
bbc05bec98 network/nexthop: introduce ManageForeignNextHops= boolean setting
Closes #29034.
2023-12-12 23:51:10 +09:00
Yu Watanabe
cfe69f962b network: drop unused Manager.routes_foreign 2023-12-11 15:44:08 +09:00
Yu Watanabe
11cee6efbf network/brvlan: read bridge vlan IDs through netlink and save them
In this commit, obtained vlan IDs are not used, but they will be used in
the later commits.
2023-11-13 03:58:46 +09:00
Yu Watanabe
eba449fa81 sd-device-monitor: unconditionally increase buffer size by sd_device_monitor_new()
As suggested at https://github.com/systemd/systemd/pull/29872#discussion_r1382932633:
> socket memory is these days accounted to the process that owns a socket,
> hence we shouldn't be too concerned that this might waste memory.
2023-11-06 20:39:51 +09:00