Sven Eckelmann | 7db7d9f | 2017-11-19 15:05:11 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Sven Eckelmann | cfa55c6 | 2021-01-01 00:00:01 +0100 | [diff] [blame] | 2 | /* Copyright (C) B.A.T.M.A.N. contributors: |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 3 | * |
| 4 | * Antonio Quartulli |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Quartulli | a48bcac | 2013-10-13 23:02:45 +0200 | [diff] [blame] | 7 | #ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ |
| 8 | #define _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 9 | |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 10 | #include "main.h" |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 11 | |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 12 | #include <linux/compiler.h> |
| 13 | #include <linux/netdevice.h> |
Sven Eckelmann | 68a600d | 2019-05-24 20:11:17 +0200 | [diff] [blame] | 14 | #include <linux/netlink.h> |
Sven Eckelmann | 68a600d | 2019-05-24 20:11:17 +0200 | [diff] [blame] | 15 | #include <linux/skbuff.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 16 | #include <linux/types.h> |
Sven Eckelmann | fec149f | 2017-12-21 10:17:41 +0100 | [diff] [blame] | 17 | #include <uapi/linux/batadv_packet.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 18 | |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 19 | #include "originator.h" |
| 20 | |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 21 | #ifdef CONFIG_BATMAN_ADV_DAT |
Antonio Quartulli | 5c3a0e5 | 2011-06-02 12:29:51 +0200 | [diff] [blame] | 22 | |
Martin Hundebøll | ba97abb | 2014-07-15 09:41:07 +0200 | [diff] [blame] | 23 | /* BATADV_DAT_ADDR_MAX - maximum address value in the DHT space */ |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 24 | #define BATADV_DAT_ADDR_MAX ((batadv_dat_addr_t)~(batadv_dat_addr_t)0) |
| 25 | |
Marek Lindner | 17cf0ea | 2013-04-23 21:39:59 +0800 | [diff] [blame] | 26 | void batadv_dat_status_update(struct net_device *net_dev); |
Antonio Quartulli | c384ea3 | 2011-06-26 03:37:18 +0200 | [diff] [blame] | 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); |
Linus Lüssing | b61ec31 | 2018-12-30 16:52:53 +0100 | [diff] [blame] | 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); |
Antonio Quartulli | c384ea3 | 2011-06-26 03:37:18 +0200 | [diff] [blame] | 41 | bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv, |
| 42 | struct batadv_forw_packet *forw_packet); |
| 43 | |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 44 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 45 | * batadv_dat_init_orig_node_addr() - assign a DAT address to the orig_node |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 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 | { |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 51 | u32 addr; |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 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 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 58 | * batadv_dat_init_own_addr() - assign a DAT address to the node itself |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 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 | { |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 66 | u32 addr; |
Antonio Quartulli | 785ea11 | 2011-11-23 11:35:44 +0100 | [diff] [blame] | 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 | |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 74 | int batadv_dat_init(struct batadv_priv *bat_priv); |
| 75 | void batadv_dat_free(struct batadv_priv *bat_priv); |
Linus Lüssing | 41aeefc | 2018-03-13 11:41:12 +0100 | [diff] [blame] | 76 | int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb); |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 77 | |
Martin Hundebøll | 4046b24 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 78 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 79 | * batadv_dat_inc_counter() - increment the correct DAT packet counter |
Martin Hundebøll | 4046b24 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 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, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 86 | u8 subtype) |
Martin Hundebøll | 4046b24 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 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 | |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 100 | #else |
| 101 | |
Marek Lindner | 17cf0ea | 2013-04-23 21:39:59 +0800 | [diff] [blame] | 102 | static inline void batadv_dat_status_update(struct net_device *net_dev) |
| 103 | { |
| 104 | } |
| 105 | |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 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 | |
Linus Lüssing | b61ec31 | 2018-12-30 16:52:53 +0100 | [diff] [blame] | 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 | |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 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 | |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 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 | |
Linus Lüssing | 41aeefc | 2018-03-13 11:41:12 +0100 | [diff] [blame] | 173 | static inline int |
| 174 | batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb) |
| 175 | { |
| 176 | return -EOPNOTSUPP; |
| 177 | } |
| 178 | |
Martin Hundebøll | 4046b24 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 179 | static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv, |
Sven Eckelmann | 6b5e971 | 2015-05-26 18:34:26 +0200 | [diff] [blame] | 180 | u8 subtype) |
Martin Hundebøll | 4046b24 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 181 | { |
| 182 | } |
| 183 | |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 184 | #endif /* CONFIG_BATMAN_ADV_DAT */ |
| 185 | |
Antonio Quartulli | a48bcac | 2013-10-13 23:02:45 +0200 | [diff] [blame] | 186 | #endif /* _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ */ |