17db7d9f3SSven Eckelmann /* SPDX-License-Identifier: GPL-2.0 */ 2ac79cbb9SSven Eckelmann /* Copyright (C) 2007-2017 B.A.T.M.A.N. contributors: 3c6c8fea2SSven Eckelmann * 4c6c8fea2SSven Eckelmann * Marek Lindner, Simon Wunderlich 5c6c8fea2SSven Eckelmann * 6c6c8fea2SSven Eckelmann * This program is free software; you can redistribute it and/or 7c6c8fea2SSven Eckelmann * modify it under the terms of version 2 of the GNU General Public 8c6c8fea2SSven Eckelmann * License as published by the Free Software Foundation. 9c6c8fea2SSven Eckelmann * 10c6c8fea2SSven Eckelmann * This program is distributed in the hope that it will be useful, but 11c6c8fea2SSven Eckelmann * WITHOUT ANY WARRANTY; without even the implied warranty of 12c6c8fea2SSven Eckelmann * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13c6c8fea2SSven Eckelmann * General Public License for more details. 14c6c8fea2SSven Eckelmann * 15c6c8fea2SSven Eckelmann * You should have received a copy of the GNU General Public License 16ebf38fb7SAntonio Quartulli * along with this program; if not, see <http://www.gnu.org/licenses/>. 17c6c8fea2SSven Eckelmann */ 18c6c8fea2SSven Eckelmann 19c6c8fea2SSven Eckelmann #ifndef _NET_BATMAN_ADV_MAIN_H_ 20c6c8fea2SSven Eckelmann #define _NET_BATMAN_ADV_MAIN_H_ 21c6c8fea2SSven Eckelmann 22bc58eeefSMarek Lindner #define BATADV_DRIVER_AUTHOR "Marek Lindner <mareklindner@neomailbox.ch>, " \ 23c679ff8fSSimon Wunderlich "Simon Wunderlich <sw@simonwunderlich.de>" 2442d0b044SSven Eckelmann #define BATADV_DRIVER_DESC "B.A.T.M.A.N. advanced" 2542d0b044SSven Eckelmann #define BATADV_DRIVER_DEVICE "batman-adv" 26c6c8fea2SSven Eckelmann 2742d0b044SSven Eckelmann #ifndef BATADV_SOURCE_VERSION 2802dd9a8aSSimon Wunderlich #define BATADV_SOURCE_VERSION "2018.0" 2944c4349aSSven Eckelmann #endif 30c6c8fea2SSven Eckelmann 31c6c8fea2SSven Eckelmann /* B.A.T.M.A.N. parameters */ 32c6c8fea2SSven Eckelmann 3342d0b044SSven Eckelmann #define BATADV_TQ_MAX_VALUE 255 340da00359SAntonio Quartulli #define BATADV_THROUGHPUT_MAX_VALUE 0xFFFFFFFF 3542d0b044SSven Eckelmann #define BATADV_JITTER 20 36c6c8fea2SSven Eckelmann 376e215fd8SSven Eckelmann /* Time To Live of broadcast messages */ 3842d0b044SSven Eckelmann #define BATADV_TTL 50 396e215fd8SSven Eckelmann 4081f02683SSimon Wunderlich /* maximum sequence number age of broadcast messages */ 4181f02683SSimon Wunderlich #define BATADV_BCAST_MAX_AGE 64 4281f02683SSimon Wunderlich 436e215fd8SSven Eckelmann /* purge originators after time in seconds if no valid packet comes in 4442d0b044SSven Eckelmann * -> TODO: check influence on BATADV_TQ_LOCAL_WINDOW_SIZE 459cfc7bd6SSven Eckelmann */ 4642d0b044SSven Eckelmann #define BATADV_PURGE_TIMEOUT 200000 /* 200 seconds */ 477cf4d520SAntonio Quartulli #define BATADV_TT_LOCAL_TIMEOUT 600000 /* in milliseconds */ 48a51fb9b2SAntonio Quartulli #define BATADV_TT_CLIENT_ROAM_TIMEOUT 600000 /* in milliseconds */ 4930cfd02bSAntonio Quartulli #define BATADV_TT_CLIENT_TEMP_TIMEOUT 600000 /* in milliseconds */ 5072414442SAntonio Quartulli #define BATADV_TT_WORK_PERIOD 5000 /* 5 seconds */ 5172414442SAntonio Quartulli #define BATADV_ORIG_WORK_PERIOD 1000 /* 1 second */ 52cbebd363SLinus Lüssing #define BATADV_MCAST_WORK_PERIOD 500 /* 0.5 seconds */ 532f1dfbe1SAntonio Quartulli #define BATADV_DAT_ENTRY_TIMEOUT (5 * 60000) /* 5 mins in milliseconds */ 54015758d0SAntonio Quartulli /* sliding packet range of received originator messages in sequence numbers 559cfc7bd6SSven Eckelmann * (should be a multiple of our word size) 569cfc7bd6SSven Eckelmann */ 5742d0b044SSven Eckelmann #define BATADV_TQ_LOCAL_WINDOW_SIZE 64 58a51fb9b2SAntonio Quartulli /* milliseconds we have to keep pending tt_req */ 5942d0b044SSven Eckelmann #define BATADV_TT_REQUEST_TIMEOUT 3000 60a73105b8SAntonio Quartulli 6142d0b044SSven Eckelmann #define BATADV_TQ_GLOBAL_WINDOW_SIZE 5 6242d0b044SSven Eckelmann #define BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM 1 6342d0b044SSven Eckelmann #define BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM 1 6442d0b044SSven Eckelmann #define BATADV_TQ_TOTAL_BIDRECT_LIMIT 1 65c6c8fea2SSven Eckelmann 66162bd64cSLinus Luessing /* B.A.T.M.A.N. V */ 67c833484eSAntonio Quartulli #define BATADV_THROUGHPUT_DEFAULT_VALUE 10 /* 1 Mbps */ 688d2d499eSAntonio Quartulli #define BATADV_ELP_PROBES_PER_NODE 2 698d2d499eSAntonio Quartulli #define BATADV_ELP_MIN_PROBE_SIZE 200 /* bytes */ 708d2d499eSAntonio Quartulli #define BATADV_ELP_PROBE_MAX_TX_DIFF 100 /* milliseconds */ 71162bd64cSLinus Luessing #define BATADV_ELP_MAX_AGE 64 729323158eSAntonio Quartulli #define BATADV_OGM_MAX_ORIGDIFF 5 739323158eSAntonio Quartulli #define BATADV_OGM_MAX_AGE 64 74162bd64cSLinus Luessing 7542d0b044SSven Eckelmann /* number of OGMs sent with the last tt diff */ 7642d0b044SSven Eckelmann #define BATADV_TT_OGM_APPEND_MAX 3 77a73105b8SAntonio Quartulli 789cfc7bd6SSven Eckelmann /* Time in which a client can roam at most ROAMING_MAX_COUNT times in 79a51fb9b2SAntonio Quartulli * milliseconds 809cfc7bd6SSven Eckelmann */ 8142d0b044SSven Eckelmann #define BATADV_ROAMING_MAX_TIME 20000 8242d0b044SSven Eckelmann #define BATADV_ROAMING_MAX_COUNT 5 83cc47f66eSAntonio Quartulli 8442d0b044SSven Eckelmann #define BATADV_NO_FLAGS 0 85ecbd5321SMarek Lindner 8642d0b044SSven Eckelmann #define BATADV_NULL_IFINDEX 0 /* dummy ifindex used to avoid iface checks */ 87bc279080SAntonio Quartulli 889464d071SAntonio Quartulli #define BATADV_NO_MARK 0 899464d071SAntonio Quartulli 9089652331SSimon Wunderlich /* default interface for multi interface operation. The default interface is 9189652331SSimon Wunderlich * used for communication which originated locally (i.e. is not forwarded) 9289652331SSimon Wunderlich * or where special forwarding is not desired/necessary. 9389652331SSimon Wunderlich */ 9489652331SSimon Wunderlich #define BATADV_IF_DEFAULT ((struct batadv_hard_iface *)NULL) 9589652331SSimon Wunderlich 9642d0b044SSven Eckelmann #define BATADV_NUM_WORDS BITS_TO_LONGS(BATADV_TQ_LOCAL_WINDOW_SIZE) 97c6c8fea2SSven Eckelmann 9842d0b044SSven Eckelmann #define BATADV_LOG_BUF_LEN 8192 /* has to be a power of 2 */ 99c6c8fea2SSven Eckelmann 100caf65bfcSMatthias Schiffer /* number of packets to send for broadcasts on different interface types */ 101caf65bfcSMatthias Schiffer #define BATADV_NUM_BCASTS_DEFAULT 1 102caf65bfcSMatthias Schiffer #define BATADV_NUM_BCASTS_WIRELESS 3 103caf65bfcSMatthias Schiffer #define BATADV_NUM_BCASTS_MAX 3 104caf65bfcSMatthias Schiffer 10533a3bb4aSAntonio Quartulli /* length of the single packet used by the TP meter */ 10633a3bb4aSAntonio Quartulli #define BATADV_TP_PACKET_LEN ETH_DATA_LEN 10733a3bb4aSAntonio Quartulli 108c384ea3eSAntonio Quartulli /* msecs after which an ARP_REQUEST is sent in broadcast as fallback */ 109c384ea3eSAntonio Quartulli #define ARP_REQ_DELAY 250 110785ea114SAntonio Quartulli /* numbers of originator to contact for any PUT/GET DHT operation */ 111785ea114SAntonio Quartulli #define BATADV_DAT_CANDIDATES_NUM 3 112785ea114SAntonio Quartulli 113a0e28775SMartin Hundebøll /* BATADV_TQ_SIMILARITY_THRESHOLD - TQ points that a secondary metric can differ 114c43c981eSAntonio Quartulli * at most from the primary one in order to be still considered acceptable 115c43c981eSAntonio Quartulli */ 116c43c981eSAntonio Quartulli #define BATADV_TQ_SIMILARITY_THRESHOLD 50 117c43c981eSAntonio Quartulli 1186e215fd8SSven Eckelmann /* should not be bigger than 512 bytes or change the size of 1199cfc7bd6SSven Eckelmann * forw_packet->direct_link_flags 1209cfc7bd6SSven Eckelmann */ 12142d0b044SSven Eckelmann #define BATADV_MAX_AGGREGATION_BYTES 512 12242d0b044SSven Eckelmann #define BATADV_MAX_AGGREGATION_MS 100 123c6c8fea2SSven Eckelmann 12442d0b044SSven Eckelmann #define BATADV_BLA_PERIOD_LENGTH 10000 /* 10 seconds */ 125e1544f3cSSimon Wunderlich #define BATADV_BLA_BACKBONE_TIMEOUT (BATADV_BLA_PERIOD_LENGTH * 6) 12642d0b044SSven Eckelmann #define BATADV_BLA_CLAIM_TIMEOUT (BATADV_BLA_PERIOD_LENGTH * 10) 12728709878SSimon Wunderlich #define BATADV_BLA_WAIT_PERIODS 3 128cd9c7bfbSSimon Wunderlich #define BATADV_BLA_LOOPDETECT_PERIODS 6 129cd9c7bfbSSimon Wunderlich #define BATADV_BLA_LOOPDETECT_TIMEOUT 3000 /* 3 seconds */ 130fe2da6ffSSimon Wunderlich 13142d0b044SSven Eckelmann #define BATADV_DUPLIST_SIZE 16 13242d0b044SSven Eckelmann #define BATADV_DUPLIST_TIMEOUT 500 /* 500 ms */ 1336e215fd8SSven Eckelmann /* don't reset again within 30 seconds */ 13442d0b044SSven Eckelmann #define BATADV_RESET_PROTECTION_MS 30000 13542d0b044SSven Eckelmann #define BATADV_EXPECTED_SEQNO_RANGE 65536 136c6c8fea2SSven Eckelmann 137d56b1705SMartin Hundebøll #define BATADV_NC_NODE_TIMEOUT 10000 /* Milliseconds */ 138d56b1705SMartin Hundebøll 13933a3bb4aSAntonio Quartulli /** 14033a3bb4aSAntonio Quartulli * BATADV_TP_MAX_NUM - maximum number of simultaneously active tp sessions 14133a3bb4aSAntonio Quartulli */ 14233a3bb4aSAntonio Quartulli #define BATADV_TP_MAX_NUM 5 14333a3bb4aSAntonio Quartulli 14473844a8cSSven Eckelmann /** 14573844a8cSSven Eckelmann * enum batadv_mesh_state - State of a soft interface 14673844a8cSSven Eckelmann */ 14739c75a51SSven Eckelmann enum batadv_mesh_state { 14873844a8cSSven Eckelmann /** @BATADV_MESH_INACTIVE: soft interface is not yet running */ 14939c75a51SSven Eckelmann BATADV_MESH_INACTIVE, 15073844a8cSSven Eckelmann 15173844a8cSSven Eckelmann /** @BATADV_MESH_ACTIVE: interface is up and running */ 15239c75a51SSven Eckelmann BATADV_MESH_ACTIVE, 15373844a8cSSven Eckelmann 15473844a8cSSven Eckelmann /** @BATADV_MESH_DEACTIVATING: interface is getting shut down */ 15539c75a51SSven Eckelmann BATADV_MESH_DEACTIVATING, 156e8958dbfSSven Eckelmann }; 157c6c8fea2SSven Eckelmann 15842d0b044SSven Eckelmann #define BATADV_BCAST_QUEUE_LEN 256 15942d0b044SSven Eckelmann #define BATADV_BATMAN_QUEUE_LEN 256 160c6c8fea2SSven Eckelmann 16173844a8cSSven Eckelmann /** 16273844a8cSSven Eckelmann * enum batadv_uev_action - action type of uevent 16373844a8cSSven Eckelmann */ 16439c75a51SSven Eckelmann enum batadv_uev_action { 16573844a8cSSven Eckelmann /** @BATADV_UEV_ADD: gateway was selected (after none was selected) */ 16639c75a51SSven Eckelmann BATADV_UEV_ADD = 0, 16773844a8cSSven Eckelmann 16873844a8cSSven Eckelmann /** 16973844a8cSSven Eckelmann * @BATADV_UEV_DEL: selected gateway was removed and none is selected 17073844a8cSSven Eckelmann * anymore 17173844a8cSSven Eckelmann */ 17239c75a51SSven Eckelmann BATADV_UEV_DEL, 17373844a8cSSven Eckelmann 17473844a8cSSven Eckelmann /** 17573844a8cSSven Eckelmann * @BATADV_UEV_CHANGE: a different gateway was selected as based gateway 17673844a8cSSven Eckelmann */ 17739c75a51SSven Eckelmann BATADV_UEV_CHANGE, 17873844a8cSSven Eckelmann 17973844a8cSSven Eckelmann /** 18073844a8cSSven Eckelmann * @BATADV_UEV_LOOPDETECT: loop was detected which cannot be handled by 18173844a8cSSven Eckelmann * bridge loop avoidance 18273844a8cSSven Eckelmann */ 183cd9c7bfbSSimon Wunderlich BATADV_UEV_LOOPDETECT, 184c6bda689SAntonio Quartulli }; 185c6bda689SAntonio Quartulli 18673844a8cSSven Eckelmann /** 18773844a8cSSven Eckelmann * enum batadv_uev_type - Type of uevent 18873844a8cSSven Eckelmann */ 18939c75a51SSven Eckelmann enum batadv_uev_type { 19073844a8cSSven Eckelmann /** @BATADV_UEV_GW: selected gateway was modified */ 19139c75a51SSven Eckelmann BATADV_UEV_GW = 0, 19273844a8cSSven Eckelmann 19373844a8cSSven Eckelmann /** @BATADV_UEV_BLA: bridge loop avoidance event */ 194cd9c7bfbSSimon Wunderlich BATADV_UEV_BLA, 195c6bda689SAntonio Quartulli }; 196c6bda689SAntonio Quartulli 19742d0b044SSven Eckelmann #define BATADV_GW_THRESHOLD 50 19843676ab5SAntonio Quartulli 199610bfc6bSMartin Hundebøll /* Number of fragment chains for each orig_node */ 200610bfc6bSMartin Hundebøll #define BATADV_FRAG_BUFFER_COUNT 8 201610bfc6bSMartin Hundebøll /* Maximum number of fragments for one packet */ 202610bfc6bSMartin Hundebøll #define BATADV_FRAG_MAX_FRAGMENTS 16 203610bfc6bSMartin Hundebøll /* Maxumim size of each fragment */ 2048ea026b1SMatthias Schiffer #define BATADV_FRAG_MAX_FRAG_SIZE 1280 205610bfc6bSMartin Hundebøll /* Time to keep fragments while waiting for rest of the fragments */ 206610bfc6bSMartin Hundebøll #define BATADV_FRAG_TIMEOUT 10000 207610bfc6bSMartin Hundebøll 208785ea114SAntonio Quartulli #define BATADV_DAT_CANDIDATE_NOT_FOUND 0 209785ea114SAntonio Quartulli #define BATADV_DAT_CANDIDATE_ORIG 1 210785ea114SAntonio Quartulli 21121a1236bSSven Eckelmann /* Debug Messages */ 212c6c8fea2SSven Eckelmann #ifdef pr_fmt 213c6c8fea2SSven Eckelmann #undef pr_fmt 214c6c8fea2SSven Eckelmann #endif 2156e215fd8SSven Eckelmann /* Append 'batman-adv: ' before kernel messages */ 2166e215fd8SSven Eckelmann #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 217c6c8fea2SSven Eckelmann 21821a1236bSSven Eckelmann /* Kernel headers */ 219c6c8fea2SSven Eckelmann 2201e2c2a4fSSven Eckelmann #include <linux/compiler.h> 2211e2c2a4fSSven Eckelmann #include <linux/etherdevice.h> 222fcafa5e7SSven Eckelmann #include <linux/if_vlan.h> 223fcafa5e7SSven Eckelmann #include <linux/jiffies.h> 224fcafa5e7SSven Eckelmann #include <linux/percpu.h> 2251e2c2a4fSSven Eckelmann #include <linux/types.h> 226*fec149f5SSven Eckelmann #include <uapi/linux/batadv_packet.h> 22716052789SAntonio Quartulli 228c6c8fea2SSven Eckelmann #include "types.h" 229c6c8fea2SSven Eckelmann 230ba412080SSven Eckelmann struct net_device; 231ba412080SSven Eckelmann struct packet_type; 2321e2c2a4fSSven Eckelmann struct seq_file; 2331e2c2a4fSSven Eckelmann struct sk_buff; 2341e2c2a4fSSven Eckelmann 235f7a2bd65SSven Eckelmann /** 2367e9a8c2cSSven Eckelmann * batadv_print_vid() - return printable version of vid information 237f7a2bd65SSven Eckelmann * @vid: the VLAN identifier 238f7a2bd65SSven Eckelmann * 239f7a2bd65SSven Eckelmann * Return: -1 when no VLAN is used, VLAN id otherwise 240f7a2bd65SSven Eckelmann */ 241f7a2bd65SSven Eckelmann static inline int batadv_print_vid(unsigned short vid) 242f7a2bd65SSven Eckelmann { 243f7a2bd65SSven Eckelmann if (vid & BATADV_VLAN_HAS_TAG) 244f7a2bd65SSven Eckelmann return (int)(vid & VLAN_VID_MASK); 245f7a2bd65SSven Eckelmann else 246f7a2bd65SSven Eckelmann return -1; 247f7a2bd65SSven Eckelmann } 248eb2deb6bSAntonio Quartulli 2493193e8fdSSven Eckelmann extern struct list_head batadv_hardif_list; 250c6c8fea2SSven Eckelmann 2513193e8fdSSven Eckelmann extern unsigned char batadv_broadcast_addr[]; 2523193e8fdSSven Eckelmann extern struct workqueue_struct *batadv_event_workqueue; 253c6c8fea2SSven Eckelmann 2543193e8fdSSven Eckelmann int batadv_mesh_init(struct net_device *soft_iface); 2553193e8fdSSven Eckelmann void batadv_mesh_free(struct net_device *soft_iface); 2566b5e971aSSven Eckelmann bool batadv_is_my_mac(struct batadv_priv *bat_priv, const u8 *addr); 25730da63a6SMarek Lindner struct batadv_hard_iface * 25830da63a6SMarek Lindner batadv_seq_print_text_primary_if_get(struct seq_file *seq); 259411d6ed9SMarek Lindner int batadv_max_header_len(void); 260c54f38c9SSimon Wunderlich void batadv_skb_set_priority(struct sk_buff *skb, int offset); 2613193e8fdSSven Eckelmann int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev, 2623193e8fdSSven Eckelmann struct packet_type *ptype, 2633193e8fdSSven Eckelmann struct net_device *orig_dev); 26456303d34SSven Eckelmann int 2656b5e971aSSven Eckelmann batadv_recv_handler_register(u8 packet_type, 266ffa995e0SMarek Lindner int (*recv_handler)(struct sk_buff *, 26756303d34SSven Eckelmann struct batadv_hard_iface *)); 2686b5e971aSSven Eckelmann void batadv_recv_handler_unregister(u8 packet_type); 26995a066d8SSven Eckelmann __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr); 270c6c8fea2SSven Eckelmann 2710aca86cdSAntonio Quartulli /** 2727e9a8c2cSSven Eckelmann * batadv_compare_eth() - Compare two not u16 aligned Ethernet addresses 2737afcbbefSSven Eckelmann * @data1: Pointer to a six-byte array containing the Ethernet address 2747afcbbefSSven Eckelmann * @data2: Pointer other six-byte array containing the Ethernet address 27539901e71SMarek Lindner * 276c3923b7aSJoe Perches * note: can't use ether_addr_equal() as it requires aligned memory 27762fe710fSSven Eckelmann * 2784b426b10SSven Eckelmann * Return: true if they are the same ethernet addr 27939901e71SMarek Lindner */ 280f2d5cf2aSMarkus Pargmann static inline bool batadv_compare_eth(const void *data1, const void *data2) 28139901e71SMarek Lindner { 282d9cd4fe5SJoe Perches return ether_addr_equal_unaligned(data1, data2); 28339901e71SMarek Lindner } 28439901e71SMarek Lindner 2852c53040fSBen Hutchings /** 2867e9a8c2cSSven Eckelmann * batadv_has_timed_out() - compares current time (jiffies) and timestamp + 2876d030de8SAntonio Quartulli * timeout 288a04ccd59SMartin Hundebøll * @timestamp: base value to compare with (in jiffies) 289a04ccd59SMartin Hundebøll * @timeout: added to base value before comparing (in milliseconds) 290a04ccd59SMartin Hundebøll * 29162fe710fSSven Eckelmann * Return: true if current time is after timestamp + timeout 292a04ccd59SMartin Hundebøll */ 2931eda58bfSSven Eckelmann static inline bool batadv_has_timed_out(unsigned long timestamp, 2941eda58bfSSven Eckelmann unsigned int timeout) 295a04ccd59SMartin Hundebøll { 296a04ccd59SMartin Hundebøll return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout)); 297a04ccd59SMartin Hundebøll } 298747e4221SSven Eckelmann 299e57acf8eSSven Eckelmann /** 300e57acf8eSSven Eckelmann * batadv_atomic_dec_not_zero() - Decrease unless the number is 0 301e57acf8eSSven Eckelmann * @v: pointer of type atomic_t 302e57acf8eSSven Eckelmann * 303e57acf8eSSven Eckelmann * Return: non-zero if v was not 0, and zero otherwise. 304e57acf8eSSven Eckelmann */ 3053e34819eSSven Eckelmann #define batadv_atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) 3065f657ec0SAntonio Quartulli 307e57acf8eSSven Eckelmann /** 308e57acf8eSSven Eckelmann * batadv_smallest_signed_int() - Returns the smallest signed integer in two's 309e57acf8eSSven Eckelmann * complement with the sizeof x 310e57acf8eSSven Eckelmann * @x: type of integer 311e57acf8eSSven Eckelmann * 312e57acf8eSSven Eckelmann * Return: smallest signed integer of type 313e57acf8eSSven Eckelmann */ 3143e34819eSSven Eckelmann #define batadv_smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u))) 315f5d33d37SAntonio Quartulli 316e57acf8eSSven Eckelmann /** 317e57acf8eSSven Eckelmann * batadv_seq_before() - Checks if a sequence number x is a predecessor of y 318e57acf8eSSven Eckelmann * @x: potential predecessor of @y 319e57acf8eSSven Eckelmann * @y: value to compare @x against 320e57acf8eSSven Eckelmann * 321e57acf8eSSven Eckelmann * It handles overflows/underflows and can correctly check for a predecessor 322e57acf8eSSven Eckelmann * unless the variable sequence number has grown by more then 323e57acf8eSSven Eckelmann * 2**(bitwidth(x)-1)-1. 324e57acf8eSSven Eckelmann * 3256b5e971aSSven Eckelmann * This means that for a u8 with the maximum value 255, it would think: 326e57acf8eSSven Eckelmann * 327e57acf8eSSven Eckelmann * * when adding nothing - it is neither a predecessor nor a successor 328e57acf8eSSven Eckelmann * * before adding more than 127 to the starting value - it is a predecessor, 329e57acf8eSSven Eckelmann * * when adding 128 - it is neither a predecessor nor a successor, 330e57acf8eSSven Eckelmann * * after adding more than 127 to the starting value - it is a successor 331e57acf8eSSven Eckelmann * 332e57acf8eSSven Eckelmann * Return: true when x is a predecessor of y, false otherwise 3339cfc7bd6SSven Eckelmann */ 3343e34819eSSven Eckelmann #define batadv_seq_before(x, y) ({typeof(x)_d1 = (x); \ 3350bb85751SSven Eckelmann typeof(y)_d2 = (y); \ 3360bb85751SSven Eckelmann typeof(x)_dummy = (_d1 - _d2); \ 3370bb85751SSven Eckelmann (void)(&_d1 == &_d2); \ 3383e34819eSSven Eckelmann _dummy > batadv_smallest_signed_int(_dummy); }) 339e57acf8eSSven Eckelmann 340e57acf8eSSven Eckelmann /** 341e57acf8eSSven Eckelmann * batadv_seq_after() - Checks if a sequence number x is a successor of y 342e57acf8eSSven Eckelmann * @x: potential sucessor of @y 343e57acf8eSSven Eckelmann * @y: value to compare @x against 344e57acf8eSSven Eckelmann * 345e57acf8eSSven Eckelmann * It handles overflows/underflows and can correctly check for a successor 346e57acf8eSSven Eckelmann * unless the variable sequence number has grown by more then 347e57acf8eSSven Eckelmann * 2**(bitwidth(x)-1)-1. 348e57acf8eSSven Eckelmann * 349e57acf8eSSven Eckelmann * This means that for a u8 with the maximum value 255, it would think: 350e57acf8eSSven Eckelmann * 351e57acf8eSSven Eckelmann * * when adding nothing - it is neither a predecessor nor a successor 352e57acf8eSSven Eckelmann * * before adding more than 127 to the starting value - it is a predecessor, 353e57acf8eSSven Eckelmann * * when adding 128 - it is neither a predecessor nor a successor, 354e57acf8eSSven Eckelmann * * after adding more than 127 to the starting value - it is a successor 355e57acf8eSSven Eckelmann * 356e57acf8eSSven Eckelmann * Return: true when x is a successor of y, false otherwise 357e57acf8eSSven Eckelmann */ 3583e34819eSSven Eckelmann #define batadv_seq_after(x, y) batadv_seq_before(y, x) 359f5d33d37SAntonio Quartulli 360e57acf8eSSven Eckelmann /** 361e57acf8eSSven Eckelmann * batadv_add_counter() - Add to per cpu statistics counter of soft interface 362e57acf8eSSven Eckelmann * @bat_priv: the bat priv with all the soft interface information 363e57acf8eSSven Eckelmann * @idx: counter index which should be modified 364e57acf8eSSven Eckelmann * @count: value to increase counter by 365e57acf8eSSven Eckelmann * 366e57acf8eSSven Eckelmann * Stop preemption on local cpu while incrementing the counter 367e57acf8eSSven Eckelmann */ 36856303d34SSven Eckelmann static inline void batadv_add_counter(struct batadv_priv *bat_priv, size_t idx, 369f8214865SMartin Hundebøll size_t count) 370f8214865SMartin Hundebøll { 37156917443SShan Wei this_cpu_add(bat_priv->bat_counters[idx], count); 372f8214865SMartin Hundebøll } 373f8214865SMartin Hundebøll 374e57acf8eSSven Eckelmann /** 375e57acf8eSSven Eckelmann * batadv_inc_counter() - Increase per cpu statistics counter of soft interface 376e57acf8eSSven Eckelmann * @b: the bat priv with all the soft interface information 377e57acf8eSSven Eckelmann * @i: counter index which should be modified 378e57acf8eSSven Eckelmann */ 379f8214865SMartin Hundebøll #define batadv_inc_counter(b, i) batadv_add_counter(b, i, 1) 380f8214865SMartin Hundebøll 381e57acf8eSSven Eckelmann /** 382e57acf8eSSven Eckelmann * BATADV_SKB_CB() - Get batadv_skb_cb from skb control buffer 383e57acf8eSSven Eckelmann * @__skb: skb holding the control buffer 384e57acf8eSSven Eckelmann * 385e57acf8eSSven Eckelmann * The members of the control buffer are defined in struct batadv_skb_cb in 386e57acf8eSSven Eckelmann * types.h. The macro is inspired by the similar macro TCP_SKB_CB() in tcp.h. 387e57acf8eSSven Eckelmann * 388e57acf8eSSven Eckelmann * Return: pointer to the batadv_skb_cb of the skb 3893c12de9aSMartin Hundebøll */ 3903c12de9aSMartin Hundebøll #define BATADV_SKB_CB(__skb) ((struct batadv_skb_cb *)&((__skb)->cb[0])) 3913c12de9aSMartin Hundebøll 392c018ad3dSAntonio Quartulli unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len); 393eceb22aeSAntonio Quartulli bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid); 394ef261577SMarek Lindner 395c6c8fea2SSven Eckelmann #endif /* _NET_BATMAN_ADV_MAIN_H_ */ 396