Skip to content

Commit d396a91

Browse files
committed
tests: check decoding of ndmsg netlink attributes
* tests/nlattr_ndmsg.c: Include <netinet/in.h> and <arpa/inet.h>. (NDA_PORT): New macro. (main): Check decoding of NDA_DST, NDA_CACHEINFO and NDA_PORT.
1 parent 19abd52 commit d396a91

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/nlattr_ndmsg.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
#include "tests.h"
3030

3131
#include <stdio.h>
32+
#include <netinet/in.h>
33+
#include <arpa/inet.h>
3234
#include "test_nlattr.h"
3335
#ifdef HAVE_LINUX_NEIGHBOUR_H
3436
# include <linux/neighbour.h>
3537
#endif
3638
#include <linux/rtnetlink.h>
3739

40+
#define NDA_PORT 6
41+
3842
static void
3943
init_ndmsg(struct nlmsghdr *const nlh, const unsigned int msg_len)
4044
{
@@ -87,6 +91,33 @@ main(void)
8791
4, pattern, 4,
8892
print_quoted_hex(pattern, 4));
8993

94+
TEST_NLATTR(fd, nlh0, hdrlen,
95+
init_ndmsg, print_ndmsg,
96+
NDA_DST, 4, pattern, 4,
97+
print_quoted_hex(pattern, 4));
98+
99+
static const struct nda_cacheinfo ci = {
100+
.ndm_confirmed = 0xabcdedad,
101+
.ndm_used = 0xbcdaedad,
102+
.ndm_updated = 0xcdbadeda,
103+
.ndm_refcnt = 0xdeadbeda
104+
};
105+
106+
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
107+
init_ndmsg, print_ndmsg,
108+
NDA_CACHEINFO, pattern, ci,
109+
PRINT_FIELD_U("{", ci, ndm_confirmed);
110+
PRINT_FIELD_U(", ", ci, ndm_used);
111+
PRINT_FIELD_U(", ", ci, ndm_updated);
112+
PRINT_FIELD_U(", ", ci, ndm_refcnt);
113+
printf("}"));
114+
115+
const uint16_t port = 0xabcd;
116+
TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
117+
init_ndmsg, print_ndmsg,
118+
NDA_PORT, pattern, port,
119+
printf("htons(%u)", ntohs(port)));
120+
90121
puts("+++ exited with 0 +++");
91122
return 0;
92123
}

0 commit comments

Comments
 (0)