1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
8 #include <sys/socket.h>
9 #include <libubox/uloop.h>
12 #define NETWORK_PEX_HOSTS_LIMIT 128
16 struct network_pex_host
{
17 struct list_head list
;
21 union network_endpoint endpoint
;
26 struct list_head hosts
;
28 struct uloop_timeout request_update_timer
;
31 enum network_stun_state
{
33 STUN_STATE_PEX_QUERY_WAIT
,
34 STUN_STATE_STUN_QUERY_SEND
,
35 STUN_STATE_STUN_QUERY_WAIT
,
38 struct network_stun_server
{
39 struct list_head list
;
41 struct avl_node pending_node
;
42 struct stun_request req
;
51 struct list_head servers
;
52 struct avl_tree pending
;
54 struct uloop_timeout timer
;
56 enum network_stun_state state
;
59 uint16_t auth_port_ext
;
65 struct uloop_fd socket
;
70 PEX_EV_ENDPOINT_CHANGE
,
75 void network_pex_init(struct network
*net
);
76 int network_pex_open(struct network
*net
);
77 void network_pex_close(struct network
*net
);
78 void network_pex_free(struct network
*net
);
80 void network_pex_event(struct network
*net
, struct network_peer
*peer
,
82 void network_pex_create_host(struct network
*net
, union network_endpoint
*ep
,
83 unsigned int timeout
);
85 void network_stun_init(struct network
*net
);
86 void network_stun_free(struct network
*net
);
87 void network_stun_server_add(struct network
*net
, const char *host
);
88 void network_stun_rx_packet(struct network
*net
, const void *data
, size_t len
);
89 void network_stun_update_port(struct network
*net
, bool auth
, uint16_t val
);
90 void network_stun_start(struct network
*net
);
92 static inline bool network_pex_active(struct network_pex
*pex
)
94 return pex
->fd
.fd
>= 0;
97 int global_pex_open(const char *unix_path
);