diff options
author | hrs <hrs@FreeBSD.org> | 2012-07-09 07:25:09 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2012-07-09 07:25:09 +0000 |
commit | cb8b05054c4ba695af191e936a81d3dd581250b5 (patch) | |
tree | b0ac3a49cf969beee4d45522efbd86778388f44b /usr.sbin/usbdump | |
parent | de86634e9a9edfa2f24d507afdddf3f16d9f4282 (diff) | |
download | FreeBSD-src-cb8b05054c4ba695af191e936a81d3dd581250b5.zip FreeBSD-src-cb8b05054c4ba695af191e936a81d3dd581250b5.tar.gz |
Make usbusN logging pseudo-interface used by usbdump(8) clonable. One is
now created/destroyed automatically by usbdump(8).
Note that "hw.usb.no_pf" loader tunable is now obsolete.
Reviewed by: hselasky
Diffstat (limited to 'usr.sbin/usbdump')
-rw-r--r-- | usr.sbin/usbdump/usbdump.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/usr.sbin/usbdump/usbdump.c b/usr.sbin/usbdump/usbdump.c index 1e8d171..7e7eae9 100644 --- a/usr.sbin/usbdump/usbdump.c +++ b/usr.sbin/usbdump/usbdump.c @@ -795,6 +795,8 @@ main(int argc, char *argv[]) int o; int filt_unit; int filt_ep; + int s; + int ifindex; const char *optstring; char *pp; @@ -887,9 +889,20 @@ main(int argc, char *argv[]) /* clear ifr structure */ memset(&ifr, 0, sizeof(ifr)); + /* Try to create usbusN interface if it is not available. */ + s = socket(AF_LOCAL, SOCK_DGRAM, 0); + if (s < 0) + errx(EXIT_FAILURE, "Could not open a socket"); + ifindex = if_nametoindex(i_arg); + if (ifindex == 0) { + (void)strlcpy(ifr.ifr_name, i_arg, sizeof(ifr.ifr_name)); + if (ioctl(s, SIOCIFCREATE2, &ifr) < 0) + errx(EXIT_FAILURE, "Invalid bus interface: %s", i_arg); + } + for ( ; v >= USBPF_HDR_LEN; v >>= 1) { (void)ioctl(fd, BIOCSBLEN, (caddr_t)&v); - (void)strncpy(ifr.ifr_name, i_arg, sizeof(ifr.ifr_name)); + (void)strlcpy(ifr.ifr_name, i_arg, sizeof(ifr.ifr_name)); if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) >= 0) break; } @@ -930,6 +943,17 @@ main(int argc, char *argv[]) printf("%d packets received by filter\n", us.bs_recv); printf("%d packets dropped by kernel\n", us.bs_drop); + /* + * Destroy the usbusN interface only if it was created by + * usbdump(8). Ignore when it was already destroyed. + */ + if (ifindex == 0 && if_nametoindex(i_arg) > 0) { + (void)strlcpy(ifr.ifr_name, i_arg, sizeof(ifr.ifr_name)); + if (ioctl(s, SIOCIFDESTROY, &ifr) < 0) + warn("SIOCIFDESTROY ioctl failed"); + } + close(s); + if (p->fd > 0) close(p->fd); if (p->rfd > 0) |