Skip to content

Commit

Permalink
[NETNS][IPV6] route6 - pass always a valid socket to ip6_dst_lookup
Browse files Browse the repository at this point in the history
The ip6_dst_lookup receive a socket as parameter. In some part of the code
it is called with a NULL socket parameter. We want to rely on the socket
to retrieve the network namespace, so we always pass a valid socket in all
cases.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: Benjamin Thery <benjamin.thery@bull.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Daniel Lezcano authored and David S. Miller committed Mar 5, 2008
1 parent 4591db4 commit c20121a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions net/ipv6/ip6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ static int ip6_dst_lookup_tail(struct sock *sk,
int err;

if (*dst == NULL)
*dst = ip6_route_output(&init_net, sk, fl);
*dst = ip6_route_output(sk->sk_net, sk, fl);

if ((err = (*dst)->error))
goto out_err_release;
Expand Down Expand Up @@ -954,7 +954,7 @@ static int ip6_dst_lookup_tail(struct sock *sk,
dst_release(*dst);
memcpy(&fl_gw, fl, sizeof(struct flowi));
memset(&fl_gw.fl6_dst, 0, sizeof(struct in6_addr));
*dst = ip6_route_output(&init_net, sk, &fl_gw);
*dst = ip6_route_output(sk->sk_net, sk, &fl_gw);
if ((err = (*dst)->error))
goto out_err_release;
}
Expand Down
9 changes: 6 additions & 3 deletions net/ipv6/tcp_ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,11 @@ static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb)
fl.fl_ip_sport = t1->source;
security_skb_classify_flow(skb, &fl);

/* sk = NULL, but it is safe for now. RST socket required. */
if (!ip6_dst_lookup(NULL, &buff->dst, &fl)) {
/* Pass a socket to ip6_dst_lookup either it is for RST
* Underlying function will use this to retrieve the network
* namespace
*/
if (!ip6_dst_lookup(tcp6_socket->sk, &buff->dst, &fl)) {

if (xfrm_lookup(&buff->dst, &fl, NULL, 0) >= 0) {
ip6_xmit(tcp6_socket->sk, buff, &fl, NULL, 0);
Expand Down Expand Up @@ -1172,7 +1175,7 @@ static void tcp_v6_send_ack(struct tcp_timewait_sock *tw,
fl.fl_ip_sport = t1->source;
security_skb_classify_flow(skb, &fl);

if (!ip6_dst_lookup(NULL, &buff->dst, &fl)) {
if (!ip6_dst_lookup(tcp6_socket->sk, &buff->dst, &fl)) {
if (xfrm_lookup(&buff->dst, &fl, NULL, 0) >= 0) {
ip6_xmit(tcp6_socket->sk, buff, &fl, NULL, 0);
TCP_INC_STATS_BH(TCP_MIB_OUTSEGS);
Expand Down

0 comments on commit c20121a

Please sign in to comment.