jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * IS-IS Rout(e)ing protocol - isis_pdu.c |
| 3 | * PDU processing |
| 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 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 24 | #include <zebra.h> |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 25 | |
| 26 | #include "memory.h" |
| 27 | #include "thread.h" |
| 28 | #include "linklist.h" |
| 29 | #include "log.h" |
| 30 | #include "stream.h" |
| 31 | #include "vty.h" |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 32 | #include "hash.h" |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 33 | #include "prefix.h" |
| 34 | #include "if.h" |
Jingjing Duan | 6a270cd | 2008-08-13 19:09:10 +0100 | [diff] [blame] | 35 | #include "checksum.h" |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 36 | #include "md5.h" |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 37 | |
| 38 | #include "isisd/dict.h" |
| 39 | #include "isisd/include-netbsd/iso.h" |
| 40 | #include "isisd/isis_constants.h" |
| 41 | #include "isisd/isis_common.h" |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 42 | #include "isisd/isis_flags.h" |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 43 | #include "isisd/isis_adjacency.h" |
| 44 | #include "isisd/isis_circuit.h" |
| 45 | #include "isisd/isis_network.h" |
| 46 | #include "isisd/isis_misc.h" |
| 47 | #include "isisd/isis_dr.h" |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 48 | #include "isisd/isis_tlv.h" |
| 49 | #include "isisd/isisd.h" |
| 50 | #include "isisd/isis_dynhn.h" |
| 51 | #include "isisd/isis_lsp.h" |
| 52 | #include "isisd/isis_pdu.h" |
| 53 | #include "isisd/iso_checksum.h" |
| 54 | #include "isisd/isis_csm.h" |
| 55 | #include "isisd/isis_events.h" |
| 56 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 57 | #define ISIS_MINIMUM_FIXED_HDR_LEN 15 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 58 | #define ISIS_MIN_PDU_LEN 13 /* partial seqnum pdu with id_len=2 */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 59 | |
| 60 | #ifndef PNBBY |
| 61 | #define PNBBY 8 |
| 62 | #endif /* PNBBY */ |
| 63 | |
| 64 | /* Utility mask array. */ |
Stephen Hemminger | 88d37b9 | 2014-11-03 01:20:09 +0000 | [diff] [blame^] | 65 | static const u_char maskbit[] = { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 66 | 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff |
| 67 | }; |
| 68 | |
| 69 | /* |
| 70 | * HELPER FUNCS |
| 71 | */ |
| 72 | |
| 73 | /* |
| 74 | * Compares two sets of area addresses |
| 75 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 76 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 77 | area_match (struct list *left, struct list *right) |
| 78 | { |
| 79 | struct area_addr *addr1, *addr2; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 80 | struct listnode *node1, *node2; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 81 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 82 | for (ALL_LIST_ELEMENTS_RO (left, node1, addr1)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 83 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 84 | for (ALL_LIST_ELEMENTS_RO (right, node2, addr2)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 85 | { |
| 86 | if (addr1->addr_len == addr2->addr_len && |
| 87 | !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len)) |
| 88 | return 1; /* match */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 92 | return 0; /* mismatch */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /* |
| 96 | * Check if ip2 is in the ip1's network (function like Prefix.h:prefix_match() ) |
| 97 | * param ip1 the IS interface ip address structure |
| 98 | * param ip2 the IIH's ip address |
| 99 | * return 0 the IIH's IP is not in the IS's subnetwork |
| 100 | * 1 the IIH's IP is in the IS's subnetwork |
| 101 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 102 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 103 | ip_same_subnet (struct prefix_ipv4 *ip1, struct in_addr *ip2) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 104 | { |
| 105 | u_char *addr1, *addr2; |
hasso | 53c997c | 2004-09-15 16:21:59 +0000 | [diff] [blame] | 106 | int shift, offset, offsetloop; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 107 | int len; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 108 | |
| 109 | addr1 = (u_char *) & ip1->prefix.s_addr; |
| 110 | addr2 = (u_char *) & ip2->s_addr; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 111 | len = ip1->prefixlen; |
| 112 | |
| 113 | shift = len % PNBBY; |
hasso | 53c997c | 2004-09-15 16:21:59 +0000 | [diff] [blame] | 114 | offsetloop = offset = len / PNBBY; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 115 | |
hasso | 53c997c | 2004-09-15 16:21:59 +0000 | [diff] [blame] | 116 | while (offsetloop--) |
| 117 | if (addr1[offsetloop] != addr2[offsetloop]) |
| 118 | return 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 119 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 120 | if (shift) |
hasso | 53c997c | 2004-09-15 16:21:59 +0000 | [diff] [blame] | 121 | if (maskbit[shift] & (addr1[offset] ^ addr2[offset])) |
| 122 | return 0; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 123 | |
| 124 | return 1; /* match */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 125 | } |
| 126 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 127 | /* |
| 128 | * Compares two set of ip addresses |
| 129 | * param left the local interface's ip addresses |
| 130 | * param right the iih interface's ip address |
| 131 | * return 0 no match; |
| 132 | * 1 match; |
| 133 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 134 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 135 | ip_match (struct list *left, struct list *right) |
| 136 | { |
| 137 | struct prefix_ipv4 *ip1; |
| 138 | struct in_addr *ip2; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 139 | struct listnode *node1, *node2; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 140 | |
hasso | e082ac1 | 2004-09-27 18:13:57 +0000 | [diff] [blame] | 141 | if ((left == NULL) || (right == NULL)) |
| 142 | return 0; |
| 143 | |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 144 | for (ALL_LIST_ELEMENTS_RO (left, node1, ip1)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 145 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 146 | for (ALL_LIST_ELEMENTS_RO (right, node2, ip2)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 147 | { |
| 148 | if (ip_same_subnet (ip1, ip2)) |
| 149 | { |
| 150 | return 1; /* match */ |
| 151 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 152 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 153 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 154 | } |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * Checks whether we should accept a PDU of given level |
| 160 | */ |
| 161 | static int |
| 162 | accept_level (int level, int circuit_t) |
| 163 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 164 | int retval = ((circuit_t & level) == level); /* simple approach */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 165 | |
| 166 | return retval; |
| 167 | } |
| 168 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 169 | /* |
| 170 | * Verify authentication information |
| 171 | * Support cleartext and HMAC MD5 authentication |
| 172 | */ |
| 173 | static int |
| 174 | authentication_check (struct isis_passwd *remote, struct isis_passwd *local, |
| 175 | struct stream *stream, uint32_t auth_tlv_offset) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 176 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 177 | unsigned char digest[ISIS_AUTH_MD5_SIZE]; |
| 178 | |
| 179 | /* Auth fail () - passwd type mismatch */ |
| 180 | if (local->type != remote->type) |
| 181 | return ISIS_ERROR; |
| 182 | |
| 183 | switch (local->type) |
| 184 | { |
| 185 | /* No authentication required */ |
| 186 | case ISIS_PASSWD_TYPE_UNUSED: |
| 187 | break; |
| 188 | |
| 189 | /* Cleartext (ISO 10589) */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 190 | case ISIS_PASSWD_TYPE_CLEARTXT: |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 191 | /* Auth fail () - passwd len mismatch */ |
| 192 | if (remote->len != local->len) |
| 193 | return ISIS_ERROR; |
| 194 | return memcmp (local->passwd, remote->passwd, local->len); |
| 195 | |
| 196 | /* HMAC MD5 (RFC 3567) */ |
| 197 | case ISIS_PASSWD_TYPE_HMAC_MD5: |
| 198 | /* Auth fail () - passwd len mismatch */ |
| 199 | if (remote->len != ISIS_AUTH_MD5_SIZE) |
| 200 | return ISIS_ERROR; |
| 201 | /* Set the authentication value to 0 before the check */ |
| 202 | memset (STREAM_DATA (stream) + auth_tlv_offset + 3, 0, |
| 203 | ISIS_AUTH_MD5_SIZE); |
| 204 | /* Compute the digest */ |
| 205 | hmac_md5 (STREAM_DATA (stream), stream_get_endp (stream), |
| 206 | (unsigned char *) &(local->passwd), local->len, |
| 207 | (caddr_t) &digest); |
| 208 | /* Copy back the authentication value after the check */ |
| 209 | memcpy (STREAM_DATA (stream) + auth_tlv_offset + 3, |
| 210 | remote->passwd, ISIS_AUTH_MD5_SIZE); |
| 211 | return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE); |
| 212 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 213 | default: |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 214 | zlog_err ("Unsupported authentication type"); |
| 215 | return ISIS_ERROR; |
| 216 | } |
| 217 | |
| 218 | /* Authentication pass when no authentication is configured */ |
| 219 | return ISIS_OK; |
| 220 | } |
| 221 | |
| 222 | static int |
| 223 | lsp_authentication_check (struct stream *stream, struct isis_area *area, |
| 224 | int level, struct isis_passwd *passwd) |
| 225 | { |
| 226 | struct isis_link_state_hdr *hdr; |
| 227 | uint32_t expected = 0, found = 0, auth_tlv_offset = 0; |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 228 | uint16_t checksum, rem_lifetime, pdu_len; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 229 | struct tlvs tlvs; |
| 230 | int retval = ISIS_OK; |
| 231 | |
| 232 | hdr = (struct isis_link_state_hdr *) (STREAM_PNT (stream)); |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 233 | pdu_len = ntohs (hdr->pdu_len); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 234 | expected |= TLVFLAG_AUTH_INFO; |
| 235 | auth_tlv_offset = stream_get_getp (stream) + ISIS_LSP_HDR_LEN; |
| 236 | retval = parse_tlvs (area->area_tag, STREAM_PNT (stream) + ISIS_LSP_HDR_LEN, |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 237 | pdu_len - ISIS_FIXED_HDR_LEN - ISIS_LSP_HDR_LEN, |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 238 | &expected, &found, &tlvs, &auth_tlv_offset); |
| 239 | |
| 240 | if (retval != ISIS_OK) |
| 241 | { |
| 242 | zlog_err ("ISIS-Upd (%s): Parse failed L%d LSP %s, seq 0x%08x, " |
| 243 | "cksum 0x%04x, lifetime %us, len %u", |
| 244 | area->area_tag, level, rawlspid_print (hdr->lsp_id), |
| 245 | ntohl (hdr->seq_num), ntohs (hdr->checksum), |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 246 | ntohs (hdr->rem_lifetime), pdu_len); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 247 | if ((isis->debugs & DEBUG_UPDATE_PACKETS) && |
| 248 | (isis->debugs & DEBUG_PACKET_DUMP)) |
| 249 | zlog_dump_data (STREAM_DATA (stream), stream_get_endp (stream)); |
| 250 | return retval; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 251 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 252 | |
| 253 | if (!(found & TLVFLAG_AUTH_INFO)) |
| 254 | { |
| 255 | zlog_err ("No authentication tlv in LSP"); |
| 256 | return ISIS_ERROR; |
| 257 | } |
| 258 | |
| 259 | if (tlvs.auth_info.type != ISIS_PASSWD_TYPE_CLEARTXT && |
| 260 | tlvs.auth_info.type != ISIS_PASSWD_TYPE_HMAC_MD5) |
| 261 | { |
| 262 | zlog_err ("Unknown authentication type in LSP"); |
| 263 | return ISIS_ERROR; |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * RFC 5304 set checksum and remaining lifetime to zero before |
| 268 | * verification and reset to old values after verification. |
| 269 | */ |
| 270 | checksum = hdr->checksum; |
| 271 | rem_lifetime = hdr->rem_lifetime; |
| 272 | hdr->checksum = 0; |
| 273 | hdr->rem_lifetime = 0; |
| 274 | retval = authentication_check (&tlvs.auth_info, passwd, stream, |
| 275 | auth_tlv_offset); |
| 276 | hdr->checksum = checksum; |
| 277 | hdr->rem_lifetime = rem_lifetime; |
| 278 | |
| 279 | return retval; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /* |
| 283 | * Processing helper functions |
| 284 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 285 | static void |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 286 | del_addr (void *val) |
| 287 | { |
| 288 | XFREE (MTYPE_ISIS_TMP, val); |
| 289 | } |
| 290 | |
| 291 | static void |
| 292 | tlvs_to_adj_area_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) |
| 293 | { |
| 294 | struct listnode *node; |
| 295 | struct area_addr *area_addr, *malloced; |
| 296 | |
| 297 | if (adj->area_addrs) |
| 298 | { |
| 299 | adj->area_addrs->del = del_addr; |
| 300 | list_delete (adj->area_addrs); |
| 301 | } |
| 302 | adj->area_addrs = list_new (); |
| 303 | if (tlvs->area_addrs) |
| 304 | { |
| 305 | for (ALL_LIST_ELEMENTS_RO (tlvs->area_addrs, node, area_addr)) |
| 306 | { |
| 307 | malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct area_addr)); |
| 308 | memcpy (malloced, area_addr, sizeof (struct area_addr)); |
| 309 | listnode_add (adj->area_addrs, malloced); |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
David Lamparter | 655071f | 2012-05-08 13:32:53 +0200 | [diff] [blame] | 314 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 315 | tlvs_to_adj_nlpids (struct tlvs *tlvs, struct isis_adjacency *adj) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 316 | { |
| 317 | int i; |
| 318 | struct nlpids *tlv_nlpids; |
| 319 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 320 | if (tlvs->nlpids) |
| 321 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 322 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 323 | tlv_nlpids = tlvs->nlpids; |
David Lamparter | 655071f | 2012-05-08 13:32:53 +0200 | [diff] [blame] | 324 | if (tlv_nlpids->count > array_size (adj->nlpids.nlpids)) |
| 325 | return 1; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 326 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 327 | adj->nlpids.count = tlv_nlpids->count; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 328 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 329 | for (i = 0; i < tlv_nlpids->count; i++) |
| 330 | { |
| 331 | adj->nlpids.nlpids[i] = tlv_nlpids->nlpids[i]; |
| 332 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 333 | } |
David Lamparter | 655071f | 2012-05-08 13:32:53 +0200 | [diff] [blame] | 334 | return 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 335 | } |
| 336 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 337 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 338 | tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 339 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 340 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 341 | struct in_addr *ipv4_addr, *malloced; |
| 342 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 343 | if (adj->ipv4_addrs) |
| 344 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 345 | adj->ipv4_addrs->del = del_addr; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 346 | list_delete (adj->ipv4_addrs); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 347 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 348 | adj->ipv4_addrs = list_new (); |
| 349 | if (tlvs->ipv4_addrs) |
| 350 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 351 | for (ALL_LIST_ELEMENTS_RO (tlvs->ipv4_addrs, node, ipv4_addr)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 352 | { |
| 353 | malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr)); |
| 354 | memcpy (malloced, ipv4_addr, sizeof (struct in_addr)); |
| 355 | listnode_add (adj->ipv4_addrs, malloced); |
| 356 | } |
| 357 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | #ifdef HAVE_IPV6 |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 361 | static void |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 362 | tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 363 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 364 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 365 | struct in6_addr *ipv6_addr, *malloced; |
| 366 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 367 | if (adj->ipv6_addrs) |
| 368 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 369 | adj->ipv6_addrs->del = del_addr; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 370 | list_delete (adj->ipv6_addrs); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 371 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 372 | adj->ipv6_addrs = list_new (); |
| 373 | if (tlvs->ipv6_addrs) |
| 374 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 375 | for (ALL_LIST_ELEMENTS_RO (tlvs->ipv6_addrs, node, ipv6_addr)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 376 | { |
| 377 | malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr)); |
| 378 | memcpy (malloced, ipv6_addr, sizeof (struct in6_addr)); |
| 379 | listnode_add (adj->ipv6_addrs, malloced); |
| 380 | } |
| 381 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 382 | |
| 383 | } |
| 384 | #endif /* HAVE_IPV6 */ |
| 385 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 386 | /* |
| 387 | * RECEIVE SIDE |
| 388 | */ |
| 389 | |
| 390 | /* |
| 391 | * Process P2P IIH |
| 392 | * ISO - 10589 |
| 393 | * Section 8.2.5 - Receiving point-to-point IIH PDUs |
| 394 | * |
| 395 | */ |
| 396 | static int |
| 397 | process_p2p_hello (struct isis_circuit *circuit) |
| 398 | { |
| 399 | int retval = ISIS_OK; |
| 400 | struct isis_p2p_hello_hdr *hdr; |
| 401 | struct isis_adjacency *adj; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 402 | u_int32_t expected = 0, found = 0, auth_tlv_offset = 0; |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 403 | uint16_t pdu_len; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 404 | struct tlvs tlvs; |
David Lamparter | 28a8cfc | 2014-06-29 13:48:18 +0200 | [diff] [blame] | 405 | int v4_usable = 0, v6_usable = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 406 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 407 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 408 | { |
| 409 | zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH on %s, cirType %s, cirID %u", |
| 410 | circuit->area->area_tag, circuit->interface->name, |
| 411 | circuit_t2string (circuit->is_type), circuit->circuit_id); |
| 412 | if (isis->debugs & DEBUG_PACKET_DUMP) |
| 413 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), |
| 414 | stream_get_endp (circuit->rcv_stream)); |
| 415 | } |
| 416 | |
| 417 | if (circuit->circ_type != CIRCUIT_T_P2P) |
| 418 | { |
| 419 | zlog_warn ("p2p hello on non p2p circuit"); |
| 420 | return ISIS_WARNING; |
| 421 | } |
| 422 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 423 | if ((stream_get_endp (circuit->rcv_stream) - |
| 424 | stream_get_getp (circuit->rcv_stream)) < ISIS_P2PHELLO_HDRLEN) |
| 425 | { |
| 426 | zlog_warn ("Packet too short"); |
| 427 | return ISIS_WARNING; |
| 428 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 429 | |
| 430 | /* 8.2.5.1 PDU acceptance tests */ |
| 431 | |
| 432 | /* 8.2.5.1 a) external domain untrue */ |
| 433 | /* FIXME: not useful at all? */ |
| 434 | |
| 435 | /* 8.2.5.1 b) ID Length mismatch */ |
| 436 | /* checked at the handle_pdu */ |
| 437 | |
| 438 | /* 8.2.5.2 IIH PDU Processing */ |
| 439 | |
| 440 | /* 8.2.5.2 a) 1) Maximum Area Addresses */ |
| 441 | /* Already checked, and can also be ommited */ |
| 442 | |
| 443 | /* |
| 444 | * Get the header |
| 445 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 446 | hdr = (struct isis_p2p_hello_hdr *) STREAM_PNT (circuit->rcv_stream); |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 447 | pdu_len = ntohs (hdr->pdu_len); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 448 | |
Avneesh Sachdev | a22ab5a | 2012-05-05 23:50:30 -0700 | [diff] [blame] | 449 | if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_P2PHELLO_HDRLEN) || |
| 450 | pdu_len > ISO_MTU(circuit) || |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 451 | pdu_len > stream_get_endp (circuit->rcv_stream)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 452 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 453 | zlog_warn ("ISIS-Adj (%s): Rcvd P2P IIH from (%s) with " |
| 454 | "invalid pdu length %d", |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 455 | circuit->area->area_tag, circuit->interface->name, pdu_len); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 456 | return ISIS_WARNING; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 457 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 458 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 459 | /* |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 460 | * Set the stream endp to PDU length, ignoring additional padding |
| 461 | * introduced by transport chips. |
| 462 | */ |
| 463 | if (pdu_len < stream_get_endp (circuit->rcv_stream)) |
| 464 | stream_set_endp (circuit->rcv_stream, pdu_len); |
| 465 | |
| 466 | stream_forward_getp (circuit->rcv_stream, ISIS_P2PHELLO_HDRLEN); |
| 467 | |
| 468 | /* |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 469 | * Lets get the TLVS now |
| 470 | */ |
| 471 | expected |= TLVFLAG_AREA_ADDRS; |
| 472 | expected |= TLVFLAG_AUTH_INFO; |
| 473 | expected |= TLVFLAG_NLPID; |
| 474 | expected |= TLVFLAG_IPV4_ADDR; |
| 475 | expected |= TLVFLAG_IPV6_ADDR; |
| 476 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 477 | auth_tlv_offset = stream_get_getp (circuit->rcv_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 478 | retval = parse_tlvs (circuit->area->area_tag, |
| 479 | STREAM_PNT (circuit->rcv_stream), |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 480 | pdu_len - ISIS_P2PHELLO_HDRLEN - ISIS_FIXED_HDR_LEN, |
| 481 | &expected, &found, &tlvs, &auth_tlv_offset); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 482 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 483 | if (retval > ISIS_WARNING) |
| 484 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 485 | zlog_warn ("parse_tlvs() failed"); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 486 | free_tlvs (&tlvs); |
| 487 | return retval; |
| 488 | }; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 489 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 490 | if (!(found & TLVFLAG_AREA_ADDRS)) |
| 491 | { |
| 492 | zlog_warn ("No Area addresses TLV in P2P IS to IS hello"); |
| 493 | free_tlvs (&tlvs); |
| 494 | return ISIS_WARNING; |
| 495 | } |
| 496 | |
David Lamparter | b72f345 | 2012-11-27 01:10:26 +0000 | [diff] [blame] | 497 | if (!(found & TLVFLAG_NLPID)) |
| 498 | { |
| 499 | zlog_warn ("No supported protocols TLV in P2P IS to IS hello"); |
| 500 | free_tlvs (&tlvs); |
| 501 | return ISIS_WARNING; |
| 502 | } |
| 503 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 504 | /* 8.2.5.1 c) Authentication */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 505 | if (circuit->passwd.type) |
| 506 | { |
| 507 | if (!(found & TLVFLAG_AUTH_INFO) || |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 508 | authentication_check (&tlvs.auth_info, &circuit->passwd, |
| 509 | circuit->rcv_stream, auth_tlv_offset)) |
| 510 | { |
| 511 | isis_event_auth_failure (circuit->area->area_tag, |
| 512 | "P2P hello authentication failure", |
| 513 | hdr->source_id); |
| 514 | free_tlvs (&tlvs); |
| 515 | return ISIS_OK; |
| 516 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 517 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 518 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 519 | /* |
| 520 | * check if it's own interface ip match iih ip addrs |
| 521 | */ |
David Lamparter | 28a8cfc | 2014-06-29 13:48:18 +0200 | [diff] [blame] | 522 | if (found & TLVFLAG_IPV4_ADDR) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 523 | { |
David Lamparter | 28a8cfc | 2014-06-29 13:48:18 +0200 | [diff] [blame] | 524 | if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs)) |
| 525 | v4_usable = 1; |
| 526 | else |
| 527 | zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap " |
| 528 | "in P2P IIH from %s\n", circuit->interface->name); |
| 529 | } |
| 530 | #ifndef HAVE_IPV6 |
| 531 | else /* !(found & TLVFLAG_IPV4_ADDR) */ |
| 532 | zlog_warn ("ISIS-Adj: no IPv4 in P2P IIH from %s " |
| 533 | "(this isisd has no IPv6)\n", circuit->interface->name); |
| 534 | |
| 535 | #else |
| 536 | if (found & TLVFLAG_IPV6_ADDR) |
| 537 | { |
| 538 | /* TBA: check that we have a linklocal ourselves? */ |
| 539 | struct listnode *node; |
David Lamparter | ad2f92b | 2014-08-18 18:05:25 +0200 | [diff] [blame] | 540 | struct in6_addr *ip; |
David Lamparter | 28a8cfc | 2014-06-29 13:48:18 +0200 | [diff] [blame] | 541 | for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip)) |
| 542 | if (IN6_IS_ADDR_LINKLOCAL (ip)) |
| 543 | { |
| 544 | v6_usable = 1; |
| 545 | break; |
| 546 | } |
| 547 | |
| 548 | if (!v6_usable) |
| 549 | zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local " |
| 550 | "in P2P IIH from %s\n", circuit->interface->name); |
| 551 | } |
| 552 | |
| 553 | if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR))) |
| 554 | zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in P2P IIH from %s\n", |
| 555 | circuit->interface->name); |
| 556 | #endif |
| 557 | |
| 558 | if (!v6_usable && !v4_usable) |
| 559 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 560 | free_tlvs (&tlvs); |
| 561 | return ISIS_WARNING; |
| 562 | } |
| 563 | |
| 564 | /* |
| 565 | * My interpertation of the ISO, if no adj exists we will create one for |
| 566 | * the circuit |
| 567 | */ |
| 568 | adj = circuit->u.p2p.neighbor; |
| 569 | if (!adj || adj->level != hdr->circuit_t) |
| 570 | { |
| 571 | if (!adj) |
| 572 | { |
| 573 | adj = isis_new_adj (hdr->source_id, NULL, hdr->circuit_t, circuit); |
| 574 | if (adj == NULL) |
| 575 | return ISIS_ERROR; |
| 576 | } |
| 577 | else |
| 578 | { |
| 579 | adj->level = hdr->circuit_t; |
| 580 | } |
| 581 | circuit->u.p2p.neighbor = adj; |
| 582 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); |
| 583 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; |
| 584 | } |
| 585 | |
| 586 | /* 8.2.6 Monitoring point-to-point adjacencies */ |
| 587 | adj->hold_time = ntohs (hdr->hold_time); |
| 588 | adj->last_upd = time (NULL); |
| 589 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 590 | /* we do this now because the adj may not survive till the end... */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 591 | tlvs_to_adj_area_addrs (&tlvs, adj); |
| 592 | |
| 593 | /* which protocol are spoken ??? */ |
David Lamparter | b72f345 | 2012-11-27 01:10:26 +0000 | [diff] [blame] | 594 | if (tlvs_to_adj_nlpids (&tlvs, adj)) |
| 595 | { |
| 596 | free_tlvs (&tlvs); |
| 597 | return ISIS_WARNING; |
| 598 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 599 | |
| 600 | /* we need to copy addresses to the adj */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 601 | if (found & TLVFLAG_IPV4_ADDR) |
| 602 | tlvs_to_adj_ipv4_addrs (&tlvs, adj); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 603 | |
| 604 | #ifdef HAVE_IPV6 |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 605 | if (found & TLVFLAG_IPV6_ADDR) |
| 606 | tlvs_to_adj_ipv6_addrs (&tlvs, adj); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 607 | #endif /* HAVE_IPV6 */ |
| 608 | |
| 609 | /* lets take care of the expiry */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 610 | THREAD_TIMER_OFF (adj->t_expire); |
| 611 | THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj, |
| 612 | (long) adj->hold_time); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 613 | |
| 614 | /* 8.2.5.2 a) a match was detected */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 615 | if (area_match (circuit->area->area_addrs, tlvs.area_addrs)) |
| 616 | { |
| 617 | /* 8.2.5.2 a) 2) If the system is L1 - table 5 */ |
| 618 | if (circuit->area->is_type == IS_LEVEL_1) |
| 619 | { |
| 620 | switch (hdr->circuit_t) |
| 621 | { |
| 622 | case IS_LEVEL_1: |
| 623 | case IS_LEVEL_1_AND_2: |
| 624 | if (adj->adj_state != ISIS_ADJ_UP) |
| 625 | { |
| 626 | /* (4) adj state up */ |
| 627 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); |
| 628 | /* (5) adj usage level 1 */ |
| 629 | adj->adj_usage = ISIS_ADJ_LEVEL1; |
| 630 | } |
| 631 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) |
| 632 | { |
| 633 | ; /* accept */ |
| 634 | } |
| 635 | break; |
| 636 | case IS_LEVEL_2: |
| 637 | if (adj->adj_state != ISIS_ADJ_UP) |
| 638 | { |
| 639 | /* (7) reject - wrong system type event */ |
| 640 | zlog_warn ("wrongSystemType"); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 641 | free_tlvs (&tlvs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 642 | return ISIS_WARNING; /* Reject */ |
| 643 | } |
| 644 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) |
| 645 | { |
| 646 | /* (6) down - wrong system */ |
| 647 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); |
| 648 | } |
| 649 | break; |
| 650 | } |
| 651 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 652 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 653 | /* 8.2.5.2 a) 3) If the system is L1L2 - table 6 */ |
| 654 | if (circuit->area->is_type == IS_LEVEL_1_AND_2) |
| 655 | { |
| 656 | switch (hdr->circuit_t) |
| 657 | { |
| 658 | case IS_LEVEL_1: |
| 659 | if (adj->adj_state != ISIS_ADJ_UP) |
| 660 | { |
| 661 | /* (6) adj state up */ |
| 662 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); |
| 663 | /* (7) adj usage level 1 */ |
| 664 | adj->adj_usage = ISIS_ADJ_LEVEL1; |
| 665 | } |
| 666 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) |
| 667 | { |
| 668 | ; /* accept */ |
| 669 | } |
| 670 | else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || |
| 671 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) |
| 672 | { |
| 673 | /* (8) down - wrong system */ |
| 674 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); |
| 675 | } |
| 676 | break; |
| 677 | case IS_LEVEL_2: |
| 678 | if (adj->adj_state != ISIS_ADJ_UP) |
| 679 | { |
| 680 | /* (6) adj state up */ |
| 681 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); |
| 682 | /* (9) adj usage level 2 */ |
| 683 | adj->adj_usage = ISIS_ADJ_LEVEL2; |
| 684 | } |
| 685 | else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) || |
| 686 | (adj->adj_usage == ISIS_ADJ_LEVEL1AND2)) |
| 687 | { |
| 688 | /* (8) down - wrong system */ |
| 689 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); |
| 690 | } |
| 691 | else if (adj->adj_usage == ISIS_ADJ_LEVEL2) |
| 692 | { |
| 693 | ; /* Accept */ |
| 694 | } |
| 695 | break; |
| 696 | case IS_LEVEL_1_AND_2: |
| 697 | if (adj->adj_state != ISIS_ADJ_UP) |
| 698 | { |
| 699 | /* (6) adj state up */ |
| 700 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); |
| 701 | /* (10) adj usage level 1 */ |
| 702 | adj->adj_usage = ISIS_ADJ_LEVEL1AND2; |
| 703 | } |
| 704 | else if ((adj->adj_usage == ISIS_ADJ_LEVEL1) || |
| 705 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) |
| 706 | { |
| 707 | /* (8) down - wrong system */ |
| 708 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); |
| 709 | } |
| 710 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) |
| 711 | { |
| 712 | ; /* Accept */ |
| 713 | } |
| 714 | break; |
| 715 | } |
| 716 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 717 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 718 | /* 8.2.5.2 a) 4) If the system is L2 - table 7 */ |
| 719 | if (circuit->area->is_type == IS_LEVEL_2) |
| 720 | { |
| 721 | switch (hdr->circuit_t) |
| 722 | { |
| 723 | case IS_LEVEL_1: |
| 724 | if (adj->adj_state != ISIS_ADJ_UP) |
| 725 | { |
| 726 | /* (5) reject - wrong system type event */ |
| 727 | zlog_warn ("wrongSystemType"); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 728 | free_tlvs (&tlvs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 729 | return ISIS_WARNING; /* Reject */ |
| 730 | } |
| 731 | else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || |
| 732 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) |
| 733 | { |
| 734 | /* (6) down - wrong system */ |
| 735 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); |
| 736 | } |
| 737 | break; |
| 738 | case IS_LEVEL_1_AND_2: |
| 739 | case IS_LEVEL_2: |
| 740 | if (adj->adj_state != ISIS_ADJ_UP) |
| 741 | { |
| 742 | /* (7) adj state up */ |
| 743 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); |
| 744 | /* (8) adj usage level 2 */ |
| 745 | adj->adj_usage = ISIS_ADJ_LEVEL2; |
| 746 | } |
| 747 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) |
| 748 | { |
| 749 | /* (6) down - wrong system */ |
| 750 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); |
| 751 | } |
| 752 | else if (adj->adj_usage == ISIS_ADJ_LEVEL2) |
| 753 | { |
| 754 | ; /* Accept */ |
| 755 | } |
| 756 | break; |
| 757 | } |
| 758 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 759 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 760 | /* 8.2.5.2 b) if no match was detected */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 761 | else if (listcount (circuit->area->area_addrs) > 0) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 762 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 763 | if (circuit->area->is_type == IS_LEVEL_1) |
| 764 | { |
| 765 | /* 8.2.5.2 b) 1) is_type L1 and adj is not up */ |
| 766 | if (adj->adj_state != ISIS_ADJ_UP) |
| 767 | { |
| 768 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch"); |
| 769 | /* 8.2.5.2 b) 2)is_type L1 and adj is up */ |
| 770 | } |
| 771 | else |
| 772 | { |
| 773 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, |
| 774 | "Down - Area Mismatch"); |
| 775 | } |
| 776 | } |
| 777 | /* 8.2.5.2 b 3 If the system is L2 or L1L2 - table 8 */ |
| 778 | else |
| 779 | { |
| 780 | switch (hdr->circuit_t) |
| 781 | { |
| 782 | case IS_LEVEL_1: |
| 783 | if (adj->adj_state != ISIS_ADJ_UP) |
| 784 | { |
| 785 | /* (6) reject - Area Mismatch event */ |
| 786 | zlog_warn ("AreaMismatch"); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 787 | free_tlvs (&tlvs); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 788 | return ISIS_WARNING; /* Reject */ |
| 789 | } |
| 790 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) |
| 791 | { |
| 792 | /* (7) down - area mismatch */ |
| 793 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch"); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 794 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 795 | } |
| 796 | else if ((adj->adj_usage == ISIS_ADJ_LEVEL1AND2) || |
| 797 | (adj->adj_usage == ISIS_ADJ_LEVEL2)) |
| 798 | { |
| 799 | /* (7) down - wrong system */ |
| 800 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); |
| 801 | } |
| 802 | break; |
| 803 | case IS_LEVEL_1_AND_2: |
| 804 | case IS_LEVEL_2: |
| 805 | if (adj->adj_state != ISIS_ADJ_UP) |
| 806 | { |
| 807 | /* (8) adj state up */ |
| 808 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL); |
| 809 | /* (9) adj usage level 2 */ |
| 810 | adj->adj_usage = ISIS_ADJ_LEVEL2; |
| 811 | } |
| 812 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) |
| 813 | { |
| 814 | /* (7) down - wrong system */ |
| 815 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System"); |
| 816 | } |
| 817 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) |
| 818 | { |
| 819 | if (hdr->circuit_t == IS_LEVEL_2) |
| 820 | { |
| 821 | /* (7) down - wrong system */ |
| 822 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, |
| 823 | "Wrong System"); |
| 824 | } |
| 825 | else |
| 826 | { |
| 827 | /* (7) down - area mismatch */ |
| 828 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, |
| 829 | "Area Mismatch"); |
| 830 | } |
| 831 | } |
| 832 | else if (adj->adj_usage == ISIS_ADJ_LEVEL2) |
| 833 | { |
| 834 | ; /* Accept */ |
| 835 | } |
| 836 | break; |
| 837 | } |
| 838 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 839 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 840 | else |
| 841 | { |
| 842 | /* down - area mismatch */ |
| 843 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch"); |
| 844 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 845 | /* 8.2.5.2 c) if the action was up - comparing circuit IDs */ |
| 846 | /* FIXME - Missing parts */ |
| 847 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 848 | /* some of my own understanding of the ISO, why the heck does |
| 849 | * it not say what should I change the system_type to... |
| 850 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 851 | switch (adj->adj_usage) |
| 852 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 853 | case ISIS_ADJ_LEVEL1: |
| 854 | adj->sys_type = ISIS_SYSTYPE_L1_IS; |
| 855 | break; |
| 856 | case ISIS_ADJ_LEVEL2: |
| 857 | adj->sys_type = ISIS_SYSTYPE_L2_IS; |
| 858 | break; |
| 859 | case ISIS_ADJ_LEVEL1AND2: |
| 860 | adj->sys_type = ISIS_SYSTYPE_L2_IS; |
| 861 | break; |
| 862 | case ISIS_ADJ_NONE: |
| 863 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; |
| 864 | break; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 865 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 866 | |
| 867 | adj->circuit_t = hdr->circuit_t; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 868 | |
| 869 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 870 | { |
| 871 | zlog_debug ("ISIS-Adj (%s): Rcvd P2P IIH from (%s), cir type %s," |
| 872 | " cir id %02d, length %d", |
| 873 | circuit->area->area_tag, circuit->interface->name, |
| 874 | circuit_t2string (circuit->is_type), |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 875 | circuit->circuit_id, pdu_len); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 876 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 877 | |
| 878 | free_tlvs (&tlvs); |
| 879 | |
| 880 | return retval; |
| 881 | } |
| 882 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 883 | /* |
| 884 | * Process IS-IS LAN Level 1/2 Hello PDU |
| 885 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 886 | static int |
| 887 | process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 888 | { |
| 889 | int retval = ISIS_OK; |
| 890 | struct isis_lan_hello_hdr hdr; |
| 891 | struct isis_adjacency *adj; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 892 | u_int32_t expected = 0, found = 0, auth_tlv_offset = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 893 | struct tlvs tlvs; |
| 894 | u_char *snpa; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 895 | struct listnode *node; |
David Lamparter | 28a8cfc | 2014-06-29 13:48:18 +0200 | [diff] [blame] | 896 | int v4_usable = 0, v6_usable = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 897 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 898 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 899 | { |
| 900 | zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH on %s, cirType %s, " |
| 901 | "cirID %u", |
| 902 | circuit->area->area_tag, level, circuit->interface->name, |
| 903 | circuit_t2string (circuit->is_type), circuit->circuit_id); |
| 904 | if (isis->debugs & DEBUG_PACKET_DUMP) |
| 905 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), |
| 906 | stream_get_endp (circuit->rcv_stream)); |
| 907 | } |
| 908 | |
| 909 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 910 | { |
| 911 | zlog_warn ("lan hello on non broadcast circuit"); |
| 912 | return ISIS_WARNING; |
| 913 | } |
| 914 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 915 | if ((stream_get_endp (circuit->rcv_stream) - |
| 916 | stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN) |
| 917 | { |
| 918 | zlog_warn ("Packet too short"); |
| 919 | return ISIS_WARNING; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 920 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 921 | |
| 922 | if (circuit->ext_domain) |
| 923 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 924 | zlog_debug ("level %d LAN Hello received over circuit with " |
| 925 | "externalDomain = true", level); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 926 | return ISIS_WARNING; |
| 927 | } |
| 928 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 929 | if (!accept_level (level, circuit->is_type)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 930 | { |
| 931 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 932 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 933 | zlog_debug ("ISIS-Adj (%s): Interface level mismatch, %s", |
| 934 | circuit->area->area_tag, circuit->interface->name); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 935 | } |
| 936 | return ISIS_WARNING; |
| 937 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 938 | |
| 939 | #if 0 |
| 940 | /* Cisco's debug message compatability */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 941 | if (!accept_level (level, circuit->area->is_type)) |
| 942 | { |
| 943 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 944 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 945 | zlog_debug ("ISIS-Adj (%s): is type mismatch", |
| 946 | circuit->area->area_tag); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 947 | } |
| 948 | return ISIS_WARNING; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 949 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 950 | #endif |
| 951 | /* |
| 952 | * Fill the header |
| 953 | */ |
| 954 | hdr.circuit_t = stream_getc (circuit->rcv_stream); |
| 955 | stream_get (hdr.source_id, circuit->rcv_stream, ISIS_SYS_ID_LEN); |
| 956 | hdr.hold_time = stream_getw (circuit->rcv_stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 957 | hdr.pdu_len = stream_getw (circuit->rcv_stream); |
| 958 | hdr.prio = stream_getc (circuit->rcv_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 959 | stream_get (hdr.lan_id, circuit->rcv_stream, ISIS_SYS_ID_LEN + 1); |
| 960 | |
Avneesh Sachdev | a22ab5a | 2012-05-05 23:50:30 -0700 | [diff] [blame] | 961 | if (hdr.pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LANHELLO_HDRLEN) || |
| 962 | hdr.pdu_len > ISO_MTU(circuit) || |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 963 | hdr.pdu_len > stream_get_endp (circuit->rcv_stream)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 964 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 965 | zlog_warn ("ISIS-Adj (%s): Rcvd LAN IIH from (%s) with " |
| 966 | "invalid pdu length %d", |
| 967 | circuit->area->area_tag, circuit->interface->name, |
| 968 | hdr.pdu_len); |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 969 | return ISIS_WARNING; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 972 | /* |
| 973 | * Set the stream endp to PDU length, ignoring additional padding |
| 974 | * introduced by transport chips. |
| 975 | */ |
| 976 | if (hdr.pdu_len < stream_get_endp (circuit->rcv_stream)) |
| 977 | stream_set_endp (circuit->rcv_stream, hdr.pdu_len); |
| 978 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 979 | if (hdr.circuit_t != IS_LEVEL_1 && |
| 980 | hdr.circuit_t != IS_LEVEL_2 && |
| 981 | hdr.circuit_t != IS_LEVEL_1_AND_2 && |
| 982 | (level & hdr.circuit_t) == 0) |
| 983 | { |
| 984 | zlog_err ("Level %d LAN Hello with Circuit Type %d", level, |
| 985 | hdr.circuit_t); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 986 | return ISIS_ERROR; |
| 987 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 988 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 989 | /* |
| 990 | * Then get the tlvs |
| 991 | */ |
| 992 | expected |= TLVFLAG_AUTH_INFO; |
| 993 | expected |= TLVFLAG_AREA_ADDRS; |
| 994 | expected |= TLVFLAG_LAN_NEIGHS; |
| 995 | expected |= TLVFLAG_NLPID; |
| 996 | expected |= TLVFLAG_IPV4_ADDR; |
| 997 | expected |= TLVFLAG_IPV6_ADDR; |
| 998 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 999 | auth_tlv_offset = stream_get_getp (circuit->rcv_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1000 | retval = parse_tlvs (circuit->area->area_tag, |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1001 | STREAM_PNT (circuit->rcv_stream), |
| 1002 | hdr.pdu_len - ISIS_LANHELLO_HDRLEN - ISIS_FIXED_HDR_LEN, |
| 1003 | &expected, &found, &tlvs, |
| 1004 | &auth_tlv_offset); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1005 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1006 | if (retval > ISIS_WARNING) |
| 1007 | { |
| 1008 | zlog_warn ("parse_tlvs() failed"); |
| 1009 | goto out; |
| 1010 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1011 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1012 | if (!(found & TLVFLAG_AREA_ADDRS)) |
| 1013 | { |
| 1014 | zlog_warn ("No Area addresses TLV in Level %d LAN IS to IS hello", |
| 1015 | level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1016 | retval = ISIS_WARNING; |
| 1017 | goto out; |
| 1018 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1019 | |
David Lamparter | b72f345 | 2012-11-27 01:10:26 +0000 | [diff] [blame] | 1020 | if (!(found & TLVFLAG_NLPID)) |
| 1021 | { |
| 1022 | zlog_warn ("No supported protocols TLV in Level %d LAN IS to IS hello", |
| 1023 | level); |
| 1024 | retval = ISIS_WARNING; |
| 1025 | goto out; |
| 1026 | } |
| 1027 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1028 | /* Verify authentication, either cleartext of HMAC MD5 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1029 | if (circuit->passwd.type) |
| 1030 | { |
| 1031 | if (!(found & TLVFLAG_AUTH_INFO) || |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1032 | authentication_check (&tlvs.auth_info, &circuit->passwd, |
| 1033 | circuit->rcv_stream, auth_tlv_offset)) |
| 1034 | { |
| 1035 | isis_event_auth_failure (circuit->area->area_tag, |
| 1036 | "LAN hello authentication failure", |
| 1037 | hdr.source_id); |
| 1038 | retval = ISIS_WARNING; |
| 1039 | goto out; |
| 1040 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1041 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1042 | |
David Lamparter | 19f78ce | 2012-11-27 01:10:25 +0000 | [diff] [blame] | 1043 | if (!memcmp (hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 1044 | { |
| 1045 | zlog_warn ("ISIS-Adj (%s): duplicate system ID on interface %s", |
| 1046 | circuit->area->area_tag, circuit->interface->name); |
| 1047 | return ISIS_WARNING; |
| 1048 | } |
| 1049 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1050 | /* |
| 1051 | * Accept the level 1 adjacency only if a match between local and |
| 1052 | * remote area addresses is found |
| 1053 | */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1054 | if (listcount (circuit->area->area_addrs) == 0 || |
| 1055 | (level == IS_LEVEL_1 && |
| 1056 | area_match (circuit->area->area_addrs, tlvs.area_addrs) == 0)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1057 | { |
| 1058 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 1059 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1060 | zlog_debug ("ISIS-Adj (%s): Area mismatch, level %d IIH on %s", |
| 1061 | circuit->area->area_tag, level, |
| 1062 | circuit->interface->name); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1063 | } |
| 1064 | retval = ISIS_OK; |
| 1065 | goto out; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1066 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1067 | |
| 1068 | /* |
| 1069 | * it's own IIH PDU - discard silently |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1070 | */ |
| 1071 | if (!memcmp (circuit->u.bc.snpa, ssnpa, ETH_ALEN)) |
| 1072 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1073 | zlog_debug ("ISIS-Adj (%s): it's own IIH PDU - discarded", |
| 1074 | circuit->area->area_tag); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1075 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1076 | retval = ISIS_OK; |
| 1077 | goto out; |
| 1078 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1079 | |
| 1080 | /* |
| 1081 | * check if it's own interface ip match iih ip addrs |
| 1082 | */ |
David Lamparter | 28a8cfc | 2014-06-29 13:48:18 +0200 | [diff] [blame] | 1083 | if (found & TLVFLAG_IPV4_ADDR) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1084 | { |
David Lamparter | 28a8cfc | 2014-06-29 13:48:18 +0200 | [diff] [blame] | 1085 | if (ip_match (circuit->ip_addrs, tlvs.ipv4_addrs)) |
| 1086 | v4_usable = 1; |
| 1087 | else |
| 1088 | zlog_warn ("ISIS-Adj: IPv4 addresses present but no overlap " |
| 1089 | "in LAN IIH from %s\n", circuit->interface->name); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1090 | } |
David Lamparter | 28a8cfc | 2014-06-29 13:48:18 +0200 | [diff] [blame] | 1091 | #ifndef HAVE_IPV6 |
| 1092 | else /* !(found & TLVFLAG_IPV4_ADDR) */ |
| 1093 | zlog_warn ("ISIS-Adj: no IPv4 in LAN IIH from %s " |
| 1094 | "(this isisd has no IPv6)\n", circuit->interface->name); |
| 1095 | |
| 1096 | #else |
| 1097 | if (found & TLVFLAG_IPV6_ADDR) |
| 1098 | { |
| 1099 | /* TBA: check that we have a linklocal ourselves? */ |
| 1100 | struct listnode *node; |
David Lamparter | ad2f92b | 2014-08-18 18:05:25 +0200 | [diff] [blame] | 1101 | struct in6_addr *ip; |
David Lamparter | 28a8cfc | 2014-06-29 13:48:18 +0200 | [diff] [blame] | 1102 | for (ALL_LIST_ELEMENTS_RO (tlvs.ipv6_addrs, node, ip)) |
| 1103 | if (IN6_IS_ADDR_LINKLOCAL (ip)) |
| 1104 | { |
| 1105 | v6_usable = 1; |
| 1106 | break; |
| 1107 | } |
| 1108 | |
| 1109 | if (!v6_usable) |
| 1110 | zlog_warn ("ISIS-Adj: IPv6 addresses present but no link-local " |
| 1111 | "in LAN IIH from %s\n", circuit->interface->name); |
| 1112 | } |
| 1113 | |
| 1114 | if (!(found & (TLVFLAG_IPV4_ADDR | TLVFLAG_IPV6_ADDR))) |
| 1115 | zlog_warn ("ISIS-Adj: neither IPv4 nor IPv6 addr in LAN IIH from %s\n", |
| 1116 | circuit->interface->name); |
| 1117 | #endif |
| 1118 | |
| 1119 | if (!v6_usable && !v4_usable) |
| 1120 | { |
| 1121 | free_tlvs (&tlvs); |
| 1122 | return ISIS_WARNING; |
| 1123 | } |
| 1124 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1125 | |
| 1126 | adj = isis_adj_lookup (hdr.source_id, circuit->u.bc.adjdb[level - 1]); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1127 | if ((adj == NULL) || (memcmp(adj->snpa, ssnpa, ETH_ALEN)) || |
| 1128 | (adj->level != level)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1129 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1130 | if (!adj) |
| 1131 | { |
| 1132 | /* |
| 1133 | * Do as in 8.4.2.5 |
| 1134 | */ |
| 1135 | adj = isis_new_adj (hdr.source_id, ssnpa, level, circuit); |
| 1136 | if (adj == NULL) |
| 1137 | { |
| 1138 | retval = ISIS_ERROR; |
| 1139 | goto out; |
| 1140 | } |
| 1141 | } |
| 1142 | else |
| 1143 | { |
| 1144 | if (ssnpa) { |
| 1145 | memcpy (adj->snpa, ssnpa, 6); |
| 1146 | } else { |
| 1147 | memset (adj->snpa, ' ', 6); |
| 1148 | } |
| 1149 | adj->level = level; |
| 1150 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1151 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1152 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1153 | if (level == IS_LEVEL_1) |
| 1154 | adj->sys_type = ISIS_SYSTYPE_L1_IS; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1155 | else |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1156 | adj->sys_type = ISIS_SYSTYPE_L2_IS; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1157 | list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]); |
| 1158 | isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1], |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1159 | circuit->u.bc.lan_neighs[level - 1]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1160 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1161 | |
hasso | a211d65 | 2004-09-20 14:55:29 +0000 | [diff] [blame] | 1162 | if(adj->dis_record[level-1].dis==ISIS_IS_DIS) |
| 1163 | switch (level) |
| 1164 | { |
| 1165 | case 1: |
| 1166 | if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1)) |
| 1167 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1168 | thread_add_event (master, isis_event_dis_status_change, circuit, 0); |
hasso | 64a7afd | 2004-09-14 11:05:13 +0000 | [diff] [blame] | 1169 | memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id, |
| 1170 | ISIS_SYS_ID_LEN + 1); |
hasso | a211d65 | 2004-09-20 14:55:29 +0000 | [diff] [blame] | 1171 | } |
| 1172 | break; |
| 1173 | case 2: |
| 1174 | if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1)) |
| 1175 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1176 | thread_add_event (master, isis_event_dis_status_change, circuit, 0); |
hasso | 64a7afd | 2004-09-14 11:05:13 +0000 | [diff] [blame] | 1177 | memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id, |
| 1178 | ISIS_SYS_ID_LEN + 1); |
hasso | a211d65 | 2004-09-20 14:55:29 +0000 | [diff] [blame] | 1179 | } |
| 1180 | break; |
| 1181 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1182 | |
| 1183 | adj->hold_time = hdr.hold_time; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1184 | adj->last_upd = time (NULL); |
| 1185 | adj->prio[level - 1] = hdr.prio; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1186 | |
| 1187 | memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1); |
| 1188 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1189 | tlvs_to_adj_area_addrs (&tlvs, adj); |
| 1190 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1191 | /* which protocol are spoken ??? */ |
David Lamparter | b72f345 | 2012-11-27 01:10:26 +0000 | [diff] [blame] | 1192 | if (tlvs_to_adj_nlpids (&tlvs, adj)) |
| 1193 | { |
| 1194 | retval = ISIS_WARNING; |
| 1195 | goto out; |
| 1196 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1197 | |
| 1198 | /* we need to copy addresses to the adj */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1199 | if (found & TLVFLAG_IPV4_ADDR) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1200 | tlvs_to_adj_ipv4_addrs (&tlvs, adj); |
| 1201 | |
| 1202 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1203 | if (found & TLVFLAG_IPV6_ADDR) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1204 | tlvs_to_adj_ipv6_addrs (&tlvs, adj); |
| 1205 | #endif /* HAVE_IPV6 */ |
| 1206 | |
| 1207 | adj->circuit_t = hdr.circuit_t; |
| 1208 | |
| 1209 | /* lets take care of the expiry */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1210 | THREAD_TIMER_OFF (adj->t_expire); |
| 1211 | THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj, |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1212 | (long) adj->hold_time); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1213 | |
| 1214 | /* |
| 1215 | * If the snpa for this circuit is found from LAN Neighbours TLV |
| 1216 | * we have two-way communication -> adjacency can be put to state "up" |
| 1217 | */ |
| 1218 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1219 | if (found & TLVFLAG_LAN_NEIGHS) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1220 | { |
| 1221 | if (adj->adj_state != ISIS_ADJ_UP) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1222 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1223 | for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa)) |
| 1224 | { |
| 1225 | if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN)) |
| 1226 | { |
| 1227 | isis_adj_state_change (adj, ISIS_ADJ_UP, |
| 1228 | "own SNPA found in LAN Neighbours TLV"); |
| 1229 | } |
| 1230 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1231 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1232 | else |
| 1233 | { |
| 1234 | int found = 0; |
| 1235 | for (ALL_LIST_ELEMENTS_RO (tlvs.lan_neighs, node, snpa)) |
| 1236 | if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN)) |
| 1237 | { |
| 1238 | found = 1; |
| 1239 | break; |
| 1240 | } |
| 1241 | if (found == 0) |
| 1242 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, |
| 1243 | "own SNPA not found in LAN Neighbours TLV"); |
| 1244 | } |
| 1245 | } |
| 1246 | else if (adj->adj_state == ISIS_ADJ_UP) |
| 1247 | { |
| 1248 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, |
| 1249 | "no LAN Neighbours TLV found"); |
| 1250 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1251 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1252 | out: |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1253 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 1254 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1255 | zlog_debug ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, " |
| 1256 | "cirID %u, length %ld", |
| 1257 | circuit->area->area_tag, |
| 1258 | level, snpa_print (ssnpa), circuit->interface->name, |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1259 | circuit_t2string (circuit->is_type), |
hasso | 29e50b2 | 2005-09-01 18:18:47 +0000 | [diff] [blame] | 1260 | circuit->circuit_id, |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1261 | stream_get_endp (circuit->rcv_stream)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1262 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1263 | |
| 1264 | free_tlvs (&tlvs); |
| 1265 | |
| 1266 | return retval; |
| 1267 | } |
| 1268 | |
| 1269 | /* |
| 1270 | * Process Level 1/2 Link State |
| 1271 | * ISO - 10589 |
| 1272 | * Section 7.3.15.1 - Action on receipt of a link state PDU |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1273 | */ |
| 1274 | static int |
| 1275 | process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1276 | { |
| 1277 | struct isis_link_state_hdr *hdr; |
| 1278 | struct isis_adjacency *adj = NULL; |
| 1279 | struct isis_lsp *lsp, *lsp0 = NULL; |
| 1280 | int retval = ISIS_OK, comp = 0; |
| 1281 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
| 1282 | struct isis_passwd *passwd; |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1283 | uint16_t pdu_len; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1284 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1285 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 1286 | { |
| 1287 | zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP on %s, cirType %s, cirID %u", |
| 1288 | circuit->area->area_tag, level, circuit->interface->name, |
| 1289 | circuit_t2string (circuit->is_type), circuit->circuit_id); |
| 1290 | if (isis->debugs & DEBUG_PACKET_DUMP) |
| 1291 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), |
| 1292 | stream_get_endp (circuit->rcv_stream)); |
| 1293 | } |
| 1294 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1295 | if ((stream_get_endp (circuit->rcv_stream) - |
| 1296 | stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN) |
| 1297 | { |
| 1298 | zlog_warn ("Packet too short"); |
| 1299 | return ISIS_WARNING; |
| 1300 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1301 | |
| 1302 | /* Reference the header */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1303 | hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream); |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1304 | pdu_len = ntohs (hdr->pdu_len); |
| 1305 | |
| 1306 | /* lsp length check */ |
Avneesh Sachdev | a22ab5a | 2012-05-05 23:50:30 -0700 | [diff] [blame] | 1307 | if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN) || |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1308 | pdu_len > ISO_MTU(circuit) || |
| 1309 | pdu_len > stream_get_endp (circuit->rcv_stream)) |
| 1310 | { |
| 1311 | zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP length %d", |
| 1312 | circuit->area->area_tag, |
| 1313 | rawlspid_print (hdr->lsp_id), pdu_len); |
| 1314 | |
| 1315 | return ISIS_WARNING; |
| 1316 | } |
| 1317 | |
| 1318 | /* |
| 1319 | * Set the stream endp to PDU length, ignoring additional padding |
| 1320 | * introduced by transport chips. |
| 1321 | */ |
| 1322 | if (pdu_len < stream_get_endp (circuit->rcv_stream)) |
| 1323 | stream_set_endp (circuit->rcv_stream, pdu_len); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1324 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1325 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 1326 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1327 | zlog_debug ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, " |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1328 | "lifetime %us, len %u, on %s", |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1329 | circuit->area->area_tag, |
| 1330 | level, |
| 1331 | rawlspid_print (hdr->lsp_id), |
| 1332 | ntohl (hdr->seq_num), |
| 1333 | ntohs (hdr->checksum), |
| 1334 | ntohs (hdr->rem_lifetime), |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1335 | pdu_len, |
paul | 15935e9 | 2005-05-03 09:27:23 +0000 | [diff] [blame] | 1336 | circuit->interface->name); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1337 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1338 | |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1339 | /* lsp is_type check */ |
| 1340 | if ((hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1 && |
| 1341 | (hdr->lsp_bits & IS_LEVEL_1_AND_2) != IS_LEVEL_1_AND_2) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1342 | { |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1343 | zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP is type %x", |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1344 | circuit->area->area_tag, |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1345 | rawlspid_print (hdr->lsp_id), hdr->lsp_bits); |
| 1346 | /* continue as per RFC1122 Be liberal in what you accept, and |
| 1347 | * conservative in what you send */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1348 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1349 | |
| 1350 | /* Checksum sanity check - FIXME: move to correct place */ |
| 1351 | /* 12 = sysid+pdu+remtime */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1352 | if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4, |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1353 | pdu_len - 12, &hdr->checksum)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1354 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1355 | zlog_debug ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x", |
| 1356 | circuit->area->area_tag, |
| 1357 | rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1358 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1359 | return ISIS_WARNING; |
| 1360 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1361 | |
| 1362 | /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1363 | if (circuit->ext_domain) |
| 1364 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1365 | zlog_debug |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1366 | ("ISIS-Upd (%s): LSP %s received at level %d over circuit with " |
| 1367 | "externalDomain = true", circuit->area->area_tag, |
| 1368 | rawlspid_print (hdr->lsp_id), level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1369 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1370 | return ISIS_WARNING; |
| 1371 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1372 | |
| 1373 | /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1374 | if (!accept_level (level, circuit->is_type)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1375 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1376 | zlog_debug ("ISIS-Upd (%s): LSP %s received at level %d over circuit of" |
| 1377 | " type %s", |
| 1378 | circuit->area->area_tag, |
| 1379 | rawlspid_print (hdr->lsp_id), |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1380 | level, circuit_t2string (circuit->is_type)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1381 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1382 | return ISIS_WARNING; |
| 1383 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1384 | |
| 1385 | /* 7.3.15.1 a) 4 - need to make sure IDLength matches */ |
| 1386 | |
| 1387 | /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */ |
| 1388 | |
| 1389 | /* 7.3.15.1 a) 7 - password check */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1390 | (level == IS_LEVEL_1) ? (passwd = &circuit->area->area_passwd) : |
| 1391 | (passwd = &circuit->area->domain_passwd); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1392 | if (passwd->type) |
| 1393 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1394 | if (lsp_authentication_check (circuit->rcv_stream, circuit->area, |
| 1395 | level, passwd)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1396 | { |
| 1397 | isis_event_auth_failure (circuit->area->area_tag, |
| 1398 | "LSP authentication failure", hdr->lsp_id); |
| 1399 | return ISIS_WARNING; |
| 1400 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1401 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1402 | /* Find the LSP in our database and compare it to this Link State header */ |
| 1403 | lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]); |
| 1404 | if (lsp) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1405 | comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num, |
| 1406 | hdr->checksum, hdr->rem_lifetime); |
| 1407 | if (lsp && (lsp->own_lsp |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1408 | #ifdef TOPOLOGY_GENERATE |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1409 | || lsp->from_topology |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1410 | #endif /* TOPOLOGY_GENERATE */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1411 | )) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1412 | goto dontcheckadj; |
| 1413 | |
| 1414 | /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */ |
| 1415 | /* for broadcast circuits, snpa should be compared */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1416 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1417 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 1418 | { |
| 1419 | adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]); |
| 1420 | if (!adj) |
| 1421 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1422 | zlog_debug ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, " |
| 1423 | "lifetime %us on %s", |
| 1424 | circuit->area->area_tag, |
| 1425 | rawlspid_print (hdr->lsp_id), |
| 1426 | ntohl (hdr->seq_num), |
| 1427 | ntohs (hdr->checksum), |
| 1428 | ntohs (hdr->rem_lifetime), circuit->interface->name); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1429 | return ISIS_WARNING; /* Silently discard */ |
| 1430 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1431 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1432 | /* for non broadcast, we just need to find same level adj */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1433 | else |
| 1434 | { |
| 1435 | /* If no adj, or no sharing of level */ |
| 1436 | if (!circuit->u.p2p.neighbor) |
| 1437 | { |
| 1438 | return ISIS_OK; /* Silently discard */ |
| 1439 | } |
| 1440 | else |
| 1441 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1442 | if (((level == IS_LEVEL_1) && |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1443 | (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) || |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1444 | ((level == IS_LEVEL_2) && |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1445 | (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1))) |
| 1446 | return ISIS_WARNING; /* Silently discard */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1447 | adj = circuit->u.p2p.neighbor; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1448 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1449 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1450 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1451 | dontcheckadj: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1452 | /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */ |
| 1453 | |
| 1454 | /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */ |
| 1455 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1456 | /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1457 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1458 | /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */ |
| 1459 | if (hdr->rem_lifetime == 0) |
| 1460 | { |
| 1461 | if (!lsp) |
| 1462 | { |
| 1463 | /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */ |
| 1464 | /* only needed on explicit update, eg - p2p */ |
| 1465 | if (circuit->circ_type == CIRCUIT_T_P2P) |
| 1466 | ack_lsp (hdr, circuit, level); |
| 1467 | return retval; /* FIXME: do we need a purge? */ |
| 1468 | } |
| 1469 | else |
| 1470 | { |
| 1471 | if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 1472 | { |
| 1473 | /* LSP by some other system -> do 7.3.16.4 b) */ |
| 1474 | /* 7.3.16.4 b) 1) */ |
| 1475 | if (comp == LSP_NEWER) |
| 1476 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1477 | lsp_update (lsp, circuit->rcv_stream, circuit->area, level); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1478 | /* ii */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1479 | lsp_set_all_srmflags (lsp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1480 | /* iii */ |
| 1481 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
| 1482 | /* v */ |
| 1483 | ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */ |
| 1484 | /* iv */ |
| 1485 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 1486 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1487 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1488 | } /* 7.3.16.4 b) 2) */ |
| 1489 | else if (comp == LSP_EQUAL) |
| 1490 | { |
| 1491 | /* i */ |
| 1492 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
| 1493 | /* ii */ |
| 1494 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 1495 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
| 1496 | } /* 7.3.16.4 b) 3) */ |
| 1497 | else |
| 1498 | { |
| 1499 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
| 1500 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); |
| 1501 | } |
| 1502 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1503 | else if (lsp->lsp_header->rem_lifetime != 0) |
| 1504 | { |
| 1505 | /* our own LSP -> 7.3.16.4 c) */ |
| 1506 | if (comp == LSP_NEWER) |
| 1507 | { |
| 1508 | lsp_inc_seqnum (lsp, ntohl (hdr->seq_num)); |
| 1509 | lsp_set_all_srmflags (lsp); |
| 1510 | } |
| 1511 | else |
| 1512 | { |
| 1513 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
| 1514 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); |
| 1515 | } |
| 1516 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 1517 | zlog_debug ("ISIS-Upd (%s): (1) re-originating LSP %s new " |
| 1518 | "seq 0x%08x", circuit->area->area_tag, |
| 1519 | rawlspid_print (hdr->lsp_id), |
| 1520 | ntohl (lsp->lsp_header->seq_num)); |
| 1521 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1522 | } |
| 1523 | return retval; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1524 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1525 | /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a |
| 1526 | * purge */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1527 | if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0) |
| 1528 | { |
| 1529 | if (!lsp) |
| 1530 | { |
| 1531 | /* 7.3.16.4: initiate a purge */ |
| 1532 | lsp_purge_non_exist (hdr, circuit->area); |
| 1533 | return ISIS_OK; |
| 1534 | } |
| 1535 | /* 7.3.15.1 d) - If this is our own lsp and we have it */ |
| 1536 | |
| 1537 | /* In 7.3.16.1, If an Intermediate system R somewhere in the domain |
| 1538 | * has information that the current sequence number for source S is |
| 1539 | * "greater" than that held by S, ... */ |
| 1540 | |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1541 | if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1542 | { |
| 1543 | /* 7.3.16.1 */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1544 | lsp_inc_seqnum (lsp, ntohl (hdr->seq_num)); |
hasso | c89c05d | 2005-09-04 21:36:36 +0000 | [diff] [blame] | 1545 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 1546 | zlog_debug ("ISIS-Upd (%s): (2) re-originating LSP %s new seq " |
| 1547 | "0x%08x", circuit->area->area_tag, |
| 1548 | rawlspid_print (hdr->lsp_id), |
| 1549 | ntohl (lsp->lsp_header->seq_num)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1550 | } |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1551 | /* If the received LSP is older or equal, |
| 1552 | * resend the LSP which will act as ACK */ |
| 1553 | lsp_set_all_srmflags (lsp); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1554 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1555 | else |
| 1556 | { |
| 1557 | /* 7.3.15.1 e) - This lsp originated on another system */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1558 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1559 | /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */ |
| 1560 | if ((!lsp || comp == LSP_NEWER)) |
| 1561 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1562 | /* |
| 1563 | * If this lsp is a frag, need to see if we have zero lsp present |
| 1564 | */ |
| 1565 | if (LSP_FRAGMENT (hdr->lsp_id) != 0) |
| 1566 | { |
| 1567 | memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1); |
| 1568 | LSP_FRAGMENT (lspid) = 0; |
| 1569 | lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]); |
| 1570 | if (!lsp0) |
| 1571 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1572 | zlog_debug ("Got lsp frag, while zero lsp not in database"); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1573 | return ISIS_OK; |
| 1574 | } |
| 1575 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1576 | /* i */ |
| 1577 | if (!lsp) |
| 1578 | { |
| 1579 | lsp = lsp_new_from_stream_ptr (circuit->rcv_stream, |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1580 | pdu_len, lsp0, |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1581 | circuit->area, level); |
| 1582 | lsp_insert (lsp, circuit->area->lspdb[level - 1]); |
| 1583 | } |
| 1584 | else /* exists, so we overwrite */ |
| 1585 | { |
| 1586 | lsp_update (lsp, circuit->rcv_stream, circuit->area, level); |
| 1587 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1588 | /* ii */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1589 | lsp_set_all_srmflags (lsp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1590 | /* iii */ |
| 1591 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1592 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1593 | /* iv */ |
| 1594 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 1595 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
| 1596 | /* FIXME: v) */ |
| 1597 | } |
| 1598 | /* 7.3.15.1 e) 2) LSP equal to the one in db */ |
| 1599 | else if (comp == LSP_EQUAL) |
| 1600 | { |
| 1601 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1602 | lsp_update (lsp, circuit->rcv_stream, circuit->area, level); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1603 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1604 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1605 | } |
| 1606 | /* 7.3.15.1 e) 3) LSP older than the one in db */ |
| 1607 | else |
| 1608 | { |
| 1609 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
| 1610 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); |
| 1611 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1612 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1613 | return retval; |
| 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | * Process Sequence Numbers |
| 1618 | * ISO - 10589 |
| 1619 | * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU |
| 1620 | */ |
| 1621 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1622 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1623 | process_snp (int snp_type, int level, struct isis_circuit *circuit, |
| 1624 | u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1625 | { |
| 1626 | int retval = ISIS_OK; |
| 1627 | int cmp, own_lsp; |
| 1628 | char typechar = ' '; |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1629 | uint16_t pdu_len; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1630 | struct isis_adjacency *adj; |
| 1631 | struct isis_complete_seqnum_hdr *chdr = NULL; |
| 1632 | struct isis_partial_seqnum_hdr *phdr = NULL; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1633 | uint32_t found = 0, expected = 0, auth_tlv_offset = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1634 | struct isis_lsp *lsp; |
| 1635 | struct lsp_entry *entry; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1636 | struct listnode *node, *nnode; |
| 1637 | struct listnode *node2, *nnode2; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1638 | struct tlvs tlvs; |
| 1639 | struct list *lsp_list = NULL; |
| 1640 | struct isis_passwd *passwd; |
| 1641 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1642 | if (snp_type == ISIS_SNP_CSNP_FLAG) |
| 1643 | { |
| 1644 | /* getting the header info */ |
| 1645 | typechar = 'C'; |
| 1646 | chdr = |
| 1647 | (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream); |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1648 | stream_forward_getp (circuit->rcv_stream, ISIS_CSNP_HDRLEN); |
| 1649 | pdu_len = ntohs (chdr->pdu_len); |
Avneesh Sachdev | a22ab5a | 2012-05-05 23:50:30 -0700 | [diff] [blame] | 1650 | if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_CSNP_HDRLEN) || |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1651 | pdu_len > ISO_MTU(circuit) || |
| 1652 | pdu_len > stream_get_endp (circuit->rcv_stream)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1653 | { |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1654 | zlog_warn ("Received a CSNP with bogus length %d", pdu_len); |
| 1655 | return ISIS_WARNING; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1656 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1657 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1658 | else |
| 1659 | { |
| 1660 | typechar = 'P'; |
| 1661 | phdr = |
| 1662 | (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream); |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1663 | stream_forward_getp (circuit->rcv_stream, ISIS_PSNP_HDRLEN); |
| 1664 | pdu_len = ntohs (phdr->pdu_len); |
Avneesh Sachdev | a22ab5a | 2012-05-05 23:50:30 -0700 | [diff] [blame] | 1665 | if (pdu_len < (ISIS_FIXED_HDR_LEN + ISIS_PSNP_HDRLEN) || |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1666 | pdu_len > ISO_MTU(circuit) || |
| 1667 | pdu_len > stream_get_endp (circuit->rcv_stream)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1668 | { |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1669 | zlog_warn ("Received a CSNP with bogus length %d", pdu_len); |
| 1670 | return ISIS_WARNING; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1671 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1672 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1673 | |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1674 | /* |
| 1675 | * Set the stream endp to PDU length, ignoring additional padding |
| 1676 | * introduced by transport chips. |
| 1677 | */ |
| 1678 | if (pdu_len < stream_get_endp (circuit->rcv_stream)) |
| 1679 | stream_set_endp (circuit->rcv_stream, pdu_len); |
| 1680 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1681 | /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1682 | if (circuit->ext_domain) |
| 1683 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1684 | |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1685 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, " |
| 1686 | "skipping: circuit externalDomain = true", |
| 1687 | circuit->area->area_tag, |
| 1688 | level, typechar, circuit->interface->name); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1689 | |
| 1690 | return ISIS_OK; |
| 1691 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1692 | |
| 1693 | /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1694 | if (!accept_level (level, circuit->is_type)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1695 | { |
| 1696 | |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1697 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, " |
| 1698 | "skipping: circuit type %s does not match level %d", |
| 1699 | circuit->area->area_tag, |
| 1700 | level, |
| 1701 | typechar, |
| 1702 | circuit->interface->name, |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1703 | circuit_t2string (circuit->is_type), level); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1704 | |
| 1705 | return ISIS_OK; |
| 1706 | } |
| 1707 | |
| 1708 | /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */ |
| 1709 | if ((snp_type == ISIS_SNP_PSNP_FLAG) && |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1710 | (circuit->circ_type == CIRCUIT_T_BROADCAST) && |
| 1711 | (!circuit->u.bc.is_dr[level - 1])) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1712 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1713 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, " |
| 1714 | "skipping: we are not the DIS", |
| 1715 | circuit->area->area_tag, |
| 1716 | level, |
| 1717 | typechar, snpa_print (ssnpa), circuit->interface->name); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1718 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1719 | return ISIS_OK; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1720 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1721 | |
| 1722 | /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */ |
| 1723 | |
| 1724 | /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3 |
| 1725 | * - already checked */ |
| 1726 | |
| 1727 | /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */ |
| 1728 | /* for broadcast circuits, snpa should be compared */ |
| 1729 | /* FIXME : Do we need to check SNPA? */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1730 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 1731 | { |
| 1732 | if (snp_type == ISIS_SNP_CSNP_FLAG) |
| 1733 | { |
| 1734 | adj = |
| 1735 | isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]); |
| 1736 | } |
| 1737 | else |
| 1738 | { |
| 1739 | /* a psnp on a broadcast, how lovely of Juniper :) */ |
| 1740 | adj = |
| 1741 | isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]); |
| 1742 | } |
| 1743 | if (!adj) |
| 1744 | return ISIS_OK; /* Silently discard */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1745 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1746 | else |
| 1747 | { |
| 1748 | if (!circuit->u.p2p.neighbor) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1749 | { |
| 1750 | zlog_warn ("no p2p neighbor on circuit %s", circuit->interface->name); |
| 1751 | return ISIS_OK; /* Silently discard */ |
| 1752 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1753 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1754 | |
| 1755 | /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */ |
| 1756 | |
| 1757 | /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */ |
| 1758 | |
| 1759 | memset (&tlvs, 0, sizeof (struct tlvs)); |
| 1760 | |
| 1761 | /* parse the SNP */ |
| 1762 | expected |= TLVFLAG_LSP_ENTRIES; |
| 1763 | expected |= TLVFLAG_AUTH_INFO; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1764 | |
| 1765 | auth_tlv_offset = stream_get_getp (circuit->rcv_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1766 | retval = parse_tlvs (circuit->area->area_tag, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1767 | STREAM_PNT (circuit->rcv_stream), |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 1768 | pdu_len - stream_get_getp (circuit->rcv_stream), |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1769 | &expected, &found, &tlvs, &auth_tlv_offset); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1770 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1771 | if (retval > ISIS_WARNING) |
| 1772 | { |
| 1773 | zlog_warn ("something went very wrong processing SNP"); |
| 1774 | free_tlvs (&tlvs); |
| 1775 | return retval; |
| 1776 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1777 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1778 | if (level == IS_LEVEL_1) |
hasso | 1cbc562 | 2005-01-01 10:29:51 +0000 | [diff] [blame] | 1779 | passwd = &circuit->area->area_passwd; |
| 1780 | else |
| 1781 | passwd = &circuit->area->domain_passwd; |
| 1782 | |
| 1783 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_RECV)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1784 | { |
hasso | 1cbc562 | 2005-01-01 10:29:51 +0000 | [diff] [blame] | 1785 | if (passwd->type) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1786 | { |
| 1787 | if (!(found & TLVFLAG_AUTH_INFO) || |
| 1788 | authentication_check (&tlvs.auth_info, passwd, |
| 1789 | circuit->rcv_stream, auth_tlv_offset)) |
| 1790 | { |
| 1791 | isis_event_auth_failure (circuit->area->area_tag, |
| 1792 | "SNP authentication" " failure", |
| 1793 | phdr ? phdr->source_id : |
| 1794 | chdr->source_id); |
| 1795 | free_tlvs (&tlvs); |
| 1796 | return ISIS_OK; |
| 1797 | } |
| 1798 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1799 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1800 | |
| 1801 | /* debug isis snp-packets */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1802 | if (isis->debugs & DEBUG_SNP_PACKETS) |
| 1803 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1804 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s", |
| 1805 | circuit->area->area_tag, |
| 1806 | level, |
| 1807 | typechar, snpa_print (ssnpa), circuit->interface->name); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1808 | if (tlvs.lsp_entries) |
| 1809 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1810 | for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1811 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 1812 | zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x," |
| 1813 | " cksum 0x%04x, lifetime %us", |
| 1814 | circuit->area->area_tag, |
| 1815 | typechar, |
| 1816 | rawlspid_print (entry->lsp_id), |
| 1817 | ntohl (entry->seq_num), |
| 1818 | ntohs (entry->checksum), ntohs (entry->rem_lifetime)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1819 | } |
| 1820 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1821 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1822 | |
| 1823 | /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1824 | if (tlvs.lsp_entries) |
| 1825 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1826 | for (ALL_LIST_ELEMENTS_RO (tlvs.lsp_entries, node, entry)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1827 | { |
| 1828 | lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]); |
| 1829 | own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1830 | if (lsp) |
| 1831 | { |
| 1832 | /* 7.3.15.2 b) 1) is this LSP newer */ |
| 1833 | cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num, |
| 1834 | entry->checksum, entry->rem_lifetime); |
| 1835 | /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */ |
| 1836 | if (cmp == LSP_EQUAL) |
| 1837 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1838 | /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */ |
| 1839 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1840 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1841 | /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1842 | else if (cmp == LSP_OLDER) |
| 1843 | { |
| 1844 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); |
| 1845 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
| 1846 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1847 | /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM on p2p */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1848 | else |
| 1849 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1850 | if (own_lsp) |
| 1851 | { |
| 1852 | lsp_inc_seqnum (lsp, ntohl (entry->seq_num)); |
| 1853 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
| 1854 | } |
| 1855 | else |
| 1856 | { |
| 1857 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1858 | /* if (circuit->circ_type != CIRCUIT_T_BROADCAST) */ |
| 1859 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1860 | } |
| 1861 | } |
| 1862 | } |
| 1863 | else |
| 1864 | { |
| 1865 | /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0, |
| 1866 | * insert it and set SSN on it */ |
| 1867 | if (entry->rem_lifetime && entry->checksum && entry->seq_num && |
| 1868 | memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 1869 | { |
| 1870 | lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime), |
| 1871 | 0, 0, entry->checksum, level); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1872 | lsp->area = circuit->area; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1873 | lsp_insert (lsp, circuit->area->lspdb[level - 1]); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1874 | ISIS_FLAGS_CLEAR_ALL (lsp->SRMflags); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1875 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
| 1876 | } |
| 1877 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1878 | } |
| 1879 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1880 | |
| 1881 | /* 7.3.15.2 c) on CSNP set SRM for all in range which were not reported */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1882 | if (snp_type == ISIS_SNP_CSNP_FLAG) |
| 1883 | { |
| 1884 | /* |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1885 | * Build a list from our own LSP db bounded with |
| 1886 | * start_lsp_id and stop_lsp_id |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1887 | */ |
| 1888 | lsp_list = list_new (); |
| 1889 | lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id, |
| 1890 | lsp_list, circuit->area->lspdb[level - 1]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1891 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1892 | /* Fixme: Find a better solution */ |
| 1893 | if (tlvs.lsp_entries) |
| 1894 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1895 | for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1896 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1897 | for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1898 | { |
| 1899 | if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0) |
| 1900 | { |
| 1901 | list_delete_node (lsp_list, node2); |
| 1902 | break; |
| 1903 | } |
| 1904 | } |
| 1905 | } |
| 1906 | } |
| 1907 | /* on remaining LSPs we set SRM (neighbor knew not of) */ |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 1908 | for (ALL_LIST_ELEMENTS_RO (lsp_list, node, lsp)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1909 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1910 | /* lets free it */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1911 | list_delete (lsp_list); |
| 1912 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1913 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1914 | |
| 1915 | free_tlvs (&tlvs); |
| 1916 | return retval; |
| 1917 | } |
| 1918 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1919 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1920 | process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1921 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1922 | if (isis->debugs & DEBUG_SNP_PACKETS) |
| 1923 | { |
| 1924 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d CSNP on %s, cirType %s, cirID %u", |
| 1925 | circuit->area->area_tag, level, circuit->interface->name, |
| 1926 | circuit_t2string (circuit->is_type), circuit->circuit_id); |
| 1927 | if (isis->debugs & DEBUG_PACKET_DUMP) |
| 1928 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), |
| 1929 | stream_get_endp (circuit->rcv_stream)); |
| 1930 | } |
| 1931 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1932 | /* Sanity check - FIXME: move to correct place */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1933 | if ((stream_get_endp (circuit->rcv_stream) - |
| 1934 | stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN) |
| 1935 | { |
| 1936 | zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN); |
| 1937 | return ISIS_WARNING; |
| 1938 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1939 | |
| 1940 | return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa); |
| 1941 | } |
| 1942 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1943 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1944 | process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1945 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1946 | if (isis->debugs & DEBUG_SNP_PACKETS) |
| 1947 | { |
| 1948 | zlog_debug ("ISIS-Snp (%s): Rcvd L%d PSNP on %s, cirType %s, cirID %u", |
| 1949 | circuit->area->area_tag, level, circuit->interface->name, |
| 1950 | circuit_t2string (circuit->is_type), circuit->circuit_id); |
| 1951 | if (isis->debugs & DEBUG_PACKET_DUMP) |
| 1952 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), |
| 1953 | stream_get_endp (circuit->rcv_stream)); |
| 1954 | } |
| 1955 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1956 | if ((stream_get_endp (circuit->rcv_stream) - |
| 1957 | stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN) |
| 1958 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1959 | zlog_warn ("Packet too short ( < %d)", ISIS_PSNP_HDRLEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1960 | return ISIS_WARNING; |
| 1961 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1962 | |
| 1963 | return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa); |
| 1964 | } |
| 1965 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1966 | /* |
| 1967 | * Process ISH |
| 1968 | * ISO - 10589 |
| 1969 | * Section 8.2.2 - Receiving ISH PDUs by an intermediate system |
| 1970 | * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 1971 | * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59 |
| 1972 | * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00 |
| 1973 | * 0x03 0x00 0x81 0x01 0xcc |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1974 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 1975 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1976 | process_is_hello (struct isis_circuit *circuit) |
| 1977 | { |
| 1978 | struct isis_adjacency *adj; |
| 1979 | int retval = ISIS_OK; |
| 1980 | u_char neigh_len; |
| 1981 | u_char *sysid; |
| 1982 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 1983 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 1984 | { |
| 1985 | zlog_debug ("ISIS-Adj (%s): Rcvd ISH on %s, cirType %s, cirID %u", |
| 1986 | circuit->area->area_tag, circuit->interface->name, |
| 1987 | circuit_t2string (circuit->is_type), circuit->circuit_id); |
| 1988 | if (isis->debugs & DEBUG_PACKET_DUMP) |
| 1989 | zlog_dump_data (STREAM_DATA (circuit->rcv_stream), |
| 1990 | stream_get_endp (circuit->rcv_stream)); |
| 1991 | } |
| 1992 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1993 | /* In this point in time we are not yet able to handle is_hellos |
| 1994 | * on lan - Sorry juniper... |
| 1995 | */ |
| 1996 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 1997 | return retval; |
| 1998 | |
| 1999 | neigh_len = stream_getc (circuit->rcv_stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2000 | sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2001 | adj = circuit->u.p2p.neighbor; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2002 | if (!adj) |
| 2003 | { |
| 2004 | /* 8.2.2 */ |
Paul Jakma | 41b36e9 | 2006-12-08 01:09:50 +0000 | [diff] [blame] | 2005 | adj = isis_new_adj (sysid, NULL, 0, circuit); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2006 | if (adj == NULL) |
| 2007 | return ISIS_ERROR; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2008 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2009 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); |
| 2010 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; |
| 2011 | circuit->u.p2p.neighbor = adj; |
| 2012 | } |
| 2013 | /* 8.2.2 a) */ |
| 2014 | if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid, |
| 2015 | ISIS_SYS_ID_LEN)) |
| 2016 | { |
| 2017 | /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */ |
| 2018 | /* 8.2.2 a) 2) delete the adj */ |
| 2019 | XFREE (MTYPE_ISIS_ADJACENCY, adj); |
| 2020 | /* 8.2.2 a) 3) create a new adj */ |
Paul Jakma | 41b36e9 | 2006-12-08 01:09:50 +0000 | [diff] [blame] | 2021 | adj = isis_new_adj (sysid, NULL, 0, circuit); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2022 | if (adj == NULL) |
| 2023 | return ISIS_ERROR; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2024 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2025 | /* 8.2.2 a) 3) i */ |
| 2026 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); |
| 2027 | /* 8.2.2 a) 3) ii */ |
| 2028 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; |
| 2029 | /* 8.2.2 a) 4) quite meaningless */ |
| 2030 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2031 | /* 8.2.2 b) ignore on condition */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2032 | if ((adj->adj_state == ISIS_ADJ_INITIALIZING) && |
| 2033 | (adj->sys_type == ISIS_SYSTYPE_IS)) |
| 2034 | { |
| 2035 | /* do nothing */ |
| 2036 | } |
| 2037 | else |
| 2038 | { |
| 2039 | /* 8.2.2 c) respond with a p2p IIH */ |
| 2040 | send_hello (circuit, 1); |
| 2041 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2042 | /* 8.2.2 d) type is IS */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2043 | adj->sys_type = ISIS_SYSTYPE_IS; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2044 | /* 8.2.2 e) FIXME: Circuit type of? */ |
| 2045 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2046 | return retval; |
| 2047 | } |
| 2048 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2049 | /* |
| 2050 | * PDU Dispatcher |
| 2051 | */ |
| 2052 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 2053 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2054 | isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2055 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2056 | struct isis_fixed_hdr *hdr; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2057 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2058 | int retval = ISIS_OK; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2059 | |
| 2060 | /* |
| 2061 | * Let's first read data from stream to the header |
| 2062 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2063 | hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2064 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2065 | if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS)) |
| 2066 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2067 | zlog_err ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2068 | return ISIS_ERROR; |
| 2069 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2070 | |
| 2071 | /* now we need to know if this is an ISO 9542 packet and |
| 2072 | * take real good care of it, waaa! |
| 2073 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2074 | if (hdr->idrp == ISO9542_ESIS) |
| 2075 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2076 | zlog_err ("No support for ES-IS packet IDRP=%02x", hdr->idrp); |
| 2077 | return ISIS_ERROR; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2078 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2079 | stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN); |
| 2080 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2081 | /* |
| 2082 | * and then process it |
| 2083 | */ |
| 2084 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2085 | if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN) |
| 2086 | { |
| 2087 | zlog_err ("Fixed header length = %d", hdr->length); |
| 2088 | return ISIS_ERROR; |
| 2089 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2090 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2091 | if (hdr->version1 != 1) |
| 2092 | { |
| 2093 | zlog_warn ("Unsupported ISIS version %u", hdr->version1); |
| 2094 | return ISIS_WARNING; |
| 2095 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2096 | /* either 6 or 0 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2097 | if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN)) |
| 2098 | { |
| 2099 | zlog_err |
| 2100 | ("IDFieldLengthMismatch: ID Length field in a received PDU %u, " |
| 2101 | "while the parameter for this IS is %u", hdr->id_len, |
| 2102 | ISIS_SYS_ID_LEN); |
| 2103 | return ISIS_ERROR; |
| 2104 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2105 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2106 | if (hdr->version2 != 1) |
| 2107 | { |
| 2108 | zlog_warn ("Unsupported ISIS version %u", hdr->version2); |
| 2109 | return ISIS_WARNING; |
| 2110 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2111 | |
| 2112 | if (circuit->is_passive) |
| 2113 | { |
| 2114 | zlog_warn ("Received ISIS PDU on passive circuit %s", |
| 2115 | circuit->interface->name); |
| 2116 | return ISIS_WARNING; |
| 2117 | } |
| 2118 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2119 | /* either 3 or 0 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2120 | if ((hdr->max_area_addrs != 0) |
| 2121 | && (hdr->max_area_addrs != isis->max_area_addrs)) |
| 2122 | { |
| 2123 | zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a " |
| 2124 | "received PDU %u while the parameter for this IS is %u", |
| 2125 | hdr->max_area_addrs, isis->max_area_addrs); |
| 2126 | return ISIS_ERROR; |
| 2127 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2128 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2129 | switch (hdr->pdu_type) |
| 2130 | { |
| 2131 | case L1_LAN_HELLO: |
| 2132 | retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa); |
| 2133 | break; |
| 2134 | case L2_LAN_HELLO: |
| 2135 | retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa); |
| 2136 | break; |
| 2137 | case P2P_HELLO: |
| 2138 | retval = process_p2p_hello (circuit); |
| 2139 | break; |
| 2140 | case L1_LINK_STATE: |
| 2141 | retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa); |
| 2142 | break; |
| 2143 | case L2_LINK_STATE: |
| 2144 | retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa); |
| 2145 | break; |
| 2146 | case L1_COMPLETE_SEQ_NUM: |
| 2147 | retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa); |
| 2148 | break; |
| 2149 | case L2_COMPLETE_SEQ_NUM: |
| 2150 | retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa); |
| 2151 | break; |
| 2152 | case L1_PARTIAL_SEQ_NUM: |
| 2153 | retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa); |
| 2154 | break; |
| 2155 | case L2_PARTIAL_SEQ_NUM: |
| 2156 | retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa); |
| 2157 | break; |
| 2158 | default: |
| 2159 | return ISIS_ERROR; |
| 2160 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2161 | |
| 2162 | return retval; |
| 2163 | } |
| 2164 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2165 | #ifdef GNU_LINUX |
| 2166 | int |
| 2167 | isis_receive (struct thread *thread) |
| 2168 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2169 | struct isis_circuit *circuit; |
| 2170 | u_char ssnpa[ETH_ALEN]; |
| 2171 | int retval; |
| 2172 | |
| 2173 | /* |
| 2174 | * Get the circuit |
| 2175 | */ |
| 2176 | circuit = THREAD_ARG (thread); |
| 2177 | assert (circuit); |
| 2178 | |
| 2179 | if (circuit->rcv_stream == NULL) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2180 | circuit->rcv_stream = stream_new (ISO_MTU (circuit)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2181 | else |
| 2182 | stream_reset (circuit->rcv_stream); |
| 2183 | |
| 2184 | retval = circuit->rx (circuit, ssnpa); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2185 | circuit->t_read = NULL; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2186 | |
| 2187 | if (retval == ISIS_OK) |
| 2188 | retval = isis_handle_pdu (circuit, ssnpa); |
| 2189 | |
| 2190 | /* |
| 2191 | * prepare for next packet. |
| 2192 | */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2193 | if (!circuit->is_passive) |
| 2194 | { |
| 2195 | THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit, |
| 2196 | circuit->fd); |
| 2197 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2198 | |
| 2199 | return retval; |
| 2200 | } |
| 2201 | |
| 2202 | #else |
| 2203 | int |
| 2204 | isis_receive (struct thread *thread) |
| 2205 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2206 | struct isis_circuit *circuit; |
| 2207 | u_char ssnpa[ETH_ALEN]; |
| 2208 | int retval; |
| 2209 | |
| 2210 | /* |
| 2211 | * Get the circuit |
| 2212 | */ |
| 2213 | circuit = THREAD_ARG (thread); |
| 2214 | assert (circuit); |
| 2215 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2216 | circuit->t_read = NULL; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2217 | |
| 2218 | if (circuit->rcv_stream == NULL) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2219 | circuit->rcv_stream = stream_new (ISO_MTU (circuit)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2220 | else |
| 2221 | stream_reset (circuit->rcv_stream); |
| 2222 | |
| 2223 | retval = circuit->rx (circuit, ssnpa); |
| 2224 | |
| 2225 | if (retval == ISIS_OK) |
| 2226 | retval = isis_handle_pdu (circuit, ssnpa); |
| 2227 | |
| 2228 | /* |
| 2229 | * prepare for next packet. |
| 2230 | */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2231 | if (!circuit->is_passive) |
| 2232 | { |
| 2233 | circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit, |
| 2234 | listcount |
| 2235 | (circuit->area->circuit_list) * |
| 2236 | 100); |
| 2237 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2238 | |
| 2239 | return retval; |
| 2240 | } |
| 2241 | |
| 2242 | #endif |
| 2243 | |
| 2244 | /* filling of the fixed isis header */ |
| 2245 | void |
| 2246 | fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type) |
| 2247 | { |
| 2248 | memset (hdr, 0, sizeof (struct isis_fixed_hdr)); |
| 2249 | |
| 2250 | hdr->idrp = ISO10589_ISIS; |
| 2251 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2252 | switch (pdu_type) |
| 2253 | { |
| 2254 | case L1_LAN_HELLO: |
| 2255 | case L2_LAN_HELLO: |
| 2256 | hdr->length = ISIS_LANHELLO_HDRLEN; |
| 2257 | break; |
| 2258 | case P2P_HELLO: |
| 2259 | hdr->length = ISIS_P2PHELLO_HDRLEN; |
| 2260 | break; |
| 2261 | case L1_LINK_STATE: |
| 2262 | case L2_LINK_STATE: |
| 2263 | hdr->length = ISIS_LSP_HDR_LEN; |
| 2264 | break; |
| 2265 | case L1_COMPLETE_SEQ_NUM: |
| 2266 | case L2_COMPLETE_SEQ_NUM: |
| 2267 | hdr->length = ISIS_CSNP_HDRLEN; |
| 2268 | break; |
| 2269 | case L1_PARTIAL_SEQ_NUM: |
| 2270 | case L2_PARTIAL_SEQ_NUM: |
| 2271 | hdr->length = ISIS_PSNP_HDRLEN; |
| 2272 | break; |
| 2273 | default: |
| 2274 | zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type); |
| 2275 | return; |
| 2276 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2277 | hdr->length += ISIS_FIXED_HDR_LEN; |
| 2278 | hdr->pdu_type = pdu_type; |
| 2279 | hdr->version1 = 1; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2280 | hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2281 | hdr->version2 = 1; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2282 | hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2283 | } |
| 2284 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2285 | /* |
| 2286 | * SEND SIDE |
| 2287 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 2288 | static void |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2289 | fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2290 | struct stream *stream) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2291 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2292 | fill_fixed_hdr (hdr, pdu_type); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2293 | |
| 2294 | stream_putc (stream, hdr->idrp); |
| 2295 | stream_putc (stream, hdr->length); |
| 2296 | stream_putc (stream, hdr->version1); |
| 2297 | stream_putc (stream, hdr->id_len); |
| 2298 | stream_putc (stream, hdr->pdu_type); |
| 2299 | stream_putc (stream, hdr->version2); |
| 2300 | stream_putc (stream, hdr->reserved); |
| 2301 | stream_putc (stream, hdr->max_area_addrs); |
| 2302 | |
| 2303 | return; |
| 2304 | } |
| 2305 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2306 | int |
| 2307 | send_hello (struct isis_circuit *circuit, int level) |
| 2308 | { |
| 2309 | struct isis_fixed_hdr fixed_hdr; |
| 2310 | struct isis_lan_hello_hdr hello_hdr; |
| 2311 | struct isis_p2p_hello_hdr p2p_hello_hdr; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2312 | unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE]; |
| 2313 | unsigned long len_pointer, length, auth_tlv_offset = 0; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2314 | u_int32_t interval; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2315 | int retval; |
| 2316 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2317 | if (circuit->is_passive) |
| 2318 | return ISIS_OK; |
| 2319 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2320 | if (circuit->interface->mtu == 0) |
| 2321 | { |
| 2322 | zlog_warn ("circuit has zero MTU"); |
| 2323 | return ISIS_WARNING; |
| 2324 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2325 | |
| 2326 | if (!circuit->snd_stream) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2327 | circuit->snd_stream = stream_new (ISO_MTU (circuit)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2328 | else |
| 2329 | stream_reset (circuit->snd_stream); |
| 2330 | |
| 2331 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2332 | if (level == IS_LEVEL_1) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2333 | fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO, |
| 2334 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2335 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2336 | fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO, |
| 2337 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2338 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2339 | fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2340 | |
| 2341 | /* |
| 2342 | * Fill LAN Level 1 or 2 Hello PDU header |
| 2343 | */ |
| 2344 | memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2345 | interval = circuit->hello_multiplier[level - 1] * |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2346 | circuit->hello_interval[level - 1]; |
| 2347 | if (interval > USHRT_MAX) |
| 2348 | interval = USHRT_MAX; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2349 | hello_hdr.circuit_t = circuit->is_type; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2350 | memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2351 | hello_hdr.hold_time = htons ((u_int16_t) interval); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2352 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2353 | hello_hdr.pdu_len = 0; /* Update the PDU Length later */ |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 2354 | len_pointer = stream_get_endp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2355 | |
| 2356 | /* copy the shared part of the hello to the p2p hello if needed */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2357 | if (circuit->circ_type == CIRCUIT_T_P2P) |
| 2358 | { |
| 2359 | memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN); |
| 2360 | p2p_hello_hdr.local_id = circuit->circuit_id; |
| 2361 | /* FIXME: need better understanding */ |
| 2362 | stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2363 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2364 | else |
| 2365 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2366 | hello_hdr.prio = circuit->priority[level - 1]; |
| 2367 | if (level == IS_LEVEL_1) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2368 | { |
| 2369 | memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is, |
| 2370 | ISIS_SYS_ID_LEN + 1); |
| 2371 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2372 | else if (level == IS_LEVEL_2) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2373 | { |
| 2374 | memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is, |
| 2375 | ISIS_SYS_ID_LEN + 1); |
| 2376 | } |
| 2377 | stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN); |
| 2378 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2379 | |
| 2380 | /* |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2381 | * Then the variable length part. |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2382 | */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2383 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2384 | /* add circuit password */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2385 | switch (circuit->passwd.type) |
| 2386 | { |
| 2387 | /* Cleartext */ |
| 2388 | case ISIS_PASSWD_TYPE_CLEARTXT: |
| 2389 | if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len, |
| 2390 | circuit->passwd.passwd, circuit->snd_stream)) |
| 2391 | return ISIS_WARNING; |
| 2392 | break; |
| 2393 | |
| 2394 | /* HMAC MD5 */ |
| 2395 | case ISIS_PASSWD_TYPE_HMAC_MD5: |
| 2396 | /* Remember where TLV is written so we can later overwrite the MD5 hash */ |
| 2397 | auth_tlv_offset = stream_get_endp (circuit->snd_stream); |
| 2398 | memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE); |
| 2399 | if (tlv_add_authinfo (circuit->passwd.type, ISIS_AUTH_MD5_SIZE, |
| 2400 | hmac_md5_hash, circuit->snd_stream)) |
| 2401 | return ISIS_WARNING; |
| 2402 | break; |
| 2403 | |
| 2404 | default: |
| 2405 | break; |
| 2406 | } |
| 2407 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2408 | /* Area Addresses TLV */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2409 | if (listcount (circuit->area->area_addrs) == 0) |
| 2410 | return ISIS_WARNING; |
| 2411 | if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream)) |
| 2412 | return ISIS_WARNING; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2413 | |
| 2414 | /* LAN Neighbors TLV */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2415 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 2416 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2417 | if (level == IS_LEVEL_1 && circuit->u.bc.lan_neighs[0] && |
| 2418 | listcount (circuit->u.bc.lan_neighs[0]) > 0) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2419 | if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0], |
| 2420 | circuit->snd_stream)) |
| 2421 | return ISIS_WARNING; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2422 | if (level == IS_LEVEL_2 && circuit->u.bc.lan_neighs[1] && |
| 2423 | listcount (circuit->u.bc.lan_neighs[1]) > 0) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2424 | if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1], |
| 2425 | circuit->snd_stream)) |
| 2426 | return ISIS_WARNING; |
| 2427 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2428 | |
| 2429 | /* Protocols Supported TLV */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2430 | if (circuit->nlpids.count > 0) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2431 | if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream)) |
| 2432 | return ISIS_WARNING; |
| 2433 | /* IP interface Address TLV */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2434 | if (circuit->ip_router && circuit->ip_addrs && |
| 2435 | listcount (circuit->ip_addrs) > 0) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2436 | if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream)) |
| 2437 | return ISIS_WARNING; |
| 2438 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2439 | #ifdef HAVE_IPV6 |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2440 | /* IPv6 Interface Address TLV */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2441 | if (circuit->ipv6_router && circuit->ipv6_link && |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2442 | listcount (circuit->ipv6_link) > 0) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2443 | if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream)) |
| 2444 | return ISIS_WARNING; |
| 2445 | #endif /* HAVE_IPV6 */ |
| 2446 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2447 | if (circuit->pad_hellos) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2448 | if (tlv_add_padding (circuit->snd_stream)) |
| 2449 | return ISIS_WARNING; |
| 2450 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 2451 | length = stream_get_endp (circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2452 | /* Update PDU length */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2453 | stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2454 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2455 | /* For HMAC MD5 we need to compute the md5 hash and store it */ |
| 2456 | if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) |
| 2457 | { |
| 2458 | hmac_md5 (STREAM_DATA (circuit->snd_stream), |
| 2459 | stream_get_endp (circuit->snd_stream), |
| 2460 | (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len, |
| 2461 | (caddr_t) &hmac_md5_hash); |
| 2462 | /* Copy the hash into the stream */ |
| 2463 | memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3, |
| 2464 | hmac_md5_hash, ISIS_AUTH_MD5_SIZE); |
| 2465 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2466 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2467 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 2468 | { |
| 2469 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 2470 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 2471 | zlog_debug ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld", |
| 2472 | circuit->area->area_tag, level, circuit->interface->name, |
hasso | 29e50b2 | 2005-09-01 18:18:47 +0000 | [diff] [blame] | 2473 | /* FIXME: use %z when we stop supporting old compilers. */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2474 | length); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2475 | } |
| 2476 | else |
| 2477 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 2478 | zlog_debug ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld", |
| 2479 | circuit->area->area_tag, circuit->interface->name, |
hasso | 29e50b2 | 2005-09-01 18:18:47 +0000 | [diff] [blame] | 2480 | /* FIXME: use %z when we stop supporting old compilers. */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2481 | length); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2482 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2483 | if (isis->debugs & DEBUG_PACKET_DUMP) |
| 2484 | zlog_dump_data (STREAM_DATA (circuit->snd_stream), |
| 2485 | stream_get_endp (circuit->snd_stream)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2486 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2487 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2488 | retval = circuit->tx (circuit, level); |
| 2489 | if (retval != ISIS_OK) |
| 2490 | zlog_err ("ISIS-Adj (%s): Send L%d IIH on %s failed", |
| 2491 | circuit->area->area_tag, level, circuit->interface->name); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2492 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2493 | return retval; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | int |
| 2497 | send_lan_l1_hello (struct thread *thread) |
| 2498 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2499 | struct isis_circuit *circuit; |
| 2500 | int retval; |
| 2501 | |
| 2502 | circuit = THREAD_ARG (thread); |
| 2503 | assert (circuit); |
| 2504 | circuit->u.bc.t_send_lan_hello[0] = NULL; |
| 2505 | |
| 2506 | if (circuit->u.bc.run_dr_elect[0]) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2507 | retval = isis_dr_elect (circuit, 1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2508 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2509 | retval = send_hello (circuit, 1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2510 | |
| 2511 | /* set next timer thread */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2512 | THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0], |
| 2513 | send_lan_l1_hello, circuit, |
| 2514 | isis_jitter (circuit->hello_interval[0], IIH_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2515 | |
| 2516 | return retval; |
| 2517 | } |
| 2518 | |
| 2519 | int |
| 2520 | send_lan_l2_hello (struct thread *thread) |
| 2521 | { |
| 2522 | struct isis_circuit *circuit; |
| 2523 | int retval; |
| 2524 | |
| 2525 | circuit = THREAD_ARG (thread); |
| 2526 | assert (circuit); |
| 2527 | circuit->u.bc.t_send_lan_hello[1] = NULL; |
| 2528 | |
| 2529 | if (circuit->u.bc.run_dr_elect[1]) |
| 2530 | retval = isis_dr_elect (circuit, 2); |
| 2531 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2532 | retval = send_hello (circuit, 2); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2533 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2534 | /* set next timer thread */ |
| 2535 | THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1], |
| 2536 | send_lan_l2_hello, circuit, |
| 2537 | isis_jitter (circuit->hello_interval[1], IIH_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2538 | |
| 2539 | return retval; |
| 2540 | } |
| 2541 | |
| 2542 | int |
| 2543 | send_p2p_hello (struct thread *thread) |
| 2544 | { |
| 2545 | struct isis_circuit *circuit; |
| 2546 | |
| 2547 | circuit = THREAD_ARG (thread); |
| 2548 | assert (circuit); |
| 2549 | circuit->u.p2p.t_send_p2p_hello = NULL; |
| 2550 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2551 | send_hello (circuit, 1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2552 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2553 | /* set next timer thread */ |
| 2554 | THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello, |
| 2555 | circuit, isis_jitter (circuit->hello_interval[1], |
| 2556 | IIH_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2557 | |
| 2558 | return ISIS_OK; |
| 2559 | } |
| 2560 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 2561 | static int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2562 | build_csnp (int level, u_char * start, u_char * stop, struct list *lsps, |
| 2563 | struct isis_circuit *circuit) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2564 | { |
| 2565 | struct isis_fixed_hdr fixed_hdr; |
| 2566 | struct isis_passwd *passwd; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2567 | unsigned long lenp; |
| 2568 | u_int16_t length; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2569 | unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE]; |
| 2570 | unsigned long auth_tlv_offset = 0; |
| 2571 | int retval = ISIS_OK; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2572 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2573 | if (circuit->snd_stream == NULL) |
| 2574 | circuit->snd_stream = stream_new (ISO_MTU (circuit)); |
| 2575 | else |
| 2576 | stream_reset (circuit->snd_stream); |
| 2577 | |
| 2578 | if (level == IS_LEVEL_1) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2579 | fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM, |
| 2580 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2581 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2582 | fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM, |
| 2583 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2584 | |
| 2585 | /* |
| 2586 | * Fill Level 1 or 2 Complete Sequence Numbers header |
| 2587 | */ |
| 2588 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 2589 | lenp = stream_get_endp (circuit->snd_stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2590 | stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2591 | /* no need to send the source here, it is always us if we csnp */ |
| 2592 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); |
| 2593 | /* with zero circuit id - ref 9.10, 9.11 */ |
| 2594 | stream_putc (circuit->snd_stream, 0x00); |
| 2595 | |
| 2596 | stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2); |
| 2597 | stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2); |
| 2598 | |
| 2599 | /* |
| 2600 | * And TLVs |
| 2601 | */ |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2602 | if (level == IS_LEVEL_1) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2603 | passwd = &circuit->area->area_passwd; |
| 2604 | else |
| 2605 | passwd = &circuit->area->domain_passwd; |
| 2606 | |
hasso | 1cbc562 | 2005-01-01 10:29:51 +0000 | [diff] [blame] | 2607 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2608 | { |
| 2609 | switch (passwd->type) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2610 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2611 | /* Cleartext */ |
| 2612 | case ISIS_PASSWD_TYPE_CLEARTXT: |
| 2613 | if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len, |
| 2614 | passwd->passwd, circuit->snd_stream)) |
| 2615 | return ISIS_WARNING; |
| 2616 | break; |
| 2617 | |
| 2618 | /* HMAC MD5 */ |
| 2619 | case ISIS_PASSWD_TYPE_HMAC_MD5: |
| 2620 | /* Remember where TLV is written so we can later overwrite the MD5 hash */ |
| 2621 | auth_tlv_offset = stream_get_endp (circuit->snd_stream); |
| 2622 | memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE); |
| 2623 | if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE, |
| 2624 | hmac_md5_hash, circuit->snd_stream)) |
| 2625 | return ISIS_WARNING; |
| 2626 | break; |
| 2627 | |
| 2628 | default: |
| 2629 | break; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2630 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | retval = tlv_add_lsp_entries (lsps, circuit->snd_stream); |
| 2634 | if (retval != ISIS_OK) |
| 2635 | return retval; |
| 2636 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 2637 | length = (u_int16_t) stream_get_endp (circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2638 | /* Update PU length */ |
| 2639 | stream_putw_at (circuit->snd_stream, lenp, length); |
| 2640 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2641 | /* For HMAC MD5 we need to compute the md5 hash and store it */ |
| 2642 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) && |
| 2643 | passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5) |
| 2644 | { |
| 2645 | hmac_md5 (STREAM_DATA (circuit->snd_stream), |
| 2646 | stream_get_endp(circuit->snd_stream), |
| 2647 | (unsigned char *) &passwd->passwd, passwd->len, |
| 2648 | (caddr_t) &hmac_md5_hash); |
| 2649 | /* Copy the hash into the stream */ |
| 2650 | memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3, |
| 2651 | hmac_md5_hash, ISIS_AUTH_MD5_SIZE); |
| 2652 | } |
| 2653 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2654 | return retval; |
| 2655 | } |
| 2656 | |
| 2657 | /* |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2658 | * Count the maximum number of lsps that can be accomodated by a given size. |
| 2659 | */ |
| 2660 | static uint16_t |
| 2661 | get_max_lsp_count (uint16_t size) |
| 2662 | { |
| 2663 | uint16_t tlv_count; |
| 2664 | uint16_t lsp_count; |
| 2665 | uint16_t remaining_size; |
| 2666 | |
| 2667 | /* First count the full size TLVs */ |
| 2668 | tlv_count = size / MAX_LSP_ENTRIES_TLV_SIZE; |
| 2669 | lsp_count = tlv_count * (MAX_LSP_ENTRIES_TLV_SIZE / LSP_ENTRIES_LEN); |
| 2670 | |
| 2671 | /* The last TLV, if any */ |
| 2672 | remaining_size = size % MAX_LSP_ENTRIES_TLV_SIZE; |
| 2673 | if (remaining_size - 2 >= LSP_ENTRIES_LEN) |
| 2674 | lsp_count += (remaining_size - 2) / LSP_ENTRIES_LEN; |
| 2675 | |
| 2676 | return lsp_count; |
| 2677 | } |
| 2678 | |
| 2679 | /* |
| 2680 | * Calculate the length of Authentication Info. TLV. |
| 2681 | */ |
| 2682 | static uint16_t |
| 2683 | auth_tlv_length (int level, struct isis_circuit *circuit) |
| 2684 | { |
| 2685 | struct isis_passwd *passwd; |
| 2686 | uint16_t length; |
| 2687 | |
| 2688 | if (level == IS_LEVEL_1) |
| 2689 | passwd = &circuit->area->area_passwd; |
| 2690 | else |
| 2691 | passwd = &circuit->area->domain_passwd; |
| 2692 | |
| 2693 | /* Also include the length of TLV header */ |
| 2694 | length = AUTH_INFO_HDRLEN; |
| 2695 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) |
| 2696 | { |
| 2697 | switch (passwd->type) |
| 2698 | { |
| 2699 | /* Cleartext */ |
| 2700 | case ISIS_PASSWD_TYPE_CLEARTXT: |
| 2701 | length += passwd->len; |
| 2702 | break; |
| 2703 | |
| 2704 | /* HMAC MD5 */ |
| 2705 | case ISIS_PASSWD_TYPE_HMAC_MD5: |
| 2706 | length += ISIS_AUTH_MD5_SIZE; |
| 2707 | break; |
| 2708 | |
| 2709 | default: |
| 2710 | break; |
| 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | return length; |
| 2715 | } |
| 2716 | |
| 2717 | /* |
| 2718 | * Calculate the maximum number of lsps that can be accomodated in a CSNP/PSNP. |
| 2719 | */ |
| 2720 | static uint16_t |
| 2721 | max_lsps_per_snp (int snp_type, int level, struct isis_circuit *circuit) |
| 2722 | { |
| 2723 | int snp_hdr_len; |
| 2724 | int auth_tlv_len; |
| 2725 | uint16_t lsp_count; |
| 2726 | |
| 2727 | snp_hdr_len = ISIS_FIXED_HDR_LEN; |
| 2728 | if (snp_type == ISIS_SNP_CSNP_FLAG) |
| 2729 | snp_hdr_len += ISIS_CSNP_HDRLEN; |
| 2730 | else |
| 2731 | snp_hdr_len += ISIS_PSNP_HDRLEN; |
| 2732 | |
| 2733 | auth_tlv_len = auth_tlv_length (level, circuit); |
| 2734 | lsp_count = get_max_lsp_count ( |
| 2735 | stream_get_size (circuit->snd_stream) - snp_hdr_len - auth_tlv_len); |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 2736 | return lsp_count; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | /* |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2740 | * FIXME: support multiple CSNPs |
| 2741 | */ |
| 2742 | |
| 2743 | int |
| 2744 | send_csnp (struct isis_circuit *circuit, int level) |
| 2745 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2746 | u_char start[ISIS_SYS_ID_LEN + 2]; |
| 2747 | u_char stop[ISIS_SYS_ID_LEN + 2]; |
| 2748 | struct list *list = NULL; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 2749 | struct listnode *node; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2750 | struct isis_lsp *lsp; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2751 | u_char num_lsps, loop = 1; |
| 2752 | int i, retval = ISIS_OK; |
| 2753 | |
| 2754 | if (circuit->area->lspdb[level - 1] == NULL || |
| 2755 | dict_count (circuit->area->lspdb[level - 1]) == 0) |
| 2756 | return retval; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2757 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2758 | memset (start, 0x00, ISIS_SYS_ID_LEN + 2); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2759 | memset (stop, 0xff, ISIS_SYS_ID_LEN + 2); |
| 2760 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2761 | num_lsps = max_lsps_per_snp (ISIS_SNP_CSNP_FLAG, level, circuit); |
| 2762 | |
| 2763 | while (loop) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2764 | { |
| 2765 | list = list_new (); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2766 | lsp_build_list (start, stop, num_lsps, list, |
| 2767 | circuit->area->lspdb[level - 1]); |
| 2768 | /* |
| 2769 | * Update the stop lsp_id before encoding this CSNP. |
| 2770 | */ |
| 2771 | if (listcount (list) < num_lsps) |
| 2772 | { |
| 2773 | memset (stop, 0xff, ISIS_SYS_ID_LEN + 2); |
| 2774 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2775 | else |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2776 | { |
| 2777 | node = listtail (list); |
| 2778 | lsp = listgetdata (node); |
| 2779 | memcpy (stop, lsp->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 2); |
| 2780 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2781 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2782 | retval = build_csnp (level, start, stop, list, circuit); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2783 | if (retval != ISIS_OK) |
| 2784 | { |
| 2785 | zlog_err ("ISIS-Snp (%s): Build L%d CSNP on %s failed", |
| 2786 | circuit->area->area_tag, level, circuit->interface->name); |
| 2787 | list_delete (list); |
| 2788 | return retval; |
| 2789 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2790 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2791 | if (isis->debugs & DEBUG_SNP_PACKETS) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2792 | { |
| 2793 | zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld", |
| 2794 | circuit->area->area_tag, level, circuit->interface->name, |
| 2795 | stream_get_endp (circuit->snd_stream)); |
| 2796 | for (ALL_LIST_ELEMENTS_RO (list, node, lsp)) |
| 2797 | { |
| 2798 | zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x," |
| 2799 | " cksum 0x%04x, lifetime %us", |
| 2800 | circuit->area->area_tag, |
| 2801 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 2802 | ntohl (lsp->lsp_header->seq_num), |
| 2803 | ntohs (lsp->lsp_header->checksum), |
| 2804 | ntohs (lsp->lsp_header->rem_lifetime)); |
| 2805 | } |
| 2806 | if (isis->debugs & DEBUG_PACKET_DUMP) |
| 2807 | zlog_dump_data (STREAM_DATA (circuit->snd_stream), |
| 2808 | stream_get_endp (circuit->snd_stream)); |
| 2809 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2810 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2811 | retval = circuit->tx (circuit, level); |
| 2812 | if (retval != ISIS_OK) |
| 2813 | { |
| 2814 | zlog_err ("ISIS-Snp (%s): Send L%d CSNP on %s failed", |
| 2815 | circuit->area->area_tag, level, |
| 2816 | circuit->interface->name); |
| 2817 | list_delete (list); |
| 2818 | return retval; |
| 2819 | } |
| 2820 | |
| 2821 | /* |
| 2822 | * Start lsp_id of the next CSNP should be one plus the |
| 2823 | * stop lsp_id in this current CSNP. |
| 2824 | */ |
| 2825 | memcpy (start, stop, ISIS_SYS_ID_LEN + 2); |
| 2826 | loop = 0; |
| 2827 | for (i = ISIS_SYS_ID_LEN + 1; i >= 0; --i) |
| 2828 | { |
| 2829 | if (start[i] < (u_char)0xff) |
| 2830 | { |
| 2831 | start[i] += 1; |
| 2832 | loop = 1; |
| 2833 | break; |
| 2834 | } |
| 2835 | } |
| 2836 | memset (stop, 0xff, ISIS_SYS_ID_LEN + 2); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2837 | list_delete (list); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2838 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2839 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2840 | return retval; |
| 2841 | } |
| 2842 | |
| 2843 | int |
| 2844 | send_l1_csnp (struct thread *thread) |
| 2845 | { |
| 2846 | struct isis_circuit *circuit; |
| 2847 | int retval = ISIS_OK; |
| 2848 | |
| 2849 | circuit = THREAD_ARG (thread); |
| 2850 | assert (circuit); |
| 2851 | |
| 2852 | circuit->t_send_csnp[0] = NULL; |
| 2853 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2854 | if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0]) |
| 2855 | { |
| 2856 | send_csnp (circuit, 1); |
| 2857 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2858 | /* set next timer thread */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2859 | THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit, |
| 2860 | isis_jitter (circuit->csnp_interval[0], CSNP_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2861 | |
| 2862 | return retval; |
| 2863 | } |
| 2864 | |
| 2865 | int |
| 2866 | send_l2_csnp (struct thread *thread) |
| 2867 | { |
| 2868 | struct isis_circuit *circuit; |
| 2869 | int retval = ISIS_OK; |
| 2870 | |
| 2871 | circuit = THREAD_ARG (thread); |
| 2872 | assert (circuit); |
| 2873 | |
| 2874 | circuit->t_send_csnp[1] = NULL; |
| 2875 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2876 | if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1]) |
| 2877 | { |
| 2878 | send_csnp (circuit, 2); |
| 2879 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2880 | /* set next timer thread */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2881 | THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit, |
| 2882 | isis_jitter (circuit->csnp_interval[1], CSNP_JITTER)); |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 2883 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2884 | return retval; |
| 2885 | } |
| 2886 | |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 2887 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2888 | build_psnp (int level, struct isis_circuit *circuit, struct list *lsps) |
| 2889 | { |
| 2890 | struct isis_fixed_hdr fixed_hdr; |
| 2891 | unsigned long lenp; |
| 2892 | u_int16_t length; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2893 | struct isis_lsp *lsp; |
| 2894 | struct isis_passwd *passwd; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 2895 | struct listnode *node; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2896 | unsigned char hmac_md5_hash[ISIS_AUTH_MD5_SIZE]; |
| 2897 | unsigned long auth_tlv_offset = 0; |
| 2898 | int retval = ISIS_OK; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2899 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2900 | if (circuit->snd_stream == NULL) |
| 2901 | circuit->snd_stream = stream_new (ISO_MTU (circuit)); |
| 2902 | else |
| 2903 | stream_reset (circuit->snd_stream); |
| 2904 | |
| 2905 | if (level == IS_LEVEL_1) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2906 | fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM, |
| 2907 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2908 | else |
| 2909 | fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2910 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2911 | |
| 2912 | /* |
| 2913 | * Fill Level 1 or 2 Partial Sequence Numbers header |
| 2914 | */ |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 2915 | lenp = stream_get_endp (circuit->snd_stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2916 | stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2917 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); |
| 2918 | stream_putc (circuit->snd_stream, circuit->idx); |
| 2919 | |
| 2920 | /* |
| 2921 | * And TLVs |
| 2922 | */ |
| 2923 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2924 | if (level == IS_LEVEL_1) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2925 | passwd = &circuit->area->area_passwd; |
| 2926 | else |
| 2927 | passwd = &circuit->area->domain_passwd; |
| 2928 | |
hasso | 1cbc562 | 2005-01-01 10:29:51 +0000 | [diff] [blame] | 2929 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2930 | { |
| 2931 | switch (passwd->type) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2932 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2933 | /* Cleartext */ |
| 2934 | case ISIS_PASSWD_TYPE_CLEARTXT: |
| 2935 | if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, passwd->len, |
| 2936 | passwd->passwd, circuit->snd_stream)) |
| 2937 | return ISIS_WARNING; |
| 2938 | break; |
| 2939 | |
| 2940 | /* HMAC MD5 */ |
| 2941 | case ISIS_PASSWD_TYPE_HMAC_MD5: |
| 2942 | /* Remember where TLV is written so we can later overwrite the MD5 hash */ |
| 2943 | auth_tlv_offset = stream_get_endp (circuit->snd_stream); |
| 2944 | memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE); |
| 2945 | if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE, |
| 2946 | hmac_md5_hash, circuit->snd_stream)) |
| 2947 | return ISIS_WARNING; |
| 2948 | break; |
| 2949 | |
| 2950 | default: |
| 2951 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2952 | } |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | retval = tlv_add_lsp_entries (lsps, circuit->snd_stream); |
| 2956 | if (retval != ISIS_OK) |
| 2957 | return retval; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2958 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2959 | if (isis->debugs & DEBUG_SNP_PACKETS) |
| 2960 | { |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 2961 | for (ALL_LIST_ELEMENTS_RO (lsps, node, lsp)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2962 | { |
hasso | 529d65b | 2004-12-24 00:14:50 +0000 | [diff] [blame] | 2963 | zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x," |
| 2964 | " cksum 0x%04x, lifetime %us", |
| 2965 | circuit->area->area_tag, |
| 2966 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 2967 | ntohl (lsp->lsp_header->seq_num), |
| 2968 | ntohs (lsp->lsp_header->checksum), |
| 2969 | ntohs (lsp->lsp_header->rem_lifetime)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 2970 | } |
| 2971 | } |
| 2972 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 2973 | length = (u_int16_t) stream_get_endp (circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2974 | /* Update PDU length */ |
| 2975 | stream_putw_at (circuit->snd_stream, lenp, length); |
| 2976 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 2977 | /* For HMAC MD5 we need to compute the md5 hash and store it */ |
| 2978 | if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND) && |
| 2979 | passwd->type == ISIS_PASSWD_TYPE_HMAC_MD5) |
| 2980 | { |
| 2981 | hmac_md5 (STREAM_DATA (circuit->snd_stream), |
| 2982 | stream_get_endp(circuit->snd_stream), |
| 2983 | (unsigned char *) &passwd->passwd, passwd->len, |
| 2984 | (caddr_t) &hmac_md5_hash); |
| 2985 | /* Copy the hash into the stream */ |
| 2986 | memcpy (STREAM_DATA (circuit->snd_stream) + auth_tlv_offset + 3, |
| 2987 | hmac_md5_hash, ISIS_AUTH_MD5_SIZE); |
| 2988 | } |
| 2989 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2990 | return ISIS_OK; |
| 2991 | } |
| 2992 | |
| 2993 | /* |
| 2994 | * 7.3.15.4 action on expiration of partial SNP interval |
| 2995 | * level 1 |
| 2996 | */ |
hasso | 9236588 | 2005-01-18 13:53:33 +0000 | [diff] [blame] | 2997 | static int |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2998 | send_psnp (int level, struct isis_circuit *circuit) |
| 2999 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3000 | struct isis_lsp *lsp; |
| 3001 | struct list *list = NULL; |
hasso | 3fdb2dd | 2005-09-28 18:45:54 +0000 | [diff] [blame] | 3002 | struct listnode *node; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3003 | u_char num_lsps; |
| 3004 | int retval = ISIS_OK; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3005 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3006 | if (circuit->circ_type == CIRCUIT_T_BROADCAST && |
| 3007 | circuit->u.bc.is_dr[level - 1]) |
| 3008 | return ISIS_OK; |
| 3009 | |
| 3010 | if (circuit->area->lspdb[level - 1] == NULL || |
| 3011 | dict_count (circuit->area->lspdb[level - 1]) == 0) |
| 3012 | return ISIS_OK; |
| 3013 | |
Subbaiah Venkata | e38e0df | 2012-03-27 23:48:05 -0700 | [diff] [blame] | 3014 | if (! circuit->snd_stream) |
| 3015 | return ISIS_ERROR; |
| 3016 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3017 | num_lsps = max_lsps_per_snp (ISIS_SNP_PSNP_FLAG, level, circuit); |
| 3018 | |
| 3019 | while (1) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3020 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3021 | list = list_new (); |
| 3022 | lsp_build_list_ssn (circuit, num_lsps, list, |
| 3023 | circuit->area->lspdb[level - 1]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3024 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3025 | if (listcount (list) == 0) |
| 3026 | { |
| 3027 | list_delete (list); |
| 3028 | return ISIS_OK; |
| 3029 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3030 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3031 | retval = build_psnp (level, circuit, list); |
| 3032 | if (retval != ISIS_OK) |
| 3033 | { |
| 3034 | zlog_err ("ISIS-Snp (%s): Build L%d PSNP on %s failed", |
| 3035 | circuit->area->area_tag, level, circuit->interface->name); |
| 3036 | list_delete (list); |
| 3037 | return retval; |
| 3038 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3039 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3040 | if (isis->debugs & DEBUG_SNP_PACKETS) |
| 3041 | { |
| 3042 | zlog_debug ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld", |
| 3043 | circuit->area->area_tag, level, |
| 3044 | circuit->interface->name, |
| 3045 | stream_get_endp (circuit->snd_stream)); |
| 3046 | if (isis->debugs & DEBUG_PACKET_DUMP) |
| 3047 | zlog_dump_data (STREAM_DATA (circuit->snd_stream), |
| 3048 | stream_get_endp (circuit->snd_stream)); |
| 3049 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3050 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3051 | retval = circuit->tx (circuit, level); |
| 3052 | if (retval != ISIS_OK) |
| 3053 | { |
| 3054 | zlog_err ("ISIS-Snp (%s): Send L%d PSNP on %s failed", |
| 3055 | circuit->area->area_tag, level, |
| 3056 | circuit->interface->name); |
| 3057 | list_delete (list); |
| 3058 | return retval; |
| 3059 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3060 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3061 | /* |
| 3062 | * sending succeeded, we can clear SSN flags of this circuit |
| 3063 | * for the LSPs in list |
| 3064 | */ |
| 3065 | for (ALL_LIST_ELEMENTS_RO (list, node, lsp)) |
| 3066 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); |
| 3067 | list_delete (list); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3068 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3069 | |
| 3070 | return retval; |
| 3071 | } |
| 3072 | |
| 3073 | int |
| 3074 | send_l1_psnp (struct thread *thread) |
| 3075 | { |
| 3076 | |
| 3077 | struct isis_circuit *circuit; |
| 3078 | int retval = ISIS_OK; |
| 3079 | |
| 3080 | circuit = THREAD_ARG (thread); |
| 3081 | assert (circuit); |
| 3082 | |
| 3083 | circuit->t_send_psnp[0] = NULL; |
| 3084 | |
| 3085 | send_psnp (1, circuit); |
| 3086 | /* set next timer thread */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3087 | THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit, |
| 3088 | isis_jitter (circuit->psnp_interval[0], PSNP_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3089 | |
| 3090 | return retval; |
| 3091 | } |
| 3092 | |
| 3093 | /* |
| 3094 | * 7.3.15.4 action on expiration of partial SNP interval |
| 3095 | * level 2 |
| 3096 | */ |
| 3097 | int |
| 3098 | send_l2_psnp (struct thread *thread) |
| 3099 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3100 | struct isis_circuit *circuit; |
| 3101 | int retval = ISIS_OK; |
| 3102 | |
| 3103 | circuit = THREAD_ARG (thread); |
| 3104 | assert (circuit); |
| 3105 | |
| 3106 | circuit->t_send_psnp[1] = NULL; |
| 3107 | |
| 3108 | send_psnp (2, circuit); |
| 3109 | |
| 3110 | /* set next timer thread */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3111 | THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit, |
| 3112 | isis_jitter (circuit->psnp_interval[1], PSNP_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3113 | |
| 3114 | return retval; |
| 3115 | } |
| 3116 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3117 | /* |
| 3118 | * ISO 10589 - 7.3.14.3 |
| 3119 | */ |
| 3120 | int |
| 3121 | send_lsp (struct thread *thread) |
| 3122 | { |
| 3123 | struct isis_circuit *circuit; |
| 3124 | struct isis_lsp *lsp; |
| 3125 | struct listnode *node; |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3126 | int retval = ISIS_OK; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3127 | |
| 3128 | circuit = THREAD_ARG (thread); |
| 3129 | assert (circuit); |
| 3130 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3131 | if (circuit->state != C_STATE_UP || circuit->is_passive == 1) |
| 3132 | { |
| 3133 | return retval; |
| 3134 | } |
| 3135 | |
Avneesh Sachdev | 0fece07 | 2012-05-06 00:03:07 -0700 | [diff] [blame] | 3136 | node = listhead (circuit->lsp_queue); |
| 3137 | |
| 3138 | /* |
| 3139 | * Handle case where there are no LSPs on the queue. This can |
| 3140 | * happen, for instance, if an adjacency goes down before this |
| 3141 | * thread gets a chance to run. |
| 3142 | */ |
| 3143 | if (!node) |
| 3144 | { |
| 3145 | return retval; |
| 3146 | } |
| 3147 | |
| 3148 | lsp = listgetdata(node); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3149 | |
| 3150 | /* |
| 3151 | * Do not send if levels do not match |
| 3152 | */ |
| 3153 | if (!(lsp->level & circuit->is_type)) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3154 | { |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3155 | list_delete_node (circuit->lsp_queue, node); |
| 3156 | return retval; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3157 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3158 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3159 | /* |
| 3160 | * Do not send if we do not have adjacencies in state up on the circuit |
| 3161 | */ |
| 3162 | if (circuit->upadjcount[lsp->level - 1] == 0) |
| 3163 | { |
| 3164 | list_delete_node (circuit->lsp_queue, node); |
| 3165 | return retval; |
| 3166 | } |
| 3167 | |
| 3168 | /* copy our lsp to the send buffer */ |
| 3169 | stream_copy (circuit->snd_stream, lsp->pdu); |
| 3170 | |
| 3171 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 3172 | { |
| 3173 | zlog_debug |
| 3174 | ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x," |
| 3175 | " lifetime %us on %s", circuit->area->area_tag, lsp->level, |
| 3176 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 3177 | ntohl (lsp->lsp_header->seq_num), |
| 3178 | ntohs (lsp->lsp_header->checksum), |
| 3179 | ntohs (lsp->lsp_header->rem_lifetime), |
| 3180 | circuit->interface->name); |
| 3181 | if (isis->debugs & DEBUG_PACKET_DUMP) |
| 3182 | zlog_dump_data (STREAM_DATA (circuit->snd_stream), |
| 3183 | stream_get_endp (circuit->snd_stream)); |
| 3184 | } |
| 3185 | |
| 3186 | retval = circuit->tx (circuit, lsp->level); |
| 3187 | if (retval != ISIS_OK) |
| 3188 | { |
| 3189 | zlog_err ("ISIS-Upd (%s): Send L%d LSP on %s failed", |
| 3190 | circuit->area->area_tag, lsp->level, |
| 3191 | circuit->interface->name); |
| 3192 | return retval; |
| 3193 | } |
| 3194 | |
| 3195 | /* |
| 3196 | * If the sending succeeded, we can del the lsp from circuits |
| 3197 | * lsp_queue |
| 3198 | */ |
| 3199 | list_delete_node (circuit->lsp_queue, node); |
| 3200 | |
| 3201 | /* Set the last-cleared time if the queue is empty. */ |
| 3202 | /* TODO: Is is possible that new lsps keep being added to the queue |
| 3203 | * that the queue is never empty? */ |
| 3204 | if (list_isempty (circuit->lsp_queue)) |
| 3205 | circuit->lsp_queue_last_cleared = time (NULL); |
| 3206 | |
| 3207 | /* |
| 3208 | * On broadcast circuits also the SRMflag can be cleared |
| 3209 | */ |
| 3210 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 3211 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
| 3212 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3213 | return retval; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3214 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3215 | |
| 3216 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3217 | ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit, |
| 3218 | int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3219 | { |
| 3220 | unsigned long lenp; |
| 3221 | int retval; |
| 3222 | u_int16_t length; |
| 3223 | struct isis_fixed_hdr fixed_hdr; |
| 3224 | |
| 3225 | if (!circuit->snd_stream) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3226 | circuit->snd_stream = stream_new (ISO_MTU (circuit)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3227 | else |
| 3228 | stream_reset (circuit->snd_stream); |
| 3229 | |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3230 | // fill_llc_hdr (stream); |
| 3231 | if (level == IS_LEVEL_1) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3232 | fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM, |
| 3233 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3234 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3235 | fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM, |
| 3236 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3237 | |
| 3238 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 3239 | lenp = stream_get_endp (circuit->snd_stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3240 | stream_putw (circuit->snd_stream, 0); /* PDU length */ |
| 3241 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3242 | stream_putc (circuit->snd_stream, circuit->idx); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3243 | stream_putc (circuit->snd_stream, 9); /* code */ |
| 3244 | stream_putc (circuit->snd_stream, 16); /* len */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3245 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame] | 3246 | stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime)); |
| 3247 | stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2); |
| 3248 | stream_putl (circuit->snd_stream, ntohl (hdr->seq_num)); |
| 3249 | stream_putw (circuit->snd_stream, ntohs (hdr->checksum)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3250 | |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 3251 | length = (u_int16_t) stream_get_endp (circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3252 | /* Update PDU length */ |
| 3253 | stream_putw_at (circuit->snd_stream, lenp, length); |
| 3254 | |
| 3255 | retval = circuit->tx (circuit, level); |
Josh Bailey | 3f045a0 | 2012-03-24 08:35:20 -0700 | [diff] [blame] | 3256 | if (retval != ISIS_OK) |
| 3257 | zlog_err ("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed", |
| 3258 | circuit->area->area_tag, level, |
| 3259 | circuit->interface->name); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 3260 | |
| 3261 | return retval; |
| 3262 | } |