From e9cf2344e33f7940f6db676d637dcd93228ce78a Mon Sep 17 00:00:00 2001 From: renmingshuai Date: Mon, 13 Mar 2023 20:12:34 +0800 Subject: [PATCH] add test case and enable in rpmbuild --- add-test-case-and-enable-in-rpmbuild.patch | 107 +++++++++++++++++++++ libnfnetlink.spec | 8 +- 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 add-test-case-and-enable-in-rpmbuild.patch diff --git a/add-test-case-and-enable-in-rpmbuild.patch b/add-test-case-and-enable-in-rpmbuild.patch new file mode 100644 index 0000000..a1d73bf --- /dev/null +++ b/add-test-case-and-enable-in-rpmbuild.patch @@ -0,0 +1,107 @@ +From be875657f0fcaa2f87658a07c9de9fefb7f74f29 Mon Sep 17 00:00:00 2001 +From: renmingshuai +Date: Mon, 13 Mar 2023 19:58:35 +0800 +Subject: [PATCH] add test case and enable in rpmbuild + +--- + utils/Makefile.in | 1 + + utils/iftest.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-- + 2 files changed, 49 insertions(+), 2 deletions(-) + +diff --git a/utils/Makefile.in b/utils/Makefile.in +index d0c62f6..df5db23 100644 +--- a/utils/Makefile.in ++++ b/utils/Makefile.in +@@ -404,6 +404,7 @@ distdir: $(DISTFILES) + done + check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) ++ ./iftest enp3s0 + check: check-am + all-am: Makefile + installdirs: +diff --git a/utils/iftest.c b/utils/iftest.c +index 02f5807..f5c3664 100644 +--- a/utils/iftest.c ++++ b/utils/iftest.c +@@ -5,15 +5,19 @@ + #include + #include + #include ++#include + ++#include + #include + + int main(int argc, char *argv[]) + { + int idx; + struct nlif_handle *h; ++ struct nfnl_handle *nf; ++ struct nfnl_subsys_handle *nsh; + char name[IFNAMSIZ]; +- unsigned int flags; ++ unsigned int flags,bf; + + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); +@@ -40,7 +44,6 @@ int main(int argc, char *argv[]) + + if (nlif_get_ifflags(h, idx, &flags) == -1) { + fprintf(stderr, "Cannot get flags for device `%s'\n", argv[1]); +- exit(EXIT_FAILURE); + } + + printf("index (%d) is %s (%s) (%s)\n", idx, argv[1], +@@ -48,5 +51,48 @@ int main(int argc, char *argv[]) + flags & IFF_UP ? "UP" : "DOWN"); + + nlif_close(h); ++ ++ nf = nfnl_open(); ++ ++ bf = nfnl_rcvbufsiz(nf,NFNL_BUFFSIZE/2); ++ if(bf != NFNL_BUFFSIZE){ ++ printf("set the socket buffer size fail.\n"); ++ } ++ ++ nsh = nfnl_subsys_open(nf,NFNL_SUBSYS_CTNETLINK,5,0); ++ ++ if(nfnl_callback_unregister(nsh,16)!=-1){ ++ fprintf(stderr,"test ungister nfnl callback Anomalies failure\n"); ++ } ++ if(nfnl_callback_unregister(nsh,0)==-1){ ++ fprintf(stderr,"Cannot get unregister nfnl callback for device `%s'\n", argv[1]); ++ } ++ ++ struct nfqnl_msg_config_params { ++ __be32 copy_range; ++ __u8 copy_mode; ++ } __attribute__ ((packed)); ++ ++ union { ++ char buf[NFNL_HEADER_LEN ++ +NFA_LENGTH(sizeof(struct nfqnl_msg_config_params))]; ++ struct nlmsghdr nmh; ++ } u; ++ struct nfqnl_msg_config_params params; ++ nfnl_fill_hdr(nsh, &u.nmh, 0, 0, 0, ++ 0, NLM_F_REQUEST|NLM_F_ACK); ++ ++ params.copy_range = 0xffff; ++ params.copy_mode = 2; ++ nfnl_addattr_l(&u.nmh, sizeof(u), 2, ¶ms, ++ sizeof(params)); ++ ++ if(nfnl_handle_packet(nf,(char *)&u.nmh, u.nmh.nlmsg_len)<0){ ++ printf("nfnl handle packet function failure\n"); ++ } ++ ++ nfnl_subsys_close(nsh); ++ nfnl_close(nf); ++ + return EXIT_SUCCESS; + } +-- +2.23.0 + diff --git a/libnfnetlink.spec b/libnfnetlink.spec index 36d8d59..d1a35db 100644 --- a/libnfnetlink.spec +++ b/libnfnetlink.spec @@ -1,10 +1,11 @@ Name: libnfnetlink Version: 1.0.1 -Release: 16 +Release: 17 Summary: Netlink library for netfilter License: GPLv2+ URL: http://netfilter.org Source0: http://netfilter.org/projects/libnfnetlink/files/%{name}-%{version}.tar.bz2 +Patch0: add-test-case-and-enable-in-rpmbuild.patch BuildRequires: kernel-headers automake autoconf libtool pkgconfig BuildRequires: make @@ -30,6 +31,8 @@ The %{name}-devel package contains libraries and header files for %{name}. %build %configure %make_build +%check +make check %install %make_install @@ -54,6 +57,9 @@ The %{name}-devel package contains libraries and header files for %{name}. %doc README %changelog +* Mon Mar 13 2023 liubo - 1.0.1-17 +- add test case and enable in rpmbuild + * Tue Nov 01 2022 xingwei - 1.0.1-16 - add make as BuildRequires for rpmbuild -- Gitee