/* * Check if the IP interface named by `lifrp' is RDS-capable. */ boolean_t rdsv3_capable_interface(struct lifreq *lifrp) { char ifname[LIFNAMSIZ]; char drv[MAXLINKNAMELEN]; uint_t ppa; char *cp; RDSV3_DPRINTF4("rdsv3_capable_interface", "Enter"); if (lifrp->lifr_type == IFT_IB) return (B_TRUE); /* * Strip off the logical interface portion before getting * intimate with the name. */ (void) strlcpy(ifname, lifrp->lifr_name, LIFNAMSIZ); if ((cp = strchr(ifname, ':')) != NULL) *cp = '\0'; if (strcmp("lo0", ifname) == 0) { /* * loopback is considered RDS-capable */ return (B_TRUE); } return (ddi_parse(ifname, drv, &ppa) == DDI_SUCCESS && rdsv3_if_lookup_by_name(drv)); }
/* * Check if the IP interface named by `ifrp' is RDS-capable. */ boolean_t rdsv3_capable_interface_old(struct ifreq *ifrp) { char ifname[IFNAMSIZ]; char drv[MAXLINKNAMELEN]; uint_t ppa; char *cp; RDSV3_DPRINTF4("rdsv3_capable_interface_old", "Enter"); /* * Strip off the logical interface portion before getting * intimate with the name. */ (void) strlcpy(ifname, ifrp->ifr_name, IFNAMSIZ); if ((cp = strchr(ifname, ':')) != NULL) *cp = '\0'; RDSV3_DPRINTF4("rdsv3_capable_interface_old", "ifname: %s", ifname); if ((strcmp("lo0", ifname) == 0) || (strncmp("ibd", ifname, 3) == 0)) { /* * loopback and IB are considered RDS-capable */ return (B_TRUE); } return (ddi_parse(ifname, drv, &ppa) == DDI_SUCCESS && rdsv3_if_lookup_by_name(drv)); }
static kstat_t * softmac_hold_dev_kstat(softmac_t *softmac) { char drv[MAXLINKNAMELEN]; uint_t ppa; kstat_t *ksp; if (ddi_parse(softmac->smac_devname, drv, &ppa) != DDI_SUCCESS) return (NULL); /* * Find the kstat by the module name and the instance number. */ ksp = kstat_hold_byname(drv, ppa, softmac->smac_devname, ALL_ZONES); if (ksp != NULL) { KSTAT_ENTER(ksp); if ((ksp->ks_data != NULL) && (ksp->ks_type == KSTAT_TYPE_NAMED)) { /* * Update the kstat to get the latest statistics. */ if (KSTAT_UPDATE(ksp, KSTAT_READ) == 0) return (ksp); } KSTAT_EXIT(ksp); kstat_rele(ksp); } return (NULL); }
int dls_vlan_hold(const char *name, dls_vlan_t **dvpp, boolean_t create_vlan) { int err; dls_vlan_t *dvp; dls_link_t *dlp; boolean_t vlan_created = B_FALSE; again: rw_enter(&i_dls_vlan_lock, RW_WRITER); err = mod_hash_find(i_dls_vlan_hash, (mod_hash_key_t)name, (mod_hash_val_t *)&dvp); if (err != 0) { char mac[MAXNAMELEN]; uint_t index, ddi_inst, mac_ppa, len; uint16_t vid; ASSERT(err == MH_ERR_NOTFOUND); vlan_created = B_FALSE; if (!create_vlan) { err = ENOENT; goto done; } /* * Only create tagged vlans on demand. * Note that if we get here, 'name' must be a sane * value because it must have been derived from * ddi_major_to_name(). */ if (ddi_parse(name, mac, &index) != DDI_SUCCESS || (vid = DLS_PPA2VID(index)) == VLAN_ID_NONE || vid > VLAN_ID_MAX) { err = EINVAL; goto done; } mac_ppa = (uint_t)DLS_PPA2INST(index); if (strcmp(mac, "aggr") == 0) ddi_inst = 0; else ddi_inst = mac_ppa; len = strlen(mac); ASSERT(len < MAXNAMELEN); (void) snprintf(mac + len, MAXNAMELEN - len, "%d", mac_ppa); rw_exit(&i_dls_vlan_lock); if ((err = dls_vlan_create(name, mac, ddi_inst, vid)) != 0) { rw_enter(&i_dls_vlan_lock, RW_WRITER); goto done; } /* * At this point someone else could do a dls_vlan_hold and * dls_vlan_rele on this new vlan and causes it to be * destroyed. This will at worst cause us to spin a few * times. */ vlan_created = B_TRUE; goto again; } dlp = dvp->dv_dlp; if ((err = dls_mac_hold(dlp)) != 0) goto done; /* * Do not allow the creation of tagged VLAN interfaces on * non-Ethernet links. Note that we cannot do this check in * dls_vlan_create() nor in this function prior to the call to * dls_mac_hold(). The reason is that before we do a * dls_mac_hold(), we may not have opened the mac, and therefore do * not know what kind of media the mac represents. In other words, * dls_mac_hold() assigns the dl_mip of the dls_link_t we're * interested in. */ if (dvp->dv_id != VLAN_ID_NONE && dlp->dl_mip->mi_media != DL_ETHER) { dls_mac_rele(dlp); err = EINVAL; goto done; } if ((err = mac_start(dlp->dl_mh)) != 0) { dls_mac_rele(dlp); goto done; } if (dvp->dv_ref++ == 0) dls_mac_stat_create(dvp); *dvpp = dvp; done: rw_exit(&i_dls_vlan_lock); /* * We could be destroying a vlan created by another thread. This * is ok because this other thread will just loop back up and * recreate the vlan. */ if (err != 0 && vlan_created) (void) dls_vlan_destroy(name); return (err); }