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