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