summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-08-04 19:30:19 +0300
committerTobias Klauser <tklauser@distanz.ch>2016-08-05 10:55:10 +0200
commit20a5e15443bfbbb7e6624a754832cdce19d462a0 (patch)
treee1bfc3dd5ae574279a53f2bc669a3ca863957117
parentc831bcda3e2638c55b286bd538415ea79f510cdb (diff)
netsniff-ng: Allow to compile without libnl
One might not want to install libnl just for sniffing packets, for example if netsniff-ng will be compiled on embedded or switch system. Hide libnl dependend code if CONFIG_LIBNL=0. In case the `--rfraw' option is used, the user will get a panic message. In case of netlink messages being sniffed, they will not be dissected. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--dissector.h4
-rw-r--r--dissector_netlink.c2
-rw-r--r--dissector_netlink.h5
-rw-r--r--dissector_sll.c5
-rw-r--r--netsniff-ng/Makefile27
5 files changed, 29 insertions, 14 deletions
diff --git a/dissector.h b/dissector.h
index 52f341b..0689247 100644
--- a/dissector.h
+++ b/dissector.h
@@ -10,9 +10,9 @@
#include <stdlib.h>
#include <stdint.h>
#include <sys/socket.h>
-#include <linux/if_packet.h>
#include <linux/if.h>
-#include <netlink/msg.h>
+#include <linux/netlink.h>
+#include <linux/if_packet.h>
#include "ring.h"
#include "tprintf.h"
diff --git a/dissector_netlink.c b/dissector_netlink.c
index 2b23a99..1884d74 100644
--- a/dissector_netlink.c
+++ b/dissector_netlink.c
@@ -9,7 +9,7 @@
static inline void dissector_init_entry(int type)
{
- dissector_set_print_type(&nlmsg_ops, type);
+ dissector_set_print_type(dissector_get_netlink_entry_point(), type);
}
static inline void dissector_init_exit(int type)
diff --git a/dissector_netlink.h b/dissector_netlink.h
index 9d30e56..240ff1c 100644
--- a/dissector_netlink.h
+++ b/dissector_netlink.h
@@ -7,6 +7,7 @@
#ifndef DISSECTOR_NETLINK_H
#define DISSECTOR_NETLINK_H
+#include "config.h"
#include "protos.h"
extern void dissector_init_netlink(int fnttype);
@@ -14,7 +15,11 @@ extern void dissector_cleanup_netlink(void);
static inline struct protocol *dissector_get_netlink_entry_point(void)
{
+#ifdef HAVE_LIBNL
return &nlmsg_ops;
+#else
+ return &none_ops;
+#endif
}
static inline struct protocol *dissector_get_netlink_exit_point(void)
diff --git a/dissector_sll.c b/dissector_sll.c
index cde0d54..10fd7d9 100644
--- a/dissector_sll.c
+++ b/dissector_sll.c
@@ -3,12 +3,15 @@
* Subject to the GPL, version 2.
*/
+#include <arpa/inet.h>
+
#include "protos.h"
#include "pcap_io.h"
#include "pkt_buff.h"
#include "dissector.h"
#include "dissector_sll.h"
#include "dissector_eth.h"
+#include "dissector_netlink.h"
#include "lookup.h"
static char *pkt_type2str(uint8_t pkttype)
@@ -56,7 +59,7 @@ static void sll_print_full(struct pkt_buff *pkt)
break;
case LINKTYPE_NETLINK:
case ___constant_swab32(LINKTYPE_NETLINK):
- pkt->dissector = &nlmsg_ops;
+ pkt->dissector = dissector_get_netlink_entry_point();
break;
default:
tprintf(" [ Unknown protocol ]\n");
diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile
index 6f9d0b2..d1d8a85 100644
--- a/netsniff-ng/Makefile
+++ b/netsniff-ng/Makefile
@@ -1,7 +1,4 @@
-netsniff-ng-libs = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libnl-3.0) \
- $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libnl-genl-3.0) \
- $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libnl-route-3.0) \
- -lpthread
+netsniff-ng-libs = -lpthread
ifeq ($(CONFIG_LIBPCAP), 1)
netsniff-ng-libs += -lpcap
@@ -10,6 +7,11 @@ ifeq ($(CONFIG_GEOIP), 1)
netsniff-ng-libs += -lGeoIP \
-lz
endif
+ifeq ($(CONFIG_LIBNL), 1)
+netsniff-ng-libs += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libnl-3.0) \
+ $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libnl-genl-3.0) \
+ $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libnl-route-3.0)
+endif
netsniff-ng-objs = dissector.o \
dissector_sll.o \
@@ -34,7 +36,6 @@ netsniff-ng-objs = dissector.o \
proto_ipv6_no_nxt_hdr.o \
proto_ipv6_routing.o \
proto_lldp.o \
- proto_nlmsg.o \
proto_none.o \
proto_tcp.o \
proto_udp.o \
@@ -63,7 +64,6 @@ netsniff-ng-objs = dissector.o \
ring.o \
tprintf.o \
timer.o \
- mac80211.o \
die.o \
sysctl.o \
netsniff-ng.o
@@ -77,11 +77,18 @@ endif
ifeq ($(CONFIG_HWTSTAMP), 1)
netsniff-ng-objs += tstamping.o
endif
+ifeq ($(CONFIG_LIBNL), 1)
+netsniff-ng-objs += mac80211.o \
+ proto_nlmsg.o
+endif
+
+netsniff-ng-eflags = -DNEED_TCPDUMP_LIKE_FILTER
-netsniff-ng-eflags = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnl-3.0) \
- $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnl-genl-3.0) \
- $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnl-route-3.0) \
- -DNEED_TCPDUMP_LIKE_FILTER
+ifeq ($(CONFIG_LIBNL), 1)
+netsniff-ng-eflags += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnl-3.0) \
+ $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnl-genl-3.0) \
+ $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libnl-route-3.0)
+endif
netsniff-ng-confs = ether.conf \
tcp.conf \