diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-11-10 01:51:32 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-11-14 02:17:19 +0100 |
commit | 422b7c857c47aa008af07b74080280c2d8577d95 (patch) | |
tree | 6f36ea8a5c1b7927765b58aa311ea560cf6aac14 /src | |
parent | network/netdev: fix counter handling if request is cancelled (diff) | |
download | systemd-422b7c857c47aa008af07b74080280c2d8577d95.tar.xz systemd-422b7c857c47aa008af07b74080280c2d8577d95.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/netdev/bareudp.c | 1 | ||||
-rw-r--r-- | src/network/netdev/ipvlan.c | 2 | ||||
-rw-r--r-- | src/network/netdev/macvlan.c | 2 | ||||
-rw-r--r-- | src/network/netdev/netdev.c | 20 | ||||
-rw-r--r-- | src/network/netdev/netdev.h | 4 | ||||
-rw-r--r-- | src/network/netdev/veth.c | 1 | ||||
-rw-r--r-- | src/network/netdev/vrf.c | 1 | ||||
-rw-r--r-- | src/network/netdev/vxcan.c | 1 | ||||
-rw-r--r-- | src/network/netdev/wireguard.c | 1 |
9 files changed, 32 insertions, 1 deletions
diff --git a/src/network/netdev/bareudp.c b/src/network/netdev/bareudp.c index b2a161ee7a..e122abd97f 100644 --- a/src/network/netdev/bareudp.c +++ b/src/network/netdev/bareudp.c @@ -72,4 +72,5 @@ const NetDevVTable bare_udp_vtable = { .fill_message_create = netdev_bare_udp_fill_message_create, .create_type = NETDEV_CREATE_INDEPENDENT, .iftype = ARPHRD_NONE, + .keep_existing = true, }; diff --git a/src/network/netdev/ipvlan.c b/src/network/netdev/ipvlan.c index 5cfae1eb64..6e50f72aaa 100644 --- a/src/network/netdev/ipvlan.c +++ b/src/network/netdev/ipvlan.c @@ -60,6 +60,7 @@ const NetDevVTable ipvlan_vtable = { .can_set_mac = ipvlan_can_set_mac, .iftype = ARPHRD_ETHER, .generate_mac = true, + .keep_existing = true, }; const NetDevVTable ipvtap_vtable = { @@ -71,6 +72,7 @@ const NetDevVTable ipvtap_vtable = { .can_set_mac = ipvlan_can_set_mac, .iftype = ARPHRD_ETHER, .generate_mac = true, + .keep_existing = true, }; IPVlanMode link_get_ipvlan_mode(Link *link) { diff --git a/src/network/netdev/macvlan.c b/src/network/netdev/macvlan.c index 1537d868b5..fd112b58e1 100644 --- a/src/network/netdev/macvlan.c +++ b/src/network/netdev/macvlan.c @@ -178,6 +178,7 @@ const NetDevVTable macvtap_vtable = { .create_type = NETDEV_CREATE_STACKED, .iftype = ARPHRD_ETHER, .generate_mac = true, + .keep_existing = true, }; const NetDevVTable macvlan_vtable = { @@ -189,4 +190,5 @@ const NetDevVTable macvlan_vtable = { .create_type = NETDEV_CREATE_STACKED, .iftype = ARPHRD_ETHER, .generate_mac = true, + .keep_existing = true, }; diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index 6cce3838d1..d3c2a8e442 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -400,7 +400,7 @@ int netdev_enter_ready(NetDev *netdev) { assert(netdev); assert(netdev->ifname); - if (netdev->state != NETDEV_STATE_CREATING) + if (!IN_SET(netdev->state, NETDEV_STATE_LOADING, NETDEV_STATE_CREATING)) return 0; netdev->state = NETDEV_STATE_READY; @@ -856,6 +856,15 @@ static int stacked_netdev_process_request(Request *req, Link *link, void *userda if (!netdev_is_managed(netdev)) goto cancelled; /* Already detached, due to e.g. reloading .netdev files, cancelling the request. */ + if (NETDEV_VTABLE(netdev)->keep_existing && netdev->ifindex > 0) { + /* Already exists, and the netdev does not support updating, entering the ready state. */ + r = netdev_enter_ready(netdev); + if (r < 0) + return r; + + goto cancelled; + } + r = netdev_is_ready_to_create(netdev, link); if (r <= 0) return r; @@ -948,6 +957,15 @@ static int independent_netdev_process_request(Request *req, Link *link, void *us if (!netdev_is_managed(netdev)) return 1; /* Already detached, due to e.g. reloading .netdev files, cancelling the request. */ + if (NETDEV_VTABLE(netdev)->keep_existing && netdev->ifindex > 0) { + /* Already exists, and the netdev does not support updating, entering the ready state. */ + r = netdev_enter_ready(netdev); + if (r < 0) + return r; + + return 1; /* Skip this request. */ + } + r = netdev_is_ready_to_create(netdev, NULL); if (r <= 0) return r; diff --git a/src/network/netdev/netdev.h b/src/network/netdev/netdev.h index 765496d044..b330aa394d 100644 --- a/src/network/netdev/netdev.h +++ b/src/network/netdev/netdev.h @@ -199,6 +199,10 @@ typedef struct NetDevVTable { /* When assigning ifindex to the netdev, skip to check if the netdev kind matches. */ bool skip_netdev_kind_check; + + /* Provides if the netdev can be updated, that is, whether RTM_NEWLINK with existing ifindex is supported or not. + * If this is true, the netdev does not support updating. */ + bool keep_existing; } NetDevVTable; extern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX]; diff --git a/src/network/netdev/veth.c b/src/network/netdev/veth.c index edebcf0a74..54d3b59734 100644 --- a/src/network/netdev/veth.c +++ b/src/network/netdev/veth.c @@ -150,4 +150,5 @@ const NetDevVTable veth_vtable = { .get_ifindex = netdev_veth_get_ifindex, .iftype = ARPHRD_ETHER, .generate_mac = true, + .keep_existing = true, }; diff --git a/src/network/netdev/vrf.c b/src/network/netdev/vrf.c index 9e20bd22b2..c35419f859 100644 --- a/src/network/netdev/vrf.c +++ b/src/network/netdev/vrf.c @@ -33,4 +33,5 @@ const NetDevVTable vrf_vtable = { .can_set_mac = vrf_can_set_mac, .iftype = ARPHRD_ETHER, .generate_mac = true, + .keep_existing = true, }; diff --git a/src/network/netdev/vxcan.c b/src/network/netdev/vxcan.c index 929d70f61a..2de89b8e24 100644 --- a/src/network/netdev/vxcan.c +++ b/src/network/netdev/vxcan.c @@ -124,4 +124,5 @@ const NetDevVTable vxcan_vtable = { .set_ifindex = netdev_vxcan_set_ifindex, .get_ifindex = netdev_vxcan_get_ifindex, .iftype = ARPHRD_CAN, + .keep_existing = true, }; diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c index 9e8dfb259a..8d1dddf828 100644 --- a/src/network/netdev/wireguard.c +++ b/src/network/netdev/wireguard.c @@ -1265,4 +1265,5 @@ const NetDevVTable wireguard_vtable = { .create_type = NETDEV_CREATE_INDEPENDENT, .config_verify = wireguard_verify, .iftype = ARPHRD_NONE, + .keep_existing = true, }; |