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