Changeset View
Changeset View
Standalone View
Standalone View
lib/libpfctl/libpfctl.c
Show First 20 Lines • Show All 600 Lines • ▼ Show 20 Lines | pfctl_nveth_rule_to_eth_rule(const nvlist_t *nvl, struct pfctl_eth_rule *rule) | ||||
strlcpy(rule->qname, nvlist_get_string(nvl, "qname"), PF_QNAME_SIZE); | strlcpy(rule->qname, nvlist_get_string(nvl, "qname"), PF_QNAME_SIZE); | ||||
strlcpy(rule->tagname, nvlist_get_string(nvl, "tagname"), | strlcpy(rule->tagname, nvlist_get_string(nvl, "tagname"), | ||||
PF_TAG_NAME_SIZE); | PF_TAG_NAME_SIZE); | ||||
rule->dnpipe = nvlist_get_number(nvl, "dnpipe"); | rule->dnpipe = nvlist_get_number(nvl, "dnpipe"); | ||||
rule->dnflags = nvlist_get_number(nvl, "dnflags"); | rule->dnflags = nvlist_get_number(nvl, "dnflags"); | ||||
rule->anchor_relative = nvlist_get_number(nvl, "anchor_relative"); | |||||
rule->anchor_wildcard = nvlist_get_number(nvl, "anchor_wildcard"); | |||||
rule->action = nvlist_get_number(nvl, "action"); | rule->action = nvlist_get_number(nvl, "action"); | ||||
} | } | ||||
int | int | ||||
pfctl_get_eth_rules_info(int dev, struct pfctl_eth_rules_info *rules) | pfctl_get_eth_rules_info(int dev, struct pfctl_eth_rules_info *rules, | ||||
const char *path) | |||||
{ | { | ||||
uint8_t buf[1024]; | uint8_t buf[1024]; | ||||
struct pfioc_nv nv; | struct pfioc_nv nv; | ||||
nvlist_t *nvl; | nvlist_t *nvl; | ||||
void *packed; | |||||
size_t len; | |||||
bzero(rules, sizeof(*rules)); | bzero(rules, sizeof(*rules)); | ||||
nvl = nvlist_create(0); | |||||
nvlist_add_string(nvl, "anchor", path); | |||||
packed = nvlist_pack(nvl, &len); | |||||
memcpy(buf, packed, len); | |||||
free(packed); | |||||
nvlist_destroy(nvl); | |||||
nv.data = buf; | nv.data = buf; | ||||
nv.len = nv.size = sizeof(buf); | nv.len = len; | ||||
nv.size = sizeof(buf); | |||||
if (ioctl(dev, DIOCGETETHRULES, &nv) != 0) | if (ioctl(dev, DIOCGETETHRULES, &nv) != 0) | ||||
return (errno); | return (errno); | ||||
nvl = nvlist_unpack(buf, nv.len, 0); | nvl = nvlist_unpack(buf, nv.len, 0); | ||||
if (nvl == NULL) | if (nvl == NULL) | ||||
return (EIO); | return (EIO); | ||||
rules->nr = nvlist_get_number(nvl, "nr"); | rules->nr = nvlist_get_number(nvl, "nr"); | ||||
rules->ticket = nvlist_get_number(nvl, "ticket"); | rules->ticket = nvlist_get_number(nvl, "ticket"); | ||||
nvlist_destroy(nvl); | nvlist_destroy(nvl); | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
pfctl_get_eth_rule(int dev, uint32_t nr, uint32_t ticket, | pfctl_get_eth_rule(int dev, uint32_t nr, uint32_t ticket, | ||||
struct pfctl_eth_rule *rule, bool clear) | const char *path, struct pfctl_eth_rule *rule, bool clear, | ||||
char *anchor_call) | |||||
{ | { | ||||
uint8_t buf[1024]; | uint8_t buf[1024]; | ||||
struct pfioc_nv nv; | struct pfioc_nv nv; | ||||
nvlist_t *nvl; | nvlist_t *nvl; | ||||
void *data; | void *data; | ||||
size_t len; | size_t len; | ||||
nvl = nvlist_create(0); | nvl = nvlist_create(0); | ||||
nvlist_add_string(nvl, "anchor", path); | |||||
nvlist_add_number(nvl, "ticket", ticket); | nvlist_add_number(nvl, "ticket", ticket); | ||||
nvlist_add_number(nvl, "nr", nr); | nvlist_add_number(nvl, "nr", nr); | ||||
nvlist_add_bool(nvl, "clear", clear); | nvlist_add_bool(nvl, "clear", clear); | ||||
data = nvlist_pack(nvl, &len); | data = nvlist_pack(nvl, &len); | ||||
nv.data = buf; | nv.data = buf; | ||||
memcpy(buf, data, len); | memcpy(buf, data, len); | ||||
free(data); | free(data); | ||||
nv.len = len; | nv.len = len; | ||||
nv.size = sizeof(buf); | nv.size = sizeof(buf); | ||||
if (ioctl(dev, DIOCGETETHRULE, &nv)) { | if (ioctl(dev, DIOCGETETHRULE, &nv)) { | ||||
nvlist_destroy(nvl); | nvlist_destroy(nvl); | ||||
return (errno); | return (errno); | ||||
} | } | ||||
nvlist_destroy(nvl); | nvlist_destroy(nvl); | ||||
nvl = nvlist_unpack(buf, nv.len, 0); | nvl = nvlist_unpack(buf, nv.len, 0); | ||||
if (nvl == NULL) { | if (nvl == NULL) { | ||||
return (EIO); | return (EIO); | ||||
} | } | ||||
pfctl_nveth_rule_to_eth_rule(nvl, rule); | pfctl_nveth_rule_to_eth_rule(nvl, rule); | ||||
if (anchor_call) | |||||
strlcpy(anchor_call, nvlist_get_string(nvl, "anchor_call"), | |||||
MAXPATHLEN); | |||||
nvlist_destroy(nvl); | nvlist_destroy(nvl); | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
pfctl_add_eth_rule(int dev, const struct pfctl_eth_rule *r, uint32_t ticket) | pfctl_add_eth_rule(int dev, const struct pfctl_eth_rule *r, const char *anchor, | ||||
const char *anchor_call, uint32_t ticket) | |||||
{ | { | ||||
struct pfioc_nv nv; | struct pfioc_nv nv; | ||||
nvlist_t *nvl, *addr; | nvlist_t *nvl, *addr; | ||||
void *packed; | void *packed; | ||||
int error; | int error; | ||||
size_t size; | size_t size; | ||||
nvl = nvlist_create(0); | nvl = nvlist_create(0); | ||||
nvlist_add_number(nvl, "ticket", ticket); | nvlist_add_number(nvl, "ticket", ticket); | ||||
nvlist_add_string(nvl, "anchor", anchor); | |||||
nvlist_add_string(nvl, "anchor_call", anchor_call); | |||||
nvlist_add_number(nvl, "nr", r->nr); | nvlist_add_number(nvl, "nr", r->nr); | ||||
nvlist_add_bool(nvl, "quick", r->quick); | nvlist_add_bool(nvl, "quick", r->quick); | ||||
nvlist_add_string(nvl, "ifname", r->ifname); | nvlist_add_string(nvl, "ifname", r->ifname); | ||||
nvlist_add_bool(nvl, "ifnot", r->ifnot); | nvlist_add_bool(nvl, "ifnot", r->ifnot); | ||||
nvlist_add_number(nvl, "direction", r->direction); | nvlist_add_number(nvl, "direction", r->direction); | ||||
nvlist_add_number(nvl, "proto", r->proto); | nvlist_add_number(nvl, "proto", r->proto); | ||||
▲ Show 20 Lines • Show All 541 Lines • Show Last 20 Lines |