Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'batadv-net-for-davem-20200918' of git://git.open-mesh.org/linux-merge

Simon Wunderlich says:

====================
Here are some batman-adv bugfixes:

- fix wrong type use in backbone_gw hash, by Linus Luessing

- disable TT re-routing for multicast packets, by Linus Luessing

- Add missing include for in_interrupt(), by Sven Eckelmann

- fix BLA/multicast issues for packets sent via unicast,
by Linus Luessing (3 patches)
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+179 -46
+117 -28
net/batman-adv/bridge_loop_avoidance.c
··· 25 25 #include <linux/lockdep.h> 26 26 #include <linux/netdevice.h> 27 27 #include <linux/netlink.h> 28 + #include <linux/preempt.h> 28 29 #include <linux/rculist.h> 29 30 #include <linux/rcupdate.h> 30 31 #include <linux/seq_file.h> ··· 84 83 */ 85 84 static inline u32 batadv_choose_backbone_gw(const void *data, u32 size) 86 85 { 87 - const struct batadv_bla_claim *claim = (struct batadv_bla_claim *)data; 86 + const struct batadv_bla_backbone_gw *gw; 88 87 u32 hash = 0; 89 88 90 - hash = jhash(&claim->addr, sizeof(claim->addr), hash); 91 - hash = jhash(&claim->vid, sizeof(claim->vid), hash); 89 + gw = (struct batadv_bla_backbone_gw *)data; 90 + hash = jhash(&gw->orig, sizeof(gw->orig), hash); 91 + hash = jhash(&gw->vid, sizeof(gw->vid), hash); 92 92 93 93 return hash % size; 94 94 } ··· 1581 1579 } 1582 1580 1583 1581 /** 1584 - * batadv_bla_check_bcast_duplist() - Check if a frame is in the broadcast dup. 1582 + * batadv_bla_check_duplist() - Check if a frame is in the broadcast dup. 1585 1583 * @bat_priv: the bat priv with all the soft interface information 1586 - * @skb: contains the bcast_packet to be checked 1584 + * @skb: contains the multicast packet to be checked 1585 + * @payload_ptr: pointer to position inside the head buffer of the skb 1586 + * marking the start of the data to be CRC'ed 1587 + * @orig: originator mac address, NULL if unknown 1587 1588 * 1588 - * check if it is on our broadcast list. Another gateway might 1589 - * have sent the same packet because it is connected to the same backbone, 1590 - * so we have to remove this duplicate. 1589 + * Check if it is on our broadcast list. Another gateway might have sent the 1590 + * same packet because it is connected to the same backbone, so we have to 1591 + * remove this duplicate. 1591 1592 * 1592 1593 * This is performed by checking the CRC, which will tell us 1593 1594 * with a good chance that it is the same packet. If it is furthermore ··· 1599 1594 * 1600 1595 * Return: true if a packet is in the duplicate list, false otherwise. 1601 1596 */ 1602 - bool batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv, 1603 - struct sk_buff *skb) 1597 + static bool batadv_bla_check_duplist(struct batadv_priv *bat_priv, 1598 + struct sk_buff *skb, u8 *payload_ptr, 1599 + const u8 *orig) 1604 1600 { 1605 - int i, curr; 1606 - __be32 crc; 1607 - struct batadv_bcast_packet *bcast_packet; 1608 1601 struct batadv_bcast_duplist_entry *entry; 1609 1602 bool ret = false; 1610 - 1611 - bcast_packet = (struct batadv_bcast_packet *)skb->data; 1603 + int i, curr; 1604 + __be32 crc; 1612 1605 1613 1606 /* calculate the crc ... */ 1614 - crc = batadv_skb_crc32(skb, (u8 *)(bcast_packet + 1)); 1607 + crc = batadv_skb_crc32(skb, payload_ptr); 1615 1608 1616 1609 spin_lock_bh(&bat_priv->bla.bcast_duplist_lock); 1617 1610 ··· 1628 1625 if (entry->crc != crc) 1629 1626 continue; 1630 1627 1631 - if (batadv_compare_eth(entry->orig, bcast_packet->orig)) 1632 - continue; 1628 + /* are the originators both known and not anonymous? */ 1629 + if (orig && !is_zero_ether_addr(orig) && 1630 + !is_zero_ether_addr(entry->orig)) { 1631 + /* If known, check if the new frame came from 1632 + * the same originator: 1633 + * We are safe to take identical frames from the 1634 + * same orig, if known, as multiplications in 1635 + * the mesh are detected via the (orig, seqno) pair. 1636 + * So we can be a bit more liberal here and allow 1637 + * identical frames from the same orig which the source 1638 + * host might have sent multiple times on purpose. 1639 + */ 1640 + if (batadv_compare_eth(entry->orig, orig)) 1641 + continue; 1642 + } 1633 1643 1634 1644 /* this entry seems to match: same crc, not too old, 1635 1645 * and from another gw. therefore return true to forbid it. ··· 1658 1642 entry = &bat_priv->bla.bcast_duplist[curr]; 1659 1643 entry->crc = crc; 1660 1644 entry->entrytime = jiffies; 1661 - ether_addr_copy(entry->orig, bcast_packet->orig); 1645 + 1646 + /* known originator */ 1647 + if (orig) 1648 + ether_addr_copy(entry->orig, orig); 1649 + /* anonymous originator */ 1650 + else 1651 + eth_zero_addr(entry->orig); 1652 + 1662 1653 bat_priv->bla.bcast_duplist_curr = curr; 1663 1654 1664 1655 out: 1665 1656 spin_unlock_bh(&bat_priv->bla.bcast_duplist_lock); 1666 1657 1667 1658 return ret; 1659 + } 1660 + 1661 + /** 1662 + * batadv_bla_check_ucast_duplist() - Check if a frame is in the broadcast dup. 1663 + * @bat_priv: the bat priv with all the soft interface information 1664 + * @skb: contains the multicast packet to be checked, decapsulated from a 1665 + * unicast_packet 1666 + * 1667 + * Check if it is on our broadcast list. Another gateway might have sent the 1668 + * same packet because it is connected to the same backbone, so we have to 1669 + * remove this duplicate. 1670 + * 1671 + * Return: true if a packet is in the duplicate list, false otherwise. 1672 + */ 1673 + static bool batadv_bla_check_ucast_duplist(struct batadv_priv *bat_priv, 1674 + struct sk_buff *skb) 1675 + { 1676 + return batadv_bla_check_duplist(bat_priv, skb, (u8 *)skb->data, NULL); 1677 + } 1678 + 1679 + /** 1680 + * batadv_bla_check_bcast_duplist() - Check if a frame is in the broadcast dup. 1681 + * @bat_priv: the bat priv with all the soft interface information 1682 + * @skb: contains the bcast_packet to be checked 1683 + * 1684 + * Check if it is on our broadcast list. Another gateway might have sent the 1685 + * same packet because it is connected to the same backbone, so we have to 1686 + * remove this duplicate. 1687 + * 1688 + * Return: true if a packet is in the duplicate list, false otherwise. 1689 + */ 1690 + bool batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv, 1691 + struct sk_buff *skb) 1692 + { 1693 + struct batadv_bcast_packet *bcast_packet; 1694 + u8 *payload_ptr; 1695 + 1696 + bcast_packet = (struct batadv_bcast_packet *)skb->data; 1697 + payload_ptr = (u8 *)(bcast_packet + 1); 1698 + 1699 + return batadv_bla_check_duplist(bat_priv, skb, payload_ptr, 1700 + bcast_packet->orig); 1668 1701 } 1669 1702 1670 1703 /** ··· 1877 1812 * @bat_priv: the bat priv with all the soft interface information 1878 1813 * @skb: the frame to be checked 1879 1814 * @vid: the VLAN ID of the frame 1880 - * @is_bcast: the packet came in a broadcast packet type. 1815 + * @packet_type: the batman packet type this frame came in 1881 1816 * 1882 1817 * batadv_bla_rx avoidance checks if: 1883 1818 * * we have to race for a claim ··· 1889 1824 * further process the skb. 1890 1825 */ 1891 1826 bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, 1892 - unsigned short vid, bool is_bcast) 1827 + unsigned short vid, int packet_type) 1893 1828 { 1894 1829 struct batadv_bla_backbone_gw *backbone_gw; 1895 1830 struct ethhdr *ethhdr; ··· 1911 1846 goto handled; 1912 1847 1913 1848 if (unlikely(atomic_read(&bat_priv->bla.num_requests))) 1914 - /* don't allow broadcasts while requests are in flight */ 1915 - if (is_multicast_ether_addr(ethhdr->h_dest) && is_bcast) 1916 - goto handled; 1849 + /* don't allow multicast packets while requests are in flight */ 1850 + if (is_multicast_ether_addr(ethhdr->h_dest)) 1851 + /* Both broadcast flooding or multicast-via-unicasts 1852 + * delivery might send to multiple backbone gateways 1853 + * sharing the same LAN and therefore need to coordinate 1854 + * which backbone gateway forwards into the LAN, 1855 + * by claiming the payload source address. 1856 + * 1857 + * Broadcast flooding and multicast-via-unicasts 1858 + * delivery use the following two batman packet types. 1859 + * Note: explicitly exclude BATADV_UNICAST_4ADDR, 1860 + * as the DHCP gateway feature will send explicitly 1861 + * to only one BLA gateway, so the claiming process 1862 + * should be avoided there. 1863 + */ 1864 + if (packet_type == BATADV_BCAST || 1865 + packet_type == BATADV_UNICAST) 1866 + goto handled; 1867 + 1868 + /* potential duplicates from foreign BLA backbone gateways via 1869 + * multicast-in-unicast packets 1870 + */ 1871 + if (is_multicast_ether_addr(ethhdr->h_dest) && 1872 + packet_type == BATADV_UNICAST && 1873 + batadv_bla_check_ucast_duplist(bat_priv, skb)) 1874 + goto handled; 1917 1875 1918 1876 ether_addr_copy(search_claim.addr, ethhdr->h_source); 1919 1877 search_claim.vid = vid; ··· 1971 1883 goto allow; 1972 1884 } 1973 1885 1974 - /* if it is a broadcast ... */ 1975 - if (is_multicast_ether_addr(ethhdr->h_dest) && is_bcast) { 1886 + /* if it is a multicast ... */ 1887 + if (is_multicast_ether_addr(ethhdr->h_dest) && 1888 + (packet_type == BATADV_BCAST || packet_type == BATADV_UNICAST)) { 1976 1889 /* ... drop it. the responsible gateway is in charge. 1977 1890 * 1978 - * We need to check is_bcast because with the gateway 1891 + * We need to check packet type because with the gateway 1979 1892 * feature, broadcasts (like DHCP requests) may be sent 1980 - * using a unicast packet type. 1893 + * using a unicast 4 address packet type. See comment above. 1981 1894 */ 1982 1895 goto handled; 1983 1896 } else {
+2 -2
net/batman-adv/bridge_loop_avoidance.h
··· 35 35 36 36 #ifdef CONFIG_BATMAN_ADV_BLA 37 37 bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, 38 - unsigned short vid, bool is_bcast); 38 + unsigned short vid, int packet_type); 39 39 bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, 40 40 unsigned short vid); 41 41 bool batadv_bla_is_backbone_gw(struct sk_buff *skb, ··· 66 66 67 67 static inline bool batadv_bla_rx(struct batadv_priv *bat_priv, 68 68 struct sk_buff *skb, unsigned short vid, 69 - bool is_bcast) 69 + int packet_type) 70 70 { 71 71 return false; 72 72 }
+36 -10
net/batman-adv/multicast.c
··· 51 51 #include <uapi/linux/batadv_packet.h> 52 52 #include <uapi/linux/batman_adv.h> 53 53 54 + #include "bridge_loop_avoidance.h" 54 55 #include "hard-interface.h" 55 56 #include "hash.h" 56 57 #include "log.h" ··· 1436 1435 } 1437 1436 1438 1437 /** 1438 + * batadv_mcast_forw_send_orig() - send a multicast packet to an originator 1439 + * @bat_priv: the bat priv with all the soft interface information 1440 + * @skb: the multicast packet to send 1441 + * @vid: the vlan identifier 1442 + * @orig_node: the originator to send the packet to 1443 + * 1444 + * Return: NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise. 1445 + */ 1446 + int batadv_mcast_forw_send_orig(struct batadv_priv *bat_priv, 1447 + struct sk_buff *skb, 1448 + unsigned short vid, 1449 + struct batadv_orig_node *orig_node) 1450 + { 1451 + /* Avoid sending multicast-in-unicast packets to other BLA 1452 + * gateways - they already got the frame from the LAN side 1453 + * we share with them. 1454 + * TODO: Refactor to take BLA into account earlier, to avoid 1455 + * reducing the mcast_fanout count. 1456 + */ 1457 + if (batadv_bla_is_backbone_gw_orig(bat_priv, orig_node->orig, vid)) { 1458 + dev_kfree_skb(skb); 1459 + return NET_XMIT_SUCCESS; 1460 + } 1461 + 1462 + return batadv_send_skb_unicast(bat_priv, skb, BATADV_UNICAST, 0, 1463 + orig_node, vid); 1464 + } 1465 + 1466 + /** 1439 1467 * batadv_mcast_forw_tt() - forwards a packet to multicast listeners 1440 1468 * @bat_priv: the bat priv with all the soft interface information 1441 1469 * @skb: the multicast packet to transmit ··· 1501 1471 break; 1502 1472 } 1503 1473 1504 - batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0, 1505 - orig_entry->orig_node, vid); 1474 + batadv_mcast_forw_send_orig(bat_priv, newskb, vid, 1475 + orig_entry->orig_node); 1506 1476 } 1507 1477 rcu_read_unlock(); 1508 1478 ··· 1543 1513 break; 1544 1514 } 1545 1515 1546 - batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0, 1547 - orig_node, vid); 1516 + batadv_mcast_forw_send_orig(bat_priv, newskb, vid, orig_node); 1548 1517 } 1549 1518 rcu_read_unlock(); 1550 1519 return ret; ··· 1580 1551 break; 1581 1552 } 1582 1553 1583 - batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0, 1584 - orig_node, vid); 1554 + batadv_mcast_forw_send_orig(bat_priv, newskb, vid, orig_node); 1585 1555 } 1586 1556 rcu_read_unlock(); 1587 1557 return ret; ··· 1646 1618 break; 1647 1619 } 1648 1620 1649 - batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0, 1650 - orig_node, vid); 1621 + batadv_mcast_forw_send_orig(bat_priv, newskb, vid, orig_node); 1651 1622 } 1652 1623 rcu_read_unlock(); 1653 1624 return ret; ··· 1683 1656 break; 1684 1657 } 1685 1658 1686 - batadv_send_skb_unicast(bat_priv, newskb, BATADV_UNICAST, 0, 1687 - orig_node, vid); 1659 + batadv_mcast_forw_send_orig(bat_priv, newskb, vid, orig_node); 1688 1660 } 1689 1661 rcu_read_unlock(); 1690 1662 return ret;
+15
net/batman-adv/multicast.h
··· 46 46 batadv_mcast_forw_mode(struct batadv_priv *bat_priv, struct sk_buff *skb, 47 47 struct batadv_orig_node **mcast_single_orig); 48 48 49 + int batadv_mcast_forw_send_orig(struct batadv_priv *bat_priv, 50 + struct sk_buff *skb, 51 + unsigned short vid, 52 + struct batadv_orig_node *orig_node); 53 + 49 54 int batadv_mcast_forw_send(struct batadv_priv *bat_priv, struct sk_buff *skb, 50 55 unsigned short vid); 51 56 ··· 74 69 struct batadv_orig_node **mcast_single_orig) 75 70 { 76 71 return BATADV_FORW_ALL; 72 + } 73 + 74 + static inline int 75 + batadv_mcast_forw_send_orig(struct batadv_priv *bat_priv, 76 + struct sk_buff *skb, 77 + unsigned short vid, 78 + struct batadv_orig_node *orig_node) 79 + { 80 + kfree_skb(skb); 81 + return NET_XMIT_DROP; 77 82 } 78 83 79 84 static inline int
+4
net/batman-adv/routing.c
··· 826 826 vid = batadv_get_vid(skb, hdr_len); 827 827 ethhdr = (struct ethhdr *)(skb->data + hdr_len); 828 828 829 + /* do not reroute multicast frames in a unicast header */ 830 + if (is_multicast_ether_addr(ethhdr->h_dest)) 831 + return true; 832 + 829 833 /* check if the destination client was served by this node and it is now 830 834 * roaming. In this case, it means that the node has got a ROAM_ADV 831 835 * message and that it knows the new destination in the mesh to re-route
+5 -6
net/batman-adv/soft-interface.c
··· 364 364 goto dropped; 365 365 ret = batadv_send_skb_via_gw(bat_priv, skb, vid); 366 366 } else if (mcast_single_orig) { 367 - ret = batadv_send_skb_unicast(bat_priv, skb, 368 - BATADV_UNICAST, 0, 369 - mcast_single_orig, vid); 367 + ret = batadv_mcast_forw_send_orig(bat_priv, skb, vid, 368 + mcast_single_orig); 370 369 } else if (forw_mode == BATADV_FORW_SOME) { 371 370 ret = batadv_mcast_forw_send(bat_priv, skb, vid); 372 371 } else { ··· 424 425 struct vlan_ethhdr *vhdr; 425 426 struct ethhdr *ethhdr; 426 427 unsigned short vid; 427 - bool is_bcast; 428 + int packet_type; 428 429 429 430 batadv_bcast_packet = (struct batadv_bcast_packet *)skb->data; 430 - is_bcast = (batadv_bcast_packet->packet_type == BATADV_BCAST); 431 + packet_type = batadv_bcast_packet->packet_type; 431 432 432 433 skb_pull_rcsum(skb, hdr_size); 433 434 skb_reset_mac_header(skb); ··· 470 471 /* Let the bridge loop avoidance check the packet. If will 471 472 * not handle it, we can safely push it up. 472 473 */ 473 - if (batadv_bla_rx(bat_priv, skb, vid, is_bcast)) 474 + if (batadv_bla_rx(bat_priv, skb, vid, packet_type)) 474 475 goto out; 475 476 476 477 if (orig_node)