Merge pull request #30936 from yuwata/network-automatically-reconfigure-interface-on-failure

network: automatically reconfigure interface on failure
This commit is contained in:
Luca Boccassi
2024-01-15 10:09:30 +00:00
committed by GitHub
3 changed files with 45 additions and 8 deletions

View File

@@ -381,6 +381,8 @@ int link_stop_engines(Link *link, bool may_keep_dhcp) {
}
void link_enter_failed(Link *link) {
int r;
assert(link);
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
@@ -390,7 +392,22 @@ void link_enter_failed(Link *link) {
link_set_state(link, LINK_STATE_FAILED);
(void) link_stop_engines(link, false);
if (!ratelimit_below(&link->automatic_reconfigure_ratelimit)) {
log_link_warning(link, "The interface entered the failed state frequently, refusing to reconfigure it automatically.");
goto stop;
}
log_link_info(link, "Trying to reconfigure the interface.");
r = link_reconfigure(link, /* force = */ true);
if (r < 0) {
log_link_warning_errno(link, r, "Failed to reconfigure interface: %m");
goto stop;
}
return;
stop:
(void) link_stop_engines(link, /* may_keep_dhcp = */ false);
}
void link_check_ready(Link *link) {
@@ -416,11 +433,9 @@ void link_check_ready(Link *link) {
if (!link->activated)
return (void) log_link_debug(link, "%s(): link is not activated.", __func__);
if (link->iftype == ARPHRD_CAN) {
if (link->iftype == ARPHRD_CAN)
/* let's shortcut things for CAN which doesn't need most of checks below. */
link_set_state(link, LINK_STATE_CONFIGURED);
return;
}
goto ready;
if (!link->stacked_netdevs_created)
return (void) log_link_debug(link, "%s(): stacked netdevs are not created.", __func__);
@@ -2554,6 +2569,7 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
.n_ref = 1,
.state = LINK_STATE_PENDING,
.online_state = _LINK_ONLINE_STATE_INVALID,
.automatic_reconfigure_ratelimit = (const RateLimit) { .interval = 10 * USEC_PER_SEC, .burst = 5 },
.ifindex = ifindex,
.iftype = iftype,
.ifname = TAKE_PTR(ifname),

View File

@@ -25,6 +25,7 @@
#include "networkd-ipv6ll.h"
#include "networkd-util.h"
#include "ordered-set.h"
#include "ratelimit.h"
#include "resolve-util.h"
#include "set.h"
@@ -106,6 +107,7 @@ typedef struct Link {
LinkAddressState ipv4_address_state;
LinkAddressState ipv6_address_state;
LinkOnlineState online_state;
RateLimit automatic_reconfigure_ratelimit;
unsigned static_address_messages;
unsigned static_address_label_messages;

View File

@@ -12,6 +12,7 @@ import itertools
import json
import os
import pathlib
import random
import re
import shutil
import signal
@@ -5109,9 +5110,7 @@ class NetworkdRATests(unittest.TestCase, Utilities):
self.teardown_nftset('addr6', 'network6', 'ifindex')
def test_ipv6_token_static(self):
copy_network_unit('25-veth.netdev', '25-ipv6-prefix.network', '25-ipv6-prefix-veth-token-static.network')
start_networkd()
def check_ipv6_token_static(self):
self.wait_online(['veth99:routable', 'veth-peer:degraded'])
output = networkctl_status('veth99')
@@ -5121,6 +5120,26 @@ class NetworkdRATests(unittest.TestCase, Utilities):
self.assertRegex(output, '2002:da8:2:0:1a:2b:3c:4d')
self.assertRegex(output, '2002:da8:2:0:fa:de:ca:fe')
def test_ipv6_token_static(self):
copy_network_unit('25-veth.netdev', '25-ipv6-prefix.network', '25-ipv6-prefix-veth-token-static.network')
start_networkd()
self.check_ipv6_token_static()
for _ in range(20):
check_output('ip link set veth99 down')
check_output('ip link set veth99 up')
self.check_ipv6_token_static()
for _ in range(20):
check_output('ip link set veth99 down')
time.sleep(random.uniform(0, 0.1))
check_output('ip link set veth99 up')
time.sleep(random.uniform(0, 0.1))
self.check_ipv6_token_static()
def test_ipv6_token_prefixstable(self):
copy_network_unit('25-veth.netdev', '25-ipv6-prefix.network', '25-ipv6-prefix-veth-token-prefixstable.network')
start_networkd()