Commit Graph
100 Commits
Author SHA1 Message Date
Yu Watanabe e1effd2974 exec-invoke: update log message a bit 2024-02-01 17:45:47 +09:00
Yu Watanabe 41ad015205 core/exec-invoke: call pam_setcred(PAM_DELETE_CRED) after pam_close_session()
The man page pam_setcred(3) states:
> The credentials should be deleted after the session has been closed
> (with pam_close_session(3)).

Follow-up for 3bb39ea936.
2024-02-01 17:45:47 +09:00
Yu Watanabe 613d953988 varlink: add short comment that the log message is checked in test
Follow-up for 038e455462.
2024-01-30 15:41:52 +00:00
Yu Watanabe a342d9e087 nspawn: resolve network interface names before moving to container network namespace
To escape a kernel issue fixed by
https://github.com/torvalds/linux/commit/8e15aee621618a3ee3abecaf1fd8c1428098b7ef,
let's resolve provided interface names earlier, and adjust the interface
name pairs with the result.

Fixes #31104.
2024-01-30 20:37:13 +09:00
Yu Watanabe 3652891c39 sd-device: use new interface name resolvers 2024-01-30 20:37:13 +09:00
Yu Watanabe 4e235561d6 sd-netlink: unify network interface name getter and resolvers
This makes rtnl_resolve_interface() always check the existence of the
resolved interface, which previously did not when a decimal formatted
ifindex is provided, e.g. "1" or "42".
2024-01-30 20:37:04 +09:00
Yu Watanabe 94114711f7 core/service: introduce SERVICE_STATE_WITH_{MAIN,CONTROL}_PROCESS() 2024-01-27 23:08:42 +09:00
Yu Watanabe 6b09c99cba core/socket: introduce SOCKET_STATE_WITH_PROCESS() helper function 2024-01-27 23:08:42 +09:00
Yu Watanabe 28364bc324 core/unit: update outdated comment
Follow-up for 37eb258e91.
2024-01-27 23:08:26 +09:00
Yu Watanabe 107d036c03 Merge pull request #31083 from yuwata/core-several-cleanups
core: several cleanups
2024-01-26 05:30:01 +09:00
Yu Watanabe ea1e0bf10b core: introduce unit_unwatch_pidref_done() helper function
No functional change, just refactoring.
2024-01-26 00:31:02 +09:00
Yu Watanabe ec5e2a1393 core/unit: split out unit_kill_one()
This also renames 'error' -> 'ret_error'.

No functional change, just refactoring.
2024-01-26 00:31:02 +09:00
Yu Watanabe fe80d62657 core/unit: split out unit_kill_context_one()
No functional change, just refactoring.
2024-01-26 00:30:59 +09:00
Yu Watanabe b5edf3a996 test-network: check if networkd forgets routes silently removed by the kernel 2024-01-25 16:43:44 +09:00
Yu Watanabe b91743e019 network/nexthop: drop dependent routes on removal
If a nexthop is removed, dependent routes are silently removed by the kernel.
Hence, networkd may be confused that routes that depends on the nexthop still
exist, and may fail to configure other routes or so.

This is the one for routes of 3cbbe8635a.
2024-01-25 16:43:44 +09:00
Yu Watanabe 6f09031e4d network/route: introduce reverse map for route with nexthop ID
It is not used in this commit, but will be used later.
Preparation for later commits.

This is the one for routes of 531c724682.
2024-01-25 16:43:44 +09:00
Yu Watanabe 97979ece0e network/route: also remove route on cancelling request
Otherwise, the route may arrive after we call
link_drop_foreign_address() or so on reconfiguring interface.

This is the one for routes of 4303e9806b.
2024-01-25 16:43:44 +09:00
Yu Watanabe d529b12a01 network/route: drop Route object even if we fail to remove the route
If we could not remove a route, then previously the corresponding
Route object was never removed, as it was freed only when we receive
remove notification from the kernel. So, we might confused that the
route still exists and being removed, and might block reconfiguring
the route.

With this change, even if we fail to remove a route, the corresponding
Route object will be freed.

This is the one for routes of 56a995fe8e.
2024-01-25 16:43:44 +09:00
Yu Watanabe 74c301b9ee network/route: introduce ref/unref functions for Route object
Then, Route object can live if it is detached from the owner (Manager,
Network, or Wireguard object).

This is the one for routes of ebd9690647.
2024-01-25 16:43:44 +09:00
Yu Watanabe 3caed9ea08 network/route: introduce route_remove_and_cancel()
Then, replace route_remove_and_drop() with it.

If a route is requested, and the request is already called,
we may not received its reply and notification from the kernel, and
the corresponding Route object may not be remembered. Even in such
case, we need to remove the route, otherwise the route will come
later after the function called.

This is the version for route of f22b586a21.
2024-01-25 16:43:44 +09:00
Yu Watanabe 8d01e44c1f network/route: manage all routes by Manager object
Previously, a Route object is owned by a Link object corresponding to the
outgoing interface of the route, and a Route object that does not have
outgoing interface is owned by the Manager object.

However, there were several issues:
- if a route has a nexthop ID, then the corresponding nexthop may be
  changed to use another interface, hence the outgoing interface of the
  route may be changed.
- if a route requested with MultiPathRoute=, then the link who requests
  the route is different from the outgoing interface of the configured
  route. So, we need to find routes on other interfaces on reconfiguring
  or so.

By this change, the limit of the number of routes per-interface is
tentatively dropped. Let's re-introduce the limit later in a nicer way.
2024-01-24 21:52:33 +09:00
Yu Watanabe 6f5c0fafcc Merge pull request #31070 from yuwata/core-cleanups
core: several trivial cleanups
2024-01-24 16:31:37 +09:00
Yu Watanabe 330c080eeb core/exec-invoke: drop unused pam_pid 2024-01-24 14:43:18 +09:00
Yu Watanabe c917a80701 core/service: declare 'int r' at the beginning 2024-01-24 14:43:18 +09:00
Yu Watanabe ae6a9e650c unit: modernize unit_pid_set() 2024-01-24 14:43:18 +09:00
Yu Watanabe b826e31754 core: use helper functions like unit_main_pid() in unit_kill_context()
No functional changes. Just refactoring.
2024-01-24 14:43:18 +09:00
Yu Watanabe 3e22239da7 core: introduce unit_main_pid_full() which optionally provides if the PID is alien or not 2024-01-24 14:43:18 +09:00
Yu Watanabe d70dfe1b27 core: constify PidRef arguments 2024-01-24 14:43:18 +09:00
Yu Watanabe 232e66217d pidref: split out pidref_copy() from pidref_dup() 2024-01-23 22:21:44 +09:00
Yu Watanabe d203659a13 test: add basic tests for PidRef 2024-01-23 22:09:32 +09:00
Yu Watanabe fc5edc91cb Merge pull request #31015 from yuwata/local-addresses
local-addresses: several cleanups and fixes, add test cases
2024-01-23 10:25:35 +09:00
Yu Watanabe 1c62c4fe0b network/route: update MTU of IPv6 route even if the kernel returns -EEXIST 2024-01-20 22:17:26 +09:00
Yu Watanabe c29138697d test-local-addresses: add more test cases 2024-01-20 16:07:19 +09:00
Yu Watanabe e5ee645344 local-addresses: introduce has_local_address() helper function
It will be used later.
2024-01-20 16:07:19 +09:00
Yu Watanabe d10311f407 sd-netlink: drop unused parser for RTA_MULTIPATH 2024-01-20 16:07:19 +09:00
Yu Watanabe 16d95d6ff8 local-addresses: introduce own parser for RTA_MULTIPATH 2024-01-20 16:07:19 +09:00
Yu Watanabe eb1f9ed6a0 local-addresses: also save weight of multipath routes 2024-01-20 16:07:19 +09:00
Yu Watanabe 0b2c0c3159 local-addresses: introduce generic setter add_local_addresses_full() 2024-01-20 16:07:19 +09:00
Yu Watanabe 1305fe4ecf local-addresses: RTA_OIF and RTA_MULTIPATH are exclusive 2024-01-20 16:07:19 +09:00
Yu Watanabe 4019bec852 local-addresses: fix memleak of 'multipath_routes'
Also reduces scopes of some variables.
2024-01-20 16:07:19 +09:00
Yu Watanabe a64f60416c local-addresses: always sort and dedup even if addresses are not requested
Otherwise, the return value may different when ret is NULL or not.
2024-01-20 16:07:19 +09:00
Yu Watanabe e90863f231 local-addresses: ignore tentative addresses
As tentative addresses may be dropped soon if DAD failed.
2024-01-20 16:07:19 +09:00
Yu Watanabe 5cb56068d0 local-addresses: check family more
Just for safety. No functional change, unless the kernel sends broken
messages.
2024-01-20 16:07:19 +09:00
Yu Watanabe 37359b1c81 local-addresses: rename metric -> priority
To make it consistent with the netlink attribute RTA_PRIORITY.
2024-01-20 16:07:19 +09:00
Yu Watanabe d8a3e44a5c test-local-addresses: several modernization
- use size_t for number of addresses,
- use FOREACH_ARRAY() macro,
- use IN_ADDR_TO_STRING() macro, etc.
2024-01-20 16:07:19 +09:00
Yu Watanabe fe0c684b34 network: fix typo
Follow-up for 406fde1a4d.
2024-01-19 23:28:03 +09:00
Yu Watanabe cfe8975a37 network/route-nexthop: configure as a simple gateway when MultipathRoute= is specified only once
The kernel handles such configuration completely equivalent to the case
that Gateway= is specified.
2024-01-19 19:20:29 +09:00
Yu Watanabe e217da1380 network/route: drop unnecessary ownership transfer
Let's free Route objects on the caller side.
2024-01-19 19:20:29 +09:00
Yu Watanabe 10b08b6790 network/route-nexthop: drop unnecessary link arguments
These arguments are unused now.
2024-01-19 19:20:29 +09:00
Yu Watanabe 5a18697d61 network/route: convert route before requesting
Previously,
1. use the passed Route object as is when a route is requested,
2. when the route becomes ready to configure, convert the Route object
   if necessary, to resolve outgoing interface name, and split multipath
   routes, and save them to the associated interfaces,
3. configure the route with the passed Route object.

However, there are several inconsistencies with what kernel does:
- The kernel does not merge nor split IPv4 multipath routes. However, we
  unconditionally split multipath routes to manage.
- The kernel does not set gateway or so to a route if it has nexthop ID.

Fortunately, I do not find any issues caused by the inconsistencies. But
for safety, let's manage routes in a consistent way with the kernel.

This makes,
1. when a route is requested, split IPv6 multipath routes, but keep IPv4
   multipath routes as is, and queue (possibly multiple) requests for
   the route.
2. when the route becomes ready to configure, resolve nexthop and interface
   name, and requeue request if necessary.
3. configure the (possibly split) route.

By using the logic,
- Now we manage routes in a mostly consistent way with the kernel.
- We can drop ConvertedRoutes object.
- Hopefully the code becomes much simpler.
2024-01-19 19:20:29 +09:00
Yu Watanabe ed6a7148f4 network/route-nexthop: fix route_nexthop_copy()
Follow-up for 413ea20ab3.
2024-01-19 19:20:21 +09:00
Yu Watanabe e8736fb6c9 test-13-NSPAWN: add more test case for passing network interfaces
- test interface renaming that conflicts with the current alternative
  network interface name,
- test passing wlan interfaces.
2024-01-19 19:06:19 +09:00
Yu Watanabe 1c3e5b4210 nspawn-network: support passing wireless interface to container
Closes #7873.
2024-01-19 19:06:12 +09:00
Yu Watanabe 326214bfa8 nspawn-network: also check alternative names
If the requested new name for a network interface is already assigned as a
alternative name, then it is not necessary to and cannot rename the
interface.
2024-01-19 19:05:27 +09:00
Yu Watanabe 38475cac6f nspawn-network: split out move_network_interface_one()
This also changes to use sd_device to get some attributes.
So, on moving interfaces back to the parent, we need to populate sysfs
associated to the client netns.
That may look redundant and complicated, but it makes later change
easier, and hopefully faster.
2024-01-19 19:05:26 +09:00
Yu Watanabe cdd9988e43 nspawn-network: split out move_back_network_interfaces()
No functional change, just refactoring and preparation for later
commits.
2024-01-19 19:05:25 +09:00
Yu Watanabe d926864073 sd-netlink: add policy for NL80211_ATTR_NETNS_FD 2024-01-19 15:06:08 +09:00
Yu Watanabe 6e931bc578 sd-netlink: introduce rtnl_rename_link() 2024-01-19 15:06:08 +09:00
Yu Watanabe 3e98379ec0 sd-device: introduce device_get_sysattr_u32() 2024-01-19 15:06:08 +09:00
Yu Watanabe a3df693799 udev-util: introduce reset_cached_udev_availability() 2024-01-19 15:06:08 +09:00
Yu Watanabe 3f53332d4e namespace-util: introduce netns_acquire()
Similar to userns_acquire(), but for network namespace.
2024-01-19 15:06:08 +09:00
Yu Watanabe 387f39ea30 process-util: introduce FORK_NEW_NETNS for safe_fork()
Similar to FORK_NEW_MOUNTNS or FORK_NEW_USERNS.
2024-01-19 15:06:08 +09:00
Yu Watanabe cb566b5d13 namespace-util: downgrade log level in userns_acquire()
On failure, the caller logs the error in LOG_ERR.
2024-01-19 15:06:08 +09:00
Yu Watanabe d2881ef96e tree-wide: add short comments for namespace_open() and namespace_enter()
Also use -EBADF when unspecified.
2024-01-19 15:06:08 +09:00
Yu Watanabe 5178d4a77e namespace-util: rename arguments to prefix 'ret_'
Also reorder opening namespace fd to make it match with the order of the
arguments.
2024-01-19 15:06:08 +09:00
Yu Watanabe 6504d41c63 network: use strdup_or_null() where appropriate 2024-01-19 14:53:51 +09:00
Yu Watanabe 4abb8d7b0b Merge pull request #30975 from yuwata/network-route-several-helper-functions
network/route: introduce several helper functions
2024-01-19 14:42:40 +09:00
Yu Watanabe 3babbdf632 network/route: introduce route_get_request()
No functional change, just refactoring and preparation for later
commits.
2024-01-19 10:23:14 +09:00
Yu Watanabe 2f542fc3d4 network: adjust nexthops of dynamic routes before requesting
No effective functionality is changed. Preparation for later commits.
2024-01-19 10:23:14 +09:00
Yu Watanabe acc3fc9e5f network/route-nexthop: introduce route_adjust_nexthops() and route_nexthops_needs_adjust()
These are not used in this commit, but will be used later.
Preparation for later commits.
2024-01-19 10:23:14 +09:00
Yu Watanabe 413ea20ab3 network/route-nexthop: introduce route_nexthops_copy()
This also introduce an extra argument for route_dup(), but it is
currently unused, will be used later.

No functional change, just preparation for later commits.
2024-01-19 10:21:55 +09:00
Yu Watanabe 406fde1a4d network/route-nexthop: use RTA_MULTIPATH when weight is not zero
As we have no way to specify the weight of gateway without using
RTA_MULTIPATH.
2024-01-19 10:13:44 +09:00
Yu Watanabe 1cdd8b1b66 sd-netlink: fix rtnl_resolve_link_alternative_name()
Fixes a bug introduced by afdf6c3b60.
2024-01-17 18:53:45 +08:00
Yu Watanabe 443afd6c19 Merge pull request #30967 from yuwata/network-can-required-operstate-for-online
network: several cleanups for required operstate for online, and change the default for CAN devices
2024-01-17 07:01:24 +09:00
Yu Watanabe 7155ad9532 test-network: test the default required operational state for CAN devices 2024-01-17 04:05:43 +09:00
Yu Watanabe 3255bda698 network: make 'carrier' as the default required operational state for CAN device
As CAN devices do not support IP address, hence the state never goes to
higher than 'carrier'.

Prompted by https://github.com/linux-can/can-utils/issues/68#issuecomment-1327987724.
2024-01-17 04:05:43 +09:00
Yu Watanabe 2e59ba4e24 wait-online: several cleanups for LinkOperationalState
- fix memleak in parser,
- fix missing return in parser on failure,
- drop unnecessary temporary argument in command line argument parser,
- use recently introduced macros and helper functions.
2024-01-17 04:05:43 +09:00
Yu Watanabe 2278d9f66e network: several cleanups for LinkOperationalState
- introduce link_required_operstate_for_online() helper function,
- use recently introduced macros and helper functions,
- unconditionally serialize the minimum and maximum of required
  operational state.
2024-01-17 04:05:43 +09:00
Yu Watanabe ba04f957fe network: drop unnecessary temporary variables 2024-01-17 04:05:43 +09:00
Yu Watanabe 2db2979505 sd-network: modernize parse_operational_state_range()
- rename 'out' -> 'ret',
- introduce LINK_OPERSTATE_RANGE_INVALID,
- constify LINK_OPERSTATE_RANGE_DEFAULT,
- drop spurious const specifier for allocated string,
- etc,.
2024-01-17 04:05:43 +09:00
Yu Watanabe 15f624f80f sd-network: introduce three helper functions for LinkOperationalState 2024-01-17 04:05:43 +09:00
Yu Watanabe 47420573a7 network/route: find/distinguish routes in the same way that the kernel uses
The kernel uses different logics to find or distinguish IPv4 and IPv6 routes.
Let's follow the same way that the kernel uses.
See comments in the code for more details.
2024-01-16 16:13:53 +00:00
Yu Watanabe b9b5096edb network/queue: detach request from the queue only when the request is actually queued
No effective functionality is changed in this commit.
Refactoring and preparation for later commits.
2024-01-16 23:25:32 +09:00
Yu Watanabe e30dc59c2e network/queue: increase the reference counter of the request before processing it
To prevent the request freed in req->process().

This also makes a request that is not requested by a link detached on failure.
Otherwise, the request may periodically processed and failed forever.
2024-01-16 23:25:32 +09:00
Yu Watanabe 3518ff4a42 network/route: introduce route_get_link() and use it in log_route_debug()
No functional change, just refactoring and preparation for later
commits.
2024-01-16 12:35:58 +00:00
Yu Watanabe f8a6fc51a6 Merge pull request #30851 from lnussel/kernel-install
kernel-install fixes
2024-01-16 14:55:35 +09:00
Yu Watanabe f9b5c27645 test-network: add test case for removal of nexthop that is a member of a group nexthop 2024-01-16 12:48:50 +09:00
Yu Watanabe 3cbbe8635a network/nexthop: drop dependent nexthops on removal
If a nexthop is removed, dependent nexthops are silently removed by the
kernel. Hence, networkd may be confused that nexthops that depends on the
nexthop still exist, and may fail to configure other routes or so.
2024-01-16 12:48:50 +09:00
Yu Watanabe 531c724682 network/nexthop: introduce a reverse map of nexthop group members
It is not used in this commit, but will be used later.
Preparation for later commits.
2024-01-16 12:48:50 +09:00
Yu Watanabe 4e9795ebfa network/nexthop: read netlink message in nexthop_update_group()
No functional change, preparation for later commits.
2024-01-16 12:48:50 +09:00
Yu Watanabe 04a25cc425 network/nexthop: reorder elements in NextHop 2024-01-16 12:48:50 +09:00
Yu Watanabe 0a94e19c72 network/route: trivial cosmetic changes
- downgrade log level,
- add short comment for boolean argument.
2024-01-16 11:45:14 +09:00
Yu Watanabe 0013863972 network/route: reorder getters in manager_rtnl_process_route()
No functional change, just refactoring and preparation for later
commits.
2024-01-16 11:02:55 +09:00
Yu Watanabe 31b26dee4f network/route: reorder setter called in route_set_netlink_message()
Also, this renames 'req' -> 'm', and makes the function unconditionally
set route type and route metric, and override type later if necessary.

Should not change any effective behavior. Just refactoring.
2024-01-16 11:02:55 +09:00
Yu Watanabe e717b825d4 network/route: reorder elements in Route object and add comments 2024-01-16 11:02:55 +09:00
Yu Watanabe 1bcd7cd0e7 network/route: relocate route_new() and friends
No functional change, preparation for later commits.
2024-01-16 11:02:55 +09:00
Yu Watanabe a663ddc04e test-network: add simple test case for DHCP relay on bridge interface
For issue #30763.
2024-01-15 10:53:07 +00:00
Yu Watanabe 3db1e6a874 resolve: on_transaction_stream_error() may free multiple transactions
Fixes #30928.
2024-01-15 10:36:14 +00:00
Yu Watanabe 6d1cea7bc6 test-network: try to flip interface state frequently 2024-01-15 15:46:33 +09:00
Yu Watanabe c2eb7753dd network/link: automatically reconfigure interface on failure
Closes #29246.
2024-01-15 15:46:33 +09:00