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