-struct sockaddr_entry *
-sockaddrentry_alloc(int how)
-{
- struct sockaddr_entry *se;
-
- se = (how == M_WAITOK) ? zalloc(se_zone) : zalloc_noblock(se_zone);
- if (se != NULL)
- bzero(se, se_zone_size);
-
- return (se);
-}
-
-void
-sockaddrentry_free(struct sockaddr_entry *se)
-{
- if (se->se_addr != NULL) {
- FREE(se->se_addr, M_SONAME);
- se->se_addr = NULL;
- }
- zfree(se_zone, se);
-}
-
-struct sockaddr_entry *
-sockaddrentry_dup(const struct sockaddr_entry *src_se, int how)
-{
- struct sockaddr_entry *dst_se;
-
- dst_se = sockaddrentry_alloc(how);
- if (dst_se != NULL) {
- int len = src_se->se_addr->sa_len;
-
- MALLOC(dst_se->se_addr, struct sockaddr *,
- len, M_SONAME, how | M_ZERO);
- if (dst_se->se_addr != NULL) {
- bcopy(src_se->se_addr, dst_se->se_addr, len);
- } else {
- sockaddrentry_free(dst_se);
- dst_se = NULL;
- }
- }
-
- return (dst_se);
-}
-
-struct sockaddr_list *
-sockaddrlist_alloc(int how)
-{
- struct sockaddr_list *sl;
-
- sl = (how == M_WAITOK) ? zalloc(sl_zone) : zalloc_noblock(sl_zone);
- if (sl != NULL) {
- bzero(sl, sl_zone_size);
- TAILQ_INIT(&sl->sl_head);
- }
- return (sl);
-}
-
-void
-sockaddrlist_free(struct sockaddr_list *sl)
-{
- struct sockaddr_entry *se, *tse;
-
- TAILQ_FOREACH_SAFE(se, &sl->sl_head, se_link, tse) {
- sockaddrlist_remove(sl, se);
- sockaddrentry_free(se);
- }
- VERIFY(sl->sl_cnt == 0 && TAILQ_EMPTY(&sl->sl_head));
- zfree(sl_zone, sl);
-}
-
-void
-sockaddrlist_insert(struct sockaddr_list *sl, struct sockaddr_entry *se)
-{
- VERIFY(!(se->se_flags & SEF_ATTACHED));
- se->se_flags |= SEF_ATTACHED;
- TAILQ_INSERT_TAIL(&sl->sl_head, se, se_link);
- sl->sl_cnt++;
- VERIFY(sl->sl_cnt != 0);
-}
-
-void
-sockaddrlist_remove(struct sockaddr_list *sl, struct sockaddr_entry *se)
-{
- VERIFY(se->se_flags & SEF_ATTACHED);
- se->se_flags &= ~SEF_ATTACHED;
- VERIFY(sl->sl_cnt != 0);
- sl->sl_cnt--;
- TAILQ_REMOVE(&sl->sl_head, se, se_link);
-}
-
-struct sockaddr_list *
-sockaddrlist_dup(const struct sockaddr_list *src_sl, int how)
-{
- struct sockaddr_entry *src_se, *tse;
- struct sockaddr_list *dst_sl;
-
- dst_sl = sockaddrlist_alloc(how);
- if (dst_sl == NULL)
- return (NULL);
-
- TAILQ_FOREACH_SAFE(src_se, &src_sl->sl_head, se_link, tse) {
- struct sockaddr_entry *dst_se;
-
- if (src_se->se_addr == NULL)
- continue;
-
- dst_se = sockaddrentry_dup(src_se, how);
- if (dst_se == NULL) {
- sockaddrlist_free(dst_sl);
- return (NULL);
- }
-
- sockaddrlist_insert(dst_sl, dst_se);
- }
- VERIFY(src_sl->sl_cnt == dst_sl->sl_cnt);
-
- return (dst_sl);
-}
-