Changeset View
Changeset View
Standalone View
Standalone View
lib/libpfctl/libpfctl.c
Show First 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | pf_nvrule_addr_to_rule_addr(const nvlist_t *nvl, struct pf_rule_addr *addr) | ||||
pf_nvaddr_wrap_to_addr_wrap(nvlist_get_nvlist(nvl, "addr"), &addr->addr); | pf_nvaddr_wrap_to_addr_wrap(nvlist_get_nvlist(nvl, "addr"), &addr->addr); | ||||
pf_nvuint_16_array(nvl, "port", 2, addr->port, NULL); | pf_nvuint_16_array(nvl, "port", 2, addr->port, NULL); | ||||
addr->neg = nvlist_get_number(nvl, "neg"); | addr->neg = nvlist_get_number(nvl, "neg"); | ||||
addr->port_op = nvlist_get_number(nvl, "port_op"); | addr->port_op = nvlist_get_number(nvl, "port_op"); | ||||
} | } | ||||
static void | static void | ||||
pfctl_nv_add_mape(nvlist_t *nvparent, const char *name, | |||||
const struct pf_mape_portset *mape) | |||||
{ | |||||
nvlist_t *nvl = nvlist_create(0); | |||||
nvlist_add_number(nvl, "offset", mape->offset); | |||||
nvlist_add_number(nvl, "psidlen", mape->psidlen); | |||||
nvlist_add_number(nvl, "psid", mape->psid); | |||||
nvlist_add_nvlist(nvparent, name, nvl); | |||||
} | |||||
static void | |||||
pfctl_nv_add_pool(nvlist_t *nvparent, const char *name, | pfctl_nv_add_pool(nvlist_t *nvparent, const char *name, | ||||
const struct pfctl_pool *pool) | const struct pfctl_pool *pool) | ||||
{ | { | ||||
u_int64_t ports[2]; | u_int64_t ports[2]; | ||||
nvlist_t *nvl = nvlist_create(0); | nvlist_t *nvl = nvlist_create(0); | ||||
nvlist_add_binary(nvl, "key", &pool->key, sizeof(pool->key)); | nvlist_add_binary(nvl, "key", &pool->key, sizeof(pool->key)); | ||||
pfctl_nv_add_addr(nvl, "counter", &pool->counter); | pfctl_nv_add_addr(nvl, "counter", &pool->counter); | ||||
nvlist_add_number(nvl, "tblidx", pool->tblidx); | nvlist_add_number(nvl, "tblidx", pool->tblidx); | ||||
ports[0] = pool->proxy_port[0]; | ports[0] = pool->proxy_port[0]; | ||||
ports[1] = pool->proxy_port[1]; | ports[1] = pool->proxy_port[1]; | ||||
nvlist_add_number_array(nvl, "proxy_port", ports, 2); | nvlist_add_number_array(nvl, "proxy_port", ports, 2); | ||||
nvlist_add_number(nvl, "opts", pool->opts); | nvlist_add_number(nvl, "opts", pool->opts); | ||||
pfctl_nv_add_mape(nvl, "mape", &pool->mape); | |||||
nvlist_add_nvlist(nvparent, name, nvl); | nvlist_add_nvlist(nvparent, name, nvl); | ||||
} | } | ||||
static void | static void | ||||
pf_nvmape_to_mape(const nvlist_t *nvl, struct pf_mape_portset *mape) | |||||
{ | |||||
mape->offset = nvlist_get_number(nvl, "offset"); | |||||
mape->psidlen = nvlist_get_number(nvl, "psidlen"); | |||||
mape->psid = nvlist_get_number(nvl, "psid"); | |||||
} | |||||
static void | |||||
pf_nvpool_to_pool(const nvlist_t *nvl, struct pfctl_pool *pool) | pf_nvpool_to_pool(const nvlist_t *nvl, struct pfctl_pool *pool) | ||||
{ | { | ||||
size_t len; | size_t len; | ||||
const void *data; | const void *data; | ||||
data = nvlist_get_binary(nvl, "key", &len); | data = nvlist_get_binary(nvl, "key", &len); | ||||
assert(len == sizeof(pool->key)); | assert(len == sizeof(pool->key)); | ||||
memcpy(&pool->key, data, len); | memcpy(&pool->key, data, len); | ||||
pf_nvaddr_to_addr(nvlist_get_nvlist(nvl, "counter"), &pool->counter); | pf_nvaddr_to_addr(nvlist_get_nvlist(nvl, "counter"), &pool->counter); | ||||
pool->tblidx = nvlist_get_number(nvl, "tblidx"); | pool->tblidx = nvlist_get_number(nvl, "tblidx"); | ||||
pf_nvuint_16_array(nvl, "proxy_port", 2, pool->proxy_port, NULL); | pf_nvuint_16_array(nvl, "proxy_port", 2, pool->proxy_port, NULL); | ||||
pool->opts = nvlist_get_number(nvl, "opts"); | pool->opts = nvlist_get_number(nvl, "opts"); | ||||
if (nvlist_exists_nvlist(nvl, "mape")) | |||||
pf_nvmape_to_mape(nvlist_get_nvlist(nvl, "mape"), &pool->mape); | |||||
kp: I think I'd prefer this to be a sub-nvlist with three separate numbers, but that's a nitpick… | |||||
Done Inline ActionsIndeed I feel it's ugly. takahiro.kurosawa_gmail.com: Indeed I feel it's ugly.
I'll add a "mape" nvlist node and add three integers under it as you… | |||||
} | } | ||||
static void | static void | ||||
pfctl_nv_add_uid(nvlist_t *nvparent, const char *name, | pfctl_nv_add_uid(nvlist_t *nvparent, const char *name, | ||||
const struct pf_rule_uid *uid) | const struct pf_rule_uid *uid) | ||||
{ | { | ||||
u_int64_t uids[2]; | u_int64_t uids[2]; | ||||
nvlist_t *nvl = nvlist_create(0); | nvlist_t *nvl = nvlist_create(0); | ||||
▲ Show 20 Lines • Show All 296 Lines • Show Last 20 Lines |
I think I'd prefer this to be a sub-nvlist with three separate numbers, but that's a nitpick more than a genuine criticism.
It'd be easier to add extra settings that way, but perhaps that's not realistically going to be needed. You probably have a better view of that than I do.