Merge branch 'sctp-src-addr'

Marcelo Ricardo Leitner says:

====================
sctp: fix src address selection if using secondary address

This series improves the way SCTP chooses its src address so that the
choosen one will always belong to the interface being used for output.

v1->v2:
 - split out the refactoring from the fix itself
 - Doing a full reverse routing as in v1 is not necessary. Only looking
   for the interface that has the address and comparing its number is
   enough.
====================

Acked-by: Vlad Yasevich <vyasevich@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David S. Miller 2015-07-21 00:20:18 -07:00
commit 57816cbcb8
1 changed files with 26 additions and 14 deletions

View File

@ -487,10 +487,14 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
*/ */
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(laddr, &bp->address_list, list) { list_for_each_entry_rcu(laddr, &bp->address_list, list) {
struct net_device *odev;
if (!laddr->valid) if (!laddr->valid)
continue; continue;
if ((laddr->state == SCTP_ADDR_SRC) && if (laddr->state != SCTP_ADDR_SRC ||
(AF_INET == laddr->a.sa.sa_family)) { AF_INET != laddr->a.sa.sa_family)
continue;
fl4->fl4_sport = laddr->a.v4.sin_port; fl4->fl4_sport = laddr->a.v4.sin_port;
flowi4_update_output(fl4, flowi4_update_output(fl4,
asoc->base.sk->sk_bound_dev_if, asoc->base.sk->sk_bound_dev_if,
@ -499,11 +503,19 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
laddr->a.v4.sin_addr.s_addr); laddr->a.v4.sin_addr.s_addr);
rt = ip_route_output_key(sock_net(sk), fl4); rt = ip_route_output_key(sock_net(sk), fl4);
if (!IS_ERR(rt)) { if (IS_ERR(rt))
continue;
/* Ensure the src address belongs to the output
* interface.
*/
odev = __ip_dev_find(sock_net(sk), laddr->a.v4.sin_addr.s_addr,
false);
if (!odev || odev->ifindex != fl4->flowi4_oif)
continue;
dst = &rt->dst; dst = &rt->dst;
goto out_unlock; break;
}
}
} }
out_unlock: out_unlock: