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