Re: [PATCH] batman-adv: Don't skb_split skbuffs with frag_list
On Sat, Apr 16, 2022 at 07:17:28PM +0200, Sven Eckelmann wrote: > On Saturday, 16 April 2022 16:21:19 CEST Andrew Lunn wrote: > > This is not an area of the kernel i'm very familiar with. But i'm > > wondering, is this a BATMAN specific problem, or a generic problem? > > Should the fix be in BATMAN, or the core? > > I understand what you mean. But let me cite two places which required to > operate on parts of the frag lists: > > /* If we need update frag list, we are in troubles. >* Certainly, it is possible to add an offset to skb data, >* but taking into account that pulling is expected to >* be very rare operation, it is worth to fight against >* further bloating skb head and crucify ourselves here instead. >* Pure masohism, indeed. 8)8) >*/ > > /* Misery. We are in troubles, going to mincer fragments... */ > > > And since I cannot reproduce this here at the moment, I've decided not to > start with that. O.K. The BUG_ON() should at least catch other drivers hitting the same issue, and hopefully a search engine will point to this discussion. However, i suggest you post the fix to netdev, and see what others think. Andrew
Re: [PATCH] batman-adv: Don't skb_split skbuffs with frag_list
On Sat, Apr 16, 2022 at 02:24:34PM +0200, Sven Eckelmann wrote: > The receiving interface might have used GRO to receive more fragments than > MAX_SKB_FRAGS fragments. In this case, these will not be stored in > skb_shinfo(skb)->frags but merged into the frag list. > > batman-adv relies on the function skb_split to split packets up into > multiple smaller packets which are not larger than the MTU on the outgoing > interface. But this function cannot handle frag_list entries and is only > operating on skb_shinfo(skb)->frags. If it is then still trying to split > such an skb and xmit'ing it on an interface without support for > NETIF_F_FRAGLIST then validate_xmit_skb() will try to linearize it. But > this fails due to inconsistent information and __pskb_pull_tail will > trigger a BUG_ON after skb_copy_bits() returns an error. > > In case of entries in frag_list, just linearize the skb before operating on > it with skb_split(). Hi Sven This is not an area of the kernel i'm very familiar with. But i'm wondering, is this a BATMAN specific problem, or a generic problem? Should the fix be in BATMAN, or the core? Andrew
Re: [B.A.T.M.A.N.] [PATCH 8/9] batman-adv: Change batman_adv.h license to MIT
On Thu, Nov 23, 2017 at 03:36:04PM +0100, Sven Eckelmann wrote: > Hi Andrew, > > On Sonntag, 19. November 2017 15:05:16 CET Sven Eckelmann wrote: > > The ISC license is considered as not recommended in "Linux kernel licensing > > rules". It should only be used for existing code or for importing code from > > a different project with that license. > > > > But the kernel still has the similar sounding MIT/Expat license under the > > preferred licenses. Switching to this license for this relatively new file > > should therefore allow batman-adv to better follow the new licensing rules. > > > > Signed-off-by: Sven Eckelmann > > --- > > I would ask for Acked-by from following persons > > What I wanted to say here: "I would like to get an Acked-by reply from > following persons" (thanks to Simon, Matthias and Antonio for the fast > response). Hi Sven Sorry, was not paying close enough attentions to notice you wanted my feedback. I just looked at Linus's current master branch: ~/linux/include/uapi$ grep -hr SPDX * | sort | uniq -c 14 /* SPDX-License-Identifier: GPL-1.0+ WITH Linux-syscall-note */ 541 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 113 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 1 /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) AND MIT) */ 21 /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) */ 17 /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ 4 /* SPDX-License-Identifier: ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) */ 3 /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR MIT) */ 3 /* SPDX-License-Identifier: LGPL-2.0+ WITH Linux-syscall-note */ 3 /* SPDX-License-Identifier: LGPL-2.1 WITH Linux-syscall-note */ 15 /* SPDX-License-Identifier: LGPL-2.1+ WITH Linux-syscall-note */ We are in the region of "Lies, damn lies, and statistics", but everything with an SPDX tag has some form of GPL/LGPL. Now, adding SPDX tags is a new activity, and adding the GPLs tags have been done first, since they are easier to do. So it could be there are a lot of UAPI header files which are not {L}GPL. Also, given this small sample, it seems BSD is more popular over MIT. I understand the reasons for ISC to MIT, so Acked-by: Andrew Lunn However, i wounder if GPL-2.0 WITH Linux-syscall-note OR one of the BSD variants would be more consistent with the rest of the kernel? Andrew
Re: [B.A.T.M.A.N.] wired performance
> And there is currently no special batman-adv support for the flow > dissector [1] in the kernel. This could be also a reason why multiple flows > are not distributed well to different cores when you enable RPS/XPS. It is > not > yet know whether this will actually be helpful but at least someone > interested > could do same research and implement a proof-of-concept patches for further > testing. Hi Sven DSA just added a patch to help with flow dissectors. Maybe it can be generalized and made to work for BATMAN as well? commit 43e665287f931a167cd2eea3387efda901bff0ce Author: John Crispin Date: Wed Aug 9 14:41:19 2017 +0200 net-next: dsa: fix flow dissection RPS and probably other kernel features are currently broken on some if not all DSA devices. The root cause of this is that skb_hash will call the flow_dissector. At this point the skb still contains the magic switch header and the skb->protocol field is not set up to the correct 802.3 value yet. By the time the tag specific code is called, removing the header and properly setting the protocol an invalid hash is already set. In the case of the mt7530 this will result in all flows always having the same hash.
Re: [B.A.T.M.A.N.] Interface limit 127 in bat0?!
Hi Jens The script i just used is: # add one if per 3 second and give output, also monitor dmesg dmesg -w & for i in `seq 1 255`; do # one interface ip link add gre$i type gretap local 192.168.99.1 remote 192.168.3.$i ttl 255 dev lan1 ip link set up dev gre$i batctl if add gre$i # another inf ip link add grex$i type gretap local 192.168.99.1 remote 192.168.4.$i ttl 255 dev lan1 ip link set up dev grex$i batctl if add grex$i echo -n $(uptime|cut -d"," -f4-) $(ifconfig lan1|grep TX\ p) $i sleep 3 done So this adds two interfaces per 3 seconds to bat0. root@wrt1900ac:~# batctl if grex122: active gre123: active grex123: active gre124: active grex124: active gre125: active grex125: active gre126: active ... grex119: active gre120: active grex120: active gre121: active grex121: active gre122: active root@wrt1900ac:~# batctl if | wc 344 6885116 So i have 344 interfaces in the mesh. No memory problems reported. Andrew
Re: [B.A.T.M.A.N.] Interface limit 127 in bat0?!
> |Error - can't write to file > '/sys/class/net/gre127/batman_adv/mesh_iface': Cannot allocate memory| As the message suggests, you are out of memory. This is not a BATMAN limit, it is a limit from the amount of RAM you have in your device. Andrew
Re: [B.A.T.M.A.N.] limit of if per batman
On Wed, Jan 25, 2017 at 03:21:58AM +0100, jens wrote: > On 24.01.2017 14:39, Sven Eckelmann wrote: > > There is no artificial limit added by batman-adv. But transmitting a lot of > > broadcasts over 255 virtual links sharing the same physical link > > might get interesting (independent of batman-adv). > > this made me curious , and i modified your script a bit - turns out > after the 127. IF you add to batman-adv you get an Error - > all 510 gretap links was succesfully build ... > # ifconfig |grep gre| wc -l > 515 > # batctl if|sort|wc -l > 127 > the error is mainly > *Error - can't write to file > '/sys/class/net/gre128/batman_adv/mesh_iface': Cannot allocate memory Hi Jens What sort of machine are you running this on? How much RAM does it have? My guess is, you are running it on a little box with not much RAM. If you tried again on your desktop with a few Giga byte of RAM, you will get a different limit. Andrew
[B.A.T.M.A.N.] [PATCH v7 09/11] batman-adv: add B.A.T.M.A.N. Dump gateways via netlink
Dump the list of gateways via the netlink socket. Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 8 +++ net/batman-adv/gateway_client.c | 148 net/batman-adv/gateway_client.h | 2 + net/batman-adv/netlink.c| 10 +++ 4 files changed, 168 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index a46662c..04bf8af 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -81,6 +81,9 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_NEIGH_ADDRESS: Neighbour MAC address * @BATADV_ATTR_TQ: TQ to neighbour * @BATADV_ATTR_THROUGHPUT: Estimated throughput to Neighbour + * @BATADV_ATTR_BANDWIDTH_UP: Reported uplink bandwidth + * @BATADV_ATTR_BANDWIDTH_DOWN: Reported downlink bandwidth + * @BATADV_ATTR_ROUTER: Gateway router MAC address * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -108,6 +111,9 @@ enum batadv_nl_attrs { BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, BATADV_ATTR_THROUGHPUT, + BATADV_ATTR_BANDWIDTH_UP, + BATADV_ATTR_BANDWIDTH_DOWN, + BATADV_ATTR_ROUTER, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -125,6 +131,7 @@ enum batadv_nl_attrs { * @BATADV_CMD_GET_TRANSTABLE_GLOBAL Query list of global translations * @BATADV_CMD_GET_ORIGINATORS: Query list of originators * @BATADV_CMD_GET_NEIGHBORS: Query list of neighbours + * @BATADV_CMD_GET_GATEWAYS: Query list of gateways * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -137,6 +144,7 @@ enum batadv_nl_commands { BATADV_CMD_GET_TRANSTABLE_GLOBAL, BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, + BATADV_CMD_GET_GATEWAYS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 31ba24e..9967f5e 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -39,12 +41,18 @@ #include #include #include +#include +#include +#include +#include #include "gateway_common.h" #include "hard-interface.h" +#include "netlink.h" #include "originator.h" #include "packet.h" #include "routing.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -663,6 +671,146 @@ out: } /** + * batadv_gw_dump_entry - Dump a gateway into a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @bat_priv: The bat priv with all the soft interface information + * @gw_node: Gateway to be dumped + * + * Return: Error code, or 0 on success + */ +static int +batadv_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_gw_node *gw_node) +{ + struct batadv_neigh_ifinfo *router_ifinfo = NULL; + struct batadv_neigh_node *router; + struct batadv_gw_node *curr_gw; + int ret = -EINVAL; + void *hdr; + + router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); + if (!router) + goto out; + + router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT); + if (!router_ifinfo) + goto out; + + curr_gw = batadv_gw_get_selected_gw_node(bat_priv); + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_GATEWAYS); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + ret = -EMSGSIZE; + + if (curr_gw == gw_node) + if (nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, + gw_node->orig_node->orig) || + nla_put_u8(msg, BATADV_ATTR_TQ, router_ifinfo->bat_iv.tq_avg) || + nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN, + router->addr) || + nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, + router->if_incoming->net_dev->name) || + nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN, + gw_node-&g
[B.A.T.M.A.N.] [PATCH v7 11/11] batman-adv: Indicate netlink socket can be used with netns.
Set the netnsof flag on the family structure, indicating it can be used with different network name spaces. Signed-off-by: Andrew Lunn --- net/batman-adv/netlink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 013505e..b56b8c2 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -50,6 +50,7 @@ struct genl_family batadv_netlink_family = { .name = BATADV_NL_NAME, .version = 1, .maxattr = BATADV_ATTR_MAX, + .netnsok = true, }; static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v7 10/11] batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink
Dump the list of bridge loop avoidance claims via the netlink socket. Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h| 12 +++ net/batman-adv/bridge_loop_avoidance.c | 166 + net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/netlink.c | 13 +++ 4 files changed, 200 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 04bf8af..03403d4 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -84,6 +84,11 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_BANDWIDTH_UP: Reported uplink bandwidth * @BATADV_ATTR_BANDWIDTH_DOWN: Reported downlink bandwidth * @BATADV_ATTR_ROUTER: Gateway router MAC address + * @BATADV_ATTR_BLA_OWN: Flag indicating own originator + * @BATADV_ATTR_BLA_ADDRESS: Bridge loop avoidance claim MAC address + * @BATADV_ATTR_BLA_VID: BLA VLAN ID + * @BATADV_ATTR_BLA_BACKBONE: BLA gateway originator MAC address + * @BATADV_ATTR_BLA_CRC: BLA CRC * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -114,6 +119,11 @@ enum batadv_nl_attrs { BATADV_ATTR_BANDWIDTH_UP, BATADV_ATTR_BANDWIDTH_DOWN, BATADV_ATTR_ROUTER, + BATADV_ATTR_BLA_OWN, + BATADV_ATTR_BLA_ADDRESS, + BATADV_ATTR_BLA_VID, + BATADV_ATTR_BLA_BACKBONE, + BATADV_ATTR_BLA_CRC, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -132,6 +142,7 @@ enum batadv_nl_attrs { * @BATADV_CMD_GET_ORIGINATORS: Query list of originators * @BATADV_CMD_GET_NEIGHBORS: Query list of neighbours * @BATADV_CMD_GET_GATEWAYS: Query list of gateways + * @BATADV_CMD_GET_BLA_CLAIM: Query list of bridge loop avoidance claims * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -145,6 +156,7 @@ enum batadv_nl_commands { BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, BATADV_CMD_GET_GATEWAYS, + BATADV_CMD_GET_BLA_CLAIM, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 748a9ea..99458f3 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -45,11 +46,17 @@ #include #include #include +#include +#include +#include +#include #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -1983,6 +1990,165 @@ out: } /** + * batadv_bla_claim_dump_entry - dump one entry of the backbone table + * to a netlink socket + * @msg: buffer for the message + * @portid: netlink port + * @seq: Sequence number of netlink message + * @primary_if: primary interface + * @claim: entry to dump + * + * Return: 0 or error code. + */ +static int +batadv_bla_claim_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hard_iface *primary_if, + struct batadv_bla_claim *claim) +{ + u8 *primary_addr = primary_if->net_dev->dev_addr; + u16 backbone_crc; + bool is_own; + void *hdr; + int ret = -EINVAL; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_BLA_CLAIM); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + is_own = batadv_compare_eth(claim->backbone_gw->orig, + primary_addr); + + spin_lock_bh(&claim->backbone_gw->crc_lock); + backbone_crc = claim->backbone_gw->crc; + spin_unlock_bh(&claim->backbone_gw->crc_lock); + + if (is_own) + if (nla_put_flag(msg, BATADV_ATTR_BLA_OWN)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_BLA_ADDRESS, ETH_ALEN, claim->addr) || + nla_put_u16(msg, BATADV_ATTR_BLA_VID, claim->vid) || + nla_put(msg, BATADV_ATTR_BLA_BACKBONE, ETH_ALEN, + claim->backbone_gw->orig) || + nla_put_u16(msg, BATADV_ATTR_BLA_CRC, + backbone_crc)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + genlmsg_end(msg, hdr); + ret = 0; + +out: + return re
[B.A.T.M.A.N.] [PATCH v7 08/11] batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Dump the algo V originators and neighbours. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 2 + net/batman-adv/bat_v.c | 337 net/batman-adv/netlink.c| 1 + 3 files changed, 340 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 70ea9e4..a46662c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -80,6 +80,7 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_LAST_SEEN_MSECS: Time in milliseconds since last seen * @BATADV_ATTR_NEIGH_ADDRESS: Neighbour MAC address * @BATADV_ATTR_TQ: TQ to neighbour + * @BATADV_ATTR_THROUGHPUT: Estimated throughput to Neighbour * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -106,6 +107,7 @@ enum batadv_nl_attrs { BATADV_ATTR_LAST_SEEN_MSECS, BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, + BATADV_ATTR_THROUGHPUT, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index b9c2850..8012829 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c @@ -19,24 +19,33 @@ #include "main.h" #include +#include +#include #include #include #include #include +#include #include #include #include #include #include #include +#include +#include +#include #include "bat_v_elp.h" #include "bat_v_ogm.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +struct sk_buff; + static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface) { struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); @@ -198,6 +207,136 @@ static void batadv_v_neigh_print(struct batadv_priv *bat_priv, } /** + * batadv_v_neigh_dump_neigh - Dump a neighbour into a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @hardif_neigh: Neighbour to dump + * + * Return: Error code, or 0 on success + */ +static int +batadv_v_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hardif_neigh_node *hardif_neigh) +{ + void *hdr; + unsigned int last_seen_msecs; + u32 throughput; + + last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen); + throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); + throughput = throughput * 100; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, + BATADV_CMD_GET_NEIGHBORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + hardif_neigh->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + hardif_neigh->if_incoming->net_dev->ifindex) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs) || + nla_put_u32(msg, BATADV_ATTR_THROUGHPUT, throughput)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +/** + * batadv_v_neigh_dump_hardif - Dump the neighbours of a hard interface into + * a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @bat_priv: The bat priv with all the soft interface information + * @hard_iface: The hard interface to be dumped + * @idx_s: Entries to be skipped + * + * Return: Error code, or 0 on success + */ +static int +batadv_v_neigh_dump_hardif(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *hard_iface, + int *idx_s) +{ + struct batadv_hardif_neigh_node *hardif_neigh; + int idx = 0; + + hlist_for_each_entry_rcu(hardif_neigh, +&hard_iface->neigh_list, list) { + if (idx++ < *idx_s) + continue; + + if (batadv_v_neigh_dump_neigh(msg, portid, seq, hardif_neigh)) { + *idx_s = idx - 1; + return -EMSGSIZE; + } + } + + *idx_s = 0; + return 0; +} + +/** + * batadv_v_neigh_dump - Dump the neighbours of a hard interface into a + * message + * @msg: Netlink message to
[B.A.T.M.A.N.] [PATCH v7 07/11] batman-adv: add B.A.T.M.A.N. IV bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 4 + net/batman-adv/bat_iv_ogm.c | 359 net/batman-adv/netlink.c| 2 + 3 files changed, 365 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index def3799..70ea9e4 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -78,6 +78,8 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_TT_FLAGS: Translation table client flags * @BATADV_ATTR_FLAG_BEST: Flags indicating entry is the best * @BATADV_ATTR_LAST_SEEN_MSECS: Time in milliseconds since last seen + * @BATADV_ATTR_NEIGH_ADDRESS: Neighbour MAC address + * @BATADV_ATTR_TQ: TQ to neighbour * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -102,6 +104,8 @@ enum batadv_nl_attrs { BATADV_ATTR_TT_FLAGS, BATADV_ATTR_FLAG_BEST, BATADV_ATTR_LAST_SEEN_MSECS, + BATADV_ATTR_NEIGH_ADDRESS, + BATADV_ATTR_TQ, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 4815db9..faeba72 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -48,10 +49,14 @@ #include #include #include +#include +#include +#include #include "bitarray.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "network-coding.h" #include "originator.h" #include "packet.h" @@ -1976,6 +1981,233 @@ next: } /** + * batadv_iv_ogm_neigh_get_tq_avg - Get the TQ average for a neighbour on a + * given outgoing interface. + * @neigh_node: Neighbour of interest + * @if_outgoing: Outgoing interface of interest + * @tq_avg: Pointer of where to store the TQ average + * + * Return: False if no average TQ available, otherwise true. + */ +static bool +batadv_iv_ogm_neigh_get_tq_avg(struct batadv_neigh_node *neigh_node, + struct batadv_hard_iface *if_outgoing, + u8 *tq_avg) +{ + struct batadv_neigh_ifinfo *n_ifinfo; + + n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); + if (!n_ifinfo) + return false; + + *tq_avg = n_ifinfo->bat_iv.tq_avg; + batadv_neigh_ifinfo_put(n_ifinfo); + + return true; +} + +/** + * batadv_iv_ogm_orig_dump_subentry - Dump an originator subentry into a + * message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @bat_priv: The bat priv with all the soft interface information + * @if_outgoing: Limit dump to entries with this outgoing interface + * @orig_node: Originator to dump + * @neigh_node: Single hops neighbour + * @best: Is the best originator + * + * Return: Error code, or 0 on success + */ +static int +batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_hard_iface *if_outgoing, +struct batadv_orig_node *orig_node, +struct batadv_neigh_node *neigh_node, +bool best) +{ + void *hdr; + u8 tq_avg; + unsigned int last_seen_msecs; + + last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen); + + if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node, if_outgoing, &tq_avg)) + return 0; + + if (if_outgoing != BATADV_IF_DEFAULT && + if_outgoing != neigh_node->if_incoming) + return 0; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_ORIGINATORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, + orig_node->orig) || + nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + neigh_node->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + neigh_node->if_incoming->net_dev->ifindex) || + nla_put_u8(msg, BATADV_ATTR_TQ, tq_avg) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs)) + goto nla_put_failure; + + if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) + goto nla_put_failure; + + ge
[B.A.T.M.A.N.] [PATCH v7 03/11] batman-adv: netlink: add routing_algo query
From: Matthias Schiffer BATADV_CMD_GET_ROUTING_ALGOS is used to get the list of supported routing algorithms. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn [sven.eckelm...@open-mesh.com: Reduce the number of changes to BATADV_CMD_GET_ROUTING_ALGOS] Signed-off-by: Sven Eckelmann --- compat-include/linux/netlink.h | 45 include/uapi/linux/batman_adv.h | 2 ++ net/batman-adv/main.c | 66 + net/batman-adv/main.h | 2 ++ net/batman-adv/netlink.c| 10 +-- net/batman-adv/netlink.h| 9 ++ 6 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 compat-include/linux/netlink.h diff --git a/compat-include/linux/netlink.h b/compat-include/linux/netlink.h new file mode 100644 index 000..4d0eb5b --- /dev/null +++ b/compat-include/linux/netlink.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ + +#include +#include_next + +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) + +struct batadv_netlink_skb_parms { + struct ucredcreds; /* Skb credentials */ + union { + __u32 portid; + __u32 pid; + }; + __u32 dst_group; +}; + +#undef NETLINK_CB +#define NETLINK_CB(skb) (*(struct batadv_netlink_skb_parms *)&((skb)->cb)) + +#endif /* < KERNEL_VERSION(3, 7, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ */ diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index a908140..d2a9740 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -57,12 +57,14 @@ enum batadv_nl_attrs { * * @BATADV_CMD_UNSPEC: unspecified command to catch errors * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device + * @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms. * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ enum batadv_nl_commands { BATADV_CMD_UNSPEC, BATADV_CMD_GET_MESH_INFO, + BATADV_CMD_GET_ROUTING_ALGOS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index e78b318..fe03721 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,10 @@ #include #include #include +#include +#include #include +#include #include "bat_algo.h" #include "bridge_loop_avoidance.h" @@ -612,6 +616,68 @@ int batadv_algo_seq_print_text(struct seq_file *seq, void *offset) } /** + * batadv_algo_dump_entry - fill in information about one supported routing + * algorithm + * @msg: netlink message to be sent back + * @portid: Port to reply to + * @seq: Sequence number of message + * @bat_algo_ops: Algorithm to be dumped + * + * Return: Error number, or 0 on success + */ +static int batadv_algo_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_algo_ops *bat_algo_ops) +{ + void *hdr; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_ROUTING_ALGOS); + if (!hdr) + return -EMSGSIZE; + + if (nla_put_string(msg, BATADV_ATTR_ALGO_NAME, bat_algo_ops->name)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +/** + * batadv_algo_dump - fill in information about supported routing + * algorithms + * @msg: netlink message to be sent back + * @cb: Parameters to the netlink request + * + * Return: Length of reply message. + */ +int batadv_algo_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + int portid = NETLINK_CB(cb->skb).portid; + struct batadv_algo
[B.A.T.M.A.N.] [PATCH v7 04/11] batman-adv: netlink: hardif query
From: Matthias Schiffer BATADV_CMD_GET_HARDIFS will return the list of hardifs (including index, name and MAC address) of all hardifs for a given softif. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn [sven.eckelm...@open-mesh.com: Reduce the number of changes to BATADV_CMD_GET_HARDIFS, add policy for attributes] Signed-off-by: Sven Eckelmann --- include/uapi/linux/batman_adv.h | 4 ++ net/batman-adv/netlink.c| 129 +++- 2 files changed, 131 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index d2a9740..9e7d77a 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -32,6 +32,7 @@ * @BATADV_ATTR_HARD_IFINDEX: index of the non-batman-adv interface * @BATADV_ATTR_HARD_IFNAME: name of the non-batman-adv interface * @BATADV_ATTR_HARD_ADDRESS: mac address of the non-batman-adv interface + * @BATADV_ATTR_ACTIVE: Flag indicating if the hard interface is active * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -46,6 +47,7 @@ enum batadv_nl_attrs { BATADV_ATTR_HARD_IFINDEX, BATADV_ATTR_HARD_IFNAME, BATADV_ATTR_HARD_ADDRESS, + BATADV_ATTR_ACTIVE, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -58,6 +60,7 @@ enum batadv_nl_attrs { * @BATADV_CMD_UNSPEC: unspecified command to catch errors * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device * @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms. + * @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -65,6 +68,7 @@ enum batadv_nl_commands { BATADV_CMD_UNSPEC, BATADV_CMD_GET_MESH_INFO, BATADV_CMD_GET_ROUTING_ALGOS, + BATADV_CMD_GET_HARDIFS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 717d7d0..bc4fcc2 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -26,16 +26,19 @@ #include #include #include +#include +#include +#include #include +#include #include #include +#include #include #include "hard-interface.h" #include "soft-interface.h" -struct sk_buff; - struct genl_family batadv_netlink_family = { .id = GENL_ID_GENERATE, .hdrsize = 0, @@ -53,9 +56,25 @@ static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 }, [BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING }, [BATADV_ATTR_HARD_ADDRESS] = { .len = ETH_ALEN }, + [BATADV_ATTR_ACTIVE]= { .type = NLA_FLAG }, }; /** + * batadv_netlink_get_ifindex - Extract an interface index from a message + * @nlh: Message header + * @attrtype: Attribute which holds an interface index + * + * Return: interface index, or 0. + */ +static int +batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype) +{ + struct nlattr *attr = nlmsg_find_attr(nlh, GENL_HDRLEN, attrtype); + + return attr ? nla_get_u32(attr) : 0; +} + +/** * batadv_netlink_mesh_info_put - fill in generic information about mesh * interface * @msg: netlink message to be sent back @@ -163,6 +182,106 @@ batadv_netlink_get_mesh_info(struct sk_buff *skb, struct genl_info *info) return genlmsg_reply(msg, info); } +/** + * batadv_netlink_dump_hardif_entry - Dump one hard interface into a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @hard_iface: Hard interface to dump + * + * Return: error code, or 0 on success + */ +static int +batadv_netlink_dump_hardif_entry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_hard_iface *hard_iface) +{ + struct net_device *net_dev = hard_iface->net_dev; + void *hdr; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, + BATADV_CMD_GET_HARDIFS); + if (!hdr) + return -EMSGSIZE; + + if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + net_dev->ifindex) || + nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, + net_dev->name) || + nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN, + net_dev->dev_addr)) + goto nla_put_failure; + + if (hard_iface->if_status == BATADV_IF_ACTIVE) { + if (nla_put_flag(msg, BATADV_ATT
[B.A.T.M.A.N.] [PATCH v7 06/11] batman-adv: netlink: add originator and neighbor table queries
From: Matthias Schiffer Add BATADV_CMD_GET_ORIGINATORS and BATADV_CMD_GET_NEIGHBORS commands, using handlers bat_orig_dump and bat_neigh_dump in batadv_algo_ops. Will always return -EOPNOTSUPP for now, as no implementations exist yet. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 4 + net/batman-adv/netlink.c| 13 net/batman-adv/originator.c | 160 net/batman-adv/originator.h | 4 + net/batman-adv/types.h | 9 +++ 5 files changed, 190 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 78f3584..def3799 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -117,6 +117,8 @@ enum batadv_nl_attrs { * @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces * @BATADV_CMD_GET_TRANSTABLE_LOCAL: Query list of local translations * @BATADV_CMD_GET_TRANSTABLE_GLOBAL Query list of global translations + * @BATADV_CMD_GET_ORIGINATORS: Query list of originators + * @BATADV_CMD_GET_NEIGHBORS: Query list of neighbours * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -127,6 +129,8 @@ enum batadv_nl_commands { BATADV_CMD_GET_HARDIFS, BATADV_CMD_GET_TRANSTABLE_LOCAL, BATADV_CMD_GET_TRANSTABLE_GLOBAL, + BATADV_CMD_GET_ORIGINATORS, + BATADV_CMD_GET_NEIGHBORS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index cede827..eb7a403 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -37,6 +37,7 @@ #include #include "hard-interface.h" +#include "originator.h" #include "soft-interface.h" #include "translation-table.h" @@ -323,6 +324,18 @@ static struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_tt_global_dump, }, + { + .cmd = BATADV_CMD_GET_ORIGINATORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_orig_dump, + }, + { + .cmd = BATADV_CMD_GET_NEIGHBORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_hardif_neigh_dump, + }, }; /** diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index 076d258..71b63e7 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c @@ -28,11 +28,15 @@ #include #include #include +#include #include #include +#include #include #include #include +#include +#include #include "distributed-arp-table.h" #include "fragmentation.h" @@ -40,8 +44,10 @@ #include "hard-interface.h" #include "hash.h" #include "multicast.h" +#include "netlink.h" #include "network-coding.h" #include "routing.h" +#include "soft-interface.h" #include "translation-table.h" /* hash class keys */ @@ -719,6 +725,83 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset) } /** + * batadv_hardif_neigh_dump - Dump to netlink the neighbor infos for a specific + * outgoing interface + * @msg: message to dump into + * @cb: parameters for the dump + * + * Return: 0 or error value + */ +int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + struct net *net = sock_net(cb->skb->sk); + struct net_device *soft_iface = NULL; + struct net_device *hard_iface = NULL; + struct batadv_hard_iface *hardif = BATADV_IF_DEFAULT; + struct batadv_priv *bat_priv; + struct batadv_hard_iface *primary_if = NULL; + int ret; + int ifindex, hard_ifindex; + + ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX); + if (!ifindex) + return -EINVAL; + + soft_iface = dev_get_by_index(net, ifindex); + if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { + ret = -ENODEV; + goto out; + } + + bat_priv = netdev_priv(soft_iface); + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { + ret = -ENOENT; + goto out; + } + + hard_ifindex = batadv_netlink_get_ifindex(cb->nlh, + BATADV_ATTR_HARD_IFINDEX); + if (hard_ifindex) { + hard_iface = dev_get_by_index(net, hard_ifindex); + if (hard_iface) + hardif = batadv_hardif_get_by_netdev(hard_iface); + + if (!
[B.A.T.M.A.N.] [PATCH v7 05/11] batman-adv: netlink: add translation table query
From: Matthias Schiffer This adds the commands BATADV_CMD_GET_TRANSTABLE_LOCAL and BATADV_CMD_GET_TRANSTABLE_GLOBAL, which correspond to the transtable_local and transtable_global debugfs files. The batadv_tt_client_flags enum is moved to the UAPI to expose it as part of the netlink API. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h| 58 ++ net/batman-adv/netlink.c | 24 ++- net/batman-adv/netlink.h | 1 + net/batman-adv/packet.h| 36 net/batman-adv/translation-table.c | 379 + net/batman-adv/translation-table.h | 4 + 6 files changed, 465 insertions(+), 37 deletions(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 9e7d77a..78f3584 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -21,6 +21,42 @@ #define BATADV_NL_NAME "batadv" /** + * enum batadv_tt_client_flags - TT client specific flags + * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table + * @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new + * update telling its new real location has not been received/sent yet + * @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface. + * This information is used by the "AP Isolation" feature + * @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This + * information is used by the Extended Isolation feature + * @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table + * @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has + * not been announced yet + * @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept + * in the table for one more originator interval for consistency purposes + * @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of + * the network but no nnode has already announced it + * + * Bits from 0 to 7 are called _remote flags_ because they are sent on the wire. + * Bits from 8 to 15 are called _local flags_ because they are used for local + * computations only. + * + * Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with + * the other nodes in the network. To achieve this goal these flags are included + * in the TT CRC computation. + */ +enum batadv_tt_client_flags { + BATADV_TT_CLIENT_DEL = (1 << 0), + BATADV_TT_CLIENT_ROAM= (1 << 1), + BATADV_TT_CLIENT_WIFI= (1 << 4), + BATADV_TT_CLIENT_ISOLA = (1 << 5), + BATADV_TT_CLIENT_NOPURGE = (1 << 8), + BATADV_TT_CLIENT_NEW = (1 << 9), + BATADV_TT_CLIENT_PENDING = (1 << 10), + BATADV_TT_CLIENT_TEMP= (1 << 11), +}; + +/** * enum batadv_nl_attrs - batman-adv netlink attributes * * @BATADV_ATTR_UNSPEC: unspecified attribute to catch errors @@ -33,6 +69,15 @@ * @BATADV_ATTR_HARD_IFNAME: name of the non-batman-adv interface * @BATADV_ATTR_HARD_ADDRESS: mac address of the non-batman-adv interface * @BATADV_ATTR_ACTIVE: Flag indicating if the hard interface is active + * @BATADV_ATTR_ORIG_ADDRESS: Originator MAC address + * @BATADV_ATTR_TT_ADDRESS: Client MAC address + * @BATADV_ATTR_TT_TTVN: Translation table version + * @BATADV_ATTR_TT_LAST_TTVN: Previous translation table version + * @BATADV_ATTR_TT_CRC32: CRC32 over translation table + * @BATADV_ATTR_TT_VID: VLAN ID + * @BATADV_ATTR_TT_FLAGS: Translation table client flags + * @BATADV_ATTR_FLAG_BEST: Flags indicating entry is the best + * @BATADV_ATTR_LAST_SEEN_MSECS: Time in milliseconds since last seen * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -48,6 +93,15 @@ enum batadv_nl_attrs { BATADV_ATTR_HARD_IFNAME, BATADV_ATTR_HARD_ADDRESS, BATADV_ATTR_ACTIVE, + BATADV_ATTR_ORIG_ADDRESS, + BATADV_ATTR_TT_ADDRESS, + BATADV_ATTR_TT_TTVN, + BATADV_ATTR_TT_LAST_TTVN, + BATADV_ATTR_TT_CRC32, + BATADV_ATTR_TT_VID, + BATADV_ATTR_TT_FLAGS, + BATADV_ATTR_FLAG_BEST, + BATADV_ATTR_LAST_SEEN_MSECS, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -61,6 +115,8 @@ enum batadv_nl_attrs { * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device * @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms. * @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces + * @BATADV_CMD_GET_TRANSTABLE_LOCAL: Query list of local translations + * @BATADV_CMD_GET_TRANSTABLE_GLOBAL Query list of global translations * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */
[B.A.T.M.A.N.] [PATCH v7 01/11] batman-adv: Handle parent interfaces in a different netns
batman-adv tries to prevent the user from placing a batX soft interface into another batman mesh as a hard interface. It does this by walking up the devices list of parents and ensures they are all none batX interfaces. iflink can point to an interface in a different namespace, so also retrieve the parents name space when finding the parent and use it when doing the comparison. Signed-off-by: Andrew Lunn Signed-off-by: Sven Eckelmann Acked-by: Antonio Quartulli --- compat.h| 7 ++ net/batman-adv/hard-interface.c | 50 +++-- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/compat.h b/compat.h index 7d5c8b6..fc78948 100644 --- a/compat.h +++ b/compat.h @@ -146,6 +146,13 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\ #endif /* < KERNEL_VERSION(3, 15, 0) */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) + +/* WARNING for batadv_getlink_net */ +#define get_link_net get_xstats_size || 1 || netdev->rtnl_link_ops->get_xstats_size + +#endif /* < KERNEL_VERSION(4, 0, 0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) #define IFF_NO_QUEUE 0; dev->tx_queue_len = 0 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index a8cda76..bf4ee24 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include "bridge_loop_avoidance.h" #include "debugfs.h" @@ -83,25 +85,55 @@ out: } /** + * batadv_getlink_net - return link net namespace (of use fallback) + * @netdev: net_device to check + * @fallback_net: return in case get_link_net is not available for @netdev + * + * Return: result of rtnl_link_ops->get_link_net or @fallback_net + */ +static const struct net *batadv_getlink_net(const struct net_device *netdev, + const struct net *fallback_net) +{ + if (!netdev->rtnl_link_ops) + return fallback_net; + + if (!netdev->rtnl_link_ops->get_link_net) + return fallback_net; + + return netdev->rtnl_link_ops->get_link_net(netdev); +} + +/** * batadv_mutual_parents - check if two devices are each others parent - * @dev1: 1st net_device - * @dev2: 2nd net_device + * @dev1: 1st net dev + * @net1: 1st devices netns + * @dev2: 2nd net dev + * @net2: 2nd devices netns * * veth devices come in pairs and each is the parent of the other! * * Return: true if the devices are each others parent, otherwise false */ static bool batadv_mutual_parents(const struct net_device *dev1, - const struct net_device *dev2) + const struct net *net1, + const struct net_device *dev2, + const struct net *net2) { int dev1_parent_iflink = dev_get_iflink(dev1); int dev2_parent_iflink = dev_get_iflink(dev2); + const struct net *dev1_parent_net; + const struct net *dev2_parent_net; + + dev1_parent_net = batadv_getlink_net(dev1, net1); + dev2_parent_net = batadv_getlink_net(dev2, net2); if (!dev1_parent_iflink || !dev2_parent_iflink) return false; return (dev1_parent_iflink == dev2->ifindex) && - (dev2_parent_iflink == dev1->ifindex); + (dev2_parent_iflink == dev1->ifindex) && + net_eq(dev1_parent_net, net2) && + net_eq(dev2_parent_net, net1); } /** @@ -119,8 +151,9 @@ static bool batadv_mutual_parents(const struct net_device *dev1, */ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) { - struct net_device *parent_dev; struct net *net = dev_net(net_dev); + struct net_device *parent_dev; + const struct net *parent_net; bool ret; /* check if this is a batman-adv mesh interface */ @@ -132,13 +165,16 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) dev_get_iflink(net_dev) == net_dev->ifindex) return false; + parent_net = batadv_getlink_net(net_dev, net); + /* recurse over the parent device */ - parent_dev = __dev_get_by_index(net, dev_get_iflink(net_dev)); + parent_dev = __dev_get_by_index((struct net *)parent_net, + dev_get_iflink(net_dev)); /* if we got a NULL parent_dev there is something broken.. */ if (WARN(!parent_dev, "Cannot find parent device")) return false; - if (batadv_mutual_parents(net_dev, parent_dev)) + if (batadv_mutual_parents(net_dev, net, parent_dev, parent_net)) return false; ret = batadv_is_on_batman_iface(parent_dev); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v7 02/11] batman-adv: Suppress debugfs entries for netns's
Debugfs is not netns aware. It thus has problems when the same interface name exists in multiple network name spaces. Work around this by not creating entries for interfaces in name spaces other than the default name space. This means meshes in network namespaces cannot be managed via debugfs, but there will soon be a netlink interface which is netns aware. Signed-off-by: Andrew Lunn --- net/batman-adv/debugfs.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c index f187a8f..50545b0 100644 --- a/net/batman-adv/debugfs.c +++ b/net/batman-adv/debugfs.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "bridge_loop_avoidance.h" @@ -518,12 +519,16 @@ void batadv_debugfs_destroy(void) */ int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); struct batadv_debuginfo **bat_debug; struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name, batadv_debugfs); if (!hard_iface->debug_dir) @@ -554,6 +559,11 @@ out: */ void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); + + if (net != &init_net) + return; + if (batadv_debugfs) { debugfs_remove_recursive(hard_iface->debug_dir); hard_iface->debug_dir = NULL; @@ -564,11 +574,15 @@ int batadv_debugfs_add_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); struct batadv_debuginfo **bat_debug; + struct net *net = dev_net(dev); struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); if (!bat_priv->debug_dir) goto out; @@ -605,6 +619,10 @@ out: void batadv_debugfs_del_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); + struct net *net = dev_net(dev); + + if (net != &init_net) + return; batadv_debug_log_cleanup(bat_priv); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v7 00/11] netns and netlink support
This patchset completes netns support, by disabling debugfs entries when not in the default name space, and correctly handling interface stack loops when the parent is in a different name space. It additionally adds netlink support for most of the information found in debugfs, and is netns awaire. Note: BLA is untested, so best assume it is broken... v7: Fix compat.h get_link_net() - Thanks Sven Move originator.h in netlink.c to the correct place. Andrew Lunn (5): batman-adv: Handle parent interfaces in a different netns batman-adv: Suppress debugfs entries for netns's batman-adv: add B.A.T.M.A.N. Dump gateways via netlink batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink batman-adv: Indicate netlink socket can be used with netns. Matthias Schiffer (6): batman-adv: netlink: add routing_algo query batman-adv: netlink: hardif query batman-adv: netlink: add translation table query batman-adv: netlink: add originator and neighbor table queries batman-adv: add B.A.T.M.A.N. IV bat_{orig, neigh}_dump implementations batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations compat-include/linux/netlink.h | 45 compat.h | 7 + include/uapi/linux/batman_adv.h| 94 net/batman-adv/bat_iv_ogm.c| 359 +++ net/batman-adv/bat_v.c | 337 + net/batman-adv/bridge_loop_avoidance.c | 166 +++ net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/debugfs.c | 18 ++ net/batman-adv/gateway_client.c| 148 + net/batman-adv/gateway_client.h| 2 + net/batman-adv/hard-interface.c| 50 - net/batman-adv/main.c | 66 ++ net/batman-adv/main.h | 2 + net/batman-adv/netlink.c | 201 - net/batman-adv/netlink.h | 10 + net/batman-adv/originator.c| 160 ++ net/batman-adv/originator.h| 4 + net/batman-adv/packet.h| 36 net/batman-adv/translation-table.c | 379 + net/batman-adv/translation-table.h | 4 + net/batman-adv/types.h | 9 + 21 files changed, 2059 insertions(+), 48 deletions(-) create mode 100644 compat-include/linux/netlink.h -- 2.8.0.rc3
Re: [B.A.T.M.A.N.] [PATCH v5 00/11] netns and netlink support
> headers ecsv/netlink > > > diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c > index 25fd4be..c5e6db5 100644 > --- a/net/batman-adv/bat_v.c > +++ b/net/batman-adv/bat_v.c > @@ -19,9 +19,9 @@ > #include "main.h" > > #include > +#include > #include > #include > -#include > #include > #include > #include So this is i think a false positive. Linus moved cache.h according the git blame. Nothing to do with my patch. > diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c > index 949a048..e0fd914 100644 > --- a/net/batman-adv/netlink.c > +++ b/net/batman-adv/netlink.c > @@ -36,10 +36,10 @@ > #include > #include > > -#include "originator.h" > #include "bridge_loop_avoidance.h" > #include "gateway_client.h" > #include "hard-interface.h" > +#include "originator.h" > #include "soft-interface.h" > #include "translation-table.h" This one is interesting. I copied this from your rebased_split_netlink/v4-0008-batman-adv-netlink-add-originator-and-neighbor-ta.patch I did consider changing the order, but since you wrote it that way, it must be O.K. > diff --git a/net/batman-adv/netlink.h b/net/batman-adv/netlink.h > index ef861db..fac7d91 100644 > --- a/net/batman-adv/netlink.h > +++ b/net/batman-adv/netlink.h > @@ -18,12 +18,9 @@ > #ifndef _NET_BATMAN_ADV_NETLINK_H_ > #define _NET_BATMAN_ADV_NETLINK_H_ > > #include "main.h" > > -#include > -#include > #include > -#include > > struct nlmsghdr; Another false positive. These are from: 9492a25881c75ab9910328ff27834707c83df124 which has your Signed-off-by. So overall, nothing useful in this report. Andrew
[B.A.T.M.A.N.] [PATCH] batman-adv: Fix hardif remove/add race
A hard interface can be removed and then added back in quick succession. This is particularly true for hdlc interface when changing the protocol. It is not possible it synchronously remove the sysfs and debugfs entries for the hard interface when it is removed because the files may be open. Thus removal is deferred. The files may thus already exist in sysfs and debugfs when the hard interface is re-added, and the operations fail. To fix this race, synchronously rename the debugfs and sysfs files to a unique temporary name, thus making the name available when the interface comes back, yet keeps open files still available. Signed-off-by: Andrew Lunn --- net/batman-adv/debugfs.c| 23 +++ net/batman-adv/debugfs.h| 1 + net/batman-adv/hard-interface.c | 19 +++ net/batman-adv/sysfs.c | 17 + net/batman-adv/sysfs.h | 2 ++ 5 files changed, 62 insertions(+) diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c index 50545b0..8b852aa 100644 --- a/net/batman-adv/debugfs.c +++ b/net/batman-adv/debugfs.c @@ -55,6 +55,7 @@ #include "translation-table.h" static struct dentry *batadv_debugfs; +static atomic_t batadv_rename = ATOMIC_INIT(0); #ifdef CONFIG_BATMAN_ADV_DEBUG #define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1) @@ -570,6 +571,28 @@ void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface) } } +/** + * batadv_debugfs_rename_hardif - rename the base directory + * @hard_iface: hard interface which is renamed. + * + * The interface may be removed and then quickly added back + * again. Rename the old instance to something temporary and unique, + * so avoiding a name space clash if it does reappear before the deferred + * work completes the removal. + */ +void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface) +{ + char new_name[32]; + + snprintf(new_name, sizeof(*new_name) - 1, "tmp-%d", +atomic_inc_return(&batadv_rename)); + + if (batadv_debugfs && hard_iface->debug_dir) { + debugfs_rename(batadv_debugfs, hard_iface->debug_dir, + batadv_debugfs, new_name); + } +} + int batadv_debugfs_add_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); diff --git a/net/batman-adv/debugfs.h b/net/batman-adv/debugfs.h index 1ab4e2e..e7d19c1 100644 --- a/net/batman-adv/debugfs.h +++ b/net/batman-adv/debugfs.h @@ -34,6 +34,7 @@ int batadv_debugfs_add_meshif(struct net_device *dev); void batadv_debugfs_del_meshif(struct net_device *dev); int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface); void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface); +void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface); #else diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index bf4ee24..08b62d9 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -747,6 +747,23 @@ out: return NULL; } +/** + * batadv_hardif_rename - rename the sysfs and debugfs + * @hard_iface: The hard interface to rename + * + * The sysfs and debugfs files cannot be removed until all users close + * them. So the removal is differed into a work queue. This however + * means if the interface comes back before the work queue runs, the + * files are still there, and so the create gives an EEXISTS error. To + * avoid this, rename them to a tempory name. + */ +static void batadv_hardif_rename(struct batadv_hard_iface *hard_iface) +{ + batadv_sysfs_rename_hardif(&hard_iface->hardif_obj, + hard_iface->net_dev); + batadv_debugfs_rename_hardif(hard_iface); +} + static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface) { ASSERT_RTNL(); @@ -760,6 +777,8 @@ static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface) return; hard_iface->if_status = BATADV_IF_TO_BE_REMOVED; + batadv_hardif_rename(hard_iface); + queue_work(batadv_event_workqueue, &hard_iface->cleanup_work); } diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c index 233abcf..37b0aae 100644 --- a/net/batman-adv/sysfs.c +++ b/net/batman-adv/sysfs.c @@ -47,6 +47,8 @@ #include "packet.h" #include "soft-interface.h" +static atomic_t batadv_rename = ATOMIC_INIT(0); + static struct net_device *batadv_kobj_to_netdev(struct kobject *obj) { struct device *dev = container_of(obj->parent, struct device, kobj); @@ -1045,6 +1047,21 @@ out: return -ENOMEM; } +void batadv_sysfs_rename_hardif(struct kobject **hardif_obj, + struct net_device *dev) +{ + char new_name[32]; + int err; + + snprintf(new_name, sizeof(*new_name) - 1, "tmp-%d
Re: [B.A.T.M.A.N.] [PATCH v6 01/11] batman-adv: Handle parent interfaces in a different netns
On Tue, May 17, 2016 at 02:22:29PM +0200, Sven Eckelmann wrote: > On Tuesday 17 May 2016 14:18:35 Andrew Lunn wrote: > > I'm actually getting close to the point where i'm going to give up. > > Ok, I will try to not review anything from you again. Sorry for trying to > inform you about things which would make it harder to get these patches > accepted and sent upstream. I'm quite happy to get bug reports, and now i look at, 1 is definitely correct. However, most of the rest has nothing about getting DaveM to accept the patches. Of the 120 patches i've got into mailine via DaveM, i don't remember him every complaining about indentation, or kerneldoc headers, or forward declarations. Andrew
Re: [B.A.T.M.A.N.] [PATCH v6 01/11] batman-adv: Handle parent interfaces in a different netns
> I think I removed this multiple times but this misalignment seems to be > immortal: > > > return (dev1_parent_iflink == dev2->ifindex) && > > - (dev2_parent_iflink == dev1->ifindex); > > + (dev2_parent_iflink == dev1->ifindex) && > > + net_eq(dev1_parent_net, net2) && > > + net_eq(dev2_parent_net, net1); According to checkpatch and emacs, it is also correct as it is :-) If you really want to enforce some other arbitrary white space alignment policy than checkpatch.pl, it would help if the scripts you are using are placed into ./tools, just like checkpatch.pl is. Better still, provide patches to checkpatch.pl. You should also put all your other tools there. Checkpatch mostly works because it is easily available, making it easy to push back against when people don't use it. Developing code for BATMAN is easy, but making it pass all your arbitrary style checks, header file requirements, structure forward declaration, negative value kerneldoc function headers, etc is hard and takes much much longer than developing the code. Putting these scripts at the figures of the developers, ./scripts/batadv-checkpatch.pl, and you stand a better chance of compliance. I'm actually getting close to the point where i'm going to give up. Andrew
Re: [B.A.T.M.A.N.] [PATCH v6 00/11] netns and netlink support
On Mon, May 16, 2016 at 08:58:13PM +0200, Sven Eckelmann wrote: > On Monday 16 May 2016 19:27:58 Andrew Lunn wrote: > > * No change to code indentation. I consider it a false positive. The > > code is more readable the way it is, checkpatch is happy, and it > > does not violate anything in CodingStyle, as far as i can see. > > @Antonio, @Marek, @Simon: Do you want to allow free-form alignments like this? > > if (batadv_iv_ogm_neigh_dump_hardif( > msg, portid, cb->nlh->nlmsg_seq, > bat_priv, hard_iface, &idx)) { > i_hardif--; > break; > } It is not fully free-form, however i cannot tell you exactly where it comes from. If you have emacs do auto indent, using the linux kernel indentation style, that is where emacs puts it. Andrew
[B.A.T.M.A.N.] [PATCH v6 11/11] batman-adv: Indicate netlink socket can be used with netns.
Set the netnsof flag on the family structure, indicating it can be used with different network name spaces. Signed-off-by: Andrew Lunn --- net/batman-adv/netlink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 972b4cf..e79de09 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -49,6 +49,7 @@ struct genl_family batadv_netlink_family = { .name = BATADV_NL_NAME, .version = 1, .maxattr = BATADV_ATTR_MAX, + .netnsok = true, }; static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v6 09/11] batman-adv: add B.A.T.M.A.N. Dump gateways via netlink
Dump the list of gateways via the netlink socket. Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 8 +++ net/batman-adv/gateway_client.c | 148 net/batman-adv/gateway_client.h | 2 + net/batman-adv/netlink.c| 10 +++ 4 files changed, 168 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index a46662c..04bf8af 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -81,6 +81,9 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_NEIGH_ADDRESS: Neighbour MAC address * @BATADV_ATTR_TQ: TQ to neighbour * @BATADV_ATTR_THROUGHPUT: Estimated throughput to Neighbour + * @BATADV_ATTR_BANDWIDTH_UP: Reported uplink bandwidth + * @BATADV_ATTR_BANDWIDTH_DOWN: Reported downlink bandwidth + * @BATADV_ATTR_ROUTER: Gateway router MAC address * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -108,6 +111,9 @@ enum batadv_nl_attrs { BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, BATADV_ATTR_THROUGHPUT, + BATADV_ATTR_BANDWIDTH_UP, + BATADV_ATTR_BANDWIDTH_DOWN, + BATADV_ATTR_ROUTER, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -125,6 +131,7 @@ enum batadv_nl_attrs { * @BATADV_CMD_GET_TRANSTABLE_GLOBAL Query list of global translations * @BATADV_CMD_GET_ORIGINATORS: Query list of originators * @BATADV_CMD_GET_NEIGHBORS: Query list of neighbours + * @BATADV_CMD_GET_GATEWAYS: Query list of gateways * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -137,6 +144,7 @@ enum batadv_nl_commands { BATADV_CMD_GET_TRANSTABLE_GLOBAL, BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, + BATADV_CMD_GET_GATEWAYS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 31ba24e..9967f5e 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -39,12 +41,18 @@ #include #include #include +#include +#include +#include +#include #include "gateway_common.h" #include "hard-interface.h" +#include "netlink.h" #include "originator.h" #include "packet.h" #include "routing.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -663,6 +671,146 @@ out: } /** + * batadv_gw_dump_entry - Dump a gateway into a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @bat_priv: The bat priv with all the soft interface information + * @gw_node: Gateway to be dumped + * + * Return: Error code, or 0 on success + */ +static int +batadv_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_gw_node *gw_node) +{ + struct batadv_neigh_ifinfo *router_ifinfo = NULL; + struct batadv_neigh_node *router; + struct batadv_gw_node *curr_gw; + int ret = -EINVAL; + void *hdr; + + router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); + if (!router) + goto out; + + router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT); + if (!router_ifinfo) + goto out; + + curr_gw = batadv_gw_get_selected_gw_node(bat_priv); + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_GATEWAYS); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + ret = -EMSGSIZE; + + if (curr_gw == gw_node) + if (nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, + gw_node->orig_node->orig) || + nla_put_u8(msg, BATADV_ATTR_TQ, router_ifinfo->bat_iv.tq_avg) || + nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN, + router->addr) || + nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, + router->if_incoming->net_dev->name) || + nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN, + gw_node-&g
[B.A.T.M.A.N.] [PATCH v6 10/11] batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink
Dump the list of bridge loop avoidance claims via the netlink socket. Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h| 12 +++ net/batman-adv/bridge_loop_avoidance.c | 166 + net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/netlink.c | 12 +++ 4 files changed, 199 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 04bf8af..03403d4 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -84,6 +84,11 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_BANDWIDTH_UP: Reported uplink bandwidth * @BATADV_ATTR_BANDWIDTH_DOWN: Reported downlink bandwidth * @BATADV_ATTR_ROUTER: Gateway router MAC address + * @BATADV_ATTR_BLA_OWN: Flag indicating own originator + * @BATADV_ATTR_BLA_ADDRESS: Bridge loop avoidance claim MAC address + * @BATADV_ATTR_BLA_VID: BLA VLAN ID + * @BATADV_ATTR_BLA_BACKBONE: BLA gateway originator MAC address + * @BATADV_ATTR_BLA_CRC: BLA CRC * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -114,6 +119,11 @@ enum batadv_nl_attrs { BATADV_ATTR_BANDWIDTH_UP, BATADV_ATTR_BANDWIDTH_DOWN, BATADV_ATTR_ROUTER, + BATADV_ATTR_BLA_OWN, + BATADV_ATTR_BLA_ADDRESS, + BATADV_ATTR_BLA_VID, + BATADV_ATTR_BLA_BACKBONE, + BATADV_ATTR_BLA_CRC, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -132,6 +142,7 @@ enum batadv_nl_attrs { * @BATADV_CMD_GET_ORIGINATORS: Query list of originators * @BATADV_CMD_GET_NEIGHBORS: Query list of neighbours * @BATADV_CMD_GET_GATEWAYS: Query list of gateways + * @BATADV_CMD_GET_BLA_CLAIM: Query list of bridge loop avoidance claims * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -145,6 +156,7 @@ enum batadv_nl_commands { BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, BATADV_CMD_GET_GATEWAYS, + BATADV_CMD_GET_BLA_CLAIM, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 748a9ea..99458f3 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -45,11 +46,17 @@ #include #include #include +#include +#include +#include +#include #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -1983,6 +1990,165 @@ out: } /** + * batadv_bla_claim_dump_entry - dump one entry of the backbone table + * to a netlink socket + * @msg: buffer for the message + * @portid: netlink port + * @seq: Sequence number of netlink message + * @primary_if: primary interface + * @claim: entry to dump + * + * Return: 0 or error code. + */ +static int +batadv_bla_claim_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hard_iface *primary_if, + struct batadv_bla_claim *claim) +{ + u8 *primary_addr = primary_if->net_dev->dev_addr; + u16 backbone_crc; + bool is_own; + void *hdr; + int ret = -EINVAL; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_BLA_CLAIM); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + is_own = batadv_compare_eth(claim->backbone_gw->orig, + primary_addr); + + spin_lock_bh(&claim->backbone_gw->crc_lock); + backbone_crc = claim->backbone_gw->crc; + spin_unlock_bh(&claim->backbone_gw->crc_lock); + + if (is_own) + if (nla_put_flag(msg, BATADV_ATTR_BLA_OWN)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_BLA_ADDRESS, ETH_ALEN, claim->addr) || + nla_put_u16(msg, BATADV_ATTR_BLA_VID, claim->vid) || + nla_put(msg, BATADV_ATTR_BLA_BACKBONE, ETH_ALEN, + claim->backbone_gw->orig) || + nla_put_u16(msg, BATADV_ATTR_BLA_CRC, + backbone_crc)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + genlmsg_end(msg, hdr); + ret = 0; + +out: + return re
[B.A.T.M.A.N.] [PATCH v6 08/11] batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Dump the algo V originators and neighbours. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 2 + net/batman-adv/bat_v.c | 337 net/batman-adv/netlink.c| 1 + 3 files changed, 340 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 70ea9e4..a46662c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -80,6 +80,7 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_LAST_SEEN_MSECS: Time in milliseconds since last seen * @BATADV_ATTR_NEIGH_ADDRESS: Neighbour MAC address * @BATADV_ATTR_TQ: TQ to neighbour + * @BATADV_ATTR_THROUGHPUT: Estimated throughput to Neighbour * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -106,6 +107,7 @@ enum batadv_nl_attrs { BATADV_ATTR_LAST_SEEN_MSECS, BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, + BATADV_ATTR_THROUGHPUT, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index b9c2850..8012829 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c @@ -19,24 +19,33 @@ #include "main.h" #include +#include +#include #include #include #include #include +#include #include #include #include #include #include #include +#include +#include +#include #include "bat_v_elp.h" #include "bat_v_ogm.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +struct sk_buff; + static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface) { struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); @@ -198,6 +207,136 @@ static void batadv_v_neigh_print(struct batadv_priv *bat_priv, } /** + * batadv_v_neigh_dump_neigh - Dump a neighbour into a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @hardif_neigh: Neighbour to dump + * + * Return: Error code, or 0 on success + */ +static int +batadv_v_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hardif_neigh_node *hardif_neigh) +{ + void *hdr; + unsigned int last_seen_msecs; + u32 throughput; + + last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen); + throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); + throughput = throughput * 100; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, + BATADV_CMD_GET_NEIGHBORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + hardif_neigh->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + hardif_neigh->if_incoming->net_dev->ifindex) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs) || + nla_put_u32(msg, BATADV_ATTR_THROUGHPUT, throughput)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +/** + * batadv_v_neigh_dump_hardif - Dump the neighbours of a hard interface into + * a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @bat_priv: The bat priv with all the soft interface information + * @hard_iface: The hard interface to be dumped + * @idx_s: Entries to be skipped + * + * Return: Error code, or 0 on success + */ +static int +batadv_v_neigh_dump_hardif(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *hard_iface, + int *idx_s) +{ + struct batadv_hardif_neigh_node *hardif_neigh; + int idx = 0; + + hlist_for_each_entry_rcu(hardif_neigh, +&hard_iface->neigh_list, list) { + if (idx++ < *idx_s) + continue; + + if (batadv_v_neigh_dump_neigh(msg, portid, seq, hardif_neigh)) { + *idx_s = idx - 1; + return -EMSGSIZE; + } + } + + *idx_s = 0; + return 0; +} + +/** + * batadv_v_neigh_dump - Dump the neighbours of a hard interface into a + * message + * @msg: Netlink message to
[B.A.T.M.A.N.] [PATCH v6 03/11] batman-adv: netlink: add routing_algo query
From: Matthias Schiffer BATADV_CMD_GET_ROUTING_ALGOS is used to get the list of supported routing algorithms. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn [sven.eckelm...@open-mesh.com: Reduce the number of changes to BATADV_CMD_GET_ROUTING_ALGOS] Signed-off-by: Sven Eckelmann --- compat-include/linux/netlink.h | 45 include/uapi/linux/batman_adv.h | 2 ++ net/batman-adv/main.c | 66 + net/batman-adv/main.h | 2 ++ net/batman-adv/netlink.c| 10 +-- net/batman-adv/netlink.h| 9 ++ 6 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 compat-include/linux/netlink.h diff --git a/compat-include/linux/netlink.h b/compat-include/linux/netlink.h new file mode 100644 index 000..4d0eb5b --- /dev/null +++ b/compat-include/linux/netlink.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ + +#include +#include_next + +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) + +struct batadv_netlink_skb_parms { + struct ucredcreds; /* Skb credentials */ + union { + __u32 portid; + __u32 pid; + }; + __u32 dst_group; +}; + +#undef NETLINK_CB +#define NETLINK_CB(skb) (*(struct batadv_netlink_skb_parms *)&((skb)->cb)) + +#endif /* < KERNEL_VERSION(3, 7, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ */ diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index a908140..d2a9740 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -57,12 +57,14 @@ enum batadv_nl_attrs { * * @BATADV_CMD_UNSPEC: unspecified command to catch errors * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device + * @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms. * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ enum batadv_nl_commands { BATADV_CMD_UNSPEC, BATADV_CMD_GET_MESH_INFO, + BATADV_CMD_GET_ROUTING_ALGOS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index e78b318..fe03721 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,10 @@ #include #include #include +#include +#include #include +#include #include "bat_algo.h" #include "bridge_loop_avoidance.h" @@ -612,6 +616,68 @@ int batadv_algo_seq_print_text(struct seq_file *seq, void *offset) } /** + * batadv_algo_dump_entry - fill in information about one supported routing + * algorithm + * @msg: netlink message to be sent back + * @portid: Port to reply to + * @seq: Sequence number of message + * @bat_algo_ops: Algorithm to be dumped + * + * Return: Error number, or 0 on success + */ +static int batadv_algo_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_algo_ops *bat_algo_ops) +{ + void *hdr; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_ROUTING_ALGOS); + if (!hdr) + return -EMSGSIZE; + + if (nla_put_string(msg, BATADV_ATTR_ALGO_NAME, bat_algo_ops->name)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +/** + * batadv_algo_dump - fill in information about supported routing + * algorithms + * @msg: netlink message to be sent back + * @cb: Parameters to the netlink request + * + * Return: Length of reply message. + */ +int batadv_algo_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + int portid = NETLINK_CB(cb->skb).portid; + struct batadv_algo
[B.A.T.M.A.N.] [PATCH v6 04/11] batman-adv: netlink: hardif query
From: Matthias Schiffer BATADV_CMD_GET_HARDIFS will return the list of hardifs (including index, name and MAC address) of all hardifs for a given softif. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn [sven.eckelm...@open-mesh.com: Reduce the number of changes to BATADV_CMD_GET_HARDIFS, add policy for attributes] Signed-off-by: Sven Eckelmann --- include/uapi/linux/batman_adv.h | 4 ++ net/batman-adv/netlink.c| 129 +++- 2 files changed, 131 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index d2a9740..9e7d77a 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -32,6 +32,7 @@ * @BATADV_ATTR_HARD_IFINDEX: index of the non-batman-adv interface * @BATADV_ATTR_HARD_IFNAME: name of the non-batman-adv interface * @BATADV_ATTR_HARD_ADDRESS: mac address of the non-batman-adv interface + * @BATADV_ATTR_ACTIVE: Flag indicating if the hard interface is active * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -46,6 +47,7 @@ enum batadv_nl_attrs { BATADV_ATTR_HARD_IFINDEX, BATADV_ATTR_HARD_IFNAME, BATADV_ATTR_HARD_ADDRESS, + BATADV_ATTR_ACTIVE, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -58,6 +60,7 @@ enum batadv_nl_attrs { * @BATADV_CMD_UNSPEC: unspecified command to catch errors * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device * @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms. + * @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -65,6 +68,7 @@ enum batadv_nl_commands { BATADV_CMD_UNSPEC, BATADV_CMD_GET_MESH_INFO, BATADV_CMD_GET_ROUTING_ALGOS, + BATADV_CMD_GET_HARDIFS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 717d7d0..bc4fcc2 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -26,16 +26,19 @@ #include #include #include +#include +#include +#include #include +#include #include #include +#include #include #include "hard-interface.h" #include "soft-interface.h" -struct sk_buff; - struct genl_family batadv_netlink_family = { .id = GENL_ID_GENERATE, .hdrsize = 0, @@ -53,9 +56,25 @@ static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 }, [BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING }, [BATADV_ATTR_HARD_ADDRESS] = { .len = ETH_ALEN }, + [BATADV_ATTR_ACTIVE]= { .type = NLA_FLAG }, }; /** + * batadv_netlink_get_ifindex - Extract an interface index from a message + * @nlh: Message header + * @attrtype: Attribute which holds an interface index + * + * Return: interface index, or 0. + */ +static int +batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype) +{ + struct nlattr *attr = nlmsg_find_attr(nlh, GENL_HDRLEN, attrtype); + + return attr ? nla_get_u32(attr) : 0; +} + +/** * batadv_netlink_mesh_info_put - fill in generic information about mesh * interface * @msg: netlink message to be sent back @@ -163,6 +182,106 @@ batadv_netlink_get_mesh_info(struct sk_buff *skb, struct genl_info *info) return genlmsg_reply(msg, info); } +/** + * batadv_netlink_dump_hardif_entry - Dump one hard interface into a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @hard_iface: Hard interface to dump + * + * Return: error code, or 0 on success + */ +static int +batadv_netlink_dump_hardif_entry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_hard_iface *hard_iface) +{ + struct net_device *net_dev = hard_iface->net_dev; + void *hdr; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, + BATADV_CMD_GET_HARDIFS); + if (!hdr) + return -EMSGSIZE; + + if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + net_dev->ifindex) || + nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, + net_dev->name) || + nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN, + net_dev->dev_addr)) + goto nla_put_failure; + + if (hard_iface->if_status == BATADV_IF_ACTIVE) { + if (nla_put_flag(msg, BATADV_ATT
[B.A.T.M.A.N.] [PATCH v6 06/11] batman-adv: netlink: add originator and neighbor table queries
From: Matthias Schiffer Add BATADV_CMD_GET_ORIGINATORS and BATADV_CMD_GET_NEIGHBORS commands, using handlers bat_orig_dump and bat_neigh_dump in batadv_algo_ops. Will always return -EOPNOTSUPP for now, as no implementations exist yet. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 4 + net/batman-adv/netlink.c| 13 net/batman-adv/originator.c | 160 net/batman-adv/originator.h | 4 + net/batman-adv/types.h | 9 +++ 5 files changed, 190 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 78f3584..def3799 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -117,6 +117,8 @@ enum batadv_nl_attrs { * @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces * @BATADV_CMD_GET_TRANSTABLE_LOCAL: Query list of local translations * @BATADV_CMD_GET_TRANSTABLE_GLOBAL Query list of global translations + * @BATADV_CMD_GET_ORIGINATORS: Query list of originators + * @BATADV_CMD_GET_NEIGHBORS: Query list of neighbours * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -127,6 +129,8 @@ enum batadv_nl_commands { BATADV_CMD_GET_HARDIFS, BATADV_CMD_GET_TRANSTABLE_LOCAL, BATADV_CMD_GET_TRANSTABLE_GLOBAL, + BATADV_CMD_GET_ORIGINATORS, + BATADV_CMD_GET_NEIGHBORS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index cede827..b5a9dfb 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -36,6 +36,7 @@ #include #include +#include "originator.h" #include "hard-interface.h" #include "soft-interface.h" #include "translation-table.h" @@ -323,6 +324,18 @@ static struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_tt_global_dump, }, + { + .cmd = BATADV_CMD_GET_ORIGINATORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_orig_dump, + }, + { + .cmd = BATADV_CMD_GET_NEIGHBORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_hardif_neigh_dump, + }, }; /** diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index 076d258..71b63e7 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c @@ -28,11 +28,15 @@ #include #include #include +#include #include #include +#include #include #include #include +#include +#include #include "distributed-arp-table.h" #include "fragmentation.h" @@ -40,8 +44,10 @@ #include "hard-interface.h" #include "hash.h" #include "multicast.h" +#include "netlink.h" #include "network-coding.h" #include "routing.h" +#include "soft-interface.h" #include "translation-table.h" /* hash class keys */ @@ -719,6 +725,83 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset) } /** + * batadv_hardif_neigh_dump - Dump to netlink the neighbor infos for a specific + * outgoing interface + * @msg: message to dump into + * @cb: parameters for the dump + * + * Return: 0 or error value + */ +int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + struct net *net = sock_net(cb->skb->sk); + struct net_device *soft_iface = NULL; + struct net_device *hard_iface = NULL; + struct batadv_hard_iface *hardif = BATADV_IF_DEFAULT; + struct batadv_priv *bat_priv; + struct batadv_hard_iface *primary_if = NULL; + int ret; + int ifindex, hard_ifindex; + + ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX); + if (!ifindex) + return -EINVAL; + + soft_iface = dev_get_by_index(net, ifindex); + if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { + ret = -ENODEV; + goto out; + } + + bat_priv = netdev_priv(soft_iface); + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { + ret = -ENOENT; + goto out; + } + + hard_ifindex = batadv_netlink_get_ifindex(cb->nlh, + BATADV_ATTR_HARD_IFINDEX); + if (hard_ifindex) { + hard_iface = dev_get_by_index(net, hard_ifindex); + if (hard_iface) + hardif = batadv_hardif_get_by_netdev(hard_iface); + + if (!
[B.A.T.M.A.N.] [PATCH v6 07/11] batman-adv: add B.A.T.M.A.N. IV bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 4 + net/batman-adv/bat_iv_ogm.c | 359 net/batman-adv/netlink.c| 2 + 3 files changed, 365 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index def3799..70ea9e4 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -78,6 +78,8 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_TT_FLAGS: Translation table client flags * @BATADV_ATTR_FLAG_BEST: Flags indicating entry is the best * @BATADV_ATTR_LAST_SEEN_MSECS: Time in milliseconds since last seen + * @BATADV_ATTR_NEIGH_ADDRESS: Neighbour MAC address + * @BATADV_ATTR_TQ: TQ to neighbour * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -102,6 +104,8 @@ enum batadv_nl_attrs { BATADV_ATTR_TT_FLAGS, BATADV_ATTR_FLAG_BEST, BATADV_ATTR_LAST_SEEN_MSECS, + BATADV_ATTR_NEIGH_ADDRESS, + BATADV_ATTR_TQ, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 4815db9..faeba72 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -48,10 +49,14 @@ #include #include #include +#include +#include +#include #include "bitarray.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "network-coding.h" #include "originator.h" #include "packet.h" @@ -1976,6 +1981,233 @@ next: } /** + * batadv_iv_ogm_neigh_get_tq_avg - Get the TQ average for a neighbour on a + * given outgoing interface. + * @neigh_node: Neighbour of interest + * @if_outgoing: Outgoing interface of interest + * @tq_avg: Pointer of where to store the TQ average + * + * Return: False if no average TQ available, otherwise true. + */ +static bool +batadv_iv_ogm_neigh_get_tq_avg(struct batadv_neigh_node *neigh_node, + struct batadv_hard_iface *if_outgoing, + u8 *tq_avg) +{ + struct batadv_neigh_ifinfo *n_ifinfo; + + n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); + if (!n_ifinfo) + return false; + + *tq_avg = n_ifinfo->bat_iv.tq_avg; + batadv_neigh_ifinfo_put(n_ifinfo); + + return true; +} + +/** + * batadv_iv_ogm_orig_dump_subentry - Dump an originator subentry into a + * message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @bat_priv: The bat priv with all the soft interface information + * @if_outgoing: Limit dump to entries with this outgoing interface + * @orig_node: Originator to dump + * @neigh_node: Single hops neighbour + * @best: Is the best originator + * + * Return: Error code, or 0 on success + */ +static int +batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_hard_iface *if_outgoing, +struct batadv_orig_node *orig_node, +struct batadv_neigh_node *neigh_node, +bool best) +{ + void *hdr; + u8 tq_avg; + unsigned int last_seen_msecs; + + last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen); + + if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node, if_outgoing, &tq_avg)) + return 0; + + if (if_outgoing != BATADV_IF_DEFAULT && + if_outgoing != neigh_node->if_incoming) + return 0; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_ORIGINATORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, + orig_node->orig) || + nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + neigh_node->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + neigh_node->if_incoming->net_dev->ifindex) || + nla_put_u8(msg, BATADV_ATTR_TQ, tq_avg) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs)) + goto nla_put_failure; + + if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) + goto nla_put_failure; + + ge
[B.A.T.M.A.N.] [PATCH v6 02/11] batman-adv: Suppress debugfs entries for netns's
Debugfs is not netns aware. It thus has problems when the same interface name exists in multiple network name spaces. Work around this by not creating entries for interfaces in name spaces other than the default name space. This means meshes in network namespaces cannot be managed via debugfs, but there will soon be a netlink interface which is netns aware. Signed-off-by: Andrew Lunn --- net/batman-adv/debugfs.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c index f187a8f..50545b0 100644 --- a/net/batman-adv/debugfs.c +++ b/net/batman-adv/debugfs.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "bridge_loop_avoidance.h" @@ -518,12 +519,16 @@ void batadv_debugfs_destroy(void) */ int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); struct batadv_debuginfo **bat_debug; struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name, batadv_debugfs); if (!hard_iface->debug_dir) @@ -554,6 +559,11 @@ out: */ void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); + + if (net != &init_net) + return; + if (batadv_debugfs) { debugfs_remove_recursive(hard_iface->debug_dir); hard_iface->debug_dir = NULL; @@ -564,11 +574,15 @@ int batadv_debugfs_add_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); struct batadv_debuginfo **bat_debug; + struct net *net = dev_net(dev); struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); if (!bat_priv->debug_dir) goto out; @@ -605,6 +619,10 @@ out: void batadv_debugfs_del_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); + struct net *net = dev_net(dev); + + if (net != &init_net) + return; batadv_debug_log_cleanup(bat_priv); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v6 01/11] batman-adv: Handle parent interfaces in a different netns
batman-adv tries to prevent the user from placing a batX soft interface into another batman mesh as a hard interface. It does this by walking up the devices list of parents and ensures they are all none batX interfaces. iflink can point to an interface in a different namespace, so also retrieve the parents name space when finding the parent and use it when doing the comparison. Signed-off-by: Andrew Lunn Signed-off-by: Sven Eckelmann Acked-by: Antonio Quartulli --- compat.h| 7 ++ net/batman-adv/hard-interface.c | 50 +++-- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/compat.h b/compat.h index 7d5c8b6..ac4f7a0 100644 --- a/compat.h +++ b/compat.h @@ -146,6 +146,13 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\ #endif /* < KERNEL_VERSION(3, 15, 0) */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) + +/* WARNING for batadv_getlink_net */ +#define get_link_net get_xstats_size || 0 || netdev->rtnl_link_ops->get_xstats_size + +#endif /* < KERNEL_VERSION(4, 0, 0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) #define IFF_NO_QUEUE 0; dev->tx_queue_len = 0 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index a8cda76..bf4ee24 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include "bridge_loop_avoidance.h" #include "debugfs.h" @@ -83,25 +85,55 @@ out: } /** + * batadv_getlink_net - return link net namespace (of use fallback) + * @netdev: net_device to check + * @fallback_net: return in case get_link_net is not available for @netdev + * + * Return: result of rtnl_link_ops->get_link_net or @fallback_net + */ +static const struct net *batadv_getlink_net(const struct net_device *netdev, + const struct net *fallback_net) +{ + if (!netdev->rtnl_link_ops) + return fallback_net; + + if (!netdev->rtnl_link_ops->get_link_net) + return fallback_net; + + return netdev->rtnl_link_ops->get_link_net(netdev); +} + +/** * batadv_mutual_parents - check if two devices are each others parent - * @dev1: 1st net_device - * @dev2: 2nd net_device + * @dev1: 1st net dev + * @net1: 1st devices netns + * @dev2: 2nd net dev + * @net2: 2nd devices netns * * veth devices come in pairs and each is the parent of the other! * * Return: true if the devices are each others parent, otherwise false */ static bool batadv_mutual_parents(const struct net_device *dev1, - const struct net_device *dev2) + const struct net *net1, + const struct net_device *dev2, + const struct net *net2) { int dev1_parent_iflink = dev_get_iflink(dev1); int dev2_parent_iflink = dev_get_iflink(dev2); + const struct net *dev1_parent_net; + const struct net *dev2_parent_net; + + dev1_parent_net = batadv_getlink_net(dev1, net1); + dev2_parent_net = batadv_getlink_net(dev2, net2); if (!dev1_parent_iflink || !dev2_parent_iflink) return false; return (dev1_parent_iflink == dev2->ifindex) && - (dev2_parent_iflink == dev1->ifindex); + (dev2_parent_iflink == dev1->ifindex) && + net_eq(dev1_parent_net, net2) && + net_eq(dev2_parent_net, net1); } /** @@ -119,8 +151,9 @@ static bool batadv_mutual_parents(const struct net_device *dev1, */ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) { - struct net_device *parent_dev; struct net *net = dev_net(net_dev); + struct net_device *parent_dev; + const struct net *parent_net; bool ret; /* check if this is a batman-adv mesh interface */ @@ -132,13 +165,16 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) dev_get_iflink(net_dev) == net_dev->ifindex) return false; + parent_net = batadv_getlink_net(net_dev, net); + /* recurse over the parent device */ - parent_dev = __dev_get_by_index(net, dev_get_iflink(net_dev)); + parent_dev = __dev_get_by_index((struct net *)parent_net, + dev_get_iflink(net_dev)); /* if we got a NULL parent_dev there is something broken.. */ if (WARN(!parent_dev, "Cannot find parent device")) return false; - if (batadv_mutual_parents(net_dev, parent_dev)) + if (batadv_mutual_parents(net_dev, net, parent_dev, parent_net)) return false; ret = batadv_is_on_batman_iface(parent_dev); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v6 05/11] batman-adv: netlink: add translation table query
From: Matthias Schiffer This adds the commands BATADV_CMD_GET_TRANSTABLE_LOCAL and BATADV_CMD_GET_TRANSTABLE_GLOBAL, which correspond to the transtable_local and transtable_global debugfs files. The batadv_tt_client_flags enum is moved to the UAPI to expose it as part of the netlink API. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h| 58 ++ net/batman-adv/netlink.c | 24 ++- net/batman-adv/netlink.h | 1 + net/batman-adv/packet.h| 36 net/batman-adv/translation-table.c | 379 + net/batman-adv/translation-table.h | 4 + 6 files changed, 465 insertions(+), 37 deletions(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 9e7d77a..78f3584 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -21,6 +21,42 @@ #define BATADV_NL_NAME "batadv" /** + * enum batadv_tt_client_flags - TT client specific flags + * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table + * @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new + * update telling its new real location has not been received/sent yet + * @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface. + * This information is used by the "AP Isolation" feature + * @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This + * information is used by the Extended Isolation feature + * @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table + * @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has + * not been announced yet + * @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept + * in the table for one more originator interval for consistency purposes + * @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of + * the network but no nnode has already announced it + * + * Bits from 0 to 7 are called _remote flags_ because they are sent on the wire. + * Bits from 8 to 15 are called _local flags_ because they are used for local + * computations only. + * + * Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with + * the other nodes in the network. To achieve this goal these flags are included + * in the TT CRC computation. + */ +enum batadv_tt_client_flags { + BATADV_TT_CLIENT_DEL = (1 << 0), + BATADV_TT_CLIENT_ROAM= (1 << 1), + BATADV_TT_CLIENT_WIFI= (1 << 4), + BATADV_TT_CLIENT_ISOLA = (1 << 5), + BATADV_TT_CLIENT_NOPURGE = (1 << 8), + BATADV_TT_CLIENT_NEW = (1 << 9), + BATADV_TT_CLIENT_PENDING = (1 << 10), + BATADV_TT_CLIENT_TEMP= (1 << 11), +}; + +/** * enum batadv_nl_attrs - batman-adv netlink attributes * * @BATADV_ATTR_UNSPEC: unspecified attribute to catch errors @@ -33,6 +69,15 @@ * @BATADV_ATTR_HARD_IFNAME: name of the non-batman-adv interface * @BATADV_ATTR_HARD_ADDRESS: mac address of the non-batman-adv interface * @BATADV_ATTR_ACTIVE: Flag indicating if the hard interface is active + * @BATADV_ATTR_ORIG_ADDRESS: Originator MAC address + * @BATADV_ATTR_TT_ADDRESS: Client MAC address + * @BATADV_ATTR_TT_TTVN: Translation table version + * @BATADV_ATTR_TT_LAST_TTVN: Previous translation table version + * @BATADV_ATTR_TT_CRC32: CRC32 over translation table + * @BATADV_ATTR_TT_VID: VLAN ID + * @BATADV_ATTR_TT_FLAGS: Translation table client flags + * @BATADV_ATTR_FLAG_BEST: Flags indicating entry is the best + * @BATADV_ATTR_LAST_SEEN_MSECS: Time in milliseconds since last seen * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -48,6 +93,15 @@ enum batadv_nl_attrs { BATADV_ATTR_HARD_IFNAME, BATADV_ATTR_HARD_ADDRESS, BATADV_ATTR_ACTIVE, + BATADV_ATTR_ORIG_ADDRESS, + BATADV_ATTR_TT_ADDRESS, + BATADV_ATTR_TT_TTVN, + BATADV_ATTR_TT_LAST_TTVN, + BATADV_ATTR_TT_CRC32, + BATADV_ATTR_TT_VID, + BATADV_ATTR_TT_FLAGS, + BATADV_ATTR_FLAG_BEST, + BATADV_ATTR_LAST_SEEN_MSECS, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -61,6 +115,8 @@ enum batadv_nl_attrs { * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device * @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms. * @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces + * @BATADV_CMD_GET_TRANSTABLE_LOCAL: Query list of local translations + * @BATADV_CMD_GET_TRANSTABLE_GLOBAL Query list of global translations * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */
[B.A.T.M.A.N.] [PATCH v6 00/11] netns and netlink support
This patchset completes netns support, by disabling debugfs entries when not in the default name space, and correctly handling interface stack loops when the parent is in a different name space. It additionally adds netlink support for most of the information found in debugfs, and is netns aware. Note: BLA is still untested, so best assume it is broken... v6: * Add missing kernel doc for local/global transtable and bla claims * No change to code indentation. I consider it a false positive. The code is more readable the way it is, checkpatch is happy, and it does not violate anything in CodingStyle, as far as i can see. v5: * Rebase on top of master which now has basic netlink support * Complete all the kerneldoc cut/paste work requested by Sven. v4: * Fix the batctl o -i use case by actually performing the filtering on the outgoing interface v3: * Fix the compat with older kernels. It now at least compiles with 3.18.32. I've not booted it though. * Add missing kerneldoc v2: All changes requested by Sven: * Added lots of missing includes and structure forward declarations * Add two kernel doc comments * Fixed an obvious bug in BLA, but it is probably still broken... * Merged in the compat code Sven suggested. Only compile tested with 4.5.0 Andrew Lunn (5): batman-adv: Handle parent interfaces in a different netns batman-adv: Suppress debugfs entries for netns's batman-adv: add B.A.T.M.A.N. Dump gateways via netlink batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink batman-adv: Indicate netlink socket can be used with netns. Matthias Schiffer (6): batman-adv: netlink: add routing_algo query batman-adv: netlink: hardif query batman-adv: netlink: add translation table query batman-adv: netlink: add originator and neighbor table queries batman-adv: add B.A.T.M.A.N. IV bat_{orig, neigh}_dump implementations batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations compat-include/linux/netlink.h | 45 compat.h | 7 + include/uapi/linux/batman_adv.h| 91 net/batman-adv/bat_iv_ogm.c| 361 +++ net/batman-adv/bat_v.c | 337 + net/batman-adv/bridge_loop_avoidance.c | 166 +++ net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/debugfs.c | 18 ++ net/batman-adv/gateway_client.c| 148 + net/batman-adv/gateway_client.h| 2 + net/batman-adv/hard-interface.c| 50 - net/batman-adv/main.c | 66 ++ net/batman-adv/main.h | 2 + net/batman-adv/netlink.c | 200 - net/batman-adv/netlink.h | 10 + net/batman-adv/originator.c| 160 ++ net/batman-adv/originator.h| 4 + net/batman-adv/packet.h| 36 net/batman-adv/translation-table.c | 379 + net/batman-adv/translation-table.h | 4 + net/batman-adv/types.h | 9 + 21 files changed, 2057 insertions(+), 48 deletions(-) create mode 100644 compat-include/linux/netlink.h -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v5 06/11] batman-adv: netlink: add originator and neighbor table queries
From: Matthias Schiffer Add BATADV_CMD_GET_ORIGINATORS and BATADV_CMD_GET_NEIGHBORS commands, using handlers bat_orig_dump and bat_neigh_dump in batadv_algo_ops. Will always return -EOPNOTSUPP for now, as no implementations exist yet. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 4 + net/batman-adv/netlink.c| 13 net/batman-adv/originator.c | 160 net/batman-adv/originator.h | 4 + net/batman-adv/types.h | 9 +++ 5 files changed, 190 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index c5ef3df..1f2f5fc 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -115,6 +115,8 @@ enum batadv_nl_attrs { * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device * @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms. * @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces + * @BATADV_CMD_GET_ORIGINATORS: Query list of originators + * @BATADV_CMD_GET_NEIGHBORS: Query list of neighbours * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -125,6 +127,8 @@ enum batadv_nl_commands { BATADV_CMD_GET_HARDIFS, BATADV_CMD_GET_TRANSTABLE_LOCAL, BATADV_CMD_GET_TRANSTABLE_GLOBAL, + BATADV_CMD_GET_ORIGINATORS, + BATADV_CMD_GET_NEIGHBORS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index cede827..b5a9dfb 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -36,6 +36,7 @@ #include #include +#include "originator.h" #include "hard-interface.h" #include "soft-interface.h" #include "translation-table.h" @@ -323,6 +324,18 @@ static struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_tt_global_dump, }, + { + .cmd = BATADV_CMD_GET_ORIGINATORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_orig_dump, + }, + { + .cmd = BATADV_CMD_GET_NEIGHBORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_hardif_neigh_dump, + }, }; /** diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index 076d258..71b63e7 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c @@ -28,11 +28,15 @@ #include #include #include +#include #include #include +#include #include #include #include +#include +#include #include "distributed-arp-table.h" #include "fragmentation.h" @@ -40,8 +44,10 @@ #include "hard-interface.h" #include "hash.h" #include "multicast.h" +#include "netlink.h" #include "network-coding.h" #include "routing.h" +#include "soft-interface.h" #include "translation-table.h" /* hash class keys */ @@ -719,6 +725,83 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset) } /** + * batadv_hardif_neigh_dump - Dump to netlink the neighbor infos for a specific + * outgoing interface + * @msg: message to dump into + * @cb: parameters for the dump + * + * Return: 0 or error value + */ +int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + struct net *net = sock_net(cb->skb->sk); + struct net_device *soft_iface = NULL; + struct net_device *hard_iface = NULL; + struct batadv_hard_iface *hardif = BATADV_IF_DEFAULT; + struct batadv_priv *bat_priv; + struct batadv_hard_iface *primary_if = NULL; + int ret; + int ifindex, hard_ifindex; + + ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX); + if (!ifindex) + return -EINVAL; + + soft_iface = dev_get_by_index(net, ifindex); + if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { + ret = -ENODEV; + goto out; + } + + bat_priv = netdev_priv(soft_iface); + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { + ret = -ENOENT; + goto out; + } + + hard_ifindex = batadv_netlink_get_ifindex(cb->nlh, + BATADV_ATTR_HARD_IFINDEX); + if (hard_ifindex) { + hard_iface = dev_get_by_index(net, hard_ifindex); + if (hard_iface) + hardif = batadv_hardif_get_by_netdev(hard_iface); + + if (!
[B.A.T.M.A.N.] [PATCH v5 09/11] batman-adv: add B.A.T.M.A.N. Dump gateways via netlink
Dump the list of gateways via the netlink socket. Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 8 +++ net/batman-adv/gateway_client.c | 148 net/batman-adv/gateway_client.h | 2 + net/batman-adv/netlink.c| 10 +++ 4 files changed, 168 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 28731d9..d45ec98 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -81,6 +81,9 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_NEIGH_ADDRESS: Neighbour MAC address * @BATADV_ATTR_TQ: TQ to neighbour * @BATADV_ATTR_THROUGHPUT: Estimated throughput to Neighbour + * @BATADV_ATTR_BANDWIDTH_UP: Reported uplink bandwidth + * @BATADV_ATTR_BANDWIDTH_DOWN: Reported downlink bandwidth + * @BATADV_ATTR_ROUTER: Gateway router MAC address * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -108,6 +111,9 @@ enum batadv_nl_attrs { BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, BATADV_ATTR_THROUGHPUT, + BATADV_ATTR_BANDWIDTH_UP, + BATADV_ATTR_BANDWIDTH_DOWN, + BATADV_ATTR_ROUTER, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -123,6 +129,7 @@ enum batadv_nl_attrs { * @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces * @BATADV_CMD_GET_ORIGINATORS: Query list of originators * @BATADV_CMD_GET_NEIGHBORS: Query list of neighbours + * @BATADV_CMD_GET_GATEWAYS: Query list of gateways * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -135,6 +142,7 @@ enum batadv_nl_commands { BATADV_CMD_GET_TRANSTABLE_GLOBAL, BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, + BATADV_CMD_GET_GATEWAYS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 31ba24e..9967f5e 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -39,12 +41,18 @@ #include #include #include +#include +#include +#include +#include #include "gateway_common.h" #include "hard-interface.h" +#include "netlink.h" #include "originator.h" #include "packet.h" #include "routing.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -663,6 +671,146 @@ out: } /** + * batadv_gw_dump_entry - Dump a gateway into a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @bat_priv: The bat priv with all the soft interface information + * @gw_node: Gateway to be dumped + * + * Return: Error code, or 0 on success + */ +static int +batadv_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_gw_node *gw_node) +{ + struct batadv_neigh_ifinfo *router_ifinfo = NULL; + struct batadv_neigh_node *router; + struct batadv_gw_node *curr_gw; + int ret = -EINVAL; + void *hdr; + + router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); + if (!router) + goto out; + + router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT); + if (!router_ifinfo) + goto out; + + curr_gw = batadv_gw_get_selected_gw_node(bat_priv); + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_GATEWAYS); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + ret = -EMSGSIZE; + + if (curr_gw == gw_node) + if (nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, + gw_node->orig_node->orig) || + nla_put_u8(msg, BATADV_ATTR_TQ, router_ifinfo->bat_iv.tq_avg) || + nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN, + router->addr) || + nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, + router->if_incoming->net_dev->name) || + nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN, + gw_node->bandwidth_down) || + nla_pu
[B.A.T.M.A.N.] [PATCH v5 10/11] batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink
Dump the list of bridge loop avoidance claims via the netlink socket. Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h| 11 +++ net/batman-adv/bridge_loop_avoidance.c | 166 + net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/netlink.c | 12 +++ 4 files changed, 198 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index d45ec98..5fca706 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -84,6 +84,11 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_BANDWIDTH_UP: Reported uplink bandwidth * @BATADV_ATTR_BANDWIDTH_DOWN: Reported downlink bandwidth * @BATADV_ATTR_ROUTER: Gateway router MAC address + * @BATADV_ATTR_BLA_OWN: Flag indicating own originator + * @BATADV_ATTR_BLA_ADDRESS: Bridge loop avoidance claim MAC address + * @BATADV_ATTR_BLA_VID: BLA VLAN ID + * @BATADV_ATTR_BLA_BACKBONE: BLA gateway originator MAC address + * @BATADV_ATTR_BLA_CRC: BLA CRC * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -114,6 +119,11 @@ enum batadv_nl_attrs { BATADV_ATTR_BANDWIDTH_UP, BATADV_ATTR_BANDWIDTH_DOWN, BATADV_ATTR_ROUTER, + BATADV_ATTR_BLA_OWN, + BATADV_ATTR_BLA_ADDRESS, + BATADV_ATTR_BLA_VID, + BATADV_ATTR_BLA_BACKBONE, + BATADV_ATTR_BLA_CRC, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -143,6 +153,7 @@ enum batadv_nl_commands { BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, BATADV_CMD_GET_GATEWAYS, + BATADV_CMD_GET_BLA_CLAIM, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 748a9ea..99458f3 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -45,11 +46,17 @@ #include #include #include +#include +#include +#include +#include #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -1983,6 +1990,165 @@ out: } /** + * batadv_bla_claim_dump_entry - dump one entry of the backbone table + * to a netlink socket + * @msg: buffer for the message + * @portid: netlink port + * @seq: Sequence number of netlink message + * @primary_if: primary interface + * @claim: entry to dump + * + * Return: 0 or error code. + */ +static int +batadv_bla_claim_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hard_iface *primary_if, + struct batadv_bla_claim *claim) +{ + u8 *primary_addr = primary_if->net_dev->dev_addr; + u16 backbone_crc; + bool is_own; + void *hdr; + int ret = -EINVAL; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_BLA_CLAIM); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + is_own = batadv_compare_eth(claim->backbone_gw->orig, + primary_addr); + + spin_lock_bh(&claim->backbone_gw->crc_lock); + backbone_crc = claim->backbone_gw->crc; + spin_unlock_bh(&claim->backbone_gw->crc_lock); + + if (is_own) + if (nla_put_flag(msg, BATADV_ATTR_BLA_OWN)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_BLA_ADDRESS, ETH_ALEN, claim->addr) || + nla_put_u16(msg, BATADV_ATTR_BLA_VID, claim->vid) || + nla_put(msg, BATADV_ATTR_BLA_BACKBONE, ETH_ALEN, + claim->backbone_gw->orig) || + nla_put_u16(msg, BATADV_ATTR_BLA_CRC, + backbone_crc)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + genlmsg_end(msg, hdr); + ret = 0; + +out: + return ret; +} + +/** + * batadv_bla_claim_dump_bucket - dump one bucket of the backbone table + * to a netlink socket + * @msg: buffer for the message + * @portid: netlink port + * @seq: Sequence number of netlink message + * @primary_if: primary interface + * @head: bucket to dump + * @idx_skip: How many entries to skip + * + * Return: always 0. + */ +static int +ba
[B.A.T.M.A.N.] [PATCH v5 03/11] batman-adv: netlink: add routing_algo query
From: Matthias Schiffer BATADV_CMD_GET_ROUTING_ALGOS is used to get the list of supported routing algorithms. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn [sven.eckelm...@open-mesh.com: Reduce the number of changes to BATADV_CMD_GET_ROUTING_ALGOS] Signed-off-by: Sven Eckelmann --- compat-include/linux/netlink.h | 45 include/uapi/linux/batman_adv.h | 2 ++ net/batman-adv/main.c | 66 + net/batman-adv/main.h | 2 ++ net/batman-adv/netlink.c| 10 +-- net/batman-adv/netlink.h| 9 ++ 6 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 compat-include/linux/netlink.h diff --git a/compat-include/linux/netlink.h b/compat-include/linux/netlink.h new file mode 100644 index 000..4d0eb5b --- /dev/null +++ b/compat-include/linux/netlink.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ + +#include +#include_next + +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) + +struct batadv_netlink_skb_parms { + struct ucredcreds; /* Skb credentials */ + union { + __u32 portid; + __u32 pid; + }; + __u32 dst_group; +}; + +#undef NETLINK_CB +#define NETLINK_CB(skb) (*(struct batadv_netlink_skb_parms *)&((skb)->cb)) + +#endif /* < KERNEL_VERSION(3, 7, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ */ diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index a908140..d2a9740 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -57,12 +57,14 @@ enum batadv_nl_attrs { * * @BATADV_CMD_UNSPEC: unspecified command to catch errors * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device + * @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms. * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ enum batadv_nl_commands { BATADV_CMD_UNSPEC, BATADV_CMD_GET_MESH_INFO, + BATADV_CMD_GET_ROUTING_ALGOS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index e78b318..fe03721 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,10 @@ #include #include #include +#include +#include #include +#include #include "bat_algo.h" #include "bridge_loop_avoidance.h" @@ -612,6 +616,68 @@ int batadv_algo_seq_print_text(struct seq_file *seq, void *offset) } /** + * batadv_algo_dump_entry - fill in information about one supported routing + * algorithm + * @msg: netlink message to be sent back + * @portid: Port to reply to + * @seq: Sequence number of message + * @bat_algo_ops: Algorithm to be dumped + * + * Return: Error number, or 0 on success + */ +static int batadv_algo_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_algo_ops *bat_algo_ops) +{ + void *hdr; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_ROUTING_ALGOS); + if (!hdr) + return -EMSGSIZE; + + if (nla_put_string(msg, BATADV_ATTR_ALGO_NAME, bat_algo_ops->name)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +/** + * batadv_algo_dump - fill in information about supported routing + * algorithms + * @msg: netlink message to be sent back + * @cb: Parameters to the netlink request + * + * Return: Length of reply message. + */ +int batadv_algo_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + int portid = NETLINK_CB(cb->skb).portid; + struct batadv_algo
[B.A.T.M.A.N.] [PATCH v5 11/11] batman-adv: Indicate netlink socket can be used with netns.
Set the netnsof flag on the family structure, indicating it can be used with different network name spaces. Signed-off-by: Andrew Lunn --- net/batman-adv/netlink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 972b4cf..e79de09 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -49,6 +49,7 @@ struct genl_family batadv_netlink_family = { .name = BATADV_NL_NAME, .version = 1, .maxattr = BATADV_ATTR_MAX, + .netnsok = true, }; static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v5 08/11] batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Dump the algo V originators and neighbours. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 2 + net/batman-adv/bat_v.c | 337 net/batman-adv/netlink.c| 1 + 3 files changed, 340 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index bcd89bf..28731d9 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -80,6 +80,7 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_LAST_SEEN_MSECS: Time in milliseconds since last seen * @BATADV_ATTR_NEIGH_ADDRESS: Neighbour MAC address * @BATADV_ATTR_TQ: TQ to neighbour + * @BATADV_ATTR_THROUGHPUT: Estimated throughput to Neighbour * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -106,6 +107,7 @@ enum batadv_nl_attrs { BATADV_ATTR_LAST_SEEN_MSECS, BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, + BATADV_ATTR_THROUGHPUT, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index b9c2850..8012829 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c @@ -19,24 +19,33 @@ #include "main.h" #include +#include +#include #include #include #include #include +#include #include #include #include #include #include #include +#include +#include +#include #include "bat_v_elp.h" #include "bat_v_ogm.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +struct sk_buff; + static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface) { struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); @@ -198,6 +207,136 @@ static void batadv_v_neigh_print(struct batadv_priv *bat_priv, } /** + * batadv_v_neigh_dump_neigh - Dump a neighbour into a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @hardif_neigh: Neighbour to dump + * + * Return: Error code, or 0 on success + */ +static int +batadv_v_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hardif_neigh_node *hardif_neigh) +{ + void *hdr; + unsigned int last_seen_msecs; + u32 throughput; + + last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen); + throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); + throughput = throughput * 100; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, + BATADV_CMD_GET_NEIGHBORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + hardif_neigh->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + hardif_neigh->if_incoming->net_dev->ifindex) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs) || + nla_put_u32(msg, BATADV_ATTR_THROUGHPUT, throughput)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +/** + * batadv_v_neigh_dump_hardif - Dump the neighbours of a hard interface into + * a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @bat_priv: The bat priv with all the soft interface information + * @hard_iface: The hard interface to be dumped + * @idx_s: Entries to be skipped + * + * Return: Error code, or 0 on success + */ +static int +batadv_v_neigh_dump_hardif(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *hard_iface, + int *idx_s) +{ + struct batadv_hardif_neigh_node *hardif_neigh; + int idx = 0; + + hlist_for_each_entry_rcu(hardif_neigh, +&hard_iface->neigh_list, list) { + if (idx++ < *idx_s) + continue; + + if (batadv_v_neigh_dump_neigh(msg, portid, seq, hardif_neigh)) { + *idx_s = idx - 1; + return -EMSGSIZE; + } + } + + *idx_s = 0; + return 0; +} + +/** + * batadv_v_neigh_dump - Dump the neighbours of a hard interface into a + * message + * @msg: Netlink message to
[B.A.T.M.A.N.] [PATCH v5 01/11] batman-adv: Handle parent interfaces in a different netns
batman-adv tries to prevent the user from placing a batX soft interface into another batman mesh as a hard interface. It does this by walking up the devices list of parents and ensures they are all none batX interfaces. iflink can point to an interface in a different namespace, so also retrieve the parents name space when finding the parent and use it when doing the comparison. Signed-off-by: Andrew Lunn Signed-off-by: Sven Eckelmann Acked-by: Antonio Quartulli --- compat.h| 7 ++ net/batman-adv/hard-interface.c | 50 +++-- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/compat.h b/compat.h index 7d5c8b6..ac4f7a0 100644 --- a/compat.h +++ b/compat.h @@ -146,6 +146,13 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\ #endif /* < KERNEL_VERSION(3, 15, 0) */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) + +/* WARNING for batadv_getlink_net */ +#define get_link_net get_xstats_size || 0 || netdev->rtnl_link_ops->get_xstats_size + +#endif /* < KERNEL_VERSION(4, 0, 0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) #define IFF_NO_QUEUE 0; dev->tx_queue_len = 0 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index a8cda76..bf4ee24 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include "bridge_loop_avoidance.h" #include "debugfs.h" @@ -83,25 +85,55 @@ out: } /** + * batadv_getlink_net - return link net namespace (of use fallback) + * @netdev: net_device to check + * @fallback_net: return in case get_link_net is not available for @netdev + * + * Return: result of rtnl_link_ops->get_link_net or @fallback_net + */ +static const struct net *batadv_getlink_net(const struct net_device *netdev, + const struct net *fallback_net) +{ + if (!netdev->rtnl_link_ops) + return fallback_net; + + if (!netdev->rtnl_link_ops->get_link_net) + return fallback_net; + + return netdev->rtnl_link_ops->get_link_net(netdev); +} + +/** * batadv_mutual_parents - check if two devices are each others parent - * @dev1: 1st net_device - * @dev2: 2nd net_device + * @dev1: 1st net dev + * @net1: 1st devices netns + * @dev2: 2nd net dev + * @net2: 2nd devices netns * * veth devices come in pairs and each is the parent of the other! * * Return: true if the devices are each others parent, otherwise false */ static bool batadv_mutual_parents(const struct net_device *dev1, - const struct net_device *dev2) + const struct net *net1, + const struct net_device *dev2, + const struct net *net2) { int dev1_parent_iflink = dev_get_iflink(dev1); int dev2_parent_iflink = dev_get_iflink(dev2); + const struct net *dev1_parent_net; + const struct net *dev2_parent_net; + + dev1_parent_net = batadv_getlink_net(dev1, net1); + dev2_parent_net = batadv_getlink_net(dev2, net2); if (!dev1_parent_iflink || !dev2_parent_iflink) return false; return (dev1_parent_iflink == dev2->ifindex) && - (dev2_parent_iflink == dev1->ifindex); + (dev2_parent_iflink == dev1->ifindex) && + net_eq(dev1_parent_net, net2) && + net_eq(dev2_parent_net, net1); } /** @@ -119,8 +151,9 @@ static bool batadv_mutual_parents(const struct net_device *dev1, */ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) { - struct net_device *parent_dev; struct net *net = dev_net(net_dev); + struct net_device *parent_dev; + const struct net *parent_net; bool ret; /* check if this is a batman-adv mesh interface */ @@ -132,13 +165,16 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) dev_get_iflink(net_dev) == net_dev->ifindex) return false; + parent_net = batadv_getlink_net(net_dev, net); + /* recurse over the parent device */ - parent_dev = __dev_get_by_index(net, dev_get_iflink(net_dev)); + parent_dev = __dev_get_by_index((struct net *)parent_net, + dev_get_iflink(net_dev)); /* if we got a NULL parent_dev there is something broken.. */ if (WARN(!parent_dev, "Cannot find parent device")) return false; - if (batadv_mutual_parents(net_dev, parent_dev)) + if (batadv_mutual_parents(net_dev, net, parent_dev, parent_net)) return false; ret = batadv_is_on_batman_iface(parent_dev); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v5 07/11] batman-adv: add B.A.T.M.A.N. IV bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h | 4 + net/batman-adv/bat_iv_ogm.c | 361 net/batman-adv/netlink.c| 2 + 3 files changed, 367 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 1f2f5fc..bcd89bf 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -78,6 +78,8 @@ enum batadv_tt_client_flags { * @BATADV_ATTR_TT_FLAGS: Translation table client flags * @BATADV_ATTR_FLAG_BEST: Flags indicating entry is the best * @BATADV_ATTR_LAST_SEEN_MSECS: Time in milliseconds since last seen + * @BATADV_ATTR_NEIGH_ADDRESS: Neighbour MAC address + * @BATADV_ATTR_TQ: TQ to neighbour * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -102,6 +104,8 @@ enum batadv_nl_attrs { BATADV_ATTR_TT_FLAGS, BATADV_ATTR_FLAG_BEST, BATADV_ATTR_LAST_SEEN_MSECS, + BATADV_ATTR_NEIGH_ADDRESS, + BATADV_ATTR_TQ, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 4815db9..cc882a5 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -48,10 +49,14 @@ #include #include #include +#include +#include +#include #include "bitarray.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "network-coding.h" #include "originator.h" #include "packet.h" @@ -1976,6 +1981,233 @@ next: } /** + * batadv_iv_ogm_neigh_get_tq_avg - Get the TQ average for a neighbour on a + * given outgoing interface. + * @neigh_node: Neighbour of interest + * @if_outgoing: Outgoing interface of interest + * @tq_avg: Pointer of where to store the TQ average + * + * Return: False if no average TQ available, otherwise true. + */ +static bool +batadv_iv_ogm_neigh_get_tq_avg(struct batadv_neigh_node *neigh_node, + struct batadv_hard_iface *if_outgoing, + u8 *tq_avg) +{ + struct batadv_neigh_ifinfo *n_ifinfo; + + n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); + if (!n_ifinfo) + return false; + + *tq_avg = n_ifinfo->bat_iv.tq_avg; + batadv_neigh_ifinfo_put(n_ifinfo); + + return true; +} + +/** + * batadv_iv_ogm_orig_dump_subentry - Dump an originator subentry into a + * message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @bat_priv: The bat priv with all the soft interface information + * @if_outgoing: Limit dump to entries with this outgoing interface + * @orig_node: Originator to dump + * @neigh_node: Single hops neighbour + * @best: Is the best originator + * + * Return: Error code, or 0 on success + */ +static int +batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_hard_iface *if_outgoing, +struct batadv_orig_node *orig_node, +struct batadv_neigh_node *neigh_node, +bool best) +{ + void *hdr; + u8 tq_avg; + unsigned int last_seen_msecs; + + last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen); + + if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node, if_outgoing, &tq_avg)) + return 0; + + if (if_outgoing != BATADV_IF_DEFAULT && + if_outgoing != neigh_node->if_incoming) + return 0; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_ORIGINATORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, + orig_node->orig) || + nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + neigh_node->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + neigh_node->if_incoming->net_dev->ifindex) || + nla_put_u8(msg, BATADV_ATTR_TQ, tq_avg) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs)) + goto nla_put_failure; + + if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) + goto nla_put_failure; + + ge
[B.A.T.M.A.N.] [PATCH v5 05/11] batman-adv: netlink: add translation table query
From: Matthias Schiffer This adds the commands BATADV_CMD_GET_TRANSTABLE_LOCAL and BATADV_CMD_GET_TRANSTABLE_GLOBAL, which correspond to the transtable_local and transtable_global debugfs files. The batadv_tt_client_flags enum is moved to the UAPI to expose it as part of the netlink API. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- include/uapi/linux/batman_adv.h| 56 ++ net/batman-adv/netlink.c | 24 ++- net/batman-adv/netlink.h | 1 + net/batman-adv/packet.h| 36 net/batman-adv/translation-table.c | 379 + net/batman-adv/translation-table.h | 4 + 6 files changed, 463 insertions(+), 37 deletions(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 9e7d77a..c5ef3df 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -21,6 +21,42 @@ #define BATADV_NL_NAME "batadv" /** + * enum batadv_tt_client_flags - TT client specific flags + * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table + * @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new + * update telling its new real location has not been received/sent yet + * @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface. + * This information is used by the "AP Isolation" feature + * @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This + * information is used by the Extended Isolation feature + * @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table + * @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has + * not been announced yet + * @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept + * in the table for one more originator interval for consistency purposes + * @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of + * the network but no nnode has already announced it + * + * Bits from 0 to 7 are called _remote flags_ because they are sent on the wire. + * Bits from 8 to 15 are called _local flags_ because they are used for local + * computations only. + * + * Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with + * the other nodes in the network. To achieve this goal these flags are included + * in the TT CRC computation. + */ +enum batadv_tt_client_flags { + BATADV_TT_CLIENT_DEL = (1 << 0), + BATADV_TT_CLIENT_ROAM= (1 << 1), + BATADV_TT_CLIENT_WIFI= (1 << 4), + BATADV_TT_CLIENT_ISOLA = (1 << 5), + BATADV_TT_CLIENT_NOPURGE = (1 << 8), + BATADV_TT_CLIENT_NEW = (1 << 9), + BATADV_TT_CLIENT_PENDING = (1 << 10), + BATADV_TT_CLIENT_TEMP= (1 << 11), +}; + +/** * enum batadv_nl_attrs - batman-adv netlink attributes * * @BATADV_ATTR_UNSPEC: unspecified attribute to catch errors @@ -33,6 +69,15 @@ * @BATADV_ATTR_HARD_IFNAME: name of the non-batman-adv interface * @BATADV_ATTR_HARD_ADDRESS: mac address of the non-batman-adv interface * @BATADV_ATTR_ACTIVE: Flag indicating if the hard interface is active + * @BATADV_ATTR_ORIG_ADDRESS: Originator MAC address + * @BATADV_ATTR_TT_ADDRESS: Client MAC address + * @BATADV_ATTR_TT_TTVN: Translation table version + * @BATADV_ATTR_TT_LAST_TTVN: Previous translation table version + * @BATADV_ATTR_TT_CRC32: CRC32 over translation table + * @BATADV_ATTR_TT_VID: VLAN ID + * @BATADV_ATTR_TT_FLAGS: Translation table client flags + * @BATADV_ATTR_FLAG_BEST: Flags indicating entry is the best + * @BATADV_ATTR_LAST_SEEN_MSECS: Time in milliseconds since last seen * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -48,6 +93,15 @@ enum batadv_nl_attrs { BATADV_ATTR_HARD_IFNAME, BATADV_ATTR_HARD_ADDRESS, BATADV_ATTR_ACTIVE, + BATADV_ATTR_ORIG_ADDRESS, + BATADV_ATTR_TT_ADDRESS, + BATADV_ATTR_TT_TTVN, + BATADV_ATTR_TT_LAST_TTVN, + BATADV_ATTR_TT_CRC32, + BATADV_ATTR_TT_VID, + BATADV_ATTR_TT_FLAGS, + BATADV_ATTR_FLAG_BEST, + BATADV_ATTR_LAST_SEEN_MSECS, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -69,6 +123,8 @@ enum batadv_nl_commands { BATADV_CMD_GET_MESH_INFO, BATADV_CMD_GET_ROUTING_ALGOS, BATADV_CMD_GET_HARDIFS, + BATADV_CMD_GET_TRANSTABLE_LOCAL, + BATADV_CMD_GET_TRANSTABLE_GLOBAL, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index bc4fcc2..cede827 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-
[B.A.T.M.A.N.] [PATCH v5 04/11] batman-adv: netlink: hardif query
From: Matthias Schiffer BATADV_CMD_GET_HARDIFS will return the list of hardifs (including index, name and MAC address) of all hardifs for a given softif. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn [sven.eckelm...@open-mesh.com: Reduce the number of changes to BATADV_CMD_GET_HARDIFS, add policy for attributes] Signed-off-by: Sven Eckelmann --- include/uapi/linux/batman_adv.h | 4 ++ net/batman-adv/netlink.c| 129 +++- 2 files changed, 131 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index d2a9740..9e7d77a 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -32,6 +32,7 @@ * @BATADV_ATTR_HARD_IFINDEX: index of the non-batman-adv interface * @BATADV_ATTR_HARD_IFNAME: name of the non-batman-adv interface * @BATADV_ATTR_HARD_ADDRESS: mac address of the non-batman-adv interface + * @BATADV_ATTR_ACTIVE: Flag indicating if the hard interface is active * @__BATADV_ATTR_AFTER_LAST: internal use * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available * @BATADV_ATTR_MAX: highest attribute number currently defined @@ -46,6 +47,7 @@ enum batadv_nl_attrs { BATADV_ATTR_HARD_IFINDEX, BATADV_ATTR_HARD_IFNAME, BATADV_ATTR_HARD_ADDRESS, + BATADV_ATTR_ACTIVE, /* add attributes above here, update the policy in netlink.c */ __BATADV_ATTR_AFTER_LAST, NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, @@ -58,6 +60,7 @@ enum batadv_nl_attrs { * @BATADV_CMD_UNSPEC: unspecified command to catch errors * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device * @BATADV_CMD_GET_ROUTING_ALGOS: Query the list of routing algorithms. + * @BATADV_CMD_GET_HARDIFS: Query list of hard interfaces * @__BATADV_CMD_AFTER_LAST: internal use * @BATADV_CMD_MAX: highest used command number */ @@ -65,6 +68,7 @@ enum batadv_nl_commands { BATADV_CMD_UNSPEC, BATADV_CMD_GET_MESH_INFO, BATADV_CMD_GET_ROUTING_ALGOS, + BATADV_CMD_GET_HARDIFS, /* add new commands above here */ __BATADV_CMD_AFTER_LAST, BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 717d7d0..bc4fcc2 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -26,16 +26,19 @@ #include #include #include +#include +#include +#include #include +#include #include #include +#include #include #include "hard-interface.h" #include "soft-interface.h" -struct sk_buff; - struct genl_family batadv_netlink_family = { .id = GENL_ID_GENERATE, .hdrsize = 0, @@ -53,9 +56,25 @@ static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 }, [BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING }, [BATADV_ATTR_HARD_ADDRESS] = { .len = ETH_ALEN }, + [BATADV_ATTR_ACTIVE]= { .type = NLA_FLAG }, }; /** + * batadv_netlink_get_ifindex - Extract an interface index from a message + * @nlh: Message header + * @attrtype: Attribute which holds an interface index + * + * Return: interface index, or 0. + */ +static int +batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype) +{ + struct nlattr *attr = nlmsg_find_attr(nlh, GENL_HDRLEN, attrtype); + + return attr ? nla_get_u32(attr) : 0; +} + +/** * batadv_netlink_mesh_info_put - fill in generic information about mesh * interface * @msg: netlink message to be sent back @@ -163,6 +182,106 @@ batadv_netlink_get_mesh_info(struct sk_buff *skb, struct genl_info *info) return genlmsg_reply(msg, info); } +/** + * batadv_netlink_dump_hardif_entry - Dump one hard interface into a message + * @msg: Netlink message to dump into + * @portid: Port making netlink request + * @seq: Sequence number of netlink message + * @hard_iface: Hard interface to dump + * + * Return: error code, or 0 on success + */ +static int +batadv_netlink_dump_hardif_entry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_hard_iface *hard_iface) +{ + struct net_device *net_dev = hard_iface->net_dev; + void *hdr; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, + BATADV_CMD_GET_HARDIFS); + if (!hdr) + return -EMSGSIZE; + + if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + net_dev->ifindex) || + nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, + net_dev->name) || + nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN, + net_dev->dev_addr)) + goto nla_put_failure; + + if (hard_iface->if_status == BATADV_IF_ACTIVE) { + if (nla_put_flag(msg, BATADV_ATT
[B.A.T.M.A.N.] [PATCH v5 02/11] batman-adv: Suppress debugfs entries for netns's
Debugfs is not netns aware. It thus has problems when the same interface name exists in multiple network name spaces. Work around this by not creating entries for interfaces in name spaces other than the default name space. This means meshes in network namespaces cannot be managed via debugfs, but there will soon be a netlink interface which is netns aware. Signed-off-by: Andrew Lunn --- net/batman-adv/debugfs.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c index f187a8f..50545b0 100644 --- a/net/batman-adv/debugfs.c +++ b/net/batman-adv/debugfs.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "bridge_loop_avoidance.h" @@ -518,12 +519,16 @@ void batadv_debugfs_destroy(void) */ int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); struct batadv_debuginfo **bat_debug; struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name, batadv_debugfs); if (!hard_iface->debug_dir) @@ -554,6 +559,11 @@ out: */ void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); + + if (net != &init_net) + return; + if (batadv_debugfs) { debugfs_remove_recursive(hard_iface->debug_dir); hard_iface->debug_dir = NULL; @@ -564,11 +574,15 @@ int batadv_debugfs_add_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); struct batadv_debuginfo **bat_debug; + struct net *net = dev_net(dev); struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); if (!bat_priv->debug_dir) goto out; @@ -605,6 +619,10 @@ out: void batadv_debugfs_del_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); + struct net *net = dev_net(dev); + + if (net != &init_net) + return; batadv_debug_log_cleanup(bat_priv); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v5 00/11] netns and netlink support
This patchset completes netns support, by disabling debugfs entries when not in the default name space, and correctly handling interface stack loops when the parent is in a different name space. It additionally adds netlink support for most of the information found in debugfs, and is netns aware. Note: BLA is still untested, so best assume it is broken... v5: * Rebase on top of master which now has basic netlink support * Complete all the kerneldoc cut/paste work requested by Sven. v4: * Fix the batctl o -i use case by actually performing the filtering on the outgoing interface v3: * Fix the compat with older kernels. It now at least compiles with 3.18.32. I've not booted it though. * Add missing kerneldoc v2: All changes requested by Sven: * Added lots of missing includes and structure forward declarations * Add two kernel doc comments * Fixed an obvious bug in BLA, but it is probably still broken... * Merged in the compat code Sven suggested. Only compile tested with 4.5.0 Andrew Lunn (5): batman-adv: Handle parent interfaces in a different netns batman-adv: Suppress debugfs entries for netns's batman-adv: add B.A.T.M.A.N. Dump gateways via netlink batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink batman-adv: Indicate netlink socket can be used with netns. Matthias Schiffer (6): batman-adv: netlink: add routing_algo query batman-adv: netlink: hardif query batman-adv: netlink: add translation table query batman-adv: netlink: add originator and neighbor table queries batman-adv: add B.A.T.M.A.N. IV bat_{orig, neigh}_dump implementations batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations compat-include/linux/netlink.h | 45 compat.h | 7 + include/uapi/linux/batman_adv.h| 91 net/batman-adv/bat_iv_ogm.c| 361 +++ net/batman-adv/bat_v.c | 337 + net/batman-adv/bridge_loop_avoidance.c | 166 +++ net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/debugfs.c | 18 ++ net/batman-adv/gateway_client.c| 148 + net/batman-adv/gateway_client.h| 2 + net/batman-adv/hard-interface.c| 50 - net/batman-adv/main.c | 66 ++ net/batman-adv/main.h | 2 + net/batman-adv/netlink.c | 200 - net/batman-adv/netlink.h | 10 + net/batman-adv/originator.c| 160 ++ net/batman-adv/originator.h| 4 + net/batman-adv/packet.h| 36 net/batman-adv/translation-table.c | 379 + net/batman-adv/translation-table.h | 4 + net/batman-adv/types.h | 9 + 21 files changed, 2057 insertions(+), 48 deletions(-) create mode 100644 compat-include/linux/netlink.h -- 2.8.0.rc3
Re: [B.A.T.M.A.N.] [PATCHv4 00/12] netns and netlink support
> I hope this helps to reduce the conflicts (even when not resolving it > completely) between the tp_meter and the netlink patchset. Hi Sven Do you want to take over my patches and merge them all into one set? Andrew
[B.A.T.M.A.N.] [PATCHv4 12/12] batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink
Dump the list of bridge loop avoidance claims via the netlink socket. Signed-off-by: Andrew Lunn --- v2: Missing includes and forward declarations Fix exit on error when dumping. --- include/uapi/linux/batman_adv.h| 6 ++ net/batman-adv/bridge_loop_avoidance.c | 166 + net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/netlink.c | 7 ++ 4 files changed, 188 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index cce4955..6a97a2c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -82,6 +82,11 @@ enum { BATADV_ATTR_BANDWIDTH_UP, BATADV_ATTR_BANDWIDTH_DOWN, BATADV_ATTR_ROUTER, + BATADV_ATTR_BLA_OWN, + BATADV_ATTR_BLA_ADDRESS, + BATADV_ATTR_BLA_VID, + BATADV_ATTR_BLA_BACKBONE, + BATADV_ATTR_BLA_CRC, __BATADV_ATTR_MAX, }; @@ -97,6 +102,7 @@ enum { BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, BATADV_CMD_GET_GATEWAYS, + BATADV_CMD_GET_BLA_CLAIM, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 748a9ea..99458f3 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -45,11 +46,17 @@ #include #include #include +#include +#include +#include +#include #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -1983,6 +1990,165 @@ out: } /** + * batadv_bla_claim_dump_entry - dump one entry of the backbone table + * to a netlink socket + * @msg: buffer for the message + * @portid: netlink port + * @seq: Sequence number of netlink message + * @primary_if: primary interface + * @claim: entry to dump + * + * Return: 0 or error code. + */ +static int +batadv_bla_claim_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hard_iface *primary_if, + struct batadv_bla_claim *claim) +{ + u8 *primary_addr = primary_if->net_dev->dev_addr; + u16 backbone_crc; + bool is_own; + void *hdr; + int ret = -EINVAL; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_BLA_CLAIM); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + is_own = batadv_compare_eth(claim->backbone_gw->orig, + primary_addr); + + spin_lock_bh(&claim->backbone_gw->crc_lock); + backbone_crc = claim->backbone_gw->crc; + spin_unlock_bh(&claim->backbone_gw->crc_lock); + + if (is_own) + if (nla_put_flag(msg, BATADV_ATTR_BLA_OWN)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_BLA_ADDRESS, ETH_ALEN, claim->addr) || + nla_put_u16(msg, BATADV_ATTR_BLA_VID, claim->vid) || + nla_put(msg, BATADV_ATTR_BLA_BACKBONE, ETH_ALEN, + claim->backbone_gw->orig) || + nla_put_u16(msg, BATADV_ATTR_BLA_CRC, + backbone_crc)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + genlmsg_end(msg, hdr); + ret = 0; + +out: + return ret; +} + +/** + * batadv_bla_claim_dump_bucket - dump one bucket of the backbone table + * to a netlink socket + * @msg: buffer for the message + * @portid: netlink port + * @seq: Sequence number of netlink message + * @primary_if: primary interface + * @head: bucket to dump + * @idx_skip: How many entries to skip + * + * Return: always 0. + */ +static int +batadv_bla_claim_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_hard_iface *primary_if, +struct hlist_head *head, int *idx_skip) +{ + struct batadv_bla_claim *claim; + int idx = 0; + + rcu_read_lock(); + hlist_for_each_entry_rcu(claim, head, hash_entry) { + if (idx++ < *idx_skip) + continue; + if (batadv_bla_claim_dump_entry(msg, portid, seq, + primary_if, claim)) { + *idx_skip = idx - 1; + goto unlock; + } + } + + *idx_skip = idx; +unlock: + rcu_read_unlock(); + return 0; +} + +/** + * batadv_bla_claim_dump - dump backbone table to a netlink socket + * @msg: buffe
[B.A.T.M.A.N.] [PATCHv4 11/12] batman-adv: add B.A.T.M.A.N. Dump gateways via netlink
Dump the list of gateways via the netlink socket. Signed-off-by: Andrew Lunn --- v2: Add missing includes and forward declarations. --- include/uapi/linux/batman_adv.h | 4 ++ net/batman-adv/gateway_client.c | 131 net/batman-adv/gateway_client.h | 2 + net/batman-adv/netlink.c| 9 ++- 4 files changed, 145 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 27f277f..cce4955 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -79,6 +79,9 @@ enum { BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, BATADV_ATTR_THROUGHPUT, + BATADV_ATTR_BANDWIDTH_UP, + BATADV_ATTR_BANDWIDTH_DOWN, + BATADV_ATTR_ROUTER, __BATADV_ATTR_MAX, }; @@ -93,6 +96,7 @@ enum { BATADV_CMD_GET_TRANSTABLE_GLOBAL, BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, + BATADV_CMD_GET_GATEWAYS, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 31ba24e..7f38aea 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -39,12 +41,18 @@ #include #include #include +#include +#include +#include +#include #include "gateway_common.h" #include "hard-interface.h" +#include "netlink.h" #include "originator.h" #include "packet.h" #include "routing.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -662,6 +670,129 @@ out: return 0; } +static int +batadv_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_gw_node *gw_node) +{ + struct batadv_neigh_ifinfo *router_ifinfo = NULL; + struct batadv_neigh_node *router; + struct batadv_gw_node *curr_gw; + int ret = -EINVAL; + void *hdr; + + router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); + if (!router) + goto out; + + router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT); + if (!router_ifinfo) + goto out; + + curr_gw = batadv_gw_get_selected_gw_node(bat_priv); + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_GATEWAYS); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + ret = -EMSGSIZE; + + if (curr_gw == gw_node) + if (nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, + gw_node->orig_node->orig) || + nla_put_u8(msg, BATADV_ATTR_TQ, router_ifinfo->bat_iv.tq_avg) || + nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN, + router->addr) || + nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, + router->if_incoming->net_dev->name) || + nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN, + gw_node->bandwidth_down) || + nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_UP, + gw_node->bandwidth_up)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + genlmsg_end(msg, hdr); + ret = 0; + +out: + if (router_ifinfo) + batadv_neigh_ifinfo_put(router_ifinfo); + if (router) + batadv_neigh_node_put(router); + return ret; +} + +int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + struct batadv_hard_iface *primary_if = NULL; + struct net *net = sock_net(cb->skb->sk); + int portid = NETLINK_CB(cb->skb).portid; + struct net_device *soft_iface = NULL; + struct batadv_gw_node *gw_node; + struct batadv_priv *bat_priv; + int idx_skip = cb->args[0]; + int ifindex; + int idx = 0; + int ret; + + ifindex = batadv_netlink_get_ifindex(cb->nlh, +BATADV_ATTR_MESH_IFINDEX); + if (!ifindex) + return -EINVAL; + + soft_iface = dev_get_by_index(net, ifindex); + if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { + ret = -ENODEV; + goto out; + } + + bat_priv = netdev_priv(soft_iface); + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { +
[B.A.T.M.A.N.] [PATCHv5] batctl: Use netlink to replace some of debugfs
The kernel has gained support for exporting some information via netlink. Use this when available, rather than debugfs. If netlink is not available, or the information is not yet available via netlink, batctl will fall back to debugfs. Signed-off-by: Andrew Lunn --- v2: Verify mandatory attributes are returned by the kernel, and that they have the expected size. v3: Use libnl to perform more verification Add originator header checkpatch cleanup v4: Add the missing netlink.h to the patch v5: Handle -i flag to originators Handle -u and -m flag to tg and tl Fix type of BATADV_ATTR_THROUGHPUT --- Makefile | 13 +- batman_adv.h | 111 +++ debug.c | 22 +- debug.h |4 +- functions.c | 11 + functions.h |2 + main.h |1 + netlink.c| 1050 ++ netlink.h| 40 +++ 9 files changed, 1250 insertions(+), 4 deletions(-) create mode 100644 batman_adv.h create mode 100644 netlink.c create mode 100644 netlink.h diff --git a/Makefile b/Makefile index b82c0c6..60795f7 100755 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ export CONFIG_BATCTL_BISECT=n # batctl build BINARY_NAME = batctl -OBJ = main.o bat-hosts.o functions.o sys.o debug.o ping.o traceroute.o tcpdump.o hash.o debugfs.o ioctl.o list-batman.o translate.o +OBJ = main.o bat-hosts.o functions.o sys.o debug.o ping.o traceroute.o tcpdump.o hash.o debugfs.o ioctl.o list-batman.o translate.o netlink.o OBJ_BISECT = bisect_iv.o MANPAGE = man/batctl.8 @@ -61,6 +61,17 @@ endif CFLAGS += $(LIBNL_CFLAGS) LDLIBS += $(LIBNL_LDLIBS) +ifeq ($(origin LIBNL_GENL_CFLAGS) $(origin LIBNL_GENL_LDLIBS), undefined undefined) + LIBNL_GENL_NAME ?= libnl-genl-3.0 + ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_GENL_NAME) 2>/dev/null),) +$(error No $(LIBNL_GENL_NAME) development libraries found!) + endif + LIBNL_GENL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBNL_GENL_NAME)) + LIBNL_GENL_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBNL_GENL_NAME)) +endif +CFLAGS += $(LIBNL_GENL_CFLAGS) +LDLIBS += $(LIBNL_GENL_LDLIBS) + # standard build tools ifeq ($(CONFIG_BATCTL_BISECT),y) OBJ += $(OBJ_BISECT) diff --git a/batman_adv.h b/batman_adv.h new file mode 100644 index 000..6a97a2c --- /dev/null +++ b/batman_adv.h @@ -0,0 +1,111 @@ +/* Copyright (C) 2016 B.A.T.M.A.N. contributors: + * + * Matthias Schiffer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _UAPI_LINUX_BATMAN_ADV_H_ +#define _UAPI_LINUX_BATMAN_ADV_H_ + +#define BATADV_NL_NAME "batadv" + +/** + * enum batadv_tt_client_flags - TT client specific flags + * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table + * @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new + * update telling its new real location has not been received/sent yet + * @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface. + * This information is used by the "AP Isolation" feature + * @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This + * information is used by the Extended Isolation feature + * @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table + * @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has + * not been announced yet + * @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept + * in the table for one more originator interval for consistency purposes + * @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of + * the network but no nnode has already announced it + * + * Bits from 0 to 7 are called _remote flags_ because they are sent on the wire. + * Bits from 8 to 15 are called _local flags_ because they are used for local + * computations only. + * + * Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with + * the other nodes in the network. To achieve this goal these flags are included + * in the TT CRC computation. + */ +enum batadv_tt_client_flags { + BATADV_TT_CLIENT_DEL = (1 << 0), + BATADV_TT_CLIENT_ROAM= (1 << 1), + BATADV_TT_CLIENT_WIFI= (1 << 4), + BATADV_TT_CLIENT_ISOLA = (1 << 5), + BATADV_TT_CLIENT_NOPURGE = (1 << 8), + BATADV_TT_CLIENT_NEW = (1 << 9), + BATADV_TT_CLIENT_PEN
[B.A.T.M.A.N.] [PATCHv4 10/12] batman-adv: Indicate netlink socket can be used with netns.
Set the netnsof flag on the family structure, indicating it can be used with different network name spaces. Signed-off-by: Andrew Lunn --- net/batman-adv/netlink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index a01bdf5..e188c2b 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -44,6 +44,7 @@ struct genl_family batadv_netlink_family = { .name = BATADV_NL_NAME, .version = 1, .maxattr = BATADV_ATTR_MAX, + .netnsok = true, }; static int -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCHv4 04/12] batman-adv: add generic netlink query API to replace debugfs files
From: Matthias Schiffer debugfs is currently severely broken virtually everywhere in the kernel where files are dynamically added and removed (see http://lkml.iu.edu/hypermail/linux/kernel/1506.1/02196.html for some details). In addition to that, debugfs is not namespace-aware. Also, the debugfs interface will try to fix the whole list of originators/ TT entries into a single buffer. The situation has improved in recent kernels,as the seq_file infrastructure will fall back to vmalloc now when kmalloc fails. Still, converting all information to text and potentially retrying multiple times until the buffer is big enough is very inefficient. This commit adds generic infrastructur for the netlink interface to batman-adv and implements the following command: * BATADV_CMD_GET_ROUTING_ALGOS: will return the list of supported routing algorithms * BATADV_CMD_GET_MESH_INFO: will return basic information about a batman-adv softif (name, index and MAC address for both the softif and the primary hardif; routing algorithm; batman-adv version) * BATADV_CMD_GET_HARDIFS: will return the list of hardifs (including index, name and MAC address) of all hardifs for a given softif Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Added missing includes and forward declarations of structures. --- Makefile| 1 + include/uapi/linux/batman_adv.h | 49 net/batman-adv/Makefile | 1 + net/batman-adv/main.c | 51 net/batman-adv/main.h | 2 + net/batman-adv/netlink.c| 260 net/batman-adv/netlink.h| 41 +++ 7 files changed, 405 insertions(+) create mode 100644 include/uapi/linux/batman_adv.h create mode 100644 net/batman-adv/netlink.c create mode 100644 net/batman-adv/netlink.h diff --git a/Makefile b/Makefile index 5d2c058..f17bde5 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ REVISION= $(shell if [ -d "$(PWD)/.git" ]; then \ fi) export NOSTDINC_FLAGS := \ -I$(PWD)/compat-include/ \ + -I$(PWD)/include/ \ -include $(PWD)/compat.h \ $(CFLAGS) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h new file mode 100644 index 000..b9b7dfd --- /dev/null +++ b/include/uapi/linux/batman_adv.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2016 B.A.T.M.A.N. contributors: + * + * Matthias Schiffer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _UAPI_LINUX_BATMAN_ADV_H_ +#define _UAPI_LINUX_BATMAN_ADV_H_ + +#define BATADV_NL_NAME "batadv" + +enum { + BATADV_ATTR_UNSPEC, + BATADV_ATTR_VERSION, + BATADV_ATTR_ALGO_NAME, + BATADV_ATTR_MESH_IFINDEX, + BATADV_ATTR_MESH_IFNAME, + BATADV_ATTR_MESH_ADDRESS, + BATADV_ATTR_HARD_IFINDEX, + BATADV_ATTR_HARD_IFNAME, + BATADV_ATTR_HARD_ADDRESS, + BATADV_ATTR_ACTIVE, + __BATADV_ATTR_MAX, +}; + +#define BATADV_ATTR_MAX (__BATADV_ATTR_MAX - 1) + +enum { + BATADV_CMD_UNSPEC, + BATADV_CMD_GET_ROUTING_ALGOS, + BATADV_CMD_GET_MESH_INFO, + BATADV_CMD_GET_HARDIFS, + __BATADV_CMD_MAX, +}; + +#define BATADV_CMD_MAX (__BATADV_CMD_MAX - 1) + +#endif /* _UAPI_LINUX_BATMAN_ADV_H_ */ diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile index 797cf2f..4e5adba 100644 --- a/net/batman-adv/Makefile +++ b/net/batman-adv/Makefile @@ -33,6 +33,7 @@ batman-adv-y += hash.o batman-adv-y += icmp_socket.o batman-adv-y += main.o batman-adv-$(CONFIG_BATMAN_ADV_MCAST) += multicast.o +batman-adv-y += netlink.o batman-adv-$(CONFIG_BATMAN_ADV_NC) += network-coding.o batman-adv-y += originator.o batman-adv-y += routing.o diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index 627d14e..3127d28 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,10 @@ #include #include #include +#include +#include #include +#include #include "bat_algo.h" #include "bridge_loop_avoidance.h" @@ -57,6 +61,7 @@ #include "hard-interface.h" #include "icmp_socket.h" #include "multicast.h" +#include "netlink.h" #include "network-coding.h" #include "originator.h" #include "packet.h" @@
[B.A.T.M.A.N.] [PATCHv4 06/12] batman-adv: netlink: add translation table query
From: Matthias Schiffer This adds the commands BATADV_CMD_GET_TRANSTABLE_LOCAL and BATADV_CMD_GET_TRANSTABLE_GLOBAL, which correspond to the transtable_local and transtable_global debugfs files. The batadv_tt_client_flags enum is moved to the UAPI to expose it as part of the netlink API. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Add missing header files. --- include/uapi/linux/batman_adv.h| 47 ++ net/batman-adv/netlink.c | 13 ++ net/batman-adv/packet.h| 36 - net/batman-adv/translation-table.c | 308 + net/batman-adv/translation-table.h | 4 + 5 files changed, 372 insertions(+), 36 deletions(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index b9b7dfd..25dee3c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -20,6 +20,42 @@ #define BATADV_NL_NAME "batadv" +/** + * enum batadv_tt_client_flags - TT client specific flags + * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table + * @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new + * update telling its new real location has not been received/sent yet + * @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface. + * This information is used by the "AP Isolation" feature + * @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This + * information is used by the Extended Isolation feature + * @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table + * @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has + * not been announced yet + * @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept + * in the table for one more originator interval for consistency purposes + * @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of + * the network but no nnode has already announced it + * + * Bits from 0 to 7 are called _remote flags_ because they are sent on the wire. + * Bits from 8 to 15 are called _local flags_ because they are used for local + * computations only. + * + * Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with + * the other nodes in the network. To achieve this goal these flags are included + * in the TT CRC computation. + */ +enum batadv_tt_client_flags { + BATADV_TT_CLIENT_DEL = (1 << 0), + BATADV_TT_CLIENT_ROAM= (1 << 1), + BATADV_TT_CLIENT_WIFI= (1 << 4), + BATADV_TT_CLIENT_ISOLA = (1 << 5), + BATADV_TT_CLIENT_NOPURGE = (1 << 8), + BATADV_TT_CLIENT_NEW = (1 << 9), + BATADV_TT_CLIENT_PENDING = (1 << 10), + BATADV_TT_CLIENT_TEMP= (1 << 11), +}; + enum { BATADV_ATTR_UNSPEC, BATADV_ATTR_VERSION, @@ -31,6 +67,15 @@ enum { BATADV_ATTR_HARD_IFNAME, BATADV_ATTR_HARD_ADDRESS, BATADV_ATTR_ACTIVE, + BATADV_ATTR_ORIG_ADDRESS, + BATADV_ATTR_TT_ADDRESS, + BATADV_ATTR_TT_TTVN, + BATADV_ATTR_TT_LAST_TTVN, + BATADV_ATTR_TT_CRC32, + BATADV_ATTR_TT_VID, + BATADV_ATTR_TT_FLAGS, + BATADV_ATTR_FLAG_BEST, + BATADV_ATTR_LAST_SEEN_MSECS, __BATADV_ATTR_MAX, }; @@ -41,6 +86,8 @@ enum { BATADV_CMD_GET_ROUTING_ALGOS, BATADV_CMD_GET_MESH_INFO, BATADV_CMD_GET_HARDIFS, + BATADV_CMD_GET_TRANSTABLE_LOCAL, + BATADV_CMD_GET_TRANSTABLE_GLOBAL, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index e302de3..3fb1c1f 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -35,6 +35,7 @@ #include "hard-interface.h" #include "soft-interface.h" +#include "translation-table.h" struct genl_family batadv_netlink_family = { .id = GENL_ID_GENERATE, @@ -242,6 +243,18 @@ static struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_netlink_dump_hardifs, }, + { + .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_tt_local_dump, + }, + { + .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_tt_global_dump, + }, }; void __init batadv_netlink_register(void) diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h index 372128d..b45460d 100644 --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h @@ -126,42 +126,6 @@ enum batadv_tt_data_flags { }; /** - * enum batadv_tt_client_flags - TT client specific flags - * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the tabl
[B.A.T.M.A.N.] [PATCHv4 09/12] batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Add missing includes --- include/uapi/linux/batman_adv.h | 1 + net/batman-adv/bat_iv_ogm.c | 3 + net/batman-adv/bat_v.c | 262 3 files changed, 266 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index baf4ac8..27f277f 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -78,6 +78,7 @@ enum { BATADV_ATTR_LAST_SEEN_MSECS, BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, + BATADV_ATTR_THROUGHPUT, __BATADV_ATTR_MAX, }; diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 632e60a..9abfdbb 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,8 @@ #include #include #include +#include +#include #include #include "bitarray.h" diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index c16cd44..5daa300 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c @@ -20,24 +20,33 @@ #include #include +#include +#include #include #include #include #include +#include #include #include #include #include #include #include +#include +#include +#include #include "bat_v_elp.h" #include "bat_v_ogm.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +struct sk_buff; + static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface) { struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); @@ -203,6 +212,107 @@ static void batadv_v_neigh_print(struct batadv_priv *bat_priv, seq_puts(seq, "No batman nodes in range ...\n"); } +static int +batadv_v_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hardif_neigh_node *hardif_neigh) +{ + void *hdr; + unsigned int last_seen_msecs; + u32 throughput; + + last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen); + throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); + throughput = throughput * 100; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, + BATADV_CMD_GET_NEIGHBORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + hardif_neigh->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + hardif_neigh->if_incoming->net_dev->ifindex) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs) || + nla_put_u32(msg, BATADV_ATTR_THROUGHPUT, throughput)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +static int +batadv_v_neigh_dump_hardif(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *hard_iface, + int *idx_s) +{ + struct batadv_hardif_neigh_node *hardif_neigh; + int idx = 0; + + hlist_for_each_entry_rcu(hardif_neigh, +&hard_iface->neigh_list, list) { + if (idx++ < *idx_s) + continue; + + if (batadv_v_neigh_dump_neigh(msg, portid, seq, hardif_neigh)) { + *idx_s = idx - 1; + return -EMSGSIZE; + } + } + + *idx_s = 0; + return 0; +} + +static void +batadv_v_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *single_hardif) +{ + struct batadv_hard_iface *hard_iface; + int i_hardif = 0; + int i_hardif_s = cb->args[0]; + int idx = cb->args[1]; + int portid = NETLINK_CB(cb->skb).portid; + + rcu_read_lock(); + if (single_hardif) { + if (i_hardif_s == 0) { + if (batadv_v_neigh_dump_hardif(msg, portid, + cb->nlh->nlmsg_seq, + bat_priv, single_hardif, + &idx) == 0) + i_hardif++; + } + } else { + list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { +
[B.A.T.M.A.N.] [PATCHv4 07/12] batman-adv: netlink: add originator and neighbor table queries
From: Matthias Schiffer Add BATADV_CMD_GET_ORIGINATORS and BATADV_CMD_GET_NEIGHBORS commands, using handlers bat_orig_dump and bat_neigh_dump in batadv_algo_ops. Will always return -EOPNOTSUPP for now, as no implementations exist yet. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Add missing includes and forward declarations Add kernel doc to the two dump functions. v3: Add kernel doc for new members in batadv_algo_ops --- include/uapi/linux/batman_adv.h | 2 + net/batman-adv/netlink.c| 14 net/batman-adv/originator.c | 161 net/batman-adv/originator.h | 4 + net/batman-adv/types.h | 9 +++ 5 files changed, 190 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 25dee3c..35d8e8c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -88,6 +88,8 @@ enum { BATADV_CMD_GET_HARDIFS, BATADV_CMD_GET_TRANSTABLE_LOCAL, BATADV_CMD_GET_TRANSTABLE_GLOBAL, + BATADV_CMD_GET_ORIGINATORS, + BATADV_CMD_GET_NEIGHBORS, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 3fb1c1f..a01bdf5 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -33,6 +33,7 @@ #include #include +#include "originator.h" #include "hard-interface.h" #include "soft-interface.h" #include "translation-table.h" @@ -222,6 +223,7 @@ batadv_netlink_dump_hardifs(struct sk_buff *msg, struct netlink_callback *cb) static struct nla_policy batadv_netlink_policy[BATADV_ATTR_MAX + 1] = { [BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 }, + [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 }, }; static struct genl_ops batadv_netlink_ops[] = { @@ -255,6 +257,18 @@ static struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_tt_global_dump, }, + { + .cmd = BATADV_CMD_GET_ORIGINATORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_orig_dump, + }, + { + .cmd = BATADV_CMD_GET_NEIGHBORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_hardif_neigh_dump, + }, }; void __init batadv_netlink_register(void) diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index 076d258..0455e54 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c @@ -28,11 +28,15 @@ #include #include #include +#include #include #include +#include #include #include #include +#include +#include #include "distributed-arp-table.h" #include "fragmentation.h" @@ -40,8 +44,10 @@ #include "hard-interface.h" #include "hash.h" #include "multicast.h" +#include "netlink.h" #include "network-coding.h" #include "routing.h" +#include "soft-interface.h" #include "translation-table.h" /* hash class keys */ @@ -719,6 +725,83 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset) } /** + * batadv_hardif_neigh_dump - Dump to netlink the neighbor infos for a specific + * outgoing interface + * @msg: message to dump into + * @cb: parameters for the dump + * + * Return: 0 or error value + */ +int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + struct net *net = sock_net(cb->skb->sk); + struct net_device *soft_iface = NULL; + struct net_device *hard_iface = NULL; + struct batadv_hard_iface *hardif = BATADV_IF_DEFAULT; + struct batadv_priv *bat_priv; + struct batadv_hard_iface *primary_if = NULL; + int ret; + int ifindex, hard_ifindex; + + ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX); + if (!ifindex) + return -EINVAL; + + soft_iface = dev_get_by_index(net, ifindex); + if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { + ret = -ENODEV; + goto out; + } + + bat_priv = netdev_priv(soft_iface); + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { + ret = -ENOENT; + goto out; + } + + hard_ifindex = batadv_netlink_get_ifindex(cb->nlh, + BATADV_ATTR_HARD_IFINDEX); + if (hard_ifindex) { + hard_iface = dev_get_by_index(net, hard_ifindex); + if (hard_iface) + hardif = batadv_hardif_get_by_netdev(hard_iface); + + if (!hardif) { +
[B.A.T.M.A.N.] [PATCHv4 05/12] batman-adv: compat: Workarounds for previous patch
* NETLINK_CB portid changed name * info->snd_portid changed name * genl_register_family_with_ops implementation Signed-off-by: Sven Eckelmann Signed-off-by: Andrew Lunn --- compat-include/linux/netlink.h | 45 ++ compat-include/net/genetlink.h | 34 +++ compat.h | 6 ++ 3 files changed, 85 insertions(+) create mode 100644 compat-include/linux/netlink.h create mode 100644 compat-include/net/genetlink.h diff --git a/compat-include/linux/netlink.h b/compat-include/linux/netlink.h new file mode 100644 index 000..696f6da --- /dev/null +++ b/compat-include/linux/netlink.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ + +#include +#include_next + +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) + +struct batadv_netlink_skb_parms { + struct ucredcreds; /* Skb credentials */ + union { + __u32 portid; + __u32 pid; + }; + __u32 dst_group; +}; + +#undef NETLINK_CB +#define NETLINK_CB(skb) (*(struct batadv_netlink_skb_parms*)&((skb)->cb)) + +#endif /* < KERNEL_VERSION(3, 7, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ */ diff --git a/compat-include/net/genetlink.h b/compat-include/net/genetlink.h new file mode 100644 index 000..bf1ba3d --- /dev/null +++ b/compat-include/net/genetlink.h @@ -0,0 +1,34 @@ +/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_NET_GENETLINK_H_ +#define _NET_BATMAN_ADV_COMPAT_NET_GENETLINK_H_ + +#include +#include_next + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0) + +#define genl_register_family_with_ops(family, ops) \ + genl_register_family_with_ops((family), (ops), ARRAY_SIZE(ops)) + +#endif /* < KERNEL_VERSION(3, 13, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_NET_GENETLINK_H_ */ diff --git a/compat.h b/compat.h index 813e637..ac4f7a0 100644 --- a/compat.h +++ b/compat.h @@ -62,6 +62,12 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\ #endif /* < KERNEL_VERSION(3, 3, 0) */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) + +#define snd_portid snd_pid + +#endif /* < KERNEL_VERSION(3, 7, 0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) #define batadv_interface_set_mac_addr(x, y) \ -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCHv4 03/12] batman-adv: Suppress debugfs entries for netns's
Debugfs is not netns aware. It thus has problems when the same interface name exists in multiple network name spaces. Work around this by not creating entries for interfaces in name spaces other than the default name space. This means meshes in network namespaces cannot be managed via debugfs, but there will soon be a netlink interface which is netns aware. Signed-off-by: Andrew Lunn --- v2: Fix accidental change to __printf Add missing includes. --- net/batman-adv/debugfs.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c index 9529004..e54f0da 100644 --- a/net/batman-adv/debugfs.c +++ b/net/batman-adv/debugfs.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "bridge_loop_avoidance.h" @@ -495,12 +496,16 @@ void batadv_debugfs_destroy(void) */ int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); struct batadv_debuginfo **bat_debug; struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name, batadv_debugfs); if (!hard_iface->debug_dir) @@ -531,6 +536,11 @@ out: */ void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); + + if (net != &init_net) + return; + if (batadv_debugfs) { debugfs_remove_recursive(hard_iface->debug_dir); hard_iface->debug_dir = NULL; @@ -541,11 +551,15 @@ int batadv_debugfs_add_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); struct batadv_debuginfo **bat_debug; + struct net *net = dev_net(dev); struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); if (!bat_priv->debug_dir) goto out; @@ -582,6 +596,10 @@ out: void batadv_debugfs_del_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); + struct net *net = dev_net(dev); + + if (net != &init_net) + return; batadv_debug_log_cleanup(bat_priv); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCHv4 00/12] netns and netlink support
This patchset completes netns support, by disabling debugfs entries when not in the default name space, and correctly handling interface stack loops when the parent is in a different name space. It additionally adds netlink support for most of the information found in debugfs, and is netns awaire. Note: BLA is still untested, so best assume it is broken... v4: * Fix the batctl o -i use case by actually performing the filtering on the outgoing interface v3: * Fix the compat with older kernels. It now at least compiles with 3.18.32. I've not booted it though. * Add missing kerneldoc v2: All changes requested by Sven: * Added lots of missing includes and structure forward declarations * Add two kernel doc comments * Fixed an obvious bug in BLA, but it is probably still broken... * Merged in the compat code Sven suggested. Only compile tested with 4.5.0 Andrew Lunn (7): batman-adv: Handle parent interfaces in a different netns batman-adv: compat.h: Add workaround for get_link_net() batman-adv: Suppress debugfs entries for netns's batman-adv: compat: Workarounds for previous patch batman-adv: Indicate netlink socket can be used with netns. batman-adv: add B.A.T.M.A.N. Dump gateways via netlink batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink Matthias Schiffer (5): batman-adv: add generic netlink query API to replace debugfs files batman-adv: netlink: add translation table query batman-adv: netlink: add originator and neighbor table queries batman-adv: add B.A.T.M.A.N. IV bat_{orig, neigh}_dump implementations batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations Makefile | 1 + compat-include/linux/netlink.h | 45 + compat-include/net/genetlink.h | 34 compat.h | 13 ++ include/uapi/linux/batman_adv.h| 111 net/batman-adv/Makefile| 1 + net/batman-adv/bat_iv_ogm.c| 277 + net/batman-adv/bat_v.c | 262 net/batman-adv/bridge_loop_avoidance.c | 166 ++ net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/debugfs.c | 18 ++ net/batman-adv/gateway_client.c| 131 ++ net/batman-adv/gateway_client.h| 2 + net/batman-adv/hard-interface.c| 50 +- net/batman-adv/main.c | 51 ++ net/batman-adv/main.h | 2 + net/batman-adv/netlink.c | 302 net/batman-adv/netlink.h | 41 + net/batman-adv/originator.c| 161 + net/batman-adv/originator.h| 4 + net/batman-adv/packet.h| 36 net/batman-adv/translation-table.c | 308 + net/batman-adv/translation-table.h | 4 + net/batman-adv/types.h | 9 + 24 files changed, 1995 insertions(+), 44 deletions(-) create mode 100644 compat-include/linux/netlink.h create mode 100644 compat-include/net/genetlink.h create mode 100644 include/uapi/linux/batman_adv.h create mode 100644 net/batman-adv/netlink.c create mode 100644 net/batman-adv/netlink.h -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCHv4 01/12] batman-adv: Handle parent interfaces in a different netns
batman-adv tries to prevent the user from placing a batX soft interface into another batman mesh as a hard interface. It does this by walking up the devices list of parents and ensures they are all none batX interfaces. iflink can point to an interface in a different namespace, so also retrieve the parents name space when finding the parent and use it when doing the comparison. Signed-off-by: Andrew Lunn Signed-off-by: Sven Eckelmann Acked-by: Antonio Quartulli --- v2: Add missing header files Use Sven's code to facilitate a compat.h change v3: More of Sven's code to facilitate a compat.h --- net/batman-adv/hard-interface.c | 50 +++-- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index db2009d..5592f4a 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include "bridge_loop_avoidance.h" #include "debugfs.h" @@ -83,25 +85,55 @@ out: } /** + * batadv_getlink_net - return link net namespace (of use fallback) + * @netdev: net_device to check + * @fallback_net: return in case get_link_net is not available for @netdev + * + * Return: result of rtnl_link_ops->get_link_net or @fallback_net + */ +static const struct net *batadv_getlink_net(const struct net_device *netdev, + const struct net *fallback_net) +{ + if (!netdev->rtnl_link_ops) + return fallback_net; + + if (!netdev->rtnl_link_ops->get_link_net) + return fallback_net; + + return netdev->rtnl_link_ops->get_link_net(netdev); +} + +/** * batadv_mutual_parents - check if two devices are each others parent - * @dev1: 1st net_device - * @dev2: 2nd net_device + * @dev1: 1st net dev + * @net1: 1st devices netns + * @dev2: 2nd net dev + * @net2: 2nd devices netns * * veth devices come in pairs and each is the parent of the other! * * Return: true if the devices are each others parent, otherwise false */ static bool batadv_mutual_parents(const struct net_device *dev1, - const struct net_device *dev2) + const struct net *net1, + const struct net_device *dev2, + const struct net *net2) { int dev1_parent_iflink = dev_get_iflink(dev1); int dev2_parent_iflink = dev_get_iflink(dev2); + const struct net *dev1_parent_net; + const struct net *dev2_parent_net; + + dev1_parent_net = batadv_getlink_net(dev1, net1); + dev2_parent_net = batadv_getlink_net(dev2, net2); if (!dev1_parent_iflink || !dev2_parent_iflink) return false; return (dev1_parent_iflink == dev2->ifindex) && - (dev2_parent_iflink == dev1->ifindex); + (dev2_parent_iflink == dev1->ifindex) && + net_eq(dev1_parent_net, net2) && + net_eq(dev2_parent_net, net1); } /** @@ -119,8 +151,9 @@ static bool batadv_mutual_parents(const struct net_device *dev1, */ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) { - struct net_device *parent_dev; struct net *net = dev_net(net_dev); + struct net_device *parent_dev; + const struct net *parent_net; bool ret; /* check if this is a batman-adv mesh interface */ @@ -132,13 +165,16 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) dev_get_iflink(net_dev) == net_dev->ifindex) return false; + parent_net = batadv_getlink_net(net_dev, net); + /* recurse over the parent device */ - parent_dev = __dev_get_by_index(net, dev_get_iflink(net_dev)); + parent_dev = __dev_get_by_index((struct net *)parent_net, + dev_get_iflink(net_dev)); /* if we got a NULL parent_dev there is something broken.. */ if (WARN(!parent_dev, "Cannot find parent device")) return false; - if (batadv_mutual_parents(net_dev, parent_dev)) + if (batadv_mutual_parents(net_dev, net, parent_dev, parent_net)) return false; ret = batadv_is_on_batman_iface(parent_dev); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCHv4 02/12] batman-adv: compat.h: Add workaround for get_link_net()
Signed-off-by: Sven Eckelmann Signed-off-by: Andrew Lunn --- v2: Fix accidental newline deletion --- compat.h | 7 +++ 1 file changed, 7 insertions(+) diff --git a/compat.h b/compat.h index 5a5f478..813e637 100644 --- a/compat.h +++ b/compat.h @@ -140,6 +140,13 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\ #endif /* < KERNEL_VERSION(3, 15, 0) */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) + +/* WARNING for batadv_getlink_net */ +#define get_link_net get_xstats_size || 0 || netdev->rtnl_link_ops->get_xstats_size + +#endif /* < KERNEL_VERSION(4, 0, 0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) #define IFF_NO_QUEUE 0; dev->tx_queue_len = 0 -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCHv4 08/12] batman-adv: add B.A.T.M.A.N. IV bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Signed-off-by: Matthias Schiffer --- include/uapi/linux/batman_adv.h | 2 + net/batman-adv/bat_iv_ogm.c | 274 2 files changed, 276 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 35d8e8c..baf4ac8 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -76,6 +76,8 @@ enum { BATADV_ATTR_TT_FLAGS, BATADV_ATTR_FLAG_BEST, BATADV_ATTR_LAST_SEEN_MSECS, + BATADV_ATTR_NEIGH_ADDRESS, + BATADV_ATTR_TQ, __BATADV_ATTR_MAX, }; diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index 4815db9..632e60a 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -48,10 +48,12 @@ #include #include #include +#include #include "bitarray.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "network-coding.h" #include "originator.h" #include "packet.h" @@ -1975,6 +1977,177 @@ next: seq_puts(seq, "No batman nodes in range ...\n"); } +static bool +batadv_iv_ogm_neigh_get_tq_avg(struct batadv_neigh_node *neigh_node, + struct batadv_hard_iface *if_outgoing, + u8 *tq_avg) +{ + struct batadv_neigh_ifinfo *n_ifinfo; + + n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); + if (!n_ifinfo) + return false; + + *tq_avg = n_ifinfo->bat_iv.tq_avg; + batadv_neigh_ifinfo_put(n_ifinfo); + + return true; +} + +static int +batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_hard_iface *if_outgoing, +struct batadv_orig_node *orig_node, +struct batadv_neigh_node *neigh_node, +bool best) +{ + void *hdr; + u8 tq_avg; + unsigned int last_seen_msecs; + + last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen); + + if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node, if_outgoing, &tq_avg)) + return 0; + + if (if_outgoing != BATADV_IF_DEFAULT && + if_outgoing != neigh_node->if_incoming) + return 0; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_ORIGINATORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, + orig_node->orig) || + nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + neigh_node->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + neigh_node->if_incoming->net_dev->ifindex) || + nla_put_u8(msg, BATADV_ATTR_TQ, tq_avg) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs)) + goto nla_put_failure; + + if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +static int +batadv_iv_ogm_orig_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *if_outgoing, + struct batadv_orig_node *orig_node, int *sub_s) +{ + struct batadv_neigh_node *neigh_node_best; + struct batadv_neigh_node *neigh_node; + int sub = 0; + bool best; + u8 tq_avg_best; + + neigh_node_best = batadv_orig_router_get(orig_node, if_outgoing); + if (!neigh_node_best) + goto out; + + if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node_best, if_outgoing, + &tq_avg_best)) + goto out; + + if (tq_avg_best == 0) + goto out; + + hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { + if (sub++ < *sub_s) + continue; + + best = (neigh_node == neigh_node_best); + + if (batadv_iv_ogm_orig_dump_subentry(msg, portid, seq, +bat_priv, if_outgoing, +orig_node, neigh_node, +best)) { + batadv_neigh_node_put(neigh_node_best); + + *sub_s = sub - 1; + return -EMSGSIZE; + } + } + + out: + if (neigh_node_best) + batadv_neigh_node_put(neigh_node_best); + + *sub_s = 0; + return 0; +} + +static int +batadv_
[B.A.T.M.A.N.] [PATCH 2/2] batman-adv: Include frame priority in fragment header
Unfragmented frames which traverse a node have their skb->priority set by looking at the IP ToS byte, or the 802.1p header. However for fragments this is not possible, only one of the fragments will contain the headers. Instead, place the priority into the fragment header and on receiving a fragment, use this information to set the skb->priority for when the fragment is forwarded. Signed-off-by: Andrew Lunn --- net/batman-adv/fragmentation.c | 2 ++ net/batman-adv/packet.h| 7 +-- net/batman-adv/routing.c | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c index a3fefbd..c703767 100644 --- a/net/batman-adv/fragmentation.c +++ b/net/batman-adv/fragmentation.c @@ -473,6 +473,8 @@ bool batadv_frag_send_packet(struct sk_buff *skb, frag_header.reserved = 0; frag_header.no = 0; frag_header.total_size = htons(skb->len); + if (skb->priority >= 256 && skb->priority <= 263) + frag_header.priority = skb->priority - 256; ether_addr_copy(frag_header.orig, primary_if->net_dev->dev_addr); ether_addr_copy(frag_header.dest, orig_node->orig); diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h index b45460d..7acc6a2 100644 --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h @@ -384,6 +384,7 @@ struct batadv_unicast_4addr_packet { * @dest: final destination used when routing fragments * @orig: originator of the fragment used when merging the packet * @no: fragment number within this sequence + * @priority: priority of frame, from ToS IP precedence or 802.1p * @reserved: reserved byte for alignment * @seqno: sequence identification * @total_size: size of the merged packet @@ -394,9 +395,11 @@ struct batadv_frag_packet { u8 ttl; #if defined(__BIG_ENDIAN_BITFIELD) u8 no:4; - u8 reserved:4; + u8 priority:3; + u8 reserved:1; #elif defined(__LITTLE_ENDIAN_BITFIELD) - u8 reserved:4; + u8 reserved:1; + u8 priority:3; u8 no:4; #else #error "unknown bitfield endianness" diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index ae850f2..01d36e3 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c @@ -1004,6 +1004,8 @@ int batadv_recv_frag_packet(struct sk_buff *skb, if (!orig_node_src) goto out; + skb->priority = frag_packet->priority + 256; + /* Route the fragment if it is not for us and too big to be merged. */ if (!batadv_is_my_mac(bat_priv, frag_packet->dest) && batadv_frag_skb_fwd(skb, recv_if, orig_node_src)) { -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH 1/2] batman-adv: Set skb priority in fragments
BATMAN will set the skb->priority based on the IP precedence or 802.1q tag. However, if it needs to fragment the frame, it currently leaves the fragment skb with the default priority and actually overwrites the priority in the unfragmented frame. Fix this. Signed-off-by: Andrew Lunn --- net/batman-adv/fragmentation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c index 65536db..a3fefbd 100644 --- a/net/batman-adv/fragmentation.c +++ b/net/batman-adv/fragmentation.c @@ -414,7 +414,7 @@ static struct sk_buff *batadv_frag_create(struct sk_buff *skb, if (!skb_fragment) goto err; - skb->priority = TC_PRIO_CONTROL; + skb_fragment->priority = skb->priority; /* Eat the last mtu-bytes of the skb */ skb_reserve(skb_fragment, header_size + ETH_HLEN); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH 0/2] Fragments and QoS
BATMAN currently does not allow QoS policies to be used with fragmented packets. The first patch copies the skb priority from the unfragmented packet into the fragments as they are built, so the lower layers can then prioritise as appropriated. The second patch places the priority into the fragment header, and upon reception of a fragment, copies it into the skb priority, so that when the fragment is retransmitted, it is correctly prioritised. Andrew Lunn (2): batman-adv: Set skb priority in fragments batman-adv: Include frame priority in fragment header net/batman-adv/fragmentation.c | 4 +++- net/batman-adv/packet.h| 7 +-- net/batman-adv/routing.c | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) -- 2.8.0.rc3
Re: [B.A.T.M.A.N.] [PATCHv4] batctl: Use netlink to replace some of debugfs
On Mon, May 09, 2016 at 06:28:29PM +0200, Sven Eckelmann wrote: > On Wednesday 04 May 2016 16:30:07 Andrew Lunn wrote: > > + [BATADV_ATTR_THROUGHPUT]= { .type = NLA_FLAG }, > > Why is throughput a flag when you access it with > > throughput_kbits = nla_get_u32(attrs[BATADV_ATTR_THROUGHPUT]); > > Most likely just a copy+paste error and it should be NLA_U32. Yep, thanks. Andrew
Re: [B.A.T.M.A.N.] [PATCHv4] batctl: Use netlink to replace some of debugfs
> This is actually a report of a possible problem by Simon (I've only > checked it): Hi Sven, Simon > It looks like the orig_iface handling isn't handled here (see > handle_debug_table "case 'i'") or am I missing something? Yes, the -i handling is missing. Also -m and -u for translocal and transglobal. I will fix this up. Andrew
[B.A.T.M.A.N.] [PATCHv4] batctl: Use netlink to replace some of debugfs
The kernel has gained support for exporting some information via netlink. Use this when available, rather than debugfs. If netlink is not available, or the information is not yet available via netlink, batctl will fall back to debugfs. Signed-off-by: Andrew Lunn --- v2: Verify mandatory attributes are returned by the kernel, and that they have the expected size. v3: Use libnl to perform more verification Add originator header checkpatch cleanup v4: Add the missing netlink.h to the patch --- Makefile | 13 +- batman_adv.h | 111 +++ debug.c | 20 +- debug.h |4 +- functions.c | 11 + functions.h |2 + main.h |1 + netlink.c| 1024 ++ netlink.h| 40 +++ 9 files changed, 1222 insertions(+), 4 deletions(-) create mode 100644 batman_adv.h create mode 100644 netlink.c create mode 100644 netlink.h diff --git a/Makefile b/Makefile index b82c0c6..60795f7 100755 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ export CONFIG_BATCTL_BISECT=n # batctl build BINARY_NAME = batctl -OBJ = main.o bat-hosts.o functions.o sys.o debug.o ping.o traceroute.o tcpdump.o hash.o debugfs.o ioctl.o list-batman.o translate.o +OBJ = main.o bat-hosts.o functions.o sys.o debug.o ping.o traceroute.o tcpdump.o hash.o debugfs.o ioctl.o list-batman.o translate.o netlink.o OBJ_BISECT = bisect_iv.o MANPAGE = man/batctl.8 @@ -61,6 +61,17 @@ endif CFLAGS += $(LIBNL_CFLAGS) LDLIBS += $(LIBNL_LDLIBS) +ifeq ($(origin LIBNL_GENL_CFLAGS) $(origin LIBNL_GENL_LDLIBS), undefined undefined) + LIBNL_GENL_NAME ?= libnl-genl-3.0 + ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_GENL_NAME) 2>/dev/null),) +$(error No $(LIBNL_GENL_NAME) development libraries found!) + endif + LIBNL_GENL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBNL_GENL_NAME)) + LIBNL_GENL_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBNL_GENL_NAME)) +endif +CFLAGS += $(LIBNL_GENL_CFLAGS) +LDLIBS += $(LIBNL_GENL_LDLIBS) + # standard build tools ifeq ($(CONFIG_BATCTL_BISECT),y) OBJ += $(OBJ_BISECT) diff --git a/batman_adv.h b/batman_adv.h new file mode 100644 index 000..6a97a2c --- /dev/null +++ b/batman_adv.h @@ -0,0 +1,111 @@ +/* Copyright (C) 2016 B.A.T.M.A.N. contributors: + * + * Matthias Schiffer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _UAPI_LINUX_BATMAN_ADV_H_ +#define _UAPI_LINUX_BATMAN_ADV_H_ + +#define BATADV_NL_NAME "batadv" + +/** + * enum batadv_tt_client_flags - TT client specific flags + * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table + * @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new + * update telling its new real location has not been received/sent yet + * @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface. + * This information is used by the "AP Isolation" feature + * @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This + * information is used by the Extended Isolation feature + * @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table + * @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has + * not been announced yet + * @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept + * in the table for one more originator interval for consistency purposes + * @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of + * the network but no nnode has already announced it + * + * Bits from 0 to 7 are called _remote flags_ because they are sent on the wire. + * Bits from 8 to 15 are called _local flags_ because they are used for local + * computations only. + * + * Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with + * the other nodes in the network. To achieve this goal these flags are included + * in the TT CRC computation. + */ +enum batadv_tt_client_flags { + BATADV_TT_CLIENT_DEL = (1 << 0), + BATADV_TT_CLIENT_ROAM= (1 << 1), + BATADV_TT_CLIENT_WIFI= (1 << 4), + BATADV_TT_CLIENT_ISOLA = (1 << 5), + BATADV_TT_CLIENT_NOPURGE = (1 << 8), + BATADV_TT_CLIENT_NEW = (1 << 9), + BATADV_TT_CLIENT_PENDING = (1 << 10), + BATADV_TT_CLIENT_TEMP= (1 << 11), +}; + +enum { + BATADV_ATTR_UNSPEC, +
Re: [B.A.T.M.A.N.] [PATCHv2] batctl: Use netlink to replace some of debugfs
> > Once the code is mostly complete and stable, i think a local copy > > would be good. It does seems to be the common way. > > A local copy sounds like a sensible choice and common practice. Hi Marek v3 has a local copy. Andrew
Re: [B.A.T.M.A.N.] [PATCHv3] batctl: Use netlink to replace some of debugfs
Hi Sven > diff --git a/debug.c b/debug.c > index 3db3ed9..c61970e 100644 > --- a/debug.c > +++ b/debug.c > @@ -23,10 +23,12 @@ > #include > #include > #include > +#include > > #include "debug.h" > #include "debugfs.h" > #include "functions.h" > +#include "netlink.h" > #include "sys.h" ... > diff --git a/functions.c b/functions.c > index be8f8b0..27c14d6 100644 > --- a/functions.c > +++ b/functions.c > @@ -52,6 +52,7 @@ > #include "sys.h" > #include "debug.h" > #include "debugfs.h" > +#include "netlink.h" ... > diff --git a/netlink.c b/netlink.c > new file mode 100644 > index 000..951b842 > --- /dev/null > +++ b/netlink.c > @@ -0,0 +1,1024 @@ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "bat-hosts.h" > +#include "batman_adv.h" > +#include "netlink.h" > +#include "functions.h" > +#include "main.h" Where is netlink.h missing? Thanks Andrew
[B.A.T.M.A.N.] [PATCHv3] batctl: Use netlink to replace some of debugfs
The kernel has gained support for exporting some information via netlink. Use this when available, rather than debugfs. If netlink is not available, or the information is not yet available via netlink, batctl will fall back to debugfs. Signed-off-by: Andrew Lunn --- v2: Verify mandatory attributes are returned by the kernel, and that they have the expected size. v3: Use libnl to perform more verification Add originator header checkpatch cleanup --- Makefile | 13 +- batman_adv.h | 111 +++ debug.c | 19 +- debug.h |4 +- functions.c | 11 + functions.h |2 + main.h |1 + netlink.c| 1024 ++ 8 files changed, 1181 insertions(+), 4 deletions(-) create mode 100644 batman_adv.h create mode 100644 netlink.c diff --git a/Makefile b/Makefile index b82c0c6..60795f7 100755 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ export CONFIG_BATCTL_BISECT=n # batctl build BINARY_NAME = batctl -OBJ = main.o bat-hosts.o functions.o sys.o debug.o ping.o traceroute.o tcpdump.o hash.o debugfs.o ioctl.o list-batman.o translate.o +OBJ = main.o bat-hosts.o functions.o sys.o debug.o ping.o traceroute.o tcpdump.o hash.o debugfs.o ioctl.o list-batman.o translate.o netlink.o OBJ_BISECT = bisect_iv.o MANPAGE = man/batctl.8 @@ -61,6 +61,17 @@ endif CFLAGS += $(LIBNL_CFLAGS) LDLIBS += $(LIBNL_LDLIBS) +ifeq ($(origin LIBNL_GENL_CFLAGS) $(origin LIBNL_GENL_LDLIBS), undefined undefined) + LIBNL_GENL_NAME ?= libnl-genl-3.0 + ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_GENL_NAME) 2>/dev/null),) +$(error No $(LIBNL_GENL_NAME) development libraries found!) + endif + LIBNL_GENL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBNL_GENL_NAME)) + LIBNL_GENL_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBNL_GENL_NAME)) +endif +CFLAGS += $(LIBNL_GENL_CFLAGS) +LDLIBS += $(LIBNL_GENL_LDLIBS) + # standard build tools ifeq ($(CONFIG_BATCTL_BISECT),y) OBJ += $(OBJ_BISECT) diff --git a/batman_adv.h b/batman_adv.h new file mode 100644 index 000..6a97a2c --- /dev/null +++ b/batman_adv.h @@ -0,0 +1,111 @@ +/* Copyright (C) 2016 B.A.T.M.A.N. contributors: + * + * Matthias Schiffer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _UAPI_LINUX_BATMAN_ADV_H_ +#define _UAPI_LINUX_BATMAN_ADV_H_ + +#define BATADV_NL_NAME "batadv" + +/** + * enum batadv_tt_client_flags - TT client specific flags + * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table + * @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new + * update telling its new real location has not been received/sent yet + * @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface. + * This information is used by the "AP Isolation" feature + * @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This + * information is used by the Extended Isolation feature + * @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table + * @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has + * not been announced yet + * @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept + * in the table for one more originator interval for consistency purposes + * @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of + * the network but no nnode has already announced it + * + * Bits from 0 to 7 are called _remote flags_ because they are sent on the wire. + * Bits from 8 to 15 are called _local flags_ because they are used for local + * computations only. + * + * Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with + * the other nodes in the network. To achieve this goal these flags are included + * in the TT CRC computation. + */ +enum batadv_tt_client_flags { + BATADV_TT_CLIENT_DEL = (1 << 0), + BATADV_TT_CLIENT_ROAM= (1 << 1), + BATADV_TT_CLIENT_WIFI= (1 << 4), + BATADV_TT_CLIENT_ISOLA = (1 << 5), + BATADV_TT_CLIENT_NOPURGE = (1 << 8), + BATADV_TT_CLIENT_NEW = (1 << 9), + BATADV_TT_CLIENT_PENDING = (1 << 10), + BATADV_TT_CLIENT_TEMP= (1 << 11), +}; + +enum { + BATADV_ATTR_UNSPEC, + BATADV_ATTR_VERSION, + BATADV_ATTR_ALGO_NAME, + BATADV_ATTR_MESH_IFINDEX, + BATA
Re: [B.A.T.M.A.N.] [PATCHv2] batctl: Use netlink to replace some of debugfs
On Tue, May 03, 2016 at 02:54:26PM +0200, Sven Eckelmann wrote: > On Tuesday 03 May 2016 14:47:19 Andrew Lunn wrote: > > On Tue, May 03, 2016 at 02:26:34PM +0200, Sven Eckelmann wrote: > > > On Tuesday 03 May 2016 14:20:46 Andrew Lunn wrote: > > > [...] > > > > There does not seem to be a way to say that BATADV_ATTR_VERSION is > > > > also an NLA_STRING. > > > > > > Please check "policy" in the link I gave you. > > > > I did. And i still don't get how you can check the type. > > > > Andrew > >struct nla_policy { > uint16_ttype; > uint16_tminlen; > uint16_tmaxlen; >}; > > there is an entry for type, minlen and maxlen. The type member is to check for > the type. Here is an example how to check the type from batctl: > > static struct nla_policy info_data_link_policy[IFLA_MAX + 1] = { > [IFLA_LINKINFO] = { .type = NLA_NESTED }, > [IFLA_LINK] = { .type = NLA_U32 }, > }; > [...] > ret = nlmsg_parse(n, sizeof(struct ifinfomsg), tb, IFLA_MAX, > info_data_link_policy); Ah. Now i get it. The problem is the overloaded 'type'. An attribute in a message has a header which includes a type. It takes the value e.g. BATADV_ATTR_VERSION. In nla_policy, we again have type, but this time it takes e.g. NLA_U32. Once you figure out type != type, it all becomes clear... Andrew
Re: [B.A.T.M.A.N.] [PATCHv2] batctl: Use netlink to replace some of debugfs
On Tue, May 03, 2016 at 02:26:34PM +0200, Sven Eckelmann wrote: > On Tuesday 03 May 2016 14:20:46 Andrew Lunn wrote: > [...] > > There does not seem to be a way to say that BATADV_ATTR_VERSION is > > also an NLA_STRING. > > Please check "policy" in the link I gave you. I did. And i still don't get how you can check the type. Andrew
Re: [B.A.T.M.A.N.] [PATCHv2] batctl: Use netlink to replace some of debugfs
> It looks like the header line is missing here. The debugfs table show > something like: > > " Originator last-seen (#/255) Nexthop [outgoingIF]: > Potential nexthops ...\n"); > > or > > " Originator last-seen ( throughput) Nexthop > [outgoingIF]: Potential nexthops ...\n"); Ah, yes. I wanted to come back and look at this. It needs an extra call to ask what algorithm is being used, so you know which header to print. > the nexthops are also done differently now (not sure if this is better > but at least something which should be discussed): I've deliberately not made the output the same as the kernel debugfs. There is no real reason to do that. You should not be 'screen scraping' batctl, you should use the netlink socket... Anything where the kernel consolidates information does not happen. We get the raw information from the kernel, and it is printed as is, with the exception that bathosts is used to translate MAC addresses to names. There are also likely to be white space changes. The callback structure used by netlink does not help here. You get to see one originator record at once. So in order to print consolidated information, you would have to build a database in the callback function, and once all the information is available, do the consolidate and then printing. Doable, but i took the easier option of printing a line per originator record. > originator > == > > netlink > --- > > [B.A.T.M.A.N. adv 2016.1-62-g55e9890, MainIF/MAC: eth0/02:ba:de:af:fe:01 > (bat0/f2:f2:2d:c3:71:8c BATMAN_IV)] > * 02:ba:de:af:fe:020.004s (251) 02:ba:de:af:fe:02 [ eth0] > > debugfs > --- > > [B.A.T.M.A.N. adv 2016.1-62-g55e9890, MainIF/MAC: eth0/02:ba:de:af:fe:01 > (bat0 BATMAN_IV)] > Originator last-seen (#/255) Nexthop [outgoingIF]: > Potential nexthops ... > 02:ba:de:af:fe:020.024s (251) 02:ba:de:af:fe:02 [ eth0]: > 02:ba:de:af:fe:02 (251) > > The output "No batman nodes in range ...\n" also isn't there anymore > (not that I would miss it). Again, the callback structure makes that messy. A global variable which needs setting in the callback, and after parsing all the records, if that global variable is not set, print the "No batman nodes in range ...\n" Andrew
Re: [B.A.T.M.A.N.] [PATCHv2] batctl: Use netlink to replace some of debugfs
On Tue, May 03, 2016 at 09:07:35AM +0200, Sven Eckelmann wrote: > [...] > > +ifeq ($(origin LIBNL_GENL_CFLAGS) $(origin LIBNL_GENL_LDLIBS), undefined > > undefined) > > + LIBNL_GENL_NAME ?= libnl-genl-3.0 > > + ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_GENL_NAME) > > 2>/dev/null),) > > +$(error No $(LIBNL_GENL_NAME) development libraries found!) > > + endif > > + LIBNL_GENL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBNL_GENL_NAME)) > > + LIBNL_GENL_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBNL_GENL_NAME)) > > +endif > > +CFLAGS += $(LIBNL_GENL_CFLAGS) > > +LDLIBS += $(LIBNL_GENL_LDLIBS) > > @Simon, @Matthias, @Antonio, @Marek: Should the header file be included in > batctl like nl80211.h in iw. Or should we always require the current kernel > header files installed to build batctl? Once the code is mostly complete and stable, i think a local copy would be good. It does seems to be the common way. While doing development work, it saved me copying the header file around for each change. I can make this change in the next version. > [...] > > +struct mandatory_attr { > > + int attr; > > + int datalen; > > +}; > > + > > +static int last_err; > > + > > +static int invalidate_mandatory_attrs(struct nlattr *attrs[], > > + const struct mandatory_attr *mandatory[], > > + int num) > > +{ > > + int i; > > + int len; > > + > > + for (i = 0; i < num; i++) { > > + if (!attrs[mandatory[i]->attr]) > > + return EINVAL; > > + len = nla_len(attrs[mandatory[i]->attr]); > > + if (mandatory[i]->datalen && (len != mandatory[i]->datalen)) > > + return EINVAL; > > + } > > + > > + return 0; > > +} > > + > > +static const struct mandatory_attr mandatory_attr_version= { > > + BATADV_ATTR_VERSION, 0 }; > [...] > > +static const struct mandatory_attr *info_hard_mandatory[] = { > > + &mandatory_attr_version, > > + &mandatory_attr_algo_name, > > + &mandatory_attr_hard_ifname, > > + &mandatory_attr_hard_address, > > +}; > > + > > +static int info_callback(struct nl_msg *msg, void *arg __unused) > > +{ > [...] > > + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), > > + genlmsg_len(ghdr), NULL)) { > > + fputs("Received invalid data from kernel.", stderr); > > + exit(1); > > + } > > + > > + if (invalidate_mandatory_attrs(attrs, info_mandatory, > > + ARRAY_SIZE(info_mandatory))) { > > + fputs("Missing/invalid attributes from kernel\n", stderr); > > + exit(1); > > + } > > Interesting idea to check the mandatory attributes with a common function. But > shouldn't be the length checked by the nl_parse(..., policy) [1]? This is > especially important because you don't check the type. I could be missing something, but i don't see how to check the type, i.e. string, u8, u16, etc. The header file is defining attribute types: enum { BATADV_ATTR_UNSPEC, BATADV_ATTR_VERSION, BATADV_ATTR_ALGO_NAME, BATADV_ATTR_MESH_IFINDEX, There does not seem to be a way to say that BATADV_ATTR_VERSION is also an NLA_STRING. However, yes, i should do the length checking as part of nl_parse. Andrew
[B.A.T.M.A.N.] [PATCHv2] batctl: Use netlink to replace some of debugfs
The kernel has gained support for exporting some information via netlink. Use this when available, rather than debugfs. If netlink is not available, or the information is not yet available via netlink, batctl will fall back to debugfs. Signed-off-by: Andrew Lunn --- v2: Verify mandatory attributes are returned by the kernel, and that they have the expected size. --- Makefile| 20 +- debug.c | 19 +- debug.h |4 +- functions.c | 11 + functions.h |1 + main.h |1 + netlink.c | 1038 +++ 7 files changed, 1090 insertions(+), 4 deletions(-) create mode 100644 netlink.c diff --git a/Makefile b/Makefile index b82c0c6..debca29 100755 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ export CONFIG_BATCTL_BISECT=n # batctl build BINARY_NAME = batctl -OBJ = main.o bat-hosts.o functions.o sys.o debug.o ping.o traceroute.o tcpdump.o hash.o debugfs.o ioctl.o list-batman.o translate.o +OBJ = main.o bat-hosts.o functions.o sys.o debug.o ping.o traceroute.o tcpdump.o hash.o debugfs.o ioctl.o list-batman.o translate.o netlink.o OBJ_BISECT = bisect_iv.o MANPAGE = man/batctl.8 @@ -43,6 +43,13 @@ ifndef V endif endif +KERNELPATH ?= /lib/modules/$(shell uname -r)/build +# sanity check: does KERNELPATH exist? +ifeq ($(shell cd $(KERNELPATH) && pwd),) +$(warning $(KERNELPATH) is missing, please set KERNELPATH) +endif +CFLAGS += -I $(KERNELPATH)/include/uapi/linux/ + ifeq ($(origin PKG_CONFIG), undefined) PKG_CONFIG = pkg-config ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),) @@ -61,6 +68,17 @@ endif CFLAGS += $(LIBNL_CFLAGS) LDLIBS += $(LIBNL_LDLIBS) +ifeq ($(origin LIBNL_GENL_CFLAGS) $(origin LIBNL_GENL_LDLIBS), undefined undefined) + LIBNL_GENL_NAME ?= libnl-genl-3.0 + ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_GENL_NAME) 2>/dev/null),) +$(error No $(LIBNL_GENL_NAME) development libraries found!) + endif + LIBNL_GENL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBNL_GENL_NAME)) + LIBNL_GENL_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBNL_GENL_NAME)) +endif +CFLAGS += $(LIBNL_GENL_CFLAGS) +LDLIBS += $(LIBNL_GENL_LDLIBS) + # standard build tools ifeq ($(CONFIG_BATCTL_BISECT),y) OBJ += $(OBJ_BISECT) diff --git a/debug.c b/debug.c index 3db3ed9..5d08b42 100644 --- a/debug.c +++ b/debug.c @@ -23,10 +23,12 @@ #include #include #include +#include #include "debug.h" #include "debugfs.h" #include "functions.h" +#include "netlink.h" #include "sys.h" const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM] = { @@ -35,36 +37,42 @@ const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM] = { .opt_short = "n", .debugfs_name = "neighbors", .header_lines = 2, + .netlink_fn = netlink_print_neighbors, }, { .opt_long = "originators", .opt_short = "o", .debugfs_name = "originators", .header_lines = 2, + .netlink_fn = netlink_print_originators, }, { .opt_long = "gateways", .opt_short = "gwl", .debugfs_name = "gateways", .header_lines = 1, + .netlink_fn = netlink_print_gateways, }, { .opt_long = "translocal", .opt_short = "tl", .debugfs_name = "transtable_local", .header_lines = 2, + .netlink_fn = netlink_print_translocal, }, { .opt_long = "transglobal", .opt_short = "tg", .debugfs_name = "transtable_global", .header_lines = 2, + .netlink_fn = netlink_print_transglobal, }, { .opt_long = "claimtable", .opt_short = "cl", .debugfs_name = "bla_claim_table", .header_lines = 2, + .netlink_fn = netlink_print_bla_claim, }, { .opt_long = "backbonetable", @@ -115,7 +123,7 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv) char *orig_iface = NULL; float orig_timeout = 0.0f; float watch_interval = 1; - opterr = 0; + int err; while ((optchar = getopt(argc, argv, "hnw:t:Humi:")) != -1) { switch (optchar) { @@ -220,12 +228,19 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv) debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", orig_iface, full_path, sizeof(full_path)); else debugfs_make_path(DEBUG_BA
[B.A.T.M.A.N.] [PATCH v3 12/12] batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink
Dump the list of bridge loop avoidance claims via the netlink socket. Signed-off-by: Andrew Lunn --- v2: Missing includes and forward declarations Fix exit on error when dumping. --- include/uapi/linux/batman_adv.h| 6 ++ net/batman-adv/bridge_loop_avoidance.c | 166 + net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/netlink.c | 7 ++ 4 files changed, 188 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index cce4955..6a97a2c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -82,6 +82,11 @@ enum { BATADV_ATTR_BANDWIDTH_UP, BATADV_ATTR_BANDWIDTH_DOWN, BATADV_ATTR_ROUTER, + BATADV_ATTR_BLA_OWN, + BATADV_ATTR_BLA_ADDRESS, + BATADV_ATTR_BLA_VID, + BATADV_ATTR_BLA_BACKBONE, + BATADV_ATTR_BLA_CRC, __BATADV_ATTR_MAX, }; @@ -97,6 +102,7 @@ enum { BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, BATADV_CMD_GET_GATEWAYS, + BATADV_CMD_GET_BLA_CLAIM, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 748a9ea..99458f3 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -45,11 +46,17 @@ #include #include #include +#include +#include +#include +#include #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -1983,6 +1990,165 @@ out: } /** + * batadv_bla_claim_dump_entry - dump one entry of the backbone table + * to a netlink socket + * @msg: buffer for the message + * @portid: netlink port + * @seq: Sequence number of netlink message + * @primary_if: primary interface + * @claim: entry to dump + * + * Return: 0 or error code. + */ +static int +batadv_bla_claim_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hard_iface *primary_if, + struct batadv_bla_claim *claim) +{ + u8 *primary_addr = primary_if->net_dev->dev_addr; + u16 backbone_crc; + bool is_own; + void *hdr; + int ret = -EINVAL; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_BLA_CLAIM); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + is_own = batadv_compare_eth(claim->backbone_gw->orig, + primary_addr); + + spin_lock_bh(&claim->backbone_gw->crc_lock); + backbone_crc = claim->backbone_gw->crc; + spin_unlock_bh(&claim->backbone_gw->crc_lock); + + if (is_own) + if (nla_put_flag(msg, BATADV_ATTR_BLA_OWN)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_BLA_ADDRESS, ETH_ALEN, claim->addr) || + nla_put_u16(msg, BATADV_ATTR_BLA_VID, claim->vid) || + nla_put(msg, BATADV_ATTR_BLA_BACKBONE, ETH_ALEN, + claim->backbone_gw->orig) || + nla_put_u16(msg, BATADV_ATTR_BLA_CRC, + backbone_crc)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + genlmsg_end(msg, hdr); + ret = 0; + +out: + return ret; +} + +/** + * batadv_bla_claim_dump_bucket - dump one bucket of the backbone table + * to a netlink socket + * @msg: buffer for the message + * @portid: netlink port + * @seq: Sequence number of netlink message + * @primary_if: primary interface + * @head: bucket to dump + * @idx_skip: How many entries to skip + * + * Return: always 0. + */ +static int +batadv_bla_claim_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_hard_iface *primary_if, +struct hlist_head *head, int *idx_skip) +{ + struct batadv_bla_claim *claim; + int idx = 0; + + rcu_read_lock(); + hlist_for_each_entry_rcu(claim, head, hash_entry) { + if (idx++ < *idx_skip) + continue; + if (batadv_bla_claim_dump_entry(msg, portid, seq, + primary_if, claim)) { + *idx_skip = idx - 1; + goto unlock; + } + } + + *idx_skip = idx; +unlock: + rcu_read_unlock(); + return 0; +} + +/** + * batadv_bla_claim_dump - dump backbone table to a netlink socket + * @msg: buffe
[B.A.T.M.A.N.] [PATCH v3 10/12] batman-adv: Indicate netlink socket can be used with netns.
Set the netnsof flag on the family structure, indicating it can be used with different network name spaces. Signed-off-by: Andrew Lunn --- net/batman-adv/netlink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index a01bdf5..e188c2b 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -44,6 +44,7 @@ struct genl_family batadv_netlink_family = { .name = BATADV_NL_NAME, .version = 1, .maxattr = BATADV_ATTR_MAX, + .netnsok = true, }; static int -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v3 11/12] batman-adv: add B.A.T.M.A.N. Dump gateways via netlink
Dump the list of gateways via the netlink socket. Signed-off-by: Andrew Lunn --- v2: Add missing includes and forward declarations. --- include/uapi/linux/batman_adv.h | 4 ++ net/batman-adv/gateway_client.c | 131 net/batman-adv/gateway_client.h | 2 + net/batman-adv/netlink.c| 9 ++- 4 files changed, 145 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 27f277f..cce4955 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -79,6 +79,9 @@ enum { BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, BATADV_ATTR_THROUGHPUT, + BATADV_ATTR_BANDWIDTH_UP, + BATADV_ATTR_BANDWIDTH_DOWN, + BATADV_ATTR_ROUTER, __BATADV_ATTR_MAX, }; @@ -93,6 +96,7 @@ enum { BATADV_CMD_GET_TRANSTABLE_GLOBAL, BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, + BATADV_CMD_GET_GATEWAYS, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 5839c56..96b0e91 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -39,12 +41,18 @@ #include #include #include +#include +#include +#include +#include #include "gateway_common.h" #include "hard-interface.h" +#include "netlink.h" #include "originator.h" #include "packet.h" #include "routing.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -662,6 +670,129 @@ out: return 0; } +static int +batadv_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_gw_node *gw_node) +{ + struct batadv_neigh_ifinfo *router_ifinfo = NULL; + struct batadv_neigh_node *router; + struct batadv_gw_node *curr_gw; + int ret = -EINVAL; + void *hdr; + + router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); + if (!router) + goto out; + + router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT); + if (!router_ifinfo) + goto out; + + curr_gw = batadv_gw_get_selected_gw_node(bat_priv); + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_GATEWAYS); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + ret = -EMSGSIZE; + + if (curr_gw == gw_node) + if (nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, + gw_node->orig_node->orig) || + nla_put_u8(msg, BATADV_ATTR_TQ, router_ifinfo->bat_iv.tq_avg) || + nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN, + router->addr) || + nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, + router->if_incoming->net_dev->name) || + nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN, + gw_node->bandwidth_down) || + nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_UP, + gw_node->bandwidth_up)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + genlmsg_end(msg, hdr); + ret = 0; + +out: + if (router_ifinfo) + batadv_neigh_ifinfo_put(router_ifinfo); + if (router) + batadv_neigh_node_put(router); + return ret; +} + +int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + struct batadv_hard_iface *primary_if = NULL; + struct net *net = sock_net(cb->skb->sk); + int portid = NETLINK_CB(cb->skb).portid; + struct net_device *soft_iface = NULL; + struct batadv_gw_node *gw_node; + struct batadv_priv *bat_priv; + int idx_skip = cb->args[0]; + int ifindex; + int idx = 0; + int ret; + + ifindex = batadv_netlink_get_ifindex(cb->nlh, +BATADV_ATTR_MESH_IFINDEX); + if (!ifindex) + return -EINVAL; + + soft_iface = dev_get_by_index(net, ifindex); + if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { + ret = -ENODEV; + goto out; + } + + bat_priv = netdev_priv(soft_iface); + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { +
[B.A.T.M.A.N.] [PATCH v3 04/12] batman-adv: add generic netlink query API to replace debugfs files
From: Matthias Schiffer debugfs is currently severely broken virtually everywhere in the kernel where files are dynamically added and removed (see http://lkml.iu.edu/hypermail/linux/kernel/1506.1/02196.html for some details). In addition to that, debugfs is not namespace-aware. Also, the debugfs interface will try to fix the whole list of originators/ TT entries into a single buffer. The situation has improved in recent kernels,as the seq_file infrastructure will fall back to vmalloc now when kmalloc fails. Still, converting all information to text and potentially retrying multiple times until the buffer is big enough is very inefficient. This commit adds generic infrastructur for the netlink interface to batman-adv and implements the following command: * BATADV_CMD_GET_ROUTING_ALGOS: will return the list of supported routing algorithms * BATADV_CMD_GET_MESH_INFO: will return basic information about a batman-adv softif (name, index and MAC address for both the softif and the primary hardif; routing algorithm; batman-adv version) * BATADV_CMD_GET_HARDIFS: will return the list of hardifs (including index, name and MAC address) of all hardifs for a given softif Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Added missing includes and forward declarations of structures. --- Makefile| 1 + include/uapi/linux/batman_adv.h | 49 net/batman-adv/Makefile | 1 + net/batman-adv/main.c | 51 net/batman-adv/main.h | 2 + net/batman-adv/netlink.c| 260 net/batman-adv/netlink.h| 41 +++ 7 files changed, 405 insertions(+) create mode 100644 include/uapi/linux/batman_adv.h create mode 100644 net/batman-adv/netlink.c create mode 100644 net/batman-adv/netlink.h diff --git a/Makefile b/Makefile index 5d2c058..f17bde5 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ REVISION= $(shell if [ -d "$(PWD)/.git" ]; then \ fi) export NOSTDINC_FLAGS := \ -I$(PWD)/compat-include/ \ + -I$(PWD)/include/ \ -include $(PWD)/compat.h \ $(CFLAGS) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h new file mode 100644 index 000..b9b7dfd --- /dev/null +++ b/include/uapi/linux/batman_adv.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2016 B.A.T.M.A.N. contributors: + * + * Matthias Schiffer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _UAPI_LINUX_BATMAN_ADV_H_ +#define _UAPI_LINUX_BATMAN_ADV_H_ + +#define BATADV_NL_NAME "batadv" + +enum { + BATADV_ATTR_UNSPEC, + BATADV_ATTR_VERSION, + BATADV_ATTR_ALGO_NAME, + BATADV_ATTR_MESH_IFINDEX, + BATADV_ATTR_MESH_IFNAME, + BATADV_ATTR_MESH_ADDRESS, + BATADV_ATTR_HARD_IFINDEX, + BATADV_ATTR_HARD_IFNAME, + BATADV_ATTR_HARD_ADDRESS, + BATADV_ATTR_ACTIVE, + __BATADV_ATTR_MAX, +}; + +#define BATADV_ATTR_MAX (__BATADV_ATTR_MAX - 1) + +enum { + BATADV_CMD_UNSPEC, + BATADV_CMD_GET_ROUTING_ALGOS, + BATADV_CMD_GET_MESH_INFO, + BATADV_CMD_GET_HARDIFS, + __BATADV_CMD_MAX, +}; + +#define BATADV_CMD_MAX (__BATADV_CMD_MAX - 1) + +#endif /* _UAPI_LINUX_BATMAN_ADV_H_ */ diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile index 797cf2f..4e5adba 100644 --- a/net/batman-adv/Makefile +++ b/net/batman-adv/Makefile @@ -33,6 +33,7 @@ batman-adv-y += hash.o batman-adv-y += icmp_socket.o batman-adv-y += main.o batman-adv-$(CONFIG_BATMAN_ADV_MCAST) += multicast.o +batman-adv-y += netlink.o batman-adv-$(CONFIG_BATMAN_ADV_NC) += network-coding.o batman-adv-y += originator.o batman-adv-y += routing.o diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index 5f2974b..7b5f585 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,10 @@ #include #include #include +#include +#include #include +#include #include "bat_algo.h" #include "bridge_loop_avoidance.h" @@ -57,6 +61,7 @@ #include "hard-interface.h" #include "icmp_socket.h" #include "multicast.h" +#include "netlink.h" #include "network-coding.h" #include "originator.h" #include "packet.h" @@
[B.A.T.M.A.N.] [PATCH v3 09/12] batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Add missing includes --- include/uapi/linux/batman_adv.h | 1 + net/batman-adv/bat_iv_ogm.c | 3 + net/batman-adv/bat_v.c | 257 3 files changed, 261 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index baf4ac8..27f277f 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -78,6 +78,7 @@ enum { BATADV_ATTR_LAST_SEEN_MSECS, BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, + BATADV_ATTR_THROUGHPUT, __BATADV_ATTR_MAX, }; diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index e70560e..6659035 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,8 @@ #include #include #include +#include +#include #include #include "bitarray.h" diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index 3ff8bd1..18821a7 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c @@ -20,23 +20,32 @@ #include #include +#include +#include #include #include #include #include +#include #include #include #include #include #include +#include +#include +#include #include "bat_v_elp.h" #include "bat_v_ogm.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +struct sk_buff; + static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface) { /* B.A.T.M.A.N. V does not use any queuing mechanism, therefore it can @@ -182,6 +191,107 @@ static void batadv_v_neigh_print(struct batadv_priv *bat_priv, seq_puts(seq, "No batman nodes in range ...\n"); } +static int +batadv_v_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hardif_neigh_node *hardif_neigh) +{ + void *hdr; + unsigned int last_seen_msecs; + u32 throughput; + + last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen); + throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); + throughput = throughput * 100; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, + BATADV_CMD_GET_NEIGHBORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + hardif_neigh->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + hardif_neigh->if_incoming->net_dev->ifindex) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs) || + nla_put_u32(msg, BATADV_ATTR_THROUGHPUT, throughput)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +static int +batadv_v_neigh_dump_hardif(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *hard_iface, + int *idx_s) +{ + struct batadv_hardif_neigh_node *hardif_neigh; + int idx = 0; + + hlist_for_each_entry_rcu(hardif_neigh, +&hard_iface->neigh_list, list) { + if (idx++ < *idx_s) + continue; + + if (batadv_v_neigh_dump_neigh(msg, portid, seq, hardif_neigh)) { + *idx_s = idx - 1; + return -EMSGSIZE; + } + } + + *idx_s = 0; + return 0; +} + +static void +batadv_v_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *single_hardif) +{ + struct batadv_hard_iface *hard_iface; + int i_hardif = 0; + int i_hardif_s = cb->args[0]; + int idx = cb->args[1]; + int portid = NETLINK_CB(cb->skb).portid; + + rcu_read_lock(); + if (single_hardif) { + if (i_hardif_s == 0) { + if (batadv_v_neigh_dump_hardif(msg, portid, + cb->nlh->nlmsg_seq, + bat_priv, single_hardif, + &idx) == 0) + i_hardif++; + } + } else { + list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { +
[B.A.T.M.A.N.] [PATCH v3 07/12] batman-adv: netlink: add originator and neighbor table queries
From: Matthias Schiffer Add BATADV_CMD_GET_ORIGINATORS and BATADV_CMD_GET_NEIGHBORS commands, using handlers bat_orig_dump and bat_neigh_dump in batadv_algo_ops. Will always return -EOPNOTSUPP for now, as no implementations exist yet. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Add missing includes and forward declarations Add kernel doc to the two dump functions. v3: Add kernel doc for new members in batadv_algo_ops --- include/uapi/linux/batman_adv.h | 2 + net/batman-adv/netlink.c| 14 net/batman-adv/originator.c | 160 net/batman-adv/originator.h | 4 + net/batman-adv/types.h | 9 +++ 5 files changed, 189 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 25dee3c..35d8e8c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -88,6 +88,8 @@ enum { BATADV_CMD_GET_HARDIFS, BATADV_CMD_GET_TRANSTABLE_LOCAL, BATADV_CMD_GET_TRANSTABLE_GLOBAL, + BATADV_CMD_GET_ORIGINATORS, + BATADV_CMD_GET_NEIGHBORS, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 3fb1c1f..a01bdf5 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -33,6 +33,7 @@ #include #include +#include "originator.h" #include "hard-interface.h" #include "soft-interface.h" #include "translation-table.h" @@ -222,6 +223,7 @@ batadv_netlink_dump_hardifs(struct sk_buff *msg, struct netlink_callback *cb) static struct nla_policy batadv_netlink_policy[BATADV_ATTR_MAX + 1] = { [BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 }, + [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 }, }; static struct genl_ops batadv_netlink_ops[] = { @@ -255,6 +257,18 @@ static struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_tt_global_dump, }, + { + .cmd = BATADV_CMD_GET_ORIGINATORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_orig_dump, + }, + { + .cmd = BATADV_CMD_GET_NEIGHBORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_hardif_neigh_dump, + }, }; void __init batadv_netlink_register(void) diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index 1ff4ee4..2ba7a0d 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c @@ -28,11 +28,15 @@ #include #include #include +#include #include #include +#include #include #include #include +#include +#include #include "distributed-arp-table.h" #include "fragmentation.h" @@ -40,8 +44,10 @@ #include "hard-interface.h" #include "hash.h" #include "multicast.h" +#include "netlink.h" #include "network-coding.h" #include "routing.h" +#include "soft-interface.h" #include "translation-table.h" /* hash class keys */ @@ -699,6 +705,83 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset) } /** + * batadv_hardif_neigh_dump - Dump to netlink the neighbor infos for a specific + * outgoing interface + * @msg: message to dump into + * @cb: parameters for the dump + * + * Return: 0 or error value + */ +int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + struct net *net = sock_net(cb->skb->sk); + struct net_device *soft_iface = NULL; + struct net_device *hard_iface = NULL; + struct batadv_hard_iface *hardif = BATADV_IF_DEFAULT; + struct batadv_priv *bat_priv; + struct batadv_hard_iface *primary_if = NULL; + int ret; + int ifindex, hard_ifindex; + + ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX); + if (!ifindex) + return -EINVAL; + + soft_iface = dev_get_by_index(net, ifindex); + if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { + ret = -ENODEV; + goto out; + } + + bat_priv = netdev_priv(soft_iface); + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { + ret = -ENOENT; + goto out; + } + + hard_ifindex = batadv_netlink_get_ifindex(cb->nlh, + BATADV_ATTR_HARD_IFINDEX); + if (hard_ifindex) { + hard_iface = dev_get_by_index(net, hard_ifindex); + if (hard_iface) + hardif = batadv_hardif_get_by_netdev(hard_iface); + + if (!hardif) { +
[B.A.T.M.A.N.] [PATCH v3 06/12] batman-adv: netlink: add translation table query
From: Matthias Schiffer This adds the commands BATADV_CMD_GET_TRANSTABLE_LOCAL and BATADV_CMD_GET_TRANSTABLE_GLOBAL, which correspond to the transtable_local and transtable_global debugfs files. The batadv_tt_client_flags enum is moved to the UAPI to expose it as part of the netlink API. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Add missing header files. --- include/uapi/linux/batman_adv.h| 47 ++ net/batman-adv/netlink.c | 13 ++ net/batman-adv/packet.h| 36 - net/batman-adv/translation-table.c | 308 + net/batman-adv/translation-table.h | 4 + 5 files changed, 372 insertions(+), 36 deletions(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index b9b7dfd..25dee3c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -20,6 +20,42 @@ #define BATADV_NL_NAME "batadv" +/** + * enum batadv_tt_client_flags - TT client specific flags + * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table + * @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new + * update telling its new real location has not been received/sent yet + * @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface. + * This information is used by the "AP Isolation" feature + * @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This + * information is used by the Extended Isolation feature + * @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table + * @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has + * not been announced yet + * @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept + * in the table for one more originator interval for consistency purposes + * @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of + * the network but no nnode has already announced it + * + * Bits from 0 to 7 are called _remote flags_ because they are sent on the wire. + * Bits from 8 to 15 are called _local flags_ because they are used for local + * computations only. + * + * Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with + * the other nodes in the network. To achieve this goal these flags are included + * in the TT CRC computation. + */ +enum batadv_tt_client_flags { + BATADV_TT_CLIENT_DEL = (1 << 0), + BATADV_TT_CLIENT_ROAM= (1 << 1), + BATADV_TT_CLIENT_WIFI= (1 << 4), + BATADV_TT_CLIENT_ISOLA = (1 << 5), + BATADV_TT_CLIENT_NOPURGE = (1 << 8), + BATADV_TT_CLIENT_NEW = (1 << 9), + BATADV_TT_CLIENT_PENDING = (1 << 10), + BATADV_TT_CLIENT_TEMP= (1 << 11), +}; + enum { BATADV_ATTR_UNSPEC, BATADV_ATTR_VERSION, @@ -31,6 +67,15 @@ enum { BATADV_ATTR_HARD_IFNAME, BATADV_ATTR_HARD_ADDRESS, BATADV_ATTR_ACTIVE, + BATADV_ATTR_ORIG_ADDRESS, + BATADV_ATTR_TT_ADDRESS, + BATADV_ATTR_TT_TTVN, + BATADV_ATTR_TT_LAST_TTVN, + BATADV_ATTR_TT_CRC32, + BATADV_ATTR_TT_VID, + BATADV_ATTR_TT_FLAGS, + BATADV_ATTR_FLAG_BEST, + BATADV_ATTR_LAST_SEEN_MSECS, __BATADV_ATTR_MAX, }; @@ -41,6 +86,8 @@ enum { BATADV_CMD_GET_ROUTING_ALGOS, BATADV_CMD_GET_MESH_INFO, BATADV_CMD_GET_HARDIFS, + BATADV_CMD_GET_TRANSTABLE_LOCAL, + BATADV_CMD_GET_TRANSTABLE_GLOBAL, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index e302de3..3fb1c1f 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -35,6 +35,7 @@ #include "hard-interface.h" #include "soft-interface.h" +#include "translation-table.h" struct genl_family batadv_netlink_family = { .id = GENL_ID_GENERATE, @@ -242,6 +243,18 @@ static struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_netlink_dump_hardifs, }, + { + .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_tt_local_dump, + }, + { + .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_tt_global_dump, + }, }; void __init batadv_netlink_register(void) diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h index 372128d..b45460d 100644 --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h @@ -126,42 +126,6 @@ enum batadv_tt_data_flags { }; /** - * enum batadv_tt_client_flags - TT client specific flags - * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the tabl
[B.A.T.M.A.N.] [PATCH v3 05/12] batman-adv: compat: Workarounds for previous patch
* NETLINK_CB portid changed name * info->snd_portid changed name * genl_register_family_with_ops implementation Signed-off-by: Sven Eckelmann Signed-off-by: Andrew Lunn --- compat-include/linux/netlink.h | 45 ++ compat-include/net/genetlink.h | 34 +++ compat.h | 6 ++ 3 files changed, 85 insertions(+) create mode 100644 compat-include/linux/netlink.h create mode 100644 compat-include/net/genetlink.h diff --git a/compat-include/linux/netlink.h b/compat-include/linux/netlink.h new file mode 100644 index 000..696f6da --- /dev/null +++ b/compat-include/linux/netlink.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ + +#include +#include_next + +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) + +struct batadv_netlink_skb_parms { + struct ucredcreds; /* Skb credentials */ + union { + __u32 portid; + __u32 pid; + }; + __u32 dst_group; +}; + +#undef NETLINK_CB +#define NETLINK_CB(skb) (*(struct batadv_netlink_skb_parms*)&((skb)->cb)) + +#endif /* < KERNEL_VERSION(3, 7, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ */ diff --git a/compat-include/net/genetlink.h b/compat-include/net/genetlink.h new file mode 100644 index 000..bf1ba3d --- /dev/null +++ b/compat-include/net/genetlink.h @@ -0,0 +1,34 @@ +/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_NET_GENETLINK_H_ +#define _NET_BATMAN_ADV_COMPAT_NET_GENETLINK_H_ + +#include +#include_next + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0) + +#define genl_register_family_with_ops(family, ops) \ + genl_register_family_with_ops((family), (ops), ARRAY_SIZE(ops)) + +#endif /* < KERNEL_VERSION(3, 13, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_NET_GENETLINK_H_ */ diff --git a/compat.h b/compat.h index 813e637..ac4f7a0 100644 --- a/compat.h +++ b/compat.h @@ -62,6 +62,12 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\ #endif /* < KERNEL_VERSION(3, 3, 0) */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) + +#define snd_portid snd_pid + +#endif /* < KERNEL_VERSION(3, 7, 0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) #define batadv_interface_set_mac_addr(x, y) \ -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v3 03/12] batman-adv: Suppress debugfs entries for netns's
Debugfs is not netns aware. It thus has problems when the same interface name exists in multiple network name spaces. Work around this by not creating entries for interfaces in name spaces other than the default name space. This means meshes in network namespaces cannot be managed via debugfs, but there will soon be a netlink interface which is netns aware. Signed-off-by: Andrew Lunn --- v2: Fix accidental change to __printf Add missing includes. --- net/batman-adv/debugfs.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c index 9529004..e54f0da 100644 --- a/net/batman-adv/debugfs.c +++ b/net/batman-adv/debugfs.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "bridge_loop_avoidance.h" @@ -495,12 +496,16 @@ void batadv_debugfs_destroy(void) */ int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); struct batadv_debuginfo **bat_debug; struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name, batadv_debugfs); if (!hard_iface->debug_dir) @@ -531,6 +536,11 @@ out: */ void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); + + if (net != &init_net) + return; + if (batadv_debugfs) { debugfs_remove_recursive(hard_iface->debug_dir); hard_iface->debug_dir = NULL; @@ -541,11 +551,15 @@ int batadv_debugfs_add_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); struct batadv_debuginfo **bat_debug; + struct net *net = dev_net(dev); struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); if (!bat_priv->debug_dir) goto out; @@ -582,6 +596,10 @@ out: void batadv_debugfs_del_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); + struct net *net = dev_net(dev); + + if (net != &init_net) + return; batadv_debug_log_cleanup(bat_priv); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v3 02/12] batman-adv: compat.h: Add workaround for get_link_net()
Signed-off-by: Sven Eckelmann Signed-off-by: Andrew Lunn --- v2: Fix accidental newline deletion --- compat.h | 7 +++ 1 file changed, 7 insertions(+) diff --git a/compat.h b/compat.h index 5a5f478..813e637 100644 --- a/compat.h +++ b/compat.h @@ -140,6 +140,13 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\ #endif /* < KERNEL_VERSION(3, 15, 0) */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) + +/* WARNING for batadv_getlink_net */ +#define get_link_net get_xstats_size || 0 || netdev->rtnl_link_ops->get_xstats_size + +#endif /* < KERNEL_VERSION(4, 0, 0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) #define IFF_NO_QUEUE 0; dev->tx_queue_len = 0 -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v3 00/12] netns and netlink support
This patchset completes netns support, by disabling debugfs entries when not in the default name space, and correctly handling interface stack loops when the parent is in a different name space. It additionally adds netlink support for most of the information found in debugfs, and is netns awaire. Note: BLA is untested, so best assume it is broken... v3: * Fix the compat with older kernels. It now at least compiles with 3.18.32. I've not booted it though. * Add missing kerneldoc v2: All changes requested by Sven: * Added lots of missing includes and structure forward declarations * Add two kernel doc comments * Fixed an obvious bug in BLA, but it is probably still broken... * Merged in the compat code Sven suggested. Only compile tested with 4.5.0 *** BLURB HERE *** Andrew Lunn (7): batman-adv: Handle parent interfaces in a different netns batman-adv: compat.h: Add workaround for get_link_net() batman-adv: Suppress debugfs entries for netns's batman-adv: compat: Workarounds for previous patch batman-adv: Indicate netlink socket can be used with netns. batman-adv: add B.A.T.M.A.N. Dump gateways via netlink batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink Matthias Schiffer (5): batman-adv: add generic netlink query API to replace debugfs files batman-adv: netlink: add translation table query batman-adv: netlink: add originator and neighbor table queries batman-adv: add B.A.T.M.A.N. IV bat_{orig, neigh}_dump implementations batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations Makefile | 1 + compat-include/linux/netlink.h | 45 + compat-include/net/genetlink.h | 34 compat.h | 13 ++ include/uapi/linux/batman_adv.h| 111 net/batman-adv/Makefile| 1 + net/batman-adv/bat_iv_ogm.c| 271 + net/batman-adv/bat_v.c | 257 +++ net/batman-adv/bridge_loop_avoidance.c | 166 ++ net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/debugfs.c | 18 ++ net/batman-adv/gateway_client.c| 131 ++ net/batman-adv/gateway_client.h| 2 + net/batman-adv/hard-interface.c| 50 +- net/batman-adv/main.c | 51 ++ net/batman-adv/main.h | 2 + net/batman-adv/netlink.c | 302 net/batman-adv/netlink.h | 41 + net/batman-adv/originator.c| 160 + net/batman-adv/originator.h| 4 + net/batman-adv/packet.h| 36 net/batman-adv/translation-table.c | 308 + net/batman-adv/translation-table.h | 4 + net/batman-adv/types.h | 9 + 24 files changed, 1983 insertions(+), 44 deletions(-) create mode 100644 compat-include/linux/netlink.h create mode 100644 compat-include/net/genetlink.h create mode 100644 include/uapi/linux/batman_adv.h create mode 100644 net/batman-adv/netlink.c create mode 100644 net/batman-adv/netlink.h -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v3 08/12] batman-adv: add B.A.T.M.A.N. IV bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Signed-off-by: Matthias Schiffer --- include/uapi/linux/batman_adv.h | 2 + net/batman-adv/bat_iv_ogm.c | 268 2 files changed, 270 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 35d8e8c..baf4ac8 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -76,6 +76,8 @@ enum { BATADV_ATTR_TT_FLAGS, BATADV_ATTR_FLAG_BEST, BATADV_ATTR_LAST_SEEN_MSECS, + BATADV_ATTR_NEIGH_ADDRESS, + BATADV_ATTR_TQ, __BATADV_ATTR_MAX, }; diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index ce2f203..e70560e 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -47,10 +47,12 @@ #include #include #include +#include #include "bitarray.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "network-coding.h" #include "originator.h" #include "packet.h" @@ -1918,6 +1920,171 @@ next: seq_puts(seq, "No batman nodes in range ...\n"); } +static bool +batadv_iv_ogm_neigh_get_tq_avg(struct batadv_neigh_node *neigh_node, + struct batadv_hard_iface *if_outgoing, + u8 *tq_avg) +{ + struct batadv_neigh_ifinfo *n_ifinfo; + + n_ifinfo = batadv_neigh_ifinfo_get(neigh_node, if_outgoing); + if (!n_ifinfo) + return false; + + *tq_avg = n_ifinfo->bat_iv.tq_avg; + batadv_neigh_ifinfo_put(n_ifinfo); + + return true; +} + +static int +batadv_iv_ogm_orig_dump_subentry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_hard_iface *if_outgoing, +struct batadv_orig_node *orig_node, +struct batadv_neigh_node *neigh_node, +bool best) +{ + void *hdr; + u8 tq_avg; + unsigned int last_seen_msecs; + + last_seen_msecs = jiffies_to_msecs(jiffies - orig_node->last_seen); + + if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node, if_outgoing, &tq_avg)) + return 0; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, + BATADV_CMD_GET_ORIGINATORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, orig_node->orig) || + nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + neigh_node->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + neigh_node->if_incoming->net_dev->ifindex) || + nla_put_u8(msg, BATADV_ATTR_TQ, tq_avg) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs)) + goto nla_put_failure; + + if (best && nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +static int +batadv_iv_ogm_orig_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *if_outgoing, + struct batadv_orig_node *orig_node, int *sub_s) +{ + struct batadv_neigh_node *neigh_node_best; + struct batadv_neigh_node *neigh_node; + int sub = 0; + bool best; + u8 tq_avg_best; + + neigh_node_best = batadv_orig_router_get(orig_node, if_outgoing); + if (!neigh_node_best) + goto out; + + if (!batadv_iv_ogm_neigh_get_tq_avg(neigh_node_best, if_outgoing, + &tq_avg_best)) + goto out; + + if (tq_avg_best == 0) + goto out; + + hlist_for_each_entry_rcu(neigh_node, &orig_node->neigh_list, list) { + if (sub++ < *sub_s) + continue; + + best = (neigh_node == neigh_node_best); + + if (batadv_iv_ogm_orig_dump_subentry(msg, portid, seq, bat_priv, +if_outgoing, orig_node, +neigh_node, best)) { + batadv_neigh_node_put(neigh_node_best); + + *sub_s = sub - 1; + return -EMSGSIZE; + } + } + + out: + if (neigh_node_best) + batadv_neigh_node_put(neigh_node_best); + + *sub_s = 0; + return 0; +} + +static int +batadv_iv_ogm_orig_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *if_outgoing, +
[B.A.T.M.A.N.] [PATCH v3 01/12] batman-adv: Handle parent interfaces in a different netns
batman-adv tries to prevent the user from placing a batX soft interface into another batman mesh as a hard interface. It does this by walking up the devices list of parents and ensures they are all none batX interfaces. iflink can point to an interface in a different namespace, so also retrieve the parents name space when finding the parent and use it when doing the comparison. Signed-off-by: Andrew Lunn Signed-off-by: Sven Eckelmann Acked-by: Antonio Quartulli --- v2: Add missing header files Use Sven's code to facilitate a compat.h change v3: More of Sven's code to facilitate a compat.h --- net/batman-adv/hard-interface.c | 50 +++-- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 8c2f399..1deb5de 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include "bridge_loop_avoidance.h" #include "debugfs.h" @@ -83,25 +85,55 @@ out: } /** + * batadv_getlink_net - return link net namespace (of use fallback) + * @netdev: net_device to check + * @fallback_net: return in case get_link_net is not available for @netdev + * + * Return: result of rtnl_link_ops->get_link_net or @fallback_net + */ +static const struct net *batadv_getlink_net(const struct net_device *netdev, + const struct net *fallback_net) +{ + if (!netdev->rtnl_link_ops) + return fallback_net; + + if (!netdev->rtnl_link_ops->get_link_net) + return fallback_net; + + return netdev->rtnl_link_ops->get_link_net(netdev); +} + +/** * batadv_mutual_parents - check if two devices are each others parent - * @dev1: 1st net_device - * @dev2: 2nd net_device + * @dev1: 1st net dev + * @net1: 1st devices netns + * @dev2: 2nd net dev + * @net2: 2nd devices netns * * veth devices come in pairs and each is the parent of the other! * * Return: true if the devices are each others parent, otherwise false */ static bool batadv_mutual_parents(const struct net_device *dev1, - const struct net_device *dev2) + const struct net *net1, + const struct net_device *dev2, + const struct net *net2) { int dev1_parent_iflink = dev_get_iflink(dev1); int dev2_parent_iflink = dev_get_iflink(dev2); + const struct net *dev1_parent_net; + const struct net *dev2_parent_net; + + dev1_parent_net = batadv_getlink_net(dev1, net1); + dev2_parent_net = batadv_getlink_net(dev2, net2); if (!dev1_parent_iflink || !dev2_parent_iflink) return false; return (dev1_parent_iflink == dev2->ifindex) && - (dev2_parent_iflink == dev1->ifindex); + (dev2_parent_iflink == dev1->ifindex) && + net_eq(dev1_parent_net, net2) && + net_eq(dev2_parent_net, net1); } /** @@ -119,8 +151,9 @@ static bool batadv_mutual_parents(const struct net_device *dev1, */ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) { - struct net_device *parent_dev; struct net *net = dev_net(net_dev); + struct net_device *parent_dev; + const struct net *parent_net; bool ret; /* check if this is a batman-adv mesh interface */ @@ -132,13 +165,16 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) dev_get_iflink(net_dev) == net_dev->ifindex) return false; + parent_net = batadv_getlink_net(net_dev, net); + /* recurse over the parent device */ - parent_dev = __dev_get_by_index(net, dev_get_iflink(net_dev)); + parent_dev = __dev_get_by_index((struct net *)parent_net, + dev_get_iflink(net_dev)); /* if we got a NULL parent_dev there is something broken.. */ if (WARN(!parent_dev, "Cannot find parent device")) return false; - if (batadv_mutual_parents(net_dev, parent_dev)) + if (batadv_mutual_parents(net_dev, net, parent_dev, parent_net)) return false; ret = batadv_is_on_batman_iface(parent_dev); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v2 12/12] batman-adv: add B.A.T.M.A.N. Dump BLA claims via netlink
Dump the list of bridge loop avoidance claims via the netlink socket. Signed-off-by: Andrew Lunn --- v2: Missing includes and forward declarations Fix exit on error when dumping. --- include/uapi/linux/batman_adv.h| 6 ++ net/batman-adv/bridge_loop_avoidance.c | 166 + net/batman-adv/bridge_loop_avoidance.h | 10 +- net/batman-adv/netlink.c | 7 ++ 4 files changed, 188 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index cce4955..6a97a2c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -82,6 +82,11 @@ enum { BATADV_ATTR_BANDWIDTH_UP, BATADV_ATTR_BANDWIDTH_DOWN, BATADV_ATTR_ROUTER, + BATADV_ATTR_BLA_OWN, + BATADV_ATTR_BLA_ADDRESS, + BATADV_ATTR_BLA_VID, + BATADV_ATTR_BLA_BACKBONE, + BATADV_ATTR_BLA_CRC, __BATADV_ATTR_MAX, }; @@ -97,6 +102,7 @@ enum { BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, BATADV_CMD_GET_GATEWAYS, + BATADV_CMD_GET_BLA_CLAIM, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 748a9ea..99458f3 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -45,11 +46,17 @@ #include #include #include +#include +#include +#include +#include #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -1983,6 +1990,165 @@ out: } /** + * batadv_bla_claim_dump_entry - dump one entry of the backbone table + * to a netlink socket + * @msg: buffer for the message + * @portid: netlink port + * @seq: Sequence number of netlink message + * @primary_if: primary interface + * @claim: entry to dump + * + * Return: 0 or error code. + */ +static int +batadv_bla_claim_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hard_iface *primary_if, + struct batadv_bla_claim *claim) +{ + u8 *primary_addr = primary_if->net_dev->dev_addr; + u16 backbone_crc; + bool is_own; + void *hdr; + int ret = -EINVAL; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_BLA_CLAIM); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + is_own = batadv_compare_eth(claim->backbone_gw->orig, + primary_addr); + + spin_lock_bh(&claim->backbone_gw->crc_lock); + backbone_crc = claim->backbone_gw->crc; + spin_unlock_bh(&claim->backbone_gw->crc_lock); + + if (is_own) + if (nla_put_flag(msg, BATADV_ATTR_BLA_OWN)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_BLA_ADDRESS, ETH_ALEN, claim->addr) || + nla_put_u16(msg, BATADV_ATTR_BLA_VID, claim->vid) || + nla_put(msg, BATADV_ATTR_BLA_BACKBONE, ETH_ALEN, + claim->backbone_gw->orig) || + nla_put_u16(msg, BATADV_ATTR_BLA_CRC, + backbone_crc)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + genlmsg_end(msg, hdr); + ret = 0; + +out: + return ret; +} + +/** + * batadv_bla_claim_dump_bucket - dump one bucket of the backbone table + * to a netlink socket + * @msg: buffer for the message + * @portid: netlink port + * @seq: Sequence number of netlink message + * @primary_if: primary interface + * @head: bucket to dump + * @idx_skip: How many entries to skip + * + * Return: always 0. + */ +static int +batadv_bla_claim_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_hard_iface *primary_if, +struct hlist_head *head, int *idx_skip) +{ + struct batadv_bla_claim *claim; + int idx = 0; + + rcu_read_lock(); + hlist_for_each_entry_rcu(claim, head, hash_entry) { + if (idx++ < *idx_skip) + continue; + if (batadv_bla_claim_dump_entry(msg, portid, seq, + primary_if, claim)) { + *idx_skip = idx - 1; + goto unlock; + } + } + + *idx_skip = idx; +unlock: + rcu_read_unlock(); + return 0; +} + +/** + * batadv_bla_claim_dump - dump backbone table to a netlink socket + * @msg: buffe
[B.A.T.M.A.N.] [PATCH v2 11/12] batman-adv: add B.A.T.M.A.N. Dump gateways via netlink
Dump the list of gateways via the netlink socket. Signed-off-by: Andrew Lunn --- v2: Add missing includes and forward declarations. --- include/uapi/linux/batman_adv.h | 4 ++ net/batman-adv/gateway_client.c | 131 net/batman-adv/gateway_client.h | 2 + net/batman-adv/netlink.c| 9 ++- 4 files changed, 145 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 27f277f..cce4955 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -79,6 +79,9 @@ enum { BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, BATADV_ATTR_THROUGHPUT, + BATADV_ATTR_BANDWIDTH_UP, + BATADV_ATTR_BANDWIDTH_DOWN, + BATADV_ATTR_ROUTER, __BATADV_ATTR_MAX, }; @@ -93,6 +96,7 @@ enum { BATADV_CMD_GET_TRANSTABLE_GLOBAL, BATADV_CMD_GET_ORIGINATORS, BATADV_CMD_GET_NEIGHBORS, + BATADV_CMD_GET_GATEWAYS, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 5839c56..96b0e91 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -39,12 +41,18 @@ #include #include #include +#include +#include +#include +#include #include "gateway_common.h" #include "hard-interface.h" +#include "netlink.h" #include "originator.h" #include "packet.h" #include "routing.h" +#include "soft-interface.h" #include "sysfs.h" #include "translation-table.h" @@ -662,6 +670,129 @@ out: return 0; } +static int +batadv_gw_dump_entry(struct sk_buff *msg, u32 portid, u32 seq, +struct batadv_priv *bat_priv, +struct batadv_gw_node *gw_node) +{ + struct batadv_neigh_ifinfo *router_ifinfo = NULL; + struct batadv_neigh_node *router; + struct batadv_gw_node *curr_gw; + int ret = -EINVAL; + void *hdr; + + router = batadv_orig_router_get(gw_node->orig_node, BATADV_IF_DEFAULT); + if (!router) + goto out; + + router_ifinfo = batadv_neigh_ifinfo_get(router, BATADV_IF_DEFAULT); + if (!router_ifinfo) + goto out; + + curr_gw = batadv_gw_get_selected_gw_node(bat_priv); + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, + NLM_F_MULTI, BATADV_CMD_GET_GATEWAYS); + if (!hdr) { + ret = -ENOBUFS; + goto out; + } + + ret = -EMSGSIZE; + + if (curr_gw == gw_node) + if (nla_put_flag(msg, BATADV_ATTR_FLAG_BEST)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, + gw_node->orig_node->orig) || + nla_put_u8(msg, BATADV_ATTR_TQ, router_ifinfo->bat_iv.tq_avg) || + nla_put(msg, BATADV_ATTR_ROUTER, ETH_ALEN, + router->addr) || + nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, + router->if_incoming->net_dev->name) || + nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_DOWN, + gw_node->bandwidth_down) || + nla_put_u32(msg, BATADV_ATTR_BANDWIDTH_UP, + gw_node->bandwidth_up)) { + genlmsg_cancel(msg, hdr); + goto out; + } + + genlmsg_end(msg, hdr); + ret = 0; + +out: + if (router_ifinfo) + batadv_neigh_ifinfo_put(router_ifinfo); + if (router) + batadv_neigh_node_put(router); + return ret; +} + +int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + struct batadv_hard_iface *primary_if = NULL; + struct net *net = sock_net(cb->skb->sk); + int portid = NETLINK_CB(cb->skb).portid; + struct net_device *soft_iface = NULL; + struct batadv_gw_node *gw_node; + struct batadv_priv *bat_priv; + int idx_skip = cb->args[0]; + int ifindex; + int idx = 0; + int ret; + + ifindex = batadv_netlink_get_ifindex(cb->nlh, +BATADV_ATTR_MESH_IFINDEX); + if (!ifindex) + return -EINVAL; + + soft_iface = dev_get_by_index(net, ifindex); + if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { + ret = -ENODEV; + goto out; + } + + bat_priv = netdev_priv(soft_iface); + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { +
[B.A.T.M.A.N.] [PATCH v2 09/12] batman-adv: add B.A.T.M.A.N. V bat_{orig, neigh}_dump implementations
From: Matthias Schiffer Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Add missing includes --- include/uapi/linux/batman_adv.h | 1 + net/batman-adv/bat_iv_ogm.c | 3 + net/batman-adv/bat_v.c | 257 3 files changed, 261 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index baf4ac8..27f277f 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -78,6 +78,7 @@ enum { BATADV_ATTR_LAST_SEEN_MSECS, BATADV_ATTR_NEIGH_ADDRESS, BATADV_ATTR_TQ, + BATADV_ATTR_THROUGHPUT, __BATADV_ATTR_MAX, }; diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index e70560e..6659035 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,8 @@ #include #include #include +#include +#include #include #include "bitarray.h" diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index 3ff8bd1..18821a7 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c @@ -20,23 +20,32 @@ #include #include +#include +#include #include #include #include #include +#include #include #include #include #include #include +#include +#include +#include #include "bat_v_elp.h" #include "bat_v_ogm.h" #include "hard-interface.h" #include "hash.h" +#include "netlink.h" #include "originator.h" #include "packet.h" +struct sk_buff; + static void batadv_v_iface_activate(struct batadv_hard_iface *hard_iface) { /* B.A.T.M.A.N. V does not use any queuing mechanism, therefore it can @@ -182,6 +191,107 @@ static void batadv_v_neigh_print(struct batadv_priv *bat_priv, seq_puts(seq, "No batman nodes in range ...\n"); } +static int +batadv_v_neigh_dump_neigh(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_hardif_neigh_node *hardif_neigh) +{ + void *hdr; + unsigned int last_seen_msecs; + u32 throughput; + + last_seen_msecs = jiffies_to_msecs(jiffies - hardif_neigh->last_seen); + throughput = ewma_throughput_read(&hardif_neigh->bat_v.throughput); + throughput = throughput * 100; + + hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family, NLM_F_MULTI, + BATADV_CMD_GET_NEIGHBORS); + if (!hdr) + return -ENOBUFS; + + if (nla_put(msg, BATADV_ATTR_NEIGH_ADDRESS, ETH_ALEN, + hardif_neigh->addr) || + nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, + hardif_neigh->if_incoming->net_dev->ifindex) || + nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, + last_seen_msecs) || + nla_put_u32(msg, BATADV_ATTR_THROUGHPUT, throughput)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + + nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +static int +batadv_v_neigh_dump_hardif(struct sk_buff *msg, u32 portid, u32 seq, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *hard_iface, + int *idx_s) +{ + struct batadv_hardif_neigh_node *hardif_neigh; + int idx = 0; + + hlist_for_each_entry_rcu(hardif_neigh, +&hard_iface->neigh_list, list) { + if (idx++ < *idx_s) + continue; + + if (batadv_v_neigh_dump_neigh(msg, portid, seq, hardif_neigh)) { + *idx_s = idx - 1; + return -EMSGSIZE; + } + } + + *idx_s = 0; + return 0; +} + +static void +batadv_v_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb, + struct batadv_priv *bat_priv, + struct batadv_hard_iface *single_hardif) +{ + struct batadv_hard_iface *hard_iface; + int i_hardif = 0; + int i_hardif_s = cb->args[0]; + int idx = cb->args[1]; + int portid = NETLINK_CB(cb->skb).portid; + + rcu_read_lock(); + if (single_hardif) { + if (i_hardif_s == 0) { + if (batadv_v_neigh_dump_hardif(msg, portid, + cb->nlh->nlmsg_seq, + bat_priv, single_hardif, + &idx) == 0) + i_hardif++; + } + } else { + list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { +
[B.A.T.M.A.N.] [PATCH v2 07/12] batman-adv: netlink: add originator and neighbor table queries
From: Matthias Schiffer Add BATADV_CMD_GET_ORIGINATORS and BATADV_CMD_GET_NEIGHBORS commands, using handlers bat_orig_dump and bat_neigh_dump in batadv_algo_ops. Will always return -EOPNOTSUPP for now, as no implementations exist yet. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Add missing includes and forward declarations Add kernel doc to the two dump functions. --- include/uapi/linux/batman_adv.h | 2 + net/batman-adv/netlink.c| 14 net/batman-adv/originator.c | 160 net/batman-adv/originator.h | 4 + net/batman-adv/types.h | 7 ++ 5 files changed, 187 insertions(+) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index 25dee3c..35d8e8c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -88,6 +88,8 @@ enum { BATADV_CMD_GET_HARDIFS, BATADV_CMD_GET_TRANSTABLE_LOCAL, BATADV_CMD_GET_TRANSTABLE_GLOBAL, + BATADV_CMD_GET_ORIGINATORS, + BATADV_CMD_GET_NEIGHBORS, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index 3fb1c1f..a01bdf5 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -33,6 +33,7 @@ #include #include +#include "originator.h" #include "hard-interface.h" #include "soft-interface.h" #include "translation-table.h" @@ -222,6 +223,7 @@ batadv_netlink_dump_hardifs(struct sk_buff *msg, struct netlink_callback *cb) static struct nla_policy batadv_netlink_policy[BATADV_ATTR_MAX + 1] = { [BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 }, + [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 }, }; static struct genl_ops batadv_netlink_ops[] = { @@ -255,6 +257,18 @@ static struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_tt_global_dump, }, + { + .cmd = BATADV_CMD_GET_ORIGINATORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_orig_dump, + }, + { + .cmd = BATADV_CMD_GET_NEIGHBORS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_hardif_neigh_dump, + }, }; void __init batadv_netlink_register(void) diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index 1ff4ee4..2ba7a0d 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c @@ -28,11 +28,15 @@ #include #include #include +#include #include #include +#include #include #include #include +#include +#include #include "distributed-arp-table.h" #include "fragmentation.h" @@ -40,8 +44,10 @@ #include "hard-interface.h" #include "hash.h" #include "multicast.h" +#include "netlink.h" #include "network-coding.h" #include "routing.h" +#include "soft-interface.h" #include "translation-table.h" /* hash class keys */ @@ -699,6 +705,83 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset) } /** + * batadv_hardif_neigh_dump - Dump to netlink the neighbor infos for a specific + * outgoing interface + * @msg: message to dump into + * @cb: parameters for the dump + * + * Return: 0 or error value + */ +int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb) +{ + struct net *net = sock_net(cb->skb->sk); + struct net_device *soft_iface = NULL; + struct net_device *hard_iface = NULL; + struct batadv_hard_iface *hardif = BATADV_IF_DEFAULT; + struct batadv_priv *bat_priv; + struct batadv_hard_iface *primary_if = NULL; + int ret; + int ifindex, hard_ifindex; + + ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX); + if (!ifindex) + return -EINVAL; + + soft_iface = dev_get_by_index(net, ifindex); + if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { + ret = -ENODEV; + goto out; + } + + bat_priv = netdev_priv(soft_iface); + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) { + ret = -ENOENT; + goto out; + } + + hard_ifindex = batadv_netlink_get_ifindex(cb->nlh, + BATADV_ATTR_HARD_IFINDEX); + if (hard_ifindex) { + hard_iface = dev_get_by_index(net, hard_ifindex); + if (hard_iface) + hardif = batadv_hardif_get_by_netdev(hard_iface); + + if (!hardif) { + ret = -ENODEV; + go
[B.A.T.M.A.N.] [PATCH v2 10/12] batman-adv: Indicate netlink socket can be used with netns.
Set the netnsof flag on the family structure, indicating it can be used with different network name spaces. Signed-off-by: Andrew Lunn --- net/batman-adv/netlink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index a01bdf5..e188c2b 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -44,6 +44,7 @@ struct genl_family batadv_netlink_family = { .name = BATADV_NL_NAME, .version = 1, .maxattr = BATADV_ATTR_MAX, + .netnsok = true, }; static int -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v2 05/12] batman-adv: compat: Workarounds for previous patch
* NETLINK_CB portid changed name * info->snd_portid changed name * genl_register_family_with_ops implementation Signed-off-by: Sven Eckelmann Signed-off-by: Andrew Lunn --- compat-include/linux/netlink.h | 45 ++ compat-include/net/genetlink.h | 34 +++ compat.h | 6 ++ 3 files changed, 85 insertions(+) create mode 100644 compat-include/linux/netlink.h create mode 100644 compat-include/net/genetlink.h diff --git a/compat-include/linux/netlink.h b/compat-include/linux/netlink.h new file mode 100644 index 000..696f6da --- /dev/null +++ b/compat-include/linux/netlink.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ +#define _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ + +#include +#include_next + +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) + +struct batadv_netlink_skb_parms { + struct ucredcreds; /* Skb credentials */ + union { + __u32 portid; + __u32 pid; + }; + __u32 dst_group; +}; + +#undef NETLINK_CB +#define NETLINK_CB(skb) (*(struct batadv_netlink_skb_parms*)&((skb)->cb)) + +#endif /* < KERNEL_VERSION(3, 7, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NETLINK_H_ */ diff --git a/compat-include/net/genetlink.h b/compat-include/net/genetlink.h new file mode 100644 index 000..bf1ba3d --- /dev/null +++ b/compat-include/net/genetlink.h @@ -0,0 +1,34 @@ +/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: + * + * Marek Lindner, Simon Wunderlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + * + * This file contains macros for maintaining compatibility with older versions + * of the Linux kernel. + */ + +#ifndef _NET_BATMAN_ADV_COMPAT_NET_GENETLINK_H_ +#define _NET_BATMAN_ADV_COMPAT_NET_GENETLINK_H_ + +#include +#include_next + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0) + +#define genl_register_family_with_ops(family, ops) \ + genl_register_family_with_ops((family), (ops), ARRAY_SIZE(ops)) + +#endif /* < KERNEL_VERSION(3, 13, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_NET_GENETLINK_H_ */ diff --git a/compat.h b/compat.h index f746163..440c5db 100644 --- a/compat.h +++ b/compat.h @@ -62,6 +62,12 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\ #endif /* < KERNEL_VERSION(3, 3, 0) */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) + +#define snd_portid snd_pid + +#endif /* < KERNEL_VERSION(3, 7, 0) */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) #define batadv_interface_set_mac_addr(x, y) \ -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v2 03/12] batman-adv: Suppress debugfs entries for netns's
Debugfs is not netns aware. It thus has problems when the same interface name exists in multiple network name spaces. Work around this by not creating entries for interfaces in name spaces other than the default name space. This means meshes in network namespaces cannot be managed via debugfs, but there will soon be a netlink interface which is netns aware. Signed-off-by: Andrew Lunn --- v2: Fix accidental change to __printf Add missing includes. --- net/batman-adv/debugfs.c | 18 ++ 1 file changed, 18 insertions(+) diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c index 9529004..e54f0da 100644 --- a/net/batman-adv/debugfs.c +++ b/net/batman-adv/debugfs.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "bridge_loop_avoidance.h" @@ -495,12 +496,16 @@ void batadv_debugfs_destroy(void) */ int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); struct batadv_debuginfo **bat_debug; struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name, batadv_debugfs); if (!hard_iface->debug_dir) @@ -531,6 +536,11 @@ out: */ void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface) { + struct net *net = dev_net(hard_iface->net_dev); + + if (net != &init_net) + return; + if (batadv_debugfs) { debugfs_remove_recursive(hard_iface->debug_dir); hard_iface->debug_dir = NULL; @@ -541,11 +551,15 @@ int batadv_debugfs_add_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); struct batadv_debuginfo **bat_debug; + struct net *net = dev_net(dev); struct dentry *file; if (!batadv_debugfs) goto out; + if (net != &init_net) + return 0; + bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); if (!bat_priv->debug_dir) goto out; @@ -582,6 +596,10 @@ out: void batadv_debugfs_del_meshif(struct net_device *dev) { struct batadv_priv *bat_priv = netdev_priv(dev); + struct net *net = dev_net(dev); + + if (net != &init_net) + return; batadv_debug_log_cleanup(bat_priv); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v2 06/12] batman-adv: netlink: add translation table query
From: Matthias Schiffer This adds the commands BATADV_CMD_GET_TRANSTABLE_LOCAL and BATADV_CMD_GET_TRANSTABLE_GLOBAL, which correspond to the transtable_local and transtable_global debugfs files. The batadv_tt_client_flags enum is moved to the UAPI to expose it as part of the netlink API. Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Add missing header files. --- include/uapi/linux/batman_adv.h| 47 ++ net/batman-adv/netlink.c | 13 ++ net/batman-adv/packet.h| 36 - net/batman-adv/translation-table.c | 308 + net/batman-adv/translation-table.h | 4 + 5 files changed, 372 insertions(+), 36 deletions(-) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h index b9b7dfd..25dee3c 100644 --- a/include/uapi/linux/batman_adv.h +++ b/include/uapi/linux/batman_adv.h @@ -20,6 +20,42 @@ #define BATADV_NL_NAME "batadv" +/** + * enum batadv_tt_client_flags - TT client specific flags + * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the table + * @BATADV_TT_CLIENT_ROAM: the client roamed to/from another node and the new + * update telling its new real location has not been received/sent yet + * @BATADV_TT_CLIENT_WIFI: this client is connected through a wifi interface. + * This information is used by the "AP Isolation" feature + * @BATADV_TT_CLIENT_ISOLA: this client is considered "isolated". This + * information is used by the Extended Isolation feature + * @BATADV_TT_CLIENT_NOPURGE: this client should never be removed from the table + * @BATADV_TT_CLIENT_NEW: this client has been added to the local table but has + * not been announced yet + * @BATADV_TT_CLIENT_PENDING: this client is marked for removal but it is kept + * in the table for one more originator interval for consistency purposes + * @BATADV_TT_CLIENT_TEMP: this global client has been detected to be part of + * the network but no nnode has already announced it + * + * Bits from 0 to 7 are called _remote flags_ because they are sent on the wire. + * Bits from 8 to 15 are called _local flags_ because they are used for local + * computations only. + * + * Bits from 4 to 7 - a subset of remote flags - are ensured to be in sync with + * the other nodes in the network. To achieve this goal these flags are included + * in the TT CRC computation. + */ +enum batadv_tt_client_flags { + BATADV_TT_CLIENT_DEL = (1 << 0), + BATADV_TT_CLIENT_ROAM= (1 << 1), + BATADV_TT_CLIENT_WIFI= (1 << 4), + BATADV_TT_CLIENT_ISOLA = (1 << 5), + BATADV_TT_CLIENT_NOPURGE = (1 << 8), + BATADV_TT_CLIENT_NEW = (1 << 9), + BATADV_TT_CLIENT_PENDING = (1 << 10), + BATADV_TT_CLIENT_TEMP= (1 << 11), +}; + enum { BATADV_ATTR_UNSPEC, BATADV_ATTR_VERSION, @@ -31,6 +67,15 @@ enum { BATADV_ATTR_HARD_IFNAME, BATADV_ATTR_HARD_ADDRESS, BATADV_ATTR_ACTIVE, + BATADV_ATTR_ORIG_ADDRESS, + BATADV_ATTR_TT_ADDRESS, + BATADV_ATTR_TT_TTVN, + BATADV_ATTR_TT_LAST_TTVN, + BATADV_ATTR_TT_CRC32, + BATADV_ATTR_TT_VID, + BATADV_ATTR_TT_FLAGS, + BATADV_ATTR_FLAG_BEST, + BATADV_ATTR_LAST_SEEN_MSECS, __BATADV_ATTR_MAX, }; @@ -41,6 +86,8 @@ enum { BATADV_CMD_GET_ROUTING_ALGOS, BATADV_CMD_GET_MESH_INFO, BATADV_CMD_GET_HARDIFS, + BATADV_CMD_GET_TRANSTABLE_LOCAL, + BATADV_CMD_GET_TRANSTABLE_GLOBAL, __BATADV_CMD_MAX, }; diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c index e302de3..3fb1c1f 100644 --- a/net/batman-adv/netlink.c +++ b/net/batman-adv/netlink.c @@ -35,6 +35,7 @@ #include "hard-interface.h" #include "soft-interface.h" +#include "translation-table.h" struct genl_family batadv_netlink_family = { .id = GENL_ID_GENERATE, @@ -242,6 +243,18 @@ static struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_netlink_dump_hardifs, }, + { + .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_tt_local_dump, + }, + { + .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_tt_global_dump, + }, }; void __init batadv_netlink_register(void) diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h index 372128d..b45460d 100644 --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h @@ -126,42 +126,6 @@ enum batadv_tt_data_flags { }; /** - * enum batadv_tt_client_flags - TT client specific flags - * @BATADV_TT_CLIENT_DEL: the client has to be deleted from the tabl
[B.A.T.M.A.N.] [PATCH v2 01/12] batman-adv: Handle parent interfaces in a different netns
batman-adv tries to prevent the user from placing a batX soft interface into another batman mesh as a hard interface. It does this by walking up the devices list of parents and ensures they are all none batX interfaces. iflink can point to an interface in a different namespace, so also retrieve the parents name space when finding the parent and use it when doing the comparison. Signed-off-by: Andrew Lunn Signed-off-by: Sven Eckelmann Acked-by: Antonio Quartulli --- v2: Add missing header files Use Sven's code to facilitate a compat.h change --- net/batman-adv/hard-interface.c | 56 +++-- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 8c2f399..cbc8112 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #include "bridge_loop_avoidance.h" #include "debugfs.h" @@ -83,25 +85,61 @@ out: } /** + * batadv_getlink_net - return link net namespace (of use fallback) + * @netdev: net_device to check + * @fallback_net: return in case get_link_net is not available for @netdev + * + * Return: result of rtnl_link_ops->get_link_net or @fallback_net + */ +static const struct net *batadv_getlink_net(const struct net_device *netdev, + const struct net *fallback_net) +{ + + if (!netdev->rtnl_link_ops) + return fallback_net; + + if (!netdev->rtnl_link_ops->get_link_net) + return fallback_net; + + return netdev->rtnl_link_ops->get_link_net(netdev); +} + +/** * batadv_mutual_parents - check if two devices are each others parent - * @dev1: 1st net_device - * @dev2: 2nd net_device + * @dev1: 1st net dev + * @net1: 1st devices netns + * @dev2: 2nd net dev + * @net2: 2nd devices netns * * veth devices come in pairs and each is the parent of the other! * * Return: true if the devices are each others parent, otherwise false */ static bool batadv_mutual_parents(const struct net_device *dev1, - const struct net_device *dev2) + const struct net *net1, + const struct net_device *dev2, + const struct net *net2) { int dev1_parent_iflink = dev_get_iflink(dev1); int dev2_parent_iflink = dev_get_iflink(dev2); + const struct net *dev1_parent_net; + const struct net *dev2_parent_net; + + dev1_parent_net = batadv_getlink_net(dev1, net1); + dev2_parent_net = batadv_getlink_net(dev2, net2); + + if (dev1->rtnl_link_ops && dev1->rtnl_link_ops->get_link_net) + dev1_parent_net = dev1->rtnl_link_ops->get_link_net(dev1); + if (dev2->rtnl_link_ops && dev2->rtnl_link_ops->get_link_net) + dev2_parent_net = dev2->rtnl_link_ops->get_link_net(dev2); if (!dev1_parent_iflink || !dev2_parent_iflink) return false; return (dev1_parent_iflink == dev2->ifindex) && - (dev2_parent_iflink == dev1->ifindex); + (dev2_parent_iflink == dev1->ifindex) && + net_eq(dev1_parent_net, net2) && + net_eq(dev2_parent_net, net1); } /** @@ -119,8 +157,9 @@ static bool batadv_mutual_parents(const struct net_device *dev1, */ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) { - struct net_device *parent_dev; struct net *net = dev_net(net_dev); + struct net_device *parent_dev; + struct net *parent_net = net; bool ret; /* check if this is a batman-adv mesh interface */ @@ -132,13 +171,16 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) dev_get_iflink(net_dev) == net_dev->ifindex) return false; + if (net_dev->rtnl_link_ops && net_dev->rtnl_link_ops->get_link_net) + parent_net = net_dev->rtnl_link_ops->get_link_net(net_dev); + /* recurse over the parent device */ - parent_dev = __dev_get_by_index(net, dev_get_iflink(net_dev)); + parent_dev = __dev_get_by_index(parent_net, dev_get_iflink(net_dev)); /* if we got a NULL parent_dev there is something broken.. */ if (WARN(!parent_dev, "Cannot find parent device")) return false; - if (batadv_mutual_parents(net_dev, parent_dev)) + if (batadv_mutual_parents(net_dev, net, parent_dev, parent_net)) return false; ret = batadv_is_on_batman_iface(parent_dev); -- 2.8.0.rc3
[B.A.T.M.A.N.] [PATCH v2 04/12] batman-adv: add generic netlink query API to replace debugfs files
From: Matthias Schiffer debugfs is currently severely broken virtually everywhere in the kernel where files are dynamically added and removed (see http://lkml.iu.edu/hypermail/linux/kernel/1506.1/02196.html for some details). In addition to that, debugfs is not namespace-aware. Also, the debugfs interface will try to fix the whole list of originators/ TT entries into a single buffer. The situation has improved in recent kernels,as the seq_file infrastructure will fall back to vmalloc now when kmalloc fails. Still, converting all information to text and potentially retrying multiple times until the buffer is big enough is very inefficient. This commit adds generic infrastructur for the netlink interface to batman-adv and implements the following command: * BATADV_CMD_GET_ROUTING_ALGOS: will return the list of supported routing algorithms * BATADV_CMD_GET_MESH_INFO: will return basic information about a batman-adv softif (name, index and MAC address for both the softif and the primary hardif; routing algorithm; batman-adv version) * BATADV_CMD_GET_HARDIFS: will return the list of hardifs (including index, name and MAC address) of all hardifs for a given softif Signed-off-by: Matthias Schiffer Signed-off-by: Andrew Lunn --- v2: Added missing includes and forward declarations of structures. --- Makefile| 1 + include/uapi/linux/batman_adv.h | 49 net/batman-adv/Makefile | 1 + net/batman-adv/main.c | 51 net/batman-adv/main.h | 2 + net/batman-adv/netlink.c| 260 net/batman-adv/netlink.h| 41 +++ 7 files changed, 405 insertions(+) create mode 100644 include/uapi/linux/batman_adv.h create mode 100644 net/batman-adv/netlink.c create mode 100644 net/batman-adv/netlink.h diff --git a/Makefile b/Makefile index 5d2c058..f17bde5 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,7 @@ REVISION= $(shell if [ -d "$(PWD)/.git" ]; then \ fi) export NOSTDINC_FLAGS := \ -I$(PWD)/compat-include/ \ + -I$(PWD)/include/ \ -include $(PWD)/compat.h \ $(CFLAGS) diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h new file mode 100644 index 000..b9b7dfd --- /dev/null +++ b/include/uapi/linux/batman_adv.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2016 B.A.T.M.A.N. contributors: + * + * Matthias Schiffer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _UAPI_LINUX_BATMAN_ADV_H_ +#define _UAPI_LINUX_BATMAN_ADV_H_ + +#define BATADV_NL_NAME "batadv" + +enum { + BATADV_ATTR_UNSPEC, + BATADV_ATTR_VERSION, + BATADV_ATTR_ALGO_NAME, + BATADV_ATTR_MESH_IFINDEX, + BATADV_ATTR_MESH_IFNAME, + BATADV_ATTR_MESH_ADDRESS, + BATADV_ATTR_HARD_IFINDEX, + BATADV_ATTR_HARD_IFNAME, + BATADV_ATTR_HARD_ADDRESS, + BATADV_ATTR_ACTIVE, + __BATADV_ATTR_MAX, +}; + +#define BATADV_ATTR_MAX (__BATADV_ATTR_MAX - 1) + +enum { + BATADV_CMD_UNSPEC, + BATADV_CMD_GET_ROUTING_ALGOS, + BATADV_CMD_GET_MESH_INFO, + BATADV_CMD_GET_HARDIFS, + __BATADV_CMD_MAX, +}; + +#define BATADV_CMD_MAX (__BATADV_CMD_MAX - 1) + +#endif /* _UAPI_LINUX_BATMAN_ADV_H_ */ diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile index 797cf2f..4e5adba 100644 --- a/net/batman-adv/Makefile +++ b/net/batman-adv/Makefile @@ -33,6 +33,7 @@ batman-adv-y += hash.o batman-adv-y += icmp_socket.o batman-adv-y += main.o batman-adv-$(CONFIG_BATMAN_ADV_MCAST) += multicast.o +batman-adv-y += netlink.o batman-adv-$(CONFIG_BATMAN_ADV_NC) += network-coding.o batman-adv-y += originator.o batman-adv-y += routing.o diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index 5f2974b..7b5f585 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,10 @@ #include #include #include +#include +#include #include +#include #include "bat_algo.h" #include "bridge_loop_avoidance.h" @@ -57,6 +61,7 @@ #include "hard-interface.h" #include "icmp_socket.h" #include "multicast.h" +#include "netlink.h" #include "network-coding.h" #include "originator.h" #include "packet.h" @@