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",
.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,
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_??? */",
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),
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,
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);
", \"\\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));
{
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 */
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;
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),
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",
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);
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,
.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"),
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,
.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"),
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,
.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"),
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,
.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"),
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(),
.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"),
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,
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(),
.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"),
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,
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,
.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"),
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"),
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,
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"),
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,
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_??? */",
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);
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);
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,
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);
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),
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);
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,
.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"),
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,
.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"),
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,
.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"),
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,
.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"),
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,
.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"),
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,
.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"),
{
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),
.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))
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,
.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))
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),
.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))
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,
.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))
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),
.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))
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,
.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))
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);
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);
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);
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);
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);
{
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);
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");
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");
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,
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,
{
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,
.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,
{
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,
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);
{
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,
{
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,
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,
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,
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,
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,
}
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,
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),
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);
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);
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);
{
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));
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);
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);
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);
{
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,
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,
{
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,
{
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,
.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(),
.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,
.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,
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,
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,
{
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,
.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,
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,
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);
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);
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);
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);
{
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,
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,
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);
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.