Skip to content

Commit eaff8b0

Browse files
committed
net: ip: make ip_mc_validate_source() return drop reason
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 d46f827 Author: Menglong Dong <menglong8.dong@gmail.com> Date: Thu Nov 7 20:55:55 2024 +0800 net: ip: make ip_mc_validate_source() return drop reason Make ip_mc_validate_source() return drop reason, and adjust the call of it in ip_route_input_mc(). Another caller of it is ip_rcv_finish_core->udp_v4_early_demux, and the errno is not checked in detail, so we don't do more adjustment for it. The drop reason "SKB_DROP_REASON_IP_LOCALNET" is added in this commit. Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Antoine Tenart <atenart@redhat.com>
1 parent e2f4ccb commit eaff8b0

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

include/net/dropreason-core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
FN(IP_INNOROUTES) \
7979
FN(IP_LOCAL_SOURCE) \
8080
FN(IP_INVALID_SOURCE) \
81+
FN(IP_LOCALNET) \
8182
FN(PKT_TOO_BIG) \
8283
FN(DUP_FRAG) \
8384
FN(FRAG_REASM_TIMEOUT) \
@@ -383,6 +384,8 @@ enum skb_drop_reason {
383384
* 2) source ip is zero and not IGMP
384385
*/
385386
SKB_DROP_REASON_IP_INVALID_SOURCE,
387+
/** @SKB_DROP_REASON_IP_LOCALNET: source or dest ip is local net */
388+
SKB_DROP_REASON_IP_LOCALNET,
386389
/**
387390
* @SKB_DROP_REASON_PKT_TOO_BIG: packet size is too big (maybe exceed the
388391
* MTU)

include/net/route.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4
198198
fl4->fl4_gre_key = gre_key;
199199
return ip_route_output_key(net, fl4);
200200
}
201-
int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
202-
u8 tos, struct net_device *dev,
203-
struct in_device *in_dev, u32 *itag);
201+
202+
enum skb_drop_reason
203+
ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
204+
u8 tos, struct net_device *dev,
205+
struct in_device *in_dev, u32 *itag);
204206
int ip_route_input_noref(struct sk_buff *skb, __be32 dst, __be32 src,
205207
u8 tos, struct net_device *devin);
206208
int ip_route_use_hint(struct sk_buff *skb, __be32 dst, __be32 src,

net/ipv4/route.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,34 +1676,37 @@ struct rtable *rt_dst_clone(struct net_device *dev, struct rtable *rt)
16761676
EXPORT_SYMBOL(rt_dst_clone);
16771677

16781678
/* called in rcu_read_lock() section */
1679-
int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1680-
u8 tos, struct net_device *dev,
1681-
struct in_device *in_dev, u32 *itag)
1679+
enum skb_drop_reason
1680+
ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1681+
u8 tos, struct net_device *dev,
1682+
struct in_device *in_dev, u32 *itag)
16821683
{
16831684
enum skb_drop_reason reason;
16841685

16851686
/* Primary sanity checks. */
16861687
if (!in_dev)
1687-
return -EINVAL;
1688+
return SKB_DROP_REASON_NOT_SPECIFIED;
16881689

1689-
if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr) ||
1690-
skb->protocol != htons(ETH_P_IP))
1691-
return -EINVAL;
1690+
if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr))
1691+
return SKB_DROP_REASON_IP_INVALID_SOURCE;
1692+
1693+
if (skb->protocol != htons(ETH_P_IP))
1694+
return SKB_DROP_REASON_INVALID_PROTO;
16921695

16931696
if (ipv4_is_loopback(saddr) && !IN_DEV_ROUTE_LOCALNET(in_dev))
1694-
return -EINVAL;
1697+
return SKB_DROP_REASON_IP_LOCALNET;
16951698

16961699
if (ipv4_is_zeronet(saddr)) {
16971700
if (!ipv4_is_local_multicast(daddr) &&
16981701
ip_hdr(skb)->protocol != IPPROTO_IGMP)
1699-
return -EINVAL;
1702+
return SKB_DROP_REASON_IP_INVALID_SOURCE;
17001703
} else {
17011704
reason = fib_validate_source_reason(skb, saddr, 0, tos, 0,
17021705
dev, in_dev, itag);
17031706
if (reason)
1704-
return -EINVAL;
1707+
return reason;
17051708
}
1706-
return 0;
1709+
return SKB_NOT_DROPPED_YET;
17071710
}
17081711

17091712
/* called in rcu_read_lock() section */
@@ -1713,13 +1716,14 @@ ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
17131716
{
17141717
struct in_device *in_dev = __in_dev_get_rcu(dev);
17151718
unsigned int flags = RTCF_MULTICAST;
1719+
enum skb_drop_reason reason;
17161720
struct rtable *rth;
17171721
u32 itag = 0;
1718-
int err;
17191722

1720-
err = ip_mc_validate_source(skb, daddr, saddr, tos, dev, in_dev, &itag);
1721-
if (err)
1722-
return SKB_DROP_REASON_NOT_SPECIFIED;
1723+
reason = ip_mc_validate_source(skb, daddr, saddr, tos, dev, in_dev,
1724+
&itag);
1725+
if (reason)
1726+
return reason;
17231727

17241728
if (our)
17251729
flags |= RTCF_LOCAL;

0 commit comments

Comments
 (0)