Skip to content

Commit f51ffde

Browse files
committed
Merge branch 'ipv6-udp-set-dst-cache-for-a-connected-sk-if-current-not-valid'
Alexey Kodanev says: ==================== ipv6: udp: set dst cache for a connected sk if current not valid A new RTF_CACHE route can be created with the socket's dst cache update between the below calls in udpv6_sendmsg(), when datagram sending results to ICMPV6_PKT_TOOBIG error: dst = ip6_sk_dst_lookup_flow(...) ... release_dst: if (dst) { if (connected) { ip6_dst_store(sk, dst) Therefore, the new socket's dst cache reset to the old one on "release_dst:". The first three patches prepare the code to store dst cache with ip6_sk_dst_lookup_flow(): * the first patch adds ip6_sk_dst_store_flow() function with commonly used source and destiantion addresses checks using the flow information. * the second patch adds a new argument to ip6_sk_dst_lookup_flow() and ability to store dst in the socket's cache. Also, the two users of the function are updated without enabling the new behavior: pingv6_sendmsg() and udpv6_sendmsg(). * the third patch makes 'connected' variable in udpv6_sendmsg() to be consistent with ip6_sk_dst_store_flow(), changes its type from int to bool. The last patch contains the actual fix that removes sk dst cache update in the end of udpv6_sendmsg(), and allows to do it in ip6_sk_dst_lookup_flow(). v6: * use bool type for a new parameter in ip_sk_dst_lookup_flow() * add one more patch to convert 'connected' variable in udpv6_sendmsg() from int to bool type. If it shouldn't be here I will resend it when the net-next is opened. v5: * relocate ip6_sk_dst_store_flow() to net/ipv6/route.c and rename ip6_dst_store_flow() to ip6_sk_dst_store_flow() as suggested by Martin v4: * fix the error in the build of ip_dst_store_flow() reported by kbuild test robot due to missing checks for CONFIG_IPV6: add new function to ip6_output.c instead of ip6_route.h * add 'const' to struct flowi6 in ip6_dst_store_flow() * minor commit messages fixes v3: * instead of moving ip6_dst_store() above udp_v6_send_skb(), update socket's dst cache inside ip6_sk_dst_lookup_flow() if the current one is invalid * the issue not reproduced in 4.1, but starting from 4.2. Add one more 'Fixes:' commit that creates new RTF_CACHE route. Though, it is also mentioned in the first one ==================== Acked-by: Martin KaFai Lau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2 parents 0d3ad85 + 4f858c5 commit f51ffde

File tree

7 files changed

+43
-37
lines changed

7 files changed

+43
-37
lines changed

include/net/ip6_route.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
214214
#endif
215215
}
216216

217+
void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst,
218+
const struct flowi6 *fl6);
219+
217220
static inline bool ipv6_unicast_destination(const struct sk_buff *skb)
218221
{
219222
struct rt6_info *rt = (struct rt6_info *) skb_dst(skb);

include/net/ipv6.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@ int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
965965
struct dst_entry *ip6_dst_lookup_flow(const struct sock *sk, struct flowi6 *fl6,
966966
const struct in6_addr *final_dst);
967967
struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
968-
const struct in6_addr *final_dst);
968+
const struct in6_addr *final_dst,
969+
bool connected);
969970
struct dst_entry *ip6_blackhole_route(struct net *net,
970971
struct dst_entry *orig_dst);
971972

net/ipv6/datagram.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,7 @@ int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr)
106106
}
107107
}
108108

109-
ip6_dst_store(sk, dst,
110-
ipv6_addr_equal(&fl6.daddr, &sk->sk_v6_daddr) ?
111-
&sk->sk_v6_daddr : NULL,
112-
#ifdef CONFIG_IPV6_SUBTREES
113-
ipv6_addr_equal(&fl6.saddr, &np->saddr) ?
114-
&np->saddr :
115-
#endif
116-
NULL);
109+
ip6_sk_dst_store_flow(sk, dst, &fl6);
117110

118111
out:
119112
fl6_sock_release(flowlabel);

net/ipv6/ip6_output.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,23 +1105,32 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);
11051105
* @sk: socket which provides the dst cache and route info
11061106
* @fl6: flow to lookup
11071107
* @final_dst: final destination address for ipsec lookup
1108+
* @connected: whether @sk is connected or not
11081109
*
11091110
* This function performs a route lookup on the given flow with the
11101111
* possibility of using the cached route in the socket if it is valid.
11111112
* It will take the socket dst lock when operating on the dst cache.
11121113
* As a result, this function can only be used in process context.
11131114
*
1115+
* In addition, for a connected socket, cache the dst in the socket
1116+
* if the current cache is not valid.
1117+
*
11141118
* It returns a valid dst pointer on success, or a pointer encoded
11151119
* error code.
11161120
*/
11171121
struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
1118-
const struct in6_addr *final_dst)
1122+
const struct in6_addr *final_dst,
1123+
bool connected)
11191124
{
11201125
struct dst_entry *dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie);
11211126

11221127
dst = ip6_sk_dst_check(sk, dst, fl6);
1123-
if (!dst)
1124-
dst = ip6_dst_lookup_flow(sk, fl6, final_dst);
1128+
if (dst)
1129+
return dst;
1130+
1131+
dst = ip6_dst_lookup_flow(sk, fl6, final_dst);
1132+
if (connected && !IS_ERR(dst))
1133+
ip6_sk_dst_store_flow(sk, dst_clone(dst), fl6);
11251134

11261135
return dst;
11271136
}

net/ipv6/ping.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
121121
ipc6.tclass = np->tclass;
122122
fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel);
123123

124-
dst = ip6_sk_dst_lookup_flow(sk, &fl6, daddr);
124+
dst = ip6_sk_dst_lookup_flow(sk, &fl6, daddr, false);
125125
if (IS_ERR(dst))
126126
return PTR_ERR(dst);
127127
rt = (struct rt6_info *) dst;

net/ipv6/route.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,6 +2229,23 @@ void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, __be32 mtu)
22292229
}
22302230
EXPORT_SYMBOL_GPL(ip6_sk_update_pmtu);
22312231

2232+
void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst,
2233+
const struct flowi6 *fl6)
2234+
{
2235+
#ifdef CONFIG_IPV6_SUBTREES
2236+
struct ipv6_pinfo *np = inet6_sk(sk);
2237+
#endif
2238+
2239+
ip6_dst_store(sk, dst,
2240+
ipv6_addr_equal(&fl6->daddr, &sk->sk_v6_daddr) ?
2241+
&sk->sk_v6_daddr : NULL,
2242+
#ifdef CONFIG_IPV6_SUBTREES
2243+
ipv6_addr_equal(&fl6->saddr, &np->saddr) ?
2244+
&np->saddr :
2245+
#endif
2246+
NULL);
2247+
}
2248+
22322249
/* Handle redirects */
22332250
struct ip6rd_flowi {
22342251
struct flowi6 fl6;

net/ipv6/udp.c

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,10 +1116,10 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
11161116
struct dst_entry *dst;
11171117
struct ipcm6_cookie ipc6;
11181118
int addr_len = msg->msg_namelen;
1119+
bool connected = false;
11191120
int ulen = len;
11201121
int corkreq = up->corkflag || msg->msg_flags&MSG_MORE;
11211122
int err;
1122-
int connected = 0;
11231123
int is_udplite = IS_UDPLITE(sk);
11241124
int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);
11251125
struct sockcm_cookie sockc;
@@ -1241,7 +1241,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
12411241
fl6.fl6_dport = inet->inet_dport;
12421242
daddr = &sk->sk_v6_daddr;
12431243
fl6.flowlabel = np->flow_label;
1244-
connected = 1;
1244+
connected = true;
12451245
}
12461246

12471247
if (!fl6.flowi6_oif)
@@ -1271,7 +1271,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
12711271
}
12721272
if (!(opt->opt_nflen|opt->opt_flen))
12731273
opt = NULL;
1274-
connected = 0;
1274+
connected = false;
12751275
}
12761276
if (!opt) {
12771277
opt = txopt_get(np);
@@ -1293,11 +1293,11 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
12931293

12941294
final_p = fl6_update_dst(&fl6, opt, &final);
12951295
if (final_p)
1296-
connected = 0;
1296+
connected = false;
12971297

12981298
if (!fl6.flowi6_oif && ipv6_addr_is_multicast(&fl6.daddr)) {
12991299
fl6.flowi6_oif = np->mcast_oif;
1300-
connected = 0;
1300+
connected = false;
13011301
} else if (!fl6.flowi6_oif)
13021302
fl6.flowi6_oif = np->ucast_oif;
13031303

@@ -1308,7 +1308,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
13081308

13091309
fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel);
13101310

1311-
dst = ip6_sk_dst_lookup_flow(sk, &fl6, final_p);
1311+
dst = ip6_sk_dst_lookup_flow(sk, &fl6, final_p, connected);
13121312
if (IS_ERR(dst)) {
13131313
err = PTR_ERR(dst);
13141314
dst = NULL;
@@ -1333,7 +1333,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
13331333
err = PTR_ERR(skb);
13341334
if (!IS_ERR_OR_NULL(skb))
13351335
err = udp_v6_send_skb(skb, &fl6);
1336-
goto release_dst;
1336+
goto out;
13371337
}
13381338

13391339
lock_sock(sk);
@@ -1367,23 +1367,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
13671367
err = np->recverr ? net_xmit_errno(err) : 0;
13681368
release_sock(sk);
13691369

1370-
release_dst:
1371-
if (dst) {
1372-
if (connected) {
1373-
ip6_dst_store(sk, dst,
1374-
ipv6_addr_equal(&fl6.daddr, &sk->sk_v6_daddr) ?
1375-
&sk->sk_v6_daddr : NULL,
1376-
#ifdef CONFIG_IPV6_SUBTREES
1377-
ipv6_addr_equal(&fl6.saddr, &np->saddr) ?
1378-
&np->saddr :
1379-
#endif
1380-
NULL);
1381-
} else {
1382-
dst_release(dst);
1383-
}
1384-
dst = NULL;
1385-
}
1386-
13871370
out:
13881371
dst_release(dst);
13891372
fl6_sock_release(flowlabel);

0 commit comments

Comments
 (0)