summaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2015-10-23 10:22:31 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2015-10-23 10:22:31 +0000
commitd0e914952ac6acf71103ad34d6307e60937d99f2 (patch)
treea0f023eb1cfb52a512cc7fb137d9400433952ef5 /sys/net
parent302c8cd7894d4b7403fdab6604cd441749367ed7 (diff)
Introduce a new sysctl NET_RT_IFNAMES that returns only ifnames to ifindex
mappings. This will be used by if_nameindex(3), if_nametoindex(3) and if_indextoname(3) soon to fix the issues in pledge because of inet6 link local addressing. OK mpi@ benno@ deraadt@ The libc version will follow soon so better start updating your kernels
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if.h8
-rw-r--r--sys/net/rtsock.c37
2 files changed, 42 insertions, 3 deletions
diff --git a/sys/net/if.h b/sys/net/if.h
index 82dd41cc06e..760892939c1 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.h,v 1.170 2015/10/23 01:19:04 dlg Exp $ */
+/* $OpenBSD: if.h,v 1.171 2015/10/23 10:22:29 claudio Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -304,6 +304,12 @@ struct if_announcemsghdr {
#define IFAN_ARRIVAL 0 /* interface arrival */
#define IFAN_DEPARTURE 1 /* interface departure */
+/* message format used to pass interface name to index mappings */
+struct if_nameindex_msg {
+ unsigned int if_index;
+ char if_name[IFNAMSIZ];
+};
+
/*
* interface groups
*/
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 4f7d6261fac..12d963e4dec 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.173 2015/10/22 17:19:38 mpi Exp $ */
+/* $OpenBSD: rtsock.c,v 1.174 2015/10/23 10:22:29 claudio Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -102,6 +102,9 @@ int rt_msg2(int, int, struct rt_addrinfo *, caddr_t,
struct walkarg *);
void rt_xaddrs(caddr_t, caddr_t, struct rt_addrinfo *);
+int sysctl_iflist(int, struct walkarg *);
+int sysctl_ifnames(struct walkarg *);
+
struct routecb {
struct rawcb rcb;
struct timeout timeout;
@@ -1321,6 +1324,34 @@ sysctl_iflist(int af, struct walkarg *w)
}
int
+sysctl_ifnames(struct walkarg *w)
+{
+ struct if_nameindex_msg ifn;
+ struct ifnet *ifp;
+ int error = 0;
+
+ /* XXX ignore tableid for now */
+ TAILQ_FOREACH(ifp, &ifnet, if_list) {
+ if (w->w_arg && w->w_arg != ifp->if_index)
+ continue;
+ w->w_needed += sizeof(ifn);
+ if (w->w_where && w->w_needed <= 0) {
+
+ memset(&ifn, 0, sizeof(ifn));
+ ifn.if_index = ifp->if_index;
+ strlcpy(ifn.if_name, ifp->if_xname,
+ sizeof(ifn.if_name));
+ error = copyout(&ifn, w->w_where, sizeof(ifn));
+ if (error)
+ return (error);
+ w->w_where += sizeof(ifn);
+ }
+ }
+
+ return (0);
+}
+
+int
sysctl_rtable(int *name, u_int namelen, void *where, size_t *given, void *new,
size_t newlen)
{
@@ -1351,7 +1382,6 @@ sysctl_rtable(int *name, u_int namelen, void *where, size_t *given, void *new,
s = splsoftnet();
switch (w.w_op) {
-
case NET_RT_DUMP:
case NET_RT_FLAGS:
for (i = 1; i <= AF_MAX; i++) {
@@ -1387,6 +1417,9 @@ sysctl_rtable(int *name, u_int namelen, void *where, size_t *given, void *new,
&tableinfo, sizeof(tableinfo));
splx(s);
return (error);
+ case NET_RT_IFNAMES:
+ error = sysctl_ifnames(&w);
+ break;
}
splx(s);
free(w.w_tmem, M_RTABLE, 0);