Skip to contentSkip to conversation

reorganized kernel interface patches (version 2)

B.A.T.M.A.N. New Marek Lindner 2 participants 6 messages Mar 2, 2010 – Mar 11, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

I merged the feedback given so far into the patchset and post them again to offer you the chance of generating even more feedback. :-)

Changes since version1:
* the known issue from version1 turned out to be a bug in the used kernel
* batctl sysfs path has been changed to /sys/class/net/ since older kernels don't provide the "virtual" subdirectory
* the year of the copyright notice was corrected
* In case the erroneous of input contains a newline it will not be printed to avoid printing 2 subsequent newlines
* the function calls which used global variables before now receive the bat_priv struct as an argument
* added _GNU_SOURCE to bat-hosts.c to avoid compile warning
* batctl gets bonding mode support

Cheers,
Marek

#1 lore raw

PATCH 1/3 batman-adv: convert multiple /proc files to use sysfs

This is the first patch in a series of patches which aim to convert all batman-adv /proc files to sysfs. To keep the changes in a digestable size it has been split up into smaller chunks. During the transition period batman-adv will use /proc as well as sysfs.

As a first step the following files have been converted:
aggregate_ogm, bonding, originators, transtable_global, transtable_local

---
 batman-adv-kernelland/Makefile.kbuild     |    2 +-
 batman-adv-kernelland/aggregation.c       |    5 +-
 batman-adv-kernelland/aggregation.h       |    3 +-
 batman-adv-kernelland/bat_sysfs.c         |  324 ++++++++++++++++++++++++++
 batman-adv-kernelland/bat_sysfs.h         |   26 +++
 batman-adv-kernelland/main.c              |   13 +-
 batman-adv-kernelland/main.h              |    1 -
 batman-adv-kernelland/originator.c        |   78 +++++++-
 batman-adv-kernelland/originator.h        |    1 +
 batman-adv-kernelland/proc.c              |  350 +----------------------------
 batman-adv-kernelland/proc.h              |    5 -
 batman-adv-kernelland/routing.c           |   31 ++-
 batman-adv-kernelland/routing.h           |    3 +-
 batman-adv-kernelland/send.c              |   17 +-
 batman-adv-kernelland/translation-table.c |   44 +++-
 batman-adv-kernelland/translation-table.h |    6 +-
 batman-adv-kernelland/types.h             |    3 +
 17 files changed, 518 insertions(+), 394 deletions(-)
 create mode 100644 batman-adv-kernelland/bat_sysfs.c
 create mode 100644 batman-adv-kernelland/bat_sysfs.h
batman-adv-kernelland/Makefile.kbuild +1 -1
index 3cee49c..b206bc6 100644
@@ -32,4 +32,4 @@ EXTRA_CFLAGS += -DREVISION_VERSION=\"r$(REVISION)\"
 endif
 
 obj-m += batman-adv.o
-batman-adv-objs := main.o proc.o send.o routing.o soft-interface.o device.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o originator.o gateway_common.o gateway_client.o $(shell [ "2" -eq "$(VERSION)" ] 2>&- && [ "6" -eq "$(PATCHLEVEL)" ] 2>&- && [ "$(SUBLEVEL)" -le "28" ] 2>&- && echo bat_printk.o)
+batman-adv-objs := main.o proc.o bat_sysfs.o send.o routing.o soft-interface.o device.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o originator.o gateway_common.o gateway_client.o $(shell [ "2" -eq "$(VERSION)" ] 2>&- && [ "6" -eq "$(PATCHLEVEL)" ] 2>&- && [ "$(SUBLEVEL)" -le "28" ] 2>&- && echo bat_printk.o)
batman-adv-kernelland/aggregation.c +3 -2
index 7917322..a829814 100644
@@ -159,7 +159,8 @@ static void aggregate(struct forw_packet *forw_packet_aggr,
 
 void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len,
 			    struct batman_if *if_incoming, char own_packet,
-			    unsigned long send_time)
+			    unsigned long send_time,
+			    struct bat_priv *bat_priv)
 {
 	/**
 	 * _aggr -> pointer to the packet we want to aggregate with
@@ -175,7 +176,7 @@ void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len,
 	/* find position for the packet in the forward queue */
 	spin_lock_irqsave(&forw_bat_list_lock, flags);
 	/* own packets are not to be aggregated */
-	if ((atomic_read(&aggregation_enabled)) && (!own_packet)) {
+	if ((atomic_read(&bat_priv->aggregation_enabled)) && (!own_packet)) {
 		hlist_for_each_entry(forw_packet_pos, tmp_node, &forw_bat_list,
 				     list) {
 			if (can_aggregate_with(batman_packet,
batman-adv-kernelland/aggregation.h +2 -1
index 6da8df9..7c8e6f7 100644
@@ -32,6 +32,7 @@ static inline int aggregated_packet(int buff_pos, int packet_len, int num_hna)
 
 void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len,
 			    struct batman_if *if_outgoing, char own_packet,
-			    unsigned long send_time);
+			    unsigned long send_time,
+			    struct bat_priv *bat_priv);
 void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff,
 			     int packet_len, struct batman_if *if_incoming);
batman-adv-kernelland/bat_sysfs.c new file +324 -0

324 lines not on this page · raw message

batman-adv-kernelland/bat_sysfs.h new file +26 -0
new file mode 100644
index 0000000..671ebd1
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ */
+
+
+#define SYSFS_IF_MESH_SUBDIR "mesh"
+
+int sysfs_add_meshif(struct net_device *dev);
+void sysfs_del_meshif(struct net_device *dev);
batman-adv-kernelland/main.c +9 -4
index 5c5bde9..a1f7111 100644
@@ -21,6 +21,7 @@
 
 #include "main.h"
 #include "proc.h"
+#include "bat_sysfs.h"
 #include "routing.h"
 #include "send.h"
 #include "originator.h"
@@ -47,8 +48,6 @@ DEFINE_SPINLOCK(forw_bcast_list_lock);
 atomic_t originator_interval;
 atomic_t vis_interval;
 atomic_t vis_mode;
-atomic_t aggregation_enabled;
-atomic_t bonding_enabled;
 int16_t num_hna;
 int16_t num_ifs;
 
@@ -89,8 +88,6 @@ int init_module(void)
 	atomic_set(&vis_interval, 1000);/* TODO: raise this later, this is only
 					 * for debugging now. */
 	atomic_set(&vis_mode, VIS_TYPE_CLIENT_UPDATE);
-	atomic_set(&aggregation_enabled, 1);
-	atomic_set(&bonding_enabled, 0);
 	atomic_set(&gw_mode, GW_MODE_OFF);
 	atomic_set(&gw_srv_class, 0);
 	atomic_set(&gw_clnt_class, 0);
@@ -124,6 +121,11 @@ int init_module(void)
 		goto free_soft_device;
 	}
 
+	retval = sysfs_add_meshif(soft_device);
+
+	if (retval < 0)
+		goto unreg_soft_device;
+
 	register_netdevice_notifier(&hard_if_notifier);
 	dev_add_pack(&batman_adv_packet_type);
 
@@ -132,6 +134,8 @@ int init_module(void)
 
 	return 0;
 
+unreg_soft_device:
+	unregister_netdevice(soft_device);
 free_soft_device:
 	free_netdev(soft_device);
 	soft_device = NULL;
@@ -144,6 +148,7 @@ void cleanup_module(void)
 	shutdown_module();
 
 	if (soft_device) {
+		sysfs_del_meshif(soft_device);
 		unregister_netdev(soft_device);
 		soft_device = NULL;
 	}
batman-adv-kernelland/main.h +0 -1
index 2018c4e..307a6e6 100644
@@ -136,7 +136,6 @@ extern spinlock_t forw_bcast_list_lock;
 extern atomic_t originator_interval;
 extern atomic_t vis_interval;
 extern atomic_t vis_mode;
-extern atomic_t aggregation_enabled;
 extern atomic_t bonding_enabled;
 extern int16_t num_hna;
 extern int16_t num_ifs;
batman-adv-kernelland/originator.c +77 -1

93 lines not on this page · raw message

batman-adv-kernelland/originator.h +1 -0
index c1a9c2d..3d22259 100644
@@ -28,3 +28,4 @@ struct orig_node *get_orig_node(uint8_t *addr);
 struct neigh_node *
 create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
 		uint8_t *neigh, struct batman_if *if_incoming);
+ssize_t orig_fill_buffer_text(char *buff, size_t count, loff_t off);
batman-adv-kernelland/proc.c +1 -349

422 lines not on this page · raw message

batman-adv-kernelland/proc.h +0 -5
index ae33057..6d74c54 100644
@@ -25,16 +25,11 @@
 #define PROC_ROOT_DIR "batman-adv"
 #define PROC_FILE_INTERFACES "interfaces"
 #define PROC_FILE_ORIG_INTERVAL "orig_interval"
-#define PROC_FILE_ORIGINATORS "originators"
 #define PROC_FILE_GATEWAYS "gateways"
 #define PROC_FILE_LOG "log"
 #define PROC_FILE_LOG_LEVEL "log_level"
-#define PROC_FILE_TRANST_LOCAL "transtable_local"
-#define PROC_FILE_TRANST_GLOBAL "transtable_global"
 #define PROC_FILE_VIS_SRV "vis_server"
 #define PROC_FILE_VIS_DATA "vis_data"
-#define PROC_FILE_AGGR "aggregate_ogm"
-#define PROC_FILE_BOND "bonding"
 #define PROC_FILE_GW_MODE "gateway_mode"
 #define PROC_FILE_GW_SRV_LIST "gateway_srv_list"
 
batman-adv-kernelland/routing.c +19 -12
index 47d5757..8610b22 100644
@@ -363,34 +363,36 @@ static char count_real_packets(struct ethhdr *ethhdr,
 
 /* copy primary address for bonding */
 static void mark_bonding_address(struct orig_node *orig_node,
-				struct orig_node *orig_neigh_node,
-				struct batman_packet *batman_packet)
+				 struct orig_node *orig_neigh_node,
+				 struct batman_packet *batman_packet,
+				 struct bat_priv *bat_priv)
 
 {
 	/* don't care if bonding is not enabled */
-	if (!atomic_read(&bonding_enabled)) {
+	if (!atomic_read(&bat_priv->bonding_enabled)) {
 		orig_node->bond.candidates = 0;
 		return;
 	}
 
 	if (batman_packet->flags & PRIMARIES_FIRST_HOP)
 		memcpy(orig_neigh_node->primary_addr,
-						orig_node->orig, ETH_ALEN);
-	 else
-		return;
+		       orig_node->orig, ETH_ALEN);
+
+	return;
 }
 
 /* mark possible bonding candidates in the neighbor list */
-void update_bonding_candidates(struct orig_node *orig_node)
+void update_bonding_candidates(struct orig_node *orig_node,
+			       struct bat_priv *bat_priv)
 {
 	int candidates;
 	int interference_candidate;
 	int best_tq;
 	struct neigh_node *tmp_neigh_node, *tmp_neigh_node2;
-    struct neigh_node *first_candidate, *last_candidate;
+	struct neigh_node *first_candidate, *last_candidate;
 
 	/* don't care if bonding is not enabled */
-	if (!atomic_read(&bonding_enabled)) {
+	if (!atomic_read(&bat_priv->bonding_enabled)) {
 		orig_node->bond.candidates = 0;
 		return;
 	}
@@ -477,6 +479,8 @@ void receive_bat_packet(struct ethhdr *ethhdr,
 				unsigned char *hna_buff, int hna_buff_len,
 				struct batman_if *if_incoming)
 {
+	/* FIXME: each orig_node->batman_if will be attached to a softif */
+	struct bat_priv *bat_priv = netdev_priv(soft_device);
 	struct batman_if *batman_if;
 	struct orig_node *orig_neigh_node, *orig_node;
 	char has_directlink_flag;
@@ -638,8 +642,9 @@ void receive_bat_packet(struct ethhdr *ethhdr,
 		update_orig(orig_node, ethhdr, batman_packet,
 			    if_incoming, hna_buff, hna_buff_len, is_duplicate);
 
-	mark_bonding_address(orig_node, orig_neigh_node, batman_packet);
-	update_bonding_candidates(orig_node);
+	mark_bonding_address(orig_node, orig_neigh_node,
+			     batman_packet, bat_priv);
+	update_bonding_candidates(orig_node, bat_priv);
 
 	/* is single hop (direct) neighbor */
 	if (is_single_hop_neigh) {
@@ -928,6 +933,8 @@ int recv_icmp_packet(struct sk_buff *skb)
  * bonding if possible. */
 struct neigh_node *find_router(struct orig_node *orig_node)
 {
+	/* FIXME: each orig_node->batman_if will be attached to a softif */
+	struct bat_priv *bat_priv = netdev_priv(soft_device);
 	struct orig_node *primary_orig_node;
 	struct orig_node *router_orig;
 	struct neigh_node *router;
@@ -940,7 +947,7 @@ struct neigh_node *find_router(struct orig_node *orig_node)
 		return NULL;
 
 	/* don't care if bonding is not enabled */
-	if (!atomic_read(&bonding_enabled))
+	if (!atomic_read(&bat_priv->bonding_enabled))
 		return orig_node->router;
 
 	router_orig = orig_node->router->orig_node;
batman-adv-kernelland/routing.h +2 -1
index 725779f..9e3d4a2 100644
@@ -38,4 +38,5 @@ int recv_vis_packet(struct sk_buff *skb);
 int recv_bat_packet(struct sk_buff *skb,
 				struct batman_if *batman_if);
 struct neigh_node *find_router(struct orig_node *orig_node);
-void update_bonding_candidates(struct orig_node *orig_node);
+void update_bonding_candidates(struct orig_node *orig_node,
+			       struct bat_priv *bat_priv);
batman-adv-kernelland/send.c +12 -5
index 3e63535..1c82f43 100644
@@ -47,11 +47,11 @@ static unsigned long own_send_time(void)
 }
 
 /* when do we schedule a forwarded packet to be sent */
-static unsigned long forward_send_time(void)
+static unsigned long forward_send_time(struct bat_priv *bat_priv)
 {
 	unsigned long send_time = jiffies; /* Starting now plus... */
 
-	if (atomic_read(&aggregation_enabled))
+	if (atomic_read(&bat_priv->aggregation_enabled))
 		send_time += (((MAX_AGGREGATION_MS - (JITTER/2) +
 				(random32() % JITTER)) * HZ) / 1000);
 	else
@@ -249,6 +249,8 @@ static void rebuild_batman_packet(struct batman_if *batman_if)
 
 void schedule_own_packet(struct batman_if *batman_if)
 {
+	/* FIXME: each batman_if will be attached to a softif */
+	struct bat_priv *bat_priv = netdev_priv(soft_device);
 	unsigned long send_time;
 	struct batman_packet *batman_packet;
 	int vis_server = atomic_read(&vis_mode);
@@ -289,7 +291,9 @@ void schedule_own_packet(struct batman_if *batman_if)
 	slide_own_bcast_window(batman_if);
 	send_time = own_send_time();
 	add_bat_packet_to_list(batman_if->packet_buff,
-			       batman_if->packet_len, batman_if, 1, send_time);
+			       batman_if->packet_len,
+			       batman_if, 1, send_time,
+			       bat_priv);
 }
 
 void schedule_forward_packet(struct orig_node *orig_node,
@@ -298,6 +302,8 @@ void schedule_forward_packet(struct orig_node *orig_node,
 			     uint8_t directlink, int hna_buff_len,
 			     struct batman_if *if_incoming)
 {
+	/* FIXME: each batman_if will be attached to a softif */
+	struct bat_priv *bat_priv = netdev_priv(soft_device);
 	unsigned char in_tq, in_ttl, tq_avg = 0;
 	unsigned long send_time;
 
@@ -343,10 +349,11 @@ void schedule_forward_packet(struct orig_node *orig_node,
 	else
 		batman_packet->flags &= ~DIRECTLINK;
 
-	send_time = forward_send_time();
+	send_time = forward_send_time(bat_priv);
 	add_bat_packet_to_list((unsigned char *)batman_packet,
 			       sizeof(struct batman_packet) + hna_buff_len,
-			       if_incoming, 0, send_time);
+			       if_incoming, 0, send_time,
+			       bat_priv);
 }
 
 static void forw_packet_free(struct forw_packet *forw_packet)
batman-adv-kernelland/translation-table.c +34 -10

95 lines not on this page · raw message

batman-adv-kernelland/translation-table.h +4 -2
index 281125b..fc1be65 100644
@@ -25,13 +25,15 @@ int hna_local_init(void);
 void hna_local_add(uint8_t *addr);
 void hna_local_remove(uint8_t *addr, char *message);
 int hna_local_fill_buffer(unsigned char *buff, int buff_len);
-int hna_local_fill_buffer_text(unsigned char *buff, int buff_len);
+int hna_local_fill_buffer_text(struct net_device *net_dev, char *buff,
+			       size_t count, loff_t off);
 void hna_local_purge(struct work_struct *work);
 void hna_local_free(void);
 int hna_global_init(void);
 void hna_global_add_orig(struct orig_node *orig_node, unsigned char *hna_buff,
 			 int hna_buff_len);
-int hna_global_fill_buffer_text(unsigned char *buff, int buff_len);
+int hna_global_fill_buffer_text(struct net_device *net_dev, char *buff,
+				size_t count, loff_t off);
 void _hna_global_del_orig(struct hna_global_entry *hna_global_entry,
 			  char *orig_str);
 void hna_global_del_orig(struct orig_node *orig_node, char *message);
batman-adv-kernelland/types.h +3 -0
index a82b52d..feb3343 100644
@@ -94,6 +94,9 @@ struct neigh_node {
 
 struct bat_priv {
 	struct net_device_stats stats;
+	atomic_t aggregation_enabled;
+	atomic_t bonding_enabled;
+	struct kobject *mesh_obj;
 };
 
 struct device_client {
Signature · 1 line
1.7.0
#2 lore raw

PATCH 2/3 batctl: follow /proc to sysfs conversion & introduce input validation

In reply to Marek Lindner

batman-adv is in the process of migrating to sysfs, hence batctl needs to adapt the file paths. In addition batctl makes use of the input validation support of the new files in sysfs.

---
 batctl/bat-hosts.c |    2 +-
 batctl/functions.c |    9 +++-
 batctl/functions.h |    3 +
 batctl/main.c      |    8 ++--
 batctl/proc.c      |   34 --------------
 batctl/proc.h      |    8 ---
 batctl/sys.c       |  123 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 batctl/sys.h       |   17 ++++++-
 8 files changed, 149 insertions(+), 55 deletions(-)
batctl/bat-hosts.c +1 -1
index e770a49..33823be 100644
@@ -20,7 +20,7 @@
  */
 
 
-
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
batctl/functions.c +7 -2
index 2ead2fc..cf4d264 100644
@@ -35,8 +35,6 @@
 #include "functions.h"
 #include "bat-hosts.h"
 
-#define BATMAN_ADV_TAG "batman-adv:"
-
 static struct timeval start_time;
 static char *host_name;
 char *line_ptr = NULL;
@@ -174,6 +172,13 @@ open:
 
 read:
 	while ((read = getline(&line_ptr, &len, fp)) != -1) {
+		if (read_opt & SEARCH_ARGS) {
+			/* omit log lines which don't start with the correct tag */
+			if (strncmp(line_ptr, SEARCH_ARGS_TAG, strlen(SEARCH_ARGS_TAG)) == 0)
+				break;
+
+			continue;
+		}
 
 		/* the buffer will be handled elsewhere */
 		if (read_opt & USE_READ_BUFF)
batctl/functions.h +3 -0
index 88fa53b..c21e9a3 100644
@@ -25,6 +25,8 @@
 
 
 #define ETH_STR_LEN 17
+#define BATMAN_ADV_TAG "batman-adv:"
+#define SEARCH_ARGS_TAG "commands:"
 
 /* return time delta from start to end in milliseconds */
 void start_timer(void);
@@ -45,4 +47,5 @@ enum {
 	USE_BAT_HOSTS = 0x04,
 	LOG_MODE = 0x08,
 	USE_READ_BUFF = 0x10,
+	SEARCH_ARGS = 0x20,
 };
batctl/main.c +4 -4
index 6e4493d..99bfb5b 100644
@@ -102,15 +102,15 @@ int main(int argc, char **argv)
 
 	} else if ((strcmp(argv[1], "originators") == 0) || (strcmp(argv[1], "o") == 0)) {
 
-		ret = handle_table(argc - 1, argv + 1, PROC_ORIGINATORS, originators_usage);
+		ret = handle_sys_table(argc - 1, argv + 1, SYS_ORIGINATORS, originators_usage);
 
 	} else if ((strcmp(argv[1], "translocal") == 0) || (strcmp(argv[1], "tl") == 0)) {
 
-		ret = handle_table(argc - 1, argv + 1, PROC_TRANSTABLE_LOCAL, trans_local_usage);
+		ret = handle_sys_table(argc - 1, argv + 1, SYS_TRANSTABLE_LOCAL, trans_local_usage);
 
 	} else if ((strcmp(argv[1], "transglobal") == 0) || (strcmp(argv[1], "tg") == 0)) {
 
-		ret = handle_table(argc - 1, argv + 1, PROC_TRANSTABLE_GLOBAL, trans_global_usage);
+		ret = handle_sys_table(argc - 1, argv + 1, SYS_TRANSTABLE_GLOBAL, trans_global_usage);
 
 	} else if ((strcmp(argv[1], "loglevel") == 0) || (strcmp(argv[1], "ll") == 0)) {
 
@@ -142,7 +142,7 @@ int main(int argc, char **argv)
 
 	} else if ((strcmp(argv[1], "aggregation") == 0) || (strcmp(argv[1], "ag") == 0)) {
 
-		ret = handle_proc_setting(argc - 1, argv + 1, PROC_AGGR, aggregation_usage);
+		ret = handle_sys_setting(argc - 1, argv + 1, SYS_AGGR, aggregation_usage);
 
 	} else if ((strcmp(argv[1], "bisect") == 0)) {
 
batctl/proc.c +0 -34
index 3294662..e323a52 100644
@@ -68,33 +68,6 @@ int interface(int argc, char **argv)
 	return EXIT_SUCCESS;
 }
 
-void originators_usage(void)
-{
-	printf("Usage: batctl [options] originators \n");
-	printf("options:\n");
-	printf(" \t -h print this help\n");
-	printf(" \t -n don't replace mac addresses with bat-host names\n");
-	printf(" \t -w watch mode - refresh the originator table continuously\n");
-}
-
-void trans_local_usage(void)
-{
-	printf("Usage: batctl [options] translocal \n");
-	printf("options:\n");
-	printf(" \t -h print this help\n");
-	printf(" \t -n don't replace mac addresses with bat-host names\n");
-	printf(" \t -w watch mode - refresh the local translation table continuously\n");
-}
-
-void trans_global_usage(void)
-{
-	printf("Usage: batctl [options] transglobal \n");
-	printf("options:\n");
-	printf(" \t -h print this help\n");
-	printf(" \t -n don't replace mac addresses with bat-host names\n");
-	printf(" \t -w watch mode - refresh the global translation table continuously\n");
-}
-
 void gw_srv_list_usage(void)
 {
 	printf("Usage: batctl [options] gw_srv_list \n");
@@ -118,13 +91,6 @@ void vis_server_usage(void)
 	printf(" \t -h print this help\n");
 }
 
-void aggregation_usage(void)
-{
-	printf("Usage: batctl [options] aggregation \n");
-	printf("options:\n");
-	printf(" \t -h print this help\n");
-}
-
 void gw_mode_usage(void)
 {
 	printf("Usage: batctl [options] gw_mode [mode]\n");
batctl/proc.h +0 -8
index d867b78..fba9a19 100644
@@ -21,24 +21,16 @@
 
 #define PROC_ROOT_PATH "/proc/net/batman-adv/"
 #define PROC_INTERFACES "interfaces"
-#define PROC_ORIGINATORS "originators"
 #define PROC_ORIG_INTERVAL "orig_interval"
-#define PROC_TRANSTABLE_LOCAL "transtable_local"
-#define PROC_TRANSTABLE_GLOBAL "transtable_global"
 #define PROC_VIS_SERVER "vis_server"
 #define PROC_VIS_DATA "vis_data"
-#define PROC_AGGR "aggregate_ogm"
 #define PROC_GW_MODE "gateway_mode"
 #define PROC_GW_SRV_LIST "gateway_srv_list"
 
 int interface(int argc, char **argv);
 
-void originators_usage(void);
-void trans_local_usage(void);
-void trans_global_usage(void);
 void orig_interval_usage(void);
 void vis_server_usage(void);
-void aggregation_usage(void);
 void gw_mode_usage(void);
 void gw_srv_list_usage(void);
 int handle_table(int argc, char **argv, char *file_path, void table_usage(void));
batctl/sys.c +120 -3

139 lines not on this page · raw message

batctl/sys.h +14 -3
index 812da63..b7dd975 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 B.A.T.M.A.N. contributors:
+ * Copyright (C) 2009-2010 B.A.T.M.A.N. contributors:
  *
  * Marek Lindner <[email protected]>
  *
@@ -20,10 +20,21 @@
  */
 
 
-#define SYS_ROOT_PATH "/sys/module/batman_adv/"
+#define SYS_MODULE_PATH "/sys/module/batman_adv/"
+#define SYS_BATIF_PATH "/sys/class/net/bat0/mesh/"
 #define SYS_LOG_LEVEL "parameters/debug"
 #define SYS_LOG "log"
+#define SYS_ORIGINATORS "originators"
+#define SYS_TRANSTABLE_LOCAL "transtable_local"
+#define SYS_TRANSTABLE_GLOBAL "transtable_global"
+#define SYS_AGGR "aggregate_ogm"
 
-
+void originators_usage(void);
+void trans_local_usage(void);
+void trans_global_usage(void);
+void aggregation_usage(void);
+void bonding_usage(void);
 int log_print(int argc, char **argv);
 int handle_loglevel(int argc, char **argv);
+int handle_sys_table(int argc, char **argv, char *file_path, void table_usage(void));
+int handle_sys_setting(int argc, char **argv, char *file_path, void setting_usage(void));
Signature · 1 line
1.7.0
#3 lore raw

PATCH 3/3 batctl: adding batctl bonding mode support

In reply to Marek Lindner
---
 batctl/main.c       |   37 +++++++++++++++++++++----------------
 batctl/man/batctl.8 |    4 ++++
 batctl/sys.c        |    7 +++++++
 batctl/sys.h        |    1 +
 4 files changed, 33 insertions(+), 16 deletions(-)
batctl/main.c +21 -16
index 99bfb5b..e0b7f55 100644
@@ -41,23 +41,24 @@
 void print_usage(void) {
 	printf("Usage: batctl [options] commands \n");
 	printf("commands:\n");
-	printf(" \tinterface|if  [none|interface]  \tdisplay or modify the interface settings\n");
-	printf(" \toriginators|o                   \tdisplay the originator table\n");
-	printf(" \tinterval|it   [orig_interval]   \tdisplay or modify the originator interval in ms\n");
-	printf(" \tloglevel|ll   [level]           \tdisplay or modify the log level\n");
-	printf(" \tlog|l                           \tread the log produced by the kernel module\n");
-	printf(" \tgw_mode|gw    [mode]            \tdisplay or modify the gateway mode\n");
-	printf(" \tgw_srv_list|gwl                 \tdisplay the gateway server list\n");
-	printf(" \ttranslocal|tl                   \tdisplay the local translation table\n");
-	printf(" \ttransglobal|tg                  \tdisplay the global translation table\n");
-	printf(" \tvis_server|vs [enable|disable]  \tdisplay or modify the status of the VIS server\n");
-	printf(" \tvis_data|vd [dot|JSON]          \tdisplay the VIS data in dot or JSON format\n");
-	printf(" \taggregation|ag   [0|1]          \tdisplay or modify the packet aggregation setting\n");
+	printf(" \tinterface|if   [none|interface]  \tdisplay or modify the interface settings\n");
+	printf(" \toriginators|o                    \tdisplay the originator table\n");
+	printf(" \tinterval|it    [orig_interval]   \tdisplay or modify the originator interval in ms\n");
+	printf(" \tloglevel|ll    [level]           \tdisplay or modify the log level\n");
+	printf(" \tlog|l                            \tread the log produced by the kernel module\n");
+	printf(" \tgw_mode|gw     [mode]            \tdisplay or modify the gateway mode\n");
+	printf(" \tgw_srv_list|gwl                  \tdisplay the gateway server list\n");
+	printf(" \ttranslocal|tl                    \tdisplay the local translation table\n");
+	printf(" \ttransglobal|tg                   \tdisplay the global translation table\n");
+	printf(" \tvis_server|vs  [enable|disable]  \tdisplay or modify the status of the VIS server\n");
+	printf(" \tvis_data|vd    [dot|JSON]        \tdisplay the VIS data in dot or JSON format\n");
+	printf(" \taggregation|ag [0|1]             \tdisplay or modify the packet aggregation setting\n");
+	printf(" \tbonding|b      [0|1]             \tdisplay or modify the bonding mode setting\n");
 	printf("\n");
-	printf(" \tping|p        <destination>     \tping another batman adv host via layer 2\n");
-	printf(" \ttraceroute|tr <destination>     \ttraceroute another batman adv host via layer 2\n");
-	printf(" \ttcpdump|td    <interface>       \ttcpdump layer 2 traffic on the given interface\n");
-	printf(" \tbisect        <file1> .. <fileN>\tanalyze given log files for routing stability\n");
+	printf(" \tping|p         <destination>     \tping another batman adv host via layer 2\n");
+	printf(" \ttraceroute|tr  <destination>     \ttraceroute another batman adv host via layer 2\n");
+	printf(" \ttcpdump|td     <interface>       \ttcpdump layer 2 traffic on the given interface\n");
+	printf(" \tbisect         <file1> .. <fileN>\tanalyze given log files for routing stability\n");
 	printf("options:\n");
 	printf(" \t-h print this help (or 'batctl <command> -h' for the command specific help)\n");
 	printf(" \t-v print version\n");
@@ -144,6 +145,10 @@ int main(int argc, char **argv)
 
 		ret = handle_sys_setting(argc - 1, argv + 1, SYS_AGGR, aggregation_usage);
 
+	} else if ((strcmp(argv[1], "bonding") == 0) || (strcmp(argv[1], "b") == 0)) {
+
+		ret = handle_sys_setting(argc - 1, argv + 1, SYS_BONDING, bonding_usage);
+
 	} else if ((strcmp(argv[1], "bisect") == 0)) {
 
 		ret = bisect(argc - 1, argv + 1);
batctl/man/batctl.8 +4 -0
index 63b5bd4..dcadec4 100644
@@ -126,6 +126,10 @@ If no parameter is given the current aggregation setting is displayed.
 Otherwise the parameter is used to enable or disable packet
 aggregation.
 .br
+.IP "\fBbonding\fP|\fBb\fP [\fB1\fP|\fB0\fP]"
+If no parameter is given the current bonding mode setting is displayed.
+Otherwise the parameter is used to enable or disable the bonding mode.
+.br
 .IP "\fBping\fP|\fBp\fP [\fB\-c \fP\fIcount\fP][\fB\-i \fP\fIinterval\fP][\fB\-t \fP\fItime\fP] \fIMAC_address\fP|\fIbat\-host_name\fP"
 Layer 2 ping of a MAC address or bat\-host name.  batctl will try to
 find the bat\-host name if the given parameter was not a MAC
batctl/sys.c +7 -0
index 8afffc7..5b4a9fa 100644
@@ -177,6 +177,13 @@ void aggregation_usage(void)
 	printf(" \t -h print this help\n");
 }
 
+void bonding_usage(void)
+{
+	printf("Usage: batctl [options] bonding \n");
+	printf("options:\n");
+	printf(" \t -h print this help\n");
+}
+
 int handle_sys_setting(int argc, char **argv, char *file_path, void setting_usage(void))
 {
 	int optchar, res;
batctl/sys.h +1 -0
index b7dd975..3560f98 100644
@@ -28,6 +28,7 @@
 #define SYS_TRANSTABLE_LOCAL "transtable_local"
 #define SYS_TRANSTABLE_GLOBAL "transtable_global"
 #define SYS_AGGR "aggregate_ogm"
+#define SYS_BONDING "bonding"
 
 void originators_usage(void);
 void trans_local_usage(void);
Signature · 1 line
1.7.0
#4 lore raw
In reply to Marek Lindner

Hi Marek,

those patches look quite good to me now, seems to work here as expected.
Just one note: One of those warnings has gone now with the _GNU_SOURCE stuff. However, getline is also being used in funcitions.c:174 (so adding the define to functions.c too, got rid of the second warning for instance).

Cheers, Linus

Quoted 21 lines · Marek Lindner

Hi,

I merged the feedback given so far into the patchset and post them again to offer you the chance of generating even more feedback. :-)

Changes since version1:
* the known issue from version1 turned out to be a bug in the used kernel
* batctl sysfs path has been changed to /sys/class/net/ since older kernels don't provide the "virtual" subdirectory
* the year of the copyright notice was corrected
* In case the erroneous of input contains a newline it will not be printed to avoid printing 2 subsequent newlines
* the function calls which used global variables before now receive the bat_priv struct as an argument
* added _GNU_SOURCE to bat-hosts.c to avoid compile warning
* batctl gets bonding mode support

Cheers,
Marek

#5 lore raw

Hey,

Quoted 2 lines

those patches look quite good to me now, seems to work here as expected.

thanks for the review. Since there have been no further complains I committed the patches.

Quoted 4 lines

Just one note: One of those warnings has gone now with the _GNU_SOURCE stuff. However, getline is also being used in funcitions.c:174 (so adding the define to functions.c too, got rid of the second warning for instance).

I made a seperate patch for the _GNU_SOURCE stuff as this does not really part of the sysfs conversion.

Regards,
Marek