Skip to content

Commit 50038bf

Browse files
image-dragonPaolo Abeni
authored andcommitted
net: ip: make ip_route_input() return drop reasons
In this commit, we make ip_route_input() return skb drop reasons that come from ip_route_input_noref(). Meanwhile, adjust all the call to it. Signed-off-by: Menglong Dong <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 82d9983 commit 50038bf

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

include/net/route.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
210210
dscp_t dscp, struct net_device *dev,
211211
const struct sk_buff *hint);
212212

213-
static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src,
214-
dscp_t dscp, struct net_device *devin)
213+
static inline enum skb_drop_reason
214+
ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src, dscp_t dscp,
215+
struct net_device *devin)
215216
{
216217
enum skb_drop_reason reason;
217218

@@ -224,7 +225,7 @@ static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src,
224225
}
225226
rcu_read_unlock();
226227

227-
return reason ? -EINVAL : 0;
228+
return reason;
228229
}
229230

230231
void ipv4_update_pmtu(struct sk_buff *skb, struct net *net, u32 mtu, int oif,

net/bridge/br_netfilter_hooks.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
373373
struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
374374
struct net_device *dev = skb->dev, *br_indev;
375375
const struct iphdr *iph = ip_hdr(skb);
376+
enum skb_drop_reason reason;
376377
struct rtable *rt;
377-
int err;
378378

379379
br_indev = nf_bridge_get_physindev(skb, net);
380380
if (!br_indev) {
@@ -390,9 +390,9 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
390390
}
391391
nf_bridge->in_prerouting = 0;
392392
if (br_nf_ipv4_daddr_was_changed(skb, nf_bridge)) {
393-
err = ip_route_input(skb, iph->daddr, iph->saddr,
394-
ip4h_dscp(iph), dev);
395-
if (err) {
393+
reason = ip_route_input(skb, iph->daddr, iph->saddr,
394+
ip4h_dscp(iph), dev);
395+
if (reason) {
396396
struct in_device *in_dev = __in_dev_get_rcu(dev);
397397

398398
/* If err equals -EHOSTUNREACH the error is due to a
@@ -402,7 +402,8 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
402402
* martian destinations: loopback destinations and destination
403403
* 0.0.0.0. In both cases the packet will be dropped because the
404404
* destination is the loopback device and not the bridge. */
405-
if (err != -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev))
405+
if (reason != SKB_DROP_REASON_IP_INADDRERRORS || !in_dev ||
406+
IN_DEV_FORWARD(in_dev))
406407
goto free_skb;
407408

408409
rt = ip_route_output(net, iph->daddr, 0,

net/ipv4/icmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ static struct rtable *icmp_route_lookup(struct net *net, struct flowi4 *fl4,
545545
orefdst = skb_in->_skb_refdst; /* save old refdst */
546546
skb_dst_set(skb_in, NULL);
547547
err = ip_route_input(skb_in, fl4_dec.daddr, fl4_dec.saddr,
548-
dscp, rt2->dst.dev);
548+
dscp, rt2->dst.dev) ? -EINVAL : 0;
549549

550550
dst_release(&rt2->dst);
551551
rt2 = skb_rtable(skb_in);

net/ipv4/ip_options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ int ip_options_rcv_srr(struct sk_buff *skb, struct net_device *dev)
618618
orefdst = skb->_skb_refdst;
619619
skb_dst_set(skb, NULL);
620620
err = ip_route_input(skb, nexthop, iph->saddr, ip4h_dscp(iph),
621-
dev);
621+
dev) ? -EINVAL : 0;
622622
rt2 = skb_rtable(skb);
623623
if (err || (rt2->rt_type != RTN_UNICAST && rt2->rt_type != RTN_LOCAL)) {
624624
skb_dst_drop(skb);

net/ipv6/seg6_local.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -954,10 +954,10 @@ static int input_action_end_dx4_finish(struct net *net, struct sock *sk,
954954
struct sk_buff *skb)
955955
{
956956
struct dst_entry *orig_dst = skb_dst(skb);
957+
enum skb_drop_reason reason;
957958
struct seg6_local_lwt *slwt;
958959
struct iphdr *iph;
959960
__be32 nhaddr;
960-
int err;
961961

962962
slwt = seg6_local_lwtunnel(orig_dst->lwtstate);
963963

@@ -967,9 +967,9 @@ static int input_action_end_dx4_finish(struct net *net, struct sock *sk,
967967

968968
skb_dst_drop(skb);
969969

970-
err = ip_route_input(skb, nhaddr, iph->saddr, 0, skb->dev);
971-
if (err) {
972-
kfree_skb(skb);
970+
reason = ip_route_input(skb, nhaddr, iph->saddr, 0, skb->dev);
971+
if (reason) {
972+
kfree_skb_reason(skb, reason);
973973
return -EINVAL;
974974
}
975975

@@ -1174,8 +1174,8 @@ static struct sk_buff *end_dt_vrf_core(struct sk_buff *skb,
11741174
static int input_action_end_dt4(struct sk_buff *skb,
11751175
struct seg6_local_lwt *slwt)
11761176
{
1177+
enum skb_drop_reason reason;
11771178
struct iphdr *iph;
1178-
int err;
11791179

11801180
if (!decap_and_validate(skb, IPPROTO_IPIP))
11811181
goto drop;
@@ -1193,8 +1193,8 @@ static int input_action_end_dt4(struct sk_buff *skb,
11931193

11941194
iph = ip_hdr(skb);
11951195

1196-
err = ip_route_input(skb, iph->daddr, iph->saddr, 0, skb->dev);
1197-
if (unlikely(err))
1196+
reason = ip_route_input(skb, iph->daddr, iph->saddr, 0, skb->dev);
1197+
if (unlikely(reason))
11981198
goto drop;
11991199

12001200
return dst_input(skb);

0 commit comments

Comments
 (0)