public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH v3 7/9] batctl: Move check_mesh_iface* to functions.c
Date: Tue, 18 Oct 2016 16:17:29 +0200	[thread overview]
Message-ID: <20161018141731.7970-7-sven@narfation.org> (raw)
In-Reply-To: <2403515.P9aVkiGJpp@bentobox>

The check_mesh_iface* functions are not used to modify anything in sysfs.
So they are better placed in the common/shared functions file than in
sys.c.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
v3:
 - rebased on current master
v2:
 - no change
---
 functions.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 functions.h |  2 ++
 sys.c       | 56 --------------------------------------------------------
 sys.h       |  2 --
 4 files changed, 61 insertions(+), 58 deletions(-)

diff --git a/functions.c b/functions.c
index 85482b4..66b2d16 100644
--- a/functions.c
+++ b/functions.c
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <dirent.h>
 #include <sys/time.h>
 #include <netinet/in.h>
 #include <stdint.h>
@@ -57,6 +58,8 @@
 #include "debugfs.h"
 #include "netlink.h"
 
+#define PATH_BUFF_LEN 200
+
 static struct timespec start_time;
 static char *host_name;
 char *line_ptr = NULL;
@@ -1013,3 +1016,59 @@ err_free_sock:
 
 	return err;
 }
+
+int check_mesh_iface(char *mesh_iface)
+{
+	char *base_dev = NULL;
+	char path_buff[PATH_BUFF_LEN];
+	int ret = -1, vid;
+	DIR *dir;
+
+	/* use the parent interface if this is a VLAN */
+	vid = vlan_get_link(mesh_iface, &base_dev);
+	if (vid >= 0)
+		snprintf(path_buff, PATH_BUFF_LEN, SYS_VLAN_PATH, base_dev, vid);
+	else
+		snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface);
+
+	/* try to open the mesh sys directory */
+	dir = opendir(path_buff);
+	if (!dir)
+		goto out;
+
+	closedir(dir);
+
+	ret = 0;
+out:
+	if (base_dev)
+		free(base_dev);
+
+	return ret;
+}
+
+int check_mesh_iface_ownership(char *mesh_iface, char *hard_iface)
+{
+	char path_buff[PATH_BUFF_LEN];
+	int res;
+
+	/* check if this device actually belongs to the mesh interface */
+	snprintf(path_buff, sizeof(path_buff), SYS_MESH_IFACE_FMT, hard_iface);
+	res = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
+	if (res != EXIT_SUCCESS) {
+		fprintf(stderr, "Error - the directory '%s' could not be read: %s\n",
+			path_buff, strerror(errno));
+		fprintf(stderr, "Is the batman-adv module loaded and sysfs mounted ?\n");
+		return EXIT_FAILURE;
+	}
+
+	if (line_ptr[strlen(line_ptr) - 1] == '\n')
+		line_ptr[strlen(line_ptr) - 1] = '\0';
+
+	if (strcmp(line_ptr, mesh_iface) != 0) {
+		fprintf(stderr, "Error - interface %s is part of batman network %s, not %s\n",
+			hard_iface, line_ptr, mesh_iface);
+		return EXIT_FAILURE;
+	}
+
+	return EXIT_SUCCESS;
+}
diff --git a/functions.h b/functions.h
index 4c350f8..e413d6b 100644
--- a/functions.h
+++ b/functions.h
@@ -50,6 +50,8 @@ struct ether_addr *resolve_mac(const char *asc);
 int vlan_get_link(const char *ifname, char **parent);\
 int query_rtnl_link(int ifindex, nl_recvmsg_msg_cb_t func, void *arg);
 int netlink_simple_request(struct nl_msg *msg);
+int check_mesh_iface(char *mesh_iface);
+int check_mesh_iface_ownership(char *mesh_iface, char *hard_iface);
 
 int print_routing_algos(void);
 extern char *line_ptr;
diff --git a/sys.c b/sys.c
index 59cbdae..b524340 100644
--- a/sys.c
+++ b/sys.c
@@ -511,59 +511,3 @@ free_buff:
 out:
 	return res;
 }
-
-int check_mesh_iface(char *mesh_iface)
-{
-	char *base_dev = NULL;
-	char path_buff[PATH_BUFF_LEN];
-	int ret = -1, vid;
-	DIR *dir;
-
-	/* use the parent interface if this is a VLAN */
-	vid = vlan_get_link(mesh_iface, &base_dev);
-	if (vid >= 0)
-		snprintf(path_buff, PATH_BUFF_LEN, SYS_VLAN_PATH, base_dev, vid);
-	else
-		snprintf(path_buff, PATH_BUFF_LEN, SYS_BATIF_PATH_FMT, mesh_iface);
-
-	/* try to open the mesh sys directory */
-	dir = opendir(path_buff);
-	if (!dir)
-		goto out;
-
-	closedir(dir);
-
-	ret = 0;
-out:
-	if (base_dev)
-		free(base_dev);
-
-	return ret;
-}
-
-int check_mesh_iface_ownership(char *mesh_iface, char *hard_iface)
-{
-	char path_buff[PATH_BUFF_LEN];
-	int res;
-
-	/* check if this device actually belongs to the mesh interface */
-	snprintf(path_buff, sizeof(path_buff), SYS_MESH_IFACE_FMT, hard_iface);
-	res = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
-	if (res != EXIT_SUCCESS) {
-		fprintf(stderr, "Error - the directory '%s' could not be read: %s\n",
-			path_buff, strerror(errno));
-		fprintf(stderr, "Is the batman-adv module loaded and sysfs mounted ?\n");
-		return EXIT_FAILURE;
-	}
-
-	if (line_ptr[strlen(line_ptr) - 1] == '\n')
-		line_ptr[strlen(line_ptr) - 1] = '\0';
-
-	if (strcmp(line_ptr, mesh_iface) != 0) {
-		fprintf(stderr, "Error - interface %s is part of batman network %s, not %s\n",
-			hard_iface, line_ptr, mesh_iface);
-		return EXIT_FAILURE;
-	}
-
-	return EXIT_SUCCESS;
-}
diff --git a/sys.h b/sys.h
index be9480e..1365e76 100644
--- a/sys.h
+++ b/sys.h
@@ -74,7 +74,5 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv);
 int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv);
 int handle_gw_setting(char *mesh_iface, int argc, char **argv);
 int handle_ra_setting(int argc, char **argv);
-int check_mesh_iface(char *mesh_iface);
-int check_mesh_iface_ownership(char *mesh_iface, char *hard_iface);
 
 #endif
-- 
2.9.3


  parent reply	other threads:[~2016-10-18 14:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18 14:16 [B.A.T.M.A.N.] [PATCH v3 0/9] batctl: rtnetlink interface manipulation + userspace icmp Sven Eckelmann
2016-10-18 14:17 ` [B.A.T.M.A.N.] [PATCH v3 1/9] batctl: Use rtnl to query list of softif devices Sven Eckelmann
2016-10-18 14:17 ` [B.A.T.M.A.N.] [PATCH v3 2/9] batctl: Add command to create/destroy batman-adv interface Sven Eckelmann
2016-10-18 14:17 ` [B.A.T.M.A.N.] [PATCH v3 3/9] batctl: Use rtnl to add/remove interfaces Sven Eckelmann
2016-10-18 14:17 ` [B.A.T.M.A.N.] [PATCH v3 4/9] batctl: Parse interface arguments relative to last parsed option Sven Eckelmann
2016-10-18 14:17 ` [B.A.T.M.A.N.] [PATCH v3 5/9] batctl: Allow to disable automatic interface create/destroy Sven Eckelmann
2016-10-18 14:17 ` [B.A.T.M.A.N.] [PATCH v3 6/9] batctl: Move interface command to extra file Sven Eckelmann
2016-10-18 14:17 ` Sven Eckelmann [this message]
2016-10-18 14:17 ` [B.A.T.M.A.N.] [PATCH v3 8/9] batctl: Add helper to generate instant random bytes Sven Eckelmann
2016-10-18 14:17 ` [B.A.T.M.A.N.] [PATCH v3 9/9] batctl: Implement non-routing batadv_icmp in userspace Sven Eckelmann
2016-10-24 11:18 ` [B.A.T.M.A.N.] [PATCH v3 0/9] batctl: rtnetlink interface manipulation + userspace icmp Simon Wunderlich

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=20161018141731.7970-7-sven@narfation.org \
    --to=sven@narfation.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox