mirror of
https://github.com/systemd/systemd.git
synced 2025-01-10 05:18:17 +03:00
network: assign corresponding NetDev object to Link
This commit is contained in:
parent
c2b19b8f70
commit
9aa2585e2f
@ -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"))
|
||||
assert(link);
|
||||
|
||||
ipvlan = IPVLAN(link->netdev);
|
||||
if (!ipvlan)
|
||||
return _NETDEV_IPVLAN_MODE_INVALID;
|
||||
|
||||
if (netdev_get(link->manager, link->ifname, &netdev) < 0)
|
||||
return _NETDEV_IPVLAN_MODE_INVALID;
|
||||
|
||||
if (netdev->kind != NETDEV_KIND_IPVLAN)
|
||||
return _NETDEV_IPVLAN_MODE_INVALID;
|
||||
|
||||
return IPVLAN(netdev)->mode;
|
||||
return ipvlan->mode;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user