diff options
author | Maciej Żenczykowski <maze@google.com> | 2023-03-14 00:25:46 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-03-14 00:25:46 +0000 |
commit | 4b8904f3d12f379393dff7849a124eea6fa149af (patch) | |
tree | 588a1a731bbb204358e31de288c39ad49992504b | |
parent | 52c87308a0b70a258615945aac44c0cd04a8db95 (diff) | |
parent | db02e4ef436352d8b7bb5cc9b42a50a694b731bb (diff) | |
download | android-clat-4b8904f3d12f379393dff7849a124eea6fa149af.tar.gz |
Merge "clatd: rework buffer sizes" am: db02e4ef43
Original change: https://android-review.googlesource.com/c/platform/external/android-clat/+/2484896
Change-Id: I6138776fb4a31e18b5a66a747427dba313bb18b8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | clatd.c | 12 | ||||
-rw-r--r-- | clatd.h | 15 |
2 files changed, 14 insertions, 13 deletions
@@ -80,10 +80,10 @@ int ipv6_address_changed(const char *interface) { // reads L3 IPv6 packet from AF_PACKET socket, translates to IPv4, writes to tun void process_packet_6_to_4(struct tun_data *tunnel) { char cmsg_buf[CMSG_SPACE(sizeof(struct tpacket_auxdata))]; - uint8_t buf[MAXMTU]; + uint8_t buf[MAXMTU + 1]; // +1 to make packet truncation obvious struct iovec iov = { .iov_base = buf, - .iov_len = MAXMTU, + .iov_len = sizeof(buf), }; struct msghdr msgh = { .msg_iov = &iov, @@ -102,7 +102,7 @@ void process_packet_6_to_4(struct tun_data *tunnel) { logmsg(ANDROID_LOG_WARN, "%s: packet socket removed?", __func__); running = 0; return; - } else if (readlen >= MAXMTU) { + } else if (readlen >= sizeof(buf)) { logmsg(ANDROID_LOG_WARN, "%s: read truncation - ignoring pkt", __func__); return; } @@ -131,8 +131,8 @@ void process_packet_6_to_4(struct tun_data *tunnel) { // reads TUN_PI + L3 IPv4 packet from tun, translates to IPv6, writes to AF_INET6/RAW socket void process_packet_4_to_6(struct tun_data *tunnel) { - uint8_t buf[PACKETLEN]; - ssize_t readlen = read(tunnel->fd4, buf, PACKETLEN); + uint8_t buf[sizeof(struct tun_pi) + MAXMTU + 1]; // +1 to make packet truncation obvious + ssize_t readlen = read(tunnel->fd4, buf, sizeof(buf)); if (readlen < 0) { if (errno != EAGAIN) { @@ -143,7 +143,7 @@ void process_packet_4_to_6(struct tun_data *tunnel) { logmsg(ANDROID_LOG_WARN, "%s: tun interface removed", __func__); running = 0; return; - } else if (readlen >= PACKETLEN) { + } else if (readlen >= sizeof(buf)) { logmsg(ANDROID_LOG_WARN, "%s: read truncation - ignoring pkt", __func__); return; } @@ -38,14 +38,15 @@ struct tun_data; // // (since there's no jumbogram support in IPv4, IPv6 jumbograms cannot be meaningfully // converted to IPv4 anyway, and are thus entirely unsupported) -// -// We bump it by one more, since it makes truncation more obvious. -// ie. if we ever read >= MAXMTU bytes we should discard. -#define MAXMTU (0xFFFF + 28 + 1) -#define PACKETLEN (sizeof(struct tun_pi) + MAXMTU) +#define MAXMTU (0xFFFF + 28) -// logcat_hexdump() maximum binary data length -#define MAXDUMPLEN PACKETLEN +// logcat_hexdump() maximum binary data length, this is the maximum packet size +// plus some extra space for various headers: +// struct tun_pi (4 bytes) +// struct virtio_net_hdr (10 bytes) +// ethernet (14 bytes), potentially including vlan tag (4) or tags (8 or 12) +// plus some extra just-in-case headroom, because it doesn't hurt. +#define MAXDUMPLEN (64 + MAXMTU) #define CLATD_VERSION "1.6" |