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