Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107139188
D47557.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
8 KB
Referenced Files
None
Subscribers
None
D47557.diff
View Options
diff --git a/sbin/route/route_netlink.c b/sbin/route/route_netlink.c
--- a/sbin/route/route_netlink.c
+++ b/sbin/route/route_netlink.c
@@ -589,7 +589,7 @@
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 @@
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 @@
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
--- a/sys/netinet/ip_carp.c
+++ b/sys/netinet/ip_carp.c
@@ -2986,7 +2986,7 @@
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
--- a/sys/netlink/netlink.h
+++ b/sys/netlink/netlink.h
@@ -61,7 +61,7 @@
#ifndef _NETLINK_NETLINK_H_
#define _NETLINK_NETLINK_H_
-#include <sys/types.h>
+#include <sys/param.h>
#include <sys/socket.h>
struct sockaddr_nl {
@@ -194,9 +194,6 @@
};
-#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
--- a/sys/netlink/netlink_ctl.h
+++ b/sys/netlink/netlink_ctl.h
@@ -65,8 +65,6 @@
((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 <netlink/netlink_message_writer.h>
#include <netlink/netlink_message_parser.h>
diff --git a/sys/netlink/netlink_generic.c b/sys/netlink/netlink_generic.c
--- a/sys/netlink/netlink_generic.c
+++ b/sys/netlink/netlink_generic.c
@@ -284,7 +284,7 @@
{
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
--- a/sys/netlink/netlink_message_parser.h
+++ b/sys/netlink/netlink_message_parser.h
@@ -128,8 +128,8 @@
.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 @@
.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 @@
#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
--- a/sys/netlink/netlink_snl.h
+++ b/sys/netlink/netlink_snl.h
@@ -31,6 +31,12 @@
* Simple Netlink Library
*/
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <netlink/netlink.h>
+#include <netlink/netlink_bitset.h>
+
#include <assert.h>
#include <errno.h>
#include <stdalign.h>
@@ -41,11 +47,6 @@
#include <string.h>
#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netlink/netlink.h>
-#include <netlink/netlink_bitset.h>
-
#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 @@
.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 @@
.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 = { \
.out_size = _sz_out, \
.np = &((_np)[0]), \
- .np_size = NL_ARRAY_LEN(_np), \
+ .np_size = nitems(_np), \
.cb_post = _cb, \
}
@@ -418,7 +417,7 @@
}
}
}
-#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
--- a/sys/netlink/route/iface.c
+++ b/sys/netlink/route/iface.c
@@ -1522,7 +1522,7 @@
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
--- a/sys/netlink/route/neigh.c
+++ b/sys/netlink/route/neigh.c
@@ -589,7 +589,7 @@
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
--- a/sys/netlink/route/nexthop.c
+++ b/sys/netlink/route/nexthop.c
@@ -1119,5 +1119,5 @@
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
--- a/sys/netlink/route/rt.c
+++ b/sys/netlink/route/rt.c
@@ -1119,5 +1119,5 @@
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
--- a/sys/netpfil/pf/pf_nl.c
+++ b/sys/netpfil/pf/pf_nl.c
@@ -2004,7 +2004,7 @@
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
--- a/sys/netpfil/pf/pflow.c
+++ b/sys/netpfil/pf/pflow.c
@@ -1807,7 +1807,8 @@
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
--- a/sys/tests/ktest.c
+++ b/sys/tests/ktest.c
@@ -370,7 +370,8 @@
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);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 11, 5:42 PM (20 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15751015
Default Alt Text
D47557.diff (8 KB)
Attached To
Mode
D47557: netlink: use nitems() and roundup(2) from param.h
Attached
Detach File
Event Timeline
Log In to Comment