aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2015-09-25 16:00:40 -0400
committerDavid S. Miller <davem@davemloft.net>2015-09-25 16:00:40 -0400
commit4d54d86546f62c7c4a0fe3b36a64c5e3b98ce1a9 (patch)
treebd48e072bacebb47bc6cd4ebb3483e9bd9da21b0
parent6ea29da1d04f56e167ec8cc5ed15e927997d9d67 (diff)
parent1b70e977cef6ce7e7411c9bbec21f9adc8e29097 (diff)
Merge branch 'listener-sock-const'
Eric Dumazet says: ==================== dccp/tcp: constify listener sock Another patch bomb to prepare lockless TCP/DCCP LISTEN handling. SYNACK retransmits are built and sent without listener socket being locked. Soon, initial SYNACK packets will have same property. This series makes sure we did not something wrong with this model, by adding a const qualifier in all the paths taken from synack building and transmit, for IPv4/IPv6 and TCP/dccp. The only potential problem was the rewrite of ecn bits for connections with DCTCP as congestion module, but this was a very minor one. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/dst.h9
-rw-r--r--include/net/inet6_connection_sock.h2
-rw-r--r--include/net/inet_connection_sock.h2
-rw-r--r--include/net/ip.h10
-rw-r--r--include/net/ipv6.h4
-rw-r--r--include/net/request_sock.h4
-rw-r--r--include/net/route.h2
-rw-r--r--include/net/tcp.h22
-rw-r--r--net/dccp/dccp.h2
-rw-r--r--net/dccp/ipv4.c2
-rw-r--r--net/dccp/ipv6.c2
-rw-r--r--net/dccp/output.c17
-rw-r--r--net/ipv4/inet_connection_sock.c4
-rw-r--r--net/ipv4/ip_output.c14
-rw-r--r--net/ipv4/route.c2
-rw-r--r--net/ipv4/tcp_cong.c12
-rw-r--r--net/ipv4/tcp_ipv4.c11
-rw-r--r--net/ipv4/tcp_minisocks.c28
-rw-r--r--net/ipv4/tcp_output.c51
-rw-r--r--net/ipv6/datagram.c2
-rw-r--r--net/ipv6/inet6_connection_sock.c2
-rw-r--r--net/ipv6/ip6_output.c30
-rw-r--r--net/ipv6/tcp_ipv6.c15
-rw-r--r--net/xfrm/xfrm_policy.c6
24 files changed, 149 insertions, 106 deletions
diff --git a/include/net/dst.h b/include/net/dst.h
index df0481a07029..779206c15f8b 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -489,7 +489,8 @@ struct flowi;
489#ifndef CONFIG_XFRM 489#ifndef CONFIG_XFRM
490static inline struct dst_entry *xfrm_lookup(struct net *net, 490static inline struct dst_entry *xfrm_lookup(struct net *net,
491 struct dst_entry *dst_orig, 491 struct dst_entry *dst_orig,
492 const struct flowi *fl, struct sock *sk, 492 const struct flowi *fl,
493 const struct sock *sk,
493 int flags) 494 int flags)
494{ 495{
495 return dst_orig; 496 return dst_orig;
@@ -498,7 +499,7 @@ static inline struct dst_entry *xfrm_lookup(struct net *net,
498static inline struct dst_entry *xfrm_lookup_route(struct net *net, 499static inline struct dst_entry *xfrm_lookup_route(struct net *net,
499 struct dst_entry *dst_orig, 500 struct dst_entry *dst_orig,
500 const struct flowi *fl, 501 const struct flowi *fl,
501 struct sock *sk, 502 const struct sock *sk,
502 int flags) 503 int flags)
503{ 504{
504 return dst_orig; 505 return dst_orig;
@@ -511,11 +512,11 @@ static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
511 512
512#else 513#else
513struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig, 514struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
514 const struct flowi *fl, struct sock *sk, 515 const struct flowi *fl, const struct sock *sk,
515 int flags); 516 int flags);
516 517
517struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig, 518struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig,
518 const struct flowi *fl, struct sock *sk, 519 const struct flowi *fl, const struct sock *sk,
519 int flags); 520 int flags);
520 521
521/* skb attached with this dst needs transformation if dst->xfrm is valid */ 522/* skb attached with this dst needs transformation if dst->xfrm is valid */
diff --git a/include/net/inet6_connection_sock.h b/include/net/inet6_connection_sock.h
index 6d539e4e5ba7..81d937e820c4 100644
--- a/include/net/inet6_connection_sock.h
+++ b/include/net/inet6_connection_sock.h
@@ -25,7 +25,7 @@ struct sockaddr;
25int inet6_csk_bind_conflict(const struct sock *sk, 25int inet6_csk_bind_conflict(const struct sock *sk,
26 const struct inet_bind_bucket *tb, bool relax); 26 const struct inet_bind_bucket *tb, bool relax);
27 27
28struct dst_entry *inet6_csk_route_req(struct sock *sk, struct flowi6 *fl6, 28struct dst_entry *inet6_csk_route_req(const struct sock *sk, struct flowi6 *fl6,
29 const struct request_sock *req); 29 const struct request_sock *req);
30 30
31struct request_sock *inet6_csk_search_req(struct sock *sk, 31struct request_sock *inet6_csk_search_req(struct sock *sk,
diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
index 0320bbb7d7b5..00c3ced6ee55 100644
--- a/include/net/inet_connection_sock.h
+++ b/include/net/inet_connection_sock.h
@@ -266,7 +266,7 @@ int inet_csk_bind_conflict(const struct sock *sk,
266 const struct inet_bind_bucket *tb, bool relax); 266 const struct inet_bind_bucket *tb, bool relax);
267int inet_csk_get_port(struct sock *sk, unsigned short snum); 267int inet_csk_get_port(struct sock *sk, unsigned short snum);
268 268
269struct dst_entry *inet_csk_route_req(struct sock *sk, struct flowi4 *fl4, 269struct dst_entry *inet_csk_route_req(const struct sock *sk, struct flowi4 *fl4,
270 const struct request_sock *req); 270 const struct request_sock *req);
271struct dst_entry *inet_csk_route_child_sock(struct sock *sk, struct sock *newsk, 271struct dst_entry *inet_csk_route_child_sock(struct sock *sk, struct sock *newsk,
272 const struct request_sock *req); 272 const struct request_sock *req);
diff --git a/include/net/ip.h b/include/net/ip.h
index 9b9ca2839399..91a6b2c88341 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -100,7 +100,7 @@ int igmp_mc_init(void);
100 * Functions provided by ip.c 100 * Functions provided by ip.c
101 */ 101 */
102 102
103int ip_build_and_send_pkt(struct sk_buff *skb, struct sock *sk, 103int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk,
104 __be32 saddr, __be32 daddr, 104 __be32 saddr, __be32 daddr,
105 struct ip_options_rcu *opt); 105 struct ip_options_rcu *opt);
106int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, 106int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
@@ -282,10 +282,12 @@ int ip_decrease_ttl(struct iphdr *iph)
282} 282}
283 283
284static inline 284static inline
285int ip_dont_fragment(struct sock *sk, struct dst_entry *dst) 285int ip_dont_fragment(const struct sock *sk, const struct dst_entry *dst)
286{ 286{
287 return inet_sk(sk)->pmtudisc == IP_PMTUDISC_DO || 287 u8 pmtudisc = READ_ONCE(inet_sk(sk)->pmtudisc);
288 (inet_sk(sk)->pmtudisc == IP_PMTUDISC_WANT && 288
289 return pmtudisc == IP_PMTUDISC_DO ||
290 (pmtudisc == IP_PMTUDISC_WANT &&
289 !(dst_metric_locked(dst, RTAX_MTU))); 291 !(dst_metric_locked(dst, RTAX_MTU)));
290} 292}
291 293
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 384a93cf07d6..3dde042bcd3f 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -812,7 +812,7 @@ int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
812/* 812/*
813 * upper-layer output functions 813 * upper-layer output functions
814 */ 814 */
815int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, 815int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
816 struct ipv6_txoptions *opt, int tclass); 816 struct ipv6_txoptions *opt, int tclass);
817 817
818int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr); 818int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr);
@@ -849,7 +849,7 @@ static inline struct sk_buff *ip6_finish_skb(struct sock *sk)
849 849
850int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst, 850int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
851 struct flowi6 *fl6); 851 struct flowi6 *fl6);
852struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6, 852struct dst_entry *ip6_dst_lookup_flow(const struct sock *sk, struct flowi6 *fl6,
853 const struct in6_addr *final_dst); 853 const struct in6_addr *final_dst);
854struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6, 854struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
855 const struct in6_addr *final_dst); 855 const struct in6_addr *final_dst);
diff --git a/include/net/request_sock.h b/include/net/request_sock.h
index 87935cad2f7b..181f97f9fe1c 100644
--- a/include/net/request_sock.h
+++ b/include/net/request_sock.h
@@ -32,7 +32,7 @@ struct request_sock_ops {
32 int obj_size; 32 int obj_size;
33 struct kmem_cache *slab; 33 struct kmem_cache *slab;
34 char *slab_name; 34 char *slab_name;
35 int (*rtx_syn_ack)(struct sock *sk, 35 int (*rtx_syn_ack)(const struct sock *sk,
36 struct request_sock *req); 36 struct request_sock *req);
37 void (*send_ack)(struct sock *sk, struct sk_buff *skb, 37 void (*send_ack)(struct sock *sk, struct sk_buff *skb,
38 struct request_sock *req); 38 struct request_sock *req);
@@ -42,7 +42,7 @@ struct request_sock_ops {
42 void (*syn_ack_timeout)(const struct request_sock *req); 42 void (*syn_ack_timeout)(const struct request_sock *req);
43}; 43};
44 44
45int inet_rtx_syn_ack(struct sock *parent, struct request_sock *req); 45int inet_rtx_syn_ack(const struct sock *parent, struct request_sock *req);
46 46
47/* struct request_sock - mini sock to represent a connection request 47/* struct request_sock - mini sock to represent a connection request
48 */ 48 */
diff --git a/include/net/route.h b/include/net/route.h
index 10a7d21a211c..414beadc619f 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -114,7 +114,7 @@ void rt_cache_flush(struct net *net);
114void rt_flush_dev(struct net_device *dev); 114void rt_flush_dev(struct net_device *dev);
115struct rtable *__ip_route_output_key(struct net *, struct flowi4 *flp); 115struct rtable *__ip_route_output_key(struct net *, struct flowi4 *flp);
116struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp, 116struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
117 struct sock *sk); 117 const struct sock *sk);
118struct dst_entry *ipv4_blackhole_route(struct net *net, 118struct dst_entry *ipv4_blackhole_route(struct net *net,
119 struct dst_entry *dst_orig); 119 struct dst_entry *dst_orig);
120 120
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 5cf9672c13e2..6630ab180f5c 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -461,7 +461,7 @@ struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
461int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb); 461int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb);
462int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len); 462int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
463int tcp_connect(struct sock *sk); 463int tcp_connect(struct sock *sk);
464struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst, 464struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst,
465 struct request_sock *req, 465 struct request_sock *req,
466 struct tcp_fastopen_cookie *foc); 466 struct tcp_fastopen_cookie *foc);
467int tcp_disconnect(struct sock *sk, int flags); 467int tcp_disconnect(struct sock *sk, int flags);
@@ -1207,7 +1207,8 @@ static inline int tcp_full_space(const struct sock *sk)
1207} 1207}
1208 1208
1209extern void tcp_openreq_init_rwin(struct request_sock *req, 1209extern void tcp_openreq_init_rwin(struct request_sock *req,
1210 struct sock *sk, struct dst_entry *dst); 1210 const struct sock *sk_listener,
1211 const struct dst_entry *dst);
1211 1212
1212void tcp_enter_memory_pressure(struct sock *sk); 1213void tcp_enter_memory_pressure(struct sock *sk);
1213 1214
@@ -1371,16 +1372,16 @@ int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr,
1371 int family, const u8 *newkey, u8 newkeylen, gfp_t gfp); 1372 int family, const u8 *newkey, u8 newkeylen, gfp_t gfp);
1372int tcp_md5_do_del(struct sock *sk, const union tcp_md5_addr *addr, 1373int tcp_md5_do_del(struct sock *sk, const union tcp_md5_addr *addr,
1373 int family); 1374 int family);
1374struct tcp_md5sig_key *tcp_v4_md5_lookup(struct sock *sk, 1375struct tcp_md5sig_key *tcp_v4_md5_lookup(const struct sock *sk,
1375 const struct sock *addr_sk); 1376 const struct sock *addr_sk);
1376 1377
1377#ifdef CONFIG_TCP_MD5SIG 1378#ifdef CONFIG_TCP_MD5SIG
1378struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk, 1379struct tcp_md5sig_key *tcp_md5_do_lookup(const struct sock *sk,
1379 const union tcp_md5_addr *addr, 1380 const union tcp_md5_addr *addr,
1380 int family); 1381 int family);
1381#define tcp_twsk_md5_key(twsk) ((twsk)->tw_md5_key) 1382#define tcp_twsk_md5_key(twsk) ((twsk)->tw_md5_key)
1382#else 1383#else
1383static inline struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk, 1384static inline struct tcp_md5sig_key *tcp_md5_do_lookup(const struct sock *sk,
1384 const union tcp_md5_addr *addr, 1385 const union tcp_md5_addr *addr,
1385 int family) 1386 int family)
1386{ 1387{
@@ -1675,7 +1676,7 @@ int tcp4_proc_init(void);
1675void tcp4_proc_exit(void); 1676void tcp4_proc_exit(void);
1676#endif 1677#endif
1677 1678
1678int tcp_rtx_synack(struct sock *sk, struct request_sock *req); 1679int tcp_rtx_synack(const struct sock *sk, struct request_sock *req);
1679int tcp_conn_request(struct request_sock_ops *rsk_ops, 1680int tcp_conn_request(struct request_sock_ops *rsk_ops,
1680 const struct tcp_request_sock_ops *af_ops, 1681 const struct tcp_request_sock_ops *af_ops,
1681 struct sock *sk, struct sk_buff *skb); 1682 struct sock *sk, struct sk_buff *skb);
@@ -1683,7 +1684,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
1683/* TCP af-specific functions */ 1684/* TCP af-specific functions */
1684struct tcp_sock_af_ops { 1685struct tcp_sock_af_ops {
1685#ifdef CONFIG_TCP_MD5SIG 1686#ifdef CONFIG_TCP_MD5SIG
1686 struct tcp_md5sig_key *(*md5_lookup) (struct sock *sk, 1687 struct tcp_md5sig_key *(*md5_lookup) (const struct sock *sk,
1687 const struct sock *addr_sk); 1688 const struct sock *addr_sk);
1688 int (*calc_md5_hash)(char *location, 1689 int (*calc_md5_hash)(char *location,
1689 const struct tcp_md5sig_key *md5, 1690 const struct tcp_md5sig_key *md5,
@@ -1698,14 +1699,15 @@ struct tcp_sock_af_ops {
1698struct tcp_request_sock_ops { 1699struct tcp_request_sock_ops {
1699 u16 mss_clamp; 1700 u16 mss_clamp;
1700#ifdef CONFIG_TCP_MD5SIG 1701#ifdef CONFIG_TCP_MD5SIG
1701 struct tcp_md5sig_key *(*req_md5_lookup)(struct sock *sk, 1702 struct tcp_md5sig_key *(*req_md5_lookup)(const struct sock *sk,
1702 const struct sock *addr_sk); 1703 const struct sock *addr_sk);
1703 int (*calc_md5_hash) (char *location, 1704 int (*calc_md5_hash) (char *location,
1704 const struct tcp_md5sig_key *md5, 1705 const struct tcp_md5sig_key *md5,
1705 const struct sock *sk, 1706 const struct sock *sk,
1706 const struct sk_buff *skb); 1707 const struct sk_buff *skb);
1707#endif 1708#endif
1708 void (*init_req)(struct request_sock *req, struct sock *sk, 1709 void (*init_req)(struct request_sock *req,
1710 const struct sock *sk_listener,
1709 struct sk_buff *skb); 1711 struct sk_buff *skb);
1710#ifdef CONFIG_SYN_COOKIES 1712#ifdef CONFIG_SYN_COOKIES
1711 __u32 (*cookie_init_seq)(struct sock *sk, const struct sk_buff *skb, 1713 __u32 (*cookie_init_seq)(struct sock *sk, const struct sk_buff *skb,
@@ -1715,7 +1717,7 @@ struct tcp_request_sock_ops {
1715 const struct request_sock *req, 1717 const struct request_sock *req,
1716 bool *strict); 1718 bool *strict);
1717 __u32 (*init_seq)(const struct sk_buff *skb); 1719 __u32 (*init_seq)(const struct sk_buff *skb);
1718 int (*send_synack)(struct sock *sk, struct dst_entry *dst, 1720 int (*send_synack)(const struct sock *sk, struct dst_entry *dst,
1719 struct flowi *fl, struct request_sock *req, 1721 struct flowi *fl, struct request_sock *req,
1720 u16 queue_mapping, struct tcp_fastopen_cookie *foc); 1722 u16 queue_mapping, struct tcp_fastopen_cookie *foc);
1721 void (*queue_hash_add)(struct sock *sk, struct request_sock *req, 1723 void (*queue_hash_add)(struct sock *sk, struct request_sock *req,
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index bebc735f5afc..31e96df500d1 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -293,7 +293,7 @@ int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized);
293void dccp_destroy_sock(struct sock *sk); 293void dccp_destroy_sock(struct sock *sk);
294 294
295void dccp_close(struct sock *sk, long timeout); 295void dccp_close(struct sock *sk, long timeout);
296struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst, 296struct sk_buff *dccp_make_response(const struct sock *sk, struct dst_entry *dst,
297 struct request_sock *req); 297 struct request_sock *req);
298 298
299int dccp_connect(struct sock *sk); 299int dccp_connect(struct sock *sk);
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index ccf4c5629b3c..a46ae9c69ccf 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -498,7 +498,7 @@ static struct dst_entry* dccp_v4_route_skb(struct net *net, struct sock *sk,
498 return &rt->dst; 498 return &rt->dst;
499} 499}
500 500
501static int dccp_v4_send_response(struct sock *sk, struct request_sock *req) 501static int dccp_v4_send_response(const struct sock *sk, struct request_sock *req)
502{ 502{
503 int err = -1; 503 int err = -1;
504 struct sk_buff *skb; 504 struct sk_buff *skb;
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 5165571f397a..4fa199dc69a3 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -181,7 +181,7 @@ out:
181} 181}
182 182
183 183
184static int dccp_v6_send_response(struct sock *sk, struct request_sock *req) 184static int dccp_v6_send_response(const struct sock *sk, struct request_sock *req)
185{ 185{
186 struct inet_request_sock *ireq = inet_rsk(req); 186 struct inet_request_sock *ireq = inet_rsk(req);
187 struct ipv6_pinfo *np = inet6_sk(sk); 187 struct ipv6_pinfo *np = inet6_sk(sk);
diff --git a/net/dccp/output.c b/net/dccp/output.c
index 0248e8a3460c..4ce912e691d0 100644
--- a/net/dccp/output.c
+++ b/net/dccp/output.c
@@ -390,7 +390,7 @@ int dccp_retransmit_skb(struct sock *sk)
390 return dccp_transmit_skb(sk, skb_clone(sk->sk_send_head, GFP_ATOMIC)); 390 return dccp_transmit_skb(sk, skb_clone(sk->sk_send_head, GFP_ATOMIC));
391} 391}
392 392
393struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst, 393struct sk_buff *dccp_make_response(const struct sock *sk, struct dst_entry *dst,
394 struct request_sock *req) 394 struct request_sock *req)
395{ 395{
396 struct dccp_hdr *dh; 396 struct dccp_hdr *dh;
@@ -398,13 +398,18 @@ struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,
398 const u32 dccp_header_size = sizeof(struct dccp_hdr) + 398 const u32 dccp_header_size = sizeof(struct dccp_hdr) +
399 sizeof(struct dccp_hdr_ext) + 399 sizeof(struct dccp_hdr_ext) +
400 sizeof(struct dccp_hdr_response); 400 sizeof(struct dccp_hdr_response);
401 struct sk_buff *skb = sock_wmalloc(sk, sk->sk_prot->max_header, 1, 401 struct sk_buff *skb;
402 GFP_ATOMIC); 402
403 if (skb == NULL) 403 /* sk is marked const to clearly express we dont hold socket lock.
404 * sock_wmalloc() will atomically change sk->sk_wmem_alloc,
405 * it is safe to promote sk to non const.
406 */
407 skb = sock_wmalloc((struct sock *)sk, MAX_DCCP_HEADER, 1,
408 GFP_ATOMIC);
409 if (!skb)
404 return NULL; 410 return NULL;
405 411
406 /* Reserve space for headers. */ 412 skb_reserve(skb, MAX_DCCP_HEADER);
407 skb_reserve(skb, sk->sk_prot->max_header);
408 413
409 skb_dst_set(skb, dst_clone(dst)); 414 skb_dst_set(skb, dst_clone(dst));
410 415
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 134957159c27..bac205136e1c 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -408,7 +408,7 @@ void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long len)
408} 408}
409EXPORT_SYMBOL(inet_csk_reset_keepalive_timer); 409EXPORT_SYMBOL(inet_csk_reset_keepalive_timer);
410 410
411struct dst_entry *inet_csk_route_req(struct sock *sk, 411struct dst_entry *inet_csk_route_req(const struct sock *sk,
412 struct flowi4 *fl4, 412 struct flowi4 *fl4,
413 const struct request_sock *req) 413 const struct request_sock *req)
414{ 414{
@@ -563,7 +563,7 @@ static inline void syn_ack_recalc(struct request_sock *req, const int thresh,
563 req->num_timeout >= rskq_defer_accept - 1; 563 req->num_timeout >= rskq_defer_accept - 1;
564} 564}
565 565
566int inet_rtx_syn_ack(struct sock *parent, struct request_sock *req) 566int inet_rtx_syn_ack(const struct sock *parent, struct request_sock *req)
567{ 567{
568 int err = req->rsk_ops->rtx_syn_ack(parent, req); 568 int err = req->rsk_ops->rtx_syn_ack(parent, req);
569 569
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 09a6b7bb7ea3..06d2c87ed505 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -137,7 +137,7 @@ static inline int ip_select_ttl(struct inet_sock *inet, struct dst_entry *dst)
137 * Add an ip header to a skbuff and send it out. 137 * Add an ip header to a skbuff and send it out.
138 * 138 *
139 */ 139 */
140int ip_build_and_send_pkt(struct sk_buff *skb, struct sock *sk, 140int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk,
141 __be32 saddr, __be32 daddr, struct ip_options_rcu *opt) 141 __be32 saddr, __be32 daddr, struct ip_options_rcu *opt)
142{ 142{
143 struct inet_sock *inet = inet_sk(sk); 143 struct inet_sock *inet = inet_sk(sk);
@@ -151,15 +151,17 @@ int ip_build_and_send_pkt(struct sk_buff *skb, struct sock *sk,
151 iph->version = 4; 151 iph->version = 4;
152 iph->ihl = 5; 152 iph->ihl = 5;
153 iph->tos = inet->tos; 153 iph->tos = inet->tos;
154 if (ip_dont_fragment(sk, &rt->dst))
155 iph->frag_off = htons(IP_DF);
156 else
157 iph->frag_off = 0;
158 iph->ttl = ip_select_ttl(inet, &rt->dst); 154 iph->ttl = ip_select_ttl(inet, &rt->dst);
159 iph->daddr = (opt && opt->opt.srr ? opt->opt.faddr : daddr); 155 iph->daddr = (opt && opt->opt.srr ? opt->opt.faddr : daddr);
160 iph->saddr = saddr; 156 iph->saddr = saddr;
161 iph->protocol = sk->sk_protocol; 157 iph->protocol = sk->sk_protocol;
162 ip_select_ident(sock_net(sk), skb, sk); 158 if (ip_dont_fragment(sk, &rt->dst)) {
159 iph->frag_off = htons(IP_DF);
160 iph->id = 0;
161 } else {
162 iph->frag_off = 0;
163 __ip_select_ident(sock_net(sk), iph, 1);
164 }
163 165
164 if (opt && opt->opt.optlen) { 166 if (opt && opt->opt.optlen) {
165 iph->ihl += opt->opt.optlen>>2; 167 iph->ihl += opt->opt.optlen>>2;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 80f7c5b7b832..f7afcba8b1a1 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2291,7 +2291,7 @@ struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_or
2291} 2291}
2292 2292
2293struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4, 2293struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4,
2294 struct sock *sk) 2294 const struct sock *sk)
2295{ 2295{
2296 struct rtable *rt = __ip_route_output_key(net, flp4); 2296 struct rtable *rt = __ip_route_output_key(net, flp4);
2297 2297
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
index 93c4dc3ab23f..882caa4e72bc 100644
--- a/net/ipv4/tcp_cong.c
+++ b/net/ipv4/tcp_cong.c
@@ -173,6 +173,10 @@ out:
173 */ 173 */
174 if (ca->get_info) 174 if (ca->get_info)
175 memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv)); 175 memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv));
176 if (ca->flags & TCP_CONG_NEEDS_ECN)
177 INET_ECN_xmit(sk);
178 else
179 INET_ECN_dontxmit(sk);
176} 180}
177 181
178void tcp_init_congestion_control(struct sock *sk) 182void tcp_init_congestion_control(struct sock *sk)
@@ -181,6 +185,10 @@ void tcp_init_congestion_control(struct sock *sk)
181 185
182 if (icsk->icsk_ca_ops->init) 186 if (icsk->icsk_ca_ops->init)
183 icsk->icsk_ca_ops->init(sk); 187 icsk->icsk_ca_ops->init(sk);
188 if (tcp_ca_needs_ecn(sk))
189 INET_ECN_xmit(sk);
190 else
191 INET_ECN_dontxmit(sk);
184} 192}
185 193
186static void tcp_reinit_congestion_control(struct sock *sk, 194static void tcp_reinit_congestion_control(struct sock *sk,
@@ -192,8 +200,8 @@ static void tcp_reinit_congestion_control(struct sock *sk,
192 icsk->icsk_ca_ops = ca; 200 icsk->icsk_ca_ops = ca;
193 icsk->icsk_ca_setsockopt = 1; 201 icsk->icsk_ca_setsockopt = 1;
194 202
195 if (sk->sk_state != TCP_CLOSE && icsk->icsk_ca_ops->init) 203 if (sk->sk_state != TCP_CLOSE)
196 icsk->icsk_ca_ops->init(sk); 204 tcp_init_congestion_control(sk);
197} 205}
198 206
199/* Manage refcounts on socket close. */ 207/* Manage refcounts on socket close. */
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 7e2646542312..a23ba7daecbf 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -818,7 +818,7 @@ static void tcp_v4_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
818 * This still operates on a request_sock only, not on a big 818 * This still operates on a request_sock only, not on a big
819 * socket. 819 * socket.
820 */ 820 */
821static int tcp_v4_send_synack(struct sock *sk, struct dst_entry *dst, 821static int tcp_v4_send_synack(const struct sock *sk, struct dst_entry *dst,
822 struct flowi *fl, 822 struct flowi *fl,
823 struct request_sock *req, 823 struct request_sock *req,
824 u16 queue_mapping, 824 u16 queue_mapping,
@@ -865,7 +865,7 @@ static void tcp_v4_reqsk_destructor(struct request_sock *req)
865 */ 865 */
866 866
867/* Find the Key structure for an address. */ 867/* Find the Key structure for an address. */
868struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk, 868struct tcp_md5sig_key *tcp_md5_do_lookup(const struct sock *sk,
869 const union tcp_md5_addr *addr, 869 const union tcp_md5_addr *addr,
870 int family) 870 int family)
871{ 871{
@@ -877,7 +877,7 @@ struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk,
877 /* caller either holds rcu_read_lock() or socket lock */ 877 /* caller either holds rcu_read_lock() or socket lock */
878 md5sig = rcu_dereference_check(tp->md5sig_info, 878 md5sig = rcu_dereference_check(tp->md5sig_info,
879 sock_owned_by_user(sk) || 879 sock_owned_by_user(sk) ||
880 lockdep_is_held(&sk->sk_lock.slock)); 880 lockdep_is_held((spinlock_t *)&sk->sk_lock.slock));
881 if (!md5sig) 881 if (!md5sig)
882 return NULL; 882 return NULL;
883#if IS_ENABLED(CONFIG_IPV6) 883#if IS_ENABLED(CONFIG_IPV6)
@@ -894,7 +894,7 @@ struct tcp_md5sig_key *tcp_md5_do_lookup(struct sock *sk,
894} 894}
895EXPORT_SYMBOL(tcp_md5_do_lookup); 895EXPORT_SYMBOL(tcp_md5_do_lookup);
896 896
897struct tcp_md5sig_key *tcp_v4_md5_lookup(struct sock *sk, 897struct tcp_md5sig_key *tcp_v4_md5_lookup(const struct sock *sk,
898 const struct sock *addr_sk) 898 const struct sock *addr_sk)
899{ 899{
900 const union tcp_md5_addr *addr; 900 const union tcp_md5_addr *addr;
@@ -1168,7 +1168,8 @@ static bool tcp_v4_inbound_md5_hash(struct sock *sk,
1168} 1168}
1169#endif 1169#endif
1170 1170
1171static void tcp_v4_init_req(struct request_sock *req, struct sock *sk_listener, 1171static void tcp_v4_init_req(struct request_sock *req,
1172 const struct sock *sk_listener,
1172 struct sk_buff *skb) 1173 struct sk_buff *skb)
1173{ 1174{
1174 struct inet_request_sock *ireq = inet_rsk(req); 1175 struct inet_request_sock *ireq = inet_rsk(req);
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 85830bb92d04..e0a87c238882 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -362,27 +362,35 @@ void tcp_twsk_destructor(struct sock *sk)
362} 362}
363EXPORT_SYMBOL_GPL(tcp_twsk_destructor); 363EXPORT_SYMBOL_GPL(tcp_twsk_destructor);
364 364
365/* Warning : This function is called without sk_listener being locked.
366 * Be sure to read socket fields once, as their value could change under us.
367 */
365void tcp_openreq_init_rwin(struct request_sock *req, 368void tcp_openreq_init_rwin(struct request_sock *req,
366 struct sock *sk, struct dst_entry *dst) 369 const struct sock *sk_listener,
370 const struct dst_entry *dst)
367{ 371{
368 struct inet_request_sock *ireq = inet_rsk(req); 372 struct inet_request_sock *ireq = inet_rsk(req);
369 struct tcp_sock *tp = tcp_sk(sk); 373 const struct tcp_sock *tp = tcp_sk(sk_listener);
370 __u8 rcv_wscale; 374 u16 user_mss = READ_ONCE(tp->rx_opt.user_mss);
375 int full_space = tcp_full_space(sk_listener);
371 int mss = dst_metric_advmss(dst); 376 int mss = dst_metric_advmss(dst);
377 u32 window_clamp;
378 __u8 rcv_wscale;
372 379
373 if (tp->rx_opt.user_mss && tp->rx_opt.user_mss < mss) 380 if (user_mss && user_mss < mss)
374 mss = tp->rx_opt.user_mss; 381 mss = user_mss;
375 382
383 window_clamp = READ_ONCE(tp->window_clamp);
376 /* Set this up on the first call only */ 384 /* Set this up on the first call only */
377 req->window_clamp = tp->window_clamp ? : dst_metric(dst, RTAX_WINDOW); 385 req->window_clamp = window_clamp ? : dst_metric(dst, RTAX_WINDOW);
378 386
379 /* limit the window selection if the user enforce a smaller rx buffer */ 387 /* limit the window selection if the user enforce a smaller rx buffer */
380 if (sk->sk_userlocks & SOCK_RCVBUF_LOCK && 388 if (sk_listener->sk_userlocks & SOCK_RCVBUF_LOCK &&
381 (req->window_clamp > tcp_full_space(sk) || req->window_clamp == 0)) 389 (req->window_clamp > full_space || req->window_clamp == 0))
382 req->window_clamp = tcp_full_space(sk); 390 req->window_clamp = full_space;
383 391
384 /* tcp_full_space because it is guaranteed to be the first packet */ 392 /* tcp_full_space because it is guaranteed to be the first packet */
385 tcp_select_initial_window(tcp_full_space(sk), 393 tcp_select_initial_window(full_space,
386 mss - (ireq->tstamp_ok ? TCPOLEN_TSTAMP_ALIGNED : 0), 394 mss - (ireq->tstamp_ok ? TCPOLEN_TSTAMP_ALIGNED : 0),
387 &req->rcv_wnd, 395 &req->rcv_wnd,
388 &req->window_clamp, 396 &req->window_clamp,
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 4cd0b50d4e46..53ce6cf55598 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -357,14 +357,10 @@ static void tcp_ecn_clear_syn(struct sock *sk, struct sk_buff *skb)
357} 357}
358 358
359static void 359static void
360tcp_ecn_make_synack(const struct request_sock *req, struct tcphdr *th, 360tcp_ecn_make_synack(const struct request_sock *req, struct tcphdr *th)
361 struct sock *sk)
362{ 361{
363 if (inet_rsk(req)->ecn_ok) { 362 if (inet_rsk(req)->ecn_ok)
364 th->ece = 1; 363 th->ece = 1;
365 if (tcp_ca_needs_ecn(sk))
366 INET_ECN_xmit(sk);
367 }
368} 364}
369 365
370/* Set up ECN state for a packet on a ESTABLISHED socket that is about to 366/* Set up ECN state for a packet on a ESTABLISHED socket that is about to
@@ -612,12 +608,11 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
612} 608}
613 609
614/* Set up TCP options for SYN-ACKs. */ 610/* Set up TCP options for SYN-ACKs. */
615static unsigned int tcp_synack_options(struct sock *sk, 611static unsigned int tcp_synack_options(struct request_sock *req,
616 struct request_sock *req, 612 unsigned int mss, struct sk_buff *skb,
617 unsigned int mss, struct sk_buff *skb, 613 struct tcp_out_options *opts,
618 struct tcp_out_options *opts, 614 const struct tcp_md5sig_key *md5,
619 const struct tcp_md5sig_key *md5, 615 struct tcp_fastopen_cookie *foc)
620 struct tcp_fastopen_cookie *foc)
621{ 616{
622 struct inet_request_sock *ireq = inet_rsk(req); 617 struct inet_request_sock *ireq = inet_rsk(req);
623 unsigned int remaining = MAX_TCP_OPTION_SPACE; 618 unsigned int remaining = MAX_TCP_OPTION_SPACE;
@@ -2949,20 +2944,25 @@ int tcp_send_synack(struct sock *sk)
2949 * Allocate one skb and build a SYNACK packet. 2944 * Allocate one skb and build a SYNACK packet.
2950 * @dst is consumed : Caller should not use it again. 2945 * @dst is consumed : Caller should not use it again.
2951 */ 2946 */
2952struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst, 2947struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst,
2953 struct request_sock *req, 2948 struct request_sock *req,
2954 struct tcp_fastopen_cookie *foc) 2949 struct tcp_fastopen_cookie *foc)
2955{ 2950{
2956 struct tcp_out_options opts;
2957 struct inet_request_sock *ireq = inet_rsk(req); 2951 struct inet_request_sock *ireq = inet_rsk(req);
2958 struct tcp_sock *tp = tcp_sk(sk); 2952 const struct tcp_sock *tp = tcp_sk(sk);
2959 struct tcphdr *th;
2960 struct sk_buff *skb;
2961 struct tcp_md5sig_key *md5 = NULL; 2953 struct tcp_md5sig_key *md5 = NULL;
2954 struct tcp_out_options opts;
2955 struct sk_buff *skb;
2962 int tcp_header_size; 2956 int tcp_header_size;
2957 struct tcphdr *th;
2958 u16 user_mss;
2963 int mss; 2959 int mss;
2964 2960
2965 skb = sock_wmalloc(sk, MAX_TCP_HEADER, 1, GFP_ATOMIC); 2961 /* sk is a const pointer, because we want to express multiple cpus
2962 * might call us concurrently.
2963 * sock_wmalloc() will change sk->sk_wmem_alloc in an atomic way.
2964 */
2965 skb = sock_wmalloc((struct sock *)sk, MAX_TCP_HEADER, 1, GFP_ATOMIC);
2966 if (unlikely(!skb)) { 2966 if (unlikely(!skb)) {
2967 dst_release(dst); 2967 dst_release(dst);
2968 return NULL; 2968 return NULL;
@@ -2973,8 +2973,9 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2973 skb_dst_set(skb, dst); 2973 skb_dst_set(skb, dst);
2974 2974
2975 mss = dst_metric_advmss(dst); 2975 mss = dst_metric_advmss(dst);
2976 if (tp->rx_opt.user_mss && tp->rx_opt.user_mss < mss) 2976 user_mss = READ_ONCE(tp->rx_opt.user_mss);
2977 mss = tp->rx_opt.user_mss; 2977 if (user_mss && user_mss < mss)
2978 mss = user_mss;
2978 2979
2979 memset(&opts, 0, sizeof(opts)); 2980 memset(&opts, 0, sizeof(opts));
2980#ifdef CONFIG_SYN_COOKIES 2981#ifdef CONFIG_SYN_COOKIES
@@ -2989,8 +2990,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2989 md5 = tcp_rsk(req)->af_specific->req_md5_lookup(sk, req_to_sk(req)); 2990 md5 = tcp_rsk(req)->af_specific->req_md5_lookup(sk, req_to_sk(req));
2990#endif 2991#endif
2991 skb_set_hash(skb, tcp_rsk(req)->txhash, PKT_HASH_TYPE_L4); 2992 skb_set_hash(skb, tcp_rsk(req)->txhash, PKT_HASH_TYPE_L4);
2992 tcp_header_size = tcp_synack_options(sk, req, mss, skb, &opts, md5, 2993 tcp_header_size = tcp_synack_options(req, mss, skb, &opts, md5, foc) +
2993 foc) + sizeof(*th); 2994 sizeof(*th);
2994 2995
2995 skb_push(skb, tcp_header_size); 2996 skb_push(skb, tcp_header_size);
2996 skb_reset_transport_header(skb); 2997 skb_reset_transport_header(skb);
@@ -2999,7 +3000,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
2999 memset(th, 0, sizeof(struct tcphdr)); 3000 memset(th, 0, sizeof(struct tcphdr));
3000 th->syn = 1; 3001 th->syn = 1;
3001 th->ack = 1; 3002 th->ack = 1;
3002 tcp_ecn_make_synack(req, th, sk); 3003 tcp_ecn_make_synack(req, th);
3003 th->source = htons(ireq->ir_num); 3004 th->source = htons(ireq->ir_num);
3004 th->dest = ireq->ir_rmt_port; 3005 th->dest = ireq->ir_rmt_port;
3005 /* Setting of flags are superfluous here for callers (and ECE is 3006 /* Setting of flags are superfluous here for callers (and ECE is
@@ -3014,7 +3015,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
3014 3015
3015 /* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */ 3016 /* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */
3016 th->window = htons(min(req->rcv_wnd, 65535U)); 3017 th->window = htons(min(req->rcv_wnd, 65535U));
3017 tcp_options_write((__be32 *)(th + 1), tp, &opts); 3018 tcp_options_write((__be32 *)(th + 1), NULL, &opts);
3018 th->doff = (tcp_header_size >> 2); 3019 th->doff = (tcp_header_size >> 2);
3019 TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_OUTSEGS); 3020 TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_OUTSEGS);
3020 3021
@@ -3501,7 +3502,7 @@ void tcp_send_probe0(struct sock *sk)
3501 TCP_RTO_MAX); 3502 TCP_RTO_MAX);
3502} 3503}
3503 3504
3504int tcp_rtx_synack(struct sock *sk, struct request_sock *req) 3505int tcp_rtx_synack(const struct sock *sk, struct request_sock *req)
3505{ 3506{
3506 const struct tcp_request_sock_ops *af_ops = tcp_rsk(req)->af_specific; 3507 const struct tcp_request_sock_ops *af_ops = tcp_rsk(req)->af_specific;
3507 struct flowi fl; 3508 struct flowi fl;
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index 9aadd57808a5..d70b0238f468 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -263,7 +263,7 @@ void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
263 263
264void ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info) 264void ipv6_local_error(struct sock *sk, int err, struct flowi6 *fl6, u32 info)
265{ 265{
266 struct ipv6_pinfo *np = inet6_sk(sk); 266 const struct ipv6_pinfo *np = inet6_sk(sk);
267 struct sock_exterr_skb *serr; 267 struct sock_exterr_skb *serr;
268 struct ipv6hdr *iph; 268 struct ipv6hdr *iph;
269 struct sk_buff *skb; 269 struct sk_buff *skb;
diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
index 6927f3fb5597..91b7d33f508b 100644
--- a/net/ipv6/inet6_connection_sock.c
+++ b/net/ipv6/inet6_connection_sock.c
@@ -65,7 +65,7 @@ int inet6_csk_bind_conflict(const struct sock *sk,
65} 65}
66EXPORT_SYMBOL_GPL(inet6_csk_bind_conflict); 66EXPORT_SYMBOL_GPL(inet6_csk_bind_conflict);
67 67
68struct dst_entry *inet6_csk_route_req(struct sock *sk, 68struct dst_entry *inet6_csk_route_req(const struct sock *sk,
69 struct flowi6 *fl6, 69 struct flowi6 *fl6,
70 const struct request_sock *req) 70 const struct request_sock *req)
71{ 71{
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 291a07be5dfb..60c565309d0a 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -150,14 +150,16 @@ int ip6_output(struct sock *sk, struct sk_buff *skb)
150} 150}
151 151
152/* 152/*
153 * xmit an sk_buff (used by TCP, SCTP and DCCP) 153 * xmit an sk_buff (used by TCP, SCTP and DCCP)
154 * Note : socket lock is not held for SYNACK packets, but might be modified
155 * by calls to skb_set_owner_w() and ipv6_local_error(),
156 * which are using proper atomic operations or spinlocks.
154 */ 157 */
155 158int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
156int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
157 struct ipv6_txoptions *opt, int tclass) 159 struct ipv6_txoptions *opt, int tclass)
158{ 160{
159 struct net *net = sock_net(sk); 161 struct net *net = sock_net(sk);
160 struct ipv6_pinfo *np = inet6_sk(sk); 162 const struct ipv6_pinfo *np = inet6_sk(sk);
161 struct in6_addr *first_hop = &fl6->daddr; 163 struct in6_addr *first_hop = &fl6->daddr;
162 struct dst_entry *dst = skb_dst(skb); 164 struct dst_entry *dst = skb_dst(skb);
163 struct ipv6hdr *hdr; 165 struct ipv6hdr *hdr;
@@ -186,7 +188,10 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
186 } 188 }
187 consume_skb(skb); 189 consume_skb(skb);
188 skb = skb2; 190 skb = skb2;
189 skb_set_owner_w(skb, sk); 191 /* skb_set_owner_w() changes sk->sk_wmem_alloc atomically,
192 * it is safe to call in our context (socket lock not held)
193 */
194 skb_set_owner_w(skb, (struct sock *)sk);
190 } 195 }
191 if (opt->opt_flen) 196 if (opt->opt_flen)
192 ipv6_push_frag_opts(skb, opt, &proto); 197 ipv6_push_frag_opts(skb, opt, &proto);
@@ -224,13 +229,20 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
224 if ((skb->len <= mtu) || skb->ignore_df || skb_is_gso(skb)) { 229 if ((skb->len <= mtu) || skb->ignore_df || skb_is_gso(skb)) {
225 IP6_UPD_PO_STATS(net, ip6_dst_idev(skb_dst(skb)), 230 IP6_UPD_PO_STATS(net, ip6_dst_idev(skb_dst(skb)),
226 IPSTATS_MIB_OUT, skb->len); 231 IPSTATS_MIB_OUT, skb->len);
232 /* hooks should never assume socket lock is held.
233 * we promote our socket to non const
234 */
227 return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, 235 return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT,
228 net, sk, skb, NULL, dst->dev, 236 net, (struct sock *)sk, skb, NULL, dst->dev,
229 dst_output_okfn); 237 dst_output_okfn);
230 } 238 }
231 239
232 skb->dev = dst->dev; 240 skb->dev = dst->dev;
233 ipv6_local_error(sk, EMSGSIZE, fl6, mtu); 241 /* ipv6_local_error() does not require socket lock,
242 * we promote our socket to non const
243 */
244 ipv6_local_error((struct sock *)sk, EMSGSIZE, fl6, mtu);
245
234 IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS); 246 IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS);
235 kfree_skb(skb); 247 kfree_skb(skb);
236 return -EMSGSIZE; 248 return -EMSGSIZE;
@@ -883,7 +895,7 @@ out:
883 return dst; 895 return dst;
884} 896}
885 897
886static int ip6_dst_lookup_tail(struct net *net, struct sock *sk, 898static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk,
887 struct dst_entry **dst, struct flowi6 *fl6) 899 struct dst_entry **dst, struct flowi6 *fl6)
888{ 900{
889#ifdef CONFIG_IPV6_OPTIMISTIC_DAD 901#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
@@ -1014,7 +1026,7 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup);
1014 * It returns a valid dst pointer on success, or a pointer encoded 1026 * It returns a valid dst pointer on success, or a pointer encoded
1015 * error code. 1027 * error code.
1016 */ 1028 */
1017struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6, 1029struct dst_entry *ip6_dst_lookup_flow(const struct sock *sk, struct flowi6 *fl6,
1018 const struct in6_addr *final_dst) 1030 const struct in6_addr *final_dst)
1019{ 1031{
1020 struct dst_entry *dst = NULL; 1032 struct dst_entry *dst = NULL;
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index a004e0b0b3e9..16fb299dcab8 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -434,7 +434,7 @@ out:
434} 434}
435 435
436 436
437static int tcp_v6_send_synack(struct sock *sk, struct dst_entry *dst, 437static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
438 struct flowi *fl, 438 struct flowi *fl,
439 struct request_sock *req, 439 struct request_sock *req,
440 u16 queue_mapping, 440 u16 queue_mapping,
@@ -476,13 +476,13 @@ static void tcp_v6_reqsk_destructor(struct request_sock *req)
476} 476}
477 477
478#ifdef CONFIG_TCP_MD5SIG 478#ifdef CONFIG_TCP_MD5SIG
479static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk, 479static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(const struct sock *sk,
480 const struct in6_addr *addr) 480 const struct in6_addr *addr)
481{ 481{
482 return tcp_md5_do_lookup(sk, (union tcp_md5_addr *)addr, AF_INET6); 482 return tcp_md5_do_lookup(sk, (union tcp_md5_addr *)addr, AF_INET6);
483} 483}
484 484
485static struct tcp_md5sig_key *tcp_v6_md5_lookup(struct sock *sk, 485static struct tcp_md5sig_key *tcp_v6_md5_lookup(const struct sock *sk,
486 const struct sock *addr_sk) 486 const struct sock *addr_sk)
487{ 487{
488 return tcp_v6_md5_do_lookup(sk, &addr_sk->sk_v6_daddr); 488 return tcp_v6_md5_do_lookup(sk, &addr_sk->sk_v6_daddr);
@@ -663,22 +663,23 @@ static bool tcp_v6_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb)
663} 663}
664#endif 664#endif
665 665
666static void tcp_v6_init_req(struct request_sock *req, struct sock *sk, 666static void tcp_v6_init_req(struct request_sock *req,
667 const struct sock *sk_listener,
667 struct sk_buff *skb) 668 struct sk_buff *skb)
668{ 669{
669 struct inet_request_sock *ireq = inet_rsk(req); 670 struct inet_request_sock *ireq = inet_rsk(req);
670 struct ipv6_pinfo *np = inet6_sk(sk); 671 const struct ipv6_pinfo *np = inet6_sk(sk_listener);
671 672
672 ireq->ir_v6_rmt_addr = ipv6_hdr(skb)->saddr; 673 ireq->ir_v6_rmt_addr = ipv6_hdr(skb)->saddr;
673 ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr; 674 ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
674 675
675 /* So that link locals have meaning */ 676 /* So that link locals have meaning */
676 if (!sk->sk_bound_dev_if && 677 if (!sk_listener->sk_bound_dev_if &&
677 ipv6_addr_type(&ireq->ir_v6_rmt_addr) & IPV6_ADDR_LINKLOCAL) 678 ipv6_addr_type(&ireq->ir_v6_rmt_addr) & IPV6_ADDR_LINKLOCAL)
678 ireq->ir_iif = tcp_v6_iif(skb); 679 ireq->ir_iif = tcp_v6_iif(skb);
679 680
680 if (!TCP_SKB_CB(skb)->tcp_tw_isn && 681 if (!TCP_SKB_CB(skb)->tcp_tw_isn &&
681 (ipv6_opt_accepted(sk, skb, &TCP_SKB_CB(skb)->header.h6) || 682 (ipv6_opt_accepted(sk_listener, skb, &TCP_SKB_CB(skb)->header.h6) ||
682 np->rxopt.bits.rxinfo || 683 np->rxopt.bits.rxinfo ||
683 np->rxopt.bits.rxoinfo || np->rxopt.bits.rxhlim || 684 np->rxopt.bits.rxoinfo || np->rxopt.bits.rxhlim ||
684 np->rxopt.bits.rxohlim || np->repflow)) { 685 np->rxopt.bits.rxohlim || np->repflow)) {
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index e7f64bcb78a8..418daa038edf 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1208,7 +1208,7 @@ static inline int policy_to_flow_dir(int dir)
1208 } 1208 }
1209} 1209}
1210 1210
1211static struct xfrm_policy *xfrm_sk_policy_lookup(struct sock *sk, int dir, 1211static struct xfrm_policy *xfrm_sk_policy_lookup(const struct sock *sk, int dir,
1212 const struct flowi *fl) 1212 const struct flowi *fl)
1213{ 1213{
1214 struct xfrm_policy *pol; 1214 struct xfrm_policy *pol;
@@ -2185,7 +2185,7 @@ static struct dst_entry *make_blackhole(struct net *net, u16 family,
2185 */ 2185 */
2186struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig, 2186struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
2187 const struct flowi *fl, 2187 const struct flowi *fl,
2188 struct sock *sk, int flags) 2188 const struct sock *sk, int flags)
2189{ 2189{
2190 struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX]; 2190 struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX];
2191 struct flow_cache_object *flo; 2191 struct flow_cache_object *flo;
@@ -2333,7 +2333,7 @@ EXPORT_SYMBOL(xfrm_lookup);
2333 */ 2333 */
2334struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig, 2334struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig,
2335 const struct flowi *fl, 2335 const struct flowi *fl,
2336 struct sock *sk, int flags) 2336 const struct sock *sk, int flags)
2337{ 2337{
2338 struct dst_entry *dst = xfrm_lookup(net, dst_orig, fl, sk, 2338 struct dst_entry *dst = xfrm_lookup(net, dst_orig, fl, sk,
2339 flags | XFRM_LOOKUP_QUEUE | 2339 flags | XFRM_LOOKUP_QUEUE |