32 static int batadv_route_unicast_packet(
struct sk_buff *
skb,
47 for (i = 0; i < hash->
size; i++) {
51 hlist_for_each_entry_rcu(orig_node, node, head,
hash_entry) {
54 word = &(orig_node->
bcast_own[word_index]);
74 if ((curr_router) && (!neigh_node)) {
76 "Deleting route towards: %pM\n", orig_node->
orig);
78 "Deleted route towards originator");
81 }
else if ((!curr_router) && (neigh_node)) {
84 "Adding route towards: %pM (via %pM)\n",
87 }
else if (neigh_node && curr_router) {
89 "Changing route towards: %pM (now via %pM - was via %pM)\n",
121 if (router != neigh_node)
122 _batadv_update_route(bat_priv, orig_node, neigh_node);
151 uint8_t interference_candidate = 0;
156 if (!batadv_compare_eth(orig_node->
orig,
172 hlist_for_each_entry_rcu(tmp_neigh_node, node,
175 if (tmp_neigh_node == neigh_node)
185 (batadv_compare_eth(neigh_node->
addr,
186 tmp_neigh_node->
addr))) {
187 interference_candidate = 1;
193 if (interference_candidate)
235 unsigned long *last_reset)
239 if (!batadv_has_timed_out(*last_reset,
245 "old packet received, start protection\n");
258 if (
unlikely(!pskb_may_pull(skb, header_len)))
261 ethhdr = (
struct ethhdr *)skb_mac_header(skb);
264 if (!is_broadcast_ether_addr(ethhdr->
h_dest))
268 if (is_broadcast_ether_addr(ethhdr->
h_source))
272 if (skb_cow(skb, 0) < 0)
276 if (skb_linearize(skb) < 0)
282 static int batadv_recv_my_icmp_packet(
struct batadv_priv *bat_priv,
299 primary_if = batadv_primary_if_get_selected(bat_priv);
305 orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->
orig);
329 batadv_hardif_free_ref(primary_if);
337 static int batadv_recv_icmp_ttl_exceeded(
struct batadv_priv *bat_priv,
350 pr_debug(
"Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n",
351 icmp_packet->
orig, icmp_packet->
dst);
355 primary_if = batadv_primary_if_get_selected(bat_priv);
360 orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->
orig);
384 batadv_hardif_free_ref(primary_if);
409 if (
unlikely(!pskb_may_pull(skb, hdr_size)))
412 ethhdr = (
struct ethhdr *)skb_mac_header(skb);
415 if (is_broadcast_ether_addr(ethhdr->
h_dest))
419 if (is_broadcast_ether_addr(ethhdr->
h_source))
438 return batadv_recv_my_icmp_packet(bat_priv, skb, hdr_size);
441 if (icmp_packet->
header.ttl < 2)
442 return batadv_recv_icmp_ttl_exceeded(bat_priv, skb);
445 orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->
dst);
460 icmp_packet->
header.ttl--;
488 list_for_each_entry_rcu(tmp_neigh_node, &primary_orig->
bond_list,
490 if (!first_candidate)
491 first_candidate = tmp_neigh_node;
500 router = tmp_neigh_node;
505 if (!router && first_candidate &&
507 router = first_candidate;
543 list_for_each_entry_rcu(tmp_neigh_node, &primary_orig->
bond_list,
545 if (!first_candidate)
546 first_candidate = tmp_neigh_node;
566 router = tmp_neigh_node;
574 if (!router && first_candidate &&
576 router = first_candidate;
582 static int batadv_check_unicast_packet(
struct sk_buff *skb,
int hdr_size)
587 if (
unlikely(!pskb_may_pull(skb, hdr_size)))
590 ethhdr = (
struct ethhdr *)skb_mac_header(skb);
593 if (is_broadcast_ether_addr(ethhdr->
h_dest))
597 if (is_broadcast_ether_addr(ethhdr->
h_source))
612 int hdr_size =
sizeof(*tt_query);
616 if (batadv_check_unicast_packet(skb, hdr_size) < 0)
639 "Routing TT_REQUEST to %pM [%c]\n",
642 return batadv_route_unicast_packet(skb, recv_if);
652 if (skb_linearize(skb) < 0)
661 packet_size += tt_size;
662 if (
unlikely(skb_headlen(skb) < packet_size))
672 "Routing TT_RESPONSE to %pM [%c]\n",
675 return batadv_route_unicast_packet(skb, recv_if);
690 struct ethhdr *ethhdr;
697 ethhdr = (
struct ethhdr *)skb_mac_header(skb);
700 if (is_broadcast_ether_addr(ethhdr->
h_dest))
704 if (is_broadcast_ether_addr(ethhdr->
h_source))
712 return batadv_route_unicast_packet(skb, recv_if);
721 orig_node = batadv_orig_hash_find(bat_priv, roam_adv_packet->
src);
726 "Received ROAMING_ADV from %pM (client %pM)\n",
727 roam_adv_packet->
src, roam_adv_packet->
client);
737 bat_priv->
tt.poss_change =
true;
779 if ((!recv_if) && (!bonding_enabled))
787 if (batadv_compare_eth(primary_addr, zero_mac))
793 if (batadv_compare_eth(primary_addr, router_orig->
orig)) {
794 primary_orig_node = router_orig;
796 primary_orig_node = batadv_orig_hash_find(bat_priv,
798 if (!primary_orig_node)
817 router = batadv_find_bond_router(primary_orig_node, recv_if);
819 router = batadv_find_ifalter_router(primary_orig_node, recv_if);
835 static int batadv_route_unicast_packet(
struct sk_buff *skb,
842 struct ethhdr *ethhdr = (
struct ethhdr *)skb_mac_header(skb);
849 if (unicast_packet->
header.ttl < 2) {
850 pr_debug(
"Warning - can't forward unicast packet from %pM to %pM: ttl exceeded\n",
856 orig_node = batadv_orig_hash_find(bat_priv, unicast_packet->
dest);
883 batadv_frag_can_reassemble(skb,
902 unicast_packet->
header.ttl--;
921 static int batadv_check_unicast_ttvn(
struct batadv_priv *bat_priv,
925 struct ethhdr *ethhdr;
938 tt_poss_change = bat_priv->
tt.poss_change;
941 orig_node = batadv_orig_hash_find(bat_priv,
942 unicast_packet->
dest);
954 if (is_old_ttvn || tt_poss_change) {
960 ethhdr = (
struct ethhdr *)(skb->
data +
sizeof(*unicast_packet));
975 primary_if = batadv_primary_if_get_selected(bat_priv);
980 batadv_hardif_free_ref(primary_if);
989 "TTVN mismatch (old_ttvn %u new_ttvn %u)! Rerouting unicast packet (for %pM) to %pM\n",
990 unicast_packet->
ttvn, curr_ttvn, ethhdr->
h_dest,
991 unicast_packet->
dest);
993 unicast_packet->
ttvn = curr_ttvn;
1003 int hdr_size =
sizeof(*unicast_packet);
1005 if (batadv_check_unicast_packet(skb, hdr_size) < 0)
1008 if (!batadv_check_unicast_ttvn(bat_priv, skb))
1021 return batadv_route_unicast_packet(skb, recv_if);
1029 int hdr_size =
sizeof(*unicast_packet);
1033 if (batadv_check_unicast_packet(skb, hdr_size) < 0)
1036 if (!batadv_check_unicast_ttvn(bat_priv, skb))
1058 return batadv_route_unicast_packet(skb, recv_if);
1068 struct ethhdr *ethhdr;
1069 int hdr_size =
sizeof(*bcast_packet);
1074 if (
unlikely(!pskb_may_pull(skb, hdr_size)))
1077 ethhdr = (
struct ethhdr *)skb_mac_header(skb);
1080 if (!is_broadcast_ether_addr(ethhdr->
h_dest))
1084 if (is_broadcast_ether_addr(ethhdr->
h_source))
1097 if (bcast_packet->
header.ttl < 2)
1100 orig_node = batadv_orig_hash_find(bat_priv, bcast_packet->
orig);
1128 if (skb_linearize(skb) < 0)
1164 struct ethhdr *ethhdr;
1166 int hdr_size =
sizeof(*vis_packet);
1169 if (skb_linearize(skb) < 0)
1172 if (
unlikely(!pskb_may_pull(skb, hdr_size)))
1176 ethhdr = (
struct ethhdr *)skb_mac_header(skb);