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