Skip to content

Commit 633853c

Browse files
committed
net: ip: make ip_mkroute_input/__mkroute_input return drop reasons
JIRA: https://issues.redhat.com/browse/RHEL-88891 Upstream Status: linux.git Conflicts:\ - Minor code differences as the tos to dscp conversion wasn't done in c10s yet. commit d9340d1 Author: Menglong Dong <[email protected]> Date: Thu Nov 7 20:56:00 2024 +0800 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]> Signed-off-by: Antoine Tenart <[email protected]>
1 parent 12cba8f commit 633853c

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
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 & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,11 +1780,12 @@ static void ip_handle_martian_source(struct net_device *dev,
17801780
}
17811781

17821782
/* called in rcu_read_lock() section */
1783-
static int __mkroute_input(struct sk_buff *skb,
1784-
const struct fib_result *res,
1785-
struct in_device *in_dev,
1786-
__be32 daddr, __be32 saddr, u32 tos)
1783+
static enum skb_drop_reason
1784+
__mkroute_input(struct sk_buff *skb, const struct fib_result *res,
1785+
struct in_device *in_dev, __be32 daddr,
1786+
__be32 saddr, u32 tos)
17871787
{
1788+
enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
17881789
struct fib_nh_common *nhc = FIB_RES_NHC(*res);
17891790
struct net_device *dev = nhc->nhc_dev;
17901791
struct fib_nh_exception *fnhe;
@@ -1798,13 +1799,13 @@ static int __mkroute_input(struct sk_buff *skb,
17981799
out_dev = __in_dev_get_rcu(dev);
17991800
if (!out_dev) {
18001801
net_crit_ratelimited("Bug in ip_route_input_slow(). Please report.\n");
1801-
return -EINVAL;
1802+
return reason;
18021803
}
18031804

18041805
err = fib_validate_source(skb, saddr, daddr, tos, FIB_RES_OIF(*res),
18051806
in_dev->dev, in_dev, &itag);
18061807
if (err < 0) {
1807-
err = -EINVAL;
1808+
reason = -err;
18081809
ip_handle_martian_source(in_dev->dev, in_dev, skb, daddr,
18091810
saddr);
18101811

@@ -1832,7 +1833,7 @@ static int __mkroute_input(struct sk_buff *skb,
18321833
*/
18331834
if (out_dev == in_dev &&
18341835
IN_DEV_PROXY_ARP_PVLAN(in_dev) == 0) {
1835-
err = -EINVAL;
1836+
reason = SKB_DROP_REASON_ARP_PVLAN_DISABLE;
18361837
goto cleanup;
18371838
}
18381839
}
@@ -1855,7 +1856,7 @@ static int __mkroute_input(struct sk_buff *skb,
18551856
rth = rt_dst_alloc(out_dev->dev, 0, res->type,
18561857
IN_DEV_ORCONF(out_dev, NOXFRM));
18571858
if (!rth) {
1858-
err = -ENOBUFS;
1859+
reason = SKB_DROP_REASON_NOMEM;
18591860
goto cleanup;
18601861
}
18611862

@@ -1869,9 +1870,9 @@ static int __mkroute_input(struct sk_buff *skb,
18691870
lwtunnel_set_redirect(&rth->dst);
18701871
skb_dst_set(skb, &rth->dst);
18711872
out:
1872-
err = 0;
1873-
cleanup:
1874-
return err;
1873+
reason = SKB_NOT_DROPPED_YET;
1874+
cleanup:
1875+
return reason;
18751876
}
18761877

18771878
#ifdef CONFIG_IP_ROUTE_MULTIPATH
@@ -2129,11 +2130,10 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
21292130
}
21302131
#endif /* CONFIG_IP_ROUTE_MULTIPATH */
21312132

2132-
static int ip_mkroute_input(struct sk_buff *skb,
2133-
struct fib_result *res,
2134-
struct in_device *in_dev,
2135-
__be32 daddr, __be32 saddr, u32 tos,
2136-
struct flow_keys *hkeys)
2133+
static enum skb_drop_reason
2134+
ip_mkroute_input(struct sk_buff *skb, struct fib_result *res,
2135+
struct in_device *in_dev, __be32 daddr,
2136+
__be32 saddr, u32 tos, struct flow_keys *hkeys)
21372137
{
21382138
#ifdef CONFIG_IP_ROUTE_MULTIPATH
21392139
if (res->fi && fib_info_num_path(res->fi) > 1) {
@@ -2348,9 +2348,8 @@ ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
23482348
}
23492349

23502350
make_route:
2351-
err = ip_mkroute_input(skb, res, in_dev, daddr, saddr, tos, flkeys);
2352-
if (!err)
2353-
reason = SKB_NOT_DROPPED_YET;
2351+
reason = ip_mkroute_input(skb, res, in_dev, daddr, saddr, tos,
2352+
flkeys);
23542353

23552354
out:
23562355
return reason;

0 commit comments

Comments
 (0)