Skip to content

Commit 7586ece

Browse files
edumazetdavem330
authored andcommitted
ipv4: tcp: dont cache output dst for syncookies
Don't cache output dst for syncookies, as this adds pressure on IP route cache and rcu subsystem for no gain. Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: Hans Schillstrom <hans.schillstrom@ericsson.com> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 24ea818 commit 7586ece

6 files changed

Lines changed: 21 additions & 10 deletions

File tree

‎include/net/flow.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct flowi_common {
2222
#define FLOWI_FLAG_ANYSRC 0x01
2323
#define FLOWI_FLAG_PRECOW_METRICS 0x02
2424
#define FLOWI_FLAG_CAN_SLEEP 0x04
25+
#define FLOWI_FLAG_RT_NOCACHE 0x08
2526
__u32 flowic_secid;
2627
};
2728

‎include/net/inet_connection_sock.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ extern int inet_csk_get_port(struct sock *sk, unsigned short snum);
251251

252252
extern struct dst_entry* inet_csk_route_req(struct sock *sk,
253253
struct flowi4 *fl4,
254-
const struct request_sock *req);
254+
const struct request_sock *req,
255+
bool nocache);
255256
extern struct dst_entry* inet_csk_route_child_sock(struct sock *sk,
256257
struct sock *newsk,
257258
const struct request_sock *req);

‎net/dccp/ipv4.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ static int dccp_v4_send_response(struct sock *sk, struct request_sock *req,
504504
struct dst_entry *dst;
505505
struct flowi4 fl4;
506506

507-
dst = inet_csk_route_req(sk, &fl4, req);
507+
dst = inet_csk_route_req(sk, &fl4, req, false);
508508
if (dst == NULL)
509509
goto out;
510510

‎net/ipv4/inet_connection_sock.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,21 @@ EXPORT_SYMBOL(inet_csk_reset_keepalive_timer);
368368

369369
struct dst_entry *inet_csk_route_req(struct sock *sk,
370370
struct flowi4 *fl4,
371-
const struct request_sock *req)
371+
const struct request_sock *req,
372+
bool nocache)
372373
{
373374
struct rtable *rt;
374375
const struct inet_request_sock *ireq = inet_rsk(req);
375376
struct ip_options_rcu *opt = inet_rsk(req)->opt;
376377
struct net *net = sock_net(sk);
378+
int flags = inet_sk_flowi_flags(sk) & ~FLOWI_FLAG_PRECOW_METRICS;
377379

380+
if (nocache)
381+
flags |= FLOWI_FLAG_RT_NOCACHE;
378382
flowi4_init_output(fl4, sk->sk_bound_dev_if, sk->sk_mark,
379383
RT_CONN_FLAGS(sk), RT_SCOPE_UNIVERSE,
380384
sk->sk_protocol,
381-
inet_sk_flowi_flags(sk) & ~FLOWI_FLAG_PRECOW_METRICS,
385+
flags,
382386
(opt && opt->opt.srr) ? opt->opt.faddr : ireq->rmt_addr,
383387
ireq->loc_addr, ireq->rmt_port, inet_sk(sk)->inet_sport);
384388
security_req_classify_flow(req, flowi4_to_flowi(fl4));

‎net/ipv4/route.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ static struct rtable *rt_intern_hash(unsigned int hash, struct rtable *rt,
11561156
candp = NULL;
11571157
now = jiffies;
11581158

1159-
if (!rt_caching(dev_net(rt->dst.dev))) {
1159+
if (!rt_caching(dev_net(rt->dst.dev)) || (rt->dst.flags & DST_NOCACHE)) {
11601160
/*
11611161
* If we're not caching, just tell the caller we
11621162
* were successful and don't touch the route. The
@@ -2582,6 +2582,9 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
25822582

25832583
rt_set_nexthop(rth, fl4, res, fi, type, 0);
25842584

2585+
if (fl4->flowi4_flags & FLOWI_FLAG_RT_NOCACHE)
2586+
rth->dst.flags |= DST_NOCACHE;
2587+
25852588
return rth;
25862589
}
25872590

‎net/ipv4/tcp_ipv4.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,15 +825,16 @@ static void tcp_v4_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
825825
static int tcp_v4_send_synack(struct sock *sk, struct dst_entry *dst,
826826
struct request_sock *req,
827827
struct request_values *rvp,
828-
u16 queue_mapping)
828+
u16 queue_mapping,
829+
bool nocache)
829830
{
830831
const struct inet_request_sock *ireq = inet_rsk(req);
831832
struct flowi4 fl4;
832833
int err = -1;
833834
struct sk_buff * skb;
834835

835836
/* First, grab a route. */
836-
if (!dst && (dst = inet_csk_route_req(sk, &fl4, req)) == NULL)
837+
if (!dst && (dst = inet_csk_route_req(sk, &fl4, req, nocache)) == NULL)
837838
return -1;
838839

839840
skb = tcp_make_synack(sk, dst, req, rvp);
@@ -855,7 +856,7 @@ static int tcp_v4_rtx_synack(struct sock *sk, struct request_sock *req,
855856
struct request_values *rvp)
856857
{
857858
TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_RETRANSSEGS);
858-
return tcp_v4_send_synack(sk, NULL, req, rvp, 0);
859+
return tcp_v4_send_synack(sk, NULL, req, rvp, 0, false);
859860
}
860861

861862
/*
@@ -1388,7 +1389,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
13881389
*/
13891390
if (tmp_opt.saw_tstamp &&
13901391
tcp_death_row.sysctl_tw_recycle &&
1391-
(dst = inet_csk_route_req(sk, &fl4, req)) != NULL &&
1392+
(dst = inet_csk_route_req(sk, &fl4, req, want_cookie)) != NULL &&
13921393
fl4.daddr == saddr &&
13931394
(peer = rt_get_peer((struct rtable *)dst, fl4.daddr)) != NULL) {
13941395
inet_peer_refcheck(peer);
@@ -1424,7 +1425,8 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
14241425

14251426
if (tcp_v4_send_synack(sk, dst, req,
14261427
(struct request_values *)&tmp_ext,
1427-
skb_get_queue_mapping(skb)) ||
1428+
skb_get_queue_mapping(skb),
1429+
want_cookie) ||
14281430
want_cookie)
14291431
goto drop_and_free;
14301432

0 commit comments

Comments
 (0)