diff options
43 files changed, 3831 insertions, 1217 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index 772c9ffa2272..67e4a6584cf5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -2297,6 +2297,7 @@ S: Maintained | |||
| 2297 | F: Documentation/ABI/testing/sysfs-class-net-batman-adv | 2297 | F: Documentation/ABI/testing/sysfs-class-net-batman-adv |
| 2298 | F: Documentation/ABI/testing/sysfs-class-net-mesh | 2298 | F: Documentation/ABI/testing/sysfs-class-net-mesh |
| 2299 | F: Documentation/networking/batman-adv.txt | 2299 | F: Documentation/networking/batman-adv.txt |
| 2300 | F: include/uapi/linux/batman_adv.h | ||
| 2300 | F: net/batman-adv/ | 2301 | F: net/batman-adv/ |
| 2301 | 2302 | ||
| 2302 | BAYCOM/HDLCDRV DRIVERS FOR AX.25 | 2303 | BAYCOM/HDLCDRV DRIVERS FOR AX.25 |
diff --git a/include/uapi/linux/batman_adv.h b/include/uapi/linux/batman_adv.h new file mode 100644 index 000000000000..0fbf6fd4711b --- /dev/null +++ b/include/uapi/linux/batman_adv.h | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | /* Copyright (C) 2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Matthias Schiffer | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and/or distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef _UAPI_LINUX_BATMAN_ADV_H_ | ||
| 19 | #define _UAPI_LINUX_BATMAN_ADV_H_ | ||
| 20 | |||
| 21 | #define BATADV_NL_NAME "batadv" | ||
| 22 | |||
| 23 | #define BATADV_NL_MCAST_GROUP_TPMETER "tpmeter" | ||
| 24 | |||
| 25 | /** | ||
| 26 | * enum batadv_nl_attrs - batman-adv netlink attributes | ||
| 27 | * | ||
| 28 | * @BATADV_ATTR_UNSPEC: unspecified attribute to catch errors | ||
| 29 | * @BATADV_ATTR_VERSION: batman-adv version string | ||
| 30 | * @BATADV_ATTR_ALGO_NAME: name of routing algorithm | ||
| 31 | * @BATADV_ATTR_MESH_IFINDEX: index of the batman-adv interface | ||
| 32 | * @BATADV_ATTR_MESH_IFNAME: name of the batman-adv interface | ||
| 33 | * @BATADV_ATTR_MESH_ADDRESS: mac address of the batman-adv interface | ||
| 34 | * @BATADV_ATTR_HARD_IFINDEX: index of the non-batman-adv interface | ||
| 35 | * @BATADV_ATTR_HARD_IFNAME: name of the non-batman-adv interface | ||
| 36 | * @BATADV_ATTR_HARD_ADDRESS: mac address of the non-batman-adv interface | ||
| 37 | * @BATADV_ATTR_ORIG_ADDRESS: originator mac address | ||
| 38 | * @BATADV_ATTR_TPMETER_RESULT: result of run (see batadv_tp_meter_status) | ||
| 39 | * @BATADV_ATTR_TPMETER_TEST_TIME: time (msec) the run took | ||
| 40 | * @BATADV_ATTR_TPMETER_BYTES: amount of acked bytes during run | ||
| 41 | * @BATADV_ATTR_TPMETER_COOKIE: session cookie to match tp_meter session | ||
| 42 | * @BATADV_ATTR_PAD: attribute used for padding for 64-bit alignment | ||
| 43 | * @__BATADV_ATTR_AFTER_LAST: internal use | ||
| 44 | * @NUM_BATADV_ATTR: total number of batadv_nl_attrs available | ||
| 45 | * @BATADV_ATTR_MAX: highest attribute number currently defined | ||
| 46 | */ | ||
| 47 | enum batadv_nl_attrs { | ||
| 48 | BATADV_ATTR_UNSPEC, | ||
| 49 | BATADV_ATTR_VERSION, | ||
| 50 | BATADV_ATTR_ALGO_NAME, | ||
| 51 | BATADV_ATTR_MESH_IFINDEX, | ||
| 52 | BATADV_ATTR_MESH_IFNAME, | ||
| 53 | BATADV_ATTR_MESH_ADDRESS, | ||
| 54 | BATADV_ATTR_HARD_IFINDEX, | ||
| 55 | BATADV_ATTR_HARD_IFNAME, | ||
| 56 | BATADV_ATTR_HARD_ADDRESS, | ||
| 57 | BATADV_ATTR_ORIG_ADDRESS, | ||
| 58 | BATADV_ATTR_TPMETER_RESULT, | ||
| 59 | BATADV_ATTR_TPMETER_TEST_TIME, | ||
| 60 | BATADV_ATTR_TPMETER_BYTES, | ||
| 61 | BATADV_ATTR_TPMETER_COOKIE, | ||
| 62 | BATADV_ATTR_PAD, | ||
| 63 | /* add attributes above here, update the policy in netlink.c */ | ||
| 64 | __BATADV_ATTR_AFTER_LAST, | ||
| 65 | NUM_BATADV_ATTR = __BATADV_ATTR_AFTER_LAST, | ||
| 66 | BATADV_ATTR_MAX = __BATADV_ATTR_AFTER_LAST - 1 | ||
| 67 | }; | ||
| 68 | |||
| 69 | /** | ||
| 70 | * enum batadv_nl_commands - supported batman-adv netlink commands | ||
| 71 | * | ||
| 72 | * @BATADV_CMD_UNSPEC: unspecified command to catch errors | ||
| 73 | * @BATADV_CMD_GET_MESH_INFO: Query basic information about batman-adv device | ||
| 74 | * @BATADV_CMD_TP_METER: Start a tp meter session | ||
| 75 | * @BATADV_CMD_TP_METER_CANCEL: Cancel a tp meter session | ||
| 76 | * @__BATADV_CMD_AFTER_LAST: internal use | ||
| 77 | * @BATADV_CMD_MAX: highest used command number | ||
| 78 | */ | ||
| 79 | enum batadv_nl_commands { | ||
| 80 | BATADV_CMD_UNSPEC, | ||
| 81 | BATADV_CMD_GET_MESH_INFO, | ||
| 82 | BATADV_CMD_TP_METER, | ||
| 83 | BATADV_CMD_TP_METER_CANCEL, | ||
| 84 | /* add new commands above here */ | ||
| 85 | __BATADV_CMD_AFTER_LAST, | ||
| 86 | BATADV_CMD_MAX = __BATADV_CMD_AFTER_LAST - 1 | ||
| 87 | }; | ||
| 88 | |||
| 89 | /** | ||
| 90 | * enum batadv_tp_meter_reason - reason of a tp meter test run stop | ||
| 91 | * @BATADV_TP_REASON_COMPLETE: sender finished tp run | ||
| 92 | * @BATADV_TP_REASON_CANCEL: sender was stopped during run | ||
| 93 | * @BATADV_TP_REASON_DST_UNREACHABLE: receiver could not be reached or didn't | ||
| 94 | * answer | ||
| 95 | * @BATADV_TP_REASON_RESEND_LIMIT: (unused) sender retry reached limit | ||
| 96 | * @BATADV_TP_REASON_ALREADY_ONGOING: test to or from the same node already | ||
| 97 | * ongoing | ||
| 98 | * @BATADV_TP_REASON_MEMORY_ERROR: test was stopped due to low memory | ||
| 99 | * @BATADV_TP_REASON_CANT_SEND: failed to send via outgoing interface | ||
| 100 | * @BATADV_TP_REASON_TOO_MANY: too many ongoing sessions | ||
| 101 | */ | ||
| 102 | enum batadv_tp_meter_reason { | ||
| 103 | BATADV_TP_REASON_COMPLETE = 3, | ||
| 104 | BATADV_TP_REASON_CANCEL = 4, | ||
| 105 | /* error status >= 128 */ | ||
| 106 | BATADV_TP_REASON_DST_UNREACHABLE = 128, | ||
| 107 | BATADV_TP_REASON_RESEND_LIMIT = 129, | ||
| 108 | BATADV_TP_REASON_ALREADY_ONGOING = 130, | ||
| 109 | BATADV_TP_REASON_MEMORY_ERROR = 131, | ||
| 110 | BATADV_TP_REASON_CANT_SEND = 132, | ||
| 111 | BATADV_TP_REASON_TOO_MANY = 133, | ||
| 112 | }; | ||
| 113 | |||
| 114 | #endif /* _UAPI_LINUX_BATMAN_ADV_H_ */ | ||
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile index 797cf2fc88c1..a83fc6c58d19 100644 --- a/net/batman-adv/Makefile +++ b/net/batman-adv/Makefile | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | # | 17 | # |
| 18 | 18 | ||
| 19 | obj-$(CONFIG_BATMAN_ADV) += batman-adv.o | 19 | obj-$(CONFIG_BATMAN_ADV) += batman-adv.o |
| 20 | batman-adv-y += bat_algo.o | ||
| 20 | batman-adv-y += bat_iv_ogm.o | 21 | batman-adv-y += bat_iv_ogm.o |
| 21 | batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v.o | 22 | batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v.o |
| 22 | batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v_elp.o | 23 | batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v_elp.o |
| @@ -31,12 +32,16 @@ batman-adv-y += gateway_common.o | |||
| 31 | batman-adv-y += hard-interface.o | 32 | batman-adv-y += hard-interface.o |
| 32 | batman-adv-y += hash.o | 33 | batman-adv-y += hash.o |
| 33 | batman-adv-y += icmp_socket.o | 34 | batman-adv-y += icmp_socket.o |
| 35 | batman-adv-$(CONFIG_BATMAN_ADV_DEBUG) += log.o | ||
| 34 | batman-adv-y += main.o | 36 | batman-adv-y += main.o |
| 35 | batman-adv-$(CONFIG_BATMAN_ADV_MCAST) += multicast.o | 37 | batman-adv-$(CONFIG_BATMAN_ADV_MCAST) += multicast.o |
| 38 | batman-adv-y += netlink.o | ||
| 36 | batman-adv-$(CONFIG_BATMAN_ADV_NC) += network-coding.o | 39 | batman-adv-$(CONFIG_BATMAN_ADV_NC) += network-coding.o |
| 37 | batman-adv-y += originator.o | 40 | batman-adv-y += originator.o |
| 38 | batman-adv-y += routing.o | 41 | batman-adv-y += routing.o |
| 39 | batman-adv-y += send.o | 42 | batman-adv-y += send.o |
| 40 | batman-adv-y += soft-interface.o | 43 | batman-adv-y += soft-interface.o |
| 41 | batman-adv-y += sysfs.o | 44 | batman-adv-y += sysfs.o |
| 45 | batman-adv-y += tp_meter.o | ||
| 42 | batman-adv-y += translation-table.o | 46 | batman-adv-y += translation-table.o |
| 47 | batman-adv-y += tvlv.o | ||
diff --git a/net/batman-adv/bat_algo.c b/net/batman-adv/bat_algo.c new file mode 100644 index 000000000000..81dbbf569bd4 --- /dev/null +++ b/net/batman-adv/bat_algo.c | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | /* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Marek Lindner, Simon Wunderlich | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "main.h" | ||
| 19 | |||
| 20 | #include <linux/errno.h> | ||
| 21 | #include <linux/list.h> | ||
| 22 | #include <linux/moduleparam.h> | ||
| 23 | #include <linux/printk.h> | ||
| 24 | #include <linux/seq_file.h> | ||
| 25 | #include <linux/stddef.h> | ||
| 26 | #include <linux/string.h> | ||
| 27 | |||
| 28 | #include "bat_algo.h" | ||
| 29 | |||
| 30 | char batadv_routing_algo[20] = "BATMAN_IV"; | ||
| 31 | static struct hlist_head batadv_algo_list; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * batadv_algo_init - Initialize batman-adv algorithm management data structures | ||
| 35 | */ | ||
| 36 | void batadv_algo_init(void) | ||
| 37 | { | ||
| 38 | INIT_HLIST_HEAD(&batadv_algo_list); | ||
| 39 | } | ||
| 40 | |||
| 41 | static struct batadv_algo_ops *batadv_algo_get(char *name) | ||
| 42 | { | ||
| 43 | struct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp; | ||
| 44 | |||
| 45 | hlist_for_each_entry(bat_algo_ops_tmp, &batadv_algo_list, list) { | ||
| 46 | if (strcmp(bat_algo_ops_tmp->name, name) != 0) | ||
| 47 | continue; | ||
| 48 | |||
| 49 | bat_algo_ops = bat_algo_ops_tmp; | ||
| 50 | break; | ||
| 51 | } | ||
| 52 | |||
| 53 | return bat_algo_ops; | ||
| 54 | } | ||
| 55 | |||
| 56 | int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops) | ||
| 57 | { | ||
| 58 | struct batadv_algo_ops *bat_algo_ops_tmp; | ||
| 59 | |||
| 60 | bat_algo_ops_tmp = batadv_algo_get(bat_algo_ops->name); | ||
| 61 | if (bat_algo_ops_tmp) { | ||
| 62 | pr_info("Trying to register already registered routing algorithm: %s\n", | ||
| 63 | bat_algo_ops->name); | ||
| 64 | return -EEXIST; | ||
| 65 | } | ||
| 66 | |||
| 67 | /* all algorithms must implement all ops (for now) */ | ||
| 68 | if (!bat_algo_ops->iface.enable || | ||
| 69 | !bat_algo_ops->iface.disable || | ||
| 70 | !bat_algo_ops->iface.update_mac || | ||
| 71 | !bat_algo_ops->iface.primary_set || | ||
| 72 | !bat_algo_ops->neigh.cmp || | ||
| 73 | !bat_algo_ops->neigh.is_similar_or_better) { | ||
| 74 | pr_info("Routing algo '%s' does not implement required ops\n", | ||
| 75 | bat_algo_ops->name); | ||
| 76 | return -EINVAL; | ||
| 77 | } | ||
| 78 | |||
| 79 | INIT_HLIST_NODE(&bat_algo_ops->list); | ||
| 80 | hlist_add_head(&bat_algo_ops->list, &batadv_algo_list); | ||
| 81 | |||
| 82 | return 0; | ||
| 83 | } | ||
| 84 | |||
| 85 | int batadv_algo_select(struct batadv_priv *bat_priv, char *name) | ||
| 86 | { | ||
| 87 | struct batadv_algo_ops *bat_algo_ops; | ||
| 88 | |||
| 89 | bat_algo_ops = batadv_algo_get(name); | ||
| 90 | if (!bat_algo_ops) | ||
| 91 | return -EINVAL; | ||
| 92 | |||
| 93 | bat_priv->algo_ops = bat_algo_ops; | ||
| 94 | |||
| 95 | return 0; | ||
| 96 | } | ||
| 97 | |||
| 98 | int batadv_algo_seq_print_text(struct seq_file *seq, void *offset) | ||
| 99 | { | ||
| 100 | struct batadv_algo_ops *bat_algo_ops; | ||
| 101 | |||
| 102 | seq_puts(seq, "Available routing algorithms:\n"); | ||
| 103 | |||
| 104 | hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) { | ||
| 105 | seq_printf(seq, " * %s\n", bat_algo_ops->name); | ||
| 106 | } | ||
| 107 | |||
| 108 | return 0; | ||
| 109 | } | ||
| 110 | |||
| 111 | static int batadv_param_set_ra(const char *val, const struct kernel_param *kp) | ||
| 112 | { | ||
| 113 | struct batadv_algo_ops *bat_algo_ops; | ||
| 114 | char *algo_name = (char *)val; | ||
| 115 | size_t name_len = strlen(algo_name); | ||
| 116 | |||
| 117 | if (name_len > 0 && algo_name[name_len - 1] == '\n') | ||
| 118 | algo_name[name_len - 1] = '\0'; | ||
| 119 | |||
| 120 | bat_algo_ops = batadv_algo_get(algo_name); | ||
| 121 | if (!bat_algo_ops) { | ||
| 122 | pr_err("Routing algorithm '%s' is not supported\n", algo_name); | ||
| 123 | return -EINVAL; | ||
| 124 | } | ||
| 125 | |||
| 126 | return param_set_copystring(algo_name, kp); | ||
| 127 | } | ||
| 128 | |||
| 129 | static const struct kernel_param_ops batadv_param_ops_ra = { | ||
| 130 | .set = batadv_param_set_ra, | ||
| 131 | .get = param_get_string, | ||
| 132 | }; | ||
| 133 | |||
| 134 | static struct kparam_string batadv_param_string_ra = { | ||
| 135 | .maxlen = sizeof(batadv_routing_algo), | ||
| 136 | .string = batadv_routing_algo, | ||
| 137 | }; | ||
| 138 | |||
| 139 | module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra, | ||
| 140 | 0644); | ||
diff --git a/net/batman-adv/bat_algo.h b/net/batman-adv/bat_algo.h index 36542962de7d..860d773dd8fa 100644 --- a/net/batman-adv/bat_algo.h +++ b/net/batman-adv/bat_algo.h | |||
| @@ -20,35 +20,16 @@ | |||
| 20 | 20 | ||
| 21 | #include "main.h" | 21 | #include "main.h" |
| 22 | 22 | ||
| 23 | int batadv_iv_init(void); | 23 | #include <linux/types.h> |
| 24 | 24 | ||
| 25 | #ifdef CONFIG_BATMAN_ADV_BATMAN_V | 25 | struct seq_file; |
| 26 | 26 | ||
| 27 | int batadv_v_init(void); | 27 | extern char batadv_routing_algo[]; |
| 28 | void batadv_v_hardif_init(struct batadv_hard_iface *hardif); | 28 | extern struct list_head batadv_hardif_list; |
| 29 | int batadv_v_mesh_init(struct batadv_priv *bat_priv); | ||
| 30 | void batadv_v_mesh_free(struct batadv_priv *bat_priv); | ||
| 31 | 29 | ||
| 32 | #else | 30 | void batadv_algo_init(void); |
| 33 | 31 | int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops); | |
| 34 | static inline int batadv_v_init(void) | 32 | int batadv_algo_select(struct batadv_priv *bat_priv, char *name); |
| 35 | { | 33 | int batadv_algo_seq_print_text(struct seq_file *seq, void *offset); |
| 36 | return 0; | ||
| 37 | } | ||
| 38 | |||
| 39 | static inline void batadv_v_hardif_init(struct batadv_hard_iface *hardif) | ||
| 40 | { | ||
| 41 | } | ||
| 42 | |||
| 43 | static inline int batadv_v_mesh_init(struct batadv_priv *bat_priv) | ||
| 44 | { | ||
| 45 | return 0; | ||
| 46 | } | ||
| 47 | |||
| 48 | static inline void batadv_v_mesh_free(struct batadv_priv *bat_priv) | ||
| 49 | { | ||
| 50 | } | ||
| 51 | |||
| 52 | #endif /* CONFIG_BATMAN_ADV_BATMAN_V */ | ||
| 53 | 34 | ||
| 54 | #endif /* _NET_BATMAN_ADV_BAT_ALGO_H_ */ | 35 | #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 4815db978c27..19b0abd6c640 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #include "bat_algo.h" | 18 | #include "bat_iv_ogm.h" |
| 19 | #include "main.h" | 19 | #include "main.h" |
| 20 | 20 | ||
| 21 | #include <linux/atomic.h> | 21 | #include <linux/atomic.h> |
| @@ -31,8 +31,8 @@ | |||
| 31 | #include <linux/init.h> | 31 | #include <linux/init.h> |
| 32 | #include <linux/jiffies.h> | 32 | #include <linux/jiffies.h> |
| 33 | #include <linux/kernel.h> | 33 | #include <linux/kernel.h> |
| 34 | #include <linux/list.h> | ||
| 35 | #include <linux/kref.h> | 34 | #include <linux/kref.h> |
| 35 | #include <linux/list.h> | ||
| 36 | #include <linux/lockdep.h> | 36 | #include <linux/lockdep.h> |
| 37 | #include <linux/netdevice.h> | 37 | #include <linux/netdevice.h> |
| 38 | #include <linux/pkt_sched.h> | 38 | #include <linux/pkt_sched.h> |
| @@ -49,15 +49,18 @@ | |||
| 49 | #include <linux/types.h> | 49 | #include <linux/types.h> |
| 50 | #include <linux/workqueue.h> | 50 | #include <linux/workqueue.h> |
| 51 | 51 | ||
| 52 | #include "bat_algo.h" | ||
| 52 | #include "bitarray.h" | 53 | #include "bitarray.h" |
| 53 | #include "hard-interface.h" | 54 | #include "hard-interface.h" |
| 54 | #include "hash.h" | 55 | #include "hash.h" |
| 56 | #include "log.h" | ||
| 55 | #include "network-coding.h" | 57 | #include "network-coding.h" |
| 56 | #include "originator.h" | 58 | #include "originator.h" |
| 57 | #include "packet.h" | 59 | #include "packet.h" |
| 58 | #include "routing.h" | 60 | #include "routing.h" |
| 59 | #include "send.h" | 61 | #include "send.h" |
| 60 | #include "translation-table.h" | 62 | #include "translation-table.h" |
| 63 | #include "tvlv.h" | ||
| 61 | 64 | ||
| 62 | static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work); | 65 | static void batadv_iv_send_outstanding_bat_ogm_packet(struct work_struct *work); |
| 63 | 66 | ||
| @@ -1850,8 +1853,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb, | |||
| 1850 | /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface | 1853 | /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface |
| 1851 | * that does not have B.A.T.M.A.N. IV enabled ? | 1854 | * that does not have B.A.T.M.A.N. IV enabled ? |
| 1852 | */ | 1855 | */ |
| 1853 | if (bat_priv->bat_algo_ops->bat_iface_enable != | 1856 | if (bat_priv->algo_ops->iface.enable != batadv_iv_ogm_iface_enable) |
| 1854 | batadv_iv_ogm_iface_enable) | ||
| 1855 | return NET_RX_DROP; | 1857 | return NET_RX_DROP; |
| 1856 | 1858 | ||
| 1857 | batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX); | 1859 | batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX); |
| @@ -2117,18 +2119,24 @@ static void batadv_iv_iface_activate(struct batadv_hard_iface *hard_iface) | |||
| 2117 | 2119 | ||
| 2118 | static struct batadv_algo_ops batadv_batman_iv __read_mostly = { | 2120 | static struct batadv_algo_ops batadv_batman_iv __read_mostly = { |
| 2119 | .name = "BATMAN_IV", | 2121 | .name = "BATMAN_IV", |
| 2120 | .bat_iface_activate = batadv_iv_iface_activate, | 2122 | .iface = { |
| 2121 | .bat_iface_enable = batadv_iv_ogm_iface_enable, | 2123 | .activate = batadv_iv_iface_activate, |
| 2122 | .bat_iface_disable = batadv_iv_ogm_iface_disable, | 2124 | .enable = batadv_iv_ogm_iface_enable, |
| 2123 | .bat_iface_update_mac = batadv_iv_ogm_iface_update_mac, | 2125 | .disable = batadv_iv_ogm_iface_disable, |
| 2124 | .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set, | 2126 | .update_mac = batadv_iv_ogm_iface_update_mac, |
| 2125 | .bat_neigh_cmp = batadv_iv_ogm_neigh_cmp, | 2127 | .primary_set = batadv_iv_ogm_primary_iface_set, |
| 2126 | .bat_neigh_is_similar_or_better = batadv_iv_ogm_neigh_is_sob, | 2128 | }, |
| 2127 | .bat_neigh_print = batadv_iv_neigh_print, | 2129 | .neigh = { |
| 2128 | .bat_orig_print = batadv_iv_ogm_orig_print, | 2130 | .cmp = batadv_iv_ogm_neigh_cmp, |
| 2129 | .bat_orig_free = batadv_iv_ogm_orig_free, | 2131 | .is_similar_or_better = batadv_iv_ogm_neigh_is_sob, |
| 2130 | .bat_orig_add_if = batadv_iv_ogm_orig_add_if, | 2132 | .print = batadv_iv_neigh_print, |
| 2131 | .bat_orig_del_if = batadv_iv_ogm_orig_del_if, | 2133 | }, |
| 2134 | .orig = { | ||
| 2135 | .print = batadv_iv_ogm_orig_print, | ||
| 2136 | .free = batadv_iv_ogm_orig_free, | ||
| 2137 | .add_if = batadv_iv_ogm_orig_add_if, | ||
| 2138 | .del_if = batadv_iv_ogm_orig_del_if, | ||
| 2139 | }, | ||
| 2132 | }; | 2140 | }; |
| 2133 | 2141 | ||
| 2134 | int __init batadv_iv_init(void) | 2142 | int __init batadv_iv_init(void) |
diff --git a/net/batman-adv/bat_iv_ogm.h b/net/batman-adv/bat_iv_ogm.h new file mode 100644 index 000000000000..b9f3550faaf7 --- /dev/null +++ b/net/batman-adv/bat_iv_ogm.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | /* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Marek Lindner, Simon Wunderlich | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef _BATMAN_ADV_BATADV_IV_OGM_H_ | ||
| 19 | #define _BATMAN_ADV_BATADV_IV_OGM_H_ | ||
| 20 | |||
| 21 | #include "main.h" | ||
| 22 | |||
| 23 | int batadv_iv_init(void); | ||
| 24 | |||
| 25 | #endif /* _BATMAN_ADV_BATADV_IV_OGM_H_ */ | ||
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c index c2fea812fb48..0366cbf5e444 100644 --- a/net/batman-adv/bat_v.c +++ b/net/batman-adv/bat_v.c | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #include "bat_algo.h" | 18 | #include "bat_v.h" |
| 19 | #include "main.h" | 19 | #include "main.h" |
| 20 | 20 | ||
| 21 | #include <linux/atomic.h> | 21 | #include <linux/atomic.h> |
| @@ -31,6 +31,7 @@ | |||
| 31 | #include <linux/types.h> | 31 | #include <linux/types.h> |
| 32 | #include <linux/workqueue.h> | 32 | #include <linux/workqueue.h> |
| 33 | 33 | ||
| 34 | #include "bat_algo.h" | ||
| 34 | #include "bat_v_elp.h" | 35 | #include "bat_v_elp.h" |
| 35 | #include "bat_v_ogm.h" | 36 | #include "bat_v_ogm.h" |
| 36 | #include "hard-interface.h" | 37 | #include "hard-interface.h" |
| @@ -321,16 +322,22 @@ err_ifinfo1: | |||
| 321 | 322 | ||
| 322 | static struct batadv_algo_ops batadv_batman_v __read_mostly = { | 323 | static struct batadv_algo_ops batadv_batman_v __read_mostly = { |
| 323 | .name = "BATMAN_V", | 324 | .name = "BATMAN_V", |
| 324 | .bat_iface_activate = batadv_v_iface_activate, | 325 | .iface = { |
| 325 | .bat_iface_enable = batadv_v_iface_enable, | 326 | .activate = batadv_v_iface_activate, |
| 326 | .bat_iface_disable = batadv_v_iface_disable, | 327 | .enable = batadv_v_iface_enable, |
| 327 | .bat_iface_update_mac = batadv_v_iface_update_mac, | 328 | .disable = batadv_v_iface_disable, |
| 328 | .bat_primary_iface_set = batadv_v_primary_iface_set, | 329 | .update_mac = batadv_v_iface_update_mac, |
| 329 | .bat_hardif_neigh_init = batadv_v_hardif_neigh_init, | 330 | .primary_set = batadv_v_primary_iface_set, |
| 330 | .bat_orig_print = batadv_v_orig_print, | 331 | }, |
| 331 | .bat_neigh_cmp = batadv_v_neigh_cmp, | 332 | .neigh = { |
| 332 | .bat_neigh_is_similar_or_better = batadv_v_neigh_is_sob, | 333 | .hardif_init = batadv_v_hardif_neigh_init, |
| 333 | .bat_neigh_print = batadv_v_neigh_print, | 334 | .cmp = batadv_v_neigh_cmp, |
| 335 | .is_similar_or_better = batadv_v_neigh_is_sob, | ||
| 336 | .print = batadv_v_neigh_print, | ||
| 337 | }, | ||
| 338 | .orig = { | ||
| 339 | .print = batadv_v_orig_print, | ||
| 340 | }, | ||
| 334 | }; | 341 | }; |
| 335 | 342 | ||
| 336 | /** | 343 | /** |
diff --git a/net/batman-adv/bat_v.h b/net/batman-adv/bat_v.h new file mode 100644 index 000000000000..83b77639729e --- /dev/null +++ b/net/batman-adv/bat_v.h | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* Copyright (C) 2011-2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Marek Lindner, Linus Lüssing | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef _NET_BATMAN_ADV_BAT_V_H_ | ||
| 19 | #define _NET_BATMAN_ADV_BAT_V_H_ | ||
| 20 | |||
| 21 | #include "main.h" | ||
| 22 | |||
| 23 | #ifdef CONFIG_BATMAN_ADV_BATMAN_V | ||
| 24 | |||
| 25 | int batadv_v_init(void); | ||
| 26 | void batadv_v_hardif_init(struct batadv_hard_iface *hardif); | ||
| 27 | int batadv_v_mesh_init(struct batadv_priv *bat_priv); | ||
| 28 | void batadv_v_mesh_free(struct batadv_priv *bat_priv); | ||
| 29 | |||
| 30 | #else | ||
| 31 | |||
| 32 | static inline int batadv_v_init(void) | ||
| 33 | { | ||
| 34 | return 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | static inline void batadv_v_hardif_init(struct batadv_hard_iface *hardif) | ||
| 38 | { | ||
| 39 | } | ||
| 40 | |||
| 41 | static inline int batadv_v_mesh_init(struct batadv_priv *bat_priv) | ||
| 42 | { | ||
| 43 | return 0; | ||
| 44 | } | ||
| 45 | |||
| 46 | static inline void batadv_v_mesh_free(struct batadv_priv *bat_priv) | ||
| 47 | { | ||
| 48 | } | ||
| 49 | |||
| 50 | #endif /* CONFIG_BATMAN_ADV_BATMAN_V */ | ||
| 51 | |||
| 52 | #endif /* _NET_BATMAN_ADV_BAT_V_H_ */ | ||
diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c index cf0262becd08..7d170010beb9 100644 --- a/net/batman-adv/bat_v_elp.c +++ b/net/batman-adv/bat_v_elp.c | |||
| @@ -43,6 +43,7 @@ | |||
| 43 | #include "bat_algo.h" | 43 | #include "bat_algo.h" |
| 44 | #include "bat_v_ogm.h" | 44 | #include "bat_v_ogm.h" |
| 45 | #include "hard-interface.h" | 45 | #include "hard-interface.h" |
| 46 | #include "log.h" | ||
| 46 | #include "originator.h" | 47 | #include "originator.h" |
| 47 | #include "packet.h" | 48 | #include "packet.h" |
| 48 | #include "routing.h" | 49 | #include "routing.h" |
| @@ -503,7 +504,7 @@ int batadv_v_elp_packet_recv(struct sk_buff *skb, | |||
| 503 | /* did we receive a B.A.T.M.A.N. V ELP packet on an interface | 504 | /* did we receive a B.A.T.M.A.N. V ELP packet on an interface |
| 504 | * that does not have B.A.T.M.A.N. V ELP enabled ? | 505 | * that does not have B.A.T.M.A.N. V ELP enabled ? |
| 505 | */ | 506 | */ |
| 506 | if (strcmp(bat_priv->bat_algo_ops->name, "BATMAN_V") != 0) | 507 | if (strcmp(bat_priv->algo_ops->name, "BATMAN_V") != 0) |
| 507 | return NET_RX_DROP; | 508 | return NET_RX_DROP; |
| 508 | 509 | ||
| 509 | elp_packet = (struct batadv_elp_packet *)skb->data; | 510 | elp_packet = (struct batadv_elp_packet *)skb->data; |
diff --git a/net/batman-adv/bat_v_elp.h b/net/batman-adv/bat_v_elp.h index cc130b2d05e5..be17c0b1369e 100644 --- a/net/batman-adv/bat_v_elp.h +++ b/net/batman-adv/bat_v_elp.h | |||
| @@ -15,11 +15,11 @@ | |||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | #include "main.h" | ||
| 19 | |||
| 20 | #ifndef _NET_BATMAN_ADV_BAT_V_ELP_H_ | 18 | #ifndef _NET_BATMAN_ADV_BAT_V_ELP_H_ |
| 21 | #define _NET_BATMAN_ADV_BAT_V_ELP_H_ | 19 | #define _NET_BATMAN_ADV_BAT_V_ELP_H_ |
| 22 | 20 | ||
| 21 | #include "main.h" | ||
| 22 | |||
| 23 | struct sk_buff; | 23 | struct sk_buff; |
| 24 | struct work_struct; | 24 | struct work_struct; |
| 25 | 25 | ||
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c index 23ea9bfb9f67..6fbba4eb0617 100644 --- a/net/batman-adv/bat_v_ogm.c +++ b/net/batman-adv/bat_v_ogm.c | |||
| @@ -39,13 +39,16 @@ | |||
| 39 | #include <linux/types.h> | 39 | #include <linux/types.h> |
| 40 | #include <linux/workqueue.h> | 40 | #include <linux/workqueue.h> |
| 41 | 41 | ||
| 42 | #include "bat_algo.h" | ||
| 42 | #include "hard-interface.h" | 43 | #include "hard-interface.h" |
| 43 | #include "hash.h" | 44 | #include "hash.h" |
| 45 | #include "log.h" | ||
| 44 | #include "originator.h" | 46 | #include "originator.h" |
| 45 | #include "packet.h" | 47 | #include "packet.h" |
| 46 | #include "routing.h" | 48 | #include "routing.h" |
| 47 | #include "send.h" | 49 | #include "send.h" |
| 48 | #include "translation-table.h" | 50 | #include "translation-table.h" |
| 51 | #include "tvlv.h" | ||
| 49 | 52 | ||
| 50 | /** | 53 | /** |
| 51 | * batadv_v_ogm_orig_get - retrieve and possibly create an originator node | 54 | * batadv_v_ogm_orig_get - retrieve and possibly create an originator node |
| @@ -751,7 +754,7 @@ int batadv_v_ogm_packet_recv(struct sk_buff *skb, | |||
| 751 | /* did we receive a OGM2 packet on an interface that does not have | 754 | /* did we receive a OGM2 packet on an interface that does not have |
| 752 | * B.A.T.M.A.N. V enabled ? | 755 | * B.A.T.M.A.N. V enabled ? |
| 753 | */ | 756 | */ |
| 754 | if (strcmp(bat_priv->bat_algo_ops->name, "BATMAN_V") != 0) | 757 | if (strcmp(bat_priv->algo_ops->name, "BATMAN_V") != 0) |
| 755 | return NET_RX_DROP; | 758 | return NET_RX_DROP; |
| 756 | 759 | ||
| 757 | if (!batadv_check_management_packet(skb, if_incoming, BATADV_OGM2_HLEN)) | 760 | if (!batadv_check_management_packet(skb, if_incoming, BATADV_OGM2_HLEN)) |
diff --git a/net/batman-adv/bat_v_ogm.h b/net/batman-adv/bat_v_ogm.h index d849c75ada0e..4c4d45caa422 100644 --- a/net/batman-adv/bat_v_ogm.h +++ b/net/batman-adv/bat_v_ogm.h | |||
| @@ -18,10 +18,10 @@ | |||
| 18 | #ifndef _BATMAN_ADV_BATADV_V_OGM_H_ | 18 | #ifndef _BATMAN_ADV_BATADV_V_OGM_H_ |
| 19 | #define _BATMAN_ADV_BATADV_V_OGM_H_ | 19 | #define _BATMAN_ADV_BATADV_V_OGM_H_ |
| 20 | 20 | ||
| 21 | #include "main.h" | ||
| 22 | |||
| 21 | #include <linux/types.h> | 23 | #include <linux/types.h> |
| 22 | 24 | ||
| 23 | struct batadv_hard_iface; | ||
| 24 | struct batadv_priv; | ||
| 25 | struct sk_buff; | 25 | struct sk_buff; |
| 26 | 26 | ||
| 27 | int batadv_v_ogm_init(struct batadv_priv *bat_priv); | 27 | int batadv_v_ogm_init(struct batadv_priv *bat_priv); |
diff --git a/net/batman-adv/bitarray.c b/net/batman-adv/bitarray.c index a0c7913837a5..032271421a20 100644 --- a/net/batman-adv/bitarray.c +++ b/net/batman-adv/bitarray.c | |||
| @@ -20,6 +20,8 @@ | |||
| 20 | 20 | ||
| 21 | #include <linux/bitmap.h> | 21 | #include <linux/bitmap.h> |
| 22 | 22 | ||
| 23 | #include "log.h" | ||
| 24 | |||
| 23 | /* shift the packet array by n places. */ | 25 | /* shift the packet array by n places. */ |
| 24 | static void batadv_bitmap_shift_left(unsigned long *seq_bits, s32 n) | 26 | static void batadv_bitmap_shift_left(unsigned long *seq_bits, s32 n) |
| 25 | { | 27 | { |
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 748a9ead7ce5..e4f7494fb974 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c | |||
| @@ -48,6 +48,7 @@ | |||
| 48 | 48 | ||
| 49 | #include "hard-interface.h" | 49 | #include "hard-interface.h" |
| 50 | #include "hash.h" | 50 | #include "hash.h" |
| 51 | #include "log.h" | ||
| 51 | #include "originator.h" | 52 | #include "originator.h" |
| 52 | #include "packet.h" | 53 | #include "packet.h" |
| 53 | #include "sysfs.h" | 54 | #include "sysfs.h" |
diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c index f187a8ff2184..1d68b6e63b96 100644 --- a/net/batman-adv/debugfs.c +++ b/net/batman-adv/debugfs.c | |||
| @@ -18,36 +18,26 @@ | |||
| 18 | #include "debugfs.h" | 18 | #include "debugfs.h" |
| 19 | #include "main.h" | 19 | #include "main.h" |
| 20 | 20 | ||
| 21 | #include <linux/compiler.h> | ||
| 22 | #include <linux/debugfs.h> | 21 | #include <linux/debugfs.h> |
| 23 | #include <linux/device.h> | 22 | #include <linux/device.h> |
| 24 | #include <linux/errno.h> | 23 | #include <linux/errno.h> |
| 25 | #include <linux/export.h> | 24 | #include <linux/export.h> |
| 26 | #include <linux/fcntl.h> | ||
| 27 | #include <linux/fs.h> | 25 | #include <linux/fs.h> |
| 28 | #include <linux/jiffies.h> | ||
| 29 | #include <linux/kernel.h> | ||
| 30 | #include <linux/module.h> | ||
| 31 | #include <linux/netdevice.h> | 26 | #include <linux/netdevice.h> |
| 32 | #include <linux/poll.h> | ||
| 33 | #include <linux/printk.h> | 27 | #include <linux/printk.h> |
| 34 | #include <linux/sched.h> /* for linux/wait.h */ | 28 | #include <linux/sched.h> /* for linux/wait.h */ |
| 35 | #include <linux/seq_file.h> | 29 | #include <linux/seq_file.h> |
| 36 | #include <linux/slab.h> | ||
| 37 | #include <linux/spinlock.h> | ||
| 38 | #include <linux/stat.h> | 30 | #include <linux/stat.h> |
| 39 | #include <linux/stddef.h> | 31 | #include <linux/stddef.h> |
| 40 | #include <linux/stringify.h> | 32 | #include <linux/stringify.h> |
| 41 | #include <linux/sysfs.h> | 33 | #include <linux/sysfs.h> |
| 42 | #include <linux/types.h> | ||
| 43 | #include <linux/uaccess.h> | ||
| 44 | #include <linux/wait.h> | ||
| 45 | #include <stdarg.h> | ||
| 46 | 34 | ||
| 35 | #include "bat_algo.h" | ||
| 47 | #include "bridge_loop_avoidance.h" | 36 | #include "bridge_loop_avoidance.h" |
| 48 | #include "distributed-arp-table.h" | 37 | #include "distributed-arp-table.h" |
| 49 | #include "gateway_client.h" | 38 | #include "gateway_client.h" |
| 50 | #include "icmp_socket.h" | 39 | #include "icmp_socket.h" |
| 40 | #include "log.h" | ||
| 51 | #include "multicast.h" | 41 | #include "multicast.h" |
| 52 | #include "network-coding.h" | 42 | #include "network-coding.h" |
| 53 | #include "originator.h" | 43 | #include "originator.h" |
| @@ -55,209 +45,6 @@ | |||
| 55 | 45 | ||
| 56 | static struct dentry *batadv_debugfs; | 46 | static struct dentry *batadv_debugfs; |
| 57 | 47 | ||
| 58 | #ifdef CONFIG_BATMAN_ADV_DEBUG | ||
| 59 | #define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1) | ||
| 60 | |||
| 61 | static const int batadv_log_buff_len = BATADV_LOG_BUF_LEN; | ||
| 62 | |||
| 63 | static char *batadv_log_char_addr(struct batadv_priv_debug_log *debug_log, | ||
| 64 | size_t idx) | ||
| 65 | { | ||
| 66 | return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK]; | ||
| 67 | } | ||
| 68 | |||
| 69 | static void batadv_emit_log_char(struct batadv_priv_debug_log *debug_log, | ||
| 70 | char c) | ||
| 71 | { | ||
| 72 | char *char_addr; | ||
| 73 | |||
| 74 | char_addr = batadv_log_char_addr(debug_log, debug_log->log_end); | ||
| 75 | *char_addr = c; | ||
| 76 | debug_log->log_end++; | ||
| 77 | |||
| 78 | if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len) | ||
| 79 | debug_log->log_start = debug_log->log_end - batadv_log_buff_len; | ||
| 80 | } | ||
| 81 | |||
| 82 | __printf(2, 3) | ||
| 83 | static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log, | ||
| 84 | const char *fmt, ...) | ||
| 85 | { | ||
| 86 | va_list args; | ||
| 87 | static char debug_log_buf[256]; | ||
| 88 | char *p; | ||
| 89 | |||
| 90 | if (!debug_log) | ||
| 91 | return 0; | ||
| 92 | |||
| 93 | spin_lock_bh(&debug_log->lock); | ||
| 94 | va_start(args, fmt); | ||
| 95 | vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args); | ||
| 96 | va_end(args); | ||
| 97 | |||
| 98 | for (p = debug_log_buf; *p != 0; p++) | ||
| 99 | batadv_emit_log_char(debug_log, *p); | ||
| 100 | |||
| 101 | spin_unlock_bh(&debug_log->lock); | ||
| 102 | |||
| 103 | wake_up(&debug_log->queue_wait); | ||
| 104 | |||
| 105 | return 0; | ||
| 106 | } | ||
| 107 | |||
| 108 | int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...) | ||
| 109 | { | ||
| 110 | va_list args; | ||
| 111 | char tmp_log_buf[256]; | ||
| 112 | |||
| 113 | va_start(args, fmt); | ||
| 114 | vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args); | ||
| 115 | batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s", | ||
| 116 | jiffies_to_msecs(jiffies), tmp_log_buf); | ||
| 117 | va_end(args); | ||
| 118 | |||
| 119 | return 0; | ||
| 120 | } | ||
| 121 | |||
| 122 | static int batadv_log_open(struct inode *inode, struct file *file) | ||
| 123 | { | ||
| 124 | if (!try_module_get(THIS_MODULE)) | ||
| 125 | return -EBUSY; | ||
| 126 | |||
| 127 | nonseekable_open(inode, file); | ||
| 128 | file->private_data = inode->i_private; | ||
| 129 | return 0; | ||
| 130 | } | ||
| 131 | |||
| 132 | static int batadv_log_release(struct inode *inode, struct file *file) | ||
| 133 | { | ||
| 134 | module_put(THIS_MODULE); | ||
| 135 | return 0; | ||
| 136 | } | ||
| 137 | |||
| 138 | static bool batadv_log_empty(struct batadv_priv_debug_log *debug_log) | ||
| 139 | { | ||
| 140 | return !(debug_log->log_start - debug_log->log_end); | ||
| 141 | } | ||
| 142 | |||
| 143 | static ssize_t batadv_log_read(struct file *file, char __user *buf, | ||
| 144 | size_t count, loff_t *ppos) | ||
| 145 | { | ||
| 146 | struct batadv_priv *bat_priv = file->private_data; | ||
| 147 | struct batadv_priv_debug_log *debug_log = bat_priv->debug_log; | ||
| 148 | int error, i = 0; | ||
| 149 | char *char_addr; | ||
| 150 | char c; | ||
| 151 | |||
| 152 | if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log)) | ||
| 153 | return -EAGAIN; | ||
| 154 | |||
| 155 | if (!buf) | ||
| 156 | return -EINVAL; | ||
| 157 | |||
| 158 | if (count == 0) | ||
| 159 | return 0; | ||
| 160 | |||
| 161 | if (!access_ok(VERIFY_WRITE, buf, count)) | ||
| 162 | return -EFAULT; | ||
| 163 | |||
| 164 | error = wait_event_interruptible(debug_log->queue_wait, | ||
| 165 | (!batadv_log_empty(debug_log))); | ||
| 166 | |||
| 167 | if (error) | ||
| 168 | return error; | ||
| 169 | |||
| 170 | spin_lock_bh(&debug_log->lock); | ||
| 171 | |||
| 172 | while ((!error) && (i < count) && | ||
| 173 | (debug_log->log_start != debug_log->log_end)) { | ||
| 174 | char_addr = batadv_log_char_addr(debug_log, | ||
| 175 | debug_log->log_start); | ||
| 176 | c = *char_addr; | ||
| 177 | |||
| 178 | debug_log->log_start++; | ||
| 179 | |||
| 180 | spin_unlock_bh(&debug_log->lock); | ||
| 181 | |||
| 182 | error = __put_user(c, buf); | ||
| 183 | |||
| 184 | spin_lock_bh(&debug_log->lock); | ||
| 185 | |||
| 186 | buf++; | ||
| 187 | i++; | ||
| 188 | } | ||
| 189 | |||
| 190 | spin_unlock_bh(&debug_log->lock); | ||
| 191 | |||
| 192 | if (!error) | ||
| 193 | return i; | ||
| 194 | |||
| 195 | return error; | ||
| 196 | } | ||
| 197 | |||
| 198 | static unsigned int batadv_log_poll(struct file *file, poll_table *wait) | ||
| 199 | { | ||
| 200 | struct batadv_priv *bat_priv = file->private_data; | ||
| 201 | struct batadv_priv_debug_log *debug_log = bat_priv->debug_log; | ||
| 202 | |||
| 203 | poll_wait(file, &debug_log->queue_wait, wait); | ||
| 204 | |||
| 205 | if (!batadv_log_empty(debug_log)) | ||
| 206 | return POLLIN | POLLRDNORM; | ||
| 207 | |||
| 208 | return 0; | ||
| 209 | } | ||
| 210 | |||
| 211 | static const struct file_operations batadv_log_fops = { | ||
| 212 | .open = batadv_log_open, | ||
| 213 | .release = batadv_log_release, | ||
| 214 | .read = batadv_log_read, | ||
| 215 | .poll = batadv_log_poll, | ||
| 216 | .llseek = no_llseek, | ||
| 217 | }; | ||
| 218 | |||
| 219 | static int batadv_debug_log_setup(struct batadv_priv *bat_priv) | ||
| 220 | { | ||
| 221 | struct dentry *d; | ||
| 222 | |||
| 223 | if (!bat_priv->debug_dir) | ||
| 224 | goto err; | ||
| 225 | |||
| 226 | bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC); | ||
| 227 | if (!bat_priv->debug_log) | ||
| 228 | goto err; | ||
| 229 | |||
| 230 | spin_lock_init(&bat_priv->debug_log->lock); | ||
| 231 | init_waitqueue_head(&bat_priv->debug_log->queue_wait); | ||
| 232 | |||
| 233 | d = debugfs_create_file("log", S_IFREG | S_IRUSR, | ||
| 234 | bat_priv->debug_dir, bat_priv, | ||
| 235 | &batadv_log_fops); | ||
| 236 | if (!d) | ||
| 237 | goto err; | ||
| 238 | |||
| 239 | return 0; | ||
| 240 | |||
| 241 | err: | ||
| 242 | return -ENOMEM; | ||
| 243 | } | ||
| 244 | |||
| 245 | static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv) | ||
| 246 | { | ||
| 247 | kfree(bat_priv->debug_log); | ||
| 248 | bat_priv->debug_log = NULL; | ||
| 249 | } | ||
| 250 | #else /* CONFIG_BATMAN_ADV_DEBUG */ | ||
| 251 | static int batadv_debug_log_setup(struct batadv_priv *bat_priv) | ||
| 252 | { | ||
| 253 | return 0; | ||
| 254 | } | ||
| 255 | |||
| 256 | static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv) | ||
| 257 | { | ||
| 258 | } | ||
| 259 | #endif | ||
| 260 | |||
| 261 | static int batadv_algorithms_open(struct inode *inode, struct file *file) | 48 | static int batadv_algorithms_open(struct inode *inode, struct file *file) |
| 262 | { | 49 | { |
| 263 | return single_open(file, batadv_algo_seq_print_text, NULL); | 50 | 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 278800a99c69..fa7646532a13 100644 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c | |||
| @@ -45,9 +45,11 @@ | |||
| 45 | 45 | ||
| 46 | #include "hard-interface.h" | 46 | #include "hard-interface.h" |
| 47 | #include "hash.h" | 47 | #include "hash.h" |
| 48 | #include "log.h" | ||
| 48 | #include "originator.h" | 49 | #include "originator.h" |
| 49 | #include "send.h" | 50 | #include "send.h" |
| 50 | #include "translation-table.h" | 51 | #include "translation-table.h" |
| 52 | #include "tvlv.h" | ||
| 51 | 53 | ||
| 52 | static void batadv_dat_purge(struct work_struct *work); | 54 | static void batadv_dat_purge(struct work_struct *work); |
| 53 | 55 | ||
diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c index 9f41a0a0d6ab..0934730fb7ff 100644 --- a/net/batman-adv/fragmentation.c +++ b/net/batman-adv/fragmentation.c | |||
| @@ -433,11 +433,12 @@ err: | |||
| 433 | * @orig_node: final destination of the created fragments | 433 | * @orig_node: final destination of the created fragments |
| 434 | * @neigh_node: next-hop of the created fragments | 434 | * @neigh_node: next-hop of the created fragments |
| 435 | * | 435 | * |
| 436 | * Return: true on success, false otherwise. | 436 | * Return: the netdev tx status or -1 in case of error. |
| 437 | * When -1 is returned the skb is not consumed. | ||
| 437 | */ | 438 | */ |
| 438 | bool batadv_frag_send_packet(struct sk_buff *skb, | 439 | int batadv_frag_send_packet(struct sk_buff *skb, |
| 439 | struct batadv_orig_node *orig_node, | 440 | struct batadv_orig_node *orig_node, |
| 440 | struct batadv_neigh_node *neigh_node) | 441 | struct batadv_neigh_node *neigh_node) |
| 441 | { | 442 | { |
| 442 | struct batadv_priv *bat_priv; | 443 | struct batadv_priv *bat_priv; |
| 443 | struct batadv_hard_iface *primary_if = NULL; | 444 | struct batadv_hard_iface *primary_if = NULL; |
| @@ -446,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb, | |||
| 446 | unsigned int mtu = neigh_node->if_incoming->net_dev->mtu; | 447 | unsigned int mtu = neigh_node->if_incoming->net_dev->mtu; |
| 447 | unsigned int header_size = sizeof(frag_header); | 448 | unsigned int header_size = sizeof(frag_header); |
| 448 | unsigned int max_fragment_size, max_packet_size; | 449 | unsigned int max_fragment_size, max_packet_size; |
| 449 | bool ret = false; | 450 | int ret = -1; |
| 450 | 451 | ||
| 451 | /* To avoid merge and refragmentation at next-hops we never send | 452 | /* To avoid merge and refragmentation at next-hops we never send |
| 452 | * fragments larger than BATADV_FRAG_MAX_FRAG_SIZE | 453 | * fragments larger than BATADV_FRAG_MAX_FRAG_SIZE |
| @@ -457,12 +458,12 @@ bool batadv_frag_send_packet(struct sk_buff *skb, | |||
| 457 | 458 | ||
| 458 | /* Don't even try to fragment, if we need more than 16 fragments */ | 459 | /* Don't even try to fragment, if we need more than 16 fragments */ |
| 459 | if (skb->len > max_packet_size) | 460 | if (skb->len > max_packet_size) |
| 460 | goto out_err; | 461 | goto out; |
| 461 | 462 | ||
| 462 | bat_priv = orig_node->bat_priv; | 463 | bat_priv = orig_node->bat_priv; |
| 463 | primary_if = batadv_primary_if_get_selected(bat_priv); | 464 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 464 | if (!primary_if) | 465 | if (!primary_if) |
| 465 | goto out_err; | 466 | goto out; |
| 466 | 467 | ||
| 467 | /* Create one header to be copied to all fragments */ | 468 | /* Create one header to be copied to all fragments */ |
| 468 | frag_header.packet_type = BATADV_UNICAST_FRAG; | 469 | frag_header.packet_type = BATADV_UNICAST_FRAG; |
| @@ -488,23 +489,33 @@ bool batadv_frag_send_packet(struct sk_buff *skb, | |||
| 488 | while (skb->len > max_fragment_size) { | 489 | while (skb->len > max_fragment_size) { |
| 489 | skb_fragment = batadv_frag_create(skb, &frag_header, mtu); | 490 | skb_fragment = batadv_frag_create(skb, &frag_header, mtu); |
| 490 | if (!skb_fragment) | 491 | if (!skb_fragment) |
| 491 | goto out_err; | 492 | goto out; |
| 492 | 493 | ||
| 493 | batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_TX); | 494 | batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_TX); |
| 494 | batadv_add_counter(bat_priv, BATADV_CNT_FRAG_TX_BYTES, | 495 | batadv_add_counter(bat_priv, BATADV_CNT_FRAG_TX_BYTES, |
| 495 | skb_fragment->len + ETH_HLEN); | 496 | skb_fragment->len + ETH_HLEN); |
| 496 | batadv_send_unicast_skb(skb_fragment, neigh_node); | 497 | ret = batadv_send_unicast_skb(skb_fragment, neigh_node); |
| 498 | if (ret != NET_XMIT_SUCCESS) { | ||
| 499 | /* return -1 so that the caller can free the original | ||
| 500 | * skb | ||
| 501 | */ | ||
| 502 | ret = -1; | ||
| 503 | goto out; | ||
| 504 | } | ||
| 505 | |||
| 497 | frag_header.no++; | 506 | frag_header.no++; |
| 498 | 507 | ||
| 499 | /* The initial check in this function should cover this case */ | 508 | /* The initial check in this function should cover this case */ |
| 500 | if (frag_header.no == BATADV_FRAG_MAX_FRAGMENTS - 1) | 509 | if (frag_header.no == BATADV_FRAG_MAX_FRAGMENTS - 1) { |
| 501 | goto out_err; | 510 | ret = -1; |
| 511 | goto out; | ||
| 512 | } | ||
| 502 | } | 513 | } |
| 503 | 514 | ||
| 504 | /* Make room for the fragment header. */ | 515 | /* Make room for the fragment header. */ |
| 505 | if (batadv_skb_head_push(skb, header_size) < 0 || | 516 | if (batadv_skb_head_push(skb, header_size) < 0 || |
| 506 | pskb_expand_head(skb, header_size + ETH_HLEN, 0, GFP_ATOMIC) < 0) | 517 | pskb_expand_head(skb, header_size + ETH_HLEN, 0, GFP_ATOMIC) < 0) |
| 507 | goto out_err; | 518 | goto out; |
| 508 | 519 | ||
| 509 | memcpy(skb->data, &frag_header, header_size); | 520 | memcpy(skb->data, &frag_header, header_size); |
| 510 | 521 | ||
| @@ -512,11 +523,9 @@ bool batadv_frag_send_packet(struct sk_buff *skb, | |||
| 512 | batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_TX); | 523 | batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_TX); |
| 513 | batadv_add_counter(bat_priv, BATADV_CNT_FRAG_TX_BYTES, | 524 | batadv_add_counter(bat_priv, BATADV_CNT_FRAG_TX_BYTES, |
| 514 | skb->len + ETH_HLEN); | 525 | skb->len + ETH_HLEN); |
| 515 | batadv_send_unicast_skb(skb, neigh_node); | 526 | ret = batadv_send_unicast_skb(skb, neigh_node); |
| 516 | 527 | ||
| 517 | ret = true; | 528 | out: |
| 518 | |||
| 519 | out_err: | ||
| 520 | if (primary_if) | 529 | if (primary_if) |
| 521 | batadv_hardif_put(primary_if); | 530 | batadv_hardif_put(primary_if); |
| 522 | 531 | ||
diff --git a/net/batman-adv/fragmentation.h b/net/batman-adv/fragmentation.h index 9ff77c7ef7c7..3202fe329e63 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, | |||
| 34 | struct batadv_orig_node *orig_node_src); | 34 | struct batadv_orig_node *orig_node_src); |
| 35 | bool batadv_frag_skb_buffer(struct sk_buff **skb, | 35 | bool batadv_frag_skb_buffer(struct sk_buff **skb, |
| 36 | struct batadv_orig_node *orig_node); | 36 | struct batadv_orig_node *orig_node); |
| 37 | bool batadv_frag_send_packet(struct sk_buff *skb, | 37 | int batadv_frag_send_packet(struct sk_buff *skb, |
| 38 | struct batadv_orig_node *orig_node, | 38 | struct batadv_orig_node *orig_node, |
| 39 | struct batadv_neigh_node *neigh_node); | 39 | struct batadv_neigh_node *neigh_node); |
| 40 | 40 | ||
| 41 | /** | 41 | /** |
| 42 | * batadv_frag_check_entry - check if a list of fragments has timed out | 42 | * batadv_frag_check_entry - check if a list of fragments has timed out |
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 18c3715e5e27..63a805d3f96e 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c | |||
| @@ -42,6 +42,7 @@ | |||
| 42 | 42 | ||
| 43 | #include "gateway_common.h" | 43 | #include "gateway_common.h" |
| 44 | #include "hard-interface.h" | 44 | #include "hard-interface.h" |
| 45 | #include "log.h" | ||
| 45 | #include "originator.h" | 46 | #include "originator.h" |
| 46 | #include "packet.h" | 47 | #include "packet.h" |
| 47 | #include "routing.h" | 48 | #include "routing.h" |
diff --git a/net/batman-adv/gateway_common.c b/net/batman-adv/gateway_common.c index 3c269457776e..d7bc6a87bcc9 100644 --- a/net/batman-adv/gateway_common.c +++ b/net/batman-adv/gateway_common.c | |||
| @@ -19,8 +19,8 @@ | |||
| 19 | #include "main.h" | 19 | #include "main.h" |
| 20 | 20 | ||
| 21 | #include <linux/atomic.h> | 21 | #include <linux/atomic.h> |
| 22 | #include <linux/errno.h> | ||
| 23 | #include <linux/byteorder/generic.h> | 22 | #include <linux/byteorder/generic.h> |
| 23 | #include <linux/errno.h> | ||
| 24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/math64.h> | 25 | #include <linux/math64.h> |
| 26 | #include <linux/netdevice.h> | 26 | #include <linux/netdevice.h> |
| @@ -28,7 +28,9 @@ | |||
| 28 | #include <linux/string.h> | 28 | #include <linux/string.h> |
| 29 | 29 | ||
| 30 | #include "gateway_client.h" | 30 | #include "gateway_client.h" |
| 31 | #include "log.h" | ||
| 31 | #include "packet.h" | 32 | #include "packet.h" |
| 33 | #include "tvlv.h" | ||
| 32 | 34 | ||
| 33 | /** | 35 | /** |
| 34 | * batadv_parse_throughput - parse supplied string buffer to extract throughput | 36 | * batadv_parse_throughput - parse supplied string buffer to extract throughput |
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 3696929e5692..1f9080840566 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c | |||
| @@ -23,9 +23,9 @@ | |||
| 23 | #include <linux/byteorder/generic.h> | 23 | #include <linux/byteorder/generic.h> |
| 24 | #include <linux/errno.h> | 24 | #include <linux/errno.h> |
| 25 | #include <linux/fs.h> | 25 | #include <linux/fs.h> |
| 26 | #include <linux/if.h> | ||
| 26 | #include <linux/if_arp.h> | 27 | #include <linux/if_arp.h> |
| 27 | #include <linux/if_ether.h> | 28 | #include <linux/if_ether.h> |
| 28 | #include <linux/if.h> | ||
| 29 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
| 30 | #include <linux/kref.h> | 30 | #include <linux/kref.h> |
| 31 | #include <linux/list.h> | 31 | #include <linux/list.h> |
| @@ -37,11 +37,12 @@ | |||
| 37 | #include <linux/spinlock.h> | 37 | #include <linux/spinlock.h> |
| 38 | #include <linux/workqueue.h> | 38 | #include <linux/workqueue.h> |
| 39 | 39 | ||
| 40 | #include "bat_algo.h" | 40 | #include "bat_v.h" |
| 41 | #include "bridge_loop_avoidance.h" | 41 | #include "bridge_loop_avoidance.h" |
| 42 | #include "debugfs.h" | 42 | #include "debugfs.h" |
| 43 | #include "distributed-arp-table.h" | 43 | #include "distributed-arp-table.h" |
| 44 | #include "gateway_client.h" | 44 | #include "gateway_client.h" |
| 45 | #include "log.h" | ||
| 45 | #include "originator.h" | 46 | #include "originator.h" |
| 46 | #include "packet.h" | 47 | #include "packet.h" |
| 47 | #include "send.h" | 48 | #include "send.h" |
| @@ -246,7 +247,7 @@ static void batadv_primary_if_select(struct batadv_priv *bat_priv, | |||
| 246 | if (!new_hard_iface) | 247 | if (!new_hard_iface) |
| 247 | goto out; | 248 | goto out; |
| 248 | 249 | ||
| 249 | bat_priv->bat_algo_ops->bat_primary_iface_set(new_hard_iface); | 250 | bat_priv->algo_ops->iface.primary_set(new_hard_iface); |
| 250 | batadv_primary_if_update_addr(bat_priv, curr_hard_iface); | 251 | batadv_primary_if_update_addr(bat_priv, curr_hard_iface); |
| 251 | 252 | ||
| 252 | out: | 253 | out: |
| @@ -393,7 +394,7 @@ batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface) | |||
| 393 | 394 | ||
| 394 | bat_priv = netdev_priv(hard_iface->soft_iface); | 395 | bat_priv = netdev_priv(hard_iface->soft_iface); |
| 395 | 396 | ||
| 396 | bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface); | 397 | bat_priv->algo_ops->iface.update_mac(hard_iface); |
| 397 | hard_iface->if_status = BATADV_IF_TO_BE_ACTIVATED; | 398 | hard_iface->if_status = BATADV_IF_TO_BE_ACTIVATED; |
| 398 | 399 | ||
| 399 | /* the first active interface becomes our primary interface or | 400 | /* the first active interface becomes our primary interface or |
| @@ -408,8 +409,8 @@ batadv_hardif_activate_interface(struct batadv_hard_iface *hard_iface) | |||
| 408 | 409 | ||
| 409 | batadv_update_min_mtu(hard_iface->soft_iface); | 410 | batadv_update_min_mtu(hard_iface->soft_iface); |
| 410 | 411 | ||
| 411 | if (bat_priv->bat_algo_ops->bat_iface_activate) | 412 | if (bat_priv->algo_ops->iface.activate) |
| 412 | bat_priv->bat_algo_ops->bat_iface_activate(hard_iface); | 413 | bat_priv->algo_ops->iface.activate(hard_iface); |
| 413 | 414 | ||
| 414 | out: | 415 | out: |
| 415 | if (primary_if) | 416 | if (primary_if) |
| @@ -507,7 +508,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, | |||
| 507 | if (ret) | 508 | if (ret) |
| 508 | goto err_dev; | 509 | goto err_dev; |
| 509 | 510 | ||
| 510 | ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface); | 511 | ret = bat_priv->algo_ops->iface.enable(hard_iface); |
| 511 | if (ret < 0) | 512 | if (ret < 0) |
| 512 | goto err_upper; | 513 | goto err_upper; |
| 513 | 514 | ||
| @@ -516,7 +517,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, | |||
| 516 | hard_iface->if_status = BATADV_IF_INACTIVE; | 517 | hard_iface->if_status = BATADV_IF_INACTIVE; |
| 517 | ret = batadv_orig_hash_add_if(hard_iface, bat_priv->num_ifaces); | 518 | ret = batadv_orig_hash_add_if(hard_iface, bat_priv->num_ifaces); |
| 518 | if (ret < 0) { | 519 | if (ret < 0) { |
| 519 | bat_priv->bat_algo_ops->bat_iface_disable(hard_iface); | 520 | bat_priv->algo_ops->iface.disable(hard_iface); |
| 520 | bat_priv->num_ifaces--; | 521 | bat_priv->num_ifaces--; |
| 521 | hard_iface->if_status = BATADV_IF_NOT_IN_USE; | 522 | hard_iface->if_status = BATADV_IF_NOT_IN_USE; |
| 522 | goto err_upper; | 523 | goto err_upper; |
| @@ -597,7 +598,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface, | |||
| 597 | batadv_hardif_put(new_if); | 598 | batadv_hardif_put(new_if); |
| 598 | } | 599 | } |
| 599 | 600 | ||
| 600 | bat_priv->bat_algo_ops->bat_iface_disable(hard_iface); | 601 | bat_priv->algo_ops->iface.disable(hard_iface); |
| 601 | hard_iface->if_status = BATADV_IF_NOT_IN_USE; | 602 | hard_iface->if_status = BATADV_IF_NOT_IN_USE; |
| 602 | 603 | ||
| 603 | /* delete all references to this hard_iface */ | 604 | /* delete all references to this hard_iface */ |
| @@ -782,7 +783,7 @@ static int batadv_hard_if_event(struct notifier_block *this, | |||
| 782 | batadv_check_known_mac_addr(hard_iface->net_dev); | 783 | batadv_check_known_mac_addr(hard_iface->net_dev); |
| 783 | 784 | ||
| 784 | bat_priv = netdev_priv(hard_iface->soft_iface); | 785 | bat_priv = netdev_priv(hard_iface->soft_iface); |
| 785 | bat_priv->bat_algo_ops->bat_iface_update_mac(hard_iface); | 786 | bat_priv->algo_ops->iface.update_mac(hard_iface); |
| 786 | 787 | ||
| 787 | primary_if = batadv_primary_if_get_selected(bat_priv); | 788 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 788 | if (!primary_if) | 789 | if (!primary_if) |
diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c index 777aea10cd8f..378cc1119d66 100644 --- a/net/batman-adv/icmp_socket.c +++ b/net/batman-adv/icmp_socket.c | |||
| @@ -45,6 +45,7 @@ | |||
| 45 | #include <linux/wait.h> | 45 | #include <linux/wait.h> |
| 46 | 46 | ||
| 47 | #include "hard-interface.h" | 47 | #include "hard-interface.h" |
| 48 | #include "log.h" | ||
| 48 | #include "originator.h" | 49 | #include "originator.h" |
| 49 | #include "packet.h" | 50 | #include "packet.h" |
| 50 | #include "send.h" | 51 | #include "send.h" |
diff --git a/net/batman-adv/log.c b/net/batman-adv/log.c new file mode 100644 index 000000000000..56dc532f7a2c --- /dev/null +++ b/net/batman-adv/log.c | |||
| @@ -0,0 +1,231 @@ | |||
| 1 | /* Copyright (C) 2010-2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Marek Lindner | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "log.h" | ||
| 19 | #include "main.h" | ||
| 20 | |||
| 21 | #include <linux/compiler.h> | ||
| 22 | #include <linux/debugfs.h> | ||
| 23 | #include <linux/errno.h> | ||
| 24 | #include <linux/export.h> | ||
| 25 | #include <linux/fcntl.h> | ||
| 26 | #include <linux/fs.h> | ||
| 27 | #include <linux/jiffies.h> | ||
| 28 | #include <linux/kernel.h> | ||
| 29 | #include <linux/module.h> | ||
| 30 | #include <linux/poll.h> | ||
| 31 | #include <linux/sched.h> /* for linux/wait.h */ | ||
| 32 | #include <linux/slab.h> | ||
| 33 | #include <linux/spinlock.h> | ||
| 34 | #include <linux/stat.h> | ||
| 35 | #include <linux/stddef.h> | ||
| 36 | #include <linux/types.h> | ||
| 37 | #include <linux/uaccess.h> | ||
| 38 | #include <linux/wait.h> | ||
| 39 | #include <stdarg.h> | ||
| 40 | |||
| 41 | #define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1) | ||
| 42 | |||
| 43 | static const int batadv_log_buff_len = BATADV_LOG_BUF_LEN; | ||
| 44 | |||
| 45 | static char *batadv_log_char_addr(struct batadv_priv_debug_log *debug_log, | ||
| 46 | size_t idx) | ||
| 47 | { | ||
| 48 | return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK]; | ||
| 49 | } | ||
| 50 | |||
| 51 | static void batadv_emit_log_char(struct batadv_priv_debug_log *debug_log, | ||
| 52 | char c) | ||
| 53 | { | ||
| 54 | char *char_addr; | ||
| 55 | |||
| 56 | char_addr = batadv_log_char_addr(debug_log, debug_log->log_end); | ||
| 57 | *char_addr = c; | ||
| 58 | debug_log->log_end++; | ||
| 59 | |||
| 60 | if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len) | ||
| 61 | debug_log->log_start = debug_log->log_end - batadv_log_buff_len; | ||
| 62 | } | ||
| 63 | |||
| 64 | __printf(2, 3) | ||
| 65 | static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log, | ||
| 66 | const char *fmt, ...) | ||
| 67 | { | ||
| 68 | va_list args; | ||
| 69 | static char debug_log_buf[256]; | ||
| 70 | char *p; | ||
| 71 | |||
| 72 | if (!debug_log) | ||
| 73 | return 0; | ||
| 74 | |||
| 75 | spin_lock_bh(&debug_log->lock); | ||
| 76 | va_start(args, fmt); | ||
| 77 | vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args); | ||
| 78 | va_end(args); | ||
| 79 | |||
| 80 | for (p = debug_log_buf; *p != 0; p++) | ||
| 81 | batadv_emit_log_char(debug_log, *p); | ||
| 82 | |||
| 83 | spin_unlock_bh(&debug_log->lock); | ||
| 84 | |||
| 85 | wake_up(&debug_log->queue_wait); | ||
| 86 | |||
| 87 | return 0; | ||
| 88 | } | ||
| 89 | |||
| 90 | int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...) | ||
| 91 | { | ||
| 92 | va_list args; | ||
| 93 | char tmp_log_buf[256]; | ||
| 94 | |||
| 95 | va_start(args, fmt); | ||
| 96 | vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args); | ||
| 97 | batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s", | ||
| 98 | jiffies_to_msecs(jiffies), tmp_log_buf); | ||
| 99 | va_end(args); | ||
| 100 | |||
| 101 | return 0; | ||
| 102 | } | ||
| 103 | |||
| 104 | static int batadv_log_open(struct inode *inode, struct file *file) | ||
| 105 | { | ||
| 106 | if (!try_module_get(THIS_MODULE)) | ||
| 107 | return -EBUSY; | ||
| 108 | |||
| 109 | nonseekable_open(inode, file); | ||
| 110 | file->private_data = inode->i_private; | ||
| 111 | return 0; | ||
| 112 | } | ||
| 113 | |||
| 114 | static int batadv_log_release(struct inode *inode, struct file *file) | ||
| 115 | { | ||
| 116 | module_put(THIS_MODULE); | ||
| 117 | return 0; | ||
| 118 | } | ||
| 119 | |||
| 120 | static bool batadv_log_empty(struct batadv_priv_debug_log *debug_log) | ||
| 121 | { | ||
| 122 | return !(debug_log->log_start - debug_log->log_end); | ||
| 123 | } | ||
| 124 | |||
| 125 | static ssize_t batadv_log_read(struct file *file, char __user *buf, | ||
| 126 | size_t count, loff_t *ppos) | ||
| 127 | { | ||
| 128 | struct batadv_priv *bat_priv = file->private_data; | ||
| 129 | struct batadv_priv_debug_log *debug_log = bat_priv->debug_log; | ||
| 130 | int error, i = 0; | ||
| 131 | char *char_addr; | ||
| 132 | char c; | ||
| 133 | |||
| 134 | if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log)) | ||
| 135 | return -EAGAIN; | ||
| 136 | |||
| 137 | if (!buf) | ||
| 138 | return -EINVAL; | ||
| 139 | |||
| 140 | if (count == 0) | ||
| 141 | return 0; | ||
| 142 | |||
| 143 | if (!access_ok(VERIFY_WRITE, buf, count)) | ||
| 144 | return -EFAULT; | ||
| 145 | |||
| 146 | error = wait_event_interruptible(debug_log->queue_wait, | ||
| 147 | (!batadv_log_empty(debug_log))); | ||
| 148 | |||
| 149 | if (error) | ||
| 150 | return error; | ||
| 151 | |||
| 152 | spin_lock_bh(&debug_log->lock); | ||
| 153 | |||
| 154 | while ((!error) && (i < count) && | ||
| 155 | (debug_log->log_start != debug_log->log_end)) { | ||
| 156 | char_addr = batadv_log_char_addr(debug_log, | ||
| 157 | debug_log->log_start); | ||
| 158 | c = *char_addr; | ||
| 159 | |||
| 160 | debug_log->log_start++; | ||
| 161 | |||
| 162 | spin_unlock_bh(&debug_log->lock); | ||
| 163 | |||
| 164 | error = __put_user(c, buf); | ||
| 165 | |||
| 166 | spin_lock_bh(&debug_log->lock); | ||
| 167 | |||
| 168 | buf++; | ||
| 169 | i++; | ||
| 170 | } | ||
| 171 | |||
| 172 | spin_unlock_bh(&debug_log->lock); | ||
| 173 | |||
| 174 | if (!error) | ||
| 175 | return i; | ||
| 176 | |||
| 177 | return error; | ||
| 178 | } | ||
| 179 | |||
| 180 | static unsigned int batadv_log_poll(struct file *file, poll_table *wait) | ||
| 181 | { | ||
| 182 | struct batadv_priv *bat_priv = file->private_data; | ||
| 183 | struct batadv_priv_debug_log *debug_log = bat_priv->debug_log; | ||
| 184 | |||
| 185 | poll_wait(file, &debug_log->queue_wait, wait); | ||
| 186 | |||
| 187 | if (!batadv_log_empty(debug_log)) | ||
| 188 | return POLLIN | POLLRDNORM; | ||
| 189 | |||
| 190 | return 0; | ||
| 191 | } | ||
| 192 | |||
| 193 | static const struct file_operations batadv_log_fops = { | ||
| 194 | .open = batadv_log_open, | ||
| 195 | .release = batadv_log_release, | ||
| 196 | .read = batadv_log_read, | ||
| 197 | .poll = batadv_log_poll, | ||
| 198 | .llseek = no_llseek, | ||
| 199 | }; | ||
| 200 | |||
| 201 | int batadv_debug_log_setup(struct batadv_priv *bat_priv) | ||
| 202 | { | ||
| 203 | struct dentry *d; | ||
| 204 | |||
| 205 | if (!bat_priv->debug_dir) | ||
| 206 | goto err; | ||
| 207 | |||
| 208 | bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC); | ||
| 209 | if (!bat_priv->debug_log) | ||
| 210 | goto err; | ||
| 211 | |||
| 212 | spin_lock_init(&bat_priv->debug_log->lock); | ||
| 213 | init_waitqueue_head(&bat_priv->debug_log->queue_wait); | ||
| 214 | |||
| 215 | d = debugfs_create_file("log", S_IFREG | S_IRUSR, | ||
| 216 | bat_priv->debug_dir, bat_priv, | ||
| 217 | &batadv_log_fops); | ||
| 218 | if (!d) | ||
| 219 | goto err; | ||
| 220 | |||
| 221 | return 0; | ||
| 222 | |||
| 223 | err: | ||
| 224 | return -ENOMEM; | ||
| 225 | } | ||
| 226 | |||
| 227 | void batadv_debug_log_cleanup(struct batadv_priv *bat_priv) | ||
| 228 | { | ||
| 229 | kfree(bat_priv->debug_log); | ||
| 230 | bat_priv->debug_log = NULL; | ||
| 231 | } | ||
diff --git a/net/batman-adv/log.h b/net/batman-adv/log.h new file mode 100644 index 000000000000..e0e1a88c3e58 --- /dev/null +++ b/net/batman-adv/log.h | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | /* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Marek Lindner, Simon Wunderlich | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef _NET_BATMAN_ADV_LOG_H_ | ||
| 19 | #define _NET_BATMAN_ADV_LOG_H_ | ||
| 20 | |||
| 21 | #include "main.h" | ||
| 22 | |||
| 23 | #include <linux/bitops.h> | ||
| 24 | #include <linux/compiler.h> | ||
| 25 | #include <linux/printk.h> | ||
| 26 | |||
| 27 | #ifdef CONFIG_BATMAN_ADV_DEBUG | ||
| 28 | |||
| 29 | int batadv_debug_log_setup(struct batadv_priv *bat_priv); | ||
| 30 | void batadv_debug_log_cleanup(struct batadv_priv *bat_priv); | ||
| 31 | |||
| 32 | #else | ||
| 33 | |||
| 34 | static inline int batadv_debug_log_setup(struct batadv_priv *bat_priv) | ||
| 35 | { | ||
| 36 | return 0; | ||
| 37 | } | ||
| 38 | |||
| 39 | static inline void batadv_debug_log_cleanup(struct batadv_priv *bat_priv) | ||
| 40 | { | ||
| 41 | } | ||
| 42 | |||
| 43 | #endif | ||
| 44 | |||
| 45 | /** | ||
| 46 | * enum batadv_dbg_level - available log levels | ||
| 47 | * @BATADV_DBG_BATMAN: OGM and TQ computations related messages | ||
| 48 | * @BATADV_DBG_ROUTES: route added / changed / deleted | ||
| 49 | * @BATADV_DBG_TT: translation table messages | ||
| 50 | * @BATADV_DBG_BLA: bridge loop avoidance messages | ||
| 51 | * @BATADV_DBG_DAT: ARP snooping and DAT related messages | ||
| 52 | * @BATADV_DBG_NC: network coding related messages | ||
| 53 | * @BATADV_DBG_MCAST: multicast related messages | ||
| 54 | * @BATADV_DBG_TP_METER: throughput meter messages | ||
| 55 | * @BATADV_DBG_ALL: the union of all the above log levels | ||
| 56 | */ | ||
| 57 | enum batadv_dbg_level { | ||
| 58 | BATADV_DBG_BATMAN = BIT(0), | ||
| 59 | BATADV_DBG_ROUTES = BIT(1), | ||
| 60 | BATADV_DBG_TT = BIT(2), | ||
| 61 | BATADV_DBG_BLA = BIT(3), | ||
| 62 | BATADV_DBG_DAT = BIT(4), | ||
| 63 | BATADV_DBG_NC = BIT(5), | ||
| 64 | BATADV_DBG_MCAST = BIT(6), | ||
| 65 | BATADV_DBG_TP_METER = BIT(7), | ||
| 66 | BATADV_DBG_ALL = 127, | ||
| 67 | }; | ||
| 68 | |||
| 69 | #ifdef CONFIG_BATMAN_ADV_DEBUG | ||
| 70 | int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...) | ||
| 71 | __printf(2, 3); | ||
| 72 | |||
| 73 | /* possibly ratelimited debug output */ | ||
| 74 | #define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \ | ||
| 75 | do { \ | ||
| 76 | if (atomic_read(&bat_priv->log_level) & type && \ | ||
| 77 | (!ratelimited || net_ratelimit())) \ | ||
| 78 | batadv_debug_log(bat_priv, fmt, ## arg);\ | ||
| 79 | } \ | ||
| 80 | while (0) | ||
| 81 | #else /* !CONFIG_BATMAN_ADV_DEBUG */ | ||
| 82 | __printf(4, 5) | ||
| 83 | static inline void _batadv_dbg(int type __always_unused, | ||
| 84 | struct batadv_priv *bat_priv __always_unused, | ||
| 85 | int ratelimited __always_unused, | ||
| 86 | const char *fmt __always_unused, ...) | ||
| 87 | { | ||
| 88 | } | ||
| 89 | #endif | ||
| 90 | |||
| 91 | #define batadv_dbg(type, bat_priv, arg...) \ | ||
| 92 | _batadv_dbg(type, bat_priv, 0, ## arg) | ||
| 93 | #define batadv_dbg_ratelimited(type, bat_priv, arg...) \ | ||
| 94 | _batadv_dbg(type, bat_priv, 1, ## arg) | ||
| 95 | |||
| 96 | #define batadv_info(net_dev, fmt, arg...) \ | ||
| 97 | do { \ | ||
| 98 | struct net_device *_netdev = (net_dev); \ | ||
| 99 | struct batadv_priv *_batpriv = netdev_priv(_netdev); \ | ||
| 100 | batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \ | ||
| 101 | pr_info("%s: " fmt, _netdev->name, ## arg); \ | ||
| 102 | } while (0) | ||
| 103 | #define batadv_err(net_dev, fmt, arg...) \ | ||
| 104 | do { \ | ||
| 105 | struct net_device *_netdev = (net_dev); \ | ||
| 106 | struct batadv_priv *_batpriv = netdev_priv(_netdev); \ | ||
| 107 | batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \ | ||
| 108 | pr_err("%s: " fmt, _netdev->name, ## arg); \ | ||
| 109 | } while (0) | ||
| 110 | |||
| 111 | #endif /* _NET_BATMAN_ADV_LOG_H_ */ | ||
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index 627d14ececaf..fe4c5e29f96b 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c | |||
| @@ -31,16 +31,13 @@ | |||
| 31 | #include <linux/kernel.h> | 31 | #include <linux/kernel.h> |
| 32 | #include <linux/kref.h> | 32 | #include <linux/kref.h> |
| 33 | #include <linux/list.h> | 33 | #include <linux/list.h> |
| 34 | #include <linux/lockdep.h> | ||
| 35 | #include <linux/module.h> | 34 | #include <linux/module.h> |
| 36 | #include <linux/moduleparam.h> | ||
| 37 | #include <linux/netdevice.h> | 35 | #include <linux/netdevice.h> |
| 38 | #include <linux/pkt_sched.h> | 36 | #include <linux/printk.h> |
| 39 | #include <linux/rculist.h> | 37 | #include <linux/rculist.h> |
| 40 | #include <linux/rcupdate.h> | 38 | #include <linux/rcupdate.h> |
| 41 | #include <linux/seq_file.h> | 39 | #include <linux/seq_file.h> |
| 42 | #include <linux/skbuff.h> | 40 | #include <linux/skbuff.h> |
| 43 | #include <linux/slab.h> | ||
| 44 | #include <linux/spinlock.h> | 41 | #include <linux/spinlock.h> |
| 45 | #include <linux/stddef.h> | 42 | #include <linux/stddef.h> |
| 46 | #include <linux/string.h> | 43 | #include <linux/string.h> |
| @@ -49,6 +46,8 @@ | |||
| 49 | #include <net/rtnetlink.h> | 46 | #include <net/rtnetlink.h> |
| 50 | 47 | ||
| 51 | #include "bat_algo.h" | 48 | #include "bat_algo.h" |
| 49 | #include "bat_iv_ogm.h" | ||
| 50 | #include "bat_v.h" | ||
| 52 | #include "bridge_loop_avoidance.h" | 51 | #include "bridge_loop_avoidance.h" |
| 53 | #include "debugfs.h" | 52 | #include "debugfs.h" |
| 54 | #include "distributed-arp-table.h" | 53 | #include "distributed-arp-table.h" |
| @@ -56,13 +55,16 @@ | |||
| 56 | #include "gateway_common.h" | 55 | #include "gateway_common.h" |
| 57 | #include "hard-interface.h" | 56 | #include "hard-interface.h" |
| 58 | #include "icmp_socket.h" | 57 | #include "icmp_socket.h" |
| 58 | #include "log.h" | ||
| 59 | #include "multicast.h" | 59 | #include "multicast.h" |
| 60 | #include "netlink.h" | ||
| 60 | #include "network-coding.h" | 61 | #include "network-coding.h" |
| 61 | #include "originator.h" | 62 | #include "originator.h" |
| 62 | #include "packet.h" | 63 | #include "packet.h" |
| 63 | #include "routing.h" | 64 | #include "routing.h" |
| 64 | #include "send.h" | 65 | #include "send.h" |
| 65 | #include "soft-interface.h" | 66 | #include "soft-interface.h" |
| 67 | #include "tp_meter.h" | ||
| 66 | #include "translation-table.h" | 68 | #include "translation-table.h" |
| 67 | 69 | ||
| 68 | /* List manipulations on hardif_list have to be rtnl_lock()'ed, | 70 | /* List manipulations on hardif_list have to be rtnl_lock()'ed, |
| @@ -71,8 +73,6 @@ | |||
| 71 | struct list_head batadv_hardif_list; | 73 | struct list_head batadv_hardif_list; |
| 72 | static int (*batadv_rx_handler[256])(struct sk_buff *, | 74 | static int (*batadv_rx_handler[256])(struct sk_buff *, |
| 73 | struct batadv_hard_iface *); | 75 | struct batadv_hard_iface *); |
| 74 | char batadv_routing_algo[20] = "BATMAN_IV"; | ||
| 75 | static struct hlist_head batadv_algo_list; | ||
| 76 | 76 | ||
| 77 | unsigned char batadv_broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | 77 | unsigned char batadv_broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 78 | 78 | ||
| @@ -83,13 +83,14 @@ static void batadv_recv_handler_init(void); | |||
| 83 | static int __init batadv_init(void) | 83 | static int __init batadv_init(void) |
| 84 | { | 84 | { |
| 85 | INIT_LIST_HEAD(&batadv_hardif_list); | 85 | INIT_LIST_HEAD(&batadv_hardif_list); |
| 86 | INIT_HLIST_HEAD(&batadv_algo_list); | 86 | batadv_algo_init(); |
| 87 | 87 | ||
| 88 | batadv_recv_handler_init(); | 88 | batadv_recv_handler_init(); |
| 89 | 89 | ||
| 90 | batadv_v_init(); | 90 | batadv_v_init(); |
| 91 | batadv_iv_init(); | 91 | batadv_iv_init(); |
| 92 | batadv_nc_init(); | 92 | batadv_nc_init(); |
| 93 | batadv_tp_meter_init(); | ||
| 93 | 94 | ||
| 94 | batadv_event_workqueue = create_singlethread_workqueue("bat_events"); | 95 | batadv_event_workqueue = create_singlethread_workqueue("bat_events"); |
| 95 | 96 | ||
| @@ -101,6 +102,7 @@ static int __init batadv_init(void) | |||
| 101 | 102 | ||
| 102 | register_netdevice_notifier(&batadv_hard_if_notifier); | 103 | register_netdevice_notifier(&batadv_hard_if_notifier); |
| 103 | rtnl_link_register(&batadv_link_ops); | 104 | rtnl_link_register(&batadv_link_ops); |
| 105 | batadv_netlink_register(); | ||
| 104 | 106 | ||
| 105 | pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n", | 107 | pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n", |
| 106 | BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION); | 108 | BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION); |
| @@ -111,6 +113,7 @@ static int __init batadv_init(void) | |||
| 111 | static void __exit batadv_exit(void) | 113 | static void __exit batadv_exit(void) |
| 112 | { | 114 | { |
| 113 | batadv_debugfs_destroy(); | 115 | batadv_debugfs_destroy(); |
| 116 | batadv_netlink_unregister(); | ||
| 114 | rtnl_link_unregister(&batadv_link_ops); | 117 | rtnl_link_unregister(&batadv_link_ops); |
| 115 | unregister_netdevice_notifier(&batadv_hard_if_notifier); | 118 | unregister_netdevice_notifier(&batadv_hard_if_notifier); |
| 116 | batadv_hardif_remove_interfaces(); | 119 | batadv_hardif_remove_interfaces(); |
| @@ -141,6 +144,7 @@ int batadv_mesh_init(struct net_device *soft_iface) | |||
| 141 | spin_lock_init(&bat_priv->tvlv.container_list_lock); | 144 | spin_lock_init(&bat_priv->tvlv.container_list_lock); |
| 142 | spin_lock_init(&bat_priv->tvlv.handler_list_lock); | 145 | spin_lock_init(&bat_priv->tvlv.handler_list_lock); |
| 143 | spin_lock_init(&bat_priv->softif_vlan_list_lock); | 146 | spin_lock_init(&bat_priv->softif_vlan_list_lock); |
| 147 | spin_lock_init(&bat_priv->tp_list_lock); | ||
| 144 | 148 | ||
| 145 | INIT_HLIST_HEAD(&bat_priv->forw_bat_list); | 149 | INIT_HLIST_HEAD(&bat_priv->forw_bat_list); |
| 146 | INIT_HLIST_HEAD(&bat_priv->forw_bcast_list); | 150 | INIT_HLIST_HEAD(&bat_priv->forw_bcast_list); |
| @@ -159,6 +163,7 @@ int batadv_mesh_init(struct net_device *soft_iface) | |||
| 159 | INIT_HLIST_HEAD(&bat_priv->tvlv.container_list); | 163 | INIT_HLIST_HEAD(&bat_priv->tvlv.container_list); |
| 160 | INIT_HLIST_HEAD(&bat_priv->tvlv.handler_list); | 164 | INIT_HLIST_HEAD(&bat_priv->tvlv.handler_list); |
| 161 | INIT_HLIST_HEAD(&bat_priv->softif_vlan_list); | 165 | INIT_HLIST_HEAD(&bat_priv->softif_vlan_list); |
| 166 | INIT_HLIST_HEAD(&bat_priv->tp_list); | ||
| 162 | 167 | ||
| 163 | ret = batadv_v_mesh_init(bat_priv); | 168 | ret = batadv_v_mesh_init(bat_priv); |
| 164 | if (ret < 0) | 169 | if (ret < 0) |
| @@ -538,76 +543,6 @@ void batadv_recv_handler_unregister(u8 packet_type) | |||
| 538 | batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet; | 543 | batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet; |
| 539 | } | 544 | } |
| 540 | 545 | ||
| 541 | static struct batadv_algo_ops *batadv_algo_get(char *name) | ||
| 542 | { | ||
| 543 | struct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp; | ||
| 544 | |||
| 545 | hlist_for_each_entry(bat_algo_ops_tmp, &batadv_algo_list, list) { | ||
| 546 | if (strcmp(bat_algo_ops_tmp->name, name) != 0) | ||
| 547 | continue; | ||
| 548 | |||
| 549 | bat_algo_ops = bat_algo_ops_tmp; | ||
| 550 | break; | ||
| 551 | } | ||
| 552 | |||
| 553 | return bat_algo_ops; | ||
| 554 | } | ||
| 555 | |||
| 556 | int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops) | ||
| 557 | { | ||
| 558 | struct batadv_algo_ops *bat_algo_ops_tmp; | ||
| 559 | |||
| 560 | bat_algo_ops_tmp = batadv_algo_get(bat_algo_ops->name); | ||
| 561 | if (bat_algo_ops_tmp) { | ||
| 562 | pr_info("Trying to register already registered routing algorithm: %s\n", | ||
| 563 | bat_algo_ops->name); | ||
| 564 | return -EEXIST; | ||
| 565 | } | ||
| 566 | |||
| 567 | /* all algorithms must implement all ops (for now) */ | ||
| 568 | if (!bat_algo_ops->bat_iface_enable || | ||
| 569 | !bat_algo_ops->bat_iface_disable || | ||
| 570 | !bat_algo_ops->bat_iface_update_mac || | ||
| 571 | !bat_algo_ops->bat_primary_iface_set || | ||
| 572 | !bat_algo_ops->bat_neigh_cmp || | ||
| 573 | !bat_algo_ops->bat_neigh_is_similar_or_better) { | ||
| 574 | pr_info("Routing algo '%s' does not implement required ops\n", | ||
| 575 | bat_algo_ops->name); | ||
| 576 | return -EINVAL; | ||
| 577 | } | ||
| 578 | |||
| 579 | INIT_HLIST_NODE(&bat_algo_ops->list); | ||
| 580 | hlist_add_head(&bat_algo_ops->list, &batadv_algo_list); | ||
| 581 | |||
| 582 | return 0; | ||
| 583 | } | ||
| 584 | |||
| 585 | int batadv_algo_select(struct batadv_priv *bat_priv, char *name) | ||
| 586 | { | ||
| 587 | struct batadv_algo_ops *bat_algo_ops; | ||
| 588 | |||
| 589 | bat_algo_ops = batadv_algo_get(name); | ||
| 590 | if (!bat_algo_ops) | ||
| 591 | return -EINVAL; | ||
| 592 | |||
| 593 | bat_priv->bat_algo_ops = bat_algo_ops; | ||
| 594 | |||
| 595 | return 0; | ||
| 596 | } | ||
| 597 | |||
| 598 | int batadv_algo_seq_print_text(struct seq_file *seq, void *offset) | ||
| 599 | { | ||
| 600 | struct batadv_algo_ops *bat_algo_ops; | ||
| 601 | |||
| 602 | seq_puts(seq, "Available routing algorithms:\n"); | ||
| 603 | |||
| 604 | hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) { | ||
| 605 | seq_printf(seq, " * %s\n", bat_algo_ops->name); | ||
| 606 | } | ||
| 607 | |||
| 608 | return 0; | ||
| 609 | } | ||
| 610 | |||
| 611 | /** | 546 | /** |
| 612 | * batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in | 547 | * batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in |
| 613 | * the header | 548 | * the header |
| @@ -642,594 +577,6 @@ __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr) | |||
| 642 | } | 577 | } |
| 643 | 578 | ||
| 644 | /** | 579 | /** |
| 645 | * batadv_tvlv_handler_release - release tvlv handler from lists and queue for | ||
| 646 | * free after rcu grace period | ||
| 647 | * @ref: kref pointer of the tvlv | ||
| 648 | */ | ||
| 649 | static void batadv_tvlv_handler_release(struct kref *ref) | ||
| 650 | { | ||
| 651 | struct batadv_tvlv_handler *tvlv_handler; | ||
| 652 | |||
| 653 | tvlv_handler = container_of(ref, struct batadv_tvlv_handler, refcount); | ||
| 654 | kfree_rcu(tvlv_handler, rcu); | ||
| 655 | } | ||
| 656 | |||
| 657 | /** | ||
| 658 | * batadv_tvlv_handler_put - decrement the tvlv container refcounter and | ||
| 659 | * possibly release it | ||
| 660 | * @tvlv_handler: the tvlv handler to free | ||
| 661 | */ | ||
| 662 | static void batadv_tvlv_handler_put(struct batadv_tvlv_handler *tvlv_handler) | ||
| 663 | { | ||
| 664 | kref_put(&tvlv_handler->refcount, batadv_tvlv_handler_release); | ||
| 665 | } | ||
| 666 | |||
| 667 | /** | ||
| 668 | * batadv_tvlv_handler_get - retrieve tvlv handler from the tvlv handler list | ||
| 669 | * based on the provided type and version (both need to match) | ||
| 670 | * @bat_priv: the bat priv with all the soft interface information | ||
| 671 | * @type: tvlv handler type to look for | ||
| 672 | * @version: tvlv handler version to look for | ||
| 673 | * | ||
| 674 | * Return: tvlv handler if found or NULL otherwise. | ||
| 675 | */ | ||
| 676 | static struct batadv_tvlv_handler * | ||
| 677 | batadv_tvlv_handler_get(struct batadv_priv *bat_priv, u8 type, u8 version) | ||
| 678 | { | ||
| 679 | struct batadv_tvlv_handler *tvlv_handler_tmp, *tvlv_handler = NULL; | ||
| 680 | |||
| 681 | rcu_read_lock(); | ||
| 682 | hlist_for_each_entry_rcu(tvlv_handler_tmp, | ||
| 683 | &bat_priv->tvlv.handler_list, list) { | ||
| 684 | if (tvlv_handler_tmp->type != type) | ||
| 685 | continue; | ||
| 686 | |||
| 687 | if (tvlv_handler_tmp->version != version) | ||
| 688 | continue; | ||
| 689 | |||
| 690 | if (!kref_get_unless_zero(&tvlv_handler_tmp->refcount)) | ||
| 691 | continue; | ||
| 692 | |||
| 693 | tvlv_handler = tvlv_handler_tmp; | ||
| 694 | break; | ||
| 695 | } | ||
| 696 | rcu_read_unlock(); | ||
| 697 | |||
| 698 | return tvlv_handler; | ||
| 699 | } | ||
| 700 | |||
| 701 | /** | ||
| 702 | * batadv_tvlv_container_release - release tvlv from lists and free | ||
| 703 | * @ref: kref pointer of the tvlv | ||
| 704 | */ | ||
| 705 | static void batadv_tvlv_container_release(struct kref *ref) | ||
| 706 | { | ||
| 707 | struct batadv_tvlv_container *tvlv; | ||
| 708 | |||
| 709 | tvlv = container_of(ref, struct batadv_tvlv_container, refcount); | ||
| 710 | kfree(tvlv); | ||
| 711 | } | ||
| 712 | |||
| 713 | /** | ||
| 714 | * batadv_tvlv_container_put - decrement the tvlv container refcounter and | ||
| 715 | * possibly release it | ||
| 716 | * @tvlv: the tvlv container to free | ||
| 717 | */ | ||
| 718 | static void batadv_tvlv_container_put(struct batadv_tvlv_container *tvlv) | ||
| 719 | { | ||
| 720 | kref_put(&tvlv->refcount, batadv_tvlv_container_release); | ||
| 721 | } | ||
| 722 | |||
| 723 | /** | ||
| 724 | * batadv_tvlv_container_get - retrieve tvlv container from the tvlv container | ||
| 725 | * list based on the provided type and version (both need to match) | ||
| 726 | * @bat_priv: the bat priv with all the soft interface information | ||
| 727 | * @type: tvlv container type to look for | ||
| 728 | * @version: tvlv container version to look for | ||
| 729 | * | ||
| 730 | * Has to be called with the appropriate locks being acquired | ||
| 731 | * (tvlv.container_list_lock). | ||
| 732 | * | ||
| 733 | * Return: tvlv container if found or NULL otherwise. | ||
| 734 | */ | ||
| 735 | static struct batadv_tvlv_container * | ||
| 736 | batadv_tvlv_container_get(struct batadv_priv *bat_priv, u8 type, u8 version) | ||
| 737 | { | ||
| 738 | struct batadv_tvlv_container *tvlv_tmp, *tvlv = NULL; | ||
| 739 | |||
| 740 | lockdep_assert_held(&bat_priv->tvlv.container_list_lock); | ||
| 741 | |||
| 742 | hlist_for_each_entry(tvlv_tmp, &bat_priv->tvlv.container_list, list) { | ||
| 743 | if (tvlv_tmp->tvlv_hdr.type != type) | ||
| 744 | continue; | ||
| 745 | |||
| 746 | if (tvlv_tmp->tvlv_hdr.version != version) | ||
| 747 | continue; | ||
| 748 | |||
| 749 | kref_get(&tvlv_tmp->refcount); | ||
| 750 | tvlv = tvlv_tmp; | ||
| 751 | break; | ||
| 752 | } | ||
| 753 | |||
| 754 | return tvlv; | ||
| 755 | } | ||
| 756 | |||
| 757 | /** | ||
| 758 | * batadv_tvlv_container_list_size - calculate the size of the tvlv container | ||
| 759 | * list entries | ||
| 760 | * @bat_priv: the bat priv with all the soft interface information | ||
| 761 | * | ||
| 762 | * Has to be called with the appropriate locks being acquired | ||
| 763 | * (tvlv.container_list_lock). | ||
| 764 | * | ||
| 765 | * Return: size of all currently registered tvlv containers in bytes. | ||
| 766 | */ | ||
| 767 | static u16 batadv_tvlv_container_list_size(struct batadv_priv *bat_priv) | ||
| 768 | { | ||
| 769 | struct batadv_tvlv_container *tvlv; | ||
| 770 | u16 tvlv_len = 0; | ||
| 771 | |||
| 772 | lockdep_assert_held(&bat_priv->tvlv.container_list_lock); | ||
| 773 | |||
| 774 | hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) { | ||
| 775 | tvlv_len += sizeof(struct batadv_tvlv_hdr); | ||
| 776 | tvlv_len += ntohs(tvlv->tvlv_hdr.len); | ||
| 777 | } | ||
| 778 | |||
| 779 | return tvlv_len; | ||
| 780 | } | ||
| 781 | |||
| 782 | /** | ||
| 783 | * batadv_tvlv_container_remove - remove tvlv container from the tvlv container | ||
| 784 | * list | ||
| 785 | * @bat_priv: the bat priv with all the soft interface information | ||
| 786 | * @tvlv: the to be removed tvlv container | ||
| 787 | * | ||
| 788 | * Has to be called with the appropriate locks being acquired | ||
| 789 | * (tvlv.container_list_lock). | ||
| 790 | */ | ||
| 791 | static void batadv_tvlv_container_remove(struct batadv_priv *bat_priv, | ||
| 792 | struct batadv_tvlv_container *tvlv) | ||
| 793 | { | ||
| 794 | lockdep_assert_held(&bat_priv->tvlv.container_list_lock); | ||
| 795 | |||
| 796 | if (!tvlv) | ||
| 797 | return; | ||
| 798 | |||
| 799 | hlist_del(&tvlv->list); | ||
| 800 | |||
| 801 | /* first call to decrement the counter, second call to free */ | ||
| 802 | batadv_tvlv_container_put(tvlv); | ||
| 803 | batadv_tvlv_container_put(tvlv); | ||
| 804 | } | ||
| 805 | |||
| 806 | /** | ||
| 807 | * batadv_tvlv_container_unregister - unregister tvlv container based on the | ||
| 808 | * provided type and version (both need to match) | ||
| 809 | * @bat_priv: the bat priv with all the soft interface information | ||
| 810 | * @type: tvlv container type to unregister | ||
| 811 | * @version: tvlv container type to unregister | ||
| 812 | */ | ||
| 813 | void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv, | ||
| 814 | u8 type, u8 version) | ||
| 815 | { | ||
| 816 | struct batadv_tvlv_container *tvlv; | ||
| 817 | |||
| 818 | spin_lock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 819 | tvlv = batadv_tvlv_container_get(bat_priv, type, version); | ||
| 820 | batadv_tvlv_container_remove(bat_priv, tvlv); | ||
| 821 | spin_unlock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 822 | } | ||
| 823 | |||
| 824 | /** | ||
| 825 | * batadv_tvlv_container_register - register tvlv type, version and content | ||
| 826 | * to be propagated with each (primary interface) OGM | ||
| 827 | * @bat_priv: the bat priv with all the soft interface information | ||
| 828 | * @type: tvlv container type | ||
| 829 | * @version: tvlv container version | ||
| 830 | * @tvlv_value: tvlv container content | ||
| 831 | * @tvlv_value_len: tvlv container content length | ||
| 832 | * | ||
| 833 | * If a container of the same type and version was already registered the new | ||
| 834 | * content is going to replace the old one. | ||
| 835 | */ | ||
| 836 | void batadv_tvlv_container_register(struct batadv_priv *bat_priv, | ||
| 837 | u8 type, u8 version, | ||
| 838 | void *tvlv_value, u16 tvlv_value_len) | ||
| 839 | { | ||
| 840 | struct batadv_tvlv_container *tvlv_old, *tvlv_new; | ||
| 841 | |||
| 842 | if (!tvlv_value) | ||
| 843 | tvlv_value_len = 0; | ||
| 844 | |||
| 845 | tvlv_new = kzalloc(sizeof(*tvlv_new) + tvlv_value_len, GFP_ATOMIC); | ||
| 846 | if (!tvlv_new) | ||
| 847 | return; | ||
| 848 | |||
| 849 | tvlv_new->tvlv_hdr.version = version; | ||
| 850 | tvlv_new->tvlv_hdr.type = type; | ||
| 851 | tvlv_new->tvlv_hdr.len = htons(tvlv_value_len); | ||
| 852 | |||
| 853 | memcpy(tvlv_new + 1, tvlv_value, ntohs(tvlv_new->tvlv_hdr.len)); | ||
| 854 | INIT_HLIST_NODE(&tvlv_new->list); | ||
| 855 | kref_init(&tvlv_new->refcount); | ||
| 856 | |||
| 857 | spin_lock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 858 | tvlv_old = batadv_tvlv_container_get(bat_priv, type, version); | ||
| 859 | batadv_tvlv_container_remove(bat_priv, tvlv_old); | ||
| 860 | hlist_add_head(&tvlv_new->list, &bat_priv->tvlv.container_list); | ||
| 861 | spin_unlock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 862 | } | ||
| 863 | |||
| 864 | /** | ||
| 865 | * batadv_tvlv_realloc_packet_buff - reallocate packet buffer to accommodate | ||
| 866 | * requested packet size | ||
| 867 | * @packet_buff: packet buffer | ||
| 868 | * @packet_buff_len: packet buffer size | ||
| 869 | * @min_packet_len: requested packet minimum size | ||
| 870 | * @additional_packet_len: requested additional packet size on top of minimum | ||
| 871 | * size | ||
| 872 | * | ||
| 873 | * Return: true of the packet buffer could be changed to the requested size, | ||
| 874 | * false otherwise. | ||
| 875 | */ | ||
| 876 | static bool batadv_tvlv_realloc_packet_buff(unsigned char **packet_buff, | ||
| 877 | int *packet_buff_len, | ||
| 878 | int min_packet_len, | ||
| 879 | int additional_packet_len) | ||
| 880 | { | ||
| 881 | unsigned char *new_buff; | ||
| 882 | |||
| 883 | new_buff = kmalloc(min_packet_len + additional_packet_len, GFP_ATOMIC); | ||
| 884 | |||
| 885 | /* keep old buffer if kmalloc should fail */ | ||
| 886 | if (!new_buff) | ||
| 887 | return false; | ||
| 888 | |||
| 889 | memcpy(new_buff, *packet_buff, min_packet_len); | ||
| 890 | kfree(*packet_buff); | ||
| 891 | *packet_buff = new_buff; | ||
| 892 | *packet_buff_len = min_packet_len + additional_packet_len; | ||
| 893 | |||
| 894 | return true; | ||
| 895 | } | ||
| 896 | |||
| 897 | /** | ||
| 898 | * batadv_tvlv_container_ogm_append - append tvlv container content to given | ||
| 899 | * OGM packet buffer | ||
| 900 | * @bat_priv: the bat priv with all the soft interface information | ||
| 901 | * @packet_buff: ogm packet buffer | ||
| 902 | * @packet_buff_len: ogm packet buffer size including ogm header and tvlv | ||
| 903 | * content | ||
| 904 | * @packet_min_len: ogm header size to be preserved for the OGM itself | ||
| 905 | * | ||
| 906 | * The ogm packet might be enlarged or shrunk depending on the current size | ||
| 907 | * and the size of the to-be-appended tvlv containers. | ||
| 908 | * | ||
| 909 | * Return: size of all appended tvlv containers in bytes. | ||
| 910 | */ | ||
| 911 | u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv, | ||
| 912 | unsigned char **packet_buff, | ||
| 913 | int *packet_buff_len, int packet_min_len) | ||
| 914 | { | ||
| 915 | struct batadv_tvlv_container *tvlv; | ||
| 916 | struct batadv_tvlv_hdr *tvlv_hdr; | ||
| 917 | u16 tvlv_value_len; | ||
| 918 | void *tvlv_value; | ||
| 919 | bool ret; | ||
| 920 | |||
| 921 | spin_lock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 922 | tvlv_value_len = batadv_tvlv_container_list_size(bat_priv); | ||
| 923 | |||
| 924 | ret = batadv_tvlv_realloc_packet_buff(packet_buff, packet_buff_len, | ||
| 925 | packet_min_len, tvlv_value_len); | ||
| 926 | |||
| 927 | if (!ret) | ||
| 928 | goto end; | ||
| 929 | |||
| 930 | if (!tvlv_value_len) | ||
| 931 | goto end; | ||
| 932 | |||
| 933 | tvlv_value = (*packet_buff) + packet_min_len; | ||
| 934 | |||
| 935 | hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) { | ||
| 936 | tvlv_hdr = tvlv_value; | ||
| 937 | tvlv_hdr->type = tvlv->tvlv_hdr.type; | ||
| 938 | tvlv_hdr->version = tvlv->tvlv_hdr.version; | ||
| 939 | tvlv_hdr->len = tvlv->tvlv_hdr.len; | ||
| 940 | tvlv_value = tvlv_hdr + 1; | ||
| 941 | memcpy(tvlv_value, tvlv + 1, ntohs(tvlv->tvlv_hdr.len)); | ||
| 942 | tvlv_value = (u8 *)tvlv_value + ntohs(tvlv->tvlv_hdr.len); | ||
| 943 | } | ||
| 944 | |||
| 945 | end: | ||
| 946 | spin_unlock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 947 | return tvlv_value_len; | ||
| 948 | } | ||
| 949 | |||
| 950 | /** | ||
| 951 | * batadv_tvlv_call_handler - parse the given tvlv buffer to call the | ||
| 952 | * appropriate handlers | ||
| 953 | * @bat_priv: the bat priv with all the soft interface information | ||
| 954 | * @tvlv_handler: tvlv callback function handling the tvlv content | ||
| 955 | * @ogm_source: flag indicating whether the tvlv is an ogm or a unicast packet | ||
| 956 | * @orig_node: orig node emitting the ogm packet | ||
| 957 | * @src: source mac address of the unicast packet | ||
| 958 | * @dst: destination mac address of the unicast packet | ||
| 959 | * @tvlv_value: tvlv content | ||
| 960 | * @tvlv_value_len: tvlv content length | ||
| 961 | * | ||
| 962 | * Return: success if handler was not found or the return value of the handler | ||
| 963 | * callback. | ||
| 964 | */ | ||
| 965 | static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv, | ||
| 966 | struct batadv_tvlv_handler *tvlv_handler, | ||
| 967 | bool ogm_source, | ||
| 968 | struct batadv_orig_node *orig_node, | ||
| 969 | u8 *src, u8 *dst, | ||
| 970 | void *tvlv_value, u16 tvlv_value_len) | ||
| 971 | { | ||
| 972 | if (!tvlv_handler) | ||
| 973 | return NET_RX_SUCCESS; | ||
| 974 | |||
| 975 | if (ogm_source) { | ||
| 976 | if (!tvlv_handler->ogm_handler) | ||
| 977 | return NET_RX_SUCCESS; | ||
| 978 | |||
| 979 | if (!orig_node) | ||
| 980 | return NET_RX_SUCCESS; | ||
| 981 | |||
| 982 | tvlv_handler->ogm_handler(bat_priv, orig_node, | ||
| 983 | BATADV_NO_FLAGS, | ||
| 984 | tvlv_value, tvlv_value_len); | ||
| 985 | tvlv_handler->flags |= BATADV_TVLV_HANDLER_OGM_CALLED; | ||
| 986 | } else { | ||
| 987 | if (!src) | ||
| 988 | return NET_RX_SUCCESS; | ||
| 989 | |||
| 990 | if (!dst) | ||
| 991 | return NET_RX_SUCCESS; | ||
| 992 | |||
| 993 | if (!tvlv_handler->unicast_handler) | ||
| 994 | return NET_RX_SUCCESS; | ||
| 995 | |||
| 996 | return tvlv_handler->unicast_handler(bat_priv, src, | ||
| 997 | dst, tvlv_value, | ||
| 998 | tvlv_value_len); | ||
| 999 | } | ||
| 1000 | |||
| 1001 | return NET_RX_SUCCESS; | ||
| 1002 | } | ||
| 1003 | |||
| 1004 | /** | ||
| 1005 | * batadv_tvlv_containers_process - parse the given tvlv buffer to call the | ||
| 1006 | * appropriate handlers | ||
| 1007 | * @bat_priv: the bat priv with all the soft interface information | ||
| 1008 | * @ogm_source: flag indicating whether the tvlv is an ogm or a unicast packet | ||
| 1009 | * @orig_node: orig node emitting the ogm packet | ||
| 1010 | * @src: source mac address of the unicast packet | ||
| 1011 | * @dst: destination mac address of the unicast packet | ||
| 1012 | * @tvlv_value: tvlv content | ||
| 1013 | * @tvlv_value_len: tvlv content length | ||
| 1014 | * | ||
| 1015 | * Return: success when processing an OGM or the return value of all called | ||
| 1016 | * handler callbacks. | ||
| 1017 | */ | ||
| 1018 | int batadv_tvlv_containers_process(struct batadv_priv *bat_priv, | ||
| 1019 | bool ogm_source, | ||
| 1020 | struct batadv_orig_node *orig_node, | ||
| 1021 | u8 *src, u8 *dst, | ||
| 1022 | void *tvlv_value, u16 tvlv_value_len) | ||
| 1023 | { | ||
| 1024 | struct batadv_tvlv_handler *tvlv_handler; | ||
| 1025 | struct batadv_tvlv_hdr *tvlv_hdr; | ||
| 1026 | u16 tvlv_value_cont_len; | ||
| 1027 | u8 cifnotfound = BATADV_TVLV_HANDLER_OGM_CIFNOTFND; | ||
| 1028 | int ret = NET_RX_SUCCESS; | ||
| 1029 | |||
| 1030 | while (tvlv_value_len >= sizeof(*tvlv_hdr)) { | ||
| 1031 | tvlv_hdr = tvlv_value; | ||
| 1032 | tvlv_value_cont_len = ntohs(tvlv_hdr->len); | ||
| 1033 | tvlv_value = tvlv_hdr + 1; | ||
| 1034 | tvlv_value_len -= sizeof(*tvlv_hdr); | ||
| 1035 | |||
| 1036 | if (tvlv_value_cont_len > tvlv_value_len) | ||
| 1037 | break; | ||
| 1038 | |||
| 1039 | tvlv_handler = batadv_tvlv_handler_get(bat_priv, | ||
| 1040 | tvlv_hdr->type, | ||
| 1041 | tvlv_hdr->version); | ||
| 1042 | |||
| 1043 | ret |= batadv_tvlv_call_handler(bat_priv, tvlv_handler, | ||
| 1044 | ogm_source, orig_node, | ||
| 1045 | src, dst, tvlv_value, | ||
| 1046 | tvlv_value_cont_len); | ||
| 1047 | if (tvlv_handler) | ||
| 1048 | batadv_tvlv_handler_put(tvlv_handler); | ||
| 1049 | tvlv_value = (u8 *)tvlv_value + tvlv_value_cont_len; | ||
| 1050 | tvlv_value_len -= tvlv_value_cont_len; | ||
| 1051 | } | ||
| 1052 | |||
| 1053 | if (!ogm_source) | ||
| 1054 | return ret; | ||
| 1055 | |||
| 1056 | rcu_read_lock(); | ||
| 1057 | hlist_for_each_entry_rcu(tvlv_handler, | ||
| 1058 | &bat_priv->tvlv.handler_list, list) { | ||
| 1059 | if ((tvlv_handler->flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND) && | ||
| 1060 | !(tvlv_handler->flags & BATADV_TVLV_HANDLER_OGM_CALLED)) | ||
| 1061 | tvlv_handler->ogm_handler(bat_priv, orig_node, | ||
| 1062 | cifnotfound, NULL, 0); | ||
| 1063 | |||
| 1064 | tvlv_handler->flags &= ~BATADV_TVLV_HANDLER_OGM_CALLED; | ||
| 1065 | } | ||
| 1066 | rcu_read_unlock(); | ||
| 1067 | |||
| 1068 | return NET_RX_SUCCESS; | ||
| 1069 | } | ||
| 1070 | |||
| 1071 | /** | ||
| 1072 | * batadv_tvlv_ogm_receive - process an incoming ogm and call the appropriate | ||
| 1073 | * handlers | ||
| 1074 | * @bat_priv: the bat priv with all the soft interface information | ||
| 1075 | * @batadv_ogm_packet: ogm packet containing the tvlv containers | ||
| 1076 | * @orig_node: orig node emitting the ogm packet | ||
| 1077 | */ | ||
| 1078 | void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv, | ||
| 1079 | struct batadv_ogm_packet *batadv_ogm_packet, | ||
| 1080 | struct batadv_orig_node *orig_node) | ||
| 1081 | { | ||
| 1082 | void *tvlv_value; | ||
| 1083 | u16 tvlv_value_len; | ||
| 1084 | |||
| 1085 | if (!batadv_ogm_packet) | ||
| 1086 | return; | ||
| 1087 | |||
| 1088 | tvlv_value_len = ntohs(batadv_ogm_packet->tvlv_len); | ||
| 1089 | if (!tvlv_value_len) | ||
| 1090 | return; | ||
| 1091 | |||
| 1092 | tvlv_value = batadv_ogm_packet + 1; | ||
| 1093 | |||
| 1094 | batadv_tvlv_containers_process(bat_priv, true, orig_node, NULL, NULL, | ||
| 1095 | tvlv_value, tvlv_value_len); | ||
| 1096 | } | ||
| 1097 | |||
| 1098 | /** | ||
| 1099 | * batadv_tvlv_handler_register - register tvlv handler based on the provided | ||
| 1100 | * type and version (both need to match) for ogm tvlv payload and/or unicast | ||
| 1101 | * payload | ||
| 1102 | * @bat_priv: the bat priv with all the soft interface information | ||
| 1103 | * @optr: ogm tvlv handler callback function. This function receives the orig | ||
| 1104 | * node, flags and the tvlv content as argument to process. | ||
| 1105 | * @uptr: unicast tvlv handler callback function. This function receives the | ||
| 1106 | * source & destination of the unicast packet as well as the tvlv content | ||
| 1107 | * to process. | ||
| 1108 | * @type: tvlv handler type to be registered | ||
| 1109 | * @version: tvlv handler version to be registered | ||
| 1110 | * @flags: flags to enable or disable TVLV API behavior | ||
| 1111 | */ | ||
| 1112 | void batadv_tvlv_handler_register(struct batadv_priv *bat_priv, | ||
| 1113 | void (*optr)(struct batadv_priv *bat_priv, | ||
| 1114 | struct batadv_orig_node *orig, | ||
| 1115 | u8 flags, | ||
| 1116 | void *tvlv_value, | ||
| 1117 | u16 tvlv_value_len), | ||
| 1118 | int (*uptr)(struct batadv_priv *bat_priv, | ||
| 1119 | u8 *src, u8 *dst, | ||
| 1120 | void *tvlv_value, | ||
| 1121 | u16 tvlv_value_len), | ||
| 1122 | u8 type, u8 version, u8 flags) | ||
| 1123 | { | ||
| 1124 | struct batadv_tvlv_handler *tvlv_handler; | ||
| 1125 | |||
| 1126 | tvlv_handler = batadv_tvlv_handler_get(bat_priv, type, version); | ||
| 1127 | if (tvlv_handler) { | ||
| 1128 | batadv_tvlv_handler_put(tvlv_handler); | ||
| 1129 | return; | ||
| 1130 | } | ||
| 1131 | |||
| 1132 | tvlv_handler = kzalloc(sizeof(*tvlv_handler), GFP_ATOMIC); | ||
| 1133 | if (!tvlv_handler) | ||
| 1134 | return; | ||
| 1135 | |||
| 1136 | tvlv_handler->ogm_handler = optr; | ||
| 1137 | tvlv_handler->unicast_handler = uptr; | ||
| 1138 | tvlv_handler->type = type; | ||
| 1139 | tvlv_handler->version = version; | ||
| 1140 | tvlv_handler->flags = flags; | ||
| 1141 | kref_init(&tvlv_handler->refcount); | ||
| 1142 | INIT_HLIST_NODE(&tvlv_handler->list); | ||
| 1143 | |||
| 1144 | spin_lock_bh(&bat_priv->tvlv.handler_list_lock); | ||
| 1145 | hlist_add_head_rcu(&tvlv_handler->list, &bat_priv->tvlv.handler_list); | ||
| 1146 | spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); | ||
| 1147 | } | ||
| 1148 | |||
| 1149 | /** | ||
| 1150 | * batadv_tvlv_handler_unregister - unregister tvlv handler based on the | ||
| 1151 | * provided type and version (both need to match) | ||
| 1152 | * @bat_priv: the bat priv with all the soft interface information | ||
| 1153 | * @type: tvlv handler type to be unregistered | ||
| 1154 | * @version: tvlv handler version to be unregistered | ||
| 1155 | */ | ||
| 1156 | void batadv_tvlv_handler_unregister(struct batadv_priv *bat_priv, | ||
| 1157 | u8 type, u8 version) | ||
| 1158 | { | ||
| 1159 | struct batadv_tvlv_handler *tvlv_handler; | ||
| 1160 | |||
| 1161 | tvlv_handler = batadv_tvlv_handler_get(bat_priv, type, version); | ||
| 1162 | if (!tvlv_handler) | ||
| 1163 | return; | ||
| 1164 | |||
| 1165 | batadv_tvlv_handler_put(tvlv_handler); | ||
| 1166 | spin_lock_bh(&bat_priv->tvlv.handler_list_lock); | ||
| 1167 | hlist_del_rcu(&tvlv_handler->list); | ||
| 1168 | spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); | ||
| 1169 | batadv_tvlv_handler_put(tvlv_handler); | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | /** | ||
| 1173 | * batadv_tvlv_unicast_send - send a unicast packet with tvlv payload to the | ||
| 1174 | * specified host | ||
| 1175 | * @bat_priv: the bat priv with all the soft interface information | ||
| 1176 | * @src: source mac address of the unicast packet | ||
| 1177 | * @dst: destination mac address of the unicast packet | ||
| 1178 | * @type: tvlv type | ||
| 1179 | * @version: tvlv version | ||
| 1180 | * @tvlv_value: tvlv content | ||
| 1181 | * @tvlv_value_len: tvlv content length | ||
| 1182 | */ | ||
| 1183 | void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src, | ||
| 1184 | u8 *dst, u8 type, u8 version, | ||
| 1185 | void *tvlv_value, u16 tvlv_value_len) | ||
| 1186 | { | ||
| 1187 | struct batadv_unicast_tvlv_packet *unicast_tvlv_packet; | ||
| 1188 | struct batadv_tvlv_hdr *tvlv_hdr; | ||
| 1189 | struct batadv_orig_node *orig_node; | ||
| 1190 | struct sk_buff *skb; | ||
| 1191 | unsigned char *tvlv_buff; | ||
| 1192 | unsigned int tvlv_len; | ||
| 1193 | ssize_t hdr_len = sizeof(*unicast_tvlv_packet); | ||
| 1194 | |||
| 1195 | orig_node = batadv_orig_hash_find(bat_priv, dst); | ||
| 1196 | if (!orig_node) | ||
| 1197 | return; | ||
| 1198 | |||
| 1199 | tvlv_len = sizeof(*tvlv_hdr) + tvlv_value_len; | ||
| 1200 | |||
| 1201 | skb = netdev_alloc_skb_ip_align(NULL, ETH_HLEN + hdr_len + tvlv_len); | ||
| 1202 | if (!skb) | ||
| 1203 | goto out; | ||
| 1204 | |||
| 1205 | skb->priority = TC_PRIO_CONTROL; | ||
| 1206 | skb_reserve(skb, ETH_HLEN); | ||
| 1207 | tvlv_buff = skb_put(skb, sizeof(*unicast_tvlv_packet) + tvlv_len); | ||
| 1208 | unicast_tvlv_packet = (struct batadv_unicast_tvlv_packet *)tvlv_buff; | ||
| 1209 | unicast_tvlv_packet->packet_type = BATADV_UNICAST_TVLV; | ||
| 1210 | unicast_tvlv_packet->version = BATADV_COMPAT_VERSION; | ||
| 1211 | unicast_tvlv_packet->ttl = BATADV_TTL; | ||
| 1212 | unicast_tvlv_packet->reserved = 0; | ||
| 1213 | unicast_tvlv_packet->tvlv_len = htons(tvlv_len); | ||
| 1214 | unicast_tvlv_packet->align = 0; | ||
| 1215 | ether_addr_copy(unicast_tvlv_packet->src, src); | ||
| 1216 | ether_addr_copy(unicast_tvlv_packet->dst, dst); | ||
| 1217 | |||
| 1218 | tvlv_buff = (unsigned char *)(unicast_tvlv_packet + 1); | ||
| 1219 | tvlv_hdr = (struct batadv_tvlv_hdr *)tvlv_buff; | ||
| 1220 | tvlv_hdr->version = version; | ||
| 1221 | tvlv_hdr->type = type; | ||
| 1222 | tvlv_hdr->len = htons(tvlv_value_len); | ||
| 1223 | tvlv_buff += sizeof(*tvlv_hdr); | ||
| 1224 | memcpy(tvlv_buff, tvlv_value, tvlv_value_len); | ||
| 1225 | |||
| 1226 | if (batadv_send_skb_to_orig(skb, orig_node, NULL) == NET_XMIT_DROP) | ||
| 1227 | kfree_skb(skb); | ||
| 1228 | out: | ||
| 1229 | batadv_orig_node_put(orig_node); | ||
| 1230 | } | ||
| 1231 | |||
| 1232 | /** | ||
| 1233 | * batadv_get_vid - extract the VLAN identifier from skb if any | 580 | * batadv_get_vid - extract the VLAN identifier from skb if any |
| 1234 | * @skb: the buffer containing the packet | 581 | * @skb: the buffer containing the packet |
| 1235 | * @header_len: length of the batman header preceding the ethernet header | 582 | * @header_len: length of the batman header preceding the ethernet header |
| @@ -1282,36 +629,6 @@ bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid) | |||
| 1282 | return ap_isolation_enabled; | 629 | return ap_isolation_enabled; |
| 1283 | } | 630 | } |
| 1284 | 631 | ||
| 1285 | static int batadv_param_set_ra(const char *val, const struct kernel_param *kp) | ||
| 1286 | { | ||
| 1287 | struct batadv_algo_ops *bat_algo_ops; | ||
| 1288 | char *algo_name = (char *)val; | ||
| 1289 | size_t name_len = strlen(algo_name); | ||
| 1290 | |||
| 1291 | if (name_len > 0 && algo_name[name_len - 1] == '\n') | ||
| 1292 | algo_name[name_len - 1] = '\0'; | ||
| 1293 | |||
| 1294 | bat_algo_ops = batadv_algo_get(algo_name); | ||
| 1295 | if (!bat_algo_ops) { | ||
| 1296 | pr_err("Routing algorithm '%s' is not supported\n", algo_name); | ||
| 1297 | return -EINVAL; | ||
| 1298 | } | ||
| 1299 | |||
| 1300 | return param_set_copystring(algo_name, kp); | ||
| 1301 | } | ||
| 1302 | |||
| 1303 | static const struct kernel_param_ops batadv_param_ops_ra = { | ||
| 1304 | .set = batadv_param_set_ra, | ||
| 1305 | .get = param_get_string, | ||
| 1306 | }; | ||
| 1307 | |||
| 1308 | static struct kparam_string batadv_param_string_ra = { | ||
| 1309 | .maxlen = sizeof(batadv_routing_algo), | ||
| 1310 | .string = batadv_routing_algo, | ||
| 1311 | }; | ||
| 1312 | |||
| 1313 | module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra, | ||
| 1314 | 0644); | ||
| 1315 | module_init(batadv_init); | 632 | module_init(batadv_init); |
| 1316 | module_exit(batadv_exit); | 633 | module_exit(batadv_exit); |
| 1317 | 634 | ||
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h index cd83e2824f70..06a860845434 100644 --- a/net/batman-adv/main.h +++ b/net/batman-adv/main.h | |||
| @@ -100,6 +100,9 @@ | |||
| 100 | #define BATADV_NUM_BCASTS_WIRELESS 3 | 100 | #define BATADV_NUM_BCASTS_WIRELESS 3 |
| 101 | #define BATADV_NUM_BCASTS_MAX 3 | 101 | #define BATADV_NUM_BCASTS_MAX 3 |
| 102 | 102 | ||
| 103 | /* length of the single packet used by the TP meter */ | ||
| 104 | #define BATADV_TP_PACKET_LEN ETH_DATA_LEN | ||
| 105 | |||
| 103 | /* msecs after which an ARP_REQUEST is sent in broadcast as fallback */ | 106 | /* msecs after which an ARP_REQUEST is sent in broadcast as fallback */ |
| 104 | #define ARP_REQ_DELAY 250 | 107 | #define ARP_REQ_DELAY 250 |
| 105 | /* numbers of originator to contact for any PUT/GET DHT operation */ | 108 | /* numbers of originator to contact for any PUT/GET DHT operation */ |
| @@ -131,6 +134,11 @@ | |||
| 131 | 134 | ||
| 132 | #define BATADV_NC_NODE_TIMEOUT 10000 /* Milliseconds */ | 135 | #define BATADV_NC_NODE_TIMEOUT 10000 /* Milliseconds */ |
| 133 | 136 | ||
| 137 | /** | ||
| 138 | * BATADV_TP_MAX_NUM - maximum number of simultaneously active tp sessions | ||
| 139 | */ | ||
| 140 | #define BATADV_TP_MAX_NUM 5 | ||
| 141 | |||
| 134 | enum batadv_mesh_state { | 142 | enum batadv_mesh_state { |
| 135 | BATADV_MESH_INACTIVE, | 143 | BATADV_MESH_INACTIVE, |
| 136 | BATADV_MESH_ACTIVE, | 144 | BATADV_MESH_ACTIVE, |
| @@ -175,29 +183,26 @@ enum batadv_uev_type { | |||
| 175 | 183 | ||
| 176 | /* Kernel headers */ | 184 | /* Kernel headers */ |
| 177 | 185 | ||
| 178 | #include <linux/atomic.h> | ||
| 179 | #include <linux/bitops.h> /* for packet.h */ | 186 | #include <linux/bitops.h> /* for packet.h */ |
| 180 | #include <linux/compiler.h> | 187 | #include <linux/compiler.h> |
| 181 | #include <linux/cpumask.h> | 188 | #include <linux/cpumask.h> |
| 182 | #include <linux/etherdevice.h> | 189 | #include <linux/etherdevice.h> |
| 183 | #include <linux/if_ether.h> /* for packet.h */ | 190 | #include <linux/if_ether.h> /* for packet.h */ |
| 184 | #include <linux/netdevice.h> | ||
| 185 | #include <linux/printk.h> | ||
| 186 | #include <linux/types.h> | ||
| 187 | #include <linux/percpu.h> | ||
| 188 | #include <linux/jiffies.h> | ||
| 189 | #include <linux/if_vlan.h> | 191 | #include <linux/if_vlan.h> |
| 192 | #include <linux/jiffies.h> | ||
| 193 | #include <linux/percpu.h> | ||
| 194 | #include <linux/types.h> | ||
| 190 | 195 | ||
| 191 | #include "types.h" | 196 | #include "types.h" |
| 192 | 197 | ||
| 193 | struct batadv_ogm_packet; | 198 | struct net_device; |
| 199 | struct packet_type; | ||
| 194 | struct seq_file; | 200 | struct seq_file; |
| 195 | struct sk_buff; | 201 | struct sk_buff; |
| 196 | 202 | ||
| 197 | #define BATADV_PRINT_VID(vid) ((vid & BATADV_VLAN_HAS_TAG) ? \ | 203 | #define BATADV_PRINT_VID(vid) ((vid & BATADV_VLAN_HAS_TAG) ? \ |
| 198 | (int)(vid & VLAN_VID_MASK) : -1) | 204 | (int)(vid & VLAN_VID_MASK) : -1) |
| 199 | 205 | ||
| 200 | extern char batadv_routing_algo[]; | ||
| 201 | extern struct list_head batadv_hardif_list; | 206 | extern struct list_head batadv_hardif_list; |
| 202 | 207 | ||
| 203 | extern unsigned char batadv_broadcast_addr[]; | 208 | extern unsigned char batadv_broadcast_addr[]; |
| @@ -218,76 +223,9 @@ batadv_recv_handler_register(u8 packet_type, | |||
| 218 | int (*recv_handler)(struct sk_buff *, | 223 | int (*recv_handler)(struct sk_buff *, |
| 219 | struct batadv_hard_iface *)); | 224 | struct batadv_hard_iface *)); |
| 220 | void batadv_recv_handler_unregister(u8 packet_type); | 225 | void batadv_recv_handler_unregister(u8 packet_type); |
| 221 | int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops); | ||
| 222 | int batadv_algo_select(struct batadv_priv *bat_priv, char *name); | ||
| 223 | int batadv_algo_seq_print_text(struct seq_file *seq, void *offset); | ||
| 224 | __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr); | 226 | __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr); |
| 225 | 227 | ||
| 226 | /** | 228 | /** |
| 227 | * enum batadv_dbg_level - available log levels | ||
| 228 | * @BATADV_DBG_BATMAN: OGM and TQ computations related messages | ||
| 229 | * @BATADV_DBG_ROUTES: route added / changed / deleted | ||
| 230 | * @BATADV_DBG_TT: translation table messages | ||
| 231 | * @BATADV_DBG_BLA: bridge loop avoidance messages | ||
| 232 | * @BATADV_DBG_DAT: ARP snooping and DAT related messages | ||
| 233 | * @BATADV_DBG_NC: network coding related messages | ||
| 234 | * @BATADV_DBG_MCAST: multicast related messages | ||
| 235 | * @BATADV_DBG_ALL: the union of all the above log levels | ||
| 236 | */ | ||
| 237 | enum batadv_dbg_level { | ||
| 238 | BATADV_DBG_BATMAN = BIT(0), | ||
| 239 | BATADV_DBG_ROUTES = BIT(1), | ||
| 240 | BATADV_DBG_TT = BIT(2), | ||
| 241 | BATADV_DBG_BLA = BIT(3), | ||
| 242 | BATADV_DBG_DAT = BIT(4), | ||
| 243 | BATADV_DBG_NC = BIT(5), | ||
| 244 | BATADV_DBG_MCAST = BIT(6), | ||
| 245 | BATADV_DBG_ALL = 127, | ||
| 246 | }; | ||
| 247 | |||
| 248 | #ifdef CONFIG_BATMAN_ADV_DEBUG | ||
| 249 | int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...) | ||
| 250 | __printf(2, 3); | ||
| 251 | |||
| 252 | /* possibly ratelimited debug output */ | ||
| 253 | #define _batadv_dbg(type, bat_priv, ratelimited, fmt, arg...) \ | ||
| 254 | do { \ | ||
| 255 | if (atomic_read(&bat_priv->log_level) & type && \ | ||
| 256 | (!ratelimited || net_ratelimit())) \ | ||
| 257 | batadv_debug_log(bat_priv, fmt, ## arg);\ | ||
| 258 | } \ | ||
| 259 | while (0) | ||
| 260 | #else /* !CONFIG_BATMAN_ADV_DEBUG */ | ||
| 261 | __printf(4, 5) | ||
| 262 | static inline void _batadv_dbg(int type __always_unused, | ||
| 263 | struct batadv_priv *bat_priv __always_unused, | ||
| 264 | int ratelimited __always_unused, | ||
| 265 | const char *fmt __always_unused, ...) | ||
| 266 | { | ||
| 267 | } | ||
| 268 | #endif | ||
| 269 | |||
| 270 | #define batadv_dbg(type, bat_priv, arg...) \ | ||
| 271 | _batadv_dbg(type, bat_priv, 0, ## arg) | ||
| 272 | #define batadv_dbg_ratelimited(type, bat_priv, arg...) \ | ||
| 273 | _batadv_dbg(type, bat_priv, 1, ## arg) | ||
| 274 | |||
| 275 | #define batadv_info(net_dev, fmt, arg...) \ | ||
| 276 | do { \ | ||
| 277 | struct net_device *_netdev = (net_dev); \ | ||
| 278 | struct batadv_priv *_batpriv = netdev_priv(_netdev); \ | ||
| 279 | batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \ | ||
| 280 | pr_info("%s: " fmt, _netdev->name, ## arg); \ | ||
| 281 | } while (0) | ||
| 282 | #define batadv_err(net_dev, fmt, arg...) \ | ||
| 283 | do { \ | ||
| 284 | struct net_device *_netdev = (net_dev); \ | ||
| 285 | struct batadv_priv *_batpriv = netdev_priv(_netdev); \ | ||
| 286 | batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg); \ | ||
| 287 | pr_err("%s: " fmt, _netdev->name, ## arg); \ | ||
| 288 | } while (0) | ||
| 289 | |||
| 290 | /** | ||
| 291 | * batadv_compare_eth - Compare two not u16 aligned Ethernet addresses | 229 | * batadv_compare_eth - Compare two not u16 aligned Ethernet addresses |
| 292 | * @data1: Pointer to a six-byte array containing the Ethernet address | 230 | * @data1: Pointer to a six-byte array containing the Ethernet address |
| 293 | * @data2: Pointer other six-byte array containing the Ethernet address | 231 | * @data2: Pointer other six-byte array containing the Ethernet address |
| @@ -372,39 +310,6 @@ static inline u64 batadv_sum_counter(struct batadv_priv *bat_priv, size_t idx) | |||
| 372 | */ | 310 | */ |
| 373 | #define BATADV_SKB_CB(__skb) ((struct batadv_skb_cb *)&((__skb)->cb[0])) | 311 | #define BATADV_SKB_CB(__skb) ((struct batadv_skb_cb *)&((__skb)->cb[0])) |
| 374 | 312 | ||
| 375 | void batadv_tvlv_container_register(struct batadv_priv *bat_priv, | ||
| 376 | u8 type, u8 version, | ||
| 377 | void *tvlv_value, u16 tvlv_value_len); | ||
| 378 | u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv, | ||
| 379 | unsigned char **packet_buff, | ||
| 380 | int *packet_buff_len, int packet_min_len); | ||
| 381 | void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv, | ||
| 382 | struct batadv_ogm_packet *batadv_ogm_packet, | ||
| 383 | struct batadv_orig_node *orig_node); | ||
| 384 | void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv, | ||
| 385 | u8 type, u8 version); | ||
| 386 | |||
| 387 | void batadv_tvlv_handler_register(struct batadv_priv *bat_priv, | ||
| 388 | void (*optr)(struct batadv_priv *bat_priv, | ||
| 389 | struct batadv_orig_node *orig, | ||
| 390 | u8 flags, | ||
| 391 | void *tvlv_value, | ||
| 392 | u16 tvlv_value_len), | ||
| 393 | int (*uptr)(struct batadv_priv *bat_priv, | ||
| 394 | u8 *src, u8 *dst, | ||
| 395 | void *tvlv_value, | ||
| 396 | u16 tvlv_value_len), | ||
| 397 | u8 type, u8 version, u8 flags); | ||
| 398 | void batadv_tvlv_handler_unregister(struct batadv_priv *bat_priv, | ||
| 399 | u8 type, u8 version); | ||
| 400 | int batadv_tvlv_containers_process(struct batadv_priv *bat_priv, | ||
| 401 | bool ogm_source, | ||
| 402 | struct batadv_orig_node *orig_node, | ||
| 403 | u8 *src, u8 *dst, | ||
| 404 | void *tvlv_buff, u16 tvlv_buff_len); | ||
| 405 | void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src, | ||
| 406 | u8 *dst, u8 type, u8 version, | ||
| 407 | void *tvlv_value, u16 tvlv_value_len); | ||
| 408 | unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len); | 313 | unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len); |
| 409 | bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid); | 314 | bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid); |
| 410 | 315 | ||
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c index d3222db60fd0..cc915073a753 100644 --- a/net/batman-adv/multicast.c +++ b/net/batman-adv/multicast.c | |||
| @@ -55,8 +55,10 @@ | |||
| 55 | 55 | ||
| 56 | #include "hard-interface.h" | 56 | #include "hard-interface.h" |
| 57 | #include "hash.h" | 57 | #include "hash.h" |
| 58 | #include "log.h" | ||
| 58 | #include "packet.h" | 59 | #include "packet.h" |
| 59 | #include "translation-table.h" | 60 | #include "translation-table.h" |
| 61 | #include "tvlv.h" | ||
| 60 | 62 | ||
| 61 | /** | 63 | /** |
| 62 | * batadv_mcast_get_bridge - get the bridge on top of the softif if it exists | 64 | * batadv_mcast_get_bridge - get the bridge on top of the softif if it exists |
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c new file mode 100644 index 000000000000..231f8eaf075b --- /dev/null +++ b/net/batman-adv/netlink.c | |||
| @@ -0,0 +1,424 @@ | |||
| 1 | /* Copyright (C) 2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Matthias Schiffer | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "netlink.h" | ||
| 19 | #include "main.h" | ||
| 20 | |||
| 21 | #include <linux/errno.h> | ||
| 22 | #include <linux/fs.h> | ||
| 23 | #include <linux/genetlink.h> | ||
| 24 | #include <linux/if_ether.h> | ||
| 25 | #include <linux/init.h> | ||
| 26 | #include <linux/netdevice.h> | ||
| 27 | #include <linux/netlink.h> | ||
| 28 | #include <linux/printk.h> | ||
| 29 | #include <linux/stddef.h> | ||
| 30 | #include <linux/types.h> | ||
| 31 | #include <net/genetlink.h> | ||
| 32 | #include <net/netlink.h> | ||
| 33 | #include <uapi/linux/batman_adv.h> | ||
| 34 | |||
| 35 | #include "hard-interface.h" | ||
| 36 | #include "soft-interface.h" | ||
| 37 | #include "tp_meter.h" | ||
| 38 | |||
| 39 | struct sk_buff; | ||
| 40 | |||
| 41 | static struct genl_family batadv_netlink_family = { | ||
| 42 | .id = GENL_ID_GENERATE, | ||
| 43 | .hdrsize = 0, | ||
| 44 | .name = BATADV_NL_NAME, | ||
| 45 | .version = 1, | ||
| 46 | .maxattr = BATADV_ATTR_MAX, | ||
| 47 | }; | ||
| 48 | |||
| 49 | /* multicast groups */ | ||
| 50 | enum batadv_netlink_multicast_groups { | ||
| 51 | BATADV_NL_MCGRP_TPMETER, | ||
| 52 | }; | ||
| 53 | |||
| 54 | static struct genl_multicast_group batadv_netlink_mcgrps[] = { | ||
| 55 | [BATADV_NL_MCGRP_TPMETER] = { .name = BATADV_NL_MCAST_GROUP_TPMETER }, | ||
| 56 | }; | ||
| 57 | |||
| 58 | static struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { | ||
| 59 | [BATADV_ATTR_VERSION] = { .type = NLA_STRING }, | ||
| 60 | [BATADV_ATTR_ALGO_NAME] = { .type = NLA_STRING }, | ||
| 61 | [BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 }, | ||
| 62 | [BATADV_ATTR_MESH_IFNAME] = { .type = NLA_STRING }, | ||
| 63 | [BATADV_ATTR_MESH_ADDRESS] = { .len = ETH_ALEN }, | ||
| 64 | [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 }, | ||
| 65 | [BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING }, | ||
| 66 | [BATADV_ATTR_HARD_ADDRESS] = { .len = ETH_ALEN }, | ||
| 67 | [BATADV_ATTR_ORIG_ADDRESS] = { .len = ETH_ALEN }, | ||
| 68 | [BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 }, | ||
| 69 | [BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 }, | ||
| 70 | [BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 }, | ||
| 71 | [BATADV_ATTR_TPMETER_COOKIE] = { .type = NLA_U32 }, | ||
| 72 | }; | ||
| 73 | |||
| 74 | /** | ||
| 75 | * batadv_netlink_mesh_info_put - fill in generic information about mesh | ||
| 76 | * interface | ||
| 77 | * @msg: netlink message to be sent back | ||
| 78 | * @soft_iface: interface for which the data should be taken | ||
| 79 | * | ||
| 80 | * Return: 0 on success, < 0 on error | ||
| 81 | */ | ||
| 82 | static int | ||
| 83 | batadv_netlink_mesh_info_put(struct sk_buff *msg, struct net_device *soft_iface) | ||
| 84 | { | ||
| 85 | struct batadv_priv *bat_priv = netdev_priv(soft_iface); | ||
| 86 | struct batadv_hard_iface *primary_if = NULL; | ||
| 87 | struct net_device *hard_iface; | ||
| 88 | int ret = -ENOBUFS; | ||
| 89 | |||
| 90 | if (nla_put_string(msg, BATADV_ATTR_VERSION, BATADV_SOURCE_VERSION) || | ||
| 91 | nla_put_string(msg, BATADV_ATTR_ALGO_NAME, | ||
| 92 | bat_priv->algo_ops->name) || | ||
| 93 | nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, soft_iface->ifindex) || | ||
| 94 | nla_put_string(msg, BATADV_ATTR_MESH_IFNAME, soft_iface->name) || | ||
| 95 | nla_put(msg, BATADV_ATTR_MESH_ADDRESS, ETH_ALEN, | ||
| 96 | soft_iface->dev_addr)) | ||
| 97 | goto out; | ||
| 98 | |||
| 99 | primary_if = batadv_primary_if_get_selected(bat_priv); | ||
| 100 | if (primary_if && primary_if->if_status == BATADV_IF_ACTIVE) { | ||
| 101 | hard_iface = primary_if->net_dev; | ||
| 102 | |||
| 103 | if (nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, | ||
| 104 | hard_iface->ifindex) || | ||
| 105 | nla_put_string(msg, BATADV_ATTR_HARD_IFNAME, | ||
| 106 | hard_iface->name) || | ||
| 107 | nla_put(msg, BATADV_ATTR_HARD_ADDRESS, ETH_ALEN, | ||
| 108 | hard_iface->dev_addr)) | ||
| 109 | goto out; | ||
| 110 | } | ||
| 111 | |||
| 112 | ret = 0; | ||
| 113 | |||
| 114 | out: | ||
| 115 | if (primary_if) | ||
| 116 | batadv_hardif_put(primary_if); | ||
| 117 | |||
| 118 | return ret; | ||
| 119 | } | ||
| 120 | |||
| 121 | /** | ||
| 122 | * batadv_netlink_get_mesh_info - handle incoming BATADV_CMD_GET_MESH_INFO | ||
| 123 | * netlink request | ||
| 124 | * @skb: received netlink message | ||
| 125 | * @info: receiver information | ||
| 126 | * | ||
| 127 | * Return: 0 on success, < 0 on error | ||
| 128 | */ | ||
| 129 | static int | ||
| 130 | batadv_netlink_get_mesh_info(struct sk_buff *skb, struct genl_info *info) | ||
| 131 | { | ||
| 132 | struct net *net = genl_info_net(info); | ||
| 133 | struct net_device *soft_iface; | ||
| 134 | struct sk_buff *msg = NULL; | ||
| 135 | void *msg_head; | ||
| 136 | int ifindex; | ||
| 137 | int ret; | ||
| 138 | |||
| 139 | if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) | ||
| 140 | return -EINVAL; | ||
| 141 | |||
| 142 | ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); | ||
| 143 | if (!ifindex) | ||
| 144 | return -EINVAL; | ||
| 145 | |||
| 146 | soft_iface = dev_get_by_index(net, ifindex); | ||
| 147 | if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { | ||
| 148 | ret = -ENODEV; | ||
| 149 | goto out; | ||
| 150 | } | ||
| 151 | |||
| 152 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | ||
| 153 | if (!msg) { | ||
| 154 | ret = -ENOMEM; | ||
| 155 | goto out; | ||
| 156 | } | ||
| 157 | |||
| 158 | msg_head = genlmsg_put(msg, info->snd_portid, info->snd_seq, | ||
| 159 | &batadv_netlink_family, 0, | ||
| 160 | BATADV_CMD_GET_MESH_INFO); | ||
| 161 | if (!msg_head) { | ||
| 162 | ret = -ENOBUFS; | ||
| 163 | goto out; | ||
| 164 | } | ||
| 165 | |||
| 166 | ret = batadv_netlink_mesh_info_put(msg, soft_iface); | ||
| 167 | |||
| 168 | out: | ||
| 169 | if (soft_iface) | ||
| 170 | dev_put(soft_iface); | ||
| 171 | |||
| 172 | if (ret) { | ||
| 173 | if (msg) | ||
| 174 | nlmsg_free(msg); | ||
| 175 | return ret; | ||
| 176 | } | ||
| 177 | |||
| 178 | genlmsg_end(msg, msg_head); | ||
| 179 | return genlmsg_reply(msg, info); | ||
| 180 | } | ||
| 181 | |||
| 182 | /** | ||
| 183 | * batadv_netlink_tp_meter_put - Fill information of started tp_meter session | ||
| 184 | * @msg: netlink message to be sent back | ||
| 185 | * @cookie: tp meter session cookie | ||
| 186 | * | ||
| 187 | * Return: 0 on success, < 0 on error | ||
| 188 | */ | ||
| 189 | static int | ||
| 190 | batadv_netlink_tp_meter_put(struct sk_buff *msg, u32 cookie) | ||
| 191 | { | ||
| 192 | if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie)) | ||
| 193 | return -ENOBUFS; | ||
| 194 | |||
| 195 | return 0; | ||
| 196 | } | ||
| 197 | |||
| 198 | /** | ||
| 199 | * batadv_netlink_tpmeter_notify - send tp_meter result via netlink to client | ||
| 200 | * @bat_priv: the bat priv with all the soft interface information | ||
| 201 | * @dst: destination of tp_meter session | ||
| 202 | * @result: reason for tp meter session stop | ||
| 203 | * @test_time: total time ot the tp_meter session | ||
| 204 | * @total_bytes: bytes acked to the receiver | ||
| 205 | * @cookie: cookie of tp_meter session | ||
| 206 | * | ||
| 207 | * Return: 0 on success, < 0 on error | ||
| 208 | */ | ||
| 209 | int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst, | ||
| 210 | u8 result, u32 test_time, u64 total_bytes, | ||
| 211 | u32 cookie) | ||
| 212 | { | ||
| 213 | struct sk_buff *msg; | ||
| 214 | void *hdr; | ||
| 215 | int ret; | ||
| 216 | |||
| 217 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | ||
| 218 | if (!msg) | ||
| 219 | return -ENOMEM; | ||
| 220 | |||
| 221 | hdr = genlmsg_put(msg, 0, 0, &batadv_netlink_family, 0, | ||
| 222 | BATADV_CMD_TP_METER); | ||
| 223 | if (!hdr) { | ||
| 224 | ret = -ENOBUFS; | ||
| 225 | goto err_genlmsg; | ||
| 226 | } | ||
| 227 | |||
| 228 | if (nla_put_u32(msg, BATADV_ATTR_TPMETER_COOKIE, cookie)) | ||
| 229 | goto nla_put_failure; | ||
| 230 | |||
| 231 | if (nla_put_u32(msg, BATADV_ATTR_TPMETER_TEST_TIME, test_time)) | ||
| 232 | goto nla_put_failure; | ||
| 233 | |||
| 234 | if (nla_put_u64_64bit(msg, BATADV_ATTR_TPMETER_BYTES, total_bytes, | ||
| 235 | BATADV_ATTR_PAD)) | ||
| 236 | goto nla_put_failure; | ||
| 237 | |||
| 238 | if (nla_put_u8(msg, BATADV_ATTR_TPMETER_RESULT, result)) | ||
| 239 | goto nla_put_failure; | ||
| 240 | |||
| 241 | if (nla_put(msg, BATADV_ATTR_ORIG_ADDRESS, ETH_ALEN, dst)) | ||
| 242 | goto nla_put_failure; | ||
| 243 | |||
| 244 | genlmsg_end(msg, hdr); | ||
| 245 | |||
| 246 | genlmsg_multicast_netns(&batadv_netlink_family, | ||
| 247 | dev_net(bat_priv->soft_iface), msg, 0, | ||
| 248 | BATADV_NL_MCGRP_TPMETER, GFP_KERNEL); | ||
| 249 | |||
| 250 | return 0; | ||
| 251 | |||
| 252 | nla_put_failure: | ||
| 253 | genlmsg_cancel(msg, hdr); | ||
| 254 | ret = -EMSGSIZE; | ||
| 255 | |||
| 256 | err_genlmsg: | ||
| 257 | nlmsg_free(msg); | ||
| 258 | return ret; | ||
| 259 | } | ||
| 260 | |||
| 261 | /** | ||
| 262 | * batadv_netlink_tp_meter_start - Start a new tp_meter session | ||
| 263 | * @skb: received netlink message | ||
| 264 | * @info: receiver information | ||
| 265 | * | ||
| 266 | * Return: 0 on success, < 0 on error | ||
| 267 | */ | ||
| 268 | static int | ||
| 269 | batadv_netlink_tp_meter_start(struct sk_buff *skb, struct genl_info *info) | ||
| 270 | { | ||
| 271 | struct net *net = genl_info_net(info); | ||
| 272 | struct net_device *soft_iface; | ||
| 273 | struct batadv_priv *bat_priv; | ||
| 274 | struct sk_buff *msg = NULL; | ||
| 275 | u32 test_length; | ||
| 276 | void *msg_head; | ||
| 277 | int ifindex; | ||
| 278 | u32 cookie; | ||
| 279 | u8 *dst; | ||
| 280 | int ret; | ||
| 281 | |||
| 282 | if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) | ||
| 283 | return -EINVAL; | ||
| 284 | |||
| 285 | if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS]) | ||
| 286 | return -EINVAL; | ||
| 287 | |||
| 288 | if (!info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]) | ||
| 289 | return -EINVAL; | ||
| 290 | |||
| 291 | ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); | ||
| 292 | if (!ifindex) | ||
| 293 | return -EINVAL; | ||
| 294 | |||
| 295 | dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]); | ||
| 296 | |||
| 297 | test_length = nla_get_u32(info->attrs[BATADV_ATTR_TPMETER_TEST_TIME]); | ||
| 298 | |||
| 299 | soft_iface = dev_get_by_index(net, ifindex); | ||
| 300 | if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { | ||
| 301 | ret = -ENODEV; | ||
| 302 | goto out; | ||
| 303 | } | ||
| 304 | |||
| 305 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | ||
| 306 | if (!msg) { | ||
| 307 | ret = -ENOMEM; | ||
| 308 | goto out; | ||
| 309 | } | ||
| 310 | |||
| 311 | msg_head = genlmsg_put(msg, info->snd_portid, info->snd_seq, | ||
| 312 | &batadv_netlink_family, 0, | ||
| 313 | BATADV_CMD_TP_METER); | ||
| 314 | if (!msg_head) { | ||
| 315 | ret = -ENOBUFS; | ||
| 316 | goto out; | ||
| 317 | } | ||
| 318 | |||
| 319 | bat_priv = netdev_priv(soft_iface); | ||
| 320 | batadv_tp_start(bat_priv, dst, test_length, &cookie); | ||
| 321 | |||
| 322 | ret = batadv_netlink_tp_meter_put(msg, cookie); | ||
| 323 | |||
| 324 | out: | ||
| 325 | if (soft_iface) | ||
| 326 | dev_put(soft_iface); | ||
| 327 | |||
| 328 | if (ret) { | ||
| 329 | if (msg) | ||
| 330 | nlmsg_free(msg); | ||
| 331 | return ret; | ||
| 332 | } | ||
| 333 | |||
| 334 | genlmsg_end(msg, msg_head); | ||
| 335 | return genlmsg_reply(msg, info); | ||
| 336 | } | ||
| 337 | |||
| 338 | /** | ||
| 339 | * batadv_netlink_tp_meter_start - Cancel a running tp_meter session | ||
| 340 | * @skb: received netlink message | ||
| 341 | * @info: receiver information | ||
| 342 | * | ||
| 343 | * Return: 0 on success, < 0 on error | ||
| 344 | */ | ||
| 345 | static int | ||
| 346 | batadv_netlink_tp_meter_cancel(struct sk_buff *skb, struct genl_info *info) | ||
| 347 | { | ||
| 348 | struct net *net = genl_info_net(info); | ||
| 349 | struct net_device *soft_iface; | ||
| 350 | struct batadv_priv *bat_priv; | ||
| 351 | int ifindex; | ||
| 352 | u8 *dst; | ||
| 353 | int ret = 0; | ||
| 354 | |||
| 355 | if (!info->attrs[BATADV_ATTR_MESH_IFINDEX]) | ||
| 356 | return -EINVAL; | ||
| 357 | |||
| 358 | if (!info->attrs[BATADV_ATTR_ORIG_ADDRESS]) | ||
| 359 | return -EINVAL; | ||
| 360 | |||
| 361 | ifindex = nla_get_u32(info->attrs[BATADV_ATTR_MESH_IFINDEX]); | ||
| 362 | if (!ifindex) | ||
| 363 | return -EINVAL; | ||
| 364 | |||
| 365 | dst = nla_data(info->attrs[BATADV_ATTR_ORIG_ADDRESS]); | ||
| 366 | |||
| 367 | soft_iface = dev_get_by_index(net, ifindex); | ||
| 368 | if (!soft_iface || !batadv_softif_is_valid(soft_iface)) { | ||
| 369 | ret = -ENODEV; | ||
| 370 | goto out; | ||
| 371 | } | ||
| 372 | |||
| 373 | bat_priv = netdev_priv(soft_iface); | ||
| 374 | batadv_tp_stop(bat_priv, dst, BATADV_TP_REASON_CANCEL); | ||
| 375 | |||
| 376 | out: | ||
| 377 | if (soft_iface) | ||
| 378 | dev_put(soft_iface); | ||
| 379 | |||
| 380 | return ret; | ||
| 381 | } | ||
| 382 | |||
| 383 | static struct genl_ops batadv_netlink_ops[] = { | ||
| 384 | { | ||
| 385 | .cmd = BATADV_CMD_GET_MESH_INFO, | ||
| 386 | .flags = GENL_ADMIN_PERM, | ||
| 387 | .policy = batadv_netlink_policy, | ||
| 388 | .doit = batadv_netlink_get_mesh_info, | ||
| 389 | }, | ||
| 390 | { | ||
| 391 | .cmd = BATADV_CMD_TP_METER, | ||
| 392 | .flags = GENL_ADMIN_PERM, | ||
| 393 | .policy = batadv_netlink_policy, | ||
| 394 | .doit = batadv_netlink_tp_meter_start, | ||
| 395 | }, | ||
| 396 | { | ||
| 397 | .cmd = BATADV_CMD_TP_METER_CANCEL, | ||
| 398 | .flags = GENL_ADMIN_PERM, | ||
| 399 | .policy = batadv_netlink_policy, | ||
| 400 | .doit = batadv_netlink_tp_meter_cancel, | ||
| 401 | }, | ||
| 402 | }; | ||
| 403 | |||
| 404 | /** | ||
| 405 | * batadv_netlink_register - register batadv genl netlink family | ||
| 406 | */ | ||
| 407 | void __init batadv_netlink_register(void) | ||
| 408 | { | ||
| 409 | int ret; | ||
| 410 | |||
| 411 | ret = genl_register_family_with_ops_groups(&batadv_netlink_family, | ||
| 412 | batadv_netlink_ops, | ||
| 413 | batadv_netlink_mcgrps); | ||
| 414 | if (ret) | ||
| 415 | pr_warn("unable to register netlink family"); | ||
| 416 | } | ||
| 417 | |||
| 418 | /** | ||
| 419 | * batadv_netlink_unregister - unregister batadv genl netlink family | ||
| 420 | */ | ||
| 421 | void batadv_netlink_unregister(void) | ||
| 422 | { | ||
| 423 | genl_unregister_family(&batadv_netlink_family); | ||
| 424 | } | ||
diff --git a/net/batman-adv/netlink.h b/net/batman-adv/netlink.h new file mode 100644 index 000000000000..945653ab58c6 --- /dev/null +++ b/net/batman-adv/netlink.h | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /* Copyright (C) 2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Matthias Schiffer | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef _NET_BATMAN_ADV_NETLINK_H_ | ||
| 19 | #define _NET_BATMAN_ADV_NETLINK_H_ | ||
| 20 | |||
| 21 | #include "main.h" | ||
| 22 | |||
| 23 | #include <linux/types.h> | ||
| 24 | |||
| 25 | void batadv_netlink_register(void); | ||
| 26 | void batadv_netlink_unregister(void); | ||
| 27 | |||
| 28 | int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst, | ||
| 29 | u8 result, u32 test_time, u64 total_bytes, | ||
| 30 | u32 cookie); | ||
| 31 | |||
| 32 | #endif /* _NET_BATMAN_ADV_NETLINK_H_ */ | ||
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c index 678f06865312..293ef4ffd4e1 100644 --- a/net/batman-adv/network-coding.c +++ b/net/batman-adv/network-coding.c | |||
| @@ -51,10 +51,12 @@ | |||
| 51 | 51 | ||
| 52 | #include "hard-interface.h" | 52 | #include "hard-interface.h" |
| 53 | #include "hash.h" | 53 | #include "hash.h" |
| 54 | #include "log.h" | ||
| 54 | #include "originator.h" | 55 | #include "originator.h" |
| 55 | #include "packet.h" | 56 | #include "packet.h" |
| 56 | #include "routing.h" | 57 | #include "routing.h" |
| 57 | #include "send.h" | 58 | #include "send.h" |
| 59 | #include "tvlv.h" | ||
| 58 | 60 | ||
| 59 | static struct lock_class_key batadv_nc_coding_hash_lock_class_key; | 61 | static struct lock_class_key batadv_nc_coding_hash_lock_class_key; |
| 60 | static struct lock_class_key batadv_nc_decoding_hash_lock_class_key; | 62 | static struct lock_class_key batadv_nc_decoding_hash_lock_class_key; |
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index 076d258c92e1..7d1e5421f6bc 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c | |||
| @@ -34,11 +34,13 @@ | |||
| 34 | #include <linux/spinlock.h> | 34 | #include <linux/spinlock.h> |
| 35 | #include <linux/workqueue.h> | 35 | #include <linux/workqueue.h> |
| 36 | 36 | ||
| 37 | #include "bat_algo.h" | ||
| 37 | #include "distributed-arp-table.h" | 38 | #include "distributed-arp-table.h" |
| 38 | #include "fragmentation.h" | 39 | #include "fragmentation.h" |
| 39 | #include "gateway_client.h" | 40 | #include "gateway_client.h" |
| 40 | #include "hard-interface.h" | 41 | #include "hard-interface.h" |
| 41 | #include "hash.h" | 42 | #include "hash.h" |
| 43 | #include "log.h" | ||
| 42 | #include "multicast.h" | 44 | #include "multicast.h" |
| 43 | #include "network-coding.h" | 45 | #include "network-coding.h" |
| 44 | #include "routing.h" | 46 | #include "routing.h" |
| @@ -532,8 +534,8 @@ batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface, | |||
| 532 | 534 | ||
| 533 | kref_init(&hardif_neigh->refcount); | 535 | kref_init(&hardif_neigh->refcount); |
| 534 | 536 | ||
| 535 | if (bat_priv->bat_algo_ops->bat_hardif_neigh_init) | 537 | if (bat_priv->algo_ops->neigh.hardif_init) |
| 536 | bat_priv->bat_algo_ops->bat_hardif_neigh_init(hardif_neigh); | 538 | bat_priv->algo_ops->neigh.hardif_init(hardif_neigh); |
| 537 | 539 | ||
| 538 | hlist_add_head(&hardif_neigh->list, &hard_iface->neigh_list); | 540 | hlist_add_head(&hardif_neigh->list, &hard_iface->neigh_list); |
| 539 | 541 | ||
| @@ -704,17 +706,17 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset) | |||
| 704 | seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n", | 706 | seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n", |
| 705 | BATADV_SOURCE_VERSION, primary_if->net_dev->name, | 707 | BATADV_SOURCE_VERSION, primary_if->net_dev->name, |
| 706 | primary_if->net_dev->dev_addr, net_dev->name, | 708 | primary_if->net_dev->dev_addr, net_dev->name, |
| 707 | bat_priv->bat_algo_ops->name); | 709 | bat_priv->algo_ops->name); |
| 708 | 710 | ||
| 709 | batadv_hardif_put(primary_if); | 711 | batadv_hardif_put(primary_if); |
| 710 | 712 | ||
| 711 | if (!bat_priv->bat_algo_ops->bat_neigh_print) { | 713 | if (!bat_priv->algo_ops->neigh.print) { |
| 712 | seq_puts(seq, | 714 | seq_puts(seq, |
| 713 | "No printing function for this routing protocol\n"); | 715 | "No printing function for this routing protocol\n"); |
| 714 | return 0; | 716 | return 0; |
| 715 | } | 717 | } |
| 716 | 718 | ||
| 717 | bat_priv->bat_algo_ops->bat_neigh_print(bat_priv, seq); | 719 | bat_priv->algo_ops->neigh.print(bat_priv, seq); |
| 718 | return 0; | 720 | return 0; |
| 719 | } | 721 | } |
| 720 | 722 | ||
| @@ -765,8 +767,8 @@ static void batadv_orig_node_free_rcu(struct rcu_head *rcu) | |||
| 765 | 767 | ||
| 766 | batadv_frag_purge_orig(orig_node, NULL); | 768 | batadv_frag_purge_orig(orig_node, NULL); |
| 767 | 769 | ||
| 768 | if (orig_node->bat_priv->bat_algo_ops->bat_orig_free) | 770 | if (orig_node->bat_priv->algo_ops->orig.free) |
| 769 | orig_node->bat_priv->bat_algo_ops->bat_orig_free(orig_node); | 771 | orig_node->bat_priv->algo_ops->orig.free(orig_node); |
| 770 | 772 | ||
| 771 | kfree(orig_node->tt_buff); | 773 | kfree(orig_node->tt_buff); |
| 772 | kfree(orig_node); | 774 | kfree(orig_node); |
| @@ -1095,12 +1097,12 @@ batadv_find_best_neighbor(struct batadv_priv *bat_priv, | |||
| 1095 | struct batadv_hard_iface *if_outgoing) | 1097 | struct batadv_hard_iface *if_outgoing) |
| 1096 | { | 1098 | { |
| 1097 | struct batadv_neigh_node *best = NULL, *neigh; | 1099 | struct batadv_neigh_node *best = NULL, *neigh; |
| 1098 | struct batadv_algo_ops *bao = bat_priv->bat_algo_ops; | 1100 | struct batadv_algo_ops *bao = bat_priv->algo_ops; |
| 1099 | 1101 | ||
| 1100 | rcu_read_lock(); | 1102 | rcu_read_lock(); |
| 1101 | hlist_for_each_entry_rcu(neigh, &orig_node->neigh_list, list) { | 1103 | hlist_for_each_entry_rcu(neigh, &orig_node->neigh_list, list) { |
| 1102 | if (best && (bao->bat_neigh_cmp(neigh, if_outgoing, | 1104 | if (best && (bao->neigh.cmp(neigh, if_outgoing, best, |
| 1103 | best, if_outgoing) <= 0)) | 1105 | if_outgoing) <= 0)) |
| 1104 | continue; | 1106 | continue; |
| 1105 | 1107 | ||
| 1106 | if (!kref_get_unless_zero(&neigh->refcount)) | 1108 | if (!kref_get_unless_zero(&neigh->refcount)) |
| @@ -1252,18 +1254,17 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset) | |||
| 1252 | seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n", | 1254 | seq_printf(seq, "[B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s %s)]\n", |
| 1253 | BATADV_SOURCE_VERSION, primary_if->net_dev->name, | 1255 | BATADV_SOURCE_VERSION, primary_if->net_dev->name, |
| 1254 | primary_if->net_dev->dev_addr, net_dev->name, | 1256 | primary_if->net_dev->dev_addr, net_dev->name, |
| 1255 | bat_priv->bat_algo_ops->name); | 1257 | bat_priv->algo_ops->name); |
| 1256 | 1258 | ||
| 1257 | batadv_hardif_put(primary_if); | 1259 | batadv_hardif_put(primary_if); |
| 1258 | 1260 | ||
| 1259 | if (!bat_priv->bat_algo_ops->bat_orig_print) { | 1261 | if (!bat_priv->algo_ops->orig.print) { |
| 1260 | seq_puts(seq, | 1262 | seq_puts(seq, |
| 1261 | "No printing function for this routing protocol\n"); | 1263 | "No printing function for this routing protocol\n"); |
| 1262 | return 0; | 1264 | return 0; |
| 1263 | } | 1265 | } |
| 1264 | 1266 | ||
| 1265 | bat_priv->bat_algo_ops->bat_orig_print(bat_priv, seq, | 1267 | bat_priv->algo_ops->orig.print(bat_priv, seq, BATADV_IF_DEFAULT); |
| 1266 | BATADV_IF_DEFAULT); | ||
| 1267 | 1268 | ||
| 1268 | return 0; | 1269 | return 0; |
| 1269 | } | 1270 | } |
| @@ -1290,7 +1291,7 @@ int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset) | |||
| 1290 | } | 1291 | } |
| 1291 | 1292 | ||
| 1292 | bat_priv = netdev_priv(hard_iface->soft_iface); | 1293 | bat_priv = netdev_priv(hard_iface->soft_iface); |
| 1293 | if (!bat_priv->bat_algo_ops->bat_orig_print) { | 1294 | if (!bat_priv->algo_ops->orig.print) { |
| 1294 | seq_puts(seq, | 1295 | seq_puts(seq, |
| 1295 | "No printing function for this routing protocol\n"); | 1296 | "No printing function for this routing protocol\n"); |
| 1296 | goto out; | 1297 | goto out; |
| @@ -1304,9 +1305,9 @@ int batadv_orig_hardif_seq_print_text(struct seq_file *seq, void *offset) | |||
| 1304 | seq_printf(seq, "[B.A.T.M.A.N. adv %s, IF/MAC: %s/%pM (%s %s)]\n", | 1305 | seq_printf(seq, "[B.A.T.M.A.N. adv %s, IF/MAC: %s/%pM (%s %s)]\n", |
| 1305 | BATADV_SOURCE_VERSION, hard_iface->net_dev->name, | 1306 | BATADV_SOURCE_VERSION, hard_iface->net_dev->name, |
| 1306 | hard_iface->net_dev->dev_addr, | 1307 | hard_iface->net_dev->dev_addr, |
| 1307 | hard_iface->soft_iface->name, bat_priv->bat_algo_ops->name); | 1308 | hard_iface->soft_iface->name, bat_priv->algo_ops->name); |
| 1308 | 1309 | ||
| 1309 | bat_priv->bat_algo_ops->bat_orig_print(bat_priv, seq, hard_iface); | 1310 | bat_priv->algo_ops->orig.print(bat_priv, seq, hard_iface); |
| 1310 | 1311 | ||
| 1311 | out: | 1312 | out: |
| 1312 | if (hard_iface) | 1313 | if (hard_iface) |
| @@ -1318,7 +1319,7 @@ int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface, | |||
| 1318 | int max_if_num) | 1319 | int max_if_num) |
| 1319 | { | 1320 | { |
| 1320 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); | 1321 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
| 1321 | struct batadv_algo_ops *bao = bat_priv->bat_algo_ops; | 1322 | struct batadv_algo_ops *bao = bat_priv->algo_ops; |
| 1322 | struct batadv_hashtable *hash = bat_priv->orig_hash; | 1323 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 1323 | struct hlist_head *head; | 1324 | struct hlist_head *head; |
| 1324 | struct batadv_orig_node *orig_node; | 1325 | struct batadv_orig_node *orig_node; |
| @@ -1334,9 +1335,8 @@ int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface, | |||
| 1334 | rcu_read_lock(); | 1335 | rcu_read_lock(); |
| 1335 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { | 1336 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
| 1336 | ret = 0; | 1337 | ret = 0; |
| 1337 | if (bao->bat_orig_add_if) | 1338 | if (bao->orig.add_if) |
| 1338 | ret = bao->bat_orig_add_if(orig_node, | 1339 | ret = bao->orig.add_if(orig_node, max_if_num); |
| 1339 | max_if_num); | ||
| 1340 | if (ret == -ENOMEM) | 1340 | if (ret == -ENOMEM) |
| 1341 | goto err; | 1341 | goto err; |
| 1342 | } | 1342 | } |
| @@ -1358,7 +1358,7 @@ int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface, | |||
| 1358 | struct hlist_head *head; | 1358 | struct hlist_head *head; |
| 1359 | struct batadv_hard_iface *hard_iface_tmp; | 1359 | struct batadv_hard_iface *hard_iface_tmp; |
| 1360 | struct batadv_orig_node *orig_node; | 1360 | struct batadv_orig_node *orig_node; |
| 1361 | struct batadv_algo_ops *bao = bat_priv->bat_algo_ops; | 1361 | struct batadv_algo_ops *bao = bat_priv->algo_ops; |
| 1362 | u32 i; | 1362 | u32 i; |
| 1363 | int ret; | 1363 | int ret; |
| 1364 | 1364 | ||
| @@ -1371,10 +1371,9 @@ int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface, | |||
| 1371 | rcu_read_lock(); | 1371 | rcu_read_lock(); |
| 1372 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { | 1372 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
| 1373 | ret = 0; | 1373 | ret = 0; |
| 1374 | if (bao->bat_orig_del_if) | 1374 | if (bao->orig.del_if) |
| 1375 | ret = bao->bat_orig_del_if(orig_node, | 1375 | ret = bao->orig.del_if(orig_node, max_if_num, |
| 1376 | max_if_num, | 1376 | hard_iface->if_num); |
| 1377 | hard_iface->if_num); | ||
| 1378 | if (ret == -ENOMEM) | 1377 | if (ret == -ENOMEM) |
| 1379 | goto err; | 1378 | goto err; |
| 1380 | } | 1379 | } |
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h index 71567794df17..6b011ff64dd8 100644 --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h | |||
| @@ -21,6 +21,8 @@ | |||
| 21 | #include <asm/byteorder.h> | 21 | #include <asm/byteorder.h> |
| 22 | #include <linux/types.h> | 22 | #include <linux/types.h> |
| 23 | 23 | ||
| 24 | #define batadv_tp_is_error(n) ((u8)n > 127 ? 1 : 0) | ||
| 25 | |||
| 24 | /** | 26 | /** |
| 25 | * enum batadv_packettype - types for batman-adv encapsulated packets | 27 | * enum batadv_packettype - types for batman-adv encapsulated packets |
| 26 | * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV | 28 | * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV |
| @@ -93,6 +95,7 @@ enum batadv_icmp_packettype { | |||
| 93 | BATADV_ECHO_REQUEST = 8, | 95 | BATADV_ECHO_REQUEST = 8, |
| 94 | BATADV_TTL_EXCEEDED = 11, | 96 | BATADV_TTL_EXCEEDED = 11, |
| 95 | BATADV_PARAMETER_PROBLEM = 12, | 97 | BATADV_PARAMETER_PROBLEM = 12, |
| 98 | BATADV_TP = 15, | ||
| 96 | }; | 99 | }; |
| 97 | 100 | ||
| 98 | /** | 101 | /** |
| @@ -285,6 +288,16 @@ struct batadv_elp_packet { | |||
| 285 | #define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet) | 288 | #define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet) |
| 286 | 289 | ||
| 287 | /** | 290 | /** |
| 291 | * enum batadv_icmp_user_cmd_type - types for batman-adv icmp cmd modes | ||
| 292 | * @BATADV_TP_START: start a throughput meter run | ||
| 293 | * @BATADV_TP_STOP: stop a throughput meter run | ||
| 294 | */ | ||
| 295 | enum batadv_icmp_user_cmd_type { | ||
| 296 | BATADV_TP_START = 0, | ||
| 297 | BATADV_TP_STOP = 2, | ||
| 298 | }; | ||
| 299 | |||
| 300 | /** | ||
| 288 | * struct batadv_icmp_header - common members among all the ICMP packets | 301 | * struct batadv_icmp_header - common members among all the ICMP packets |
| 289 | * @packet_type: batman-adv packet type, part of the general header | 302 | * @packet_type: batman-adv packet type, part of the general header |
| 290 | * @version: batman-adv protocol version, part of the genereal header | 303 | * @version: batman-adv protocol version, part of the genereal header |
| @@ -334,6 +347,47 @@ struct batadv_icmp_packet { | |||
| 334 | __be16 seqno; | 347 | __be16 seqno; |
| 335 | }; | 348 | }; |
| 336 | 349 | ||
| 350 | /** | ||
| 351 | * struct batadv_icmp_tp_packet - ICMP TP Meter packet | ||
| 352 | * @packet_type: batman-adv packet type, part of the general header | ||
| 353 | * @version: batman-adv protocol version, part of the genereal header | ||
| 354 | * @ttl: time to live for this packet, part of the genereal header | ||
| 355 | * @msg_type: ICMP packet type | ||
| 356 | * @dst: address of the destination node | ||
| 357 | * @orig: address of the source node | ||
| 358 | * @uid: local ICMP socket identifier | ||
| 359 | * @subtype: TP packet subtype (see batadv_icmp_tp_subtype) | ||
| 360 | * @session: TP session identifier | ||
| 361 | * @seqno: the TP sequence number | ||
| 362 | * @timestamp: time when the packet has been sent. This value is filled in a | ||
| 363 | * TP_MSG and echoed back in the next TP_ACK so that the sender can compute the | ||
| 364 | * RTT. Since it is read only by the host which wrote it, there is no need to | ||
| 365 | * store it using network order | ||
| 366 | */ | ||
| 367 | struct batadv_icmp_tp_packet { | ||
| 368 | u8 packet_type; | ||
| 369 | u8 version; | ||
| 370 | u8 ttl; | ||
| 371 | u8 msg_type; /* see ICMP message types above */ | ||
| 372 | u8 dst[ETH_ALEN]; | ||
| 373 | u8 orig[ETH_ALEN]; | ||
| 374 | u8 uid; | ||
| 375 | u8 subtype; | ||
| 376 | u8 session[2]; | ||
| 377 | __be32 seqno; | ||
| 378 | __be32 timestamp; | ||
| 379 | }; | ||
| 380 | |||
| 381 | /** | ||
| 382 | * enum batadv_icmp_tp_subtype - ICMP TP Meter packet subtypes | ||
| 383 | * @BATADV_TP_MSG: Msg from sender to receiver | ||
| 384 | * @BATADV_TP_ACK: acknowledgment from receiver to sender | ||
| 385 | */ | ||
| 386 | enum batadv_icmp_tp_subtype { | ||
| 387 | BATADV_TP_MSG = 0, | ||
| 388 | BATADV_TP_ACK, | ||
| 389 | }; | ||
| 390 | |||
| 337 | #define BATADV_RR_LEN 16 | 391 | #define BATADV_RR_LEN 16 |
| 338 | 392 | ||
| 339 | /** | 393 | /** |
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 319a58820197..af8e11933928 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c | |||
| @@ -40,12 +40,15 @@ | |||
| 40 | #include "fragmentation.h" | 40 | #include "fragmentation.h" |
| 41 | #include "hard-interface.h" | 41 | #include "hard-interface.h" |
| 42 | #include "icmp_socket.h" | 42 | #include "icmp_socket.h" |
| 43 | #include "log.h" | ||
| 43 | #include "network-coding.h" | 44 | #include "network-coding.h" |
| 44 | #include "originator.h" | 45 | #include "originator.h" |
| 45 | #include "packet.h" | 46 | #include "packet.h" |
| 46 | #include "send.h" | 47 | #include "send.h" |
| 47 | #include "soft-interface.h" | 48 | #include "soft-interface.h" |
| 49 | #include "tp_meter.h" | ||
| 48 | #include "translation-table.h" | 50 | #include "translation-table.h" |
| 51 | #include "tvlv.h" | ||
| 49 | 52 | ||
| 50 | static int batadv_route_unicast_packet(struct sk_buff *skb, | 53 | static int batadv_route_unicast_packet(struct sk_buff *skb, |
| 51 | struct batadv_hard_iface *recv_if); | 54 | struct batadv_hard_iface *recv_if); |
| @@ -268,10 +271,19 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv, | |||
| 268 | icmph->ttl = BATADV_TTL; | 271 | icmph->ttl = BATADV_TTL; |
| 269 | 272 | ||
| 270 | res = batadv_send_skb_to_orig(skb, orig_node, NULL); | 273 | res = batadv_send_skb_to_orig(skb, orig_node, NULL); |
| 271 | if (res != NET_XMIT_DROP) | 274 | if (res == -1) |
| 272 | ret = NET_RX_SUCCESS; | 275 | goto out; |
| 276 | |||
| 277 | ret = NET_RX_SUCCESS; | ||
| 273 | 278 | ||
| 274 | break; | 279 | break; |
| 280 | case BATADV_TP: | ||
| 281 | if (!pskb_may_pull(skb, sizeof(struct batadv_icmp_tp_packet))) | ||
| 282 | goto out; | ||
| 283 | |||
| 284 | batadv_tp_meter_recv(bat_priv, skb); | ||
| 285 | ret = NET_RX_SUCCESS; | ||
| 286 | goto out; | ||
| 275 | default: | 287 | default: |
| 276 | /* drop unknown type */ | 288 | /* drop unknown type */ |
| 277 | goto out; | 289 | goto out; |
| @@ -290,7 +302,7 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv, | |||
| 290 | struct batadv_hard_iface *primary_if = NULL; | 302 | struct batadv_hard_iface *primary_if = NULL; |
| 291 | struct batadv_orig_node *orig_node = NULL; | 303 | struct batadv_orig_node *orig_node = NULL; |
| 292 | struct batadv_icmp_packet *icmp_packet; | 304 | struct batadv_icmp_packet *icmp_packet; |
| 293 | int ret = NET_RX_DROP; | 305 | int res, ret = NET_RX_DROP; |
| 294 | 306 | ||
| 295 | icmp_packet = (struct batadv_icmp_packet *)skb->data; | 307 | icmp_packet = (struct batadv_icmp_packet *)skb->data; |
| 296 | 308 | ||
| @@ -321,7 +333,8 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv, | |||
| 321 | icmp_packet->msg_type = BATADV_TTL_EXCEEDED; | 333 | icmp_packet->msg_type = BATADV_TTL_EXCEEDED; |
| 322 | icmp_packet->ttl = BATADV_TTL; | 334 | icmp_packet->ttl = BATADV_TTL; |
| 323 | 335 | ||
| 324 | if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP) | 336 | res = batadv_send_skb_to_orig(skb, orig_node, NULL); |
| 337 | if (res != -1) | ||
| 325 | ret = NET_RX_SUCCESS; | 338 | ret = NET_RX_SUCCESS; |
| 326 | 339 | ||
| 327 | out: | 340 | out: |
| @@ -341,7 +354,7 @@ int batadv_recv_icmp_packet(struct sk_buff *skb, | |||
| 341 | struct ethhdr *ethhdr; | 354 | struct ethhdr *ethhdr; |
| 342 | struct batadv_orig_node *orig_node = NULL; | 355 | struct batadv_orig_node *orig_node = NULL; |
| 343 | int hdr_size = sizeof(struct batadv_icmp_header); | 356 | int hdr_size = sizeof(struct batadv_icmp_header); |
| 344 | int ret = NET_RX_DROP; | 357 | int res, ret = NET_RX_DROP; |
| 345 | 358 | ||
| 346 | /* drop packet if it has not necessary minimum size */ | 359 | /* drop packet if it has not necessary minimum size */ |
| 347 | if (unlikely(!pskb_may_pull(skb, hdr_size))) | 360 | if (unlikely(!pskb_may_pull(skb, hdr_size))) |
| @@ -408,7 +421,8 @@ int batadv_recv_icmp_packet(struct sk_buff *skb, | |||
| 408 | icmph->ttl--; | 421 | icmph->ttl--; |
| 409 | 422 | ||
| 410 | /* route it */ | 423 | /* route it */ |
| 411 | if (batadv_send_skb_to_orig(skb, orig_node, recv_if) != NET_XMIT_DROP) | 424 | res = batadv_send_skb_to_orig(skb, orig_node, recv_if); |
| 425 | if (res != -1) | ||
| 412 | ret = NET_RX_SUCCESS; | 426 | ret = NET_RX_SUCCESS; |
| 413 | 427 | ||
| 414 | out: | 428 | out: |
| @@ -469,7 +483,7 @@ batadv_find_router(struct batadv_priv *bat_priv, | |||
| 469 | struct batadv_orig_node *orig_node, | 483 | struct batadv_orig_node *orig_node, |
| 470 | struct batadv_hard_iface *recv_if) | 484 | struct batadv_hard_iface *recv_if) |
| 471 | { | 485 | { |
| 472 | struct batadv_algo_ops *bao = bat_priv->bat_algo_ops; | 486 | struct batadv_algo_ops *bao = bat_priv->algo_ops; |
| 473 | struct batadv_neigh_node *first_candidate_router = NULL; | 487 | struct batadv_neigh_node *first_candidate_router = NULL; |
| 474 | struct batadv_neigh_node *next_candidate_router = NULL; | 488 | struct batadv_neigh_node *next_candidate_router = NULL; |
| 475 | struct batadv_neigh_node *router, *cand_router = NULL; | 489 | struct batadv_neigh_node *router, *cand_router = NULL; |
| @@ -523,9 +537,9 @@ batadv_find_router(struct batadv_priv *bat_priv, | |||
| 523 | /* alternative candidate should be good enough to be | 537 | /* alternative candidate should be good enough to be |
| 524 | * considered | 538 | * considered |
| 525 | */ | 539 | */ |
| 526 | if (!bao->bat_neigh_is_similar_or_better(cand_router, | 540 | if (!bao->neigh.is_similar_or_better(cand_router, |
| 527 | cand->if_outgoing, | 541 | cand->if_outgoing, router, |
| 528 | router, recv_if)) | 542 | recv_if)) |
| 529 | goto next; | 543 | goto next; |
| 530 | 544 | ||
| 531 | /* don't use the same router twice */ | 545 | /* don't use the same router twice */ |
| @@ -645,6 +659,8 @@ static int batadv_route_unicast_packet(struct sk_buff *skb, | |||
| 645 | 659 | ||
| 646 | len = skb->len; | 660 | len = skb->len; |
| 647 | res = batadv_send_skb_to_orig(skb, orig_node, recv_if); | 661 | res = batadv_send_skb_to_orig(skb, orig_node, recv_if); |
| 662 | if (res == -1) | ||
| 663 | goto out; | ||
| 648 | 664 | ||
| 649 | /* translate transmit result into receive result */ | 665 | /* translate transmit result into receive result */ |
| 650 | if (res == NET_XMIT_SUCCESS) { | 666 | if (res == NET_XMIT_SUCCESS) { |
| @@ -652,13 +668,10 @@ static int batadv_route_unicast_packet(struct sk_buff *skb, | |||
| 652 | batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD); | 668 | batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD); |
| 653 | batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES, | 669 | batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES, |
| 654 | len + ETH_HLEN); | 670 | len + ETH_HLEN); |
| 655 | |||
| 656 | ret = NET_RX_SUCCESS; | ||
| 657 | } else if (res == -EINPROGRESS) { | ||
| 658 | /* skb was buffered and consumed */ | ||
| 659 | ret = NET_RX_SUCCESS; | ||
| 660 | } | 671 | } |
| 661 | 672 | ||
| 673 | ret = NET_RX_SUCCESS; | ||
| 674 | |||
| 662 | out: | 675 | out: |
| 663 | if (orig_node) | 676 | if (orig_node) |
| 664 | batadv_orig_node_put(orig_node); | 677 | batadv_orig_node_put(orig_node); |
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c index 59e695b5cfbd..3a10d87b4b76 100644 --- a/net/batman-adv/send.c +++ b/net/batman-adv/send.c | |||
| @@ -20,10 +20,11 @@ | |||
| 20 | 20 | ||
| 21 | #include <linux/atomic.h> | 21 | #include <linux/atomic.h> |
| 22 | #include <linux/byteorder/generic.h> | 22 | #include <linux/byteorder/generic.h> |
| 23 | #include <linux/errno.h> | ||
| 23 | #include <linux/etherdevice.h> | 24 | #include <linux/etherdevice.h> |
| 24 | #include <linux/fs.h> | 25 | #include <linux/fs.h> |
| 25 | #include <linux/if_ether.h> | ||
| 26 | #include <linux/if.h> | 26 | #include <linux/if.h> |
| 27 | #include <linux/if_ether.h> | ||
| 27 | #include <linux/jiffies.h> | 28 | #include <linux/jiffies.h> |
| 28 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
| 29 | #include <linux/kref.h> | 30 | #include <linux/kref.h> |
| @@ -42,6 +43,7 @@ | |||
| 42 | #include "fragmentation.h" | 43 | #include "fragmentation.h" |
| 43 | #include "gateway_client.h" | 44 | #include "gateway_client.h" |
| 44 | #include "hard-interface.h" | 45 | #include "hard-interface.h" |
| 46 | #include "log.h" | ||
| 45 | #include "network-coding.h" | 47 | #include "network-coding.h" |
| 46 | #include "originator.h" | 48 | #include "originator.h" |
| 47 | #include "routing.h" | 49 | #include "routing.h" |
| @@ -71,6 +73,7 @@ int batadv_send_skb_packet(struct sk_buff *skb, | |||
| 71 | { | 73 | { |
| 72 | struct batadv_priv *bat_priv; | 74 | struct batadv_priv *bat_priv; |
| 73 | struct ethhdr *ethhdr; | 75 | struct ethhdr *ethhdr; |
| 76 | int ret; | ||
| 74 | 77 | ||
| 75 | bat_priv = netdev_priv(hard_iface->soft_iface); | 78 | bat_priv = netdev_priv(hard_iface->soft_iface); |
| 76 | 79 | ||
| @@ -108,8 +111,15 @@ int batadv_send_skb_packet(struct sk_buff *skb, | |||
| 108 | /* dev_queue_xmit() returns a negative result on error. However on | 111 | /* dev_queue_xmit() returns a negative result on error. However on |
| 109 | * congestion and traffic shaping, it drops and returns NET_XMIT_DROP | 112 | * congestion and traffic shaping, it drops and returns NET_XMIT_DROP |
| 110 | * (which is > 0). This will not be treated as an error. | 113 | * (which is > 0). This will not be treated as an error. |
| 114 | * | ||
| 115 | * a negative value cannot be returned because it could be interepreted | ||
| 116 | * as not consumed skb by callers of batadv_send_skb_to_orig. | ||
| 111 | */ | 117 | */ |
| 112 | return dev_queue_xmit(skb); | 118 | ret = dev_queue_xmit(skb); |
| 119 | if (ret < 0) | ||
| 120 | ret = NET_XMIT_DROP; | ||
| 121 | |||
| 122 | return ret; | ||
| 113 | send_skb_err: | 123 | send_skb_err: |
| 114 | kfree_skb(skb); | 124 | kfree_skb(skb); |
| 115 | return NET_XMIT_DROP; | 125 | return NET_XMIT_DROP; |
| @@ -155,8 +165,11 @@ int batadv_send_unicast_skb(struct sk_buff *skb, | |||
| 155 | * host, NULL can be passed as recv_if and no interface alternating is | 165 | * host, NULL can be passed as recv_if and no interface alternating is |
| 156 | * attempted. | 166 | * attempted. |
| 157 | * | 167 | * |
| 158 | * Return: NET_XMIT_SUCCESS on success, NET_XMIT_DROP on failure, or | 168 | * Return: -1 on failure (and the skb is not consumed), -EINPROGRESS if the |
| 159 | * -EINPROGRESS if the skb is buffered for later transmit. | 169 | * skb is buffered for later transmit or the NET_XMIT status returned by the |
| 170 | * lower routine if the packet has been passed down. | ||
| 171 | * | ||
| 172 | * If the returning value is not -1 the skb has been consumed. | ||
| 160 | */ | 173 | */ |
| 161 | int batadv_send_skb_to_orig(struct sk_buff *skb, | 174 | int batadv_send_skb_to_orig(struct sk_buff *skb, |
| 162 | struct batadv_orig_node *orig_node, | 175 | struct batadv_orig_node *orig_node, |
| @@ -164,7 +177,7 @@ int batadv_send_skb_to_orig(struct sk_buff *skb, | |||
| 164 | { | 177 | { |
| 165 | struct batadv_priv *bat_priv = orig_node->bat_priv; | 178 | struct batadv_priv *bat_priv = orig_node->bat_priv; |
| 166 | struct batadv_neigh_node *neigh_node; | 179 | struct batadv_neigh_node *neigh_node; |
| 167 | int ret = NET_XMIT_DROP; | 180 | int ret = -1; |
| 168 | 181 | ||
| 169 | /* batadv_find_router() increases neigh_nodes refcount if found. */ | 182 | /* batadv_find_router() increases neigh_nodes refcount if found. */ |
| 170 | neigh_node = batadv_find_router(bat_priv, orig_node, recv_if); | 183 | neigh_node = batadv_find_router(bat_priv, orig_node, recv_if); |
| @@ -177,8 +190,7 @@ int batadv_send_skb_to_orig(struct sk_buff *skb, | |||
| 177 | if (atomic_read(&bat_priv->fragmentation) && | 190 | if (atomic_read(&bat_priv->fragmentation) && |
| 178 | skb->len > neigh_node->if_incoming->net_dev->mtu) { | 191 | skb->len > neigh_node->if_incoming->net_dev->mtu) { |
| 179 | /* Fragment and send packet. */ | 192 | /* Fragment and send packet. */ |
| 180 | if (batadv_frag_send_packet(skb, orig_node, neigh_node)) | 193 | ret = batadv_frag_send_packet(skb, orig_node, neigh_node); |
| 181 | ret = NET_XMIT_SUCCESS; | ||
| 182 | 194 | ||
| 183 | goto out; | 195 | goto out; |
| 184 | } | 196 | } |
| @@ -187,12 +199,10 @@ int batadv_send_skb_to_orig(struct sk_buff *skb, | |||
| 187 | * (i.e. being forwarded). If the packet originates from this node or if | 199 | * (i.e. being forwarded). If the packet originates from this node or if |
| 188 | * network coding fails, then send the packet as usual. | 200 | * network coding fails, then send the packet as usual. |
| 189 | */ | 201 | */ |
| 190 | if (recv_if && batadv_nc_skb_forward(skb, neigh_node)) { | 202 | if (recv_if && batadv_nc_skb_forward(skb, neigh_node)) |
| 191 | ret = -EINPROGRESS; | 203 | ret = -EINPROGRESS; |
| 192 | } else { | 204 | else |
| 193 | batadv_send_unicast_skb(skb, neigh_node); | 205 | ret = batadv_send_unicast_skb(skb, neigh_node); |
| 194 | ret = NET_XMIT_SUCCESS; | ||
| 195 | } | ||
| 196 | 206 | ||
| 197 | out: | 207 | out: |
| 198 | if (neigh_node) | 208 | if (neigh_node) |
| @@ -318,7 +328,7 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv, | |||
| 318 | { | 328 | { |
| 319 | struct batadv_unicast_packet *unicast_packet; | 329 | struct batadv_unicast_packet *unicast_packet; |
| 320 | struct ethhdr *ethhdr; | 330 | struct ethhdr *ethhdr; |
| 321 | int ret = NET_XMIT_DROP; | 331 | int res, ret = NET_XMIT_DROP; |
| 322 | 332 | ||
| 323 | if (!orig_node) | 333 | if (!orig_node) |
| 324 | goto out; | 334 | goto out; |
| @@ -355,7 +365,8 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv, | |||
| 355 | if (batadv_tt_global_client_is_roaming(bat_priv, ethhdr->h_dest, vid)) | 365 | if (batadv_tt_global_client_is_roaming(bat_priv, ethhdr->h_dest, vid)) |
| 356 | unicast_packet->ttvn = unicast_packet->ttvn - 1; | 366 | unicast_packet->ttvn = unicast_packet->ttvn - 1; |
| 357 | 367 | ||
| 358 | if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP) | 368 | res = batadv_send_skb_to_orig(skb, orig_node, NULL); |
| 369 | if (res != -1) | ||
| 359 | ret = NET_XMIT_SUCCESS; | 370 | ret = NET_XMIT_SUCCESS; |
| 360 | 371 | ||
| 361 | out: | 372 | out: |
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c index 4ba894ca8b2a..7527c0652dd5 100644 --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c | |||
| @@ -48,6 +48,7 @@ | |||
| 48 | #include <linux/types.h> | 48 | #include <linux/types.h> |
| 49 | #include <linux/workqueue.h> | 49 | #include <linux/workqueue.h> |
| 50 | 50 | ||
| 51 | #include "bat_algo.h" | ||
| 51 | #include "bridge_loop_avoidance.h" | 52 | #include "bridge_loop_avoidance.h" |
| 52 | #include "debugfs.h" | 53 | #include "debugfs.h" |
| 53 | #include "distributed-arp-table.h" | 54 | #include "distributed-arp-table.h" |
| @@ -841,6 +842,8 @@ static int batadv_softif_init_late(struct net_device *dev) | |||
| 841 | #ifdef CONFIG_BATMAN_ADV_BLA | 842 | #ifdef CONFIG_BATMAN_ADV_BLA |
| 842 | atomic_set(&bat_priv->bla.num_requests, 0); | 843 | atomic_set(&bat_priv->bla.num_requests, 0); |
| 843 | #endif | 844 | #endif |
| 845 | atomic_set(&bat_priv->tp_num, 0); | ||
| 846 | |||
| 844 | bat_priv->tt.last_changeset = NULL; | 847 | bat_priv->tt.last_changeset = NULL; |
| 845 | bat_priv->tt.last_changeset_len = 0; | 848 | bat_priv->tt.last_changeset_len = 0; |
| 846 | bat_priv->isolation_mark = 0; | 849 | bat_priv->isolation_mark = 0; |
diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c index 233abcf33c03..fe9ca94ddee2 100644 --- a/net/batman-adv/sysfs.c +++ b/net/batman-adv/sysfs.c | |||
| @@ -25,8 +25,8 @@ | |||
| 25 | #include <linux/fs.h> | 25 | #include <linux/fs.h> |
| 26 | #include <linux/if.h> | 26 | #include <linux/if.h> |
| 27 | #include <linux/if_vlan.h> | 27 | #include <linux/if_vlan.h> |
| 28 | #include <linux/kref.h> | ||
| 29 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
| 29 | #include <linux/kref.h> | ||
| 30 | #include <linux/netdevice.h> | 30 | #include <linux/netdevice.h> |
| 31 | #include <linux/printk.h> | 31 | #include <linux/printk.h> |
| 32 | #include <linux/rculist.h> | 32 | #include <linux/rculist.h> |
| @@ -38,11 +38,12 @@ | |||
| 38 | #include <linux/string.h> | 38 | #include <linux/string.h> |
| 39 | #include <linux/stringify.h> | 39 | #include <linux/stringify.h> |
| 40 | 40 | ||
| 41 | #include "bridge_loop_avoidance.h" | ||
| 41 | #include "distributed-arp-table.h" | 42 | #include "distributed-arp-table.h" |
| 42 | #include "gateway_client.h" | 43 | #include "gateway_client.h" |
| 43 | #include "gateway_common.h" | 44 | #include "gateway_common.h" |
| 44 | #include "bridge_loop_avoidance.h" | ||
| 45 | #include "hard-interface.h" | 45 | #include "hard-interface.h" |
| 46 | #include "log.h" | ||
| 46 | #include "network-coding.h" | 47 | #include "network-coding.h" |
| 47 | #include "packet.h" | 48 | #include "packet.h" |
| 48 | #include "soft-interface.h" | 49 | #include "soft-interface.h" |
| @@ -411,7 +412,7 @@ static ssize_t batadv_show_bat_algo(struct kobject *kobj, | |||
| 411 | { | 412 | { |
| 412 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); | 413 | struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
| 413 | 414 | ||
| 414 | return sprintf(buff, "%s\n", bat_priv->bat_algo_ops->name); | 415 | return sprintf(buff, "%s\n", bat_priv->algo_ops->name); |
| 415 | } | 416 | } |
| 416 | 417 | ||
| 417 | static void batadv_post_gw_reselect(struct net_device *net_dev) | 418 | static void batadv_post_gw_reselect(struct net_device *net_dev) |
diff --git a/net/batman-adv/tp_meter.c b/net/batman-adv/tp_meter.c new file mode 100644 index 000000000000..2333777f919d --- /dev/null +++ b/net/batman-adv/tp_meter.c | |||
| @@ -0,0 +1,1507 @@ | |||
| 1 | /* Copyright (C) 2012-2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Edo Monticelli, Antonio Quartulli | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "tp_meter.h" | ||
| 19 | #include "main.h" | ||
| 20 | |||
| 21 | #include <linux/atomic.h> | ||
| 22 | #include <linux/bug.h> | ||
| 23 | #include <linux/byteorder/generic.h> | ||
| 24 | #include <linux/cache.h> | ||
| 25 | #include <linux/compiler.h> | ||
| 26 | #include <linux/device.h> | ||
| 27 | #include <linux/etherdevice.h> | ||
| 28 | #include <linux/fs.h> | ||
| 29 | #include <linux/if_ether.h> | ||
| 30 | #include <linux/jiffies.h> | ||
| 31 | #include <linux/kernel.h> | ||
| 32 | #include <linux/kref.h> | ||
| 33 | #include <linux/kthread.h> | ||
| 34 | #include <linux/list.h> | ||
| 35 | #include <linux/netdevice.h> | ||
| 36 | #include <linux/param.h> | ||
| 37 | #include <linux/printk.h> | ||
| 38 | #include <linux/random.h> | ||
| 39 | #include <linux/rculist.h> | ||
| 40 | #include <linux/rcupdate.h> | ||
| 41 | #include <linux/sched.h> | ||
| 42 | #include <linux/skbuff.h> | ||
| 43 | #include <linux/slab.h> | ||
| 44 | #include <linux/spinlock.h> | ||
| 45 | #include <linux/stddef.h> | ||
| 46 | #include <linux/string.h> | ||
| 47 | #include <linux/timer.h> | ||
| 48 | #include <linux/wait.h> | ||
| 49 | #include <linux/workqueue.h> | ||
| 50 | #include <uapi/linux/batman_adv.h> | ||
| 51 | |||
| 52 | #include "hard-interface.h" | ||
| 53 | #include "log.h" | ||
| 54 | #include "netlink.h" | ||
| 55 | #include "originator.h" | ||
| 56 | #include "packet.h" | ||
| 57 | #include "send.h" | ||
| 58 | |||
| 59 | /** | ||
| 60 | * BATADV_TP_DEF_TEST_LENGTH - Default test length if not specified by the user | ||
| 61 | * in milliseconds | ||
| 62 | */ | ||
| 63 | #define BATADV_TP_DEF_TEST_LENGTH 10000 | ||
| 64 | |||
| 65 | /** | ||
| 66 | * BATADV_TP_AWND - Advertised window by the receiver (in bytes) | ||
| 67 | */ | ||
| 68 | #define BATADV_TP_AWND 0x20000000 | ||
| 69 | |||
| 70 | /** | ||
| 71 | * BATADV_TP_RECV_TIMEOUT - Receiver activity timeout. If the receiver does not | ||
| 72 | * get anything for such amount of milliseconds, the connection is killed | ||
| 73 | */ | ||
| 74 | #define BATADV_TP_RECV_TIMEOUT 1000 | ||
| 75 | |||
| 76 | /** | ||
| 77 | * BATADV_TP_MAX_RTO - Maximum sender timeout. If the sender RTO gets beyond | ||
| 78 | * such amound of milliseconds, the receiver is considered unreachable and the | ||
| 79 | * connection is killed | ||
| 80 | */ | ||
| 81 | #define BATADV_TP_MAX_RTO 30000 | ||
| 82 | |||
| 83 | /** | ||
| 84 | * BATADV_TP_FIRST_SEQ - First seqno of each session. The number is rather high | ||
| 85 | * in order to immediately trigger a wrap around (test purposes) | ||
| 86 | */ | ||
| 87 | #define BATADV_TP_FIRST_SEQ ((u32)-1 - 2000) | ||
| 88 | |||
| 89 | /** | ||
| 90 | * BATADV_TP_PLEN - length of the payload (data after the batadv_unicast header) | ||
| 91 | * to simulate | ||
| 92 | */ | ||
| 93 | #define BATADV_TP_PLEN (BATADV_TP_PACKET_LEN - ETH_HLEN - \ | ||
| 94 | sizeof(struct batadv_unicast_packet)) | ||
| 95 | |||
| 96 | static u8 batadv_tp_prerandom[4096] __read_mostly; | ||
| 97 | |||
| 98 | /** | ||
| 99 | * batadv_tp_session_cookie - generate session cookie based on session ids | ||
| 100 | * @session: TP session identifier | ||
| 101 | * @icmp_uid: icmp pseudo uid of the tp session | ||
| 102 | * | ||
| 103 | * Return: 32 bit tp_meter session cookie | ||
| 104 | */ | ||
| 105 | static u32 batadv_tp_session_cookie(const u8 session[2], u8 icmp_uid) | ||
| 106 | { | ||
| 107 | u32 cookie; | ||
| 108 | |||
| 109 | cookie = icmp_uid << 16; | ||
| 110 | cookie |= session[0] << 8; | ||
| 111 | cookie |= session[1]; | ||
| 112 | |||
| 113 | return cookie; | ||
| 114 | } | ||
| 115 | |||
| 116 | /** | ||
| 117 | * batadv_tp_cwnd - compute the new cwnd size | ||
| 118 | * @base: base cwnd size value | ||
| 119 | * @increment: the value to add to base to get the new size | ||
| 120 | * @min: minumim cwnd value (usually MSS) | ||
| 121 | * | ||
| 122 | * Return the new cwnd size and ensures it does not exceed the Advertised | ||
| 123 | * Receiver Window size. It is wrap around safe. | ||
| 124 | * For details refer to Section 3.1 of RFC5681 | ||
| 125 | * | ||
| 126 | * Return: new congestion window size in bytes | ||
| 127 | */ | ||
| 128 | static u32 batadv_tp_cwnd(u32 base, u32 increment, u32 min) | ||
| 129 | { | ||
| 130 | u32 new_size = base + increment; | ||
| 131 | |||
| 132 | /* check for wrap-around */ | ||
| 133 | if (new_size < base) | ||
| 134 | new_size = (u32)ULONG_MAX; | ||
| 135 | |||
| 136 | new_size = min_t(u32, new_size, BATADV_TP_AWND); | ||
| 137 | |||
| 138 | return max_t(u32, new_size, min); | ||
| 139 | } | ||
| 140 | |||
| 141 | /** | ||
| 142 | * batadv_tp_updated_cwnd - update the Congestion Windows | ||
| 143 | * @tp_vars: the private data of the current TP meter session | ||
| 144 | * @mss: maximum segment size of transmission | ||
| 145 | * | ||
| 146 | * 1) if the session is in Slow Start, the CWND has to be increased by 1 | ||
| 147 | * MSS every unique received ACK | ||
| 148 | * 2) if the session is in Congestion Avoidance, the CWND has to be | ||
| 149 | * increased by MSS * MSS / CWND for every unique received ACK | ||
| 150 | */ | ||
| 151 | static void batadv_tp_update_cwnd(struct batadv_tp_vars *tp_vars, u32 mss) | ||
| 152 | { | ||
| 153 | spin_lock_bh(&tp_vars->cwnd_lock); | ||
| 154 | |||
| 155 | /* slow start... */ | ||
| 156 | if (tp_vars->cwnd <= tp_vars->ss_threshold) { | ||
| 157 | tp_vars->dec_cwnd = 0; | ||
| 158 | tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd, mss, mss); | ||
| 159 | spin_unlock_bh(&tp_vars->cwnd_lock); | ||
| 160 | return; | ||
| 161 | } | ||
| 162 | |||
| 163 | /* increment CWND at least of 1 (section 3.1 of RFC5681) */ | ||
| 164 | tp_vars->dec_cwnd += max_t(u32, 1U << 3, | ||
| 165 | ((mss * mss) << 6) / (tp_vars->cwnd << 3)); | ||
| 166 | if (tp_vars->dec_cwnd < (mss << 3)) { | ||
| 167 | spin_unlock_bh(&tp_vars->cwnd_lock); | ||
| 168 | return; | ||
| 169 | } | ||
| 170 | |||
| 171 | tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd, mss, mss); | ||
| 172 | tp_vars->dec_cwnd = 0; | ||
| 173 | |||
| 174 | spin_unlock_bh(&tp_vars->cwnd_lock); | ||
| 175 | } | ||
| 176 | |||
| 177 | /** | ||
| 178 | * batadv_tp_update_rto - calculate new retransmission timeout | ||
| 179 | * @tp_vars: the private data of the current TP meter session | ||
| 180 | * @new_rtt: new roundtrip time in msec | ||
| 181 | */ | ||
| 182 | static void batadv_tp_update_rto(struct batadv_tp_vars *tp_vars, | ||
| 183 | u32 new_rtt) | ||
| 184 | { | ||
| 185 | long m = new_rtt; | ||
| 186 | |||
| 187 | /* RTT update | ||
| 188 | * Details in Section 2.2 and 2.3 of RFC6298 | ||
| 189 | * | ||
| 190 | * It's tricky to understand. Don't lose hair please. | ||
| 191 | * Inspired by tcp_rtt_estimator() tcp_input.c | ||
| 192 | */ | ||
| 193 | if (tp_vars->srtt != 0) { | ||
| 194 | m -= (tp_vars->srtt >> 3); /* m is now error in rtt est */ | ||
| 195 | tp_vars->srtt += m; /* rtt = 7/8 srtt + 1/8 new */ | ||
| 196 | if (m < 0) | ||
| 197 | m = -m; | ||
| 198 | |||
| 199 | m -= (tp_vars->rttvar >> 2); | ||
| 200 | tp_vars->rttvar += m; /* mdev ~= 3/4 rttvar + 1/4 new */ | ||
| 201 | } else { | ||
| 202 | /* first measure getting in */ | ||
| 203 | tp_vars->srtt = m << 3; /* take the measured time to be srtt */ | ||
| 204 | tp_vars->rttvar = m << 1; /* new_rtt / 2 */ | ||
| 205 | } | ||
| 206 | |||
| 207 | /* rto = srtt + 4 * rttvar. | ||
| 208 | * rttvar is scaled by 4, therefore doesn't need to be multiplied | ||
| 209 | */ | ||
| 210 | tp_vars->rto = (tp_vars->srtt >> 3) + tp_vars->rttvar; | ||
| 211 | } | ||
| 212 | |||
| 213 | /** | ||
| 214 | * batadv_tp_batctl_notify - send client status result to client | ||
| 215 | * @reason: reason for tp meter session stop | ||
| 216 | * @dst: destination of tp_meter session | ||
| 217 | * @bat_priv: the bat priv with all the soft interface information | ||
| 218 | * @start_time: start of transmission in jiffies | ||
| 219 | * @total_sent: bytes acked to the receiver | ||
| 220 | * @cookie: cookie of tp_meter session | ||
| 221 | */ | ||
| 222 | static void batadv_tp_batctl_notify(enum batadv_tp_meter_reason reason, | ||
| 223 | const u8 *dst, struct batadv_priv *bat_priv, | ||
| 224 | unsigned long start_time, u64 total_sent, | ||
| 225 | u32 cookie) | ||
| 226 | { | ||
| 227 | u32 test_time; | ||
| 228 | u8 result; | ||
| 229 | u32 total_bytes; | ||
| 230 | |||
| 231 | if (!batadv_tp_is_error(reason)) { | ||
| 232 | result = BATADV_TP_REASON_COMPLETE; | ||
| 233 | test_time = jiffies_to_msecs(jiffies - start_time); | ||
| 234 | total_bytes = total_sent; | ||
| 235 | } else { | ||
| 236 | result = reason; | ||
| 237 | test_time = 0; | ||
| 238 | total_bytes = 0; | ||
| 239 | } | ||
| 240 | |||
| 241 | batadv_netlink_tpmeter_notify(bat_priv, dst, result, test_time, | ||
| 242 | total_bytes, cookie); | ||
| 243 | } | ||
| 244 | |||
| 245 | /** | ||
| 246 | * batadv_tp_batctl_error_notify - send client error result to client | ||
| 247 | * @reason: reason for tp meter session stop | ||
| 248 | * @dst: destination of tp_meter session | ||
| 249 | * @bat_priv: the bat priv with all the soft interface information | ||
| 250 | * @cookie: cookie of tp_meter session | ||
| 251 | */ | ||
| 252 | static void batadv_tp_batctl_error_notify(enum batadv_tp_meter_reason reason, | ||
| 253 | const u8 *dst, | ||
| 254 | struct batadv_priv *bat_priv, | ||
| 255 | u32 cookie) | ||
| 256 | { | ||
| 257 | batadv_tp_batctl_notify(reason, dst, bat_priv, 0, 0, cookie); | ||
| 258 | } | ||
| 259 | |||
| 260 | /** | ||
| 261 | * batadv_tp_list_find - find a tp_vars object in the global list | ||
| 262 | * @bat_priv: the bat priv with all the soft interface information | ||
| 263 | * @dst: the other endpoint MAC address to look for | ||
| 264 | * | ||
| 265 | * Look for a tp_vars object matching dst as end_point and return it after | ||
| 266 | * having incremented the refcounter. Return NULL is not found | ||
| 267 | * | ||
| 268 | * Return: matching tp_vars or NULL when no tp_vars with @dst was found | ||
| 269 | */ | ||
| 270 | static struct batadv_tp_vars *batadv_tp_list_find(struct batadv_priv *bat_priv, | ||
| 271 | const u8 *dst) | ||
| 272 | { | ||
| 273 | struct batadv_tp_vars *pos, *tp_vars = NULL; | ||
| 274 | |||
| 275 | rcu_read_lock(); | ||
| 276 | hlist_for_each_entry_rcu(pos, &bat_priv->tp_list, list) { | ||
| 277 | if (!batadv_compare_eth(pos->other_end, dst)) | ||
| 278 | continue; | ||
| 279 | |||
| 280 | /* most of the time this function is invoked during the normal | ||
| 281 | * process..it makes sens to pay more when the session is | ||
| 282 | * finished and to speed the process up during the measurement | ||
| 283 | */ | ||
| 284 | if (unlikely(!kref_get_unless_zero(&pos->refcount))) | ||
| 285 | continue; | ||
| 286 | |||
| 287 | tp_vars = pos; | ||
| 288 | break; | ||
| 289 | } | ||
| 290 | rcu_read_unlock(); | ||
| 291 | |||
| 292 | return tp_vars; | ||
| 293 | } | ||
| 294 | |||
| 295 | /** | ||
| 296 | * batadv_tp_list_find_session - find tp_vars session object in the global list | ||
| 297 | * @bat_priv: the bat priv with all the soft interface information | ||
| 298 | * @dst: the other endpoint MAC address to look for | ||
| 299 | * @session: session identifier | ||
| 300 | * | ||
| 301 | * Look for a tp_vars object matching dst as end_point, session as tp meter | ||
| 302 | * session and return it after having incremented the refcounter. Return NULL | ||
| 303 | * is not found | ||
| 304 | * | ||
| 305 | * Return: matching tp_vars or NULL when no tp_vars was found | ||
| 306 | */ | ||
| 307 | static struct batadv_tp_vars * | ||
| 308 | batadv_tp_list_find_session(struct batadv_priv *bat_priv, const u8 *dst, | ||
| 309 | const u8 *session) | ||
| 310 | { | ||
| 311 | struct batadv_tp_vars *pos, *tp_vars = NULL; | ||
| 312 | |||
| 313 | rcu_read_lock(); | ||
| 314 | hlist_for_each_entry_rcu(pos, &bat_priv->tp_list, list) { | ||
| 315 | if (!batadv_compare_eth(pos->other_end, dst)) | ||
| 316 | continue; | ||
| 317 | |||
| 318 | if (memcmp(pos->session, session, sizeof(pos->session)) != 0) | ||
| 319 | continue; | ||
| 320 | |||
| 321 | /* most of the time this function is invoked during the normal | ||
| 322 | * process..it makes sense to pay more when the session is | ||
| 323 | * finished and to speed the process up during the measurement | ||
| 324 | */ | ||
| 325 | if (unlikely(!kref_get_unless_zero(&pos->refcount))) | ||
| 326 | continue; | ||
| 327 | |||
| 328 | tp_vars = pos; | ||
| 329 | break; | ||
| 330 | } | ||
| 331 | rcu_read_unlock(); | ||
| 332 | |||
| 333 | return tp_vars; | ||
| 334 | } | ||
| 335 | |||
| 336 | /** | ||
| 337 | * batadv_tp_vars_release - release batadv_tp_vars from lists and queue for | ||
| 338 | * free after rcu grace period | ||
| 339 | * @ref: kref pointer of the batadv_tp_vars | ||
| 340 | */ | ||
| 341 | static void batadv_tp_vars_release(struct kref *ref) | ||
| 342 | { | ||
| 343 | struct batadv_tp_vars *tp_vars; | ||
| 344 | struct batadv_tp_unacked *un, *safe; | ||
| 345 | |||
| 346 | tp_vars = container_of(ref, struct batadv_tp_vars, refcount); | ||
| 347 | |||
| 348 | /* lock should not be needed because this object is now out of any | ||
| 349 | * context! | ||
| 350 | */ | ||
| 351 | spin_lock_bh(&tp_vars->unacked_lock); | ||
| 352 | list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) { | ||
| 353 | list_del(&un->list); | ||
| 354 | kfree(un); | ||
| 355 | } | ||
| 356 | spin_unlock_bh(&tp_vars->unacked_lock); | ||
| 357 | |||
| 358 | kfree_rcu(tp_vars, rcu); | ||
| 359 | } | ||
| 360 | |||
| 361 | /** | ||
| 362 | * batadv_tp_vars_put - decrement the batadv_tp_vars refcounter and possibly | ||
| 363 | * release it | ||
| 364 | * @tp_vars: the private data of the current TP meter session to be free'd | ||
| 365 | */ | ||
| 366 | static void batadv_tp_vars_put(struct batadv_tp_vars *tp_vars) | ||
| 367 | { | ||
| 368 | kref_put(&tp_vars->refcount, batadv_tp_vars_release); | ||
| 369 | } | ||
| 370 | |||
| 371 | /** | ||
| 372 | * batadv_tp_sender_cleanup - cleanup sender data and drop and timer | ||
| 373 | * @bat_priv: the bat priv with all the soft interface information | ||
| 374 | * @tp_vars: the private data of the current TP meter session to cleanup | ||
| 375 | */ | ||
| 376 | static void batadv_tp_sender_cleanup(struct batadv_priv *bat_priv, | ||
| 377 | struct batadv_tp_vars *tp_vars) | ||
| 378 | { | ||
| 379 | cancel_delayed_work(&tp_vars->finish_work); | ||
| 380 | |||
| 381 | spin_lock_bh(&tp_vars->bat_priv->tp_list_lock); | ||
| 382 | hlist_del_rcu(&tp_vars->list); | ||
| 383 | spin_unlock_bh(&tp_vars->bat_priv->tp_list_lock); | ||
| 384 | |||
| 385 | /* drop list reference */ | ||
| 386 | batadv_tp_vars_put(tp_vars); | ||
| 387 | |||
| 388 | atomic_dec(&tp_vars->bat_priv->tp_num); | ||
| 389 | |||
| 390 | /* kill the timer and remove its reference */ | ||
| 391 | del_timer_sync(&tp_vars->timer); | ||
| 392 | /* the worker might have rearmed itself therefore we kill it again. Note | ||
| 393 | * that if the worker should run again before invoking the following | ||
| 394 | * del_timer(), it would not re-arm itself once again because the status | ||
| 395 | * is OFF now | ||
| 396 | */ | ||
| 397 | del_timer(&tp_vars->timer); | ||
| 398 | batadv_tp_vars_put(tp_vars); | ||
| 399 | } | ||
| 400 | |||
| 401 | /** | ||
| 402 | * batadv_tp_sender_end - print info about ended session and inform client | ||
| 403 | * @bat_priv: the bat priv with all the soft interface information | ||
| 404 | * @tp_vars: the private data of the current TP meter session | ||
| 405 | */ | ||
| 406 | static void batadv_tp_sender_end(struct batadv_priv *bat_priv, | ||
| 407 | struct batadv_tp_vars *tp_vars) | ||
| 408 | { | ||
| 409 | u32 session_cookie; | ||
| 410 | |||
| 411 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 412 | "Test towards %pM finished..shutting down (reason=%d)\n", | ||
| 413 | tp_vars->other_end, tp_vars->reason); | ||
| 414 | |||
| 415 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 416 | "Last timing stats: SRTT=%ums RTTVAR=%ums RTO=%ums\n", | ||
| 417 | tp_vars->srtt >> 3, tp_vars->rttvar >> 2, tp_vars->rto); | ||
| 418 | |||
| 419 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 420 | "Final values: cwnd=%u ss_threshold=%u\n", | ||
| 421 | tp_vars->cwnd, tp_vars->ss_threshold); | ||
| 422 | |||
| 423 | session_cookie = batadv_tp_session_cookie(tp_vars->session, | ||
| 424 | tp_vars->icmp_uid); | ||
| 425 | |||
| 426 | batadv_tp_batctl_notify(tp_vars->reason, | ||
| 427 | tp_vars->other_end, | ||
| 428 | bat_priv, | ||
| 429 | tp_vars->start_time, | ||
| 430 | atomic64_read(&tp_vars->tot_sent), | ||
| 431 | session_cookie); | ||
| 432 | } | ||
| 433 | |||
| 434 | /** | ||
| 435 | * batadv_tp_sender_shutdown - let sender thread/timer stop gracefully | ||
| 436 | * @tp_vars: the private data of the current TP meter session | ||
| 437 | * @reason: reason for tp meter session stop | ||
| 438 | */ | ||
| 439 | static void batadv_tp_sender_shutdown(struct batadv_tp_vars *tp_vars, | ||
| 440 | enum batadv_tp_meter_reason reason) | ||
| 441 | { | ||
| 442 | if (!atomic_dec_and_test(&tp_vars->sending)) | ||
| 443 | return; | ||
| 444 | |||
| 445 | tp_vars->reason = reason; | ||
| 446 | } | ||
| 447 | |||
| 448 | /** | ||
| 449 | * batadv_tp_sender_finish - stop sender session after test_length was reached | ||
| 450 | * @work: delayed work reference of the related tp_vars | ||
| 451 | */ | ||
| 452 | static void batadv_tp_sender_finish(struct work_struct *work) | ||
| 453 | { | ||
| 454 | struct delayed_work *delayed_work; | ||
| 455 | struct batadv_tp_vars *tp_vars; | ||
| 456 | |||
| 457 | delayed_work = to_delayed_work(work); | ||
| 458 | tp_vars = container_of(delayed_work, struct batadv_tp_vars, | ||
| 459 | finish_work); | ||
| 460 | |||
| 461 | batadv_tp_sender_shutdown(tp_vars, BATADV_TP_REASON_COMPLETE); | ||
| 462 | } | ||
| 463 | |||
| 464 | /** | ||
| 465 | * batadv_tp_reset_sender_timer - reschedule the sender timer | ||
| 466 | * @tp_vars: the private TP meter data for this session | ||
| 467 | * | ||
| 468 | * Reschedule the timer using tp_vars->rto as delay | ||
| 469 | */ | ||
| 470 | static void batadv_tp_reset_sender_timer(struct batadv_tp_vars *tp_vars) | ||
| 471 | { | ||
| 472 | /* most of the time this function is invoked while normal packet | ||
| 473 | * reception... | ||
| 474 | */ | ||
| 475 | if (unlikely(atomic_read(&tp_vars->sending) == 0)) | ||
| 476 | /* timer ref will be dropped in batadv_tp_sender_cleanup */ | ||
| 477 | return; | ||
| 478 | |||
| 479 | mod_timer(&tp_vars->timer, jiffies + msecs_to_jiffies(tp_vars->rto)); | ||
| 480 | } | ||
| 481 | |||
| 482 | /** | ||
| 483 | * batadv_tp_sender_timeout - timer that fires in case of packet loss | ||
| 484 | * @arg: address of the related tp_vars | ||
| 485 | * | ||
| 486 | * If fired it means that there was packet loss. | ||
| 487 | * Switch to Slow Start, set the ss_threshold to half of the current cwnd and | ||
| 488 | * reset the cwnd to 3*MSS | ||
| 489 | */ | ||
| 490 | static void batadv_tp_sender_timeout(unsigned long arg) | ||
| 491 | { | ||
| 492 | struct batadv_tp_vars *tp_vars = (struct batadv_tp_vars *)arg; | ||
| 493 | struct batadv_priv *bat_priv = tp_vars->bat_priv; | ||
| 494 | |||
| 495 | if (atomic_read(&tp_vars->sending) == 0) | ||
| 496 | return; | ||
| 497 | |||
| 498 | /* if the user waited long enough...shutdown the test */ | ||
| 499 | if (unlikely(tp_vars->rto >= BATADV_TP_MAX_RTO)) { | ||
| 500 | batadv_tp_sender_shutdown(tp_vars, | ||
| 501 | BATADV_TP_REASON_DST_UNREACHABLE); | ||
| 502 | return; | ||
| 503 | } | ||
| 504 | |||
| 505 | /* RTO exponential backoff | ||
| 506 | * Details in Section 5.5 of RFC6298 | ||
| 507 | */ | ||
| 508 | tp_vars->rto <<= 1; | ||
| 509 | |||
| 510 | spin_lock_bh(&tp_vars->cwnd_lock); | ||
| 511 | |||
| 512 | tp_vars->ss_threshold = tp_vars->cwnd >> 1; | ||
| 513 | if (tp_vars->ss_threshold < BATADV_TP_PLEN * 2) | ||
| 514 | tp_vars->ss_threshold = BATADV_TP_PLEN * 2; | ||
| 515 | |||
| 516 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 517 | "Meter: RTO fired during test towards %pM! cwnd=%u new ss_thr=%u, resetting last_sent to %u\n", | ||
| 518 | tp_vars->other_end, tp_vars->cwnd, tp_vars->ss_threshold, | ||
| 519 | atomic_read(&tp_vars->last_acked)); | ||
| 520 | |||
| 521 | tp_vars->cwnd = BATADV_TP_PLEN * 3; | ||
| 522 | |||
| 523 | spin_unlock_bh(&tp_vars->cwnd_lock); | ||
| 524 | |||
| 525 | /* resend the non-ACKed packets.. */ | ||
| 526 | tp_vars->last_sent = atomic_read(&tp_vars->last_acked); | ||
| 527 | wake_up(&tp_vars->more_bytes); | ||
| 528 | |||
| 529 | batadv_tp_reset_sender_timer(tp_vars); | ||
| 530 | } | ||
| 531 | |||
| 532 | /** | ||
| 533 | * batadv_tp_fill_prerandom - Fill buffer with prefetched random bytes | ||
| 534 | * @tp_vars: the private TP meter data for this session | ||
| 535 | * @buf: Buffer to fill with bytes | ||
| 536 | * @nbytes: amount of pseudorandom bytes | ||
| 537 | */ | ||
| 538 | static void batadv_tp_fill_prerandom(struct batadv_tp_vars *tp_vars, | ||
| 539 | u8 *buf, size_t nbytes) | ||
| 540 | { | ||
| 541 | u32 local_offset; | ||
| 542 | size_t bytes_inbuf; | ||
| 543 | size_t to_copy; | ||
| 544 | size_t pos = 0; | ||
| 545 | |||
| 546 | spin_lock_bh(&tp_vars->prerandom_lock); | ||
| 547 | local_offset = tp_vars->prerandom_offset; | ||
| 548 | tp_vars->prerandom_offset += nbytes; | ||
| 549 | tp_vars->prerandom_offset %= sizeof(batadv_tp_prerandom); | ||
| 550 | spin_unlock_bh(&tp_vars->prerandom_lock); | ||
| 551 | |||
| 552 | while (nbytes) { | ||
| 553 | local_offset %= sizeof(batadv_tp_prerandom); | ||
| 554 | bytes_inbuf = sizeof(batadv_tp_prerandom) - local_offset; | ||
| 555 | to_copy = min(nbytes, bytes_inbuf); | ||
| 556 | |||
| 557 | memcpy(&buf[pos], &batadv_tp_prerandom[local_offset], to_copy); | ||
| 558 | pos += to_copy; | ||
| 559 | nbytes -= to_copy; | ||
| 560 | local_offset = 0; | ||
| 561 | } | ||
| 562 | } | ||
| 563 | |||
| 564 | /** | ||
| 565 | * batadv_tp_send_msg - send a single message | ||
| 566 | * @tp_vars: the private TP meter data for this session | ||
| 567 | * @src: source mac address | ||
| 568 | * @orig_node: the originator of the destination | ||
| 569 | * @seqno: sequence number of this packet | ||
| 570 | * @len: length of the entire packet | ||
| 571 | * @session: session identifier | ||
| 572 | * @uid: local ICMP "socket" index | ||
| 573 | * @timestamp: timestamp in jiffies which is replied in ack | ||
| 574 | * | ||
| 575 | * Create and send a single TP Meter message. | ||
| 576 | * | ||
| 577 | * Return: 0 on success, BATADV_TP_REASON_DST_UNREACHABLE if the destination is | ||
| 578 | * not reachable, BATADV_TP_REASON_MEMORY_ERROR if the packet couldn't be | ||
| 579 | * allocated | ||
| 580 | */ | ||
| 581 | static int batadv_tp_send_msg(struct batadv_tp_vars *tp_vars, const u8 *src, | ||
| 582 | struct batadv_orig_node *orig_node, | ||
| 583 | u32 seqno, size_t len, const u8 *session, | ||
| 584 | int uid, u32 timestamp) | ||
| 585 | { | ||
| 586 | struct batadv_icmp_tp_packet *icmp; | ||
| 587 | struct sk_buff *skb; | ||
| 588 | int r; | ||
| 589 | u8 *data; | ||
| 590 | size_t data_len; | ||
| 591 | |||
| 592 | skb = netdev_alloc_skb_ip_align(NULL, len + ETH_HLEN); | ||
| 593 | if (unlikely(!skb)) | ||
| 594 | return BATADV_TP_REASON_MEMORY_ERROR; | ||
| 595 | |||
| 596 | skb_reserve(skb, ETH_HLEN); | ||
| 597 | icmp = (struct batadv_icmp_tp_packet *)skb_put(skb, sizeof(*icmp)); | ||
| 598 | |||
| 599 | /* fill the icmp header */ | ||
| 600 | ether_addr_copy(icmp->dst, orig_node->orig); | ||
| 601 | ether_addr_copy(icmp->orig, src); | ||
| 602 | icmp->version = BATADV_COMPAT_VERSION; | ||
| 603 | icmp->packet_type = BATADV_ICMP; | ||
| 604 | icmp->ttl = BATADV_TTL; | ||
| 605 | icmp->msg_type = BATADV_TP; | ||
| 606 | icmp->uid = uid; | ||
| 607 | |||
| 608 | icmp->subtype = BATADV_TP_MSG; | ||
| 609 | memcpy(icmp->session, session, sizeof(icmp->session)); | ||
| 610 | icmp->seqno = htonl(seqno); | ||
| 611 | icmp->timestamp = htonl(timestamp); | ||
| 612 | |||
| 613 | data_len = len - sizeof(*icmp); | ||
| 614 | data = (u8 *)skb_put(skb, data_len); | ||
| 615 | batadv_tp_fill_prerandom(tp_vars, data, data_len); | ||
| 616 | |||
| 617 | r = batadv_send_skb_to_orig(skb, orig_node, NULL); | ||
| 618 | if (r == -1) | ||
| 619 | kfree_skb(skb); | ||
| 620 | |||
| 621 | if (r == NET_XMIT_SUCCESS) | ||
| 622 | return 0; | ||
| 623 | |||
| 624 | return BATADV_TP_REASON_CANT_SEND; | ||
| 625 | } | ||
| 626 | |||
| 627 | /** | ||
| 628 | * batadv_tp_recv_ack - ACK receiving function | ||
| 629 | * @bat_priv: the bat priv with all the soft interface information | ||
| 630 | * @skb: the buffer containing the received packet | ||
| 631 | * | ||
| 632 | * Process a received TP ACK packet | ||
| 633 | */ | ||
| 634 | static void batadv_tp_recv_ack(struct batadv_priv *bat_priv, | ||
| 635 | const struct sk_buff *skb) | ||
| 636 | { | ||
| 637 | struct batadv_hard_iface *primary_if = NULL; | ||
| 638 | struct batadv_orig_node *orig_node = NULL; | ||
| 639 | const struct batadv_icmp_tp_packet *icmp; | ||
| 640 | struct batadv_tp_vars *tp_vars; | ||
| 641 | size_t packet_len, mss; | ||
| 642 | u32 rtt, recv_ack, cwnd; | ||
| 643 | unsigned char *dev_addr; | ||
| 644 | |||
| 645 | packet_len = BATADV_TP_PLEN; | ||
| 646 | mss = BATADV_TP_PLEN; | ||
| 647 | packet_len += sizeof(struct batadv_unicast_packet); | ||
| 648 | |||
| 649 | icmp = (struct batadv_icmp_tp_packet *)skb->data; | ||
| 650 | |||
| 651 | /* find the tp_vars */ | ||
| 652 | tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig, | ||
| 653 | icmp->session); | ||
| 654 | if (unlikely(!tp_vars)) | ||
| 655 | return; | ||
| 656 | |||
| 657 | if (unlikely(atomic_read(&tp_vars->sending) == 0)) | ||
| 658 | goto out; | ||
| 659 | |||
| 660 | /* old ACK? silently drop it.. */ | ||
| 661 | if (batadv_seq_before(ntohl(icmp->seqno), | ||
| 662 | (u32)atomic_read(&tp_vars->last_acked))) | ||
| 663 | goto out; | ||
| 664 | |||
| 665 | primary_if = batadv_primary_if_get_selected(bat_priv); | ||
| 666 | if (unlikely(!primary_if)) | ||
| 667 | goto out; | ||
| 668 | |||
| 669 | orig_node = batadv_orig_hash_find(bat_priv, icmp->orig); | ||
| 670 | if (unlikely(!orig_node)) | ||
| 671 | goto out; | ||
| 672 | |||
| 673 | /* update RTO with the new sampled RTT, if any */ | ||
| 674 | rtt = jiffies_to_msecs(jiffies) - ntohl(icmp->timestamp); | ||
| 675 | if (icmp->timestamp && rtt) | ||
| 676 | batadv_tp_update_rto(tp_vars, rtt); | ||
| 677 | |||
| 678 | /* ACK for new data... reset the timer */ | ||
| 679 | batadv_tp_reset_sender_timer(tp_vars); | ||
| 680 | |||
| 681 | recv_ack = ntohl(icmp->seqno); | ||
| 682 | |||
| 683 | /* check if this ACK is a duplicate */ | ||
| 684 | if (atomic_read(&tp_vars->last_acked) == recv_ack) { | ||
| 685 | atomic_inc(&tp_vars->dup_acks); | ||
| 686 | if (atomic_read(&tp_vars->dup_acks) != 3) | ||
| 687 | goto out; | ||
| 688 | |||
| 689 | if (recv_ack >= tp_vars->recover) | ||
| 690 | goto out; | ||
| 691 | |||
| 692 | /* if this is the third duplicate ACK do Fast Retransmit */ | ||
| 693 | batadv_tp_send_msg(tp_vars, primary_if->net_dev->dev_addr, | ||
| 694 | orig_node, recv_ack, packet_len, | ||
| 695 | icmp->session, icmp->uid, | ||
| 696 | jiffies_to_msecs(jiffies)); | ||
| 697 | |||
| 698 | spin_lock_bh(&tp_vars->cwnd_lock); | ||
| 699 | |||
| 700 | /* Fast Recovery */ | ||
| 701 | tp_vars->fast_recovery = true; | ||
| 702 | /* Set recover to the last outstanding seqno when Fast Recovery | ||
| 703 | * is entered. RFC6582, Section 3.2, step 1 | ||
| 704 | */ | ||
| 705 | tp_vars->recover = tp_vars->last_sent; | ||
| 706 | tp_vars->ss_threshold = tp_vars->cwnd >> 1; | ||
| 707 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 708 | "Meter: Fast Recovery, (cur cwnd=%u) ss_thr=%u last_sent=%u recv_ack=%u\n", | ||
| 709 | tp_vars->cwnd, tp_vars->ss_threshold, | ||
| 710 | tp_vars->last_sent, recv_ack); | ||
| 711 | tp_vars->cwnd = batadv_tp_cwnd(tp_vars->ss_threshold, 3 * mss, | ||
| 712 | mss); | ||
| 713 | tp_vars->dec_cwnd = 0; | ||
| 714 | tp_vars->last_sent = recv_ack; | ||
| 715 | |||
| 716 | spin_unlock_bh(&tp_vars->cwnd_lock); | ||
| 717 | } else { | ||
| 718 | /* count the acked data */ | ||
| 719 | atomic64_add(recv_ack - atomic_read(&tp_vars->last_acked), | ||
| 720 | &tp_vars->tot_sent); | ||
| 721 | /* reset the duplicate ACKs counter */ | ||
| 722 | atomic_set(&tp_vars->dup_acks, 0); | ||
| 723 | |||
| 724 | if (tp_vars->fast_recovery) { | ||
| 725 | /* partial ACK */ | ||
| 726 | if (batadv_seq_before(recv_ack, tp_vars->recover)) { | ||
| 727 | /* this is another hole in the window. React | ||
| 728 | * immediately as specified by NewReno (see | ||
| 729 | * Section 3.2 of RFC6582 for details) | ||
| 730 | */ | ||
| 731 | dev_addr = primary_if->net_dev->dev_addr; | ||
| 732 | batadv_tp_send_msg(tp_vars, dev_addr, | ||
| 733 | orig_node, recv_ack, | ||
| 734 | packet_len, icmp->session, | ||
| 735 | icmp->uid, | ||
| 736 | jiffies_to_msecs(jiffies)); | ||
| 737 | tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd, | ||
| 738 | mss, mss); | ||
| 739 | } else { | ||
| 740 | tp_vars->fast_recovery = false; | ||
| 741 | /* set cwnd to the value of ss_threshold at the | ||
| 742 | * moment that Fast Recovery was entered. | ||
| 743 | * RFC6582, Section 3.2, step 3 | ||
| 744 | */ | ||
| 745 | cwnd = batadv_tp_cwnd(tp_vars->ss_threshold, 0, | ||
| 746 | mss); | ||
| 747 | tp_vars->cwnd = cwnd; | ||
| 748 | } | ||
| 749 | goto move_twnd; | ||
| 750 | } | ||
| 751 | |||
| 752 | if (recv_ack - atomic_read(&tp_vars->last_acked) >= mss) | ||
| 753 | batadv_tp_update_cwnd(tp_vars, mss); | ||
| 754 | move_twnd: | ||
| 755 | /* move the Transmit Window */ | ||
| 756 | atomic_set(&tp_vars->last_acked, recv_ack); | ||
| 757 | } | ||
| 758 | |||
| 759 | wake_up(&tp_vars->more_bytes); | ||
| 760 | out: | ||
| 761 | if (likely(primary_if)) | ||
| 762 | batadv_hardif_put(primary_if); | ||
| 763 | if (likely(orig_node)) | ||
| 764 | batadv_orig_node_put(orig_node); | ||
| 765 | if (likely(tp_vars)) | ||
| 766 | batadv_tp_vars_put(tp_vars); | ||
| 767 | } | ||
| 768 | |||
| 769 | /** | ||
| 770 | * batadv_tp_avail - check if congestion window is not full | ||
| 771 | * @tp_vars: the private data of the current TP meter session | ||
| 772 | * @payload_len: size of the payload of a single message | ||
| 773 | * | ||
| 774 | * Return: true when congestion window is not full, false otherwise | ||
| 775 | */ | ||
| 776 | static bool batadv_tp_avail(struct batadv_tp_vars *tp_vars, | ||
| 777 | size_t payload_len) | ||
| 778 | { | ||
| 779 | u32 win_left, win_limit; | ||
| 780 | |||
| 781 | win_limit = atomic_read(&tp_vars->last_acked) + tp_vars->cwnd; | ||
| 782 | win_left = win_limit - tp_vars->last_sent; | ||
| 783 | |||
| 784 | return win_left >= payload_len; | ||
| 785 | } | ||
| 786 | |||
| 787 | /** | ||
| 788 | * batadv_tp_wait_available - wait until congestion window becomes free or | ||
| 789 | * timeout is reached | ||
| 790 | * @tp_vars: the private data of the current TP meter session | ||
| 791 | * @plen: size of the payload of a single message | ||
| 792 | * | ||
| 793 | * Return: 0 if the condition evaluated to false after the timeout elapsed, | ||
| 794 | * 1 if the condition evaluated to true after the timeout elapsed, the | ||
| 795 | * remaining jiffies (at least 1) if the condition evaluated to true before | ||
| 796 | * the timeout elapsed, or -ERESTARTSYS if it was interrupted by a signal. | ||
| 797 | */ | ||
| 798 | static int batadv_tp_wait_available(struct batadv_tp_vars *tp_vars, size_t plen) | ||
| 799 | { | ||
| 800 | int ret; | ||
| 801 | |||
| 802 | ret = wait_event_interruptible_timeout(tp_vars->more_bytes, | ||
| 803 | batadv_tp_avail(tp_vars, plen), | ||
| 804 | HZ / 10); | ||
| 805 | |||
| 806 | return ret; | ||
| 807 | } | ||
| 808 | |||
| 809 | /** | ||
| 810 | * batadv_tp_send - main sending thread of a tp meter session | ||
| 811 | * @arg: address of the related tp_vars | ||
| 812 | * | ||
| 813 | * Return: nothing, this function never returns | ||
| 814 | */ | ||
| 815 | static int batadv_tp_send(void *arg) | ||
| 816 | { | ||
| 817 | struct batadv_tp_vars *tp_vars = arg; | ||
| 818 | struct batadv_priv *bat_priv = tp_vars->bat_priv; | ||
| 819 | struct batadv_hard_iface *primary_if = NULL; | ||
| 820 | struct batadv_orig_node *orig_node = NULL; | ||
| 821 | size_t payload_len, packet_len; | ||
| 822 | int err = 0; | ||
| 823 | |||
| 824 | if (unlikely(tp_vars->role != BATADV_TP_SENDER)) { | ||
| 825 | err = BATADV_TP_REASON_DST_UNREACHABLE; | ||
| 826 | tp_vars->reason = err; | ||
| 827 | goto out; | ||
| 828 | } | ||
| 829 | |||
| 830 | orig_node = batadv_orig_hash_find(bat_priv, tp_vars->other_end); | ||
| 831 | if (unlikely(!orig_node)) { | ||
| 832 | err = BATADV_TP_REASON_DST_UNREACHABLE; | ||
| 833 | tp_vars->reason = err; | ||
| 834 | goto out; | ||
| 835 | } | ||
| 836 | |||
| 837 | primary_if = batadv_primary_if_get_selected(bat_priv); | ||
| 838 | if (unlikely(!primary_if)) { | ||
| 839 | err = BATADV_TP_REASON_DST_UNREACHABLE; | ||
| 840 | goto out; | ||
| 841 | } | ||
| 842 | |||
| 843 | /* assume that all the hard_interfaces have a correctly | ||
| 844 | * configured MTU, so use the soft_iface MTU as MSS. | ||
| 845 | * This might not be true and in that case the fragmentation | ||
| 846 | * should be used. | ||
| 847 | * Now, try to send the packet as it is | ||
| 848 | */ | ||
| 849 | payload_len = BATADV_TP_PLEN; | ||
| 850 | BUILD_BUG_ON(sizeof(struct batadv_icmp_tp_packet) > BATADV_TP_PLEN); | ||
| 851 | |||
| 852 | batadv_tp_reset_sender_timer(tp_vars); | ||
| 853 | |||
| 854 | /* queue the worker in charge of terminating the test */ | ||
| 855 | queue_delayed_work(batadv_event_workqueue, &tp_vars->finish_work, | ||
| 856 | msecs_to_jiffies(tp_vars->test_length)); | ||
| 857 | |||
| 858 | while (atomic_read(&tp_vars->sending) != 0) { | ||
| 859 | if (unlikely(!batadv_tp_avail(tp_vars, payload_len))) { | ||
| 860 | batadv_tp_wait_available(tp_vars, payload_len); | ||
| 861 | continue; | ||
| 862 | } | ||
| 863 | |||
| 864 | /* to emulate normal unicast traffic, add to the payload len | ||
| 865 | * the size of the unicast header | ||
| 866 | */ | ||
| 867 | packet_len = payload_len + sizeof(struct batadv_unicast_packet); | ||
| 868 | |||
| 869 | err = batadv_tp_send_msg(tp_vars, primary_if->net_dev->dev_addr, | ||
| 870 | orig_node, tp_vars->last_sent, | ||
| 871 | packet_len, | ||
| 872 | tp_vars->session, tp_vars->icmp_uid, | ||
| 873 | jiffies_to_msecs(jiffies)); | ||
| 874 | |||
| 875 | /* something went wrong during the preparation/transmission */ | ||
| 876 | if (unlikely(err && err != BATADV_TP_REASON_CANT_SEND)) { | ||
| 877 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 878 | "Meter: batadv_tp_send() cannot send packets (%d)\n", | ||
| 879 | err); | ||
| 880 | /* ensure nobody else tries to stop the thread now */ | ||
| 881 | if (atomic_dec_and_test(&tp_vars->sending)) | ||
| 882 | tp_vars->reason = err; | ||
| 883 | break; | ||
| 884 | } | ||
| 885 | |||
| 886 | /* right-shift the TWND */ | ||
| 887 | if (!err) | ||
| 888 | tp_vars->last_sent += payload_len; | ||
| 889 | |||
| 890 | cond_resched(); | ||
| 891 | } | ||
| 892 | |||
| 893 | out: | ||
| 894 | if (likely(primary_if)) | ||
| 895 | batadv_hardif_put(primary_if); | ||
| 896 | if (likely(orig_node)) | ||
| 897 | batadv_orig_node_put(orig_node); | ||
| 898 | |||
| 899 | batadv_tp_sender_end(bat_priv, tp_vars); | ||
| 900 | batadv_tp_sender_cleanup(bat_priv, tp_vars); | ||
| 901 | |||
| 902 | batadv_tp_vars_put(tp_vars); | ||
| 903 | |||
| 904 | do_exit(0); | ||
| 905 | } | ||
| 906 | |||
| 907 | /** | ||
| 908 | * batadv_tp_start_kthread - start new thread which manages the tp meter sender | ||
| 909 | * @tp_vars: the private data of the current TP meter session | ||
| 910 | */ | ||
| 911 | static void batadv_tp_start_kthread(struct batadv_tp_vars *tp_vars) | ||
| 912 | { | ||
| 913 | struct task_struct *kthread; | ||
| 914 | struct batadv_priv *bat_priv = tp_vars->bat_priv; | ||
| 915 | u32 session_cookie; | ||
| 916 | |||
| 917 | kref_get(&tp_vars->refcount); | ||
| 918 | kthread = kthread_create(batadv_tp_send, tp_vars, "kbatadv_tp_meter"); | ||
| 919 | if (IS_ERR(kthread)) { | ||
| 920 | session_cookie = batadv_tp_session_cookie(tp_vars->session, | ||
| 921 | tp_vars->icmp_uid); | ||
| 922 | pr_err("batadv: cannot create tp meter kthread\n"); | ||
| 923 | batadv_tp_batctl_error_notify(BATADV_TP_REASON_MEMORY_ERROR, | ||
| 924 | tp_vars->other_end, | ||
| 925 | bat_priv, session_cookie); | ||
| 926 | |||
| 927 | /* drop reserved reference for kthread */ | ||
| 928 | batadv_tp_vars_put(tp_vars); | ||
| 929 | |||
| 930 | /* cleanup of failed tp meter variables */ | ||
| 931 | batadv_tp_sender_cleanup(bat_priv, tp_vars); | ||
| 932 | return; | ||
| 933 | } | ||
| 934 | |||
| 935 | wake_up_process(kthread); | ||
| 936 | } | ||
| 937 | |||
| 938 | /** | ||
| 939 | * batadv_tp_start - start a new tp meter session | ||
| 940 | * @bat_priv: the bat priv with all the soft interface information | ||
| 941 | * @dst: the receiver MAC address | ||
| 942 | * @test_length: test length in milliseconds | ||
| 943 | * @cookie: session cookie | ||
| 944 | */ | ||
| 945 | void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, | ||
| 946 | u32 test_length, u32 *cookie) | ||
| 947 | { | ||
| 948 | struct batadv_tp_vars *tp_vars; | ||
| 949 | u8 session_id[2]; | ||
| 950 | u8 icmp_uid; | ||
| 951 | u32 session_cookie; | ||
| 952 | |||
| 953 | get_random_bytes(session_id, sizeof(session_id)); | ||
| 954 | get_random_bytes(&icmp_uid, 1); | ||
| 955 | session_cookie = batadv_tp_session_cookie(session_id, icmp_uid); | ||
| 956 | *cookie = session_cookie; | ||
| 957 | |||
| 958 | /* look for an already existing test towards this node */ | ||
| 959 | spin_lock_bh(&bat_priv->tp_list_lock); | ||
| 960 | tp_vars = batadv_tp_list_find(bat_priv, dst); | ||
| 961 | if (tp_vars) { | ||
| 962 | spin_unlock_bh(&bat_priv->tp_list_lock); | ||
| 963 | batadv_tp_vars_put(tp_vars); | ||
| 964 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 965 | "Meter: test to or from the same node already ongoing, aborting\n"); | ||
| 966 | batadv_tp_batctl_error_notify(BATADV_TP_REASON_ALREADY_ONGOING, | ||
| 967 | dst, bat_priv, session_cookie); | ||
| 968 | return; | ||
| 969 | } | ||
| 970 | |||
| 971 | if (!atomic_add_unless(&bat_priv->tp_num, 1, BATADV_TP_MAX_NUM)) { | ||
| 972 | spin_unlock_bh(&bat_priv->tp_list_lock); | ||
| 973 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 974 | "Meter: too many ongoing sessions, aborting (SEND)\n"); | ||
| 975 | batadv_tp_batctl_error_notify(BATADV_TP_REASON_TOO_MANY, dst, | ||
| 976 | bat_priv, session_cookie); | ||
| 977 | return; | ||
| 978 | } | ||
| 979 | |||
| 980 | tp_vars = kmalloc(sizeof(*tp_vars), GFP_ATOMIC); | ||
| 981 | if (!tp_vars) { | ||
| 982 | spin_unlock_bh(&bat_priv->tp_list_lock); | ||
| 983 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 984 | "Meter: batadv_tp_start cannot allocate list elements\n"); | ||
| 985 | batadv_tp_batctl_error_notify(BATADV_TP_REASON_MEMORY_ERROR, | ||
| 986 | dst, bat_priv, session_cookie); | ||
| 987 | return; | ||
| 988 | } | ||
| 989 | |||
| 990 | /* initialize tp_vars */ | ||
| 991 | ether_addr_copy(tp_vars->other_end, dst); | ||
| 992 | kref_init(&tp_vars->refcount); | ||
| 993 | tp_vars->role = BATADV_TP_SENDER; | ||
| 994 | atomic_set(&tp_vars->sending, 1); | ||
| 995 | memcpy(tp_vars->session, session_id, sizeof(session_id)); | ||
| 996 | tp_vars->icmp_uid = icmp_uid; | ||
| 997 | |||
| 998 | tp_vars->last_sent = BATADV_TP_FIRST_SEQ; | ||
| 999 | atomic_set(&tp_vars->last_acked, BATADV_TP_FIRST_SEQ); | ||
| 1000 | tp_vars->fast_recovery = false; | ||
| 1001 | tp_vars->recover = BATADV_TP_FIRST_SEQ; | ||
| 1002 | |||
| 1003 | /* initialise the CWND to 3*MSS (Section 3.1 in RFC5681). | ||
| 1004 | * For batman-adv the MSS is the size of the payload received by the | ||
| 1005 | * soft_interface, hence its MTU | ||
| 1006 | */ | ||
| 1007 | tp_vars->cwnd = BATADV_TP_PLEN * 3; | ||
| 1008 | /* at the beginning initialise the SS threshold to the biggest possible | ||
| 1009 | * window size, hence the AWND size | ||
| 1010 | */ | ||
| 1011 | tp_vars->ss_threshold = BATADV_TP_AWND; | ||
| 1012 | |||
| 1013 | /* RTO initial value is 3 seconds. | ||
| 1014 | * Details in Section 2.1 of RFC6298 | ||
| 1015 | */ | ||
| 1016 | tp_vars->rto = 1000; | ||
| 1017 | tp_vars->srtt = 0; | ||
| 1018 | tp_vars->rttvar = 0; | ||
| 1019 | |||
| 1020 | atomic64_set(&tp_vars->tot_sent, 0); | ||
| 1021 | |||
| 1022 | kref_get(&tp_vars->refcount); | ||
| 1023 | setup_timer(&tp_vars->timer, batadv_tp_sender_timeout, | ||
| 1024 | (unsigned long)tp_vars); | ||
| 1025 | |||
| 1026 | tp_vars->bat_priv = bat_priv; | ||
| 1027 | tp_vars->start_time = jiffies; | ||
| 1028 | |||
| 1029 | init_waitqueue_head(&tp_vars->more_bytes); | ||
| 1030 | |||
| 1031 | spin_lock_init(&tp_vars->unacked_lock); | ||
| 1032 | INIT_LIST_HEAD(&tp_vars->unacked_list); | ||
| 1033 | |||
| 1034 | spin_lock_init(&tp_vars->cwnd_lock); | ||
| 1035 | |||
| 1036 | tp_vars->prerandom_offset = 0; | ||
| 1037 | spin_lock_init(&tp_vars->prerandom_lock); | ||
| 1038 | |||
| 1039 | kref_get(&tp_vars->refcount); | ||
| 1040 | hlist_add_head_rcu(&tp_vars->list, &bat_priv->tp_list); | ||
| 1041 | spin_unlock_bh(&bat_priv->tp_list_lock); | ||
| 1042 | |||
| 1043 | tp_vars->test_length = test_length; | ||
| 1044 | if (!tp_vars->test_length) | ||
| 1045 | tp_vars->test_length = BATADV_TP_DEF_TEST_LENGTH; | ||
| 1046 | |||
| 1047 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 1048 | "Meter: starting throughput meter towards %pM (length=%ums)\n", | ||
| 1049 | dst, test_length); | ||
| 1050 | |||
| 1051 | /* init work item for finished tp tests */ | ||
| 1052 | INIT_DELAYED_WORK(&tp_vars->finish_work, batadv_tp_sender_finish); | ||
| 1053 | |||
| 1054 | /* start tp kthread. This way the write() call issued from userspace can | ||
| 1055 | * happily return and avoid to block | ||
| 1056 | */ | ||
| 1057 | batadv_tp_start_kthread(tp_vars); | ||
| 1058 | |||
| 1059 | /* don't return reference to new tp_vars */ | ||
| 1060 | batadv_tp_vars_put(tp_vars); | ||
| 1061 | } | ||
| 1062 | |||
| 1063 | /** | ||
| 1064 | * batadv_tp_stop - stop currently running tp meter session | ||
| 1065 | * @bat_priv: the bat priv with all the soft interface information | ||
| 1066 | * @dst: the receiver MAC address | ||
| 1067 | * @return_value: reason for tp meter session stop | ||
| 1068 | */ | ||
| 1069 | void batadv_tp_stop(struct batadv_priv *bat_priv, const u8 *dst, | ||
| 1070 | u8 return_value) | ||
| 1071 | { | ||
| 1072 | struct batadv_orig_node *orig_node; | ||
| 1073 | struct batadv_tp_vars *tp_vars; | ||
| 1074 | |||
| 1075 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 1076 | "Meter: stopping test towards %pM\n", dst); | ||
| 1077 | |||
| 1078 | orig_node = batadv_orig_hash_find(bat_priv, dst); | ||
| 1079 | if (!orig_node) | ||
| 1080 | return; | ||
| 1081 | |||
| 1082 | tp_vars = batadv_tp_list_find(bat_priv, orig_node->orig); | ||
| 1083 | if (!tp_vars) { | ||
| 1084 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 1085 | "Meter: trying to interrupt an already over connection\n"); | ||
| 1086 | goto out; | ||
| 1087 | } | ||
| 1088 | |||
| 1089 | batadv_tp_sender_shutdown(tp_vars, return_value); | ||
| 1090 | batadv_tp_vars_put(tp_vars); | ||
| 1091 | out: | ||
| 1092 | batadv_orig_node_put(orig_node); | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | /** | ||
| 1096 | * batadv_tp_reset_receiver_timer - reset the receiver shutdown timer | ||
| 1097 | * @tp_vars: the private data of the current TP meter session | ||
| 1098 | * | ||
| 1099 | * start the receiver shutdown timer or reset it if already started | ||
| 1100 | */ | ||
| 1101 | static void batadv_tp_reset_receiver_timer(struct batadv_tp_vars *tp_vars) | ||
| 1102 | { | ||
| 1103 | mod_timer(&tp_vars->timer, | ||
| 1104 | jiffies + msecs_to_jiffies(BATADV_TP_RECV_TIMEOUT)); | ||
| 1105 | } | ||
| 1106 | |||
| 1107 | /** | ||
| 1108 | * batadv_tp_receiver_shutdown - stop a tp meter receiver when timeout is | ||
| 1109 | * reached without received ack | ||
| 1110 | * @arg: address of the related tp_vars | ||
| 1111 | */ | ||
| 1112 | static void batadv_tp_receiver_shutdown(unsigned long arg) | ||
| 1113 | { | ||
| 1114 | struct batadv_tp_vars *tp_vars = (struct batadv_tp_vars *)arg; | ||
| 1115 | struct batadv_tp_unacked *un, *safe; | ||
| 1116 | struct batadv_priv *bat_priv; | ||
| 1117 | |||
| 1118 | bat_priv = tp_vars->bat_priv; | ||
| 1119 | |||
| 1120 | /* if there is recent activity rearm the timer */ | ||
| 1121 | if (!batadv_has_timed_out(tp_vars->last_recv_time, | ||
| 1122 | BATADV_TP_RECV_TIMEOUT)) { | ||
| 1123 | /* reset the receiver shutdown timer */ | ||
| 1124 | batadv_tp_reset_receiver_timer(tp_vars); | ||
| 1125 | return; | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 1129 | "Shutting down for inactivity (more than %dms) from %pM\n", | ||
| 1130 | BATADV_TP_RECV_TIMEOUT, tp_vars->other_end); | ||
| 1131 | |||
| 1132 | spin_lock_bh(&tp_vars->bat_priv->tp_list_lock); | ||
| 1133 | hlist_del_rcu(&tp_vars->list); | ||
| 1134 | spin_unlock_bh(&tp_vars->bat_priv->tp_list_lock); | ||
| 1135 | |||
| 1136 | /* drop list reference */ | ||
| 1137 | batadv_tp_vars_put(tp_vars); | ||
| 1138 | |||
| 1139 | atomic_dec(&bat_priv->tp_num); | ||
| 1140 | |||
| 1141 | spin_lock_bh(&tp_vars->unacked_lock); | ||
| 1142 | list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) { | ||
| 1143 | list_del(&un->list); | ||
| 1144 | kfree(un); | ||
| 1145 | } | ||
| 1146 | spin_unlock_bh(&tp_vars->unacked_lock); | ||
| 1147 | |||
| 1148 | /* drop reference of timer */ | ||
| 1149 | batadv_tp_vars_put(tp_vars); | ||
| 1150 | } | ||
| 1151 | |||
| 1152 | /** | ||
| 1153 | * batadv_tp_send_ack - send an ACK packet | ||
| 1154 | * @bat_priv: the bat priv with all the soft interface information | ||
| 1155 | * @dst: the mac address of the destination originator | ||
| 1156 | * @seq: the sequence number to ACK | ||
| 1157 | * @timestamp: the timestamp to echo back in the ACK | ||
| 1158 | * @session: session identifier | ||
| 1159 | * @socket_index: local ICMP socket identifier | ||
| 1160 | * | ||
| 1161 | * Return: 0 on success, a positive integer representing the reason of the | ||
| 1162 | * failure otherwise | ||
| 1163 | */ | ||
| 1164 | static int batadv_tp_send_ack(struct batadv_priv *bat_priv, const u8 *dst, | ||
| 1165 | u32 seq, __be32 timestamp, const u8 *session, | ||
| 1166 | int socket_index) | ||
| 1167 | { | ||
| 1168 | struct batadv_hard_iface *primary_if = NULL; | ||
| 1169 | struct batadv_orig_node *orig_node; | ||
| 1170 | struct batadv_icmp_tp_packet *icmp; | ||
| 1171 | struct sk_buff *skb; | ||
| 1172 | int r, ret; | ||
| 1173 | |||
| 1174 | orig_node = batadv_orig_hash_find(bat_priv, dst); | ||
| 1175 | if (unlikely(!orig_node)) { | ||
| 1176 | ret = BATADV_TP_REASON_DST_UNREACHABLE; | ||
| 1177 | goto out; | ||
| 1178 | } | ||
| 1179 | |||
| 1180 | primary_if = batadv_primary_if_get_selected(bat_priv); | ||
| 1181 | if (unlikely(!primary_if)) { | ||
| 1182 | ret = BATADV_TP_REASON_DST_UNREACHABLE; | ||
| 1183 | goto out; | ||
| 1184 | } | ||
| 1185 | |||
| 1186 | skb = netdev_alloc_skb_ip_align(NULL, sizeof(*icmp) + ETH_HLEN); | ||
| 1187 | if (unlikely(!skb)) { | ||
| 1188 | ret = BATADV_TP_REASON_MEMORY_ERROR; | ||
| 1189 | goto out; | ||
| 1190 | } | ||
| 1191 | |||
| 1192 | skb_reserve(skb, ETH_HLEN); | ||
| 1193 | icmp = (struct batadv_icmp_tp_packet *)skb_put(skb, sizeof(*icmp)); | ||
| 1194 | icmp->packet_type = BATADV_ICMP; | ||
| 1195 | icmp->version = BATADV_COMPAT_VERSION; | ||
| 1196 | icmp->ttl = BATADV_TTL; | ||
| 1197 | icmp->msg_type = BATADV_TP; | ||
| 1198 | ether_addr_copy(icmp->dst, orig_node->orig); | ||
| 1199 | ether_addr_copy(icmp->orig, primary_if->net_dev->dev_addr); | ||
| 1200 | icmp->uid = socket_index; | ||
| 1201 | |||
| 1202 | icmp->subtype = BATADV_TP_ACK; | ||
| 1203 | memcpy(icmp->session, session, sizeof(icmp->session)); | ||
| 1204 | icmp->seqno = htonl(seq); | ||
| 1205 | icmp->timestamp = timestamp; | ||
| 1206 | |||
| 1207 | /* send the ack */ | ||
| 1208 | r = batadv_send_skb_to_orig(skb, orig_node, NULL); | ||
| 1209 | if (r == -1) | ||
| 1210 | kfree_skb(skb); | ||
| 1211 | |||
| 1212 | if (unlikely(r < 0) || (r == NET_XMIT_DROP)) { | ||
| 1213 | ret = BATADV_TP_REASON_DST_UNREACHABLE; | ||
| 1214 | goto out; | ||
| 1215 | } | ||
| 1216 | ret = 0; | ||
| 1217 | |||
| 1218 | out: | ||
| 1219 | if (likely(orig_node)) | ||
| 1220 | batadv_orig_node_put(orig_node); | ||
| 1221 | if (likely(primary_if)) | ||
| 1222 | batadv_hardif_put(primary_if); | ||
| 1223 | |||
| 1224 | return ret; | ||
| 1225 | } | ||
| 1226 | |||
| 1227 | /** | ||
| 1228 | * batadv_tp_handle_out_of_order - store an out of order packet | ||
| 1229 | * @tp_vars: the private data of the current TP meter session | ||
| 1230 | * @skb: the buffer containing the received packet | ||
| 1231 | * | ||
| 1232 | * Store the out of order packet in the unacked list for late processing. This | ||
| 1233 | * packets are kept in this list so that they can be ACKed at once as soon as | ||
| 1234 | * all the previous packets have been received | ||
| 1235 | * | ||
| 1236 | * Return: true if the packed has been successfully processed, false otherwise | ||
| 1237 | */ | ||
| 1238 | static bool batadv_tp_handle_out_of_order(struct batadv_tp_vars *tp_vars, | ||
| 1239 | const struct sk_buff *skb) | ||
| 1240 | { | ||
| 1241 | const struct batadv_icmp_tp_packet *icmp; | ||
| 1242 | struct batadv_tp_unacked *un, *new; | ||
| 1243 | u32 payload_len; | ||
| 1244 | bool added = false; | ||
| 1245 | |||
| 1246 | new = kmalloc(sizeof(*new), GFP_ATOMIC); | ||
| 1247 | if (unlikely(!new)) | ||
| 1248 | return false; | ||
| 1249 | |||
| 1250 | icmp = (struct batadv_icmp_tp_packet *)skb->data; | ||
| 1251 | |||
| 1252 | new->seqno = ntohl(icmp->seqno); | ||
| 1253 | payload_len = skb->len - sizeof(struct batadv_unicast_packet); | ||
| 1254 | new->len = payload_len; | ||
| 1255 | |||
| 1256 | spin_lock_bh(&tp_vars->unacked_lock); | ||
| 1257 | /* if the list is empty immediately attach this new object */ | ||
| 1258 | if (list_empty(&tp_vars->unacked_list)) { | ||
| 1259 | list_add(&new->list, &tp_vars->unacked_list); | ||
| 1260 | goto out; | ||
| 1261 | } | ||
| 1262 | |||
| 1263 | /* otherwise loop over the list and either drop the packet because this | ||
| 1264 | * is a duplicate or store it at the right position. | ||
| 1265 | * | ||
| 1266 | * The iteration is done in the reverse way because it is likely that | ||
| 1267 | * the last received packet (the one being processed now) has a bigger | ||
| 1268 | * seqno than all the others already stored. | ||
| 1269 | */ | ||
| 1270 | list_for_each_entry_reverse(un, &tp_vars->unacked_list, list) { | ||
| 1271 | /* check for duplicates */ | ||
| 1272 | if (new->seqno == un->seqno) { | ||
| 1273 | if (new->len > un->len) | ||
| 1274 | un->len = new->len; | ||
| 1275 | kfree(new); | ||
| 1276 | added = true; | ||
| 1277 | break; | ||
| 1278 | } | ||
| 1279 | |||
| 1280 | /* look for the right position */ | ||
| 1281 | if (batadv_seq_before(new->seqno, un->seqno)) | ||
| 1282 | continue; | ||
| 1283 | |||
| 1284 | /* as soon as an entry having a bigger seqno is found, the new | ||
| 1285 | * one is attached _after_ it. In this way the list is kept in | ||
| 1286 | * ascending order | ||
| 1287 | */ | ||
| 1288 | list_add_tail(&new->list, &un->list); | ||
| 1289 | added = true; | ||
| 1290 | break; | ||
| 1291 | } | ||
| 1292 | |||
| 1293 | /* received packet with smallest seqno out of order; add it to front */ | ||
| 1294 | if (!added) | ||
| 1295 | list_add(&new->list, &tp_vars->unacked_list); | ||
| 1296 | |||
| 1297 | out: | ||
| 1298 | spin_unlock_bh(&tp_vars->unacked_lock); | ||
| 1299 | |||
| 1300 | return true; | ||
| 1301 | } | ||
| 1302 | |||
| 1303 | /** | ||
| 1304 | * batadv_tp_ack_unordered - update number received bytes in current stream | ||
| 1305 | * without gaps | ||
| 1306 | * @tp_vars: the private data of the current TP meter session | ||
| 1307 | */ | ||
| 1308 | static void batadv_tp_ack_unordered(struct batadv_tp_vars *tp_vars) | ||
| 1309 | { | ||
| 1310 | struct batadv_tp_unacked *un, *safe; | ||
| 1311 | u32 to_ack; | ||
| 1312 | |||
| 1313 | /* go through the unacked packet list and possibly ACK them as | ||
| 1314 | * well | ||
| 1315 | */ | ||
| 1316 | spin_lock_bh(&tp_vars->unacked_lock); | ||
| 1317 | list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) { | ||
| 1318 | /* the list is ordered, therefore it is possible to stop as soon | ||
| 1319 | * there is a gap between the last acked seqno and the seqno of | ||
| 1320 | * the packet under inspection | ||
| 1321 | */ | ||
| 1322 | if (batadv_seq_before(tp_vars->last_recv, un->seqno)) | ||
| 1323 | break; | ||
| 1324 | |||
| 1325 | to_ack = un->seqno + un->len - tp_vars->last_recv; | ||
| 1326 | |||
| 1327 | if (batadv_seq_before(tp_vars->last_recv, un->seqno + un->len)) | ||
| 1328 | tp_vars->last_recv += to_ack; | ||
| 1329 | |||
| 1330 | list_del(&un->list); | ||
| 1331 | kfree(un); | ||
| 1332 | } | ||
| 1333 | spin_unlock_bh(&tp_vars->unacked_lock); | ||
| 1334 | } | ||
| 1335 | |||
| 1336 | /** | ||
| 1337 | * batadv_tp_init_recv - return matching or create new receiver tp_vars | ||
| 1338 | * @bat_priv: the bat priv with all the soft interface information | ||
| 1339 | * @icmp: received icmp tp msg | ||
| 1340 | * | ||
| 1341 | * Return: corresponding tp_vars or NULL on errors | ||
| 1342 | */ | ||
| 1343 | static struct batadv_tp_vars * | ||
| 1344 | batadv_tp_init_recv(struct batadv_priv *bat_priv, | ||
| 1345 | const struct batadv_icmp_tp_packet *icmp) | ||
| 1346 | { | ||
| 1347 | struct batadv_tp_vars *tp_vars; | ||
| 1348 | |||
| 1349 | spin_lock_bh(&bat_priv->tp_list_lock); | ||
| 1350 | tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig, | ||
| 1351 | icmp->session); | ||
| 1352 | if (tp_vars) | ||
| 1353 | goto out_unlock; | ||
| 1354 | |||
| 1355 | if (!atomic_add_unless(&bat_priv->tp_num, 1, BATADV_TP_MAX_NUM)) { | ||
| 1356 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 1357 | "Meter: too many ongoing sessions, aborting (RECV)\n"); | ||
| 1358 | goto out_unlock; | ||
| 1359 | } | ||
| 1360 | |||
| 1361 | tp_vars = kmalloc(sizeof(*tp_vars), GFP_ATOMIC); | ||
| 1362 | if (!tp_vars) | ||
| 1363 | goto out_unlock; | ||
| 1364 | |||
| 1365 | ether_addr_copy(tp_vars->other_end, icmp->orig); | ||
| 1366 | tp_vars->role = BATADV_TP_RECEIVER; | ||
| 1367 | memcpy(tp_vars->session, icmp->session, sizeof(tp_vars->session)); | ||
| 1368 | tp_vars->last_recv = BATADV_TP_FIRST_SEQ; | ||
| 1369 | tp_vars->bat_priv = bat_priv; | ||
| 1370 | kref_init(&tp_vars->refcount); | ||
| 1371 | |||
| 1372 | spin_lock_init(&tp_vars->unacked_lock); | ||
| 1373 | INIT_LIST_HEAD(&tp_vars->unacked_list); | ||
| 1374 | |||
| 1375 | kref_get(&tp_vars->refcount); | ||
| 1376 | hlist_add_head_rcu(&tp_vars->list, &bat_priv->tp_list); | ||
| 1377 | |||
| 1378 | kref_get(&tp_vars->refcount); | ||
| 1379 | setup_timer(&tp_vars->timer, batadv_tp_receiver_shutdown, | ||
| 1380 | (unsigned long)tp_vars); | ||
| 1381 | |||
| 1382 | batadv_tp_reset_receiver_timer(tp_vars); | ||
| 1383 | |||
| 1384 | out_unlock: | ||
| 1385 | spin_unlock_bh(&bat_priv->tp_list_lock); | ||
| 1386 | |||
| 1387 | return tp_vars; | ||
| 1388 | } | ||
| 1389 | |||
| 1390 | /** | ||
| 1391 | * batadv_tp_recv_msg - process a single data message | ||
| 1392 | * @bat_priv: the bat priv with all the soft interface information | ||
| 1393 | * @skb: the buffer containing the received packet | ||
| 1394 | * | ||
| 1395 | * Process a received TP MSG packet | ||
| 1396 | */ | ||
| 1397 | static void batadv_tp_recv_msg(struct batadv_priv *bat_priv, | ||
| 1398 | const struct sk_buff *skb) | ||
| 1399 | { | ||
| 1400 | const struct batadv_icmp_tp_packet *icmp; | ||
| 1401 | struct batadv_tp_vars *tp_vars; | ||
| 1402 | size_t packet_size; | ||
| 1403 | u32 seqno; | ||
| 1404 | |||
| 1405 | icmp = (struct batadv_icmp_tp_packet *)skb->data; | ||
| 1406 | |||
| 1407 | seqno = ntohl(icmp->seqno); | ||
| 1408 | /* check if this is the first seqno. This means that if the | ||
| 1409 | * first packet is lost, the tp meter does not work anymore! | ||
| 1410 | */ | ||
| 1411 | if (seqno == BATADV_TP_FIRST_SEQ) { | ||
| 1412 | tp_vars = batadv_tp_init_recv(bat_priv, icmp); | ||
| 1413 | if (!tp_vars) { | ||
| 1414 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 1415 | "Meter: seqno != BATADV_TP_FIRST_SEQ cannot initiate connection\n"); | ||
| 1416 | goto out; | ||
| 1417 | } | ||
| 1418 | } else { | ||
| 1419 | tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig, | ||
| 1420 | icmp->session); | ||
| 1421 | if (!tp_vars) { | ||
| 1422 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 1423 | "Unexpected packet from %pM!\n", | ||
| 1424 | icmp->orig); | ||
| 1425 | goto out; | ||
| 1426 | } | ||
| 1427 | } | ||
| 1428 | |||
| 1429 | if (unlikely(tp_vars->role != BATADV_TP_RECEIVER)) { | ||
| 1430 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 1431 | "Meter: dropping packet: not expected (role=%u)\n", | ||
| 1432 | tp_vars->role); | ||
| 1433 | goto out; | ||
| 1434 | } | ||
| 1435 | |||
| 1436 | tp_vars->last_recv_time = jiffies; | ||
| 1437 | |||
| 1438 | /* if the packet is a duplicate, it may be the case that an ACK has been | ||
| 1439 | * lost. Resend the ACK | ||
| 1440 | */ | ||
| 1441 | if (batadv_seq_before(seqno, tp_vars->last_recv)) | ||
| 1442 | goto send_ack; | ||
| 1443 | |||
| 1444 | /* if the packet is out of order enqueue it */ | ||
| 1445 | if (ntohl(icmp->seqno) != tp_vars->last_recv) { | ||
| 1446 | /* exit immediately (and do not send any ACK) if the packet has | ||
| 1447 | * not been enqueued correctly | ||
| 1448 | */ | ||
| 1449 | if (!batadv_tp_handle_out_of_order(tp_vars, skb)) | ||
| 1450 | goto out; | ||
| 1451 | |||
| 1452 | /* send a duplicate ACK */ | ||
| 1453 | goto send_ack; | ||
| 1454 | } | ||
| 1455 | |||
| 1456 | /* if everything was fine count the ACKed bytes */ | ||
| 1457 | packet_size = skb->len - sizeof(struct batadv_unicast_packet); | ||
| 1458 | tp_vars->last_recv += packet_size; | ||
| 1459 | |||
| 1460 | /* check if this ordered message filled a gap.... */ | ||
| 1461 | batadv_tp_ack_unordered(tp_vars); | ||
| 1462 | |||
| 1463 | send_ack: | ||
| 1464 | /* send the ACK. If the received packet was out of order, the ACK that | ||
| 1465 | * is going to be sent is a duplicate (the sender will count them and | ||
| 1466 | * possibly enter Fast Retransmit as soon as it has reached 3) | ||
| 1467 | */ | ||
| 1468 | batadv_tp_send_ack(bat_priv, icmp->orig, tp_vars->last_recv, | ||
| 1469 | icmp->timestamp, icmp->session, icmp->uid); | ||
| 1470 | out: | ||
| 1471 | if (likely(tp_vars)) | ||
| 1472 | batadv_tp_vars_put(tp_vars); | ||
| 1473 | } | ||
| 1474 | |||
| 1475 | /** | ||
| 1476 | * batadv_tp_meter_recv - main TP Meter receiving function | ||
| 1477 | * @bat_priv: the bat priv with all the soft interface information | ||
| 1478 | * @skb: the buffer containing the received packet | ||
| 1479 | */ | ||
| 1480 | void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb) | ||
| 1481 | { | ||
| 1482 | struct batadv_icmp_tp_packet *icmp; | ||
| 1483 | |||
| 1484 | icmp = (struct batadv_icmp_tp_packet *)skb->data; | ||
| 1485 | |||
| 1486 | switch (icmp->subtype) { | ||
| 1487 | case BATADV_TP_MSG: | ||
| 1488 | batadv_tp_recv_msg(bat_priv, skb); | ||
| 1489 | break; | ||
| 1490 | case BATADV_TP_ACK: | ||
| 1491 | batadv_tp_recv_ack(bat_priv, skb); | ||
| 1492 | break; | ||
| 1493 | default: | ||
| 1494 | batadv_dbg(BATADV_DBG_TP_METER, bat_priv, | ||
| 1495 | "Received unknown TP Metric packet type %u\n", | ||
| 1496 | icmp->subtype); | ||
| 1497 | } | ||
| 1498 | consume_skb(skb); | ||
| 1499 | } | ||
| 1500 | |||
| 1501 | /** | ||
| 1502 | * batadv_tp_meter_init - initialize global tp_meter structures | ||
| 1503 | */ | ||
| 1504 | void batadv_tp_meter_init(void) | ||
| 1505 | { | ||
| 1506 | get_random_bytes(batadv_tp_prerandom, sizeof(batadv_tp_prerandom)); | ||
| 1507 | } | ||
diff --git a/net/batman-adv/tp_meter.h b/net/batman-adv/tp_meter.h new file mode 100644 index 000000000000..ba922c425e56 --- /dev/null +++ b/net/batman-adv/tp_meter.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* Copyright (C) 2012-2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Edo Monticelli, Antonio Quartulli | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef _NET_BATMAN_ADV_TP_METER_H_ | ||
| 19 | #define _NET_BATMAN_ADV_TP_METER_H_ | ||
| 20 | |||
| 21 | #include "main.h" | ||
| 22 | |||
| 23 | #include <linux/types.h> | ||
| 24 | |||
| 25 | struct sk_buff; | ||
| 26 | |||
| 27 | void batadv_tp_meter_init(void); | ||
| 28 | void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, | ||
| 29 | u32 test_length, u32 *cookie); | ||
| 30 | void batadv_tp_stop(struct batadv_priv *bat_priv, const u8 *dst, | ||
| 31 | u8 return_value); | ||
| 32 | void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb); | ||
| 33 | |||
| 34 | #endif /* _NET_BATMAN_ADV_TP_METER_H_ */ | ||
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 0d441aac1ad5..7e6df7a4964a 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c | |||
| @@ -47,10 +47,12 @@ | |||
| 47 | #include "bridge_loop_avoidance.h" | 47 | #include "bridge_loop_avoidance.h" |
| 48 | #include "hard-interface.h" | 48 | #include "hard-interface.h" |
| 49 | #include "hash.h" | 49 | #include "hash.h" |
| 50 | #include "log.h" | ||
| 50 | #include "multicast.h" | 51 | #include "multicast.h" |
| 51 | #include "originator.h" | 52 | #include "originator.h" |
| 52 | #include "packet.h" | 53 | #include "packet.h" |
| 53 | #include "soft-interface.h" | 54 | #include "soft-interface.h" |
| 55 | #include "tvlv.h" | ||
| 54 | 56 | ||
| 55 | /* hash class keys */ | 57 | /* hash class keys */ |
| 56 | static struct lock_class_key batadv_tt_local_hash_lock_class_key; | 58 | static struct lock_class_key batadv_tt_local_hash_lock_class_key; |
| @@ -1545,7 +1547,7 @@ batadv_transtable_best_orig(struct batadv_priv *bat_priv, | |||
| 1545 | struct batadv_tt_global_entry *tt_global_entry) | 1547 | struct batadv_tt_global_entry *tt_global_entry) |
| 1546 | { | 1548 | { |
| 1547 | struct batadv_neigh_node *router, *best_router = NULL; | 1549 | struct batadv_neigh_node *router, *best_router = NULL; |
| 1548 | struct batadv_algo_ops *bao = bat_priv->bat_algo_ops; | 1550 | struct batadv_algo_ops *bao = bat_priv->algo_ops; |
| 1549 | struct hlist_head *head; | 1551 | struct hlist_head *head; |
| 1550 | struct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL; | 1552 | struct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL; |
| 1551 | 1553 | ||
| @@ -1557,8 +1559,8 @@ batadv_transtable_best_orig(struct batadv_priv *bat_priv, | |||
| 1557 | continue; | 1559 | continue; |
| 1558 | 1560 | ||
| 1559 | if (best_router && | 1561 | if (best_router && |
| 1560 | bao->bat_neigh_cmp(router, BATADV_IF_DEFAULT, | 1562 | bao->neigh.cmp(router, BATADV_IF_DEFAULT, best_router, |
| 1561 | best_router, BATADV_IF_DEFAULT) <= 0) { | 1563 | BATADV_IF_DEFAULT) <= 0) { |
| 1562 | batadv_neigh_node_put(router); | 1564 | batadv_neigh_node_put(router); |
| 1563 | continue; | 1565 | continue; |
| 1564 | } | 1566 | } |
diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c new file mode 100644 index 000000000000..3d1cf0fb112d --- /dev/null +++ b/net/batman-adv/tvlv.c | |||
| @@ -0,0 +1,632 @@ | |||
| 1 | /* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Marek Lindner, Simon Wunderlich | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "main.h" | ||
| 19 | |||
| 20 | #include <linux/byteorder/generic.h> | ||
| 21 | #include <linux/etherdevice.h> | ||
| 22 | #include <linux/fs.h> | ||
| 23 | #include <linux/if_ether.h> | ||
| 24 | #include <linux/kernel.h> | ||
| 25 | #include <linux/kref.h> | ||
| 26 | #include <linux/list.h> | ||
| 27 | #include <linux/lockdep.h> | ||
| 28 | #include <linux/netdevice.h> | ||
| 29 | #include <linux/pkt_sched.h> | ||
| 30 | #include <linux/rculist.h> | ||
| 31 | #include <linux/rcupdate.h> | ||
| 32 | #include <linux/skbuff.h> | ||
| 33 | #include <linux/slab.h> | ||
| 34 | #include <linux/spinlock.h> | ||
| 35 | #include <linux/stddef.h> | ||
| 36 | #include <linux/string.h> | ||
| 37 | #include <linux/types.h> | ||
| 38 | |||
| 39 | #include "originator.h" | ||
| 40 | #include "packet.h" | ||
| 41 | #include "send.h" | ||
| 42 | #include "tvlv.h" | ||
| 43 | |||
| 44 | /** | ||
| 45 | * batadv_tvlv_handler_release - release tvlv handler from lists and queue for | ||
| 46 | * free after rcu grace period | ||
| 47 | * @ref: kref pointer of the tvlv | ||
| 48 | */ | ||
| 49 | static void batadv_tvlv_handler_release(struct kref *ref) | ||
| 50 | { | ||
| 51 | struct batadv_tvlv_handler *tvlv_handler; | ||
| 52 | |||
| 53 | tvlv_handler = container_of(ref, struct batadv_tvlv_handler, refcount); | ||
| 54 | kfree_rcu(tvlv_handler, rcu); | ||
| 55 | } | ||
| 56 | |||
| 57 | /** | ||
| 58 | * batadv_tvlv_handler_put - decrement the tvlv container refcounter and | ||
| 59 | * possibly release it | ||
| 60 | * @tvlv_handler: the tvlv handler to free | ||
| 61 | */ | ||
| 62 | static void batadv_tvlv_handler_put(struct batadv_tvlv_handler *tvlv_handler) | ||
| 63 | { | ||
| 64 | kref_put(&tvlv_handler->refcount, batadv_tvlv_handler_release); | ||
| 65 | } | ||
| 66 | |||
| 67 | /** | ||
| 68 | * batadv_tvlv_handler_get - retrieve tvlv handler from the tvlv handler list | ||
| 69 | * based on the provided type and version (both need to match) | ||
| 70 | * @bat_priv: the bat priv with all the soft interface information | ||
| 71 | * @type: tvlv handler type to look for | ||
| 72 | * @version: tvlv handler version to look for | ||
| 73 | * | ||
| 74 | * Return: tvlv handler if found or NULL otherwise. | ||
| 75 | */ | ||
| 76 | static struct batadv_tvlv_handler * | ||
| 77 | batadv_tvlv_handler_get(struct batadv_priv *bat_priv, u8 type, u8 version) | ||
| 78 | { | ||
| 79 | struct batadv_tvlv_handler *tvlv_handler_tmp, *tvlv_handler = NULL; | ||
| 80 | |||
| 81 | rcu_read_lock(); | ||
| 82 | hlist_for_each_entry_rcu(tvlv_handler_tmp, | ||
| 83 | &bat_priv->tvlv.handler_list, list) { | ||
| 84 | if (tvlv_handler_tmp->type != type) | ||
| 85 | continue; | ||
| 86 | |||
| 87 | if (tvlv_handler_tmp->version != version) | ||
| 88 | continue; | ||
| 89 | |||
| 90 | if (!kref_get_unless_zero(&tvlv_handler_tmp->refcount)) | ||
| 91 | continue; | ||
| 92 | |||
| 93 | tvlv_handler = tvlv_handler_tmp; | ||
| 94 | break; | ||
| 95 | } | ||
| 96 | rcu_read_unlock(); | ||
| 97 | |||
| 98 | return tvlv_handler; | ||
| 99 | } | ||
| 100 | |||
| 101 | /** | ||
| 102 | * batadv_tvlv_container_release - release tvlv from lists and free | ||
| 103 | * @ref: kref pointer of the tvlv | ||
| 104 | */ | ||
| 105 | static void batadv_tvlv_container_release(struct kref *ref) | ||
| 106 | { | ||
| 107 | struct batadv_tvlv_container *tvlv; | ||
| 108 | |||
| 109 | tvlv = container_of(ref, struct batadv_tvlv_container, refcount); | ||
| 110 | kfree(tvlv); | ||
| 111 | } | ||
| 112 | |||
| 113 | /** | ||
| 114 | * batadv_tvlv_container_put - decrement the tvlv container refcounter and | ||
| 115 | * possibly release it | ||
| 116 | * @tvlv: the tvlv container to free | ||
| 117 | */ | ||
| 118 | static void batadv_tvlv_container_put(struct batadv_tvlv_container *tvlv) | ||
| 119 | { | ||
| 120 | kref_put(&tvlv->refcount, batadv_tvlv_container_release); | ||
| 121 | } | ||
| 122 | |||
| 123 | /** | ||
| 124 | * batadv_tvlv_container_get - retrieve tvlv container from the tvlv container | ||
| 125 | * list based on the provided type and version (both need to match) | ||
| 126 | * @bat_priv: the bat priv with all the soft interface information | ||
| 127 | * @type: tvlv container type to look for | ||
| 128 | * @version: tvlv container version to look for | ||
| 129 | * | ||
| 130 | * Has to be called with the appropriate locks being acquired | ||
| 131 | * (tvlv.container_list_lock). | ||
| 132 | * | ||
| 133 | * Return: tvlv container if found or NULL otherwise. | ||
| 134 | */ | ||
| 135 | static struct batadv_tvlv_container * | ||
| 136 | batadv_tvlv_container_get(struct batadv_priv *bat_priv, u8 type, u8 version) | ||
| 137 | { | ||
| 138 | struct batadv_tvlv_container *tvlv_tmp, *tvlv = NULL; | ||
| 139 | |||
| 140 | lockdep_assert_held(&bat_priv->tvlv.container_list_lock); | ||
| 141 | |||
| 142 | hlist_for_each_entry(tvlv_tmp, &bat_priv->tvlv.container_list, list) { | ||
| 143 | if (tvlv_tmp->tvlv_hdr.type != type) | ||
| 144 | continue; | ||
| 145 | |||
| 146 | if (tvlv_tmp->tvlv_hdr.version != version) | ||
| 147 | continue; | ||
| 148 | |||
| 149 | kref_get(&tvlv_tmp->refcount); | ||
| 150 | tvlv = tvlv_tmp; | ||
| 151 | break; | ||
| 152 | } | ||
| 153 | |||
| 154 | return tvlv; | ||
| 155 | } | ||
| 156 | |||
| 157 | /** | ||
| 158 | * batadv_tvlv_container_list_size - calculate the size of the tvlv container | ||
| 159 | * list entries | ||
| 160 | * @bat_priv: the bat priv with all the soft interface information | ||
| 161 | * | ||
| 162 | * Has to be called with the appropriate locks being acquired | ||
| 163 | * (tvlv.container_list_lock). | ||
| 164 | * | ||
| 165 | * Return: size of all currently registered tvlv containers in bytes. | ||
| 166 | */ | ||
| 167 | static u16 batadv_tvlv_container_list_size(struct batadv_priv *bat_priv) | ||
| 168 | { | ||
| 169 | struct batadv_tvlv_container *tvlv; | ||
| 170 | u16 tvlv_len = 0; | ||
| 171 | |||
| 172 | lockdep_assert_held(&bat_priv->tvlv.container_list_lock); | ||
| 173 | |||
| 174 | hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) { | ||
| 175 | tvlv_len += sizeof(struct batadv_tvlv_hdr); | ||
| 176 | tvlv_len += ntohs(tvlv->tvlv_hdr.len); | ||
| 177 | } | ||
| 178 | |||
| 179 | return tvlv_len; | ||
| 180 | } | ||
| 181 | |||
| 182 | /** | ||
| 183 | * batadv_tvlv_container_remove - remove tvlv container from the tvlv container | ||
| 184 | * list | ||
| 185 | * @bat_priv: the bat priv with all the soft interface information | ||
| 186 | * @tvlv: the to be removed tvlv container | ||
| 187 | * | ||
| 188 | * Has to be called with the appropriate locks being acquired | ||
| 189 | * (tvlv.container_list_lock). | ||
| 190 | */ | ||
| 191 | static void batadv_tvlv_container_remove(struct batadv_priv *bat_priv, | ||
| 192 | struct batadv_tvlv_container *tvlv) | ||
| 193 | { | ||
| 194 | lockdep_assert_held(&bat_priv->tvlv.container_list_lock); | ||
| 195 | |||
| 196 | if (!tvlv) | ||
| 197 | return; | ||
| 198 | |||
| 199 | hlist_del(&tvlv->list); | ||
| 200 | |||
| 201 | /* first call to decrement the counter, second call to free */ | ||
| 202 | batadv_tvlv_container_put(tvlv); | ||
| 203 | batadv_tvlv_container_put(tvlv); | ||
| 204 | } | ||
| 205 | |||
| 206 | /** | ||
| 207 | * batadv_tvlv_container_unregister - unregister tvlv container based on the | ||
| 208 | * provided type and version (both need to match) | ||
| 209 | * @bat_priv: the bat priv with all the soft interface information | ||
| 210 | * @type: tvlv container type to unregister | ||
| 211 | * @version: tvlv container type to unregister | ||
| 212 | */ | ||
| 213 | void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv, | ||
| 214 | u8 type, u8 version) | ||
| 215 | { | ||
| 216 | struct batadv_tvlv_container *tvlv; | ||
| 217 | |||
| 218 | spin_lock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 219 | tvlv = batadv_tvlv_container_get(bat_priv, type, version); | ||
| 220 | batadv_tvlv_container_remove(bat_priv, tvlv); | ||
| 221 | spin_unlock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 222 | } | ||
| 223 | |||
| 224 | /** | ||
| 225 | * batadv_tvlv_container_register - register tvlv type, version and content | ||
| 226 | * to be propagated with each (primary interface) OGM | ||
| 227 | * @bat_priv: the bat priv with all the soft interface information | ||
| 228 | * @type: tvlv container type | ||
| 229 | * @version: tvlv container version | ||
| 230 | * @tvlv_value: tvlv container content | ||
| 231 | * @tvlv_value_len: tvlv container content length | ||
| 232 | * | ||
| 233 | * If a container of the same type and version was already registered the new | ||
| 234 | * content is going to replace the old one. | ||
| 235 | */ | ||
| 236 | void batadv_tvlv_container_register(struct batadv_priv *bat_priv, | ||
| 237 | u8 type, u8 version, | ||
| 238 | void *tvlv_value, u16 tvlv_value_len) | ||
| 239 | { | ||
| 240 | struct batadv_tvlv_container *tvlv_old, *tvlv_new; | ||
| 241 | |||
| 242 | if (!tvlv_value) | ||
| 243 | tvlv_value_len = 0; | ||
| 244 | |||
| 245 | tvlv_new = kzalloc(sizeof(*tvlv_new) + tvlv_value_len, GFP_ATOMIC); | ||
| 246 | if (!tvlv_new) | ||
| 247 | return; | ||
| 248 | |||
| 249 | tvlv_new->tvlv_hdr.version = version; | ||
| 250 | tvlv_new->tvlv_hdr.type = type; | ||
| 251 | tvlv_new->tvlv_hdr.len = htons(tvlv_value_len); | ||
| 252 | |||
| 253 | memcpy(tvlv_new + 1, tvlv_value, ntohs(tvlv_new->tvlv_hdr.len)); | ||
| 254 | INIT_HLIST_NODE(&tvlv_new->list); | ||
| 255 | kref_init(&tvlv_new->refcount); | ||
| 256 | |||
| 257 | spin_lock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 258 | tvlv_old = batadv_tvlv_container_get(bat_priv, type, version); | ||
| 259 | batadv_tvlv_container_remove(bat_priv, tvlv_old); | ||
| 260 | hlist_add_head(&tvlv_new->list, &bat_priv->tvlv.container_list); | ||
| 261 | spin_unlock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 262 | } | ||
| 263 | |||
| 264 | /** | ||
| 265 | * batadv_tvlv_realloc_packet_buff - reallocate packet buffer to accommodate | ||
| 266 | * requested packet size | ||
| 267 | * @packet_buff: packet buffer | ||
| 268 | * @packet_buff_len: packet buffer size | ||
| 269 | * @min_packet_len: requested packet minimum size | ||
| 270 | * @additional_packet_len: requested additional packet size on top of minimum | ||
| 271 | * size | ||
| 272 | * | ||
| 273 | * Return: true of the packet buffer could be changed to the requested size, | ||
| 274 | * false otherwise. | ||
| 275 | */ | ||
| 276 | static bool batadv_tvlv_realloc_packet_buff(unsigned char **packet_buff, | ||
| 277 | int *packet_buff_len, | ||
| 278 | int min_packet_len, | ||
| 279 | int additional_packet_len) | ||
| 280 | { | ||
| 281 | unsigned char *new_buff; | ||
| 282 | |||
| 283 | new_buff = kmalloc(min_packet_len + additional_packet_len, GFP_ATOMIC); | ||
| 284 | |||
| 285 | /* keep old buffer if kmalloc should fail */ | ||
| 286 | if (!new_buff) | ||
| 287 | return false; | ||
| 288 | |||
| 289 | memcpy(new_buff, *packet_buff, min_packet_len); | ||
| 290 | kfree(*packet_buff); | ||
| 291 | *packet_buff = new_buff; | ||
| 292 | *packet_buff_len = min_packet_len + additional_packet_len; | ||
| 293 | |||
| 294 | return true; | ||
| 295 | } | ||
| 296 | |||
| 297 | /** | ||
| 298 | * batadv_tvlv_container_ogm_append - append tvlv container content to given | ||
| 299 | * OGM packet buffer | ||
| 300 | * @bat_priv: the bat priv with all the soft interface information | ||
| 301 | * @packet_buff: ogm packet buffer | ||
| 302 | * @packet_buff_len: ogm packet buffer size including ogm header and tvlv | ||
| 303 | * content | ||
| 304 | * @packet_min_len: ogm header size to be preserved for the OGM itself | ||
| 305 | * | ||
| 306 | * The ogm packet might be enlarged or shrunk depending on the current size | ||
| 307 | * and the size of the to-be-appended tvlv containers. | ||
| 308 | * | ||
| 309 | * Return: size of all appended tvlv containers in bytes. | ||
| 310 | */ | ||
| 311 | u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv, | ||
| 312 | unsigned char **packet_buff, | ||
| 313 | int *packet_buff_len, int packet_min_len) | ||
| 314 | { | ||
| 315 | struct batadv_tvlv_container *tvlv; | ||
| 316 | struct batadv_tvlv_hdr *tvlv_hdr; | ||
| 317 | u16 tvlv_value_len; | ||
| 318 | void *tvlv_value; | ||
| 319 | bool ret; | ||
| 320 | |||
| 321 | spin_lock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 322 | tvlv_value_len = batadv_tvlv_container_list_size(bat_priv); | ||
| 323 | |||
| 324 | ret = batadv_tvlv_realloc_packet_buff(packet_buff, packet_buff_len, | ||
| 325 | packet_min_len, tvlv_value_len); | ||
| 326 | |||
| 327 | if (!ret) | ||
| 328 | goto end; | ||
| 329 | |||
| 330 | if (!tvlv_value_len) | ||
| 331 | goto end; | ||
| 332 | |||
| 333 | tvlv_value = (*packet_buff) + packet_min_len; | ||
| 334 | |||
| 335 | hlist_for_each_entry(tvlv, &bat_priv->tvlv.container_list, list) { | ||
| 336 | tvlv_hdr = tvlv_value; | ||
| 337 | tvlv_hdr->type = tvlv->tvlv_hdr.type; | ||
| 338 | tvlv_hdr->version = tvlv->tvlv_hdr.version; | ||
| 339 | tvlv_hdr->len = tvlv->tvlv_hdr.len; | ||
| 340 | tvlv_value = tvlv_hdr + 1; | ||
| 341 | memcpy(tvlv_value, tvlv + 1, ntohs(tvlv->tvlv_hdr.len)); | ||
| 342 | tvlv_value = (u8 *)tvlv_value + ntohs(tvlv->tvlv_hdr.len); | ||
| 343 | } | ||
| 344 | |||
| 345 | end: | ||
| 346 | spin_unlock_bh(&bat_priv->tvlv.container_list_lock); | ||
| 347 | return tvlv_value_len; | ||
| 348 | } | ||
| 349 | |||
| 350 | /** | ||
| 351 | * batadv_tvlv_call_handler - parse the given tvlv buffer to call the | ||
| 352 | * appropriate handlers | ||
| 353 | * @bat_priv: the bat priv with all the soft interface information | ||
| 354 | * @tvlv_handler: tvlv callback function handling the tvlv content | ||
| 355 | * @ogm_source: flag indicating whether the tvlv is an ogm or a unicast packet | ||
| 356 | * @orig_node: orig node emitting the ogm packet | ||
| 357 | * @src: source mac address of the unicast packet | ||
| 358 | * @dst: destination mac address of the unicast packet | ||
| 359 | * @tvlv_value: tvlv content | ||
| 360 | * @tvlv_value_len: tvlv content length | ||
| 361 | * | ||
| 362 | * Return: success if handler was not found or the return value of the handler | ||
| 363 | * callback. | ||
| 364 | */ | ||
| 365 | static int batadv_tvlv_call_handler(struct batadv_priv *bat_priv, | ||
| 366 | struct batadv_tvlv_handler *tvlv_handler, | ||
| 367 | bool ogm_source, | ||
| 368 | struct batadv_orig_node *orig_node, | ||
| 369 | u8 *src, u8 *dst, | ||
| 370 | void *tvlv_value, u16 tvlv_value_len) | ||
| 371 | { | ||
| 372 | if (!tvlv_handler) | ||
| 373 | return NET_RX_SUCCESS; | ||
| 374 | |||
| 375 | if (ogm_source) { | ||
| 376 | if (!tvlv_handler->ogm_handler) | ||
| 377 | return NET_RX_SUCCESS; | ||
| 378 | |||
| 379 | if (!orig_node) | ||
| 380 | return NET_RX_SUCCESS; | ||
| 381 | |||
| 382 | tvlv_handler->ogm_handler(bat_priv, orig_node, | ||
| 383 | BATADV_NO_FLAGS, | ||
| 384 | tvlv_value, tvlv_value_len); | ||
| 385 | tvlv_handler->flags |= BATADV_TVLV_HANDLER_OGM_CALLED; | ||
| 386 | } else { | ||
| 387 | if (!src) | ||
| 388 | return NET_RX_SUCCESS; | ||
| 389 | |||
| 390 | if (!dst) | ||
| 391 | return NET_RX_SUCCESS; | ||
| 392 | |||
| 393 | if (!tvlv_handler->unicast_handler) | ||
| 394 | return NET_RX_SUCCESS; | ||
| 395 | |||
| 396 | return tvlv_handler->unicast_handler(bat_priv, src, | ||
| 397 | dst, tvlv_value, | ||
| 398 | tvlv_value_len); | ||
| 399 | } | ||
| 400 | |||
| 401 | return NET_RX_SUCCESS; | ||
| 402 | } | ||
| 403 | |||
| 404 | /** | ||
| 405 | * batadv_tvlv_containers_process - parse the given tvlv buffer to call the | ||
| 406 | * appropriate handlers | ||
| 407 | * @bat_priv: the bat priv with all the soft interface information | ||
| 408 | * @ogm_source: flag indicating whether the tvlv is an ogm or a unicast packet | ||
| 409 | * @orig_node: orig node emitting the ogm packet | ||
| 410 | * @src: source mac address of the unicast packet | ||
| 411 | * @dst: destination mac address of the unicast packet | ||
| 412 | * @tvlv_value: tvlv content | ||
| 413 | * @tvlv_value_len: tvlv content length | ||
| 414 | * | ||
| 415 | * Return: success when processing an OGM or the return value of all called | ||
| 416 | * handler callbacks. | ||
| 417 | */ | ||
| 418 | int batadv_tvlv_containers_process(struct batadv_priv *bat_priv, | ||
| 419 | bool ogm_source, | ||
| 420 | struct batadv_orig_node *orig_node, | ||
| 421 | u8 *src, u8 *dst, | ||
| 422 | void *tvlv_value, u16 tvlv_value_len) | ||
| 423 | { | ||
| 424 | struct batadv_tvlv_handler *tvlv_handler; | ||
| 425 | struct batadv_tvlv_hdr *tvlv_hdr; | ||
| 426 | u16 tvlv_value_cont_len; | ||
| 427 | u8 cifnotfound = BATADV_TVLV_HANDLER_OGM_CIFNOTFND; | ||
| 428 | int ret = NET_RX_SUCCESS; | ||
| 429 | |||
| 430 | while (tvlv_value_len >= sizeof(*tvlv_hdr)) { | ||
| 431 | tvlv_hdr = tvlv_value; | ||
| 432 | tvlv_value_cont_len = ntohs(tvlv_hdr->len); | ||
| 433 | tvlv_value = tvlv_hdr + 1; | ||
| 434 | tvlv_value_len -= sizeof(*tvlv_hdr); | ||
| 435 | |||
| 436 | if (tvlv_value_cont_len > tvlv_value_len) | ||
| 437 | break; | ||
| 438 | |||
| 439 | tvlv_handler = batadv_tvlv_handler_get(bat_priv, | ||
| 440 | tvlv_hdr->type, | ||
| 441 | tvlv_hdr->version); | ||
| 442 | |||
| 443 | ret |= batadv_tvlv_call_handler(bat_priv, tvlv_handler, | ||
| 444 | ogm_source, orig_node, | ||
| 445 | src, dst, tvlv_value, | ||
| 446 | tvlv_value_cont_len); | ||
| 447 | if (tvlv_handler) | ||
| 448 | batadv_tvlv_handler_put(tvlv_handler); | ||
| 449 | tvlv_value = (u8 *)tvlv_value + tvlv_value_cont_len; | ||
| 450 | tvlv_value_len -= tvlv_value_cont_len; | ||
| 451 | } | ||
| 452 | |||
| 453 | if (!ogm_source) | ||
| 454 | return ret; | ||
| 455 | |||
| 456 | rcu_read_lock(); | ||
| 457 | hlist_for_each_entry_rcu(tvlv_handler, | ||
| 458 | &bat_priv->tvlv.handler_list, list) { | ||
| 459 | if ((tvlv_handler->flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND) && | ||
| 460 | !(tvlv_handler->flags & BATADV_TVLV_HANDLER_OGM_CALLED)) | ||
| 461 | tvlv_handler->ogm_handler(bat_priv, orig_node, | ||
| 462 | cifnotfound, NULL, 0); | ||
| 463 | |||
| 464 | tvlv_handler->flags &= ~BATADV_TVLV_HANDLER_OGM_CALLED; | ||
| 465 | } | ||
| 466 | rcu_read_unlock(); | ||
| 467 | |||
| 468 | return NET_RX_SUCCESS; | ||
| 469 | } | ||
| 470 | |||
| 471 | /** | ||
| 472 | * batadv_tvlv_ogm_receive - process an incoming ogm and call the appropriate | ||
| 473 | * handlers | ||
| 474 | * @bat_priv: the bat priv with all the soft interface information | ||
| 475 | * @batadv_ogm_packet: ogm packet containing the tvlv containers | ||
| 476 | * @orig_node: orig node emitting the ogm packet | ||
| 477 | */ | ||
| 478 | void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv, | ||
| 479 | struct batadv_ogm_packet *batadv_ogm_packet, | ||
| 480 | struct batadv_orig_node *orig_node) | ||
| 481 | { | ||
| 482 | void *tvlv_value; | ||
| 483 | u16 tvlv_value_len; | ||
| 484 | |||
| 485 | if (!batadv_ogm_packet) | ||
| 486 | return; | ||
| 487 | |||
| 488 | tvlv_value_len = ntohs(batadv_ogm_packet->tvlv_len); | ||
| 489 | if (!tvlv_value_len) | ||
| 490 | return; | ||
| 491 | |||
| 492 | tvlv_value = batadv_ogm_packet + 1; | ||
| 493 | |||
| 494 | batadv_tvlv_containers_process(bat_priv, true, orig_node, NULL, NULL, | ||
| 495 | tvlv_value, tvlv_value_len); | ||
| 496 | } | ||
| 497 | |||
| 498 | /** | ||
| 499 | * batadv_tvlv_handler_register - register tvlv handler based on the provided | ||
| 500 | * type and version (both need to match) for ogm tvlv payload and/or unicast | ||
| 501 | * payload | ||
| 502 | * @bat_priv: the bat priv with all the soft interface information | ||
| 503 | * @optr: ogm tvlv handler callback function. This function receives the orig | ||
| 504 | * node, flags and the tvlv content as argument to process. | ||
| 505 | * @uptr: unicast tvlv handler callback function. This function receives the | ||
| 506 | * source & destination of the unicast packet as well as the tvlv content | ||
| 507 | * to process. | ||
| 508 | * @type: tvlv handler type to be registered | ||
| 509 | * @version: tvlv handler version to be registered | ||
| 510 | * @flags: flags to enable or disable TVLV API behavior | ||
| 511 | */ | ||
| 512 | void batadv_tvlv_handler_register(struct batadv_priv *bat_priv, | ||
| 513 | void (*optr)(struct batadv_priv *bat_priv, | ||
| 514 | struct batadv_orig_node *orig, | ||
| 515 | u8 flags, | ||
| 516 | void *tvlv_value, | ||
| 517 | u16 tvlv_value_len), | ||
| 518 | int (*uptr)(struct batadv_priv *bat_priv, | ||
| 519 | u8 *src, u8 *dst, | ||
| 520 | void *tvlv_value, | ||
| 521 | u16 tvlv_value_len), | ||
| 522 | u8 type, u8 version, u8 flags) | ||
| 523 | { | ||
| 524 | struct batadv_tvlv_handler *tvlv_handler; | ||
| 525 | |||
| 526 | tvlv_handler = batadv_tvlv_handler_get(bat_priv, type, version); | ||
| 527 | if (tvlv_handler) { | ||
| 528 | batadv_tvlv_handler_put(tvlv_handler); | ||
| 529 | return; | ||
| 530 | } | ||
| 531 | |||
| 532 | tvlv_handler = kzalloc(sizeof(*tvlv_handler), GFP_ATOMIC); | ||
| 533 | if (!tvlv_handler) | ||
| 534 | return; | ||
| 535 | |||
| 536 | tvlv_handler->ogm_handler = optr; | ||
| 537 | tvlv_handler->unicast_handler = uptr; | ||
| 538 | tvlv_handler->type = type; | ||
| 539 | tvlv_handler->version = version; | ||
| 540 | tvlv_handler->flags = flags; | ||
| 541 | kref_init(&tvlv_handler->refcount); | ||
| 542 | INIT_HLIST_NODE(&tvlv_handler->list); | ||
| 543 | |||
| 544 | spin_lock_bh(&bat_priv->tvlv.handler_list_lock); | ||
| 545 | hlist_add_head_rcu(&tvlv_handler->list, &bat_priv->tvlv.handler_list); | ||
| 546 | spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); | ||
| 547 | } | ||
| 548 | |||
| 549 | /** | ||
| 550 | * batadv_tvlv_handler_unregister - unregister tvlv handler based on the | ||
| 551 | * provided type and version (both need to match) | ||
| 552 | * @bat_priv: the bat priv with all the soft interface information | ||
| 553 | * @type: tvlv handler type to be unregistered | ||
| 554 | * @version: tvlv handler version to be unregistered | ||
| 555 | */ | ||
| 556 | void batadv_tvlv_handler_unregister(struct batadv_priv *bat_priv, | ||
| 557 | u8 type, u8 version) | ||
| 558 | { | ||
| 559 | struct batadv_tvlv_handler *tvlv_handler; | ||
| 560 | |||
| 561 | tvlv_handler = batadv_tvlv_handler_get(bat_priv, type, version); | ||
| 562 | if (!tvlv_handler) | ||
| 563 | return; | ||
| 564 | |||
| 565 | batadv_tvlv_handler_put(tvlv_handler); | ||
| 566 | spin_lock_bh(&bat_priv->tvlv.handler_list_lock); | ||
| 567 | hlist_del_rcu(&tvlv_handler->list); | ||
| 568 | spin_unlock_bh(&bat_priv->tvlv.handler_list_lock); | ||
| 569 | batadv_tvlv_handler_put(tvlv_handler); | ||
| 570 | } | ||
| 571 | |||
| 572 | /** | ||
| 573 | * batadv_tvlv_unicast_send - send a unicast packet with tvlv payload to the | ||
| 574 | * specified host | ||
| 575 | * @bat_priv: the bat priv with all the soft interface information | ||
| 576 | * @src: source mac address of the unicast packet | ||
| 577 | * @dst: destination mac address of the unicast packet | ||
| 578 | * @type: tvlv type | ||
| 579 | * @version: tvlv version | ||
| 580 | * @tvlv_value: tvlv content | ||
| 581 | * @tvlv_value_len: tvlv content length | ||
| 582 | */ | ||
| 583 | void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src, | ||
| 584 | u8 *dst, u8 type, u8 version, | ||
| 585 | void *tvlv_value, u16 tvlv_value_len) | ||
| 586 | { | ||
| 587 | struct batadv_unicast_tvlv_packet *unicast_tvlv_packet; | ||
| 588 | struct batadv_tvlv_hdr *tvlv_hdr; | ||
| 589 | struct batadv_orig_node *orig_node; | ||
| 590 | struct sk_buff *skb; | ||
| 591 | unsigned char *tvlv_buff; | ||
| 592 | unsigned int tvlv_len; | ||
| 593 | ssize_t hdr_len = sizeof(*unicast_tvlv_packet); | ||
| 594 | int res; | ||
| 595 | |||
| 596 | orig_node = batadv_orig_hash_find(bat_priv, dst); | ||
| 597 | if (!orig_node) | ||
| 598 | return; | ||
| 599 | |||
| 600 | tvlv_len = sizeof(*tvlv_hdr) + tvlv_value_len; | ||
| 601 | |||
| 602 | skb = netdev_alloc_skb_ip_align(NULL, ETH_HLEN + hdr_len + tvlv_len); | ||
| 603 | if (!skb) | ||
| 604 | goto out; | ||
| 605 | |||
| 606 | skb->priority = TC_PRIO_CONTROL; | ||
| 607 | skb_reserve(skb, ETH_HLEN); | ||
| 608 | tvlv_buff = skb_put(skb, sizeof(*unicast_tvlv_packet) + tvlv_len); | ||
| 609 | unicast_tvlv_packet = (struct batadv_unicast_tvlv_packet *)tvlv_buff; | ||
| 610 | unicast_tvlv_packet->packet_type = BATADV_UNICAST_TVLV; | ||
| 611 | unicast_tvlv_packet->version = BATADV_COMPAT_VERSION; | ||
| 612 | unicast_tvlv_packet->ttl = BATADV_TTL; | ||
| 613 | unicast_tvlv_packet->reserved = 0; | ||
| 614 | unicast_tvlv_packet->tvlv_len = htons(tvlv_len); | ||
| 615 | unicast_tvlv_packet->align = 0; | ||
| 616 | ether_addr_copy(unicast_tvlv_packet->src, src); | ||
| 617 | ether_addr_copy(unicast_tvlv_packet->dst, dst); | ||
| 618 | |||
| 619 | tvlv_buff = (unsigned char *)(unicast_tvlv_packet + 1); | ||
| 620 | tvlv_hdr = (struct batadv_tvlv_hdr *)tvlv_buff; | ||
| 621 | tvlv_hdr->version = version; | ||
| 622 | tvlv_hdr->type = type; | ||
| 623 | tvlv_hdr->len = htons(tvlv_value_len); | ||
| 624 | tvlv_buff += sizeof(*tvlv_hdr); | ||
| 625 | memcpy(tvlv_buff, tvlv_value, tvlv_value_len); | ||
| 626 | |||
| 627 | res = batadv_send_skb_to_orig(skb, orig_node, NULL); | ||
| 628 | if (res == -1) | ||
| 629 | kfree_skb(skb); | ||
| 630 | out: | ||
| 631 | batadv_orig_node_put(orig_node); | ||
| 632 | } | ||
diff --git a/net/batman-adv/tvlv.h b/net/batman-adv/tvlv.h new file mode 100644 index 000000000000..e4369b547b43 --- /dev/null +++ b/net/batman-adv/tvlv.h | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | /* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors: | ||
| 2 | * | ||
| 3 | * Marek Lindner, Simon Wunderlich | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or | ||
| 6 | * modify it under the terms of version 2 of the GNU General Public | ||
| 7 | * License as published by the Free Software Foundation. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, but | ||
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef _NET_BATMAN_ADV_TVLV_H_ | ||
| 19 | #define _NET_BATMAN_ADV_TVLV_H_ | ||
| 20 | |||
| 21 | #include "main.h" | ||
| 22 | |||
| 23 | #include <linux/types.h> | ||
| 24 | |||
| 25 | struct batadv_ogm_packet; | ||
| 26 | |||
| 27 | void batadv_tvlv_container_register(struct batadv_priv *bat_priv, | ||
| 28 | u8 type, u8 version, | ||
| 29 | void *tvlv_value, u16 tvlv_value_len); | ||
| 30 | u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv, | ||
| 31 | unsigned char **packet_buff, | ||
| 32 | int *packet_buff_len, int packet_min_len); | ||
| 33 | void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv, | ||
| 34 | struct batadv_ogm_packet *batadv_ogm_packet, | ||
| 35 | struct batadv_orig_node *orig_node); | ||
| 36 | void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv, | ||
| 37 | u8 type, u8 version); | ||
| 38 | |||
| 39 | void batadv_tvlv_handler_register(struct batadv_priv *bat_priv, | ||
| 40 | void (*optr)(struct batadv_priv *bat_priv, | ||
| 41 | struct batadv_orig_node *orig, | ||
| 42 | u8 flags, | ||
| 43 | void *tvlv_value, | ||
| 44 | u16 tvlv_value_len), | ||
| 45 | int (*uptr)(struct batadv_priv *bat_priv, | ||
| 46 | u8 *src, u8 *dst, | ||
| 47 | void *tvlv_value, | ||
| 48 | u16 tvlv_value_len), | ||
| 49 | u8 type, u8 version, u8 flags); | ||
| 50 | void batadv_tvlv_handler_unregister(struct batadv_priv *bat_priv, | ||
| 51 | u8 type, u8 version); | ||
| 52 | int batadv_tvlv_containers_process(struct batadv_priv *bat_priv, | ||
| 53 | bool ogm_source, | ||
| 54 | struct batadv_orig_node *orig_node, | ||
| 55 | u8 *src, u8 *dst, | ||
| 56 | void *tvlv_buff, u16 tvlv_buff_len); | ||
| 57 | void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src, | ||
| 58 | u8 *dst, u8 type, u8 version, | ||
| 59 | void *tvlv_value, u16 tvlv_value_len); | ||
| 60 | |||
| 61 | #endif /* _NET_BATMAN_ADV_TVLV_H_ */ | ||
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index 02e22763a880..43db7b61f8eb 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h | |||
| @@ -33,6 +33,7 @@ | |||
| 33 | #include <linux/types.h> | 33 | #include <linux/types.h> |
| 34 | #include <linux/wait.h> | 34 | #include <linux/wait.h> |
| 35 | #include <linux/workqueue.h> | 35 | #include <linux/workqueue.h> |
| 36 | #include <uapi/linux/batman_adv.h> | ||
| 36 | 37 | ||
| 37 | #include "packet.h" | 38 | #include "packet.h" |
| 38 | 39 | ||
| @@ -833,6 +834,111 @@ struct batadv_priv_nc { | |||
| 833 | }; | 834 | }; |
| 834 | 835 | ||
| 835 | /** | 836 | /** |
| 837 | * struct batadv_tp_unacked - unacked packet meta-information | ||
| 838 | * @seqno: seqno of the unacked packet | ||
| 839 | * @len: length of the packet | ||
| 840 | * @list: list node for batadv_tp_vars::unacked_list | ||
| 841 | * | ||
| 842 | * This struct is supposed to represent a buffer unacked packet. However, since | ||
| 843 | * the purpose of the TP meter is to count the traffic only, there is no need to | ||
| 844 | * store the entire sk_buff, the starting offset and the length are enough | ||
| 845 | */ | ||
| 846 | struct batadv_tp_unacked { | ||
| 847 | u32 seqno; | ||
| 848 | u16 len; | ||
| 849 | struct list_head list; | ||
| 850 | }; | ||
| 851 | |||
| 852 | /** | ||
| 853 | * enum batadv_tp_meter_role - Modus in tp meter session | ||
| 854 | * @BATADV_TP_RECEIVER: Initialized as receiver | ||
| 855 | * @BATADV_TP_SENDER: Initialized as sender | ||
| 856 | */ | ||
| 857 | enum batadv_tp_meter_role { | ||
| 858 | BATADV_TP_RECEIVER, | ||
| 859 | BATADV_TP_SENDER | ||
| 860 | }; | ||
| 861 | |||
| 862 | /** | ||
| 863 | * struct batadv_tp_vars - tp meter private variables per session | ||
| 864 | * @list: list node for bat_priv::tp_list | ||
| 865 | * @timer: timer for ack (receiver) and retry (sender) | ||
| 866 | * @bat_priv: pointer to the mesh object | ||
| 867 | * @start_time: start time in jiffies | ||
| 868 | * @other_end: mac address of remote | ||
| 869 | * @role: receiver/sender modi | ||
| 870 | * @sending: sending binary semaphore: 1 if sending, 0 is not | ||
| 871 | * @reason: reason for a stopped session | ||
| 872 | * @finish_work: work item for the finishing procedure | ||
| 873 | * @test_length: test length in milliseconds | ||
| 874 | * @session: TP session identifier | ||
| 875 | * @icmp_uid: local ICMP "socket" index | ||
| 876 | * @dec_cwnd: decimal part of the cwnd used during linear growth | ||
| 877 | * @cwnd: current size of the congestion window | ||
| 878 | * @cwnd_lock: lock do protect @cwnd & @dec_cwnd | ||
| 879 | * @ss_threshold: Slow Start threshold. Once cwnd exceeds this value the | ||
| 880 | * connection switches to the Congestion Avoidance state | ||
| 881 | * @last_acked: last acked byte | ||
| 882 | * @last_sent: last sent byte, not yet acked | ||
| 883 | * @tot_sent: amount of data sent/ACKed so far | ||
| 884 | * @dup_acks: duplicate ACKs counter | ||
| 885 | * @fast_recovery: true if in Fast Recovery mode | ||
| 886 | * @recover: last sent seqno when entering Fast Recovery | ||
| 887 | * @rto: sender timeout | ||
| 888 | * @srtt: smoothed RTT scaled by 2^3 | ||
| 889 | * @rttvar: RTT variation scaled by 2^2 | ||
| 890 | * @more_bytes: waiting queue anchor when waiting for more ack/retry timeout | ||
| 891 | * @prerandom_offset: offset inside the prerandom buffer | ||
| 892 | * @prerandom_lock: spinlock protecting access to prerandom_offset | ||
| 893 | * @last_recv: last in-order received packet | ||
| 894 | * @unacked_list: list of unacked packets (meta-info only) | ||
| 895 | * @unacked_lock: protect unacked_list | ||
| 896 | * @last_recv_time: time time (jiffies) a msg was received | ||
| 897 | * @refcount: number of context where the object is used | ||
| 898 | * @rcu: struct used for freeing in an RCU-safe manner | ||
| 899 | */ | ||
| 900 | struct batadv_tp_vars { | ||
| 901 | struct hlist_node list; | ||
| 902 | struct timer_list timer; | ||
| 903 | struct batadv_priv *bat_priv; | ||
| 904 | unsigned long start_time; | ||
| 905 | u8 other_end[ETH_ALEN]; | ||
| 906 | enum batadv_tp_meter_role role; | ||
| 907 | atomic_t sending; | ||
| 908 | enum batadv_tp_meter_reason reason; | ||
| 909 | struct delayed_work finish_work; | ||
| 910 | u32 test_length; | ||
| 911 | u8 session[2]; | ||
| 912 | u8 icmp_uid; | ||
| 913 | |||
| 914 | /* sender variables */ | ||
| 915 | u16 dec_cwnd; | ||
| 916 | u32 cwnd; | ||
| 917 | spinlock_t cwnd_lock; /* Protects cwnd & dec_cwnd */ | ||
| 918 | u32 ss_threshold; | ||
| 919 | atomic_t last_acked; | ||
| 920 | u32 last_sent; | ||
| 921 | atomic64_t tot_sent; | ||
| 922 | atomic_t dup_acks; | ||
| 923 | bool fast_recovery; | ||
| 924 | u32 recover; | ||
| 925 | u32 rto; | ||
| 926 | u32 srtt; | ||
| 927 | u32 rttvar; | ||
| 928 | wait_queue_head_t more_bytes; | ||
| 929 | u32 prerandom_offset; | ||
| 930 | spinlock_t prerandom_lock; /* Protects prerandom_offset */ | ||
| 931 | |||
| 932 | /* receiver variables */ | ||
| 933 | u32 last_recv; | ||
| 934 | struct list_head unacked_list; | ||
| 935 | spinlock_t unacked_lock; /* Protects unacked_list */ | ||
| 936 | unsigned long last_recv_time; | ||
| 937 | struct kref refcount; | ||
| 938 | struct rcu_head rcu; | ||
| 939 | }; | ||
| 940 | |||
| 941 | /** | ||
| 836 | * struct batadv_softif_vlan - per VLAN attributes set | 942 | * struct batadv_softif_vlan - per VLAN attributes set |
| 837 | * @bat_priv: pointer to the mesh object | 943 | * @bat_priv: pointer to the mesh object |
| 838 | * @vid: VLAN identifier | 944 | * @vid: VLAN identifier |
| @@ -900,14 +1006,17 @@ struct batadv_priv_bat_v { | |||
| 900 | * @debug_dir: dentry for debugfs batman-adv subdirectory | 1006 | * @debug_dir: dentry for debugfs batman-adv subdirectory |
| 901 | * @forw_bat_list: list of aggregated OGMs that will be forwarded | 1007 | * @forw_bat_list: list of aggregated OGMs that will be forwarded |
| 902 | * @forw_bcast_list: list of broadcast packets that will be rebroadcasted | 1008 | * @forw_bcast_list: list of broadcast packets that will be rebroadcasted |
| 1009 | * @tp_list: list of tp sessions | ||
| 1010 | * @tp_num: number of currently active tp sessions | ||
| 903 | * @orig_hash: hash table containing mesh participants (orig nodes) | 1011 | * @orig_hash: hash table containing mesh participants (orig nodes) |
| 904 | * @forw_bat_list_lock: lock protecting forw_bat_list | 1012 | * @forw_bat_list_lock: lock protecting forw_bat_list |
| 905 | * @forw_bcast_list_lock: lock protecting forw_bcast_list | 1013 | * @forw_bcast_list_lock: lock protecting forw_bcast_list |
| 1014 | * @tp_list_lock: spinlock protecting @tp_list | ||
| 906 | * @orig_work: work queue callback item for orig node purging | 1015 | * @orig_work: work queue callback item for orig node purging |
| 907 | * @cleanup_work: work queue callback item for soft-interface deinit | 1016 | * @cleanup_work: work queue callback item for soft-interface deinit |
| 908 | * @primary_if: one of the hard-interfaces assigned to this mesh interface | 1017 | * @primary_if: one of the hard-interfaces assigned to this mesh interface |
| 909 | * becomes the primary interface | 1018 | * becomes the primary interface |
| 910 | * @bat_algo_ops: routing algorithm used by this mesh interface | 1019 | * @algo_ops: routing algorithm used by this mesh interface |
| 911 | * @softif_vlan_list: a list of softif_vlan structs, one per VLAN created on top | 1020 | * @softif_vlan_list: a list of softif_vlan structs, one per VLAN created on top |
| 912 | * of the mesh interface represented by this object | 1021 | * of the mesh interface represented by this object |
| 913 | * @softif_vlan_list_lock: lock protecting softif_vlan_list | 1022 | * @softif_vlan_list_lock: lock protecting softif_vlan_list |
| @@ -956,13 +1065,16 @@ struct batadv_priv { | |||
| 956 | struct dentry *debug_dir; | 1065 | struct dentry *debug_dir; |
| 957 | struct hlist_head forw_bat_list; | 1066 | struct hlist_head forw_bat_list; |
| 958 | struct hlist_head forw_bcast_list; | 1067 | struct hlist_head forw_bcast_list; |
| 1068 | struct hlist_head tp_list; | ||
| 959 | struct batadv_hashtable *orig_hash; | 1069 | struct batadv_hashtable *orig_hash; |
| 960 | spinlock_t forw_bat_list_lock; /* protects forw_bat_list */ | 1070 | spinlock_t forw_bat_list_lock; /* protects forw_bat_list */ |
| 961 | spinlock_t forw_bcast_list_lock; /* protects forw_bcast_list */ | 1071 | spinlock_t forw_bcast_list_lock; /* protects forw_bcast_list */ |
| 1072 | spinlock_t tp_list_lock; /* protects tp_list */ | ||
| 1073 | atomic_t tp_num; | ||
| 962 | struct delayed_work orig_work; | 1074 | struct delayed_work orig_work; |
| 963 | struct work_struct cleanup_work; | 1075 | struct work_struct cleanup_work; |
| 964 | struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */ | 1076 | struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */ |
| 965 | struct batadv_algo_ops *bat_algo_ops; | 1077 | struct batadv_algo_ops *algo_ops; |
| 966 | struct hlist_head softif_vlan_list; | 1078 | struct hlist_head softif_vlan_list; |
| 967 | spinlock_t softif_vlan_list_lock; /* protects softif_vlan_list */ | 1079 | spinlock_t softif_vlan_list_lock; /* protects softif_vlan_list */ |
| 968 | #ifdef CONFIG_BATMAN_ADV_BLA | 1080 | #ifdef CONFIG_BATMAN_ADV_BLA |
| @@ -1278,59 +1390,77 @@ struct batadv_forw_packet { | |||
| 1278 | }; | 1390 | }; |
| 1279 | 1391 | ||
| 1280 | /** | 1392 | /** |
| 1393 | * struct batadv_algo_iface_ops - mesh algorithm callbacks (interface specific) | ||
| 1394 | * @activate: start routing mechanisms when hard-interface is brought up | ||
| 1395 | * @enable: init routing info when hard-interface is enabled | ||
| 1396 | * @disable: de-init routing info when hard-interface is disabled | ||
| 1397 | * @update_mac: (re-)init mac addresses of the protocol information | ||
| 1398 | * belonging to this hard-interface | ||
| 1399 | * @primary_set: called when primary interface is selected / changed | ||
| 1400 | */ | ||
| 1401 | struct batadv_algo_iface_ops { | ||
| 1402 | void (*activate)(struct batadv_hard_iface *hard_iface); | ||
| 1403 | int (*enable)(struct batadv_hard_iface *hard_iface); | ||
| 1404 | void (*disable)(struct batadv_hard_iface *hard_iface); | ||
| 1405 | void (*update_mac)(struct batadv_hard_iface *hard_iface); | ||
| 1406 | void (*primary_set)(struct batadv_hard_iface *hard_iface); | ||
| 1407 | }; | ||
| 1408 | |||
| 1409 | /** | ||
| 1410 | * struct batadv_algo_neigh_ops - mesh algorithm callbacks (neighbour specific) | ||
| 1411 | * @hardif_init: called on creation of single hop entry | ||
| 1412 | * @cmp: compare the metrics of two neighbors for their respective outgoing | ||
| 1413 | * interfaces | ||
| 1414 | * @is_similar_or_better: check if neigh1 is equally similar or better than | ||
| 1415 | * neigh2 for their respective outgoing interface from the metric prospective | ||
| 1416 | * @print: print the single hop neighbor list (optional) | ||
| 1417 | */ | ||
| 1418 | struct batadv_algo_neigh_ops { | ||
| 1419 | void (*hardif_init)(struct batadv_hardif_neigh_node *neigh); | ||
| 1420 | int (*cmp)(struct batadv_neigh_node *neigh1, | ||
| 1421 | struct batadv_hard_iface *if_outgoing1, | ||
| 1422 | struct batadv_neigh_node *neigh2, | ||
| 1423 | struct batadv_hard_iface *if_outgoing2); | ||
| 1424 | bool (*is_similar_or_better)(struct batadv_neigh_node *neigh1, | ||
| 1425 | struct batadv_hard_iface *if_outgoing1, | ||
| 1426 | struct batadv_neigh_node *neigh2, | ||
| 1427 | struct batadv_hard_iface *if_outgoing2); | ||
| 1428 | void (*print)(struct batadv_priv *priv, struct seq_file *seq); | ||
| 1429 | }; | ||
| 1430 | |||
| 1431 | /** | ||
| 1432 | * struct batadv_algo_orig_ops - mesh algorithm callbacks (originator specific) | ||
| 1433 | * @free: free the resources allocated by the routing algorithm for an orig_node | ||
| 1434 | * object | ||
| 1435 | * @add_if: ask the routing algorithm to apply the needed changes to the | ||
| 1436 | * orig_node due to a new hard-interface being added into the mesh | ||
| 1437 | * @del_if: ask the routing algorithm to apply the needed changes to the | ||
| 1438 | * orig_node due to an hard-interface being removed from the mesh | ||
| 1439 | * @print: print the originator table (optional) | ||
| 1440 | */ | ||
| 1441 | struct batadv_algo_orig_ops { | ||
| 1442 | void (*free)(struct batadv_orig_node *orig_node); | ||
| 1443 | int (*add_if)(struct batadv_orig_node *orig_node, int max_if_num); | ||
| 1444 | int (*del_if)(struct batadv_orig_node *orig_node, int max_if_num, | ||
| 1445 | int del_if_num); | ||
| 1446 | void (*print)(struct batadv_priv *priv, struct seq_file *seq, | ||
| 1447 | struct batadv_hard_iface *hard_iface); | ||
| 1448 | }; | ||
| 1449 | |||
| 1450 | /** | ||
| 1281 | * struct batadv_algo_ops - mesh algorithm callbacks | 1451 | * struct batadv_algo_ops - mesh algorithm callbacks |
| 1282 | * @list: list node for the batadv_algo_list | 1452 | * @list: list node for the batadv_algo_list |
| 1283 | * @name: name of the algorithm | 1453 | * @name: name of the algorithm |
| 1284 | * @bat_iface_activate: start routing mechanisms when hard-interface is brought | 1454 | * @iface: callbacks related to interface handling |
| 1285 | * up | 1455 | * @neigh: callbacks related to neighbors handling |
| 1286 | * @bat_iface_enable: init routing info when hard-interface is enabled | 1456 | * @orig: callbacks related to originators handling |
| 1287 | * @bat_iface_disable: de-init routing info when hard-interface is disabled | ||
| 1288 | * @bat_iface_update_mac: (re-)init mac addresses of the protocol information | ||
| 1289 | * belonging to this hard-interface | ||
| 1290 | * @bat_primary_iface_set: called when primary interface is selected / changed | ||
| 1291 | * @bat_hardif_neigh_init: called on creation of single hop entry | ||
| 1292 | * @bat_neigh_cmp: compare the metrics of two neighbors for their respective | ||
| 1293 | * outgoing interfaces | ||
| 1294 | * @bat_neigh_is_similar_or_better: check if neigh1 is equally similar or | ||
| 1295 | * better than neigh2 for their respective outgoing interface from the metric | ||
| 1296 | * prospective | ||
| 1297 | * @bat_neigh_print: print the single hop neighbor list (optional) | ||
| 1298 | * @bat_orig_print: print the originator table (optional) | ||
| 1299 | * @bat_orig_free: free the resources allocated by the routing algorithm for an | ||
| 1300 | * orig_node object | ||
| 1301 | * @bat_orig_add_if: ask the routing algorithm to apply the needed changes to | ||
| 1302 | * the orig_node due to a new hard-interface being added into the mesh | ||
| 1303 | * @bat_orig_del_if: ask the routing algorithm to apply the needed changes to | ||
| 1304 | * the orig_node due to an hard-interface being removed from the mesh | ||
| 1305 | */ | 1457 | */ |
| 1306 | struct batadv_algo_ops { | 1458 | struct batadv_algo_ops { |
| 1307 | struct hlist_node list; | 1459 | struct hlist_node list; |
| 1308 | char *name; | 1460 | char *name; |
| 1309 | void (*bat_iface_activate)(struct batadv_hard_iface *hard_iface); | 1461 | struct batadv_algo_iface_ops iface; |
| 1310 | int (*bat_iface_enable)(struct batadv_hard_iface *hard_iface); | 1462 | struct batadv_algo_neigh_ops neigh; |
| 1311 | void (*bat_iface_disable)(struct batadv_hard_iface *hard_iface); | 1463 | struct batadv_algo_orig_ops orig; |
| 1312 | void (*bat_iface_update_mac)(struct batadv_hard_iface *hard_iface); | ||
| 1313 | void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface); | ||
| 1314 | /* neigh_node handling API */ | ||
| 1315 | void (*bat_hardif_neigh_init)(struct batadv_hardif_neigh_node *neigh); | ||
| 1316 | int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1, | ||
| 1317 | struct batadv_hard_iface *if_outgoing1, | ||
| 1318 | struct batadv_neigh_node *neigh2, | ||
| 1319 | struct batadv_hard_iface *if_outgoing2); | ||
| 1320 | bool (*bat_neigh_is_similar_or_better) | ||
| 1321 | (struct batadv_neigh_node *neigh1, | ||
| 1322 | struct batadv_hard_iface *if_outgoing1, | ||
| 1323 | struct batadv_neigh_node *neigh2, | ||
| 1324 | struct batadv_hard_iface *if_outgoing2); | ||
| 1325 | void (*bat_neigh_print)(struct batadv_priv *priv, struct seq_file *seq); | ||
| 1326 | /* orig_node handling API */ | ||
| 1327 | void (*bat_orig_print)(struct batadv_priv *priv, struct seq_file *seq, | ||
| 1328 | struct batadv_hard_iface *hard_iface); | ||
| 1329 | void (*bat_orig_free)(struct batadv_orig_node *orig_node); | ||
| 1330 | int (*bat_orig_add_if)(struct batadv_orig_node *orig_node, | ||
| 1331 | int max_if_num); | ||
| 1332 | int (*bat_orig_del_if)(struct batadv_orig_node *orig_node, | ||
| 1333 | int max_if_num, int del_if_num); | ||
| 1334 | }; | 1464 | }; |
| 1335 | 1465 | ||
| 1336 | /** | 1466 | /** |
