1 /* SPDX-License-Identifier: GPL-2.0+ */
8 #include <linux/siphash.h>
9 #include <linux/jhash.h>
10 #include <linux/netdevice.h>
11 #include <net/gro_cells.h>
12 #include <net/rtnetlink.h>
15 AMT_MSG_DISCOVERY = 1,
16 AMT_MSG_ADVERTISEMENT,
18 AMT_MSG_MEMBERSHIP_QUERY,
19 AMT_MSG_MEMBERSHIP_UPDATE,
20 AMT_MSG_MULTICAST_DATA,
25 #define AMT_MSG_MAX (__AMT_MSG_MAX - 1)
39 #define AMT_OPS_MAX (__AMT_OPS_MAX - 1)
53 #define AMT_FILTER_MAX (__AMT_FILTER_MAX - 1)
59 AMT_ACT_STATUS_FWD_NEW,
60 AMT_ACT_STATUS_D_FWD_NEW,
61 AMT_ACT_STATUS_NONE_NEW,
65 #define AMT_ACT_MAX (__AMT_ACT_MAX - 1)
69 AMT_STATUS_SENT_DISCOVERY,
70 AMT_STATUS_RECEIVED_DISCOVERY,
71 AMT_STATUS_SENT_ADVERTISEMENT,
72 AMT_STATUS_RECEIVED_ADVERTISEMENT,
73 AMT_STATUS_SENT_REQUEST,
74 AMT_STATUS_RECEIVED_REQUEST,
75 AMT_STATUS_SENT_QUERY,
76 AMT_STATUS_RECEIVED_QUERY,
77 AMT_STATUS_SENT_UPDATE,
78 AMT_STATUS_RECEIVED_UPDATE,
82 #define AMT_STATUS_MAX (__AMT_STATUS_MAX - 1)
84 /* Gateway events only */
88 AMT_EVENT_SEND_DISCOVERY,
89 AMT_EVENT_SEND_REQUEST,
94 #if defined(__LITTLE_ENDIAN_BITFIELD)
97 #elif defined(__BIG_ENDIAN_BITFIELD)
101 #error "Please fix <asm/byteorder.h>"
105 struct amt_header_discovery {
106 #if defined(__LITTLE_ENDIAN_BITFIELD)
110 #elif defined(__BIG_ENDIAN_BITFIELD)
115 #error "Please fix <asm/byteorder.h>"
120 struct amt_header_advertisement {
121 #if defined(__LITTLE_ENDIAN_BITFIELD)
125 #elif defined(__BIG_ENDIAN_BITFIELD)
130 #error "Please fix <asm/byteorder.h>"
136 struct amt_header_request {
137 #if defined(__LITTLE_ENDIAN_BITFIELD)
143 #elif defined(__BIG_ENDIAN_BITFIELD)
150 #error "Please fix <asm/byteorder.h>"
155 struct amt_header_membership_query {
156 #if defined(__LITTLE_ENDIAN_BITFIELD)
163 #elif defined(__BIG_ENDIAN_BITFIELD)
171 #error "Please fix <asm/byteorder.h>"
176 struct amt_header_membership_update {
177 #if defined(__LITTLE_ENDIAN_BITFIELD)
182 #elif defined(__BIG_ENDIAN_BITFIELD)
188 #error "Please fix <asm/byteorder.h>"
193 struct amt_header_mcast_data {
194 #if defined(__LITTLE_ENDIAN_BITFIELD)
198 #elif defined(__BIG_ENDIAN_BITFIELD)
203 #error "Please fix <asm/byteorder.h>"
209 struct amt_header_discovery discovery;
210 struct amt_header_advertisement advertisement;
211 struct amt_header_request request;
212 struct amt_header_membership_query query;
213 struct amt_header_membership_update update;
214 struct amt_header_mcast_data data;
218 struct amt_gw_headers {
220 struct amt_header_discovery discovery;
221 struct amt_header_request request;
222 struct amt_header_membership_update update;
226 struct amt_relay_headers {
228 struct amt_header_advertisement advertisement;
229 struct amt_header_membership_query query;
230 struct amt_header_mcast_data data;
235 struct amt_tunnel_list *tunnel;
238 struct amt_tunnel_list {
239 struct list_head list;
240 /* Protect All resources under an amt_tunne_list */
245 enum amt_status status;
246 struct delayed_work gc_wq;
254 struct hlist_head groups[];
259 #if IS_ENABLED(CONFIG_IPV6)
266 * When the router is in EXCLUDE mode, the router state is represented
267 * by the notation EXCLUDE (X,Y), where X is called the "Requested List"
268 * and Y is called the "Exclude List". All sources, except those from
269 * the Exclude List, will be forwarded by the router
271 enum amt_source_status {
272 AMT_SOURCE_STATUS_NONE,
273 /* Node of Requested List */
274 AMT_SOURCE_STATUS_FWD,
275 /* Node of Exclude List */
276 AMT_SOURCE_STATUS_D_FWD,
279 /* protected by gnode->lock */
280 struct amt_source_node {
281 struct hlist_node node;
282 struct amt_group_node *gnode;
283 struct delayed_work source_timer;
284 union amt_addr source_addr;
285 enum amt_source_status status;
286 #define AMT_SOURCE_OLD 0
287 #define AMT_SOURCE_NEW 1
292 /* Protected by amt_tunnel_list->lock */
293 struct amt_group_node {
295 union amt_addr group_addr;
296 union amt_addr host_addr;
300 struct amt_tunnel_list *tunnel_list;
301 struct hlist_node node;
302 struct delayed_work group_timer;
304 struct hlist_head sources[];
307 #define AMT_MAX_EVENTS 16
309 enum amt_event event;
314 struct net_device *dev;
315 struct net_device *stream_dev;
317 /* Global lock for amt device */
319 /* Used only in relay mode */
320 struct list_head tunnel_list;
321 struct gro_cells gro_cells;
323 /* Protected by RTNL */
324 struct delayed_work discovery_wq;
325 /* Protected by RTNL */
326 struct delayed_work req_wq;
327 /* Protected by RTNL */
328 struct delayed_work secret_wq;
329 struct work_struct event_wq;
331 enum amt_status status;
334 struct socket __rcu *sock;
343 /* Gateway or Relay mode */
351 /* Outer remote ip */
353 /* Outer discovery ip */
355 /* Only used in gateway mode */
357 /* Gateway sent request and received query */
364 /* Used only in gateway mode */
367 /* AMT gateway side message handler queue */
368 struct amt_events events[AMT_MAX_EVENTS];
374 #define AMT_IPHDR_OPTS 4
375 #define AMT_IP6HDR_OPTS 8
376 #define AMT_GC_INTERVAL (30 * 1000)
377 #define AMT_MAX_GROUP 32
378 #define AMT_MAX_SOURCE 128
379 #define AMT_HSIZE_SHIFT 8
380 #define AMT_HSIZE (1 << AMT_HSIZE_SHIFT)
382 #define AMT_DISCOVERY_TIMEOUT 5000
383 #define AMT_INIT_REQ_TIMEOUT 1
384 #define AMT_INIT_QUERY_INTERVAL 125
385 #define AMT_MAX_REQ_TIMEOUT 120
386 #define AMT_MAX_REQ_COUNT 3
387 #define AMT_SECRET_TIMEOUT 60000
388 #define IANA_AMT_UDP_PORT 2268
389 #define AMT_MAX_TUNNELS 128
390 #define AMT_MAX_REQS 128
391 #define AMT_GW_HLEN (sizeof(struct iphdr) + \
392 sizeof(struct udphdr) + \
393 sizeof(struct amt_gw_headers))
394 #define AMT_RELAY_HLEN (sizeof(struct iphdr) + \
395 sizeof(struct udphdr) + \
396 sizeof(struct amt_relay_headers))
398 static inline bool netif_is_amt(const struct net_device *dev)
400 return dev->rtnl_link_ops && !strcmp(dev->rtnl_link_ops->kind, "amt");
403 static inline u64 amt_gmi(const struct amt_dev *amt)
405 return ((amt->qrv * amt->qi) + amt->qri) * 1000;
408 #endif /* _NET_AMT_H_ */