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>
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);
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);
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;
}
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;
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)
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);