paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3 | * |
| 4 | * This file is part of GNU Zebra. |
| 5 | * |
| 6 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2, or (at your option) any |
| 9 | * later version. |
| 10 | * |
| 11 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with GNU Zebra; see the file COPYING. If not, write to the |
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 22 | #include <zebra.h> |
| 23 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 24 | #include "memory.h" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 25 | #include "log.h" |
| 26 | #include "vty.h" |
| 27 | #include "command.h" |
| 28 | #include "thread.h" |
| 29 | #include "linklist.h" |
| 30 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 31 | #include "ospf6_proto.h" |
| 32 | #include "ospf6_lsa.h" |
| 33 | #include "ospf6_lsdb.h" |
| 34 | #include "ospf6_network.h" |
| 35 | #include "ospf6_message.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 36 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 37 | #include "ospf6_top.h" |
| 38 | #include "ospf6_area.h" |
| 39 | #include "ospf6_neighbor.h" |
| 40 | #include "ospf6_interface.h" |
| 41 | |
Denis Ovsienko | 552563a | 2011-09-26 13:18:51 +0400 | [diff] [blame] | 42 | /* for structures and macros ospf6_lsa_examin() needs */ |
| 43 | #include "ospf6_abr.h" |
| 44 | #include "ospf6_asbr.h" |
| 45 | #include "ospf6_intra.h" |
| 46 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 47 | #include "ospf6_flood.h" |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 48 | #include "ospf6d.h" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 49 | |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 50 | #include <netinet/ip6.h> |
| 51 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 52 | unsigned char conf_debug_ospf6_message[6] = {0x03, 0, 0, 0, 0, 0}; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 53 | const char *ospf6_message_type_str[] = |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 54 | { "Unknown", "Hello", "DbDesc", "LSReq", "LSUpdate", "LSAck" }; |
| 55 | |
Denis Ovsienko | 552563a | 2011-09-26 13:18:51 +0400 | [diff] [blame] | 56 | /* Minimum (besides the standard OSPF packet header) lengths for OSPF |
| 57 | packets of particular types, offset is the "type" field. */ |
| 58 | const u_int16_t ospf6_packet_minlen[OSPF6_MESSAGE_TYPE_ALL] = |
| 59 | { |
| 60 | 0, |
| 61 | OSPF6_HELLO_MIN_SIZE, |
| 62 | OSPF6_DB_DESC_MIN_SIZE, |
| 63 | OSPF6_LS_REQ_MIN_SIZE, |
| 64 | OSPF6_LS_UPD_MIN_SIZE, |
| 65 | OSPF6_LS_ACK_MIN_SIZE |
| 66 | }; |
| 67 | |
| 68 | /* Minimum (besides the standard LSA header) lengths for LSAs of particular |
| 69 | types, offset is the "LSA function code" portion of "LSA type" field. */ |
| 70 | const u_int16_t ospf6_lsa_minlen[OSPF6_LSTYPE_SIZE] = |
| 71 | { |
| 72 | 0, |
| 73 | /* 0x2001 */ OSPF6_ROUTER_LSA_MIN_SIZE, |
| 74 | /* 0x2002 */ OSPF6_NETWORK_LSA_MIN_SIZE, |
| 75 | /* 0x2003 */ OSPF6_INTER_PREFIX_LSA_MIN_SIZE, |
| 76 | /* 0x2004 */ OSPF6_INTER_ROUTER_LSA_FIX_SIZE, |
| 77 | /* 0x4005 */ OSPF6_AS_EXTERNAL_LSA_MIN_SIZE, |
| 78 | /* 0x2006 */ 0, |
| 79 | /* 0x2007 */ OSPF6_AS_EXTERNAL_LSA_MIN_SIZE, |
| 80 | /* 0x0008 */ OSPF6_LINK_LSA_MIN_SIZE, |
| 81 | /* 0x2009 */ OSPF6_INTRA_PREFIX_LSA_MIN_SIZE |
| 82 | }; |
| 83 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 84 | /* print functions */ |
| 85 | |
| 86 | static void |
| 87 | ospf6_header_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 88 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 89 | char router_id[16], area_id[16]; |
| 90 | inet_ntop (AF_INET, &oh->router_id, router_id, sizeof (router_id)); |
| 91 | inet_ntop (AF_INET, &oh->area_id, area_id, sizeof (area_id)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 92 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 93 | zlog_debug (" OSPFv%d Type:%d Len:%hu Router-ID:%s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 94 | oh->version, oh->type, ntohs (oh->length), router_id); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 95 | zlog_debug (" Area-ID:%s Cksum:%hx Instance-ID:%d", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 96 | area_id, ntohs (oh->checksum), oh->instance_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 97 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 98 | |
| 99 | void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 100 | ospf6_hello_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 101 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 102 | struct ospf6_hello *hello; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 103 | char options[16]; |
| 104 | char drouter[16], bdrouter[16], neighbor[16]; |
| 105 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 106 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 107 | ospf6_header_print (oh); |
| 108 | assert (oh->type == OSPF6_MESSAGE_TYPE_HELLO); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 109 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 110 | hello = (struct ospf6_hello *) |
| 111 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 112 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 113 | inet_ntop (AF_INET, &hello->drouter, drouter, sizeof (drouter)); |
| 114 | inet_ntop (AF_INET, &hello->bdrouter, bdrouter, sizeof (bdrouter)); |
| 115 | ospf6_options_printbuf (hello->options, options, sizeof (options)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 116 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 117 | zlog_debug (" I/F-Id:%ld Priority:%d Option:%s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 118 | (u_long) ntohl (hello->interface_id), hello->priority, options); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 119 | zlog_debug (" HelloInterval:%hu DeadInterval:%hu", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 120 | ntohs (hello->hello_interval), ntohs (hello->dead_interval)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 121 | zlog_debug (" DR:%s BDR:%s", drouter, bdrouter); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 122 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 123 | for (p = (char *) ((caddr_t) hello + sizeof (struct ospf6_hello)); |
| 124 | p + sizeof (u_int32_t) <= OSPF6_MESSAGE_END (oh); |
| 125 | p += sizeof (u_int32_t)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 126 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 127 | inet_ntop (AF_INET, (void *) p, neighbor, sizeof (neighbor)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 128 | zlog_debug (" Neighbor: %s", neighbor); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 129 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 130 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 131 | assert (p == OSPF6_MESSAGE_END (oh)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 132 | } |
| 133 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 134 | void |
| 135 | ospf6_dbdesc_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 136 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 137 | struct ospf6_dbdesc *dbdesc; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 138 | char options[16]; |
| 139 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 140 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 141 | ospf6_header_print (oh); |
| 142 | assert (oh->type == OSPF6_MESSAGE_TYPE_DBDESC); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 143 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 144 | dbdesc = (struct ospf6_dbdesc *) |
| 145 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 146 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 147 | ospf6_options_printbuf (dbdesc->options, options, sizeof (options)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 148 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 149 | zlog_debug (" MBZ: %#x Option: %s IfMTU: %hu", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 150 | dbdesc->reserved1, options, ntohs (dbdesc->ifmtu)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 151 | zlog_debug (" MBZ: %#x Bits: %s%s%s SeqNum: %#lx", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 152 | dbdesc->reserved2, |
| 153 | (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) ? "I" : "-"), |
| 154 | (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) ? "M" : "-"), |
| 155 | (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) ? "m" : "s"), |
| 156 | (u_long) ntohl (dbdesc->seqnum)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 157 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 158 | for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc)); |
| 159 | p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh); |
| 160 | p += sizeof (struct ospf6_lsa_header)) |
| 161 | ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p); |
| 162 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 163 | assert (p == OSPF6_MESSAGE_END (oh)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 164 | } |
| 165 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 166 | void |
| 167 | ospf6_lsreq_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 168 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 169 | char id[16], adv_router[16]; |
| 170 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 171 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 172 | ospf6_header_print (oh); |
| 173 | assert (oh->type == OSPF6_MESSAGE_TYPE_LSREQ); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 174 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 175 | for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 176 | p + sizeof (struct ospf6_lsreq_entry) <= OSPF6_MESSAGE_END (oh); |
| 177 | p += sizeof (struct ospf6_lsreq_entry)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 178 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 179 | struct ospf6_lsreq_entry *e = (struct ospf6_lsreq_entry *) p; |
| 180 | inet_ntop (AF_INET, &e->adv_router, adv_router, sizeof (adv_router)); |
| 181 | inet_ntop (AF_INET, &e->id, id, sizeof (id)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 182 | zlog_debug (" [%s Id:%s Adv:%s]", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 183 | ospf6_lstype_name (e->type), id, adv_router); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 184 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 185 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 186 | assert (p == OSPF6_MESSAGE_END (oh)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 187 | } |
| 188 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 189 | void |
| 190 | ospf6_lsupdate_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 191 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 192 | struct ospf6_lsupdate *lsupdate; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 193 | u_long num; |
| 194 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 195 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 196 | ospf6_header_print (oh); |
| 197 | assert (oh->type == OSPF6_MESSAGE_TYPE_LSUPDATE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 198 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 199 | lsupdate = (struct ospf6_lsupdate *) |
| 200 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 201 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 202 | num = ntohl (lsupdate->lsa_number); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 203 | zlog_debug (" Number of LSA: %ld", num); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 204 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 205 | for (p = (char *) ((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate)); |
| 206 | p < OSPF6_MESSAGE_END (oh) && |
| 207 | p + OSPF6_LSA_SIZE (p) <= OSPF6_MESSAGE_END (oh); |
| 208 | p += OSPF6_LSA_SIZE (p)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 209 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 210 | ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 211 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 212 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 213 | assert (p == OSPF6_MESSAGE_END (oh)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 214 | } |
| 215 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 216 | void |
| 217 | ospf6_lsack_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 218 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 219 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 220 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 221 | ospf6_header_print (oh); |
| 222 | assert (oh->type == OSPF6_MESSAGE_TYPE_LSACK); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 223 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 224 | for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 225 | p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh); |
| 226 | p += sizeof (struct ospf6_lsa_header)) |
| 227 | ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p); |
| 228 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 229 | assert (p == OSPF6_MESSAGE_END (oh)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 232 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 233 | ospf6_hello_recv (struct in6_addr *src, struct in6_addr *dst, |
| 234 | struct ospf6_interface *oi, struct ospf6_header *oh) |
| 235 | { |
| 236 | struct ospf6_hello *hello; |
| 237 | struct ospf6_neighbor *on; |
| 238 | char *p; |
| 239 | int twoway = 0; |
| 240 | int neighborchange = 0; |
| 241 | int backupseen = 0; |
| 242 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 243 | hello = (struct ospf6_hello *) |
| 244 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 245 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 246 | /* HelloInterval check */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 247 | if (ntohs (hello->hello_interval) != oi->hello_interval) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 248 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 249 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 250 | zlog_debug ("HelloInterval mismatch"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 251 | return; |
| 252 | } |
| 253 | |
| 254 | /* RouterDeadInterval check */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 255 | if (ntohs (hello->dead_interval) != oi->dead_interval) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 256 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 257 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 258 | zlog_debug ("RouterDeadInterval mismatch"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 259 | return; |
| 260 | } |
| 261 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 262 | /* E-bit check */ |
| 263 | if (OSPF6_OPT_ISSET (hello->options, OSPF6_OPT_E) != |
| 264 | OSPF6_OPT_ISSET (oi->area->options, OSPF6_OPT_E)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 265 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 266 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 267 | zlog_debug ("E-bit mismatch"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 268 | return; |
| 269 | } |
| 270 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 271 | /* Find neighbor, create if not exist */ |
| 272 | on = ospf6_neighbor_lookup (oh->router_id, oi); |
| 273 | if (on == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 274 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 275 | on = ospf6_neighbor_create (oh->router_id, oi); |
| 276 | on->prev_drouter = on->drouter = hello->drouter; |
| 277 | on->prev_bdrouter = on->bdrouter = hello->bdrouter; |
| 278 | on->priority = hello->priority; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 279 | } |
| 280 | |
hasso | 7b6ae02 | 2005-06-24 08:17:51 +0000 | [diff] [blame] | 281 | /* always override neighbor's source address and ifindex */ |
| 282 | on->ifindex = ntohl (hello->interface_id); |
| 283 | memcpy (&on->linklocal_addr, src, sizeof (struct in6_addr)); |
| 284 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 285 | /* TwoWay check */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 286 | for (p = (char *) ((caddr_t) hello + sizeof (struct ospf6_hello)); |
| 287 | p + sizeof (u_int32_t) <= OSPF6_MESSAGE_END (oh); |
| 288 | p += sizeof (u_int32_t)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 289 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 290 | u_int32_t *router_id = (u_int32_t *) p; |
| 291 | |
| 292 | if (*router_id == oi->area->ospf6->router_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 293 | twoway++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 296 | assert (p == OSPF6_MESSAGE_END (oh)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 297 | |
| 298 | /* RouterPriority check */ |
| 299 | if (on->priority != hello->priority) |
| 300 | { |
| 301 | on->priority = hello->priority; |
| 302 | neighborchange++; |
| 303 | } |
| 304 | |
| 305 | /* DR check */ |
| 306 | if (on->drouter != hello->drouter) |
| 307 | { |
| 308 | on->prev_drouter = on->drouter; |
| 309 | on->drouter = hello->drouter; |
| 310 | if (on->prev_drouter == on->router_id || on->drouter == on->router_id) |
| 311 | neighborchange++; |
| 312 | } |
| 313 | |
| 314 | /* BDR check */ |
| 315 | if (on->bdrouter != hello->bdrouter) |
| 316 | { |
| 317 | on->prev_bdrouter = on->bdrouter; |
| 318 | on->bdrouter = hello->bdrouter; |
| 319 | if (on->prev_bdrouter == on->router_id || on->bdrouter == on->router_id) |
| 320 | neighborchange++; |
| 321 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 322 | |
| 323 | /* BackupSeen check */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 324 | if (oi->state == OSPF6_INTERFACE_WAITING) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 325 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 326 | if (hello->bdrouter == on->router_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 327 | backupseen++; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 328 | else if (hello->drouter == on->router_id && hello->bdrouter == htonl (0)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 329 | backupseen++; |
| 330 | } |
| 331 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 332 | /* Execute neighbor events */ |
| 333 | thread_execute (master, hello_received, on, 0); |
| 334 | if (twoway) |
| 335 | thread_execute (master, twoway_received, on, 0); |
| 336 | else |
| 337 | thread_execute (master, oneway_received, on, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 338 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 339 | /* Schedule interface events */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 340 | if (backupseen) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 341 | thread_add_event (master, backup_seen, oi, 0); |
| 342 | if (neighborchange) |
| 343 | thread_add_event (master, neighbor_change, oi, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 344 | } |
| 345 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 346 | static void |
| 347 | ospf6_dbdesc_recv_master (struct ospf6_header *oh, |
| 348 | struct ospf6_neighbor *on) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 349 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 350 | struct ospf6_dbdesc *dbdesc; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 351 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 352 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 353 | dbdesc = (struct ospf6_dbdesc *) |
| 354 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 355 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 356 | if (on->state < OSPF6_NEIGHBOR_INIT) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 357 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 358 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 359 | zlog_debug ("Neighbor state less than Init, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 360 | return; |
| 361 | } |
| 362 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 363 | switch (on->state) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 364 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 365 | case OSPF6_NEIGHBOR_TWOWAY: |
| 366 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 367 | zlog_debug ("Neighbor state is 2-Way, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 368 | return; |
| 369 | |
| 370 | case OSPF6_NEIGHBOR_INIT: |
| 371 | thread_execute (master, twoway_received, on, 0); |
| 372 | if (on->state != OSPF6_NEIGHBOR_EXSTART) |
| 373 | { |
| 374 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 375 | zlog_debug ("Neighbor state is not ExStart, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 376 | return; |
| 377 | } |
| 378 | /* else fall through to ExStart */ |
| 379 | |
| 380 | case OSPF6_NEIGHBOR_EXSTART: |
| 381 | /* if neighbor obeys us as our slave, schedule negotiation_done |
| 382 | and process LSA Headers. Otherwise, ignore this message */ |
| 383 | if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) && |
| 384 | ! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) && |
| 385 | ntohl (dbdesc->seqnum) == on->dbdesc_seqnum) |
| 386 | { |
| 387 | /* execute NegotiationDone */ |
| 388 | thread_execute (master, negotiation_done, on, 0); |
| 389 | |
| 390 | /* Record neighbor options */ |
| 391 | memcpy (on->options, dbdesc->options, sizeof (on->options)); |
| 392 | } |
| 393 | else |
| 394 | { |
| 395 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 396 | zlog_debug ("Negotiation failed"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 397 | return; |
| 398 | } |
| 399 | /* fall through to exchange */ |
| 400 | |
| 401 | case OSPF6_NEIGHBOR_EXCHANGE: |
| 402 | if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc))) |
| 403 | { |
| 404 | /* Duplicated DatabaseDescription is dropped by master */ |
| 405 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 406 | zlog_debug ("Duplicated dbdesc discarded by Master, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 407 | return; |
| 408 | } |
| 409 | |
| 410 | if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT)) |
| 411 | { |
| 412 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 413 | zlog_debug ("Master/Slave bit mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 414 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 415 | return; |
| 416 | } |
| 417 | |
| 418 | if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT)) |
| 419 | { |
| 420 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 421 | zlog_debug ("Initialize bit mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 422 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 423 | return; |
| 424 | } |
| 425 | |
| 426 | if (memcmp (on->options, dbdesc->options, sizeof (on->options))) |
| 427 | { |
| 428 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 429 | zlog_debug ("Option field mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 430 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 431 | return; |
| 432 | } |
| 433 | |
| 434 | if (ntohl (dbdesc->seqnum) != on->dbdesc_seqnum) |
| 435 | { |
| 436 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 437 | zlog_debug ("Sequence number mismatch (%#lx expected)", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 438 | (u_long) on->dbdesc_seqnum); |
| 439 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 440 | return; |
| 441 | } |
| 442 | break; |
| 443 | |
| 444 | case OSPF6_NEIGHBOR_LOADING: |
| 445 | case OSPF6_NEIGHBOR_FULL: |
| 446 | if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc))) |
| 447 | { |
| 448 | /* Duplicated DatabaseDescription is dropped by master */ |
| 449 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 450 | zlog_debug ("Duplicated dbdesc discarded by Master, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 451 | return; |
| 452 | } |
| 453 | |
| 454 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 455 | zlog_debug ("Not duplicate dbdesc in state %s", |
| 456 | ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 457 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 458 | return; |
| 459 | |
| 460 | default: |
| 461 | assert (0); |
| 462 | break; |
| 463 | } |
| 464 | |
| 465 | /* Process LSA headers */ |
| 466 | for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc)); |
| 467 | p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh); |
| 468 | p += sizeof (struct ospf6_lsa_header)) |
| 469 | { |
| 470 | struct ospf6_lsa *his, *mine; |
| 471 | struct ospf6_lsdb *lsdb = NULL; |
| 472 | |
| 473 | his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 474 | |
| 475 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 476 | zlog_debug ("%s", his->name); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 477 | |
| 478 | switch (OSPF6_LSA_SCOPE (his->header->type)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 479 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 480 | case OSPF6_SCOPE_LINKLOCAL: |
| 481 | lsdb = on->ospf6_if->lsdb; |
| 482 | break; |
| 483 | case OSPF6_SCOPE_AREA: |
| 484 | lsdb = on->ospf6_if->area->lsdb; |
| 485 | break; |
| 486 | case OSPF6_SCOPE_AS: |
| 487 | lsdb = on->ospf6_if->area->ospf6->lsdb; |
| 488 | break; |
| 489 | case OSPF6_SCOPE_RESERVED: |
| 490 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 491 | zlog_debug ("Ignoring LSA of reserved scope"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 492 | ospf6_lsa_delete (his); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 493 | continue; |
| 494 | break; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | if (ntohs (his->header->type) == OSPF6_LSTYPE_AS_EXTERNAL && |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 498 | IS_AREA_STUB (on->ospf6_if->area)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 499 | { |
| 500 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 501 | zlog_debug ("SeqNumMismatch (E-bit mismatch), discard"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 502 | ospf6_lsa_delete (his); |
| 503 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 504 | return; |
| 505 | } |
| 506 | |
| 507 | mine = ospf6_lsdb_lookup (his->header->type, his->header->id, |
| 508 | his->header->adv_router, lsdb); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 509 | if (mine == NULL) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 510 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 511 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 512 | zlog_debug ("Add request (No database copy)"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 513 | ospf6_lsdb_add (his, on->request_list); |
| 514 | } |
| 515 | else if (ospf6_lsa_compare (his, mine) < 0) |
| 516 | { |
| 517 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 518 | zlog_debug ("Add request (Received MoreRecent)"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 519 | ospf6_lsdb_add (his, on->request_list); |
| 520 | } |
| 521 | else |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 522 | { |
| 523 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 524 | zlog_debug ("Discard (Existing MoreRecent)"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 525 | ospf6_lsa_delete (his); |
| 526 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 529 | assert (p == OSPF6_MESSAGE_END (oh)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 530 | |
| 531 | /* Increment sequence number */ |
| 532 | on->dbdesc_seqnum ++; |
| 533 | |
| 534 | /* schedule send lsreq */ |
| 535 | if (on->thread_send_lsreq == NULL) |
| 536 | on->thread_send_lsreq = |
| 537 | thread_add_event (master, ospf6_lsreq_send, on, 0); |
| 538 | |
| 539 | THREAD_OFF (on->thread_send_dbdesc); |
| 540 | |
| 541 | /* More bit check */ |
| 542 | if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) && |
| 543 | ! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT)) |
| 544 | thread_add_event (master, exchange_done, on, 0); |
| 545 | else |
| 546 | on->thread_send_dbdesc = |
| 547 | thread_add_event (master, ospf6_dbdesc_send_newone, on, 0); |
| 548 | |
| 549 | /* save last received dbdesc */ |
| 550 | memcpy (&on->dbdesc_last, dbdesc, sizeof (struct ospf6_dbdesc)); |
| 551 | } |
| 552 | |
| 553 | static void |
| 554 | ospf6_dbdesc_recv_slave (struct ospf6_header *oh, |
| 555 | struct ospf6_neighbor *on) |
| 556 | { |
| 557 | struct ospf6_dbdesc *dbdesc; |
| 558 | char *p; |
| 559 | |
| 560 | dbdesc = (struct ospf6_dbdesc *) |
| 561 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 562 | |
| 563 | if (on->state < OSPF6_NEIGHBOR_INIT) |
| 564 | { |
| 565 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 566 | zlog_debug ("Neighbor state less than Init, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 567 | return; |
| 568 | } |
| 569 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 570 | switch (on->state) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 571 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 572 | case OSPF6_NEIGHBOR_TWOWAY: |
| 573 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 574 | zlog_debug ("Neighbor state is 2-Way, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 575 | return; |
| 576 | |
| 577 | case OSPF6_NEIGHBOR_INIT: |
| 578 | thread_execute (master, twoway_received, on, 0); |
| 579 | if (on->state != OSPF6_NEIGHBOR_EXSTART) |
| 580 | { |
| 581 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 582 | zlog_debug ("Neighbor state is not ExStart, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 583 | return; |
| 584 | } |
| 585 | /* else fall through to ExStart */ |
| 586 | |
| 587 | case OSPF6_NEIGHBOR_EXSTART: |
| 588 | /* If the neighbor is Master, act as Slave. Schedule negotiation_done |
| 589 | and process LSA Headers. Otherwise, ignore this message */ |
| 590 | if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) && |
| 591 | CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) && |
| 592 | CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) && |
| 593 | ntohs (oh->length) == sizeof (struct ospf6_header) + |
| 594 | sizeof (struct ospf6_dbdesc)) |
| 595 | { |
| 596 | /* set the master/slave bit to slave */ |
| 597 | UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT); |
| 598 | |
| 599 | /* set the DD sequence number to one specified by master */ |
| 600 | on->dbdesc_seqnum = ntohl (dbdesc->seqnum); |
| 601 | |
| 602 | /* schedule NegotiationDone */ |
| 603 | thread_execute (master, negotiation_done, on, 0); |
| 604 | |
| 605 | /* Record neighbor options */ |
| 606 | memcpy (on->options, dbdesc->options, sizeof (on->options)); |
| 607 | } |
| 608 | else |
| 609 | { |
| 610 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 611 | zlog_debug ("Negotiation failed"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 612 | return; |
| 613 | } |
| 614 | break; |
| 615 | |
| 616 | case OSPF6_NEIGHBOR_EXCHANGE: |
| 617 | if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc))) |
| 618 | { |
| 619 | /* Duplicated DatabaseDescription causes slave to retransmit */ |
| 620 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 621 | zlog_debug ("Duplicated dbdesc causes retransmit"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 622 | THREAD_OFF (on->thread_send_dbdesc); |
| 623 | on->thread_send_dbdesc = |
| 624 | thread_add_event (master, ospf6_dbdesc_send, on, 0); |
| 625 | return; |
| 626 | } |
| 627 | |
| 628 | if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT)) |
| 629 | { |
| 630 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 631 | zlog_debug ("Master/Slave bit mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 632 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT)) |
| 637 | { |
| 638 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 639 | zlog_debug ("Initialize bit mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 640 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 641 | return; |
| 642 | } |
| 643 | |
| 644 | if (memcmp (on->options, dbdesc->options, sizeof (on->options))) |
| 645 | { |
| 646 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 647 | zlog_debug ("Option field mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 648 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 649 | return; |
| 650 | } |
| 651 | |
| 652 | if (ntohl (dbdesc->seqnum) != on->dbdesc_seqnum + 1) |
| 653 | { |
| 654 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 655 | zlog_debug ("Sequence number mismatch (%#lx expected)", |
| 656 | (u_long) on->dbdesc_seqnum + 1); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 657 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 658 | return; |
| 659 | } |
| 660 | break; |
| 661 | |
| 662 | case OSPF6_NEIGHBOR_LOADING: |
| 663 | case OSPF6_NEIGHBOR_FULL: |
| 664 | if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc))) |
| 665 | { |
| 666 | /* Duplicated DatabaseDescription causes slave to retransmit */ |
| 667 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 668 | zlog_debug ("Duplicated dbdesc causes retransmit"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 669 | THREAD_OFF (on->thread_send_dbdesc); |
| 670 | on->thread_send_dbdesc = |
| 671 | thread_add_event (master, ospf6_dbdesc_send, on, 0); |
| 672 | return; |
| 673 | } |
| 674 | |
| 675 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 676 | zlog_debug ("Not duplicate dbdesc in state %s", |
| 677 | ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 678 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 679 | return; |
| 680 | |
| 681 | default: |
| 682 | assert (0); |
| 683 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 684 | } |
| 685 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 686 | /* Process LSA headers */ |
| 687 | for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc)); |
| 688 | p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh); |
| 689 | p += sizeof (struct ospf6_lsa_header)) |
| 690 | { |
| 691 | struct ospf6_lsa *his, *mine; |
| 692 | struct ospf6_lsdb *lsdb = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 693 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 694 | his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 695 | |
| 696 | switch (OSPF6_LSA_SCOPE (his->header->type)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 697 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 698 | case OSPF6_SCOPE_LINKLOCAL: |
| 699 | lsdb = on->ospf6_if->lsdb; |
| 700 | break; |
| 701 | case OSPF6_SCOPE_AREA: |
| 702 | lsdb = on->ospf6_if->area->lsdb; |
| 703 | break; |
| 704 | case OSPF6_SCOPE_AS: |
| 705 | lsdb = on->ospf6_if->area->ospf6->lsdb; |
| 706 | break; |
| 707 | case OSPF6_SCOPE_RESERVED: |
| 708 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 709 | zlog_debug ("Ignoring LSA of reserved scope"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 710 | ospf6_lsa_delete (his); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 711 | continue; |
| 712 | break; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 713 | } |
| 714 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 715 | if (OSPF6_LSA_SCOPE (his->header->type) == OSPF6_SCOPE_AS && |
| 716 | IS_AREA_STUB (on->ospf6_if->area)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 717 | { |
| 718 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 719 | zlog_debug ("E-bit mismatch with LSA Headers"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 720 | ospf6_lsa_delete (his); |
| 721 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 722 | return; |
| 723 | } |
| 724 | |
| 725 | mine = ospf6_lsdb_lookup (his->header->type, his->header->id, |
| 726 | his->header->adv_router, lsdb); |
| 727 | if (mine == NULL || ospf6_lsa_compare (his, mine) < 0) |
| 728 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 729 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 730 | zlog_debug ("Add request-list: %s", his->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 731 | ospf6_lsdb_add (his, on->request_list); |
| 732 | } |
| 733 | else |
| 734 | ospf6_lsa_delete (his); |
| 735 | } |
| 736 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 737 | assert (p == OSPF6_MESSAGE_END (oh)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 738 | |
| 739 | /* Set sequence number to Master's */ |
| 740 | on->dbdesc_seqnum = ntohl (dbdesc->seqnum); |
| 741 | |
| 742 | /* schedule send lsreq */ |
| 743 | if (on->thread_send_lsreq == NULL) |
| 744 | on->thread_send_lsreq = |
| 745 | thread_add_event (master, ospf6_lsreq_send, on, 0); |
| 746 | |
| 747 | THREAD_OFF (on->thread_send_dbdesc); |
| 748 | on->thread_send_dbdesc = |
| 749 | thread_add_event (master, ospf6_dbdesc_send_newone, on, 0); |
| 750 | |
| 751 | /* save last received dbdesc */ |
| 752 | memcpy (&on->dbdesc_last, dbdesc, sizeof (struct ospf6_dbdesc)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 755 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 756 | ospf6_dbdesc_recv (struct in6_addr *src, struct in6_addr *dst, |
| 757 | struct ospf6_interface *oi, struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 758 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 759 | struct ospf6_neighbor *on; |
| 760 | struct ospf6_dbdesc *dbdesc; |
| 761 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 762 | on = ospf6_neighbor_lookup (oh->router_id, oi); |
| 763 | if (on == NULL) |
| 764 | { |
| 765 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 766 | zlog_debug ("Neighbor not found, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 767 | return; |
| 768 | } |
| 769 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 770 | dbdesc = (struct ospf6_dbdesc *) |
| 771 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 772 | |
| 773 | /* Interface MTU check */ |
Dmitrij Tejblum | ab1be8a | 2011-04-22 19:27:54 +0400 | [diff] [blame] | 774 | if (!oi->mtu_ignore && ntohs (dbdesc->ifmtu) != oi->ifmtu) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 775 | { |
| 776 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 777 | zlog_debug ("I/F MTU mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 778 | return; |
| 779 | } |
| 780 | |
| 781 | if (dbdesc->reserved1 || dbdesc->reserved2) |
| 782 | { |
| 783 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 784 | zlog_debug ("Non-0 reserved field in %s's DbDesc, correct", |
| 785 | on->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 786 | dbdesc->reserved1 = 0; |
| 787 | dbdesc->reserved2 = 0; |
| 788 | } |
| 789 | |
| 790 | if (ntohl (oh->router_id) < ntohl (ospf6->router_id)) |
| 791 | ospf6_dbdesc_recv_master (oh, on); |
| 792 | else if (ntohl (ospf6->router_id) < ntohl (oh->router_id)) |
| 793 | ospf6_dbdesc_recv_slave (oh, on); |
| 794 | else |
| 795 | { |
| 796 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 797 | zlog_debug ("Can't decide which is master, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 798 | } |
| 799 | } |
| 800 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 801 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 802 | ospf6_lsreq_recv (struct in6_addr *src, struct in6_addr *dst, |
| 803 | struct ospf6_interface *oi, struct ospf6_header *oh) |
| 804 | { |
| 805 | struct ospf6_neighbor *on; |
| 806 | char *p; |
| 807 | struct ospf6_lsreq_entry *e; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 808 | struct ospf6_lsdb *lsdb = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 809 | struct ospf6_lsa *lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 810 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 811 | on = ospf6_neighbor_lookup (oh->router_id, oi); |
| 812 | if (on == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 813 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 814 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 815 | zlog_debug ("Neighbor not found, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 816 | return; |
| 817 | } |
| 818 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 819 | if (on->state != OSPF6_NEIGHBOR_EXCHANGE && |
| 820 | on->state != OSPF6_NEIGHBOR_LOADING && |
| 821 | on->state != OSPF6_NEIGHBOR_FULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 822 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 823 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 824 | zlog_debug ("Neighbor state less than Exchange, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 825 | return; |
| 826 | } |
| 827 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 828 | /* Process each request */ |
| 829 | for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 830 | p + sizeof (struct ospf6_lsreq_entry) <= OSPF6_MESSAGE_END (oh); |
| 831 | p += sizeof (struct ospf6_lsreq_entry)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 832 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 833 | e = (struct ospf6_lsreq_entry *) p; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 834 | |
| 835 | switch (OSPF6_LSA_SCOPE (e->type)) |
| 836 | { |
| 837 | case OSPF6_SCOPE_LINKLOCAL: |
| 838 | lsdb = on->ospf6_if->lsdb; |
| 839 | break; |
| 840 | case OSPF6_SCOPE_AREA: |
| 841 | lsdb = on->ospf6_if->area->lsdb; |
| 842 | break; |
| 843 | case OSPF6_SCOPE_AS: |
| 844 | lsdb = on->ospf6_if->area->ospf6->lsdb; |
| 845 | break; |
| 846 | default: |
| 847 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 848 | zlog_debug ("Ignoring LSA of reserved scope"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 849 | continue; |
| 850 | break; |
| 851 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 852 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 853 | /* Find database copy */ |
| 854 | lsa = ospf6_lsdb_lookup (e->type, e->id, e->adv_router, lsdb); |
| 855 | if (lsa == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 856 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 857 | char id[16], adv_router[16]; |
| 858 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
| 859 | { |
| 860 | inet_ntop (AF_INET, &e->id, id, sizeof (id)); |
| 861 | inet_ntop (AF_INET, &e->adv_router, adv_router, |
| 862 | sizeof (adv_router)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 863 | zlog_debug ("Can't find requested [%s Id:%s Adv:%s]", |
| 864 | ospf6_lstype_name (e->type), id, adv_router); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 865 | } |
| 866 | thread_add_event (master, bad_lsreq, on, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 867 | return; |
| 868 | } |
| 869 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 870 | ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->lsupdate_list); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 873 | assert (p == OSPF6_MESSAGE_END (oh)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 874 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 875 | /* schedule send lsupdate */ |
| 876 | THREAD_OFF (on->thread_send_lsupdate); |
| 877 | on->thread_send_lsupdate = |
| 878 | thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 879 | } |
| 880 | |
Denis Ovsienko | 552563a | 2011-09-26 13:18:51 +0400 | [diff] [blame] | 881 | /* Verify, that the specified memory area contains exactly N valid IPv6 |
| 882 | prefixes as specified by RFC5340, A.4.1. */ |
| 883 | static unsigned |
| 884 | ospf6_prefixes_examin |
| 885 | ( |
| 886 | struct ospf6_prefix *current, /* start of buffer */ |
| 887 | unsigned length, |
| 888 | const u_int32_t req_num_pfxs /* always compared with the actual number of prefixes */ |
| 889 | ) |
| 890 | { |
| 891 | u_char requested_pfx_bytes; |
| 892 | u_int32_t real_num_pfxs = 0; |
| 893 | |
| 894 | while (length) |
| 895 | { |
| 896 | if (length < OSPF6_PREFIX_MIN_SIZE) |
| 897 | { |
| 898 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 899 | zlog_debug ("%s: undersized IPv6 prefix header", __func__); |
| 900 | return MSG_NG; |
| 901 | } |
| 902 | /* safe to look deeper */ |
| 903 | if (current->prefix_length > IPV6_MAX_BITLEN) |
| 904 | { |
| 905 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 906 | zlog_debug ("%s: invalid PrefixLength (%u bits)", __func__, current->prefix_length); |
| 907 | return MSG_NG; |
| 908 | } |
| 909 | /* covers both fixed- and variable-sized fields */ |
| 910 | requested_pfx_bytes = OSPF6_PREFIX_MIN_SIZE + OSPF6_PREFIX_SPACE (current->prefix_length); |
| 911 | if (requested_pfx_bytes > length) |
| 912 | { |
| 913 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 914 | zlog_debug ("%s: undersized IPv6 prefix", __func__); |
| 915 | return MSG_NG; |
| 916 | } |
| 917 | /* next prefix */ |
| 918 | length -= requested_pfx_bytes; |
| 919 | current = (struct ospf6_prefix *) ((caddr_t) current + requested_pfx_bytes); |
| 920 | real_num_pfxs++; |
| 921 | } |
| 922 | if (real_num_pfxs != req_num_pfxs) |
| 923 | { |
| 924 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 925 | zlog_debug ("%s: IPv6 prefix number mismatch (%u required, %u real)", |
| 926 | __func__, req_num_pfxs, real_num_pfxs); |
| 927 | return MSG_NG; |
| 928 | } |
| 929 | return MSG_OK; |
| 930 | } |
| 931 | |
| 932 | /* Verify an LSA to have a valid length and dispatch further (where |
| 933 | appropriate) to check if the contents, including nested IPv6 prefixes, |
| 934 | is properly sized/aligned within the LSA. Note that this function gets |
| 935 | LSA type in network byte order, uses in host byte order and passes to |
| 936 | ospf6_lstype_name() in network byte order again. */ |
| 937 | static unsigned |
| 938 | ospf6_lsa_examin (struct ospf6_lsa_header *lsah, const u_int16_t lsalen, const u_char headeronly) |
| 939 | { |
| 940 | struct ospf6_intra_prefix_lsa *intra_prefix_lsa; |
| 941 | struct ospf6_as_external_lsa *as_external_lsa; |
| 942 | struct ospf6_link_lsa *link_lsa; |
| 943 | unsigned exp_length; |
| 944 | u_int8_t ltindex; |
| 945 | u_int16_t lsatype; |
| 946 | |
| 947 | /* In case an additional minimum length constraint is defined for current |
| 948 | LSA type, make sure that this constraint is met. */ |
| 949 | lsatype = ntohs (lsah->type); |
| 950 | ltindex = lsatype & OSPF6_LSTYPE_FCODE_MASK; |
| 951 | if |
| 952 | ( |
| 953 | ltindex < OSPF6_LSTYPE_SIZE && |
| 954 | ospf6_lsa_minlen[ltindex] && |
| 955 | lsalen < ospf6_lsa_minlen[ltindex] + OSPF6_LSA_HEADER_SIZE |
| 956 | ) |
| 957 | { |
| 958 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 959 | zlog_debug ("%s: undersized (%u B) LSA", __func__, lsalen); |
| 960 | return MSG_NG; |
| 961 | } |
| 962 | switch (lsatype) |
| 963 | { |
| 964 | case OSPF6_LSTYPE_ROUTER: |
| 965 | /* RFC5340 A.4.3, LSA header + OSPF6_ROUTER_LSA_MIN_SIZE bytes followed |
| 966 | by N>=0 interface descriptions. */ |
| 967 | if ((lsalen - OSPF6_LSA_HEADER_SIZE - OSPF6_ROUTER_LSA_MIN_SIZE) % OSPF6_ROUTER_LSDESC_FIX_SIZE) |
| 968 | { |
| 969 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 970 | zlog_debug ("%s: interface description alignment error", __func__); |
| 971 | return MSG_NG; |
| 972 | } |
| 973 | break; |
| 974 | case OSPF6_LSTYPE_NETWORK: |
| 975 | /* RFC5340 A.4.4, LSA header + OSPF6_NETWORK_LSA_MIN_SIZE bytes |
| 976 | followed by N>=0 attached router descriptions. */ |
| 977 | if ((lsalen - OSPF6_LSA_HEADER_SIZE - OSPF6_NETWORK_LSA_MIN_SIZE) % OSPF6_NETWORK_LSDESC_FIX_SIZE) |
| 978 | { |
| 979 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 980 | zlog_debug ("%s: router description alignment error", __func__); |
| 981 | return MSG_NG; |
| 982 | } |
| 983 | break; |
| 984 | case OSPF6_LSTYPE_INTER_PREFIX: |
| 985 | /* RFC5340 A.4.5, LSA header + OSPF6_INTER_PREFIX_LSA_MIN_SIZE bytes |
| 986 | followed by 3-4 fields of a single IPv6 prefix. */ |
| 987 | if (headeronly) |
| 988 | break; |
| 989 | return ospf6_prefixes_examin |
| 990 | ( |
| 991 | (struct ospf6_prefix *) ((caddr_t) lsah + OSPF6_LSA_HEADER_SIZE + OSPF6_INTER_PREFIX_LSA_MIN_SIZE), |
| 992 | lsalen - OSPF6_LSA_HEADER_SIZE - OSPF6_INTER_PREFIX_LSA_MIN_SIZE, |
| 993 | 1 |
| 994 | ); |
| 995 | case OSPF6_LSTYPE_INTER_ROUTER: |
| 996 | /* RFC5340 A.4.6, fixed-size LSA. */ |
| 997 | if (lsalen > OSPF6_LSA_HEADER_SIZE + OSPF6_INTER_ROUTER_LSA_FIX_SIZE) |
| 998 | { |
| 999 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1000 | zlog_debug ("%s: oversized (%u B) LSA", __func__, lsalen); |
| 1001 | return MSG_NG; |
| 1002 | } |
| 1003 | break; |
| 1004 | case OSPF6_LSTYPE_AS_EXTERNAL: /* RFC5340 A.4.7, same as A.4.8. */ |
| 1005 | case OSPF6_LSTYPE_TYPE_7: |
| 1006 | /* RFC5340 A.4.8, LSA header + OSPF6_AS_EXTERNAL_LSA_MIN_SIZE bytes |
| 1007 | followed by 3-4 fields of IPv6 prefix and 3 conditional LSA fields: |
| 1008 | 16 bytes of forwarding address, 4 bytes of external route tag, |
| 1009 | 4 bytes of referenced link state ID. */ |
| 1010 | if (headeronly) |
| 1011 | break; |
| 1012 | as_external_lsa = (struct ospf6_as_external_lsa *) ((caddr_t) lsah + OSPF6_LSA_HEADER_SIZE); |
| 1013 | exp_length = OSPF6_LSA_HEADER_SIZE + OSPF6_AS_EXTERNAL_LSA_MIN_SIZE; |
| 1014 | /* To find out if the last optional field (Referenced Link State ID) is |
| 1015 | assumed in this LSA, we need to access fixed fields of the IPv6 |
| 1016 | prefix before ospf6_prefix_examin() confirms its sizing. */ |
| 1017 | if (exp_length + OSPF6_PREFIX_MIN_SIZE > lsalen) |
| 1018 | { |
| 1019 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1020 | zlog_debug ("%s: undersized (%u B) LSA header", __func__, lsalen); |
| 1021 | return MSG_NG; |
| 1022 | } |
| 1023 | /* forwarding address */ |
| 1024 | if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F)) |
| 1025 | exp_length += 16; |
| 1026 | /* external route tag */ |
| 1027 | if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T)) |
| 1028 | exp_length += 4; |
| 1029 | /* referenced link state ID */ |
| 1030 | if (as_external_lsa->prefix.u._prefix_referenced_lstype) |
| 1031 | exp_length += 4; |
| 1032 | /* All the fixed-size fields (mandatory and optional) must fit. I.e., |
| 1033 | this check does not include any IPv6 prefix fields. */ |
| 1034 | if (exp_length > lsalen) |
| 1035 | { |
| 1036 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1037 | zlog_debug ("%s: undersized (%u B) LSA header", __func__, lsalen); |
| 1038 | return MSG_NG; |
| 1039 | } |
| 1040 | /* The last call completely covers the remainder (IPv6 prefix). */ |
| 1041 | return ospf6_prefixes_examin |
| 1042 | ( |
| 1043 | (struct ospf6_prefix *) ((caddr_t) as_external_lsa + OSPF6_AS_EXTERNAL_LSA_MIN_SIZE), |
| 1044 | lsalen - exp_length, |
| 1045 | 1 |
| 1046 | ); |
| 1047 | case OSPF6_LSTYPE_LINK: |
| 1048 | /* RFC5340 A.4.9, LSA header + OSPF6_LINK_LSA_MIN_SIZE bytes followed |
| 1049 | by N>=0 IPv6 prefix blocks (with N declared beforehand). */ |
| 1050 | if (headeronly) |
| 1051 | break; |
| 1052 | link_lsa = (struct ospf6_link_lsa *) ((caddr_t) lsah + OSPF6_LSA_HEADER_SIZE); |
| 1053 | return ospf6_prefixes_examin |
| 1054 | ( |
| 1055 | (struct ospf6_prefix *) ((caddr_t) link_lsa + OSPF6_LINK_LSA_MIN_SIZE), |
| 1056 | lsalen - OSPF6_LSA_HEADER_SIZE - OSPF6_LINK_LSA_MIN_SIZE, |
| 1057 | ntohl (link_lsa->prefix_num) /* 32 bits */ |
| 1058 | ); |
| 1059 | case OSPF6_LSTYPE_INTRA_PREFIX: |
| 1060 | /* RFC5340 A.4.10, LSA header + OSPF6_INTRA_PREFIX_LSA_MIN_SIZE bytes |
| 1061 | followed by N>=0 IPv6 prefixes (with N declared beforehand). */ |
| 1062 | if (headeronly) |
| 1063 | break; |
| 1064 | intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *) ((caddr_t) lsah + OSPF6_LSA_HEADER_SIZE); |
| 1065 | return ospf6_prefixes_examin |
| 1066 | ( |
| 1067 | (struct ospf6_prefix *) ((caddr_t) intra_prefix_lsa + OSPF6_INTRA_PREFIX_LSA_MIN_SIZE), |
| 1068 | lsalen - OSPF6_LSA_HEADER_SIZE - OSPF6_INTRA_PREFIX_LSA_MIN_SIZE, |
| 1069 | ntohs (intra_prefix_lsa->prefix_num) /* 16 bits */ |
| 1070 | ); |
| 1071 | } |
| 1072 | /* No additional validation is possible for unknown LSA types, which are |
| 1073 | themselves valid in OPSFv3, hence the default decision is to accept. */ |
| 1074 | return MSG_OK; |
| 1075 | } |
| 1076 | |
| 1077 | /* Verify if the provided input buffer is a valid sequence of LSAs. This |
| 1078 | includes verification of LSA blocks length/alignment and dispatching |
| 1079 | of deeper-level checks. */ |
| 1080 | static unsigned |
| 1081 | ospf6_lsaseq_examin |
| 1082 | ( |
| 1083 | struct ospf6_lsa_header *lsah, /* start of buffered data */ |
| 1084 | size_t length, |
| 1085 | const u_char headeronly, |
| 1086 | /* When declared_num_lsas is not 0, compare it to the real number of LSAs |
| 1087 | and treat the difference as an error. */ |
| 1088 | const u_int32_t declared_num_lsas |
| 1089 | ) |
| 1090 | { |
| 1091 | u_int32_t counted_lsas = 0; |
| 1092 | |
| 1093 | while (length) |
| 1094 | { |
| 1095 | u_int16_t lsalen; |
| 1096 | if (length < OSPF6_LSA_HEADER_SIZE) |
| 1097 | { |
| 1098 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1099 | zlog_debug ("%s: undersized (%u B) trailing (#%u) LSA header", |
| 1100 | __func__, length, counted_lsas); |
| 1101 | return MSG_NG; |
| 1102 | } |
| 1103 | /* save on ntohs() calls here and in the LSA validator */ |
| 1104 | lsalen = OSPF6_LSA_SIZE (lsah); |
| 1105 | if (lsalen < OSPF6_LSA_HEADER_SIZE) |
| 1106 | { |
| 1107 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1108 | zlog_debug ("%s: malformed LSA header #%u, declared length is %u B", |
| 1109 | __func__, counted_lsas, lsalen); |
| 1110 | return MSG_NG; |
| 1111 | } |
| 1112 | if (headeronly) |
| 1113 | { |
| 1114 | /* less checks here and in ospf6_lsa_examin() */ |
| 1115 | if (MSG_OK != ospf6_lsa_examin (lsah, lsalen, 1)) |
| 1116 | { |
| 1117 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1118 | zlog_debug ("%s: anomaly in header-only %s LSA #%u", __func__, |
| 1119 | ospf6_lstype_name (lsah->type), counted_lsas); |
| 1120 | return MSG_NG; |
| 1121 | } |
| 1122 | lsah = (struct ospf6_lsa_header *) ((caddr_t) lsah + OSPF6_LSA_HEADER_SIZE); |
| 1123 | length -= OSPF6_LSA_HEADER_SIZE; |
| 1124 | } |
| 1125 | else |
| 1126 | { |
| 1127 | /* make sure the input buffer is deep enough before further checks */ |
| 1128 | if (lsalen > length) |
| 1129 | { |
| 1130 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1131 | zlog_debug ("%s: anomaly in %s LSA #%u: declared length is %u B, buffered length is %u B", |
| 1132 | __func__, ospf6_lstype_name (lsah->type), counted_lsas, lsalen, length); |
| 1133 | return MSG_NG; |
| 1134 | } |
| 1135 | if (MSG_OK != ospf6_lsa_examin (lsah, lsalen, 0)) |
| 1136 | { |
| 1137 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1138 | zlog_debug ("%s: anomaly in %s LSA #%u", __func__, |
| 1139 | ospf6_lstype_name (lsah->type), counted_lsas); |
| 1140 | return MSG_NG; |
| 1141 | } |
| 1142 | lsah = (struct ospf6_lsa_header *) ((caddr_t) lsah + lsalen); |
| 1143 | length -= lsalen; |
| 1144 | } |
| 1145 | counted_lsas++; |
| 1146 | } |
| 1147 | |
| 1148 | if (declared_num_lsas && counted_lsas != declared_num_lsas) |
| 1149 | { |
| 1150 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1151 | zlog_debug ("%s: #LSAs declared (%u) does not match actual (%u)", |
| 1152 | __func__, declared_num_lsas, counted_lsas); |
| 1153 | return MSG_NG; |
| 1154 | } |
| 1155 | return MSG_OK; |
| 1156 | } |
| 1157 | |
| 1158 | /* Verify a complete OSPF packet for proper sizing/alignment. */ |
| 1159 | static unsigned |
| 1160 | ospf6_packet_examin (struct ospf6_header *oh, const unsigned bytesonwire) |
| 1161 | { |
| 1162 | struct ospf6_lsupdate *lsupd; |
| 1163 | unsigned test; |
| 1164 | |
| 1165 | /* length, 1st approximation */ |
| 1166 | if (bytesonwire < OSPF6_HEADER_SIZE) |
| 1167 | { |
| 1168 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1169 | zlog_debug ("%s: undersized (%u B) packet", __func__, bytesonwire); |
| 1170 | return MSG_NG; |
| 1171 | } |
| 1172 | /* Now it is safe to access header fields. */ |
| 1173 | if (bytesonwire != ntohs (oh->length)) |
| 1174 | { |
| 1175 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1176 | zlog_debug ("%s: packet length error (%u real, %u declared)", |
| 1177 | __func__, bytesonwire, ntohs (oh->length)); |
| 1178 | return MSG_NG; |
| 1179 | } |
| 1180 | /* version check */ |
| 1181 | if (oh->version != OSPFV3_VERSION) |
| 1182 | { |
| 1183 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1184 | zlog_debug ("%s: invalid (%u) protocol version", __func__, oh->version); |
| 1185 | return MSG_NG; |
| 1186 | } |
| 1187 | /* length, 2nd approximation */ |
| 1188 | if |
| 1189 | ( |
| 1190 | oh->type < OSPF6_MESSAGE_TYPE_ALL && |
| 1191 | ospf6_packet_minlen[oh->type] && |
| 1192 | bytesonwire < OSPF6_HEADER_SIZE + ospf6_packet_minlen[oh->type] |
| 1193 | ) |
| 1194 | { |
| 1195 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1196 | zlog_debug ("%s: undersized (%u B) %s packet", __func__, |
| 1197 | bytesonwire, ospf6_message_type_str[oh->type]); |
| 1198 | return MSG_NG; |
| 1199 | } |
| 1200 | /* type-specific deeper validation */ |
| 1201 | switch (oh->type) |
| 1202 | { |
| 1203 | case OSPF6_MESSAGE_TYPE_HELLO: |
| 1204 | /* RFC5340 A.3.2, packet header + OSPF6_HELLO_MIN_SIZE bytes followed |
| 1205 | by N>=0 router-IDs. */ |
| 1206 | if (0 == (bytesonwire - OSPF6_HEADER_SIZE - OSPF6_HELLO_MIN_SIZE) % 4) |
| 1207 | return MSG_OK; |
| 1208 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1209 | zlog_debug ("%s: alignment error in %s packet", |
| 1210 | __func__, ospf6_message_type_str[oh->type]); |
| 1211 | return MSG_NG; |
| 1212 | case OSPF6_MESSAGE_TYPE_DBDESC: |
| 1213 | /* RFC5340 A.3.3, packet header + OSPF6_DB_DESC_MIN_SIZE bytes followed |
| 1214 | by N>=0 header-only LSAs. */ |
| 1215 | test = ospf6_lsaseq_examin |
| 1216 | ( |
| 1217 | (struct ospf6_lsa_header *) ((caddr_t) oh + OSPF6_HEADER_SIZE + OSPF6_DB_DESC_MIN_SIZE), |
| 1218 | bytesonwire - OSPF6_HEADER_SIZE - OSPF6_DB_DESC_MIN_SIZE, |
| 1219 | 1, |
| 1220 | 0 |
| 1221 | ); |
| 1222 | break; |
| 1223 | case OSPF6_MESSAGE_TYPE_LSREQ: |
| 1224 | /* RFC5340 A.3.4, packet header + N>=0 LS description blocks. */ |
| 1225 | if (0 == (bytesonwire - OSPF6_HEADER_SIZE - OSPF6_LS_REQ_MIN_SIZE) % OSPF6_LSREQ_LSDESC_FIX_SIZE) |
| 1226 | return MSG_OK; |
| 1227 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1228 | zlog_debug ("%s: alignment error in %s packet", |
| 1229 | __func__, ospf6_message_type_str[oh->type]); |
| 1230 | return MSG_NG; |
| 1231 | case OSPF6_MESSAGE_TYPE_LSUPDATE: |
| 1232 | /* RFC5340 A.3.5, packet header + OSPF6_LS_UPD_MIN_SIZE bytes followed |
| 1233 | by N>=0 full LSAs (with N declared beforehand). */ |
| 1234 | lsupd = (struct ospf6_lsupdate *) ((caddr_t) oh + OSPF6_HEADER_SIZE); |
| 1235 | test = ospf6_lsaseq_examin |
| 1236 | ( |
| 1237 | (struct ospf6_lsa_header *) ((caddr_t) lsupd + OSPF6_LS_UPD_MIN_SIZE), |
| 1238 | bytesonwire - OSPF6_HEADER_SIZE - OSPF6_LS_UPD_MIN_SIZE, |
| 1239 | 0, |
| 1240 | ntohl (lsupd->lsa_number) /* 32 bits */ |
| 1241 | ); |
| 1242 | break; |
| 1243 | case OSPF6_MESSAGE_TYPE_LSACK: |
| 1244 | /* RFC5340 A.3.6, packet header + N>=0 header-only LSAs. */ |
| 1245 | test = ospf6_lsaseq_examin |
| 1246 | ( |
| 1247 | (struct ospf6_lsa_header *) ((caddr_t) oh + OSPF6_HEADER_SIZE + OSPF6_LS_ACK_MIN_SIZE), |
| 1248 | bytesonwire - OSPF6_HEADER_SIZE - OSPF6_LS_ACK_MIN_SIZE, |
| 1249 | 1, |
| 1250 | 0 |
| 1251 | ); |
| 1252 | break; |
| 1253 | default: |
| 1254 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1255 | zlog_debug ("%s: invalid (%u) message type", __func__, oh->type); |
| 1256 | return MSG_NG; |
| 1257 | } |
| 1258 | if (test != MSG_OK && IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1259 | zlog_debug ("%s: anomaly in %s packet", __func__, ospf6_message_type_str[oh->type]); |
| 1260 | return test; |
| 1261 | } |
| 1262 | |
| 1263 | /* Verify particular fields of otherwise correct received OSPF packet to |
| 1264 | meet the requirements of RFC. */ |
| 1265 | static int |
| 1266 | ospf6_rxpacket_examin (struct ospf6_interface *oi, struct ospf6_header *oh, const unsigned bytesonwire) |
| 1267 | { |
| 1268 | char buf[2][INET_ADDRSTRLEN]; |
| 1269 | |
| 1270 | if (MSG_OK != ospf6_packet_examin (oh, bytesonwire)) |
| 1271 | return MSG_NG; |
| 1272 | |
| 1273 | /* Area-ID check */ |
| 1274 | if (oh->area_id != oi->area->area_id) |
| 1275 | { |
| 1276 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
| 1277 | { |
| 1278 | if (oh->area_id == BACKBONE_AREA_ID) |
| 1279 | zlog_debug ("%s: Message may be via Virtual Link: not supported", __func__); |
| 1280 | else |
| 1281 | zlog_debug |
| 1282 | ( |
| 1283 | "%s: Area-ID mismatch (my %s, rcvd %s)", __func__, |
| 1284 | inet_ntop (AF_INET, &oi->area->area_id, buf[0], INET_ADDRSTRLEN), |
| 1285 | inet_ntop (AF_INET, &oh->area_id, buf[1], INET_ADDRSTRLEN) |
| 1286 | ); |
| 1287 | } |
| 1288 | return MSG_NG; |
| 1289 | } |
| 1290 | |
| 1291 | /* Instance-ID check */ |
| 1292 | if (oh->instance_id != oi->instance_id) |
| 1293 | { |
| 1294 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
| 1295 | zlog_debug ("%s: Instance-ID mismatch (my %u, rcvd %u)", __func__, oi->instance_id, oh->instance_id); |
| 1296 | return MSG_NG; |
| 1297 | } |
| 1298 | |
| 1299 | /* Router-ID check */ |
| 1300 | if (oh->router_id == oi->area->ospf6->router_id) |
| 1301 | { |
| 1302 | zlog_warn ("%s: Duplicate Router-ID (%s)", __func__, inet_ntop (AF_INET, &oh->router_id, buf[0], INET_ADDRSTRLEN)); |
| 1303 | return MSG_NG; |
| 1304 | } |
| 1305 | return MSG_OK; |
| 1306 | } |
| 1307 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1308 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1309 | ospf6_lsupdate_recv (struct in6_addr *src, struct in6_addr *dst, |
| 1310 | struct ospf6_interface *oi, struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1311 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1312 | struct ospf6_neighbor *on; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1313 | struct ospf6_lsupdate *lsupdate; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1314 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1315 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1316 | on = ospf6_neighbor_lookup (oh->router_id, oi); |
| 1317 | if (on == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1318 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1319 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1320 | zlog_debug ("Neighbor not found, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1321 | return; |
| 1322 | } |
| 1323 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1324 | if (on->state != OSPF6_NEIGHBOR_EXCHANGE && |
| 1325 | on->state != OSPF6_NEIGHBOR_LOADING && |
| 1326 | on->state != OSPF6_NEIGHBOR_FULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1327 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1328 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1329 | zlog_debug ("Neighbor state less than Exchange, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1330 | return; |
| 1331 | } |
| 1332 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1333 | lsupdate = (struct ospf6_lsupdate *) |
| 1334 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1335 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1336 | /* Process LSAs */ |
| 1337 | for (p = (char *) ((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate)); |
| 1338 | p < OSPF6_MESSAGE_END (oh) && |
| 1339 | p + OSPF6_LSA_SIZE (p) <= OSPF6_MESSAGE_END (oh); |
| 1340 | p += OSPF6_LSA_SIZE (p)) |
| 1341 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1342 | ospf6_receive_lsa (on, (struct ospf6_lsa_header *) p); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 1345 | assert (p == OSPF6_MESSAGE_END (oh)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1346 | |
| 1347 | /* RFC2328 Section 10.9: When the neighbor responds to these requests |
| 1348 | with the proper Link State Update packet(s), the Link state request |
| 1349 | list is truncated and a new Link State Request packet is sent. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1350 | /* send new Link State Request packet if this LS Update packet |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1351 | can be recognized as a response to our previous LS Request */ |
| 1352 | if (! IN6_IS_ADDR_MULTICAST (dst) && |
| 1353 | (on->state == OSPF6_NEIGHBOR_EXCHANGE || |
| 1354 | on->state == OSPF6_NEIGHBOR_LOADING)) |
| 1355 | { |
| 1356 | THREAD_OFF (on->thread_send_lsreq); |
| 1357 | on->thread_send_lsreq = |
| 1358 | thread_add_event (master, ospf6_lsreq_send, on, 0); |
| 1359 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1362 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1363 | ospf6_lsack_recv (struct in6_addr *src, struct in6_addr *dst, |
| 1364 | struct ospf6_interface *oi, struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1365 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1366 | struct ospf6_neighbor *on; |
| 1367 | char *p; |
| 1368 | struct ospf6_lsa *his, *mine; |
| 1369 | struct ospf6_lsdb *lsdb = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1370 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1371 | assert (oh->type == OSPF6_MESSAGE_TYPE_LSACK); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1372 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1373 | on = ospf6_neighbor_lookup (oh->router_id, oi); |
| 1374 | if (on == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1375 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1376 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1377 | zlog_debug ("Neighbor not found, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1378 | return; |
| 1379 | } |
| 1380 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1381 | if (on->state != OSPF6_NEIGHBOR_EXCHANGE && |
| 1382 | on->state != OSPF6_NEIGHBOR_LOADING && |
| 1383 | on->state != OSPF6_NEIGHBOR_FULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1384 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1385 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1386 | zlog_debug ("Neighbor state less than Exchange, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1387 | return; |
| 1388 | } |
| 1389 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1390 | for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 1391 | p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh); |
| 1392 | p += sizeof (struct ospf6_lsa_header)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1393 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1394 | his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1395 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1396 | switch (OSPF6_LSA_SCOPE (his->header->type)) |
| 1397 | { |
| 1398 | case OSPF6_SCOPE_LINKLOCAL: |
| 1399 | lsdb = on->ospf6_if->lsdb; |
| 1400 | break; |
| 1401 | case OSPF6_SCOPE_AREA: |
| 1402 | lsdb = on->ospf6_if->area->lsdb; |
| 1403 | break; |
| 1404 | case OSPF6_SCOPE_AS: |
| 1405 | lsdb = on->ospf6_if->area->ospf6->lsdb; |
| 1406 | break; |
| 1407 | case OSPF6_SCOPE_RESERVED: |
| 1408 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1409 | zlog_debug ("Ignoring LSA of reserved scope"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1410 | ospf6_lsa_delete (his); |
| 1411 | continue; |
| 1412 | break; |
| 1413 | } |
| 1414 | |
| 1415 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1416 | zlog_debug ("%s acknowledged by %s", his->name, on->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1417 | |
| 1418 | /* Find database copy */ |
| 1419 | mine = ospf6_lsdb_lookup (his->header->type, his->header->id, |
| 1420 | his->header->adv_router, lsdb); |
| 1421 | if (mine == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1422 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1423 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1424 | zlog_debug ("No database copy"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1425 | ospf6_lsa_delete (his); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1426 | continue; |
| 1427 | } |
| 1428 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1429 | /* Check if the LSA is on his retrans-list */ |
| 1430 | mine = ospf6_lsdb_lookup (his->header->type, his->header->id, |
| 1431 | his->header->adv_router, on->retrans_list); |
| 1432 | if (mine == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1433 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1434 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1435 | zlog_debug ("Not on %s's retrans-list", on->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1436 | ospf6_lsa_delete (his); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1437 | continue; |
| 1438 | } |
| 1439 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1440 | if (ospf6_lsa_compare (his, mine) != 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1441 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1442 | /* Log this questionable acknowledgement, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1443 | and examine the next one. */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1444 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1445 | zlog_debug ("Questionable acknowledgement"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1446 | ospf6_lsa_delete (his); |
| 1447 | continue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1450 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1451 | zlog_debug ("Acknowledged, remove from %s's retrans-list", |
| 1452 | on->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1453 | |
Paul Jakma | 932bf19 | 2006-05-15 10:42:24 +0000 | [diff] [blame] | 1454 | ospf6_decrement_retrans_count (mine); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1455 | if (OSPF6_LSA_IS_MAXAGE (mine)) |
| 1456 | ospf6_maxage_remove (on->ospf6_if->area->ospf6); |
Paul Jakma | cf1ce25 | 2006-05-15 10:46:07 +0000 | [diff] [blame] | 1457 | ospf6_lsdb_remove (mine, on->retrans_list); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1458 | ospf6_lsa_delete (his); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 1461 | assert (p == OSPF6_MESSAGE_END (oh)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1464 | static u_char *recvbuf = NULL; |
| 1465 | static u_char *sendbuf = NULL; |
| 1466 | static unsigned int iobuflen = 0; |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1467 | |
| 1468 | int |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1469 | ospf6_iobuf_size (unsigned int size) |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1470 | { |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1471 | u_char *recvnew, *sendnew; |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1472 | |
| 1473 | if (size <= iobuflen) |
| 1474 | return iobuflen; |
| 1475 | |
| 1476 | recvnew = XMALLOC (MTYPE_OSPF6_MESSAGE, size); |
| 1477 | sendnew = XMALLOC (MTYPE_OSPF6_MESSAGE, size); |
| 1478 | if (recvnew == NULL || sendnew == NULL) |
| 1479 | { |
hasso | b596c71 | 2004-07-09 18:33:43 +0000 | [diff] [blame] | 1480 | if (recvnew) |
| 1481 | XFREE (MTYPE_OSPF6_MESSAGE, recvnew); |
| 1482 | if (sendnew) |
| 1483 | XFREE (MTYPE_OSPF6_MESSAGE, sendnew); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1484 | zlog_debug ("Could not allocate I/O buffer of size %d.", size); |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1485 | return iobuflen; |
| 1486 | } |
| 1487 | |
| 1488 | if (recvbuf) |
| 1489 | XFREE (MTYPE_OSPF6_MESSAGE, recvbuf); |
| 1490 | if (sendbuf) |
| 1491 | XFREE (MTYPE_OSPF6_MESSAGE, sendbuf); |
| 1492 | recvbuf = recvnew; |
| 1493 | sendbuf = sendnew; |
| 1494 | iobuflen = size; |
| 1495 | |
| 1496 | return iobuflen; |
| 1497 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1498 | |
| 1499 | int |
| 1500 | ospf6_receive (struct thread *thread) |
| 1501 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1502 | int sockfd; |
| 1503 | unsigned int len; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1504 | char srcname[64], dstname[64]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1505 | struct in6_addr src, dst; |
| 1506 | unsigned int ifindex; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1507 | struct iovec iovector[2]; |
| 1508 | struct ospf6_interface *oi; |
| 1509 | struct ospf6_header *oh; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1510 | |
| 1511 | /* add next read thread */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1512 | sockfd = THREAD_FD (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1513 | thread_add_read (master, ospf6_receive, NULL, sockfd); |
| 1514 | |
| 1515 | /* initialize */ |
Paul Jakma | cf1ce25 | 2006-05-15 10:46:07 +0000 | [diff] [blame] | 1516 | memset (&src, 0, sizeof (src)); |
| 1517 | memset (&dst, 0, sizeof (dst)); |
| 1518 | ifindex = 0; |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1519 | memset (recvbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1520 | iovector[0].iov_base = recvbuf; |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1521 | iovector[0].iov_len = iobuflen; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1522 | iovector[1].iov_base = NULL; |
| 1523 | iovector[1].iov_len = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1524 | |
| 1525 | /* receive message */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1526 | len = ospf6_recvmsg (&src, &dst, &ifindex, iovector); |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1527 | if (len > iobuflen) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1528 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1529 | zlog_err ("Excess message read"); |
| 1530 | return 0; |
| 1531 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1532 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1533 | oi = ospf6_interface_lookup_by_ifindex (ifindex); |
| 1534 | if (oi == NULL || oi->area == NULL) |
| 1535 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1536 | zlog_debug ("Message received on disabled interface"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1537 | return 0; |
| 1538 | } |
Denis Ovsienko | 552563a | 2011-09-26 13:18:51 +0400 | [diff] [blame] | 1539 | if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE)) |
| 1540 | { |
| 1541 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
| 1542 | zlog_debug ("%s: Ignore message on passive interface %s", |
| 1543 | __func__, oi->interface->name); |
| 1544 | return 0; |
| 1545 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1546 | |
| 1547 | oh = (struct ospf6_header *) recvbuf; |
Denis Ovsienko | 552563a | 2011-09-26 13:18:51 +0400 | [diff] [blame] | 1548 | if (ospf6_rxpacket_examin (oi, oh, len) != MSG_OK) |
| 1549 | return 0; |
| 1550 | |
| 1551 | /* Being here means, that no sizing/alignment issues were detected in |
| 1552 | the input packet. This renders the additional checks performed below |
| 1553 | and also in the type-specific dispatching functions a dead code, |
| 1554 | which can be dismissed in a cleanup-focused review round later. */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1555 | |
| 1556 | /* Log */ |
| 1557 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
| 1558 | { |
| 1559 | inet_ntop (AF_INET6, &src, srcname, sizeof (srcname)); |
| 1560 | inet_ntop (AF_INET6, &dst, dstname, sizeof (dstname)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1561 | zlog_debug ("%s received on %s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1562 | OSPF6_MESSAGE_TYPE_NAME (oh->type), oi->interface->name); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1563 | zlog_debug (" src: %s", srcname); |
| 1564 | zlog_debug (" dst: %s", dstname); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1565 | |
| 1566 | switch (oh->type) |
| 1567 | { |
| 1568 | case OSPF6_MESSAGE_TYPE_HELLO: |
| 1569 | ospf6_hello_print (oh); |
| 1570 | break; |
| 1571 | case OSPF6_MESSAGE_TYPE_DBDESC: |
| 1572 | ospf6_dbdesc_print (oh); |
| 1573 | break; |
| 1574 | case OSPF6_MESSAGE_TYPE_LSREQ: |
| 1575 | ospf6_lsreq_print (oh); |
| 1576 | break; |
| 1577 | case OSPF6_MESSAGE_TYPE_LSUPDATE: |
| 1578 | ospf6_lsupdate_print (oh); |
| 1579 | break; |
| 1580 | case OSPF6_MESSAGE_TYPE_LSACK: |
| 1581 | ospf6_lsack_print (oh); |
| 1582 | break; |
| 1583 | default: |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 1584 | assert (0); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1585 | } |
| 1586 | } |
| 1587 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1588 | switch (oh->type) |
| 1589 | { |
| 1590 | case OSPF6_MESSAGE_TYPE_HELLO: |
| 1591 | ospf6_hello_recv (&src, &dst, oi, oh); |
| 1592 | break; |
| 1593 | |
| 1594 | case OSPF6_MESSAGE_TYPE_DBDESC: |
| 1595 | ospf6_dbdesc_recv (&src, &dst, oi, oh); |
| 1596 | break; |
| 1597 | |
| 1598 | case OSPF6_MESSAGE_TYPE_LSREQ: |
| 1599 | ospf6_lsreq_recv (&src, &dst, oi, oh); |
| 1600 | break; |
| 1601 | |
| 1602 | case OSPF6_MESSAGE_TYPE_LSUPDATE: |
| 1603 | ospf6_lsupdate_recv (&src, &dst, oi, oh); |
| 1604 | break; |
| 1605 | |
| 1606 | case OSPF6_MESSAGE_TYPE_LSACK: |
| 1607 | ospf6_lsack_recv (&src, &dst, oi, oh); |
| 1608 | break; |
| 1609 | |
| 1610 | default: |
Denis Ovsienko | 484af2c | 2011-10-08 17:22:45 +0400 | [diff] [blame] | 1611 | assert (0); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | return 0; |
| 1615 | } |
| 1616 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1617 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1618 | ospf6_send (struct in6_addr *src, struct in6_addr *dst, |
| 1619 | struct ospf6_interface *oi, struct ospf6_header *oh) |
| 1620 | { |
| 1621 | int len; |
| 1622 | char srcname[64], dstname[64]; |
| 1623 | struct iovec iovector[2]; |
| 1624 | |
| 1625 | /* initialize */ |
| 1626 | iovector[0].iov_base = (caddr_t) oh; |
| 1627 | iovector[0].iov_len = ntohs (oh->length); |
| 1628 | iovector[1].iov_base = NULL; |
| 1629 | iovector[1].iov_len = 0; |
| 1630 | |
| 1631 | /* fill OSPF header */ |
| 1632 | oh->version = OSPFV3_VERSION; |
| 1633 | /* message type must be set before */ |
| 1634 | /* message length must be set before */ |
| 1635 | oh->router_id = oi->area->ospf6->router_id; |
| 1636 | oh->area_id = oi->area->area_id; |
| 1637 | /* checksum is calculated by kernel */ |
| 1638 | oh->instance_id = oi->instance_id; |
| 1639 | oh->reserved = 0; |
| 1640 | |
| 1641 | /* Log */ |
| 1642 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, SEND)) |
| 1643 | { |
| 1644 | inet_ntop (AF_INET6, dst, dstname, sizeof (dstname)); |
| 1645 | if (src) |
| 1646 | inet_ntop (AF_INET6, src, srcname, sizeof (srcname)); |
| 1647 | else |
| 1648 | memset (srcname, 0, sizeof (srcname)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1649 | zlog_debug ("%s send on %s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1650 | OSPF6_MESSAGE_TYPE_NAME (oh->type), oi->interface->name); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1651 | zlog_debug (" src: %s", srcname); |
| 1652 | zlog_debug (" dst: %s", dstname); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1653 | |
| 1654 | switch (oh->type) |
| 1655 | { |
| 1656 | case OSPF6_MESSAGE_TYPE_HELLO: |
| 1657 | ospf6_hello_print (oh); |
| 1658 | break; |
| 1659 | case OSPF6_MESSAGE_TYPE_DBDESC: |
| 1660 | ospf6_dbdesc_print (oh); |
| 1661 | break; |
| 1662 | case OSPF6_MESSAGE_TYPE_LSREQ: |
| 1663 | ospf6_lsreq_print (oh); |
| 1664 | break; |
| 1665 | case OSPF6_MESSAGE_TYPE_LSUPDATE: |
| 1666 | ospf6_lsupdate_print (oh); |
| 1667 | break; |
| 1668 | case OSPF6_MESSAGE_TYPE_LSACK: |
| 1669 | ospf6_lsack_print (oh); |
| 1670 | break; |
| 1671 | default: |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1672 | zlog_debug ("Unknown message"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1673 | assert (0); |
| 1674 | break; |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | /* send message */ |
| 1679 | len = ospf6_sendmsg (src, dst, &oi->interface->ifindex, iovector); |
| 1680 | if (len != ntohs (oh->length)) |
| 1681 | zlog_err ("Could not send entire message"); |
| 1682 | } |
| 1683 | |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 1684 | static int |
| 1685 | ospf6_packet_max(struct ospf6_interface *oi) |
| 1686 | { |
| 1687 | return oi->ifmtu - sizeof(struct ip6_hdr); |
| 1688 | } |
| 1689 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1690 | int |
| 1691 | ospf6_hello_send (struct thread *thread) |
| 1692 | { |
| 1693 | struct ospf6_interface *oi; |
| 1694 | struct ospf6_header *oh; |
| 1695 | struct ospf6_hello *hello; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1696 | u_char *p; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1697 | struct listnode *node, *nnode; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1698 | struct ospf6_neighbor *on; |
| 1699 | |
| 1700 | oi = (struct ospf6_interface *) THREAD_ARG (thread); |
| 1701 | oi->thread_send_hello = (struct thread *) NULL; |
| 1702 | |
| 1703 | if (oi->state <= OSPF6_INTERFACE_DOWN) |
| 1704 | { |
| 1705 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_HELLO, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1706 | zlog_debug ("Unable to send Hello on down interface %s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1707 | oi->interface->name); |
| 1708 | return 0; |
| 1709 | } |
| 1710 | |
| 1711 | /* set next thread */ |
| 1712 | oi->thread_send_hello = thread_add_timer (master, ospf6_hello_send, |
| 1713 | oi, oi->hello_interval); |
| 1714 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1715 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1716 | oh = (struct ospf6_header *) sendbuf; |
| 1717 | hello = (struct ospf6_hello *)((caddr_t) oh + sizeof (struct ospf6_header)); |
| 1718 | |
| 1719 | hello->interface_id = htonl (oi->interface->ifindex); |
| 1720 | hello->priority = oi->priority; |
| 1721 | hello->options[0] = oi->area->options[0]; |
| 1722 | hello->options[1] = oi->area->options[1]; |
| 1723 | hello->options[2] = oi->area->options[2]; |
| 1724 | hello->hello_interval = htons (oi->hello_interval); |
| 1725 | hello->dead_interval = htons (oi->dead_interval); |
| 1726 | hello->drouter = oi->drouter; |
| 1727 | hello->bdrouter = oi->bdrouter; |
| 1728 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1729 | p = (u_char *)((caddr_t) hello + sizeof (struct ospf6_hello)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1730 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1731 | for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1732 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1733 | if (on->state < OSPF6_NEIGHBOR_INIT) |
| 1734 | continue; |
| 1735 | |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 1736 | if (p - sendbuf + sizeof (u_int32_t) > ospf6_packet_max(oi)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1737 | { |
| 1738 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_HELLO, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1739 | zlog_debug ("sending Hello message: exceeds I/F MTU"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1740 | break; |
| 1741 | } |
| 1742 | |
| 1743 | memcpy (p, &on->router_id, sizeof (u_int32_t)); |
| 1744 | p += sizeof (u_int32_t); |
| 1745 | } |
| 1746 | |
| 1747 | oh->type = OSPF6_MESSAGE_TYPE_HELLO; |
| 1748 | oh->length = htons (p - sendbuf); |
| 1749 | |
| 1750 | ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh); |
| 1751 | return 0; |
| 1752 | } |
| 1753 | |
| 1754 | int |
| 1755 | ospf6_dbdesc_send (struct thread *thread) |
| 1756 | { |
| 1757 | struct ospf6_neighbor *on; |
| 1758 | struct ospf6_header *oh; |
| 1759 | struct ospf6_dbdesc *dbdesc; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1760 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1761 | struct ospf6_lsa *lsa; |
| 1762 | |
| 1763 | on = (struct ospf6_neighbor *) THREAD_ARG (thread); |
| 1764 | on->thread_send_dbdesc = (struct thread *) NULL; |
| 1765 | |
| 1766 | if (on->state < OSPF6_NEIGHBOR_EXSTART) |
| 1767 | { |
| 1768 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_DBDESC, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1769 | zlog_debug ("Quit to send DbDesc to neighbor %s state %s", |
| 1770 | on->name, ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1771 | return 0; |
| 1772 | } |
| 1773 | |
| 1774 | /* set next thread if master */ |
| 1775 | if (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT)) |
| 1776 | on->thread_send_dbdesc = |
| 1777 | thread_add_timer (master, ospf6_dbdesc_send, on, |
| 1778 | on->ospf6_if->rxmt_interval); |
| 1779 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1780 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1781 | oh = (struct ospf6_header *) sendbuf; |
| 1782 | dbdesc = (struct ospf6_dbdesc *)((caddr_t) oh + |
| 1783 | sizeof (struct ospf6_header)); |
| 1784 | |
| 1785 | /* if this is initial one, initialize sequence number for DbDesc */ |
| 1786 | if (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT)) |
| 1787 | { |
| 1788 | struct timeval tv; |
Takashi Sogabe | 86f72dc | 2009-06-22 13:07:02 +0900 | [diff] [blame] | 1789 | if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &tv) < 0) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1790 | tv.tv_sec = 1; |
| 1791 | on->dbdesc_seqnum = tv.tv_sec; |
| 1792 | } |
| 1793 | |
| 1794 | dbdesc->options[0] = on->ospf6_if->area->options[0]; |
| 1795 | dbdesc->options[1] = on->ospf6_if->area->options[1]; |
| 1796 | dbdesc->options[2] = on->ospf6_if->area->options[2]; |
| 1797 | dbdesc->ifmtu = htons (on->ospf6_if->ifmtu); |
| 1798 | dbdesc->bits = on->dbdesc_bits; |
| 1799 | dbdesc->seqnum = htonl (on->dbdesc_seqnum); |
| 1800 | |
| 1801 | /* if this is not initial one, set LSA headers in dbdesc */ |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1802 | p = (u_char *)((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1803 | if (! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT)) |
| 1804 | { |
| 1805 | for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa; |
| 1806 | lsa = ospf6_lsdb_next (lsa)) |
| 1807 | { |
| 1808 | ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay); |
| 1809 | |
| 1810 | /* MTU check */ |
| 1811 | if (p - sendbuf + sizeof (struct ospf6_lsa_header) > |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 1812 | ospf6_packet_max(on->ospf6_if)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1813 | { |
| 1814 | ospf6_lsa_unlock (lsa); |
| 1815 | break; |
| 1816 | } |
| 1817 | memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header)); |
| 1818 | p += sizeof (struct ospf6_lsa_header); |
| 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | oh->type = OSPF6_MESSAGE_TYPE_DBDESC; |
| 1823 | oh->length = htons (p - sendbuf); |
| 1824 | |
| 1825 | ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr, |
| 1826 | on->ospf6_if, oh); |
| 1827 | return 0; |
| 1828 | } |
| 1829 | |
| 1830 | int |
| 1831 | ospf6_dbdesc_send_newone (struct thread *thread) |
| 1832 | { |
| 1833 | struct ospf6_neighbor *on; |
| 1834 | struct ospf6_lsa *lsa; |
| 1835 | unsigned int size = 0; |
| 1836 | |
| 1837 | on = (struct ospf6_neighbor *) THREAD_ARG (thread); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1838 | ospf6_lsdb_remove_all (on->dbdesc_list); |
| 1839 | |
| 1840 | /* move LSAs from summary_list to dbdesc_list (within neighbor structure) |
| 1841 | so that ospf6_send_dbdesc () can send those LSAs */ |
| 1842 | size = sizeof (struct ospf6_lsa_header) + sizeof (struct ospf6_dbdesc); |
| 1843 | for (lsa = ospf6_lsdb_head (on->summary_list); lsa; |
| 1844 | lsa = ospf6_lsdb_next (lsa)) |
| 1845 | { |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 1846 | if (size + sizeof (struct ospf6_lsa_header) > ospf6_packet_max(on->ospf6_if)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1847 | { |
| 1848 | ospf6_lsa_unlock (lsa); |
| 1849 | break; |
| 1850 | } |
| 1851 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1852 | ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->dbdesc_list); |
| 1853 | ospf6_lsdb_remove (lsa, on->summary_list); |
| 1854 | size += sizeof (struct ospf6_lsa_header); |
| 1855 | } |
| 1856 | |
| 1857 | if (on->summary_list->count == 0) |
| 1858 | UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT); |
| 1859 | |
| 1860 | /* If slave, More bit check must be done here */ |
| 1861 | if (! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) && /* Slave */ |
| 1862 | ! CHECK_FLAG (on->dbdesc_last.bits, OSPF6_DBDESC_MBIT) && |
| 1863 | ! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT)) |
| 1864 | thread_add_event (master, exchange_done, on, 0); |
| 1865 | |
| 1866 | thread_execute (master, ospf6_dbdesc_send, on, 0); |
| 1867 | return 0; |
| 1868 | } |
| 1869 | |
| 1870 | int |
| 1871 | ospf6_lsreq_send (struct thread *thread) |
| 1872 | { |
| 1873 | struct ospf6_neighbor *on; |
| 1874 | struct ospf6_header *oh; |
| 1875 | struct ospf6_lsreq_entry *e; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1876 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1877 | struct ospf6_lsa *lsa; |
| 1878 | |
| 1879 | on = (struct ospf6_neighbor *) THREAD_ARG (thread); |
| 1880 | on->thread_send_lsreq = (struct thread *) NULL; |
| 1881 | |
| 1882 | /* LSReq will be sent only in ExStart or Loading */ |
| 1883 | if (on->state != OSPF6_NEIGHBOR_EXCHANGE && |
| 1884 | on->state != OSPF6_NEIGHBOR_LOADING) |
| 1885 | { |
| 1886 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSREQ, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1887 | zlog_debug ("Quit to send LSReq to neighbor %s state %s", |
| 1888 | on->name, ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1889 | return 0; |
| 1890 | } |
| 1891 | |
| 1892 | /* schedule loading_done if request list is empty */ |
| 1893 | if (on->request_list->count == 0) |
| 1894 | { |
| 1895 | thread_add_event (master, loading_done, on, 0); |
| 1896 | return 0; |
| 1897 | } |
| 1898 | |
| 1899 | /* set next thread */ |
| 1900 | on->thread_send_lsreq = |
| 1901 | thread_add_timer (master, ospf6_lsreq_send, on, |
| 1902 | on->ospf6_if->rxmt_interval); |
| 1903 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1904 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1905 | oh = (struct ospf6_header *) sendbuf; |
| 1906 | |
| 1907 | /* set Request entries in lsreq */ |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1908 | p = (u_char *)((caddr_t) oh + sizeof (struct ospf6_header)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1909 | for (lsa = ospf6_lsdb_head (on->request_list); lsa; |
| 1910 | lsa = ospf6_lsdb_next (lsa)) |
| 1911 | { |
| 1912 | /* MTU check */ |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 1913 | if (p - sendbuf + sizeof (struct ospf6_lsreq_entry) > ospf6_packet_max(on->ospf6_if)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1914 | { |
| 1915 | ospf6_lsa_unlock (lsa); |
| 1916 | break; |
| 1917 | } |
| 1918 | |
| 1919 | e = (struct ospf6_lsreq_entry *) p; |
| 1920 | e->type = lsa->header->type; |
| 1921 | e->id = lsa->header->id; |
| 1922 | e->adv_router = lsa->header->adv_router; |
| 1923 | p += sizeof (struct ospf6_lsreq_entry); |
| 1924 | } |
| 1925 | |
| 1926 | oh->type = OSPF6_MESSAGE_TYPE_LSREQ; |
| 1927 | oh->length = htons (p - sendbuf); |
| 1928 | |
| 1929 | ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr, |
| 1930 | on->ospf6_if, oh); |
| 1931 | return 0; |
| 1932 | } |
| 1933 | |
| 1934 | int |
| 1935 | ospf6_lsupdate_send_neighbor (struct thread *thread) |
| 1936 | { |
| 1937 | struct ospf6_neighbor *on; |
| 1938 | struct ospf6_header *oh; |
| 1939 | struct ospf6_lsupdate *lsupdate; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1940 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1941 | int num; |
| 1942 | struct ospf6_lsa *lsa; |
| 1943 | |
| 1944 | on = (struct ospf6_neighbor *) THREAD_ARG (thread); |
| 1945 | on->thread_send_lsupdate = (struct thread *) NULL; |
| 1946 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1947 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1948 | zlog_debug ("LSUpdate to neighbor %s", on->name); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1949 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1950 | if (on->state < OSPF6_NEIGHBOR_EXCHANGE) |
| 1951 | { |
| 1952 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1953 | zlog_debug ("Quit to send (neighbor state %s)", |
| 1954 | ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1955 | return 0; |
| 1956 | } |
| 1957 | |
| 1958 | /* if we have nothing to send, return */ |
| 1959 | if (on->lsupdate_list->count == 0 && |
| 1960 | on->retrans_list->count == 0) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1961 | { |
| 1962 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1963 | zlog_debug ("Quit to send (nothing to send)"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1964 | return 0; |
| 1965 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1966 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1967 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1968 | oh = (struct ospf6_header *) sendbuf; |
| 1969 | lsupdate = (struct ospf6_lsupdate *) |
| 1970 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 1971 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1972 | p = (u_char *)((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1973 | num = 0; |
| 1974 | |
| 1975 | /* lsupdate_list lists those LSA which doesn't need to be |
| 1976 | retransmitted. remove those from the list */ |
| 1977 | for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa; |
| 1978 | lsa = ospf6_lsdb_next (lsa)) |
| 1979 | { |
| 1980 | /* MTU check */ |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1981 | if ( (p - sendbuf + (unsigned int)OSPF6_LSA_SIZE (lsa->header)) |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 1982 | > ospf6_packet_max(on->ospf6_if)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1983 | { |
| 1984 | ospf6_lsa_unlock (lsa); |
| 1985 | break; |
| 1986 | } |
| 1987 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1988 | ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay); |
| 1989 | memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header)); |
| 1990 | p += OSPF6_LSA_SIZE (lsa->header); |
| 1991 | num++; |
| 1992 | |
| 1993 | assert (lsa->lock == 2); |
| 1994 | ospf6_lsdb_remove (lsa, on->lsupdate_list); |
| 1995 | } |
| 1996 | |
| 1997 | for (lsa = ospf6_lsdb_head (on->retrans_list); lsa; |
| 1998 | lsa = ospf6_lsdb_next (lsa)) |
| 1999 | { |
| 2000 | /* MTU check */ |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 2001 | if ( (p - sendbuf + (unsigned int)OSPF6_LSA_SIZE (lsa->header)) |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 2002 | > ospf6_packet_max(on->ospf6_if)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2003 | { |
| 2004 | ospf6_lsa_unlock (lsa); |
| 2005 | break; |
| 2006 | } |
| 2007 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2008 | ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay); |
| 2009 | memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header)); |
| 2010 | p += OSPF6_LSA_SIZE (lsa->header); |
| 2011 | num++; |
| 2012 | } |
| 2013 | |
| 2014 | lsupdate->lsa_number = htonl (num); |
| 2015 | |
| 2016 | oh->type = OSPF6_MESSAGE_TYPE_LSUPDATE; |
| 2017 | oh->length = htons (p - sendbuf); |
| 2018 | |
| 2019 | ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr, |
| 2020 | on->ospf6_if, oh); |
| 2021 | |
| 2022 | if (on->lsupdate_list->count != 0 || |
| 2023 | on->retrans_list->count != 0) |
| 2024 | { |
| 2025 | if (on->lsupdate_list->count != 0) |
| 2026 | on->thread_send_lsupdate = |
| 2027 | thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0); |
| 2028 | else |
| 2029 | on->thread_send_lsupdate = |
| 2030 | thread_add_timer (master, ospf6_lsupdate_send_neighbor, on, |
| 2031 | on->ospf6_if->rxmt_interval); |
| 2032 | } |
| 2033 | |
| 2034 | return 0; |
| 2035 | } |
| 2036 | |
| 2037 | int |
| 2038 | ospf6_lsupdate_send_interface (struct thread *thread) |
| 2039 | { |
| 2040 | struct ospf6_interface *oi; |
| 2041 | struct ospf6_header *oh; |
| 2042 | struct ospf6_lsupdate *lsupdate; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 2043 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2044 | int num; |
| 2045 | struct ospf6_lsa *lsa; |
| 2046 | |
| 2047 | oi = (struct ospf6_interface *) THREAD_ARG (thread); |
| 2048 | oi->thread_send_lsupdate = (struct thread *) NULL; |
| 2049 | |
| 2050 | if (oi->state <= OSPF6_INTERFACE_WAITING) |
| 2051 | { |
| 2052 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 2053 | zlog_debug ("Quit to send LSUpdate to interface %s state %s", |
| 2054 | oi->interface->name, ospf6_interface_state_str[oi->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2055 | return 0; |
| 2056 | } |
| 2057 | |
| 2058 | /* if we have nothing to send, return */ |
| 2059 | if (oi->lsupdate_list->count == 0) |
| 2060 | return 0; |
| 2061 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 2062 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2063 | oh = (struct ospf6_header *) sendbuf; |
| 2064 | lsupdate = (struct ospf6_lsupdate *)((caddr_t) oh + |
| 2065 | sizeof (struct ospf6_header)); |
| 2066 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 2067 | p = (u_char *)((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2068 | num = 0; |
| 2069 | |
| 2070 | for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa; |
| 2071 | lsa = ospf6_lsdb_next (lsa)) |
| 2072 | { |
| 2073 | /* MTU check */ |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 2074 | if ( (p - sendbuf + ((unsigned int)OSPF6_LSA_SIZE (lsa->header))) |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 2075 | > ospf6_packet_max(oi)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2076 | { |
| 2077 | ospf6_lsa_unlock (lsa); |
| 2078 | break; |
| 2079 | } |
| 2080 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2081 | ospf6_lsa_age_update_to_send (lsa, oi->transdelay); |
| 2082 | memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header)); |
| 2083 | p += OSPF6_LSA_SIZE (lsa->header); |
| 2084 | num++; |
| 2085 | |
| 2086 | assert (lsa->lock == 2); |
| 2087 | ospf6_lsdb_remove (lsa, oi->lsupdate_list); |
| 2088 | } |
| 2089 | |
| 2090 | lsupdate->lsa_number = htonl (num); |
| 2091 | |
| 2092 | oh->type = OSPF6_MESSAGE_TYPE_LSUPDATE; |
| 2093 | oh->length = htons (p - sendbuf); |
| 2094 | |
| 2095 | if (oi->state == OSPF6_INTERFACE_DR || |
| 2096 | oi->state == OSPF6_INTERFACE_BDR) |
| 2097 | ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh); |
| 2098 | else |
| 2099 | ospf6_send (oi->linklocal_addr, &alldrouters6, oi, oh); |
| 2100 | |
| 2101 | if (oi->lsupdate_list->count > 0) |
| 2102 | { |
| 2103 | oi->thread_send_lsupdate = |
| 2104 | thread_add_event (master, ospf6_lsupdate_send_interface, oi, 0); |
| 2105 | } |
| 2106 | |
| 2107 | return 0; |
| 2108 | } |
| 2109 | |
| 2110 | int |
| 2111 | ospf6_lsack_send_neighbor (struct thread *thread) |
| 2112 | { |
| 2113 | struct ospf6_neighbor *on; |
| 2114 | struct ospf6_header *oh; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 2115 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2116 | struct ospf6_lsa *lsa; |
| 2117 | |
| 2118 | on = (struct ospf6_neighbor *) THREAD_ARG (thread); |
| 2119 | on->thread_send_lsack = (struct thread *) NULL; |
| 2120 | |
| 2121 | if (on->state < OSPF6_NEIGHBOR_EXCHANGE) |
| 2122 | { |
| 2123 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSACK, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 2124 | zlog_debug ("Quit to send LSAck to neighbor %s state %s", |
| 2125 | on->name, ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2126 | return 0; |
| 2127 | } |
| 2128 | |
| 2129 | /* if we have nothing to send, return */ |
| 2130 | if (on->lsack_list->count == 0) |
| 2131 | return 0; |
| 2132 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 2133 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2134 | oh = (struct ospf6_header *) sendbuf; |
| 2135 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 2136 | p = (u_char *)((caddr_t) oh + sizeof (struct ospf6_header)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2137 | |
| 2138 | for (lsa = ospf6_lsdb_head (on->lsack_list); lsa; |
| 2139 | lsa = ospf6_lsdb_next (lsa)) |
| 2140 | { |
| 2141 | /* MTU check */ |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 2142 | if (p - sendbuf + sizeof (struct ospf6_lsa_header) > ospf6_packet_max(on->ospf6_if)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2143 | { |
| 2144 | /* if we run out of packet size/space here, |
| 2145 | better to try again soon. */ |
| 2146 | THREAD_OFF (on->thread_send_lsack); |
| 2147 | on->thread_send_lsack = |
| 2148 | thread_add_event (master, ospf6_lsack_send_neighbor, on, 0); |
| 2149 | |
| 2150 | ospf6_lsa_unlock (lsa); |
| 2151 | break; |
| 2152 | } |
| 2153 | |
| 2154 | ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay); |
| 2155 | memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header)); |
| 2156 | p += sizeof (struct ospf6_lsa_header); |
| 2157 | |
| 2158 | assert (lsa->lock == 2); |
| 2159 | ospf6_lsdb_remove (lsa, on->lsack_list); |
| 2160 | } |
| 2161 | |
| 2162 | oh->type = OSPF6_MESSAGE_TYPE_LSACK; |
| 2163 | oh->length = htons (p - sendbuf); |
| 2164 | |
| 2165 | ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr, |
| 2166 | on->ospf6_if, oh); |
| 2167 | return 0; |
| 2168 | } |
| 2169 | |
| 2170 | int |
| 2171 | ospf6_lsack_send_interface (struct thread *thread) |
| 2172 | { |
| 2173 | struct ospf6_interface *oi; |
| 2174 | struct ospf6_header *oh; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 2175 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2176 | struct ospf6_lsa *lsa; |
| 2177 | |
| 2178 | oi = (struct ospf6_interface *) THREAD_ARG (thread); |
| 2179 | oi->thread_send_lsack = (struct thread *) NULL; |
| 2180 | |
| 2181 | if (oi->state <= OSPF6_INTERFACE_WAITING) |
| 2182 | { |
| 2183 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSACK, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 2184 | zlog_debug ("Quit to send LSAck to interface %s state %s", |
| 2185 | oi->interface->name, ospf6_interface_state_str[oi->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2186 | return 0; |
| 2187 | } |
| 2188 | |
| 2189 | /* if we have nothing to send, return */ |
| 2190 | if (oi->lsack_list->count == 0) |
| 2191 | return 0; |
| 2192 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 2193 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2194 | oh = (struct ospf6_header *) sendbuf; |
| 2195 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 2196 | p = (u_char *)((caddr_t) oh + sizeof (struct ospf6_header)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2197 | |
| 2198 | for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa; |
| 2199 | lsa = ospf6_lsdb_next (lsa)) |
| 2200 | { |
| 2201 | /* MTU check */ |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame] | 2202 | if (p - sendbuf + sizeof (struct ospf6_lsa_header) > ospf6_packet_max(oi)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2203 | { |
| 2204 | /* if we run out of packet size/space here, |
| 2205 | better to try again soon. */ |
| 2206 | THREAD_OFF (oi->thread_send_lsack); |
| 2207 | oi->thread_send_lsack = |
| 2208 | thread_add_event (master, ospf6_lsack_send_interface, oi, 0); |
| 2209 | |
| 2210 | ospf6_lsa_unlock (lsa); |
| 2211 | break; |
| 2212 | } |
| 2213 | |
| 2214 | ospf6_lsa_age_update_to_send (lsa, oi->transdelay); |
| 2215 | memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header)); |
| 2216 | p += sizeof (struct ospf6_lsa_header); |
| 2217 | |
| 2218 | assert (lsa->lock == 2); |
| 2219 | ospf6_lsdb_remove (lsa, oi->lsack_list); |
| 2220 | } |
| 2221 | |
| 2222 | oh->type = OSPF6_MESSAGE_TYPE_LSACK; |
| 2223 | oh->length = htons (p - sendbuf); |
| 2224 | |
| 2225 | if (oi->state == OSPF6_INTERFACE_DR || |
| 2226 | oi->state == OSPF6_INTERFACE_BDR) |
| 2227 | ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh); |
| 2228 | else |
| 2229 | ospf6_send (oi->linklocal_addr, &alldrouters6, oi, oh); |
| 2230 | |
| 2231 | if (oi->thread_send_lsack == NULL && oi->lsack_list->count > 0) |
| 2232 | { |
| 2233 | oi->thread_send_lsack = |
| 2234 | thread_add_event (master, ospf6_lsack_send_interface, oi, 0); |
| 2235 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2236 | |
| 2237 | return 0; |
| 2238 | } |
| 2239 | |
| 2240 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2241 | /* Commands */ |
| 2242 | DEFUN (debug_ospf6_message, |
| 2243 | debug_ospf6_message_cmd, |
| 2244 | "debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all)", |
| 2245 | DEBUG_STR |
| 2246 | OSPF6_STR |
| 2247 | "Debug OSPFv3 message\n" |
| 2248 | "Debug Unknown message\n" |
| 2249 | "Debug Hello message\n" |
| 2250 | "Debug Database Description message\n" |
| 2251 | "Debug Link State Request message\n" |
| 2252 | "Debug Link State Update message\n" |
| 2253 | "Debug Link State Acknowledgement message\n" |
| 2254 | "Debug All message\n" |
| 2255 | ) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2256 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2257 | unsigned char level = 0; |
| 2258 | int type = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2259 | int i; |
| 2260 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2261 | assert (argc > 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2262 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2263 | /* check type */ |
| 2264 | if (! strncmp (argv[0], "u", 1)) |
| 2265 | type = OSPF6_MESSAGE_TYPE_UNKNOWN; |
| 2266 | else if (! strncmp (argv[0], "h", 1)) |
| 2267 | type = OSPF6_MESSAGE_TYPE_HELLO; |
| 2268 | else if (! strncmp (argv[0], "d", 1)) |
| 2269 | type = OSPF6_MESSAGE_TYPE_DBDESC; |
| 2270 | else if (! strncmp (argv[0], "lsr", 3)) |
| 2271 | type = OSPF6_MESSAGE_TYPE_LSREQ; |
| 2272 | else if (! strncmp (argv[0], "lsu", 3)) |
| 2273 | type = OSPF6_MESSAGE_TYPE_LSUPDATE; |
| 2274 | else if (! strncmp (argv[0], "lsa", 3)) |
| 2275 | type = OSPF6_MESSAGE_TYPE_LSACK; |
| 2276 | else if (! strncmp (argv[0], "a", 1)) |
| 2277 | type = OSPF6_MESSAGE_TYPE_ALL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2278 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2279 | if (argc == 1) |
| 2280 | level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV; |
| 2281 | else if (! strncmp (argv[1], "s", 1)) |
| 2282 | level = OSPF6_DEBUG_MESSAGE_SEND; |
| 2283 | else if (! strncmp (argv[1], "r", 1)) |
| 2284 | level = OSPF6_DEBUG_MESSAGE_RECV; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2285 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2286 | if (type == OSPF6_MESSAGE_TYPE_ALL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2287 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2288 | for (i = 0; i < 6; i++) |
| 2289 | OSPF6_DEBUG_MESSAGE_ON (i, level); |
| 2290 | } |
| 2291 | else |
| 2292 | OSPF6_DEBUG_MESSAGE_ON (type, level); |
| 2293 | |
| 2294 | return CMD_SUCCESS; |
| 2295 | } |
| 2296 | |
| 2297 | ALIAS (debug_ospf6_message, |
| 2298 | debug_ospf6_message_sendrecv_cmd, |
| 2299 | "debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all) (send|recv)", |
| 2300 | DEBUG_STR |
| 2301 | OSPF6_STR |
| 2302 | "Debug OSPFv3 message\n" |
| 2303 | "Debug Unknown message\n" |
| 2304 | "Debug Hello message\n" |
| 2305 | "Debug Database Description message\n" |
| 2306 | "Debug Link State Request message\n" |
| 2307 | "Debug Link State Update message\n" |
| 2308 | "Debug Link State Acknowledgement message\n" |
| 2309 | "Debug All message\n" |
| 2310 | "Debug only sending message\n" |
| 2311 | "Debug only receiving message\n" |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 2312 | ) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2313 | |
| 2314 | |
| 2315 | DEFUN (no_debug_ospf6_message, |
| 2316 | no_debug_ospf6_message_cmd, |
| 2317 | "no debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all)", |
| 2318 | NO_STR |
| 2319 | DEBUG_STR |
| 2320 | OSPF6_STR |
| 2321 | "Debug OSPFv3 message\n" |
| 2322 | "Debug Unknown message\n" |
| 2323 | "Debug Hello message\n" |
| 2324 | "Debug Database Description message\n" |
| 2325 | "Debug Link State Request message\n" |
| 2326 | "Debug Link State Update message\n" |
| 2327 | "Debug Link State Acknowledgement message\n" |
| 2328 | "Debug All message\n" |
| 2329 | ) |
| 2330 | { |
| 2331 | unsigned char level = 0; |
| 2332 | int type = 0; |
| 2333 | int i; |
| 2334 | |
| 2335 | assert (argc > 0); |
| 2336 | |
| 2337 | /* check type */ |
| 2338 | if (! strncmp (argv[0], "u", 1)) |
| 2339 | type = OSPF6_MESSAGE_TYPE_UNKNOWN; |
| 2340 | else if (! strncmp (argv[0], "h", 1)) |
| 2341 | type = OSPF6_MESSAGE_TYPE_HELLO; |
| 2342 | else if (! strncmp (argv[0], "d", 1)) |
| 2343 | type = OSPF6_MESSAGE_TYPE_DBDESC; |
| 2344 | else if (! strncmp (argv[0], "lsr", 3)) |
| 2345 | type = OSPF6_MESSAGE_TYPE_LSREQ; |
| 2346 | else if (! strncmp (argv[0], "lsu", 3)) |
| 2347 | type = OSPF6_MESSAGE_TYPE_LSUPDATE; |
| 2348 | else if (! strncmp (argv[0], "lsa", 3)) |
| 2349 | type = OSPF6_MESSAGE_TYPE_LSACK; |
| 2350 | else if (! strncmp (argv[0], "a", 1)) |
| 2351 | type = OSPF6_MESSAGE_TYPE_ALL; |
| 2352 | |
| 2353 | if (argc == 1) |
| 2354 | level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV; |
| 2355 | else if (! strncmp (argv[1], "s", 1)) |
| 2356 | level = OSPF6_DEBUG_MESSAGE_SEND; |
| 2357 | else if (! strncmp (argv[1], "r", 1)) |
| 2358 | level = OSPF6_DEBUG_MESSAGE_RECV; |
| 2359 | |
| 2360 | if (type == OSPF6_MESSAGE_TYPE_ALL) |
| 2361 | { |
| 2362 | for (i = 0; i < 6; i++) |
| 2363 | OSPF6_DEBUG_MESSAGE_OFF (i, level); |
| 2364 | } |
| 2365 | else |
| 2366 | OSPF6_DEBUG_MESSAGE_OFF (type, level); |
| 2367 | |
| 2368 | return CMD_SUCCESS; |
| 2369 | } |
| 2370 | |
| 2371 | ALIAS (no_debug_ospf6_message, |
| 2372 | no_debug_ospf6_message_sendrecv_cmd, |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2373 | "no debug ospf6 message " |
| 2374 | "(unknown|hello|dbdesc|lsreq|lsupdate|lsack|all) (send|recv)", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2375 | NO_STR |
| 2376 | DEBUG_STR |
| 2377 | OSPF6_STR |
| 2378 | "Debug OSPFv3 message\n" |
| 2379 | "Debug Unknown message\n" |
| 2380 | "Debug Hello message\n" |
| 2381 | "Debug Database Description message\n" |
| 2382 | "Debug Link State Request message\n" |
| 2383 | "Debug Link State Update message\n" |
| 2384 | "Debug Link State Acknowledgement message\n" |
| 2385 | "Debug All message\n" |
| 2386 | "Debug only sending message\n" |
| 2387 | "Debug only receiving message\n" |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 2388 | ) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2389 | |
| 2390 | int |
| 2391 | config_write_ospf6_debug_message (struct vty *vty) |
| 2392 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 2393 | const char *type_str[] = {"unknown", "hello", "dbdesc", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2394 | "lsreq", "lsupdate", "lsack"}; |
| 2395 | unsigned char s = 0, r = 0; |
| 2396 | int i; |
| 2397 | |
| 2398 | for (i = 0; i < 6; i++) |
| 2399 | { |
| 2400 | if (IS_OSPF6_DEBUG_MESSAGE (i, SEND)) |
| 2401 | s |= 1 << i; |
| 2402 | if (IS_OSPF6_DEBUG_MESSAGE (i, RECV)) |
| 2403 | r |= 1 << i; |
| 2404 | } |
| 2405 | |
| 2406 | if (s == 0x3f && r == 0x3f) |
| 2407 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2408 | vty_out (vty, "debug ospf6 message all%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2409 | return 0; |
| 2410 | } |
| 2411 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2412 | if (s == 0x3f && r == 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2413 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2414 | vty_out (vty, "debug ospf6 message all send%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2415 | return 0; |
| 2416 | } |
| 2417 | else if (s == 0 && r == 0x3f) |
| 2418 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2419 | vty_out (vty, "debug ospf6 message all recv%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2420 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2421 | } |
| 2422 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2423 | /* Unknown message is logged by default */ |
| 2424 | if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, SEND) && |
| 2425 | ! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2426 | vty_out (vty, "no debug ospf6 message unknown%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2427 | else if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, SEND)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2428 | vty_out (vty, "no debug ospf6 message unknown send%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2429 | else if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2430 | vty_out (vty, "no debug ospf6 message unknown recv%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2431 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2432 | for (i = 1; i < 6; i++) |
| 2433 | { |
| 2434 | if (IS_OSPF6_DEBUG_MESSAGE (i, SEND) && |
| 2435 | IS_OSPF6_DEBUG_MESSAGE (i, RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2436 | vty_out (vty, "debug ospf6 message %s%s", type_str[i], VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2437 | else if (IS_OSPF6_DEBUG_MESSAGE (i, SEND)) |
| 2438 | vty_out (vty, "debug ospf6 message %s send%s", type_str[i], |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2439 | VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2440 | else if (IS_OSPF6_DEBUG_MESSAGE (i, RECV)) |
| 2441 | vty_out (vty, "debug ospf6 message %s recv%s", type_str[i], |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2442 | VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2443 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2444 | |
| 2445 | return 0; |
| 2446 | } |
| 2447 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2448 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 2449 | install_element_ospf6_debug_message (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2450 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2451 | install_element (ENABLE_NODE, &debug_ospf6_message_cmd); |
| 2452 | install_element (ENABLE_NODE, &no_debug_ospf6_message_cmd); |
| 2453 | install_element (ENABLE_NODE, &debug_ospf6_message_sendrecv_cmd); |
| 2454 | install_element (ENABLE_NODE, &no_debug_ospf6_message_sendrecv_cmd); |
| 2455 | install_element (CONFIG_NODE, &debug_ospf6_message_cmd); |
| 2456 | install_element (CONFIG_NODE, &no_debug_ospf6_message_cmd); |
| 2457 | install_element (CONFIG_NODE, &debug_ospf6_message_sendrecv_cmd); |
| 2458 | install_element (CONFIG_NODE, &no_debug_ospf6_message_sendrecv_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2459 | } |
| 2460 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2461 | |