| 728 | } |
| 729 | |
| 730 | static int |
| 731 | epair_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params) |
| 732 | { |
| 733 | struct epair_softc *sca, *scb; |
| 734 | struct ifnet *ifp; |
| 735 | char *dp; |
| 736 | int error, unit, wildcard; |
| 737 | uint64_t hostid; |
| 738 | uint32_t key[3]; |
| 739 | uint32_t hash; |
| 740 | uint8_t eaddr[ETHER_ADDR_LEN]; /* 00:00:00:00:00:00 */ |
| 741 | |
| 742 | /* Try to see if a special unit was requested. */ |
| 743 | error = ifc_name2unit(name, &unit); |
| 744 | if (error != 0) |
| 745 | return (error); |
| 746 | wildcard = (unit < 0); |
| 747 | |
| 748 | error = ifc_alloc_unit(ifc, &unit); |
| 749 | if (error != 0) |
| 750 | return (error); |
| 751 | |
| 752 | /* |
| 753 | * If no unit had been given, we need to adjust the ifName. |
| 754 | * Also make sure there is space for our extra [ab] suffix. |
| 755 | */ |
| 756 | for (dp = name; *dp != '\0'; dp++); |
| 757 | if (wildcard) { |
| 758 | error = snprintf(dp, len - (dp - name), "%d", unit); |
| 759 | if (error > len - (dp - name) - 1) { |
| 760 | /* ifName too long. */ |
| 761 | ifc_free_unit(ifc, unit); |
| 762 | return (ENOSPC); |
| 763 | } |
| 764 | dp += error; |
| 765 | } |
| 766 | if (len - (dp - name) - 1 < 1) { |
| 767 | /* No space left for our [ab] suffix. */ |
| 768 | ifc_free_unit(ifc, unit); |
| 769 | return (ENOSPC); |
| 770 | } |
| 771 | *dp = 'b'; |
| 772 | /* Must not change dp so we can replace 'a' by 'b' later. */ |
| 773 | *(dp+1) = '\0'; |
| 774 | |
| 775 | /* Check if 'a' and 'b' interfaces already exist. */ |
| 776 | if (ifunit(name) != NULL) |
| 777 | return (EEXIST); |
| 778 | *dp = 'a'; |
| 779 | if (ifunit(name) != NULL) |
| 780 | return (EEXIST); |
| 781 | |
| 782 | /* Allocate memory for both [ab] interfaces */ |
| 783 | sca = malloc(sizeof(struct epair_softc), M_EPAIR, M_WAITOK | M_ZERO); |
| 784 | EPAIR_REFCOUNT_INIT(&sca->refcount, 1); |
| 785 | sca->ifp = if_alloc(IFT_ETHER); |
| 786 | if (sca->ifp == NULL) { |
| 787 | free(sca, M_EPAIR); |
nothing calls this directly
no test coverage detected