aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2025-01-03 22:25:10 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2025-01-03 22:25:10 +0000
commite9255dafa1ef0c635385aee78ead3a0050b19cca (patch)
treec402c97009096e22ba04002a3a6a6d1608188861
parent88766e7af52bbde32b14ad48fb76798a3ba4650c (diff)
pf: netlink KPI use cleanup
- use nlf_p_empty instead of declaring own empty array - don't declare _IN() macro when we don't parse a header Reviewed by: kp Differential Revision: https://reviews.freebsd.org/D48306
-rw-r--r--sys/netinet/ip_carp.c7
-rw-r--r--sys/netpfil/pf/pf_nl.c49
-rw-r--r--sys/netpfil/pf/pflow.c15
3 files changed, 15 insertions, 56 deletions
diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c
index 133dba45cf36..871638adb048 100644
--- a/sys/netinet/ip_carp.c
+++ b/sys/netinet/ip_carp.c
@@ -2803,9 +2803,7 @@ struct nl_carp_parsed {
uint16_t vrrp_adv_inter;
};
-#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct nl_carp_parsed, _field)
-
static const struct nlattr_parser nla_p_set[] = {
{ .type = CARP_NL_VHID, .off = _OUT(vhid), .cb = nlattr_get_uint32 },
{ .type = CARP_NL_STATE, .off = _OUT(state), .cb = nlattr_get_uint32 },
@@ -2820,10 +2818,7 @@ static const struct nlattr_parser nla_p_set[] = {
{ .type = CARP_NL_VRRP_PRIORITY, .off = _OUT(vrrp_prio), .cb = nlattr_get_uint8 },
{ .type = CARP_NL_VRRP_ADV_INTER, .off = _OUT(vrrp_adv_inter), .cb = nlattr_get_uint16 },
};
-static const struct nlfield_parser nlf_p_set[] = {
-};
-NL_DECLARE_PARSER(carp_parser, struct genlmsghdr, nlf_p_set, nla_p_set);
-#undef _IN
+NL_DECLARE_PARSER(carp_parser, struct genlmsghdr, nlf_p_empty, nla_p_set);
#undef _OUT
diff --git a/sys/netpfil/pf/pf_nl.c b/sys/netpfil/pf/pf_nl.c
index 79d6c380e31e..e586ad082e4b 100644
--- a/sys/netpfil/pf/pf_nl.c
+++ b/sys/netpfil/pf/pf_nl.c
@@ -746,7 +746,6 @@ struct nl_parsed_addrule {
char *anchor;
char *anchor_call;
};
-#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct nl_parsed_addrule, _field)
static const struct nlattr_parser nla_p_addrule[] = {
{ .type = PF_ART_TICKET, .off = _OUT(ticket), .cb = nlattr_get_uint32 },
@@ -755,11 +754,8 @@ static const struct nlattr_parser nla_p_addrule[] = {
{ .type = PF_ART_ANCHOR_CALL, .off = _OUT(anchor_call), .cb = nlattr_get_string },
{ .type = PF_ART_RULE, .off = _OUT(rule), .arg = &rule_parser, .cb = nlattr_get_nested_ptr }
};
-static const struct nlfield_parser nlf_p_addrule[] = {
-};
-#undef _IN
#undef _OUT
-NL_DECLARE_PARSER(addrule_parser, struct genlmsghdr, nlf_p_addrule, nla_p_addrule);
+NL_DECLARE_PARSER(addrule_parser, struct genlmsghdr, nlf_p_empty, nla_p_addrule);
static int
pf_handle_addrule(struct nlmsghdr *hdr, struct nl_pstate *npt)
@@ -782,17 +778,13 @@ pf_handle_addrule(struct nlmsghdr *hdr, struct nl_pstate *npt)
return (error);
}
-#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct pfioc_rule, _field)
static const struct nlattr_parser nla_p_getrules[] = {
{ .type = PF_GR_ANCHOR, .off = _OUT(anchor), .arg = (void *)MAXPATHLEN, .cb = nlattr_get_chara },
{ .type = PF_GR_ACTION, .off = _OUT(rule.action), .cb = nlattr_get_uint8 },
};
-static const struct nlfield_parser nlf_p_getrules[] = {
-};
-#undef _IN
#undef _OUT
-NL_DECLARE_PARSER(getrules_parser, struct genlmsghdr, nlf_p_getrules, nla_p_getrules);
+NL_DECLARE_PARSER(getrules_parser, struct genlmsghdr, nlf_p_empty, nla_p_getrules);
static int
pf_handle_getrules(struct nlmsghdr *hdr, struct nl_pstate *npt)
@@ -840,7 +832,6 @@ struct nl_parsed_get_rule {
uint32_t ticket;
uint8_t clear;
};
-#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct nl_parsed_get_rule, _field)
static const struct nlattr_parser nla_p_getrule[] = {
{ .type = PF_GR_ANCHOR, .off = _OUT(anchor), .arg = (void *)MAXPATHLEN, .cb = nlattr_get_chara },
@@ -849,11 +840,8 @@ static const struct nlattr_parser nla_p_getrule[] = {
{ .type = PF_GR_TICKET, .off = _OUT(ticket), .cb = nlattr_get_uint32 },
{ .type = PF_GR_CLEAR, .off = _OUT(clear), .cb = nlattr_get_uint8 },
};
-static const struct nlfield_parser nlf_p_getrule[] = {
-};
-#undef _IN
#undef _OUT
-NL_DECLARE_PARSER(getrule_parser, struct genlmsghdr, nlf_p_getrule, nla_p_getrule);
+NL_DECLARE_PARSER(getrule_parser, struct genlmsghdr, nlf_p_empty, nla_p_getrule);
static int
pf_handle_getrule(struct nlmsghdr *hdr, struct nl_pstate *npt)
@@ -1016,7 +1004,6 @@ out:
return (error);
}
-#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct pf_kstate_kill, _field)
static const struct nlattr_parser nla_p_clear_states[] = {
{ .type = PF_CS_CMP_ID, .off = _OUT(psk_pfcmp.id), .cb = nlattr_get_uint64 },
@@ -1032,10 +1019,8 @@ static const struct nlattr_parser nla_p_clear_states[] = {
{ .type = PF_CS_KILL_MATCH, .off = _OUT(psk_kill_match), .cb = nlattr_get_bool },
{ .type = PF_CS_NAT, .off = _OUT(psk_nat), .cb = nlattr_get_bool },
};
-static const struct nlfield_parser nlf_p_clear_states[] = {};
-#undef _IN
#undef _OUT
-NL_DECLARE_PARSER(clear_states_parser, struct genlmsghdr, nlf_p_clear_states, nla_p_clear_states);
+NL_DECLARE_PARSER(clear_states_parser, struct genlmsghdr, nlf_p_empty, nla_p_clear_states);
static int
pf_handle_killclear_states(struct nlmsghdr *hdr, struct nl_pstate *npt, int cmd)
@@ -1095,15 +1080,12 @@ pf_handle_kill_states(struct nlmsghdr *hdr, struct nl_pstate *npt)
struct nl_parsed_set_statusif {
char ifname[IFNAMSIZ];
};
-#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct nl_parsed_set_statusif, _field)
static const struct nlattr_parser nla_p_set_statusif[] = {
{ .type = PF_SS_IFNAME, .off = _OUT(ifname), .arg = (const void *)IFNAMSIZ, .cb = nlattr_get_chara },
};
-static const struct nlfield_parser nlf_p_set_statusif[] = {};
-#undef _IN
#undef _OUT
-NL_DECLARE_PARSER(set_statusif_parser, struct genlmsghdr, nlf_p_set_statusif, nla_p_set_statusif);
+NL_DECLARE_PARSER(set_statusif_parser, struct genlmsghdr, nlf_p_empty, nla_p_set_statusif);
static int
pf_handle_set_statusif(struct nlmsghdr *hdr, struct nl_pstate *npt)
@@ -1245,7 +1227,6 @@ struct pf_nl_natlook {
uint16_t dport;
};
-#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct pf_nl_natlook, _field)
static const struct nlattr_parser nla_p_natlook[] = {
{ .type = PF_NL_AF, .off = _OUT(af), .cb = nlattr_get_uint8 },
@@ -1256,10 +1237,8 @@ static const struct nlattr_parser nla_p_natlook[] = {
{ .type = PF_NL_SRC_PORT, .off = _OUT(sport), .cb = nlattr_get_uint16 },
{ .type = PF_NL_DST_PORT, .off = _OUT(dport), .cb = nlattr_get_uint16 },
};
-static const struct nlfield_parser nlf_p_natlook[] = {};
-#undef _IN
#undef _OUT
-NL_DECLARE_PARSER(natlook_parser, struct genlmsghdr, nlf_p_natlook, nla_p_natlook);
+NL_DECLARE_PARSER(natlook_parser, struct genlmsghdr, nlf_p_empty, nla_p_natlook);
static int
pf_handle_natlook(struct nlmsghdr *hdr, struct nl_pstate *npt)
@@ -1338,9 +1317,8 @@ struct pf_nl_set_debug
static const struct nlattr_parser nla_p_set_debug[] = {
{ .type = PF_SD_LEVEL, .off = _OUT(level), .cb = nlattr_get_uint32 },
};
-static const struct nlfield_parser nlf_p_set_debug[] = {};
#undef _OUT
-NL_DECLARE_PARSER(set_debug_parser, struct genlmsghdr, nlf_p_set_debug, nla_p_set_debug);
+NL_DECLARE_PARSER(set_debug_parser, struct genlmsghdr, nlf_p_empty, nla_p_set_debug);
static int
pf_handle_set_debug(struct nlmsghdr *hdr, struct nl_pstate *npt)
@@ -1369,9 +1347,8 @@ static const struct nlattr_parser nla_p_set_timeout[] = {
{ .type = PF_TO_TIMEOUT, .off = _OUT(timeout), .cb = nlattr_get_uint32 },
{ .type = PF_TO_SECONDS, .off = _OUT(seconds), .cb = nlattr_get_uint32 },
};
-static const struct nlfield_parser nlf_p_set_timeout[] = {};
#undef _OUT
-NL_DECLARE_PARSER(set_timeout_parser, struct genlmsghdr, nlf_p_set_timeout, nla_p_set_timeout);
+NL_DECLARE_PARSER(set_timeout_parser, struct genlmsghdr, nlf_p_empty, nla_p_set_timeout);
static int
pf_handle_set_timeout(struct nlmsghdr *hdr, struct nl_pstate *npt)
@@ -1430,9 +1407,8 @@ static const struct nlattr_parser nla_p_set_limit[] = {
{ .type = PF_LI_INDEX, .off = _OUT(index), .cb = nlattr_get_uint32 },
{ .type = PF_LI_LIMIT, .off = _OUT(limit), .cb = nlattr_get_uint32 },
};
-static const struct nlfield_parser nlf_p_set_limit[] = {};
#undef _OUT
-NL_DECLARE_PARSER(set_limit_parser, struct genlmsghdr, nlf_p_set_limit, nla_p_set_limit);
+NL_DECLARE_PARSER(set_limit_parser, struct genlmsghdr, nlf_p_empty, nla_p_set_limit);
static int
pf_handle_set_limit(struct nlmsghdr *hdr, struct nl_pstate *npt)
@@ -1547,9 +1523,8 @@ static const struct nlattr_parser nla_p_add_addr[] = {
{ .type = PF_AA_ADDR, .off = _OUT(addr), .arg = &pool_addr_parser, .cb = nlattr_get_nested },
{ .type = PF_AA_WHICH, .off = _OUT(which), .cb = nlattr_get_uint32 },
};
-static const struct nlfield_parser nlf_p_add_addr[] = {};
#undef _OUT
-NL_DECLARE_PARSER(add_addr_parser, struct genlmsghdr, nlf_p_add_addr, nla_p_add_addr);
+NL_DECLARE_PARSER(add_addr_parser, struct genlmsghdr, nlf_p_empty, nla_p_add_addr);
static int
pf_handle_add_addr(struct nlmsghdr *hdr, struct nl_pstate *npt)
@@ -1656,9 +1631,7 @@ static const struct nlattr_parser nla_p_ruleset[] = {
{ .type = PF_RS_PATH, .off = _OUT(path), .arg = (void *)MAXPATHLEN, .cb = nlattr_get_chara },
{ .type = PF_RS_NR, .off = _OUT(nr), .cb = nlattr_get_uint32 },
};
-static const struct nlfield_parser nlf_p_ruleset[] = {
-};
-NL_DECLARE_PARSER(ruleset_parser, struct genlmsghdr, nlf_p_ruleset, nla_p_ruleset);
+NL_DECLARE_PARSER(ruleset_parser, struct genlmsghdr, nlf_p_empty, nla_p_ruleset);
#undef _OUT
static int
diff --git a/sys/netpfil/pf/pflow.c b/sys/netpfil/pf/pflow.c
index 397d720215b2..8741d55b622c 100644
--- a/sys/netpfil/pf/pflow.c
+++ b/sys/netpfil/pf/pflow.c
@@ -1389,15 +1389,12 @@ pflow_nl_create(struct nlmsghdr *hdr, struct nl_pstate *npt)
struct pflow_parsed_del {
int id;
};
-#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct pflow_parsed_del, _field)
static const struct nlattr_parser nla_p_del[] = {
{ .type = PFLOWNL_DEL_ID, .off = _OUT(id), .cb = nlattr_get_uint32 },
};
-static const struct nlfield_parser nlf_p_del[] = {};
-#undef _IN
#undef _OUT
-NL_DECLARE_PARSER(del_parser, struct genlmsghdr, nlf_p_del, nla_p_del);
+NL_DECLARE_PARSER(del_parser, struct genlmsghdr, nlf_p_empty, nla_p_del);
static int
pflow_nl_del(struct nlmsghdr *hdr, struct nl_pstate *npt)
@@ -1417,15 +1414,12 @@ pflow_nl_del(struct nlmsghdr *hdr, struct nl_pstate *npt)
struct pflow_parsed_get {
int id;
};
-#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct pflow_parsed_get, _field)
static const struct nlattr_parser nla_p_get[] = {
{ .type = PFLOWNL_GET_ID, .off = _OUT(id), .cb = nlattr_get_uint32 },
};
-static const struct nlfield_parser nlf_p_get[] = {};
-#undef _IN
#undef _OUT
-NL_DECLARE_PARSER(get_parser, struct genlmsghdr, nlf_p_get, nla_p_get);
+NL_DECLARE_PARSER(get_parser, struct genlmsghdr, nlf_p_empty, nla_p_get);
static bool
nlattr_add_sockaddr(struct nl_writer *nw, int attr, const struct sockaddr *s)
@@ -1558,7 +1552,6 @@ struct pflow_parsed_set {
struct sockaddr_storage dst;
uint32_t observation_dom;
};
-#define _IN(_field) offsetof(struct genlmsghdr, _field)
#define _OUT(_field) offsetof(struct pflow_parsed_set, _field)
static const struct nlattr_parser nla_p_set[] = {
{ .type = PFLOWNL_SET_ID, .off = _OUT(id), .cb = nlattr_get_uint32 },
@@ -1567,10 +1560,8 @@ static const struct nlattr_parser nla_p_set[] = {
{ .type = PFLOWNL_SET_DST, .off = _OUT(dst), .arg = &addr_parser, .cb = nlattr_get_nested },
{ .type = PFLOWNL_SET_OBSERVATION_DOMAIN, .off = _OUT(observation_dom), .cb = nlattr_get_uint32 },
};
-static const struct nlfield_parser nlf_p_set[] = {};
-#undef _IN
#undef _OUT
-NL_DECLARE_PARSER(set_parser, struct genlmsghdr, nlf_p_set, nla_p_set);
+NL_DECLARE_PARSER(set_parser, struct genlmsghdr, nlf_p_empty, nla_p_set);
static int
pflow_set(struct pflow_softc *sc, const struct pflow_parsed_set *pflowr, struct ucred *cred)