xref: /linux/net/batman-adv/main.h (revision c018ad3de61a1dc4194879a53e5559e094aa7b1a)
10b873931SAntonio Quartulli /* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
2c6c8fea2SSven Eckelmann  *
3c6c8fea2SSven Eckelmann  * Marek Lindner, Simon Wunderlich
4c6c8fea2SSven Eckelmann  *
5c6c8fea2SSven Eckelmann  * This program is free software; you can redistribute it and/or
6c6c8fea2SSven Eckelmann  * modify it under the terms of version 2 of the GNU General Public
7c6c8fea2SSven Eckelmann  * License as published by the Free Software Foundation.
8c6c8fea2SSven Eckelmann  *
9c6c8fea2SSven Eckelmann  * This program is distributed in the hope that it will be useful, but
10c6c8fea2SSven Eckelmann  * WITHOUT ANY WARRANTY; without even the implied warranty of
11c6c8fea2SSven Eckelmann  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12c6c8fea2SSven Eckelmann  * General Public License for more details.
13c6c8fea2SSven Eckelmann  *
14c6c8fea2SSven Eckelmann  * You should have received a copy of the GNU General Public License
15c6c8fea2SSven Eckelmann  * along with this program; if not, write to the Free Software
16c6c8fea2SSven Eckelmann  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17c6c8fea2SSven Eckelmann  * 02110-1301, USA
18c6c8fea2SSven Eckelmann  */
19c6c8fea2SSven Eckelmann 
20c6c8fea2SSven Eckelmann #ifndef _NET_BATMAN_ADV_MAIN_H_
21c6c8fea2SSven Eckelmann #define _NET_BATMAN_ADV_MAIN_H_
22c6c8fea2SSven Eckelmann 
23bc58eeefSMarek Lindner #define BATADV_DRIVER_AUTHOR "Marek Lindner <mareklindner@neomailbox.ch>, " \
24c679ff8fSSimon Wunderlich 			     "Simon Wunderlich <sw@simonwunderlich.de>"
2542d0b044SSven Eckelmann #define BATADV_DRIVER_DESC   "B.A.T.M.A.N. advanced"
2642d0b044SSven Eckelmann #define BATADV_DRIVER_DEVICE "batman-adv"
27c6c8fea2SSven Eckelmann 
2842d0b044SSven Eckelmann #ifndef BATADV_SOURCE_VERSION
29c00a072dSSimon Wunderlich #define BATADV_SOURCE_VERSION "2013.4.0"
3044c4349aSSven Eckelmann #endif
31c6c8fea2SSven Eckelmann 
32c6c8fea2SSven Eckelmann /* B.A.T.M.A.N. parameters */
33c6c8fea2SSven Eckelmann 
3442d0b044SSven Eckelmann #define BATADV_TQ_MAX_VALUE 255
3542d0b044SSven Eckelmann #define BATADV_JITTER 20
36c6c8fea2SSven Eckelmann 
376e215fd8SSven Eckelmann /* Time To Live of broadcast messages */
3842d0b044SSven Eckelmann #define BATADV_TTL 50
396e215fd8SSven Eckelmann 
406e215fd8SSven Eckelmann /* purge originators after time in seconds if no valid packet comes in
4142d0b044SSven Eckelmann  * -> TODO: check influence on BATADV_TQ_LOCAL_WINDOW_SIZE
429cfc7bd6SSven Eckelmann  */
4342d0b044SSven Eckelmann #define BATADV_PURGE_TIMEOUT 200000 /* 200 seconds */
447cf4d520SAntonio Quartulli #define BATADV_TT_LOCAL_TIMEOUT 600000 /* in milliseconds */
45a51fb9b2SAntonio Quartulli #define BATADV_TT_CLIENT_ROAM_TIMEOUT 600000 /* in milliseconds */
4630cfd02bSAntonio Quartulli #define BATADV_TT_CLIENT_TEMP_TIMEOUT 600000 /* in milliseconds */
4772414442SAntonio Quartulli #define BATADV_TT_WORK_PERIOD 5000 /* 5 seconds */
4872414442SAntonio Quartulli #define BATADV_ORIG_WORK_PERIOD 1000 /* 1 second */
492f1dfbe1SAntonio Quartulli #define BATADV_DAT_ENTRY_TIMEOUT (5*60000) /* 5 mins in milliseconds */
50015758d0SAntonio Quartulli /* sliding packet range of received originator messages in sequence numbers
519cfc7bd6SSven Eckelmann  * (should be a multiple of our word size)
529cfc7bd6SSven Eckelmann  */
5342d0b044SSven Eckelmann #define BATADV_TQ_LOCAL_WINDOW_SIZE 64
54a51fb9b2SAntonio Quartulli /* milliseconds we have to keep pending tt_req */
5542d0b044SSven Eckelmann #define BATADV_TT_REQUEST_TIMEOUT 3000
56a73105b8SAntonio Quartulli 
5742d0b044SSven Eckelmann #define BATADV_TQ_GLOBAL_WINDOW_SIZE 5
5842d0b044SSven Eckelmann #define BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM 1
5942d0b044SSven Eckelmann #define BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
6042d0b044SSven Eckelmann #define BATADV_TQ_TOTAL_BIDRECT_LIMIT 1
61c6c8fea2SSven Eckelmann 
6242d0b044SSven Eckelmann /* number of OGMs sent with the last tt diff */
6342d0b044SSven Eckelmann #define BATADV_TT_OGM_APPEND_MAX 3
64a73105b8SAntonio Quartulli 
659cfc7bd6SSven Eckelmann /* Time in which a client can roam at most ROAMING_MAX_COUNT times in
66a51fb9b2SAntonio Quartulli  * milliseconds
679cfc7bd6SSven Eckelmann  */
6842d0b044SSven Eckelmann #define BATADV_ROAMING_MAX_TIME 20000
6942d0b044SSven Eckelmann #define BATADV_ROAMING_MAX_COUNT 5
70cc47f66eSAntonio Quartulli 
7142d0b044SSven Eckelmann #define BATADV_NO_FLAGS 0
72ecbd5321SMarek Lindner 
7342d0b044SSven Eckelmann #define BATADV_NULL_IFINDEX 0 /* dummy ifindex used to avoid iface checks */
74bc279080SAntonio Quartulli 
7542d0b044SSven Eckelmann #define BATADV_NUM_WORDS BITS_TO_LONGS(BATADV_TQ_LOCAL_WINDOW_SIZE)
76c6c8fea2SSven Eckelmann 
7742d0b044SSven Eckelmann #define BATADV_LOG_BUF_LEN 8192	  /* has to be a power of 2 */
78c6c8fea2SSven Eckelmann 
79caf65bfcSMatthias Schiffer /* number of packets to send for broadcasts on different interface types */
80caf65bfcSMatthias Schiffer #define BATADV_NUM_BCASTS_DEFAULT 1
81caf65bfcSMatthias Schiffer #define BATADV_NUM_BCASTS_WIRELESS 3
82caf65bfcSMatthias Schiffer #define BATADV_NUM_BCASTS_MAX 3
83caf65bfcSMatthias Schiffer 
84c384ea3eSAntonio Quartulli /* msecs after which an ARP_REQUEST is sent in broadcast as fallback */
85c384ea3eSAntonio Quartulli #define ARP_REQ_DELAY 250
86785ea114SAntonio Quartulli /* numbers of originator to contact for any PUT/GET DHT operation */
87785ea114SAntonio Quartulli #define BATADV_DAT_CANDIDATES_NUM 3
88785ea114SAntonio Quartulli 
896e215fd8SSven Eckelmann /* how much worse secondary interfaces may be to be considered as bonding
909cfc7bd6SSven Eckelmann  * candidates
919cfc7bd6SSven Eckelmann  */
9242d0b044SSven Eckelmann #define BATADV_BONDING_TQ_THRESHOLD	50
93c6c8fea2SSven Eckelmann 
946e215fd8SSven Eckelmann /* should not be bigger than 512 bytes or change the size of
959cfc7bd6SSven Eckelmann  * forw_packet->direct_link_flags
969cfc7bd6SSven Eckelmann  */
9742d0b044SSven Eckelmann #define BATADV_MAX_AGGREGATION_BYTES 512
9842d0b044SSven Eckelmann #define BATADV_MAX_AGGREGATION_MS 100
99c6c8fea2SSven Eckelmann 
10042d0b044SSven Eckelmann #define BATADV_BLA_PERIOD_LENGTH	10000	/* 10 seconds */
10142d0b044SSven Eckelmann #define BATADV_BLA_BACKBONE_TIMEOUT	(BATADV_BLA_PERIOD_LENGTH * 3)
10242d0b044SSven Eckelmann #define BATADV_BLA_CLAIM_TIMEOUT	(BATADV_BLA_PERIOD_LENGTH * 10)
10328709878SSimon Wunderlich #define BATADV_BLA_WAIT_PERIODS		3
104fe2da6ffSSimon Wunderlich 
10542d0b044SSven Eckelmann #define BATADV_DUPLIST_SIZE		16
10642d0b044SSven Eckelmann #define BATADV_DUPLIST_TIMEOUT		500	/* 500 ms */
1076e215fd8SSven Eckelmann /* don't reset again within 30 seconds */
10842d0b044SSven Eckelmann #define BATADV_RESET_PROTECTION_MS 30000
10942d0b044SSven Eckelmann #define BATADV_EXPECTED_SEQNO_RANGE	65536
110c6c8fea2SSven Eckelmann 
111d56b1705SMartin Hundebøll #define BATADV_NC_NODE_TIMEOUT 10000 /* Milliseconds */
112d56b1705SMartin Hundebøll 
11339c75a51SSven Eckelmann enum batadv_mesh_state {
11439c75a51SSven Eckelmann 	BATADV_MESH_INACTIVE,
11539c75a51SSven Eckelmann 	BATADV_MESH_ACTIVE,
11639c75a51SSven Eckelmann 	BATADV_MESH_DEACTIVATING,
117e8958dbfSSven Eckelmann };
118c6c8fea2SSven Eckelmann 
11942d0b044SSven Eckelmann #define BATADV_BCAST_QUEUE_LEN		256
12042d0b044SSven Eckelmann #define BATADV_BATMAN_QUEUE_LEN	256
121c6c8fea2SSven Eckelmann 
12239c75a51SSven Eckelmann enum batadv_uev_action {
12339c75a51SSven Eckelmann 	BATADV_UEV_ADD = 0,
12439c75a51SSven Eckelmann 	BATADV_UEV_DEL,
12539c75a51SSven Eckelmann 	BATADV_UEV_CHANGE,
126c6bda689SAntonio Quartulli };
127c6bda689SAntonio Quartulli 
12839c75a51SSven Eckelmann enum batadv_uev_type {
12939c75a51SSven Eckelmann 	BATADV_UEV_GW = 0,
130c6bda689SAntonio Quartulli };
131c6bda689SAntonio Quartulli 
13242d0b044SSven Eckelmann #define BATADV_GW_THRESHOLD	50
13343676ab5SAntonio Quartulli 
134610bfc6bSMartin Hundebøll /* Number of fragment chains for each orig_node */
135610bfc6bSMartin Hundebøll #define BATADV_FRAG_BUFFER_COUNT 8
136610bfc6bSMartin Hundebøll /* Maximum number of fragments for one packet */
137610bfc6bSMartin Hundebøll #define BATADV_FRAG_MAX_FRAGMENTS 16
138610bfc6bSMartin Hundebøll /* Maxumim size of each fragment */
139610bfc6bSMartin Hundebøll #define BATADV_FRAG_MAX_FRAG_SIZE 1400
140610bfc6bSMartin Hundebøll /* Time to keep fragments while waiting for rest of the fragments */
141610bfc6bSMartin Hundebøll #define BATADV_FRAG_TIMEOUT 10000
142610bfc6bSMartin Hundebøll 
143785ea114SAntonio Quartulli #define BATADV_DAT_CANDIDATE_NOT_FOUND	0
144785ea114SAntonio Quartulli #define BATADV_DAT_CANDIDATE_ORIG	1
145785ea114SAntonio Quartulli 
14621a1236bSSven Eckelmann /* Debug Messages */
147c6c8fea2SSven Eckelmann #ifdef pr_fmt
148c6c8fea2SSven Eckelmann #undef pr_fmt
149c6c8fea2SSven Eckelmann #endif
1506e215fd8SSven Eckelmann /* Append 'batman-adv: ' before kernel messages */
1516e215fd8SSven Eckelmann #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
152c6c8fea2SSven Eckelmann 
15321a1236bSSven Eckelmann /* Kernel headers */
154c6c8fea2SSven Eckelmann 
155c6c8fea2SSven Eckelmann #include <linux/mutex.h>	/* mutex */
156c6c8fea2SSven Eckelmann #include <linux/module.h>	/* needed by all modules */
157c6c8fea2SSven Eckelmann #include <linux/netdevice.h>	/* netdevice */
158015758d0SAntonio Quartulli #include <linux/etherdevice.h>  /* ethernet address classification */
159c6c8fea2SSven Eckelmann #include <linux/if_ether.h>	/* ethernet header */
160c6c8fea2SSven Eckelmann #include <linux/poll.h>		/* poll_table */
161c6c8fea2SSven Eckelmann #include <linux/kthread.h>	/* kernel threads */
162c6c8fea2SSven Eckelmann #include <linux/pkt_sched.h>	/* schedule types */
163c6c8fea2SSven Eckelmann #include <linux/workqueue.h>	/* workqueue */
164f8214865SMartin Hundebøll #include <linux/percpu.h>
165c6c8fea2SSven Eckelmann #include <linux/slab.h>
166c6c8fea2SSven Eckelmann #include <net/sock.h>		/* struct sock */
167a4ac28c0SSven Eckelmann #include <net/rtnetlink.h>
168c6c8fea2SSven Eckelmann #include <linux/jiffies.h>
169c6c8fea2SSven Eckelmann #include <linux/seq_file.h>
170c6c8fea2SSven Eckelmann #include "types.h"
171c6c8fea2SSven Eckelmann 
172eb2deb6bSAntonio Quartulli #define BATADV_PRINT_VID(vid) (vid & BATADV_VLAN_HAS_TAG ? \
173eb2deb6bSAntonio Quartulli 			       (int)(vid & VLAN_VID_MASK) : -1)
174eb2deb6bSAntonio Quartulli 
1753193e8fdSSven Eckelmann extern char batadv_routing_algo[];
1763193e8fdSSven Eckelmann extern struct list_head batadv_hardif_list;
177c6c8fea2SSven Eckelmann 
1783193e8fdSSven Eckelmann extern unsigned char batadv_broadcast_addr[];
1793193e8fdSSven Eckelmann extern struct workqueue_struct *batadv_event_workqueue;
180c6c8fea2SSven Eckelmann 
1813193e8fdSSven Eckelmann int batadv_mesh_init(struct net_device *soft_iface);
1823193e8fdSSven Eckelmann void batadv_mesh_free(struct net_device *soft_iface);
183fe8a93b9SAntonio Quartulli int batadv_is_my_mac(struct batadv_priv *bat_priv, const uint8_t *addr);
18430da63a6SMarek Lindner struct batadv_hard_iface *
18530da63a6SMarek Lindner batadv_seq_print_text_primary_if_get(struct seq_file *seq);
186411d6ed9SMarek Lindner int batadv_max_header_len(void);
187c54f38c9SSimon Wunderlich void batadv_skb_set_priority(struct sk_buff *skb, int offset);
1883193e8fdSSven Eckelmann int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
1893193e8fdSSven Eckelmann 			   struct packet_type *ptype,
1903193e8fdSSven Eckelmann 			   struct net_device *orig_dev);
19156303d34SSven Eckelmann int
19256303d34SSven Eckelmann batadv_recv_handler_register(uint8_t packet_type,
193ffa995e0SMarek Lindner 			     int (*recv_handler)(struct sk_buff *,
19456303d34SSven Eckelmann 						 struct batadv_hard_iface *));
1953193e8fdSSven Eckelmann void batadv_recv_handler_unregister(uint8_t packet_type);
19656303d34SSven Eckelmann int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops);
19756303d34SSven Eckelmann int batadv_algo_select(struct batadv_priv *bat_priv, char *name);
1983193e8fdSSven Eckelmann int batadv_algo_seq_print_text(struct seq_file *seq, void *offset);
19995a066d8SSven Eckelmann __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr);
200c6c8fea2SSven Eckelmann 
2010aca86cdSAntonio Quartulli /**
2020aca86cdSAntonio Quartulli  * enum batadv_dbg_level - available log levels
2030aca86cdSAntonio Quartulli  * @BATADV_DBG_BATMAN: OGM and TQ computations related messages
2040aca86cdSAntonio Quartulli  * @BATADV_DBG_ROUTES: route added / changed / deleted
2050aca86cdSAntonio Quartulli  * @BATADV_DBG_TT: translation table messages
2060aca86cdSAntonio Quartulli  * @BATADV_DBG_BLA: bridge loop avoidance messages
2070e861a3cSAntonio Quartulli  * @BATADV_DBG_DAT: ARP snooping and DAT related messages
208d353d8d4SMartin Hundebøll  * @BATADV_DBG_NC: network coding related messages
2090aca86cdSAntonio Quartulli  * @BATADV_DBG_ALL: the union of all the above log levels
2100aca86cdSAntonio Quartulli  */
2118de47de5SSven Eckelmann enum batadv_dbg_level {
2128de47de5SSven Eckelmann 	BATADV_DBG_BATMAN = BIT(0),
2130aca86cdSAntonio Quartulli 	BATADV_DBG_ROUTES = BIT(1),
2140aca86cdSAntonio Quartulli 	BATADV_DBG_TT	  = BIT(2),
2150aca86cdSAntonio Quartulli 	BATADV_DBG_BLA    = BIT(3),
2160e861a3cSAntonio Quartulli 	BATADV_DBG_DAT    = BIT(4),
217d353d8d4SMartin Hundebøll 	BATADV_DBG_NC	  = BIT(5),
218d353d8d4SMartin Hundebøll 	BATADV_DBG_ALL    = 63,
2198de47de5SSven Eckelmann };
2208de47de5SSven Eckelmann 
221c6c8fea2SSven Eckelmann #ifdef CONFIG_BATMAN_ADV_DEBUG
22256303d34SSven Eckelmann int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
22340a072d7SSven Eckelmann __printf(2, 3);
224c6c8fea2SSven Eckelmann 
2251eda58bfSSven Eckelmann #define batadv_dbg(type, bat_priv, fmt, arg...)			\
226c6c8fea2SSven Eckelmann 	do {							\
227c6c8fea2SSven Eckelmann 		if (atomic_read(&bat_priv->log_level) & type)	\
22840a072d7SSven Eckelmann 			batadv_debug_log(bat_priv, fmt, ## arg);\
229c6c8fea2SSven Eckelmann 	}							\
230c6c8fea2SSven Eckelmann 	while (0)
231c6c8fea2SSven Eckelmann #else /* !CONFIG_BATMAN_ADV_DEBUG */
232d3a547beSSven Eckelmann __printf(3, 4)
2331eda58bfSSven Eckelmann static inline void batadv_dbg(int type __always_unused,
23456303d34SSven Eckelmann 			      struct batadv_priv *bat_priv __always_unused,
235747e4221SSven Eckelmann 			      const char *fmt __always_unused, ...)
236c6c8fea2SSven Eckelmann {
237c6c8fea2SSven Eckelmann }
238c6c8fea2SSven Eckelmann #endif
239c6c8fea2SSven Eckelmann 
2403e34819eSSven Eckelmann #define batadv_info(net_dev, fmt, arg...)				\
241c6c8fea2SSven Eckelmann 	do {								\
242c6c8fea2SSven Eckelmann 		struct net_device *_netdev = (net_dev);                 \
24356303d34SSven Eckelmann 		struct batadv_priv *_batpriv = netdev_priv(_netdev);    \
24439c75a51SSven Eckelmann 		batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg);	\
245c6c8fea2SSven Eckelmann 		pr_info("%s: " fmt, _netdev->name, ## arg);		\
246c6c8fea2SSven Eckelmann 	} while (0)
2473e34819eSSven Eckelmann #define batadv_err(net_dev, fmt, arg...)				\
248c6c8fea2SSven Eckelmann 	do {								\
249c6c8fea2SSven Eckelmann 		struct net_device *_netdev = (net_dev);                 \
25056303d34SSven Eckelmann 		struct batadv_priv *_batpriv = netdev_priv(_netdev);    \
25139c75a51SSven Eckelmann 		batadv_dbg(BATADV_DBG_ALL, _batpriv, fmt, ## arg);	\
252c6c8fea2SSven Eckelmann 		pr_err("%s: " fmt, _netdev->name, ## arg);		\
253c6c8fea2SSven Eckelmann 	} while (0)
254c6c8fea2SSven Eckelmann 
2559cfc7bd6SSven Eckelmann /* returns 1 if they are the same ethernet addr
25639901e71SMarek Lindner  *
257c3923b7aSJoe Perches  * note: can't use ether_addr_equal() as it requires aligned memory
25839901e71SMarek Lindner  */
2591eda58bfSSven Eckelmann static inline int batadv_compare_eth(const void *data1, const void *data2)
26039901e71SMarek Lindner {
26139901e71SMarek Lindner 	return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
26239901e71SMarek Lindner }
26339901e71SMarek Lindner 
2642c53040fSBen Hutchings /**
2652c53040fSBen Hutchings  * has_timed_out - compares current time (jiffies) and timestamp + timeout
266a04ccd59SMartin Hundebøll  * @timestamp:		base value to compare with (in jiffies)
267a04ccd59SMartin Hundebøll  * @timeout:		added to base value before comparing (in milliseconds)
268a04ccd59SMartin Hundebøll  *
269a04ccd59SMartin Hundebøll  * Returns true if current time is after timestamp + timeout
270a04ccd59SMartin Hundebøll  */
2711eda58bfSSven Eckelmann static inline bool batadv_has_timed_out(unsigned long timestamp,
2721eda58bfSSven Eckelmann 					unsigned int timeout)
273a04ccd59SMartin Hundebøll {
274a04ccd59SMartin Hundebøll 	return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout));
275a04ccd59SMartin Hundebøll }
276747e4221SSven Eckelmann 
2773e34819eSSven Eckelmann #define batadv_atomic_dec_not_zero(v)	atomic_add_unless((v), -1, 0)
2785f657ec0SAntonio Quartulli 
279f5d33d37SAntonio Quartulli /* Returns the smallest signed integer in two's complement with the sizeof x */
2803e34819eSSven Eckelmann #define batadv_smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
281f5d33d37SAntonio Quartulli 
282f5d33d37SAntonio Quartulli /* Checks if a sequence number x is a predecessor/successor of y.
283f5d33d37SAntonio Quartulli  * they handle overflows/underflows and can correctly check for a
284f5d33d37SAntonio Quartulli  * predecessor/successor unless the variable sequence number has grown by
285f5d33d37SAntonio Quartulli  * more then 2**(bitwidth(x)-1)-1.
286f5d33d37SAntonio Quartulli  * This means that for a uint8_t with the maximum value 255, it would think:
287f5d33d37SAntonio Quartulli  *  - when adding nothing - it is neither a predecessor nor a successor
288f5d33d37SAntonio Quartulli  *  - before adding more than 127 to the starting value - it is a predecessor,
289f5d33d37SAntonio Quartulli  *  - when adding 128 - it is neither a predecessor nor a successor,
2909cfc7bd6SSven Eckelmann  *  - after adding more than 127 to the starting value - it is a successor
2919cfc7bd6SSven Eckelmann  */
2923e34819eSSven Eckelmann #define batadv_seq_before(x, y) ({typeof(x) _d1 = (x); \
2930bb85751SSven Eckelmann 				 typeof(y) _d2 = (y); \
2940bb85751SSven Eckelmann 				 typeof(x) _dummy = (_d1 - _d2); \
2950bb85751SSven Eckelmann 				 (void) (&_d1 == &_d2); \
2963e34819eSSven Eckelmann 				 _dummy > batadv_smallest_signed_int(_dummy); })
2973e34819eSSven Eckelmann #define batadv_seq_after(x, y) batadv_seq_before(y, x)
298f5d33d37SAntonio Quartulli 
299f8214865SMartin Hundebøll /* Stop preemption on local cpu while incrementing the counter */
30056303d34SSven Eckelmann static inline void batadv_add_counter(struct batadv_priv *bat_priv, size_t idx,
301f8214865SMartin Hundebøll 				      size_t count)
302f8214865SMartin Hundebøll {
30356917443SShan Wei 	this_cpu_add(bat_priv->bat_counters[idx], count);
304f8214865SMartin Hundebøll }
305f8214865SMartin Hundebøll 
306f8214865SMartin Hundebøll #define batadv_inc_counter(b, i) batadv_add_counter(b, i, 1)
307f8214865SMartin Hundebøll 
308f8214865SMartin Hundebøll /* Sum and return the cpu-local counters for index 'idx' */
30956303d34SSven Eckelmann static inline uint64_t batadv_sum_counter(struct batadv_priv *bat_priv,
31056303d34SSven Eckelmann 					  size_t idx)
311f8214865SMartin Hundebøll {
3120c5e45b6SMarek Lindner 	uint64_t *counters, sum = 0;
313f8214865SMartin Hundebøll 	int cpu;
314f8214865SMartin Hundebøll 
315f8214865SMartin Hundebøll 	for_each_possible_cpu(cpu) {
316f8214865SMartin Hundebøll 		counters = per_cpu_ptr(bat_priv->bat_counters, cpu);
317f8214865SMartin Hundebøll 		sum += counters[idx];
318f8214865SMartin Hundebøll 	}
319f8214865SMartin Hundebøll 
320f8214865SMartin Hundebøll 	return sum;
321f8214865SMartin Hundebøll }
322f8214865SMartin Hundebøll 
3233c12de9aSMartin Hundebøll /* Define a macro to reach the control buffer of the skb. The members of the
3243c12de9aSMartin Hundebøll  * control buffer are defined in struct batadv_skb_cb in types.h.
3253c12de9aSMartin Hundebøll  * The macro is inspired by the similar macro TCP_SKB_CB() in tcp.h.
3263c12de9aSMartin Hundebøll  */
3273c12de9aSMartin Hundebøll #define BATADV_SKB_CB(__skb)       ((struct batadv_skb_cb *)&((__skb)->cb[0]))
3283c12de9aSMartin Hundebøll 
329ef261577SMarek Lindner void batadv_tvlv_container_register(struct batadv_priv *bat_priv,
330ef261577SMarek Lindner 				    uint8_t type, uint8_t version,
331ef261577SMarek Lindner 				    void *tvlv_value, uint16_t tvlv_value_len);
332ef261577SMarek Lindner uint16_t batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,
333ef261577SMarek Lindner 					  unsigned char **packet_buff,
334ef261577SMarek Lindner 					  int *packet_buff_len,
335ef261577SMarek Lindner 					  int packet_min_len);
336ef261577SMarek Lindner void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,
337ef261577SMarek Lindner 			     struct batadv_ogm_packet *batadv_ogm_packet,
338ef261577SMarek Lindner 			     struct batadv_orig_node *orig_node);
339ef261577SMarek Lindner void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv,
340ef261577SMarek Lindner 				      uint8_t type, uint8_t version);
341ef261577SMarek Lindner 
342ef261577SMarek Lindner void batadv_tvlv_handler_register(struct batadv_priv *bat_priv,
343ef261577SMarek Lindner 				  void (*optr)(struct batadv_priv *bat_priv,
344ef261577SMarek Lindner 					       struct batadv_orig_node *orig,
345ef261577SMarek Lindner 					       uint8_t flags,
346ef261577SMarek Lindner 					       void *tvlv_value,
347ef261577SMarek Lindner 					       uint16_t tvlv_value_len),
348ef261577SMarek Lindner 				  int (*uptr)(struct batadv_priv *bat_priv,
349ef261577SMarek Lindner 					      uint8_t *src, uint8_t *dst,
350ef261577SMarek Lindner 					      void *tvlv_value,
351ef261577SMarek Lindner 					      uint16_t tvlv_value_len),
352ef261577SMarek Lindner 				  uint8_t type, uint8_t version, uint8_t flags);
353ef261577SMarek Lindner void batadv_tvlv_handler_unregister(struct batadv_priv *bat_priv,
354ef261577SMarek Lindner 				    uint8_t type, uint8_t version);
355ef261577SMarek Lindner int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
356ef261577SMarek Lindner 				   bool ogm_source,
357ef261577SMarek Lindner 				   struct batadv_orig_node *orig_node,
358ef261577SMarek Lindner 				   uint8_t *src, uint8_t *dst,
359ef261577SMarek Lindner 				   void *tvlv_buff, uint16_t tvlv_buff_len);
360ef261577SMarek Lindner void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, uint8_t *src,
361ef261577SMarek Lindner 			      uint8_t *dst, uint8_t type, uint8_t version,
362ef261577SMarek Lindner 			      void *tvlv_value, uint16_t tvlv_value_len);
363*c018ad3dSAntonio Quartulli unsigned short batadv_get_vid(struct sk_buff *skb, size_t header_len);
364ef261577SMarek Lindner 
365c6c8fea2SSven Eckelmann #endif /* _NET_BATMAN_ADV_MAIN_H_ */
366