sctp_os_bsd.h revision 165220
1191783Srmacklem/*-
2191783Srmacklem * Copyright (c) 2006, Cisco Systems, Inc. All rights reserved.
3191783Srmacklem *
4191783Srmacklem * Redistribution and use in source and binary forms, with or without
5191783Srmacklem * modification, are permitted provided that the following conditions are met:
6191783Srmacklem *
7191783Srmacklem * a) Redistributions of source code must retain the above copyright notice,
8191783Srmacklem *   this list of conditions and the following disclaimer.
9191783Srmacklem *
10191783Srmacklem * b) Redistributions in binary form must reproduce the above copyright
11191783Srmacklem *    notice, this list of conditions and the following disclaimer in
12191783Srmacklem *   the documentation and/or other materials provided with the distribution.
13191783Srmacklem *
14191783Srmacklem * c) Neither the name of Cisco Systems, Inc. nor the names of its
15191783Srmacklem *    contributors may be used to endorse or promote products derived
16191783Srmacklem *    from this software without specific prior written permission.
17191783Srmacklem *
18191783Srmacklem * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19191783Srmacklem * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20191783Srmacklem * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21191783Srmacklem * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22191783Srmacklem * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23191783Srmacklem * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24191783Srmacklem * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25191783Srmacklem * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26191783Srmacklem * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27191783Srmacklem * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28191783Srmacklem * THE POSSIBILITY OF SUCH DAMAGE.
29191783Srmacklem */
30191783Srmacklem#include <sys/cdefs.h>
31191783Srmacklem__FBSDID("$FreeBSD: head/sys/netinet/sctp_os_bsd.h 165220 2006-12-14 17:02:55Z rrs $");
32191783Srmacklem#ifndef __sctp_os_bsd_h__
33191783Srmacklem#define __sctp_os_bsd_h__
34191783Srmacklem
35191783Srmacklem/*
36191783Srmacklem * includes
37191783Srmacklem */
38191783Srmacklem#include <sys/random.h>
39191783Srmacklem
40191783Srmacklem
41191783Srmacklem/*
42191783Srmacklem *
43191783Srmacklem */
44191783Srmacklemtypedef struct mbuf *sctp_mbuf_t;
45191783Srmacklem
46191783Srmacklem#define USER_ADDR_NULL	(NULL)	/* FIX ME: temp */
47191783Srmacklem
48191783Srmacklem/*
49191783Srmacklem * general memory allocation
50191783Srmacklem */
51191783Srmacklem#define SCTP_MALLOC(var, type, size, name) \
52191783Srmacklem    do { \
53191783Srmacklem	MALLOC(var, type, size, M_PCB, M_NOWAIT); \
54191783Srmacklem    } while (0)
55191783Srmacklem
56191783Srmacklem#define SCTP_FREE(var)	FREE(var, M_PCB)
57191783Srmacklem
58191783Srmacklem#define SCTP_MALLOC_SONAME(var, type, size) \
59191783Srmacklem    do { \
60191783Srmacklem	MALLOC(var, type, size, M_SONAME, M_WAITOK | M_ZERO); \
61191783Srmacklem    } while (0)
62191783Srmacklem
63191783Srmacklem#define SCTP_FREE_SONAME(var)	FREE(var, M_SONAME)
64191783Srmacklem
65191783Srmacklem/*
66191783Srmacklem * zone allocation functions
67191783Srmacklem */
68191783Srmacklem#include <vm/uma.h>
69191783Srmacklem/* SCTP_ZONE_INIT: initialize the zone */
70191783Srmacklemtypedef struct uma_zone *sctp_zone_t;
71191783Srmacklem
72191783Srmacklem#define UMA_ZFLAG_FULL	0x0020
73191783Srmacklem#define SCTP_ZONE_INIT(zone, name, size, number) { \
74191783Srmacklem	zone = uma_zcreate(name, size, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,\
75191783Srmacklem		UMA_ZFLAG_FULL); \
76191783Srmacklem	uma_zone_set_max(zone, number); \
77191783Srmacklem}
78191783Srmacklem
79191783Srmacklem/* SCTP_ZONE_GET: allocate element from the zone */
80191783Srmacklem#define SCTP_ZONE_GET(zone) \
81191783Srmacklem	uma_zalloc(zone, M_NOWAIT);
82191783Srmacklem
83191783Srmacklem/* SCTP_ZONE_FREE: free element from the zone */
84191783Srmacklem#define SCTP_ZONE_FREE(zone, element) \
85191783Srmacklem	uma_zfree(zone, element);
86191783Srmacklem
87191783Srmacklem/*
88192115Srmacklem * Functions
89191783Srmacklem */
90191783Srmacklem#define sctp_read_random(buf, len)	read_random(buf, len)
91191783Srmacklem
92191783Srmacklem#endif
93191783Srmacklem