jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * IS-IS Rout(e)ing protocol - isis_tlv.c |
| 3 | * IS-IS TLV related routines |
| 4 | * |
| 5 | * Copyright (C) 2001,2002 Sampo Saaristo |
| 6 | * Tampere University of Technology |
| 7 | * Institute of Communications Engineering |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public Licenseas published by the Free |
| 11 | * Software Foundation; either version 2 of the License, or (at your option) |
| 12 | * any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful,but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <zebra.h> |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 25 | |
| 26 | #include "log.h" |
| 27 | #include "linklist.h" |
| 28 | #include "stream.h" |
| 29 | #include "memory.h" |
| 30 | #include "prefix.h" |
| 31 | #include "vty.h" |
| 32 | #include "if.h" |
| 33 | |
| 34 | #include "isisd/dict.h" |
| 35 | #include "isisd/isis_constants.h" |
| 36 | #include "isisd/isis_common.h" |
| 37 | #include "isisd/isis_flags.h" |
| 38 | #include "isisd/isis_circuit.h" |
| 39 | #include "isisd/isis_tlv.h" |
| 40 | #include "isisd/isisd.h" |
| 41 | #include "isisd/isis_dynhn.h" |
| 42 | #include "isisd/isis_misc.h" |
| 43 | #include "isisd/isis_pdu.h" |
| 44 | #include "isisd/isis_lsp.h" |
| 45 | |
| 46 | extern struct isis *isis; |
| 47 | |
| 48 | void |
| 49 | free_tlv (void *val) |
| 50 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 51 | XFREE (MTYPE_ISIS_TLV, val); |
| 52 | |
| 53 | return; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /* |
| 57 | * Called after parsing of a PDU. There shouldn't be any tlv's left, so this |
| 58 | * is only a caution to avoid memory leaks |
| 59 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 60 | void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 61 | free_tlvs (struct tlvs *tlvs) |
| 62 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 63 | if (tlvs->area_addrs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 64 | list_delete (tlvs->area_addrs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 65 | if (tlvs->is_neighs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 66 | list_delete (tlvs->is_neighs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 67 | if (tlvs->te_is_neighs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 68 | list_delete (tlvs->te_is_neighs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 69 | if (tlvs->es_neighs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 70 | list_delete (tlvs->es_neighs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 71 | if (tlvs->lsp_entries) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 72 | list_delete (tlvs->lsp_entries); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 73 | if (tlvs->lan_neighs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 74 | list_delete (tlvs->lan_neighs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 75 | if (tlvs->prefix_neighs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 76 | list_delete (tlvs->prefix_neighs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 77 | if (tlvs->ipv4_addrs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 78 | list_delete (tlvs->ipv4_addrs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 79 | if (tlvs->ipv4_int_reachs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 80 | list_delete (tlvs->ipv4_int_reachs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 81 | if (tlvs->ipv4_ext_reachs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 82 | list_delete (tlvs->ipv4_ext_reachs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 83 | if (tlvs->te_ipv4_reachs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 84 | list_delete (tlvs->te_ipv4_reachs); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 85 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 86 | if (tlvs->ipv6_addrs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 87 | list_delete (tlvs->ipv6_addrs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 88 | if (tlvs->ipv6_reachs) |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 89 | list_delete (tlvs->ipv6_reachs); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 90 | #endif /* HAVE_IPV6 */ |
hasso | aac372f | 2005-09-01 17:52:33 +0000 | [diff] [blame] | 91 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 92 | return; |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * Parses the tlvs found in the variant length part of the PDU. |
| 97 | * Caller tells with flags in "expected" which TLV's it is interested in. |
| 98 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 99 | int |
| 100 | parse_tlvs (char *areatag, u_char * stream, int size, u_int32_t * expected, |
| 101 | u_int32_t * found, struct tlvs *tlvs) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 102 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 103 | u_char type, length; |
| 104 | struct lan_neigh *lan_nei; |
| 105 | struct area_addr *area_addr; |
| 106 | struct is_neigh *is_nei; |
| 107 | struct te_is_neigh *te_is_nei; |
| 108 | struct es_neigh *es_nei; |
| 109 | struct lsp_entry *lsp_entry; |
| 110 | struct in_addr *ipv4_addr; |
| 111 | struct ipv4_reachability *ipv4_reach; |
| 112 | struct te_ipv4_reachability *te_ipv4_reach; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 113 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 114 | struct in6_addr *ipv6_addr; |
| 115 | struct ipv6_reachability *ipv6_reach; |
| 116 | int prefix_octets; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 117 | #endif /* HAVE_IPV6 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 118 | u_char virtual; |
| 119 | int value_len, retval = ISIS_OK; |
| 120 | u_char *pnt = stream; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 121 | |
| 122 | *found = 0; |
| 123 | memset (tlvs, 0, sizeof (struct tlvs)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 124 | |
| 125 | while (pnt < stream + size - 2) |
| 126 | { |
| 127 | type = *pnt; |
| 128 | length = *(pnt + 1); |
| 129 | pnt += 2; |
| 130 | value_len = 0; |
| 131 | if (pnt + length > stream + size) |
| 132 | { |
| 133 | zlog_warn ("ISIS-TLV (%s): TLV (type %d, length %d) exceeds packet " |
| 134 | "boundaries", areatag, type, length); |
| 135 | retval = ISIS_WARNING; |
| 136 | break; |
| 137 | } |
| 138 | switch (type) |
| 139 | { |
| 140 | case AREA_ADDRESSES: |
| 141 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 142 | * | Address Length | |
| 143 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 144 | * | Area Address | |
| 145 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 146 | * : : |
| 147 | */ |
| 148 | *found |= TLVFLAG_AREA_ADDRS; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 149 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 150 | zlog_debug ("TLV Area Adresses len %d", length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 151 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 152 | if (*expected & TLVFLAG_AREA_ADDRS) |
| 153 | { |
| 154 | while (length > value_len) |
| 155 | { |
| 156 | area_addr = (struct area_addr *) pnt; |
| 157 | value_len += area_addr->addr_len + 1; |
| 158 | pnt += area_addr->addr_len + 1; |
| 159 | if (!tlvs->area_addrs) |
| 160 | tlvs->area_addrs = list_new (); |
| 161 | listnode_add (tlvs->area_addrs, area_addr); |
| 162 | } |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | pnt += length; |
| 167 | } |
| 168 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 169 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 170 | case IS_NEIGHBOURS: |
| 171 | *found |= TLVFLAG_IS_NEIGHS; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 172 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 173 | zlog_debug ("ISIS-TLV (%s): IS Neighbours length %d", |
| 174 | areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 175 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 176 | if (TLVFLAG_IS_NEIGHS & *expected) |
| 177 | { |
| 178 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 179 | * | Virtual Flag | |
| 180 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 181 | */ |
| 182 | virtual = *pnt; /* FIXME: what is the use for this? */ |
| 183 | pnt++; |
| 184 | value_len++; |
| 185 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 186 | * | 0 | I/E | Default Metric | |
| 187 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 188 | * | S | I/E | Delay Metric | |
| 189 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 190 | * | S | I/E | Expense Metric | |
| 191 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 192 | * | S | I/E | Error Metric | |
| 193 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 194 | * | Neighbour ID | |
| 195 | * +---------------------------------------------------------------+ |
| 196 | * : : |
| 197 | */ |
| 198 | while (length > value_len) |
| 199 | { |
| 200 | is_nei = (struct is_neigh *) pnt; |
| 201 | value_len += 4 + ISIS_SYS_ID_LEN + 1; |
| 202 | pnt += 4 + ISIS_SYS_ID_LEN + 1; |
| 203 | if (!tlvs->is_neighs) |
| 204 | tlvs->is_neighs = list_new (); |
| 205 | listnode_add (tlvs->is_neighs, is_nei); |
| 206 | } |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | pnt += length; |
| 211 | } |
| 212 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 213 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 214 | case TE_IS_NEIGHBOURS: |
| 215 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 216 | * | Neighbour ID | 7 |
| 217 | * +---------------------------------------------------------------+ |
| 218 | * | TE Metric | 3 |
| 219 | * +---------------------------------------------------------------+ |
| 220 | * | SubTLVs Length | 1 |
| 221 | * +---------------------------------------------------------------+ |
| 222 | * : : |
| 223 | */ |
| 224 | *found |= TLVFLAG_TE_IS_NEIGHS; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 225 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 226 | zlog_debug ("ISIS-TLV (%s): Extended IS Neighbours length %d", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 227 | areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 228 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 229 | if (TLVFLAG_TE_IS_NEIGHS & *expected) |
| 230 | { |
| 231 | while (length > value_len) |
| 232 | { |
| 233 | te_is_nei = (struct te_is_neigh *) pnt; |
| 234 | value_len += 11; |
| 235 | pnt += 11; |
| 236 | /* FIXME - subtlvs are handled here, for now we skip */ |
| 237 | value_len += te_is_nei->sub_tlvs_length; |
| 238 | pnt += te_is_nei->sub_tlvs_length; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 239 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 240 | if (!tlvs->te_is_neighs) |
| 241 | tlvs->te_is_neighs = list_new (); |
| 242 | listnode_add (tlvs->te_is_neighs, te_is_nei); |
| 243 | } |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | pnt += length; |
| 248 | } |
| 249 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 250 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 251 | case ES_NEIGHBOURS: |
| 252 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 253 | * | 0 | I/E | Default Metric | |
| 254 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 255 | * | S | I/E | Delay Metric | |
| 256 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 257 | * | S | I/E | Expense Metric | |
| 258 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 259 | * | S | I/E | Error Metric | |
| 260 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 261 | * | Neighbour ID | |
| 262 | * +---------------------------------------------------------------+ |
| 263 | * | Neighbour ID | |
| 264 | * +---------------------------------------------------------------+ |
| 265 | * : : |
| 266 | */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 267 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 268 | zlog_debug ("ISIS-TLV (%s): ES Neighbours length %d", |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 269 | areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 270 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 271 | *found |= TLVFLAG_ES_NEIGHS; |
| 272 | if (*expected & TLVFLAG_ES_NEIGHS) |
| 273 | { |
| 274 | es_nei = (struct es_neigh *) pnt; |
| 275 | value_len += 4; |
| 276 | pnt += 4; |
| 277 | while (length > value_len) |
| 278 | { |
| 279 | /* FIXME FIXME FIXME - add to the list */ |
| 280 | /* sys_id->id = pnt; */ |
| 281 | value_len += ISIS_SYS_ID_LEN; |
| 282 | pnt += ISIS_SYS_ID_LEN; |
| 283 | /* if (!es_nei->neigh_ids) es_nei->neigh_ids = sysid; */ |
| 284 | } |
| 285 | if (!tlvs->es_neighs) |
| 286 | tlvs->es_neighs = list_new (); |
| 287 | listnode_add (tlvs->es_neighs, es_nei); |
| 288 | } |
| 289 | else |
| 290 | { |
| 291 | pnt += length; |
| 292 | } |
| 293 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 294 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 295 | case LAN_NEIGHBOURS: |
| 296 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 297 | * | LAN Address | |
| 298 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 299 | * : : |
| 300 | */ |
| 301 | *found |= TLVFLAG_LAN_NEIGHS; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 302 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 303 | zlog_debug ("ISIS-TLV (%s): LAN Neigbours length %d", |
| 304 | areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 305 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 306 | if (TLVFLAG_LAN_NEIGHS & *expected) |
| 307 | { |
| 308 | while (length > value_len) |
| 309 | { |
| 310 | lan_nei = (struct lan_neigh *) pnt; |
| 311 | if (!tlvs->lan_neighs) |
| 312 | tlvs->lan_neighs = list_new (); |
| 313 | listnode_add (tlvs->lan_neighs, lan_nei); |
| 314 | value_len += ETH_ALEN; |
| 315 | pnt += ETH_ALEN; |
| 316 | } |
| 317 | } |
| 318 | else |
| 319 | { |
| 320 | pnt += length; |
| 321 | } |
| 322 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 323 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 324 | case PADDING: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 325 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 326 | zlog_debug ("TLV padding %d", length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 327 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 328 | pnt += length; |
| 329 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 330 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 331 | case LSP_ENTRIES: |
| 332 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 333 | * | Remaining Lifetime | 2 |
| 334 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 335 | * | LSP ID | id+2 |
| 336 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 337 | * | LSP Sequence Number |Â 4 |
| 338 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 339 | * | Checksum | 2 |
| 340 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 341 | */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 342 | #ifdef EXTREME_TLV_DEBUG |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 343 | zlog_debug ("ISIS-TLV (%s): LSP Entries length %d", areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 344 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 345 | *found |= TLVFLAG_LSP_ENTRIES; |
| 346 | if (TLVFLAG_LSP_ENTRIES & *expected) |
| 347 | { |
| 348 | while (length > value_len) |
| 349 | { |
| 350 | lsp_entry = (struct lsp_entry *) pnt; |
| 351 | value_len += 10 + ISIS_SYS_ID_LEN; |
| 352 | pnt += 10 + ISIS_SYS_ID_LEN; |
| 353 | if (!tlvs->lsp_entries) |
| 354 | tlvs->lsp_entries = list_new (); |
| 355 | listnode_add (tlvs->lsp_entries, lsp_entry); |
| 356 | } |
| 357 | } |
| 358 | else |
| 359 | { |
| 360 | pnt += length; |
| 361 | } |
| 362 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 363 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 364 | case CHECKSUM: |
| 365 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 366 | * | 16 bit fletcher CHECKSUM | |
| 367 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 368 | * : : |
| 369 | */ |
| 370 | *found |= TLVFLAG_CHECKSUM; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 371 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 372 | zlog_debug ("ISIS-TLV (%s): Checksum length %d", areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 373 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 374 | if (*expected & TLVFLAG_CHECKSUM) |
| 375 | { |
| 376 | tlvs->checksum = (struct checksum *) pnt; |
| 377 | } |
| 378 | pnt += length; |
| 379 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 380 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 381 | case PROTOCOLS_SUPPORTED: |
| 382 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 383 | * | NLPID | |
| 384 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 385 | * : : |
| 386 | */ |
| 387 | *found |= TLVFLAG_NLPID; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 388 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 389 | zlog_debug ("ISIS-TLV (%s): Protocols Supported length %d", |
| 390 | areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 391 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 392 | if (*expected & TLVFLAG_NLPID) |
| 393 | { |
| 394 | tlvs->nlpids = (struct nlpids *) (pnt - 1); |
| 395 | } |
| 396 | pnt += length; |
| 397 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 398 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 399 | case IPV4_ADDR: |
| 400 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 401 | * + IP version 4 address + 4 |
| 402 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 403 | * : : |
| 404 | */ |
| 405 | *found |= TLVFLAG_IPV4_ADDR; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 406 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 407 | zlog_debug ("ISIS-TLV (%s): IPv4 Address length %d", |
| 408 | areatag, length); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 409 | #endif /* EXTREME_TLV_DEBUG */ |
| 410 | if (*expected & TLVFLAG_IPV4_ADDR) |
| 411 | { |
| 412 | while (length > value_len) |
| 413 | { |
| 414 | ipv4_addr = (struct in_addr *) pnt; |
hasso | f891f44 | 2004-09-14 13:54:30 +0000 | [diff] [blame] | 415 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 416 | zlog_debug ("ISIS-TLV (%s) : IP ADDR %s, pnt %p", areatag, |
| 417 | inet_ntoa (*ipv4_addr), pnt); |
hasso | f891f44 | 2004-09-14 13:54:30 +0000 | [diff] [blame] | 418 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 419 | if (!tlvs->ipv4_addrs) |
| 420 | tlvs->ipv4_addrs = list_new (); |
| 421 | listnode_add (tlvs->ipv4_addrs, ipv4_addr); |
| 422 | value_len += 4; |
| 423 | pnt += 4; |
| 424 | } |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | pnt += length; |
| 429 | } |
| 430 | break; |
| 431 | |
| 432 | case AUTH_INFO: |
| 433 | *found |= TLVFLAG_AUTH_INFO; |
| 434 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 435 | zlog_debug ("ISIS-TLV (%s): IS-IS Authentication Information", |
| 436 | areatag); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 437 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 438 | if (*expected & TLVFLAG_AUTH_INFO) |
| 439 | { |
| 440 | tlvs->auth_info.type = *pnt; |
hasso | 53c997c | 2004-09-15 16:21:59 +0000 | [diff] [blame] | 441 | tlvs->auth_info.len = length-1; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 442 | pnt++; |
| 443 | memcpy (tlvs->auth_info.passwd, pnt, length - 1); |
| 444 | pnt += length - 1; |
| 445 | } |
| 446 | else |
| 447 | { |
| 448 | pnt += length; |
| 449 | } |
| 450 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 451 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 452 | case DYNAMIC_HOSTNAME: |
| 453 | *found |= TLVFLAG_DYN_HOSTNAME; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 454 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 455 | zlog_debug ("ISIS-TLV (%s): Dynamic Hostname length %d", |
| 456 | areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 457 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 458 | if (*expected & TLVFLAG_DYN_HOSTNAME) |
| 459 | { |
| 460 | /* the length is also included in the pointed struct */ |
| 461 | tlvs->hostname = (struct hostname *) (pnt - 1); |
| 462 | } |
| 463 | pnt += length; |
| 464 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 465 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 466 | case TE_ROUTER_ID: |
| 467 | /* +---------------------------------------------------------------+ |
| 468 | * + Router ID + 4 |
| 469 | * +---------------------------------------------------------------+ |
| 470 | */ |
| 471 | *found |= TLVFLAG_TE_ROUTER_ID; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 472 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 473 | zlog_debug ("ISIS-TLV (%s): TE Router ID %d", areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 474 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 475 | if (*expected & TLVFLAG_TE_ROUTER_ID) |
hasso | 1cd8084 | 2004-10-07 20:07:40 +0000 | [diff] [blame] | 476 | tlvs->router_id = (struct te_router_id *) (pnt); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 477 | pnt += length; |
| 478 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 479 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 480 | case IPV4_INT_REACHABILITY: |
| 481 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 482 | * | 0 | I/E | Default Metric | 1 |
| 483 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 484 | * | S | I/E | Delay Metric | 1 |
| 485 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 486 | * | S | I/E | Expense Metric | 1 |
| 487 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 488 | * | S | I/E | Error Metric | 1 |
| 489 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 490 | * | ip address | 4 |
| 491 | * +---------------------------------------------------------------+ |
| 492 | * | address mask | 4 |
| 493 | * +---------------------------------------------------------------+ |
| 494 | * : : |
| 495 | */ |
| 496 | *found |= TLVFLAG_IPV4_INT_REACHABILITY; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 497 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 498 | zlog_debug ("ISIS-TLV (%s): IPv4 internal Reachability length %d", |
| 499 | areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 500 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 501 | if (*expected & TLVFLAG_IPV4_INT_REACHABILITY) |
| 502 | { |
| 503 | while (length > value_len) |
| 504 | { |
| 505 | ipv4_reach = (struct ipv4_reachability *) pnt; |
| 506 | if (!tlvs->ipv4_int_reachs) |
| 507 | tlvs->ipv4_int_reachs = list_new (); |
| 508 | listnode_add (tlvs->ipv4_int_reachs, ipv4_reach); |
| 509 | value_len += 12; |
| 510 | pnt += 12; |
| 511 | } |
| 512 | } |
| 513 | else |
| 514 | { |
| 515 | pnt += length; |
| 516 | } |
| 517 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 518 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 519 | case IPV4_EXT_REACHABILITY: |
| 520 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 521 | * | 0 | I/E | Default Metric | 1 |
| 522 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 523 | * | S | I/E | Delay Metric | 1 |
| 524 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 525 | * | S | I/E | Expense Metric | 1 |
| 526 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 527 | * | S | I/E | Error Metric | 1 |
| 528 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 529 | * | ip address | 4 |
| 530 | * +---------------------------------------------------------------+ |
| 531 | * | address mask | 4 |
| 532 | * +---------------------------------------------------------------+ |
| 533 | * : : |
| 534 | */ |
| 535 | *found |= TLVFLAG_IPV4_EXT_REACHABILITY; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 536 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 537 | zlog_debug ("ISIS-TLV (%s): IPv4 external Reachability length %d", |
| 538 | areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 539 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 540 | if (*expected & TLVFLAG_IPV4_EXT_REACHABILITY) |
| 541 | { |
| 542 | while (length > value_len) |
| 543 | { |
| 544 | ipv4_reach = (struct ipv4_reachability *) pnt; |
| 545 | if (!tlvs->ipv4_ext_reachs) |
| 546 | tlvs->ipv4_ext_reachs = list_new (); |
| 547 | listnode_add (tlvs->ipv4_ext_reachs, ipv4_reach); |
| 548 | value_len += 12; |
| 549 | pnt += 12; |
| 550 | } |
| 551 | } |
| 552 | else |
| 553 | { |
| 554 | pnt += length; |
| 555 | } |
| 556 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 557 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 558 | case TE_IPV4_REACHABILITY: |
| 559 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 560 | * | TE Metric | 4 |
| 561 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 562 | * | U/D | sTLV? | Prefix Mask Len | 1 |
| 563 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 564 | * | Prefix | 0-4 |
| 565 | * +---------------------------------------------------------------+ |
| 566 | * | sub tlvs | |
| 567 | * +---------------------------------------------------------------+ |
| 568 | * : : |
| 569 | */ |
| 570 | *found |= TLVFLAG_TE_IPV4_REACHABILITY; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 571 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 572 | zlog_debug ("ISIS-TLV (%s): IPv4 extended Reachability length %d", |
| 573 | areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 574 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 575 | if (*expected & TLVFLAG_TE_IPV4_REACHABILITY) |
| 576 | { |
| 577 | while (length > value_len) |
| 578 | { |
| 579 | te_ipv4_reach = (struct te_ipv4_reachability *) pnt; |
| 580 | if (!tlvs->te_ipv4_reachs) |
| 581 | tlvs->te_ipv4_reachs = list_new (); |
| 582 | listnode_add (tlvs->te_ipv4_reachs, te_ipv4_reach); |
| 583 | /* this trickery is permitable since no subtlvs are defined */ |
| 584 | value_len += 5 + ((te_ipv4_reach->control & 0x3F) ? |
| 585 | ((((te_ipv4_reach->control & 0x3F) - |
| 586 | 1) >> 3) + 1) : 0); |
| 587 | pnt += 5 + ((te_ipv4_reach->control & 0x3F) ? |
| 588 | ((((te_ipv4_reach->control & 0x3F) - 1) >> 3) + 1) : 0); |
| 589 | } |
| 590 | } |
| 591 | else |
| 592 | { |
| 593 | pnt += length; |
| 594 | } |
| 595 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 596 | |
| 597 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 598 | case IPV6_ADDR: |
| 599 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 600 | * + IP version 6 address + 16 |
| 601 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 602 | * : : |
| 603 | */ |
| 604 | *found |= TLVFLAG_IPV6_ADDR; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 605 | #ifdef EXTREME_TLV_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 606 | zlog_debug ("ISIS-TLV (%s): IPv6 Address length %d", |
| 607 | areatag, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 608 | #endif /* EXTREME_TLV_DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 609 | if (*expected & TLVFLAG_IPV6_ADDR) |
| 610 | { |
| 611 | while (length > value_len) |
| 612 | { |
| 613 | ipv6_addr = (struct in6_addr *) pnt; |
| 614 | if (!tlvs->ipv6_addrs) |
| 615 | tlvs->ipv6_addrs = list_new (); |
| 616 | listnode_add (tlvs->ipv6_addrs, ipv6_addr); |
| 617 | value_len += 16; |
| 618 | pnt += 16; |
| 619 | } |
| 620 | } |
| 621 | else |
| 622 | { |
| 623 | pnt += length; |
| 624 | } |
| 625 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 626 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 627 | case IPV6_REACHABILITY: |
| 628 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 629 | * | Default Metric | 4 |
| 630 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 631 | * | Control Informantion | |
| 632 | * +---------------------------------------------------------------+ |
| 633 | * | IPv6 Prefix Length |--+ |
| 634 | * +---------------------------------------------------------------+ | |
| 635 | * | IPv6 Prefix |<-+ |
| 636 | * +---------------------------------------------------------------+ |
| 637 | */ |
| 638 | *found |= TLVFLAG_IPV6_REACHABILITY; |
| 639 | if (*expected & TLVFLAG_IPV6_REACHABILITY) |
| 640 | { |
| 641 | while (length > value_len) |
| 642 | { |
| 643 | ipv6_reach = (struct ipv6_reachability *) pnt; |
| 644 | prefix_octets = ((ipv6_reach->prefix_len + 7) / 8); |
| 645 | value_len += prefix_octets + 6; |
| 646 | pnt += prefix_octets + 6; |
| 647 | /* FIXME: sub-tlvs */ |
| 648 | if (!tlvs->ipv6_reachs) |
| 649 | tlvs->ipv6_reachs = list_new (); |
| 650 | listnode_add (tlvs->ipv6_reachs, ipv6_reach); |
| 651 | } |
| 652 | } |
| 653 | else |
| 654 | { |
| 655 | pnt += length; |
| 656 | } |
| 657 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 658 | #endif /* HAVE_IPV6 */ |
| 659 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 660 | case WAY3_HELLO: |
| 661 | /* +---------------------------------------------------------------+ |
| 662 | * | Adjacency state | 1 |
| 663 | * +---------------------------------------------------------------+ |
| 664 | * | Extended Local Circuit ID | 4 |
| 665 | * +---------------------------------------------------------------+ |
| 666 | * | Neighbor System ID (If known) | 0-8 |
| 667 | * (probably 6) |
| 668 | * +---------------------------------------------------------------+ |
| 669 | * | Neighbor Local Circuit ID (If known) | 4 |
| 670 | * +---------------------------------------------------------------+ |
| 671 | */ |
| 672 | *found |= TLVFLAG_3WAY_HELLO; |
| 673 | if (*expected & TLVFLAG_3WAY_HELLO) |
| 674 | { |
| 675 | while (length > value_len) |
| 676 | { |
| 677 | /* FIXME: make this work */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 678 | /* Adjacency State (one octet): |
| 679 | 0 = Up |
| 680 | 1 = Initializing |
| 681 | 2 = Down |
| 682 | Extended Local Circuit ID (four octets) |
| 683 | Neighbor System ID if known (zero to eight octets) |
| 684 | Neighbor Extended Local Circuit ID (four octets, if Neighbor |
| 685 | System ID is present) */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 686 | pnt += length; |
| 687 | } |
| 688 | } |
| 689 | else |
| 690 | { |
| 691 | pnt += length; |
| 692 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 693 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 694 | break; |
| 695 | case GRACEFUL_RESTART: |
| 696 | /* +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 697 | * | Reserved | SA | RA | RR | 1 |
| 698 | * +-------+-------+-------+-------+-------+-------+-------+-------+ |
| 699 | * | Remaining Time | 2 |
| 700 | * +---------------------------------------------------------------+ |
| 701 | * | Restarting Neighbor ID (If known) | 0-8 |
| 702 | * +---------------------------------------------------------------+ |
| 703 | */ |
| 704 | *found |= TLVFLAG_GRACEFUL_RESTART; |
| 705 | if (*expected & TLVFLAG_GRACEFUL_RESTART) |
| 706 | { |
| 707 | /* FIXME: make this work */ |
| 708 | } |
| 709 | pnt += length; |
| 710 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 711 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 712 | default: |
| 713 | zlog_warn ("ISIS-TLV (%s): unsupported TLV type %d, length %d", |
| 714 | areatag, type, length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 715 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 716 | retval = ISIS_WARNING; |
| 717 | pnt += length; |
| 718 | break; |
| 719 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 720 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 721 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 722 | return retval; |
| 723 | } |
| 724 | |
| 725 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 726 | add_tlv (u_char tag, u_char len, u_char * value, struct stream *stream) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 727 | { |
| 728 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 729 | if (STREAM_SIZE (stream) - stream_get_endp (stream) < (unsigned) len + 2) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 730 | { |
| 731 | zlog_warn ("No room for TLV of type %d", tag); |
| 732 | return ISIS_WARNING; |
| 733 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 734 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 735 | stream_putc (stream, tag); /* TAG */ |
| 736 | stream_putc (stream, len); /* LENGTH */ |
| 737 | stream_put (stream, value, (int) len); /* VALUE */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 738 | |
| 739 | #ifdef EXTREME_DEBUG |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 740 | zlog_debug ("Added TLV %d len %d", tag, len); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 741 | #endif /* EXTREME DEBUG */ |
| 742 | return ISIS_OK; |
| 743 | } |
| 744 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 745 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 746 | tlv_add_area_addrs (struct list *area_addrs, struct stream *stream) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 747 | { |
| 748 | struct listnode *node; |
| 749 | struct area_addr *area_addr; |
| 750 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 751 | u_char value[255]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 752 | u_char *pos = value; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 753 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 754 | for (ALL_LIST_ELEMENTS_RO (area_addrs, node, area_addr)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 755 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 756 | if (pos - value + area_addr->addr_len > 255) |
| 757 | goto err; |
| 758 | *pos = area_addr->addr_len; |
| 759 | pos++; |
| 760 | memcpy (pos, area_addr->area_addr, (int) area_addr->addr_len); |
| 761 | pos += area_addr->addr_len; |
| 762 | } |
| 763 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 764 | return add_tlv (AREA_ADDRESSES, pos - value, value, stream); |
| 765 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 766 | err: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 767 | zlog_warn ("tlv_add_area_addrs(): TLV longer than 255"); |
| 768 | return ISIS_WARNING; |
| 769 | } |
| 770 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 771 | int |
| 772 | tlv_add_is_neighs (struct list *is_neighs, struct stream *stream) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 773 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 774 | struct listnode *node, *nnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 775 | struct is_neigh *is_neigh; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 776 | u_char value[255]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 777 | u_char *pos = value; |
| 778 | int retval; |
| 779 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 780 | *pos = 0; /*is_neigh->virtual; */ |
| 781 | pos++; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 782 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 783 | for (ALL_LIST_ELEMENTS (is_neighs, node, nnode, is_neigh)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 784 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 785 | if (pos - value + IS_NEIGHBOURS_LEN > 255) |
| 786 | { |
| 787 | retval = add_tlv (IS_NEIGHBOURS, pos - value, value, stream); |
| 788 | if (retval != ISIS_OK) |
| 789 | return retval; |
| 790 | pos = value; |
| 791 | } |
| 792 | *pos = is_neigh->metrics.metric_default; |
| 793 | pos++; |
| 794 | *pos = is_neigh->metrics.metric_delay; |
| 795 | pos++; |
| 796 | *pos = is_neigh->metrics.metric_expense; |
| 797 | pos++; |
| 798 | *pos = is_neigh->metrics.metric_error; |
| 799 | pos++; |
| 800 | memcpy (pos, is_neigh->neigh_id, ISIS_SYS_ID_LEN + 1); |
| 801 | pos += ISIS_SYS_ID_LEN + 1; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 802 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 803 | |
| 804 | return add_tlv (IS_NEIGHBOURS, pos - value, value, stream); |
| 805 | } |
| 806 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 807 | int |
| 808 | tlv_add_lan_neighs (struct list *lan_neighs, struct stream *stream) |
| 809 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 810 | struct listnode *node, *nnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 811 | u_char *snpa; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 812 | u_char value[255]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 813 | u_char *pos = value; |
| 814 | int retval; |
| 815 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 816 | for (ALL_LIST_ELEMENTS (lan_neighs, node, nnode, snpa)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 817 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 818 | if (pos - value + ETH_ALEN > 255) |
| 819 | { |
| 820 | retval = add_tlv (LAN_NEIGHBOURS, pos - value, value, stream); |
| 821 | if (retval != ISIS_OK) |
| 822 | return retval; |
| 823 | pos = value; |
| 824 | } |
| 825 | memcpy (pos, snpa, ETH_ALEN); |
| 826 | pos += ETH_ALEN; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 827 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 828 | |
| 829 | return add_tlv (LAN_NEIGHBOURS, pos - value, value, stream); |
| 830 | } |
| 831 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 832 | /* |
| 833 | u_char value[255]; |
| 834 | u_char *pos = value; |
| 835 | |
| 836 | if (circuit->ip_router) { |
| 837 | *pos = (u_char)NLPID_IP; |
| 838 | pos ++; |
| 839 | } |
| 840 | if (circuit->ipv6_router) { |
| 841 | *pos = (u_char)NLPID_IPV6; |
| 842 | pos ++; |
| 843 | } |
| 844 | */ |
| 845 | |
| 846 | int |
| 847 | tlv_add_nlpid (struct nlpids *nlpids, struct stream *stream) |
| 848 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 849 | |
| 850 | return add_tlv (PROTOCOLS_SUPPORTED, nlpids->count, nlpids->nlpids, stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 851 | } |
| 852 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 853 | int |
hasso | f7c43dc | 2004-09-26 16:24:14 +0000 | [diff] [blame] | 854 | tlv_add_authinfo (char auth_type, char auth_len, u_char *auth_value, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 855 | struct stream *stream) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 856 | { |
| 857 | u_char value[255]; |
| 858 | u_char *pos = value; |
hasso | 53c997c | 2004-09-15 16:21:59 +0000 | [diff] [blame] | 859 | *pos++ = ISIS_PASSWD_TYPE_CLEARTXT; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 860 | memcpy (pos, auth_value, auth_len); |
| 861 | |
| 862 | return add_tlv (AUTH_INFO, auth_len + 1, value, stream); |
| 863 | } |
| 864 | |
| 865 | int |
| 866 | tlv_add_checksum (struct checksum *checksum, struct stream *stream) |
| 867 | { |
| 868 | u_char value[255]; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 869 | u_char *pos = value; |
| 870 | return add_tlv (CHECKSUM, pos - value, value, stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | int |
| 874 | tlv_add_ip_addrs (struct list *ip_addrs, struct stream *stream) |
| 875 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 876 | struct listnode *node, *nnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 877 | struct prefix_ipv4 *ipv4; |
| 878 | u_char value[255]; |
| 879 | u_char *pos = value; |
| 880 | int retval; |
| 881 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 882 | for (ALL_LIST_ELEMENTS (ip_addrs, node, nnode, ipv4)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 883 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 884 | if (pos - value + IPV4_MAX_BYTELEN > 255) |
| 885 | { |
| 886 | retval = add_tlv (IPV4_ADDR, pos - value, value, stream); |
| 887 | if (retval != ISIS_OK) |
| 888 | return retval; |
| 889 | pos = value; |
| 890 | } |
| 891 | *(u_int32_t *) pos = ipv4->prefix.s_addr; |
| 892 | pos += IPV4_MAX_BYTELEN; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 893 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 894 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 895 | return add_tlv (IPV4_ADDR, pos - value, value, stream); |
| 896 | } |
| 897 | |
| 898 | int |
| 899 | tlv_add_dynamic_hostname (struct hostname *hostname, struct stream *stream) |
| 900 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 901 | return add_tlv (DYNAMIC_HOSTNAME, hostname->namelen, hostname->name, |
| 902 | stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 903 | } |
| 904 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 905 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 906 | tlv_add_lsp_entries (struct list *lsps, struct stream *stream) |
| 907 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 908 | struct listnode *node, *nnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 909 | struct isis_lsp *lsp; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 910 | u_char value[255]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 911 | u_char *pos = value; |
| 912 | int retval; |
| 913 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 914 | for (ALL_LIST_ELEMENTS (lsps, node, nnode, lsp)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 915 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 916 | if (pos - value + LSP_ENTRIES_LEN > 255) |
| 917 | { |
| 918 | retval = add_tlv (LSP_ENTRIES, pos - value, value, stream); |
| 919 | if (retval != ISIS_OK) |
| 920 | return retval; |
| 921 | pos = value; |
| 922 | } |
| 923 | *((u_int16_t *) pos) = lsp->lsp_header->rem_lifetime; |
| 924 | pos += 2; |
| 925 | memcpy (pos, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2); |
| 926 | pos += ISIS_SYS_ID_LEN + 2; |
| 927 | *((u_int32_t *) pos) = lsp->lsp_header->seq_num; |
| 928 | pos += 4; |
| 929 | *((u_int16_t *) pos) = lsp->lsp_header->checksum; |
| 930 | pos += 2; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 931 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 932 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 933 | return add_tlv (LSP_ENTRIES, pos - value, value, stream); |
| 934 | } |
| 935 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 936 | int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 937 | tlv_add_ipv4_reachs (struct list *ipv4_reachs, struct stream *stream) |
| 938 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 939 | struct listnode *node, *nnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 940 | struct ipv4_reachability *reach; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 941 | u_char value[255]; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 942 | u_char *pos = value; |
| 943 | int retval; |
| 944 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 945 | for (ALL_LIST_ELEMENTS (ipv4_reachs, node, nnode, reach)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 946 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 947 | if (pos - value + IPV4_REACH_LEN > 255) |
| 948 | { |
| 949 | retval = |
| 950 | add_tlv (IPV4_INT_REACHABILITY, pos - value, value, stream); |
| 951 | if (retval != ISIS_OK) |
| 952 | return retval; |
| 953 | pos = value; |
| 954 | } |
| 955 | *pos = reach->metrics.metric_default; |
| 956 | pos++; |
| 957 | *pos = reach->metrics.metric_delay; |
| 958 | pos++; |
| 959 | *pos = reach->metrics.metric_expense; |
| 960 | pos++; |
| 961 | *pos = reach->metrics.metric_error; |
| 962 | pos++; |
| 963 | *(u_int32_t *) pos = reach->prefix.s_addr; |
| 964 | pos += IPV4_MAX_BYTELEN; |
| 965 | *(u_int32_t *) pos = reach->mask.s_addr; |
| 966 | pos += IPV4_MAX_BYTELEN; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 967 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 968 | |
| 969 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 970 | return add_tlv (IPV4_INT_REACHABILITY, pos - value, value, stream); |
| 971 | } |
| 972 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 973 | #ifdef HAVE_IPV6 |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 974 | int |
| 975 | tlv_add_ipv6_addrs (struct list *ipv6_addrs, struct stream *stream) |
| 976 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 977 | struct listnode *node, *nnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 978 | struct prefix_ipv6 *ipv6; |
| 979 | u_char value[255]; |
| 980 | u_char *pos = value; |
| 981 | int retval; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 982 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 983 | for (ALL_LIST_ELEMENTS (ipv6_addrs, node, nnode, ipv6)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 984 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 985 | if (pos - value + IPV6_MAX_BYTELEN > 255) |
| 986 | { |
| 987 | retval = add_tlv (IPV6_ADDR, pos - value, value, stream); |
| 988 | if (retval != ISIS_OK) |
| 989 | return retval; |
| 990 | pos = value; |
| 991 | } |
| 992 | memcpy (pos, ipv6->prefix.s6_addr, IPV6_MAX_BYTELEN); |
| 993 | pos += IPV6_MAX_BYTELEN; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 994 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 995 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 996 | return add_tlv (IPV6_ADDR, pos - value, value, stream); |
| 997 | } |
| 998 | |
| 999 | int |
| 1000 | tlv_add_ipv6_reachs (struct list *ipv6_reachs, struct stream *stream) |
| 1001 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1002 | struct listnode *node, *nnode; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1003 | struct ipv6_reachability *ip6reach; |
| 1004 | u_char value[255]; |
| 1005 | u_char *pos = value; |
| 1006 | int retval, prefix_octets; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1007 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1008 | for (ALL_LIST_ELEMENTS (ipv6_reachs, node, nnode, ip6reach)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1009 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1010 | if (pos - value + IPV6_MAX_BYTELEN + 6 > 255) |
| 1011 | { |
| 1012 | retval = add_tlv (IPV6_REACHABILITY, pos - value, value, stream); |
| 1013 | if (retval != ISIS_OK) |
| 1014 | return retval; |
| 1015 | pos = value; |
| 1016 | } |
| 1017 | *(uint32_t *) pos = ip6reach->metric; |
| 1018 | pos += 4; |
| 1019 | *pos = ip6reach->control_info; |
| 1020 | pos++; |
| 1021 | prefix_octets = ((ip6reach->prefix_len + 7) / 8); |
| 1022 | *pos = ip6reach->prefix_len; |
| 1023 | pos++; |
| 1024 | memcpy (pos, ip6reach->prefix, prefix_octets); |
| 1025 | pos += prefix_octets; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1026 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1027 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1028 | return add_tlv (IPV6_REACHABILITY, pos - value, value, stream); |
| 1029 | } |
| 1030 | #endif /* HAVE_IPV6 */ |
| 1031 | |
| 1032 | int |
| 1033 | tlv_add_padding (struct stream *stream) |
| 1034 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1035 | int fullpads, i, left; |
| 1036 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1037 | /* |
| 1038 | * How many times can we add full padding ? |
| 1039 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1040 | fullpads = (STREAM_SIZE (stream) - stream_get_endp (stream)) / 257; |
| 1041 | for (i = 0; i < fullpads; i++) |
| 1042 | { |
| 1043 | if (!stream_putc (stream, (u_char) PADDING)) /* TAG */ |
| 1044 | goto err; |
| 1045 | if (!stream_putc (stream, (u_char) 255)) /* LENGHT */ |
| 1046 | goto err; |
paul | 15935e9 | 2005-05-03 09:27:23 +0000 | [diff] [blame] | 1047 | stream_put (stream, NULL, 255); /* zero padding */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 1050 | left = STREAM_SIZE (stream) - stream_get_endp (stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1051 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1052 | if (left < 2) |
| 1053 | return ISIS_OK; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1054 | |
| 1055 | if (left == 2) |
| 1056 | { |
| 1057 | stream_putc (stream, PADDING); |
| 1058 | stream_putc (stream, 0); |
| 1059 | return ISIS_OK; |
| 1060 | } |
| 1061 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1062 | stream_putc (stream, PADDING); |
| 1063 | stream_putc (stream, left - 2); |
paul | 15935e9 | 2005-05-03 09:27:23 +0000 | [diff] [blame] | 1064 | stream_put (stream, NULL, left-2); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1065 | |
| 1066 | return ISIS_OK; |
| 1067 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1068 | err: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1069 | zlog_warn ("tlv_add_padding(): no room for tlv"); |
| 1070 | return ISIS_WARNING; |
| 1071 | } |