summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHervé Boisse <admin@netgeek.ovh>2023-01-17 10:43:35 +0100
committerHervé Boisse <admin@netgeek.ovh>2023-01-17 12:15:51 +0100
commit19979c4541ddcc817c64ea911a309ee71a8cc250 (patch)
treea5049ee8ea83d7eb642171006a3aec0dcc1102fc
parent8e8e0f71162ef33b045bf424bb1bd83411a9ac6a (diff)
downloadlibnet-19979c4541ddcc817c64ea911a309ee71a8cc250.tar.gz
Remove support for SOCK_PACKET sockets
The current code has a build-time check to verify that PF_PACKET sockets are supported on Linux systems and if not, fallback on SOCK_PACKET sockets. The test implementation relies on FTM (Feature Test Macros) to detect glibc and its version to include correct headers. But, some libc such as the musl libc do not have such macros, making the test program compilation fail and libnet fallback on SOCK_PACKET. Since PF_PACKET support is present in kernel for more than 20 years now, the simplest solution and safe choice is to just drop support for SOCK_PACKET and assume PF_PACKET is always available on any Linux system. Signed-off-by: Hervé Boisse <admin@netgeek.ovh>
-rw-r--r--configure.ac3
-rw-r--r--m4/acinclude.m487
-rw-r--r--src/libnet_link_linux.c17
-rw-r--r--win32/config.h1
4 files changed, 0 insertions, 108 deletions
diff --git a/configure.ac b/configure.ac
index b0a5e93..f1c592e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,7 +77,6 @@ AC_MSG_RESULT($have_socklen_t)
#
AC_LIBNET_ENDIAN_CHECK
AC_SUBST(ENDIANESS)
-AC_SUBST(HAVE_PACKET_SOCKET)
AC_SUBST(ADDITIONAL_LIBS)
AC_SUBST(PKG_CONFIG_DEFINES)
AC_SUBST(PKG_CONFIG_LIBS)
@@ -105,7 +104,6 @@ AS_IF([test -n "${with_link_layer}"], [
[win32], [AC_LIBOBJ([libnet_link_win32])],
[none], [AC_LIBOBJ([libnet_link_none])],
[linux], [AC_LIBOBJ([libnet_link_linux])
- AC_LIBNET_CHECK_PF_PACKET
AC_LIBNET_LINUX_PROCFS],
[AC_MSG_ERROR([Invalid link type "${with_link_layer}"])])
AC_MSG_RESULT(user selected link layer ${with_link_layer})],
@@ -131,7 +129,6 @@ AS_IF([test -n "${with_link_layer}"], [
[test "${ac_cv_header_linux_socket_h}" = "yes"], [
AC_LIBOBJ([libnet_link_linux])
AC_MSG_RESULT(found link layer linux)
- AC_LIBNET_CHECK_PF_PACKET
AC_LIBNET_LINUX_PROCFS],
[test "${cross_compiling}" != "yes" -a -c /dev/bpf0], [
# check again in case not readable
diff --git a/m4/acinclude.m4 b/m4/acinclude.m4
index f0d8ef8..b0e1891 100644
--- a/m4/acinclude.m4
+++ b/m4/acinclude.m4
@@ -26,93 +26,6 @@ AC_DEFUN([AC_LIBNET_LINUX_PROCFS],
fi])
dnl
-dnl Checks to see if this linux kernel has a working PF_PACKET
-dnl
-dnl usage:
-dnl
-dnl AC_LIBNET_CHECK_PF_PACKET
-dnl
-dnl results:
-dnl
-dnl HAVE_PACKET_SOCKET (DEFINED)
-dnl
-
-AC_DEFUN([AC_LIBNET_CHECK_PF_PACKET],
-[
- AC_MSG_CHECKING(for packet socket (PF_PACKET))
- AC_CACHE_VAL(libnet_cv_have_packet_socket,
-
- [
- cat > pf_packet-test.c << EOF
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <features.h> /* for the glibc version number */
-#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
-#include <netpacket/packet.h>
-#include <net/ethernet.h> /* the L2 protocols */
-#else
-#include <asm/types.h>
-#include <linux/if_packet.h>
-#include <linux/if_ether.h> /* The L2 protocols */
-#endif
-
-#ifndef SOL_PACKET
-#define SOL_PACKET 263
-#endif /* SOL_PACKET */
-
-int
-main(int argc, char **argv)
-{
- int fd;
-
- fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
- if (fd == -1)
- {
- if (errno == EPERM)
- {
- /* user's UID != 0 */
- printf("probably");
- exit (EXIT_FAILURE);
- }
- printf("no");
- exit (EXIT_FAILURE);
- }
- printf("yes");
- exit (EXIT_SUCCESS);
-}
-EOF
- ${CC-cc} -o pf_packet-test $CFLAGS pf_packet-test.c >/dev/null 2>&1
-
- # Oopz 4.3 BSD doesn't have this. Sorry.
- if test ! -x ./pf_packet-test ; then
- libnet_cv_have_packet_socket=choked
- else
- libnet_cv_have_packet_socket=`./pf_packet-test`;
- fi
- if test $libnet_cv_have_packet_socket = choked; then
- AC_MSG_RESULT(test program compile choked... assuming no)
- elif test $libnet_cv_have_packet_socket = yes; then
- AC_MSG_RESULT(yes)
- elif test $libnet_cv_have_packet_socket = probably; then
- AC_MSG_RESULT(test program got EPERM... assuming yes)
- elif test $libnet_cv_have_packet_socket = no; then
- AC_MSG_RESULT(no)
- fi
-
- rm -f pf_packet-test* core core.pf_packet-test
-
- ])
-
- if test $libnet_cv_have_packet_socket = yes -o $libnet_cv_have_packet_socket = probably; then
- AC_DEFINE(HAVE_PACKET_SOCKET, 1,
- [Define if we're running on a Linux system with PF_PACKET sockets.])
- fi
-])
-
-dnl
dnl Looks for a previous libnet version and attempts to determine which version
dnl it is. Version 0.8 was the first version that actually knew internally
dnl what version it was.
diff --git a/src/libnet_link_linux.c b/src/libnet_link_linux.c
index e3921f6..1bbcdcb 100644
--- a/src/libnet_link_linux.c
+++ b/src/libnet_link_linux.c
@@ -41,13 +41,11 @@
#include <netinet/if_ether.h>
#include <net/if_arp.h>
-#if (HAVE_PACKET_SOCKET)
#ifndef SOL_PACKET
#define SOL_PACKET 263
#endif /* SOL_PACKET */
#include <netpacket/packet.h>
#include <net/ethernet.h> /* the L2 protocols */
-#endif /* HAVE_PACKET_SOCKET */
#include "../include/libnet.h"
@@ -77,11 +75,7 @@ libnet_open_link(libnet_t *l)
return (-1);
}
-#if (HAVE_PACKET_SOCKET)
l->fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
-#else
- l->fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
-#endif
if (l->fd == -1)
{
if (errno == EPERM) {
@@ -186,7 +180,6 @@ libnet_close_link(libnet_t *l)
}
-#if (HAVE_PACKET_SOCKET)
static int
get_iface_index(int fd, const char *device)
{
@@ -203,18 +196,13 @@ get_iface_index(int fd, const char *device)
return ifr.ifr_ifindex;
}
-#endif
int
libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
{
ssize_t c;
-#if (HAVE_PACKET_SOCKET)
struct sockaddr_ll sa;
-#else
- struct sockaddr sa;
-#endif
if (l == NULL)
{
@@ -222,7 +210,6 @@ libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
}
memset(&sa, 0, sizeof (sa));
-#if (HAVE_PACKET_SOCKET)
sa.sll_family = AF_PACKET;
sa.sll_ifindex = get_iface_index(l->fd, l->device);
if (sa.sll_ifindex == -1)
@@ -230,10 +217,6 @@ libnet_write_link(libnet_t *l, const uint8_t *packet, uint32_t size)
return (-1);
}
sa.sll_protocol = htons(ETH_P_ALL);
-#else
- strncpy(sa.sa_data, l->device, sizeof (sa.sa_data) - 1);
- sa.sa_data[sizeof (sa.sa_data) - 1] = 0;
-#endif
c = sendto(l->fd, packet, size, 0,
(struct sockaddr *)&sa, sizeof (sa));
diff --git a/win32/config.h b/win32/config.h
index 730c678..e9005dd 100644
--- a/win32/config.h
+++ b/win32/config.h
@@ -10,7 +10,6 @@
#undef HAVE_HPUX11
#undef HAVE_SOCKADDR_SA_LEN
#undef HAVE_DLPI
-#undef HAVE_PACKET_SOCKET
#undef HAVE_STRUCT_IP_CSUM
#undef HAVE_LIB_PCAP
#undef STUPID_SOLARIS_CHECKSUM_BUG