Index: sys/net/if.h =================================================================== --- sys/net/if.h +++ sys/net/if.h @@ -588,6 +588,7 @@ IF_VLAN, IF_TOEDEV, IF_MEDIA, + IF_RING, /* * Space above 99999 is split among different vendors. * @@ -727,6 +728,10 @@ * later. Otherwise it inherits static iftsomax from ifdriver. */ struct iftsomax *ifat_tsomax; + /* + * Number of the tx/rx rings. + */ + int ifat_nrings; }; /* Index: sys/net/if.c =================================================================== --- sys/net/if.c +++ sys/net/if.c @@ -515,8 +515,9 @@ struct iftype *ift; struct ifnet *ifp; struct ifaddr *ifa; + struct ifring **ifrs; struct sockaddr_dl *sdl; - int socksize, ifasize, namelen, masklen; + int socksize, ifasize, namelen, masklen, nrings; KASSERT(ifat->ifat_version == IF_ATTACH_VERSION, ("%s: version %d, expected %d", @@ -612,6 +613,18 @@ refcount_init(&ifp->if_refcount, 1); /* + * Allocate ifring to store the per-ring statistics for this + * interface. + */ + nrings = ifat->ifat_nrings; + ifrs = malloc(sizeof(struct ifring *) * nrings, M_IFNET, M_WAITOK); + for (int i = 0; i < nrings; i++) + ifrs[i] = malloc(sizeof(struct ifring), M_IFNET, + M_WAITOK | M_ZERO); + ifp->if_nrings = nrings; + ifp->if_rings = ifrs; + + /* * Allocate ifaddr to store link level address and name for this * interface. Always save enough space for any possiable name so * we can do a rename in place later. @@ -684,6 +697,10 @@ ifmedia_free(ifp); + for (int i = 0; i < ifp->if_nrings; i++) + free(ifp->if_rings[i], M_IFNET); + free(ifp->if_rings, M_IFNET); + rw_destroy(&ifp->if_lock); free(ifp, M_IFNET); } @@ -1573,6 +1590,8 @@ return (ifp->if_xname); case IF_VLAN: return (ifp->if_vlantrunk); + case IF_RING: + return (ifp->if_rings); default: /* fall through */ ; Index: sys/net/if_var.h =================================================================== --- sys/net/if_var.h +++ sys/net/if_var.h @@ -152,6 +152,8 @@ size_t if_linkmiblen; /* length of above data */ u_int if_refcount; /* reference count */ u_int if_fib; /* interface FIB */ + struct ifring **if_rings; /* pairs of tx and rx rings */ + int if_nrings; /* elements in if_rings */ uint8_t if_link_state; /* current link state */ uint32_t if_mtu; /* maximum transmission unit */