diff options
Diffstat (limited to 'net/batman-adv')
-rw-r--r-- | net/batman-adv/Kconfig | 14 | ||||
-rw-r--r-- | net/batman-adv/Makefile | 3 | ||||
-rw-r--r-- | net/batman-adv/bat_iv_ogm.c | 5 | ||||
-rw-r--r-- | net/batman-adv/bridge_loop_avoidance.c | 2 | ||||
-rw-r--r-- | net/batman-adv/debugfs.c | 18 | ||||
-rw-r--r-- | net/batman-adv/distributed-arp-table.c | 22 | ||||
-rw-r--r-- | net/batman-adv/gateway_client.c | 2 | ||||
-rw-r--r-- | net/batman-adv/hard-interface.c | 66 | ||||
-rw-r--r-- | net/batman-adv/hard-interface.h | 13 | ||||
-rw-r--r-- | net/batman-adv/main.c | 16 | ||||
-rw-r--r-- | net/batman-adv/main.h | 15 | ||||
-rw-r--r-- | net/batman-adv/network-coding.c | 1822 | ||||
-rw-r--r-- | net/batman-adv/network-coding.h | 123 | ||||
-rw-r--r-- | net/batman-adv/originator.c | 10 | ||||
-rw-r--r-- | net/batman-adv/packet.h | 33 | ||||
-rw-r--r-- | net/batman-adv/routing.c | 50 | ||||
-rw-r--r-- | net/batman-adv/send.c | 5 | ||||
-rw-r--r-- | net/batman-adv/soft-interface.c | 288 | ||||
-rw-r--r-- | net/batman-adv/soft-interface.h | 3 | ||||
-rw-r--r-- | net/batman-adv/sysfs.c | 22 | ||||
-rw-r--r-- | net/batman-adv/translation-table.c | 29 | ||||
-rw-r--r-- | net/batman-adv/types.h | 136 | ||||
-rw-r--r-- | net/batman-adv/unicast.c | 6 | ||||
-rw-r--r-- | net/batman-adv/vis.c | 4 |
24 files changed, 2528 insertions, 179 deletions
diff --git a/net/batman-adv/Kconfig b/net/batman-adv/Kconfig index 8d8afb134b3a..fa780b76630e 100644 --- a/net/batman-adv/Kconfig +++ b/net/batman-adv/Kconfig | |||
@@ -36,6 +36,20 @@ config BATMAN_ADV_DAT | |||
36 | mesh networks. If you think that your network does not need | 36 | mesh networks. If you think that your network does not need |
37 | this option you can safely remove it and save some space. | 37 | this option you can safely remove it and save some space. |
38 | 38 | ||
39 | config BATMAN_ADV_NC | ||
40 | bool "Network Coding" | ||
41 | depends on BATMAN_ADV | ||
42 | default n | ||
43 | help | ||
44 | This option enables network coding, a mechanism that aims to | ||
45 | increase the overall network throughput by fusing multiple | ||
46 | packets in one transmission. | ||
47 | Note that interfaces controlled by batman-adv must be manually | ||
48 | configured to have promiscuous mode enabled in order to make | ||
49 | network coding work. | ||
50 | If you think that your network does not need this feature you | ||
51 | can safely disable it and save some space. | ||
52 | |||
39 | config BATMAN_ADV_DEBUG | 53 | config BATMAN_ADV_DEBUG |
40 | bool "B.A.T.M.A.N. debugging" | 54 | bool "B.A.T.M.A.N. debugging" |
41 | depends on BATMAN_ADV | 55 | depends on BATMAN_ADV |
diff --git a/net/batman-adv/Makefile b/net/batman-adv/Makefile index e45e3b4e32e3..acbac2a9c62f 100644 --- a/net/batman-adv/Makefile +++ b/net/batman-adv/Makefile | |||
@@ -1,5 +1,5 @@ | |||
1 | # | 1 | # |
2 | # Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: | 2 | # Copyright (C) 2007-2013 B.A.T.M.A.N. contributors: |
3 | # | 3 | # |
4 | # Marek Lindner, Simon Wunderlich | 4 | # Marek Lindner, Simon Wunderlich |
5 | # | 5 | # |
@@ -30,6 +30,7 @@ batman-adv-y += hard-interface.o | |||
30 | batman-adv-y += hash.o | 30 | batman-adv-y += hash.o |
31 | batman-adv-y += icmp_socket.o | 31 | batman-adv-y += icmp_socket.o |
32 | batman-adv-y += main.o | 32 | batman-adv-y += main.o |
33 | batman-adv-$(CONFIG_BATMAN_ADV_NC) += network-coding.o | ||
33 | batman-adv-y += originator.o | 34 | batman-adv-y += originator.o |
34 | batman-adv-y += ring_buffer.o | 35 | batman-adv-y += ring_buffer.o |
35 | batman-adv-y += routing.o | 36 | batman-adv-y += routing.o |
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index a5bb0a769eb9..071f288b77a8 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "hard-interface.h" | 27 | #include "hard-interface.h" |
28 | #include "send.h" | 28 | #include "send.h" |
29 | #include "bat_algo.h" | 29 | #include "bat_algo.h" |
30 | #include "network-coding.h" | ||
30 | 31 | ||
31 | static struct batadv_neigh_node * | 32 | static struct batadv_neigh_node * |
32 | batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface, | 33 | batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface, |
@@ -1185,6 +1186,10 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr, | |||
1185 | if (!orig_neigh_node) | 1186 | if (!orig_neigh_node) |
1186 | goto out; | 1187 | goto out; |
1187 | 1188 | ||
1189 | /* Update nc_nodes of the originator */ | ||
1190 | batadv_nc_update_nc_node(bat_priv, orig_node, orig_neigh_node, | ||
1191 | batadv_ogm_packet, is_single_hop_neigh); | ||
1192 | |||
1188 | orig_neigh_router = batadv_orig_node_get_router(orig_neigh_node); | 1193 | orig_neigh_router = batadv_orig_node_get_router(orig_neigh_node); |
1189 | 1194 | ||
1190 | /* drop packet if sender is not a direct neighbor and if we | 1195 | /* drop packet if sender is not a direct neighbor and if we |
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 6a4f728680ae..379061c72549 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c | |||
@@ -341,7 +341,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, | |||
341 | } | 341 | } |
342 | 342 | ||
343 | if (vid != -1) | 343 | if (vid != -1) |
344 | skb = vlan_insert_tag(skb, vid); | 344 | skb = vlan_insert_tag(skb, htons(ETH_P_8021Q), vid); |
345 | 345 | ||
346 | skb_reset_mac_header(skb); | 346 | skb_reset_mac_header(skb); |
347 | skb->protocol = eth_type_trans(skb, soft_iface); | 347 | skb->protocol = eth_type_trans(skb, soft_iface); |
diff --git a/net/batman-adv/debugfs.c b/net/batman-adv/debugfs.c index 6ae86516db4d..f186a55b23c3 100644 --- a/net/batman-adv/debugfs.c +++ b/net/batman-adv/debugfs.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "icmp_socket.h" | 32 | #include "icmp_socket.h" |
33 | #include "bridge_loop_avoidance.h" | 33 | #include "bridge_loop_avoidance.h" |
34 | #include "distributed-arp-table.h" | 34 | #include "distributed-arp-table.h" |
35 | #include "network-coding.h" | ||
35 | 36 | ||
36 | static struct dentry *batadv_debugfs; | 37 | static struct dentry *batadv_debugfs; |
37 | 38 | ||
@@ -310,6 +311,14 @@ struct batadv_debuginfo { | |||
310 | const struct file_operations fops; | 311 | const struct file_operations fops; |
311 | }; | 312 | }; |
312 | 313 | ||
314 | #ifdef CONFIG_BATMAN_ADV_NC | ||
315 | static int batadv_nc_nodes_open(struct inode *inode, struct file *file) | ||
316 | { | ||
317 | struct net_device *net_dev = (struct net_device *)inode->i_private; | ||
318 | return single_open(file, batadv_nc_nodes_seq_print_text, net_dev); | ||
319 | } | ||
320 | #endif | ||
321 | |||
313 | #define BATADV_DEBUGINFO(_name, _mode, _open) \ | 322 | #define BATADV_DEBUGINFO(_name, _mode, _open) \ |
314 | struct batadv_debuginfo batadv_debuginfo_##_name = { \ | 323 | struct batadv_debuginfo batadv_debuginfo_##_name = { \ |
315 | .attr = { .name = __stringify(_name), \ | 324 | .attr = { .name = __stringify(_name), \ |
@@ -348,6 +357,9 @@ static BATADV_DEBUGINFO(dat_cache, S_IRUGO, batadv_dat_cache_open); | |||
348 | static BATADV_DEBUGINFO(transtable_local, S_IRUGO, | 357 | static BATADV_DEBUGINFO(transtable_local, S_IRUGO, |
349 | batadv_transtable_local_open); | 358 | batadv_transtable_local_open); |
350 | static BATADV_DEBUGINFO(vis_data, S_IRUGO, batadv_vis_data_open); | 359 | static BATADV_DEBUGINFO(vis_data, S_IRUGO, batadv_vis_data_open); |
360 | #ifdef CONFIG_BATMAN_ADV_NC | ||
361 | static BATADV_DEBUGINFO(nc_nodes, S_IRUGO, batadv_nc_nodes_open); | ||
362 | #endif | ||
351 | 363 | ||
352 | static struct batadv_debuginfo *batadv_mesh_debuginfos[] = { | 364 | static struct batadv_debuginfo *batadv_mesh_debuginfos[] = { |
353 | &batadv_debuginfo_originators, | 365 | &batadv_debuginfo_originators, |
@@ -362,6 +374,9 @@ static struct batadv_debuginfo *batadv_mesh_debuginfos[] = { | |||
362 | #endif | 374 | #endif |
363 | &batadv_debuginfo_transtable_local, | 375 | &batadv_debuginfo_transtable_local, |
364 | &batadv_debuginfo_vis_data, | 376 | &batadv_debuginfo_vis_data, |
377 | #ifdef CONFIG_BATMAN_ADV_NC | ||
378 | &batadv_debuginfo_nc_nodes, | ||
379 | #endif | ||
365 | NULL, | 380 | NULL, |
366 | }; | 381 | }; |
367 | 382 | ||
@@ -431,6 +446,9 @@ int batadv_debugfs_add_meshif(struct net_device *dev) | |||
431 | } | 446 | } |
432 | } | 447 | } |
433 | 448 | ||
449 | if (batadv_nc_init_debugfs(bat_priv) < 0) | ||
450 | goto rem_attr; | ||
451 | |||
434 | return 0; | 452 | return 0; |
435 | rem_attr: | 453 | rem_attr: |
436 | debugfs_remove_recursive(bat_priv->debug_dir); | 454 | debugfs_remove_recursive(bat_priv->debug_dir); |
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c index d54188a112ea..8e15d966d9b0 100644 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c | |||
@@ -816,7 +816,6 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, | |||
816 | bool ret = false; | 816 | bool ret = false; |
817 | struct batadv_dat_entry *dat_entry = NULL; | 817 | struct batadv_dat_entry *dat_entry = NULL; |
818 | struct sk_buff *skb_new; | 818 | struct sk_buff *skb_new; |
819 | struct batadv_hard_iface *primary_if = NULL; | ||
820 | 819 | ||
821 | if (!atomic_read(&bat_priv->distributed_arp_table)) | 820 | if (!atomic_read(&bat_priv->distributed_arp_table)) |
822 | goto out; | 821 | goto out; |
@@ -838,22 +837,18 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, | |||
838 | 837 | ||
839 | dat_entry = batadv_dat_entry_hash_find(bat_priv, ip_dst); | 838 | dat_entry = batadv_dat_entry_hash_find(bat_priv, ip_dst); |
840 | if (dat_entry) { | 839 | if (dat_entry) { |
841 | primary_if = batadv_primary_if_get_selected(bat_priv); | ||
842 | if (!primary_if) | ||
843 | goto out; | ||
844 | |||
845 | skb_new = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_src, | 840 | skb_new = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_src, |
846 | primary_if->soft_iface, ip_dst, hw_src, | 841 | bat_priv->soft_iface, ip_dst, hw_src, |
847 | dat_entry->mac_addr, hw_src); | 842 | dat_entry->mac_addr, hw_src); |
848 | if (!skb_new) | 843 | if (!skb_new) |
849 | goto out; | 844 | goto out; |
850 | 845 | ||
851 | skb_reset_mac_header(skb_new); | 846 | skb_reset_mac_header(skb_new); |
852 | skb_new->protocol = eth_type_trans(skb_new, | 847 | skb_new->protocol = eth_type_trans(skb_new, |
853 | primary_if->soft_iface); | 848 | bat_priv->soft_iface); |
854 | bat_priv->stats.rx_packets++; | 849 | bat_priv->stats.rx_packets++; |
855 | bat_priv->stats.rx_bytes += skb->len + ETH_HLEN; | 850 | bat_priv->stats.rx_bytes += skb->len + ETH_HLEN; |
856 | primary_if->soft_iface->last_rx = jiffies; | 851 | bat_priv->soft_iface->last_rx = jiffies; |
857 | 852 | ||
858 | netif_rx(skb_new); | 853 | netif_rx(skb_new); |
859 | batadv_dbg(BATADV_DBG_DAT, bat_priv, "ARP request replied locally\n"); | 854 | batadv_dbg(BATADV_DBG_DAT, bat_priv, "ARP request replied locally\n"); |
@@ -866,8 +861,6 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, | |||
866 | out: | 861 | out: |
867 | if (dat_entry) | 862 | if (dat_entry) |
868 | batadv_dat_entry_free_ref(dat_entry); | 863 | batadv_dat_entry_free_ref(dat_entry); |
869 | if (primary_if) | ||
870 | batadv_hardif_free_ref(primary_if); | ||
871 | return ret; | 864 | return ret; |
872 | } | 865 | } |
873 | 866 | ||
@@ -887,7 +880,6 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv, | |||
887 | __be32 ip_src, ip_dst; | 880 | __be32 ip_src, ip_dst; |
888 | uint8_t *hw_src; | 881 | uint8_t *hw_src; |
889 | struct sk_buff *skb_new; | 882 | struct sk_buff *skb_new; |
890 | struct batadv_hard_iface *primary_if = NULL; | ||
891 | struct batadv_dat_entry *dat_entry = NULL; | 883 | struct batadv_dat_entry *dat_entry = NULL; |
892 | bool ret = false; | 884 | bool ret = false; |
893 | int err; | 885 | int err; |
@@ -912,12 +904,8 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv, | |||
912 | if (!dat_entry) | 904 | if (!dat_entry) |
913 | goto out; | 905 | goto out; |
914 | 906 | ||
915 | primary_if = batadv_primary_if_get_selected(bat_priv); | ||
916 | if (!primary_if) | ||
917 | goto out; | ||
918 | |||
919 | skb_new = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_src, | 907 | skb_new = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_src, |
920 | primary_if->soft_iface, ip_dst, hw_src, | 908 | bat_priv->soft_iface, ip_dst, hw_src, |
921 | dat_entry->mac_addr, hw_src); | 909 | dat_entry->mac_addr, hw_src); |
922 | 910 | ||
923 | if (!skb_new) | 911 | if (!skb_new) |
@@ -941,8 +929,6 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv, | |||
941 | out: | 929 | out: |
942 | if (dat_entry) | 930 | if (dat_entry) |
943 | batadv_dat_entry_free_ref(dat_entry); | 931 | batadv_dat_entry_free_ref(dat_entry); |
944 | if (primary_if) | ||
945 | batadv_hardif_free_ref(primary_if); | ||
946 | if (ret) | 932 | if (ret) |
947 | kfree_skb(skb); | 933 | kfree_skb(skb); |
948 | return ret; | 934 | return ret; |
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 34f99a46ec1d..f105219f4a4b 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c | |||
@@ -500,7 +500,7 @@ int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset) | |||
500 | rcu_read_unlock(); | 500 | rcu_read_unlock(); |
501 | 501 | ||
502 | if (gw_count == 0) | 502 | if (gw_count == 0) |
503 | seq_printf(seq, "No gateways in range ...\n"); | 503 | seq_puts(seq, "No gateways in range ...\n"); |
504 | 504 | ||
505 | out: | 505 | out: |
506 | if (primary_if) | 506 | if (primary_if) |
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 368219e026a9..522243aff2f3 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c | |||
@@ -307,11 +307,35 @@ batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface) | |||
307 | batadv_update_min_mtu(hard_iface->soft_iface); | 307 | batadv_update_min_mtu(hard_iface->soft_iface); |
308 | } | 308 | } |
309 | 309 | ||
310 | /** | ||
311 | * batadv_master_del_slave - remove hard_iface from the current master interface | ||
312 | * @slave: the interface enslaved in another master | ||
313 | * @master: the master from which slave has to be removed | ||
314 | * | ||
315 | * Invoke ndo_del_slave on master passing slave as argument. In this way slave | ||
316 | * is free'd and master can correctly change its internal state. | ||
317 | * Return 0 on success, a negative value representing the error otherwise | ||
318 | */ | ||
319 | static int batadv_master_del_slave(struct batadv_hard_iface *slave, | ||
320 | struct net_device *master) | ||
321 | { | ||
322 | int ret; | ||
323 | |||
324 | if (!master) | ||
325 | return 0; | ||
326 | |||
327 | ret = -EBUSY; | ||
328 | if (master->netdev_ops->ndo_del_slave) | ||
329 | ret = master->netdev_ops->ndo_del_slave(master, slave->net_dev); | ||
330 | |||
331 | return ret; | ||
332 | } | ||
333 | |||
310 | int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, | 334 | int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, |
311 | const char *iface_name) | 335 | const char *iface_name) |
312 | { | 336 | { |
313 | struct batadv_priv *bat_priv; | 337 | struct batadv_priv *bat_priv; |
314 | struct net_device *soft_iface; | 338 | struct net_device *soft_iface, *master; |
315 | __be16 ethertype = __constant_htons(ETH_P_BATMAN); | 339 | __be16 ethertype = __constant_htons(ETH_P_BATMAN); |
316 | int ret; | 340 | int ret; |
317 | 341 | ||
@@ -321,11 +345,6 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, | |||
321 | if (!atomic_inc_not_zero(&hard_iface->refcount)) | 345 | if (!atomic_inc_not_zero(&hard_iface->refcount)) |
322 | goto out; | 346 | goto out; |
323 | 347 | ||
324 | /* hard-interface is part of a bridge */ | ||
325 | if (hard_iface->net_dev->priv_flags & IFF_BRIDGE_PORT) | ||
326 | pr_err("You are about to enable batman-adv on '%s' which already is part of a bridge. Unless you know exactly what you are doing this is probably wrong and won't work the way you think it would.\n", | ||
327 | hard_iface->net_dev->name); | ||
328 | |||
329 | soft_iface = dev_get_by_name(&init_net, iface_name); | 348 | soft_iface = dev_get_by_name(&init_net, iface_name); |
330 | 349 | ||
331 | if (!soft_iface) { | 350 | if (!soft_iface) { |
@@ -347,12 +366,24 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, | |||
347 | goto err_dev; | 366 | goto err_dev; |
348 | } | 367 | } |
349 | 368 | ||
369 | /* check if the interface is enslaved in another virtual one and | ||
370 | * in that case unlink it first | ||
371 | */ | ||
372 | master = netdev_master_upper_dev_get(hard_iface->net_dev); | ||
373 | ret = batadv_master_del_slave(hard_iface, master); | ||
374 | if (ret) | ||
375 | goto err_dev; | ||
376 | |||
350 | hard_iface->soft_iface = soft_iface; | 377 | hard_iface->soft_iface = soft_iface; |
351 | bat_priv = netdev_priv(hard_iface->soft_iface); | 378 | bat_priv = netdev_priv(hard_iface->soft_iface); |
352 | 379 | ||
380 | ret = netdev_master_upper_dev_link(hard_iface->net_dev, soft_iface); | ||
381 | if (ret) | ||
382 | goto err_dev; | ||
383 | |||
353 | ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface); | 384 | ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface); |
354 | if (ret < 0) | 385 | if (ret < 0) |
355 | goto err_dev; | 386 | goto err_upper; |
356 | 387 | ||
357 | hard_iface->if_num = bat_priv->num_ifaces; | 388 | hard_iface->if_num = bat_priv->num_ifaces; |
358 | bat_priv->num_ifaces++; | 389 | bat_priv->num_ifaces++; |
@@ -362,7 +393,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, | |||
362 | bat_priv->bat_algo_ops->bat_iface_disable(hard_iface); | 393 | bat_priv->bat_algo_ops->bat_iface_disable(hard_iface); |
363 | bat_priv->num_ifaces--; | 394 | bat_priv->num_ifaces--; |
364 | hard_iface->if_status = BATADV_IF_NOT_IN_USE; | 395 | hard_iface->if_status = BATADV_IF_NOT_IN_USE; |
365 | goto err_dev; | 396 | goto err_upper; |
366 | } | 397 | } |
367 | 398 | ||
368 | hard_iface->batman_adv_ptype.type = ethertype; | 399 | hard_iface->batman_adv_ptype.type = ethertype; |
@@ -401,14 +432,18 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, | |||
401 | out: | 432 | out: |
402 | return 0; | 433 | return 0; |
403 | 434 | ||
435 | err_upper: | ||
436 | netdev_upper_dev_unlink(hard_iface->net_dev, soft_iface); | ||
404 | err_dev: | 437 | err_dev: |
438 | hard_iface->soft_iface = NULL; | ||
405 | dev_put(soft_iface); | 439 | dev_put(soft_iface); |
406 | err: | 440 | err: |
407 | batadv_hardif_free_ref(hard_iface); | 441 | batadv_hardif_free_ref(hard_iface); |
408 | return ret; | 442 | return ret; |
409 | } | 443 | } |
410 | 444 | ||
411 | void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface) | 445 | void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface, |
446 | enum batadv_hard_if_cleanup autodel) | ||
412 | { | 447 | { |
413 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); | 448 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
414 | struct batadv_hard_iface *primary_if = NULL; | 449 | struct batadv_hard_iface *primary_if = NULL; |
@@ -446,9 +481,10 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface) | |||
446 | dev_put(hard_iface->soft_iface); | 481 | dev_put(hard_iface->soft_iface); |
447 | 482 | ||
448 | /* nobody uses this interface anymore */ | 483 | /* nobody uses this interface anymore */ |
449 | if (!bat_priv->num_ifaces) | 484 | if (!bat_priv->num_ifaces && autodel == BATADV_IF_CLEANUP_AUTO) |
450 | batadv_softif_destroy(hard_iface->soft_iface); | 485 | batadv_softif_destroy_sysfs(hard_iface->soft_iface); |
451 | 486 | ||
487 | netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface); | ||
452 | hard_iface->soft_iface = NULL; | 488 | hard_iface->soft_iface = NULL; |
453 | batadv_hardif_free_ref(hard_iface); | 489 | batadv_hardif_free_ref(hard_iface); |
454 | 490 | ||
@@ -533,7 +569,8 @@ static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface) | |||
533 | 569 | ||
534 | /* first deactivate interface */ | 570 | /* first deactivate interface */ |
535 | if (hard_iface->if_status != BATADV_IF_NOT_IN_USE) | 571 | if (hard_iface->if_status != BATADV_IF_NOT_IN_USE) |
536 | batadv_hardif_disable_interface(hard_iface); | 572 | batadv_hardif_disable_interface(hard_iface, |
573 | BATADV_IF_CLEANUP_AUTO); | ||
537 | 574 | ||
538 | if (hard_iface->if_status != BATADV_IF_NOT_IN_USE) | 575 | if (hard_iface->if_status != BATADV_IF_NOT_IN_USE) |
539 | return; | 576 | return; |
@@ -563,6 +600,11 @@ static int batadv_hard_if_event(struct notifier_block *this, | |||
563 | struct batadv_hard_iface *primary_if = NULL; | 600 | struct batadv_hard_iface *primary_if = NULL; |
564 | struct batadv_priv *bat_priv; | 601 | struct batadv_priv *bat_priv; |
565 | 602 | ||
603 | if (batadv_softif_is_valid(net_dev) && event == NETDEV_REGISTER) { | ||
604 | batadv_sysfs_add_meshif(net_dev); | ||
605 | return NOTIFY_DONE; | ||
606 | } | ||
607 | |||
566 | hard_iface = batadv_hardif_get_by_netdev(net_dev); | 608 | hard_iface = batadv_hardif_get_by_netdev(net_dev); |
567 | if (!hard_iface && event == NETDEV_REGISTER) | 609 | if (!hard_iface && event == NETDEV_REGISTER) |
568 | hard_iface = batadv_hardif_add_interface(net_dev); | 610 | hard_iface = batadv_hardif_add_interface(net_dev); |
diff --git a/net/batman-adv/hard-interface.h b/net/batman-adv/hard-interface.h index 308437d52e22..49892881a7c5 100644 --- a/net/batman-adv/hard-interface.h +++ b/net/batman-adv/hard-interface.h | |||
@@ -29,13 +29,24 @@ enum batadv_hard_if_state { | |||
29 | BATADV_IF_I_WANT_YOU, | 29 | BATADV_IF_I_WANT_YOU, |
30 | }; | 30 | }; |
31 | 31 | ||
32 | /** | ||
33 | * enum batadv_hard_if_cleanup - Cleanup modi for soft_iface after slave removal | ||
34 | * @BATADV_IF_CLEANUP_KEEP: Don't automatically delete soft-interface | ||
35 | * @BATADV_IF_CLEANUP_AUTO: Delete soft-interface after last slave was removed | ||
36 | */ | ||
37 | enum batadv_hard_if_cleanup { | ||
38 | BATADV_IF_CLEANUP_KEEP, | ||
39 | BATADV_IF_CLEANUP_AUTO, | ||
40 | }; | ||
41 | |||
32 | extern struct notifier_block batadv_hard_if_notifier; | 42 | extern struct notifier_block batadv_hard_if_notifier; |
33 | 43 | ||
34 | struct batadv_hard_iface* | 44 | struct batadv_hard_iface* |
35 | batadv_hardif_get_by_netdev(const struct net_device *net_dev); | 45 | batadv_hardif_get_by_netdev(const struct net_device *net_dev); |
36 | int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, | 46 | int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, |
37 | const char *iface_name); | 47 | const char *iface_name); |
38 | void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface); | 48 | void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface, |
49 | enum batadv_hard_if_cleanup autodel); | ||
39 | void batadv_hardif_remove_interfaces(void); | 50 | void batadv_hardif_remove_interfaces(void); |
40 | int batadv_hardif_min_mtu(struct net_device *soft_iface); | 51 | int batadv_hardif_min_mtu(struct net_device *soft_iface); |
41 | void batadv_update_min_mtu(struct net_device *soft_iface); | 52 | void batadv_update_min_mtu(struct net_device *soft_iface); |
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index fa563e497c48..3e30a0f1b908 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include "vis.h" | 35 | #include "vis.h" |
36 | #include "hash.h" | 36 | #include "hash.h" |
37 | #include "bat_algo.h" | 37 | #include "bat_algo.h" |
38 | #include "network-coding.h" | ||
38 | 39 | ||
39 | 40 | ||
40 | /* List manipulations on hardif_list have to be rtnl_lock()'ed, | 41 | /* List manipulations on hardif_list have to be rtnl_lock()'ed, |
@@ -70,6 +71,7 @@ static int __init batadv_init(void) | |||
70 | batadv_debugfs_init(); | 71 | batadv_debugfs_init(); |
71 | 72 | ||
72 | register_netdevice_notifier(&batadv_hard_if_notifier); | 73 | register_netdevice_notifier(&batadv_hard_if_notifier); |
74 | rtnl_link_register(&batadv_link_ops); | ||
73 | 75 | ||
74 | pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n", | 76 | pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n", |
75 | BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION); | 77 | BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION); |
@@ -80,6 +82,7 @@ static int __init batadv_init(void) | |||
80 | static void __exit batadv_exit(void) | 82 | static void __exit batadv_exit(void) |
81 | { | 83 | { |
82 | batadv_debugfs_destroy(); | 84 | batadv_debugfs_destroy(); |
85 | rtnl_link_unregister(&batadv_link_ops); | ||
83 | unregister_netdevice_notifier(&batadv_hard_if_notifier); | 86 | unregister_netdevice_notifier(&batadv_hard_if_notifier); |
84 | batadv_hardif_remove_interfaces(); | 87 | batadv_hardif_remove_interfaces(); |
85 | 88 | ||
@@ -135,6 +138,10 @@ int batadv_mesh_init(struct net_device *soft_iface) | |||
135 | if (ret < 0) | 138 | if (ret < 0) |
136 | goto err; | 139 | goto err; |
137 | 140 | ||
141 | ret = batadv_nc_init(bat_priv); | ||
142 | if (ret < 0) | ||
143 | goto err; | ||
144 | |||
138 | atomic_set(&bat_priv->gw.reselect, 0); | 145 | atomic_set(&bat_priv->gw.reselect, 0); |
139 | atomic_set(&bat_priv->mesh_state, BATADV_MESH_ACTIVE); | 146 | atomic_set(&bat_priv->mesh_state, BATADV_MESH_ACTIVE); |
140 | 147 | ||
@@ -157,6 +164,7 @@ void batadv_mesh_free(struct net_device *soft_iface) | |||
157 | 164 | ||
158 | batadv_gw_node_purge(bat_priv); | 165 | batadv_gw_node_purge(bat_priv); |
159 | batadv_originator_free(bat_priv); | 166 | batadv_originator_free(bat_priv); |
167 | batadv_nc_free(bat_priv); | ||
160 | 168 | ||
161 | batadv_tt_free(bat_priv); | 169 | batadv_tt_free(bat_priv); |
162 | 170 | ||
@@ -169,6 +177,12 @@ void batadv_mesh_free(struct net_device *soft_iface) | |||
169 | atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE); | 177 | atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE); |
170 | } | 178 | } |
171 | 179 | ||
180 | /** | ||
181 | * batadv_is_my_mac - check if the given mac address belongs to any of the real | ||
182 | * interfaces in the current mesh | ||
183 | * @bat_priv: the bat priv with all the soft interface information | ||
184 | * @addr: the address to check | ||
185 | */ | ||
172 | int batadv_is_my_mac(struct batadv_priv *bat_priv, const uint8_t *addr) | 186 | int batadv_is_my_mac(struct batadv_priv *bat_priv, const uint8_t *addr) |
173 | { | 187 | { |
174 | const struct batadv_hard_iface *hard_iface; | 188 | const struct batadv_hard_iface *hard_iface; |
@@ -414,7 +428,7 @@ int batadv_algo_seq_print_text(struct seq_file *seq, void *offset) | |||
414 | { | 428 | { |
415 | struct batadv_algo_ops *bat_algo_ops; | 429 | struct batadv_algo_ops *bat_algo_ops; |
416 | 430 | ||
417 | seq_printf(seq, "Available routing algorithms:\n"); | 431 | seq_puts(seq, "Available routing algorithms:\n"); |
418 | 432 | ||
419 | hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) { | 433 | hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) { |
420 | seq_printf(seq, "%s\n", bat_algo_ops->name); | 434 | seq_printf(seq, "%s\n", bat_algo_ops->name); |
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h index d40910dfc8ea..59a0d6af15c8 100644 --- a/net/batman-adv/main.h +++ b/net/batman-adv/main.h | |||
@@ -26,7 +26,7 @@ | |||
26 | #define BATADV_DRIVER_DEVICE "batman-adv" | 26 | #define BATADV_DRIVER_DEVICE "batman-adv" |
27 | 27 | ||
28 | #ifndef BATADV_SOURCE_VERSION | 28 | #ifndef BATADV_SOURCE_VERSION |
29 | #define BATADV_SOURCE_VERSION "2013.1.0" | 29 | #define BATADV_SOURCE_VERSION "2013.2.0" |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | /* B.A.T.M.A.N. parameters */ | 32 | /* B.A.T.M.A.N. parameters */ |
@@ -105,6 +105,8 @@ | |||
105 | #define BATADV_RESET_PROTECTION_MS 30000 | 105 | #define BATADV_RESET_PROTECTION_MS 30000 |
106 | #define BATADV_EXPECTED_SEQNO_RANGE 65536 | 106 | #define BATADV_EXPECTED_SEQNO_RANGE 65536 |
107 | 107 | ||
108 | #define BATADV_NC_NODE_TIMEOUT 10000 /* Milliseconds */ | ||
109 | |||
108 | enum batadv_mesh_state { | 110 | enum batadv_mesh_state { |
109 | BATADV_MESH_INACTIVE, | 111 | BATADV_MESH_INACTIVE, |
110 | BATADV_MESH_ACTIVE, | 112 | BATADV_MESH_ACTIVE, |
@@ -150,6 +152,7 @@ enum batadv_uev_type { | |||
150 | #include <linux/percpu.h> | 152 | #include <linux/percpu.h> |
151 | #include <linux/slab.h> | 153 | #include <linux/slab.h> |
152 | #include <net/sock.h> /* struct sock */ | 154 | #include <net/sock.h> /* struct sock */ |
155 | #include <net/rtnetlink.h> | ||
153 | #include <linux/jiffies.h> | 156 | #include <linux/jiffies.h> |
154 | #include <linux/seq_file.h> | 157 | #include <linux/seq_file.h> |
155 | #include "types.h" | 158 | #include "types.h" |
@@ -185,6 +188,7 @@ __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr); | |||
185 | * @BATADV_DBG_TT: translation table messages | 188 | * @BATADV_DBG_TT: translation table messages |
186 | * @BATADV_DBG_BLA: bridge loop avoidance messages | 189 | * @BATADV_DBG_BLA: bridge loop avoidance messages |
187 | * @BATADV_DBG_DAT: ARP snooping and DAT related messages | 190 | * @BATADV_DBG_DAT: ARP snooping and DAT related messages |
191 | * @BATADV_DBG_NC: network coding related messages | ||
188 | * @BATADV_DBG_ALL: the union of all the above log levels | 192 | * @BATADV_DBG_ALL: the union of all the above log levels |
189 | */ | 193 | */ |
190 | enum batadv_dbg_level { | 194 | enum batadv_dbg_level { |
@@ -193,7 +197,8 @@ enum batadv_dbg_level { | |||
193 | BATADV_DBG_TT = BIT(2), | 197 | BATADV_DBG_TT = BIT(2), |
194 | BATADV_DBG_BLA = BIT(3), | 198 | BATADV_DBG_BLA = BIT(3), |
195 | BATADV_DBG_DAT = BIT(4), | 199 | BATADV_DBG_DAT = BIT(4), |
196 | BATADV_DBG_ALL = 31, | 200 | BATADV_DBG_NC = BIT(5), |
201 | BATADV_DBG_ALL = 63, | ||
197 | }; | 202 | }; |
198 | 203 | ||
199 | #ifdef CONFIG_BATMAN_ADV_DEBUG | 204 | #ifdef CONFIG_BATMAN_ADV_DEBUG |
@@ -298,4 +303,10 @@ static inline uint64_t batadv_sum_counter(struct batadv_priv *bat_priv, | |||
298 | return sum; | 303 | return sum; |
299 | } | 304 | } |
300 | 305 | ||
306 | /* Define a macro to reach the control buffer of the skb. The members of the | ||
307 | * control buffer are defined in struct batadv_skb_cb in types.h. | ||
308 | * The macro is inspired by the similar macro TCP_SKB_CB() in tcp.h. | ||
309 | */ | ||
310 | #define BATADV_SKB_CB(__skb) ((struct batadv_skb_cb *)&((__skb)->cb[0])) | ||
311 | |||
301 | #endif /* _NET_BATMAN_ADV_MAIN_H_ */ | 312 | #endif /* _NET_BATMAN_ADV_MAIN_H_ */ |
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c new file mode 100644 index 000000000000..f7c54305a918 --- /dev/null +++ b/net/batman-adv/network-coding.c | |||
@@ -0,0 +1,1822 @@ | |||
1 | /* Copyright (C) 2012-2013 B.A.T.M.A.N. contributors: | ||
2 | * | ||
3 | * Martin Hundebøll, Jeppe Ledet-Pedersen | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of version 2 of the GNU General Public | ||
7 | * License as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but | ||
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | * 02110-1301, USA | ||
18 | */ | ||
19 | |||
20 | #include <linux/debugfs.h> | ||
21 | |||
22 | #include "main.h" | ||
23 | #include "hash.h" | ||
24 | #include "network-coding.h" | ||
25 | #include "send.h" | ||
26 | #include "originator.h" | ||
27 | #include "hard-interface.h" | ||
28 | #include "routing.h" | ||
29 | |||
30 | static struct lock_class_key batadv_nc_coding_hash_lock_class_key; | ||
31 | static struct lock_class_key batadv_nc_decoding_hash_lock_class_key; | ||
32 | |||
33 | static void batadv_nc_worker(struct work_struct *work); | ||
34 | static int batadv_nc_recv_coded_packet(struct sk_buff *skb, | ||
35 | struct batadv_hard_iface *recv_if); | ||
36 | |||
37 | /** | ||
38 | * batadv_nc_start_timer - initialise the nc periodic worker | ||
39 | * @bat_priv: the bat priv with all the soft interface information | ||
40 | */ | ||
41 | static void batadv_nc_start_timer(struct batadv_priv *bat_priv) | ||
42 | { | ||
43 | queue_delayed_work(batadv_event_workqueue, &bat_priv->nc.work, | ||
44 | msecs_to_jiffies(10)); | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * batadv_nc_init - initialise coding hash table and start house keeping | ||
49 | * @bat_priv: the bat priv with all the soft interface information | ||
50 | */ | ||
51 | int batadv_nc_init(struct batadv_priv *bat_priv) | ||
52 | { | ||
53 | bat_priv->nc.timestamp_fwd_flush = jiffies; | ||
54 | bat_priv->nc.timestamp_sniffed_purge = jiffies; | ||
55 | |||
56 | if (bat_priv->nc.coding_hash || bat_priv->nc.decoding_hash) | ||
57 | return 0; | ||
58 | |||
59 | bat_priv->nc.coding_hash = batadv_hash_new(128); | ||
60 | if (!bat_priv->nc.coding_hash) | ||
61 | goto err; | ||
62 | |||
63 | batadv_hash_set_lock_class(bat_priv->nc.coding_hash, | ||
64 | &batadv_nc_coding_hash_lock_class_key); | ||
65 | |||
66 | bat_priv->nc.decoding_hash = batadv_hash_new(128); | ||
67 | if (!bat_priv->nc.decoding_hash) | ||
68 | goto err; | ||
69 | |||
70 | batadv_hash_set_lock_class(bat_priv->nc.coding_hash, | ||
71 | &batadv_nc_decoding_hash_lock_class_key); | ||
72 | |||
73 | /* Register our packet type */ | ||
74 | if (batadv_recv_handler_register(BATADV_CODED, | ||
75 | batadv_nc_recv_coded_packet) < 0) | ||
76 | goto err; | ||
77 | |||
78 | INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker); | ||
79 | batadv_nc_start_timer(bat_priv); | ||
80 | |||
81 | return 0; | ||
82 | |||
83 | err: | ||
84 | return -ENOMEM; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * batadv_nc_init_bat_priv - initialise the nc specific bat_priv variables | ||
89 | * @bat_priv: the bat priv with all the soft interface information | ||
90 | */ | ||
91 | void batadv_nc_init_bat_priv(struct batadv_priv *bat_priv) | ||
92 | { | ||
93 | atomic_set(&bat_priv->network_coding, 1); | ||
94 | bat_priv->nc.min_tq = 200; | ||
95 | bat_priv->nc.max_fwd_delay = 10; | ||
96 | bat_priv->nc.max_buffer_time = 200; | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * batadv_nc_init_orig - initialise the nc fields of an orig_node | ||
101 | * @orig_node: the orig_node which is going to be initialised | ||
102 | */ | ||
103 | void batadv_nc_init_orig(struct batadv_orig_node *orig_node) | ||
104 | { | ||
105 | INIT_LIST_HEAD(&orig_node->in_coding_list); | ||
106 | INIT_LIST_HEAD(&orig_node->out_coding_list); | ||
107 | spin_lock_init(&orig_node->in_coding_list_lock); | ||
108 | spin_lock_init(&orig_node->out_coding_list_lock); | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * batadv_nc_node_free_rcu - rcu callback to free an nc node and remove | ||
113 | * its refcount on the orig_node | ||
114 | * @rcu: rcu pointer of the nc node | ||
115 | */ | ||
116 | static void batadv_nc_node_free_rcu(struct rcu_head *rcu) | ||
117 | { | ||
118 | struct batadv_nc_node *nc_node; | ||
119 | |||
120 | nc_node = container_of(rcu, struct batadv_nc_node, rcu); | ||
121 | batadv_orig_node_free_ref(nc_node->orig_node); | ||
122 | kfree(nc_node); | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * batadv_nc_node_free_ref - decrements the nc node refcounter and possibly | ||
127 | * frees it | ||
128 | * @nc_node: the nc node to free | ||
129 | */ | ||
130 | static void batadv_nc_node_free_ref(struct batadv_nc_node *nc_node) | ||
131 | { | ||
132 | if (atomic_dec_and_test(&nc_node->refcount)) | ||
133 | call_rcu(&nc_node->rcu, batadv_nc_node_free_rcu); | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * batadv_nc_path_free_ref - decrements the nc path refcounter and possibly | ||
138 | * frees it | ||
139 | * @nc_path: the nc node to free | ||
140 | */ | ||
141 | static void batadv_nc_path_free_ref(struct batadv_nc_path *nc_path) | ||
142 | { | ||
143 | if (atomic_dec_and_test(&nc_path->refcount)) | ||
144 | kfree_rcu(nc_path, rcu); | ||
145 | } | ||
146 | |||
147 | /** | ||
148 | * batadv_nc_packet_free - frees nc packet | ||
149 | * @nc_packet: the nc packet to free | ||
150 | */ | ||
151 | static void batadv_nc_packet_free(struct batadv_nc_packet *nc_packet) | ||
152 | { | ||
153 | if (nc_packet->skb) | ||
154 | kfree_skb(nc_packet->skb); | ||
155 | |||
156 | batadv_nc_path_free_ref(nc_packet->nc_path); | ||
157 | kfree(nc_packet); | ||
158 | } | ||
159 | |||
160 | /** | ||
161 | * batadv_nc_to_purge_nc_node - checks whether an nc node has to be purged | ||
162 | * @bat_priv: the bat priv with all the soft interface information | ||
163 | * @nc_node: the nc node to check | ||
164 | * | ||
165 | * Returns true if the entry has to be purged now, false otherwise | ||
166 | */ | ||
167 | static bool batadv_nc_to_purge_nc_node(struct batadv_priv *bat_priv, | ||
168 | struct batadv_nc_node *nc_node) | ||
169 | { | ||
170 | if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) | ||
171 | return true; | ||
172 | |||
173 | return batadv_has_timed_out(nc_node->last_seen, BATADV_NC_NODE_TIMEOUT); | ||
174 | } | ||
175 | |||
176 | /** | ||
177 | * batadv_nc_to_purge_nc_path_coding - checks whether an nc path has timed out | ||
178 | * @bat_priv: the bat priv with all the soft interface information | ||
179 | * @nc_path: the nc path to check | ||
180 | * | ||
181 | * Returns true if the entry has to be purged now, false otherwise | ||
182 | */ | ||
183 | static bool batadv_nc_to_purge_nc_path_coding(struct batadv_priv *bat_priv, | ||
184 | struct batadv_nc_path *nc_path) | ||
185 | { | ||
186 | if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) | ||
187 | return true; | ||
188 | |||
189 | /* purge the path when no packets has been added for 10 times the | ||
190 | * max_fwd_delay time | ||
191 | */ | ||
192 | return batadv_has_timed_out(nc_path->last_valid, | ||
193 | bat_priv->nc.max_fwd_delay * 10); | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * batadv_nc_to_purge_nc_path_decoding - checks whether an nc path has timed out | ||
198 | * @bat_priv: the bat priv with all the soft interface information | ||
199 | * @nc_path: the nc path to check | ||
200 | * | ||
201 | * Returns true if the entry has to be purged now, false otherwise | ||
202 | */ | ||
203 | static bool batadv_nc_to_purge_nc_path_decoding(struct batadv_priv *bat_priv, | ||
204 | struct batadv_nc_path *nc_path) | ||
205 | { | ||
206 | if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) | ||
207 | return true; | ||
208 | |||
209 | /* purge the path when no packets has been added for 10 times the | ||
210 | * max_buffer time | ||
211 | */ | ||
212 | return batadv_has_timed_out(nc_path->last_valid, | ||
213 | bat_priv->nc.max_buffer_time*10); | ||
214 | } | ||
215 | |||
216 | /** | ||
217 | * batadv_nc_purge_orig_nc_nodes - go through list of nc nodes and purge stale | ||
218 | * entries | ||
219 | * @bat_priv: the bat priv with all the soft interface information | ||
220 | * @list: list of nc nodes | ||
221 | * @lock: nc node list lock | ||
222 | * @to_purge: function in charge to decide whether an entry has to be purged or | ||
223 | * not. This function takes the nc node as argument and has to return | ||
224 | * a boolean value: true if the entry has to be deleted, false | ||
225 | * otherwise | ||
226 | */ | ||
227 | static void | ||
228 | batadv_nc_purge_orig_nc_nodes(struct batadv_priv *bat_priv, | ||
229 | struct list_head *list, | ||
230 | spinlock_t *lock, | ||
231 | bool (*to_purge)(struct batadv_priv *, | ||
232 | struct batadv_nc_node *)) | ||
233 | { | ||
234 | struct batadv_nc_node *nc_node, *nc_node_tmp; | ||
235 | |||
236 | /* For each nc_node in list */ | ||
237 | spin_lock_bh(lock); | ||
238 | list_for_each_entry_safe(nc_node, nc_node_tmp, list, list) { | ||
239 | /* if an helper function has been passed as parameter, | ||
240 | * ask it if the entry has to be purged or not | ||
241 | */ | ||
242 | if (to_purge && !to_purge(bat_priv, nc_node)) | ||
243 | continue; | ||
244 | |||
245 | batadv_dbg(BATADV_DBG_NC, bat_priv, | ||
246 | "Removing nc_node %pM -> %pM\n", | ||
247 | nc_node->addr, nc_node->orig_node->orig); | ||
248 | list_del_rcu(&nc_node->list); | ||
249 | batadv_nc_node_free_ref(nc_node); | ||
250 | } | ||
251 | spin_unlock_bh(lock); | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * batadv_nc_purge_orig - purges all nc node data attached of the given | ||
256 | * originator | ||
257 | * @bat_priv: the bat priv with all the soft interface information | ||
258 | * @orig_node: orig_node with the nc node entries to be purged | ||
259 | * @to_purge: function in charge to decide whether an entry has to be purged or | ||
260 | * not. This function takes the nc node as argument and has to return | ||
261 | * a boolean value: true is the entry has to be deleted, false | ||
262 | * otherwise | ||
263 | */ | ||
264 | void batadv_nc_purge_orig(struct batadv_priv *bat_priv, | ||
265 | struct batadv_orig_node *orig_node, | ||
266 | bool (*to_purge)(struct batadv_priv *, | ||
267 | struct batadv_nc_node *)) | ||
268 | { | ||
269 | /* Check ingoing nc_node's of this orig_node */ | ||
270 | batadv_nc_purge_orig_nc_nodes(bat_priv, &orig_node->in_coding_list, | ||
271 | &orig_node->in_coding_list_lock, | ||
272 | to_purge); | ||
273 | |||
274 | /* Check outgoing nc_node's of this orig_node */ | ||
275 | batadv_nc_purge_orig_nc_nodes(bat_priv, &orig_node->out_coding_list, | ||
276 | &orig_node->out_coding_list_lock, | ||
277 | to_purge); | ||
278 | } | ||
279 | |||
280 | /** | ||
281 | * batadv_nc_purge_orig_hash - traverse entire originator hash to check if they | ||
282 | * have timed out nc nodes | ||
283 | * @bat_priv: the bat priv with all the soft interface information | ||
284 | */ | ||
285 | static void batadv_nc_purge_orig_hash(struct batadv_priv *bat_priv) | ||
286 | { | ||
287 | struct batadv_hashtable *hash = bat_priv->orig_hash; | ||
288 | struct hlist_head *head; | ||
289 | struct batadv_orig_node *orig_node; | ||
290 | uint32_t i; | ||
291 | |||
292 | if (!hash) | ||
293 | return; | ||
294 | |||
295 | /* For each orig_node */ | ||
296 | for (i = 0; i < hash->size; i++) { | ||
297 | head = &hash->table[i]; | ||
298 | |||
299 | rcu_read_lock(); | ||
300 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) | ||
301 | batadv_nc_purge_orig(bat_priv, orig_node, | ||
302 | batadv_nc_to_purge_nc_node); | ||
303 | rcu_read_unlock(); | ||
304 | } | ||
305 | } | ||
306 | |||
307 | /** | ||
308 | * batadv_nc_purge_paths - traverse all nc paths part of the hash and remove | ||
309 | * unused ones | ||
310 | * @bat_priv: the bat priv with all the soft interface information | ||
311 | * @hash: hash table containing the nc paths to check | ||
312 | * @to_purge: function in charge to decide whether an entry has to be purged or | ||
313 | * not. This function takes the nc node as argument and has to return | ||
314 | * a boolean value: true is the entry has to be deleted, false | ||
315 | * otherwise | ||
316 | */ | ||
317 | static void batadv_nc_purge_paths(struct batadv_priv *bat_priv, | ||
318 | struct batadv_hashtable *hash, | ||
319 | bool (*to_purge)(struct batadv_priv *, | ||
320 | struct batadv_nc_path *)) | ||
321 | { | ||
322 | struct hlist_head *head; | ||
323 | struct hlist_node *node_tmp; | ||
324 | struct batadv_nc_path *nc_path; | ||
325 | spinlock_t *lock; /* Protects lists in hash */ | ||
326 | uint32_t i; | ||
327 | |||
328 | for (i = 0; i < hash->size; i++) { | ||
329 | head = &hash->table[i]; | ||
330 | lock = &hash->list_locks[i]; | ||
331 | |||
332 | /* For each nc_path in this bin */ | ||
333 | spin_lock_bh(lock); | ||
334 | hlist_for_each_entry_safe(nc_path, node_tmp, head, hash_entry) { | ||
335 | /* if an helper function has been passed as parameter, | ||
336 | * ask it if the entry has to be purged or not | ||
337 | */ | ||
338 | if (to_purge && !to_purge(bat_priv, nc_path)) | ||
339 | continue; | ||
340 | |||
341 | /* purging an non-empty nc_path should never happen, but | ||
342 | * is observed under high CPU load. Delay the purging | ||
343 | * until next iteration to allow the packet_list to be | ||
344 | * emptied first. | ||
345 | */ | ||
346 | if (!unlikely(list_empty(&nc_path->packet_list))) { | ||
347 | net_ratelimited_function(printk, | ||
348 | KERN_WARNING | ||
349 | "Skipping free of non-empty nc_path (%pM -> %pM)!\n", | ||
350 | nc_path->prev_hop, | ||
351 | nc_path->next_hop); | ||
352 | continue; | ||
353 | } | ||
354 | |||
355 | /* nc_path is unused, so remove it */ | ||
356 | batadv_dbg(BATADV_DBG_NC, bat_priv, | ||
357 | "Remove nc_path %pM -> %pM\n", | ||
358 | nc_path->prev_hop, nc_path->next_hop); | ||
359 | hlist_del_rcu(&nc_path->hash_entry); | ||
360 | batadv_nc_path_free_ref(nc_path); | ||
361 | } | ||
362 | spin_unlock_bh(lock); | ||
363 | } | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * batadv_nc_hash_key_gen - computes the nc_path hash key | ||
368 | * @key: buffer to hold the final hash key | ||
369 | * @src: source ethernet mac address going into the hash key | ||
370 | * @dst: destination ethernet mac address going into the hash key | ||
371 | */ | ||
372 | static void batadv_nc_hash_key_gen(struct batadv_nc_path *key, const char *src, | ||
373 | const char *dst) | ||
374 | { | ||
375 | memcpy(key->prev_hop, src, sizeof(key->prev_hop)); | ||
376 | memcpy(key->next_hop, dst, sizeof(key->next_hop)); | ||
377 | } | ||
378 | |||
379 | /** | ||
380 | * batadv_nc_hash_choose - compute the hash value for an nc path | ||
381 | * @data: data to hash | ||
382 | * @size: size of the hash table | ||
383 | * | ||
384 | * Returns the selected index in the hash table for the given data. | ||
385 | */ | ||
386 | static uint32_t batadv_nc_hash_choose(const void *data, uint32_t size) | ||
387 | { | ||
388 | const struct batadv_nc_path *nc_path = data; | ||
389 | uint32_t hash = 0; | ||
390 | |||
391 | hash = batadv_hash_bytes(hash, &nc_path->prev_hop, | ||
392 | sizeof(nc_path->prev_hop)); | ||
393 | hash = batadv_hash_bytes(hash, &nc_path->next_hop, | ||
394 | sizeof(nc_path->next_hop)); | ||
395 | |||
396 | hash += (hash << 3); | ||
397 | hash ^= (hash >> 11); | ||
398 | hash += (hash << 15); | ||
399 | |||
400 | return hash % size; | ||
401 | } | ||
402 | |||
403 | /** | ||
404 | * batadv_nc_hash_compare - comparing function used in the network coding hash | ||
405 | * tables | ||
406 | * @node: node in the local table | ||
407 | * @data2: second object to compare the node to | ||
408 | * | ||
409 | * Returns 1 if the two entry are the same, 0 otherwise | ||
410 | */ | ||
411 | static int batadv_nc_hash_compare(const struct hlist_node *node, | ||
412 | const void *data2) | ||
413 | { | ||
414 | const struct batadv_nc_path *nc_path1, *nc_path2; | ||
415 | |||
416 | nc_path1 = container_of(node, struct batadv_nc_path, hash_entry); | ||
417 | nc_path2 = data2; | ||
418 | |||
419 | /* Return 1 if the two keys are identical */ | ||
420 | if (memcmp(nc_path1->prev_hop, nc_path2->prev_hop, | ||
421 | sizeof(nc_path1->prev_hop)) != 0) | ||
422 | return 0; | ||
423 | |||
424 | if (memcmp(nc_path1->next_hop, nc_path2->next_hop, | ||
425 | sizeof(nc_path1->next_hop)) != 0) | ||
426 | return 0; | ||
427 | |||
428 | return 1; | ||
429 | } | ||
430 | |||
431 | /** | ||
432 | * batadv_nc_hash_find - search for an existing nc path and return it | ||
433 | * @hash: hash table containing the nc path | ||
434 | * @data: search key | ||
435 | * | ||
436 | * Returns the nc_path if found, NULL otherwise. | ||
437 | */ | ||
438 | static struct batadv_nc_path * | ||
439 | batadv_nc_hash_find(struct batadv_hashtable *hash, | ||
440 | void *data) | ||
441 | { | ||
442 | struct hlist_head *head; | ||
443 | struct batadv_nc_path *nc_path, *nc_path_tmp = NULL; | ||
444 | int index; | ||
445 | |||
446 | if (!hash) | ||
447 | return NULL; | ||
448 | |||
449 | index = batadv_nc_hash_choose(data, hash->size); | ||
450 | head = &hash->table[index]; | ||
451 | |||
452 | rcu_read_lock(); | ||
453 | hlist_for_each_entry_rcu(nc_path, head, hash_entry) { | ||
454 | if (!batadv_nc_hash_compare(&nc_path->hash_entry, data)) | ||
455 | continue; | ||
456 | |||
457 | if (!atomic_inc_not_zero(&nc_path->refcount)) | ||
458 | continue; | ||
459 | |||
460 | nc_path_tmp = nc_path; | ||
461 | break; | ||
462 | } | ||
463 | rcu_read_unlock(); | ||
464 | |||
465 | return nc_path_tmp; | ||
466 | } | ||
467 | |||
468 | /** | ||
469 | * batadv_nc_send_packet - send non-coded packet and free nc_packet struct | ||
470 | * @nc_packet: the nc packet to send | ||
471 | */ | ||
472 | static void batadv_nc_send_packet(struct batadv_nc_packet *nc_packet) | ||
473 | { | ||
474 | batadv_send_skb_packet(nc_packet->skb, | ||
475 | nc_packet->neigh_node->if_incoming, | ||
476 | nc_packet->nc_path->next_hop); | ||
477 | nc_packet->skb = NULL; | ||
478 | batadv_nc_packet_free(nc_packet); | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * batadv_nc_sniffed_purge - Checks timestamp of given sniffed nc_packet. | ||
483 | * @bat_priv: the bat priv with all the soft interface information | ||
484 | * @nc_path: the nc path the packet belongs to | ||
485 | * @nc_packet: the nc packet to be checked | ||
486 | * | ||
487 | * Checks whether the given sniffed (overheard) nc_packet has hit its buffering | ||
488 | * timeout. If so, the packet is no longer kept and the entry deleted from the | ||
489 | * queue. Has to be called with the appropriate locks. | ||
490 | * | ||
491 | * Returns false as soon as the entry in the fifo queue has not been timed out | ||
492 | * yet and true otherwise. | ||
493 | */ | ||
494 | static bool batadv_nc_sniffed_purge(struct batadv_priv *bat_priv, | ||
495 | struct batadv_nc_path *nc_path, | ||
496 | struct batadv_nc_packet *nc_packet) | ||
497 | { | ||
498 | unsigned long timeout = bat_priv->nc.max_buffer_time; | ||
499 | bool res = false; | ||
500 | |||
501 | /* Packets are added to tail, so the remaining packets did not time | ||
502 | * out and we can stop processing the current queue | ||
503 | */ | ||
504 | if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE && | ||
505 | !batadv_has_timed_out(nc_packet->timestamp, timeout)) | ||
506 | goto out; | ||
507 | |||
508 | /* purge nc packet */ | ||
509 | list_del(&nc_packet->list); | ||
510 | batadv_nc_packet_free(nc_packet); | ||
511 | |||
512 | res = true; | ||
513 | |||
514 | out: | ||
515 | return res; | ||
516 | } | ||
517 | |||
518 | /** | ||
519 | * batadv_nc_fwd_flush - Checks the timestamp of the given nc packet. | ||
520 | * @bat_priv: the bat priv with all the soft interface information | ||
521 | * @nc_path: the nc path the packet belongs to | ||
522 | * @nc_packet: the nc packet to be checked | ||
523 | * | ||
524 | * Checks whether the given nc packet has hit its forward timeout. If so, the | ||
525 | * packet is no longer delayed, immediately sent and the entry deleted from the | ||
526 | * queue. Has to be called with the appropriate locks. | ||
527 | * | ||
528 | * Returns false as soon as the entry in the fifo queue has not been timed out | ||
529 | * yet and true otherwise. | ||
530 | */ | ||
531 | static bool batadv_nc_fwd_flush(struct batadv_priv *bat_priv, | ||
532 | struct batadv_nc_path *nc_path, | ||
533 | struct batadv_nc_packet *nc_packet) | ||
534 | { | ||
535 | unsigned long timeout = bat_priv->nc.max_fwd_delay; | ||
536 | |||
537 | /* Packets are added to tail, so the remaining packets did not time | ||
538 | * out and we can stop processing the current queue | ||
539 | */ | ||
540 | if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE && | ||
541 | !batadv_has_timed_out(nc_packet->timestamp, timeout)) | ||
542 | return false; | ||
543 | |||
544 | /* Send packet */ | ||
545 | batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD); | ||
546 | batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES, | ||
547 | nc_packet->skb->len + ETH_HLEN); | ||
548 | list_del(&nc_packet->list); | ||
549 | batadv_nc_send_packet(nc_packet); | ||
550 | |||
551 | return true; | ||
552 | } | ||
553 | |||
554 | /** | ||
555 | * batadv_nc_process_nc_paths - traverse given nc packet pool and free timed out | ||
556 | * nc packets | ||
557 | * @bat_priv: the bat priv with all the soft interface information | ||
558 | * @hash: to be processed hash table | ||
559 | * @process_fn: Function called to process given nc packet. Should return true | ||
560 | * to encourage this function to proceed with the next packet. | ||
561 | * Otherwise the rest of the current queue is skipped. | ||
562 | */ | ||
563 | static void | ||
564 | batadv_nc_process_nc_paths(struct batadv_priv *bat_priv, | ||
565 | struct batadv_hashtable *hash, | ||
566 | bool (*process_fn)(struct batadv_priv *, | ||
567 | struct batadv_nc_path *, | ||
568 | struct batadv_nc_packet *)) | ||
569 | { | ||
570 | struct hlist_head *head; | ||
571 | struct batadv_nc_packet *nc_packet, *nc_packet_tmp; | ||
572 | struct batadv_nc_path *nc_path; | ||
573 | bool ret; | ||
574 | int i; | ||
575 | |||
576 | if (!hash) | ||
577 | return; | ||
578 | |||
579 | /* Loop hash table bins */ | ||
580 | for (i = 0; i < hash->size; i++) { | ||
581 | head = &hash->table[i]; | ||
582 | |||
583 | /* Loop coding paths */ | ||
584 | rcu_read_lock(); | ||
585 | hlist_for_each_entry_rcu(nc_path, head, hash_entry) { | ||
586 | /* Loop packets */ | ||
587 | spin_lock_bh(&nc_path->packet_list_lock); | ||
588 | list_for_each_entry_safe(nc_packet, nc_packet_tmp, | ||
589 | &nc_path->packet_list, list) { | ||
590 | ret = process_fn(bat_priv, nc_path, nc_packet); | ||
591 | if (!ret) | ||
592 | break; | ||
593 | } | ||
594 | spin_unlock_bh(&nc_path->packet_list_lock); | ||
595 | } | ||
596 | rcu_read_unlock(); | ||
597 | } | ||
598 | } | ||
599 | |||
600 | /** | ||
601 | * batadv_nc_worker - periodic task for house keeping related to network coding | ||
602 | * @work: kernel work struct | ||
603 | */ | ||
604 | static void batadv_nc_worker(struct work_struct *work) | ||
605 | { | ||
606 | struct delayed_work *delayed_work; | ||
607 | struct batadv_priv_nc *priv_nc; | ||
608 | struct batadv_priv *bat_priv; | ||
609 | unsigned long timeout; | ||
610 | |||
611 | delayed_work = container_of(work, struct delayed_work, work); | ||
612 | priv_nc = container_of(delayed_work, struct batadv_priv_nc, work); | ||
613 | bat_priv = container_of(priv_nc, struct batadv_priv, nc); | ||
614 | |||
615 | batadv_nc_purge_orig_hash(bat_priv); | ||
616 | batadv_nc_purge_paths(bat_priv, bat_priv->nc.coding_hash, | ||
617 | batadv_nc_to_purge_nc_path_coding); | ||
618 | batadv_nc_purge_paths(bat_priv, bat_priv->nc.decoding_hash, | ||
619 | batadv_nc_to_purge_nc_path_decoding); | ||
620 | |||
621 | timeout = bat_priv->nc.max_fwd_delay; | ||
622 | |||
623 | if (batadv_has_timed_out(bat_priv->nc.timestamp_fwd_flush, timeout)) { | ||
624 | batadv_nc_process_nc_paths(bat_priv, bat_priv->nc.coding_hash, | ||
625 | batadv_nc_fwd_flush); | ||
626 | bat_priv->nc.timestamp_fwd_flush = jiffies; | ||
627 | } | ||
628 | |||
629 | if (batadv_has_timed_out(bat_priv->nc.timestamp_sniffed_purge, | ||
630 | bat_priv->nc.max_buffer_time)) { | ||
631 | batadv_nc_process_nc_paths(bat_priv, bat_priv->nc.decoding_hash, | ||
632 | batadv_nc_sniffed_purge); | ||
633 | bat_priv->nc.timestamp_sniffed_purge = jiffies; | ||
634 | } | ||
635 | |||
636 | /* Schedule a new check */ | ||
637 | batadv_nc_start_timer(bat_priv); | ||
638 | } | ||
639 | |||
640 | /** | ||
641 | * batadv_can_nc_with_orig - checks whether the given orig node is suitable for | ||
642 | * coding or not | ||
643 | * @bat_priv: the bat priv with all the soft interface information | ||
644 | * @orig_node: neighboring orig node which may be used as nc candidate | ||
645 | * @ogm_packet: incoming ogm packet also used for the checks | ||
646 | * | ||
647 | * Returns true if: | ||
648 | * 1) The OGM must have the most recent sequence number. | ||
649 | * 2) The TTL must be decremented by one and only one. | ||
650 | * 3) The OGM must be received from the first hop from orig_node. | ||
651 | * 4) The TQ value of the OGM must be above bat_priv->nc.min_tq. | ||
652 | */ | ||
653 | static bool batadv_can_nc_with_orig(struct batadv_priv *bat_priv, | ||
654 | struct batadv_orig_node *orig_node, | ||
655 | struct batadv_ogm_packet *ogm_packet) | ||
656 | { | ||
657 | if (orig_node->last_real_seqno != ntohl(ogm_packet->seqno)) | ||
658 | return false; | ||
659 | if (orig_node->last_ttl != ogm_packet->header.ttl + 1) | ||
660 | return false; | ||
661 | if (!batadv_compare_eth(ogm_packet->orig, ogm_packet->prev_sender)) | ||
662 | return false; | ||
663 | if (ogm_packet->tq < bat_priv->nc.min_tq) | ||
664 | return false; | ||
665 | |||
666 | return true; | ||
667 | } | ||
668 | |||
669 | /** | ||
670 | * batadv_nc_find_nc_node - search for an existing nc node and return it | ||
671 | * @orig_node: orig node originating the ogm packet | ||
672 | * @orig_neigh_node: neighboring orig node from which we received the ogm packet | ||
673 | * (can be equal to orig_node) | ||
674 | * @in_coding: traverse incoming or outgoing network coding list | ||
675 | * | ||
676 | * Returns the nc_node if found, NULL otherwise. | ||
677 | */ | ||
678 | static struct batadv_nc_node | ||
679 | *batadv_nc_find_nc_node(struct batadv_orig_node *orig_node, | ||
680 | struct batadv_orig_node *orig_neigh_node, | ||
681 | bool in_coding) | ||
682 | { | ||
683 | struct batadv_nc_node *nc_node, *nc_node_out = NULL; | ||
684 | struct list_head *list; | ||
685 | |||
686 | if (in_coding) | ||
687 | list = &orig_neigh_node->in_coding_list; | ||
688 | else | ||
689 | list = &orig_neigh_node->out_coding_list; | ||
690 | |||
691 | /* Traverse list of nc_nodes to orig_node */ | ||
692 | rcu_read_lock(); | ||
693 | list_for_each_entry_rcu(nc_node, list, list) { | ||
694 | if (!batadv_compare_eth(nc_node->addr, orig_node->orig)) | ||
695 | continue; | ||
696 | |||
697 | if (!atomic_inc_not_zero(&nc_node->refcount)) | ||
698 | continue; | ||
699 | |||
700 | /* Found a match */ | ||
701 | nc_node_out = nc_node; | ||
702 | break; | ||
703 | } | ||
704 | rcu_read_unlock(); | ||
705 | |||
706 | return nc_node_out; | ||
707 | } | ||
708 | |||
709 | /** | ||
710 | * batadv_nc_get_nc_node - retrieves an nc node or creates the entry if it was | ||
711 | * not found | ||
712 | * @bat_priv: the bat priv with all the soft interface information | ||
713 | * @orig_node: orig node originating the ogm packet | ||
714 | * @orig_neigh_node: neighboring orig node from which we received the ogm packet | ||
715 | * (can be equal to orig_node) | ||
716 | * @in_coding: traverse incoming or outgoing network coding list | ||
717 | * | ||
718 | * Returns the nc_node if found or created, NULL in case of an error. | ||
719 | */ | ||
720 | static struct batadv_nc_node | ||
721 | *batadv_nc_get_nc_node(struct batadv_priv *bat_priv, | ||
722 | struct batadv_orig_node *orig_node, | ||
723 | struct batadv_orig_node *orig_neigh_node, | ||
724 | bool in_coding) | ||
725 | { | ||
726 | struct batadv_nc_node *nc_node; | ||
727 | spinlock_t *lock; /* Used to lock list selected by "int in_coding" */ | ||
728 | struct list_head *list; | ||
729 | |||
730 | /* Check if nc_node is already added */ | ||
731 | nc_node = batadv_nc_find_nc_node(orig_node, orig_neigh_node, in_coding); | ||
732 | |||
733 | /* Node found */ | ||
734 | if (nc_node) | ||
735 | return nc_node; | ||
736 | |||
737 | nc_node = kzalloc(sizeof(*nc_node), GFP_ATOMIC); | ||
738 | if (!nc_node) | ||
739 | return NULL; | ||
740 | |||
741 | if (!atomic_inc_not_zero(&orig_neigh_node->refcount)) | ||
742 | goto free; | ||
743 | |||
744 | /* Initialize nc_node */ | ||
745 | INIT_LIST_HEAD(&nc_node->list); | ||
746 | memcpy(nc_node->addr, orig_node->orig, ETH_ALEN); | ||
747 | nc_node->orig_node = orig_neigh_node; | ||
748 | atomic_set(&nc_node->refcount, 2); | ||
749 | |||
750 | /* Select ingoing or outgoing coding node */ | ||
751 | if (in_coding) { | ||
752 | lock = &orig_neigh_node->in_coding_list_lock; | ||
753 | list = &orig_neigh_node->in_coding_list; | ||
754 | } else { | ||
755 | lock = &orig_neigh_node->out_coding_list_lock; | ||
756 | list = &orig_neigh_node->out_coding_list; | ||
757 | } | ||
758 | |||
759 | batadv_dbg(BATADV_DBG_NC, bat_priv, "Adding nc_node %pM -> %pM\n", | ||
760 | nc_node->addr, nc_node->orig_node->orig); | ||
761 | |||
762 | /* Add nc_node to orig_node */ | ||
763 | spin_lock_bh(lock); | ||
764 | list_add_tail_rcu(&nc_node->list, list); | ||
765 | spin_unlock_bh(lock); | ||
766 | |||
767 | return nc_node; | ||
768 | |||
769 | free: | ||
770 | kfree(nc_node); | ||
771 | return NULL; | ||
772 | } | ||
773 | |||
774 | /** | ||
775 | * batadv_nc_update_nc_node - updates stored incoming and outgoing nc node structs | ||
776 | * (best called on incoming OGMs) | ||
777 | * @bat_priv: the bat priv with all the soft interface information | ||
778 | * @orig_node: orig node originating the ogm packet | ||
779 | * @orig_neigh_node: neighboring orig node from which we received the ogm packet | ||
780 | * (can be equal to orig_node) | ||
781 | * @ogm_packet: incoming ogm packet | ||
782 | * @is_single_hop_neigh: orig_node is a single hop neighbor | ||
783 | */ | ||
784 | void batadv_nc_update_nc_node(struct batadv_priv *bat_priv, | ||
785 | struct batadv_orig_node *orig_node, | ||
786 | struct batadv_orig_node *orig_neigh_node, | ||
787 | struct batadv_ogm_packet *ogm_packet, | ||
788 | int is_single_hop_neigh) | ||
789 | { | ||
790 | struct batadv_nc_node *in_nc_node = NULL, *out_nc_node = NULL; | ||
791 | |||
792 | /* Check if network coding is enabled */ | ||
793 | if (!atomic_read(&bat_priv->network_coding)) | ||
794 | goto out; | ||
795 | |||
796 | /* accept ogms from 'good' neighbors and single hop neighbors */ | ||
797 | if (!batadv_can_nc_with_orig(bat_priv, orig_node, ogm_packet) && | ||
798 | !is_single_hop_neigh) | ||
799 | goto out; | ||
800 | |||
801 | /* Add orig_node as in_nc_node on hop */ | ||
802 | in_nc_node = batadv_nc_get_nc_node(bat_priv, orig_node, | ||
803 | orig_neigh_node, true); | ||
804 | if (!in_nc_node) | ||
805 | goto out; | ||
806 | |||
807 | in_nc_node->last_seen = jiffies; | ||
808 | |||
809 | /* Add hop as out_nc_node on orig_node */ | ||
810 | out_nc_node = batadv_nc_get_nc_node(bat_priv, orig_neigh_node, | ||
811 | orig_node, false); | ||
812 | if (!out_nc_node) | ||
813 | goto out; | ||
814 | |||
815 | out_nc_node->last_seen = jiffies; | ||
816 | |||
817 | out: | ||
818 | if (in_nc_node) | ||
819 | batadv_nc_node_free_ref(in_nc_node); | ||
820 | if (out_nc_node) | ||
821 | batadv_nc_node_free_ref(out_nc_node); | ||
822 | } | ||
823 | |||
824 | /** | ||
825 | * batadv_nc_get_path - get existing nc_path or allocate a new one | ||
826 | * @bat_priv: the bat priv with all the soft interface information | ||
827 | * @hash: hash table containing the nc path | ||
828 | * @src: ethernet source address - first half of the nc path search key | ||
829 | * @dst: ethernet destination address - second half of the nc path search key | ||
830 | * | ||
831 | * Returns pointer to nc_path if the path was found or created, returns NULL | ||
832 | * on error. | ||
833 | */ | ||
834 | static struct batadv_nc_path *batadv_nc_get_path(struct batadv_priv *bat_priv, | ||
835 | struct batadv_hashtable *hash, | ||
836 | uint8_t *src, | ||
837 | uint8_t *dst) | ||
838 | { | ||
839 | int hash_added; | ||
840 | struct batadv_nc_path *nc_path, nc_path_key; | ||
841 | |||
842 | batadv_nc_hash_key_gen(&nc_path_key, src, dst); | ||
843 | |||
844 | /* Search for existing nc_path */ | ||
845 | nc_path = batadv_nc_hash_find(hash, (void *)&nc_path_key); | ||
846 | |||
847 | if (nc_path) { | ||
848 | /* Set timestamp to delay removal of nc_path */ | ||
849 | nc_path->last_valid = jiffies; | ||
850 | return nc_path; | ||
851 | } | ||
852 | |||
853 | /* No existing nc_path was found; create a new */ | ||
854 | nc_path = kzalloc(sizeof(*nc_path), GFP_ATOMIC); | ||
855 | |||
856 | if (!nc_path) | ||
857 | return NULL; | ||
858 | |||
859 | /* Initialize nc_path */ | ||
860 | INIT_LIST_HEAD(&nc_path->packet_list); | ||
861 | spin_lock_init(&nc_path->packet_list_lock); | ||
862 | atomic_set(&nc_path->refcount, 2); | ||
863 | nc_path->last_valid = jiffies; | ||
864 | memcpy(nc_path->next_hop, dst, ETH_ALEN); | ||
865 | memcpy(nc_path->prev_hop, src, ETH_ALEN); | ||
866 | |||
867 | batadv_dbg(BATADV_DBG_NC, bat_priv, "Adding nc_path %pM -> %pM\n", | ||
868 | nc_path->prev_hop, | ||
869 | nc_path->next_hop); | ||
870 | |||
871 | /* Add nc_path to hash table */ | ||
872 | hash_added = batadv_hash_add(hash, batadv_nc_hash_compare, | ||
873 | batadv_nc_hash_choose, &nc_path_key, | ||
874 | &nc_path->hash_entry); | ||
875 | |||
876 | if (hash_added < 0) { | ||
877 | kfree(nc_path); | ||
878 | return NULL; | ||
879 | } | ||
880 | |||
881 | return nc_path; | ||
882 | } | ||
883 | |||
884 | /** | ||
885 | * batadv_nc_random_weight_tq - scale the receivers TQ-value to avoid unfair | ||
886 | * selection of a receiver with slightly lower TQ than the other | ||
887 | * @tq: to be weighted tq value | ||
888 | */ | ||
889 | static uint8_t batadv_nc_random_weight_tq(uint8_t tq) | ||
890 | { | ||
891 | uint8_t rand_val, rand_tq; | ||
892 | |||
893 | get_random_bytes(&rand_val, sizeof(rand_val)); | ||
894 | |||
895 | /* randomize the estimated packet loss (max TQ - estimated TQ) */ | ||
896 | rand_tq = rand_val * (BATADV_TQ_MAX_VALUE - tq); | ||
897 | |||
898 | /* normalize the randomized packet loss */ | ||
899 | rand_tq /= BATADV_TQ_MAX_VALUE; | ||
900 | |||
901 | /* convert to (randomized) estimated tq again */ | ||
902 | return BATADV_TQ_MAX_VALUE - rand_tq; | ||
903 | } | ||
904 | |||
905 | /** | ||
906 | * batadv_nc_memxor - XOR destination with source | ||
907 | * @dst: byte array to XOR into | ||
908 | * @src: byte array to XOR from | ||
909 | * @len: length of destination array | ||
910 | */ | ||
911 | static void batadv_nc_memxor(char *dst, const char *src, unsigned int len) | ||
912 | { | ||
913 | unsigned int i; | ||
914 | |||
915 | for (i = 0; i < len; ++i) | ||
916 | dst[i] ^= src[i]; | ||
917 | } | ||
918 | |||
919 | /** | ||
920 | * batadv_nc_code_packets - code a received unicast_packet with an nc packet | ||
921 | * into a coded_packet and send it | ||
922 | * @bat_priv: the bat priv with all the soft interface information | ||
923 | * @skb: data skb to forward | ||
924 | * @ethhdr: pointer to the ethernet header inside the skb | ||
925 | * @nc_packet: structure containing the packet to the skb can be coded with | ||
926 | * @neigh_node: next hop to forward packet to | ||
927 | * | ||
928 | * Returns true if both packets are consumed, false otherwise. | ||
929 | */ | ||
930 | static bool batadv_nc_code_packets(struct batadv_priv *bat_priv, | ||
931 | struct sk_buff *skb, | ||
932 | struct ethhdr *ethhdr, | ||
933 | struct batadv_nc_packet *nc_packet, | ||
934 | struct batadv_neigh_node *neigh_node) | ||
935 | { | ||
936 | uint8_t tq_weighted_neigh, tq_weighted_coding; | ||
937 | struct sk_buff *skb_dest, *skb_src; | ||
938 | struct batadv_unicast_packet *packet1; | ||
939 | struct batadv_unicast_packet *packet2; | ||
940 | struct batadv_coded_packet *coded_packet; | ||
941 | struct batadv_neigh_node *neigh_tmp, *router_neigh; | ||
942 | struct batadv_neigh_node *router_coding = NULL; | ||
943 | uint8_t *first_source, *first_dest, *second_source, *second_dest; | ||
944 | __be32 packet_id1, packet_id2; | ||
945 | size_t count; | ||
946 | bool res = false; | ||
947 | int coding_len; | ||
948 | int unicast_size = sizeof(*packet1); | ||
949 | int coded_size = sizeof(*coded_packet); | ||
950 | int header_add = coded_size - unicast_size; | ||
951 | |||
952 | router_neigh = batadv_orig_node_get_router(neigh_node->orig_node); | ||
953 | if (!router_neigh) | ||
954 | goto out; | ||
955 | |||
956 | neigh_tmp = nc_packet->neigh_node; | ||
957 | router_coding = batadv_orig_node_get_router(neigh_tmp->orig_node); | ||
958 | if (!router_coding) | ||
959 | goto out; | ||
960 | |||
961 | tq_weighted_neigh = batadv_nc_random_weight_tq(router_neigh->tq_avg); | ||
962 | tq_weighted_coding = batadv_nc_random_weight_tq(router_coding->tq_avg); | ||
963 | |||
964 | /* Select one destination for the MAC-header dst-field based on | ||
965 | * weighted TQ-values. | ||
966 | */ | ||
967 | if (tq_weighted_neigh >= tq_weighted_coding) { | ||
968 | /* Destination from nc_packet is selected for MAC-header */ | ||
969 | first_dest = nc_packet->nc_path->next_hop; | ||
970 | first_source = nc_packet->nc_path->prev_hop; | ||
971 | second_dest = neigh_node->addr; | ||
972 | second_source = ethhdr->h_source; | ||
973 | packet1 = (struct batadv_unicast_packet *)nc_packet->skb->data; | ||
974 | packet2 = (struct batadv_unicast_packet *)skb->data; | ||
975 | packet_id1 = nc_packet->packet_id; | ||
976 | packet_id2 = batadv_skb_crc32(skb, | ||
977 | skb->data + sizeof(*packet2)); | ||
978 | } else { | ||
979 | /* Destination for skb is selected for MAC-header */ | ||
980 | first_dest = neigh_node->addr; | ||
981 | first_source = ethhdr->h_source; | ||
982 | second_dest = nc_packet->nc_path->next_hop; | ||
983 | second_source = nc_packet->nc_path->prev_hop; | ||
984 | packet1 = (struct batadv_unicast_packet *)skb->data; | ||
985 | packet2 = (struct batadv_unicast_packet *)nc_packet->skb->data; | ||
986 | packet_id1 = batadv_skb_crc32(skb, | ||
987 | skb->data + sizeof(*packet1)); | ||
988 | packet_id2 = nc_packet->packet_id; | ||
989 | } | ||
990 | |||
991 | /* Instead of zero padding the smallest data buffer, we | ||
992 | * code into the largest. | ||
993 | */ | ||
994 | if (skb->len <= nc_packet->skb->len) { | ||
995 | skb_dest = nc_packet->skb; | ||
996 | skb_src = skb; | ||
997 | } else { | ||
998 | skb_dest = skb; | ||
999 | skb_src = nc_packet->skb; | ||
1000 | } | ||
1001 | |||
1002 | /* coding_len is used when decoding the packet shorter packet */ | ||
1003 | coding_len = skb_src->len - unicast_size; | ||
1004 | |||
1005 | if (skb_linearize(skb_dest) < 0 || skb_linearize(skb_src) < 0) | ||
1006 | goto out; | ||
1007 | |||
1008 | skb_push(skb_dest, header_add); | ||
1009 | |||
1010 | coded_packet = (struct batadv_coded_packet *)skb_dest->data; | ||
1011 | skb_reset_mac_header(skb_dest); | ||
1012 | |||
1013 | coded_packet->header.packet_type = BATADV_CODED; | ||
1014 | coded_packet->header.version = BATADV_COMPAT_VERSION; | ||
1015 | coded_packet->header.ttl = packet1->header.ttl; | ||
1016 | |||
1017 | /* Info about first unicast packet */ | ||
1018 | memcpy(coded_packet->first_source, first_source, ETH_ALEN); | ||
1019 | memcpy(coded_packet->first_orig_dest, packet1->dest, ETH_ALEN); | ||
1020 | coded_packet->first_crc = packet_id1; | ||
1021 | coded_packet->first_ttvn = packet1->ttvn; | ||
1022 | |||
1023 | /* Info about second unicast packet */ | ||
1024 | memcpy(coded_packet->second_dest, second_dest, ETH_ALEN); | ||
1025 | memcpy(coded_packet->second_source, second_source, ETH_ALEN); | ||
1026 | memcpy(coded_packet->second_orig_dest, packet2->dest, ETH_ALEN); | ||
1027 | coded_packet->second_crc = packet_id2; | ||
1028 | coded_packet->second_ttl = packet2->header.ttl; | ||
1029 | coded_packet->second_ttvn = packet2->ttvn; | ||
1030 | coded_packet->coded_len = htons(coding_len); | ||
1031 | |||
1032 | /* This is where the magic happens: Code skb_src into skb_dest */ | ||
1033 | batadv_nc_memxor(skb_dest->data + coded_size, | ||
1034 | skb_src->data + unicast_size, coding_len); | ||
1035 | |||
1036 | /* Update counters accordingly */ | ||
1037 | if (BATADV_SKB_CB(skb_src)->decoded && | ||
1038 | BATADV_SKB_CB(skb_dest)->decoded) { | ||
1039 | /* Both packets are recoded */ | ||
1040 | count = skb_src->len + ETH_HLEN; | ||
1041 | count += skb_dest->len + ETH_HLEN; | ||
1042 | batadv_add_counter(bat_priv, BATADV_CNT_NC_RECODE, 2); | ||
1043 | batadv_add_counter(bat_priv, BATADV_CNT_NC_RECODE_BYTES, count); | ||
1044 | } else if (!BATADV_SKB_CB(skb_src)->decoded && | ||
1045 | !BATADV_SKB_CB(skb_dest)->decoded) { | ||
1046 | /* Both packets are newly coded */ | ||
1047 | count = skb_src->len + ETH_HLEN; | ||
1048 | count += skb_dest->len + ETH_HLEN; | ||
1049 | batadv_add_counter(bat_priv, BATADV_CNT_NC_CODE, 2); | ||
1050 | batadv_add_counter(bat_priv, BATADV_CNT_NC_CODE_BYTES, count); | ||
1051 | } else if (BATADV_SKB_CB(skb_src)->decoded && | ||
1052 | !BATADV_SKB_CB(skb_dest)->decoded) { | ||
1053 | /* skb_src recoded and skb_dest is newly coded */ | ||
1054 | batadv_inc_counter(bat_priv, BATADV_CNT_NC_RECODE); | ||
1055 | batadv_add_counter(bat_priv, BATADV_CNT_NC_RECODE_BYTES, | ||
1056 | skb_src->len + ETH_HLEN); | ||
1057 | batadv_inc_counter(bat_priv, BATADV_CNT_NC_CODE); | ||
1058 | batadv_add_counter(bat_priv, BATADV_CNT_NC_CODE_BYTES, | ||
1059 | skb_dest->len + ETH_HLEN); | ||
1060 | } else if (!BATADV_SKB_CB(skb_src)->decoded && | ||
1061 | BATADV_SKB_CB(skb_dest)->decoded) { | ||
1062 | /* skb_src is newly coded and skb_dest is recoded */ | ||
1063 | batadv_inc_counter(bat_priv, BATADV_CNT_NC_CODE); | ||
1064 | batadv_add_counter(bat_priv, BATADV_CNT_NC_CODE_BYTES, | ||
1065 | skb_src->len + ETH_HLEN); | ||
1066 | batadv_inc_counter(bat_priv, BATADV_CNT_NC_RECODE); | ||
1067 | batadv_add_counter(bat_priv, BATADV_CNT_NC_RECODE_BYTES, | ||
1068 | skb_dest->len + ETH_HLEN); | ||
1069 | } | ||
1070 | |||
1071 | /* skb_src is now coded into skb_dest, so free it */ | ||
1072 | kfree_skb(skb_src); | ||
1073 | |||
1074 | /* avoid duplicate free of skb from nc_packet */ | ||
1075 | nc_packet->skb = NULL; | ||
1076 | batadv_nc_packet_free(nc_packet); | ||
1077 | |||
1078 | /* Send the coded packet and return true */ | ||
1079 | batadv_send_skb_packet(skb_dest, neigh_node->if_incoming, first_dest); | ||
1080 | res = true; | ||
1081 | out: | ||
1082 | if (router_neigh) | ||
1083 | batadv_neigh_node_free_ref(router_neigh); | ||
1084 | if (router_coding) | ||
1085 | batadv_neigh_node_free_ref(router_coding); | ||
1086 | return res; | ||
1087 | } | ||
1088 | |||
1089 | /** | ||
1090 | * batadv_nc_skb_coding_possible - true if a decoded skb is available at dst. | ||
1091 | * @skb: data skb to forward | ||
1092 | * @dst: destination mac address of the other skb to code with | ||
1093 | * @src: source mac address of skb | ||
1094 | * | ||
1095 | * Whenever we network code a packet we have to check whether we received it in | ||
1096 | * a network coded form. If so, we may not be able to use it for coding because | ||
1097 | * some neighbors may also have received (overheard) the packet in the network | ||
1098 | * coded form without being able to decode it. It is hard to know which of the | ||
1099 | * neighboring nodes was able to decode the packet, therefore we can only | ||
1100 | * re-code the packet if the source of the previous encoded packet is involved. | ||
1101 | * Since the source encoded the packet we can be certain it has all necessary | ||
1102 | * decode information. | ||
1103 | * | ||
1104 | * Returns true if coding of a decoded packet is allowed. | ||
1105 | */ | ||
1106 | static bool batadv_nc_skb_coding_possible(struct sk_buff *skb, | ||
1107 | uint8_t *dst, uint8_t *src) | ||
1108 | { | ||
1109 | if (BATADV_SKB_CB(skb)->decoded && !batadv_compare_eth(dst, src)) | ||
1110 | return false; | ||
1111 | else | ||
1112 | return true; | ||
1113 | } | ||
1114 | |||
1115 | /** | ||
1116 | * batadv_nc_path_search - Find the coding path matching in_nc_node and | ||
1117 | * out_nc_node to retrieve a buffered packet that can be used for coding. | ||
1118 | * @bat_priv: the bat priv with all the soft interface information | ||
1119 | * @in_nc_node: pointer to skb next hop's neighbor nc node | ||
1120 | * @out_nc_node: pointer to skb source's neighbor nc node | ||
1121 | * @skb: data skb to forward | ||
1122 | * @eth_dst: next hop mac address of skb | ||
1123 | * | ||
1124 | * Returns true if coding of a decoded skb is allowed. | ||
1125 | */ | ||
1126 | static struct batadv_nc_packet * | ||
1127 | batadv_nc_path_search(struct batadv_priv *bat_priv, | ||
1128 | struct batadv_nc_node *in_nc_node, | ||
1129 | struct batadv_nc_node *out_nc_node, | ||
1130 | struct sk_buff *skb, | ||
1131 | uint8_t *eth_dst) | ||
1132 | { | ||
1133 | struct batadv_nc_path *nc_path, nc_path_key; | ||
1134 | struct batadv_nc_packet *nc_packet_out = NULL; | ||
1135 | struct batadv_nc_packet *nc_packet, *nc_packet_tmp; | ||
1136 | struct batadv_hashtable *hash = bat_priv->nc.coding_hash; | ||
1137 | int idx; | ||
1138 | |||
1139 | if (!hash) | ||
1140 | return NULL; | ||
1141 | |||
1142 | /* Create almost path key */ | ||
1143 | batadv_nc_hash_key_gen(&nc_path_key, in_nc_node->addr, | ||
1144 | out_nc_node->addr); | ||
1145 | idx = batadv_nc_hash_choose(&nc_path_key, hash->size); | ||
1146 | |||
1147 | /* Check for coding opportunities in this nc_path */ | ||
1148 | rcu_read_lock(); | ||
1149 | hlist_for_each_entry_rcu(nc_path, &hash->table[idx], hash_entry) { | ||
1150 | if (!batadv_compare_eth(nc_path->prev_hop, in_nc_node->addr)) | ||
1151 | continue; | ||
1152 | |||
1153 | if (!batadv_compare_eth(nc_path->next_hop, out_nc_node->addr)) | ||
1154 | continue; | ||
1155 | |||
1156 | spin_lock_bh(&nc_path->packet_list_lock); | ||
1157 | if (list_empty(&nc_path->packet_list)) { | ||
1158 | spin_unlock_bh(&nc_path->packet_list_lock); | ||
1159 | continue; | ||
1160 | } | ||
1161 | |||
1162 | list_for_each_entry_safe(nc_packet, nc_packet_tmp, | ||
1163 | &nc_path->packet_list, list) { | ||
1164 | if (!batadv_nc_skb_coding_possible(nc_packet->skb, | ||
1165 | eth_dst, | ||
1166 | in_nc_node->addr)) | ||
1167 | continue; | ||
1168 | |||
1169 | /* Coding opportunity is found! */ | ||
1170 | list_del(&nc_packet->list); | ||
1171 | nc_packet_out = nc_packet; | ||
1172 | break; | ||
1173 | } | ||
1174 | |||
1175 | spin_unlock_bh(&nc_path->packet_list_lock); | ||
1176 | break; | ||
1177 | } | ||
1178 | rcu_read_unlock(); | ||
1179 | |||
1180 | return nc_packet_out; | ||
1181 | } | ||
1182 | |||
1183 | /** | ||
1184 | * batadv_nc_skb_src_search - Loops through the list of neighoring nodes of the | ||
1185 | * skb's sender (may be equal to the originator). | ||
1186 | * @bat_priv: the bat priv with all the soft interface information | ||
1187 | * @skb: data skb to forward | ||
1188 | * @eth_dst: next hop mac address of skb | ||
1189 | * @eth_src: source mac address of skb | ||
1190 | * @in_nc_node: pointer to skb next hop's neighbor nc node | ||
1191 | * | ||
1192 | * Returns an nc packet if a suitable coding packet was found, NULL otherwise. | ||
1193 | */ | ||
1194 | static struct batadv_nc_packet * | ||
1195 | batadv_nc_skb_src_search(struct batadv_priv *bat_priv, | ||
1196 | struct sk_buff *skb, | ||
1197 | uint8_t *eth_dst, | ||
1198 | uint8_t *eth_src, | ||
1199 | struct batadv_nc_node *in_nc_node) | ||
1200 | { | ||
1201 | struct batadv_orig_node *orig_node; | ||
1202 | struct batadv_nc_node *out_nc_node; | ||
1203 | struct batadv_nc_packet *nc_packet = NULL; | ||
1204 | |||
1205 | orig_node = batadv_orig_hash_find(bat_priv, eth_src); | ||
1206 | if (!orig_node) | ||
1207 | return NULL; | ||
1208 | |||
1209 | rcu_read_lock(); | ||
1210 | list_for_each_entry_rcu(out_nc_node, | ||
1211 | &orig_node->out_coding_list, list) { | ||
1212 | /* Check if the skb is decoded and if recoding is possible */ | ||
1213 | if (!batadv_nc_skb_coding_possible(skb, | ||
1214 | out_nc_node->addr, eth_src)) | ||
1215 | continue; | ||
1216 | |||
1217 | /* Search for an opportunity in this nc_path */ | ||
1218 | nc_packet = batadv_nc_path_search(bat_priv, in_nc_node, | ||
1219 | out_nc_node, skb, eth_dst); | ||
1220 | if (nc_packet) | ||
1221 | break; | ||
1222 | } | ||
1223 | rcu_read_unlock(); | ||
1224 | |||
1225 | batadv_orig_node_free_ref(orig_node); | ||
1226 | return nc_packet; | ||
1227 | } | ||
1228 | |||
1229 | /** | ||
1230 | * batadv_nc_skb_store_before_coding - set the ethernet src and dst of the | ||
1231 | * unicast skb before it is stored for use in later decoding | ||
1232 | * @bat_priv: the bat priv with all the soft interface information | ||
1233 | * @skb: data skb to store | ||
1234 | * @eth_dst_new: new destination mac address of skb | ||
1235 | */ | ||
1236 | static void batadv_nc_skb_store_before_coding(struct batadv_priv *bat_priv, | ||
1237 | struct sk_buff *skb, | ||
1238 | uint8_t *eth_dst_new) | ||
1239 | { | ||
1240 | struct ethhdr *ethhdr; | ||
1241 | |||
1242 | /* Copy skb header to change the mac header */ | ||
1243 | skb = pskb_copy(skb, GFP_ATOMIC); | ||
1244 | if (!skb) | ||
1245 | return; | ||
1246 | |||
1247 | /* Set the mac header as if we actually sent the packet uncoded */ | ||
1248 | ethhdr = (struct ethhdr *)skb_mac_header(skb); | ||
1249 | memcpy(ethhdr->h_source, ethhdr->h_dest, ETH_ALEN); | ||
1250 | memcpy(ethhdr->h_dest, eth_dst_new, ETH_ALEN); | ||
1251 | |||
1252 | /* Set data pointer to MAC header to mimic packets from our tx path */ | ||
1253 | skb_push(skb, ETH_HLEN); | ||
1254 | |||
1255 | /* Add the packet to the decoding packet pool */ | ||
1256 | batadv_nc_skb_store_for_decoding(bat_priv, skb); | ||
1257 | |||
1258 | /* batadv_nc_skb_store_for_decoding() clones the skb, so we must free | ||
1259 | * our ref | ||
1260 | */ | ||
1261 | kfree_skb(skb); | ||
1262 | } | ||
1263 | |||
1264 | /** | ||
1265 | * batadv_nc_skb_dst_search - Loops through list of neighboring nodes to dst. | ||
1266 | * @skb: data skb to forward | ||
1267 | * @neigh_node: next hop to forward packet to | ||
1268 | * @ethhdr: pointer to the ethernet header inside the skb | ||
1269 | * | ||
1270 | * Loops through list of neighboring nodes the next hop has a good connection to | ||
1271 | * (receives OGMs with a sufficient quality). We need to find a neighbor of our | ||
1272 | * next hop that potentially sent a packet which our next hop also received | ||
1273 | * (overheard) and has stored for later decoding. | ||
1274 | * | ||
1275 | * Returns true if the skb was consumed (encoded packet sent) or false otherwise | ||
1276 | */ | ||
1277 | static bool batadv_nc_skb_dst_search(struct sk_buff *skb, | ||
1278 | struct batadv_neigh_node *neigh_node, | ||
1279 | struct ethhdr *ethhdr) | ||
1280 | { | ||
1281 | struct net_device *netdev = neigh_node->if_incoming->soft_iface; | ||
1282 | struct batadv_priv *bat_priv = netdev_priv(netdev); | ||
1283 | struct batadv_orig_node *orig_node = neigh_node->orig_node; | ||
1284 | struct batadv_nc_node *nc_node; | ||
1285 | struct batadv_nc_packet *nc_packet = NULL; | ||
1286 | |||
1287 | rcu_read_lock(); | ||
1288 | list_for_each_entry_rcu(nc_node, &orig_node->in_coding_list, list) { | ||
1289 | /* Search for coding opportunity with this in_nc_node */ | ||
1290 | nc_packet = batadv_nc_skb_src_search(bat_priv, skb, | ||
1291 | neigh_node->addr, | ||
1292 | ethhdr->h_source, nc_node); | ||
1293 | |||
1294 | /* Opportunity was found, so stop searching */ | ||
1295 | if (nc_packet) | ||
1296 | break; | ||
1297 | } | ||
1298 | rcu_read_unlock(); | ||
1299 | |||
1300 | if (!nc_packet) | ||
1301 | return false; | ||
1302 | |||
1303 | /* Save packets for later decoding */ | ||
1304 | batadv_nc_skb_store_before_coding(bat_priv, skb, | ||
1305 | neigh_node->addr); | ||
1306 | batadv_nc_skb_store_before_coding(bat_priv, nc_packet->skb, | ||
1307 | nc_packet->neigh_node->addr); | ||
1308 | |||
1309 | /* Code and send packets */ | ||
1310 | if (batadv_nc_code_packets(bat_priv, skb, ethhdr, nc_packet, | ||
1311 | neigh_node)) | ||
1312 | return true; | ||
1313 | |||
1314 | /* out of mem ? Coding failed - we have to free the buffered packet | ||
1315 | * to avoid memleaks. The skb passed as argument will be dealt with | ||
1316 | * by the calling function. | ||
1317 | */ | ||
1318 | batadv_nc_send_packet(nc_packet); | ||
1319 | return false; | ||
1320 | } | ||
1321 | |||
1322 | /** | ||
1323 | * batadv_nc_skb_add_to_path - buffer skb for later encoding / decoding | ||
1324 | * @skb: skb to add to path | ||
1325 | * @nc_path: path to add skb to | ||
1326 | * @neigh_node: next hop to forward packet to | ||
1327 | * @packet_id: checksum to identify packet | ||
1328 | * | ||
1329 | * Returns true if the packet was buffered or false in case of an error. | ||
1330 | */ | ||
1331 | static bool batadv_nc_skb_add_to_path(struct sk_buff *skb, | ||
1332 | struct batadv_nc_path *nc_path, | ||
1333 | struct batadv_neigh_node *neigh_node, | ||
1334 | __be32 packet_id) | ||
1335 | { | ||
1336 | struct batadv_nc_packet *nc_packet; | ||
1337 | |||
1338 | nc_packet = kzalloc(sizeof(*nc_packet), GFP_ATOMIC); | ||
1339 | if (!nc_packet) | ||
1340 | return false; | ||
1341 | |||
1342 | /* Initialize nc_packet */ | ||
1343 | nc_packet->timestamp = jiffies; | ||
1344 | nc_packet->packet_id = packet_id; | ||
1345 | nc_packet->skb = skb; | ||
1346 | nc_packet->neigh_node = neigh_node; | ||
1347 | nc_packet->nc_path = nc_path; | ||
1348 | |||
1349 | /* Add coding packet to list */ | ||
1350 | spin_lock_bh(&nc_path->packet_list_lock); | ||
1351 | list_add_tail(&nc_packet->list, &nc_path->packet_list); | ||
1352 | spin_unlock_bh(&nc_path->packet_list_lock); | ||
1353 | |||
1354 | return true; | ||
1355 | } | ||
1356 | |||
1357 | /** | ||
1358 | * batadv_nc_skb_forward - try to code a packet or add it to the coding packet | ||
1359 | * buffer | ||
1360 | * @skb: data skb to forward | ||
1361 | * @neigh_node: next hop to forward packet to | ||
1362 | * @ethhdr: pointer to the ethernet header inside the skb | ||
1363 | * | ||
1364 | * Returns true if the skb was consumed (encoded packet sent) or false otherwise | ||
1365 | */ | ||
1366 | bool batadv_nc_skb_forward(struct sk_buff *skb, | ||
1367 | struct batadv_neigh_node *neigh_node, | ||
1368 | struct ethhdr *ethhdr) | ||
1369 | { | ||
1370 | const struct net_device *netdev = neigh_node->if_incoming->soft_iface; | ||
1371 | struct batadv_priv *bat_priv = netdev_priv(netdev); | ||
1372 | struct batadv_unicast_packet *packet; | ||
1373 | struct batadv_nc_path *nc_path; | ||
1374 | __be32 packet_id; | ||
1375 | u8 *payload; | ||
1376 | |||
1377 | /* Check if network coding is enabled */ | ||
1378 | if (!atomic_read(&bat_priv->network_coding)) | ||
1379 | goto out; | ||
1380 | |||
1381 | /* We only handle unicast packets */ | ||
1382 | payload = skb_network_header(skb); | ||
1383 | packet = (struct batadv_unicast_packet *)payload; | ||
1384 | if (packet->header.packet_type != BATADV_UNICAST) | ||
1385 | goto out; | ||
1386 | |||
1387 | /* Try to find a coding opportunity and send the skb if one is found */ | ||
1388 | if (batadv_nc_skb_dst_search(skb, neigh_node, ethhdr)) | ||
1389 | return true; | ||
1390 | |||
1391 | /* Find or create a nc_path for this src-dst pair */ | ||
1392 | nc_path = batadv_nc_get_path(bat_priv, | ||
1393 | bat_priv->nc.coding_hash, | ||
1394 | ethhdr->h_source, | ||
1395 | neigh_node->addr); | ||
1396 | |||
1397 | if (!nc_path) | ||
1398 | goto out; | ||
1399 | |||
1400 | /* Add skb to nc_path */ | ||
1401 | packet_id = batadv_skb_crc32(skb, payload + sizeof(*packet)); | ||
1402 | if (!batadv_nc_skb_add_to_path(skb, nc_path, neigh_node, packet_id)) | ||
1403 | goto free_nc_path; | ||
1404 | |||
1405 | /* Packet is consumed */ | ||
1406 | return true; | ||
1407 | |||
1408 | free_nc_path: | ||
1409 | batadv_nc_path_free_ref(nc_path); | ||
1410 | out: | ||
1411 | /* Packet is not consumed */ | ||
1412 | return false; | ||
1413 | } | ||
1414 | |||
1415 | /** | ||
1416 | * batadv_nc_skb_store_for_decoding - save a clone of the skb which can be used | ||
1417 | * when decoding coded packets | ||
1418 | * @bat_priv: the bat priv with all the soft interface information | ||
1419 | * @skb: data skb to store | ||
1420 | */ | ||
1421 | void batadv_nc_skb_store_for_decoding(struct batadv_priv *bat_priv, | ||
1422 | struct sk_buff *skb) | ||
1423 | { | ||
1424 | struct batadv_unicast_packet *packet; | ||
1425 | struct batadv_nc_path *nc_path; | ||
1426 | struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb); | ||
1427 | __be32 packet_id; | ||
1428 | u8 *payload; | ||
1429 | |||
1430 | /* Check if network coding is enabled */ | ||
1431 | if (!atomic_read(&bat_priv->network_coding)) | ||
1432 | goto out; | ||
1433 | |||
1434 | /* Check for supported packet type */ | ||
1435 | payload = skb_network_header(skb); | ||
1436 | packet = (struct batadv_unicast_packet *)payload; | ||
1437 | if (packet->header.packet_type != BATADV_UNICAST) | ||
1438 | goto out; | ||
1439 | |||
1440 | /* Find existing nc_path or create a new */ | ||
1441 | nc_path = batadv_nc_get_path(bat_priv, | ||
1442 | bat_priv->nc.decoding_hash, | ||
1443 | ethhdr->h_source, | ||
1444 | ethhdr->h_dest); | ||
1445 | |||
1446 | if (!nc_path) | ||
1447 | goto out; | ||
1448 | |||
1449 | /* Clone skb and adjust skb->data to point at batman header */ | ||
1450 | skb = skb_clone(skb, GFP_ATOMIC); | ||
1451 | if (unlikely(!skb)) | ||
1452 | goto free_nc_path; | ||
1453 | |||
1454 | if (unlikely(!pskb_may_pull(skb, ETH_HLEN))) | ||
1455 | goto free_skb; | ||
1456 | |||
1457 | if (unlikely(!skb_pull_rcsum(skb, ETH_HLEN))) | ||
1458 | goto free_skb; | ||
1459 | |||
1460 | /* Add skb to nc_path */ | ||
1461 | packet_id = batadv_skb_crc32(skb, payload + sizeof(*packet)); | ||
1462 | if (!batadv_nc_skb_add_to_path(skb, nc_path, NULL, packet_id)) | ||
1463 | goto free_skb; | ||
1464 | |||
1465 | batadv_inc_counter(bat_priv, BATADV_CNT_NC_BUFFER); | ||
1466 | return; | ||
1467 | |||
1468 | free_skb: | ||
1469 | kfree_skb(skb); | ||
1470 | free_nc_path: | ||
1471 | batadv_nc_path_free_ref(nc_path); | ||
1472 | out: | ||
1473 | return; | ||
1474 | } | ||
1475 | |||
1476 | /** | ||
1477 | * batadv_nc_skb_store_sniffed_unicast - check if a received unicast packet | ||
1478 | * should be saved in the decoding buffer and, if so, store it there | ||
1479 | * @bat_priv: the bat priv with all the soft interface information | ||
1480 | * @skb: unicast skb to store | ||
1481 | */ | ||
1482 | void batadv_nc_skb_store_sniffed_unicast(struct batadv_priv *bat_priv, | ||
1483 | struct sk_buff *skb) | ||
1484 | { | ||
1485 | struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb); | ||
1486 | |||
1487 | if (batadv_is_my_mac(bat_priv, ethhdr->h_dest)) | ||
1488 | return; | ||
1489 | |||
1490 | /* Set data pointer to MAC header to mimic packets from our tx path */ | ||
1491 | skb_push(skb, ETH_HLEN); | ||
1492 | |||
1493 | batadv_nc_skb_store_for_decoding(bat_priv, skb); | ||
1494 | } | ||
1495 | |||
1496 | /** | ||
1497 | * batadv_nc_skb_decode_packet - decode given skb using the decode data stored | ||
1498 | * in nc_packet | ||
1499 | * @bat_priv: the bat priv with all the soft interface information | ||
1500 | * @skb: unicast skb to decode | ||
1501 | * @nc_packet: decode data needed to decode the skb | ||
1502 | * | ||
1503 | * Returns pointer to decoded unicast packet if the packet was decoded or NULL | ||
1504 | * in case of an error. | ||
1505 | */ | ||
1506 | static struct batadv_unicast_packet * | ||
1507 | batadv_nc_skb_decode_packet(struct batadv_priv *bat_priv, struct sk_buff *skb, | ||
1508 | struct batadv_nc_packet *nc_packet) | ||
1509 | { | ||
1510 | const int h_size = sizeof(struct batadv_unicast_packet); | ||
1511 | const int h_diff = sizeof(struct batadv_coded_packet) - h_size; | ||
1512 | struct batadv_unicast_packet *unicast_packet; | ||
1513 | struct batadv_coded_packet coded_packet_tmp; | ||
1514 | struct ethhdr *ethhdr, ethhdr_tmp; | ||
1515 | uint8_t *orig_dest, ttl, ttvn; | ||
1516 | unsigned int coding_len; | ||
1517 | |||
1518 | /* Save headers temporarily */ | ||
1519 | memcpy(&coded_packet_tmp, skb->data, sizeof(coded_packet_tmp)); | ||
1520 | memcpy(ðhdr_tmp, skb_mac_header(skb), sizeof(ethhdr_tmp)); | ||
1521 | |||
1522 | if (skb_cow(skb, 0) < 0) | ||
1523 | return NULL; | ||
1524 | |||
1525 | if (unlikely(!skb_pull_rcsum(skb, h_diff))) | ||
1526 | return NULL; | ||
1527 | |||
1528 | /* Data points to batman header, so set mac header 14 bytes before | ||
1529 | * and network to data | ||
1530 | */ | ||
1531 | skb_set_mac_header(skb, -ETH_HLEN); | ||
1532 | skb_reset_network_header(skb); | ||
1533 | |||
1534 | /* Reconstruct original mac header */ | ||
1535 | ethhdr = (struct ethhdr *)skb_mac_header(skb); | ||
1536 | memcpy(ethhdr, ðhdr_tmp, sizeof(*ethhdr)); | ||
1537 | |||
1538 | /* Select the correct unicast header information based on the location | ||
1539 | * of our mac address in the coded_packet header | ||
1540 | */ | ||
1541 | if (batadv_is_my_mac(bat_priv, coded_packet_tmp.second_dest)) { | ||
1542 | /* If we are the second destination the packet was overheard, | ||
1543 | * so the Ethernet address must be copied to h_dest and | ||
1544 | * pkt_type changed from PACKET_OTHERHOST to PACKET_HOST | ||
1545 | */ | ||
1546 | memcpy(ethhdr->h_dest, coded_packet_tmp.second_dest, ETH_ALEN); | ||
1547 | skb->pkt_type = PACKET_HOST; | ||
1548 | |||
1549 | orig_dest = coded_packet_tmp.second_orig_dest; | ||
1550 | ttl = coded_packet_tmp.second_ttl; | ||
1551 | ttvn = coded_packet_tmp.second_ttvn; | ||
1552 | } else { | ||
1553 | orig_dest = coded_packet_tmp.first_orig_dest; | ||
1554 | ttl = coded_packet_tmp.header.ttl; | ||
1555 | ttvn = coded_packet_tmp.first_ttvn; | ||
1556 | } | ||
1557 | |||
1558 | coding_len = ntohs(coded_packet_tmp.coded_len); | ||
1559 | |||
1560 | if (coding_len > skb->len) | ||
1561 | return NULL; | ||
1562 | |||
1563 | /* Here the magic is reversed: | ||
1564 | * extract the missing packet from the received coded packet | ||
1565 | */ | ||
1566 | batadv_nc_memxor(skb->data + h_size, | ||
1567 | nc_packet->skb->data + h_size, | ||
1568 | coding_len); | ||
1569 | |||
1570 | /* Resize decoded skb if decoded with larger packet */ | ||
1571 | if (nc_packet->skb->len > coding_len + h_size) | ||
1572 | pskb_trim_rcsum(skb, coding_len + h_size); | ||
1573 | |||
1574 | /* Create decoded unicast packet */ | ||
1575 | unicast_packet = (struct batadv_unicast_packet *)skb->data; | ||
1576 | unicast_packet->header.packet_type = BATADV_UNICAST; | ||
1577 | unicast_packet->header.version = BATADV_COMPAT_VERSION; | ||
1578 | unicast_packet->header.ttl = ttl; | ||
1579 | memcpy(unicast_packet->dest, orig_dest, ETH_ALEN); | ||
1580 | unicast_packet->ttvn = ttvn; | ||
1581 | |||
1582 | batadv_nc_packet_free(nc_packet); | ||
1583 | return unicast_packet; | ||
1584 | } | ||
1585 | |||
1586 | /** | ||
1587 | * batadv_nc_find_decoding_packet - search through buffered decoding data to | ||
1588 | * find the data needed to decode the coded packet | ||
1589 | * @bat_priv: the bat priv with all the soft interface information | ||
1590 | * @ethhdr: pointer to the ethernet header inside the coded packet | ||
1591 | * @coded: coded packet we try to find decode data for | ||
1592 | * | ||
1593 | * Returns pointer to nc packet if the needed data was found or NULL otherwise. | ||
1594 | */ | ||
1595 | static struct batadv_nc_packet * | ||
1596 | batadv_nc_find_decoding_packet(struct batadv_priv *bat_priv, | ||
1597 | struct ethhdr *ethhdr, | ||
1598 | struct batadv_coded_packet *coded) | ||
1599 | { | ||
1600 | struct batadv_hashtable *hash = bat_priv->nc.decoding_hash; | ||
1601 | struct batadv_nc_packet *tmp_nc_packet, *nc_packet = NULL; | ||
1602 | struct batadv_nc_path *nc_path, nc_path_key; | ||
1603 | uint8_t *dest, *source; | ||
1604 | __be32 packet_id; | ||
1605 | int index; | ||
1606 | |||
1607 | if (!hash) | ||
1608 | return NULL; | ||
1609 | |||
1610 | /* Select the correct packet id based on the location of our mac-addr */ | ||
1611 | dest = ethhdr->h_source; | ||
1612 | if (!batadv_is_my_mac(bat_priv, coded->second_dest)) { | ||
1613 | source = coded->second_source; | ||
1614 | packet_id = coded->second_crc; | ||
1615 | } else { | ||
1616 | source = coded->first_source; | ||
1617 | packet_id = coded->first_crc; | ||
1618 | } | ||
1619 | |||
1620 | batadv_nc_hash_key_gen(&nc_path_key, source, dest); | ||
1621 | index = batadv_nc_hash_choose(&nc_path_key, hash->size); | ||
1622 | |||
1623 | /* Search for matching coding path */ | ||
1624 | rcu_read_lock(); | ||
1625 | hlist_for_each_entry_rcu(nc_path, &hash->table[index], hash_entry) { | ||
1626 | /* Find matching nc_packet */ | ||
1627 | spin_lock_bh(&nc_path->packet_list_lock); | ||
1628 | list_for_each_entry(tmp_nc_packet, | ||
1629 | &nc_path->packet_list, list) { | ||
1630 | if (packet_id == tmp_nc_packet->packet_id) { | ||
1631 | list_del(&tmp_nc_packet->list); | ||
1632 | |||
1633 | nc_packet = tmp_nc_packet; | ||
1634 | break; | ||
1635 | } | ||
1636 | } | ||
1637 | spin_unlock_bh(&nc_path->packet_list_lock); | ||
1638 | |||
1639 | if (nc_packet) | ||
1640 | break; | ||
1641 | } | ||
1642 | rcu_read_unlock(); | ||
1643 | |||
1644 | if (!nc_packet) | ||
1645 | batadv_dbg(BATADV_DBG_NC, bat_priv, | ||
1646 | "No decoding packet found for %u\n", packet_id); | ||
1647 | |||
1648 | return nc_packet; | ||
1649 | } | ||
1650 | |||
1651 | /** | ||
1652 | * batadv_nc_recv_coded_packet - try to decode coded packet and enqueue the | ||
1653 | * resulting unicast packet | ||
1654 | * @skb: incoming coded packet | ||
1655 | * @recv_if: pointer to interface this packet was received on | ||
1656 | */ | ||
1657 | static int batadv_nc_recv_coded_packet(struct sk_buff *skb, | ||
1658 | struct batadv_hard_iface *recv_if) | ||
1659 | { | ||
1660 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); | ||
1661 | struct batadv_unicast_packet *unicast_packet; | ||
1662 | struct batadv_coded_packet *coded_packet; | ||
1663 | struct batadv_nc_packet *nc_packet; | ||
1664 | struct ethhdr *ethhdr; | ||
1665 | int hdr_size = sizeof(*coded_packet); | ||
1666 | |||
1667 | /* Check if network coding is enabled */ | ||
1668 | if (!atomic_read(&bat_priv->network_coding)) | ||
1669 | return NET_RX_DROP; | ||
1670 | |||
1671 | /* Make sure we can access (and remove) header */ | ||
1672 | if (unlikely(!pskb_may_pull(skb, hdr_size))) | ||
1673 | return NET_RX_DROP; | ||
1674 | |||
1675 | coded_packet = (struct batadv_coded_packet *)skb->data; | ||
1676 | ethhdr = (struct ethhdr *)skb_mac_header(skb); | ||
1677 | |||
1678 | /* Verify frame is destined for us */ | ||
1679 | if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest) && | ||
1680 | !batadv_is_my_mac(bat_priv, coded_packet->second_dest)) | ||
1681 | return NET_RX_DROP; | ||
1682 | |||
1683 | /* Update stat counter */ | ||
1684 | if (batadv_is_my_mac(bat_priv, coded_packet->second_dest)) | ||
1685 | batadv_inc_counter(bat_priv, BATADV_CNT_NC_SNIFFED); | ||
1686 | |||
1687 | nc_packet = batadv_nc_find_decoding_packet(bat_priv, ethhdr, | ||
1688 | coded_packet); | ||
1689 | if (!nc_packet) { | ||
1690 | batadv_inc_counter(bat_priv, BATADV_CNT_NC_DECODE_FAILED); | ||
1691 | return NET_RX_DROP; | ||
1692 | } | ||
1693 | |||
1694 | /* Make skb's linear, because decoding accesses the entire buffer */ | ||
1695 | if (skb_linearize(skb) < 0) | ||
1696 | goto free_nc_packet; | ||
1697 | |||
1698 | if (skb_linearize(nc_packet->skb) < 0) | ||
1699 | goto free_nc_packet; | ||
1700 | |||
1701 | /* Decode the packet */ | ||
1702 | unicast_packet = batadv_nc_skb_decode_packet(bat_priv, skb, nc_packet); | ||
1703 | if (!unicast_packet) { | ||
1704 | batadv_inc_counter(bat_priv, BATADV_CNT_NC_DECODE_FAILED); | ||
1705 | goto free_nc_packet; | ||
1706 | } | ||
1707 | |||
1708 | /* Mark packet as decoded to do correct recoding when forwarding */ | ||
1709 | BATADV_SKB_CB(skb)->decoded = true; | ||
1710 | batadv_inc_counter(bat_priv, BATADV_CNT_NC_DECODE); | ||
1711 | batadv_add_counter(bat_priv, BATADV_CNT_NC_DECODE_BYTES, | ||
1712 | skb->len + ETH_HLEN); | ||
1713 | return batadv_recv_unicast_packet(skb, recv_if); | ||
1714 | |||
1715 | free_nc_packet: | ||
1716 | batadv_nc_packet_free(nc_packet); | ||
1717 | return NET_RX_DROP; | ||
1718 | } | ||
1719 | |||
1720 | /** | ||
1721 | * batadv_nc_free - clean up network coding memory | ||
1722 | * @bat_priv: the bat priv with all the soft interface information | ||
1723 | */ | ||
1724 | void batadv_nc_free(struct batadv_priv *bat_priv) | ||
1725 | { | ||
1726 | batadv_recv_handler_unregister(BATADV_CODED); | ||
1727 | cancel_delayed_work_sync(&bat_priv->nc.work); | ||
1728 | |||
1729 | batadv_nc_purge_paths(bat_priv, bat_priv->nc.coding_hash, NULL); | ||
1730 | batadv_hash_destroy(bat_priv->nc.coding_hash); | ||
1731 | batadv_nc_purge_paths(bat_priv, bat_priv->nc.decoding_hash, NULL); | ||
1732 | batadv_hash_destroy(bat_priv->nc.decoding_hash); | ||
1733 | } | ||
1734 | |||
1735 | /** | ||
1736 | * batadv_nc_nodes_seq_print_text - print the nc node information | ||
1737 | * @seq: seq file to print on | ||
1738 | * @offset: not used | ||
1739 | */ | ||
1740 | int batadv_nc_nodes_seq_print_text(struct seq_file *seq, void *offset) | ||
1741 | { | ||
1742 | struct net_device *net_dev = (struct net_device *)seq->private; | ||
1743 | struct batadv_priv *bat_priv = netdev_priv(net_dev); | ||
1744 | struct batadv_hashtable *hash = bat_priv->orig_hash; | ||
1745 | struct batadv_hard_iface *primary_if; | ||
1746 | struct hlist_head *head; | ||
1747 | struct batadv_orig_node *orig_node; | ||
1748 | struct batadv_nc_node *nc_node; | ||
1749 | int i; | ||
1750 | |||
1751 | primary_if = batadv_seq_print_text_primary_if_get(seq); | ||
1752 | if (!primary_if) | ||
1753 | goto out; | ||
1754 | |||
1755 | /* Traverse list of originators */ | ||
1756 | for (i = 0; i < hash->size; i++) { | ||
1757 | head = &hash->table[i]; | ||
1758 | |||
1759 | /* For each orig_node in this bin */ | ||
1760 | rcu_read_lock(); | ||
1761 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { | ||
1762 | seq_printf(seq, "Node: %pM\n", orig_node->orig); | ||
1763 | |||
1764 | seq_puts(seq, " Ingoing: "); | ||
1765 | /* For each in_nc_node to this orig_node */ | ||
1766 | list_for_each_entry_rcu(nc_node, | ||
1767 | &orig_node->in_coding_list, | ||
1768 | list) | ||
1769 | seq_printf(seq, "%pM ", | ||
1770 | nc_node->addr); | ||
1771 | seq_puts(seq, "\n"); | ||
1772 | |||
1773 | seq_puts(seq, " Outgoing: "); | ||
1774 | /* For out_nc_node to this orig_node */ | ||
1775 | list_for_each_entry_rcu(nc_node, | ||
1776 | &orig_node->out_coding_list, | ||
1777 | list) | ||
1778 | seq_printf(seq, "%pM ", | ||
1779 | nc_node->addr); | ||
1780 | seq_puts(seq, "\n\n"); | ||
1781 | } | ||
1782 | rcu_read_unlock(); | ||
1783 | } | ||
1784 | |||
1785 | out: | ||
1786 | if (primary_if) | ||
1787 | batadv_hardif_free_ref(primary_if); | ||
1788 | return 0; | ||
1789 | } | ||
1790 | |||
1791 | /** | ||
1792 | * batadv_nc_init_debugfs - create nc folder and related files in debugfs | ||
1793 | * @bat_priv: the bat priv with all the soft interface information | ||
1794 | */ | ||
1795 | int batadv_nc_init_debugfs(struct batadv_priv *bat_priv) | ||
1796 | { | ||
1797 | struct dentry *nc_dir, *file; | ||
1798 | |||
1799 | nc_dir = debugfs_create_dir("nc", bat_priv->debug_dir); | ||
1800 | if (!nc_dir) | ||
1801 | goto out; | ||
1802 | |||
1803 | file = debugfs_create_u8("min_tq", S_IRUGO | S_IWUSR, nc_dir, | ||
1804 | &bat_priv->nc.min_tq); | ||
1805 | if (!file) | ||
1806 | goto out; | ||
1807 | |||
1808 | file = debugfs_create_u32("max_fwd_delay", S_IRUGO | S_IWUSR, nc_dir, | ||
1809 | &bat_priv->nc.max_fwd_delay); | ||
1810 | if (!file) | ||
1811 | goto out; | ||
1812 | |||
1813 | file = debugfs_create_u32("max_buffer_time", S_IRUGO | S_IWUSR, nc_dir, | ||
1814 | &bat_priv->nc.max_buffer_time); | ||
1815 | if (!file) | ||
1816 | goto out; | ||
1817 | |||
1818 | return 0; | ||
1819 | |||
1820 | out: | ||
1821 | return -ENOMEM; | ||
1822 | } | ||
diff --git a/net/batman-adv/network-coding.h b/net/batman-adv/network-coding.h new file mode 100644 index 000000000000..4fa6d0caddbd --- /dev/null +++ b/net/batman-adv/network-coding.h | |||
@@ -0,0 +1,123 @@ | |||
1 | /* Copyright (C) 2012-2013 B.A.T.M.A.N. contributors: | ||
2 | * | ||
3 | * Martin Hundebøll, Jeppe Ledet-Pedersen | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of version 2 of the GNU General Public | ||
7 | * License as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but | ||
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | * 02110-1301, USA | ||
18 | */ | ||
19 | |||
20 | #ifndef _NET_BATMAN_ADV_NETWORK_CODING_H_ | ||
21 | #define _NET_BATMAN_ADV_NETWORK_CODING_H_ | ||
22 | |||
23 | #ifdef CONFIG_BATMAN_ADV_NC | ||
24 | |||
25 | int batadv_nc_init(struct batadv_priv *bat_priv); | ||
26 | void batadv_nc_free(struct batadv_priv *bat_priv); | ||
27 | void batadv_nc_update_nc_node(struct batadv_priv *bat_priv, | ||
28 | struct batadv_orig_node *orig_node, | ||
29 | struct batadv_orig_node *orig_neigh_node, | ||
30 | struct batadv_ogm_packet *ogm_packet, | ||
31 | int is_single_hop_neigh); | ||
32 | void batadv_nc_purge_orig(struct batadv_priv *bat_priv, | ||
33 | struct batadv_orig_node *orig_node, | ||
34 | bool (*to_purge)(struct batadv_priv *, | ||
35 | struct batadv_nc_node *)); | ||
36 | void batadv_nc_init_bat_priv(struct batadv_priv *bat_priv); | ||
37 | void batadv_nc_init_orig(struct batadv_orig_node *orig_node); | ||
38 | bool batadv_nc_skb_forward(struct sk_buff *skb, | ||
39 | struct batadv_neigh_node *neigh_node, | ||
40 | struct ethhdr *ethhdr); | ||
41 | void batadv_nc_skb_store_for_decoding(struct batadv_priv *bat_priv, | ||
42 | struct sk_buff *skb); | ||
43 | void batadv_nc_skb_store_sniffed_unicast(struct batadv_priv *bat_priv, | ||
44 | struct sk_buff *skb); | ||
45 | int batadv_nc_nodes_seq_print_text(struct seq_file *seq, void *offset); | ||
46 | int batadv_nc_init_debugfs(struct batadv_priv *bat_priv); | ||
47 | |||
48 | #else /* ifdef CONFIG_BATMAN_ADV_NC */ | ||
49 | |||
50 | static inline int batadv_nc_init(struct batadv_priv *bat_priv) | ||
51 | { | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | static inline void batadv_nc_free(struct batadv_priv *bat_priv) | ||
56 | { | ||
57 | return; | ||
58 | } | ||
59 | |||
60 | static inline void | ||
61 | batadv_nc_update_nc_node(struct batadv_priv *bat_priv, | ||
62 | struct batadv_orig_node *orig_node, | ||
63 | struct batadv_orig_node *orig_neigh_node, | ||
64 | struct batadv_ogm_packet *ogm_packet, | ||
65 | int is_single_hop_neigh) | ||
66 | { | ||
67 | return; | ||
68 | } | ||
69 | |||
70 | static inline void | ||
71 | batadv_nc_purge_orig(struct batadv_priv *bat_priv, | ||
72 | struct batadv_orig_node *orig_node, | ||
73 | bool (*to_purge)(struct batadv_priv *, | ||
74 | struct batadv_nc_node *)) | ||
75 | { | ||
76 | return; | ||
77 | } | ||
78 | |||
79 | static inline void batadv_nc_init_bat_priv(struct batadv_priv *bat_priv) | ||
80 | { | ||
81 | return; | ||
82 | } | ||
83 | |||
84 | static inline void batadv_nc_init_orig(struct batadv_orig_node *orig_node) | ||
85 | { | ||
86 | return; | ||
87 | } | ||
88 | |||
89 | static inline bool batadv_nc_skb_forward(struct sk_buff *skb, | ||
90 | struct batadv_neigh_node *neigh_node, | ||
91 | struct ethhdr *ethhdr) | ||
92 | { | ||
93 | return false; | ||
94 | } | ||
95 | |||
96 | static inline void | ||
97 | batadv_nc_skb_store_for_decoding(struct batadv_priv *bat_priv, | ||
98 | struct sk_buff *skb) | ||
99 | { | ||
100 | return; | ||
101 | } | ||
102 | |||
103 | static inline void | ||
104 | batadv_nc_skb_store_sniffed_unicast(struct batadv_priv *bat_priv, | ||
105 | struct sk_buff *skb) | ||
106 | { | ||
107 | return; | ||
108 | } | ||
109 | |||
110 | static inline int batadv_nc_nodes_seq_print_text(struct seq_file *seq, | ||
111 | void *offset) | ||
112 | { | ||
113 | return 0; | ||
114 | } | ||
115 | |||
116 | static inline int batadv_nc_init_debugfs(struct batadv_priv *bat_priv) | ||
117 | { | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | #endif /* ifdef CONFIG_BATMAN_ADV_NC */ | ||
122 | |||
123 | #endif /* _NET_BATMAN_ADV_NETWORK_CODING_H_ */ | ||
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index 96fb80b724dc..2f3452546636 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "unicast.h" | 28 | #include "unicast.h" |
29 | #include "soft-interface.h" | 29 | #include "soft-interface.h" |
30 | #include "bridge_loop_avoidance.h" | 30 | #include "bridge_loop_avoidance.h" |
31 | #include "network-coding.h" | ||
31 | 32 | ||
32 | /* hash class keys */ | 33 | /* hash class keys */ |
33 | static struct lock_class_key batadv_orig_hash_lock_class_key; | 34 | static struct lock_class_key batadv_orig_hash_lock_class_key; |
@@ -142,6 +143,9 @@ static void batadv_orig_node_free_rcu(struct rcu_head *rcu) | |||
142 | 143 | ||
143 | spin_unlock_bh(&orig_node->neigh_list_lock); | 144 | spin_unlock_bh(&orig_node->neigh_list_lock); |
144 | 145 | ||
146 | /* Free nc_nodes */ | ||
147 | batadv_nc_purge_orig(orig_node->bat_priv, orig_node, NULL); | ||
148 | |||
145 | batadv_frag_list_free(&orig_node->frag_list); | 149 | batadv_frag_list_free(&orig_node->frag_list); |
146 | batadv_tt_global_del_orig(orig_node->bat_priv, orig_node, | 150 | batadv_tt_global_del_orig(orig_node->bat_priv, orig_node, |
147 | "originator timed out"); | 151 | "originator timed out"); |
@@ -219,6 +223,8 @@ struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv, | |||
219 | spin_lock_init(&orig_node->neigh_list_lock); | 223 | spin_lock_init(&orig_node->neigh_list_lock); |
220 | spin_lock_init(&orig_node->tt_buff_lock); | 224 | spin_lock_init(&orig_node->tt_buff_lock); |
221 | 225 | ||
226 | batadv_nc_init_orig(orig_node); | ||
227 | |||
222 | /* extra reference for return */ | 228 | /* extra reference for return */ |
223 | atomic_set(&orig_node->refcount, 2); | 229 | atomic_set(&orig_node->refcount, 2); |
224 | 230 | ||
@@ -459,7 +465,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset) | |||
459 | neigh_node_tmp->tq_avg); | 465 | neigh_node_tmp->tq_avg); |
460 | } | 466 | } |
461 | 467 | ||
462 | seq_printf(seq, "\n"); | 468 | seq_puts(seq, "\n"); |
463 | batman_count++; | 469 | batman_count++; |
464 | 470 | ||
465 | next: | 471 | next: |
@@ -469,7 +475,7 @@ next: | |||
469 | } | 475 | } |
470 | 476 | ||
471 | if (batman_count == 0) | 477 | if (batman_count == 0) |
472 | seq_printf(seq, "No batman nodes in range ...\n"); | 478 | seq_puts(seq, "No batman nodes in range ...\n"); |
473 | 479 | ||
474 | out: | 480 | out: |
475 | if (primary_if) | 481 | if (primary_if) |
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h index ed0aa89bbf8b..a51ccfc39da4 100644 --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h | |||
@@ -30,6 +30,7 @@ enum batadv_packettype { | |||
30 | BATADV_TT_QUERY = 0x07, | 30 | BATADV_TT_QUERY = 0x07, |
31 | BATADV_ROAM_ADV = 0x08, | 31 | BATADV_ROAM_ADV = 0x08, |
32 | BATADV_UNICAST_4ADDR = 0x09, | 32 | BATADV_UNICAST_4ADDR = 0x09, |
33 | BATADV_CODED = 0x0a, | ||
33 | }; | 34 | }; |
34 | 35 | ||
35 | /** | 36 | /** |
@@ -278,4 +279,36 @@ struct batadv_tt_change { | |||
278 | uint8_t addr[ETH_ALEN]; | 279 | uint8_t addr[ETH_ALEN]; |
279 | } __packed; | 280 | } __packed; |
280 | 281 | ||
282 | /** | ||
283 | * struct batadv_coded_packet - network coded packet | ||
284 | * @header: common batman packet header and ttl of first included packet | ||
285 | * @reserved: Align following fields to 2-byte boundaries | ||
286 | * @first_source: original source of first included packet | ||
287 | * @first_orig_dest: original destinal of first included packet | ||
288 | * @first_crc: checksum of first included packet | ||
289 | * @first_ttvn: tt-version number of first included packet | ||
290 | * @second_ttl: ttl of second packet | ||
291 | * @second_dest: second receiver of this coded packet | ||
292 | * @second_source: original source of second included packet | ||
293 | * @second_orig_dest: original destination of second included packet | ||
294 | * @second_crc: checksum of second included packet | ||
295 | * @second_ttvn: tt version number of second included packet | ||
296 | * @coded_len: length of network coded part of the payload | ||
297 | */ | ||
298 | struct batadv_coded_packet { | ||
299 | struct batadv_header header; | ||
300 | uint8_t first_ttvn; | ||
301 | /* uint8_t first_dest[ETH_ALEN]; - saved in mac header destination */ | ||
302 | uint8_t first_source[ETH_ALEN]; | ||
303 | uint8_t first_orig_dest[ETH_ALEN]; | ||
304 | __be32 first_crc; | ||
305 | uint8_t second_ttl; | ||
306 | uint8_t second_ttvn; | ||
307 | uint8_t second_dest[ETH_ALEN]; | ||
308 | uint8_t second_source[ETH_ALEN]; | ||
309 | uint8_t second_orig_dest[ETH_ALEN]; | ||
310 | __be32 second_crc; | ||
311 | __be16 coded_len; | ||
312 | }; | ||
313 | |||
281 | #endif /* _NET_BATMAN_ADV_PACKET_H_ */ | 314 | #endif /* _NET_BATMAN_ADV_PACKET_H_ */ |
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 7de033667ebc..b27a4d792d15 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "unicast.h" | 29 | #include "unicast.h" |
30 | #include "bridge_loop_avoidance.h" | 30 | #include "bridge_loop_avoidance.h" |
31 | #include "distributed-arp-table.h" | 31 | #include "distributed-arp-table.h" |
32 | #include "network-coding.h" | ||
32 | 33 | ||
33 | static int batadv_route_unicast_packet(struct sk_buff *skb, | 34 | static int batadv_route_unicast_packet(struct sk_buff *skb, |
34 | struct batadv_hard_iface *recv_if); | 35 | struct batadv_hard_iface *recv_if); |
@@ -548,6 +549,17 @@ batadv_find_ifalter_router(struct batadv_orig_node *primary_orig, | |||
548 | return router; | 549 | return router; |
549 | } | 550 | } |
550 | 551 | ||
552 | /** | ||
553 | * batadv_check_unicast_packet - Check for malformed unicast packets | ||
554 | * @bat_priv: the bat priv with all the soft interface information | ||
555 | * @skb: packet to check | ||
556 | * @hdr_size: size of header to pull | ||
557 | * | ||
558 | * Check for short header and bad addresses in given packet. Returns negative | ||
559 | * value when check fails and 0 otherwise. The negative value depends on the | ||
560 | * reason: -ENODATA for bad header, -EBADR for broadcast destination or source, | ||
561 | * and -EREMOTE for non-local (other host) destination. | ||
562 | */ | ||
551 | static int batadv_check_unicast_packet(struct batadv_priv *bat_priv, | 563 | static int batadv_check_unicast_packet(struct batadv_priv *bat_priv, |
552 | struct sk_buff *skb, int hdr_size) | 564 | struct sk_buff *skb, int hdr_size) |
553 | { | 565 | { |
@@ -555,21 +567,21 @@ static int batadv_check_unicast_packet(struct batadv_priv *bat_priv, | |||
555 | 567 | ||
556 | /* drop packet if it has not necessary minimum size */ | 568 | /* drop packet if it has not necessary minimum size */ |
557 | if (unlikely(!pskb_may_pull(skb, hdr_size))) | 569 | if (unlikely(!pskb_may_pull(skb, hdr_size))) |
558 | return -1; | 570 | return -ENODATA; |
559 | 571 | ||
560 | ethhdr = (struct ethhdr *)skb_mac_header(skb); | 572 | ethhdr = (struct ethhdr *)skb_mac_header(skb); |
561 | 573 | ||
562 | /* packet with unicast indication but broadcast recipient */ | 574 | /* packet with unicast indication but broadcast recipient */ |
563 | if (is_broadcast_ether_addr(ethhdr->h_dest)) | 575 | if (is_broadcast_ether_addr(ethhdr->h_dest)) |
564 | return -1; | 576 | return -EBADR; |
565 | 577 | ||
566 | /* packet with broadcast sender address */ | 578 | /* packet with broadcast sender address */ |
567 | if (is_broadcast_ether_addr(ethhdr->h_source)) | 579 | if (is_broadcast_ether_addr(ethhdr->h_source)) |
568 | return -1; | 580 | return -EBADR; |
569 | 581 | ||
570 | /* not for me */ | 582 | /* not for me */ |
571 | if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest)) | 583 | if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest)) |
572 | return -1; | 584 | return -EREMOTE; |
573 | 585 | ||
574 | return 0; | 586 | return 0; |
575 | } | 587 | } |
@@ -852,15 +864,18 @@ static int batadv_route_unicast_packet(struct sk_buff *skb, | |||
852 | /* decrement ttl */ | 864 | /* decrement ttl */ |
853 | unicast_packet->header.ttl--; | 865 | unicast_packet->header.ttl--; |
854 | 866 | ||
855 | /* Update stats counter */ | 867 | /* network code packet if possible */ |
856 | batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD); | 868 | if (batadv_nc_skb_forward(skb, neigh_node, ethhdr)) { |
857 | batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES, | 869 | ret = NET_RX_SUCCESS; |
858 | skb->len + ETH_HLEN); | 870 | } else if (batadv_send_skb_to_orig(skb, orig_node, recv_if)) { |
859 | |||
860 | /* route it */ | ||
861 | if (batadv_send_skb_to_orig(skb, orig_node, recv_if)) | ||
862 | ret = NET_RX_SUCCESS; | 871 | ret = NET_RX_SUCCESS; |
863 | 872 | ||
873 | /* Update stats counter */ | ||
874 | batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD); | ||
875 | batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES, | ||
876 | skb->len + ETH_HLEN); | ||
877 | } | ||
878 | |||
864 | out: | 879 | out: |
865 | if (neigh_node) | 880 | if (neigh_node) |
866 | batadv_neigh_node_free_ref(neigh_node); | 881 | batadv_neigh_node_free_ref(neigh_node); |
@@ -1035,7 +1050,7 @@ int batadv_recv_unicast_packet(struct sk_buff *skb, | |||
1035 | struct batadv_unicast_4addr_packet *unicast_4addr_packet; | 1050 | struct batadv_unicast_4addr_packet *unicast_4addr_packet; |
1036 | uint8_t *orig_addr; | 1051 | uint8_t *orig_addr; |
1037 | struct batadv_orig_node *orig_node = NULL; | 1052 | struct batadv_orig_node *orig_node = NULL; |
1038 | int hdr_size = sizeof(*unicast_packet); | 1053 | int check, hdr_size = sizeof(*unicast_packet); |
1039 | bool is4addr; | 1054 | bool is4addr; |
1040 | 1055 | ||
1041 | unicast_packet = (struct batadv_unicast_packet *)skb->data; | 1056 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
@@ -1046,7 +1061,16 @@ int batadv_recv_unicast_packet(struct sk_buff *skb, | |||
1046 | if (is4addr) | 1061 | if (is4addr) |
1047 | hdr_size = sizeof(*unicast_4addr_packet); | 1062 | hdr_size = sizeof(*unicast_4addr_packet); |
1048 | 1063 | ||
1049 | if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0) | 1064 | /* function returns -EREMOTE for promiscuous packets */ |
1065 | check = batadv_check_unicast_packet(bat_priv, skb, hdr_size); | ||
1066 | |||
1067 | /* Even though the packet is not for us, we might save it to use for | ||
1068 | * decoding a later received coded packet | ||
1069 | */ | ||
1070 | if (check == -EREMOTE) | ||
1071 | batadv_nc_skb_store_sniffed_unicast(bat_priv, skb); | ||
1072 | |||
1073 | if (check < 0) | ||
1050 | return NET_RX_DROP; | 1074 | return NET_RX_DROP; |
1051 | if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size)) | 1075 | if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size)) |
1052 | return NET_RX_DROP; | 1076 | return NET_RX_DROP; |
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c index a67cffde37ae..263cfd1ccee7 100644 --- a/net/batman-adv/send.c +++ b/net/batman-adv/send.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "vis.h" | 27 | #include "vis.h" |
28 | #include "gateway_common.h" | 28 | #include "gateway_common.h" |
29 | #include "originator.h" | 29 | #include "originator.h" |
30 | #include "network-coding.h" | ||
30 | 31 | ||
31 | #include <linux/if_ether.h> | 32 | #include <linux/if_ether.h> |
32 | 33 | ||
@@ -39,6 +40,7 @@ int batadv_send_skb_packet(struct sk_buff *skb, | |||
39 | struct batadv_hard_iface *hard_iface, | 40 | struct batadv_hard_iface *hard_iface, |
40 | const uint8_t *dst_addr) | 41 | const uint8_t *dst_addr) |
41 | { | 42 | { |
43 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); | ||
42 | struct ethhdr *ethhdr; | 44 | struct ethhdr *ethhdr; |
43 | 45 | ||
44 | if (hard_iface->if_status != BATADV_IF_ACTIVE) | 46 | if (hard_iface->if_status != BATADV_IF_ACTIVE) |
@@ -70,6 +72,9 @@ int batadv_send_skb_packet(struct sk_buff *skb, | |||
70 | 72 | ||
71 | skb->dev = hard_iface->net_dev; | 73 | skb->dev = hard_iface->net_dev; |
72 | 74 | ||
75 | /* Save a clone of the skb to use when decoding coded packets */ | ||
76 | batadv_nc_skb_store_for_decoding(bat_priv, skb); | ||
77 | |||
73 | /* dev_queue_xmit() returns a negative result on error. However on | 78 | /* dev_queue_xmit() returns a negative result on error. However on |
74 | * congestion and traffic shaping, it drops and returns NET_XMIT_DROP | 79 | * congestion and traffic shaping, it drops and returns NET_XMIT_DROP |
75 | * (which is > 0). This will not be treated as an error. | 80 | * (which is > 0). This will not be treated as an error. |
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c index 2711e870f557..6f20d339e33a 100644 --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/if_ether.h> | 37 | #include <linux/if_ether.h> |
38 | #include "unicast.h" | 38 | #include "unicast.h" |
39 | #include "bridge_loop_avoidance.h" | 39 | #include "bridge_loop_avoidance.h" |
40 | #include "network-coding.h" | ||
40 | 41 | ||
41 | 42 | ||
42 | static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd); | 43 | static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd); |
@@ -401,55 +402,6 @@ static void batadv_set_lockdep_class(struct net_device *dev) | |||
401 | } | 402 | } |
402 | 403 | ||
403 | /** | 404 | /** |
404 | * batadv_softif_init - Late stage initialization of soft interface | ||
405 | * @dev: registered network device to modify | ||
406 | * | ||
407 | * Returns error code on failures | ||
408 | */ | ||
409 | static int batadv_softif_init(struct net_device *dev) | ||
410 | { | ||
411 | batadv_set_lockdep_class(dev); | ||
412 | |||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | static const struct net_device_ops batadv_netdev_ops = { | ||
417 | .ndo_init = batadv_softif_init, | ||
418 | .ndo_open = batadv_interface_open, | ||
419 | .ndo_stop = batadv_interface_release, | ||
420 | .ndo_get_stats = batadv_interface_stats, | ||
421 | .ndo_set_mac_address = batadv_interface_set_mac_addr, | ||
422 | .ndo_change_mtu = batadv_interface_change_mtu, | ||
423 | .ndo_start_xmit = batadv_interface_tx, | ||
424 | .ndo_validate_addr = eth_validate_addr | ||
425 | }; | ||
426 | |||
427 | static void batadv_interface_setup(struct net_device *dev) | ||
428 | { | ||
429 | struct batadv_priv *priv = netdev_priv(dev); | ||
430 | |||
431 | ether_setup(dev); | ||
432 | |||
433 | dev->netdev_ops = &batadv_netdev_ops; | ||
434 | dev->destructor = free_netdev; | ||
435 | dev->tx_queue_len = 0; | ||
436 | |||
437 | /* can't call min_mtu, because the needed variables | ||
438 | * have not been initialized yet | ||
439 | */ | ||
440 | dev->mtu = ETH_DATA_LEN; | ||
441 | /* reserve more space in the skbuff for our header */ | ||
442 | dev->hard_header_len = BATADV_HEADER_LEN; | ||
443 | |||
444 | /* generate random address */ | ||
445 | eth_hw_addr_random(dev); | ||
446 | |||
447 | SET_ETHTOOL_OPS(dev, &batadv_ethtool_ops); | ||
448 | |||
449 | memset(priv, 0, sizeof(*priv)); | ||
450 | } | ||
451 | |||
452 | /** | ||
453 | * batadv_softif_destroy_finish - cleans up the remains of a softif | 405 | * batadv_softif_destroy_finish - cleans up the remains of a softif |
454 | * @work: work queue item | 406 | * @work: work queue item |
455 | * | 407 | * |
@@ -465,7 +417,6 @@ static void batadv_softif_destroy_finish(struct work_struct *work) | |||
465 | cleanup_work); | 417 | cleanup_work); |
466 | soft_iface = bat_priv->soft_iface; | 418 | soft_iface = bat_priv->soft_iface; |
467 | 419 | ||
468 | batadv_debugfs_del_meshif(soft_iface); | ||
469 | batadv_sysfs_del_meshif(soft_iface); | 420 | batadv_sysfs_del_meshif(soft_iface); |
470 | 421 | ||
471 | rtnl_lock(); | 422 | rtnl_lock(); |
@@ -473,21 +424,22 @@ static void batadv_softif_destroy_finish(struct work_struct *work) | |||
473 | rtnl_unlock(); | 424 | rtnl_unlock(); |
474 | } | 425 | } |
475 | 426 | ||
476 | struct net_device *batadv_softif_create(const char *name) | 427 | /** |
428 | * batadv_softif_init_late - late stage initialization of soft interface | ||
429 | * @dev: registered network device to modify | ||
430 | * | ||
431 | * Returns error code on failures | ||
432 | */ | ||
433 | static int batadv_softif_init_late(struct net_device *dev) | ||
477 | { | 434 | { |
478 | struct net_device *soft_iface; | ||
479 | struct batadv_priv *bat_priv; | 435 | struct batadv_priv *bat_priv; |
480 | int ret; | 436 | int ret; |
481 | size_t cnt_len = sizeof(uint64_t) * BATADV_CNT_NUM; | 437 | size_t cnt_len = sizeof(uint64_t) * BATADV_CNT_NUM; |
482 | 438 | ||
483 | soft_iface = alloc_netdev(sizeof(*bat_priv), name, | 439 | batadv_set_lockdep_class(dev); |
484 | batadv_interface_setup); | ||
485 | |||
486 | if (!soft_iface) | ||
487 | goto out; | ||
488 | 440 | ||
489 | bat_priv = netdev_priv(soft_iface); | 441 | bat_priv = netdev_priv(dev); |
490 | bat_priv->soft_iface = soft_iface; | 442 | bat_priv->soft_iface = dev; |
491 | INIT_WORK(&bat_priv->cleanup_work, batadv_softif_destroy_finish); | 443 | INIT_WORK(&bat_priv->cleanup_work, batadv_softif_destroy_finish); |
492 | 444 | ||
493 | /* batadv_interface_stats() needs to be available as soon as | 445 | /* batadv_interface_stats() needs to be available as soon as |
@@ -495,14 +447,7 @@ struct net_device *batadv_softif_create(const char *name) | |||
495 | */ | 447 | */ |
496 | bat_priv->bat_counters = __alloc_percpu(cnt_len, __alignof__(uint64_t)); | 448 | bat_priv->bat_counters = __alloc_percpu(cnt_len, __alignof__(uint64_t)); |
497 | if (!bat_priv->bat_counters) | 449 | if (!bat_priv->bat_counters) |
498 | goto free_soft_iface; | 450 | return -ENOMEM; |
499 | |||
500 | ret = register_netdevice(soft_iface); | ||
501 | if (ret < 0) { | ||
502 | pr_err("Unable to register the batman interface '%s': %i\n", | ||
503 | name, ret); | ||
504 | goto free_bat_counters; | ||
505 | } | ||
506 | 451 | ||
507 | atomic_set(&bat_priv->aggregated_ogms, 1); | 452 | atomic_set(&bat_priv->aggregated_ogms, 1); |
508 | atomic_set(&bat_priv->bonding, 0); | 453 | atomic_set(&bat_priv->bonding, 0); |
@@ -540,49 +485,196 @@ struct net_device *batadv_softif_create(const char *name) | |||
540 | bat_priv->primary_if = NULL; | 485 | bat_priv->primary_if = NULL; |
541 | bat_priv->num_ifaces = 0; | 486 | bat_priv->num_ifaces = 0; |
542 | 487 | ||
543 | ret = batadv_algo_select(bat_priv, batadv_routing_algo); | 488 | batadv_nc_init_bat_priv(bat_priv); |
544 | if (ret < 0) | ||
545 | goto unreg_soft_iface; | ||
546 | 489 | ||
547 | ret = batadv_sysfs_add_meshif(soft_iface); | 490 | ret = batadv_algo_select(bat_priv, batadv_routing_algo); |
548 | if (ret < 0) | 491 | if (ret < 0) |
549 | goto unreg_soft_iface; | 492 | goto free_bat_counters; |
550 | 493 | ||
551 | ret = batadv_debugfs_add_meshif(soft_iface); | 494 | ret = batadv_debugfs_add_meshif(dev); |
552 | if (ret < 0) | 495 | if (ret < 0) |
553 | goto unreg_sysfs; | 496 | goto free_bat_counters; |
554 | 497 | ||
555 | ret = batadv_mesh_init(soft_iface); | 498 | ret = batadv_mesh_init(dev); |
556 | if (ret < 0) | 499 | if (ret < 0) |
557 | goto unreg_debugfs; | 500 | goto unreg_debugfs; |
558 | 501 | ||
559 | return soft_iface; | 502 | return 0; |
560 | 503 | ||
561 | unreg_debugfs: | 504 | unreg_debugfs: |
562 | batadv_debugfs_del_meshif(soft_iface); | 505 | batadv_debugfs_del_meshif(dev); |
563 | unreg_sysfs: | ||
564 | batadv_sysfs_del_meshif(soft_iface); | ||
565 | unreg_soft_iface: | ||
566 | free_percpu(bat_priv->bat_counters); | ||
567 | unregister_netdevice(soft_iface); | ||
568 | return NULL; | ||
569 | |||
570 | free_bat_counters: | 506 | free_bat_counters: |
571 | free_percpu(bat_priv->bat_counters); | 507 | free_percpu(bat_priv->bat_counters); |
572 | free_soft_iface: | 508 | |
573 | free_netdev(soft_iface); | 509 | return ret; |
510 | } | ||
511 | |||
512 | /** | ||
513 | * batadv_softif_slave_add - Add a slave interface to a batadv_soft_interface | ||
514 | * @dev: batadv_soft_interface used as master interface | ||
515 | * @slave_dev: net_device which should become the slave interface | ||
516 | * | ||
517 | * Return 0 if successful or error otherwise. | ||
518 | */ | ||
519 | static int batadv_softif_slave_add(struct net_device *dev, | ||
520 | struct net_device *slave_dev) | ||
521 | { | ||
522 | struct batadv_hard_iface *hard_iface; | ||
523 | int ret = -EINVAL; | ||
524 | |||
525 | hard_iface = batadv_hardif_get_by_netdev(slave_dev); | ||
526 | if (!hard_iface || hard_iface->soft_iface != NULL) | ||
527 | goto out; | ||
528 | |||
529 | ret = batadv_hardif_enable_interface(hard_iface, dev->name); | ||
530 | |||
574 | out: | 531 | out: |
575 | return NULL; | 532 | if (hard_iface) |
533 | batadv_hardif_free_ref(hard_iface); | ||
534 | return ret; | ||
576 | } | 535 | } |
577 | 536 | ||
578 | void batadv_softif_destroy(struct net_device *soft_iface) | 537 | /** |
538 | * batadv_softif_slave_del - Delete a slave iface from a batadv_soft_interface | ||
539 | * @dev: batadv_soft_interface used as master interface | ||
540 | * @slave_dev: net_device which should be removed from the master interface | ||
541 | * | ||
542 | * Return 0 if successful or error otherwise. | ||
543 | */ | ||
544 | static int batadv_softif_slave_del(struct net_device *dev, | ||
545 | struct net_device *slave_dev) | ||
546 | { | ||
547 | struct batadv_hard_iface *hard_iface; | ||
548 | int ret = -EINVAL; | ||
549 | |||
550 | hard_iface = batadv_hardif_get_by_netdev(slave_dev); | ||
551 | |||
552 | if (!hard_iface || hard_iface->soft_iface != dev) | ||
553 | goto out; | ||
554 | |||
555 | batadv_hardif_disable_interface(hard_iface, BATADV_IF_CLEANUP_KEEP); | ||
556 | ret = 0; | ||
557 | |||
558 | out: | ||
559 | if (hard_iface) | ||
560 | batadv_hardif_free_ref(hard_iface); | ||
561 | return ret; | ||
562 | } | ||
563 | |||
564 | static const struct net_device_ops batadv_netdev_ops = { | ||
565 | .ndo_init = batadv_softif_init_late, | ||
566 | .ndo_open = batadv_interface_open, | ||
567 | .ndo_stop = batadv_interface_release, | ||
568 | .ndo_get_stats = batadv_interface_stats, | ||
569 | .ndo_set_mac_address = batadv_interface_set_mac_addr, | ||
570 | .ndo_change_mtu = batadv_interface_change_mtu, | ||
571 | .ndo_start_xmit = batadv_interface_tx, | ||
572 | .ndo_validate_addr = eth_validate_addr, | ||
573 | .ndo_add_slave = batadv_softif_slave_add, | ||
574 | .ndo_del_slave = batadv_softif_slave_del, | ||
575 | }; | ||
576 | |||
577 | /** | ||
578 | * batadv_softif_free - Deconstructor of batadv_soft_interface | ||
579 | * @dev: Device to cleanup and remove | ||
580 | */ | ||
581 | static void batadv_softif_free(struct net_device *dev) | ||
582 | { | ||
583 | batadv_debugfs_del_meshif(dev); | ||
584 | batadv_mesh_free(dev); | ||
585 | |||
586 | /* some scheduled RCU callbacks need the bat_priv struct to accomplish | ||
587 | * their tasks. Wait for them all to be finished before freeing the | ||
588 | * netdev and its private data (bat_priv) | ||
589 | */ | ||
590 | rcu_barrier(); | ||
591 | |||
592 | free_netdev(dev); | ||
593 | } | ||
594 | |||
595 | /** | ||
596 | * batadv_softif_init_early - early stage initialization of soft interface | ||
597 | * @dev: registered network device to modify | ||
598 | */ | ||
599 | static void batadv_softif_init_early(struct net_device *dev) | ||
600 | { | ||
601 | struct batadv_priv *priv = netdev_priv(dev); | ||
602 | |||
603 | ether_setup(dev); | ||
604 | |||
605 | dev->netdev_ops = &batadv_netdev_ops; | ||
606 | dev->destructor = batadv_softif_free; | ||
607 | dev->tx_queue_len = 0; | ||
608 | |||
609 | /* can't call min_mtu, because the needed variables | ||
610 | * have not been initialized yet | ||
611 | */ | ||
612 | dev->mtu = ETH_DATA_LEN; | ||
613 | /* reserve more space in the skbuff for our header */ | ||
614 | dev->hard_header_len = BATADV_HEADER_LEN; | ||
615 | |||
616 | /* generate random address */ | ||
617 | eth_hw_addr_random(dev); | ||
618 | |||
619 | SET_ETHTOOL_OPS(dev, &batadv_ethtool_ops); | ||
620 | |||
621 | memset(priv, 0, sizeof(*priv)); | ||
622 | } | ||
623 | |||
624 | struct net_device *batadv_softif_create(const char *name) | ||
625 | { | ||
626 | struct net_device *soft_iface; | ||
627 | int ret; | ||
628 | |||
629 | soft_iface = alloc_netdev(sizeof(struct batadv_priv), name, | ||
630 | batadv_softif_init_early); | ||
631 | if (!soft_iface) | ||
632 | return NULL; | ||
633 | |||
634 | soft_iface->rtnl_link_ops = &batadv_link_ops; | ||
635 | |||
636 | ret = register_netdevice(soft_iface); | ||
637 | if (ret < 0) { | ||
638 | pr_err("Unable to register the batman interface '%s': %i\n", | ||
639 | name, ret); | ||
640 | free_netdev(soft_iface); | ||
641 | return NULL; | ||
642 | } | ||
643 | |||
644 | return soft_iface; | ||
645 | } | ||
646 | |||
647 | /** | ||
648 | * batadv_softif_destroy_sysfs - deletion of batadv_soft_interface via sysfs | ||
649 | * @soft_iface: the to-be-removed batman-adv interface | ||
650 | */ | ||
651 | void batadv_softif_destroy_sysfs(struct net_device *soft_iface) | ||
579 | { | 652 | { |
580 | struct batadv_priv *bat_priv = netdev_priv(soft_iface); | 653 | struct batadv_priv *bat_priv = netdev_priv(soft_iface); |
581 | 654 | ||
582 | batadv_mesh_free(soft_iface); | ||
583 | queue_work(batadv_event_workqueue, &bat_priv->cleanup_work); | 655 | queue_work(batadv_event_workqueue, &bat_priv->cleanup_work); |
584 | } | 656 | } |
585 | 657 | ||
658 | /** | ||
659 | * batadv_softif_destroy_netlink - deletion of batadv_soft_interface via netlink | ||
660 | * @soft_iface: the to-be-removed batman-adv interface | ||
661 | * @head: list pointer | ||
662 | */ | ||
663 | static void batadv_softif_destroy_netlink(struct net_device *soft_iface, | ||
664 | struct list_head *head) | ||
665 | { | ||
666 | struct batadv_hard_iface *hard_iface; | ||
667 | |||
668 | list_for_each_entry(hard_iface, &batadv_hardif_list, list) { | ||
669 | if (hard_iface->soft_iface == soft_iface) | ||
670 | batadv_hardif_disable_interface(hard_iface, | ||
671 | BATADV_IF_CLEANUP_KEEP); | ||
672 | } | ||
673 | |||
674 | batadv_sysfs_del_meshif(soft_iface); | ||
675 | unregister_netdevice_queue(soft_iface, head); | ||
676 | } | ||
677 | |||
586 | int batadv_softif_is_valid(const struct net_device *net_dev) | 678 | int batadv_softif_is_valid(const struct net_device *net_dev) |
587 | { | 679 | { |
588 | if (net_dev->netdev_ops->ndo_start_xmit == batadv_interface_tx) | 680 | if (net_dev->netdev_ops->ndo_start_xmit == batadv_interface_tx) |
@@ -591,6 +683,13 @@ int batadv_softif_is_valid(const struct net_device *net_dev) | |||
591 | return 0; | 683 | return 0; |
592 | } | 684 | } |
593 | 685 | ||
686 | struct rtnl_link_ops batadv_link_ops __read_mostly = { | ||
687 | .kind = "batadv", | ||
688 | .priv_size = sizeof(struct batadv_priv), | ||
689 | .setup = batadv_softif_init_early, | ||
690 | .dellink = batadv_softif_destroy_netlink, | ||
691 | }; | ||
692 | |||
594 | /* ethtool */ | 693 | /* ethtool */ |
595 | static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | 694 | static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
596 | { | 695 | { |
@@ -662,6 +761,17 @@ static const struct { | |||
662 | { "dat_put_rx" }, | 761 | { "dat_put_rx" }, |
663 | { "dat_cached_reply_tx" }, | 762 | { "dat_cached_reply_tx" }, |
664 | #endif | 763 | #endif |
764 | #ifdef CONFIG_BATMAN_ADV_NC | ||
765 | { "nc_code" }, | ||
766 | { "nc_code_bytes" }, | ||
767 | { "nc_recode" }, | ||
768 | { "nc_recode_bytes" }, | ||
769 | { "nc_buffer" }, | ||
770 | { "nc_decode" }, | ||
771 | { "nc_decode_bytes" }, | ||
772 | { "nc_decode_failed" }, | ||
773 | { "nc_sniffed" }, | ||
774 | #endif | ||
665 | }; | 775 | }; |
666 | 776 | ||
667 | static void batadv_get_strings(struct net_device *dev, uint32_t stringset, | 777 | static void batadv_get_strings(struct net_device *dev, uint32_t stringset, |
diff --git a/net/batman-adv/soft-interface.h b/net/batman-adv/soft-interface.h index 43182e5e603a..2f2472c2ea0d 100644 --- a/net/batman-adv/soft-interface.h +++ b/net/batman-adv/soft-interface.h | |||
@@ -25,7 +25,8 @@ void batadv_interface_rx(struct net_device *soft_iface, | |||
25 | struct sk_buff *skb, struct batadv_hard_iface *recv_if, | 25 | struct sk_buff *skb, struct batadv_hard_iface *recv_if, |
26 | int hdr_size, struct batadv_orig_node *orig_node); | 26 | int hdr_size, struct batadv_orig_node *orig_node); |
27 | struct net_device *batadv_softif_create(const char *name); | 27 | struct net_device *batadv_softif_create(const char *name); |
28 | void batadv_softif_destroy(struct net_device *soft_iface); | 28 | void batadv_softif_destroy_sysfs(struct net_device *soft_iface); |
29 | int batadv_softif_is_valid(const struct net_device *net_dev); | 29 | int batadv_softif_is_valid(const struct net_device *net_dev); |
30 | extern struct rtnl_link_ops batadv_link_ops; | ||
30 | 31 | ||
31 | #endif /* _NET_BATMAN_ADV_SOFT_INTERFACE_H_ */ | 32 | #endif /* _NET_BATMAN_ADV_SOFT_INTERFACE_H_ */ |
diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c index afbba319d73a..15a22efa9a67 100644 --- a/net/batman-adv/sysfs.c +++ b/net/batman-adv/sysfs.c | |||
@@ -442,6 +442,9 @@ static BATADV_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth, | |||
442 | #ifdef CONFIG_BATMAN_ADV_DEBUG | 442 | #ifdef CONFIG_BATMAN_ADV_DEBUG |
443 | BATADV_ATTR_SIF_UINT(log_level, S_IRUGO | S_IWUSR, 0, BATADV_DBG_ALL, NULL); | 443 | BATADV_ATTR_SIF_UINT(log_level, S_IRUGO | S_IWUSR, 0, BATADV_DBG_ALL, NULL); |
444 | #endif | 444 | #endif |
445 | #ifdef CONFIG_BATMAN_ADV_NC | ||
446 | BATADV_ATTR_SIF_BOOL(network_coding, S_IRUGO | S_IWUSR, NULL); | ||
447 | #endif | ||
445 | 448 | ||
446 | static struct batadv_attribute *batadv_mesh_attrs[] = { | 449 | static struct batadv_attribute *batadv_mesh_attrs[] = { |
447 | &batadv_attr_aggregated_ogms, | 450 | &batadv_attr_aggregated_ogms, |
@@ -464,6 +467,9 @@ static struct batadv_attribute *batadv_mesh_attrs[] = { | |||
464 | #ifdef CONFIG_BATMAN_ADV_DEBUG | 467 | #ifdef CONFIG_BATMAN_ADV_DEBUG |
465 | &batadv_attr_log_level, | 468 | &batadv_attr_log_level, |
466 | #endif | 469 | #endif |
470 | #ifdef CONFIG_BATMAN_ADV_NC | ||
471 | &batadv_attr_network_coding, | ||
472 | #endif | ||
467 | NULL, | 473 | NULL, |
468 | }; | 474 | }; |
469 | 475 | ||
@@ -582,13 +588,15 @@ static ssize_t batadv_store_mesh_iface(struct kobject *kobj, | |||
582 | } | 588 | } |
583 | 589 | ||
584 | if (status_tmp == BATADV_IF_NOT_IN_USE) { | 590 | if (status_tmp == BATADV_IF_NOT_IN_USE) { |
585 | batadv_hardif_disable_interface(hard_iface); | 591 | batadv_hardif_disable_interface(hard_iface, |
592 | BATADV_IF_CLEANUP_AUTO); | ||
586 | goto unlock; | 593 | goto unlock; |
587 | } | 594 | } |
588 | 595 | ||
589 | /* if the interface already is in use */ | 596 | /* if the interface already is in use */ |
590 | if (hard_iface->if_status != BATADV_IF_NOT_IN_USE) | 597 | if (hard_iface->if_status != BATADV_IF_NOT_IN_USE) |
591 | batadv_hardif_disable_interface(hard_iface); | 598 | batadv_hardif_disable_interface(hard_iface, |
599 | BATADV_IF_CLEANUP_AUTO); | ||
592 | 600 | ||
593 | ret = batadv_hardif_enable_interface(hard_iface, buff); | 601 | ret = batadv_hardif_enable_interface(hard_iface, buff); |
594 | 602 | ||
@@ -688,15 +696,10 @@ int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type, | |||
688 | enum batadv_uev_action action, const char *data) | 696 | enum batadv_uev_action action, const char *data) |
689 | { | 697 | { |
690 | int ret = -ENOMEM; | 698 | int ret = -ENOMEM; |
691 | struct batadv_hard_iface *primary_if; | ||
692 | struct kobject *bat_kobj; | 699 | struct kobject *bat_kobj; |
693 | char *uevent_env[4] = { NULL, NULL, NULL, NULL }; | 700 | char *uevent_env[4] = { NULL, NULL, NULL, NULL }; |
694 | 701 | ||
695 | primary_if = batadv_primary_if_get_selected(bat_priv); | 702 | bat_kobj = &bat_priv->soft_iface->dev.kobj; |
696 | if (!primary_if) | ||
697 | goto out; | ||
698 | |||
699 | bat_kobj = &primary_if->soft_iface->dev.kobj; | ||
700 | 703 | ||
701 | uevent_env[0] = kmalloc(strlen(BATADV_UEV_TYPE_VAR) + | 704 | uevent_env[0] = kmalloc(strlen(BATADV_UEV_TYPE_VAR) + |
702 | strlen(batadv_uev_type_str[type]) + 1, | 705 | strlen(batadv_uev_type_str[type]) + 1, |
@@ -732,9 +735,6 @@ out: | |||
732 | kfree(uevent_env[1]); | 735 | kfree(uevent_env[1]); |
733 | kfree(uevent_env[2]); | 736 | kfree(uevent_env[2]); |
734 | 737 | ||
735 | if (primary_if) | ||
736 | batadv_hardif_free_ref(primary_if); | ||
737 | |||
738 | if (ret) | 738 | if (ret) |
739 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, | 739 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
740 | "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n", | 740 | "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n", |
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 7abee19567e9..5e89deeb9542 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c | |||
@@ -385,25 +385,19 @@ static void batadv_tt_prepare_packet_buff(struct batadv_priv *bat_priv, | |||
385 | int *packet_buff_len, | 385 | int *packet_buff_len, |
386 | int min_packet_len) | 386 | int min_packet_len) |
387 | { | 387 | { |
388 | struct batadv_hard_iface *primary_if; | ||
389 | int req_len; | 388 | int req_len; |
390 | 389 | ||
391 | primary_if = batadv_primary_if_get_selected(bat_priv); | ||
392 | |||
393 | req_len = min_packet_len; | 390 | req_len = min_packet_len; |
394 | req_len += batadv_tt_len(atomic_read(&bat_priv->tt.local_changes)); | 391 | req_len += batadv_tt_len(atomic_read(&bat_priv->tt.local_changes)); |
395 | 392 | ||
396 | /* if we have too many changes for one packet don't send any | 393 | /* if we have too many changes for one packet don't send any |
397 | * and wait for the tt table request which will be fragmented | 394 | * and wait for the tt table request which will be fragmented |
398 | */ | 395 | */ |
399 | if ((!primary_if) || (req_len > primary_if->soft_iface->mtu)) | 396 | if (req_len > bat_priv->soft_iface->mtu) |
400 | req_len = min_packet_len; | 397 | req_len = min_packet_len; |
401 | 398 | ||
402 | batadv_tt_realloc_packet_buff(packet_buff, packet_buff_len, | 399 | batadv_tt_realloc_packet_buff(packet_buff, packet_buff_len, |
403 | min_packet_len, req_len); | 400 | min_packet_len, req_len); |
404 | |||
405 | if (primary_if) | ||
406 | batadv_hardif_free_ref(primary_if); | ||
407 | } | 401 | } |
408 | 402 | ||
409 | static int batadv_tt_changes_fill_buff(struct batadv_priv *bat_priv, | 403 | static int batadv_tt_changes_fill_buff(struct batadv_priv *bat_priv, |
@@ -908,7 +902,7 @@ out_remove: | |||
908 | /* remove address from local hash if present */ | 902 | /* remove address from local hash if present */ |
909 | local_flags = batadv_tt_local_remove(bat_priv, tt_addr, | 903 | local_flags = batadv_tt_local_remove(bat_priv, tt_addr, |
910 | "global tt received", | 904 | "global tt received", |
911 | !!(flags & BATADV_TT_CLIENT_ROAM)); | 905 | flags & BATADV_TT_CLIENT_ROAM); |
912 | tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI; | 906 | tt_global_entry->common.flags |= local_flags & BATADV_TT_CLIENT_WIFI; |
913 | 907 | ||
914 | if (!(flags & BATADV_TT_CLIENT_ROAM)) | 908 | if (!(flags & BATADV_TT_CLIENT_ROAM)) |
@@ -1580,7 +1574,7 @@ static int batadv_tt_global_valid(const void *entry_ptr, | |||
1580 | static struct sk_buff * | 1574 | static struct sk_buff * |
1581 | batadv_tt_response_fill_table(uint16_t tt_len, uint8_t ttvn, | 1575 | batadv_tt_response_fill_table(uint16_t tt_len, uint8_t ttvn, |
1582 | struct batadv_hashtable *hash, | 1576 | struct batadv_hashtable *hash, |
1583 | struct batadv_hard_iface *primary_if, | 1577 | struct batadv_priv *bat_priv, |
1584 | int (*valid_cb)(const void *, const void *), | 1578 | int (*valid_cb)(const void *, const void *), |
1585 | void *cb_data) | 1579 | void *cb_data) |
1586 | { | 1580 | { |
@@ -1594,8 +1588,8 @@ batadv_tt_response_fill_table(uint16_t tt_len, uint8_t ttvn, | |||
1594 | uint32_t i; | 1588 | uint32_t i; |
1595 | size_t len; | 1589 | size_t len; |
1596 | 1590 | ||
1597 | if (tt_query_size + tt_len > primary_if->soft_iface->mtu) { | 1591 | if (tt_query_size + tt_len > bat_priv->soft_iface->mtu) { |
1598 | tt_len = primary_if->soft_iface->mtu - tt_query_size; | 1592 | tt_len = bat_priv->soft_iface->mtu - tt_query_size; |
1599 | tt_len -= tt_len % sizeof(struct batadv_tt_change); | 1593 | tt_len -= tt_len % sizeof(struct batadv_tt_change); |
1600 | } | 1594 | } |
1601 | tt_tot = tt_len / sizeof(struct batadv_tt_change); | 1595 | tt_tot = tt_len / sizeof(struct batadv_tt_change); |
@@ -1715,7 +1709,6 @@ batadv_send_other_tt_response(struct batadv_priv *bat_priv, | |||
1715 | { | 1709 | { |
1716 | struct batadv_orig_node *req_dst_orig_node; | 1710 | struct batadv_orig_node *req_dst_orig_node; |
1717 | struct batadv_orig_node *res_dst_orig_node = NULL; | 1711 | struct batadv_orig_node *res_dst_orig_node = NULL; |
1718 | struct batadv_hard_iface *primary_if = NULL; | ||
1719 | uint8_t orig_ttvn, req_ttvn, ttvn; | 1712 | uint8_t orig_ttvn, req_ttvn, ttvn; |
1720 | int ret = false; | 1713 | int ret = false; |
1721 | unsigned char *tt_buff; | 1714 | unsigned char *tt_buff; |
@@ -1740,10 +1733,6 @@ batadv_send_other_tt_response(struct batadv_priv *bat_priv, | |||
1740 | if (!res_dst_orig_node) | 1733 | if (!res_dst_orig_node) |
1741 | goto out; | 1734 | goto out; |
1742 | 1735 | ||
1743 | primary_if = batadv_primary_if_get_selected(bat_priv); | ||
1744 | if (!primary_if) | ||
1745 | goto out; | ||
1746 | |||
1747 | orig_ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn); | 1736 | orig_ttvn = (uint8_t)atomic_read(&req_dst_orig_node->last_ttvn); |
1748 | req_ttvn = tt_request->ttvn; | 1737 | req_ttvn = tt_request->ttvn; |
1749 | 1738 | ||
@@ -1791,7 +1780,7 @@ batadv_send_other_tt_response(struct batadv_priv *bat_priv, | |||
1791 | 1780 | ||
1792 | skb = batadv_tt_response_fill_table(tt_len, ttvn, | 1781 | skb = batadv_tt_response_fill_table(tt_len, ttvn, |
1793 | bat_priv->tt.global_hash, | 1782 | bat_priv->tt.global_hash, |
1794 | primary_if, | 1783 | bat_priv, |
1795 | batadv_tt_global_valid, | 1784 | batadv_tt_global_valid, |
1796 | req_dst_orig_node); | 1785 | req_dst_orig_node); |
1797 | if (!skb) | 1786 | if (!skb) |
@@ -1828,8 +1817,6 @@ out: | |||
1828 | batadv_orig_node_free_ref(res_dst_orig_node); | 1817 | batadv_orig_node_free_ref(res_dst_orig_node); |
1829 | if (req_dst_orig_node) | 1818 | if (req_dst_orig_node) |
1830 | batadv_orig_node_free_ref(req_dst_orig_node); | 1819 | batadv_orig_node_free_ref(req_dst_orig_node); |
1831 | if (primary_if) | ||
1832 | batadv_hardif_free_ref(primary_if); | ||
1833 | if (!ret) | 1820 | if (!ret) |
1834 | kfree_skb(skb); | 1821 | kfree_skb(skb); |
1835 | return ret; | 1822 | return ret; |
@@ -1907,7 +1894,7 @@ batadv_send_my_tt_response(struct batadv_priv *bat_priv, | |||
1907 | 1894 | ||
1908 | skb = batadv_tt_response_fill_table(tt_len, ttvn, | 1895 | skb = batadv_tt_response_fill_table(tt_len, ttvn, |
1909 | bat_priv->tt.local_hash, | 1896 | bat_priv->tt.local_hash, |
1910 | primary_if, | 1897 | bat_priv, |
1911 | batadv_tt_local_valid_entry, | 1898 | batadv_tt_local_valid_entry, |
1912 | NULL); | 1899 | NULL); |
1913 | if (!skb) | 1900 | if (!skb) |
@@ -2528,7 +2515,7 @@ bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv, | |||
2528 | if (!tt_global_entry) | 2515 | if (!tt_global_entry) |
2529 | goto out; | 2516 | goto out; |
2530 | 2517 | ||
2531 | ret = !!(tt_global_entry->common.flags & BATADV_TT_CLIENT_ROAM); | 2518 | ret = tt_global_entry->common.flags & BATADV_TT_CLIENT_ROAM; |
2532 | batadv_tt_global_entry_free_ref(tt_global_entry); | 2519 | batadv_tt_global_entry_free_ref(tt_global_entry); |
2533 | out: | 2520 | out: |
2534 | return ret; | 2521 | return ret; |
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index 4cd87a0b5b80..aba8364c3689 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h | |||
@@ -128,6 +128,10 @@ struct batadv_hard_iface { | |||
128 | * @bond_list: list of bonding candidates | 128 | * @bond_list: list of bonding candidates |
129 | * @refcount: number of contexts the object is used | 129 | * @refcount: number of contexts the object is used |
130 | * @rcu: struct used for freeing in an RCU-safe manner | 130 | * @rcu: struct used for freeing in an RCU-safe manner |
131 | * @in_coding_list: list of nodes this orig can hear | ||
132 | * @out_coding_list: list of nodes that can hear this orig | ||
133 | * @in_coding_list_lock: protects in_coding_list | ||
134 | * @out_coding_list_lock: protects out_coding_list | ||
131 | */ | 135 | */ |
132 | struct batadv_orig_node { | 136 | struct batadv_orig_node { |
133 | uint8_t orig[ETH_ALEN]; | 137 | uint8_t orig[ETH_ALEN]; |
@@ -171,6 +175,12 @@ struct batadv_orig_node { | |||
171 | struct list_head bond_list; | 175 | struct list_head bond_list; |
172 | atomic_t refcount; | 176 | atomic_t refcount; |
173 | struct rcu_head rcu; | 177 | struct rcu_head rcu; |
178 | #ifdef CONFIG_BATMAN_ADV_NC | ||
179 | struct list_head in_coding_list; | ||
180 | struct list_head out_coding_list; | ||
181 | spinlock_t in_coding_list_lock; /* Protects in_coding_list */ | ||
182 | spinlock_t out_coding_list_lock; /* Protects out_coding_list */ | ||
183 | #endif | ||
174 | }; | 184 | }; |
175 | 185 | ||
176 | /** | 186 | /** |
@@ -265,6 +275,17 @@ struct batadv_bcast_duplist_entry { | |||
265 | * @BATADV_CNT_DAT_PUT_RX: received dht PUT traffic packet counter | 275 | * @BATADV_CNT_DAT_PUT_RX: received dht PUT traffic packet counter |
266 | * @BATADV_CNT_DAT_CACHED_REPLY_TX: transmitted dat cache reply traffic packet | 276 | * @BATADV_CNT_DAT_CACHED_REPLY_TX: transmitted dat cache reply traffic packet |
267 | * counter | 277 | * counter |
278 | * @BATADV_CNT_NC_CODE: transmitted nc-combined traffic packet counter | ||
279 | * @BATADV_CNT_NC_CODE_BYTES: transmitted nc-combined traffic bytes counter | ||
280 | * @BATADV_CNT_NC_RECODE: transmitted nc-recombined traffic packet counter | ||
281 | * @BATADV_CNT_NC_RECODE_BYTES: transmitted nc-recombined traffic bytes counter | ||
282 | * @BATADV_CNT_NC_BUFFER: counter for packets buffered for later nc decoding | ||
283 | * @BATADV_CNT_NC_DECODE: received and nc-decoded traffic packet counter | ||
284 | * @BATADV_CNT_NC_DECODE_BYTES: received and nc-decoded traffic bytes counter | ||
285 | * @BATADV_CNT_NC_DECODE_FAILED: received and decode-failed traffic packet | ||
286 | * counter | ||
287 | * @BATADV_CNT_NC_SNIFFED: counter for nc-decoded packets received in promisc | ||
288 | * mode. | ||
268 | * @BATADV_CNT_NUM: number of traffic counters | 289 | * @BATADV_CNT_NUM: number of traffic counters |
269 | */ | 290 | */ |
270 | enum batadv_counters { | 291 | enum batadv_counters { |
@@ -292,6 +313,17 @@ enum batadv_counters { | |||
292 | BATADV_CNT_DAT_PUT_RX, | 313 | BATADV_CNT_DAT_PUT_RX, |
293 | BATADV_CNT_DAT_CACHED_REPLY_TX, | 314 | BATADV_CNT_DAT_CACHED_REPLY_TX, |
294 | #endif | 315 | #endif |
316 | #ifdef CONFIG_BATMAN_ADV_NC | ||
317 | BATADV_CNT_NC_CODE, | ||
318 | BATADV_CNT_NC_CODE_BYTES, | ||
319 | BATADV_CNT_NC_RECODE, | ||
320 | BATADV_CNT_NC_RECODE_BYTES, | ||
321 | BATADV_CNT_NC_BUFFER, | ||
322 | BATADV_CNT_NC_DECODE, | ||
323 | BATADV_CNT_NC_DECODE_BYTES, | ||
324 | BATADV_CNT_NC_DECODE_FAILED, | ||
325 | BATADV_CNT_NC_SNIFFED, | ||
326 | #endif | ||
295 | BATADV_CNT_NUM, | 327 | BATADV_CNT_NUM, |
296 | }; | 328 | }; |
297 | 329 | ||
@@ -428,6 +460,35 @@ struct batadv_priv_dat { | |||
428 | #endif | 460 | #endif |
429 | 461 | ||
430 | /** | 462 | /** |
463 | * struct batadv_priv_nc - per mesh interface network coding private data | ||
464 | * @work: work queue callback item for cleanup | ||
465 | * @debug_dir: dentry for nc subdir in batman-adv directory in debugfs | ||
466 | * @min_tq: only consider neighbors for encoding if neigh_tq > min_tq | ||
467 | * @max_fwd_delay: maximum packet forward delay to allow coding of packets | ||
468 | * @max_buffer_time: buffer time for sniffed packets used to decoding | ||
469 | * @timestamp_fwd_flush: timestamp of last forward packet queue flush | ||
470 | * @timestamp_sniffed_purge: timestamp of last sniffed packet queue purge | ||
471 | * @coding_hash: Hash table used to buffer skbs while waiting for another | ||
472 | * incoming skb to code it with. Skbs are added to the buffer just before being | ||
473 | * forwarded in routing.c | ||
474 | * @decoding_hash: Hash table used to buffer skbs that might be needed to decode | ||
475 | * a received coded skb. The buffer is used for 1) skbs arriving on the | ||
476 | * soft-interface; 2) skbs overheard on the hard-interface; and 3) skbs | ||
477 | * forwarded by batman-adv. | ||
478 | */ | ||
479 | struct batadv_priv_nc { | ||
480 | struct delayed_work work; | ||
481 | struct dentry *debug_dir; | ||
482 | u8 min_tq; | ||
483 | u32 max_fwd_delay; | ||
484 | u32 max_buffer_time; | ||
485 | unsigned long timestamp_fwd_flush; | ||
486 | unsigned long timestamp_sniffed_purge; | ||
487 | struct batadv_hashtable *coding_hash; | ||
488 | struct batadv_hashtable *decoding_hash; | ||
489 | }; | ||
490 | |||
491 | /** | ||
431 | * struct batadv_priv - per mesh interface data | 492 | * struct batadv_priv - per mesh interface data |
432 | * @mesh_state: current status of the mesh (inactive/active/deactivating) | 493 | * @mesh_state: current status of the mesh (inactive/active/deactivating) |
433 | * @soft_iface: net device which holds this struct as private data | 494 | * @soft_iface: net device which holds this struct as private data |
@@ -470,6 +531,8 @@ struct batadv_priv_dat { | |||
470 | * @tt: translation table data | 531 | * @tt: translation table data |
471 | * @vis: vis data | 532 | * @vis: vis data |
472 | * @dat: distributed arp table data | 533 | * @dat: distributed arp table data |
534 | * @network_coding: bool indicating whether network coding is enabled | ||
535 | * @batadv_priv_nc: network coding data | ||
473 | */ | 536 | */ |
474 | struct batadv_priv { | 537 | struct batadv_priv { |
475 | atomic_t mesh_state; | 538 | atomic_t mesh_state; |
@@ -522,6 +585,10 @@ struct batadv_priv { | |||
522 | #ifdef CONFIG_BATMAN_ADV_DAT | 585 | #ifdef CONFIG_BATMAN_ADV_DAT |
523 | struct batadv_priv_dat dat; | 586 | struct batadv_priv_dat dat; |
524 | #endif | 587 | #endif |
588 | #ifdef CONFIG_BATMAN_ADV_NC | ||
589 | atomic_t network_coding; | ||
590 | struct batadv_priv_nc nc; | ||
591 | #endif /* CONFIG_BATMAN_ADV_NC */ | ||
525 | }; | 592 | }; |
526 | 593 | ||
527 | /** | 594 | /** |
@@ -702,6 +769,75 @@ struct batadv_tt_roam_node { | |||
702 | }; | 769 | }; |
703 | 770 | ||
704 | /** | 771 | /** |
772 | * struct batadv_nc_node - network coding node | ||
773 | * @list: next and prev pointer for the list handling | ||
774 | * @addr: the node's mac address | ||
775 | * @refcount: number of contexts the object is used by | ||
776 | * @rcu: struct used for freeing in an RCU-safe manner | ||
777 | * @orig_node: pointer to corresponding orig node struct | ||
778 | * @last_seen: timestamp of last ogm received from this node | ||
779 | */ | ||
780 | struct batadv_nc_node { | ||
781 | struct list_head list; | ||
782 | uint8_t addr[ETH_ALEN]; | ||
783 | atomic_t refcount; | ||
784 | struct rcu_head rcu; | ||
785 | struct batadv_orig_node *orig_node; | ||
786 | unsigned long last_seen; | ||
787 | }; | ||
788 | |||
789 | /** | ||
790 | * struct batadv_nc_path - network coding path | ||
791 | * @hash_entry: next and prev pointer for the list handling | ||
792 | * @rcu: struct used for freeing in an RCU-safe manner | ||
793 | * @refcount: number of contexts the object is used by | ||
794 | * @packet_list: list of buffered packets for this path | ||
795 | * @packet_list_lock: access lock for packet list | ||
796 | * @next_hop: next hop (destination) of path | ||
797 | * @prev_hop: previous hop (source) of path | ||
798 | * @last_valid: timestamp for last validation of path | ||
799 | */ | ||
800 | struct batadv_nc_path { | ||
801 | struct hlist_node hash_entry; | ||
802 | struct rcu_head rcu; | ||
803 | atomic_t refcount; | ||
804 | struct list_head packet_list; | ||
805 | spinlock_t packet_list_lock; /* Protects packet_list */ | ||
806 | uint8_t next_hop[ETH_ALEN]; | ||
807 | uint8_t prev_hop[ETH_ALEN]; | ||
808 | unsigned long last_valid; | ||
809 | }; | ||
810 | |||
811 | /** | ||
812 | * struct batadv_nc_packet - network coding packet used when coding and | ||
813 | * decoding packets | ||
814 | * @list: next and prev pointer for the list handling | ||
815 | * @packet_id: crc32 checksum of skb data | ||
816 | * @timestamp: field containing the info when the packet was added to path | ||
817 | * @neigh_node: pointer to original next hop neighbor of skb | ||
818 | * @skb: skb which can be encoded or used for decoding | ||
819 | * @nc_path: pointer to path this nc packet is attached to | ||
820 | */ | ||
821 | struct batadv_nc_packet { | ||
822 | struct list_head list; | ||
823 | __be32 packet_id; | ||
824 | unsigned long timestamp; | ||
825 | struct batadv_neigh_node *neigh_node; | ||
826 | struct sk_buff *skb; | ||
827 | struct batadv_nc_path *nc_path; | ||
828 | }; | ||
829 | |||
830 | /** | ||
831 | * batadv_skb_cb - control buffer structure used to store private data relevant | ||
832 | * to batman-adv in the skb->cb buffer in skbs. | ||
833 | * @decoded: Marks a skb as decoded, which is checked when searching for coding | ||
834 | * opportunities in network-coding.c | ||
835 | */ | ||
836 | struct batadv_skb_cb { | ||
837 | bool decoded; | ||
838 | }; | ||
839 | |||
840 | /** | ||
705 | * struct batadv_forw_packet - structure for bcast packets to be sent/forwarded | 841 | * struct batadv_forw_packet - structure for bcast packets to be sent/forwarded |
706 | * @list: list node for batadv_socket_client::queue_list | 842 | * @list: list node for batadv_socket_client::queue_list |
707 | * @send_time: execution time for delayed_work (packet sending) | 843 | * @send_time: execution time for delayed_work (packet sending) |
diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c index 50e079f00be6..0bb3b5982f94 100644 --- a/net/batman-adv/unicast.c +++ b/net/batman-adv/unicast.c | |||
@@ -122,7 +122,7 @@ batadv_frag_search_packet(struct list_head *head, | |||
122 | { | 122 | { |
123 | struct batadv_frag_packet_list_entry *tfp; | 123 | struct batadv_frag_packet_list_entry *tfp; |
124 | struct batadv_unicast_frag_packet *tmp_up = NULL; | 124 | struct batadv_unicast_frag_packet *tmp_up = NULL; |
125 | int is_head_tmp, is_head; | 125 | bool is_head_tmp, is_head; |
126 | uint16_t search_seqno; | 126 | uint16_t search_seqno; |
127 | 127 | ||
128 | if (up->flags & BATADV_UNI_FRAG_HEAD) | 128 | if (up->flags & BATADV_UNI_FRAG_HEAD) |
@@ -130,7 +130,7 @@ batadv_frag_search_packet(struct list_head *head, | |||
130 | else | 130 | else |
131 | search_seqno = ntohs(up->seqno)-1; | 131 | search_seqno = ntohs(up->seqno)-1; |
132 | 132 | ||
133 | is_head = !!(up->flags & BATADV_UNI_FRAG_HEAD); | 133 | is_head = up->flags & BATADV_UNI_FRAG_HEAD; |
134 | 134 | ||
135 | list_for_each_entry(tfp, head, list) { | 135 | list_for_each_entry(tfp, head, list) { |
136 | if (!tfp->skb) | 136 | if (!tfp->skb) |
@@ -142,7 +142,7 @@ batadv_frag_search_packet(struct list_head *head, | |||
142 | tmp_up = (struct batadv_unicast_frag_packet *)tfp->skb->data; | 142 | tmp_up = (struct batadv_unicast_frag_packet *)tfp->skb->data; |
143 | 143 | ||
144 | if (tfp->seqno == search_seqno) { | 144 | if (tfp->seqno == search_seqno) { |
145 | is_head_tmp = !!(tmp_up->flags & BATADV_UNI_FRAG_HEAD); | 145 | is_head_tmp = tmp_up->flags & BATADV_UNI_FRAG_HEAD; |
146 | if (is_head_tmp != is_head) | 146 | if (is_head_tmp != is_head) |
147 | return tfp; | 147 | return tfp; |
148 | else | 148 | else |
diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c index 6a1e646be96d..1625e5793a89 100644 --- a/net/batman-adv/vis.c +++ b/net/batman-adv/vis.c | |||
@@ -149,7 +149,7 @@ static void batadv_vis_data_read_prim_sec(struct seq_file *seq, | |||
149 | 149 | ||
150 | hlist_for_each_entry(entry, if_list, list) { | 150 | hlist_for_each_entry(entry, if_list, list) { |
151 | if (entry->primary) | 151 | if (entry->primary) |
152 | seq_printf(seq, "PRIMARY, "); | 152 | seq_puts(seq, "PRIMARY, "); |
153 | else | 153 | else |
154 | seq_printf(seq, "SEC %pM, ", entry->addr); | 154 | seq_printf(seq, "SEC %pM, ", entry->addr); |
155 | } | 155 | } |
@@ -207,7 +207,7 @@ static void batadv_vis_data_read_entries(struct seq_file *seq, | |||
207 | if (batadv_compare_eth(entry->addr, packet->vis_orig)) | 207 | if (batadv_compare_eth(entry->addr, packet->vis_orig)) |
208 | batadv_vis_data_read_prim_sec(seq, list); | 208 | batadv_vis_data_read_prim_sec(seq, list); |
209 | 209 | ||
210 | seq_printf(seq, "\n"); | 210 | seq_puts(seq, "\n"); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | 213 | ||