Skip to content

Commit d9340d1

Browse files
image-dragonPaolo Abeni
authored andcommitted
net: ip: make ip_mkroute_input/__mkroute_input return drop reasons
In this commit, we make ip_mkroute_input() and __mkroute_input() return drop reasons. The drop reason "SKB_DROP_REASON_ARP_PVLAN_DISABLE" is introduced for the case: the packet which is not IP is forwarded to the in_dev, and the proxy_arp_pvlan is not enabled. Signed-off-by: Menglong Dong <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 50038bf commit d9340d1

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

include/net/dropreason-core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
FN(IP_TUNNEL_ECN) \
105105
FN(TUNNEL_TXINFO) \
106106
FN(LOCAL_MAC) \
107+
FN(ARP_PVLAN_DISABLE) \
107108
FNe(MAX)
108109

109110
/**
@@ -477,6 +478,12 @@ enum skb_drop_reason {
477478
* the MAC address of the local netdev.
478479
*/
479480
SKB_DROP_REASON_LOCAL_MAC,
481+
/**
482+
* @SKB_DROP_REASON_ARP_PVLAN_DISABLE: packet which is not IP is
483+
* forwarded to the in_dev, and the proxy_arp_pvlan is not
484+
* enabled.
485+
*/
486+
SKB_DROP_REASON_ARP_PVLAN_DISABLE,
480487
/**
481488
* @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which
482489
* shouldn't be used as a real 'reason' - only for tracing code gen

net/ipv4/route.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,10 +1782,12 @@ static void ip_handle_martian_source(struct net_device *dev,
17821782
}
17831783

17841784
/* called in rcu_read_lock() section */
1785-
static int __mkroute_input(struct sk_buff *skb, const struct fib_result *res,
1786-
struct in_device *in_dev, __be32 daddr,
1787-
__be32 saddr, dscp_t dscp)
1785+
static enum skb_drop_reason
1786+
__mkroute_input(struct sk_buff *skb, const struct fib_result *res,
1787+
struct in_device *in_dev, __be32 daddr,
1788+
__be32 saddr, dscp_t dscp)
17881789
{
1790+
enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
17891791
struct fib_nh_common *nhc = FIB_RES_NHC(*res);
17901792
struct net_device *dev = nhc->nhc_dev;
17911793
struct fib_nh_exception *fnhe;
@@ -1799,13 +1801,13 @@ static int __mkroute_input(struct sk_buff *skb, const struct fib_result *res,
17991801
out_dev = __in_dev_get_rcu(dev);
18001802
if (!out_dev) {
18011803
net_crit_ratelimited("Bug in ip_route_input_slow(). Please report.\n");
1802-
return -EINVAL;
1804+
return reason;
18031805
}
18041806

18051807
err = fib_validate_source(skb, saddr, daddr, dscp, FIB_RES_OIF(*res),
18061808
in_dev->dev, in_dev, &itag);
18071809
if (err < 0) {
1808-
err = -EINVAL;
1810+
reason = -err;
18091811
ip_handle_martian_source(in_dev->dev, in_dev, skb, daddr,
18101812
saddr);
18111813

@@ -1833,7 +1835,7 @@ static int __mkroute_input(struct sk_buff *skb, const struct fib_result *res,
18331835
*/
18341836
if (out_dev == in_dev &&
18351837
IN_DEV_PROXY_ARP_PVLAN(in_dev) == 0) {
1836-
err = -EINVAL;
1838+
reason = SKB_DROP_REASON_ARP_PVLAN_DISABLE;
18371839
goto cleanup;
18381840
}
18391841
}
@@ -1856,7 +1858,7 @@ static int __mkroute_input(struct sk_buff *skb, const struct fib_result *res,
18561858
rth = rt_dst_alloc(out_dev->dev, 0, res->type,
18571859
IN_DEV_ORCONF(out_dev, NOXFRM));
18581860
if (!rth) {
1859-
err = -ENOBUFS;
1861+
reason = SKB_DROP_REASON_NOMEM;
18601862
goto cleanup;
18611863
}
18621864

@@ -1870,9 +1872,9 @@ static int __mkroute_input(struct sk_buff *skb, const struct fib_result *res,
18701872
lwtunnel_set_redirect(&rth->dst);
18711873
skb_dst_set(skb, &rth->dst);
18721874
out:
1873-
err = 0;
1874-
cleanup:
1875-
return err;
1875+
reason = SKB_NOT_DROPPED_YET;
1876+
cleanup:
1877+
return reason;
18761878
}
18771879

18781880
#ifdef CONFIG_IP_ROUTE_MULTIPATH
@@ -2130,9 +2132,10 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
21302132
}
21312133
#endif /* CONFIG_IP_ROUTE_MULTIPATH */
21322134

2133-
static int ip_mkroute_input(struct sk_buff *skb, struct fib_result *res,
2134-
struct in_device *in_dev, __be32 daddr,
2135-
__be32 saddr, dscp_t dscp, struct flow_keys *hkeys)
2135+
static enum skb_drop_reason
2136+
ip_mkroute_input(struct sk_buff *skb, struct fib_result *res,
2137+
struct in_device *in_dev, __be32 daddr,
2138+
__be32 saddr, dscp_t dscp, struct flow_keys *hkeys)
21362139
{
21372140
#ifdef CONFIG_IP_ROUTE_MULTIPATH
21382141
if (res->fi && fib_info_num_path(res->fi) > 1) {
@@ -2346,9 +2349,8 @@ ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
23462349
}
23472350

23482351
make_route:
2349-
err = ip_mkroute_input(skb, res, in_dev, daddr, saddr, dscp, flkeys);
2350-
if (!err)
2351-
reason = SKB_NOT_DROPPED_YET;
2352+
reason = ip_mkroute_input(skb, res, in_dev, daddr, saddr, dscp,
2353+
flkeys);
23522354

23532355
out:
23542356
return reason;

0 commit comments

Comments
 (0)