Merge IPv4 and IPv6 versions of get_saddr() with their corresponding get_dst().
Subsystems (3)
PATCH 9/13 Merge IPv4 and IPv6 versions of get_saddr() with their corresponding get_dst().
As the IPv6 route lookup now also returns the selected source address there is no need for a separate source address lookup. In fact, the source address selection needs to be moved to get_dst() because the selected IPv6 source address isn't always stored in the route. Sometimes this makes it impossible to guess the correct address later on.
--- include/net/sctp/structs.h | 7 - net/sctp/ipv6.c | 235 +++++++++++++++++++++++--------------------- net/sctp/protocol.c | 56 ++++------ net/sctp/transport.c | 8 + 4 files changed, 148 insertions(+), 158 deletions(-)
include/net/sctp/structs.h +0 -7
@@ -529,15 +529,8 @@ struct sctp_af {struct dst_entry *(*get_dst) (struct sctp_association *asoc,union sctp_addr *daddr,union sctp_addr *saddr); -void (*get_saddr) (struct sctp_association *asoc, -struct dst_entry *dst, -union sctp_addr *daddr, -union sctp_addr *saddr);void (*copy_addrlist) (struct list_head *,struct net_device *); -void (*dst_saddr) (union sctp_addr *saddr, -struct dst_entry *dst, -unsigned short port);int (*cmp_addr) (const union sctp_addr *addr1,const union sctp_addr *addr2); void (*addr_copy) (union sctp_addr *dst,
net/sctp/ipv6.c +125 -110
274 lines not on this page · raw message
net/sctp/protocol.c +19 -37
120 lines not on this page · raw message
net/sctp/transport.c +4 -4
@@ -232,7 +232,8 @@ void sctp_transport_pmtu(struct sctp_tra {struct dst_entry *dst; - dst = transport->af_specific->get_dst (NULL , &transport->ipaddr,NULL ); + dst = transport->af_specific->get_dst (NULL , &transport->ipaddr, + &transport->saddr);if (dst) { transport->pathmtu =dst_mtu (dst);
@@ -252,12 +253,11 @@ void sctp_transport_route(struct sctp_trunion sctp_addr *daddr = &transport->ipaddr;struct dst_entry *dst; - dst = af->get_dst (asoc, daddr, saddr); -if (saddr)memcpy (&transport->saddr, saddr,sizeof (union sctp_addr ));else - af->get_saddr (asoc, dst, daddr, &transport->saddr); + af->inaddr_any (&transport->saddr, transport->saddr.v4.sin_port); + dst = af->get_dst (asoc, daddr, &transport->saddr); transport->dst = dst;if ((transport->param_flags &SPP_PMTUD_DISABLE ) && transport->pathmtu) {
Signature · 1 line
1.4.2.3
RFC PATCH 9/13 Merge IPv4 and IPv6 versions of get_saddr() with their corresponding get_dst().
Oops, this almost more than any other patch was RFC. Sorry about that!
Regards,
Ville
Quoted 7 lines · Ville Nuorvala
As the IPv6 route lookup now also returns the selected source address there is no need for a separate source address lookup. In fact, the source address selection needs to be moved to
get_dst()because the selected IPv6 source address isn't always stored in the route. Sometimes this makes it impossible to guess the correct address later on.
I remember having to do a separate call to ipv6_get_saddr() specifically because ip6_route_output() didn't fill in the source address. Now if the route lookup also returns the source address, it looks logical to remove the separate source address lookup. So i agree with the idea behind the patch.
I will review the patch in detail and try it out next week to see that it doesn't break SCTP and get back to you.
I guess this is targeted for 2.6.20. Is that right?
Thanks
Sridhar
Quoted 6 lines · Ville Nuorvala
As the IPv6 route lookup now also returns the selected source address there is no need for a separate source address lookup. In fact, the source address selection needs to be moved to
get_dst()because the selected IPv6 source address isn't always stored in the route. Sometimes this makes it impossible to guess the correct address later on.
Ville,
Overall the patch looks pretty good. I found only 1 issue in sctp_v6_get_dst(). See below.
<snip>
Quoted 39 lines
net/sctp/ipv6.c +38
-0+/* Returns the dst cache entry for the given source and destination ip +* addresses. +*/ +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 flowi fl; +struct sctp_bind_addr *bp; +rwlock_t *addr_lock; +struct sctp_sockaddr_entry *laddr; +struct list_head *pos; +struct rt6_info *rt; +union sctp_addr baddr; +sctp_scope_t scope; +__u8 matchlen =0 ; +__u8 bmatchlen; + +memset (&fl,0 ,sizeof (fl)); +ipv6_addr_copy (&fl.fl6_dst, &daddr->v6.sin6_addr); +if (ipv6_addr_type (&daddr->v6.sin6_addr) &IPV6_ADDR_LINKLOCAL ) + fl.oif = daddr->v6.sin6_scope_id; + +ipv6_addr_copy (&fl.fl6_src, &saddr->v6.sin6_addr); +SCTP_DEBUG_PRINTK ("%s: DST=" NIP6_FMT " SRC=" NIP6_FMT " " , + __FUNCTION__,NIP6 (fl.fl6_dst),NIP6 (fl.fl6_src)); + + dst =ip6_route_output (NULL , &fl); +if (dst->error) { +dst_release (dst); + dst =NULL ; + } +if (!ipv6_addr_any (&saddr->v6.sin6_addr)) + goto out; +if (!asoc) { +if (dst) +ipv6_addr_copy (&saddr->v6.sin6_addr, &fl.fl6_src);
net/sctp/ipv6.c static int sctp_v6_cmp_addr(const union · line 426
Quoted 10 lines
net/sctp/ipv6.c +10
-0+ goto out; + } + bp = &asoc->base.bind_addr; + addr_lock = &asoc->base.addr_lock; + +if (dst) { +/* Walk through the bind address list and look for a bind +* address that matches the source address of the returned rt. +*/ +sctp_v6_fl_saddr (&baddr, &fl, bp->port);
Here we are checking if the source address returned in the dst matches one of the address in the bind address list of the association. Not the source address that is passed to this routine(it could be INADDRY_ANY).
So this should be changed back to sctp_v6_dst_saddr().
Thanks
Sridhar
Quoted 71 lines
net/sctp/ipv6.c +71
-0+sctp_read_lock (addr_lock); +list_for_each (pos, &bp->address_list) { + laddr = list_entry(pos, struct sctp_sockaddr_entry, + list); +if (!laddr->use_as_src) +continue ; +if (sctp_v6_cmp_addr (&baddr, &laddr->a)) + goto init_saddr; + } +sctp_read_unlock (addr_lock); + +/* Invalid rt or none of the bound addresses match the source +* address. So release it. +*/ +dst_release (dst); + dst =NULL ; + } + +/* Go through the bind address list and find the best source address +* that matches the scope of the destination address. +*/ +memset (&baddr,0 ,sizeof (union sctp_addr )); + scope =sctp_scope (daddr); +sctp_read_lock (addr_lock); +list_for_each (pos, &bp->address_list) { + laddr = list_entry(pos, struct sctp_sockaddr_entry, list); + +if (!laddr->use_as_src || + laddr->a.sa.sa_family !=AF_INET6 || + scope >sctp_scope (&laddr->a) || + (ipv6_addr_type (&laddr->a.v6.sin6_addr) & +IPV6_ADDR_LINKLOCAL && + laddr->a.v6.sin6_scope_id != fl.oif)) +continue ; + + bmatchlen =sctp_v6_addr_match_len (daddr, &laddr->a); +if (!dst || (matchlen < bmatchlen)) { +struct dst_entry *dst2; +ipv6_addr_copy (&fl.fl6_src, &laddr->a.v6.sin6_addr); + dst2 =ip6_route_output (NULL , &fl); +if (dst2->error) { +dst_release (dst2); + dst2 =NULL ; +continue ; + } +dst_release (dst); + dst = dst2; +memcpy (&baddr, &laddr->a,sizeof (union sctp_addr )); + matchlen = bmatchlen; + } + } +if (dst) + goto init_saddr; +out_unlock: +sctp_read_unlock (addr_lock); +out: +if (dst) { + rt = (struct rt6_info *) dst; +SCTP_DEBUG_PRINTK ("SRC=" NIP6_FMT +" rt6_dst=" NIP6_FMT +" rt6_src=" NIP6_FMT "\n" , +NIP6 (saddr->v6.sin6_addr), +NIP6 (rt->rt6i_dst.addr), +NIP6 (rt->rt6i_src.addr)); + }else +SCTP_DEBUG_PRINTK ("NO ROUTE\n" ); +return dst; +init_saddr: +memcpy (saddr, &baddr,sizeof (union sctp_addr )); + goto out_unlock; +}
Quoted 61 lines · Sridhar Samudrala
Quoted 6 lines · Ville Nuorvala
As the IPv6 route lookup now also returns the selected source address there is no need for a separate source address lookup. In fact, the source address selection needs to be moved to
get_dst()because the selected IPv6 source address isn't always stored in the route. Sometimes this makes it impossible to guess the correct address later on.Ville,
Overall the patch looks pretty good. I found only 1 issue in
sctp_v6_get_dst(). See below.<snip>
Quoted 44 lines
net/sctp/ipv6.c +44
-0+/* Returns the dst cache entry for the given source and destination ip +* addresses. +*/ +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 flowi fl; +struct sctp_bind_addr *bp; +rwlock_t *addr_lock; +struct sctp_sockaddr_entry *laddr; +struct list_head *pos; +struct rt6_info *rt; +union sctp_addr baddr; +sctp_scope_t scope; +__u8 matchlen =0 ; +__u8 bmatchlen; + +memset (&fl,0 ,sizeof (fl)); +ipv6_addr_copy (&fl.fl6_dst, &daddr->v6.sin6_addr); +if (ipv6_addr_type (&daddr->v6.sin6_addr) &IPV6_ADDR_LINKLOCAL ) + fl.oif = daddr->v6.sin6_scope_id; + +ipv6_addr_copy (&fl.fl6_src, &saddr->v6.sin6_addr); +SCTP_DEBUG_PRINTK ("%s: DST=" NIP6_FMT " SRC=" NIP6_FMT " " , + __FUNCTION__,NIP6 (fl.fl6_dst),NIP6 (fl.fl6_src)); + + dst =ip6_route_output (NULL , &fl); +if (dst->error) { +dst_release (dst); + dst =NULL ; + } +if (!ipv6_addr_any (&saddr->v6.sin6_addr)) + goto out; +if (!asoc) { +if (dst) +ipv6_addr_copy (&saddr->v6.sin6_addr, &fl.fl6_src); + goto out; + } + bp = &asoc->base.bind_addr; + addr_lock = &asoc->base.addr_lock; + +if (dst) {
Quoted 8 lines
net/sctp/ipv6.c static int sctp_v6_cmp_addr(const union · line 426
Quoted 4 lines
net/sctp/ipv6.c +4
-0+/* Walk through the bind address list and look for a bind +* address that matches the source address of the returned rt. +*/ +sctp_v6_fl_saddr (&baddr, &fl, bp->port);Here we are checking if the source address returned in the dst matches one of the address in the bind address list of the association. Not the source address that is passed to this
routine(it could be INADDRY_ANY).
So this should be changed back tosctp_v6_dst_saddr().
No, see that's the problem. The source address isn't always stored in the rt6_info. Therefore I copy the address into the flowi, so after ip6_route_output() fl does indeed contain the selected source address. Sorry if I didn't cc you all relevant patches from the patch set.
Anyway there are still some unresolved issues with my code, but it's nice to know I didn't at least mess up SCTP in a big way ;-)
Thanks,
Ville
Quoted 71 lines · Ville Nuorvala
Quoted 61 lines · Sridhar Samudrala
Quoted 6 lines · Ville Nuorvala
As the IPv6 route lookup now also returns the selected source address there is no need for a separate source address lookup. In fact, the source address selection needs to be moved to
get_dst()because the selected IPv6 source address isn't always stored in the route. Sometimes this makes it impossible to guess the correct address later on.Ville,
Overall the patch looks pretty good. I found only 1 issue in
sctp_v6_get_dst(). See below.<snip>
Quoted 44 lines
net/sctp/ipv6.c +44
-0+/* Returns the dst cache entry for the given source and destination ip +* addresses. +*/ +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 flowi fl; +struct sctp_bind_addr *bp; +rwlock_t *addr_lock; +struct sctp_sockaddr_entry *laddr; +struct list_head *pos; +struct rt6_info *rt; +union sctp_addr baddr; +sctp_scope_t scope; +__u8 matchlen =0 ; +__u8 bmatchlen; + +memset (&fl,0 ,sizeof (fl)); +ipv6_addr_copy (&fl.fl6_dst, &daddr->v6.sin6_addr); +if (ipv6_addr_type (&daddr->v6.sin6_addr) &IPV6_ADDR_LINKLOCAL ) + fl.oif = daddr->v6.sin6_scope_id; + +ipv6_addr_copy (&fl.fl6_src, &saddr->v6.sin6_addr); +SCTP_DEBUG_PRINTK ("%s: DST=" NIP6_FMT " SRC=" NIP6_FMT " " , + __FUNCTION__,NIP6 (fl.fl6_dst),NIP6 (fl.fl6_src)); + + dst =ip6_route_output (NULL , &fl); +if (dst->error) { +dst_release (dst); + dst =NULL ; + } +if (!ipv6_addr_any (&saddr->v6.sin6_addr)) + goto out; +if (!asoc) { +if (dst) +ipv6_addr_copy (&saddr->v6.sin6_addr, &fl.fl6_src); + goto out; + } + bp = &asoc->base.bind_addr; + addr_lock = &asoc->base.addr_lock; + +if (dst) {Quoted 8 lines
net/sctp/ipv6.c static int sctp_v6_cmp_addr(const union · line 426
Quoted 4 lines
net/sctp/ipv6.c +4
-0+/* Walk through the bind address list and look for a bind +* address that matches the source address of the returned rt. +*/ +sctp_v6_fl_saddr (&baddr, &fl, bp->port);Here we are checking if the source address returned in the dst matches one of the address in the bind address list of the association. Not the source address that is passed to this
routine(it could be INADDRY_ANY).
So this should be changed back tosctp_v6_dst_saddr().
Quoted 4 lines
No, see that's the problem. The source address isn't always stored in the
rt6_info. Therefore I copy the address into the flowi, so afterip6_route_output()fl does indeed contain the selected source address. Sorry if I didn't cc you all relevant patches from the patch set.
When you said that IPV6 route lookup returns the selected source address, i assumed it will be returned via rt6_info->rt6i_src. But looks like it is returned in fl->fl6_src. If so, there is no problem. Why is rt6i_src not filled in some cases?
I noticed this problem when i ran SCTP frametests that use a IP simulator in userspace. We have our own ip6_route_output that i modified to set source in rt6_info and not fl.
Thanks
Sridhar
Quoted 6 lines
Anyway there are still some unresolved issues with my code, but it's nice to know I didn't at least mess up SCTP in a big way ;-)
Thanks,
Ville