static int usbpf_clone_match(struct if_clone *ifc, const char *name) { struct usb_bus *ubus; ubus = usbpf_ifname2ubus(name); if (ubus == NULL) return (0); if (ubus->ifp != NULL) return (0); return (1); }
static int usbpf_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) { int error; int unit; struct ifnet *ifp; struct usb_bus *ubus; error = ifc_name2unit(name, &unit); if (error) return (error); if (unit < 0) return (EINVAL); ubus = usbpf_ifname2ubus(name); if (ubus == NULL) return (1); if (ubus->ifp != NULL) return (1); error = ifc_alloc_unit(ifc, &unit); if (error) { ifc_free_unit(ifc, unit); device_printf(ubus->parent, "usbpf: Could not allocate " "instance\n"); return (error); } ifp = ubus->ifp = if_alloc(IFT_USB); if (ifp == NULL) { ifc_free_unit(ifc, unit); device_printf(ubus->parent, "usbpf: Could not allocate " "instance\n"); return (ENOSPC); } strlcpy(ifp->if_xname, name, sizeof(ifp->if_xname)); ifp->if_softc = ubus; ifp->if_dname = usbusname; ifp->if_dunit = unit; ifp->if_ioctl = usbpf_ioctl; if_attach(ifp); ifp->if_flags |= IFF_UP; rt_ifmsg(ifp); /* * XXX According to the specification of DLT_USB, it indicates * packets beginning with USB setup header. But not sure all * packets would be. */ bpfattach(ifp, DLT_USB, USBPF_HDR_LEN); return (0); }