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
;
31 bool has_local_ep_addr
;
33 union network_addr local_ep_addr
;
34 union network_endpoint endpoint
;
36 uint8_t next_endpoint_idx
;
37 union network_endpoint next_endpoint
[__ENDPOINT_TYPE_MAX
];
38 uint64_t last_ep_update
;
41 uint64_t last_handshake
;
42 uint64_t last_request
;
43 uint64_t last_query_sent
;
50 struct network_dynamic_peer
{
51 struct list_head list
;
53 struct network_peer peer
;
60 struct network_peer peer
;
63 struct network_group
{
68 struct network_host
**members
;
71 static inline const char *network_host_name(struct network_host
*host
)
76 return host
->node
.key
;
79 static inline bool network_host_is_peer(struct network_host
*host
)
81 return !!host
->peer
.node
.avl
.key
;
84 static inline const char *network_peer_name(struct network_peer
*peer
)
86 struct network_host
*host
;
88 if (!peer
|| peer
->dynamic
)
91 host
= container_of(peer
, struct network_host
, peer
);
92 return network_host_name(host
);
97 network_host_uses_peer_route(struct network_host
*host
, struct network
*net
,
98 struct network_peer
*peer
)
100 if (&host
->peer
== peer
|| host
== net
->net_config
.local_host
)
103 if (net
->net_config
.local_host
->gateway
&&
104 !strcmp(net
->net_config
.local_host
->gateway
, network_peer_name(peer
)))
110 return !strcmp(host
->gateway
, network_peer_name(peer
));
113 #define for_each_routed_host(cur_host, net, peer) \
114 avl_for_each_element(&(net)->hosts, cur_host, node) \
115 if (network_host_uses_peer_route(host, net, peer))
118 void network_hosts_update_start(struct network
*net
);
119 void network_hosts_update_done(struct network
*net
);
120 void network_hosts_add(struct network
*net
, struct blob_attr
*hosts
);
121 void network_hosts_reload_dynamic_peers(struct network
*net
);
123 void network_hosts_init(struct network
*net
);
124 void network_hosts_free(struct network
*net
);