1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (C) 2011-2019 B.A.T.M.A.N. contributors: 3 * 4 * Antonio Quartulli 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of version 2 of the GNU General Public 8 * License as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ 20 #define _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ 21 22 #include "main.h" 23 24 #include <linux/compiler.h> 25 #include <linux/netdevice.h> 26 #include <linux/types.h> 27 #include <uapi/linux/batadv_packet.h> 28 29 #include "originator.h" 30 31 struct netlink_callback; 32 struct seq_file; 33 struct sk_buff; 34 35 #ifdef CONFIG_BATMAN_ADV_DAT 36 37 /* BATADV_DAT_ADDR_MAX - maximum address value in the DHT space */ 38 #define BATADV_DAT_ADDR_MAX ((batadv_dat_addr_t)~(batadv_dat_addr_t)0) 39 40 void batadv_dat_status_update(struct net_device *net_dev); 41 bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, 42 struct sk_buff *skb); 43 bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv, 44 struct sk_buff *skb, int hdr_size); 45 void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv, 46 struct sk_buff *skb); 47 bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv, 48 struct sk_buff *skb, int hdr_size); 49 void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv, 50 struct sk_buff *skb, 51 __be16 proto, 52 unsigned short vid); 53 void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv, 54 struct sk_buff *skb, int hdr_size); 55 bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv, 56 struct batadv_forw_packet *forw_packet); 57 58 /** 59 * batadv_dat_init_orig_node_addr() - assign a DAT address to the orig_node 60 * @orig_node: the node to assign the DAT address to 61 */ 62 static inline void 63 batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node) 64 { 65 u32 addr; 66 67 addr = batadv_choose_orig(orig_node->orig, BATADV_DAT_ADDR_MAX); 68 orig_node->dat_addr = (batadv_dat_addr_t)addr; 69 } 70 71 /** 72 * batadv_dat_init_own_addr() - assign a DAT address to the node itself 73 * @bat_priv: the bat priv with all the soft interface information 74 * @primary_if: a pointer to the primary interface 75 */ 76 static inline void 77 batadv_dat_init_own_addr(struct batadv_priv *bat_priv, 78 struct batadv_hard_iface *primary_if) 79 { 80 u32 addr; 81 82 addr = batadv_choose_orig(primary_if->net_dev->dev_addr, 83 BATADV_DAT_ADDR_MAX); 84 85 bat_priv->dat.addr = (batadv_dat_addr_t)addr; 86 } 87 88 int batadv_dat_init(struct batadv_priv *bat_priv); 89 void batadv_dat_free(struct batadv_priv *bat_priv); 90 int batadv_dat_cache_seq_print_text(struct seq_file *seq, void *offset); 91 int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb); 92 93 /** 94 * batadv_dat_inc_counter() - increment the correct DAT packet counter 95 * @bat_priv: the bat priv with all the soft interface information 96 * @subtype: the 4addr subtype of the packet to be counted 97 * 98 * Updates the ethtool statistics for the received packet if it is a DAT subtype 99 */ 100 static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv, 101 u8 subtype) 102 { 103 switch (subtype) { 104 case BATADV_P_DAT_DHT_GET: 105 batadv_inc_counter(bat_priv, 106 BATADV_CNT_DAT_GET_RX); 107 break; 108 case BATADV_P_DAT_DHT_PUT: 109 batadv_inc_counter(bat_priv, 110 BATADV_CNT_DAT_PUT_RX); 111 break; 112 } 113 } 114 115 #else 116 117 static inline void batadv_dat_status_update(struct net_device *net_dev) 118 { 119 } 120 121 static inline bool 122 batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, 123 struct sk_buff *skb) 124 { 125 return false; 126 } 127 128 static inline bool 129 batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv, 130 struct sk_buff *skb, int hdr_size) 131 { 132 return false; 133 } 134 135 static inline bool 136 batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv, 137 struct sk_buff *skb) 138 { 139 return false; 140 } 141 142 static inline bool 143 batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv, 144 struct sk_buff *skb, int hdr_size) 145 { 146 return false; 147 } 148 149 static inline void 150 batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv, 151 struct sk_buff *skb, __be16 proto, 152 unsigned short vid) 153 { 154 } 155 156 static inline void 157 batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv, 158 struct sk_buff *skb, int hdr_size) 159 { 160 } 161 162 static inline bool 163 batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv, 164 struct batadv_forw_packet *forw_packet) 165 { 166 return false; 167 } 168 169 static inline void 170 batadv_dat_init_orig_node_addr(struct batadv_orig_node *orig_node) 171 { 172 } 173 174 static inline void batadv_dat_init_own_addr(struct batadv_priv *bat_priv, 175 struct batadv_hard_iface *iface) 176 { 177 } 178 179 static inline void batadv_arp_change_timeout(struct net_device *soft_iface, 180 const char *name) 181 { 182 } 183 184 static inline int batadv_dat_init(struct batadv_priv *bat_priv) 185 { 186 return 0; 187 } 188 189 static inline void batadv_dat_free(struct batadv_priv *bat_priv) 190 { 191 } 192 193 static inline int 194 batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb) 195 { 196 return -EOPNOTSUPP; 197 } 198 199 static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv, 200 u8 subtype) 201 { 202 } 203 204 #endif /* CONFIG_BATMAN_ADV_DAT */ 205 206 #endif /* _NET_BATMAN_ADV_DISTRIBUTED_ARP_TABLE_H_ */ 207