]> granicus.if.org Git - strace/commitdiff
tests: introduce midtail_alloc and use it in netlink tests
authorEugene Syromyatnikov <evgsyr@gmail.com>
Tue, 8 May 2018 05:10:16 +0000 (07:10 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 9 May 2018 22:01:45 +0000 (22:01 +0000)
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>
36 files changed:
tests/netlink_crypto.c
tests/netlink_netfilter.c
tests/netlink_protocol.c
tests/netlink_route.c
tests/netlink_selinux.c
tests/netlink_sock_diag.c
tests/nlattr_br_port_msg.c
tests/nlattr_crypto_user_alg.c
tests/nlattr_dcbmsg.c
tests/nlattr_fib_rule_hdr.c
tests/nlattr_ifaddrlblmsg.c
tests/nlattr_ifaddrmsg.c
tests/nlattr_ifinfomsg.c
tests/nlattr_ifla_brport.c
tests/nlattr_ifla_port.c
tests/nlattr_ifla_xdp.c
tests/nlattr_inet_diag_msg.c
tests/nlattr_inet_diag_req_compat.c
tests/nlattr_inet_diag_req_v2.c
tests/nlattr_mdba_mdb_entry.c
tests/nlattr_mdba_router_port.c
tests/nlattr_ndmsg.c
tests/nlattr_ndtmsg.c
tests/nlattr_netconfmsg.c
tests/nlattr_netlink_diag_msg.c
tests/nlattr_nlmsgerr.c
tests/nlattr_packet_diag_msg.c
tests/nlattr_rtgenmsg.c
tests/nlattr_rtmsg.c
tests/nlattr_smc_diag_msg.c
tests/nlattr_tc_stats.c
tests/nlattr_tca_stab.c
tests/nlattr_tcamsg.c
tests/nlattr_tcmsg.c
tests/nlattr_unix_diag_msg.c
tests/tests.h

index d15c17cf185a87937b74fbe39b67e047c356b1d3..f6d13419bdf4493286a56648f3adb2519499c41a 100644 (file)
@@ -98,8 +98,6 @@ test_nlmsg_flags(const int fd)
 static void
 test_crypto_msg_newalg(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
-
        struct crypto_user_alg alg = {
                .cru_name = "abcd",
                .cru_driver_name = "efgh",
@@ -109,6 +107,8 @@ test_crypto_msg_newalg(const int fd)
                .cru_refcnt = 0xbcacfacd,
                .cru_flags = 0xefacdbad
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(alg));
+
        TEST_NETLINK_OBJECT_EX(fd, nlh0,
                               CRYPTO_MSG_NEWALG, NLM_F_REQUEST,
                               alg, print_quoted_memory,
@@ -149,7 +149,7 @@ test_crypto_msg_newalg(const int fd)
 static void
 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,
                      0xffff, "0xffff /* CRYPTO_MSG_??? */",
index 57532f5295a9781a205f3b0a970120d6d42b0eae..2842e15484712a4286780e674ae9df7435f070d4 100644 (file)
@@ -88,8 +88,8 @@ test_nlmsg_type(const int fd)
 static void
 test_nlmsg_done(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const int num = 0xabcdefad;
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(num));
 
        TEST_NETLINK(fd, nlh0, NLMSG_DONE, NLM_F_REQUEST,
                     sizeof(num), &num, sizeof(num),
@@ -99,13 +99,21 @@ test_nlmsg_done(const int fd)
 static void
 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 = {
                .nfgen_family = AF_UNIX,
                .version = NFNETLINK_V0,
                .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,
                                NFNL_SUBSYS_NFTABLES << 8 | NFT_MSG_NEWTABLE,
@@ -150,8 +158,6 @@ test_nfgenmsg(const int fd)
                     printf(", version=NFNETLINK_V0");
                     printf(", res_id=htons(%d)", NFNL_SUBSYS_NFTABLES));
 
-       char str_buf[NLMSG_ALIGN(sizeof(msg)) + 4];
-
        msg.res_id = htons(0xabcd);
        memcpy(str_buf, &msg, sizeof(msg));
        memcpy(str_buf + NLMSG_ALIGN(sizeof(msg)), "1234", 4);
@@ -165,12 +171,6 @@ test_nfgenmsg(const int fd)
                            ", \"\\x31\\x32\\x33\\x34\"", 0xabcd));
 # 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);
        memcpy(nla_buf, &msg, sizeof(msg));
        memcpy(nla_buf + NLMSG_ALIGN(sizeof(msg)), &nla, sizeof(nla));
index be1a6528a95a335e302d93b640bbcd56815ed0c8..b01ac70578cdb8d4399b8dfcecb216694614f233 100644 (file)
@@ -203,7 +203,7 @@ test_nlmsgerr(const int fd)
 {
        struct nlmsgerr *err;
        struct nlmsghdr *nlh;
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(*err) + 4);
        long rc;
 
        /* error message without enough room for the error code */
@@ -318,9 +318,9 @@ static void
 test_nlmsg_done(const int fd)
 {
        struct nlmsghdr *nlh;
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
-       long rc;
        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 */
        nlh = nlh0;
index a1c7d1f8926954ffd67cf4df077a50687211c536..3a5ba39a09cc6dd443b354e33a7d1fb1bf3c0cc2 100644 (file)
@@ -143,8 +143,8 @@ test_nlmsg_flags(const int fd)
 static void
 test_nlmsg_done(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const int num = 0xabcdefad;
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(num));
 
        TEST_NETLINK(fd, nlh0, NLMSG_DONE, NLM_F_REQUEST,
                     sizeof(num), &num, sizeof(num),
@@ -154,10 +154,11 @@ test_nlmsg_done(const int fd)
 static void
 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 */
-       uint8_t family = 0;
        TEST_NETLINK_(fd, nlh0,
                      0xffff, "0xffff /* RTM_??? */",
                      NLM_F_REQUEST, "NLM_F_REQUEST",
@@ -180,7 +181,6 @@ test_rtnl_unspec(const int fd)
                      printf("%p", NLMSG_DATA(TEST_NETLINK_nlh)));
 
        /* unspecified family and string */
-       char buf[sizeof(family) + 4];
        family = 0;
        memcpy(buf, &family, sizeof(family));
        memcpy(buf + sizeof(family), "1234", 4);
@@ -204,7 +204,6 @@ test_rtnl_unspec(const int fd)
 static void
 test_rtnl_link(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const struct ifinfomsg ifinfo = {
                .ifi_family = AF_UNIX,
                .ifi_type = ARPHRD_LOOPBACK,
@@ -212,6 +211,7 @@ test_rtnl_link(const int fd)
                .ifi_flags = IFF_UP,
                .ifi_change = 0xfabcdeba
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(ifinfo));
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETLINK, ifinfo,
                      printf("{ifi_family=AF_UNIX"),
@@ -225,7 +225,6 @@ test_rtnl_link(const int fd)
 static void
 test_rtnl_addr(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const struct ifaddrmsg msg = {
                .ifa_family = AF_UNIX,
                .ifa_prefixlen = 0xde,
@@ -233,6 +232,7 @@ test_rtnl_addr(const int fd)
                .ifa_scope = RT_SCOPE_UNIVERSE,
                .ifa_index = ifindex_lo()
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETADDR, msg,
                      printf("{ifa_family=AF_UNIX"),
@@ -246,7 +246,6 @@ test_rtnl_addr(const int fd)
 static void
 test_rtnl_route(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        static const struct rtmsg msg = {
                .rtm_family = AF_UNIX,
                .rtm_dst_len = 0xaf,
@@ -258,6 +257,7 @@ test_rtnl_route(const int fd)
                .rtm_type = RTN_LOCAL,
                .rtm_flags = RTM_F_NOTIFY
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETROUTE, msg,
                      printf("{rtm_family=AF_UNIX"),
@@ -275,7 +275,6 @@ test_rtnl_route(const int fd)
 static void
 test_rtnl_rule(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        struct rtmsg msg = {
                .rtm_family = AF_UNIX,
                .rtm_dst_len = 0xaf,
@@ -285,6 +284,7 @@ test_rtnl_rule(const int fd)
                .rtm_type = FR_ACT_TO_TBL,
                .rtm_flags = FIB_RULE_INVERT
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETRULE, msg,
                      printf("{family=AF_UNIX"),
@@ -301,7 +301,6 @@ test_rtnl_rule(const int fd)
 static void
 test_rtnl_neigh(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const struct ndmsg msg = {
                .ndm_family = AF_UNIX,
                .ndm_ifindex = ifindex_lo(),
@@ -309,6 +308,7 @@ test_rtnl_neigh(const int fd)
                .ndm_flags = NTF_PROXY,
                .ndm_type = RTN_UNSPEC
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETNEIGH, msg,
                      printf("{ndm_family=AF_UNIX"),
@@ -321,10 +321,10 @@ test_rtnl_neigh(const int fd)
 static void
 test_rtnl_neightbl(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        static const struct ndtmsg msg = {
                .ndtm_family = AF_NETLINK
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NETLINK(fd, nlh0,
                     RTM_GETNEIGHTBL, NLM_F_REQUEST,
@@ -335,7 +335,6 @@ test_rtnl_neightbl(const int fd)
 static void
 test_rtnl_tc(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const struct tcmsg msg = {
                .tcm_family = AF_UNIX,
                .tcm_ifindex = ifindex_lo(),
@@ -343,6 +342,7 @@ test_rtnl_tc(const int fd)
                .tcm_parent = 0xafbcadab,
                .tcm_info = 0xbcaedafa
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETQDISC, msg,
                      printf("{tcm_family=AF_UNIX"),
@@ -356,10 +356,10 @@ test_rtnl_tc(const int fd)
 static void
 test_rtnl_tca(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        struct tcamsg msg = {
                .tca_family = AF_INET
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NETLINK(fd, nlh0,
                     RTM_GETACTION, NLM_F_REQUEST,
@@ -371,7 +371,6 @@ test_rtnl_tca(const int fd)
 static void
 test_rtnl_addrlabel(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const struct ifaddrlblmsg msg = {
                .ifal_family = AF_UNIX,
                .ifal_prefixlen = 0xaf,
@@ -379,6 +378,7 @@ test_rtnl_addrlabel(const int fd)
                .ifal_index = ifindex_lo(),
                .ifal_seq = 0xfadcdafb
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETADDRLABEL, msg,
                      printf("{ifal_family=AF_UNIX"),
@@ -394,11 +394,11 @@ test_rtnl_addrlabel(const int fd)
 static void
 test_rtnl_dcb(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        static const struct dcbmsg msg = {
                .dcb_family = AF_UNIX,
                .cmd = DCB_CMD_UNDEFINED
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETDCB, msg,
                      printf("{dcb_family=AF_UNIX"),
@@ -410,10 +410,10 @@ test_rtnl_dcb(const int fd)
 static void
 test_rtnl_netconf(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        static const struct netconfmsg msg = {
                .ncm_family = AF_INET
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NETLINK(fd, nlh0,
                     RTM_GETNETCONF, NLM_F_REQUEST,
@@ -426,11 +426,11 @@ test_rtnl_netconf(const int fd)
 static void
 test_rtnl_mdb(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        const struct br_port_msg msg = {
                .family = AF_UNIX,
                .ifindex = ifindex_lo()
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NL_ROUTE(fd, nlh0, RTM_GETMDB, msg,
                      printf("{family=AF_UNIX"),
@@ -442,10 +442,10 @@ test_rtnl_mdb(const int fd)
 static void
 test_rtnl_nsid(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        static const struct rtgenmsg msg = {
                .rtgen_family = AF_UNIX
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        TEST_NETLINK(fd, nlh0,
                     RTM_GETNSID, NLM_F_REQUEST,
index 2d768222f86b07997022df3786d68b2dadca9338..43922013d89039236df6f60fb9ecacafdf7516bc 100644 (file)
@@ -53,7 +53,7 @@ test_nlmsg_type(const int fd)
 static void
 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,
                      0xffff, "0xffff /* SELNL_MSG_??? */",
@@ -65,11 +65,11 @@ test_selnl_msg_unspec(const int fd)
 static void
 test_selnl_msg_setenforce(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
-
        static const struct selnl_msg_setenforce msg = {
                .val = 0xfbdcdfab
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
+
        TEST_NETLINK_OBJECT(fd, nlh0,
                            SELNL_MSG_SETENFORCE, NLM_F_REQUEST, msg,
                            PRINT_FIELD_D("{", msg, val);
@@ -79,11 +79,11 @@ test_selnl_msg_setenforce(const int fd)
 static void
 test_selnl_msg_policyload(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
-
        static const struct selnl_msg_policyload msg = {
                .seqno = 0xabdcfabc
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
+
        TEST_NETLINK_OBJECT(fd, nlh0,
                            SELNL_MSG_POLICYLOAD, NLM_F_REQUEST, msg,
                            PRINT_FIELD_U("{", msg, seqno);
index c2ebf129cdcf3235154582198680ee0e6a421588..c9e1232f94a7c0eefc42d65d73ad4fdecfed0983 100644 (file)
@@ -127,10 +127,11 @@ test_nlmsg_flags(const int fd)
 static void
 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 */
-       uint8_t family = 0;
        TEST_NETLINK(fd, nlh0,
                     SOCK_DIAG_BY_FAMILY,
                     NLM_F_REQUEST,
@@ -153,7 +154,6 @@ test_odd_family_req(const int fd)
                     printf("%p", NLMSG_DATA(TEST_NETLINK_nlh)));
 
        /* unspecified family and string */
-       char buf[sizeof(family) + 4];
        family = 0;
        memcpy(buf, &family, sizeof(family));
        memcpy(buf + sizeof(family), "1234", 4);
@@ -177,10 +177,11 @@ test_odd_family_req(const int fd)
 static void
 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 */
-       uint8_t family = 0;
        TEST_NETLINK(fd, nlh0,
                     SOCK_DIAG_BY_FAMILY, NLM_F_DUMP,
                     sizeof(family), &family, sizeof(family),
@@ -200,7 +201,6 @@ test_odd_family_msg(const int fd)
                     printf("%p", NLMSG_DATA(TEST_NETLINK_nlh)));
 
        /* unspecified family and string */
-       char buf[sizeof(family) + 4];
        family = 0;
        memcpy(buf, &family, sizeof(family));
        memcpy(buf + sizeof(family), "1234", 4);
@@ -222,7 +222,6 @@ test_odd_family_msg(const int fd)
 static void
 test_unix_diag_req(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        static const struct unix_diag_req req = {
                .sdiag_family = AF_UNIX,
                .sdiag_protocol = 253,
@@ -231,6 +230,7 @@ test_unix_diag_req(const int fd)
                .udiag_show = UDIAG_SHOW_NAME,
                .udiag_cookie = { 0xdeadbeef, 0xbadc0ded }
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
        TEST_SOCK_DIAG(fd, nlh0, AF_UNIX,
                       SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req,
                       printf("{sdiag_family=AF_UNIX"),
@@ -245,7 +245,6 @@ test_unix_diag_req(const int fd)
 static void
 test_unix_diag_msg(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        static const struct unix_diag_msg msg = {
                .udiag_family = AF_UNIX,
                .udiag_type = SOCK_STREAM,
@@ -253,6 +252,7 @@ test_unix_diag_msg(const int fd)
                .udiag_ino = 0xfacefeed,
                .udiag_cookie = { 0xdeadbeef, 0xbadc0ded }
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
        TEST_SOCK_DIAG(fd, nlh0, AF_UNIX,
                       SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg,
                       printf("{udiag_family=AF_UNIX"),
@@ -266,7 +266,6 @@ test_unix_diag_msg(const int fd)
 static void
 test_netlink_diag_req(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        struct netlink_diag_req req = {
                .sdiag_family = AF_NETLINK,
                .sdiag_protocol = NDIAG_PROTO_ALL,
@@ -274,6 +273,7 @@ test_netlink_diag_req(const int fd)
                .ndiag_show = NDIAG_SHOW_MEMINFO,
                .ndiag_cookie = { 0xdeadbeef, 0xbadc0ded }
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
        TEST_SOCK_DIAG(fd, nlh0, AF_NETLINK,
                       SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req,
                       printf("{sdiag_family=AF_NETLINK"),
@@ -298,7 +298,6 @@ test_netlink_diag_req(const int fd)
 static void
 test_netlink_diag_msg(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        static const struct netlink_diag_msg msg = {
                .ndiag_family = AF_NETLINK,
                .ndiag_type = SOCK_RAW,
@@ -310,6 +309,7 @@ test_netlink_diag_msg(const int fd)
                .ndiag_ino = 0xdaeefacd,
                .ndiag_cookie = { 0xbadc0ded, 0xdeadbeef }
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
        TEST_SOCK_DIAG(fd, nlh0, AF_NETLINK,
                       SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg,
                       printf("{ndiag_family=AF_NETLINK"),
@@ -327,7 +327,6 @@ test_netlink_diag_msg(const int fd)
 static void
 test_packet_diag_req(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        static const struct packet_diag_req req = {
                .sdiag_family = AF_PACKET,
                .sdiag_protocol = ETH_P_LOOP,
@@ -335,6 +334,7 @@ test_packet_diag_req(const int fd)
                .pdiag_show = PACKET_SHOW_INFO,
                .pdiag_cookie = { 0xdeadbeef, 0xbadc0ded }
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
        TEST_SOCK_DIAG(fd, nlh0, AF_PACKET,
                       SOCK_DIAG_BY_FAMILY, NLM_F_REQUEST, req,
                       printf("{sdiag_family=AF_PACKET"),
@@ -348,7 +348,6 @@ test_packet_diag_req(const int fd)
 static void
 test_packet_diag_msg(const int fd)
 {
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        static const struct packet_diag_msg msg = {
                .pdiag_family = AF_PACKET,
                .pdiag_type = SOCK_STREAM,
@@ -356,6 +355,7 @@ test_packet_diag_msg(const int fd)
                .pdiag_ino = 0xfacefeed,
                .pdiag_cookie = { 0xdeadbeef, 0xbadc0ded }
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
        TEST_SOCK_DIAG(fd, nlh0, AF_PACKET,
                       SOCK_DIAG_BY_FAMILY, NLM_F_DUMP, msg,
                       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 address6[] = "12:34:56:78:90:ab:cd:ef";
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        struct inet_diag_req_v2 req = {
                .sdiag_family = AF_INET,
                .idiag_ext = 1 << (INET_DIAG_CONG - 1),
@@ -384,6 +383,7 @@ test_inet_diag_sockid(const int fd)
                        .idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
                },
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
 
        if (!inet_pton(AF_INET, address, &req.id.idiag_src) ||
            !inet_pton(AF_INET, address, &req.id.idiag_dst))
@@ -435,7 +435,6 @@ static void
 test_inet_diag_req(const int fd)
 {
        const char address[] = "12.34.56.78";
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        struct inet_diag_req req = {
                .idiag_family = AF_INET,
                .idiag_src_len = 0xde,
@@ -450,6 +449,7 @@ test_inet_diag_req(const int fd)
                .idiag_states = 1 << TCP_LAST_ACK,
                .idiag_dbs = 0xfacefeed,
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
 
        if (!inet_pton(AF_INET, address, &req.id.idiag_src) ||
            !inet_pton(AF_INET, address, &req.id.idiag_dst))
@@ -479,7 +479,6 @@ static void
 test_inet_diag_req_v2(const int fd)
 {
        const char address[] = "87.65.43.21";
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        struct inet_diag_req_v2 req = {
                .sdiag_family = AF_INET,
                .idiag_ext = 1 << (INET_DIAG_CONG - 1),
@@ -492,6 +491,7 @@ test_inet_diag_req_v2(const int fd)
                        .idiag_cookie = { 0xdeadbeef, 0xbadc0ded }
                },
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
 
        if (!inet_pton(AF_INET, address, &req.id.idiag_src) ||
            !inet_pton(AF_INET, address, &req.id.idiag_dst))
@@ -519,7 +519,6 @@ static void
 test_inet_diag_msg(const int fd)
 {
        const char address[] = "11.22.33.44";
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        struct inet_diag_msg msg = {
                .idiag_family = AF_INET,
                .idiag_state = TCP_LISTEN,
@@ -537,6 +536,7 @@ test_inet_diag_msg(const int fd)
                .idiag_uid = 0xdecefaeb,
                .idiag_inode = 0xbadc0ded,
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        if (!inet_pton(AF_INET, address, &msg.id.idiag_src) ||
            !inet_pton(AF_INET, address, &msg.id.idiag_dst))
@@ -570,7 +570,6 @@ static void
 test_smc_diag_req(const int fd)
 {
        const char address[] = "43.21.56.78";
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        struct smc_diag_req req = {
                .diag_family = AF_SMC,
                .diag_ext = 1 << (SMC_DIAG_CONNINFO - 1),
@@ -581,6 +580,7 @@ test_smc_diag_req(const int fd)
                        .idiag_cookie = { 0xdeadbeef, 0xbadc0ded },
                },
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(req));
 
        if (!inet_pton(AF_INET, address, &req.id.idiag_src) ||
            !inet_pton(AF_INET, address, &req.id.idiag_dst))
@@ -606,7 +606,6 @@ static void
 test_smc_diag_msg(const int fd)
 {
        const char address[] = "34.87.12.90";
-       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
        struct smc_diag_msg msg = {
                .diag_family = AF_SMC,
                .diag_state = SMC_ACTIVE,
@@ -621,6 +620,7 @@ test_smc_diag_msg(const int fd)
                .diag_uid = 0xadcdfafc,
                .diag_inode = 0xbadc0ded,
        };
+       void *const nlh0 = midtail_alloc(NLMSG_HDRLEN, sizeof(msg));
 
        if (!inet_pton(AF_INET, address, &msg.id.idiag_src) ||
            !inet_pton(AF_INET, address, &msg.id.idiag_dst))
index a2a4792dd807e0fc7771be61d5969ef2c1ee56cd..ef34fcada74e6dbdca2cb2c8fabe38752c8104ff 100644 (file)
@@ -69,7 +69,7 @@ main(void)
        const int fd = create_nl_socket(NETLINK_ROUTE);
 
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index 2482b33b6bfb6bec7eebc7d024d7c6bebfdefdcd..c8c93acbdb0e63bd6ee9e23bf22564509da5afbb 100644 (file)
@@ -72,7 +72,12 @@ main(void)
 
        const int fd = create_nl_socket(NETLINK_CRYPTO);
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index cd63bb601472acabd3fc3a2d75c1bb4e88ac6a6a..e8f0287eafdab79d3daebc13b63e55b63d54a172 100644 (file)
@@ -67,7 +67,7 @@ main(void)
 
        const int fd = create_nl_socket(NETLINK_ROUTE);
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index 394ab10313e6676667718b259f85d0c65b8d0b77..a8242d033ead3abbbc77d9d86d34c9608c743422 100644 (file)
@@ -80,7 +80,7 @@ main(void)
 
        const int fd = create_nl_socket(NETLINK_ROUTE);
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index 600363404742db08faf40f549f5ea689f312efce..e1fecc52fe2915a2787fafc3eb79f07edaece04a 100644 (file)
@@ -69,7 +69,7 @@ main(void)
 
        const int fd = create_nl_socket(NETLINK_ROUTE);
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index 93fbef1be8ddb1fd21be2c3dc2c8f3f0c4243a6e..6f4098c5c301f7cae556feeda83fa40b0fea4be1 100644 (file)
@@ -83,9 +83,23 @@ main(void)
 {
        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 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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
@@ -106,8 +120,6 @@ main(void)
                    print_quoted_hex(pattern, 4));
 
        SET_IFA_FAMILY(AF_INET);
-       static const char address4[] = "12.34.56.78";
-       struct in_addr a4;
 
        if (!inet_pton(AF_INET, address4, &a4))
                perror_msg_and_skip("inet_pton");
@@ -118,8 +130,6 @@ main(void)
                           printf("%s", address4));
 
        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))
                perror_msg_and_skip("inet_pton");
@@ -129,12 +139,6 @@ main(void)
                           IFA_ADDRESS, pattern, a6,
                           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,
                           init_ifaddrmsg, print_ifaddrmsg,
                           IFA_CACHEINFO, pattern, ci,
@@ -144,7 +148,6 @@ main(void)
                           PRINT_FIELD_U(", ", ci, tstamp);
                           printf("}"));
 
-       const uint32_t ifa_flags = IFA_F_SECONDARY | IFA_F_PERMANENT;
        TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
                           init_ifaddrmsg, print_ifaddrmsg,
                           IFA_FLAGS, pattern, ifa_flags,
index 1fff52ca914c16afcac4caa321805af1ae0b2960..fde9f8c4b872a19ee4b401d81e4f829d16a08a6d 100644 (file)
@@ -89,28 +89,6 @@ main(void)
 {
        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 = {
                .rx_packets = 0xabcdefac,
                .tx_packets = 0xbcdacdab,
@@ -136,6 +114,29 @@ main(void)
                .rx_compressed = 0xdeffadbd,
                .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,
                           init_ifinfomsg, print_ifinfomsg,
                           IFLA_STATS, pattern, st,
index ae7c9da98a5cfdb9d84461ae2d8a551406f36a6d..dfc1b3d18b88e6eeaf1451bee54c11745fecba76 100644 (file)
@@ -84,19 +84,20 @@ main(void)
 {
        skip_if_unavailable("/proc/self/fd/");
 
+       const uint16_t u16 = 0xabcd;
+       const uint64_t u64 = 0xabcdedeeefeafeab;
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
 
-       const uint16_t u16 = 0xabcd;
        TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
                                  init_ifinfomsg, print_ifinfomsg,
                                  IFLA_BRPORT_PRIORITY, pattern, u16,
                                  printf("%u", u16));
 
-       const uint64_t u64 = 0xabcdedeeefeafeab;
        TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
                                  init_ifinfomsg, print_ifinfomsg,
                                  IFLA_BRPORT_MESSAGE_AGE_TIMER, pattern, u64,
index 61e90fe08b8e5c0b93334057a7d7b98de370ace7..0691394e86582cdaec450e0e0e07c3018448e3bd 100644 (file)
@@ -88,7 +88,7 @@ main(void)
        skip_if_unavailable("/proc/self/fd/");
 
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index cca5219eb4e17db735bdfe5f654313069d1d322e..cede99635fa22dbb21eabc41f24efff44976e1fe 100644 (file)
@@ -87,13 +87,14 @@ main(void)
 {
        skip_if_unavailable("/proc/self/fd/");
 
+       const int32_t num = 0xabacdbcd;
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
 
-       const int32_t num = 0xabacdbcd;
        TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
                                  init_ifinfomsg, print_ifinfomsg,
                                  IFLA_XDP_FD, pattern, num,
index ccc62aed5c1e8a722a95ea7063165076307ba6ef..6c724d8dcaacd4f8dcce8f37806ea2190759f1bd 100644 (file)
@@ -87,19 +87,46 @@ main(void)
 {
        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 = {
                .idiag_rmem = 0xfadcacdb,
                .idiag_wmem = 0xbdabcada,
                .idiag_fmem = 0xbadbfafb,
                .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,
                           init_inet_diag_msg, print_inet_diag_msg,
                           INET_DIAG_MEMINFO, pattern, minfo,
@@ -109,12 +136,6 @@ main(void)
                           PRINT_FIELD_U(", ", minfo, idiag_tmem);
                           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,
                           init_inet_diag_msg, print_inet_diag_msg,
                           INET_DIAG_VEGASINFO, pattern, vegas,
@@ -125,13 +146,6 @@ main(void)
                           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,
                           init_inet_diag_msg, print_inet_diag_msg,
                           INET_DIAG_DCTCPINFO, pattern, dctcp,
@@ -142,13 +156,6 @@ main(void)
                           PRINT_FIELD_U(", ", dctcp, dctcp_ab_tot);
                           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,
                           init_inet_diag_msg, print_inet_diag_msg,
                           INET_DIAG_BBRINFO, pattern, bbr,
@@ -159,12 +166,10 @@ main(void)
                           PRINT_FIELD_U(", ", bbr, bbr_cwnd_gain);
                           printf("}"));
 
-       static const uint32_t mem[] = { 0xaffacbad, 0xffadbcab };
        TEST_NLATTR_ARRAY(fd, nlh0, hdrlen,
                          init_inet_diag_msg, print_inet_diag_msg,
                          INET_DIAG_SKMEMINFO, pattern, mem, print_uint);
 
-       static uint32_t bigmem[SK_MEMINFO_VARS + 1];
        memcpy(bigmem, pattern, sizeof(bigmem));
 
        TEST_NLATTR(fd, nlh0, hdrlen, init_inet_diag_msg, print_inet_diag_msg,
@@ -176,7 +181,6 @@ main(void)
                    }
                    printf(", ...]"));
 
-       static const uint32_t mark = 0xabdfadca;
        TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
                           init_inet_diag_msg, print_inet_diag_msg,
                           INET_DIAG_MARK, pattern, mark,
@@ -187,7 +191,6 @@ main(void)
                           INET_DIAG_CLASS_ID, pattern, mark,
                           printf("%u", mark));
 
-       static const uint8_t shutdown = 0xcd;
        TEST_NLATTR(fd, nlh0, hdrlen,
                    init_inet_diag_msg, print_inet_diag_msg, INET_DIAG_SHUTDOWN,
                    sizeof(shutdown), &shutdown, sizeof(shutdown),
index b0b217138666ac4928f83fb14bcc9b3442f88a79..a3e773d992b5843d0ee88be87e128ed6b580f7a0 100644 (file)
@@ -86,7 +86,7 @@ main(void)
 
        int fd = create_nl_socket(NETLINK_SOCK_DIAG);
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index 1e09abe685fb73352049159ba9d07fd65bc3ae31..8d4cc2e699d8426e45f534ceeef5d628d1c5b31f 100644 (file)
@@ -407,7 +407,10 @@ main(void)
        skip_if_unavailable("/proc/self/fd/");
 
        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);
 
        test_inet_diag_bc_op(fd);
index 124fe1d4e58a05f1fcdfebe7bfa9179cba99bb6d..6bd21fab0a87382b27f62317e7c31ba2f5c18365 100644 (file)
@@ -99,7 +99,12 @@ main(void)
 
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index af908cd85290bf79442ffda8957effe161545c41..651492e40c173ed8c7c6e635dbb08c456d6e0d6c 100644 (file)
@@ -87,25 +87,27 @@ main(void)
 {
        skip_if_unavailable("/proc/self/fd/");
 
+       const uint32_t ifindex = ifindex_lo();
+       const uint8_t type = MDB_RTR_TYPE_DISABLED;
+       static const struct nlattr nla = {
+               .nla_len = NLA_HDRLEN + sizeof(type),
+               .nla_type = MDBA_ROUTER_PATTR_TYPE
+       };
+       char buf[NLMSG_ALIGN(ifindex) + NLA_HDRLEN + sizeof(type)];
+
        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(buf));
 
        static char pattern[4096];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
 
-       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;
-       static const struct nlattr nla = {
-               .nla_len = NLA_HDRLEN + sizeof(type),
-               .nla_type = MDBA_ROUTER_PATTR_TYPE
-       };
-       char buf[NLMSG_ALIGN(ifindex) + NLA_HDRLEN + sizeof(type)];
        memcpy(buf, &ifindex, sizeof(ifindex));
        memcpy(buf + NLMSG_ALIGN(ifindex), &nla, sizeof(nla));
        memcpy(buf + NLMSG_ALIGN(ifindex) + NLA_HDRLEN, &type, sizeof(type));
index 8538a8275235cb29b0c5953c8acb4a12211fbad3..abb7c39d06e8b88ebe38b98e26f9e88aecf08722 100644 (file)
@@ -77,7 +77,8 @@ main(void)
 
        const int fd = create_nl_socket(NETLINK_ROUTE);
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index d3f1bdb7e3824fdb2ebe0edabba745402f39b7b6..98978e9379e164e113141ffb841247017dbd425b 100644 (file)
@@ -68,7 +68,7 @@ main(void)
 
        const int fd = create_nl_socket(NETLINK_ROUTE);
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index 6866adc955a4edb7f620fb30766cbc569ef9f692..e4644afa9c929285346f460ee2a5529df7e3b174 100644 (file)
@@ -66,7 +66,7 @@ main(void)
        const int fd = create_nl_socket(NETLINK_ROUTE);
 
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index 76a2d19e47dfea56d9741ab04942065228566080..17afc58b7eac0ed820edfe2df6d676587adf0b8e 100644 (file)
@@ -76,27 +76,32 @@ main(void)
 {
        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[] = {
                (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 = {
                .ndr_block_size = 0xfabfabdc,
                .ndr_block_nr = 0xabcdabda,
                .ndr_frame_size = 0xcbadbafa,
                .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,
                           init_netlink_diag_msg, print_netlink_diag_msg,
                           NETLINK_DIAG_RX_RING, pattern, ndr,
@@ -106,8 +111,6 @@ main(void)
                           PRINT_FIELD_U(", ", ndr, ndr_frame_nr);
                           printf("}"));
 
-       static const uint32_t flags =
-               NDIAG_FLAG_CB_RUNNING | NDIAG_FLAG_PKTINFO;
        TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
                           init_netlink_diag_msg, print_netlink_diag_msg,
                           NETLINK_DIAG_FLAGS, pattern, flags,
index 837283c0cf40ec5663b9900200a145a55695cdfc..be1f359953fe81f12d866b6259386b26cdfdaa41 100644 (file)
@@ -69,11 +69,13 @@ main(void)
 {
        skip_if_unavailable("/proc/self/fd/");
 
+       static const uint8_t cookie[] = { 0xab, 0xfe };
+
        const int fd = create_nl_socket(NETLINK_SOCK_DIAG);
        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,
                    init_nlmsgerr, print_nlmsgerr,
                    NLMSGERR_ATTR_COOKIE,
index 4211e201198c4e3c0d0f558f5bf259f707c69ca0..12cefcf94cbbe14b41ce4cbcd1d0b434afd466fa 100644 (file)
@@ -98,13 +98,6 @@ main(void)
 {
        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 = {
                .pdi_index = 0xabcddafa,
                .pdi_version = 0xbabcdafb,
@@ -113,16 +106,6 @@ main(void)
                .pdi_tstamp = 0xeafbaadf,
                .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[] = {
                {
                        .pdmc_index = ifindex_lo(),
@@ -139,11 +122,6 @@ main(void)
                        .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 = {
                .pdr_block_size = 0xabcdafed,
                .pdr_block_nr = 0xbcadefae,
@@ -153,6 +131,30 @@ main(void)
                .pdr_sizeof_priv = 0xfeadeacd,
                .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,
                           init_packet_diag_msg, print_packet_diag_msg,
                           PACKET_DIAG_RX_RING, pattern, pdr,
index ceb061df12e3980c331f9a0e53659cd777365934..24bd377226149d4bffdb0451cd9b1b46124db82d 100644 (file)
@@ -66,13 +66,14 @@ main(void)
 
        const int fd = create_nl_socket(NETLINK_ROUTE);
        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];
        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);
        TEST_NLATTR_(fd, nlh0, hdrlen,
                     init_rtgenmsg, print_rtgenmsg,
index 5f29f0c0ce2024f97034121d75293dc9ebeabfbb..8f1afbf73f3aad45d4238166a2b2539c75042114 100644 (file)
@@ -81,13 +81,14 @@ main(void)
 
        const int fd = create_nl_socket(NETLINK_ROUTE);
        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];
        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);
        TEST_NLATTR_(fd, nlh0, hdrlen,
                     init_rtmsg, print_rtmsg,
index a06ad624680aad4db6a39ac71a0616457e98f198..3e7e7209270283e2f3dc4d65db77b3d301c4c9d5 100644 (file)
@@ -97,13 +97,6 @@ int main(void)
 {
        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 = {
                .token = 0xabcdefac,
                .sndbuf_size = 0xbcdaefad,
@@ -149,6 +142,25 @@ int main(void)
                        .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,
                           init_smc_diag_msg, print_smc_diag_msg,
@@ -170,16 +182,6 @@ int main(void)
                           PRINT_FIELD_SMC_DIAG_CURSOR(", ", cinfo, tx_fin);
                           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,
                           init_smc_diag_msg, print_smc_diag_msg,
                           SMC_DIAG_LGRINFO, pattern, linfo,
index dd76cc7d136e01244a40250a43479086743f45f7..cb9d8b5552906d45effb0cc26e48bd287495efa4 100644 (file)
@@ -77,7 +77,7 @@ main(void)
        skip_if_unavailable("/proc/self/fd/");
 
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index de6d356915006605168db7a82c2b6c43e975fa2c..690a50533838bdd798e429a930a8ab5ca3f81739 100644 (file)
@@ -87,7 +87,11 @@ main(void)
        skip_if_unavailable("/proc/self/fd/");
 
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index 7f611532821fe348d4a5423e697d28a198d50a12..ced74d2fc022aea1ff106ecee070cef91a0a3d15 100644 (file)
@@ -62,7 +62,7 @@ main(void)
 
        const int fd = create_nl_socket(NETLINK_ROUTE);
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index 32ce47905b8355ecbf42080a62942757aeff46e8..a8741c6086f9aff08a27782e0e79d80df648446a 100644 (file)
@@ -68,7 +68,8 @@ main(void)
 
        const int fd = create_nl_socket(NETLINK_ROUTE);
        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];
        fill_memory_ex(pattern, sizeof(pattern), 'a', 'z' - 'a' + 1);
index 229540428a8592e1e35184c1f3932ef4b8a2a048..488891c39d186a6494a44befdc3e8487d5c1ccb9 100644 (file)
@@ -75,17 +75,24 @@ main(void)
 {
        skip_if_unavailable("/proc/self/fd/");
 
+       static const struct unix_diag_vfs uv = {
+               .udiag_vfs_dev = 0xabcddafa,
+               .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 = tail_alloc(NLMSG_SPACE(hdrlen));
+       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);
 
-       static const struct unix_diag_vfs uv = {
-               .udiag_vfs_dev = 0xabcddafa,
-               .udiag_vfs_ino = 0xbafabcda
-       };
        TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
                           init_unix_diag_msg, print_unix_diag_msg,
                           UNIX_DIAG_VFS, pattern, uv,
@@ -95,10 +102,6 @@ main(void)
                           PRINT_FIELD_U(", ", uv, udiag_vfs_ino);
                           printf("}"));
 
-       static const struct unix_diag_rqlen rql = {
-               .udiag_rqueue = 0xfabdcdad,
-               .udiag_wqueue = 0xbacdadcf
-       };
        TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
                           init_unix_diag_msg, print_unix_diag_msg,
                           UNIX_DIAG_RQLEN, pattern, rql,
@@ -106,7 +109,6 @@ main(void)
                           PRINT_FIELD_U(", ", rql, udiag_wqueue);
                           printf("}"));
 
-       static const uint32_t inode[] = { 0xadbcadbc, 0xfabdcdac };
        TEST_NLATTR_ARRAY(fd, nlh0, hdrlen,
                          init_unix_diag_msg, print_unix_diag_msg,
                          UNIX_DIAG_ICONS, pattern, inode, print_uint);
index 1712294c698045db61a8e446a412d83a5e06ca97..7c323dc608a39ac197fae2a058d05d16adb65110 100644 (file)
@@ -117,6 +117,9 @@ void *tail_alloc(const size_t)
 void *tail_memdup(const void *, const size_t)
        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
  * of a mapped memory region.