Index: head/usr.sbin/Makefile =================================================================== --- head/usr.sbin/Makefile (revision 327176) +++ head/usr.sbin/Makefile (revision 327177) @@ -1,220 +1,221 @@ # From: @(#)Makefile 5.20 (Berkeley) 6/12/93 # $FreeBSD$ .include SUBDIR= adduser \ arp \ binmiscctl \ camdd \ cdcontrol \ chkgrp \ chown \ chroot \ ckdist \ clear_locks \ crashinfo \ cron \ ctladm \ ctld \ daemon \ dconschat \ devctl \ devinfo \ + devmath \ digictl \ diskinfo \ dumpcis \ etcupdate \ extattr \ extattrctl \ fifolog \ fstyp \ fwcontrol \ getfmac \ getpmac \ gstat \ i2c \ ifmcstat \ iostat \ iovctl \ kldxref \ mailwrapper \ makefs \ memcontrol \ mergemaster \ mfiutil \ mixer \ mlxcontrol \ mountd \ mount_smbfs \ mpsutil \ mptutil \ mtest \ newsyslog \ nfscbd \ nfsd \ nfsdumpstate \ nfsrevoke \ nfsuserd \ nmtree \ nologin \ pciconf \ periodic \ powerd \ prometheus_sysctl_exporter \ pstat \ pw \ pwd_mkdb \ quot \ rarpd \ rmt \ rpcbind \ rpc.lockd \ rpc.statd \ rpc.umntall \ rtprio \ rwhod \ service \ services_mkdb \ sesutil \ setfib \ setfmac \ setpmac \ smbmsg \ snapinfo \ spray \ syslogd \ sysrc \ tcpdrop \ tcpdump \ traceroute \ trpt \ tzsetup \ uefisign \ ugidfw \ vigr \ vipw \ wake \ watch \ watchdogd \ zic \ zonectl # NB: keep these sorted by MK_* knobs SUBDIR.${MK_ACCT}+= accton SUBDIR.${MK_ACCT}+= sa SUBDIR.${MK_AMD}+= amd SUBDIR.${MK_AUDIT}+= audit SUBDIR.${MK_AUDIT}+= auditd .if ${MK_OPENSSL} != "no" SUBDIR.${MK_AUDIT}+= auditdistd .endif SUBDIR.${MK_AUDIT}+= auditreduce SUBDIR.${MK_AUDIT}+= praudit SUBDIR.${MK_AUTHPF}+= authpf SUBDIR.${MK_AUTOFS}+= autofs SUBDIR.${MK_BLACKLIST}+= blacklistctl SUBDIR.${MK_BLACKLIST}+= blacklistd SUBDIR.${MK_BLUETOOTH}+= bluetooth SUBDIR.${MK_BOOTPARAMD}+= bootparamd SUBDIR.${MK_BSDINSTALL}+= bsdinstall SUBDIR.${MK_BSNMP}+= bsnmpd SUBDIR.${MK_CTM}+= ctm SUBDIR.${MK_CXGBETOOL}+= cxgbetool SUBDIR.${MK_DIALOG}+= bsdconfig SUBDIR.${MK_EFI}+= efivar efidp efibootmgr SUBDIR.${MK_FLOPPY}+= fdcontrol SUBDIR.${MK_FLOPPY}+= fdformat SUBDIR.${MK_FLOPPY}+= fdread SUBDIR.${MK_FLOPPY}+= fdwrite SUBDIR.${MK_FMTREE}+= fmtree SUBDIR.${MK_FREEBSD_UPDATE}+= freebsd-update SUBDIR.${MK_GSSAPI}+= gssd SUBDIR.${MK_GPIO}+= gpioctl SUBDIR.${MK_INET6}+= ip6addrctl SUBDIR.${MK_INET6}+= mld6query SUBDIR.${MK_INET6}+= ndp SUBDIR.${MK_INET6}+= rip6query SUBDIR.${MK_INET6}+= route6d SUBDIR.${MK_INET6}+= rrenumd SUBDIR.${MK_INET6}+= rtadvctl SUBDIR.${MK_INET6}+= rtadvd SUBDIR.${MK_INET6}+= rtsold SUBDIR.${MK_INET6}+= traceroute6 SUBDIR.${MK_INETD}+= inetd SUBDIR.${MK_IPFW}+= ipfwpcap SUBDIR.${MK_ISCSI}+= iscsid SUBDIR.${MK_JAIL}+= jail SUBDIR.${MK_JAIL}+= jexec SUBDIR.${MK_JAIL}+= jls # XXX MK_SYSCONS SUBDIR.${MK_LEGACY_CONSOLE}+= kbdcontrol SUBDIR.${MK_LEGACY_CONSOLE}+= kbdmap SUBDIR.${MK_LEGACY_CONSOLE}+= moused SUBDIR.${MK_LEGACY_CONSOLE}+= vidcontrol .if ${MK_LIBTHR} != "no" || ${MK_LIBPTHREAD} != "no" SUBDIR.${MK_PPP}+= pppctl SUBDIR.${MK_NS_CACHING}+= nscd .endif SUBDIR.${MK_LPR}+= lpr SUBDIR.${MK_MAN_UTILS}+= manctl SUBDIR.${MK_NAND}+= nandsim SUBDIR.${MK_NAND}+= nandtool SUBDIR.${MK_NETGRAPH}+= flowctl SUBDIR.${MK_NETGRAPH}+= lmcconfig SUBDIR.${MK_NETGRAPH}+= ngctl SUBDIR.${MK_NETGRAPH}+= nghook SUBDIR.${MK_NIS}+= rpc.yppasswdd SUBDIR.${MK_NIS}+= rpc.ypupdated SUBDIR.${MK_NIS}+= rpc.ypxfrd SUBDIR.${MK_NIS}+= ypbind SUBDIR.${MK_NIS}+= ypldap SUBDIR.${MK_NIS}+= yp_mkdb SUBDIR.${MK_NIS}+= yppoll SUBDIR.${MK_NIS}+= yppush SUBDIR.${MK_NIS}+= ypserv SUBDIR.${MK_NIS}+= ypset SUBDIR.${MK_NTP}+= ntp SUBDIR.${MK_OPENSSL}+= keyserv SUBDIR.${MK_PC_SYSINSTALL}+= pc-sysinstall SUBDIR.${MK_PF}+= ftp-proxy SUBDIR.${MK_PKGBOOTSTRAP}+= pkg SUBDIR.${MK_PMC}+= pmcannotate SUBDIR.${MK_PMC}+= pmccontrol SUBDIR.${MK_PMC}+= pmcstat SUBDIR.${MK_PMC}+= pmcstudy SUBDIR.${MK_PORTSNAP}+= portsnap SUBDIR.${MK_PPP}+= ppp SUBDIR.${MK_QUOTAS}+= edquota SUBDIR.${MK_QUOTAS}+= quotaon SUBDIR.${MK_QUOTAS}+= repquota SUBDIR.${MK_SENDMAIL}+= editmap SUBDIR.${MK_SENDMAIL}+= mailstats SUBDIR.${MK_SENDMAIL}+= makemap SUBDIR.${MK_SENDMAIL}+= praliases SUBDIR.${MK_SENDMAIL}+= sendmail SUBDIR.${MK_TCP_WRAPPERS}+= tcpdchk SUBDIR.${MK_TCP_WRAPPERS}+= tcpdmatch SUBDIR.${MK_TIMED}+= timed SUBDIR.${MK_TOOLCHAIN}+= config SUBDIR.${MK_TOOLCHAIN}+= crunch SUBDIR.${MK_UNBOUND}+= unbound SUBDIR.${MK_USB}+= uathload SUBDIR.${MK_USB}+= uhsoctl SUBDIR.${MK_USB}+= usbconfig SUBDIR.${MK_USB}+= usbdump SUBDIR.${MK_UTMPX}+= ac SUBDIR.${MK_UTMPX}+= lastlogin SUBDIR.${MK_UTMPX}+= utx SUBDIR.${MK_WIRELESS}+= ancontrol SUBDIR.${MK_WIRELESS}+= wlandebug SUBDIR.${MK_WIRELESS}+= wpa SUBDIR.${MK_TESTS}+= tests .include SUBDIR_PARALLEL= .include Index: head/usr.sbin/devmatch/Makefile =================================================================== --- head/usr.sbin/devmatch/Makefile (nonexistent) +++ head/usr.sbin/devmatch/Makefile (revision 327177) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +PROG= devmatch +MAN= devmatch.8 + +LIBADD= devinfo + +.include Property changes on: head/usr.sbin/devmatch/Makefile ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/usr.sbin/devmatch/devmatch.8 =================================================================== --- head/usr.sbin/devmatch/devmatch.8 (nonexistent) +++ head/usr.sbin/devmatch/devmatch.8 (revision 327177) @@ -0,0 +1,85 @@ +.\" +.\" Copyright (c) 2017 Netflix, Inc +.\" +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd December 25, 2017 +.Dt DEVMATCH 8 +.Os +.Sh NAME +.Nm devinfo +.Nd print information about unattached devices +.Sh SYNOPSIS +.Nm +.Op Fl aduv +.Op Fl -all +.Op Fl -dump +.Op Fl -unbound +.Op Fl -verbose +.Sh DESCRIPTION +The +.Nm +utility, without any arguments, prints all the kernel modules it has +found for all the unattached, enabled devices in the system. +.Bl -tag -width 20m +.It Fl a Fl -all +Include all devices, not just the ones that are unattached. +.It Fl d Fl -dump +Produce a human readable dump of the +.Pa linker.hints +file. +.It Fl u Fl -unbound +Attempt to produce a list of those drivers with PNP info whose driver +tables with that PNP info can't be found. +.It Fl v Fl -verbose +Produce more verbose output. +.El +.Sh SEE ALSO +.Xr devinfo 8 +.Sh BUGS +The kernel has hints in it, but we exclude it from the list of modules +to suggest for unmatched devices. +We exclude it when suggesting drivers, but include it when looking for +unbound devices or producing a full dump of +.Pa linker.hints . +This can be confusing. +.Pp +Some modules are hard links in +.Pa /boot/kernel +and will be reported twice. +.Pp +The PNP string's attributes are evaluated once per PNP entry on that +bus rather than once. +.Pp +The term PNP is overloaded in FreeBSD. +It means, generically, the identifying data the bus provides about a +device. +While this include old ISA PNP identifiers, it also includes the +logical equivalent in USB, PCI, and others. +.Pp +Many drivers currently lack proper PNP table decorations and need to +be updated. +.Sh AUTHORS +.An Warner Losh Aq Mt imp@FreeBSD.org Property changes on: head/usr.sbin/devmatch/devmatch.8 ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/usr.sbin/devmatch/devmatch.c =================================================================== --- head/usr.sbin/devmatch/devmatch.c (nonexistent) +++ head/usr.sbin/devmatch/devmatch.c (revision 327177) @@ -0,0 +1,425 @@ +/*- + * Copyright (c) 2017 Netflix, Inc + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* options descriptor */ +static struct option longopts[] = { + { "all", no_argument, NULL, 'a' }, + { "dump", no_argument, NULL, 'd' }, + { "unbound", no_argument, NULL, 'u' }, + { "verbose", no_argument, NULL, 'v' }, + { NULL, 0, NULL, 0 } +}; + +static int all_flag; +static int dump_flag; +static int unbound_flag; +static int verbose_flag; + +static void *hints; +static void *hints_end; + +static void +read_linker_hints(void) +{ + char fn[MAXPATHLEN]; + struct stat sb; + char *modpath, *p, *q; + size_t buflen; + int fd; + + if (sysctlbyname("kern.module_path", NULL, &buflen, NULL, 0) < 0) + errx(1, "Can't find kernel module path."); + modpath = malloc(buflen); + if (modpath == NULL) + err(1, "Can't get memory for modpath."); + if (sysctlbyname("kern.module_path", modpath, &buflen, NULL, 0) < 0) + errx(1, "Can't find kernel module path."); + p = modpath; + while ((q = strsep(&p, ";")) != NULL) { + snprintf(fn, sizeof(fn), "%s/linker.hints", q); + if (stat(fn, &sb) != 0) + continue; + hints = malloc(sb.st_size); + if (hints == NULL) + err(1, "not enough space to read hints file of %ju bytes", (uintmax_t)sb.st_size); + fd = open(fn, O_RDONLY); + if (fd < 0) + err(1, "Can't open %s for reading", fn); + if (read(fd, hints, sb.st_size) != sb.st_size) + err(1, "Can't read in %ju bytes from %s", (uintmax_t)sb.st_size, fn); + close(fd); + break; + } + if (q == NULL) { + warnx("Can't read linker hints file."); + free(hints); + hints = NULL; + } + if (*(int *)(intptr_t)hints != LINKER_HINTS_VERSION) { + warnx("Linker hints version %d doesn't match expected %d.", + *(int *)(intptr_t)hints, LINKER_HINTS_VERSION); + free(hints); + hints = NULL; + } + if (hints != NULL) + hints_end = (void *)((intptr_t)hints + (intptr_t)sb.st_size); +} + +static int +getint(void **ptr) +{ + int *p = *ptr; + int rv; + + p = (int *)roundup2((intptr_t)p, sizeof(int)); + rv = *p++; + *ptr = p; + return rv; +} + +static void +getstr(void **ptr, char *val) +{ + int *p = *ptr; + char *c = (char *)p; + int len = *(uint8_t *)c; + + memcpy(val, c + 1, len); + val[len] = 0; + c += len + 1; + *ptr = (void *)c; +} + +static int +pnpval_as_int(const char *val, const char *pnpinfo) +{ + int rv; + char key[256]; + char *cp; + + if (pnpinfo == NULL) + return -1; + + cp = strchr(val, ';'); + key[0] = ' '; + if (cp == NULL) + strcpy(key + 1, val); + else { + memcpy(key + 1, val, cp - val); + key[cp - val + 1] = '\0'; + } + strcat(key, "="); + if (strncmp(key + 1, pnpinfo, strlen(key + 1)) == 0) + rv = strtol(pnpinfo + strlen(key + 1), NULL, 0); + else { + cp = strstr(pnpinfo, key); + if (cp == NULL) + rv = -1; + else + rv = strtol(cp + strlen(key), NULL, 0); + } + return rv; +} + +static void +quoted_strcpy(char *dst, const char *src) +{ + char q = ' '; + + if (*src == '\'' || *src == '"') + q = *src++; + while (*src && *src != q) + *dst++ = *src++; // XXX backtick quoting + *dst++ = '\0'; + // XXX overflow +} + +static char * +pnpval_as_str(const char *val, const char *pnpinfo) +{ + static char retval[256]; + char key[256]; + char *cp; + + if (pnpinfo == NULL) { + *retval = '\0'; + return retval; + } + + cp = strchr(val, ';'); + key[0] = ' '; + if (cp == NULL) + strcpy(key + 1, val); + else { + memcpy(key + 1, val, cp - val); + key[cp - val + 1] = '\0'; + } + strcat(key, "="); + if (strncmp(key + 1, pnpinfo, strlen(key + 1)) == 0) + quoted_strcpy(retval, pnpinfo + strlen(key + 1)); + else { + cp = strstr(pnpinfo, key); + if (cp == NULL) + strcpy(retval, "MISSING"); + else + quoted_strcpy(retval, cp + strlen(key)); + } + return retval; +} + +static void +search_hints(const char *bus, const char *dev, const char *pnpinfo) +{ + char val1[256], val2[256]; + int ival, len, ents, i, notme, mask, bit, v, found; + void *ptr, *walker; + char *lastmod = NULL, *cp, *s; + + walker = hints; + getint(&walker); + found = 0; + while (walker < hints_end) { + len = getint(&walker); + ival = getint(&walker); + ptr = walker; + switch (ival) { + case MDT_VERSION: + getstr(&ptr, val1); + ival = getint(&ptr); + getstr(&ptr, val2); + if (dump_flag) + printf("Version: if %s.%d kmod %s\n", val1, ival, val2); + break; + case MDT_MODULE: + getstr(&ptr, val1); + getstr(&ptr, val2); + if (lastmod) + free(lastmod); + lastmod = strdup(val2); + if (dump_flag) + printf("Module %s in %s\n", val1, val2); + break; + case MDT_PNP_INFO: + if (!dump_flag && !unbound_flag && strcmp(lastmod, "kernel") == 0) + break; + getstr(&ptr, val1); + getstr(&ptr, val2); + ents = getint(&ptr); + if (bus && strcmp(val1, bus) != 0) + break; + if (dump_flag) + printf("PNP info for bus %s format %s %d entries (%s)\n", + val1, val2, ents, lastmod); + for (i = 0; i < ents; i++) { + if (dump_flag) + printf(" "); + cp = val2; + notme = 0; + mask = -1; + bit = -1; + do { + switch (*cp) { + case 'I': + case 'J': + case 'G': + case 'L': + case 'M': + ival = getint(&ptr); + if (dump_flag) { + printf("%#x:", ival); + break; + } + if (bit >= 0 && ((1 << bit) & mask) == 0) + break; + v = pnpval_as_int(cp + 2, pnpinfo); + switch (*cp) { + case 'J': + if (ival == -1) + break; + /*FALLTHROUGH*/ + case 'I': + if (v != ival && ival != 0) + notme++; + break; + case 'G': + if (v < ival) + notme++; + break; + case 'L': + if (v > ival) + notme++; + break; + case 'M': + mask = ival; + break; + } + break; + case 'D': + case 'Z': + getstr(&ptr, val1); + if (dump_flag) { + printf("'%s':", val1); + break; + } + if (*cp == 'D') + break; + s = pnpval_as_str(cp + 2, pnpinfo); + if (strcmp(s, val1) != 0) + notme++; + break; + default: + break; + } + bit++; + cp = strchr(cp, ';'); + if (cp) + cp++; + } while (cp && *cp); + if (dump_flag) + printf("\n"); + else if (!notme) { + if (!unbound_flag) { + if (all_flag) + printf("%s: ", *dev ? dev : "unattahed" ); + printf("%s\n", lastmod); + } + found++; + } + } + break; + default: + if (dump_flag) + printf("Unknown Type %d len %d\n", ival, len); + break; + } + walker = (void *)(len - sizeof(int) + (intptr_t)walker); + } + if (unbound_flag && found == 0 && *pnpinfo) { + if (verbose_flag) + printf("------------------------- "); + printf("%s on %s pnpinfo %s", *dev ? dev : "unattahed", bus, pnpinfo); + if (verbose_flag) + printf(" -------------------------"); + printf("\n"); + } +} + +static int +find_unmatched(struct devinfo_dev *dev, void *arg) +{ + struct devinfo_dev *parent; + char *bus, *p; + + do { + if (!all_flag && dev->dd_name[0] != '\0') + break; + if (!(dev->dd_flags & DF_ENABLED)) + break; + parent = devinfo_handle_to_device(dev->dd_parent); + bus = strdup(parent->dd_name); + p = bus + strlen(bus) - 1; + while (p >= bus && isdigit(*p)) + p--; + *++p = '\0'; + if (verbose_flag) + printf("Searching %s %s bus at %s for pnpinfo %s\n", + dev->dd_name, bus, dev->dd_location, dev->dd_pnpinfo); + search_hints(bus, dev->dd_name, dev->dd_pnpinfo); + free(bus); + } while (0); + + return (devinfo_foreach_device_child(dev, find_unmatched, arg)); +} + +static void +usage(void) +{ + + errx(1, "devmatch [-adv]"); +} + +int +main(int argc, char **argv) +{ + struct devinfo_dev *root; + int ch; + + while ((ch = getopt_long(argc, argv, "aduv", + longopts, NULL)) != -1) { + switch (ch) { + case 'a': + all_flag++; + break; + case 'd': + dump_flag++; + break; + case 'u': + unbound_flag++; + break; + case 'v': + verbose_flag++; + break; + default: + usage(); + } + } + argc -= optind; + argv += optind; + + if (argc >= 1) + usage(); + + read_linker_hints(); + if (dump_flag) { + search_hints(NULL, NULL, NULL); + exit(0); + } + + if (devinfo_init()) + err(1, "devinfo_init"); + if ((root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE)) == NULL) + errx(1, "can't find root device"); + devinfo_foreach_device_child(root, find_unmatched, (void *)0); + devinfo_free(); +} Property changes on: head/usr.sbin/devmatch/devmatch.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property