Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/if_wg/module/module.c
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
MALLOC_DEFINE(M_WG, "WG", "wireguard"); | MALLOC_DEFINE(M_WG, "WG", "wireguard"); | ||||
#define WG_CAPS IFCAP_LINKSTATE | #define WG_CAPS IFCAP_LINKSTATE | ||||
#define ph_family PH_loc.eight[5] | #define ph_family PH_loc.eight[5] | ||||
TASKQGROUP_DECLARE(if_io_tqg); | TASKQGROUP_DECLARE(if_io_tqg); | ||||
struct wg_timespec64 { | |||||
uint64_t tv_sec; | |||||
uint64_t tv_nsec; | |||||
}; | |||||
struct wg_peer_export { | struct wg_peer_export { | ||||
struct sockaddr_storage endpoint; | struct sockaddr_storage endpoint; | ||||
struct timespec last_handshake; | |||||
uint8_t public_key[WG_KEY_SIZE]; | uint8_t public_key[WG_KEY_SIZE]; | ||||
size_t endpoint_sz; | size_t endpoint_sz; | ||||
struct wg_allowedip *aip; | struct wg_allowedip *aip; | ||||
uint64_t rx_bytes; | |||||
uint64_t tx_bytes; | |||||
int aip_count; | int aip_count; | ||||
uint16_t persistent_keepalive; | uint16_t persistent_keepalive; | ||||
}; | }; | ||||
static int clone_count; | static int clone_count; | ||||
uma_zone_t ratelimit_zone; | uma_zone_t ratelimit_zone; | ||||
void | void | ||||
▲ Show 20 Lines • Show All 329 Lines • ▼ Show 20 Lines | if (ep->e_remote.r_sa.sa_family != 0) { | ||||
memcpy(&exp->endpoint, &ep->e_remote, exp->endpoint_sz); | memcpy(&exp->endpoint, &ep->e_remote, exp->endpoint_sz); | ||||
} | } | ||||
memcpy(exp->public_key, peer->p_remote.r_public, | memcpy(exp->public_key, peer->p_remote.r_public, | ||||
sizeof(exp->public_key)); | sizeof(exp->public_key)); | ||||
exp->persistent_keepalive = | exp->persistent_keepalive = | ||||
peer->p_timers.t_persistent_keepalive_interval; | peer->p_timers.t_persistent_keepalive_interval; | ||||
wg_timers_get_last_handshake(&peer->p_timers, &exp->last_handshake); | |||||
exp->rx_bytes = counter_u64_fetch(peer->p_rx_bytes); | |||||
exp->tx_bytes = counter_u64_fetch(peer->p_tx_bytes); | |||||
exp->aip_count = 0; | exp->aip_count = 0; | ||||
CK_LIST_FOREACH(rt, &peer->p_routes, r_entry) { | CK_LIST_FOREACH(rt, &peer->p_routes, r_entry) { | ||||
exp->aip_count++; | exp->aip_count++; | ||||
} | } | ||||
/* Early success; no allowed-ips to copy out. */ | /* Early success; no allowed-ips to copy out. */ | ||||
if (exp->aip_count == 0) | if (exp->aip_count == 0) | ||||
Show All 14 Lines | wg_peer_to_export(struct wg_peer *peer, struct wg_peer_export *exp) | ||||
exp->aip_count = i; | exp->aip_count = i; | ||||
return (0); | return (0); | ||||
} | } | ||||
static nvlist_t * | static nvlist_t * | ||||
wg_peer_export_to_nvl(struct wg_peer_export *exp) | wg_peer_export_to_nvl(struct wg_peer_export *exp) | ||||
{ | { | ||||
struct wg_timespec64 ts64; | |||||
nvlist_t *nvl; | nvlist_t *nvl; | ||||
if ((nvl = nvlist_create(0)) == NULL) | if ((nvl = nvlist_create(0)) == NULL) | ||||
return (NULL); | return (NULL); | ||||
nvlist_add_binary(nvl, "public-key", exp->public_key, WG_KEY_SIZE); | nvlist_add_binary(nvl, "public-key", exp->public_key, WG_KEY_SIZE); | ||||
if (exp->endpoint_sz != 0) | if (exp->endpoint_sz != 0) | ||||
nvlist_add_binary(nvl, "endpoint", &exp->endpoint, | nvlist_add_binary(nvl, "endpoint", &exp->endpoint, | ||||
exp->endpoint_sz); | exp->endpoint_sz); | ||||
nvlist_add_binary(nvl, "allowed-ips", exp->aip, | nvlist_add_binary(nvl, "allowed-ips", exp->aip, | ||||
exp->aip_count * sizeof(*exp->aip)); | exp->aip_count * sizeof(*exp->aip)); | ||||
ts64.tv_sec = exp->last_handshake.tv_sec; | |||||
ts64.tv_nsec = exp->last_handshake.tv_nsec; | |||||
nvlist_add_binary(nvl, "last_handshake", &ts64, sizeof(ts64)); | |||||
if (exp->persistent_keepalive != 0) | if (exp->persistent_keepalive != 0) | ||||
nvlist_add_number(nvl, "persistent-keepalive-interval", | nvlist_add_number(nvl, "persistent-keepalive-interval", | ||||
exp->persistent_keepalive); | exp->persistent_keepalive); | ||||
if (exp->rx_bytes != 0) | |||||
nvlist_add_number(nvl, "rx_bytes", exp->rx_bytes); | |||||
if (exp->tx_bytes != 0) | |||||
markj: Why is this conditional? | |||||
Done Inline ActionsMy working thought process was to avoid the nvpair allocation since the wg(8) side will assume '0' if these are omitted -- their absence is insignificant. kevans: My working thought process was to avoid the nvpair allocation since the wg(8) side will assume… | |||||
nvlist_add_number(nvl, "tx_bytes", exp->tx_bytes); | |||||
return (nvl); | return (nvl); | ||||
} | } | ||||
static int | static int | ||||
wg_marshal_peers(struct wg_softc *sc, nvlist_t **nvlp, nvlist_t ***nvl_arrayp, int *peer_countp) | wg_marshal_peers(struct wg_softc *sc, nvlist_t **nvlp, nvlist_t ***nvl_arrayp, int *peer_countp) | ||||
{ | { | ||||
struct wg_peer *peer; | struct wg_peer *peer; | ||||
▲ Show 20 Lines • Show All 458 Lines • Show Last 20 Lines |
Why is this conditional?