net: ipv4: add skb drop reasons to ip_error()

Eventually, I find out the handler function for inputting route lookup
fail: ip_error().

The drop reasons we used in ip_error() are almost corresponding to
IPSTATS_MIB_*, and following new reasons are introduced:

SKB_DROP_REASON_IP_INADDRERRORS
SKB_DROP_REASON_IP_INNOROUTES

Isn't the name SKB_DROP_REASON_IP_HOSTUNREACH and
SKB_DROP_REASON_IP_NETUNREACH more accurate? To make them corresponding
to IPSTATS_MIB_*, we keep their name still.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
Reviewed-by: Jiang Biao <benbjiang@tencent.com>
Reviewed-by: Hao Peng <flyingpeng@tencent.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Menglong Dong 2022-04-13 16:15:53 +08:00 committed by David S. Miller
parent d6d3146ce5
commit c4eb664191
3 changed files with 13 additions and 1 deletions

View File

@ -447,6 +447,12 @@ enum skb_drop_reason {
* 2211, such as a broadcasts * 2211, such as a broadcasts
* ICMP_TIMESTAMP * ICMP_TIMESTAMP
*/ */
SKB_DROP_REASON_IP_INADDRERRORS, /* host unreachable, corresponding
* to IPSTATS_MIB_INADDRERRORS
*/
SKB_DROP_REASON_IP_INNOROUTES, /* network unreachable, corresponding
* to IPSTATS_MIB_INADDRERRORS
*/
SKB_DROP_REASON_MAX, SKB_DROP_REASON_MAX,
}; };

View File

@ -63,6 +63,8 @@
EM(SKB_DROP_REASON_TAP_TXFILTER, TAP_TXFILTER) \ EM(SKB_DROP_REASON_TAP_TXFILTER, TAP_TXFILTER) \
EM(SKB_DROP_REASON_ICMP_CSUM, ICMP_CSUM) \ EM(SKB_DROP_REASON_ICMP_CSUM, ICMP_CSUM) \
EM(SKB_DROP_REASON_INVALID_PROTO, INVALID_PROTO) \ EM(SKB_DROP_REASON_INVALID_PROTO, INVALID_PROTO) \
EM(SKB_DROP_REASON_IP_INADDRERRORS, IP_INADDRERRORS) \
EM(SKB_DROP_REASON_IP_INNOROUTES, IP_INNOROUTES) \
EMe(SKB_DROP_REASON_MAX, MAX) EMe(SKB_DROP_REASON_MAX, MAX)
#undef EM #undef EM

View File

@ -945,6 +945,7 @@ static int ip_error(struct sk_buff *skb)
struct inet_peer *peer; struct inet_peer *peer;
unsigned long now; unsigned long now;
struct net *net; struct net *net;
SKB_DR(reason);
bool send; bool send;
int code; int code;
@ -964,10 +965,12 @@ static int ip_error(struct sk_buff *skb)
if (!IN_DEV_FORWARD(in_dev)) { if (!IN_DEV_FORWARD(in_dev)) {
switch (rt->dst.error) { switch (rt->dst.error) {
case EHOSTUNREACH: case EHOSTUNREACH:
SKB_DR_SET(reason, IP_INADDRERRORS);
__IP_INC_STATS(net, IPSTATS_MIB_INADDRERRORS); __IP_INC_STATS(net, IPSTATS_MIB_INADDRERRORS);
break; break;
case ENETUNREACH: case ENETUNREACH:
SKB_DR_SET(reason, IP_INNOROUTES);
__IP_INC_STATS(net, IPSTATS_MIB_INNOROUTES); __IP_INC_STATS(net, IPSTATS_MIB_INNOROUTES);
break; break;
} }
@ -983,6 +986,7 @@ static int ip_error(struct sk_buff *skb)
break; break;
case ENETUNREACH: case ENETUNREACH:
code = ICMP_NET_UNREACH; code = ICMP_NET_UNREACH;
SKB_DR_SET(reason, IP_INNOROUTES);
__IP_INC_STATS(net, IPSTATS_MIB_INNOROUTES); __IP_INC_STATS(net, IPSTATS_MIB_INNOROUTES);
break; break;
case EACCES: case EACCES:
@ -1009,7 +1013,7 @@ static int ip_error(struct sk_buff *skb)
if (send) if (send)
icmp_send(skb, ICMP_DEST_UNREACH, code, 0); icmp_send(skb, ICMP_DEST_UNREACH, code, 0);
out: kfree_skb(skb); out: kfree_skb_reason(skb, reason);
return 0; return 0;
} }