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