Linux Netfilter discussions
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Alexey Kashavkin <akashavkin@gmail.com>
Cc: netfilter@vger.kernel.org, ssuryaextr@gmail.com
Subject: Re: Clarification of the procedure for filtering IP option fields
Date: Thu, 30 Jan 2025 19:06:58 +0100	[thread overview]
Message-ID: <Z5u_wv3bfDkRKLXE@calendula> (raw)
In-Reply-To: <Z5u8cNsrlEn5JH5g@calendula>

[-- Attachment #1: Type: text/plain, Size: 1257 bytes --]

On Thu, Jan 30, 2025 at 06:52:52PM +0100, Pablo Neira Ayuso wrote:
> On Thu, Jan 30, 2025 at 06:49:41PM +0100, Pablo Neira Ayuso wrote:
> > Hi,
> > 
> > On Thu, Jan 30, 2025 at 04:52:29PM +0300, Alexey Kashavkin wrote:
> > > Hello, 
> > > 
> > > I am still figuring out the syntax for adding rules to filter IP
> > > options. Please, if anyone has an understanding of how this works
> > > give at least a short reply.
> > 
> > This 'type' field is redundant.
> > 
> > > I understand how the exthdr expression works in the kernel code. But
> > > so far there is still a question about specifying the type field,
> > > what is the purpose of this field here? There is also a question
> > > about other fields, let's take for example the IP option LSRR, it
> > > has an addr field. I assume, knowing this option from RFC791 it
> > > specifies IP addresses, but in the case of nft it is not so, this
> > > field has datatype intereger.
> > 
> > Yes, this should be at least 32-bits.
> 
> Actually, this is 32-bits already:
> 
> # nft describe ip option lsrr addr
> exthdr expression, datatype integer (integer), 32 bits

This is what you mean:

# nft describe ip option lsrr addr
exthdr expression, datatype ipv4_addr (IPv4 address) (basetype integer), 32 bits

[-- Attachment #2: ip-option-use-ipv4-type.patch --]
[-- Type: text/x-diff, Size: 1560 bytes --]

diff --git a/src/ipopt.c b/src/ipopt.c
index 37f779d468ab..ddb42f5712d4 100644
--- a/src/ipopt.c
+++ b/src/ipopt.c
@@ -24,7 +24,7 @@ static const struct exthdr_desc ipopt_lsrr = {
 		[IPOPT_FIELD_TYPE]		= PHT("type",    0,  8),
 		[IPOPT_FIELD_LENGTH]		= PHT("length",  8,  8),
 		[IPOPT_FIELD_PTR]		= PHT("ptr",    16,  8),
-		[IPOPT_FIELD_ADDR_0]		= PHT("addr",   24, 32),
+		[IPOPT_FIELD_ADDR_0]		= PROTO_HDR_TEMPLATE("addr", &ipaddr_type, BYTEORDER_BIG_ENDIAN, 24, 32),
 	},
 };
 
@@ -35,7 +35,7 @@ static const struct exthdr_desc ipopt_rr = {
 		[IPOPT_FIELD_TYPE]		= PHT("type",   0,   8),
 		[IPOPT_FIELD_LENGTH]		= PHT("length",  8,  8),
 		[IPOPT_FIELD_PTR]		= PHT("ptr",    16,  8),
-		[IPOPT_FIELD_ADDR_0]		= PHT("addr",   24, 32),
+		[IPOPT_FIELD_ADDR_0]		= PROTO_HDR_TEMPLATE("addr", &ipaddr_type, BYTEORDER_BIG_ENDIAN, 24, 32),
 	},
 };
 
@@ -46,7 +46,7 @@ static const struct exthdr_desc ipopt_ssrr = {
 		[IPOPT_FIELD_TYPE]		= PHT("type",   0,   8),
 		[IPOPT_FIELD_LENGTH]		= PHT("length",  8,  8),
 		[IPOPT_FIELD_PTR]		= PHT("ptr",    16,  8),
-		[IPOPT_FIELD_ADDR_0]		= PHT("addr",   24, 32),
+		[IPOPT_FIELD_ADDR_0]		= PROTO_HDR_TEMPLATE("addr", &ipaddr_type, BYTEORDER_BIG_ENDIAN, 24, 32),
 	},
 };
 
@@ -56,7 +56,7 @@ static const struct exthdr_desc ipopt_ra = {
 	.templates	= {
 		[IPOPT_FIELD_TYPE]		= PHT("type",   0,   8),
 		[IPOPT_FIELD_LENGTH]		= PHT("length", 8,   8),
-		[IPOPT_FIELD_VALUE]		= PHT("value",  16, 16),
+		[IPOPT_FIELD_ADDR_0]		= PROTO_HDR_TEMPLATE("addr", &ipaddr_type, BYTEORDER_BIG_ENDIAN, 24, 32),
 	},
 };
 

  reply	other threads:[~2025-01-30 18:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-31 10:54 Clarification of the procedure for filtering IP option fields Alexey Kashavkin
2025-01-30 13:52 ` Alexey Kashavkin
2025-01-30 17:49   ` Pablo Neira Ayuso
2025-01-30 17:52     ` Pablo Neira Ayuso
2025-01-30 18:06       ` Pablo Neira Ayuso [this message]
2025-01-30 23:23         ` Alexey Kashavkin

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=Z5u_wv3bfDkRKLXE@calendula \
    --to=pablo@netfilter.org \
    --cc=akashavkin@gmail.com \
    --cc=netfilter@vger.kernel.org \
    --cc=ssuryaextr@gmail.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