From d62b2ff05b3489b3b555c1d0afb7b6fabac553be Mon Sep 17 00:00:00 2001 From: Alberto Leiva Popper Date: Fri, 2 Dec 2016 10:40:04 -0600 Subject: [PATCH] Add more improvements inspired by the #232 review Includes - A fix to the 6791 pool: was always using host addresses, regardless of whether the pool had elements or not. - More graybox improvements. - More comments. --- include/nat64/mod/common/log.h | 4 +- mod/common/rfc6145/4to6.c | 6 +- mod/stateless/rfc6791.c | 2 +- test/graybox/README.md | 72 +++++++++--------- test/graybox/test-suite/client/siit/manual.sh | 19 +++-- .../client/siit/manual/6791-expected.pkt | Bin 0 -> 88 bytes ...error-addresses-test.pkt => 6791-test.pkt} | Bin .../test-suite/client/siit/manual/6791.pkt | Bin 100 -> 0 bytes ...eceiver-nofrag.pkt => igmp46-expected.pkt} | Bin ...gmp4-sender-nofrag.pkt => igmp46-test.pkt} | Bin ...eceiver-nofrag.pkt => igmp64-expected.pkt} | Bin ...gmp6-sender-nofrag.pkt => igmp64-test.pkt} | Bin .../test-suite/client/siit/manual/loop.pkt | Bin 52 -> 0 bytes 13 files changed, 52 insertions(+), 51 deletions(-) create mode 100644 test/graybox/test-suite/client/siit/manual/6791-expected.pkt rename test/graybox/test-suite/client/siit/manual/{error-addresses-test.pkt => 6791-test.pkt} (100%) delete mode 100644 test/graybox/test-suite/client/siit/manual/6791.pkt rename test/graybox/test-suite/client/siit/manual/{igmp6-receiver-nofrag.pkt => igmp46-expected.pkt} (100%) rename test/graybox/test-suite/client/siit/manual/{igmp4-sender-nofrag.pkt => igmp46-test.pkt} (100%) rename test/graybox/test-suite/client/siit/manual/{igmp4-receiver-nofrag.pkt => igmp64-expected.pkt} (100%) rename test/graybox/test-suite/client/siit/manual/{igmp6-sender-nofrag.pkt => igmp64-test.pkt} (100%) delete mode 100644 test/graybox/test-suite/client/siit/manual/loop.pkt diff --git a/include/nat64/mod/common/log.h b/include/nat64/mod/common/log.h index 867c278fb..4f2f9da26 100644 --- a/include/nat64/mod/common/log.h +++ b/include/nat64/mod/common/log.h @@ -15,12 +15,12 @@ * (bad checksums, bogus addresses, etc) and some failed memory allocations * (because the kernel already prints those). */ -#define log_debug(text, ...) pr_debug(text "\n", ##__VA_ARGS__) +#define log_debug(text, ...) pr_debug("%s: " text "\n", xlat_get_name(), ##__VA_ARGS__) /** * Responses to events triggered by the user, which might not show signs of life * elsehow. */ -#define log_info(text, ...) pr_info(text "\n", ##__VA_ARGS__) +#define log_info(text, ...) pr_info("%s: " text "\n", xlat_get_name(), ##__VA_ARGS__) /** * "I'm not going to translate this because the config's not right." * These rate limit themselves so the log doesn't get too flooded. diff --git a/mod/common/rfc6145/4to6.c b/mod/common/rfc6145/4to6.c index b1740d0a1..ce9620e25 100644 --- a/mod/common/rfc6145/4to6.c +++ b/mod/common/rfc6145/4to6.c @@ -36,10 +36,12 @@ verdict ttp46_create_skb(struct xlation *state) * The subpayload might get truncated to maximize delivery probability. */ l3_hdr_len = sizeof(struct ipv6hdr); - if (will_need_frag_hdr(pkt_ip4_hdr(in))) + if (will_need_frag_hdr(pkt_ip4_hdr(in))) { l3_hdr_len += sizeof(struct frag_hdr); - else + } else { + /* The kernel might want to fragment this so leave room.*/ reserve += sizeof(struct frag_hdr); + } total_len = l3_hdr_len + pkt_l3payload_len(in); if (is_first_frag4(pkt_ip4_hdr(in)) && pkt_is_icmp4_error(in)) { diff --git a/mod/stateless/rfc6791.c b/mod/stateless/rfc6791.c index 3ef759041..aa6731d99 100644 --- a/mod/stateless/rfc6791.c +++ b/mod/stateless/rfc6791.c @@ -95,7 +95,7 @@ static int get_rfc6791_address(struct xlation *state, unsigned int count, done = pool_foreach(state->jool.siit.pool6791, find_nth_addr, &args, NULL); if (done) - return done; + return 0; if (args.flushed) return -ESRCH; diff --git a/test/graybox/README.md b/test/graybox/README.md index 84a91092b..841aeeb85 100644 --- a/test/graybox/README.md +++ b/test/graybox/README.md @@ -31,42 +31,46 @@ See the content of `run.sh` for more versatility. Please [report](https://github.com/NICMx/Jool/issues) any errors or queued packets you find. Please include your distro, kernel version (`uname -r`) and the tail of `dmesg` (after the "SIIT/NAT64 Jool vX.Y.Z.W module inserted" caption). -That's everything most users need to know. See below if you want to add tests to the suite. +That's everything you need to know if you just want to run the tests. See below if you'd like to add tests to the suite. ## Preparing tests This is what you need to know: -Adding tests to the suite right away is cumbersome; you don't want to run the entire suite when you're testing your *test*. To speed things up, you can run improvised standalone packet exchanges with the suite's translators by interacting with the following scripts (attached): +Adding tests to the suite right away is cumbersome; you don't want to run the entire thing when you're just testing your *test*. To speed things up, you can run improvised standalone packet exchanges with the suite's translators by interacting with the following scripts (in the `test-suite` folder): - test-suite/namespace-create.sh + namespace-create.sh Creates a network namespace where the translator will be enclosed and the relevant virtual interfaces. - test-suite/namespace-destroy.sh - Cleans up whatever namespace-crete.sh did. - test-suite/network-create.sh + See the output of `ip netns` and `ip link` to take a peek + to the results. + namespace-destroy.sh + Reverts whatever namespace-create.sh did. + network-create.sh Prepares the test network for the relevant translator. can be either "siit" or "nat64". - test-suite/network-destroy.sh - Cleans up whatever network-crete.sh did. + See the output of `ip addr` to take a peek to the + results. + network-destroy.sh + Reverts whatever network-create.sh did. So, for example, to prepare an environment to send some improvised packets to the SIIT translator, run ```bash -test-suite/namespace-create.sh -test-suite/network-create.sh siit +cd test-suite +sudo ./namespace-create.sh +sudo ./network-create.sh siit +cd .. ``` -A description of the network we just created can be found in `test-suite/siit network.txt`. (TODO we need a NAT64 version too.) - -You can run `ip address` here to see your channels to your "improvised" translator. +A description of the network you just created can be found in `test-suite/siit network.txt`. (TODO we need a NAT64 version too.) See `ip address` too. -Then send some packets and see how Jool behaves (via `tcpdump`, `dmesg` and stuff): +Then send some test packets. Evaluate results via tools such as `dmesg` (if you enabled [debug](https://github.com/NICMx/Jool/wiki/Jool's-Compilation-Options#-ddebug)) and `tcpdump`. Graybox expects test packets to be contained verbatim (from layer 3 header onwards) in a file. See examples in `test-suite/client/siit/manual`. ```bash -usr/graybox send some-packet-1.pkt -usr/graybox send some-packet-2.pkt -usr/graybox send some-packet-3.pkt +usr/graybox send /path/to/some-packet-1.pkt +usr/graybox send /path/to/some-packet-2.pkt +usr/graybox send /path/to/some-packet-3.pkt ``` See `man usr/graybox.7` for more documentation on what `usr/graybox` can do. @@ -74,34 +78,28 @@ See `man usr/graybox.7` for more documentation on what `usr/graybox` can do. Finally, when you're done, issue the following commands to clean up: ```bash -test-suite/network-destroy.sh siit -test-suite/namespace-destroy.sh +cd test-suite +sudo ./network-destroy.sh siit +sudo ./namespace-destroy.sh +cd .. ``` -## Adding improvised tests to the suite - -(TODO now that I added the previous section, this is kind of obsolete and should become "how to add your improvised test to the suite.") +## Adding your "improvised" test to the suite -You need to provide: +For every test, you need to provide: -- A "test" packet. (A packet that is sent to the translator.) +- A "test" packet. (A packet that is sent to the translator. It's the one you generated during the previous step.) - An "expected" packet. (The packet that we expect the translator to turn the "test" packet into.) -The framework expects each packet to be found verbatim (layer 3 header, layer 4 header, payload) in a dedicated file. See examples in `test-suite/client/siit/manual`. - -Assuming that there is a translator available, and the packets' addresses will be routed towards and back from it, a standalone test can be pulled off as follows: +Test "expected" by doing something like (assuming the namespace and the network are set) ```bash -# Start graybox. -insmod mod/graybox.ko # Tell graybox to "expect" packet foo.pkt -usr/graybox expect add foo.pkt -# Tell graybox to send "test" packet bar.pkt -usr/graybox send bar.pkt +usr/graybox expect add /path/to/foo.pkt +# Ask graybox to send "test" packet bar.pkt +usr/graybox send /path/to/bar.pkt # Wait. Jool translates bar.pkt and graybox validates the response. # Hopefully this should happen in less than a tenth of a second. -# I wish I had a more bulletproff and less wasteful way to do this. -# Maybe later. # This is only for scripts. If you're typing this, you obviously don't need this # unless you can type faster than the kernel can send packets. sleep 0.1 @@ -111,10 +109,12 @@ sleep 0.1 usr/graybox expect flush # Print the results. usr/graybox stats display -# Stop graybox. -rmmod graybox ``` +Place both the expected and test packets in `test-suite/client//manual` and register them in `test-suite/client//manual.sh`. + +Test the full suite and you're done. Might want to commit and upload your work to the repository. + ## Some notes - I don't know if the graybox kernel module is a very elegant way to do this. Perhaps raw sockets would get the job done just fine. diff --git a/test/graybox/test-suite/client/siit/manual.sh b/test/graybox/test-suite/client/siit/manual.sh index 3f9052a5e..e8e043a76 100755 --- a/test/graybox/test-suite/client/siit/manual.sh +++ b/test/graybox/test-suite/client/siit/manual.sh @@ -1,22 +1,21 @@ #!/bin/bash +GRAYBOX=`dirname $0`/../../../usr/graybox + + function test-single { - graybox expect add $2-nofrag.pkt $3 - graybox send $1-nofrag.pkt + $GRAYBOX expect add $2-expected.pkt $3 + $GRAYBOX send $1-test.pkt sleep 0.1 - graybox expect flush + $GRAYBOX expect flush } -# test-frags 4-udp-csumok-nodf 6-udp-csumok-nodf -# test-frags 4-udp-csumfail-nodf 6-udp-csumfail-nodf - -test-single manual/igmp6-sender manual/igmp4-receiver 4,5,10,11 -test-single manual/igmp4-sender manual/igmp6-receiver +test-single manual/igmp64 4,5,10,11 +test-single manual/igmp46 +test-single manual/6791 4,5,10,11,32,33,38,39 -#NAT64/tests/graybox/usr/graybox -sa --pkt manual/error-addresses-test.pkt -#NAT64/tests/graybox/usr/graybox -sa --pkt manual/loop.pkt graybox stats display graybox stats flush diff --git a/test/graybox/test-suite/client/siit/manual/6791-expected.pkt b/test/graybox/test-suite/client/siit/manual/6791-expected.pkt new file mode 100644 index 0000000000000000000000000000000000000000..cb1122d06018e878b2f3c7be09c4d8f4667752ff GIT binary patch literal 88 zcmZ=|V2EG<0((Z$^wSK59LJ1Pn3$Pg_JYJ*85nFpw1Z$@6iEC41Ct{A1^xvL8eG>H j7@3$^SlQS)IJvlac=`AR1cih}M8(7L85kLu5