system-linux: delete bridge devices using netlink
authorFelix Fietkau <nbd@nbd.name>
Tue, 1 Feb 2022 10:58:44 +0000 (11:58 +0100)
committerFelix Fietkau <nbd@nbd.name>
Tue, 1 Feb 2022 11:52:41 +0000 (12:52 +0100)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
system-linux.c

index a242f756697d94c7b7f4b8e21ae5f921ee8ff12e..f4d9e73f95887dbe0acae22750d697fc1aa89900 100644 (file)
@@ -755,9 +755,27 @@ static int system_rtnl_call(struct nl_msg *msg)
        return nl_wait_for_ack(sock_rtnl);
 }
 
+static int system_link_del(const char *ifname)
+{
+       struct nl_msg *msg;
+       struct ifinfomsg iim = {
+               .ifi_family = AF_UNSPEC,
+               .ifi_index = 0,
+       };
+
+       msg = nlmsg_alloc_simple(RTM_DELLINK, NLM_F_REQUEST);
+
+       if (!msg)
+               return -1;
+
+       nlmsg_append(msg, &iim, sizeof(iim), 0);
+       nla_put_string(msg, IFLA_IFNAME, ifname);
+       return system_rtnl_call(msg);
+}
+
 int system_bridge_delbr(struct device *bridge)
 {
-       return ioctl(sock_ioctl, SIOCBRDELBR, bridge->ifname);
+       return system_link_del(bridge->ifname);
 }
 
 static int system_bridge_if(const char *bridge, struct device *dev, int cmd, void *data)
@@ -1419,24 +1437,6 @@ int system_link_netns_move(struct device *dev, int netns_fd, const char *target_
        return system_rtnl_call(msg);
 }
 
-static int system_link_del(const char *ifname)
-{
-       struct nl_msg *msg;
-       struct ifinfomsg iim = {
-               .ifi_family = AF_UNSPEC,
-               .ifi_index = 0,
-       };
-
-       msg = nlmsg_alloc_simple(RTM_DELLINK, NLM_F_REQUEST);
-
-       if (!msg)
-               return -1;
-
-       nlmsg_append(msg, &iim, sizeof(iim), 0);
-       nla_put_string(msg, IFLA_IFNAME, ifname);
-       return system_rtnl_call(msg);
-}
-
 int system_macvlan_del(struct device *macvlan)
 {
        return system_link_del(macvlan->ifname);