[batctl] master: batctl: Add helper to generate instant random bytes (98541a8)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batctl
On branch : master
>---------------------------------------------------------------
commit 98541a89ff9946e80e645bb8c30027486cf1eaf9
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Oct 18 16:17:30 2016 +0200
batctl: Add helper to generate instant random bytes
Linux provides different ways to get instant random bytes. These are not
all supported on all systems and thus a fallback may have to be used.
Abstract all this in a single function which can be used from different
parts of the code.
The current implementations are
* get random data from urandom pool via SYS_getrandom syscall
* get random data from reading /dev/urandom
* fallback to per-program prng initialized via the current time (seconds +
nanoseconds)
All are tried in this order in hope to get a high quality random number
source before falling back to some really low quality one.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
98541a89ff9946e80e645bb8c30027486cf1eaf9
functions.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
functions.h | 2 ++
2 files changed, 68 insertions(+)
diff --git a/functions.c b/functions.c
index 66b2d16..abd5882 100644
--- a/functions.c
+++ b/functions.c
@@ -41,6 +41,7 @@
#include <linux/if_link.h>
#include <linux/rtnetlink.h>
#include <linux/neighbour.h>
+#include <sys/syscall.h>
#include <errno.h>
#include <net/if.h>
#include <netlink/socket.h>
@@ -1072,3 +1073,68 @@ int check_mesh_iface_ownership(char *mesh_iface, char *hard_iface)
return EXIT_SUCCESS;
}
+
+static int get_random_bytes_syscall(void *buf __maybe_unused,
+ size_t buflen __maybe_unused)
+{
+#ifdef SYS_getrandom
+ return syscall(SYS_getrandom, buf, buflen, 0);
+#else
+ return -EOPNOTSUPP;
+#endif
+}
+
+static int get_random_bytes_urandom(void *buf, size_t buflen)
+{
+ int fd;
+ ssize_t r;
+
+ fd = open("/dev/urandom", O_RDONLY);
+ if (fd < 0)
+ return -EOPNOTSUPP;
+
+ r = read(fd, buf, buflen);
+ close(fd);
+ if (r < 0)
+ return -EOPNOTSUPP;
+
+ if ((size_t)r != buflen)
+ return -EOPNOTSUPP;
+
+ return 0;
+}
+
+static int get_random_bytes_fallback(void *buf, size_t buflen)
+{
+ struct timespec now;
+ static int initialized = 0;
+ size_t i;
+ uint8_t *bufc = buf;
+
+ /* this is not a good source for randomness */
+ if (!initialized) {
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ srand(now.tv_sec ^ now.tv_nsec);
+ initialized = 1;
+ }
+
+ for (i = 0; i < buflen; i++)
+ bufc[i] = rand() & 0xff;
+
+ return 0;
+}
+
+void get_random_bytes(void *buf, size_t buflen)
+{
+ int ret;
+
+ ret = get_random_bytes_syscall(buf, buflen);
+ if (ret != -EOPNOTSUPP)
+ return;
+
+ ret = get_random_bytes_urandom(buf, buflen);
+ if (ret != -EOPNOTSUPP)
+ return;
+
+ get_random_bytes_fallback(buf, buflen);
+}
diff --git a/functions.h b/functions.h
index e413d6b..95cd6cf 100644
--- a/functions.h
+++ b/functions.h
@@ -53,6 +53,8 @@ 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);
+void get_random_bytes(void *buf, size_t buflen);
+
int print_routing_algos(void);
extern char *line_ptr;
4 years, 2 months
[batctl] master: batctl: Use rtnl to add/remove interfaces (25022e0)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batctl
On branch : master
>---------------------------------------------------------------
commit 25022e0b154db3e9659741093d93e9fb752a3948
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Oct 18 16:17:25 2016 +0200
batctl: Use rtnl to add/remove interfaces
The sysfs interface to add/remove interfaces to/from a batman-adv
soft-interface was downgraded in batman-adv master to a second-class
citizen. This was done because it has conceptional problems (for example
locking of sysfs vs. locking of the network core code). The only direct way
to modify network interfaces is rtnetlink. sysfs still exists but has to
use workers which delay the actual add/del to a later point.
It is therefore prefered to use the modern rtnetlink. Only batman-adv
versions older than v2013.2.0 (Linux 3.10) will not yet support the
rtnl_link operations required for it to work.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
25022e0b154db3e9659741093d93e9fb752a3948
sys.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 145 insertions(+), 27 deletions(-)
diff --git a/sys.c b/sys.c
index c18c6b8..cefd53c 100644
--- a/sys.c
+++ b/sys.c
@@ -199,6 +199,58 @@ static int print_interfaces(char *mesh_iface)
return EXIT_SUCCESS;
}
+struct count_interfaces_rtnl_arg {
+ int ifindex;
+ unsigned int count;
+};
+
+static int count_interfaces_rtnl_parse(struct nl_msg *msg, void *arg)
+{
+ struct count_interfaces_rtnl_arg *count_arg = arg;
+ struct nlattr *attrs[IFLA_MAX + 1];
+ struct ifinfomsg *ifm;
+ int ret;
+ int master;
+
+ ifm = nlmsg_data(nlmsg_hdr(msg));
+ ret = nlmsg_parse(nlmsg_hdr(msg), sizeof(*ifm), attrs, IFLA_MAX,
+ link_policy);
+ if (ret < 0)
+ goto err;
+
+ if (!attrs[IFLA_IFNAME])
+ goto err;
+
+ if (!attrs[IFLA_MASTER])
+ goto err;
+
+ master = nla_get_u32(attrs[IFLA_MASTER]);
+
+ /* required on older kernels which don't prefilter the results */
+ if (master != count_arg->ifindex)
+ goto err;
+
+ count_arg->count++;
+
+err:
+ return NL_OK;
+}
+
+static unsigned int count_interfaces(char *mesh_iface)
+{
+ struct count_interfaces_rtnl_arg count_arg;
+
+ count_arg.count = 0;
+ count_arg.ifindex = if_nametoindex(mesh_iface);
+ if (!count_arg.ifindex)
+ return 0;
+
+ query_rtnl_link(count_arg.ifindex, count_interfaces_rtnl_parse,
+ &count_arg);
+
+ return count_arg.count;
+}
+
static int create_interface(const char *mesh_iface)
{
struct ifinfomsg rt_hdr = {
@@ -283,11 +335,54 @@ err_free_msg:
return err;
}
+static int set_master_interface(const char *iface, unsigned int ifmaster)
+{
+ struct ifinfomsg rt_hdr = {
+ .ifi_family = IFLA_UNSPEC,
+ };
+ struct nl_msg *msg;
+ int err = 0;
+ int ret;
+
+ msg = nlmsg_alloc_simple(RTM_SETLINK, NLM_F_REQUEST | NLM_F_ACK);
+ if (!msg) {
+ return -ENOMEM;
+ }
+
+ ret = nlmsg_append(msg, &rt_hdr, sizeof(rt_hdr), NLMSG_ALIGNTO);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ ret = nla_put_string(msg, IFLA_IFNAME, iface);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ ret = nla_put_u32(msg, IFLA_MASTER, ifmaster);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ err = netlink_simple_request(msg);
+
+err_free_msg:
+ nlmsg_free(msg);
+
+ return err;
+}
+
int interface(char *mesh_iface, int argc, char **argv)
{
- char *path_buff;
- int i, res, optchar;
+ int i, optchar;
int ret;
+ unsigned int ifindex;
+ unsigned int ifmaster;
+ const char *long_op;
+ unsigned int cnt;
while ((optchar = getopt(argc, argv, "h")) != -1) {
switch (optchar) {
@@ -363,46 +458,69 @@ int interface(char *mesh_iface, int argc, char **argv)
break;
}
- path_buff = malloc(PATH_BUFF_LEN);
- if (!path_buff) {
- fprintf(stderr, "Error - could not allocate path buffer: out of memory ?\n");
- goto err;
- }
+ /* get index of batman-adv interface - or try to create it */
+ ifmaster = if_nametoindex(mesh_iface);
+ if (!ifmaster && argv[1][0] == 'a') {
+ ret = create_interface(mesh_iface);
+ if (ret < 0) {
+ fprintf(stderr,
+ "Error - failed to create batman-adv interface: %s\n",
+ strerror(-ret));
+ goto err;
+ }
- for (i = 2; i < argc; i++) {
- snprintf(path_buff, PATH_BUFF_LEN, SYS_MESH_IFACE_FMT, argv[i]);
+ ifmaster = if_nametoindex(mesh_iface);
+ }
- if (!file_exists(path_buff)) {
- snprintf(path_buff, PATH_BUFF_LEN, SYS_IFACE_DIR, argv[i]);
+ if (!ifmaster) {
+ ret = -ENODEV;
+ fprintf(stderr,
+ "Error - failed to find batman-adv interface: %s\n",
+ strerror(-ret));
+ goto err;
+ }
- if (!file_exists(path_buff)) {
- fprintf(stderr, "Error - interface does not exist: %s\n", argv[i]);
- continue;
- }
+ /* make sure that batman-adv is loaded or was loaded by create_interface */
+ if (!file_exists(module_ver_path)) {
+ fprintf(stderr, "Error - batman-adv module has not been loaded\n");
+ goto err;
+ }
- if (!file_exists(module_ver_path)) {
- fprintf(stderr, "Error - batman-adv module has not been loaded\n");
- goto err_buff;
- }
+ for (i = 2; i < argc; i++) {
+ ifindex = if_nametoindex(argv[i]);
- fprintf(stderr, "Error - interface type not supported by batman-adv: %s\n", argv[i]);
+ if (!ifindex) {
+ fprintf(stderr, "Error - interface does not exist: %s\n", argv[i]);
continue;
}
if (argv[1][0] == 'a')
- res = write_file("", path_buff, mesh_iface, NULL);
+ ifindex = ifmaster;
else
- res = write_file("", path_buff, "none", NULL);
+ ifindex = 0;
- if (res != EXIT_SUCCESS)
- goto err_buff;
+ ret = set_master_interface(argv[i], ifindex);
+ if (ret < 0) {
+ if (argv[1][0] == 'a')
+ long_op = "add";
+ else
+ long_op = "delete";
+
+ fprintf(stderr, "Error - failed to %s interface %s: %s\n",
+ long_op, argv[i], strerror(-ret));
+ goto err;
+ }
+ }
+
+ /* check if there is no interface left and then destroy mesh_iface */
+ if (argv[1][0] == 'd') {
+ cnt = count_interfaces(mesh_iface);
+ if (cnt == 0)
+ destroy_interface(mesh_iface);
}
- free(path_buff);
return EXIT_SUCCESS;
-err_buff:
- free(path_buff);
err:
return EXIT_FAILURE;
}
4 years, 2 months
[batctl] master: batctl: Parse interface arguments relative to last parsed option (611e5af)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batctl
On branch : master
>---------------------------------------------------------------
commit 611e5af1cd6de307aa1147454aebdb18aec101f9
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Oct 18 16:17:26 2016 +0200
batctl: Parse interface arguments relative to last parsed option
Arguments may be added between "interface" and the subcommands "add" and
"del". Thus is should not be hardcoded which positions of argv the
subcommands start and instead the information from getopt should be used to
calculate the correct position.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
611e5af1cd6de307aa1147454aebdb18aec101f9
sys.c | 51 ++++++++++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/sys.c b/sys.c
index cefd53c..190fd06 100644
--- a/sys.c
+++ b/sys.c
@@ -383,6 +383,8 @@ int interface(char *mesh_iface, int argc, char **argv)
unsigned int ifmaster;
const char *long_op;
unsigned int cnt;
+ int rest_argc;
+ char **rest_argv;
while ((optchar = getopt(argc, argv, "h")) != -1) {
switch (optchar) {
@@ -395,38 +397,41 @@ int interface(char *mesh_iface, int argc, char **argv)
}
}
- if (argc == 1)
+ rest_argc = argc - optind;
+ rest_argv = &argv[optind];
+
+ if (rest_argc == 0)
return print_interfaces(mesh_iface);
- if ((strcmp(argv[1], "add") != 0) && (strcmp(argv[1], "a") != 0) &&
- (strcmp(argv[1], "del") != 0) && (strcmp(argv[1], "d") != 0) &&
- (strcmp(argv[1], "create") != 0) && (strcmp(argv[1], "c") != 0) &&
- (strcmp(argv[1], "destroy") != 0) && (strcmp(argv[1], "D") != 0)) {
- fprintf(stderr, "Error - unknown argument specified: %s\n", argv[1]);
+ if ((strcmp(rest_argv[0], "add") != 0) && (strcmp(rest_argv[0], "a") != 0) &&
+ (strcmp(rest_argv[0], "del") != 0) && (strcmp(rest_argv[0], "d") != 0) &&
+ (strcmp(rest_argv[0], "create") != 0) && (strcmp(rest_argv[0], "c") != 0) &&
+ (strcmp(rest_argv[0], "destroy") != 0) && (strcmp(rest_argv[0], "D") != 0)) {
+ fprintf(stderr, "Error - unknown argument specified: %s\n", rest_argv[0]);
interface_usage();
goto err;
}
- if (strcmp(argv[1], "destroy") == 0)
- argv[1][0] = 'D';
+ if (strcmp(rest_argv[0], "destroy") == 0)
+ rest_argv[0][0] = 'D';
- switch (argv[1][0]) {
+ switch (rest_argv[0][0]) {
case 'a':
case 'd':
- if (argc == 2) {
+ if (rest_argc == 1) {
fprintf(stderr,
"Error - missing interface name(s) after '%s'\n",
- argv[1]);
+ rest_argv[0]);
interface_usage();
goto err;
}
break;
case 'c':
case 'D':
- if (argc != 2) {
+ if (rest_argc != 1) {
fprintf(stderr,
"Error - extra parameter after '%s'\n",
- argv[1]);
+ rest_argv[0]);
interface_usage();
goto err;
}
@@ -435,7 +440,7 @@ int interface(char *mesh_iface, int argc, char **argv)
break;
}
- switch (argv[1][0]) {
+ switch (rest_argv[0][0]) {
case 'c':
ret = create_interface(mesh_iface);
if (ret < 0) {
@@ -460,7 +465,7 @@ int interface(char *mesh_iface, int argc, char **argv)
/* get index of batman-adv interface - or try to create it */
ifmaster = if_nametoindex(mesh_iface);
- if (!ifmaster && argv[1][0] == 'a') {
+ if (!ifmaster && rest_argv[0][0] == 'a') {
ret = create_interface(mesh_iface);
if (ret < 0) {
fprintf(stderr,
@@ -486,34 +491,34 @@ int interface(char *mesh_iface, int argc, char **argv)
goto err;
}
- for (i = 2; i < argc; i++) {
- ifindex = if_nametoindex(argv[i]);
+ for (i = 1; i < rest_argc; i++) {
+ ifindex = if_nametoindex(rest_argv[i]);
if (!ifindex) {
- fprintf(stderr, "Error - interface does not exist: %s\n", argv[i]);
+ fprintf(stderr, "Error - interface does not exist: %s\n", rest_argv[i]);
continue;
}
- if (argv[1][0] == 'a')
+ if (rest_argv[0][0] == 'a')
ifindex = ifmaster;
else
ifindex = 0;
- ret = set_master_interface(argv[i], ifindex);
+ ret = set_master_interface(rest_argv[i], ifindex);
if (ret < 0) {
- if (argv[1][0] == 'a')
+ if (rest_argv[0][0] == 'a')
long_op = "add";
else
long_op = "delete";
fprintf(stderr, "Error - failed to %s interface %s: %s\n",
- long_op, argv[i], strerror(-ret));
+ long_op, rest_argv[i], strerror(-ret));
goto err;
}
}
/* check if there is no interface left and then destroy mesh_iface */
- if (argv[1][0] == 'd') {
+ if (rest_argv[0][0] == 'd') {
cnt = count_interfaces(mesh_iface);
if (cnt == 0)
destroy_interface(mesh_iface);
4 years, 2 months
[batctl] master: batctl: Allow to disable automatic interface create/destroy (4cbd15d)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batctl
On branch : master
>---------------------------------------------------------------
commit 4cbd15d1049a7937193d5c95dc49e1c56d79e410
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Oct 18 16:17:27 2016 +0200
batctl: Allow to disable automatic interface create/destroy
Users may not want to lose their configured batman-adv soft-interface when
they remove a single interface from it. The default configuration may not
working well enough in the network setup of the user and thus it should be
possible to avoid that it gets reset to it when a new interface is added
after the last one was removed.
This can be done by avoiding automatic creation of an interface when the
command "add" is used together with the option "-M". The add would fail
when the soft-interface disappeared for some reason and thus the
soft-interface would not be created again with the default configuration.
But more importantly, the "del" command can be informed with the option
"-M" to not try to remove the soft-interface in the first place.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
4cbd15d1049a7937193d5c95dc49e1c56d79e410
man/batctl.8 | 4 +++-
sys.c | 12 +++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/man/batctl.8 b/man/batctl.8
index 37b5632..9ee0e31 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -52,10 +52,12 @@ performances, is also included.
.br
.TP
.I \fBcommands:
-.IP "\fBinterface\fP|\fBif\fP [\fBadd\fP|\fBdel iface(s)\fP]"
+.IP "\fBinterface\fP|\fBif\fP [\fB-M\fP] [\fBadd\fP|\fBdel iface(s)\fP]"
If no parameter is given or the first parameter is neither "add" nor "del" the current interface settings are displayed.
In order to add or delete interfaces specify "add" or "del" as first argument and append the interface names you wish to
add or delete. Multiple interfaces can be specified.
+The "\-M" option tells batctl to not automatically create the batman-adv interface on "add" or to destroy it when "del"
+removed all interfaces which belonged to it.
.IP "\fBinterface\fP|\fBif\fP [\fBcreate\fP|\fBdestroy\fP]"
A batman-adv interface without attached interfaces can be created using "create". The parameter "destroy" can be used to
free all attached interfaces and remove batman-adv interface.
diff --git a/sys.c b/sys.c
index 190fd06..2cbccea 100644
--- a/sys.c
+++ b/sys.c
@@ -22,6 +22,7 @@
#include <unistd.h>
#include <stdio.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -122,6 +123,7 @@ static void interface_usage(void)
fprintf(stderr, "Usage: batctl [options] interface [parameters] [add|del iface(s)]\n");
fprintf(stderr, " batctl [options] interface [parameters] [create|destroy]\n");
fprintf(stderr, "parameters:\n");
+ fprintf(stderr, " \t -M disable automatic creation/removal of batman-adv interface\n");
fprintf(stderr, " \t -h print this help\n");
}
@@ -385,12 +387,16 @@ int interface(char *mesh_iface, int argc, char **argv)
unsigned int cnt;
int rest_argc;
char **rest_argv;
+ bool manual_mode = false;
- while ((optchar = getopt(argc, argv, "h")) != -1) {
+ while ((optchar = getopt(argc, argv, "hM")) != -1) {
switch (optchar) {
case 'h':
interface_usage();
return EXIT_SUCCESS;
+ case 'M':
+ manual_mode = true;
+ break;
default:
interface_usage();
return EXIT_FAILURE;
@@ -465,7 +471,7 @@ int interface(char *mesh_iface, int argc, char **argv)
/* get index of batman-adv interface - or try to create it */
ifmaster = if_nametoindex(mesh_iface);
- if (!ifmaster && rest_argv[0][0] == 'a') {
+ if (!manual_mode && !ifmaster && rest_argv[0][0] == 'a') {
ret = create_interface(mesh_iface);
if (ret < 0) {
fprintf(stderr,
@@ -518,7 +524,7 @@ int interface(char *mesh_iface, int argc, char **argv)
}
/* check if there is no interface left and then destroy mesh_iface */
- if (rest_argv[0][0] == 'd') {
+ if (!manual_mode && rest_argv[0][0] == 'd') {
cnt = count_interfaces(mesh_iface);
if (cnt == 0)
destroy_interface(mesh_iface);
4 years, 2 months
[batctl] master: batctl: Use rtnl to query list of softif devices (60e519b)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batctl
On branch : master
>---------------------------------------------------------------
commit 60e519bfeaa3c37f4790ebf2f75b1dd642167103
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Oct 18 16:17:23 2016 +0200
batctl: Use rtnl to query list of softif devices
The normal way of network related programs to query the state of interfaces
is to use the rtnetlink. Most of these data can also be queried via sysfs
but it is easier to use the same way for both retrieving the list of
interfaces and modifying the list of interfaces.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
60e519bfeaa3c37f4790ebf2f75b1dd642167103
functions.c | 64 +++++++++++++++++++++++++++++++++++
functions.h | 5 ++-
sys.c | 111 +++++++++++++++++++++++++++++++++---------------------------
3 files changed, 129 insertions(+), 51 deletions(-)
diff --git a/functions.c b/functions.c
index 92de8e3..8470b49 100644
--- a/functions.c
+++ b/functions.c
@@ -37,6 +37,7 @@
#include <stdint.h>
#include <linux/netlink.h>
#include <net/ethernet.h>
+#include <linux/if_link.h>
#include <linux/rtnetlink.h>
#include <linux/neighbour.h>
#include <errno.h>
@@ -890,3 +891,66 @@ int print_routing_algos(void)
err = debug_print_routing_algos();
return err;
}
+
+int query_rtnl_link(int ifindex, nl_recvmsg_msg_cb_t func, void *arg)
+{
+ struct ifinfomsg rt_hdr = {
+ .ifi_family = IFLA_UNSPEC,
+ };
+ struct nl_sock *sock;
+ struct nl_msg *msg;
+ struct nl_cb *cb;
+ int err = 0;
+ int ret;
+
+ sock = nl_socket_alloc();
+ if (!sock)
+ return -ENOMEM;
+
+ ret = nl_connect(sock, NETLINK_ROUTE);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_sock;
+ }
+
+ cb = nl_cb_alloc(NL_CB_DEFAULT);
+ if (!cb) {
+ err = -ENOMEM;
+ goto err_free_sock;
+ }
+
+ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, func, arg);
+
+ msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST | NLM_F_DUMP);
+ if (!msg) {
+ err = -ENOMEM;
+ goto err_free_cb;
+ }
+
+ ret = nlmsg_append(msg, &rt_hdr, sizeof(rt_hdr), NLMSG_ALIGNTO);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ ret = nla_put_u32(msg, IFLA_MASTER, ifindex);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ ret = nl_send_auto_complete(sock, msg);
+ if (ret < 0)
+ goto err_free_msg;
+
+ nl_recvmsgs(sock, cb);
+
+err_free_msg:
+ nlmsg_free(msg);
+err_free_cb:
+ nl_cb_put(cb);
+err_free_sock:
+ nl_socket_free(sock);
+
+ return err;
+}
diff --git a/functions.h b/functions.h
index e24dea0..a6090b6 100644
--- a/functions.h
+++ b/functions.h
@@ -23,6 +23,8 @@
#define _BATCTL_FUNCTIONS_H
#include <net/ethernet.h>
+#include <netlink/netlink.h>
+#include <netlink/handlers.h>
#include <stddef.h>
@@ -43,7 +45,8 @@ int write_file(const char *dir, const char *fname, const char *arg1,
struct ether_addr *translate_mac(const char *mesh_iface,
const struct ether_addr *mac);
struct ether_addr *resolve_mac(const char *asc);
-int vlan_get_link(const char *ifname, char **parent);
+int vlan_get_link(const char *ifname, char **parent);\
+int query_rtnl_link(int ifindex, nl_recvmsg_msg_cb_t func, void *arg);
int print_routing_algos(void);
extern char *line_ptr;
diff --git a/sys.c b/sys.c
index ca837f6..0140b28 100644
--- a/sys.c
+++ b/sys.c
@@ -26,6 +26,11 @@
#include <string.h>
#include <errno.h>
#include <dirent.h>
+#include <net/if.h>
+#include <linux/if_link.h>
+#include <netlink/netlink.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
#include "main.h"
#include "sys.h"
@@ -119,72 +124,78 @@ static void interface_usage(void)
fprintf(stderr, " \t -h print this help\n");
}
-static int print_interfaces(char *mesh_iface)
-{
- DIR *iface_base_dir;
- struct dirent *iface_dir;
- char *path_buff;
- int res;
+static struct nla_policy link_policy[IFLA_MAX + 1] = {
+ [IFLA_IFNAME] = { .type = NLA_STRING, .maxlen = IFNAMSIZ },
+ [IFLA_MASTER] = { .type = NLA_U32 },
+};
- if (!file_exists(module_ver_path)) {
- fprintf(stderr, "Error - batman-adv module has not been loaded\n");
+struct print_interfaces_rtnl_arg {
+ int ifindex;
+};
+
+static int print_interfaces_rtnl_parse(struct nl_msg *msg, void *arg)
+{
+ struct print_interfaces_rtnl_arg *print_arg = arg;
+ struct nlattr *attrs[IFLA_MAX + 1];
+ char path_buff[PATH_BUFF_LEN];
+ struct ifinfomsg *ifm;
+ char *ifname;
+ int ret;
+ const char *status;
+ int master;
+
+ ifm = nlmsg_data(nlmsg_hdr(msg));
+ ret = nlmsg_parse(nlmsg_hdr(msg), sizeof(*ifm), attrs, IFLA_MAX,
+ link_policy);
+ if (ret < 0)
goto err;
- }
- path_buff = malloc(PATH_BUFF_LEN);
- if (!path_buff) {
- fprintf(stderr, "Error - could not allocate path buffer: out of memory ?\n");
+ if (!attrs[IFLA_IFNAME])
goto err;
- }
- iface_base_dir = opendir(SYS_IFACE_PATH);
- if (!iface_base_dir) {
- fprintf(stderr, "Error - the directory '%s' could not be read: %s\n",
- SYS_IFACE_PATH, strerror(errno));
- fprintf(stderr, "Is the batman-adv module loaded and sysfs mounted ?\n");
- goto err_buff;
- }
+ if (!attrs[IFLA_MASTER])
+ goto err;
- while ((iface_dir = readdir(iface_base_dir)) != NULL) {
- snprintf(path_buff, PATH_BUFF_LEN, SYS_MESH_IFACE_FMT, iface_dir->d_name);
- res = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
- if (res != EXIT_SUCCESS)
- continue;
+ ifname = nla_get_string(attrs[IFLA_IFNAME]);
+ master = nla_get_u32(attrs[IFLA_MASTER]);
- if (line_ptr[strlen(line_ptr) - 1] == '\n')
- line_ptr[strlen(line_ptr) - 1] = '\0';
+ /* required on older kernels which don't prefilter the results */
+ if (master != print_arg->ifindex)
+ goto err;
- if (strcmp(line_ptr, "none") == 0)
- goto free_line;
+ snprintf(path_buff, sizeof(path_buff), SYS_IFACE_STATUS_FMT, ifname);
+ ret = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
+ if (ret != EXIT_SUCCESS)
+ status = "<error reading status>\n";
+ else
+ status = line_ptr;
- if (strcmp(line_ptr, mesh_iface) != 0)
- goto free_line;
+ printf("%s: %s", ifname, status);
- free(line_ptr);
- line_ptr = NULL;
+ free(line_ptr);
+ line_ptr = NULL;
- snprintf(path_buff, PATH_BUFF_LEN, SYS_IFACE_STATUS_FMT, iface_dir->d_name);
- res = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
- if (res != EXIT_SUCCESS) {
- fprintf(stderr, "<error reading status>\n");
- continue;
- }
+err:
+ return NL_OK;
+}
- printf("%s: %s", iface_dir->d_name, line_ptr);
+static int print_interfaces(char *mesh_iface)
+{
+ struct print_interfaces_rtnl_arg print_arg;
-free_line:
- free(line_ptr);
- line_ptr = NULL;
+ if (!file_exists(module_ver_path)) {
+ fprintf(stderr, "Error - batman-adv module has not been loaded\n");
+ return EXIT_FAILURE;
}
- free(path_buff);
- closedir(iface_base_dir);
- return EXIT_SUCCESS;
+ print_arg.ifindex = if_nametoindex(mesh_iface);
+ if (!print_arg.ifindex)
+ return EXIT_FAILURE;
-err_buff:
- free(path_buff);
-err:
- return EXIT_FAILURE;
+ query_rtnl_link(print_arg.ifindex, print_interfaces_rtnl_parse,
+ &print_arg);
+
+ return EXIT_SUCCESS;
}
int interface(char *mesh_iface, int argc, char **argv)
4 years, 2 months
[batctl] master: batctl: Add command to create/destroy batman-adv interface (dd2bbe1)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batctl
On branch : master
>---------------------------------------------------------------
commit dd2bbe1827800b974f0760352aed819907c70b8a
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Oct 18 16:17:24 2016 +0200
batctl: Add command to create/destroy batman-adv interface
The command "create" can be used to create a batman-adv interface without
any interface attached. This is helpful when the interfaces should be
configured independently of the first attached interface.
The command "destroy" can be used to destroy a batman-adv interface without
going through all attached interfaces and delete them manually.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
dd2bbe1827800b974f0760352aed819907c70b8a
functions.c | 59 ++++++++++++++++++++++++
functions.h | 1 +
man/batctl.8 | 3 ++
sys.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 201 insertions(+), 5 deletions(-)
diff --git a/functions.c b/functions.c
index 8470b49..85482b4 100644
--- a/functions.c
+++ b/functions.c
@@ -954,3 +954,62 @@ err_free_sock:
return err;
}
+
+static int ack_errno_handler(struct sockaddr_nl *nla __maybe_unused,
+ struct nlmsgerr *nlerr,
+ void *arg)
+{
+ int *err = arg;
+
+ *err = nlerr->error;
+
+ return NL_STOP;
+}
+
+static int ack_wait_handler(struct nl_msg *msg __maybe_unused,
+ void *arg __maybe_unused)
+{
+ return NL_STOP;
+}
+
+int netlink_simple_request(struct nl_msg *msg)
+{
+ struct nl_sock *sock;
+ struct nl_cb *cb;
+ int err = 0;
+ int ret;
+
+ sock = nl_socket_alloc();
+ if (!sock)
+ return -ENOMEM;
+
+ ret = nl_connect(sock, NETLINK_ROUTE);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_sock;
+ }
+
+ cb = nl_cb_alloc(NL_CB_DEFAULT);
+ if (!cb) {
+ err = -ENOMEM;
+ goto err_free_sock;
+ }
+
+ nl_cb_err(cb, NL_CB_CUSTOM, ack_errno_handler, &err);
+ nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_wait_handler, NULL);
+
+ ret = nl_send_auto_complete(sock, msg);
+ if (ret < 0)
+ goto err_free_cb;
+
+ // ack_errno_handler sets err on errors
+ err = 0;
+ nl_recvmsgs(sock, cb);
+
+err_free_cb:
+ nl_cb_put(cb);
+err_free_sock:
+ nl_socket_free(sock);
+
+ return err;
+}
diff --git a/functions.h b/functions.h
index a6090b6..7757731 100644
--- a/functions.h
+++ b/functions.h
@@ -47,6 +47,7 @@ struct ether_addr *translate_mac(const char *mesh_iface,
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 print_routing_algos(void);
extern char *line_ptr;
diff --git a/man/batctl.8 b/man/batctl.8
index d5a5ce0..37b5632 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -56,6 +56,9 @@ performances, is also included.
If no parameter is given or the first parameter is neither "add" nor "del" the current interface settings are displayed.
In order to add or delete interfaces specify "add" or "del" as first argument and append the interface names you wish to
add or delete. Multiple interfaces can be specified.
+.IP "\fBinterface\fP|\fBif\fP [\fBcreate\fP|\fBdestroy\fP]"
+A batman-adv interface without attached interfaces can be created using "create". The parameter "destroy" can be used to
+free all attached interfaces and remove batman-adv interface.
.br
.IP "\fBorig_interval\fP|\fBit\fP [\fBinterval\fP]"
If no parameter is given the current originator interval setting is displayed otherwise the parameter is used to set the
diff --git a/sys.c b/sys.c
index 0140b28..c18c6b8 100644
--- a/sys.c
+++ b/sys.c
@@ -120,6 +120,7 @@ const struct settings_data batctl_settings[BATCTL_SETTINGS_NUM] = {
static void interface_usage(void)
{
fprintf(stderr, "Usage: batctl [options] interface [parameters] [add|del iface(s)]\n");
+ fprintf(stderr, " batctl [options] interface [parameters] [create|destroy]\n");
fprintf(stderr, "parameters:\n");
fprintf(stderr, " \t -h print this help\n");
}
@@ -198,10 +199,95 @@ static int print_interfaces(char *mesh_iface)
return EXIT_SUCCESS;
}
+static int create_interface(const char *mesh_iface)
+{
+ struct ifinfomsg rt_hdr = {
+ .ifi_family = IFLA_UNSPEC,
+ };
+ struct nlattr *linkinfo;
+ struct nl_msg *msg;
+ int err = 0;
+ int ret;
+
+ msg = nlmsg_alloc_simple(RTM_NEWLINK,
+ NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL | NLM_F_ACK);
+ if (!msg) {
+ return -ENOMEM;
+ }
+
+ ret = nlmsg_append(msg, &rt_hdr, sizeof(rt_hdr), NLMSG_ALIGNTO);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ ret = nla_put_string(msg, IFLA_IFNAME, mesh_iface);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ linkinfo = nla_nest_start(msg, IFLA_LINKINFO);
+ if (!linkinfo) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ ret = nla_put_string(msg, IFLA_INFO_KIND, "batadv");
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ nla_nest_end(msg, linkinfo);
+
+ err = netlink_simple_request(msg);
+
+err_free_msg:
+ nlmsg_free(msg);
+
+ return err;
+}
+
+static int destroy_interface(const char *mesh_iface)
+{
+ struct ifinfomsg rt_hdr = {
+ .ifi_family = IFLA_UNSPEC,
+ };
+ struct nl_msg *msg;
+ int err = 0;
+ int ret;
+
+ msg = nlmsg_alloc_simple(RTM_DELLINK, NLM_F_REQUEST | NLM_F_ACK);
+ if (!msg) {
+ return -ENOMEM;
+ }
+
+ ret = nlmsg_append(msg, &rt_hdr, sizeof(rt_hdr), NLMSG_ALIGNTO);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ ret = nla_put_string(msg, IFLA_IFNAME, mesh_iface);
+ if (ret < 0) {
+ err = -ENOMEM;
+ goto err_free_msg;
+ }
+
+ err = netlink_simple_request(msg);
+
+err_free_msg:
+ nlmsg_free(msg);
+
+ return err;
+}
+
int interface(char *mesh_iface, int argc, char **argv)
{
char *path_buff;
int i, res, optchar;
+ int ret;
while ((optchar = getopt(argc, argv, "h")) != -1) {
switch (optchar) {
@@ -218,16 +304,63 @@ int interface(char *mesh_iface, int argc, char **argv)
return print_interfaces(mesh_iface);
if ((strcmp(argv[1], "add") != 0) && (strcmp(argv[1], "a") != 0) &&
- (strcmp(argv[1], "del") != 0) && (strcmp(argv[1], "d") != 0)) {
+ (strcmp(argv[1], "del") != 0) && (strcmp(argv[1], "d") != 0) &&
+ (strcmp(argv[1], "create") != 0) && (strcmp(argv[1], "c") != 0) &&
+ (strcmp(argv[1], "destroy") != 0) && (strcmp(argv[1], "D") != 0)) {
fprintf(stderr, "Error - unknown argument specified: %s\n", argv[1]);
interface_usage();
goto err;
}
- if (argc == 2) {
- fprintf(stderr, "Error - missing interface name(s) after '%s'\n", argv[1]);
- interface_usage();
- goto err;
+ if (strcmp(argv[1], "destroy") == 0)
+ argv[1][0] = 'D';
+
+ switch (argv[1][0]) {
+ case 'a':
+ case 'd':
+ if (argc == 2) {
+ fprintf(stderr,
+ "Error - missing interface name(s) after '%s'\n",
+ argv[1]);
+ interface_usage();
+ goto err;
+ }
+ break;
+ case 'c':
+ case 'D':
+ if (argc != 2) {
+ fprintf(stderr,
+ "Error - extra parameter after '%s'\n",
+ argv[1]);
+ interface_usage();
+ goto err;
+ }
+ break;
+ default:
+ break;
+ }
+
+ switch (argv[1][0]) {
+ case 'c':
+ ret = create_interface(mesh_iface);
+ if (ret < 0) {
+ fprintf(stderr,
+ "Error - failed to create batman-adv interface: %s\n",
+ strerror(-ret));
+ goto err;
+ }
+ return EXIT_SUCCESS;
+ case 'D':
+ ret = destroy_interface(mesh_iface);
+ if (ret < 0) {
+ fprintf(stderr,
+ "Error - failed to destroy batman-adv interface: %s\n",
+ strerror(-ret));
+ goto err;
+ }
+ return EXIT_SUCCESS;
+ default:
+ break;
}
path_buff = malloc(PATH_BUFF_LEN);
4 years, 2 months
[batman-adv] master: batman-adv: compat: Move get_link_net patch to coccinelle (3b79cd3)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 3b79cd3d9b3eb920d17233b5270ee7162d55587e
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Oct 18 15:57:42 2016 +0200
batman-adv: compat: Move get_link_net patch to coccinelle
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
3b79cd3d9b3eb920d17233b5270ee7162d55587e
compat-patches/0004-get_link_net.cocci | 13 +++++++++++++
compat.h | 7 -------
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/compat-patches/0004-get_link_net.cocci b/compat-patches/0004-get_link_net.cocci
new file mode 100644
index 0000000..1ae3192
--- /dev/null
+++ b/compat-patches/0004-get_link_net.cocci
@@ -0,0 +1,13 @@
+@@
+identifier netdev, fallback_net;
+@@
+
+ static const struct net *batadv_getlink_net(const struct net_device *netdev,
+ const struct net *fallback_net)
+ {
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
++ return fallback_net;
++#else
+ ...
++#endif
+ }
diff --git a/compat.h b/compat.h
index 245621f..2865eeb 100644
--- a/compat.h
+++ b/compat.h
@@ -145,11 +145,4 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
#endif /* < KERNEL_VERSION(3, 15, 0) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
-
-/* WARNING for batadv_getlink_net */
-#define get_link_net get_xstats_size || 1 || netdev->rtnl_link_ops->get_xstats_size
-
-#endif /* < KERNEL_VERSION(4, 0, 0) */
-
#endif /* _NET_BATMAN_ADV_COMPAT_H_ */
4 years, 2 months
[batman-adv] master: batman-adv: compat: Move vid api wrapper to coccinelle (7f40f38)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 7f40f382af1125698ad149d1b743c2de70a5ad5c
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Oct 18 15:57:43 2016 +0200
batman-adv: compat: Move vid api wrapper to coccinelle
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
7f40f382af1125698ad149d1b743c2de70a5ad5c
compat-include/linux/netdevice.h | 6 +++
compat-patches/0005-vid-callbacks.cocci | 74 +++++++++++++++++++++++++++++++++
compat.h | 54 ------------------------
3 files changed, 80 insertions(+), 54 deletions(-)
diff --git a/compat-include/linux/netdevice.h b/compat-include/linux/netdevice.h
index e71e614..0536549 100644
--- a/compat-include/linux/netdevice.h
+++ b/compat-include/linux/netdevice.h
@@ -28,6 +28,12 @@
#include <linux/netdev_features.h>
+#define __vid_api_returntype void
+
+#else
+
+#define __vid_api_returntype int
+
#endif /* < KERNEL_VERSION(3, 3, 0) */
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
diff --git a/compat-patches/0005-vid-callbacks.cocci b/compat-patches/0005-vid-callbacks.cocci
new file mode 100644
index 0000000..2cebc0e
--- /dev/null
+++ b/compat-patches/0005-vid-callbacks.cocci
@@ -0,0 +1,74 @@
+@ add_assignment @
+identifier batadv_interface_add_vid, batadv_netdev_ops;
+@@
+
+ struct net_device_ops batadv_netdev_ops = {
+ .ndo_vlan_rx_add_vid = batadv_interface_add_vid,
+ };
+
+@ kill_assignment @
+identifier batadv_interface_kill_vid, batadv_netdev_ops;
+@@
+
+ struct net_device_ops batadv_netdev_ops = {
+ .ndo_vlan_rx_kill_vid = batadv_interface_kill_vid,
+ };
+
+@ add_vid @
+identifier add_assignment.batadv_interface_add_vid;
+type be16;
+identifier dev, proto, vid;
+@@
+
+-batadv_interface_add_vid
++batadv_interface_add_vid_orig
+ (struct net_device *dev, be16 proto,
+ unsigned short vid)
+ { ... }
+
++static __vid_api_returntype batadv_interface_add_vid(struct net_device *dev,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
++ be16 proto,
++#endif
++ unsigned short vid)
++{
++#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
++ be16 proto = htons(ETH_P_8021Q);
++#endif
++
++#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
++ batadv_interface_add_vid_orig(dev, proto, vid);
++#else
++ return batadv_interface_add_vid_orig(dev, proto, vid);
++#endif
++}
+
+
+@ kill_vid @
+identifier kill_assignment.batadv_interface_kill_vid;
+type be16;
+identifier dev, proto, vid;
+@@
+
+-batadv_interface_kill_vid
++batadv_interface_kill_vid_orig
+ (struct net_device *dev, be16 proto,
+ unsigned short vid)
+ { ... }
+
++static __vid_api_returntype batadv_interface_kill_vid(struct net_device *dev,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
++ be16 proto,
++#endif
++ unsigned short vid)
++{
++#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
++ be16 proto = htons(ETH_P_8021Q);
++#endif
++
++#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
++ batadv_interface_kill_vid_orig(dev, proto, vid);
++#else
++ return batadv_interface_kill_vid_orig(dev, proto, vid);
++#endif
++}
diff --git a/compat.h b/compat.h
index 2865eeb..d59fb5f 100644
--- a/compat.h
+++ b/compat.h
@@ -42,31 +42,6 @@
#endif /* < KERNEL_VERSION(3, 9, 0) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
-
-#define batadv_interface_add_vid(x, y, z) \
-__batadv_interface_add_vid(struct net_device *dev, __be16 proto,\
- unsigned short vid);\
-static void batadv_interface_add_vid(struct net_device *dev, unsigned short vid)\
-{\
- __batadv_interface_add_vid(dev, htons(ETH_P_8021Q), vid);\
-}\
-static int __batadv_interface_add_vid(struct net_device *dev, __be16 proto,\
- unsigned short vid)
-
-#define batadv_interface_kill_vid(x, y, z) \
-__batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
- unsigned short vid);\
-static void batadv_interface_kill_vid(struct net_device *dev,\
- unsigned short vid)\
-{\
- __batadv_interface_kill_vid(dev, htons(ETH_P_8021Q), vid);\
-}\
-static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
- unsigned short vid)
-
-#endif /* < KERNEL_VERSION(3, 3, 0) */
-
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
#define batadv_interface_set_mac_addr(x, y) \
@@ -95,35 +70,6 @@ static int __batadv_interface_tx(struct sk_buff *skb, \
#endif /* < KERNEL_VERSION(3, 9, 0) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)
-
-#define batadv_interface_add_vid(x, y, z) \
-__batadv_interface_add_vid(struct net_device *dev, __be16 proto,\
- unsigned short vid);\
-static int batadv_interface_add_vid(struct net_device *dev, unsigned short vid)\
-{\
- return __batadv_interface_add_vid(dev, htons(ETH_P_8021Q), vid);\
-}\
-static int __batadv_interface_add_vid(struct net_device *dev, __be16 proto,\
- unsigned short vid)
-
-#define batadv_interface_kill_vid(x, y, z) \
-__batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
- unsigned short vid);\
-static int batadv_interface_kill_vid(struct net_device *dev,\
- unsigned short vid)\
-{\
- return __batadv_interface_kill_vid(dev, htons(ETH_P_8021Q), vid);\
-}\
-static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
- unsigned short vid)
-
-#endif /* >= KERNEL_VERSION(3, 3, 0) */
-
-#endif /* < KERNEL_VERSION(3, 10, 0) */
-
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
/* the expected behaviour of this function is to return 0 on success, therefore
4 years, 2 months
[batman-adv] master: batman-adv: Remove replacement compat script (684d4ca)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 684d4cad930d979026f5e3ffc0af587f488b7e24
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Oct 18 15:57:40 2016 +0200
batman-adv: Remove replacement compat script
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
684d4cad930d979026f5e3ffc0af587f488b7e24
Makefile | 3 +--
compat-patches/replacements.sh | 3 ---
2 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 99e67da..7eea0ab 100644
--- a/Makefile
+++ b/Makefile
@@ -107,7 +107,7 @@ install: config $(SOURCE_STAMP)
config:
$(PWD)/gen-compat-autoconf.sh $(PWD)/compat-autoconf.h
-$(SOURCE_STAMP): $(SOURCE) compat-patches/* compat-patches/replacements.sh
+$(SOURCE_STAMP): $(SOURCE) compat-patches/*
$(MKDIR) $(BUILD_DIR)/net/batman-adv/
@$(RM) $(SOURCE_BUILD)
@$(CP) $(SOURCE) $(BUILD_DIR)/net/batman-adv/
@@ -124,7 +124,6 @@ $(SOURCE_STAMP): $(SOURCE) compat-patches/* compat-patches/replacements.sh
$(SPATCH) $(SPATCH_FLAGS) --dir $(BUILD_DIR) --sp-file compat-patches/$${i} > /dev/null; \
fi; \
done
- compat-patches/replacements.sh
touch $(SOURCE_STAMP)
.PHONY: all clean install config
diff --git a/compat-patches/replacements.sh b/compat-patches/replacements.sh
deleted file mode 100755
index c7875c0..0000000
--- a/compat-patches/replacements.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#! /bin/sh
-
-set -e
4 years, 2 months
[batman-adv] master: batman-adv: compat: Replace IFF_NO_QUEUE with coccinelle (541c087)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 541c087012bd6b57d37f041aedc4d0b4440a96d1
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Oct 18 15:57:41 2016 +0200
batman-adv: compat: Replace IFF_NO_QUEUE with coccinelle
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
541c087012bd6b57d37f041aedc4d0b4440a96d1
compat-patches/0003-iff-no-queue.cocci | 9 +++++++++
compat.h | 6 ------
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/compat-patches/0003-iff-no-queue.cocci b/compat-patches/0003-iff-no-queue.cocci
new file mode 100644
index 0000000..9c95b85
--- /dev/null
+++ b/compat-patches/0003-iff-no-queue.cocci
@@ -0,0 +1,9 @@
+@@
+expression E;
+@@
+
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)
+ E->priv_flags |= IFF_NO_QUEUE;
++#else
++E->tx_queue_len = 0;
++#endif
diff --git a/compat.h b/compat.h
index 78de7ea..245621f 100644
--- a/compat.h
+++ b/compat.h
@@ -152,10 +152,4 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
#endif /* < KERNEL_VERSION(4, 0, 0) */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
-
-#define IFF_NO_QUEUE 0; dev->tx_queue_len = 0
-
-#endif /* < KERNEL_VERSION(4, 3, 0) */
-
#endif /* _NET_BATMAN_ADV_COMPAT_H_ */
4 years, 2 months