Skip to content

Commit d46f827

Browse files
image-dragonPaolo Abeni
authored and
Paolo Abeni
committed
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 <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent c6c6707 commit d46f827

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4
199199
return ip_route_output_key(net, fl4);
200200
}
201201

202-
int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
203-
dscp_t dscp, struct net_device *dev,
204-
struct in_device *in_dev, u32 *itag);
202+
enum skb_drop_reason
203+
ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
204+
dscp_t dscp, struct net_device *dev,
205+
struct in_device *in_dev, u32 *itag);
205206
int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,
206207
dscp_t dscp, struct net_device *dev);
207208
int ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,

net/ipv4/route.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,34 +1678,37 @@ struct rtable *rt_dst_clone(struct net_device *dev, struct rtable *rt)
16781678
EXPORT_SYMBOL(rt_dst_clone);
16791679

16801680
/* called in rcu_read_lock() section */
1681-
int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1682-
dscp_t dscp, struct net_device *dev,
1683-
struct in_device *in_dev, u32 *itag)
1681+
enum skb_drop_reason
1682+
ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr,
1683+
dscp_t dscp, struct net_device *dev,
1684+
struct in_device *in_dev, u32 *itag)
16841685
{
16851686
enum skb_drop_reason reason;
16861687

16871688
/* Primary sanity checks. */
16881689
if (!in_dev)
1689-
return -EINVAL;
1690+
return SKB_DROP_REASON_NOT_SPECIFIED;
16901691

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

16951698
if (ipv4_is_loopback(saddr) && !IN_DEV_ROUTE_LOCALNET(in_dev))
1696-
return -EINVAL;
1699+
return SKB_DROP_REASON_IP_LOCALNET;
16971700

16981701
if (ipv4_is_zeronet(saddr)) {
16991702
if (!ipv4_is_local_multicast(daddr) &&
17001703
ip_hdr(skb)->protocol != IPPROTO_IGMP)
1701-
return -EINVAL;
1704+
return SKB_DROP_REASON_IP_INVALID_SOURCE;
17021705
} else {
17031706
reason = fib_validate_source_reason(skb, saddr, 0, dscp, 0,
17041707
dev, in_dev, itag);
17051708
if (reason)
1706-
return -EINVAL;
1709+
return reason;
17071710
}
1708-
return 0;
1711+
return SKB_NOT_DROPPED_YET;
17091712
}
17101713

17111714
/* called in rcu_read_lock() section */
@@ -1715,14 +1718,14 @@ ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
17151718
{
17161719
struct in_device *in_dev = __in_dev_get_rcu(dev);
17171720
unsigned int flags = RTCF_MULTICAST;
1721+
enum skb_drop_reason reason;
17181722
struct rtable *rth;
17191723
u32 itag = 0;
1720-
int err;
17211724

1722-
err = ip_mc_validate_source(skb, daddr, saddr, dscp, dev, in_dev,
1723-
&itag);
1724-
if (err)
1725-
return SKB_DROP_REASON_NOT_SPECIFIED;
1725+
reason = ip_mc_validate_source(skb, daddr, saddr, dscp, dev, in_dev,
1726+
&itag);
1727+
if (reason)
1728+
return reason;
17261729

17271730
if (our)
17281731
flags |= RTCF_LOCAL;

0 commit comments

Comments
 (0)