Commit 62503411 authored by Weixing Shi's avatar Weixing Shi Committed by David S. Miller
Browse files

sctp: fix sctp to work with ipv6 source address routing

In the below test case, using the source address routing,
sctp can not work.
1)ifconfig eth0 inet6 add 2001:1::1/64
2)ip -6 rule add from 2001:1::1 table 100 pref 100
3)ip -6 route add 2001:2::1 dev eth0 table 100
4)sctp_darn -H 2001:1::1 -P 250 -l &
1)ifconfig eth0 inet6 add 2001:2::1/64
2)ip -6 rule add from 2001:2::1 table 100 pref 100
3)ip -6 route add 2001:1::1 dev eth0 table 100
4)sctp_darn -H 2001:2::1 -P 250 -h 2001:1::1 -p 250 -s

root cause:
Node-A and Node-B use the source address routing, and
at begining, source address will be NULL,sctp will
search the  routing table by the destination address,
because using the source address routing table, and
the result dst_entry will be NULL.

walk through the bind address list to get the source
address and then lookup the routing table again to get
the correct dst_entry.
Signed-off-by: default avatarWeixing Shi <>
Signed-off-by: default avatarVlad Yasevich <>
Signed-off-by: default avatarWei Yongjun <>
Signed-off-by: default avatarDavid S. Miller <>
parent 66e6961c
......@@ -80,6 +80,9 @@
#include <asm/uaccess.h>
static inline int sctp_v6_addr_match_len(union sctp_addr *s1,
union sctp_addr *s2);
/* Event handler for inet6 address addition/deletion events.
* The sctp_local_addr_list needs to be protocted by a spin lock since
* multiple notifiers (say IPv4 and IPv6) may be running at the same
......@@ -244,8 +247,14 @@ static struct dst_entry *sctp_v6_get_dst(struct sctp_association *asoc,
union sctp_addr *daddr,
union sctp_addr *saddr)
struct dst_entry *dst;
struct dst_entry *dst = NULL;
struct flowi6 fl6;
struct sctp_bind_addr *bp;
struct sctp_sockaddr_entry *laddr;
union sctp_addr *baddr = NULL;
__u8 matchlen = 0;
__u8 bmatchlen;
sctp_scope_t scope;
memset(&fl6, 0, sizeof(fl6));
ipv6_addr_copy(&fl6.daddr, &daddr->v6.sin6_addr);
......@@ -261,6 +270,39 @@ static struct dst_entry *sctp_v6_get_dst(struct sctp_association *asoc,
dst = ip6_route_output(&init_net, NULL, &fl6);
if (!asoc || saddr)
goto out;
if (dst->error) {
dst = NULL;
bp = &asoc->base.bind_addr;
scope = sctp_scope(daddr);
/* Walk through the bind address list and try to get a dst that
* matches a bind address as the source address.
list_for_each_entry_rcu(laddr, &bp->address_list, list) {
if (!laddr->valid)
if ((laddr->state == SCTP_ADDR_SRC) &&
(laddr-> == AF_INET6) &&
(scope <= sctp_scope(&laddr->a))) {
bmatchlen = sctp_v6_addr_match_len(daddr,
if (!baddr || (matchlen < bmatchlen)) {
baddr = &laddr->a;
matchlen = bmatchlen;
if (baddr) {
ipv6_addr_copy(&fl6.saddr, &baddr->v6.sin6_addr);
dst = ip6_route_output(&init_net, NULL, &fl6);
if (!dst->error) {
struct rt6_info *rt;
rt = (struct rt6_info *)dst;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment