Skip to content

Commit 479aed0

Browse files
image-dragonPaolo Abeni
authored andcommitted
net: ip: make ip_route_use_hint() return drop reasons
In this commit, we make ip_route_use_hint() return drop reasons. The drop reasons that we return are similar to what we do in ip_route_input_slow(), and no drop reasons are added in this commit. Signed-off-by: Menglong Dong <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent d9340d1 commit 479aed0

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

include/net/route.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
206206
enum skb_drop_reason
207207
ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
208208
dscp_t dscp, struct net_device *dev);
209-
int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
210-
dscp_t dscp, struct net_device *dev,
211-
const struct sk_buff *hint);
209+
enum skb_drop_reason
210+
ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
211+
dscp_t dscp, struct net_device *dev,
212+
const struct sk_buff *hint);
212213

213214
static inline enum skb_drop_reason
214215
ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src, dscp_t dscp,

net/ipv4/ip_input.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,14 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk,
322322
int err, drop_reason;
323323
struct rtable *rt;
324324

325-
drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
326-
327325
if (ip_can_use_hint(skb, iph, hint)) {
328-
err = ip_route_use_hint(skb, iph->daddr, iph->saddr,
329-
ip4h_dscp(iph), dev, hint);
330-
if (unlikely(err))
326+
drop_reason = ip_route_use_hint(skb, iph->daddr, iph->saddr,
327+
ip4h_dscp(iph), dev, hint);
328+
if (unlikely(drop_reason))
331329
goto drop_error;
332330
}
333331

332+
drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
334333
if (READ_ONCE(net->ipv4.sysctl_ip_early_demux) &&
335334
!skb_dst(skb) &&
336335
!skb->sk &&

net/ipv4/route.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,28 +2154,34 @@ ip_mkroute_input(struct sk_buff *skb, struct fib_result *res,
21542154
* assuming daddr is valid and the destination is not a local broadcast one.
21552155
* Uses the provided hint instead of performing a route lookup.
21562156
*/
2157-
int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2158-
dscp_t dscp, struct net_device *dev,
2159-
const struct sk_buff *hint)
2157+
enum skb_drop_reason
2158+
ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2159+
dscp_t dscp, struct net_device *dev,
2160+
const struct sk_buff *hint)
21602161
{
2162+
enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
21612163
struct in_device *in_dev = __in_dev_get_rcu(dev);
21622164
struct rtable *rt = skb_rtable(hint);
21632165
struct net *net = dev_net(dev);
2164-
enum skb_drop_reason reason;
2165-
int err = -EINVAL;
21662166
u32 tag = 0;
21672167

21682168
if (!in_dev)
2169-
return -EINVAL;
2169+
return reason;
21702170

2171-
if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr))
2171+
if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr)) {
2172+
reason = SKB_DROP_REASON_IP_INVALID_SOURCE;
21722173
goto martian_source;
2174+
}
21732175

2174-
if (ipv4_is_zeronet(saddr))
2176+
if (ipv4_is_zeronet(saddr)) {
2177+
reason = SKB_DROP_REASON_IP_INVALID_SOURCE;
21752178
goto martian_source;
2179+
}
21762180

2177-
if (ipv4_is_loopback(saddr) && !IN_DEV_NET_ROUTE_LOCALNET(in_dev, net))
2181+
if (ipv4_is_loopback(saddr) && !IN_DEV_NET_ROUTE_LOCALNET(in_dev, net)) {
2182+
reason = SKB_DROP_REASON_IP_LOCALNET;
21782183
goto martian_source;
2184+
}
21792185

21802186
if (rt->rt_type != RTN_LOCAL)
21812187
goto skip_validate_source;
@@ -2187,11 +2193,11 @@ int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
21872193

21882194
skip_validate_source:
21892195
skb_dst_copy(skb, hint);
2190-
return 0;
2196+
return SKB_NOT_DROPPED_YET;
21912197

21922198
martian_source:
21932199
ip_handle_martian_source(dev, in_dev, skb, daddr, saddr);
2194-
return err;
2200+
return reason;
21952201
}
21962202

21972203
/* get device for dst_alloc with local routes */

0 commit comments

Comments
 (0)