1 /* SPDX-License-Identifier: GPL-2.0+ */
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)
82 #if defined(__LITTLE_ENDIAN_BITFIELD)
85 #elif defined(__BIG_ENDIAN_BITFIELD)
89 #error "Please fix <asm/byteorder.h>"
93 struct amt_header_discovery {
94 #if defined(__LITTLE_ENDIAN_BITFIELD)
98 #elif defined(__BIG_ENDIAN_BITFIELD)
103 #error "Please fix <asm/byteorder.h>"
108 struct amt_header_advertisement {
109 #if defined(__LITTLE_ENDIAN_BITFIELD)
113 #elif defined(__BIG_ENDIAN_BITFIELD)
118 #error "Please fix <asm/byteorder.h>"
124 struct amt_header_request {
125 #if defined(__LITTLE_ENDIAN_BITFIELD)
131 #elif defined(__BIG_ENDIAN_BITFIELD)
138 #error "Please fix <asm/byteorder.h>"
143 struct amt_header_membership_query {
144 #if defined(__LITTLE_ENDIAN_BITFIELD)
151 #elif defined(__BIG_ENDIAN_BITFIELD)
159 #error "Please fix <asm/byteorder.h>"
164 struct amt_header_membership_update {
165 #if defined(__LITTLE_ENDIAN_BITFIELD)
170 #elif defined(__BIG_ENDIAN_BITFIELD)
176 #error "Please fix <asm/byteorder.h>"
181 struct amt_header_mcast_data {
182 #if defined(__LITTLE_ENDIAN_BITFIELD)
186 #elif defined(__BIG_ENDIAN_BITFIELD)
191 #error "Please fix <asm/byteorder.h>"
197 struct amt_header_discovery discovery;
198 struct amt_header_advertisement advertisement;
199 struct amt_header_request request;
200 struct amt_header_membership_query query;
201 struct amt_header_membership_update update;
202 struct amt_header_mcast_data data;
206 struct amt_gw_headers {
208 struct amt_header_discovery discovery;
209 struct amt_header_request request;
210 struct amt_header_membership_update update;
214 struct amt_relay_headers {
216 struct amt_header_advertisement advertisement;
217 struct amt_header_membership_query query;
218 struct amt_header_mcast_data data;
223 struct amt_tunnel_list *tunnel;
226 struct amt_tunnel_list {
227 struct list_head list;
228 /* Protect All resources under an amt_tunne_list */
233 enum amt_status status;
234 struct delayed_work gc_wq;
242 struct hlist_head groups[];
247 #if IS_ENABLED(CONFIG_IPV6)
254 * When the router is in EXCLUDE mode, the router state is represented
255 * by the notation EXCLUDE (X,Y), where X is called the "Requested List"
256 * and Y is called the "Exclude List". All sources, except those from
257 * the Exclude List, will be forwarded by the router
259 enum amt_source_status {
260 AMT_SOURCE_STATUS_NONE,
261 /* Node of Requested List */
262 AMT_SOURCE_STATUS_FWD,
263 /* Node of Exclude List */
264 AMT_SOURCE_STATUS_D_FWD,
267 /* protected by gnode->lock */
268 struct amt_source_node {
269 struct hlist_node node;
270 struct amt_group_node *gnode;
271 struct delayed_work source_timer;
272 union amt_addr source_addr;
273 enum amt_source_status status;
274 #define AMT_SOURCE_OLD 0
275 #define AMT_SOURCE_NEW 1
280 /* Protected by amt_tunnel_list->lock */
281 struct amt_group_node {
283 union amt_addr group_addr;
284 union amt_addr host_addr;
288 struct amt_tunnel_list *tunnel_list;
289 struct hlist_node node;
290 struct delayed_work group_timer;
292 struct hlist_head sources[];
296 struct net_device *dev;
297 struct net_device *stream_dev;
299 /* Global lock for amt device */
301 /* Used only in relay mode */
302 struct list_head tunnel_list;
303 struct gro_cells gro_cells;
305 /* Protected by RTNL */
306 struct delayed_work discovery_wq;
307 /* Protected by RTNL */
308 struct delayed_work req_wq;
309 /* Protected by RTNL */
310 struct delayed_work secret_wq;
312 enum amt_status status;
315 struct socket __rcu *sock;
324 /* Gateway or Relay mode */
332 /* Outer remote ip */
334 /* Outer discovery ip */
336 /* Only used in gateway mode */
338 /* Gateway sent request and received query */
345 /* Used only in gateway mode */
351 #define AMT_IPHDR_OPTS 4
352 #define AMT_IP6HDR_OPTS 8
353 #define AMT_GC_INTERVAL (30 * 1000)
354 #define AMT_MAX_GROUP 32
355 #define AMT_MAX_SOURCE 128
356 #define AMT_HSIZE_SHIFT 8
357 #define AMT_HSIZE (1 << AMT_HSIZE_SHIFT)
359 #define AMT_DISCOVERY_TIMEOUT 5000
360 #define AMT_INIT_REQ_TIMEOUT 1
361 #define AMT_INIT_QUERY_INTERVAL 125
362 #define AMT_MAX_REQ_TIMEOUT 120
363 #define AMT_MAX_REQ_COUNT 3
364 #define AMT_SECRET_TIMEOUT 60000
365 #define IANA_AMT_UDP_PORT 2268
366 #define AMT_MAX_TUNNELS 128
367 #define AMT_MAX_REQS 128
368 #define AMT_GW_HLEN (sizeof(struct iphdr) + \
369 sizeof(struct udphdr) + \
370 sizeof(struct amt_gw_headers))
371 #define AMT_RELAY_HLEN (sizeof(struct iphdr) + \
372 sizeof(struct udphdr) + \
373 sizeof(struct amt_relay_headers))
375 static inline bool netif_is_amt(const struct net_device *dev)
377 return dev->rtnl_link_ops && !strcmp(dev->rtnl_link_ops->kind, "amt");
380 static inline u64 amt_gmi(const struct amt_dev *amt)
382 return ((amt->qrv * amt->qi) + amt->qri) * 1000;
385 #endif /* _NET_AMT_H_ */