aboutsummaryrefslogtreecommitdiffstats
path: root/main/lxc/network-restore-ability-to-move-nl80211-devices.patch
blob: 965ef8949849808dd4dac9a660ccbbf134c2f44d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From 3dd7829433f63b2ec1323a1f237efa7d67ea6e2b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner@ubuntu.com>
Date: Fri, 26 Jul 2019 08:20:02 +0200
Subject: [PATCH] network: restore ability to move nl80211 devices

Closes #3105.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
---
 src/lxc/network.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/lxc/network.c b/src/lxc/network.c
index 9755116ba1..7684f95918 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -1248,22 +1248,21 @@ static int lxc_netdev_rename_by_name_in_netns(pid_t pid, const char *old,
 static int lxc_netdev_move_wlan(char *physname, const char *ifname, pid_t pid,
 				const char *newname)
 {
-	char *cmd;
+	__do_free char *cmd = NULL;
 	pid_t fpid;
-	int err = -1;
 
 	/* Move phyN into the container.  TODO - do this using netlink.
 	 * However, IIUC this involves a bit more complicated work to talk to
 	 * the 80211 module, so for now just call out to iw.
 	 */
 	cmd = on_path("iw", NULL);
-	if (!cmd)
-		goto out1;
-	free(cmd);
+	if (!cmd) {
+		return -1;
+	}
 
 	fpid = fork();
 	if (fpid < 0)
-		goto out1;
+		return -1;
 
 	if (fpid == 0) {
 		char pidstr[30];
@@ -1274,21 +1273,18 @@ static int lxc_netdev_move_wlan(char *physname, const char *ifname, pid_t pid,
 	}
 
 	if (wait_for_pid(fpid))
-		goto out1;
+		return -1;
 
-	err = 0;
 	if (newname)
-		err = lxc_netdev_rename_by_name_in_netns(pid, ifname, newname);
+		return lxc_netdev_rename_by_name_in_netns(pid, ifname, newname);
 
-out1:
-	free(physname);
-	return err;
+	return 0;
 }
 
 int lxc_netdev_move_by_name(const char *ifname, pid_t pid, const char* newname)
 {
+	__do_free char *physname = NULL;
 	int index;
-	char *physname;
 
 	if (!ifname)
 		return -EINVAL;
@@ -3279,13 +3275,20 @@ int lxc_network_move_created_netdev_priv(struct lxc_handler *handler)
 		return 0;
 
 	lxc_list_for_each(iterator, network) {
+		__do_free char *physname = NULL;
 		int ret;
 		struct lxc_netdev *netdev = iterator->elem;
 
 		if (!netdev->ifindex)
 			continue;
 
-		ret = lxc_netdev_move_by_index(netdev->ifindex, pid, NULL);
+		if (netdev->type == LXC_NET_PHYS)
+			physname = is_wlan(netdev->link);
+
+		if (physname)
+			ret = lxc_netdev_move_wlan(physname, netdev->link, pid, NULL);
+		else
+			ret = lxc_netdev_move_by_index(netdev->ifindex, pid, NULL);
 		if (ret) {
 			errno = -ret;
 			SYSERROR("Failed to move network device \"%s\" with ifindex %d to network namespace %d",