summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-02-17 16:01:28 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-02-25 21:49:52 +0100
commit9aa2585e2f45df1538352d5eb0b2471f5accb3e8 (patch)
tree5dba22d6ac482bb2a754ac8133106060b5bb8880 /src/network
parentnetwork/netdev: drop unused argument (diff)
downloadsystemd-9aa2585e2f45df1538352d5eb0b2471f5accb3e8.tar.xz
systemd-9aa2585e2f45df1538352d5eb0b2471f5accb3e8.zip
network: assign corresponding NetDev object to Link
Diffstat (limited to 'src/network')
-rw-r--r--src/network/netdev/ipvlan.c13
-rw-r--r--src/network/networkd-link.c9
-rw-r--r--src/network/networkd-link.h2
-rw-r--r--src/network/networkd-route.c9
4 files changed, 17 insertions, 16 deletions
diff --git a/src/network/netdev/ipvlan.c b/src/network/netdev/ipvlan.c
index 727e46085b..058eadebd7 100644
--- a/src/network/netdev/ipvlan.c
+++ b/src/network/netdev/ipvlan.c
@@ -80,16 +80,13 @@ const NetDevVTable ipvtap_vtable = {
};
IPVlanMode link_get_ipvlan_mode(Link *link) {
- NetDev *netdev;
+ IPVlan *ipvlan;
- if (!streq_ptr(link->kind, "ipvlan"))
- return _NETDEV_IPVLAN_MODE_INVALID;
-
- if (netdev_get(link->manager, link->ifname, &netdev) < 0)
- return _NETDEV_IPVLAN_MODE_INVALID;
+ assert(link);
- if (netdev->kind != NETDEV_KIND_IPVLAN)
+ ipvlan = IPVLAN(link->netdev);
+ if (!ipvlan)
return _NETDEV_IPVLAN_MODE_INVALID;
- return IPVLAN(netdev)->mode;
+ return ipvlan->mode;
}
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index d26027f0bd..121b4d5e0a 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -228,6 +228,7 @@ static Link *link_free(Link *link) {
unlink_and_free(link->state_file);
sd_device_unref(link->sd_device);
+ netdev_unref(link->netdev);
hashmap_free(link->bound_to_links);
hashmap_free(link->bound_by_links);
@@ -1206,6 +1207,7 @@ static int link_get_network(Link *link, Network **ret) {
static int link_reconfigure_impl(Link *link, bool force) {
Network *network = NULL;
+ NetDev *netdev = NULL;
int r;
assert(link);
@@ -1213,6 +1215,10 @@ static int link_reconfigure_impl(Link *link, bool force) {
if (!IN_SET(link->state, LINK_STATE_INITIALIZED, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED, LINK_STATE_UNMANAGED))
return 0;
+ r = netdev_get(link->manager, link->ifname, &netdev);
+ if (r < 0 && r != -ENOENT)
+ return r;
+
r = link_get_network(link, &network);
if (r < 0 && r != -ENOENT)
return r;
@@ -1265,6 +1271,9 @@ static int link_reconfigure_impl(Link *link, bool force) {
link_free_engines(link);
link->network = network_unref(link->network);
+ netdev_unref(link->netdev);
+ link->netdev = netdev_ref(netdev);
+
if (!network) {
link_set_state(link, LINK_STATE_UNMANAGED);
return 0;
diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h
index 0b257c2414..1a3231efc0 100644
--- a/src/network/networkd-link.h
+++ b/src/network/networkd-link.h
@@ -41,6 +41,7 @@ typedef enum LinkState {
typedef struct Manager Manager;
typedef struct Network Network;
+typedef struct NetDev NetDev;
typedef struct DUID DUID;
typedef struct Link {
@@ -83,6 +84,7 @@ typedef struct Link {
sd_event_source *carrier_lost_timer;
Network *network;
+ NetDev *netdev;
LinkState state;
LinkOperationalState operstate;
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index cb40e3f1ae..2de75f2485 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -871,18 +871,11 @@ static bool route_by_kernel(const Route *route) {
static void link_unmark_wireguard_routes(Link *link) {
Route *route, *existing;
- NetDev *netdev;
Wireguard *w;
assert(link);
- if (!streq_ptr(link->kind, "wireguard"))
- return;
-
- if (netdev_get(link->manager, link->ifname, &netdev) < 0)
- return;
-
- w = WIREGUARD(netdev);
+ w = WIREGUARD(link->netdev);
if (!w)
return;