batman-adv: netlink support for DAT and MCAST
v2 cover batman-adv: netlink support for DAT and MCAST
This patchset adds netlink support for dumping DAT cache and multicast flags tables.
Changes in v2:
==============
- Added missing includes, "#include <linux/netlink.h>" and "#include <uapi/linux/batman_adv.h>", to distributed-arp-table.c
- Added missing forward declaration for "struct netlink_callback" to distributed-arp-table.h
- Changed nla_put_u32() to nla_put_in_addr() for BATADV_ATTR_DC_ADDRESS, removed the then obsolete ntohl() conversion
- Added missing include, "#include <linux/netlink.h>", to multicast.c
- Changed nla_put_u8() to nla_put_u32() for BATADV_ATTR_MCAST_FLAGS and BATADV_ATTR_MCAST_FLAGS_PRIV to enhance extensibility
PATCH v2 1/2 batman-adv: add DAT cache netlink support
Dump the list of DAT cache entries via the netlink socket.
--- compat-include/net/netlink.h | 51 +++++++++++ include/uapi/linux/batman_adv.h | 20 +++++ net/batman-adv/distributed-arp-table.c | 151 +++++++++++++++++++++++++++++++++ net/batman-adv/distributed-arp-table.h | 8 ++ net/batman-adv/netlink.c | 10 +++ 5 files changed, 240 insertions(+) create mode 100644 compat-include/net/netlink.h
compat-include/net/netlink.h new file +51 -0
@@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2007-2018 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_NETLINK_H_ +#define _NET_BATMAN_ADV_COMPAT_NET_NETLINK_H_ + +#include <linux/version.h> +#include_next <net/netlink.h> + +#if LINUX_VERSION_CODE <KERNEL_VERSION (3 ,5 ,0 ) + +static inline int nla_put_be32 (struct sk_buff *skb,int attrtype,__be32 value) +{ +__be32 tmp = value; + +return nla_put (skb, attrtype,sizeof (__be32), &tmp); +} + +#endif /* < KERNEL_VERSION(3, 5, 0) */ + +#if LINUX_VERSION_CODE <KERNEL_VERSION (4 ,1 ,0 ) + +static inline int nla_put_in_addr (struct sk_buff *skb,int attrtype, +__be32 addr) +{ +__be32 tmp = addr; + +return nla_put_be32 (skb, attrtype, tmp); +} + +#endif /* < KERNEL_VERSION(4, 1, 0) */ + +#endif /* _NET_BATMAN_ADV_COMPAT_NET_NETLINK_H_ */
include/uapi/linux/batman_adv.h +20 -0
@@ -272,6 +272,21 @@ enum batadv_nl_attrs {*/ BATADV_ATTR_BLA_CRC , +/** +* @BATADV_ATTR_DC_ADDRESS: Client IPv4 address +*/ +BATADV_ATTR_DC_ADDRESS , + +/** +* @BATADV_ATTR_DC_HWADDRESS: Client MAC address +*/ +BATADV_ATTR_DC_HWADDRESS , + +/** +* @BATADV_ATTR_DC_VID: VLAN ID +*/ +BATADV_ATTR_DC_VID , +/* add attributes above here, update the policy in netlink.c */ /**
@@ -361,6 +376,11 @@ enum batadv_nl_commands {*/ BATADV_CMD_GET_BLA_BACKBONE , +/** +* @BATADV_CMD_GET_DAT_CACHE: Query list of DAT cache entries +*/ + BATADV_CMD_GET_DAT_CACHE, +/* add new commands above here */ /**
net/batman-adv/distributed-arp-table.c +151 -0
176 lines not on this page · raw message
net/batman-adv/distributed-arp-table.h +8 -0
@@ -28,6 +28,7 @@#include "originator.h" +struct netlink_callback ;struct seq_file ;struct sk_buff ;
@@ -81,6 +82,7 @@ batadv_dat_init_own_addr(struct batadv_priv *bat_priv,int batadv_dat_init (struct batadv_priv *bat_priv);void batadv_dat_free (struct batadv_priv *bat_priv);int batadv_dat_cache_seq_print_text (struct seq_file *seq,void *offset); +int batadv_dat_cache_dump (struct sk_buff *msg,struct netlink_callback *cb);/** * batadv_dat_inc_counter() - increment the correct DAT packet counter
@@ -169,6 +171,12 @@ static inline void batadv_dat_free(struct batadv_priv *bat_priv) { } +static inline int +batadv_dat_cache_dump (struct sk_buff *msg,struct netlink_callback *cb) +{ +return -EOPNOTSUPP ; +} +static inline void batadv_dat_inc_counter (struct batadv_priv *bat_priv,u8 subtype) {
net/batman-adv/netlink.c +10 -0
@@ -45,6 +45,7 @@#include "bat_algo.h" #include "bridge_loop_avoidance.h" +#include "distributed-arp-table.h" #include "gateway_client.h" #include "hard-interface.h" #include "originator.h"
@@ -97,6 +98,9 @@ static const struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_BLA_VID] = { .type = NLA_U16 }, [BATADV_ATTR_BLA_BACKBONE] = { .len = ETH_ALEN }, [BATADV_ATTR_BLA_CRC] = { .type = NLA_U16 }, + [BATADV_ATTR_DC_ADDRESS] = { .type = NLA_U32 }, + [BATADV_ATTR_DC_HWADDRESS] = { .len = ETH_ALEN }, + [BATADV_ATTR_DC_VID] = { .type = NLA_U16 }, };/**
@@ -604,6 +608,12 @@ static const struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_bla_backbone_dump, }, + { + .cmd = BATADV_CMD_GET_DAT_CACHE, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_dat_cache_dump, + }, };
Signature · 1 line
2.11.0
PATCH v2 2/2 batman-adv: add multicast flags netlink support
In reply to Linus LüssingDump the list of multicast flags entries via the netlink socket.
--- include/uapi/linux/batman_adv.h | 62 +++++++++++ net/batman-adv/multicast.c | 237 ++++++++++++++++++++++++++++++++++++++++ net/batman-adv/multicast.h | 18 +++ net/batman-adv/netlink.c | 12 ++ 4 files changed, 329 insertions(+)
include/uapi/linux/batman_adv.h +62 -0
@@ -92,6 +92,53 @@ enum batadv_tt_client_flags { };/** +* enum batadv_mcast_flags_priv - Private, own multicast flags +* +* These are internal, multicast related flags. Currently they describe certain +* multicast related attributes of the segment this originator bridges into the +* mesh. +* +* Those attributes are used to determine the public multicast flags this +* originator is going to announce via TT. +* +* For netlink, if BATADV_MCAST_FLAGS_BRIDGED is unset then all querier +* related flags are undefined. +*/ +enum batadv_mcast_flags_priv { +/** +* @BATADV_MCAST_FLAGS_BRIDGED: There is a bridge on top of the mesh +* interface. +*/ +BATADV_MCAST_FLAGS_BRIDGED = (1 <<0 ), + +/** +* @BATADV_MCAST_FLAGS_QUERIER_IPV4_EXISTS: Whether an IGMP querier +* exists in the mesh +*/ +BATADV_MCAST_FLAGS_QUERIER_IPV4_EXISTS = (1 <<1 ), + +/** +* @BATADV_MCAST_FLAGS_QUERIER_IPV6_EXISTS: Whether an MLD querier +* exists in the mesh +*/ +BATADV_MCAST_FLAGS_QUERIER_IPV6_EXISTS = (1 <<2 ), + +/** +* @BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING: If an IGMP querier +* exists, whether it is potentially shadowing multicast listeners +* (i.e. querier is behind our own bridge segment) +*/ +BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING = (1 <<3 ), + +/** +* @BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING: If an MLD querier +* exists, whether it is potentially shadowing multicast listeners +* (i.e. querier is behind our own bridge segment) +*/ +BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING = (1 <<4 ), +}; + +/** * enum batadv_nl_attrs - batman-adv netlink attributes */ enum batadv_nl_attrs {
@@ -287,6 +334,16 @@ enum batadv_nl_attrs {*/ BATADV_ATTR_DC_VID , +/** +* @BATADV_ATTR_MCAST_FLAGS: Per originator multicast flags +*/ +BATADV_ATTR_MCAST_FLAGS , + +/** +* @BATADV_ATTR_MCAST_FLAGS_PRIV: Private, own multicast flags +*/ + BATADV_ATTR_MCAST_FLAGS_PRIV, +/* add attributes above here, update the policy in netlink.c */ /**
@@ -381,6 +438,11 @@ enum batadv_nl_commands {*/ BATADV_CMD_GET_DAT_CACHE , +/** +* @BATADV_CMD_GET_MCAST_FLAGS: Query list of multicast flags +*/ + BATADV_CMD_GET_MCAST_FLAGS, +/* add new commands above here */ /**
net/batman-adv/multicast.c +237 -0
263 lines not on this page · raw message
net/batman-adv/multicast.h +18 -0
@@ -21,6 +21,7 @@#include "main.h" +struct netlink_callback ;struct seq_file ;struct sk_buff ;
@@ -54,6 +55,11 @@ void batadv_mcast_init(struct batadv_priv *bat_priv);int batadv_mcast_flags_seq_print_text (struct seq_file *seq,void *offset); +int batadv_mcast_mesh_info_put (struct sk_buff *msg, +struct batadv_priv *bat_priv); + +int batadv_mcast_flags_dump (struct sk_buff *msg,struct netlink_callback *cb); +void batadv_mcast_free (struct batadv_priv *bat_priv);void batadv_mcast_purge_orig (struct batadv_orig_node *orig_node);
@@ -72,6 +78,18 @@ static inline int batadv_mcast_init(struct batadv_priv *bat_priv)return 0 ; } +static inline int +batadv_mcast_mesh_info_put (struct sk_buff *msg,struct batadv_priv *bat_priv) +{ +return 0 ; +} + +static inline int batadv_mcast_flags_dump (struct sk_buff *msg, +struct netlink_callback *cb) +{ +return -EOPNOTSUPP ; +} +static inline void batadv_mcast_free (struct batadv_priv *bat_priv) { }
net/batman-adv/netlink.c +12 -0
@@ -48,6 +48,7 @@#include "distributed-arp-table.h" #include "gateway_client.h" #include "hard-interface.h" +#include "multicast.h" #include "originator.h" #include "soft-interface.h" #include "tp_meter.h"
@@ -101,6 +102,8 @@ static const struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_DC_ADDRESS] = { .type = NLA_U32 }, [BATADV_ATTR_DC_HWADDRESS] = { .len = ETH_ALEN }, [BATADV_ATTR_DC_VID] = { .type = NLA_U16 }, + [BATADV_ATTR_MCAST_FLAGS] = { .type = NLA_U32 }, + [BATADV_ATTR_MCAST_FLAGS_PRIV] = { .type = NLA_U32 }, };/**
@@ -151,6 +154,9 @@ batadv_netlink_mesh_info_put(struct sk_buff *msg, struct net_device *soft_iface) goto out;#endif +if (batadv_mcast_mesh_info_put (msg, bat_priv)) + goto out; + primary_if =batadv_primary_if_get_selected (bat_priv);if (primary_if && primary_if->if_status ==BATADV_IF_ACTIVE ) { hard_iface = primary_if->net_dev;
@@ -614,6 +620,12 @@ static const struct genl_ops batadv_netlink_ops[] = { .policy = batadv_netlink_policy, .dumpit = batadv_dat_cache_dump, }, + { + .cmd = BATADV_CMD_GET_MCAST_FLAGS, + .flags = GENL_ADMIN_PERM, + .policy = batadv_netlink_policy, + .dumpit = batadv_mcast_flags_dump, + }, };
Signature · 1 line
2.11.0
Sven Eckelmann
maintainerQuoted 6 lines · On Sonntag, 11. März 2018 00:53:19 CET Linus Lüssing wrote:
This patchset adds netlink support for dumping DAT cache and multicast flags tables.
Changes in v2:
==============
Quoted 9 lines
- Added missing includes, "#include <
linux/netlink.h>" and "#include <uapi/linux/batman_adv.h>", todistributed-arp-table.c
- Added missing forward declaration for "structnetlink_callback" todistributed-arp-table.h
- Changednla_put_u32()tonla_put_in_addr()forBATADV_ATTR_DC_ADDRESS, removed the then obsoletentohl()conversion
- Added missing include, "#include <linux/netlink.h>", tomulticast.c
- Changednla_put_u8()tonla_put_u32()forBATADV_ATTR_MCAST_FLAGSandBATADV_ATTR_MCAST_FLAGS_PRIVto enhance extensibility
Thanks for the doing the requested changes.
@Antonio: Can you please check whether you are ok with the new netlink names and types.
Review
Quoted 3 lines
(quoted diff) +3
-0+ [BATADV_ATTR_DC_ADDRESS] = { .type = NLA_U32 }, + [BATADV_ATTR_DC_HWADDRESS] = { .len = ETH_ALEN }, + [BATADV_ATTR_DC_VID] = { .type = NLA_U16 },
Kind regards,
Sven
Quoted 17 lines · Sven Eckelmann
Quoted 6 lines · On Sonntag, 11. März 2018 00:53:19 CET Linus Lüssing wrote:
This patchset adds netlink support for dumping DAT cache and multicast flags tables.
Changes in v2:
==============Quoted 9 lines
- Added missing includes, "#include <
linux/netlink.h>" and "#include <uapi/linux/batman_adv.h>", todistributed-arp-table.c
- Added missing forward declaration for "structnetlink_callback" todistributed-arp-table.h
- Changednla_put_u32()tonla_put_in_addr()forBATADV_ATTR_DC_ADDRESS, removed the then obsoletentohl()conversion
- Added missing include, "#include <linux/netlink.h>", tomulticast.c
- Changednla_put_u8()tonla_put_u32()forBATADV_ATTR_MCAST_FLAGSandBATADV_ATTR_MCAST_FLAGS_PRIVto enhance extensibility
Quoted 9 lines
Thanks for the doing the requested changes.
@Antonio: Can you please check whether you are ok with the new netlink names and types.
Quoted 3 lines
(quoted diff) +3
-0+ [BATADV_ATTR_DC_ADDRESS] = { .type = NLA_U32 }, + [BATADV_ATTR_DC_HWADDRESS] = { .len = ETH_ALEN }, + [BATADV_ATTR_DC_VID] = { .type = NLA_U16 },
Personally I'd find "DAT_CACHE" easier to parse than "DC".
I know we have the "batctl dc" command, but that's more to keep the CLI compact.
This said, DAT was meant to be extended in the future and not store only IPv4 addresses. This said, shouldn't we use a more specific name for the address?
Another observation: do these attributes need to be DAT specific? or can we just define (or reuse) a generic HWADDRESS attribute that we might already be using somewhere else (i.e. for TT)?
Regards,
Signature · 1 line
Antonio Quartulli
Sven Eckelmann
maintainerOn Dienstag, 13. März 2018 16:02:34 CET Antonio Quartulli wrote:
[...]
Quoted 3 lines
Another observation: do these attributes need to be DAT specific? or can we just define (or reuse) a generic HWADDRESS attribute that we might already be using somewhere else (i.e. for TT)?
I've asked myself the same but we have BLA_- and TT_ADDRESS and these are named in a way which connects them to these specific subsystems. Using one of them for DAT seems to be a little bit odd.
Kind regards,
Sven
Quoted 9 lines · Sven Eckelmann
On Dienstag, 13. März 2018 16:02:34 CET Antonio Quartulli wrote:
[...]Quoted 3 lines
Another observation: do these attributes need to be DAT specific? or can we just define (or reuse) a generic HWADDRESS attribute that we might already be using somewhere else (i.e. for TT)?
I've asked myself the same but we have BLA_- and
TT_ADDRESSand these are named in a way which connects them to these specific subsystems. Using one of them for DAT seems to be a little bit odd.
Oh ok. In this case it makes sense to have DAT specific attrs.
(if we wanted to, we could still rename all the attrs pointing to the very same data type and unify them, but I don't have a strong opinion about it at this time).
Cheers,
Signature · 1 line
Antonio Quartulli
Sven Eckelmann
maintainerOn Dienstag, 13. März 2018 16:22:24 CET Antonio Quartulli wrote:
[...]
Quoted 3 lines
(if we wanted to, we could still rename all the attrs pointing to the very same data type and unify them, but I don't have a strong opinion about it at this time).
This would break backwards compatibility.
Kind regards,
Sven
Quoted 7 lines · Sven Eckelmann
On Dienstag, 13. März 2018 16:22:24 CET Antonio Quartulli wrote:
[...]Quoted 3 lines
(if we wanted to, we could still rename all the attrs pointing to the very same data type and unify them, but I don't have a strong opinion about it at this time).
This would break backwards compatibility.
Ah right, those names are exported to user space too with the same header file.
We'll live with that then.
Cheers,
Signature · 1 line
Antonio Quartulli