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