Changeset View
Changeset View
Standalone View
Standalone View
sbin/ipfw/nat64lsn.c
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | static struct _s_x nat64cmds[] = { | ||||
{ "stats", TOK_STATS }, | { "stats", TOK_STATS }, | ||||
{ NULL, 0 } | { NULL, 0 } | ||||
}; | }; | ||||
static uint64_t | static uint64_t | ||||
nat64lsn_print_states(void *buf) | nat64lsn_print_states(void *buf) | ||||
{ | { | ||||
char s[INET6_ADDRSTRLEN], a[INET_ADDRSTRLEN], f[INET_ADDRSTRLEN]; | char s[INET6_ADDRSTRLEN], a[INET_ADDRSTRLEN], f[INET_ADDRSTRLEN]; | ||||
char sflags[4], *sf, *proto; | const char *proto; | ||||
char sflags[4], *sf; | |||||
ipfw_obj_header *oh; | ipfw_obj_header *oh; | ||||
ipfw_obj_data *od; | ipfw_obj_data *od; | ||||
ipfw_nat64lsn_stg_v1 *stg; | ipfw_nat64lsn_stg_v1 *stg; | ||||
ipfw_nat64lsn_state_v1 *ste; | ipfw_nat64lsn_state_v1 *ste; | ||||
uint64_t next_idx; | uint64_t next_idx; | ||||
int i, sz; | uint32_t i; | ||||
int sz; | |||||
oh = (ipfw_obj_header *)buf; | oh = (ipfw_obj_header *)buf; | ||||
od = (ipfw_obj_data *)(oh + 1); | od = (ipfw_obj_data *)(oh + 1); | ||||
stg = (ipfw_nat64lsn_stg_v1 *)(od + 1); | stg = (ipfw_nat64lsn_stg_v1 *)(od + 1); | ||||
sz = od->head.length - sizeof(*od); | sz = od->head.length - sizeof(*od); | ||||
next_idx = 0; | next_idx = 0; | ||||
while (sz > 0 && next_idx != 0xFF) { | while (sz > 0 && next_idx != 0xFF) { | ||||
next_idx = stg->next.index; | next_idx = stg->next.index; | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | |||||
#define nat64lsn_check_name table_check_name | #define nat64lsn_check_name table_check_name | ||||
void | void | ||||
ipfw_nat64lsn_handler(int ac, char *av[]) | ipfw_nat64lsn_handler(int ac, char *av[]) | ||||
{ | { | ||||
const char *name; | const char *name; | ||||
int tcmd; | int tcmd; | ||||
uint8_t set; | uint8_t set; | ||||
if (co.use_set != 0) | if (g_co.use_set != 0) | ||||
set = co.use_set - 1; | set = g_co.use_set - 1; | ||||
else | else | ||||
set = 0; | set = 0; | ||||
ac--; av++; | ac--; av++; | ||||
NEED1("nat64lsn needs instance name"); | NEED1("nat64lsn needs instance name"); | ||||
name = *av; | name = *av; | ||||
if (nat64lsn_check_name(name) != 0) { | if (nat64lsn_check_name(name) != 0) { | ||||
if (strcmp(name, "all") == 0) | if (strcmp(name, "all") == 0) | ||||
▲ Show 20 Lines • Show All 430 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
nat64lsn_stats(const char *name, uint8_t set) | nat64lsn_stats(const char *name, uint8_t set) | ||||
{ | { | ||||
struct ipfw_nat64lsn_stats stats; | struct ipfw_nat64lsn_stats stats; | ||||
if (nat64lsn_get_stats(name, set, &stats) != 0) | if (nat64lsn_get_stats(name, set, &stats) != 0) | ||||
err(EX_OSERR, "Error retrieving stats"); | err(EX_OSERR, "Error retrieving stats"); | ||||
if (co.use_set != 0 || set != 0) | if (g_co.use_set != 0 || set != 0) | ||||
printf("set %u ", set); | printf("set %u ", set); | ||||
printf("nat64lsn %s\n", name); | printf("nat64lsn %s\n", name); | ||||
printf("\t%ju packets translated from IPv6 to IPv4\n", | printf("\t%ju packets translated from IPv6 to IPv4\n", | ||||
(uintmax_t)stats.opcnt64); | (uintmax_t)stats.opcnt64); | ||||
printf("\t%ju packets translated from IPv4 to IPv6\n", | printf("\t%ju packets translated from IPv4 to IPv6\n", | ||||
(uintmax_t)stats.opcnt46); | (uintmax_t)stats.opcnt46); | ||||
printf("\t%ju IPv6 fragments created\n", | printf("\t%ju IPv6 fragments created\n", | ||||
(uintmax_t)stats.ofrags); | (uintmax_t)stats.ofrags); | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
nat64lsn_show_cb(ipfw_nat64lsn_cfg *cfg, const char *name, uint8_t set) | nat64lsn_show_cb(ipfw_nat64lsn_cfg *cfg, const char *name, uint8_t set) | ||||
{ | { | ||||
char abuf[INET6_ADDRSTRLEN]; | char abuf[INET6_ADDRSTRLEN]; | ||||
if (name != NULL && strcmp(cfg->name, name) != 0) | if (name != NULL && strcmp(cfg->name, name) != 0) | ||||
return (ESRCH); | return (ESRCH); | ||||
if (co.use_set != 0 && cfg->set != set) | if (g_co.use_set != 0 && cfg->set != set) | ||||
return (ESRCH); | return (ESRCH); | ||||
if (co.use_set != 0 || cfg->set != 0) | if (g_co.use_set != 0 || cfg->set != 0) | ||||
printf("set %u ", cfg->set); | printf("set %u ", cfg->set); | ||||
inet_ntop(AF_INET, &cfg->prefix4, abuf, sizeof(abuf)); | inet_ntop(AF_INET, &cfg->prefix4, abuf, sizeof(abuf)); | ||||
printf("nat64lsn %s prefix4 %s/%u", cfg->name, abuf, cfg->plen4); | printf("nat64lsn %s prefix4 %s/%u", cfg->name, abuf, cfg->plen4); | ||||
inet_ntop(AF_INET6, &cfg->prefix6, abuf, sizeof(abuf)); | inet_ntop(AF_INET6, &cfg->prefix6, abuf, sizeof(abuf)); | ||||
printf(" prefix6 %s/%u", abuf, cfg->plen6); | printf(" prefix6 %s/%u", abuf, cfg->plen6); | ||||
if (co.verbose || cfg->states_chunks > 1) | if (g_co.verbose || cfg->states_chunks > 1) | ||||
printf(" states_chunks %u", cfg->states_chunks); | printf(" states_chunks %u", cfg->states_chunks); | ||||
if (co.verbose || cfg->nh_delete_delay != NAT64LSN_HOST_AGE) | if (g_co.verbose || cfg->nh_delete_delay != NAT64LSN_HOST_AGE) | ||||
printf(" host_del_age %u", cfg->nh_delete_delay); | printf(" host_del_age %u", cfg->nh_delete_delay); | ||||
if (co.verbose || cfg->pg_delete_delay != NAT64LSN_PG_AGE) | if (g_co.verbose || cfg->pg_delete_delay != NAT64LSN_PG_AGE) | ||||
printf(" pg_del_age %u", cfg->pg_delete_delay); | printf(" pg_del_age %u", cfg->pg_delete_delay); | ||||
if (co.verbose || cfg->st_syn_ttl != NAT64LSN_TCP_SYN_AGE) | if (g_co.verbose || cfg->st_syn_ttl != NAT64LSN_TCP_SYN_AGE) | ||||
printf(" tcp_syn_age %u", cfg->st_syn_ttl); | printf(" tcp_syn_age %u", cfg->st_syn_ttl); | ||||
if (co.verbose || cfg->st_close_ttl != NAT64LSN_TCP_FIN_AGE) | if (g_co.verbose || cfg->st_close_ttl != NAT64LSN_TCP_FIN_AGE) | ||||
printf(" tcp_close_age %u", cfg->st_close_ttl); | printf(" tcp_close_age %u", cfg->st_close_ttl); | ||||
if (co.verbose || cfg->st_estab_ttl != NAT64LSN_TCP_EST_AGE) | if (g_co.verbose || cfg->st_estab_ttl != NAT64LSN_TCP_EST_AGE) | ||||
printf(" tcp_est_age %u", cfg->st_estab_ttl); | printf(" tcp_est_age %u", cfg->st_estab_ttl); | ||||
if (co.verbose || cfg->st_udp_ttl != NAT64LSN_UDP_AGE) | if (g_co.verbose || cfg->st_udp_ttl != NAT64LSN_UDP_AGE) | ||||
printf(" udp_age %u", cfg->st_udp_ttl); | printf(" udp_age %u", cfg->st_udp_ttl); | ||||
if (co.verbose || cfg->st_icmp_ttl != NAT64LSN_ICMP_AGE) | if (g_co.verbose || cfg->st_icmp_ttl != NAT64LSN_ICMP_AGE) | ||||
printf(" icmp_age %u", cfg->st_icmp_ttl); | printf(" icmp_age %u", cfg->st_icmp_ttl); | ||||
if (co.verbose || cfg->jmaxlen != NAT64LSN_JMAXLEN) | if (g_co.verbose || cfg->jmaxlen != NAT64LSN_JMAXLEN) | ||||
printf(" jmaxlen %u", cfg->jmaxlen); | printf(" jmaxlen %u", cfg->jmaxlen); | ||||
if (cfg->flags & NAT64_LOG) | if (cfg->flags & NAT64_LOG) | ||||
printf(" log"); | printf(" log"); | ||||
if (cfg->flags & NAT64_ALLOW_PRIVATE) | if (cfg->flags & NAT64_ALLOW_PRIVATE) | ||||
printf(" allow_private"); | printf(" allow_private"); | ||||
printf("\n"); | printf("\n"); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
nat64lsn_destroy_cb(ipfw_nat64lsn_cfg *cfg, const char *name, uint8_t set) | nat64lsn_destroy_cb(ipfw_nat64lsn_cfg *cfg, const char *name __unused, | ||||
uint8_t set) | |||||
{ | { | ||||
if (co.use_set != 0 && cfg->set != set) | if (g_co.use_set != 0 && cfg->set != set) | ||||
return (ESRCH); | return (ESRCH); | ||||
nat64lsn_destroy(cfg->name, cfg->set); | nat64lsn_destroy(cfg->name, cfg->set); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Compare nat64lsn instances names. | * Compare nat64lsn instances names. | ||||
* Honor number comparison. | * Honor number comparison. | ||||
*/ | */ | ||||
static int | static int | ||||
nat64name_cmp(const void *a, const void *b) | nat64name_cmp(const void *a, const void *b) | ||||
{ | { | ||||
ipfw_nat64lsn_cfg *ca, *cb; | const ipfw_nat64lsn_cfg *ca, *cb; | ||||
ca = (ipfw_nat64lsn_cfg *)a; | ca = (const ipfw_nat64lsn_cfg *)a; | ||||
cb = (ipfw_nat64lsn_cfg *)b; | cb = (const ipfw_nat64lsn_cfg *)b; | ||||
if (ca->set > cb->set) | if (ca->set > cb->set) | ||||
return (1); | return (1); | ||||
else if (ca->set < cb->set) | else if (ca->set < cb->set) | ||||
return (-1); | return (-1); | ||||
return (stringnum_cmp(ca->name, cb->name)); | return (stringnum_cmp(ca->name, cb->name)); | ||||
} | } | ||||
/* | /* | ||||
* Retrieves nat64lsn instance list from kernel, | * Retrieves nat64lsn instance list from kernel, | ||||
* optionally sorts it and calls requested function for each instance. | * optionally sorts it and calls requested function for each instance. | ||||
* | * | ||||
* Request: [ ipfw_obj_lheader ] | * Request: [ ipfw_obj_lheader ] | ||||
* Reply: [ ipfw_obj_lheader ipfw_nat64lsn_cfg x N ] | * Reply: [ ipfw_obj_lheader ipfw_nat64lsn_cfg x N ] | ||||
*/ | */ | ||||
static int | static int | ||||
nat64lsn_foreach(nat64lsn_cb_t *f, const char *name, uint8_t set, int sort) | nat64lsn_foreach(nat64lsn_cb_t *f, const char *name, uint8_t set, int sort) | ||||
{ | { | ||||
ipfw_obj_lheader *olh; | ipfw_obj_lheader *olh; | ||||
ipfw_nat64lsn_cfg *cfg; | ipfw_nat64lsn_cfg *cfg; | ||||
size_t sz; | size_t sz; | ||||
int i, error; | uint32_t i; | ||||
int error; | |||||
/* Start with reasonable default */ | /* Start with reasonable default */ | ||||
sz = sizeof(*olh) + 16 * sizeof(ipfw_nat64lsn_cfg); | sz = sizeof(*olh) + 16 * sizeof(ipfw_nat64lsn_cfg); | ||||
for (;;) { | for (;;) { | ||||
if ((olh = calloc(1, sz)) == NULL) | if ((olh = calloc(1, sz)) == NULL) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
Show All 25 Lines |