tests: introduce midtail_alloc and use it in netlink tests

netlink tests happen to access memory located before the tail_malloc'ed
pointers, a practice that doesn't go well with the latest compilers
because tail_malloc is marked with ATTRIBUTE_MALLOC.
For example, glibc in -D_FORTIFY_SOURCE=2 mode and gcc 8 with
-Warray-bounds enabled complain about negative offsets out of bounds.
Fix this issue by introducing midtail_alloc.

* tests/tests.h (midtail_alloc): New macro.
* tests/netlink_crypto.c: Use it instead of tail_malloc for nlh0 allocation.
* tests/netlink_netfilter.c: Likewise.
* tests/netlink_protocol.c: Likewise.
* tests/netlink_route.c: Likewise.
* tests/netlink_selinux.c: Likewise.
* tests/netlink_sock_diag.c: Likewise.
* tests/nlattr_br_port_msg.c: Likewise.
* tests/nlattr_crypto_user_alg.c: Likewise.
* tests/nlattr_dcbmsg.c: Likewise.
* tests/nlattr_fib_rule_hdr.c: Likewise.
* tests/nlattr_ifaddrlblmsg.c: Likewise.
* tests/nlattr_ifaddrmsg.c: Likewise.
* tests/nlattr_ifinfomsg.c: Likewise.
* tests/nlattr_ifla_brport.c: Likewise.
* tests/nlattr_ifla_port.c: Likewise.
* tests/nlattr_ifla_xdp.c: Likewise.
* tests/nlattr_inet_diag_msg.c: Likewise.
* tests/nlattr_inet_diag_req_compat.c: Likewise.
* tests/nlattr_inet_diag_req_v2.c: Likewise.
* tests/nlattr_mdba_mdb_entry.c: Likewise.
* tests/nlattr_mdba_router_port.c: Likewise.
* tests/nlattr_ndmsg.c: Likewise.
* tests/nlattr_ndtmsg.c: Likewise.
* tests/nlattr_netconfmsg.c: Likewise.
* tests/nlattr_netlink_diag_msg.c: Likewise.
* tests/nlattr_nlmsgerr.c: Likewise.
* tests/nlattr_packet_diag_msg.c: Likewise.
* tests/nlattr_rtgenmsg.c: Likewise.
* tests/nlattr_rtmsg.c: Likewise.
* tests/nlattr_smc_diag_msg.c: Likewise.
* tests/nlattr_tc_stats.c: Likewise.
* tests/nlattr_tca_stab.c: Likewise.
* tests/nlattr_tcamsg.c: Likewise.
* tests/nlattr_tcmsg.c: Likewise.
* tests/nlattr_unix_diag_msg.c: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
This commit is contained in:
Eugene Syromyatnikov 2018-05-08 07:10:16 +02:00 committed by Dmitry V. Levin
parent afc49df0b0
commit 346e8002b0
36 changed files with 272 additions and 226 deletions

View File

@ -98,8 +98,6 @@ test_nlmsg_flags(const int fd)
static void static void
test_crypto_msg_newalg(const int fd) test_crypto_msg_newalg(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
struct crypto_user_alg alg = { struct crypto_user_alg alg = {
.cru_name = "abcd", .cru_name = "abcd",
.cru_driver_name = "efgh", .cru_driver_name = "efgh",
@ -109,6 +107,8 @@ test_crypto_msg_newalg(const int fd)
.cru_refcnt = 0xbcacfacd, .cru_refcnt = 0xbcacfacd,
.cru_flags = 0xefacdbad .cru_flags = 0xefacdbad
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(alg));
TEST_NETLINK_OBJECT_EX(fd, nlh0, TEST_NETLINK_OBJECT_EX(fd, nlh0,
CRYPTO_MSG_NEWALG, NLM_F_REQUEST, CRYPTO_MSG_NEWALG, NLM_F_REQUEST,
alg, print_quoted_memory, alg, print_quoted_memory,
@ -149,7 +149,7 @@ test_crypto_msg_newalg(const int fd)
static void static void
test_crypto_msg_unspec(const int fd) test_crypto_msg_unspec(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN); void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, 4);
TEST_NETLINK_(fd, nlh0, TEST_NETLINK_(fd, nlh0,
0xffff, "0xffff /* CRYPTO_MSG_??? */", 0xffff, "0xffff /* CRYPTO_MSG_??? */",

View File

@ -88,8 +88,8 @@ test_nlmsg_type(const int fd)
static void static void
test_nlmsg_done(const int fd) test_nlmsg_done(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
const int num = 0xabcdefad; const int num = 0xabcdefad;
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(num));
TEST_NETLINK(fd, nlh0, NLMSG_DONE, NLM_F_REQUEST, TEST_NETLINK(fd, nlh0, NLMSG_DONE, NLM_F_REQUEST,
sizeof(num), &num, sizeof(num), sizeof(num), &num, sizeof(num),
@ -99,13 +99,21 @@ test_nlmsg_done(const int fd)
static void static void
test_nfgenmsg(const int fd) test_nfgenmsg(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN); static const struct nlattr nla = {
.nla_len = sizeof(nla),
.nla_type = 0x0bcd
};
struct nfgenmsg msg = { struct nfgenmsg msg = {
.nfgen_family = AF_UNIX, .nfgen_family = AF_UNIX,
.version = NFNETLINK_V0, .version = NFNETLINK_V0,
.res_id = NFNL_SUBSYS_NFTABLES .res_id = NFNL_SUBSYS_NFTABLES
}; };
char str_buf[NLMSG_ALIGN(sizeof(msg)) + 4];
char nla_buf[NLMSG_ALIGN(sizeof(msg)) + sizeof(nla)];
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN,
MAX(sizeof(str_buf), sizeof(nla_buf)));
TEST_NETLINK_OBJECT_EX_(fd, nlh0, TEST_NETLINK_OBJECT_EX_(fd, nlh0,
NFNL_SUBSYS_NFTABLES << 8 | NFT_MSG_NEWTABLE, NFNL_SUBSYS_NFTABLES << 8 | NFT_MSG_NEWTABLE,
@ -150,8 +158,6 @@ test_nfgenmsg(const int fd)
printf(", version=NFNETLINK_V0"); printf(", version=NFNETLINK_V0");
printf(", res_id=htons(%d)", NFNL_SUBSYS_NFTABLES)); printf(", res_id=htons(%d)", NFNL_SUBSYS_NFTABLES));
char str_buf[NLMSG_ALIGN(sizeof(msg)) + 4];
msg.res_id = htons(0xabcd); msg.res_id = htons(0xabcd);
memcpy(str_buf, &msg, sizeof(msg)); memcpy(str_buf, &msg, sizeof(msg));
memcpy(str_buf + NLMSG_ALIGN(sizeof(msg)), "1234", 4); memcpy(str_buf + NLMSG_ALIGN(sizeof(msg)), "1234", 4);
@ -165,12 +171,6 @@ test_nfgenmsg(const int fd)
", \"\\x31\\x32\\x33\\x34\"", 0xabcd)); ", \"\\x31\\x32\\x33\\x34\"", 0xabcd));
# endif /* NFNL_MSG_BATCH_BEGIN */ # endif /* NFNL_MSG_BATCH_BEGIN */
static const struct nlattr nla = {
.nla_len = sizeof(nla),
.nla_type = 0x0bcd
};
char nla_buf[NLMSG_ALIGN(sizeof(msg)) + sizeof(nla)];
msg.res_id = htons(NFNL_SUBSYS_NFTABLES); msg.res_id = htons(NFNL_SUBSYS_NFTABLES);
memcpy(nla_buf, &msg, sizeof(msg)); memcpy(nla_buf, &msg, sizeof(msg));
memcpy(nla_buf + NLMSG_ALIGN(sizeof(msg)), &nla, sizeof(nla)); memcpy(nla_buf + NLMSG_ALIGN(sizeof(msg)), &nla, sizeof(nla));

View File

@ -203,7 +203,7 @@ test_nlmsgerr(const int fd)
{ {
struct nlmsgerr *err; struct nlmsgerr *err;
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
void *const nlh0 = tail_alloc(NLMSG_HDRLEN); void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(*err) + 4);
long rc; long rc;
/* error message without enough room for the error code */ /* error message without enough room for the error code */
@ -318,9 +318,9 @@ static void
test_nlmsg_done(const int fd) test_nlmsg_done(const int fd)
{ {
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
long rc;
const int num = 0xfacefeed; const int num = 0xfacefeed;
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(num));
long rc;
/* NLMSG_DONE message without enough room for an integer payload */ /* NLMSG_DONE message without enough room for an integer payload */
nlh = nlh0; nlh = nlh0;

View File

@ -143,8 +143,8 @@ test_nlmsg_flags(const int fd)
static void static void
test_nlmsg_done(const int fd) test_nlmsg_done(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
const int num = 0xabcdefad; const int num = 0xabcdefad;
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(num));
TEST_NETLINK(fd, nlh0, NLMSG_DONE, NLM_F_REQUEST, TEST_NETLINK(fd, nlh0, NLMSG_DONE, NLM_F_REQUEST,
sizeof(num), &num, sizeof(num), sizeof(num), &num, sizeof(num),
@ -154,10 +154,11 @@ test_nlmsg_done(const int fd)
static void static void
test_rtnl_unspec(const int fd) test_rtnl_unspec(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN); uint8_t family = 0;
char buf[sizeof(family) + 4];
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(buf));
/* unspecified family only */ /* unspecified family only */
uint8_t family = 0;
TEST_NETLINK_(fd, nlh0, TEST_NETLINK_(fd, nlh0,
0xffff, "0xffff /* RTM_??? */", 0xffff, "0xffff /* RTM_??? */",
NLM_F_REQUEST, "NLM_F_REQUEST", NLM_F_REQUEST, "NLM_F_REQUEST",
@ -180,7 +181,6 @@ test_rtnl_unspec(const int fd)
printf("%p", NLMSG_DATA(TEST_NETLINK_nlh))); printf("%p", NLMSG_DATA(TEST_NETLINK_nlh)));
/* unspecified family and string */ /* unspecified family and string */
char buf[sizeof(family) + 4];
family = 0; family = 0;
memcpy(buf, &family, sizeof(family)); memcpy(buf, &family, sizeof(family));
memcpy(buf + sizeof(family), "1234", 4); memcpy(buf + sizeof(family), "1234", 4);
@ -204,7 +204,6 @@ test_rtnl_unspec(const int fd)
static void static void
test_rtnl_link(const int fd) test_rtnl_link(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
const struct ifinfomsg ifinfo = { const struct ifinfomsg ifinfo = {
.ifi_family = AF_UNIX, .ifi_family = AF_UNIX,
.ifi_type = ARPHRD_LOOPBACK, .ifi_type = ARPHRD_LOOPBACK,
@ -212,6 +211,7 @@ test_rtnl_link(const int fd)
.ifi_flags = IFF_UP, .ifi_flags = IFF_UP,
.ifi_change = 0xfabcdeba .ifi_change = 0xfabcdeba
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(ifinfo));
TEST_NL_ROUTE(fd, nlh0, RTM_GETLINK, ifinfo, TEST_NL_ROUTE(fd, nlh0, RTM_GETLINK, ifinfo,
printf("{ifi_family=AF_UNIX"), printf("{ifi_family=AF_UNIX"),
@ -225,7 +225,6 @@ test_rtnl_link(const int fd)
static void static void
test_rtnl_addr(const int fd) test_rtnl_addr(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
const struct ifaddrmsg msg = { const struct ifaddrmsg msg = {
.ifa_family = AF_UNIX, .ifa_family = AF_UNIX,
.ifa_prefixlen = 0xde, .ifa_prefixlen = 0xde,
@ -233,6 +232,7 @@ test_rtnl_addr(const int fd)
.ifa_scope = RT_SCOPE_UNIVERSE, .ifa_scope = RT_SCOPE_UNIVERSE,
.ifa_index = ifindex_lo() .ifa_index = ifindex_lo()
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NL_ROUTE(fd, nlh0, RTM_GETADDR, msg, TEST_NL_ROUTE(fd, nlh0, RTM_GETADDR, msg,
printf("{ifa_family=AF_UNIX"), printf("{ifa_family=AF_UNIX"),
@ -246,7 +246,6 @@ test_rtnl_addr(const int fd)
static void static void
test_rtnl_route(const int fd) test_rtnl_route(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct rtmsg msg = { static const struct rtmsg msg = {
.rtm_family = AF_UNIX, .rtm_family = AF_UNIX,
.rtm_dst_len = 0xaf, .rtm_dst_len = 0xaf,
@ -258,6 +257,7 @@ test_rtnl_route(const int fd)
.rtm_type = RTN_LOCAL, .rtm_type = RTN_LOCAL,
.rtm_flags = RTM_F_NOTIFY .rtm_flags = RTM_F_NOTIFY
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NL_ROUTE(fd, nlh0, RTM_GETROUTE, msg, TEST_NL_ROUTE(fd, nlh0, RTM_GETROUTE, msg,
printf("{rtm_family=AF_UNIX"), printf("{rtm_family=AF_UNIX"),
@ -275,7 +275,6 @@ test_rtnl_route(const int fd)
static void static void
test_rtnl_rule(const int fd) test_rtnl_rule(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
struct rtmsg msg = { struct rtmsg msg = {
.rtm_family = AF_UNIX, .rtm_family = AF_UNIX,
.rtm_dst_len = 0xaf, .rtm_dst_len = 0xaf,
@ -285,6 +284,7 @@ test_rtnl_rule(const int fd)
.rtm_type = FR_ACT_TO_TBL, .rtm_type = FR_ACT_TO_TBL,
.rtm_flags = FIB_RULE_INVERT .rtm_flags = FIB_RULE_INVERT
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NL_ROUTE(fd, nlh0, RTM_GETRULE, msg, TEST_NL_ROUTE(fd, nlh0, RTM_GETRULE, msg,
printf("{family=AF_UNIX"), printf("{family=AF_UNIX"),
@ -301,7 +301,6 @@ test_rtnl_rule(const int fd)
static void static void
test_rtnl_neigh(const int fd) test_rtnl_neigh(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
const struct ndmsg msg = { const struct ndmsg msg = {
.ndm_family = AF_UNIX, .ndm_family = AF_UNIX,
.ndm_ifindex = ifindex_lo(), .ndm_ifindex = ifindex_lo(),
@ -309,6 +308,7 @@ test_rtnl_neigh(const int fd)
.ndm_flags = NTF_PROXY, .ndm_flags = NTF_PROXY,
.ndm_type = RTN_UNSPEC .ndm_type = RTN_UNSPEC
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NL_ROUTE(fd, nlh0, RTM_GETNEIGH, msg, TEST_NL_ROUTE(fd, nlh0, RTM_GETNEIGH, msg,
printf("{ndm_family=AF_UNIX"), printf("{ndm_family=AF_UNIX"),
@ -321,10 +321,10 @@ test_rtnl_neigh(const int fd)
static void static void
test_rtnl_neightbl(const int fd) test_rtnl_neightbl(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct ndtmsg msg = { static const struct ndtmsg msg = {
.ndtm_family = AF_NETLINK .ndtm_family = AF_NETLINK
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NETLINK(fd, nlh0, TEST_NETLINK(fd, nlh0,
RTM_GETNEIGHTBL, NLM_F_REQUEST, RTM_GETNEIGHTBL, NLM_F_REQUEST,
@ -335,7 +335,6 @@ test_rtnl_neightbl(const int fd)
static void static void
test_rtnl_tc(const int fd) test_rtnl_tc(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
const struct tcmsg msg = { const struct tcmsg msg = {
.tcm_family = AF_UNIX, .tcm_family = AF_UNIX,
.tcm_ifindex = ifindex_lo(), .tcm_ifindex = ifindex_lo(),
@ -343,6 +342,7 @@ test_rtnl_tc(const int fd)
.tcm_parent = 0xafbcadab, .tcm_parent = 0xafbcadab,
.tcm_info = 0xbcaedafa .tcm_info = 0xbcaedafa
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NL_ROUTE(fd, nlh0, RTM_GETQDISC, msg, TEST_NL_ROUTE(fd, nlh0, RTM_GETQDISC, msg,
printf("{tcm_family=AF_UNIX"), printf("{tcm_family=AF_UNIX"),
@ -356,10 +356,10 @@ test_rtnl_tc(const int fd)
static void static void
test_rtnl_tca(const int fd) test_rtnl_tca(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
struct tcamsg msg = { struct tcamsg msg = {
.tca_family = AF_INET .tca_family = AF_INET
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NETLINK(fd, nlh0, TEST_NETLINK(fd, nlh0,
RTM_GETACTION, NLM_F_REQUEST, RTM_GETACTION, NLM_F_REQUEST,
@ -371,7 +371,6 @@ test_rtnl_tca(const int fd)
static void static void
test_rtnl_addrlabel(const int fd) test_rtnl_addrlabel(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
const struct ifaddrlblmsg msg = { const struct ifaddrlblmsg msg = {
.ifal_family = AF_UNIX, .ifal_family = AF_UNIX,
.ifal_prefixlen = 0xaf, .ifal_prefixlen = 0xaf,
@ -379,6 +378,7 @@ test_rtnl_addrlabel(const int fd)
.ifal_index = ifindex_lo(), .ifal_index = ifindex_lo(),
.ifal_seq = 0xfadcdafb .ifal_seq = 0xfadcdafb
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NL_ROUTE(fd, nlh0, RTM_GETADDRLABEL, msg, TEST_NL_ROUTE(fd, nlh0, RTM_GETADDRLABEL, msg,
printf("{ifal_family=AF_UNIX"), printf("{ifal_family=AF_UNIX"),
@ -394,11 +394,11 @@ test_rtnl_addrlabel(const int fd)
static void static void
test_rtnl_dcb(const int fd) test_rtnl_dcb(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct dcbmsg msg = { static const struct dcbmsg msg = {
.dcb_family = AF_UNIX, .dcb_family = AF_UNIX,
.cmd = DCB_CMD_UNDEFINED .cmd = DCB_CMD_UNDEFINED
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NL_ROUTE(fd, nlh0, RTM_GETDCB, msg, TEST_NL_ROUTE(fd, nlh0, RTM_GETDCB, msg,
printf("{dcb_family=AF_UNIX"), printf("{dcb_family=AF_UNIX"),
@ -410,10 +410,10 @@ test_rtnl_dcb(const int fd)
static void static void
test_rtnl_netconf(const int fd) test_rtnl_netconf(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct netconfmsg msg = { static const struct netconfmsg msg = {
.ncm_family = AF_INET .ncm_family = AF_INET
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NETLINK(fd, nlh0, TEST_NETLINK(fd, nlh0,
RTM_GETNETCONF, NLM_F_REQUEST, RTM_GETNETCONF, NLM_F_REQUEST,
@ -426,11 +426,11 @@ test_rtnl_netconf(const int fd)
static void static void
test_rtnl_mdb(const int fd) test_rtnl_mdb(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
const struct br_port_msg msg = { const struct br_port_msg msg = {
.family = AF_UNIX, .family = AF_UNIX,
.ifindex = ifindex_lo() .ifindex = ifindex_lo()
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NL_ROUTE(fd, nlh0, RTM_GETMDB, msg, TEST_NL_ROUTE(fd, nlh0, RTM_GETMDB, msg,
printf("{family=AF_UNIX"), printf("{family=AF_UNIX"),
@ -442,10 +442,10 @@ test_rtnl_mdb(const int fd)
static void static void
test_rtnl_nsid(const int fd) test_rtnl_nsid(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct rtgenmsg msg = { static const struct rtgenmsg msg = {
.rtgen_family = AF_UNIX .rtgen_family = AF_UNIX
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NETLINK(fd, nlh0, TEST_NETLINK(fd, nlh0,
RTM_GETNSID, NLM_F_REQUEST, RTM_GETNSID, NLM_F_REQUEST,

View File

@ -53,7 +53,7 @@ test_nlmsg_type(const int fd)
static void static void
test_selnl_msg_unspec(const int fd) test_selnl_msg_unspec(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN); void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, 4);
TEST_NETLINK_(fd, nlh0, TEST_NETLINK_(fd, nlh0,
0xffff, "0xffff /* SELNL_MSG_??? */", 0xffff, "0xffff /* SELNL_MSG_??? */",
@ -65,11 +65,11 @@ test_selnl_msg_unspec(const int fd)
static void static void
test_selnl_msg_setenforce(const int fd) test_selnl_msg_setenforce(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct selnl_msg_setenforce msg = { static const struct selnl_msg_setenforce msg = {
.val = 0xfbdcdfab .val = 0xfbdcdfab
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NETLINK_OBJECT(fd, nlh0, TEST_NETLINK_OBJECT(fd, nlh0,
SELNL_MSG_SETENFORCE, NLM_F_REQUEST, msg, SELNL_MSG_SETENFORCE, NLM_F_REQUEST, msg,
PRINT_FIELD_D("{", msg, val); PRINT_FIELD_D("{", msg, val);
@ -79,11 +79,11 @@ test_selnl_msg_setenforce(const int fd)
static void static void
test_selnl_msg_policyload(const int fd) test_selnl_msg_policyload(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct selnl_msg_policyload msg = { static const struct selnl_msg_policyload msg = {
.seqno = 0xabdcfabc .seqno = 0xabdcfabc
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_NETLINK_OBJECT(fd, nlh0, TEST_NETLINK_OBJECT(fd, nlh0,
SELNL_MSG_POLICYLOAD, NLM_F_REQUEST, msg, SELNL_MSG_POLICYLOAD, NLM_F_REQUEST, msg,
PRINT_FIELD_U("{", msg, seqno); PRINT_FIELD_U("{", msg, seqno);

View File

@ -127,10 +127,11 @@ test_nlmsg_flags(const int fd)
static void static void
test_odd_family_req(const int fd) test_odd_family_req(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN); uint8_t family = 0;
char buf[sizeof(family) + 4];
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(buf));
/* unspecified family only */ /* unspecified family only */
uint8_t family = 0;
TEST_NETLINK(fd, nlh0, TEST_NETLINK(fd, nlh0,
SOCK_DIAG_BY_FAMILY, SOCK_DIAG_BY_FAMILY,
NLM_F_REQUEST, NLM_F_REQUEST,
@ -153,7 +154,6 @@ test_odd_family_req(const int fd)
printf("%p", NLMSG_DATA(TEST_NETLINK_nlh))); printf("%p", NLMSG_DATA(TEST_NETLINK_nlh)));
/* unspecified family and string */ /* unspecified family and string */
char buf[sizeof(family) + 4];
family = 0; family = 0;
memcpy(buf, &family, sizeof(family)); memcpy(buf, &family, sizeof(family));
memcpy(buf + sizeof(family), "1234", 4); memcpy(buf + sizeof(family), "1234", 4);
@ -177,10 +177,11 @@ test_odd_family_req(const int fd)
static void static void
test_odd_family_msg(const int fd) test_odd_family_msg(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN); uint8_t family = 0;
char buf[sizeof(family) + 4];
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(buf));
/* unspecified family only */ /* unspecified family only */
uint8_t family = 0;
TEST_NETLINK(fd, nlh0, TEST_NETLINK(fd, nlh0,
SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, SOCK_DIAG_BY_FAMILY, NLM_F_DUMP,
sizeof(family), &family, sizeof(family), sizeof(family), &family, sizeof(family),
@ -200,7 +201,6 @@ test_odd_family_msg(const int fd)
printf("%p", NLMSG_DATA(TEST_NETLINK_nlh))); printf("%p", NLMSG_DATA(TEST_NETLINK_nlh)));
/* unspecified family and string */ /* unspecified family and string */
char buf[sizeof(family) + 4];
family = 0; family = 0;
memcpy(buf, &family, sizeof(family)); memcpy(buf, &family, sizeof(family));
memcpy(buf + sizeof(family), "1234", 4); memcpy(buf + sizeof(family), "1234", 4);
@ -222,7 +222,6 @@ test_odd_family_msg(const int fd)
static void static void
test_unix_diag_req(const int fd) test_unix_diag_req(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct unix_diag_req req = { static const struct unix_diag_req req = {
.sdiag_family = AF_UNIX, .sdiag_family = AF_UNIX,
.sdiag_protocol = 253, .sdiag_protocol = 253,
@ -231,6 +230,7 @@ test_unix_diag_req(const int fd)
.udiag_show = UDIAG_SHOW_NAME, .udiag_show = UDIAG_SHOW_NAME,
.udiag_cookie = { 0xdeadbeef, 0xbadc0ded } .udiag_cookie = { 0xdeadbeef, 0xbadc0ded }
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
TEST_SOCK_DIAG(fd, nlh0, AF_UNIX, TEST_SOCK_DIAG(fd, nlh0, AF_UNIX,
SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req, SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req,
printf("{sdiag_family=AF_UNIX"), printf("{sdiag_family=AF_UNIX"),
@ -245,7 +245,6 @@ test_unix_diag_req(const int fd)
static void static void
test_unix_diag_msg(const int fd) test_unix_diag_msg(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct unix_diag_msg msg = { static const struct unix_diag_msg msg = {
.udiag_family = AF_UNIX, .udiag_family = AF_UNIX,
.udiag_type = SOCK_STREAM, .udiag_type = SOCK_STREAM,
@ -253,6 +252,7 @@ test_unix_diag_msg(const int fd)
.udiag_ino = 0xfacefeed, .udiag_ino = 0xfacefeed,
.udiag_cookie = { 0xdeadbeef, 0xbadc0ded } .udiag_cookie = { 0xdeadbeef, 0xbadc0ded }
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_SOCK_DIAG(fd, nlh0, AF_UNIX, TEST_SOCK_DIAG(fd, nlh0, AF_UNIX,
SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg, SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg,
printf("{udiag_family=AF_UNIX"), printf("{udiag_family=AF_UNIX"),
@ -266,7 +266,6 @@ test_unix_diag_msg(const int fd)
static void static void
test_netlink_diag_req(const int fd) test_netlink_diag_req(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
struct netlink_diag_req req = { struct netlink_diag_req req = {
.sdiag_family = AF_NETLINK, .sdiag_family = AF_NETLINK,
.sdiag_protocol = NDIAG_PROTO_ALL, .sdiag_protocol = NDIAG_PROTO_ALL,
@ -274,6 +273,7 @@ test_netlink_diag_req(const int fd)
.ndiag_show = NDIAG_SHOW_MEMINFO, .ndiag_show = NDIAG_SHOW_MEMINFO,
.ndiag_cookie = { 0xdeadbeef, 0xbadc0ded } .ndiag_cookie = { 0xdeadbeef, 0xbadc0ded }
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
TEST_SOCK_DIAG(fd, nlh0, AF_NETLINK, TEST_SOCK_DIAG(fd, nlh0, AF_NETLINK,
SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req, SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req,
printf("{sdiag_family=AF_NETLINK"), printf("{sdiag_family=AF_NETLINK"),
@ -298,7 +298,6 @@ test_netlink_diag_req(const int fd)
static void static void
test_netlink_diag_msg(const int fd) test_netlink_diag_msg(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct netlink_diag_msg msg = { static const struct netlink_diag_msg msg = {
.ndiag_family = AF_NETLINK, .ndiag_family = AF_NETLINK,
.ndiag_type = SOCK_RAW, .ndiag_type = SOCK_RAW,
@ -310,6 +309,7 @@ test_netlink_diag_msg(const int fd)
.ndiag_ino = 0xdaeefacd, .ndiag_ino = 0xdaeefacd,
.ndiag_cookie = { 0xbadc0ded, 0xdeadbeef } .ndiag_cookie = { 0xbadc0ded, 0xdeadbeef }
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_SOCK_DIAG(fd, nlh0, AF_NETLINK, TEST_SOCK_DIAG(fd, nlh0, AF_NETLINK,
SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg, SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg,
printf("{ndiag_family=AF_NETLINK"), printf("{ndiag_family=AF_NETLINK"),
@ -327,7 +327,6 @@ test_netlink_diag_msg(const int fd)
static void static void
test_packet_diag_req(const int fd) test_packet_diag_req(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct packet_diag_req req = { static const struct packet_diag_req req = {
.sdiag_family = AF_PACKET, .sdiag_family = AF_PACKET,
.sdiag_protocol = ETH_P_LOOP, .sdiag_protocol = ETH_P_LOOP,
@ -335,6 +334,7 @@ test_packet_diag_req(const int fd)
.pdiag_show = PACKET_SHOW_INFO, .pdiag_show = PACKET_SHOW_INFO,
.pdiag_cookie = { 0xdeadbeef, 0xbadc0ded } .pdiag_cookie = { 0xdeadbeef, 0xbadc0ded }
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
TEST_SOCK_DIAG(fd, nlh0, AF_PACKET, TEST_SOCK_DIAG(fd, nlh0, AF_PACKET,
SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req, SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req,
printf("{sdiag_family=AF_PACKET"), printf("{sdiag_family=AF_PACKET"),
@ -348,7 +348,6 @@ test_packet_diag_req(const int fd)
static void static void
test_packet_diag_msg(const int fd) test_packet_diag_msg(const int fd)
{ {
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
static const struct packet_diag_msg msg = { static const struct packet_diag_msg msg = {
.pdiag_family = AF_PACKET, .pdiag_family = AF_PACKET,
.pdiag_type = SOCK_STREAM, .pdiag_type = SOCK_STREAM,
@ -356,6 +355,7 @@ test_packet_diag_msg(const int fd)
.pdiag_ino = 0xfacefeed, .pdiag_ino = 0xfacefeed,
.pdiag_cookie = { 0xdeadbeef, 0xbadc0ded } .pdiag_cookie = { 0xdeadbeef, 0xbadc0ded }
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
TEST_SOCK_DIAG(fd, nlh0, AF_PACKET, TEST_SOCK_DIAG(fd, nlh0, AF_PACKET,
SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg, SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg,
printf("{pdiag_family=AF_PACKET"), printf("{pdiag_family=AF_PACKET"),
@ -371,7 +371,6 @@ test_inet_diag_sockid(const int fd)
{ {
const char address[] = "12.34.56.78"; const char address[] = "12.34.56.78";
const char address6[] = "12:34:56:78:90:ab:cd:ef"; const char address6[] = "12:34:56:78:90:ab:cd:ef";
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
struct inet_diag_req_v2 req = { struct inet_diag_req_v2 req = {
.sdiag_family = AF_INET, .sdiag_family = AF_INET,
.idiag_ext = 1 << (INET_DIAG_CONG - 1), .idiag_ext = 1 << (INET_DIAG_CONG - 1),
@ -384,6 +383,7 @@ test_inet_diag_sockid(const int fd)
.idiag_cookie = { 0xdeadbeef, 0xbadc0ded } .idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
}, },
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
if (!inet_pton(AF_INET, address, &req.id.idiag_src) || if (!inet_pton(AF_INET, address, &req.id.idiag_src) ||
!inet_pton(AF_INET, address, &req.id.idiag_dst)) !inet_pton(AF_INET, address, &req.id.idiag_dst))
@ -435,7 +435,6 @@ static void
test_inet_diag_req(const int fd) test_inet_diag_req(const int fd)
{ {
const char address[] = "12.34.56.78"; const char address[] = "12.34.56.78";
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
struct inet_diag_req req = { struct inet_diag_req req = {
.idiag_family = AF_INET, .idiag_family = AF_INET,
.idiag_src_len = 0xde, .idiag_src_len = 0xde,
@ -450,6 +449,7 @@ test_inet_diag_req(const int fd)
.idiag_states = 1 << TCP_LAST_ACK, .idiag_states = 1 << TCP_LAST_ACK,
.idiag_dbs = 0xfacefeed, .idiag_dbs = 0xfacefeed,
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
if (!inet_pton(AF_INET, address, &req.id.idiag_src) || if (!inet_pton(AF_INET, address, &req.id.idiag_src) ||
!inet_pton(AF_INET, address, &req.id.idiag_dst)) !inet_pton(AF_INET, address, &req.id.idiag_dst))
@ -479,7 +479,6 @@ static void
test_inet_diag_req_v2(const int fd) test_inet_diag_req_v2(const int fd)
{ {
const char address[] = "87.65.43.21"; const char address[] = "87.65.43.21";
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
struct inet_diag_req_v2 req = { struct inet_diag_req_v2 req = {
.sdiag_family = AF_INET, .sdiag_family = AF_INET,
.idiag_ext = 1 << (INET_DIAG_CONG - 1), .idiag_ext = 1 << (INET_DIAG_CONG - 1),
@ -492,6 +491,7 @@ test_inet_diag_req_v2(const int fd)
.idiag_cookie = { 0xdeadbeef, 0xbadc0ded } .idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
}, },
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
if (!inet_pton(AF_INET, address, &req.id.idiag_src) || if (!inet_pton(AF_INET, address, &req.id.idiag_src) ||
!inet_pton(AF_INET, address, &req.id.idiag_dst)) !inet_pton(AF_INET, address, &req.id.idiag_dst))
@ -519,7 +519,6 @@ static void
test_inet_diag_msg(const int fd) test_inet_diag_msg(const int fd)
{ {
const char address[] = "11.22.33.44"; const char address[] = "11.22.33.44";
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
struct inet_diag_msg msg = { struct inet_diag_msg msg = {
.idiag_family = AF_INET, .idiag_family = AF_INET,
.idiag_state = TCP_LISTEN, .idiag_state = TCP_LISTEN,
@ -537,6 +536,7 @@ test_inet_diag_msg(const int fd)
.idiag_uid = 0xdecefaeb, .idiag_uid = 0xdecefaeb,
.idiag_inode = 0xbadc0ded, .idiag_inode = 0xbadc0ded,
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
if (!inet_pton(AF_INET, address, &msg.id.idiag_src) || if (!inet_pton(AF_INET, address, &msg.id.idiag_src) ||
!inet_pton(AF_INET, address, &msg.id.idiag_dst)) !inet_pton(AF_INET, address, &msg.id.idiag_dst))
@ -570,7 +570,6 @@ static void
test_smc_diag_req(const int fd) test_smc_diag_req(const int fd)
{ {
const char address[] = "43.21.56.78"; const char address[] = "43.21.56.78";
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
struct smc_diag_req req = { struct smc_diag_req req = {
.diag_family = AF_SMC, .diag_family = AF_SMC,
.diag_ext = 1 << (SMC_DIAG_CONNINFO - 1), .diag_ext = 1 << (SMC_DIAG_CONNINFO - 1),
@ -581,6 +580,7 @@ test_smc_diag_req(const int fd)
.idiag_cookie = { 0xdeadbeef, 0xbadc0ded }, .idiag_cookie = { 0xdeadbeef, 0xbadc0ded },
}, },
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
if (!inet_pton(AF_INET, address, &req.id.idiag_src) || if (!inet_pton(AF_INET, address, &req.id.idiag_src) ||
!inet_pton(AF_INET, address, &req.id.idiag_dst)) !inet_pton(AF_INET, address, &req.id.idiag_dst))
@ -606,7 +606,6 @@ static void
test_smc_diag_msg(const int fd) test_smc_diag_msg(const int fd)
{ {
const char address[] = "34.87.12.90"; const char address[] = "34.87.12.90";
void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
struct smc_diag_msg msg = { struct smc_diag_msg msg = {
.diag_family = AF_SMC, .diag_family = AF_SMC,
.diag_state = SMC_ACTIVE, .diag_state = SMC_ACTIVE,
@ -621,6 +620,7 @@ test_smc_diag_msg(const int fd)
.diag_uid = 0xadcdfafc, .diag_uid = 0xadcdfafc,
.diag_inode = 0xbadc0ded, .diag_inode = 0xbadc0ded,
}; };
void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
if (!inet_pton(AF_INET, address, &msg.id.idiag_src) || if (!inet_pton(AF_INET, address, &msg.id.idiag_src) ||
!inet_pton(AF_INET, address, &msg.id.idiag_dst)) !inet_pton(AF_INET, address, &msg.id.idiag_dst))

View File

@ -69,7 +69,7 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct br_port_msg); const unsigned int hdrlen = sizeof(struct br_port_msg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -72,7 +72,12 @@ main(void)
const int fd = create_nl_socket(NETLINK_CRYPTO); const int fd = create_nl_socket(NETLINK_CRYPTO);
const unsigned int hdrlen = sizeof(struct crypto_user_alg); const unsigned int hdrlen = sizeof(struct crypto_user_alg);
void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); /*
* There are also other structures, but they are not bigger than
* DEFAULT_STRLEN so far.
*/
void *const nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + DEFAULT_STRLEN);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -67,7 +67,7 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct dcbmsg); const unsigned int hdrlen = sizeof(struct dcbmsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -80,7 +80,7 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct rtmsg); const unsigned int hdrlen = sizeof(struct rtmsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 8);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -69,7 +69,7 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct ifaddrlblmsg); const unsigned int hdrlen = sizeof(struct ifaddrlblmsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -83,9 +83,23 @@ main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
static const char address4[] = "12.34.56.78";
static const char address6[] = "12:34:56:78:90:ab:cd:ef";
static const struct ifa_cacheinfo ci = {
.ifa_prefered = 0xabcdefac,
.ifa_valid = 0xbcdadbca,
.cstamp = 0xcdabedba,
.tstamp = 0xdebabdac
};
struct in_addr a4;
struct in6_addr a6;
const uint32_t ifa_flags = IFA_F_SECONDARY | IFA_F_PERMANENT;
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct ifaddrmsg); const unsigned int hdrlen = sizeof(struct ifaddrmsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + MAX(sizeof(ci), sizeof(a6)));
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
@ -106,8 +120,6 @@ main(void)
print_quoted_hex(pattern, 4)); print_quoted_hex(pattern, 4));
SET_IFA_FAMILY(AF_INET); SET_IFA_FAMILY(AF_INET);
static const char address4[] = "12.34.56.78";
struct in_addr a4;
if (!inet_pton(AF_INET, address4, &a4)) if (!inet_pton(AF_INET, address4, &a4))
perror_msg_and_skip("inet_pton"); perror_msg_and_skip("inet_pton");
@ -118,8 +130,6 @@ main(void)
printf("%s", address4)); printf("%s", address4));
SET_IFA_FAMILY(AF_INET6); SET_IFA_FAMILY(AF_INET6);
static const char address6[] = "12:34:56:78:90:ab:cd:ef";
struct in6_addr a6;
if (!inet_pton(AF_INET6, address6, &a6)) if (!inet_pton(AF_INET6, address6, &a6))
perror_msg_and_skip("inet_pton"); perror_msg_and_skip("inet_pton");
@ -129,12 +139,6 @@ main(void)
IFA_ADDRESS, pattern, a6, IFA_ADDRESS, pattern, a6,
printf("%s", address6)); printf("%s", address6));
static const struct ifa_cacheinfo ci = {
.ifa_prefered = 0xabcdefac,
.ifa_valid = 0xbcdadbca,
.cstamp = 0xcdabedba,
.tstamp = 0xdebabdac
};
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_ifaddrmsg, print_ifaddrmsg, init_ifaddrmsg, print_ifaddrmsg,
IFA_CACHEINFO, pattern, ci, IFA_CACHEINFO, pattern, ci,
@ -144,7 +148,6 @@ main(void)
PRINT_FIELD_U(", ", ci, tstamp); PRINT_FIELD_U(", ", ci, tstamp);
printf("}")); printf("}"));
const uint32_t ifa_flags = IFA_F_SECONDARY | IFA_F_PERMANENT;
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_ifaddrmsg, print_ifaddrmsg, init_ifaddrmsg, print_ifaddrmsg,
IFA_FLAGS, pattern, ifa_flags, IFA_FLAGS, pattern, ifa_flags,

View File

@ -89,28 +89,6 @@ main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct ifinfomsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
char nla_type_str[256];
sprintf(nla_type_str, "%#x /* IFLA_??? */", nla_type);
TEST_NLATTR_(fd, nlh0, hdrlen,
init_ifinfomsg, print_ifinfomsg,
nla_type, nla_type_str,
4, pattern, 4,
print_quoted_hex(pattern, 4));
const int32_t netnsid = 0xacbdabda;
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_ifinfomsg, print_ifinfomsg,
IFLA_LINK_NETNSID, pattern, netnsid,
printf("%d", netnsid));
static const struct rtnl_link_stats st = { static const struct rtnl_link_stats st = {
.rx_packets = 0xabcdefac, .rx_packets = 0xabcdefac,
.tx_packets = 0xbcdacdab, .tx_packets = 0xbcdacdab,
@ -136,6 +114,29 @@ main(void)
.rx_compressed = 0xdeffadbd, .rx_compressed = 0xdeffadbd,
.tx_compressed = 0xefdadfab .tx_compressed = 0xefdadfab
}; };
const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct ifinfomsg);
void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(st));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
char nla_type_str[256];
sprintf(nla_type_str, "%#x /* IFLA_??? */", nla_type);
TEST_NLATTR_(fd, nlh0, hdrlen,
init_ifinfomsg, print_ifinfomsg,
nla_type, nla_type_str,
4, pattern, 4,
print_quoted_hex(pattern, 4));
const int32_t netnsid = 0xacbdabda;
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_ifinfomsg, print_ifinfomsg,
IFLA_LINK_NETNSID, pattern, netnsid,
printf("%d", netnsid));
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_ifinfomsg, print_ifinfomsg, init_ifinfomsg, print_ifinfomsg,
IFLA_STATS, pattern, st, IFLA_STATS, pattern, st,

View File

@ -84,19 +84,20 @@ main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
const uint16_t u16 = 0xabcd;
const uint64_t u64 = 0xabcdedeeefeafeab;
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN * 2 + sizeof(u64));
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
const uint16_t u16 = 0xabcd;
TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_ifinfomsg, print_ifinfomsg, init_ifinfomsg, print_ifinfomsg,
IFLA_BRPORT_PRIORITY, pattern, u16, IFLA_BRPORT_PRIORITY, pattern, u16,
printf("%u", u16)); printf("%u", u16));
const uint64_t u64 = 0xabcdedeeefeafeab;
TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_ifinfomsg, print_ifinfomsg, init_ifinfomsg, print_ifinfomsg,
IFLA_BRPORT_MESSAGE_AGE_TIMER, pattern, u64, IFLA_BRPORT_MESSAGE_AGE_TIMER, pattern, u64,

View File

@ -88,7 +88,7 @@ main(void)
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), 2 * NLA_HDRLEN + 8);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -87,13 +87,14 @@ main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
const int32_t num = 0xabacdbcd;
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(num));
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
const int32_t num = 0xabacdbcd;
TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_ifinfomsg, print_ifinfomsg, init_ifinfomsg, print_ifinfomsg,
IFLA_XDP_FD, pattern, num, IFLA_XDP_FD, pattern, num,

View File

@ -87,19 +87,46 @@ main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct inet_diag_msg);
void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
static const struct inet_diag_meminfo minfo = { static const struct inet_diag_meminfo minfo = {
.idiag_rmem = 0xfadcacdb, .idiag_rmem = 0xfadcacdb,
.idiag_wmem = 0xbdabcada, .idiag_wmem = 0xbdabcada,
.idiag_fmem = 0xbadbfafb, .idiag_fmem = 0xbadbfafb,
.idiag_tmem = 0xfdacdadf .idiag_tmem = 0xfdacdadf
}; };
static const struct tcpvegas_info vegas = {
.tcpv_enabled = 0xfadcacdb,
.tcpv_rttcnt = 0xbdabcada,
.tcpv_rtt = 0xbadbfafb,
.tcpv_minrtt = 0xfdacdadf
};
static const struct tcp_dctcp_info dctcp = {
.dctcp_enabled = 0xfdac,
.dctcp_ce_state = 0xfadc,
.dctcp_alpha = 0xbdabcada,
.dctcp_ab_ecn = 0xbadbfafb,
.dctcp_ab_tot = 0xfdacdadf
};
static const struct tcp_bbr_info bbr = {
.bbr_bw_lo = 0xfdacdadf,
.bbr_bw_hi = 0xfadcacdb,
.bbr_min_rtt = 0xbdabcada,
.bbr_pacing_gain = 0xbadbfafb,
.bbr_cwnd_gain = 0xfdacdadf
};
static const uint32_t mem[] = { 0xaffacbad, 0xffadbcab };
static uint32_t bigmem[SK_MEMINFO_VARS + 1];
static const uint32_t mark = 0xabdfadca;
static const uint8_t shutdown = 0xcd;
const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct inet_diag_msg);
void *const nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN +
MAX(sizeof(bigmem), DEFAULT_STRLEN));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_inet_diag_msg, print_inet_diag_msg, init_inet_diag_msg, print_inet_diag_msg,
INET_DIAG_MEMINFO, pattern, minfo, INET_DIAG_MEMINFO, pattern, minfo,
@ -109,12 +136,6 @@ main(void)
PRINT_FIELD_U(", ", minfo, idiag_tmem); PRINT_FIELD_U(", ", minfo, idiag_tmem);
printf("}")); printf("}"));
static const struct tcpvegas_info vegas = {
.tcpv_enabled = 0xfadcacdb,
.tcpv_rttcnt = 0xbdabcada,
.tcpv_rtt = 0xbadbfafb,
.tcpv_minrtt = 0xfdacdadf
};
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_inet_diag_msg, print_inet_diag_msg, init_inet_diag_msg, print_inet_diag_msg,
INET_DIAG_VEGASINFO, pattern, vegas, INET_DIAG_VEGASINFO, pattern, vegas,
@ -125,13 +146,6 @@ main(void)
printf("}")); printf("}"));
static const struct tcp_dctcp_info dctcp = {
.dctcp_enabled = 0xfdac,
.dctcp_ce_state = 0xfadc,
.dctcp_alpha = 0xbdabcada,
.dctcp_ab_ecn = 0xbadbfafb,
.dctcp_ab_tot = 0xfdacdadf
};
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_inet_diag_msg, print_inet_diag_msg, init_inet_diag_msg, print_inet_diag_msg,
INET_DIAG_DCTCPINFO, pattern, dctcp, INET_DIAG_DCTCPINFO, pattern, dctcp,
@ -142,13 +156,6 @@ main(void)
PRINT_FIELD_U(", ", dctcp, dctcp_ab_tot); PRINT_FIELD_U(", ", dctcp, dctcp_ab_tot);
printf("}")); printf("}"));
static const struct tcp_bbr_info bbr = {
.bbr_bw_lo = 0xfdacdadf,
.bbr_bw_hi = 0xfadcacdb,
.bbr_min_rtt = 0xbdabcada,
.bbr_pacing_gain = 0xbadbfafb,
.bbr_cwnd_gain = 0xfdacdadf
};
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_inet_diag_msg, print_inet_diag_msg, init_inet_diag_msg, print_inet_diag_msg,
INET_DIAG_BBRINFO, pattern, bbr, INET_DIAG_BBRINFO, pattern, bbr,
@ -159,12 +166,10 @@ main(void)
PRINT_FIELD_U(", ", bbr, bbr_cwnd_gain); PRINT_FIELD_U(", ", bbr, bbr_cwnd_gain);
printf("}")); printf("}"));
static const uint32_t mem[] = { 0xaffacbad, 0xffadbcab };
TEST_NLATTR_ARRAY(fd, nlh0, hdrlen, TEST_NLATTR_ARRAY(fd, nlh0, hdrlen,
init_inet_diag_msg, print_inet_diag_msg, init_inet_diag_msg, print_inet_diag_msg,
INET_DIAG_SKMEMINFO, pattern, mem, print_uint); INET_DIAG_SKMEMINFO, pattern, mem, print_uint);
static uint32_t bigmem[SK_MEMINFO_VARS + 1];
memcpy(bigmem, pattern, sizeof(bigmem)); memcpy(bigmem, pattern, sizeof(bigmem));
TEST_NLATTR(fd, nlh0, hdrlen, init_inet_diag_msg, print_inet_diag_msg, TEST_NLATTR(fd, nlh0, hdrlen, init_inet_diag_msg, print_inet_diag_msg,
@ -176,7 +181,6 @@ main(void)
} }
printf(", ...]")); printf(", ...]"));
static const uint32_t mark = 0xabdfadca;
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_inet_diag_msg, print_inet_diag_msg, init_inet_diag_msg, print_inet_diag_msg,
INET_DIAG_MARK, pattern, mark, INET_DIAG_MARK, pattern, mark,
@ -187,7 +191,6 @@ main(void)
INET_DIAG_CLASS_ID, pattern, mark, INET_DIAG_CLASS_ID, pattern, mark,
printf("%u", mark)); printf("%u", mark));
static const uint8_t shutdown = 0xcd;
TEST_NLATTR(fd, nlh0, hdrlen, TEST_NLATTR(fd, nlh0, hdrlen,
init_inet_diag_msg, print_inet_diag_msg, INET_DIAG_SHUTDOWN, init_inet_diag_msg, print_inet_diag_msg, INET_DIAG_SHUTDOWN,
sizeof(shutdown), &shutdown, sizeof(shutdown), sizeof(shutdown), &shutdown, sizeof(shutdown),

View File

@ -86,7 +86,7 @@ main(void)
int fd = create_nl_socket(NETLINK_SOCK_DIAG); int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct inet_diag_req); const unsigned int hdrlen = sizeof(struct inet_diag_req);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -407,7 +407,10 @@ main(void)
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
int fd = create_nl_socket(NETLINK_SOCK_DIAG); int fd = create_nl_socket(NETLINK_SOCK_DIAG);
nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN +
sizeof(struct inet_diag_bc_op) +
sizeof(struct inet_diag_hostcond) +
sizeof(struct in6_addr) + DEFAULT_STRLEN);
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
test_inet_diag_bc_op(fd); test_inet_diag_bc_op(fd);

View File

@ -99,7 +99,12 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4
# ifdef HAVE_STRUCT_BR_MDB_ENTRY
- 4 + NLA_HDRLEN * 2 + sizeof(struct nlattr)
+ sizeof(struct br_mdb_entry)
# endif
);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -87,25 +87,27 @@ main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
const int fd = create_nl_socket(NETLINK_ROUTE);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
const uint32_t ifindex = ifindex_lo(); const uint32_t ifindex = ifindex_lo();
TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_br_port_msg, print_br_port_msg,
MDBA_ROUTER_PORT, pattern, ifindex,
printf(IFINDEX_LO_STR));
const uint8_t type = MDB_RTR_TYPE_DISABLED; const uint8_t type = MDB_RTR_TYPE_DISABLED;
static const struct nlattr nla = { static const struct nlattr nla = {
.nla_len = NLA_HDRLEN + sizeof(type), .nla_len = NLA_HDRLEN + sizeof(type),
.nla_type = MDBA_ROUTER_PATTR_TYPE .nla_type = MDBA_ROUTER_PATTR_TYPE
}; };
char buf[NLMSG_ALIGN(ifindex) + NLA_HDRLEN + sizeof(type)]; char buf[NLMSG_ALIGN(ifindex) + NLA_HDRLEN + sizeof(type)];
const int fd = create_nl_socket(NETLINK_ROUTE);
void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(buf));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_br_port_msg, print_br_port_msg,
MDBA_ROUTER_PORT, pattern, ifindex,
printf(IFINDEX_LO_STR));
memcpy(buf, &ifindex, sizeof(ifindex)); memcpy(buf, &ifindex, sizeof(ifindex));
memcpy(buf + NLMSG_ALIGN(ifindex), &nla, sizeof(nla)); memcpy(buf + NLMSG_ALIGN(ifindex), &nla, sizeof(nla));
memcpy(buf + NLMSG_ALIGN(ifindex) + NLA_HDRLEN, &type, sizeof(type)); memcpy(buf + NLMSG_ALIGN(ifindex) + NLA_HDRLEN, &type, sizeof(type));

View File

@ -77,7 +77,8 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct ndmsg); const unsigned int hdrlen = sizeof(struct ndmsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(struct nda_cacheinfo));
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -68,7 +68,7 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct ndtmsg); const unsigned int hdrlen = sizeof(struct ndtmsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 11 * 8);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -66,7 +66,7 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct netconfmsg); const unsigned int hdrlen = sizeof(struct netconfmsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -76,27 +76,32 @@ main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct netlink_diag_msg);
void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
static const unsigned long groups[] = { static const unsigned long groups[] = {
(unsigned long) 0xdeadbeefbadc0dedULL, (unsigned long) 0xdeadbeefbadc0dedULL,
(unsigned long) 0xdeadbeefbadc0dedULL (unsigned long) 0xdeadbeefbadc0dedULL
}; };
TEST_NLATTR_ARRAY(fd, nlh0, hdrlen,
init_netlink_diag_msg, print_netlink_diag_msg,
NETLINK_DIAG_GROUPS, pattern, groups, print_xlong);
static const struct netlink_diag_ring ndr = { static const struct netlink_diag_ring ndr = {
.ndr_block_size = 0xfabfabdc, .ndr_block_size = 0xfabfabdc,
.ndr_block_nr = 0xabcdabda, .ndr_block_nr = 0xabcdabda,
.ndr_frame_size = 0xcbadbafa, .ndr_frame_size = 0xcbadbafa,
.ndr_frame_nr = 0xdbcafadb .ndr_frame_nr = 0xdbcafadb
}; };
static const uint32_t flags =
NDIAG_FLAG_CB_RUNNING | NDIAG_FLAG_PKTINFO;
const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct netlink_diag_msg);
void *const nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN +
MAX(sizeof(groups), sizeof(ndr)));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
TEST_NLATTR_ARRAY(fd, nlh0, hdrlen,
init_netlink_diag_msg, print_netlink_diag_msg,
NETLINK_DIAG_GROUPS, pattern, groups, print_xlong);
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_netlink_diag_msg, print_netlink_diag_msg, init_netlink_diag_msg, print_netlink_diag_msg,
NETLINK_DIAG_RX_RING, pattern, ndr, NETLINK_DIAG_RX_RING, pattern, ndr,
@ -106,8 +111,6 @@ main(void)
PRINT_FIELD_U(", ", ndr, ndr_frame_nr); PRINT_FIELD_U(", ", ndr, ndr_frame_nr);
printf("}")); printf("}"));
static const uint32_t flags =
NDIAG_FLAG_CB_RUNNING | NDIAG_FLAG_PKTINFO;
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_netlink_diag_msg, print_netlink_diag_msg, init_netlink_diag_msg, print_netlink_diag_msg,
NETLINK_DIAG_FLAGS, pattern, flags, NETLINK_DIAG_FLAGS, pattern, flags,

View File

@ -69,11 +69,13 @@ main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
static const uint8_t cookie[] = { 0xab, 0xfe };
const int fd = create_nl_socket(NETLINK_SOCK_DIAG); const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct nlmsgerr); const unsigned int hdrlen = sizeof(struct nlmsgerr);
void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *const nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(cookie));
static const uint8_t cookie[] = { 0xab, 0xfe };
TEST_NLATTR(fd, nlh0, hdrlen, TEST_NLATTR(fd, nlh0, hdrlen,
init_nlmsgerr, print_nlmsgerr, init_nlmsgerr, print_nlmsgerr,
NLMSGERR_ATTR_COOKIE, NLMSGERR_ATTR_COOKIE,

View File

@ -98,13 +98,6 @@ main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct packet_diag_msg);
void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
static const struct packet_diag_info pinfo = { static const struct packet_diag_info pinfo = {
.pdi_index = 0xabcddafa, .pdi_index = 0xabcddafa,
.pdi_version = 0xbabcdafb, .pdi_version = 0xbabcdafb,
@ -113,16 +106,6 @@ main(void)
.pdi_tstamp = 0xeafbaadf, .pdi_tstamp = 0xeafbaadf,
.pdi_flags = PDI_RUNNING .pdi_flags = PDI_RUNNING
}; };
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_packet_diag_msg, print_packet_diag_msg,
PACKET_DIAG_INFO, pattern, pinfo,
PRINT_FIELD_U("{", pinfo, pdi_index);
PRINT_FIELD_U(", ", pinfo, pdi_version);
PRINT_FIELD_U(", ", pinfo, pdi_reserve);
PRINT_FIELD_U(", ", pinfo, pdi_copy_thresh);
PRINT_FIELD_U(", ", pinfo, pdi_tstamp);
printf(", pdi_flags=PDI_RUNNING}"));
const struct packet_diag_mclist dml[] = { const struct packet_diag_mclist dml[] = {
{ {
.pdmc_index = ifindex_lo(), .pdmc_index = ifindex_lo(),
@ -139,11 +122,6 @@ main(void)
.pdmc_addr = "5678" .pdmc_addr = "5678"
} }
}; };
TEST_NLATTR_ARRAY(fd, nlh0, hdrlen,
init_packet_diag_msg, print_packet_diag_msg,
PACKET_DIAG_MCLIST, pattern, dml,
print_packet_diag_mclist);
static const struct packet_diag_ring pdr = { static const struct packet_diag_ring pdr = {
.pdr_block_size = 0xabcdafed, .pdr_block_size = 0xabcdafed,
.pdr_block_nr = 0xbcadefae, .pdr_block_nr = 0xbcadefae,
@ -153,6 +131,30 @@ main(void)
.pdr_sizeof_priv = 0xfeadeacd, .pdr_sizeof_priv = 0xfeadeacd,
.pdr_features = 0xadebadea .pdr_features = 0xadebadea
}; };
int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct packet_diag_msg);
void *const nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(dml));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_packet_diag_msg, print_packet_diag_msg,
PACKET_DIAG_INFO, pattern, pinfo,
PRINT_FIELD_U("{", pinfo, pdi_index);
PRINT_FIELD_U(", ", pinfo, pdi_version);
PRINT_FIELD_U(", ", pinfo, pdi_reserve);
PRINT_FIELD_U(", ", pinfo, pdi_copy_thresh);
PRINT_FIELD_U(", ", pinfo, pdi_tstamp);
printf(", pdi_flags=PDI_RUNNING}"));
TEST_NLATTR_ARRAY(fd, nlh0, hdrlen,
init_packet_diag_msg, print_packet_diag_msg,
PACKET_DIAG_MCLIST, pattern, dml,
print_packet_diag_mclist);
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_packet_diag_msg, print_packet_diag_msg, init_packet_diag_msg, print_packet_diag_msg,
PACKET_DIAG_RX_RING, pattern, pdr, PACKET_DIAG_RX_RING, pattern, pdr,

View File

@ -66,13 +66,14 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct rtgenmsg); const unsigned int hdrlen = sizeof(struct rtgenmsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
char nla_type_str[256];
void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(nla_type_str));
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
char nla_type_str[256];
sprintf(nla_type_str, "%#x /* NETNSA_??? */", nla_type); sprintf(nla_type_str, "%#x /* NETNSA_??? */", nla_type);
TEST_NLATTR_(fd, nlh0, hdrlen, TEST_NLATTR_(fd, nlh0, hdrlen,
init_rtgenmsg, print_rtgenmsg, init_rtgenmsg, print_rtgenmsg,

View File

@ -81,13 +81,14 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct rtmsg); const unsigned int hdrlen = sizeof(struct rtmsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
char nla_type_str[256];
void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(nla_type_str));
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
const unsigned int nla_type = 0xffff & NLA_TYPE_MASK;
char nla_type_str[256];
sprintf(nla_type_str, "%#x /* RTA_??? */", nla_type); sprintf(nla_type_str, "%#x /* RTA_??? */", nla_type);
TEST_NLATTR_(fd, nlh0, hdrlen, TEST_NLATTR_(fd, nlh0, hdrlen,
init_rtmsg, print_rtmsg, init_rtmsg, print_rtmsg,

View File

@ -97,13 +97,6 @@ int main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct smc_diag_msg);
void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
static const struct smc_diag_conninfo cinfo = { static const struct smc_diag_conninfo cinfo = {
.token = 0xabcdefac, .token = 0xabcdefac,
.sndbuf_size = 0xbcdaefad, .sndbuf_size = 0xbcdaefad,
@ -149,6 +142,25 @@ int main(void)
.count = 0xcdedbad7 .count = 0xcdedbad7
} }
}; };
static const struct smc_diag_lgrinfo linfo = {
.lnk[0] = {
.link_id = 0xaf,
.ibport = 0xfa,
.ibname = "123",
.gid = "456",
.peer_gid = "789"
},
.role = SMC_CLNT
};
int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct smc_diag_msg);
void *const nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN +
MAX(sizeof(cinfo), sizeof(linfo)));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_smc_diag_msg, print_smc_diag_msg, init_smc_diag_msg, print_smc_diag_msg,
@ -170,16 +182,6 @@ int main(void)
PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_fin); PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_fin);
printf("}")); printf("}"));
static const struct smc_diag_lgrinfo linfo = {
.lnk[0] = {
.link_id = 0xaf,
.ibport = 0xfa,
.ibname = "123",
.gid = "456",
.peer_gid = "789"
},
.role = SMC_CLNT
};
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_smc_diag_msg, print_smc_diag_msg, init_smc_diag_msg, print_smc_diag_msg,
SMC_DIAG_LGRINFO, pattern, linfo, SMC_DIAG_LGRINFO, pattern, linfo,

View File

@ -77,7 +77,7 @@ main(void)
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 8 * 5);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -87,7 +87,11 @@ main(void)
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4
#ifdef HAVE_STRUCT_TC_SIZESPEC
- 4 + sizeof(struct tc_sizespec)
#endif
);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -62,7 +62,7 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct tcamsg); const unsigned int hdrlen = sizeof(struct tcamsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen), NLA_HDRLEN + 4);
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -68,7 +68,8 @@ main(void)
const int fd = create_nl_socket(NETLINK_ROUTE); const int fd = create_nl_socket(NETLINK_ROUTE);
const unsigned int hdrlen = sizeof(struct tcmsg); const unsigned int hdrlen = sizeof(struct tcmsg);
void *nlh0 = tail_alloc(NLMSG_SPACE(hdrlen)); void *nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(struct tc_stats));
static char pattern[4096]; static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1); fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);

View File

@ -75,17 +75,24 @@ main(void)
{ {
skip_if_unavailable("/proc/self/fd/"); skip_if_unavailable("/proc/self/fd/");
const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct unix_diag_msg);
void *const nlh0 = tail_alloc(NLMSG_SPACE(hdrlen));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
static const struct unix_diag_vfs uv = { static const struct unix_diag_vfs uv = {
.udiag_vfs_dev = 0xabcddafa, .udiag_vfs_dev = 0xabcddafa,
.udiag_vfs_ino = 0xbafabcda .udiag_vfs_ino = 0xbafabcda
}; };
static const struct unix_diag_rqlen rql = {
.udiag_rqueue = 0xfabdcdad,
.udiag_wqueue = 0xbacdadcf
};
static const uint32_t inode[] = { 0xadbcadbc, 0xfabdcdac };
const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
const unsigned int hdrlen = sizeof(struct unix_diag_msg);
void *const nlh0 = midtail_alloc(NLMSG_SPACE(hdrlen),
NLA_HDRLEN + sizeof(inode));
static char pattern[4096];
fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_unix_diag_msg, print_unix_diag_msg, init_unix_diag_msg, print_unix_diag_msg,
UNIX_DIAG_VFS, pattern, uv, UNIX_DIAG_VFS, pattern, uv,
@ -95,10 +102,6 @@ main(void)
PRINT_FIELD_U(", ", uv, udiag_vfs_ino); PRINT_FIELD_U(", ", uv, udiag_vfs_ino);
printf("}")); printf("}"));
static const struct unix_diag_rqlen rql = {
.udiag_rqueue = 0xfabdcdad,
.udiag_wqueue = 0xbacdadcf
};
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen, TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
init_unix_diag_msg, print_unix_diag_msg, init_unix_diag_msg, print_unix_diag_msg,
UNIX_DIAG_RQLEN, pattern, rql, UNIX_DIAG_RQLEN, pattern, rql,
@ -106,7 +109,6 @@ main(void)
PRINT_FIELD_U(", ", rql, udiag_wqueue); PRINT_FIELD_U(", ", rql, udiag_wqueue);
printf("}")); printf("}"));
static const uint32_t inode[] = { 0xadbcadbc, 0xfabdcdac };
TEST_NLATTR_ARRAY(fd, nlh0, hdrlen, TEST_NLATTR_ARRAY(fd, nlh0, hdrlen,
init_unix_diag_msg, print_unix_diag_msg, init_unix_diag_msg, print_unix_diag_msg,
UNIX_DIAG_ICONS, pattern, inode, print_uint); UNIX_DIAG_ICONS, pattern, inode, print_uint);

View File

@ -117,6 +117,9 @@ void *tail_alloc(const size_t)
void *tail_memdup(const void *, const size_t) void *tail_memdup(const void *, const size_t)
ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((2)); ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((2));
#define midtail_alloc(after_, before_) \
((void *) ((char *) tail_alloc(((before_) + (after_))) + (before_)))
/* /*
* Allocate an object of the specified type at the end * Allocate an object of the specified type at the end
* of a mapped memory region. * of a mapped memory region.