* test_netlink.h (TEST_NETLINK_OBJECT): New macro. * tests/netlink_selinux.c: Include "test_netlink.h" instead of "netlink.h". (test_selnl_msg_unspec, test_selnl_msg_setenforce, test_selnl_msg_policyload): New functions. (main): Use them. --- tests/netlink_selinux.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- tests/test_netlink.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/tests/netlink_selinux.c b/tests/netlink_selinux.c index 6494fda..2d76822 100644 --- a/tests/netlink_selinux.c +++ b/tests/netlink_selinux.c @@ -30,7 +30,7 @@ #include <string.h> #include <unistd.h> #include <sys/socket.h> -#include "netlink.h" +#include "test_netlink.h" #include <linux/selinux_netlink.h> static void @@ -50,6 +50,46 @@ test_nlmsg_type(const int fd) fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc)); } +static void +test_selnl_msg_unspec(const int fd) +{ + void *const nlh0 = tail_alloc(NLMSG_HDRLEN); + + TEST_NETLINK_(fd, nlh0, + 0xffff, "0xffff /* SELNL_MSG_??? */", + NLM_F_REQUEST, "NLM_F_REQUEST", + 4, "1234", 4, + printf("\"\\x31\\x32\\x33\\x34\"")); +} + +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 + }; + TEST_NETLINK_OBJECT(fd, nlh0, + SELNL_MSG_SETENFORCE, NLM_F_REQUEST, msg, + PRINT_FIELD_D("{", msg, val); + printf("}")); +} + +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 + }; + TEST_NETLINK_OBJECT(fd, nlh0, + SELNL_MSG_POLICYLOAD, NLM_F_REQUEST, msg, + PRINT_FIELD_U("{", msg, seqno); + printf("}")); +} + int main(void) { skip_if_unavailable("/proc/self/fd/"); @@ -57,6 +97,9 @@ int main(void) int fd = create_nl_socket(NETLINK_SELINUX); test_nlmsg_type(fd); + test_selnl_msg_unspec(fd); + test_selnl_msg_setenforce(fd); + test_selnl_msg_policyload(fd); printf("+++ exited with 0 +++\n"); diff --git a/tests/test_netlink.h b/tests/test_netlink.h index 7049128..0648d79 100644 --- a/tests/test_netlink.h +++ b/tests/test_netlink.h @@ -45,3 +45,36 @@ (type_), #type_, \ (flags_), #flags_, \ (data_len_), (src_), (slen_), __VA_ARGS__) + +#define TEST_NETLINK_OBJECT(fd_, nlh0_, \ + type_, flags_, \ + obj_, ...) \ + do { \ + char pattern[DEFAULT_STRLEN]; \ + fill_memory_ex(pattern, sizeof(pattern), \ + 'a', 'z' - 'a' + 1); \ + const unsigned int plen = \ + sizeof(obj_) - 1 > DEFAULT_STRLEN \ + ? DEFAULT_STRLEN : (int) sizeof(obj_) - 1; \ + /* len < sizeof(obj_) */ \ + TEST_NETLINK_((fd_), (nlh0_), \ + (type_), #type_, \ + (flags_), #flags_, \ + plen, pattern, plen, \ + print_quoted_hex(pattern, plen)); \ + /* short read of sizeof(obj_) */ \ + TEST_NETLINK_((fd_), (nlh0_), \ + (type_), #type_, \ + (flags_), #flags_, \ + sizeof(obj_), \ + pattern, plen, \ + printf("%p", \ + NLMSG_DATA(TEST_NETLINK_nlh))); \ + /* sizeof(obj_) */ \ + TEST_NETLINK_((fd_), (nlh0_), \ + (type_), #type_, \ + (flags_), #flags_, \ + sizeof(obj_), \ + &(obj_), sizeof(obj_), \ + __VA_ARGS__); \ + } while (0) -- 2.7.4 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel