There is reason to do not install libnl-xxx packages just for sniffing packets, for example if netsniff-ng will be compiled on embedded or switch system.
Hide libnl depended code with CONFIG_NO_LIBNL option. In case if user will use --rfraw option the panic message will be printed, in case if netlink messages will be sniffed the noop will be used. Signed-off-by: Vadim Kochan <vadi...@gmail.com> --- dissector.h | 4 ++-- dissector_netlink.c | 4 ++++ dissector_netlink.h | 4 ++++ dissector_sll.c | 5 ++++- netsniff-ng/Makefile | 27 +++++++++++++++++---------- 5 files changed, 31 insertions(+), 13 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..f2c2897 100644 --- a/dissector_netlink.c +++ b/dissector_netlink.c @@ -9,7 +9,11 @@ static inline void dissector_init_entry(int type) { +#ifdef CONFIG_NO_LIBNL + dissector_set_print_type(&none_ops, type); +#else dissector_set_print_type(&nlmsg_ops, type); +#endif } static inline void dissector_init_exit(int type) diff --git a/dissector_netlink.h b/dissector_netlink.h index 9d30e56..c4cf3d9 100644 --- a/dissector_netlink.h +++ b/dissector_netlink.h @@ -14,7 +14,11 @@ extern void dissector_cleanup_netlink(void); static inline struct protocol *dissector_get_netlink_entry_point(void) { +#ifdef CONFIG_NO_LIBNL + return &none_ops; +#else return &nlmsg_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..645d2a9 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 +ifneq ($(CONFIG_NO_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 +ifneq ($(CONFIG_NO_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 +ifneq ($(CONFIG_NO_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 \ -- 2.6.3 -- You received this message because you are subscribed to the Google Groups "netsniff-ng" group. To unsubscribe from this group and stop receiving emails from it, send an email to netsniff-ng+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.