Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (C) B.A.T.M.A.N. contributors:
0003  *
0004  * Marek Lindner, Simon Wunderlich
0005  */
0006 
0007 #include "routing.h"
0008 #include "main.h"
0009 
0010 #include <linux/atomic.h>
0011 #include <linux/byteorder/generic.h>
0012 #include <linux/compiler.h>
0013 #include <linux/errno.h>
0014 #include <linux/etherdevice.h>
0015 #include <linux/if_ether.h>
0016 #include <linux/jiffies.h>
0017 #include <linux/kref.h>
0018 #include <linux/netdevice.h>
0019 #include <linux/printk.h>
0020 #include <linux/rculist.h>
0021 #include <linux/rcupdate.h>
0022 #include <linux/skbuff.h>
0023 #include <linux/spinlock.h>
0024 #include <linux/stddef.h>
0025 #include <uapi/linux/batadv_packet.h>
0026 
0027 #include "bitarray.h"
0028 #include "bridge_loop_avoidance.h"
0029 #include "distributed-arp-table.h"
0030 #include "fragmentation.h"
0031 #include "hard-interface.h"
0032 #include "log.h"
0033 #include "network-coding.h"
0034 #include "originator.h"
0035 #include "send.h"
0036 #include "soft-interface.h"
0037 #include "tp_meter.h"
0038 #include "translation-table.h"
0039 #include "tvlv.h"
0040 
0041 static int batadv_route_unicast_packet(struct sk_buff *skb,
0042                        struct batadv_hard_iface *recv_if);
0043 
0044 /**
0045  * _batadv_update_route() - set the router for this originator
0046  * @bat_priv: the bat priv with all the soft interface information
0047  * @orig_node: orig node which is to be configured
0048  * @recv_if: the receive interface for which this route is set
0049  * @neigh_node: neighbor which should be the next router
0050  *
0051  * This function does not perform any error checks
0052  */
0053 static void _batadv_update_route(struct batadv_priv *bat_priv,
0054                  struct batadv_orig_node *orig_node,
0055                  struct batadv_hard_iface *recv_if,
0056                  struct batadv_neigh_node *neigh_node)
0057 {
0058     struct batadv_orig_ifinfo *orig_ifinfo;
0059     struct batadv_neigh_node *curr_router;
0060 
0061     orig_ifinfo = batadv_orig_ifinfo_get(orig_node, recv_if);
0062     if (!orig_ifinfo)
0063         return;
0064 
0065     spin_lock_bh(&orig_node->neigh_list_lock);
0066     /* curr_router used earlier may not be the current orig_ifinfo->router
0067      * anymore because it was dereferenced outside of the neigh_list_lock
0068      * protected region. After the new best neighbor has replace the current
0069      * best neighbor the reference counter needs to decrease. Consequently,
0070      * the code needs to ensure the curr_router variable contains a pointer
0071      * to the replaced best neighbor.
0072      */
0073 
0074     /* increase refcount of new best neighbor */
0075     if (neigh_node)
0076         kref_get(&neigh_node->refcount);
0077 
0078     curr_router = rcu_replace_pointer(orig_ifinfo->router, neigh_node,
0079                       true);
0080     spin_unlock_bh(&orig_node->neigh_list_lock);
0081     batadv_orig_ifinfo_put(orig_ifinfo);
0082 
0083     /* route deleted */
0084     if (curr_router && !neigh_node) {
0085         batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
0086                "Deleting route towards: %pM\n", orig_node->orig);
0087         batadv_tt_global_del_orig(bat_priv, orig_node, -1,
0088                       "Deleted route towards originator");
0089 
0090     /* route added */
0091     } else if (!curr_router && neigh_node) {
0092         batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
0093                "Adding route towards: %pM (via %pM)\n",
0094                orig_node->orig, neigh_node->addr);
0095     /* route changed */
0096     } else if (neigh_node && curr_router) {
0097         batadv_dbg(BATADV_DBG_ROUTES, bat_priv,
0098                "Changing route towards: %pM (now via %pM - was via %pM)\n",
0099                orig_node->orig, neigh_node->addr,
0100                curr_router->addr);
0101     }
0102 
0103     /* decrease refcount of previous best neighbor */
0104     batadv_neigh_node_put(curr_router);
0105 }
0106 
0107 /**
0108  * batadv_update_route() - set the router for this originator
0109  * @bat_priv: the bat priv with all the soft interface information
0110  * @orig_node: orig node which is to be configured
0111  * @recv_if: the receive interface for which this route is set
0112  * @neigh_node: neighbor which should be the next router
0113  */
0114 void batadv_update_route(struct batadv_priv *bat_priv,
0115              struct batadv_orig_node *orig_node,
0116              struct batadv_hard_iface *recv_if,
0117              struct batadv_neigh_node *neigh_node)
0118 {
0119     struct batadv_neigh_node *router = NULL;
0120 
0121     if (!orig_node)
0122         goto out;
0123 
0124     router = batadv_orig_router_get(orig_node, recv_if);
0125 
0126     if (router != neigh_node)
0127         _batadv_update_route(bat_priv, orig_node, recv_if, neigh_node);
0128 
0129 out:
0130     batadv_neigh_node_put(router);
0131 }
0132 
0133 /**
0134  * batadv_window_protected() - checks whether the host restarted and is in the
0135  *  protection time.
0136  * @bat_priv: the bat priv with all the soft interface information
0137  * @seq_num_diff: difference between the current/received sequence number and
0138  *  the last sequence number
0139  * @seq_old_max_diff: maximum age of sequence number not considered as restart
0140  * @last_reset: jiffies timestamp of the last reset, will be updated when reset
0141  *  is detected
0142  * @protection_started: is set to true if the protection window was started,
0143  *   doesn't change otherwise.
0144  *
0145  * Return:
0146  *  false if the packet is to be accepted.
0147  *  true if the packet is to be ignored.
0148  */
0149 bool batadv_window_protected(struct batadv_priv *bat_priv, s32 seq_num_diff,
0150                  s32 seq_old_max_diff, unsigned long *last_reset,
0151                  bool *protection_started)
0152 {
0153     if (seq_num_diff <= -seq_old_max_diff ||
0154         seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE) {
0155         if (!batadv_has_timed_out(*last_reset,
0156                       BATADV_RESET_PROTECTION_MS))
0157             return true;
0158 
0159         *last_reset = jiffies;
0160         if (protection_started)
0161             *protection_started = true;
0162         batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
0163                "old packet received, start protection\n");
0164     }
0165 
0166     return false;
0167 }
0168 
0169 /**
0170  * batadv_check_management_packet() - Check preconditions for management packets
0171  * @skb: incoming packet buffer
0172  * @hard_iface: incoming hard interface
0173  * @header_len: minimal header length of packet type
0174  *
0175  * Return: true when management preconditions are met, false otherwise
0176  */
0177 bool batadv_check_management_packet(struct sk_buff *skb,
0178                     struct batadv_hard_iface *hard_iface,
0179                     int header_len)
0180 {
0181     struct ethhdr *ethhdr;
0182 
0183     /* drop packet if it has not necessary minimum size */
0184     if (unlikely(!pskb_may_pull(skb, header_len)))
0185         return false;
0186 
0187     ethhdr = eth_hdr(skb);
0188 
0189     /* packet with broadcast indication but unicast recipient */
0190     if (!is_broadcast_ether_addr(ethhdr->h_dest))
0191         return false;
0192 
0193     /* packet with invalid sender address */
0194     if (!is_valid_ether_addr(ethhdr->h_source))
0195         return false;
0196 
0197     /* create a copy of the skb, if needed, to modify it. */
0198     if (skb_cow(skb, 0) < 0)
0199         return false;
0200 
0201     /* keep skb linear */
0202     if (skb_linearize(skb) < 0)
0203         return false;
0204 
0205     return true;
0206 }
0207 
0208 /**
0209  * batadv_recv_my_icmp_packet() - receive an icmp packet locally
0210  * @bat_priv: the bat priv with all the soft interface information
0211  * @skb: icmp packet to process
0212  *
0213  * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
0214  * otherwise.
0215  */
0216 static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
0217                       struct sk_buff *skb)
0218 {
0219     struct batadv_hard_iface *primary_if = NULL;
0220     struct batadv_orig_node *orig_node = NULL;
0221     struct batadv_icmp_header *icmph;
0222     int res, ret = NET_RX_DROP;
0223 
0224     icmph = (struct batadv_icmp_header *)skb->data;
0225 
0226     switch (icmph->msg_type) {
0227     case BATADV_ECHO_REQUEST:
0228         /* answer echo request (ping) */
0229         primary_if = batadv_primary_if_get_selected(bat_priv);
0230         if (!primary_if)
0231             goto out;
0232 
0233         /* get routing information */
0234         orig_node = batadv_orig_hash_find(bat_priv, icmph->orig);
0235         if (!orig_node)
0236             goto out;
0237 
0238         /* create a copy of the skb, if needed, to modify it. */
0239         if (skb_cow(skb, ETH_HLEN) < 0)
0240             goto out;
0241 
0242         icmph = (struct batadv_icmp_header *)skb->data;
0243 
0244         ether_addr_copy(icmph->dst, icmph->orig);
0245         ether_addr_copy(icmph->orig, primary_if->net_dev->dev_addr);
0246         icmph->msg_type = BATADV_ECHO_REPLY;
0247         icmph->ttl = BATADV_TTL;
0248 
0249         res = batadv_send_skb_to_orig(skb, orig_node, NULL);
0250         if (res == NET_XMIT_SUCCESS)
0251             ret = NET_RX_SUCCESS;
0252 
0253         /* skb was consumed */
0254         skb = NULL;
0255         break;
0256     case BATADV_TP:
0257         if (!pskb_may_pull(skb, sizeof(struct batadv_icmp_tp_packet)))
0258             goto out;
0259 
0260         batadv_tp_meter_recv(bat_priv, skb);
0261         ret = NET_RX_SUCCESS;
0262         /* skb was consumed */
0263         skb = NULL;
0264         goto out;
0265     default:
0266         /* drop unknown type */
0267         goto out;
0268     }
0269 out:
0270     batadv_hardif_put(primary_if);
0271     batadv_orig_node_put(orig_node);
0272 
0273     kfree_skb(skb);
0274 
0275     return ret;
0276 }
0277 
0278 static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
0279                      struct sk_buff *skb)
0280 {
0281     struct batadv_hard_iface *primary_if = NULL;
0282     struct batadv_orig_node *orig_node = NULL;
0283     struct batadv_icmp_packet *icmp_packet;
0284     int res, ret = NET_RX_DROP;
0285 
0286     icmp_packet = (struct batadv_icmp_packet *)skb->data;
0287 
0288     /* send TTL exceeded if packet is an echo request (traceroute) */
0289     if (icmp_packet->msg_type != BATADV_ECHO_REQUEST) {
0290         pr_debug("Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n",
0291              icmp_packet->orig, icmp_packet->dst);
0292         goto out;
0293     }
0294 
0295     primary_if = batadv_primary_if_get_selected(bat_priv);
0296     if (!primary_if)
0297         goto out;
0298 
0299     /* get routing information */
0300     orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->orig);
0301     if (!orig_node)
0302         goto out;
0303 
0304     /* create a copy of the skb, if needed, to modify it. */
0305     if (skb_cow(skb, ETH_HLEN) < 0)
0306         goto out;
0307 
0308     icmp_packet = (struct batadv_icmp_packet *)skb->data;
0309 
0310     ether_addr_copy(icmp_packet->dst, icmp_packet->orig);
0311     ether_addr_copy(icmp_packet->orig, primary_if->net_dev->dev_addr);
0312     icmp_packet->msg_type = BATADV_TTL_EXCEEDED;
0313     icmp_packet->ttl = BATADV_TTL;
0314 
0315     res = batadv_send_skb_to_orig(skb, orig_node, NULL);
0316     if (res == NET_RX_SUCCESS)
0317         ret = NET_XMIT_SUCCESS;
0318 
0319     /* skb was consumed */
0320     skb = NULL;
0321 
0322 out:
0323     batadv_hardif_put(primary_if);
0324     batadv_orig_node_put(orig_node);
0325 
0326     kfree_skb(skb);
0327 
0328     return ret;
0329 }
0330 
0331 /**
0332  * batadv_recv_icmp_packet() - Process incoming icmp packet
0333  * @skb: incoming packet buffer
0334  * @recv_if: incoming hard interface
0335  *
0336  * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure
0337  */
0338 int batadv_recv_icmp_packet(struct sk_buff *skb,
0339                 struct batadv_hard_iface *recv_if)
0340 {
0341     struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
0342     struct batadv_icmp_header *icmph;
0343     struct batadv_icmp_packet_rr *icmp_packet_rr;
0344     struct ethhdr *ethhdr;
0345     struct batadv_orig_node *orig_node = NULL;
0346     int hdr_size = sizeof(struct batadv_icmp_header);
0347     int res, ret = NET_RX_DROP;
0348 
0349     /* drop packet if it has not necessary minimum size */
0350     if (unlikely(!pskb_may_pull(skb, hdr_size)))
0351         goto free_skb;
0352 
0353     ethhdr = eth_hdr(skb);
0354 
0355     /* packet with unicast indication but non-unicast recipient */
0356     if (!is_valid_ether_addr(ethhdr->h_dest))
0357         goto free_skb;
0358 
0359     /* packet with broadcast/multicast sender address */
0360     if (is_multicast_ether_addr(ethhdr->h_source))
0361         goto free_skb;
0362 
0363     /* not for me */
0364     if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
0365         goto free_skb;
0366 
0367     icmph = (struct batadv_icmp_header *)skb->data;
0368 
0369     /* add record route information if not full */
0370     if ((icmph->msg_type == BATADV_ECHO_REPLY ||
0371          icmph->msg_type == BATADV_ECHO_REQUEST) &&
0372         skb->len >= sizeof(struct batadv_icmp_packet_rr)) {
0373         if (skb_linearize(skb) < 0)
0374             goto free_skb;
0375 
0376         /* create a copy of the skb, if needed, to modify it. */
0377         if (skb_cow(skb, ETH_HLEN) < 0)
0378             goto free_skb;
0379 
0380         ethhdr = eth_hdr(skb);
0381         icmph = (struct batadv_icmp_header *)skb->data;
0382         icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmph;
0383         if (icmp_packet_rr->rr_cur >= BATADV_RR_LEN)
0384             goto free_skb;
0385 
0386         ether_addr_copy(icmp_packet_rr->rr[icmp_packet_rr->rr_cur],
0387                 ethhdr->h_dest);
0388         icmp_packet_rr->rr_cur++;
0389     }
0390 
0391     /* packet for me */
0392     if (batadv_is_my_mac(bat_priv, icmph->dst))
0393         return batadv_recv_my_icmp_packet(bat_priv, skb);
0394 
0395     /* TTL exceeded */
0396     if (icmph->ttl < 2)
0397         return batadv_recv_icmp_ttl_exceeded(bat_priv, skb);
0398 
0399     /* get routing information */
0400     orig_node = batadv_orig_hash_find(bat_priv, icmph->dst);
0401     if (!orig_node)
0402         goto free_skb;
0403 
0404     /* create a copy of the skb, if needed, to modify it. */
0405     if (skb_cow(skb, ETH_HLEN) < 0)
0406         goto put_orig_node;
0407 
0408     icmph = (struct batadv_icmp_header *)skb->data;
0409 
0410     /* decrement ttl */
0411     icmph->ttl--;
0412 
0413     /* route it */
0414     res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
0415     if (res == NET_XMIT_SUCCESS)
0416         ret = NET_RX_SUCCESS;
0417 
0418     /* skb was consumed */
0419     skb = NULL;
0420 
0421 put_orig_node:
0422     batadv_orig_node_put(orig_node);
0423 free_skb:
0424     kfree_skb(skb);
0425 
0426     return ret;
0427 }
0428 
0429 /**
0430  * batadv_check_unicast_packet() - Check for malformed unicast packets
0431  * @bat_priv: the bat priv with all the soft interface information
0432  * @skb: packet to check
0433  * @hdr_size: size of header to pull
0434  *
0435  * Checks for short header and bad addresses in the given packet.
0436  *
0437  * Return: negative value when check fails and 0 otherwise. The negative value
0438  * depends on the reason: -ENODATA for bad header, -EBADR for broadcast
0439  * destination or source, and -EREMOTE for non-local (other host) destination.
0440  */
0441 static int batadv_check_unicast_packet(struct batadv_priv *bat_priv,
0442                        struct sk_buff *skb, int hdr_size)
0443 {
0444     struct ethhdr *ethhdr;
0445 
0446     /* drop packet if it has not necessary minimum size */
0447     if (unlikely(!pskb_may_pull(skb, hdr_size)))
0448         return -ENODATA;
0449 
0450     ethhdr = eth_hdr(skb);
0451 
0452     /* packet with unicast indication but non-unicast recipient */
0453     if (!is_valid_ether_addr(ethhdr->h_dest))
0454         return -EBADR;
0455 
0456     /* packet with broadcast/multicast sender address */
0457     if (is_multicast_ether_addr(ethhdr->h_source))
0458         return -EBADR;
0459 
0460     /* not for me */
0461     if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
0462         return -EREMOTE;
0463 
0464     return 0;
0465 }
0466 
0467 /**
0468  * batadv_last_bonding_get() - Get last_bonding_candidate of orig_node
0469  * @orig_node: originator node whose last bonding candidate should be retrieved
0470  *
0471  * Return: last bonding candidate of router or NULL if not found
0472  *
0473  * The object is returned with refcounter increased by 1.
0474  */
0475 static struct batadv_orig_ifinfo *
0476 batadv_last_bonding_get(struct batadv_orig_node *orig_node)
0477 {
0478     struct batadv_orig_ifinfo *last_bonding_candidate;
0479 
0480     spin_lock_bh(&orig_node->neigh_list_lock);
0481     last_bonding_candidate = orig_node->last_bonding_candidate;
0482 
0483     if (last_bonding_candidate)
0484         kref_get(&last_bonding_candidate->refcount);
0485     spin_unlock_bh(&orig_node->neigh_list_lock);
0486 
0487     return last_bonding_candidate;
0488 }
0489 
0490 /**
0491  * batadv_last_bonding_replace() - Replace last_bonding_candidate of orig_node
0492  * @orig_node: originator node whose bonding candidates should be replaced
0493  * @new_candidate: new bonding candidate or NULL
0494  */
0495 static void
0496 batadv_last_bonding_replace(struct batadv_orig_node *orig_node,
0497                 struct batadv_orig_ifinfo *new_candidate)
0498 {
0499     struct batadv_orig_ifinfo *old_candidate;
0500 
0501     spin_lock_bh(&orig_node->neigh_list_lock);
0502     old_candidate = orig_node->last_bonding_candidate;
0503 
0504     if (new_candidate)
0505         kref_get(&new_candidate->refcount);
0506     orig_node->last_bonding_candidate = new_candidate;
0507     spin_unlock_bh(&orig_node->neigh_list_lock);
0508 
0509     batadv_orig_ifinfo_put(old_candidate);
0510 }
0511 
0512 /**
0513  * batadv_find_router() - find a suitable router for this originator
0514  * @bat_priv: the bat priv with all the soft interface information
0515  * @orig_node: the destination node
0516  * @recv_if: pointer to interface this packet was received on
0517  *
0518  * Return: the router which should be used for this orig_node on
0519  * this interface, or NULL if not available.
0520  */
0521 struct batadv_neigh_node *
0522 batadv_find_router(struct batadv_priv *bat_priv,
0523            struct batadv_orig_node *orig_node,
0524            struct batadv_hard_iface *recv_if)
0525 {
0526     struct batadv_algo_ops *bao = bat_priv->algo_ops;
0527     struct batadv_neigh_node *first_candidate_router = NULL;
0528     struct batadv_neigh_node *next_candidate_router = NULL;
0529     struct batadv_neigh_node *router, *cand_router = NULL;
0530     struct batadv_neigh_node *last_cand_router = NULL;
0531     struct batadv_orig_ifinfo *cand, *first_candidate = NULL;
0532     struct batadv_orig_ifinfo *next_candidate = NULL;
0533     struct batadv_orig_ifinfo *last_candidate;
0534     bool last_candidate_found = false;
0535 
0536     if (!orig_node)
0537         return NULL;
0538 
0539     router = batadv_orig_router_get(orig_node, recv_if);
0540 
0541     if (!router)
0542         return router;
0543 
0544     /* only consider bonding for recv_if == BATADV_IF_DEFAULT (first hop)
0545      * and if activated.
0546      */
0547     if (!(recv_if == BATADV_IF_DEFAULT && atomic_read(&bat_priv->bonding)))
0548         return router;
0549 
0550     /* bonding: loop through the list of possible routers found
0551      * for the various outgoing interfaces and find a candidate after
0552      * the last chosen bonding candidate (next_candidate). If no such
0553      * router is found, use the first candidate found (the previously
0554      * chosen bonding candidate might have been the last one in the list).
0555      * If this can't be found either, return the previously chosen
0556      * router - obviously there are no other candidates.
0557      */
0558     rcu_read_lock();
0559     last_candidate = batadv_last_bonding_get(orig_node);
0560     if (last_candidate)
0561         last_cand_router = rcu_dereference(last_candidate->router);
0562 
0563     hlist_for_each_entry_rcu(cand, &orig_node->ifinfo_list, list) {
0564         /* acquire some structures and references ... */
0565         if (!kref_get_unless_zero(&cand->refcount))
0566             continue;
0567 
0568         cand_router = rcu_dereference(cand->router);
0569         if (!cand_router)
0570             goto next;
0571 
0572         if (!kref_get_unless_zero(&cand_router->refcount)) {
0573             cand_router = NULL;
0574             goto next;
0575         }
0576 
0577         /* alternative candidate should be good enough to be
0578          * considered
0579          */
0580         if (!bao->neigh.is_similar_or_better(cand_router,
0581                              cand->if_outgoing, router,
0582                              recv_if))
0583             goto next;
0584 
0585         /* don't use the same router twice */
0586         if (last_cand_router == cand_router)
0587             goto next;
0588 
0589         /* mark the first possible candidate */
0590         if (!first_candidate) {
0591             kref_get(&cand_router->refcount);
0592             kref_get(&cand->refcount);
0593             first_candidate = cand;
0594             first_candidate_router = cand_router;
0595         }
0596 
0597         /* check if the loop has already passed the previously selected
0598          * candidate ... this function should select the next candidate
0599          * AFTER the previously used bonding candidate.
0600          */
0601         if (!last_candidate || last_candidate_found) {
0602             next_candidate = cand;
0603             next_candidate_router = cand_router;
0604             break;
0605         }
0606 
0607         if (last_candidate == cand)
0608             last_candidate_found = true;
0609 next:
0610         /* free references */
0611         if (cand_router) {
0612             batadv_neigh_node_put(cand_router);
0613             cand_router = NULL;
0614         }
0615         batadv_orig_ifinfo_put(cand);
0616     }
0617     rcu_read_unlock();
0618 
0619     /* After finding candidates, handle the three cases:
0620      * 1) there is a next candidate, use that
0621      * 2) there is no next candidate, use the first of the list
0622      * 3) there is no candidate at all, return the default router
0623      */
0624     if (next_candidate) {
0625         batadv_neigh_node_put(router);
0626 
0627         kref_get(&next_candidate_router->refcount);
0628         router = next_candidate_router;
0629         batadv_last_bonding_replace(orig_node, next_candidate);
0630     } else if (first_candidate) {
0631         batadv_neigh_node_put(router);
0632 
0633         kref_get(&first_candidate_router->refcount);
0634         router = first_candidate_router;
0635         batadv_last_bonding_replace(orig_node, first_candidate);
0636     } else {
0637         batadv_last_bonding_replace(orig_node, NULL);
0638     }
0639 
0640     /* cleanup of candidates */
0641     if (first_candidate) {
0642         batadv_neigh_node_put(first_candidate_router);
0643         batadv_orig_ifinfo_put(first_candidate);
0644     }
0645 
0646     if (next_candidate) {
0647         batadv_neigh_node_put(next_candidate_router);
0648         batadv_orig_ifinfo_put(next_candidate);
0649     }
0650 
0651     batadv_orig_ifinfo_put(last_candidate);
0652 
0653     return router;
0654 }
0655 
0656 static int batadv_route_unicast_packet(struct sk_buff *skb,
0657                        struct batadv_hard_iface *recv_if)
0658 {
0659     struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
0660     struct batadv_orig_node *orig_node = NULL;
0661     struct batadv_unicast_packet *unicast_packet;
0662     struct ethhdr *ethhdr = eth_hdr(skb);
0663     int res, hdr_len, ret = NET_RX_DROP;
0664     unsigned int len;
0665 
0666     unicast_packet = (struct batadv_unicast_packet *)skb->data;
0667 
0668     /* TTL exceeded */
0669     if (unicast_packet->ttl < 2) {
0670         pr_debug("Warning - can't forward unicast packet from %pM to %pM: ttl exceeded\n",
0671              ethhdr->h_source, unicast_packet->dest);
0672         goto free_skb;
0673     }
0674 
0675     /* get routing information */
0676     orig_node = batadv_orig_hash_find(bat_priv, unicast_packet->dest);
0677 
0678     if (!orig_node)
0679         goto free_skb;
0680 
0681     /* create a copy of the skb, if needed, to modify it. */
0682     if (skb_cow(skb, ETH_HLEN) < 0)
0683         goto put_orig_node;
0684 
0685     /* decrement ttl */
0686     unicast_packet = (struct batadv_unicast_packet *)skb->data;
0687     unicast_packet->ttl--;
0688 
0689     switch (unicast_packet->packet_type) {
0690     case BATADV_UNICAST_4ADDR:
0691         hdr_len = sizeof(struct batadv_unicast_4addr_packet);
0692         break;
0693     case BATADV_UNICAST:
0694         hdr_len = sizeof(struct batadv_unicast_packet);
0695         break;
0696     default:
0697         /* other packet types not supported - yet */
0698         hdr_len = -1;
0699         break;
0700     }
0701 
0702     if (hdr_len > 0)
0703         batadv_skb_set_priority(skb, hdr_len);
0704 
0705     len = skb->len;
0706     res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
0707 
0708     /* translate transmit result into receive result */
0709     if (res == NET_XMIT_SUCCESS) {
0710         ret = NET_RX_SUCCESS;
0711         /* skb was transmitted and consumed */
0712         batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD);
0713         batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES,
0714                    len + ETH_HLEN);
0715     }
0716 
0717     /* skb was consumed */
0718     skb = NULL;
0719 
0720 put_orig_node:
0721     batadv_orig_node_put(orig_node);
0722 free_skb:
0723     kfree_skb(skb);
0724 
0725     return ret;
0726 }
0727 
0728 /**
0729  * batadv_reroute_unicast_packet() - update the unicast header for re-routing
0730  * @bat_priv: the bat priv with all the soft interface information
0731  * @skb: unicast packet to process
0732  * @unicast_packet: the unicast header to be updated
0733  * @dst_addr: the payload destination
0734  * @vid: VLAN identifier
0735  *
0736  * Search the translation table for dst_addr and update the unicast header with
0737  * the new corresponding information (originator address where the destination
0738  * client currently is and its known TTVN)
0739  *
0740  * Return: true if the packet header has been updated, false otherwise
0741  */
0742 static bool
0743 batadv_reroute_unicast_packet(struct batadv_priv *bat_priv, struct sk_buff *skb,
0744                   struct batadv_unicast_packet *unicast_packet,
0745                   u8 *dst_addr, unsigned short vid)
0746 {
0747     struct batadv_orig_node *orig_node = NULL;
0748     struct batadv_hard_iface *primary_if = NULL;
0749     bool ret = false;
0750     const u8 *orig_addr;
0751     u8 orig_ttvn;
0752 
0753     if (batadv_is_my_client(bat_priv, dst_addr, vid)) {
0754         primary_if = batadv_primary_if_get_selected(bat_priv);
0755         if (!primary_if)
0756             goto out;
0757         orig_addr = primary_if->net_dev->dev_addr;
0758         orig_ttvn = (u8)atomic_read(&bat_priv->tt.vn);
0759     } else {
0760         orig_node = batadv_transtable_search(bat_priv, NULL, dst_addr,
0761                              vid);
0762         if (!orig_node)
0763             goto out;
0764 
0765         if (batadv_compare_eth(orig_node->orig, unicast_packet->dest))
0766             goto out;
0767 
0768         orig_addr = orig_node->orig;
0769         orig_ttvn = (u8)atomic_read(&orig_node->last_ttvn);
0770     }
0771 
0772     /* update the packet header */
0773     skb_postpull_rcsum(skb, unicast_packet, sizeof(*unicast_packet));
0774     ether_addr_copy(unicast_packet->dest, orig_addr);
0775     unicast_packet->ttvn = orig_ttvn;
0776     skb_postpush_rcsum(skb, unicast_packet, sizeof(*unicast_packet));
0777 
0778     ret = true;
0779 out:
0780     batadv_hardif_put(primary_if);
0781     batadv_orig_node_put(orig_node);
0782 
0783     return ret;
0784 }
0785 
0786 static bool batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
0787                       struct sk_buff *skb, int hdr_len)
0788 {
0789     struct batadv_unicast_packet *unicast_packet;
0790     struct batadv_hard_iface *primary_if;
0791     struct batadv_orig_node *orig_node;
0792     u8 curr_ttvn, old_ttvn;
0793     struct ethhdr *ethhdr;
0794     unsigned short vid;
0795     int is_old_ttvn;
0796 
0797     /* check if there is enough data before accessing it */
0798     if (!pskb_may_pull(skb, hdr_len + ETH_HLEN))
0799         return false;
0800 
0801     /* create a copy of the skb (in case of for re-routing) to modify it. */
0802     if (skb_cow(skb, sizeof(*unicast_packet)) < 0)
0803         return false;
0804 
0805     unicast_packet = (struct batadv_unicast_packet *)skb->data;
0806     vid = batadv_get_vid(skb, hdr_len);
0807     ethhdr = (struct ethhdr *)(skb->data + hdr_len);
0808 
0809     /* do not reroute multicast frames in a unicast header */
0810     if (is_multicast_ether_addr(ethhdr->h_dest))
0811         return true;
0812 
0813     /* check if the destination client was served by this node and it is now
0814      * roaming. In this case, it means that the node has got a ROAM_ADV
0815      * message and that it knows the new destination in the mesh to re-route
0816      * the packet to
0817      */
0818     if (batadv_tt_local_client_is_roaming(bat_priv, ethhdr->h_dest, vid)) {
0819         if (batadv_reroute_unicast_packet(bat_priv, skb, unicast_packet,
0820                           ethhdr->h_dest, vid))
0821             batadv_dbg_ratelimited(BATADV_DBG_TT,
0822                            bat_priv,
0823                            "Rerouting unicast packet to %pM (dst=%pM): Local Roaming\n",
0824                            unicast_packet->dest,
0825                            ethhdr->h_dest);
0826         /* at this point the mesh destination should have been
0827          * substituted with the originator address found in the global
0828          * table. If not, let the packet go untouched anyway because
0829          * there is nothing the node can do
0830          */
0831         return true;
0832     }
0833 
0834     /* retrieve the TTVN known by this node for the packet destination. This
0835      * value is used later to check if the node which sent (or re-routed
0836      * last time) the packet had an updated information or not
0837      */
0838     curr_ttvn = (u8)atomic_read(&bat_priv->tt.vn);
0839     if (!batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
0840         orig_node = batadv_orig_hash_find(bat_priv,
0841                           unicast_packet->dest);
0842         /* if it is not possible to find the orig_node representing the
0843          * destination, the packet can immediately be dropped as it will
0844          * not be possible to deliver it
0845          */
0846         if (!orig_node)
0847             return false;
0848 
0849         curr_ttvn = (u8)atomic_read(&orig_node->last_ttvn);
0850         batadv_orig_node_put(orig_node);
0851     }
0852 
0853     /* check if the TTVN contained in the packet is fresher than what the
0854      * node knows
0855      */
0856     is_old_ttvn = batadv_seq_before(unicast_packet->ttvn, curr_ttvn);
0857     if (!is_old_ttvn)
0858         return true;
0859 
0860     old_ttvn = unicast_packet->ttvn;
0861     /* the packet was forged based on outdated network information. Its
0862      * destination can possibly be updated and forwarded towards the new
0863      * target host
0864      */
0865     if (batadv_reroute_unicast_packet(bat_priv, skb, unicast_packet,
0866                       ethhdr->h_dest, vid)) {
0867         batadv_dbg_ratelimited(BATADV_DBG_TT, bat_priv,
0868                        "Rerouting unicast packet to %pM (dst=%pM): TTVN mismatch old_ttvn=%u new_ttvn=%u\n",
0869                        unicast_packet->dest, ethhdr->h_dest,
0870                        old_ttvn, curr_ttvn);
0871         return true;
0872     }
0873 
0874     /* the packet has not been re-routed: either the destination is
0875      * currently served by this node or there is no destination at all and
0876      * it is possible to drop the packet
0877      */
0878     if (!batadv_is_my_client(bat_priv, ethhdr->h_dest, vid))
0879         return false;
0880 
0881     /* update the header in order to let the packet be delivered to this
0882      * node's soft interface
0883      */
0884     primary_if = batadv_primary_if_get_selected(bat_priv);
0885     if (!primary_if)
0886         return false;
0887 
0888     /* update the packet header */
0889     skb_postpull_rcsum(skb, unicast_packet, sizeof(*unicast_packet));
0890     ether_addr_copy(unicast_packet->dest, primary_if->net_dev->dev_addr);
0891     unicast_packet->ttvn = curr_ttvn;
0892     skb_postpush_rcsum(skb, unicast_packet, sizeof(*unicast_packet));
0893 
0894     batadv_hardif_put(primary_if);
0895 
0896     return true;
0897 }
0898 
0899 /**
0900  * batadv_recv_unhandled_unicast_packet() - receive and process packets which
0901  *  are in the unicast number space but not yet known to the implementation
0902  * @skb: unicast tvlv packet to process
0903  * @recv_if: pointer to interface this packet was received on
0904  *
0905  * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
0906  * otherwise.
0907  */
0908 int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb,
0909                      struct batadv_hard_iface *recv_if)
0910 {
0911     struct batadv_unicast_packet *unicast_packet;
0912     struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
0913     int check, hdr_size = sizeof(*unicast_packet);
0914 
0915     check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
0916     if (check < 0)
0917         goto free_skb;
0918 
0919     /* we don't know about this type, drop it. */
0920     unicast_packet = (struct batadv_unicast_packet *)skb->data;
0921     if (batadv_is_my_mac(bat_priv, unicast_packet->dest))
0922         goto free_skb;
0923 
0924     return batadv_route_unicast_packet(skb, recv_if);
0925 
0926 free_skb:
0927     kfree_skb(skb);
0928     return NET_RX_DROP;
0929 }
0930 
0931 /**
0932  * batadv_recv_unicast_packet() - Process incoming unicast packet
0933  * @skb: incoming packet buffer
0934  * @recv_if: incoming hard interface
0935  *
0936  * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure
0937  */
0938 int batadv_recv_unicast_packet(struct sk_buff *skb,
0939                    struct batadv_hard_iface *recv_if)
0940 {
0941     struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
0942     struct batadv_unicast_packet *unicast_packet;
0943     struct batadv_unicast_4addr_packet *unicast_4addr_packet;
0944     u8 *orig_addr, *orig_addr_gw;
0945     struct batadv_orig_node *orig_node = NULL, *orig_node_gw = NULL;
0946     int check, hdr_size = sizeof(*unicast_packet);
0947     enum batadv_subtype subtype;
0948     int ret = NET_RX_DROP;
0949     bool is4addr, is_gw;
0950 
0951     unicast_packet = (struct batadv_unicast_packet *)skb->data;
0952     is4addr = unicast_packet->packet_type == BATADV_UNICAST_4ADDR;
0953     /* the caller function should have already pulled 2 bytes */
0954     if (is4addr)
0955         hdr_size = sizeof(*unicast_4addr_packet);
0956 
0957     /* function returns -EREMOTE for promiscuous packets */
0958     check = batadv_check_unicast_packet(bat_priv, skb, hdr_size);
0959 
0960     /* Even though the packet is not for us, we might save it to use for
0961      * decoding a later received coded packet
0962      */
0963     if (check == -EREMOTE)
0964         batadv_nc_skb_store_sniffed_unicast(bat_priv, skb);
0965 
0966     if (check < 0)
0967         goto free_skb;
0968     if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size))
0969         goto free_skb;
0970 
0971     unicast_packet = (struct batadv_unicast_packet *)skb->data;
0972 
0973     /* packet for me */
0974     if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
0975         /* If this is a unicast packet from another backgone gw,
0976          * drop it.
0977          */
0978         orig_addr_gw = eth_hdr(skb)->h_source;
0979         orig_node_gw = batadv_orig_hash_find(bat_priv, orig_addr_gw);
0980         if (orig_node_gw) {
0981             is_gw = batadv_bla_is_backbone_gw(skb, orig_node_gw,
0982                               hdr_size);
0983             batadv_orig_node_put(orig_node_gw);
0984             if (is_gw) {
0985                 batadv_dbg(BATADV_DBG_BLA, bat_priv,
0986                        "%s(): Dropped unicast pkt received from another backbone gw %pM.\n",
0987                        __func__, orig_addr_gw);
0988                 goto free_skb;
0989             }
0990         }
0991 
0992         if (is4addr) {
0993             unicast_4addr_packet =
0994                 (struct batadv_unicast_4addr_packet *)skb->data;
0995             subtype = unicast_4addr_packet->subtype;
0996             batadv_dat_inc_counter(bat_priv, subtype);
0997 
0998             /* Only payload data should be considered for speedy
0999              * join. For example, DAT also uses unicast 4addr
1000              * types, but those packets should not be considered
1001              * for speedy join, since the clients do not actually
1002              * reside at the sending originator.
1003              */
1004             if (subtype == BATADV_P_DATA) {
1005                 orig_addr = unicast_4addr_packet->src;
1006                 orig_node = batadv_orig_hash_find(bat_priv,
1007                                   orig_addr);
1008             }
1009         }
1010 
1011         if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb,
1012                               hdr_size))
1013             goto rx_success;
1014         if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb,
1015                             hdr_size))
1016             goto rx_success;
1017 
1018         batadv_dat_snoop_incoming_dhcp_ack(bat_priv, skb, hdr_size);
1019 
1020         batadv_interface_rx(recv_if->soft_iface, skb, hdr_size,
1021                     orig_node);
1022 
1023 rx_success:
1024         batadv_orig_node_put(orig_node);
1025 
1026         return NET_RX_SUCCESS;
1027     }
1028 
1029     ret = batadv_route_unicast_packet(skb, recv_if);
1030     /* skb was consumed */
1031     skb = NULL;
1032 
1033 free_skb:
1034     kfree_skb(skb);
1035 
1036     return ret;
1037 }
1038 
1039 /**
1040  * batadv_recv_unicast_tvlv() - receive and process unicast tvlv packets
1041  * @skb: unicast tvlv packet to process
1042  * @recv_if: pointer to interface this packet was received on
1043  *
1044  * Return: NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
1045  * otherwise.
1046  */
1047 int batadv_recv_unicast_tvlv(struct sk_buff *skb,
1048                  struct batadv_hard_iface *recv_if)
1049 {
1050     struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
1051     struct batadv_unicast_tvlv_packet *unicast_tvlv_packet;
1052     unsigned char *tvlv_buff;
1053     u16 tvlv_buff_len;
1054     int hdr_size = sizeof(*unicast_tvlv_packet);
1055     int ret = NET_RX_DROP;
1056 
1057     if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0)
1058         goto free_skb;
1059 
1060     /* the header is likely to be modified while forwarding */
1061     if (skb_cow(skb, hdr_size) < 0)
1062         goto free_skb;
1063 
1064     /* packet needs to be linearized to access the tvlv content */
1065     if (skb_linearize(skb) < 0)
1066         goto free_skb;
1067 
1068     unicast_tvlv_packet = (struct batadv_unicast_tvlv_packet *)skb->data;
1069 
1070     tvlv_buff = (unsigned char *)(skb->data + hdr_size);
1071     tvlv_buff_len = ntohs(unicast_tvlv_packet->tvlv_len);
1072 
1073     if (tvlv_buff_len > skb->len - hdr_size)
1074         goto free_skb;
1075 
1076     ret = batadv_tvlv_containers_process(bat_priv, false, NULL,
1077                          unicast_tvlv_packet->src,
1078                          unicast_tvlv_packet->dst,
1079                          tvlv_buff, tvlv_buff_len);
1080 
1081     if (ret != NET_RX_SUCCESS) {
1082         ret = batadv_route_unicast_packet(skb, recv_if);
1083         /* skb was consumed */
1084         skb = NULL;
1085     }
1086 
1087 free_skb:
1088     kfree_skb(skb);
1089 
1090     return ret;
1091 }
1092 
1093 /**
1094  * batadv_recv_frag_packet() - process received fragment
1095  * @skb: the received fragment
1096  * @recv_if: interface that the skb is received on
1097  *
1098  * This function does one of the three following things: 1) Forward fragment, if
1099  * the assembled packet will exceed our MTU; 2) Buffer fragment, if we still
1100  * lack further fragments; 3) Merge fragments, if we have all needed parts.
1101  *
1102  * Return: NET_RX_DROP if the skb is not consumed, NET_RX_SUCCESS otherwise.
1103  */
1104 int batadv_recv_frag_packet(struct sk_buff *skb,
1105                 struct batadv_hard_iface *recv_if)
1106 {
1107     struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
1108     struct batadv_orig_node *orig_node_src = NULL;
1109     struct batadv_frag_packet *frag_packet;
1110     int ret = NET_RX_DROP;
1111 
1112     if (batadv_check_unicast_packet(bat_priv, skb,
1113                     sizeof(*frag_packet)) < 0)
1114         goto free_skb;
1115 
1116     frag_packet = (struct batadv_frag_packet *)skb->data;
1117     orig_node_src = batadv_orig_hash_find(bat_priv, frag_packet->orig);
1118     if (!orig_node_src)
1119         goto free_skb;
1120 
1121     skb->priority = frag_packet->priority + 256;
1122 
1123     /* Route the fragment if it is not for us and too big to be merged. */
1124     if (!batadv_is_my_mac(bat_priv, frag_packet->dest) &&
1125         batadv_frag_skb_fwd(skb, recv_if, orig_node_src)) {
1126         /* skb was consumed */
1127         skb = NULL;
1128         ret = NET_RX_SUCCESS;
1129         goto put_orig_node;
1130     }
1131 
1132     batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_RX);
1133     batadv_add_counter(bat_priv, BATADV_CNT_FRAG_RX_BYTES, skb->len);
1134 
1135     /* Add fragment to buffer and merge if possible. */
1136     if (!batadv_frag_skb_buffer(&skb, orig_node_src))
1137         goto put_orig_node;
1138 
1139     /* Deliver merged packet to the appropriate handler, if it was
1140      * merged
1141      */
1142     if (skb) {
1143         batadv_batman_skb_recv(skb, recv_if->net_dev,
1144                        &recv_if->batman_adv_ptype, NULL);
1145         /* skb was consumed */
1146         skb = NULL;
1147     }
1148 
1149     ret = NET_RX_SUCCESS;
1150 
1151 put_orig_node:
1152     batadv_orig_node_put(orig_node_src);
1153 free_skb:
1154     kfree_skb(skb);
1155 
1156     return ret;
1157 }
1158 
1159 /**
1160  * batadv_recv_bcast_packet() - Process incoming broadcast packet
1161  * @skb: incoming packet buffer
1162  * @recv_if: incoming hard interface
1163  *
1164  * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure
1165  */
1166 int batadv_recv_bcast_packet(struct sk_buff *skb,
1167                  struct batadv_hard_iface *recv_if)
1168 {
1169     struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
1170     struct batadv_orig_node *orig_node = NULL;
1171     struct batadv_bcast_packet *bcast_packet;
1172     struct ethhdr *ethhdr;
1173     int hdr_size = sizeof(*bcast_packet);
1174     s32 seq_diff;
1175     u32 seqno;
1176     int ret;
1177 
1178     /* drop packet if it has not necessary minimum size */
1179     if (unlikely(!pskb_may_pull(skb, hdr_size)))
1180         goto free_skb;
1181 
1182     ethhdr = eth_hdr(skb);
1183 
1184     /* packet with broadcast indication but unicast recipient */
1185     if (!is_broadcast_ether_addr(ethhdr->h_dest))
1186         goto free_skb;
1187 
1188     /* packet with broadcast/multicast sender address */
1189     if (is_multicast_ether_addr(ethhdr->h_source))
1190         goto free_skb;
1191 
1192     /* ignore broadcasts sent by myself */
1193     if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
1194         goto free_skb;
1195 
1196     bcast_packet = (struct batadv_bcast_packet *)skb->data;
1197 
1198     /* ignore broadcasts originated by myself */
1199     if (batadv_is_my_mac(bat_priv, bcast_packet->orig))
1200         goto free_skb;
1201 
1202     if (bcast_packet->ttl-- < 2)
1203         goto free_skb;
1204 
1205     orig_node = batadv_orig_hash_find(bat_priv, bcast_packet->orig);
1206 
1207     if (!orig_node)
1208         goto free_skb;
1209 
1210     spin_lock_bh(&orig_node->bcast_seqno_lock);
1211 
1212     seqno = ntohl(bcast_packet->seqno);
1213     /* check whether the packet is a duplicate */
1214     if (batadv_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno,
1215                 seqno))
1216         goto spin_unlock;
1217 
1218     seq_diff = seqno - orig_node->last_bcast_seqno;
1219 
1220     /* check whether the packet is old and the host just restarted. */
1221     if (batadv_window_protected(bat_priv, seq_diff,
1222                     BATADV_BCAST_MAX_AGE,
1223                     &orig_node->bcast_seqno_reset, NULL))
1224         goto spin_unlock;
1225 
1226     /* mark broadcast in flood history, update window position
1227      * if required.
1228      */
1229     if (batadv_bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1))
1230         orig_node->last_bcast_seqno = seqno;
1231 
1232     spin_unlock_bh(&orig_node->bcast_seqno_lock);
1233 
1234     /* check whether this has been sent by another originator before */
1235     if (batadv_bla_check_bcast_duplist(bat_priv, skb))
1236         goto free_skb;
1237 
1238     batadv_skb_set_priority(skb, sizeof(struct batadv_bcast_packet));
1239 
1240     /* rebroadcast packet */
1241     ret = batadv_forw_bcast_packet(bat_priv, skb, 0, false);
1242     if (ret == NETDEV_TX_BUSY)
1243         goto free_skb;
1244 
1245     /* don't hand the broadcast up if it is from an originator
1246      * from the same backbone.
1247      */
1248     if (batadv_bla_is_backbone_gw(skb, orig_node, hdr_size))
1249         goto free_skb;
1250 
1251     if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb, hdr_size))
1252         goto rx_success;
1253     if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, hdr_size))
1254         goto rx_success;
1255 
1256     batadv_dat_snoop_incoming_dhcp_ack(bat_priv, skb, hdr_size);
1257 
1258     /* broadcast for me */
1259     batadv_interface_rx(recv_if->soft_iface, skb, hdr_size, orig_node);
1260 
1261 rx_success:
1262     ret = NET_RX_SUCCESS;
1263     goto out;
1264 
1265 spin_unlock:
1266     spin_unlock_bh(&orig_node->bcast_seqno_lock);
1267 free_skb:
1268     kfree_skb(skb);
1269     ret = NET_RX_DROP;
1270 out:
1271     batadv_orig_node_put(orig_node);
1272     return ret;
1273 }