blob: 2f403a145f3af53b9c1c0972e3d63704be794451 [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,
37 MTYPE_VTY,
38 MTYPE_VTY_HIST,
39 MTYPE_VTY_OUT_BUF,
40 MTYPE_IF,
hassoca776982004-06-12 14:33:05 +000041 MTYPE_IF_IRDP,
paul718e3742002-12-13 20:15:29 +000042 MTYPE_CONNECTED,
43 MTYPE_AS_SEG,
44 MTYPE_AS_STR,
45 MTYPE_AS_PATH,
46 MTYPE_CLUSTER,
47 MTYPE_CLUSTER_VAL,
48 MTYPE_ATTR,
49 MTYPE_TRANSIT,
50 MTYPE_TRANSIT_VAL,
51 MTYPE_BUFFER,
52 MTYPE_BUFFER_DATA,
53 MTYPE_STREAM,
54 MTYPE_STREAM_DATA,
55 MTYPE_STREAM_FIFO,
56 MTYPE_PREFIX,
57 MTYPE_PREFIX_IPV4,
58 MTYPE_PREFIX_IPV6,
59 MTYPE_HASH,
60 MTYPE_HASH_INDEX,
61 MTYPE_HASH_BACKET,
paul718e3742002-12-13 20:15:29 +000062 MTYPE_ROUTE_TABLE,
63 MTYPE_ROUTE_NODE,
64 MTYPE_ACCESS_LIST,
65 MTYPE_ACCESS_LIST_STR,
66 MTYPE_ACCESS_FILTER,
67 MTYPE_PREFIX_LIST,
68 MTYPE_PREFIX_LIST_STR,
69 MTYPE_PREFIX_LIST_ENTRY,
70 MTYPE_ROUTE_MAP,
71 MTYPE_ROUTE_MAP_NAME,
72 MTYPE_ROUTE_MAP_INDEX,
73 MTYPE_ROUTE_MAP_RULE,
74 MTYPE_ROUTE_MAP_RULE_STR,
75 MTYPE_ROUTE_MAP_COMPILED,
76
77 MTYPE_RIB,
paul9035efa2004-10-10 11:56:56 +000078
paul718e3742002-12-13 20:15:29 +000079 MTYPE_DISTRIBUTE,
paul9035efa2004-10-10 11:56:56 +000080 MTYPE_DISTRIBUTE_IFNAME,
paul718e3742002-12-13 20:15:29 +000081 MTYPE_ZLOG,
82 MTYPE_ZCLIENT,
83 MTYPE_NEXTHOP,
84 MTYPE_RTADV_PREFIX,
85 MTYPE_IF_RMAP,
86 MTYPE_SOCKUNION,
87 MTYPE_STATIC_IPV4,
88 MTYPE_STATIC_IPV6,
89
90 MTYPE_DESC,
91 MTYPE_OSPF_TOP,
92 MTYPE_OSPF_AREA,
93 MTYPE_OSPF_AREA_RANGE,
94 MTYPE_OSPF_NETWORK,
95 MTYPE_OSPF_NEIGHBOR_STATIC,
96 MTYPE_OSPF_IF,
97 MTYPE_OSPF_NEIGHBOR,
98 MTYPE_OSPF_ROUTE,
99 MTYPE_OSPF_TMP,
100 MTYPE_OSPF_LSA,
101 MTYPE_OSPF_LSA_DATA,
102 MTYPE_OSPF_LSDB,
103 MTYPE_OSPF_PACKET,
104 MTYPE_OSPF_FIFO,
105 MTYPE_OSPF_VERTEX,
106 MTYPE_OSPF_NEXTHOP,
107 MTYPE_OSPF_PATH,
108 MTYPE_OSPF_VL_DATA,
109 MTYPE_OSPF_CRYPT_KEY,
110 MTYPE_OSPF_EXTERNAL_INFO,
111 MTYPE_OSPF_MESSAGE,
112 MTYPE_OSPF_DISTANCE,
113 MTYPE_OSPF_IF_INFO,
114 MTYPE_OSPF_IF_PARAMS,
115
116 MTYPE_OSPF6_TOP,
117 MTYPE_OSPF6_AREA,
118 MTYPE_OSPF6_IF,
119 MTYPE_OSPF6_NEIGHBOR,
120 MTYPE_OSPF6_ROUTE,
121 MTYPE_OSPF6_PREFIX,
122 MTYPE_OSPF6_MESSAGE,
123 MTYPE_OSPF6_LSA,
124 MTYPE_OSPF6_LSA_SUMMARY,
125 MTYPE_OSPF6_LSDB,
126 MTYPE_OSPF6_VERTEX,
127 MTYPE_OSPF6_SPFTREE,
128 MTYPE_OSPF6_NEXTHOP,
129 MTYPE_OSPF6_EXTERNAL_INFO,
130 MTYPE_OSPF6_OTHER,
131
jardin9e867fe2003-12-23 08:56:18 +0000132
133 MTYPE_ISIS,
134 MTYPE_ISIS_TMP,
135 MTYPE_ISIS_CIRCUIT,
136 MTYPE_ISIS_LSP,
137 MTYPE_ISIS_ADJACENCY,
138 MTYPE_ISIS_AREA,
139 MTYPE_ISIS_AREA_ADDR,
140 MTYPE_ISIS_TLV,
141 MTYPE_ISIS_DYNHN,
142 MTYPE_ISIS_SPFTREE,
143 MTYPE_ISIS_VERTEX,
144 MTYPE_ISIS_ROUTE_INFO,
145 MTYPE_ISIS_NEXTHOP,
146 MTYPE_ISIS_NEXTHOP6,
147
paul718e3742002-12-13 20:15:29 +0000148 MTYPE_BGP,
149 MTYPE_BGP_PEER,
150 MTYPE_PEER_GROUP,
151 MTYPE_PEER_DESC,
152 MTYPE_PEER_UPDATE_SOURCE,
153 MTYPE_BGP_STATIC,
154 MTYPE_BGP_AGGREGATE,
155 MTYPE_BGP_CONFED_LIST,
156 MTYPE_BGP_NEXTHOP_CACHE,
157 MTYPE_BGP_DAMP_INFO,
158 MTYPE_BGP_DAMP_ARRAY,
159 MTYPE_BGP_ANNOUNCE,
160 MTYPE_BGP_ATTR_QUEUE,
161 MTYPE_BGP_ROUTE_QUEUE,
162 MTYPE_BGP_DISTANCE,
163 MTYPE_BGP_ROUTE,
164 MTYPE_BGP_TABLE,
165 MTYPE_BGP_NODE,
166 MTYPE_BGP_ADVERTISE_ATTR,
167 MTYPE_BGP_ADVERTISE,
168 MTYPE_BGP_ADJ_IN,
169 MTYPE_BGP_ADJ_OUT,
170 MTYPE_BGP_REGEXP,
171 MTYPE_AS_FILTER,
172 MTYPE_AS_FILTER_STR,
173 MTYPE_AS_LIST,
174
175 MTYPE_COMMUNITY,
176 MTYPE_COMMUNITY_VAL,
177 MTYPE_COMMUNITY_STR,
178
179 MTYPE_ECOMMUNITY,
180 MTYPE_ECOMMUNITY_VAL,
181 MTYPE_ECOMMUNITY_STR,
182
183 /* community-list and extcommunity-list. */
184 MTYPE_COMMUNITY_LIST_HANDLER,
185 MTYPE_COMMUNITY_LIST,
186 MTYPE_COMMUNITY_LIST_NAME,
187 MTYPE_COMMUNITY_LIST_ENTRY,
188 MTYPE_COMMUNITY_LIST_CONFIG,
189
190 MTYPE_RIP,
191 MTYPE_RIP_INTERFACE,
192 MTYPE_RIP_DISTANCE,
193 MTYPE_RIP_OFFSET_LIST,
194 MTYPE_RIP_INFO,
195 MTYPE_RIP_PEER,
196 MTYPE_KEYCHAIN,
197 MTYPE_KEY,
198
hassoa94434b2003-05-25 17:10:12 +0000199 MTYPE_RIPNG,
200 MTYPE_RIPNG_ROUTE,
201 MTYPE_RIPNG_AGGREGATE,
202 MTYPE_RIPNG_PEER,
203 MTYPE_RIPNG_OFFSET_LIST,
204 MTYPE_RIPNG_RTE_DATA,
205
paul718e3742002-12-13 20:15:29 +0000206 MTYPE_VTYSH_CONFIG,
207 MTYPE_VTYSH_CONFIG_LINE,
208
209 MTYPE_VRF,
210 MTYPE_VRF_NAME,
pauledd7c242003-06-04 13:59:38 +0000211
212 MTYPE_PRIVS,
paul718e3742002-12-13 20:15:29 +0000213
214 MTYPE_MAX
215};
216
217#ifdef MEMORY_LOG
218#define XMALLOC(mtype, size) \
219 mtype_zmalloc (__FILE__, __LINE__, (mtype), (size))
220#define XCALLOC(mtype, size) \
221 mtype_zcalloc (__FILE__, __LINE__, (mtype), (size))
222#define XREALLOC(mtype, ptr, size) \
223 mtype_zrealloc (__FILE__, __LINE__, (mtype), (ptr), (size))
224#define XFREE(mtype, ptr) \
225 mtype_zfree (__FILE__, __LINE__, (mtype), (ptr))
226#define XSTRDUP(mtype, str) \
227 mtype_zstrdup (__FILE__, __LINE__, (mtype), (str))
228#else
229#define XMALLOC(mtype, size) zmalloc ((mtype), (size))
230#define XCALLOC(mtype, size) zcalloc ((mtype), (size))
231#define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size))
232#define XFREE(mtype, ptr) zfree ((mtype), (ptr))
233#define XSTRDUP(mtype, str) zstrdup ((mtype), (str))
234#endif /* MEMORY_LOG */
235
236/* Prototypes of memory function. */
237void *zmalloc (int type, size_t size);
238void *zcalloc (int type, size_t size);
239void *zrealloc (int type, void *ptr, size_t size);
240void zfree (int type, void *ptr);
hassob04c6992004-10-04 19:10:31 +0000241char *zstrdup (int type, const char *str);
paul718e3742002-12-13 20:15:29 +0000242
243void *mtype_zmalloc (const char *file,
244 int line,
245 int type,
246 size_t size);
247
248void *mtype_zcalloc (const char *file,
249 int line,
250 int type,
251 size_t num,
252 size_t size);
253
254void *mtype_zrealloc (const char *file,
255 int line,
256 int type,
257 void *ptr,
258 size_t size);
259
260void mtype_zfree (const char *file,
261 int line,
262 int type,
263 void *ptr);
264
265char *mtype_zstrdup (const char *file,
266 int line,
267 int type,
hassob04c6992004-10-04 19:10:31 +0000268 const char *str);
paul718e3742002-12-13 20:15:29 +0000269void memory_init ();
270
271#endif /* _ZEBRA_MEMORY_H */