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