MCPcopy Create free account
hub / github.com/F-Stack/f-stack / epair_clone_create

Function epair_clone_create

freebsd/net/if_epair.c:730–916  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

728}
729
730static int
731epair_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);

Callers

nothing calls this directly

Calls 15

ifc_name2unitFunction · 0.85
ifc_alloc_unitFunction · 0.85
snprintfFunction · 0.85
ifc_free_unitFunction · 0.85
ifunitFunction · 0.85
mallocFunction · 0.85
if_allocFunction · 0.85
if_freeFunction · 0.85
netisr_get_cpuidFunction · 0.85
ifmedia_initFunction · 0.85
ifmedia_addFunction · 0.85
ifmedia_setFunction · 0.85

Tested by

no test coverage detected