|
@@ -196,8 +196,8 @@ bool batadv_check_management_packet(struct sk_buff *skb,
|
|
|
if (!is_broadcast_ether_addr(ethhdr->h_dest))
|
|
|
return false;
|
|
|
|
|
|
- /* packet with broadcast sender address */
|
|
|
- if (is_broadcast_ether_addr(ethhdr->h_source))
|
|
|
+ /* packet with invalid sender address */
|
|
|
+ if (!is_valid_ether_addr(ethhdr->h_source))
|
|
|
return false;
|
|
|
|
|
|
/* create a copy of the skb, if needed, to modify it. */
|
|
@@ -262,11 +262,11 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
|
|
|
icmph->ttl = BATADV_TTL;
|
|
|
|
|
|
res = batadv_send_skb_to_orig(skb, orig_node, NULL);
|
|
|
- if (res == -1)
|
|
|
- goto out;
|
|
|
-
|
|
|
- ret = NET_RX_SUCCESS;
|
|
|
+ if (res == NET_XMIT_SUCCESS)
|
|
|
+ ret = NET_RX_SUCCESS;
|
|
|
|
|
|
+ /* skb was consumed */
|
|
|
+ skb = NULL;
|
|
|
break;
|
|
|
case BATADV_TP:
|
|
|
if (!pskb_may_pull(skb, sizeof(struct batadv_icmp_tp_packet)))
|
|
@@ -274,6 +274,8 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
|
|
|
|
|
|
batadv_tp_meter_recv(bat_priv, skb);
|
|
|
ret = NET_RX_SUCCESS;
|
|
|
+ /* skb was consumed */
|
|
|
+ skb = NULL;
|
|
|
goto out;
|
|
|
default:
|
|
|
/* drop unknown type */
|
|
@@ -284,6 +286,9 @@ out:
|
|
|
batadv_hardif_put(primary_if);
|
|
|
if (orig_node)
|
|
|
batadv_orig_node_put(orig_node);
|
|
|
+
|
|
|
+ kfree_skb(skb);
|
|
|
+
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -325,14 +330,20 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
|
|
|
icmp_packet->ttl = BATADV_TTL;
|
|
|
|
|
|
res = batadv_send_skb_to_orig(skb, orig_node, NULL);
|
|
|
- if (res != -1)
|
|
|
- ret = NET_RX_SUCCESS;
|
|
|
+ if (res == NET_RX_SUCCESS)
|
|
|
+ ret = NET_XMIT_SUCCESS;
|
|
|
+
|
|
|
+ /* skb was consumed */
|
|
|
+ skb = NULL;
|
|
|
|
|
|
out:
|
|
|
if (primary_if)
|
|
|
batadv_hardif_put(primary_if);
|
|
|
if (orig_node)
|
|
|
batadv_orig_node_put(orig_node);
|
|
|
+
|
|
|
+ kfree_skb(skb);
|
|
|
+
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -349,21 +360,21 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
|
|
|
|
|
|
/* drop packet if it has not necessary minimum size */
|
|
|
if (unlikely(!pskb_may_pull(skb, hdr_size)))
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
ethhdr = eth_hdr(skb);
|
|
|
|
|
|
- /* packet with unicast indication but broadcast recipient */
|
|
|
- if (is_broadcast_ether_addr(ethhdr->h_dest))
|
|
|
- goto out;
|
|
|
+ /* packet with unicast indication but non-unicast recipient */
|
|
|
+ if (!is_valid_ether_addr(ethhdr->h_dest))
|
|
|
+ goto free_skb;
|
|
|
|
|
|
- /* packet with broadcast sender address */
|
|
|
- if (is_broadcast_ether_addr(ethhdr->h_source))
|
|
|
- goto out;
|
|
|
+ /* packet with broadcast/multicast sender address */
|
|
|
+ if (is_multicast_ether_addr(ethhdr->h_source))
|
|
|
+ goto free_skb;
|
|
|
|
|
|
/* not for me */
|
|
|
if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
icmph = (struct batadv_icmp_header *)skb->data;
|
|
|
|
|
@@ -372,17 +383,17 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
|
|
|
icmph->msg_type == BATADV_ECHO_REQUEST) &&
|
|
|
(skb->len >= sizeof(struct batadv_icmp_packet_rr))) {
|
|
|
if (skb_linearize(skb) < 0)
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
/* create a copy of the skb, if needed, to modify it. */
|
|
|
if (skb_cow(skb, ETH_HLEN) < 0)
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
ethhdr = eth_hdr(skb);
|
|
|
icmph = (struct batadv_icmp_header *)skb->data;
|
|
|
icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmph;
|
|
|
if (icmp_packet_rr->rr_cur >= BATADV_RR_LEN)
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
ether_addr_copy(icmp_packet_rr->rr[icmp_packet_rr->rr_cur],
|
|
|
ethhdr->h_dest);
|
|
@@ -400,11 +411,11 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
|
|
|
/* get routing information */
|
|
|
orig_node = batadv_orig_hash_find(bat_priv, icmph->dst);
|
|
|
if (!orig_node)
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
/* create a copy of the skb, if needed, to modify it. */
|
|
|
if (skb_cow(skb, ETH_HLEN) < 0)
|
|
|
- goto out;
|
|
|
+ goto put_orig_node;
|
|
|
|
|
|
icmph = (struct batadv_icmp_header *)skb->data;
|
|
|
|
|
@@ -413,12 +424,18 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
|
|
|
|
|
|
/* route it */
|
|
|
res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
|
|
|
- if (res != -1)
|
|
|
+ if (res == NET_XMIT_SUCCESS)
|
|
|
ret = NET_RX_SUCCESS;
|
|
|
|
|
|
-out:
|
|
|
+ /* skb was consumed */
|
|
|
+ skb = NULL;
|
|
|
+
|
|
|
+put_orig_node:
|
|
|
if (orig_node)
|
|
|
batadv_orig_node_put(orig_node);
|
|
|
+free_skb:
|
|
|
+ kfree_skb(skb);
|
|
|
+
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -445,12 +462,12 @@ static int batadv_check_unicast_packet(struct batadv_priv *bat_priv,
|
|
|
|
|
|
ethhdr = eth_hdr(skb);
|
|
|
|
|
|
- /* packet with unicast indication but broadcast recipient */
|
|
|
- if (is_broadcast_ether_addr(ethhdr->h_dest))
|
|
|
+ /* packet with unicast indication but non-unicast recipient */
|
|
|
+ if (!is_valid_ether_addr(ethhdr->h_dest))
|
|
|
return -EBADR;
|
|
|
|
|
|
- /* packet with broadcast sender address */
|
|
|
- if (is_broadcast_ether_addr(ethhdr->h_source))
|
|
|
+ /* packet with broadcast/multicast sender address */
|
|
|
+ if (is_multicast_ether_addr(ethhdr->h_source))
|
|
|
return -EBADR;
|
|
|
|
|
|
/* not for me */
|
|
@@ -667,18 +684,18 @@ static int batadv_route_unicast_packet(struct sk_buff *skb,
|
|
|
if (unicast_packet->ttl < 2) {
|
|
|
pr_debug("Warning - can't forward unicast packet from %pM to %pM: ttl exceeded\n",
|
|
|
ethhdr->h_source, unicast_packet->dest);
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
}
|
|
|
|
|
|
/* get routing information */
|
|
|
orig_node = batadv_orig_hash_find(bat_priv, unicast_packet->dest);
|
|
|
|
|
|
if (!orig_node)
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
/* create a copy of the skb, if needed, to modify it. */
|
|
|
if (skb_cow(skb, ETH_HLEN) < 0)
|
|
|
- goto out;
|
|
|
+ goto put_orig_node;
|
|
|
|
|
|
/* decrement ttl */
|
|
|
unicast_packet = (struct batadv_unicast_packet *)skb->data;
|
|
@@ -702,8 +719,11 @@ static int batadv_route_unicast_packet(struct sk_buff *skb,
|
|
|
|
|
|
len = skb->len;
|
|
|
res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
|
|
|
- if (res == -1)
|
|
|
- goto out;
|
|
|
+ if (res == NET_XMIT_SUCCESS)
|
|
|
+ ret = NET_RX_SUCCESS;
|
|
|
+
|
|
|
+ /* skb was consumed */
|
|
|
+ skb = NULL;
|
|
|
|
|
|
/* translate transmit result into receive result */
|
|
|
if (res == NET_XMIT_SUCCESS) {
|
|
@@ -713,11 +733,11 @@ static int batadv_route_unicast_packet(struct sk_buff *skb,
|
|
|
len + ETH_HLEN);
|
|
|
}
|
|
|
|
|
|
- ret = NET_RX_SUCCESS;
|
|
|
+put_orig_node:
|
|
|
+ batadv_orig_node_put(orig_node);
|
|
|
+free_skb:
|
|
|
+ kfree_skb(skb);
|
|
|
|
|
|
-out:
|
|
|
- if (orig_node)
|
|
|
- batadv_orig_node_put(orig_node);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -902,14 +922,18 @@ int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
|
|
|
|
|
|
check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
|
|
|
if (check < 0)
|
|
|
- return NET_RX_DROP;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
/* we don't know about this type, drop it. */
|
|
|
unicast_packet = (struct batadv_unicast_packet *)skb->data;
|
|
|
if (batadv_is_my_mac(bat_priv, unicast_packet->dest))
|
|
|
- return NET_RX_DROP;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
return batadv_route_unicast_packet(skb, recv_if);
|
|
|
+
|
|
|
+free_skb:
|
|
|
+ kfree_skb(skb);
|
|
|
+ return NET_RX_DROP;
|
|
|
}
|
|
|
|
|
|
int batadv_recv_unicast_packet(struct sk_buff *skb,
|
|
@@ -923,6 +947,7 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
|
|
|
int check, hdr_size = sizeof(*unicast_packet);
|
|
|
enum batadv_subtype subtype;
|
|
|
bool is4addr;
|
|
|
+ int ret = NET_RX_DROP;
|
|
|
|
|
|
unicast_packet = (struct batadv_unicast_packet *)skb->data;
|
|
|
unicast_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data;
|
|
@@ -942,9 +967,9 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
|
|
|
batadv_nc_skb_store_sniffed_unicast(bat_priv, skb);
|
|
|
|
|
|
if (check < 0)
|
|
|
- return NET_RX_DROP;
|
|
|
+ goto free_skb;
|
|
|
if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size))
|
|
|
- return NET_RX_DROP;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
/* packet for me */
|
|
|
if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
|
|
@@ -982,7 +1007,14 @@ rx_success:
|
|
|
return NET_RX_SUCCESS;
|
|
|
}
|
|
|
|
|
|
- return batadv_route_unicast_packet(skb, recv_if);
|
|
|
+ ret = batadv_route_unicast_packet(skb, recv_if);
|
|
|
+ /* skb was consumed */
|
|
|
+ skb = NULL;
|
|
|
+
|
|
|
+free_skb:
|
|
|
+ kfree_skb(skb);
|
|
|
+
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1004,15 +1036,15 @@ int batadv_recv_unicast_tvlv(struct sk_buff *skb,
|
|
|
int ret = NET_RX_DROP;
|
|
|
|
|
|
if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0)
|
|
|
- return NET_RX_DROP;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
/* the header is likely to be modified while forwarding */
|
|
|
if (skb_cow(skb, hdr_size) < 0)
|
|
|
- return NET_RX_DROP;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
/* packet needs to be linearized to access the tvlv content */
|
|
|
if (skb_linearize(skb) < 0)
|
|
|
- return NET_RX_DROP;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
unicast_tvlv_packet = (struct batadv_unicast_tvlv_packet *)skb->data;
|
|
|
|
|
@@ -1020,17 +1052,21 @@ int batadv_recv_unicast_tvlv(struct sk_buff *skb,
|
|
|
tvlv_buff_len = ntohs(unicast_tvlv_packet->tvlv_len);
|
|
|
|
|
|
if (tvlv_buff_len > skb->len - hdr_size)
|
|
|
- return NET_RX_DROP;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
ret = batadv_tvlv_containers_process(bat_priv, false, NULL,
|
|
|
unicast_tvlv_packet->src,
|
|
|
unicast_tvlv_packet->dst,
|
|
|
tvlv_buff, tvlv_buff_len);
|
|
|
|
|
|
- if (ret != NET_RX_SUCCESS)
|
|
|
+ if (ret != NET_RX_SUCCESS) {
|
|
|
ret = batadv_route_unicast_packet(skb, recv_if);
|
|
|
- else
|
|
|
- consume_skb(skb);
|
|
|
+ /* skb was consumed */
|
|
|
+ skb = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+free_skb:
|
|
|
+ kfree_skb(skb);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -1056,20 +1092,22 @@ int batadv_recv_frag_packet(struct sk_buff *skb,
|
|
|
|
|
|
if (batadv_check_unicast_packet(bat_priv, skb,
|
|
|
sizeof(*frag_packet)) < 0)
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
frag_packet = (struct batadv_frag_packet *)skb->data;
|
|
|
orig_node_src = batadv_orig_hash_find(bat_priv, frag_packet->orig);
|
|
|
if (!orig_node_src)
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
skb->priority = frag_packet->priority + 256;
|
|
|
|
|
|
/* Route the fragment if it is not for us and too big to be merged. */
|
|
|
if (!batadv_is_my_mac(bat_priv, frag_packet->dest) &&
|
|
|
batadv_frag_skb_fwd(skb, recv_if, orig_node_src)) {
|
|
|
+ /* skb was consumed */
|
|
|
+ skb = NULL;
|
|
|
ret = NET_RX_SUCCESS;
|
|
|
- goto out;
|
|
|
+ goto put_orig_node;
|
|
|
}
|
|
|
|
|
|
batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_RX);
|
|
@@ -1077,20 +1115,24 @@ int batadv_recv_frag_packet(struct sk_buff *skb,
|
|
|
|
|
|
/* Add fragment to buffer and merge if possible. */
|
|
|
if (!batadv_frag_skb_buffer(&skb, orig_node_src))
|
|
|
- goto out;
|
|
|
+ goto put_orig_node;
|
|
|
|
|
|
/* Deliver merged packet to the appropriate handler, if it was
|
|
|
* merged
|
|
|
*/
|
|
|
- if (skb)
|
|
|
+ if (skb) {
|
|
|
batadv_batman_skb_recv(skb, recv_if->net_dev,
|
|
|
&recv_if->batman_adv_ptype, NULL);
|
|
|
+ /* skb was consumed */
|
|
|
+ skb = NULL;
|
|
|
+ }
|
|
|
|
|
|
ret = NET_RX_SUCCESS;
|
|
|
|
|
|
-out:
|
|
|
- if (orig_node_src)
|
|
|
- batadv_orig_node_put(orig_node_src);
|
|
|
+put_orig_node:
|
|
|
+ batadv_orig_node_put(orig_node_src);
|
|
|
+free_skb:
|
|
|
+ kfree_skb(skb);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
@@ -1109,35 +1151,35 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
|
|
|
|
|
|
/* drop packet if it has not necessary minimum size */
|
|
|
if (unlikely(!pskb_may_pull(skb, hdr_size)))
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
ethhdr = eth_hdr(skb);
|
|
|
|
|
|
/* packet with broadcast indication but unicast recipient */
|
|
|
if (!is_broadcast_ether_addr(ethhdr->h_dest))
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
- /* packet with broadcast sender address */
|
|
|
- if (is_broadcast_ether_addr(ethhdr->h_source))
|
|
|
- goto out;
|
|
|
+ /* packet with broadcast/multicast sender address */
|
|
|
+ if (is_multicast_ether_addr(ethhdr->h_source))
|
|
|
+ goto free_skb;
|
|
|
|
|
|
/* ignore broadcasts sent by myself */
|
|
|
if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
bcast_packet = (struct batadv_bcast_packet *)skb->data;
|
|
|
|
|
|
/* ignore broadcasts originated by myself */
|
|
|
if (batadv_is_my_mac(bat_priv, bcast_packet->orig))
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
if (bcast_packet->ttl < 2)
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
orig_node = batadv_orig_hash_find(bat_priv, bcast_packet->orig);
|
|
|
|
|
|
if (!orig_node)
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
spin_lock_bh(&orig_node->bcast_seqno_lock);
|
|
|
|
|
@@ -1165,18 +1207,18 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
|
|
|
|
|
|
/* check whether this has been sent by another originator before */
|
|
|
if (batadv_bla_check_bcast_duplist(bat_priv, skb))
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
batadv_skb_set_priority(skb, sizeof(struct batadv_bcast_packet));
|
|
|
|
|
|
/* rebroadcast packet */
|
|
|
- batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
|
|
|
+ batadv_add_bcast_packet_to_list(bat_priv, skb, 1, false);
|
|
|
|
|
|
/* don't hand the broadcast up if it is from an originator
|
|
|
* from the same backbone.
|
|
|
*/
|
|
|
if (batadv_bla_is_backbone_gw(skb, orig_node, hdr_size))
|
|
|
- goto out;
|
|
|
+ goto free_skb;
|
|
|
|
|
|
if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb, hdr_size))
|
|
|
goto rx_success;
|
|
@@ -1192,6 +1234,8 @@ rx_success:
|
|
|
|
|
|
spin_unlock:
|
|
|
spin_unlock_bh(&orig_node->bcast_seqno_lock);
|
|
|
+free_skb:
|
|
|
+ kfree_skb(skb);
|
|
|
out:
|
|
|
if (orig_node)
|
|
|
batadv_orig_node_put(orig_node);
|