diff options
author | Daniel Golle <daniel@makrotopia.org> | 2020-04-13 20:03:35 +0100 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2020-04-14 00:03:00 +0100 |
commit | d93126d3b91ea9e3831b9fd0b5318989f82daebe (patch) | |
tree | 0a4df774abf479338d5c66234a675eed8c5e7e5f /system-linux.c | |
parent | aaaca2e40895775135b13a1992ff139b7610b217 (diff) |
interface: allow renaming interface when moving to jail netns
Introduce jail_ifname option to define the name of a Linux network
interface when moved into a jail's network namespace.
This is useful for containers which expect the network interface to
have a specific name (eg. 'host0' in case of systemd).
While at it, clean-up and fix bugs in jail interface up/down routines.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'system-linux.c')
-rw-r--r-- | system-linux.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/system-linux.c b/system-linux.c index 775b448..04b9bdf 100644 --- a/system-linux.c +++ b/system-linux.c @@ -843,16 +843,21 @@ int system_bridge_delif(struct device *bridge, struct device *dev) return system_bridge_if(bridge->ifname, dev, SIOCBRDELIF, NULL); } -int system_if_resolve(struct device *dev) +static int system_ifname_resolve(const char *ifname) { struct ifreq ifr; - strncpy(ifr.ifr_name, dev->ifname, sizeof(ifr.ifr_name) - 1); + strncpy(ifr.ifr_name, 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; @@ -1246,21 +1251,23 @@ nla_put_failure: return -ENOMEM; } -int system_link_netns_move(const char *ifname, int netns_fd) +int system_link_netns_move(const char *ifname, int netns_fd, const char *target_ifname) { struct nl_msg *msg; struct ifinfomsg iim = { .ifi_family = AF_UNSPEC, - .ifi_index = 0, }; + iim.ifi_index = system_ifname_resolve(ifname); msg = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST); if (!msg) return -1; nlmsg_append(msg, &iim, sizeof(iim), 0); - nla_put_string(msg, IFLA_IFNAME, ifname); + if (target_ifname) + nla_put_string(msg, IFLA_IFNAME, target_ifname); + nla_put_u32(msg, IFLA_NET_NS_FD, netns_fd); return system_rtnl_call(msg); } |