Skip to content

Commit e98f3e0

Browse files
committed
net: ip: make ip_route_use_hint() 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 479aed0 Author: Menglong Dong <[email protected]> Date: Thu Nov 7 20:56:01 2024 +0800 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]> Signed-off-by: Antoine Tenart <[email protected]>
1 parent 633853c commit e98f3e0

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
u8 tos, struct net_device *dev);
209-
int ip_route_use_hint(struct sk_buff *skb, __be32 dst, __be32 src,
210-
u8 tos, struct net_device *devin,
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+
u8 tos, 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, u8 tos,

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, iph->tos,
329-
dev, hint);
330-
if (unlikely(err))
326+
drop_reason = ip_route_use_hint(skb, iph->daddr, iph->saddr,
327+
iph->tos, 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
@@ -2152,28 +2152,34 @@ ip_mkroute_input(struct sk_buff *skb, struct fib_result *res,
21522152
* assuming daddr is valid and the destination is not a local broadcast one.
21532153
* Uses the provided hint instead of performing a route lookup.
21542154
*/
2155-
int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2156-
u8 tos, struct net_device *dev,
2157-
const struct sk_buff *hint)
2155+
enum skb_drop_reason
2156+
ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
2157+
u8 tos, struct net_device *dev,
2158+
const struct sk_buff *hint)
21582159
{
2160+
enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
21592161
struct in_device *in_dev = __in_dev_get_rcu(dev);
21602162
struct rtable *rt = skb_rtable(hint);
21612163
struct net *net = dev_net(dev);
2162-
enum skb_drop_reason reason;
2163-
int err = -EINVAL;
21642164
u32 tag = 0;
21652165

21662166
if (!in_dev)
2167-
return -EINVAL;
2167+
return reason;
21682168

2169-
if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr))
2169+
if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr)) {
2170+
reason = SKB_DROP_REASON_IP_INVALID_SOURCE;
21702171
goto martian_source;
2172+
}
21712173

2172-
if (ipv4_is_zeronet(saddr))
2174+
if (ipv4_is_zeronet(saddr)) {
2175+
reason = SKB_DROP_REASON_IP_INVALID_SOURCE;
21732176
goto martian_source;
2177+
}
21742178

2175-
if (ipv4_is_loopback(saddr) && !IN_DEV_NET_ROUTE_LOCALNET(in_dev, net))
2179+
if (ipv4_is_loopback(saddr) && !IN_DEV_NET_ROUTE_LOCALNET(in_dev, net)) {
2180+
reason = SKB_DROP_REASON_IP_LOCALNET;
21762181
goto martian_source;
2182+
}
21772183

21782184
if (rt->rt_type != RTN_LOCAL)
21792185
goto skip_validate_source;
@@ -2186,11 +2192,11 @@ int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
21862192

21872193
skip_validate_source:
21882194
skb_dst_copy(skb, hint);
2189-
return 0;
2195+
return SKB_NOT_DROPPED_YET;
21902196

21912197
martian_source:
21922198
ip_handle_martian_source(dev, in_dev, skb, daddr, saddr);
2193-
return err;
2199+
return reason;
21942200
}
21952201

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

0 commit comments

Comments
 (0)