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 | |
| 42 | #include "ospf6_flood.h" |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 43 | #include "ospf6d.h" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 44 | |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 45 | #include <netinet/ip6.h> |
| 46 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 47 | unsigned char conf_debug_ospf6_message[6] = {0x03, 0, 0, 0, 0, 0}; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 48 | const char *ospf6_message_type_str[] = |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 49 | { "Unknown", "Hello", "DbDesc", "LSReq", "LSUpdate", "LSAck" }; |
| 50 | |
| 51 | /* print functions */ |
| 52 | |
| 53 | static void |
| 54 | ospf6_header_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 55 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 56 | char router_id[16], area_id[16]; |
| 57 | inet_ntop (AF_INET, &oh->router_id, router_id, sizeof (router_id)); |
| 58 | inet_ntop (AF_INET, &oh->area_id, area_id, sizeof (area_id)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 59 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 60 | zlog_debug (" OSPFv%d Type:%d Len:%hu Router-ID:%s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 61 | oh->version, oh->type, ntohs (oh->length), router_id); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 62 | zlog_debug (" Area-ID:%s Cksum:%hx Instance-ID:%d", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 63 | area_id, ntohs (oh->checksum), oh->instance_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 64 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | |
| 66 | void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 67 | ospf6_hello_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 68 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 69 | struct ospf6_hello *hello; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 70 | char options[16]; |
| 71 | char drouter[16], bdrouter[16], neighbor[16]; |
| 72 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 73 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 74 | ospf6_header_print (oh); |
| 75 | assert (oh->type == OSPF6_MESSAGE_TYPE_HELLO); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 76 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 77 | hello = (struct ospf6_hello *) |
| 78 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 79 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 80 | inet_ntop (AF_INET, &hello->drouter, drouter, sizeof (drouter)); |
| 81 | inet_ntop (AF_INET, &hello->bdrouter, bdrouter, sizeof (bdrouter)); |
| 82 | ospf6_options_printbuf (hello->options, options, sizeof (options)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 83 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 84 | zlog_debug (" I/F-Id:%ld Priority:%d Option:%s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 85 | (u_long) ntohl (hello->interface_id), hello->priority, options); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 86 | zlog_debug (" HelloInterval:%hu DeadInterval:%hu", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 87 | ntohs (hello->hello_interval), ntohs (hello->dead_interval)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 88 | zlog_debug (" DR:%s BDR:%s", drouter, bdrouter); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 89 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 90 | for (p = (char *) ((caddr_t) hello + sizeof (struct ospf6_hello)); |
| 91 | p + sizeof (u_int32_t) <= OSPF6_MESSAGE_END (oh); |
| 92 | p += sizeof (u_int32_t)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 93 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 94 | inet_ntop (AF_INET, (void *) p, neighbor, sizeof (neighbor)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 95 | zlog_debug (" Neighbor: %s", neighbor); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 96 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 97 | |
| 98 | if (p != OSPF6_MESSAGE_END (oh)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 99 | zlog_debug ("Trailing garbage exists"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 100 | } |
| 101 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 102 | void |
| 103 | ospf6_dbdesc_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 104 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 105 | struct ospf6_dbdesc *dbdesc; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 106 | char options[16]; |
| 107 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 108 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 109 | ospf6_header_print (oh); |
| 110 | assert (oh->type == OSPF6_MESSAGE_TYPE_DBDESC); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 111 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 112 | dbdesc = (struct ospf6_dbdesc *) |
| 113 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 114 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 115 | ospf6_options_printbuf (dbdesc->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 (" MBZ: %#x Option: %s IfMTU: %hu", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 118 | dbdesc->reserved1, options, ntohs (dbdesc->ifmtu)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 119 | zlog_debug (" MBZ: %#x Bits: %s%s%s SeqNum: %#lx", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 120 | dbdesc->reserved2, |
| 121 | (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) ? "I" : "-"), |
| 122 | (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) ? "M" : "-"), |
| 123 | (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) ? "m" : "s"), |
| 124 | (u_long) ntohl (dbdesc->seqnum)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 125 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 126 | for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc)); |
| 127 | p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh); |
| 128 | p += sizeof (struct ospf6_lsa_header)) |
| 129 | ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p); |
| 130 | |
| 131 | if (p != OSPF6_MESSAGE_END (oh)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 132 | zlog_debug ("Trailing garbage exists"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 133 | } |
| 134 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 135 | void |
| 136 | ospf6_lsreq_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 137 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 138 | char id[16], adv_router[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_LSREQ); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 143 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 144 | for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 145 | p + sizeof (struct ospf6_lsreq_entry) <= OSPF6_MESSAGE_END (oh); |
| 146 | p += sizeof (struct ospf6_lsreq_entry)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 147 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 148 | struct ospf6_lsreq_entry *e = (struct ospf6_lsreq_entry *) p; |
| 149 | inet_ntop (AF_INET, &e->adv_router, adv_router, sizeof (adv_router)); |
| 150 | inet_ntop (AF_INET, &e->id, id, sizeof (id)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 151 | zlog_debug (" [%s Id:%s Adv:%s]", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 152 | ospf6_lstype_name (e->type), id, adv_router); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 153 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 154 | |
| 155 | if (p != OSPF6_MESSAGE_END (oh)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 156 | zlog_debug ("Trailing garbage exists"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 157 | } |
| 158 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 159 | void |
| 160 | ospf6_lsupdate_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 161 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 162 | struct ospf6_lsupdate *lsupdate; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 163 | u_long num; |
| 164 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 165 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 166 | ospf6_header_print (oh); |
| 167 | assert (oh->type == OSPF6_MESSAGE_TYPE_LSUPDATE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 168 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 169 | lsupdate = (struct ospf6_lsupdate *) |
| 170 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 171 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 172 | num = ntohl (lsupdate->lsa_number); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 173 | zlog_debug (" Number of LSA: %ld", num); |
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) lsupdate + sizeof (struct ospf6_lsupdate)); |
| 176 | p < OSPF6_MESSAGE_END (oh) && |
| 177 | p + OSPF6_LSA_SIZE (p) <= OSPF6_MESSAGE_END (oh); |
| 178 | p += OSPF6_LSA_SIZE (p)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 179 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 180 | ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p); |
| 181 | if (OSPF6_LSA_SIZE (p) < sizeof (struct ospf6_lsa_header)) |
| 182 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 183 | zlog_debug (" Malformed LSA length, quit printing"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 184 | break; |
| 185 | } |
| 186 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 187 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 188 | if (p != OSPF6_MESSAGE_END (oh)) |
| 189 | { |
| 190 | char buf[32]; |
| 191 | |
| 192 | int num = 0; |
| 193 | memset (buf, 0, sizeof (buf)); |
| 194 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 195 | zlog_debug (" Trailing garbage exists"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 196 | while (p < OSPF6_MESSAGE_END (oh)) |
| 197 | { |
| 198 | snprintf (buf, sizeof (buf), "%s %2x", buf, *p++); |
| 199 | num++; |
| 200 | if (num == 8) |
| 201 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 202 | zlog_debug (" %s", buf); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 203 | memset (buf, 0, sizeof (buf)); |
| 204 | num = 0; |
| 205 | } |
| 206 | } |
| 207 | if (num) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 208 | zlog_debug (" %s", buf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 212 | void |
| 213 | ospf6_lsack_print (struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 214 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 215 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 216 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 217 | ospf6_header_print (oh); |
| 218 | assert (oh->type == OSPF6_MESSAGE_TYPE_LSACK); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 219 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 220 | for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 221 | p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh); |
| 222 | p += sizeof (struct ospf6_lsa_header)) |
| 223 | ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p); |
| 224 | |
| 225 | if (p != OSPF6_MESSAGE_END (oh)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 226 | zlog_debug ("Trailing garbage exists"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 227 | } |
| 228 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 229 | /* Receive function */ |
| 230 | #define MSG_OK 0 |
| 231 | #define MSG_NG 1 |
| 232 | static int |
| 233 | ospf6_header_examin (struct in6_addr *src, struct in6_addr *dst, |
| 234 | struct ospf6_interface *oi, struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 235 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 236 | u_char type; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 237 | type = OSPF6_MESSAGE_TYPE_CANONICAL (oh->type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 238 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 239 | /* version check */ |
| 240 | if (oh->version != OSPFV3_VERSION) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 241 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 242 | if (IS_OSPF6_DEBUG_MESSAGE (type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 243 | zlog_debug ("Message with unknown version"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 244 | return MSG_NG; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 245 | } |
| 246 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 247 | /* Area-ID check */ |
| 248 | if (oh->area_id != oi->area->area_id) |
| 249 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 250 | if (oh->area_id == BACKBONE_AREA_ID) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 251 | { |
| 252 | if (IS_OSPF6_DEBUG_MESSAGE (type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 253 | zlog_debug ("Message may be via Virtual Link: not supported"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 254 | return MSG_NG; |
| 255 | } |
| 256 | |
| 257 | if (IS_OSPF6_DEBUG_MESSAGE (type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 258 | zlog_debug ("Area-ID mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 259 | return MSG_NG; |
| 260 | } |
| 261 | |
| 262 | /* Instance-ID check */ |
| 263 | if (oh->instance_id != oi->instance_id) |
| 264 | { |
| 265 | if (IS_OSPF6_DEBUG_MESSAGE (type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 266 | zlog_debug ("Instance-ID mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 267 | return MSG_NG; |
| 268 | } |
| 269 | |
| 270 | /* Router-ID check */ |
| 271 | if (oh->router_id == oi->area->ospf6->router_id) |
| 272 | zlog_warn ("Detect duplicate Router-ID"); |
| 273 | |
| 274 | return MSG_OK; |
| 275 | } |
| 276 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 277 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 278 | ospf6_hello_recv (struct in6_addr *src, struct in6_addr *dst, |
| 279 | struct ospf6_interface *oi, struct ospf6_header *oh) |
| 280 | { |
| 281 | struct ospf6_hello *hello; |
| 282 | struct ospf6_neighbor *on; |
| 283 | char *p; |
| 284 | int twoway = 0; |
| 285 | int neighborchange = 0; |
| 286 | int backupseen = 0; |
| 287 | |
| 288 | if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK) |
| 289 | return; |
| 290 | |
| 291 | hello = (struct ospf6_hello *) |
| 292 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 293 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 294 | /* HelloInterval check */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 295 | if (ntohs (hello->hello_interval) != oi->hello_interval) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 296 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 297 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 298 | zlog_debug ("HelloInterval mismatch"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 299 | return; |
| 300 | } |
| 301 | |
| 302 | /* RouterDeadInterval check */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 303 | if (ntohs (hello->dead_interval) != oi->dead_interval) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 304 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 305 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 306 | zlog_debug ("RouterDeadInterval mismatch"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 307 | return; |
| 308 | } |
| 309 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 310 | /* E-bit check */ |
| 311 | if (OSPF6_OPT_ISSET (hello->options, OSPF6_OPT_E) != |
| 312 | OSPF6_OPT_ISSET (oi->area->options, OSPF6_OPT_E)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 313 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 314 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 315 | zlog_debug ("E-bit mismatch"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 316 | return; |
| 317 | } |
| 318 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 319 | /* Find neighbor, create if not exist */ |
| 320 | on = ospf6_neighbor_lookup (oh->router_id, oi); |
| 321 | if (on == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 322 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 323 | on = ospf6_neighbor_create (oh->router_id, oi); |
| 324 | on->prev_drouter = on->drouter = hello->drouter; |
| 325 | on->prev_bdrouter = on->bdrouter = hello->bdrouter; |
| 326 | on->priority = hello->priority; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 327 | } |
| 328 | |
hasso | 7b6ae02 | 2005-06-24 08:17:51 +0000 | [diff] [blame] | 329 | /* always override neighbor's source address and ifindex */ |
| 330 | on->ifindex = ntohl (hello->interface_id); |
| 331 | memcpy (&on->linklocal_addr, src, sizeof (struct in6_addr)); |
| 332 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 333 | /* TwoWay check */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 334 | for (p = (char *) ((caddr_t) hello + sizeof (struct ospf6_hello)); |
| 335 | p + sizeof (u_int32_t) <= OSPF6_MESSAGE_END (oh); |
| 336 | p += sizeof (u_int32_t)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 337 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 338 | u_int32_t *router_id = (u_int32_t *) p; |
| 339 | |
| 340 | if (*router_id == oi->area->ospf6->router_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 341 | twoway++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 342 | } |
| 343 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 344 | if (p != OSPF6_MESSAGE_END (oh)) |
| 345 | { |
| 346 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 347 | zlog_debug ("Trailing garbage ignored"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* RouterPriority check */ |
| 351 | if (on->priority != hello->priority) |
| 352 | { |
| 353 | on->priority = hello->priority; |
| 354 | neighborchange++; |
| 355 | } |
| 356 | |
| 357 | /* DR check */ |
| 358 | if (on->drouter != hello->drouter) |
| 359 | { |
| 360 | on->prev_drouter = on->drouter; |
| 361 | on->drouter = hello->drouter; |
| 362 | if (on->prev_drouter == on->router_id || on->drouter == on->router_id) |
| 363 | neighborchange++; |
| 364 | } |
| 365 | |
| 366 | /* BDR check */ |
| 367 | if (on->bdrouter != hello->bdrouter) |
| 368 | { |
| 369 | on->prev_bdrouter = on->bdrouter; |
| 370 | on->bdrouter = hello->bdrouter; |
| 371 | if (on->prev_bdrouter == on->router_id || on->bdrouter == on->router_id) |
| 372 | neighborchange++; |
| 373 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 374 | |
| 375 | /* BackupSeen check */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 376 | if (oi->state == OSPF6_INTERFACE_WAITING) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 377 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 378 | if (hello->bdrouter == on->router_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 379 | backupseen++; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 380 | else if (hello->drouter == on->router_id && hello->bdrouter == htonl (0)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 381 | backupseen++; |
| 382 | } |
| 383 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 384 | /* Execute neighbor events */ |
| 385 | thread_execute (master, hello_received, on, 0); |
| 386 | if (twoway) |
| 387 | thread_execute (master, twoway_received, on, 0); |
| 388 | else |
| 389 | thread_execute (master, oneway_received, on, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 390 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 391 | /* Schedule interface events */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 392 | if (backupseen) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 393 | thread_add_event (master, backup_seen, oi, 0); |
| 394 | if (neighborchange) |
| 395 | thread_add_event (master, neighbor_change, oi, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 396 | } |
| 397 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 398 | static void |
| 399 | ospf6_dbdesc_recv_master (struct ospf6_header *oh, |
| 400 | struct ospf6_neighbor *on) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 401 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 402 | struct ospf6_dbdesc *dbdesc; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 403 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 404 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 405 | dbdesc = (struct ospf6_dbdesc *) |
| 406 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 407 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 408 | if (on->state < OSPF6_NEIGHBOR_INIT) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 409 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 410 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 411 | zlog_debug ("Neighbor state less than Init, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 412 | return; |
| 413 | } |
| 414 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 415 | switch (on->state) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 416 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 417 | case OSPF6_NEIGHBOR_TWOWAY: |
| 418 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 419 | zlog_debug ("Neighbor state is 2-Way, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 420 | return; |
| 421 | |
| 422 | case OSPF6_NEIGHBOR_INIT: |
| 423 | thread_execute (master, twoway_received, on, 0); |
| 424 | if (on->state != OSPF6_NEIGHBOR_EXSTART) |
| 425 | { |
| 426 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 427 | zlog_debug ("Neighbor state is not ExStart, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 428 | return; |
| 429 | } |
| 430 | /* else fall through to ExStart */ |
| 431 | |
| 432 | case OSPF6_NEIGHBOR_EXSTART: |
| 433 | /* if neighbor obeys us as our slave, schedule negotiation_done |
| 434 | and process LSA Headers. Otherwise, ignore this message */ |
| 435 | if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) && |
| 436 | ! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) && |
| 437 | ntohl (dbdesc->seqnum) == on->dbdesc_seqnum) |
| 438 | { |
| 439 | /* execute NegotiationDone */ |
| 440 | thread_execute (master, negotiation_done, on, 0); |
| 441 | |
| 442 | /* Record neighbor options */ |
| 443 | memcpy (on->options, dbdesc->options, sizeof (on->options)); |
| 444 | } |
| 445 | else |
| 446 | { |
| 447 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 448 | zlog_debug ("Negotiation failed"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 449 | return; |
| 450 | } |
| 451 | /* fall through to exchange */ |
| 452 | |
| 453 | case OSPF6_NEIGHBOR_EXCHANGE: |
| 454 | if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc))) |
| 455 | { |
| 456 | /* Duplicated DatabaseDescription is dropped by master */ |
| 457 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 458 | zlog_debug ("Duplicated dbdesc discarded by Master, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 459 | return; |
| 460 | } |
| 461 | |
| 462 | if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT)) |
| 463 | { |
| 464 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 465 | zlog_debug ("Master/Slave bit mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 466 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 467 | return; |
| 468 | } |
| 469 | |
| 470 | if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT)) |
| 471 | { |
| 472 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 473 | zlog_debug ("Initialize bit mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 474 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 475 | return; |
| 476 | } |
| 477 | |
| 478 | if (memcmp (on->options, dbdesc->options, sizeof (on->options))) |
| 479 | { |
| 480 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 481 | zlog_debug ("Option field mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 482 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | if (ntohl (dbdesc->seqnum) != on->dbdesc_seqnum) |
| 487 | { |
| 488 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 489 | zlog_debug ("Sequence number mismatch (%#lx expected)", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 490 | (u_long) on->dbdesc_seqnum); |
| 491 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 492 | return; |
| 493 | } |
| 494 | break; |
| 495 | |
| 496 | case OSPF6_NEIGHBOR_LOADING: |
| 497 | case OSPF6_NEIGHBOR_FULL: |
| 498 | if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc))) |
| 499 | { |
| 500 | /* Duplicated DatabaseDescription is dropped by master */ |
| 501 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 502 | zlog_debug ("Duplicated dbdesc discarded by Master, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 503 | return; |
| 504 | } |
| 505 | |
| 506 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 507 | zlog_debug ("Not duplicate dbdesc in state %s", |
| 508 | ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 509 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 510 | return; |
| 511 | |
| 512 | default: |
| 513 | assert (0); |
| 514 | break; |
| 515 | } |
| 516 | |
| 517 | /* Process LSA headers */ |
| 518 | for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc)); |
| 519 | p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh); |
| 520 | p += sizeof (struct ospf6_lsa_header)) |
| 521 | { |
| 522 | struct ospf6_lsa *his, *mine; |
| 523 | struct ospf6_lsdb *lsdb = NULL; |
| 524 | |
| 525 | his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 526 | |
| 527 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 528 | zlog_debug ("%s", his->name); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 529 | |
| 530 | switch (OSPF6_LSA_SCOPE (his->header->type)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 531 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 532 | case OSPF6_SCOPE_LINKLOCAL: |
| 533 | lsdb = on->ospf6_if->lsdb; |
| 534 | break; |
| 535 | case OSPF6_SCOPE_AREA: |
| 536 | lsdb = on->ospf6_if->area->lsdb; |
| 537 | break; |
| 538 | case OSPF6_SCOPE_AS: |
| 539 | lsdb = on->ospf6_if->area->ospf6->lsdb; |
| 540 | break; |
| 541 | case OSPF6_SCOPE_RESERVED: |
| 542 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 543 | zlog_debug ("Ignoring LSA of reserved scope"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 544 | ospf6_lsa_delete (his); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 545 | continue; |
| 546 | break; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | if (ntohs (his->header->type) == OSPF6_LSTYPE_AS_EXTERNAL && |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 550 | IS_AREA_STUB (on->ospf6_if->area)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 551 | { |
| 552 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 553 | zlog_debug ("SeqNumMismatch (E-bit mismatch), discard"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 554 | ospf6_lsa_delete (his); |
| 555 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 556 | return; |
| 557 | } |
| 558 | |
| 559 | mine = ospf6_lsdb_lookup (his->header->type, his->header->id, |
| 560 | his->header->adv_router, lsdb); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 561 | if (mine == NULL) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 562 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 563 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 564 | zlog_debug ("Add request (No database copy)"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 565 | ospf6_lsdb_add (his, on->request_list); |
| 566 | } |
| 567 | else if (ospf6_lsa_compare (his, mine) < 0) |
| 568 | { |
| 569 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 570 | zlog_debug ("Add request (Received MoreRecent)"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 571 | ospf6_lsdb_add (his, on->request_list); |
| 572 | } |
| 573 | else |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 574 | { |
| 575 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 576 | zlog_debug ("Discard (Existing MoreRecent)"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 577 | ospf6_lsa_delete (his); |
| 578 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | if (p != OSPF6_MESSAGE_END (oh)) |
| 582 | { |
| 583 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 584 | zlog_debug ("Trailing garbage ignored"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* Increment sequence number */ |
| 588 | on->dbdesc_seqnum ++; |
| 589 | |
| 590 | /* schedule send lsreq */ |
| 591 | if (on->thread_send_lsreq == NULL) |
| 592 | on->thread_send_lsreq = |
| 593 | thread_add_event (master, ospf6_lsreq_send, on, 0); |
| 594 | |
| 595 | THREAD_OFF (on->thread_send_dbdesc); |
| 596 | |
| 597 | /* More bit check */ |
| 598 | if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) && |
| 599 | ! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT)) |
| 600 | thread_add_event (master, exchange_done, on, 0); |
| 601 | else |
| 602 | on->thread_send_dbdesc = |
| 603 | thread_add_event (master, ospf6_dbdesc_send_newone, on, 0); |
| 604 | |
| 605 | /* save last received dbdesc */ |
| 606 | memcpy (&on->dbdesc_last, dbdesc, sizeof (struct ospf6_dbdesc)); |
| 607 | } |
| 608 | |
| 609 | static void |
| 610 | ospf6_dbdesc_recv_slave (struct ospf6_header *oh, |
| 611 | struct ospf6_neighbor *on) |
| 612 | { |
| 613 | struct ospf6_dbdesc *dbdesc; |
| 614 | char *p; |
| 615 | |
| 616 | dbdesc = (struct ospf6_dbdesc *) |
| 617 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 618 | |
| 619 | if (on->state < OSPF6_NEIGHBOR_INIT) |
| 620 | { |
| 621 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 622 | zlog_debug ("Neighbor state less than Init, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 623 | return; |
| 624 | } |
| 625 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 626 | switch (on->state) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 627 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 628 | case OSPF6_NEIGHBOR_TWOWAY: |
| 629 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 630 | zlog_debug ("Neighbor state is 2-Way, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 631 | return; |
| 632 | |
| 633 | case OSPF6_NEIGHBOR_INIT: |
| 634 | thread_execute (master, twoway_received, on, 0); |
| 635 | if (on->state != OSPF6_NEIGHBOR_EXSTART) |
| 636 | { |
| 637 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 638 | zlog_debug ("Neighbor state is not ExStart, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 639 | return; |
| 640 | } |
| 641 | /* else fall through to ExStart */ |
| 642 | |
| 643 | case OSPF6_NEIGHBOR_EXSTART: |
| 644 | /* If the neighbor is Master, act as Slave. Schedule negotiation_done |
| 645 | and process LSA Headers. Otherwise, ignore this message */ |
| 646 | if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) && |
| 647 | CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) && |
| 648 | CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) && |
| 649 | ntohs (oh->length) == sizeof (struct ospf6_header) + |
| 650 | sizeof (struct ospf6_dbdesc)) |
| 651 | { |
| 652 | /* set the master/slave bit to slave */ |
| 653 | UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT); |
| 654 | |
| 655 | /* set the DD sequence number to one specified by master */ |
| 656 | on->dbdesc_seqnum = ntohl (dbdesc->seqnum); |
| 657 | |
| 658 | /* schedule NegotiationDone */ |
| 659 | thread_execute (master, negotiation_done, on, 0); |
| 660 | |
| 661 | /* Record neighbor options */ |
| 662 | memcpy (on->options, dbdesc->options, sizeof (on->options)); |
| 663 | } |
| 664 | else |
| 665 | { |
| 666 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 667 | zlog_debug ("Negotiation failed"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 668 | return; |
| 669 | } |
| 670 | break; |
| 671 | |
| 672 | case OSPF6_NEIGHBOR_EXCHANGE: |
| 673 | if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc))) |
| 674 | { |
| 675 | /* Duplicated DatabaseDescription causes slave to retransmit */ |
| 676 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 677 | zlog_debug ("Duplicated dbdesc causes retransmit"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 678 | THREAD_OFF (on->thread_send_dbdesc); |
| 679 | on->thread_send_dbdesc = |
| 680 | thread_add_event (master, ospf6_dbdesc_send, on, 0); |
| 681 | return; |
| 682 | } |
| 683 | |
| 684 | if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT)) |
| 685 | { |
| 686 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 687 | zlog_debug ("Master/Slave bit mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 688 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 689 | return; |
| 690 | } |
| 691 | |
| 692 | if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT)) |
| 693 | { |
| 694 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 695 | zlog_debug ("Initialize bit mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 696 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 697 | return; |
| 698 | } |
| 699 | |
| 700 | if (memcmp (on->options, dbdesc->options, sizeof (on->options))) |
| 701 | { |
| 702 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 703 | zlog_debug ("Option field mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 704 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 705 | return; |
| 706 | } |
| 707 | |
| 708 | if (ntohl (dbdesc->seqnum) != on->dbdesc_seqnum + 1) |
| 709 | { |
| 710 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 711 | zlog_debug ("Sequence number mismatch (%#lx expected)", |
| 712 | (u_long) on->dbdesc_seqnum + 1); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 713 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 714 | return; |
| 715 | } |
| 716 | break; |
| 717 | |
| 718 | case OSPF6_NEIGHBOR_LOADING: |
| 719 | case OSPF6_NEIGHBOR_FULL: |
| 720 | if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc))) |
| 721 | { |
| 722 | /* Duplicated DatabaseDescription causes slave to retransmit */ |
| 723 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 724 | zlog_debug ("Duplicated dbdesc causes retransmit"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 725 | THREAD_OFF (on->thread_send_dbdesc); |
| 726 | on->thread_send_dbdesc = |
| 727 | thread_add_event (master, ospf6_dbdesc_send, on, 0); |
| 728 | return; |
| 729 | } |
| 730 | |
| 731 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 732 | zlog_debug ("Not duplicate dbdesc in state %s", |
| 733 | ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 734 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 735 | return; |
| 736 | |
| 737 | default: |
| 738 | assert (0); |
| 739 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 740 | } |
| 741 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 742 | /* Process LSA headers */ |
| 743 | for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc)); |
| 744 | p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh); |
| 745 | p += sizeof (struct ospf6_lsa_header)) |
| 746 | { |
| 747 | struct ospf6_lsa *his, *mine; |
| 748 | struct ospf6_lsdb *lsdb = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 749 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 750 | his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 751 | |
| 752 | switch (OSPF6_LSA_SCOPE (his->header->type)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 753 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 754 | case OSPF6_SCOPE_LINKLOCAL: |
| 755 | lsdb = on->ospf6_if->lsdb; |
| 756 | break; |
| 757 | case OSPF6_SCOPE_AREA: |
| 758 | lsdb = on->ospf6_if->area->lsdb; |
| 759 | break; |
| 760 | case OSPF6_SCOPE_AS: |
| 761 | lsdb = on->ospf6_if->area->ospf6->lsdb; |
| 762 | break; |
| 763 | case OSPF6_SCOPE_RESERVED: |
| 764 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 765 | zlog_debug ("Ignoring LSA of reserved scope"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 766 | ospf6_lsa_delete (his); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 767 | continue; |
| 768 | break; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 769 | } |
| 770 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 771 | if (OSPF6_LSA_SCOPE (his->header->type) == OSPF6_SCOPE_AS && |
| 772 | IS_AREA_STUB (on->ospf6_if->area)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 773 | { |
| 774 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 775 | zlog_debug ("E-bit mismatch with LSA Headers"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 776 | ospf6_lsa_delete (his); |
| 777 | thread_add_event (master, seqnumber_mismatch, on, 0); |
| 778 | return; |
| 779 | } |
| 780 | |
| 781 | mine = ospf6_lsdb_lookup (his->header->type, his->header->id, |
| 782 | his->header->adv_router, lsdb); |
| 783 | if (mine == NULL || ospf6_lsa_compare (his, mine) < 0) |
| 784 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 785 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 786 | zlog_debug ("Add request-list: %s", his->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 787 | ospf6_lsdb_add (his, on->request_list); |
| 788 | } |
| 789 | else |
| 790 | ospf6_lsa_delete (his); |
| 791 | } |
| 792 | |
| 793 | if (p != OSPF6_MESSAGE_END (oh)) |
| 794 | { |
| 795 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 796 | zlog_debug ("Trailing garbage ignored"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | /* Set sequence number to Master's */ |
| 800 | on->dbdesc_seqnum = ntohl (dbdesc->seqnum); |
| 801 | |
| 802 | /* schedule send lsreq */ |
| 803 | if (on->thread_send_lsreq == NULL) |
| 804 | on->thread_send_lsreq = |
| 805 | thread_add_event (master, ospf6_lsreq_send, on, 0); |
| 806 | |
| 807 | THREAD_OFF (on->thread_send_dbdesc); |
| 808 | on->thread_send_dbdesc = |
| 809 | thread_add_event (master, ospf6_dbdesc_send_newone, on, 0); |
| 810 | |
| 811 | /* save last received dbdesc */ |
| 812 | memcpy (&on->dbdesc_last, dbdesc, sizeof (struct ospf6_dbdesc)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 815 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 816 | ospf6_dbdesc_recv (struct in6_addr *src, struct in6_addr *dst, |
| 817 | struct ospf6_interface *oi, struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 818 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 819 | struct ospf6_neighbor *on; |
| 820 | struct ospf6_dbdesc *dbdesc; |
| 821 | |
| 822 | if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK) |
| 823 | return; |
| 824 | |
| 825 | on = ospf6_neighbor_lookup (oh->router_id, oi); |
| 826 | if (on == NULL) |
| 827 | { |
| 828 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 829 | zlog_debug ("Neighbor not found, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 830 | return; |
| 831 | } |
| 832 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 833 | dbdesc = (struct ospf6_dbdesc *) |
| 834 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 835 | |
| 836 | /* Interface MTU check */ |
Dmitrij Tejblum | ab1be8a | 2011-04-22 19:27:54 +0400 | [diff] [blame] | 837 | if (!oi->mtu_ignore && ntohs (dbdesc->ifmtu) != oi->ifmtu) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 838 | { |
| 839 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 840 | zlog_debug ("I/F MTU mismatch"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 841 | return; |
| 842 | } |
| 843 | |
| 844 | if (dbdesc->reserved1 || dbdesc->reserved2) |
| 845 | { |
| 846 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 847 | zlog_debug ("Non-0 reserved field in %s's DbDesc, correct", |
| 848 | on->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 849 | dbdesc->reserved1 = 0; |
| 850 | dbdesc->reserved2 = 0; |
| 851 | } |
| 852 | |
| 853 | if (ntohl (oh->router_id) < ntohl (ospf6->router_id)) |
| 854 | ospf6_dbdesc_recv_master (oh, on); |
| 855 | else if (ntohl (ospf6->router_id) < ntohl (oh->router_id)) |
| 856 | ospf6_dbdesc_recv_slave (oh, on); |
| 857 | else |
| 858 | { |
| 859 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 860 | zlog_debug ("Can't decide which is master, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 864 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 865 | ospf6_lsreq_recv (struct in6_addr *src, struct in6_addr *dst, |
| 866 | struct ospf6_interface *oi, struct ospf6_header *oh) |
| 867 | { |
| 868 | struct ospf6_neighbor *on; |
| 869 | char *p; |
| 870 | struct ospf6_lsreq_entry *e; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 871 | struct ospf6_lsdb *lsdb = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 872 | struct ospf6_lsa *lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 873 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 874 | if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK) |
| 875 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 876 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 877 | on = ospf6_neighbor_lookup (oh->router_id, oi); |
| 878 | if (on == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 879 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 880 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 881 | zlog_debug ("Neighbor not found, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 882 | return; |
| 883 | } |
| 884 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 885 | if (on->state != OSPF6_NEIGHBOR_EXCHANGE && |
| 886 | on->state != OSPF6_NEIGHBOR_LOADING && |
| 887 | on->state != OSPF6_NEIGHBOR_FULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 888 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 889 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 890 | zlog_debug ("Neighbor state less than Exchange, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 891 | return; |
| 892 | } |
| 893 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 894 | /* Process each request */ |
| 895 | for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 896 | p + sizeof (struct ospf6_lsreq_entry) <= OSPF6_MESSAGE_END (oh); |
| 897 | p += sizeof (struct ospf6_lsreq_entry)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 898 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 899 | e = (struct ospf6_lsreq_entry *) p; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 900 | |
| 901 | switch (OSPF6_LSA_SCOPE (e->type)) |
| 902 | { |
| 903 | case OSPF6_SCOPE_LINKLOCAL: |
| 904 | lsdb = on->ospf6_if->lsdb; |
| 905 | break; |
| 906 | case OSPF6_SCOPE_AREA: |
| 907 | lsdb = on->ospf6_if->area->lsdb; |
| 908 | break; |
| 909 | case OSPF6_SCOPE_AS: |
| 910 | lsdb = on->ospf6_if->area->ospf6->lsdb; |
| 911 | break; |
| 912 | default: |
| 913 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 914 | zlog_debug ("Ignoring LSA of reserved scope"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 915 | continue; |
| 916 | break; |
| 917 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 918 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 919 | /* Find database copy */ |
| 920 | lsa = ospf6_lsdb_lookup (e->type, e->id, e->adv_router, lsdb); |
| 921 | if (lsa == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 922 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 923 | char id[16], adv_router[16]; |
| 924 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
| 925 | { |
| 926 | inet_ntop (AF_INET, &e->id, id, sizeof (id)); |
| 927 | inet_ntop (AF_INET, &e->adv_router, adv_router, |
| 928 | sizeof (adv_router)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 929 | zlog_debug ("Can't find requested [%s Id:%s Adv:%s]", |
| 930 | ospf6_lstype_name (e->type), id, adv_router); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 931 | } |
| 932 | thread_add_event (master, bad_lsreq, on, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 933 | return; |
| 934 | } |
| 935 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 936 | ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->lsupdate_list); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 937 | } |
| 938 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 939 | if (p != OSPF6_MESSAGE_END (oh)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 940 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 941 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 942 | zlog_debug ("Trailing garbage ignored"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 943 | } |
| 944 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 945 | /* schedule send lsupdate */ |
| 946 | THREAD_OFF (on->thread_send_lsupdate); |
| 947 | on->thread_send_lsupdate = |
| 948 | thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 951 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 952 | ospf6_lsupdate_recv (struct in6_addr *src, struct in6_addr *dst, |
| 953 | struct ospf6_interface *oi, struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 954 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 955 | struct ospf6_neighbor *on; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 956 | struct ospf6_lsupdate *lsupdate; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 957 | unsigned long num; |
| 958 | char *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 959 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 960 | if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK) |
| 961 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 962 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 963 | on = ospf6_neighbor_lookup (oh->router_id, oi); |
| 964 | if (on == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 965 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 966 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 967 | zlog_debug ("Neighbor not found, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 968 | return; |
| 969 | } |
| 970 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 971 | if (on->state != OSPF6_NEIGHBOR_EXCHANGE && |
| 972 | on->state != OSPF6_NEIGHBOR_LOADING && |
| 973 | on->state != OSPF6_NEIGHBOR_FULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 974 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 975 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 976 | zlog_debug ("Neighbor state less than Exchange, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 977 | return; |
| 978 | } |
| 979 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 980 | lsupdate = (struct ospf6_lsupdate *) |
| 981 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 982 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 983 | num = ntohl (lsupdate->lsa_number); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 984 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 985 | /* Process LSAs */ |
| 986 | for (p = (char *) ((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate)); |
| 987 | p < OSPF6_MESSAGE_END (oh) && |
| 988 | p + OSPF6_LSA_SIZE (p) <= OSPF6_MESSAGE_END (oh); |
| 989 | p += OSPF6_LSA_SIZE (p)) |
| 990 | { |
| 991 | if (num == 0) |
| 992 | break; |
| 993 | if (OSPF6_LSA_SIZE (p) < sizeof (struct ospf6_lsa_header)) |
| 994 | { |
| 995 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 996 | zlog_debug ("Malformed LSA length, quit processing"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 997 | break; |
| 998 | } |
| 999 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1000 | ospf6_receive_lsa (on, (struct ospf6_lsa_header *) p); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1001 | num--; |
| 1002 | } |
| 1003 | |
| 1004 | if (num != 0) |
| 1005 | { |
| 1006 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1007 | zlog_debug ("Malformed LSA number or LSA length"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1008 | } |
| 1009 | if (p != OSPF6_MESSAGE_END (oh)) |
| 1010 | { |
| 1011 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1012 | zlog_debug ("Trailing garbage ignored"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1013 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1014 | |
| 1015 | /* RFC2328 Section 10.9: When the neighbor responds to these requests |
| 1016 | with the proper Link State Update packet(s), the Link state request |
| 1017 | list is truncated and a new Link State Request packet is sent. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1018 | /* send new Link State Request packet if this LS Update packet |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1019 | can be recognized as a response to our previous LS Request */ |
| 1020 | if (! IN6_IS_ADDR_MULTICAST (dst) && |
| 1021 | (on->state == OSPF6_NEIGHBOR_EXCHANGE || |
| 1022 | on->state == OSPF6_NEIGHBOR_LOADING)) |
| 1023 | { |
| 1024 | THREAD_OFF (on->thread_send_lsreq); |
| 1025 | on->thread_send_lsreq = |
| 1026 | thread_add_event (master, ospf6_lsreq_send, on, 0); |
| 1027 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1030 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1031 | ospf6_lsack_recv (struct in6_addr *src, struct in6_addr *dst, |
| 1032 | struct ospf6_interface *oi, struct ospf6_header *oh) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1033 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1034 | struct ospf6_neighbor *on; |
| 1035 | char *p; |
| 1036 | struct ospf6_lsa *his, *mine; |
| 1037 | struct ospf6_lsdb *lsdb = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1038 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1039 | assert (oh->type == OSPF6_MESSAGE_TYPE_LSACK); |
| 1040 | if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK) |
| 1041 | return; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1042 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1043 | on = ospf6_neighbor_lookup (oh->router_id, oi); |
| 1044 | if (on == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1045 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1046 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1047 | zlog_debug ("Neighbor not found, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1048 | return; |
| 1049 | } |
| 1050 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1051 | if (on->state != OSPF6_NEIGHBOR_EXCHANGE && |
| 1052 | on->state != OSPF6_NEIGHBOR_LOADING && |
| 1053 | on->state != OSPF6_NEIGHBOR_FULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1054 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1055 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1056 | zlog_debug ("Neighbor state less than Exchange, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1057 | return; |
| 1058 | } |
| 1059 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1060 | for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 1061 | p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh); |
| 1062 | p += sizeof (struct ospf6_lsa_header)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1063 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1064 | his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1065 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1066 | switch (OSPF6_LSA_SCOPE (his->header->type)) |
| 1067 | { |
| 1068 | case OSPF6_SCOPE_LINKLOCAL: |
| 1069 | lsdb = on->ospf6_if->lsdb; |
| 1070 | break; |
| 1071 | case OSPF6_SCOPE_AREA: |
| 1072 | lsdb = on->ospf6_if->area->lsdb; |
| 1073 | break; |
| 1074 | case OSPF6_SCOPE_AS: |
| 1075 | lsdb = on->ospf6_if->area->ospf6->lsdb; |
| 1076 | break; |
| 1077 | case OSPF6_SCOPE_RESERVED: |
| 1078 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1079 | zlog_debug ("Ignoring LSA of reserved scope"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1080 | ospf6_lsa_delete (his); |
| 1081 | continue; |
| 1082 | break; |
| 1083 | } |
| 1084 | |
| 1085 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1086 | zlog_debug ("%s acknowledged by %s", his->name, on->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1087 | |
| 1088 | /* Find database copy */ |
| 1089 | mine = ospf6_lsdb_lookup (his->header->type, his->header->id, |
| 1090 | his->header->adv_router, lsdb); |
| 1091 | if (mine == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1092 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1093 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1094 | zlog_debug ("No database copy"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1095 | ospf6_lsa_delete (his); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1096 | continue; |
| 1097 | } |
| 1098 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1099 | /* Check if the LSA is on his retrans-list */ |
| 1100 | mine = ospf6_lsdb_lookup (his->header->type, his->header->id, |
| 1101 | his->header->adv_router, on->retrans_list); |
| 1102 | if (mine == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1103 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1104 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1105 | zlog_debug ("Not on %s's retrans-list", on->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1106 | ospf6_lsa_delete (his); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1107 | continue; |
| 1108 | } |
| 1109 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1110 | if (ospf6_lsa_compare (his, mine) != 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1111 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1112 | /* Log this questionable acknowledgement, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1113 | and examine the next one. */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1114 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1115 | zlog_debug ("Questionable acknowledgement"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1116 | ospf6_lsa_delete (his); |
| 1117 | continue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1120 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1121 | zlog_debug ("Acknowledged, remove from %s's retrans-list", |
| 1122 | on->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1123 | |
Paul Jakma | 932bf19 | 2006-05-15 10:42:24 +0000 | [diff] [blame] | 1124 | ospf6_decrement_retrans_count (mine); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1125 | if (OSPF6_LSA_IS_MAXAGE (mine)) |
| 1126 | ospf6_maxage_remove (on->ospf6_if->area->ospf6); |
Paul Jakma | cf1ce25 | 2006-05-15 10:46:07 +0000 | [diff] [blame] | 1127 | ospf6_lsdb_remove (mine, on->retrans_list); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1128 | ospf6_lsa_delete (his); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1131 | if (p != OSPF6_MESSAGE_END (oh)) |
| 1132 | { |
| 1133 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1134 | zlog_debug ("Trailing garbage ignored"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1135 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1138 | static u_char *recvbuf = NULL; |
| 1139 | static u_char *sendbuf = NULL; |
| 1140 | static unsigned int iobuflen = 0; |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1141 | |
| 1142 | int |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1143 | ospf6_iobuf_size (unsigned int size) |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1144 | { |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1145 | u_char *recvnew, *sendnew; |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1146 | |
| 1147 | if (size <= iobuflen) |
| 1148 | return iobuflen; |
| 1149 | |
| 1150 | recvnew = XMALLOC (MTYPE_OSPF6_MESSAGE, size); |
| 1151 | sendnew = XMALLOC (MTYPE_OSPF6_MESSAGE, size); |
| 1152 | if (recvnew == NULL || sendnew == NULL) |
| 1153 | { |
hasso | b596c71 | 2004-07-09 18:33:43 +0000 | [diff] [blame] | 1154 | if (recvnew) |
| 1155 | XFREE (MTYPE_OSPF6_MESSAGE, recvnew); |
| 1156 | if (sendnew) |
| 1157 | XFREE (MTYPE_OSPF6_MESSAGE, sendnew); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1158 | zlog_debug ("Could not allocate I/O buffer of size %d.", size); |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1159 | return iobuflen; |
| 1160 | } |
| 1161 | |
| 1162 | if (recvbuf) |
| 1163 | XFREE (MTYPE_OSPF6_MESSAGE, recvbuf); |
| 1164 | if (sendbuf) |
| 1165 | XFREE (MTYPE_OSPF6_MESSAGE, sendbuf); |
| 1166 | recvbuf = recvnew; |
| 1167 | sendbuf = sendnew; |
| 1168 | iobuflen = size; |
| 1169 | |
| 1170 | return iobuflen; |
| 1171 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1172 | |
| 1173 | int |
| 1174 | ospf6_receive (struct thread *thread) |
| 1175 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1176 | int sockfd; |
| 1177 | unsigned int len; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1178 | char srcname[64], dstname[64]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1179 | struct in6_addr src, dst; |
| 1180 | unsigned int ifindex; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1181 | struct iovec iovector[2]; |
| 1182 | struct ospf6_interface *oi; |
| 1183 | struct ospf6_header *oh; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1184 | |
| 1185 | /* add next read thread */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1186 | sockfd = THREAD_FD (thread); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1187 | thread_add_read (master, ospf6_receive, NULL, sockfd); |
| 1188 | |
| 1189 | /* initialize */ |
Paul Jakma | cf1ce25 | 2006-05-15 10:46:07 +0000 | [diff] [blame] | 1190 | memset (&src, 0, sizeof (src)); |
| 1191 | memset (&dst, 0, sizeof (dst)); |
| 1192 | ifindex = 0; |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1193 | memset (recvbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1194 | iovector[0].iov_base = recvbuf; |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1195 | iovector[0].iov_len = iobuflen; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1196 | iovector[1].iov_base = NULL; |
| 1197 | iovector[1].iov_len = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1198 | |
| 1199 | /* receive message */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1200 | len = ospf6_recvmsg (&src, &dst, &ifindex, iovector); |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1201 | if (len > iobuflen) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1202 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1203 | zlog_err ("Excess message read"); |
| 1204 | return 0; |
| 1205 | } |
| 1206 | else if (len < sizeof (struct ospf6_header)) |
| 1207 | { |
| 1208 | zlog_err ("Deficient message read"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1209 | return 0; |
| 1210 | } |
| 1211 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1212 | oi = ospf6_interface_lookup_by_ifindex (ifindex); |
| 1213 | if (oi == NULL || oi->area == NULL) |
| 1214 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1215 | zlog_debug ("Message received on disabled interface"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1216 | return 0; |
| 1217 | } |
| 1218 | |
| 1219 | oh = (struct ospf6_header *) recvbuf; |
| 1220 | |
| 1221 | /* Log */ |
| 1222 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
| 1223 | { |
| 1224 | inet_ntop (AF_INET6, &src, srcname, sizeof (srcname)); |
| 1225 | inet_ntop (AF_INET6, &dst, dstname, sizeof (dstname)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1226 | zlog_debug ("%s received on %s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1227 | OSPF6_MESSAGE_TYPE_NAME (oh->type), oi->interface->name); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1228 | zlog_debug (" src: %s", srcname); |
| 1229 | zlog_debug (" dst: %s", dstname); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1230 | if (len != ntohs (oh->length)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1231 | zlog_debug ("Message length does not match actually received: %d", len); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1232 | |
| 1233 | switch (oh->type) |
| 1234 | { |
| 1235 | case OSPF6_MESSAGE_TYPE_HELLO: |
| 1236 | ospf6_hello_print (oh); |
| 1237 | break; |
| 1238 | case OSPF6_MESSAGE_TYPE_DBDESC: |
| 1239 | ospf6_dbdesc_print (oh); |
| 1240 | break; |
| 1241 | case OSPF6_MESSAGE_TYPE_LSREQ: |
| 1242 | ospf6_lsreq_print (oh); |
| 1243 | break; |
| 1244 | case OSPF6_MESSAGE_TYPE_LSUPDATE: |
| 1245 | ospf6_lsupdate_print (oh); |
| 1246 | break; |
| 1247 | case OSPF6_MESSAGE_TYPE_LSACK: |
| 1248 | ospf6_lsack_print (oh); |
| 1249 | break; |
| 1250 | default: |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1251 | zlog_debug ("Unknown message"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1252 | break; |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE)) |
| 1257 | { |
| 1258 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1259 | zlog_debug ("Ignore message on passive interface %s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1260 | oi->interface->name); |
| 1261 | return 0; |
| 1262 | } |
| 1263 | |
| 1264 | switch (oh->type) |
| 1265 | { |
| 1266 | case OSPF6_MESSAGE_TYPE_HELLO: |
| 1267 | ospf6_hello_recv (&src, &dst, oi, oh); |
| 1268 | break; |
| 1269 | |
| 1270 | case OSPF6_MESSAGE_TYPE_DBDESC: |
| 1271 | ospf6_dbdesc_recv (&src, &dst, oi, oh); |
| 1272 | break; |
| 1273 | |
| 1274 | case OSPF6_MESSAGE_TYPE_LSREQ: |
| 1275 | ospf6_lsreq_recv (&src, &dst, oi, oh); |
| 1276 | break; |
| 1277 | |
| 1278 | case OSPF6_MESSAGE_TYPE_LSUPDATE: |
| 1279 | ospf6_lsupdate_recv (&src, &dst, oi, oh); |
| 1280 | break; |
| 1281 | |
| 1282 | case OSPF6_MESSAGE_TYPE_LSACK: |
| 1283 | ospf6_lsack_recv (&src, &dst, oi, oh); |
| 1284 | break; |
| 1285 | |
| 1286 | default: |
| 1287 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1288 | zlog_debug ("Unknown message"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1289 | break; |
| 1290 | } |
| 1291 | |
| 1292 | return 0; |
| 1293 | } |
| 1294 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1295 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1296 | ospf6_send (struct in6_addr *src, struct in6_addr *dst, |
| 1297 | struct ospf6_interface *oi, struct ospf6_header *oh) |
| 1298 | { |
| 1299 | int len; |
| 1300 | char srcname[64], dstname[64]; |
| 1301 | struct iovec iovector[2]; |
| 1302 | |
| 1303 | /* initialize */ |
| 1304 | iovector[0].iov_base = (caddr_t) oh; |
| 1305 | iovector[0].iov_len = ntohs (oh->length); |
| 1306 | iovector[1].iov_base = NULL; |
| 1307 | iovector[1].iov_len = 0; |
| 1308 | |
| 1309 | /* fill OSPF header */ |
| 1310 | oh->version = OSPFV3_VERSION; |
| 1311 | /* message type must be set before */ |
| 1312 | /* message length must be set before */ |
| 1313 | oh->router_id = oi->area->ospf6->router_id; |
| 1314 | oh->area_id = oi->area->area_id; |
| 1315 | /* checksum is calculated by kernel */ |
| 1316 | oh->instance_id = oi->instance_id; |
| 1317 | oh->reserved = 0; |
| 1318 | |
| 1319 | /* Log */ |
| 1320 | if (IS_OSPF6_DEBUG_MESSAGE (oh->type, SEND)) |
| 1321 | { |
| 1322 | inet_ntop (AF_INET6, dst, dstname, sizeof (dstname)); |
| 1323 | if (src) |
| 1324 | inet_ntop (AF_INET6, src, srcname, sizeof (srcname)); |
| 1325 | else |
| 1326 | memset (srcname, 0, sizeof (srcname)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1327 | zlog_debug ("%s send on %s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1328 | OSPF6_MESSAGE_TYPE_NAME (oh->type), oi->interface->name); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1329 | zlog_debug (" src: %s", srcname); |
| 1330 | zlog_debug (" dst: %s", dstname); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1331 | |
| 1332 | switch (oh->type) |
| 1333 | { |
| 1334 | case OSPF6_MESSAGE_TYPE_HELLO: |
| 1335 | ospf6_hello_print (oh); |
| 1336 | break; |
| 1337 | case OSPF6_MESSAGE_TYPE_DBDESC: |
| 1338 | ospf6_dbdesc_print (oh); |
| 1339 | break; |
| 1340 | case OSPF6_MESSAGE_TYPE_LSREQ: |
| 1341 | ospf6_lsreq_print (oh); |
| 1342 | break; |
| 1343 | case OSPF6_MESSAGE_TYPE_LSUPDATE: |
| 1344 | ospf6_lsupdate_print (oh); |
| 1345 | break; |
| 1346 | case OSPF6_MESSAGE_TYPE_LSACK: |
| 1347 | ospf6_lsack_print (oh); |
| 1348 | break; |
| 1349 | default: |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1350 | zlog_debug ("Unknown message"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1351 | assert (0); |
| 1352 | break; |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | /* send message */ |
| 1357 | len = ospf6_sendmsg (src, dst, &oi->interface->ifindex, iovector); |
| 1358 | if (len != ntohs (oh->length)) |
| 1359 | zlog_err ("Could not send entire message"); |
| 1360 | } |
| 1361 | |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 1362 | static int |
| 1363 | ospf6_packet_max(struct ospf6_interface *oi) |
| 1364 | { |
| 1365 | return oi->ifmtu - sizeof(struct ip6_hdr); |
| 1366 | } |
| 1367 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1368 | int |
| 1369 | ospf6_hello_send (struct thread *thread) |
| 1370 | { |
| 1371 | struct ospf6_interface *oi; |
| 1372 | struct ospf6_header *oh; |
| 1373 | struct ospf6_hello *hello; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1374 | u_char *p; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1375 | struct listnode *node, *nnode; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1376 | struct ospf6_neighbor *on; |
| 1377 | |
| 1378 | oi = (struct ospf6_interface *) THREAD_ARG (thread); |
| 1379 | oi->thread_send_hello = (struct thread *) NULL; |
| 1380 | |
| 1381 | if (oi->state <= OSPF6_INTERFACE_DOWN) |
| 1382 | { |
| 1383 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_HELLO, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1384 | zlog_debug ("Unable to send Hello on down interface %s", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1385 | oi->interface->name); |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
| 1389 | /* set next thread */ |
| 1390 | oi->thread_send_hello = thread_add_timer (master, ospf6_hello_send, |
| 1391 | oi, oi->hello_interval); |
| 1392 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1393 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1394 | oh = (struct ospf6_header *) sendbuf; |
| 1395 | hello = (struct ospf6_hello *)((caddr_t) oh + sizeof (struct ospf6_header)); |
| 1396 | |
| 1397 | hello->interface_id = htonl (oi->interface->ifindex); |
| 1398 | hello->priority = oi->priority; |
| 1399 | hello->options[0] = oi->area->options[0]; |
| 1400 | hello->options[1] = oi->area->options[1]; |
| 1401 | hello->options[2] = oi->area->options[2]; |
| 1402 | hello->hello_interval = htons (oi->hello_interval); |
| 1403 | hello->dead_interval = htons (oi->dead_interval); |
| 1404 | hello->drouter = oi->drouter; |
| 1405 | hello->bdrouter = oi->bdrouter; |
| 1406 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1407 | p = (u_char *)((caddr_t) hello + sizeof (struct ospf6_hello)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1408 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1409 | for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1410 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1411 | if (on->state < OSPF6_NEIGHBOR_INIT) |
| 1412 | continue; |
| 1413 | |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 1414 | if (p - sendbuf + sizeof (u_int32_t) > ospf6_packet_max(oi)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1415 | { |
| 1416 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_HELLO, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1417 | zlog_debug ("sending Hello message: exceeds I/F MTU"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1418 | break; |
| 1419 | } |
| 1420 | |
| 1421 | memcpy (p, &on->router_id, sizeof (u_int32_t)); |
| 1422 | p += sizeof (u_int32_t); |
| 1423 | } |
| 1424 | |
| 1425 | oh->type = OSPF6_MESSAGE_TYPE_HELLO; |
| 1426 | oh->length = htons (p - sendbuf); |
| 1427 | |
| 1428 | ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh); |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
| 1432 | int |
| 1433 | ospf6_dbdesc_send (struct thread *thread) |
| 1434 | { |
| 1435 | struct ospf6_neighbor *on; |
| 1436 | struct ospf6_header *oh; |
| 1437 | struct ospf6_dbdesc *dbdesc; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1438 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1439 | struct ospf6_lsa *lsa; |
| 1440 | |
| 1441 | on = (struct ospf6_neighbor *) THREAD_ARG (thread); |
| 1442 | on->thread_send_dbdesc = (struct thread *) NULL; |
| 1443 | |
| 1444 | if (on->state < OSPF6_NEIGHBOR_EXSTART) |
| 1445 | { |
| 1446 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_DBDESC, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1447 | zlog_debug ("Quit to send DbDesc to neighbor %s state %s", |
| 1448 | on->name, ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1449 | return 0; |
| 1450 | } |
| 1451 | |
| 1452 | /* set next thread if master */ |
| 1453 | if (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT)) |
| 1454 | on->thread_send_dbdesc = |
| 1455 | thread_add_timer (master, ospf6_dbdesc_send, on, |
| 1456 | on->ospf6_if->rxmt_interval); |
| 1457 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1458 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1459 | oh = (struct ospf6_header *) sendbuf; |
| 1460 | dbdesc = (struct ospf6_dbdesc *)((caddr_t) oh + |
| 1461 | sizeof (struct ospf6_header)); |
| 1462 | |
| 1463 | /* if this is initial one, initialize sequence number for DbDesc */ |
| 1464 | if (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT)) |
| 1465 | { |
| 1466 | struct timeval tv; |
Takashi Sogabe | 86f72dc | 2009-06-22 13:07:02 +0900 | [diff] [blame] | 1467 | if (quagga_gettime (QUAGGA_CLK_MONOTONIC, &tv) < 0) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1468 | tv.tv_sec = 1; |
| 1469 | on->dbdesc_seqnum = tv.tv_sec; |
| 1470 | } |
| 1471 | |
| 1472 | dbdesc->options[0] = on->ospf6_if->area->options[0]; |
| 1473 | dbdesc->options[1] = on->ospf6_if->area->options[1]; |
| 1474 | dbdesc->options[2] = on->ospf6_if->area->options[2]; |
| 1475 | dbdesc->ifmtu = htons (on->ospf6_if->ifmtu); |
| 1476 | dbdesc->bits = on->dbdesc_bits; |
| 1477 | dbdesc->seqnum = htonl (on->dbdesc_seqnum); |
| 1478 | |
| 1479 | /* if this is not initial one, set LSA headers in dbdesc */ |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1480 | p = (u_char *)((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1481 | if (! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT)) |
| 1482 | { |
| 1483 | for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa; |
| 1484 | lsa = ospf6_lsdb_next (lsa)) |
| 1485 | { |
| 1486 | ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay); |
| 1487 | |
| 1488 | /* MTU check */ |
| 1489 | if (p - sendbuf + sizeof (struct ospf6_lsa_header) > |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 1490 | ospf6_packet_max(on->ospf6_if)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1491 | { |
| 1492 | ospf6_lsa_unlock (lsa); |
| 1493 | break; |
| 1494 | } |
| 1495 | memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header)); |
| 1496 | p += sizeof (struct ospf6_lsa_header); |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | oh->type = OSPF6_MESSAGE_TYPE_DBDESC; |
| 1501 | oh->length = htons (p - sendbuf); |
| 1502 | |
| 1503 | ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr, |
| 1504 | on->ospf6_if, oh); |
| 1505 | return 0; |
| 1506 | } |
| 1507 | |
| 1508 | int |
| 1509 | ospf6_dbdesc_send_newone (struct thread *thread) |
| 1510 | { |
| 1511 | struct ospf6_neighbor *on; |
| 1512 | struct ospf6_lsa *lsa; |
| 1513 | unsigned int size = 0; |
| 1514 | |
| 1515 | on = (struct ospf6_neighbor *) THREAD_ARG (thread); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1516 | ospf6_lsdb_remove_all (on->dbdesc_list); |
| 1517 | |
| 1518 | /* move LSAs from summary_list to dbdesc_list (within neighbor structure) |
| 1519 | so that ospf6_send_dbdesc () can send those LSAs */ |
| 1520 | size = sizeof (struct ospf6_lsa_header) + sizeof (struct ospf6_dbdesc); |
| 1521 | for (lsa = ospf6_lsdb_head (on->summary_list); lsa; |
| 1522 | lsa = ospf6_lsdb_next (lsa)) |
| 1523 | { |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 1524 | if (size + sizeof (struct ospf6_lsa_header) > ospf6_packet_max(on->ospf6_if)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1525 | { |
| 1526 | ospf6_lsa_unlock (lsa); |
| 1527 | break; |
| 1528 | } |
| 1529 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1530 | ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->dbdesc_list); |
| 1531 | ospf6_lsdb_remove (lsa, on->summary_list); |
| 1532 | size += sizeof (struct ospf6_lsa_header); |
| 1533 | } |
| 1534 | |
| 1535 | if (on->summary_list->count == 0) |
| 1536 | UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT); |
| 1537 | |
| 1538 | /* If slave, More bit check must be done here */ |
| 1539 | if (! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) && /* Slave */ |
| 1540 | ! CHECK_FLAG (on->dbdesc_last.bits, OSPF6_DBDESC_MBIT) && |
| 1541 | ! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT)) |
| 1542 | thread_add_event (master, exchange_done, on, 0); |
| 1543 | |
| 1544 | thread_execute (master, ospf6_dbdesc_send, on, 0); |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | int |
| 1549 | ospf6_lsreq_send (struct thread *thread) |
| 1550 | { |
| 1551 | struct ospf6_neighbor *on; |
| 1552 | struct ospf6_header *oh; |
| 1553 | struct ospf6_lsreq_entry *e; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1554 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1555 | struct ospf6_lsa *lsa; |
| 1556 | |
| 1557 | on = (struct ospf6_neighbor *) THREAD_ARG (thread); |
| 1558 | on->thread_send_lsreq = (struct thread *) NULL; |
| 1559 | |
| 1560 | /* LSReq will be sent only in ExStart or Loading */ |
| 1561 | if (on->state != OSPF6_NEIGHBOR_EXCHANGE && |
| 1562 | on->state != OSPF6_NEIGHBOR_LOADING) |
| 1563 | { |
| 1564 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSREQ, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1565 | zlog_debug ("Quit to send LSReq to neighbor %s state %s", |
| 1566 | on->name, ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1567 | return 0; |
| 1568 | } |
| 1569 | |
| 1570 | /* schedule loading_done if request list is empty */ |
| 1571 | if (on->request_list->count == 0) |
| 1572 | { |
| 1573 | thread_add_event (master, loading_done, on, 0); |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
| 1577 | /* set next thread */ |
| 1578 | on->thread_send_lsreq = |
| 1579 | thread_add_timer (master, ospf6_lsreq_send, on, |
| 1580 | on->ospf6_if->rxmt_interval); |
| 1581 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1582 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1583 | oh = (struct ospf6_header *) sendbuf; |
| 1584 | |
| 1585 | /* set Request entries in lsreq */ |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1586 | p = (u_char *)((caddr_t) oh + sizeof (struct ospf6_header)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1587 | for (lsa = ospf6_lsdb_head (on->request_list); lsa; |
| 1588 | lsa = ospf6_lsdb_next (lsa)) |
| 1589 | { |
| 1590 | /* MTU check */ |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 1591 | 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] | 1592 | { |
| 1593 | ospf6_lsa_unlock (lsa); |
| 1594 | break; |
| 1595 | } |
| 1596 | |
| 1597 | e = (struct ospf6_lsreq_entry *) p; |
| 1598 | e->type = lsa->header->type; |
| 1599 | e->id = lsa->header->id; |
| 1600 | e->adv_router = lsa->header->adv_router; |
| 1601 | p += sizeof (struct ospf6_lsreq_entry); |
| 1602 | } |
| 1603 | |
| 1604 | oh->type = OSPF6_MESSAGE_TYPE_LSREQ; |
| 1605 | oh->length = htons (p - sendbuf); |
| 1606 | |
| 1607 | ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr, |
| 1608 | on->ospf6_if, oh); |
| 1609 | return 0; |
| 1610 | } |
| 1611 | |
| 1612 | int |
| 1613 | ospf6_lsupdate_send_neighbor (struct thread *thread) |
| 1614 | { |
| 1615 | struct ospf6_neighbor *on; |
| 1616 | struct ospf6_header *oh; |
| 1617 | struct ospf6_lsupdate *lsupdate; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1618 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1619 | int num; |
| 1620 | struct ospf6_lsa *lsa; |
| 1621 | |
| 1622 | on = (struct ospf6_neighbor *) THREAD_ARG (thread); |
| 1623 | on->thread_send_lsupdate = (struct thread *) NULL; |
| 1624 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1625 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1626 | zlog_debug ("LSUpdate to neighbor %s", on->name); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1627 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1628 | if (on->state < OSPF6_NEIGHBOR_EXCHANGE) |
| 1629 | { |
| 1630 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1631 | zlog_debug ("Quit to send (neighbor state %s)", |
| 1632 | ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1633 | return 0; |
| 1634 | } |
| 1635 | |
| 1636 | /* if we have nothing to send, return */ |
| 1637 | if (on->lsupdate_list->count == 0 && |
| 1638 | on->retrans_list->count == 0) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1639 | { |
| 1640 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1641 | zlog_debug ("Quit to send (nothing to send)"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1642 | return 0; |
| 1643 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1644 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1645 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1646 | oh = (struct ospf6_header *) sendbuf; |
| 1647 | lsupdate = (struct ospf6_lsupdate *) |
| 1648 | ((caddr_t) oh + sizeof (struct ospf6_header)); |
| 1649 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1650 | p = (u_char *)((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1651 | num = 0; |
| 1652 | |
| 1653 | /* lsupdate_list lists those LSA which doesn't need to be |
| 1654 | retransmitted. remove those from the list */ |
| 1655 | for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa; |
| 1656 | lsa = ospf6_lsdb_next (lsa)) |
| 1657 | { |
| 1658 | /* MTU check */ |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1659 | if ( (p - sendbuf + (unsigned int)OSPF6_LSA_SIZE (lsa->header)) |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 1660 | > ospf6_packet_max(on->ospf6_if)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1661 | { |
| 1662 | ospf6_lsa_unlock (lsa); |
| 1663 | break; |
| 1664 | } |
| 1665 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1666 | ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay); |
| 1667 | memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header)); |
| 1668 | p += OSPF6_LSA_SIZE (lsa->header); |
| 1669 | num++; |
| 1670 | |
| 1671 | assert (lsa->lock == 2); |
| 1672 | ospf6_lsdb_remove (lsa, on->lsupdate_list); |
| 1673 | } |
| 1674 | |
| 1675 | for (lsa = ospf6_lsdb_head (on->retrans_list); lsa; |
| 1676 | lsa = ospf6_lsdb_next (lsa)) |
| 1677 | { |
| 1678 | /* MTU check */ |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1679 | if ( (p - sendbuf + (unsigned int)OSPF6_LSA_SIZE (lsa->header)) |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 1680 | > ospf6_packet_max(on->ospf6_if)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1681 | { |
| 1682 | ospf6_lsa_unlock (lsa); |
| 1683 | break; |
| 1684 | } |
| 1685 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1686 | ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay); |
| 1687 | memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header)); |
| 1688 | p += OSPF6_LSA_SIZE (lsa->header); |
| 1689 | num++; |
| 1690 | } |
| 1691 | |
| 1692 | lsupdate->lsa_number = htonl (num); |
| 1693 | |
| 1694 | oh->type = OSPF6_MESSAGE_TYPE_LSUPDATE; |
| 1695 | oh->length = htons (p - sendbuf); |
| 1696 | |
| 1697 | ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr, |
| 1698 | on->ospf6_if, oh); |
| 1699 | |
| 1700 | if (on->lsupdate_list->count != 0 || |
| 1701 | on->retrans_list->count != 0) |
| 1702 | { |
| 1703 | if (on->lsupdate_list->count != 0) |
| 1704 | on->thread_send_lsupdate = |
| 1705 | thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0); |
| 1706 | else |
| 1707 | on->thread_send_lsupdate = |
| 1708 | thread_add_timer (master, ospf6_lsupdate_send_neighbor, on, |
| 1709 | on->ospf6_if->rxmt_interval); |
| 1710 | } |
| 1711 | |
| 1712 | return 0; |
| 1713 | } |
| 1714 | |
| 1715 | int |
| 1716 | ospf6_lsupdate_send_interface (struct thread *thread) |
| 1717 | { |
| 1718 | struct ospf6_interface *oi; |
| 1719 | struct ospf6_header *oh; |
| 1720 | struct ospf6_lsupdate *lsupdate; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1721 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1722 | int num; |
| 1723 | struct ospf6_lsa *lsa; |
| 1724 | |
| 1725 | oi = (struct ospf6_interface *) THREAD_ARG (thread); |
| 1726 | oi->thread_send_lsupdate = (struct thread *) NULL; |
| 1727 | |
| 1728 | if (oi->state <= OSPF6_INTERFACE_WAITING) |
| 1729 | { |
| 1730 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1731 | zlog_debug ("Quit to send LSUpdate to interface %s state %s", |
| 1732 | oi->interface->name, ospf6_interface_state_str[oi->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1733 | return 0; |
| 1734 | } |
| 1735 | |
| 1736 | /* if we have nothing to send, return */ |
| 1737 | if (oi->lsupdate_list->count == 0) |
| 1738 | return 0; |
| 1739 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1740 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1741 | oh = (struct ospf6_header *) sendbuf; |
| 1742 | lsupdate = (struct ospf6_lsupdate *)((caddr_t) oh + |
| 1743 | sizeof (struct ospf6_header)); |
| 1744 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1745 | p = (u_char *)((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1746 | num = 0; |
| 1747 | |
| 1748 | for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa; |
| 1749 | lsa = ospf6_lsdb_next (lsa)) |
| 1750 | { |
| 1751 | /* MTU check */ |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1752 | if ( (p - sendbuf + ((unsigned int)OSPF6_LSA_SIZE (lsa->header))) |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 1753 | > ospf6_packet_max(oi)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1754 | { |
| 1755 | ospf6_lsa_unlock (lsa); |
| 1756 | break; |
| 1757 | } |
| 1758 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1759 | ospf6_lsa_age_update_to_send (lsa, oi->transdelay); |
| 1760 | memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header)); |
| 1761 | p += OSPF6_LSA_SIZE (lsa->header); |
| 1762 | num++; |
| 1763 | |
| 1764 | assert (lsa->lock == 2); |
| 1765 | ospf6_lsdb_remove (lsa, oi->lsupdate_list); |
| 1766 | } |
| 1767 | |
| 1768 | lsupdate->lsa_number = htonl (num); |
| 1769 | |
| 1770 | oh->type = OSPF6_MESSAGE_TYPE_LSUPDATE; |
| 1771 | oh->length = htons (p - sendbuf); |
| 1772 | |
| 1773 | if (oi->state == OSPF6_INTERFACE_DR || |
| 1774 | oi->state == OSPF6_INTERFACE_BDR) |
| 1775 | ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh); |
| 1776 | else |
| 1777 | ospf6_send (oi->linklocal_addr, &alldrouters6, oi, oh); |
| 1778 | |
| 1779 | if (oi->lsupdate_list->count > 0) |
| 1780 | { |
| 1781 | oi->thread_send_lsupdate = |
| 1782 | thread_add_event (master, ospf6_lsupdate_send_interface, oi, 0); |
| 1783 | } |
| 1784 | |
| 1785 | return 0; |
| 1786 | } |
| 1787 | |
| 1788 | int |
| 1789 | ospf6_lsack_send_neighbor (struct thread *thread) |
| 1790 | { |
| 1791 | struct ospf6_neighbor *on; |
| 1792 | struct ospf6_header *oh; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1793 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1794 | struct ospf6_lsa *lsa; |
| 1795 | |
| 1796 | on = (struct ospf6_neighbor *) THREAD_ARG (thread); |
| 1797 | on->thread_send_lsack = (struct thread *) NULL; |
| 1798 | |
| 1799 | if (on->state < OSPF6_NEIGHBOR_EXCHANGE) |
| 1800 | { |
| 1801 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSACK, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1802 | zlog_debug ("Quit to send LSAck to neighbor %s state %s", |
| 1803 | on->name, ospf6_neighbor_state_str[on->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1804 | return 0; |
| 1805 | } |
| 1806 | |
| 1807 | /* if we have nothing to send, return */ |
| 1808 | if (on->lsack_list->count == 0) |
| 1809 | return 0; |
| 1810 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1811 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1812 | oh = (struct ospf6_header *) sendbuf; |
| 1813 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1814 | p = (u_char *)((caddr_t) oh + sizeof (struct ospf6_header)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1815 | |
| 1816 | for (lsa = ospf6_lsdb_head (on->lsack_list); lsa; |
| 1817 | lsa = ospf6_lsdb_next (lsa)) |
| 1818 | { |
| 1819 | /* MTU check */ |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 1820 | 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] | 1821 | { |
| 1822 | /* if we run out of packet size/space here, |
| 1823 | better to try again soon. */ |
| 1824 | THREAD_OFF (on->thread_send_lsack); |
| 1825 | on->thread_send_lsack = |
| 1826 | thread_add_event (master, ospf6_lsack_send_neighbor, on, 0); |
| 1827 | |
| 1828 | ospf6_lsa_unlock (lsa); |
| 1829 | break; |
| 1830 | } |
| 1831 | |
| 1832 | ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay); |
| 1833 | memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header)); |
| 1834 | p += sizeof (struct ospf6_lsa_header); |
| 1835 | |
| 1836 | assert (lsa->lock == 2); |
| 1837 | ospf6_lsdb_remove (lsa, on->lsack_list); |
| 1838 | } |
| 1839 | |
| 1840 | oh->type = OSPF6_MESSAGE_TYPE_LSACK; |
| 1841 | oh->length = htons (p - sendbuf); |
| 1842 | |
| 1843 | ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr, |
| 1844 | on->ospf6_if, oh); |
| 1845 | return 0; |
| 1846 | } |
| 1847 | |
| 1848 | int |
| 1849 | ospf6_lsack_send_interface (struct thread *thread) |
| 1850 | { |
| 1851 | struct ospf6_interface *oi; |
| 1852 | struct ospf6_header *oh; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 1853 | u_char *p; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1854 | struct ospf6_lsa *lsa; |
| 1855 | |
| 1856 | oi = (struct ospf6_interface *) THREAD_ARG (thread); |
| 1857 | oi->thread_send_lsack = (struct thread *) NULL; |
| 1858 | |
| 1859 | if (oi->state <= OSPF6_INTERFACE_WAITING) |
| 1860 | { |
| 1861 | if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSACK, SEND)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1862 | zlog_debug ("Quit to send LSAck to interface %s state %s", |
| 1863 | oi->interface->name, ospf6_interface_state_str[oi->state]); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1864 | return 0; |
| 1865 | } |
| 1866 | |
| 1867 | /* if we have nothing to send, return */ |
| 1868 | if (oi->lsack_list->count == 0) |
| 1869 | return 0; |
| 1870 | |
hasso | 3b4cd3a | 2004-05-18 19:28:32 +0000 | [diff] [blame] | 1871 | memset (sendbuf, 0, iobuflen); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1872 | oh = (struct ospf6_header *) sendbuf; |
| 1873 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1874 | p = (u_char *)((caddr_t) oh + sizeof (struct ospf6_header)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1875 | |
| 1876 | for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa; |
| 1877 | lsa = ospf6_lsdb_next (lsa)) |
| 1878 | { |
| 1879 | /* MTU check */ |
Dmitrij Tejblum | 82a963a | 2011-07-12 17:53:33 +0400 | [diff] [blame^] | 1880 | if (p - sendbuf + sizeof (struct ospf6_lsa_header) > ospf6_packet_max(oi)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1881 | { |
| 1882 | /* if we run out of packet size/space here, |
| 1883 | better to try again soon. */ |
| 1884 | THREAD_OFF (oi->thread_send_lsack); |
| 1885 | oi->thread_send_lsack = |
| 1886 | thread_add_event (master, ospf6_lsack_send_interface, oi, 0); |
| 1887 | |
| 1888 | ospf6_lsa_unlock (lsa); |
| 1889 | break; |
| 1890 | } |
| 1891 | |
| 1892 | ospf6_lsa_age_update_to_send (lsa, oi->transdelay); |
| 1893 | memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header)); |
| 1894 | p += sizeof (struct ospf6_lsa_header); |
| 1895 | |
| 1896 | assert (lsa->lock == 2); |
| 1897 | ospf6_lsdb_remove (lsa, oi->lsack_list); |
| 1898 | } |
| 1899 | |
| 1900 | oh->type = OSPF6_MESSAGE_TYPE_LSACK; |
| 1901 | oh->length = htons (p - sendbuf); |
| 1902 | |
| 1903 | if (oi->state == OSPF6_INTERFACE_DR || |
| 1904 | oi->state == OSPF6_INTERFACE_BDR) |
| 1905 | ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh); |
| 1906 | else |
| 1907 | ospf6_send (oi->linklocal_addr, &alldrouters6, oi, oh); |
| 1908 | |
| 1909 | if (oi->thread_send_lsack == NULL && oi->lsack_list->count > 0) |
| 1910 | { |
| 1911 | oi->thread_send_lsack = |
| 1912 | thread_add_event (master, ospf6_lsack_send_interface, oi, 0); |
| 1913 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1914 | |
| 1915 | return 0; |
| 1916 | } |
| 1917 | |
| 1918 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1919 | /* Commands */ |
| 1920 | DEFUN (debug_ospf6_message, |
| 1921 | debug_ospf6_message_cmd, |
| 1922 | "debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all)", |
| 1923 | DEBUG_STR |
| 1924 | OSPF6_STR |
| 1925 | "Debug OSPFv3 message\n" |
| 1926 | "Debug Unknown message\n" |
| 1927 | "Debug Hello message\n" |
| 1928 | "Debug Database Description message\n" |
| 1929 | "Debug Link State Request message\n" |
| 1930 | "Debug Link State Update message\n" |
| 1931 | "Debug Link State Acknowledgement message\n" |
| 1932 | "Debug All message\n" |
| 1933 | ) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1934 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1935 | unsigned char level = 0; |
| 1936 | int type = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1937 | int i; |
| 1938 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1939 | assert (argc > 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1940 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1941 | /* check type */ |
| 1942 | if (! strncmp (argv[0], "u", 1)) |
| 1943 | type = OSPF6_MESSAGE_TYPE_UNKNOWN; |
| 1944 | else if (! strncmp (argv[0], "h", 1)) |
| 1945 | type = OSPF6_MESSAGE_TYPE_HELLO; |
| 1946 | else if (! strncmp (argv[0], "d", 1)) |
| 1947 | type = OSPF6_MESSAGE_TYPE_DBDESC; |
| 1948 | else if (! strncmp (argv[0], "lsr", 3)) |
| 1949 | type = OSPF6_MESSAGE_TYPE_LSREQ; |
| 1950 | else if (! strncmp (argv[0], "lsu", 3)) |
| 1951 | type = OSPF6_MESSAGE_TYPE_LSUPDATE; |
| 1952 | else if (! strncmp (argv[0], "lsa", 3)) |
| 1953 | type = OSPF6_MESSAGE_TYPE_LSACK; |
| 1954 | else if (! strncmp (argv[0], "a", 1)) |
| 1955 | type = OSPF6_MESSAGE_TYPE_ALL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1956 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1957 | if (argc == 1) |
| 1958 | level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV; |
| 1959 | else if (! strncmp (argv[1], "s", 1)) |
| 1960 | level = OSPF6_DEBUG_MESSAGE_SEND; |
| 1961 | else if (! strncmp (argv[1], "r", 1)) |
| 1962 | level = OSPF6_DEBUG_MESSAGE_RECV; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1963 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1964 | if (type == OSPF6_MESSAGE_TYPE_ALL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1965 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1966 | for (i = 0; i < 6; i++) |
| 1967 | OSPF6_DEBUG_MESSAGE_ON (i, level); |
| 1968 | } |
| 1969 | else |
| 1970 | OSPF6_DEBUG_MESSAGE_ON (type, level); |
| 1971 | |
| 1972 | return CMD_SUCCESS; |
| 1973 | } |
| 1974 | |
| 1975 | ALIAS (debug_ospf6_message, |
| 1976 | debug_ospf6_message_sendrecv_cmd, |
| 1977 | "debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all) (send|recv)", |
| 1978 | DEBUG_STR |
| 1979 | OSPF6_STR |
| 1980 | "Debug OSPFv3 message\n" |
| 1981 | "Debug Unknown message\n" |
| 1982 | "Debug Hello message\n" |
| 1983 | "Debug Database Description message\n" |
| 1984 | "Debug Link State Request message\n" |
| 1985 | "Debug Link State Update message\n" |
| 1986 | "Debug Link State Acknowledgement message\n" |
| 1987 | "Debug All message\n" |
| 1988 | "Debug only sending message\n" |
| 1989 | "Debug only receiving message\n" |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 1990 | ) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1991 | |
| 1992 | |
| 1993 | DEFUN (no_debug_ospf6_message, |
| 1994 | no_debug_ospf6_message_cmd, |
| 1995 | "no debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all)", |
| 1996 | NO_STR |
| 1997 | DEBUG_STR |
| 1998 | OSPF6_STR |
| 1999 | "Debug OSPFv3 message\n" |
| 2000 | "Debug Unknown message\n" |
| 2001 | "Debug Hello message\n" |
| 2002 | "Debug Database Description message\n" |
| 2003 | "Debug Link State Request message\n" |
| 2004 | "Debug Link State Update message\n" |
| 2005 | "Debug Link State Acknowledgement message\n" |
| 2006 | "Debug All message\n" |
| 2007 | ) |
| 2008 | { |
| 2009 | unsigned char level = 0; |
| 2010 | int type = 0; |
| 2011 | int i; |
| 2012 | |
| 2013 | assert (argc > 0); |
| 2014 | |
| 2015 | /* check type */ |
| 2016 | if (! strncmp (argv[0], "u", 1)) |
| 2017 | type = OSPF6_MESSAGE_TYPE_UNKNOWN; |
| 2018 | else if (! strncmp (argv[0], "h", 1)) |
| 2019 | type = OSPF6_MESSAGE_TYPE_HELLO; |
| 2020 | else if (! strncmp (argv[0], "d", 1)) |
| 2021 | type = OSPF6_MESSAGE_TYPE_DBDESC; |
| 2022 | else if (! strncmp (argv[0], "lsr", 3)) |
| 2023 | type = OSPF6_MESSAGE_TYPE_LSREQ; |
| 2024 | else if (! strncmp (argv[0], "lsu", 3)) |
| 2025 | type = OSPF6_MESSAGE_TYPE_LSUPDATE; |
| 2026 | else if (! strncmp (argv[0], "lsa", 3)) |
| 2027 | type = OSPF6_MESSAGE_TYPE_LSACK; |
| 2028 | else if (! strncmp (argv[0], "a", 1)) |
| 2029 | type = OSPF6_MESSAGE_TYPE_ALL; |
| 2030 | |
| 2031 | if (argc == 1) |
| 2032 | level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV; |
| 2033 | else if (! strncmp (argv[1], "s", 1)) |
| 2034 | level = OSPF6_DEBUG_MESSAGE_SEND; |
| 2035 | else if (! strncmp (argv[1], "r", 1)) |
| 2036 | level = OSPF6_DEBUG_MESSAGE_RECV; |
| 2037 | |
| 2038 | if (type == OSPF6_MESSAGE_TYPE_ALL) |
| 2039 | { |
| 2040 | for (i = 0; i < 6; i++) |
| 2041 | OSPF6_DEBUG_MESSAGE_OFF (i, level); |
| 2042 | } |
| 2043 | else |
| 2044 | OSPF6_DEBUG_MESSAGE_OFF (type, level); |
| 2045 | |
| 2046 | return CMD_SUCCESS; |
| 2047 | } |
| 2048 | |
| 2049 | ALIAS (no_debug_ospf6_message, |
| 2050 | no_debug_ospf6_message_sendrecv_cmd, |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2051 | "no debug ospf6 message " |
| 2052 | "(unknown|hello|dbdesc|lsreq|lsupdate|lsack|all) (send|recv)", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2053 | NO_STR |
| 2054 | DEBUG_STR |
| 2055 | OSPF6_STR |
| 2056 | "Debug OSPFv3 message\n" |
| 2057 | "Debug Unknown message\n" |
| 2058 | "Debug Hello message\n" |
| 2059 | "Debug Database Description message\n" |
| 2060 | "Debug Link State Request message\n" |
| 2061 | "Debug Link State Update message\n" |
| 2062 | "Debug Link State Acknowledgement message\n" |
| 2063 | "Debug All message\n" |
| 2064 | "Debug only sending message\n" |
| 2065 | "Debug only receiving message\n" |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 2066 | ) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2067 | |
| 2068 | int |
| 2069 | config_write_ospf6_debug_message (struct vty *vty) |
| 2070 | { |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 2071 | const char *type_str[] = {"unknown", "hello", "dbdesc", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2072 | "lsreq", "lsupdate", "lsack"}; |
| 2073 | unsigned char s = 0, r = 0; |
| 2074 | int i; |
| 2075 | |
| 2076 | for (i = 0; i < 6; i++) |
| 2077 | { |
| 2078 | if (IS_OSPF6_DEBUG_MESSAGE (i, SEND)) |
| 2079 | s |= 1 << i; |
| 2080 | if (IS_OSPF6_DEBUG_MESSAGE (i, RECV)) |
| 2081 | r |= 1 << i; |
| 2082 | } |
| 2083 | |
| 2084 | if (s == 0x3f && r == 0x3f) |
| 2085 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2086 | vty_out (vty, "debug ospf6 message all%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2087 | return 0; |
| 2088 | } |
| 2089 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2090 | if (s == 0x3f && r == 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2091 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2092 | vty_out (vty, "debug ospf6 message all send%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2093 | return 0; |
| 2094 | } |
| 2095 | else if (s == 0 && r == 0x3f) |
| 2096 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2097 | vty_out (vty, "debug ospf6 message all recv%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2098 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2101 | /* Unknown message is logged by default */ |
| 2102 | if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, SEND) && |
| 2103 | ! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2104 | vty_out (vty, "no debug ospf6 message unknown%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2105 | else if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, SEND)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2106 | vty_out (vty, "no debug ospf6 message unknown send%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2107 | else if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2108 | vty_out (vty, "no debug ospf6 message unknown recv%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2109 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2110 | for (i = 1; i < 6; i++) |
| 2111 | { |
| 2112 | if (IS_OSPF6_DEBUG_MESSAGE (i, SEND) && |
| 2113 | IS_OSPF6_DEBUG_MESSAGE (i, RECV)) |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2114 | vty_out (vty, "debug ospf6 message %s%s", type_str[i], VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2115 | else if (IS_OSPF6_DEBUG_MESSAGE (i, SEND)) |
| 2116 | vty_out (vty, "debug ospf6 message %s send%s", type_str[i], |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2117 | VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2118 | else if (IS_OSPF6_DEBUG_MESSAGE (i, RECV)) |
| 2119 | vty_out (vty, "debug ospf6 message %s recv%s", type_str[i], |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 2120 | VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2121 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2122 | |
| 2123 | return 0; |
| 2124 | } |
| 2125 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2126 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 2127 | install_element_ospf6_debug_message (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2128 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2129 | install_element (ENABLE_NODE, &debug_ospf6_message_cmd); |
| 2130 | install_element (ENABLE_NODE, &no_debug_ospf6_message_cmd); |
| 2131 | install_element (ENABLE_NODE, &debug_ospf6_message_sendrecv_cmd); |
| 2132 | install_element (ENABLE_NODE, &no_debug_ospf6_message_sendrecv_cmd); |
| 2133 | install_element (CONFIG_NODE, &debug_ospf6_message_cmd); |
| 2134 | install_element (CONFIG_NODE, &no_debug_ospf6_message_cmd); |
| 2135 | install_element (CONFIG_NODE, &debug_ospf6_message_sendrecv_cmd); |
| 2136 | install_element (CONFIG_NODE, &no_debug_ospf6_message_sendrecv_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2137 | } |
| 2138 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2139 | |