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