net: tcp: add skb drop reasons to route_req()

Add skb drop reasons to the route_req() in struct tcp_request_sock_ops.
Following functions are involved:

  tcp_v4_route_req()
  tcp_v6_route_req()
  subflow_v4_route_req()
  subflow_v6_route_req()

And the new reason SKB_DROP_REASON_LSM is added, which is used when
skb is dropped by LSM.

Reviewed-by: Jiang Biao <benbjiang@tencent.com>
Reviewed-by: Hao Peng <flyingpeng@tencent.com>
Signed-off-by: Menglong Dong <imagedong@tencent.com>
This commit is contained in:
Menglong Dong 2022-06-09 15:43:54 +08:00
parent 212fff12aa
commit 1edd2e3639
5 changed files with 21 additions and 6 deletions

View File

@ -264,6 +264,8 @@ enum skb_drop_reason {
* 'SYN' packet
*/
SKB_DROP_REASON_TIMEWAIT,
/** @SKB_DROP_REASON_LSM: dropped by LSM */
SKB_DROP_REASON_LSM,
/**
* @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be
* used as a real 'reason'

View File

@ -2035,7 +2035,8 @@ struct tcp_request_sock_ops {
__u16 *mss);
#endif
struct dst_entry *(*route_req)(const struct sock *sk, struct flowi *fl,
const struct request_sock *req);
struct request_sock *req,
enum skb_drop_reason *reason);
u32 (*init_seq)(const struct sk_buff *skb);
u32 (*init_ts_off)(const struct net *net, const struct sk_buff *skb);
int (*send_synack)(const struct sock *sk, struct dst_entry *dst,

View File

@ -6746,7 +6746,7 @@ enum skb_drop_reason tcp_conn_request(struct request_sock_ops *rsk_ops,
if (tmp_opt.tstamp_ok)
tcp_rsk(req)->ts_off = af_ops->init_ts_off(net, skb);
dst = af_ops->route_req(sk, &fl, req);
dst = af_ops->route_req(sk, &fl, req, &reason);
if (!dst)
goto drop_and_free;

View File

@ -1370,9 +1370,15 @@ static void tcp_v4_init_req(struct request_sock *req,
static struct dst_entry *tcp_v4_route_req(const struct sock *sk,
struct flowi *fl,
const struct request_sock *req)
struct request_sock *req,
enum skb_drop_reason *reason)
{
return inet_csk_route_req(sk, &fl->u.ip4, req);
struct dst_entry *dst;
dst = inet_csk_route_req(sk, &fl->u.ip4, req);
if (!dst)
SKB_DR_SET(*reason, IP_OUTNOROUTES);
return dst;
}
struct request_sock_ops tcp_request_sock_ops __read_mostly = {

View File

@ -770,9 +770,15 @@ static void tcp_v6_init_req(struct request_sock *req,
static struct dst_entry *tcp_v6_route_req(const struct sock *sk,
struct flowi *fl,
const struct request_sock *req)
struct request_sock *req,
enum skb_drop_reason *reason)
{
return inet6_csk_route_req(sk, &fl->u.ip6, req, IPPROTO_TCP);
struct dst_entry *dst;
dst = inet6_csk_route_req(sk, &fl->u.ip6, req, IPPROTO_TCP);
if (!dst)
SKB_DR_SET(*reason, IP_OUTNOROUTES);
return dst;
}
struct request_sock_ops tcp6_request_sock_ops __read_mostly = {