summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2015-11-11 10:23:23 +0000
committermpi <mpi@openbsd.org>2015-11-11 10:23:23 +0000
commit5e9a6f6c0847c3c556b6904c110e113d5a7fd7c9 (patch)
tree0f37a8e0259508318032cc5c4aa2d2b2a4606d9c
parentKill useless IFQ_POLL(). (diff)
downloadwireguard-openbsd-5e9a6f6c0847c3c556b6904c110e113d5a7fd7c9.tar.xz
wireguard-openbsd-5e9a6f6c0847c3c556b6904c110e113d5a7fd7c9.zip
Store the index of the lo0 interface instead of a pointer to its
descriptor. Allow to get rid of two if_ref() in the output paths. ok dlg@
-rw-r--r--sys/net/if.c15
-rw-r--r--sys/net/if_loop.c8
-rw-r--r--sys/net/if_var.h4
-rw-r--r--sys/netinet/ip_output.c4
-rw-r--r--sys/netinet6/ip6_input.c4
-rw-r--r--sys/netinet6/ip6_output.c4
6 files changed, 22 insertions, 17 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index fb88918fd43..41589ce3a80 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.404 2015/11/07 12:42:19 mpi Exp $ */
+/* $OpenBSD: if.c,v 1.405 2015/11/11 10:23:23 mpi Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -250,7 +250,7 @@ struct srp_gc if_map_gc = SRP_GC_INITIALIZER(if_map_dtor, NULL);
struct ifnet_head ifnet = TAILQ_HEAD_INITIALIZER(ifnet);
struct ifnet_head iftxlist = TAILQ_HEAD_INITIALIZER(iftxlist);
-struct ifnet *lo0ifp;
+unsigned int lo0ifidx;
void
if_idxmap_init(unsigned int limit)
@@ -1275,11 +1275,12 @@ if_rtrequest_dummy(struct ifnet *ifp, int req, struct rtentry *rt)
void
p2p_rtrequest(struct ifnet *ifp, int req, struct rtentry *rt)
{
+ struct ifnet *lo0ifp;
struct ifaddr *ifa, *lo0ifa;
switch (req) {
case RTM_ADD:
- if ((rt->rt_flags & RTF_LOCAL) == 0)
+ if (!ISSET(rt->rt_flags, RTF_LOCAL))
break;
TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
@@ -1298,10 +1299,14 @@ p2p_rtrequest(struct ifnet *ifp, int req, struct rtentry *rt)
* (ab)use it for any route related to an interface of a
* different rdomain.
*/
- TAILQ_FOREACH(lo0ifa, &lo0ifp->if_addrlist, ifa_list)
+ lo0ifp = if_get(lo0ifidx);
+ KASSERT(lo0ifp != NULL);
+ TAILQ_FOREACH(lo0ifa, &lo0ifp->if_addrlist, ifa_list) {
if (lo0ifa->ifa_addr->sa_family ==
ifa->ifa_addr->sa_family)
break;
+ }
+ if_put(lo0ifp);
if (lo0ifa == NULL)
break;
@@ -1377,7 +1382,7 @@ if_up(struct ifnet *ifp)
#ifdef INET6
/* Userland expects the kernel to set ::1 on lo0. */
- if (ifp == lo0ifp)
+ if (ifp->if_index == lo0ifidx)
in6_ifattach(ifp);
#endif
diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c
index be1e31f62e8..7611b39bb7e 100644
--- a/sys/net/if_loop.c
+++ b/sys/net/if_loop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_loop.c,v 1.72 2015/10/25 11:58:11 mpi Exp $ */
+/* $OpenBSD: if_loop.c,v 1.73 2015/11/11 10:23:23 mpi Exp $ */
/* $NetBSD: if_loop.c,v 1.15 1996/05/07 02:40:33 thorpej Exp $ */
/*
@@ -176,9 +176,9 @@ loop_clone_create(struct if_clone *ifc, int unit)
ifp->if_addrlen = 0;
IFQ_SET_READY(&ifp->if_snd);
if (unit == 0) {
- lo0ifp = ifp;
if_attachhead(ifp);
- if_addgroup(lo0ifp, ifc->ifc_name);
+ if_addgroup(ifp, ifc->ifc_name);
+ lo0ifidx = ifp->if_index;
} else
if_attach(ifp);
if_alloc_sadl(ifp);
@@ -191,7 +191,7 @@ loop_clone_create(struct if_clone *ifc, int unit)
int
loop_clone_destroy(struct ifnet *ifp)
{
- if (ifp == lo0ifp)
+ if (ifp->if_index == lo0ifidx)
return (EPERM);
if_detach(ifp);
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 4c169c18dba..b2e70e50a1b 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_var.h,v 1.51 2015/10/25 11:58:11 mpi Exp $ */
+/* $OpenBSD: if_var.h,v 1.52 2015/11/11 10:23:23 mpi Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -402,7 +402,7 @@ int niq_enlist(struct niqueue *, struct mbuf_list *);
sysctl_mq((_n), (_l), (_op), (_olp), (_np), (_nl), &(_niq)->ni_q)
extern struct ifnet_head ifnet;
-extern struct ifnet *lo0ifp;
+extern unsigned int lo0ifidx;
void if_start(struct ifnet *);
int if_enqueue(struct ifnet *, struct mbuf *);
diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index 7f50c60f638..6833a0c3133 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_output.c,v 1.305 2015/11/03 21:11:48 naddy Exp $ */
+/* $OpenBSD: ip_output.c,v 1.306 2015/11/11 10:23:23 mpi Exp $ */
/* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */
/*
@@ -202,7 +202,7 @@ reroute:
ia = ifatoia(ro->ro_rt->rt_ifa);
if (ISSET(ro->ro_rt->rt_flags, RTF_LOCAL))
- ifp = if_ref(lo0ifp);
+ ifp = if_get(lo0ifidx);
else
ifp = if_get(ro->ro_rt->rt_ifidx);
if ((mtu = ro->ro_rt->rt_rmx.rmx_mtu) == 0)
diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c
index 5fe4f880d5a..3479082b849 100644
--- a/sys/netinet6/ip6_input.c
+++ b/sys/netinet6/ip6_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_input.c,v 1.150 2015/10/29 16:04:10 tedu Exp $ */
+/* $OpenBSD: ip6_input.c,v 1.151 2015/11/11 10:23:23 mpi Exp $ */
/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
/*
@@ -202,7 +202,7 @@ ip6_input(struct mbuf *m)
} else {
if (m->m_next) {
if (m->m_flags & M_LOOP) {
- ip6stat.ip6s_m2m[lo0ifp->if_index]++; /*XXX*/
+ ip6stat.ip6s_m2m[lo0ifidx]++; /*XXX*/
} else if (ifp->if_index < nitems(ip6stat.ip6s_m2m))
ip6stat.ip6s_m2m[ifp->if_index]++;
else
diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c
index b9c5dc3c01b..c14909eb0fa 100644
--- a/sys/netinet6/ip6_output.c
+++ b/sys/netinet6/ip6_output.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_output.c,v 1.198 2015/11/03 21:39:34 chl Exp $ */
+/* $OpenBSD: ip6_output.c,v 1.199 2015/11/11 10:23:23 mpi Exp $ */
/* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */
/*
@@ -549,7 +549,7 @@ reroute:
goto bad;
}
if (ISSET(rt->rt_flags, RTF_LOCAL))
- ifp = if_ref(lo0ifp);
+ ifp = if_get(lo0ifidx);
else
ifp = if_get(rt->rt_ifidx);
} else {