[net,v4] ipv6: fib6_rules: flush route cache when rule is changed

Message ID 09f2ab1b7946339da5092e10aa216e07c579c60b.camel@mediatek.com
State New
Headers
Series [net,v4] ipv6: fib6_rules: flush route cache when rule is changed |

Commit Message

Lena Wang (王娜) March 1, 2024, 2:39 p.m. UTC
  From: Shiming Cheng <shiming.cheng@mediatek.com>

When rule policy is changed, ipv6 socket cache is not refreshed.
The sock's skb still uses a outdated route cache and was sent to
a wrong interface.

To avoid this error we should update fib node's version when
rule is changed. Then skb's route will be reroute checked as
route cache version is already different with fib node version.
The route cache is refreshed to match the latest rule.

Fixes: 101367c2f8c4 ("[IPV6]: Policy Routing Rules")
Signed-off-by: Shiming Cheng <shiming.cheng@mediatek.com>
Signed-off-by: Lena Wang <lena.wang@mediatek.com>
---
v4: 
  - add "Fixes:" tag.
  - update subject as requested. 
v3: 
  - update patch description and name format in commit message.
v2: 
  - modify flush function same way as ipv4 flush cache.
  - use tabs to aligh with existing code.
---
---
 net/ipv6/fib6_rules.c | 6 ++++++
 1 file changed, 6 insertions(+)

 	.family			= AF_INET6,
 	.rule_size		= sizeof(struct fib6_rule),
@@ -461,6 +466,7 @@ static const struct fib_rules_ops __net_initconst
fib6_rules_ops_template = {
 	.compare		= fib6_rule_compare,
 	.fill			= fib6_rule_fill,
 	.nlmsg_payload		= fib6_rule_nlmsg_payload,
+	.flush_cache		= fib6_rule_flush_cache,
 	.nlgroup		= RTNLGRP_IPV6_RULE,
 	.owner			= THIS_MODULE,
 	.fro_net		= &init_net,
-- 
2.18.0
  

Comments

David Ahern March 1, 2024, 3:27 p.m. UTC | #1
On 3/1/24 7:39 AM, Lena Wang (王娜) wrote:
> From: Shiming Cheng <shiming.cheng@mediatek.com>
> 
> When rule policy is changed, ipv6 socket cache is not refreshed.
> The sock's skb still uses a outdated route cache and was sent to
> a wrong interface.
> 
> To avoid this error we should update fib node's version when
> rule is changed. Then skb's route will be reroute checked as
> route cache version is already different with fib node version.
> The route cache is refreshed to match the latest rule.
> 
> Fixes: 101367c2f8c4 ("[IPV6]: Policy Routing Rules")
> Signed-off-by: Shiming Cheng <shiming.cheng@mediatek.com>
> Signed-off-by: Lena Wang <lena.wang@mediatek.com>
> ---
> v4: 
>   - add "Fixes:" tag.
>   - update subject as requested. 
> v3: 
>   - update patch description and name format in commit message.
> v2: 
>   - modify flush function same way as ipv4 flush cache.
>   - use tabs to aligh with existing code.
> ---
> ---
>  net/ipv6/fib6_rules.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>
  
Jiri Pirko March 1, 2024, 3:28 p.m. UTC | #2
Fri, Mar 01, 2024 at 03:39:46PM CET, Lena.Wang@mediatek.com wrote:
>From: Shiming Cheng <shiming.cheng@mediatek.com>
>
>When rule policy is changed, ipv6 socket cache is not refreshed.
>The sock's skb still uses a outdated route cache and was sent to
>a wrong interface.
>
>To avoid this error we should update fib node's version when
>rule is changed. Then skb's route will be reroute checked as
>route cache version is already different with fib node version.
>The route cache is refreshed to match the latest rule.
>
>Fixes: 101367c2f8c4 ("[IPV6]: Policy Routing Rules")
>Signed-off-by: Shiming Cheng <shiming.cheng@mediatek.com>
>Signed-off-by: Lena Wang <lena.wang@mediatek.com>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
  

Patch

diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c
index 7523c4baef35..52c04f0ac498 100644
--- a/net/ipv6/fib6_rules.c
+++ b/net/ipv6/fib6_rules.c
@@ -449,6 +449,11 @@  static size_t fib6_rule_nlmsg_payload(struct
fib_rule *rule)
 	       + nla_total_size(16); /* src */
 }
 
+static void fib6_rule_flush_cache(struct fib_rules_ops *ops)
+{
+	rt_genid_bump_ipv6(ops->fro_net);
+}
+
 static const struct fib_rules_ops __net_initconst
fib6_rules_ops_template = {