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