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

Function ifa_alloc

freebsd/net/if.c:1821–1855  ·  view source on GitHub ↗

* Initialization, destruction and refcounting functions for ifaddrs. */

Source from the content-addressed store, hash-verified

1819 * Initialization, destruction and refcounting functions for ifaddrs.
1820 */
1821struct ifaddr *
1822ifa_alloc(size_t size, int flags)
1823{
1824 struct ifaddr *ifa;
1825
1826 KASSERT(size >= sizeof(struct ifaddr),
1827 ("%s: invalid size %zu", __func__, size));
1828
1829 ifa = malloc(size, M_IFADDR, M_ZERO | flags);
1830 if (ifa == NULL)
1831 return (NULL);
1832
1833 if ((ifa->ifa_opackets = counter_u64_alloc(flags)) == NULL)
1834 goto fail;
1835 if ((ifa->ifa_ipackets = counter_u64_alloc(flags)) == NULL)
1836 goto fail;
1837 if ((ifa->ifa_obytes = counter_u64_alloc(flags)) == NULL)
1838 goto fail;
1839 if ((ifa->ifa_ibytes = counter_u64_alloc(flags)) == NULL)
1840 goto fail;
1841
1842 refcount_init(&ifa->ifa_refcnt, 1);
1843
1844 return (ifa);
1845
1846fail:
1847 /* free(NULL) is okay */
1848 counter_u64_free(ifa->ifa_opackets);
1849 counter_u64_free(ifa->ifa_ipackets);
1850 counter_u64_free(ifa->ifa_obytes);
1851 counter_u64_free(ifa->ifa_ibytes);
1852 free(ifa, M_IFADDR);
1853
1854 return (NULL);
1855}
1856
1857void
1858ifa_ref(struct ifaddr *ifa)

Callers 3

in_aifaddr_ioctlFunction · 0.85
in6_alloc_ifaFunction · 0.85
if_attach_internalFunction · 0.85

Calls 5

mallocFunction · 0.85
counter_u64_allocFunction · 0.85
refcount_initFunction · 0.85
counter_u64_freeFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected