blob: 1ffda55885192187ec0babc2191da610745afd09 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Memory management routine
2 Copyright (C) 1998 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#ifndef _ZEBRA_MEMORY_H
22#define _ZEBRA_MEMORY_H
23
24/* #define MEMORY_LOG */
25
26/* For tagging memory, below is the type of the memory. */
27enum
28{
29 MTYPE_TMP = 1,
30 MTYPE_STRVEC,
31 MTYPE_VECTOR,
32 MTYPE_VECTOR_INDEX,
33 MTYPE_LINK_LIST,
34 MTYPE_LINK_NODE,
35 MTYPE_THREAD,
36 MTYPE_THREAD_MASTER,
paul9d11a192004-10-31 16:19:24 +000037 MTYPE_THREAD_STATS,
38 MTYPE_THREAD_FUNCNAME,
paul718e3742002-12-13 20:15:29 +000039 MTYPE_VTY,
40 MTYPE_VTY_HIST,
41 MTYPE_VTY_OUT_BUF,
42 MTYPE_IF,
hassoca776982004-06-12 14:33:05 +000043 MTYPE_IF_IRDP,
paul718e3742002-12-13 20:15:29 +000044 MTYPE_CONNECTED,
45 MTYPE_AS_SEG,
46 MTYPE_AS_STR,
47 MTYPE_AS_PATH,
48 MTYPE_CLUSTER,
49 MTYPE_CLUSTER_VAL,
50 MTYPE_ATTR,
51 MTYPE_TRANSIT,
52 MTYPE_TRANSIT_VAL,
53 MTYPE_BUFFER,
54 MTYPE_BUFFER_DATA,
55 MTYPE_STREAM,
56 MTYPE_STREAM_DATA,
57 MTYPE_STREAM_FIFO,
58 MTYPE_PREFIX,
59 MTYPE_PREFIX_IPV4,
60 MTYPE_PREFIX_IPV6,
61 MTYPE_HASH,
62 MTYPE_HASH_INDEX,
63 MTYPE_HASH_BACKET,
paul718e3742002-12-13 20:15:29 +000064 MTYPE_ROUTE_TABLE,
65 MTYPE_ROUTE_NODE,
66 MTYPE_ACCESS_LIST,
67 MTYPE_ACCESS_LIST_STR,
68 MTYPE_ACCESS_FILTER,
69 MTYPE_PREFIX_LIST,
70 MTYPE_PREFIX_LIST_STR,
71 MTYPE_PREFIX_LIST_ENTRY,
72 MTYPE_ROUTE_MAP,
73 MTYPE_ROUTE_MAP_NAME,
74 MTYPE_ROUTE_MAP_INDEX,
75 MTYPE_ROUTE_MAP_RULE,
76 MTYPE_ROUTE_MAP_RULE_STR,
77 MTYPE_ROUTE_MAP_COMPILED,
78
79 MTYPE_RIB,
paul9035efa2004-10-10 11:56:56 +000080
paul718e3742002-12-13 20:15:29 +000081 MTYPE_DISTRIBUTE,
paul9035efa2004-10-10 11:56:56 +000082 MTYPE_DISTRIBUTE_IFNAME,
paul718e3742002-12-13 20:15:29 +000083 MTYPE_ZLOG,
84 MTYPE_ZCLIENT,
85 MTYPE_NEXTHOP,
86 MTYPE_RTADV_PREFIX,
87 MTYPE_IF_RMAP,
88 MTYPE_SOCKUNION,
89 MTYPE_STATIC_IPV4,
90 MTYPE_STATIC_IPV6,
91
92 MTYPE_DESC,
93 MTYPE_OSPF_TOP,
94 MTYPE_OSPF_AREA,
95 MTYPE_OSPF_AREA_RANGE,
96 MTYPE_OSPF_NETWORK,
97 MTYPE_OSPF_NEIGHBOR_STATIC,
98 MTYPE_OSPF_IF,
99 MTYPE_OSPF_NEIGHBOR,
100 MTYPE_OSPF_ROUTE,
101 MTYPE_OSPF_TMP,
102 MTYPE_OSPF_LSA,
103 MTYPE_OSPF_LSA_DATA,
104 MTYPE_OSPF_LSDB,
105 MTYPE_OSPF_PACKET,
106 MTYPE_OSPF_FIFO,
107 MTYPE_OSPF_VERTEX,
108 MTYPE_OSPF_NEXTHOP,
109 MTYPE_OSPF_PATH,
110 MTYPE_OSPF_VL_DATA,
111 MTYPE_OSPF_CRYPT_KEY,
112 MTYPE_OSPF_EXTERNAL_INFO,
113 MTYPE_OSPF_MESSAGE,
114 MTYPE_OSPF_DISTANCE,
115 MTYPE_OSPF_IF_INFO,
116 MTYPE_OSPF_IF_PARAMS,
117
118 MTYPE_OSPF6_TOP,
119 MTYPE_OSPF6_AREA,
120 MTYPE_OSPF6_IF,
121 MTYPE_OSPF6_NEIGHBOR,
122 MTYPE_OSPF6_ROUTE,
123 MTYPE_OSPF6_PREFIX,
124 MTYPE_OSPF6_MESSAGE,
125 MTYPE_OSPF6_LSA,
126 MTYPE_OSPF6_LSA_SUMMARY,
127 MTYPE_OSPF6_LSDB,
128 MTYPE_OSPF6_VERTEX,
129 MTYPE_OSPF6_SPFTREE,
130 MTYPE_OSPF6_NEXTHOP,
131 MTYPE_OSPF6_EXTERNAL_INFO,
132 MTYPE_OSPF6_OTHER,
133
jardin9e867fe2003-12-23 08:56:18 +0000134
135 MTYPE_ISIS,
136 MTYPE_ISIS_TMP,
137 MTYPE_ISIS_CIRCUIT,
138 MTYPE_ISIS_LSP,
139 MTYPE_ISIS_ADJACENCY,
140 MTYPE_ISIS_AREA,
141 MTYPE_ISIS_AREA_ADDR,
142 MTYPE_ISIS_TLV,
143 MTYPE_ISIS_DYNHN,
144 MTYPE_ISIS_SPFTREE,
145 MTYPE_ISIS_VERTEX,
146 MTYPE_ISIS_ROUTE_INFO,
147 MTYPE_ISIS_NEXTHOP,
148 MTYPE_ISIS_NEXTHOP6,
149
paul718e3742002-12-13 20:15:29 +0000150 MTYPE_BGP,
151 MTYPE_BGP_PEER,
152 MTYPE_PEER_GROUP,
153 MTYPE_PEER_DESC,
154 MTYPE_PEER_UPDATE_SOURCE,
155 MTYPE_BGP_STATIC,
156 MTYPE_BGP_AGGREGATE,
157 MTYPE_BGP_CONFED_LIST,
158 MTYPE_BGP_NEXTHOP_CACHE,
159 MTYPE_BGP_DAMP_INFO,
160 MTYPE_BGP_DAMP_ARRAY,
161 MTYPE_BGP_ANNOUNCE,
162 MTYPE_BGP_ATTR_QUEUE,
163 MTYPE_BGP_ROUTE_QUEUE,
164 MTYPE_BGP_DISTANCE,
165 MTYPE_BGP_ROUTE,
166 MTYPE_BGP_TABLE,
167 MTYPE_BGP_NODE,
168 MTYPE_BGP_ADVERTISE_ATTR,
169 MTYPE_BGP_ADVERTISE,
170 MTYPE_BGP_ADJ_IN,
171 MTYPE_BGP_ADJ_OUT,
172 MTYPE_BGP_REGEXP,
173 MTYPE_AS_FILTER,
174 MTYPE_AS_FILTER_STR,
175 MTYPE_AS_LIST,
176
177 MTYPE_COMMUNITY,
178 MTYPE_COMMUNITY_VAL,
179 MTYPE_COMMUNITY_STR,
180
181 MTYPE_ECOMMUNITY,
182 MTYPE_ECOMMUNITY_VAL,
183 MTYPE_ECOMMUNITY_STR,
184
185 /* community-list and extcommunity-list. */
186 MTYPE_COMMUNITY_LIST_HANDLER,
187 MTYPE_COMMUNITY_LIST,
188 MTYPE_COMMUNITY_LIST_NAME,
189 MTYPE_COMMUNITY_LIST_ENTRY,
190 MTYPE_COMMUNITY_LIST_CONFIG,
191
192 MTYPE_RIP,
193 MTYPE_RIP_INTERFACE,
194 MTYPE_RIP_DISTANCE,
195 MTYPE_RIP_OFFSET_LIST,
196 MTYPE_RIP_INFO,
197 MTYPE_RIP_PEER,
198 MTYPE_KEYCHAIN,
199 MTYPE_KEY,
200
hassoa94434b2003-05-25 17:10:12 +0000201 MTYPE_RIPNG,
202 MTYPE_RIPNG_ROUTE,
203 MTYPE_RIPNG_AGGREGATE,
204 MTYPE_RIPNG_PEER,
205 MTYPE_RIPNG_OFFSET_LIST,
206 MTYPE_RIPNG_RTE_DATA,
207
paul718e3742002-12-13 20:15:29 +0000208 MTYPE_VTYSH_CONFIG,
209 MTYPE_VTYSH_CONFIG_LINE,
210
211 MTYPE_VRF,
212 MTYPE_VRF_NAME,
pauledd7c242003-06-04 13:59:38 +0000213
214 MTYPE_PRIVS,
paul718e3742002-12-13 20:15:29 +0000215
216 MTYPE_MAX
217};
218
219#ifdef MEMORY_LOG
220#define XMALLOC(mtype, size) \
221 mtype_zmalloc (__FILE__, __LINE__, (mtype), (size))
222#define XCALLOC(mtype, size) \
223 mtype_zcalloc (__FILE__, __LINE__, (mtype), (size))
224#define XREALLOC(mtype, ptr, size) \
225 mtype_zrealloc (__FILE__, __LINE__, (mtype), (ptr), (size))
226#define XFREE(mtype, ptr) \
227 mtype_zfree (__FILE__, __LINE__, (mtype), (ptr))
228#define XSTRDUP(mtype, str) \
229 mtype_zstrdup (__FILE__, __LINE__, (mtype), (str))
230#else
231#define XMALLOC(mtype, size) zmalloc ((mtype), (size))
232#define XCALLOC(mtype, size) zcalloc ((mtype), (size))
233#define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size))
234#define XFREE(mtype, ptr) zfree ((mtype), (ptr))
235#define XSTRDUP(mtype, str) zstrdup ((mtype), (str))
236#endif /* MEMORY_LOG */
237
238/* Prototypes of memory function. */
239void *zmalloc (int type, size_t size);
240void *zcalloc (int type, size_t size);
241void *zrealloc (int type, void *ptr, size_t size);
242void zfree (int type, void *ptr);
hassob04c6992004-10-04 19:10:31 +0000243char *zstrdup (int type, const char *str);
paul718e3742002-12-13 20:15:29 +0000244
245void *mtype_zmalloc (const char *file,
246 int line,
247 int type,
248 size_t size);
249
250void *mtype_zcalloc (const char *file,
251 int line,
252 int type,
253 size_t num,
254 size_t size);
255
256void *mtype_zrealloc (const char *file,
257 int line,
258 int type,
259 void *ptr,
260 size_t size);
261
262void mtype_zfree (const char *file,
263 int line,
264 int type,
265 void *ptr);
266
267char *mtype_zstrdup (const char *file,
268 int line,
269 int type,
hassob04c6992004-10-04 19:10:31 +0000270 const char *str);
paul718e3742002-12-13 20:15:29 +0000271void memory_init ();
272
273#endif /* _ZEBRA_MEMORY_H */