Skip to content

Commit

Permalink
Move logging into its own header
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishcoleman committed Oct 31, 2023
1 parent fd01a6c commit ea573d6
Show file tree
Hide file tree
Showing 34 changed files with 127 additions and 43 deletions.
2 changes: 2 additions & 0 deletions apps/edge.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -21,6 +22,7 @@
#include <ctype.h> // for isspace
#include <errno.h> // for errno
#include <getopt.h> // for required_argument, no_argument
#include <n3n/logging.h> // for traceEvent
#include <signal.h> // for signal, SIG_IGN, SIGPIPE, SIGCHLD
#include <stdbool.h>
#include <stdint.h> // for uint8_t, uint16_t
Expand Down
4 changes: 3 additions & 1 deletion apps/supernode.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -21,6 +22,7 @@
#include <ctype.h> // for isspace
#include <errno.h> // for errno
#include <getopt.h> // for required_argument, getopt_long, no_arg...
#include <n3n/logging.h> // for traceEvent
#include <signal.h> // for signal, SIGHUP, SIGINT, SIGPIPE, SIGTERM
#include <stdbool.h>
#include <stdint.h> // for uint8_t, uint32_t
Expand All @@ -30,7 +32,7 @@
#include <sys/types.h> // for time_t, u_char, u_int
#include <time.h> // for time
#include <unistd.h> // for _exit, daemon, getgid, getuid, setgid
#include "n2n.h" // for n2n_sn_t, sn_community, traceEvent
#include "n2n.h" // for n2n_sn_t, sn_community
#include "pearson.h" // for pearson_hash_64
#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_ADD_STR

Expand Down
19 changes: 0 additions & 19 deletions include/n2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@



/* ************************************** */

#ifndef TRACE_ERROR
#define TRACE_ERROR 0
#define TRACE_WARNING 1
#define TRACE_NORMAL 2
#define TRACE_INFO 3
#define TRACE_DEBUG 4
#endif

/* ************************************** */

/* Transop Init Functions */
Expand All @@ -117,15 +107,6 @@ int n2n_transop_lzo_init (const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
int n2n_transop_zstd_init (const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
#endif

/* Log */
void setTraceLevel (int level);
void setUseSyslog (int use_syslog);
void setTraceFile (FILE *f);
int getTraceLevel ();
void closeTraceFile ();
void _traceEvent (int eventTraceLevel, char* file, int line, char * format, ...);
#define traceEvent(level, format, ...) _traceEvent(level, __FILE__, __LINE__, format, ## __VA_ARGS__)

/* Tuntap API */
int tuntap_open (struct tuntap_dev *device, char *dev, const char *address_mode, char *device_ip,
char *device_mask, const char * device_mac, int mtu, int metric);
Expand Down
28 changes: 28 additions & 0 deletions include/n3n/logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* Public API for logging
*/

#ifndef _N2N_LOGGING_H_
#define _N2N_LOGGING_H_

#include <stdio.h> // for FILE

#define TRACE_ERROR 0
#define TRACE_WARNING 1
#define TRACE_NORMAL 2
#define TRACE_INFO 3
#define TRACE_DEBUG 4

void setTraceLevel (int level);
void setUseSyslog (int use_syslog);
void setTraceFile (FILE *f);
int getTraceLevel ();
void closeTraceFile ();
void _traceEvent (int eventTraceLevel, char* file, int line, char * format, ...);
#define traceEvent(level, format, ...) _traceEvent(level, __FILE__, __LINE__, format, ## __VA_ARGS__)

#endif
4 changes: 3 additions & 1 deletion src/aes.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -18,11 +20,11 @@

#include "config.h"

#include <n3n/logging.h> // for traceEvent
#include <stdint.h> // for uint32_t, uint8_t
#include <stdlib.h> // for calloc, free
#include <string.h> // for memcpy, size_t
#include "aes.h" // for AES_BLOCK_SIZE, aes_context_t, AES128_KEY_BYTES
#include "n2n.h" // for TRACE_ERROR, traceEvent
#include "portable_endian.h" // for be32toh, htobe32


Expand Down
3 changes: 3 additions & 0 deletions src/auth.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -18,6 +20,7 @@


#include "auth.h"
#include <n3n/logging.h> // for traceEvent
#include <stdlib.h> // for calloc, free
#include <string.h> // for strlen, size_t
#include "curve25519.h" // for curve25519
Expand Down
4 changes: 3 additions & 1 deletion src/cc20.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,11 +19,11 @@
*/


#include <n3n/logging.h> // for traceEvent
#include <stdlib.h> // for calloc, free, size_t
#include <string.h> // for memcpy
#include "cc20.h"
#include "config.h" // HAVE_LIBCRYPTO
#include "n2n.h" // for TRACE_ERROR, traceEvent
#include "portable_endian.h" // for htole32


Expand Down
5 changes: 3 additions & 2 deletions src/edge_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*
*/

#include "n2n.h" // for n2n_edge_t, peer_info, getTraceLevel, N2N_...
#include "n2n.h" // for n2n_edge_t, N2N_...
// FIXME: if this headers is sorted alphabetically, the test_integration_edge
// fails with what looks like a struct rearrangement involving eee->stats

#include <errno.h> // for errno
#include <n3n/logging.h> // for traceEvent
#include <stdbool.h>
#include <stdint.h> // for uint32_t
#include <stdio.h> // for snprintf, size_t, NULL
Expand All @@ -32,7 +33,7 @@
#include "config.h" // for PACKAGE_VERSION
#include "management.h" // for mgmt_req_t, send_reply, send_json_1str
#include "n2n_define.h" // for N2N_PKT_BUF_SIZE, N2N_EVENT_DEBUG, N2N_EVE...
#include "n2n_typedefs.h" // for n2n_edge_t, peer_info, n2n_edge_conf_t
#include "n2n_typedefs.h" // for n2n_edge_t, n2n_edge_conf_t
#include "peer_info.h" // for peer_info, peer_info_t
#include "sn_selection.h" // for sn_selection_criterion_str, selection_crit...
#include "strbuf.h" // for strbuf_t, STRBUF_INIT
Expand Down
4 changes: 3 additions & 1 deletion src/edge_utils.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -20,6 +21,7 @@

#include <errno.h> // for errno, EAFNOSUPPORT, EINPROGRESS
#include <fcntl.h> // for fcntl, F_SETFL, O_NONBLOCK
#include <n3n/logging.h> // for traceEvent
#include <stdbool.h>
#include <stdint.h> // for uint8_t, uint16_t, uint32_t, uin...
#include <stdio.h> // for snprintf, sprintf
Expand All @@ -32,7 +34,7 @@
#include "auth.h" // for generate_private_key
#include "portable_endian.h" // for be16toh, htobe16
#include "header_encryption.h" // for packet_header_encrypt, packet_he...
#include "n2n.h" // for n2n_edge_t, peer_info, n2n_edge_...
#include "n2n.h" // for n2n_edge_t, n2n_edge_...
#include "n2n_wire.h" // for encode_mac, fill_sockaddr, decod...
#include "network_traffic_filter.h" // for create_network_traffic_filter
#include "pearson.h" // for pearson_hash_128, pearson_hash_64
Expand Down
5 changes: 4 additions & 1 deletion src/header_encryption.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,11 +19,12 @@
*/


#include <n3n/logging.h> // for traceEvent
#include <stdint.h> // for uint32_t, uint8_t, uint64_t, uint16_t
#include <stdlib.h> // for calloc
#include <string.h> // for memcpy
#include "header_encryption.h" // for packet_header_change_dynamic_key, pac...
#include "n2n.h" // for he_context_t, N2N_COMMUNITY_SIZE, TRA...
#include "n2n.h" // for he_context_t, N2N_COMMUNITY_SIZE...
#include "n2n_define.h" // for N2N_COMMUNITY_SIZE
#include "n2n_typedefs.h" // for he_context_t, N2N_AUTH_CHALLENGE_SIZE
#include "pearson.h" // for pearson_hash_128, pearson_hash_64
Expand Down
2 changes: 1 addition & 1 deletion src/management.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
*/


#include <n3n/logging.h> // for traceEvent
#include <pearson.h> // for pearson_hash_64
#include <stdbool.h>
#include <stdio.h> // for snprintf, NULL, size_t
#include <stdlib.h> // for strtoul
#include <string.h> // for strtok, strlen, strncpy
#include "management.h"
#include "n2n.h" // for TRACE_DEBUG, traceEvent

#ifdef _WIN32
#include "win32/defs.h"
Expand Down
6 changes: 4 additions & 2 deletions src/n2n.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,6 +20,7 @@


#include <errno.h> // for errno
#include <n3n/logging.h> // for traceEvent
#include <stdarg.h> // for va_end, va_list, va_start
#include <stdbool.h>
#include <stdlib.h> // for free, atoi, calloc, strtol
Expand Down Expand Up @@ -615,8 +617,8 @@ void print_n2n_version () {

printf("Welcome to n3n v.%s\n"
"Built on %s\n"
"Copyright (C) 2023 Hamish Coleman\n",
"Copyright 2007-2022 - ntop.org and contributors\n\n",
"Copyright 2007-2022 - ntop.org and contributors\n"
"Copyright (C) 2023 Hamish Coleman\n\n",
PACKAGE_VERSION, PACKAGE_BUILDDATE);
}

Expand Down
3 changes: 3 additions & 0 deletions src/network_traffic_filter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,6 +19,7 @@
*/


#include <n3n/logging.h> // for traceEvent
#include <stdint.h> // for uint8_t, uint16_t, uint32_t
#include <stdio.h> // for sprintf
#include <stdlib.h> // for free, malloc, atoi
Expand Down
2 changes: 2 additions & 0 deletions src/peer_info.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/**
* (C) 2007-23 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
*/

#include <n2n.h> // for time_stamp
#include <n2n_define.h> // for TIME_STAMP_FRAME
#include <n3n/logging.h> // for traceEvent
#include <stdbool.h>
#include "peer_info.h"

Expand Down
4 changes: 3 additions & 1 deletion src/random_numbers.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,11 +19,11 @@
*/


#include <n3n/logging.h> // for traceEvent
#include <errno.h> // for errno, EAGAIN
#include <stddef.h> // for NULL, size_t
#include <time.h> // for clock, time
#include <unistd.h> // for syscall
#include "n2n.h" // for TRACE_ERROR, traceEvent
#include "random_numbers.h"


Expand Down
3 changes: 2 additions & 1 deletion src/sn_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@


#include <errno.h> // for errno
#include <n3n/logging.h> // for traceEvent
#include <stdbool.h>
#include <stdint.h> // for uint8_t, uint32_t
#include <stdio.h> // for snprintf, size_t, sprintf, NULL
#include <string.h> // for memcmp, memcpy, strerror, strncpy
#include <sys/types.h> // for ssize_t, time_t
#include "management.h" // for mgmt_req_t, send_reply, mgmt_handler_t, mgmt...
#include "n2n.h" // for n2n_sn_t, sn_community, peer_info, N2N_SN_PK...
#include "n2n.h" // for n2n_sn_t, sn_community, N2N_SN_PK...
#include "n2n_define.h" // for N2N_SN_PKTBUF_SIZE, UNPURGEABLE
#include "n2n_typedefs.h" // for n2n_sn_t, sn_community, peer_info, sn_stats_t
#include "peer_info.h" // for peer_info, peer_info_t
Expand Down
3 changes: 3 additions & 0 deletions src/sn_selection.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,6 +19,7 @@
*/


#include <n3n/logging.h> // for traceEvent
#include <stdint.h> // for UINT64_MAX, uint32_t, int64_t, uint64_t
#include <stdio.h> // for snprintf, NULL
#include <string.h> // for memcpy, memset
Expand Down
4 changes: 3 additions & 1 deletion src/sn_utils.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* (C) 2007-22 - ntop.org and contributors
* Copyright (C) 2023 Hamish Coleman
* SPDX-License-Identifier: GPL-3.0-only
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,6 +20,7 @@


#include <errno.h> // for errno, EAFNOSUPPORT
#include <n3n/logging.h> // for traceEvent
#include <stdbool.h>
#include <stdint.h> // for uint8_t, uint32_t, uint16_t, uint64_t
#include <stdio.h> // for sscanf, snprintf, fclose, fgets, fopen
Expand All @@ -31,7 +33,7 @@
#include "auth.h" // for ascii_to_bin, calculate_dynamic_key
#include "config.h" // for PACKAGE_VERSION
#include "header_encryption.h" // for packet_header_encrypt, packet_header_...
#include "n2n.h" // for sn_community, n2n_sn_t, peer_info
#include "n2n.h" // for sn_community, n2n_sn_t
#include "n2n_regex.h" // for re_matchp, re_compile
#include "n2n_wire.h" // for encode_buf, encode_PEER_INFO, encode_...
#include "pearson.h" // for pearson_hash_128, pearson_hash_32
Expand Down
Loading

0 comments on commit ea573d6

Please sign in to comment.