[PATCH 1/1] STA: Add support for Virtual Interface creation/deletion
Jithu Jance
jithu
Fri Mar 20 03:08:32 PDT 2015
Hi Jouni,
>>> 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 +++++++++++++++++++++++++++++++++++++++----
1 file changed, 50 insertions(+), 4 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;
}
--
1.7.9.5
More information about the Hostap
mailing list