void mq_disconnect(ipc_t ipc) { msgctl(QKEY,IPC_RMID, NULL); free(ipc->ipcdata); qdel(ipc->inbox); qdel(ipc->outbox); free(ipc); return; }
int ni_delete(NET ifp) { int iface; if ((ifp->n_flags & NF_DYNIF) == 0) /* not a dynamic iface */ return ENP_PARAM; ni_set_state(ifp, NI_DOWN); /* mark iface as down */ if (qdel(&netlist, (void*)ifp)==NULL) /* delete from list */ return ENP_PARAM; /* interface not in queue */ /* remove ifp from nets[], filling it's hole */ for(iface = 0; iface < MAXNETS; iface++) { if(nets[iface] == ifp) /* found ifp to delete */ { /* move following nets[] entrys up 1 slot to cover deleted net */ for( ; iface < (MAXNETS - 1); iface++) nets[iface] = nets[iface + 1]; break; } } ifNumber = netlist.q_len; /* fix global if c ount */ NET_FREE(ifp); return 0; /* no way this can fail? */ }
void sofree(struct socket * so) { INET_TRACE (INETM_SOCKET|INETM_CLOSE, ("INET: sofree, so %lx so_pcb %lx so_state %x so_head %lx\n", so, so->so_pcb, so->so_state, so->so_head)); if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0) return; if (so->so_head) { if (!soqremque(so, 0) && !soqremque(so, 1)) panic("sofree"); so->so_head = 0; } sbrelease(&so->so_snd); sorflush(so); #ifdef SAVE_SOCK_ENDPOINTS if (so->so_endpoint) _socket_free_entry (so); #endif /* SAVE_SOCK_ENDPOINTS */ #ifdef IP_MULTICAST /* multicast opts? */ if (so->inp_moptions) ip_freemoptions(so->inp_moptions); #endif /* IP_MULTICAST */ /* IP_TOS opts? */ if (so->so_optsPack) SOCOPT_FREE(so->so_optsPack); qdel(&soq, so); /* Delete the socket entry from the queue */ if (so_evtmap) (*so_evtmap_delete) (so); SOC_FREE(so); }
struct mbuf * m_free(struct mbuf * m) { struct mbuf * nextptr; #ifdef NPDEBUG if (mbufq.q_len < 1) panic("mfree: q_len"); if (m->m_type < MT_RXDATA || m->m_type > MT_IFADDR) { if (m->m_type == MT_FREE) { dtrap(); /* debug double free of mbuf by tcp_in() */ return m->m_next; /* seems harmless, though.... */ } else panic("m_free: type"); } #endif /* NPDEBUG */ nextptr = m->m_next; /* remember value to return */ if (qdel(&mbufq, m) == NULL) panic("m_free: missing"); m->m_type = MT_FREE; /* this may seem silly, but helps error checking */ if (m->pkt) { LOCK_NET_RESOURCE(FREEQ_RESID); pk_free(m->pkt); /* free up the netport buffer */ UNLOCK_NET_RESOURCE(FREEQ_RESID); } mbstat.frees++; putq(&mfreeq, (qp)m); return nextptr; }
int ni_create(NET * newifp, /* OUT - created handle */ int (*create_device)(NET newifp, void * bindinfo), /* IN */ char * name, /* IN */ void * bindinfo) /* IN */ { int i; int err; int iface; /* index into nets[], for legacy support */ struct net * ifp; struct IfMib * mib; iface = netlist.q_len; /* index to new interface */ /* Make sure we have spare slots in various net arrays */ if(iface >= MAXNETS) return ENP_RESOURCE; /* first allocate the memory */ ifp = (struct net *)NET_ALLOC(sizeof(struct net)); if (!ifp) return ENP_NOMEM; mib = &ifp->mib; /* set MIB pointer for backward compatability */ /* set up pointers - add net to list */ putq(&netlist, ifp); ifp->n_mib = mib; /* support the old style nets[] array */ nets[iface] = ifp; ifp->n_flags = NF_DYNIF; /* set flags field */ if (name != NULL) { MEMCPY(ifp->name, name, IF_NAMELEN-1); ifp->name[IF_NAMELEN-1] = 0; } err = (*create_device)(ifp, bindinfo); if (err) goto bad_create; /* don't allow the max header or MTU size to grow. If this is * a problem then set the MaxXxx ints at init time *BEFORE* * calling NetInit() or ip_startup(). */ if ((ifp->n_lnh > MaxLnh) || (ifp->n_mtu > MaxMtu)) { dtrap(); /* programming, see note above */ err = ENP_LOGIC; goto bad_create; } if (ifp->n_reg_type) /* do we need to register types? */ { for (i = 0; i < PLLISTLEN; i++) { if (protlist[i] == 0) break; ifp->n_reg_type(protlist[i], ifp); } } err = ni_set_state(ifp, NI_UP); if (err) goto bad_create; /* interface is created, no error */ ifNumber = netlist.q_len; *newifp = ifp; return 0; /* OK return */ bad_create: /* user create routine returned an error. */ qdel(&netlist, (void*)ifp); /* delete from list */ NET_FREE(ifp); nets[iface] = NULL; return err; }
void pk_free_heapbuf (PACKET pkt) { u_char start_offset; u_char num_guard_bytes; char * bufp; #ifdef HEAPBUFS_DEBUG PHLEP phlep; #endif u_long len; u_long decrement; #ifdef NPDEBUG start_offset = ALIGN_TYPE; num_guard_bytes = ALIGN_TYPE + 1; #else start_offset = num_guard_bytes = 0; #endif bufp = pkt->nb_buff - start_offset; len = pkt->nb_blen + num_guard_bytes; #ifdef HEAPBUFS_DEBUG /* update private heapbuf list - remove element */ ENTER_CRIT_SECTION(&phlq); for (phlep=(PHLEP)phlq.q_head; phlep; phlep = phlep->next) { if ((phlep->netbufp == pkt) && (phlep->databufp == bufp)) { /* found a matching entry; remove it... */ break; } } EXIT_CRIT_SECTION(&phlq); /* did we find the private heapbuf list entry corresponding to this allocation? */ if (phlep == 0) { /* No; we were able to validate this PACKET earlier, * but the corresponding PHL entry has now disappeared! */ INCR_SHARED_VAR (hbufstats, NO_PHLE_ERR, 1); return; } else { /* delete PHLE entry from its queue. This deletion is protected via * ENTER_CRIT_SECTION () and EXIT_CRIT_SECTION () macros. */ qdel(&phlq, phlep); } #endif /* HEAPBUFS_DEBUG */ if (heap_type == HEAP_ACCESS_BLOCKING) UNLOCK_NET_RESOURCE (FREEQ_RESID); HB_FREE (pkt); HB_FREE (bufp); #ifdef HEAPBUFS_DEBUG HB_FREE (phlep); #endif /* HEAPBUFS_DEBUG */ if (heap_type == HEAP_ACCESS_BLOCKING) LOCK_NET_RESOURCE (FREEQ_RESID); /* decrement the global counter that is used to keep track of the total * heap allocation */ decrement = sizeof (struct netbuf) + len; #ifdef HEAPBUFS_DEBUG /* also account for the size of the debug structure if HEAPBUFS_DEBUG * is enabled */ decrement += sizeof (PHLE); #endif DECR_SHARED_VAR (heap_curr_mem, decrement); return; }