blob: a38cda3f3d3f487066335813b352f51212f24c4d [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
129 MTYPE_BGP,
130 MTYPE_BGP_PEER,
131 MTYPE_PEER_GROUP,
132 MTYPE_PEER_DESC,
133 MTYPE_PEER_UPDATE_SOURCE,
134 MTYPE_BGP_STATIC,
135 MTYPE_BGP_AGGREGATE,
136 MTYPE_BGP_CONFED_LIST,
137 MTYPE_BGP_NEXTHOP_CACHE,
138 MTYPE_BGP_DAMP_INFO,
139 MTYPE_BGP_DAMP_ARRAY,
140 MTYPE_BGP_ANNOUNCE,
141 MTYPE_BGP_ATTR_QUEUE,
142 MTYPE_BGP_ROUTE_QUEUE,
143 MTYPE_BGP_DISTANCE,
144 MTYPE_BGP_ROUTE,
145 MTYPE_BGP_TABLE,
146 MTYPE_BGP_NODE,
147 MTYPE_BGP_ADVERTISE_ATTR,
148 MTYPE_BGP_ADVERTISE,
149 MTYPE_BGP_ADJ_IN,
150 MTYPE_BGP_ADJ_OUT,
151 MTYPE_BGP_REGEXP,
152 MTYPE_AS_FILTER,
153 MTYPE_AS_FILTER_STR,
154 MTYPE_AS_LIST,
155
156 MTYPE_COMMUNITY,
157 MTYPE_COMMUNITY_VAL,
158 MTYPE_COMMUNITY_STR,
159
160 MTYPE_ECOMMUNITY,
161 MTYPE_ECOMMUNITY_VAL,
162 MTYPE_ECOMMUNITY_STR,
163
164 /* community-list and extcommunity-list. */
165 MTYPE_COMMUNITY_LIST_HANDLER,
166 MTYPE_COMMUNITY_LIST,
167 MTYPE_COMMUNITY_LIST_NAME,
168 MTYPE_COMMUNITY_LIST_ENTRY,
169 MTYPE_COMMUNITY_LIST_CONFIG,
170
171 MTYPE_RIP,
172 MTYPE_RIP_INTERFACE,
173 MTYPE_RIP_DISTANCE,
174 MTYPE_RIP_OFFSET_LIST,
175 MTYPE_RIP_INFO,
176 MTYPE_RIP_PEER,
177 MTYPE_KEYCHAIN,
178 MTYPE_KEY,
179
hassoa94434b2003-05-25 17:10:12 +0000180 MTYPE_RIPNG,
181 MTYPE_RIPNG_ROUTE,
182 MTYPE_RIPNG_AGGREGATE,
183 MTYPE_RIPNG_PEER,
184 MTYPE_RIPNG_OFFSET_LIST,
185 MTYPE_RIPNG_RTE_DATA,
186
paul718e3742002-12-13 20:15:29 +0000187 MTYPE_VTYSH_CONFIG,
188 MTYPE_VTYSH_CONFIG_LINE,
189
190 MTYPE_VRF,
191 MTYPE_VRF_NAME,
192
193 MTYPE_MAX
194};
195
196#ifdef MEMORY_LOG
197#define XMALLOC(mtype, size) \
198 mtype_zmalloc (__FILE__, __LINE__, (mtype), (size))
199#define XCALLOC(mtype, size) \
200 mtype_zcalloc (__FILE__, __LINE__, (mtype), (size))
201#define XREALLOC(mtype, ptr, size) \
202 mtype_zrealloc (__FILE__, __LINE__, (mtype), (ptr), (size))
203#define XFREE(mtype, ptr) \
204 mtype_zfree (__FILE__, __LINE__, (mtype), (ptr))
205#define XSTRDUP(mtype, str) \
206 mtype_zstrdup (__FILE__, __LINE__, (mtype), (str))
207#else
208#define XMALLOC(mtype, size) zmalloc ((mtype), (size))
209#define XCALLOC(mtype, size) zcalloc ((mtype), (size))
210#define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size))
211#define XFREE(mtype, ptr) zfree ((mtype), (ptr))
212#define XSTRDUP(mtype, str) zstrdup ((mtype), (str))
213#endif /* MEMORY_LOG */
214
215/* Prototypes of memory function. */
216void *zmalloc (int type, size_t size);
217void *zcalloc (int type, size_t size);
218void *zrealloc (int type, void *ptr, size_t size);
219void zfree (int type, void *ptr);
220char *zstrdup (int type, char *str);
221
222void *mtype_zmalloc (const char *file,
223 int line,
224 int type,
225 size_t size);
226
227void *mtype_zcalloc (const char *file,
228 int line,
229 int type,
230 size_t num,
231 size_t size);
232
233void *mtype_zrealloc (const char *file,
234 int line,
235 int type,
236 void *ptr,
237 size_t size);
238
239void mtype_zfree (const char *file,
240 int line,
241 int type,
242 void *ptr);
243
244char *mtype_zstrdup (const char *file,
245 int line,
246 int type,
247 char *str);
248void memory_init ();
249
250#endif /* _ZEBRA_MEMORY_H */