/* * The "packet" keg constructor. */ static int mb_ctor_pack(void *mem, int size, void *arg, int how) { struct mbuf *m; struct mb_args *args; int error, flags; short type; m = (struct mbuf *)mem; args = (struct mb_args *)arg; flags = args->flags; type = args->type; #ifdef INVARIANTS trash_ctor(m->m_ext.ext_buf, MCLBYTES, arg, how); #endif error = m_init(m, NULL, size, how, type, flags); /* m_ext is already initialized. */ m->m_data = m->m_ext.ext_buf; m->m_flags = (flags | M_EXT); return (error); }
/* * Constructor for Mbuf master zone. * * The 'arg' pointer points to a mb_args structure which * contains call-specific information required to support the * mbuf allocation API. See mbuf.h. */ static int mb_ctor_mbuf(void *mem, int size, void *arg, int how) { struct mbuf *m; struct mb_args *args; int error; int flags; short type; #ifdef INVARIANTS trash_ctor(mem, size, arg, how); #endif args = (struct mb_args *)arg; type = args->type; /* * The mbuf is initialized later. The caller has the * responsibility to set up any MAC labels too. */ if (type == MT_NOINIT) return (0); m = (struct mbuf *)mem; flags = args->flags; error = m_init(m, NULL, size, how, type, flags); return (error); }
/* * The Cluster and Jumbo[PAGESIZE|9|16] zone constructor. * * Here the 'arg' pointer points to the Mbuf which we * are configuring cluster storage for. If 'arg' is * empty we allocate just the cluster without setting * the mbuf to it. See mbuf.h. */ static int mb_ctor_clust(void *mem, int size, void *arg, int how) { struct mbuf *m; u_int *refcnt; int type; uma_zone_t zone; #ifdef INVARIANTS trash_ctor(mem, size, arg, how); #endif switch (size) { case MCLBYTES: type = EXT_CLUSTER; zone = zone_clust; break; #if MJUMPAGESIZE != MCLBYTES case MJUMPAGESIZE: type = EXT_JUMBOP; zone = zone_jumbop; break; #endif #ifdef PACKET_MMAP: case MBUF_FRAME_SIZE: type = EXT_PACKETMMAP; zone = zone_packetmmap; break; #endif case MJUM9BYTES: type = EXT_JUMBO9; zone = zone_jumbo9; break; case MJUM16BYTES: type = EXT_JUMBO16; zone = zone_jumbo16; break; default: panic("unknown cluster size"); break; } m = (struct mbuf *)arg; refcnt = uma_find_refcnt(zone, mem); *refcnt = 1; if (m != NULL) { m->m_ext.ext_buf = (caddr_t)mem; m->m_data = m->m_ext.ext_buf; m->m_flags |= M_EXT; m->m_ext.ext_free = NULL; m->m_ext.ext_arg1 = NULL; m->m_ext.ext_arg2 = NULL; m->m_ext.ext_size = size; m->m_ext.ext_type = type; m->m_ext.ref_cnt = refcnt; } return (0); }
/* * Constructor for Mbuf master zone. * * The 'arg' pointer points to a mb_args structure which * contains call-specific information required to support the * mbuf allocation API. See mbuf.h. */ static int mb_ctor_mbuf(void *mem, int size, void *arg, int how) { struct mbuf *m; struct mb_args *args; #ifdef MAC int error; #endif int flags; short type; #ifdef INVARIANTS trash_ctor(mem, size, arg, how); #endif m = (struct mbuf *)mem; args = (struct mb_args *)arg; flags = args->flags; type = args->type; /* * The mbuf is initialized later. The caller has the * responsibility to set up any MAC labels too. */ if (type == MT_NOINIT) return (0); m->m_next = NULL; CHECK_SPLIT_LINKCNT(m, m->m_next, "mb_ctor_mbuf"); m->m_nextpkt = NULL; m->m_len = 0; m->m_flags = flags; m->m_type = type; if (flags & M_PKTHDR) { m->m_data = m->m_pktdat; m->m_pkthdr.rcvif = NULL; m->m_pkthdr.header = NULL; m->m_pkthdr.len = 0; m->m_pkthdr.csum_flags = 0; m->m_pkthdr.csum_data = 0; m->m_pkthdr.tso_segsz = 0; m->m_pkthdr.ether_vtag = 0; m->m_pkthdr.flowid = 0; SLIST_INIT(&m->m_pkthdr.tags); #ifdef MAC /* If the label init fails, fail the alloc */ error = mac_mbuf_init(m, how); if (error) return (error); #endif } else m->m_data = m->m_dat; return (0); }
/* * The "packet" keg constructor. */ static int mb_ctor_pack(void *mem, int size, void *arg, int how) { struct mbuf *m; struct mb_args *args; #ifdef MAC int error; #endif int flags; short type; m = (struct mbuf *)mem; args = (struct mb_args *)arg; flags = args->flags; type = args->type; #ifdef INVARIANTS trash_ctor(m->m_ext.ext_buf, MCLBYTES, arg, how); #endif m->m_next = NULL; CHECK_SPLIT_LINKCNT(m, m->m_next, "mb_ctor_pack"); m->m_nextpkt = NULL; m->m_data = m->m_ext.ext_buf; m->m_len = 0; m->m_flags = (flags | M_EXT); m->m_type = type; if (flags & M_PKTHDR) { m->m_pkthdr.rcvif = NULL; m->m_pkthdr.len = 0; m->m_pkthdr.header = NULL; m->m_pkthdr.csum_flags = 0; m->m_pkthdr.csum_data = 0; m->m_pkthdr.tso_segsz = 0; m->m_pkthdr.ether_vtag = 0; m->m_pkthdr.flowid = 0; SLIST_INIT(&m->m_pkthdr.tags); #ifdef MAC /* If the label init fails, fail the alloc */ error = mac_mbuf_init(m, how); if (error) return (error); #endif } /* m_ext is already initialized. */ return (0); }
/* * The Cluster and Jumbo[PAGESIZE|9|16] zone constructor. * * Here the 'arg' pointer points to the Mbuf which we * are configuring cluster storage for. If 'arg' is * empty we allocate just the cluster without setting * the mbuf to it. See mbuf.h. */ static int mb_ctor_clust(void *mem, int size, void *arg, int how) { struct mbuf *m; #ifdef INVARIANTS trash_ctor(mem, size, arg, how); #endif m = (struct mbuf *)arg; if (m != NULL) { m->m_ext.ext_buf = (caddr_t)mem; m->m_data = m->m_ext.ext_buf; m->m_flags |= M_EXT; m->m_ext.ext_free = NULL; m->m_ext.ext_arg1 = NULL; m->m_ext.ext_arg2 = NULL; m->m_ext.ext_size = size; m->m_ext.ext_type = m_gettype(size); m->m_ext.ext_flags = EXT_FLAG_EMBREF; m->m_ext.ext_count = 1; } return (0); }
/* * Checks an item to make sure it hasn't been overwritten since it was freed. * * Complies with standard fini arg/return * */ void trash_fini(void *mem, int size) { (void)trash_ctor(mem, size, NULL, 0); }