| 1664 | } |
| 1665 | |
| 1666 | void |
| 1667 | ifmaybeload(const char *name) |
| 1668 | { |
| 1669 | #ifndef FSTACK |
| 1670 | #define MOD_PREFIX_LEN 3 /* "if_" */ |
| 1671 | struct module_stat mstat; |
| 1672 | int i, fileid, modid; |
| 1673 | char ifkind[IFNAMSIZ + MOD_PREFIX_LEN], ifname[IFNAMSIZ], *dp; |
| 1674 | const char *cp; |
| 1675 | struct module_map_entry *mme; |
| 1676 | bool found; |
| 1677 | |
| 1678 | /* loading suppressed by the user */ |
| 1679 | if (noload) |
| 1680 | return; |
| 1681 | |
| 1682 | /* trim the interface number off the end */ |
| 1683 | strlcpy(ifname, name, sizeof(ifname)); |
| 1684 | for (dp = ifname; *dp != 0; dp++) |
| 1685 | if (isdigit(*dp)) { |
| 1686 | *dp = 0; |
| 1687 | break; |
| 1688 | } |
| 1689 | |
| 1690 | /* Either derive it from the map or guess otherwise */ |
| 1691 | *ifkind = '\0'; |
| 1692 | found = false; |
| 1693 | for (i = 0; i < nitems(module_map); ++i) { |
| 1694 | mme = &module_map[i]; |
| 1695 | if (strcmp(mme->ifname, ifname) == 0) { |
| 1696 | strlcpy(ifkind, mme->kldname, sizeof(ifkind)); |
| 1697 | found = true; |
| 1698 | break; |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | /* We didn't have an alias for it... we'll guess. */ |
| 1703 | if (!found) { |
| 1704 | /* turn interface and unit into module name */ |
| 1705 | strlcpy(ifkind, "if_", sizeof(ifkind)); |
| 1706 | strlcat(ifkind, ifname, sizeof(ifkind)); |
| 1707 | } |
| 1708 | |
| 1709 | /* scan files in kernel */ |
| 1710 | mstat.version = sizeof(struct module_stat); |
| 1711 | for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { |
| 1712 | /* scan modules in file */ |
| 1713 | for (modid = kldfirstmod(fileid); modid > 0; |
| 1714 | modid = modfnext(modid)) { |
| 1715 | if (modstat(modid, &mstat) < 0) |
| 1716 | continue; |
| 1717 | /* strip bus name if present */ |
| 1718 | if ((cp = strchr(mstat.name, '/')) != NULL) { |
| 1719 | cp++; |
| 1720 | } else { |
| 1721 | cp = mstat.name; |
| 1722 | } |
| 1723 | /* |