Skip to content

Commit f6c0f5d

Browse files
edumazetdavem330
authored andcommitted
tcp: honor SO_PRIORITY in TIME_WAIT state
ctl packets sent on behalf of TIME_WAIT sockets currently have a zero skb->priority, which can cause various problems. In this patch we : - add a tw_priority field in struct inet_timewait_sock. - populate it from sk->sk_priority when a TIME_WAIT is created. - For IPv4, change ip_send_unicast_reply() and its two callers to propagate tw_priority correctly. ip_send_unicast_reply() no longer changes sk->sk_priority. - For IPv6, make sure TIME_WAIT sockets pass their tw_priority field to tcp_v6_send_response() and tcp_v6_send_ack(). Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e9a5dce commit f6c0f5d

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

include/net/inet_timewait_sock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct inet_timewait_sock {
7171
tw_pad : 2, /* 2 bits hole */
7272
tw_tos : 8;
7373
u32 tw_txhash;
74+
u32 tw_priority;
7475
struct timer_list tw_timer;
7576
struct inet_bind_bucket *tw_tb;
7677
};

net/ipv4/ip_output.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,6 @@ void ip_send_unicast_reply(struct sock *sk, struct sk_buff *skb,
16941694

16951695
inet_sk(sk)->tos = arg->tos;
16961696

1697-
sk->sk_priority = skb->priority;
16981697
sk->sk_protocol = ip_hdr(skb)->protocol;
16991698
sk->sk_bound_dev_if = arg->bound_dev_if;
17001699
sk->sk_sndbuf = sysctl_wmem_default;

net/ipv4/tcp_ipv4.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
771771
if (sk) {
772772
ctl_sk->sk_mark = (sk->sk_state == TCP_TIME_WAIT) ?
773773
inet_twsk(sk)->tw_mark : sk->sk_mark;
774+
ctl_sk->sk_priority = (sk->sk_state == TCP_TIME_WAIT) ?
775+
inet_twsk(sk)->tw_priority : sk->sk_priority;
774776
transmit_time = tcp_transmit_time(sk);
775777
}
776778
ip_send_unicast_reply(ctl_sk,
@@ -866,6 +868,8 @@ static void tcp_v4_send_ack(const struct sock *sk,
866868
ctl_sk = this_cpu_read(*net->ipv4.tcp_sk);
867869
ctl_sk->sk_mark = (sk->sk_state == TCP_TIME_WAIT) ?
868870
inet_twsk(sk)->tw_mark : sk->sk_mark;
871+
ctl_sk->sk_priority = (sk->sk_state == TCP_TIME_WAIT) ?
872+
inet_twsk(sk)->tw_priority : sk->sk_priority;
869873
transmit_time = tcp_transmit_time(sk);
870874
ip_send_unicast_reply(ctl_sk,
871875
skb, &TCP_SKB_CB(skb)->header.h4.opt,

net/ipv4/tcp_minisocks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
266266

267267
tw->tw_transparent = inet->transparent;
268268
tw->tw_mark = sk->sk_mark;
269+
tw->tw_priority = sk->sk_priority;
269270
tw->tw_rcv_wscale = tp->rx_opt.rcv_wscale;
270271
tcptw->tw_rcv_nxt = tp->rcv_nxt;
271272
tcptw->tw_snd_nxt = tp->snd_nxt;

net/ipv6/tcp_ipv6.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,10 @@ static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb)
995995
label = ip6_flowlabel(ipv6h);
996996
priority = sk->sk_priority;
997997
}
998-
if (sk->sk_state == TCP_TIME_WAIT)
998+
if (sk->sk_state == TCP_TIME_WAIT) {
999999
label = cpu_to_be32(inet_twsk(sk)->tw_flowlabel);
1000+
priority = inet_twsk(sk)->tw_priority;
1001+
}
10001002
} else {
10011003
if (net->ipv6.sysctl.flowlabel_reflect & FLOWLABEL_REFLECT_TCP_RESET)
10021004
label = ip6_flowlabel(ipv6h);
@@ -1029,7 +1031,7 @@ static void tcp_v6_timewait_ack(struct sock *sk, struct sk_buff *skb)
10291031
tcptw->tw_rcv_wnd >> tw->tw_rcv_wscale,
10301032
tcp_time_stamp_raw() + tcptw->tw_ts_offset,
10311033
tcptw->tw_ts_recent, tw->tw_bound_dev_if, tcp_twsk_md5_key(tcptw),
1032-
tw->tw_tclass, cpu_to_be32(tw->tw_flowlabel), 0);
1034+
tw->tw_tclass, cpu_to_be32(tw->tw_flowlabel), tw->tw_priority);
10331035

10341036
inet_twsk_put(tw);
10351037
}

0 commit comments

Comments
 (0)