[linux-merge]linux integration; annotated tag, v4.7-rc1, created. v4.7-rc1
by postmaster@open-mesh.org
The annotated tag, v4.7-rc1 has been created
at 2fa60a513cc5f5007310895202d1cf708610d2ee (tag)
tagging 1a695a905c18548062509178b98bc91e67510864 (commit)
replaces batman-adv-fix-for-davem
tagged by Linus Torvalds
on Sun May 29 09:30:01 2016 -0700
- Shortlog ------------------------------------------------------------
Linux 4.7-rc1
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAABAgAGBQJXSxkJAAoJEHm+PkMAQRiGwfcH/iK8kqycIUhLc/Wn2TnY0TcO
9FPW6EREzc7cRu38rXAgLyU15ysCK56QtV8anqvxkalHgY0ovmE3bwR3BKyUtW3W
IdevRChiGCH0jwG+KjlGrguBI1PCejnY9/El2F1mzUvlkMv7OYYMcUHPUm96HN15
TLjOYgUQyK+YBsj/LBWj7qUmpWEa+DuQyY/AoohtGQR9KHRAxxAr0SsvFrC+/phJ
xkozkqhy5/snqiqbVgDcqxqFBqHO23IYAbWjaCWG3M2/9HPOjw7tJwM7P2d6LQuz
mQi3+FY3sIKgjGS6T9vKYpt3PE3KmziVkzL13iU0yX/iuatjrhUKapifwPZfiKc=
=Ihgt
-----END PGP SIGNATURE-----
-----------------------------------------------------------------------
--
linux integration
4 years, 7 months
[alfred] master: alfred: Mount debugfs before reducing capabilities (d08b0e0)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit d08b0e098637e57a26ea8076bbedfeb3aa2aa172
Author: Andrew Lunn <andrew(a)lunn.ch>
Date: Wed Mar 16 20:51:12 2016 +0100
alfred: Mount debugfs before reducing capabilities
The debugfs helper code has the ability to mount the debugfs file
system if it is not already mounted. However, it cannot do this
after the capabilities have been dropped. So perform the mount early,
and remove all the other attempts to do the mount.
Signed-off-by: Andrew Lunn <andrew(a)lunn.ch>
[sw(a)simonwunderlich.de: removed namespace references from commit msg]
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
d08b0e098637e57a26ea8076bbedfeb3aa2aa172
batadv_query.c | 17 -----------------
main.c | 4 ++++
2 files changed, 4 insertions(+), 17 deletions(-)
diff --git a/batadv_query.c b/batadv_query.c
index 6dc2cf4..a5fa565 100644
--- a/batadv_query.c
+++ b/batadv_query.c
@@ -94,16 +94,9 @@ int ipv6_to_mac(const struct in6_addr *addr, struct ether_addr *mac)
int batadv_interface_check(const char *mesh_iface)
{
- char *debugfs_mnt;
char full_path[MAX_PATH + 1];
FILE *f;
- debugfs_mnt = debugfs_mount(NULL);
- if (!debugfs_mnt) {
- fprintf(stderr, "Could not find debugfs path\n");
- return -1;
- }
-
debugfs_make_path(DEBUG_BATIF_PATH_FMT "/" DEBUG_TRANSTABLE_GLOBAL,
mesh_iface, full_path, sizeof(full_path));
f = fopen(full_path, "r");
@@ -138,7 +131,6 @@ struct ether_addr *translate_mac(const char *mesh_iface, struct ether_addr *mac)
tg_originator,
} pos;
char full_path[MAX_PATH + 1];
- char *debugfs_mnt;
static struct ether_addr in_mac;
struct ether_addr *mac_result, *mac_tmp;
FILE *f = NULL;
@@ -150,10 +142,6 @@ struct ether_addr *translate_mac(const char *mesh_iface, struct ether_addr *mac)
memcpy(&in_mac, mac, sizeof(in_mac));
mac_result = &in_mac;
- debugfs_mnt = debugfs_mount(NULL);
- if (!debugfs_mnt)
- goto out;
-
debugfs_make_path(DEBUG_BATIF_PATH_FMT "/" DEBUG_TRANSTABLE_GLOBAL,
mesh_iface, full_path, sizeof(full_path));
@@ -220,7 +208,6 @@ uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac)
orig_tqvalue,
} pos;
char full_path[MAX_PATH + 1];
- char *debugfs_mnt;
static struct ether_addr in_mac;
struct ether_addr *mac_tmp;
FILE *f = NULL;
@@ -232,10 +219,6 @@ uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac)
memcpy(&in_mac, mac, sizeof(in_mac));
- debugfs_mnt = debugfs_mount(NULL);
- if (!debugfs_mnt)
- goto out;
-
debugfs_make_path(DEBUG_BATIF_PATH_FMT "/" DEBUG_ORIGINATORS,
mesh_iface, full_path, sizeof(full_path));
diff --git a/main.c b/main.c
index 9610398..52dca97 100644
--- a/main.c
+++ b/main.c
@@ -30,6 +30,7 @@
#include <unistd.h>
#endif
#include "alfred.h"
+#include "debugfs.h"
#include "packet.h"
#include "list.h"
@@ -160,6 +161,9 @@ static struct globals *alfred_init(int argc, char *argv[])
{NULL, 0, NULL, 0},
};
+ /* We need full capabilities to mount debugfs, so do that now */
+ debugfs_mount(NULL);
+
ret = reduce_capabilities();
if (ret < 0)
return NULL;
4 years, 7 months
[batctl] master: batctl: introduce throughput meter support (f109b34)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batctl
On branch : master
>---------------------------------------------------------------
commit f109b3473f866217a8e5fc4c8d4c7fc6fd0d3beb
Author: Antonio Quartulli <antonio.quartulli(a)open-mesh.com>
Date: Wed May 18 11:38:50 2016 +0200
batctl: introduce throughput meter support
Add command to launch the throughput meter test. The throughput meter is a
batman kernelspace tool for throughput measurements. The syntax is:
batctl tp <MAC>
The test is interruptible with SIGINT or SIGTERM; if the test succeeds with
no error the throughput and the elapsed time are printed to stdout,
otherwise occurred an error message is displayed (on stdout) accordingly.
Based on a prototype from Edo Monticelli <montik(a)autistici.org>
Signed-off-by: Antonio Quartulli <antonio.quartulli(a)open-mesh.com>
Signed-off-by: Sven Eckelmann <sven.eckelmann(a)open-mesh.com>
Signed-off-by: Marek Lindner <mareklindner(a)neomailbox.ch>
>---------------------------------------------------------------
f109b3473f866217a8e5fc4c8d4c7fc6fd0d3beb
Makefile | 2 +
batman_adv.h | 43 ++++
genl.c | 140 ++++++++++++
netlink.h => genl.h | 9 +-
main.c | 6 +
main.h | 2 +
man/batctl.8 | 24 +-
netlink.c | 8 +
packet.h | 54 +++++
tcpdump.c | 14 +-
tp_meter.c | 540 +++++++++++++++++++++++++++++++++++++++++++++
traceroute.h => tp_meter.h | 12 +-
12 files changed, 841 insertions(+), 13 deletions(-)
diff --git a/Makefile b/Makefile
index 3fa21f4..0cec413 100755
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,7 @@ OBJ += bat-hosts.o
OBJ += debugfs.o
OBJ += debug.o
OBJ += functions.o
+OBJ += genl.o
OBJ += hash.o
OBJ += ioctl.o
OBJ += list-batman.o
@@ -36,6 +37,7 @@ OBJ += netlink.o
OBJ += ping.o
OBJ += sys.o
OBJ += tcpdump.o
+OBJ += tp_meter.o
OBJ += traceroute.o
OBJ += translate.o
OBJ_BISECT = bisect_iv.o
diff --git a/batman_adv.h b/batman_adv.h
index a908140..acb72f8 100644
--- a/batman_adv.h
+++ b/batman_adv.h
@@ -20,6 +20,8 @@
#define BATADV_NL_NAME "batadv"
+#define BATADV_NL_MCAST_GROUP_TPMETER "tpmeter"
+
/**
* enum batadv_nl_attrs - batman-adv netlink attributes
*
@@ -32,6 +34,12 @@
* @BATADV_ATTR_HARD_IFINDEX: index of the non-batman-adv interface
* @BATADV_ATTR_HARD_IFNAME: name of the non-batman-adv interface
* @BATADV_ATTR_HARD_ADDRESS: mac address of the non-batman-adv interface
+ * @BATADV_ATTR_ORIG_ADDRESS: originator mac address
+ * @BATADV_ATTR_TPMETER_RESULT: result of run (see batadv_tp_meter_status)
+ * @BATADV_ATTR_TPMETER_TEST_TIME: time (msec) the run took
+ * @BATADV_ATTR_TPMETER_BYTES: amount of acked bytes during run
+ * @BATADV_ATTR_TPMETER_COOKIE: session cookie to match tp_meter session
+ * @BATADV_ATTR_PAD: attribute used for padding for 64-bit alignment
* @__BATADV_ATTR_AFTER_LAST: internal use
* @NUM_BATADV_ATTR: total number of batadv_nl_attrs available
* @BATADV_ATTR_MAX: highest attribute number currently defined
@@ -46,6 +54,12 @@ enum batadv_nl_attrs {
BATADV_ATTR_HARD_IFINDEX,
BATADV_ATTR_HARD_IFNAME,
BATADV_ATTR_HARD_ADDRESS,
+ BATADV_ATTR_ORIG_ADDRESS,
+ BATADV_ATTR_TPMETER_RESULT,
+ BATADV_ATTR_TPMETER_TEST_TIME,
+ BATADV_ATTR_TPMETER_BYTES,
+ BATADV_ATTR_TPMETER_COOKIE,
+ BATADV_ATTR_PAD,
/* add attributes above here, update the policy in netlink.c */
__BATADV_ATTR_AFTER_LAST,
NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST,
@@ -57,15 +71,44 @@ enum batadv_nl_attrs {
*
* @BATADV_CMD_UNSPEC: unspecified command to catch errors
* @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device
+ * @BATADV_CMD_TP_METER: Start a tp meter session
+ * @BATADV_CMD_TP_METER_CANCEL: Cancel a tp meter session
* @__BATADV_CMD_AFTER_LAST: internal use
* @BATADV_CMD_MAX: highest used command number
*/
enum batadv_nl_commands {
BATADV_CMD_UNSPEC,
BATADV_CMD_GET_MESH_INFO,
+ BATADV_CMD_TP_METER,
+ BATADV_CMD_TP_METER_CANCEL,
/* add new commands above here */
__BATADV_CMD_AFTER_LAST,
BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1
};
+/**
+ * enum batadv_tp_meter_reason - reason of a tp meter test run stop
+ * @BATADV_TP_REASON_COMPLETE: sender finished tp run
+ * @BATADV_TP_REASON_CANCEL: sender was stopped during run
+ * @BATADV_TP_REASON_DST_UNREACHABLE: receiver could not be reached or didn't
+ * answer
+ * @BATADV_TP_REASON_RESEND_LIMIT: (unused) sender retry reached limit
+ * @BATADV_TP_REASON_ALREADY_ONGOING: test to or from the same node already
+ * ongoing
+ * @BATADV_TP_REASON_MEMORY_ERROR: test was stopped due to low memory
+ * @BATADV_TP_REASON_CANT_SEND: failed to send via outgoing interface
+ * @BATADV_TP_REASON_TOO_MANY: too many ongoing sessions
+ */
+enum batadv_tp_meter_reason {
+ BATADV_TP_REASON_COMPLETE = 3,
+ BATADV_TP_REASON_CANCEL = 4,
+ /* error status >= 128 */
+ BATADV_TP_REASON_DST_UNREACHABLE = 128,
+ BATADV_TP_REASON_RESEND_LIMIT = 129,
+ BATADV_TP_REASON_ALREADY_ONGOING = 130,
+ BATADV_TP_REASON_MEMORY_ERROR = 131,
+ BATADV_TP_REASON_CANT_SEND = 132,
+ BATADV_TP_REASON_TOO_MANY = 133,
+};
+
#endif /* _UAPI_LINUX_BATMAN_ADV_H_ */
diff --git a/genl.c b/genl.c
new file mode 100644
index 0000000..b6f66fd
--- /dev/null
+++ b/genl.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2007, 2008 Johannes Berg
+ * Copyright (c) 2007 Andy Lutomirski
+ * Copyright (c) 2007 Mike Kershaw
+ * Copyright (c) 2008-2009 Luis R. Rodriguez
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * This ought to be provided by libnl - but was borrowed from iw/genl.c
+ */
+
+#include "netlink.h"
+#include "main.h"
+
+#include <errno.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+#include <linux/genetlink.h>
+
+#include "batman_adv.h"
+
+static int mcast_error_handler(struct sockaddr_nl *nla __unused,
+ struct nlmsgerr *err, void *arg)
+{
+ int *ret = arg;
+ *ret = err->error;
+ return NL_STOP;
+}
+
+static int mcast_ack_handler(struct nl_msg *msg __unused, void *arg)
+{
+ int *ret = arg;
+ *ret = 0;
+ return NL_STOP;
+}
+
+struct mcast_handler_args {
+ const char *group;
+ int id;
+};
+
+static int mcast_family_handler(struct nl_msg *msg, void *arg)
+{
+ struct mcast_handler_args *grp = arg;
+ struct nlattr *tb[CTRL_ATTR_MAX + 1];
+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+ struct nlattr *mcgrp;
+ int rem_mcgrp;
+
+ nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+ genlmsg_attrlen(gnlh, 0), NULL);
+
+ if (!tb[CTRL_ATTR_MCAST_GROUPS])
+ return NL_SKIP;
+
+ nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], rem_mcgrp) {
+ struct nlattr *tb_mcgrp[CTRL_ATTR_MCAST_GRP_MAX + 1];
+
+ nla_parse(tb_mcgrp, CTRL_ATTR_MCAST_GRP_MAX,
+ nla_data(mcgrp), nla_len(mcgrp), NULL);
+
+ if (!tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME] ||
+ !tb_mcgrp[CTRL_ATTR_MCAST_GRP_ID])
+ continue;
+ if (strncmp(nla_data(tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME]),
+ grp->group, nla_len(tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME])))
+ continue;
+ grp->id = nla_get_u32(tb_mcgrp[CTRL_ATTR_MCAST_GRP_ID]);
+ break;
+ }
+
+ return NL_SKIP;
+}
+
+int nl_get_multicast_id(struct nl_sock *sock, const char *family,
+ const char *group)
+{
+ struct nl_msg *msg;
+ struct nl_cb *cb;
+ int ret, ctrlid;
+ struct mcast_handler_args grp = {
+ .group = group,
+ .id = -ENOENT,
+ };
+
+ msg = nlmsg_alloc();
+ if (!msg)
+ return -ENOMEM;
+
+ cb = nl_cb_alloc(NL_CB_DEFAULT);
+ if (!cb) {
+ ret = -ENOMEM;
+ goto out_fail_cb;
+ }
+
+ ctrlid = genl_ctrl_resolve(sock, "nlctrl");
+
+ genlmsg_put(msg, 0, 0, ctrlid, 0,
+ 0, CTRL_CMD_GETFAMILY, 0);
+
+ ret = -ENOBUFS;
+ NLA_PUT_STRING(msg, CTRL_ATTR_FAMILY_NAME, family);
+
+ ret = nl_send_auto_complete(sock, msg);
+ if (ret < 0)
+ goto out;
+
+ ret = 1;
+
+ nl_cb_err(cb, NL_CB_CUSTOM, mcast_error_handler, &ret);
+ nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, mcast_ack_handler, &ret);
+ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, mcast_family_handler, &grp);
+
+ while (ret > 0)
+ nl_recvmsgs(sock, cb);
+
+ if (ret == 0)
+ ret = grp.id;
+ nla_put_failure:
+ out:
+ nl_cb_put(cb);
+ out_fail_cb:
+ nlmsg_free(msg);
+ return ret;
+}
diff --git a/netlink.h b/genl.h
similarity index 83%
copy from netlink.h
copy to genl.h
index 0a4d3dd..0b622bb 100644
--- a/netlink.h
+++ b/genl.h
@@ -19,12 +19,13 @@
*
*/
-#ifndef _BATCTL_NETLINK_H
-#define _BATCTL_NETLINK_H
+#ifndef _BATCTL_GENL_H
+#define _BATCTL_GENL_H
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>
-extern struct nla_policy batadv_netlink_policy[];
+int nl_get_multicast_id(struct nl_sock *sock, const char *family,
+ const char *group);
-#endif /* _BATCTL_NETLINK_H */
+#endif /* _BATCTL_GENL_H */
diff --git a/main.c b/main.c
index a2cda5b..5e1ecc7 100644
--- a/main.c
+++ b/main.c
@@ -33,6 +33,7 @@
#include "translate.h"
#include "traceroute.h"
#include "tcpdump.h"
+#include "tp_meter.h"
#include "bisect_iv.h"
#include "ioctl.h"
#include "functions.h"
@@ -82,6 +83,7 @@ static void print_usage(void)
fprintf(stderr, " \tping|p <destination> \tping another batman adv host via layer 2\n");
fprintf(stderr, " \ttraceroute|tr <destination> \ttraceroute another batman adv host via layer 2\n");
fprintf(stderr, " \ttcpdump|td <interface> \ttcpdump layer 2 traffic on the given interface\n");
+ printf(" \tthroughputmeter|tp <destination> \tstart a throughput measurement\n");
fprintf(stderr, " \ttranslate|t <destination> \ttranslate a destination to the originator responsible for it\n");
#ifdef BATCTL_BISECT
fprintf(stderr, " \tbisect_iv <file1> .. <fileN>\tanalyze given batman iv log files for routing stability\n");
@@ -162,6 +164,10 @@ int main(int argc, char **argv)
ret = ping(mesh_iface, argc - 1, argv + 1);
+ } else if ((strcmp(argv[1], "throughputmeter") == 0) || (strcmp(argv[1], "tp") == 0)) {
+
+ ret = tp_meter (mesh_iface, argc -1, argv + 1);
+
} else if ((strcmp(argv[1], "traceroute") == 0) || (strcmp(argv[1], "tr") == 0)) {
ret = traceroute(mesh_iface, argc - 1, argv + 1);
diff --git a/main.h b/main.h
index e94fc33..0e57f32 100644
--- a/main.h
+++ b/main.h
@@ -47,10 +47,12 @@
#endif
#define __packed __attribute((packed)) /* linux kernel compat */
+#define __unused __attribute__((unused))
#define BIT(nr) (1UL << (nr)) /* linux kernel compat */
typedef uint8_t u8; /* linux kernel compat */
typedef uint16_t u16; /* linux kernel compat */
+typedef uint32_t u32; /* linux kernel compat */
extern char module_ver_path[];
diff --git a/man/batctl.8 b/man/batctl.8
index 05f68d3..8bac727 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -36,9 +36,11 @@ B.A.T.M.A.N. advanced operates on layer 2. Thus all hosts participating in the v
connected together for all protocols above layer 2. Therefore the common diagnosis tools do not work as expected. To
overcome these problems batctl contains the commands \fBping\fP, \fBtraceroute\fP, \fBtcpdump\fP which provide similar
functionality to the normal \fBping\fP(1), \fBtraceroute\fP(1), \fBtcpdump\fP(1) commands, but modified to layer 2
-behaviour or using the B.A.T.M.A.N. advanced protocol.
-.PP
+behaviour or using the B.A.T.M.A.N. advanced protocol. For similar reasons, \fBthroughputmeter\fP, a command to test network
+performances, is also included.
+
.PP
+.Pp
.SH OPTIONS
.TP
.I \fBoptions:
@@ -322,6 +324,24 @@ for routing loops. Use "\-t" to trace OGMs of a host throughout the network. Use
nodes. The option "\-s" can be used to limit the output to a range of sequence numbers, between min and max, or to one
specific sequence number, min. Furthermore using "\-o" you can filter the output to a specified originator. If "\-n" is
given batctl will not replace the MAC addresses with bat\-host names in the output.
+.RE
+.br
+.IP "\fBthroughputmeter\fP|\fBtp\fP \fBMAC\fP"
+This command starts a throughput test entirely controlled by batman module in
+kernel space: the computational resources needed to align memory and copy data
+between user and kernel space that are required by other user space tools may
+represent a bootleneck on some low profile device.
+
+The test consist of the transfer of 14 MB of data between the two nodes. The
+protocol used to transfer the data is somehow similar to TCP, but simpler: some
+TCP features are still missing, thus protocol performances could be worst. Since
+a fixed amount of data is transferred the experiment duration depends on the
+network conditions. The experiment can be interrupted with CTRL + C. At the end
+of a succesful experiment the throughput in KBytes per second is returned,
+togheter with the experiment duration in millisecond and the amount of bytes
+transferred. If too many packets are lost or the specified MAC address is not
+reachable, a message notifing the error is returned instead of the result.
+.RE
.br
.SH FILES
.TP
diff --git a/netlink.c b/netlink.c
index 74d7566..365cda1 100644
--- a/netlink.c
+++ b/netlink.c
@@ -41,4 +41,12 @@ struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
[BATADV_ATTR_HARD_ADDRESS] = { .type = NLA_UNSPEC,
.minlen = ETH_ALEN,
.maxlen = ETH_ALEN },
+ [BATADV_ATTR_ORIG_ADDRESS] = { .type = NLA_UNSPEC,
+ .minlen = ETH_ALEN,
+ .maxlen = ETH_ALEN },
+ [BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 },
+ [BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 },
+ [BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 },
+ [BATADV_ATTR_TPMETER_COOKIE] = { .type = NLA_U32 },
+ [BATADV_ATTR_PAD] = { .type = NLA_UNSPEC },
};
diff --git a/packet.h b/packet.h
index 7156779..6b011ff 100644
--- a/packet.h
+++ b/packet.h
@@ -21,6 +21,8 @@
#include <asm/byteorder.h>
#include <linux/types.h>
+#define batadv_tp_is_error(n) ((u8)n > 127 ? 1 : 0)
+
/**
* enum batadv_packettype - types for batman-adv encapsulated packets
* @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV
@@ -93,6 +95,7 @@ enum batadv_icmp_packettype {
BATADV_ECHO_REQUEST = 8,
BATADV_TTL_EXCEEDED = 11,
BATADV_PARAMETER_PROBLEM = 12,
+ BATADV_TP = 15,
};
/**
@@ -285,6 +288,16 @@ struct batadv_elp_packet {
#define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet)
/**
+ * enum batadv_icmp_user_cmd_type - types for batman-adv icmp cmd modes
+ * @BATADV_TP_START: start a throughput meter run
+ * @BATADV_TP_STOP: stop a throughput meter run
+ */
+enum batadv_icmp_user_cmd_type {
+ BATADV_TP_START = 0,
+ BATADV_TP_STOP = 2,
+};
+
+/**
* struct batadv_icmp_header - common members among all the ICMP packets
* @packet_type: batman-adv packet type, part of the general header
* @version: batman-adv protocol version, part of the genereal header
@@ -334,6 +347,47 @@ struct batadv_icmp_packet {
__be16 seqno;
};
+/**
+ * struct batadv_icmp_tp_packet - ICMP TP Meter packet
+ * @packet_type: batman-adv packet type, part of the general header
+ * @version: batman-adv protocol version, part of the genereal header
+ * @ttl: time to live for this packet, part of the genereal header
+ * @msg_type: ICMP packet type
+ * @dst: address of the destination node
+ * @orig: address of the source node
+ * @uid: local ICMP socket identifier
+ * @subtype: TP packet subtype (see batadv_icmp_tp_subtype)
+ * @session: TP session identifier
+ * @seqno: the TP sequence number
+ * @timestamp: time when the packet has been sent. This value is filled in a
+ * TP_MSG and echoed back in the next TP_ACK so that the sender can compute the
+ * RTT. Since it is read only by the host which wrote it, there is no need to
+ * store it using network order
+ */
+struct batadv_icmp_tp_packet {
+ u8 packet_type;
+ u8 version;
+ u8 ttl;
+ u8 msg_type; /* see ICMP message types above */
+ u8 dst[ETH_ALEN];
+ u8 orig[ETH_ALEN];
+ u8 uid;
+ u8 subtype;
+ u8 session[2];
+ __be32 seqno;
+ __be32 timestamp;
+};
+
+/**
+ * enum batadv_icmp_tp_subtype - ICMP TP Meter packet subtypes
+ * @BATADV_TP_MSG: Msg from sender to receiver
+ * @BATADV_TP_ACK: acknowledgment from receiver to sender
+ */
+enum batadv_icmp_tp_subtype {
+ BATADV_TP_MSG = 0,
+ BATADV_TP_ACK,
+};
+
#define BATADV_RR_LEN 16
/**
diff --git a/tcpdump.c b/tcpdump.c
index 363e9e4..be0c4f0 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -808,11 +808,14 @@ static void dump_batman_elp(unsigned char *packet_buff, ssize_t buff_len,
static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed)
{
struct batadv_icmp_packet *icmp_packet;
+ struct batadv_icmp_tp_packet *tp;
+
char *name;
LEN_CHECK((size_t)buff_len - sizeof(struct ether_header), sizeof(struct batadv_icmp_packet), "BAT ICMP");
icmp_packet = (struct batadv_icmp_packet *)(packet_buff + sizeof(struct ether_header));
+ tp = (struct batadv_icmp_tp_packet *)icmp_packet;
if (!time_printed)
print_time();
@@ -820,7 +823,8 @@ static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int r
printf("BAT %s > ",
get_name_by_macaddr((struct ether_addr *)icmp_packet->orig, read_opt));
- name = get_name_by_macaddr((struct ether_addr *)icmp_packet->dst, read_opt);
+ name = get_name_by_macaddr((struct ether_addr *)icmp_packet->dst,
+ read_opt);
switch (icmp_packet->msg_type) {
case BATADV_ECHO_REPLY:
@@ -841,6 +845,14 @@ static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int r
icmp_packet->ttl, icmp_packet->version,
(size_t)buff_len - sizeof(struct ether_header));
break;
+ case BATADV_TP:
+ printf("%s: ICMP TP type %s (%hhu), id %hhu, seq %u, ttl %2d, v %d, length %zu\n",
+ name, tp->subtype == BATADV_TP_MSG ? "MSG" :
+ tp->subtype == BATADV_TP_ACK ? "ACK" : "N/A",
+ tp->subtype, tp->uid, ntohl(tp->seqno), tp->ttl,
+ tp->version,
+ (size_t)buff_len - sizeof(struct ether_header));
+ break;
default:
printf("%s: ICMP type %hhu, length %zu\n",
name, icmp_packet->msg_type,
diff --git a/tp_meter.c b/tp_meter.c
new file mode 100644
index 0000000..d980ebd
--- /dev/null
+++ b/tp_meter.c
@@ -0,0 +1,540 @@
+/*
+ * Copyright (C) 2013-2016 B.A.T.M.A.N. contributors:
+ *
+ * Antonio Quartulli <a(a)unstable.cc>
+ *
+ * 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 "main.h"
+#include "tp_meter.h"
+
+#include <netinet/ether.h>
+#include <netinet/in.h>
+#include <netlink/netlink.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <net/if.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+
+#include "bat-hosts.h"
+#include "batman_adv.h"
+#include "functions.h"
+#include "genl.h"
+#include "netlink.h"
+#include "packet.h"
+#include "debugfs.h"
+
+static struct ether_addr *dst_mac;
+static char *tp_mesh_iface;
+
+struct tp_result {
+ int error;
+ bool found;
+ uint32_t cookie;
+ uint8_t return_value;
+ uint32_t test_time;
+ uint64_t total_bytes;
+};
+
+struct tp_cookie {
+ int error;
+ bool found;
+ uint32_t cookie;
+};
+
+static int tpmeter_nl_print_error(struct sockaddr_nl *nla __unused,
+ struct nlmsgerr *nlerr,
+ void *arg)
+{
+ struct tp_result *result = arg;
+
+ if (nlerr->error != -EOPNOTSUPP)
+ fprintf(stderr, "Error received: %s\n",
+ strerror(-nlerr->error));
+
+ result->error = nlerr->error;
+
+ return NL_STOP;
+}
+
+static int tp_meter_result_callback(struct nl_msg *msg, void *arg)
+{
+ struct tp_result *result = arg;
+ struct nlmsghdr *nlh = nlmsg_hdr(msg);
+ struct nlattr *attrs[NUM_BATADV_ATTR];
+ struct genlmsghdr *ghdr;
+ uint32_t cookie;
+
+ if (!genlmsg_valid_hdr(nlh, 0)) {
+ result->error = -EINVAL;
+ return NL_STOP;
+ }
+
+ ghdr = nlmsg_data(nlh);
+ if (ghdr->cmd != BATADV_CMD_TP_METER)
+ return NL_OK;
+
+ if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
+ genlmsg_len(ghdr), batadv_netlink_policy)) {
+ fputs("Received invalid data from kernel.\n", stderr);
+ result->error = -EINVAL;
+ return NL_STOP;
+ }
+
+ if (!attrs[BATADV_ATTR_TPMETER_COOKIE]) {
+ result->error = -EINVAL;
+ return NL_STOP;
+ }
+
+ if (!attrs[BATADV_ATTR_TPMETER_RESULT])
+ return NL_OK;
+
+ cookie = nla_get_u32(attrs[BATADV_ATTR_TPMETER_COOKIE]);
+ if (cookie != result->cookie)
+ return NL_OK;
+
+ result->found = true;
+
+ result->return_value = nla_get_u8(attrs[BATADV_ATTR_TPMETER_RESULT]);
+
+ if (attrs[BATADV_ATTR_TPMETER_TEST_TIME])
+ result->test_time = nla_get_u32(attrs[BATADV_ATTR_TPMETER_TEST_TIME]);
+
+ if (attrs[BATADV_ATTR_TPMETER_BYTES])
+ result->total_bytes = nla_get_u64(attrs[BATADV_ATTR_TPMETER_BYTES]);
+
+ return NL_OK;
+}
+
+static int tp_meter_cookie_callback(struct nl_msg *msg, void *arg)
+{
+ struct tp_cookie *cookie = arg;
+ struct nlmsghdr *nlh = nlmsg_hdr(msg);
+ struct nlattr *attrs[NUM_BATADV_ATTR];
+ struct genlmsghdr *ghdr;
+
+ if (!genlmsg_valid_hdr(nlh, 0)) {
+ cookie->error = -EINVAL;
+ return NL_STOP;
+ }
+
+ ghdr = nlmsg_data(nlh);
+ if (ghdr->cmd != BATADV_CMD_TP_METER) {
+ cookie->error = -EINVAL;
+ return NL_STOP;
+ }
+
+ if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
+ genlmsg_len(ghdr), batadv_netlink_policy)) {
+ fputs("Received invalid data from kernel.\n", stderr);
+ cookie->error = -EINVAL;
+ return NL_STOP;
+ }
+
+ if (!attrs[BATADV_ATTR_TPMETER_COOKIE]) {
+ cookie->error = -EINVAL;
+ return NL_STOP;
+ }
+
+ cookie->cookie = nla_get_u32(attrs[BATADV_ATTR_TPMETER_COOKIE]);
+ cookie->found = true;
+
+ return NL_OK;
+}
+
+static int tp_meter_start(char *mesh_iface, struct ether_addr *dst_mac,
+ uint32_t time, struct tp_cookie *cookie)
+{
+ struct nl_sock *sock;
+ struct nl_msg *msg;
+ struct nl_cb *cb;
+ int ifindex;
+ int family;
+ int ret;
+ int err = 0;
+
+ sock = nl_socket_alloc();
+ if (!sock)
+ return -ENOMEM;
+
+ ret = genl_connect(sock);
+ if (ret < 0) {
+ err = -EOPNOTSUPP;
+ goto out;
+ }
+
+ family = genl_ctrl_resolve(sock, BATADV_NL_NAME);
+ if (family < 0) {
+ err = -EOPNOTSUPP;
+ goto out;
+ }
+
+ ifindex = if_nametoindex(mesh_iface);
+ if (!ifindex) {
+ fprintf(stderr, "Interface %s is unknown\n", mesh_iface);
+ err = -ENODEV;
+ goto out;
+ }
+
+ cb = nl_cb_alloc(NL_CB_DEFAULT);
+ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, tp_meter_cookie_callback,
+ cookie);
+ nl_cb_err(cb, NL_CB_CUSTOM, tpmeter_nl_print_error, cookie);
+
+ msg = nlmsg_alloc();
+ if (!msg) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0,
+ 0, BATADV_CMD_TP_METER, 1);
+
+ nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, ifindex);
+ nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, dst_mac);
+ nla_put_u32(msg, BATADV_ATTR_TPMETER_TEST_TIME, time);
+
+ nl_send_auto_complete(sock, msg);
+ nlmsg_free(msg);
+
+ nl_recvmsgs(sock, cb);
+
+ nl_cb_put(cb);
+
+ if (cookie->error < 0)
+ err = cookie->error;
+ else if (!cookie->found)
+ err= -EINVAL;
+
+out:
+ nl_socket_free(sock);
+
+ return err;
+}
+
+static int no_seq_check(struct nl_msg *msg __unused, void *arg __unused)
+{
+ return NL_OK;
+}
+
+static int tp_recv_result(struct nl_sock *sock, struct tp_result *result)
+{
+ int err = 0;
+ struct nl_cb *cb;
+
+ cb = nl_cb_alloc(NL_CB_DEFAULT);
+ nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
+ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, tp_meter_result_callback,
+ result);
+ nl_cb_err(cb, NL_CB_CUSTOM, tpmeter_nl_print_error, result);
+
+ while (result->error == 0 && !result->found)
+ nl_recvmsgs(sock, cb);
+
+ nl_cb_put(cb);
+
+ if (result->error < 0)
+ err = result->error;
+ else if (!result->found)
+ err= -EINVAL;
+
+ return err;
+}
+
+static int tp_meter_stop(char *mesh_iface, struct ether_addr *dst_mac)
+{
+ struct nl_sock *sock;
+ struct nl_msg *msg;
+ int ifindex;
+ int family;
+ int ret;
+ int err = 0;
+
+ sock = nl_socket_alloc();
+ if (!sock)
+ return -ENOMEM;
+
+ ret = genl_connect(sock);
+ if (ret < 0) {
+ err = -EOPNOTSUPP;
+ goto out;
+ }
+
+ family = genl_ctrl_resolve(sock, BATADV_NL_NAME);
+ if (family < 0) {
+ err = -EOPNOTSUPP;
+ goto out;
+ }
+
+ ifindex = if_nametoindex(mesh_iface);
+ if (!ifindex) {
+ fprintf(stderr, "Interface %s is unknown\n", mesh_iface);
+ err = -ENODEV;
+ goto out;
+ }
+
+ msg = nlmsg_alloc();
+ if (!msg) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0,
+ 0, BATADV_CMD_TP_METER_CANCEL, 1);
+
+ nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, ifindex);
+ nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, dst_mac);
+
+ nl_send_auto_complete(sock, msg);
+ nlmsg_free(msg);
+
+out:
+ nl_socket_free(sock);
+
+ return err;
+}
+
+static struct nl_sock *tp_prepare_listening_sock(void)
+{
+ struct nl_sock *sock;
+ int family;
+ int ret;
+ int mcid;
+
+ sock = nl_socket_alloc();
+ if (!sock)
+ return NULL;
+
+ ret = genl_connect(sock);
+ if (ret < 0) {
+ fprintf(stderr, "Failed to connect to generic netlink: %d\n",
+ ret);
+ goto err;
+ }
+
+ family = genl_ctrl_resolve(sock, BATADV_NL_NAME);
+ if (family < 0) {
+ fprintf(stderr, "Failed to resolve batman-adv netlink: %d\n",
+ family);
+ goto err;
+ }
+
+ mcid = nl_get_multicast_id(sock, BATADV_NL_NAME,
+ BATADV_NL_MCAST_GROUP_TPMETER);
+ if (mcid < 0) {
+ fprintf(stderr, "Failed to resolve batman-adv tpmeter multicast group: %d\n",
+ mcid);
+ goto err;
+ }
+
+ ret = nl_socket_add_membership(sock, mcid);
+ if (ret) {
+ fprintf(stderr, "Failed to join batman-adv tpmeter multicast group: %d\n",
+ ret);
+ goto err;
+ }
+
+ return sock;
+
+err:
+ nl_socket_free(sock);
+
+ return NULL;
+}
+
+void tp_sig_handler(int sig)
+{
+ switch (sig) {
+ case SIGINT:
+ case SIGTERM:
+ fflush(stdout);
+ tp_meter_stop(tp_mesh_iface, dst_mac);
+ break;
+ default:
+ break;
+ }
+}
+
+static void tp_meter_usage(void)
+{
+ fprintf(stderr, "Usage: batctl tp [parameters] <MAC>\n");
+ fprintf(stderr, "Parameters:\n");
+ fprintf(stderr, "\t -t <time> test length in milliseconds\n");
+ fprintf(stderr, "\t -n don't convert addresses to bat-host names\n");
+}
+
+int tp_meter(char *mesh_iface, int argc, char **argv)
+{
+ struct bat_host *bat_host;
+ uint64_t throughput;
+ char *dst_string;
+ int ret = EXIT_FAILURE;
+ int found_args = 1, read_opt = USE_BAT_HOSTS;
+ uint32_t time = 0;
+ char optchar;
+ struct nl_sock *listen_sock = NULL;
+ struct tp_result result = {
+ .error = 0,
+ .return_value = 0,
+ .test_time = 0,
+ .total_bytes = 0,
+ .found = false,
+ };
+ struct tp_cookie cookie = {
+ .error = 0,
+ .cookie = 0,
+ .found = false,
+ };
+
+ while ((optchar = getopt(argc, argv, "t:n")) != -1) {
+ switch (optchar) {
+ case 't':
+ found_args += 2;
+ time = strtoul(optarg, NULL, 10);
+ break;
+ case 'n':
+ read_opt &= ~USE_BAT_HOSTS;
+ found_args += 1;
+ break;
+ default:
+ tp_meter_usage();
+ return EXIT_FAILURE;
+ }
+ }
+
+ if (argc <= found_args) {
+ tp_meter_usage();
+ return EXIT_FAILURE;
+ }
+
+ dst_string = argv[found_args];
+ bat_hosts_init(read_opt);
+ bat_host = bat_hosts_find_by_name(dst_string);
+
+ if (bat_host)
+ dst_mac = &bat_host->mac_addr;
+
+ if (!dst_mac) {
+ dst_mac = ether_aton(dst_string);
+
+ if (!dst_mac) {
+ printf("Error - the tp meter destination is not a mac address or bat-host name: %s\n",
+ dst_string);
+ goto out;
+ }
+ }
+
+
+ if (bat_host && (read_opt & USE_BAT_HOSTS))
+ dst_string = bat_host->name;
+ else
+ dst_string = ether_ntoa_long(dst_mac);
+
+ /* for sighandler */
+ tp_mesh_iface = mesh_iface;
+ signal(SIGINT, tp_sig_handler);
+ signal(SIGTERM, tp_sig_handler);
+
+ listen_sock = tp_prepare_listening_sock();
+ if (!listen_sock)
+ goto out;
+
+ ret = tp_meter_start(mesh_iface, dst_mac, time, &cookie);
+ if (ret < 0) {
+ printf("Failed to send tp_meter request to kernel: %d\n", ret);
+ goto out;
+ }
+
+ result.cookie = cookie.cookie;
+ ret = tp_recv_result(listen_sock, &result);
+ if (ret < 0) {
+ printf("Failed to recv tp_meter result from kernel: %d\n", ret);
+ goto out;
+ }
+
+ switch (result.return_value) {
+ case BATADV_TP_REASON_DST_UNREACHABLE:
+ fprintf(stderr, "Destination unreachable\n");
+ break;
+ case BATADV_TP_REASON_RESEND_LIMIT:
+ fprintf(stderr,
+ "The number of retry for the same window exceeds the limit, test aborted\n");
+ break;
+ case BATADV_TP_REASON_ALREADY_ONGOING:
+ fprintf(stderr,
+ "Cannot run two test towards the same node\n");
+ break;
+ case BATADV_TP_REASON_MEMORY_ERROR:
+ fprintf(stderr,
+ "Kernel cannot allocate memory, aborted\n");
+ break;
+ case BATADV_TP_REASON_TOO_MANY:
+ fprintf(stderr, "Too many ongoing sessions\n");
+ break;
+ case BATADV_TP_REASON_CANCEL:
+ printf("CANCEL received: test aborted\n");
+ /* fall through and print the partial result */
+ case BATADV_TP_REASON_COMPLETE:
+ if (result.test_time > 0) {
+ throughput = result.total_bytes * 1000;
+ throughput /= result.test_time;
+ } else {
+ throughput = UINT64_MAX;
+ }
+
+ printf("Test duration %ums.\n", result.test_time);
+ printf("Sent %" PRIu64 " Bytes.\n", result.total_bytes);
+ printf("Throughput: ");
+ if (throughput == UINT64_MAX)
+ printf("inf\n");
+ else if (throughput > (1UL<<30))
+ printf("%.2f GB/s (%2.f Gbps)\n",
+ (float)throughput / (1<<30),
+ (float)throughput * 8 / 1000000000);
+ else if (throughput > (1UL<<20))
+ printf("%.2f MB/s (%.2f Mbps)\n",
+ (float)throughput / (1<<20),
+ (float)throughput * 8 / 1000000);
+ else if (throughput > (1UL<<10))
+ printf("%.2f KB/s (%.2f Kbps)\n",
+ (float)throughput / (1<<10),
+ (float)throughput * 8 / 1000);
+ else
+ printf("%lu Bytes/s (%lu Bps)\n",
+ throughput, throughput * 8);
+
+ ret = 0;
+ break;
+ default:
+ printf("Unrecognized return value %d\n", result.return_value);
+ }
+
+out:
+ nl_socket_free(listen_sock);
+ bat_hosts_free();
+ return ret;
+}
diff --git a/traceroute.h b/tp_meter.h
similarity index 74%
copy from traceroute.h
copy to tp_meter.h
index 6dc5603..aef4dbc 100644
--- a/traceroute.h
+++ b/tp_meter.h
@@ -1,7 +1,7 @@
/*
- * Copyright (C) 2009-2016 B.A.T.M.A.N. contributors:
+ * Copyright (C) 2013-2016 B.A.T.M.A.N. contributors:
*
- * Marek Lindner <mareklindner(a)neomailbox.ch>
+ * Antonio Quartulli <a(a)unstable.cc>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
@@ -19,9 +19,9 @@
*
*/
-#ifndef _BATCTL_TRACEROUTE_H
-#define _BATCTL_TRACEROUTE_H
+#ifndef _BATCTL_TP_METER_H
+#define _BATCTL_TP_METER_H
-int traceroute(char *mesh_iface, int argc, char **argv);
+int tp_meter(char *mesh_iface, int argc, char **argv);
-#endif
+#endif /* _BATCTL_TP_METER_H */
4 years, 8 months
[batman-adv] master: batman-adv: throughput meter implementation (98d7a76)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 98d7a766b645432f683f20d6ee6c304ab42bdf2f
Author: Antonio Quartulli <antonio.quartulli(a)open-mesh.com>
Date: Thu May 5 13:09:43 2016 +0200
batman-adv: throughput meter implementation
The throughput meter module is a simple, kernel-space replacement for
throughtput measurements tool like iperf and netperf. It is intended to
approximate TCP behaviour.
It is invoked through batctl: the protocol is connection oriented, with
cumulative acknowledgment and a dynamic-size sliding window.
The test *can* be interrupted by batctl. A receiver side timeout avoids
unlimited waitings for sender packets: after one second of inactivity, the
receiver abort the ongoing test.
Based on a prototype from Edo Monticelli <montik(a)autistici.org>
Signed-off-by: Antonio Quartulli <antonio.quartulli(a)open-mesh.com>
Signed-off-by: Sven Eckelmann <sven.eckelmann(a)open-mesh.com>
Signed-off-by: Marek Lindner <mareklindner(a)neomailbox.ch>
>---------------------------------------------------------------
compat-include/linux/netlink.h | 113 ++
compat-include/net/genetlink.h | 127 ++-
include/uapi/linux/batman_adv.h | 43 +
net/batman-adv/Makefile | 1 +
net/batman-adv/log.c | 1 +
net/batman-adv/log.h | 18 +-
net/batman-adv/main.c | 4 +
net/batman-adv/main.h | 8 +
net/batman-adv/netlink.c | 234 +++-
net/batman-adv/netlink.h | 6 +
net/batman-adv/packet.h | 54 +
net/batman-adv/routing.c | 8 +
net/batman-adv/soft-interface.c | 2 +
net/batman-adv/tp_meter.c | 1504 ++++++++++++++++++++++++++
net/batman-adv/{icmp_socket.h => tp_meter.h} | 24 +-
net/batman-adv/types.h | 112 ++
16 files changed, 2235 insertions(+), 24 deletions(-)
Diff suppressed because of size. To see it, use:
git diff-tree --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc 98d7a766b645432f683f20d6ee6c304ab42bdf2f
4 years, 8 months
[batman-adv] master: batman-adv: return netdev status in the TX path (e3b8acb)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit e3b8acbff9c84dda26f3e2fd346291ef79bdf283
Author: Antonio Quartulli <antonio.quartulli(a)open-mesh.com>
Date: Wed May 18 11:38:48 2016 +0200
batman-adv: return netdev status in the TX path
Return the proper netdev TX status along the TX path so that the tp_meter
can understand when the queue is full and should stop sending packets.
Signed-off-by: Antonio Quartulli <antonio.quartulli(a)open-mesh.com>
Signed-off-by: Sven Eckelmann <sven.eckelmann(a)open-mesh.com>
Signed-off-by: Marek Lindner <mareklindner(a)neomailbox.ch>
>---------------------------------------------------------------
e3b8acbff9c84dda26f3e2fd346291ef79bdf283
net/batman-adv/fragmentation.c | 41 +++++++++++++++++++++++++----------------
net/batman-adv/fragmentation.h | 6 +++---
net/batman-adv/routing.c | 23 ++++++++++++++---------
net/batman-adv/send.c | 25 +++++++++++++------------
net/batman-adv/tvlv.c | 4 +++-
5 files changed, 58 insertions(+), 41 deletions(-)
diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
index 9f41a0a..0934730 100644
--- a/net/batman-adv/fragmentation.c
+++ b/net/batman-adv/fragmentation.c
@@ -433,11 +433,12 @@ err:
* @orig_node: final destination of the created fragments
* @neigh_node: next-hop of the created fragments
*
- * Return: true on success, false otherwise.
+ * Return: the netdev tx status or -1 in case of error.
+ * When -1 is returned the skb is not consumed.
*/
-bool batadv_frag_send_packet(struct sk_buff *skb,
- struct batadv_orig_node *orig_node,
- struct batadv_neigh_node *neigh_node)
+int batadv_frag_send_packet(struct sk_buff *skb,
+ struct batadv_orig_node *orig_node,
+ struct batadv_neigh_node *neigh_node)
{
struct batadv_priv *bat_priv;
struct batadv_hard_iface *primary_if = NULL;
@@ -446,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
unsigned int mtu = neigh_node->if_incoming->net_dev->mtu;
unsigned int header_size = sizeof(frag_header);
unsigned int max_fragment_size, max_packet_size;
- bool ret = false;
+ int ret = -1;
/* To avoid merge and refragmentation at next-hops we never send
* fragments larger than BATADV_FRAG_MAX_FRAG_SIZE
@@ -457,12 +458,12 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
/* Don't even try to fragment, if we need more than 16 fragments */
if (skb->len > max_packet_size)
- goto out_err;
+ goto out;
bat_priv = orig_node->bat_priv;
primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if)
- goto out_err;
+ goto out;
/* Create one header to be copied to all fragments */
frag_header.packet_type = BATADV_UNICAST_FRAG;
@@ -488,23 +489,33 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
while (skb->len > max_fragment_size) {
skb_fragment = batadv_frag_create(skb, &frag_header, mtu);
if (!skb_fragment)
- goto out_err;
+ goto out;
batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_TX);
batadv_add_counter(bat_priv, BATADV_CNT_FRAG_TX_BYTES,
skb_fragment->len + ETH_HLEN);
- batadv_send_unicast_skb(skb_fragment, neigh_node);
+ ret = batadv_send_unicast_skb(skb_fragment, neigh_node);
+ if (ret != NET_XMIT_SUCCESS) {
+ /* return -1 so that the caller can free the original
+ * skb
+ */
+ ret = -1;
+ goto out;
+ }
+
frag_header.no++;
/* The initial check in this function should cover this case */
- if (frag_header.no == BATADV_FRAG_MAX_FRAGMENTS - 1)
- goto out_err;
+ if (frag_header.no == BATADV_FRAG_MAX_FRAGMENTS - 1) {
+ ret = -1;
+ goto out;
+ }
}
/* Make room for the fragment header. */
if (batadv_skb_head_push(skb, header_size) < 0 ||
pskb_expand_head(skb, header_size + ETH_HLEN, 0, GFP_ATOMIC) < 0)
- goto out_err;
+ goto out;
memcpy(skb->data, &frag_header, header_size);
@@ -512,11 +523,9 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_TX);
batadv_add_counter(bat_priv, BATADV_CNT_FRAG_TX_BYTES,
skb->len + ETH_HLEN);
- batadv_send_unicast_skb(skb, neigh_node);
+ ret = batadv_send_unicast_skb(skb, neigh_node);
- ret = true;
-
-out_err:
+out:
if (primary_if)
batadv_hardif_put(primary_if);
diff --git a/net/batman-adv/fragmentation.h b/net/batman-adv/fragmentation.h
index 9ff77c7..3202fe3 100644
--- a/net/batman-adv/fragmentation.h
+++ b/net/batman-adv/fragmentation.h
@@ -34,9 +34,9 @@ bool batadv_frag_skb_fwd(struct sk_buff *skb,
struct batadv_orig_node *orig_node_src);
bool batadv_frag_skb_buffer(struct sk_buff **skb,
struct batadv_orig_node *orig_node);
-bool batadv_frag_send_packet(struct sk_buff *skb,
- struct batadv_orig_node *orig_node,
- struct batadv_neigh_node *neigh_node);
+int batadv_frag_send_packet(struct sk_buff *skb,
+ struct batadv_orig_node *orig_node,
+ struct batadv_neigh_node *neigh_node);
/**
* batadv_frag_check_entry - check if a list of fragments has timed out
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 49f464d..ded80ca 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -270,7 +270,10 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
icmph->ttl = BATADV_TTL;
res = batadv_send_skb_to_orig(skb, orig_node, NULL);
- if (res != NET_XMIT_DROP)
+ if (res == -1)
+ goto out;
+
+ if (dev_xmit_complete(res))
ret = NET_RX_SUCCESS;
break;
@@ -292,7 +295,7 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if = NULL;
struct batadv_orig_node *orig_node = NULL;
struct batadv_icmp_packet *icmp_packet;
- int ret = NET_RX_DROP;
+ int res, ret = NET_RX_DROP;
icmp_packet = (struct batadv_icmp_packet *)skb->data;
@@ -323,7 +326,8 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
icmp_packet->msg_type = BATADV_TTL_EXCEEDED;
icmp_packet->ttl = BATADV_TTL;
- if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
+ res = batadv_send_skb_to_orig(skb, orig_node, NULL);
+ if (res != -1 && dev_xmit_complete(res))
ret = NET_RX_SUCCESS;
out:
@@ -343,7 +347,7 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
struct ethhdr *ethhdr;
struct batadv_orig_node *orig_node = NULL;
int hdr_size = sizeof(struct batadv_icmp_header);
- int ret = NET_RX_DROP;
+ int res, ret = NET_RX_DROP;
/* drop packet if it has not necessary minimum size */
if (unlikely(!pskb_may_pull(skb, hdr_size)))
@@ -409,7 +413,8 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
icmph->ttl--;
/* route it */
- if (batadv_send_skb_to_orig(skb, orig_node, recv_if) != NET_XMIT_DROP)
+ res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
+ if (res != -1 && dev_xmit_complete(res))
ret = NET_RX_SUCCESS;
out:
@@ -646,6 +651,8 @@ static int batadv_route_unicast_packet(struct sk_buff *skb,
len = skb->len;
res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
+ if (res == -1)
+ goto out;
/* translate transmit result into receive result */
if (res == NET_XMIT_SUCCESS) {
@@ -653,12 +660,10 @@ static int batadv_route_unicast_packet(struct sk_buff *skb,
batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD);
batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES,
len + ETH_HLEN);
+ }
+ if (dev_xmit_complete(res))
ret = NET_RX_SUCCESS;
- } else if (res == NET_XMIT_POLICED) {
- /* skb was buffered and consumed */
- ret = NET_RX_SUCCESS;
- }
out:
if (orig_node)
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 6b82468..49836da 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -156,8 +156,11 @@ int batadv_send_unicast_skb(struct sk_buff *skb,
* host, NULL can be passed as recv_if and no interface alternating is
* attempted.
*
- * Return: NET_XMIT_SUCCESS on success, NET_XMIT_DROP on failure, or
- * NET_XMIT_POLICED if the skb is buffered for later transmit.
+ * Return: -1 on failure (and the skb is not consumed), NET_XMIT_POLICED if the
+ * skb is buffered for later transmit or the NET_XMIT status returned by the
+ * lower routine if the packet has been passed down.
+ *
+ * If the returning value is not -1 the skb has been consumed.
*/
int batadv_send_skb_to_orig(struct sk_buff *skb,
struct batadv_orig_node *orig_node,
@@ -165,7 +168,7 @@ int batadv_send_skb_to_orig(struct sk_buff *skb,
{
struct batadv_priv *bat_priv = orig_node->bat_priv;
struct batadv_neigh_node *neigh_node;
- int ret = NET_XMIT_DROP;
+ int ret = -1;
/* batadv_find_router() increases neigh_nodes refcount if found. */
neigh_node = batadv_find_router(bat_priv, orig_node, recv_if);
@@ -178,8 +181,7 @@ int batadv_send_skb_to_orig(struct sk_buff *skb,
if (atomic_read(&bat_priv->fragmentation) &&
skb->len > neigh_node->if_incoming->net_dev->mtu) {
/* Fragment and send packet. */
- if (batadv_frag_send_packet(skb, orig_node, neigh_node))
- ret = NET_XMIT_SUCCESS;
+ ret = batadv_frag_send_packet(skb, orig_node, neigh_node);
goto out;
}
@@ -188,12 +190,10 @@ int batadv_send_skb_to_orig(struct sk_buff *skb,
* (i.e. being forwarded). If the packet originates from this node or if
* network coding fails, then send the packet as usual.
*/
- if (recv_if && batadv_nc_skb_forward(skb, neigh_node)) {
+ if (recv_if && batadv_nc_skb_forward(skb, neigh_node))
ret = NET_XMIT_POLICED;
- } else {
- batadv_send_unicast_skb(skb, neigh_node);
- ret = NET_XMIT_SUCCESS;
- }
+ else
+ ret = batadv_send_unicast_skb(skb, neigh_node);
out:
if (neigh_node)
@@ -319,7 +319,7 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
{
struct batadv_unicast_packet *unicast_packet;
struct ethhdr *ethhdr;
- int ret = NET_XMIT_DROP;
+ int res, ret = NET_XMIT_DROP;
if (!orig_node)
goto out;
@@ -356,7 +356,8 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
if (batadv_tt_global_client_is_roaming(bat_priv, ethhdr->h_dest, vid))
unicast_packet->ttvn = unicast_packet->ttvn - 1;
- if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
+ res = batadv_send_skb_to_orig(skb, orig_node, NULL);
+ if (res != -1 && dev_xmit_complete(res))
ret = NET_XMIT_SUCCESS;
out:
diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
index 2fd542e..8c59420 100644
--- a/net/batman-adv/tvlv.c
+++ b/net/batman-adv/tvlv.c
@@ -591,6 +591,7 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
unsigned char *tvlv_buff;
unsigned int tvlv_len;
ssize_t hdr_len = sizeof(*unicast_tvlv_packet);
+ int res;
orig_node = batadv_orig_hash_find(bat_priv, dst);
if (!orig_node)
@@ -623,7 +624,8 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
tvlv_buff += sizeof(*tvlv_hdr);
memcpy(tvlv_buff, tvlv_value, tvlv_value_len);
- if (batadv_send_skb_to_orig(skb, orig_node, NULL) == NET_XMIT_DROP)
+ res = batadv_send_skb_to_orig(skb, orig_node, NULL);
+ if (!(res != -1 && dev_xmit_complete(res)))
kfree_skb(skb);
out:
batadv_orig_node_put(orig_node);
4 years, 8 months
[batman-adv] master: batman-adv: Fix bat_(iv|v) function declaration header (1373a7e)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 1373a7e0e612be4300f90e3a3accacef60a25e9d
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Sun May 15 11:07:46 2016 +0200
batman-adv: Fix bat_(iv|v) function declaration header
The bat_algo.h had some functions declared which were not part of the
bat_algo.c file. These are instead stored in bat_v.c and bat_iv_ogm.c. The
declaration should therefore be also in bat_v.h and bat_iv_ogm,h to make
them easier to find.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Marek Lindner <mareklindner(a)neomailbox.ch>
>---------------------------------------------------------------
1373a7e0e612be4300f90e3a3accacef60a25e9d
net/batman-adv/bat_algo.h | 26 --------------------------
net/batman-adv/bat_iv_ogm.c | 3 ++-
net/batman-adv/{netlink.h => bat_iv_ogm.h} | 13 ++++++-------
net/batman-adv/bat_v.c | 3 ++-
net/batman-adv/{bat_algo.h => bat_v.h} | 20 +++-----------------
net/batman-adv/main.c | 2 ++
net/batman-adv/routing.c | 1 -
net/batman-adv/translation-table.c | 1 -
8 files changed, 15 insertions(+), 54 deletions(-)
diff --git a/net/batman-adv/bat_algo.h b/net/batman-adv/bat_algo.h
index e178206..860d773 100644
--- a/net/batman-adv/bat_algo.h
+++ b/net/batman-adv/bat_algo.h
@@ -24,8 +24,6 @@
struct seq_file;
-int batadv_iv_init(void);
-
extern char batadv_routing_algo[];
extern struct list_head batadv_hardif_list;
@@ -34,28 +32,4 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops);
int batadv_algo_select(struct batadv_priv *bat_priv, char *name);
int batadv_algo_seq_print_text(struct seq_file *seq, void *offset);
-#ifdef CONFIG_BATMAN_ADV_BATMAN_V
-
-int batadv_v_init(void);
-int batadv_v_mesh_init(struct batadv_priv *bat_priv);
-void batadv_v_mesh_free(struct batadv_priv *bat_priv);
-
-#else
-
-static inline int batadv_v_init(void)
-{
- return 0;
-}
-
-static inline int batadv_v_mesh_init(struct batadv_priv *bat_priv)
-{
- return 0;
-}
-
-static inline void batadv_v_mesh_free(struct batadv_priv *bat_priv)
-{
-}
-
-#endif /* CONFIG_BATMAN_ADV_BATMAN_V */
-
#endif /* _NET_BATMAN_ADV_BAT_ALGO_H_ */
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 805532a..e2d8848 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -15,7 +15,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "bat_algo.h"
+#include "bat_iv_ogm.h"
#include "main.h"
#include <linux/atomic.h>
@@ -49,6 +49,7 @@
#include <linux/types.h>
#include <linux/workqueue.h>
+#include "bat_algo.h"
#include "bitarray.h"
#include "hard-interface.h"
#include "hash.h"
diff --git a/net/batman-adv/netlink.h b/net/batman-adv/bat_iv_ogm.h
similarity index 70%
copy from net/batman-adv/netlink.h
copy to net/batman-adv/bat_iv_ogm.h
index 39044cc..b9f3550 100644
--- a/net/batman-adv/netlink.h
+++ b/net/batman-adv/bat_iv_ogm.h
@@ -1,6 +1,6 @@
-/* Copyright (C) 2016 B.A.T.M.A.N. contributors:
+/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
*
- * Matthias Schiffer
+ * Marek Lindner, Simon Wunderlich
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
@@ -15,12 +15,11 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _NET_BATMAN_ADV_NETLINK_H_
-#define _NET_BATMAN_ADV_NETLINK_H_
+#ifndef _BATMAN_ADV_BATADV_IV_OGM_H_
+#define _BATMAN_ADV_BATADV_IV_OGM_H_
#include "main.h"
-void batadv_netlink_register(void);
-void batadv_netlink_unregister(void);
+int batadv_iv_init(void);
-#endif /* _NET_BATMAN_ADV_NETLINK_H_ */
+#endif /* _BATMAN_ADV_BATADV_IV_OGM_H_ */
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
index b9c2850..e4a91cd 100644
--- a/net/batman-adv/bat_v.c
+++ b/net/batman-adv/bat_v.c
@@ -15,7 +15,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "bat_algo.h"
+#include "bat_v.h"
#include "main.h"
#include <linux/bug.h>
@@ -30,6 +30,7 @@
#include <linux/types.h>
#include <linux/workqueue.h>
+#include "bat_algo.h"
#include "bat_v_elp.h"
#include "bat_v_ogm.h"
#include "hard-interface.h"
diff --git a/net/batman-adv/bat_algo.h b/net/batman-adv/bat_v.h
similarity index 69%
copy from net/batman-adv/bat_algo.h
copy to net/batman-adv/bat_v.h
index e178206..52dd6cf 100644
--- a/net/batman-adv/bat_algo.h
+++ b/net/batman-adv/bat_v.h
@@ -15,25 +15,11 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _NET_BATMAN_ADV_BAT_ALGO_H_
-#define _NET_BATMAN_ADV_BAT_ALGO_H_
+#ifndef _NET_BATMAN_ADV_BAT_V_H_
+#define _NET_BATMAN_ADV_BAT_V_H_
#include "main.h"
-#include <linux/types.h>
-
-struct seq_file;
-
-int batadv_iv_init(void);
-
-extern char batadv_routing_algo[];
-extern struct list_head batadv_hardif_list;
-
-void batadv_algo_init(void);
-int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops);
-int batadv_algo_select(struct batadv_priv *bat_priv, char *name);
-int batadv_algo_seq_print_text(struct seq_file *seq, void *offset);
-
#ifdef CONFIG_BATMAN_ADV_BATMAN_V
int batadv_v_init(void);
@@ -58,4 +44,4 @@ static inline void batadv_v_mesh_free(struct batadv_priv *bat_priv)
#endif /* CONFIG_BATMAN_ADV_BATMAN_V */
-#endif /* _NET_BATMAN_ADV_BAT_ALGO_H_ */
+#endif /* _NET_BATMAN_ADV_BAT_V_H_ */
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 919dd03..275604b 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -46,6 +46,8 @@
#include <net/rtnetlink.h>
#include "bat_algo.h"
+#include "bat_iv_ogm.h"
+#include "bat_v.h"
#include "bridge_loop_avoidance.h"
#include "debugfs.h"
#include "distributed-arp-table.h"
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index d1a6bad..49f464d 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -34,7 +34,6 @@
#include <linux/spinlock.h>
#include <linux/stddef.h>
-#include "bat_algo.h"
#include "bitarray.h"
#include "bridge_loop_avoidance.h"
#include "distributed-arp-table.h"
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index ae5811f..9be4ff0 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -44,7 +44,6 @@
#include <linux/string.h>
#include <linux/workqueue.h>
-#include "bat_algo.h"
#include "bridge_loop_avoidance.h"
#include "hard-interface.h"
#include "hash.h"
4 years, 8 months
[batman-adv] master: batman-adv: Consolidate logging related functions (421d988)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 421d988b2c0849e49362b416af68d502ef7df1bb
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Sun May 15 23:48:31 2016 +0200
batman-adv: Consolidate logging related functions
There are several places in batman-adv which provide logging related
functions. These should be grouped together in the log.* files to make them
easier to find.
Reported-by: Markus Pargmann <mpa(a)pengutronix.de>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Marek Lindner <mareklindner(a)neomailbox.ch>
>---------------------------------------------------------------
421d988b2c0849e49362b416af68d502ef7df1bb
net/batman-adv/Makefile | 1 +
net/batman-adv/bat_iv_ogm.c | 1 +
net/batman-adv/bat_v_elp.c | 1 +
net/batman-adv/bat_v_ogm.c | 1 +
net/batman-adv/bitarray.c | 2 +
net/batman-adv/bridge_loop_avoidance.c | 1 +
net/batman-adv/debugfs.c | 216 +------------------------------
net/batman-adv/distributed-arp-table.c | 1 +
net/batman-adv/gateway_client.c | 1 +
net/batman-adv/gateway_common.c | 1 +
net/batman-adv/hard-interface.c | 1 +
net/batman-adv/icmp_socket.c | 1 +
net/batman-adv/log.c | 230 +++++++++++++++++++++++++++++++++
net/batman-adv/log.h | 109 ++++++++++++++++
net/batman-adv/main.c | 2 +
net/batman-adv/main.h | 69 +---------
net/batman-adv/multicast.c | 1 +
net/batman-adv/network-coding.c | 1 +
net/batman-adv/originator.c | 1 +
net/batman-adv/routing.c | 1 +
net/batman-adv/send.c | 1 +
net/batman-adv/sysfs.c | 1 +
net/batman-adv/translation-table.c | 1 +
23 files changed, 363 insertions(+), 282 deletions(-)
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile
index 6ce53e5..7da5901 100644
--- a/net/batman-adv/Makefile
+++ b/net/batman-adv/Makefile
@@ -32,6 +32,7 @@ batman-adv-y += gateway_common.o
batman-adv-y += hard-interface.o
batman-adv-y += hash.o
batman-adv-y += icmp_socket.o
+batman-adv-$(CONFIG_BATMAN_ADV_DEBUG) += log.o
batman-adv-y += main.o
batman-adv-$(CONFIG_BATMAN_ADV_MCAST) += multicast.o
batman-adv-y += netlink.o
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 948a5b4..805532a 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -52,6 +52,7 @@
#include "bitarray.h"
#include "hard-interface.h"
#include "hash.h"
+#include "log.h"
#include "network-coding.h"
#include "originator.h"
#include "packet.h"
diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
index cf0262b..15cf272 100644
--- a/net/batman-adv/bat_v_elp.c
+++ b/net/batman-adv/bat_v_elp.c
@@ -43,6 +43,7 @@
#include "bat_algo.h"
#include "bat_v_ogm.h"
#include "hard-interface.h"
+#include "log.h"
#include "originator.h"
#include "packet.h"
#include "routing.h"
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index 93e3d76..7ac9e0b 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -42,6 +42,7 @@
#include "bat_algo.h"
#include "hard-interface.h"
#include "hash.h"
+#include "log.h"
#include "originator.h"
#include "packet.h"
#include "routing.h"
diff --git a/net/batman-adv/bitarray.c b/net/batman-adv/bitarray.c
index a0c7913..0322714 100644
--- a/net/batman-adv/bitarray.c
+++ b/net/batman-adv/bitarray.c
@@ -20,6 +20,8 @@
#include <linux/bitmap.h>
+#include "log.h"
+
/* shift the packet array by n places. */
static void batadv_bitmap_shift_left(unsigned long *seq_bits, s32 n)
{
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 748a9ea..e4f7494 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -48,6 +48,7 @@
#include "hard-interface.h"
#include "hash.h"
+#include "log.h"
#include "originator.h"
#include "packet.h"
#include "sysfs.h"
diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c
index 227c84b..1d68b6e 100644
--- a/net/batman-adv/debugfs.c
+++ b/net/batman-adv/debugfs.c
@@ -18,37 +18,26 @@
#include "debugfs.h"
#include "main.h"
-#include <linux/compiler.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/export.h>
-#include <linux/fcntl.h>
#include <linux/fs.h>
-#include <linux/jiffies.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
#include <linux/netdevice.h>
-#include <linux/poll.h>
#include <linux/printk.h>
#include <linux/sched.h> /* for linux/wait.h */
#include <linux/seq_file.h>
-#include <linux/slab.h>
-#include <linux/spinlock.h>
#include <linux/stat.h>
#include <linux/stddef.h>
#include <linux/stringify.h>
#include <linux/sysfs.h>
-#include <linux/types.h>
-#include <linux/uaccess.h>
-#include <linux/wait.h>
-#include <stdarg.h>
#include "bat_algo.h"
#include "bridge_loop_avoidance.h"
#include "distributed-arp-table.h"
#include "gateway_client.h"
#include "icmp_socket.h"
+#include "log.h"
#include "multicast.h"
#include "network-coding.h"
#include "originator.h"
@@ -56,209 +45,6 @@
static struct dentry *batadv_debugfs;
-#ifdef CONFIG_BATMAN_ADV_DEBUG
-#define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1)
-
-static const int batadv_log_buff_len = BATADV_LOG_BUF_LEN;
-
-static char *batadv_log_char_addr(struct batadv_priv_debug_log *debug_log,
- size_t idx)
-{
- return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK];
-}
-
-static void batadv_emit_log_char(struct batadv_priv_debug_log *debug_log,
- char c)
-{
- char *char_addr;
-
- char_addr = batadv_log_char_addr(debug_log, debug_log->log_end);
- *char_addr = c;
- debug_log->log_end++;
-
- if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len)
- debug_log->log_start = debug_log->log_end - batadv_log_buff_len;
-}
-
-__printf(2, 3)
-static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log,
- const char *fmt, ...)
-{
- va_list args;
- static char debug_log_buf[256];
- char *p;
-
- if (!debug_log)
- return 0;
-
- spin_lock_bh(&debug_log->lock);
- va_start(args, fmt);
- vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args);
- va_end(args);
-
- for (p = debug_log_buf; *p != 0; p++)
- batadv_emit_log_char(debug_log, *p);
-
- spin_unlock_bh(&debug_log->lock);
-
- wake_up(&debug_log->queue_wait);
-
- return 0;
-}
-
-int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
-{
- va_list args;
- char tmp_log_buf[256];
-
- va_start(args, fmt);
- vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args);
- batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s",
- jiffies_to_msecs(jiffies), tmp_log_buf);
- va_end(args);
-
- return 0;
-}
-
-static int batadv_log_open(struct inode *inode, struct file *file)
-{
- if (!try_module_get(THIS_MODULE))
- return -EBUSY;
-
- nonseekable_open(inode, file);
- file->private_data = inode->i_private;
- return 0;
-}
-
-static int batadv_log_release(struct inode *inode, struct file *file)
-{
- module_put(THIS_MODULE);
- return 0;
-}
-
-static bool batadv_log_empty(struct batadv_priv_debug_log *debug_log)
-{
- return !(debug_log->log_start - debug_log->log_end);
-}
-
-static ssize_t batadv_log_read(struct file *file, char __user *buf,
- size_t count, loff_t *ppos)
-{
- struct batadv_priv *bat_priv = file->private_data;
- struct batadv_priv_debug_log *debug_log = bat_priv->debug_log;
- int error, i = 0;
- char *char_addr;
- char c;
-
- if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log))
- return -EAGAIN;
-
- if (!buf)
- return -EINVAL;
-
- if (count == 0)
- return 0;
-
- if (!access_ok(VERIFY_WRITE, buf, count))
- return -EFAULT;
-
- error = wait_event_interruptible(debug_log->queue_wait,
- (!batadv_log_empty(debug_log)));
-
- if (error)
- return error;
-
- spin_lock_bh(&debug_log->lock);
-
- while ((!error) && (i < count) &&
- (debug_log->log_start != debug_log->log_end)) {
- char_addr = batadv_log_char_addr(debug_log,
- debug_log->log_start);
- c = *char_addr;
-
- debug_log->log_start++;
-
- spin_unlock_bh(&debug_log->lock);
-
- error = __put_user(c, buf);
-
- spin_lock_bh(&debug_log->lock);
-
- buf++;
- i++;
- }
-
- spin_unlock_bh(&debug_log->lock);
-
- if (!error)
- return i;
-
- return error;
-}
-
-static unsigned int batadv_log_poll(struct file *file, poll_table *wait)
-{
- struct batadv_priv *bat_priv = file->private_data;
- struct batadv_priv_debug_log *debug_log = bat_priv->debug_log;
-
- poll_wait(file, &debug_log->queue_wait, wait);
-
- if (!batadv_log_empty(debug_log))
- return POLLIN | POLLRDNORM;
-
- return 0;
-}
-
-static const struct file_operations batadv_log_fops = {
- .open = batadv_log_open,
- .release = batadv_log_release,
- .read = batadv_log_read,
- .poll = batadv_log_poll,
- .llseek = no_llseek,
-};
-
-static int batadv_debug_log_setup(struct batadv_priv *bat_priv)
-{
- struct dentry *d;
-
- if (!bat_priv->debug_dir)
- goto err;
-
- bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC);
- if (!bat_priv->debug_log)
- goto err;
-
- spin_lock_init(&bat_priv->debug_log->lock);
- init_waitqueue_head(&bat_priv->debug_log->queue_wait);
-
- d = debugfs_create_file("log", S_IFREG | S_IRUSR,
- bat_priv->debug_dir, bat_priv,
- &batadv_log_fops);
- if (!d)
- goto err;
-
- return 0;
-
-err:
- return -ENOMEM;
-}
-
-static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
-{
- kfree(bat_priv->debug_log);
- bat_priv->debug_log = NULL;
-}
-#else /* CONFIG_BATMAN_ADV_DEBUG */
-static int batadv_debug_log_setup(struct batadv_priv *bat_priv)
-{
- return 0;
-}
-
-static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
-{
-}
-#endif
-
static int batadv_algorithms_open(struct inode *inode, struct file *file)
{
return single_open(file, batadv_algo_seq_print_text, NULL);
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index 584b827..fa76465 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -45,6 +45,7 @@
#include "hard-interface.h"
#include "hash.h"
+#include "log.h"
#include "originator.h"
#include "send.h"
#include "translation-table.h"
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index 31ba24e..e108d45 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -42,6 +42,7 @@
#include "gateway_common.h"
#include "hard-interface.h"
+#include "log.h"
#include "originator.h"
#include "packet.h"
#include "routing.h"
diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c
index 6a6f2d4..d7bc6a8 100644
--- a/net/batman-adv/gateway_common.c
+++ b/net/batman-adv/gateway_common.c
@@ -28,6 +28,7 @@
#include <linux/string.h>
#include "gateway_client.h"
+#include "log.h"
#include "packet.h"
#include "tvlv.h"
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 1e26a0b..6689656 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -41,6 +41,7 @@
#include "debugfs.h"
#include "distributed-arp-table.h"
#include "gateway_client.h"
+#include "log.h"
#include "originator.h"
#include "packet.h"
#include "send.h"
diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c
index 777aea1..378cc11 100644
--- a/net/batman-adv/icmp_socket.c
+++ b/net/batman-adv/icmp_socket.c
@@ -45,6 +45,7 @@
#include <linux/wait.h>
#include "hard-interface.h"
+#include "log.h"
#include "originator.h"
#include "packet.h"
#include "send.h"
diff --git a/net/batman-adv/log.c b/net/batman-adv/log.c
new file mode 100644
index 0000000..cd7e824
--- /dev/null
+++ b/net/batman-adv/log.c
@@ -0,0 +1,230 @@
+/* Copyright (C) 2010-2016 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "log.h"
+#include "main.h"
+
+#include <linux/compiler.h>
+#include <linux/debugfs.h>
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/fcntl.h>
+#include <linux/fs.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/poll.h>
+#include <linux/sched.h> /* for linux/wait.h */
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/stat.h>
+#include <linux/stddef.h>
+#include <linux/types.h>
+#include <linux/uaccess.h>
+#include <linux/wait.h>
+#include <stdarg.h>
+
+#define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1)
+
+static const int batadv_log_buff_len = BATADV_LOG_BUF_LEN;
+
+static char *batadv_log_char_addr(struct batadv_priv_debug_log *debug_log,
+ size_t idx)
+{
+ return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK];
+}
+
+static void batadv_emit_log_char(struct batadv_priv_debug_log *debug_log,
+ char c)
+{
+ char *char_addr;
+
+ char_addr = batadv_log_char_addr(debug_log, debug_log->log_end);
+ *char_addr = c;
+ debug_log->log_end++;
+
+ if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len)
+ debug_log->log_start = debug_log->log_end - batadv_log_buff_len;
+}
+
+__printf(2, 3)
+static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log,
+ const char *fmt, ...)
+{
+ va_list args;
+ static char debug_log_buf[256];
+ char *p;
+
+ if (!debug_log)
+ return 0;
+
+ spin_lock_bh(&debug_log->lock);
+ va_start(args, fmt);
+ vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args);
+ va_end(args);
+
+ for (p = debug_log_buf; *p != 0; p++)
+ batadv_emit_log_char(debug_log, *p);
+
+ spin_unlock_bh(&debug_log->lock);
+
+ wake_up(&debug_log->queue_wait);
+
+ return 0;
+}
+
+int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
+{
+ va_list args;
+ char tmp_log_buf[256];
+
+ va_start(args, fmt);
+ vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args);
+ batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s",
+ jiffies_to_msecs(jiffies), tmp_log_buf);
+ va_end(args);
+
+ return 0;
+}
+
+static int batadv_log_open(struct inode *inode, struct file *file)
+{
+ if (!try_module_get(THIS_MODULE))
+ return -EBUSY;
+
+ nonseekable_open(inode, file);
+ file->private_data = inode->i_private;
+ return 0;
+}
+
+static int batadv_log_release(struct inode *inode, struct file *file)
+{
+ module_put(THIS_MODULE);
+ return 0;
+}
+
+static bool batadv_log_empty(struct batadv_priv_debug_log *debug_log)
+{
+ return !(debug_log->log_start - debug_log->log_end);
+}
+
+static ssize_t batadv_log_read(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ struct batadv_priv *bat_priv = file->private_data;
+ struct batadv_priv_debug_log *debug_log = bat_priv->debug_log;
+ int error, i = 0;
+ char *char_addr;
+ char c;
+
+ if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log))
+ return -EAGAIN;
+
+ if (!buf)
+ return -EINVAL;
+
+ if (count == 0)
+ return 0;
+
+ if (!access_ok(VERIFY_WRITE, buf, count))
+ return -EFAULT;
+
+ error = wait_event_interruptible(debug_log->queue_wait,
+ (!batadv_log_empty(debug_log)));
+
+ if (error)
+ return error;
+
+ spin_lock_bh(&debug_log->lock);
+
+ while ((!error) && (i < count) &&
+ (debug_log->log_start != debug_log->log_end)) {
+ char_addr = batadv_log_char_addr(debug_log,
+ debug_log->log_start);
+ c = *char_addr;
+
+ debug_log->log_start++;
+
+ spin_unlock_bh(&debug_log->lock);
+
+ error = __put_user(c, buf);
+
+ spin_lock_bh(&debug_log->lock);
+
+ buf++;
+ i++;
+ }
+
+ spin_unlock_bh(&debug_log->lock);
+
+ if (!error)
+ return i;
+
+ return error;
+}
+
+static unsigned int batadv_log_poll(struct file *file, poll_table *wait)
+{
+ struct batadv_priv *bat_priv = file->private_data;
+ struct batadv_priv_debug_log *debug_log = bat_priv->debug_log;
+
+ poll_wait(file, &debug_log->queue_wait, wait);
+
+ if (!batadv_log_empty(debug_log))
+ return POLLIN | POLLRDNORM;
+
+ return 0;
+}
+
+static const struct file_operations batadv_log_fops = {
+ .open = batadv_log_open,
+ .release = batadv_log_release,
+ .read = batadv_log_read,
+ .poll = batadv_log_poll,
+ .llseek = no_llseek,
+};
+
+int batadv_debug_log_setup(struct batadv_priv *bat_priv)
+{
+ struct dentry *d;
+
+ if (!bat_priv->debug_dir)
+ goto err;
+
+ bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC);
+ if (!bat_priv->debug_log)
+ goto err;
+
+ spin_lock_init(&bat_priv->debug_log->lock);
+ init_waitqueue_head(&bat_priv->debug_log->queue_wait);
+
+ d = debugfs_create_file("log", S_IFREG | S_IRUSR,
+ bat_priv->debug_dir, bat_priv,
+ &batadv_log_fops);
+ if (!d)
+ goto err;
+
+ return 0;
+
+err:
+ return -ENOMEM;
+}
+
+void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
+{
+ kfree(bat_priv->debug_log);
+ bat_priv->debug_log = NULL;
+}
diff --git a/net/batman-adv/log.h b/net/batman-adv/log.h
new file mode 100644
index 0000000..9948e56
--- /dev/null
+++ b/net/batman-adv/log.h
@@ -0,0 +1,109 @@
+/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner, Simon Wunderlich
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _NET_BATMAN_ADV_LOG_H_
+#define _NET_BATMAN_ADV_LOG_H_
+
+#include "main.h"
+
+#include <linux/bitops.h>
+#include <linux/compiler.h>
+#include <linux/printk.h>
+
+#ifdef CONFIG_BATMAN_ADV_DEBUG
+
+int batadv_debug_log_setup(struct batadv_priv *bat_priv);
+void batadv_debug_log_cleanup(struct batadv_priv *bat_priv);
+
+#else
+
+static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv)
+{
+ return 0;
+}
+
+static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
+{
+}
+
+#endif
+
+/**
+ * enum batadv_dbg_level - available log levels
+ * @BATADV_DBG_BATMAN: OGM and TQ computations related messages
+ * @BATADV_DBG_ROUTES: route added / changed / deleted
+ * @BATADV_DBG_TT: translation table messages
+ * @BATADV_DBG_BLA: bridge loop avoidance messages
+ * @BATADV_DBG_DAT: ARP snooping and DAT related messages
+ * @BATADV_DBG_NC: network coding related messages
+ * @BATADV_DBG_MCAST: multicast related messages
+ * @BATADV_DBG_ALL: the union of all the above log levels
+ */
+enum batadv_dbg_level {
+ BATADV_DBG_BATMAN = BIT(0),
+ BATADV_DBG_ROUTES = BIT(1),
+ BATADV_DBG_TT = BIT(2),
+ BATADV_DBG_BLA = BIT(3),
+ BATADV_DBG_DAT = BIT(4),
+ BATADV_DBG_NC = BIT(5),
+ BATADV_DBG_MCAST = BIT(6),
+ BATADV_DBG_ALL = 127,
+};
+
+#ifdef CONFIG_BATMAN_ADV_DEBUG
+int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
+__printf(2, 3);
+
+/* possibly ratelimited debug output */
+#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \
+ do { \
+ if (atomic_read(&bat_priv->log_level) & type && \
+ (!ratelimited || net_ratelimit())) \
+ batadv_debug_log(bat_priv, fmt, ## arg);\
+ } \
+ while (0)
+#else /* !CONFIG_BATMAN_ADV_DEBUG */
+__printf(4, 5)
+static inline void _batadv_dbg(int type __always_unused,
+ struct batadv_priv *bat_priv __always_unused,
+ int ratelimited __always_unused,
+ const char *fmt __always_unused, ...)
+{
+}
+#endif
+
+#define batadv_dbg(type, bat_priv, arg...) \
+ _batadv_dbg(type, bat_priv, 0, ## arg)
+#define batadv_dbg_ratelimited(type, bat_priv, arg...) \
+ _batadv_dbg(type, bat_priv, 1, ## arg)
+
+#define batadv_info(net_dev, fmt, arg...) \
+ do { \
+ struct net_device *_netdev = (net_dev); \
+ struct batadv_priv *_batpriv = netdev_priv(_netdev); \
+ batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
+ pr_info("%s: " fmt, _netdev->name, ## arg); \
+ } while (0)
+#define batadv_err(net_dev, fmt, arg...) \
+ do { \
+ struct net_device *_netdev = (net_dev); \
+ struct batadv_priv *_batpriv = netdev_priv(_netdev); \
+ batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
+ pr_err("%s: " fmt, _netdev->name, ## arg); \
+ } while (0)
+
+#endif /* _NET_BATMAN_ADV_LOG_H_ */
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 04d20c4..919dd03 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -33,6 +33,7 @@
#include <linux/list.h>
#include <linux/module.h>
#include <linux/netdevice.h>
+#include <linux/printk.h>
#include <linux/rculist.h>
#include <linux/rcupdate.h>
#include <linux/seq_file.h>
@@ -52,6 +53,7 @@
#include "gateway_common.h"
#include "hard-interface.h"
#include "icmp_socket.h"
+#include "log.h"
#include "multicast.h"
#include "netlink.h"
#include "network-coding.h"
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 91cc776..48de999 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -175,7 +175,6 @@ enum batadv_uev_type {
/* Kernel headers */
-#include <linux/atomic.h>
#include <linux/bitops.h> /* for packet.h */
#include <linux/compiler.h>
#include <linux/cpumask.h>
@@ -183,13 +182,13 @@ enum batadv_uev_type {
#include <linux/if_ether.h> /* for packet.h */
#include <linux/if_vlan.h>
#include <linux/jiffies.h>
-#include <linux/netdevice.h>
#include <linux/percpu.h>
-#include <linux/printk.h>
#include <linux/types.h>
#include "types.h"
+struct net_device;
+struct packet_type;
struct seq_file;
struct sk_buff;
@@ -219,70 +218,6 @@ void batadv_recv_handler_unregister(u8 packet_type);
__be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr);
/**
- * enum batadv_dbg_level - available log levels
- * @BATADV_DBG_BATMAN: OGM and TQ computations related messages
- * @BATADV_DBG_ROUTES: route added / changed / deleted
- * @BATADV_DBG_TT: translation table messages
- * @BATADV_DBG_BLA: bridge loop avoidance messages
- * @BATADV_DBG_DAT: ARP snooping and DAT related messages
- * @BATADV_DBG_NC: network coding related messages
- * @BATADV_DBG_MCAST: multicast related messages
- * @BATADV_DBG_ALL: the union of all the above log levels
- */
-enum batadv_dbg_level {
- BATADV_DBG_BATMAN = BIT(0),
- BATADV_DBG_ROUTES = BIT(1),
- BATADV_DBG_TT = BIT(2),
- BATADV_DBG_BLA = BIT(3),
- BATADV_DBG_DAT = BIT(4),
- BATADV_DBG_NC = BIT(5),
- BATADV_DBG_MCAST = BIT(6),
- BATADV_DBG_ALL = 127,
-};
-
-#ifdef CONFIG_BATMAN_ADV_DEBUG
-int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
-__printf(2, 3);
-
-/* possibly ratelimited debug output */
-#define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \
- do { \
- if (atomic_read(&bat_priv->log_level) & type && \
- (!ratelimited || net_ratelimit())) \
- batadv_debug_log(bat_priv, fmt, ## arg);\
- } \
- while (0)
-#else /* !CONFIG_BATMAN_ADV_DEBUG */
-__printf(4, 5)
-static inline void _batadv_dbg(int type __always_unused,
- struct batadv_priv *bat_priv __always_unused,
- int ratelimited __always_unused,
- const char *fmt __always_unused, ...)
-{
-}
-#endif
-
-#define batadv_dbg(type, bat_priv, arg...) \
- _batadv_dbg(type, bat_priv, 0, ## arg)
-#define batadv_dbg_ratelimited(type, bat_priv, arg...) \
- _batadv_dbg(type, bat_priv, 1, ## arg)
-
-#define batadv_info(net_dev, fmt, arg...) \
- do { \
- struct net_device *_netdev = (net_dev); \
- struct batadv_priv *_batpriv = netdev_priv(_netdev); \
- batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
- pr_info("%s: " fmt, _netdev->name, ## arg); \
- } while (0)
-#define batadv_err(net_dev, fmt, arg...) \
- do { \
- struct net_device *_netdev = (net_dev); \
- struct batadv_priv *_batpriv = netdev_priv(_netdev); \
- batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \
- pr_err("%s: " fmt, _netdev->name, ## arg); \
- } while (0)
-
-/**
* batadv_compare_eth - Compare two not u16 aligned Ethernet addresses
* @data1: Pointer to a six-byte array containing the Ethernet address
* @data2: Pointer other six-byte array containing the Ethernet address
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index 0e7d78f..cc91507 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -55,6 +55,7 @@
#include "hard-interface.h"
#include "hash.h"
+#include "log.h"
#include "packet.h"
#include "translation-table.h"
#include "tvlv.h"
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index d0383de..293ef4f 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -51,6 +51,7 @@
#include "hard-interface.h"
#include "hash.h"
+#include "log.h"
#include "originator.h"
#include "packet.h"
#include "routing.h"
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 592cbda..8ad17ad 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -40,6 +40,7 @@
#include "gateway_client.h"
#include "hard-interface.h"
#include "hash.h"
+#include "log.h"
#include "multicast.h"
#include "network-coding.h"
#include "routing.h"
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index a6429d3..d1a6bad 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -41,6 +41,7 @@
#include "fragmentation.h"
#include "hard-interface.h"
#include "icmp_socket.h"
+#include "log.h"
#include "network-coding.h"
#include "originator.h"
#include "packet.h"
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 45ca6ac..6b82468 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -42,6 +42,7 @@
#include "fragmentation.h"
#include "gateway_client.h"
#include "hard-interface.h"
+#include "log.h"
#include "network-coding.h"
#include "originator.h"
#include "routing.h"
diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c
index 6244a9a..1a7942d 100644
--- a/net/batman-adv/sysfs.c
+++ b/net/batman-adv/sysfs.c
@@ -43,6 +43,7 @@
#include "gateway_client.h"
#include "gateway_common.h"
#include "hard-interface.h"
+#include "log.h"
#include "network-coding.h"
#include "packet.h"
#include "soft-interface.h"
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index e9e40b1..ae5811f 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -48,6 +48,7 @@
#include "bridge_loop_avoidance.h"
#include "hard-interface.h"
#include "hash.h"
+#include "log.h"
#include "multicast.h"
#include "originator.h"
#include "packet.h"
4 years, 8 months
[batman-adv] master: batman-adv: move bat_algo functions into a separate file (c14a11a)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit c14a11ab5ad7e4bc32e4e4f1fef149f263ad1a50
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Sun May 15 11:07:44 2016 +0200
batman-adv: move bat_algo functions into a separate file
The bat_algo functionality in main.c is mostly unrelated to the rest of the
content. It still takes up a large portion of this source file (~15%, 103
lines). Moving it to a separate file makes it better visible as a main
component of the batman-adv implementation and hides it less in the other
helper functions in main.c.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Marek Lindner <mareklindner(a)neomailbox.ch>
>---------------------------------------------------------------
c14a11ab5ad7e4bc32e4e4f1fef149f263ad1a50
net/batman-adv/Makefile | 1 +
net/batman-adv/bat_algo.c | 140 +++++++++++++++++++++++++++++++++++++
net/batman-adv/bat_algo.h | 12 ++++
net/batman-adv/bat_v_ogm.c | 1 +
net/batman-adv/debugfs.c | 1 +
net/batman-adv/main.c | 105 +---------------------------
net/batman-adv/main.h | 4 --
net/batman-adv/originator.c | 1 +
net/batman-adv/routing.c | 1 +
net/batman-adv/soft-interface.c | 1 +
net/batman-adv/translation-table.c | 1 +
11 files changed, 160 insertions(+), 108 deletions(-)
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile
index a688fc0..6ce53e5 100644
--- a/net/batman-adv/Makefile
+++ b/net/batman-adv/Makefile
@@ -17,6 +17,7 @@
#
obj-$(CONFIG_BATMAN_ADV) += batman-adv.o
+batman-adv-y += bat_algo.o
batman-adv-y += bat_iv_ogm.o
batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v.o
batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v_elp.o
diff --git a/net/batman-adv/bat_algo.c b/net/batman-adv/bat_algo.c
new file mode 100644
index 0000000..610d4de
--- /dev/null
+++ b/net/batman-adv/bat_algo.c
@@ -0,0 +1,140 @@
+/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner, Simon Wunderlich
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "main.h"
+
+#include <linux/errno.h>
+#include <linux/list.h>
+#include <linux/moduleparam.h>
+#include <linux/printk.h>
+#include <linux/seq_file.h>
+#include <linux/stddef.h>
+#include <linux/string.h>
+
+#include "bat_algo.h"
+
+char batadv_routing_algo[20] = "BATMAN_IV";
+static struct hlist_head batadv_algo_list;
+
+/**
+ * batadv_algo_init - Initialize batman-adv algorithm management data structures
+ */
+void batadv_algo_init(void)
+{
+ INIT_HLIST_HEAD(&batadv_algo_list);
+}
+
+static struct batadv_algo_ops *batadv_algo_get(char *name)
+{
+ struct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;
+
+ hlist_for_each_entry(bat_algo_ops_tmp, &batadv_algo_list, list) {
+ if (strcmp(bat_algo_ops_tmp->name, name) != 0)
+ continue;
+
+ bat_algo_ops = bat_algo_ops_tmp;
+ break;
+ }
+
+ return bat_algo_ops;
+}
+
+int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
+{
+ struct batadv_algo_ops *bat_algo_ops_tmp;
+
+ bat_algo_ops_tmp = batadv_algo_get(bat_algo_ops->name);
+ if (bat_algo_ops_tmp) {
+ pr_info("Trying to register already registered routing algorithm: %s\n",
+ bat_algo_ops->name);
+ return -EEXIST;
+ }
+
+ /* all algorithms must implement all ops (for now) */
+ if (!bat_algo_ops->bat_iface_enable ||
+ !bat_algo_ops->bat_iface_disable ||
+ !bat_algo_ops->bat_iface_update_mac ||
+ !bat_algo_ops->bat_primary_iface_set ||
+ !bat_algo_ops->bat_neigh_cmp ||
+ !bat_algo_ops->bat_neigh_is_similar_or_better) {
+ pr_info("Routing algo '%s' does not implement required ops\n",
+ bat_algo_ops->name);
+ return -EINVAL;
+ }
+
+ INIT_HLIST_NODE(&bat_algo_ops->list);
+ hlist_add_head(&bat_algo_ops->list, &batadv_algo_list);
+
+ return 0;
+}
+
+int batadv_algo_select(struct batadv_priv *bat_priv, char *name)
+{
+ struct batadv_algo_ops *bat_algo_ops;
+
+ bat_algo_ops = batadv_algo_get(name);
+ if (!bat_algo_ops)
+ return -EINVAL;
+
+ bat_priv->bat_algo_ops = bat_algo_ops;
+
+ return 0;
+}
+
+int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
+{
+ struct batadv_algo_ops *bat_algo_ops;
+
+ seq_puts(seq, "Available routing algorithms:\n");
+
+ hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) {
+ seq_printf(seq, " * %s\n", bat_algo_ops->name);
+ }
+
+ return 0;
+}
+
+static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
+{
+ struct batadv_algo_ops *bat_algo_ops;
+ char *algo_name = (char *)val;
+ size_t name_len = strlen(algo_name);
+
+ if (name_len > 0 && algo_name[name_len - 1] == '\n')
+ algo_name[name_len - 1] = '\0';
+
+ bat_algo_ops = batadv_algo_get(algo_name);
+ if (!bat_algo_ops) {
+ pr_err("Routing algorithm '%s' is not supported\n", algo_name);
+ return -EINVAL;
+ }
+
+ return param_set_copystring(algo_name, kp);
+}
+
+static const struct kernel_param_ops batadv_param_ops_ra = {
+ .set = batadv_param_set_ra,
+ .get = param_get_string,
+};
+
+static struct kparam_string batadv_param_string_ra = {
+ .maxlen = sizeof(batadv_routing_algo),
+ .string = batadv_routing_algo,
+};
+
+module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra,
+ 0644);
diff --git a/net/batman-adv/bat_algo.h b/net/batman-adv/bat_algo.h
index b727762..e178206 100644
--- a/net/batman-adv/bat_algo.h
+++ b/net/batman-adv/bat_algo.h
@@ -20,8 +20,20 @@
#include "main.h"
+#include <linux/types.h>
+
+struct seq_file;
+
int batadv_iv_init(void);
+extern char batadv_routing_algo[];
+extern struct list_head batadv_hardif_list;
+
+void batadv_algo_init(void);
+int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops);
+int batadv_algo_select(struct batadv_priv *bat_priv, char *name);
+int batadv_algo_seq_print_text(struct seq_file *seq, void *offset);
+
#ifdef CONFIG_BATMAN_ADV_BATMAN_V
int batadv_v_init(void);
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index ca5a679..93e3d76 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -39,6 +39,7 @@
#include <linux/types.h>
#include <linux/workqueue.h>
+#include "bat_algo.h"
#include "hard-interface.h"
#include "hash.h"
#include "originator.h"
diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c
index f187a8f..227c84b 100644
--- a/net/batman-adv/debugfs.c
+++ b/net/batman-adv/debugfs.c
@@ -44,6 +44,7 @@
#include <linux/wait.h>
#include <stdarg.h>
+#include "bat_algo.h"
#include "bridge_loop_avoidance.h"
#include "distributed-arp-table.h"
#include "gateway_client.h"
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 994ab82..04d20c4 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -32,7 +32,6 @@
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/module.h>
-#include <linux/moduleparam.h>
#include <linux/netdevice.h>
#include <linux/rculist.h>
#include <linux/rcupdate.h>
@@ -69,8 +68,6 @@
struct list_head batadv_hardif_list;
static int (*batadv_rx_handler[256])(struct sk_buff *,
struct batadv_hard_iface *);
-char batadv_routing_algo[20] = "BATMAN_IV";
-static struct hlist_head batadv_algo_list;
unsigned char batadv_broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
@@ -81,7 +78,7 @@ static void batadv_recv_handler_init(void);
static int __init batadv_init(void)
{
INIT_LIST_HEAD(&batadv_hardif_list);
- INIT_HLIST_HEAD(&batadv_algo_list);
+ batadv_algo_init();
batadv_recv_handler_init();
@@ -538,76 +535,6 @@ void batadv_recv_handler_unregister(u8 packet_type)
batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet;
}
-static struct batadv_algo_ops *batadv_algo_get(char *name)
-{
- struct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;
-
- hlist_for_each_entry(bat_algo_ops_tmp, &batadv_algo_list, list) {
- if (strcmp(bat_algo_ops_tmp->name, name) != 0)
- continue;
-
- bat_algo_ops = bat_algo_ops_tmp;
- break;
- }
-
- return bat_algo_ops;
-}
-
-int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
-{
- struct batadv_algo_ops *bat_algo_ops_tmp;
-
- bat_algo_ops_tmp = batadv_algo_get(bat_algo_ops->name);
- if (bat_algo_ops_tmp) {
- pr_info("Trying to register already registered routing algorithm: %s\n",
- bat_algo_ops->name);
- return -EEXIST;
- }
-
- /* all algorithms must implement all ops (for now) */
- if (!bat_algo_ops->bat_iface_enable ||
- !bat_algo_ops->bat_iface_disable ||
- !bat_algo_ops->bat_iface_update_mac ||
- !bat_algo_ops->bat_primary_iface_set ||
- !bat_algo_ops->bat_neigh_cmp ||
- !bat_algo_ops->bat_neigh_is_similar_or_better) {
- pr_info("Routing algo '%s' does not implement required ops\n",
- bat_algo_ops->name);
- return -EINVAL;
- }
-
- INIT_HLIST_NODE(&bat_algo_ops->list);
- hlist_add_head(&bat_algo_ops->list, &batadv_algo_list);
-
- return 0;
-}
-
-int batadv_algo_select(struct batadv_priv *bat_priv, char *name)
-{
- struct batadv_algo_ops *bat_algo_ops;
-
- bat_algo_ops = batadv_algo_get(name);
- if (!bat_algo_ops)
- return -EINVAL;
-
- bat_priv->bat_algo_ops = bat_algo_ops;
-
- return 0;
-}
-
-int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
-{
- struct batadv_algo_ops *bat_algo_ops;
-
- seq_puts(seq, "Available routing algorithms:\n");
-
- hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) {
- seq_printf(seq, " * %s\n", bat_algo_ops->name);
- }
-
- return 0;
-}
-
/**
* batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in
* the header
@@ -694,36 +621,6 @@ bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid)
return ap_isolation_enabled;
}
-static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
-{
- struct batadv_algo_ops *bat_algo_ops;
- char *algo_name = (char *)val;
- size_t name_len = strlen(algo_name);
-
- if (name_len > 0 && algo_name[name_len - 1] == '\n')
- algo_name[name_len - 1] = '\0';
-
- bat_algo_ops = batadv_algo_get(algo_name);
- if (!bat_algo_ops) {
- pr_err("Routing algorithm '%s' is not supported\n", algo_name);
- return -EINVAL;
- }
-
- return param_set_copystring(algo_name, kp);
-}
-
-static const struct kernel_param_ops batadv_param_ops_ra = {
- .set = batadv_param_set_ra,
- .get = param_get_string,
-};
-
-static struct kparam_string batadv_param_string_ra = {
- .maxlen = sizeof(batadv_routing_algo),
- .string = batadv_routing_algo,
-};
-
-module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra,
- 0644);
module_init(batadv_init);
module_exit(batadv_exit);
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index e523a38..91cc776 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -196,7 +196,6 @@ struct sk_buff;
#define BATADV_PRINT_VID(vid) ((vid & BATADV_VLAN_HAS_TAG) ? \
(int)(vid & VLAN_VID_MASK) : -1)
-extern char batadv_routing_algo[];
extern struct list_head batadv_hardif_list;
extern unsigned char batadv_broadcast_addr[];
@@ -217,9 +216,6 @@ batadv_recv_handler_register(u8 packet_type,
int (*recv_handler)(struct sk_buff *,
struct batadv_hard_iface *));
void batadv_recv_handler_unregister(u8 packet_type);
-int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops);
-int batadv_algo_select(struct batadv_priv *bat_priv, char *name);
-int batadv_algo_seq_print_text(struct seq_file *seq, void *offset);
__be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr);
/**
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 076d258..592cbda 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -34,6 +34,7 @@
#include <linux/spinlock.h>
#include <linux/workqueue.h>
+#include "bat_algo.h"
#include "distributed-arp-table.h"
#include "fragmentation.h"
#include "gateway_client.h"
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 1d66289..a6429d3 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -34,6 +34,7 @@
#include <linux/spinlock.h>
#include <linux/stddef.h>
+#include "bat_algo.h"
#include "bitarray.h"
#include "bridge_loop_avoidance.h"
#include "distributed-arp-table.h"
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index b60999d..f75631e 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -48,6 +48,7 @@
#include <linux/types.h>
#include <linux/workqueue.h>
+#include "bat_algo.h"
#include "bridge_loop_avoidance.h"
#include "debugfs.h"
#include "distributed-arp-table.h"
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index fcbe287..e9e40b1 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -44,6 +44,7 @@
#include <linux/string.h>
#include <linux/workqueue.h>
+#include "bat_algo.h"
#include "bridge_loop_avoidance.h"
#include "hard-interface.h"
#include "hash.h"
4 years, 8 months
[batman-adv] master: batman-adv: split tvlv into a separate file (65326e3)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 65326e3965dc5ff1863e26b3387510497d18ee8b
Author: Markus Pargmann <mpa(a)pengutronix.de>
Date: Sun May 15 11:07:43 2016 +0200
batman-adv: split tvlv into a separate file
The tvlv functionality in main.c is mostly unrelated to the rest of the
content. It still takes up a large portion of this source file (~45%, 588
lines). Moving it to a separate file makes it better visible as a main
component of the batman-adv implementation and hides it less in the other
helper functions in main.c
Signed-off-by: Markus Pargmann <mpa(a)pengutronix.de>
[sven(a)narfation.org: fix conflicts with current version, fix includes,
rewrote commit message]
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Marek Lindner <mareklindner(a)neomailbox.ch>
>---------------------------------------------------------------
65326e3965dc5ff1863e26b3387510497d18ee8b
net/batman-adv/Makefile | 1 +
net/batman-adv/bat_iv_ogm.c | 1 +
net/batman-adv/bat_v_ogm.c | 1 +
net/batman-adv/distributed-arp-table.c | 1 +
net/batman-adv/gateway_common.c | 1 +
net/batman-adv/main.c | 591 ---------------------------
net/batman-adv/main.h | 34 --
net/batman-adv/multicast.c | 1 +
net/batman-adv/network-coding.c | 1 +
net/batman-adv/routing.c | 1 +
net/batman-adv/translation-table.c | 1 +
net/batman-adv/{main.c => tvlv.c} | 704 +--------------------------------
net/batman-adv/tvlv.h | 61 +++
13 files changed, 74 insertions(+), 1325 deletions(-)
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile
index 4e5adba..a688fc0 100644
--- a/net/batman-adv/Makefile
+++ b/net/batman-adv/Makefile
@@ -41,3 +41,4 @@ batman-adv-y += send.o
batman-adv-y += soft-interface.o
batman-adv-y += sysfs.o
batman-adv-y += translation-table.o
+batman-adv-y += tvlv.o
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 6dc89b0..948a5b4 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -58,6 +58,7 @@
#include "routing.h"
#include "send.h"
#include "translation-table.h"
+#include "tvlv.h"
static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work);
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index 23ea9bf..ca5a679 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -46,6 +46,7 @@
#include "routing.h"
#include "send.h"
#include "translation-table.h"
+#include "tvlv.h"
/**
* batadv_v_ogm_orig_get - retrieve and possibly create an originator node
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index 278800a..584b827 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -48,6 +48,7 @@
#include "originator.h"
#include "send.h"
#include "translation-table.h"
+#include "tvlv.h"
static void batadv_dat_purge(struct work_struct *work);
diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c
index 7754435..6a6f2d4 100644
--- a/net/batman-adv/gateway_common.c
+++ b/net/batman-adv/gateway_common.c
@@ -29,6 +29,7 @@
#include "gateway_client.h"
#include "packet.h"
+#include "tvlv.h"
/**
* batadv_parse_throughput - parse supplied string buffer to extract throughput
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index e78b318..994ab82 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -31,16 +31,13 @@
#include <linux/kernel.h>
#include <linux/kref.h>
#include <linux/list.h>
-#include <linux/lockdep.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/netdevice.h>
-#include <linux/pkt_sched.h>
#include <linux/rculist.h>
#include <linux/rcupdate.h>
#include <linux/seq_file.h>
#include <linux/skbuff.h>
-#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/stddef.h>
#include <linux/string.h>
@@ -645,594 +642,6 @@ __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
}
/**
- * batadv_tvlv_handler_release - release tvlv handler from lists and queue for
- * free after rcu grace period
- * @ref: kref pointer of the tvlv
- */
-static void batadv_tvlv_handler_release(struct kref *ref)
-{
- struct batadv_tvlv_handler *tvlv_handler;
-
- tvlv_handler = container_of(ref, struct batadv_tvlv_handler, refcount);
- kfree_rcu(tvlv_handler, rcu);
-}
-
-/**
- * batadv_tvlv_handler_put - decrement the tvlv container refcounter and
- * possibly release it
- * @tvlv_handler: the tvlv handler to free
- */
-static void batadv_tvlv_handler_put(struct batadv_tvlv_handler *tvlv_handler)
-{
- kref_put(&tvlv_handler->refcount, batadv_tvlv_handler_release);
-}
-
-/**
- * batadv_tvlv_handler_get - retrieve tvlv handler from the tvlv handler list
- * based on the provided type and version (both need to match)
- * @bat_priv: the bat priv with all the soft interface information
- * @type: tvlv handler type to look for
- * @version: tvlv handler version to look for
- *
- * Return: tvlv handler if found or NULL otherwise.
- */
-static struct batadv_tvlv_handler *
-batadv_tvlv_handler_get(struct batadv_priv *bat_priv, u8 type, u8 version)
-{
- struct batadv_tvlv_handler *tvlv_handler_tmp, *tvlv_handler = NULL;
-
- rcu_read_lock();
- hlist_for_each_entry_rcu(tvlv_handler_tmp,
- &bat_priv->tvlv.handler_list, list) {
- if (tvlv_handler_tmp->type != type)
- continue;
-
- if (tvlv_handler_tmp->version != version)
- continue;
-
- if (!kref_get_unless_zero(&tvlv_handler_tmp->refcount))
- continue;
-
- tvlv_handler = tvlv_handler_tmp;
- break;
- }
- rcu_read_unlock();
-
- return tvlv_handler;
-}
-
-/**
- * batadv_tvlv_container_release - release tvlv from lists and free
- * @ref: kref pointer of the tvlv
- */
-static void batadv_tvlv_container_release(struct kref *ref)
-{
- struct batadv_tvlv_container *tvlv;
-
- tvlv = container_of(ref, struct batadv_tvlv_container, refcount);
- kfree(tvlv);
-}
-
-/**
- * batadv_tvlv_container_put - decrement the tvlv container refcounter and
- * possibly release it
- * @tvlv: the tvlv container to free
- */
-static void batadv_tvlv_container_put(struct batadv_tvlv_container *tvlv)
-{
- kref_put(&tvlv->refcount, batadv_tvlv_container_release);
-}
-
-/**
- * batadv_tvlv_container_get - retrieve tvlv container from the tvlv container
- * list based on the provided type and version (both need to match)
- * @bat_priv: the bat priv with all the soft interface information
- * @type: tvlv container type to look for
- * @version: tvlv container version to look for
- *
- * Has to be called with the appropriate locks being acquired
- * (tvlv.container_list_lock).
- *
- * Return: tvlv container if found or NULL otherwise.
- */
-static struct batadv_tvlv_container *
-batadv_tvlv_container_get(struct batadv_priv *bat_priv, u8 type, u8 version)
-{
- struct batadv_tvlv_container *tvlv_tmp, *tvlv = NULL;
-
- lockdep_assert_held(&bat_priv->tvlv.container_list_lock);
-
- hlist_for_each_entry(tvlv_tmp, &bat_priv->tvlv.container_list, list) {
- if (tvlv_tmp->tvlv_hdr.type != type)
- continue;
-
- if (tvlv_tmp->tvlv_hdr.version != version)
- continue;
-
- kref_get(&tvlv_tmp->refcount);
- tvlv = tvlv_tmp;
- break;
- }
-
- return tvlv;
-}
-
-/**
- * batadv_tvlv_container_list_size - calculate the size of the tvlv container
- * list entries
- * @bat_priv: the bat priv with all the soft interface information
- *
- * Has to be called with the appropriate locks being acquired
- * (tvlv.container_list_lock).
- *
- * Return: size of all currently registered tvlv containers in bytes.
- */
-static u16 batadv_tvlv_container_list_size(struct batadv_priv *bat_priv)
-{
- struct batadv_tvlv_container *tvlv;
- u16 tvlv_len = 0;
-
- lockdep_assert_held(&bat_priv->tvlv.container_list_lock);
-
- hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) {
- tvlv_len += sizeof(struct batadv_tvlv_hdr);
- tvlv_len += ntohs(tvlv->tvlv_hdr.len);
- }
-
- return tvlv_len;
-}
-
-/**
- * batadv_tvlv_container_remove - remove tvlv container from the tvlv container
- * list
- * @bat_priv: the bat priv with all the soft interface information
- * @tvlv: the to be removed tvlv container
- *
- * Has to be called with the appropriate locks being acquired
- * (tvlv.container_list_lock).
- */
-static void batadv_tvlv_container_remove(struct batadv_priv *bat_priv,
- struct batadv_tvlv_container *tvlv)
-{
- lockdep_assert_held(&bat_priv->tvlv.container_list_lock);
-
- if (!tvlv)
- return;
-
- hlist_del(&tvlv->list);
-
- /* first call to decrement the counter, second call to free */
- batadv_tvlv_container_put(tvlv);
- batadv_tvlv_container_put(tvlv);
-}
-
-/**
- * batadv_tvlv_container_unregister - unregister tvlv container based on the
- * provided type and version (both need to match)
- * @bat_priv: the bat priv with all the soft interface information
- * @type: tvlv container type to unregister
- * @version: tvlv container type to unregister
- */
-void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv,
- u8 type, u8 version)
-{
- struct batadv_tvlv_container *tvlv;
-
- spin_lock_bh(&bat_priv->tvlv.container_list_lock);
- tvlv = batadv_tvlv_container_get(bat_priv, type, version);
- batadv_tvlv_container_remove(bat_priv, tvlv);
- spin_unlock_bh(&bat_priv->tvlv.container_list_lock);
-}
-
-/**
- * batadv_tvlv_container_register - register tvlv type, version and content
- * to be propagated with each (primary interface) OGM
- * @bat_priv: the bat priv with all the soft interface information
- * @type: tvlv container type
- * @version: tvlv container version
- * @tvlv_value: tvlv container content
- * @tvlv_value_len: tvlv container content length
- *
- * If a container of the same type and version was already registered the new
- * content is going to replace the old one.
- */
-void batadv_tvlv_container_register(struct batadv_priv *bat_priv,
- u8 type, u8 version,
- void *tvlv_value, u16 tvlv_value_len)
-{
- struct batadv_tvlv_container *tvlv_old, *tvlv_new;
-
- if (!tvlv_value)
- tvlv_value_len = 0;
-
- tvlv_new = kzalloc(sizeof(*tvlv_new) + tvlv_value_len, GFP_ATOMIC);
- if (!tvlv_new)
- return;
-
- tvlv_new->tvlv_hdr.version = version;
- tvlv_new->tvlv_hdr.type = type;
- tvlv_new->tvlv_hdr.len = htons(tvlv_value_len);
-
- memcpy(tvlv_new + 1, tvlv_value, ntohs(tvlv_new->tvlv_hdr.len));
- INIT_HLIST_NODE(&tvlv_new->list);
- kref_init(&tvlv_new->refcount);
-
- spin_lock_bh(&bat_priv->tvlv.container_list_lock);
- tvlv_old = batadv_tvlv_container_get(bat_priv, type, version);
- batadv_tvlv_container_remove(bat_priv, tvlv_old);
- hlist_add_head(&tvlv_new->list, &bat_priv->tvlv.container_list);
- spin_unlock_bh(&bat_priv->tvlv.container_list_lock);
-}
-
-/**
- * batadv_tvlv_realloc_packet_buff - reallocate packet buffer to accommodate
- * requested packet size
- * @packet_buff: packet buffer
- * @packet_buff_len: packet buffer size
- * @min_packet_len: requested packet minimum size
- * @additional_packet_len: requested additional packet size on top of minimum
- * size
- *
- * Return: true of the packet buffer could be changed to the requested size,
- * false otherwise.
- */
-static bool batadv_tvlv_realloc_packet_buff(unsigned char **packet_buff,
- int *packet_buff_len,
- int min_packet_len,
- int additional_packet_len)
-{
- unsigned char *new_buff;
-
- new_buff = kmalloc(min_packet_len + additional_packet_len, GFP_ATOMIC);
-
- /* keep old buffer if kmalloc should fail */
- if (!new_buff)
- return false;
-
- memcpy(new_buff, *packet_buff, min_packet_len);
- kfree(*packet_buff);
- *packet_buff = new_buff;
- *packet_buff_len = min_packet_len + additional_packet_len;
-
- return true;
-}
-
-/**
- * batadv_tvlv_container_ogm_append - append tvlv container content to given
- * OGM packet buffer
- * @bat_priv: the bat priv with all the soft interface information
- * @packet_buff: ogm packet buffer
- * @packet_buff_len: ogm packet buffer size including ogm header and tvlv
- * content
- * @packet_min_len: ogm header size to be preserved for the OGM itself
- *
- * The ogm packet might be enlarged or shrunk depending on the current size
- * and the size of the to-be-appended tvlv containers.
- *
- * Return: size of all appended tvlv containers in bytes.
- */
-u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,
- unsigned char **packet_buff,
- int *packet_buff_len, int packet_min_len)
-{
- struct batadv_tvlv_container *tvlv;
- struct batadv_tvlv_hdr *tvlv_hdr;
- u16 tvlv_value_len;
- void *tvlv_value;
- bool ret;
-
- spin_lock_bh(&bat_priv->tvlv.container_list_lock);
- tvlv_value_len = batadv_tvlv_container_list_size(bat_priv);
-
- ret = batadv_tvlv_realloc_packet_buff(packet_buff, packet_buff_len,
- packet_min_len, tvlv_value_len);
-
- if (!ret)
- goto end;
-
- if (!tvlv_value_len)
- goto end;
-
- tvlv_value = (*packet_buff) + packet_min_len;
-
- hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) {
- tvlv_hdr = tvlv_value;
- tvlv_hdr->type = tvlv->tvlv_hdr.type;
- tvlv_hdr->version = tvlv->tvlv_hdr.version;
- tvlv_hdr->len = tvlv->tvlv_hdr.len;
- tvlv_value = tvlv_hdr + 1;
- memcpy(tvlv_value, tvlv + 1, ntohs(tvlv->tvlv_hdr.len));
- tvlv_value = (u8 *)tvlv_value + ntohs(tvlv->tvlv_hdr.len);
- }
-
-end:
- spin_unlock_bh(&bat_priv->tvlv.container_list_lock);
- return tvlv_value_len;
-}
-
-/**
- * batadv_tvlv_call_handler - parse the given tvlv buffer to call the
- * appropriate handlers
- * @bat_priv: the bat priv with all the soft interface information
- * @tvlv_handler: tvlv callback function handling the tvlv content
- * @ogm_source: flag indicating whether the tvlv is an ogm or a unicast packet
- * @orig_node: orig node emitting the ogm packet
- * @src: source mac address of the unicast packet
- * @dst: destination mac address of the unicast packet
- * @tvlv_value: tvlv content
- * @tvlv_value_len: tvlv content length
- *
- * Return: success if handler was not found or the return value of the handler
- * callback.
- */
-static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv,
- struct batadv_tvlv_handler *tvlv_handler,
- bool ogm_source,
- struct batadv_orig_node *orig_node,
- u8 *src, u8 *dst,
- void *tvlv_value, u16 tvlv_value_len)
-{
- if (!tvlv_handler)
- return NET_RX_SUCCESS;
-
- if (ogm_source) {
- if (!tvlv_handler->ogm_handler)
- return NET_RX_SUCCESS;
-
- if (!orig_node)
- return NET_RX_SUCCESS;
-
- tvlv_handler->ogm_handler(bat_priv, orig_node,
- BATADV_NO_FLAGS,
- tvlv_value, tvlv_value_len);
- tvlv_handler->flags |= BATADV_TVLV_HANDLER_OGM_CALLED;
- } else {
- if (!src)
- return NET_RX_SUCCESS;
-
- if (!dst)
- return NET_RX_SUCCESS;
-
- if (!tvlv_handler->unicast_handler)
- return NET_RX_SUCCESS;
-
- return tvlv_handler->unicast_handler(bat_priv, src,
- dst, tvlv_value,
- tvlv_value_len);
- }
-
- return NET_RX_SUCCESS;
-}
-
-/**
- * batadv_tvlv_containers_process - parse the given tvlv buffer to call the
- * appropriate handlers
- * @bat_priv: the bat priv with all the soft interface information
- * @ogm_source: flag indicating whether the tvlv is an ogm or a unicast packet
- * @orig_node: orig node emitting the ogm packet
- * @src: source mac address of the unicast packet
- * @dst: destination mac address of the unicast packet
- * @tvlv_value: tvlv content
- * @tvlv_value_len: tvlv content length
- *
- * Return: success when processing an OGM or the return value of all called
- * handler callbacks.
- */
-int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
- bool ogm_source,
- struct batadv_orig_node *orig_node,
- u8 *src, u8 *dst,
- void *tvlv_value, u16 tvlv_value_len)
-{
- struct batadv_tvlv_handler *tvlv_handler;
- struct batadv_tvlv_hdr *tvlv_hdr;
- u16 tvlv_value_cont_len;
- u8 cifnotfound = BATADV_TVLV_HANDLER_OGM_CIFNOTFND;
- int ret = NET_RX_SUCCESS;
-
- while (tvlv_value_len >= sizeof(*tvlv_hdr)) {
- tvlv_hdr = tvlv_value;
- tvlv_value_cont_len = ntohs(tvlv_hdr->len);
- tvlv_value = tvlv_hdr + 1;
- tvlv_value_len -= sizeof(*tvlv_hdr);
-
- if (tvlv_value_cont_len > tvlv_value_len)
- break;
-
- tvlv_handler = batadv_tvlv_handler_get(bat_priv,
- tvlv_hdr->type,
- tvlv_hdr->version);
-
- ret |= batadv_tvlv_call_handler(bat_priv, tvlv_handler,
- ogm_source, orig_node,
- src, dst, tvlv_value,
- tvlv_value_cont_len);
- if (tvlv_handler)
- batadv_tvlv_handler_put(tvlv_handler);
- tvlv_value = (u8 *)tvlv_value + tvlv_value_cont_len;
- tvlv_value_len -= tvlv_value_cont_len;
- }
-
- if (!ogm_source)
- return ret;
-
- rcu_read_lock();
- hlist_for_each_entry_rcu(tvlv_handler,
- &bat_priv->tvlv.handler_list, list) {
- if ((tvlv_handler->flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND) &&
- !(tvlv_handler->flags & BATADV_TVLV_HANDLER_OGM_CALLED))
- tvlv_handler->ogm_handler(bat_priv, orig_node,
- cifnotfound, NULL, 0);
-
- tvlv_handler->flags &= ~BATADV_TVLV_HANDLER_OGM_CALLED;
- }
- rcu_read_unlock();
-
- return NET_RX_SUCCESS;
-}
-
-/**
- * batadv_tvlv_ogm_receive - process an incoming ogm and call the appropriate
- * handlers
- * @bat_priv: the bat priv with all the soft interface information
- * @batadv_ogm_packet: ogm packet containing the tvlv containers
- * @orig_node: orig node emitting the ogm packet
- */
-void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,
- struct batadv_ogm_packet *batadv_ogm_packet,
- struct batadv_orig_node *orig_node)
-{
- void *tvlv_value;
- u16 tvlv_value_len;
-
- if (!batadv_ogm_packet)
- return;
-
- tvlv_value_len = ntohs(batadv_ogm_packet->tvlv_len);
- if (!tvlv_value_len)
- return;
-
- tvlv_value = batadv_ogm_packet + 1;
-
- batadv_tvlv_containers_process(bat_priv, true, orig_node, NULL, NULL,
- tvlv_value, tvlv_value_len);
-}
-
-/**
- * batadv_tvlv_handler_register - register tvlv handler based on the provided
- * type and version (both need to match) for ogm tvlv payload and/or unicast
- * payload
- * @bat_priv: the bat priv with all the soft interface information
- * @optr: ogm tvlv handler callback function. This function receives the orig
- * node, flags and the tvlv content as argument to process.
- * @uptr: unicast tvlv handler callback function. This function receives the
- * source & destination of the unicast packet as well as the tvlv content
- * to process.
- * @type: tvlv handler type to be registered
- * @version: tvlv handler version to be registered
- * @flags: flags to enable or disable TVLV API behavior
- */
-void batadv_tvlv_handler_register(struct batadv_priv *bat_priv,
- void (*optr)(struct batadv_priv *bat_priv,
- struct batadv_orig_node *orig,
- u8 flags,
- void *tvlv_value,
- u16 tvlv_value_len),
- int (*uptr)(struct batadv_priv *bat_priv,
- u8 *src, u8 *dst,
- void *tvlv_value,
- u16 tvlv_value_len),
- u8 type, u8 version, u8 flags)
-{
- struct batadv_tvlv_handler *tvlv_handler;
-
- tvlv_handler = batadv_tvlv_handler_get(bat_priv, type, version);
- if (tvlv_handler) {
- batadv_tvlv_handler_put(tvlv_handler);
- return;
- }
-
- tvlv_handler = kzalloc(sizeof(*tvlv_handler), GFP_ATOMIC);
- if (!tvlv_handler)
- return;
-
- tvlv_handler->ogm_handler = optr;
- tvlv_handler->unicast_handler = uptr;
- tvlv_handler->type = type;
- tvlv_handler->version = version;
- tvlv_handler->flags = flags;
- kref_init(&tvlv_handler->refcount);
- INIT_HLIST_NODE(&tvlv_handler->list);
-
- spin_lock_bh(&bat_priv->tvlv.handler_list_lock);
- hlist_add_head_rcu(&tvlv_handler->list, &bat_priv->tvlv.handler_list);
- spin_unlock_bh(&bat_priv->tvlv.handler_list_lock);
-}
-
-/**
- * batadv_tvlv_handler_unregister - unregister tvlv handler based on the
- * provided type and version (both need to match)
- * @bat_priv: the bat priv with all the soft interface information
- * @type: tvlv handler type to be unregistered
- * @version: tvlv handler version to be unregistered
- */
-void batadv_tvlv_handler_unregister(struct batadv_priv *bat_priv,
- u8 type, u8 version)
-{
- struct batadv_tvlv_handler *tvlv_handler;
-
- tvlv_handler = batadv_tvlv_handler_get(bat_priv, type, version);
- if (!tvlv_handler)
- return;
-
- batadv_tvlv_handler_put(tvlv_handler);
- spin_lock_bh(&bat_priv->tvlv.handler_list_lock);
- hlist_del_rcu(&tvlv_handler->list);
- spin_unlock_bh(&bat_priv->tvlv.handler_list_lock);
- batadv_tvlv_handler_put(tvlv_handler);
-}
-
-/**
- * batadv_tvlv_unicast_send - send a unicast packet with tvlv payload to the
- * specified host
- * @bat_priv: the bat priv with all the soft interface information
- * @src: source mac address of the unicast packet
- * @dst: destination mac address of the unicast packet
- * @type: tvlv type
- * @version: tvlv version
- * @tvlv_value: tvlv content
- * @tvlv_value_len: tvlv content length
- */
-void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
- u8 *dst, u8 type, u8 version,
- void *tvlv_value, u16 tvlv_value_len)
-{
- struct batadv_unicast_tvlv_packet *unicast_tvlv_packet;
- struct batadv_tvlv_hdr *tvlv_hdr;
- struct batadv_orig_node *orig_node;
- struct sk_buff *skb;
- unsigned char *tvlv_buff;
- unsigned int tvlv_len;
- ssize_t hdr_len = sizeof(*unicast_tvlv_packet);
-
- orig_node = batadv_orig_hash_find(bat_priv, dst);
- if (!orig_node)
- return;
-
- tvlv_len = sizeof(*tvlv_hdr) + tvlv_value_len;
-
- skb = netdev_alloc_skb_ip_align(NULL, ETH_HLEN + hdr_len + tvlv_len);
- if (!skb)
- goto out;
-
- skb->priority = TC_PRIO_CONTROL;
- skb_reserve(skb, ETH_HLEN);
- tvlv_buff = skb_put(skb, sizeof(*unicast_tvlv_packet) + tvlv_len);
- unicast_tvlv_packet = (struct batadv_unicast_tvlv_packet *)tvlv_buff;
- unicast_tvlv_packet->packet_type = BATADV_UNICAST_TVLV;
- unicast_tvlv_packet->version = BATADV_COMPAT_VERSION;
- unicast_tvlv_packet->ttl = BATADV_TTL;
- unicast_tvlv_packet->reserved = 0;
- unicast_tvlv_packet->tvlv_len = htons(tvlv_len);
- unicast_tvlv_packet->align = 0;
- ether_addr_copy(unicast_tvlv_packet->src, src);
- ether_addr_copy(unicast_tvlv_packet->dst, dst);
-
- tvlv_buff = (unsigned char *)(unicast_tvlv_packet + 1);
- tvlv_hdr = (struct batadv_tvlv_hdr *)tvlv_buff;
- tvlv_hdr->version = version;
- tvlv_hdr->type = type;
- tvlv_hdr->len = htons(tvlv_value_len);
- tvlv_buff += sizeof(*tvlv_hdr);
- memcpy(tvlv_buff, tvlv_value, tvlv_value_len);
-
- if (batadv_send_skb_to_orig(skb, orig_node, NULL) == NET_XMIT_DROP)
- kfree_skb(skb);
-out:
- batadv_orig_node_put(orig_node);
-}
-
-/**
* batadv_get_vid - extract the VLAN identifier from skb if any
* @skb: the buffer containing the packet
* @header_len: length of the batman header preceding the ethernet header
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 94bf4f8..e523a38 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -190,7 +190,6 @@ enum batadv_uev_type {
#include "types.h"
-struct batadv_ogm_packet;
struct seq_file;
struct sk_buff;
@@ -372,39 +371,6 @@ static inline u64 batadv_sum_counter(struct batadv_priv *bat_priv, size_t idx)
*/
#define BATADV_SKB_CB(__skb) ((struct batadv_skb_cb *)&((__skb)->cb[0]))
-void batadv_tvlv_container_register(struct batadv_priv *bat_priv,
- u8 type, u8 version,
- void *tvlv_value, u16 tvlv_value_len);
-u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,
- unsigned char **packet_buff,
- int *packet_buff_len, int packet_min_len);
-void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,
- struct batadv_ogm_packet *batadv_ogm_packet,
- struct batadv_orig_node *orig_node);
-void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv,
- u8 type, u8 version);
-
-void batadv_tvlv_handler_register(struct batadv_priv *bat_priv,
- void (*optr)(struct batadv_priv *bat_priv,
- struct batadv_orig_node *orig,
- u8 flags,
- void *tvlv_value,
- u16 tvlv_value_len),
- int (*uptr)(struct batadv_priv *bat_priv,
- u8 *src, u8 *dst,
- void *tvlv_value,
- u16 tvlv_value_len),
- u8 type, u8 version, u8 flags);
-void batadv_tvlv_handler_unregister(struct batadv_priv *bat_priv,
- u8 type, u8 version);
-int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
- bool ogm_source,
- struct batadv_orig_node *orig_node,
- u8 *src, u8 *dst,
- void *tvlv_buff, u16 tvlv_buff_len);
-void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
- u8 *dst, u8 type, u8 version,
- void *tvlv_value, u16 tvlv_value_len);
unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len);
bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid);
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index d3222db..0e7d78f 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -57,6 +57,7 @@
#include "hash.h"
#include "packet.h"
#include "translation-table.h"
+#include "tvlv.h"
/**
* batadv_mcast_get_bridge - get the bridge on top of the softif if it exists
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index 678f068..d0383de 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -55,6 +55,7 @@
#include "packet.h"
#include "routing.h"
#include "send.h"
+#include "tvlv.h"
static struct lock_class_key batadv_nc_coding_hash_lock_class_key;
static struct lock_class_key batadv_nc_decoding_hash_lock_class_key;
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 93ee5c7..1d66289 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -46,6 +46,7 @@
#include "send.h"
#include "soft-interface.h"
#include "translation-table.h"
+#include "tvlv.h"
static int batadv_route_unicast_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if);
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 72abab7..fcbe287 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -51,6 +51,7 @@
#include "originator.h"
#include "packet.h"
#include "soft-interface.h"
+#include "tvlv.h"
/* hash class keys */
static struct lock_class_key batadv_tt_local_hash_lock_class_key;
diff --git a/net/batman-adv/main.c b/net/batman-adv/tvlv.c
similarity index 50%
copy from net/batman-adv/main.c
copy to net/batman-adv/tvlv.c
index e78b318..2fd542e 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/tvlv.c
@@ -17,632 +17,29 @@
#include "main.h"
-#include <linux/atomic.h>
-#include <linux/bug.h>
#include <linux/byteorder/generic.h>
-#include <linux/crc32c.h>
-#include <linux/errno.h>
+#include <linux/etherdevice.h>
#include <linux/fs.h>
#include <linux/if_ether.h>
-#include <linux/if_vlan.h>
-#include <linux/init.h>
-#include <linux/ip.h>
-#include <linux/ipv6.h>
#include <linux/kernel.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/lockdep.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
#include <linux/netdevice.h>
#include <linux/pkt_sched.h>
#include <linux/rculist.h>
#include <linux/rcupdate.h>
-#include <linux/seq_file.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/stddef.h>
#include <linux/string.h>
-#include <linux/workqueue.h>
-#include <net/dsfield.h>
-#include <net/rtnetlink.h>
-
-#include "bat_algo.h"
-#include "bridge_loop_avoidance.h"
-#include "debugfs.h"
-#include "distributed-arp-table.h"
-#include "gateway_client.h"
-#include "gateway_common.h"
-#include "hard-interface.h"
-#include "icmp_socket.h"
-#include "multicast.h"
-#include "netlink.h"
-#include "network-coding.h"
+#include <linux/types.h>
+
#include "originator.h"
#include "packet.h"
-#include "routing.h"
#include "send.h"
-#include "soft-interface.h"
-#include "translation-table.h"
-
-/* List manipulations on hardif_list have to be rtnl_lock()'ed,
- * list traversals just rcu-locked
- */
-struct list_head batadv_hardif_list;
-static int (*batadv_rx_handler[256])(struct sk_buff *,
- struct batadv_hard_iface *);
-char batadv_routing_algo[20] = "BATMAN_IV";
-static struct hlist_head batadv_algo_list;
-
-unsigned char batadv_broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-
-struct workqueue_struct *batadv_event_workqueue;
-
-static void batadv_recv_handler_init(void);
-
-static int __init batadv_init(void)
-{
- INIT_LIST_HEAD(&batadv_hardif_list);
- INIT_HLIST_HEAD(&batadv_algo_list);
-
- batadv_recv_handler_init();
-
- batadv_v_init();
- batadv_iv_init();
- batadv_nc_init();
-
- batadv_event_workqueue = create_singlethread_workqueue("bat_events");
-
- if (!batadv_event_workqueue)
- return -ENOMEM;
-
- batadv_socket_init();
- batadv_debugfs_init();
-
- register_netdevice_notifier(&batadv_hard_if_notifier);
- rtnl_link_register(&batadv_link_ops);
- batadv_netlink_register();
-
- pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n",
- BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION);
-
- return 0;
-}
-
-static void __exit batadv_exit(void)
-{
- batadv_debugfs_destroy();
- batadv_netlink_unregister();
- rtnl_link_unregister(&batadv_link_ops);
- unregister_netdevice_notifier(&batadv_hard_if_notifier);
- batadv_hardif_remove_interfaces();
-
- flush_workqueue(batadv_event_workqueue);
- destroy_workqueue(batadv_event_workqueue);
- batadv_event_workqueue = NULL;
-
- rcu_barrier();
-}
-
-int batadv_mesh_init(struct net_device *soft_iface)
-{
- struct batadv_priv *bat_priv = netdev_priv(soft_iface);
- int ret;
-
- spin_lock_init(&bat_priv->forw_bat_list_lock);
- spin_lock_init(&bat_priv->forw_bcast_list_lock);
- spin_lock_init(&bat_priv->tt.changes_list_lock);
- spin_lock_init(&bat_priv->tt.req_list_lock);
- spin_lock_init(&bat_priv->tt.roam_list_lock);
- spin_lock_init(&bat_priv->tt.last_changeset_lock);
- spin_lock_init(&bat_priv->tt.commit_lock);
- spin_lock_init(&bat_priv->gw.list_lock);
-#ifdef CONFIG_BATMAN_ADV_MCAST
- spin_lock_init(&bat_priv->mcast.want_lists_lock);
-#endif
- spin_lock_init(&bat_priv->tvlv.container_list_lock);
- spin_lock_init(&bat_priv->tvlv.handler_list_lock);
- spin_lock_init(&bat_priv->softif_vlan_list_lock);
-
- INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
- INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
- INIT_HLIST_HEAD(&bat_priv->gw.list);
-#ifdef CONFIG_BATMAN_ADV_MCAST
- INIT_HLIST_HEAD(&bat_priv->mcast.want_all_unsnoopables_list);
- INIT_HLIST_HEAD(&bat_priv->mcast.want_all_ipv4_list);
- INIT_HLIST_HEAD(&bat_priv->mcast.want_all_ipv6_list);
-#endif
- INIT_LIST_HEAD(&bat_priv->tt.changes_list);
- INIT_HLIST_HEAD(&bat_priv->tt.req_list);
- INIT_LIST_HEAD(&bat_priv->tt.roam_list);
-#ifdef CONFIG_BATMAN_ADV_MCAST
- INIT_HLIST_HEAD(&bat_priv->mcast.mla_list);
-#endif
- INIT_HLIST_HEAD(&bat_priv->tvlv.container_list);
- INIT_HLIST_HEAD(&bat_priv->tvlv.handler_list);
- INIT_HLIST_HEAD(&bat_priv->softif_vlan_list);
-
- ret = batadv_v_mesh_init(bat_priv);
- if (ret < 0)
- goto err;
-
- ret = batadv_originator_init(bat_priv);
- if (ret < 0)
- goto err;
-
- ret = batadv_tt_init(bat_priv);
- if (ret < 0)
- goto err;
-
- ret = batadv_bla_init(bat_priv);
- if (ret < 0)
- goto err;
-
- ret = batadv_dat_init(bat_priv);
- if (ret < 0)
- goto err;
-
- ret = batadv_nc_mesh_init(bat_priv);
- if (ret < 0)
- goto err;
-
- batadv_gw_init(bat_priv);
- batadv_mcast_init(bat_priv);
-
- atomic_set(&bat_priv->gw.reselect, 0);
- atomic_set(&bat_priv->mesh_state, BATADV_MESH_ACTIVE);
-
- return 0;
-
-err:
- batadv_mesh_free(soft_iface);
- return ret;
-}
-
-void batadv_mesh_free(struct net_device *soft_iface)
-{
- struct batadv_priv *bat_priv = netdev_priv(soft_iface);
-
- atomic_set(&bat_priv->mesh_state, BATADV_MESH_DEACTIVATING);
-
- batadv_purge_outstanding_packets(bat_priv, NULL);
-
- batadv_gw_node_free(bat_priv);
-
- batadv_v_mesh_free(bat_priv);
- batadv_nc_mesh_free(bat_priv);
- batadv_dat_free(bat_priv);
- batadv_bla_free(bat_priv);
-
- batadv_mcast_free(bat_priv);
-
- /* Free the TT and the originator tables only after having terminated
- * all the other depending components which may use these structures for
- * their purposes.
- */
- batadv_tt_free(bat_priv);
-
- /* Since the originator table clean up routine is accessing the TT
- * tables as well, it has to be invoked after the TT tables have been
- * freed and marked as empty. This ensures that no cleanup RCU callbacks
- * accessing the TT data are scheduled for later execution.
- */
- batadv_originator_free(bat_priv);
-
- batadv_gw_free(bat_priv);
-
- free_percpu(bat_priv->bat_counters);
- bat_priv->bat_counters = NULL;
-
- atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
-}
-
-/**
- * batadv_is_my_mac - check if the given mac address belongs to any of the real
- * interfaces in the current mesh
- * @bat_priv: the bat priv with all the soft interface information
- * @addr: the address to check
- *
- * Return: 'true' if the mac address was found, false otherwise.
- */
-bool batadv_is_my_mac(struct batadv_priv *bat_priv, const u8 *addr)
-{
- const struct batadv_hard_iface *hard_iface;
- bool is_my_mac = false;
-
- rcu_read_lock();
- list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
- if (hard_iface->if_status != BATADV_IF_ACTIVE)
- continue;
-
- if (hard_iface->soft_iface != bat_priv->soft_iface)
- continue;
-
- if (batadv_compare_eth(hard_iface->net_dev->dev_addr, addr)) {
- is_my_mac = true;
- break;
- }
- }
- rcu_read_unlock();
- return is_my_mac;
-}
-
-/**
- * batadv_seq_print_text_primary_if_get - called from debugfs table printing
- * function that requires the primary interface
- * @seq: debugfs table seq_file struct
- *
- * Return: primary interface if found or NULL otherwise.
- */
-struct batadv_hard_iface *
-batadv_seq_print_text_primary_if_get(struct seq_file *seq)
-{
- struct net_device *net_dev = (struct net_device *)seq->private;
- struct batadv_priv *bat_priv = netdev_priv(net_dev);
- struct batadv_hard_iface *primary_if;
-
- primary_if = batadv_primary_if_get_selected(bat_priv);
-
- if (!primary_if) {
- seq_printf(seq,
- "BATMAN mesh %s disabled - please specify interfaces to enable it\n",
- net_dev->name);
- goto out;
- }
-
- if (primary_if->if_status == BATADV_IF_ACTIVE)
- goto out;
-
- seq_printf(seq,
- "BATMAN mesh %s disabled - primary interface not active\n",
- net_dev->name);
- batadv_hardif_put(primary_if);
- primary_if = NULL;
-
-out:
- return primary_if;
-}
-
-/**
- * batadv_max_header_len - calculate maximum encapsulation overhead for a
- * payload packet
- *
- * Return: the maximum encapsulation overhead in bytes.
- */
-int batadv_max_header_len(void)
-{
- int header_len = 0;
-
- header_len = max_t(int, header_len,
- sizeof(struct batadv_unicast_packet));
- header_len = max_t(int, header_len,
- sizeof(struct batadv_unicast_4addr_packet));
- header_len = max_t(int, header_len,
- sizeof(struct batadv_bcast_packet));
-
-#ifdef CONFIG_BATMAN_ADV_NC
- header_len = max_t(int, header_len,
- sizeof(struct batadv_coded_packet));
-#endif
-
- return header_len + ETH_HLEN;
-}
-
-/**
- * batadv_skb_set_priority - sets skb priority according to packet content
- * @skb: the packet to be sent
- * @offset: offset to the packet content
- *
- * This function sets a value between 256 and 263 (802.1d priority), which
- * can be interpreted by the cfg80211 or other drivers.
- */
-void batadv_skb_set_priority(struct sk_buff *skb, int offset)
-{
- struct iphdr ip_hdr_tmp, *ip_hdr;
- struct ipv6hdr ip6_hdr_tmp, *ip6_hdr;
- struct ethhdr ethhdr_tmp, *ethhdr;
- struct vlan_ethhdr *vhdr, vhdr_tmp;
- u32 prio;
-
- /* already set, do nothing */
- if (skb->priority >= 256 && skb->priority <= 263)
- return;
-
- ethhdr = skb_header_pointer(skb, offset, sizeof(*ethhdr), ðhdr_tmp);
- if (!ethhdr)
- return;
-
- switch (ethhdr->h_proto) {
- case htons(ETH_P_8021Q):
- vhdr = skb_header_pointer(skb, offset + sizeof(*vhdr),
- sizeof(*vhdr), &vhdr_tmp);
- if (!vhdr)
- return;
- prio = ntohs(vhdr->h_vlan_TCI) & VLAN_PRIO_MASK;
- prio = prio >> VLAN_PRIO_SHIFT;
- break;
- case htons(ETH_P_IP):
- ip_hdr = skb_header_pointer(skb, offset + sizeof(*ethhdr),
- sizeof(*ip_hdr), &ip_hdr_tmp);
- if (!ip_hdr)
- return;
- prio = (ipv4_get_dsfield(ip_hdr) & 0xfc) >> 5;
- break;
- case htons(ETH_P_IPV6):
- ip6_hdr = skb_header_pointer(skb, offset + sizeof(*ethhdr),
- sizeof(*ip6_hdr), &ip6_hdr_tmp);
- if (!ip6_hdr)
- return;
- prio = (ipv6_get_dsfield(ip6_hdr) & 0xfc) >> 5;
- break;
- default:
- return;
- }
-
- skb->priority = prio + 256;
-}
-
-static int batadv_recv_unhandled_packet(struct sk_buff *skb,
- struct batadv_hard_iface *recv_if)
-{
- return NET_RX_DROP;
-}
-
-/* incoming packets with the batman ethertype received on any active hard
- * interface
- */
-int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
- struct packet_type *ptype,
- struct net_device *orig_dev)
-{
- struct batadv_priv *bat_priv;
- struct batadv_ogm_packet *batadv_ogm_packet;
- struct batadv_hard_iface *hard_iface;
- u8 idx;
- int ret;
-
- hard_iface = container_of(ptype, struct batadv_hard_iface,
- batman_adv_ptype);
-
- /* Prevent processing a packet received on an interface which is getting
- * shut down otherwise the packet may trigger de-reference errors
- * further down in the receive path.
- */
- if (!kref_get_unless_zero(&hard_iface->refcount))
- goto err_out;
-
- skb = skb_share_check(skb, GFP_ATOMIC);
-
- /* skb was released by skb_share_check() */
- if (!skb)
- goto err_put;
-
- /* packet should hold at least type and version */
- if (unlikely(!pskb_may_pull(skb, 2)))
- goto err_free;
-
- /* expect a valid ethernet header here. */
- if (unlikely(skb->mac_len != ETH_HLEN || !skb_mac_header(skb)))
- goto err_free;
-
- if (!hard_iface->soft_iface)
- goto err_free;
-
- bat_priv = netdev_priv(hard_iface->soft_iface);
-
- if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
- goto err_free;
-
- /* discard frames on not active interfaces */
- if (hard_iface->if_status != BATADV_IF_ACTIVE)
- goto err_free;
-
- batadv_ogm_packet = (struct batadv_ogm_packet *)skb->data;
-
- if (batadv_ogm_packet->version != BATADV_COMPAT_VERSION) {
- batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
- "Drop packet: incompatible batman version (%i)\n",
- batadv_ogm_packet->version);
- goto err_free;
- }
-
- /* reset control block to avoid left overs from previous users */
- memset(skb->cb, 0, sizeof(struct batadv_skb_cb));
-
- /* all receive handlers return whether they received or reused
- * the supplied skb. if not, we have to free the skb.
- */
- idx = batadv_ogm_packet->packet_type;
- ret = (*batadv_rx_handler[idx])(skb, hard_iface);
-
- if (ret == NET_RX_DROP)
- kfree_skb(skb);
-
- batadv_hardif_put(hard_iface);
-
- /* return NET_RX_SUCCESS in any case as we
- * most probably dropped the packet for
- * routing-logical reasons.
- */
- return NET_RX_SUCCESS;
-
-err_free:
- kfree_skb(skb);
-err_put:
- batadv_hardif_put(hard_iface);
-err_out:
- return NET_RX_DROP;
-}
-
-static void batadv_recv_handler_init(void)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(batadv_rx_handler); i++)
- batadv_rx_handler[i] = batadv_recv_unhandled_packet;
-
- for (i = BATADV_UNICAST_MIN; i <= BATADV_UNICAST_MAX; i++)
- batadv_rx_handler[i] = batadv_recv_unhandled_unicast_packet;
-
- /* compile time checks for sizes */
- BUILD_BUG_ON(sizeof(struct batadv_bla_claim_dst) != 6);
- BUILD_BUG_ON(sizeof(struct batadv_ogm_packet) != 24);
- BUILD_BUG_ON(sizeof(struct batadv_icmp_header) != 20);
- BUILD_BUG_ON(sizeof(struct batadv_icmp_packet) != 20);
- BUILD_BUG_ON(sizeof(struct batadv_icmp_packet_rr) != 116);
- BUILD_BUG_ON(sizeof(struct batadv_unicast_packet) != 10);
- BUILD_BUG_ON(sizeof(struct batadv_unicast_4addr_packet) != 18);
- BUILD_BUG_ON(sizeof(struct batadv_frag_packet) != 20);
- BUILD_BUG_ON(sizeof(struct batadv_bcast_packet) != 14);
- BUILD_BUG_ON(sizeof(struct batadv_coded_packet) != 46);
- BUILD_BUG_ON(sizeof(struct batadv_unicast_tvlv_packet) != 20);
- BUILD_BUG_ON(sizeof(struct batadv_tvlv_hdr) != 4);
- BUILD_BUG_ON(sizeof(struct batadv_tvlv_gateway_data) != 8);
- BUILD_BUG_ON(sizeof(struct batadv_tvlv_tt_vlan_data) != 8);
- BUILD_BUG_ON(sizeof(struct batadv_tvlv_tt_change) != 12);
- BUILD_BUG_ON(sizeof(struct batadv_tvlv_roam_adv) != 8);
-
- /* broadcast packet */
- batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet;
-
- /* unicast packets ... */
- /* unicast with 4 addresses packet */
- batadv_rx_handler[BATADV_UNICAST_4ADDR] = batadv_recv_unicast_packet;
- /* unicast packet */
- batadv_rx_handler[BATADV_UNICAST] = batadv_recv_unicast_packet;
- /* unicast tvlv packet */
- batadv_rx_handler[BATADV_UNICAST_TVLV] = batadv_recv_unicast_tvlv;
- /* batman icmp packet */
- batadv_rx_handler[BATADV_ICMP] = batadv_recv_icmp_packet;
- /* Fragmented packets */
- batadv_rx_handler[BATADV_UNICAST_FRAG] = batadv_recv_frag_packet;
-}
-
-int
-batadv_recv_handler_register(u8 packet_type,
- int (*recv_handler)(struct sk_buff *,
- struct batadv_hard_iface *))
-{
- int (*curr)(struct sk_buff *,
- struct batadv_hard_iface *);
- curr = batadv_rx_handler[packet_type];
-
- if ((curr != batadv_recv_unhandled_packet) &&
- (curr != batadv_recv_unhandled_unicast_packet))
- return -EBUSY;
-
- batadv_rx_handler[packet_type] = recv_handler;
- return 0;
-}
-
-void batadv_recv_handler_unregister(u8 packet_type)
-{
- batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet;
-}
-
-static struct batadv_algo_ops *batadv_algo_get(char *name)
-{
- struct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;
-
- hlist_for_each_entry(bat_algo_ops_tmp, &batadv_algo_list, list) {
- if (strcmp(bat_algo_ops_tmp->name, name) != 0)
- continue;
-
- bat_algo_ops = bat_algo_ops_tmp;
- break;
- }
-
- return bat_algo_ops;
-}
-
-int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
-{
- struct batadv_algo_ops *bat_algo_ops_tmp;
-
- bat_algo_ops_tmp = batadv_algo_get(bat_algo_ops->name);
- if (bat_algo_ops_tmp) {
- pr_info("Trying to register already registered routing algorithm: %s\n",
- bat_algo_ops->name);
- return -EEXIST;
- }
-
- /* all algorithms must implement all ops (for now) */
- if (!bat_algo_ops->bat_iface_enable ||
- !bat_algo_ops->bat_iface_disable ||
- !bat_algo_ops->bat_iface_update_mac ||
- !bat_algo_ops->bat_primary_iface_set ||
- !bat_algo_ops->bat_neigh_cmp ||
- !bat_algo_ops->bat_neigh_is_similar_or_better) {
- pr_info("Routing algo '%s' does not implement required ops\n",
- bat_algo_ops->name);
- return -EINVAL;
- }
-
- INIT_HLIST_NODE(&bat_algo_ops->list);
- hlist_add_head(&bat_algo_ops->list, &batadv_algo_list);
-
- return 0;
-}
-
-int batadv_algo_select(struct batadv_priv *bat_priv, char *name)
-{
- struct batadv_algo_ops *bat_algo_ops;
-
- bat_algo_ops = batadv_algo_get(name);
- if (!bat_algo_ops)
- return -EINVAL;
-
- bat_priv->bat_algo_ops = bat_algo_ops;
-
- return 0;
-}
-
-int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
-{
- struct batadv_algo_ops *bat_algo_ops;
-
- seq_puts(seq, "Available routing algorithms:\n");
-
- hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) {
- seq_printf(seq, " * %s\n", bat_algo_ops->name);
- }
-
- return 0;
-}
-
-/**
- * batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in
- * the header
- * @skb: skb pointing to fragmented socket buffers
- * @payload_ptr: Pointer to position inside the head buffer of the skb
- * marking the start of the data to be CRC'ed
- *
- * payload_ptr must always point to an address in the skb head buffer and not to
- * a fragment.
- *
- * Return: big endian crc32c of the checksummed data
- */
-__be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
-{
- u32 crc = 0;
- unsigned int from;
- unsigned int to = skb->len;
- struct skb_seq_state st;
- const u8 *data;
- unsigned int len;
- unsigned int consumed = 0;
-
- from = (unsigned int)(payload_ptr - skb->data);
-
- skb_prepare_seq_read(skb, from, to, &st);
- while ((len = skb_seq_read(consumed, &data, &st)) != 0) {
- crc = crc32c(crc, data, len);
- consumed += len;
- }
-
- return htonl(crc);
-}
+#include "tvlv.h"
/**
* batadv_tvlv_handler_release - release tvlv handler from lists and queue for
@@ -1231,96 +628,3 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
out:
batadv_orig_node_put(orig_node);
}
-
-/**
- * batadv_get_vid - extract the VLAN identifier from skb if any
- * @skb: the buffer containing the packet
- * @header_len: length of the batman header preceding the ethernet header
- *
- * Return: VID with the BATADV_VLAN_HAS_TAG flag when the packet embedded in the
- * skb is vlan tagged. Otherwise BATADV_NO_FLAGS.
- */
-unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len)
-{
- struct ethhdr *ethhdr = (struct ethhdr *)(skb->data + header_len);
- struct vlan_ethhdr *vhdr;
- unsigned short vid;
-
- if (ethhdr->h_proto != htons(ETH_P_8021Q))
- return BATADV_NO_FLAGS;
-
- if (!pskb_may_pull(skb, header_len + VLAN_ETH_HLEN))
- return BATADV_NO_FLAGS;
-
- vhdr = (struct vlan_ethhdr *)(skb->data + header_len);
- vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
- vid |= BATADV_VLAN_HAS_TAG;
-
- return vid;
-}
-
-/**
- * batadv_vlan_ap_isola_get - return the AP isolation status for the given vlan
- * @bat_priv: the bat priv with all the soft interface information
- * @vid: the VLAN identifier for which the AP isolation attributed as to be
- * looked up
- *
- * Return: true if AP isolation is on for the VLAN idenfied by vid, false
- * otherwise
- */
-bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid)
-{
- bool ap_isolation_enabled = false;
- struct batadv_softif_vlan *vlan;
-
- /* if the AP isolation is requested on a VLAN, then check for its
- * setting in the proper VLAN private data structure
- */
- vlan = batadv_softif_vlan_get(bat_priv, vid);
- if (vlan) {
- ap_isolation_enabled = atomic_read(&vlan->ap_isolation);
- batadv_softif_vlan_put(vlan);
- }
-
- return ap_isolation_enabled;
-}
-
-static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
-{
- struct batadv_algo_ops *bat_algo_ops;
- char *algo_name = (char *)val;
- size_t name_len = strlen(algo_name);
-
- if (name_len > 0 && algo_name[name_len - 1] == '\n')
- algo_name[name_len - 1] = '\0';
-
- bat_algo_ops = batadv_algo_get(algo_name);
- if (!bat_algo_ops) {
- pr_err("Routing algorithm '%s' is not supported\n", algo_name);
- return -EINVAL;
- }
-
- return param_set_copystring(algo_name, kp);
-}
-
-static const struct kernel_param_ops batadv_param_ops_ra = {
- .set = batadv_param_set_ra,
- .get = param_get_string,
-};
-
-static struct kparam_string batadv_param_string_ra = {
- .maxlen = sizeof(batadv_routing_algo),
- .string = batadv_routing_algo,
-};
-
-module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra,
- 0644);
-module_init(batadv_init);
-module_exit(batadv_exit);
-
-MODULE_LICENSE("GPL");
-
-MODULE_AUTHOR(BATADV_DRIVER_AUTHOR);
-MODULE_DESCRIPTION(BATADV_DRIVER_DESC);
-MODULE_SUPPORTED_DEVICE(BATADV_DRIVER_DEVICE);
-MODULE_VERSION(BATADV_SOURCE_VERSION);
diff --git a/net/batman-adv/tvlv.h b/net/batman-adv/tvlv.h
new file mode 100644
index 0000000..e4369b5
--- /dev/null
+++ b/net/batman-adv/tvlv.h
@@ -0,0 +1,61 @@
+/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner, Simon Wunderlich
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _NET_BATMAN_ADV_TVLV_H_
+#define _NET_BATMAN_ADV_TVLV_H_
+
+#include "main.h"
+
+#include <linux/types.h>
+
+struct batadv_ogm_packet;
+
+void batadv_tvlv_container_register(struct batadv_priv *bat_priv,
+ u8 type, u8 version,
+ void *tvlv_value, u16 tvlv_value_len);
+u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,
+ unsigned char **packet_buff,
+ int *packet_buff_len, int packet_min_len);
+void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,
+ struct batadv_ogm_packet *batadv_ogm_packet,
+ struct batadv_orig_node *orig_node);
+void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv,
+ u8 type, u8 version);
+
+void batadv_tvlv_handler_register(struct batadv_priv *bat_priv,
+ void (*optr)(struct batadv_priv *bat_priv,
+ struct batadv_orig_node *orig,
+ u8 flags,
+ void *tvlv_value,
+ u16 tvlv_value_len),
+ int (*uptr)(struct batadv_priv *bat_priv,
+ u8 *src, u8 *dst,
+ void *tvlv_value,
+ u16 tvlv_value_len),
+ u8 type, u8 version, u8 flags);
+void batadv_tvlv_handler_unregister(struct batadv_priv *bat_priv,
+ u8 type, u8 version);
+int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
+ bool ogm_source,
+ struct batadv_orig_node *orig_node,
+ u8 *src, u8 *dst,
+ void *tvlv_buff, u16 tvlv_buff_len);
+void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
+ u8 *dst, u8 type, u8 version,
+ void *tvlv_value, u16 tvlv_value_len);
+
+#endif /* _NET_BATMAN_ADV_TVLV_H_ */
4 years, 8 months
[batman-adv] master: batman-adv: Keep includes ordered by filename (b87df5f)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit b87df5f9a6e9ea3916fb42cb7d7481b33ef0ad34
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Sun May 15 11:07:42 2016 +0200
batman-adv: Keep includes ordered by filename
It is easier to detect if a include is already there for a used
functionality when the includes are ordered. Using an alphabetic order
together with the grouping in commit 7df620092727 ("batman-adv: Add
required includes to all files") makes includes better manageable.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Marek Lindner <mareklindner(a)neomailbox.ch>
>---------------------------------------------------------------
b87df5f9a6e9ea3916fb42cb7d7481b33ef0ad34
net/batman-adv/bat_iv_ogm.c | 2 +-
net/batman-adv/gateway_common.c | 2 +-
net/batman-adv/hard-interface.c | 2 +-
net/batman-adv/main.h | 6 +++---
net/batman-adv/multicast.c | 2 +-
net/batman-adv/netlink.c | 4 ++--
net/batman-adv/send.c | 2 +-
net/batman-adv/sysfs.c | 4 ++--
8 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 4815db9..6dc89b0 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -31,8 +31,8 @@
#include <linux/init.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
-#include <linux/list.h>
#include <linux/kref.h>
+#include <linux/list.h>
#include <linux/lockdep.h>
#include <linux/netdevice.h>
#include <linux/pkt_sched.h>
diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c
index 3c26945..7754435 100644
--- a/net/batman-adv/gateway_common.c
+++ b/net/batman-adv/gateway_common.c
@@ -19,8 +19,8 @@
#include "main.h"
#include <linux/atomic.h>
-#include <linux/errno.h>
#include <linux/byteorder/generic.h>
+#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/math64.h>
#include <linux/netdevice.h>
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index a8cda76..1e26a0b 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -23,9 +23,9 @@
#include <linux/byteorder/generic.h>
#include <linux/errno.h>
#include <linux/fs.h>
+#include <linux/if.h>
#include <linux/if_arp.h>
#include <linux/if_ether.h>
-#include <linux/if.h>
#include <linux/kernel.h>
#include <linux/kref.h>
#include <linux/list.h>
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 832df0f..94bf4f8 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -181,12 +181,12 @@ enum batadv_uev_type {
#include <linux/cpumask.h>
#include <linux/etherdevice.h>
#include <linux/if_ether.h> /* for packet.h */
+#include <linux/if_vlan.h>
+#include <linux/jiffies.h>
#include <linux/netdevice.h>
+#include <linux/percpu.h>
#include <linux/printk.h>
#include <linux/types.h>
-#include <linux/percpu.h>
-#include <linux/jiffies.h>
-#include <linux/if_vlan.h>
#include "types.h"
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index 2dd5aec..d3222db 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -29,8 +29,8 @@
#include <linux/if_bridge.h>
#include <linux/if_ether.h>
#include <linux/igmp.h>
-#include <linux/in6.h>
#include <linux/in.h>
+#include <linux/in6.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/kernel.h>
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
index 54724b7..68152aa 100644
--- a/net/batman-adv/netlink.c
+++ b/net/batman-adv/netlink.c
@@ -15,8 +15,8 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "main.h"
#include "netlink.h"
+#include "main.h"
#include <linux/errno.h>
#include <linux/fs.h>
@@ -25,8 +25,8 @@
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/netlink.h>
-#include <linux/stddef.h>
#include <linux/printk.h>
+#include <linux/stddef.h>
#include <net/genetlink.h>
#include <net/netlink.h>
#include <uapi/linux/batman_adv.h>
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 638d1c1..45ca6ac 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -22,8 +22,8 @@
#include <linux/byteorder/generic.h>
#include <linux/etherdevice.h>
#include <linux/fs.h>
-#include <linux/if_ether.h>
#include <linux/if.h>
+#include <linux/if_ether.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/kref.h>
diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c
index 233abcf..6244a9a 100644
--- a/net/batman-adv/sysfs.c
+++ b/net/batman-adv/sysfs.c
@@ -25,8 +25,8 @@
#include <linux/fs.h>
#include <linux/if.h>
#include <linux/if_vlan.h>
-#include <linux/kref.h>
#include <linux/kernel.h>
+#include <linux/kref.h>
#include <linux/netdevice.h>
#include <linux/printk.h>
#include <linux/rculist.h>
@@ -38,10 +38,10 @@
#include <linux/string.h>
#include <linux/stringify.h>
+#include "bridge_loop_avoidance.h"
#include "distributed-arp-table.h"
#include "gateway_client.h"
#include "gateway_common.h"
-#include "bridge_loop_avoidance.h"
#include "hard-interface.h"
#include "network-coding.h"
#include "packet.h"
4 years, 8 months