* Initialization, destruction and refcounting functions for ifaddrs. */
| 1819 | * Initialization, destruction and refcounting functions for ifaddrs. |
| 1820 | */ |
| 1821 | struct ifaddr * |
| 1822 | ifa_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 | |
| 1846 | fail: |
| 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 | |
| 1857 | void |
| 1858 | ifa_ref(struct ifaddr *ifa) |
no test coverage detected