1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Wed, 28 Jul 2021 05:49:46 +0200
3 Subject: [PATCH] driver_nl80211: rewrite neigh code to not depend on
6 Removes an unnecessary dependency and also makes the code smaller
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 --- a/src/drivers/driver_nl80211.c
12 +++ b/src/drivers/driver_nl80211.c
15 #include <netlink/genl/genl.h>
16 #include <netlink/genl/ctrl.h>
17 -#ifdef CONFIG_LIBNL3_ROUTE
18 -#include <netlink/route/neighbour.h>
19 -#endif /* CONFIG_LIBNL3_ROUTE */
20 #include <linux/rtnetlink.h>
21 #include <netpacket/packet.h>
22 #include <linux/errqueue.h>
23 @@ -5783,26 +5780,29 @@ fail:
25 static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
27 -#ifdef CONFIG_LIBNL3_ROUTE
28 struct wpa_driver_nl80211_data *drv = bss->drv;
29 - struct rtnl_neigh *rn;
30 - struct nl_addr *nl_addr;
31 + struct ndmsg nhdr = {
32 + .ndm_state = NUD_PERMANENT,
33 + .ndm_ifindex = bss->ifindex,
34 + .ndm_family = AF_BRIDGE,
39 - rn = rtnl_neigh_alloc();
41 + msg = nlmsg_alloc_simple(RTM_DELNEIGH, NLM_F_CREATE);
45 - rtnl_neigh_set_family(rn, AF_BRIDGE);
46 - rtnl_neigh_set_ifindex(rn, bss->ifindex);
47 - nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
52 - rtnl_neigh_set_lladdr(rn, nl_addr);
53 + if (nlmsg_append(msg, &nhdr, sizeof(nhdr), NLMSG_ALIGNTO) < 0)
56 + if (nla_put(msg, NDA_LLADDR, ETH_ALEN, (void *)addr))
59 + if (nl_send_auto_complete(drv->rtnl_sk, msg) < 0)
62 - err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
63 + err = nl_wait_for_ack(drv->rtnl_sk);
65 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
66 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
67 @@ -5812,9 +5812,8 @@ static void rtnl_neigh_delete_fdb_entry(
68 MACSTR, MAC2STR(addr));
71 - nl_addr_put(nl_addr);
73 -#endif /* CONFIG_LIBNL3_ROUTE */
79 @@ -8492,7 +8491,6 @@ static void *i802_init(struct hostapd_da
80 (params->num_bridge == 0 || !params->bridge[0]))
81 add_ifidx(drv, br_ifindex, drv->ifindex);
83 -#ifdef CONFIG_LIBNL3_ROUTE
84 if (bss->added_if_into_bridge || bss->already_in_bridge) {
87 @@ -8509,7 +8507,6 @@ static void *i802_init(struct hostapd_da
91 -#endif /* CONFIG_LIBNL3_ROUTE */
93 if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
95 @@ -11843,13 +11840,14 @@ static int wpa_driver_br_add_ip_neigh(vo
96 const u8 *ipaddr, int prefixlen,
99 -#ifdef CONFIG_LIBNL3_ROUTE
100 struct i802_bss *bss = priv;
101 struct wpa_driver_nl80211_data *drv = bss->drv;
102 - struct rtnl_neigh *rn;
103 - struct nl_addr *nl_ipaddr = NULL;
104 - struct nl_addr *nl_lladdr = NULL;
105 - int family, addrsize;
106 + struct ndmsg nhdr = {
107 + .ndm_state = NUD_PERMANENT,
108 + .ndm_ifindex = bss->br_ifindex,
110 + struct nl_msg *msg;
114 if (!ipaddr || prefixlen == 0 || !addr)
115 @@ -11868,85 +11866,66 @@ static int wpa_driver_br_add_ip_neigh(vo
120 + nhdr.ndm_family = AF_INET;
122 } else if (version == 6) {
124 + nhdr.ndm_family = AF_INET6;
130 - rn = rtnl_neigh_alloc();
132 + msg = nlmsg_alloc_simple(RTM_NEWNEIGH, NLM_F_CREATE);
136 - /* set the destination ip address for neigh */
137 - nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
138 - if (nl_ipaddr == NULL) {
139 - wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
142 + if (nlmsg_append(msg, &nhdr, sizeof(nhdr), NLMSG_ALIGNTO) < 0)
145 - nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
146 - res = rtnl_neigh_set_dst(rn, nl_ipaddr);
148 - wpa_printf(MSG_DEBUG,
149 - "nl80211: neigh set destination addr failed");
151 + if (nla_put(msg, NDA_DST, addrsize, (void *)ipaddr))
155 - /* set the corresponding lladdr for neigh */
156 - nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
157 - if (nl_lladdr == NULL) {
158 - wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
160 + if (nla_put(msg, NDA_LLADDR, ETH_ALEN, (void *)addr))
163 - rtnl_neigh_set_lladdr(rn, nl_lladdr);
165 - rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
166 - rtnl_neigh_set_state(rn, NUD_PERMANENT);
167 + res = nl_send_auto_complete(drv->rtnl_sk, msg);
171 - res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
172 + res = nl_wait_for_ack(drv->rtnl_sk);
174 wpa_printf(MSG_DEBUG,
175 "nl80211: Adding bridge ip neigh failed: %s",
180 - nl_addr_put(nl_lladdr);
182 - nl_addr_put(nl_ipaddr);
184 - rtnl_neigh_put(rn);
187 -#else /* CONFIG_LIBNL3_ROUTE */
189 -#endif /* CONFIG_LIBNL3_ROUTE */
193 static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
196 -#ifdef CONFIG_LIBNL3_ROUTE
197 struct i802_bss *bss = priv;
198 struct wpa_driver_nl80211_data *drv = bss->drv;
199 - struct rtnl_neigh *rn;
200 - struct nl_addr *nl_ipaddr;
201 - int family, addrsize;
202 + struct ndmsg nhdr = {
203 + .ndm_state = NUD_PERMANENT,
204 + .ndm_ifindex = bss->br_ifindex,
206 + struct nl_msg *msg;
215 + nhdr.ndm_family = AF_INET;
217 } else if (version == 6) {
219 + nhdr.ndm_family = AF_INET6;
223 @@ -11964,41 +11943,30 @@ static int wpa_driver_br_delete_ip_neigh
227 - rn = rtnl_neigh_alloc();
229 + msg = nlmsg_alloc_simple(RTM_DELNEIGH, NLM_F_CREATE);
233 - /* set the destination ip address for neigh */
234 - nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
235 - if (nl_ipaddr == NULL) {
236 - wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
239 + if (nlmsg_append(msg, &nhdr, sizeof(nhdr), NLMSG_ALIGNTO) < 0)
242 - res = rtnl_neigh_set_dst(rn, nl_ipaddr);
244 - wpa_printf(MSG_DEBUG,
245 - "nl80211: neigh set destination addr failed");
247 + if (nla_put(msg, NDA_DST, addrsize, (void *)ipaddr))
251 - rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
252 + res = nl_send_auto_complete(drv->rtnl_sk, msg);
256 - res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
257 + res = nl_wait_for_ack(drv->rtnl_sk);
259 wpa_printf(MSG_DEBUG,
260 "nl80211: Deleting bridge ip neigh failed: %s",
265 - nl_addr_put(nl_ipaddr);
267 - rtnl_neigh_put(rn);
270 -#else /* CONFIG_LIBNL3_ROUTE */
272 -#endif /* CONFIG_LIBNL3_ROUTE */