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

Function if_allocmulti

freebsd/net/if.c:3337–3376  ·  view source on GitHub ↗

* Allocate a new ifmultiaddr and initialize based on passed arguments. We * make copies of passed sockaddrs. The ifmultiaddr will not be added to * the ifnet multicast address list here, so the caller must do that and * other setup work (such as notifying the device driver). The reference * count is initialized to 1. */

Source from the content-addressed store, hash-verified

3335 * count is initialized to 1.
3336 */
3337static struct ifmultiaddr *
3338if_allocmulti(struct ifnet *ifp, struct sockaddr *sa, struct sockaddr *llsa,
3339 int mflags)
3340{
3341 struct ifmultiaddr *ifma;
3342 struct sockaddr *dupsa;
3343
3344 ifma = malloc(sizeof *ifma, M_IFMADDR, mflags |
3345 M_ZERO);
3346 if (ifma == NULL)
3347 return (NULL);
3348
3349 dupsa = malloc(sa->sa_len, M_IFMADDR, mflags);
3350 if (dupsa == NULL) {
3351 free(ifma, M_IFMADDR);
3352 return (NULL);
3353 }
3354 bcopy(sa, dupsa, sa->sa_len);
3355 ifma->ifma_addr = dupsa;
3356
3357 ifma->ifma_ifp = ifp;
3358 ifma->ifma_refcount = 1;
3359 ifma->ifma_protospec = NULL;
3360
3361 if (llsa == NULL) {
3362 ifma->ifma_lladdr = NULL;
3363 return (ifma);
3364 }
3365
3366 dupsa = malloc(llsa->sa_len, M_IFMADDR, mflags);
3367 if (dupsa == NULL) {
3368 free(ifma->ifma_addr, M_IFMADDR);
3369 free(ifma, M_IFMADDR);
3370 return (NULL);
3371 }
3372 bcopy(llsa, dupsa, llsa->sa_len);
3373 ifma->ifma_lladdr = dupsa;
3374
3375 return (ifma);
3376}
3377
3378/*
3379 * if_freemulti: free ifmultiaddr structure and possibly attached related

Callers 1

if_addmultiFunction · 0.85

Calls 2

mallocFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected