From ff3e4272ff46f1187f53c3d20275b9e9df14e2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= Date: Fri, 15 Oct 2021 13:27:49 +0200 Subject: [PATCH 1/5] Integrate libxdp as a submodule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds libxdp as a submodule and link target alongside libbpf. This should make it just as easy for examples to use libxdp as it currently is for libbpf. Some hoops need to be jumped through to make libxdp link against the same version of libbpf as the one we use in this repository. Signed-off-by: Toke Høiland-Jørgensen --- .gitmodules | 3 +++ configure | 45 +++++++++++++++++++++++++++++++++++++++++++-- lib/.gitignore | 1 + lib/Makefile | 41 ++++++++++++++++++++++++++++++++++------- lib/common.mk | 3 +++ lib/xdp-tools | 1 + 6 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 lib/.gitignore create mode 160000 lib/xdp-tools diff --git a/.gitmodules b/.gitmodules index a06b6a08..3ce07b77 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,6 @@ path = lib/libbpf url = https://github.com/xdp-project/libbpf.git ignore = dirty +[submodule "lib/xdp-tools"] + path = lib/xdp-tools + url = https://github.com/xdp-project/xdp-tools diff --git a/configure b/configure index 48b95048..966b9ff8 100755 --- a/configure +++ b/configure @@ -11,6 +11,8 @@ CONFIG=".${CONFIG}.tmp" TMPDIR=$(mktemp -d config.XXXXXX) trap 'status=$?; rm -rf $TMPDIR; rm -f $CONFIG; exit $status' EXIT HUP INT QUIT TERM +SUBMODULE_LIBBPF=0 + check_toolchain() { local clang_version @@ -123,9 +125,10 @@ EOF fi echo submodule + SUBMODULE_LIBBPF=1 echo "SYSTEM_LIBBPF:=n" >> $CONFIG - echo 'CFLAGS += -I$(LIB_DIR)/libbpf-install/usr/include' >>$CONFIG - echo 'BPF_CFLAGS += -I$(LIB_DIR)/libbpf-install/usr/include' >>$CONFIG + echo 'CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG + echo 'BPF_CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG echo 'LDFLAGS += -L$(LIB_DIR)/libbpf/src' >>$CONFIG echo 'LDLIBS += -l:libbpf.a' >>$CONFIG echo 'OBJECT_LIBBPF = $(LIB_DIR)/libbpf/src/libbpf.a' >>$CONFIG @@ -173,6 +176,42 @@ EOF fi } +check_libxdp() +{ + if [ "${FORCE_SUBMODULE_LIBXDP:-0}" -ne "1" ] && ${PKG_CONFIG} libxdp --exists; then + + LIBXDP_CFLAGS=$(${PKG_CONFIG} libxdp --cflags) + LIBXDP_LDLIBS=$(${PKG_CONFIG} libxdp --libs) + echo "SYSTEM_LIBXDP:=y" >>$CONFIG + echo 'CFLAGS += ' $LIBXDP_CFLAGS >> $CONFIG + echo 'LDLIBS += ' $LIBXDP_LDLIBS >>$CONFIG + echo 'OBJECT_LIBXDP = ' >>$CONFIG + echo system + + return 0 + fi + + echo submodule + echo "SYSTEM_LIBXDP:=n" >> $CONFIG + if [ "$SUBMODULE_LIBBPF" -eq "1" ]; then + echo "Configuring libxdp to use our libbpf submodule" + (export LIBBPF_DIR="$(readlink -m lib/libbpf)" LIBBPF_INCLUDE_DIR="$(readlink -m lib/lib-install/usr/include)"; + cd lib/xdp-tools; ./configure) + else + echo "Configuring libxdp without our libbpf" + (cd lib/xdp-tools; ./configure) + # these are already set if using libbpf as a submodule + echo 'CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG + echo 'BPF_CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG + fi + echo 'LDFLAGS += -L$(LIB_DIR)/lib-install/usr/lib' >>$CONFIG + echo 'LDLIBS += -l:libxdp.a' >>$CONFIG + echo 'OBJECT_LIBXDP = $(LIB_DIR)/lib-install/usr/lib/libxdp.a' >>$CONFIG + if ! [ -d "lib/xdp-tools/lib" ] && [ -f ".gitmodules" ] && [ -e ".git" ]; then + git submodule init && git submodule update + fi +} + quiet_config() { cat </dev/null +endif + +# Detect submodule libbpf source file changes +LIBXDP_SOURCES := $(wildcard xdp-tools/lib/libxdp/*.[ch]) + + +$(LIB_INSTALL)/usr/lib/libxdp.a: $(LIBXDP_SOURCES) + @echo ; echo " libxdp" + $(QUIET_CC)$(MAKE) -C xdp-tools BUILD_STATIC_ONLY=1 libxdp $P + $(QUIET_INSTALL)$(MAKE) -C xdp-tools DESTDIR=../../../$(LIB_INSTALL) PREFIX=/usr BUILD_STATIC_ONLY=1 libxdp_install $P + +.PHONY: libxdp_clean +libxdp_clean: + $(Q)$(MAKE) -C xdp-tools clean $P + $(Q)$(RM) -r $(LIB_INSTALL) + +else + +libxdp_clean: + @echo -n +endif diff --git a/lib/common.mk b/lib/common.mk index 811bab01..1a6a264c 100644 --- a/lib/common.mk +++ b/lib/common.mk @@ -61,6 +61,9 @@ clean:: $(OBJECT_LIBBPF): $(LIBBPF_SOURCES) $(Q)$(MAKE) -C $(LIB_DIR) libbpf +$(OBJECT_LIBXDP): $(LIBXDP_SOURCES) + $(Q)$(MAKE) -C $(LIB_DIR) libxdp + $(CONFIGMK): $(Q)$(MAKE) -C $(LIB_DIR)/.. config.mk diff --git a/lib/xdp-tools b/lib/xdp-tools new file mode 160000 index 00000000..27cbd728 --- /dev/null +++ b/lib/xdp-tools @@ -0,0 +1 @@ +Subproject commit 27cbd728e210da926d9e8584954cf6e0a1d4d2a0 From 4ac5a33a40be67c6f0a53cfd71eff93e40b89885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= Date: Fri, 15 Oct 2021 18:28:57 +0200 Subject: [PATCH 2/5] lib: simplify installation of libbpf and libxdp submodule libraries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of having the someone redundantly named 'lib/lib-install' folder, let's rename it to just 'lib/install', and drop the 'usr/' prefix of the files installed into that directory. Also, to simplify the configure script, check in the directory to git so it's always present, and always include it in the include and linker paths. On clean we just clear out the contents. Also, copy over libbpf.a to lib/install/lib alongside libxdp.a instead of putting libbpf/src in the linker path. Signed-off-by: Toke Høiland-Jørgensen --- configure | 14 ++++---------- lib/.gitignore | 1 - lib/Makefile | 15 ++++++++------- lib/common.mk | 5 +++-- lib/install/.gitignore | 4 ++++ lib/install/include/.gitignore | 2 ++ lib/install/lib/.gitignore | 2 ++ 7 files changed, 23 insertions(+), 20 deletions(-) delete mode 100644 lib/.gitignore create mode 100644 lib/install/.gitignore create mode 100644 lib/install/include/.gitignore create mode 100644 lib/install/lib/.gitignore diff --git a/configure b/configure index 966b9ff8..b133c79a 100755 --- a/configure +++ b/configure @@ -127,11 +127,8 @@ EOF echo submodule SUBMODULE_LIBBPF=1 echo "SYSTEM_LIBBPF:=n" >> $CONFIG - echo 'CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG - echo 'BPF_CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG - echo 'LDFLAGS += -L$(LIB_DIR)/libbpf/src' >>$CONFIG echo 'LDLIBS += -l:libbpf.a' >>$CONFIG - echo 'OBJECT_LIBBPF = $(LIB_DIR)/libbpf/src/libbpf.a' >>$CONFIG + echo 'OBJECT_LIBBPF = $(LIB_DIR)/install/lib/libbpf.a' >>$CONFIG if ! [ -d "lib/libbpf/src" ] && [ -f ".gitmodules" ] && [ -e ".git" ]; then git submodule init && git submodule update fi @@ -195,18 +192,15 @@ check_libxdp() echo "SYSTEM_LIBXDP:=n" >> $CONFIG if [ "$SUBMODULE_LIBBPF" -eq "1" ]; then echo "Configuring libxdp to use our libbpf submodule" - (export LIBBPF_DIR="$(readlink -m lib/libbpf)" LIBBPF_INCLUDE_DIR="$(readlink -m lib/lib-install/usr/include)"; + (export LIBBPF_DIR="$(readlink -m lib/libbpf)" LIBBPF_INCLUDE_DIR="$(readlink -m lib/install/include)"; cd lib/xdp-tools; ./configure) else echo "Configuring libxdp without our libbpf" (cd lib/xdp-tools; ./configure) - # these are already set if using libbpf as a submodule - echo 'CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG - echo 'BPF_CFLAGS += -I$(LIB_DIR)/lib-install/usr/include' >>$CONFIG fi - echo 'LDFLAGS += -L$(LIB_DIR)/lib-install/usr/lib' >>$CONFIG + echo 'LDFLAGS += -L$(LIB_DIR)/install/lib' >>$CONFIG echo 'LDLIBS += -l:libxdp.a' >>$CONFIG - echo 'OBJECT_LIBXDP = $(LIB_DIR)/lib-install/usr/lib/libxdp.a' >>$CONFIG + echo 'OBJECT_LIBXDP = $(LIB_DIR)/install/lib/libxdp.a' >>$CONFIG if ! [ -d "lib/xdp-tools/lib" ] && [ -f ".gitmodules" ] && [ -e ".git" ]; then git submodule init && git submodule update fi diff --git a/lib/.gitignore b/lib/.gitignore deleted file mode 100644 index 36d52771..00000000 --- a/lib/.gitignore +++ /dev/null @@ -1 +0,0 @@ -lib-install diff --git a/lib/Makefile b/lib/Makefile index bbcbfd67..f4eaab4f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,7 +2,7 @@ LIBBPF_CFLAGS:=$(if $(CFLAGS),$(CFLAGS),-g -O2 -Werror -Wall) -fPIC LIB_DIR = . -LIB_INSTALL := lib-install +LIB_INSTALL := $(LIB_DIR)/install include defines.mk SUBDIRS= @@ -16,6 +16,8 @@ all: $(OBJECT_LIBBPF) $(OBJECT_LIBXDP) clean: libbpf_clean libxdp_clean @for i in $(SUBDIRS); \ do $(MAKE) -C $$i clean; done + $(Q)find $(LIB_INSTALL) -type f -not -name .gitignore -delete + $(Q)find $(LIB_INSTALL) -type d -empty -delete install: install -m 0755 -d $(DESTDIR)$(HDRDIR) @@ -35,15 +37,15 @@ endif # Detect submodule libbpf source file changes LIBBPF_SOURCES := $(wildcard libbpf/src/*.[ch]) -libbpf/src/libbpf.a: $(LIBBPF_SOURCES) +$(LIB_INSTALL)/lib/libbpf.a: $(LIBBPF_SOURCES) @echo ; echo " libbpf" $(QUIET_CC)$(MAKE) -C libbpf/src CFLAGS="$(LIBBPF_CFLAGS)" $P - $(QUIET_INSTALL)$(MAKE) -C libbpf/src DESTDIR=../../$(LIB_INSTALL) install_headers $P + $(QUIET_INSTALL)$(MAKE) -C libbpf/src DESTDIR=../../$(LIB_INSTALL) PREFIX= install_headers $P + $(Q)cp -fp libbpf/src/libbpf.a install/lib/ .PHONY: libbpf_clean libbpf_clean: $(Q)$(MAKE) -C libbpf/src clean $P - $(Q)$(RM) -r $(LIB_INSTALL) else @@ -61,15 +63,14 @@ endif LIBXDP_SOURCES := $(wildcard xdp-tools/lib/libxdp/*.[ch]) -$(LIB_INSTALL)/usr/lib/libxdp.a: $(LIBXDP_SOURCES) +$(LIB_INSTALL)/lib/libxdp.a: $(LIBXDP_SOURCES) @echo ; echo " libxdp" $(QUIET_CC)$(MAKE) -C xdp-tools BUILD_STATIC_ONLY=1 libxdp $P - $(QUIET_INSTALL)$(MAKE) -C xdp-tools DESTDIR=../../../$(LIB_INSTALL) PREFIX=/usr BUILD_STATIC_ONLY=1 libxdp_install $P + $(QUIET_INSTALL)$(MAKE) -C xdp-tools DESTDIR=../../../$(LIB_INSTALL) PREFIX= BUILD_STATIC_ONLY=1 libxdp_install $P .PHONY: libxdp_clean libxdp_clean: $(Q)$(MAKE) -C xdp-tools clean $P - $(Q)$(RM) -r $(LIB_INSTALL) else diff --git a/lib/common.mk b/lib/common.mk index 1a6a264c..1e28df44 100644 --- a/lib/common.mk +++ b/lib/common.mk @@ -47,8 +47,9 @@ BPF_CFLAGS += -D__TARGET_ARCH_$(ARCH) # BPF-prog kern and userspace shares struct via header file: KERN_USER_H ?= $(wildcard common_kern_user.h) -CFLAGS += -I$(INCLUDE_DIR) -I$(HEADER_DIR) -I$(LIB_DIR)/util $(EXTRA_CFLAGS) -BPF_CFLAGS += -I$(INCLUDE_DIR) -I$(HEADER_DIR) $(EXTRA_CFLAGS) +CFLAGS += -I$(INCLUDE_DIR) -I$(HEADER_DIR) -I$(LIB_DIR)/util -I$(LIB_DIR)/install/include $(EXTRA_CFLAGS) +BPF_CFLAGS += -I$(INCLUDE_DIR) -I$(HEADER_DIR) -I$(LIB_DIR)/install/include $(EXTRA_CFLAGS) +LDFLAGS += -L$(LIB_DIR)/install/lib BPF_HEADERS := $(wildcard $(HEADER_DIR)/*/*.h) $(wildcard $(INCLUDE_DIR)/*/*.h) diff --git a/lib/install/.gitignore b/lib/install/.gitignore new file mode 100644 index 00000000..14f255b9 --- /dev/null +++ b/lib/install/.gitignore @@ -0,0 +1,4 @@ +* +!.gitignore +!include +!lib diff --git a/lib/install/include/.gitignore b/lib/install/include/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/lib/install/include/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/lib/install/lib/.gitignore b/lib/install/lib/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/lib/install/lib/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From 4d74e4aaf3d0f79ef8718ed80dfb9d3d98c4d80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= Date: Fri, 15 Oct 2021 18:31:59 +0200 Subject: [PATCH 3/5] lib/xdp-tools: update version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pull the latest version of xdp-tools into the submodule. Change the wildcard pattern for libxdp to not include the XDP programs to avoid constantly recompiling it. Signed-off-by: Toke Høiland-Jørgensen --- lib/Makefile | 2 +- lib/xdp-tools | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index f4eaab4f..a5c562d3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -60,7 +60,7 @@ P:= >/dev/null endif # Detect submodule libbpf source file changes -LIBXDP_SOURCES := $(wildcard xdp-tools/lib/libxdp/*.[ch]) +LIBXDP_SOURCES := $(wildcard xdp-tools/lib/libxdp/libxdp*.[ch]) xdp-tools/lib/libxdp/xsk.c $(LIB_INSTALL)/lib/libxdp.a: $(LIBXDP_SOURCES) diff --git a/lib/xdp-tools b/lib/xdp-tools index 27cbd728..8858c814 160000 --- a/lib/xdp-tools +++ b/lib/xdp-tools @@ -1 +1 @@ -Subproject commit 27cbd728e210da926d9e8584954cf6e0a1d4d2a0 +Subproject commit 8858c814d039340f1789a12412e995da5d7e909c From f27c7c2c46d5c292f2c2260bbcd846726832a46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= Date: Wed, 20 Apr 2022 13:24:22 +0200 Subject: [PATCH 4/5] lib/util: Import logging helpers from xdp-tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Include logging.{h,c} from xdp-tools so utilities can use them for setting libxdp and libbpf logging. Signed-off-by: Toke Høiland-Jørgensen --- lib/Makefile | 2 +- lib/util/Makefile | 18 +++++++++ lib/util/logging.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++ lib/util/logging.h | 35 ++++++++++++++++++ lib/util/util.mk | 2 +- 5 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 lib/util/Makefile create mode 100644 lib/util/logging.c create mode 100644 lib/util/logging.h diff --git a/lib/Makefile b/lib/Makefile index a5c562d3..7c32959f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -5,7 +5,7 @@ LIB_DIR = . LIB_INSTALL := $(LIB_DIR)/install include defines.mk -SUBDIRS= +SUBDIRS=util all: $(OBJECT_LIBBPF) $(OBJECT_LIBXDP) @set -e; \ diff --git a/lib/util/Makefile b/lib/util/Makefile new file mode 100644 index 00000000..6df9a733 --- /dev/null +++ b/lib/util/Makefile @@ -0,0 +1,18 @@ +include util.mk + +LIB_DIR ?= .. + +include $(LIB_DIR)/defines.mk + +all: $(UTIL_OBJS) + +# Create expansions for dependencies +UTIL_H := ${UTIL_OBJS:.o=.h} + +CFLAGS+= -I$(LIB_DIR)/install/include + +$(UTIL_OBJS): %.o: %.c $(UTIL_H) $(LIBMK) + $(QUIET_CC)$(CC) $(CFLAGS) -Wall -I../../headers -c -o $@ $< + +clean: + $(Q)rm -f $(UTIL_OBJS) diff --git a/lib/util/logging.c b/lib/util/logging.c new file mode 100644 index 00000000..149386e0 --- /dev/null +++ b/lib/util/logging.c @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include + +#include +#include + +#define __unused __attribute__((unused)) +#include "logging.h" + +static enum logging_print_level log_level = LOG_INFO; + +static int print_func(enum logging_print_level level, const char *format, + va_list args) +{ + if (level > log_level) + return 0; + + return vfprintf(stderr, format, args); +} + +static int libbpf_print_func(enum libbpf_print_level level, const char *format, + va_list args) +{ + return print_func(level + 1, format, args); +} + +static int libbpf_silent_func(__unused enum libbpf_print_level level, + __unused const char *format, + __unused va_list args) +{ + return 0; +} + +static int libxdp_print_func(enum libxdp_print_level level, const char *format, + va_list args) +{ + return print_func(level + 1, format, args); +} + +static int libxdp_silent_func(__unused enum libxdp_print_level level, + __unused const char *format, + __unused va_list args) +{ + return 0; +} + +#define __printf(a, b) __attribute__((format(printf, a, b))) + +__printf(2, 3) void logging_print(enum logging_print_level level, + const char *format, ...) +{ + va_list args; + + va_start(args, format); + print_func(level, format, args); + va_end(args); +} + +void init_lib_logging(void) +{ + libbpf_set_print(libbpf_print_func); + libxdp_set_print(libxdp_print_func); +} + +void silence_libbpf_logging(void) +{ + if (log_level < LOG_VERBOSE) + libbpf_set_print(libbpf_silent_func); +} + +void silence_libxdp_logging(void) +{ + if (log_level < LOG_VERBOSE) + libxdp_set_print(libxdp_silent_func); +} + +enum logging_print_level set_log_level(enum logging_print_level level) +{ + enum logging_print_level old_level = log_level; + + log_level = level; + return old_level; +} + +enum logging_print_level increase_log_level(void) +{ + if (log_level < LOG_VERBOSE) + log_level++; + return log_level; +} diff --git a/lib/util/logging.h b/lib/util/logging.h new file mode 100644 index 00000000..16c4e744 --- /dev/null +++ b/lib/util/logging.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LOGGING_H +#define __LOGGING_H + +/* This matches the libbpf logging levels, but with an additional VERBOSE level; + * we demote all libbpf messages by one level so debug messages only show up on + * VERBOSE. + */ +enum logging_print_level { + LOG_WARN, + LOG_INFO, + LOG_DEBUG, + LOG_VERBOSE, +}; + +extern void logging_print(enum logging_print_level level, const char *format, + ...) __attribute__((format(printf, 2, 3))); + +#define __pr(level, fmt, ...) \ + do { \ + logging_print(level, fmt, ##__VA_ARGS__); \ + } while (0) + +#define pr_warn(fmt, ...) __pr(LOG_WARN, fmt, ##__VA_ARGS__) +#define pr_info(fmt, ...) __pr(LOG_INFO, fmt, ##__VA_ARGS__) +#define pr_debug(fmt, ...) __pr(LOG_DEBUG, fmt, ##__VA_ARGS__) + +void init_lib_logging(void); +void silence_libbpf_logging(void); +void silence_libxdp_logging(void); +enum logging_print_level set_log_level(enum logging_print_level level); +enum logging_print_level increase_log_level(); + +#endif diff --git a/lib/util/util.mk b/lib/util/util.mk index b7f160a9..ab443bb5 100644 --- a/lib/util/util.mk +++ b/lib/util/util.mk @@ -1,2 +1,2 @@ # list of objects in this directory -UTIL_OBJS := json_writer.o +UTIL_OBJS := json_writer.o logging.o From 24cea3847419f03c3eb1c535bf74bd6d917e4ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= Date: Wed, 20 Apr 2022 13:25:27 +0200 Subject: [PATCH 5/5] nat64-bpf: Use logging helpers and add verbose option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the newly-added logging helpers from logging.h and add a -v option to increase the effective log level. Signed-off-by: Toke Høiland-Jørgensen --- nat64-bpf/nat64.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nat64-bpf/nat64.c b/nat64-bpf/nat64.c index 694b6b34..887f1331 100644 --- a/nat64-bpf/nat64.c +++ b/nat64-bpf/nat64.c @@ -20,6 +20,8 @@ #include #include +#include "logging.h" + #include "nat64.h" #include "nat64_kern.skel.h" @@ -34,6 +36,7 @@ static const struct option long_options[] = { { "v6-prefix", required_argument, NULL, '6' }, // v6 prefix to use for nat64 { "v4-prefix", required_argument, NULL, '4' }, // v4 prefix to use for nat64 { "timeout", required_argument, NULL, 't' }, // Address mapping timeout interval in s + { "verbose", required_argument, NULL, 'v' }, // verbose logging { 0, 0, NULL, 0 } }; @@ -85,7 +88,7 @@ static int parse_arguments(int argc, char *argv[], struct nat64_user_config *con config->c.v6_prefix.s6_addr[2] = 0xff; config->c.v6_prefix.s6_addr[3] = 0x9b; - while ((opt = getopt_long(argc, argv, "i:6:4:t:a:hu", long_options, + while ((opt = getopt_long(argc, argv, "i:6:4:t:a:huv", long_options, NULL)) != -1) { switch (opt) { case 'i': @@ -161,6 +164,9 @@ static int parse_arguments(int argc, char *argv[], struct nat64_user_config *con case 'u': config->unload = true; break; + case 'v': + increase_log_level(); + break; default: fprintf(stderr, "Unknown option %s\n", argv[optind]); return -EINVAL; @@ -362,6 +368,8 @@ int main(int argc, char *argv[]) DECLARE_LIBBPF_OPTS(bpf_tc_opts, attach_egress); DECLARE_LIBBPF_OPTS(bpf_tc_opts, attach_ingress); + init_lib_logging(); + err = parse_arguments(argc, argv, &cfg); if (err) return EXIT_FAILURE;