diff mbox

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

Message ID 909127a1966ae326e33daad587b39d2ad7d6960e.1426847720.git.jithu@broadcom.com
State Accepted
Headers show

Commit Message

Jithu Jance March 20, 2015, 10:39 a.m. UTC
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@broadcom.com>
---
 wpa_supplicant/ctrl_iface.c |   54 +++++++++++++++++++++++++++++++++++++++----
 wpa_supplicant/wpa_cli.c    |   30 +++++++++++++++++++-----
 2 files changed, 74 insertions(+), 10 deletions(-)

--
1.7.9.5

Comments

Jouni Malinen March 26, 2015, 9:21 p.m. UTC | #1
On Fri, Mar 20, 2015 at 04:09:50PM +0530, Jithu Jance wrote:
> 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)

Thanks, I applied this with number of changes.

> -	 * <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>

This does not work very well since "create" is a valid prefix for the
existing confname parameter. I moved "TAB<create>" to the end of the
command.

> @@ -8564,13 +8588,35 @@ static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
> +	 * <ifname>TAB[<delete>]

And this does not look desired, so I replaced the addition here by
tracking whether the vif was added (that "create" parameter on the add
command).
Jithu Jance March 27, 2015, 9:41 a.m. UTC | #2
> Thanks, I applied this with number of changes.
> so I replaced the addition here by
tracking whether the vif was added (that "create" parameter on the add
command).
This looks better. Thanks Jouni!



*- JJ*



On Fri, Mar 27, 2015 at 2:51 AM, Jouni Malinen <j@w1.fi> wrote:

> On Fri, Mar 20, 2015 at 04:09:50PM +0530, Jithu Jance wrote:
> > 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)
>
> Thanks, I applied this with number of changes.
>
> > -      *
> <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>
>
> This does not work very well since "create" is a valid prefix for the
> existing confname parameter. I moved "TAB<create>" to the end of the
> command.
>
> > @@ -8564,13 +8588,35 @@ static int
> wpa_supplicant_global_iface_remove(struct wpa_global *global,
> > +      * <ifname>TAB[<delete>]
>
> And this does not look desired, so I replaced the addition here by
> tracking whether the vif was added (that "create" parameter on the add
> command).
>
> --
> Jouni Malinen                                            PGP id EFC895FA
> _______________________________________________
> HostAP mailing list
> HostAP@lists.shmoo.com
> http://lists.shmoo.com/mailman/listinfo/hostap
>
diff mbox

Patch

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