Browse Source

Basic C Code lint checker and shell checker (#859)

* Factor build packages out into a more maintainable list

* Create a location for scripts to live

* Provide a make target to return the source dir as close as reasonable to the original distributed state

* Add a code lint step, checking the coding style

* Change test harness as recommended by shellcheck

* Ensure we actually have the linter tool installed

* Use the correct directory for cmake to run the tests

* Adjust for the older uncrustify in the current github ubuntu-latest

* Make one file pass the linter

* Integrate the lint with the existing test workflow

* Add files with minimal changes needed to the linter

* Add more files with minimal changes needed to the linter

* Dont build binaries if we fail the lint test

* Update the phony targets with the lint steps

* Ensure the flake8 package is installed in the new lint workflow job

* Use the makefile to drive the packages needed to install for linting

* No need to add dependancies on lint, just rely on the workflow status to show failure

* Update the scripts dir README to reflect current assumptions

* Rename and briefly document the indent.sh script

* Fix the ignore to ignore the right Makefile

* Rename the test_harness script to make it clear it is a shell script

* Provide a master lint make target and add a shell script lint tool

* Elminate stray tabs

* Drop include/auth.h from linter - there are inconsistant results with function definitions when using the current uncrustify rules
pull/864/head
Hamish Coleman 3 years ago
committed by GitHub
parent
commit
80b33cd1a9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 39
      .github/workflows/tests.yml
  2. 7
      .gitignore
  3. 2
      CMakeLists.txt
  4. 59
      Makefile.in
  5. 8
      doc/Scripts.md
  6. 2
      include/auth.h
  7. 2
      include/edge_utils_win32.h
  8. 6
      include/n2n_define.h
  9. 2
      include/pearson.h
  10. 9
      scripts/README.md
  11. 60
      scripts/indent.sh
  12. 8
      scripts/test_harness.sh
  13. 19
      src/edge_utils_win32.c
  14. 2
      src/example_edge_embed_quick_edge_init.c
  15. 2
      src/header_encryption.c
  16. 2
      src/sn_selection.c
  17. 8
      src/wire.c
  18. 31
      tools/tests-compress.c
  19. 4
      tools/tests-elliptic.c
  20. 11
      tools/tests-hashing.c
  21. 17
      tools/tests-transform.c
  22. 38
      tools/tests-wire.c
  23. 34
      uncrustify.cfg

39
.github/workflows/tests.yml

@ -12,15 +12,31 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Install essential
run: |
sudo apt-get install flake8
- name: Run minimal test set - name: Run minimal test set
run: | run: |
./autogen.sh ./autogen.sh
./configure ./configure
make test make test
make lint.python
lint:
name: Code syntax
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Make the makefiles
run: |
./autogen.sh
./configure
- name: Install essential
run: |
make build-dep
- name: Run the lint tools
run: |
make lint
test_linux: test_linux:
needs: smoketest needs: smoketest
@ -216,8 +232,9 @@ jobs:
uses: codecov/codecov-action@v2 uses: codecov/codecov-action@v2
package_dpkg: package_dpkg:
needs: test_linux
name: Package for Debian/Ubuntu name: Package for Debian/Ubuntu
needs:
- test_linux
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: true fail-fast: true
@ -260,8 +277,9 @@ jobs:
path: packages/debian/*.deb path: packages/debian/*.deb
package_rpm: package_rpm:
needs: test_linux
name: Package for Redhat/RPM name: Package for Redhat/RPM
needs:
- test_linux
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -296,8 +314,9 @@ jobs:
path: rpmbuild/RPMS/x86_64/*.rpm path: rpmbuild/RPMS/x86_64/*.rpm
binaries_windows: binaries_windows:
needs: test_windows
name: Binaries for Windows (x86_64-pc-mingw64) name: Binaries for Windows (x86_64-pc-mingw64)
needs:
- test_windows
runs-on: windows-latest runs-on: windows-latest
steps: steps:
@ -321,8 +340,9 @@ jobs:
path: binaries path: binaries
binaries_macos: binaries_macos:
needs: test_macos
name: Binaries for MacOS (x86_64-apple-darwin) name: Binaries for MacOS (x86_64-apple-darwin)
needs:
- test_macos
runs-on: macos-latest runs-on: macos-latest
steps: steps:
@ -351,8 +371,9 @@ jobs:
path: binaries path: binaries
binaries_linux_crosscompile: binaries_linux_crosscompile:
needs: test_linux
name: Binaries for linux name: Binaries for linux
needs:
- test_linux
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: true fail-fast: true

7
.gitignore

@ -4,7 +4,7 @@
configure configure
configure.ac configure.ac
config.* config.*
./Makefile /Makefile
tools/Makefile tools/Makefile
autom4te.cache autom4te.cache
edge edge
@ -45,3 +45,8 @@ tests/*.out
*.gcda *.gcda
*.gcov *.gcov
coverage/ coverage/
# Files generated while running linting
*.indent
*.unc-backup.md5~
*.unc-backup~

2
CMakeLists.txt

@ -271,6 +271,6 @@ install(FILES ${PROJECT_BINARY_DIR}/doc/n2n.7.gz
# TODO: # TODO:
# - Add the right dependancy so that the tests binaries get built first # - Add the right dependancy so that the tests binaries get built first
enable_testing() enable_testing()
add_test(tests ${PROJECT_SOURCE_DIR}/tools/test_harness ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/tests) add_test(tests ${PROJECT_SOURCE_DIR}/scripts/test_harness.sh ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/tests)
endif(DEFINED UNIX) endif(DEFINED UNIX)

59
Makefile.in

@ -83,7 +83,28 @@ N2N_LIB=libn2n.a
N2N_OBJS=$(patsubst src/%.c, src/%.o, $(wildcard src/*.c)) N2N_OBJS=$(patsubst src/%.c, src/%.o, $(wildcard src/*.c))
N2N_DEPS=$(wildcard include/*.h) $(wildcard src/*.c) Makefile N2N_DEPS=$(wildcard include/*.h) $(wildcard src/*.c) Makefile
# As source files pass the linter, they can be added here (If all the source
# is passing the linter tests, this can be refactored)
LINT_CCODE=\
include/edge_utils_win32.h \
include/n2n_define.h \
include/pearson.h \
include/speck.h \
src/edge_utils_win32.c \
src/example_edge_embed_quick_edge_init.c \
src/header_encryption.c \
src/sn_selection.c \
src/transform_cc20.c \
src/tuntap_linux.c \
src/wire.c \
tools/tests-compress.c \
tools/tests-elliptic.c \
tools/tests-hashing.c \
tools/tests-transform.c \
tools/tests-wire.c \
export LDLIBS export LDLIBS
LDLIBS+=-ln2n LDLIBS+=-ln2n
LDLIBS+=@N2N_LIBS@ LDLIBS+=@N2N_LIBS@
@ -108,12 +129,26 @@ APPS+=example_sn_embed
DOCS=edge.8.gz supernode.1.gz n2n.7.gz DOCS=edge.8.gz supernode.1.gz n2n.7.gz
# This is the superset of all packages that might be needed during the build.
# Mostly of use in automated build systems.
BUILD_DEP:=\
autoconf \
build-essential \
flake8 \
gcovr \
libcap-dev \
libzstd-dev \
shellcheck \
uncrustify \
SUBDIRS+=tools SUBDIRS+=tools
COVERAGEDIR?=coverage COVERAGEDIR?=coverage
.PHONY: $(SUBDIRS) .PHONY: $(SUBDIRS)
.PHONY: steps build push all clean install test cover gcov build-dep .PHONY: steps build push all clean distclean install test cover gcov build-dep
.PHONY: lint lint.python lint.ccode lint.shell
all: $(APPS) $(DOCS) $(SUBDIRS) all: $(APPS) $(DOCS) $(SUBDIRS)
tools: $(N2N_LIB) tools: $(N2N_LIB)
@ -147,11 +182,19 @@ $(N2N_LIB): $(N2N_OBJS)
win32/n2n_win32.a: win32 win32/n2n_win32.a: win32
test: tools test: tools
tools/test_harness scripts/test_harness.sh
lint: lint.python lint.ccode lint.shell
lint.python: lint.python:
flake8 scripts/n2nctl scripts/n2nhttpd flake8 scripts/n2nctl scripts/n2nhttpd
lint.ccode:
scripts/indent.sh $(LINT_CCODE)
lint.shell:
shellcheck scripts/*.sh
# To generate coverage information, run configure with # To generate coverage information, run configure with
# CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="--coverage" # CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="--coverage"
# and run the desired tests. Ensure that package gcovr is installed # and run the desired tests. Ensure that package gcovr is installed
@ -168,11 +211,10 @@ gcov:
gcov $(N2N_OBJS) gcov $(N2N_OBJS)
$(MAKE) -C tools gcov $(MAKE) -C tools gcov
# This is the superset of all packages that might be needed. # This is a convinent target to use during development or from a CI/CD system
# It is a convinent target to use during development or from a CI/CD system
build-dep: build-dep:
ifeq ($(CONFIG_TARGET),generic) ifeq ($(CONFIG_TARGET),generic)
sudo apt install build-essential autoconf libcap-dev libzstd-dev gcovr flake8 sudo apt install $(BUILD_DEP)
else ifeq ($(CONFIG_TARGET),darwin) else ifeq ($(CONFIG_TARGET),darwin)
brew install automake gcovr brew install automake gcovr
else else
@ -184,6 +226,13 @@ clean:
rm -f tests/*.out src/*.gcno src/*.gcda rm -f tests/*.out src/*.gcno src/*.gcda
for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean; done for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean; done
distclean:
rm -f tests/*.out src/*.gcno src/*.gcda src/*.indent src/*.unc-backup*
rm -rf autom4te.cache/
rm -f config.log config.status configure configure.ac Makefile tools/Makefile include/config.h include/config.h.in
rm -f doc/edge.8.gz doc/n2n.7.gz doc/supernode.1.gz
rm -f $(addprefix src/,$(APPS))
install: edge supernode edge.8.gz supernode.1.gz n2n.7.gz install: edge supernode edge.8.gz supernode.1.gz n2n.7.gz
echo "MANDIR=$(MANDIR)" echo "MANDIR=$(MANDIR)"
$(MKDIR) $(SBINDIR) $(MAN1DIR) $(MAN7DIR) $(MAN8DIR) $(MKDIR) $(SBINDIR) $(MAN1DIR) $(MAN7DIR) $(MAN8DIR)

8
doc/Scripts.md

@ -13,7 +13,13 @@ This shell script is used during development to help build on Windows
systems. An example of how to use it is shown in systems. An example of how to use it is shown in
the [Building document](Building.md) the [Building document](Building.md)
## `tools/test_harness` ## `scripts/indent.sh`
This shell script is a wrapper for the `uncrustify` C code style checker
which checks or applies a set of rules to the code. It is used during
the automated lint checks.
## `scripts/test_harness.sh`
This shell script is used to run automated tests during development. This shell script is used to run automated tests during development.

2
include/auth.h

@ -28,7 +28,7 @@ int bin_to_ascii (char *out, uint8_t *in, size_t in_len);
int ascii_to_bin (uint8_t *out, char *in); int ascii_to_bin (uint8_t *out, char *in);
int generate_private_key(n2n_private_public_key_t key, char *in); int generate_private_key (n2n_private_public_key_t key, char *in);
int generate_public_key (n2n_private_public_key_t pub, n2n_private_public_key_t prv); int generate_public_key (n2n_private_public_key_t pub, n2n_private_public_key_t prv);

2
include/edge_utils_win32.h

@ -43,7 +43,7 @@ struct tunread_arg {
}; };
extern HANDLE startTunReadThread (struct tunread_arg *arg); extern HANDLE startTunReadThread (struct tunread_arg *arg);
int get_best_interface_ip(n2n_edge_t * eee, dec_ip_str_t ip_addr); int get_best_interface_ip (n2n_edge_t * eee, dec_ip_str_t ip_addr);
#endif /* WIN32 */ #endif /* WIN32 */

6
include/n2n_define.h

@ -92,14 +92,14 @@
/* Federation name and indicators */ /* Federation name and indicators */
#define FEDERATION_NAME "*Federation" #define FEDERATION_NAME "*Federation"
enum federation{IS_NO_FEDERATION = 0,IS_FEDERATION = 1}; enum federation {IS_NO_FEDERATION = 0,IS_FEDERATION = 1};
/* (un)purgeable community indicator (supernode) */ /* (un)purgeable community indicator (supernode) */
#define COMMUNITY_UNPURGEABLE 0 #define COMMUNITY_UNPURGEABLE 0
#define COMMUNITY_PURGEABLE 1 #define COMMUNITY_PURGEABLE 1
/* (un)purgeable supernode indicator */ /* (un)purgeable supernode indicator */
enum sn_purge{SN_PURGEABLE = 0, SN_UNPURGEABLE = 1}; enum sn_purge {SN_PURGEABLE = 0, SN_UNPURGEABLE = 1};
/* Header encryption indicators */ /* Header encryption indicators */
#define HEADER_ENCRYPTION_UNKNOWN 0 #define HEADER_ENCRYPTION_UNKNOWN 0
@ -133,7 +133,7 @@ enum n2n_mgmt_type {
/* which the socket explicitly is closed before reopening */ /* which the socket explicitly is closed before reopening */
/* flag used in add_sn_to_list_by_mac_or_sock */ /* flag used in add_sn_to_list_by_mac_or_sock */
enum skip_add{SN_ADD = 0, SN_ADD_SKIP = 1, SN_ADD_ADDED = 2}; enum skip_add {SN_ADD = 0, SN_ADD_SKIP = 1, SN_ADD_ADDED = 2};
#define N2N_NETMASK_STR_SIZE 16 /* dotted decimal 12 numbers + 3 dots */ #define N2N_NETMASK_STR_SIZE 16 /* dotted decimal 12 numbers + 3 dots */
#define N2N_MACNAMSIZ 18 /* AA:BB:CC:DD:EE:FF + NULL*/ #define N2N_MACNAMSIZ 18 /* AA:BB:CC:DD:EE:FF + NULL*/

2
include/pearson.h

@ -33,4 +33,4 @@ uint32_t pearson_hash_32 (const uint8_t *in, size_t len);
uint16_t pearson_hash_16 (const uint8_t *in, size_t len); uint16_t pearson_hash_16 (const uint8_t *in, size_t len);
void pearson_hash_init(); void pearson_hash_init ();

9
scripts/README.md

@ -0,0 +1,9 @@
This directory contains executables that are not compiled. Some of these may
end up installed for use by end users, but many of them are for use during
development, builds and tests.
Nothing in this directory should need compiling to use and they should be
written such that they do not need configuring (e.g: they might probe several
directories for their requirements)
See the [Scripts Documentation](../docs/Scripts.md) for further details

60
scripts/indent.sh

@ -0,0 +1,60 @@
#!/bin/sh
#
# Given one or more input source files, run a re-indenter on them.
help() {
echo "Usage: scripts/indent [-i] [file...]"
echo " -i modify file in place with reindent results"
echo ""
echo "By default, will output a diff and exitcode if changed are needed"
echo "If modifying files, no exit code or diff is output"
exit 1
}
[ -z "$1" ] && help
[ "$1" = "-h" ] && help
INPLACE=0
if [ "$1" = "-i" ]; then
shift
INPLACE=1
fi
## indentOneClang() {
## rm -f "$1.indent"
## clang-format "$1" >"$1.indent"
## if [ $? -ne 0 ]; then
## echo "Error while formatting \"$1\""
## RESULT=1
## return
## fi
## diff -u "$1" "$1.indent"
## if [ $? -ne 0 ]; then
## RESULT=1
## fi
## }
indentOne() {
IFILE="$1"
if [ "$INPLACE" -eq 0 ]; then
OFILE="$1.indent"
rm -f "$OFILE"
else
OFILE="$1"
fi
if ! uncrustify -c uncrustify.cfg -f "$IFILE" -o "$OFILE"; then
echo "Error while formatting \"$1\""
RESULT=1
return
fi
if ! diff -u "$IFILE" "$OFILE"; then
RESULT=1
fi
}
RESULT=0
while [ -n "$1" ]; do
indentOne "$1"
shift
done
exit $RESULT

8
tools/test_harness → scripts/test_harness.sh

@ -20,11 +20,11 @@ TESTDATA=tests
# Confirm we have all the tools and data # Confirm we have all the tools and data
for i in $TESTS; do for i in $TESTS; do
if [ ! -e $TOOLSDIR/$i ]; then if [ ! -e "$TOOLSDIR/$i" ]; then
echo "Could not find test $TOOLSDIR/$i" echo "Could not find test $TOOLSDIR/$i"
exit 1 exit 1
fi fi
if [ ! -e $TESTDATA/$i.expected ]; then if [ ! -e "$TESTDATA/$i.expected" ]; then
echo "Could not find testdata $TESTDATA/$i.expected" echo "Could not find testdata $TESTDATA/$i.expected"
exit 1 exit 1
fi fi
@ -34,6 +34,6 @@ done
set -e set -e
for i in $TESTS; do for i in $TESTS; do
echo "$TOOLSDIR/$i >$TESTDATA/$i.out" echo "$TOOLSDIR/$i >$TESTDATA/$i.out"
$TOOLSDIR/$i >$TESTDATA/$i.out "$TOOLSDIR/$i" >"$TESTDATA/$i.out"
cmp $TESTDATA/$i.expected $TESTDATA/$i.out cmp "$TESTDATA/$i.expected" "$TESTDATA/$i.out"
done done

19
src/edge_utils_win32.c

@ -51,7 +51,7 @@ HANDLE startTunReadThread (struct tunread_arg *arg) {
int get_best_interface_ip(n2n_edge_t * eee, dec_ip_str_t ip_addr){ int get_best_interface_ip (n2n_edge_t * eee, dec_ip_str_t ip_addr){
DWORD interface_index = -1; DWORD interface_index = -1;
DWORD dwRetVal = 0; DWORD dwRetVal = 0;
PIP_ADAPTER_INFO pAdapterInfo = NULL, pAdapter = NULL; PIP_ADAPTER_INFO pAdapterInfo = NULL, pAdapter = NULL;
@ -62,15 +62,15 @@ int get_best_interface_ip(n2n_edge_t * eee, dec_ip_str_t ip_addr){
if(dwRetVal != NO_ERROR) return -1; if(dwRetVal != NO_ERROR) return -1;
pAdapterInfo = (PIP_ADAPTER_INFO)malloc(ulOutBufLen); pAdapterInfo = (PIP_ADAPTER_INFO)malloc(ulOutBufLen);
if (pAdapterInfo == NULL) { if(pAdapterInfo == NULL) {
traceEvent(TRACE_INFO, "Error allocating memory needed to call GetAdaptersInfo\n"); traceEvent(TRACE_INFO, "Error allocating memory needed to call GetAdaptersInfo\n");
return -1; return -1;
} }
dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen); dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
if(dwRetVal == ERROR_BUFFER_OVERFLOW){ if(dwRetVal == ERROR_BUFFER_OVERFLOW) {
pAdapterInfo = (PIP_ADAPTER_INFO)realloc(pAdapterInfo, ulOutBufLen); pAdapterInfo = (PIP_ADAPTER_INFO)realloc(pAdapterInfo, ulOutBufLen);
if (pAdapterInfo == NULL) { if(pAdapterInfo == NULL) {
traceEvent(TRACE_INFO, "Error allocating memory needed to call GetAdaptersInfo\n"); traceEvent(TRACE_INFO, "Error allocating memory needed to call GetAdaptersInfo\n");
return -1; return -1;
} }
@ -78,9 +78,9 @@ int get_best_interface_ip(n2n_edge_t * eee, dec_ip_str_t ip_addr){
dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen); dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
// hexdump((uint8_t*)pAdapterInfo, ulOutBufLen); // hexdump((uint8_t*)pAdapterInfo, ulOutBufLen);
if (dwRetVal == NO_ERROR) { if(dwRetVal == NO_ERROR) {
for(pAdapter = pAdapterInfo; pAdapter != NULL; pAdapter = pAdapter->Next){ for(pAdapter = pAdapterInfo; pAdapter != NULL; pAdapter = pAdapter->Next) {
if (pAdapter->Index != interface_index) continue; if(pAdapter->Index != interface_index) continue;
traceEvent(TRACE_DEBUG, "Adapter Index: %ld\n", pAdapter->Index); traceEvent(TRACE_DEBUG, "Adapter Index: %ld\n", pAdapter->Index);
traceEvent(TRACE_DEBUG, "Combo Index: %ld\n", pAdapter->ComboIndex); traceEvent(TRACE_DEBUG, "Combo Index: %ld\n", pAdapter->ComboIndex);
@ -96,11 +96,10 @@ int get_best_interface_ip(n2n_edge_t * eee, dec_ip_str_t ip_addr){
traceEvent(TRACE_DEBUG, "Gateway: %s\n", pAdapter->GatewayList.IpAddress.String); traceEvent(TRACE_DEBUG, "Gateway: %s\n", pAdapter->GatewayList.IpAddress.String);
strncpy(ip_addr, pAdapter->IpAddressList.IpAddress.String, sizeof(dec_ip_str_t)-1); strncpy(ip_addr, pAdapter->IpAddressList.IpAddress.String, sizeof(dec_ip_str_t)-1);
} }
} } else {
else {
traceEvent(TRACE_WARNING, "GetAdaptersInfo failed with error: %d\n", dwRetVal); traceEvent(TRACE_WARNING, "GetAdaptersInfo failed with error: %d\n", dwRetVal);
} }
if (pAdapterInfo != NULL){ if(pAdapterInfo != NULL) {
free(pAdapterInfo); free(pAdapterInfo);
pAdapterInfo = NULL; pAdapterInfo = NULL;
} }

2
src/example_edge_embed_quick_edge_init.c

@ -37,7 +37,7 @@ int main (int argc, char* argv[]) {
setTraceLevel(10); setTraceLevel(10);
/* Random seed */ /* Random seed */
n2n_srand (n2n_seed()); n2n_srand(n2n_seed());
/* /*
NOTE NOTE

2
src/header_encryption.c

@ -41,7 +41,7 @@ int packet_header_decrypt (uint8_t packet[], uint16_t packet_len,
//extract header length (lower 2 bytes) //extract header length (lower 2 bytes)
uint32_t header_len = test_magic - magic; uint32_t header_len = test_magic - magic;
if (header_len <= packet_len) { if(header_len <= packet_len) {
// decrypt the complete header // decrypt the complete header
speck_ctr(&packet[16], &packet[16], header_len - 16, packet, (speck_context_t*)ctx); speck_ctr(&packet[16], &packet[16], header_len - 16, packet, (speck_context_t*)ctx);

2
src/sn_selection.c

@ -175,7 +175,7 @@ extern char * sn_selection_criterion_str (selection_criterion_str_t out, peer_in
#endif #endif
/* this test is to make "-Wformat-truncation" less sad */ /* this test is to make "-Wformat-truncation" less sad */
if (chars > SN_SELECTION_CRITERION_BUF_SIZE) { if(chars > SN_SELECTION_CRITERION_BUF_SIZE) {
traceEvent(TRACE_INFO, "selection_criterion buffer overflow"); traceEvent(TRACE_INFO, "selection_criterion buffer overflow");
} }
} }

8
src/wire.c

@ -71,7 +71,7 @@ int decode_uint16 (uint16_t * out,
size_t * rem, size_t * rem,
size_t * idx) { size_t * idx) {
if (*rem < 2) { if(*rem < 2) {
return 0; return 0;
} }
@ -101,7 +101,7 @@ int decode_uint32 (uint32_t * out,
size_t * rem, size_t * rem,
size_t * idx) { size_t * idx) {
if (*rem < 4) { if(*rem < 4) {
return 0; return 0;
} }
@ -130,7 +130,7 @@ int decode_uint64 (uint64_t * out,
size_t * rem, size_t * rem,
size_t * idx) { size_t * idx) {
if (*rem < 8) { if(*rem < 8) {
return 0; return 0;
} }
@ -159,7 +159,7 @@ int decode_buf (uint8_t * out,
size_t * rem, size_t * rem,
size_t * idx) { size_t * idx) {
if (*rem < bufsize) { if(*rem < bufsize) {
return 0; return 0;
} }

31
tools/tests-compress.c

@ -44,9 +44,10 @@ uint8_t PKT_CONTENT[]={
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }; 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
};
static void init_compression_for_benchmark(void) { static void init_compression_for_benchmark (void) {
if(lzo_init() != LZO_E_OK) { if(lzo_init() != LZO_E_OK) {
traceEvent(TRACE_ERROR, "LZO compression init error"); traceEvent(TRACE_ERROR, "LZO compression init error");
@ -59,7 +60,7 @@ static void init_compression_for_benchmark(void) {
} }
static void deinit_compression_for_benchmark(void) { static void deinit_compression_for_benchmark (void) {
// lzo1x does not require de-initialization. if it were required, this would be a good place // lzo1x does not require de-initialization. if it were required, this would be a good place
@ -68,27 +69,27 @@ static void deinit_compression_for_benchmark(void) {
#endif #endif
} }
void test_lzo1x() { void test_lzo1x () {
char *test_name = "lzo1x"; char *test_name = "lzo1x";
uint8_t compression_buffer[N2N_PKT_BUF_SIZE]; // size allows enough of a reserve required for compression uint8_t compression_buffer[N2N_PKT_BUF_SIZE]; // size allows enough of a reserve required for compression
lzo_uint compression_len = sizeof(compression_buffer); lzo_uint compression_len = sizeof(compression_buffer);
if (lzo1x_1_compress(PKT_CONTENT, sizeof(PKT_CONTENT), compression_buffer, &compression_len, wrkmem) != LZO_E_OK) { if(lzo1x_1_compress(PKT_CONTENT, sizeof(PKT_CONTENT), compression_buffer, &compression_len, wrkmem) != LZO_E_OK) {
fprintf(stderr, "%s: compression error\n", test_name); fprintf(stderr, "%s: compression error\n", test_name);
exit(1); exit(1);
} }
assert(compression_len == 47); assert(compression_len == 47);
printf("%s: output size = 0x%"PRIx64"\n", test_name, compression_len); printf("%s: output size = 0x%" PRIx64 "\n", test_name, compression_len);
fhexdump(0, compression_buffer, compression_len, stdout); fhexdump(0, compression_buffer, compression_len, stdout);
uint8_t deflation_buffer[N2N_PKT_BUF_SIZE]; uint8_t deflation_buffer[N2N_PKT_BUF_SIZE];
lzo_uint deflated_len; lzo_uint deflated_len;
lzo1x_decompress (compression_buffer, compression_len, deflation_buffer, &deflated_len, NULL); lzo1x_decompress(compression_buffer, compression_len, deflation_buffer, &deflated_len, NULL);
assert(deflated_len == sizeof(PKT_CONTENT)); assert(deflated_len == sizeof(PKT_CONTENT));
if (memcmp(PKT_CONTENT, deflation_buffer, deflated_len)!=0) { if(memcmp(PKT_CONTENT, deflation_buffer, deflated_len)!=0) {
fprintf(stderr, "%s: round-trip buffer mismatch\n", test_name); fprintf(stderr, "%s: round-trip buffer mismatch\n", test_name);
exit(1); exit(1);
} }
@ -97,7 +98,7 @@ void test_lzo1x() {
printf("\n"); printf("\n");
} }
void test_zstd() { void test_zstd () {
char *test_name = "zstd"; char *test_name = "zstd";
#ifdef N2N_HAVE_ZSTD #ifdef N2N_HAVE_ZSTD
@ -105,7 +106,7 @@ void test_zstd() {
lzo_uint compression_len = sizeof(compression_buffer); lzo_uint compression_len = sizeof(compression_buffer);
compression_len = N2N_PKT_BUF_SIZE; compression_len = N2N_PKT_BUF_SIZE;
compression_len = ZSTD_compress(compression_buffer, compression_len, PKT_CONTENT, sizeof(PKT_CONTENT), ZSTD_COMPRESSION_LEVEL) ; compression_len = ZSTD_compress(compression_buffer, compression_len, PKT_CONTENT, sizeof(PKT_CONTENT), ZSTD_COMPRESSION_LEVEL);
if(ZSTD_isError(compression_len)) { if(ZSTD_isError(compression_len)) {
fprintf(stderr, "%s: compression error\n", test_name); fprintf(stderr, "%s: compression error\n", test_name);
exit(1); exit(1);
@ -113,12 +114,12 @@ void test_zstd() {
assert(compression_len == 33); assert(compression_len == 33);
printf("%s: output size = 0x%"PRIx64"\n", test_name, compression_len); printf("%s: output size = 0x%" PRIx64 "\n", test_name, compression_len);
fhexdump(0, compression_buffer, compression_len, stdout); fhexdump(0, compression_buffer, compression_len, stdout);
uint8_t deflation_buffer[N2N_PKT_BUF_SIZE]; uint8_t deflation_buffer[N2N_PKT_BUF_SIZE];
int64_t deflated_len = sizeof(deflation_buffer); int64_t deflated_len = sizeof(deflation_buffer);
deflated_len = (int32_t)ZSTD_decompress (deflation_buffer, deflated_len, compression_buffer, compression_len); deflated_len = (int32_t)ZSTD_decompress(deflation_buffer, deflated_len, compression_buffer, compression_len);
if(ZSTD_isError(deflated_len)) { if(ZSTD_isError(deflated_len)) {
fprintf(stderr, "%s: decompression error '%s'\n", fprintf(stderr, "%s: decompression error '%s'\n",
test_name, ZSTD_getErrorName(deflated_len)); test_name, ZSTD_getErrorName(deflated_len));
@ -126,7 +127,7 @@ void test_zstd() {
} }
assert(deflated_len == sizeof(PKT_CONTENT)); assert(deflated_len == sizeof(PKT_CONTENT));
if (memcmp(PKT_CONTENT, deflation_buffer, deflated_len)!=0) { if(memcmp(PKT_CONTENT, deflation_buffer, deflated_len)!=0) {
fprintf(stderr, "%s: round-trip buffer mismatch\n", test_name); fprintf(stderr, "%s: round-trip buffer mismatch\n", test_name);
exit(1); exit(1);
} }
@ -145,12 +146,12 @@ void test_zstd() {
} }
int main(int argc, char * argv[]) { int main (int argc, char * argv[]) {
/* Also for compression (init moved here for ciphers get run before in case of lzo init error) */ /* Also for compression (init moved here for ciphers get run before in case of lzo init error) */
init_compression_for_benchmark(); init_compression_for_benchmark();
printf("%s: input size = 0x%"PRIx64"\n", "original", sizeof(PKT_CONTENT)); printf("%s: input size = 0x%" PRIx64 "\n", "original", sizeof(PKT_CONTENT));
fhexdump(0, PKT_CONTENT, sizeof(PKT_CONTENT), stdout); fhexdump(0, PKT_CONTENT, sizeof(PKT_CONTENT), stdout);
printf("\n"); printf("\n");

4
tools/tests-elliptic.c

@ -19,7 +19,7 @@
#include "n2n.h" #include "n2n.h"
#include "hexdump.h" #include "hexdump.h"
void test_curve25519(unsigned char *pkt_input, unsigned char *key) { void test_curve25519 (unsigned char *pkt_input, unsigned char *key) {
char *test_name = "curve25519"; char *test_name = "curve25519";
unsigned char pkt_output[32]; unsigned char pkt_output[32];
@ -32,7 +32,7 @@ void test_curve25519(unsigned char *pkt_input, unsigned char *key) {
printf("\n"); printf("\n");
} }
int main(int argc, char * argv[]) { int main (int argc, char * argv[]) {
char *test_name = "environment"; char *test_name = "environment";
unsigned char key[32]; unsigned char key[32];

11
tools/tests-hashing.c

@ -38,24 +38,25 @@ uint8_t PKT_CONTENT[]={
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }; 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
};
void test_pearson(void *buf, unsigned int bufsize) { void test_pearson (void *buf, unsigned int bufsize) {
char *test_name = "pearson"; char *test_name = "pearson";
uint64_t hash = pearson_hash_64(buf, bufsize); uint64_t hash = pearson_hash_64(buf, bufsize);
printf("%s: output = 0x%"PRIx64"\n", test_name, hash); printf("%s: output = 0x%" PRIx64 "\n", test_name, hash);
fprintf(stderr, "%s: tested\n", test_name); fprintf(stderr, "%s: tested\n", test_name);
printf("\n"); printf("\n");
} }
int main(int argc, char * argv[]) { int main (int argc, char * argv[]) {
pearson_hash_init(); pearson_hash_init();
char *test_name = "environment"; char *test_name = "environment";
printf("%s: input size = 0x%"PRIx64"\n", test_name, sizeof(PKT_CONTENT)); printf("%s: input size = 0x%" PRIx64 "\n", test_name, sizeof(PKT_CONTENT));
fhexdump(0, PKT_CONTENT, sizeof(PKT_CONTENT), stdout); fhexdump(0, PKT_CONTENT, sizeof(PKT_CONTENT), stdout);
printf("\n"); printf("\n");

17
tools/tests-transform.c

@ -41,14 +41,15 @@ uint8_t PKT_CONTENT[]={
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }; 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
};
/* Prototypes */ /* Prototypes */
static ssize_t do_encode_packet( uint8_t * pktbuf, size_t bufsize, const n2n_community_t c ); static ssize_t do_encode_packet ( uint8_t * pktbuf, size_t bufsize, const n2n_community_t c );
static void run_transop_benchmark(const char *op_name, n2n_trans_op_t *op_fn, n2n_edge_conf_t *conf, uint8_t *pktbuf); static void run_transop_benchmark (const char *op_name, n2n_trans_op_t *op_fn, n2n_edge_conf_t *conf, uint8_t *pktbuf);
int main(int argc, char * argv[]) { int main (int argc, char * argv[]) {
uint8_t pktbuf[N2N_PKT_BUF_SIZE]; uint8_t pktbuf[N2N_PKT_BUF_SIZE];
n2n_trans_op_t transop_null, transop_tf; n2n_trans_op_t transop_null, transop_tf;
n2n_trans_op_t transop_aes; n2n_trans_op_t transop_aes;
@ -65,7 +66,7 @@ int main(int argc, char * argv[]) {
char *test_name = "environment"; char *test_name = "environment";
printf("%s: community_name = \"%s\"\n", test_name, conf.community_name); printf("%s: community_name = \"%s\"\n", test_name, conf.community_name);
printf("%s: encrypt_key = \"%s\"\n", test_name, conf.encrypt_key); printf("%s: encrypt_key = \"%s\"\n", test_name, conf.encrypt_key);
printf("%s: input size = 0x%"PRIx64"\n", test_name, sizeof(PKT_CONTENT)); printf("%s: input size = 0x%" PRIx64 "\n", test_name, sizeof(PKT_CONTENT));
fhexdump(0, PKT_CONTENT, sizeof(PKT_CONTENT), stdout); fhexdump(0, PKT_CONTENT, sizeof(PKT_CONTENT), stdout);
printf("\n"); printf("\n");
@ -96,7 +97,7 @@ int main(int argc, char * argv[]) {
// --- cipher benchmark ------------------------------------------------------------------- // --- cipher benchmark -------------------------------------------------------------------
static void run_transop_benchmark(const char *op_name, n2n_trans_op_t *op_fn, n2n_edge_conf_t *conf, uint8_t *pktbuf) { static void run_transop_benchmark (const char *op_name, n2n_trans_op_t *op_fn, n2n_edge_conf_t *conf, uint8_t *pktbuf) {
n2n_common_t cmn; n2n_common_t cmn;
n2n_PACKET_t pkt; n2n_PACKET_t pkt;
n2n_mac_t mac_buf; n2n_mac_t mac_buf;
@ -113,7 +114,7 @@ static void run_transop_benchmark(const char *op_name, n2n_trans_op_t *op_fn, n2
pktbuf+nw, N2N_PKT_BUF_SIZE-nw, pktbuf+nw, N2N_PKT_BUF_SIZE-nw,
PKT_CONTENT, sizeof(PKT_CONTENT), mac_buf); PKT_CONTENT, sizeof(PKT_CONTENT), mac_buf);
printf("%s: output size = 0x%"PRIx64"\n", op_name, nw); printf("%s: output size = 0x%" PRIx64 "\n", op_name, nw);
fhexdump(0, pktbuf, nw, stdout); fhexdump(0, pktbuf, nw, stdout);
// decrpytion // decrpytion
@ -133,7 +134,7 @@ static void run_transop_benchmark(const char *op_name, n2n_trans_op_t *op_fn, n2
} }
static ssize_t do_encode_packet( uint8_t * pktbuf, size_t bufsize, const n2n_community_t c ) static ssize_t do_encode_packet ( uint8_t * pktbuf, size_t bufsize, const n2n_community_t c )
{ {
// FIXME: this is a parameter of the test environment // FIXME: this is a parameter of the test environment
n2n_mac_t destMac={0,1,2,3,4,5}; n2n_mac_t destMac={0,1,2,3,4,5};

38
tools/tests-wire.c

@ -21,19 +21,19 @@
#include "n2n.h" #include "n2n.h"
#include "hexdump.h" #include "hexdump.h"
void init_ip_subnet(n2n_ip_subnet_t * d) { void init_ip_subnet (n2n_ip_subnet_t * d) {
d->net_addr = 0x20212223; d->net_addr = 0x20212223;
d->net_bitlen = 25; d->net_bitlen = 25;
} }
void print_ip_subnet(char *test_name, char *field, n2n_ip_subnet_t * d) { void print_ip_subnet (char *test_name, char *field, n2n_ip_subnet_t * d) {
printf("%s: %s.net_addr = 0x%08x\n", printf("%s: %s.net_addr = 0x%08x\n",
test_name, field, d->net_addr); test_name, field, d->net_addr);
printf("%s: %s.net_bitlen = %i\n", printf("%s: %s.net_bitlen = %i\n",
test_name, field, d->net_bitlen); test_name, field, d->net_bitlen);
} }
void init_mac(n2n_mac_t mac, const uint8_t o0, const uint8_t o1, void init_mac (n2n_mac_t mac, const uint8_t o0, const uint8_t o1,
const uint8_t o2, const uint8_t o3, const uint8_t o2, const uint8_t o3,
const uint8_t o4, const uint8_t o5) { const uint8_t o4, const uint8_t o5) {
mac[0] = o0; mac[0] = o0;
@ -44,13 +44,13 @@ void init_mac(n2n_mac_t mac, const uint8_t o0, const uint8_t o1,
mac[5] = o5; mac[5] = o5;
} }
void print_mac(char *test_name, char *field, n2n_mac_t mac) { void print_mac (char *test_name, char *field, n2n_mac_t mac) {
printf("%s: %s[] = %x:%x:%x:%x:%x:%x\n", printf("%s: %s[] = %x:%x:%x:%x:%x:%x\n",
test_name, field, test_name, field,
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
} }
void init_auth(n2n_auth_t *auth) { void init_auth (n2n_auth_t *auth) {
auth->scheme = n2n_auth_simple_id; auth->scheme = n2n_auth_simple_id;
auth->token_size = 16; auth->token_size = 16;
auth->token[0] = 0xfe; auth->token[0] = 0xfe;
@ -59,13 +59,13 @@ void init_auth(n2n_auth_t *auth) {
auth->token[15] = 0xfb; auth->token[15] = 0xfb;
} }
void print_auth(char *test_name, char *field, n2n_auth_t *auth) { void print_auth (char *test_name, char *field, n2n_auth_t *auth) {
printf("%s: %s.scheme = %i\n", test_name, field, auth->scheme); printf("%s: %s.scheme = %i\n", test_name, field, auth->scheme);
printf("%s: %s.token_size = %i\n", test_name, field, auth->token_size); printf("%s: %s.token_size = %i\n", test_name, field, auth->token_size);
printf("%s: %s.token[0] = 0x%02x\n", test_name, field, auth->token[0]); printf("%s: %s.token[0] = 0x%02x\n", test_name, field, auth->token[0]);
} }
void init_common(n2n_common_t *common, char *community) { void init_common (n2n_common_t *common, char *community) {
memset( common, 0, sizeof(*common) ); memset( common, 0, sizeof(*common) );
common->ttl = N2N_DEFAULT_TTL; common->ttl = N2N_DEFAULT_TTL;
common->flags = 0; common->flags = 0;
@ -73,13 +73,13 @@ void init_common(n2n_common_t *common, char *community) {
common->community[N2N_COMMUNITY_SIZE - 1] = '\0'; common->community[N2N_COMMUNITY_SIZE - 1] = '\0';
} }
void print_common(char *test_name, n2n_common_t *common) { void print_common (char *test_name, n2n_common_t *common) {
printf("%s: common.ttl = %i\n", test_name, common->ttl); printf("%s: common.ttl = %i\n", test_name, common->ttl);
printf("%s: common.flags = %i\n", test_name, common->flags); printf("%s: common.flags = %i\n", test_name, common->flags);
printf("%s: common.community = \"%s\"\n", test_name, common->community); printf("%s: common.community = \"%s\"\n", test_name, common->community);
} }
void test_REGISTER(n2n_common_t *common) { void test_REGISTER (n2n_common_t *common) {
char *test_name = "REGISTER"; char *test_name = "REGISTER";
common->pc = n2n_register; common->pc = n2n_register;
@ -104,8 +104,8 @@ void test_REGISTER(n2n_common_t *common) {
size_t idx = 0; size_t idx = 0;
size_t retval = encode_REGISTER( pktbuf, &idx, common, &reg); size_t retval = encode_REGISTER( pktbuf, &idx, common, &reg);
printf("%s: output retval = 0x%"PRIx64"\n", test_name, retval); printf("%s: output retval = 0x%" PRIx64 "\n", test_name, retval);
printf("%s: output idx = 0x%"PRIx64"\n", test_name, idx); printf("%s: output idx = 0x%" PRIx64 "\n", test_name, idx);
fhexdump(0, pktbuf, idx, stdout); fhexdump(0, pktbuf, idx, stdout);
// TODO: decode_REGISTER() and print // TODO: decode_REGISTER() and print
@ -114,7 +114,7 @@ void test_REGISTER(n2n_common_t *common) {
printf("\n"); printf("\n");
} }
void test_REGISTER_SUPER(n2n_common_t *common) { void test_REGISTER_SUPER (n2n_common_t *common) {
char *test_name = "REGISTER_SUPER"; char *test_name = "REGISTER_SUPER";
common->pc = n2n_register_super; common->pc = n2n_register_super;
@ -136,15 +136,15 @@ void test_REGISTER_SUPER(n2n_common_t *common) {
print_ip_subnet(test_name, "reg.dev_addr", &reg.dev_addr); print_ip_subnet(test_name, "reg.dev_addr", &reg.dev_addr);
printf("%s: reg.dev_desc = \"%s\"\n", test_name, reg.dev_desc); printf("%s: reg.dev_desc = \"%s\"\n", test_name, reg.dev_desc);
print_auth(test_name, "reg.auth", &reg.auth); print_auth(test_name, "reg.auth", &reg.auth);
printf("%s: reg.key_time = %"PRIi32"\n", test_name, reg.key_time); printf("%s: reg.key_time = %" PRIi32 "\n", test_name, reg.key_time);
printf("\n"); printf("\n");
uint8_t pktbuf[N2N_PKT_BUF_SIZE]; uint8_t pktbuf[N2N_PKT_BUF_SIZE];
size_t idx = 0; size_t idx = 0;
size_t retval = encode_REGISTER_SUPER( pktbuf, &idx, common, &reg); size_t retval = encode_REGISTER_SUPER( pktbuf, &idx, common, &reg);
printf("%s: output retval = 0x%"PRIx64"\n", test_name, retval); printf("%s: output retval = 0x%" PRIx64 "\n", test_name, retval);
printf("%s: output idx = 0x%"PRIx64"\n", test_name, idx); printf("%s: output idx = 0x%" PRIx64 "\n", test_name, idx);
fhexdump(0, pktbuf, idx, stdout); fhexdump(0, pktbuf, idx, stdout);
// TODO: decode_REGISTER_SUPER() and print // TODO: decode_REGISTER_SUPER() and print
@ -153,7 +153,7 @@ void test_REGISTER_SUPER(n2n_common_t *common) {
printf("\n"); printf("\n");
} }
void test_UNREGISTER_SUPER(n2n_common_t *common) { void test_UNREGISTER_SUPER (n2n_common_t *common) {
char *test_name = "UNREGISTER_SUPER"; char *test_name = "UNREGISTER_SUPER";
common->pc = n2n_unregister_super; common->pc = n2n_unregister_super;
@ -173,8 +173,8 @@ void test_UNREGISTER_SUPER(n2n_common_t *common) {
size_t idx = 0; size_t idx = 0;
size_t retval = encode_UNREGISTER_SUPER( pktbuf, &idx, common, &unreg); size_t retval = encode_UNREGISTER_SUPER( pktbuf, &idx, common, &unreg);
printf("%s: output retval = 0x%"PRIx64"\n", test_name, retval); printf("%s: output retval = 0x%" PRIx64 "\n", test_name, retval);
printf("%s: output idx = 0x%"PRIx64"\n", test_name, idx); printf("%s: output idx = 0x%" PRIx64 "\n", test_name, idx);
fhexdump(0, pktbuf, idx, stdout); fhexdump(0, pktbuf, idx, stdout);
// TODO: decode_UNREGISTER_SUPER() and print // TODO: decode_UNREGISTER_SUPER() and print
@ -183,7 +183,7 @@ void test_UNREGISTER_SUPER(n2n_common_t *common) {
printf("\n"); printf("\n");
} }
int main(int argc, char * argv[]) { int main (int argc, char * argv[]) {
char *test_name = "environment"; char *test_name = "environment";
n2n_common_t common; n2n_common_t common;

34
uncrustify.cfg

@ -0,0 +1,34 @@
# Initial rules taken from a quick discussion
# (See https://github.com/ntop/n2n/commit/00159d0d012c6836fd972af1748833eeaf50fa22#commitcomment-57137247)
# 4 space indention (never use tabs)
indent_columns = 4
indent_with_tabs = 0
indent_switch_case = 4
# space between name and bracket during function define
sp_func_def_paren = force
sp_func_proto_paren = force
# no space between name and bracket during call
sp_func_call_paren = remove
# no space after if and while
sp_before_sparen = remove
#sp_while_paren_open = remove # only in newer uncrustify
# block-braces as seen above
nl_if_brace = remove
nl_brace_else = remove
nl_elseif_brace = remove
nl_else_brace = remove
#nl_before_opening_brace_func_class_def = remove # only in newer uncrustify
nl_for_brace = remove
nl_while_brace = remove
# multi-line parameters with indentation under the opening bracket
# looks like this is the default, but might be the following:
#indent_func_call_param = false ?
# Want to keep var definition alignment
#align_keep_extra_space = true
Loading…
Cancel
Save