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