Skip to contentSkip to conversation

Create ipv4_is_<type>(__be32 addr) functions

PATCH Applied Joe Perches 4 participants 30 messages Dec 13, 2007 – Dec 17, 2007

Subsystems (8)
lore
Share & tools
lore
#4 lore raw

PATCH 5/8 net/netfilter: Use ipv4_is_<type>

In reply to Joe Perches
---
 net/netfilter/xt_pkttype.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/netfilter/xt_pkttype.c +1 -1
index c598bbe..2762449 100644
@@ -31,7 +31,7 @@ pkttype_mt(const struct sk_buff *skb, const struct net_device *in,
 	const struct xt_pkttype_info *info = matchinfo;
 
 	if (skb->pkt_type == PACKET_LOOPBACK)
-		type = MULTICAST(ip_hdr(skb)->daddr)
+		type = ipv4_is_multicast(ip_hdr(skb)->daddr)
 			? PACKET_MULTICAST
 			: PACKET_BROADCAST;
 	else
Signature · 1 line
1.5.3.7.949.g2221a6
#19 lore raw

PATCH 5/8 net/netfilter: Use ipv4_is_<type>

In reply to Joe Perches
---
 net/netfilter/xt_pkttype.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/netfilter/xt_pkttype.c +1 -1
index c598bbe..2762449 100644
@@ -31,7 +31,7 @@ pkttype_mt(const struct sk_buff *skb, const struct net_device *in,
 	const struct xt_pkttype_info *info = matchinfo;
 
 	if (skb->pkt_type == PACKET_LOOPBACK)
-		type = MULTICAST(ip_hdr(skb)->daddr)
+		type = ipv4_is_multicast(ip_hdr(skb)->daddr)
 			? PACKET_MULTICAST
 			: PACKET_BROADCAST;
 	else
Signature · 1 line
1.5.3.7.949.g2221a6
#20 lore raw

PATCH 5/8 net/netfilter: Use ipv4_is_<type>

In reply to Joe Perches
---
 net/netfilter/xt_pkttype.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/netfilter/xt_pkttype.c +1 -1
index c598bbe..2762449 100644
@@ -31,7 +31,7 @@ pkttype_mt(const struct sk_buff *skb, const struct net_device *in,
 	const struct xt_pkttype_info *info = matchinfo;
 
 	if (skb->pkt_type == PACKET_LOOPBACK)
-		type = MULTICAST(ip_hdr(skb)->daddr)
+		type = ipv4_is_multicast(ip_hdr(skb)->daddr)
 			? PACKET_MULTICAST
 			: PACKET_BROADCAST;
 	else
Signature · 1 line
1.5.3.7.949.g2221a6
#6 lore raw

PATCH 7/8 drivers/infiniband: Use ipv4_is_<type>

In reply to Joe Perches
---
 drivers/infiniband/core/addr.c |    4 ++--
 drivers/infiniband/core/cma.c  |    5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/infiniband/core/addr.c +2 -2
index 5381c80..0802b79 100644
@@ -265,11 +265,11 @@ static int addr_resolve_local(struct sockaddr_in *src_in,
 	if (!dev)
 		return -EADDRNOTAVAIL;
 
-	if (ZERONET(src_ip)) {
+	if (ipv4_is_zeronet(src_ip)) {
 		src_in->sin_family = dst_in->sin_family;
 		src_in->sin_addr.s_addr = dst_ip;
 		ret = rdma_copy_addr(addr, dev, dev->dev_addr);
-	} else if (LOOPBACK(src_ip)) {
+	} else if (ipv4_is_loopback(src_ip)) {
 		ret = rdma_translate_ip((struct sockaddr *)dst_in, addr);
 		if (!ret)
 			memcpy(addr->dst_dev_addr, dev->dev_addr, MAX_ADDR_LEN);
drivers/infiniband/core/cma.c +3 -2
index 0751697..b37045c 100644
@@ -624,7 +624,8 @@ static inline int cma_zero_addr(struct sockaddr *addr)
 	struct in6_addr *ip6;
 
 	if (addr->sa_family == AF_INET)
-		return ZERONET(((struct sockaddr_in *) addr)->sin_addr.s_addr);
+		return ipv4_is_zeronet(
+			((struct sockaddr_in *)addr)->sin_addr.s_addr);
 	else {
 		ip6 = &((struct sockaddr_in6 *) addr)->sin6_addr;
 		return (ip6->s6_addr32[0] | ip6->s6_addr32[1] |
@@ -634,7 +635,7 @@ static inline int cma_zero_addr(struct sockaddr *addr)
 
 static inline int cma_loopback_addr(struct sockaddr *addr)
 {
-	return LOOPBACK(((struct sockaddr_in *) addr)->sin_addr.s_addr);
+	return ipv4_is_loopback(((struct sockaddr_in *) addr)->sin_addr.s_addr);
 }
 
 static inline int cma_any_addr(struct sockaddr *addr)
Signature · 1 line
1.5.3.7.949.g2221a6
#7 lore raw

PATCH 8/8 Remove unused IPV4TYPE macros

---
 include/linux/in.h |   14 --------------
 1 files changed, 0 insertions(+), 14 deletions(-)
include/linux/in.h +0 -13
index f8d6073..27d8a5a 100644
@@ -272,12 +272,6 @@ static inline bool ipv4_is_zeronet(__be32 addr)
 	return (addr & htonl(0xff000000)) == htonl(0x00000000);
 }
 
-#define LOOPBACK(x)		ipv4_is_loopback(x)
-#define MULTICAST(x)		ipv4_is_multicast(x)
-#define BADCLASS(x)		ipv4_is_badclass(x)
-#define ZERONET(x)		ipv4_is_zeronet(x)
-#define LOCAL_MCAST(x)		ipv4_is_local_multicast(x)
-
 /* Special-Use IPv4 Addresses (RFC3330) */
 
 static inline bool ipv4_is_private_10(__be32 addr)
@@ -316,12 +310,4 @@ static inline bool ipv4_is_test_198(__be32 addr)
 }
 #endif
 
-#define PRIVATE_10(x)		ipv4_is_private_10(x)
-#define LINKLOCAL_169(x)	ipv4_is_linklocal_169(x)
-#define PRIVATE_172(x)		ipv4_is_private_172(x)
-#define TEST_192(x)		ipv4_is_test_192(x)
-#define ANYCAST_6TO4(x)		ipv4_is_anycast_6to4(x)
-#define PRIVATE_192(x)		ipv4_is_private_192(x)
-#define TEST_198(x)		ipv4_is_test_198(x)
#0 lore raw

PATCH 1/8 Create ipv4_is_<type>(__be32 addr) functions

Change IPV4 specific macros LOOPBACK MULTICAST LOCAL_MCAST BADCLASS and ZERONET macros to inline functions ipv4_is_<type>(__be32 addr)

Adds type safety and arguably some readability.

Changes since last submission:

Removed ipv4_addr_octets function
Used hex constants
Converted recently added rfc3330 macros

---
 include/linux/in.h |   87 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 74 insertions(+), 13 deletions(-)
include/linux/in.h +74 -13
index a8f00ca..f8d6073 100644
@@ -246,21 +246,82 @@ struct sockaddr_in {
 #include <asm/byteorder.h> 
 
 #ifdef __KERNEL__
-/* Some random defines to make it easier in the kernel.. */
-#define LOOPBACK(x)	(((x) & htonl(0xff000000)) == htonl(0x7f000000))
-#define MULTICAST(x)	(((x) & htonl(0xf0000000)) == htonl(0xe0000000))
-#define BADCLASS(x)	(((x) & htonl(0xf0000000)) == htonl(0xf0000000))
-#define ZERONET(x)	(((x) & htonl(0xff000000)) == htonl(0x00000000))
-#define LOCAL_MCAST(x)	(((x) & htonl(0xFFFFFF00)) == htonl(0xE0000000))
+
+static inline bool ipv4_is_loopback(__be32 addr)
+{
+	return (addr & htonl(0xff000000)) == htonl(0x7f000000);
+}
+
+static inline bool ipv4_is_multicast(__be32 addr)
+{
+	return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
+}
+
+static inline bool ipv4_is_local_multicast(__be32 addr)
+{
+	return (addr & htonl(0xffffff00)) == htonl(0xe0000000);
+}
+
+static inline bool ipv4_is_badclass(__be32 addr)
+{
+	return (addr & htonl(0xf0000000)) == htonl(0xf0000000);
+}
+
+static inline bool ipv4_is_zeronet(__be32 addr)
+{
+	return (addr & htonl(0xff000000)) == htonl(0x00000000);
+}
+
+#define LOOPBACK(x)		ipv4_is_loopback(x)
+#define MULTICAST(x)		ipv4_is_multicast(x)
+#define BADCLASS(x)		ipv4_is_badclass(x)
+#define ZERONET(x)		ipv4_is_zeronet(x)
+#define LOCAL_MCAST(x)		ipv4_is_local_multicast(x)
 
 /* Special-Use IPv4 Addresses (RFC3330) */
-#define PRIVATE_10(x)	(((x) & htonl(0xff000000)) == htonl(0x0A000000))
-#define LINKLOCAL_169(x) (((x) & htonl(0xffff0000)) == htonl(0xA9FE0000))
-#define PRIVATE_172(x)	(((x) & htonl(0xfff00000)) == htonl(0xAC100000))
-#define TEST_192(x)	(((x) & htonl(0xffffff00)) == htonl(0xC0000200))
-#define ANYCAST_6TO4(x)	(((x) & htonl(0xffffff00)) == htonl(0xC0586300))
-#define PRIVATE_192(x)	(((x) & htonl(0xffff0000)) == htonl(0xC0A80000))
-#define TEST_198(x)	(((x) & htonl(0xfffe0000)) == htonl(0xC6120000))
+
+static inline bool ipv4_is_private_10(__be32 addr)
+{
+	return (addr & htonl(0xff000000)) == htonl(0x0a000000);
+}
+
+static inline bool ipv4_is_private_172(__be32 addr)
+{
+	return (addr & htonl(0xfff00000)) == htonl(0xac100000);
+}
+
+static inline bool ipv4_is_private_192(__be32 addr)
+{
+	return (addr & htonl(0xffff0000)) == htonl(0xc0a80000);
+}
+
+static inline bool ipv4_is_linklocal_169(__be32 addr)
+{
+	return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000);
+}
+
+static inline bool ipv4_is_anycast_6to4(__be32 addr)
+{
+	return (addr & htonl(0xffffff00)) == htonl(0xc0586300);
+}
+
+static inline bool ipv4_is_test_192(__be32 addr)
+{
+	return (addr & htonl(0xffffff00)) == htonl(0xc0000200);
+}
+
+static inline bool ipv4_is_test_198(__be32 addr)
+{
+	return (addr & htonl(0xfffe0000)) == htonl(0xc6120000);
+}
 #endif
 
+#define PRIVATE_10(x)		ipv4_is_private_10(x)
+#define LINKLOCAL_169(x)	ipv4_is_linklocal_169(x)
+#define PRIVATE_172(x)		ipv4_is_private_172(x)
+#define TEST_192(x)		ipv4_is_test_192(x)
+#define ANYCAST_6TO4(x)		ipv4_is_anycast_6to4(x)
+#define PRIVATE_192(x)		ipv4_is_private_192(x)
+#define TEST_198(x)		ipv4_is_test_198(x)
+
 #endif	/* _LINUX_IN_H */
Signature · 1 line
1.5.3.7.949.g2221a6
#1 lore raw

PATCH 2/8 include/net: Use ipv4_is_<type>

---
 include/net/addrconf.h |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
include/net/addrconf.h +6 -4
index c56827d..1c3a560 100644
@@ -252,10 +252,12 @@ static inline int ipv6_addr_is_ll_all_routers(const struct in6_addr *addr)
 
 static inline int ipv6_isatap_eui64(u8 *eui, __be32 addr)
 {
-	eui[0] = (ZERONET(addr) || PRIVATE_10(addr) || LOOPBACK(addr) ||
-		  LINKLOCAL_169(addr) || PRIVATE_172(addr) || TEST_192(addr) ||
-		  ANYCAST_6TO4(addr) || PRIVATE_192(addr) || TEST_198(addr) ||
-		  MULTICAST(addr) || BADCLASS(addr)) ? 0x00 : 0x02;
+	eui[0] = (ipv4_is_zeronet(addr) || ipv4_is_private_10(addr) ||
+		  ipv4_is_loopback(addr) || ipv4_is_linklocal_169(addr) ||
+		  ipv4_is_private_172(addr) || ipv4_is_test_192(addr) ||
+		  ipv4_is_anycast_6to4(addr) || ipv4_is_private_192(addr) ||
+		  ipv4_is_test_198(addr) || ipv4_is_multicast(addr) ||
+		  ipv4_is_badclass(addr)) ? 0x00 : 0x02;
 	eui[1] = 0;
 	eui[2] = 0x5E;
 	eui[3] = 0xFE;
Signature · 1 line
1.5.3.7.949.g2221a6
#2 lore raw

PATCH 3/8 net/core: Use ipv4_is_<type>

---
 net/core/netpoll.c |    3 ++-
 net/core/pktgen.c  |    8 +++++---
 2 files changed, 7 insertions(+), 4 deletions(-)
net/core/netpoll.c +2 -1
index b1d5acd..6faa128 100644
@@ -410,7 +410,8 @@ static void arp_reply(struct sk_buff *skb)
 	memcpy(&tip, arp_ptr, 4);
 
 	/* Should we ignore arp? */
-	if (tip != htonl(np->local_ip) || LOOPBACK(tip) || MULTICAST(tip))
+	if (tip != htonl(np->local_ip) ||
+	    ipv4_is_loopback(tip) || ipv4_is_multicast(tip))
 		return;
 
 	size = sizeof(struct arphdr) + 2 * (skb->dev->addr_len + 4);
net/core/pktgen.c +5 -3
index 285ec3e..ede1fea 100644
@@ -2358,9 +2358,11 @@ static void mod_cur_headers(struct pktgen_dev *pkt_dev)
 					t = random32() % (imx - imn) + imn;
 					s = htonl(t);
 
-					while (LOOPBACK(s) || MULTICAST(s)
-					       || BADCLASS(s) || ZERONET(s)
-					       || LOCAL_MCAST(s)) {
+					while (ipv4_is_loopback(s) ||
+					       ipv4_is_multicast(s) ||
+					       ipv4_is_badclass(s) ||
+					       ipv4_is_zeronet(s) ||
+					       ipv4_is_local_multicast(s)) {
 						t = random32() % (imx - imn) + imn;
 						s = htonl(t);
 					}
Signature · 1 line
1.5.3.7.949.g2221a6
#3 lore raw

PATCH 4/8 net/ipv4: Use ipv4_is_<type>

---
 net/ipv4/arp.c          |    2 +-
 net/ipv4/datagram.c     |    2 +-
 net/ipv4/devinet.c      |    4 +-
 net/ipv4/fib_frontend.c |    6 ++--
 net/ipv4/igmp.c         |   12 +++++-----
 net/ipv4/ip_gre.c       |   23 +++++++++++---------
 net/ipv4/ipmr.c         |    6 ++--
 net/ipv4/raw.c          |    2 +-
 net/ipv4/route.c        |   52 ++++++++++++++++++++++++++--------------------
 net/ipv4/udp.c          |    2 +-
 10 files changed, 60 insertions(+), 51 deletions(-)
net/ipv4/arp.c +1 -1
index 48e7bf6..80bf2d0 100644
@@ -778,7 +778,7 @@ static int arp_process(struct sk_buff *skb)
  *	Check for bad requests for 127.x.x.x and requests for multicast
  *	addresses.  If this is one such, delete it.
  */
-	if (LOOPBACK(tip) || MULTICAST(tip))
+	if (ipv4_is_loopback(tip) || ipv4_is_multicast(tip))
 		goto out;
 
 /*
net/ipv4/datagram.c +1 -1
index 0301dd4..0c0c73f 100644
@@ -40,7 +40,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 
 	oif = sk->sk_bound_dev_if;
 	saddr = inet->saddr;
-	if (MULTICAST(usin->sin_addr.s_addr)) {
+	if (ipv4_is_multicast(usin->sin_addr.s_addr)) {
 		if (!oif)
 			oif = inet->mc_index;
 		if (!saddr)
net/ipv4/devinet.c +2 -2
index 0e2a829..fda7414 100644
@@ -401,7 +401,7 @@ static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)
 		in_dev_hold(in_dev);
 		ifa->ifa_dev = in_dev;
 	}
-	if (LOOPBACK(ifa->ifa_local))
+	if (ipv4_is_loopback(ifa->ifa_local))
 		ifa->ifa_scope = RT_SCOPE_HOST;
 	return inet_insert_ifa(ifa);
 }
@@ -580,7 +580,7 @@ static __inline__ int inet_abc_len(__be32 addr)
 {
 	int rc = -1;	/* Something else, probably a multicast. */
 
-	if (ZERONET(addr))
+	if (ipv4_is_zeronet(addr))
 		rc = 0;
 	else {
 		__u32 haddr = ntohl(addr);
net/ipv4/fib_frontend.c +3 -3
index 7962830..b03c4c6 100644
@@ -167,9 +167,9 @@ static inline unsigned __inet_dev_addr_type(const struct net_device *dev,
 	unsigned ret = RTN_BROADCAST;
 	struct fib_table *local_table;
 
-	if (ZERONET(addr) || BADCLASS(addr))
+	if (ipv4_is_zeronet(addr) || ipv4_is_badclass(addr))
 		return RTN_BROADCAST;
-	if (MULTICAST(addr))
+	if (ipv4_is_multicast(addr))
 		return RTN_MULTICAST;
 
 #ifdef CONFIG_IP_MULTIPLE_TABLES
@@ -710,7 +710,7 @@ void fib_add_ifaddr(struct in_ifaddr *ifa)
 	if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF))
 		fib_magic(RTM_NEWROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32, prim);
 
-	if (!ZERONET(prefix) && !(ifa->ifa_flags&IFA_F_SECONDARY) &&
+	if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags&IFA_F_SECONDARY) &&
 	    (prefix != addr || ifa->ifa_prefixlen < 32)) {
 		fib_magic(RTM_NEWROUTE, dev->flags&IFF_LOOPBACK ? RTN_LOCAL :
 			  RTN_UNICAST, prefix, ifa->ifa_prefixlen, prim);
net/ipv4/igmp.c +6 -6
index c560a93..1bb4d0d 100644
@@ -1742,7 +1742,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
 	int ifindex;
 	int count = 0;
 
-	if (!MULTICAST(addr))
+	if (!ipv4_is_multicast(addr))
 		return -EINVAL;
 
 	rtnl_lock();
@@ -1855,7 +1855,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
 	int leavegroup = 0;
 	int i, j, rv;
 
-	if (!MULTICAST(addr))
+	if (!ipv4_is_multicast(addr))
 		return -EINVAL;
 
 	rtnl_lock();
@@ -1985,7 +1985,7 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex)
 	struct ip_sf_socklist *newpsl, *psl;
 	int leavegroup = 0;
 
-	if (!MULTICAST(addr))
+	if (!ipv4_is_multicast(addr))
 		return -EINVAL;
 	if (msf->imsf_fmode != MCAST_INCLUDE &&
 	    msf->imsf_fmode != MCAST_EXCLUDE)
@@ -2068,7 +2068,7 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
 	struct inet_sock *inet = inet_sk(sk);
 	struct ip_sf_socklist *psl;
 
-	if (!MULTICAST(addr))
+	if (!ipv4_is_multicast(addr))
 		return -EINVAL;
 
 	rtnl_lock();
@@ -2130,7 +2130,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
 	if (psin->sin_family != AF_INET)
 		return -EINVAL;
 	addr = psin->sin_addr.s_addr;
-	if (!MULTICAST(addr))
+	if (!ipv4_is_multicast(addr))
 		return -EINVAL;
 
 	rtnl_lock();
@@ -2180,7 +2180,7 @@ int ip_mc_sf_allow(struct sock *sk, __be32 loc_addr, __be32 rmt_addr, int dif)
 	struct ip_sf_socklist *psl;
 	int i;
 
-	if (!MULTICAST(loc_addr))
+	if (!ipv4_is_multicast(loc_addr))
 		return 1;
 
 	for (pmc=inet->mc_list; pmc; pmc=pmc->next) {
net/ipv4/ip_gre.c +13 -10
index 02b02a8..591eed4 100644
@@ -176,7 +176,8 @@ static struct ip_tunnel * ipgre_tunnel_lookup(__be32 remote, __be32 local, __be3
 	}
 	for (t = tunnels_l[h1]; t; t = t->next) {
 		if (local == t->parms.iph.saddr ||
-		     (local == t->parms.iph.daddr && MULTICAST(local))) {
+		     (local == t->parms.iph.daddr &&
+		      ipv4_is_multicast(local))) {
 			if (t->parms.i_key == key && (t->dev->flags&IFF_UP))
 				return t;
 		}
@@ -201,7 +202,7 @@ static struct ip_tunnel **__ipgre_bucket(struct ip_tunnel_parm *parms)
 
 	if (local)
 		prio |= 1;
-	if (remote && !MULTICAST(remote)) {
+	if (remote && !ipv4_is_multicast(remote)) {
 		prio |= 2;
 		h ^= HASH(remote);
 	}
@@ -367,7 +368,8 @@ static void ipgre_err(struct sk_buff *skb, u32 info)
 
 	read_lock(&ipgre_lock);
 	t = ipgre_tunnel_lookup(iph->daddr, iph->saddr, (flags&GRE_KEY) ? *(((__be32*)p) + (grehlen>>2) - 1) : 0);
-	if (t == NULL || t->parms.iph.daddr == 0 || MULTICAST(t->parms.iph.daddr))
+	if (t == NULL || t->parms.iph.daddr == 0 ||
+	    ipv4_is_multicast(t->parms.iph.daddr))
 		goto out;
 
 	if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED)
@@ -619,7 +621,7 @@ static int ipgre_rcv(struct sk_buff *skb)
 		skb_postpull_rcsum(skb, skb_transport_header(skb), offset);
 		skb->pkt_type = PACKET_HOST;
 #ifdef CONFIG_NET_IPGRE_BROADCAST
-		if (MULTICAST(iph->daddr)) {
+		if (ipv4_is_multicast(iph->daddr)) {
 			/* Looped back packet, drop it! */
 			if (((struct rtable*)skb->dst)->fl.iif == 0)
 				goto drop;
@@ -783,7 +785,8 @@ static int ipgre_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
 		struct rt6_info *rt6 = (struct rt6_info*)skb->dst;
 
 		if (rt6 && mtu < dst_mtu(skb->dst) && mtu >= IPV6_MIN_MTU) {
-			if ((tunnel->parms.iph.daddr && !MULTICAST(tunnel->parms.iph.daddr)) ||
+			if ((tunnel->parms.iph.daddr &&
+			     !ipv4_is_multicast(tunnel->parms.iph.daddr)) ||
 			    rt6->rt6i_dst.plen == 128) {
 				rt6->rt6i_flags |= RTF_MODIFIED;
 				skb->dst->metrics[RTAX_MTU-1] = mtu;
@@ -956,7 +959,7 @@ ipgre_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
 
 				t = netdev_priv(dev);
 
-				if (MULTICAST(p.iph.daddr))
+				if (ipv4_is_multicast(p.iph.daddr))
 					nflags = IFF_BROADCAST;
 				else if (p.iph.daddr)
 					nflags = IFF_POINTOPOINT;
@@ -1085,7 +1088,7 @@ static int ipgre_header(struct sk_buff *skb, struct net_device *dev,
 		memcpy(&iph->daddr, daddr, 4);
 		return t->hlen;
 	}
-	if (iph->daddr && !MULTICAST(iph->daddr))
+	if (iph->daddr && !ipv4_is_multicast(iph->daddr))
 		return t->hlen;
 
 	return -t->hlen;
@@ -1108,7 +1111,7 @@ static int ipgre_open(struct net_device *dev)
 {
 	struct ip_tunnel *t = netdev_priv(dev);
 
-	if (MULTICAST(t->parms.iph.daddr)) {
+	if (ipv4_is_multicast(t->parms.iph.daddr)) {
 		struct flowi fl = { .oif = t->parms.link,
 				    .nl_u = { .ip4_u =
 					      { .daddr = t->parms.iph.daddr,
@@ -1131,7 +1134,7 @@ static int ipgre_open(struct net_device *dev)
 static int ipgre_close(struct net_device *dev)
 {
 	struct ip_tunnel *t = netdev_priv(dev);
-	if (MULTICAST(t->parms.iph.daddr) && t->mlink) {
+	if (ipv4_is_multicast(t->parms.iph.daddr) && t->mlink) {
 		struct in_device *in_dev = inetdev_by_index(t->mlink);
 		if (in_dev) {
 			ip_mc_dec_group(in_dev, t->parms.iph.daddr);
@@ -1196,7 +1199,7 @@ static int ipgre_tunnel_init(struct net_device *dev)
 		dev->flags |= IFF_POINTOPOINT;
 
 #ifdef CONFIG_NET_IPGRE_BROADCAST
-		if (MULTICAST(iph->daddr)) {
+		if (ipv4_is_multicast(iph->daddr)) {
 			if (!iph->saddr)
 				return -EINVAL;
 			dev->flags = IFF_BROADCAST;
net/ipv4/ipmr.c +3 -3
index 1187928..6586324 100644
@@ -749,7 +749,7 @@ static int ipmr_mfc_add(struct mfcctl *mfc, int mrtsock)
 		return 0;
 	}
 
-	if (!MULTICAST(mfc->mfcc_mcastgrp.s_addr))
+	if (!ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr))
 		return -EINVAL;
 
 	c=ipmr_cache_alloc();
@@ -1461,7 +1461,7 @@ int pim_rcv_v1(struct sk_buff * skb)
 	   b. packet is not a NULL-REGISTER
 	   c. packet is not truncated
 	 */
-	if (!MULTICAST(encap->daddr) ||
+	if (!ipv4_is_multicast(encap->daddr) ||
 	    encap->tot_len == 0 ||
 	    ntohs(encap->tot_len) + sizeof(*pim) > skb->len)
 		goto drop;
@@ -1517,7 +1517,7 @@ static int pim_rcv(struct sk_buff * skb)
 	/* check if the inner packet is destined to mcast group */
 	encap = (struct iphdr *)(skb_transport_header(skb) +
 				 sizeof(struct pimreghdr));
-	if (!MULTICAST(encap->daddr) ||
+	if (!ipv4_is_multicast(encap->daddr) ||
 	    encap->tot_len == 0 ||
 	    ntohs(encap->tot_len) + sizeof(*pim) > skb->len)
 		goto drop;
net/ipv4/raw.c +1 -1
index f99828e..1bd188f 100644
@@ -528,7 +528,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
 	if (msg->msg_flags & MSG_DONTROUTE)
 		tos |= RTO_ONLINK;
 
-	if (MULTICAST(daddr)) {
+	if (ipv4_is_multicast(daddr)) {
 		if (!ipc.oif)
 			ipc.oif = inet->mc_index;
 		if (!saddr)
net/ipv4/route.c +29 -23

151 lines not on this page · raw message

net/ipv4/udp.c +1 -1
index 9ed6393..bb2b404 100644
@@ -623,7 +623,7 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
 		connected = 0;
 	}
 
-	if (MULTICAST(daddr)) {
+	if (ipv4_is_multicast(daddr)) {
 		if (!ipc.oif)
 			ipc.oif = inet->mc_index;
 		if (!saddr)
Signature · 1 line
1.5.3.7.949.g2221a6
#5 lore raw

PATCH 6/8 sctp: Use ipv4_is_<type>

In reply to Joe Perches
---
 include/net/sctp/constants.h |   36 ++++++------------------------------
 net/sctp/protocol.c          |   12 +++++++-----
 2 files changed, 13 insertions(+), 35 deletions(-)
include/net/sctp/constants.h +6 -30
index 05f22a6..fefcba6 100644
@@ -365,36 +365,12 @@ typedef enum {
  * Also, RFC 8.4, non-unicast addresses are not considered valid SCTP
  * addresses.
  */
-#define IS_IPV4_UNUSABLE_ADDRESS(a) \
-	((htonl(INADDR_BROADCAST) == *a) || \
-	(MULTICAST(*a)) || \
-	(((unsigned char *)(a))[0] == 0) || \
-	((((unsigned char *)(a))[0] == 198) && \
-	(((unsigned char *)(a))[1] == 18) && \
-	(((unsigned char *)(a))[2] == 0)) || \
-	((((unsigned char *)(a))[0] == 192) && \
-	(((unsigned char *)(a))[1] == 88) && \
-	(((unsigned char *)(a))[2] == 99)))
-
-/* IPv4 Link-local addresses: 169.254.0.0/16.  */
-#define IS_IPV4_LINK_ADDRESS(a) \
-	((((unsigned char *)(a))[0] == 169) && \
-	(((unsigned char *)(a))[1] == 254))
-
-/* RFC 1918 "Address Allocation for Private Internets" defines the IPv4
- * private address space as the following:
- *
- * 10.0.0.0 - 10.255.255.255 (10/8 prefix)
- * 172.16.0.0.0 - 172.31.255.255 (172.16/12 prefix)
- * 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
- */
-#define IS_IPV4_PRIVATE_ADDRESS(a) \
-	((((unsigned char *)(a))[0] == 10) || \
-	((((unsigned char *)(a))[0] == 172) && \
-	(((unsigned char *)(a))[1] >= 16) && \
-	(((unsigned char *)(a))[1] < 32)) || \
-	((((unsigned char *)(a))[0] == 192) && \
-	(((unsigned char *)(a))[1] == 168)))
+#define IS_IPV4_UNUSABLE_ADDRESS(a)	    \
+	((htonl(INADDR_BROADCAST) == a) ||  \
+	 ipv4_is_multicast(a) ||	    \
+	 ipv4_is_zeronet(a) ||		    \
+	 ipv4_is_test_198(a) ||		    \
+	 ipv4_is_anycast_6to4(a))
 
 /* Flags used for the bind address copy functions.  */
 #define SCTP_ADDR6_ALLOWED	0x00000001	/* IPv6 address is allowed by
net/sctp/protocol.c +7 -5
index d50f610..dc22d71 100644
@@ -359,7 +359,7 @@ static int sctp_v4_addr_valid(union sctp_addr *addr,
 			      const struct sk_buff *skb)
 {
 	/* Is this a non-unicast address or a unusable SCTP address? */
-	if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr))
+	if (IS_IPV4_UNUSABLE_ADDRESS(addr->v4.sin_addr.s_addr))
 		return 0;
 
 	/* Is this a broadcast address? */
@@ -408,13 +408,15 @@ static sctp_scope_t sctp_v4_scope(union sctp_addr *addr)
 	 */
 
 	/* Check for unusable SCTP addresses. */
-	if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr)) {
+	if (IS_IPV4_UNUSABLE_ADDRESS(addr->v4.sin_addr.s_addr)) {
 		retval =  SCTP_SCOPE_UNUSABLE;
-	} else if (LOOPBACK(addr->v4.sin_addr.s_addr)) {
+	} else if (ipv4_is_loopback(addr->v4.sin_addr.s_addr)) {
 		retval = SCTP_SCOPE_LOOPBACK;
-	} else if (IS_IPV4_LINK_ADDRESS(&addr->v4.sin_addr.s_addr)) {
+	} else if (ipv4_is_linklocal_169(addr->v4.sin_addr.s_addr)) {
 		retval = SCTP_SCOPE_LINK;
-	} else if (IS_IPV4_PRIVATE_ADDRESS(&addr->v4.sin_addr.s_addr)) {
+	} else if (ipv4_is_private_10(addr->v4.sin_addr.s_addr) ||
+		   ipv4_is_private_172(addr->v4.sin_addr.s_addr) ||
+		   ipv4_is_private_192(addr->v4.sin_addr.s_addr)) {
 		retval = SCTP_SCOPE_PRIVATE;
 	} else {
 		retval = SCTP_SCOPE_GLOBAL;
Signature · 1 line
1.5.3.7.949.g2221a6
#8 lore raw

PATCH 8/8 Remove unused IPV4TYPE macros

In reply to Joe Perches
---
 include/linux/in.h |   14 --------------
 1 files changed, 0 insertions(+), 14 deletions(-)
include/linux/in.h +0 -14
index f8d6073..27d8a5a 100644
@@ -272,12 +272,6 @@ static inline bool ipv4_is_zeronet(__be32 addr)
 	return (addr & htonl(0xff000000)) == htonl(0x00000000);
 }
 
-#define LOOPBACK(x)		ipv4_is_loopback(x)
-#define MULTICAST(x)		ipv4_is_multicast(x)
-#define BADCLASS(x)		ipv4_is_badclass(x)
-#define ZERONET(x)		ipv4_is_zeronet(x)
-#define LOCAL_MCAST(x)		ipv4_is_local_multicast(x)
-
 /* Special-Use IPv4 Addresses (RFC3330) */
 
 static inline bool ipv4_is_private_10(__be32 addr)
@@ -316,12 +310,4 @@ static inline bool ipv4_is_test_198(__be32 addr)
 }
 #endif
 
-#define PRIVATE_10(x)		ipv4_is_private_10(x)
-#define LINKLOCAL_169(x)	ipv4_is_linklocal_169(x)
-#define PRIVATE_172(x)		ipv4_is_private_172(x)
-#define TEST_192(x)		ipv4_is_test_192(x)
-#define ANYCAST_6TO4(x)		ipv4_is_anycast_6to4(x)
-#define PRIVATE_192(x)		ipv4_is_private_192(x)
-#define TEST_198(x)		ipv4_is_test_198(x)
-
 #endif	/* _LINUX_IN_H */
Signature · 1 line
1.5.3.7.949.g2221a6
#13 lore raw

PATCH 7/8 drivers/infiniband: Use ipv4_is_<type>

In reply to Joe Perches
---
 drivers/infiniband/core/addr.c |    4 ++--
 drivers/infiniband/core/cma.c  |    5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/infiniband/core/addr.c +2 -2
index 5381c80..0802b79 100644
@@ -265,11 +265,11 @@ static int addr_resolve_local(struct sockaddr_in *src_in,
 	if (!dev)
 		return -EADDRNOTAVAIL;
 
-	if (ZERONET(src_ip)) {
+	if (ipv4_is_zeronet(src_ip)) {
 		src_in->sin_family = dst_in->sin_family;
 		src_in->sin_addr.s_addr = dst_ip;
 		ret = rdma_copy_addr(addr, dev, dev->dev_addr);
-	} else if (LOOPBACK(src_ip)) {
+	} else if (ipv4_is_loopback(src_ip)) {
 		ret = rdma_translate_ip((struct sockaddr *)dst_in, addr);
 		if (!ret)
 			memcpy(addr->dst_dev_addr, dev->dev_addr, MAX_ADDR_LEN);
drivers/infiniband/core/cma.c +3 -2
index 0751697..b37045c 100644
@@ -624,7 +624,8 @@ static inline int cma_zero_addr(struct sockaddr *addr)
 	struct in6_addr *ip6;
 
 	if (addr->sa_family == AF_INET)
-		return ZERONET(((struct sockaddr_in *) addr)->sin_addr.s_addr);
+		return ipv4_is_zeronet(
+			((struct sockaddr_in *)addr)->sin_addr.s_addr);
 	else {
 		ip6 = &((struct sockaddr_in6 *) addr)->sin6_addr;
 		return (ip6->s6_addr32[0] | ip6->s6_addr32[1] |
@@ -634,7 +635,7 @@ static inline int cma_zero_addr(struct sockaddr *addr)
 
 static inline int cma_loopback_addr(struct sockaddr *addr)
 {
-	return LOOPBACK(((struct sockaddr_in *) addr)->sin_addr.s_addr);
+	return ipv4_is_loopback(((struct sockaddr_in *) addr)->sin_addr.s_addr);
 }
 
 static inline int cma_any_addr(struct sockaddr *addr)
Signature · 1 line
1.5.3.7.949.g2221a6
maintainer
#15 lore raw

Re: [PATCH net-2.6.25 6/8] sctp: Use ipv4_is_<type>

From: Vlad Yasevich <[email protected]>
Date: Fri, 14 Dec 2007 14:11:44 -0500

Quoted 4 lines
Quoted 1 line · Joe Perches

Thanks Joe. I've put this into my tree.

You can't, because your tree won't build without his first patch and I have to approve that and stick it into my tree first.

Just let me review and potentially pick up all of
Joe's stuff since we have this dependency.

#16 lore raw

Re: [PATCH net-2.6.25 6/8] sctp: Use ipv4_is_<type>

Quoted 4 lines · David Miller

From: Vlad Yasevich <[email protected]>
Date: Fri, 14 Dec 2007 14:11:44 -0500

Quoted 1 line

Joe Perches wrote:

Quoted 9 lines
Quoted 2 lines
Quoted 1 line

Thanks Joe. I've put this into my tree.

You can't, because your tree won't build without his first patch and I have to approve that and stick it into my tree first.

Just let me review and potentially pick up all of
Joe's stuff since we have this dependency.

Ok. In that case, you can have my ACK for the SCTP stuff.

-vlad

maintainer Applied
#24 lore raw
In reply to Joe Perches

From: Joe Perches <[email protected]>
Date: Thu, 13 Dec 2007 15:38:54 -0800

Quoted 5 lines

Change IPV4 specific macros LOOPBACK MULTICAST LOCAL_MCAST BADCLASS and ZERONET macros to inline functions ipv4_is_<type>(__be32 addr)

Adds type safety and arguably some readability.

Quoted 7 lines

Changes since last submission:

Removed ipv4_addr_octets function
Used hex constants
Converted recently added rfc3330 macros

Applied.

#10 lore raw

Re: [PATCH net-2.6.25 8/8] Remove unused IPV4TYPE macros

Quoted 4 lines · David Miller

From: Joe Perches <[email protected]>
Date: Thu, 13 Dec 2007 15:39:01 -0800

Quoted 1 line

Applied, thanks for doing this work Joe.

I broke the parisc build. Bad Joe...

Here's the patch:

drivers/parisc/led.c +1 -1
index a6d6b24..703b85e 100644
@@ -364,7 +364,7 @@ static __inline__ int led_get_net_activity(void)
 	    struct in_device *in_dev = __in_dev_get_rcu(dev);
 	    if (!in_dev || !in_dev->ifa_list)
 		continue;
-	    if (LOOPBACK(in_dev->ifa_list->ifa_local))
+	    if (ipv4_is_loopback(in_dev->ifa_list->ifa_local))
 		continue;
 	    stats = dev->get_stats(dev);
 	    rx_total += stats->rx_packets;
maintainer Applied
#11 lore raw

Re: [PATCH net-2.6.25 8/8] Remove unused IPV4TYPE macros

From: Joe Perches <[email protected]>
Date: Sun, 16 Dec 2007 20:01:06 -0800

Quoted 11 lines · David Miller
Quoted 4 lines

From: Joe Perches <[email protected]>
Date: Thu, 13 Dec 2007 15:39:01 -0800

Quoted 1 line

Applied, thanks for doing this work Joe.

I broke the parisc build. Bad Joe...

Here's the patch:

Applied, thanks.

#25 lore raw
In reply to Joe Perches
Quoted 14 lines · Joe Perches

Change IPV4 specific macros LOOPBACK MULTICAST LOCAL_MCAST BADCLASS and ZERONET macros to inline functions ipv4_is_<type>(__be32 addr)

Adds type safety and arguably some readability.

Changes since last submission:

Removed ipv4_addr_octets function
Used hex constants
Converted recently added rfc3330 macros

---

include/linux/in.h struct sockaddr_in { · line 254

Quoted 5 lines
include/linux/in.h +5 -0
+static inline bool ipv4_is_loopback(__be32 addr)
+{
+	return (addr & htonl(0xff000000)) == htonl(0x7f000000);
+}
+

Can we use __constant_htonl()?

include/linux/in.h struct sockaddr_in { · line 286

Quoted 4 lines
include/linux/in.h +4 -0
+static inline bool ipv4_is_private_10(__be32 addr)
+{
+	return (addr & htonl(0xff000000)) == htonl(0x0a000000);
+}

What are these functions needed for, even? There does not seem to be any code (at least in davem's net-2.6.25:net/ipv4/, where I dared to grep) that uses them.

maintainer
#26 lore raw

From: Jan Engelhardt <[email protected]>
Date: Mon, 17 Dec 2007 23:37:24 +0100 (CET)

Quoted 1 line

Can we use __constant_htonl()?

That should only be used in initializers.

#27 lore raw
In reply to Jan Engelhardt
Quoted 6 lines · Jan Engelhardt

include/linux/in.h struct sockaddr_in { · line 254

Quoted 5 lines
include/linux/in.h +5 -0
+static inline bool ipv4_is_loopback(__be32 addr)
+{
+	return (addr & htonl(0xff000000)) == htonl(0x7f000000);
+}
+

Can we use __constant_htonl()?

I believe the generated code is the same.

Quoted 8 lines

include/linux/in.h struct sockaddr_in { · line 286

Quoted 4 lines
include/linux/in.h +4 -0
+static inline bool ipv4_is_private_10(__be32 addr)
+{
+	return (addr & htonl(0xff000000)) == htonl(0x0a000000);
+}

What are these functions needed for, even? There does not seem to be any code (at least in davem's net-2.6.25:net/ipv4/, where I dared to grep) that uses them.

include/net/addrconf.h
net/sctp/protocol.c

cheers, Joe

maintainer
#28 lore raw
In reply to Jan Engelhardt

From: Jan Engelhardt <[email protected]>
Date: Mon, 17 Dec 2007 23:37:24 +0100 (CET)

Quoted 10 lines · Joe Perches

include/linux/in.h struct sockaddr_in { · line 286

Quoted 4 lines
include/linux/in.h +4 -0
+static inline bool ipv4_is_private_10(__be32 addr)
+{
+	return (addr & htonl(0xff000000)) == htonl(0x0a000000);
+}

What are these functions needed for, even? There does not seem to be any code (at least in davem's net-2.6.25:net/ipv4/, where I dared to grep) that uses them.

You really need to grep the whole tree, never ever decrease the scope of directories to search if you want to see if an interface is used.

It's used by some ipv6 address translation code as well as some bits in SCTP:

include/net/addrconf.h: eui[0] = (ipv4_is_zeronet(addr) || ipv4_is_private_10(addr) ||
net/sctp/protocol.c: } else if (ipv4_is_private_10(addr->v4.sin_addr.s_addr) ||

So lazy...

#29 lore raw
Quoted 10 lines · David Miller
Quoted 9 lines · Joe Perches

include/linux/in.h struct sockaddr_in { · line 286

Quoted 4 lines
include/linux/in.h +4 -0
+static inline bool ipv4_is_private_10(__be32 addr)
+{
+	return (addr & htonl(0xff000000)) == htonl(0x0a000000);
+}

What are these functions needed for, even? There does not seem to be any code (at least in davem's net-2.6.25:net/ipv4/, where I dared to grep) that uses them.

Quoted 3 lines

You really need to grep the whole tree, never ever decrease the scope of directories to search if you want to see if an interface is used.

Hah you got me there :)

Quoted 7 lines

It's used by some ipv6 address translation code as well as some bits in SCTP:

include/net/addrconf.h: eui[0] = (ipv4_is_zeronet(addr) || ipv4_is_private_10(addr) ||
net/sctp/protocol.c: } else if (ipv4_is_private_10(addr->v4.sin_addr.s_addr) ||

So lazy...

I just discovered git-grep...