From c3bada27b1db3044418733296cd00ba2e63b74fd Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Mon, 3 Jan 2022 14:13:21 +0100 Subject: examples: print hwaddr attribute if present There was a bug in 5.15 where HWADDR was included even if mac_header start was same as network header. In that case, userspace would get network header re-interpreted as a mac address, i.e. hw->hw_addr[] set to network_header + 6 in ethernet case. Dump hwaddr if present. Signed-off-by: Florian Westphal --- examples/nf-queue.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/nf-queue.c b/examples/nf-queue.c index 5b86e69..6983418 100644 --- a/examples/nf-queue.c +++ b/examples/nf-queue.c @@ -86,6 +86,24 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) printf("packet received (id=%u hw=0x%04x hook=%u, payload len %u", id, ntohs(ph->hw_protocol), ph->hook, plen); + if (attr[NFQA_HWADDR]) { + struct nfqnl_msg_packet_hw *hw = mnl_attr_get_payload(attr[NFQA_HWADDR]); + unsigned int hwlen = ntohs(hw->hw_addrlen); + const char *addr = hw->hw_addr; + unsigned int i; + + printf(", hwaddr %02x", addr[0]); + for (i = 1; i < hwlen; i++) { + if (i >= sizeof(hw->hw_addr)) { + printf("[truncated]"); + break; + } + printf(":%02x", (unsigned char)addr[i]); + } + + printf(" len %u", hwlen); + } + /* * ip/tcp checksums are not yet valid, e.g. due to GRO/GSO. * The application should behave as if the checksums are correct. -- cgit v1.2.3