-/* $OpenBSD: kern_pledge.c,v 1.66 2015/10/23 01:10:01 deraadt Exp $ */
+/* $OpenBSD: kern_pledge.c,v 1.67 2015/10/23 10:22:29 claudio Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
if (miblen == 2 && /* gethostname() */
mib[0] == CTL_KERN && mib[1] == KERN_HOSTNAME)
return (0);
+ if (miblen == 6 && /* if_nameindex() */
+ mib[0] == CTL_NET && mib[1] == PF_ROUTE &&
+ mib[2] == 0 && mib[3] == 0 && mib[4] == NET_RT_IFNAMES)
+ return (0);
if (miblen == 2 && /* uname() */
mib[0] == CTL_KERN && mib[1] == KERN_OSTYPE)
return (0);
-/* $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 $ */
/*
#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
*/
-/* $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 $ */
/*
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;
return (0);
}
+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)
s = splsoftnet();
switch (w.w_op) {
-
case NET_RT_DUMP:
case NET_RT_FLAGS:
for (i = 1; i <= AF_MAX; i++) {
&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);
-/* $OpenBSD: socket.h,v 1.89 2015/10/20 18:04:03 deraadt Exp $ */
+/* $OpenBSD: socket.h,v 1.90 2015/10/23 10:22:30 claudio Exp $ */
/* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */
/*
#define NET_RT_IFLIST 3 /* survey interface list */
#define NET_RT_STATS 4 /* routing table statistics */
#define NET_RT_TABLE 5
-#define NET_RT_MAXID 6
+#define NET_RT_IFNAMES 6
+#define NET_RT_MAXID 7
#define CTL_NET_RT_NAMES { \
{ 0, 0 }, \
{ "iflist", CTLTYPE_STRUCT }, \
{ "stats", CTLTYPE_STRUCT }, \
{ "table", CTLTYPE_STRUCT }, \
+ { "ifnames", CTLTYPE_STRUCT }, \
}
/*
-/* $OpenBSD: sysctl.h,v 1.156 2015/07/18 15:51:17 mpi Exp $ */
+/* $OpenBSD: sysctl.h,v 1.157 2015/10/23 10:22:30 claudio Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
struct rtentry;
struct walkarg;
int sysctl_dumpentry(struct rtentry *, void *, unsigned int);
-int sysctl_iflist(int, struct walkarg *);
int sysctl_rtable(int *, u_int, void *, size_t *, void *, size_t);
int sysctl_clockrate(char *, size_t *, void *);
int sysctl_vnode(char *, size_t *, struct proc *);