static int tun_clone_create(struct if_clone *ifc, int unit) { struct tun_softc *tp; if ((tp = tun_find_zunit(unit)) == NULL) { /* Allocate a new instance */ tp = malloc(sizeof(*tp), M_DEVBUF, M_WAITOK|M_ZERO); tp->tun_unit = unit; mutex_init(&tp->tun_lock, MUTEX_DEFAULT, IPL_NET); selinit(&tp->tun_rsel); selinit(&tp->tun_wsel); } else { /* Revive tunnel instance; clear ifp part */ (void)memset(&tp->tun_if, 0, sizeof(struct ifnet)); } if_initname(&tp->tun_if, ifc->ifc_name, unit); tunattach0(tp); tp->tun_flags |= TUN_INITED; tp->tun_osih = softint_establish(SOFTINT_CLOCK, tun_o_softintr, tp); tp->tun_isih = softint_establish(SOFTINT_CLOCK, tun_i_softintr, tp); simple_lock(&tun_softc_lock); LIST_INSERT_HEAD(&tun_softc_list, tp, tun_list); simple_unlock(&tun_softc_lock); return (0); }
static int mpls_clone_create(struct if_clone *ifc, int unit) { struct mpls_softc *sc; atomic_inc_uint(&mpls_count); sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO); if_initname(&sc->sc_if, ifc->ifc_name, unit); sc->sc_if.if_softc = sc; sc->sc_if.if_type = IFT_MPLS; sc->sc_if.if_addrlen = 0; sc->sc_if.if_hdrlen = sizeof(union mpls_shim); sc->sc_if.if_dlt = DLT_NULL; sc->sc_if.if_mtu = 1500; sc->sc_if.if_flags = 0; sc->sc_if._if_input = mpls_input; sc->sc_if.if_output = mpls_output; sc->sc_if.if_ioctl = mpls_ioctl; if_attach(&sc->sc_if); if_alloc_sadl(&sc->sc_if); bpf_attach(&sc->sc_if, DLT_NULL, sizeof(uint32_t)); return 0; }
static int enc_clone_create(struct if_clone *ifc, int unit, caddr_t params) { struct ifnet *ifp; struct enc_softc *sc; sc = malloc(sizeof(struct enc_softc), M_DEVBUF, M_WAITOK | M_ZERO); ifp = sc->sc_ifp = if_alloc(IFT_ENC); if (ifp == NULL) { free(sc, M_DEVBUF); return (ENOSPC); } if (V_enc_sc != NULL) { if_free(ifp); free(sc, M_DEVBUF); return (EEXIST); } V_enc_sc = sc; if_initname(ifp, encname, unit); ifp->if_mtu = ENCMTU; ifp->if_ioctl = enc_ioctl; ifp->if_output = enc_output; ifp->if_softc = sc; if_attach(ifp); bpfattach(ifp, DLT_ENC, sizeof(struct enchdr)); return (0); }
/* ARGSUSED */ static void loopattach(void *dummy) { struct ifnet *ifp; int i; for (i = 0, ifp = loif; i < NLOOP; i++, ifp++) { if_initname(ifp, "lo", i); ifp->if_mtu = LOMTU; ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST; ifp->if_capabilities = IFCAP_HWCSUM; ifp->if_hwassist = LO_CSUM_FEATURES; ifp->if_capenable = ifp->if_capabilities; ifp->if_ioctl = loioctl; ifp->if_output = looutput; ifp->if_type = IFT_LOOP; ifq_set_maxlen(&ifp->if_snd, ifqmaxlen); ifq_set_ready(&ifp->if_snd); #ifdef ALTQ ifp->if_start = lo_altqstart; #endif if_attach(ifp, NULL); bpfattach(ifp, DLT_NULL, sizeof(u_int)); } }
static int vhost_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) { struct vhost_priv *sc; struct ifnet *ifp; sc = malloc(sizeof(*sc), M_VROUTER, M_WAITOK|M_ZERO); ifp = if_alloc(IFT_ETHER); if (!ifp) return (ENOSPC); /* Set up private data */ ifp->if_softc = sc; sc->vp_ifp = ifp; mtx_init(&sc->vp_mtx, "vhost_mtx", NULL, MTX_DEF); /* Set up interface */ if_initname(ifp, name, IF_DUNIT_NONE); ifp->if_init = vhost_if_init; ifp->if_start = vhost_if_start; ifp->if_ioctl = vhost_if_ioctl; ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST); ether_ifattach(ifp, vhost_mac); ifp->if_capabilities = ifp->if_capenable = 0; return (0); }
static int pflog_clone_create(struct if_clone *ifc, int unit, caddr_t param) { struct ifnet *ifp; if (unit >= PFLOGIFS_MAX) return (EINVAL); ifp = if_alloc(IFT_PFLOG); if (ifp == NULL) { return (ENOSPC); } if_initname(ifp, pflogname, unit); ifp->if_mtu = PFLOGMTU; ifp->if_ioctl = pflogioctl; ifp->if_output = pflogoutput; ifp->if_start = pflogstart; ifp->if_snd.ifq_maxlen = ifqmaxlen; ifp->if_hdrlen = PFLOG_HDRLEN; if_attach(ifp); bpfattach(ifp, DLT_PFLOG, PFLOG_HDRLEN); pflogifs[unit] = ifp; return (0); }
static int ipfwlog_clone_create(struct if_clone *ifc, int unit, caddr_t params) { struct ifnet *ifp; ifp = if_alloc(IFT_PFLOG); if (ifp == NULL) return (ENOSPC); if_initname(ifp, ipfwlogname, unit); ifp->if_flags = IFF_UP | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_mtu = 65536; ifp->if_ioctl = ipfw_bpf_ioctl; ifp->if_output = ipfw_bpf_output; ifp->if_hdrlen = PFLOG_HDRLEN; if_attach(ifp); bpfattach(ifp, DLT_PFLOG, PFLOG_HDRLEN); LOGIF_WLOCK(); if (V_pflog_if != NULL) { LOGIF_WUNLOCK(); bpfdetach(ifp); if_detach(ifp); if_free(ifp); return (EEXIST); } V_pflog_if = ifp; LOGIF_WUNLOCK(); return (0); }
static int lo_clone_create(struct if_clone *ifc, int unit, caddr_t params) { struct ifnet *ifp; ifp = if_alloc(IFT_LOOP); if (ifp == NULL) return (ENOSPC); if_initname(ifp, loname, unit); ifp->if_mtu = LOMTU; ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST; ifp->if_ioctl = loioctl; ifp->if_output = looutput; ifp->if_snd.ifq_maxlen = ifqmaxlen; ifp->if_capabilities = ifp->if_capenable = IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6; ifp->if_hwassist = LO_CSUM_FEATURES | LO_CSUM_FEATURES6; if_attach(ifp); bpfattach(ifp, DLT_NULL, sizeof(u_int32_t)); if (V_loif == NULL) V_loif = ifp; return (0); }
static int gif_clone_create(struct if_clone *ifc, int unit, caddr_t params) { struct gif_softc *sc; sc = malloc(sizeof(struct gif_softc), M_GIF, M_WAITOK | M_ZERO); sc->gif_fibnum = curthread->td_proc->p_fibnum; GIF2IFP(sc) = if_alloc(IFT_GIF); GIF_LOCK_INIT(sc); GIF2IFP(sc)->if_softc = sc; if_initname(GIF2IFP(sc), gifname, unit); GIF2IFP(sc)->if_addrlen = 0; GIF2IFP(sc)->if_mtu = GIF_MTU; GIF2IFP(sc)->if_flags = IFF_POINTOPOINT | IFF_MULTICAST; #if 0 /* turn off ingress filter */ GIF2IFP(sc)->if_flags |= IFF_LINK2; #endif GIF2IFP(sc)->if_ioctl = gif_ioctl; GIF2IFP(sc)->if_transmit = gif_transmit; GIF2IFP(sc)->if_qflush = gif_qflush; GIF2IFP(sc)->if_output = gif_output; if_attach(GIF2IFP(sc)); bpfattach(GIF2IFP(sc), DLT_NULL, sizeof(u_int32_t)); if (ng_gif_attach_p != NULL) (*ng_gif_attach_p)(GIF2IFP(sc)); GIF_LIST_LOCK(); LIST_INSERT_HEAD(&V_gif_softc_list, sc, gif_list); GIF_LIST_UNLOCK(); return (0); }
/* * Called from boot code to establish ppp interfaces. */ static void pppattach(void *dummy) { struct ppp_softc *sc; int i = 0; for (sc = ppp_softc; i < NPPP; sc++) { if_initname(&(sc->sc_if), "ppp", i++); sc->sc_if.if_softc = sc; sc->sc_if.if_mtu = PPP_MTU; sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; sc->sc_if.if_type = IFT_PPP; sc->sc_if.if_hdrlen = PPP_HDRLEN; sc->sc_if.if_ioctl = pppsioctl; sc->sc_if.if_output = pppoutput; sc->sc_if.if_start = ppp_ifstart; ifq_set_maxlen(&sc->sc_if.if_snd, IFQ_MAXLEN); ifq_set_ready(&sc->sc_if.if_snd); sc->sc_inq.ifq_maxlen = IFQ_MAXLEN; sc->sc_fastq.ifq_maxlen = IFQ_MAXLEN; sc->sc_rawq.ifq_maxlen = IFQ_MAXLEN; callout_init(&sc->sc_timeout); if_attach(&sc->sc_if, NULL); bpfattach(&sc->sc_if, DLT_PPP, PPP_HDRLEN); } netisr_register(NETISR_PPP, pppintr, NULL); /* * XXX layering violation - if_ppp can work over any lower level * transport that cares to attach to it. */ pppasyncattach(dummy); }
static int pflog_clone_create(struct if_clone *ifc, int unit) { struct pflog_softc *sc; MALLOC(sc, struct pflog_softc *, sizeof(*sc), M_PFLOG, M_WAITOK|M_ZERO); if_initname(&sc->sc_if, ifc->ifc_name, unit); sc->sc_if.if_mtu = PFLOGMTU; sc->sc_if.if_ioctl = pflogioctl; sc->sc_if.if_output = pflogoutput; sc->sc_if.if_start = pflogstart; sc->sc_if.if_type = IFT_PFLOG; sc->sc_if.if_snd.ifq_maxlen = ifqmaxlen; sc->sc_if.if_hdrlen = PFLOG_HDRLEN; sc->sc_if.if_softc = sc; if_attach(&sc->sc_if); LIST_INSERT_HEAD(&pflog_list, sc, sc_next); #if NBPFILTER > 0 bpfattach(&sc->sc_if, DLT_PFLOG, PFLOG_HDRLEN); #endif return (0); }
static int gre_clone_create(struct if_clone *ifc, int unit, caddr_t param __unused) { struct gre_softc *sc; sc = kmalloc(sizeof(struct gre_softc), M_GRE, M_WAITOK); memset(sc, 0, sizeof(struct gre_softc)); sc->sc_if.if_softc = sc; if_initname(&(sc->sc_if), GRENAME, unit); ifq_set_maxlen(&sc->sc_if.if_snd, IFQ_MAXLEN); sc->sc_if.if_type = IFT_OTHER; sc->sc_if.if_addrlen = 0; sc->sc_if.if_hdrlen = 24; /* IP + GRE */ sc->sc_if.if_mtu = GREMTU; sc->sc_if.if_flags = IFF_POINTOPOINT|IFF_MULTICAST; sc->sc_if.if_output = gre_output; sc->sc_if.if_ioctl = gre_ioctl; sc->g_dst.s_addr = sc->g_src.s_addr = INADDR_ANY; sc->g_proto = IPPROTO_GRE; sc->sc_if.if_flags |= IFF_LINK0; sc->encap = NULL; sc->called = 0; sc->route_pcpu = kmalloc(netisr_ncpus * sizeof(struct route), M_GRE, M_WAITOK | M_ZERO); if_attach(&sc->sc_if, NULL); bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int32_t)); LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list); return (0); }
/* * icattach() */ static int icattach(device_t dev) { struct ic_softc *sc = (struct ic_softc *)device_get_softc(dev); struct ifnet *ifp; ifp = sc->ic_ifp = if_alloc(IFT_PARA); if (ifp == NULL) return (ENOSPC); mtx_init(&sc->ic_lock, device_get_nameunit(dev), MTX_NETWORK_LOCK, MTX_DEF); sc->ic_addr = PCF_MASTER_ADDRESS; /* XXX only PCF masters */ sc->ic_dev = dev; ifp->if_softc = sc; if_initname(ifp, device_get_name(dev), device_get_unit(dev)); ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST; ifp->if_ioctl = icioctl; ifp->if_output = icoutput; ifp->if_hdrlen = 0; ifp->if_addrlen = 0; ifp->if_snd.ifq_maxlen = ifqmaxlen; ic_alloc_buffers(sc, ICMTU); if_attach(ifp); bpfattach(ifp, DLT_NULL, ICHDRLEN); return (0); }
static int disc_clone_create(struct if_clone *ifc, int unit) { struct ifnet *ifp; struct disc_softc *sc; sc = malloc(sizeof(struct disc_softc), M_DISC, M_WAITOK | M_ZERO); ifp = &sc->sc_if; ifp->if_softc = sc; if_initname(ifp, ifc->ifc_name, unit); ifp->if_mtu = DSMTU; ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST; ifp->if_ioctl = discioctl; ifp->if_output = discoutput; ifp->if_type = IFT_LOOP; ifp->if_hdrlen = 0; ifp->if_addrlen = 0; ifp->if_snd.ifq_maxlen = 20; if_attach(ifp); bpfattach(ifp, DLT_NULL, sizeof(u_int)); mtx_lock(&disc_mtx); LIST_INSERT_HEAD(&disc_softc_list, sc, sc_list); mtx_unlock(&disc_mtx); return (0); }
static void tuncreate(struct cdev *dev) { struct tun_softc *sc; struct ifnet *ifp; dev->si_flags &= ~SI_CHEAPCLONE; MALLOC(sc, struct tun_softc *, sizeof(*sc), M_TUN, M_WAITOK | M_ZERO); mtx_init(&sc->tun_mtx, "tun_mtx", NULL, MTX_DEF); sc->tun_flags = TUN_INITED; sc->tun_dev = dev; mtx_lock(&tunmtx); TAILQ_INSERT_TAIL(&tunhead, sc, tun_list); mtx_unlock(&tunmtx); ifp = &sc->tun_if; if_initname(ifp, TUNNAME, dev2unit(dev)); ifp->if_mtu = TUNMTU; ifp->if_ioctl = tunifioctl; ifp->if_output = tunoutput; ifp->if_start = tunstart; ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST; ifp->if_type = IFT_PPP; ifp->if_softc = sc; IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); ifp->if_snd.ifq_drv_maxlen = 0; IFQ_SET_READY(&ifp->if_snd); if_attach(ifp); bpfattach(ifp, DLT_NULL, sizeof(u_int)); dev->si_drv1 = sc; }
void usbpf_attach(struct usb_bus *ubus) { struct ifnet *ifp; if (usb_no_pf != 0) { ubus->ifp = NULL; return; } ifp = ubus->ifp = if_alloc(IFT_USB); if (ifp == NULL) { device_printf(ubus->parent, "usbpf: Could not allocate " "instance\n"); return; } if_initname(ifp, "usbus", device_get_unit(ubus->bdev)); ifp->if_flags = IFF_CANTCONFIG; if_attach(ifp); if_up(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); if (bootverbose) device_printf(ubus->parent, "usbpf: Attached\n"); }
/* * icattach() */ static int icattach(device_t dev) { struct ic_softc *sc = (struct ic_softc *)device_get_softc(dev); struct ifnet *ifp = &sc->ic_if; sc->ic_addr = PCF_MASTER_ADDRESS; /* XXX only PCF masters */ ifp->if_softc = sc; if_initname(ifp, "ic", device_get_unit(dev)); ifp->if_mtu = ICMTU; ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST; ifp->if_ioctl = icioctl; ifp->if_output = icoutput; ifp->if_type = IFT_PARA; ifp->if_hdrlen = 0; ifp->if_addrlen = 0; ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); if_attach(ifp, NULL); bpfattach(ifp, DLT_NULL, ICHDRLEN); return (0); }
void ipfw_log_bpf(int onoff) { struct ifnet *ifp; if (onoff) { if (log_if) return; ifp = if_alloc(IFT_ETHER); if (ifp == NULL) return; if_initname(ifp, "ipfw", 0); 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 = (void *)log_dummy; ifp->if_output = (void *)log_dummy; ifp->if_addrlen = 6; ifp->if_hdrlen = 14; if_attach(ifp); ifp->if_baudrate = IF_Mbps(10); bpfattach(ifp, DLT_EN10MB, 14); log_if = ifp; } else { if (log_if) { ether_ifdetach(log_if); if_free(log_if); } log_if = NULL; } }
static int enc_clone_create(struct if_clone *ifc, int unit, caddr_t params) { struct ifnet *ifp; struct enc_softc *sc; sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO); ifp = sc->sc_ifp = if_alloc(IFT_ENC); if (ifp == NULL) { free(sc, M_DEVBUF); return (ENOSPC); } if_initname(ifp, ifc->ifc_name, unit); ifp->if_mtu = ENCMTU; ifp->if_ioctl = enc_ioctl; ifp->if_output = enc_output; ifp->if_snd.ifq_maxlen = ifqmaxlen; ifp->if_softc = sc; if_attach(ifp); bpfattach(ifp, DLT_ENC, sizeof(struct enchdr)); mtx_lock(&enc_mtx); /* grab a pointer to enc0, ignore the rest */ if (encif == NULL) encif = ifp; mtx_unlock(&enc_mtx); return (0); }
static int gif_clone_create(struct if_clone *ifc, int unit, caddr_t params) { struct gif_softc *sc; sc = malloc(sizeof(struct gif_softc), M_GIF, M_WAITOK | M_ZERO); sc->gif_fibnum = curthread->td_proc->p_fibnum; GIF2IFP(sc) = if_alloc(IFT_GIF); GIF2IFP(sc)->if_softc = sc; if_initname(GIF2IFP(sc), gifname, unit); GIF2IFP(sc)->if_addrlen = 0; GIF2IFP(sc)->if_mtu = GIF_MTU; GIF2IFP(sc)->if_flags = IFF_POINTOPOINT | IFF_MULTICAST; GIF2IFP(sc)->if_ioctl = gif_ioctl; GIF2IFP(sc)->if_transmit = gif_transmit; GIF2IFP(sc)->if_qflush = gif_qflush; GIF2IFP(sc)->if_output = gif_output; GIF2IFP(sc)->if_capabilities |= IFCAP_LINKSTATE; GIF2IFP(sc)->if_capenable |= IFCAP_LINKSTATE; if_attach(GIF2IFP(sc)); bpfattach(GIF2IFP(sc), DLT_NULL, sizeof(u_int32_t)); if (ng_gif_attach_p != NULL) (*ng_gif_attach_p)(GIF2IFP(sc)); return (0); }
static int uhso_attach_ifnet(struct uhso_softc *sc, struct usb_interface *iface, int type) { struct ifnet *ifp; usb_error_t uerr; struct sysctl_ctx_list *sctx; struct sysctl_oid *soid; unsigned int devunit; uerr = usbd_transfer_setup(sc->sc_udev, &iface->idesc->bInterfaceNumber, sc->sc_if_xfer, uhso_ifnet_config, UHSO_IFNET_MAX, sc, &sc->sc_mtx); if (uerr) { UHSO_DPRINTF(0, "usbd_transfer_setup failed: %s\n", usbd_errstr(uerr)); return (-1); } sc->sc_ifp = ifp = if_alloc(IFT_OTHER); if (sc->sc_ifp == NULL) { device_printf(sc->sc_dev, "if_alloc() failed\n"); return (-1); } callout_init_mtx(&sc->sc_c, &sc->sc_mtx, 0); mtx_lock(&sc->sc_mtx); callout_reset(&sc->sc_c, 1, uhso_if_rxflush, sc); mtx_unlock(&sc->sc_mtx); /* * We create our own unit numbers for ifnet devices because the * USB interface unit numbers can be at arbitrary positions yielding * odd looking device names. */ devunit = alloc_unr(uhso_ifnet_unit); if_initname(ifp, device_get_name(sc->sc_dev), devunit); ifp->if_mtu = UHSO_MAX_MTU; ifp->if_ioctl = uhso_if_ioctl; ifp->if_init = uhso_if_init; ifp->if_start = uhso_if_start; ifp->if_output = uhso_if_output; ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_NOARP; ifp->if_softc = sc; IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; IFQ_SET_READY(&ifp->if_snd); if_attach(ifp); bpfattach(ifp, DLT_RAW, 0); sctx = device_get_sysctl_ctx(sc->sc_dev); soid = device_get_sysctl_tree(sc->sc_dev); /* Unlocked read... */ SYSCTL_ADD_STRING(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "netif", CTLFLAG_RD, ifp->if_xname, 0, "Attached network interface"); return (0); }
static int fwip_attach(device_t dev) { struct fwip_softc *fwip; struct ifnet *ifp; int unit, s; struct fw_hwaddr *hwaddr; fwip = ((struct fwip_softc *)device_get_softc(dev)); unit = device_get_unit(dev); ifp = fwip->fw_softc.fwip_ifp = if_alloc(IFT_IEEE1394); if (ifp == NULL) return (ENOSPC); mtx_init(&fwip->mtx, "fwip", NULL, MTX_DEF); /* XXX */ fwip->dma_ch = -1; fwip->fd.fc = device_get_ivars(dev); if (tx_speed < 0) tx_speed = fwip->fd.fc->speed; fwip->fd.dev = dev; fwip->fd.post_explore = NULL; fwip->fd.post_busreset = fwip_post_busreset; fwip->fw_softc.fwip = fwip; TASK_INIT(&fwip->start_send, 0, fwip_start_send, fwip); /* * Encode our hardware the way that arp likes it. */ hwaddr = &IFP2FWC(fwip->fw_softc.fwip_ifp)->fc_hwaddr; hwaddr->sender_unique_ID_hi = htonl(fwip->fd.fc->eui.hi); hwaddr->sender_unique_ID_lo = htonl(fwip->fd.fc->eui.lo); hwaddr->sender_max_rec = fwip->fd.fc->maxrec; hwaddr->sspd = fwip->fd.fc->speed; hwaddr->sender_unicast_FIFO_hi = htons((uint16_t)(INET_FIFO >> 32)); hwaddr->sender_unicast_FIFO_lo = htonl((uint32_t)INET_FIFO); /* fill the rest and attach interface */ ifp->if_softc = &fwip->fw_softc; if_initname(ifp, device_get_name(dev), unit); ifp->if_init = fwip_init; ifp->if_start = fwip_start; ifp->if_ioctl = fwip_ioctl; ifp->if_flags = (IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST); ifp->if_snd.ifq_maxlen = TX_MAX_QUEUE; #ifdef DEVICE_POLLING ifp->if_capabilities |= IFCAP_POLLING; #endif s = splimp(); firewire_ifattach(ifp, hwaddr); splx(s); FWIPDEBUG(ifp, "interface created\n"); return 0; }
static int ff_veth_setup_interface(struct ff_veth_softc *sc, struct ff_port_cfg *cfg) { struct ifnet *ifp; ifp = sc->ifp = if_alloc(IFT_ETHER); ifp->if_init = ff_veth_init; ifp->if_softc = sc; if_initname(ifp, sc->host_ifname, IF_DUNIT_NONE); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = ff_veth_ioctl; ifp->if_start = ff_veth_start; ifp->if_transmit = ff_veth_transmit; ifp->if_qflush = ff_veth_qflush; ether_ifattach(ifp, sc->mac); if (cfg->hw_features.rx_csum) { ifp->if_capabilities |= IFCAP_RXCSUM; } if (cfg->hw_features.tx_csum_ip) { ifp->if_capabilities |= IFCAP_TXCSUM; ifp->if_hwassist |= CSUM_IP; } if (cfg->hw_features.tx_csum_l4) { ifp->if_hwassist |= CSUM_DELAY_DATA; } if (cfg->hw_features.tx_tso) { ifp->if_capabilities |= IFCAP_TSO; ifp->if_hwassist |= CSUM_TSO; } ifp->if_capenable = ifp->if_capabilities; sc->host_ctx = ff_dpdk_register_if((void *)sc, (void *)sc->ifp, cfg); if (sc->host_ctx == NULL) { printf("%s: Failed to register dpdk interface\n", sc->host_ifname); return -1; } //set ip int ret = ff_veth_setaddr(sc); if (ret != 0) { printf("ff_veth_setaddr failed\n"); } ret = ff_veth_set_gateway(sc); if (ret != 0) { printf("ff_veth_set_gateway failed\n"); } return (0); }
static int nicvf_setup_ifnet(struct nicvf *nic) { struct ifnet *ifp; ifp = if_alloc(IFT_ETHER); if (ifp == NULL) { device_printf(nic->dev, "Could not allocate ifnet structure\n"); return (ENOMEM); } nic->ifp = ifp; if_setsoftc(ifp, nic); if_initname(ifp, device_get_name(nic->dev), device_get_unit(nic->dev)); if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX); if_settransmitfn(ifp, nicvf_if_transmit); if_setqflushfn(ifp, nicvf_if_qflush); if_setioctlfn(ifp, nicvf_if_ioctl); if_setinitfn(ifp, nicvf_if_init); if_setgetcounterfn(ifp, nicvf_if_getcounter); if_setmtu(ifp, ETHERMTU); /* Reset caps */ if_setcapabilities(ifp, 0); /* Set the default values */ if_setcapabilitiesbit(ifp, IFCAP_VLAN_MTU | IFCAP_JUMBO_MTU, 0); if_setcapabilitiesbit(ifp, IFCAP_LRO, 0); if (nic->hw_tso) { /* TSO */ if_setcapabilitiesbit(ifp, IFCAP_TSO4, 0); /* TSO parameters */ if_sethwtsomax(ifp, NICVF_TSO_MAXSIZE); if_sethwtsomaxsegcount(ifp, NICVF_TSO_NSEGS); if_sethwtsomaxsegsize(ifp, MCLBYTES); } /* IP/TCP/UDP HW checksums */ if_setcapabilitiesbit(ifp, IFCAP_HWCSUM, 0); if_setcapabilitiesbit(ifp, IFCAP_HWSTATS, 0); /* * HW offload enable */ if_clearhwassist(ifp); if_sethwassistbits(ifp, (CSUM_IP | CSUM_TCP | CSUM_UDP | CSUM_SCTP), 0); if (nic->hw_tso) if_sethwassistbits(ifp, (CSUM_TSO), 0); if_setcapenable(ifp, if_getcapabilities(ifp)); return (0); }
static int ntb_setup_interface(void) { struct ifnet *ifp; struct ntb_queue_handlers handlers = { ntb_net_rx_handler, ntb_net_tx_handler, ntb_net_event_handler }; int rc; net_softc.ntb = devclass_get_softc(devclass_find("ntb_hw"), 0); if (net_softc.ntb == NULL) { printf("ntb: Cannot find devclass\n"); return (ENXIO); } ifp = net_softc.ifp = if_alloc(IFT_ETHER); if (ifp == NULL) { ntb_transport_free(&net_softc); printf("ntb: Cannot allocate ifnet structure\n"); return (ENOMEM); } if_initname(ifp, "ntb", 0); rc = ntb_transport_probe(net_softc.ntb); if (rc != 0) { printf("ntb: Cannot init transport: %d\n", rc); if_free(net_softc.ifp); return (rc); } net_softc.qp = ntb_transport_create_queue(ifp, net_softc.ntb, &handlers); ifp->if_init = ntb_net_init; ifp->if_softc = &net_softc; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; ifp->if_ioctl = ntb_ioctl; ifp->if_start = ntb_start; IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN; IFQ_SET_READY(&ifp->if_snd); create_random_local_eui48(net_softc.eaddr); ether_ifattach(ifp, net_softc.eaddr); ifp->if_capabilities = IFCAP_HWCSUM | IFCAP_JUMBO_MTU; ifp->if_capenable = ifp->if_capabilities; ifp->if_mtu = ntb_transport_max_size(net_softc.qp) - ETHER_HDR_LEN - ETHER_CRC_LEN; ntb_transport_link_up(net_softc.qp); net_softc.bufsize = ntb_transport_max_size(net_softc.qp) + sizeof(struct ether_header); return (0); }
static int gif_clone_create(struct if_clone *ifc, int unit) { struct gif_softc *sc; sc = malloc(sizeof(struct gif_softc), M_DEVBUF, M_WAITOK|M_ZERO); if_initname(&sc->gif_if, ifc->ifc_name, unit); gifattach0(sc); LIST_INSERT_HEAD(&gif_softc_list, sc, gif_list); return (0); }
static int if_netmap_setup_interface(struct if_netmap_softc *sc) { struct ifnet *ifp; ifp = sc->ifp = if_alloc(IFT_ETHER); ifp->if_init = if_netmap_init; ifp->if_softc = sc; if_initname(ifp, sc->cfg->name, IF_DUNIT_NONE); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = if_netmap_ioctl; ifp->if_start = if_netmap_start; /* XXX what values? */ IFQ_SET_MAXLEN(&ifp->if_snd, if_netmap_txslots(sc->nm_host_ctx)); ifp->if_snd.ifq_drv_maxlen = if_netmap_txslots(sc->nm_host_ctx); IFQ_SET_READY(&ifp->if_snd); ifp->if_fib = sc->cfg->cdom; ether_ifattach(ifp, sc->addr); ifp->if_capabilities = ifp->if_capenable = IFCAP_HWSTATS; mtx_init(&sc->tx_lock, "txlk", NULL, MTX_DEF); cv_init(&sc->tx_cv, "txcv"); if (kthread_add(if_netmap_send, sc, NULL, &sc->tx_thread.thr, 0, 0, "nm_tx: %s", ifp->if_xname)) { printf("Could not start transmit thread for %s (%s)\n", ifp->if_xname, sc->host_ifname); ether_ifdetach(ifp); if_free(ifp); return (1); } if (kthread_add(if_netmap_receive, sc, NULL, &sc->rx_thread.thr, 0, 0, "nm_rx: %s", ifp->if_xname)) { printf("Could not start receive thread for %s (%s)\n", ifp->if_xname, sc->host_ifname); ether_ifdetach(ifp); if_free(ifp); return (1); } return (0); }
/* ARGSUSED */ static void discattach(void) { struct ifnet *ifp = &discif; if_initname(ifp, "ds", IF_DUNIT_NONE); ifp->if_mtu = DSMTU; ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST; ifp->if_ioctl = discioctl; ifp->if_output = discoutput; ifp->if_type = IFT_LOOP; ifp->if_hdrlen = 0; ifp->if_addrlen = 0; ifp->if_snd.ifq_maxlen = 20; if_attach(ifp, NULL); bpfattach(ifp, DLT_NULL, sizeof(u_int)); }
int ep_alloc(device_t dev) { struct ep_softc * sc = device_get_softc(dev); int rid; int error = 0; rid = 0; sc->iobase = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); if (!sc->iobase) { device_printf(dev, "No I/O space?!\n"); error = ENXIO; goto bad; } rid = 0; sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); if (!sc->irq) { device_printf(dev, "No irq?!\n"); error = ENXIO; goto bad; } if_initname(&sc->arpcom.ac_if, device_get_name(dev), device_get_unit(dev)); sc->stat = 0; /* 16 bit access */ sc->ep_io_addr = rman_get_start(sc->iobase); sc->ep_btag = rman_get_bustag(sc->iobase); sc->ep_bhandle = rman_get_bushandle(sc->iobase); sc->ep_connectors = 0; sc->ep_connector = 0; GO_WINDOW(0); sc->epb.cmd_off = 0; sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID); sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG); bad: return (error); }
int pdq_ifattach(pdq_softc_t *sc, const pdq_uint8_t *llc, pdq_type_t type) { struct ifnet *ifp; ifp = PDQ_IFNET(sc) = if_alloc(IFT_FDDI); if (ifp == NULL) { device_printf(sc->dev, "can not if_alloc()\n"); return (ENOSPC); } mtx_init(&sc->mtx, device_get_nameunit(sc->dev), MTX_NETWORK_LOCK, MTX_DEF); callout_init_mtx(&sc->watchdog, &sc->mtx, 0); if_initname(ifp, device_get_name(sc->dev), device_get_unit(sc->dev)); ifp->if_softc = sc; ifp->if_init = pdq_ifinit; ifp->if_snd.ifq_maxlen = ifqmaxlen; ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST; ifp->if_ioctl = pdq_ifioctl; ifp->if_start = pdq_ifstart; #if defined(IFM_FDDI) { const int media = sc->sc_ifmedia.ifm_media; ifmedia_init(&sc->sc_ifmedia, IFM_FDX, pdq_ifmedia_change, pdq_ifmedia_status); ifmedia_add(&sc->sc_ifmedia, media, 0, 0); ifmedia_set(&sc->sc_ifmedia, media); } #endif sc->sc_pdq = pdq_initialize(sc->mem_bst, sc->mem_bsh, ifp->if_xname, -1, sc, type); if (sc->sc_pdq == NULL) { device_printf(sc->dev, "Initialization failed.\n"); return (ENXIO); } fddi_ifattach(ifp, llc, FDDI_BPF_SUPPORTED); return (0); }