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

Merge tag 'batman-adv-for-davem' of git://git.open-mesh.org/linux-merge

Included changes:
- substitute FSF address with URL
- deselect current bat-GW when GW-client mode gets deactivated
- send every DHCP packet using bat-unicast messages when GW-client mode is
enabled
- implement the Extended Isolation mechanism (it is an enhancement of the
already existing batman-AP-isolation). This mechanism allows the user to drop
packets exchanged by selected clients by using netfilter marks.
- fix typ0 in header guard
- minor code cleanups

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

+437 -311
+8
Documentation/ABI/testing/sysfs-class-net-mesh
··· 68 68 Defines the penalty which will be applied to an 69 69 originator message's tq-field on every hop. 70 70 71 + What: /sys/class/net/<mesh_iface>/mesh/isolation_mark 72 + Date: Nov 2013 73 + Contact: Antonio Quartulli <antonio@meshcoding.com> 74 + Description: 75 + Defines the isolation mark (and its bitmask) which 76 + is used to classify clients as "isolated" by the 77 + Extended Isolation feature. 78 + 71 79 What: /sys/class/net/<mesh_iface>/mesh/network_coding 72 80 Date: Nov 2012 73 81 Contact: Martin Hundeboll <martin@hundeboll.net>
+1 -3
net/batman-adv/Makefile
··· 13 13 # General Public License for more details. 14 14 # 15 15 # You should have received a copy of the GNU General Public License 16 - # along with this program; if not, write to the Free Software 17 - # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18 - # 02110-1301, USA 16 + # along with this program; if not, see <http://www.gnu.org/licenses/>. 19 17 # 20 18 21 19 obj-$(CONFIG_BATMAN_ADV) += batman-adv.o
+1 -3
net/batman-adv/bat_algo.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_BAT_ALGO_H_
+1 -3
net/batman-adv/bat_iv_ogm.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h"
+1 -3
net/batman-adv/bitarray.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h"
+1 -3
net/batman-adv/bitarray.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_BITARRAY_H_
+1 -3
net/batman-adv/bridge_loop_avoidance.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h"
+1 -3
net/batman-adv/bridge_loop_avoidance.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_BLA_H_
+1 -3
net/batman-adv/debugfs.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h"
+1 -3
net/batman-adv/debugfs.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_DEBUGFS_H_
+4 -6
net/batman-adv/distributed-arp-table.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include <linux/if_ether.h> ··· 139 141 const void *data1 = container_of(node, struct batadv_dat_entry, 140 142 hash_entry); 141 143 142 - return (memcmp(data1, data2, sizeof(__be32)) == 0 ? 1 : 0); 144 + return memcmp(data1, data2, sizeof(__be32)) == 0 ? 1 : 0; 143 145 } 144 146 145 147 /** ··· 1037 1039 if (hdr_size == sizeof(struct batadv_unicast_4addr_packet)) 1038 1040 err = batadv_send_skb_via_tt_4addr(bat_priv, skb_new, 1039 1041 BATADV_P_DAT_CACHE_REPLY, 1040 - vid); 1042 + NULL, vid); 1041 1043 else 1042 - err = batadv_send_skb_via_tt(bat_priv, skb_new, vid); 1044 + err = batadv_send_skb_via_tt(bat_priv, skb_new, NULL, vid); 1043 1045 1044 1046 if (err != NET_XMIT_DROP) { 1045 1047 batadv_inc_counter(bat_priv, BATADV_CNT_DAT_CACHED_REPLY_TX);
+4 -6
net/batman-adv/distributed-arp-table.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 - #ifndef _NET_BATMAN_ADV_ARP_H_ 21 - #define _NET_BATMAN_ADV_ARP_H_ 18 + #ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ 19 + #define _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ 22 20 23 21 #ifdef CONFIG_BATMAN_ADV_DAT 24 22 ··· 167 169 168 170 #endif /* CONFIG_BATMAN_ADV_DAT */ 169 171 170 - #endif /* _NET_BATMAN_ADV_ARP_H_ */ 172 + #endif /* _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ */
+1 -3
net/batman-adv/fragmentation.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h"
+1 -3
net/batman-adv/fragmentation.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_FRAGMENTATION_H_
+105 -110
net/batman-adv/gateway_client.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h" ··· 28 30 #include <linux/udp.h> 29 31 #include <linux/if_vlan.h> 30 32 31 - /* This is the offset of the options field in a dhcp packet starting at 32 - * the beginning of the dhcp header 33 + /* These are the offsets of the "hw type" and "hw address length" in the dhcp 34 + * packet starting at the beginning of the dhcp header 33 35 */ 34 - #define BATADV_DHCP_OPTIONS_OFFSET 240 35 - #define BATADV_DHCP_REQUEST 3 36 + #define BATADV_DHCP_HTYPE_OFFSET 1 37 + #define BATADV_DHCP_HLEN_OFFSET 2 38 + /* Value of htype representing Ethernet */ 39 + #define BATADV_DHCP_HTYPE_ETHERNET 0x01 40 + /* This is the offset of the "chaddr" field in the dhcp packet starting at the 41 + * beginning of the dhcp header 42 + */ 43 + #define BATADV_DHCP_CHADDR_OFFSET 28 36 44 37 45 static void batadv_gw_node_free_ref(struct batadv_gw_node *gw_node) 38 46 { ··· 109 105 spin_unlock_bh(&bat_priv->gw.list_lock); 110 106 } 111 107 112 - void batadv_gw_deselect(struct batadv_priv *bat_priv) 108 + /** 109 + * batadv_gw_reselect - force a gateway reselection 110 + * @bat_priv: the bat priv with all the soft interface information 111 + * 112 + * Set a flag to remind the GW component to perform a new gateway reselection. 113 + * However this function does not ensure that the current gateway is going to be 114 + * deselected. The reselection mechanism may elect the same gateway once again. 115 + * 116 + * This means that invoking batadv_gw_reselect() does not guarantee a gateway 117 + * change and therefore a uevent is not necessarily expected. 118 + */ 119 + void batadv_gw_reselect(struct batadv_priv *bat_priv) 113 120 { 114 121 atomic_set(&bat_priv->gw.reselect, 1); 115 122 } ··· 222 207 if (!curr_gw) 223 208 return; 224 209 210 + /* deselect the current gateway so that next time that client mode is 211 + * enabled a proper GW_ADD event can be sent 212 + */ 213 + batadv_gw_select(bat_priv, NULL); 214 + 225 215 /* if batman-adv is switching the gw client mode off and a gateway was 226 216 * already selected, send a DEL uevent 227 217 */ ··· 259 239 260 240 router = batadv_orig_node_get_router(next_gw->orig_node); 261 241 if (!router) { 262 - batadv_gw_deselect(bat_priv); 242 + batadv_gw_reselect(bat_priv); 263 243 goto out; 264 244 } 265 245 } ··· 311 291 312 292 curr_gw_orig = batadv_gw_get_selected_orig(bat_priv); 313 293 if (!curr_gw_orig) 314 - goto deselect; 294 + goto reselect; 315 295 316 296 router_gw = batadv_orig_node_get_router(curr_gw_orig); 317 297 if (!router_gw) 318 - goto deselect; 298 + goto reselect; 319 299 320 300 /* this node already is the gateway */ 321 301 if (curr_gw_orig == orig_node) ··· 343 323 "Restarting gateway selection: better gateway found (tq curr: %i, tq new: %i)\n", 344 324 gw_tq_avg, orig_tq_avg); 345 325 346 - deselect: 347 - batadv_gw_deselect(bat_priv); 326 + reselect: 327 + batadv_gw_reselect(bat_priv); 348 328 out: 349 329 if (curr_gw_orig) 350 330 batadv_orig_node_free_ref(curr_gw_orig); ··· 474 454 */ 475 455 curr_gw = batadv_gw_get_selected_gw_node(bat_priv); 476 456 if (gw_node == curr_gw) 477 - batadv_gw_deselect(bat_priv); 457 + batadv_gw_reselect(bat_priv); 478 458 } 479 459 480 460 out: ··· 500 480 struct batadv_gw_node *gw_node, *curr_gw; 501 481 struct hlist_node *node_tmp; 502 482 unsigned long timeout = msecs_to_jiffies(2 * BATADV_PURGE_TIMEOUT); 503 - int do_deselect = 0; 483 + int do_reselect = 0; 504 484 505 485 curr_gw = batadv_gw_get_selected_gw_node(bat_priv); 506 486 ··· 514 494 continue; 515 495 516 496 if (curr_gw == gw_node) 517 - do_deselect = 1; 497 + do_reselect = 1; 518 498 519 499 hlist_del_rcu(&gw_node->list); 520 500 batadv_gw_node_free_ref(gw_node); ··· 522 502 523 503 spin_unlock_bh(&bat_priv->gw.list_lock); 524 504 525 - /* gw_deselect() needs to acquire the gw_list_lock */ 526 - if (do_deselect) 527 - batadv_gw_deselect(bat_priv); 505 + /* gw_reselect() needs to acquire the gw_list_lock */ 506 + if (do_reselect) 507 + batadv_gw_reselect(bat_priv); 528 508 529 509 if (curr_gw) 530 510 batadv_gw_node_free_ref(curr_gw); ··· 602 582 return 0; 603 583 } 604 584 605 - /* this call might reallocate skb data */ 606 - static bool batadv_is_type_dhcprequest(struct sk_buff *skb, int header_len) 585 + /** 586 + * batadv_gw_dhcp_recipient_get - check if a packet is a DHCP message 587 + * @skb: the packet to check 588 + * @header_len: a pointer to the batman-adv header size 589 + * @chaddr: buffer where the client address will be stored. Valid 590 + * only if the function returns BATADV_DHCP_TO_CLIENT 591 + * 592 + * Returns: 593 + * - BATADV_DHCP_NO if the packet is not a dhcp message or if there was an error 594 + * while parsing it 595 + * - BATADV_DHCP_TO_SERVER if this is a message going to the DHCP server 596 + * - BATADV_DHCP_TO_CLIENT if this is a message going to a DHCP client 597 + * 598 + * This function may re-allocate the data buffer of the skb passed as argument. 599 + */ 600 + enum batadv_dhcp_recipient 601 + batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len, 602 + uint8_t *chaddr) 607 603 { 608 - int ret = false; 609 - unsigned char *p; 610 - int pkt_len; 611 - 612 - if (skb_linearize(skb) < 0) 613 - goto out; 614 - 615 - pkt_len = skb_headlen(skb); 616 - 617 - if (pkt_len < header_len + BATADV_DHCP_OPTIONS_OFFSET + 1) 618 - goto out; 619 - 620 - p = skb->data + header_len + BATADV_DHCP_OPTIONS_OFFSET; 621 - pkt_len -= header_len + BATADV_DHCP_OPTIONS_OFFSET + 1; 622 - 623 - /* Access the dhcp option lists. Each entry is made up by: 624 - * - octet 1: option type 625 - * - octet 2: option data len (only if type != 255 and 0) 626 - * - octet 3: option data 627 - */ 628 - while (*p != 255 && !ret) { 629 - /* p now points to the first octet: option type */ 630 - if (*p == 53) { 631 - /* type 53 is the message type option. 632 - * Jump the len octet and go to the data octet 633 - */ 634 - if (pkt_len < 2) 635 - goto out; 636 - p += 2; 637 - 638 - /* check if the message type is what we need */ 639 - if (*p == BATADV_DHCP_REQUEST) 640 - ret = true; 641 - break; 642 - } else if (*p == 0) { 643 - /* option type 0 (padding), just go forward */ 644 - if (pkt_len < 1) 645 - goto out; 646 - pkt_len--; 647 - p++; 648 - } else { 649 - /* This is any other option. So we get the length... */ 650 - if (pkt_len < 1) 651 - goto out; 652 - pkt_len--; 653 - p++; 654 - 655 - /* ...and then we jump over the data */ 656 - if (pkt_len < 1 + (*p)) 657 - goto out; 658 - pkt_len -= 1 + (*p); 659 - p += 1 + (*p); 660 - } 661 - } 662 - out: 663 - return ret; 664 - } 665 - 666 - /* this call might reallocate skb data */ 667 - bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len) 668 - { 604 + enum batadv_dhcp_recipient ret = BATADV_DHCP_NO; 669 605 struct ethhdr *ethhdr; 670 606 struct iphdr *iphdr; 671 607 struct ipv6hdr *ipv6hdr; 672 608 struct udphdr *udphdr; 673 609 struct vlan_ethhdr *vhdr; 610 + int chaddr_offset; 674 611 __be16 proto; 612 + uint8_t *p; 675 613 676 614 /* check for ethernet header */ 677 615 if (!pskb_may_pull(skb, *header_len + ETH_HLEN)) 678 - return false; 616 + return BATADV_DHCP_NO; 617 + 679 618 ethhdr = (struct ethhdr *)skb->data; 680 619 proto = ethhdr->h_proto; 681 620 *header_len += ETH_HLEN; ··· 642 663 /* check for initial vlan header */ 643 664 if (proto == htons(ETH_P_8021Q)) { 644 665 if (!pskb_may_pull(skb, *header_len + VLAN_HLEN)) 645 - return false; 666 + return BATADV_DHCP_NO; 646 667 647 668 vhdr = (struct vlan_ethhdr *)skb->data; 648 669 proto = vhdr->h_vlan_encapsulated_proto; ··· 653 674 switch (proto) { 654 675 case htons(ETH_P_IP): 655 676 if (!pskb_may_pull(skb, *header_len + sizeof(*iphdr))) 656 - return false; 677 + return BATADV_DHCP_NO; 678 + 657 679 iphdr = (struct iphdr *)(skb->data + *header_len); 658 680 *header_len += iphdr->ihl * 4; 659 681 660 682 /* check for udp header */ 661 683 if (iphdr->protocol != IPPROTO_UDP) 662 - return false; 684 + return BATADV_DHCP_NO; 663 685 664 686 break; 665 687 case htons(ETH_P_IPV6): 666 688 if (!pskb_may_pull(skb, *header_len + sizeof(*ipv6hdr))) 667 - return false; 689 + return BATADV_DHCP_NO; 690 + 668 691 ipv6hdr = (struct ipv6hdr *)(skb->data + *header_len); 669 692 *header_len += sizeof(*ipv6hdr); 670 693 671 694 /* check for udp header */ 672 695 if (ipv6hdr->nexthdr != IPPROTO_UDP) 673 - return false; 696 + return BATADV_DHCP_NO; 674 697 675 698 break; 676 699 default: 677 - return false; 700 + return BATADV_DHCP_NO; 678 701 } 679 702 680 703 if (!pskb_may_pull(skb, *header_len + sizeof(*udphdr))) 681 - return false; 704 + return BATADV_DHCP_NO; 682 705 683 706 /* skb->data might have been reallocated by pskb_may_pull() */ 684 707 ethhdr = (struct ethhdr *)skb->data; ··· 691 710 *header_len += sizeof(*udphdr); 692 711 693 712 /* check for bootp port */ 694 - if ((proto == htons(ETH_P_IP)) && 695 - (udphdr->dest != htons(67))) 696 - return false; 713 + switch (proto) { 714 + case htons(ETH_P_IP): 715 + if (udphdr->dest == htons(67)) 716 + ret = BATADV_DHCP_TO_SERVER; 717 + else if (udphdr->source == htons(67)) 718 + ret = BATADV_DHCP_TO_CLIENT; 719 + break; 720 + case htons(ETH_P_IPV6): 721 + if (udphdr->dest == htons(547)) 722 + ret = BATADV_DHCP_TO_SERVER; 723 + else if (udphdr->source == htons(547)) 724 + ret = BATADV_DHCP_TO_CLIENT; 725 + break; 726 + } 697 727 698 - if ((proto == htons(ETH_P_IPV6)) && 699 - (udphdr->dest != htons(547))) 700 - return false; 728 + chaddr_offset = *header_len + BATADV_DHCP_CHADDR_OFFSET; 729 + /* store the client address if the message is going to a client */ 730 + if (ret == BATADV_DHCP_TO_CLIENT && 731 + pskb_may_pull(skb, chaddr_offset + ETH_ALEN)) { 732 + /* check if the DHCP packet carries an Ethernet DHCP */ 733 + p = skb->data + *header_len + BATADV_DHCP_HTYPE_OFFSET; 734 + if (*p != BATADV_DHCP_HTYPE_ETHERNET) 735 + return BATADV_DHCP_NO; 701 736 702 - return true; 737 + /* check if the DHCP packet carries a valid Ethernet address */ 738 + p = skb->data + *header_len + BATADV_DHCP_HLEN_OFFSET; 739 + if (*p != ETH_ALEN) 740 + return BATADV_DHCP_NO; 741 + 742 + memcpy(chaddr, skb->data + chaddr_offset, ETH_ALEN); 743 + } 744 + 745 + return ret; 703 746 } 704 - 705 747 /** 706 748 * batadv_gw_out_of_range - check if the dhcp request destination is the best gw 707 749 * @bat_priv: the bat priv with all the soft interface information ··· 738 734 * false otherwise. 739 735 * 740 736 * This call might reallocate skb data. 737 + * Must be invoked only when the DHCP packet is going TO a DHCP SERVER. 741 738 */ 742 739 bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, 743 740 struct sk_buff *skb) ··· 746 741 struct batadv_neigh_node *neigh_curr = NULL, *neigh_old = NULL; 747 742 struct batadv_orig_node *orig_dst_node = NULL; 748 743 struct batadv_gw_node *gw_node = NULL, *curr_gw = NULL; 749 - struct ethhdr *ethhdr; 750 - bool ret, out_of_range = false; 751 - unsigned int header_len = 0; 744 + struct ethhdr *ethhdr = (struct ethhdr *)skb->data; 745 + bool out_of_range = false; 752 746 uint8_t curr_tq_avg; 753 747 unsigned short vid; 754 748 755 749 vid = batadv_get_vid(skb, 0); 756 750 757 - ret = batadv_gw_is_dhcp_target(skb, &header_len); 758 - if (!ret) 759 - goto out; 760 - 761 - ethhdr = (struct ethhdr *)skb->data; 762 751 orig_dst_node = batadv_transtable_search(bat_priv, ethhdr->h_source, 763 752 ethhdr->h_dest, vid); 764 753 if (!orig_dst_node) ··· 760 761 761 762 gw_node = batadv_gw_node_get(bat_priv, orig_dst_node); 762 763 if (!gw_node->bandwidth_down == 0) 763 - goto out; 764 - 765 - ret = batadv_is_type_dhcprequest(skb, header_len); 766 - if (!ret) 767 764 goto out; 768 765 769 766 switch (atomic_read(&bat_priv->gw_mode)) {
+5 -5
net/batman-adv/gateway_client.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_GATEWAY_CLIENT_H_ 21 19 #define _NET_BATMAN_ADV_GATEWAY_CLIENT_H_ 22 20 23 21 void batadv_gw_check_client_stop(struct batadv_priv *bat_priv); 24 - void batadv_gw_deselect(struct batadv_priv *bat_priv); 22 + void batadv_gw_reselect(struct batadv_priv *bat_priv); 25 23 void batadv_gw_election(struct batadv_priv *bat_priv); 26 24 struct batadv_orig_node * 27 25 batadv_gw_get_selected_orig(struct batadv_priv *bat_priv); ··· 32 34 struct batadv_orig_node *orig_node); 33 35 void batadv_gw_node_purge(struct batadv_priv *bat_priv); 34 36 int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset); 35 - bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len); 36 37 bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, struct sk_buff *skb); 38 + enum batadv_dhcp_recipient 39 + batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len, 40 + uint8_t *chaddr); 37 41 38 42 #endif /* _NET_BATMAN_ADV_GATEWAY_CLIENT_H_ */
+2 -4
net/batman-adv/gateway_common.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h" ··· 162 164 if ((down_curr == down_new) && (up_curr == up_new)) 163 165 return count; 164 166 165 - batadv_gw_deselect(bat_priv); 167 + batadv_gw_reselect(bat_priv); 166 168 batadv_info(net_dev, 167 169 "Changing gateway bandwidth from: '%u.%u/%u.%u MBit' to: '%u.%u/%u.%u MBit'\n", 168 170 down_curr / 10, down_curr % 10, up_curr / 10, up_curr % 10,
+1 -3
net/batman-adv/gateway_common.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_GATEWAY_COMMON_H_
+1 -3
net/batman-adv/hard-interface.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h"
+1 -3
net/batman-adv/hard-interface.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_HARD_INTERFACE_H_
+1 -3
net/batman-adv/hash.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h"
+1 -3
net/batman-adv/hash.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_HASH_H_
+1 -3
net/batman-adv/icmp_socket.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h"
+1 -3
net/batman-adv/icmp_socket.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_ICMP_SOCKET_H_
+27 -3
net/batman-adv/main.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include <linux/crc32c.h> ··· 1169 1171 vid |= BATADV_VLAN_HAS_TAG; 1170 1172 1171 1173 return vid; 1174 + } 1175 + 1176 + /** 1177 + * batadv_vlan_ap_isola_get - return the AP isolation status for the given vlan 1178 + * @bat_priv: the bat priv with all the soft interface information 1179 + * @vid: the VLAN identifier for which the AP isolation attributed as to be 1180 + * looked up 1181 + * 1182 + * Returns true if AP isolation is on for the VLAN idenfied by vid, false 1183 + * otherwise 1184 + */ 1185 + bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid) 1186 + { 1187 + bool ap_isolation_enabled = false; 1188 + struct batadv_softif_vlan *vlan; 1189 + 1190 + /* if the AP isolation is requested on a VLAN, then check for its 1191 + * setting in the proper VLAN private data structure 1192 + */ 1193 + vlan = batadv_softif_vlan_get(bat_priv, vid); 1194 + if (vlan) { 1195 + ap_isolation_enabled = atomic_read(&vlan->ap_isolation); 1196 + batadv_softif_vlan_free_ref(vlan); 1197 + } 1198 + 1199 + return ap_isolation_enabled; 1172 1200 } 1173 1201 1174 1202 static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
+4 -3
net/batman-adv/main.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_MAIN_H_ ··· 69 71 #define BATADV_NO_FLAGS 0 70 72 71 73 #define BATADV_NULL_IFINDEX 0 /* dummy ifindex used to avoid iface checks */ 74 + 75 + #define BATADV_NO_MARK 0 72 76 73 77 #define BATADV_NUM_WORDS BITS_TO_LONGS(BATADV_TQ_LOCAL_WINDOW_SIZE) 74 78 ··· 369 369 uint8_t *dst, uint8_t type, uint8_t version, 370 370 void *tvlv_value, uint16_t tvlv_value_len); 371 371 unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len); 372 + bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid); 372 373 373 374 #endif /* _NET_BATMAN_ADV_MAIN_H_ */
+1 -3
net/batman-adv/network-coding.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include <linux/debugfs.h>
+1 -3
net/batman-adv/network-coding.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_NETWORK_CODING_H_
+1 -3
net/batman-adv/originator.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h"
+1 -3
net/batman-adv/originator.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_ORIGINATOR_H_
+2 -3
net/batman-adv/packet.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_PACKET_H_ ··· 115 117 BATADV_TT_CLIENT_DEL = BIT(0), 116 118 BATADV_TT_CLIENT_ROAM = BIT(1), 117 119 BATADV_TT_CLIENT_WIFI = BIT(4), 120 + BATADV_TT_CLIENT_ISOLA = BIT(5), 118 121 BATADV_TT_CLIENT_NOPURGE = BIT(8), 119 122 BATADV_TT_CLIENT_NEW = BIT(9), 120 123 BATADV_TT_CLIENT_PENDING = BIT(10),
+6 -6
net/batman-adv/routing.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h" ··· 1133 1135 int hdr_size = sizeof(*bcast_packet); 1134 1136 int ret = NET_RX_DROP; 1135 1137 int32_t seq_diff; 1138 + uint32_t seqno; 1136 1139 1137 1140 /* drop packet if it has not necessary minimum size */ 1138 1141 if (unlikely(!pskb_may_pull(skb, hdr_size))) ··· 1169 1170 1170 1171 spin_lock_bh(&orig_node->bcast_seqno_lock); 1171 1172 1173 + seqno = ntohl(bcast_packet->seqno); 1172 1174 /* check whether the packet is a duplicate */ 1173 1175 if (batadv_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno, 1174 - ntohl(bcast_packet->seqno))) 1176 + seqno)) 1175 1177 goto spin_unlock; 1176 1178 1177 - seq_diff = ntohl(bcast_packet->seqno) - orig_node->last_bcast_seqno; 1179 + seq_diff = seqno - orig_node->last_bcast_seqno; 1178 1180 1179 1181 /* check whether the packet is old and the host just restarted. */ 1180 1182 if (batadv_window_protected(bat_priv, seq_diff, ··· 1186 1186 * if required. 1187 1187 */ 1188 1188 if (batadv_bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1)) 1189 - orig_node->last_bcast_seqno = ntohl(bcast_packet->seqno); 1189 + orig_node->last_bcast_seqno = seqno; 1190 1190 1191 1191 spin_unlock_bh(&orig_node->bcast_seqno_lock); 1192 1192
+1 -3
net/batman-adv/routing.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_ROUTING_H_
+14 -6
net/batman-adv/send.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h" ··· 319 321 */ 320 322 int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv, 321 323 struct sk_buff *skb, int packet_type, 322 - int packet_subtype, unsigned short vid) 324 + int packet_subtype, uint8_t *dst_hint, 325 + unsigned short vid) 323 326 { 324 327 struct ethhdr *ethhdr = (struct ethhdr *)skb->data; 325 328 struct batadv_orig_node *orig_node; 329 + uint8_t *src, *dst; 326 330 327 - orig_node = batadv_transtable_search(bat_priv, ethhdr->h_source, 328 - ethhdr->h_dest, vid); 331 + src = ethhdr->h_source; 332 + dst = ethhdr->h_dest; 333 + 334 + /* if we got an hint! let's send the packet to this client (if any) */ 335 + if (dst_hint) { 336 + src = NULL; 337 + dst = dst_hint; 338 + } 339 + orig_node = batadv_transtable_search(bat_priv, src, dst, vid); 340 + 329 341 return batadv_send_skb_unicast(bat_priv, skb, packet_type, 330 342 packet_subtype, orig_node, vid); 331 343 }
+7 -7
net/batman-adv/send.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_SEND_H_ ··· 38 40 int packet_subtype); 39 41 int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv, 40 42 struct sk_buff *skb, int packet_type, 41 - int packet_subtype, unsigned short vid); 43 + int packet_subtype, uint8_t *dst_hint, 44 + unsigned short vid); 42 45 int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb, 43 46 unsigned short vid); 44 47 ··· 56 57 * Returns NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise. 57 58 */ 58 59 static inline int batadv_send_skb_via_tt(struct batadv_priv *bat_priv, 59 - struct sk_buff *skb, 60 + struct sk_buff *skb, uint8_t *dst_hint, 60 61 unsigned short vid) 61 62 { 62 63 return batadv_send_skb_via_tt_generic(bat_priv, skb, BATADV_UNICAST, 0, 63 - vid); 64 + dst_hint, vid); 64 65 } 65 66 66 67 /** ··· 80 81 static inline int batadv_send_skb_via_tt_4addr(struct batadv_priv *bat_priv, 81 82 struct sk_buff *skb, 82 83 int packet_subtype, 84 + uint8_t *dst_hint, 83 85 unsigned short vid) 84 86 { 85 87 return batadv_send_skb_via_tt_generic(bat_priv, skb, 86 88 BATADV_UNICAST_4ADDR, 87 - packet_subtype, vid); 89 + packet_subtype, dst_hint, vid); 88 90 } 89 91 90 92 #endif /* _NET_BATMAN_ADV_SEND_H_ */
+64 -43
net/batman-adv/soft-interface.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h" ··· 119 121 batadv_tt_local_remove(bat_priv, old_addr, BATADV_NO_FLAGS, 120 122 "mac address changed", false); 121 123 batadv_tt_local_add(dev, addr->sa_data, BATADV_NO_FLAGS, 122 - BATADV_NULL_IFINDEX); 124 + BATADV_NULL_IFINDEX, BATADV_NO_MARK); 123 125 } 124 126 125 127 return 0; ··· 160 162 0x00, 0x00}; 161 163 static const uint8_t ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00, 162 164 0x00, 0x00}; 165 + enum batadv_dhcp_recipient dhcp_rcp = BATADV_DHCP_NO; 166 + uint8_t *dst_hint = NULL, chaddr[ETH_ALEN]; 163 167 struct vlan_ethhdr *vhdr; 164 168 unsigned int header_len = 0; 165 169 int data_len = skb->len, ret; ··· 169 169 bool do_bcast = false, client_added; 170 170 unsigned short vid; 171 171 uint32_t seqno; 172 + int gw_mode; 172 173 173 174 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) 174 175 goto dropped; ··· 199 198 /* Register the client MAC in the transtable */ 200 199 if (!is_multicast_ether_addr(ethhdr->h_source)) { 201 200 client_added = batadv_tt_local_add(soft_iface, ethhdr->h_source, 202 - vid, skb->skb_iif); 201 + vid, skb->skb_iif, 202 + skb->mark); 203 203 if (!client_added) 204 204 goto dropped; 205 205 } ··· 217 215 if (batadv_compare_eth(ethhdr->h_dest, ectp_addr)) 218 216 goto dropped; 219 217 218 + gw_mode = atomic_read(&bat_priv->gw_mode); 220 219 if (is_multicast_ether_addr(ethhdr->h_dest)) { 221 - do_bcast = true; 222 - 223 - switch (atomic_read(&bat_priv->gw_mode)) { 224 - case BATADV_GW_MODE_SERVER: 225 - /* gateway servers should not send dhcp 226 - * requests into the mesh 227 - */ 228 - ret = batadv_gw_is_dhcp_target(skb, &header_len); 229 - if (ret) 230 - goto dropped; 231 - break; 232 - case BATADV_GW_MODE_CLIENT: 233 - /* gateway clients should send dhcp requests 234 - * via unicast to their gateway 235 - */ 236 - ret = batadv_gw_is_dhcp_target(skb, &header_len); 237 - if (ret) 238 - do_bcast = false; 239 - break; 240 - case BATADV_GW_MODE_OFF: 241 - default: 242 - break; 220 + /* if gw mode is off, broadcast every packet */ 221 + if (gw_mode == BATADV_GW_MODE_OFF) { 222 + do_bcast = true; 223 + goto send; 243 224 } 244 225 245 - /* reminder: ethhdr might have become unusable from here on 246 - * (batadv_gw_is_dhcp_target() might have reallocated skb data) 226 + dhcp_rcp = batadv_gw_dhcp_recipient_get(skb, &header_len, 227 + chaddr); 228 + /* skb->data may have been modified by 229 + * batadv_gw_dhcp_recipient_get() 247 230 */ 231 + ethhdr = (struct ethhdr *)skb->data; 232 + /* if gw_mode is on, broadcast any non-DHCP message. 233 + * All the DHCP packets are going to be sent as unicast 234 + */ 235 + if (dhcp_rcp == BATADV_DHCP_NO) { 236 + do_bcast = true; 237 + goto send; 238 + } 239 + 240 + if (dhcp_rcp == BATADV_DHCP_TO_CLIENT) 241 + dst_hint = chaddr; 242 + else if ((gw_mode == BATADV_GW_MODE_SERVER) && 243 + (dhcp_rcp == BATADV_DHCP_TO_SERVER)) 244 + /* gateways should not forward any DHCP message if 245 + * directed to a DHCP server 246 + */ 247 + goto dropped; 248 248 } 249 249 250 + send: 250 251 batadv_skb_set_priority(skb, 0); 251 252 252 253 /* ethernet packet should be broadcasted */ ··· 295 290 296 291 /* unicast packet */ 297 292 } else { 298 - if (atomic_read(&bat_priv->gw_mode) != BATADV_GW_MODE_OFF) { 293 + /* DHCP packets going to a server will use the GW feature */ 294 + if (dhcp_rcp == BATADV_DHCP_TO_SERVER) { 299 295 ret = batadv_gw_out_of_range(bat_priv, skb); 300 296 if (ret) 301 297 goto dropped; 302 - } 303 - 304 - if (batadv_dat_snoop_outgoing_arp_request(bat_priv, skb)) 305 - goto dropped; 306 - 307 - batadv_dat_snoop_outgoing_arp_reply(bat_priv, skb); 308 - 309 - if (is_multicast_ether_addr(ethhdr->h_dest)) 310 298 ret = batadv_send_skb_via_gw(bat_priv, skb, vid); 311 - else 312 - ret = batadv_send_skb_via_tt(bat_priv, skb, vid); 299 + } else { 300 + if (batadv_dat_snoop_outgoing_arp_request(bat_priv, 301 + skb)) 302 + goto dropped; 313 303 304 + batadv_dat_snoop_outgoing_arp_reply(bat_priv, skb); 305 + 306 + ret = batadv_send_skb_via_tt(bat_priv, skb, dst_hint, 307 + vid); 308 + } 314 309 if (ret == NET_XMIT_DROP) 315 310 goto dropped_freed; 316 311 } ··· 399 394 batadv_tt_add_temporary_global_entry(bat_priv, orig_node, 400 395 ethhdr->h_source, vid); 401 396 402 - if (batadv_is_ap_isolated(bat_priv, ethhdr->h_source, ethhdr->h_dest, 403 - vid)) 397 + if (is_multicast_ether_addr(ethhdr->h_dest)) { 398 + /* set the mark on broadcast packets if AP isolation is ON and 399 + * the packet is coming from an "isolated" client 400 + */ 401 + if (batadv_vlan_ap_isola_get(bat_priv, vid) && 402 + batadv_tt_global_is_isolated(bat_priv, ethhdr->h_source, 403 + vid)) { 404 + /* save bits in skb->mark not covered by the mask and 405 + * apply the mark on the rest 406 + */ 407 + skb->mark &= ~bat_priv->isolation_mark_mask; 408 + skb->mark |= bat_priv->isolation_mark; 409 + } 410 + } else if (batadv_is_ap_isolated(bat_priv, ethhdr->h_source, 411 + ethhdr->h_dest, vid)) { 404 412 goto dropped; 413 + } 405 414 406 415 netif_rx(skb); 407 416 goto out; ··· 504 485 */ 505 486 batadv_tt_local_add(bat_priv->soft_iface, 506 487 bat_priv->soft_iface->dev_addr, vid, 507 - BATADV_NULL_IFINDEX); 488 + BATADV_NULL_IFINDEX, BATADV_NO_MARK); 508 489 509 490 spin_lock_bh(&bat_priv->softif_vlan_list_lock); 510 491 hlist_add_head_rcu(&vlan->list, &bat_priv->softif_vlan_list); ··· 716 697 #endif 717 698 bat_priv->tt.last_changeset = NULL; 718 699 bat_priv->tt.last_changeset_len = 0; 700 + bat_priv->isolation_mark = 0; 701 + bat_priv->isolation_mark_mask = 0; 719 702 720 703 /* randomize initial seqno to avoid collision */ 721 704 get_random_bytes(&random_seqno, sizeof(random_seqno));
+1 -3
net/batman-adv/soft-interface.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_SOFT_INTERFACE_H_
+85 -7
net/batman-adv/sysfs.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h" ··· 327 329 return sprintf(buff, "%s\n", bat_priv->bat_algo_ops->name); 328 330 } 329 331 330 - static void batadv_post_gw_deselect(struct net_device *net_dev) 332 + static void batadv_post_gw_reselect(struct net_device *net_dev) 331 333 { 332 334 struct batadv_priv *bat_priv = netdev_priv(net_dev); 333 - batadv_gw_deselect(bat_priv); 335 + batadv_gw_reselect(bat_priv); 334 336 } 335 337 336 338 static ssize_t batadv_show_gw_mode(struct kobject *kobj, struct attribute *attr, ··· 406 408 batadv_info(net_dev, "Changing gw mode from: %s to: %s\n", 407 409 curr_gw_mode_str, buff); 408 410 409 - batadv_gw_deselect(bat_priv); 411 + /* Invoking batadv_gw_reselect() is not enough to really de-select the 412 + * current GW. It will only instruct the gateway client code to perform 413 + * a re-election the next time that this is needed. 414 + * 415 + * When gw client mode is being switched off the current GW must be 416 + * de-selected explicitly otherwise no GW_ADD uevent is thrown on 417 + * client mode re-activation. This is operation is performed in 418 + * batadv_gw_check_client_stop(). 419 + */ 420 + batadv_gw_reselect(bat_priv); 410 421 /* always call batadv_gw_check_client_stop() before changing the gateway 411 422 * state 412 423 */ ··· 450 443 return batadv_gw_bandwidth_set(net_dev, buff, count); 451 444 } 452 445 446 + /** 447 + * batadv_show_isolation_mark - print the current isolation mark/mask 448 + * @kobj: kobject representing the private mesh sysfs directory 449 + * @attr: the batman-adv attribute the user is interacting with 450 + * @buff: the buffer that will contain the data to send back to the user 451 + * 452 + * Returns the number of bytes written into 'buff' on success or a negative 453 + * error code in case of failure 454 + */ 455 + static ssize_t batadv_show_isolation_mark(struct kobject *kobj, 456 + struct attribute *attr, char *buff) 457 + { 458 + struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); 459 + 460 + return sprintf(buff, "%#.8x/%#.8x\n", bat_priv->isolation_mark, 461 + bat_priv->isolation_mark_mask); 462 + } 463 + 464 + /** 465 + * batadv_store_isolation_mark - parse and store the isolation mark/mask entered 466 + * by the user 467 + * @kobj: kobject representing the private mesh sysfs directory 468 + * @attr: the batman-adv attribute the user is interacting with 469 + * @buff: the buffer containing the user data 470 + * @count: number of bytes in the buffer 471 + * 472 + * Returns 'count' on success or a negative error code in case of failure 473 + */ 474 + static ssize_t batadv_store_isolation_mark(struct kobject *kobj, 475 + struct attribute *attr, char *buff, 476 + size_t count) 477 + { 478 + struct net_device *net_dev = batadv_kobj_to_netdev(kobj); 479 + struct batadv_priv *bat_priv = netdev_priv(net_dev); 480 + uint32_t mark, mask; 481 + char *mask_ptr; 482 + 483 + /* parse the mask if it has been specified, otherwise assume the mask is 484 + * the biggest possible 485 + */ 486 + mask = 0xFFFFFFFF; 487 + mask_ptr = strchr(buff, '/'); 488 + if (mask_ptr) { 489 + *mask_ptr = '\0'; 490 + mask_ptr++; 491 + 492 + /* the mask must be entered in hex base as it is going to be a 493 + * bitmask and not a prefix length 494 + */ 495 + if (kstrtou32(mask_ptr, 16, &mask) < 0) 496 + return -EINVAL; 497 + } 498 + 499 + /* the mark can be entered in any base */ 500 + if (kstrtou32(buff, 0, &mark) < 0) 501 + return -EINVAL; 502 + 503 + bat_priv->isolation_mark_mask = mask; 504 + /* erase bits not covered by the mask */ 505 + bat_priv->isolation_mark = mark & bat_priv->isolation_mark_mask; 506 + 507 + batadv_info(net_dev, 508 + "New skb mark for extended isolation: %#.8x/%#.8x\n", 509 + bat_priv->isolation_mark, bat_priv->isolation_mark_mask); 510 + 511 + return count; 512 + } 513 + 453 514 BATADV_ATTR_SIF_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL); 454 515 BATADV_ATTR_SIF_BOOL(bonding, S_IRUGO | S_IWUSR, NULL); 455 516 #ifdef CONFIG_BATMAN_ADV_BLA ··· 536 461 BATADV_ATTR_SIF_UINT(hop_penalty, S_IRUGO | S_IWUSR, 0, BATADV_TQ_MAX_VALUE, 537 462 NULL); 538 463 BATADV_ATTR_SIF_UINT(gw_sel_class, S_IRUGO | S_IWUSR, 1, BATADV_TQ_MAX_VALUE, 539 - batadv_post_gw_deselect); 464 + batadv_post_gw_reselect); 540 465 static BATADV_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth, 541 466 batadv_store_gw_bwidth); 542 467 #ifdef CONFIG_BATMAN_ADV_DEBUG ··· 546 471 BATADV_ATTR_SIF_BOOL(network_coding, S_IRUGO | S_IWUSR, 547 472 batadv_nc_status_update); 548 473 #endif 474 + static BATADV_ATTR(isolation_mark, S_IRUGO | S_IWUSR, 475 + batadv_show_isolation_mark, batadv_store_isolation_mark); 549 476 550 477 static struct batadv_attribute *batadv_mesh_attrs[] = { 551 478 &batadv_attr_aggregated_ogms, ··· 571 494 #ifdef CONFIG_BATMAN_ADV_NC 572 495 &batadv_attr_network_coding, 573 496 #endif 497 + &batadv_attr_isolation_mark, 574 498 NULL, 575 499 }; 576 500
+1 -3
net/batman-adv/sysfs.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_SYSFS_H_
+56 -20
net/batman-adv/translation-table.c
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #include "main.h" ··· 474 476 * @vid: VLAN identifier 475 477 * @ifindex: index of the interface where the client is connected to (useful to 476 478 * identify wireless clients) 479 + * @mark: the value contained in the skb->mark field of the received packet (if 480 + * any) 477 481 * 478 482 * Returns true if the client was successfully added, false otherwise. 479 483 */ 480 484 bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr, 481 - unsigned short vid, int ifindex) 485 + unsigned short vid, int ifindex, uint32_t mark) 482 486 { 483 487 struct batadv_priv *bat_priv = netdev_priv(soft_iface); 484 488 struct batadv_tt_local_entry *tt_local; ··· 491 491 int hash_added, table_size, packet_size_max; 492 492 bool ret = false, roamed_back = false; 493 493 uint8_t remote_flags; 494 + uint32_t match_mark; 494 495 495 496 if (ifindex != BATADV_NULL_IFINDEX) 496 497 in_dev = dev_get_by_index(&init_net, ifindex); ··· 615 614 tt_local->common.flags |= BATADV_TT_CLIENT_WIFI; 616 615 else 617 616 tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI; 617 + 618 + /* check the mark in the skb: if it's equal to the configured 619 + * isolation_mark, it means the packet is coming from an isolated 620 + * non-mesh client 621 + */ 622 + match_mark = (mark & bat_priv->isolation_mark_mask); 623 + if (bat_priv->isolation_mark_mask && 624 + match_mark == bat_priv->isolation_mark) 625 + tt_local->common.flags |= BATADV_TT_CLIENT_ISOLA; 626 + else 627 + tt_local->common.flags &= ~BATADV_TT_CLIENT_ISOLA; 618 628 619 629 /* if any "dynamic" flag has been modified, resend an ADD event for this 620 630 * entry so that all the nodes can get the new flags ··· 887 875 seq_printf(seq, 888 876 "Locally retrieved addresses (from %s) announced via TT (TTVN: %u):\n", 889 877 net_dev->name, (uint8_t)atomic_read(&bat_priv->tt.vn)); 890 - seq_printf(seq, " %-13s %s %-7s %-9s (%-10s)\n", "Client", "VID", 878 + seq_printf(seq, " %-13s %s %-8s %-9s (%-10s)\n", "Client", "VID", 891 879 "Flags", "Last seen", "CRC"); 892 880 893 881 for (i = 0; i < hash->size; i++) { ··· 915 903 } 916 904 917 905 seq_printf(seq, 918 - " * %pM %4i [%c%c%c%c%c] %3u.%03u (%#.8x)\n", 906 + " * %pM %4i [%c%c%c%c%c%c] %3u.%03u (%#.8x)\n", 919 907 tt_common_entry->addr, 920 908 BATADV_PRINT_VID(tt_common_entry->vid), 921 909 (tt_common_entry->flags & ··· 927 915 BATADV_TT_CLIENT_PENDING ? 'X' : '.'), 928 916 (tt_common_entry->flags & 929 917 BATADV_TT_CLIENT_WIFI ? 'W' : '.'), 918 + (tt_common_entry->flags & 919 + BATADV_TT_CLIENT_ISOLA ? 'I' : '.'), 930 920 no_purge ? 0 : last_seen_secs, 931 921 no_purge ? 0 : last_seen_msecs, 932 922 vlan->tt.crc); ··· 1461 1447 1462 1448 last_ttvn = atomic_read(&best_entry->orig_node->last_ttvn); 1463 1449 seq_printf(seq, 1464 - " %c %pM %4i (%3u) via %pM (%3u) (%#.8x) [%c%c%c]\n", 1450 + " %c %pM %4i (%3u) via %pM (%3u) (%#.8x) [%c%c%c%c]\n", 1465 1451 '*', tt_global_entry->common.addr, 1466 1452 BATADV_PRINT_VID(tt_global_entry->common.vid), 1467 1453 best_entry->ttvn, best_entry->orig_node->orig, 1468 1454 last_ttvn, vlan->tt.crc, 1469 1455 (flags & BATADV_TT_CLIENT_ROAM ? 'R' : '.'), 1470 1456 (flags & BATADV_TT_CLIENT_WIFI ? 'W' : '.'), 1457 + (flags & BATADV_TT_CLIENT_ISOLA ? 'I' : '.'), 1471 1458 (flags & BATADV_TT_CLIENT_TEMP ? 'T' : '.')); 1472 1459 1473 1460 batadv_orig_node_vlan_free_ref(vlan); ··· 1493 1478 1494 1479 last_ttvn = atomic_read(&orig_entry->orig_node->last_ttvn); 1495 1480 seq_printf(seq, 1496 - " %c %pM %4d (%3u) via %pM (%3u) (%#.8x) [%c%c%c]\n", 1481 + " %c %pM %4d (%3u) via %pM (%3u) (%#.8x) [%c%c%c%c]\n", 1497 1482 '+', tt_global_entry->common.addr, 1498 1483 BATADV_PRINT_VID(tt_global_entry->common.vid), 1499 1484 orig_entry->ttvn, orig_entry->orig_node->orig, 1500 1485 last_ttvn, vlan->tt.crc, 1501 1486 (flags & BATADV_TT_CLIENT_ROAM ? 'R' : '.'), 1502 1487 (flags & BATADV_TT_CLIENT_WIFI ? 'W' : '.'), 1488 + (flags & BATADV_TT_CLIENT_ISOLA ? 'I' : '.'), 1503 1489 (flags & BATADV_TT_CLIENT_TEMP ? 'T' : '.')); 1504 1490 1505 1491 batadv_orig_node_vlan_free_ref(vlan); ··· 1869 1853 tt_global_entry->common.flags & BATADV_TT_CLIENT_WIFI) 1870 1854 ret = true; 1871 1855 1856 + /* check if the two clients are marked as isolated */ 1857 + if (tt_local_entry->common.flags & BATADV_TT_CLIENT_ISOLA && 1858 + tt_global_entry->common.flags & BATADV_TT_CLIENT_ISOLA) 1859 + ret = true; 1860 + 1872 1861 return ret; 1873 1862 } 1874 1863 ··· 1900 1879 struct batadv_tt_global_entry *tt_global_entry = NULL; 1901 1880 struct batadv_orig_node *orig_node = NULL; 1902 1881 struct batadv_tt_orig_list_entry *best_entry; 1903 - bool ap_isolation_enabled = false; 1904 - struct batadv_softif_vlan *vlan; 1905 1882 1906 - /* if the AP isolation is requested on a VLAN, then check for its 1907 - * setting in the proper VLAN private data structure 1908 - */ 1909 - vlan = batadv_softif_vlan_get(bat_priv, vid); 1910 - if (vlan) { 1911 - ap_isolation_enabled = atomic_read(&vlan->ap_isolation); 1912 - batadv_softif_vlan_free_ref(vlan); 1913 - } 1914 - 1915 - if (src && ap_isolation_enabled) { 1883 + if (src && batadv_vlan_ap_isola_get(bat_priv, vid)) { 1916 1884 tt_local_entry = batadv_tt_local_hash_find(bat_priv, src, vid); 1917 1885 if (!tt_local_entry || 1918 1886 (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING)) ··· 3576 3566 msecs_to_jiffies(BATADV_TT_WORK_PERIOD)); 3577 3567 3578 3568 return 1; 3569 + } 3570 + 3571 + /** 3572 + * batadv_tt_global_is_isolated - check if a client is marked as isolated 3573 + * @bat_priv: the bat priv with all the soft interface information 3574 + * @addr: the mac address of the client 3575 + * @vid: the identifier of the VLAN where this client is connected 3576 + * 3577 + * Returns true if the client is marked with the TT_CLIENT_ISOLA flag, false 3578 + * otherwise 3579 + */ 3580 + bool batadv_tt_global_is_isolated(struct batadv_priv *bat_priv, 3581 + const uint8_t *addr, unsigned short vid) 3582 + { 3583 + struct batadv_tt_global_entry *tt; 3584 + bool ret; 3585 + 3586 + tt = batadv_tt_global_hash_find(bat_priv, addr, vid); 3587 + if (!tt) 3588 + return false; 3589 + 3590 + ret = tt->common.flags & BATADV_TT_CLIENT_ISOLA; 3591 + 3592 + batadv_tt_global_entry_free_ref(tt); 3593 + 3594 + return ret; 3579 3595 }
+4 -4
net/batman-adv/translation-table.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ ··· 20 22 21 23 int batadv_tt_init(struct batadv_priv *bat_priv); 22 24 bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr, 23 - unsigned short vid, int ifindex); 25 + unsigned short vid, int ifindex, uint32_t mark); 24 26 uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv, 25 27 const uint8_t *addr, unsigned short vid, 26 28 const char *message, bool roaming); ··· 48 50 struct batadv_orig_node *orig_node, 49 51 const unsigned char *addr, 50 52 unsigned short vid); 53 + bool batadv_tt_global_is_isolated(struct batadv_priv *bat_priv, 54 + const uint8_t *addr, unsigned short vid); 51 55 52 56 #endif /* _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ */
+15 -3
net/batman-adv/types.h
··· 12 12 * General Public License for more details. 13 13 * 14 14 * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 - * 02110-1301, USA 15 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 16 */ 19 17 20 18 #ifndef _NET_BATMAN_ADV_TYPES_H_ ··· 32 34 #define batadv_dat_addr_t uint16_t 33 35 34 36 #endif /* CONFIG_BATMAN_ADV_DAT */ 37 + 38 + /** 39 + * enum batadv_dhcp_recipient - dhcp destination 40 + * @BATADV_DHCP_NO: packet is not a dhcp message 41 + * @BATADV_DHCP_TO_SERVER: dhcp message is directed to a server 42 + * @BATADV_DHCP_TO_CLIENT: dhcp message is directed to a client 43 + */ 44 + enum batadv_dhcp_recipient { 45 + BATADV_DHCP_NO = 0, 46 + BATADV_DHCP_TO_SERVER, 47 + BATADV_DHCP_TO_CLIENT, 48 + }; 35 49 36 50 /** 37 51 * BATADV_TT_REMOTE_MASK - bitmask selecting the flags that are sent over the ··· 697 687 #ifdef CONFIG_BATMAN_ADV_DEBUG 698 688 atomic_t log_level; 699 689 #endif 690 + uint32_t isolation_mark; 691 + uint32_t isolation_mark_mask; 700 692 atomic_t bcast_seqno; 701 693 atomic_t bcast_queue_left; 702 694 atomic_t batman_queue_left;