summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2023-03-14 03:50:28 +0000
committerMaciej Żenczykowski <maze@google.com>2023-03-14 09:54:35 +0000
commit206b238eb9ac4d634fa2bd515819a0b480bab067 (patch)
tree002567566a4b11c3630baeb1ade674cc126fd6e3
parentcfa100f7e21f3a3ed0a2f230d6c08dcf2f9c7833 (diff)
downloadandroid-clat-206b238eb9ac4d634fa2bd515819a0b480bab067.tar.gz
clatd: use struct instead of direct u8[] for buffer
(this will allow adding more headers) Note the ethernet header may or may not be present, so it has to stay as part of the payload. Test: TreeHugger Bug: 265591307 Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I4e64fd1d15ac26ebb7a41ee9884b506625018fda
-rw-r--r--clatd.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/clatd.c b/clatd.c
index 96611d1..284a676 100644
--- a/clatd.c
+++ b/clatd.c
@@ -77,14 +77,17 @@ int ipv6_address_changed(const char *interface) {
}
}
-// reads L3 IPv6 packet from AF_PACKET socket, translates to IPv4, writes to tun
+// reads IPv6 packet from AF_PACKET socket, translates to IPv4, writes to tun
void process_packet_6_to_4(struct tun_data *tunnel) {
// ethernet header is 14 bytes, plus 4 for a normal VLAN tag or 8 for Q-in-Q
// we don't really support vlans (or especially Q-in-Q)...
// but a few bytes of extra buffer space doesn't hurt...
- uint8_t buf[22 + MAXMTU + 1]; // +1 to make packet truncation obvious
+ struct {
+ uint8_t payload[22 + MAXMTU];
+ char pad; // +1 to make packet truncation obvious
+ } buf;
struct iovec iov = {
- .iov_base = buf,
+ .iov_base = &buf,
.iov_len = sizeof(buf),
};
char cmsg_buf[CMSG_SPACE(sizeof(struct tpacket_auxdata))];
@@ -137,7 +140,7 @@ void process_packet_6_to_4(struct tun_data *tunnel) {
}
}
- translate_packet(tunnel->fd4, 0 /* to_ipv6 */, buf + tp_net, readlen - tp_net);
+ translate_packet(tunnel->fd4, 0 /* to_ipv6 */, buf.payload + tp_net, readlen - tp_net);
}
// reads TUN_PI + L3 IPv4 packet from tun, translates to IPv6, writes to AF_INET6/RAW socket