Commit 1330b6ef authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

skb: make drop reason booleanable

We have a number of cases where function returns drop/no drop
decision as a boolean. Now that we want to report the reason
code as well we have to pass extra output arguments.

We can make the reason code evaluate correctly as bool.

I believe we're good to reorder the reasons as they are
reported to user space as strings.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 11633199
...@@ -314,6 +314,7 @@ struct sk_buff; ...@@ -314,6 +314,7 @@ struct sk_buff;
* used to translate the reason to string. * used to translate the reason to string.
*/ */
enum skb_drop_reason { enum skb_drop_reason {
SKB_NOT_DROPPED_YET = 0,
SKB_DROP_REASON_NOT_SPECIFIED, /* drop reason is not specified */ SKB_DROP_REASON_NOT_SPECIFIED, /* drop reason is not specified */
SKB_DROP_REASON_NO_SOCKET, /* socket not found */ SKB_DROP_REASON_NO_SOCKET, /* socket not found */
SKB_DROP_REASON_PKT_TOO_SMALL, /* packet size is too small */ SKB_DROP_REASON_PKT_TOO_SMALL, /* packet size is too small */
......
...@@ -1674,8 +1674,9 @@ tcp_md5_do_lookup(const struct sock *sk, int l3index, ...@@ -1674,8 +1674,9 @@ tcp_md5_do_lookup(const struct sock *sk, int l3index,
return NULL; return NULL;
return __tcp_md5_do_lookup(sk, l3index, addr, family); return __tcp_md5_do_lookup(sk, l3index, addr, family);
} }
bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
enum skb_drop_reason *reason, enum skb_drop_reason
tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
const void *saddr, const void *daddr, const void *saddr, const void *daddr,
int family, int dif, int sdif); int family, int dif, int sdif);
...@@ -1688,13 +1689,13 @@ tcp_md5_do_lookup(const struct sock *sk, int l3index, ...@@ -1688,13 +1689,13 @@ tcp_md5_do_lookup(const struct sock *sk, int l3index,
{ {
return NULL; return NULL;
} }
static inline bool tcp_inbound_md5_hash(const struct sock *sk,
const struct sk_buff *skb, static inline enum skb_drop_reason
enum skb_drop_reason *reason, tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
const void *saddr, const void *daddr, const void *saddr, const void *daddr,
int family, int dif, int sdif) int family, int dif, int sdif);
{ {
return false; return SKB_NOT_DROPPED_YET;
} }
#define tcp_twsk_md5_key(twsk) NULL #define tcp_twsk_md5_key(twsk) NULL
#endif #endif
......
...@@ -4434,8 +4434,8 @@ int tcp_md5_hash_key(struct tcp_md5sig_pool *hp, const struct tcp_md5sig_key *ke ...@@ -4434,8 +4434,8 @@ int tcp_md5_hash_key(struct tcp_md5sig_pool *hp, const struct tcp_md5sig_key *ke
EXPORT_SYMBOL(tcp_md5_hash_key); EXPORT_SYMBOL(tcp_md5_hash_key);
/* Called with rcu_read_lock() */ /* Called with rcu_read_lock() */
bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb, enum skb_drop_reason
enum skb_drop_reason *reason, tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
const void *saddr, const void *daddr, const void *saddr, const void *daddr,
int family, int dif, int sdif) int family, int dif, int sdif)
{ {
...@@ -4464,18 +4464,16 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb, ...@@ -4464,18 +4464,16 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
/* We've parsed the options - do we have a hash? */ /* We've parsed the options - do we have a hash? */
if (!hash_expected && !hash_location) if (!hash_expected && !hash_location)
return false; return SKB_NOT_DROPPED_YET;
if (hash_expected && !hash_location) { if (hash_expected && !hash_location) {
*reason = SKB_DROP_REASON_TCP_MD5NOTFOUND;
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND);
return true; return SKB_DROP_REASON_TCP_MD5NOTFOUND;
} }
if (!hash_expected && hash_location) { if (!hash_expected && hash_location) {
*reason = SKB_DROP_REASON_TCP_MD5UNEXPECTED;
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED);
return true; return SKB_DROP_REASON_TCP_MD5UNEXPECTED;
} }
/* check the signature */ /* check the signature */
...@@ -4483,7 +4481,6 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb, ...@@ -4483,7 +4481,6 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
NULL, skb); NULL, skb);
if (genhash || memcmp(hash_location, newhash, 16) != 0) { if (genhash || memcmp(hash_location, newhash, 16) != 0) {
*reason = SKB_DROP_REASON_TCP_MD5FAILURE;
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5FAILURE); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5FAILURE);
if (family == AF_INET) { if (family == AF_INET) {
net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s L3 index %d\n", net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s L3 index %d\n",
...@@ -4497,9 +4494,9 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb, ...@@ -4497,9 +4494,9 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
saddr, ntohs(th->source), saddr, ntohs(th->source),
daddr, ntohs(th->dest), l3index); daddr, ntohs(th->dest), l3index);
} }
return true; return SKB_DROP_REASON_TCP_MD5FAILURE;
} }
return false; return SKB_NOT_DROPPED_YET;
} }
EXPORT_SYMBOL(tcp_inbound_md5_hash); EXPORT_SYMBOL(tcp_inbound_md5_hash);
......
...@@ -1965,9 +1965,10 @@ int tcp_v4_rcv(struct sk_buff *skb) ...@@ -1965,9 +1965,10 @@ int tcp_v4_rcv(struct sk_buff *skb)
struct sock *nsk; struct sock *nsk;
sk = req->rsk_listener; sk = req->rsk_listener;
if (unlikely(tcp_inbound_md5_hash(sk, skb, &drop_reason, drop_reason = tcp_inbound_md5_hash(sk, skb,
&iph->saddr, &iph->daddr, &iph->saddr, &iph->daddr,
AF_INET, dif, sdif))) { AF_INET, dif, sdif);
if (unlikely(drop_reason)) {
sk_drops_add(sk, skb); sk_drops_add(sk, skb);
reqsk_put(req); reqsk_put(req);
goto discard_it; goto discard_it;
...@@ -2041,8 +2042,9 @@ int tcp_v4_rcv(struct sk_buff *skb) ...@@ -2041,8 +2042,9 @@ int tcp_v4_rcv(struct sk_buff *skb)
goto discard_and_relse; goto discard_and_relse;
} }
if (tcp_inbound_md5_hash(sk, skb, &drop_reason, &iph->saddr, drop_reason = tcp_inbound_md5_hash(sk, skb, &iph->saddr,
&iph->daddr, AF_INET, dif, sdif)) &iph->daddr, AF_INET, dif, sdif);
if (drop_reason)
goto discard_and_relse; goto discard_and_relse;
nf_reset_ct(skb); nf_reset_ct(skb);
......
...@@ -1632,8 +1632,10 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) ...@@ -1632,8 +1632,10 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
struct sock *nsk; struct sock *nsk;
sk = req->rsk_listener; sk = req->rsk_listener;
if (tcp_inbound_md5_hash(sk, skb, &drop_reason, &hdr->saddr, drop_reason = tcp_inbound_md5_hash(sk, skb,
&hdr->daddr, AF_INET6, dif, sdif)) { &hdr->saddr, &hdr->daddr,
AF_INET6, dif, sdif);
if (drop_reason) {
sk_drops_add(sk, skb); sk_drops_add(sk, skb);
reqsk_put(req); reqsk_put(req);
goto discard_it; goto discard_it;
...@@ -1704,8 +1706,9 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) ...@@ -1704,8 +1706,9 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
goto discard_and_relse; goto discard_and_relse;
} }
if (tcp_inbound_md5_hash(sk, skb, &drop_reason, &hdr->saddr, drop_reason = tcp_inbound_md5_hash(sk, skb, &hdr->saddr, &hdr->daddr,
&hdr->daddr, AF_INET6, dif, sdif)) AF_INET6, dif, sdif);
if (drop_reason)
goto discard_and_relse; goto discard_and_relse;
if (tcp_filter(sk, skb)) { if (tcp_filter(sk, skb)) {
......
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