summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/batman-adv/Kconfig14
-rw-r--r--net/batman-adv/Makefile2
-rw-r--r--net/batman-adv/bat_algo.h15
-rw-r--r--net/batman-adv/bat_v.c74
-rw-r--r--net/batman-adv/bat_v_elp.c193
-rw-r--r--net/batman-adv/bat_v_elp.h27
-rw-r--r--net/batman-adv/main.c1
-rw-r--r--net/batman-adv/packet.h20
-rw-r--r--net/batman-adv/types.h18
9 files changed, 363 insertions, 1 deletions
diff --git a/net/batman-adv/Kconfig b/net/batman-adv/Kconfig
index 2dd40e5ea030..5c148a8489da 100644
--- a/net/batman-adv/Kconfig
+++ b/net/batman-adv/Kconfig
@@ -15,6 +15,20 @@ config BATMAN_ADV
15 https://www.open-mesh.org/ for more information and user space 15 https://www.open-mesh.org/ for more information and user space
16 tools. 16 tools.
17 17
18config BATMAN_ADV_BATMAN_V
19 bool "B.A.T.M.A.N. V protocol (experimental)"
20 depends on BATMAN_ADV
21 default n
22 help
23 This option enables the B.A.T.M.A.N. V protocol, the successor
24 of the currently used B.A.T.M.A.N. IV protocol. The main
25 changes include splitting of the OGM protocol into a neighbor
26 discovery protocol (Echo Location Protocol, ELP) and a new OGM
27 Protocol OGMv2 for flooding protocol information through the
28 network, as well as a throughput based metric.
29 B.A.T.M.A.N. V is currently considered experimental and not
30 compatible to B.A.T.M.A.N. IV networks.
31
18config BATMAN_ADV_BLA 32config BATMAN_ADV_BLA
19 bool "Bridge Loop Avoidance" 33 bool "Bridge Loop Avoidance"
20 depends on BATMAN_ADV && INET 34 depends on BATMAN_ADV && INET
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile
index 207e2af316c7..ca51686e9f72 100644
--- a/net/batman-adv/Makefile
+++ b/net/batman-adv/Makefile
@@ -18,6 +18,8 @@
18 18
19obj-$(CONFIG_BATMAN_ADV) += batman-adv.o 19obj-$(CONFIG_BATMAN_ADV) += batman-adv.o
20batman-adv-y += bat_iv_ogm.o 20batman-adv-y += bat_iv_ogm.o
21batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v.o
22batman-adv-$(CONFIG_BATMAN_ADV_BATMAN_V) += bat_v_elp.o
21batman-adv-y += bitarray.o 23batman-adv-y += bitarray.o
22batman-adv-$(CONFIG_BATMAN_ADV_BLA) += bridge_loop_avoidance.o 24batman-adv-$(CONFIG_BATMAN_ADV_BLA) += bridge_loop_avoidance.o
23batman-adv-$(CONFIG_DEBUG_FS) += debugfs.o 25batman-adv-$(CONFIG_DEBUG_FS) += debugfs.o
diff --git a/net/batman-adv/bat_algo.h b/net/batman-adv/bat_algo.h
index a7485d676088..a4e994e26da1 100644
--- a/net/batman-adv/bat_algo.h
+++ b/net/batman-adv/bat_algo.h
@@ -1,6 +1,6 @@
1/* Copyright (C) 2011-2016 B.A.T.M.A.N. contributors: 1/* Copyright (C) 2011-2016 B.A.T.M.A.N. contributors:
2 * 2 *
3 * Marek Lindner 3 * Marek Lindner, Linus Lüssing
4 * 4 *
5 * This program is free software; you can redistribute it and/or 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 6 * modify it under the terms of version 2 of the GNU General Public
@@ -20,4 +20,17 @@
20 20
21int batadv_iv_init(void); 21int batadv_iv_init(void);
22 22
23#ifdef CONFIG_BATMAN_ADV_BATMAN_V
24
25int batadv_v_init(void);
26
27#else
28
29static inline int batadv_v_init(void)
30{
31 return 0;
32}
33
34#endif /* CONFIG_BATMAN_ADV_BATMAN_V */
35
23#endif /* _NET_BATMAN_ADV_BAT_ALGO_H_ */ 36#endif /* _NET_BATMAN_ADV_BAT_ALGO_H_ */
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
new file mode 100644
index 000000000000..01327f627a08
--- /dev/null
+++ b/net/batman-adv/bat_v.c
@@ -0,0 +1,74 @@
1/* Copyright (C) 2013-2016 B.A.T.M.A.N. contributors:
2 *
3 * Linus Lüssing, 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 "bat_algo.h"
19#include "main.h"
20
21#include <linux/cache.h>
22#include <linux/init.h>
23
24#include "bat_v_elp.h"
25
26static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface)
27{
28 return batadv_v_elp_iface_enable(hard_iface);
29}
30
31static void batadv_v_iface_disable(struct batadv_hard_iface *hard_iface)
32{
33 batadv_v_elp_iface_disable(hard_iface);
34}
35
36static void batadv_v_iface_update_mac(struct batadv_hard_iface *hard_iface)
37{
38}
39
40static void batadv_v_primary_iface_set(struct batadv_hard_iface *hard_iface)
41{
42 batadv_v_elp_primary_iface_set(hard_iface);
43}
44
45static void batadv_v_ogm_schedule(struct batadv_hard_iface *hard_iface)
46{
47}
48
49static void batadv_v_ogm_emit(struct batadv_forw_packet *forw_packet)
50{
51}
52
53static struct batadv_algo_ops batadv_batman_v __read_mostly = {
54 .name = "BATMAN_V",
55 .bat_iface_enable = batadv_v_iface_enable,
56 .bat_iface_disable = batadv_v_iface_disable,
57 .bat_iface_update_mac = batadv_v_iface_update_mac,
58 .bat_primary_iface_set = batadv_v_primary_iface_set,
59 .bat_ogm_emit = batadv_v_ogm_emit,
60 .bat_ogm_schedule = batadv_v_ogm_schedule,
61};
62
63/**
64 * batadv_v_init - B.A.T.M.A.N. V initialization function
65 *
66 * Description: Takes care of initializing all the subcomponents.
67 * It is invoked upon module load only.
68 *
69 * Return: 0 on success or a negative error code otherwise
70 */
71int __init batadv_v_init(void)
72{
73 return batadv_algo_register(&batadv_batman_v);
74}
diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
new file mode 100644
index 000000000000..bc6e046c614c
--- /dev/null
+++ b/net/batman-adv/bat_v_elp.c
@@ -0,0 +1,193 @@
1/* Copyright (C) 2011-2016 B.A.T.M.A.N. contributors:
2 *
3 * Linus Lüssing, 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 "bat_v_elp.h"
19#include "main.h"
20
21#include <linux/atomic.h>
22#include <linux/byteorder/generic.h>
23#include <linux/errno.h>
24#include <linux/etherdevice.h>
25#include <linux/fs.h>
26#include <linux/if_ether.h>
27#include <linux/jiffies.h>
28#include <linux/kernel.h>
29#include <linux/netdevice.h>
30#include <linux/random.h>
31#include <linux/rculist.h>
32#include <linux/rcupdate.h>
33#include <linux/skbuff.h>
34#include <linux/stddef.h>
35#include <linux/string.h>
36#include <linux/types.h>
37#include <linux/workqueue.h>
38
39#include "bat_algo.h"
40#include "hard-interface.h"
41#include "packet.h"
42#include "send.h"
43
44/**
45 * batadv_v_elp_start_timer - restart timer for ELP periodic work
46 * @hard_iface: the interface for which the timer has to be reset
47 */
48static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface)
49{
50 unsigned int msecs;
51
52 msecs = atomic_read(&hard_iface->bat_v.elp_interval) - BATADV_JITTER;
53 msecs += prandom_u32() % (2 * BATADV_JITTER);
54
55 queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.elp_wq,
56 msecs_to_jiffies(msecs));
57}
58
59/**
60 * batadv_v_elp_periodic_work - ELP periodic task per interface
61 * @work: work queue item
62 *
63 * Emits broadcast ELP message in regular intervals.
64 */
65static void batadv_v_elp_periodic_work(struct work_struct *work)
66{
67 struct batadv_hard_iface *hard_iface;
68 struct batadv_hard_iface_bat_v *bat_v;
69 struct batadv_elp_packet *elp_packet;
70 struct batadv_priv *bat_priv;
71 struct sk_buff *skb;
72 u32 elp_interval;
73
74 bat_v = container_of(work, struct batadv_hard_iface_bat_v, elp_wq.work);
75 hard_iface = container_of(bat_v, struct batadv_hard_iface, bat_v);
76 bat_priv = netdev_priv(hard_iface->soft_iface);
77
78 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
79 goto out;
80
81 /* we are in the process of shutting this interface down */
82 if ((hard_iface->if_status == BATADV_IF_NOT_IN_USE) ||
83 (hard_iface->if_status == BATADV_IF_TO_BE_REMOVED))
84 goto out;
85
86 /* the interface was enabled but may not be ready yet */
87 if (hard_iface->if_status != BATADV_IF_ACTIVE)
88 goto restart_timer;
89
90 skb = skb_copy(hard_iface->bat_v.elp_skb, GFP_ATOMIC);
91 if (!skb)
92 goto restart_timer;
93
94 elp_packet = (struct batadv_elp_packet *)skb->data;
95 elp_packet->seqno = htonl(atomic_read(&hard_iface->bat_v.elp_seqno));
96 elp_interval = atomic_read(&hard_iface->bat_v.elp_interval);
97 elp_packet->elp_interval = htonl(elp_interval);
98
99 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
100 "Sending broadcast ELP packet on interface %s, seqno %u\n",
101 hard_iface->net_dev->name,
102 atomic_read(&hard_iface->bat_v.elp_seqno));
103
104 batadv_send_skb_packet(skb, hard_iface, batadv_broadcast_addr);
105
106 atomic_inc(&hard_iface->bat_v.elp_seqno);
107
108restart_timer:
109 batadv_v_elp_start_timer(hard_iface);
110out:
111 return;
112}
113
114/**
115 * batadv_v_elp_iface_enable - setup the ELP interface private resources
116 * @hard_iface: interface for which the data has to be prepared
117 *
118 * Return: 0 on success or a -ENOMEM in case of failure.
119 */
120int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface)
121{
122 struct batadv_elp_packet *elp_packet;
123 unsigned char *elp_buff;
124 u32 random_seqno;
125 size_t size;
126 int res = -ENOMEM;
127
128 size = ETH_HLEN + NET_IP_ALIGN + BATADV_ELP_HLEN;
129 hard_iface->bat_v.elp_skb = dev_alloc_skb(size);
130 if (!hard_iface->bat_v.elp_skb)
131 goto out;
132
133 skb_reserve(hard_iface->bat_v.elp_skb, ETH_HLEN + NET_IP_ALIGN);
134 elp_buff = skb_push(hard_iface->bat_v.elp_skb, BATADV_ELP_HLEN);
135 elp_packet = (struct batadv_elp_packet *)elp_buff;
136 memset(elp_packet, 0, BATADV_ELP_HLEN);
137
138 elp_packet->packet_type = BATADV_ELP;
139 elp_packet->version = BATADV_COMPAT_VERSION;
140
141 /* randomize initial seqno to avoid collision */
142 get_random_bytes(&random_seqno, sizeof(random_seqno));
143 atomic_set(&hard_iface->bat_v.elp_seqno, random_seqno);
144 atomic_set(&hard_iface->bat_v.elp_interval, 500);
145
146 INIT_DELAYED_WORK(&hard_iface->bat_v.elp_wq,
147 batadv_v_elp_periodic_work);
148 batadv_v_elp_start_timer(hard_iface);
149 res = 0;
150
151out:
152 return res;
153}
154
155/**
156 * batadv_v_elp_iface_disable - release ELP interface private resources
157 * @hard_iface: interface for which the resources have to be released
158 */
159void batadv_v_elp_iface_disable(struct batadv_hard_iface *hard_iface)
160{
161 cancel_delayed_work_sync(&hard_iface->bat_v.elp_wq);
162
163 dev_kfree_skb(hard_iface->bat_v.elp_skb);
164 hard_iface->bat_v.elp_skb = NULL;
165}
166
167/**
168 * batadv_v_elp_primary_iface_set - change internal data to reflect the new
169 * primary interface
170 * @primary_iface: the new primary interface
171 */
172void batadv_v_elp_primary_iface_set(struct batadv_hard_iface *primary_iface)
173{
174 struct batadv_hard_iface *hard_iface;
175 struct batadv_elp_packet *elp_packet;
176 struct sk_buff *skb;
177
178 /* update orig field of every elp iface belonging to this mesh */
179 rcu_read_lock();
180 list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
181 if (primary_iface->soft_iface != hard_iface->soft_iface)
182 continue;
183
184 if (!hard_iface->bat_v.elp_skb)
185 continue;
186
187 skb = hard_iface->bat_v.elp_skb;
188 elp_packet = (struct batadv_elp_packet *)skb->data;
189 ether_addr_copy(elp_packet->orig,
190 primary_iface->net_dev->dev_addr);
191 }
192 rcu_read_unlock();
193}
diff --git a/net/batman-adv/bat_v_elp.h b/net/batman-adv/bat_v_elp.h
new file mode 100644
index 000000000000..7a584d1f055b
--- /dev/null
+++ b/net/batman-adv/bat_v_elp.h
@@ -0,0 +1,27 @@
1/* Copyright (C) 2013-2016 B.A.T.M.A.N. contributors:
2 *
3 * Linus Lüssing, 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 "main.h"
19
20#ifndef _NET_BATMAN_ADV_BAT_V_ELP_H_
21#define _NET_BATMAN_ADV_BAT_V_ELP_H_
22
23int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface);
24void batadv_v_elp_iface_disable(struct batadv_hard_iface *hard_iface);
25void batadv_v_elp_primary_iface_set(struct batadv_hard_iface *primary_iface);
26
27#endif /* _NET_BATMAN_ADV_BAT_V_ELP_H_ */
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index e3d7051747b0..216057205e10 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -87,6 +87,7 @@ static int __init batadv_init(void)
87 87
88 batadv_recv_handler_init(); 88 batadv_recv_handler_init();
89 89
90 batadv_v_init();
90 batadv_iv_init(); 91 batadv_iv_init();
91 batadv_nc_init(); 92 batadv_nc_init();
92 93
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index e7f915181aba..c698b6452953 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -26,6 +26,7 @@
26 * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV 26 * @BATADV_IV_OGM: originator messages for B.A.T.M.A.N. IV
27 * @BATADV_BCAST: broadcast packets carrying broadcast payload 27 * @BATADV_BCAST: broadcast packets carrying broadcast payload
28 * @BATADV_CODED: network coded packets 28 * @BATADV_CODED: network coded packets
29 * @BATADV_ELP: echo location packets for B.A.T.M.A.N. V
29 * 30 *
30 * @BATADV_UNICAST: unicast packets carrying unicast payload traffic 31 * @BATADV_UNICAST: unicast packets carrying unicast payload traffic
31 * @BATADV_UNICAST_FRAG: unicast packets carrying a fragment of the original 32 * @BATADV_UNICAST_FRAG: unicast packets carrying a fragment of the original
@@ -40,6 +41,7 @@ enum batadv_packettype {
40 BATADV_IV_OGM = 0x00, 41 BATADV_IV_OGM = 0x00,
41 BATADV_BCAST = 0x01, 42 BATADV_BCAST = 0x01,
42 BATADV_CODED = 0x02, 43 BATADV_CODED = 0x02,
44 BATADV_ELP = 0x03,
43 /* 0x40 - 0x7f: unicast */ 45 /* 0x40 - 0x7f: unicast */
44#define BATADV_UNICAST_MIN 0x40 46#define BATADV_UNICAST_MIN 0x40
45 BATADV_UNICAST = 0x40, 47 BATADV_UNICAST = 0x40,
@@ -235,6 +237,24 @@ struct batadv_ogm_packet {
235#define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet) 237#define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)
236 238
237/** 239/**
240 * struct batadv_elp_packet - elp (neighbor discovery) packet
241 * @packet_type: batman-adv packet type, part of the general header
242 * @version: batman-adv protocol version, part of the genereal header
243 * @orig: originator mac address
244 * @seqno: sequence number
245 * @elp_interval: currently used ELP sending interval in ms
246 */
247struct batadv_elp_packet {
248 u8 packet_type;
249 u8 version;
250 u8 orig[ETH_ALEN];
251 __be32 seqno;
252 __be32 elp_interval;
253};
254
255#define BATADV_ELP_HLEN sizeof(struct batadv_elp_packet)
256
257/**
238 * struct batadv_icmp_header - common members among all the ICMP packets 258 * struct batadv_icmp_header - common members among all the ICMP packets
239 * @packet_type: batman-adv packet type, part of the general header 259 * @packet_type: batman-adv packet type, part of the general header
240 * @version: batman-adv protocol version, part of the genereal header 260 * @version: batman-adv protocol version, part of the genereal header
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 612de23178e6..992d5fd5554e 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -86,6 +86,20 @@ struct batadv_hard_iface_bat_iv {
86}; 86};
87 87
88/** 88/**
89 * struct batadv_hard_iface_bat_v - per hard-interface B.A.T.M.A.N. V data
90 * @elp_interval: time interval between two ELP transmissions
91 * @elp_seqno: current ELP sequence number
92 * @elp_skb: base skb containing the ELP message to send
93 * @elp_wq: workqueue used to schedule ELP transmissions
94 */
95struct batadv_hard_iface_bat_v {
96 atomic_t elp_interval;
97 atomic_t elp_seqno;
98 struct sk_buff *elp_skb;
99 struct delayed_work elp_wq;
100};
101
102/**
89 * struct batadv_hard_iface - network device known to batman-adv 103 * struct batadv_hard_iface - network device known to batman-adv
90 * @list: list node for batadv_hardif_list 104 * @list: list node for batadv_hardif_list
91 * @if_num: identificator of the interface 105 * @if_num: identificator of the interface
@@ -99,6 +113,7 @@ struct batadv_hard_iface_bat_iv {
99 * @soft_iface: the batman-adv interface which uses this network interface 113 * @soft_iface: the batman-adv interface which uses this network interface
100 * @rcu: struct used for freeing in an RCU-safe manner 114 * @rcu: struct used for freeing in an RCU-safe manner
101 * @bat_iv: per hard-interface B.A.T.M.A.N. IV data 115 * @bat_iv: per hard-interface B.A.T.M.A.N. IV data
116 * @bat_v: per hard-interface B.A.T.M.A.N. V data
102 * @cleanup_work: work queue callback item for hard-interface deinit 117 * @cleanup_work: work queue callback item for hard-interface deinit
103 * @debug_dir: dentry for nc subdir in batman-adv directory in debugfs 118 * @debug_dir: dentry for nc subdir in batman-adv directory in debugfs
104 * @neigh_list: list of unique single hop neighbors via this interface 119 * @neigh_list: list of unique single hop neighbors via this interface
@@ -116,6 +131,9 @@ struct batadv_hard_iface {
116 struct net_device *soft_iface; 131 struct net_device *soft_iface;
117 struct rcu_head rcu; 132 struct rcu_head rcu;
118 struct batadv_hard_iface_bat_iv bat_iv; 133 struct batadv_hard_iface_bat_iv bat_iv;
134#ifdef CONFIG_BATMAN_ADV_BATMAN_V
135 struct batadv_hard_iface_bat_v bat_v;
136#endif
119 struct work_struct cleanup_work; 137 struct work_struct cleanup_work;
120 struct dentry *debug_dir; 138 struct dentry *debug_dir;
121 struct hlist_head neigh_list; 139 struct hlist_head neigh_list;