blob: bed7f3d2084442221a9d2f014c8e1cff961cf32a [file] [log] [blame]
Sven Eckelmann7db7d9f2017-11-19 15:05:11 +01001/* SPDX-License-Identifier: GPL-2.0 */
Sven Eckelmanncfa55c62021-01-01 00:00:01 +01002/* Copyright (C) B.A.T.M.A.N. contributors:
Antonio Quartulli785ea112011-11-23 11:35:44 +01003 *
4 * Antonio Quartulli
Antonio Quartulli785ea112011-11-23 11:35:44 +01005 */
6
Antonio Quartullia48bcac2013-10-13 23:02:45 +02007#ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
8#define _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_
Antonio Quartulli785ea112011-11-23 11:35:44 +01009
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020010#include "main.h"
Antonio Quartulli17224472011-11-06 12:23:55 +010011
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020012#include <linux/compiler.h>
13#include <linux/netdevice.h>
Sven Eckelmann68a600d2019-05-24 20:11:17 +020014#include <linux/netlink.h>
Sven Eckelmann68a600d2019-05-24 20:11:17 +020015#include <linux/skbuff.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020016#include <linux/types.h>
Sven Eckelmannfec149f2017-12-21 10:17:41 +010017#include <uapi/linux/batadv_packet.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020018
Antonio Quartulli785ea112011-11-23 11:35:44 +010019#include "originator.h"
20
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020021#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli5c3a0e52011-06-02 12:29:51 +020022
Martin Hundebøllba97abb2014-07-15 09:41:07 +020023/* BATADV_DAT_ADDR_MAX - maximum address value in the DHT space */
Antonio Quartulli785ea112011-11-23 11:35:44 +010024#define BATADV_DAT_ADDR_MAX ((batadv_dat_addr_t)~(batadv_dat_addr_t)0)
25
Marek Lindner17cf0ea2013-04-23 21:39:59 +080026void batadv_dat_status_update(struct net_device *net_dev);
Antonio Quartullic384ea32011-06-26 03:37:18 +020027bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
28 struct sk_buff *skb);
29bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
30 struct sk_buff *skb, int hdr_size);
31void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
32 struct sk_buff *skb);
33bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
34 struct sk_buff *skb, int hdr_size);
Linus Lüssingb61ec312018-12-30 16:52:53 +010035void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
36 struct sk_buff *skb,
37 __be16 proto,
38 unsigned short vid);
39void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,
40 struct sk_buff *skb, int hdr_size);
Antonio Quartullic384ea32011-06-26 03:37:18 +020041bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
42 struct batadv_forw_packet *forw_packet);
43
Antonio Quartulli785ea112011-11-23 11:35:44 +010044/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010045 * batadv_dat_init_orig_node_addr() - assign a DAT address to the orig_node
Antonio Quartulli785ea112011-11-23 11:35:44 +010046 * @orig_node: the node to assign the DAT address to
47 */
48static inline void
49batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node)
50{
Sven Eckelmann6b5e9712015-05-26 18:34:26 +020051 u32 addr;
Antonio Quartulli785ea112011-11-23 11:35:44 +010052
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/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010058 * batadv_dat_init_own_addr() - assign a DAT address to the node itself
Antonio Quartulli785ea112011-11-23 11:35:44 +010059 * @bat_priv: the bat priv with all the soft interface information
60 * @primary_if: a pointer to the primary interface
61 */
62static inline void
63batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
64 struct batadv_hard_iface *primary_if)
65{
Sven Eckelmann6b5e9712015-05-26 18:34:26 +020066 u32 addr;
Antonio Quartulli785ea112011-11-23 11:35:44 +010067
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
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +020074int batadv_dat_init(struct batadv_priv *bat_priv);
75void batadv_dat_free(struct batadv_priv *bat_priv);
Linus Lüssing41aeefc2018-03-13 11:41:12 +010076int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb);
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +020077
Martin Hundebøll4046b242012-04-20 17:02:45 +020078/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010079 * batadv_dat_inc_counter() - increment the correct DAT packet counter
Martin Hundebøll4046b242012-04-20 17:02:45 +020080 * @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 */
85static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
Sven Eckelmann6b5e9712015-05-26 18:34:26 +020086 u8 subtype)
Martin Hundebøll4046b242012-04-20 17:02:45 +020087{
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
Antonio Quartulli17224472011-11-06 12:23:55 +0100100#else
101
Marek Lindner17cf0ea2013-04-23 21:39:59 +0800102static inline void batadv_dat_status_update(struct net_device *net_dev)
103{
104}
105
Antonio Quartulli17224472011-11-06 12:23:55 +0100106static inline bool
107batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
108 struct sk_buff *skb)
109{
110 return false;
111}
112
113static inline bool
114batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
115 struct sk_buff *skb, int hdr_size)
116{
117 return false;
118}
119
120static inline bool
121batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
122 struct sk_buff *skb)
123{
124 return false;
125}
126
127static inline bool
128batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
129 struct sk_buff *skb, int hdr_size)
130{
131 return false;
132}
133
Linus Lüssingb61ec312018-12-30 16:52:53 +0100134static inline void
135batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
136 struct sk_buff *skb, __be16 proto,
137 unsigned short vid)
138{
139}
140
141static inline void
142batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,
143 struct sk_buff *skb, int hdr_size)
144{
145}
146
Antonio Quartulli17224472011-11-06 12:23:55 +0100147static inline bool
148batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
149 struct batadv_forw_packet *forw_packet)
150{
151 return false;
152}
153
154static inline void
155batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node)
156{
157}
158
159static inline void batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
160 struct batadv_hard_iface *iface)
161{
162}
163
Antonio Quartulli17224472011-11-06 12:23:55 +0100164static inline int batadv_dat_init(struct batadv_priv *bat_priv)
165{
166 return 0;
167}
168
169static inline void batadv_dat_free(struct batadv_priv *bat_priv)
170{
171}
172
Linus Lüssing41aeefc2018-03-13 11:41:12 +0100173static inline int
174batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
175{
176 return -EOPNOTSUPP;
177}
178
Martin Hundebøll4046b242012-04-20 17:02:45 +0200179static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
Sven Eckelmann6b5e9712015-05-26 18:34:26 +0200180 u8 subtype)
Martin Hundebøll4046b242012-04-20 17:02:45 +0200181{
182}
183
Antonio Quartulli17224472011-11-06 12:23:55 +0100184#endif /* CONFIG_BATMAN_ADV_DAT */
185
Antonio Quartullia48bcac2013-10-13 23:02:45 +0200186#endif /* _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ */