diff options
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/bpf.c | 7 | ||||
-rw-r--r-- | sys/net/bridge.c | 38 | ||||
-rw-r--r-- | sys/net/if.c | 50 | ||||
-rw-r--r-- | sys/net/if.h | 2 | ||||
-rw-r--r-- | sys/net/if_arcsubr.c | 8 | ||||
-rw-r--r-- | sys/net/if_atmsubr.c | 6 | ||||
-rw-r--r-- | sys/net/if_disc.c | 3 | ||||
-rw-r--r-- | sys/net/if_ef.c | 26 | ||||
-rw-r--r-- | sys/net/if_ethersubr.c | 5 | ||||
-rw-r--r-- | sys/net/if_faith.c | 3 | ||||
-rw-r--r-- | sys/net/if_gif.c | 3 | ||||
-rw-r--r-- | sys/net/if_gre.c | 3 | ||||
-rw-r--r-- | sys/net/if_loop.c | 3 | ||||
-rw-r--r-- | sys/net/if_media.c | 4 | ||||
-rw-r--r-- | sys/net/if_mib.c | 11 | ||||
-rw-r--r-- | sys/net/if_ppp.c | 11 | ||||
-rw-r--r-- | sys/net/if_sl.c | 13 | ||||
-rw-r--r-- | sys/net/if_spppsubr.c | 2 | ||||
-rw-r--r-- | sys/net/if_stf.c | 3 | ||||
-rw-r--r-- | sys/net/if_tap.c | 71 | ||||
-rw-r--r-- | sys/net/if_tun.c | 11 | ||||
-rw-r--r-- | sys/net/if_var.h | 8 | ||||
-rw-r--r-- | sys/net/if_vlan.c | 7 | ||||
-rw-r--r-- | sys/net/net_osdep.c | 12 | ||||
-rw-r--r-- | sys/net/net_osdep.h | 2 | ||||
-rw-r--r-- | sys/net/ppp_tty.c | 2 | ||||
-rw-r--r-- | sys/net/rtsock.c | 3 |
27 files changed, 149 insertions, 168 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 535d268..1dc40c1 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -785,8 +785,8 @@ bpfioctl(dev, cmd, addr, flags, td) struct ifnet *const ifp = d->bd_bif->bif_ifp; struct ifreq *const ifr = (struct ifreq *)addr; - snprintf(ifr->ifr_name, sizeof(ifr->ifr_name), - "%s%d", ifp->if_name, ifp->if_unit); + strlcpy(ifr->ifr_name, ifp->if_xname, + sizeof(ifr->ifr_name)); } break; @@ -1425,8 +1425,7 @@ bpfdetach(ifp) /* Interface wasn't attached */ if ((bp == NULL) || (bp->bif_ifp == NULL)) { mtx_unlock(&bpf_mtx); - printf("bpfdetach: %s%d was not attached\n", ifp->if_name, - ifp->if_unit); + printf("bpfdetach: %s was not attached\n", ifp->if_xname); return; } diff --git a/sys/net/bridge.c b/sys/net/bridge.c index 5864a6f..c34d6e2 100644 --- a/sys/net/bridge.c +++ b/sys/net/bridge.c @@ -390,8 +390,8 @@ bridge_off(void) if ( b->flags & IFF_BDG_PROMISC ) { ifpromisc(ifp, 0); b->flags &= ~(IFF_BDG_PROMISC|IFF_MUTE) ; - DPRINTF(("%s: %s%d promisc OFF if_flags 0x%x " - "bdg_flags 0x%x\n", __func__, ifp->if_name, ifp->if_unit, + DPRINTF(("%s: %s promisc OFF if_flags 0x%x " + "bdg_flags 0x%x\n", __func__, ifp->if_xname, ifp->if_flags, b->flags)); } b->flags &= ~(IFF_USED) ; @@ -433,12 +433,11 @@ bridge_on(void) if ( !(b->flags & IFF_BDG_PROMISC) ) { (void) ifpromisc(ifp, 1); b->flags |= IFF_BDG_PROMISC ; - DPRINTF(("%s: %s%d promisc ON if_flags 0x%x bdg_flags 0x%x\n", - __func__, ifp->if_name, ifp->if_unit, ifp->if_flags, b->flags)); + DPRINTF(("%s: %s promisc ON if_flags 0x%x bdg_flags 0x%x\n", + __func__, ifp->if_xname, ifp->if_flags, b->flags)); } if (b->flags & IFF_MUTE) { - DPRINTF(("%s: unmuting %s%d\n", __func__, - ifp->if_name, ifp->if_unit)); + DPRINTF(("%s: unmuting %s\n", __func__, ifp->if_xname)); b->flags &= ~IFF_MUTE; } } @@ -522,23 +521,22 @@ parse_bdg_cfg(void) */ IFNET_RLOCK(); /* could sleep XXX */ TAILQ_FOREACH(ifp, &ifnet, if_link) { - char buf[IFNAMSIZ]; - snprintf(buf, sizeof(buf), "%s%d", ifp->if_name, ifp->if_unit); - if (!strncmp(beg, buf, max(l, strlen(buf)))) { + if (!strncmp(beg, ifp->if_xname, max(l, strlen(ifp->if_xname)))) { struct bdg_softc *b = &ifp2sc[ifp->if_index]; if (ifp->if_type != IFT_ETHER && ifp->if_type != IFT_L2VLAN) { - printf("%s is not an ethernet, continue\n", buf); + printf("%s is not an ethernet, continue\n", ifp->if_xname); continue; } if (b->flags & IFF_USED) { - printf("%s already used, skipping\n", buf); + printf("%s already used, skipping\n", ifp->if_xname); break; } b->cluster = add_cluster(htons(cluster), (struct arpcom *)ifp); b->flags |= IFF_USED ; - sprintf(bdg_stats.s[ifp->if_index].name, - "%s%d:%d", ifp->if_name, ifp->if_unit, cluster); + snprintf(bdg_stats.s[ifp->if_index].name, + sizeof(bdg_stats.s[ifp->if_index].name), + "%s:%d", ifp->if_xname, cluster); DPRINTF(("%s: found %s next c %d\n", __func__, bdg_stats.s[ifp->if_index].name, c)); @@ -793,10 +791,9 @@ bridge_in(struct ifnet *ifp, struct ether_header *eh) * from the old interface. */ bt->name = ifp; /* relocate address */ - printf("-- loop (%d) %6D to %s%d from %s%d (%s)\n", + printf("-- loop (%d) %6D to %s from %s (%s)\n", bdg_loops, eh->ether_shost, ".", - ifp->if_name, ifp->if_unit, - old->if_name, old->if_unit, + ifp->if_xname, old->if_xname, BDG_MUTED(old) ? "muted":"active"); dropit = 1; if (!BDG_MUTED(old)) { @@ -810,8 +807,8 @@ bridge_in(struct ifnet *ifp, struct ether_header *eh) * now write the source address into the table */ if (bt->name == NULL) { - DPRINTF(("%s: new addr %6D at %d for %s%d\n", - __func__, eh->ether_shost, ".", index, ifp->if_name, ifp->if_unit)); + DPRINTF(("%s: new addr %6D at %d for %s\n", + __func__, eh->ether_shost, ".", index, ifp->if_xname)); ETHER_ADDR_COPY(bt->etheraddr, eh->ether_shost); bt->name = ifp; } @@ -853,13 +850,12 @@ bridge_in(struct ifnet *ifp, struct ether_header *eh) if (dst == ifp) dst = BDG_DROP; } - DPRINTF(("%s: %6D ->%6D ty 0x%04x dst %s%d\n", __func__, + DPRINTF(("%s: %6D ->%6D ty 0x%04x dst %s\n", __func__, eh->ether_shost, ".", eh->ether_dhost, ".", ntohs(eh->ether_type), (dst <= BDG_FORWARD) ? bdg_dst_names[(uintptr_t)dst] : - dst->if_name, - (dst <= BDG_FORWARD) ? 0 : dst->if_unit)); + dst->if_xname)); return dst; } diff --git a/sys/net/if.c b/sys/net/if.c index 97ea658..447e4a1 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -325,7 +325,7 @@ if_findindex(struct ifnet *ifp) eaddr[0] = '\0'; break; } - snprintf(devname, 32, "%s%d", ifp->if_name, ifp->if_unit); + strlcpy(devname, ifp->if_xname, sizeof(devname)); name = net_cdevsw.d_name; i = 0; while ((resource_find_dev(&i, name, &unit, NULL, NULL)) == 0) { @@ -364,7 +364,6 @@ if_attach(struct ifnet *ifp) { unsigned socksize, ifasize; int namelen, masklen; - char workbuf[64]; struct sockaddr_dl *sdl; struct ifaddr *ifa; @@ -399,18 +398,17 @@ if_attach(struct ifnet *ifp) ifnet_byindex(ifp->if_index) = ifp; ifdev_byindex(ifp->if_index) = make_dev(&net_cdevsw, ifp->if_index, - UID_ROOT, GID_WHEEL, 0600, "%s/%s%d", - net_cdevsw.d_name, ifp->if_name, ifp->if_unit); + UID_ROOT, GID_WHEEL, 0600, "%s/%s", + net_cdevsw.d_name, ifp->if_xname); make_dev_alias(ifdev_byindex(ifp->if_index), "%s%d", net_cdevsw.d_name, ifp->if_index); - mtx_init(&ifp->if_snd.ifq_mtx, ifp->if_name, "if send queue", MTX_DEF); + mtx_init(&ifp->if_snd.ifq_mtx, ifp->if_xname, "if send queue", MTX_DEF); /* * create a Link Level name for this device */ - namelen = snprintf(workbuf, sizeof(workbuf), - "%s%d", ifp->if_name, ifp->if_unit); + namelen = strlen(ifp->if_xname); #define _offsetof(t, m) ((int)((caddr_t)&((t *)0)->m)) masklen = _offsetof(struct sockaddr_dl, sdl_data[0]) + namelen; socksize = masklen + ifp->if_addrlen; @@ -425,7 +423,7 @@ if_attach(struct ifnet *ifp) sdl = (struct sockaddr_dl *)(ifa + 1); sdl->sdl_len = socksize; sdl->sdl_family = AF_LINK; - bcopy(workbuf, sdl->sdl_data, namelen); + bcopy(ifp->if_xname, sdl->sdl_data, namelen); sdl->sdl_nlen = namelen; sdl->sdl_index = ifp->if_index; sdl->sdl_type = ifp->if_type; @@ -881,8 +879,7 @@ if_clone_list(struct if_clonereq *ifcr) for (ifc = LIST_FIRST(&if_cloners); ifc != NULL && count != 0; ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) { - strncpy(outbuf, ifc->ifc_name, IFNAMSIZ); - outbuf[IFNAMSIZ - 1] = '\0'; /* sanity */ + strlcpy(outbuf, ifc->ifc_name, IFNAMSIZ); error = copyout(outbuf, dst, IFNAMSIZ); if (error) break; @@ -1643,8 +1640,8 @@ ifpromisc(struct ifnet *ifp, int pswitch) ifr.ifr_flagshigh = ifp->if_flags >> 16; error = (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr); if (error == 0) { - log(LOG_INFO, "%s%d: promiscuous mode %s\n", - ifp->if_name, ifp->if_unit, + log(LOG_INFO, "%s: promiscuous mode %s\n", + ifp->if_xname, (ifp->if_flags & IFF_PROMISC) ? "enabled" : "disabled"); rt_ifmsg(ifp); } else { @@ -1673,18 +1670,14 @@ ifconf(u_long cmd, caddr_t data) ifrp = ifc->ifc_req; IFNET_RLOCK(); /* could sleep XXX */ TAILQ_FOREACH(ifp, &ifnet, if_link) { - char workbuf[64]; - int ifnlen, addrs; + int addrs; if (space < sizeof(ifr)) break; - ifnlen = snprintf(workbuf, sizeof(workbuf), - "%s%d", ifp->if_name, ifp->if_unit); - if(ifnlen + 1 > sizeof ifr.ifr_name) { + if (strlcpy(ifr.ifr_name, ifp->if_xname, sizeof(ifr.ifr_name)) + >= sizeof(ifr.ifr_name)) { error = ENAMETOOLONG; break; - } else { - strcpy(ifr.ifr_name, workbuf); } addrs = 0; @@ -2019,13 +2012,30 @@ ifmaof_ifpforaddr(struct sockaddr *sa, struct ifnet *ifp) return ifma; } +/* + * The name argument must be a pointer to storage which will last as + * long as the interface does. For physical devices, the result of + * device_get_name(dev) is a good choice and for pseudo-devices a + * static string works well. + */ +void +if_initname(struct ifnet *ifp, const char *name, int unit) +{ + ifp->if_dname = name; + ifp->if_dunit = unit; + if (unit != IF_DUNIT_NONE) + snprintf(ifp->if_xname, IFNAMSIZ, "%s%d", name, unit); + else + strlcpy(ifp->if_xname, name, IFNAMSIZ); +} + int if_printf(struct ifnet *ifp, const char * fmt, ...) { va_list ap; int retval; - retval = printf("%s%d: ", ifp->if_name, ifp->if_unit); + retval = printf("%s: ", ifp->if_xname); va_start(ap, fmt); retval += vprintf(fmt, ap); va_end(ap); diff --git a/sys/net/if.h b/sys/net/if.h index 44531d2..3d21acb 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -62,7 +62,7 @@ struct ifnet; #define IF_NAMESIZE 16 #if __BSD_VISIBLE #define IFNAMSIZ IF_NAMESIZE -#define IF_MAXUNIT 0x7fff /* ifp->if_unit is only 15 bits */ +#define IF_MAXUNIT 0x7fff /* historical value */ #endif #ifdef _KERNEL diff --git a/sys/net/if_arcsubr.c b/sys/net/if_arcsubr.c index a2d8a4d..24c3a86 100644 --- a/sys/net/if_arcsubr.c +++ b/sys/net/if_arcsubr.c @@ -474,8 +474,8 @@ outofseq: if (m) m_freem(m); - log(LOG_INFO,"%s%d: got out of seq. packet: %s\n", - ifp->if_name, ifp->if_unit, s); + log(LOG_INFO,"%s: got out of seq. packet: %s\n", + ifp->if_xname, s); return NULL; } @@ -648,8 +648,8 @@ arc_ifattach(ifp, lla) ac->ac_seqid = (time_second) & 0xFFFF; /* try to make seqid unique */ if (lla == 0) { /* XXX this message isn't entirely clear, to me -- cgd */ - log(LOG_ERR,"%s%d: link address 0 reserved for broadcasts. Please change it and ifconfig %s%d down up\n", - ifp->if_name, ifp->if_unit, ifp->if_name, ifp->if_unit); + log(LOG_ERR,"%s: link address 0 reserved for broadcasts. Please change it and ifconfig %s down up\n", + ifp->if_xname, ifp->if_xname); } arc_storelladdr(ifp, lla); diff --git a/sys/net/if_atmsubr.c b/sys/net/if_atmsubr.c index 02a463f..4c8856e 100644 --- a/sys/net/if_atmsubr.c +++ b/sys/net/if_atmsubr.c @@ -181,7 +181,8 @@ atm_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst, break; default: -#if defined(__NetBSD__) || defined(__OpenBSD__) +#if (defined(__FreeBSD__) && __FreeBSD_version >= 501113) || \ + defined(__NetBSD__) || defined(__OpenBSD__) printf("%s: can't handle af%d\n", ifp->if_xname, dst->sa_family); #elif defined(__FreeBSD__) || defined(__bsdi__) @@ -301,7 +302,8 @@ atm_input(struct ifnet *ifp, struct atm_pseudohdr *ah, struct mbuf *m, return; /* failed */ alc = mtod(m, struct atmllc *); if (bcmp(alc, ATMLLC_HDR, 6)) { -#if defined(__NetBSD__) || defined(__OpenBSD__) +#if (defined(__FreeBSD__) && __FreeBSD_version >= 501113) || \ + defined(__NetBSD__) || defined(__OpenBSD__) printf("%s: recv'd invalid LLC/SNAP frame " "[vp=%d,vc=%d]\n", ifp->if_xname, ATM_PH_VPI(ah), ATM_PH_VCI(ah)); diff --git a/sys/net/if_disc.c b/sys/net/if_disc.c index a392d5f..48935b3 100644 --- a/sys/net/if_disc.c +++ b/sys/net/if_disc.c @@ -93,8 +93,7 @@ disc_clone_create(struct if_clone *ifc, int unit) ifp = &sc->sc_if; ifp->if_softc = sc; - ifp->if_name = DISCNAME; - ifp->if_unit = unit; + if_initname(ifp, ifc->ifc_name, unit); ifp->if_mtu = DSMTU; ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST; ifp->if_ioctl = discioctl; diff --git a/sys/net/if_ef.c b/sys/net/if_ef.c index cb7bc64..8b5aee0 100644 --- a/sys/net/if_ef.c +++ b/sys/net/if_ef.c @@ -79,6 +79,7 @@ struct efnet { struct arpcom ef_ac; struct ifnet * ef_ifp; + int ef_frametype; }; struct ef_link { @@ -138,7 +139,7 @@ ef_attach(struct efnet *sc) bcopy(LLADDR(sdl2), sc->ef_ac.ac_enaddr, ETHER_ADDR_LEN); - EFDEBUG("%s%d: attached\n", ifp->if_name, ifp->if_unit); + EFDEBUG("%s: attached\n", ifp->if_xname); return 1; } @@ -178,11 +179,11 @@ ef_init(void *foo) { static int ef_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { -/* struct ef_link *sc = (struct ef_link*)ifp->if_softc;*/ + struct efnet *sc = ifp->if_softc; struct ifaddr *ifa = (struct ifaddr*)data; int s, error; - EFDEBUG("IOCTL %ld for %s%d\n", cmd, ifp->if_name, ifp->if_unit); + EFDEBUG("IOCTL %ld for %s\n", cmd, ifp->if_xname); error = 0; s = splimp(); switch (cmd) { @@ -190,7 +191,7 @@ ef_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) error = 0; break; case SIOCSIFADDR: - if (ifp->if_unit == ETHER_FT_8023 && + if (sc->ef_frametype == ETHER_FT_8023 && ifa->ifa_addr->sa_family != AF_IPX) { error = EAFNOSUPPORT; break; @@ -406,13 +407,14 @@ static int ef_output(struct ifnet *ifp, struct mbuf **mp, struct sockaddr *dst, short *tp, int *hlen) { + struct efnet *sc = (struct efnet*)ifp->if_softc; struct mbuf *m = *mp; u_char *cp; short type; if (ifp->if_type != IFT_XETHER) return ENETDOWN; - switch (ifp->if_unit) { + switch (sc->ef_frametype) { case ETHER_FT_EII: #ifdef IPX type = htons(ETHERTYPE_IPX); @@ -474,20 +476,18 @@ ef_clone(struct ef_link *efl, int ft) struct efnet *efp; struct ifnet *eifp; struct ifnet *ifp = efl->el_ifp; - char cbuf[IFNAMSIZ], *ifname; - int ifnlen; efp = (struct efnet*)malloc(sizeof(struct efnet), M_IFADDR, M_WAITOK | M_ZERO); if (efp == NULL) return ENOMEM; efp->ef_ifp = ifp; + efp->ef_frametype = ft; eifp = &efp->ef_ac.ac_if; - ifnlen = 1 + snprintf(cbuf, sizeof(cbuf), "%s%df", ifp->if_name, - ifp->if_unit); - ifname = (char*)malloc(ifnlen, M_IFADDR, M_WAITOK); - eifp->if_name = strcpy(ifname, cbuf); - eifp->if_unit = ft; + snprintf(eifp->if_xname, IFNAMSIZ, + "%sf%d", ifp->if_xname, efp->ef_frametype); + eifp->if_dname = "ef"; + eifp->if_dunit = IF_DUNIT_NONE; eifp->if_softc = efp; if (ifp->if_ioctl) eifp->if_ioctl = ef_ioctl; @@ -506,7 +506,7 @@ ef_load(void) IFNET_RLOCK(); TAILQ_FOREACH(ifp, &ifnet, if_link) { if (ifp->if_type != IFT_ETHER) continue; - EFDEBUG("Found interface %s%d\n", ifp->if_name, ifp->if_unit); + EFDEBUG("Found interface %s\n", ifp->if_xname); efl = (struct ef_link*)malloc(sizeof(struct ef_link), M_IFADDR, M_WAITOK | M_ZERO); if (efl == NULL) { diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 4e0e5cb..8ceb8e3 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -503,9 +503,8 @@ ether_input(struct ifnet *ifp, struct mbuf *m) } #ifdef DIAGNOSTIC if (m->m_pkthdr.rcvif != ifp) { - if_printf(ifp, "Warning, frame marked as received on %s%u\n", - m->m_pkthdr.rcvif->if_name, - m->m_pkthdr.rcvif->if_unit); + if_printf(ifp, "Warning, frame marked as received on %s\n", + m->m_pkthdr.rcvif->if_xname); } #endif diff --git a/sys/net/if_faith.c b/sys/net/if_faith.c index 8a9cb7c..07216b5 100644 --- a/sys/net/if_faith.c +++ b/sys/net/if_faith.c @@ -163,8 +163,7 @@ faith_clone_create(ifc, unit) bzero(sc, sizeof(struct faith_softc)); sc->sc_if.if_softc = sc; - sc->sc_if.if_name = FAITHNAME; - sc->sc_if.if_unit = unit; + if_initname(&sc->sc_if, ifc->ifc_name, unit); sc->sc_if.if_mtu = FAITHMTU; /* Change to BROADCAST experimentaly to announce its prefix. */ diff --git a/sys/net/if_gif.c b/sys/net/if_gif.c index ae761e8..d77a5a5 100644 --- a/sys/net/if_gif.c +++ b/sys/net/if_gif.c @@ -141,8 +141,7 @@ gif_clone_create(ifc, unit) bzero(sc, sizeof(struct gif_softc)); sc->gif_if.if_softc = sc; - sc->gif_if.if_name = GIFNAME; - sc->gif_if.if_unit = unit; + if_initname(&sc->gif_if, ifc->ifc_name, unit); gifattach0(sc); diff --git a/sys/net/if_gre.c b/sys/net/if_gre.c index bc8f1f7..3541410 100644 --- a/sys/net/if_gre.c +++ b/sys/net/if_gre.c @@ -162,9 +162,8 @@ gre_clone_create(ifc, unit) sc = malloc(sizeof(struct gre_softc), M_GRE, M_WAITOK); memset(sc, 0, sizeof(struct gre_softc)); - sc->sc_if.if_name = GRENAME; + if_initname(&sc->sc_if, ifc->ifc_name, unit); sc->sc_if.if_softc = sc; - sc->sc_if.if_unit = unit; sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN; sc->sc_if.if_type = IFT_OTHER; sc->sc_if.if_addrlen = 0; diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index b0ec6ea..357862d 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -144,8 +144,7 @@ lo_clone_create(ifc, unit) MALLOC(sc, struct lo_softc *, sizeof(*sc), M_LO, M_WAITOK | M_ZERO); - sc->sc_if.if_name = LONAME; - sc->sc_if.if_unit = unit; + if_initname(&sc->sc_if, ifc->ifc_name, unit); sc->sc_if.if_mtu = LOMTU; sc->sc_if.if_flags = IFF_LOOPBACK | IFF_MULTICAST; sc->sc_if.if_ioctl = loioctl; diff --git a/sys/net/if_media.c b/sys/net/if_media.c index a584419..5351157 100644 --- a/sys/net/if_media.c +++ b/sys/net/if_media.c @@ -246,8 +246,8 @@ ifmedia_ioctl(ifp, ifr, ifm, cmd) */ #ifdef IFMEDIA_DEBUG if (ifmedia_debug) { - printf("ifmedia_ioctl: switching %s%d to ", - ifp->if_name, ifp->if_unit); + printf("ifmedia_ioctl: switching %s to ", + ifp->if_xname); ifmedia_printword(match->ifm_media); } #endif diff --git a/sys/net/if_mib.c b/sys/net/if_mib.c index b8e7ed6..f104b77 100644 --- a/sys/net/if_mib.c +++ b/sys/net/if_mib.c @@ -71,10 +71,9 @@ static int sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */ { int *name = (int *)arg1; - int error, ifnlen; + int error; u_int namelen = arg2; struct ifnet *ifp; - char workbuf[64]; struct ifmibdata ifmd; if (namelen != 2) @@ -91,13 +90,7 @@ sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */ return ENOENT; case IFDATA_GENERAL: - ifnlen = snprintf(workbuf, sizeof(workbuf), - "%s%d", ifp->if_name, ifp->if_unit); - if(ifnlen + 1 > sizeof ifmd.ifmd_name) { - return ENAMETOOLONG; - } else { - strcpy(ifmd.ifmd_name, workbuf); - } + strlcpy(ifmd.ifmd_name, ifp->if_xname, sizeof(ifmd.ifmd_name)); #define COPY(fld) ifmd.ifmd_##fld = ifp->if_##fld COPY(pcount); diff --git a/sys/net/if_ppp.c b/sys/net/if_ppp.c index b3dfccb..9480d92 100644 --- a/sys/net/if_ppp.c +++ b/sys/net/if_ppp.c @@ -201,8 +201,7 @@ ppp_clone_create(struct if_clone *ifc, int unit) sc = malloc(sizeof(struct ppp_softc), M_PPP, M_WAITOK | M_ZERO); sc->sc_if.if_softc = sc; - sc->sc_if.if_name = PPPNAME; - sc->sc_if.if_unit = unit; + if_initname(&sc->sc_if, ifc->ifc_name, unit); sc->sc_if.if_mtu = PPP_MTU; sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; sc->sc_if.if_type = IFT_PPP; @@ -414,7 +413,7 @@ pppioctl(sc, cmd, data, flag, td) break; case PPPIOCGUNIT: - *(int *)data = sc->sc_if.if_unit; + *(int *)data = sc->sc_if.if_dunit; break; case PPPIOCGFLAGS: @@ -850,7 +849,7 @@ pppoutput(ifp, m0, dst, rtp) len = m_length(m0, NULL); if (sc->sc_flags & SC_LOG_OUTPKT) { - printf("ppp%d output: ", ifp->if_unit); + printf("%s output: ", ifp->if_xname); pppdumpm(m0); } @@ -1214,7 +1213,7 @@ ppp_ccp(sc, m, rcvd) if (sc->sc_xc_state != NULL && (*sc->sc_xcomp->comp_init) (sc->sc_xc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN, - sc->sc_if.if_unit, 0, sc->sc_flags & SC_DEBUG)) { + sc->sc_if.if_dunit, 0, sc->sc_flags & SC_DEBUG)) { s = splimp(); sc->sc_flags |= SC_COMP_RUN; splx(s); @@ -1224,7 +1223,7 @@ ppp_ccp(sc, m, rcvd) if (sc->sc_rc_state != NULL && (*sc->sc_rcomp->decomp_init) (sc->sc_rc_state, dp + CCP_HDRLEN, slen - CCP_HDRLEN, - sc->sc_if.if_unit, 0, sc->sc_mru, + sc->sc_if.if_dunit, 0, sc->sc_mru, sc->sc_flags & SC_DEBUG)) { s = splimp(); sc->sc_flags |= SC_DECOMP_RUN; diff --git a/sys/net/if_sl.c b/sys/net/if_sl.c index 1d3fa0b..39fce74 100644 --- a/sys/net/if_sl.c +++ b/sys/net/if_sl.c @@ -288,7 +288,6 @@ slcreate() sl_compress_init(&sc->sc_comp, -1); sc->sc_if.if_softc = sc; - sc->sc_if.if_name = "sl"; sc->sc_if.if_mtu = SLMTU; sc->sc_if.if_flags = #ifdef SLIP_IFF_OPTS @@ -312,12 +311,12 @@ slcreate() if (slisstatic(unit)) continue; LIST_FOREACH(nc, &sl_list, sl_next) { - if (nc->sc_if.if_unit == unit) + if (nc->sc_if.if_dunit == unit) continue; } break; } - sc->sc_if.if_unit = unit; + if_initname(&sc->sc_if, "sl", unit); LIST_INSERT_HEAD(&sl_list, sc, sl_next); if_attach(&sc->sc_if); @@ -450,7 +449,7 @@ sltioctl(tp, cmd, data, flag, td) s = splimp(); switch (cmd) { case SLIOCGUNIT: - *(int *)data = sc->sc_if.if_unit; + *(int *)data = sc->sc_if.if_dunit; break; case SLIOCSUNIT: @@ -459,9 +458,9 @@ sltioctl(tp, cmd, data, flag, td) splx(s); return (ENXIO); } - if (sc->sc_if.if_unit != unit) { + if (sc->sc_if.if_dunit != unit) { LIST_FOREACH(nc, &sl_list, sl_next) { - if (nc->sc_if.if_unit == *(u_int *)data) { + if (nc->sc_if.if_dunit == *(u_int *)data) { splx(s); return (ENXIO); } @@ -471,7 +470,7 @@ sltioctl(tp, cmd, data, flag, td) bpfdetach(&sc->sc_if); if_detach(&sc->sc_if); LIST_REMOVE(sc, sl_next); - sc->sc_if.if_unit = unit; + if_initname(&sc->sc_if, "sl", unit); LIST_INSERT_HEAD(&sl_list, sc, sl_next); if_attach(&sc->sc_if); bpfattach(&sc->sc_if, DLT_SLIP, SLIP_HDRLEN); diff --git a/sys/net/if_spppsubr.c b/sys/net/if_spppsubr.c index c21d922..27e7638 100644 --- a/sys/net/if_spppsubr.c +++ b/sys/net/if_spppsubr.c @@ -264,7 +264,7 @@ static struct sppp *spppq; static struct callout_handle keepalive_ch; #endif -#if defined(__FreeBSD__) && __FreeBSD__ >= 3 +#if defined(__FreeBSD__) && __FreeBSD__ >= 3 && __FreeBSD_version < 501113 #define SPP_FMT "%s%d: " #define SPP_ARGS(ifp) (ifp)->if_name, (ifp)->if_unit #else diff --git a/sys/net/if_stf.c b/sys/net/if_stf.c index 93fa212..76b92ec 100644 --- a/sys/net/if_stf.c +++ b/sys/net/if_stf.c @@ -180,8 +180,7 @@ stf_clone_create(ifc, unit) struct stf_softc *sc; sc = malloc(sizeof(struct stf_softc), M_STF, M_WAITOK | M_ZERO); - sc->sc_if.if_name = STFNAME; - sc->sc_if.if_unit = unit; + if_initname(&sc->sc_if, ifc->ifc_name, unit); sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6, stf_encapcheck, &in_stf_protosw, sc); diff --git a/sys/net/if_tap.c b/sys/net/if_tap.c index 3ac2be8..80d54e6 100644 --- a/sys/net/if_tap.c +++ b/sys/net/if_tap.c @@ -199,11 +199,10 @@ bail: ifp = &tp->tap_if; - TAPDEBUG("detaching %s%d\n", ifp->if_name,ifp->if_unit); + TAPDEBUG("detaching %s\n", ifp->if_xname); - KASSERT(!(tp->tap_flags & TAP_OPEN), - ("%s%d flags is out of sync", ifp->if_name, - ifp->if_unit)); + KASSERT(!(tp->tap_flags & TAP_OPEN), + ("%s flags is out of sync", ifp->if_xname)); /* XXX makedev check? nah.. not right now :) */ @@ -346,8 +345,7 @@ tapcreate(dev) /* fill the rest and attach interface */ ifp = &tp->tap_if; ifp->if_softc = tp; - ifp->if_unit = unit; - ifp->if_name = name; + if_initname(ifp, name, unit); ifp->if_init = tapifinit; ifp->if_start = tapifstart; ifp->if_ioctl = tapifioctl; @@ -363,8 +361,8 @@ tapcreate(dev) tp->tap_flags |= TAP_INITED; - TAPDEBUG("interface %s%d is created. minor = %#x\n", - ifp->if_name, ifp->if_unit, minor(dev)); + TAPDEBUG("interface %s is created. minor = %#x\n", + ifp->if_xname, minor(dev)); } /* tapcreate */ @@ -407,8 +405,8 @@ tapopen(dev, flag, mode, td) tp = dev->si_drv1; } - KASSERT(!(tp->tap_flags & TAP_OPEN), - ("%s%d flags is out of sync", tp->tap_if.if_name, unit)); + KASSERT(!(tp->tap_flags & TAP_OPEN), + ("%s flags is out of sync", tp->tap_if.if_xname)); bcopy(tp->arpcom.ac_enaddr, tp->ether_addr, sizeof(tp->ether_addr)); @@ -416,8 +414,8 @@ tapopen(dev, flag, mode, td) tp->tap_pid = td->td_proc->p_pid; tp->tap_flags |= TAP_OPEN; - TAPDEBUG("%s%d is open. minor = %#x\n", - tp->tap_if.if_name, unit, minor(dev)); + TAPDEBUG("%s is open. minor = %#x\n", + tp->tap_if.if_xname, minor(dev)); return (0); } /* tapopen */ @@ -440,7 +438,7 @@ tapclose(dev, foo, bar, td) struct ifnet *ifp = &tp->tap_if; KASSERT((tp->tap_unit != NULL), - ("%s%d is not open", ifp->if_name, ifp->if_unit)); + ("%s is not open", ifp->if_xname)); /* junk all pending output */ IF_DRAIN(&ifp->if_snd); @@ -482,12 +480,12 @@ tapclose(dev, foo, bar, td) tp->tap_flags &= ~TAP_OPEN; tp->tap_pid = 0; error = rman_release_resource(tp->tap_unit); - KASSERT((error == 0), - ("%s%d could not release unit", ifp->if_name, ifp->if_unit)); + KASSERT((error == 0), + ("%s could not release unit", ifp->if_xname)); tp->tap_unit = NULL; - TAPDEBUG("%s%d is closed. minor = %#x\n", - ifp->if_name, ifp->if_unit, minor(dev)); + TAPDEBUG("%s is closed. minor = %#x\n", + ifp->if_xname, minor(dev)); return (0); } /* tapclose */ @@ -505,7 +503,7 @@ tapifinit(xtp) struct tap_softc *tp = (struct tap_softc *)xtp; struct ifnet *ifp = &tp->tap_if; - TAPDEBUG("initializing %s%d\n", ifp->if_name, ifp->if_unit); + TAPDEBUG("initializing %s\n", ifp->if_xname); ifp->if_flags |= IFF_RUNNING; ifp->if_flags &= ~IFF_OACTIVE; @@ -570,7 +568,7 @@ tapifstart(ifp) struct tap_softc *tp = ifp->if_softc; int s; - TAPDEBUG("%s%d starting\n", ifp->if_name, ifp->if_unit); + TAPDEBUG("%s starting\n", ifp->if_xname); /* * do not junk pending output if we are in VMnet mode. @@ -581,8 +579,8 @@ tapifstart(ifp) ((tp->tap_flags & TAP_READY) != TAP_READY)) { struct mbuf *m = NULL; - TAPDEBUG("%s%d not ready, tap_flags = 0x%x\n", ifp->if_name, - ifp->if_unit, tp->tap_flags); + TAPDEBUG("%s not ready, tap_flags = 0x%x\n", ifp->if_xname, + tp->tap_flags); s = splimp(); do { @@ -751,12 +749,11 @@ tapread(dev, uio, flag) struct mbuf *m = NULL; int error = 0, len, s; - TAPDEBUG("%s%d reading, minor = %#x\n", - ifp->if_name, ifp->if_unit, minor(dev)); + TAPDEBUG("%s reading, minor = %#x\n", ifp->if_xname, minor(dev)); if ((tp->tap_flags & TAP_READY) != TAP_READY) { - TAPDEBUG("%s%d not ready. minor = %#x, tap_flags = 0x%x\n", - ifp->if_name, ifp->if_unit, minor(dev), tp->tap_flags); + TAPDEBUG("%s not ready. minor = %#x, tap_flags = 0x%x\n", + ifp->if_xname, minor(dev), tp->tap_flags); return (EHOSTDOWN); } @@ -794,8 +791,8 @@ tapread(dev, uio, flag) } if (m != NULL) { - TAPDEBUG("%s%d dropping mbuf, minor = %#x\n", ifp->if_name, - ifp->if_unit, minor(dev)); + TAPDEBUG("%s dropping mbuf, minor = %#x\n", ifp->if_xname, + minor(dev)); m_freem(m); } @@ -819,15 +816,15 @@ tapwrite(dev, uio, flag) struct mbuf *top = NULL, **mp = NULL, *m = NULL; int error = 0, tlen, mlen; - TAPDEBUG("%s%d writting, minor = %#x\n", - ifp->if_name, ifp->if_unit, minor(dev)); + TAPDEBUG("%s writting, minor = %#x\n", + ifp->if_xname, minor(dev)); if (uio->uio_resid == 0) return (0); if ((uio->uio_resid < 0) || (uio->uio_resid > TAPMRU)) { - TAPDEBUG("%s%d invalid packet len = %d, minor = %#x\n", - ifp->if_name, ifp->if_unit, uio->uio_resid, minor(dev)); + TAPDEBUG("%s invalid packet len = %d, minor = %#x\n", + ifp->if_xname, uio->uio_resid, minor(dev)); return (EIO); } @@ -890,20 +887,20 @@ tappoll(dev, events, td) struct ifnet *ifp = &tp->tap_if; int s, revents = 0; - TAPDEBUG("%s%d polling, minor = %#x\n", - ifp->if_name, ifp->if_unit, minor(dev)); + TAPDEBUG("%s polling, minor = %#x\n", + ifp->if_xname, minor(dev)); s = splimp(); if (events & (POLLIN | POLLRDNORM)) { if (ifp->if_snd.ifq_len > 0) { - TAPDEBUG("%s%d have data in queue. len = %d, " \ - "minor = %#x\n", ifp->if_name, ifp->if_unit, + TAPDEBUG("%s have data in queue. len = %d, " \ + "minor = %#x\n", ifp->if_xname, ifp->if_snd.ifq_len, minor(dev)); revents |= (events & (POLLIN | POLLRDNORM)); } else { - TAPDEBUG("%s%d waiting for data, minor = %#x\n", - ifp->if_name, ifp->if_unit, minor(dev)); + TAPDEBUG("%s waiting for data, minor = %#x\n", + ifp->if_xname, minor(dev)); selrecord(td, &tp->tap_rsel); } diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index 9e1e180..b46cef6 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -170,10 +170,10 @@ tunmodevent(module_t mod, int type, void *data) while (tunhead != NULL) { KASSERT((tunhead->tun_flags & TUN_OPEN) == 0, ("tununits is out of sync - unit %d", - tunhead->tun_if.if_unit)); + tunhead->tun_if.if_dunit)); tp = tunhead; dev = makedev(tun_cdevsw.d_maj, - unit2minor(tp->tun_if.if_unit)); + unit2minor(tp->tun_if.if_dunit)); KASSERT(dev->si_drv1 == tp, ("Bad makedev result")); tunhead = tp->next; bpfdetach(&tp->tun_if); @@ -232,8 +232,7 @@ tuncreate(dev_t dev) tunhead = sc; ifp = &sc->tun_if; - ifp->if_unit = dev2unit(dev); - ifp->if_name = TUNNAME; + if_initname(ifp, TUNNAME, dev2unit(dev)); ifp->if_mtu = TUNMTU; ifp->if_ioctl = tunifioctl; ifp->if_output = tunoutput; @@ -296,7 +295,7 @@ tunclose(dev_t dev, int foo, int bar, struct thread *td) tp = dev->si_drv1; ifp = &tp->tun_if; - KASSERT(tp->tun_unit, ("Unit %d not marked open", ifp->if_unit)); + KASSERT(tp->tun_unit, ("Unit %d not marked open", tp->tun_if.if_dunit)); tp->tun_flags &= ~TUN_OPEN; tp->tun_pid = 0; @@ -329,7 +328,7 @@ tunclose(dev_t dev, int foo, int bar, struct thread *td) TUNDEBUG (ifp, "closed\n"); err = rman_release_resource(tp->tun_unit); - KASSERT(err == 0, ("Unit %d failed to release", ifp->if_unit)); + KASSERT(err == 0, ("Unit %d failed to release", tp->tun_if.if_dunit)); return (0); } diff --git a/sys/net/if_var.h b/sys/net/if_var.h index b97a48d..52cee55 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -84,6 +84,8 @@ struct ether_header; #include <sys/mutex.h> /* XXX */ #include <sys/event.h> /* XXX */ +#define IF_DUNIT_NONE -1 + TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ TAILQ_HEAD(ifprefixhead, ifprefix); @@ -128,14 +130,15 @@ struct ifqueue { */ struct ifnet { void *if_softc; /* pointer to driver state */ - char *if_name; /* name, e.g. ``en'' or ``lo'' */ TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ + char if_xname[IFNAMSIZ]; /* external name (name + unit) */ + const char *if_dname; /* driver name */ + int if_dunit; /* unit or IF_DUNIT_NONE */ struct ifaddrhead if_addrhead; /* linked list of addresses per if */ struct klist if_klist; /* events attached to this if */ int if_pcount; /* number of promiscuous listeners */ struct bpf_if *if_bpf; /* packet filter structure */ u_short if_index; /* numeric abbreviation for this if */ - short if_unit; /* sub-unit for lower level driver */ short if_timer; /* time 'til if_watchdog called */ u_short if_nvlans; /* number of active vlans */ int if_flags; /* up/down, broadcast, etc. */ @@ -451,6 +454,7 @@ void if_attach(struct ifnet *); int if_delmulti(struct ifnet *, struct sockaddr *); void if_detach(struct ifnet *); void if_down(struct ifnet *); +void if_initname(struct ifnet *, const char *, int); int if_printf(struct ifnet *, const char *, ...) __printflike(2, 3); void if_route(struct ifnet *, int flag, int fam); int if_setlladdr(struct ifnet *, const u_char *, int); diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index c2e7402..75f25ed 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -250,8 +250,7 @@ vlan_clone_create(struct if_clone *ifc, int unit) SLIST_INIT(&ifv->vlan_mc_listhead); ifp->if_softc = ifv; - ifp->if_name = VLANNAME; - ifp->if_unit = unit; + if_initname(ifp, ifc->ifc_name, unit); /* NB: flags are not set here */ ifp->if_linkmib = &ifv->ifv_mib; ifp->if_linkmiblen = sizeof ifv->ifv_mib; @@ -787,8 +786,8 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) bzero(&vlr, sizeof vlr); VLAN_LOCK(); if (ifv->ifv_p) { - snprintf(vlr.vlr_parent, sizeof(vlr.vlr_parent), - "%s%d", ifv->ifv_p->if_name, ifv->ifv_p->if_unit); + strlcpy(vlr.vlr_parent, ifv->ifv_p->if_xname, + sizeof(vlr.vlr_parent)); vlr.vlr_tag = ifv->ifv_tag; } VLAN_UNLOCK(); diff --git a/sys/net/net_osdep.c b/sys/net/net_osdep.c index 7cfb142..90601e2 100644 --- a/sys/net/net_osdep.c +++ b/sys/net/net_osdep.c @@ -53,15 +53,5 @@ const char * if_name(ifp) struct ifnet *ifp; { -#define MAXNUMBUF 8 - static char nam[MAXNUMBUF][IFNAMSIZ + 10]; /*enough?*/ - static int ifbufround = 0; - char *cp; - - ifbufround = (ifbufround + 1) % MAXNUMBUF; - cp = nam[ifbufround]; - - snprintf(cp, IFNAMSIZ + 10, "%s%d", ifp->if_name, ifp->if_unit); - return ((const char *)cp); -#undef MAXNUMBUF + return ifp->if_xname; } diff --git a/sys/net/net_osdep.h b/sys/net/net_osdep.h index 01a7199..3893496 100644 --- a/sys/net/net_osdep.h +++ b/sys/net/net_osdep.h @@ -116,6 +116,8 @@ * --- --- --- * FreeBSD 2 no old standard if_name+unit * FreeBSD 3 yes strange if_name+unit + * FreeBSD 4 yes strange if_name+unit + * FreeBSD 5 yes strange if_xname * OpenBSD yes standard if_xname * NetBSD yes standard if_xname * BSDI [34] no old standard if_name+unit diff --git a/sys/net/ppp_tty.c b/sys/net/ppp_tty.c index f50c4d6..135ddeb 100644 --- a/sys/net/ppp_tty.c +++ b/sys/net/ppp_tty.c @@ -1092,7 +1092,7 @@ ppplogchar(sc, c) sc->sc_rawin[sc->sc_rawin_count++] = c; if (sc->sc_rawin_count >= sizeof(sc->sc_rawin) || (c < 0 && sc->sc_rawin_count > 0)) { - printf("ppp%d input: %*D", sc->sc_if.if_unit, + printf("%s input: %*D", sc->sc_if.if_xname, sc->sc_rawin_count, sc->sc_rawin, " "); sc->sc_rawin_count = 0; } diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 201e4a9..484bfe8 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -898,8 +898,7 @@ rt_ifannouncemsg(struct ifnet *ifp, int what) return; ifan = mtod(m, struct if_announcemsghdr *); ifan->ifan_index = ifp->if_index; - snprintf(ifan->ifan_name, sizeof(ifan->ifan_name), - "%s%d", ifp->if_name, ifp->if_unit); + strlcpy(ifan->ifan_name, ifp->if_xname, sizeof(ifan->ifan_name)); ifan->ifan_what = what; rt_dispatch(m, NULL); } |