batctl netns and netlink
v9 cover batctl netns and netlink
This patchset adds netns/netlink support to batctl. It complements the batman-adv netns/netlink support v9 as sent today. This series is an update from the v8 series sent on May 23rd with the following changes:
* fix segfault when reading algo_name for originator table header
* import newest version of debugfs.[ch] from alfred
* add patches to translate client mac addresses via netlink
Cheers,
Simon
Andrew Lunn (1):
batctl: Use netlink to replace some of debugfs
Simon Wunderlich (1):
batctl: add netlink dump function for backbone tables
Sven Eckelmann (3):
batctl: Import alfred version of debugfs.*
batctl: Split translate_mac from debugfs backend
batctl: Translate mac addresses via netlink
batman_adv.h | 94 +++++ debug.c | 23 +- debug.h | 4 +- debugfs.c | 17 +- debugfs.h | 4 +- functions.c | 61 ++- functions.h | 5 +- netlink.c | 1328 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- netlink.h | 25 +- packet.h | 36 -- 10 files changed, 1534 insertions(+), 63 deletions(-)
Signature · 1 line
2.8.1
PATCH v9 1/5 batctl: Use netlink to replace some of debugfs
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]
[[email protected]: fix claimtable output format, fix name of mandatory claim table attributes, fix printing of VIDs]
--- batman_adv.h | 92 +++++ debug.c | 22 +- debug.h | 4 +- functions.c | 11 + functions.h | 2 + netlink.c | 1064 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- netlink.h | 18 +- packet.h | 36 -- 8 files changed, 1208 insertions(+), 41 deletions(-)
batman_adv.h +92 -0
@@ -23,6 +23,42 @@#define BATADV_NL_MCAST_GROUP_TPMETER "tpmeter"/** +* 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
@@ -40,6 +76,26 @@* @BATADV_ATTR_TPMETER_BYTES: amount of acked bytes during run * @BATADV_ATTR_TPMETER_COOKIE: session cookie to match tp_meter session * @BATADV_ATTR_PAD: attribute used for padding for 64-bit alignment +* @BATADV_ATTR_ACTIVE: Flag indicating if the hard interface is active +* @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_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_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
@@ -60,6 +116,26 @@ enum batadv_nl_attrs {BATADV_ATTR_TPMETER_BYTES ,BATADV_ATTR_TPMETER_COOKIE ,BATADV_ATTR_PAD , +BATADV_ATTR_ACTIVE , +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_NEIGH_ADDRESS , +BATADV_ATTR_TQ , +BATADV_ATTR_THROUGHPUT , +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,
@@ -73,6 +149,14 @@ enum batadv_nl_attrs {* @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device * @BATADV_CMD_TP_METER: Start a tp meter session * @BATADV_CMD_TP_METER_CANCEL: Cancel a tp meter session +* @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_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 */
@@ -81,6 +165,14 @@ enum batadv_nl_commands {BATADV_CMD_GET_MESH_INFO ,BATADV_CMD_TP_METER ,BATADV_CMD_TP_METER_CANCEL , +BATADV_CMD_GET_ROUTING_ALGOS , +BATADV_CMD_GET_HARDIFS , +BATADV_CMD_GET_TRANSTABLE_LOCAL , +BATADV_CMD_GET_TRANSTABLE_GLOBAL , +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
debug.c +20 -2
@@ -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
@@ -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
@@ -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
@@ -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 +1063 -1
1,083 lines not on this page · raw message
netlink.h +17 -1
@@ -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 */
packet.h +0 -36
@@ -129,42 +129,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 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 =BIT (0 ), -BATADV_TT_CLIENT_ROAM =BIT (1 ), -BATADV_TT_CLIENT_WIFI =BIT (4 ), -BATADV_TT_CLIENT_ISOLA =BIT (5 ), -BATADV_TT_CLIENT_NOPURGE =BIT (8 ), -BATADV_TT_CLIENT_NEW =BIT (9 ), -BATADV_TT_CLIENT_PENDING =BIT (10 ), -BATADV_TT_CLIENT_TEMP =BIT (11 ), -}; - -/** * enum batadv_vlan_flags - flags for the four MSB of any vlan ID field * @BATADV_VLAN_HAS_TAG: whether the field contains a valid vlan tag or not */
Signature · 1 line
2.8.1
PATCH v9 2/5 batctl: add netlink dump function for backbone tables
In reply to Simon Wunderlich--- batman_adv.h | 2 ++ debug.c | 1 + netlink.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ netlink.h | 2 ++ 4 files changed, 84 insertions(+)
batman_adv.h +2 -0
@@ -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
debug.c +1 -0
@@ -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
@@ -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
PATCH v9 3/5 batctl: Import alfred version of debugfs.*
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
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
@@ -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
@@ -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
PATCH v9 4/5 batctl: Split translate_mac from debugfs backend
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
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
@@ -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
@@ -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
PATCH v9 5/5 batctl: Translate mac addresses via netlink
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
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
@@ -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
@@ -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