hostapd: mesh: make forwarding configurable
[oweals/openwrt.git] / package / network / services / hostapd / patches / 021-mesh-make-forwarding-configurable.patch
1 From d11881c1ad0d6a102962d1a040a398f597256ae0 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Wed, 18 Apr 2018 19:24:31 +0200
4 Subject: [PATCH] mesh: make forwarding configurable
5 To: hostap@lists.infradead.org
6 Cc: Jouni Malinen <j@w1.fi>,
7     Johannes Berg <johannes.berg@intel.com>
8
9 Allow mesh_fwding to be specified in a mesh bss config, pass that
10 to the driver (only nl80211 implemented for now) and announce
11 forwarding capability accordingly.
12
13 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
14 ---
15  src/ap/ap_config.h                 | 2 ++
16  src/drivers/driver.h               | 2 ++
17  src/drivers/driver_nl80211.c       | 3 +++
18  wpa_supplicant/config.c            | 4 ++++
19  wpa_supplicant/config.h            | 3 +++
20  wpa_supplicant/config_file.c       | 4 ++++
21  wpa_supplicant/config_ssid.h       | 5 +++++
22  wpa_supplicant/mesh.c              | 6 ++++++
23  wpa_supplicant/mesh_mpm.c          | 4 ++--
24  wpa_supplicant/wpa_supplicant.conf | 6 ++++++
25  10 files changed, 37 insertions(+), 2 deletions(-)
26
27 diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
28 index 03ab80d43..804385e93 100644
29 --- a/src/ap/ap_config.h
30 +++ b/src/ap/ap_config.h
31 @@ -49,6 +49,7 @@ struct mesh_conf {
32         int dot11MeshRetryTimeout; /* msec */
33         int dot11MeshConfirmTimeout; /* msec */
34         int dot11MeshHoldingTimeout; /* msec */
35 +       int mesh_fwding;
36  };
37  
38  #define MAX_STA_COUNT 2007
39 @@ -612,6 +613,7 @@ struct hostapd_bss_config {
40  
41  #define MESH_ENABLED BIT(0)
42         int mesh;
43 +       int mesh_fwding;
44  
45         u8 radio_measurements[RRM_CAPABILITIES_IE_LEN];
46  
47 diff --git a/src/drivers/driver.h b/src/drivers/driver.h
48 index 6c9245584..7f1ec3697 100644
49 --- a/src/drivers/driver.h
50 +++ b/src/drivers/driver.h
51 @@ -1363,6 +1363,7 @@ struct wpa_driver_mesh_bss_params {
52  #define WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS       0x00000004
53  #define WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE           0x00000008
54  #define WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD       0x00000010
55 +#define WPA_DRIVER_MESH_CONF_FLAG_FORWARDING           0x00000020
56         /*
57          * TODO: Other mesh configuration parameters would go here.
58          * See NL80211_MESHCONF_* for all the mesh config parameters.
59 @@ -1372,6 +1373,7 @@ struct wpa_driver_mesh_bss_params {
60         int peer_link_timeout;
61         int max_peer_links;
62         int rssi_threshold;
63 +       int forwarding;
64         u16 ht_opmode;
65  };
66  
67 diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
68 index e9cb4ae2f..f3de61886 100644
69 --- a/src/drivers/driver_nl80211.c
70 +++ b/src/drivers/driver_nl80211.c
71 @@ -9197,6 +9197,9 @@ static int nl80211_put_mesh_config(struct nl_msg *msg,
72         if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
73              nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
74                         params->auto_plinks)) ||
75 +           ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_FORWARDING) &&
76 +            nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
77 +                       params->forwarding)) ||
78             ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) &&
79              nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
80                          params->max_peer_links)) ||
81 diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c
82 index a0b8cd007..0212e3f86 100644
83 --- a/wpa_supplicant/config.c
84 +++ b/wpa_supplicant/config.c
85 @@ -2211,6 +2211,7 @@ static const struct parse_data ssid_fields[] = {
86  #ifdef CONFIG_MESH
87         { INT_RANGE(mode, 0, 5) },
88         { INT_RANGE(no_auto_peer, 0, 1) },
89 +       { INT_RANGE(mesh_fwding, 0, 1) },
90         { INT_RANGE(mesh_rssi_threshold, -255, 1) },
91  #else /* CONFIG_MESH */
92         { INT_RANGE(mode, 0, 4) },
93 @@ -2757,6 +2758,7 @@ void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
94         ssid->dot11MeshRetryTimeout = DEFAULT_MESH_RETRY_TIMEOUT;
95         ssid->dot11MeshConfirmTimeout = DEFAULT_MESH_CONFIRM_TIMEOUT;
96         ssid->dot11MeshHoldingTimeout = DEFAULT_MESH_HOLDING_TIMEOUT;
97 +       ssid->mesh_fwding = DEFAULT_MESH_FWDING;
98         ssid->mesh_rssi_threshold = DEFAULT_MESH_RSSI_THRESHOLD;
99  #endif /* CONFIG_MESH */
100  #ifdef CONFIG_HT_OVERRIDES
101 @@ -3886,6 +3888,7 @@ struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface,
102         config->user_mpm = DEFAULT_USER_MPM;
103         config->max_peer_links = DEFAULT_MAX_PEER_LINKS;
104         config->mesh_max_inactivity = DEFAULT_MESH_MAX_INACTIVITY;
105 +       config->mesh_fwding = DEFAULT_MESH_FWDING;
106         config->dot11RSNASAERetransPeriod =
107                 DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD;
108         config->fast_reauth = DEFAULT_FAST_REAUTH;
109 @@ -4508,6 +4511,7 @@ static const struct global_parse_data global_fields[] = {
110         { INT(user_mpm), 0 },
111         { INT_RANGE(max_peer_links, 0, 255), 0 },
112         { INT(mesh_max_inactivity), 0 },
113 +       { INT_RANGE(mesh_fwding, 0, 1), 0 },
114         { INT(dot11RSNASAERetransPeriod), 0 },
115  #endif /* CONFIG_MESH */
116         { INT(disable_scan_offload), 0 },
117 diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h
118 index 05c4f8fb9..491d8aa5c 100644
119 --- a/wpa_supplicant/config.h
120 +++ b/wpa_supplicant/config.h
121 @@ -18,6 +18,7 @@
122  #define DEFAULT_USER_MPM 1
123  #define DEFAULT_MAX_PEER_LINKS 99
124  #define DEFAULT_MESH_MAX_INACTIVITY 300
125 +#define DEFAULT_MESH_FWDING 1
126  /*
127   * The default dot11RSNASAERetransPeriod is defined as 40 ms in the standard,
128   * but use 1000 ms in practice to avoid issues on low power CPUs.
129 @@ -1269,6 +1270,8 @@ struct wpa_config {
130          */
131         int mesh_max_inactivity;
132  
133 +       int mesh_fwding;
134 +
135         /**
136          * dot11RSNASAERetransPeriod - Timeout to retransmit SAE Auth frame
137          *
138 diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c
139 index 5a7186961..c4112b3ff 100644
140 --- a/wpa_supplicant/config_file.c
141 +++ b/wpa_supplicant/config_file.c
142 @@ -816,6 +816,7 @@ static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid)
143  #endif /* IEEE8021X_EAPOL */
144         INT(mode);
145         INT(no_auto_peer);
146 +       INT(mesh_fwding);
147         INT(frequency);
148         INT(fixed_freq);
149  #ifdef CONFIG_ACS
150 @@ -1433,6 +1434,9 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
151                 fprintf(f, "mesh_max_inactivity=%d\n",
152                         config->mesh_max_inactivity);
153  
154 +       if (config->mesh_fwding != DEFAULT_MESH_FWDING)
155 +               fprintf(f, "mesh_fwding=%d\n", config->mesh_fwding);
156 +
157         if (config->dot11RSNASAERetransPeriod !=
158             DEFAULT_DOT11_RSNA_SAE_RETRANS_PERIOD)
159                 fprintf(f, "dot11RSNASAERetransPeriod=%d\n",
160 diff --git a/wpa_supplicant/config_ssid.h b/wpa_supplicant/config_ssid.h
161 index 87a45c435..24d1848e0 100644
162 --- a/wpa_supplicant/config_ssid.h
163 +++ b/wpa_supplicant/config_ssid.h
164 @@ -492,6 +492,11 @@ struct wpa_ssid {
165         int dot11MeshConfirmTimeout; /* msec */
166         int dot11MeshHoldingTimeout; /* msec */
167  
168 +       /**
169 +        * Mesh network layer-2 forwarding
170 +        */
171 +       int mesh_fwding;
172 +
173         int ht;
174         int ht40;
175  
176 diff --git a/wpa_supplicant/mesh.c b/wpa_supplicant/mesh.c
177 index 3c2ee97da..22c10a015 100644
178 --- a/wpa_supplicant/mesh.c
179 +++ b/wpa_supplicant/mesh.c
180 @@ -121,6 +121,7 @@ static struct mesh_conf * mesh_config_create(struct wpa_supplicant *wpa_s,
181         conf->mesh_cc_id = 0;
182         conf->mesh_sp_id = MESH_SYNC_METHOD_NEIGHBOR_OFFSET;
183         conf->mesh_auth_id = (conf->security & MESH_CONF_SEC_AUTH) ? 1 : 0;
184 +       conf->mesh_fwding = ssid->mesh_fwding;
185         conf->dot11MeshMaxRetries = ssid->dot11MeshMaxRetries;
186         conf->dot11MeshRetryTimeout = ssid->dot11MeshRetryTimeout;
187         conf->dot11MeshConfirmTimeout = ssid->dot11MeshConfirmTimeout;
188 @@ -254,6 +255,7 @@ static int wpa_supplicant_mesh_init(struct wpa_supplicant *wpa_s,
189         bss->conf->start_disabled = 1;
190         bss->conf->mesh = MESH_ENABLED;
191         bss->conf->ap_max_inactivity = wpa_s->conf->mesh_max_inactivity;
192 +       bss->conf->mesh_fwding = wpa_s->conf->mesh_fwding;
193  
194         if (ieee80211_is_dfs(ssid->frequency) && wpa_s->conf->country[0]) {
195                 conf->ieee80211h = 1;
196 @@ -506,6 +508,10 @@ int wpa_supplicant_join_mesh(struct wpa_supplicant *wpa_s,
197         }
198         params->conf.peer_link_timeout = wpa_s->conf->mesh_max_inactivity;
199  
200 +       /* always explicitely set forwarding to on or off for now */
201 +       params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_FORWARDING;
202 +       params->conf.forwarding = ssid->mesh_fwding;
203 +
204         wpa_s->mesh_params = params;
205         if (wpa_supplicant_mesh_init(wpa_s, ssid, &params->freq)) {
206                 wpa_msg(wpa_s, MSG_ERROR, "Failed to init mesh");
207 diff --git a/wpa_supplicant/mesh_mpm.c b/wpa_supplicant/mesh_mpm.c
208 index bc3cc5ef9..e7058e646 100644
209 --- a/wpa_supplicant/mesh_mpm.c
210 +++ b/wpa_supplicant/mesh_mpm.c
211 @@ -288,9 +288,9 @@ static void mesh_mpm_send_plink_action(struct wpa_supplicant *wpa_s,
212                 info = (bss->num_plinks > 63 ? 63 : bss->num_plinks) << 1;
213                 /* TODO: Add Connected to Mesh Gate/AS subfields */
214                 wpabuf_put_u8(buf, info);
215 -               /* always forwarding & accepting plinks for now */
216 +               /* set forwarding & always accepting plinks for now */
217                 wpabuf_put_u8(buf, MESH_CAP_ACCEPT_ADDITIONAL_PEER |
218 -                             MESH_CAP_FORWARDING);
219 +                             (conf->mesh_fwding ? MESH_CAP_FORWARDING : 0));
220         } else {        /* Peer closing frame */
221                 /* IE: Mesh ID */
222                 wpabuf_put_u8(buf, WLAN_EID_MESH_ID);
223 diff --git a/wpa_supplicant/wpa_supplicant.conf b/wpa_supplicant/wpa_supplicant.conf
224 index 972e7e73d..e1c475f37 100644
225 --- a/wpa_supplicant/wpa_supplicant.conf
226 +++ b/wpa_supplicant/wpa_supplicant.conf
227 @@ -153,6 +153,12 @@ ap_scan=1
228  # This timeout value is used in mesh STA to clean up inactive stations.
229  #mesh_max_inactivity=300
230  
231 +# Enable 802.11s layer-2 routing and forwarding
232 +#mesh_fwding=1
233 +
234 +# Accept additional peer links
235 +#mesh_auto_open_plinks=1
236 +
237  # cert_in_cb - Whether to include a peer certificate dump in events
238  # This controls whether peer certificates for authentication server and
239  # its certificate chain are included in EAP peer certificate events. This is
240 -- 
241 2.17.0
242