netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: Xin Long <lucien.xin@gmail.com>
Cc: Tobias Brunner <tobias@strongswan.org>,
	network dev <netdev@vger.kernel.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Jamal Hadi Salim <hadi@cyberus.ca>,
	"Sabrina Dubroca" <sd@queasysnail.net>,
	Jamal Hadi Salim <jhs@mojatatu.com>, <pwouters@redhat.com>
Subject: Re: [PATCH ipsec] xfrm: state: match with both mark and mask on user interfaces
Date: Tue, 7 Jul 2020 08:17:19 +0200	[thread overview]
Message-ID: <20200707061719.GV19286@gauss3.secunet.de> (raw)
In-Reply-To: <CADvbK_cQBbFwYj_CYTm69LP8a7R3PsS=nr0MyfRjAcASVz=dhQ@mail.gmail.com>

On Mon, Jul 06, 2020 at 04:33:53PM +0800, Xin Long wrote:
> >
> > > @@ -1051,7 +1061,6 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
> > >       int acquire_in_progress = 0;
> > >       int error = 0;
> > >       struct xfrm_state *best = NULL;
> > > -     u32 mark = pol->mark.v & pol->mark.m;
> > >       unsigned short encap_family = tmpl->encap_family;
> > >       unsigned int sequence;
> > >       struct km_event c;
> > > @@ -1065,7 +1074,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
> > >       hlist_for_each_entry_rcu(x, net->xfrm.state_bydst + h, bydst) {
> > >               if (x->props.family == encap_family &&
> > >                   x->props.reqid == tmpl->reqid &&
> > > -                 (mark & x->mark.m) == x->mark.v &&
> > > +                 (pol->mark.v == x->mark.v && pol->mark.m == x->mark.m) &&
> > >                   x->if_id == if_id &&
> > >                   !(x->props.flags & XFRM_STATE_WILDRECV) &&
> > >                   xfrm_state_addr_check(x, daddr, saddr, encap_family) &&
> > > @@ -1082,7 +1091,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
> > >       hlist_for_each_entry_rcu(x, net->xfrm.state_bydst + h_wildcard, bydst) {
> > >               if (x->props.family == encap_family &&
> > >                   x->props.reqid == tmpl->reqid &&
> > > -                 (mark & x->mark.m) == x->mark.v &&
> > > +                 (pol->mark.v == x->mark.v && pol->mark.m == x->mark.m) &&
> > >                   x->if_id == if_id &&
> > >                   !(x->props.flags & XFRM_STATE_WILDRECV) &&
> > >                   xfrm_addr_equal(&x->id.daddr, daddr, encap_family) &&
> >
> > While this should usually not be a problem for strongSwan, as we set the
> > same mark/value on both states and corresponding policies (although the
> > latter can be disabled as users may want to install policies themselves
> > or via another daemon e.g. for MIPv6), it might be a limitation for some
> > use cases.  The current code allows sharing states with multiple
> > policies whose mark/mask doesn't match exactly (i.e. depended on the
> > masks of both).  I wonder if anybody uses it like this, and how others
> > think about it.
> IMHO, the non-exact match "(mark & x->mark.m) == x->mark.v" should be only
> for packet flow. "sharing states with multiple policies" should not be the
> purpose of xfrm_mark. (Add Jamal to the CC list)
> 
> "(((pol->mark.v & pol->mark.m) & x->mark.m) == x->mark.v)" is just strange.
> We could do either:
>  (pol->mark.v == x->mark.v && pol->mark.m == x->mark.m), like this patch.
> Or use fl->flowi_mark in xfrm_state_find():
>  (fl->flowi_mark & x->mark.m) == x->mark.v)
> 
> The 1st one will require userland to configure policy and state with the
> same xfrm_mark, like strongswan.
> 
> The 2nd one will match state with tx packet flow's mark, it's more like
> rx packet flow path.
> 
> But you're right, either of these may cause slight differences, let's see
> how other userland cases use it. (also Add Libreswan's developer, Paul Wouters)

We should care that everything that worked before, will still work after
this change. Otherwise we might break someones usecase, even if the
usecase seems to be odd and nobody complains now.

  reply	other threads:[~2020-07-07  6:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30  6:15 [PATCH ipsec] xfrm: state: match with both mark and mask on user interfaces Xin Long
2020-06-30  9:08 ` Tobias Brunner
2020-07-06  8:33   ` Xin Long
2020-07-07  6:17     ` Steffen Klassert [this message]
2020-07-07  9:09       ` Xin Long
2020-07-07 13:29 ` Dan Carpenter

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=20200707061719.GV19286@gauss3.secunet.de \
    --to=steffen.klassert@secunet.com \
    --cc=davem@davemloft.net \
    --cc=hadi@cyberus.ca \
    --cc=herbert@gondor.apana.org.au \
    --cc=jhs@mojatatu.com \
    --cc=lucien.xin@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pwouters@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=tobias@strongswan.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).