From nobody Tue Dec 03 20:05:02 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Y2s7z1c2Zz5ggbc; Tue, 03 Dec 2024 20:05:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y2s7y6tKzz4lZv; Tue, 3 Dec 2024 20:05:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733256303; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qtPGLVe8MBAC33Lu/I6JDU1GnaBSRIU7joQmleGT7+c=; b=rbvO2syaCEcBQqhR+19cJcg4GQPeUG0r0S+iFqc9bJEMF8Jzq4b+uW5Xu1XMkxRDymlwno mCVbdAQtxqhD+Rs/SPak49/iGnClCRvtgXFVDredCD5GEOMmT+xztTGh1oYGm65FvDbxM5 Z+OS/mbSB6sm/lEoGoyeof6a427DhOauyMyYYsRSD1pyfADdm8oKmbEuLt9lOzYpv1cNxM etwcKwrj1hI1D9I8GWw/ZtXFO1CyZsHs76BuCsyvh9kp1GsMoZWAeND+bW9tzKlYFAzhT6 HtSHC1TNE1OiyGppNkL41Y6icEQ9OXSKz5nTS7+wmeVWErL4Q9VUuQsTS1iGng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733256303; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qtPGLVe8MBAC33Lu/I6JDU1GnaBSRIU7joQmleGT7+c=; b=p1KfARS/NKIoiKodqoNGLm+mMzTpIpsAKoeYb0MvIwss0EwPHVqhhd9yxHoipS3DfrFbdM wLeuhbOI9NJwwk81X8ycYV0g+JaR2Zkg4ntWXzIYCpnqU88eT8qyDxlt4dlKbvJyPde82n pZRt7LCAHU9Pogj/beZPx8DIlpy9hxpgqyd273PiXfcMKYIdgHNM/vtngrkUZ1zVBc9DhY QYXOBLOgrsVsycVhbsbz61+WpyZyy6DBm9OArgtbnvBOhHDnGSJIaJxibWKkr8HztxKu4u b0xmDrYr+9Sc0tOIbRE5T7fzvdJz9Bnr284ezGDLzvXoeuJw/76hPhzmR5kVEw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733256303; a=rsa-sha256; cv=none; b=MHxP4c/VWDpzOZ/05M3wmEFBmxl1CWIVPvZ95FuXBqMBfpITMp/BX6Mio8rulm5WuJDpgz cw7fCj8yL0fLkjG7t9eOE6600UCcw/SDdgB23Mr+SthSArgX0ZPDeP/FtFWaxkrKipx1NM KIjs+75Dvdx+cG24Zn6dBDcgeBCSIUIbFWvP7Agb7wGM+FvLo+9DTGNPtkGfTEH5Jj8uta /9v/5/DhuqsfxvF8yxxDW/2nzltHI1rYvZgdMEp8xI93LELdeo6cf/CRQX0wkUaBfG/D+6 ecVT05aRDDGNkrScISiAowsgRrLyqOC3dbL9oe4PtZkQein88jJ4Si/f0FrUAw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Y2s7y6Gqkzd3k; Tue, 3 Dec 2024 20:05:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4B3K529M061900; Tue, 3 Dec 2024 20:05:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B3K52lX061897; Tue, 3 Dec 2024 20:05:02 GMT (envelope-from git) Date: Tue, 3 Dec 2024 20:05:02 GMT Message-Id: <202412032005.4B3K52lX061897@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 29f6150256c2 - main - netlink: use nitems() and roundup(2) from param.h List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 29f6150256c204a53c6f72a03d3df35ec52ccbf6 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=29f6150256c204a53c6f72a03d3df35ec52ccbf6 commit 29f6150256c204a53c6f72a03d3df35ec52ccbf6 Author: Gleb Smirnoff AuthorDate: 2024-12-03 20:04:39 +0000 Commit: Gleb Smirnoff CommitDate: 2024-12-03 20:04:39 +0000 netlink: use nitems() and roundup(2) from param.h While here style nested includes (kernel ones go first). Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D47557 --- sbin/route/route_netlink.c | 6 +++--- sys/netinet/ip_carp.c | 2 +- sys/netlink/netlink.h | 5 +---- sys/netlink/netlink_ctl.h | 2 -- sys/netlink/netlink_generic.c | 2 +- sys/netlink/netlink_message_parser.h | 12 ++++++------ sys/netlink/netlink_snl.h | 23 +++++++++++------------ sys/netlink/route/iface.c | 2 +- sys/netlink/route/neigh.c | 2 +- sys/netlink/route/nexthop.c | 2 +- sys/netlink/route/rt.c | 2 +- sys/netpfil/pf/pf_nl.c | 2 +- sys/netpfil/pf/pflow.c | 3 ++- sys/tests/ktest.c | 3 ++- 14 files changed, 32 insertions(+), 36 deletions(-) diff --git a/sbin/route/route_netlink.c b/sbin/route/route_netlink.c index 040b97568f20..631c2860b547 100644 --- a/sbin/route/route_netlink.c +++ b/sbin/route/route_netlink.c @@ -589,7 +589,7 @@ print_nlmsg_link(struct nl_helper *h, struct nlmsghdr *hdr, printf("iface#%u %s ", l.ifi_index, l.ifla_ifname); printf("admin %s ", (l.ifi_flags & IFF_UP) ? "UP" : "DOWN"); - if (l.ifla_operstate < NL_ARRAY_LEN(operstate)) + if (l.ifla_operstate < nitems(operstate)) printf("oper %s ", operstate[l.ifla_operstate]); if (l.ifla_mtu > 0) printf("mtu %u ", l.ifla_mtu); @@ -668,7 +668,7 @@ print_nlmsg_neigh(struct nl_helper *h, struct nlmsghdr *hdr, struct snl_parsed_link_simple link = {}; get_ifdata(h, attrs.nda_ifindex, &link); - for (unsigned int i = 0; i < NL_ARRAY_LEN(nudstate); i++) { + for (unsigned int i = 0; i < nitems(nudstate); i++) { if ((1 << i) & attrs.ndm_state) { printf("state %s ", nudstate[i]); break; @@ -768,7 +768,7 @@ monitor_nl(int fib) socklen_t optlen = sizeof(optval); setsockopt(ss_event.fd, SOL_NETLINK, NETLINK_MSG_INFO, &optval, optlen); - for (unsigned int i = 0; i < NL_ARRAY_LEN(groups); i++) { + for (unsigned int i = 0; i < nitems(groups); i++) { int error; int optval = groups[i]; socklen_t optlen = sizeof(optval); diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index ab001d346313..133dba45cf36 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -2986,7 +2986,7 @@ carp_nl_register(void) MPASS(family_id != 0); ret = genl_register_cmds(CARP_NL_FAMILY_NAME, carp_cmds, - NL_ARRAY_LEN(carp_cmds)); + nitems(carp_cmds)); MPASS(ret); } diff --git a/sys/netlink/netlink.h b/sys/netlink/netlink.h index 2cffa7299ef4..5724385271fc 100644 --- a/sys/netlink/netlink.h +++ b/sys/netlink/netlink.h @@ -61,7 +61,7 @@ #ifndef _NETLINK_NETLINK_H_ #define _NETLINK_NETLINK_H_ -#include +#include #include struct sockaddr_nl { @@ -194,9 +194,6 @@ enum nlmsginfo_attrs { }; -#ifndef roundup2 -#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ -#endif #define NL_ITEM_ALIGN_SIZE sizeof(uint32_t) #define NL_ITEM_ALIGN(_len) roundup2(_len, NL_ITEM_ALIGN_SIZE) #define NL_ITEM_DATA(_ptr, _off) ((void *)((char *)(_ptr) + _off)) diff --git a/sys/netlink/netlink_ctl.h b/sys/netlink/netlink_ctl.h index c2ac3e99421e..95b79c763ccd 100644 --- a/sys/netlink/netlink_ctl.h +++ b/sys/netlink/netlink_ctl.h @@ -65,8 +65,6 @@ MALLOC_DECLARE(M_NETLINK); ((char *)NLA_NEXT(_attr) <= (char *)_end); \ _attr = (_len -= NLA_ALIGN(_attr->nla_len), NLA_NEXT(_attr))) -#define NL_ARRAY_LEN(_a) (sizeof(_a) / sizeof((_a)[0])) - #include #include diff --git a/sys/netlink/netlink_generic.c b/sys/netlink/netlink_generic.c index 4a3c83da57e1..0f960d79f477 100644 --- a/sys/netlink/netlink_generic.c +++ b/sys/netlink/netlink_generic.c @@ -284,7 +284,7 @@ genl_load_all(void *u __unused) { NL_VERIFY_PARSERS(all_parsers); ctrl_family_id = genl_register_family(CTRL_FAMILY_NAME, 0, 2, CTRL_ATTR_MAX); - genl_register_cmds(CTRL_FAMILY_NAME, nlctrl_cmds, NL_ARRAY_LEN(nlctrl_cmds)); + genl_register_cmds(CTRL_FAMILY_NAME, nlctrl_cmds, nitems(nlctrl_cmds)); ctrl_group_id = genl_register_group(CTRL_FAMILY_NAME, "notify"); family_event_tag = EVENTHANDLER_REGISTER(genl_family_event, nlctrl_notify, NULL, EVENTHANDLER_PRI_ANY); diff --git a/sys/netlink/netlink_message_parser.h b/sys/netlink/netlink_message_parser.h index 49bec646b29e..42a59f45b22a 100644 --- a/sys/netlink/netlink_message_parser.h +++ b/sys/netlink/netlink_message_parser.h @@ -128,8 +128,8 @@ static const struct nlhdr_parser _name = { \ .nl_hdr_off = sizeof(_t), \ .fp = &((_fp)[0]), \ .np = &((_np)[0]), \ - .fp_size = NL_ARRAY_LEN(_fp), \ - .np_size = NL_ARRAY_LEN(_np), \ + .fp_size = nitems(_fp), \ + .np_size = nitems(_np), \ .sp = _sp, \ .post_parse = _pp, \ } @@ -146,14 +146,14 @@ static const struct nlhdr_parser _name = { \ .out_hdr_off = sizeof(_o), \ .fp = &((_fp)[0]), \ .np = &((_np)[0]), \ - .fp_size = NL_ARRAY_LEN(_fp), \ - .np_size = NL_ARRAY_LEN(_np), \ + .fp_size = nitems(_fp), \ + .np_size = nitems(_np), \ } #define NL_DECLARE_ATTR_PARSER_EXT(_name, _np, _pp) \ static const struct nlhdr_parser _name = { \ .np = &((_np)[0]), \ - .np_size = NL_ARRAY_LEN(_np), \ + .np_size = nitems(_np), \ .post_parse = (_pp) \ } @@ -308,7 +308,7 @@ nl_verify_parsers(const struct nlhdr_parser **parser, int count) #endif } void nl_verify_parsers(const struct nlhdr_parser **parser, int count); -#define NL_VERIFY_PARSERS(_p) nl_verify_parsers((_p), NL_ARRAY_LEN(_p)) +#define NL_VERIFY_PARSERS(_p) nl_verify_parsers((_p), nitems(_p)) static inline int nl_parse_nlmsg(struct nlmsghdr *hdr, const struct nlhdr_parser *parser, diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 7151f6221fca..2861ea93bafb 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -31,6 +31,12 @@ * Simple Netlink Library */ +#include +#include + +#include +#include + #include #include #include @@ -41,11 +47,6 @@ #include #include -#include -#include -#include -#include - #define _roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) #define NETLINK_ALIGN_SIZE sizeof(uint32_t) @@ -68,8 +69,6 @@ ((char *)NLA_NEXT(_attr) <= _NLA_END(_start, _len)); \ _attr = NLA_NEXT(_attr)) -#define NL_ARRAY_LEN(_a) (sizeof(_a) / sizeof((_a)[0])) - struct linear_buffer { char *base; /* Base allocated memory pointer */ uint32_t offset; /* Currently used offset */ @@ -166,8 +165,8 @@ static const struct snl_hdr_parser _name = { \ .out_size = _sz_out, \ .fp = &((_fp)[0]), \ .np = &((_np)[0]), \ - .fp_size = NL_ARRAY_LEN(_fp), \ - .np_size = NL_ARRAY_LEN(_np), \ + .fp_size = nitems(_fp), \ + .np_size = nitems(_np), \ .cb_post = _cb, \ } @@ -179,7 +178,7 @@ static const struct snl_hdr_parser _name = { \ .in_hdr_size = _sz_h_in, \ .out_size = _sz_out, \ .fp = &((_fp)[0]), \ - .fp_size = NL_ARRAY_LEN(_fp), \ + .fp_size = nitems(_fp), \ .cb_post = _cb, \ } @@ -190,7 +189,7 @@ static const struct snl_hdr_parser _name = { \ static const struct snl_hdr_parser _name = { \ .out_size = _sz_out, \ .np = &((_np)[0]), \ - .np_size = NL_ARRAY_LEN(_np), \ + .np_size = nitems(_np), \ .cb_post = _cb, \ } @@ -418,7 +417,7 @@ snl_verify_parsers(const struct snl_hdr_parser **parser, int count) } } } -#define SNL_VERIFY_PARSERS(_p) snl_verify_parsers((_p), NL_ARRAY_LEN(_p)) +#define SNL_VERIFY_PARSERS(_p) snl_verify_parsers((_p), nitems(_p)) static const struct snl_attr_parser * find_parser(const struct snl_attr_parser *ps, int pslen, int key) diff --git a/sys/netlink/route/iface.c b/sys/netlink/route/iface.c index c19161f5bbb7..86b1f8f1b1bc 100644 --- a/sys/netlink/route/iface.c +++ b/sys/netlink/route/iface.c @@ -1522,7 +1522,7 @@ rtnl_ifaces_init(void) ifnet_link_event, rtnl_handle_iflink, NULL, EVENTHANDLER_PRI_ANY); NL_VERIFY_PARSERS(all_parsers); - rtnl_register_messages(cmd_handlers, NL_ARRAY_LEN(cmd_handlers)); + rtnl_register_messages(cmd_handlers, nitems(cmd_handlers)); } void diff --git a/sys/netlink/route/neigh.c b/sys/netlink/route/neigh.c index c5003eddaba1..ec58c6140db8 100644 --- a/sys/netlink/route/neigh.c +++ b/sys/netlink/route/neigh.c @@ -589,7 +589,7 @@ void rtnl_neighs_init(void) { NL_VERIFY_PARSERS(all_parsers); - rtnl_register_messages(cmd_handlers, NL_ARRAY_LEN(cmd_handlers)); + rtnl_register_messages(cmd_handlers, nitems(cmd_handlers)); lle_event_p = EVENTHANDLER_REGISTER(lle_event, rtnl_lle_event, NULL, EVENTHANDLER_PRI_ANY); } diff --git a/sys/netlink/route/nexthop.c b/sys/netlink/route/nexthop.c index 90ed3497047e..03f1a57fd1e4 100644 --- a/sys/netlink/route/nexthop.c +++ b/sys/netlink/route/nexthop.c @@ -1119,5 +1119,5 @@ void rtnl_nexthops_init(void) { NL_VERIFY_PARSERS(all_parsers); - rtnl_register_messages(cmd_handlers, NL_ARRAY_LEN(cmd_handlers)); + rtnl_register_messages(cmd_handlers, nitems(cmd_handlers)); } diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c index c9b0f56498ec..14bd73d33411 100644 --- a/sys/netlink/route/rt.c +++ b/sys/netlink/route/rt.c @@ -1119,5 +1119,5 @@ void rtnl_routes_init(void) { NL_VERIFY_PARSERS(all_parsers); - rtnl_register_messages(cmd_handlers, NL_ARRAY_LEN(cmd_handlers)); + rtnl_register_messages(cmd_handlers, nitems(cmd_handlers)); } diff --git a/sys/netpfil/pf/pf_nl.c b/sys/netpfil/pf/pf_nl.c index 68b3659b0ed2..ad7dc97cbc1a 100644 --- a/sys/netpfil/pf/pf_nl.c +++ b/sys/netpfil/pf/pf_nl.c @@ -2004,7 +2004,7 @@ pf_nl_register(void) NL_VERIFY_PARSERS(all_parsers); family_id = genl_register_family(PFNL_FAMILY_NAME, 0, 2, PFNL_CMD_MAX); - genl_register_cmds(PFNL_FAMILY_NAME, pf_cmds, NL_ARRAY_LEN(pf_cmds)); + genl_register_cmds(PFNL_FAMILY_NAME, pf_cmds, nitems(pf_cmds)); } void diff --git a/sys/netpfil/pf/pflow.c b/sys/netpfil/pf/pflow.c index 36b528290306..397d720215b2 100644 --- a/sys/netpfil/pf/pflow.c +++ b/sys/netpfil/pf/pflow.c @@ -1807,7 +1807,8 @@ pflow_init(void) family_id = genl_register_family(PFLOWNL_FAMILY_NAME, 0, 2, PFLOWNL_CMD_MAX); MPASS(family_id != 0); - ret = genl_register_cmds(PFLOWNL_FAMILY_NAME, pflow_cmds, NL_ARRAY_LEN(pflow_cmds)); + ret = genl_register_cmds(PFLOWNL_FAMILY_NAME, pflow_cmds, + nitems(pflow_cmds)); return (ret ? 0 : ENODEV); } diff --git a/sys/tests/ktest.c b/sys/tests/ktest.c index cd83a6aaaa3f..694e1f4229b5 100644 --- a/sys/tests/ktest.c +++ b/sys/tests/ktest.c @@ -370,7 +370,8 @@ ktest_nl_register(void) family_id = genl_register_family(KTEST_FAMILY_NAME, 0, 1, KTEST_CMD_MAX); MPASS(family_id != 0); - ret = genl_register_cmds(KTEST_FAMILY_NAME, ktest_cmds, NL_ARRAY_LEN(ktest_cmds)); + ret = genl_register_cmds(KTEST_FAMILY_NAME, ktest_cmds, + nitems(ktest_cmds)); MPASS(ret); }