Beispiel #1
0
static int
stf_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params)
{
	int err, unit;
	struct stf_softc *sc;
	struct ifnet *ifp;

	/*
	 * We can only have one unit, but since unit allocation is
	 * already locked, we use it to keep from allocating extra
	 * interfaces.
	 */
	unit = STFUNIT;
	err = ifc_alloc_unit(ifc, &unit);
	if (err != 0)
		return (err);

	sc = malloc(sizeof(struct stf_softc), M_STF, M_WAITOK | M_ZERO);
	ifp = STF2IFP(sc) = if_alloc(IFT_STF);
	if (ifp == NULL) {
		free(sc, M_STF);
		ifc_free_unit(ifc, unit);
		return (ENOSPC);
	}
	ifp->if_softc = sc;
#ifndef __rtems__
	sc->sc_fibnum = curthread->td_proc->p_fibnum;
#else /* __rtems__ */
	sc->sc_fibnum = BSD_DEFAULT_FIB;
#endif /* __rtems__ */

	/*
	 * Set the name manually rather then using if_initname because
	 * we don't conform to the default naming convention for interfaces.
	 */
	strlcpy(ifp->if_xname, name, IFNAMSIZ);
	ifp->if_dname = ifc->ifc_name;
	ifp->if_dunit = IF_DUNIT_NONE;

	mtx_init(&(sc)->sc_ro_mtx, "stf ro", NULL, MTX_DEF);
	sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6,
	    stf_encapcheck, &in_stf_protosw, sc);
	if (sc->encap_cookie == NULL) {
		if_printf(ifp, "attach failed\n");
		free(sc, M_STF);
		ifc_free_unit(ifc, unit);
		return (ENOMEM);
	}

	ifp->if_mtu    = IPV6_MMTU;
	ifp->if_ioctl  = stf_ioctl;
	ifp->if_output = stf_output;
	ifp->if_snd.ifq_maxlen = ifqmaxlen;
	if_attach(ifp);
	bpfattach(ifp, DLT_NULL, sizeof(u_int32_t));
	return (0);
}
Beispiel #2
0
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);
}
Beispiel #3
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);
}
Beispiel #4
0
static int
t4_cloner_create(struct if_clone *ifc, char *name, size_t len, caddr_t params)
{
	struct match_rr mrr;
	struct adapter *sc;
	struct ifnet *ifp;
	int rc, unit;
	const uint8_t lla[ETHER_ADDR_LEN] = {0, 0, 0, 0, 0, 0};

	mrr.name = name;
	mrr.lock = 1;
	mrr.sc = NULL;
	mrr.rc = ENOENT;
	t4_iterate(match_name, &mrr);

	if (mrr.rc != 0)
		return (mrr.rc);
	sc = mrr.sc;

	KASSERT(sc != NULL, ("%s: name (%s) matched but softc is NULL",
	    __func__, name));
	ASSERT_SYNCHRONIZED_OP(sc);

	sx_xlock(&t4_trace_lock);

	if (sc->ifp != NULL) {
		rc = EEXIST;
		goto done;
	}
	if (sc->traceq < 0) {
		rc = EAGAIN;
		goto done;
	}


	unit = -1;
	rc = ifc_alloc_unit(ifc, &unit);
	if (rc != 0)
		goto done;

	ifp = if_alloc(IFT_ETHER);
	if (ifp == NULL) {
		ifc_free_unit(ifc, unit);
		rc = ENOMEM;
		goto done;
	}

	/* Note that if_xname is not <if_dname><if_dunit>. */
	strlcpy(ifp->if_xname, name, sizeof(ifp->if_xname));
	ifp->if_dname = t4_cloner_name;
	ifp->if_dunit = unit;
	ifp->if_init = tracer_init;
	ifp->if_flags = IFF_SIMPLEX | IFF_DRV_RUNNING;
	ifp->if_ioctl = tracer_ioctl;
	ifp->if_transmit = tracer_transmit;
	ifp->if_qflush = tracer_qflush;
	ifp->if_capabilities = IFCAP_JUMBO_MTU | IFCAP_VLAN_MTU;
	ifmedia_init(&sc->media, IFM_IMASK, tracer_media_change,
	    tracer_media_status);
	ifmedia_add(&sc->media, IFM_ETHER | IFM_FDX | IFM_NONE, 0, NULL);
	ifmedia_set(&sc->media, IFM_ETHER | IFM_FDX | IFM_NONE);
	ether_ifattach(ifp, lla);

	mtx_lock(&sc->ifp_lock);
	ifp->if_softc = sc;
	sc->ifp = ifp;
	mtx_unlock(&sc->ifp_lock);
done:
	sx_xunlock(&t4_trace_lock);
	end_synchronized_op(sc, 0);
	return (rc);
}