diff options
author | David S. Miller <davem@davemloft.net> | 2011-09-21 20:44:50 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-09-21 20:44:50 -0400 |
commit | b7a17c0d846aab9f0e5d1dd3d005152c4ce459aa (patch) | |
tree | 0edaae4e84b8f98ea98316581d61f6dc73ce6bba | |
parent | 38034518c086fc48232b641cab97396a615864d0 (diff) | |
parent | ce43aa6c142d69820a267431ea342d1bd9f6d3ce (diff) |
Merge branch 'master' of github.com:davem330/net-next
-rw-r--r-- | Documentation/networking/batman-adv.txt | 8 | ||||
-rw-r--r-- | drivers/net/ethernet/apple/macmace.c | 9 | ||||
-rw-r--r-- | drivers/net/ethernet/natsemi/macsonic.c | 9 | ||||
-rw-r--r-- | drivers/net/ethernet/smsc/smsc911x.c | 2 | ||||
-rw-r--r-- | net/batman-adv/Makefile | 2 | ||||
-rw-r--r-- | net/batman-adv/aggregation.c | 293 | ||||
-rw-r--r-- | net/batman-adv/bat_iv_ogm.c | 1170 | ||||
-rw-r--r-- | net/batman-adv/bat_ogm.h (renamed from net/batman-adv/aggregation.h) | 30 | ||||
-rw-r--r-- | net/batman-adv/hard-interface.c | 54 | ||||
-rw-r--r-- | net/batman-adv/main.c | 2 | ||||
-rw-r--r-- | net/batman-adv/main.h | 2 | ||||
-rw-r--r-- | net/batman-adv/originator.c | 19 | ||||
-rw-r--r-- | net/batman-adv/packet.h | 18 | ||||
-rw-r--r-- | net/batman-adv/routing.c | 602 | ||||
-rw-r--r-- | net/batman-adv/routing.h | 17 | ||||
-rw-r--r-- | net/batman-adv/send.c | 305 | ||||
-rw-r--r-- | net/batman-adv/send.h | 9 | ||||
-rw-r--r-- | net/batman-adv/soft-interface.c | 21 | ||||
-rw-r--r-- | net/batman-adv/vis.c | 4 |
19 files changed, 1284 insertions, 1292 deletions
diff --git a/Documentation/networking/batman-adv.txt b/Documentation/networking/batman-adv.txt index 88d4afbdef98..c86d03f18a5b 100644 --- a/Documentation/networking/batman-adv.txt +++ b/Documentation/networking/batman-adv.txt | |||
@@ -1,4 +1,4 @@ | |||
1 | [state: 17-04-2011] | 1 | [state: 21-08-2011] |
2 | 2 | ||
3 | BATMAN-ADV | 3 | BATMAN-ADV |
4 | ---------- | 4 | ---------- |
@@ -68,9 +68,9 @@ All mesh wide settings can be found in batman's own interface | |||
68 | folder: | 68 | folder: |
69 | 69 | ||
70 | # ls /sys/class/net/bat0/mesh/ | 70 | # ls /sys/class/net/bat0/mesh/ |
71 | # aggregated_ogms gw_bandwidth hop_penalty | 71 | # aggregated_ogms fragmentation gw_sel_class vis_mode |
72 | # bonding gw_mode orig_interval | 72 | # ap_isolation gw_bandwidth hop_penalty |
73 | # fragmentation gw_sel_class vis_mode | 73 | # bonding gw_mode orig_interval |
74 | 74 | ||
75 | 75 | ||
76 | There is a special folder for debugging information: | 76 | There is a special folder for debugging information: |
diff --git a/drivers/net/ethernet/apple/macmace.c b/drivers/net/ethernet/apple/macmace.c index 6cd3f8646dcd..7cf81bbffe0e 100644 --- a/drivers/net/ethernet/apple/macmace.c +++ b/drivers/net/ethernet/apple/macmace.c | |||
@@ -31,9 +31,8 @@ | |||
31 | #include <linux/dma-mapping.h> | 31 | #include <linux/dma-mapping.h> |
32 | #include <linux/platform_device.h> | 32 | #include <linux/platform_device.h> |
33 | #include <linux/gfp.h> | 33 | #include <linux/gfp.h> |
34 | #include <linux/interrupt.h> | ||
34 | #include <asm/io.h> | 35 | #include <asm/io.h> |
35 | #include <asm/irq.h> | ||
36 | #include <asm/macintosh.h> | ||
37 | #include <asm/macints.h> | 36 | #include <asm/macints.h> |
38 | #include <asm/mac_psc.h> | 37 | #include <asm/mac_psc.h> |
39 | #include <asm/page.h> | 38 | #include <asm/page.h> |
@@ -203,14 +202,8 @@ static int __devinit mace_probe(struct platform_device *pdev) | |||
203 | unsigned char *addr; | 202 | unsigned char *addr; |
204 | struct net_device *dev; | 203 | struct net_device *dev; |
205 | unsigned char checksum = 0; | 204 | unsigned char checksum = 0; |
206 | static int found = 0; | ||
207 | int err; | 205 | int err; |
208 | 206 | ||
209 | if (found || macintosh_config->ether_type != MAC_ETHER_MACE) | ||
210 | return -ENODEV; | ||
211 | |||
212 | found = 1; /* prevent 'finding' one on every device probe */ | ||
213 | |||
214 | dev = alloc_etherdev(PRIV_BYTES); | 207 | dev = alloc_etherdev(PRIV_BYTES); |
215 | if (!dev) | 208 | if (!dev) |
216 | return -ENOMEM; | 209 | return -ENOMEM; |
diff --git a/drivers/net/ethernet/natsemi/macsonic.c b/drivers/net/ethernet/natsemi/macsonic.c index 5c36948e54d7..a2eacbfb4252 100644 --- a/drivers/net/ethernet/natsemi/macsonic.c +++ b/drivers/net/ethernet/natsemi/macsonic.c | |||
@@ -313,22 +313,13 @@ static void __devinit mac_onboard_sonic_ethernet_addr(struct net_device *dev) | |||
313 | 313 | ||
314 | static int __devinit mac_onboard_sonic_probe(struct net_device *dev) | 314 | static int __devinit mac_onboard_sonic_probe(struct net_device *dev) |
315 | { | 315 | { |
316 | /* Bwahahaha */ | ||
317 | static int once_is_more_than_enough; | ||
318 | struct sonic_local* lp = netdev_priv(dev); | 316 | struct sonic_local* lp = netdev_priv(dev); |
319 | int sr; | 317 | int sr; |
320 | int commslot = 0; | 318 | int commslot = 0; |
321 | 319 | ||
322 | if (once_is_more_than_enough) | ||
323 | return -ENODEV; | ||
324 | once_is_more_than_enough = 1; | ||
325 | |||
326 | if (!MACH_IS_MAC) | 320 | if (!MACH_IS_MAC) |
327 | return -ENODEV; | 321 | return -ENODEV; |
328 | 322 | ||
329 | if (macintosh_config->ether_type != MAC_ETHER_SONIC) | ||
330 | return -ENODEV; | ||
331 | |||
332 | printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. "); | 323 | printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. "); |
333 | 324 | ||
334 | /* Bogus probing, on the models which may or may not have | 325 | /* Bogus probing, on the models which may or may not have |
diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c index 788c4fdab9c2..a3aa4c0e87f3 100644 --- a/drivers/net/ethernet/smsc/smsc911x.c +++ b/drivers/net/ethernet/smsc/smsc911x.c | |||
@@ -2121,6 +2121,8 @@ static int __devinit smsc911x_probe_config_dt( | |||
2121 | of_property_read_u32(np, "reg-io-width", &width); | 2121 | of_property_read_u32(np, "reg-io-width", &width); |
2122 | if (width == 4) | 2122 | if (width == 4) |
2123 | config->flags |= SMSC911X_USE_32BIT; | 2123 | config->flags |= SMSC911X_USE_32BIT; |
2124 | else | ||
2125 | config->flags |= SMSC911X_USE_16BIT; | ||
2124 | 2126 | ||
2125 | if (of_get_property(np, "smsc,irq-active-high", NULL)) | 2127 | if (of_get_property(np, "smsc,irq-active-high", NULL)) |
2126 | config->irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH; | 2128 | config->irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH; |
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile index 2de93d00631b..ce6861166499 100644 --- a/net/batman-adv/Makefile +++ b/net/batman-adv/Makefile | |||
@@ -19,8 +19,8 @@ | |||
19 | # | 19 | # |
20 | 20 | ||
21 | obj-$(CONFIG_BATMAN_ADV) += batman-adv.o | 21 | obj-$(CONFIG_BATMAN_ADV) += batman-adv.o |
22 | batman-adv-y += aggregation.o | ||
23 | batman-adv-y += bat_debugfs.o | 22 | batman-adv-y += bat_debugfs.o |
23 | batman-adv-y += bat_iv_ogm.o | ||
24 | batman-adv-y += bat_sysfs.o | 24 | batman-adv-y += bat_sysfs.o |
25 | batman-adv-y += bitarray.o | 25 | batman-adv-y += bitarray.o |
26 | batman-adv-y += gateway_client.o | 26 | batman-adv-y += gateway_client.o |
diff --git a/net/batman-adv/aggregation.c b/net/batman-adv/aggregation.c deleted file mode 100644 index 69467fe71ff2..000000000000 --- a/net/batman-adv/aggregation.c +++ /dev/null | |||
@@ -1,293 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: | ||
3 | * | ||
4 | * Marek Lindner, Simon Wunderlich | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of version 2 of the GNU General Public | ||
8 | * License as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but | ||
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
18 | * 02110-1301, USA | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include "main.h" | ||
23 | #include "translation-table.h" | ||
24 | #include "aggregation.h" | ||
25 | #include "send.h" | ||
26 | #include "routing.h" | ||
27 | #include "hard-interface.h" | ||
28 | |||
29 | /* return true if new_packet can be aggregated with forw_packet */ | ||
30 | static bool can_aggregate_with(const struct batman_packet *new_batman_packet, | ||
31 | struct bat_priv *bat_priv, | ||
32 | int packet_len, | ||
33 | unsigned long send_time, | ||
34 | bool directlink, | ||
35 | const struct hard_iface *if_incoming, | ||
36 | const struct forw_packet *forw_packet) | ||
37 | { | ||
38 | struct batman_packet *batman_packet = | ||
39 | (struct batman_packet *)forw_packet->skb->data; | ||
40 | int aggregated_bytes = forw_packet->packet_len + packet_len; | ||
41 | struct hard_iface *primary_if = NULL; | ||
42 | bool res = false; | ||
43 | |||
44 | /** | ||
45 | * we can aggregate the current packet to this aggregated packet | ||
46 | * if: | ||
47 | * | ||
48 | * - the send time is within our MAX_AGGREGATION_MS time | ||
49 | * - the resulting packet wont be bigger than | ||
50 | * MAX_AGGREGATION_BYTES | ||
51 | */ | ||
52 | |||
53 | if (time_before(send_time, forw_packet->send_time) && | ||
54 | time_after_eq(send_time + msecs_to_jiffies(MAX_AGGREGATION_MS), | ||
55 | forw_packet->send_time) && | ||
56 | (aggregated_bytes <= MAX_AGGREGATION_BYTES)) { | ||
57 | |||
58 | /** | ||
59 | * check aggregation compatibility | ||
60 | * -> direct link packets are broadcasted on | ||
61 | * their interface only | ||
62 | * -> aggregate packet if the current packet is | ||
63 | * a "global" packet as well as the base | ||
64 | * packet | ||
65 | */ | ||
66 | |||
67 | primary_if = primary_if_get_selected(bat_priv); | ||
68 | if (!primary_if) | ||
69 | goto out; | ||
70 | |||
71 | /* packets without direct link flag and high TTL | ||
72 | * are flooded through the net */ | ||
73 | if ((!directlink) && | ||
74 | (!(batman_packet->flags & DIRECTLINK)) && | ||
75 | (batman_packet->ttl != 1) && | ||
76 | |||
77 | /* own packets originating non-primary | ||
78 | * interfaces leave only that interface */ | ||
79 | ((!forw_packet->own) || | ||
80 | (forw_packet->if_incoming == primary_if))) { | ||
81 | res = true; | ||
82 | goto out; | ||
83 | } | ||
84 | |||
85 | /* if the incoming packet is sent via this one | ||
86 | * interface only - we still can aggregate */ | ||
87 | if ((directlink) && | ||
88 | (new_batman_packet->ttl == 1) && | ||
89 | (forw_packet->if_incoming == if_incoming) && | ||
90 | |||
91 | /* packets from direct neighbors or | ||
92 | * own secondary interface packets | ||
93 | * (= secondary interface packets in general) */ | ||
94 | (batman_packet->flags & DIRECTLINK || | ||
95 | (forw_packet->own && | ||
96 | forw_packet->if_incoming != primary_if))) { | ||
97 | res = true; | ||
98 | goto out; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | out: | ||
103 | if (primary_if) | ||
104 | hardif_free_ref(primary_if); | ||
105 | return res; | ||
106 | } | ||
107 | |||
108 | /* create a new aggregated packet and add this packet to it */ | ||
109 | static void new_aggregated_packet(const unsigned char *packet_buff, | ||
110 | int packet_len, unsigned long send_time, | ||
111 | bool direct_link, | ||
112 | struct hard_iface *if_incoming, | ||
113 | int own_packet) | ||
114 | { | ||
115 | struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
116 | struct forw_packet *forw_packet_aggr; | ||
117 | unsigned char *skb_buff; | ||
118 | |||
119 | if (!atomic_inc_not_zero(&if_incoming->refcount)) | ||
120 | return; | ||
121 | |||
122 | /* own packet should always be scheduled */ | ||
123 | if (!own_packet) { | ||
124 | if (!atomic_dec_not_zero(&bat_priv->batman_queue_left)) { | ||
125 | bat_dbg(DBG_BATMAN, bat_priv, | ||
126 | "batman packet queue full\n"); | ||
127 | goto out; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | forw_packet_aggr = kmalloc(sizeof(*forw_packet_aggr), GFP_ATOMIC); | ||
132 | if (!forw_packet_aggr) { | ||
133 | if (!own_packet) | ||
134 | atomic_inc(&bat_priv->batman_queue_left); | ||
135 | goto out; | ||
136 | } | ||
137 | |||
138 | if ((atomic_read(&bat_priv->aggregated_ogms)) && | ||
139 | (packet_len < MAX_AGGREGATION_BYTES)) | ||
140 | forw_packet_aggr->skb = dev_alloc_skb(MAX_AGGREGATION_BYTES + | ||
141 | sizeof(struct ethhdr)); | ||
142 | else | ||
143 | forw_packet_aggr->skb = dev_alloc_skb(packet_len + | ||
144 | sizeof(struct ethhdr)); | ||
145 | |||
146 | if (!forw_packet_aggr->skb) { | ||
147 | if (!own_packet) | ||
148 | atomic_inc(&bat_priv->batman_queue_left); | ||
149 | kfree(forw_packet_aggr); | ||
150 | goto out; | ||
151 | } | ||
152 | skb_reserve(forw_packet_aggr->skb, sizeof(struct ethhdr)); | ||
153 | |||
154 | INIT_HLIST_NODE(&forw_packet_aggr->list); | ||
155 | |||
156 | skb_buff = skb_put(forw_packet_aggr->skb, packet_len); | ||
157 | forw_packet_aggr->packet_len = packet_len; | ||
158 | memcpy(skb_buff, packet_buff, packet_len); | ||
159 | |||
160 | forw_packet_aggr->own = own_packet; | ||
161 | forw_packet_aggr->if_incoming = if_incoming; | ||
162 | forw_packet_aggr->num_packets = 0; | ||
163 | forw_packet_aggr->direct_link_flags = NO_FLAGS; | ||
164 | forw_packet_aggr->send_time = send_time; | ||
165 | |||
166 | /* save packet direct link flag status */ | ||
167 | if (direct_link) | ||
168 | forw_packet_aggr->direct_link_flags |= 1; | ||
169 | |||
170 | /* add new packet to packet list */ | ||
171 | spin_lock_bh(&bat_priv->forw_bat_list_lock); | ||
172 | hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list); | ||
173 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); | ||
174 | |||
175 | /* start timer for this packet */ | ||
176 | INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work, | ||
177 | send_outstanding_bat_packet); | ||
178 | queue_delayed_work(bat_event_workqueue, | ||
179 | &forw_packet_aggr->delayed_work, | ||
180 | send_time - jiffies); | ||
181 | |||
182 | return; | ||
183 | out: | ||
184 | hardif_free_ref(if_incoming); | ||
185 | } | ||
186 | |||
187 | /* aggregate a new packet into the existing aggregation */ | ||
188 | static void aggregate(struct forw_packet *forw_packet_aggr, | ||
189 | const unsigned char *packet_buff, int packet_len, | ||
190 | bool direct_link) | ||
191 | { | ||
192 | unsigned char *skb_buff; | ||
193 | |||
194 | skb_buff = skb_put(forw_packet_aggr->skb, packet_len); | ||
195 | memcpy(skb_buff, packet_buff, packet_len); | ||
196 | forw_packet_aggr->packet_len += packet_len; | ||
197 | forw_packet_aggr->num_packets++; | ||
198 | |||
199 | /* save packet direct link flag status */ | ||
200 | if (direct_link) | ||
201 | forw_packet_aggr->direct_link_flags |= | ||
202 | (1 << forw_packet_aggr->num_packets); | ||
203 | } | ||
204 | |||
205 | void add_bat_packet_to_list(struct bat_priv *bat_priv, | ||
206 | unsigned char *packet_buff, int packet_len, | ||
207 | struct hard_iface *if_incoming, int own_packet, | ||
208 | unsigned long send_time) | ||
209 | { | ||
210 | /** | ||
211 | * _aggr -> pointer to the packet we want to aggregate with | ||
212 | * _pos -> pointer to the position in the queue | ||
213 | */ | ||
214 | struct forw_packet *forw_packet_aggr = NULL, *forw_packet_pos = NULL; | ||
215 | struct hlist_node *tmp_node; | ||
216 | struct batman_packet *batman_packet = | ||
217 | (struct batman_packet *)packet_buff; | ||
218 | bool direct_link = batman_packet->flags & DIRECTLINK ? 1 : 0; | ||
219 | |||
220 | /* find position for the packet in the forward queue */ | ||
221 | spin_lock_bh(&bat_priv->forw_bat_list_lock); | ||
222 | /* own packets are not to be aggregated */ | ||
223 | if ((atomic_read(&bat_priv->aggregated_ogms)) && (!own_packet)) { | ||
224 | hlist_for_each_entry(forw_packet_pos, tmp_node, | ||
225 | &bat_priv->forw_bat_list, list) { | ||
226 | if (can_aggregate_with(batman_packet, | ||
227 | bat_priv, | ||
228 | packet_len, | ||
229 | send_time, | ||
230 | direct_link, | ||
231 | if_incoming, | ||
232 | forw_packet_pos)) { | ||
233 | forw_packet_aggr = forw_packet_pos; | ||
234 | break; | ||
235 | } | ||
236 | } | ||
237 | } | ||
238 | |||
239 | /* nothing to aggregate with - either aggregation disabled or no | ||
240 | * suitable aggregation packet found */ | ||
241 | if (!forw_packet_aggr) { | ||
242 | /* the following section can run without the lock */ | ||
243 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); | ||
244 | |||
245 | /** | ||
246 | * if we could not aggregate this packet with one of the others | ||
247 | * we hold it back for a while, so that it might be aggregated | ||
248 | * later on | ||
249 | */ | ||
250 | if ((!own_packet) && | ||
251 | (atomic_read(&bat_priv->aggregated_ogms))) | ||
252 | send_time += msecs_to_jiffies(MAX_AGGREGATION_MS); | ||
253 | |||
254 | new_aggregated_packet(packet_buff, packet_len, | ||
255 | send_time, direct_link, | ||
256 | if_incoming, own_packet); | ||
257 | } else { | ||
258 | aggregate(forw_packet_aggr, | ||
259 | packet_buff, packet_len, | ||
260 | direct_link); | ||
261 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); | ||
262 | } | ||
263 | } | ||
264 | |||
265 | /* unpack the aggregated packets and process them one by one */ | ||
266 | void receive_aggr_bat_packet(const struct ethhdr *ethhdr, | ||
267 | unsigned char *packet_buff, int packet_len, | ||
268 | struct hard_iface *if_incoming) | ||
269 | { | ||
270 | struct batman_packet *batman_packet; | ||
271 | int buff_pos = 0; | ||
272 | unsigned char *tt_buff; | ||
273 | |||
274 | batman_packet = (struct batman_packet *)packet_buff; | ||
275 | |||
276 | do { | ||
277 | /* network to host order for our 32bit seqno and the | ||
278 | orig_interval */ | ||
279 | batman_packet->seqno = ntohl(batman_packet->seqno); | ||
280 | batman_packet->tt_crc = ntohs(batman_packet->tt_crc); | ||
281 | |||
282 | tt_buff = packet_buff + buff_pos + BAT_PACKET_LEN; | ||
283 | |||
284 | receive_bat_packet(ethhdr, batman_packet, tt_buff, if_incoming); | ||
285 | |||
286 | buff_pos += BAT_PACKET_LEN + | ||
287 | tt_len(batman_packet->tt_num_changes); | ||
288 | |||
289 | batman_packet = (struct batman_packet *) | ||
290 | (packet_buff + buff_pos); | ||
291 | } while (aggregated_packet(buff_pos, packet_len, | ||
292 | batman_packet->tt_num_changes)); | ||
293 | } | ||
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c new file mode 100644 index 000000000000..3512e251545b --- /dev/null +++ b/net/batman-adv/bat_iv_ogm.c | |||
@@ -0,0 +1,1170 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: | ||
3 | * | ||
4 | * Marek Lindner, Simon Wunderlich | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of version 2 of the GNU General Public | ||
8 | * License as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, but | ||
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
18 | * 02110-1301, USA | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include "main.h" | ||
23 | #include "bat_ogm.h" | ||
24 | #include "translation-table.h" | ||
25 | #include "ring_buffer.h" | ||
26 | #include "originator.h" | ||
27 | #include "routing.h" | ||
28 | #include "gateway_common.h" | ||
29 | #include "gateway_client.h" | ||
30 | #include "hard-interface.h" | ||
31 | #include "send.h" | ||
32 | |||
33 | void bat_ogm_init(struct hard_iface *hard_iface) | ||
34 | { | ||
35 | struct batman_ogm_packet *batman_ogm_packet; | ||
36 | |||
37 | hard_iface->packet_len = BATMAN_OGM_LEN; | ||
38 | hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC); | ||
39 | |||
40 | batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; | ||
41 | batman_ogm_packet->packet_type = BAT_OGM; | ||
42 | batman_ogm_packet->version = COMPAT_VERSION; | ||
43 | batman_ogm_packet->flags = NO_FLAGS; | ||
44 | batman_ogm_packet->ttl = 2; | ||
45 | batman_ogm_packet->tq = TQ_MAX_VALUE; | ||
46 | batman_ogm_packet->tt_num_changes = 0; | ||
47 | batman_ogm_packet->ttvn = 0; | ||
48 | } | ||
49 | |||
50 | void bat_ogm_init_primary(struct hard_iface *hard_iface) | ||
51 | { | ||
52 | struct batman_ogm_packet *batman_ogm_packet; | ||
53 | |||
54 | batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; | ||
55 | batman_ogm_packet->flags = PRIMARIES_FIRST_HOP; | ||
56 | batman_ogm_packet->ttl = TTL; | ||
57 | } | ||
58 | |||
59 | void bat_ogm_update_mac(struct hard_iface *hard_iface) | ||
60 | { | ||
61 | struct batman_ogm_packet *batman_ogm_packet; | ||
62 | |||
63 | batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; | ||
64 | memcpy(batman_ogm_packet->orig, | ||
65 | hard_iface->net_dev->dev_addr, ETH_ALEN); | ||
66 | memcpy(batman_ogm_packet->prev_sender, | ||
67 | hard_iface->net_dev->dev_addr, ETH_ALEN); | ||
68 | } | ||
69 | |||
70 | /* when do we schedule our own ogm to be sent */ | ||
71 | static unsigned long bat_ogm_emit_send_time(const struct bat_priv *bat_priv) | ||
72 | { | ||
73 | return jiffies + msecs_to_jiffies( | ||
74 | atomic_read(&bat_priv->orig_interval) - | ||
75 | JITTER + (random32() % 2*JITTER)); | ||
76 | } | ||
77 | |||
78 | /* when do we schedule a ogm packet to be sent */ | ||
79 | static unsigned long bat_ogm_fwd_send_time(void) | ||
80 | { | ||
81 | return jiffies + msecs_to_jiffies(random32() % (JITTER/2)); | ||
82 | } | ||
83 | |||
84 | /* apply hop penalty for a normal link */ | ||
85 | static uint8_t hop_penalty(uint8_t tq, const struct bat_priv *bat_priv) | ||
86 | { | ||
87 | int hop_penalty = atomic_read(&bat_priv->hop_penalty); | ||
88 | return (tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE); | ||
89 | } | ||
90 | |||
91 | /* is there another aggregated packet here? */ | ||
92 | static int bat_ogm_aggr_packet(int buff_pos, int packet_len, | ||
93 | int tt_num_changes) | ||
94 | { | ||
95 | int next_buff_pos = buff_pos + BATMAN_OGM_LEN + tt_len(tt_num_changes); | ||
96 | |||
97 | return (next_buff_pos <= packet_len) && | ||
98 | (next_buff_pos <= MAX_AGGREGATION_BYTES); | ||
99 | } | ||
100 | |||
101 | /* send a batman ogm to a given interface */ | ||
102 | static void bat_ogm_send_to_if(struct forw_packet *forw_packet, | ||
103 | struct hard_iface *hard_iface) | ||
104 | { | ||
105 | struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); | ||
106 | char *fwd_str; | ||
107 | uint8_t packet_num; | ||
108 | int16_t buff_pos; | ||
109 | struct batman_ogm_packet *batman_ogm_packet; | ||
110 | struct sk_buff *skb; | ||
111 | |||
112 | if (hard_iface->if_status != IF_ACTIVE) | ||
113 | return; | ||
114 | |||
115 | packet_num = 0; | ||
116 | buff_pos = 0; | ||
117 | batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data; | ||
118 | |||
119 | /* adjust all flags and log packets */ | ||
120 | while (bat_ogm_aggr_packet(buff_pos, forw_packet->packet_len, | ||
121 | batman_ogm_packet->tt_num_changes)) { | ||
122 | |||
123 | /* we might have aggregated direct link packets with an | ||
124 | * ordinary base packet */ | ||
125 | if ((forw_packet->direct_link_flags & (1 << packet_num)) && | ||
126 | (forw_packet->if_incoming == hard_iface)) | ||
127 | batman_ogm_packet->flags |= DIRECTLINK; | ||
128 | else | ||
129 | batman_ogm_packet->flags &= ~DIRECTLINK; | ||
130 | |||
131 | fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ? | ||
132 | "Sending own" : | ||
133 | "Forwarding")); | ||
134 | bat_dbg(DBG_BATMAN, bat_priv, | ||
135 | "%s %spacket (originator %pM, seqno %d, TQ %d, TTL %d," | ||
136 | " IDF %s, ttvn %d) on interface %s [%pM]\n", | ||
137 | fwd_str, (packet_num > 0 ? "aggregated " : ""), | ||
138 | batman_ogm_packet->orig, | ||
139 | ntohl(batman_ogm_packet->seqno), | ||
140 | batman_ogm_packet->tq, batman_ogm_packet->ttl, | ||
141 | (batman_ogm_packet->flags & DIRECTLINK ? | ||
142 | "on" : "off"), | ||
143 | batman_ogm_packet->ttvn, hard_iface->net_dev->name, | ||
144 | hard_iface->net_dev->dev_addr); | ||
145 | |||
146 | buff_pos += BATMAN_OGM_LEN + | ||
147 | tt_len(batman_ogm_packet->tt_num_changes); | ||
148 | packet_num++; | ||
149 | batman_ogm_packet = (struct batman_ogm_packet *) | ||
150 | (forw_packet->skb->data + buff_pos); | ||
151 | } | ||
152 | |||
153 | /* create clone because function is called more than once */ | ||
154 | skb = skb_clone(forw_packet->skb, GFP_ATOMIC); | ||
155 | if (skb) | ||
156 | send_skb_packet(skb, hard_iface, broadcast_addr); | ||
157 | } | ||
158 | |||
159 | /* send a batman ogm packet */ | ||
160 | void bat_ogm_emit(struct forw_packet *forw_packet) | ||
161 | { | ||
162 | struct hard_iface *hard_iface; | ||
163 | struct net_device *soft_iface; | ||
164 | struct bat_priv *bat_priv; | ||
165 | struct hard_iface *primary_if = NULL; | ||
166 | struct batman_ogm_packet *batman_ogm_packet; | ||
167 | unsigned char directlink; | ||
168 | |||
169 | batman_ogm_packet = (struct batman_ogm_packet *) | ||
170 | (forw_packet->skb->data); | ||
171 | directlink = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0); | ||
172 | |||
173 | if (!forw_packet->if_incoming) { | ||
174 | pr_err("Error - can't forward packet: incoming iface not " | ||
175 | "specified\n"); | ||
176 | goto out; | ||
177 | } | ||
178 | |||
179 | soft_iface = forw_packet->if_incoming->soft_iface; | ||
180 | bat_priv = netdev_priv(soft_iface); | ||
181 | |||
182 | if (forw_packet->if_incoming->if_status != IF_ACTIVE) | ||
183 | goto out; | ||
184 | |||
185 | primary_if = primary_if_get_selected(bat_priv); | ||
186 | if (!primary_if) | ||
187 | goto out; | ||
188 | |||
189 | /* multihomed peer assumed */ | ||
190 | /* non-primary OGMs are only broadcasted on their interface */ | ||
191 | if ((directlink && (batman_ogm_packet->ttl == 1)) || | ||
192 | (forw_packet->own && (forw_packet->if_incoming != primary_if))) { | ||
193 | |||
194 | /* FIXME: what about aggregated packets ? */ | ||
195 | bat_dbg(DBG_BATMAN, bat_priv, | ||
196 | "%s packet (originator %pM, seqno %d, TTL %d) " | ||
197 | "on interface %s [%pM]\n", | ||
198 | (forw_packet->own ? "Sending own" : "Forwarding"), | ||
199 | batman_ogm_packet->orig, | ||
200 | ntohl(batman_ogm_packet->seqno), | ||
201 | batman_ogm_packet->ttl, | ||
202 | forw_packet->if_incoming->net_dev->name, | ||
203 | forw_packet->if_incoming->net_dev->dev_addr); | ||
204 | |||
205 | /* skb is only used once and than forw_packet is free'd */ | ||
206 | send_skb_packet(forw_packet->skb, forw_packet->if_incoming, | ||
207 | broadcast_addr); | ||
208 | forw_packet->skb = NULL; | ||
209 | |||
210 | goto out; | ||
211 | } | ||
212 | |||
213 | /* broadcast on every interface */ | ||
214 | rcu_read_lock(); | ||
215 | list_for_each_entry_rcu(hard_iface, &hardif_list, list) { | ||
216 | if (hard_iface->soft_iface != soft_iface) | ||
217 | continue; | ||
218 | |||
219 | bat_ogm_send_to_if(forw_packet, hard_iface); | ||
220 | } | ||
221 | rcu_read_unlock(); | ||
222 | |||
223 | out: | ||
224 | if (primary_if) | ||
225 | hardif_free_ref(primary_if); | ||
226 | } | ||
227 | |||
228 | /* return true if new_packet can be aggregated with forw_packet */ | ||
229 | static bool bat_ogm_can_aggregate(const struct batman_ogm_packet | ||
230 | *new_batman_ogm_packet, | ||
231 | struct bat_priv *bat_priv, | ||
232 | int packet_len, unsigned long send_time, | ||
233 | bool directlink, | ||
234 | const struct hard_iface *if_incoming, | ||
235 | const struct forw_packet *forw_packet) | ||
236 | { | ||
237 | struct batman_ogm_packet *batman_ogm_packet; | ||
238 | int aggregated_bytes = forw_packet->packet_len + packet_len; | ||
239 | struct hard_iface *primary_if = NULL; | ||
240 | bool res = false; | ||
241 | |||
242 | batman_ogm_packet = (struct batman_ogm_packet *)forw_packet->skb->data; | ||
243 | |||
244 | /** | ||
245 | * we can aggregate the current packet to this aggregated packet | ||
246 | * if: | ||
247 | * | ||
248 | * - the send time is within our MAX_AGGREGATION_MS time | ||
249 | * - the resulting packet wont be bigger than | ||
250 | * MAX_AGGREGATION_BYTES | ||
251 | */ | ||
252 | |||
253 | if (time_before(send_time, forw_packet->send_time) && | ||
254 | time_after_eq(send_time + msecs_to_jiffies(MAX_AGGREGATION_MS), | ||
255 | forw_packet->send_time) && | ||
256 | (aggregated_bytes <= MAX_AGGREGATION_BYTES)) { | ||
257 | |||
258 | /** | ||
259 | * check aggregation compatibility | ||
260 | * -> direct link packets are broadcasted on | ||
261 | * their interface only | ||
262 | * -> aggregate packet if the current packet is | ||
263 | * a "global" packet as well as the base | ||
264 | * packet | ||
265 | */ | ||
266 | |||
267 | primary_if = primary_if_get_selected(bat_priv); | ||
268 | if (!primary_if) | ||
269 | goto out; | ||
270 | |||
271 | /* packets without direct link flag and high TTL | ||
272 | * are flooded through the net */ | ||
273 | if ((!directlink) && | ||
274 | (!(batman_ogm_packet->flags & DIRECTLINK)) && | ||
275 | (batman_ogm_packet->ttl != 1) && | ||
276 | |||
277 | /* own packets originating non-primary | ||
278 | * interfaces leave only that interface */ | ||
279 | ((!forw_packet->own) || | ||
280 | (forw_packet->if_incoming == primary_if))) { | ||
281 | res = true; | ||
282 | goto out; | ||
283 | } | ||
284 | |||
285 | /* if the incoming packet is sent via this one | ||
286 | * interface only - we still can aggregate */ | ||
287 | if ((directlink) && | ||
288 | (new_batman_ogm_packet->ttl == 1) && | ||
289 | (forw_packet->if_incoming == if_incoming) && | ||
290 | |||
291 | /* packets from direct neighbors or | ||
292 | * own secondary interface packets | ||
293 | * (= secondary interface packets in general) */ | ||
294 | (batman_ogm_packet->flags & DIRECTLINK || | ||
295 | (forw_packet->own && | ||
296 | forw_packet->if_incoming != primary_if))) { | ||
297 | res = true; | ||
298 | goto out; | ||
299 | } | ||
300 | } | ||
301 | |||
302 | out: | ||
303 | if (primary_if) | ||
304 | hardif_free_ref(primary_if); | ||
305 | return res; | ||
306 | } | ||
307 | |||
308 | /* create a new aggregated packet and add this packet to it */ | ||
309 | static void bat_ogm_aggregate_new(const unsigned char *packet_buff, | ||
310 | int packet_len, unsigned long send_time, | ||
311 | bool direct_link, | ||
312 | struct hard_iface *if_incoming, | ||
313 | int own_packet) | ||
314 | { | ||
315 | struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
316 | struct forw_packet *forw_packet_aggr; | ||
317 | unsigned char *skb_buff; | ||
318 | |||
319 | if (!atomic_inc_not_zero(&if_incoming->refcount)) | ||
320 | return; | ||
321 | |||
322 | /* own packet should always be scheduled */ | ||
323 | if (!own_packet) { | ||
324 | if (!atomic_dec_not_zero(&bat_priv->batman_queue_left)) { | ||
325 | bat_dbg(DBG_BATMAN, bat_priv, | ||
326 | "batman packet queue full\n"); | ||
327 | goto out; | ||
328 | } | ||
329 | } | ||
330 | |||
331 | forw_packet_aggr = kmalloc(sizeof(*forw_packet_aggr), GFP_ATOMIC); | ||
332 | if (!forw_packet_aggr) { | ||
333 | if (!own_packet) | ||
334 | atomic_inc(&bat_priv->batman_queue_left); | ||
335 | goto out; | ||
336 | } | ||
337 | |||
338 | if ((atomic_read(&bat_priv->aggregated_ogms)) && | ||
339 | (packet_len < MAX_AGGREGATION_BYTES)) | ||
340 | forw_packet_aggr->skb = dev_alloc_skb(MAX_AGGREGATION_BYTES + | ||
341 | sizeof(struct ethhdr)); | ||
342 | else | ||
343 | forw_packet_aggr->skb = dev_alloc_skb(packet_len + | ||
344 | sizeof(struct ethhdr)); | ||
345 | |||
346 | if (!forw_packet_aggr->skb) { | ||
347 | if (!own_packet) | ||
348 | atomic_inc(&bat_priv->batman_queue_left); | ||
349 | kfree(forw_packet_aggr); | ||
350 | goto out; | ||
351 | } | ||
352 | skb_reserve(forw_packet_aggr->skb, sizeof(struct ethhdr)); | ||
353 | |||
354 | INIT_HLIST_NODE(&forw_packet_aggr->list); | ||
355 | |||
356 | skb_buff = skb_put(forw_packet_aggr->skb, packet_len); | ||
357 | forw_packet_aggr->packet_len = packet_len; | ||
358 | memcpy(skb_buff, packet_buff, packet_len); | ||
359 | |||
360 | forw_packet_aggr->own = own_packet; | ||
361 | forw_packet_aggr->if_incoming = if_incoming; | ||
362 | forw_packet_aggr->num_packets = 0; | ||
363 | forw_packet_aggr->direct_link_flags = NO_FLAGS; | ||
364 | forw_packet_aggr->send_time = send_time; | ||
365 | |||
366 | /* save packet direct link flag status */ | ||
367 | if (direct_link) | ||
368 | forw_packet_aggr->direct_link_flags |= 1; | ||
369 | |||
370 | /* add new packet to packet list */ | ||
371 | spin_lock_bh(&bat_priv->forw_bat_list_lock); | ||
372 | hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list); | ||
373 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); | ||
374 | |||
375 | /* start timer for this packet */ | ||
376 | INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work, | ||
377 | send_outstanding_bat_ogm_packet); | ||
378 | queue_delayed_work(bat_event_workqueue, | ||
379 | &forw_packet_aggr->delayed_work, | ||
380 | send_time - jiffies); | ||
381 | |||
382 | return; | ||
383 | out: | ||
384 | hardif_free_ref(if_incoming); | ||
385 | } | ||
386 | |||
387 | /* aggregate a new packet into the existing ogm packet */ | ||
388 | static void bat_ogm_aggregate(struct forw_packet *forw_packet_aggr, | ||
389 | const unsigned char *packet_buff, | ||
390 | int packet_len, bool direct_link) | ||
391 | { | ||
392 | unsigned char *skb_buff; | ||
393 | |||
394 | skb_buff = skb_put(forw_packet_aggr->skb, packet_len); | ||
395 | memcpy(skb_buff, packet_buff, packet_len); | ||
396 | forw_packet_aggr->packet_len += packet_len; | ||
397 | forw_packet_aggr->num_packets++; | ||
398 | |||
399 | /* save packet direct link flag status */ | ||
400 | if (direct_link) | ||
401 | forw_packet_aggr->direct_link_flags |= | ||
402 | (1 << forw_packet_aggr->num_packets); | ||
403 | } | ||
404 | |||
405 | static void bat_ogm_queue_add(struct bat_priv *bat_priv, | ||
406 | unsigned char *packet_buff, | ||
407 | int packet_len, struct hard_iface *if_incoming, | ||
408 | int own_packet, unsigned long send_time) | ||
409 | { | ||
410 | /** | ||
411 | * _aggr -> pointer to the packet we want to aggregate with | ||
412 | * _pos -> pointer to the position in the queue | ||
413 | */ | ||
414 | struct forw_packet *forw_packet_aggr = NULL, *forw_packet_pos = NULL; | ||
415 | struct hlist_node *tmp_node; | ||
416 | struct batman_ogm_packet *batman_ogm_packet; | ||
417 | bool direct_link; | ||
418 | |||
419 | batman_ogm_packet = (struct batman_ogm_packet *)packet_buff; | ||
420 | direct_link = batman_ogm_packet->flags & DIRECTLINK ? 1 : 0; | ||
421 | |||
422 | /* find position for the packet in the forward queue */ | ||
423 | spin_lock_bh(&bat_priv->forw_bat_list_lock); | ||
424 | /* own packets are not to be aggregated */ | ||
425 | if ((atomic_read(&bat_priv->aggregated_ogms)) && (!own_packet)) { | ||
426 | hlist_for_each_entry(forw_packet_pos, tmp_node, | ||
427 | &bat_priv->forw_bat_list, list) { | ||
428 | if (bat_ogm_can_aggregate(batman_ogm_packet, | ||
429 | bat_priv, packet_len, | ||
430 | send_time, direct_link, | ||
431 | if_incoming, | ||
432 | forw_packet_pos)) { | ||
433 | forw_packet_aggr = forw_packet_pos; | ||
434 | break; | ||
435 | } | ||
436 | } | ||
437 | } | ||
438 | |||
439 | /* nothing to aggregate with - either aggregation disabled or no | ||
440 | * suitable aggregation packet found */ | ||
441 | if (!forw_packet_aggr) { | ||
442 | /* the following section can run without the lock */ | ||
443 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); | ||
444 | |||
445 | /** | ||
446 | * if we could not aggregate this packet with one of the others | ||
447 | * we hold it back for a while, so that it might be aggregated | ||
448 | * later on | ||
449 | */ | ||
450 | if ((!own_packet) && | ||
451 | (atomic_read(&bat_priv->aggregated_ogms))) | ||
452 | send_time += msecs_to_jiffies(MAX_AGGREGATION_MS); | ||
453 | |||
454 | bat_ogm_aggregate_new(packet_buff, packet_len, | ||
455 | send_time, direct_link, | ||
456 | if_incoming, own_packet); | ||
457 | } else { | ||
458 | bat_ogm_aggregate(forw_packet_aggr, packet_buff, packet_len, | ||
459 | direct_link); | ||
460 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); | ||
461 | } | ||
462 | } | ||
463 | |||
464 | static void bat_ogm_forward(struct orig_node *orig_node, | ||
465 | const struct ethhdr *ethhdr, | ||
466 | struct batman_ogm_packet *batman_ogm_packet, | ||
467 | int directlink, struct hard_iface *if_incoming) | ||
468 | { | ||
469 | struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
470 | struct neigh_node *router; | ||
471 | uint8_t in_tq, in_ttl, tq_avg = 0; | ||
472 | uint8_t tt_num_changes; | ||
473 | |||
474 | if (batman_ogm_packet->ttl <= 1) { | ||
475 | bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n"); | ||
476 | return; | ||
477 | } | ||
478 | |||
479 | router = orig_node_get_router(orig_node); | ||
480 | |||
481 | in_tq = batman_ogm_packet->tq; | ||
482 | in_ttl = batman_ogm_packet->ttl; | ||
483 | tt_num_changes = batman_ogm_packet->tt_num_changes; | ||
484 | |||
485 | batman_ogm_packet->ttl--; | ||
486 | memcpy(batman_ogm_packet->prev_sender, ethhdr->h_source, ETH_ALEN); | ||
487 | |||
488 | /* rebroadcast tq of our best ranking neighbor to ensure the rebroadcast | ||
489 | * of our best tq value */ | ||
490 | if (router && router->tq_avg != 0) { | ||
491 | |||
492 | /* rebroadcast ogm of best ranking neighbor as is */ | ||
493 | if (!compare_eth(router->addr, ethhdr->h_source)) { | ||
494 | batman_ogm_packet->tq = router->tq_avg; | ||
495 | |||
496 | if (router->last_ttl) | ||
497 | batman_ogm_packet->ttl = router->last_ttl - 1; | ||
498 | } | ||
499 | |||
500 | tq_avg = router->tq_avg; | ||
501 | } | ||
502 | |||
503 | if (router) | ||
504 | neigh_node_free_ref(router); | ||
505 | |||
506 | /* apply hop penalty */ | ||
507 | batman_ogm_packet->tq = hop_penalty(batman_ogm_packet->tq, bat_priv); | ||
508 | |||
509 | bat_dbg(DBG_BATMAN, bat_priv, | ||
510 | "Forwarding packet: tq_orig: %i, tq_avg: %i, " | ||
511 | "tq_forw: %i, ttl_orig: %i, ttl_forw: %i\n", | ||
512 | in_tq, tq_avg, batman_ogm_packet->tq, in_ttl - 1, | ||
513 | batman_ogm_packet->ttl); | ||
514 | |||
515 | batman_ogm_packet->seqno = htonl(batman_ogm_packet->seqno); | ||
516 | batman_ogm_packet->tt_crc = htons(batman_ogm_packet->tt_crc); | ||
517 | |||
518 | /* switch of primaries first hop flag when forwarding */ | ||
519 | batman_ogm_packet->flags &= ~PRIMARIES_FIRST_HOP; | ||
520 | if (directlink) | ||
521 | batman_ogm_packet->flags |= DIRECTLINK; | ||
522 | else | ||
523 | batman_ogm_packet->flags &= ~DIRECTLINK; | ||
524 | |||
525 | bat_ogm_queue_add(bat_priv, (unsigned char *)batman_ogm_packet, | ||
526 | BATMAN_OGM_LEN + tt_len(tt_num_changes), | ||
527 | if_incoming, 0, bat_ogm_fwd_send_time()); | ||
528 | } | ||
529 | |||
530 | void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes) | ||
531 | { | ||
532 | struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); | ||
533 | struct batman_ogm_packet *batman_ogm_packet; | ||
534 | struct hard_iface *primary_if; | ||
535 | int vis_server; | ||
536 | |||
537 | vis_server = atomic_read(&bat_priv->vis_mode); | ||
538 | primary_if = primary_if_get_selected(bat_priv); | ||
539 | |||
540 | batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; | ||
541 | |||
542 | /* change sequence number to network order */ | ||
543 | batman_ogm_packet->seqno = | ||
544 | htonl((uint32_t)atomic_read(&hard_iface->seqno)); | ||
545 | |||
546 | batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn); | ||
547 | batman_ogm_packet->tt_crc = htons((uint16_t) | ||
548 | atomic_read(&bat_priv->tt_crc)); | ||
549 | if (tt_num_changes >= 0) | ||
550 | batman_ogm_packet->tt_num_changes = tt_num_changes; | ||
551 | |||
552 | if (vis_server == VIS_TYPE_SERVER_SYNC) | ||
553 | batman_ogm_packet->flags |= VIS_SERVER; | ||
554 | else | ||
555 | batman_ogm_packet->flags &= ~VIS_SERVER; | ||
556 | |||
557 | if ((hard_iface == primary_if) && | ||
558 | (atomic_read(&bat_priv->gw_mode) == GW_MODE_SERVER)) | ||
559 | batman_ogm_packet->gw_flags = | ||
560 | (uint8_t)atomic_read(&bat_priv->gw_bandwidth); | ||
561 | else | ||
562 | batman_ogm_packet->gw_flags = NO_FLAGS; | ||
563 | |||
564 | atomic_inc(&hard_iface->seqno); | ||
565 | |||
566 | slide_own_bcast_window(hard_iface); | ||
567 | bat_ogm_queue_add(bat_priv, hard_iface->packet_buff, | ||
568 | hard_iface->packet_len, hard_iface, 1, | ||
569 | bat_ogm_emit_send_time(bat_priv)); | ||
570 | |||
571 | if (primary_if) | ||
572 | hardif_free_ref(primary_if); | ||
573 | } | ||
574 | |||
575 | static void bat_ogm_orig_update(struct bat_priv *bat_priv, | ||
576 | struct orig_node *orig_node, | ||
577 | const struct ethhdr *ethhdr, | ||
578 | const struct batman_ogm_packet | ||
579 | *batman_ogm_packet, | ||
580 | struct hard_iface *if_incoming, | ||
581 | const unsigned char *tt_buff, int is_duplicate) | ||
582 | { | ||
583 | struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL; | ||
584 | struct neigh_node *router = NULL; | ||
585 | struct orig_node *orig_node_tmp; | ||
586 | struct hlist_node *node; | ||
587 | uint8_t bcast_own_sum_orig, bcast_own_sum_neigh; | ||
588 | |||
589 | bat_dbg(DBG_BATMAN, bat_priv, "update_originator(): " | ||
590 | "Searching and updating originator entry of received packet\n"); | ||
591 | |||
592 | rcu_read_lock(); | ||
593 | hlist_for_each_entry_rcu(tmp_neigh_node, node, | ||
594 | &orig_node->neigh_list, list) { | ||
595 | if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) && | ||
596 | (tmp_neigh_node->if_incoming == if_incoming) && | ||
597 | atomic_inc_not_zero(&tmp_neigh_node->refcount)) { | ||
598 | if (neigh_node) | ||
599 | neigh_node_free_ref(neigh_node); | ||
600 | neigh_node = tmp_neigh_node; | ||
601 | continue; | ||
602 | } | ||
603 | |||
604 | if (is_duplicate) | ||
605 | continue; | ||
606 | |||
607 | spin_lock_bh(&tmp_neigh_node->tq_lock); | ||
608 | ring_buffer_set(tmp_neigh_node->tq_recv, | ||
609 | &tmp_neigh_node->tq_index, 0); | ||
610 | tmp_neigh_node->tq_avg = | ||
611 | ring_buffer_avg(tmp_neigh_node->tq_recv); | ||
612 | spin_unlock_bh(&tmp_neigh_node->tq_lock); | ||
613 | } | ||
614 | |||
615 | if (!neigh_node) { | ||
616 | struct orig_node *orig_tmp; | ||
617 | |||
618 | orig_tmp = get_orig_node(bat_priv, ethhdr->h_source); | ||
619 | if (!orig_tmp) | ||
620 | goto unlock; | ||
621 | |||
622 | neigh_node = create_neighbor(orig_node, orig_tmp, | ||
623 | ethhdr->h_source, if_incoming); | ||
624 | |||
625 | orig_node_free_ref(orig_tmp); | ||
626 | if (!neigh_node) | ||
627 | goto unlock; | ||
628 | } else | ||
629 | bat_dbg(DBG_BATMAN, bat_priv, | ||
630 | "Updating existing last-hop neighbor of originator\n"); | ||
631 | |||
632 | rcu_read_unlock(); | ||
633 | |||
634 | orig_node->flags = batman_ogm_packet->flags; | ||
635 | neigh_node->last_valid = jiffies; | ||
636 | |||
637 | spin_lock_bh(&neigh_node->tq_lock); | ||
638 | ring_buffer_set(neigh_node->tq_recv, | ||
639 | &neigh_node->tq_index, | ||
640 | batman_ogm_packet->tq); | ||
641 | neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv); | ||
642 | spin_unlock_bh(&neigh_node->tq_lock); | ||
643 | |||
644 | if (!is_duplicate) { | ||
645 | orig_node->last_ttl = batman_ogm_packet->ttl; | ||
646 | neigh_node->last_ttl = batman_ogm_packet->ttl; | ||
647 | } | ||
648 | |||
649 | bonding_candidate_add(orig_node, neigh_node); | ||
650 | |||
651 | /* if this neighbor already is our next hop there is nothing | ||
652 | * to change */ | ||
653 | router = orig_node_get_router(orig_node); | ||
654 | if (router == neigh_node) | ||
655 | goto update_tt; | ||
656 | |||
657 | /* if this neighbor does not offer a better TQ we won't consider it */ | ||
658 | if (router && (router->tq_avg > neigh_node->tq_avg)) | ||
659 | goto update_tt; | ||
660 | |||
661 | /* if the TQ is the same and the link not more symmetric we | ||
662 | * won't consider it either */ | ||
663 | if (router && (neigh_node->tq_avg == router->tq_avg)) { | ||
664 | orig_node_tmp = router->orig_node; | ||
665 | spin_lock_bh(&orig_node_tmp->ogm_cnt_lock); | ||
666 | bcast_own_sum_orig = | ||
667 | orig_node_tmp->bcast_own_sum[if_incoming->if_num]; | ||
668 | spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock); | ||
669 | |||
670 | orig_node_tmp = neigh_node->orig_node; | ||
671 | spin_lock_bh(&orig_node_tmp->ogm_cnt_lock); | ||
672 | bcast_own_sum_neigh = | ||
673 | orig_node_tmp->bcast_own_sum[if_incoming->if_num]; | ||
674 | spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock); | ||
675 | |||
676 | if (bcast_own_sum_orig >= bcast_own_sum_neigh) | ||
677 | goto update_tt; | ||
678 | } | ||
679 | |||
680 | update_route(bat_priv, orig_node, neigh_node); | ||
681 | |||
682 | update_tt: | ||
683 | /* I have to check for transtable changes only if the OGM has been | ||
684 | * sent through a primary interface */ | ||
685 | if (((batman_ogm_packet->orig != ethhdr->h_source) && | ||
686 | (batman_ogm_packet->ttl > 2)) || | ||
687 | (batman_ogm_packet->flags & PRIMARIES_FIRST_HOP)) | ||
688 | tt_update_orig(bat_priv, orig_node, tt_buff, | ||
689 | batman_ogm_packet->tt_num_changes, | ||
690 | batman_ogm_packet->ttvn, | ||
691 | batman_ogm_packet->tt_crc); | ||
692 | |||
693 | if (orig_node->gw_flags != batman_ogm_packet->gw_flags) | ||
694 | gw_node_update(bat_priv, orig_node, | ||
695 | batman_ogm_packet->gw_flags); | ||
696 | |||
697 | orig_node->gw_flags = batman_ogm_packet->gw_flags; | ||
698 | |||
699 | /* restart gateway selection if fast or late switching was enabled */ | ||
700 | if ((orig_node->gw_flags) && | ||
701 | (atomic_read(&bat_priv->gw_mode) == GW_MODE_CLIENT) && | ||
702 | (atomic_read(&bat_priv->gw_sel_class) > 2)) | ||
703 | gw_check_election(bat_priv, orig_node); | ||
704 | |||
705 | goto out; | ||
706 | |||
707 | unlock: | ||
708 | rcu_read_unlock(); | ||
709 | out: | ||
710 | if (neigh_node) | ||
711 | neigh_node_free_ref(neigh_node); | ||
712 | if (router) | ||
713 | neigh_node_free_ref(router); | ||
714 | } | ||
715 | |||
716 | static int bat_ogm_calc_tq(struct orig_node *orig_node, | ||
717 | struct orig_node *orig_neigh_node, | ||
718 | struct batman_ogm_packet *batman_ogm_packet, | ||
719 | struct hard_iface *if_incoming) | ||
720 | { | ||
721 | struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
722 | struct neigh_node *neigh_node = NULL, *tmp_neigh_node; | ||
723 | struct hlist_node *node; | ||
724 | uint8_t total_count; | ||
725 | uint8_t orig_eq_count, neigh_rq_count, tq_own; | ||
726 | int tq_asym_penalty, ret = 0; | ||
727 | |||
728 | /* find corresponding one hop neighbor */ | ||
729 | rcu_read_lock(); | ||
730 | hlist_for_each_entry_rcu(tmp_neigh_node, node, | ||
731 | &orig_neigh_node->neigh_list, list) { | ||
732 | |||
733 | if (!compare_eth(tmp_neigh_node->addr, orig_neigh_node->orig)) | ||
734 | continue; | ||
735 | |||
736 | if (tmp_neigh_node->if_incoming != if_incoming) | ||
737 | continue; | ||
738 | |||
739 | if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) | ||
740 | continue; | ||
741 | |||
742 | neigh_node = tmp_neigh_node; | ||
743 | break; | ||
744 | } | ||
745 | rcu_read_unlock(); | ||
746 | |||
747 | if (!neigh_node) | ||
748 | neigh_node = create_neighbor(orig_neigh_node, | ||
749 | orig_neigh_node, | ||
750 | orig_neigh_node->orig, | ||
751 | if_incoming); | ||
752 | |||
753 | if (!neigh_node) | ||
754 | goto out; | ||
755 | |||
756 | /* if orig_node is direct neighbor update neigh_node last_valid */ | ||
757 | if (orig_node == orig_neigh_node) | ||
758 | neigh_node->last_valid = jiffies; | ||
759 | |||
760 | orig_node->last_valid = jiffies; | ||
761 | |||
762 | /* find packet count of corresponding one hop neighbor */ | ||
763 | spin_lock_bh(&orig_node->ogm_cnt_lock); | ||
764 | orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num]; | ||
765 | neigh_rq_count = neigh_node->real_packet_count; | ||
766 | spin_unlock_bh(&orig_node->ogm_cnt_lock); | ||
767 | |||
768 | /* pay attention to not get a value bigger than 100 % */ | ||
769 | total_count = (orig_eq_count > neigh_rq_count ? | ||
770 | neigh_rq_count : orig_eq_count); | ||
771 | |||
772 | /* if we have too few packets (too less data) we set tq_own to zero */ | ||
773 | /* if we receive too few packets it is not considered bidirectional */ | ||
774 | if ((total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM) || | ||
775 | (neigh_rq_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM)) | ||
776 | tq_own = 0; | ||
777 | else | ||
778 | /* neigh_node->real_packet_count is never zero as we | ||
779 | * only purge old information when getting new | ||
780 | * information */ | ||
781 | tq_own = (TQ_MAX_VALUE * total_count) / neigh_rq_count; | ||
782 | |||
783 | /* | ||
784 | * 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does | ||
785 | * affect the nearly-symmetric links only a little, but | ||
786 | * punishes asymmetric links more. This will give a value | ||
787 | * between 0 and TQ_MAX_VALUE | ||
788 | */ | ||
789 | tq_asym_penalty = TQ_MAX_VALUE - (TQ_MAX_VALUE * | ||
790 | (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) * | ||
791 | (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) * | ||
792 | (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count)) / | ||
793 | (TQ_LOCAL_WINDOW_SIZE * | ||
794 | TQ_LOCAL_WINDOW_SIZE * | ||
795 | TQ_LOCAL_WINDOW_SIZE); | ||
796 | |||
797 | batman_ogm_packet->tq = ((batman_ogm_packet->tq * tq_own | ||
798 | * tq_asym_penalty) / | ||
799 | (TQ_MAX_VALUE * TQ_MAX_VALUE)); | ||
800 | |||
801 | bat_dbg(DBG_BATMAN, bat_priv, | ||
802 | "bidirectional: " | ||
803 | "orig = %-15pM neigh = %-15pM => own_bcast = %2i, " | ||
804 | "real recv = %2i, local tq: %3i, asym_penalty: %3i, " | ||
805 | "total tq: %3i\n", | ||
806 | orig_node->orig, orig_neigh_node->orig, total_count, | ||
807 | neigh_rq_count, tq_own, tq_asym_penalty, batman_ogm_packet->tq); | ||
808 | |||
809 | /* if link has the minimum required transmission quality | ||
810 | * consider it bidirectional */ | ||
811 | if (batman_ogm_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT) | ||
812 | ret = 1; | ||
813 | |||
814 | out: | ||
815 | if (neigh_node) | ||
816 | neigh_node_free_ref(neigh_node); | ||
817 | return ret; | ||
818 | } | ||
819 | |||
820 | /* processes a batman packet for all interfaces, adjusts the sequence number and | ||
821 | * finds out whether it is a duplicate. | ||
822 | * returns: | ||
823 | * 1 the packet is a duplicate | ||
824 | * 0 the packet has not yet been received | ||
825 | * -1 the packet is old and has been received while the seqno window | ||
826 | * was protected. Caller should drop it. | ||
827 | */ | ||
828 | static int bat_ogm_update_seqnos(const struct ethhdr *ethhdr, | ||
829 | const struct batman_ogm_packet | ||
830 | *batman_ogm_packet, | ||
831 | const struct hard_iface *if_incoming) | ||
832 | { | ||
833 | struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
834 | struct orig_node *orig_node; | ||
835 | struct neigh_node *tmp_neigh_node; | ||
836 | struct hlist_node *node; | ||
837 | int is_duplicate = 0; | ||
838 | int32_t seq_diff; | ||
839 | int need_update = 0; | ||
840 | int set_mark, ret = -1; | ||
841 | |||
842 | orig_node = get_orig_node(bat_priv, batman_ogm_packet->orig); | ||
843 | if (!orig_node) | ||
844 | return 0; | ||
845 | |||
846 | spin_lock_bh(&orig_node->ogm_cnt_lock); | ||
847 | seq_diff = batman_ogm_packet->seqno - orig_node->last_real_seqno; | ||
848 | |||
849 | /* signalize caller that the packet is to be dropped. */ | ||
850 | if (window_protected(bat_priv, seq_diff, | ||
851 | &orig_node->batman_seqno_reset)) | ||
852 | goto out; | ||
853 | |||
854 | rcu_read_lock(); | ||
855 | hlist_for_each_entry_rcu(tmp_neigh_node, node, | ||
856 | &orig_node->neigh_list, list) { | ||
857 | |||
858 | is_duplicate |= get_bit_status(tmp_neigh_node->real_bits, | ||
859 | orig_node->last_real_seqno, | ||
860 | batman_ogm_packet->seqno); | ||
861 | |||
862 | if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) && | ||
863 | (tmp_neigh_node->if_incoming == if_incoming)) | ||
864 | set_mark = 1; | ||
865 | else | ||
866 | set_mark = 0; | ||
867 | |||
868 | /* if the window moved, set the update flag. */ | ||
869 | need_update |= bit_get_packet(bat_priv, | ||
870 | tmp_neigh_node->real_bits, | ||
871 | seq_diff, set_mark); | ||
872 | |||
873 | tmp_neigh_node->real_packet_count = | ||
874 | bit_packet_count(tmp_neigh_node->real_bits); | ||
875 | } | ||
876 | rcu_read_unlock(); | ||
877 | |||
878 | if (need_update) { | ||
879 | bat_dbg(DBG_BATMAN, bat_priv, | ||
880 | "updating last_seqno: old %d, new %d\n", | ||
881 | orig_node->last_real_seqno, batman_ogm_packet->seqno); | ||
882 | orig_node->last_real_seqno = batman_ogm_packet->seqno; | ||
883 | } | ||
884 | |||
885 | ret = is_duplicate; | ||
886 | |||
887 | out: | ||
888 | spin_unlock_bh(&orig_node->ogm_cnt_lock); | ||
889 | orig_node_free_ref(orig_node); | ||
890 | return ret; | ||
891 | } | ||
892 | |||
893 | static void bat_ogm_process(const struct ethhdr *ethhdr, | ||
894 | struct batman_ogm_packet *batman_ogm_packet, | ||
895 | const unsigned char *tt_buff, | ||
896 | struct hard_iface *if_incoming) | ||
897 | { | ||
898 | struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
899 | struct hard_iface *hard_iface; | ||
900 | struct orig_node *orig_neigh_node, *orig_node; | ||
901 | struct neigh_node *router = NULL, *router_router = NULL; | ||
902 | struct neigh_node *orig_neigh_router = NULL; | ||
903 | int has_directlink_flag; | ||
904 | int is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0; | ||
905 | int is_broadcast = 0, is_bidirectional, is_single_hop_neigh; | ||
906 | int is_duplicate; | ||
907 | uint32_t if_incoming_seqno; | ||
908 | |||
909 | /* Silently drop when the batman packet is actually not a | ||
910 | * correct packet. | ||
911 | * | ||
912 | * This might happen if a packet is padded (e.g. Ethernet has a | ||
913 | * minimum frame length of 64 byte) and the aggregation interprets | ||
914 | * it as an additional length. | ||
915 | * | ||
916 | * TODO: A more sane solution would be to have a bit in the | ||
917 | * batman_ogm_packet to detect whether the packet is the last | ||
918 | * packet in an aggregation. Here we expect that the padding | ||
919 | * is always zero (or not 0x01) | ||
920 | */ | ||
921 | if (batman_ogm_packet->packet_type != BAT_OGM) | ||
922 | return; | ||
923 | |||
924 | /* could be changed by schedule_own_packet() */ | ||
925 | if_incoming_seqno = atomic_read(&if_incoming->seqno); | ||
926 | |||
927 | has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0); | ||
928 | |||
929 | is_single_hop_neigh = (compare_eth(ethhdr->h_source, | ||
930 | batman_ogm_packet->orig) ? 1 : 0); | ||
931 | |||
932 | bat_dbg(DBG_BATMAN, bat_priv, | ||
933 | "Received BATMAN packet via NB: %pM, IF: %s [%pM] " | ||
934 | "(from OG: %pM, via prev OG: %pM, seqno %d, ttvn %u, " | ||
935 | "crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n", | ||
936 | ethhdr->h_source, if_incoming->net_dev->name, | ||
937 | if_incoming->net_dev->dev_addr, batman_ogm_packet->orig, | ||
938 | batman_ogm_packet->prev_sender, batman_ogm_packet->seqno, | ||
939 | batman_ogm_packet->ttvn, batman_ogm_packet->tt_crc, | ||
940 | batman_ogm_packet->tt_num_changes, batman_ogm_packet->tq, | ||
941 | batman_ogm_packet->ttl, batman_ogm_packet->version, | ||
942 | has_directlink_flag); | ||
943 | |||
944 | rcu_read_lock(); | ||
945 | list_for_each_entry_rcu(hard_iface, &hardif_list, list) { | ||
946 | if (hard_iface->if_status != IF_ACTIVE) | ||
947 | continue; | ||
948 | |||
949 | if (hard_iface->soft_iface != if_incoming->soft_iface) | ||
950 | continue; | ||
951 | |||
952 | if (compare_eth(ethhdr->h_source, | ||
953 | hard_iface->net_dev->dev_addr)) | ||
954 | is_my_addr = 1; | ||
955 | |||
956 | if (compare_eth(batman_ogm_packet->orig, | ||
957 | hard_iface->net_dev->dev_addr)) | ||
958 | is_my_orig = 1; | ||
959 | |||
960 | if (compare_eth(batman_ogm_packet->prev_sender, | ||
961 | hard_iface->net_dev->dev_addr)) | ||
962 | is_my_oldorig = 1; | ||
963 | |||
964 | if (is_broadcast_ether_addr(ethhdr->h_source)) | ||
965 | is_broadcast = 1; | ||
966 | } | ||
967 | rcu_read_unlock(); | ||
968 | |||
969 | if (batman_ogm_packet->version != COMPAT_VERSION) { | ||
970 | bat_dbg(DBG_BATMAN, bat_priv, | ||
971 | "Drop packet: incompatible batman version (%i)\n", | ||
972 | batman_ogm_packet->version); | ||
973 | return; | ||
974 | } | ||
975 | |||
976 | if (is_my_addr) { | ||
977 | bat_dbg(DBG_BATMAN, bat_priv, | ||
978 | "Drop packet: received my own broadcast (sender: %pM" | ||
979 | ")\n", | ||
980 | ethhdr->h_source); | ||
981 | return; | ||
982 | } | ||
983 | |||
984 | if (is_broadcast) { | ||
985 | bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: " | ||
986 | "ignoring all packets with broadcast source addr (sender: %pM" | ||
987 | ")\n", ethhdr->h_source); | ||
988 | return; | ||
989 | } | ||
990 | |||
991 | if (is_my_orig) { | ||
992 | unsigned long *word; | ||
993 | int offset; | ||
994 | |||
995 | orig_neigh_node = get_orig_node(bat_priv, ethhdr->h_source); | ||
996 | if (!orig_neigh_node) | ||
997 | return; | ||
998 | |||
999 | /* neighbor has to indicate direct link and it has to | ||
1000 | * come via the corresponding interface */ | ||
1001 | /* save packet seqno for bidirectional check */ | ||
1002 | if (has_directlink_flag && | ||
1003 | compare_eth(if_incoming->net_dev->dev_addr, | ||
1004 | batman_ogm_packet->orig)) { | ||
1005 | offset = if_incoming->if_num * NUM_WORDS; | ||
1006 | |||
1007 | spin_lock_bh(&orig_neigh_node->ogm_cnt_lock); | ||
1008 | word = &(orig_neigh_node->bcast_own[offset]); | ||
1009 | bit_mark(word, | ||
1010 | if_incoming_seqno - | ||
1011 | batman_ogm_packet->seqno - 2); | ||
1012 | orig_neigh_node->bcast_own_sum[if_incoming->if_num] = | ||
1013 | bit_packet_count(word); | ||
1014 | spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock); | ||
1015 | } | ||
1016 | |||
1017 | bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: " | ||
1018 | "originator packet from myself (via neighbor)\n"); | ||
1019 | orig_node_free_ref(orig_neigh_node); | ||
1020 | return; | ||
1021 | } | ||
1022 | |||
1023 | if (is_my_oldorig) { | ||
1024 | bat_dbg(DBG_BATMAN, bat_priv, | ||
1025 | "Drop packet: ignoring all rebroadcast echos (sender: " | ||
1026 | "%pM)\n", ethhdr->h_source); | ||
1027 | return; | ||
1028 | } | ||
1029 | |||
1030 | orig_node = get_orig_node(bat_priv, batman_ogm_packet->orig); | ||
1031 | if (!orig_node) | ||
1032 | return; | ||
1033 | |||
1034 | is_duplicate = bat_ogm_update_seqnos(ethhdr, batman_ogm_packet, | ||
1035 | if_incoming); | ||
1036 | |||
1037 | if (is_duplicate == -1) { | ||
1038 | bat_dbg(DBG_BATMAN, bat_priv, | ||
1039 | "Drop packet: packet within seqno protection time " | ||
1040 | "(sender: %pM)\n", ethhdr->h_source); | ||
1041 | goto out; | ||
1042 | } | ||
1043 | |||
1044 | if (batman_ogm_packet->tq == 0) { | ||
1045 | bat_dbg(DBG_BATMAN, bat_priv, | ||
1046 | "Drop packet: originator packet with tq equal 0\n"); | ||
1047 | goto out; | ||
1048 | } | ||
1049 | |||
1050 | router = orig_node_get_router(orig_node); | ||
1051 | if (router) | ||
1052 | router_router = orig_node_get_router(router->orig_node); | ||
1053 | |||
1054 | /* avoid temporary routing loops */ | ||
1055 | if (router && router_router && | ||
1056 | (compare_eth(router->addr, batman_ogm_packet->prev_sender)) && | ||
1057 | !(compare_eth(batman_ogm_packet->orig, | ||
1058 | batman_ogm_packet->prev_sender)) && | ||
1059 | (compare_eth(router->addr, router_router->addr))) { | ||
1060 | bat_dbg(DBG_BATMAN, bat_priv, | ||
1061 | "Drop packet: ignoring all rebroadcast packets that " | ||
1062 | "may make me loop (sender: %pM)\n", ethhdr->h_source); | ||
1063 | goto out; | ||
1064 | } | ||
1065 | |||
1066 | /* if sender is a direct neighbor the sender mac equals | ||
1067 | * originator mac */ | ||
1068 | orig_neigh_node = (is_single_hop_neigh ? | ||
1069 | orig_node : | ||
1070 | get_orig_node(bat_priv, ethhdr->h_source)); | ||
1071 | if (!orig_neigh_node) | ||
1072 | goto out; | ||
1073 | |||
1074 | orig_neigh_router = orig_node_get_router(orig_neigh_node); | ||
1075 | |||
1076 | /* drop packet if sender is not a direct neighbor and if we | ||
1077 | * don't route towards it */ | ||
1078 | if (!is_single_hop_neigh && (!orig_neigh_router)) { | ||
1079 | bat_dbg(DBG_BATMAN, bat_priv, | ||
1080 | "Drop packet: OGM via unknown neighbor!\n"); | ||
1081 | goto out_neigh; | ||
1082 | } | ||
1083 | |||
1084 | is_bidirectional = bat_ogm_calc_tq(orig_node, orig_neigh_node, | ||
1085 | batman_ogm_packet, if_incoming); | ||
1086 | |||
1087 | bonding_save_primary(orig_node, orig_neigh_node, batman_ogm_packet); | ||
1088 | |||
1089 | /* update ranking if it is not a duplicate or has the same | ||
1090 | * seqno and similar ttl as the non-duplicate */ | ||
1091 | if (is_bidirectional && | ||
1092 | (!is_duplicate || | ||
1093 | ((orig_node->last_real_seqno == batman_ogm_packet->seqno) && | ||
1094 | (orig_node->last_ttl - 3 <= batman_ogm_packet->ttl)))) | ||
1095 | bat_ogm_orig_update(bat_priv, orig_node, ethhdr, | ||
1096 | batman_ogm_packet, if_incoming, | ||
1097 | tt_buff, is_duplicate); | ||
1098 | |||
1099 | /* is single hop (direct) neighbor */ | ||
1100 | if (is_single_hop_neigh) { | ||
1101 | |||
1102 | /* mark direct link on incoming interface */ | ||
1103 | bat_ogm_forward(orig_node, ethhdr, batman_ogm_packet, | ||
1104 | 1, if_incoming); | ||
1105 | |||
1106 | bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: " | ||
1107 | "rebroadcast neighbor packet with direct link flag\n"); | ||
1108 | goto out_neigh; | ||
1109 | } | ||
1110 | |||
1111 | /* multihop originator */ | ||
1112 | if (!is_bidirectional) { | ||
1113 | bat_dbg(DBG_BATMAN, bat_priv, | ||
1114 | "Drop packet: not received via bidirectional link\n"); | ||
1115 | goto out_neigh; | ||
1116 | } | ||
1117 | |||
1118 | if (is_duplicate) { | ||
1119 | bat_dbg(DBG_BATMAN, bat_priv, | ||
1120 | "Drop packet: duplicate packet received\n"); | ||
1121 | goto out_neigh; | ||
1122 | } | ||
1123 | |||
1124 | bat_dbg(DBG_BATMAN, bat_priv, | ||
1125 | "Forwarding packet: rebroadcast originator packet\n"); | ||
1126 | bat_ogm_forward(orig_node, ethhdr, batman_ogm_packet, 0, if_incoming); | ||
1127 | |||
1128 | out_neigh: | ||
1129 | if ((orig_neigh_node) && (!is_single_hop_neigh)) | ||
1130 | orig_node_free_ref(orig_neigh_node); | ||
1131 | out: | ||
1132 | if (router) | ||
1133 | neigh_node_free_ref(router); | ||
1134 | if (router_router) | ||
1135 | neigh_node_free_ref(router_router); | ||
1136 | if (orig_neigh_router) | ||
1137 | neigh_node_free_ref(orig_neigh_router); | ||
1138 | |||
1139 | orig_node_free_ref(orig_node); | ||
1140 | } | ||
1141 | |||
1142 | void bat_ogm_receive(const struct ethhdr *ethhdr, unsigned char *packet_buff, | ||
1143 | int packet_len, struct hard_iface *if_incoming) | ||
1144 | { | ||
1145 | struct batman_ogm_packet *batman_ogm_packet; | ||
1146 | int buff_pos = 0; | ||
1147 | unsigned char *tt_buff; | ||
1148 | |||
1149 | batman_ogm_packet = (struct batman_ogm_packet *)packet_buff; | ||
1150 | |||
1151 | /* unpack the aggregated packets and process them one by one */ | ||
1152 | do { | ||
1153 | /* network to host order for our 32bit seqno and the | ||
1154 | orig_interval */ | ||
1155 | batman_ogm_packet->seqno = ntohl(batman_ogm_packet->seqno); | ||
1156 | batman_ogm_packet->tt_crc = ntohs(batman_ogm_packet->tt_crc); | ||
1157 | |||
1158 | tt_buff = packet_buff + buff_pos + BATMAN_OGM_LEN; | ||
1159 | |||
1160 | bat_ogm_process(ethhdr, batman_ogm_packet, | ||
1161 | tt_buff, if_incoming); | ||
1162 | |||
1163 | buff_pos += BATMAN_OGM_LEN + | ||
1164 | tt_len(batman_ogm_packet->tt_num_changes); | ||
1165 | |||
1166 | batman_ogm_packet = (struct batman_ogm_packet *) | ||
1167 | (packet_buff + buff_pos); | ||
1168 | } while (bat_ogm_aggr_packet(buff_pos, packet_len, | ||
1169 | batman_ogm_packet->tt_num_changes)); | ||
1170 | } | ||
diff --git a/net/batman-adv/aggregation.h b/net/batman-adv/bat_ogm.h index df4a5a943088..69329c107e28 100644 --- a/net/batman-adv/aggregation.h +++ b/net/batman-adv/bat_ogm.h | |||
@@ -19,27 +19,17 @@ | |||
19 | * | 19 | * |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef _NET_BATMAN_ADV_AGGREGATION_H_ | 22 | #ifndef _NET_BATMAN_ADV_OGM_H_ |
23 | #define _NET_BATMAN_ADV_AGGREGATION_H_ | 23 | #define _NET_BATMAN_ADV_OGM_H_ |
24 | 24 | ||
25 | #include "main.h" | 25 | #include "main.h" |
26 | 26 | ||
27 | /* is there another aggregated packet here? */ | 27 | void bat_ogm_init(struct hard_iface *hard_iface); |
28 | static inline int aggregated_packet(int buff_pos, int packet_len, | 28 | void bat_ogm_init_primary(struct hard_iface *hard_iface); |
29 | int tt_num_changes) | 29 | void bat_ogm_update_mac(struct hard_iface *hard_iface); |
30 | { | 30 | void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes); |
31 | int next_buff_pos = buff_pos + BAT_PACKET_LEN + tt_len(tt_num_changes); | 31 | void bat_ogm_emit(struct forw_packet *forw_packet); |
32 | void bat_ogm_receive(const struct ethhdr *ethhdr, unsigned char *packet_buff, | ||
33 | int packet_len, struct hard_iface *if_incoming); | ||
32 | 34 | ||
33 | return (next_buff_pos <= packet_len) && | 35 | #endif /* _NET_BATMAN_ADV_OGM_H_ */ |
34 | (next_buff_pos <= MAX_AGGREGATION_BYTES); | ||
35 | } | ||
36 | |||
37 | void add_bat_packet_to_list(struct bat_priv *bat_priv, | ||
38 | unsigned char *packet_buff, int packet_len, | ||
39 | struct hard_iface *if_incoming, int own_packet, | ||
40 | unsigned long send_time); | ||
41 | void receive_aggr_bat_packet(const struct ethhdr *ethhdr, | ||
42 | unsigned char *packet_buff, int packet_len, | ||
43 | struct hard_iface *if_incoming); | ||
44 | |||
45 | #endif /* _NET_BATMAN_ADV_AGGREGATION_H_ */ | ||
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index bf91e4d8a47f..7704df468e0b 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "bat_sysfs.h" | 28 | #include "bat_sysfs.h" |
29 | #include "originator.h" | 29 | #include "originator.h" |
30 | #include "hash.h" | 30 | #include "hash.h" |
31 | #include "bat_ogm.h" | ||
31 | 32 | ||
32 | #include <linux/if_arp.h> | 33 | #include <linux/if_arp.h> |
33 | 34 | ||
@@ -131,7 +132,6 @@ static void primary_if_select(struct bat_priv *bat_priv, | |||
131 | struct hard_iface *new_hard_iface) | 132 | struct hard_iface *new_hard_iface) |
132 | { | 133 | { |
133 | struct hard_iface *curr_hard_iface; | 134 | struct hard_iface *curr_hard_iface; |
134 | struct batman_packet *batman_packet; | ||
135 | 135 | ||
136 | ASSERT_RTNL(); | 136 | ASSERT_RTNL(); |
137 | 137 | ||
@@ -147,10 +147,7 @@ static void primary_if_select(struct bat_priv *bat_priv, | |||
147 | if (!new_hard_iface) | 147 | if (!new_hard_iface) |
148 | return; | 148 | return; |
149 | 149 | ||
150 | batman_packet = (struct batman_packet *)(new_hard_iface->packet_buff); | 150 | bat_ogm_init_primary(new_hard_iface); |
151 | batman_packet->flags = PRIMARIES_FIRST_HOP; | ||
152 | batman_packet->ttl = TTL; | ||
153 | |||
154 | primary_if_update_addr(bat_priv); | 151 | primary_if_update_addr(bat_priv); |
155 | } | 152 | } |
156 | 153 | ||
@@ -162,14 +159,6 @@ static bool hardif_is_iface_up(const struct hard_iface *hard_iface) | |||
162 | return false; | 159 | return false; |
163 | } | 160 | } |
164 | 161 | ||
165 | static void update_mac_addresses(struct hard_iface *hard_iface) | ||
166 | { | ||
167 | memcpy(((struct batman_packet *)(hard_iface->packet_buff))->orig, | ||
168 | hard_iface->net_dev->dev_addr, ETH_ALEN); | ||
169 | memcpy(((struct batman_packet *)(hard_iface->packet_buff))->prev_sender, | ||
170 | hard_iface->net_dev->dev_addr, ETH_ALEN); | ||
171 | } | ||
172 | |||
173 | static void check_known_mac_addr(const struct net_device *net_dev) | 162 | static void check_known_mac_addr(const struct net_device *net_dev) |
174 | { | 163 | { |
175 | const struct hard_iface *hard_iface; | 164 | const struct hard_iface *hard_iface; |
@@ -244,7 +233,7 @@ static void hardif_activate_interface(struct hard_iface *hard_iface) | |||
244 | 233 | ||
245 | bat_priv = netdev_priv(hard_iface->soft_iface); | 234 | bat_priv = netdev_priv(hard_iface->soft_iface); |
246 | 235 | ||
247 | update_mac_addresses(hard_iface); | 236 | bat_ogm_update_mac(hard_iface); |
248 | hard_iface->if_status = IF_TO_BE_ACTIVATED; | 237 | hard_iface->if_status = IF_TO_BE_ACTIVATED; |
249 | 238 | ||
250 | /** | 239 | /** |
@@ -283,7 +272,6 @@ int hardif_enable_interface(struct hard_iface *hard_iface, | |||
283 | const char *iface_name) | 272 | const char *iface_name) |
284 | { | 273 | { |
285 | struct bat_priv *bat_priv; | 274 | struct bat_priv *bat_priv; |
286 | struct batman_packet *batman_packet; | ||
287 | struct net_device *soft_iface; | 275 | struct net_device *soft_iface; |
288 | int ret; | 276 | int ret; |
289 | 277 | ||
@@ -318,8 +306,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface, | |||
318 | 306 | ||
319 | hard_iface->soft_iface = soft_iface; | 307 | hard_iface->soft_iface = soft_iface; |
320 | bat_priv = netdev_priv(hard_iface->soft_iface); | 308 | bat_priv = netdev_priv(hard_iface->soft_iface); |
321 | hard_iface->packet_len = BAT_PACKET_LEN; | 309 | |
322 | hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC); | 310 | bat_ogm_init(hard_iface); |
323 | 311 | ||
324 | if (!hard_iface->packet_buff) { | 312 | if (!hard_iface->packet_buff) { |
325 | bat_err(hard_iface->soft_iface, "Can't add interface packet " | 313 | bat_err(hard_iface->soft_iface, "Can't add interface packet " |
@@ -328,15 +316,6 @@ int hardif_enable_interface(struct hard_iface *hard_iface, | |||
328 | goto err; | 316 | goto err; |
329 | } | 317 | } |
330 | 318 | ||
331 | batman_packet = (struct batman_packet *)(hard_iface->packet_buff); | ||
332 | batman_packet->packet_type = BAT_PACKET; | ||
333 | batman_packet->version = COMPAT_VERSION; | ||
334 | batman_packet->flags = NO_FLAGS; | ||
335 | batman_packet->ttl = 2; | ||
336 | batman_packet->tq = TQ_MAX_VALUE; | ||
337 | batman_packet->tt_num_changes = 0; | ||
338 | batman_packet->ttvn = 0; | ||
339 | |||
340 | hard_iface->if_num = bat_priv->num_ifaces; | 319 | hard_iface->if_num = bat_priv->num_ifaces; |
341 | bat_priv->num_ifaces++; | 320 | bat_priv->num_ifaces++; |
342 | hard_iface->if_status = IF_INACTIVE; | 321 | hard_iface->if_status = IF_INACTIVE; |
@@ -381,7 +360,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface, | |||
381 | hard_iface->net_dev->name); | 360 | hard_iface->net_dev->name); |
382 | 361 | ||
383 | /* begin scheduling originator messages on that interface */ | 362 | /* begin scheduling originator messages on that interface */ |
384 | schedule_own_packet(hard_iface); | 363 | schedule_bat_ogm(hard_iface); |
385 | 364 | ||
386 | out: | 365 | out: |
387 | return 0; | 366 | return 0; |
@@ -455,11 +434,8 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev) | |||
455 | dev_hold(net_dev); | 434 | dev_hold(net_dev); |
456 | 435 | ||
457 | hard_iface = kmalloc(sizeof(*hard_iface), GFP_ATOMIC); | 436 | hard_iface = kmalloc(sizeof(*hard_iface), GFP_ATOMIC); |
458 | if (!hard_iface) { | 437 | if (!hard_iface) |
459 | pr_err("Can't add interface (%s): out of memory\n", | ||
460 | net_dev->name); | ||
461 | goto release_dev; | 438 | goto release_dev; |
462 | } | ||
463 | 439 | ||
464 | ret = sysfs_add_hardif(&hard_iface->hardif_obj, net_dev); | 440 | ret = sysfs_add_hardif(&hard_iface->hardif_obj, net_dev); |
465 | if (ret) | 441 | if (ret) |
@@ -551,7 +527,7 @@ static int hard_if_event(struct notifier_block *this, | |||
551 | goto hardif_put; | 527 | goto hardif_put; |
552 | 528 | ||
553 | check_known_mac_addr(hard_iface->net_dev); | 529 | check_known_mac_addr(hard_iface->net_dev); |
554 | update_mac_addresses(hard_iface); | 530 | bat_ogm_update_mac(hard_iface); |
555 | 531 | ||
556 | bat_priv = netdev_priv(hard_iface->soft_iface); | 532 | bat_priv = netdev_priv(hard_iface->soft_iface); |
557 | primary_if = primary_if_get_selected(bat_priv); | 533 | primary_if = primary_if_get_selected(bat_priv); |
@@ -580,7 +556,7 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev, | |||
580 | struct net_device *orig_dev) | 556 | struct net_device *orig_dev) |
581 | { | 557 | { |
582 | struct bat_priv *bat_priv; | 558 | struct bat_priv *bat_priv; |
583 | struct batman_packet *batman_packet; | 559 | struct batman_ogm_packet *batman_ogm_packet; |
584 | struct hard_iface *hard_iface; | 560 | struct hard_iface *hard_iface; |
585 | int ret; | 561 | int ret; |
586 | 562 | ||
@@ -612,22 +588,22 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev, | |||
612 | if (hard_iface->if_status != IF_ACTIVE) | 588 | if (hard_iface->if_status != IF_ACTIVE) |
613 | goto err_free; | 589 | goto err_free; |
614 | 590 | ||
615 | batman_packet = (struct batman_packet *)skb->data; | 591 | batman_ogm_packet = (struct batman_ogm_packet *)skb->data; |
616 | 592 | ||
617 | if (batman_packet->version != COMPAT_VERSION) { | 593 | if (batman_ogm_packet->version != COMPAT_VERSION) { |
618 | bat_dbg(DBG_BATMAN, bat_priv, | 594 | bat_dbg(DBG_BATMAN, bat_priv, |
619 | "Drop packet: incompatible batman version (%i)\n", | 595 | "Drop packet: incompatible batman version (%i)\n", |
620 | batman_packet->version); | 596 | batman_ogm_packet->version); |
621 | goto err_free; | 597 | goto err_free; |
622 | } | 598 | } |
623 | 599 | ||
624 | /* all receive handlers return whether they received or reused | 600 | /* all receive handlers return whether they received or reused |
625 | * the supplied skb. if not, we have to free the skb. */ | 601 | * the supplied skb. if not, we have to free the skb. */ |
626 | 602 | ||
627 | switch (batman_packet->packet_type) { | 603 | switch (batman_ogm_packet->packet_type) { |
628 | /* batman originator packet */ | 604 | /* batman originator packet */ |
629 | case BAT_PACKET: | 605 | case BAT_OGM: |
630 | ret = recv_bat_packet(skb, hard_iface); | 606 | ret = recv_bat_ogm_packet(skb, hard_iface); |
631 | break; | 607 | break; |
632 | 608 | ||
633 | /* batman icmp packet */ | 609 | /* batman icmp packet */ |
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index 79b9ae522ce9..fb87bdc2ce9b 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c | |||
@@ -117,8 +117,6 @@ int mesh_init(struct net_device *soft_iface) | |||
117 | goto end; | 117 | goto end; |
118 | 118 | ||
119 | err: | 119 | err: |
120 | pr_err("Unable to allocate memory for mesh information structures: " | ||
121 | "out of mem ?\n"); | ||
122 | mesh_free(soft_iface); | 120 | mesh_free(soft_iface); |
123 | return -1; | 121 | return -1; |
124 | 122 | ||
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h index 60b369635b4d..964ad4d8ba33 100644 --- a/net/batman-adv/main.h +++ b/net/batman-adv/main.h | |||
@@ -28,7 +28,7 @@ | |||
28 | #define DRIVER_DEVICE "batman-adv" | 28 | #define DRIVER_DEVICE "batman-adv" |
29 | 29 | ||
30 | #ifndef SOURCE_VERSION | 30 | #ifndef SOURCE_VERSION |
31 | #define SOURCE_VERSION "2011.3.0" | 31 | #define SOURCE_VERSION "2011.4.0" |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | /* B.A.T.M.A.N. parameters */ | 34 | /* B.A.T.M.A.N. parameters */ |
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index d448018e514f..0e5b77255d99 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c | |||
@@ -336,8 +336,7 @@ static bool purge_orig_node(struct bat_priv *bat_priv, | |||
336 | } else { | 336 | } else { |
337 | if (purge_orig_neighbors(bat_priv, orig_node, | 337 | if (purge_orig_neighbors(bat_priv, orig_node, |
338 | &best_neigh_node)) { | 338 | &best_neigh_node)) { |
339 | update_routes(bat_priv, orig_node, | 339 | update_route(bat_priv, orig_node, best_neigh_node); |
340 | best_neigh_node); | ||
341 | } | 340 | } |
342 | } | 341 | } |
343 | 342 | ||
@@ -493,10 +492,8 @@ static int orig_node_add_if(struct orig_node *orig_node, int max_if_num) | |||
493 | 492 | ||
494 | data_ptr = kmalloc(max_if_num * sizeof(unsigned long) * NUM_WORDS, | 493 | data_ptr = kmalloc(max_if_num * sizeof(unsigned long) * NUM_WORDS, |
495 | GFP_ATOMIC); | 494 | GFP_ATOMIC); |
496 | if (!data_ptr) { | 495 | if (!data_ptr) |
497 | pr_err("Can't resize orig: out of memory\n"); | ||
498 | return -1; | 496 | return -1; |
499 | } | ||
500 | 497 | ||
501 | memcpy(data_ptr, orig_node->bcast_own, | 498 | memcpy(data_ptr, orig_node->bcast_own, |
502 | (max_if_num - 1) * sizeof(unsigned long) * NUM_WORDS); | 499 | (max_if_num - 1) * sizeof(unsigned long) * NUM_WORDS); |
@@ -504,10 +501,8 @@ static int orig_node_add_if(struct orig_node *orig_node, int max_if_num) | |||
504 | orig_node->bcast_own = data_ptr; | 501 | orig_node->bcast_own = data_ptr; |
505 | 502 | ||
506 | data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC); | 503 | data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC); |
507 | if (!data_ptr) { | 504 | if (!data_ptr) |
508 | pr_err("Can't resize orig: out of memory\n"); | ||
509 | return -1; | 505 | return -1; |
510 | } | ||
511 | 506 | ||
512 | memcpy(data_ptr, orig_node->bcast_own_sum, | 507 | memcpy(data_ptr, orig_node->bcast_own_sum, |
513 | (max_if_num - 1) * sizeof(uint8_t)); | 508 | (max_if_num - 1) * sizeof(uint8_t)); |
@@ -562,10 +557,8 @@ static int orig_node_del_if(struct orig_node *orig_node, | |||
562 | 557 | ||
563 | chunk_size = sizeof(unsigned long) * NUM_WORDS; | 558 | chunk_size = sizeof(unsigned long) * NUM_WORDS; |
564 | data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC); | 559 | data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC); |
565 | if (!data_ptr) { | 560 | if (!data_ptr) |
566 | pr_err("Can't resize orig: out of memory\n"); | ||
567 | return -1; | 561 | return -1; |
568 | } | ||
569 | 562 | ||
570 | /* copy first part */ | 563 | /* copy first part */ |
571 | memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size); | 564 | memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size); |
@@ -583,10 +576,8 @@ free_bcast_own: | |||
583 | goto free_own_sum; | 576 | goto free_own_sum; |
584 | 577 | ||
585 | data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC); | 578 | data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC); |
586 | if (!data_ptr) { | 579 | if (!data_ptr) |
587 | pr_err("Can't resize orig: out of memory\n"); | ||
588 | return -1; | 580 | return -1; |
589 | } | ||
590 | 581 | ||
591 | memcpy(data_ptr, orig_node->bcast_own_sum, | 582 | memcpy(data_ptr, orig_node->bcast_own_sum, |
592 | del_if_num * sizeof(uint8_t)); | 583 | del_if_num * sizeof(uint8_t)); |
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h index 8802eab2a46d..4d9e54c57a36 100644 --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h | |||
@@ -25,14 +25,14 @@ | |||
25 | #define ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */ | 25 | #define ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */ |
26 | 26 | ||
27 | enum bat_packettype { | 27 | enum bat_packettype { |
28 | BAT_PACKET = 0x01, | 28 | BAT_OGM = 0x01, |
29 | BAT_ICMP = 0x02, | 29 | BAT_ICMP = 0x02, |
30 | BAT_UNICAST = 0x03, | 30 | BAT_UNICAST = 0x03, |
31 | BAT_BCAST = 0x04, | 31 | BAT_BCAST = 0x04, |
32 | BAT_VIS = 0x05, | 32 | BAT_VIS = 0x05, |
33 | BAT_UNICAST_FRAG = 0x06, | 33 | BAT_UNICAST_FRAG = 0x06, |
34 | BAT_TT_QUERY = 0x07, | 34 | BAT_TT_QUERY = 0x07, |
35 | BAT_ROAM_ADV = 0x08 | 35 | BAT_ROAM_ADV = 0x08 |
36 | }; | 36 | }; |
37 | 37 | ||
38 | /* this file is included by batctl which needs these defines */ | 38 | /* this file is included by batctl which needs these defines */ |
@@ -90,7 +90,7 @@ enum tt_client_flags { | |||
90 | TT_CLIENT_PENDING = 1 << 10 | 90 | TT_CLIENT_PENDING = 1 << 10 |
91 | }; | 91 | }; |
92 | 92 | ||
93 | struct batman_packet { | 93 | struct batman_ogm_packet { |
94 | uint8_t packet_type; | 94 | uint8_t packet_type; |
95 | uint8_t version; /* batman version field */ | 95 | uint8_t version; /* batman version field */ |
96 | uint8_t ttl; | 96 | uint8_t ttl; |
@@ -105,7 +105,7 @@ struct batman_packet { | |||
105 | uint16_t tt_crc; | 105 | uint16_t tt_crc; |
106 | } __packed; | 106 | } __packed; |
107 | 107 | ||
108 | #define BAT_PACKET_LEN sizeof(struct batman_packet) | 108 | #define BATMAN_OGM_LEN sizeof(struct batman_ogm_packet) |
109 | 109 | ||
110 | struct icmp_packet { | 110 | struct icmp_packet { |
111 | uint8_t packet_type; | 111 | uint8_t packet_type; |
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 19499281b695..f961cc5eade5 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c | |||
@@ -22,18 +22,14 @@ | |||
22 | #include "main.h" | 22 | #include "main.h" |
23 | #include "routing.h" | 23 | #include "routing.h" |
24 | #include "send.h" | 24 | #include "send.h" |
25 | #include "hash.h" | ||
26 | #include "soft-interface.h" | 25 | #include "soft-interface.h" |
27 | #include "hard-interface.h" | 26 | #include "hard-interface.h" |
28 | #include "icmp_socket.h" | 27 | #include "icmp_socket.h" |
29 | #include "translation-table.h" | 28 | #include "translation-table.h" |
30 | #include "originator.h" | 29 | #include "originator.h" |
31 | #include "ring_buffer.h" | ||
32 | #include "vis.h" | 30 | #include "vis.h" |
33 | #include "aggregation.h" | ||
34 | #include "gateway_common.h" | ||
35 | #include "gateway_client.h" | ||
36 | #include "unicast.h" | 31 | #include "unicast.h" |
32 | #include "bat_ogm.h" | ||
37 | 33 | ||
38 | void slide_own_bcast_window(struct hard_iface *hard_iface) | 34 | void slide_own_bcast_window(struct hard_iface *hard_iface) |
39 | { | 35 | { |
@@ -64,9 +60,9 @@ void slide_own_bcast_window(struct hard_iface *hard_iface) | |||
64 | } | 60 | } |
65 | } | 61 | } |
66 | 62 | ||
67 | static void update_route(struct bat_priv *bat_priv, | 63 | static void _update_route(struct bat_priv *bat_priv, |
68 | struct orig_node *orig_node, | 64 | struct orig_node *orig_node, |
69 | struct neigh_node *neigh_node) | 65 | struct neigh_node *neigh_node) |
70 | { | 66 | { |
71 | struct neigh_node *curr_router; | 67 | struct neigh_node *curr_router; |
72 | 68 | ||
@@ -110,8 +106,8 @@ static void update_route(struct bat_priv *bat_priv, | |||
110 | neigh_node_free_ref(curr_router); | 106 | neigh_node_free_ref(curr_router); |
111 | } | 107 | } |
112 | 108 | ||
113 | void update_routes(struct bat_priv *bat_priv, struct orig_node *orig_node, | 109 | void update_route(struct bat_priv *bat_priv, struct orig_node *orig_node, |
114 | struct neigh_node *neigh_node) | 110 | struct neigh_node *neigh_node) |
115 | { | 111 | { |
116 | struct neigh_node *router = NULL; | 112 | struct neigh_node *router = NULL; |
117 | 113 | ||
@@ -121,116 +117,13 @@ void update_routes(struct bat_priv *bat_priv, struct orig_node *orig_node, | |||
121 | router = orig_node_get_router(orig_node); | 117 | router = orig_node_get_router(orig_node); |
122 | 118 | ||
123 | if (router != neigh_node) | 119 | if (router != neigh_node) |
124 | update_route(bat_priv, orig_node, neigh_node); | 120 | _update_route(bat_priv, orig_node, neigh_node); |
125 | 121 | ||
126 | out: | 122 | out: |
127 | if (router) | 123 | if (router) |
128 | neigh_node_free_ref(router); | 124 | neigh_node_free_ref(router); |
129 | } | 125 | } |
130 | 126 | ||
131 | static int is_bidirectional_neigh(struct orig_node *orig_node, | ||
132 | struct orig_node *orig_neigh_node, | ||
133 | struct batman_packet *batman_packet, | ||
134 | struct hard_iface *if_incoming) | ||
135 | { | ||
136 | struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
137 | struct neigh_node *neigh_node = NULL, *tmp_neigh_node; | ||
138 | struct hlist_node *node; | ||
139 | uint8_t total_count; | ||
140 | uint8_t orig_eq_count, neigh_rq_count, tq_own; | ||
141 | int tq_asym_penalty, ret = 0; | ||
142 | |||
143 | /* find corresponding one hop neighbor */ | ||
144 | rcu_read_lock(); | ||
145 | hlist_for_each_entry_rcu(tmp_neigh_node, node, | ||
146 | &orig_neigh_node->neigh_list, list) { | ||
147 | |||
148 | if (!compare_eth(tmp_neigh_node->addr, orig_neigh_node->orig)) | ||
149 | continue; | ||
150 | |||
151 | if (tmp_neigh_node->if_incoming != if_incoming) | ||
152 | continue; | ||
153 | |||
154 | if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) | ||
155 | continue; | ||
156 | |||
157 | neigh_node = tmp_neigh_node; | ||
158 | break; | ||
159 | } | ||
160 | rcu_read_unlock(); | ||
161 | |||
162 | if (!neigh_node) | ||
163 | neigh_node = create_neighbor(orig_neigh_node, | ||
164 | orig_neigh_node, | ||
165 | orig_neigh_node->orig, | ||
166 | if_incoming); | ||
167 | |||
168 | if (!neigh_node) | ||
169 | goto out; | ||
170 | |||
171 | /* if orig_node is direct neighbor update neigh_node last_valid */ | ||
172 | if (orig_node == orig_neigh_node) | ||
173 | neigh_node->last_valid = jiffies; | ||
174 | |||
175 | orig_node->last_valid = jiffies; | ||
176 | |||
177 | /* find packet count of corresponding one hop neighbor */ | ||
178 | spin_lock_bh(&orig_node->ogm_cnt_lock); | ||
179 | orig_eq_count = orig_neigh_node->bcast_own_sum[if_incoming->if_num]; | ||
180 | neigh_rq_count = neigh_node->real_packet_count; | ||
181 | spin_unlock_bh(&orig_node->ogm_cnt_lock); | ||
182 | |||
183 | /* pay attention to not get a value bigger than 100 % */ | ||
184 | total_count = (orig_eq_count > neigh_rq_count ? | ||
185 | neigh_rq_count : orig_eq_count); | ||
186 | |||
187 | /* if we have too few packets (too less data) we set tq_own to zero */ | ||
188 | /* if we receive too few packets it is not considered bidirectional */ | ||
189 | if ((total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM) || | ||
190 | (neigh_rq_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM)) | ||
191 | tq_own = 0; | ||
192 | else | ||
193 | /* neigh_node->real_packet_count is never zero as we | ||
194 | * only purge old information when getting new | ||
195 | * information */ | ||
196 | tq_own = (TQ_MAX_VALUE * total_count) / neigh_rq_count; | ||
197 | |||
198 | /* | ||
199 | * 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does | ||
200 | * affect the nearly-symmetric links only a little, but | ||
201 | * punishes asymmetric links more. This will give a value | ||
202 | * between 0 and TQ_MAX_VALUE | ||
203 | */ | ||
204 | tq_asym_penalty = TQ_MAX_VALUE - (TQ_MAX_VALUE * | ||
205 | (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) * | ||
206 | (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count) * | ||
207 | (TQ_LOCAL_WINDOW_SIZE - neigh_rq_count)) / | ||
208 | (TQ_LOCAL_WINDOW_SIZE * | ||
209 | TQ_LOCAL_WINDOW_SIZE * | ||
210 | TQ_LOCAL_WINDOW_SIZE); | ||
211 | |||
212 | batman_packet->tq = ((batman_packet->tq * tq_own * tq_asym_penalty) / | ||
213 | (TQ_MAX_VALUE * TQ_MAX_VALUE)); | ||
214 | |||
215 | bat_dbg(DBG_BATMAN, bat_priv, | ||
216 | "bidirectional: " | ||
217 | "orig = %-15pM neigh = %-15pM => own_bcast = %2i, " | ||
218 | "real recv = %2i, local tq: %3i, asym_penalty: %3i, " | ||
219 | "total tq: %3i\n", | ||
220 | orig_node->orig, orig_neigh_node->orig, total_count, | ||
221 | neigh_rq_count, tq_own, tq_asym_penalty, batman_packet->tq); | ||
222 | |||
223 | /* if link has the minimum required transmission quality | ||
224 | * consider it bidirectional */ | ||
225 | if (batman_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT) | ||
226 | ret = 1; | ||
227 | |||
228 | out: | ||
229 | if (neigh_node) | ||
230 | neigh_node_free_ref(neigh_node); | ||
231 | return ret; | ||
232 | } | ||
233 | |||
234 | /* caller must hold the neigh_list_lock */ | 127 | /* caller must hold the neigh_list_lock */ |
235 | void bonding_candidate_del(struct orig_node *orig_node, | 128 | void bonding_candidate_del(struct orig_node *orig_node, |
236 | struct neigh_node *neigh_node) | 129 | struct neigh_node *neigh_node) |
@@ -248,8 +141,8 @@ out: | |||
248 | return; | 141 | return; |
249 | } | 142 | } |
250 | 143 | ||
251 | static void bonding_candidate_add(struct orig_node *orig_node, | 144 | void bonding_candidate_add(struct orig_node *orig_node, |
252 | struct neigh_node *neigh_node) | 145 | struct neigh_node *neigh_node) |
253 | { | 146 | { |
254 | struct hlist_node *node; | 147 | struct hlist_node *node; |
255 | struct neigh_node *tmp_neigh_node, *router = NULL; | 148 | struct neigh_node *tmp_neigh_node, *router = NULL; |
@@ -319,161 +212,23 @@ out: | |||
319 | } | 212 | } |
320 | 213 | ||
321 | /* copy primary address for bonding */ | 214 | /* copy primary address for bonding */ |
322 | static void bonding_save_primary(const struct orig_node *orig_node, | 215 | void bonding_save_primary(const struct orig_node *orig_node, |
323 | struct orig_node *orig_neigh_node, | 216 | struct orig_node *orig_neigh_node, |
324 | const struct batman_packet *batman_packet) | 217 | const struct batman_ogm_packet *batman_ogm_packet) |
325 | { | 218 | { |
326 | if (!(batman_packet->flags & PRIMARIES_FIRST_HOP)) | 219 | if (!(batman_ogm_packet->flags & PRIMARIES_FIRST_HOP)) |
327 | return; | 220 | return; |
328 | 221 | ||
329 | memcpy(orig_neigh_node->primary_addr, orig_node->orig, ETH_ALEN); | 222 | memcpy(orig_neigh_node->primary_addr, orig_node->orig, ETH_ALEN); |
330 | } | 223 | } |
331 | 224 | ||
332 | static void update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node, | ||
333 | const struct ethhdr *ethhdr, | ||
334 | const struct batman_packet *batman_packet, | ||
335 | struct hard_iface *if_incoming, | ||
336 | const unsigned char *tt_buff, int is_duplicate) | ||
337 | { | ||
338 | struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL; | ||
339 | struct neigh_node *router = NULL; | ||
340 | struct orig_node *orig_node_tmp; | ||
341 | struct hlist_node *node; | ||
342 | uint8_t bcast_own_sum_orig, bcast_own_sum_neigh; | ||
343 | |||
344 | bat_dbg(DBG_BATMAN, bat_priv, "update_originator(): " | ||
345 | "Searching and updating originator entry of received packet\n"); | ||
346 | |||
347 | rcu_read_lock(); | ||
348 | hlist_for_each_entry_rcu(tmp_neigh_node, node, | ||
349 | &orig_node->neigh_list, list) { | ||
350 | if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) && | ||
351 | (tmp_neigh_node->if_incoming == if_incoming) && | ||
352 | atomic_inc_not_zero(&tmp_neigh_node->refcount)) { | ||
353 | if (neigh_node) | ||
354 | neigh_node_free_ref(neigh_node); | ||
355 | neigh_node = tmp_neigh_node; | ||
356 | continue; | ||
357 | } | ||
358 | |||
359 | if (is_duplicate) | ||
360 | continue; | ||
361 | |||
362 | spin_lock_bh(&tmp_neigh_node->tq_lock); | ||
363 | ring_buffer_set(tmp_neigh_node->tq_recv, | ||
364 | &tmp_neigh_node->tq_index, 0); | ||
365 | tmp_neigh_node->tq_avg = | ||
366 | ring_buffer_avg(tmp_neigh_node->tq_recv); | ||
367 | spin_unlock_bh(&tmp_neigh_node->tq_lock); | ||
368 | } | ||
369 | |||
370 | if (!neigh_node) { | ||
371 | struct orig_node *orig_tmp; | ||
372 | |||
373 | orig_tmp = get_orig_node(bat_priv, ethhdr->h_source); | ||
374 | if (!orig_tmp) | ||
375 | goto unlock; | ||
376 | |||
377 | neigh_node = create_neighbor(orig_node, orig_tmp, | ||
378 | ethhdr->h_source, if_incoming); | ||
379 | |||
380 | orig_node_free_ref(orig_tmp); | ||
381 | if (!neigh_node) | ||
382 | goto unlock; | ||
383 | } else | ||
384 | bat_dbg(DBG_BATMAN, bat_priv, | ||
385 | "Updating existing last-hop neighbor of originator\n"); | ||
386 | |||
387 | rcu_read_unlock(); | ||
388 | |||
389 | orig_node->flags = batman_packet->flags; | ||
390 | neigh_node->last_valid = jiffies; | ||
391 | |||
392 | spin_lock_bh(&neigh_node->tq_lock); | ||
393 | ring_buffer_set(neigh_node->tq_recv, | ||
394 | &neigh_node->tq_index, | ||
395 | batman_packet->tq); | ||
396 | neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv); | ||
397 | spin_unlock_bh(&neigh_node->tq_lock); | ||
398 | |||
399 | if (!is_duplicate) { | ||
400 | orig_node->last_ttl = batman_packet->ttl; | ||
401 | neigh_node->last_ttl = batman_packet->ttl; | ||
402 | } | ||
403 | |||
404 | bonding_candidate_add(orig_node, neigh_node); | ||
405 | |||
406 | /* if this neighbor already is our next hop there is nothing | ||
407 | * to change */ | ||
408 | router = orig_node_get_router(orig_node); | ||
409 | if (router == neigh_node) | ||
410 | goto update_tt; | ||
411 | |||
412 | /* if this neighbor does not offer a better TQ we won't consider it */ | ||
413 | if (router && (router->tq_avg > neigh_node->tq_avg)) | ||
414 | goto update_tt; | ||
415 | |||
416 | /* if the TQ is the same and the link not more symmetric we | ||
417 | * won't consider it either */ | ||
418 | if (router && (neigh_node->tq_avg == router->tq_avg)) { | ||
419 | orig_node_tmp = router->orig_node; | ||
420 | spin_lock_bh(&orig_node_tmp->ogm_cnt_lock); | ||
421 | bcast_own_sum_orig = | ||
422 | orig_node_tmp->bcast_own_sum[if_incoming->if_num]; | ||
423 | spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock); | ||
424 | |||
425 | orig_node_tmp = neigh_node->orig_node; | ||
426 | spin_lock_bh(&orig_node_tmp->ogm_cnt_lock); | ||
427 | bcast_own_sum_neigh = | ||
428 | orig_node_tmp->bcast_own_sum[if_incoming->if_num]; | ||
429 | spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock); | ||
430 | |||
431 | if (bcast_own_sum_orig >= bcast_own_sum_neigh) | ||
432 | goto update_tt; | ||
433 | } | ||
434 | |||
435 | update_routes(bat_priv, orig_node, neigh_node); | ||
436 | |||
437 | update_tt: | ||
438 | /* I have to check for transtable changes only if the OGM has been | ||
439 | * sent through a primary interface */ | ||
440 | if (((batman_packet->orig != ethhdr->h_source) && | ||
441 | (batman_packet->ttl > 2)) || | ||
442 | (batman_packet->flags & PRIMARIES_FIRST_HOP)) | ||
443 | tt_update_orig(bat_priv, orig_node, tt_buff, | ||
444 | batman_packet->tt_num_changes, | ||
445 | batman_packet->ttvn, batman_packet->tt_crc); | ||
446 | |||
447 | if (orig_node->gw_flags != batman_packet->gw_flags) | ||
448 | gw_node_update(bat_priv, orig_node, batman_packet->gw_flags); | ||
449 | |||
450 | orig_node->gw_flags = batman_packet->gw_flags; | ||
451 | |||
452 | /* restart gateway selection if fast or late switching was enabled */ | ||
453 | if ((orig_node->gw_flags) && | ||
454 | (atomic_read(&bat_priv->gw_mode) == GW_MODE_CLIENT) && | ||
455 | (atomic_read(&bat_priv->gw_sel_class) > 2)) | ||
456 | gw_check_election(bat_priv, orig_node); | ||
457 | |||
458 | goto out; | ||
459 | |||
460 | unlock: | ||
461 | rcu_read_unlock(); | ||
462 | out: | ||
463 | if (neigh_node) | ||
464 | neigh_node_free_ref(neigh_node); | ||
465 | if (router) | ||
466 | neigh_node_free_ref(router); | ||
467 | } | ||
468 | |||
469 | /* checks whether the host restarted and is in the protection time. | 225 | /* checks whether the host restarted and is in the protection time. |
470 | * returns: | 226 | * returns: |
471 | * 0 if the packet is to be accepted | 227 | * 0 if the packet is to be accepted |
472 | * 1 if the packet is to be ignored. | 228 | * 1 if the packet is to be ignored. |
473 | */ | 229 | */ |
474 | static int window_protected(struct bat_priv *bat_priv, | 230 | int window_protected(struct bat_priv *bat_priv, int32_t seq_num_diff, |
475 | int32_t seq_num_diff, | 231 | unsigned long *last_reset) |
476 | unsigned long *last_reset) | ||
477 | { | 232 | { |
478 | if ((seq_num_diff <= -TQ_LOCAL_WINDOW_SIZE) | 233 | if ((seq_num_diff <= -TQ_LOCAL_WINDOW_SIZE) |
479 | || (seq_num_diff >= EXPECTED_SEQNO_RANGE)) { | 234 | || (seq_num_diff >= EXPECTED_SEQNO_RANGE)) { |
@@ -491,330 +246,12 @@ static int window_protected(struct bat_priv *bat_priv, | |||
491 | return 0; | 246 | return 0; |
492 | } | 247 | } |
493 | 248 | ||
494 | /* processes a batman packet for all interfaces, adjusts the sequence number and | 249 | int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *hard_iface) |
495 | * finds out whether it is a duplicate. | ||
496 | * returns: | ||
497 | * 1 the packet is a duplicate | ||
498 | * 0 the packet has not yet been received | ||
499 | * -1 the packet is old and has been received while the seqno window | ||
500 | * was protected. Caller should drop it. | ||
501 | */ | ||
502 | static int count_real_packets(const struct ethhdr *ethhdr, | ||
503 | const struct batman_packet *batman_packet, | ||
504 | const struct hard_iface *if_incoming) | ||
505 | { | ||
506 | struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
507 | struct orig_node *orig_node; | ||
508 | struct neigh_node *tmp_neigh_node; | ||
509 | struct hlist_node *node; | ||
510 | int is_duplicate = 0; | ||
511 | int32_t seq_diff; | ||
512 | int need_update = 0; | ||
513 | int set_mark, ret = -1; | ||
514 | |||
515 | orig_node = get_orig_node(bat_priv, batman_packet->orig); | ||
516 | if (!orig_node) | ||
517 | return 0; | ||
518 | |||
519 | spin_lock_bh(&orig_node->ogm_cnt_lock); | ||
520 | seq_diff = batman_packet->seqno - orig_node->last_real_seqno; | ||
521 | |||
522 | /* signalize caller that the packet is to be dropped. */ | ||
523 | if (window_protected(bat_priv, seq_diff, | ||
524 | &orig_node->batman_seqno_reset)) | ||
525 | goto out; | ||
526 | |||
527 | rcu_read_lock(); | ||
528 | hlist_for_each_entry_rcu(tmp_neigh_node, node, | ||
529 | &orig_node->neigh_list, list) { | ||
530 | |||
531 | is_duplicate |= get_bit_status(tmp_neigh_node->real_bits, | ||
532 | orig_node->last_real_seqno, | ||
533 | batman_packet->seqno); | ||
534 | |||
535 | if (compare_eth(tmp_neigh_node->addr, ethhdr->h_source) && | ||
536 | (tmp_neigh_node->if_incoming == if_incoming)) | ||
537 | set_mark = 1; | ||
538 | else | ||
539 | set_mark = 0; | ||
540 | |||
541 | /* if the window moved, set the update flag. */ | ||
542 | need_update |= bit_get_packet(bat_priv, | ||
543 | tmp_neigh_node->real_bits, | ||
544 | seq_diff, set_mark); | ||
545 | |||
546 | tmp_neigh_node->real_packet_count = | ||
547 | bit_packet_count(tmp_neigh_node->real_bits); | ||
548 | } | ||
549 | rcu_read_unlock(); | ||
550 | |||
551 | if (need_update) { | ||
552 | bat_dbg(DBG_BATMAN, bat_priv, | ||
553 | "updating last_seqno: old %d, new %d\n", | ||
554 | orig_node->last_real_seqno, batman_packet->seqno); | ||
555 | orig_node->last_real_seqno = batman_packet->seqno; | ||
556 | } | ||
557 | |||
558 | ret = is_duplicate; | ||
559 | |||
560 | out: | ||
561 | spin_unlock_bh(&orig_node->ogm_cnt_lock); | ||
562 | orig_node_free_ref(orig_node); | ||
563 | return ret; | ||
564 | } | ||
565 | |||
566 | void receive_bat_packet(const struct ethhdr *ethhdr, | ||
567 | struct batman_packet *batman_packet, | ||
568 | const unsigned char *tt_buff, | ||
569 | struct hard_iface *if_incoming) | ||
570 | { | ||
571 | struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
572 | struct hard_iface *hard_iface; | ||
573 | struct orig_node *orig_neigh_node, *orig_node; | ||
574 | struct neigh_node *router = NULL, *router_router = NULL; | ||
575 | struct neigh_node *orig_neigh_router = NULL; | ||
576 | int has_directlink_flag; | ||
577 | int is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0; | ||
578 | int is_broadcast = 0, is_bidirectional, is_single_hop_neigh; | ||
579 | int is_duplicate; | ||
580 | uint32_t if_incoming_seqno; | ||
581 | |||
582 | /* Silently drop when the batman packet is actually not a | ||
583 | * correct packet. | ||
584 | * | ||
585 | * This might happen if a packet is padded (e.g. Ethernet has a | ||
586 | * minimum frame length of 64 byte) and the aggregation interprets | ||
587 | * it as an additional length. | ||
588 | * | ||
589 | * TODO: A more sane solution would be to have a bit in the | ||
590 | * batman_packet to detect whether the packet is the last | ||
591 | * packet in an aggregation. Here we expect that the padding | ||
592 | * is always zero (or not 0x01) | ||
593 | */ | ||
594 | if (batman_packet->packet_type != BAT_PACKET) | ||
595 | return; | ||
596 | |||
597 | /* could be changed by schedule_own_packet() */ | ||
598 | if_incoming_seqno = atomic_read(&if_incoming->seqno); | ||
599 | |||
600 | has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0); | ||
601 | |||
602 | is_single_hop_neigh = (compare_eth(ethhdr->h_source, | ||
603 | batman_packet->orig) ? 1 : 0); | ||
604 | |||
605 | bat_dbg(DBG_BATMAN, bat_priv, | ||
606 | "Received BATMAN packet via NB: %pM, IF: %s [%pM] " | ||
607 | "(from OG: %pM, via prev OG: %pM, seqno %d, ttvn %u, " | ||
608 | "crc %u, changes %u, td %d, TTL %d, V %d, IDF %d)\n", | ||
609 | ethhdr->h_source, if_incoming->net_dev->name, | ||
610 | if_incoming->net_dev->dev_addr, batman_packet->orig, | ||
611 | batman_packet->prev_sender, batman_packet->seqno, | ||
612 | batman_packet->ttvn, batman_packet->tt_crc, | ||
613 | batman_packet->tt_num_changes, batman_packet->tq, | ||
614 | batman_packet->ttl, batman_packet->version, | ||
615 | has_directlink_flag); | ||
616 | |||
617 | rcu_read_lock(); | ||
618 | list_for_each_entry_rcu(hard_iface, &hardif_list, list) { | ||
619 | if (hard_iface->if_status != IF_ACTIVE) | ||
620 | continue; | ||
621 | |||
622 | if (hard_iface->soft_iface != if_incoming->soft_iface) | ||
623 | continue; | ||
624 | |||
625 | if (compare_eth(ethhdr->h_source, | ||
626 | hard_iface->net_dev->dev_addr)) | ||
627 | is_my_addr = 1; | ||
628 | |||
629 | if (compare_eth(batman_packet->orig, | ||
630 | hard_iface->net_dev->dev_addr)) | ||
631 | is_my_orig = 1; | ||
632 | |||
633 | if (compare_eth(batman_packet->prev_sender, | ||
634 | hard_iface->net_dev->dev_addr)) | ||
635 | is_my_oldorig = 1; | ||
636 | |||
637 | if (is_broadcast_ether_addr(ethhdr->h_source)) | ||
638 | is_broadcast = 1; | ||
639 | } | ||
640 | rcu_read_unlock(); | ||
641 | |||
642 | if (batman_packet->version != COMPAT_VERSION) { | ||
643 | bat_dbg(DBG_BATMAN, bat_priv, | ||
644 | "Drop packet: incompatible batman version (%i)\n", | ||
645 | batman_packet->version); | ||
646 | return; | ||
647 | } | ||
648 | |||
649 | if (is_my_addr) { | ||
650 | bat_dbg(DBG_BATMAN, bat_priv, | ||
651 | "Drop packet: received my own broadcast (sender: %pM" | ||
652 | ")\n", | ||
653 | ethhdr->h_source); | ||
654 | return; | ||
655 | } | ||
656 | |||
657 | if (is_broadcast) { | ||
658 | bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: " | ||
659 | "ignoring all packets with broadcast source addr (sender: %pM" | ||
660 | ")\n", ethhdr->h_source); | ||
661 | return; | ||
662 | } | ||
663 | |||
664 | if (is_my_orig) { | ||
665 | unsigned long *word; | ||
666 | int offset; | ||
667 | |||
668 | orig_neigh_node = get_orig_node(bat_priv, ethhdr->h_source); | ||
669 | if (!orig_neigh_node) | ||
670 | return; | ||
671 | |||
672 | /* neighbor has to indicate direct link and it has to | ||
673 | * come via the corresponding interface */ | ||
674 | /* save packet seqno for bidirectional check */ | ||
675 | if (has_directlink_flag && | ||
676 | compare_eth(if_incoming->net_dev->dev_addr, | ||
677 | batman_packet->orig)) { | ||
678 | offset = if_incoming->if_num * NUM_WORDS; | ||
679 | |||
680 | spin_lock_bh(&orig_neigh_node->ogm_cnt_lock); | ||
681 | word = &(orig_neigh_node->bcast_own[offset]); | ||
682 | bit_mark(word, | ||
683 | if_incoming_seqno - batman_packet->seqno - 2); | ||
684 | orig_neigh_node->bcast_own_sum[if_incoming->if_num] = | ||
685 | bit_packet_count(word); | ||
686 | spin_unlock_bh(&orig_neigh_node->ogm_cnt_lock); | ||
687 | } | ||
688 | |||
689 | bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: " | ||
690 | "originator packet from myself (via neighbor)\n"); | ||
691 | orig_node_free_ref(orig_neigh_node); | ||
692 | return; | ||
693 | } | ||
694 | |||
695 | if (is_my_oldorig) { | ||
696 | bat_dbg(DBG_BATMAN, bat_priv, | ||
697 | "Drop packet: ignoring all rebroadcast echos (sender: " | ||
698 | "%pM)\n", ethhdr->h_source); | ||
699 | return; | ||
700 | } | ||
701 | |||
702 | orig_node = get_orig_node(bat_priv, batman_packet->orig); | ||
703 | if (!orig_node) | ||
704 | return; | ||
705 | |||
706 | is_duplicate = count_real_packets(ethhdr, batman_packet, if_incoming); | ||
707 | |||
708 | if (is_duplicate == -1) { | ||
709 | bat_dbg(DBG_BATMAN, bat_priv, | ||
710 | "Drop packet: packet within seqno protection time " | ||
711 | "(sender: %pM)\n", ethhdr->h_source); | ||
712 | goto out; | ||
713 | } | ||
714 | |||
715 | if (batman_packet->tq == 0) { | ||
716 | bat_dbg(DBG_BATMAN, bat_priv, | ||
717 | "Drop packet: originator packet with tq equal 0\n"); | ||
718 | goto out; | ||
719 | } | ||
720 | |||
721 | router = orig_node_get_router(orig_node); | ||
722 | if (router) | ||
723 | router_router = orig_node_get_router(router->orig_node); | ||
724 | |||
725 | /* avoid temporary routing loops */ | ||
726 | if (router && router_router && | ||
727 | (compare_eth(router->addr, batman_packet->prev_sender)) && | ||
728 | !(compare_eth(batman_packet->orig, batman_packet->prev_sender)) && | ||
729 | (compare_eth(router->addr, router_router->addr))) { | ||
730 | bat_dbg(DBG_BATMAN, bat_priv, | ||
731 | "Drop packet: ignoring all rebroadcast packets that " | ||
732 | "may make me loop (sender: %pM)\n", ethhdr->h_source); | ||
733 | goto out; | ||
734 | } | ||
735 | |||
736 | /* if sender is a direct neighbor the sender mac equals | ||
737 | * originator mac */ | ||
738 | orig_neigh_node = (is_single_hop_neigh ? | ||
739 | orig_node : | ||
740 | get_orig_node(bat_priv, ethhdr->h_source)); | ||
741 | if (!orig_neigh_node) | ||
742 | goto out; | ||
743 | |||
744 | orig_neigh_router = orig_node_get_router(orig_neigh_node); | ||
745 | |||
746 | /* drop packet if sender is not a direct neighbor and if we | ||
747 | * don't route towards it */ | ||
748 | if (!is_single_hop_neigh && (!orig_neigh_router)) { | ||
749 | bat_dbg(DBG_BATMAN, bat_priv, | ||
750 | "Drop packet: OGM via unknown neighbor!\n"); | ||
751 | goto out_neigh; | ||
752 | } | ||
753 | |||
754 | is_bidirectional = is_bidirectional_neigh(orig_node, orig_neigh_node, | ||
755 | batman_packet, if_incoming); | ||
756 | |||
757 | bonding_save_primary(orig_node, orig_neigh_node, batman_packet); | ||
758 | |||
759 | /* update ranking if it is not a duplicate or has the same | ||
760 | * seqno and similar ttl as the non-duplicate */ | ||
761 | if (is_bidirectional && | ||
762 | (!is_duplicate || | ||
763 | ((orig_node->last_real_seqno == batman_packet->seqno) && | ||
764 | (orig_node->last_ttl - 3 <= batman_packet->ttl)))) | ||
765 | update_orig(bat_priv, orig_node, ethhdr, batman_packet, | ||
766 | if_incoming, tt_buff, is_duplicate); | ||
767 | |||
768 | /* is single hop (direct) neighbor */ | ||
769 | if (is_single_hop_neigh) { | ||
770 | |||
771 | /* mark direct link on incoming interface */ | ||
772 | schedule_forward_packet(orig_node, ethhdr, batman_packet, | ||
773 | 1, if_incoming); | ||
774 | |||
775 | bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: " | ||
776 | "rebroadcast neighbor packet with direct link flag\n"); | ||
777 | goto out_neigh; | ||
778 | } | ||
779 | |||
780 | /* multihop originator */ | ||
781 | if (!is_bidirectional) { | ||
782 | bat_dbg(DBG_BATMAN, bat_priv, | ||
783 | "Drop packet: not received via bidirectional link\n"); | ||
784 | goto out_neigh; | ||
785 | } | ||
786 | |||
787 | if (is_duplicate) { | ||
788 | bat_dbg(DBG_BATMAN, bat_priv, | ||
789 | "Drop packet: duplicate packet received\n"); | ||
790 | goto out_neigh; | ||
791 | } | ||
792 | |||
793 | bat_dbg(DBG_BATMAN, bat_priv, | ||
794 | "Forwarding packet: rebroadcast originator packet\n"); | ||
795 | schedule_forward_packet(orig_node, ethhdr, batman_packet, | ||
796 | 0, if_incoming); | ||
797 | |||
798 | out_neigh: | ||
799 | if ((orig_neigh_node) && (!is_single_hop_neigh)) | ||
800 | orig_node_free_ref(orig_neigh_node); | ||
801 | out: | ||
802 | if (router) | ||
803 | neigh_node_free_ref(router); | ||
804 | if (router_router) | ||
805 | neigh_node_free_ref(router_router); | ||
806 | if (orig_neigh_router) | ||
807 | neigh_node_free_ref(orig_neigh_router); | ||
808 | |||
809 | orig_node_free_ref(orig_node); | ||
810 | } | ||
811 | |||
812 | int recv_bat_packet(struct sk_buff *skb, struct hard_iface *hard_iface) | ||
813 | { | 250 | { |
814 | struct ethhdr *ethhdr; | 251 | struct ethhdr *ethhdr; |
815 | 252 | ||
816 | /* drop packet if it has not necessary minimum size */ | 253 | /* drop packet if it has not necessary minimum size */ |
817 | if (unlikely(!pskb_may_pull(skb, sizeof(struct batman_packet)))) | 254 | if (unlikely(!pskb_may_pull(skb, BATMAN_OGM_LEN))) |
818 | return NET_RX_DROP; | 255 | return NET_RX_DROP; |
819 | 256 | ||
820 | ethhdr = (struct ethhdr *)skb_mac_header(skb); | 257 | ethhdr = (struct ethhdr *)skb_mac_header(skb); |
@@ -837,10 +274,7 @@ int recv_bat_packet(struct sk_buff *skb, struct hard_iface *hard_iface) | |||
837 | 274 | ||
838 | ethhdr = (struct ethhdr *)skb_mac_header(skb); | 275 | ethhdr = (struct ethhdr *)skb_mac_header(skb); |
839 | 276 | ||
840 | receive_aggr_bat_packet(ethhdr, | 277 | bat_ogm_receive(ethhdr, skb->data, skb_headlen(skb), hard_iface); |
841 | skb->data, | ||
842 | skb_headlen(skb), | ||
843 | hard_iface); | ||
844 | 278 | ||
845 | kfree_skb(skb); | 279 | kfree_skb(skb); |
846 | return NET_RX_SUCCESS; | 280 | return NET_RX_SUCCESS; |
diff --git a/net/batman-adv/routing.h b/net/batman-adv/routing.h index fb14e9579b19..7aaee0fb0fdc 100644 --- a/net/batman-adv/routing.h +++ b/net/batman-adv/routing.h | |||
@@ -23,19 +23,15 @@ | |||
23 | #define _NET_BATMAN_ADV_ROUTING_H_ | 23 | #define _NET_BATMAN_ADV_ROUTING_H_ |
24 | 24 | ||
25 | void slide_own_bcast_window(struct hard_iface *hard_iface); | 25 | void slide_own_bcast_window(struct hard_iface *hard_iface); |
26 | void receive_bat_packet(const struct ethhdr *ethhdr, | 26 | void update_route(struct bat_priv *bat_priv, struct orig_node *orig_node, |
27 | struct batman_packet *batman_packet, | 27 | struct neigh_node *neigh_node); |
28 | const unsigned char *tt_buff, | ||
29 | struct hard_iface *if_incoming); | ||
30 | void update_routes(struct bat_priv *bat_priv, struct orig_node *orig_node, | ||
31 | struct neigh_node *neigh_node); | ||
32 | int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if); | 28 | int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if); |
33 | int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if); | 29 | int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if); |
34 | int recv_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if); | 30 | int recv_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if); |
35 | int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if); | 31 | int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if); |
36 | int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if); | 32 | int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if); |
37 | int recv_vis_packet(struct sk_buff *skb, struct hard_iface *recv_if); | 33 | int recv_vis_packet(struct sk_buff *skb, struct hard_iface *recv_if); |
38 | int recv_bat_packet(struct sk_buff *skb, struct hard_iface *recv_if); | 34 | int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *recv_if); |
39 | int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if); | 35 | int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if); |
40 | int recv_roam_adv(struct sk_buff *skb, struct hard_iface *recv_if); | 36 | int recv_roam_adv(struct sk_buff *skb, struct hard_iface *recv_if); |
41 | struct neigh_node *find_router(struct bat_priv *bat_priv, | 37 | struct neigh_node *find_router(struct bat_priv *bat_priv, |
@@ -43,5 +39,12 @@ struct neigh_node *find_router(struct bat_priv *bat_priv, | |||
43 | const struct hard_iface *recv_if); | 39 | const struct hard_iface *recv_if); |
44 | void bonding_candidate_del(struct orig_node *orig_node, | 40 | void bonding_candidate_del(struct orig_node *orig_node, |
45 | struct neigh_node *neigh_node); | 41 | struct neigh_node *neigh_node); |
42 | void bonding_candidate_add(struct orig_node *orig_node, | ||
43 | struct neigh_node *neigh_node); | ||
44 | void bonding_save_primary(const struct orig_node *orig_node, | ||
45 | struct orig_node *orig_neigh_node, | ||
46 | const struct batman_ogm_packet *batman_ogm_packet); | ||
47 | int window_protected(struct bat_priv *bat_priv, int32_t seq_num_diff, | ||
48 | unsigned long *last_reset); | ||
46 | 49 | ||
47 | #endif /* _NET_BATMAN_ADV_ROUTING_H_ */ | 50 | #endif /* _NET_BATMAN_ADV_ROUTING_H_ */ |
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c index 57ae80936911..8a684eb738ad 100644 --- a/net/batman-adv/send.c +++ b/net/batman-adv/send.c | |||
@@ -26,33 +26,12 @@ | |||
26 | #include "soft-interface.h" | 26 | #include "soft-interface.h" |
27 | #include "hard-interface.h" | 27 | #include "hard-interface.h" |
28 | #include "vis.h" | 28 | #include "vis.h" |
29 | #include "aggregation.h" | ||
30 | #include "gateway_common.h" | 29 | #include "gateway_common.h" |
31 | #include "originator.h" | 30 | #include "originator.h" |
31 | #include "bat_ogm.h" | ||
32 | 32 | ||
33 | static void send_outstanding_bcast_packet(struct work_struct *work); | 33 | static void send_outstanding_bcast_packet(struct work_struct *work); |
34 | 34 | ||
35 | /* apply hop penalty for a normal link */ | ||
36 | static uint8_t hop_penalty(uint8_t tq, const struct bat_priv *bat_priv) | ||
37 | { | ||
38 | int hop_penalty = atomic_read(&bat_priv->hop_penalty); | ||
39 | return (tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE); | ||
40 | } | ||
41 | |||
42 | /* when do we schedule our own packet to be sent */ | ||
43 | static unsigned long own_send_time(const struct bat_priv *bat_priv) | ||
44 | { | ||
45 | return jiffies + msecs_to_jiffies( | ||
46 | atomic_read(&bat_priv->orig_interval) - | ||
47 | JITTER + (random32() % 2*JITTER)); | ||
48 | } | ||
49 | |||
50 | /* when do we schedule a forwarded packet to be sent */ | ||
51 | static unsigned long forward_send_time(void) | ||
52 | { | ||
53 | return jiffies + msecs_to_jiffies(random32() % (JITTER/2)); | ||
54 | } | ||
55 | |||
56 | /* send out an already prepared packet to the given address via the | 35 | /* send out an already prepared packet to the given address via the |
57 | * specified batman interface */ | 36 | * specified batman interface */ |
58 | int send_skb_packet(struct sk_buff *skb, struct hard_iface *hard_iface, | 37 | int send_skb_packet(struct sk_buff *skb, struct hard_iface *hard_iface, |
@@ -99,141 +78,17 @@ send_skb_err: | |||
99 | return NET_XMIT_DROP; | 78 | return NET_XMIT_DROP; |
100 | } | 79 | } |
101 | 80 | ||
102 | /* Send a packet to a given interface */ | ||
103 | static void send_packet_to_if(struct forw_packet *forw_packet, | ||
104 | struct hard_iface *hard_iface) | ||
105 | { | ||
106 | struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); | ||
107 | char *fwd_str; | ||
108 | uint8_t packet_num; | ||
109 | int16_t buff_pos; | ||
110 | struct batman_packet *batman_packet; | ||
111 | struct sk_buff *skb; | ||
112 | |||
113 | if (hard_iface->if_status != IF_ACTIVE) | ||
114 | return; | ||
115 | |||
116 | packet_num = 0; | ||
117 | buff_pos = 0; | ||
118 | batman_packet = (struct batman_packet *)forw_packet->skb->data; | ||
119 | |||
120 | /* adjust all flags and log packets */ | ||
121 | while (aggregated_packet(buff_pos, | ||
122 | forw_packet->packet_len, | ||
123 | batman_packet->tt_num_changes)) { | ||
124 | |||
125 | /* we might have aggregated direct link packets with an | ||
126 | * ordinary base packet */ | ||
127 | if ((forw_packet->direct_link_flags & (1 << packet_num)) && | ||
128 | (forw_packet->if_incoming == hard_iface)) | ||
129 | batman_packet->flags |= DIRECTLINK; | ||
130 | else | ||
131 | batman_packet->flags &= ~DIRECTLINK; | ||
132 | |||
133 | fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ? | ||
134 | "Sending own" : | ||
135 | "Forwarding")); | ||
136 | bat_dbg(DBG_BATMAN, bat_priv, | ||
137 | "%s %spacket (originator %pM, seqno %d, TQ %d, TTL %d," | ||
138 | " IDF %s, ttvn %d) on interface %s [%pM]\n", | ||
139 | fwd_str, (packet_num > 0 ? "aggregated " : ""), | ||
140 | batman_packet->orig, ntohl(batman_packet->seqno), | ||
141 | batman_packet->tq, batman_packet->ttl, | ||
142 | (batman_packet->flags & DIRECTLINK ? | ||
143 | "on" : "off"), | ||
144 | batman_packet->ttvn, hard_iface->net_dev->name, | ||
145 | hard_iface->net_dev->dev_addr); | ||
146 | |||
147 | buff_pos += sizeof(*batman_packet) + | ||
148 | tt_len(batman_packet->tt_num_changes); | ||
149 | packet_num++; | ||
150 | batman_packet = (struct batman_packet *) | ||
151 | (forw_packet->skb->data + buff_pos); | ||
152 | } | ||
153 | |||
154 | /* create clone because function is called more than once */ | ||
155 | skb = skb_clone(forw_packet->skb, GFP_ATOMIC); | ||
156 | if (skb) | ||
157 | send_skb_packet(skb, hard_iface, broadcast_addr); | ||
158 | } | ||
159 | |||
160 | /* send a batman packet */ | ||
161 | static void send_packet(struct forw_packet *forw_packet) | ||
162 | { | ||
163 | struct hard_iface *hard_iface; | ||
164 | struct net_device *soft_iface; | ||
165 | struct bat_priv *bat_priv; | ||
166 | struct hard_iface *primary_if = NULL; | ||
167 | struct batman_packet *batman_packet = | ||
168 | (struct batman_packet *)(forw_packet->skb->data); | ||
169 | int directlink = (batman_packet->flags & DIRECTLINK ? 1 : 0); | ||
170 | |||
171 | if (!forw_packet->if_incoming) { | ||
172 | pr_err("Error - can't forward packet: incoming iface not " | ||
173 | "specified\n"); | ||
174 | goto out; | ||
175 | } | ||
176 | |||
177 | soft_iface = forw_packet->if_incoming->soft_iface; | ||
178 | bat_priv = netdev_priv(soft_iface); | ||
179 | |||
180 | if (forw_packet->if_incoming->if_status != IF_ACTIVE) | ||
181 | goto out; | ||
182 | |||
183 | primary_if = primary_if_get_selected(bat_priv); | ||
184 | if (!primary_if) | ||
185 | goto out; | ||
186 | |||
187 | /* multihomed peer assumed */ | ||
188 | /* non-primary OGMs are only broadcasted on their interface */ | ||
189 | if ((directlink && (batman_packet->ttl == 1)) || | ||
190 | (forw_packet->own && (forw_packet->if_incoming != primary_if))) { | ||
191 | |||
192 | /* FIXME: what about aggregated packets ? */ | ||
193 | bat_dbg(DBG_BATMAN, bat_priv, | ||
194 | "%s packet (originator %pM, seqno %d, TTL %d) " | ||
195 | "on interface %s [%pM]\n", | ||
196 | (forw_packet->own ? "Sending own" : "Forwarding"), | ||
197 | batman_packet->orig, ntohl(batman_packet->seqno), | ||
198 | batman_packet->ttl, | ||
199 | forw_packet->if_incoming->net_dev->name, | ||
200 | forw_packet->if_incoming->net_dev->dev_addr); | ||
201 | |||
202 | /* skb is only used once and than forw_packet is free'd */ | ||
203 | send_skb_packet(forw_packet->skb, forw_packet->if_incoming, | ||
204 | broadcast_addr); | ||
205 | forw_packet->skb = NULL; | ||
206 | |||
207 | goto out; | ||
208 | } | ||
209 | |||
210 | /* broadcast on every interface */ | ||
211 | rcu_read_lock(); | ||
212 | list_for_each_entry_rcu(hard_iface, &hardif_list, list) { | ||
213 | if (hard_iface->soft_iface != soft_iface) | ||
214 | continue; | ||
215 | |||
216 | send_packet_to_if(forw_packet, hard_iface); | ||
217 | } | ||
218 | rcu_read_unlock(); | ||
219 | |||
220 | out: | ||
221 | if (primary_if) | ||
222 | hardif_free_ref(primary_if); | ||
223 | } | ||
224 | |||
225 | static void realloc_packet_buffer(struct hard_iface *hard_iface, | 81 | static void realloc_packet_buffer(struct hard_iface *hard_iface, |
226 | int new_len) | 82 | int new_len) |
227 | { | 83 | { |
228 | unsigned char *new_buff; | 84 | unsigned char *new_buff; |
229 | struct batman_packet *batman_packet; | ||
230 | 85 | ||
231 | new_buff = kmalloc(new_len, GFP_ATOMIC); | 86 | new_buff = kmalloc(new_len, GFP_ATOMIC); |
232 | 87 | ||
233 | /* keep old buffer if kmalloc should fail */ | 88 | /* keep old buffer if kmalloc should fail */ |
234 | if (new_buff) { | 89 | if (new_buff) { |
235 | memcpy(new_buff, hard_iface->packet_buff, | 90 | memcpy(new_buff, hard_iface->packet_buff, |
236 | sizeof(*batman_packet)); | 91 | BATMAN_OGM_LEN); |
237 | 92 | ||
238 | kfree(hard_iface->packet_buff); | 93 | kfree(hard_iface->packet_buff); |
239 | hard_iface->packet_buff = new_buff; | 94 | hard_iface->packet_buff = new_buff; |
@@ -242,60 +97,48 @@ static void realloc_packet_buffer(struct hard_iface *hard_iface, | |||
242 | } | 97 | } |
243 | 98 | ||
244 | /* when calling this function (hard_iface == primary_if) has to be true */ | 99 | /* when calling this function (hard_iface == primary_if) has to be true */ |
245 | static void prepare_packet_buffer(struct bat_priv *bat_priv, | 100 | static int prepare_packet_buffer(struct bat_priv *bat_priv, |
246 | struct hard_iface *hard_iface) | 101 | struct hard_iface *hard_iface) |
247 | { | 102 | { |
248 | int new_len; | 103 | int new_len; |
249 | struct batman_packet *batman_packet; | ||
250 | 104 | ||
251 | new_len = BAT_PACKET_LEN + | 105 | new_len = BATMAN_OGM_LEN + |
252 | tt_len((uint8_t)atomic_read(&bat_priv->tt_local_changes)); | 106 | tt_len((uint8_t)atomic_read(&bat_priv->tt_local_changes)); |
253 | 107 | ||
254 | /* if we have too many changes for one packet don't send any | 108 | /* if we have too many changes for one packet don't send any |
255 | * and wait for the tt table request which will be fragmented */ | 109 | * and wait for the tt table request which will be fragmented */ |
256 | if (new_len > hard_iface->soft_iface->mtu) | 110 | if (new_len > hard_iface->soft_iface->mtu) |
257 | new_len = BAT_PACKET_LEN; | 111 | new_len = BATMAN_OGM_LEN; |
258 | 112 | ||
259 | realloc_packet_buffer(hard_iface, new_len); | 113 | realloc_packet_buffer(hard_iface, new_len); |
260 | batman_packet = (struct batman_packet *)hard_iface->packet_buff; | ||
261 | 114 | ||
262 | atomic_set(&bat_priv->tt_crc, tt_local_crc(bat_priv)); | 115 | atomic_set(&bat_priv->tt_crc, tt_local_crc(bat_priv)); |
263 | 116 | ||
264 | /* reset the sending counter */ | 117 | /* reset the sending counter */ |
265 | atomic_set(&bat_priv->tt_ogm_append_cnt, TT_OGM_APPEND_MAX); | 118 | atomic_set(&bat_priv->tt_ogm_append_cnt, TT_OGM_APPEND_MAX); |
266 | 119 | ||
267 | batman_packet->tt_num_changes = tt_changes_fill_buffer(bat_priv, | 120 | return tt_changes_fill_buffer(bat_priv, |
268 | hard_iface->packet_buff + BAT_PACKET_LEN, | 121 | hard_iface->packet_buff + BATMAN_OGM_LEN, |
269 | hard_iface->packet_len - BAT_PACKET_LEN); | 122 | hard_iface->packet_len - BATMAN_OGM_LEN); |
270 | |||
271 | } | 123 | } |
272 | 124 | ||
273 | static void reset_packet_buffer(struct bat_priv *bat_priv, | 125 | static int reset_packet_buffer(struct bat_priv *bat_priv, |
274 | struct hard_iface *hard_iface) | 126 | struct hard_iface *hard_iface) |
275 | { | 127 | { |
276 | struct batman_packet *batman_packet; | 128 | realloc_packet_buffer(hard_iface, BATMAN_OGM_LEN); |
277 | 129 | return 0; | |
278 | realloc_packet_buffer(hard_iface, BAT_PACKET_LEN); | ||
279 | |||
280 | batman_packet = (struct batman_packet *)hard_iface->packet_buff; | ||
281 | batman_packet->tt_num_changes = 0; | ||
282 | } | 130 | } |
283 | 131 | ||
284 | void schedule_own_packet(struct hard_iface *hard_iface) | 132 | void schedule_bat_ogm(struct hard_iface *hard_iface) |
285 | { | 133 | { |
286 | struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); | 134 | struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
287 | struct hard_iface *primary_if; | 135 | struct hard_iface *primary_if; |
288 | unsigned long send_time; | 136 | int tt_num_changes = -1; |
289 | struct batman_packet *batman_packet; | ||
290 | int vis_server; | ||
291 | 137 | ||
292 | if ((hard_iface->if_status == IF_NOT_IN_USE) || | 138 | if ((hard_iface->if_status == IF_NOT_IN_USE) || |
293 | (hard_iface->if_status == IF_TO_BE_REMOVED)) | 139 | (hard_iface->if_status == IF_TO_BE_REMOVED)) |
294 | return; | 140 | return; |
295 | 141 | ||
296 | vis_server = atomic_read(&bat_priv->vis_mode); | ||
297 | primary_if = primary_if_get_selected(bat_priv); | ||
298 | |||
299 | /** | 142 | /** |
300 | * the interface gets activated here to avoid race conditions between | 143 | * the interface gets activated here to avoid race conditions between |
301 | * the moment of activating the interface in | 144 | * the moment of activating the interface in |
@@ -306,124 +149,26 @@ void schedule_own_packet(struct hard_iface *hard_iface) | |||
306 | if (hard_iface->if_status == IF_TO_BE_ACTIVATED) | 149 | if (hard_iface->if_status == IF_TO_BE_ACTIVATED) |
307 | hard_iface->if_status = IF_ACTIVE; | 150 | hard_iface->if_status = IF_ACTIVE; |
308 | 151 | ||
152 | primary_if = primary_if_get_selected(bat_priv); | ||
153 | |||
309 | if (hard_iface == primary_if) { | 154 | if (hard_iface == primary_if) { |
310 | /* if at least one change happened */ | 155 | /* if at least one change happened */ |
311 | if (atomic_read(&bat_priv->tt_local_changes) > 0) { | 156 | if (atomic_read(&bat_priv->tt_local_changes) > 0) { |
312 | tt_commit_changes(bat_priv); | 157 | tt_commit_changes(bat_priv); |
313 | prepare_packet_buffer(bat_priv, hard_iface); | 158 | tt_num_changes = prepare_packet_buffer(bat_priv, |
159 | hard_iface); | ||
314 | } | 160 | } |
315 | 161 | ||
316 | /* if the changes have been sent often enough */ | 162 | /* if the changes have been sent often enough */ |
317 | if (!atomic_dec_not_zero(&bat_priv->tt_ogm_append_cnt)) | 163 | if (!atomic_dec_not_zero(&bat_priv->tt_ogm_append_cnt)) |
318 | reset_packet_buffer(bat_priv, hard_iface); | 164 | tt_num_changes = reset_packet_buffer(bat_priv, |
165 | hard_iface); | ||
319 | } | 166 | } |
320 | 167 | ||
321 | /** | ||
322 | * NOTE: packet_buff might just have been re-allocated in | ||
323 | * prepare_packet_buffer() or in reset_packet_buffer() | ||
324 | */ | ||
325 | batman_packet = (struct batman_packet *)hard_iface->packet_buff; | ||
326 | |||
327 | /* change sequence number to network order */ | ||
328 | batman_packet->seqno = | ||
329 | htonl((uint32_t)atomic_read(&hard_iface->seqno)); | ||
330 | |||
331 | batman_packet->ttvn = atomic_read(&bat_priv->ttvn); | ||
332 | batman_packet->tt_crc = htons((uint16_t)atomic_read(&bat_priv->tt_crc)); | ||
333 | |||
334 | if (vis_server == VIS_TYPE_SERVER_SYNC) | ||
335 | batman_packet->flags |= VIS_SERVER; | ||
336 | else | ||
337 | batman_packet->flags &= ~VIS_SERVER; | ||
338 | |||
339 | if ((hard_iface == primary_if) && | ||
340 | (atomic_read(&bat_priv->gw_mode) == GW_MODE_SERVER)) | ||
341 | batman_packet->gw_flags = | ||
342 | (uint8_t)atomic_read(&bat_priv->gw_bandwidth); | ||
343 | else | ||
344 | batman_packet->gw_flags = NO_FLAGS; | ||
345 | |||
346 | atomic_inc(&hard_iface->seqno); | ||
347 | |||
348 | slide_own_bcast_window(hard_iface); | ||
349 | send_time = own_send_time(bat_priv); | ||
350 | add_bat_packet_to_list(bat_priv, | ||
351 | hard_iface->packet_buff, | ||
352 | hard_iface->packet_len, | ||
353 | hard_iface, 1, send_time); | ||
354 | |||
355 | if (primary_if) | 168 | if (primary_if) |
356 | hardif_free_ref(primary_if); | 169 | hardif_free_ref(primary_if); |
357 | } | ||
358 | |||
359 | void schedule_forward_packet(struct orig_node *orig_node, | ||
360 | const struct ethhdr *ethhdr, | ||
361 | struct batman_packet *batman_packet, | ||
362 | int directlink, | ||
363 | struct hard_iface *if_incoming) | ||
364 | { | ||
365 | struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); | ||
366 | struct neigh_node *router; | ||
367 | uint8_t in_tq, in_ttl, tq_avg = 0; | ||
368 | unsigned long send_time; | ||
369 | uint8_t tt_num_changes; | ||
370 | |||
371 | if (batman_packet->ttl <= 1) { | ||
372 | bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n"); | ||
373 | return; | ||
374 | } | ||
375 | |||
376 | router = orig_node_get_router(orig_node); | ||
377 | |||
378 | in_tq = batman_packet->tq; | ||
379 | in_ttl = batman_packet->ttl; | ||
380 | tt_num_changes = batman_packet->tt_num_changes; | ||
381 | |||
382 | batman_packet->ttl--; | ||
383 | memcpy(batman_packet->prev_sender, ethhdr->h_source, ETH_ALEN); | ||
384 | |||
385 | /* rebroadcast tq of our best ranking neighbor to ensure the rebroadcast | ||
386 | * of our best tq value */ | ||
387 | if (router && router->tq_avg != 0) { | ||
388 | |||
389 | /* rebroadcast ogm of best ranking neighbor as is */ | ||
390 | if (!compare_eth(router->addr, ethhdr->h_source)) { | ||
391 | batman_packet->tq = router->tq_avg; | ||
392 | |||
393 | if (router->last_ttl) | ||
394 | batman_packet->ttl = router->last_ttl - 1; | ||
395 | } | ||
396 | |||
397 | tq_avg = router->tq_avg; | ||
398 | } | ||
399 | |||
400 | if (router) | ||
401 | neigh_node_free_ref(router); | ||
402 | |||
403 | /* apply hop penalty */ | ||
404 | batman_packet->tq = hop_penalty(batman_packet->tq, bat_priv); | ||
405 | |||
406 | bat_dbg(DBG_BATMAN, bat_priv, | ||
407 | "Forwarding packet: tq_orig: %i, tq_avg: %i, " | ||
408 | "tq_forw: %i, ttl_orig: %i, ttl_forw: %i\n", | ||
409 | in_tq, tq_avg, batman_packet->tq, in_ttl - 1, | ||
410 | batman_packet->ttl); | ||
411 | |||
412 | batman_packet->seqno = htonl(batman_packet->seqno); | ||
413 | batman_packet->tt_crc = htons(batman_packet->tt_crc); | ||
414 | |||
415 | /* switch of primaries first hop flag when forwarding */ | ||
416 | batman_packet->flags &= ~PRIMARIES_FIRST_HOP; | ||
417 | if (directlink) | ||
418 | batman_packet->flags |= DIRECTLINK; | ||
419 | else | ||
420 | batman_packet->flags &= ~DIRECTLINK; | ||
421 | 170 | ||
422 | send_time = forward_send_time(); | 171 | bat_ogm_schedule(hard_iface, tt_num_changes); |
423 | add_bat_packet_to_list(bat_priv, | ||
424 | (unsigned char *)batman_packet, | ||
425 | sizeof(*batman_packet) + tt_len(tt_num_changes), | ||
426 | if_incoming, 0, send_time); | ||
427 | } | 172 | } |
428 | 173 | ||
429 | static void forw_packet_free(struct forw_packet *forw_packet) | 174 | static void forw_packet_free(struct forw_packet *forw_packet) |
@@ -557,7 +302,7 @@ out: | |||
557 | atomic_inc(&bat_priv->bcast_queue_left); | 302 | atomic_inc(&bat_priv->bcast_queue_left); |
558 | } | 303 | } |
559 | 304 | ||
560 | void send_outstanding_bat_packet(struct work_struct *work) | 305 | void send_outstanding_bat_ogm_packet(struct work_struct *work) |
561 | { | 306 | { |
562 | struct delayed_work *delayed_work = | 307 | struct delayed_work *delayed_work = |
563 | container_of(work, struct delayed_work, work); | 308 | container_of(work, struct delayed_work, work); |
@@ -573,7 +318,7 @@ void send_outstanding_bat_packet(struct work_struct *work) | |||
573 | if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING) | 318 | if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING) |
574 | goto out; | 319 | goto out; |
575 | 320 | ||
576 | send_packet(forw_packet); | 321 | bat_ogm_emit(forw_packet); |
577 | 322 | ||
578 | /** | 323 | /** |
579 | * we have to have at least one packet in the queue | 324 | * we have to have at least one packet in the queue |
@@ -581,7 +326,7 @@ void send_outstanding_bat_packet(struct work_struct *work) | |||
581 | * shutting down | 326 | * shutting down |
582 | */ | 327 | */ |
583 | if (forw_packet->own) | 328 | if (forw_packet->own) |
584 | schedule_own_packet(forw_packet->if_incoming); | 329 | schedule_bat_ogm(forw_packet->if_incoming); |
585 | 330 | ||
586 | out: | 331 | out: |
587 | /* don't count own packet */ | 332 | /* don't count own packet */ |
diff --git a/net/batman-adv/send.h b/net/batman-adv/send.h index 1f2d1e877663..c8ca3ef7385b 100644 --- a/net/batman-adv/send.h +++ b/net/batman-adv/send.h | |||
@@ -24,15 +24,10 @@ | |||
24 | 24 | ||
25 | int send_skb_packet(struct sk_buff *skb, struct hard_iface *hard_iface, | 25 | int send_skb_packet(struct sk_buff *skb, struct hard_iface *hard_iface, |
26 | const uint8_t *dst_addr); | 26 | const uint8_t *dst_addr); |
27 | void schedule_own_packet(struct hard_iface *hard_iface); | 27 | void schedule_bat_ogm(struct hard_iface *hard_iface); |
28 | void schedule_forward_packet(struct orig_node *orig_node, | ||
29 | const struct ethhdr *ethhdr, | ||
30 | struct batman_packet *batman_packet, | ||
31 | int directlink, | ||
32 | struct hard_iface *if_outgoing); | ||
33 | int add_bcast_packet_to_list(struct bat_priv *bat_priv, | 28 | int add_bcast_packet_to_list(struct bat_priv *bat_priv, |
34 | const struct sk_buff *skb, unsigned long delay); | 29 | const struct sk_buff *skb, unsigned long delay); |
35 | void send_outstanding_bat_packet(struct work_struct *work); | 30 | void send_outstanding_bat_ogm_packet(struct work_struct *work); |
36 | void purge_outstanding_packets(struct bat_priv *bat_priv, | 31 | void purge_outstanding_packets(struct bat_priv *bat_priv, |
37 | const struct hard_iface *hard_iface); | 32 | const struct hard_iface *hard_iface); |
38 | 33 | ||
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c index 402fd96239d8..aceeabc2ca86 100644 --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c | |||
@@ -445,30 +445,31 @@ static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev, | |||
445 | { | 445 | { |
446 | struct bat_priv *bat_priv = netdev_priv(dev); | 446 | struct bat_priv *bat_priv = netdev_priv(dev); |
447 | struct ethhdr *ethhdr = (struct ethhdr *)skb->data; | 447 | struct ethhdr *ethhdr = (struct ethhdr *)skb->data; |
448 | struct batman_packet *batman_packet; | 448 | struct batman_ogm_packet *batman_ogm_packet; |
449 | struct softif_neigh *softif_neigh = NULL; | 449 | struct softif_neigh *softif_neigh = NULL; |
450 | struct hard_iface *primary_if = NULL; | 450 | struct hard_iface *primary_if = NULL; |
451 | struct softif_neigh *curr_softif_neigh = NULL; | 451 | struct softif_neigh *curr_softif_neigh = NULL; |
452 | 452 | ||
453 | if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) | 453 | if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) |
454 | batman_packet = (struct batman_packet *) | 454 | batman_ogm_packet = (struct batman_ogm_packet *) |
455 | (skb->data + ETH_HLEN + VLAN_HLEN); | 455 | (skb->data + ETH_HLEN + VLAN_HLEN); |
456 | else | 456 | else |
457 | batman_packet = (struct batman_packet *)(skb->data + ETH_HLEN); | 457 | batman_ogm_packet = (struct batman_ogm_packet *) |
458 | (skb->data + ETH_HLEN); | ||
458 | 459 | ||
459 | if (batman_packet->version != COMPAT_VERSION) | 460 | if (batman_ogm_packet->version != COMPAT_VERSION) |
460 | goto out; | 461 | goto out; |
461 | 462 | ||
462 | if (batman_packet->packet_type != BAT_PACKET) | 463 | if (batman_ogm_packet->packet_type != BAT_OGM) |
463 | goto out; | 464 | goto out; |
464 | 465 | ||
465 | if (!(batman_packet->flags & PRIMARIES_FIRST_HOP)) | 466 | if (!(batman_ogm_packet->flags & PRIMARIES_FIRST_HOP)) |
466 | goto out; | 467 | goto out; |
467 | 468 | ||
468 | if (is_my_mac(batman_packet->orig)) | 469 | if (is_my_mac(batman_ogm_packet->orig)) |
469 | goto out; | 470 | goto out; |
470 | 471 | ||
471 | softif_neigh = softif_neigh_get(bat_priv, batman_packet->orig, vid); | 472 | softif_neigh = softif_neigh_get(bat_priv, batman_ogm_packet->orig, vid); |
472 | if (!softif_neigh) | 473 | if (!softif_neigh) |
473 | goto out; | 474 | goto out; |
474 | 475 | ||
@@ -800,10 +801,8 @@ struct net_device *softif_create(const char *name) | |||
800 | 801 | ||
801 | soft_iface = alloc_netdev(sizeof(*bat_priv), name, interface_setup); | 802 | soft_iface = alloc_netdev(sizeof(*bat_priv), name, interface_setup); |
802 | 803 | ||
803 | if (!soft_iface) { | 804 | if (!soft_iface) |
804 | pr_err("Unable to allocate the batman interface: %s\n", name); | ||
805 | goto out; | 805 | goto out; |
806 | } | ||
807 | 806 | ||
808 | ret = register_netdevice(soft_iface); | 807 | ret = register_netdevice(soft_iface); |
809 | if (ret < 0) { | 808 | if (ret < 0) { |
diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c index fb9b19fc638d..f81a6b668b0c 100644 --- a/net/batman-adv/vis.c +++ b/net/batman-adv/vis.c | |||
@@ -887,10 +887,8 @@ int vis_init(struct bat_priv *bat_priv) | |||
887 | } | 887 | } |
888 | 888 | ||
889 | bat_priv->my_vis_info = kmalloc(MAX_VIS_PACKET_SIZE, GFP_ATOMIC); | 889 | bat_priv->my_vis_info = kmalloc(MAX_VIS_PACKET_SIZE, GFP_ATOMIC); |
890 | if (!bat_priv->my_vis_info) { | 890 | if (!bat_priv->my_vis_info) |
891 | pr_err("Can't initialize vis packet\n"); | ||
892 | goto err; | 891 | goto err; |
893 | } | ||
894 | 892 | ||
895 | bat_priv->my_vis_info->skb_packet = dev_alloc_skb(sizeof(*packet) + | 893 | bat_priv->my_vis_info->skb_packet = dev_alloc_skb(sizeof(*packet) + |
896 | MAX_VIS_PACKET_SIZE + | 894 | MAX_VIS_PACKET_SIZE + |