[PATCH 1/1] STA: Add support for Virtual Interface creation/deletion

Jithu Jance jithu
Fri Mar 20 03:39:50 PDT 2015


Hi Jouni,

Please ignore my previous mail. I missed a patch while merging.

>>> Can some additional checks help to address the safety concern? Like
>>> for e.g, adding code to remove the externally added interfaces in case
>>> of a terminate signal.
>>
>> Merging interface_create to interface_add could likely address the
>> concern by recording the added interface to the new driver_nl80211 data
>> structures related to the new interface rather than the one through
>> which it was added. interface_del case would be even clearer since there
>> would be no command for removing an arbitrary netdev, but it would
>> always be through interface_remove that would remove state from both
>> driver_nl80211 and core wpa_supplicant for the dynamically added
>> interface.

>Thanks Jouni for inputs!! I will post a patch after integrating
>interface_create,
>interface_del functionality to interface_add, interface_remove respectively.

Sorry for a delayed follow-up mail. Got stuck with other tasks. :(
Please find the modified patch below. Kindly see whether this is fine.


Adding support for virtual interface creation and deletion
for interface_add and interface_remove commands respectively
(via optional argument)

Signed-off-by: Jithu Jance <jithu at broadcom.com>
---
 wpa_supplicant/ctrl_iface.c |   54 +++++++++++++++++++++++++++++++++++++++----
 wpa_supplicant/wpa_cli.c    |   30 +++++++++++++++++++-----
 2 files changed, 74 insertions(+), 10 deletions(-)

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 4ebc3a1..7d3c0fa 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -8488,9 +8488,11 @@ static int wpa_supplicant_global_iface_add(struct wpa_global *global,
 {
 	struct wpa_interface iface;
 	char *pos;
+	int create_iface = 0;
+	u8 mac_addr[ETH_ALEN];

 	/*
-	 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
+	 * <ifname>TAB[<create>TAB]<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
 	 * TAB<bridge_ifname>
 	 */
 	wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
@@ -8507,6 +8509,15 @@ static int wpa_supplicant_global_iface_add(struct wpa_global *global,
 		if (pos == NULL)
 			break;

+		if (os_strncmp(pos, "create", 6) == 0) {
+			create_iface = 1;
+			pos = os_strchr(pos, '\t');
+			if (pos)
+				pos++;
+			if (pos == NULL)
+				break;
+		}
+
 		iface.confname = pos;
 		pos = os_strchr(pos, '\t');
 		if (pos)
@@ -8553,6 +8564,19 @@ static int wpa_supplicant_global_iface_add(struct wpa_global *global,
 			break;
 	} while (0);

+	if (create_iface) {
+		wpa_printf(MSG_DEBUG, "CTRL_IFACE Creating interface '%s'", iface.ifname);
+		if (wpa_drv_if_add(global->ifaces, WPA_IF_STATION, iface.ifname,
+			NULL, NULL, NULL , mac_addr, NULL) < 0)
+		{
+			wpa_printf(MSG_ERROR, "CTRL_IFACE Interface creation failed");
+			return -1;
+		}
+
+		wpa_printf(MSG_DEBUG, "CTRL_IFACE Interface '%s' is created with mac addr:" MACSTR,
+			iface.ifname, MAC2STR(mac_addr));
+	}
+
 	if (wpa_supplicant_get_iface(global, iface.ifname))
 		return -1;

@@ -8564,13 +8588,35 @@ static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
 					      char *cmd)
 {
 	struct wpa_supplicant *wpa_s;
+	int ret;
+	char *ifname;
+	char *pos;
+	int delete_iface = 0;
+
+	wpa_printf(MSG_ERROR, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
+
+	/*
+	 * <ifname>TAB[<delete>]
+	 */
+	ifname = cmd;
+	pos = os_strchr(cmd, '\t');
+	if (pos)
+	    *pos++ = '\0';

-	wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
+	if (os_strstr(pos, "delete")) {
+		/* Interface need to be deleted after de-initialization */
+		delete_iface = 1;
+	}

-	wpa_s = wpa_supplicant_get_iface(global, cmd);
+	wpa_s = wpa_supplicant_get_iface(global, ifname);
 	if (wpa_s == NULL)
 		return -1;
-	return wpa_supplicant_remove_iface(global, wpa_s, 0);
+	ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
+	if (!ret && delete_iface) {
+		wpa_printf(MSG_DEBUG, "CTRL_IFACE Deleting the interface '%s'", ifname);
+		ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, ifname);
+	}
+	return ret;
 }


diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index 2b40bbf..5557e45 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -1710,22 +1710,22 @@ static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
 	if (argc < 1) {
 		printf("Invalid INTERFACE_ADD command: needs at least one "
 		       "argument (interface name)\n"
-		       "All arguments: ifname confname driver ctrl_interface "
+		       "All arguments: ifname [create] confname driver ctrl_interface "
 		       "driver_param bridge_name\n");
 		return -1;
 	}

 	/*
-	 * INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
+	 * INTERFACE_ADD <ifname>TAB[<create>TAB]<confname>TAB<driver>TAB<ctrl_interface>TAB
 	 * <driver_param>TAB<bridge_name>
 	 */
 	res = os_snprintf(cmd, sizeof(cmd),
-			  "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s",
+			  "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s\t%s",
 			  argv[0],
 			  argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "",
 			  argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "",
-			  argc > 5 ? argv[5] : "");
-	if (os_snprintf_error(sizeof(cmd), res))
+			  argc > 5 ? argv[5] : "", argc > 6 ? argv[6] : "");
+	if (res < 0 || (size_t) res >= sizeof(cmd))
 		return -1;
 	cmd[sizeof(cmd) - 1] = '\0';
 	return wpa_ctrl_command(ctrl, cmd);
@@ -1735,7 +1735,25 @@ static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
 static int wpa_cli_cmd_interface_remove(struct wpa_ctrl *ctrl, int argc,
 					char *argv[])
 {
-	return wpa_cli_cmd(ctrl, "INTERFACE_REMOVE", 1, argc, argv);
+	char cmd[256];
+	int res;
+
+	if (argc < 1) {
+		printf("Invalid INTERFACE_REMOVE command: needs at least one "
+		       "argument (interface name)\n");
+		return -1;
+	}
+	/*
+	 * INTERFACE_REMOVE <ifname>[TAB<delete>]
+	 */
+	res = os_snprintf(cmd, sizeof(cmd),
+			  "INTERFACE_REMOVE %s\t%s",
+			  argv[0],
+			  argc > 1 ? argv[1] : "");
+	if (res < 0 || (size_t) res >= sizeof(cmd))
+		return -1;
+	cmd[sizeof(cmd) - 1] = '\0';
+	return wpa_ctrl_command(ctrl, cmd);
 }


--
1.7.9.5




More information about the Hostap mailing list