From 0bf7ae0a01717391171643718c3069c86447c9b9 Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Sun, 21 Jun 2020 22:33:28 +0200 Subject: [PATCH] Minor code claanup --- include/n2n.h | 1 + include/n2n_define.h | 3 ++- src/edge_utils.c | 4 ++++ tools/Makefile.in | 2 +- tools/benchmark.c | 53 ++++++++++++++++++-------------------------- 5 files changed, 29 insertions(+), 34 deletions(-) diff --git a/include/n2n.h b/include/n2n.h index 6545143..f38b09d 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -129,6 +129,7 @@ typedef struct ether_hdr ether_hdr_t; #include #include #include +#include #include #include #include diff --git a/include/n2n_define.h b/include/n2n_define.h index f56297a..21b31ff 100644 --- a/include/n2n_define.h +++ b/include/n2n_define.h @@ -43,10 +43,11 @@ #define IP4_MIN_SIZE 20 #define UDP_SIZE 8 +#if 0 /* heap allocation for compression as per lzo example doc */ #define HEAP_ALLOC(var,size) lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ] static HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS); - +#endif /* N2N compression indicators. */ /* Compression is disabled by default for outgoing packets if no cli diff --git a/src/edge_utils.c b/src/edge_utils.c index f4487c6..ecb616c 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -18,6 +18,10 @@ #include "n2n.h" +/* heap allocation for compression as per lzo example doc */ +#define HEAP_ALLOC(var,size) lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ] +static HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS); + /* ************************************** */ static const char * supernode_ip(const n2n_edge_t * eee); diff --git a/tools/Makefile.in b/tools/Makefile.in index 63176f0..631d5d9 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -40,7 +40,7 @@ n2n-decode: n2n_decode.c $(N2N_LIB) $(HEADERS) $(CC) $(CFLAGS) -c $< -o $@ clean: - rm -rf $(TOOLS) $(N2N_LIB) *.o *.dSYM *~ + rm -rf $(TOOLS) *.o *.dSYM *~ install: $(TOOLS) $(INSTALL_PROG) $(TOOLS) $(SBINDIR)/ diff --git a/tools/benchmark.c b/tools/benchmark.c index 748b0e7..671b639 100644 --- a/tools/benchmark.c +++ b/tools/benchmark.c @@ -1,5 +1,5 @@ /* - * (C) 2007-18 - ntop.org and contributors + * (C) 2007-20 - ntop.org and contributors * * 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 @@ -16,37 +16,26 @@ * */ -#include "n2n_wire.h" -#include "n2n_transforms.h" #include "n2n.h" -#ifdef __GNUC__ -#include -#endif -#include -#include -#include - #if defined(WIN32) && !defined(__GNUC__) -#include - static int gettimeofday(struct timeval *tp, void *tzp) { - time_t clock; - struct tm tm; - SYSTEMTIME wtm; - GetLocalTime(&wtm); - tm.tm_year = wtm.wYear - 1900; - tm.tm_mon = wtm.wMonth - 1; - tm.tm_mday = wtm.wDay; - tm.tm_hour = wtm.wHour; - tm.tm_min = wtm.wMinute; - tm.tm_sec = wtm.wSecond; - tm.tm_isdst = -1; - clock = mktime(&tm); - tp->tv_sec = clock; - tp->tv_usec = wtm.wMilliseconds * 1000; - return (0); + time_t clock; + struct tm tm; + SYSTEMTIME wtm; + GetLocalTime(&wtm); + tm.tm_year = wtm.wYear - 1900; + tm.tm_mon = wtm.wMonth - 1; + tm.tm_mday = wtm.wDay; + tm.tm_hour = wtm.wHour; + tm.tm_min = wtm.wMinute; + tm.tm_sec = wtm.wSecond; + tm.tm_isdst = -1; + clock = mktime(&tm); + tp->tv_sec = clock; + tp->tv_usec = wtm.wMilliseconds * 1000; + return (0); } #endif @@ -75,7 +64,7 @@ static int perform_decryption = 0; static void usage() { fprintf(stderr, "Usage: benchmark [-d]\n" - " -d\t\tEnable decryption. Default: only encryption is performed\n"); + " -d\t\tEnable decryption. Default: only encryption is performed\n"); exit(1); } @@ -162,7 +151,7 @@ static void run_transop_benchmark(const char *op_name, n2n_trans_op_t *op_fn, n2 size_t num_packets = 0; printf("Run %s[%s] for %us (%u bytes): ", perform_decryption ? "enc/dec" : "enc", - op_name, target_sec, (unsigned int)sizeof(PKT_CONTENT)); + op_name, target_sec, (unsigned int)sizeof(PKT_CONTENT)); fflush(stdout); memset(mac_buf, 0, sizeof(mac_buf)); @@ -172,8 +161,8 @@ static void run_transop_benchmark(const char *op_name, n2n_trans_op_t *op_fn, n2 nw = do_encode_packet( pktbuf, N2N_PKT_BUF_SIZE, conf->community_name); nw += op_fn->fwd(op_fn, - pktbuf+nw, N2N_PKT_BUF_SIZE-nw, - PKT_CONTENT, sizeof(PKT_CONTENT), mac_buf); + pktbuf+nw, N2N_PKT_BUF_SIZE-nw, + PKT_CONTENT, sizeof(PKT_CONTENT), mac_buf); idx=0; rem=nw; @@ -198,7 +187,7 @@ static void run_transop_benchmark(const char *op_name, n2n_trans_op_t *op_fn, n2 float mpps = num_packets / (tdiff / 1e6) / 1e6; printf("\t%12u packets\t%8.1f Kpps\t%8.1f MB/s\n", - (unsigned int)num_packets, mpps * 1e3, mpps * sizeof(PKT_CONTENT)); + (unsigned int)num_packets, mpps * 1e3, mpps * sizeof(PKT_CONTENT)); } static ssize_t do_encode_packet( uint8_t * pktbuf, size_t bufsize, const n2n_community_t c )