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