netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rick van Rein <rick@openfortress.nl>
To: Patrick McHardy <kaber@trash.net>
Cc: netfilter-devel@vger.kernel.org
Subject: Extensions for ICMP[6] with sport, dport
Date: Mon, 08 Jun 2020 19:31:01 +0200	[thread overview]
Message-ID: <5EDE75D5.7020303@openfortress.nl> (raw)

Hello Patrick McHardy / NFT,

I'm using NetFilter for static firewalling.  Ideally with ICMP, for
which I found that a minor extension might be helpful, adding selectors
for icmp|icmp6|l4proto sport|dport.  This avoids painstaking detail to
carry ICMP, and may be helpful to have mature firewalls more easily.
Would you agree that this is a useful extension?

Interpretation of IP content is valid for error types; for ICMP, those
are 3,11,12,31, for ICMP6, those are 1,2,3,4; this should be checked
elsewhere in the ruleset.  The code supports "l4proto" selection of ICMP
with the same rules as TCP et al.  (But a better implementation of
"l4proto" in meta.c would skip IP option headers and ICMP headers with
error types to actually arrive at layer 4, IMHO).

A sketch of code is below; I am unsure about the [THDR_?PORT] but I
think the "sport" and "dport" should be interpreted in reverse for ICMP,
as it travels upstream.  That would match "l4proto sport" match ICMP
along with the TCP, UDP, SCTP and DCCP to which it relates.  It also
seems fair that ICMP with a "dport" targets the port at the ICMP target,
so the originator of the initial message.


If you want me to continue on this, I need to find a way into
git.kernel.org and how to offer code.  Just point me to howto's.  I also
could write a Wiki about Stateful Filter WHENTO-and-HOWTO.


Cheers,
 -Rick


struct icmphdr_udphdr {
	struct icmphdr ih;
	struct udphdr uh;
};

const struct proto_desc proto_icmp = {
	…
        .templates      = {
		…
		/* ICMP travels upstream; we reverse sport/dport for icmp/l4proto */
                [THDR_SPORT]            = INET_SERVICE(“sport", struct
icmphdr_udphdr, uh.dest  ),
                [THDR_DPORT]            = INET_SERVICE(“dport", struct
icmphdr_udphdr, uh.source),
		// Unsure about these indexes…
        },
	…
};

struct icmp6hdr_udphdr {
	struct icmp6hdr ih;
	struct udphdr uh;
};


const struct proto_desc proto_icmp6 = {
	…
        .templates      = {
		…
		/* ICMP travels upstream; we reverse sport/dport for icmp6/l4proto */
                [THDR_SPORT]            = INET_SERVICE(“sport", struct
icmphdr_udphdr, uh.dest),
                [THDR_DPORT]            = INET_SERVICE(“dport", struct
icmphdr_udphdr, uh.source),
		// Unsure about these indexes…
        },
	…
};

             reply	other threads:[~2020-06-08 17:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-08 17:31 Rick van Rein [this message]
2020-06-09  4:53 ` Extensions for ICMP[6] with sport, dport Duncan Roe
2020-06-09  9:41 ` Florian Westphal
2020-06-09 10:46   ` Rick van Rein
2020-06-12 16:34     ` Florian Westphal
2020-06-12 18:42       ` Rick van Rein

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=5EDE75D5.7020303@openfortress.nl \
    --to=rick@openfortress.nl \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    /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).