add more logging for missing tpacket_auxdata cmsg

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If4ee940d4694e3f3197e14c8da9f9cd80080eee7
This commit is contained in:
Maciej Żenczykowski 2023-06-01 08:58:43 +00:00
commit 8fe16b0c52

11
clatd.c
View file

@ -88,18 +88,29 @@ void process_packet_6_to_4(struct tun_data *tunnel) {
return;
}
bool ok = false;
__u32 tp_status = 0;
__u16 tp_net = 0;
for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(&msgh,cmsg)) {
if (cmsg->cmsg_level == SOL_PACKET && cmsg->cmsg_type == PACKET_AUXDATA) {
struct tpacket_auxdata *aux = (struct tpacket_auxdata *)CMSG_DATA(cmsg);
ok = true;
tp_status = aux->tp_status;
tp_net = aux->tp_net;
break;
}
}
if (!ok) {
// theoretically this should not happen...
static bool logged = false;
if (!logged) {
logmsg(ANDROID_LOG_ERROR, "%s: failed to fetch tpacket_auxdata cmsg", __func__);
logged = true;
}
}
const int payload_offset = offsetof(typeof(buf), payload);
if (readlen < payload_offset + tp_net) {
logmsg(ANDROID_LOG_WARN, "%s: ignoring %zd byte pkt shorter than %d+%u L2 header",