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) |
| 815 | retval = ISIS_ERROR; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 816 | goto out; |
| 817 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 818 | adj->level = level; |
| 819 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 820 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 821 | if (level == 1) |
| 822 | { |
| 823 | adj->sys_type = ISIS_SYSTYPE_L1_IS; |
| 824 | } |
| 825 | else |
| 826 | { |
| 827 | adj->sys_type = ISIS_SYSTYPE_L2_IS; |
| 828 | } |
| 829 | list_delete_all_node (circuit->u.bc.lan_neighs[level - 1]); |
| 830 | isis_adj_build_neigh_list (circuit->u.bc.adjdb[level - 1], |
| 831 | circuit->u.bc.lan_neighs[level - 1]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 832 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 833 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 834 | switch (level) |
| 835 | { |
| 836 | case 1: |
| 837 | if (memcmp (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1)) |
| 838 | { |
| 839 | thread_add_event (master, isis_event_dis_status_change, circuit, 0); |
| 840 | memcpy (&circuit->u.bc.l1_desig_is, hdr.lan_id, |
| 841 | ISIS_SYS_ID_LEN + 1); |
| 842 | } |
| 843 | break; |
| 844 | case 2: |
| 845 | if (memcmp (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1)) |
| 846 | { |
| 847 | thread_add_event (master, isis_event_dis_status_change, circuit, 0); |
| 848 | memcpy (&circuit->u.bc.l2_desig_is, hdr.lan_id, |
| 849 | ISIS_SYS_ID_LEN + 1); |
| 850 | } |
| 851 | break; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 852 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 853 | |
| 854 | #if 0 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 855 | /* Old solution: believe the lan-header always |
| 856 | */ |
| 857 | if (level == 1) |
| 858 | { |
| 859 | memcpy (circuit->u.bc.l1_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1); |
| 860 | } |
| 861 | else if (level == 2) |
| 862 | { |
| 863 | memcpy (circuit->u.bc.l2_desig_is, hdr.lan_id, ISIS_SYS_ID_LEN + 1); |
| 864 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 865 | #endif |
| 866 | |
| 867 | adj->hold_time = hdr.hold_time; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 868 | adj->last_upd = time (NULL); |
| 869 | adj->prio[level - 1] = hdr.prio; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 870 | |
| 871 | memcpy (adj->lanid, hdr.lan_id, ISIS_SYS_ID_LEN + 1); |
| 872 | |
| 873 | /* which protocol are spoken ??? */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 874 | if (found & TLVFLAG_NLPID) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 875 | tlvs_to_adj_nlpids (&tlvs, adj); |
| 876 | |
| 877 | /* we need to copy addresses to the adj */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 878 | if (found & TLVFLAG_IPV4_ADDR) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 879 | tlvs_to_adj_ipv4_addrs (&tlvs, adj); |
| 880 | |
| 881 | #ifdef HAVE_IPV6 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 882 | if (found & TLVFLAG_IPV6_ADDR) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 883 | tlvs_to_adj_ipv6_addrs (&tlvs, adj); |
| 884 | #endif /* HAVE_IPV6 */ |
| 885 | |
| 886 | adj->circuit_t = hdr.circuit_t; |
| 887 | |
| 888 | /* lets take care of the expiry */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 889 | THREAD_TIMER_OFF (adj->t_expire); |
| 890 | THREAD_TIMER_ON (master, adj->t_expire, isis_adj_expire, adj, |
| 891 | (long) adj->hold_time); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 892 | |
| 893 | /* |
| 894 | * If the snpa for this circuit is found from LAN Neighbours TLV |
| 895 | * we have two-way communication -> adjacency can be put to state "up" |
| 896 | */ |
| 897 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 898 | if (found & TLVFLAG_LAN_NEIGHS) |
| 899 | { |
| 900 | if (adj->adj_state != ISIS_ADJ_UP) |
| 901 | { |
| 902 | LIST_LOOP (tlvs.lan_neighs, snpa, node) |
| 903 | if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN)) |
| 904 | { |
| 905 | isis_adj_state_change (adj, ISIS_ADJ_UP, |
| 906 | "own SNPA found in LAN Neighbours TLV"); |
| 907 | } |
| 908 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 909 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 910 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 911 | out: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 912 | /* DEBUG_ADJ_PACKETS */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 913 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 914 | { |
| 915 | /* FIXME: is this place right? fix missing info */ |
| 916 | zlog_info ("ISIS-Adj (%s): Rcvd L%d LAN IIH from %s on %s, cirType %s, " |
| 917 | "cirID %u, length %ld", |
| 918 | circuit->area->area_tag, |
| 919 | level, snpa_print (ssnpa), circuit->interface->name, |
| 920 | circuit_t2string (circuit->circuit_is_type), |
| 921 | circuit->circuit_id, stream_get_endp (circuit->rcv_stream)); |
| 922 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 923 | |
| 924 | free_tlvs (&tlvs); |
| 925 | |
| 926 | return retval; |
| 927 | } |
| 928 | |
| 929 | /* |
| 930 | * Process Level 1/2 Link State |
| 931 | * ISO - 10589 |
| 932 | * Section 7.3.15.1 - Action on receipt of a link state PDU |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 933 | */ |
| 934 | static int |
| 935 | process_lsp (int level, struct isis_circuit *circuit, u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 936 | { |
| 937 | struct isis_link_state_hdr *hdr; |
| 938 | struct isis_adjacency *adj = NULL; |
| 939 | struct isis_lsp *lsp, *lsp0 = NULL; |
| 940 | int retval = ISIS_OK, comp = 0; |
| 941 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
| 942 | struct isis_passwd *passwd; |
| 943 | |
| 944 | /* Sanity check - FIXME: move to correct place */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 945 | if ((stream_get_endp (circuit->rcv_stream) - |
| 946 | stream_get_getp (circuit->rcv_stream)) < ISIS_LSP_HDR_LEN) |
| 947 | { |
| 948 | zlog_warn ("Packet too short"); |
| 949 | return ISIS_WARNING; |
| 950 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 951 | |
| 952 | /* Reference the header */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 953 | hdr = (struct isis_link_state_hdr *) STREAM_PNT (circuit->rcv_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 954 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 955 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 956 | { |
| 957 | zlog_info ("ISIS-Upd (%s): Rcvd L%d LSP %s, seq 0x%08x, cksum 0x%04x, " |
| 958 | "lifetime %us, len %lu, on %s", |
| 959 | circuit->area->area_tag, |
| 960 | level, |
| 961 | rawlspid_print (hdr->lsp_id), |
| 962 | ntohl (hdr->seq_num), |
| 963 | ntohs (hdr->checksum), |
| 964 | ntohs (hdr->rem_lifetime), |
| 965 | circuit->rcv_stream->endp, circuit->interface->name); |
| 966 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 967 | |
| 968 | assert (ntohs (hdr->pdu_len) > ISIS_LSP_HDR_LEN); |
| 969 | |
| 970 | /* Checksum sanity check - FIXME: move to correct place */ |
| 971 | /* 12 = sysid+pdu+remtime */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 972 | if (iso_csum_verify (STREAM_PNT (circuit->rcv_stream) + 4, |
| 973 | ntohs (hdr->pdu_len) - 12, &hdr->checksum)) |
| 974 | { |
| 975 | zlog_info ("ISIS-Upd (%s): LSP %s invalid LSP checksum 0x%04x", |
| 976 | circuit->area->area_tag, |
| 977 | rawlspid_print (hdr->lsp_id), ntohs (hdr->checksum)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 978 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 979 | return ISIS_WARNING; |
| 980 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 981 | |
| 982 | /* 7.3.15.1 a) 1 - external domain circuit will discard lsps */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 983 | if (circuit->ext_domain) |
| 984 | { |
| 985 | zlog_info |
| 986 | ("ISIS-Upd (%s): LSP %s received at level %d over circuit with " |
| 987 | "externalDomain = true", circuit->area->area_tag, |
| 988 | rawlspid_print (hdr->lsp_id), level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 989 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 990 | return ISIS_WARNING; |
| 991 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 992 | |
| 993 | /* 7.3.15.1 a) 2,3 - manualL2OnlyMode not implemented */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 994 | if (!accept_level (level, circuit->circuit_is_type)) |
| 995 | { |
| 996 | zlog_info ("ISIS-Upd (%s): LSP %s received at level %d over circuit of" |
| 997 | " type %s", |
| 998 | circuit->area->area_tag, |
| 999 | rawlspid_print (hdr->lsp_id), |
| 1000 | level, circuit_t2string (circuit->circuit_is_type)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1001 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1002 | return ISIS_WARNING; |
| 1003 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1004 | |
| 1005 | /* 7.3.15.1 a) 4 - need to make sure IDLength matches */ |
| 1006 | |
| 1007 | /* 7.3.15.1 a) 5 - maximum area match, can be ommited since we only use 3 */ |
| 1008 | |
| 1009 | /* 7.3.15.1 a) 7 - password check */ |
| 1010 | (level == ISIS_LEVEL1) ? (passwd = &circuit->area->area_passwd) : |
| 1011 | (passwd = &circuit->area->domain_passwd); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1012 | if (passwd->type) |
| 1013 | { |
| 1014 | if (isis_lsp_authinfo_check (circuit->rcv_stream, circuit->area, |
| 1015 | ntohs (hdr->pdu_len), passwd)) |
| 1016 | { |
| 1017 | isis_event_auth_failure (circuit->area->area_tag, |
| 1018 | "LSP authentication failure", hdr->lsp_id); |
| 1019 | return ISIS_WARNING; |
| 1020 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1021 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1022 | /* Find the LSP in our database and compare it to this Link State header */ |
| 1023 | lsp = lsp_search (hdr->lsp_id, circuit->area->lspdb[level - 1]); |
| 1024 | if (lsp) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1025 | comp = lsp_compare (circuit->area->area_tag, lsp, hdr->seq_num, |
| 1026 | hdr->checksum, hdr->rem_lifetime); |
| 1027 | if (lsp && (lsp->own_lsp |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1028 | #ifdef TOPOLOGY_GENERATE |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1029 | || lsp->from_topology |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1030 | #endif /* TOPOLOGY_GENERATE */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1031 | )) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1032 | goto dontcheckadj; |
| 1033 | |
| 1034 | /* 7.3.15.1 a) 6 - Must check that we have an adjacency of the same level */ |
| 1035 | /* for broadcast circuits, snpa should be compared */ |
| 1036 | /* FIXME : Point To Point */ |
| 1037 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1038 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 1039 | { |
| 1040 | adj = isis_adj_lookup_snpa (ssnpa, circuit->u.bc.adjdb[level - 1]); |
| 1041 | if (!adj) |
| 1042 | { |
| 1043 | zlog_info ("(%s): DS ======= LSP %s, seq 0x%08x, cksum 0x%04x, " |
| 1044 | "lifetime %us on %s", |
| 1045 | circuit->area->area_tag, |
| 1046 | rawlspid_print (hdr->lsp_id), |
| 1047 | ntohl (hdr->seq_num), |
| 1048 | ntohs (hdr->checksum), |
| 1049 | ntohs (hdr->rem_lifetime), circuit->interface->name); |
| 1050 | return ISIS_WARNING; /* Silently discard */ |
| 1051 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1052 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1053 | |
| 1054 | /* for non broadcast, we just need to find same level adj */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1055 | else |
| 1056 | { |
| 1057 | /* If no adj, or no sharing of level */ |
| 1058 | if (!circuit->u.p2p.neighbor) |
| 1059 | { |
| 1060 | return ISIS_OK; /* Silently discard */ |
| 1061 | } |
| 1062 | else |
| 1063 | { |
| 1064 | if (((level == 1) && |
| 1065 | (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL2)) || |
| 1066 | ((level == 2) && |
| 1067 | (circuit->u.p2p.neighbor->adj_usage == ISIS_ADJ_LEVEL1))) |
| 1068 | return ISIS_WARNING; /* Silently discard */ |
| 1069 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1070 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1071 | dontcheckadj: |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1072 | /* 7.3.15.1 a) 7 - Passwords for level 1 - not implemented */ |
| 1073 | |
| 1074 | /* 7.3.15.1 a) 8 - Passwords for level 2 - not implemented */ |
| 1075 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1076 | /* 7.3.15.1 a) 9 - OriginatingLSPBufferSize - not implemented FIXME: do it */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1077 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1078 | /* 7.3.15.1 b) - If the remaining life time is 0, we perform 7.3.16.4 */ |
| 1079 | if (hdr->rem_lifetime == 0) |
| 1080 | { |
| 1081 | if (!lsp) |
| 1082 | { |
| 1083 | /* 7.3.16.4 a) 1) No LSP in db -> send an ack, but don't save */ |
| 1084 | /* only needed on explicit update, eg - p2p */ |
| 1085 | if (circuit->circ_type == CIRCUIT_T_P2P) |
| 1086 | ack_lsp (hdr, circuit, level); |
| 1087 | return retval; /* FIXME: do we need a purge? */ |
| 1088 | } |
| 1089 | else |
| 1090 | { |
| 1091 | if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 1092 | { |
| 1093 | /* LSP by some other system -> do 7.3.16.4 b) */ |
| 1094 | /* 7.3.16.4 b) 1) */ |
| 1095 | if (comp == LSP_NEWER) |
| 1096 | { |
| 1097 | lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area); |
| 1098 | /* ii */ |
| 1099 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
| 1100 | /* iii */ |
| 1101 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
| 1102 | /* v */ |
| 1103 | ISIS_FLAGS_CLEAR_ALL (lsp->SSNflags); /* FIXME: OTHER than c */ |
| 1104 | /* iv */ |
| 1105 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 1106 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1107 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1108 | } /* 7.3.16.4 b) 2) */ |
| 1109 | else if (comp == LSP_EQUAL) |
| 1110 | { |
| 1111 | /* i */ |
| 1112 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
| 1113 | /* ii */ |
| 1114 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 1115 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
| 1116 | } /* 7.3.16.4 b) 3) */ |
| 1117 | else |
| 1118 | { |
| 1119 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
| 1120 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); |
| 1121 | } |
| 1122 | } |
| 1123 | else |
| 1124 | { |
| 1125 | /* our own LSP -> 7.3.16.4 c) */ |
| 1126 | if (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) != |
| 1127 | circuit->circuit_id |
| 1128 | || (LSP_PSEUDO_ID (lsp->lsp_header->lsp_id) == |
| 1129 | circuit->circuit_id |
| 1130 | && circuit->u.bc.is_dr[level - 1] == 1)) |
| 1131 | { |
| 1132 | lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1); |
| 1133 | zlog_info ("LSP LEN: %d", ntohs (lsp->lsp_header->pdu_len)); |
| 1134 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, |
| 1135 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); |
| 1136 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
| 1137 | zlog_info |
| 1138 | ("ISIS-Upd (%s): (1) re-originating LSP %s new seq 0x%08x", |
| 1139 | circuit->area->area_tag, rawlspid_print (hdr->lsp_id), |
| 1140 | ntohl (lsp->lsp_header->seq_num)); |
| 1141 | lsp->lsp_header->rem_lifetime = |
| 1142 | htons (isis_jitter |
| 1143 | (circuit->area->max_lsp_lifetime[level - 1], |
| 1144 | MAX_AGE_JITTER)); |
| 1145 | } |
| 1146 | else |
| 1147 | { |
| 1148 | /* Got purge for own pseudo-lsp, and we are not DR */ |
| 1149 | lsp_purge_dr (lsp->lsp_header->lsp_id, circuit, level); |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | return retval; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1154 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1155 | /* 7.3.15.1 c) - If this is our own lsp and we don't have it initiate a |
| 1156 | * purge */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1157 | if (memcmp (hdr->lsp_id, isis->sysid, ISIS_SYS_ID_LEN) == 0) |
| 1158 | { |
| 1159 | if (!lsp) |
| 1160 | { |
| 1161 | /* 7.3.16.4: initiate a purge */ |
| 1162 | lsp_purge_non_exist (hdr, circuit->area); |
| 1163 | return ISIS_OK; |
| 1164 | } |
| 1165 | /* 7.3.15.1 d) - If this is our own lsp and we have it */ |
| 1166 | |
| 1167 | /* In 7.3.16.1, If an Intermediate system R somewhere in the domain |
| 1168 | * has information that the current sequence number for source S is |
| 1169 | * "greater" than that held by S, ... */ |
| 1170 | |
| 1171 | else if (ntohl (hdr->seq_num) > ntohl (lsp->lsp_header->seq_num)) |
| 1172 | { |
| 1173 | /* 7.3.16.1 */ |
| 1174 | lsp->lsp_header->seq_num = htonl (ntohl (hdr->seq_num) + 1); |
| 1175 | |
| 1176 | iso_csum_create (STREAM_DATA (lsp->pdu) + 12, |
| 1177 | ntohs (lsp->lsp_header->pdu_len) - 12, 12); |
| 1178 | |
| 1179 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
| 1180 | zlog_info |
| 1181 | ("ISIS-Upd (%s): (2) re-originating LSP %s new seq 0x%08x", |
| 1182 | circuit->area->area_tag, rawlspid_print (hdr->lsp_id), |
| 1183 | ntohl (lsp->lsp_header->seq_num)); |
| 1184 | lsp->lsp_header->rem_lifetime = |
| 1185 | htons (isis_jitter |
| 1186 | (circuit->area->max_lsp_lifetime[level - 1], |
| 1187 | MAX_AGE_JITTER)); |
| 1188 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1189 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1190 | else |
| 1191 | { |
| 1192 | /* 7.3.15.1 e) - This lsp originated on another system */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1193 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1194 | /* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */ |
| 1195 | if ((!lsp || comp == LSP_NEWER)) |
| 1196 | { |
| 1197 | /* i */ |
| 1198 | if (lsp) |
| 1199 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1200 | #ifdef EXTREME_DEBUG |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1201 | zlog_info ("level %d number is - %ld", level, |
| 1202 | circuit->area->lspdb[level - 1]->dict_nodecount); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1203 | #endif /* EXTREME DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1204 | lsp_search_and_destroy (hdr->lsp_id, |
| 1205 | circuit->area->lspdb[level - 1]); |
| 1206 | /* exists, so we overwrite */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1207 | #ifdef EXTREME_DEBUG |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1208 | zlog_info ("level %d number is - %ld", level, |
| 1209 | circuit->area->lspdb[level - 1]->dict_nodecount); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1210 | #endif /* EXTREME DEBUG */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1211 | } |
| 1212 | /* |
| 1213 | * If this lsp is a frag, need to see if we have zero lsp present |
| 1214 | */ |
| 1215 | if (LSP_FRAGMENT (hdr->lsp_id) != 0) |
| 1216 | { |
| 1217 | memcpy (lspid, hdr->lsp_id, ISIS_SYS_ID_LEN + 1); |
| 1218 | LSP_FRAGMENT (lspid) = 0; |
| 1219 | lsp0 = lsp_search (lspid, circuit->area->lspdb[level - 1]); |
| 1220 | if (!lsp0) |
| 1221 | { |
| 1222 | zlog_info ("Got lsp frag, while zero lsp not database"); |
| 1223 | return ISIS_OK; |
| 1224 | } |
| 1225 | } |
| 1226 | lsp = |
| 1227 | lsp_new_from_stream_ptr (circuit->rcv_stream, |
| 1228 | ntohs (hdr->pdu_len), lsp0, |
| 1229 | circuit->area); |
| 1230 | lsp->level = level; |
| 1231 | lsp->adj = adj; |
| 1232 | lsp_insert (lsp, circuit->area->lspdb[level - 1]); |
| 1233 | /* ii */ |
| 1234 | ISIS_FLAGS_SET_ALL (lsp->SRMflags); |
| 1235 | /* iii */ |
| 1236 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1237 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1238 | /* iv */ |
| 1239 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 1240 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
| 1241 | /* FIXME: v) */ |
| 1242 | } |
| 1243 | /* 7.3.15.1 e) 2) LSP equal to the one in db */ |
| 1244 | else if (comp == LSP_EQUAL) |
| 1245 | { |
| 1246 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
| 1247 | lsp_update (lsp, hdr, circuit->rcv_stream, circuit->area); |
| 1248 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 1249 | { |
| 1250 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
| 1251 | } |
| 1252 | } |
| 1253 | /* 7.3.15.1 e) 3) LSP older than the one in db */ |
| 1254 | else |
| 1255 | { |
| 1256 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
| 1257 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); |
| 1258 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1259 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1260 | if (lsp) |
| 1261 | lsp->adj = adj; |
| 1262 | return retval; |
| 1263 | } |
| 1264 | |
| 1265 | /* |
| 1266 | * Process Sequence Numbers |
| 1267 | * ISO - 10589 |
| 1268 | * Section 7.3.15.2 - Action on receipt of a sequence numbers PDU |
| 1269 | */ |
| 1270 | |
| 1271 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1272 | process_snp (int snp_type, int level, struct isis_circuit *circuit, |
| 1273 | u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1274 | { |
| 1275 | int retval = ISIS_OK; |
| 1276 | int cmp, own_lsp; |
| 1277 | char typechar = ' '; |
| 1278 | int len; |
| 1279 | struct isis_adjacency *adj; |
| 1280 | struct isis_complete_seqnum_hdr *chdr = NULL; |
| 1281 | struct isis_partial_seqnum_hdr *phdr = NULL; |
| 1282 | uint32_t found = 0, expected = 0; |
| 1283 | struct isis_lsp *lsp; |
| 1284 | struct lsp_entry *entry; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1285 | struct listnode *node, *node2; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1286 | struct tlvs tlvs; |
| 1287 | struct list *lsp_list = NULL; |
| 1288 | struct isis_passwd *passwd; |
| 1289 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1290 | if (snp_type == ISIS_SNP_CSNP_FLAG) |
| 1291 | { |
| 1292 | /* getting the header info */ |
| 1293 | typechar = 'C'; |
| 1294 | chdr = |
| 1295 | (struct isis_complete_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream); |
| 1296 | circuit->rcv_stream->getp += ISIS_CSNP_HDRLEN; |
| 1297 | len = ntohs (chdr->pdu_len); |
| 1298 | if (len < ISIS_CSNP_HDRLEN) |
| 1299 | { |
| 1300 | zlog_warn ("Received a CSNP with bogus length!"); |
| 1301 | return ISIS_OK; |
| 1302 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1303 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1304 | else |
| 1305 | { |
| 1306 | typechar = 'P'; |
| 1307 | phdr = |
| 1308 | (struct isis_partial_seqnum_hdr *) STREAM_PNT (circuit->rcv_stream); |
| 1309 | circuit->rcv_stream->getp += ISIS_PSNP_HDRLEN; |
| 1310 | len = ntohs (phdr->pdu_len); |
| 1311 | if (len < ISIS_PSNP_HDRLEN) |
| 1312 | { |
| 1313 | zlog_warn ("Received a CSNP with bogus length!"); |
| 1314 | return ISIS_OK; |
| 1315 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1316 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1317 | |
| 1318 | /* 7.3.15.2 a) 1 - external domain circuit will discard snp pdu */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1319 | if (circuit->ext_domain) |
| 1320 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1321 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1322 | zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, " |
| 1323 | "skipping: circuit externalDomain = true", |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1324 | circuit->area->area_tag, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1325 | level, typechar, circuit->interface->name); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1326 | |
| 1327 | return ISIS_OK; |
| 1328 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1329 | |
| 1330 | /* 7.3.15.2 a) 2,3 - manualL2OnlyMode not implemented */ |
| 1331 | if (!accept_level (level, circuit->circuit_is_type)) |
| 1332 | { |
| 1333 | |
| 1334 | zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP on %s, " |
| 1335 | "skipping: circuit type %s does not match level %d", |
| 1336 | circuit->area->area_tag, |
| 1337 | level, |
| 1338 | typechar, |
| 1339 | circuit->interface->name, |
| 1340 | circuit_t2string (circuit->circuit_is_type), level); |
| 1341 | |
| 1342 | return ISIS_OK; |
| 1343 | } |
| 1344 | |
| 1345 | /* 7.3.15.2 a) 4 - not applicable for CSNP only PSNPs on broadcast */ |
| 1346 | if ((snp_type == ISIS_SNP_PSNP_FLAG) && |
| 1347 | (circuit->circ_type == CIRCUIT_T_BROADCAST)) |
| 1348 | { |
| 1349 | if (!circuit->u.bc.is_dr[level - 1]) |
| 1350 | { |
| 1351 | |
| 1352 | zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s, " |
| 1353 | "skipping: we are not the DIS", |
| 1354 | circuit->area->area_tag, |
| 1355 | level, |
| 1356 | typechar, snpa_print (ssnpa), circuit->interface->name); |
| 1357 | |
| 1358 | return ISIS_OK; |
| 1359 | } |
| 1360 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1361 | |
| 1362 | /* 7.3.15.2 a) 5 - need to make sure IDLength matches - already checked */ |
| 1363 | |
| 1364 | /* 7.3.15.2 a) 6 - maximum area match, can be ommited since we only use 3 |
| 1365 | * - already checked */ |
| 1366 | |
| 1367 | /* 7.3.15.2 a) 7 - Must check that we have an adjacency of the same level */ |
| 1368 | /* for broadcast circuits, snpa should be compared */ |
| 1369 | /* FIXME : Do we need to check SNPA? */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1370 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 1371 | { |
| 1372 | if (snp_type == ISIS_SNP_CSNP_FLAG) |
| 1373 | { |
| 1374 | adj = |
| 1375 | isis_adj_lookup (chdr->source_id, circuit->u.bc.adjdb[level - 1]); |
| 1376 | } |
| 1377 | else |
| 1378 | { |
| 1379 | /* a psnp on a broadcast, how lovely of Juniper :) */ |
| 1380 | adj = |
| 1381 | isis_adj_lookup (phdr->source_id, circuit->u.bc.adjdb[level - 1]); |
| 1382 | } |
| 1383 | if (!adj) |
| 1384 | return ISIS_OK; /* Silently discard */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1385 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1386 | else |
| 1387 | { |
| 1388 | if (!circuit->u.p2p.neighbor) |
| 1389 | return ISIS_OK; /* Silently discard */ |
| 1390 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1391 | |
| 1392 | /* 7.3.15.2 a) 8 - Passwords for level 1 - not implemented */ |
| 1393 | |
| 1394 | /* 7.3.15.2 a) 9 - Passwords for level 2 - not implemented */ |
| 1395 | |
| 1396 | memset (&tlvs, 0, sizeof (struct tlvs)); |
| 1397 | |
| 1398 | /* parse the SNP */ |
| 1399 | expected |= TLVFLAG_LSP_ENTRIES; |
| 1400 | expected |= TLVFLAG_AUTH_INFO; |
| 1401 | retval = parse_tlvs (circuit->area->area_tag, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1402 | STREAM_PNT (circuit->rcv_stream), |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1403 | len - circuit->rcv_stream->getp, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1404 | &expected, &found, &tlvs); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1405 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1406 | if (retval > ISIS_WARNING) |
| 1407 | { |
| 1408 | zlog_warn ("something went very wrong processing SNP"); |
| 1409 | free_tlvs (&tlvs); |
| 1410 | return retval; |
| 1411 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1412 | |
| 1413 | (level == 1) ? (passwd = &circuit->area->area_passwd) : |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1414 | (passwd = &circuit->area->domain_passwd); |
| 1415 | if (passwd->type) |
| 1416 | { |
| 1417 | if (!(found & TLVFLAG_AUTH_INFO) || |
| 1418 | authentication_check (passwd, &tlvs.auth_info)) |
| 1419 | { |
| 1420 | isis_event_auth_failure (circuit->area->area_tag, |
| 1421 | "SNP authentication" " failure", |
| 1422 | phdr ? phdr->source_id : chdr->source_id); |
| 1423 | return ISIS_OK; |
| 1424 | } |
| 1425 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1426 | |
| 1427 | /* debug isis snp-packets */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1428 | if (isis->debugs & DEBUG_SNP_PACKETS) |
| 1429 | { |
| 1430 | zlog_info ("ISIS-Snp (%s): Rcvd L%d %cSNP from %s on %s", |
| 1431 | circuit->area->area_tag, |
| 1432 | level, |
| 1433 | typechar, snpa_print (ssnpa), circuit->interface->name); |
| 1434 | if (tlvs.lsp_entries) |
| 1435 | { |
| 1436 | LIST_LOOP (tlvs.lsp_entries, entry, node) |
| 1437 | { |
| 1438 | zlog_info ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x," |
| 1439 | " cksum 0x%04x, lifetime %us", |
| 1440 | circuit->area->area_tag, |
| 1441 | typechar, |
| 1442 | rawlspid_print (entry->lsp_id), |
| 1443 | ntohl (entry->seq_num), |
| 1444 | ntohs (entry->checksum), ntohs (entry->rem_lifetime)); |
| 1445 | } |
| 1446 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1447 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1448 | |
| 1449 | /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1450 | if (tlvs.lsp_entries) |
| 1451 | { |
| 1452 | LIST_LOOP (tlvs.lsp_entries, entry, node) |
| 1453 | { |
| 1454 | lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]); |
| 1455 | own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN); |
| 1456 | if (lsp) |
| 1457 | { |
| 1458 | /* 7.3.15.2 b) 1) is this LSP newer */ |
| 1459 | cmp = lsp_compare (circuit->area->area_tag, lsp, entry->seq_num, |
| 1460 | entry->checksum, entry->rem_lifetime); |
| 1461 | /* 7.3.15.2 b) 2) if it equals, clear SRM on p2p */ |
| 1462 | if (cmp == LSP_EQUAL) |
| 1463 | { |
| 1464 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 1465 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
| 1466 | /* 7.3.15.2 b) 3) if it is older, clear SSN and set SRM */ |
| 1467 | } |
| 1468 | else if (cmp == LSP_OLDER) |
| 1469 | { |
| 1470 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); |
| 1471 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
| 1472 | } |
| 1473 | else |
| 1474 | { |
| 1475 | /* 7.3.15.2 b) 4) if it is newer, set SSN and clear SRM |
| 1476 | * on p2p */ |
| 1477 | if (own_lsp) |
| 1478 | { |
| 1479 | lsp_inc_seqnum (lsp, ntohl (entry->seq_num)); |
| 1480 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
| 1481 | } |
| 1482 | else |
| 1483 | { |
| 1484 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
| 1485 | if (circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 1486 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
| 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | else |
| 1491 | { |
| 1492 | /* 7.3.15.2 b) 5) if it was not found, and all of those are not 0, |
| 1493 | * insert it and set SSN on it */ |
| 1494 | if (entry->rem_lifetime && entry->checksum && entry->seq_num && |
| 1495 | memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 1496 | { |
| 1497 | lsp = lsp_new (entry->lsp_id, ntohs (entry->rem_lifetime), |
| 1498 | 0, 0, entry->checksum, level); |
| 1499 | lsp_insert (lsp, circuit->area->lspdb[level - 1]); |
| 1500 | ISIS_SET_FLAG (lsp->SSNflags, circuit); |
| 1501 | } |
| 1502 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1503 | } |
| 1504 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1505 | |
| 1506 | /* 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^] | 1507 | if (snp_type == ISIS_SNP_CSNP_FLAG) |
| 1508 | { |
| 1509 | /* |
| 1510 | * Build a list from our own LSP db bounded with start_ and stop_lsp_id |
| 1511 | */ |
| 1512 | lsp_list = list_new (); |
| 1513 | lsp_build_list_nonzero_ht (chdr->start_lsp_id, chdr->stop_lsp_id, |
| 1514 | lsp_list, circuit->area->lspdb[level - 1]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1515 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1516 | /* Fixme: Find a better solution */ |
| 1517 | if (tlvs.lsp_entries) |
| 1518 | { |
| 1519 | LIST_LOOP (tlvs.lsp_entries, entry, node) |
| 1520 | { |
| 1521 | LIST_LOOP (lsp_list, lsp, node2) |
| 1522 | { |
| 1523 | if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0) |
| 1524 | { |
| 1525 | list_delete_node (lsp_list, node2); |
| 1526 | break; |
| 1527 | } |
| 1528 | } |
| 1529 | } |
| 1530 | } |
| 1531 | /* on remaining LSPs we set SRM (neighbor knew not of) */ |
| 1532 | LIST_LOOP (lsp_list, lsp, node2) |
| 1533 | { |
| 1534 | ISIS_SET_FLAG (lsp->SRMflags, circuit); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1535 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1536 | /* lets free it */ |
| 1537 | list_free (lsp_list); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1538 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1539 | |
| 1540 | free_tlvs (&tlvs); |
| 1541 | return retval; |
| 1542 | } |
| 1543 | |
| 1544 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1545 | process_csnp (int level, struct isis_circuit *circuit, u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1546 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1547 | /* Sanity check - FIXME: move to correct place */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1548 | if ((stream_get_endp (circuit->rcv_stream) - |
| 1549 | stream_get_getp (circuit->rcv_stream)) < ISIS_CSNP_HDRLEN) |
| 1550 | { |
| 1551 | zlog_warn ("Packet too short ( < %d)", ISIS_CSNP_HDRLEN); |
| 1552 | return ISIS_WARNING; |
| 1553 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1554 | |
| 1555 | return process_snp (ISIS_SNP_CSNP_FLAG, level, circuit, ssnpa); |
| 1556 | } |
| 1557 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1558 | int |
| 1559 | process_psnp (int level, struct isis_circuit *circuit, u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1560 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1561 | if ((stream_get_endp (circuit->rcv_stream) - |
| 1562 | stream_get_getp (circuit->rcv_stream)) < ISIS_PSNP_HDRLEN) |
| 1563 | { |
| 1564 | zlog_warn ("Packet too short"); |
| 1565 | return ISIS_WARNING; |
| 1566 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1567 | |
| 1568 | return process_snp (ISIS_SNP_PSNP_FLAG, level, circuit, ssnpa); |
| 1569 | } |
| 1570 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1571 | /* |
| 1572 | * Process ISH |
| 1573 | * ISO - 10589 |
| 1574 | * Section 8.2.2 - Receiving ISH PDUs by an intermediate system |
| 1575 | * FIXME: sample packet dump, need to figure 0x81 - looks like NLPid |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1576 | * 0x82 0x15 0x01 0x00 0x04 0x01 0x2c 0x59 |
| 1577 | * 0x38 0x08 0x47 0x00 0x01 0x00 0x02 0x00 |
| 1578 | * 0x03 0x00 0x81 0x01 0xcc |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1579 | */ |
| 1580 | int |
| 1581 | process_is_hello (struct isis_circuit *circuit) |
| 1582 | { |
| 1583 | struct isis_adjacency *adj; |
| 1584 | int retval = ISIS_OK; |
| 1585 | u_char neigh_len; |
| 1586 | u_char *sysid; |
| 1587 | |
| 1588 | /* In this point in time we are not yet able to handle is_hellos |
| 1589 | * on lan - Sorry juniper... |
| 1590 | */ |
| 1591 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 1592 | return retval; |
| 1593 | |
| 1594 | neigh_len = stream_getc (circuit->rcv_stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1595 | sysid = STREAM_PNT (circuit->rcv_stream) + neigh_len - 1 - ISIS_SYS_ID_LEN; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1596 | adj = circuit->u.p2p.neighbor; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1597 | if (!adj) |
| 1598 | { |
| 1599 | /* 8.2.2 */ |
| 1600 | adj = isis_new_adj (sysid, " ", 0, circuit); |
| 1601 | if (adj == NULL) |
| 1602 | return ISIS_ERROR; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1603 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1604 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); |
| 1605 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; |
| 1606 | circuit->u.p2p.neighbor = adj; |
| 1607 | } |
| 1608 | /* 8.2.2 a) */ |
| 1609 | if ((adj->adj_state == ISIS_ADJ_UP) && memcmp (adj->sysid, sysid, |
| 1610 | ISIS_SYS_ID_LEN)) |
| 1611 | { |
| 1612 | /* 8.2.2 a) 1) FIXME: adjStateChange(down) event */ |
| 1613 | /* 8.2.2 a) 2) delete the adj */ |
| 1614 | XFREE (MTYPE_ISIS_ADJACENCY, adj); |
| 1615 | /* 8.2.2 a) 3) create a new adj */ |
| 1616 | adj = isis_new_adj (sysid, " ", 0, circuit); |
| 1617 | if (adj == NULL) |
| 1618 | return ISIS_ERROR; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1619 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1620 | /* 8.2.2 a) 3) i */ |
| 1621 | isis_adj_state_change (adj, ISIS_ADJ_INITIALIZING, NULL); |
| 1622 | /* 8.2.2 a) 3) ii */ |
| 1623 | adj->sys_type = ISIS_SYSTYPE_UNKNOWN; |
| 1624 | /* 8.2.2 a) 4) quite meaningless */ |
| 1625 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1626 | /* 8.2.2 b) ignore on condition */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1627 | if ((adj->adj_state == ISIS_ADJ_INITIALIZING) && |
| 1628 | (adj->sys_type == ISIS_SYSTYPE_IS)) |
| 1629 | { |
| 1630 | /* do nothing */ |
| 1631 | } |
| 1632 | else |
| 1633 | { |
| 1634 | /* 8.2.2 c) respond with a p2p IIH */ |
| 1635 | send_hello (circuit, 1); |
| 1636 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1637 | /* 8.2.2 d) type is IS */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1638 | adj->sys_type = ISIS_SYSTYPE_IS; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1639 | /* 8.2.2 e) FIXME: Circuit type of? */ |
| 1640 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1641 | return retval; |
| 1642 | } |
| 1643 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1644 | /* |
| 1645 | * PDU Dispatcher |
| 1646 | */ |
| 1647 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1648 | int |
| 1649 | isis_handle_pdu (struct isis_circuit *circuit, u_char * ssnpa) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1650 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1651 | struct isis_fixed_hdr *hdr; |
| 1652 | struct esis_fixed_hdr *esis_hdr; |
| 1653 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1654 | int retval = ISIS_OK; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1655 | |
| 1656 | /* |
| 1657 | * Let's first read data from stream to the header |
| 1658 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1659 | hdr = (struct isis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1660 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1661 | if ((hdr->idrp != ISO10589_ISIS) && (hdr->idrp != ISO9542_ESIS)) |
| 1662 | { |
| 1663 | zlog_warn ("Not an IS-IS or ES-IS packet IDRP=%02x", hdr->idrp); |
| 1664 | return ISIS_ERROR; |
| 1665 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1666 | |
| 1667 | /* now we need to know if this is an ISO 9542 packet and |
| 1668 | * take real good care of it, waaa! |
| 1669 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1670 | if (hdr->idrp == ISO9542_ESIS) |
| 1671 | { |
| 1672 | esis_hdr = (struct esis_fixed_hdr *) STREAM_DATA (circuit->rcv_stream); |
| 1673 | stream_set_getp (circuit->rcv_stream, ESIS_FIXED_HDR_LEN); |
| 1674 | /* FIXME: Need to do some acceptence tests */ |
| 1675 | /* example length... */ |
| 1676 | switch (esis_hdr->pdu_type) |
| 1677 | { |
| 1678 | case ESH_PDU: |
| 1679 | /* FIXME */ |
| 1680 | break; |
| 1681 | case ISH_PDU: |
| 1682 | zlog_info ("AN ISH PDU!!"); |
| 1683 | retval = process_is_hello (circuit); |
| 1684 | break; |
| 1685 | default: |
| 1686 | return ISIS_ERROR; |
| 1687 | } |
| 1688 | return retval; |
| 1689 | } |
| 1690 | else |
| 1691 | { |
| 1692 | stream_set_getp (circuit->rcv_stream, ISIS_FIXED_HDR_LEN); |
| 1693 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1694 | /* |
| 1695 | * and then process it |
| 1696 | */ |
| 1697 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1698 | if (hdr->length < ISIS_MINIMUM_FIXED_HDR_LEN) |
| 1699 | { |
| 1700 | zlog_err ("Fixed header length = %d", hdr->length); |
| 1701 | return ISIS_ERROR; |
| 1702 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1703 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1704 | if (hdr->version1 != 1) |
| 1705 | { |
| 1706 | zlog_warn ("Unsupported ISIS version %u", hdr->version1); |
| 1707 | return ISIS_WARNING; |
| 1708 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1709 | /* either 6 or 0 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1710 | if ((hdr->id_len != 0) && (hdr->id_len != ISIS_SYS_ID_LEN)) |
| 1711 | { |
| 1712 | zlog_err |
| 1713 | ("IDFieldLengthMismatch: ID Length field in a received PDU %u, " |
| 1714 | "while the parameter for this IS is %u", hdr->id_len, |
| 1715 | ISIS_SYS_ID_LEN); |
| 1716 | return ISIS_ERROR; |
| 1717 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1718 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1719 | if (hdr->version2 != 1) |
| 1720 | { |
| 1721 | zlog_warn ("Unsupported ISIS version %u", hdr->version2); |
| 1722 | return ISIS_WARNING; |
| 1723 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1724 | /* either 3 or 0 */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1725 | if ((hdr->max_area_addrs != 0) |
| 1726 | && (hdr->max_area_addrs != isis->max_area_addrs)) |
| 1727 | { |
| 1728 | zlog_err ("maximumAreaAddressesMismatch: maximumAreaAdresses in a " |
| 1729 | "received PDU %u while the parameter for this IS is %u", |
| 1730 | hdr->max_area_addrs, isis->max_area_addrs); |
| 1731 | return ISIS_ERROR; |
| 1732 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1733 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1734 | switch (hdr->pdu_type) |
| 1735 | { |
| 1736 | case L1_LAN_HELLO: |
| 1737 | retval = process_lan_hello (ISIS_LEVEL1, circuit, ssnpa); |
| 1738 | break; |
| 1739 | case L2_LAN_HELLO: |
| 1740 | retval = process_lan_hello (ISIS_LEVEL2, circuit, ssnpa); |
| 1741 | break; |
| 1742 | case P2P_HELLO: |
| 1743 | retval = process_p2p_hello (circuit); |
| 1744 | break; |
| 1745 | case L1_LINK_STATE: |
| 1746 | retval = process_lsp (ISIS_LEVEL1, circuit, ssnpa); |
| 1747 | break; |
| 1748 | case L2_LINK_STATE: |
| 1749 | retval = process_lsp (ISIS_LEVEL2, circuit, ssnpa); |
| 1750 | break; |
| 1751 | case L1_COMPLETE_SEQ_NUM: |
| 1752 | retval = process_csnp (ISIS_LEVEL1, circuit, ssnpa); |
| 1753 | break; |
| 1754 | case L2_COMPLETE_SEQ_NUM: |
| 1755 | retval = process_csnp (ISIS_LEVEL2, circuit, ssnpa); |
| 1756 | break; |
| 1757 | case L1_PARTIAL_SEQ_NUM: |
| 1758 | retval = process_psnp (ISIS_LEVEL1, circuit, ssnpa); |
| 1759 | break; |
| 1760 | case L2_PARTIAL_SEQ_NUM: |
| 1761 | retval = process_psnp (ISIS_LEVEL2, circuit, ssnpa); |
| 1762 | break; |
| 1763 | default: |
| 1764 | return ISIS_ERROR; |
| 1765 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1766 | |
| 1767 | return retval; |
| 1768 | } |
| 1769 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1770 | #ifdef GNU_LINUX |
| 1771 | int |
| 1772 | isis_receive (struct thread *thread) |
| 1773 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1774 | struct isis_circuit *circuit; |
| 1775 | u_char ssnpa[ETH_ALEN]; |
| 1776 | int retval; |
| 1777 | |
| 1778 | /* |
| 1779 | * Get the circuit |
| 1780 | */ |
| 1781 | circuit = THREAD_ARG (thread); |
| 1782 | assert (circuit); |
| 1783 | |
| 1784 | if (circuit->rcv_stream == NULL) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1785 | circuit->rcv_stream = stream_new (ISO_MTU (circuit)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1786 | else |
| 1787 | stream_reset (circuit->rcv_stream); |
| 1788 | |
| 1789 | retval = circuit->rx (circuit, ssnpa); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1790 | circuit->t_read = NULL; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1791 | |
| 1792 | if (retval == ISIS_OK) |
| 1793 | retval = isis_handle_pdu (circuit, ssnpa); |
| 1794 | |
| 1795 | /* |
| 1796 | * prepare for next packet. |
| 1797 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1798 | THREAD_READ_ON (master, circuit->t_read, isis_receive, circuit, |
| 1799 | circuit->fd); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1800 | |
| 1801 | return retval; |
| 1802 | } |
| 1803 | |
| 1804 | #else |
| 1805 | int |
| 1806 | isis_receive (struct thread *thread) |
| 1807 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1808 | struct isis_circuit *circuit; |
| 1809 | u_char ssnpa[ETH_ALEN]; |
| 1810 | int retval; |
| 1811 | |
| 1812 | /* |
| 1813 | * Get the circuit |
| 1814 | */ |
| 1815 | circuit = THREAD_ARG (thread); |
| 1816 | assert (circuit); |
| 1817 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1818 | circuit->t_read = NULL; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1819 | |
| 1820 | if (circuit->rcv_stream == NULL) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1821 | circuit->rcv_stream = stream_new (ISO_MTU (circuit)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1822 | else |
| 1823 | stream_reset (circuit->rcv_stream); |
| 1824 | |
| 1825 | retval = circuit->rx (circuit, ssnpa); |
| 1826 | |
| 1827 | if (retval == ISIS_OK) |
| 1828 | retval = isis_handle_pdu (circuit, ssnpa); |
| 1829 | |
| 1830 | /* |
| 1831 | * prepare for next packet. |
| 1832 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1833 | circuit->t_read = thread_add_timer_msec (master, isis_receive, circuit, |
| 1834 | listcount |
| 1835 | (circuit->area->circuit_list) * |
| 1836 | 100); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1837 | |
| 1838 | return retval; |
| 1839 | } |
| 1840 | |
| 1841 | #endif |
| 1842 | |
| 1843 | /* filling of the fixed isis header */ |
| 1844 | void |
| 1845 | fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type) |
| 1846 | { |
| 1847 | memset (hdr, 0, sizeof (struct isis_fixed_hdr)); |
| 1848 | |
| 1849 | hdr->idrp = ISO10589_ISIS; |
| 1850 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1851 | switch (pdu_type) |
| 1852 | { |
| 1853 | case L1_LAN_HELLO: |
| 1854 | case L2_LAN_HELLO: |
| 1855 | hdr->length = ISIS_LANHELLO_HDRLEN; |
| 1856 | break; |
| 1857 | case P2P_HELLO: |
| 1858 | hdr->length = ISIS_P2PHELLO_HDRLEN; |
| 1859 | break; |
| 1860 | case L1_LINK_STATE: |
| 1861 | case L2_LINK_STATE: |
| 1862 | hdr->length = ISIS_LSP_HDR_LEN; |
| 1863 | break; |
| 1864 | case L1_COMPLETE_SEQ_NUM: |
| 1865 | case L2_COMPLETE_SEQ_NUM: |
| 1866 | hdr->length = ISIS_CSNP_HDRLEN; |
| 1867 | break; |
| 1868 | case L1_PARTIAL_SEQ_NUM: |
| 1869 | case L2_PARTIAL_SEQ_NUM: |
| 1870 | hdr->length = ISIS_PSNP_HDRLEN; |
| 1871 | break; |
| 1872 | default: |
| 1873 | zlog_warn ("fill_fixed_hdr(): unknown pdu type %d", pdu_type); |
| 1874 | return; |
| 1875 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1876 | hdr->length += ISIS_FIXED_HDR_LEN; |
| 1877 | hdr->pdu_type = pdu_type; |
| 1878 | hdr->version1 = 1; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1879 | hdr->id_len = 0; /* ISIS_SYS_ID_LEN - 0==6 */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1880 | hdr->version2 = 1; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1881 | hdr->max_area_addrs = 0; /* isis->max_area_addrs - 0==3 */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1882 | } |
| 1883 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1884 | /* |
| 1885 | * SEND SIDE |
| 1886 | */ |
| 1887 | void |
| 1888 | fill_fixed_hdr_andstream (struct isis_fixed_hdr *hdr, u_char pdu_type, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1889 | struct stream *stream) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1890 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1891 | fill_fixed_hdr (hdr, pdu_type); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1892 | |
| 1893 | stream_putc (stream, hdr->idrp); |
| 1894 | stream_putc (stream, hdr->length); |
| 1895 | stream_putc (stream, hdr->version1); |
| 1896 | stream_putc (stream, hdr->id_len); |
| 1897 | stream_putc (stream, hdr->pdu_type); |
| 1898 | stream_putc (stream, hdr->version2); |
| 1899 | stream_putc (stream, hdr->reserved); |
| 1900 | stream_putc (stream, hdr->max_area_addrs); |
| 1901 | |
| 1902 | return; |
| 1903 | } |
| 1904 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1905 | int |
| 1906 | send_hello (struct isis_circuit *circuit, int level) |
| 1907 | { |
| 1908 | struct isis_fixed_hdr fixed_hdr; |
| 1909 | struct isis_lan_hello_hdr hello_hdr; |
| 1910 | struct isis_p2p_hello_hdr p2p_hello_hdr; |
| 1911 | |
| 1912 | u_int32_t interval; |
| 1913 | unsigned long len_pointer, length; |
| 1914 | int retval; |
| 1915 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1916 | if (circuit->interface->mtu == 0) |
| 1917 | { |
| 1918 | zlog_warn ("circuit has zero MTU"); |
| 1919 | return ISIS_WARNING; |
| 1920 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1921 | |
| 1922 | if (!circuit->snd_stream) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1923 | circuit->snd_stream = stream_new (ISO_MTU (circuit)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1924 | else |
| 1925 | stream_reset (circuit->snd_stream); |
| 1926 | |
| 1927 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 1928 | if (level == 1) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1929 | fill_fixed_hdr_andstream (&fixed_hdr, L1_LAN_HELLO, |
| 1930 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1931 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1932 | fill_fixed_hdr_andstream (&fixed_hdr, L2_LAN_HELLO, |
| 1933 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1934 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1935 | fill_fixed_hdr_andstream (&fixed_hdr, P2P_HELLO, circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1936 | |
| 1937 | /* |
| 1938 | * Fill LAN Level 1 or 2 Hello PDU header |
| 1939 | */ |
| 1940 | memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr)); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1941 | interval = circuit->hello_multiplier[level - 1] * |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1942 | circuit->hello_interval[level - 1]; |
| 1943 | if (interval > USHRT_MAX) |
| 1944 | interval = USHRT_MAX; |
| 1945 | hello_hdr.circuit_t = circuit->circuit_is_type; |
| 1946 | memcpy (hello_hdr.source_id, isis->sysid, ISIS_SYS_ID_LEN); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1947 | hello_hdr.hold_time = htons ((u_int16_t) interval); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1948 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1949 | hello_hdr.pdu_len = 0; /* Update the PDU Length later */ |
| 1950 | len_pointer = stream_get_putp (circuit->snd_stream) + 3 + ISIS_SYS_ID_LEN; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1951 | |
| 1952 | /* copy the shared part of the hello to the p2p hello if needed */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1953 | if (circuit->circ_type == CIRCUIT_T_P2P) |
| 1954 | { |
| 1955 | memcpy (&p2p_hello_hdr, &hello_hdr, 5 + ISIS_SYS_ID_LEN); |
| 1956 | p2p_hello_hdr.local_id = circuit->circuit_id; |
| 1957 | /* FIXME: need better understanding */ |
| 1958 | stream_put (circuit->snd_stream, &p2p_hello_hdr, ISIS_P2PHELLO_HDRLEN); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1959 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1960 | else |
| 1961 | { |
| 1962 | hello_hdr.prio = circuit->u.bc.priority[level - 1]; |
| 1963 | if (level == 1 && circuit->u.bc.l1_desig_is) |
| 1964 | { |
| 1965 | memcpy (hello_hdr.lan_id, circuit->u.bc.l1_desig_is, |
| 1966 | ISIS_SYS_ID_LEN + 1); |
| 1967 | } |
| 1968 | else if (level == 2 && circuit->u.bc.l2_desig_is) |
| 1969 | { |
| 1970 | memcpy (hello_hdr.lan_id, circuit->u.bc.l2_desig_is, |
| 1971 | ISIS_SYS_ID_LEN + 1); |
| 1972 | } |
| 1973 | stream_put (circuit->snd_stream, &hello_hdr, ISIS_LANHELLO_HDRLEN); |
| 1974 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1975 | |
| 1976 | /* |
| 1977 | * Then the variable length part |
| 1978 | */ |
| 1979 | /* add circuit password */ |
| 1980 | if (circuit->passwd.type) |
| 1981 | if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len, |
| 1982 | circuit->passwd.passwd, circuit->snd_stream)) |
| 1983 | return ISIS_WARNING; |
| 1984 | /* Area Addresses TLV */ |
| 1985 | assert (circuit->area); |
| 1986 | if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0) |
| 1987 | if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream)) |
| 1988 | return ISIS_WARNING; |
| 1989 | |
| 1990 | /* LAN Neighbors TLV */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 1991 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 1992 | { |
| 1993 | if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0) |
| 1994 | if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0], |
| 1995 | circuit->snd_stream)) |
| 1996 | return ISIS_WARNING; |
| 1997 | if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0) |
| 1998 | if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1], |
| 1999 | circuit->snd_stream)) |
| 2000 | return ISIS_WARNING; |
| 2001 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2002 | |
| 2003 | /* Protocols Supported TLV */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2004 | if (circuit->nlpids.count > 0) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2005 | if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream)) |
| 2006 | return ISIS_WARNING; |
| 2007 | /* IP interface Address TLV */ |
| 2008 | if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0) |
| 2009 | if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream)) |
| 2010 | return ISIS_WARNING; |
| 2011 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2012 | #ifdef HAVE_IPV6 |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2013 | /* IPv6 Interface Address TLV */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2014 | if (circuit->ipv6_router && circuit->ipv6_link && |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2015 | circuit->ipv6_link->count > 0) |
| 2016 | if (tlv_add_ipv6_addrs (circuit->ipv6_link, circuit->snd_stream)) |
| 2017 | return ISIS_WARNING; |
| 2018 | #endif /* HAVE_IPV6 */ |
| 2019 | |
| 2020 | if (circuit->u.bc.pad_hellos) |
| 2021 | if (tlv_add_padding (circuit->snd_stream)) |
| 2022 | return ISIS_WARNING; |
| 2023 | |
| 2024 | length = stream_get_putp (circuit->snd_stream); |
| 2025 | /* Update PDU length */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2026 | stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2027 | |
| 2028 | retval = circuit->tx (circuit, level); |
| 2029 | if (retval) |
| 2030 | zlog_warn ("sending of LAN Level %d Hello failed", level); |
| 2031 | |
| 2032 | /* DEBUG_ADJ_PACKETS */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2033 | if (isis->debugs & DEBUG_ADJ_PACKETS) |
| 2034 | { |
| 2035 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 2036 | { |
| 2037 | zlog_info ("ISIS-Adj (%s): Sent L%d LAN IIH on %s, length %ld", |
| 2038 | circuit->area->area_tag, level, circuit->interface->name, |
| 2039 | STREAM_SIZE (circuit->snd_stream)); |
| 2040 | } |
| 2041 | else |
| 2042 | { |
| 2043 | zlog_info ("ISIS-Adj (%s): Sent P2P IIH on %s, length %ld", |
| 2044 | circuit->area->area_tag, circuit->interface->name, |
| 2045 | STREAM_SIZE (circuit->snd_stream)); |
| 2046 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2047 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2048 | |
| 2049 | return retval; |
| 2050 | } |
| 2051 | |
| 2052 | int |
| 2053 | send_lan_hello (struct isis_circuit *circuit, int level) |
| 2054 | { |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2055 | return send_hello (circuit, level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | int |
| 2059 | send_lan_l1_hello (struct thread *thread) |
| 2060 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2061 | struct isis_circuit *circuit; |
| 2062 | int retval; |
| 2063 | |
| 2064 | circuit = THREAD_ARG (thread); |
| 2065 | assert (circuit); |
| 2066 | circuit->u.bc.t_send_lan_hello[0] = NULL; |
| 2067 | |
| 2068 | if (circuit->u.bc.run_dr_elect[0]) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2069 | retval = isis_dr_elect (circuit, 1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2070 | |
| 2071 | retval = send_lan_hello (circuit, 1); |
| 2072 | |
| 2073 | /* set next timer thread */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2074 | THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0], |
| 2075 | send_lan_l1_hello, circuit, |
| 2076 | isis_jitter (circuit->hello_interval[0], IIH_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2077 | |
| 2078 | return retval; |
| 2079 | } |
| 2080 | |
| 2081 | int |
| 2082 | send_lan_l2_hello (struct thread *thread) |
| 2083 | { |
| 2084 | struct isis_circuit *circuit; |
| 2085 | int retval; |
| 2086 | |
| 2087 | circuit = THREAD_ARG (thread); |
| 2088 | assert (circuit); |
| 2089 | circuit->u.bc.t_send_lan_hello[1] = NULL; |
| 2090 | |
| 2091 | if (circuit->u.bc.run_dr_elect[1]) |
| 2092 | retval = isis_dr_elect (circuit, 2); |
| 2093 | |
| 2094 | retval = send_lan_hello (circuit, 2); |
| 2095 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2096 | /* set next timer thread */ |
| 2097 | THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1], |
| 2098 | send_lan_l2_hello, circuit, |
| 2099 | isis_jitter (circuit->hello_interval[1], IIH_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2100 | |
| 2101 | return retval; |
| 2102 | } |
| 2103 | |
| 2104 | int |
| 2105 | send_p2p_hello (struct thread *thread) |
| 2106 | { |
| 2107 | struct isis_circuit *circuit; |
| 2108 | |
| 2109 | circuit = THREAD_ARG (thread); |
| 2110 | assert (circuit); |
| 2111 | circuit->u.p2p.t_send_p2p_hello = NULL; |
| 2112 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2113 | send_hello (circuit, 1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2114 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2115 | /* set next timer thread */ |
| 2116 | THREAD_TIMER_ON (master, circuit->u.p2p.t_send_p2p_hello, send_p2p_hello, |
| 2117 | circuit, isis_jitter (circuit->hello_interval[1], |
| 2118 | IIH_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2119 | |
| 2120 | return ISIS_OK; |
| 2121 | } |
| 2122 | |
| 2123 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2124 | build_csnp (int level, u_char * start, u_char * stop, struct list *lsps, |
| 2125 | struct isis_circuit *circuit) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2126 | { |
| 2127 | struct isis_fixed_hdr fixed_hdr; |
| 2128 | struct isis_passwd *passwd; |
| 2129 | int retval = ISIS_OK; |
| 2130 | unsigned long lenp; |
| 2131 | u_int16_t length; |
| 2132 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2133 | if (level == 1) |
| 2134 | fill_fixed_hdr_andstream (&fixed_hdr, L1_COMPLETE_SEQ_NUM, |
| 2135 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2136 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2137 | fill_fixed_hdr_andstream (&fixed_hdr, L2_COMPLETE_SEQ_NUM, |
| 2138 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2139 | |
| 2140 | /* |
| 2141 | * Fill Level 1 or 2 Complete Sequence Numbers header |
| 2142 | */ |
| 2143 | |
| 2144 | lenp = stream_get_putp (circuit->snd_stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2145 | stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2146 | /* no need to send the source here, it is always us if we csnp */ |
| 2147 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); |
| 2148 | /* with zero circuit id - ref 9.10, 9.11 */ |
| 2149 | stream_putc (circuit->snd_stream, 0x00); |
| 2150 | |
| 2151 | stream_put (circuit->snd_stream, start, ISIS_SYS_ID_LEN + 2); |
| 2152 | stream_put (circuit->snd_stream, stop, ISIS_SYS_ID_LEN + 2); |
| 2153 | |
| 2154 | /* |
| 2155 | * And TLVs |
| 2156 | */ |
| 2157 | if (level == 1) |
| 2158 | passwd = &circuit->area->area_passwd; |
| 2159 | else |
| 2160 | passwd = &circuit->area->domain_passwd; |
| 2161 | |
| 2162 | if (passwd->type) |
| 2163 | retval = tlv_add_authinfo (passwd->type, passwd->len, |
| 2164 | passwd->passwd, circuit->snd_stream); |
| 2165 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2166 | if (!retval && lsps) |
| 2167 | { |
| 2168 | retval = tlv_add_lsp_entries (lsps, circuit->snd_stream); |
| 2169 | } |
| 2170 | length = (u_int16_t) stream_get_putp (circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2171 | assert (length >= ISIS_CSNP_HDRLEN); |
| 2172 | /* Update PU length */ |
| 2173 | stream_putw_at (circuit->snd_stream, lenp, length); |
| 2174 | |
| 2175 | return retval; |
| 2176 | } |
| 2177 | |
| 2178 | /* |
| 2179 | * FIXME: support multiple CSNPs |
| 2180 | */ |
| 2181 | |
| 2182 | int |
| 2183 | send_csnp (struct isis_circuit *circuit, int level) |
| 2184 | { |
| 2185 | int retval = ISIS_OK; |
| 2186 | u_char start[ISIS_SYS_ID_LEN + 2]; |
| 2187 | u_char stop[ISIS_SYS_ID_LEN + 2]; |
| 2188 | struct list *list = NULL; |
| 2189 | struct listnode *node; |
| 2190 | struct isis_lsp *lsp; |
| 2191 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2192 | memset (start, 0x00, ISIS_SYS_ID_LEN + 2); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2193 | memset (stop, 0xff, ISIS_SYS_ID_LEN + 2); |
| 2194 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2195 | if (circuit->area->lspdb[level - 1] && |
| 2196 | dict_count (circuit->area->lspdb[level - 1]) > 0) |
| 2197 | { |
| 2198 | list = list_new (); |
| 2199 | lsp_build_list (start, stop, list, circuit->area->lspdb[level - 1]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2200 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2201 | if (circuit->snd_stream == NULL) |
| 2202 | circuit->snd_stream = stream_new (ISO_MTU (circuit)); |
| 2203 | else |
| 2204 | stream_reset (circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2205 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2206 | retval = build_csnp (level, start, stop, list, circuit); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2207 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2208 | if (isis->debugs & DEBUG_SNP_PACKETS) |
| 2209 | { |
| 2210 | zlog_info ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld", |
| 2211 | circuit->area->area_tag, level, circuit->interface->name, |
| 2212 | STREAM_SIZE (circuit->snd_stream)); |
| 2213 | LIST_LOOP (list, lsp, node) |
| 2214 | { |
| 2215 | zlog_info ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x," |
| 2216 | " cksum 0x%04x, lifetime %us", |
| 2217 | circuit->area->area_tag, |
| 2218 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 2219 | ntohl (lsp->lsp_header->seq_num), |
| 2220 | ntohs (lsp->lsp_header->checksum), |
| 2221 | ntohs (lsp->lsp_header->rem_lifetime)); |
| 2222 | } |
| 2223 | } |
| 2224 | |
| 2225 | list_delete (list); |
| 2226 | |
| 2227 | if (retval == ISIS_OK) |
| 2228 | retval = circuit->tx (circuit, level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2229 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2230 | return retval; |
| 2231 | } |
| 2232 | |
| 2233 | int |
| 2234 | send_l1_csnp (struct thread *thread) |
| 2235 | { |
| 2236 | struct isis_circuit *circuit; |
| 2237 | int retval = ISIS_OK; |
| 2238 | |
| 2239 | circuit = THREAD_ARG (thread); |
| 2240 | assert (circuit); |
| 2241 | |
| 2242 | circuit->t_send_csnp[0] = NULL; |
| 2243 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2244 | if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0]) |
| 2245 | { |
| 2246 | send_csnp (circuit, 1); |
| 2247 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2248 | /* set next timer thread */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2249 | THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit, |
| 2250 | isis_jitter (circuit->csnp_interval[0], CSNP_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2251 | |
| 2252 | return retval; |
| 2253 | } |
| 2254 | |
| 2255 | int |
| 2256 | send_l2_csnp (struct thread *thread) |
| 2257 | { |
| 2258 | struct isis_circuit *circuit; |
| 2259 | int retval = ISIS_OK; |
| 2260 | |
| 2261 | circuit = THREAD_ARG (thread); |
| 2262 | assert (circuit); |
| 2263 | |
| 2264 | circuit->t_send_csnp[1] = NULL; |
| 2265 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2266 | if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1]) |
| 2267 | { |
| 2268 | send_csnp (circuit, 2); |
| 2269 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2270 | /* set next timer thread */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2271 | THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit, |
| 2272 | isis_jitter (circuit->csnp_interval[1], CSNP_JITTER)); |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 2273 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2274 | return retval; |
| 2275 | } |
| 2276 | |
| 2277 | int |
| 2278 | build_psnp (int level, struct isis_circuit *circuit, struct list *lsps) |
| 2279 | { |
| 2280 | struct isis_fixed_hdr fixed_hdr; |
| 2281 | unsigned long lenp; |
| 2282 | u_int16_t length; |
| 2283 | int retval = 0; |
| 2284 | struct isis_lsp *lsp; |
| 2285 | struct isis_passwd *passwd; |
| 2286 | struct listnode *node; |
| 2287 | |
| 2288 | if (level == 1) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2289 | fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM, |
| 2290 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2291 | else |
| 2292 | fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2293 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2294 | |
| 2295 | /* |
| 2296 | * Fill Level 1 or 2 Partial Sequence Numbers header |
| 2297 | */ |
| 2298 | lenp = stream_get_putp (circuit->snd_stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2299 | stream_putw (circuit->snd_stream, 0); /* PDU length - when we know it */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2300 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); |
| 2301 | stream_putc (circuit->snd_stream, circuit->idx); |
| 2302 | |
| 2303 | /* |
| 2304 | * And TLVs |
| 2305 | */ |
| 2306 | |
| 2307 | if (level == 1) |
| 2308 | passwd = &circuit->area->area_passwd; |
| 2309 | else |
| 2310 | passwd = &circuit->area->domain_passwd; |
| 2311 | |
| 2312 | if (passwd->type) |
| 2313 | retval = tlv_add_authinfo (passwd->type, passwd->len, |
| 2314 | passwd->passwd, circuit->snd_stream); |
| 2315 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2316 | if (!retval && lsps) |
| 2317 | { |
| 2318 | retval = tlv_add_lsp_entries (lsps, circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2319 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2320 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2321 | if (isis->debugs & DEBUG_SNP_PACKETS) |
| 2322 | { |
| 2323 | LIST_LOOP (lsps, lsp, node) |
| 2324 | { |
| 2325 | zlog_info ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x," |
| 2326 | " cksum 0x%04x, lifetime %us", |
| 2327 | circuit->area->area_tag, |
| 2328 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 2329 | ntohl (lsp->lsp_header->seq_num), |
| 2330 | ntohs (lsp->lsp_header->checksum), |
| 2331 | ntohs (lsp->lsp_header->rem_lifetime)); |
| 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | length = (u_int16_t) stream_get_putp (circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2336 | assert (length >= ISIS_PSNP_HDRLEN); |
| 2337 | /* Update PDU length */ |
| 2338 | stream_putw_at (circuit->snd_stream, lenp, length); |
| 2339 | |
| 2340 | return ISIS_OK; |
| 2341 | } |
| 2342 | |
| 2343 | /* |
| 2344 | * 7.3.15.4 action on expiration of partial SNP interval |
| 2345 | * level 1 |
| 2346 | */ |
| 2347 | int |
| 2348 | send_psnp (int level, struct isis_circuit *circuit) |
| 2349 | { |
| 2350 | int retval = ISIS_OK; |
| 2351 | struct isis_lsp *lsp; |
| 2352 | struct list *list = NULL; |
| 2353 | struct listnode *node; |
| 2354 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2355 | if ((circuit->circ_type == CIRCUIT_T_BROADCAST && |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2356 | !circuit->u.bc.is_dr[level - 1]) || |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2357 | circuit->circ_type != CIRCUIT_T_BROADCAST) |
| 2358 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2359 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2360 | if (circuit->area->lspdb[level - 1] && |
| 2361 | dict_count (circuit->area->lspdb[level - 1]) > 0) |
| 2362 | { |
| 2363 | list = list_new (); |
| 2364 | lsp_build_list_ssn (circuit, list, circuit->area->lspdb[level - 1]); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2365 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2366 | if (listcount (list) > 0) |
| 2367 | { |
| 2368 | if (circuit->snd_stream == NULL) |
| 2369 | circuit->snd_stream = stream_new (ISO_MTU (circuit)); |
| 2370 | else |
| 2371 | stream_reset (circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2372 | |
| 2373 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2374 | if (isis->debugs & DEBUG_SNP_PACKETS) |
| 2375 | zlog_info ("ISIS-Snp (%s): Sent L%d PSNP on %s, length %ld", |
| 2376 | circuit->area->area_tag, level, |
| 2377 | circuit->interface->name, |
| 2378 | STREAM_SIZE (circuit->snd_stream)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2379 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2380 | retval = build_psnp (level, circuit, list); |
| 2381 | if (retval == ISIS_OK) |
| 2382 | retval = circuit->tx (circuit, level); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2383 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2384 | if (retval == ISIS_OK) |
| 2385 | { |
| 2386 | /* |
| 2387 | * sending succeeded, we can clear SSN flags of this circuit |
| 2388 | * for the LSPs in list |
| 2389 | */ |
| 2390 | for (node = listhead (list); node; nextnode (node)) |
| 2391 | { |
| 2392 | lsp = getdata (node); |
| 2393 | ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); |
| 2394 | } |
| 2395 | } |
| 2396 | } |
| 2397 | list_delete (list); |
| 2398 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2399 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2400 | |
| 2401 | return retval; |
| 2402 | } |
| 2403 | |
| 2404 | int |
| 2405 | send_l1_psnp (struct thread *thread) |
| 2406 | { |
| 2407 | |
| 2408 | struct isis_circuit *circuit; |
| 2409 | int retval = ISIS_OK; |
| 2410 | |
| 2411 | circuit = THREAD_ARG (thread); |
| 2412 | assert (circuit); |
| 2413 | |
| 2414 | circuit->t_send_psnp[0] = NULL; |
| 2415 | |
| 2416 | send_psnp (1, circuit); |
| 2417 | /* set next timer thread */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2418 | THREAD_TIMER_ON (master, circuit->t_send_psnp[0], send_l1_psnp, circuit, |
| 2419 | isis_jitter (circuit->psnp_interval[0], PSNP_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2420 | |
| 2421 | return retval; |
| 2422 | } |
| 2423 | |
| 2424 | /* |
| 2425 | * 7.3.15.4 action on expiration of partial SNP interval |
| 2426 | * level 2 |
| 2427 | */ |
| 2428 | int |
| 2429 | send_l2_psnp (struct thread *thread) |
| 2430 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2431 | struct isis_circuit *circuit; |
| 2432 | int retval = ISIS_OK; |
| 2433 | |
| 2434 | circuit = THREAD_ARG (thread); |
| 2435 | assert (circuit); |
| 2436 | |
| 2437 | circuit->t_send_psnp[1] = NULL; |
| 2438 | |
| 2439 | send_psnp (2, circuit); |
| 2440 | |
| 2441 | /* set next timer thread */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2442 | THREAD_TIMER_ON (master, circuit->t_send_psnp[1], send_l2_psnp, circuit, |
| 2443 | isis_jitter (circuit->psnp_interval[1], PSNP_JITTER)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2444 | |
| 2445 | return retval; |
| 2446 | } |
| 2447 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2448 | void |
| 2449 | build_link_state (struct isis_lsp *lsp, struct isis_circuit *circuit, |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2450 | struct stream *stream) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2451 | { |
| 2452 | unsigned long length; |
| 2453 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2454 | stream_put (stream, lsp->pdu, ntohs (lsp->lsp_header->pdu_len)); |
| 2455 | length = stream_get_putp (stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2456 | |
| 2457 | return; |
| 2458 | } |
| 2459 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2460 | /* |
| 2461 | * ISO 10589 - 7.3.14.3 |
| 2462 | */ |
| 2463 | int |
| 2464 | send_lsp (struct thread *thread) |
| 2465 | { |
| 2466 | struct isis_circuit *circuit; |
| 2467 | struct isis_lsp *lsp; |
| 2468 | struct listnode *node; |
| 2469 | int retval = 0; |
| 2470 | |
| 2471 | circuit = THREAD_ARG (thread); |
| 2472 | assert (circuit); |
| 2473 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2474 | if (circuit->state == C_STATE_UP) |
| 2475 | { |
| 2476 | node = listhead (circuit->lsp_queue); |
| 2477 | assert (node); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2478 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2479 | lsp = getdata (node); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2480 | |
| 2481 | /* |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2482 | * Do not send if levels do not match |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2483 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2484 | if (!(lsp->level & circuit->circuit_is_type)) |
| 2485 | goto dontsend; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2486 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2487 | /* |
| 2488 | * Do not send if we do not have adjacencies in state up on the circuit |
| 2489 | */ |
| 2490 | if (circuit->upadjcount[lsp->level - 1] == 0) |
| 2491 | goto dontsend; |
| 2492 | /* only send if it needs sending */ |
| 2493 | if ((time (NULL) - lsp->last_sent) >= |
| 2494 | circuit->area->lsp_gen_interval[lsp->level - 1]) |
| 2495 | { |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2496 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2497 | if (isis->debugs & DEBUG_UPDATE_PACKETS) |
| 2498 | { |
| 2499 | zlog_info |
| 2500 | ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x," |
| 2501 | " lifetime %us on %s", circuit->area->area_tag, lsp->level, |
| 2502 | rawlspid_print (lsp->lsp_header->lsp_id), |
| 2503 | ntohl (lsp->lsp_header->seq_num), |
| 2504 | ntohs (lsp->lsp_header->checksum), |
| 2505 | ntohs (lsp->lsp_header->rem_lifetime), |
| 2506 | circuit->interface->name); |
| 2507 | } |
| 2508 | /* copy our lsp to the send buffer */ |
| 2509 | circuit->snd_stream->getp = lsp->pdu->getp; |
| 2510 | circuit->snd_stream->putp = lsp->pdu->putp; |
| 2511 | circuit->snd_stream->endp = lsp->pdu->endp; |
| 2512 | memcpy (circuit->snd_stream->data, lsp->pdu->data, lsp->pdu->endp); |
| 2513 | |
| 2514 | retval = circuit->tx (circuit, lsp->level); |
| 2515 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2516 | /* |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2517 | * If the sending succeeded, we can del the lsp from circuits |
| 2518 | * lsp_queue |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2519 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2520 | if (retval == ISIS_OK) |
| 2521 | { |
| 2522 | list_delete_node (circuit->lsp_queue, node); |
| 2523 | |
| 2524 | /* |
| 2525 | * On broadcast circuits also the SRMflag can be cleared |
| 2526 | */ |
| 2527 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) |
| 2528 | ISIS_CLEAR_FLAG (lsp->SRMflags, circuit); |
| 2529 | |
| 2530 | if (flags_any_set (lsp->SRMflags) == 0) |
| 2531 | { |
| 2532 | /* |
| 2533 | * need to remember when we were last sent |
| 2534 | */ |
| 2535 | lsp->last_sent = time (NULL); |
| 2536 | } |
| 2537 | } |
| 2538 | else |
| 2539 | { |
| 2540 | zlog_info ("sending of level %d link state failed", lsp->level); |
| 2541 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2542 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2543 | else |
| 2544 | { |
| 2545 | /* my belief is that if it wasn't his time, the lsp can be removed |
| 2546 | * from the queue |
| 2547 | */ |
| 2548 | dontsend: |
| 2549 | list_delete_node (circuit->lsp_queue, node); |
| 2550 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2551 | #if 0 |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2552 | /* |
| 2553 | * If there are still LSPs send next one after lsp-interval (33 msecs) |
| 2554 | */ |
| 2555 | if (listcount (circuit->lsp_queue) > 0) |
| 2556 | thread_add_timer (master, send_lsp, circuit, 1); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2557 | #endif |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2558 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2559 | |
| 2560 | return retval; |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2561 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2562 | |
| 2563 | int |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2564 | ack_lsp (struct isis_link_state_hdr *hdr, struct isis_circuit *circuit, |
| 2565 | int level) |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2566 | { |
| 2567 | unsigned long lenp; |
| 2568 | int retval; |
| 2569 | u_int16_t length; |
| 2570 | struct isis_fixed_hdr fixed_hdr; |
| 2571 | |
| 2572 | if (!circuit->snd_stream) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2573 | circuit->snd_stream = stream_new (ISO_MTU (circuit)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2574 | else |
| 2575 | stream_reset (circuit->snd_stream); |
| 2576 | |
| 2577 | // fill_llc_hdr (stream); |
| 2578 | if (level == 1) |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2579 | fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM, |
| 2580 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2581 | else |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2582 | fill_fixed_hdr_andstream (&fixed_hdr, L2_PARTIAL_SEQ_NUM, |
| 2583 | circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2584 | |
| 2585 | |
| 2586 | lenp = stream_get_putp (circuit->snd_stream); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2587 | stream_putw (circuit->snd_stream, 0); /* PDU length */ |
| 2588 | stream_put (circuit->snd_stream, isis->sysid, ISIS_SYS_ID_LEN); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2589 | stream_putc (circuit->snd_stream, circuit->idx); |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2590 | stream_putc (circuit->snd_stream, 9); /* code */ |
| 2591 | stream_putc (circuit->snd_stream, 16); /* len */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2592 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2593 | stream_putw (circuit->snd_stream, ntohs (hdr->rem_lifetime)); |
| 2594 | stream_put (circuit->snd_stream, hdr->lsp_id, ISIS_SYS_ID_LEN + 2); |
| 2595 | stream_putl (circuit->snd_stream, ntohl (hdr->seq_num)); |
| 2596 | stream_putw (circuit->snd_stream, ntohs (hdr->checksum)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2597 | |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2598 | length = (u_int16_t) stream_get_putp (circuit->snd_stream); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2599 | /* Update PDU length */ |
| 2600 | stream_putw_at (circuit->snd_stream, lenp, length); |
| 2601 | |
| 2602 | retval = circuit->tx (circuit, level); |
| 2603 | |
| 2604 | return retval; |
| 2605 | } |
| 2606 | |
| 2607 | #if 0 |
| 2608 | /* |
| 2609 | * ISH PDU Processing |
| 2610 | */ |
| 2611 | |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2612 | /* |
| 2613 | * Let's first check if the local and remote system have any common area |
| 2614 | * addresses |
| 2615 | */ |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2616 | if (area_match (tlvs.area_addrs, isis->man_area_addrs) == 0) |
| 2617 | { |
| 2618 | if (circuit->circuit_t == IS_LEVEL_2) |
| 2619 | { |
| 2620 | /* do as in table 8 (p. 40) */ |
| 2621 | switch (circuit_type) |
| 2622 | { |
| 2623 | case IS_LEVEL_1: |
| 2624 | if (adj->adj_state != ISIS_ADJ_UP) |
| 2625 | { |
| 2626 | /* Reject */ |
| 2627 | zlog_warn ("areaMismatch"); |
| 2628 | retval = ISIS_WARNING; |
| 2629 | } |
| 2630 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) |
| 2631 | { |
| 2632 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch", |
| 2633 | circuit->adjdb); |
| 2634 | } |
| 2635 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2 || |
| 2636 | adj->adj_usage == ISIS_ADJ_LEVEL2) |
| 2637 | { |
| 2638 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System", |
| 2639 | circuit->adjdb); |
| 2640 | } |
| 2641 | break; |
| 2642 | case IS_LEVEL_2: |
| 2643 | if (adj->adj_state != ISIS_ADJ_UP) |
| 2644 | { |
| 2645 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL, |
| 2646 | circuit->adjdb); |
| 2647 | adj->adj_usage = ISIS_ADJ_LEVEL2; |
| 2648 | } |
| 2649 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1 || |
| 2650 | adj->adj_usage == ISIS_ADJ_LEVEL1AND2) |
| 2651 | { |
| 2652 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System", |
| 2653 | circuit->adjdb); |
| 2654 | } |
| 2655 | else if (adj->adj_usage == ISIS_ADJ_LEVEL2) |
| 2656 | { |
| 2657 | ; /* Accept */ |
| 2658 | } |
| 2659 | break; |
| 2660 | case IS_LEVEL_1_AND_2: |
| 2661 | if (adj->adj_state != ISIS_ADJ_UP) |
| 2662 | { |
| 2663 | isis_adj_state_change (adj, ISIS_ADJ_UP, NULL, |
| 2664 | circuit->adjdb); |
| 2665 | adj->adj_usage = ISIS_ADJ_LEVEL2; |
| 2666 | } |
| 2667 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1) |
| 2668 | { |
| 2669 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Wrong System", |
| 2670 | circuit->adjdb); |
| 2671 | } |
| 2672 | else if (adj->adj_usage == ISIS_ADJ_LEVEL1AND2) |
| 2673 | { |
| 2674 | isis_adj_state_change (adj, ISIS_ADJ_DOWN, "Area Mismatch", |
| 2675 | circuit->adjdb); |
| 2676 | } |
| 2677 | else if (adj->adj_usage == ISIS_ADJ_LEVEL2) |
| 2678 | { |
| 2679 | ; /* Accept */ |
| 2680 | } |
| 2681 | break; |
| 2682 | } |
| 2683 | goto mismatch; |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2684 | } |
hasso | f390d2c | 2004-09-10 20:48:21 +0000 | [diff] [blame^] | 2685 | else |
| 2686 | { |
| 2687 | isis_delete_adj (adj, circuit->adjdb); |
| 2688 | zlog_warn ("areaMismatch"); |
| 2689 | return ISIS_WARNING; |
| 2690 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | mismatch: |
| 2694 | #endif |