summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2020-04-14 12:51:47 +0100
committerDaniel Golle <daniel@makrotopia.org>2020-04-14 12:57:17 +0100
commitcfccdc22ca6d8f28d70a2546a495c9ead4bbb765 (patch)
tree645cd82dc16395007b6993a0537801f654fb9611
parentdbf97b47a53809a6ff812d4466d2082aa4d3efb6 (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>
-rw-r--r--interface.c4
-rw-r--r--system-dummy.c4
-rw-r--r--system-linux.c16
-rw-r--r--system.h2
4 files changed, 12 insertions, 14 deletions
diff --git a/interface.c b/interface.c
index 24d90aa..782174f 100644
--- a/interface.c
+++ b/interface.c
@@ -1171,7 +1171,7 @@ interface_start_jail(const char *jail, const pid_t netns_pid)
if (!iface->jail || strcmp(iface->jail, jail))
continue;
- system_link_netns_move(iface->ifname, netns_fd, iface->jail_ifname);
+ system_link_netns_move(iface->main_dev.dev, netns_fd, iface->jail_ifname);
}
close(netns_fd);
@@ -1248,7 +1248,7 @@ interface_stop_jail(const char *jail, const pid_t netns_pid)
interface_do_reload(iface);
interface_set_down(iface);
- system_link_netns_move(iface->ifname, root_netns, orig_ifname);
+ system_link_netns_move(iface->main_dev.dev, root_netns, orig_ifname);
}
close(root_netns);
diff --git a/system-dummy.c b/system-dummy.c
index 2669a34..ab1a1b2 100644
--- a/system-dummy.c
+++ b/system-dummy.c
@@ -54,9 +54,9 @@ int system_bridge_delif(struct device *bridge, struct device *dev)
return 0;
}
-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)
{
- D(SYSTEM, "ip link dev %s name %s netns %d\n", ifname, target_ifname, netns_fd);
+ D(SYSTEM, "ip link set %s name %s netns %d\n", dev->ifname, target_ifname, netns_fd);
return 0;
}
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)
diff --git a/system.h b/system.h
index f8f8ec1..b377416 100644
--- a/system.h
+++ b/system.h
@@ -243,7 +243,7 @@ void system_fd_set_cloexec(int fd);
int system_update_ipv6_mtu(struct device *dev, int mtu);
-int system_link_netns_move(const char *ifname, const pid_t target_ns, const char *target_ifname);
+int system_link_netns_move(struct device *dev, const pid_t target_ns, const char *target_ifname);
int system_netns_open(const pid_t target_ns);
int system_netns_set(int netns_fd);