diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2014-06-02 21:20:40 +0900 |
---|---|---|
committer | Lorenzo Colitti <lorenzo@google.com> | 2014-06-13 11:47:50 +0900 |
commit | ce14088b80c2d22add83a616e567f9025d252ef7 (patch) | |
tree | 340a3483a79095473fe86598abf4f7424b4e49a8 /clatd_test.cpp | |
parent | e24982ea3a4480d9d62c75b4d9a416b9479f7f0b (diff) | |
download | android_external_android-clat-ce14088b80c2d22add83a616e567f9025d252ef7.tar.gz android_external_android-clat-ce14088b80c2d22add83a616e567f9025d252ef7.tar.bz2 android_external_android-clat-ce14088b80c2d22add83a616e567f9025d252ef7.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.
(cherry picked from commit 10e8827d636a72a7bcdfd52d15bad9342ae2a0a6)
Bug: 15340961
Change-Id: I0b62ef96364a90b9c0a9e3ac3ba97b5c19c89b69
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); } } |