Skip to contentSkip to conversation

batman-adv: netlink support for DAT and MCAST

PATCH Applied Linus Lüssing 2 participants 4 messages Mar 13, 2018 – Mar 14, 2018 Batman advanced

lore
Share & tools
lore
#0 lore raw

v3 cover batman-adv: netlink support for DAT and MCAST

This patchset adds netlink support for dumping DAT cache and multicast flags tables.

Changes in v3:
==============
- renamed netlink attributes:
- BATADV_ATTR_DC_ADDRESS -> BATADV_ATTR_DAT_CACHE_IP4ADDRESS
- BATADV_ATTR_DC_HWADDRESS -> BATADV_ATTR_DAT_CACHE_HWADDRESS
- BATADV_ATTR_DC_VID -> BATADV_ATTR_DAT_CACHE_VID

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

#1 lore raw

PATCH v3 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 | 152 +++++++++++++++++++++++++++++++++
 net/batman-adv/distributed-arp-table.h |   8 ++
 net/batman-adv/netlink.c               |  76 ++++++++++-------
 5 files changed, 274 insertions(+), 33 deletions(-)
 create mode 100644 compat-include/net/netlink.h
compat-include/net/netlink.h new file +51 -0
new file mode 100644
index 00000000..d43576e2
@@ -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
index 56ae2893..95ab5dbd 100644
@@ -272,6 +272,21 @@ enum batadv_nl_attrs {
 	 */
 	BATADV_ATTR_BLA_CRC,
 
+	/**
+	 * @BATADV_ATTR_DAT_CACHE_IP4ADDRESS: Client IPv4 address
+	 */
+	BATADV_ATTR_DAT_CACHE_IP4ADDRESS,
+
+	/**
+	 * @BATADV_ATTR_DAT_CACHE_HWADDRESS: Client MAC address
+	 */
+	BATADV_ATTR_DAT_CACHE_HWADDRESS,
+
+	/**
+	 * @BATADV_ATTR_DAT_CACHE_VID: VLAN ID
+	 */
+	BATADV_ATTR_DAT_CACHE_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 +152 -0

177 lines not on this page · raw message

net/batman-adv/distributed-arp-table.h +8 -0
index e24aa960..a0459602 100644
@@ -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 +43 -33

94 lines not on this page · raw message

Signature · 1 line
2.11.0
#2 lore raw

PATCH v3 2/2 batman-adv: add multicast flags netlink support

In reply to Linus Lüssing

Dump 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
index 95ab5dbd..324a0e11 100644
@@ -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_DAT_CACHE_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
index 6b8594e2..3b04ab13 100644
@@ -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
index 2b3e7c3f..0d9459b6 100644
@@ -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_DAT_CACHE_IP4ADDRESS]	= { .type = NLA_U32 },
 	[BATADV_ATTR_DAT_CACHE_HWADDRESS]	= { .len = ETH_ALEN },
 	[BATADV_ATTR_DAT_CACHE_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
maintainer Applied
#3 lore raw
In reply to Linus Lüssing
Quoted 14 lines · On Dienstag, 13. März 2018 11:41:11 CET Linus Lüssing wrote:

This patchset adds netlink support for dumping DAT cache and multicast flags tables.

Changes in v3:
==============
- renamed netlink attributes:
- BATADV_ATTR_DC_ADDRESS -> BATADV_ATTR_DAT_CACHE_IP4ADDRESS
- BATADV_ATTR_DC_HWADDRESS -> BATADV_ATTR_DAT_CACHE_HWADDRESS
- BATADV_ATTR_DC_VID -> BATADV_ATTR_DAT_CACHE_VID

Changes in v2:
==============

Quoted 9 lines

- 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

Applied in 0509fc0c..53c58c1e [1]

Thanks,
Sven

[1] https://git.open-mesh.org/batman-adv.git/commit/9ae766e912b1bace4e7f3ce9960ee8a29ce61dce

    https://git.open-mesh.org/batman-adv.git/commit/9ae766e912b1bace4e7f3ce9960ee8a29ce61dce