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>
14 struct network_pex_host
{
15 struct list_head list
;
18 union network_endpoint endpoint
;
23 struct list_head hosts
;
24 struct uloop_timeout request_update_timer
;
27 enum network_stun_state
{
29 STUN_STATE_PEX_QUERY_WAIT
,
30 STUN_STATE_STUN_QUERY_SEND
,
31 STUN_STATE_STUN_QUERY_WAIT
,
34 struct network_stun_server
{
35 struct list_head list
;
37 struct avl_node pending_node
;
38 struct stun_request req
;
47 struct list_head servers
;
48 struct avl_tree pending
;
50 struct uloop_timeout timer
;
52 enum network_stun_state state
;
55 uint16_t auth_port_ext
;
61 struct uloop_fd socket
;
66 PEX_EV_ENDPOINT_CHANGE
,
71 void network_pex_init(struct network
*net
);
72 int network_pex_open(struct network
*net
);
73 void network_pex_close(struct network
*net
);
74 void network_pex_free(struct network
*net
);
76 void network_pex_event(struct network
*net
, struct network_peer
*peer
,
78 void network_pex_create_host(struct network
*net
, union network_endpoint
*ep
,
79 unsigned int timeout
);
81 void network_stun_init(struct network
*net
);
82 void network_stun_free(struct network
*net
);
83 void network_stun_server_add(struct network
*net
, const char *host
);
84 void network_stun_rx_packet(struct network
*net
, const void *data
, size_t len
);
85 void network_stun_update_port(struct network
*net
, bool auth
, uint16_t val
);
86 void network_stun_start(struct network
*net
);
88 static inline bool network_pex_active(struct network_pex
*pex
)
90 return pex
->fd
.fd
>= 0;
93 int global_pex_open(const char *unix_path
);