diff mbox series

[net,2/3] ipv6: Fix tcp socket connection with DSCP.

Message ID f8b69f5aaa0049c2d9d162b1155beab535cdbf04.1675875519.git.gnault@redhat.com (mailing list archive)
State Accepted
Commit 8230680f36fd1525303d1117768c8852314c488c
Delegated to: Netdev Maintainers
Headers show
Series ipv6: Fix socket connection with DSCP fib-rules. | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Guillaume Nault Feb. 8, 2023, 5:14 p.m. UTC
Take into account the IPV6_TCLASS socket option (DSCP) in
tcp_v6_connect(). Otherwise fib6_rule_match() can't properly
match the DSCP value, resulting in invalid route lookup.

For example:

  ip route add unreachable table main 2001:db8::10/124

  ip route add table 100 2001:db8::10/124 dev eth0
  ip -6 rule add dsfield 0x04 table 100

  echo test | socat - TCP6:[2001:db8::11]:54321,ipv6-tclass=0x04

Without this patch, socat fails at connect() time ("No route to host")
because the fib-rule doesn't jump to table 100 and the lookup ends up
being done in the main table.

Fixes: 2cc67cc731d9 ("[IPV6] ROUTE: Routing by Traffic Class.")
Signed-off-by: Guillaume Nault <gnault@redhat.com>
---
 net/ipv6/tcp_ipv6.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Eric Dumazet Feb. 9, 2023, 10:56 a.m. UTC | #1
On Wed, Feb 8, 2023 at 6:14 PM Guillaume Nault <gnault@redhat.com> wrote:
>
> Take into account the IPV6_TCLASS socket option (DSCP) in
> tcp_v6_connect(). Otherwise fib6_rule_match() can't properly
> match the DSCP value, resulting in invalid route lookup.
>
> being done in the main table.
>
> Fixes: 2cc67cc731d9 ("[IPV6] ROUTE: Routing by Traffic Class.")
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> ---

Reviewed-by: Eric Dumazet <edumazet@google.com>

Thanks.
David Ahern Feb. 9, 2023, 3:39 p.m. UTC | #2
On 2/8/23 10:14 AM, Guillaume Nault wrote:
> Take into account the IPV6_TCLASS socket option (DSCP) in
> tcp_v6_connect(). Otherwise fib6_rule_match() can't properly
> match the DSCP value, resulting in invalid route lookup.
> 
> For example:
> 
>   ip route add unreachable table main 2001:db8::10/124
> 
>   ip route add table 100 2001:db8::10/124 dev eth0
>   ip -6 rule add dsfield 0x04 table 100
> 
>   echo test | socat - TCP6:[2001:db8::11]:54321,ipv6-tclass=0x04
> 
> Without this patch, socat fails at connect() time ("No route to host")
> because the fib-rule doesn't jump to table 100 and the lookup ends up
> being done in the main table.
> 
> Fixes: 2cc67cc731d9 ("[IPV6] ROUTE: Routing by Traffic Class.")
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> ---
>  net/ipv6/tcp_ipv6.c | 1 +
>  1 file changed, 1 insertion(+)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>
diff mbox series

Patch

diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 11b736a76bd7..0d25e813288d 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -272,6 +272,7 @@  static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
 	fl6.flowi6_proto = IPPROTO_TCP;
 	fl6.daddr = sk->sk_v6_daddr;
 	fl6.saddr = saddr ? *saddr : np->saddr;
+	fl6.flowlabel = ip6_make_flowinfo(np->tclass, np->flow_label);
 	fl6.flowi6_oif = sk->sk_bound_dev_if;
 	fl6.flowi6_mark = sk->sk_mark;
 	fl6.fl6_dport = usin->sin6_port;