]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
AP: Add support for setting bridge port attributes
authorKyeyoon Park <kyeyoonp@qca.qualcomm.com>
Fri, 26 Sep 2014 04:04:43 +0000 (21:04 -0700)
committerJouni Malinen <j@w1.fi>
Mon, 27 Oct 2014 23:08:29 +0000 (01:08 +0200)
This allows setting a bridge port attribute. Specifically, the bridge
port in this context is the port to which the BSS belongs.

This commit adds the needed functionality in driver_nl80211.c for the
Linux bridge implementation. In theory, this could be shared with
multiple Linux driver interfaces, but for now, only the main nl80211
interface is supported.

Signed-off-by: Kyeyoon Park <kyeyoonp@qca.qualcomm.com>
src/ap/ap_drv_ops.h
src/drivers/driver.h
src/drivers/driver_nl80211.c

index 53033501e836741ad5ecb90e1aea1ec033dca7ac..7cea317a09eaf96e0ee478baff5c229e6d91dd60 100644 (file)
@@ -300,6 +300,16 @@ static inline int hostapd_drv_br_delete_ip_neigh(struct hostapd_data *hapd,
        return hapd->driver->br_delete_ip_neigh(hapd->drv_priv, ipaddr);
 }
 
+static inline int hostapd_drv_br_port_set_attr(struct hostapd_data *hapd,
+                                              enum drv_br_port_attr attr,
+                                              unsigned int val)
+{
+       if (hapd->driver == NULL || hapd->drv_priv == NULL ||
+           hapd->driver->br_port_set_attr == NULL)
+               return -1;
+       return hapd->driver->br_port_set_attr(hapd->drv_priv, attr, val);
+}
+
 static inline int hostapd_drv_vendor_cmd(struct hostapd_data *hapd,
                                         int vendor_id, int subcmd,
                                         const u8 *data, size_t data_len,
index 78db6a11ecc6bba0da32febc18fcd93946ff22d1..4c9bbc8a8f1f8e68aa9075c27b61e121d75afd78 100644 (file)
@@ -1373,6 +1373,11 @@ struct macsec_init_params {
 };
 #endif /* CONFIG_MACSEC */
 
+enum drv_br_port_attr {
+       DRV_BR_PORT_ATTR_PROXYARP,
+       DRV_BR_PORT_ATTR_HAIRPIN_MODE,
+};
+
 
 /**
  * struct wpa_driver_ops - Driver interface API definition
@@ -2619,6 +2624,15 @@ struct wpa_driver_ops {
         */
        int (*br_delete_ip_neigh)(void *priv, be32 ipaddr);
 
+       /**
+        * br_port_set_attr - Set a bridge port attribute
+        * @attr: Bridge port attribute to set
+        * @val: Value to be set
+        * Returns: 0 on success, negative (<0) on failure
+        */
+       int (*br_port_set_attr)(void *priv, enum drv_br_port_attr attr,
+                               unsigned int val);
+
        /**
         * set_wowlan - Set wake-on-wireless triggers
         * @priv: Private driver interface data
index 4ffb313c377ec3b124aaab845101a41f2e4451e7..d40a44aeb5b88616cd0115f513fac5027efb2f4a 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "includes.h"
 #include <sys/types.h>
+#include <fcntl.h>
 #include <net/if.h>
 #include <netlink/genl/genl.h>
 #include <netlink/genl/ctrl.h>
@@ -8974,6 +8975,66 @@ errout:
 }
 
 
+static int linux_write_system_file(const char *path, unsigned int val)
+{
+       char buf[50];
+       int fd, len;
+
+       len = os_snprintf(buf, sizeof(buf), "%u\n", val);
+       if (len < 0)
+               return -1;
+
+       fd = open(path, O_WRONLY);
+       if (fd < 0)
+               return -1;
+
+       if (write(fd, buf, len) < 0) {
+               wpa_printf(MSG_DEBUG,
+                          "nl80211: Failed to write Linux system file: %s with the value of %d",
+                          path, val);
+               close(fd);
+               return -1;
+       }
+       close(fd);
+
+       return 0;
+}
+
+
+static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
+{
+       switch (attr) {
+       case DRV_BR_PORT_ATTR_PROXYARP:
+               return "proxyarp";
+       case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
+               return "hairpin_mode";
+       }
+
+       return NULL;
+}
+
+
+static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
+                                      unsigned int val)
+{
+       struct i802_bss *bss = priv;
+       char path[128];
+       const char *attr_txt;
+
+       attr_txt = drv_br_port_attr_str(attr);
+       if (attr_txt == NULL)
+               return -EINVAL;
+
+       os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
+                   bss->ifname, attr_txt);
+
+       if (linux_write_system_file(path, val))
+               return -1;
+
+       return 0;
+}
+
+
 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
        .name = "nl80211",
        .desc = "Linux nl80211/cfg80211",
@@ -9074,4 +9135,5 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
 #endif /* CONFIG_MESH */
        .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
        .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
+       .br_port_set_attr = wpa_driver_br_port_set_attr,
 };