Commit 6be49dea authored by Jason Xing's avatar Jason Xing Committed by Paolo Abeni

rstreason: prepare for passive reset

Adjust the parameter and support passing reason of reset which
is for now NOT_SPECIFIED. No functional changes.
Signed-off-by: default avatarJason Xing <kernelxing@tencent.com>
Acked-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 5cb2cb3c
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/refcount.h> #include <linux/refcount.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/rstreason.h>
struct request_sock; struct request_sock;
struct sk_buff; struct sk_buff;
...@@ -34,7 +35,8 @@ struct request_sock_ops { ...@@ -34,7 +35,8 @@ struct request_sock_ops {
void (*send_ack)(const struct sock *sk, struct sk_buff *skb, void (*send_ack)(const struct sock *sk, struct sk_buff *skb,
struct request_sock *req); struct request_sock *req);
void (*send_reset)(const struct sock *sk, void (*send_reset)(const struct sock *sk,
struct sk_buff *skb); struct sk_buff *skb,
enum sk_rst_reason reason);
void (*destructor)(struct request_sock *req); void (*destructor)(struct request_sock *req);
void (*syn_ack_timeout)(const struct request_sock *req); void (*syn_ack_timeout)(const struct request_sock *req);
}; };
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <net/xfrm.h> #include <net/xfrm.h>
#include <net/secure_seq.h> #include <net/secure_seq.h>
#include <net/netns/generic.h> #include <net/netns/generic.h>
#include <net/rstreason.h>
#include "ackvec.h" #include "ackvec.h"
#include "ccid.h" #include "ccid.h"
...@@ -521,7 +522,8 @@ static int dccp_v4_send_response(const struct sock *sk, struct request_sock *req ...@@ -521,7 +522,8 @@ static int dccp_v4_send_response(const struct sock *sk, struct request_sock *req
return err; return err;
} }
static void dccp_v4_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb) static void dccp_v4_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb,
enum sk_rst_reason reason)
{ {
int err; int err;
const struct iphdr *rxiph; const struct iphdr *rxiph;
...@@ -706,7 +708,7 @@ int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -706,7 +708,7 @@ int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
return 0; return 0;
reset: reset:
dccp_v4_ctl_send_reset(sk, skb); dccp_v4_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
} }
...@@ -869,7 +871,7 @@ static int dccp_v4_rcv(struct sk_buff *skb) ...@@ -869,7 +871,7 @@ static int dccp_v4_rcv(struct sk_buff *skb)
if (nsk == sk) { if (nsk == sk) {
reqsk_put(req); reqsk_put(req);
} else if (dccp_child_process(sk, nsk, skb)) { } else if (dccp_child_process(sk, nsk, skb)) {
dccp_v4_ctl_send_reset(sk, skb); dccp_v4_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
goto discard_and_relse; goto discard_and_relse;
} else { } else {
sock_put(sk); sock_put(sk);
...@@ -909,7 +911,7 @@ static int dccp_v4_rcv(struct sk_buff *skb) ...@@ -909,7 +911,7 @@ static int dccp_v4_rcv(struct sk_buff *skb)
if (dh->dccph_type != DCCP_PKT_RESET) { if (dh->dccph_type != DCCP_PKT_RESET) {
DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_SKB_CB(skb)->dccpd_reset_code =
DCCP_RESET_CODE_NO_CONNECTION; DCCP_RESET_CODE_NO_CONNECTION;
dccp_v4_ctl_send_reset(sk, skb); dccp_v4_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
} }
discard_it: discard_it:
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <net/secure_seq.h> #include <net/secure_seq.h>
#include <net/netns/generic.h> #include <net/netns/generic.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/rstreason.h>
#include "dccp.h" #include "dccp.h"
#include "ipv6.h" #include "ipv6.h"
...@@ -256,7 +257,8 @@ static void dccp_v6_reqsk_destructor(struct request_sock *req) ...@@ -256,7 +257,8 @@ static void dccp_v6_reqsk_destructor(struct request_sock *req)
kfree_skb(inet_rsk(req)->pktopts); kfree_skb(inet_rsk(req)->pktopts);
} }
static void dccp_v6_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb) static void dccp_v6_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb,
enum sk_rst_reason reason)
{ {
const struct ipv6hdr *rxip6h; const struct ipv6hdr *rxip6h;
struct sk_buff *skb; struct sk_buff *skb;
...@@ -656,7 +658,7 @@ static int dccp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -656,7 +658,7 @@ static int dccp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
return 0; return 0;
reset: reset:
dccp_v6_ctl_send_reset(sk, skb); dccp_v6_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
discard: discard:
if (opt_skb != NULL) if (opt_skb != NULL)
__kfree_skb(opt_skb); __kfree_skb(opt_skb);
...@@ -762,7 +764,7 @@ static int dccp_v6_rcv(struct sk_buff *skb) ...@@ -762,7 +764,7 @@ static int dccp_v6_rcv(struct sk_buff *skb)
if (nsk == sk) { if (nsk == sk) {
reqsk_put(req); reqsk_put(req);
} else if (dccp_child_process(sk, nsk, skb)) { } else if (dccp_child_process(sk, nsk, skb)) {
dccp_v6_ctl_send_reset(sk, skb); dccp_v6_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
goto discard_and_relse; goto discard_and_relse;
} else { } else {
sock_put(sk); sock_put(sk);
...@@ -801,7 +803,7 @@ static int dccp_v6_rcv(struct sk_buff *skb) ...@@ -801,7 +803,7 @@ static int dccp_v6_rcv(struct sk_buff *skb)
if (dh->dccph_type != DCCP_PKT_RESET) { if (dh->dccph_type != DCCP_PKT_RESET) {
DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_SKB_CB(skb)->dccpd_reset_code =
DCCP_RESET_CODE_NO_CONNECTION; DCCP_RESET_CODE_NO_CONNECTION;
dccp_v6_ctl_send_reset(sk, skb); dccp_v6_ctl_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
} }
discard_it: discard_it:
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <net/sock.h> #include <net/sock.h>
#include <net/xfrm.h> #include <net/xfrm.h>
#include <net/inet_timewait_sock.h> #include <net/inet_timewait_sock.h>
#include <net/rstreason.h>
#include "ackvec.h" #include "ackvec.h"
#include "ccid.h" #include "ccid.h"
...@@ -202,7 +203,7 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb, ...@@ -202,7 +203,7 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,
DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_TOO_BUSY; DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_TOO_BUSY;
drop: drop:
if (dccp_hdr(skb)->dccph_type != DCCP_PKT_RESET) if (dccp_hdr(skb)->dccph_type != DCCP_PKT_RESET)
req->rsk_ops->send_reset(sk, skb); req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
inet_csk_reqsk_queue_drop(sk, req); inet_csk_reqsk_queue_drop(sk, req);
out: out:
......
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
#include <net/xfrm.h> #include <net/xfrm.h>
#include <net/secure_seq.h> #include <net/secure_seq.h>
#include <net/busy_poll.h> #include <net/busy_poll.h>
#include <net/rstreason.h>
#include <linux/inet.h> #include <linux/inet.h>
#include <linux/ipv6.h> #include <linux/ipv6.h>
...@@ -723,7 +724,8 @@ static bool tcp_v4_ao_sign_reset(const struct sock *sk, struct sk_buff *skb, ...@@ -723,7 +724,8 @@ static bool tcp_v4_ao_sign_reset(const struct sock *sk, struct sk_buff *skb,
* Exception: precedence violation. We do not implement it in any case. * Exception: precedence violation. We do not implement it in any case.
*/ */
static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb) static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb,
enum sk_rst_reason reason)
{ {
const struct tcphdr *th = tcp_hdr(skb); const struct tcphdr *th = tcp_hdr(skb);
struct { struct {
...@@ -1934,7 +1936,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -1934,7 +1936,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
return 0; return 0;
reset: reset:
tcp_v4_send_reset(rsk, skb); tcp_v4_send_reset(rsk, skb, SK_RST_REASON_NOT_SPECIFIED);
discard: discard:
kfree_skb_reason(skb, reason); kfree_skb_reason(skb, reason);
/* Be careful here. If this function gets more complicated and /* Be careful here. If this function gets more complicated and
...@@ -2285,7 +2287,7 @@ int tcp_v4_rcv(struct sk_buff *skb) ...@@ -2285,7 +2287,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
} else { } else {
drop_reason = tcp_child_process(sk, nsk, skb); drop_reason = tcp_child_process(sk, nsk, skb);
if (drop_reason) { if (drop_reason) {
tcp_v4_send_reset(nsk, skb); tcp_v4_send_reset(nsk, skb, SK_RST_REASON_NOT_SPECIFIED);
goto discard_and_relse; goto discard_and_relse;
} }
sock_put(sk); sock_put(sk);
...@@ -2364,7 +2366,7 @@ int tcp_v4_rcv(struct sk_buff *skb) ...@@ -2364,7 +2366,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
bad_packet: bad_packet:
__TCP_INC_STATS(net, TCP_MIB_INERRS); __TCP_INC_STATS(net, TCP_MIB_INERRS);
} else { } else {
tcp_v4_send_reset(NULL, skb); tcp_v4_send_reset(NULL, skb, SK_RST_REASON_NOT_SPECIFIED);
} }
discard_it: discard_it:
...@@ -2416,7 +2418,7 @@ int tcp_v4_rcv(struct sk_buff *skb) ...@@ -2416,7 +2418,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
tcp_v4_timewait_ack(sk, skb); tcp_v4_timewait_ack(sk, skb);
break; break;
case TCP_TW_RST: case TCP_TW_RST:
tcp_v4_send_reset(sk, skb); tcp_v4_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
inet_twsk_deschedule_put(inet_twsk(sk)); inet_twsk_deschedule_put(inet_twsk(sk));
goto discard_it; goto discard_it;
case TCP_TW_SUCCESS:; case TCP_TW_SUCCESS:;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <net/tcp.h> #include <net/tcp.h>
#include <net/xfrm.h> #include <net/xfrm.h>
#include <net/busy_poll.h> #include <net/busy_poll.h>
#include <net/rstreason.h>
static bool tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win) static bool tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win)
{ {
...@@ -878,7 +879,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, ...@@ -878,7 +879,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
* avoid becoming vulnerable to outside attack aiming at * avoid becoming vulnerable to outside attack aiming at
* resetting legit local connections. * resetting legit local connections.
*/ */
req->rsk_ops->send_reset(sk, skb); req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
} else if (fastopen) { /* received a valid RST pkt */ } else if (fastopen) { /* received a valid RST pkt */
reqsk_fastopen_remove(sk, req, true); reqsk_fastopen_remove(sk, req, true);
tcp_reset(sk, skb); tcp_reset(sk, skb);
......
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include <net/secure_seq.h> #include <net/secure_seq.h>
#include <net/hotdata.h> #include <net/hotdata.h>
#include <net/busy_poll.h> #include <net/busy_poll.h>
#include <net/rstreason.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
...@@ -69,7 +70,8 @@ ...@@ -69,7 +70,8 @@
#include <trace/events/tcp.h> #include <trace/events/tcp.h>
static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb); static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb,
enum sk_rst_reason reason);
static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb, static void tcp_v6_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
struct request_sock *req); struct request_sock *req);
...@@ -1008,7 +1010,8 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 ...@@ -1008,7 +1010,8 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32
kfree_skb(buff); kfree_skb(buff);
} }
static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb) static void tcp_v6_send_reset(const struct sock *sk, struct sk_buff *skb,
enum sk_rst_reason reason)
{ {
const struct tcphdr *th = tcp_hdr(skb); const struct tcphdr *th = tcp_hdr(skb);
struct ipv6hdr *ipv6h = ipv6_hdr(skb); struct ipv6hdr *ipv6h = ipv6_hdr(skb);
...@@ -1677,7 +1680,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -1677,7 +1680,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
return 0; return 0;
reset: reset:
tcp_v6_send_reset(sk, skb); tcp_v6_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
discard: discard:
if (opt_skb) if (opt_skb)
__kfree_skb(opt_skb); __kfree_skb(opt_skb);
...@@ -1862,7 +1865,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) ...@@ -1862,7 +1865,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
} else { } else {
drop_reason = tcp_child_process(sk, nsk, skb); drop_reason = tcp_child_process(sk, nsk, skb);
if (drop_reason) { if (drop_reason) {
tcp_v6_send_reset(nsk, skb); tcp_v6_send_reset(nsk, skb, SK_RST_REASON_NOT_SPECIFIED);
goto discard_and_relse; goto discard_and_relse;
} }
sock_put(sk); sock_put(sk);
...@@ -1939,7 +1942,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) ...@@ -1939,7 +1942,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
bad_packet: bad_packet:
__TCP_INC_STATS(net, TCP_MIB_INERRS); __TCP_INC_STATS(net, TCP_MIB_INERRS);
} else { } else {
tcp_v6_send_reset(NULL, skb); tcp_v6_send_reset(NULL, skb, SK_RST_REASON_NOT_SPECIFIED);
} }
discard_it: discard_it:
...@@ -1995,7 +1998,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) ...@@ -1995,7 +1998,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
tcp_v6_timewait_ack(sk, skb); tcp_v6_timewait_ack(sk, skb);
break; break;
case TCP_TW_RST: case TCP_TW_RST:
tcp_v6_send_reset(sk, skb); tcp_v6_send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
inet_twsk_deschedule_put(inet_twsk(sk)); inet_twsk_deschedule_put(inet_twsk(sk));
goto discard_it; goto discard_it;
case TCP_TW_SUCCESS: case TCP_TW_SUCCESS:
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include <net/transp_v6.h> #include <net/transp_v6.h>
#endif #endif
#include <net/mptcp.h> #include <net/mptcp.h>
#include <net/rstreason.h>
#include "protocol.h" #include "protocol.h"
#include "mib.h" #include "mib.h"
...@@ -308,7 +310,7 @@ static struct dst_entry *subflow_v4_route_req(const struct sock *sk, ...@@ -308,7 +310,7 @@ static struct dst_entry *subflow_v4_route_req(const struct sock *sk,
dst_release(dst); dst_release(dst);
if (!req->syncookie) if (!req->syncookie)
tcp_request_sock_ops.send_reset(sk, skb); tcp_request_sock_ops.send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
return NULL; return NULL;
} }
...@@ -376,7 +378,7 @@ static struct dst_entry *subflow_v6_route_req(const struct sock *sk, ...@@ -376,7 +378,7 @@ static struct dst_entry *subflow_v6_route_req(const struct sock *sk,
dst_release(dst); dst_release(dst);
if (!req->syncookie) if (!req->syncookie)
tcp6_request_sock_ops.send_reset(sk, skb); tcp6_request_sock_ops.send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
return NULL; return NULL;
} }
#endif #endif
...@@ -911,7 +913,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, ...@@ -911,7 +913,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
tcp_rsk(req)->drop_req = true; tcp_rsk(req)->drop_req = true;
inet_csk_prepare_for_destroy_sock(child); inet_csk_prepare_for_destroy_sock(child);
tcp_done(child); tcp_done(child);
req->rsk_ops->send_reset(sk, skb); req->rsk_ops->send_reset(sk, skb, SK_RST_REASON_NOT_SPECIFIED);
/* The last child reference will be released by the caller */ /* The last child reference will be released by the caller */
return child; return child;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment