1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2011-2020 B.A.T.M.A.N. contributors:
7 #ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
8 #define _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
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>
19 #include "originator.h"
21 #ifdef CONFIG_BATMAN_ADV_DAT
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)
26 void batadv_dat_status_update(struct net_device
*net_dev
);
27 bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv
*bat_priv
,
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
,
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
,
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
);
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
49 batadv_dat_init_orig_node_addr(struct batadv_orig_node
*orig_node
)
53 addr
= batadv_choose_orig(orig_node
->orig
, BATADV_DAT_ADDR_MAX
);
54 orig_node
->dat_addr
= (batadv_dat_addr_t
)addr
;
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
63 batadv_dat_init_own_addr(struct batadv_priv
*bat_priv
,
64 struct batadv_hard_iface
*primary_if
)
68 addr
= batadv_choose_orig(primary_if
->net_dev
->dev_addr
,
71 bat_priv
->dat
.addr
= (batadv_dat_addr_t
)addr
;
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
);
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
83 * Updates the ethtool statistics for the received packet if it is a DAT subtype
85 static inline void batadv_dat_inc_counter(struct batadv_priv
*bat_priv
,
89 case BATADV_P_DAT_DHT_GET
:
90 batadv_inc_counter(bat_priv
,
91 BATADV_CNT_DAT_GET_RX
);
93 case BATADV_P_DAT_DHT_PUT
:
94 batadv_inc_counter(bat_priv
,
95 BATADV_CNT_DAT_PUT_RX
);
102 static inline void batadv_dat_status_update(struct net_device
*net_dev
)
107 batadv_dat_snoop_outgoing_arp_request(struct batadv_priv
*bat_priv
,
114 batadv_dat_snoop_incoming_arp_request(struct batadv_priv
*bat_priv
,
115 struct sk_buff
*skb
, int hdr_size
)
121 batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv
*bat_priv
,
128 batadv_dat_snoop_incoming_arp_reply(struct batadv_priv
*bat_priv
,
129 struct sk_buff
*skb
, int hdr_size
)
135 batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv
*bat_priv
,
136 struct sk_buff
*skb
, __be16 proto
,
142 batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv
*bat_priv
,
143 struct sk_buff
*skb
, int hdr_size
)
148 batadv_dat_drop_broadcast_packet(struct batadv_priv
*bat_priv
,
149 struct batadv_forw_packet
*forw_packet
)
155 batadv_dat_init_orig_node_addr(struct batadv_orig_node
*orig_node
)
159 static inline void batadv_dat_init_own_addr(struct batadv_priv
*bat_priv
,
160 struct batadv_hard_iface
*iface
)
164 static inline int batadv_dat_init(struct batadv_priv
*bat_priv
)
169 static inline void batadv_dat_free(struct batadv_priv
*bat_priv
)
174 batadv_dat_cache_dump(struct sk_buff
*msg
, struct netlink_callback
*cb
)
179 static inline void batadv_dat_inc_counter(struct batadv_priv
*bat_priv
,
184 #endif /* CONFIG_BATMAN_ADV_DAT */
186 #endif /* _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ */