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