1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors:
3 *
4 * Simon Wunderlich
5 */
6
7 #ifndef _NET_BATMAN_ADV_BLA_H_
8 #define _NET_BATMAN_ADV_BLA_H_
9
10 #include "main.h"
11
12 #include <linux/compiler.h>
13 #include <linux/netdevice.h>
14 #include <linux/netlink.h>
15 #include <linux/seq_file.h>
16 #include <linux/skbuff.h>
17 #include <linux/stddef.h>
18 #include <linux/types.h>
19
20 /**
21 * batadv_bla_is_loopdetect_mac() - check if the mac address is from a loop
22 * detect frame sent by bridge loop avoidance
23 * @mac: mac address to check
24 *
25 * Return: true if the it looks like a loop detect frame
26 * (mac starts with BA:BE), false otherwise
27 */
batadv_bla_is_loopdetect_mac(const uint8_t * mac)28 static inline bool batadv_bla_is_loopdetect_mac(const uint8_t *mac)
29 {
30 if (mac[0] == 0xba && mac[1] == 0xbe)
31 return true;
32
33 return false;
34 }
35
36 #ifdef CONFIG_BATMAN_ADV_BLA
37 bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
38 unsigned short vid, bool is_bcast);
39 bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,
40 unsigned short vid);
41 bool batadv_bla_is_backbone_gw(struct sk_buff *skb,
42 struct batadv_orig_node *orig_node,
43 int hdr_size);
44 int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset);
45 int batadv_bla_claim_dump(struct sk_buff *msg, struct netlink_callback *cb);
46 int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq,
47 void *offset);
48 int batadv_bla_backbone_dump(struct sk_buff *msg, struct netlink_callback *cb);
49 bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, u8 *orig,
50 unsigned short vid);
51 bool batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
52 struct sk_buff *skb);
53 void batadv_bla_update_orig_address(struct batadv_priv *bat_priv,
54 struct batadv_hard_iface *primary_if,
55 struct batadv_hard_iface *oldif);
56 void batadv_bla_status_update(struct net_device *net_dev);
57 int batadv_bla_init(struct batadv_priv *bat_priv);
58 void batadv_bla_free(struct batadv_priv *bat_priv);
59 int batadv_bla_claim_dump(struct sk_buff *msg, struct netlink_callback *cb);
60 #ifdef CONFIG_BATMAN_ADV_DAT
61 bool batadv_bla_check_claim(struct batadv_priv *bat_priv, u8 *addr,
62 unsigned short vid);
63 #endif
64 #define BATADV_BLA_CRC_INIT 0
65 #else /* ifdef CONFIG_BATMAN_ADV_BLA */
66
batadv_bla_rx(struct batadv_priv * bat_priv,struct sk_buff * skb,unsigned short vid,bool is_bcast)67 static inline bool batadv_bla_rx(struct batadv_priv *bat_priv,
68 struct sk_buff *skb, unsigned short vid,
69 bool is_bcast)
70 {
71 return false;
72 }
73
batadv_bla_tx(struct batadv_priv * bat_priv,struct sk_buff * skb,unsigned short vid)74 static inline bool batadv_bla_tx(struct batadv_priv *bat_priv,
75 struct sk_buff *skb, unsigned short vid)
76 {
77 return false;
78 }
79
batadv_bla_is_backbone_gw(struct sk_buff * skb,struct batadv_orig_node * orig_node,int hdr_size)80 static inline bool batadv_bla_is_backbone_gw(struct sk_buff *skb,
81 struct batadv_orig_node *orig_node,
82 int hdr_size)
83 {
84 return false;
85 }
86
batadv_bla_claim_table_seq_print_text(struct seq_file * seq,void * offset)87 static inline int batadv_bla_claim_table_seq_print_text(struct seq_file *seq,
88 void *offset)
89 {
90 return 0;
91 }
92
batadv_bla_backbone_table_seq_print_text(struct seq_file * seq,void * offset)93 static inline int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq,
94 void *offset)
95 {
96 return 0;
97 }
98
batadv_bla_is_backbone_gw_orig(struct batadv_priv * bat_priv,u8 * orig,unsigned short vid)99 static inline bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv,
100 u8 *orig, unsigned short vid)
101 {
102 return false;
103 }
104
105 static inline bool
batadv_bla_check_bcast_duplist(struct batadv_priv * bat_priv,struct sk_buff * skb)106 batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
107 struct sk_buff *skb)
108 {
109 return false;
110 }
111
112 static inline void
batadv_bla_update_orig_address(struct batadv_priv * bat_priv,struct batadv_hard_iface * primary_if,struct batadv_hard_iface * oldif)113 batadv_bla_update_orig_address(struct batadv_priv *bat_priv,
114 struct batadv_hard_iface *primary_if,
115 struct batadv_hard_iface *oldif)
116 {
117 }
118
batadv_bla_init(struct batadv_priv * bat_priv)119 static inline int batadv_bla_init(struct batadv_priv *bat_priv)
120 {
121 return 1;
122 }
123
batadv_bla_free(struct batadv_priv * bat_priv)124 static inline void batadv_bla_free(struct batadv_priv *bat_priv)
125 {
126 }
127
batadv_bla_claim_dump(struct sk_buff * msg,struct netlink_callback * cb)128 static inline int batadv_bla_claim_dump(struct sk_buff *msg,
129 struct netlink_callback *cb)
130 {
131 return -EOPNOTSUPP;
132 }
133
batadv_bla_backbone_dump(struct sk_buff * msg,struct netlink_callback * cb)134 static inline int batadv_bla_backbone_dump(struct sk_buff *msg,
135 struct netlink_callback *cb)
136 {
137 return -EOPNOTSUPP;
138 }
139
140 static inline
batadv_bla_check_claim(struct batadv_priv * bat_priv,u8 * addr,unsigned short vid)141 bool batadv_bla_check_claim(struct batadv_priv *bat_priv, u8 *addr,
142 unsigned short vid)
143 {
144 return true;
145 }
146
147 #endif /* ifdef CONFIG_BATMAN_ADV_BLA */
148
149 #endif /* ifndef _NET_BATMAN_ADV_BLA_H_ */
150