Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Replace macros to get an IP address with proper inline f...
details: https://anonhg.NetBSD.org/src/rev/3cab49817d8a
branches: trunk
changeset: 346334:3cab49817d8a
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Fri Jul 08 04:33:30 2016 +0000
description:
Replace macros to get an IP address with proper inline functions
The inline functions are more friendly for applying psz/psref;
they consist of only simple interations.
diffstat:
sys/net/if_stf.c | 6 +-
sys/netinet/if_arp.c | 29 +++++----------
sys/netinet/igmp.c | 10 ++--
sys/netinet/in.c | 8 ++--
sys/netinet/in_pcb.c | 8 ++--
sys/netinet/in_var.h | 85 +++++++++++++++++++++---------------------------
sys/netinet/ip_icmp.c | 17 +++------
sys/netinet/ip_output.c | 12 +++---
sys/netinet6/in6_var.h | 12 +-----
sys/netinet6/mld6.c | 10 ++--
10 files changed, 84 insertions(+), 113 deletions(-)
diffs (truncated from 518 to 300 lines):
diff -r 14f3a0113724 -r 3cab49817d8a sys/net/if_stf.c
--- a/sys/net/if_stf.c Fri Jul 08 03:40:34 2016 +0000
+++ b/sys/net/if_stf.c Fri Jul 08 04:33:30 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_stf.c,v 1.95 2016/07/07 09:32:02 ozaki-r Exp $ */
+/* $NetBSD: if_stf.c,v 1.96 2016/07/08 04:33:30 ozaki-r Exp $ */
/* $KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
/*
@@ -75,7 +75,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.95 2016/07/07 09:32:02 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.96 2016/07/08 04:33:30 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -322,7 +322,7 @@
continue;
memcpy(&in, GET_V4(&sin6->sin6_addr), sizeof(in));
- INADDR_TO_IA(in, ia4);
+ ia4 = in_get_ia(in);
if (ia4 == NULL)
continue;
diff -r 14f3a0113724 -r 3cab49817d8a sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c Fri Jul 08 03:40:34 2016 +0000
+++ b/sys/netinet/if_arp.c Fri Jul 08 04:33:30 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_arp.c,v 1.216 2016/07/06 06:30:08 ozaki-r Exp $ */
+/* $NetBSD: if_arp.c,v 1.217 2016/07/08 04:33:30 ozaki-r Exp $ */
/*-
* Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.216 2016/07/06 06:30:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.217 2016/07/08 04:33:30 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -555,9 +555,8 @@
}
/* Announce a new entry if requested. */
if (rt->rt_flags & RTF_ANNOUNCE) {
- INADDR_TO_IA(satocsin(rt_getkey(rt))->sin_addr, ia);
- while (ia && ia->ia_ifp != ifp)
- NEXT_IA_WITH_SAME_ADDR(ia);
+ ia = in_get_ia_on_iface(
+ satocsin(rt_getkey(rt))->sin_addr, ifp);
if (ia == NULL ||
ia->ia4_flags & (IN_IFF_NOTREADY | IN_IFF_DETACHED))
;
@@ -603,10 +602,7 @@
break;
}
- INADDR_TO_IA(satocsin(rt_getkey(rt))->sin_addr, ia);
- while (ia && ia->ia_ifp != ifp)
- NEXT_IA_WITH_SAME_ADDR(ia);
-
+ ia = in_get_ia_on_iface(satocsin(rt_getkey(rt))->sin_addr, ifp);
if (ia == NULL)
break;
@@ -1028,9 +1024,9 @@
* or any address on the interface to use
* as a dummy address in the rest of this function
*/
-
- INADDR_TO_IA(itaddr, ia);
- while (ia != NULL) {
+ IN_ADDRHASH_READER_FOREACH(ia, itaddr.s_addr) {
+ if (!in_hosteq(ia->ia_addr.sin_addr, itaddr))
+ continue;
#if NCARP > 0
if (ia->ia_ifp->if_type == IFT_CARP &&
((ia->ia_ifp->if_flags & (IFF_UP|IFF_RUNNING)) ==
@@ -1057,8 +1053,6 @@
rcvif->if_bridge == ia->ia_ifp->if_bridge)
bridge_ia = ia;
#endif /* NBRIDGE > 0 */
-
- NEXT_IA_WITH_SAME_ADDR(ia);
}
#if NBRIDGE > 0
@@ -1072,12 +1066,9 @@
#endif
if (ia == NULL) {
- INADDR_TO_IA(isaddr, ia);
- while ((ia != NULL) && ia->ia_ifp != rcvif)
- NEXT_IA_WITH_SAME_ADDR(ia);
-
+ ia = in_get_ia_on_iface(isaddr, rcvif);
if (ia == NULL) {
- IFP_TO_IA(ifp, ia);
+ ia = in_get_ia_from_ifp(ifp);
if (ia == NULL) {
ARP_STATINC(ARP_STAT_RCVNOINT);
goto out;
diff -r 14f3a0113724 -r 3cab49817d8a sys/netinet/igmp.c
--- a/sys/netinet/igmp.c Fri Jul 08 03:40:34 2016 +0000
+++ b/sys/netinet/igmp.c Fri Jul 08 04:33:30 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: igmp.c,v 1.60 2016/06/28 02:02:56 ozaki-r Exp $ */
+/* $NetBSD: igmp.c,v 1.61 2016/07/08 04:33:30 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.60 2016/06/28 02:02:56 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.61 2016/07/08 04:33:30 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_mrouting.h"
@@ -361,7 +361,7 @@
* determine the arrival interface of an incoming packet.
*/
if ((ip->ip_src.s_addr & IN_CLASSA_NET) == 0) {
- IFP_TO_IA(ifp, ia); /* XXX */
+ ia = in_get_ia_from_ifp(ifp); /* XXX */
if (ia)
ip->ip_src.s_addr = ia->ia_subnet;
}
@@ -401,7 +401,7 @@
* leave requires knowing that we are the only member of a
* group.
*/
- IFP_TO_IA(ifp, ia); /* XXX */
+ ia = in_get_ia_from_ifp(ifp); /* XXX */
if (ia && in_hosteq(ip->ip_src, ia->ia_addr.sin_addr))
break;
#endif
@@ -428,7 +428,7 @@
*/
if ((ip->ip_src.s_addr & IN_CLASSA_NET) == 0) {
#ifndef MROUTING
- IFP_TO_IA(ifp, ia); /* XXX */
+ ia = in_get_ia_from_ifp(ifp); /* XXX */
#endif
if (ia)
ip->ip_src.s_addr = ia->ia_subnet;
diff -r 14f3a0113724 -r 3cab49817d8a sys/netinet/in.c
--- a/sys/netinet/in.c Fri Jul 08 03:40:34 2016 +0000
+++ b/sys/netinet/in.c Fri Jul 08 04:33:30 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in.c,v 1.172 2016/07/07 09:32:02 ozaki-r Exp $ */
+/* $NetBSD: in.c,v 1.173 2016/07/08 04:33:30 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.172 2016/07/07 09:32:02 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.173 2016/07/08 04:33:30 ozaki-r Exp $");
#include "arp.h"
@@ -390,7 +390,7 @@
* Find address for this interface, if it exists.
*/
if (ifp != NULL)
- IFP_TO_IA(ifp, ia);
+ ia = in_get_ia_from_ifp(ifp);
hostIsNew = 1; /* moved here to appease gcc */
switch (cmd) {
@@ -1559,7 +1559,7 @@
ifp = if_byindex(imo->imo_multicast_if_index);
if (ifp != NULL) {
- IFP_TO_IA(ifp, ia); /* XXX */
+ ia = in_get_ia_from_ifp(ifp); /* XXX */
} else
ia = NULL;
if (ia == NULL || ia->ia4_flags & IN_IFF_NOTREADY) {
diff -r 14f3a0113724 -r 3cab49817d8a sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c Fri Jul 08 03:40:34 2016 +0000
+++ b/sys/netinet/in_pcb.c Fri Jul 08 04:33:30 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in_pcb.c,v 1.165 2016/07/06 08:42:34 ozaki-r Exp $ */
+/* $NetBSD: in_pcb.c,v 1.166 2016/07/08 04:33:30 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.165 2016/07/06 08:42:34 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.166 2016/07/08 04:33:30 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -283,7 +283,7 @@
} else if (!in_nullhost(sin->sin_addr)) {
struct in_ifaddr *ia = NULL;
- INADDR_TO_IA(sin->sin_addr, ia);
+ ia = in_get_ia(sin->sin_addr);
/* check for broadcast addresses */
if (ia == NULL)
ia = ifatoia(ifa_ifwithaddr(sintosa(sin)));
@@ -514,7 +514,7 @@
xerror = EADDRNOTAVAIL;
return xerror;
}
- INADDR_TO_IA(ifaddr->sin_addr, ia);
+ ia = in_get_ia(ifaddr->sin_addr);
if (ia == NULL)
return (EADDRNOTAVAIL);
}
diff -r 14f3a0113724 -r 3cab49817d8a sys/netinet/in_var.h
--- a/sys/netinet/in_var.h Fri Jul 08 03:40:34 2016 +0000
+++ b/sys/netinet/in_var.h Fri Jul 08 04:33:30 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: in_var.h,v 1.77 2016/07/08 03:40:34 ozaki-r Exp $ */
+/* $NetBSD: in_var.h,v 1.78 2016/07/08 04:33:30 ozaki-r Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -222,64 +222,55 @@
extern const int inetctlerrmap[];
/*
- * Macro for finding whether an internet address (in_addr) belongs to one
+ * Find whether an internet address (in_addr) belongs to one
* of our interfaces (in_ifaddr). NULL if the address isn't ours.
*/
-#define INADDR_TO_IA(addr, ia) \
- /* struct in_addr addr; */ \
- /* struct in_ifaddr *ia; */ \
-{ \
- IN_ADDRHASH_READER_FOREACH(ia, addr.s_addr) { \
- if (in_hosteq(ia->ia_addr.sin_addr, (addr))) \
- break; \
- } \
+static inline struct in_ifaddr *
+in_get_ia(struct in_addr addr)
+{
+ struct in_ifaddr *ia;
+
+ IN_ADDRHASH_READER_FOREACH(ia, addr.s_addr) {
+ if (in_hosteq(ia->ia_addr.sin_addr, addr))
+ break;
+ }
+
+ return ia;
}
/*
- * Macro for finding the next in_ifaddr structure with the same internet
- * address as ia. Call only with a valid ia pointer.
- * Will set ia to NULL if none found.
+ * Find whether an internet address (in_addr) belongs to a specified
+ * interface. NULL if the address isn't ours.
*/
+static inline struct in_ifaddr *
+in_get_ia_on_iface(struct in_addr addr, struct ifnet *ifp)
+{
+ struct in_ifaddr *ia;
-#define NEXT_IA_WITH_SAME_ADDR(ia) \
- /* struct in_ifaddr *ia; */ \
-{ \
- struct in_addr addr; \
- addr = ia->ia_addr.sin_addr; \
- do { \
- ia = IN_ADDRHASH_READER_NEXT(ia); \
- } while ((ia != NULL) && !in_hosteq(ia->ia_addr.sin_addr, addr)); \
+ IN_ADDRHASH_READER_FOREACH(ia, addr.s_addr) {
+ if (in_hosteq(ia->ia_addr.sin_addr, addr) &&
+ ia->ia_ifp == ifp)
+ break;
+ }
+
+ return ia;
}
/*
- * Macro for finding the interface (ifnet structure) corresponding to one
- * of our IP addresses.
- */
-#define INADDR_TO_IFP(addr, ifp) \
- /* struct in_addr addr; */ \
- /* struct ifnet *ifp; */ \
-{ \
- struct in_ifaddr *ia; \
-\
Home |
Main Index |
Thread Index |
Old Index