From: Jeremy Sowden <jeremy@azazel.net>
To: Netfilter Devel <netfilter-devel@vger.kernel.org>
Cc: Robert O'Brien <robrien@foxtrot-research.com>
Subject: [PATCH ulogd2 v3 04/11] raw2packet_BASE: store ARP address values as integers
Date: Mon, 21 Aug 2023 20:42:30 +0100	[thread overview]
Message-ID: <20230821194237.51139-5-jeremy@azazel.net> (raw)
In-Reply-To: <20230821194237.51139-1-jeremy@azazel.net>
Keys of type `ULOGD_RET_IPADDR` may be ipv4 or ipv6.  ARP protocol
addresses are 32-bits (i.e., ipv4).  By using `okey_set_u32` we keep
track of the size and allow downstream plug-ins to handle them
correctly.
Reported-by: Robert O'Brien <robrien@foxtrot-research.com>
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 filter/raw2packet/ulogd_raw2packet_BASE.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/filter/raw2packet/ulogd_raw2packet_BASE.c b/filter/raw2packet/ulogd_raw2packet_BASE.c
index 14423486a880..09e931349acf 100644
--- a/filter/raw2packet/ulogd_raw2packet_BASE.c
+++ b/filter/raw2packet/ulogd_raw2packet_BASE.c
@@ -896,18 +896,23 @@ static int _interp_arp(struct ulogd_pluginstance *pi, uint32_t len)
 	struct ulogd_key *ret = pi->output.keys;
 	const struct ether_arp *arph =
 		ikey_get_ptr(&pi->input.keys[INKEY_RAW_PCKT]);
+	uint32_t arp_spa, arp_tpa;
 
 	if (len < sizeof(struct ether_arp))
 		return ULOGD_IRET_OK;
 
-	okey_set_u16(&ret[KEY_ARP_HTYPE], ntohs(arph->arp_hrd));
-	okey_set_u16(&ret[KEY_ARP_PTYPE], ntohs(arph->arp_pro));
+	okey_set_u16(&ret[KEY_ARP_HTYPE],  ntohs(arph->arp_hrd));
+	okey_set_u16(&ret[KEY_ARP_PTYPE],  ntohs(arph->arp_pro));
 	okey_set_u16(&ret[KEY_ARP_OPCODE], ntohs(arph->arp_op));
 
 	okey_set_ptr(&ret[KEY_ARP_SHA], (void *)&arph->arp_sha);
-	okey_set_ptr(&ret[KEY_ARP_SPA], (void *)&arph->arp_spa);
 	okey_set_ptr(&ret[KEY_ARP_THA], (void *)&arph->arp_tha);
-	okey_set_ptr(&ret[KEY_ARP_TPA], (void *)&arph->arp_tpa);
+
+	memcpy(&arp_spa, arph->arp_spa, sizeof(arp_spa));
+	memcpy(&arp_tpa, arph->arp_tpa, sizeof(arp_tpa));
+
+	okey_set_u32(&ret[KEY_ARP_SPA], arp_spa);
+	okey_set_u32(&ret[KEY_ARP_TPA], arp_tpa);
 
 	return ULOGD_IRET_OK;
 }
-- 
2.40.1
next prev parent reply	other threads:[~2023-08-21 19:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-21 19:42 [PATCH ulogd2 v3 00/11] Fixes for handling and output of IP addresses Jeremy Sowden
2023-08-21 19:42 ` [PATCH ulogd2 v3 01/11] src: record length of integer key values Jeremy Sowden
2023-08-21 19:42 ` [PATCH ulogd2 v3 02/11] printpkt: fix statement punctuator Jeremy Sowden
2023-08-21 19:42 ` [PATCH ulogd2 v3 03/11] printpkt, raw2packet_BASE: keep gateway address in NBO Jeremy Sowden
2023-08-21 19:42 ` Jeremy Sowden [this message]
2023-08-21 19:42 ` [PATCH ulogd2 v3 05/11] ip2hbin: store ipv6 address as integer Jeremy Sowden
2023-08-21 19:42 ` [PATCH ulogd2 v3 06/11] ipfix: skip non-ipv4 addresses Jeremy Sowden
2023-08-21 19:42 ` [PATCH ulogd2 v3 07/11] gprint, oprint: use inet_ntop to format ip addresses Jeremy Sowden
2023-08-21 19:42 ` [PATCH ulogd2 v3 08/11] gprint, oprint: add support for printing ipv6 addresses Jeremy Sowden
2023-08-21 19:42 ` [PATCH ulogd2 v3 09/11] sqlite3: correct binding of ipv4 addresses and 64-bit integers Jeremy Sowden
2023-08-21 19:42 ` [PATCH ulogd2 v3 10/11] sqlite3: insert ipv6 addresses as null rather than garbage Jeremy Sowden
2023-08-21 19:42 ` [PATCH ulogd2 v3 11/11] db: insert ipv6 addresses in the same format as ip2bin Jeremy Sowden
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=20230821194237.51139-5-jeremy@azazel.net \
    --to=jeremy@azazel.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=robrien@foxtrot-research.com \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).