Skip to contentSkip to conversation

net: ipmr_base: Check iif when returning a (*, G) MFC

PATCH In review Yang Sun 3 participants 6 messages Oct 31, 2023 – Nov 3, 2023 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Yang Sun

author
#0 lore raw

PATCH 1/1 net: ipmr_base: Check iif when returning a (*, G) MFC

Looking for a (*, G) MFC returns the first match without checking the iif. This can return a MFC not intended for a packet's iif and forwarding the packet with this MFC will not work correctly.

When looking up for a (*, G) MFC, check that the MFC's iif is the same as the packet's iif.

---
 net/ipv4/ipmr_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/ipmr_base.c +1 -1
index 271dc03fc6db..5cf7c7088dfe 100644
@@ -97,7 +97,7 @@ void *mr_mfc_find_any(struct mr_table *mrt, int vifi, void *hasharg)
 
 	list = rhltable_lookup(&mrt->mfc_hash, hasharg, *mrt->ops.rht_params);
 	rhl_for_each_entry_rcu(c, tmp, list, mnode) {
-		if (c->mfc_un.res.ttls[vifi] < 255)
+		if (c->mfc_parent == vifi && c->mfc_un.res.ttls[vifi] < 255)
 			return c;
 
 		/* It's ok if the vifi is part of the static tree */
Signature · 1 line
2.42.0.820.g83a721a137-goog
#1 lore raw

+ Nicolas

Quoted 6 lines · Yang Sun

Looking for a (*, G) MFC returns the first match without checking the iif. This can return a MFC not intended for a packet's iif and forwarding the packet with this MFC will not work correctly.

When looking up for a (*, G) MFC, check that the MFC's iif is the same as the packet's iif.

Is this a regression (doesn't seem that way)? If not, the change should be targeted at net-next which is closed right now:

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

Quoted 11 lines
---
 net/ipv4/ipmr_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/ipmr_base.c +0 -0
index 271dc03fc6db..5cf7c7088dfe 100644

net/ipv4/ipmr_base.c void *mr_mfc_find_any(struct mr_table *mrt, int vifi, void *hasharg) · line 100

Quoted 5 lines
net/ipv4/ipmr_base.c +1 -1
@@ -97,7 +97,7 @@ void *mr_mfc_find_any(struct mr_table *mrt, int vifi, void *hasharg)
 
 	list = rhltable_lookup(&mrt->mfc_hash, hasharg, *mrt->ops.rht_params);
 	rhl_for_each_entry_rcu(c, tmp, list, mnode) {
-		if (c->mfc_un.res.ttls[vifi] < 255)
+		if (c->mfc_parent == vifi && c->mfc_un.res.ttls[vifi] < 255)

What happens if the route doesn't have an iif (-1)? It won't match anymore?

Quoted 7 lines
net/ipv4/ipmr_base.c +0 -0
 			return c;
 
 		/* It's ok if the vifi is part of the static tree */
Signature · 1 line
2.42.0.820.g83a721a137-goog
author
#2 lore raw
Quoted 4 lines

Is this a regression (doesn't seem that way)? If not, the change should be targeted at net-next which is closed right now:

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

I see.

Quoted 5 lines
Quoted 2 lines

- if (c->mfc_un.res.ttls[vifi] < 255)
+ if (c->mfc_parent == vifi && c->mfc_un.res.ttls[vifi] < 255)

What happens if the route doesn't have an iif (-1)? It won't match anymore?

Looks like the mfc_parent can't be -1? There is the check:

    if (mfc->mf6cc_parent >= MAXMIFS)
        return -ENFILE;
before setting the parent:
    c->_c.mfc_parent = mfc->mf6cc_parent;

I wrote this patch thinking (*, G) MFCs could be per iif, similar to the (S, G) MFCs, like we can add the following MFCs to forward packets from any address with group destination ff05::aa from if1 to if2, and forward packets from any address with group destination ff05::aa from if2 to both if1 and if3.

(::, ff05::aa) Iif: if1 Oifs: if1 if2 State: resolved
(::, ff05::aa) Iif: if2 Oifs: if1 if2 if3 State: resolved

But reading Nicolas's initial commit message again, it seems to me that (*, G) has to be used together with (*, *) and there should be only one (*, G) entry per group address and include all relevant interfaces in the oifs? Like the following:

(::, ::)         Iif: if1 Oifs: if1 if2 if3   State: resolved
(::, ff05::aa)   Iif: if1 Oifs: if1 if2 if3   State: resolved

Is this how the (*, *|G) MFCs are intended to be used? which means packets to ff05::aa are forwarded from any one of the interfaces to all the other interfaces? If this is the intended way it works then my patch would break things and should be rejected.

Is there a way to achieve the use case I described above? Like having different oifs for different iif?

Thanks!

Quoted 43 lines · Ido Schimmel

+ Nicolas

Quoted 6 lines · Yang Sun

Looking for a (*, G) MFC returns the first match without checking the iif. This can return a MFC not intended for a packet's iif and forwarding the packet with this MFC will not work correctly.

When looking up for a (*, G) MFC, check that the MFC's iif is the same as the packet's iif.

Is this a regression (doesn't seem that way)? If not, the change should be targeted at net-next which is closed right now:

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

Quoted 11 lines
---
 net/ipv4/ipmr_base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/ipmr_base.c +0 -0
index 271dc03fc6db..5cf7c7088dfe 100644

net/ipv4/ipmr_base.c void *mr_mfc_find_any(struct mr_table *mrt, int vifi, void *hasharg) · line 100

Quoted 5 lines
net/ipv4/ipmr_base.c +1 -1
@@ -97,7 +97,7 @@ void *mr_mfc_find_any(struct mr_table *mrt, int vifi, void *hasharg)
 
      list = rhltable_lookup(&mrt->mfc_hash, hasharg, *mrt->ops.rht_params);
      rhl_for_each_entry_rcu(c, tmp, list, mnode) {
-             if (c->mfc_un.res.ttls[vifi] < 255)
+             if (c->mfc_parent == vifi && c->mfc_un.res.ttls[vifi] < 255)

What happens if the route doesn't have an iif (-1)? It won't match anymore?

Quoted 7 lines
net/ipv4/ipmr_base.c +0 -1
                      return c;
 
              /* It's ok if the vifi is part of the static tree */
--

2.42.0.820.g83a721a137-goog

A message that is not in the archive (sent off-list or not yet received): CAF+qgb4gW8vBb8c2xDHfsXsm1-O2KCwXMCTUcT2mYqED51fHoQ@mail.gmail.com

#4 lore raw

Le 02/11/2023 à 12:48, Yang Sun a écrit :

Quoted 33 lines
Quoted 4 lines

Is this a regression (doesn't seem that way)? If not, the change should be targeted at net-next which is closed right now:

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

I see.

Quoted 5 lines
Quoted 2 lines

- if (c->mfc_un.res.ttls[vifi] < 255)
+ if (c->mfc_parent == vifi && c->mfc_un.res.ttls[vifi] < 255)

What happens if the route doesn't have an iif (-1)? It won't match anymore?

Looks like the mfc_parent can't be -1? There is the check:

    if (mfc->mf6cc_parent >= MAXMIFS)
        return -ENFILE;
before setting the parent:
    c->_c.mfc_parent = mfc->mf6cc_parent;

I wrote this patch thinking (*, G) MFCs could be per iif, similar to the (S, G) MFCs, like we can add the following MFCs to forward packets from any address with group destination ff05::aa from if1 to if2, and forward packets from any address with group destination ff05::aa from if2 to both if1 and if3.

(::, ff05::aa) Iif: if1 Oifs: if1 if2 State: resolved
(::, ff05::aa) Iif: if2 Oifs: if1 if2 if3 State: resolved

But reading Nicolas's initial commit message again, it seems to me that (*, G) has to be used together with (*, *) and there should be only one (*, G) entry per group address and include all relevant interfaces in the oifs? Like the following:

Quoted 7 lines
(::, ::)         Iif: if1 Oifs: if1 if2 if3   State: resolved
(::, ff05::aa)   Iif: if1 Oifs: if1 if2 if3   State: resolved

Is this how the (*, *|G) MFCs are intended to be used? which means packets to ff05::aa are forwarded from any one of the interfaces to all the other interfaces? If this is the intended way it works then my patch would break things and should be rejected.

Yes, this was the intend. Only one (*, G) entry was expected (per G).

Quoted 3 lines

Is there a way to achieve the use case I described above? Like having different oifs for different iif?

Instead of being too strict, maybe you could try to return the 'best' entry.

#1 (::, ff05::aa) Iif: if1 Oifs: if1 if2 State: resolved
#2 (::, ff05::aa) Iif: if2 Oifs: if1 if2 if3 State: resolved

If a packet comes from if2, returns #2, but if a packet comes from if3, returns the first matching entry, ie #1 here.

Regards,
Nicolas

author
#5 lore raw
Quoted 47 lines · Nicolas Dichtel
Quoted 33 lines · Yang Sun
Quoted 4 lines

Is this a regression (doesn't seem that way)? If not, the change should be targeted at net-next which is closed right now:

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

I see.

Quoted 5 lines
Quoted 2 lines

- if (c->mfc_un.res.ttls[vifi] < 255)
+ if (c->mfc_parent == vifi && c->mfc_un.res.ttls[vifi] < 255)

What happens if the route doesn't have an iif (-1)? It won't match anymore?

Looks like the mfc_parent can't be -1? There is the check:

    if (mfc->mf6cc_parent >= MAXMIFS)
        return -ENFILE;
before setting the parent:
    c->_c.mfc_parent = mfc->mf6cc_parent;

I wrote this patch thinking (*, G) MFCs could be per iif, similar to the (S, G) MFCs, like we can add the following MFCs to forward packets from any address with group destination ff05::aa from if1 to if2, and forward packets from any address with group destination ff05::aa from if2 to both if1 and if3.

(::, ff05::aa) Iif: if1 Oifs: if1 if2 State: resolved
(::, ff05::aa) Iif: if2 Oifs: if1 if2 if3 State: resolved

But reading Nicolas's initial commit message again, it seems to me that (*, G) has to be used together with (*, *) and there should be only one (*, G) entry per group address and include all relevant interfaces in the oifs? Like the following:

Quoted 7 lines
(::, ::)         Iif: if1 Oifs: if1 if2 if3   State: resolved
(::, ff05::aa)   Iif: if1 Oifs: if1 if2 if3   State: resolved

Is this how the (*, *|G) MFCs are intended to be used? which means packets to ff05::aa are forwarded from any one of the interfaces to all the other interfaces? If this is the intended way it works then my patch would break things and should be rejected.

Yes, this was the intend. Only one (*, G) entry was expected (per G).

Quoted 3 lines

Is there a way to achieve the use case I described above? Like having different oifs for different iif?

Quoted 8 lines

Instead of being too strict, maybe you could try to return the 'best' entry.

#1 (::, ff05::aa) Iif: if1 Oifs: if1 if2 State: resolved
#2 (::, ff05::aa) Iif: if2 Oifs: if1 if2 if3 State: resolved

If a packet comes from if2, returns #2, but if a packet comes from if3, returns the first matching entry, ie #1 here.

Thanks for your reply Nicolas!
Here if it returns the first matching then it depends on which entry is returned first
by the hash table lookup, the forwarding behavior may be indeterminate in that case
it seems.

If a packet has no matching (*, G) entry, then it will use the (*, *) entry to be forwarded
to the upstream interface in (*, *). And with the (*, *) it means we won't get any nocache upcall
for interfaces included in the static tree, right? So the (S, G) MFC and the static proxy MFCs
are not meant to be used together?

I wonder how a real use case with (*, G|*) would look like, what interface could be an
upstream interface. Is there an example?

Thanks,
Yang

Quoted 3 lines

Regards,
Nicolas

#6 lore raw

Le 03/11/2023 à 12:05, Yang Sun a écrit :

Quoted 58 lines
Quoted 47 lines · Nicolas Dichtel
Quoted 33 lines · Yang Sun
Quoted 4 lines

Is this a regression (doesn't seem that way)? If not, the change should be targeted at net-next which is closed right now:

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

I see.

Quoted 5 lines
Quoted 2 lines

- if (c->mfc_un.res.ttls[vifi] < 255)
+ if (c->mfc_parent == vifi && c->mfc_un.res.ttls[vifi] < 255)

What happens if the route doesn't have an iif (-1)? It won't match anymore?

Looks like the mfc_parent can't be -1? There is the check:

    if (mfc->mf6cc_parent >= MAXMIFS)
        return -ENFILE;
before setting the parent:
    c->_c.mfc_parent = mfc->mf6cc_parent;

I wrote this patch thinking (*, G) MFCs could be per iif, similar to the (S, G) MFCs, like we can add the following MFCs to forward packets from any address with group destination ff05::aa from if1 to if2, and forward packets from any address with group destination ff05::aa from if2 to both if1 and if3.

(::, ff05::aa) Iif: if1 Oifs: if1 if2 State: resolved
(::, ff05::aa) Iif: if2 Oifs: if1 if2 if3 State: resolved

But reading Nicolas's initial commit message again, it seems to me that (*, G) has to be used together with (*, *) and there should be only one (*, G) entry per group address and include all relevant interfaces in the oifs? Like the following:

Quoted 7 lines
(::, ::)         Iif: if1 Oifs: if1 if2 if3   State: resolved
(::, ff05::aa)   Iif: if1 Oifs: if1 if2 if3   State: resolved

Is this how the (*, *|G) MFCs are intended to be used? which means packets to ff05::aa are forwarded from any one of the interfaces to all the other interfaces? If this is the intended way it works then my patch would break things and should be rejected.

Yes, this was the intend. Only one (*, G) entry was expected (per G).

Quoted 3 lines

Is there a way to achieve the use case I described above? Like having different oifs for different iif?

Quoted 8 lines

Instead of being too strict, maybe you could try to return the 'best' entry.

#1 (::, ff05::aa) Iif: if1 Oifs: if1 if2 State: resolved
#2 (::, ff05::aa) Iif: if2 Oifs: if1 if2 if3 State: resolved

If a packet comes from if2, returns #2, but if a packet comes from if3, returns the first matching entry, ie #1 here.

Quoted 6 lines

Thanks for your reply Nicolas!
Here if it returns the first matching then it depends on which entry is returned first
by the hash table lookup, the forwarding behavior may be indeterminate in that case
it seems.

As I said, only one (*,G) entry was expected thus the 'first' one is indeterminate if there are several entries.

Quoted 8 lines

If a packet has no matching (*, G) entry, then it will use the (*, *) entry to be forwarded
to the upstream interface in (*, *). And with the (*, *) it means we won't get any nocache upcall
for interfaces included in the static tree, right? So the (S, G) MFC and the static proxy MFCs
are not meant to be used together?

Not together. With proxy multicast, the multicast tree is static, ie there is no multicast daemon. Mcast packets received from one interface are sent to the other interfaces that are part of the tree.

Regards,
Nicolas

Quoted 11 lines

I wonder how a real use case with (*, G|*) would look like, what interface could be an
upstream interface. Is there an example?

Thanks,
Yang

Quoted 3 lines

Regards,
Nicolas