OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / klips / net / ipsec_xscale / ipsec_glue_desc.c
1 /*
2  * IPSEC_GLUE_DESC interface code.
3  * Copyright 2003 Intel Corporation All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14
15  RCSID $Id: ipsec_glue_desc.c,v 1.0 2003/04/27 05:08:18 rgb Exp $
16
17  */
18  
19 /*
20  * Put the user defined include files required.
21  */
22 #include "IxTypes.h"
23 #include "IxOsCacheMMU.h"
24 #include "IxOsServices.h"
25 #include <linux/in.h>
26 #include <linux/slab.h>
27 #include "ipsec_glue_desc.h"
28 #include "ipsec_glue.h"
29
30 /*
31  * Variable declarations global to this file only.  Externs are followed by
32  * static variables.
33  */
34 static kmem_cache_t *ipsec_rcv_desc_cachep;
35 static kmem_cache_t *ipsec_xmit_desc_cachep;
36
37
38
39 /**
40  * ipsec_glue_rcv_desc_init
41  *
42  * Initialize ipsec_rcv descriptor management module. 
43  *
44  * Returns: IPSEC_GLUE_STATUS_SUCCESS - Initialization is successful
45  *                      IPSEC_GLUE_STATUS_FAIL - Initialization failure
46  */
47 int
48 ipsec_glue_rcv_desc_init (void)
49 {
50     ipsec_rcv_desc_cachep = kmem_cache_create("ipsec_rcv_desc",
51             IPSEC_RCV_DESC_SIZE, 0, 0, NULL, NULL);
52     if (!ipsec_rcv_desc_cachep)
53         return IPSEC_GLUE_STATUS_FAIL;
54
55     return IPSEC_GLUE_STATUS_SUCCESS;
56
57 } /* end of ipsec_glue_rcv_desc_init () function */
58
59
60 /**
61  * ipsec_glue_rcv_desc_get
62  *
63  * Get descriptor from the ipsec_rcv descriptor pool.
64  *
65  * Param : pIpsecRcvDescPtr [out] - Pointer to ipsec_rcv descriptor pointer
66  *
67  * Return : IPSEC_GLUE_STATUS_SUCCESS
68  *          IPSEC_GLUE_STATUS_FAIL
69  *
70  */
71 int
72 ipsec_glue_rcv_desc_get (IpsecRcvDesc **pIpsecRcvDescPtr)
73 {
74     if (!ipsec_rcv_desc_cachep)
75         return IPSEC_GLUE_STATUS_FAIL;
76
77     *pIpsecRcvDescPtr = kmem_cache_alloc(ipsec_rcv_desc_cachep, GFP_ATOMIC);
78     if (!*pIpsecRcvDescPtr)
79         return IPSEC_GLUE_STATUS_FAIL;
80
81     (*pIpsecRcvDescPtr)->stats = NULL;
82     return IPSEC_GLUE_STATUS_SUCCESS;
83 }
84
85
86 /**
87  * ipsec_glue_rcv_desc_release
88  *
89  * Release descriptor previously allocated back to the ipsec_rcv
90  * descriptor pool
91  *
92  * Return : IPSEC_GLUE_STATUS_SUCCESS
93  *          IPSEC_GLUE_STATUS_FAIL
94  */
95 int
96 ipsec_glue_rcv_desc_release (IpsecRcvDesc *pIpsecRcvDesc)
97 {
98     if (!ipsec_rcv_desc_cachep)
99         return IPSEC_GLUE_STATUS_FAIL;
100
101     kmem_cache_free(ipsec_rcv_desc_cachep, pIpsecRcvDesc);
102     return IPSEC_GLUE_STATUS_SUCCESS;
103 }
104
105
106
107
108 /**
109  * ipsec_rcv_desc_pool_free
110  *
111  * To free the memory allocated to descriptor pool through malloc
112  *        function.
113  *
114  * Param : None
115  * Return :  None
116  *
117  */
118 void
119 ipsec_rcv_desc_pool_free (void)
120 {
121     if (ipsec_rcv_desc_cachep && kmem_cache_destroy(ipsec_rcv_desc_cachep))
122         ipsec_rcv_desc_cachep = NULL;
123 }
124
125
126
127 /**
128  * ipsec_glue_xmit_desc_init
129  *
130  * Initialize ipsec_xmit descriptor management module.
131  *
132  * Return:  IPSEC_GLUE_STATUS_SUCCESS
133  *          IPSEC_GLUE_STATUS_FAIL
134  **/
135 int
136 ipsec_glue_xmit_desc_init (void)
137 {
138     ipsec_xmit_desc_cachep = kmem_cache_create("ipsec_xmit_desc",
139             IPSEC_XMIT_DESC_SIZE, 0, 0, NULL, NULL);
140     if (!ipsec_xmit_desc_cachep)
141         return IPSEC_GLUE_STATUS_FAIL;
142
143     return IPSEC_GLUE_STATUS_SUCCESS;
144 }
145
146
147
148 /**
149  * ipsec_glue_xmit_desc_get
150  *
151  * Get descriptor from the ipsec_xmit descriptor pool.
152  *
153  * Param : pIpsecXmitDescPtr [out] - Pointer to ipsec_xmit descriptor pointer
154  *
155  * Return:  IPSEC_GLUE_STATUS_SUCCESS
156  *          IPSEC_GLUE_STATUS_FAIL
157  **/
158 int
159 ipsec_glue_xmit_desc_get (IpsecXmitDesc **pIpsecXmitDescPtr)
160 {
161     if (!ipsec_xmit_desc_cachep)
162         return IPSEC_GLUE_STATUS_FAIL;
163
164     *pIpsecXmitDescPtr = kmem_cache_alloc(ipsec_xmit_desc_cachep, GFP_ATOMIC);
165     if (!*pIpsecXmitDescPtr)
166         return IPSEC_GLUE_STATUS_FAIL;
167
168     (*pIpsecXmitDescPtr)->tot_headroom = 0;
169     (*pIpsecXmitDescPtr)->tot_tailroom = 0;
170     (*pIpsecXmitDescPtr)->saved_header = NULL;
171     (*pIpsecXmitDescPtr)->oskb = NULL;
172     (*pIpsecXmitDescPtr)->pass = 0;
173     memset((char*)&((*pIpsecXmitDescPtr)->tdb), 0, sizeof(struct ipsec_sa));
174     return IPSEC_GLUE_STATUS_SUCCESS;
175 }
176
177
178
179 /**
180  * ipsec_glue_xmit_desc_release
181  *
182  * Release descriptor previously allocated back to the ipsec_xmit
183  * descriptor pool
184  *
185  * pIpsecXmitDesc [in] - Pointer to ipsec_xmit descriptor
186  *
187  * Return:  IPSEC_GLUE_STATUS_SUCCESS
188  *          IPSEC_GLUE_STATUS_FAIL
189  *
190  */
191 int
192 ipsec_glue_xmit_desc_release (IpsecXmitDesc *pIpsecXmitDesc)
193 {
194     if (!ipsec_xmit_desc_cachep)
195         return IPSEC_GLUE_STATUS_FAIL;
196
197     kmem_cache_free(ipsec_xmit_desc_cachep, pIpsecXmitDesc);
198     return IPSEC_GLUE_STATUS_SUCCESS;
199 }
200
201
202
203 /**
204  * ipsec_xmit_desc_pool_free
205  *
206  * To free the memory allocated to descriptor pool through malloc
207  *        function.
208  *
209  * Param : None
210  * Return :  None
211  *
212  */
213 void
214 ipsec_xmit_desc_pool_free (void)
215 {
216     if (ipsec_xmit_desc_cachep && kmem_cache_destroy(ipsec_xmit_desc_cachep))
217         ipsec_xmit_desc_cachep = NULL;
218 }