diff options
author | Daniel Golle <daniel@makrotopia.org> | 2020-04-14 12:51:47 +0100 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2020-04-14 12:57:17 +0100 |
commit | cfccdc22ca6d8f28d70a2546a495c9ead4bbb765 (patch) | |
tree | 645cd82dc16395007b6993a0537801f654fb9611 /system-linux.c | |
parent | dbf97b47a53809a6ff812d4466d2082aa4d3efb6 (diff) |
interface, system: clean up netns functionality
Use struct device pointer as parameter instead of bare ifname allows
for some simplication and again removing system_ifname_resolve()
function introduced in commit d93126d.
Fixes: d93126d ("interface: allow renaming interface when moving to jail netns")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'system-linux.c')
-rw-r--r-- | system-linux.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/system-linux.c b/system-linux.c index 04b9bdf..62636c4 100644 --- a/system-linux.c +++ b/system-linux.c @@ -843,21 +843,16 @@ int system_bridge_delif(struct device *bridge, struct device *dev) return system_bridge_if(bridge->ifname, dev, SIOCBRDELIF, NULL); } -static int system_ifname_resolve(const char *ifname) +int system_if_resolve(struct device *dev) { struct ifreq ifr; - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); + strncpy(ifr.ifr_name, dev->ifname, sizeof(ifr.ifr_name) - 1); if (!ioctl(sock_ioctl, SIOCGIFINDEX, &ifr)) return ifr.ifr_ifindex; else return 0; } -int system_if_resolve(struct device *dev) -{ - return system_ifname_resolve(dev->ifname); -} - static int system_if_flags(const char *ifname, unsigned add, unsigned rem) { struct ifreq ifr; @@ -1251,14 +1246,17 @@ nla_put_failure: return -ENOMEM; } -int system_link_netns_move(const char *ifname, int netns_fd, const char *target_ifname) +int system_link_netns_move(struct device *dev, int netns_fd, const char *target_ifname) { struct nl_msg *msg; struct ifinfomsg iim = { .ifi_family = AF_UNSPEC, }; - iim.ifi_index = system_ifname_resolve(ifname); + if (!dev) + return -1; + + iim.ifi_index = system_if_resolve(dev); msg = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST); if (!msg) |