Skip to contentSkip to conversation

batctl: netns and netlink support

PATCH Applied Sven Eckelmann 2 participants 21 messages Jul 18, 2016 – Jul 22, 2016

lore
Share & tools
lore
#0 lore raw

v11 cover batctl: netns and netlink support

Hi,

This patchset adds netns/netlink support to batctl. It complements the batman-adv netns/netlink support v10 from July 3th. This series is an update from the v10 sent me on July 3th with the following changes:

* rebased on current master (didn't apply anymore because batman_adv.h changes were extracted from batman-adv and these changes collided with the patchset)
* batman_adv.h changes are now separate patches (based on batman-adv patches)
* asprintf return code is evaluated for systems not initializing *strp

Kind regards,
Sven

#1 lore raw

PATCH v11 1/11 batctl: netlink: add gateway table queries

Add BATADV_CMD_GET_GATEWAYS commands, using handlers bat_gw_dump in batadv_algo_ops. Will always return -EOPNOTSUPP for now, as no implementations exist yet.

---
 batman_adv.h | 8 ++++++++
 1 file changed, 8 insertions(+)
batman_adv.h +8 -0
index 2e2747f..a13fc09 100644
@@ -88,6 +88,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
@@ -120,6 +123,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,
@@ -139,6 +145,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
  */
@@ -153,6 +160,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
Signature · 1 line
2.8.1
#2 lore raw

PATCH v11 2/11 batctl: add B.A.T.M.A.N. Dump BLA claims via netlink

In reply to Sven Eckelmann

From: Andrew Lunn <[email protected]>

Dump the list of bridge loop avoidance claims via the netlink socket.

[[email protected]: add policy for attributes, fix includes, fix soft_iface reference leak]

[[email protected]: fix kerneldoc, fix error reporting]
---
 batman_adv.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
batman_adv.h +12 -0
index a13fc09..96b37ab 100644
@@ -91,6 +91,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
@@ -126,6 +131,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,
@@ -146,6 +156,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
  */
@@ -161,6 +172,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
Signature · 1 line
2.8.1
#3 lore raw

PATCH v11 3/11 batctl: add backbone table netlink support

In reply to Sven Eckelmann

From: Simon Wunderlich <[email protected]>

Dump the list of bridge loop avoidance backbones via the netlink socket.

---
 batman_adv.h | 2 ++
 1 file changed, 2 insertions(+)
batman_adv.h +2 -0
index 96b37ab..734fe83 100644
@@ -157,6 +157,7 @@ enum batadv_nl_attrs {
  * @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_GET_BLA_BACKBONE: Query list of bridge loop avoidance backbones
  * @__BATADV_CMD_AFTER_LAST: internal use
  * @BATADV_CMD_MAX: highest used command number
  */
@@ -173,6 +174,7 @@ enum batadv_nl_commands {
 	BATADV_CMD_GET_NEIGHBORS,
 	BATADV_CMD_GET_GATEWAYS,
 	BATADV_CMD_GET_BLA_CLAIM,
+	BATADV_CMD_GET_BLA_BACKBONE,
 	/* add new commands above here */
 	__BATADV_CMD_AFTER_LAST,
 	BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1
Signature · 1 line
2.8.1
#4 lore raw

PATCH v11 4/11 batctl: Use netlink to replace some of debugfs

In reply to Sven Eckelmann

From: Andrew Lunn <[email protected]>

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.

[[email protected]: Add missing local TTVN in transtable_global, add missing local group id to claim table, fix use-after-free of algo_name, fix alignment of the originator entries]

[[email protected]: fix claimtable output format, fix name of mandatory claim table attributes, fix printing of VIDs]

---
 debug.c     |   22 +-
 debug.h     |    4 +-
 functions.c |   11 +
 functions.h |    2 +
 netlink.c   | 1069 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 netlink.h   |   18 +-
 6 files changed, 1121 insertions(+), 5 deletions(-)
debug.c +20 -2
index 5b280cb..46f03da 100644
@@ -23,10 +23,12 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #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",
@@ -121,7 +129,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) {
@@ -222,16 +230,26 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
+	if (batctl_debug_tables[debug_table].netlink_fn) {
+		err = batctl_debug_tables[debug_table].netlink_fn(
+			mesh_iface, orig_iface, read_opt, orig_timeout,
+			watch_interval);
+		if (err != -EOPNOTSUPP)
+			return err;
+	}
+
 	if (orig_iface)
 		debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", orig_iface, full_path, sizeof(full_path));
 	else
 		debugfs_make_path(DEBUG_BATIF_PATH_FMT "/", mesh_iface, full_path, sizeof(full_path));
+
 	return read_file(full_path, (char *)batctl_debug_tables[debug_table].debugfs_name,
 			 read_opt, orig_timeout, watch_interval,
 			 batctl_debug_tables[debug_table].header_lines);
 }
 
-int print_routing_algos(void) {
+int debug_print_routing_algos(void)
+{
 	char full_path[MAX_PATH+1];
 	char *debugfs_mnt;
 
debug.h +3 -1
index 46e8c3c..1c9374a 100644
@@ -49,13 +49,15 @@ struct debug_table_data {
        const char opt_short[OPT_SHORT_MAX_LEN];
        const char debugfs_name[DEBUG_TABLE_PATH_MAX_LEN];
        size_t header_lines;
+       int (*netlink_fn)(char *mesh_iface, char *hard_iface, int read_opt,
+			 float orig_timeout, float watch_interval);
 };
 
 extern const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM];
 
 int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv);
 int log_print(char *mesh_iface, int argc, char **argv);
-int print_routing_algos(void);
+int debug_print_routing_algos(void);
 int print_vis_info(char *mesh_iface);
 
 #endif
functions.c +11 -0
index 97a6dbd..5b76062 100644
@@ -52,6 +52,7 @@
 #include "sys.h"
 #include "debug.h"
 #include "debugfs.h"
+#include "netlink.h"
 
 static struct timeval start_time;
 static char *host_name;
@@ -850,3 +851,13 @@ err:
 
 	return arg.vid;
 }
+
+int print_routing_algos(void)
+{
+	int err;
+
+	err = netlink_print_routing_algos();
+	if (err == -EOPNOTSUPP)
+		err = debug_print_routing_algos();
+	return err;
+}
functions.h +2 -0
index d0b05b9..2d29d52 100644
@@ -44,6 +44,7 @@ struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac);
 struct ether_addr *resolve_mac(const char *asc);
 int vlan_get_link(const char *ifname, char **parent);
 
+int print_routing_algos(void);
 extern char *line_ptr;
 
 enum {
@@ -59,6 +60,7 @@ enum {
 	SKIP_HEADER = 0x100,
 	UNICAST_ONLY = 0x200,
 	MULTICAST_ONLY = 0x400,
+	PARSE_ONLY = 0x800,
 };
 
 #endif
netlink.c +1068 -1

1,088 lines not on this page · raw message

netlink.h +17 -1
index 0a4d3dd..69f0958 100644
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2009-2016  B.A.T.M.A.N. contributors:
  *
- * Marek Lindner <[email protected]>
+ * Marek Lindner <[email protected]>, Andrew Lunn <[email protected]>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public
@@ -25,6 +25,22 @@
 #include <netlink/genl/genl.h>
 #include <netlink/genl/ctrl.h>
 
+int netlink_print_routing_algos(void);
+int netlink_print_originators(char *mesh_iface, char *orig_iface, int read_opt,
+			      float orig_timeout, float watch_interval);
+int netlink_print_neighbors(char *mesh_iface, char *orig_iface, int read_opt,
+			    float orig_timeout, float watch_interval);
+int netlink_print_gateways(char *mesh_iface, char *orig_iface, int read_opt,
+			   float orig_timeout, float watch_interval);
+int netlink_print_transglobal(char *mesh_iface, char *orig_iface, int read_opt,
+			      float orig_timeout, float watch_interval);
+int netlink_print_translocal(char *mesh_iface, char *orig_iface, int read_opt,
+			     float orig_timeout, float watch_interval);
+int netlink_print_gateways(char *mesh_iface, char *orig_iface, int read_opt,
+			   float orig_timeout, float watch_interval);
+int netlink_print_bla_claim(char *mesh_iface, char *orig_iface, int read_opt,
+			    float orig_timeout, float watch_interval);
+
 extern struct nla_policy batadv_netlink_policy[];
 
 #endif /* _BATCTL_NETLINK_H */
Signature · 1 line
2.8.1
#6 lore raw

PATCH v11 5/11 batctl: add netlink dump function for backbone tables

In reply to Sven Eckelmann

From: Simon Wunderlich <[email protected]>

---
 debug.c   |  1 +
 netlink.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 netlink.h |  2 ++
 3 files changed, 82 insertions(+)
debug.c +1 -0
index 46f03da..ddabbfb 100644
@@ -79,6 +79,7 @@ const struct debug_table_data batctl_debug_tables[BATCTL_TABLE_NUM] = {
 		.opt_short = "bbt",
 		.debugfs_name = "bla_backbone_table",
 		.header_lines = 2,
+		.netlink_fn = netlink_print_bla_backbone,
 	},
 	{
 		.opt_long = "dat_cache",
netlink.c +79 -0

94 lines not on this page · raw message

netlink.h +2 -0
index 69f0958..5ff7ace 100644
@@ -40,6 +40,8 @@ int netlink_print_gateways(char *mesh_iface, char *orig_iface, int read_opt,
 			   float orig_timeout, float watch_interval);
 int netlink_print_bla_claim(char *mesh_iface, char *orig_iface, int read_opt,
 			    float orig_timeout, float watch_interval);
+int netlink_print_bla_backbone(char *mesh_iface, char *orig_iface, int read_opt,
+			       float orig_timeout, float watch_interval);
 
 extern struct nla_policy batadv_netlink_policy[];
 
Signature · 1 line
2.8.1
#8 lore raw

PATCH v11 6/11 batctl: add netlink dump support for B.A.T.M.A.N. V gateways

In reply to Sven Eckelmann
---
 netlink.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)
netlink.c +31 -5
index 1e406a9..43b680e 100644
@@ -794,7 +794,6 @@ static int translocal_callback(struct nl_msg *msg, void *arg)
 
 static const int gateways_mandatory[] = {
 	BATADV_ATTR_ORIG_ADDRESS,
-	BATADV_ATTR_TQ,
 	BATADV_ATTR_ROUTER,
 	BATADV_ATTR_HARD_IFNAME,
 	BATADV_ATTR_BANDWIDTH_DOWN,
@@ -811,6 +810,7 @@ static int gateways_callback(struct nl_msg *msg, void *arg)
 	const char *primary_if;
 	uint32_t bandwidth_down;
 	uint32_t bandwidth_up;
+	uint32_t throughput;
 	uint8_t *router;
 	uint8_t *orig;
 	char c = ' ';
@@ -842,7 +842,6 @@ static int gateways_callback(struct nl_msg *msg, void *arg)
 		c = '*';
 
 	orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]);
-	tq = nla_get_u8(attrs[BATADV_ATTR_TQ]);
 	router = nla_data(attrs[BATADV_ATTR_ROUTER]);
 	primary_if = nla_get_string(attrs[BATADV_ATTR_HARD_IFNAME]);
 	bandwidth_down = nla_get_u32(attrs[BATADV_ATTR_BANDWIDTH_DOWN]);
@@ -858,7 +857,13 @@ static int gateways_callback(struct nl_msg *msg, void *arg)
 	else
 		printf("%17s ", bat_host->name);
 
-	printf("(%3i) ", tq);
+	if (attrs[BATADV_ATTR_THROUGHPUT]) {
+		throughput = nla_get_u32(attrs[BATADV_ATTR_THROUGHPUT]);
+		printf("(%9u.%1u) ", throughput / 10, throughput % 10);
+	} else if (attrs[BATADV_ATTR_TQ]) {
+		tq = nla_get_u8(attrs[BATADV_ATTR_TQ]);
+		printf("(%3i) ", tq);
+	}
 
 	bat_host = bat_hosts_find_by_mac((char *)router);
 	if (!(opts->read_opt & USE_BAT_HOSTS) || !bat_host)
@@ -1168,10 +1173,31 @@ int netlink_print_translocal(char *mesh_iface, char *orig_iface, int read_opts,
 int netlink_print_gateways(char *mesh_iface, char *orig_iface, int read_opts,
 			   float orig_timeout,
 			   float watch_interval)
-{
+{	char *header;
+	int ifindex;
+
+	ifindex = if_nametoindex(mesh_iface);
+	if (!ifindex) {
+		fprintf(stderr, "Interface %s is unknown\n", mesh_iface);
+		return -ENODEV;
+	}
+
+	netlink_print_info(ifindex, BATADV_CMD_GET_ORIGINATORS, PARSE_ONLY);
+
+	if (strlen(algo_name_buf) == 0)
+		return -EINVAL;
+
+	if (!strcmp("BATMAN_IV", algo_name_buf))
+		header = "  Router            ( TQ) Next Hop          [outgoingIf]  Bandwidth\n";
+	if (!strcmp("BATMAN_V", algo_name_buf))
+		header = "  Router            ( throughput) Next Hop          [outgoingIf]  Bandwidth\n";
+
+	if (!header)
+		return -EINVAL;
+
 	return netlink_print_common(mesh_iface, orig_iface, read_opts,
 				    orig_timeout, watch_interval,
-				    "    Router           TQ      Next Hop        outgoingIf   Bandwidth\n",
+				    header,
 				    BATADV_CMD_GET_GATEWAYS,
 				    gateways_callback);
 }
Signature · 1 line
2.8.1
#10 lore raw

PATCH v11 7/11 batctl: Import alfred version of debugfs.*

In reply to Sven Eckelmann

The alfred version of debugfs.c and debugfs.h contains several cleanups regarding error message output, removal of unused declarations and usage of const buffers.

---
 debugfs.c | 17 ++++++++++-------
 debugfs.h |  4 +---
 2 files changed, 11 insertions(+), 10 deletions(-)
debugfs.c +10 -7
index 3c58195..fc39322 100644
@@ -33,6 +33,9 @@
 static int debugfs_premounted;
 static char debugfs_mountpoint[MAX_PATH+1];
 
+static const char *debugfs_find_mountpoint(void);
+static int debugfs_valid_mountpoint(const char *debugfs);
+
 static const char *debugfs_known_mountpoints[] = {
 	"/sys/kernel/debug/",
 	"/debug/",
@@ -40,7 +43,8 @@ static const char *debugfs_known_mountpoints[] = {
 };
 
 /* construct a full path to a debugfs element */
-int debugfs_make_path(const char *fmt, char *mesh_iface, char *buffer, int size)
+int debugfs_make_path(const char *fmt, const char *mesh_iface, char *buffer,
+		      int size)
 {
 	if (strlen(debugfs_mountpoint) == 0) {
 		buffer[0] = '\0';
@@ -53,14 +57,14 @@ int debugfs_make_path(const char *fmt, char *mesh_iface, char *buffer, int size)
 static int debugfs_found;
 
 /* find the path to the mounted debugfs */
-const char *debugfs_find_mountpoint(void)
+static const char *debugfs_find_mountpoint(void)
 {
 	const char **ptr;
 	char type[100];
 	FILE *fp;
 
 	if (debugfs_found)
-		return (const char *) debugfs_mountpoint;
+		return (const char *)debugfs_mountpoint;
 
 	ptr = debugfs_known_mountpoints;
 	while (*ptr) {
@@ -68,7 +72,7 @@ const char *debugfs_find_mountpoint(void)
 			debugfs_found = 1;
 			strncpy(debugfs_mountpoint, *ptr,
 				sizeof(debugfs_mountpoint));
-			debugfs_mountpoint[sizeof(debugfs_mountpoint) - 1] = '\0';
+			debugfs_mountpoint[sizeof(debugfs_mountpoint) - 1] = 0;
 			return debugfs_mountpoint;
 		}
 		ptr++;
@@ -77,8 +81,7 @@ const char *debugfs_find_mountpoint(void)
 	/* give up and parse /proc/mounts */
 	fp = fopen("/proc/mounts", "r");
 	if (fp == NULL) {
-		fprintf(stderr, "Error - can't open /proc/mounts for read: %s\n",
-		       strerror(errno));
+		perror("Error - can't open /proc/mounts for read");
 		return NULL;
 	}
 
@@ -101,7 +104,7 @@ const char *debugfs_find_mountpoint(void)
 
 /* verify that a mountpoint is actually a debugfs instance */
 
-int debugfs_valid_mountpoint(const char *debugfs)
+static int debugfs_valid_mountpoint(const char *debugfs)
 {
 	struct statfs st_fs;
 
debugfs.h +1 -3
index e608902..b4dc6bb 100644
@@ -30,11 +30,9 @@
 # define STR(x) _STR(x)
 #endif
 
-extern const char *debugfs_find_mountpoint(void);
-extern int debugfs_valid_mountpoint(const char *debugfs);
 extern int debugfs_valid_entry(const char *path);
 extern char *debugfs_mount(const char *mountpoint);
-extern int debugfs_make_path(const char *fmt, char *mesh_iface,
+extern int debugfs_make_path(const char *fmt, const char *mesh_iface,
 			     char *buffer, int size);
 
 #endif /* __DEBUGFS_H__ */
Signature · 1 line
2.8.1
#12 lore raw

PATCH v11 8/11 batctl: Split translate_mac from debugfs backend

In reply to Sven Eckelmann

The debugfs tables cannot be used by the batctl in network namespaces. These have to use netlink. Thus the translate_mac should be less tightly linked to the debugfs tables to implement optional netlink support.

---
 functions.c | 46 +++++++++++++++++++++++++++++++++++-----------
 functions.h |  3 ++-
 2 files changed, 37 insertions(+), 12 deletions(-)
functions.c +35 -11
index 5b76062..f994ced 100644
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -371,7 +372,9 @@ out:
 	return res;
 }
 
-struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac)
+static int translate_mac_debugfs(const char *mesh_iface,
+				 const struct ether_addr *mac,
+				 struct ether_addr *mac_out)
 {
 	enum {
 		tg_start,
@@ -381,26 +384,23 @@ struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac)
 	} pos;
 	char full_path[MAX_PATH+1];
 	char *debugfs_mnt;
-	static struct ether_addr in_mac;
-	struct ether_addr *mac_result, *mac_tmp;
+	struct ether_addr *mac_tmp;
 	FILE *f = NULL;
 	size_t len = 0;
 	char *line = NULL;
 	char *input, *saveptr, *token;
 	int line_invalid;
-
-	memcpy(&in_mac, mac, sizeof(in_mac));
-	mac_result = &in_mac;
+	bool found = false;
 
 	debugfs_mnt = debugfs_mount(NULL);
 	if (!debugfs_mnt)
-		goto out;
+		return -EOPNOTSUPP;
 
 	debugfs_make_path(DEBUG_BATIF_PATH_FMT "/" DEBUG_TRANSTABLE_GLOBAL, mesh_iface, full_path, sizeof(full_path));
 
 	f = fopen(full_path, "r");
 	if (!f)
-		goto out;
+		return -EOPNOTSUPP;
 
 	while (getline(&line, &len, f) != -1) {
 		line_invalid = 0;
@@ -419,8 +419,8 @@ struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac)
 				break;
 			case tg_mac:
 				mac_tmp = ether_aton(token);
-				if (!mac_tmp || memcmp(mac_tmp, &in_mac,
-						       sizeof(in_mac)) != 0)
+				if (!mac_tmp || memcmp(mac_tmp, mac,
+						       ETH_ALEN) != 0)
 					line_invalid = 1;
 				else
 					pos = tg_via;
@@ -434,7 +434,8 @@ struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac)
 				if (!mac_tmp) {
 					line_invalid = 1;
 				} else {
-					mac_result = mac_tmp;
+					memcpy(mac_out, mac_tmp, ETH_ALEN);
+					found = true;
 					goto out;
 				}
 				break;
@@ -449,6 +450,29 @@ out:
 	if (f)
 		fclose(f);
 	free(line);
+
+	if (found)
+		return 0;
+	else
+		return -ENOENT;
+}
+
+struct ether_addr *translate_mac(const char *mesh_iface,
+				 const struct ether_addr *mac)
+{
+	struct ether_addr in_mac;
+	static struct ether_addr out_mac;
+	struct ether_addr *mac_result;
+
+	/* input mac has to be copied because it could be in the shared
+	 * ether_aton buffer
+	 */
+	memcpy(&in_mac, mac, sizeof(in_mac));
+	memcpy(&out_mac, mac, sizeof(out_mac));
+	mac_result = &out_mac;
+
+	translate_mac_debugfs(mesh_iface, &in_mac, mac_result);
+
 	return mac_result;
 }
 
functions.h +2 -1
index 2d29d52..1f311ca 100644
@@ -40,7 +40,8 @@ int read_file(const char *dir, const char *path, int read_opt,
 	      float orig_timeout, float watch_interval, size_t header_lines);
 int write_file(const char *dir, const char *fname, const char *arg1,
 	       const char *arg2);
-struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac);
+struct ether_addr *translate_mac(const char *mesh_iface,
+				 const struct ether_addr *mac);
 struct ether_addr *resolve_mac(const char *asc);
 int vlan_get_link(const char *ifname, char **parent);
 
Signature · 1 line
2.8.1
#14 lore raw

PATCH v11 9/11 batctl: Translate mac addresses via netlink

In reply to Sven Eckelmann

The debugfs entries are only available on the main network namespace. All other network namespaces have to fall back to netlink to read the global translation table.

batctl has therefore try to access the translation table via netlink and try to fall back to the debugfs table in case the batman-adv module doesn't support BATADV_CMD_GET_TRANSTABLE_GLOBAL.

---
 functions.c |   6 +-
 netlink.c   | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 netlink.h   |   5 ++
 3 files changed, 195 insertions(+), 1 deletion(-)
functions.c +5 -1
index f994ced..d236d64 100644
@@ -463,6 +463,7 @@ struct ether_addr *translate_mac(const char *mesh_iface,
 	struct ether_addr in_mac;
 	static struct ether_addr out_mac;
 	struct ether_addr *mac_result;
+	int ret;
 
 	/* input mac has to be copied because it could be in the shared
 	 * ether_aton buffer
@@ -471,7 +472,10 @@ struct ether_addr *translate_mac(const char *mesh_iface,
 	memcpy(&out_mac, mac, sizeof(out_mac));
 	mac_result = &out_mac;
 
-	translate_mac_debugfs(mesh_iface, &in_mac, mac_result);
+	ret = translate_mac_netlink(mesh_iface, &in_mac, mac_result);
+
+	if (ret == -EOPNOTSUPP)
+		translate_mac_debugfs(mesh_iface, &in_mac, mac_result);
 
 	return mac_result;
 }
netlink.c +185 -0

206 lines not on this page · raw message

netlink.h +5 -0
index 5ff7ace..b2084fb 100644
@@ -25,6 +25,8 @@
 #include <netlink/genl/genl.h>
 #include <netlink/genl/ctrl.h>
 
+struct ether_addr;
+
 int netlink_print_routing_algos(void);
 int netlink_print_originators(char *mesh_iface, char *orig_iface, int read_opt,
 			      float orig_timeout, float watch_interval);
@@ -43,6 +45,9 @@ int netlink_print_bla_claim(char *mesh_iface, char *orig_iface, int read_opt,
 int netlink_print_bla_backbone(char *mesh_iface, char *orig_iface, int read_opt,
 			       float orig_timeout, float watch_interval);
 
+int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
+			  struct ether_addr *mac_out);
+
 extern struct nla_policy batadv_netlink_policy[];
 
 #endif /* _BATCTL_NETLINK_H */
Signature · 1 line
2.8.1
#16 lore raw

PATCH v11 10/11 batctl: Document a network namespaces example.

In reply to Sven Eckelmann

From: Andrew Lunn <[email protected]>

Add example of has BATMAN can be used with network name spaces in the README.

---
 README | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
README +57 -0
index 6df669a..ce049d4 100644
@@ -555,3 +555,60 @@ where:
 - IPv4 is the IP address of a client in the mesh network
 - MAC is the MAC address associated to that IP
 - last-seen is the amount of time since last refresh of this entry
+
+batctl and network name spaces
+==============================
+
+The batman-adv kernel module is netns aware. Mesh instances can be
+created in name spaces, and interfaces in that name space added to the
+mesh. The mesh interface cannot be moved between name spaces, as is
+typical for virtual interfaces.
+
+The following example creates two network namespaces, and uses veth
+pairs to connect them together into a mesh of three nodes.
+
+EMU1="ip netns exec emu1"
+EMU2="ip netns exec emu2"
+
+ip netns add emu1
+ip netns add emu2
+
+ip link add emu1-veth1 type veth peer name emu2-veth1
+ip link set emu1-veth1 netns emu1
+ip link set emu2-veth1 netns emu2
+
+$EMU1 ip link set emu1-veth1 name veth1
+$EMU2 ip link set emu2-veth1 name veth1
+
+$EMU1 ip link set veth1 up
+$EMU2 ip link set veth1 up
+
+ip link add emu1-veth2 type veth peer name veth2
+ip link set emu1-veth2 netns emu1
+$EMU1 ip link set emu1-veth2 name veth2
+
+$EMU1 ip link set veth2 up
+ip link set veth2 up
+
+$EMU1 batctl if add veth1
+$EMU1 batctl if add veth2
+$EMU1 ip link set bat0 up
+
+$EMU2 batctl if add veth1
+$EMU2 ip link set bat0 up
+
+batctl if add veth2
+ip link set bat0 up
+
+alfred and batadv-vis can also be used with name spaces. In this
+example, only netns has been used, so there are no filesystem name
+spaces. Hence the unix domain socket used by alfred needs to be given
+a unique name per instance.
+
+($EMU1 alfred -m -i bat0 -u /var/run/emu1-alfred.soc) &
+($EMU2 alfred -m -i bat0 -u /var/run/emu2-alfred.soc) &
+alfred -m -i bat0 &
+
+($EMU1 batadv-vis -s -u /var/run/emu1-alfred.soc) &
+($EMU2 batadv-vis -s -u /var/run/emu2-alfred.soc) &
+batadv-vis -s &
Signature · 1 line
2.8.1
#18 lore raw

PATCH v11 11/11 batctl: Use debugfs fallback when netlink not supported

In reply to Sven Eckelmann

The batman-adv release v2016.2 already has the batadv netlink family . Thus the fallback to debugfs not only has to be triggered when the the netlink family doesn't exist but also when the cmd returns a -EOPNOTSUPP. This still has the problem that the header is generated via a different command then the actual table entries. Falling back to debugfs would cause a second header entry for the table.

The header print functionality is therefore refactored to only gather the data for the header and print the actual header either with the first received entry or when the CMD finished without any result.

---
 functions.h |   1 -
 netlink.c   | 146 +++++++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 99 insertions(+), 48 deletions(-)
functions.h +0 -1
index 1f311ca..e24dea0 100644
@@ -61,7 +61,6 @@ enum {
 	SKIP_HEADER = 0x100,
 	UNICAST_ONLY = 0x200,
 	MULTICAST_ONLY = 0x400,
-	PARSE_ONLY = 0x800,
 };
 
 #endif
netlink.c +99 -47

269 lines not on this page · raw message

Signature · 1 line
2.8.1
#19 lore raw

PATCH v12 11/11 batctl: Use debugfs fallback when netlink not supported

The batman-adv release v2016.2 already has the batadv netlink family . Thus the fallback to debugfs not only has to be triggered when the the netlink family doesn't exist but also when the cmd returns a -EOPNOTSUPP. This still has the problem that the header is generated via a different command then the actual table entries. Falling back to debugfs would cause a second header entry for the table.

The header print functionality is therefore refactored to only gather the data for the header and print the actual header either with the first received entry or when the CMD finished without any result.

---
v12:
- also use debugfs for originators/gwl when get_mesh_info is not supported

---
 functions.h |   1 -
 netlink.c   | 150 ++++++++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 101 insertions(+), 50 deletions(-)
functions.h +0 -1
index 1f311ca..e24dea0 100644
@@ -61,7 +61,6 @@ enum {
 	SKIP_HEADER = 0x100,
 	UNICAST_ONLY = 0x200,
 	MULTICAST_ONLY = 0x400,
-	PARSE_ONLY = 0x800,
 };
 
 #endif
netlink.c +101 -49

277 lines not on this page · raw message

Signature · 1 line
2.8.1
#5 lore raw

Re: [B.A.T.M.A.N.] [PATCH v11 04/11] batctl: Use netlink to replace some of debugfs

In reply to Sven Eckelmann
Quoted 16 lines · On Monday, July 18, 2016 12:12:01 Sven Eckelmann wrote:

From: Andrew Lunn <[email protected]>

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.

[[email protected]: Add missing local TTVN in transtable_global, add missing local group id to claim table, fix use-after-free of algo_name, fix alignment of the originator entries]

[[email protected]: fix claimtable output format, fix name of mandatory claim table attributes, fix printing of VIDs]

Quoted 9 lines
---
 debug.c     |   22 +-
 debug.h     |    4 +-
 functions.c |   11 +
 functions.h |    2 +
 netlink.c   | 1069
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
netlink.h   |   18 +-
 6 files changed, 1121 insertions(+), 5 deletions(-)

Applied in revision d8dd1ff.

Thanks,
Marek

#7 lore raw

Re: [B.A.T.M.A.N.] [PATCH v11 05/11] batctl: add netlink dump function for backbone tables

In reply to Sven Eckelmann
Quoted 10 lines · On Monday, July 18, 2016 12:12:02 Sven Eckelmann wrote:

From: Simon Wunderlich <[email protected]>

---
 debug.c   |  1 +
 netlink.c | 79
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ netlink.h
|  2 ++
 3 files changed, 82 insertions(+)

Applied in revision 39c1441.

Thanks,
Marek

#9 lore raw

Re: [B.A.T.M.A.N.] [PATCH v11 06/11] batctl: add netlink dump support for B.A.T.M.A.N. V gateways

In reply to Sven Eckelmann
Quoted 4 lines · On Monday, July 18, 2016 12:12:03 Sven Eckelmann wrote:
---
 netlink.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

Applied in revision 02775f1.

Thanks,
Marek

#11 lore raw

Re: [B.A.T.M.A.N.] [PATCH v11 07/11] batctl: Import alfred version of debugfs.*

In reply to Sven Eckelmann
Quoted 9 lines · On Monday, July 18, 2016 12:12:04 Sven Eckelmann wrote:

The alfred version of debugfs.c and debugfs.h contains several cleanups regarding error message output, removal of unused declarations and usage of const buffers.

---
 debugfs.c | 17 ++++++++++-------
 debugfs.h |  4 +---
 2 files changed, 11 insertions(+), 10 deletions(-)

Applied in revision 23c3c6d.

Thanks,
Marek

#13 lore raw

Re: [B.A.T.M.A.N.] [PATCH v11 08/11] batctl: Split translate_mac from debugfs backend

In reply to Sven Eckelmann
Quoted 9 lines · On Monday, July 18, 2016 12:12:05 Sven Eckelmann wrote:

The debugfs tables cannot be used by the batctl in network namespaces. These have to use netlink. Thus the translate_mac should be less tightly linked to the debugfs tables to implement optional netlink support.

---
 functions.c | 46 +++++++++++++++++++++++++++++++++++-----------
 functions.h |  3 ++-
 2 files changed, 37 insertions(+), 12 deletions(-)

Applied in revision c8434de.

Thanks,
Marek

#15 lore raw

Re: [B.A.T.M.A.N.] [PATCH v11 09/11] batctl: Translate mac addresses via netlink

In reply to Sven Eckelmann
Quoted 8 lines · On Monday, July 18, 2016 12:12:06 Sven Eckelmann wrote:

The debugfs entries are only available on the main network namespace. All other network namespaces have to fall back to netlink to read the global translation table.

batctl has therefore try to access the translation table via netlink and try to fall back to the debugfs table in case the batman-adv module doesn't support BATADV_CMD_GET_TRANSTABLE_GLOBAL.

Quoted 7 lines
---
 functions.c |   6 +-
 netlink.c   | 185
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
netlink.h   |   5 ++
 3 files changed, 195 insertions(+), 1 deletion(-)

Applied in revision c2eb7a6.

Thanks,
Marek

#17 lore raw

Re: [B.A.T.M.A.N.] [PATCH v11 10/11] batctl: Document a network namespaces example.

In reply to Sven Eckelmann
Quoted 10 lines · On Monday, July 18, 2016 12:12:07 Sven Eckelmann wrote:

From: Andrew Lunn <[email protected]>

Add example of has BATMAN can be used with network name spaces in the README.

---
 README | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

Applied in revision 30c2e89.

Thanks,
Marek

#20 lore raw

Re: [B.A.T.M.A.N.] [PATCH v12 11/11] batctl: Use debugfs fallback when netlink not supported

In reply to Sven Eckelmann
Quoted 12 lines · On Tuesday, July 19, 2016 22:09:52 Sven Eckelmann wrote:

The batman-adv release v2016.2 already has the batadv netlink family . Thus the fallback to debugfs not only has to be triggered when the the netlink family doesn't exist but also when the cmd returns a -EOPNOTSUPP. This still has the problem that the header is generated via a different command then the actual table entries. Falling back to debugfs would cause a second header entry for the table.

The header print functionality is therefore refactored to only gather the data for the header and print the actual header either with the first received entry or when the CMD finished without any result.

Quoted 8 lines

---
v12:
- also use debugfs for originators/gwl when get_mesh_info is not supported

---
 functions.h |   1 -
 netlink.c   | 150

++++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 101 insertions(+), 50 deletions(-)

Applied in revision 5401c71.

Thanks,
Marek