xref: /linux/net/batman-adv/distributed-arp-table.h (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) B.A.T.M.A.N. contributors:
3  *
4  * Antonio Quartulli
5  */
6 
7 #ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
8 #define _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_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/skbuff.h>
16 #include <linux/types.h>
17 #include <uapi/linux/batadv_packet.h>
18 
19 #include "originator.h"
20 
21 #ifdef CONFIG_BATMAN_ADV_DAT
22 
23 /* BATADV_DAT_ADDR_MAX - maximum address value in the DHT space */
24 #define BATADV_DAT_ADDR_MAX ((batadv_dat_addr_t)~(batadv_dat_addr_t)0)
25 
26 void batadv_dat_status_update(struct net_device *net_dev);
27 bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
28 					   struct sk_buff *skb);
29 bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
30 					   struct sk_buff *skb, int hdr_size);
31 void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
32 					 struct sk_buff *skb);
33 bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
34 					 struct sk_buff *skb, int hdr_size);
35 void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
36 					struct sk_buff *skb,
37 					__be16 proto,
38 					unsigned short vid);
39 void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,
40 					struct sk_buff *skb, int hdr_size);
41 bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
42 				      struct batadv_forw_packet *forw_packet);
43 
44 /**
45  * batadv_dat_init_orig_node_addr() - assign a DAT address to the orig_node
46  * @orig_node: the node to assign the DAT address to
47  */
48 static inline void
49 batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node)
50 {
51 	u32 addr;
52 
53 	addr = batadv_choose_orig(orig_node->orig, BATADV_DAT_ADDR_MAX);
54 	orig_node->dat_addr = (batadv_dat_addr_t)addr;
55 }
56 
57 /**
58  * batadv_dat_init_own_addr() - assign a DAT address to the node itself
59  * @bat_priv: the bat priv with all the soft interface information
60  * @primary_if: a pointer to the primary interface
61  */
62 static inline void
63 batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
64 			 struct batadv_hard_iface *primary_if)
65 {
66 	u32 addr;
67 
68 	addr = batadv_choose_orig(primary_if->net_dev->dev_addr,
69 				  BATADV_DAT_ADDR_MAX);
70 
71 	bat_priv->dat.addr = (batadv_dat_addr_t)addr;
72 }
73 
74 int batadv_dat_init(struct batadv_priv *bat_priv);
75 void batadv_dat_free(struct batadv_priv *bat_priv);
76 int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb);
77 
78 /**
79  * batadv_dat_inc_counter() - increment the correct DAT packet counter
80  * @bat_priv: the bat priv with all the soft interface information
81  * @subtype: the 4addr subtype of the packet to be counted
82  *
83  * Updates the ethtool statistics for the received packet if it is a DAT subtype
84  */
85 static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
86 					  u8 subtype)
87 {
88 	switch (subtype) {
89 	case BATADV_P_DAT_DHT_GET:
90 		batadv_inc_counter(bat_priv,
91 				   BATADV_CNT_DAT_GET_RX);
92 		break;
93 	case BATADV_P_DAT_DHT_PUT:
94 		batadv_inc_counter(bat_priv,
95 				   BATADV_CNT_DAT_PUT_RX);
96 		break;
97 	}
98 }
99 
100 #else
101 
102 static inline void batadv_dat_status_update(struct net_device *net_dev)
103 {
104 }
105 
106 static inline bool
107 batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
108 				      struct sk_buff *skb)
109 {
110 	return false;
111 }
112 
113 static inline bool
114 batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
115 				      struct sk_buff *skb, int hdr_size)
116 {
117 	return false;
118 }
119 
120 static inline bool
121 batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
122 				    struct sk_buff *skb)
123 {
124 	return false;
125 }
126 
127 static inline bool
128 batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
129 				    struct sk_buff *skb, int hdr_size)
130 {
131 	return false;
132 }
133 
134 static inline void
135 batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
136 				   struct sk_buff *skb, __be16 proto,
137 				   unsigned short vid)
138 {
139 }
140 
141 static inline void
142 batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,
143 				   struct sk_buff *skb, int hdr_size)
144 {
145 }
146 
147 static inline bool
148 batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
149 				 struct batadv_forw_packet *forw_packet)
150 {
151 	return false;
152 }
153 
154 static inline void
155 batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node)
156 {
157 }
158 
159 static inline void batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
160 					    struct batadv_hard_iface *iface)
161 {
162 }
163 
164 static inline int batadv_dat_init(struct batadv_priv *bat_priv)
165 {
166 	return 0;
167 }
168 
169 static inline void batadv_dat_free(struct batadv_priv *bat_priv)
170 {
171 }
172 
173 static inline int
174 batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
175 {
176 	return -EOPNOTSUPP;
177 }
178 
179 static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
180 					  u8 subtype)
181 {
182 }
183 
184 #endif /* CONFIG_BATMAN_ADV_DAT */
185 
186 #endif /* _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ */
187