diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2014-06-02 21:20:40 +0900 |
---|---|---|
committer | Lorenzo Colitti <lorenzo@google.com> | 2014-06-11 12:42:20 +0900 |
commit | 10e8827d636a72a7bcdfd52d15bad9342ae2a0a6 (patch) | |
tree | 11c136eee521a2e0815eb51f887135d86351f53a /clatd_test.cpp | |
parent | 91d0f1bc6dd24e54ed3caef9b08525b332ab0adf (diff) | |
download | android_external_android-clat-10e8827d636a72a7bcdfd52d15bad9342ae2a0a6.tar.gz android_external_android-clat-10e8827d636a72a7bcdfd52d15bad9342ae2a0a6.tar.bz2 android_external_android-clat-10e8827d636a72a7bcdfd52d15bad9342ae2a0a6.zip |
Use a raw socket to send IPv6 packets instead of a tun.
This will allow us to bind the socket to a particular network.
Bug: 15340961
Change-Id: I50857d372955f2b6f7035157c2968cda72c32585
Diffstat (limited to 'clatd_test.cpp')
-rw-r--r-- | clatd_test.cpp | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/clatd_test.cpp b/clatd_test.cpp index bc32a84..b35bf70 100644 --- a/clatd_test.cpp +++ b/clatd_test.cpp @@ -418,6 +418,13 @@ void fix_udp_checksum(uint8_t* packet) { udp->check = ip_checksum_finish(ip_checksum_add(pseudo_checksum, udp, ntohs(udp->len))); } +// Testing stub for send_rawv6. The real version uses sendmsg() with a +// destination IPv6 address, and attempting to call that on our test socketpair +// fd results in EINVAL. +extern "C" void send_rawv6(int fd, clat_packet out, int iov_len) { + writev(fd, out, iov_len); +} + void do_translate_packet(const uint8_t *original, size_t original_len, uint8_t *out, size_t *outlen, const char *msg) { int fds[2]; @@ -453,19 +460,25 @@ void do_translate_packet(const uint8_t *original, size_t original_len, uint8_t * translate_packet(write_fd, (version == 4), original, original_len); - struct tun_pi new_tun_header; - struct iovec iov[] = { - { &new_tun_header, sizeof(new_tun_header) }, - { out, *outlen } - }; - int len = readv(read_fd, iov, 2); - if (len > (int) sizeof(new_tun_header)) { - ASSERT_LT((size_t) len, *outlen) << msg << ": Translated packet buffer too small\n"; - EXPECT_EQ(expected_proto, new_tun_header.proto) << msg << "Unexpected tun proto\n"; - *outlen = len - sizeof(new_tun_header); + if (version == 6) { + // Translating to IPv4. Expect a tun header. + struct tun_pi new_tun_header; + struct iovec iov[] = { + { &new_tun_header, sizeof(new_tun_header) }, + { out, *outlen } + }; + int len = readv(read_fd, iov, 2); + if (len > (int) sizeof(new_tun_header)) { + ASSERT_LT((size_t) len, *outlen) << msg << ": Translated packet buffer too small\n"; + EXPECT_EQ(expected_proto, new_tun_header.proto) << msg << "Unexpected tun proto\n"; + *outlen = len - sizeof(new_tun_header); + } else { + FAIL() << msg << ": Packet was not translated"; + *outlen = 0; + } } else { - FAIL() << msg << ": Packet was not translated"; - *outlen = 0; + // Translating to IPv6. Expect raw packet. + *outlen = read(read_fd, out, *outlen); } } |