17db7d9f3SSven Eckelmann /* SPDX-License-Identifier: GPL-2.0 */ 27a79d717SSven Eckelmann /* Copyright (C) 2007-2019 B.A.T.M.A.N. contributors: 3c6c8fea2SSven Eckelmann * 4c6c8fea2SSven Eckelmann * Marek Lindner, Simon Wunderlich 5c6c8fea2SSven Eckelmann */ 6c6c8fea2SSven Eckelmann 7c6c8fea2SSven Eckelmann #ifndef _NET_BATMAN_ADV_MAIN_H_ 8c6c8fea2SSven Eckelmann #define _NET_BATMAN_ADV_MAIN_H_ 9c6c8fea2SSven Eckelmann 10bc58eeefSMarek Lindner #define BATADV_DRIVER_AUTHOR "Marek Lindner <mareklindner@neomailbox.ch>, " \ 11c679ff8fSSimon Wunderlich "Simon Wunderlich <sw@simonwunderlich.de>" 1242d0b044SSven Eckelmann #define BATADV_DRIVER_DESC "B.A.T.M.A.N. advanced" 1342d0b044SSven Eckelmann #define BATADV_DRIVER_DEVICE "batman-adv" 14c6c8fea2SSven Eckelmann 1542d0b044SSven Eckelmann #ifndef BATADV_SOURCE_VERSION 16eef98918SSimon Wunderlich #define BATADV_SOURCE_VERSION "2019.3" 1744c4349aSSven Eckelmann #endif 18c6c8fea2SSven Eckelmann 19c6c8fea2SSven Eckelmann /* B.A.T.M.A.N. parameters */ 20c6c8fea2SSven Eckelmann 2142d0b044SSven Eckelmann #define BATADV_TQ_MAX_VALUE 255 220da00359SAntonio Quartulli #define BATADV_THROUGHPUT_MAX_VALUE 0xFFFFFFFF 2342d0b044SSven Eckelmann #define BATADV_JITTER 20 24c6c8fea2SSven Eckelmann 256e215fd8SSven Eckelmann /* Time To Live of broadcast messages */ 2642d0b044SSven Eckelmann #define BATADV_TTL 50 276e215fd8SSven Eckelmann 2881f02683SSimon Wunderlich /* maximum sequence number age of broadcast messages */ 2981f02683SSimon Wunderlich #define BATADV_BCAST_MAX_AGE 64 3081f02683SSimon Wunderlich 316e215fd8SSven Eckelmann /* purge originators after time in seconds if no valid packet comes in 3242d0b044SSven Eckelmann * -> TODO: check influence on BATADV_TQ_LOCAL_WINDOW_SIZE 339cfc7bd6SSven Eckelmann */ 3442d0b044SSven Eckelmann #define BATADV_PURGE_TIMEOUT 200000 /* 200 seconds */ 357cf4d520SAntonio Quartulli #define BATADV_TT_LOCAL_TIMEOUT 600000 /* in milliseconds */ 36a51fb9b2SAntonio Quartulli #define BATADV_TT_CLIENT_ROAM_TIMEOUT 600000 /* in milliseconds */ 3730cfd02bSAntonio Quartulli #define BATADV_TT_CLIENT_TEMP_TIMEOUT 600000 /* in milliseconds */ 3872414442SAntonio Quartulli #define BATADV_TT_WORK_PERIOD 5000 /* 5 seconds */ 3972414442SAntonio Quartulli #define BATADV_ORIG_WORK_PERIOD 1000 /* 1 second */ 40cbebd363SLinus Lüssing #define BATADV_MCAST_WORK_PERIOD 500 /* 0.5 seconds */ 412f1dfbe1SAntonio Quartulli #define BATADV_DAT_ENTRY_TIMEOUT (5 * 60000) /* 5 mins in milliseconds */ 42015758d0SAntonio Quartulli /* sliding packet range of received originator messages in sequence numbers 439cfc7bd6SSven Eckelmann * (should be a multiple of our word size) 449cfc7bd6SSven Eckelmann */ 4542d0b044SSven Eckelmann #define BATADV_TQ_LOCAL_WINDOW_SIZE 64 46a51fb9b2SAntonio Quartulli /* milliseconds we have to keep pending tt_req */ 4742d0b044SSven Eckelmann #define BATADV_TT_REQUEST_TIMEOUT 3000 48a73105b8SAntonio Quartulli 4942d0b044SSven Eckelmann #define BATADV_TQ_GLOBAL_WINDOW_SIZE 5 5042d0b044SSven Eckelmann #define BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM 1 5142d0b044SSven Eckelmann #define BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM 1 5242d0b044SSven Eckelmann #define BATADV_TQ_TOTAL_BIDRECT_LIMIT 1 53c6c8fea2SSven Eckelmann 54162bd64cSLinus Luessing /* B.A.T.M.A.N. V */ 55c833484eSAntonio Quartulli #define BATADV_THROUGHPUT_DEFAULT_VALUE 10 /* 1 Mbps */ 568d2d499eSAntonio Quartulli #define BATADV_ELP_PROBES_PER_NODE 2 578d2d499eSAntonio Quartulli #define BATADV_ELP_MIN_PROBE_SIZE 200 /* bytes */ 588d2d499eSAntonio Quartulli #define BATADV_ELP_PROBE_MAX_TX_DIFF 100 /* milliseconds */ 59162bd64cSLinus Luessing #define BATADV_ELP_MAX_AGE 64 609323158eSAntonio Quartulli #define BATADV_OGM_MAX_ORIGDIFF 5 619323158eSAntonio Quartulli #define BATADV_OGM_MAX_AGE 64 62162bd64cSLinus Luessing 6342d0b044SSven Eckelmann /* number of OGMs sent with the last tt diff */ 6442d0b044SSven Eckelmann #define BATADV_TT_OGM_APPEND_MAX 3 65a73105b8SAntonio Quartulli 669cfc7bd6SSven Eckelmann /* Time in which a client can roam at most ROAMING_MAX_COUNT times in 67a51fb9b2SAntonio Quartulli * milliseconds 689cfc7bd6SSven Eckelmann */ 6942d0b044SSven Eckelmann #define BATADV_ROAMING_MAX_TIME 20000 7042d0b044SSven Eckelmann #define BATADV_ROAMING_MAX_COUNT 5 71cc47f66eSAntonio Quartulli 7242d0b044SSven Eckelmann #define BATADV_NO_FLAGS 0 73ecbd5321SMarek Lindner 7442d0b044SSven Eckelmann #define BATADV_NULL_IFINDEX 0 /* dummy ifindex used to avoid iface checks */ 75bc279080SAntonio Quartulli 769464d071SAntonio Quartulli #define BATADV_NO_MARK 0 779464d071SAntonio Quartulli 7889652331SSimon Wunderlich /* default interface for multi interface operation. The default interface is 7989652331SSimon Wunderlich * used for communication which originated locally (i.e. is not forwarded) 8089652331SSimon Wunderlich * or where special forwarding is not desired/necessary. 8189652331SSimon Wunderlich */ 8289652331SSimon Wunderlich #define BATADV_IF_DEFAULT ((struct batadv_hard_iface *)NULL) 8389652331SSimon Wunderlich 8442d0b044SSven Eckelmann #define BATADV_NUM_WORDS BITS_TO_LONGS(BATADV_TQ_LOCAL_WINDOW_SIZE) 85c6c8fea2SSven Eckelmann 8642d0b044SSven Eckelmann #define BATADV_LOG_BUF_LEN 8192 /* has to be a power of 2 */ 87c6c8fea2SSven Eckelmann 88caf65bfcSMatthias Schiffer /* number of packets to send for broadcasts on different interface types */ 89caf65bfcSMatthias Schiffer #define BATADV_NUM_BCASTS_DEFAULT 1 90caf65bfcSMatthias Schiffer #define BATADV_NUM_BCASTS_WIRELESS 3 91caf65bfcSMatthias Schiffer #define BATADV_NUM_BCASTS_MAX 3 92caf65bfcSMatthias Schiffer 9333a3bb4aSAntonio Quartulli /* length of the single packet used by the TP meter */ 9433a3bb4aSAntonio Quartulli #define BATADV_TP_PACKET_LEN ETH_DATA_LEN 9533a3bb4aSAntonio Quartulli 96c384ea3eSAntonio Quartulli /* msecs after which an ARP_REQUEST is sent in broadcast as fallback */ 97c384ea3eSAntonio Quartulli #define ARP_REQ_DELAY 250 98785ea114SAntonio Quartulli /* numbers of originator to contact for any PUT/GET DHT operation */ 99785ea114SAntonio Quartulli #define BATADV_DAT_CANDIDATES_NUM 3 100785ea114SAntonio Quartulli 101a0e28775SMartin Hundebøll /* BATADV_TQ_SIMILARITY_THRESHOLD - TQ points that a secondary metric can differ 102c43c981eSAntonio Quartulli * at most from the primary one in order to be still considered acceptable 103c43c981eSAntonio Quartulli */ 104c43c981eSAntonio Quartulli #define BATADV_TQ_SIMILARITY_THRESHOLD 50 105c43c981eSAntonio Quartulli 1066e215fd8SSven Eckelmann /* should not be bigger than 512 bytes or change the size of 1079cfc7bd6SSven Eckelmann * forw_packet->direct_link_flags 1089cfc7bd6SSven Eckelmann */ 10942d0b044SSven Eckelmann #define BATADV_MAX_AGGREGATION_BYTES 512 11042d0b044SSven Eckelmann #define BATADV_MAX_AGGREGATION_MS 100 111c6c8fea2SSven Eckelmann 11242d0b044SSven Eckelmann #define BATADV_BLA_PERIOD_LENGTH 10000 /* 10 seconds */ 113e1544f3cSSimon Wunderlich #define BATADV_BLA_BACKBONE_TIMEOUT (BATADV_BLA_PERIOD_LENGTH * 6) 11442d0b044SSven Eckelmann #define BATADV_BLA_CLAIM_TIMEOUT (BATADV_BLA_PERIOD_LENGTH * 10) 11528709878SSimon Wunderlich #define BATADV_BLA_WAIT_PERIODS 3 116cd9c7bfbSSimon Wunderlich #define BATADV_BLA_LOOPDETECT_PERIODS 6 117cd9c7bfbSSimon Wunderlich #define BATADV_BLA_LOOPDETECT_TIMEOUT 3000 /* 3 seconds */ 118fe2da6ffSSimon Wunderlich 11942d0b044SSven Eckelmann #define BATADV_DUPLIST_SIZE 16 12042d0b044SSven Eckelmann #define BATADV_DUPLIST_TIMEOUT 500 /* 500 ms */ 1216e215fd8SSven Eckelmann /* don't reset again within 30 seconds */ 12242d0b044SSven Eckelmann #define BATADV_RESET_PROTECTION_MS 30000 12342d0b044SSven Eckelmann #define BATADV_EXPECTED_SEQNO_RANGE 65536 124c6c8fea2SSven Eckelmann 125d56b1705SMartin Hundebøll #define BATADV_NC_NODE_TIMEOUT 10000 /* Milliseconds */ 126d56b1705SMartin Hundebøll 12733a3bb4aSAntonio Quartulli /** 12833a3bb4aSAntonio Quartulli * BATADV_TP_MAX_NUM - maximum number of simultaneously active tp sessions 12933a3bb4aSAntonio Quartulli */ 13033a3bb4aSAntonio Quartulli #define BATADV_TP_MAX_NUM 5 13133a3bb4aSAntonio Quartulli 13273844a8cSSven Eckelmann /** 13373844a8cSSven Eckelmann * enum batadv_mesh_state - State of a soft interface 13473844a8cSSven Eckelmann */ 13539c75a51SSven Eckelmann enum batadv_mesh_state { 13673844a8cSSven Eckelmann /** @BATADV_MESH_INACTIVE: soft interface is not yet running */ 13739c75a51SSven Eckelmann BATADV_MESH_INACTIVE, 13873844a8cSSven Eckelmann 13973844a8cSSven Eckelmann /** @BATADV_MESH_ACTIVE: interface is up and running */ 14039c75a51SSven Eckelmann BATADV_MESH_ACTIVE, 14173844a8cSSven Eckelmann 14273844a8cSSven Eckelmann /** @BATADV_MESH_DEACTIVATING: interface is getting shut down */ 14339c75a51SSven Eckelmann BATADV_MESH_DEACTIVATING, 144e8958dbfSSven Eckelmann }; 145c6c8fea2SSven Eckelmann 14642d0b044SSven Eckelmann #define BATADV_BCAST_QUEUE_LEN 256 14742d0b044SSven Eckelmann #define BATADV_BATMAN_QUEUE_LEN 256 148c6c8fea2SSven Eckelmann 14973844a8cSSven Eckelmann /** 15073844a8cSSven Eckelmann * enum batadv_uev_action - action type of uevent 15173844a8cSSven Eckelmann */ 15239c75a51SSven Eckelmann enum batadv_uev_action { 15373844a8cSSven Eckelmann /** @BATADV_UEV_ADD: gateway was selected (after none was selected) */ 15439c75a51SSven Eckelmann BATADV_UEV_ADD = 0, 15573844a8cSSven Eckelmann 15673844a8cSSven Eckelmann /** 15773844a8cSSven Eckelmann * @BATADV_UEV_DEL: selected gateway was removed and none is selected 15873844a8cSSven Eckelmann * anymore 15973844a8cSSven Eckelmann */ 16039c75a51SSven Eckelmann BATADV_UEV_DEL, 16173844a8cSSven Eckelmann 16273844a8cSSven Eckelmann /** 16373844a8cSSven Eckelmann * @BATADV_UEV_CHANGE: a different gateway was selected as based gateway 16473844a8cSSven Eckelmann */ 16539c75a51SSven Eckelmann BATADV_UEV_CHANGE, 16673844a8cSSven Eckelmann 16773844a8cSSven Eckelmann /** 16873844a8cSSven Eckelmann * @BATADV_UEV_LOOPDETECT: loop was detected which cannot be handled by 16973844a8cSSven Eckelmann * bridge loop avoidance 17073844a8cSSven Eckelmann */ 171cd9c7bfbSSimon Wunderlich BATADV_UEV_LOOPDETECT, 172c6bda689SAntonio Quartulli }; 173c6bda689SAntonio Quartulli 17473844a8cSSven Eckelmann /** 17573844a8cSSven Eckelmann * enum batadv_uev_type - Type of uevent 17673844a8cSSven Eckelmann */ 17739c75a51SSven Eckelmann enum batadv_uev_type { 17873844a8cSSven Eckelmann /** @BATADV_UEV_GW: selected gateway was modified */ 17939c75a51SSven Eckelmann BATADV_UEV_GW = 0, 18073844a8cSSven Eckelmann 18173844a8cSSven Eckelmann /** @BATADV_UEV_BLA: bridge loop avoidance event */ 182cd9c7bfbSSimon Wunderlich BATADV_UEV_BLA, 183c6bda689SAntonio Quartulli }; 184c6bda689SAntonio Quartulli 18542d0b044SSven Eckelmann #define BATADV_GW_THRESHOLD 50 18643676ab5SAntonio Quartulli 187610bfc6bSMartin Hundebøll /* Number of fragment chains for each orig_node */ 188610bfc6bSMartin Hundebøll #define BATADV_FRAG_BUFFER_COUNT 8 189610bfc6bSMartin Hundebøll /* Maximum number of fragments for one packet */ 190610bfc6bSMartin Hundebøll #define BATADV_FRAG_MAX_FRAGMENTS 16 191610bfc6bSMartin Hundebøll /* Maxumim size of each fragment */ 1928ea026b1SMatthias Schiffer #define BATADV_FRAG_MAX_FRAG_SIZE 1280 193610bfc6bSMartin Hundebøll /* Time to keep fragments while waiting for rest of the fragments */ 194610bfc6bSMartin Hundebøll #define BATADV_FRAG_TIMEOUT 10000 195610bfc6bSMartin Hundebøll 196785ea114SAntonio Quartulli #define BATADV_DAT_CANDIDATE_NOT_FOUND 0 197785ea114SAntonio Quartulli #define BATADV_DAT_CANDIDATE_ORIG 1 198785ea114SAntonio Quartulli 19921a1236bSSven Eckelmann /* Debug Messages */ 200c6c8fea2SSven Eckelmann #ifdef pr_fmt 201c6c8fea2SSven Eckelmann #undef pr_fmt 202c6c8fea2SSven Eckelmann #endif 2036e215fd8SSven Eckelmann /* Append 'batman-adv: ' before kernel messages */ 2046e215fd8SSven Eckelmann #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 205c6c8fea2SSven Eckelmann 20621a1236bSSven Eckelmann /* Kernel headers */ 207c6c8fea2SSven Eckelmann 20847d4522dSSven Eckelmann #include <linux/atomic.h> 2091e2c2a4fSSven Eckelmann #include <linux/compiler.h> 2101e2c2a4fSSven Eckelmann #include <linux/etherdevice.h> 211fcafa5e7SSven Eckelmann #include <linux/if_vlan.h> 212fcafa5e7SSven Eckelmann #include <linux/jiffies.h> 213*68a600deSSven Eckelmann #include <linux/netdevice.h> 214fcafa5e7SSven Eckelmann #include <linux/percpu.h> 215*68a600deSSven Eckelmann #include <linux/seq_file.h> 216*68a600deSSven Eckelmann #include <linux/skbuff.h> 2171e2c2a4fSSven Eckelmann #include <linux/types.h> 218fec149f5SSven Eckelmann #include <uapi/linux/batadv_packet.h> 21916052789SAntonio Quartulli 220c6c8fea2SSven Eckelmann #include "types.h" 221*68a600deSSven Eckelmann #include "main.h" 2221e2c2a4fSSven Eckelmann 223f7a2bd65SSven Eckelmann /** 2247e9a8c2cSSven Eckelmann * batadv_print_vid() - return printable version of vid information 225f7a2bd65SSven Eckelmann * @vid: the VLAN identifier 226f7a2bd65SSven Eckelmann * 227f7a2bd65SSven Eckelmann * Return: -1 when no VLAN is used, VLAN id otherwise 228f7a2bd65SSven Eckelmann */ 229f7a2bd65SSven Eckelmann static inline int batadv_print_vid(unsigned short vid) 230f7a2bd65SSven Eckelmann { 231f7a2bd65SSven Eckelmann if (vid & BATADV_VLAN_HAS_TAG) 232f7a2bd65SSven Eckelmann return (int)(vid & VLAN_VID_MASK); 233f7a2bd65SSven Eckelmann else 234f7a2bd65SSven Eckelmann return -1; 235f7a2bd65SSven Eckelmann } 236eb2deb6bSAntonio Quartulli 2373193e8fdSSven Eckelmann extern struct list_head batadv_hardif_list; 238fb69be69SSven Eckelmann extern unsigned int batadv_hardif_generation; 239c6c8fea2SSven Eckelmann 2403193e8fdSSven Eckelmann extern unsigned char batadv_broadcast_addr[]; 2413193e8fdSSven Eckelmann extern struct workqueue_struct *batadv_event_workqueue; 242c6c8fea2SSven Eckelmann 2433193e8fdSSven Eckelmann int batadv_mesh_init(struct net_device *soft_iface); 2443193e8fdSSven Eckelmann void batadv_mesh_free(struct net_device *soft_iface); 2456b5e971aSSven Eckelmann bool batadv_is_my_mac(struct batadv_priv *bat_priv, const u8 *addr); 24630da63a6SMarek Lindner struct batadv_hard_iface * 24730da63a6SMarek Lindner batadv_seq_print_text_primary_if_get(struct seq_file *seq); 248411d6ed9SMarek Lindner int batadv_max_header_len(void); 249c54f38c9SSimon Wunderlich void batadv_skb_set_priority(struct sk_buff *skb, int offset); 2503193e8fdSSven Eckelmann int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev, 2513193e8fdSSven Eckelmann struct packet_type *ptype, 2523193e8fdSSven Eckelmann struct net_device *orig_dev); 25356303d34SSven Eckelmann int 2546b5e971aSSven Eckelmann batadv_recv_handler_register(u8 packet_type, 255ffa995e0SMarek Lindner int (*recv_handler)(struct sk_buff *, 25656303d34SSven Eckelmann struct batadv_hard_iface *)); 2576b5e971aSSven Eckelmann void batadv_recv_handler_unregister(u8 packet_type); 25895a066d8SSven Eckelmann __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr); 259c6c8fea2SSven Eckelmann 2600aca86cdSAntonio Quartulli /** 2617e9a8c2cSSven Eckelmann * batadv_compare_eth() - Compare two not u16 aligned Ethernet addresses 2627afcbbefSSven Eckelmann * @data1: Pointer to a six-byte array containing the Ethernet address 2637afcbbefSSven Eckelmann * @data2: Pointer other six-byte array containing the Ethernet address 26439901e71SMarek Lindner * 265c3923b7aSJoe Perches * note: can't use ether_addr_equal() as it requires aligned memory 26662fe710fSSven Eckelmann * 2674b426b10SSven Eckelmann * Return: true if they are the same ethernet addr 26839901e71SMarek Lindner */ 269f2d5cf2aSMarkus Pargmann static inline bool batadv_compare_eth(const void *data1, const void *data2) 27039901e71SMarek Lindner { 271d9cd4fe5SJoe Perches return ether_addr_equal_unaligned(data1, data2); 27239901e71SMarek Lindner } 27339901e71SMarek Lindner 2742c53040fSBen Hutchings /** 2757e9a8c2cSSven Eckelmann * batadv_has_timed_out() - compares current time (jiffies) and timestamp + 2766d030de8SAntonio Quartulli * timeout 277a04ccd59SMartin Hundebøll * @timestamp: base value to compare with (in jiffies) 278a04ccd59SMartin Hundebøll * @timeout: added to base value before comparing (in milliseconds) 279a04ccd59SMartin Hundebøll * 28062fe710fSSven Eckelmann * Return: true if current time is after timestamp + timeout 281a04ccd59SMartin Hundebøll */ 2821eda58bfSSven Eckelmann static inline bool batadv_has_timed_out(unsigned long timestamp, 2831eda58bfSSven Eckelmann unsigned int timeout) 284a04ccd59SMartin Hundebøll { 285a04ccd59SMartin Hundebøll return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout)); 286a04ccd59SMartin Hundebøll } 287747e4221SSven Eckelmann 288e57acf8eSSven Eckelmann /** 289e57acf8eSSven Eckelmann * batadv_atomic_dec_not_zero() - Decrease unless the number is 0 290e57acf8eSSven Eckelmann * @v: pointer of type atomic_t 291e57acf8eSSven Eckelmann * 292e57acf8eSSven Eckelmann * Return: non-zero if v was not 0, and zero otherwise. 293e57acf8eSSven Eckelmann */ 2943e34819eSSven Eckelmann #define batadv_atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) 2955f657ec0SAntonio Quartulli 296e57acf8eSSven Eckelmann /** 297e57acf8eSSven Eckelmann * batadv_smallest_signed_int() - Returns the smallest signed integer in two's 298e57acf8eSSven Eckelmann * complement with the sizeof x 299e57acf8eSSven Eckelmann * @x: type of integer 300e57acf8eSSven Eckelmann * 301e57acf8eSSven Eckelmann * Return: smallest signed integer of type 302e57acf8eSSven Eckelmann */ 3033e34819eSSven Eckelmann #define batadv_smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u))) 304f5d33d37SAntonio Quartulli 305e57acf8eSSven Eckelmann /** 306e57acf8eSSven Eckelmann * batadv_seq_before() - Checks if a sequence number x is a predecessor of y 307e57acf8eSSven Eckelmann * @x: potential predecessor of @y 308e57acf8eSSven Eckelmann * @y: value to compare @x against 309e57acf8eSSven Eckelmann * 310e57acf8eSSven Eckelmann * It handles overflows/underflows and can correctly check for a predecessor 311e57acf8eSSven Eckelmann * unless the variable sequence number has grown by more then 312e57acf8eSSven Eckelmann * 2**(bitwidth(x)-1)-1. 313e57acf8eSSven Eckelmann * 3146b5e971aSSven Eckelmann * This means that for a u8 with the maximum value 255, it would think: 315e57acf8eSSven Eckelmann * 316e57acf8eSSven Eckelmann * * when adding nothing - it is neither a predecessor nor a successor 317e57acf8eSSven Eckelmann * * before adding more than 127 to the starting value - it is a predecessor, 318e57acf8eSSven Eckelmann * * when adding 128 - it is neither a predecessor nor a successor, 319e57acf8eSSven Eckelmann * * after adding more than 127 to the starting value - it is a successor 320e57acf8eSSven Eckelmann * 321e57acf8eSSven Eckelmann * Return: true when x is a predecessor of y, false otherwise 3229cfc7bd6SSven Eckelmann */ 32384d0a394SSven Eckelmann #define batadv_seq_before(x, y) ({ \ 32484d0a394SSven Eckelmann typeof(x)_d1 = (x); \ 3250bb85751SSven Eckelmann typeof(y)_d2 = (y); \ 3260bb85751SSven Eckelmann typeof(x)_dummy = (_d1 - _d2); \ 3270bb85751SSven Eckelmann (void)(&_d1 == &_d2); \ 32884d0a394SSven Eckelmann _dummy > batadv_smallest_signed_int(_dummy); \ 32984d0a394SSven Eckelmann }) 330e57acf8eSSven Eckelmann 331e57acf8eSSven Eckelmann /** 332e57acf8eSSven Eckelmann * batadv_seq_after() - Checks if a sequence number x is a successor of y 333e57acf8eSSven Eckelmann * @x: potential sucessor of @y 334e57acf8eSSven Eckelmann * @y: value to compare @x against 335e57acf8eSSven Eckelmann * 336e57acf8eSSven Eckelmann * It handles overflows/underflows and can correctly check for a successor 337e57acf8eSSven Eckelmann * unless the variable sequence number has grown by more then 338e57acf8eSSven Eckelmann * 2**(bitwidth(x)-1)-1. 339e57acf8eSSven Eckelmann * 340e57acf8eSSven Eckelmann * This means that for a u8 with the maximum value 255, it would think: 341e57acf8eSSven Eckelmann * 342e57acf8eSSven Eckelmann * * when adding nothing - it is neither a predecessor nor a successor 343e57acf8eSSven Eckelmann * * before adding more than 127 to the starting value - it is a predecessor, 344e57acf8eSSven Eckelmann * * when adding 128 - it is neither a predecessor nor a successor, 345e57acf8eSSven Eckelmann * * after adding more than 127 to the starting value - it is a successor 346e57acf8eSSven Eckelmann * 347e57acf8eSSven Eckelmann * Return: true when x is a successor of y, false otherwise 348e57acf8eSSven Eckelmann */ 3493e34819eSSven Eckelmann #define batadv_seq_after(x, y) batadv_seq_before(y, x) 350f5d33d37SAntonio Quartulli 351e57acf8eSSven Eckelmann /** 352e57acf8eSSven Eckelmann * batadv_add_counter() - Add to per cpu statistics counter of soft interface 353e57acf8eSSven Eckelmann * @bat_priv: the bat priv with all the soft interface information 354e57acf8eSSven Eckelmann * @idx: counter index which should be modified 355e57acf8eSSven Eckelmann * @count: value to increase counter by 356e57acf8eSSven Eckelmann * 357e57acf8eSSven Eckelmann * Stop preemption on local cpu while incrementing the counter 358e57acf8eSSven Eckelmann */ 35956303d34SSven Eckelmann static inline void batadv_add_counter(struct batadv_priv *bat_priv, size_t idx, 360f8214865SMartin Hundebøll size_t count) 361f8214865SMartin Hundebøll { 36256917443SShan Wei this_cpu_add(bat_priv->bat_counters[idx], count); 363f8214865SMartin Hundebøll } 364f8214865SMartin Hundebøll 365e57acf8eSSven Eckelmann /** 366e57acf8eSSven Eckelmann * batadv_inc_counter() - Increase per cpu statistics counter of soft interface 367e57acf8eSSven Eckelmann * @b: the bat priv with all the soft interface information 368e57acf8eSSven Eckelmann * @i: counter index which should be modified 369e57acf8eSSven Eckelmann */ 370f8214865SMartin Hundebøll #define batadv_inc_counter(b, i) batadv_add_counter(b, i, 1) 371f8214865SMartin Hundebøll 372e57acf8eSSven Eckelmann /** 373e57acf8eSSven Eckelmann * BATADV_SKB_CB() - Get batadv_skb_cb from skb control buffer 374e57acf8eSSven Eckelmann * @__skb: skb holding the control buffer 375e57acf8eSSven Eckelmann * 376e57acf8eSSven Eckelmann * The members of the control buffer are defined in struct batadv_skb_cb in 377e57acf8eSSven Eckelmann * types.h. The macro is inspired by the similar macro TCP_SKB_CB() in tcp.h. 378e57acf8eSSven Eckelmann * 379e57acf8eSSven Eckelmann * Return: pointer to the batadv_skb_cb of the skb 3803c12de9aSMartin Hundebøll */ 3813c12de9aSMartin Hundebøll #define BATADV_SKB_CB(__skb) ((struct batadv_skb_cb *)&((__skb)->cb[0])) 3823c12de9aSMartin Hundebøll 383c018ad3dSAntonio Quartulli unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len); 384eceb22aeSAntonio Quartulli bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsigned short vid); 3850fa4c30dSSven Eckelmann int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type, 3860fa4c30dSSven Eckelmann enum batadv_uev_action action, const char *data); 387ef261577SMarek Lindner 388c6c8fea2SSven Eckelmann #endif /* _NET_BATMAN_ADV_MAIN_H_ */ 389