From 923f4c9f1c956a46cd6b2b6e4892a5326a8e71c1 Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Mon, 28 Nov 2016 11:54:07 +0100 Subject: [PATCH] l2tpd: move logging into own file --- siu/l2tp/Makefile | 2 +- siu/l2tp/l2tpd.c | 24 ++++-------------------- siu/l2tp/l2tpd.h | 4 ---- siu/l2tp/l2tpd_fsm.c | 1 + siu/l2tp/l2tpd_lapd.c | 1 + siu/l2tp/l2tpd_logging.c | 26 ++++++++++++++++++++++++++ siu/l2tp/l2tpd_logging.h | 9 +++++++++ siu/l2tp/l2tpd_packet.c | 1 + 8 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 siu/l2tp/l2tpd_logging.c create mode 100644 siu/l2tp/l2tpd_logging.h diff --git a/siu/l2tp/Makefile b/siu/l2tp/Makefile index aa3b12f..dd57b97 100644 --- a/siu/l2tp/Makefile +++ b/siu/l2tp/Makefile @@ -8,7 +8,7 @@ CFLAGS += $(EXTRA_CFLAGS) all: l2tpd test_connect -l2tpd: l2tpd.o l2tpd_fsm.o l2tpd_data.o l2tpd_packet.o l2tpd_socket.c l2tpd_lapd.c crc32.c +l2tpd: l2tpd.o l2tpd_fsm.o l2tpd_data.o l2tpd_packet.o l2tpd_socket.c l2tpd_lapd.c l2tpd_logging.c crc32.c $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) test_connect: test_connect.o diff --git a/siu/l2tp/l2tpd.c b/siu/l2tp/l2tpd.c index 84f593d..f83e86d 100644 --- a/siu/l2tp/l2tpd.c +++ b/siu/l2tp/l2tpd.c @@ -20,6 +20,7 @@ #include "l2tpd_fsm.h" #include "l2tpd_packet.h" #include "l2tpd_lapd.h" +#include "l2tpd_logging.h" #include "l2tpd_socket.h" struct l2tpd_instance *l2i; @@ -74,26 +75,14 @@ static int l2tpd_instance_start(struct l2tpd_instance *li) return 0; } -/* default categories */ -static struct log_info_cat l2tp_categories[] = { - [DL2TP] = { - .name = "DL2TP", - .description = "L2TP logging messages", - .enabled = 1, .loglevel = LOGL_DEBUG, - }, -}; - -static const struct log_info l2tp_log_info = { - .cat = l2tp_categories, - .num_cat = ARRAY_SIZE(l2tp_categories), -}; - int main(int argc, char **argv) { int rc; - struct log_target *stderr_target; + void *tall_l2tp_ctx = talloc_named_const(NULL, 0, "l2tpd"); + l2tpd_log_init(); + /* register fsms */ osmo_fsm_register(&l2tp_cc_fsm); osmo_fsm_register(&l2tp_ic_fsm); @@ -113,11 +102,6 @@ int main(int argc, char **argv) if (rc < 0) exit(1); - log_init(&l2tp_log_info, NULL); - stderr_target = log_target_create_stderr(); - log_add_target(stderr_target); - log_set_print_filename(stderr_target, 0); - l2tp_socket_init(&l2i->rsl_oml.state, l2i->cfg.rsl_oml_path, 100, DL2TP); l2tp_socket_init(&l2i->trau.state, l2i->cfg.trau_path, 100, DL2TP); l2tp_socket_init(&l2i->pgsl.state, l2i->cfg.pgsl_path, 100, DL2TP); diff --git a/siu/l2tp/l2tpd.h b/siu/l2tp/l2tpd.h index 5bea602..146dc35 100644 --- a/siu/l2tp/l2tpd.h +++ b/siu/l2tp/l2tpd.h @@ -109,10 +109,6 @@ struct l2tpd_instance { } cfg; }; -enum { - DL2TP, -}; - extern struct l2tpd_instance *l2i; extern void l2tpd_explicit_ack_cb(void *data); diff --git a/siu/l2tp/l2tpd_fsm.c b/siu/l2tp/l2tpd_fsm.c index f1e3d3d..8dcf9c5 100644 --- a/siu/l2tp/l2tpd_fsm.c +++ b/siu/l2tp/l2tpd_fsm.c @@ -7,6 +7,7 @@ #include "l2tpd_packet.h" #include "l2tpd_data.h" #include "l2tpd_fsm.h" +#include "l2tpd_logging.h" #define S(x) (1 << (x)) diff --git a/siu/l2tp/l2tpd_lapd.c b/siu/l2tp/l2tpd_lapd.c index eeea628..6d6f102 100644 --- a/siu/l2tp/l2tpd_lapd.c +++ b/siu/l2tp/l2tpd_lapd.c @@ -11,6 +11,7 @@ #include "l2tpd_lapd.h" #include "l2tpd_packet.h" #include "l2tpd_socket.h" +#include "l2tpd_logging.h" /* lapd and ehdlc differs in the first 16 bit * lapd saves tei, sapi, c/r bit, ea1, ea2 bit diff --git a/siu/l2tp/l2tpd_logging.c b/siu/l2tp/l2tpd_logging.c new file mode 100644 index 0000000..00eef53 --- /dev/null +++ b/siu/l2tp/l2tpd_logging.c @@ -0,0 +1,26 @@ + +#include +#include +#include + + +#include "l2tpd_logging.h" + +/* default categories */ +static struct log_info_cat l2tpd_categories[] = { + [DL2TP] = { + .name = "DL2TP", + .description = "L2TP logging messages", + .enabled = 1, .loglevel = LOGL_DEBUG, + }, +}; + +static const struct log_info l2tpd_log_info = { + .cat = l2tpd_categories, + .num_cat = ARRAY_SIZE(l2tpd_categories), +}; + +void l2tpd_log_init() +{ + osmo_init_logging(&l2tpd_log_info); +} diff --git a/siu/l2tp/l2tpd_logging.h b/siu/l2tp/l2tpd_logging.h new file mode 100644 index 0000000..f7f7899 --- /dev/null +++ b/siu/l2tp/l2tpd_logging.h @@ -0,0 +1,9 @@ +#pragma once + + +enum { + DL2TP, + Debug_LastEntry, +}; + +void l2tpd_log_init(); diff --git a/siu/l2tp/l2tpd_packet.c b/siu/l2tp/l2tpd_packet.c index f086279..31605f7 100644 --- a/siu/l2tp/l2tpd_packet.c +++ b/siu/l2tp/l2tpd_packet.c @@ -19,6 +19,7 @@ #include "l2tpd_data.h" #include "l2tpd_fsm.h" #include "l2tpd_lapd.h" +#include "l2tpd_logging.h" #include "crc32.h" /***********************************************************************