1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2021 Taehee Yoo <ap420073@gmail.com>
8 #include <linux/siphash.h>
9 #include <linux/jhash.h>
12 AMT_MSG_DISCOVERY = 1,
13 AMT_MSG_ADVERTISEMENT,
15 AMT_MSG_MEMBERSHIP_QUERY,
16 AMT_MSG_MEMBERSHIP_UPDATE,
17 AMT_MSG_MULTICAST_DATA,
22 #define AMT_MSG_MAX (__AMT_MSG_MAX - 1)
36 #define AMT_OPS_MAX (__AMT_OPS_MAX - 1)
50 #define AMT_FILTER_MAX (__AMT_FILTER_MAX - 1)
56 AMT_ACT_STATUS_FWD_NEW,
57 AMT_ACT_STATUS_D_FWD_NEW,
58 AMT_ACT_STATUS_NONE_NEW,
62 #define AMT_ACT_MAX (__AMT_ACT_MAX - 1)
66 AMT_STATUS_SENT_DISCOVERY,
67 AMT_STATUS_RECEIVED_DISCOVERY,
68 AMT_STATUS_SENT_ADVERTISEMENT,
69 AMT_STATUS_RECEIVED_ADVERTISEMENT,
70 AMT_STATUS_SENT_REQUEST,
71 AMT_STATUS_RECEIVED_REQUEST,
72 AMT_STATUS_SENT_QUERY,
73 AMT_STATUS_RECEIVED_QUERY,
74 AMT_STATUS_SENT_UPDATE,
75 AMT_STATUS_RECEIVED_UPDATE,
79 #define AMT_STATUS_MAX (__AMT_STATUS_MAX - 1)
81 /* Gateway events only */
85 AMT_EVENT_SEND_DISCOVERY,
86 AMT_EVENT_SEND_REQUEST,
91 #if defined(__LITTLE_ENDIAN_BITFIELD)
94 #elif defined(__BIG_ENDIAN_BITFIELD)
98 #error "Please fix <asm/byteorder.h>"
102 struct amt_header_discovery {
103 #if defined(__LITTLE_ENDIAN_BITFIELD)
107 #elif defined(__BIG_ENDIAN_BITFIELD)
112 #error "Please fix <asm/byteorder.h>"
117 struct amt_header_advertisement {
118 #if defined(__LITTLE_ENDIAN_BITFIELD)
122 #elif defined(__BIG_ENDIAN_BITFIELD)
127 #error "Please fix <asm/byteorder.h>"
133 struct amt_header_request {
134 #if defined(__LITTLE_ENDIAN_BITFIELD)
140 #elif defined(__BIG_ENDIAN_BITFIELD)
147 #error "Please fix <asm/byteorder.h>"
152 struct amt_header_membership_query {
153 #if defined(__LITTLE_ENDIAN_BITFIELD)
160 #elif defined(__BIG_ENDIAN_BITFIELD)
168 #error "Please fix <asm/byteorder.h>"
173 struct amt_header_membership_update {
174 #if defined(__LITTLE_ENDIAN_BITFIELD)
179 #elif defined(__BIG_ENDIAN_BITFIELD)
185 #error "Please fix <asm/byteorder.h>"
190 struct amt_header_mcast_data {
191 #if defined(__LITTLE_ENDIAN_BITFIELD)
195 #elif defined(__BIG_ENDIAN_BITFIELD)
200 #error "Please fix <asm/byteorder.h>"
206 struct amt_header_discovery discovery;
207 struct amt_header_advertisement advertisement;
208 struct amt_header_request request;
209 struct amt_header_membership_query query;
210 struct amt_header_membership_update update;
211 struct amt_header_mcast_data data;
215 struct amt_gw_headers {
217 struct amt_header_discovery discovery;
218 struct amt_header_request request;
219 struct amt_header_membership_update update;
223 struct amt_relay_headers {
225 struct amt_header_advertisement advertisement;
226 struct amt_header_membership_query query;
227 struct amt_header_mcast_data data;
232 struct amt_tunnel_list *tunnel;
235 struct amt_tunnel_list {
236 struct list_head list;
237 /* Protect All resources under an amt_tunne_list */
242 enum amt_status status;
243 struct delayed_work gc_wq;
251 struct hlist_head groups[];
256 #if IS_ENABLED(CONFIG_IPV6)
263 * When the router is in EXCLUDE mode, the router state is represented
264 * by the notation EXCLUDE (X,Y), where X is called the "Requested List"
265 * and Y is called the "Exclude List". All sources, except those from
266 * the Exclude List, will be forwarded by the router
268 enum amt_source_status {
269 AMT_SOURCE_STATUS_NONE,
270 /* Node of Requested List */
271 AMT_SOURCE_STATUS_FWD,
272 /* Node of Exclude List */
273 AMT_SOURCE_STATUS_D_FWD,
276 /* protected by gnode->lock */
277 struct amt_source_node {
278 struct hlist_node node;
279 struct amt_group_node *gnode;
280 struct delayed_work source_timer;
281 union amt_addr source_addr;
282 enum amt_source_status status;
283 #define AMT_SOURCE_OLD 0
284 #define AMT_SOURCE_NEW 1
289 /* Protected by amt_tunnel_list->lock */
290 struct amt_group_node {
292 union amt_addr group_addr;
293 union amt_addr host_addr;
297 struct amt_tunnel_list *tunnel_list;
298 struct hlist_node node;
299 struct delayed_work group_timer;
301 struct hlist_head sources[];
304 #define AMT_MAX_EVENTS 16
306 enum amt_event event;
311 struct net_device *dev;
312 struct net_device *stream_dev;
314 /* Global lock for amt device */
316 /* Used only in relay mode */
317 struct list_head tunnel_list;
318 struct gro_cells gro_cells;
320 /* Protected by RTNL */
321 struct delayed_work discovery_wq;
322 /* Protected by RTNL */
323 struct delayed_work req_wq;
324 /* Protected by RTNL */
325 struct delayed_work secret_wq;
326 struct work_struct event_wq;
328 enum amt_status status;
331 struct socket __rcu *sock;
340 /* Gateway or Relay mode */
348 /* Outer remote ip */
350 /* Outer discovery ip */
352 /* Only used in gateway mode */
354 /* Gateway sent request and received query */
361 /* Used only in gateway mode */
364 /* AMT gateway side message handler queue */
365 struct amt_events events[AMT_MAX_EVENTS];
371 #define AMT_IPHDR_OPTS 4
372 #define AMT_IP6HDR_OPTS 8
373 #define AMT_GC_INTERVAL (30 * 1000)
374 #define AMT_MAX_GROUP 32
375 #define AMT_MAX_SOURCE 128
376 #define AMT_HSIZE_SHIFT 8
377 #define AMT_HSIZE (1 << AMT_HSIZE_SHIFT)
379 #define AMT_DISCOVERY_TIMEOUT 5000
380 #define AMT_INIT_REQ_TIMEOUT 1
381 #define AMT_INIT_QUERY_INTERVAL 125
382 #define AMT_MAX_REQ_TIMEOUT 120
383 #define AMT_MAX_REQ_COUNT 3
384 #define AMT_SECRET_TIMEOUT 60000
385 #define IANA_AMT_UDP_PORT 2268
386 #define AMT_MAX_TUNNELS 128
387 #define AMT_MAX_REQS 128
388 #define AMT_GW_HLEN (sizeof(struct iphdr) + \
389 sizeof(struct udphdr) + \
390 sizeof(struct amt_gw_headers))
391 #define AMT_RELAY_HLEN (sizeof(struct iphdr) + \
392 sizeof(struct udphdr) + \
393 sizeof(struct amt_relay_headers))
395 static inline bool netif_is_amt(const struct net_device *dev)
397 return dev->rtnl_link_ops && !strcmp(dev->rtnl_link_ops->kind, "amt");
400 static inline u64 amt_gmi(const struct amt_dev *amt)
402 return ((amt->qrv * amt->qi) + amt->qri) * 1000;
405 #endif /* _NET_AMT_H_ */