1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
8 enum peer_endpoint_type
{
11 ENDPOINT_TYPE_ENDPOINT_NOTIFY
,
12 ENDPOINT_TYPE_ENDPOINT_PORT_NOTIFY
,
17 struct vlist_node node
;
18 uint8_t key
[CURVE25519_KEY_SIZE
];
19 union network_addr local_addr
;
21 struct blob_attr
*ipaddr
;
22 struct blob_attr
*subnet
;
32 bool has_local_ep_addr
;
34 union network_addr local_ep_addr
;
35 union network_endpoint endpoint
;
37 uint8_t next_endpoint_idx
;
38 union network_endpoint next_endpoint
[__ENDPOINT_TYPE_MAX
];
39 uint64_t last_ep_update
;
42 uint64_t last_handshake
;
43 uint64_t last_request
;
44 uint64_t last_query_sent
;
51 struct network_dynamic_peer
{
52 struct list_head list
;
54 struct network_peer peer
;
61 struct network_peer peer
;
64 struct network_group
{
69 struct network_host
**members
;
72 static inline const char *network_host_name(struct network_host
*host
)
77 return host
->node
.key
;
80 static inline bool network_host_is_peer(struct network_host
*host
)
82 return !!host
->peer
.node
.avl
.key
;
85 static inline const char *network_peer_name(struct network_peer
*peer
)
87 struct network_host
*host
;
89 if (!peer
|| peer
->dynamic
)
92 host
= container_of(peer
, struct network_host
, peer
);
93 return network_host_name(host
);
98 network_host_uses_peer_route(struct network_host
*host
, struct network
*net
,
99 struct network_peer
*peer
)
101 if (&host
->peer
== peer
|| host
== net
->net_config
.local_host
)
104 if (net
->net_config
.local_host
->gateway
&&
105 !strcmp(net
->net_config
.local_host
->gateway
, network_peer_name(peer
)))
111 return !strcmp(host
->gateway
, network_peer_name(peer
));
114 #define for_each_routed_host(cur_host, net, peer) \
115 avl_for_each_element(&(net)->hosts, cur_host, node) \
116 if (network_host_uses_peer_route(host, net, peer))
119 void network_hosts_update_start(struct network
*net
);
120 void network_hosts_update_done(struct network
*net
);
121 void network_hosts_add(struct network
*net
, struct blob_attr
*hosts
);
122 void network_hosts_reload_dynamic_peers(struct network
*net
);
124 void network_hosts_init(struct network
*net
);
125 void network_hosts_free(struct network
*net
);