static int ipfw_log_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) { int error; int unit; struct ifnet *ifp; error = ifc_name2unit(name, &unit); if (error) return (error); error = ifc_alloc_unit(ifc, &unit); if (error) return (error); ifp = if_alloc(IFT_PFLOG); if (ifp == NULL) { ifc_free_unit(ifc, unit); return (ENOSPC); } ifp->if_dname = ipfwname; ifp->if_dunit = unit; snprintf(ifp->if_xname, IFNAMSIZ, "%s%d", ipfwname, unit); strlcpy(name, ifp->if_xname, len); ifp->if_mtu = 65536; ifp->if_flags = IFF_UP | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_init = (void *)log_dummy; ifp->if_ioctl = log_dummy; ifp->if_start = ipfw_log_start; ifp->if_output = ipfw_log_output; ifp->if_addrlen = 6; ifp->if_hdrlen = 14; ifp->if_broadcastaddr = ipfwbroadcastaddr; ifp->if_baudrate = IF_Mbps(10); LOGIF_WLOCK(); if (log_if == NULL) log_if = ifp; else { LOGIF_WUNLOCK(); if_free(ifp); ifc_free_unit(ifc, unit); return (EEXIST); } LOGIF_WUNLOCK(); if_attach(ifp); bpfattach(ifp, DLT_EN10MB, 14); return (0); }
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); }
static struct usb_bus * usbpf_ifname2ubus(const char *ifname) { device_t dev; devclass_t dc; int unit; int error; if (strncmp(ifname, usbusname, sizeof(usbusname) - 1) != 0) return (NULL); error = ifc_name2unit(ifname, &unit); if (error || unit < 0) return (NULL); dc = devclass_find(usbusname); if (dc == NULL) return (NULL); dev = devclass_get_device(dc, unit); if (dev == NULL) return (NULL); return (device_get_softc(dev)); }