2525#include <linux/lockdep.h>
2626#include <linux/netdevice.h>
2727#include <linux/netlink.h>
28+ #include <linux/preempt.h>
2829#include <linux/rculist.h>
2930#include <linux/rcupdate.h>
3031#include <linux/seq_file.h>
@@ -83,11 +84,12 @@ static inline u32 batadv_choose_claim(const void *data, u32 size)
8384 */
8485static inline u32 batadv_choose_backbone_gw (const void * data , u32 size )
8586{
86- const struct batadv_bla_claim * claim = ( struct batadv_bla_claim * ) data ;
87+ const struct batadv_bla_backbone_gw * gw ;
8788 u32 hash = 0 ;
8889
89- hash = jhash (& claim -> addr , sizeof (claim -> addr ), hash );
90- hash = jhash (& claim -> vid , sizeof (claim -> vid ), hash );
90+ gw = (struct batadv_bla_backbone_gw * )data ;
91+ hash = jhash (& gw -> orig , sizeof (gw -> orig ), hash );
92+ hash = jhash (& gw -> vid , sizeof (gw -> vid ), hash );
9193
9294 return hash % size ;
9395}
@@ -1579,13 +1581,16 @@ int batadv_bla_init(struct batadv_priv *bat_priv)
15791581}
15801582
15811583/**
1582- * batadv_bla_check_bcast_duplist () - Check if a frame is in the broadcast dup.
1584+ * batadv_bla_check_duplist () - Check if a frame is in the broadcast dup.
15831585 * @bat_priv: the bat priv with all the soft interface information
1584- * @skb: contains the bcast_packet to be checked
1586+ * @skb: contains the multicast packet to be checked
1587+ * @payload_ptr: pointer to position inside the head buffer of the skb
1588+ * marking the start of the data to be CRC'ed
1589+ * @orig: originator mac address, NULL if unknown
15851590 *
1586- * check if it is on our broadcast list. Another gateway might
1587- * have sent the same packet because it is connected to the same backbone,
1588- * so we have to remove this duplicate.
1591+ * Check if it is on our broadcast list. Another gateway might have sent the
1592+ * same packet because it is connected to the same backbone, so we have to
1593+ * remove this duplicate.
15891594 *
15901595 * This is performed by checking the CRC, which will tell us
15911596 * with a good chance that it is the same packet. If it is furthermore
@@ -1594,19 +1599,17 @@ int batadv_bla_init(struct batadv_priv *bat_priv)
15941599 *
15951600 * Return: true if a packet is in the duplicate list, false otherwise.
15961601 */
1597- bool batadv_bla_check_bcast_duplist (struct batadv_priv * bat_priv ,
1598- struct sk_buff * skb )
1602+ static bool batadv_bla_check_duplist (struct batadv_priv * bat_priv ,
1603+ struct sk_buff * skb , u8 * payload_ptr ,
1604+ const u8 * orig )
15991605{
1600- int i , curr ;
1601- __be32 crc ;
1602- struct batadv_bcast_packet * bcast_packet ;
16031606 struct batadv_bcast_duplist_entry * entry ;
16041607 bool ret = false;
1605-
1606- bcast_packet = ( struct batadv_bcast_packet * ) skb -> data ;
1608+ int i , curr ;
1609+ __be32 crc ;
16071610
16081611 /* calculate the crc ... */
1609- crc = batadv_skb_crc32 (skb , ( u8 * )( bcast_packet + 1 ) );
1612+ crc = batadv_skb_crc32 (skb , payload_ptr );
16101613
16111614 spin_lock_bh (& bat_priv -> bla .bcast_duplist_lock );
16121615
@@ -1625,8 +1628,21 @@ bool batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
16251628 if (entry -> crc != crc )
16261629 continue ;
16271630
1628- if (batadv_compare_eth (entry -> orig , bcast_packet -> orig ))
1629- continue ;
1631+ /* are the originators both known and not anonymous? */
1632+ if (orig && !is_zero_ether_addr (orig ) &&
1633+ !is_zero_ether_addr (entry -> orig )) {
1634+ /* If known, check if the new frame came from
1635+ * the same originator:
1636+ * We are safe to take identical frames from the
1637+ * same orig, if known, as multiplications in
1638+ * the mesh are detected via the (orig, seqno) pair.
1639+ * So we can be a bit more liberal here and allow
1640+ * identical frames from the same orig which the source
1641+ * host might have sent multiple times on purpose.
1642+ */
1643+ if (batadv_compare_eth (entry -> orig , orig ))
1644+ continue ;
1645+ }
16301646
16311647 /* this entry seems to match: same crc, not too old,
16321648 * and from another gw. therefore return true to forbid it.
@@ -1642,7 +1658,14 @@ bool batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
16421658 entry = & bat_priv -> bla .bcast_duplist [curr ];
16431659 entry -> crc = crc ;
16441660 entry -> entrytime = jiffies ;
1645- ether_addr_copy (entry -> orig , bcast_packet -> orig );
1661+
1662+ /* known originator */
1663+ if (orig )
1664+ ether_addr_copy (entry -> orig , orig );
1665+ /* anonymous originator */
1666+ else
1667+ eth_zero_addr (entry -> orig );
1668+
16461669 bat_priv -> bla .bcast_duplist_curr = curr ;
16471670
16481671out :
@@ -1651,6 +1674,48 @@ bool batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
16511674 return ret ;
16521675}
16531676
1677+ /**
1678+ * batadv_bla_check_ucast_duplist() - Check if a frame is in the broadcast dup.
1679+ * @bat_priv: the bat priv with all the soft interface information
1680+ * @skb: contains the multicast packet to be checked, decapsulated from a
1681+ * unicast_packet
1682+ *
1683+ * Check if it is on our broadcast list. Another gateway might have sent the
1684+ * same packet because it is connected to the same backbone, so we have to
1685+ * remove this duplicate.
1686+ *
1687+ * Return: true if a packet is in the duplicate list, false otherwise.
1688+ */
1689+ static bool batadv_bla_check_ucast_duplist (struct batadv_priv * bat_priv ,
1690+ struct sk_buff * skb )
1691+ {
1692+ return batadv_bla_check_duplist (bat_priv , skb , (u8 * )skb -> data , NULL );
1693+ }
1694+
1695+ /**
1696+ * batadv_bla_check_bcast_duplist() - Check if a frame is in the broadcast dup.
1697+ * @bat_priv: the bat priv with all the soft interface information
1698+ * @skb: contains the bcast_packet to be checked
1699+ *
1700+ * Check if it is on our broadcast list. Another gateway might have sent the
1701+ * same packet because it is connected to the same backbone, so we have to
1702+ * remove this duplicate.
1703+ *
1704+ * Return: true if a packet is in the duplicate list, false otherwise.
1705+ */
1706+ bool batadv_bla_check_bcast_duplist (struct batadv_priv * bat_priv ,
1707+ struct sk_buff * skb )
1708+ {
1709+ struct batadv_bcast_packet * bcast_packet ;
1710+ u8 * payload_ptr ;
1711+
1712+ bcast_packet = (struct batadv_bcast_packet * )skb -> data ;
1713+ payload_ptr = (u8 * )(bcast_packet + 1 );
1714+
1715+ return batadv_bla_check_duplist (bat_priv , skb , payload_ptr ,
1716+ bcast_packet -> orig );
1717+ }
1718+
16541719/**
16551720 * batadv_bla_is_backbone_gw_orig() - Check if the originator is a gateway for
16561721 * the VLAN identified by vid.
@@ -1812,7 +1877,7 @@ batadv_bla_loopdetect_check(struct batadv_priv *bat_priv, struct sk_buff *skb,
18121877 * @bat_priv: the bat priv with all the soft interface information
18131878 * @skb: the frame to be checked
18141879 * @vid: the VLAN ID of the frame
1815- * @is_bcast : the packet came in a broadcast packet type.
1880+ * @packet_type : the batman packet type this frame came in
18161881 *
18171882 * batadv_bla_rx avoidance checks if:
18181883 * * we have to race for a claim
@@ -1824,7 +1889,7 @@ batadv_bla_loopdetect_check(struct batadv_priv *bat_priv, struct sk_buff *skb,
18241889 * further process the skb.
18251890 */
18261891bool batadv_bla_rx (struct batadv_priv * bat_priv , struct sk_buff * skb ,
1827- unsigned short vid , bool is_bcast )
1892+ unsigned short vid , int packet_type )
18281893{
18291894 struct batadv_bla_backbone_gw * backbone_gw ;
18301895 struct ethhdr * ethhdr ;
@@ -1846,9 +1911,32 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
18461911 goto handled ;
18471912
18481913 if (unlikely (atomic_read (& bat_priv -> bla .num_requests )))
1849- /* don't allow broadcasts while requests are in flight */
1850- if (is_multicast_ether_addr (ethhdr -> h_dest ) && is_bcast )
1851- goto handled ;
1914+ /* don't allow multicast packets while requests are in flight */
1915+ if (is_multicast_ether_addr (ethhdr -> h_dest ))
1916+ /* Both broadcast flooding or multicast-via-unicasts
1917+ * delivery might send to multiple backbone gateways
1918+ * sharing the same LAN and therefore need to coordinate
1919+ * which backbone gateway forwards into the LAN,
1920+ * by claiming the payload source address.
1921+ *
1922+ * Broadcast flooding and multicast-via-unicasts
1923+ * delivery use the following two batman packet types.
1924+ * Note: explicitly exclude BATADV_UNICAST_4ADDR,
1925+ * as the DHCP gateway feature will send explicitly
1926+ * to only one BLA gateway, so the claiming process
1927+ * should be avoided there.
1928+ */
1929+ if (packet_type == BATADV_BCAST ||
1930+ packet_type == BATADV_UNICAST )
1931+ goto handled ;
1932+
1933+ /* potential duplicates from foreign BLA backbone gateways via
1934+ * multicast-in-unicast packets
1935+ */
1936+ if (is_multicast_ether_addr (ethhdr -> h_dest ) &&
1937+ packet_type == BATADV_UNICAST &&
1938+ batadv_bla_check_ucast_duplist (bat_priv , skb ))
1939+ goto handled ;
18521940
18531941 ether_addr_copy (search_claim .addr , ethhdr -> h_source );
18541942 search_claim .vid = vid ;
@@ -1883,13 +1971,14 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
18831971 goto allow ;
18841972 }
18851973
1886- /* if it is a broadcast ... */
1887- if (is_multicast_ether_addr (ethhdr -> h_dest ) && is_bcast ) {
1974+ /* if it is a multicast ... */
1975+ if (is_multicast_ether_addr (ethhdr -> h_dest ) &&
1976+ (packet_type == BATADV_BCAST || packet_type == BATADV_UNICAST )) {
18881977 /* ... drop it. the responsible gateway is in charge.
18891978 *
1890- * We need to check is_bcast because with the gateway
1979+ * We need to check packet type because with the gateway
18911980 * feature, broadcasts (like DHCP requests) may be sent
1892- * using a unicast packet type.
1981+ * using a unicast 4 address packet type. See comment above .
18931982 */
18941983 goto handled ;
18951984 } else {
0 commit comments