Commit 2edc1a38 authored by Menglong Dong's avatar Menglong Dong Committed by David S. Miller

net: ip: add skb drop reasons to ip forwarding

Replace kfree_skb() which is used in ip6_forward() and ip_forward()
with kfree_skb_reason().

The new drop reason 'SKB_DROP_REASON_PKT_TOO_BIG' is introduced for
the case that the length of the packet exceeds MTU and can't
fragment.
Signed-off-by: default avatarMenglong Dong <imagedong@tencent.com>
Reviewed-by: default avatarJiang Biao <benbjiang@tencent.com>
Reviewed-by: default avatarHao Peng <flyingpeng@tencent.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3ae42cc8
...@@ -453,6 +453,9 @@ enum skb_drop_reason { ...@@ -453,6 +453,9 @@ enum skb_drop_reason {
SKB_DROP_REASON_IP_INNOROUTES, /* network unreachable, corresponding SKB_DROP_REASON_IP_INNOROUTES, /* network unreachable, corresponding
* to IPSTATS_MIB_INADDRERRORS * to IPSTATS_MIB_INADDRERRORS
*/ */
SKB_DROP_REASON_PKT_TOO_BIG, /* packet size is too big (maybe exceed
* the MTU)
*/
SKB_DROP_REASON_MAX, SKB_DROP_REASON_MAX,
}; };
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
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_INADDRERRORS, IP_INADDRERRORS) \
EM(SKB_DROP_REASON_IP_INNOROUTES, IP_INNOROUTES) \ EM(SKB_DROP_REASON_IP_INNOROUTES, IP_INNOROUTES) \
EM(SKB_DROP_REASON_PKT_TOO_BIG, PKT_TOO_BIG) \
EMe(SKB_DROP_REASON_MAX, MAX) EMe(SKB_DROP_REASON_MAX, MAX)
#undef EM #undef EM
......
...@@ -90,6 +90,7 @@ int ip_forward(struct sk_buff *skb) ...@@ -90,6 +90,7 @@ int ip_forward(struct sk_buff *skb)
struct rtable *rt; /* Route we use */ struct rtable *rt; /* Route we use */
struct ip_options *opt = &(IPCB(skb)->opt); struct ip_options *opt = &(IPCB(skb)->opt);
struct net *net; struct net *net;
SKB_DR(reason);
/* that should never happen */ /* that should never happen */
if (skb->pkt_type != PACKET_HOST) if (skb->pkt_type != PACKET_HOST)
...@@ -101,8 +102,10 @@ int ip_forward(struct sk_buff *skb) ...@@ -101,8 +102,10 @@ int ip_forward(struct sk_buff *skb)
if (skb_warn_if_lro(skb)) if (skb_warn_if_lro(skb))
goto drop; goto drop;
if (!xfrm4_policy_check(NULL, XFRM_POLICY_FWD, skb)) if (!xfrm4_policy_check(NULL, XFRM_POLICY_FWD, skb)) {
SKB_DR_SET(reason, XFRM_POLICY);
goto drop; goto drop;
}
if (IPCB(skb)->opt.router_alert && ip_call_ra_chain(skb)) if (IPCB(skb)->opt.router_alert && ip_call_ra_chain(skb))
return NET_RX_SUCCESS; return NET_RX_SUCCESS;
...@@ -118,8 +121,10 @@ int ip_forward(struct sk_buff *skb) ...@@ -118,8 +121,10 @@ int ip_forward(struct sk_buff *skb)
if (ip_hdr(skb)->ttl <= 1) if (ip_hdr(skb)->ttl <= 1)
goto too_many_hops; goto too_many_hops;
if (!xfrm4_route_forward(skb)) if (!xfrm4_route_forward(skb)) {
SKB_DR_SET(reason, XFRM_POLICY);
goto drop; goto drop;
}
rt = skb_rtable(skb); rt = skb_rtable(skb);
...@@ -132,6 +137,7 @@ int ip_forward(struct sk_buff *skb) ...@@ -132,6 +137,7 @@ int ip_forward(struct sk_buff *skb)
IP_INC_STATS(net, IPSTATS_MIB_FRAGFAILS); IP_INC_STATS(net, IPSTATS_MIB_FRAGFAILS);
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
htonl(mtu)); htonl(mtu));
SKB_DR_SET(reason, PKT_TOO_BIG);
goto drop; goto drop;
} }
...@@ -169,7 +175,8 @@ int ip_forward(struct sk_buff *skb) ...@@ -169,7 +175,8 @@ int ip_forward(struct sk_buff *skb)
/* Tell the sender its packet died... */ /* Tell the sender its packet died... */
__IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS);
icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0); icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0);
SKB_DR_SET(reason, IP_INHDR);
drop: drop:
kfree_skb(skb); kfree_skb_reason(skb, reason);
return NET_RX_DROP; return NET_RX_DROP;
} }
...@@ -469,6 +469,7 @@ int ip6_forward(struct sk_buff *skb) ...@@ -469,6 +469,7 @@ int ip6_forward(struct sk_buff *skb)
struct inet6_skb_parm *opt = IP6CB(skb); struct inet6_skb_parm *opt = IP6CB(skb);
struct net *net = dev_net(dst->dev); struct net *net = dev_net(dst->dev);
struct inet6_dev *idev; struct inet6_dev *idev;
SKB_DR(reason);
u32 mtu; u32 mtu;
idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif)); idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif));
...@@ -518,7 +519,7 @@ int ip6_forward(struct sk_buff *skb) ...@@ -518,7 +519,7 @@ int ip6_forward(struct sk_buff *skb)
icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0); icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0);
__IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
kfree_skb(skb); kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR);
return -ETIMEDOUT; return -ETIMEDOUT;
} }
...@@ -537,6 +538,7 @@ int ip6_forward(struct sk_buff *skb) ...@@ -537,6 +538,7 @@ int ip6_forward(struct sk_buff *skb)
if (!xfrm6_route_forward(skb)) { if (!xfrm6_route_forward(skb)) {
__IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS); __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
SKB_DR_SET(reason, XFRM_POLICY);
goto drop; goto drop;
} }
dst = skb_dst(skb); dst = skb_dst(skb);
...@@ -596,7 +598,7 @@ int ip6_forward(struct sk_buff *skb) ...@@ -596,7 +598,7 @@ int ip6_forward(struct sk_buff *skb)
__IP6_INC_STATS(net, idev, IPSTATS_MIB_INTOOBIGERRORS); __IP6_INC_STATS(net, idev, IPSTATS_MIB_INTOOBIGERRORS);
__IP6_INC_STATS(net, ip6_dst_idev(dst), __IP6_INC_STATS(net, ip6_dst_idev(dst),
IPSTATS_MIB_FRAGFAILS); IPSTATS_MIB_FRAGFAILS);
kfree_skb(skb); kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_BIG);
return -EMSGSIZE; return -EMSGSIZE;
} }
...@@ -618,8 +620,9 @@ int ip6_forward(struct sk_buff *skb) ...@@ -618,8 +620,9 @@ int ip6_forward(struct sk_buff *skb)
error: error:
__IP6_INC_STATS(net, idev, IPSTATS_MIB_INADDRERRORS); __IP6_INC_STATS(net, idev, IPSTATS_MIB_INADDRERRORS);
SKB_DR_SET(reason, IP_INADDRERRORS);
drop: drop:
kfree_skb(skb); kfree_skb_reason(skb, reason);
return -EINVAL; return -EINVAL;
} }
......
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