INSTALL | 10 +++++++--- USAGE | 2 +- USAGE.GNU+Linux | 1 - build | 2 +- tapser.c | 27 +++++++++++++++++++-------- diff --git a/INSTALL b/INSTALL index 98f7b8ba45886fdca12e495e879e27ff7a66b813994c7adda8307627f6c799ad..548a0b498b1df72aa516ab3a199efbe813147850fff632b963dc5c75103307da 100644 --- a/INSTALL +++ b/INSTALL @@ -1,9 +1,13 @@ + $ ./build -O3 + +To enable ckecksum support use -DTAPSER_ENABLE_XXH3: + $ curl -L https://api.github.com/repos/Cyan4973/xxHash/tarball/v0.8.3 | tar xf - $ cp Cyan4973-xxHash-e626a72/xxhash.[ch] . - $ ./build -O3 + $ ./build -O3 -DTAPSER_ENABLE_XXH3 -I. xxhash.c Look in xxhash.h for its related options. -To enable Zstandard compression: +To enable Zstandard compression use -DTAPSER_ENABLE_ZSTD: - $ ./build -DTAPSER_ENABLE_ZSTD -lzstd + $ ./build -O3 -DTAPSER_ENABLE_ZSTD $(pkgconf --cflags --libs libzstd) diff --git a/USAGE b/USAGE index 8a9a7b5a58d41ea145d3befa8b7b02e39b3c4867306380b2144ff932ab4faf90..1d4baa638eee5094c06437512f47d7e0590bc51f599784ecd142c87146e2bd44 100644 --- a/USAGE +++ b/USAGE @@ -6,6 +6,6 @@ created. TAPSER_IF environment variable holds its name. -t option switches from TAP to TUN mode of operation. --n option disables checksum usage, using plain SLIP. +-c option enables checksum usage. -z enabled Zstandard compression. That disables checksumming. diff --git a/USAGE.GNU+Linux b/USAGE.GNU+Linux index 9f0d18f9f00665772a4017dc2c1c795249fc13c7cbd2ea3ff7133a690e8f957e..d12eb8ea2cdb38ca9a67b24875b9b2c808a979444c5c5da35bfc6376bc5d07ba 100644 --- a/USAGE.GNU+Linux +++ b/USAGE.GNU+Linux @@ -1,5 +1,4 @@ Network interface is created with the specified name. -Reusing is currently not done. # tapser -u ' ip link set up dev $TAPSER_IF diff --git a/build b/build index 3a215ad4d703d644545379103afc92c9860f402fc16dd56e99a4ef27d715100e..6f79843d002d1b7bbef12496297fbf3db120f4ee638abccf7f14ff1715dce68b 100755 --- a/build +++ b/build @@ -7,5 +7,5 @@ -ffunction-sections -fdata-sections \ $CFLAGS \ -D_DEFAULT_SOURCE \ -DXXH_NO_STREAM \ - $@ tapser.c xxhash.c \ + $@ tapser.c \ $LDFLAGS $LDLIBS -Wl,--gc-sections diff --git a/tapser.c b/tapser.c index 4e027ba4367b74c2f7f6ed80b2e8b7919f8d4f78451bb1d15451704fc2acbd80..0b5260dac6e3cf7e1eba0d905c1a101ee8a89b1d7c9c6e52f50019df2d28cd7a 100644 --- a/tapser.c +++ b/tapser.c @@ -21,7 +21,9 @@ #include #include #endif // __linux__ -#include "xxhash.h" +#ifdef TAPSER_ENABLE_XXH3 +#include +#endif // TAPSER_ENABLE_XXH3 #ifdef TAPSER_ENABLE_ZSTD #include @@ -139,22 +141,22 @@ static void usage() { // clang-format off - fputs("Usage: tapser [-n] [-z] [-s speed] [-u cmd] [-d cmd] /dev/ttyX tapX\n", stderr); + fputs("Usage: tapser [-c] [-z] [-s speed] [-u cmd] [-d cmd] /dev/ttyX tapX\n", stderr); fputs("tapX is desirable name for the newly created TUN/TAP interface on GNU/Linux\n", stderr); fputs("tapX can be full path to already existing /dev/{tap,tun}X device on *BSD\n", stderr); fputs("tapX can be /dev/{tap,tun} to create new one on *BSD\n", stderr); - fputs("-n disables checksum usage\n", stderr); + fputs("-c enables checksums\n", stderr); fputs("-s sets the speed of TTY, by default to 115200\n", stderr); fputs("-u specifies shell command to be run after interface is ready\n", stderr); fputs("-d specifies shell command to be run when we exit\n", stderr); - fputs("-z enable compression\n", stderr); + fputs("-z enable compression (and disable checksums)\n", stderr); // clang-format on } int main(int argc, char *argv[]) { - bool useCsum = true; + bool useCsum = false; bool isTUN = false; bool compress = false; #ifdef TAPSER_ENABLE_ZSTD @@ -170,13 +172,18 @@ int exitCode = EXIT_FAILURE; extern char *optarg; extern int optind; for (int c = 0;;) { - c = getopt(argc, argv, "ns:u:d:tz"); + c = getopt(argc, argv, "cs:u:d:tz"); if (c == -1) { break; } switch (c) { - case 'n': - useCsum = false; + case 'c': +#ifdef TAPSER_ENABLE_XXH3 + useCsum = true; +#else // TAPSER_ENABLE_XXH3 + fprintf(stderr, "xxh3 was not enabled during build\n"); + goto Free; +#endif // TAPSER_ENABLE_XXH3 break; case 's': errno = 0; @@ -300,11 +307,13 @@ fprintf(stderr, "> %zu\t!IP: %d\n", pktLen, src[0]); continue; } } +#ifdef TAPSER_ENABLE_XXH3 if (useCsum) { XXH64_canonicalFromHash( (XXH64_canonical_t *)(src + srcLen), XXH3_64bits(src, srcLen)); srcLen += 8; } +#endif // TAPSER_ENABLE_XXH3 #ifdef TAPSER_ENABLE_ZSTD if (compress) { const size_t s = @@ -402,6 +411,7 @@ goto PktDone; } const size_t rxLenOrig = rxLen - (isTUN ? TUNHdrLen : 0); unsigned char *src = rx; +#ifdef TAPSER_ENABLE_XXH3 if (useCsum) { if (rxLen < TUNHdrLen + 8) { fprintf(stderr, "< %zu\ttoo short\n", rxLenOrig); @@ -415,6 +425,7 @@ goto PktDone; } rxLen -= 8; } +#endif // TAPSER_ENABLE_XXH3 #ifdef TAPSER_ENABLE_ZSTD if (compress) { const size_t s = ZSTD_decompressDCtx(