diff options
author | Tom Gundersen <teg@jklm.no> | 2013-12-03 18:48:20 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2013-12-04 14:15:13 +0100 |
commit | dd3efc0993b6e95ff04775e9125e2fc9d30fe261 (patch) | |
tree | dddf34390fd4dfdc399305a6b95c4dc9ebcc9c3a /src/network/networkd-manager.c | |
parent | 50b3c42f971f4c9c7791c3b2831f6146ebd15e06 (diff) |
networkd: add link-sense and simplify state-machine a bit
This listens to rtnetlink for changes to IFF_UP and IFF_LOWER_UP (link sense). The latter
is simply logged at the moment, but will be useful once we add dhcp support.
Diffstat (limited to 'src/network/networkd-manager.c')
-rw-r--r-- | src/network/networkd-manager.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 1dc7e88dfd..c8ec23970b 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -35,7 +35,7 @@ int manager_new(Manager **ret) { if (r < 0) return r; - r = sd_rtnl_open(0, &m->rtnl); + r = sd_rtnl_open(RTMGRP_LINK | RTMGRP_IPV4_IFADDR, &m->rtnl); if (r < 0) return r; @@ -243,6 +243,31 @@ int manager_udev_listen(Manager *m) { return 0; } +static int manager_rtnl_process_link(sd_rtnl *rtnl, sd_rtnl_message *message, void *userdata) { + Manager *m = userdata; + Link *link; + unsigned flags; + int r, ifindex; + + r = sd_rtnl_message_link_get_ifindex(message, &ifindex); + if (r < 0) + return 0; + + link = hashmap_get(m->links, &ifindex); + if (!link) + return 0; + + r = sd_rtnl_message_link_get_flags(message, &flags); + if (r < 0) + return 0; + + r = link_update_flags(link, flags); + if (r < 0) + return 0; + + return 1; +} + int manager_rtnl_listen(Manager *m) { int r; @@ -250,5 +275,9 @@ int manager_rtnl_listen(Manager *m) { if (r < 0) return r; + r = sd_rtnl_add_match(m->rtnl, RTM_NEWLINK, &manager_rtnl_process_link, m); + if (r < 0) + return r; + return 0; } |