Extended MOTD with GUI
[tomato.git] / release / src / router / zebra / ospf6d / ospf6_message.c
blobbd189f9e3670a4950f2e65a430f304203e648d02
1 /*
2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
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.
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.
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.
22 #include <zebra.h>
24 #include "memory.h"
25 #include "log.h"
26 #include "vty.h"
27 #include "command.h"
28 #include "thread.h"
29 #include "linklist.h"
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"
37 #include "ospf6_top.h"
38 #include "ospf6_area.h"
39 #include "ospf6_neighbor.h"
40 #include "ospf6_interface.h"
42 #include "ospf6_flood.h"
43 #include "ospf6d.h"
45 unsigned char conf_debug_ospf6_message[6] = {0x03, 0, 0, 0, 0, 0};
46 char *ospf6_message_type_str[] =
47 { "Unknown", "Hello", "DbDesc", "LSReq", "LSUpdate", "LSAck" };
49 /* print functions */
51 static void
52 ospf6_header_print (struct ospf6_header *oh)
54 char router_id[16], area_id[16];
55 inet_ntop (AF_INET, &oh->router_id, router_id, sizeof (router_id));
56 inet_ntop (AF_INET, &oh->area_id, area_id, sizeof (area_id));
58 zlog_info (" OSPFv%d Type:%d Len:%hu Router-ID:%s",
59 oh->version, oh->type, ntohs (oh->length), router_id);
60 zlog_info (" Area-ID:%s Cksum:%hx Instance-ID:%d",
61 area_id, ntohs (oh->checksum), oh->instance_id);
64 void
65 ospf6_hello_print (struct ospf6_header *oh)
67 struct ospf6_hello *hello;
68 char options[16];
69 char drouter[16], bdrouter[16], neighbor[16];
70 char *p;
72 ospf6_header_print (oh);
73 assert (oh->type == OSPF6_MESSAGE_TYPE_HELLO);
75 hello = (struct ospf6_hello *)
76 ((caddr_t) oh + sizeof (struct ospf6_header));
78 inet_ntop (AF_INET, &hello->drouter, drouter, sizeof (drouter));
79 inet_ntop (AF_INET, &hello->bdrouter, bdrouter, sizeof (bdrouter));
80 ospf6_options_printbuf (hello->options, options, sizeof (options));
82 zlog_info (" I/F-Id:%ld Priority:%d Option:%s",
83 (u_long) ntohl (hello->interface_id), hello->priority, options);
84 zlog_info (" HelloInterval:%hu DeadInterval:%hu",
85 ntohs (hello->hello_interval), ntohs (hello->dead_interval));
86 zlog_info (" DR:%s BDR:%s", drouter, bdrouter);
88 for (p = (char *) ((caddr_t) hello + sizeof (struct ospf6_hello));
89 p + sizeof (u_int32_t) <= OSPF6_MESSAGE_END (oh);
90 p += sizeof (u_int32_t))
92 inet_ntop (AF_INET, (void *) p, neighbor, sizeof (neighbor));
93 zlog_info (" Neighbor: %s", neighbor);
96 if (p != OSPF6_MESSAGE_END (oh))
97 zlog_info ("Trailing garbage exists");
100 void
101 ospf6_dbdesc_print (struct ospf6_header *oh)
103 struct ospf6_dbdesc *dbdesc;
104 char options[16];
105 char *p;
107 ospf6_header_print (oh);
108 assert (oh->type == OSPF6_MESSAGE_TYPE_DBDESC);
110 dbdesc = (struct ospf6_dbdesc *)
111 ((caddr_t) oh + sizeof (struct ospf6_header));
113 ospf6_options_printbuf (dbdesc->options, options, sizeof (options));
115 zlog_info (" MBZ: %#x Option: %s IfMTU: %hu",
116 dbdesc->reserved1, options, ntohs (dbdesc->ifmtu));
117 zlog_info (" MBZ: %#x Bits: %s%s%s SeqNum: %#lx",
118 dbdesc->reserved2,
119 (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) ? "I" : "-"),
120 (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) ? "M" : "-"),
121 (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) ? "m" : "s"),
122 (u_long) ntohl (dbdesc->seqnum));
124 for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc));
125 p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
126 p += sizeof (struct ospf6_lsa_header))
127 ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p);
129 if (p != OSPF6_MESSAGE_END (oh))
130 zlog_info ("Trailing garbage exists");
133 void
134 ospf6_lsreq_print (struct ospf6_header *oh)
136 char id[16], adv_router[16];
137 char *p;
139 ospf6_header_print (oh);
140 assert (oh->type == OSPF6_MESSAGE_TYPE_LSREQ);
142 for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header));
143 p + sizeof (struct ospf6_lsreq_entry) <= OSPF6_MESSAGE_END (oh);
144 p += sizeof (struct ospf6_lsreq_entry))
146 struct ospf6_lsreq_entry *e = (struct ospf6_lsreq_entry *) p;
147 inet_ntop (AF_INET, &e->adv_router, adv_router, sizeof (adv_router));
148 inet_ntop (AF_INET, &e->id, id, sizeof (id));
149 zlog_info (" [%s Id:%s Adv:%s]",
150 ospf6_lstype_name (e->type), id, adv_router);
153 if (p != OSPF6_MESSAGE_END (oh))
154 zlog_info ("Trailing garbage exists");
157 void
158 ospf6_lsupdate_print (struct ospf6_header *oh)
160 struct ospf6_lsupdate *lsupdate;
161 u_long num;
162 char *p;
164 ospf6_header_print (oh);
165 assert (oh->type == OSPF6_MESSAGE_TYPE_LSUPDATE);
167 lsupdate = (struct ospf6_lsupdate *)
168 ((caddr_t) oh + sizeof (struct ospf6_header));
170 num = ntohl (lsupdate->lsa_number);
171 zlog_info (" Number of LSA: %ld", num);
173 for (p = (char *) ((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
174 p < OSPF6_MESSAGE_END (oh) &&
175 p + OSPF6_LSA_SIZE (p) <= OSPF6_MESSAGE_END (oh);
176 p += OSPF6_LSA_SIZE (p))
178 ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p);
179 if (OSPF6_LSA_SIZE (p) < sizeof (struct ospf6_lsa_header))
181 zlog_info (" Malformed LSA length, quit printing");
182 break;
186 if (p != OSPF6_MESSAGE_END (oh))
188 char buf[32];
190 int num = 0;
191 memset (buf, 0, sizeof (buf));
193 zlog_info (" Trailing garbage exists");
194 while (p < OSPF6_MESSAGE_END (oh))
196 snprintf (buf, sizeof (buf), "%s %2x", buf, *p++);
197 num++;
198 if (num == 8)
200 zlog_info (" %s", buf);
201 memset (buf, 0, sizeof (buf));
202 num = 0;
205 if (num)
206 zlog_info (" %s", buf);
210 void
211 ospf6_lsack_print (struct ospf6_header *oh)
213 char *p;
215 ospf6_header_print (oh);
216 assert (oh->type == OSPF6_MESSAGE_TYPE_LSACK);
218 for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header));
219 p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
220 p += sizeof (struct ospf6_lsa_header))
221 ospf6_lsa_header_print_raw ((struct ospf6_lsa_header *) p);
223 if (p != OSPF6_MESSAGE_END (oh))
224 zlog_info ("Trailing garbage exists");
227 /* Receive function */
228 #define MSG_OK 0
229 #define MSG_NG 1
230 static int
231 ospf6_header_examin (struct in6_addr *src, struct in6_addr *dst,
232 struct ospf6_interface *oi, struct ospf6_header *oh)
234 u_char type;
235 type = OSPF6_MESSAGE_TYPE_CANONICAL (oh->type);
237 /* version check */
238 if (oh->version != OSPFV3_VERSION)
240 if (IS_OSPF6_DEBUG_MESSAGE (type, RECV))
241 zlog_info ("Message with unknown version");
242 return MSG_NG;
245 /* Area-ID check */
246 if (oh->area_id != oi->area->area_id)
248 if (oh->area_id == BACKBONE_AREA_ID)
250 if (IS_OSPF6_DEBUG_MESSAGE (type, RECV))
251 zlog_info ("Message may be via Virtual Link: not supported");
252 return MSG_NG;
255 if (IS_OSPF6_DEBUG_MESSAGE (type, RECV))
256 zlog_info ("Area-ID mismatch");
257 return MSG_NG;
260 /* Instance-ID check */
261 if (oh->instance_id != oi->instance_id)
263 if (IS_OSPF6_DEBUG_MESSAGE (type, RECV))
264 zlog_info ("Instance-ID mismatch");
265 return MSG_NG;
268 /* Router-ID check */
269 if (oh->router_id == oi->area->ospf6->router_id)
270 zlog_warn ("Detect duplicate Router-ID");
272 return MSG_OK;
275 void
276 ospf6_hello_recv (struct in6_addr *src, struct in6_addr *dst,
277 struct ospf6_interface *oi, struct ospf6_header *oh)
279 struct ospf6_hello *hello;
280 struct ospf6_neighbor *on;
281 char *p;
282 int twoway = 0;
283 int neighborchange = 0;
284 int backupseen = 0;
286 if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
287 return;
289 hello = (struct ospf6_hello *)
290 ((caddr_t) oh + sizeof (struct ospf6_header));
292 /* HelloInterval check */
293 if (ntohs (hello->hello_interval) != oi->hello_interval)
295 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
296 zlog_info ("HelloInterval mismatch");
297 return;
300 /* RouterDeadInterval check */
301 if (ntohs (hello->dead_interval) != oi->dead_interval)
303 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
304 zlog_info ("RouterDeadInterval mismatch");
305 return;
308 /* E-bit check */
309 if (OSPF6_OPT_ISSET (hello->options, OSPF6_OPT_E) !=
310 OSPF6_OPT_ISSET (oi->area->options, OSPF6_OPT_E))
312 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
313 zlog_info ("E-bit mismatch");
314 return;
317 /* Find neighbor, create if not exist */
318 on = ospf6_neighbor_lookup (oh->router_id, oi);
319 if (on == NULL)
321 on = ospf6_neighbor_create (oh->router_id, oi);
322 on->prev_drouter = on->drouter = hello->drouter;
323 on->prev_bdrouter = on->bdrouter = hello->bdrouter;
324 on->priority = hello->priority;
327 /* always override neighbor's source address and ifindex */
328 on->ifindex = ntohl (hello->interface_id);
329 memcpy (&on->linklocal_addr, src, sizeof (struct in6_addr));
331 /* TwoWay check */
332 for (p = (char *) ((caddr_t) hello + sizeof (struct ospf6_hello));
333 p + sizeof (u_int32_t) <= OSPF6_MESSAGE_END (oh);
334 p += sizeof (u_int32_t))
336 u_int32_t *router_id = (u_int32_t *) p;
338 if (*router_id == oi->area->ospf6->router_id)
339 twoway++;
342 if (p != OSPF6_MESSAGE_END (oh))
344 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
345 zlog_info ("Trailing garbage ignored");
348 /* RouterPriority check */
349 if (on->priority != hello->priority)
351 on->priority = hello->priority;
352 neighborchange++;
355 /* DR check */
356 if (on->drouter != hello->drouter)
358 on->prev_drouter = on->drouter;
359 on->drouter = hello->drouter;
360 if (on->prev_drouter == on->router_id || on->drouter == on->router_id)
361 neighborchange++;
364 /* BDR check */
365 if (on->bdrouter != hello->bdrouter)
367 on->prev_bdrouter = on->bdrouter;
368 on->bdrouter = hello->bdrouter;
369 if (on->prev_bdrouter == on->router_id || on->bdrouter == on->router_id)
370 neighborchange++;
373 /* BackupSeen check */
374 if (oi->state == OSPF6_INTERFACE_WAITING)
376 if (hello->bdrouter == on->router_id)
377 backupseen++;
378 else if (hello->drouter == on->router_id && hello->bdrouter == htonl (0))
379 backupseen++;
382 /* Execute neighbor events */
383 thread_execute (master, hello_received, on, 0);
384 if (twoway)
385 thread_execute (master, twoway_received, on, 0);
386 else
387 thread_execute (master, oneway_received, on, 0);
389 /* Schedule interface events */
390 if (backupseen)
391 thread_add_event (master, backup_seen, oi, 0);
392 if (neighborchange)
393 thread_add_event (master, neighbor_change, oi, 0);
396 static void
397 ospf6_dbdesc_recv_master (struct ospf6_header *oh,
398 struct ospf6_neighbor *on)
400 struct ospf6_dbdesc *dbdesc;
401 char *p;
403 dbdesc = (struct ospf6_dbdesc *)
404 ((caddr_t) oh + sizeof (struct ospf6_header));
406 if (on->state < OSPF6_NEIGHBOR_INIT)
408 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
409 zlog_info ("Neighbor state less than Init, ignore");
410 return;
413 switch (on->state)
415 case OSPF6_NEIGHBOR_TWOWAY:
416 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
417 zlog_info ("Neighbor state is 2-Way, ignore");
418 return;
420 case OSPF6_NEIGHBOR_INIT:
421 thread_execute (master, twoway_received, on, 0);
422 if (on->state != OSPF6_NEIGHBOR_EXSTART)
424 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
425 zlog_info ("Neighbor state is not ExStart, ignore");
426 return;
428 /* else fall through to ExStart */
430 case OSPF6_NEIGHBOR_EXSTART:
431 /* if neighbor obeys us as our slave, schedule negotiation_done
432 and process LSA Headers. Otherwise, ignore this message */
433 if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) &&
434 ! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) &&
435 ntohl (dbdesc->seqnum) == on->dbdesc_seqnum)
437 /* execute NegotiationDone */
438 thread_execute (master, negotiation_done, on, 0);
440 /* Record neighbor options */
441 memcpy (on->options, dbdesc->options, sizeof (on->options));
443 else
445 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
446 zlog_info ("Negotiation failed");
447 return;
449 /* fall through to exchange */
451 case OSPF6_NEIGHBOR_EXCHANGE:
452 if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc)))
454 /* Duplicated DatabaseDescription is dropped by master */
455 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
456 zlog_info ("Duplicated dbdesc discarded by Master, ignore");
457 return;
460 if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT))
462 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
463 zlog_info ("Master/Slave bit mismatch");
464 thread_add_event (master, seqnumber_mismatch, on, 0);
465 return;
468 if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT))
470 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
471 zlog_info ("Initialize bit mismatch");
472 thread_add_event (master, seqnumber_mismatch, on, 0);
473 return;
476 if (memcmp (on->options, dbdesc->options, sizeof (on->options)))
478 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
479 zlog_info ("Option field mismatch");
480 thread_add_event (master, seqnumber_mismatch, on, 0);
481 return;
484 if (ntohl (dbdesc->seqnum) != on->dbdesc_seqnum)
486 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
487 zlog_info ("Sequence number mismatch (%#lx expected)",
488 (u_long) on->dbdesc_seqnum);
489 thread_add_event (master, seqnumber_mismatch, on, 0);
490 return;
492 break;
494 case OSPF6_NEIGHBOR_LOADING:
495 case OSPF6_NEIGHBOR_FULL:
496 if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc)))
498 /* Duplicated DatabaseDescription is dropped by master */
499 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
500 zlog_info ("Duplicated dbdesc discarded by Master, ignore");
501 return;
504 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
505 zlog_info ("Not duplicate dbdesc in state %s",
506 ospf6_neighbor_state_str[on->state]);
507 thread_add_event (master, seqnumber_mismatch, on, 0);
508 return;
510 default:
511 assert (0);
512 break;
515 /* Process LSA headers */
516 for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc));
517 p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
518 p += sizeof (struct ospf6_lsa_header))
520 struct ospf6_lsa *his, *mine;
521 struct ospf6_lsdb *lsdb = NULL;
523 his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p);
525 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
526 zlog_info ("%s", his->name);
528 switch (OSPF6_LSA_SCOPE (his->header->type))
530 case OSPF6_SCOPE_LINKLOCAL:
531 lsdb = on->ospf6_if->lsdb;
532 break;
533 case OSPF6_SCOPE_AREA:
534 lsdb = on->ospf6_if->area->lsdb;
535 break;
536 case OSPF6_SCOPE_AS:
537 lsdb = on->ospf6_if->area->ospf6->lsdb;
538 break;
539 case OSPF6_SCOPE_RESERVED:
540 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
541 zlog_info ("Ignoring LSA of reserved scope");
542 ospf6_lsa_delete (his);
543 continue;
544 break;
547 if (ntohs (his->header->type) == OSPF6_LSTYPE_AS_EXTERNAL &&
548 IS_AREA_STUB (on->ospf6_if->area))
550 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
551 zlog_info ("SeqNumMismatch (E-bit mismatch), discard");
552 ospf6_lsa_delete (his);
553 thread_add_event (master, seqnumber_mismatch, on, 0);
554 return;
557 mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
558 his->header->adv_router, lsdb);
559 if (mine == NULL)
561 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
562 zlog_info ("Add request (No database copy)");
563 ospf6_lsdb_add (his, on->request_list);
565 else if (ospf6_lsa_compare (his, mine) < 0)
567 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
568 zlog_info ("Add request (Received MoreRecent)");
569 ospf6_lsdb_add (his, on->request_list);
571 else
573 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
574 zlog_info ("Discard (Existing MoreRecent)");
575 ospf6_lsa_delete (his);
579 if (p != OSPF6_MESSAGE_END (oh))
581 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
582 zlog_info ("Trailing garbage ignored");
585 /* Increment sequence number */
586 on->dbdesc_seqnum ++;
588 /* schedule send lsreq */
589 if (on->thread_send_lsreq == NULL)
590 on->thread_send_lsreq =
591 thread_add_event (master, ospf6_lsreq_send, on, 0);
593 THREAD_OFF (on->thread_send_dbdesc);
595 /* More bit check */
596 if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) &&
597 ! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT))
598 thread_add_event (master, exchange_done, on, 0);
599 else
600 on->thread_send_dbdesc =
601 thread_add_event (master, ospf6_dbdesc_send_newone, on, 0);
603 /* save last received dbdesc */
604 memcpy (&on->dbdesc_last, dbdesc, sizeof (struct ospf6_dbdesc));
607 static void
608 ospf6_dbdesc_recv_slave (struct ospf6_header *oh,
609 struct ospf6_neighbor *on)
611 struct ospf6_dbdesc *dbdesc;
612 char *p;
614 dbdesc = (struct ospf6_dbdesc *)
615 ((caddr_t) oh + sizeof (struct ospf6_header));
617 if (on->state < OSPF6_NEIGHBOR_INIT)
619 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
620 zlog_info ("Neighbor state less than Init, ignore");
621 return;
624 switch (on->state)
626 case OSPF6_NEIGHBOR_TWOWAY:
627 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
628 zlog_info ("Neighbor state is 2-Way, ignore");
629 return;
631 case OSPF6_NEIGHBOR_INIT:
632 thread_execute (master, twoway_received, on, 0);
633 if (on->state != OSPF6_NEIGHBOR_EXSTART)
635 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
636 zlog_info ("Neighbor state is not ExStart, ignore");
637 return;
639 /* else fall through to ExStart */
641 case OSPF6_NEIGHBOR_EXSTART:
642 /* If the neighbor is Master, act as Slave. Schedule negotiation_done
643 and process LSA Headers. Otherwise, ignore this message */
644 if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT) &&
645 CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MBIT) &&
646 CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT) &&
647 ntohs (oh->length) == sizeof (struct ospf6_header) +
648 sizeof (struct ospf6_dbdesc))
650 /* set the master/slave bit to slave */
651 UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
653 /* set the DD sequence number to one specified by master */
654 on->dbdesc_seqnum = ntohl (dbdesc->seqnum);
656 /* schedule NegotiationDone */
657 thread_execute (master, negotiation_done, on, 0);
659 /* Record neighbor options */
660 memcpy (on->options, dbdesc->options, sizeof (on->options));
662 else
664 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
665 zlog_info ("Negotiation failed");
666 return;
668 break;
670 case OSPF6_NEIGHBOR_EXCHANGE:
671 if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc)))
673 /* Duplicated DatabaseDescription causes slave to retransmit */
674 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
675 zlog_info ("Duplicated dbdesc causes retransmit");
676 THREAD_OFF (on->thread_send_dbdesc);
677 on->thread_send_dbdesc =
678 thread_add_event (master, ospf6_dbdesc_send, on, 0);
679 return;
682 if (! CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_MSBIT))
684 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
685 zlog_info ("Master/Slave bit mismatch");
686 thread_add_event (master, seqnumber_mismatch, on, 0);
687 return;
690 if (CHECK_FLAG (dbdesc->bits, OSPF6_DBDESC_IBIT))
692 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
693 zlog_info ("Initialize bit mismatch");
694 thread_add_event (master, seqnumber_mismatch, on, 0);
695 return;
698 if (memcmp (on->options, dbdesc->options, sizeof (on->options)))
700 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
701 zlog_info ("Option field mismatch");
702 thread_add_event (master, seqnumber_mismatch, on, 0);
703 return;
706 if (ntohl (dbdesc->seqnum) != on->dbdesc_seqnum + 1)
708 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
709 zlog_info ("Sequence number mismatch (%#lx expected)",
710 (u_long) on->dbdesc_seqnum + 1);
711 thread_add_event (master, seqnumber_mismatch, on, 0);
712 return;
714 break;
716 case OSPF6_NEIGHBOR_LOADING:
717 case OSPF6_NEIGHBOR_FULL:
718 if (! memcmp (dbdesc, &on->dbdesc_last, sizeof (struct ospf6_dbdesc)))
720 /* Duplicated DatabaseDescription causes slave to retransmit */
721 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
722 zlog_info ("Duplicated dbdesc causes retransmit");
723 THREAD_OFF (on->thread_send_dbdesc);
724 on->thread_send_dbdesc =
725 thread_add_event (master, ospf6_dbdesc_send, on, 0);
726 return;
729 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
730 zlog_info ("Not duplicate dbdesc in state %s",
731 ospf6_neighbor_state_str[on->state]);
732 thread_add_event (master, seqnumber_mismatch, on, 0);
733 return;
735 default:
736 assert (0);
737 break;
740 /* Process LSA headers */
741 for (p = (char *) ((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc));
742 p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
743 p += sizeof (struct ospf6_lsa_header))
745 struct ospf6_lsa *his, *mine;
746 struct ospf6_lsdb *lsdb = NULL;
748 his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p);
750 switch (OSPF6_LSA_SCOPE (his->header->type))
752 case OSPF6_SCOPE_LINKLOCAL:
753 lsdb = on->ospf6_if->lsdb;
754 break;
755 case OSPF6_SCOPE_AREA:
756 lsdb = on->ospf6_if->area->lsdb;
757 break;
758 case OSPF6_SCOPE_AS:
759 lsdb = on->ospf6_if->area->ospf6->lsdb;
760 break;
761 case OSPF6_SCOPE_RESERVED:
762 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
763 zlog_info ("Ignoring LSA of reserved scope");
764 ospf6_lsa_delete (his);
765 continue;
766 break;
769 if (OSPF6_LSA_SCOPE (his->header->type) == OSPF6_SCOPE_AS &&
770 IS_AREA_STUB (on->ospf6_if->area))
772 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
773 zlog_info ("E-bit mismatch with LSA Headers");
774 ospf6_lsa_delete (his);
775 thread_add_event (master, seqnumber_mismatch, on, 0);
776 return;
779 mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
780 his->header->adv_router, lsdb);
781 if (mine == NULL || ospf6_lsa_compare (his, mine) < 0)
783 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
784 zlog_info ("Add request-list: %s", his->name);
785 ospf6_lsdb_add (his, on->request_list);
787 else
788 ospf6_lsa_delete (his);
791 if (p != OSPF6_MESSAGE_END (oh))
793 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
794 zlog_info ("Trailing garbage ignored");
797 /* Set sequence number to Master's */
798 on->dbdesc_seqnum = ntohl (dbdesc->seqnum);
800 /* schedule send lsreq */
801 if (on->thread_send_lsreq == NULL)
802 on->thread_send_lsreq =
803 thread_add_event (master, ospf6_lsreq_send, on, 0);
805 THREAD_OFF (on->thread_send_dbdesc);
806 on->thread_send_dbdesc =
807 thread_add_event (master, ospf6_dbdesc_send_newone, on, 0);
809 /* save last received dbdesc */
810 memcpy (&on->dbdesc_last, dbdesc, sizeof (struct ospf6_dbdesc));
813 void
814 ospf6_dbdesc_recv (struct in6_addr *src, struct in6_addr *dst,
815 struct ospf6_interface *oi, struct ospf6_header *oh)
817 struct ospf6_neighbor *on;
818 struct ospf6_dbdesc *dbdesc;
820 if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
821 return;
823 on = ospf6_neighbor_lookup (oh->router_id, oi);
824 if (on == NULL)
826 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
827 zlog_info ("Neighbor not found, ignore");
828 return;
831 dbdesc = (struct ospf6_dbdesc *)
832 ((caddr_t) oh + sizeof (struct ospf6_header));
834 /* Interface MTU check */
835 if (ntohs (dbdesc->ifmtu) != oi->ifmtu)
837 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
838 zlog_info ("I/F MTU mismatch");
839 return;
842 if (dbdesc->reserved1 || dbdesc->reserved2)
844 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
845 zlog_info ("Non-0 reserved field in %s's DbDesc, correct",
846 on->name);
847 dbdesc->reserved1 = 0;
848 dbdesc->reserved2 = 0;
851 if (ntohl (oh->router_id) < ntohl (ospf6->router_id))
852 ospf6_dbdesc_recv_master (oh, on);
853 else if (ntohl (ospf6->router_id) < ntohl (oh->router_id))
854 ospf6_dbdesc_recv_slave (oh, on);
855 else
857 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
858 zlog_info ("Can't decide which is master, ignore");
862 void
863 ospf6_lsreq_recv (struct in6_addr *src, struct in6_addr *dst,
864 struct ospf6_interface *oi, struct ospf6_header *oh)
866 struct ospf6_neighbor *on;
867 char *p;
868 struct ospf6_lsreq_entry *e;
869 struct ospf6_lsdb *lsdb = NULL;
870 struct ospf6_lsa *lsa;
872 if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
873 return;
875 on = ospf6_neighbor_lookup (oh->router_id, oi);
876 if (on == NULL)
878 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
879 zlog_info ("Neighbor not found, ignore");
880 return;
883 if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
884 on->state != OSPF6_NEIGHBOR_LOADING &&
885 on->state != OSPF6_NEIGHBOR_FULL)
887 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
888 zlog_info ("Neighbor state less than Exchange, ignore");
889 return;
892 /* Process each request */
893 for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header));
894 p + sizeof (struct ospf6_lsreq_entry) <= OSPF6_MESSAGE_END (oh);
895 p += sizeof (struct ospf6_lsreq_entry))
897 e = (struct ospf6_lsreq_entry *) p;
899 switch (OSPF6_LSA_SCOPE (e->type))
901 case OSPF6_SCOPE_LINKLOCAL:
902 lsdb = on->ospf6_if->lsdb;
903 break;
904 case OSPF6_SCOPE_AREA:
905 lsdb = on->ospf6_if->area->lsdb;
906 break;
907 case OSPF6_SCOPE_AS:
908 lsdb = on->ospf6_if->area->ospf6->lsdb;
909 break;
910 default:
911 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
912 zlog_info ("Ignoring LSA of reserved scope");
913 continue;
914 break;
917 /* Find database copy */
918 lsa = ospf6_lsdb_lookup (e->type, e->id, e->adv_router, lsdb);
919 if (lsa == NULL)
921 char id[16], adv_router[16];
922 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
924 inet_ntop (AF_INET, &e->id, id, sizeof (id));
925 inet_ntop (AF_INET, &e->adv_router, adv_router,
926 sizeof (adv_router));
927 zlog_info ("Can't find requested [%s Id:%s Adv:%s]",
928 ospf6_lstype_name (e->type), id, adv_router);
930 thread_add_event (master, bad_lsreq, on, 0);
931 return;
934 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->lsupdate_list);
937 if (p != OSPF6_MESSAGE_END (oh))
939 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
940 zlog_info ("Trailing garbage ignored");
943 /* schedule send lsupdate */
944 THREAD_OFF (on->thread_send_lsupdate);
945 on->thread_send_lsupdate =
946 thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0);
949 void
950 ospf6_lsupdate_recv (struct in6_addr *src, struct in6_addr *dst,
951 struct ospf6_interface *oi, struct ospf6_header *oh)
953 struct ospf6_neighbor *on;
954 struct ospf6_lsupdate *lsupdate;
955 unsigned long num;
956 char *p;
958 if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
959 return;
961 on = ospf6_neighbor_lookup (oh->router_id, oi);
962 if (on == NULL)
964 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
965 zlog_info ("Neighbor not found, ignore");
966 return;
969 if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
970 on->state != OSPF6_NEIGHBOR_LOADING &&
971 on->state != OSPF6_NEIGHBOR_FULL)
973 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
974 zlog_info ("Neighbor state less than Exchange, ignore");
975 return;
978 lsupdate = (struct ospf6_lsupdate *)
979 ((caddr_t) oh + sizeof (struct ospf6_header));
981 num = ntohl (lsupdate->lsa_number);
983 /* Process LSAs */
984 for (p = (char *) ((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
985 p < OSPF6_MESSAGE_END (oh) &&
986 p + OSPF6_LSA_SIZE (p) <= OSPF6_MESSAGE_END (oh);
987 p += OSPF6_LSA_SIZE (p))
989 if (num == 0)
990 break;
991 if (OSPF6_LSA_SIZE (p) < sizeof (struct ospf6_lsa_header))
993 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
994 zlog_info ("Malformed LSA length, quit processing");
995 break;
998 ospf6_receive_lsa (on, (struct ospf6_lsa_header *) p);
999 num--;
1002 if (num != 0)
1004 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1005 zlog_info ("Malformed LSA number or LSA length");
1007 if (p != OSPF6_MESSAGE_END (oh))
1009 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1010 zlog_info ("Trailing garbage ignored");
1013 /* RFC2328 Section 10.9: When the neighbor responds to these requests
1014 with the proper Link State Update packet(s), the Link state request
1015 list is truncated and a new Link State Request packet is sent. */
1016 /* send new Link State Request packet if this LS Update packet
1017 can be recognized as a response to our previous LS Request */
1018 if (! IN6_IS_ADDR_MULTICAST (dst) &&
1019 (on->state == OSPF6_NEIGHBOR_EXCHANGE ||
1020 on->state == OSPF6_NEIGHBOR_LOADING))
1022 THREAD_OFF (on->thread_send_lsreq);
1023 on->thread_send_lsreq =
1024 thread_add_event (master, ospf6_lsreq_send, on, 0);
1028 void
1029 ospf6_lsack_recv (struct in6_addr *src, struct in6_addr *dst,
1030 struct ospf6_interface *oi, struct ospf6_header *oh)
1032 struct ospf6_neighbor *on;
1033 char *p;
1034 struct ospf6_lsa *his, *mine;
1035 struct ospf6_lsdb *lsdb = NULL;
1037 assert (oh->type == OSPF6_MESSAGE_TYPE_LSACK);
1038 if (ospf6_header_examin (src, dst, oi, oh) != MSG_OK)
1039 return;
1041 on = ospf6_neighbor_lookup (oh->router_id, oi);
1042 if (on == NULL)
1044 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1045 zlog_info ("Neighbor not found, ignore");
1046 return;
1049 if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
1050 on->state != OSPF6_NEIGHBOR_LOADING &&
1051 on->state != OSPF6_NEIGHBOR_FULL)
1053 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1054 zlog_info ("Neighbor state less than Exchange, ignore");
1055 return;
1058 for (p = (char *) ((caddr_t) oh + sizeof (struct ospf6_header));
1059 p + sizeof (struct ospf6_lsa_header) <= OSPF6_MESSAGE_END (oh);
1060 p += sizeof (struct ospf6_lsa_header))
1062 his = ospf6_lsa_create_headeronly ((struct ospf6_lsa_header *) p);
1064 switch (OSPF6_LSA_SCOPE (his->header->type))
1066 case OSPF6_SCOPE_LINKLOCAL:
1067 lsdb = on->ospf6_if->lsdb;
1068 break;
1069 case OSPF6_SCOPE_AREA:
1070 lsdb = on->ospf6_if->area->lsdb;
1071 break;
1072 case OSPF6_SCOPE_AS:
1073 lsdb = on->ospf6_if->area->ospf6->lsdb;
1074 break;
1075 case OSPF6_SCOPE_RESERVED:
1076 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1077 zlog_info ("Ignoring LSA of reserved scope");
1078 ospf6_lsa_delete (his);
1079 continue;
1080 break;
1083 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1084 zlog_info ("%s acknowledged by %s", his->name, on->name);
1086 /* Find database copy */
1087 mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
1088 his->header->adv_router, lsdb);
1089 if (mine == NULL)
1091 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1092 zlog_info ("No database copy");
1093 ospf6_lsa_delete (his);
1094 continue;
1097 /* Check if the LSA is on his retrans-list */
1098 mine = ospf6_lsdb_lookup (his->header->type, his->header->id,
1099 his->header->adv_router, on->retrans_list);
1100 if (mine == NULL)
1102 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1103 zlog_info ("Not on %s's retrans-list", on->name);
1104 ospf6_lsa_delete (his);
1105 continue;
1108 if (ospf6_lsa_compare (his, mine) != 0)
1110 /* Log this questionable acknowledgement,
1111 and examine the next one. */
1112 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1113 zlog_info ("Questionable acknowledgement");
1114 ospf6_lsa_delete (his);
1115 continue;
1118 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1119 zlog_info ("Acknowledged, remove from %s's retrans-list",
1120 on->name);
1122 if (OSPF6_LSA_IS_MAXAGE (mine))
1123 ospf6_maxage_remove (on->ospf6_if->area->ospf6);
1125 ospf6_decrement_retrans_count (mine);
1126 ospf6_lsdb_remove (mine, on->retrans_list);
1127 ospf6_lsa_delete (his);
1130 if (p != OSPF6_MESSAGE_END (oh))
1132 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1133 zlog_info ("Trailing garbage ignored");
1137 char *recvbuf = NULL;
1138 char *sendbuf = NULL;
1139 int iobuflen = 0;
1142 ospf6_iobuf_size (int size)
1144 char *recvnew, *sendnew;
1146 if (size <= iobuflen)
1147 return iobuflen;
1149 recvnew = XMALLOC (MTYPE_OSPF6_MESSAGE, size);
1150 sendnew = XMALLOC (MTYPE_OSPF6_MESSAGE, size);
1151 if (recvnew == NULL || sendnew == NULL)
1153 if (recvnew)
1154 XFREE (MTYPE_OSPF6_MESSAGE, recvnew);
1155 if (sendnew)
1156 XFREE (MTYPE_OSPF6_MESSAGE, sendnew);
1157 zlog_info ("Could not allocate I/O buffer of size %d.", size);
1158 return iobuflen;
1161 if (recvbuf)
1162 XFREE (MTYPE_OSPF6_MESSAGE, recvbuf);
1163 if (sendbuf)
1164 XFREE (MTYPE_OSPF6_MESSAGE, sendbuf);
1165 recvbuf = recvnew;
1166 sendbuf = sendnew;
1167 iobuflen = size;
1169 return iobuflen;
1173 ospf6_receive (struct thread *thread)
1175 int sockfd, len;
1176 char srcname[64], dstname[64];
1177 struct in6_addr src, dst;
1178 unsigned int ifindex;
1179 struct iovec iovector[2];
1180 struct ospf6_interface *oi;
1181 struct ospf6_header *oh;
1183 /* add next read thread */
1184 sockfd = THREAD_FD (thread);
1185 thread_add_read (master, ospf6_receive, NULL, sockfd);
1187 /* initialize */
1188 memset (recvbuf, 0, iobuflen);
1189 iovector[0].iov_base = recvbuf;
1190 iovector[0].iov_len = iobuflen;
1191 iovector[1].iov_base = NULL;
1192 iovector[1].iov_len = 0;
1194 /* receive message */
1195 len = ospf6_recvmsg (&src, &dst, &ifindex, iovector);
1196 if (len > iobuflen)
1198 zlog_err ("Excess message read");
1199 return 0;
1201 else if (len < sizeof (struct ospf6_header))
1203 zlog_err ("Deficient message read");
1204 return 0;
1207 oi = ospf6_interface_lookup_by_ifindex (ifindex);
1208 if (oi == NULL || oi->area == NULL)
1210 zlog_info ("Message received on disabled interface");
1211 return 0;
1214 oh = (struct ospf6_header *) recvbuf;
1216 /* Log */
1217 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1219 inet_ntop (AF_INET6, &src, srcname, sizeof (srcname));
1220 inet_ntop (AF_INET6, &dst, dstname, sizeof (dstname));
1221 zlog_info ("%s received on %s",
1222 OSPF6_MESSAGE_TYPE_NAME (oh->type), oi->interface->name);
1223 zlog_info (" src: %s", srcname);
1224 zlog_info (" dst: %s", dstname);
1225 if (len != ntohs (oh->length))
1226 zlog_info ("Message length does not match actually received: %d", len);
1228 switch (oh->type)
1230 case OSPF6_MESSAGE_TYPE_HELLO:
1231 ospf6_hello_print (oh);
1232 break;
1233 case OSPF6_MESSAGE_TYPE_DBDESC:
1234 ospf6_dbdesc_print (oh);
1235 break;
1236 case OSPF6_MESSAGE_TYPE_LSREQ:
1237 ospf6_lsreq_print (oh);
1238 break;
1239 case OSPF6_MESSAGE_TYPE_LSUPDATE:
1240 ospf6_lsupdate_print (oh);
1241 break;
1242 case OSPF6_MESSAGE_TYPE_LSACK:
1243 ospf6_lsack_print (oh);
1244 break;
1245 default:
1246 zlog_info ("Unknown message");
1247 break;
1251 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
1253 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, RECV))
1254 zlog_info ("Ignore message on passive interface %s",
1255 oi->interface->name);
1256 return 0;
1259 switch (oh->type)
1261 case OSPF6_MESSAGE_TYPE_HELLO:
1262 ospf6_hello_recv (&src, &dst, oi, oh);
1263 break;
1265 case OSPF6_MESSAGE_TYPE_DBDESC:
1266 ospf6_dbdesc_recv (&src, &dst, oi, oh);
1267 break;
1269 case OSPF6_MESSAGE_TYPE_LSREQ:
1270 ospf6_lsreq_recv (&src, &dst, oi, oh);
1271 break;
1273 case OSPF6_MESSAGE_TYPE_LSUPDATE:
1274 ospf6_lsupdate_recv (&src, &dst, oi, oh);
1275 break;
1277 case OSPF6_MESSAGE_TYPE_LSACK:
1278 ospf6_lsack_recv (&src, &dst, oi, oh);
1279 break;
1281 default:
1282 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
1283 zlog_info ("Unknown message");
1284 break;
1287 return 0;
1290 void
1291 ospf6_send (struct in6_addr *src, struct in6_addr *dst,
1292 struct ospf6_interface *oi, struct ospf6_header *oh)
1294 int len;
1295 char srcname[64], dstname[64];
1296 struct iovec iovector[2];
1298 /* initialize */
1299 iovector[0].iov_base = (caddr_t) oh;
1300 iovector[0].iov_len = ntohs (oh->length);
1301 iovector[1].iov_base = NULL;
1302 iovector[1].iov_len = 0;
1304 /* fill OSPF header */
1305 oh->version = OSPFV3_VERSION;
1306 /* message type must be set before */
1307 /* message length must be set before */
1308 oh->router_id = oi->area->ospf6->router_id;
1309 oh->area_id = oi->area->area_id;
1310 /* checksum is calculated by kernel */
1311 oh->instance_id = oi->instance_id;
1312 oh->reserved = 0;
1314 /* Log */
1315 if (IS_OSPF6_DEBUG_MESSAGE (oh->type, SEND))
1317 inet_ntop (AF_INET6, dst, dstname, sizeof (dstname));
1318 if (src)
1319 inet_ntop (AF_INET6, src, srcname, sizeof (srcname));
1320 else
1321 memset (srcname, 0, sizeof (srcname));
1322 zlog_info ("%s send on %s",
1323 OSPF6_MESSAGE_TYPE_NAME (oh->type), oi->interface->name);
1324 zlog_info (" src: %s", srcname);
1325 zlog_info (" dst: %s", dstname);
1327 switch (oh->type)
1329 case OSPF6_MESSAGE_TYPE_HELLO:
1330 ospf6_hello_print (oh);
1331 break;
1332 case OSPF6_MESSAGE_TYPE_DBDESC:
1333 ospf6_dbdesc_print (oh);
1334 break;
1335 case OSPF6_MESSAGE_TYPE_LSREQ:
1336 ospf6_lsreq_print (oh);
1337 break;
1338 case OSPF6_MESSAGE_TYPE_LSUPDATE:
1339 ospf6_lsupdate_print (oh);
1340 break;
1341 case OSPF6_MESSAGE_TYPE_LSACK:
1342 ospf6_lsack_print (oh);
1343 break;
1344 default:
1345 zlog_info ("Unknown message");
1346 assert (0);
1347 break;
1351 /* send message */
1352 len = ospf6_sendmsg (src, dst, &oi->interface->ifindex, iovector);
1353 if (len != ntohs (oh->length))
1354 zlog_err ("Could not send entire message");
1358 ospf6_hello_send (struct thread *thread)
1360 struct ospf6_interface *oi;
1361 struct ospf6_header *oh;
1362 struct ospf6_hello *hello;
1363 char *p;
1364 listnode node;
1365 struct ospf6_neighbor *on;
1367 oi = (struct ospf6_interface *) THREAD_ARG (thread);
1368 oi->thread_send_hello = (struct thread *) NULL;
1370 if (oi->state <= OSPF6_INTERFACE_DOWN)
1372 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_HELLO, SEND))
1373 zlog_info ("Unable to send Hello on down interface %s",
1374 oi->interface->name);
1375 return 0;
1378 /* set next thread */
1379 oi->thread_send_hello = thread_add_timer (master, ospf6_hello_send,
1380 oi, oi->hello_interval);
1382 memset (sendbuf, 0, iobuflen);
1383 oh = (struct ospf6_header *) sendbuf;
1384 hello = (struct ospf6_hello *)((caddr_t) oh + sizeof (struct ospf6_header));
1386 hello->interface_id = htonl (oi->interface->ifindex);
1387 hello->priority = oi->priority;
1388 hello->options[0] = oi->area->options[0];
1389 hello->options[1] = oi->area->options[1];
1390 hello->options[2] = oi->area->options[2];
1391 hello->hello_interval = htons (oi->hello_interval);
1392 hello->dead_interval = htons (oi->dead_interval);
1393 hello->drouter = oi->drouter;
1394 hello->bdrouter = oi->bdrouter;
1396 p = (char *)((caddr_t) hello + sizeof (struct ospf6_hello));
1398 for (node = listhead (oi->neighbor_list); node; nextnode (node))
1400 on = (struct ospf6_neighbor *) getdata (node);
1402 if (on->state < OSPF6_NEIGHBOR_INIT)
1403 continue;
1405 if (p - sendbuf + sizeof (u_int32_t) > oi->ifmtu)
1407 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_HELLO, SEND))
1408 zlog_info ("sending Hello message: exceeds I/F MTU");
1409 break;
1412 memcpy (p, &on->router_id, sizeof (u_int32_t));
1413 p += sizeof (u_int32_t);
1416 oh->type = OSPF6_MESSAGE_TYPE_HELLO;
1417 oh->length = htons (p - sendbuf);
1419 ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh);
1420 return 0;
1424 ospf6_dbdesc_send (struct thread *thread)
1426 struct ospf6_neighbor *on;
1427 struct ospf6_header *oh;
1428 struct ospf6_dbdesc *dbdesc;
1429 char *p;
1430 struct ospf6_lsa *lsa;
1432 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
1433 on->thread_send_dbdesc = (struct thread *) NULL;
1435 if (on->state < OSPF6_NEIGHBOR_EXSTART)
1437 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_DBDESC, SEND))
1438 zlog_info ("Quit to send DbDesc to neighbor %s state %s",
1439 on->name, ospf6_neighbor_state_str[on->state]);
1440 return 0;
1443 /* set next thread if master */
1444 if (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT))
1445 on->thread_send_dbdesc =
1446 thread_add_timer (master, ospf6_dbdesc_send, on,
1447 on->ospf6_if->rxmt_interval);
1449 memset (sendbuf, 0, iobuflen);
1450 oh = (struct ospf6_header *) sendbuf;
1451 dbdesc = (struct ospf6_dbdesc *)((caddr_t) oh +
1452 sizeof (struct ospf6_header));
1454 /* if this is initial one, initialize sequence number for DbDesc */
1455 if (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT))
1457 struct timeval tv;
1458 if (gettimeofday (&tv, (struct timezone *) NULL) < 0)
1459 tv.tv_sec = 1;
1460 on->dbdesc_seqnum = tv.tv_sec;
1463 dbdesc->options[0] = on->ospf6_if->area->options[0];
1464 dbdesc->options[1] = on->ospf6_if->area->options[1];
1465 dbdesc->options[2] = on->ospf6_if->area->options[2];
1466 dbdesc->ifmtu = htons (on->ospf6_if->ifmtu);
1467 dbdesc->bits = on->dbdesc_bits;
1468 dbdesc->seqnum = htonl (on->dbdesc_seqnum);
1470 /* if this is not initial one, set LSA headers in dbdesc */
1471 p = (char *)((caddr_t) dbdesc + sizeof (struct ospf6_dbdesc));
1472 if (! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT))
1474 for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa;
1475 lsa = ospf6_lsdb_next (lsa))
1477 ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
1479 /* MTU check */
1480 if (p - sendbuf + sizeof (struct ospf6_lsa_header) >
1481 on->ospf6_if->ifmtu)
1483 ospf6_lsa_unlock (lsa);
1484 break;
1486 memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header));
1487 p += sizeof (struct ospf6_lsa_header);
1491 oh->type = OSPF6_MESSAGE_TYPE_DBDESC;
1492 oh->length = htons (p - sendbuf);
1494 ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
1495 on->ospf6_if, oh);
1496 return 0;
1500 ospf6_dbdesc_send_newone (struct thread *thread)
1502 struct ospf6_neighbor *on;
1503 struct ospf6_lsa *lsa;
1504 unsigned int size = 0;
1506 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
1507 ospf6_lsdb_remove_all (on->dbdesc_list);
1509 /* move LSAs from summary_list to dbdesc_list (within neighbor structure)
1510 so that ospf6_send_dbdesc () can send those LSAs */
1511 size = sizeof (struct ospf6_lsa_header) + sizeof (struct ospf6_dbdesc);
1512 for (lsa = ospf6_lsdb_head (on->summary_list); lsa;
1513 lsa = ospf6_lsdb_next (lsa))
1515 if (size + sizeof (struct ospf6_lsa_header) > on->ospf6_if->ifmtu)
1517 ospf6_lsa_unlock (lsa);
1518 break;
1521 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->dbdesc_list);
1522 ospf6_lsdb_remove (lsa, on->summary_list);
1523 size += sizeof (struct ospf6_lsa_header);
1526 if (on->summary_list->count == 0)
1527 UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
1529 /* If slave, More bit check must be done here */
1530 if (! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) && /* Slave */
1531 ! CHECK_FLAG (on->dbdesc_last.bits, OSPF6_DBDESC_MBIT) &&
1532 ! CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT))
1533 thread_add_event (master, exchange_done, on, 0);
1535 thread_execute (master, ospf6_dbdesc_send, on, 0);
1536 return 0;
1540 ospf6_lsreq_send (struct thread *thread)
1542 struct ospf6_neighbor *on;
1543 struct ospf6_header *oh;
1544 struct ospf6_lsreq_entry *e;
1545 char *p;
1546 struct ospf6_lsa *lsa;
1548 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
1549 on->thread_send_lsreq = (struct thread *) NULL;
1551 /* LSReq will be sent only in ExStart or Loading */
1552 if (on->state != OSPF6_NEIGHBOR_EXCHANGE &&
1553 on->state != OSPF6_NEIGHBOR_LOADING)
1555 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSREQ, SEND))
1556 zlog_info ("Quit to send LSReq to neighbor %s state %s",
1557 on->name, ospf6_neighbor_state_str[on->state]);
1558 return 0;
1561 /* schedule loading_done if request list is empty */
1562 if (on->request_list->count == 0)
1564 thread_add_event (master, loading_done, on, 0);
1565 return 0;
1568 /* set next thread */
1569 on->thread_send_lsreq =
1570 thread_add_timer (master, ospf6_lsreq_send, on,
1571 on->ospf6_if->rxmt_interval);
1573 memset (sendbuf, 0, iobuflen);
1574 oh = (struct ospf6_header *) sendbuf;
1576 /* set Request entries in lsreq */
1577 p = (char *)((caddr_t) oh + sizeof (struct ospf6_header));
1578 for (lsa = ospf6_lsdb_head (on->request_list); lsa;
1579 lsa = ospf6_lsdb_next (lsa))
1581 /* MTU check */
1582 if (p - sendbuf + sizeof (struct ospf6_lsreq_entry) > on->ospf6_if->ifmtu)
1584 ospf6_lsa_unlock (lsa);
1585 break;
1588 e = (struct ospf6_lsreq_entry *) p;
1589 e->type = lsa->header->type;
1590 e->id = lsa->header->id;
1591 e->adv_router = lsa->header->adv_router;
1592 p += sizeof (struct ospf6_lsreq_entry);
1595 oh->type = OSPF6_MESSAGE_TYPE_LSREQ;
1596 oh->length = htons (p - sendbuf);
1598 ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
1599 on->ospf6_if, oh);
1600 return 0;
1604 ospf6_lsupdate_send_neighbor (struct thread *thread)
1606 struct ospf6_neighbor *on;
1607 struct ospf6_header *oh;
1608 struct ospf6_lsupdate *lsupdate;
1609 char *p;
1610 int num;
1611 struct ospf6_lsa *lsa;
1613 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
1614 on->thread_send_lsupdate = (struct thread *) NULL;
1616 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND))
1617 zlog_info ("LSUpdate to neighbor %s", on->name);
1619 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
1621 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND))
1622 zlog_info ("Quit to send (neighbor state %s)",
1623 ospf6_neighbor_state_str[on->state]);
1624 return 0;
1627 /* if we have nothing to send, return */
1628 if (on->lsupdate_list->count == 0 &&
1629 on->retrans_list->count == 0)
1631 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND))
1632 zlog_info ("Quit to send (nothing to send)");
1633 return 0;
1636 memset (sendbuf, 0, iobuflen);
1637 oh = (struct ospf6_header *) sendbuf;
1638 lsupdate = (struct ospf6_lsupdate *)
1639 ((caddr_t) oh + sizeof (struct ospf6_header));
1641 p = (char *)((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
1642 num = 0;
1644 /* lsupdate_list lists those LSA which doesn't need to be
1645 retransmitted. remove those from the list */
1646 for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa;
1647 lsa = ospf6_lsdb_next (lsa))
1649 /* MTU check */
1650 if (p - sendbuf + OSPF6_LSA_SIZE (lsa->header) > on->ospf6_if->ifmtu)
1652 ospf6_lsa_unlock (lsa);
1653 break;
1656 ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
1657 memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header));
1658 p += OSPF6_LSA_SIZE (lsa->header);
1659 num++;
1661 assert (lsa->lock == 2);
1662 ospf6_lsdb_remove (lsa, on->lsupdate_list);
1665 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
1666 lsa = ospf6_lsdb_next (lsa))
1668 /* MTU check */
1669 if (p - sendbuf + OSPF6_LSA_SIZE (lsa->header) > on->ospf6_if->ifmtu)
1671 ospf6_lsa_unlock (lsa);
1672 break;
1675 ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
1676 memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header));
1677 p += OSPF6_LSA_SIZE (lsa->header);
1678 num++;
1681 lsupdate->lsa_number = htonl (num);
1683 oh->type = OSPF6_MESSAGE_TYPE_LSUPDATE;
1684 oh->length = htons (p - sendbuf);
1686 ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
1687 on->ospf6_if, oh);
1689 if (on->lsupdate_list->count != 0 ||
1690 on->retrans_list->count != 0)
1692 if (on->lsupdate_list->count != 0)
1693 on->thread_send_lsupdate =
1694 thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0);
1695 else
1696 on->thread_send_lsupdate =
1697 thread_add_timer (master, ospf6_lsupdate_send_neighbor, on,
1698 on->ospf6_if->rxmt_interval);
1701 return 0;
1705 ospf6_lsupdate_send_interface (struct thread *thread)
1707 struct ospf6_interface *oi;
1708 struct ospf6_header *oh;
1709 struct ospf6_lsupdate *lsupdate;
1710 char *p;
1711 int num;
1712 struct ospf6_lsa *lsa;
1714 oi = (struct ospf6_interface *) THREAD_ARG (thread);
1715 oi->thread_send_lsupdate = (struct thread *) NULL;
1717 if (oi->state <= OSPF6_INTERFACE_WAITING)
1719 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSUPDATE, SEND))
1720 zlog_info ("Quit to send LSUpdate to interface %s state %s",
1721 oi->interface->name, ospf6_interface_state_str[oi->state]);
1722 return 0;
1725 /* if we have nothing to send, return */
1726 if (oi->lsupdate_list->count == 0)
1727 return 0;
1729 memset (sendbuf, 0, iobuflen);
1730 oh = (struct ospf6_header *) sendbuf;
1731 lsupdate = (struct ospf6_lsupdate *)((caddr_t) oh +
1732 sizeof (struct ospf6_header));
1734 p = (char *)((caddr_t) lsupdate + sizeof (struct ospf6_lsupdate));
1735 num = 0;
1737 for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
1738 lsa = ospf6_lsdb_next (lsa))
1740 /* MTU check */
1741 if (p - sendbuf + OSPF6_LSA_SIZE (lsa->header) > oi->ifmtu)
1743 ospf6_lsa_unlock (lsa);
1744 break;
1747 ospf6_lsa_age_update_to_send (lsa, oi->transdelay);
1748 memcpy (p, lsa->header, OSPF6_LSA_SIZE (lsa->header));
1749 p += OSPF6_LSA_SIZE (lsa->header);
1750 num++;
1752 assert (lsa->lock == 2);
1753 ospf6_lsdb_remove (lsa, oi->lsupdate_list);
1756 lsupdate->lsa_number = htonl (num);
1758 oh->type = OSPF6_MESSAGE_TYPE_LSUPDATE;
1759 oh->length = htons (p - sendbuf);
1761 if (oi->state == OSPF6_INTERFACE_DR ||
1762 oi->state == OSPF6_INTERFACE_BDR)
1763 ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh);
1764 else
1765 ospf6_send (oi->linklocal_addr, &alldrouters6, oi, oh);
1767 if (oi->lsupdate_list->count > 0)
1769 oi->thread_send_lsupdate =
1770 thread_add_event (master, ospf6_lsupdate_send_interface, oi, 0);
1773 return 0;
1777 ospf6_lsack_send_neighbor (struct thread *thread)
1779 struct ospf6_neighbor *on;
1780 struct ospf6_header *oh;
1781 char *p;
1782 struct ospf6_lsa *lsa;
1784 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
1785 on->thread_send_lsack = (struct thread *) NULL;
1787 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
1789 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSACK, SEND))
1790 zlog_info ("Quit to send LSAck to neighbor %s state %s",
1791 on->name, ospf6_neighbor_state_str[on->state]);
1792 return 0;
1795 /* if we have nothing to send, return */
1796 if (on->lsack_list->count == 0)
1797 return 0;
1799 memset (sendbuf, 0, iobuflen);
1800 oh = (struct ospf6_header *) sendbuf;
1802 p = (char *)((caddr_t) oh + sizeof (struct ospf6_header));
1804 for (lsa = ospf6_lsdb_head (on->lsack_list); lsa;
1805 lsa = ospf6_lsdb_next (lsa))
1807 /* MTU check */
1808 if (p - sendbuf + sizeof (struct ospf6_lsa_header) > on->ospf6_if->ifmtu)
1810 /* if we run out of packet size/space here,
1811 better to try again soon. */
1812 THREAD_OFF (on->thread_send_lsack);
1813 on->thread_send_lsack =
1814 thread_add_event (master, ospf6_lsack_send_neighbor, on, 0);
1816 ospf6_lsa_unlock (lsa);
1817 break;
1820 ospf6_lsa_age_update_to_send (lsa, on->ospf6_if->transdelay);
1821 memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header));
1822 p += sizeof (struct ospf6_lsa_header);
1824 assert (lsa->lock == 2);
1825 ospf6_lsdb_remove (lsa, on->lsack_list);
1828 oh->type = OSPF6_MESSAGE_TYPE_LSACK;
1829 oh->length = htons (p - sendbuf);
1831 ospf6_send (on->ospf6_if->linklocal_addr, &on->linklocal_addr,
1832 on->ospf6_if, oh);
1833 return 0;
1837 ospf6_lsack_send_interface (struct thread *thread)
1839 struct ospf6_interface *oi;
1840 struct ospf6_header *oh;
1841 char *p;
1842 struct ospf6_lsa *lsa;
1844 oi = (struct ospf6_interface *) THREAD_ARG (thread);
1845 oi->thread_send_lsack = (struct thread *) NULL;
1847 if (oi->state <= OSPF6_INTERFACE_WAITING)
1849 if (IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_LSACK, SEND))
1850 zlog_info ("Quit to send LSAck to interface %s state %s",
1851 oi->interface->name, ospf6_interface_state_str[oi->state]);
1852 return 0;
1855 /* if we have nothing to send, return */
1856 if (oi->lsack_list->count == 0)
1857 return 0;
1859 memset (sendbuf, 0, iobuflen);
1860 oh = (struct ospf6_header *) sendbuf;
1862 p = (char *)((caddr_t) oh + sizeof (struct ospf6_header));
1864 for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
1865 lsa = ospf6_lsdb_next (lsa))
1867 /* MTU check */
1868 if (p - sendbuf + sizeof (struct ospf6_lsa_header) > oi->ifmtu)
1870 /* if we run out of packet size/space here,
1871 better to try again soon. */
1872 THREAD_OFF (oi->thread_send_lsack);
1873 oi->thread_send_lsack =
1874 thread_add_event (master, ospf6_lsack_send_interface, oi, 0);
1876 ospf6_lsa_unlock (lsa);
1877 break;
1880 ospf6_lsa_age_update_to_send (lsa, oi->transdelay);
1881 memcpy (p, lsa->header, sizeof (struct ospf6_lsa_header));
1882 p += sizeof (struct ospf6_lsa_header);
1884 assert (lsa->lock == 2);
1885 ospf6_lsdb_remove (lsa, oi->lsack_list);
1888 oh->type = OSPF6_MESSAGE_TYPE_LSACK;
1889 oh->length = htons (p - sendbuf);
1891 if (oi->state == OSPF6_INTERFACE_DR ||
1892 oi->state == OSPF6_INTERFACE_BDR)
1893 ospf6_send (oi->linklocal_addr, &allspfrouters6, oi, oh);
1894 else
1895 ospf6_send (oi->linklocal_addr, &alldrouters6, oi, oh);
1897 if (oi->thread_send_lsack == NULL && oi->lsack_list->count > 0)
1899 oi->thread_send_lsack =
1900 thread_add_event (master, ospf6_lsack_send_interface, oi, 0);
1903 return 0;
1907 /* Commands */
1908 DEFUN (debug_ospf6_message,
1909 debug_ospf6_message_cmd,
1910 "debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all)",
1911 DEBUG_STR
1912 OSPF6_STR
1913 "Debug OSPFv3 message\n"
1914 "Debug Unknown message\n"
1915 "Debug Hello message\n"
1916 "Debug Database Description message\n"
1917 "Debug Link State Request message\n"
1918 "Debug Link State Update message\n"
1919 "Debug Link State Acknowledgement message\n"
1920 "Debug All message\n"
1923 unsigned char level = 0;
1924 int type = 0;
1925 int i;
1927 assert (argc > 0);
1929 /* check type */
1930 if (! strncmp (argv[0], "u", 1))
1931 type = OSPF6_MESSAGE_TYPE_UNKNOWN;
1932 else if (! strncmp (argv[0], "h", 1))
1933 type = OSPF6_MESSAGE_TYPE_HELLO;
1934 else if (! strncmp (argv[0], "d", 1))
1935 type = OSPF6_MESSAGE_TYPE_DBDESC;
1936 else if (! strncmp (argv[0], "lsr", 3))
1937 type = OSPF6_MESSAGE_TYPE_LSREQ;
1938 else if (! strncmp (argv[0], "lsu", 3))
1939 type = OSPF6_MESSAGE_TYPE_LSUPDATE;
1940 else if (! strncmp (argv[0], "lsa", 3))
1941 type = OSPF6_MESSAGE_TYPE_LSACK;
1942 else if (! strncmp (argv[0], "a", 1))
1943 type = OSPF6_MESSAGE_TYPE_ALL;
1945 if (argc == 1)
1946 level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV;
1947 else if (! strncmp (argv[1], "s", 1))
1948 level = OSPF6_DEBUG_MESSAGE_SEND;
1949 else if (! strncmp (argv[1], "r", 1))
1950 level = OSPF6_DEBUG_MESSAGE_RECV;
1952 if (type == OSPF6_MESSAGE_TYPE_ALL)
1954 for (i = 0; i < 6; i++)
1955 OSPF6_DEBUG_MESSAGE_ON (i, level);
1957 else
1958 OSPF6_DEBUG_MESSAGE_ON (type, level);
1960 return CMD_SUCCESS;
1963 ALIAS (debug_ospf6_message,
1964 debug_ospf6_message_sendrecv_cmd,
1965 "debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all) (send|recv)",
1966 DEBUG_STR
1967 OSPF6_STR
1968 "Debug OSPFv3 message\n"
1969 "Debug Unknown message\n"
1970 "Debug Hello message\n"
1971 "Debug Database Description message\n"
1972 "Debug Link State Request message\n"
1973 "Debug Link State Update message\n"
1974 "Debug Link State Acknowledgement message\n"
1975 "Debug All message\n"
1976 "Debug only sending message\n"
1977 "Debug only receiving message\n"
1981 DEFUN (no_debug_ospf6_message,
1982 no_debug_ospf6_message_cmd,
1983 "no debug ospf6 message (unknown|hello|dbdesc|lsreq|lsupdate|lsack|all)",
1984 NO_STR
1985 DEBUG_STR
1986 OSPF6_STR
1987 "Debug OSPFv3 message\n"
1988 "Debug Unknown message\n"
1989 "Debug Hello message\n"
1990 "Debug Database Description message\n"
1991 "Debug Link State Request message\n"
1992 "Debug Link State Update message\n"
1993 "Debug Link State Acknowledgement message\n"
1994 "Debug All message\n"
1997 unsigned char level = 0;
1998 int type = 0;
1999 int i;
2001 assert (argc > 0);
2003 /* check type */
2004 if (! strncmp (argv[0], "u", 1))
2005 type = OSPF6_MESSAGE_TYPE_UNKNOWN;
2006 else if (! strncmp (argv[0], "h", 1))
2007 type = OSPF6_MESSAGE_TYPE_HELLO;
2008 else if (! strncmp (argv[0], "d", 1))
2009 type = OSPF6_MESSAGE_TYPE_DBDESC;
2010 else if (! strncmp (argv[0], "lsr", 3))
2011 type = OSPF6_MESSAGE_TYPE_LSREQ;
2012 else if (! strncmp (argv[0], "lsu", 3))
2013 type = OSPF6_MESSAGE_TYPE_LSUPDATE;
2014 else if (! strncmp (argv[0], "lsa", 3))
2015 type = OSPF6_MESSAGE_TYPE_LSACK;
2016 else if (! strncmp (argv[0], "a", 1))
2017 type = OSPF6_MESSAGE_TYPE_ALL;
2019 if (argc == 1)
2020 level = OSPF6_DEBUG_MESSAGE_SEND | OSPF6_DEBUG_MESSAGE_RECV;
2021 else if (! strncmp (argv[1], "s", 1))
2022 level = OSPF6_DEBUG_MESSAGE_SEND;
2023 else if (! strncmp (argv[1], "r", 1))
2024 level = OSPF6_DEBUG_MESSAGE_RECV;
2026 if (type == OSPF6_MESSAGE_TYPE_ALL)
2028 for (i = 0; i < 6; i++)
2029 OSPF6_DEBUG_MESSAGE_OFF (i, level);
2031 else
2032 OSPF6_DEBUG_MESSAGE_OFF (type, level);
2034 return CMD_SUCCESS;
2037 ALIAS (no_debug_ospf6_message,
2038 no_debug_ospf6_message_sendrecv_cmd,
2039 "no debug ospf6 message "
2040 "(unknown|hello|dbdesc|lsreq|lsupdate|lsack|all) (send|recv)",
2041 NO_STR
2042 DEBUG_STR
2043 OSPF6_STR
2044 "Debug OSPFv3 message\n"
2045 "Debug Unknown message\n"
2046 "Debug Hello message\n"
2047 "Debug Database Description message\n"
2048 "Debug Link State Request message\n"
2049 "Debug Link State Update message\n"
2050 "Debug Link State Acknowledgement message\n"
2051 "Debug All message\n"
2052 "Debug only sending message\n"
2053 "Debug only receiving message\n"
2057 config_write_ospf6_debug_message (struct vty *vty)
2059 char *type_str[] = {"unknown", "hello", "dbdesc",
2060 "lsreq", "lsupdate", "lsack"};
2061 unsigned char s = 0, r = 0;
2062 int i;
2064 for (i = 0; i < 6; i++)
2066 if (IS_OSPF6_DEBUG_MESSAGE (i, SEND))
2067 s |= 1 << i;
2068 if (IS_OSPF6_DEBUG_MESSAGE (i, RECV))
2069 r |= 1 << i;
2072 if (s == 0x3f && r == 0x3f)
2074 vty_out (vty, "debug ospf6 message all%s", VNL);
2075 return 0;
2078 if (s == 0x3f && r == 0)
2080 vty_out (vty, "debug ospf6 message all send%s", VNL);
2081 return 0;
2083 else if (s == 0 && r == 0x3f)
2085 vty_out (vty, "debug ospf6 message all recv%s", VNL);
2086 return 0;
2089 /* Unknown message is logged by default */
2090 if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, SEND) &&
2091 ! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
2092 vty_out (vty, "no debug ospf6 message unknown%s", VNL);
2093 else if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, SEND))
2094 vty_out (vty, "no debug ospf6 message unknown send%s", VNL);
2095 else if (! IS_OSPF6_DEBUG_MESSAGE (OSPF6_MESSAGE_TYPE_UNKNOWN, RECV))
2096 vty_out (vty, "no debug ospf6 message unknown recv%s", VNL);
2098 for (i = 1; i < 6; i++)
2100 if (IS_OSPF6_DEBUG_MESSAGE (i, SEND) &&
2101 IS_OSPF6_DEBUG_MESSAGE (i, RECV))
2102 vty_out (vty, "debug ospf6 message %s%s", type_str[i], VNL);
2103 else if (IS_OSPF6_DEBUG_MESSAGE (i, SEND))
2104 vty_out (vty, "debug ospf6 message %s send%s", type_str[i],
2105 VNL);
2106 else if (IS_OSPF6_DEBUG_MESSAGE (i, RECV))
2107 vty_out (vty, "debug ospf6 message %s recv%s", type_str[i],
2108 VNL);
2111 return 0;
2114 void
2115 install_element_ospf6_debug_message ()
2117 install_element (ENABLE_NODE, &debug_ospf6_message_cmd);
2118 install_element (ENABLE_NODE, &no_debug_ospf6_message_cmd);
2119 install_element (ENABLE_NODE, &debug_ospf6_message_sendrecv_cmd);
2120 install_element (ENABLE_NODE, &no_debug_ospf6_message_sendrecv_cmd);
2121 install_element (CONFIG_NODE, &debug_ospf6_message_cmd);
2122 install_element (CONFIG_NODE, &no_debug_ospf6_message_cmd);
2123 install_element (CONFIG_NODE, &debug_ospf6_message_sendrecv_cmd);
2124 install_element (CONFIG_NODE, &no_debug_ospf6_message_sendrecv_cmd);