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