Converting from /dev to debugfs
Hi,
we had decided that different files must move from sysfs to debugfs in recent discussion with gregkh. But their was also the problem that we currently use /dev/batman-adv to send special batman-adv "icmp" packets to the mesh. This file is maybe a problem when we want to support different batX interfaces on a single machine.
So we have the problem that we want to move different files to debugfs and get support for it in batctl. It seemed to be easier (better readable) for me to first start to get a single file to debugfs and then build on top of the created infrastructure in batctl/batman-adv-kernelland to move more files. My choice was /dev/batman-adv as we had some open question how good it works with debugfs.
Unfortunately I am not able to continue it today, but don't want to stop other people working on similar things. I will attach v0 (aka works for me, but maybe not perfect/good enough) versions of these patches to support them. Please feel free to discuss the patches.
Best regards,
Sven
PATCH 1/2 batman-adv: Move device for icmp injection to debugfs
batctl uses /dev/batman-adv to send special batman-adv icmp packets to other nodes in the mesh. To get it working with multiple batX devices we must ensure that every mesh device can have their own socket which is used to inject those packets in exactly one mesh.
The current implementation still doesn't allow to use complete separated meshes as we rely on structures which are not part of the private data of a batman device.
--- batman-adv-kernelland/Makefile.kbuild | 2 +- batman-adv-kernelland/bat_debugfs.c | 76 +++++++ batman-adv-kernelland/bat_debugfs.h | 33 +++ batman-adv-kernelland/device.c | 363 --------------------------------- batman-adv-kernelland/device.h | 38 ---- batman-adv-kernelland/icmp_socket.c | 337 ++++++++++++++++++++++++++++++ batman-adv-kernelland/icmp_socket.h | 29 +++ batman-adv-kernelland/main.c | 21 ++- batman-adv-kernelland/routing.c | 4 +- batman-adv-kernelland/types.h | 5 +- 10 files changed, 495 insertions(+), 413 deletions(-) create mode 100644 batman-adv-kernelland/bat_debugfs.c create mode 100644 batman-adv-kernelland/bat_debugfs.h delete mode 100644 batman-adv-kernelland/device.c delete mode 100644 batman-adv-kernelland/device.h create mode 100644 batman-adv-kernelland/icmp_socket.c create mode 100644 batman-adv-kernelland/icmp_socket.h
batman-adv-kernelland/Makefile.kbuild +1 -1
@@ -32,4 +32,4 @@ EXTRA_CFLAGS += -DREVISION_VERSION=\"r$(REVISION)\" endif obj-m += batman-adv.o -batman-adv-objs := main.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-objs := main.o bat_debugfs.o bat_sysfs.o send.o routing.o soft-interface.o icmp_socket.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/bat_debugfs.c new file +76 -0
76 lines not on this page · raw message
batman-adv-kernelland/bat_debugfs.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* 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 +* +*/ + + +#ifndef BAT_DEBUGFS_H +#define BAT_DEBUGFS_H + +#define DEBUGFS_BAT_SUBDIR "batman_adv" + +void debugfs_init (void ); +void debugfs_destroy (void ); +int debugfs_add_meshif (struct net_device *dev); +void debugfs_del_meshif (struct net_device *dev); + +#endif
batman-adv-kernelland/device.c deleted +0 -363
363 lines not on this page · raw message
batman-adv-kernelland/device.h deleted +0 -38
@@ -1,38 +0,0 @@ -/* -* Copyright (C) 2007-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 -* -*/ - -#include "types.h" - -void bat_device_init (void ); -int bat_device_setup (void ); -void bat_device_destroy (void ); -int bat_device_open (struct inode *inode,struct file *file); -int bat_device_release (struct inode *inode,struct file *file); -ssize_t bat_device_read (struct file *file,char __user *buf,size_t count, -loff_t *ppos); -ssize_t bat_device_write (struct file *file,const char __user *buff, -size_t len,loff_t *off); -unsigned int bat_device_poll (struct file *file,poll_table *wait); -void bat_device_add_packet (struct device_client *device_client, -struct icmp_packet_rr *icmp_packet, -size_t icmp_len); -void bat_device_receive_packet (struct icmp_packet_rr *icmp_packet, -size_t icmp_len);
batman-adv-kernelland/icmp_socket.c new file +337 -0
337 lines not on this page · raw message
batman-adv-kernelland/icmp_socket.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (C) 2007-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 +* +*/ + +#include "types.h" + +#define ICMP_SOCKET "socket" + +void bat_socket_init (void ); +int bat_socket_setup (struct bat_priv *bat_priv); +void bat_socket_receive_packet (struct icmp_packet_rr *icmp_packet, +size_t icmp_len);
batman-adv-kernelland/main.c +14 -7
@@ -21,11 +21,12 @@#include "main.h" #include "bat_sysfs.h" +#include "bat_debugfs.h" #include "routing.h" #include "send.h" #include "originator.h" #include "soft-interface.h" -#include "device.h" +#include "icmp_socket.h" #include "translation-table.h" #include "hard-interface.h" #include "gateway_client.h"
@@ -85,7 +86,8 @@ int init_module(void)if (!bat_event_workqueue)return -ENOMEM ; -bat_device_init (); +bat_socket_init (); +debugfs_init ();/* initialize layer 2 interface */ soft_device = alloc_netdev(sizeof(struct bat_priv) , "bat%d",
@@ -110,6 +112,11 @@ int init_module(void)if (retval <0 ) goto unreg_soft_device; + retval =debugfs_add_meshif (soft_device); + +if (retval <0 ) + goto unreg_sysfs; +register_netdevice_notifier (&hard_if_notifier);dev_add_pack (&batman_adv_packet_type);
@@ -119,6 +126,8 @@ int init_module(void)return 0 ; +unreg_sysfs: +sysfs_del_meshif (soft_device); unreg_soft_device:unregister_netdevice (soft_device); free_soft_device:
@@ -136,6 +145,7 @@ void cleanup_module(void)hardif_remove_interfaces ();if (soft_device) { +debugfs_del_meshif (soft_device);sysfs_del_meshif (soft_device);unregister_netdev (soft_device); soft_device =NULL ;
@@ -147,7 +157,7 @@ void cleanup_module(void) bat_event_workqueue =NULL ; } -/* activates the module, creates bat device, starts timer ... */ +/* activates the module, starts timer ... */ void activate_module (void ) {if (originator_init () <1 )
@@ -161,9 +171,6 @@ void activate_module(void)hna_local_add (soft_device->dev_addr); -if (bat_device_setup () <1 ) - goto end; -if (vis_init () <1 ) goto err;
@@ -199,7 +206,7 @@ void deactivate_module(void)hna_global_free ();synchronize_net (); -bat_device_destroy (); +debugfs_destroy ();synchronize_rcu ();atomic_set (&module_state,MODULE_INACTIVE );
batman-adv-kernelland/routing.c +2 -2
@@ -25,7 +25,7 @@#include "hash.h" #include "soft-interface.h" #include "hard-interface.h" -#include "device.h" +#include "icmp_socket.h" #include "translation-table.h" #include "originator.h" #include "types.h"
@@ -801,7 +801,7 @@ static int recv_my_icmp_packet(struct sk_buff *skb, size_t icmp_len)/* add data to device queue */ if (icmp_packet->msg_type !=ECHO_REQUEST ) { -bat_device_receive_packet (icmp_packet, icmp_len); +bat_socket_receive_packet (icmp_packet, icmp_len);return NET_RX_DROP ; }
batman-adv-kernelland/types.h +3 -2
@@ -129,9 +129,10 @@ struct bat_priv {char num_ifaces;struct batman_if *primary_if;struct kobject *mesh_obj; +struct dentry *debug_dir; }; -struct device_client { +struct socket_client {struct list_head queue_list;unsigned int queue_len;unsigned char index;
@@ -139,7 +140,7 @@ struct device_client {wait_queue_head_t queue_wait; }; -struct device_packet { +struct socket_packet {struct list_head list;size_t icmp_len;struct icmp_packet_rr icmp_packet;
Signature · 1 line
1.7.1
PATCH 2/2 batctl: Use socket in debugfs instead of batman-adv device
In reply to Sven EckelmannThe batman-adv device which was only usable for a single batX net device was replaced with a file in debugfs which can be used the same way as /dev/batman-adv before.
It seems that the debugfs has no 100% common mount path in current distributions and maybe isn't mounted at all. So before we try to access a batman file in debugfs, we have to search for the mountpoint in /proc/mounts and maybe mount it manually in /sys/kernel/debug.
--- batctl/Makefile | 4 +- batctl/debugfs.c | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++ batctl/debugfs.h | 46 +++++++++ batctl/main.h | 2 +- batctl/ping.c | 21 +++- batctl/traceroute.c | 21 +++- 6 files changed, 350 insertions(+), 13 deletions(-) create mode 100644 batctl/debugfs.c create mode 100644 batctl/debugfs.h
batctl/Makefile +2 -2
@@ -39,8 +39,8 @@ SRC_FILES = "\(\.c\)\|\(\.h\)\|\(Makefile\)\|\(INSTALL\)\|\(LIESMICH\)\|\(README EXTRA_MODULES_C := bisect.c EXTRA_MODULES_H := bisect.h -SRC_C = main.c bat-hosts.c functions.c sys.c ping.c traceroute.c tcpdump.c list-batman.c hash.c vis.c $(EXTRA_MODULES_C) -SRC_H = main.h bat-hosts.h functions.h sys.h ping.h traceroute.h tcpdump.h list-batman.h hash.h allocate.h vis.h $(EXTRA_MODULES_H) +SRC_C = main.c bat-hosts.c functions.c sys.c ping.c traceroute.c tcpdump.c list-batman.c hash.c vis.c debugfs.c $(EXTRA_MODULES_C) +SRC_H = main.h bat-hosts.h functions.h sys.h ping.h traceroute.h tcpdump.h list-batman.h hash.h allocate.h vis.h debugfs.h $(EXTRA_MODULES_H) SRC_O = $(SRC_C:.c=.o) PACKAGE_NAME = batctl
batctl/debugfs.c new file +269 -0
269 lines not on this page · raw message
batctl/debugfs.h new file +46 -0
46 lines not on this page · raw message
batctl/main.h +1 -1
@@ -23,4 +23,4 @@#define SOURCE_VERSION "0.3.0-alpha"/*put exactly one distinct word inside the string like "0.3-pre-alpha" or "0.3-rc1" or "0.3" */ -#define BAT_DEVICE "/dev/batman-adv" +#define SOCKET_PATH "batman_adv/bat0/socket"
batctl/ping.c +16 -5
@@ -35,6 +35,7 @@#include "functions.h" #include "packet.h" #include "bat-hosts.h" +#include "debugfs.h" char is_aborted =0 ;
@@ -79,6 +80,8 @@ int ping(int argc, char **argv)float min =0.0 , max =0.0 , avg =0.0 ;uint8_t last_rr_cur =0 , last_rr[BAT_RR_LEN ][ETH_ALEN ];size_t packet_len; +char *debugfs_mnt; +char icmp_socket[MAX_PATH +1 ];while ((optchar =getopt (argc, argv,"hc:i:t:R" )) !=-1 ) {switch (optchar) {
@@ -139,11 +142,19 @@ int ping(int argc, char **argv)signal (SIGINT , sig_handler);signal (SIGTERM , sig_handler); - ping_fd =open (BAT_DEVICE ,O_RDWR ); + debugfs_mnt =debugfs_mount (NULL ); +if (!debugfs_mnt) { +printf ("Error - can't mount or find debugfs\n" ); + goto out; + } + +debugfs_make_path (SOCKET_PATH , icmp_socket,sizeof (icmp_socket)); + + ping_fd =open (icmp_socket,O_RDWR );if (ping_fd <0 ) { -printf ("Error - can't open a connection to the batman adv kernel module via the device '%s': %s\n" , -BAT_DEVICE ,strerror (errno)); +printf ("Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n" , + icmp_socket,strerror (errno));printf ("Check whether the module is loaded and active.\n" ); goto out; }
@@ -177,7 +188,7 @@ int ping(int argc, char **argv) icmp_packet_out.seqno =htons (++seq_counter);if (write (ping_fd, (char *)&icmp_packet_out, packet_len) <0 ) { -printf ("Error - can't write to batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't write to batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno)); goto sleep; }
@@ -207,7 +218,7 @@ int ping(int argc, char **argv) read_len =read (ping_fd, (char *)&icmp_packet_in, packet_len);if (read_len <0 ) { -printf ("Error - can't read from batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't read from batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno)); goto sleep; }
batctl/traceroute.c +16 -5
@@ -34,6 +34,7 @@#include "functions.h" #include "packet.h" #include "bat-hosts.h" +#include "debugfs.h" #define TTL_MAX 50
@@ -59,6 +60,8 @@ int traceroute(int argc, char **argv)int ret =EXIT_FAILURE , res, trace_fd =0 , i;int found_args =1 , optchar, seq_counter =0 , read_opt =USE_BAT_HOSTS ;double time_delta; +char *debugfs_mnt; +char icmp_socket[MAX_PATH +1 ];while ((optchar =getopt (argc, argv,"hn" )) !=-1 ) {switch (optchar) {
@@ -99,11 +102,19 @@ int traceroute(int argc, char **argv) mac_string =ether_ntoa_long (dst_mac); - trace_fd =open (BAT_DEVICE ,O_RDWR ); + debugfs_mnt =debugfs_mount (NULL ); +if (!debugfs_mnt) { +printf ("Error - can't mount or find debugfs\n" ); + goto out; + } + +debugfs_make_path (SOCKET_PATH , icmp_socket,sizeof (icmp_socket)); + + trace_fd =open (icmp_socket,O_RDWR );if (trace_fd <0 ) { -printf ("Error - can't open a connection to the batman adv kernel module via the device '%s': %s\n" , -BAT_DEVICE ,strerror (errno)); +printf ("Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n" , + icmp_socket,strerror (errno));printf ("Check whether the module is loaded and active.\n" ); goto out; }
@@ -123,7 +134,7 @@ int traceroute(int argc, char **argv) icmp_packet_out.seqno =htons (++seq_counter);if (write (trace_fd, (char *)&icmp_packet_out,sizeof (icmp_packet_out)) <0 ) { -printf ("Error - can't write to batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't write to batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno));continue ; }
@@ -149,7 +160,7 @@ int traceroute(int argc, char **argv) read_len =read (trace_fd, (char *)&icmp_packet_in,sizeof (icmp_packet_in));if (read_len <0 ) { -printf ("Error - can't read from batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't read from batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno));continue ; }
Signature · 1 line
1.7.1
Quoted 4 lines · Sven Eckelmann
Unfortunately I am not able to continue it today, but don't want to stop other people working on similar things. I will attach v0 (aka works for me, but maybe not perfect/good enough) versions of these patches to support them. Please feel free to discuss the patches.
I converted the remaining files from sysfs to debugfs, but I noticed that there is a problem with the output functions (see "BUG" comments in patch 3). The problem is that we may sleep during the prints in the output functions, but we disabled interrupts.... which is bad. This problem was also their before we converted from /proc to /sys. It seems that it was first introduced in r1517. The old way for hna_global_fill_buffer_text hna_local_fill_buffer_text solved it, but restricted the output to 4096 bytes. So we could either stay with a "slow" and maybe inconsistent output or restricted output length or copy the data to a local buffer and then creating the output without spinlock or something completely different.
The patches are for trunk, but I would provide backported versions when the patches are discussed and we could solve the problem in a sane way.
Best regards,
Sven
PATCH 1/4 batman-adv: Move device for icmp injection to debugfs
batctl uses /dev/batman-adv to send special batman-adv icmp packets to other nodes in the mesh. To get it working with multiple batX devices we must ensure that every mesh device can have their own socket which is used to inject those packets in exactly one mesh.
The current implementation still doesn't allow to use complete separated meshes as we rely on structures which are not part of the private data of a batman device.
--- batman-adv-kernelland/Makefile.kbuild | 2 +- batman-adv-kernelland/bat_debugfs.c | 76 +++++++ batman-adv-kernelland/bat_debugfs.h | 33 +++ batman-adv-kernelland/compat.h | 65 +++++- batman-adv-kernelland/device.c | 363 --------------------------------- batman-adv-kernelland/device.h | 38 ---- batman-adv-kernelland/icmp_socket.c | 338 ++++++++++++++++++++++++++++++ batman-adv-kernelland/icmp_socket.h | 29 +++ batman-adv-kernelland/main.c | 21 ++- batman-adv-kernelland/routing.c | 4 +- batman-adv-kernelland/types.h | 5 +- 11 files changed, 551 insertions(+), 423 deletions(-) create mode 100644 batman-adv-kernelland/bat_debugfs.c create mode 100644 batman-adv-kernelland/bat_debugfs.h delete mode 100644 batman-adv-kernelland/device.c delete mode 100644 batman-adv-kernelland/device.h create mode 100644 batman-adv-kernelland/icmp_socket.c create mode 100644 batman-adv-kernelland/icmp_socket.h
batman-adv-kernelland/Makefile.kbuild +1 -1
@@ -32,4 +32,4 @@ EXTRA_CFLAGS += -DREVISION_VERSION=\"r$(REVISION)\" endif obj-m += batman-adv.o -batman-adv-objs := main.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-objs := main.o bat_debugfs.o bat_sysfs.o send.o routing.o soft-interface.o icmp_socket.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/bat_debugfs.c new file +76 -0
76 lines not on this page · raw message
batman-adv-kernelland/bat_debugfs.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* 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 +* +*/ + + +#ifndef BAT_DEBUGFS_H +#define BAT_DEBUGFS_H + +#define DEBUGFS_BAT_SUBDIR "batman_adv" + +void debugfs_init (void ); +void debugfs_destroy (void ); +int debugfs_add_meshif (struct net_device *dev); +void debugfs_del_meshif (struct net_device *dev); + +#endif
batman-adv-kernelland/compat.h +55 -10
77 lines not on this page · raw message
batman-adv-kernelland/device.c deleted +0 -363
363 lines not on this page · raw message
batman-adv-kernelland/device.h deleted +0 -38
@@ -1,38 +0,0 @@ -/* -* Copyright (C) 2007-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 -* -*/ - -#include "types.h" - -void bat_device_init (void ); -int bat_device_setup (void ); -void bat_device_destroy (void ); -int bat_device_open (struct inode *inode,struct file *file); -int bat_device_release (struct inode *inode,struct file *file); -ssize_t bat_device_read (struct file *file,char __user *buf,size_t count, -loff_t *ppos); -ssize_t bat_device_write (struct file *file,const char __user *buff, -size_t len,loff_t *off); -unsigned int bat_device_poll (struct file *file,poll_table *wait); -void bat_device_add_packet (struct device_client *device_client, -struct icmp_packet_rr *icmp_packet, -size_t icmp_len); -void bat_device_receive_packet (struct icmp_packet_rr *icmp_packet, -size_t icmp_len);
batman-adv-kernelland/icmp_socket.c new file +338 -0
338 lines not on this page · raw message
batman-adv-kernelland/icmp_socket.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (C) 2007-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 +* +*/ + +#include "types.h" + +#define ICMP_SOCKET "socket" + +void bat_socket_init (void ); +int bat_socket_setup (struct bat_priv *bat_priv); +void bat_socket_receive_packet (struct icmp_packet_rr *icmp_packet, +size_t icmp_len);
batman-adv-kernelland/main.c +14 -7
@@ -21,11 +21,12 @@#include "main.h" #include "bat_sysfs.h" +#include "bat_debugfs.h" #include "routing.h" #include "send.h" #include "originator.h" #include "soft-interface.h" -#include "device.h" +#include "icmp_socket.h" #include "translation-table.h" #include "hard-interface.h" #include "gateway_client.h"
@@ -85,7 +86,8 @@ int init_module(void)if (!bat_event_workqueue)return -ENOMEM ; -bat_device_init (); +bat_socket_init (); +debugfs_init ();/* initialize layer 2 interface */ soft_device = alloc_netdev(sizeof(struct bat_priv) , "bat%d",
@@ -110,6 +112,11 @@ int init_module(void)if (retval <0 ) goto unreg_soft_device; + retval =debugfs_add_meshif (soft_device); + +if (retval <0 ) + goto unreg_sysfs; +register_netdevice_notifier (&hard_if_notifier);dev_add_pack (&batman_adv_packet_type);
@@ -119,6 +126,8 @@ int init_module(void)return 0 ; +unreg_sysfs: +sysfs_del_meshif (soft_device); unreg_soft_device:unregister_netdevice (soft_device); free_soft_device:
@@ -136,6 +145,7 @@ void cleanup_module(void)hardif_remove_interfaces ();if (soft_device) { +debugfs_del_meshif (soft_device);sysfs_del_meshif (soft_device);unregister_netdev (soft_device); soft_device =NULL ;
@@ -147,7 +157,7 @@ void cleanup_module(void) bat_event_workqueue =NULL ; } -/* activates the module, creates bat device, starts timer ... */ +/* activates the module, starts timer ... */ void activate_module (void ) {if (originator_init () <1 )
@@ -161,9 +171,6 @@ void activate_module(void)hna_local_add (soft_device->dev_addr); -if (bat_device_setup () <1 ) - goto end; -if (vis_init () <1 ) goto err;
@@ -199,7 +206,7 @@ void deactivate_module(void)hna_global_free ();synchronize_net (); -bat_device_destroy (); +debugfs_destroy ();synchronize_rcu ();atomic_set (&module_state,MODULE_INACTIVE );
batman-adv-kernelland/routing.c +2 -2
@@ -25,7 +25,7 @@#include "hash.h" #include "soft-interface.h" #include "hard-interface.h" -#include "device.h" +#include "icmp_socket.h" #include "translation-table.h" #include "originator.h" #include "types.h"
@@ -801,7 +801,7 @@ static int recv_my_icmp_packet(struct sk_buff *skb, size_t icmp_len)/* add data to device queue */ if (icmp_packet->msg_type !=ECHO_REQUEST ) { -bat_device_receive_packet (icmp_packet, icmp_len); +bat_socket_receive_packet (icmp_packet, icmp_len);return NET_RX_DROP ; }
batman-adv-kernelland/types.h +3 -2
@@ -129,9 +129,10 @@ struct bat_priv {char num_ifaces;struct batman_if *primary_if;struct kobject *mesh_obj; +struct dentry *debug_dir; }; -struct device_client { +struct socket_client {struct list_head queue_list;unsigned int queue_len;unsigned char index;
@@ -139,7 +140,7 @@ struct device_client {wait_queue_head_t queue_wait; }; -struct device_packet { +struct socket_packet {struct list_head list;size_t icmp_len;struct icmp_packet_rr icmp_packet;
Signature · 1 line
1.7.1
PATCH 2/4 batctl: Use socket in debugfs instead of batman-adv device
In reply to Sven EckelmannThe batman-adv device which was only usable for a single batX net device was replaced with a file in debugfs which can be used the same way as /dev/batman-adv before.
It seems that the debugfs has no 100% common mount path in current distributions and maybe isn't mounted at all. So before we try to access a batman file in debugfs, we have to search for the mountpoint in /proc/mounts and maybe mount it manually in /sys/kernel/debug.
--- batctl/Makefile | 4 +- batctl/debugfs.c | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++ batctl/debugfs.h | 46 +++++++++ batctl/main.h | 2 +- batctl/ping.c | 21 +++- batctl/traceroute.c | 21 +++- 6 files changed, 350 insertions(+), 13 deletions(-) create mode 100644 batctl/debugfs.c create mode 100644 batctl/debugfs.h
batctl/Makefile +2 -2
@@ -39,8 +39,8 @@ SRC_FILES = "\(\.c\)\|\(\.h\)\|\(Makefile\)\|\(INSTALL\)\|\(LIESMICH\)\|\(README EXTRA_MODULES_C := bisect.c EXTRA_MODULES_H := bisect.h -SRC_C = main.c bat-hosts.c functions.c sys.c ping.c traceroute.c tcpdump.c list-batman.c hash.c vis.c $(EXTRA_MODULES_C) -SRC_H = main.h bat-hosts.h functions.h sys.h ping.h traceroute.h tcpdump.h list-batman.h hash.h allocate.h vis.h $(EXTRA_MODULES_H) +SRC_C = main.c bat-hosts.c functions.c sys.c ping.c traceroute.c tcpdump.c list-batman.c hash.c vis.c debugfs.c $(EXTRA_MODULES_C) +SRC_H = main.h bat-hosts.h functions.h sys.h ping.h traceroute.h tcpdump.h list-batman.h hash.h allocate.h vis.h debugfs.h $(EXTRA_MODULES_H) SRC_O = $(SRC_C:.c=.o) PACKAGE_NAME = batctl
batctl/debugfs.c new file +269 -0
269 lines not on this page · raw message
batctl/debugfs.h new file +46 -0
46 lines not on this page · raw message
batctl/main.h +1 -1
@@ -23,4 +23,4 @@#define SOURCE_VERSION "0.3.0-alpha"/*put exactly one distinct word inside the string like "0.3-pre-alpha" or "0.3-rc1" or "0.3" */ -#define BAT_DEVICE "/dev/batman-adv" +#define SOCKET_PATH "batman_adv/bat0/socket"
batctl/ping.c +16 -5
@@ -35,6 +35,7 @@#include "functions.h" #include "packet.h" #include "bat-hosts.h" +#include "debugfs.h" char is_aborted =0 ;
@@ -79,6 +80,8 @@ int ping(int argc, char **argv)float min =0.0 , max =0.0 , avg =0.0 ;uint8_t last_rr_cur =0 , last_rr[BAT_RR_LEN ][ETH_ALEN ];size_t packet_len; +char *debugfs_mnt; +char icmp_socket[MAX_PATH +1 ];while ((optchar =getopt (argc, argv,"hc:i:t:R" )) !=-1 ) {switch (optchar) {
@@ -139,11 +142,19 @@ int ping(int argc, char **argv)signal (SIGINT , sig_handler);signal (SIGTERM , sig_handler); - ping_fd =open (BAT_DEVICE ,O_RDWR ); + debugfs_mnt =debugfs_mount (NULL ); +if (!debugfs_mnt) { +printf ("Error - can't mount or find debugfs\n" ); + goto out; + } + +debugfs_make_path (SOCKET_PATH , icmp_socket,sizeof (icmp_socket)); + + ping_fd =open (icmp_socket,O_RDWR );if (ping_fd <0 ) { -printf ("Error - can't open a connection to the batman adv kernel module via the device '%s': %s\n" , -BAT_DEVICE ,strerror (errno)); +printf ("Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n" , + icmp_socket,strerror (errno));printf ("Check whether the module is loaded and active.\n" ); goto out; }
@@ -177,7 +188,7 @@ int ping(int argc, char **argv) icmp_packet_out.seqno =htons (++seq_counter);if (write (ping_fd, (char *)&icmp_packet_out, packet_len) <0 ) { -printf ("Error - can't write to batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't write to batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno)); goto sleep; }
@@ -207,7 +218,7 @@ int ping(int argc, char **argv) read_len =read (ping_fd, (char *)&icmp_packet_in, packet_len);if (read_len <0 ) { -printf ("Error - can't read from batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't read from batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno)); goto sleep; }
batctl/traceroute.c +16 -5
@@ -34,6 +34,7 @@#include "functions.h" #include "packet.h" #include "bat-hosts.h" +#include "debugfs.h" #define TTL_MAX 50
@@ -59,6 +60,8 @@ int traceroute(int argc, char **argv)int ret =EXIT_FAILURE , res, trace_fd =0 , i;int found_args =1 , optchar, seq_counter =0 , read_opt =USE_BAT_HOSTS ;double time_delta; +char *debugfs_mnt; +char icmp_socket[MAX_PATH +1 ];while ((optchar =getopt (argc, argv,"hn" )) !=-1 ) {switch (optchar) {
@@ -99,11 +102,19 @@ int traceroute(int argc, char **argv) mac_string =ether_ntoa_long (dst_mac); - trace_fd =open (BAT_DEVICE ,O_RDWR ); + debugfs_mnt =debugfs_mount (NULL ); +if (!debugfs_mnt) { +printf ("Error - can't mount or find debugfs\n" ); + goto out; + } + +debugfs_make_path (SOCKET_PATH , icmp_socket,sizeof (icmp_socket)); + + trace_fd =open (icmp_socket,O_RDWR );if (trace_fd <0 ) { -printf ("Error - can't open a connection to the batman adv kernel module via the device '%s': %s\n" , -BAT_DEVICE ,strerror (errno)); +printf ("Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n" , + icmp_socket,strerror (errno));printf ("Check whether the module is loaded and active.\n" ); goto out; }
@@ -123,7 +134,7 @@ int traceroute(int argc, char **argv) icmp_packet_out.seqno =htons (++seq_counter);if (write (trace_fd, (char *)&icmp_packet_out,sizeof (icmp_packet_out)) <0 ) { -printf ("Error - can't write to batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't write to batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno));continue ; }
@@ -149,7 +160,7 @@ int traceroute(int argc, char **argv) read_len =read (trace_fd, (char *)&icmp_packet_in,sizeof (icmp_packet_in));if (read_len <0 ) { -printf ("Error - can't read from batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't read from batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno));continue ; }
Signature · 1 line
1.7.1
PATCH 3/4 batman-adv: Move tables from sysfs to debugfs
In reply to Sven EckelmannFiles which represent more than a single attribute aren't allowed in sysfs. As we have some files which aren't essential and are lists or tables aggregated from data from different places inside batman-adv, we must place them in a filesystem without such a restriction.
--- batman-adv-kernelland/bat_debugfs.c | 79 ++++++++++++++++++++ batman-adv-kernelland/bat_sysfs.c | 91 ----------------------- batman-adv-kernelland/gateway_client.c | 64 +++++----------- batman-adv-kernelland/gateway_client.h | 3 +- batman-adv-kernelland/main.h | 1 + batman-adv-kernelland/originator.c | 61 +++++----------- batman-adv-kernelland/originator.h | 3 +- batman-adv-kernelland/translation-table.c | 114 ++++++++++------------------- batman-adv-kernelland/translation-table.h | 6 +- batman-adv-kernelland/vis.c | 59 +++++---------- batman-adv-kernelland/vis.h | 3 +- 11 files changed, 181 insertions(+), 303 deletions(-)
batman-adv-kernelland/bat_debugfs.c +79 -0
@@ -34,6 +34,68 @@static struct dentry *bat_debugfs; +static int originators_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, orig_seq_print_text, net_dev); +} + +static int gateways_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, gw_client_seq_print_text, net_dev); +} + +static int transtable_global_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, hna_global_seq_print_text, net_dev); +} + +static int transtable_local_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, hna_local_seq_print_text, net_dev); +} + +static int vis_data_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, vis_seq_print_text, net_dev); +} + +struct bat_debuginfo { +struct attribute attr; +const struct file_operations fops; +}; + +#define BAT_DEBUGINFO (_name, _mode, _open) \ +struct bat_debuginfo bat_debuginfo_##_name = { \ + .attr = { .name = __stringify(_name), \ + .mode = _mode, }, \ + .fops = { .owner = THIS_MODULE, \ + .open = _open, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = single_release, \ + } \ +}; + +static BAT_DEBUGINFO(originators, S_IRUGO, originators_open); +static BAT_DEBUGINFO(gateways, S_IRUGO, gateways_open); +static BAT_DEBUGINFO(transtable_global, S_IRUGO, transtable_global_open); +static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open); +static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open); + +static struct bat_debuginfo *mesh_debuginfos[] = { + &bat_debuginfo_originators, + &bat_debuginfo_gateways, + &bat_debuginfo_transtable_global, + &bat_debuginfo_transtable_local, + &bat_debuginfo_vis_data, +NULL , +}; +void debugfs_init (void ) { bat_debugfs =debugfs_create_dir (DEBUGFS_BAT_SUBDIR ,NULL );
@@ -50,6 +112,8 @@ void debugfs_destroy(void)int debugfs_add_meshif (struct net_device *dev) {struct bat_priv *bat_priv =netdev_priv (dev); +struct bat_debuginfo **bat_debug; +struct dentry *file;if (!bat_debugfs) goto out;
@@ -60,7 +124,22 @@ int debugfs_add_meshif(struct net_device *dev)bat_socket_setup (bat_priv); +for (bat_debug = mesh_debuginfos; *bat_debug; ++bat_debug) { + file =debugfs_create_file (((*bat_debug)->attr).name, +S_IFREG | ((*bat_debug)->attr).mode, + bat_priv->debug_dir, + dev, &(*bat_debug)->fops); +if (!file) { +printk (KERN_ERR "batman-adv:Can't add debugfs file: " +"%s/%s\n" , dev->name, ((*bat_debug)->attr).name); + goto rem_attr; + } + } +return 0 ; +rem_attr: +debugfs_remove_recursive (bat_priv->debug_dir); + bat_priv->debug_dir =NULL ; out:return -ENOMEM ; }
batman-adv-kernelland/bat_sysfs.c +0 -91
122 lines not on this page · raw message
batman-adv-kernelland/gateway_client.c +19 -45
112 lines not on this page · raw message
batman-adv-kernelland/gateway_client.h +1 -2
@@ -27,6 +27,5 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int gw_client_seq_print_text (struct seq_file *seq,void *offset);bool gw_is_target (struct bat_priv *bat_priv,struct sk_buff *skb);
batman-adv-kernelland/main.h +1 -0
@@ -123,6 +123,7 @@ extern int bat_debug_type(int type);#include <linux/workqueue.h> /* workqueue */ #include <net/sock.h> /* struct sock */ #include <linux/jiffies.h> +#include <linux/seq_file.h> #include "types.h" #ifndef REVISION_VERSION
batman-adv-kernelland/originator.c +18 -43
109 lines not on this page · raw message
batman-adv-kernelland/originator.h +1 -2
@@ -28,7 +28,6 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int orig_seq_print_text (struct seq_file *seq,void *offset);int orig_hash_add_if (struct batman_if *batman_if,int max_if_num);int orig_hash_del_if (struct batman_if *batman_if,int max_if_num);
batman-adv-kernelland/translation-table.c +39 -75
162 lines not on this page · raw message
batman-adv-kernelland/translation-table.h +2 -4
@@ -25,15 +25,13 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int hna_local_seq_print_text (struct seq_file *seq,void *offset);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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int hna_global_seq_print_text (struct seq_file *seq,void *offset);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/vis.c +20 -39
127 lines not on this page · raw message
batman-adv-kernelland/vis.h +1 -2
@@ -47,8 +47,7 @@ struct recvlist_node {extern struct hashtable_t *vis_hash;extern spinlock_t vis_hash_lock; -ssize_t vis_fill_buffer_text (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +ssize_t vis_seq_print_text (struct seq_file *seq,void *offset);void receive_server_sync_packet (struct bat_priv *bat_priv,struct vis_packet *vis_packet,int vis_info_len);
Signature · 1 line
1.7.1
PATCH v2 3/4 batman-adv: Move tables from sysfs to debugfs
Files which represent more than a single attribute aren't allowed in sysfs. As we have some files which aren't essential and are lists or tables aggregated from data from different places inside batman-adv, we must place them in a filesystem without such a restriction.
---
Just fixed a return type which created a compiler warning.
batman-adv-kernelland/bat_debugfs.c | 79 ++++++++++++++++++++ batman-adv-kernelland/bat_sysfs.c | 91 ----------------------- batman-adv-kernelland/gateway_client.c | 64 +++++----------- batman-adv-kernelland/gateway_client.h | 3 +- batman-adv-kernelland/main.h | 1 + batman-adv-kernelland/originator.c | 61 +++++----------- batman-adv-kernelland/originator.h | 3 +- batman-adv-kernelland/translation-table.c | 114 ++++++++++------------------- batman-adv-kernelland/translation-table.h | 6 +- batman-adv-kernelland/vis.c | 59 +++++---------- batman-adv-kernelland/vis.h | 3 +- 11 files changed, 181 insertions(+), 303 deletions(-)
batman-adv-kernelland/bat_debugfs.c +79 -0
@@ -34,6 +34,68 @@static struct dentry *bat_debugfs; +static int originators_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, orig_seq_print_text, net_dev); +} + +static int gateways_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, gw_client_seq_print_text, net_dev); +} + +static int transtable_global_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, hna_global_seq_print_text, net_dev); +} + +static int transtable_local_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, hna_local_seq_print_text, net_dev); +} + +static int vis_data_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, vis_seq_print_text, net_dev); +} + +struct bat_debuginfo { +struct attribute attr; +const struct file_operations fops; +}; + +#define BAT_DEBUGINFO (_name, _mode, _open) \ +struct bat_debuginfo bat_debuginfo_##_name = { \ + .attr = { .name = __stringify(_name), \ + .mode = _mode, }, \ + .fops = { .owner = THIS_MODULE, \ + .open = _open, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = single_release, \ + } \ +}; + +static BAT_DEBUGINFO(originators, S_IRUGO, originators_open); +static BAT_DEBUGINFO(gateways, S_IRUGO, gateways_open); +static BAT_DEBUGINFO(transtable_global, S_IRUGO, transtable_global_open); +static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open); +static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open); + +static struct bat_debuginfo *mesh_debuginfos[] = { + &bat_debuginfo_originators, + &bat_debuginfo_gateways, + &bat_debuginfo_transtable_global, + &bat_debuginfo_transtable_local, + &bat_debuginfo_vis_data, +NULL , +}; +void debugfs_init (void ) { bat_debugfs =debugfs_create_dir (DEBUGFS_BAT_SUBDIR ,NULL );
@@ -50,6 +112,8 @@ void debugfs_destroy(void)int debugfs_add_meshif (struct net_device *dev) {struct bat_priv *bat_priv =netdev_priv (dev); +struct bat_debuginfo **bat_debug; +struct dentry *file;if (!bat_debugfs) goto out;
@@ -60,7 +124,22 @@ int debugfs_add_meshif(struct net_device *dev)bat_socket_setup (bat_priv); +for (bat_debug = mesh_debuginfos; *bat_debug; ++bat_debug) { + file =debugfs_create_file (((*bat_debug)->attr).name, +S_IFREG | ((*bat_debug)->attr).mode, + bat_priv->debug_dir, + dev, &(*bat_debug)->fops); +if (!file) { +printk (KERN_ERR "batman-adv:Can't add debugfs file: " +"%s/%s\n" , dev->name, ((*bat_debug)->attr).name); + goto rem_attr; + } + } +return 0 ; +rem_attr: +debugfs_remove_recursive (bat_priv->debug_dir); + bat_priv->debug_dir =NULL ; out:return -ENOMEM ; }
batman-adv-kernelland/bat_sysfs.c +0 -91
122 lines not on this page · raw message
batman-adv-kernelland/gateway_client.c +19 -45
112 lines not on this page · raw message
batman-adv-kernelland/gateway_client.h +1 -2
@@ -27,6 +27,5 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int gw_client_seq_print_text (struct seq_file *seq,void *offset);bool gw_is_target (struct bat_priv *bat_priv,struct sk_buff *skb);
batman-adv-kernelland/main.h +1 -0
@@ -123,6 +123,7 @@ extern int bat_debug_type(int type);#include <linux/workqueue.h> /* workqueue */ #include <net/sock.h> /* struct sock */ #include <linux/jiffies.h> +#include <linux/seq_file.h> #include "types.h" #ifndef REVISION_VERSION
batman-adv-kernelland/originator.c +18 -43
109 lines not on this page · raw message
batman-adv-kernelland/originator.h +1 -2
@@ -28,7 +28,6 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int orig_seq_print_text (struct seq_file *seq,void *offset);int orig_hash_add_if (struct batman_if *batman_if,int max_if_num);int orig_hash_del_if (struct batman_if *batman_if,int max_if_num);
batman-adv-kernelland/translation-table.c +39 -75
162 lines not on this page · raw message
batman-adv-kernelland/translation-table.h +2 -4
@@ -25,15 +25,13 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int hna_local_seq_print_text (struct seq_file *seq,void *offset);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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int hna_global_seq_print_text (struct seq_file *seq,void *offset);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/vis.c +20 -39
127 lines not on this page · raw message
batman-adv-kernelland/vis.h +1 -2
@@ -47,8 +47,7 @@ struct recvlist_node {extern struct hashtable_t *vis_hash;extern spinlock_t vis_hash_lock; -ssize_t vis_fill_buffer_text (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int vis_seq_print_text (struct seq_file *seq,void *offset);void receive_server_sync_packet (struct bat_priv *bat_priv,struct vis_packet *vis_packet,int vis_info_len);
Signature · 1 line
1.7.1
PATCH v3 3/4 batman-adv: Move tables from sysfs to debugfs
Files which represent more than a single attribute aren't allowed in sysfs. As we have some files which aren't essential and are lists or tables aggregated from data from different places inside batman-adv, we must place them in a filesystem without such a restriction.
---
I've adjusted the output of transtable_global, vis_data and transtable_global to use an extra buffer inside the spin_lock_irqsave and do the actual printing outside the spinlock. Even if it is not the perfect solution, it should be good enough for now - aka doesn't create a deadlock on file reads.
batman-adv-kernelland/bat_debugfs.c | 79 +++++++++++++++ batman-adv-kernelland/bat_sysfs.c | 91 ----------------- batman-adv-kernelland/gateway_client.c | 64 ++++--------- batman-adv-kernelland/gateway_client.h | 3 +- batman-adv-kernelland/main.h | 1 + batman-adv-kernelland/originator.c | 61 ++++-------- batman-adv-kernelland/originator.h | 3 +- batman-adv-kernelland/translation-table.c | 151 +++++++++++++++-------------- batman-adv-kernelland/translation-table.h | 6 +- batman-adv-kernelland/vis.c | 111 +++++++++++++++------ batman-adv-kernelland/vis.h | 3 +- 11 files changed, 278 insertions(+), 295 deletions(-)
batman-adv-kernelland/bat_debugfs.c +79 -0
@@ -34,6 +34,68 @@static struct dentry *bat_debugfs; +static int originators_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, orig_seq_print_text, net_dev); +} + +static int gateways_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, gw_client_seq_print_text, net_dev); +} + +static int transtable_global_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, hna_global_seq_print_text, net_dev); +} + +static int transtable_local_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, hna_local_seq_print_text, net_dev); +} + +static int vis_data_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, vis_seq_print_text, net_dev); +} + +struct bat_debuginfo { +struct attribute attr; +const struct file_operations fops; +}; + +#define BAT_DEBUGINFO (_name, _mode, _open) \ +struct bat_debuginfo bat_debuginfo_##_name = { \ + .attr = { .name = __stringify(_name), \ + .mode = _mode, }, \ + .fops = { .owner = THIS_MODULE, \ + .open = _open, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = single_release, \ + } \ +}; + +static BAT_DEBUGINFO(originators, S_IRUGO, originators_open); +static BAT_DEBUGINFO(gateways, S_IRUGO, gateways_open); +static BAT_DEBUGINFO(transtable_global, S_IRUGO, transtable_global_open); +static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open); +static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open); + +static struct bat_debuginfo *mesh_debuginfos[] = { + &bat_debuginfo_originators, + &bat_debuginfo_gateways, + &bat_debuginfo_transtable_global, + &bat_debuginfo_transtable_local, + &bat_debuginfo_vis_data, +NULL , +}; +void debugfs_init (void ) { bat_debugfs =debugfs_create_dir (DEBUGFS_BAT_SUBDIR ,NULL );
@@ -50,6 +112,8 @@ void debugfs_destroy(void)int debugfs_add_meshif (struct net_device *dev) {struct bat_priv *bat_priv =netdev_priv (dev); +struct bat_debuginfo **bat_debug; +struct dentry *file;if (!bat_debugfs) goto out;
@@ -60,7 +124,22 @@ int debugfs_add_meshif(struct net_device *dev)bat_socket_setup (bat_priv); +for (bat_debug = mesh_debuginfos; *bat_debug; ++bat_debug) { + file =debugfs_create_file (((*bat_debug)->attr).name, +S_IFREG | ((*bat_debug)->attr).mode, + bat_priv->debug_dir, + dev, &(*bat_debug)->fops); +if (!file) { +printk (KERN_ERR "batman-adv:Can't add debugfs file: " +"%s/%s\n" , dev->name, ((*bat_debug)->attr).name); + goto rem_attr; + } + } +return 0 ; +rem_attr: +debugfs_remove_recursive (bat_priv->debug_dir); + bat_priv->debug_dir =NULL ; out:return -ENOMEM ; }
batman-adv-kernelland/bat_sysfs.c +0 -91
122 lines not on this page · raw message
batman-adv-kernelland/gateway_client.c +19 -45
112 lines not on this page · raw message
batman-adv-kernelland/gateway_client.h +1 -2
@@ -27,6 +27,5 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int gw_client_seq_print_text (struct seq_file *seq,void *offset);bool gw_is_target (struct bat_priv *bat_priv,struct sk_buff *skb);
batman-adv-kernelland/main.h +1 -0
@@ -123,6 +123,7 @@ extern int bat_debug_type(int type);#include <linux/workqueue.h> /* workqueue */ #include <net/sock.h> /* struct sock */ #include <linux/jiffies.h> +#include <linux/seq_file.h> #include "types.h" #ifndef REVISION_VERSION
batman-adv-kernelland/originator.c +18 -43
109 lines not on this page · raw message
batman-adv-kernelland/originator.h +1 -2
@@ -28,7 +28,6 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int orig_seq_print_text (struct seq_file *seq,void *offset);int orig_hash_add_if (struct batman_if *batman_if,int max_if_num);int orig_hash_del_if (struct batman_if *batman_if,int max_if_num);
batman-adv-kernelland/translation-table.c +76 -75
199 lines not on this page · raw message
batman-adv-kernelland/translation-table.h +2 -4
@@ -25,15 +25,13 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int hna_local_seq_print_text (struct seq_file *seq,void *offset);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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int hna_global_seq_print_text (struct seq_file *seq,void *offset);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/vis.c +80 -31
176 lines not on this page · raw message
batman-adv-kernelland/vis.h +1 -2
@@ -47,8 +47,7 @@ struct recvlist_node {extern struct hashtable_t *vis_hash;extern spinlock_t vis_hash_lock; -ssize_t vis_fill_buffer_text (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int vis_seq_print_text (struct seq_file *seq,void *offset);void receive_server_sync_packet (struct bat_priv *bat_priv,struct vis_packet *vis_packet,int vis_info_len);
Signature · 1 line
1.7.1
PATCH 4/4 batctl: Get tables from debugfs instead of sysfs
In reply to Sven Eckelmannbatctl must read the tables exported by batman-adv from debugfs as the old files in /sys/class/net/bat0/mesh/ were removed to follow the sysfs guidelines.
--- batctl/Makefile | 4 +- batctl/debug.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ batctl/debug.h | 34 ++++++++++++++++++ batctl/main.c | 9 +++-- batctl/sys.c | 60 -------------------------------- batctl/sys.h | 10 ----- batctl/vis.c | 20 ++++++----- 7 files changed, 155 insertions(+), 85 deletions(-) create mode 100644 batctl/debug.c create mode 100644 batctl/debug.h
batctl/Makefile +2 -2
@@ -39,8 +39,8 @@ SRC_FILES = "\(\.c\)\|\(\.h\)\|\(Makefile\)\|\(INSTALL\)\|\(LIESMICH\)\|\(README EXTRA_MODULES_C := bisect.c EXTRA_MODULES_H := bisect.h -SRC_C = main.c bat-hosts.c functions.c sys.c ping.c traceroute.c tcpdump.c list-batman.c hash.c vis.c debugfs.c $(EXTRA_MODULES_C) -SRC_H = main.h bat-hosts.h functions.h sys.h ping.h traceroute.h tcpdump.h list-batman.h hash.h allocate.h vis.h debugfs.h $(EXTRA_MODULES_H) +SRC_C = main.c bat-hosts.c functions.c sys.c debug.c ping.c traceroute.c tcpdump.c list-batman.c hash.c vis.c debugfs.c $(EXTRA_MODULES_C) +SRC_H = main.h bat-hosts.h functions.h sys.h debug.h ping.h traceroute.h tcpdump.h list-batman.h hash.h allocate.h vis.h debugfs.h $(EXTRA_MODULES_H) SRC_O = $(SRC_C:.c=.o) PACKAGE_NAME = batctl
batctl/debug.c new file +103 -0
104 lines not on this page · raw message
batctl/debug.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (C) 2009-2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner <[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 +* 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 DEBUG_BATIF_PATH "batman_adv/bat0" +#define DEBUG_ORIGINATORS "originators" +#define DEBUG_TRANSTABLE_LOCAL "transtable_local" +#define DEBUG_TRANSTABLE_GLOBAL "transtable_global" +#define DEBUG_GATEWAYS "gateways" +#define DEBUG_VIS_DATA "vis_data" + +void originators_usage (void ); +void trans_local_usage (void ); +void trans_global_usage (void ); +void gateways_usage (void ); +int handle_debug_table (int argc,char **argv,char *file_path,void table_usage (void ));
batctl/main.c +5 -4
@@ -30,6 +30,7 @@#include "main.h" #include "sys.h" +#include "debug.h" #include "ping.h" #include "traceroute.h" #include "tcpdump.h"
@@ -102,15 +103,15 @@ int main(int argc, char **argv) }else if ((strcmp (argv[1 ],"originators" ) ==0 ) || (strcmp (argv[1 ],"o" ) ==0 )) { - ret =handle_sys_table (argc -1 , argv +1 ,SYS_ORIGINATORS , originators_usage); + ret =handle_debug_table (argc -1 , argv +1 ,DEBUG_ORIGINATORS , originators_usage); }else if ((strcmp (argv[1 ],"translocal" ) ==0 ) || (strcmp (argv[1 ],"tl" ) ==0 )) { - ret =handle_sys_table (argc -1 , argv +1 ,SYS_TRANSTABLE_LOCAL , trans_local_usage); + ret =handle_debug_table (argc -1 , argv +1 ,DEBUG_TRANSTABLE_LOCAL , trans_local_usage); }else if ((strcmp (argv[1 ],"transglobal" ) ==0 ) || (strcmp (argv[1 ],"tg" ) ==0 )) { - ret =handle_sys_table (argc -1 , argv +1 ,SYS_TRANSTABLE_GLOBAL , trans_global_usage); + ret =handle_debug_table (argc -1 , argv +1 ,DEBUG_TRANSTABLE_GLOBAL , trans_global_usage); }else if ((strcmp (argv[1 ],"loglevel" ) ==0 ) || (strcmp (argv[1 ],"ll" ) ==0 )) {
@@ -138,7 +139,7 @@ int main(int argc, char **argv) }else if ((strcmp (argv[1 ],"gateways" ) ==0 ) || (strcmp (argv[1 ],"gwl" ) ==0 )) { - ret =handle_sys_table (argc -1 , argv +1 ,SYS_GATEWAYS , gateways_usage); + ret =handle_debug_table (argc -1 , argv +1 ,DEBUG_GATEWAYS , gateways_usage); }else if ((strcmp (argv[1 ],"aggregation" ) ==0 ) || (strcmp (argv[1 ],"ag" ) ==0 )) {
batctl/sys.c +0 -60
66 lines not on this page · raw message
batctl/sys.h +0 -10
@@ -24,31 +24,21 @@#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"#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"#define SYS_ORIG_INTERVAL "orig_interval"#define SYS_IFACE_PATH "/sys/class/net"#define SYS_MESH_IFACE_FMT SYS_IFACE_PATH"/%s/batman_adv/mesh_iface"#define SYS_IFACE_STATUS_FMT SYS_IFACE_PATH"/%s/batman_adv/iface_status" -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 );void orig_interval_usage (void );int log_print (int argc,char **argv);int interface (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 ));
batctl/vis.c +11 -9
@@ -29,7 +29,8 @@#include "vis.h" #include "functions.h" #include "bat-hosts.h" -#include "sys.h" +#include "debug.h" +#include "debugfs.h" #define TQ_MAX_VALUE 255
@@ -55,9 +56,9 @@ static bool with_names = true;static void usage (void ) { -printf ("batctl vis dot {-h}{--no-HNA|-H} {--no-2nd|-2} {--numbers|-n}\n" ); +printf ("batctl vis_data dot {-h}{--no-HNA|-H} {--no-2nd|-2} {--numbers|-n}\n" );printf ("or\n" ); -printf ("batctl vis json {-h}{--no-HNA|-H} {--no-2nd|-2} {--numbers|-n}\n" ); +printf ("batctl vis_data json {-h}{--no-HNA|-H} {--no-2nd|-2} {--numbers|-n}\n" ); }static void dot_print_tq (char *orig,char *from,const long tq)
@@ -163,15 +164,16 @@ const struct funcs json_funcs = { json_print_tq,static FILE *open_vis (void ) { -char full_path[500 ]; +char full_path[MAX_PATH +1 ]; +char *debugfs_mnt; -if (check_proc_dir ("/proc" ) !=EXIT_SUCCESS ) + debugfs_mnt =debugfs_mount (NULL ); +if (!debugfs_mnt) { +printf ("Error - can't mount or find debugfs\n" );return NULL ; + } -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)); +debugfs_make_path (DEBUG_BATIF_PATH "/" DEBUG_VIS_DATA , full_path,sizeof (full_path));return fopen (full_path,"r" ); }
Signature · 1 line
1.7.1
Quoted 2 lines · On Wednesday 19 May 2010 04:35:14 Sven Eckelmann wrote:
The patches are for trunk, but I would provide backported versions when the patches are discussed and we could solve the problem in a sane way.
Ok, I applied them (rev 1667-1670).
Thanks,
Marek
Re: [B.A.T.M.A.N.] Converting to sysfs - maint versions
In reply to Sven EckelmannQuoted 2 lines · Sven Eckelmann
The patches are for trunk, but I would provide backported versions when the patches are discussed and we could solve the problem in a sane way.
I've backported following patches to a version which can be applied using git-am on top of the maint branch of batctl and batman-adv:
* [PATCHv1 1/4] batman-adv: Move device for icmp injection to debugfs
* [PATCHv1 2/4] batctl: Use socket in debugfs instead of batman-adv device
* [PATCHv3 3/4] batman-adv: Move tables from sysfs to debugfs
* [PATCHv1 4/4] batctl: Get tables from debugfs instead of sysfs
(So nearly everything in version v1 - only patch 3/4 in v3).
Best regards,
Sven
PATCH 1/4 batman-adv: Move device for icmp injection to debugfs
batctl uses /dev/batman-adv to send special batman-adv icmp packets to other nodes in the mesh. To get it working with multiple batX devices we must ensure that every mesh device can have their own socket which is used to inject those packets in exactly one mesh.
The current implementation still doesn't allow to use complete separated meshes as we rely on structures which are not part of the private data of a batman device.
---
Please apply using git-am on top of batman-adv maint branch
Makefile.kbuild | 2 +- bat_debugfs.c | 74 ++++++++++ bat_debugfs.h | 33 ++++ compat.h | 65 +++++++-- device.c | 355 --------------------------------------------- icmp_socket.c | 329 +++++++++++++++++++++++++++++++++++++++++ device.h => icmp_socket.h | 18 +-- main.c | 21 ++- routing.c | 4 +- types.h | 5 +- 10 files changed, 516 insertions(+), 390 deletions(-) create mode 100644 bat_debugfs.c create mode 100644 bat_debugfs.h delete mode 100644 device.c create mode 100644 icmp_socket.c rename device.h => icmp_socket.h (54%)
Makefile.kbuild +1 -1
@@ -32,4 +32,4 @@ EXTRA_CFLAGS += -DREVISION_VERSION=\"r$(REVISION)\" endif obj-m += batman-adv.o -batman-adv-objs := main.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 $(shell [ "2" -eq "$(VERSION)" ] 2>&- && [ "6" -eq "$(PATCHLEVEL)" ] 2>&- && [ "$(SUBLEVEL)" -le "28" ] 2>&- && echo bat_printk.o) +batman-adv-objs := main.o bat_debugfs.o bat_sysfs.o send.o routing.o soft-interface.o icmp_socket.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o originator.o $(shell [ "2" -eq "$(VERSION)" ] 2>&- && [ "6" -eq "$(PATCHLEVEL)" ] 2>&- && [ "$(SUBLEVEL)" -le "28" ] 2>&- && echo bat_printk.o)
bat_debugfs.c new file +74 -0
74 lines not on this page · raw message
bat_debugfs.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* 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 +* +*/ + + +#ifndef BAT_DEBUGFS_H +#define BAT_DEBUGFS_H + +#define DEBUGFS_BAT_SUBDIR "batman_adv" + +void debugfs_init (void ); +void debugfs_destroy (void ); +int debugfs_add_meshif (struct net_device *dev); +void debugfs_del_meshif (struct net_device *dev); + +#endif
compat.h +55 -10
77 lines not on this page · raw message
device.c deleted +0 -355
355 lines not on this page · raw message
icmp_socket.c new file +329 -0
329 lines not on this page · raw message
icmp_socket.h renamed from device.h +5 -13
@@ -21,16 +21,8 @@#include "types.h" -void bat_device_init (void ); -int bat_device_setup (void ); -void bat_device_destroy (void ); -int bat_device_open (struct inode *inode,struct file *file); -int bat_device_release (struct inode *inode,struct file *file); -ssize_t bat_device_read (struct file *file,char __user *buf,size_t count, -loff_t *ppos); -ssize_t bat_device_write (struct file *file,const char __user *buff, -size_t len,loff_t *off); -unsigned int bat_device_poll (struct file *file,poll_table *wait); -void bat_device_add_packet (struct device_client *device_client, -struct icmp_packet *icmp_packet); -void bat_device_receive_packet (struct icmp_packet *icmp_packet); +#define ICMP_SOCKET "socket" + +void bat_socket_init (void ); +int bat_socket_setup (struct bat_priv *bat_priv); +void bat_socket_receive_packet (struct icmp_packet *icmp_packet);
main.c +14 -7
@@ -21,11 +21,12 @@#include "main.h" #include "bat_sysfs.h" +#include "bat_debugfs.h" #include "routing.h" #include "send.h" #include "originator.h" #include "soft-interface.h" -#include "device.h" +#include "icmp_socket.h" #include "translation-table.h" #include "hard-interface.h" #include "types.h"
@@ -93,7 +94,8 @@ int init_module(void)if (!bat_event_workqueue)return -ENOMEM ; -bat_device_init (); +bat_socket_init (); +debugfs_init ();/* initialize layer 2 interface */ soft_device = alloc_netdev(sizeof(struct bat_priv) , "bat%d",
@@ -118,6 +120,11 @@ int init_module(void)if (retval <0 ) goto unreg_soft_device; + retval =debugfs_add_meshif (soft_device); + +if (retval <0 ) + goto unreg_sysfs; +register_netdevice_notifier (&hard_if_notifier);dev_add_pack (&batman_adv_packet_type);
@@ -127,6 +134,8 @@ int init_module(void)return 0 ; +unreg_sysfs: +sysfs_del_meshif (soft_device); unreg_soft_device:unregister_netdevice (soft_device); free_soft_device:
@@ -144,6 +153,7 @@ void cleanup_module(void)hardif_remove_interfaces ();if (soft_device) { +debugfs_del_meshif (soft_device);sysfs_del_meshif (soft_device);unregister_netdev (soft_device); soft_device =NULL ;
@@ -155,7 +165,7 @@ void cleanup_module(void) bat_event_workqueue =NULL ; } -/* activates the module, creates bat device, starts timer ... */ +/* activates the module, starts timer ... */ void activate_module (void ) {if (originator_init () <1 )
@@ -169,9 +179,6 @@ void activate_module(void)hna_local_add (soft_device->dev_addr); -if (bat_device_setup () <1 ) - goto end; -if (vis_init () <1 ) goto err;
@@ -206,7 +213,7 @@ void deactivate_module(void)hna_global_free ();synchronize_net (); -bat_device_destroy (); +debugfs_destroy ();synchronize_rcu ();atomic_set (&module_state,MODULE_INACTIVE );
routing.c +2 -2
@@ -25,7 +25,7 @@#include "hash.h" #include "soft-interface.h" #include "hard-interface.h" -#include "device.h" +#include "icmp_socket.h" #include "translation-table.h" #include "originator.h" #include "types.h"
@@ -669,7 +669,7 @@ static int recv_my_icmp_packet(struct sk_buff *skb)/* add data to device queue */ if (icmp_packet->msg_type !=ECHO_REQUEST ) { -bat_device_receive_packet (icmp_packet); +bat_socket_receive_packet (icmp_packet);return NET_RX_DROP ; }
types.h +3 -2
@@ -106,9 +106,10 @@ struct bat_priv {char num_ifaces;struct batman_if *primary_if;struct kobject *mesh_obj; +struct dentry *debug_dir; }; -struct device_client { +struct socket_client {struct list_head queue_list;unsigned int queue_len;unsigned char index;
@@ -116,7 +117,7 @@ struct device_client {wait_queue_head_t queue_wait; }; -struct device_packet { +struct socket_packet {struct list_head list;struct icmp_packet icmp_packet; };
Signature · 1 line
1.7.1
PATCH 2/4 batctl: Use socket in debugfs instead of batman-adv device
In reply to Sven EckelmannThe batman-adv device which was only usable for a single batX net device was replaced with a file in debugfs which can be used the same way as /dev/batman-adv before.
It seems that the debugfs has no 100% common mount path in current distributions and maybe isn't mounted at all. So before we try to access a batman file in debugfs, we have to search for the mountpoint in /proc/mounts and maybe mount it manually in /sys/kernel/debug.
---
Please apply on top of batctl-0.2.x branch.
Makefile | 4 +- debugfs.c | 269 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ debugfs.h | 46 ++++++++++ main.h | 2 +- ping.c | 21 ++++- traceroute.c | 21 ++++- 6 files changed, 350 insertions(+), 13 deletions(-) create mode 100644 debugfs.c create mode 100644 debugfs.h
Makefile +2 -2
@@ -39,8 +39,8 @@ SRC_FILES = "\(\.c\)\|\(\.h\)\|\(Makefile\)\|\(INSTALL\)\|\(LIESMICH\)\|\(README EXTRA_MODULES_C := bisect.c EXTRA_MODULES_H := bisect.h -SRC_C = main.c bat-hosts.c functions.c sys.c ping.c traceroute.c tcpdump.c list-batman.c hash.c vis.c $(EXTRA_MODULES_C) -SRC_H = main.h bat-hosts.h functions.h sys.h ping.h traceroute.h tcpdump.h list-batman.h hash.h allocate.h vis.h $(EXTRA_MODULES_H) +SRC_C = main.c bat-hosts.c functions.c sys.c ping.c traceroute.c tcpdump.c list-batman.c hash.c vis.c debugfs.c $(EXTRA_MODULES_C) +SRC_H = main.h bat-hosts.h functions.h sys.h ping.h traceroute.h tcpdump.h list-batman.h hash.h allocate.h vis.h debugfs.h $(EXTRA_MODULES_H) SRC_O = $(SRC_C:.c=.o) PACKAGE_NAME = batctl
debugfs.c new file +269 -0
269 lines not on this page · raw message
debugfs.h new file +46 -0
46 lines not on this page · raw message
main.h +1 -1
@@ -23,4 +23,4 @@#define SOURCE_VERSION "0.2.2-beta"/*put exactly one distinct word inside the string like "0.3-pre-alpha" or "0.3-rc1" or "0.3" */ -#define BAT_DEVICE "/dev/batman-adv" +#define SOCKET_PATH "batman_adv/bat0/socket"
ping.c +16 -5
@@ -35,6 +35,7 @@#include "functions.h" #include "packet.h" #include "bat-hosts.h" +#include "debugfs.h" char is_aborted =0 ;
@@ -76,6 +77,8 @@ int ping(int argc, char **argv)char *dst_string, *mac_string;double time_delta;float min =0.0 , max =0.0 , avg =0.0 ; +char *debugfs_mnt; +char icmp_socket[MAX_PATH +1 ];while ((optchar =getopt (argc, argv,"hc:i:t:" )) !=-1 ) {switch (optchar) {
@@ -132,11 +135,19 @@ int ping(int argc, char **argv)signal (SIGINT , sig_handler);signal (SIGTERM , sig_handler); - ping_fd =open (BAT_DEVICE ,O_RDWR ); + debugfs_mnt =debugfs_mount (NULL ); +if (!debugfs_mnt) { +printf ("Error - can't mount or find debugfs\n" ); + goto out; + } + +debugfs_make_path (SOCKET_PATH , icmp_socket,sizeof (icmp_socket)); + + ping_fd =open (icmp_socket,O_RDWR );if (ping_fd <0 ) { -printf ("Error - can't open a connection to the batman adv kernel module via the device '%s': %s\n" , -BAT_DEVICE ,strerror (errno)); +printf ("Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n" , + icmp_socket,strerror (errno));printf ("Check whether the module is loaded and active.\n" ); goto out; }
@@ -161,7 +172,7 @@ int ping(int argc, char **argv) icmp_packet_out.seqno =htons (++seq_counter);if (write (ping_fd, (char *)&icmp_packet_out,sizeof (icmp_packet_out)) <0 ) { -printf ("Error - can't write to batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't write to batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno)); goto sleep; }
@@ -191,7 +202,7 @@ int ping(int argc, char **argv) read_len =read (ping_fd, (char *)&icmp_packet_in,sizeof (icmp_packet_in));if (read_len <0 ) { -printf ("Error - can't read from batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't read from batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno)); goto sleep; }
traceroute.c +16 -5
@@ -34,6 +34,7 @@#include "functions.h" #include "packet.h" #include "bat-hosts.h" +#include "debugfs.h" #define TTL_MAX 50
@@ -59,6 +60,8 @@ int traceroute(int argc, char **argv)int ret =EXIT_FAILURE , res, trace_fd =0 , i;int found_args =1 , optchar, seq_counter =0 , read_opt =USE_BAT_HOSTS ;double time_delta; +char *debugfs_mnt; +char icmp_socket[MAX_PATH +1 ];while ((optchar =getopt (argc, argv,"hn" )) !=-1 ) {switch (optchar) {
@@ -99,11 +102,19 @@ int traceroute(int argc, char **argv) mac_string =ether_ntoa_long (dst_mac); - trace_fd =open (BAT_DEVICE ,O_RDWR ); + debugfs_mnt =debugfs_mount (NULL ); +if (!debugfs_mnt) { +printf ("Error - can't mount or find debugfs\n" ); + goto out; + } + +debugfs_make_path (SOCKET_PATH , icmp_socket,sizeof (icmp_socket)); + + trace_fd =open (icmp_socket,O_RDWR );if (trace_fd <0 ) { -printf ("Error - can't open a connection to the batman adv kernel module via the device '%s': %s\n" , -BAT_DEVICE ,strerror (errno)); +printf ("Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n" , + icmp_socket,strerror (errno));printf ("Check whether the module is loaded and active.\n" ); goto out; }
@@ -123,7 +134,7 @@ int traceroute(int argc, char **argv) icmp_packet_out.seqno =htons (++seq_counter);if (write (trace_fd, (char *)&icmp_packet_out,sizeof (icmp_packet_out)) <0 ) { -printf ("Error - can't write to batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't write to batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno));continue ; }
@@ -149,7 +160,7 @@ int traceroute(int argc, char **argv) read_len =read (trace_fd, (char *)&icmp_packet_in,sizeof (icmp_packet_in));if (read_len <0 ) { -printf ("Error - can't read from batman adv kernel file '%s': %s\n" ,BAT_DEVICE ,strerror (errno)); +printf ("Error - can't read from batman adv kernel file '%s': %s\n" , icmp_socket,strerror (errno));continue ; }
Signature · 1 line
1.7.1
PATCH 3/4 batman-adv: Move tables from sysfs to debugfs
In reply to Sven EckelmannFiles which represent more than a single attribute aren't allowed in sysfs. As we have some files which aren't essential and are lists or tables aggregated from data from different places inside batman-adv, we must place them in a filesystem without such a restriction.
---
Please apply using git-am on top of batman-adv maint branch after
* batman-adv: Move device for icmp injection to debugfs
bat_debugfs.c | 71 ++++++++++++++++++++++++ bat_sysfs.c | 79 -------------------------- main.h | 1 + originator.c | 61 ++++++-------------- originator.h | 3 +- translation-table.c | 153 ++++++++++++++++++++++++++------------------------- translation-table.h | 6 +- vis.c | 111 ++++++++++++++++++++++++++---------- vis.h | 3 +- 9 files changed, 251 insertions(+), 237 deletions(-)
bat_debugfs.c +71 -0
@@ -32,6 +32,60 @@static struct dentry *bat_debugfs; +static int originators_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, orig_seq_print_text, net_dev); +} + +static int transtable_global_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, hna_global_seq_print_text, net_dev); +} + +static int transtable_local_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, hna_local_seq_print_text, net_dev); +} + +static int vis_data_open (struct inode *inode,struct file *file) +{ +struct net_device *net_dev = (struct net_device *)inode->i_private; +return single_open (file, vis_seq_print_text, net_dev); +} + +struct bat_debuginfo { +struct attribute attr; +const struct file_operations fops; +}; + +#define BAT_DEBUGINFO (_name, _mode, _open) \ +struct bat_debuginfo bat_debuginfo_##_name = { \ + .attr = { .name = __stringify(_name), \ + .mode = _mode, }, \ + .fops = { .owner = THIS_MODULE, \ + .open = _open, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = single_release, \ + } \ +}; + +static BAT_DEBUGINFO(originators, S_IRUGO, originators_open); +static BAT_DEBUGINFO(transtable_global, S_IRUGO, transtable_global_open); +static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open); +static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open); + +static struct bat_debuginfo *mesh_debuginfos[] = { + &bat_debuginfo_originators, + &bat_debuginfo_transtable_global, + &bat_debuginfo_transtable_local, + &bat_debuginfo_vis_data, +NULL , +}; +void debugfs_init (void ) { bat_debugfs =debugfs_create_dir (DEBUGFS_BAT_SUBDIR ,NULL );
@@ -48,6 +102,8 @@ void debugfs_destroy(void)int debugfs_add_meshif (struct net_device *dev) {struct bat_priv *bat_priv =netdev_priv (dev); +struct bat_debuginfo **bat_debug; +struct dentry *file;if (!bat_debugfs) goto out;
@@ -58,7 +114,22 @@ int debugfs_add_meshif(struct net_device *dev)bat_socket_setup (bat_priv); +for (bat_debug = mesh_debuginfos; *bat_debug; ++bat_debug) { + file =debugfs_create_file (((*bat_debug)->attr).name, +S_IFREG | ((*bat_debug)->attr).mode, + bat_priv->debug_dir, + dev, &(*bat_debug)->fops); +if (!file) { +printk (KERN_ERR "batman-adv:Can't add debugfs file: " +"%s/%s\n" , dev->name, ((*bat_debug)->attr).name); + goto rem_attr; + } + } +return 0 ; +rem_attr: +debugfs_remove_recursive (bat_priv->debug_dir); + bat_priv->debug_dir =NULL ; out:return -ENOMEM ; }
bat_sysfs.c +0 -79
110 lines not on this page · raw message
main.h +1 -0
@@ -116,6 +116,7 @@ extern int bat_debug_type(int type);#include <linux/workqueue.h> /* workqueue */ #include <net/sock.h> /* struct sock */ #include <linux/jiffies.h> +#include <linux/seq_file.h> #include "types.h" #ifndef REVISION_VERSION
originator.c +18 -43
109 lines not on this page · raw message
originator.h +1 -2
@@ -28,7 +28,6 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int orig_seq_print_text (struct seq_file *seq,void *offset);int orig_hash_add_if (struct batman_if *batman_if,int max_if_num);int orig_hash_del_if (struct batman_if *batman_if,int max_if_num);
translation-table.c +77 -76
201 lines not on this page · raw message
translation-table.h +2 -4
@@ -25,15 +25,13 @@ 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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int hna_local_seq_print_text (struct seq_file *seq,void *offset);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 (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int hna_global_seq_print_text (struct seq_file *seq,void *offset);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);
vis.c +80 -31
176 lines not on this page · raw message
vis.h +1 -2
@@ -47,8 +47,7 @@ struct recvlist_node {extern struct hashtable_t *vis_hash;extern spinlock_t vis_hash_lock; -ssize_t vis_fill_buffer_text (struct net_device *net_dev,char *buff, -size_t count,loff_t off); +int vis_seq_print_text (struct seq_file *seq,void *offset);void receive_server_sync_packet (struct bat_priv *bat_priv,struct vis_packet *vis_packet,int vis_info_len);
Signature · 1 line
1.7.1
PATCH 4/4 batctl: Get tables from debugfs instead of sysfs
In reply to Sven Eckelmannbatctl must read the tables exported by batman-adv from debugfs as the old files in /sys/class/net/bat0/mesh/ were removed to follow the sysfs guidelines.
---
Please apply on top of batctl-0.2.x branch.
Makefile | 4 +- debug.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ debug.h | 32 +++++++++++++++++++ main.c | 7 ++-- sys.c | 51 ------------------------------ sys.h | 8 ----- vis.c | 20 ++++++----- 7 files changed, 152 insertions(+), 73 deletions(-) create mode 100644 debug.c create mode 100644 debug.h
Makefile +2 -2
@@ -39,8 +39,8 @@ SRC_FILES = "\(\.c\)\|\(\.h\)\|\(Makefile\)\|\(INSTALL\)\|\(LIESMICH\)\|\(README EXTRA_MODULES_C := bisect.c EXTRA_MODULES_H := bisect.h -SRC_C = main.c bat-hosts.c functions.c sys.c ping.c traceroute.c tcpdump.c list-batman.c hash.c vis.c debugfs.c $(EXTRA_MODULES_C) -SRC_H = main.h bat-hosts.h functions.h sys.h ping.h traceroute.h tcpdump.h list-batman.h hash.h allocate.h vis.h debugfs.h $(EXTRA_MODULES_H) +SRC_C = main.c bat-hosts.c functions.c sys.c debug.c ping.c traceroute.c tcpdump.c list-batman.c hash.c vis.c debugfs.c $(EXTRA_MODULES_C) +SRC_H = main.h bat-hosts.h functions.h sys.h debug.h ping.h traceroute.h tcpdump.h list-batman.h hash.h allocate.h vis.h debugfs.h $(EXTRA_MODULES_H) SRC_O = $(SRC_C:.c=.o) PACKAGE_NAME = batctl
debug.c new file +103 -0
104 lines not on this page · raw message
debug.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 2009-2010 B.A.T.M.A.N. contributors: +* +* Marek Lindner <[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 +* 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 DEBUG_BATIF_PATH "batman_adv/bat0" +#define DEBUG_ORIGINATORS "originators" +#define DEBUG_TRANSTABLE_LOCAL "transtable_local" +#define DEBUG_TRANSTABLE_GLOBAL "transtable_global" +#define DEBUG_VIS_DATA "vis_data" + +void originators_usage (void ); +void trans_local_usage (void ); +void trans_global_usage (void ); +int handle_debug_table (int argc,char **argv,char *file_path,void table_usage (void ));
main.c +4 -3
@@ -30,6 +30,7 @@#include "main.h" #include "sys.h" +#include "debug.h" #include "ping.h" #include "traceroute.h" #include "tcpdump.h"
@@ -99,15 +100,15 @@ int main(int argc, char **argv) }else if ((strcmp (argv[1 ],"originators" ) ==0 ) || (strcmp (argv[1 ],"o" ) ==0 )) { - ret =handle_sys_table (argc -1 , argv +1 ,SYS_ORIGINATORS , originators_usage); + ret =handle_debug_table (argc -1 , argv +1 ,DEBUG_ORIGINATORS , originators_usage); }else if ((strcmp (argv[1 ],"translocal" ) ==0 ) || (strcmp (argv[1 ],"tl" ) ==0 )) { - ret =handle_sys_table (argc -1 , argv +1 ,SYS_TRANSTABLE_LOCAL , trans_local_usage); + ret =handle_debug_table (argc -1 , argv +1 ,DEBUG_TRANSTABLE_LOCAL , trans_local_usage); }else if ((strcmp (argv[1 ],"transglobal" ) ==0 ) || (strcmp (argv[1 ],"tg" ) ==0 )) { - ret =handle_sys_table (argc -1 , argv +1 ,SYS_TRANSTABLE_GLOBAL , trans_global_usage); + ret =handle_debug_table (argc -1 , argv +1 ,DEBUG_TRANSTABLE_GLOBAL , trans_global_usage); }else if ((strcmp (argv[1 ],"loglevel" ) ==0 ) || (strcmp (argv[1 ],"ll" ) ==0 )) {
sys.c +0 -51
57 lines not on this page · raw message
sys.h +0 -8
@@ -24,25 +24,17 @@#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"#define SYS_VIS_MODE "vis_mode" -#define SYS_VIS_DATA "vis_data"#define SYS_ORIG_INTERVAL "orig_interval"#define SYS_IFACE_PATH "/sys/class/net"#define SYS_MESH_IFACE_FMT SYS_IFACE_PATH"/%s/batman_adv/mesh_iface"#define SYS_IFACE_STATUS_FMT SYS_IFACE_PATH"/%s/batman_adv/iface_status" -void originators_usage (void ); -void trans_local_usage (void ); -void trans_global_usage (void );void aggregation_usage (void );void vis_mode_usage (void );void orig_interval_usage (void );int log_print (int argc,char **argv);int interface (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 ));
vis.c +11 -9
@@ -31,7 +31,8 @@#include "vis.h" #include "functions.h" #include "bat-hosts.h" -#include "sys.h" +#include "debug.h" +#include "debugfs.h" #define TQ_MAX_VALUE 255
@@ -57,9 +58,9 @@ static bool with_names = true;static void usage (void ) { -printf ("batctl vis dot {-h}{--no-HNA|-H} {--no-2nd|-2} {--numbers|-n}\n" ); +printf ("batctl vis_data dot {-h}{--no-HNA|-H} {--no-2nd|-2} {--numbers|-n}\n" );printf ("or\n" ); -printf ("batctl vis json {-h}{--no-HNA|-H} {--no-2nd|-2} {--numbers|-n}\n" ); +printf ("batctl vis_data json {-h}{--no-HNA|-H} {--no-2nd|-2} {--numbers|-n}\n" ); }static void dot_print_tq (char *orig,char *from,const long tq)
@@ -165,15 +166,16 @@ const struct funcs json_funcs = { json_print_tq,static FILE *open_vis (void ) { -char full_path[500 ]; +char full_path[MAX_PATH +1 ]; +char *debugfs_mnt; -if (check_proc_dir ("/proc" ) !=EXIT_SUCCESS ) + debugfs_mnt =debugfs_mount (NULL ); +if (!debugfs_mnt) { +printf ("Error - can't mount or find debugfs\n" );return NULL ; + } -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)); +debugfs_make_path (DEBUG_BATIF_PATH "/" DEBUG_VIS_DATA , full_path,sizeof (full_path));return fopen (full_path,"r" ); }
Signature · 1 line
1.7.1