diff --git a/.gitignore b/.gitignore index e69de29..b152d8d 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,17 @@ +libpcap-1.1.1.tar.gz +/libpcap-1.2.0.tar.gz +/libpcap-1.2.1.tar.gz +/libpcap-1.3.0.tar.gz +/libpcap-1.4.0.tar.gz +/libpcap-1.5.0-20131108git459712e.tar.gz +/generate-tarball.sh +/libpcap-1.5.1.tar.gz +/libpcap-1.5.3.tar.gz +/libpcap-1.6.2.tar.gz +/libpcap-1.7.2.tar.gz +/libpcap-1.7.3.tar.gz +/libpcap-1.7.4.tar.gz +/libpcap-1.8.0.tar.gz +/libpcap-1.8.1.tar.gz +/libpcap-1.9.0.tar.gz +/libpcap-1.9.1.tar.gz diff --git a/0001-Fix-building-Bluetooth-Linux-Monitor-support-with-Bl.patch b/0001-Fix-building-Bluetooth-Linux-Monitor-support-with-Bl.patch new file mode 100644 index 0000000..8d88368 --- /dev/null +++ b/0001-Fix-building-Bluetooth-Linux-Monitor-support-with-Bl.patch @@ -0,0 +1,77 @@ +From 661a9057b123e794897c8957c29530a5f428ec7b Mon Sep 17 00:00:00 2001 +From: Jakub Sitnicki +Date: Thu, 26 Mar 2015 22:35:29 +0100 +Subject: [PATCH] Fix building Bluetooth Linux Monitor support with BlueZ 5.1+ + +Starting from version 5.1 BlueZ no longer exports the mgmt.h header +or any other header that declares the structure of packets passed +over HCI sockets set to use the HCI monitor channel. + +Declare the structure locally and give it the same name as in the +Linux kernel 3.4+. +--- + pcap-bt-monitor-linux.c | 18 ++++++++++++++---- + 1 file changed, 14 insertions(+), 4 deletions(-) + +diff --git a/pcap-bt-monitor-linux.c b/pcap-bt-monitor-linux.c +index f193e26..b18bdca 100644 +--- a/pcap-bt-monitor-linux.c ++++ b/pcap-bt-monitor-linux.c +@@ -34,12 +34,12 @@ + #endif + + #include ++#include + #include + #include + + #include + #include +-#include + + #include "pcap/bluetooth.h" + #include "pcap-int.h" +@@ -49,6 +49,16 @@ + #define BT_CONTROL_SIZE 32 + #define INTERFACE_NAME "bluetooth-monitor" + ++/* ++ * Fields and alignment must match the declaration in the Linux kernel 3.4+. ++ * See struct hci_mon_hdr in include/net/bluetooth/hci_mon.h. ++ */ ++struct hci_mon_hdr { ++ uint16_t opcode; ++ uint16_t index; ++ uint16_t len; ++} __attribute__((packed)); ++ + int + bt_monitor_findalldevs(pcap_if_t **alldevsp, char *err_str) + { +@@ -72,12 +82,12 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch + ssize_t ret; + struct pcap_pkthdr pkth; + pcap_bluetooth_linux_monitor_header *bthdr; +- struct mgmt_hdr hdr; ++ struct hci_mon_hdr hdr; + + bthdr = (pcap_bluetooth_linux_monitor_header*) &handle->buffer[handle->offset]; + + iv[0].iov_base = &hdr; +- iv[0].iov_len = MGMT_HDR_SIZE; ++ iv[0].iov_len = sizeof(hdr); + iv[1].iov_base = &handle->buffer[handle->offset + sizeof(pcap_bluetooth_linux_monitor_header)]; + iv[1].iov_len = handle->snapshot; + +@@ -103,7 +113,7 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch + return -1; + } + +- pkth.caplen = ret - MGMT_HDR_SIZE + sizeof(pcap_bluetooth_linux_monitor_header); ++ pkth.caplen = ret - sizeof(hdr) + sizeof(pcap_bluetooth_linux_monitor_header); + pkth.len = pkth.caplen; + + for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) { +-- +2.4.0 + diff --git a/0001-man-tcpdump-and-tcpslice-have-manpages-in-man8.patch b/0001-man-tcpdump-and-tcpslice-have-manpages-in-man8.patch new file mode 100644 index 0000000..888bb9a --- /dev/null +++ b/0001-man-tcpdump-and-tcpslice-have-manpages-in-man8.patch @@ -0,0 +1,27 @@ +From 208bb414553d5444d82601e6fd4ca25fbb192998 Mon Sep 17 00:00:00 2001 +From: Michal Sekletar +Date: Mon, 29 Sep 2014 08:19:05 +0200 +Subject: [PATCH 1/4] man: tcpdump and tcpslice have manpages in man8 + +Both should be run only by root, hence manpages for them should be located in +/usr/share/man/man8/ +--- + pcap.3pcap.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/pcap.3pcap.in b/pcap.3pcap.in +index f5a7e0c..f220e68 100644 +--- a/pcap.3pcap.in ++++ b/pcap.3pcap.in +@@ -882,7 +882,7 @@ use an + script or some other configuration script to check whether the libpcap + 1.0 APIs are available and use them only if they are. + .SH SEE ALSO +-autoconf(1), tcpdump(1), tcpslice(1), pcap-filter(@MAN_MISC_INFO@), pfconfig(8), ++autoconf(1), tcpdump(8), tcpslice(8), pcap-filter(@MAN_MISC_INFO@), pfconfig(8), + usermod(@MAN_ADMIN_COMMANDS@) + .SH AUTHORS + The original authors of libpcap are: +-- +1.8.3.1 + diff --git a/0002-pcap-config-mitigate-multilib-conflict.patch b/0002-pcap-config-mitigate-multilib-conflict.patch new file mode 100644 index 0000000..8b6b420 --- /dev/null +++ b/0002-pcap-config-mitigate-multilib-conflict.patch @@ -0,0 +1,88 @@ +From 5b80ca39b1f01177e98c78bbc622dfda6f7a7e71 Mon Sep 17 00:00:00 2001 +From: Michal Sekletar +Date: Mon, 29 Sep 2014 08:27:15 +0200 +Subject: [PATCH 2/4] pcap-config: mitigate multilib conflict + +libdir path is different on 64bit and 32bit arches. Hence when installing both +multilib versions on the system yum complains about conflicting pcap-config +file. + +Hence remove libdir references from pcap-config, libdir is in dynamic linker +path anyway. +--- + pcap-config.in | 27 ++++++++------------------- + 1 file changed, 8 insertions(+), 19 deletions(-) + +diff --git a/pcap-config.in b/pcap-config.in +index 206be3b..75f2c9f 100644 +--- a/pcap-config.in ++++ b/pcap-config.in +@@ -7,7 +7,6 @@ + prefix="@prefix@" + exec_prefix="@exec_prefix@" + includedir="@includedir@" +-libdir="@libdir@" + V_RPATH_OPT="@V_RPATH_OPT@" + LIBS="@LIBS@" + PACKAGE_NAME="@PACKAGE_NAME@" +@@ -36,16 +35,6 @@ do + esac + shift + done +-if [ "$V_RPATH_OPT" != "" ] +-then +- # +- # If libdir isn't /usr/lib, add it to the run-time linker path. +- # +- if [ "$libdir" != "/usr/lib" ] +- then +- RPATH=$V_RPATH_OPT$libdir +- fi +-fi + if [ "$static" = 1 ] + then + # +@@ -54,16 +43,16 @@ then + # + if [ "$show_cflags" = 1 -a "$show_libs" = 1 ] + then +- echo "-I$includedir -L$libdir -lpcap $LIBS" ++ echo "-lpcap @LIBS@" + elif [ "$show_cflags" = 1 -a "$show_additional_libs" = 1 ] + then +- echo "-I$includedir -L$libdir $LIBS" ++ echo "@LIBS@" + elif [ "$show_cflags" = 1 ] + then +- echo "-I$includedir" ++ echo "" + elif [ "$show_libs" = 1 ] + then +- echo "-L$libdir -lpcap $LIBS" ++ echo "-lpcap @LIBS@" + elif [ "$show_additional_libs" = 1 ] + then + echo "$LIBS" +@@ -75,15 +64,15 @@ else + # + if [ "$show_cflags" = 1 -a "$show_libs" = 1 ] + then +- echo "-I$includedir -L$libdir $RPATH -l$PACKAGE_NAME" ++ echo "-lpcap" + elif [ "$show_cflags" = 1 -a "$show_additional_libs" = 1 ] + then +- echo "-I$includedir" ++ echo "" + elif [ "$show_cflags" = 1 ] + then +- echo "-I$includedir" ++ echo "" + elif [ "$show_libs" = 1 ] + then +- echo "-L$libdir $RPATH -l$PACKAGE_NAME" ++ echo "-lpcap" + fi + fi +-- +1.8.3.1 + diff --git a/0003-pcap-linux-apparently-ctc-interfaces-on-s390-has-eth.patch b/0003-pcap-linux-apparently-ctc-interfaces-on-s390-has-eth.patch new file mode 100644 index 0000000..c2c9ca2 --- /dev/null +++ b/0003-pcap-linux-apparently-ctc-interfaces-on-s390-has-eth.patch @@ -0,0 +1,28 @@ +From b9fa92532328daad84766753422e8a21fd474e6f Mon Sep 17 00:00:00 2001 +From: Michal Sekletar +Date: Mon, 29 Sep 2014 08:37:25 +0200 +Subject: [PATCH 3/4] pcap-linux: apparently ctc interfaces on s390 has + ethernet DLT + +--- + pcap-linux.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/pcap-linux.c b/pcap-linux.c +index 900ebbc..58292c3 100644 +--- a/pcap-linux.c ++++ b/pcap-linux.c +@@ -3197,6 +3197,10 @@ activate_new(pcap_t *handle) + handle->linktype = DLT_LINUX_SLL; + } + ++ /* Hack to make things work on s390 ctc interfaces */ ++ if (strncmp("ctc", device, 3) == 0) ++ handle->linktype = DLT_EN10MB; ++ + handlep->ifindex = iface_get_id(sock_fd, device, + handle->errbuf); + if (handlep->ifindex == -1) { +-- +1.8.3.1 + diff --git a/0004-invalid-ipv4.patch b/0004-invalid-ipv4.patch new file mode 100644 index 0000000..d944d92 --- /dev/null +++ b/0004-invalid-ipv4.patch @@ -0,0 +1,65 @@ +From 907070918d5e81a515315b395f334e52589fe0fb Mon Sep 17 00:00:00 2001 +From: Guy Harris +Date: Wed, 18 Dec 2019 15:06:53 -0800 +Subject: [PATCH] Check for invalid IPv4 addresses. + +This should fix GitHub issue #893. +--- + gencode.c | 9 ++++++++- + nametoaddr.c | 9 ++++++++- + 2 files changed, 16 insertions(+), 2 deletions(-) + +diff --git a/gencode.c b/gencode.c +index bdc35e646..040a55315 100644 +--- a/gencode.c ++++ b/gencode.c +@@ -6947,11 +6947,15 @@ gen_mcode(compiler_state_t *cstate, const char *s1, const char *s2, + return (NULL); + + nlen = __pcap_atoin(s1, &n); ++ if (nlen < 0) ++ bpf_error(cstate, "invalid IPv4 address '%s'", s1); + /* Promote short ipaddr */ + n <<= 32 - nlen; + + if (s2 != NULL) { + mlen = __pcap_atoin(s2, &m); ++ if (mlen < 0) ++ bpf_error(cstate, "invalid IPv4 address '%s'", s2); + /* Promote short ipaddr */ + m <<= 32 - mlen; + if ((n & ~m) != 0) +@@ -7009,8 +7013,11 @@ gen_ncode(compiler_state_t *cstate, const char *s, bpf_u_int32 v, struct qual q) + vlen = __pcap_atodn(s, &v); + if (vlen == 0) + bpf_error(cstate, "malformed decnet address '%s'", s); +- } else ++ } else { + vlen = __pcap_atoin(s, &v); ++ if (vlen < 0) ++ bpf_error(cstate, "invalid IPv4 address '%s'", s); ++ } + + switch (q.addr) { + +diff --git a/nametoaddr.c b/nametoaddr.c +index 53070a285..13bf4c683 100644 +--- a/nametoaddr.c ++++ b/nametoaddr.c +@@ -674,8 +674,15 @@ __pcap_atoin(const char *s, bpf_u_int32 *addr) + len = 0; + for (;;) { + n = 0; +- while (*s && *s != '.') ++ while (*s && *s != '.') { ++ if (n > 25) { ++ /* The result will be > 255 */ ++ return -1; ++ } + n = n * 10 + *s++ - '0'; ++ } ++ if (n > 255) ++ return -1; + *addr <<= 8; + *addr |= n & 0xff; + len += 8; diff --git a/libpcap.spec b/libpcap.spec new file mode 100644 index 0000000..ab049e0 --- /dev/null +++ b/libpcap.spec @@ -0,0 +1,296 @@ +Name: libpcap +Epoch: 14 +Version: 1.9.1 +Release: 6%{?dist} +Summary: A system-independent interface for user-level packet capture +License: BSD with advertising +URL: http://www.tcpdump.org + +BuildRequires: bison +BuildRequires: bluez-libs-devel +BuildRequires: flex +BuildRequires: gcc +BuildRequires: git +BuildRequires: glibc-kernheaders >= 2.2.0 +#rdma-core-devel not available on arm +%ifnarch %{arm} +BuildRequires: rdma-core-devel +%endif + +Source: http://www.tcpdump.org/release/%{name}-%{version}.tar.gz + +Patch0001: 0001-man-tcpdump-and-tcpslice-have-manpages-in-man8.patch +Patch0002: 0002-pcap-config-mitigate-multilib-conflict.patch +Patch0003: 0003-pcap-linux-apparently-ctc-interfaces-on-s390-has-eth.patch +Patch0004: 0004-invalid-ipv4.patch + +%description +Libpcap provides a portable framework for low-level network +monitoring. Libpcap can provide network statistics collection, +security monitoring and network debugging. Since almost every system +vendor provides a different interface for packet capture, the libpcap +authors created this system-independent API to ease in porting and to +alleviate the need for several system-dependent packet capture modules +in each application. + +Install libpcap if you need to do low-level network traffic monitoring +on your network. + +%package devel +Summary: Libraries and header files for the libpcap library +Requires: %{name} = %{epoch}:%{version}-%{release} + +%description devel +Libpcap provides a portable framework for low-level network +monitoring. Libpcap can provide network statistics collection, +security monitoring and network debugging. Since almost every system +vendor provides a different interface for packet capture, the libpcap +authors created this system-independent API to ease in porting and to +alleviate the need for several system-dependent packet capture modules +in each application. + +This package provides the libraries, include files, and other +resources needed for developing libpcap applications. + +%prep +%autosetup -S git + +#sparc needs -fPIC +%ifarch %{sparc} +sed -i -e 's|-fpic|-fPIC|g' configure +%endif + +%build +export CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing" +%ifarch %{arm} +%configure +%else +%configure --enable-rdma +%endif +%make_build + +%install +%make_install +rm -f $RPM_BUILD_ROOT%{_libdir}/libpcap.a + +%ldconfig_scriptlets + +%files +%license LICENSE +%doc README.md CHANGES CREDITS +%{_libdir}/libpcap.so.* +%{_mandir}/man7/pcap*.7* + +%files devel +%{_bindir}/pcap-config +%{_includedir}/pcap*.h +%{_includedir}/pcap +%{_libdir}/libpcap.so +%{_libdir}/pkgconfig/libpcap.pc +%{_mandir}/man1/pcap-config.1* +%{_mandir}/man3/pcap*.3* +%{_mandir}/man5/pcap*.5* + +%changelog +* Mon Oct 12 2020 Michal Ruprich - 14:1.9.1-6 +- Using make macros +- https://fedoraproject.org/wiki/Changes/UseMakeBuildInstallMacro + +* Tue Jul 28 2020 Fedora Release Engineering - 14:1.9.1-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild + +* Fri May 15 2020 Michal Ruprich - 14:1.9.1-4 +- Enabling rdma support in libpcap + +* Mon Feb 24 2020 Michal Ruprich - 14:1.9.1-3 +- libpcap should print an error on wrong IPv4 address + +* Wed Jan 29 2020 Fedora Release Engineering - 14:1.9.1-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild + +* Fri Oct 11 2019 Michal Ruprich - 14:1.9.1-1 +- New version 1.9.1 +- Fix for CVE-2018-16301, CVE-2019-15161, CVE-2019-15162, CVE-2019-15163, CVE-2019-15164, CVE-2019-15165 + +* Thu Jul 25 2019 Fedora Release Engineering - 14:1.9.0-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild + +* Fri Feb 01 2019 Fedora Release Engineering - 14:1.9.0-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild + +* Mon Aug 13 2018 Peter Robinson 14:1.9.0-2 +- pkgconfig file belong in devel package +- drop obsolete group in spec + +* Wed Aug 01 2018 Michal Ruprich - 14:1.9.0-1 +- New version 1.9.0 + +* Fri Jul 13 2018 Fedora Release Engineering - 14:1.8.1-11 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild + +* Wed Jun 06 2018 Michal Ruprich - 14:1.8.1-10 +- Adding support for AF_VSOCK + +* Tue Feb 20 2018 Martin Sehnoutka - 14:1.8.1-9 +- Add gcc to BuildRequires + +* Wed Feb 07 2018 Fedora Release Engineering - 14:1.8.1-8 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild + +* Sat Feb 03 2018 Igor Gnatenko - 14:1.8.1-7 +- Switch to %%ldconfig_scriptlets + +* Thu Aug 03 2017 Fedora Release Engineering - 14:1.8.1-6 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild + +* Wed Jul 26 2017 Fedora Release Engineering - 14:1.8.1-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild + +* Thu May 18 2017 Martin Sehnoutka - 14:1.8.1-4 +- Drop TPACKET_V3 patch as it should be fixed in kernel by now + +* Fri Feb 10 2017 Fedora Release Engineering - 14:1.8.1-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild + +* Wed Feb 01 2017 Stephen Gallagher - 1.8.1-2 +- Add missing %%license macro + +* Mon Oct 31 2016 Luboš Uhliarik - 14:1.8.1-1 +- new version 1.8.1 + +* Mon Aug 08 2016 Luboš Uhliarik - 14:1.8.0-1 +- new version 1.8.0 + +* Thu Feb 04 2016 Fedora Release Engineering - 14:1.7.4-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild + +* Mon Jun 29 2015 Michal Sekletar - 14:1.7.4-1 +- update to 1.7.4 (#1236387) + +* Wed Jun 17 2015 Fedora Release Engineering - 14:1.7.3-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild + +* Tue May 26 2015 Michal Sekletar - 14:1.7.3-1 +- update to 1.7.3 (#1214723) +- fix build against bluez-5 (#1178297) + +* Fri Mar 13 2015 Michal Sekletar - 14:1.7.2-1 +- update to 1.7.2 (#1201078) + +* Mon Feb 23 2015 Michal Sekletar - 14:1.6.2-2 +- fix scaling of pcap-ng timestamps (#1169322) +- remove kernel-devel from buildrequires + +* Mon Sep 29 2014 Michal Sekletar - 14:1.6.2-1 +- update to 1.6.2 (#1124174) +- disable TPACKET_V3 support (#1131500) + +* Sun Aug 17 2014 Fedora Release Engineering - 14:1.5.3-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild + +* Sat Jun 07 2014 Fedora Release Engineering - 14:1.5.3-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild + +* Mon Mar 31 2014 Michal Sekletar - 14:1.5.3-3 +- don't link against libnl + +* Fri Mar 28 2014 Michal Sekletar - 14:1.5.3-2 +- link against libnl (#765716) + +* Wed Jan 15 2014 Michal Sekletar - 14:1.5.3-1 +- update to 1.5.3 + +* Thu Nov 28 2013 Michal Sekletar - 14:1.5.1-1 +- update to 1.5.1 + +* Fri Nov 08 2013 Michal Sekletar - 14:1.5.0-1.20131108git459712e +- update to snapshot 20131108git459712e + +* Sat Aug 03 2013 Fedora Release Engineering - 14:1.4.0-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild + +* Thu Jun 06 2013 Michal Sekletar - 14:1.4.0-1 +- update to 1.4.0 + +* Tue Mar 26 2013 Michal Sekletar - 14:1.3.0-4 +- remove unused variable from pcap-config to prevent multilib conflicts +- specfile cleanup + +* Thu Feb 14 2013 Fedora Release Engineering - 14:1.3.0-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild + +* Thu Jul 19 2012 Fedora Release Engineering - 14:1.3.0-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild + +* Wed Jun 13 2012 Michal Sekletar 14:1.3.0-1 +- Update to 1.3.0 + +* Thu Jan 05 2012 Jan Synáček 14:1.2.1-2 +- Rebuilt for GCC 4.7 + +* Tue Jan 03 2012 Jan Synáček 14:1.2.1-1 +- Update to 1.2.1 +- Drop unnecessary -fragment patch + +* Fri Dec 02 2011 Michal Sekletar 14:1.2.0-1 +- update to 1.2.0 + +* Tue Sep 06 2011 Michal Sekletar 14:1.1.1-4 +- fix capture of fragmented ipv6 packets + +* Fri Apr 22 2011 Miroslav Lichvar 14:1.1.1-3 +- ignore /sys/net/dev files on ENODEV (#693943) +- drop ppp patch +- compile with -fno-strict-aliasing + +* Tue Feb 08 2011 Fedora Release Engineering - 14:1.1.1-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild + +* Tue Apr 06 2010 Miroslav Lichvar 14:1.1.1-1 +- update to 1.1.1 + +* Wed Dec 16 2009 Miroslav Lichvar 14:1.0.0-5.20091201git117cb5 +- update to snapshot 20091201git117cb5 + +* Sat Oct 17 2009 Dennis Gilmore 14:1.0.0-4.20090922gite154e2 +- use -fPIC on sparc arches + +* Wed Sep 23 2009 Miroslav Lichvar 14:1.0.0-3.20090922gite154e2 +- update to snapshot 20090922gite154e2 +- drop old soname + +* Fri Jul 24 2009 Fedora Release Engineering - 14:1.0.0-2.20090716git6de2de +- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild + +* Wed Jul 22 2009 Miroslav Lichvar 14:1.0.0-1.20090716git6de2de +- update to 1.0.0, git snapshot 20090716git6de2de + +* Wed Feb 25 2009 Fedora Release Engineering - 14:0.9.8-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild + +* Fri Jun 27 2008 Miroslav Lichvar 14:0.9.8-3 +- use CFLAGS when linking (#445682) + +* Tue Feb 19 2008 Fedora Release Engineering - 14:0.9.8-2 +- Autorebuild for GCC 4.3 + +* Wed Oct 24 2007 Miroslav Lichvar 14:0.9.8-1 +- update to 0.9.8 + +* Wed Aug 22 2007 Miroslav Lichvar 14:0.9.7-3 +- update license tag + +* Wed Jul 25 2007 Jesse Keating - 14:0.9.7-2 +- Rebuild for RH #249435 + +* Tue Jul 24 2007 Miroslav Lichvar 14:0.9.7-1 +- update to 0.9.7 + +* Tue Jun 19 2007 Miroslav Lichvar 14:0.9.6-1 +- update to 0.9.6 + +* Tue Nov 28 2006 Miroslav Lichvar 14:0.9.5-1 +- split from tcpdump package (#193657) +- update to 0.9.5 +- don't package static library +- maintain soname diff --git a/sources b/sources new file mode 100644 index 0000000..7d73e35 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (libpcap-1.9.1.tar.gz) = ae0d6b0ad8253e7e059336c0f4ed3850d20d7d2f4dc1d942c2951f99a5443a690f0cc42c6f8fdc4a0ccb19e9e985192ba6f399c4bde2c7076e420f547fddfb08 diff --git a/tests/sanity-tests/Makefile b/tests/sanity-tests/Makefile new file mode 100644 index 0000000..23291eb --- /dev/null +++ b/tests/sanity-tests/Makefile @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/libpcap +# Description: Sanity +# Author: Susant Sahani +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export TEST=/CoreOS/libpcap +export TESTVERSION=1.0 + +INCLUDES = +OBJS = test-libpcap.c +CFLAG = -Wall -g3 +CC = gcc +LIBS = -lnet -lcmocka -lpcap -lpthread + +test-libpcap:${OBJ} + ${CC} ${CFLAGS} ${INCLUDES} -o $@ ${OBJS} ${LIBS} + +run: test-libpcap + ./runtest.sh +clean: + -rm -f *~ test-libpcap + +.c.o: + ${CC} ${CFLAGS} ${INCLUDES} -c $< + +CC = gcc + +include /usr/share/rhts/lib/rhts-make.include +$(METADATA): Makefile + @echo "Owner: Susant Sahani" > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test libpcap sanity" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: libpcap" >> $(METADATA) + @echo "Requires: libpcap libpcap-devel" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + @echo "Releases: -Fedora 29" >> $(METADATA) + rhts-lint $(METADATA) diff --git a/tests/sanity-tests/runtest.sh b/tests/sanity-tests/runtest.sh new file mode 100755 index 0000000..eb1cbc3 --- /dev/null +++ b/tests/sanity-tests/runtest.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of libpcap +# Description: Tests for libpcap +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +# ~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="libpcap" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + + rlLog "Setting up veth Interface " + rlRun "ip link add veth-test type veth peer name veth-peer" + rlRun "ip addr add 192.168.50.5 dev veth-test" + rlRun "ip addr add 192.168.50.6 dev veth-peer" + rlRun "ip link set dev veth-test up" + rlRun "ip link set dev veth-peer up" + + rlRun "cp test-libpcap /usr/bin/" + rlRun "systemctl daemon-reload" + rlPhaseEnd + + rlPhaseStartTest + rlLog "Starting libpcap tests ..." + rlRun "/usr/bin/test-libpcap" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm /usr/bin/test-libpcap" + rlRun "ip link del veth-test" + rlLog "libpcap tests done" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + +rlGetTestState diff --git a/tests/sanity-tests/test-libpcap.c b/tests/sanity-tests/test-libpcap.c new file mode 100644 index 0000000..f48d8be --- /dev/null +++ b/tests/sanity-tests/test-libpcap.c @@ -0,0 +1,229 @@ +/* +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# Description: libpcap tests +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +# ~~~ +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PCAP_FILE "/var/run/libpcap-test.pcap" + +pcap_t *handle; + +struct UDP_hdr { + u_short uh_sport; /* source port */ + u_short uh_dport; /* destination port */ + u_short uh_ulen; /* datagram length */ + u_short uh_sum; /* datagram checksum */ +}; + +static void assert_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) { + unsigned int ipl; + uint32_t src, dst; + struct ip *ip; + struct ether_header *eth_header; + + eth_header = (struct ether_header *) packet; + if (ntohs(eth_header->ether_type) != ETHERTYPE_IP) + return; + + packet += sizeof(struct ether_header); + ip = (struct ip *) packet; + ipl = ip->ip_hl * 4; + + src = inet_addr("192.168.50.6"); + dst = inet_addr("192.168.50.5"); + + assert_memory_equal(&dst, &ip->ip_dst, sizeof(uint32_t)); + assert_memory_equal(&src, &ip->ip_src, sizeof(uint32_t)); + + if (ip->ip_p == IPPROTO_UDP) { + struct UDP_hdr *udp; + + packet += ipl; + + udp = (struct UDP_hdr *) packet; + + printf("UDP src_port=%d dst_port=%d\n", ntohs(udp->uh_sport), ntohs(udp->uh_dport)); + + assert_int_equal(2425, ntohs(udp->uh_sport)); + assert_int_equal(2426, ntohs(udp->uh_dport)); + } else if (ip->ip_p == IPPROTO_TCP) { + struct tcphdr *tcp; + packet += ipl; + + tcp = (struct tcphdr *) packet; + + printf("TCP src_port=%d dst_port=%d\n", ntohs(tcp->th_sport), ntohs(tcp->th_dport)); + + assert_int_equal(2425, ntohs(tcp->th_sport)); + assert_int_equal(2426, ntohs(tcp->th_dport)); + } +} + +void *capture_packet_live(void *ptr) { + char dev[] = "veth-test"; + char error_buffer[PCAP_ERRBUF_SIZE]; + struct bpf_program filter; + bpf_u_int32 subnet_mask, ip; + int total_packet_count; + int r; + + r = pcap_lookupnet(dev, &ip, &subnet_mask, error_buffer); + assert_true(r >=0); + + handle = pcap_open_live(dev, BUFSIZ, 1, 1000, error_buffer); + assert_non_null(handle); + + r = pcap_compile(handle, &filter, ptr, 0, ip); + assert_true(r >= 0); + + r = pcap_setfilter(handle, &filter); + assert_true(r >= 0); + + pcap_loop(handle, total_packet_count, assert_packet, NULL); + + return 0; +} + +void terminate_thread(int signum) { + + pcap_breakloop(handle); + pcap_close(handle); + + handle = NULL; + pthread_exit(NULL); +} + +static void test_udp_packet_ipv4(void **state) { + char dst[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; + char src[6] = {0x12,0x34,0x56,0x78,0x9a,0xab}; + char err_buf[LIBNET_ERRBUF_SIZE] = {}; + char buf[1024] = {}; + libnet_t* l; + int r, i; + uint32_t len; + pthread_t pcap_thread; + struct itimerval tval; + + timerclear(& tval.it_interval); /* zero interval means no reset of timer */ + timerclear(& tval.it_value); + tval.it_value.tv_sec = 10; /* 10 second timeout */ + + (void) signal(SIGALRM, terminate_thread); + (void) setitimer(ITIMER_REAL, & tval, NULL); + + r = pthread_create(&pcap_thread, NULL, capture_packet_live, "udp port 2425"); + assert_true(r >=0); + + l = libnet_init(LIBNET_LINK_ADV, "veth-peer", err_buf); + assert_non_null(l); + len = sprintf(buf, "1:1:1111111111111:32:hello world%d", 1); + + for (i = 0; i < 5; i++) { + + r = libnet_build_udp(2425, 2426, len + 8, 0, buf, len, l, 0); + assert_true(r >= 0); + + r = libnet_build_ipv4(20 + 8 + len, 0, 0, 0, 128, 17, 0, inet_addr("192.168.50.6"), inet_addr("192.168.50.5"), NULL, 0, l, 0); + assert_true(r >= 0); + + r = libnet_build_ethernet(dst, src, 0x0800, NULL, 0, l, 0); + assert_true(r >= 0); + + r = libnet_write(l); + assert_true(r >= 0); + + sleep(1); + } + + libnet_destroy(l); +} + +static void test_tcp_packet_ipv4(void **state) { + char dst[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; + char src[6] = {0x12,0x34,0x56,0x78,0x9a,0xab}; + char errbuf[LIBNET_ERRBUF_SIZE]; + uint8_t *payload, payload_s; + libnet_ptag_t tcp, ip, eth; + int c, i, j, seqn, ack; + char buf[1024] = {}; + pthread_t pcap_thread; + struct itimerval tval; + uint32_t len; + libnet_t *l; + int r; + + timerclear(& tval.it_interval); + timerclear(& tval.it_value); + tval.it_value.tv_sec = 10; + + (void) signal(SIGALRM, terminate_thread); + (void) setitimer(ITIMER_REAL, & tval, NULL); + + r = pthread_create(&pcap_thread, NULL, capture_packet_live, "tcp port 2425"); + assert_true(r >=0); + + payload_s = 10; + payload = malloc(payload_s*sizeof(uint8_t)); + assert_non_null(payload); + memset(payload,0,payload_s); + + l = libnet_init(LIBNET_LINK, "veth-peer", errbuf); + assert_non_null(l); + + tcp = ip = eth = LIBNET_PTAG_INITIALIZER; + for (i=0; i<5; i++){ + seqn=i * (LIBNET_TCP_H+payload_s + 1); + r = libnet_build_tcp(2425, 2426, seqn, seqn + LIBNET_TCP_H + payload_s + 1, + TH_SYN, 32767, 0, 10, LIBNET_TCP_H + payload_s, + payload, payload_s, l, tcp); + assert_true(r >=0); + + r = libnet_build_ipv4(LIBNET_IPV4_H + LIBNET_TCP_H + payload_s,0,242,0,64,IPPROTO_TCP,0, + inet_addr("192.168.50.6"), inet_addr("192.168.50.5"), + NULL,0,l,ip); + assert_true(r >=0); + + r = libnet_build_ethernet(dst, src, ETHERTYPE_IP, NULL, 0, l, eth); + assert_true(r >=0); + + r = libnet_write(l); + assert_true(r >=0); + + sleep(1); + } +} + +int main(int argc, char *argv[]) { + const struct CMUnitTest libpcap_tests[] = { + cmocka_unit_test(test_udp_packet_ipv4), + cmocka_unit_test(test_tcp_packet_ipv4), + }; + + return cmocka_run_group_tests(libpcap_tests, NULL, NULL); +} diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..6f5f1cc --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,17 @@ +- hosts: localhost + roles: + - role: standard-test-beakerlib + tags: + - classic + tests: + - sanity-tests + required_packages: + - libnet + - libnet-devel + - libpcap + - libpcap-devel + - systemd + - wireshark-cli + - libcmocka + - libcmocka-devel + - gcc