diff options
author | Florian Westphal <fw@strlen.de> | 2022-01-03 14:13:21 +0100 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2022-01-03 14:13:21 +0100 |
commit | c3bada27b1db3044418733296cd00ba2e63b74fd (patch) | |
tree | b76d6e19d63bd4e146010998338a1d5e384d570c /examples/nf-queue.c | |
parent | ad23f9ad69c6e6538067d7c320f86b28623584e3 (diff) |
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 <fw@strlen.de>
Diffstat (limited to 'examples/nf-queue.c')
-rw-r--r-- | examples/nf-queue.c | 18 |
1 files changed, 18 insertions, 0 deletions
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. |