paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Memory management routine |
| 2 | Copyright (C) 1998 Kunihiro Ishiguro |
| 3 | |
| 4 | This file is part of GNU Zebra. |
| 5 | |
| 6 | GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | under the terms of the GNU General Public License as published by the |
| 8 | Free Software Foundation; either version 2, or (at your option) any |
| 9 | later version. |
| 10 | |
| 11 | GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | 02111-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. */ |
| 27 | enum |
| 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, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 41 | MTYPE_IF_IRDP, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 42 | 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, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 62 | 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, |
| 78 | MTYPE_DISTRIBUTE, |
| 79 | MTYPE_ZLOG, |
| 80 | MTYPE_ZCLIENT, |
| 81 | MTYPE_NEXTHOP, |
| 82 | MTYPE_RTADV_PREFIX, |
| 83 | MTYPE_IF_RMAP, |
| 84 | MTYPE_SOCKUNION, |
| 85 | MTYPE_STATIC_IPV4, |
| 86 | MTYPE_STATIC_IPV6, |
| 87 | |
| 88 | MTYPE_DESC, |
| 89 | MTYPE_OSPF_TOP, |
| 90 | MTYPE_OSPF_AREA, |
| 91 | MTYPE_OSPF_AREA_RANGE, |
| 92 | MTYPE_OSPF_NETWORK, |
| 93 | MTYPE_OSPF_NEIGHBOR_STATIC, |
| 94 | MTYPE_OSPF_IF, |
| 95 | MTYPE_OSPF_NEIGHBOR, |
| 96 | MTYPE_OSPF_ROUTE, |
| 97 | MTYPE_OSPF_TMP, |
| 98 | MTYPE_OSPF_LSA, |
| 99 | MTYPE_OSPF_LSA_DATA, |
| 100 | MTYPE_OSPF_LSDB, |
| 101 | MTYPE_OSPF_PACKET, |
| 102 | MTYPE_OSPF_FIFO, |
| 103 | MTYPE_OSPF_VERTEX, |
| 104 | MTYPE_OSPF_NEXTHOP, |
| 105 | MTYPE_OSPF_PATH, |
| 106 | MTYPE_OSPF_VL_DATA, |
| 107 | MTYPE_OSPF_CRYPT_KEY, |
| 108 | MTYPE_OSPF_EXTERNAL_INFO, |
| 109 | MTYPE_OSPF_MESSAGE, |
| 110 | MTYPE_OSPF_DISTANCE, |
| 111 | MTYPE_OSPF_IF_INFO, |
| 112 | MTYPE_OSPF_IF_PARAMS, |
| 113 | |
| 114 | MTYPE_OSPF6_TOP, |
| 115 | MTYPE_OSPF6_AREA, |
| 116 | MTYPE_OSPF6_IF, |
| 117 | MTYPE_OSPF6_NEIGHBOR, |
| 118 | MTYPE_OSPF6_ROUTE, |
| 119 | MTYPE_OSPF6_PREFIX, |
| 120 | MTYPE_OSPF6_MESSAGE, |
| 121 | MTYPE_OSPF6_LSA, |
| 122 | MTYPE_OSPF6_LSA_SUMMARY, |
| 123 | MTYPE_OSPF6_LSDB, |
| 124 | MTYPE_OSPF6_VERTEX, |
| 125 | MTYPE_OSPF6_SPFTREE, |
| 126 | MTYPE_OSPF6_NEXTHOP, |
| 127 | MTYPE_OSPF6_EXTERNAL_INFO, |
| 128 | MTYPE_OSPF6_OTHER, |
| 129 | |
jardin | 9e867fe | 2003-12-23 08:56:18 +0000 | [diff] [blame] | 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 197 | MTYPE_RIPNG, |
| 198 | MTYPE_RIPNG_ROUTE, |
| 199 | MTYPE_RIPNG_AGGREGATE, |
| 200 | MTYPE_RIPNG_PEER, |
| 201 | MTYPE_RIPNG_OFFSET_LIST, |
| 202 | MTYPE_RIPNG_RTE_DATA, |
| 203 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 204 | MTYPE_VTYSH_CONFIG, |
| 205 | MTYPE_VTYSH_CONFIG_LINE, |
| 206 | |
| 207 | MTYPE_VRF, |
| 208 | MTYPE_VRF_NAME, |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 209 | |
| 210 | MTYPE_PRIVS, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 211 | |
| 212 | MTYPE_MAX |
| 213 | }; |
| 214 | |
| 215 | #ifdef MEMORY_LOG |
| 216 | #define XMALLOC(mtype, size) \ |
| 217 | mtype_zmalloc (__FILE__, __LINE__, (mtype), (size)) |
| 218 | #define XCALLOC(mtype, size) \ |
| 219 | mtype_zcalloc (__FILE__, __LINE__, (mtype), (size)) |
| 220 | #define XREALLOC(mtype, ptr, size) \ |
| 221 | mtype_zrealloc (__FILE__, __LINE__, (mtype), (ptr), (size)) |
| 222 | #define XFREE(mtype, ptr) \ |
| 223 | mtype_zfree (__FILE__, __LINE__, (mtype), (ptr)) |
| 224 | #define XSTRDUP(mtype, str) \ |
| 225 | mtype_zstrdup (__FILE__, __LINE__, (mtype), (str)) |
| 226 | #else |
| 227 | #define XMALLOC(mtype, size) zmalloc ((mtype), (size)) |
| 228 | #define XCALLOC(mtype, size) zcalloc ((mtype), (size)) |
| 229 | #define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size)) |
| 230 | #define XFREE(mtype, ptr) zfree ((mtype), (ptr)) |
| 231 | #define XSTRDUP(mtype, str) zstrdup ((mtype), (str)) |
| 232 | #endif /* MEMORY_LOG */ |
| 233 | |
| 234 | /* Prototypes of memory function. */ |
| 235 | void *zmalloc (int type, size_t size); |
| 236 | void *zcalloc (int type, size_t size); |
| 237 | void *zrealloc (int type, void *ptr, size_t size); |
| 238 | void zfree (int type, void *ptr); |
hasso | b04c699 | 2004-10-04 19:10:31 +0000 | [diff] [blame^] | 239 | char *zstrdup (int type, const char *str); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 240 | |
| 241 | void *mtype_zmalloc (const char *file, |
| 242 | int line, |
| 243 | int type, |
| 244 | size_t size); |
| 245 | |
| 246 | void *mtype_zcalloc (const char *file, |
| 247 | int line, |
| 248 | int type, |
| 249 | size_t num, |
| 250 | size_t size); |
| 251 | |
| 252 | void *mtype_zrealloc (const char *file, |
| 253 | int line, |
| 254 | int type, |
| 255 | void *ptr, |
| 256 | size_t size); |
| 257 | |
| 258 | void mtype_zfree (const char *file, |
| 259 | int line, |
| 260 | int type, |
| 261 | void *ptr); |
| 262 | |
| 263 | char *mtype_zstrdup (const char *file, |
| 264 | int line, |
| 265 | int type, |
hasso | b04c699 | 2004-10-04 19:10:31 +0000 | [diff] [blame^] | 266 | const char *str); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 267 | void memory_init (); |
| 268 | |
| 269 | #endif /* _ZEBRA_MEMORY_H */ |