From: Marco Dalla Torre <marco.dallato@gmail.com>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: Re: [B.A.T.M.A.N.] [PATCHv3] batctl: add sys framework for VLAN support
Date: Thu, 29 Aug 2013 17:15:51 +0200 [thread overview]
Message-ID: <521F65A7.2000701@gmail.com> (raw)
In-Reply-To: <201308292018.28480.lindner_marek@yahoo.de>
Allow the batctl tool to take advantage of changes from commit
e4ff5c153dab054a6cd1c4132f87bc5e77127456 ("add sys framework for VLAN")
recently added to batman-adv, so that users can execute commands in
a per VLAN fashion.
If no directory entry corresponding to the user-selected device is found
at the standard location for non VLAN interfaces
(/sys/class/net/${base_device}), 'batctl' now looks into directory:
/sys/devices/virtual/net/${base_device}/mesh/vlan${vid}
Where:
-${base_device}: the batman device on top of which the VLAN is sitting
-${device}: the device interface for the VLAN,
-${vid}: the identifier assigned to the VLAN.
Information on VLAN devices (base device, vid) necessary to construct the
directory path is acquired by parsing /proc/net/vlan/${device}.
If the user-selected command is not supported by the VLAN, an appropriate
error is shown.
Signed-off-by: Marco Dalla Torre<marco.dallato@gmail.com>
---
functions.c | 3 +++
main.c | 2 +-
man/batctl.8 | 2 +-
sys.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 56 insertions(+), 2 deletions(-)
=======================================
diff --git a/functions.c b/functions.c
index cc05a48..ed010ea 100644
--- a/functions.c
+++ b/functions.c
@@ -135,7 +135,10 @@
static·void·file_open_problem_dbg(char·*dir,·char·*fname,·char·*full_path)
» » »
fprintf(stderr,·"Error·-·the·folder·'/sys/'·was·not·found·on·the·system\n");
» » »
fprintf(stderr,·"Please·make·sure·that·the·sys·filesystem·is·properly·mounted\n");
» » » return;
+» » }·else·if·(strstr(dir,·"/sys/devices/virtual/"))·{
+» » »
fprintf(stderr,·"The·selected·feature·'%s'·is·not·supported·for·vlans\n",·fname);
+» » » return;
» » }
» }
=======================================
diff --git a/main.c b/main.c
index 24d42fb..bac37ca 100644
--- a/main.c
+++ b/main.c
@@ -49,8 +49,8 @@
void·print_usage(void)
»
fprintf(stderr,·"Usage:·batctl·[options]·command|debug·table·[parameters]\n");
» fprintf(stderr,·"options:\n");
-» fprintf(stderr,·"·\t-m·mesh·interface·(default·'bat0')\n");
+»
fprintf(stderr,·"·\t-m·mesh·interface·or·mesh-based·VLAN·interface·(default·'bat0')\n");
»
fprintf(stderr,·"·\t-h·print·this·help·(or·'batctl·<command|debug·table>·-h'·for·the·parameter·help)\n");
» fprintf(stderr,·"·\t-v·print·version\n");
» fprintf(stderr,·"\n");
=======================================
diff --git a/man/batctl.8 b/man/batctl.8
index d04385b..7fd324d 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -42,8 +42,8 @@
behaviour·or·using·the·B.A.T.M.A.N.·advanced·protocol.
.SH·OPTIONS
.TP
.I·\fBoptions:
-\-m·····specify·mesh·interface·(default·'bat0')
+\-m·····specify·mesh·interface·or·a·mesh-based·VLAN·interface·(default·'bat0')
.br
\-h·····print·general·batctl·help
.br
=======================================
diff --git a/sys.c b/sys.c
index b1d7ea8..00d2ed1 100644
--- a/sys.c
+++ b/sys.c
@@ -371,7 +371,38 @@
static·void·settings_usage(int·setting)
» fprintf(stderr,·"·\t·-h·print·this·help\n");
}
+int·get_basedev_vid(char·*mesh_iface,·char·**base_dev,·unsigned·short·*vid)
+{
+» char·*vdev;
+» char·line[100];
+» const·char·path[]·=·"/proc/net/vlan/";
+» int·size·=·sizeof(path)·+·sizeof(mesh_iface);
+» FILE·*fp·=·NULL;
+
+» char·*fpath·=·malloc(size);
+» strcpy(fpath,·path);
+» /*·prepare·path·file·path:·/proc/net/vlan/$mesh_iface*/
+» strcat(fpath,·mesh_iface);
+
+» fp·=·fopen(fpath,·"r");
+» if·(fp·==·NULL)
+» » return·1;
+
+» if·(fscanf(fp,·"%ms·%*s·%hu·%*s·%*d·%*s·%*d",·&vdev,·vid)·==·0)
+» » return·0;
+
+» while·(fgets(line,·sizeof(line),·fp)·!=·NULL)·{
+» » if·(sscanf(line,·"Device:·%ms",·base_dev)·==·1)
+» » » break;
+» }
+» /*·handle·base·device·not·found·case·*/
+» if·(*base_dev·==·NULL)
+» » return·0;
+
+» return·1;
+}
+
int·handle_sys_setting(char·*mesh_iface,·int·setting,·int·argc,·char·**argv)
{
» int·optchar,·res·=·EXIT_FAILURE;
@@ -392,8 +423,27 @@
int·handle_sys_setting(char·*mesh_iface,·int·setting,·int·argc,·char·**argv)
» snprintf(path_buff,·PATH_BUFF_LEN,·SYS_BATIF_PATH_FMT,·mesh_iface);
» path_buff[PATH_BUFF_LEN·-·1]·=·'\0';
+» if·(access(path_buff,·F_OK)·!=·0)·{
+» » if·(errno·==·ENOENT)·{
+» » » /*·path·does·not·exist,·no·lan·interface:·check·vlan·*/
+» » » unsigned·short·vid·=·0;
+» » » char·*base_dev·=·NULL;
+» » » if·(get_basedev_vid(mesh_iface,·&base_dev,·&vid)·==·1)·{
+» » » » free(path_buff);
+» » » » char·sys_vlan_path[]·=
+» » » » » "/sys/devices/virtual/net/%s/mesh/vlan%d/";
+» » » » int·size·=·sizeof(sys_vlan_path)·+·sizeof(base_dev);
+» » » » path_buff·=·malloc(size);
+» » » » sprintf(path_buff,·sys_vlan_path,·base_dev,·vid);
+» » » }
+» » }·else·if·(errno·==·ENOTDIR)·{
+» » » /*·not·a·directory,·something·wrong·here·*/
+» » » fprintf(stderr,·"Error·-·expected·directory·at·'%s'\n",
+» » » » path_buff);
+» » » return·EXIT_FAILURE;
+» » }
+» }
» if·(argc·==·1)·{
» » res·=·read_file(path_buff,·(char·*)batctl_settings[setting].sysfs_name,
» » » » NO_FLAGS,·0,·0,·0);
--·
1.8.3.2
next prev parent reply other threads:[~2013-08-29 15:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-27 12:29 [B.A.T.M.A.N.] [PATCH] batctl: add sys framework for VLAN support Marco Dalla Torre
2013-08-28 15:05 ` Antonio Quartulli
2013-08-29 12:18 ` Marek Lindner
2013-08-29 15:15 ` Marco Dalla Torre [this message]
2013-08-29 18:43 ` [B.A.T.M.A.N.] [PATCHv3] " Marco Dalla Torre
2013-09-02 7:03 ` Antonio Quartulli
2013-09-03 12:45 ` [B.A.T.M.A.N.] [PATCHv4] " Marco Dalla Torre
2013-09-04 6:48 ` Marek Lindner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=521F65A7.2000701@gmail.com \
--to=marco.dallato@gmail.com \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.