netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sriram Yagnaraman <sriram.yagnaraman@est.tech>
To: Florian Westphal <fw@strlen.de>
Cc: "netfilter-devel@vger.kernel.org"
	<netfilter-devel@vger.kernel.org>,
	kernel test robot <lkp@intel.com>,
	"claudio.porfiri@ericsson.com" <claudio.porfiri@ericsson.com>
Subject: Re: [PATCH v2 1/2] netfilter: conntrack: introduce no_random_port proc entry
Date: Mon, 31 Oct 2022 18:41:37 +0000	[thread overview]
Message-ID: <7c24bfe4-94be-6eab-d30a-6dc0500652da@est.tech> (raw)
In-Reply-To: <20221031083858.GB5040@breakpoint.cc>

On 2022-10-31 09:38, Florian Westphal wrote:

> sriram.yagnaraman@est.tech <sriram.yagnaraman@est.tech> wrote:
>> From: Sriram Yagnaraman <sriram.yagnaraman@est.tech>
>>
>> This patch introduces a new proc entry to disable source port
>> randomization for SCTP connections.
> Hmm.  Can you elaborate?  The sport is never randomized, unless either
> 1. User explicitly requested it via "random" flag passed to snat rule, or
> 2. the is an existing connection, using the *same* sport:saddr -> daddr:dport
>    quadruple as the new request.
>
> In 2), this new toggle prevents communication.  So I wonder why ...

Thank you so much for the detailed review comments.

My use case for this flag originates from a deployment of SCTP client
endpoints on docker/kubernetes environments, where typically there exists
SNAT rules for the endpoints on egress. The *user* in this case are the
CNI plugins that configure the SNAT rules, and some of the most common
plugins use --random-fully regardless of the protocol.

Consider an SCTP association A -> B, which has two paths via NAT A and B
A: 1.2.3.4:12345
B: 5.6.7.8/9:42
NAT A: 1.2.31.4 (used for path towards 5.6.7.8)
NAT B: 1.2.32.4 (used for path towards 5.6.7.9)

              ┌───────┐   ┌───┐
           ┌──► NAT A ├───►   │
 ┌─────┐   │  └───────┘   │   │
 │  A  ├───┤              │ B │
 └─────┘   │  ┌───────┐   │   │
           └──► NAT B ├───►   │
              └───────┘   └───┘

Let us assume in NAT A (1.2.31.4), the connections is setup as
	ORIGINAL TUPLE		    REPLY TUPLE
1.2.3.4:12345 -> 5.6.7.8:42, 5.6.7.8.42 -> 1.2.31.4:33333

Let us assume in NAT B (1.2.32.4), the connections is setup as
	ORIGINAL TUPLE		    REPLY TUPLE
1.2.3.4:12345 -> 5.6.7.9:42, 5.6.7.8.42 -> 1.2.32.4:44444

Since the port numbers are different when viewed from B, the association
will not become multihomed, with only the primary path being active.
Moreover, on a NAT/middlebox restart, we will end up getting new ports.

I understand this is a problem in the way SNAT rules are configured, my
proposal was to have this flag as a means of preventing such a problem
even if the user wanted to.

>> As specified in RFC9260 all transport addresses used by an SCTP endpoint
>> MUST use the same port number but can use multiple IP addresses. That
>> means that all paths taken within an SCTP association should have the
>> same port even if they pass through different NAT/middleboxes in the
>> network.
> ... the rfc mandates this, especially given the fact that endpoints have
> 0 control on middlebox behaviour.
>
> This flag will completely prevent communication in case another
> middlebox does sport randomization, so I wonder why its needed -- I see
> no advantages but I see a downside.

Since the flag is optional, the idea is to enable it only on hosts that
are part of docker/kubernetes environments and use NAT in their datapath.

>> Disabling source port randomization provides a deterministic source port
>> for the remote SCTP endpoint for all paths used in the SCTP association.
>> On NAT/middlebox restarts we will always end up with the same port after
>> the restart, and the SCTP endpoints involved in the SCTP association can
>> remain transparent to restarts.
> Can you elaborate? If we're the middlebox and we restarted, we have no
> record of the "old" incarnation so there is no sport reallocation.
>
>> Of course, there is a downside as this makes it impossible to have
>> multiple SCTP endpoints behind NAT that use the same source port.
> Hmm?  Not following.
>
> 1.2.3.4:12345 -> 5.6.7.8:42
> 1.2.3.4:12345 -> 5.6.7.8:43
>
> ... should work fine. Same for
> 1.2.3.4:12345 -> 5.6.7.8:42
> 1.2.3.4:12345 -> 5.6.7.9:42

I meant to note the limitation you rightly pointed above, that when there
is an existing connection, using the *same* sport:saddr -> dport:daddr, the
new connection attempt will be dropped. For e.g.

1.2.3.41:12345 -> 5.6.7.8:42 (Existing connection)
1.2.3.42:12345 -> 5.6.7.8:42 (This connection request will fail)

Will be translated to conflicting reply tuples
1.2.3.40:12345 <- 5.6.7.8:42
1.2.3.40:12345 <- 5.6.7.8:42

>> But, this is a lesser of a problem than losing an existing association
>> altogether.
> Can you elaborate?  How is an existing assocation lost?
> For example, what sequence of events is needed to result in loss of
> an existing association?

Consider two SCTP associations A -> C and B -> C
A: 1.2.3.41:12345
B: 1.2.3.42:12345
C: 5.6.7.8:42 
NAT public IP: 1.2.3.40

  ┌─────┐
  │  A  ├───┐
  └─────┘   │    ┌─────┐   ┌─────┐
            ├────► NAT ├───►  C  │
  ┌─────┐   │    └─────┘   └─────┘
  │  B  ├───┘
  └─────┘

Let us assume in NAT (1.2.3.40), the connections are setup as
	ORIGINAL TUPLE		    REPLY TUPLE
1.2.3.41:12345 -> 5.6.7.8:42, 5.6.7.8.42 -> 1.2.3.40:12345
1.2.3.42:12345 -> 5.6.7.8:42, 5.6.7.8.42 -> 1.2.3.40:44444

After a restart there is a chance that the connections will be setup as
	ORIGINAL TUPLE		    REPLY TUPLE
1.2.3.41:12345 -> 5.6.7.8:42, 5.6.7.8.42 -> 1.2.3.40:55555
1.2.3.42:12345 -> 5.6.7.8:42, 5.6.7.8.42 -> 1.2.3.40:12345

From C's point of view the port numbers for the two associations will be 
different after a restart, hence there can be no communication using the
existing associations.




  reply	other threads:[~2022-10-31 18:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-30 12:25 [PATCH v2 0/2] netfilter: conntrack: improve SCTP multihoming sriram.yagnaraman
2022-10-30 12:25 ` [PATCH v2 1/2] netfilter: conntrack: introduce no_random_port proc entry sriram.yagnaraman
2022-10-31  8:38   ` Florian Westphal
2022-10-31 18:41     ` Sriram Yagnaraman [this message]
2022-11-02 14:00       ` Florian Westphal
2022-11-03 20:02         ` Sriram Yagnaraman
2022-11-21 11:24           ` Marcelo Ricardo Leitner
2022-10-30 12:25 ` [PATCH v2 2/2] netfilter: conntrack: add sctp DATA_SENT state sriram.yagnaraman
2022-11-02 14:02   ` Florian Westphal
2022-11-21 11:20   ` Marcelo Ricardo Leitner

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=7c24bfe4-94be-6eab-d30a-6dc0500652da@est.tech \
    --to=sriram.yagnaraman@est.tech \
    --cc=claudio.porfiri@ericsson.com \
    --cc=fw@strlen.de \
    --cc=lkp@intel.com \
    --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).