Skip to contentSkip to conversation

reorganized kernel interface patches [part II]

B.A.T.M.A.N. New Marek Lindner 1 participant 4 messages Mar 15, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

since we have initial steps behind us it is time to move on. The following patches convert 4 files from /proc to /sys - nothing fancy here. Please give it a try and let me know what you think.

Cheers,
Marek

#1 lore raw

PATCH 1/3 batman-adv: convert more files from /proc to /sys

converted files:
vis_mode, gw_mode, vis_data, gateways

---
 batman-adv-kernelland/aggregation.c       |    6 +-
 batman-adv-kernelland/aggregation.h       |    8 +-
 batman-adv-kernelland/bat_sysfs.c         |  221 ++++++++++++++-------
 batman-adv-kernelland/gateway_client.c    |   62 +++++-
 batman-adv-kernelland/gateway_client.h    |    5 +-
 batman-adv-kernelland/gateway_common.c    |   79 ++++-----
 batman-adv-kernelland/gateway_common.h    |    5 +-
 batman-adv-kernelland/main.c              |    6 -
 batman-adv-kernelland/main.h              |    2 -
 batman-adv-kernelland/originator.c        |   34 +++-
 batman-adv-kernelland/originator.h        |    3 +-
 batman-adv-kernelland/proc.c              |  308 -----------------------------
 batman-adv-kernelland/proc.h              |    7 -
 batman-adv-kernelland/routing.c           |   26 ++-
 batman-adv-kernelland/routing.h           |    4 +-
 batman-adv-kernelland/send.c              |   20 ++-
 batman-adv-kernelland/soft-interface.c    |    6 +-
 batman-adv-kernelland/translation-table.c |   26 +++
 batman-adv-kernelland/types.h             |    3 +
 batman-adv-kernelland/vis.c               |  124 ++++++++++--
 batman-adv-kernelland/vis.h               |   17 +-
 21 files changed, 457 insertions(+), 515 deletions(-)
batman-adv-kernelland/aggregation.c +3 -3
index a829814..73c9166 100644
@@ -157,10 +157,10 @@ static void aggregate(struct forw_packet *forw_packet_aggr,
 			(1 << forw_packet_aggr->num_packets);
 }
 
-void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len,
+void add_bat_packet_to_list(struct bat_priv *bat_priv,
+			    unsigned char *packet_buff, int packet_len,
 			    struct batman_if *if_incoming, char own_packet,
-			    unsigned long send_time,
-			    struct bat_priv *bat_priv)
+			    unsigned long send_time)
 {
 	/**
 	 * _aggr -> pointer to the packet we want to aggregate with
batman-adv-kernelland/aggregation.h +4 -4
index 7c8e6f7..cda243b 100644
@@ -30,9 +30,9 @@ static inline int aggregated_packet(int buff_pos, int packet_len, int num_hna)
 		(next_buff_pos <= MAX_AGGREGATION_BYTES);
 }
 
-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,
-			    struct bat_priv *bat_priv);
+void add_bat_packet_to_list(struct bat_priv *bat_priv,
+			    unsigned char *packet_buff, int packet_len,
+			    struct batman_if *if_incoming, char own_packet,
+			    unsigned long send_time);
 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 +152 -69

314 lines not on this page · raw message

batman-adv-kernelland/gateway_client.c +53 -9

100 lines not on this page · raw message

batman-adv-kernelland/gateway_client.h +3 -2
index fc7a0df..9920adc 100644
@@ -27,5 +27,6 @@ void gw_node_update(struct orig_node *orig_node, uint8_t new_gwflags);
 void gw_node_delete(struct orig_node *orig_node);
 void gw_node_purge_deleted(void);
 void gw_node_list_free(void);
-int gw_client_fill_buffer_text(unsigned char *buff, int buff_len);
-bool gw_is_target(struct sk_buff *skb);
+int gw_client_fill_buffer_text(struct net_device *net_dev, char *buff,
+			       size_t count, loff_t off);
+bool gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb);
batman-adv-kernelland/gateway_common.c +34 -45

181 lines not on this page · raw message

batman-adv-kernelland/gateway_common.h +1 -4
index 365cd00..91c6a38 100644
@@ -27,8 +27,5 @@ enum gw_modes {
 #define GW_MODE_CLIENT_NAME	"client"
 #define GW_MODE_SERVER_NAME	"server"
 
-extern atomic_t gw_mode;
-extern atomic_t gw_srv_class;
-
 void gw_srv_class_to_kbit(uint8_t gw_class, int *down, int *up);
-ssize_t gw_mode_set(const char __user *userbuffer, size_t count);
+ssize_t gw_mode_set(struct bat_priv *bat_priv, char *buff, size_t count);
batman-adv-kernelland/main.c +0 -6
index a1f7111..6867cad 100644
@@ -29,7 +29,6 @@
 #include "device.h"
 #include "translation-table.h"
 #include "hard-interface.h"
-#include "gateway_common.h"
 #include "gateway_client.h"
 #include "types.h"
 #include "vis.h"
@@ -47,7 +46,6 @@ DEFINE_SPINLOCK(forw_bcast_list_lock);
 
 atomic_t originator_interval;
 atomic_t vis_interval;
-atomic_t vis_mode;
 int16_t num_hna;
 int16_t num_ifs;
 
@@ -87,10 +85,6 @@ int init_module(void)
 	atomic_set(&originator_interval, 1000);
 	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(&gw_mode, GW_MODE_OFF);
-	atomic_set(&gw_srv_class, 0);
-	atomic_set(&gw_clnt_class, 0);
 
 	/* the name should not be longer than 10 chars - see
 	 * http://lwn.net/Articles/23634/ */
batman-adv-kernelland/main.h +0 -2
index 307a6e6..6b9bbf1 100644
@@ -135,8 +135,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 bonding_enabled;
 extern int16_t num_hna;
 extern int16_t num_ifs;
 
batman-adv-kernelland/originator.c +29 -5
index dd69a32..0a9f905 100644
@@ -28,6 +28,7 @@
 #include "routing.h"
 #include "compat.h"
 #include "gateway_client.h"
+#include "hard-interface.h"
 
 static DECLARE_DELAYED_WORK(purge_orig_wq, purge_orig);
 
@@ -207,7 +208,6 @@ static bool purge_orig_neighbors(struct orig_node *orig_node,
 	return neigh_purged;
 }
 
-
 static bool purge_orig_node(struct orig_node *orig_node)
 {
 	/* FIXME: each batman_if will be attached to a softif */
@@ -229,7 +229,7 @@ static bool purge_orig_node(struct orig_node *orig_node)
 				      orig_node->hna_buff_len);
 			/* update bonding candidates, we could have lost
 			 * some candidates. */
-			update_bonding_candidates(orig_node, bat_priv);
+			update_bonding_candidates(bat_priv, orig_node);
 		}
 	}
 	return false;
@@ -261,7 +261,8 @@ void purge_orig(struct work_struct *work)
 	start_purge_timer();
 }
 
-ssize_t orig_fill_buffer_text(char *buff, size_t count, loff_t off)
+ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff,
+			      size_t count, loff_t off)
 {
 	HASHIT(hashit);
 	struct orig_node *orig_node;
@@ -272,12 +273,35 @@ ssize_t orig_fill_buffer_text(char *buff, size_t count, loff_t off)
 	char orig_str[ETH_STR_LEN], router_str[ETH_STR_LEN];
 
 	rcu_read_lock();
+	if (list_empty(&if_list)) {
+		rcu_read_unlock();
+
+		if (off == 0)
+			return sprintf(buff,
+				       "BATMAN mesh %s disabled - please specify interfaces to enable it\n",
+				       net_dev->name);
+
+		return 0;
+	}
+
+	if (((struct batman_if *)if_list.next)->if_active != IF_ACTIVE) {
+		rcu_read_unlock();
+
+		if (off == 0)
+			return sprintf(buff,
+				       "BATMAN mesh %s disabled - primary interface not active\n",
+				       net_dev->name);
+
+		return 0;
+	}
+
 	hdr_len = sprintf(buff,
-		   "  %-14s (%s/%i) %17s [%10s]: %20s ... [B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s] \n",
+		   "  %-14s (%s/%i) %17s [%10s]: %20s ... [B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s (%s)] \n",
 		   "Originator", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF",
 		   "Potential nexthops", SOURCE_VERSION, REVISION_VERSION_STR,
 		   ((struct batman_if *)if_list.next)->dev,
-		   ((struct batman_if *)if_list.next)->addr_str);
+		   ((struct batman_if *)if_list.next)->addr_str,
+		   net_dev->name);
 	rcu_read_unlock();
 
 	if (off < hdr_len)
batman-adv-kernelland/originator.h +2 -1
index 3d22259..1f025b7 100644
@@ -28,4 +28,5 @@ 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);
+ssize_t orig_fill_buffer_text(struct net_device *net_dev, char *buff,
+			      size_t count, loff_t off);
batman-adv-kernelland/proc.c +0 -308

331 lines not on this page · raw message

batman-adv-kernelland/proc.h +0 -7
index 6d74c54..37d0558 100644
@@ -25,13 +25,6 @@
 #define PROC_ROOT_DIR "batman-adv"
 #define PROC_FILE_INTERFACES "interfaces"
 #define PROC_FILE_ORIG_INTERVAL "orig_interval"
-#define PROC_FILE_GATEWAYS "gateways"
-#define PROC_FILE_LOG "log"
-#define PROC_FILE_LOG_LEVEL "log_level"
-#define PROC_FILE_VIS_SRV "vis_server"
-#define PROC_FILE_VIS_DATA "vis_data"
-#define PROC_FILE_GW_MODE "gateway_mode"
-#define PROC_FILE_GW_SRV_LIST "gateway_srv_list"
 
 void cleanup_procfs(void);
 int setup_procfs(void);
batman-adv-kernelland/routing.c +16 -10
index 0051259..479c579 100644
@@ -362,10 +362,10 @@ static char count_real_packets(struct ethhdr *ethhdr,
 }
 
 /* copy primary address for bonding */
-static void mark_bonding_address(struct orig_node *orig_node,
+static void mark_bonding_address(struct bat_priv *bat_priv,
+				 struct orig_node *orig_node,
 				 struct orig_node *orig_neigh_node,
-				 struct batman_packet *batman_packet,
-				 struct bat_priv *bat_priv)
+				 struct batman_packet *batman_packet)
 
 {
 	/* don't care if bonding is not enabled */
@@ -382,8 +382,8 @@ static void mark_bonding_address(struct orig_node *orig_node,
 }
 
 /* mark possible bonding candidates in the neighbor list */
-void update_bonding_candidates(struct orig_node *orig_node,
-			       struct bat_priv *bat_priv)
+void update_bonding_candidates(struct bat_priv *bat_priv,
+			       struct orig_node *orig_node)
 {
 	int candidates;
 	int interference_candidate;
@@ -642,9 +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, bat_priv);
-	update_bonding_candidates(orig_node, bat_priv);
+	mark_bonding_address(bat_priv, orig_node,
+			     orig_neigh_node, batman_packet);
+	update_bonding_candidates(bat_priv, orig_node);
 
 	/* is single hop (direct) neighbor */
 	if (is_single_hop_neigh) {
@@ -1150,6 +1150,7 @@ int recv_vis_packet(struct sk_buff *skb)
 {
 	struct vis_packet *vis_packet;
 	struct ethhdr *ethhdr;
+	struct bat_priv *bat_priv;
 	int hdr_size = sizeof(struct vis_packet);
 
 	if (skb_headlen(skb) < hdr_size)
@@ -1169,15 +1170,20 @@ int recv_vis_packet(struct sk_buff *skb)
 	if (is_my_mac(vis_packet->sender_orig))
 		return NET_RX_DROP;
 
+	/* FIXME: each batman_if will be attached to a softif */
+	bat_priv = netdev_priv(soft_device);
+
 	switch (vis_packet->vis_type) {
 	case VIS_TYPE_SERVER_SYNC:
 		/* TODO: handle fragmented skbs properly */
-		receive_server_sync_packet(vis_packet, skb_headlen(skb));
+		receive_server_sync_packet(bat_priv, vis_packet,
+					   skb_headlen(skb));
 		break;
 
 	case VIS_TYPE_CLIENT_UPDATE:
 		/* TODO: handle fragmented skbs properly */
-		receive_client_update_packet(vis_packet, skb_headlen(skb));
+		receive_client_update_packet(bat_priv, vis_packet,
+					     skb_headlen(skb));
 		break;
 
 	default:	/* ignore unknown packet */
batman-adv-kernelland/routing.h +2 -2
index 9e3d4a2..bce4458 100644
@@ -38,5 +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,
-			       struct bat_priv *bat_priv);
+void update_bonding_candidates(struct bat_priv *bat_priv,
+			       struct orig_node *orig_node);
batman-adv-kernelland/send.c +12 -8
index 1c82f43..ae6e745 100644
@@ -253,7 +253,7 @@ void schedule_own_packet(struct batman_if *batman_if)
 	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);
+	int vis_server = atomic_read(&bat_priv->vis_mode);
 
 	/**
 	 * the interface gets activated here to avoid race conditions between
@@ -283,17 +283,21 @@ void schedule_own_packet(struct batman_if *batman_if)
 	else
 		batman_packet->flags &= ~VIS_SERVER;
 
-	batman_packet->gw_flags = (uint8_t)atomic_read(&gw_srv_class);
+	if (atomic_read(&bat_priv->gw_mode) == GW_MODE_SERVER)
+		batman_packet->gw_flags =
+				(uint8_t)atomic_read(&bat_priv->gw_class);
+	else
+		batman_packet->gw_flags = 0;
 
 	/* could be read by receive_bat_packet() */
 	atomic_inc(&batman_if->seqno);
 
 	slide_own_bcast_window(batman_if);
 	send_time = own_send_time();
-	add_bat_packet_to_list(batman_if->packet_buff,
+	add_bat_packet_to_list(bat_priv,
+			       batman_if->packet_buff,
 			       batman_if->packet_len,
-			       batman_if, 1, send_time,
-			       bat_priv);
+			       batman_if, 1, send_time);
 }
 
 void schedule_forward_packet(struct orig_node *orig_node,
@@ -350,10 +354,10 @@ void schedule_forward_packet(struct orig_node *orig_node,
 		batman_packet->flags &= ~DIRECTLINK;
 
 	send_time = forward_send_time(bat_priv);
-	add_bat_packet_to_list((unsigned char *)batman_packet,
+	add_bat_packet_to_list(bat_priv,
+			       (unsigned char *)batman_packet,
 			       sizeof(struct batman_packet) + hna_buff_len,
-			       if_incoming, 0, send_time,
-			       bat_priv);
+			       if_incoming, 0, send_time);
 }
 
 static void forw_packet_free(struct forw_packet *forw_packet)
batman-adv-kernelland/soft-interface.c +5 -1
index 582134f..1e0eff0 100644
@@ -187,6 +187,7 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev)
 	struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
 	struct bat_priv *priv = netdev_priv(dev);
 	struct batman_if *batman_if;
+	struct bat_priv *bat_priv;
 	uint8_t dstaddr[6];
 	int data_len = skb->len;
 	unsigned long flags;
@@ -195,6 +196,9 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev)
 	if (atomic_read(&module_state) != MODULE_ACTIVE)
 		goto dropped;
 
+	/* FIXME: each batman_if will be attached to a softif */
+	bat_priv = netdev_priv(soft_device);
+
 	dev->trans_start = jiffies;
 	/* TODO: check this for locks */
 	hna_local_add(ethhdr->h_source);
@@ -202,7 +206,7 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev)
 	if (is_bcast(ethhdr->h_dest) || is_mcast(ethhdr->h_dest))
 		bcast_dst = true;
 
-	if ((bcast_dst) && gw_is_target(skb))
+	if ((bcast_dst) && gw_is_target(bat_priv, skb))
 		do_bcast = false;
 
 	/* ethernet packet should be broadcasted */
batman-adv-kernelland/translation-table.c +26 -0
index e118d59..f9fb14b 100644
@@ -166,6 +166,19 @@ int hna_local_fill_buffer_text(struct net_device *net_dev, char *buff,
 	unsigned long flags;
 	size_t hdr_len;
 
+	rcu_read_lock();
+	if (list_empty(&if_list)) {
+		rcu_read_unlock();
+
+		if (off == 0)
+			return sprintf(buff,
+				       "BATMAN mesh %s disabled - please specify interfaces to enable it\n",
+				       net_dev->name);
+
+		return 0;
+	}
+	rcu_read_unlock();
+
 	hdr_len = sprintf(buff,
 			  "Locally retrieved addresses (from %s) announced via HNA:\n",
 			  net_dev->name);
@@ -370,6 +383,19 @@ int hna_global_fill_buffer_text(struct net_device *net_dev, char *buff,
 	unsigned long flags;
 	size_t hdr_len;
 
+	rcu_read_lock();
+	if (list_empty(&if_list)) {
+		rcu_read_unlock();
+
+		if (off == 0)
+			return sprintf(buff,
+				       "BATMAN mesh %s disabled - please specify interfaces to enable it\n",
+				       net_dev->name);
+
+		return 0;
+	}
+	rcu_read_unlock();
+
 	hdr_len = sprintf(buff,
 			  "Globally announced HNAs received via the mesh %s (translation table):\n",
 			  net_dev->name);
batman-adv-kernelland/types.h +3 -0
index feb3343..ca34353 100644
@@ -96,6 +96,9 @@ struct bat_priv {
 	struct net_device_stats stats;
 	atomic_t aggregation_enabled;
 	atomic_t bonding_enabled;
+	atomic_t vis_mode;
+	atomic_t gw_mode;
+	atomic_t gw_class;
 	struct kobject *mesh_obj;
 };
 
batman-adv-kernelland/vis.c +106 -18

200 lines not on this page · raw message

batman-adv-kernelland/vis.h +6 -11
index a1f92a4..7e803bb 100644
@@ -49,18 +49,13 @@ struct recvlist_node {
 extern struct hashtable_t *vis_hash;
 extern spinlock_t vis_hash_lock;
 
-void proc_vis_insert_interface(const uint8_t *interface,
-				      struct hlist_head *if_list,
-				      bool primary);
-void proc_vis_read_entry(struct seq_file *seq,
-				struct vis_info_entry *entry,
-				uint8_t *src,
-				bool primary);
-void proc_vis_read_prim_sec(struct seq_file *seq,
-			    struct hlist_head *if_list);
-void receive_server_sync_packet(struct vis_packet *vis_packet,
+ssize_t vis_fill_buffer_text(struct net_device *net_dev, char *buff,
+			      size_t count, loff_t off);
+void receive_server_sync_packet(struct bat_priv *bat_priv,
+				struct vis_packet *vis_packet,
 				int vis_info_len);
-void receive_client_update_packet(struct vis_packet *vis_packet,
+void receive_client_update_packet(struct bat_priv *bat_priv,
+				  struct vis_packet *vis_packet,
 				  int vis_info_len);
 int vis_init(void);
 void vis_quit(void);
Signature · 1 line
1.7.0
#2 lore raw

PATCH 2/3 batctl: adjust to new /sysfs paths

In reply to Marek Lindner
---
 batctl/functions.c |    7 +++++--
 batctl/functions.h |    2 +-
 batctl/main.c      |   14 +++++++-------
 batctl/proc.c      |   29 +++--------------------------
 batctl/proc.h      |    7 -------
 batctl/sys.c       |   33 ++++++++++++++++++++++++++++-----
 batctl/sys.h       |    7 +++++++
 batctl/vis.c       |    8 ++++----
 8 files changed, 55 insertions(+), 52 deletions(-)
batctl/functions.c +5 -2
index 58ba861..a7f4b77 100644
@@ -268,7 +268,7 @@ out:
 	return res;
 }
 
-int write_file(char *dir, char *fname, char *value)
+int write_file(char *dir, char *fname, char *arg1, char *arg2)
 {
 	int fd = 0, res = EXIT_FAILURE;
 	char full_path[500];
@@ -293,7 +293,10 @@ int write_file(char *dir, char *fname, char *value)
 		goto out;
 	}
 
-	write_len = write(fd, value, strlen(value) + 1);
+	if (arg2)
+		write_len = dprintf(fd, "%s %s", arg1, arg2);
+	else
+		write_len = write(fd, arg1, strlen(arg1) + 1);
 
 	if (write_len < 0) {
 		printf("Error - can't write to file '%s': %s\n", full_path, strerror(errno));
batctl/functions.h +1 -1
index c21e9a3..3756392 100644
@@ -35,7 +35,7 @@ char *ether_ntoa_long(const struct ether_addr *addr);
 char *get_name_by_macaddr(struct ether_addr *mac_addr, int read_opt);
 char *get_name_by_macstr(char *mac_str, int read_opt);
 int read_file(char *dir, char *path, int read_opt);
-int write_file(char *dir, char *path, char *value);
+int write_file(char *dir, char *fname, char *arg1, char *arg2);
 int check_proc_dir(char *dir);
 
 extern char *line_ptr;
batctl/main.c +7 -7
index e0b7f55..a07e75b 100644
@@ -47,10 +47,10 @@ void print_usage(void) {
 	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(" \tgateways|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_mode|vm    [mode]            \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");
@@ -125,9 +125,9 @@ int main(int argc, char **argv)
 
 		ret = handle_proc_setting(argc - 1, argv + 1, PROC_ORIG_INTERVAL, orig_interval_usage);
 
-	} else if ((strcmp(argv[1], "vis_server") == 0) || (strcmp(argv[1], "vs") == 0)) {
+	} else if ((strcmp(argv[1], "vis_mode") == 0) || (strcmp(argv[1], "vm") == 0)) {
 
-		ret = handle_proc_setting(argc - 1, argv + 1, PROC_VIS_SERVER, vis_server_usage);
+		ret = handle_sys_setting(argc - 1, argv + 1, SYS_VIS_MODE, vis_mode_usage);
 
 	} else if ((strcmp(argv[1], "vis_data") == 0) || (strcmp(argv[1], "vd") == 0)) {
 
@@ -135,11 +135,11 @@ int main(int argc, char **argv)
 
 	} else if ((strcmp(argv[1], "gw_mode") == 0) || (strcmp(argv[1], "gw") == 0)) {
 
-		ret = handle_proc_setting(argc - 1, argv + 1, PROC_GW_MODE, gw_mode_usage);
+		ret = handle_sys_setting(argc - 1, argv + 1, SYS_GW_MODE, gw_mode_usage);
 
-	} else if ((strcmp(argv[1], "gw_srv_list") == 0) || (strcmp(argv[1], "gwl") == 0)) {
+	} else if ((strcmp(argv[1], "gateways") == 0) || (strcmp(argv[1], "gwl") == 0)) {
 
-		ret = handle_table(argc - 1, argv + 1, PROC_GW_SRV_LIST, gw_srv_list_usage);
+		ret = handle_sys_table(argc - 1, argv + 1, SYS_GATEWAYS, gateways_usage);
 
 	} else if ((strcmp(argv[1], "aggregation") == 0) || (strcmp(argv[1], "ag") == 0)) {
 
batctl/proc.c +3 -26
index e323a52..9f5c24f 100644
@@ -57,9 +57,9 @@ int interface(int argc, char **argv)
 
 	for (i = 1; i < argc; i++) {
 		if (strcmp(argv[i], "none") == 0)
-			res = write_file(PROC_ROOT_PATH, PROC_INTERFACES, "");
+			res = write_file(PROC_ROOT_PATH, PROC_INTERFACES, "", NULL);
 		else
-			res = write_file(PROC_ROOT_PATH, PROC_INTERFACES, argv[i]);
+			res = write_file(PROC_ROOT_PATH, PROC_INTERFACES, argv[i], NULL);
 
 		if (res != EXIT_SUCCESS)
 			return res;
@@ -68,15 +68,6 @@ int interface(int argc, char **argv)
 	return EXIT_SUCCESS;
 }
 
-void gw_srv_list_usage(void)
-{
-	printf("Usage: batctl [options] gw_srv_list \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 gateway server list continuously\n");
-}
-
 void orig_interval_usage(void)
 {
 	printf("Usage: batctl [options] interval \n");
@@ -84,20 +75,6 @@ void orig_interval_usage(void)
 	printf(" \t -h print this help\n");
 }
 
-void vis_server_usage(void)
-{
-	printf("Usage: batctl [options] vis_server \n");
-	printf("options:\n");
-	printf(" \t -h print this help\n");
-}
-
-void gw_mode_usage(void)
-{
-	printf("Usage: batctl [options] gw_mode [mode]\n");
-	printf("options:\n");
-	printf(" \t -h print this help\n");
-}
-
 int handle_table(int argc, char **argv, char *file_path, void table_usage(void))
 {
 	int optchar, read_opt = USE_BAT_HOSTS;
@@ -140,5 +117,5 @@ int handle_proc_setting(int argc, char **argv, char *file_path, void setting_usa
 	if (argc == 1)
 		return read_file(PROC_ROOT_PATH, file_path, SINGLE_READ);
 
-	return write_file(PROC_ROOT_PATH, file_path, argv[1]);
+	return write_file(PROC_ROOT_PATH, file_path, argv[1], NULL);
 }
batctl/proc.h +0 -7
index fba9a19..0b5a6f2 100644
@@ -22,16 +22,9 @@
 #define PROC_ROOT_PATH "/proc/net/batman-adv/"
 #define PROC_INTERFACES "interfaces"
 #define PROC_ORIG_INTERVAL "orig_interval"
-#define PROC_VIS_SERVER "vis_server"
-#define PROC_VIS_DATA "vis_data"
-#define PROC_GW_MODE "gateway_mode"
-#define PROC_GW_SRV_LIST "gateway_srv_list"
 
 int interface(int argc, char **argv);
 
 void orig_interval_usage(void);
-void vis_server_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));
 int handle_proc_setting(int argc, char **argv, char *file_path, void setting_usage(void));
batctl/sys.c +28 -5
index 5b4a9fa..7d035d6 100644
@@ -73,7 +73,7 @@ int log_print(int argc, char **argv)
 
 static void log_level_usage(void)
 {
-	printf("Usage: batctl [options] loglevel \n");
+	printf("Usage: batctl [options] loglevel [level]\n");
 	printf("options:\n");
 	printf(" \t -h print this help\n");
 }
@@ -94,7 +94,7 @@ int handle_loglevel(int argc, char **argv)
 	}
 
 	if (argc != 1) {
-		res = write_file(SYS_MODULE_PATH, SYS_LOG_LEVEL, argv[1]);
+		res = write_file(SYS_MODULE_PATH, SYS_LOG_LEVEL, argv[1], NULL);
 		goto out;
 	}
 
@@ -146,6 +146,15 @@ void trans_global_usage(void)
 	printf(" \t -w watch mode - refresh the global translation table continuously\n");
 }
 
+void gateways_usage(void)
+{
+	printf("Usage: batctl [options] gateways \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 gateway server list continuously\n");
+}
+
 int handle_sys_table(int argc, char **argv, char *file_path, void table_usage(void))
 {
 	int optchar, read_opt = USE_BAT_HOSTS;
@@ -172,14 +181,28 @@ int handle_sys_table(int argc, char **argv, char *file_path, void table_usage(vo
 
 void aggregation_usage(void)
 {
-	printf("Usage: batctl [options] aggregation \n");
+	printf("Usage: batctl [options] aggregation [0|1]\n");
 	printf("options:\n");
 	printf(" \t -h print this help\n");
 }
 
 void bonding_usage(void)
 {
-	printf("Usage: batctl [options] bonding \n");
+	printf("Usage: batctl [options] bonding [0|1]\n");
+	printf("options:\n");
+	printf(" \t -h print this help\n");
+}
+
+void gw_mode_usage(void)
+{
+	printf("Usage: batctl [options] gw_mode [mode]\n");
+	printf("options:\n");
+	printf(" \t -h print this help\n");
+}
+
+void vis_mode_usage(void)
+{
+	printf("Usage: batctl [options] vis_mode [mode]\n");
 	printf("options:\n");
 	printf(" \t -h print this help\n");
 }
@@ -240,5 +263,5 @@ next:
 	return EXIT_FAILURE;
 
 write_file:
-	return write_file(SYS_BATIF_PATH, file_path, argv[1]);
+	return write_file(SYS_BATIF_PATH, file_path, argv[1], argc > 2 ? argv[2] : NULL);
 }
batctl/sys.h +7 -0
index 3560f98..4f10cee 100644
@@ -29,12 +29,19 @@
 #define SYS_TRANSTABLE_GLOBAL "transtable_global"
 #define SYS_AGGR "aggregate_ogm"
 #define SYS_BONDING "bonding"
+#define SYS_GW_MODE "gw_mode"
+#define SYS_GATEWAYS "gateways"
+#define SYS_VIS_MODE "vis_mode"
+#define SYS_VIS_DATA "vis_data"
 
 void originators_usage(void);
 void trans_local_usage(void);
 void trans_global_usage(void);
 void aggregation_usage(void);
 void bonding_usage(void);
+void gw_mode_usage(void);
+void gateways_usage(void);
+void vis_mode_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));
batctl/vis.c +4 -4
index 58a68b7..bf7fa6c 100644
@@ -29,7 +29,7 @@
 #include "vis.h"
 #include "functions.h"
 #include "bat-hosts.h"
-#include "proc.h"
+#include "sys.h"
 
 #define TQ_MAX_VALUE 255
 
@@ -168,9 +168,9 @@ static FILE *open_vis(void)
 	if (check_proc_dir("/proc") != EXIT_SUCCESS)
 		return NULL;
 
-	strncpy(full_path, PROC_ROOT_PATH, strlen(PROC_ROOT_PATH));
-	full_path[strlen(PROC_ROOT_PATH)] = '\0';
-	strncat(full_path, PROC_VIS_DATA,
+	strncpy(full_path, SYS_BATIF_PATH, strlen(SYS_BATIF_PATH));
+	full_path[strlen(SYS_BATIF_PATH)] = '\0';
+	strncat(full_path, SYS_VIS_DATA,
 		sizeof(full_path) - strlen(full_path));
 
 	return fopen(full_path, "r");
Signature · 1 line
1.7.0
#3 lore raw

PATCH 3/3 batctl: update man page

In reply to Marek Lindner
---
 batctl/man/batctl.8 |  138 ++++++++++++++++++++++++++++----------------------
 1 files changed, 77 insertions(+), 61 deletions(-)
batctl/man/batctl.8 +77 -61
index 43fce87..43af853 100644
@@ -53,53 +53,78 @@ protocol.
 .br
 .TP
 .I \fBcommands:
-.IP "\fBinterface\fP|\fBif\fP   [\fBnone\fP|\fIinterface\fP]"
+.IP "\fBinterface\fP|\fBif\fP     [\fBnone\fP|\fBinterface\fP]"
 If no parameter is given the current interface settings are displayed
 otherwise the parameter(s) are added as new interfaces. Use the "none"
 keyword to deactivate all interfaces.
 .br
-.IP "\fBoriginators\fP|\fBo\fP   [\fB\-b\fP][\fB\-n\fP]"
-Display the originator table. Once started batctl will refresh the
-displayed originator table every second. The "\-b" option causes the
-table to be displayed only once (useful for scripts). If "\-n" is
-given batctl will not replace the MAC addresses with bat\-host names
-in the output.
-.br
-.IP "\fBinterval\fP|\fBit\fP    [\fIorig_interval\fP]"
-If no parameter is given the current originator interval setting is
-displayed otherwise the parameter is used to set the originator
-interval. The interval is in units of milliseconds.
-.br
-.IP "\fBloglevel\fP|\fBll\fP    [\fIlevel\fP]"
-If no parameter is given the current log level settings are displayed
-otherwise the parameter is used to set the log level. Level 0 disables
-all logging. Level 1 enables messages related to routing / flooding /
-broadcasting. Level 2 enables messages related to route or hna added /
-changed / deleted. Level 3 enables all messages. The messages are sent
-to the kernel log. Use \fBdmesg\fP(1) to see them.
-.br
-.IP "\fBlog\fP|\fBl\fP           [\fIlogfile\fP][\fB\-b\fP][\fB\-n\fP]\fP"
-batctl will read the file logfile, or stdin if the logfile parameter
-is not given, applying filtering so only the B.A.T.M.A.N. Advanced
-messages are displayed. Whenever there are new log messages appended
-to the file batctl will display them. The option "\-b" causes batctl
-to exit once the end of the file has been reached. If "\-n" is given
-batctl will not replace the MAC addresses with bat\-host names in the
-output.
-.br
-.IP "\fBtranslocal\fP|\fBtl\fP   [\fB\-b\fP][\fB\-n\fP]"
-Display the local translation table. batctl will refresh the
-displayed table every second. The "\-b" option causes the table to be
-displayed only once (useful for scripts). If "\-n" is given batctl
-will not replace the MAC addresses with bat\-host names in the output.
-.br
-.IP "\fBtransglobal\fP|\fBtg\fP  [\fB\-b\fP][\fB\-n\fP]"
-Display the global translation table. batctl will refresh the
-displayed table every second. The "\-b" option causes the table to be
-displayed only once (useful for scripts). If "\-n" is given batctl
-will not replace the MAC addresses with bat\-host names in the output.
-.br
-.IP "\fBvis dot\fP         [\fB\-n\fP|\fB\-\-numbers\fP][\fB\-H\fP|\fB\-\-no-HNA\fP][\fB\-2\fP|\fB\-\-no-2nd\fP]"
+.IP "\fBoriginators\fP|\fBo\fP    [\fB\-b\fP][\fB\-n\fP]"
+Once started batctl will display the list of announced gateways in the network. Use the "\-w" option to let batctl refresh the list every second. If "\-n" is given batctl will not replace the MAC addresses with bat\-host names in the output.
+.br
+.IP "\fBinterval\fP|\fBit\fP      [\fBorig_interval\fP]"
+If no parameter is given the current originator interval setting is displayed otherwise the parameter is used to set the originator interval. The interval is in units of milliseconds.
+.br
+.IP "\fBloglevel\fP|\fBll\fP      [\fBlevel\fP]"
+If no parameter is given the current log level settings are displayed otherwise the parameter is used to set the log level. Level 0 disables all logging. Level 1 enables messages related to routing / flooding / broadcasting. Level 2 enables messages related to route or hna added / changed / deleted. Level 3 enables all messages. The messages are sent to the kernel log. Use \fBdmesg\fP(1) to see them. Make sure to have debugging output enabled when compiling the module otherwise the output as well as the loglevel options won't be available.
+.br
+.IP "\fBlog\fP|\fBl\fP            [\fBlogfile\fP][\fB\-b\fP][\fB\-n\fP]\fP"
+batctl will read the file logfile, or stdin if the logfile parameter is not given, applying filtering so only the B.A.T.M.A.N. Advanced messages are displayed. Once the end of the file has been reached batctl will exit unless the option "\-w" was specified which causes batctl to continue reading the file and print log output whenever new log data has been appended to the file.
+.br
+.IP "\fBgw_mode|gw\fP       [\fBoff\fP|\fBclient\fP|\fBserver\fP] [\fBgw_class\fP]\fP"
+If no parameter is given the current gateway mode is displayed otherwise the parameter is used to set the gateway mode. The second (optional) argument specifies the gateway class. Its function depends on whether the node is a server or a client. If the node is a server this parameter is used to inform other nodes in the network about this node's internet connection bandwidth. Just enter any number (optionally followed by "kbit" or "mbit") and the batman-adv module will guess your appropriate gateway class. Use "/" to separate the down\(hy and upload rates. You can omit the upload rate and the module will assume an upload of download / 5.
+.RS 17
+default: 2000 \-> gateway class 20
+.RE
+.RS 16
+examples: 5000 \-> gateway class 49
+.RE
+.RS 25
+ 5000kbit
+ 5mbit
+ 5mbit/1024
+ 5mbit/1024kbit
+ 5mbit/1mbit
+.RE
+.RS 7
+If the node is a gateway client the parameter will decide which criterias to consider when the batman-adv module has to choose between different internet connections announced by the aforementioned servers.
+.RE
+.RS 17
+default: 20 \-> late switch (TQ 20)
+.RE
+.RS 16
+examples:  1 -> fast connection
+.RS 16
+consider the gateway's advertised throughput as well as the link quality towards the gateway
+.RE
+.RE
+.RS 25
+ 2  \-> stable connection
+.RS 7
+chooses the gateway with the best link quality and stick with it (ignore the advertised throughput)
+.RE
+ 3  \-> fast switch connection
+.RS 7
+chooses the gateway with the best link quality but switches to another gateway as soon as a better one is found
+.RE
+ XX \-> late switch connection
+.RS 7
+chooses the gateway with the best link quality but switches to another gateway as soon as a better one is found which is at least XX TQ better than the currently selected gateway (XX has to be a number between 3 and 256).
+.RE
+.RE
+.br
+.IP "\fBgateways|gwl\fP     [\fB\-w\fP][\fB\-n\fP]"
+Once started batctl will display the list of announced gateways in the network. Use the "\-w" option to let batctl refresh the list every second. If "\-n" was given batctl will not replace the mac addresses with bat\-host names in the output.
+.br
+.IP "\fBtranslocal\fP|\fBtl\fP    [\fB\-w\fP][\fB\-n\fP]"
+Display the local translation table. batctl will refresh the displayed table every second if the "\-w" option was given. Use "\-n" to let batctl not replace the MAC addresses with bat\-host names in the output.
+.br
+.IP "\fBtransglobal\fP|\fBtg\fP   [\fB\-w\fP][\fB\-n\fP]"
+Display the global translation table. batctl will refresh the displayed table every second if the "\-w" option was given. Use "\-n" to let batctl not replace the MAC addresses with bat\-host names in the output.
+.br
+.IP "\fBvis_mode|vm\fP	  [\fBmode\fP]\fP"
+If no parameter is given the current vis mode is displayed otherwise the parameter is used to set the vis mode.
+.br
+.IP "\fBvis_data|vd dot\fP  [\fB\-n\fP|\fB\-\-numbers\fP][\fB\-H\fP|\fB\-\-no-HNA\fP][\fB\-2\fP|\fB\-\-no-2nd\fP]"
 Display the visualisation data in graphviz \fBdot\fP(1) format. If
 "\-\-numbers" or "\-n" is given batctl will not replace the MAC
 addresses with bat-host names in the output. With "\-\-no-HNA" or
@@ -107,7 +132,7 @@ addresses with bat-host names in the output. With "\-\-no-HNA" or
 be seen. With "\-\-no-2nd" or "\-2" a dot cluster is not formed around
 primary and secondary addresses from the same device.
 .br
-.IP "\fBvis json\fP        [\fB\-n\fP|\fB\-\-numbers\fP][\fB\-H\fP|\fB\-\-no-HNA\fP][\fB\-2\fP|\fB\-\-no-2nd\fP]"
+.IP "\fBvis_data|vd json\fP [\fB\-n\fP|\fB\-\-numbers\fP][\fB\-H\fP|\fB\-\-no-HNA\fP][\fB\-2\fP|\fB\-\-no-2nd\fP]"
 Display the visualisation data in JSON format. If "\-\-numbers" or
 "\-n" is given batctl will not replace the MAC addresses with bat-host
 names in the output. With "\-\-no-HNA" or "\-H" the HNA entries are
@@ -115,22 +140,13 @@ not displayed, so the pure mesh topology can be seen. With
 "\-\-no-2nd" or "\-2" a dot cluster is not formed around primary and
 secondary addresses from the same device.
 .br
-.IP "\fBgw_mode|gw	[off|client|server]\fP"
-If no parameter is given the current gateway mode is displayed otherwise the parameter is used to set the gateway mode.
+.IP "\fBaggregation\fP|\fBag\fP   [\fB1\fP|\fB0\fP]"
+If no parameter is given the current aggregation setting is displayed. Otherwise the parameter is used to enable or disable packet aggregation.
 .br
-.IP "\fBgw_srv_list|gwl\fP"
-Once started batctl will refresh the displayed gateway server list every second. Use the "\-b" option to let batctl display the list only once (useful for scripts). If "\-n" was given batctl will not replace the mac addresses with bat\-host names in the output.
+.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 "\fBaggregation\fP|\fBag\fP [\fB1\fP|\fB0\fP]"
-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][\fB\-R\fP] \fIMAC_address\fP|\fIbat\-host_name\fP"
+.IP "\fBping\fP|\fBp\fP           [\fB\-c count\fP][\fB\-i interval\fP][\fB\-t time\fP][\fB\-R\fP] \fBMAC_address\fP|\fBbat\-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
 address. The "\-c" option tells batctl how man pings should be sent
@@ -140,14 +156,14 @@ you can set the default interval between pings and the timeout time
 for replies, both in seconds. When run with "\-R", the route taken by
 the ping messages will be recorded.
 .br
-.IP "\fBtraceroute\fP|\fBtr\fP  [\fB\-n\fP] \fIMAC_address\fP|\fIbat\-host_name\fP"
+.IP "\fBtraceroute\fP|\fBtr\fP    [\fB\-n\fP] \fBMAC_address\fP|\fBbat\-host_name\fP"
 Layer 2 traceroute to a MAC address or bat\-host name. batctl will try
 to find the bat\-host name if the given parameter was not a MAC
 address. batctl will send 3 packets to each host and display the
 response time. If "\-n" is given batctl will not replace the MAC
 addresses with bat\-host names in the output.
 .br
-.IP "\fBtcpdump\fP|\fBtd\fP     [\fB\-p \fP\fIfilter\fP][\fB\-n\fP] \fIinterface ...\fP"
+.IP "\fBtcpdump\fP|\fBtd\fP       [\fB\-p filter\fP][\fB\-n\fP] \fBinterface ...\fP"
 batctl will display all packets that are seen on the given
 interface(s). The "\-p" options allows the filtering of certain packet
 types: 1 - batman ogm packets, 2 - batman icmp packets, 4 - unicast
@@ -157,7 +173,7 @@ type, e.g. use "\-p 3" to display batman ogm packets and batman icmp
 packets only. If "\-n" is given batctl will not replace the MAC
 addresses with bat\-host names in the output.
 .br
-.IP "\fBbisect\fP               [\fB\-l \fP\fIMAC\fP][\fB\-t \fP\fIMAC\fP][\fB\-r \fP\fIMAC\fP][\fB\-s \fP\fImin\fP [\fB\- \fP\fImax\fP]][\fB\-o \fP\fIMAC\fP][\fB\-n\fP] \fIlogfile1\fP [\fIlogfile2\fP ... \fIlogfileN\fP]"
+.IP "\fBbisect\fP           [\fB\-l MAC\fP][\fB\-t MAC\fP][\fB\-r MAC\fP][\fB\-s min\fP [\fB\- max\fP]][\fB\-o MAC\fP][\fB\-n\fP] \fBlogfile1\fP [\fBlogfile2\fP ... \fBlogfileN\fP]"
 Analyses the logfiles to build a small internal database of all sent
 sequence numbers and routing table changes. This database can then be
 analyzed in a number of different ways. With "\-l" the database can be
Signature · 1 line
1.7.0