forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathospf_dump.c
2140 lines (1844 loc) · 55.1 KB
/
ospf_dump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* OSPFd dump routine.
* Copyright (C) 1999, 2000 Toshiaki Takada
*
* This file is part of GNU Zebra.
*
* GNU Zebra is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* GNU Zebra is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "lib/bfd.h"
#include "monotime.h"
#include "linklist.h"
#include "thread.h"
#include "prefix.h"
#include "command.h"
#include "stream.h"
#include "log.h"
#include "sockopt.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
#include "ospfd/ospf_ism.h"
#include "ospfd/ospf_asbr.h"
#include "ospfd/ospf_lsa.h"
#include "ospfd/ospf_lsdb.h"
#include "ospfd/ospf_neighbor.h"
#include "ospfd/ospf_nsm.h"
#include "ospfd/ospf_dump.h"
#include "ospfd/ospf_packet.h"
#include "ospfd/ospf_network.h"
#include "ospfd/ospf_dump_clippy.c"
/* Configuration debug option variables. */
unsigned long conf_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
unsigned long conf_debug_ospf_event = 0;
unsigned long conf_debug_ospf_ism = 0;
unsigned long conf_debug_ospf_nsm = 0;
unsigned long conf_debug_ospf_lsa = 0;
unsigned long conf_debug_ospf_zebra = 0;
unsigned long conf_debug_ospf_nssa = 0;
unsigned long conf_debug_ospf_te;
unsigned long conf_debug_ospf_ext = 0;
unsigned long conf_debug_ospf_sr;
unsigned long conf_debug_ospf_ti_lfa;
unsigned long conf_debug_ospf_defaultinfo;
unsigned long conf_debug_ospf_ldp_sync;
unsigned long conf_debug_ospf_gr;
unsigned long conf_debug_ospf_bfd;
unsigned long conf_debug_ospf_client_api;
unsigned long conf_debug_ospf_orr;
/* Enable debug option variables -- valid only session. */
unsigned long term_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
unsigned long term_debug_ospf_event;
unsigned long term_debug_ospf_ism = 0;
unsigned long term_debug_ospf_nsm = 0;
unsigned long term_debug_ospf_lsa = 0;
unsigned long term_debug_ospf_zebra = 0;
unsigned long term_debug_ospf_nssa = 0;
unsigned long term_debug_ospf_te;
unsigned long term_debug_ospf_ext = 0;
unsigned long term_debug_ospf_sr;
unsigned long term_debug_ospf_ti_lfa;
unsigned long term_debug_ospf_defaultinfo;
unsigned long term_debug_ospf_ldp_sync;
unsigned long term_debug_ospf_gr;
unsigned long term_debug_ospf_bfd;
unsigned long term_debug_ospf_client_api;
unsigned long term_debug_ospf_orr;
const char *ospf_redist_string(unsigned int route_type)
{
return (route_type == ZEBRA_ROUTE_MAX) ? "Default"
: zebra_route_string(route_type);
}
#define OSPF_AREA_STRING_MAXLEN 16
const char *ospf_area_name_string(struct ospf_area *area)
{
static char buf[OSPF_AREA_STRING_MAXLEN] = "";
uint32_t area_id;
if (!area)
return "-";
area_id = ntohl(area->area_id.s_addr);
snprintf(buf, sizeof(buf), "%d.%d.%d.%d", (area_id >> 24) & 0xff,
(area_id >> 16) & 0xff, (area_id >> 8) & 0xff, area_id & 0xff);
return buf;
}
#define OSPF_AREA_DESC_STRING_MAXLEN 23
const char *ospf_area_desc_string(struct ospf_area *area)
{
static char buf[OSPF_AREA_DESC_STRING_MAXLEN] = "";
uint8_t type;
if (!area)
return "(incomplete)";
type = area->external_routing;
switch (type) {
case OSPF_AREA_NSSA:
snprintf(buf, sizeof(buf), "%s [NSSA]",
ospf_area_name_string(area));
break;
case OSPF_AREA_STUB:
snprintf(buf, sizeof(buf), "%s [Stub]",
ospf_area_name_string(area));
break;
default:
return ospf_area_name_string(area);
}
return buf;
}
#define OSPF_IF_STRING_MAXLEN 40
/* Display both nbr and ism state of the ospf neighbor.*/
const char *ospf_if_name_string(struct ospf_interface *oi)
{
static char buf[OSPF_IF_STRING_MAXLEN] = "";
uint32_t ifaddr;
if (!oi || !oi->address)
return "inactive";
if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
return oi->ifp->name;
ifaddr = ntohl(oi->address->u.prefix4.s_addr);
snprintf(buf, sizeof(buf), "%s:%d.%d.%d.%d", oi->ifp->name,
(ifaddr >> 24) & 0xff, (ifaddr >> 16) & 0xff,
(ifaddr >> 8) & 0xff, ifaddr & 0xff);
return buf;
}
/* Display only the nbr state.*/
void ospf_nbr_state_message(struct ospf_neighbor *nbr, char *buf, size_t size)
{
snprintf(buf, size, "%s",
lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
}
int ospf_nbr_ism_state(struct ospf_neighbor *nbr)
{
int state;
struct ospf_interface *oi = nbr->oi;
if (IPV4_ADDR_SAME(&DR(oi), &nbr->address.u.prefix4))
state = ISM_DR;
else if (IPV4_ADDR_SAME(&BDR(oi), &nbr->address.u.prefix4))
state = ISM_Backup;
else
state = ISM_DROther;
return state;
}
void ospf_nbr_ism_state_message(struct ospf_neighbor *nbr, char *buf,
size_t size)
{
int state;
struct ospf_interface *oi = nbr->oi;
if (!oi)
return;
/* network type is point-to-point */
if (oi->type == OSPF_IFTYPE_POINTOPOINT) {
snprintf(buf, size, "%s/-",
lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
return;
}
state = ospf_nbr_ism_state(nbr);
snprintf(buf, size, "%s/%s",
lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
lookup_msg(ospf_ism_state_msg, state, NULL));
}
const char *ospf_timeval_dump(struct timeval *t, char *buf, size_t size)
{
/* Making formatted timer strings. */
#define MINUTE_IN_SECONDS 60
#define HOUR_IN_SECONDS (60*MINUTE_IN_SECONDS)
unsigned long w, d, h, m, ms, us;
if (!t)
return "inactive";
w = d = h = m = ms = 0;
memset(buf, 0, size);
us = t->tv_usec;
if (us >= 1000) {
ms = us / 1000;
us %= 1000;
(void)us; /* unused */
}
if (ms >= 1000) {
t->tv_sec += ms / 1000;
ms %= 1000;
}
if (t->tv_sec > ONE_WEEK_SECOND) {
w = t->tv_sec / ONE_WEEK_SECOND;
t->tv_sec -= w * ONE_WEEK_SECOND;
}
if (t->tv_sec > ONE_DAY_SECOND) {
d = t->tv_sec / ONE_DAY_SECOND;
t->tv_sec -= d * ONE_DAY_SECOND;
}
if (t->tv_sec >= HOUR_IN_SECONDS) {
h = t->tv_sec / HOUR_IN_SECONDS;
t->tv_sec -= h * HOUR_IN_SECONDS;
}
if (t->tv_sec >= MINUTE_IN_SECONDS) {
m = t->tv_sec / MINUTE_IN_SECONDS;
t->tv_sec -= m * MINUTE_IN_SECONDS;
}
if (w > 99)
snprintf(buf, size, "%luw%1lud", w, d);
else if (w)
snprintf(buf, size, "%luw%1lud%02luh", w, d, h);
else if (d)
snprintf(buf, size, "%1lud%02luh%02lum", d, h, m);
else if (h)
snprintf(buf, size, "%luh%02lum%02lds", h, m, (long)t->tv_sec);
else if (m)
snprintf(buf, size, "%lum%02lds", m, (long)t->tv_sec);
else if (t->tv_sec > 0 || ms > 0)
snprintf(buf, size, "%ld.%03lus", (long)t->tv_sec, ms);
else
snprintf(buf, size, "%ld usecs", (long)t->tv_usec);
return buf;
}
const char *ospf_timer_dump(struct thread *t, char *buf, size_t size)
{
struct timeval result;
if (!t)
return "inactive";
monotime_until(&t->u.sands, &result);
return ospf_timeval_dump(&result, buf, size);
}
static void ospf_packet_hello_dump(struct stream *s, uint16_t length)
{
struct ospf_hello *hello;
int i, len;
hello = (struct ospf_hello *)stream_pnt(s);
zlog_debug("Hello");
zlog_debug(" NetworkMask %pI4", &hello->network_mask);
zlog_debug(" HelloInterval %d", ntohs(hello->hello_interval));
zlog_debug(" Options %d (%s)", hello->options,
ospf_options_dump(hello->options));
zlog_debug(" RtrPriority %d", hello->priority);
zlog_debug(" RtrDeadInterval %ld",
(unsigned long)ntohl(hello->dead_interval));
zlog_debug(" DRouter %pI4", &hello->d_router);
zlog_debug(" BDRouter %pI4", &hello->bd_router);
len = length - OSPF_HEADER_SIZE - OSPF_HELLO_MIN_SIZE;
zlog_debug(" # Neighbors %d", len / 4);
for (i = 0; len > 0; i++, len -= sizeof(struct in_addr))
zlog_debug(" Neighbor %pI4", &hello->neighbors[i]);
}
static char *ospf_dd_flags_dump(uint8_t flags, char *buf, size_t size)
{
snprintf(buf, size, "%s|%s|%s", (flags & OSPF_DD_FLAG_I) ? "I" : "-",
(flags & OSPF_DD_FLAG_M) ? "M" : "-",
(flags & OSPF_DD_FLAG_MS) ? "MS" : "-");
return buf;
}
static char *ospf_router_lsa_flags_dump(uint8_t flags, char *buf, size_t size)
{
snprintf(buf, size, "%s|%s|%s",
(flags & ROUTER_LSA_VIRTUAL) ? "V" : "-",
(flags & ROUTER_LSA_EXTERNAL) ? "E" : "-",
(flags & ROUTER_LSA_BORDER) ? "B" : "-");
return buf;
}
static void ospf_router_lsa_dump(struct stream *s, uint16_t length)
{
char buf[BUFSIZ];
struct router_lsa *rl;
struct router_link *rlnk;
int i, len, sum;
rl = (struct router_lsa *)stream_pnt(s);
zlog_debug(" Router-LSA");
zlog_debug(" flags %s",
ospf_router_lsa_flags_dump(rl->flags, buf, BUFSIZ));
zlog_debug(" # links %d", ntohs(rl->links));
len = length - OSPF_LSA_HEADER_SIZE - 4;
rlnk = &rl->link[0];
sum = 0;
for (i = 0; sum < len && rlnk; sum += 12, rlnk = &rl->link[++i]) {
zlog_debug(" Link ID %pI4", &rlnk->link_id);
zlog_debug(" Link Data %pI4", &rlnk->link_data);
zlog_debug(" Type %d", (uint8_t)rlnk->type);
zlog_debug(" TOS %d", (uint8_t)rlnk->tos);
zlog_debug(" metric %d", ntohs(rlnk->metric));
}
}
static void ospf_network_lsa_dump(struct stream *s, uint16_t length)
{
struct network_lsa *nl;
int i, cnt;
zlog_debug(" Network-LSA");
nl = (struct network_lsa *)stream_pnt(s);
cnt = (length - (OSPF_LSA_HEADER_SIZE + 4)) / 4;
/*
zlog_debug ("LSA total size %d", ntohs (nl->header.length));
zlog_debug ("Network-LSA size %d",
ntohs (nl->header.length) - OSPF_LSA_HEADER_SIZE);
*/
zlog_debug(" Network Mask %pI4", &nl->mask);
zlog_debug(" # Attached Routers %d", cnt);
for (i = 0; i < cnt; i++)
zlog_debug(" Attached Router %pI4",
&nl->routers[i]);
}
static void ospf_summary_lsa_dump(struct stream *s, uint16_t length)
{
struct summary_lsa *sl;
sl = (struct summary_lsa *)stream_pnt(s);
zlog_debug(" Summary-LSA");
zlog_debug(" Network Mask %pI4", &sl->mask);
zlog_debug(" TOS=%d metric %d", sl->tos, GET_METRIC(sl->metric));
}
static void ospf_as_external_lsa_dump(struct stream *s, uint16_t length)
{
struct as_external_lsa *al;
struct as_route *asr;
int size, sum;
int i;
al = (struct as_external_lsa *)stream_pnt(s);
zlog_debug(" %s", ospf_lsa_type_msg[al->header.type].str);
zlog_debug(" Network Mask %pI4", &al->mask);
size = length - OSPF_LSA_HEADER_SIZE - 4;
asr = &al->e[0];
sum = 0;
for (i = 0; sum < size && asr; sum += 12, asr = &al->e[++i]) {
zlog_debug(" bit %s TOS=%d metric %d",
IS_EXTERNAL_METRIC(asr->tos) ? "E" : "-",
asr->tos & 0x7f, GET_METRIC(asr->metric));
zlog_debug(" Forwarding address %pI4", &asr->fwd_addr);
zlog_debug(" External Route Tag %" ROUTE_TAG_PRI,
ntohl(asr->route_tag));
}
}
static void ospf_lsa_header_list_dump(struct stream *s, uint16_t length)
{
struct lsa_header *lsa;
int len;
zlog_debug(" # LSA Headers %d", length / OSPF_LSA_HEADER_SIZE);
/* LSA Headers. */
len = length;
while (len > 0) {
lsa = (struct lsa_header *)stream_pnt(s);
ospf_lsa_header_dump(lsa);
stream_forward_getp(s, OSPF_LSA_HEADER_SIZE);
len -= OSPF_LSA_HEADER_SIZE;
}
}
static void ospf_packet_db_desc_dump(struct stream *s, uint16_t length)
{
struct ospf_db_desc *dd;
char dd_flags[8];
uint32_t gp;
gp = stream_get_getp(s);
dd = (struct ospf_db_desc *)stream_pnt(s);
zlog_debug("Database Description");
zlog_debug(" Interface MTU %d", ntohs(dd->mtu));
zlog_debug(" Options %d (%s)", dd->options,
ospf_options_dump(dd->options));
zlog_debug(" Flags %d (%s)", dd->flags,
ospf_dd_flags_dump(dd->flags, dd_flags, sizeof(dd_flags)));
zlog_debug(" Sequence Number 0x%08lx",
(unsigned long)ntohl(dd->dd_seqnum));
length -= OSPF_HEADER_SIZE + OSPF_DB_DESC_MIN_SIZE;
stream_forward_getp(s, OSPF_DB_DESC_MIN_SIZE);
ospf_lsa_header_list_dump(s, length);
stream_set_getp(s, gp);
}
static void ospf_packet_ls_req_dump(struct stream *s, uint16_t length)
{
uint32_t sp;
uint32_t ls_type;
struct in_addr ls_id;
struct in_addr adv_router;
int sum;
sp = stream_get_getp(s);
length -= OSPF_HEADER_SIZE;
zlog_debug("Link State Request");
zlog_debug(" # Requests %d", length / 12);
sum = 0;
for (; sum < length; sum += 12) {
ls_type = stream_getl(s);
ls_id.s_addr = stream_get_ipv4(s);
adv_router.s_addr = stream_get_ipv4(s);
zlog_debug(" LS type %d", ls_type);
zlog_debug(" Link State ID %pI4", &ls_id);
zlog_debug(" Advertising Router %pI4", &adv_router);
}
stream_set_getp(s, sp);
}
static void ospf_packet_ls_upd_dump(struct stream *s, uint16_t length)
{
uint32_t sp;
struct lsa_header *lsa;
int lsa_len, len;
uint32_t count;
len = length - OSPF_HEADER_SIZE;
sp = stream_get_getp(s);
count = stream_getl(s);
len -= 4;
zlog_debug("Link State Update");
zlog_debug(" # LSAs %d", count);
while (len > 0 && count > 0) {
if ((uint16_t)len < OSPF_LSA_HEADER_SIZE || len % 4 != 0) {
zlog_debug(" Remaining %d bytes; Incorrect length.",
len);
break;
}
lsa = (struct lsa_header *)stream_pnt(s);
lsa_len = ntohs(lsa->length);
ospf_lsa_header_dump(lsa);
/* Check that LSA length is valid */
if (lsa_len > len || lsa_len % 4 != 0) {
zlog_debug(" LSA length %d is incorrect!", lsa_len);
break;
}
switch (lsa->type) {
case OSPF_ROUTER_LSA:
ospf_router_lsa_dump(s, lsa_len);
break;
case OSPF_NETWORK_LSA:
ospf_network_lsa_dump(s, lsa_len);
break;
case OSPF_SUMMARY_LSA:
case OSPF_ASBR_SUMMARY_LSA:
ospf_summary_lsa_dump(s, lsa_len);
break;
case OSPF_AS_EXTERNAL_LSA:
ospf_as_external_lsa_dump(s, lsa_len);
break;
case OSPF_AS_NSSA_LSA:
ospf_as_external_lsa_dump(s, lsa_len);
break;
case OSPF_OPAQUE_LINK_LSA:
case OSPF_OPAQUE_AREA_LSA:
case OSPF_OPAQUE_AS_LSA:
ospf_opaque_lsa_dump(s, lsa_len);
break;
default:
break;
}
stream_forward_getp(s, lsa_len);
len -= lsa_len;
count--;
}
stream_set_getp(s, sp);
}
static void ospf_packet_ls_ack_dump(struct stream *s, uint16_t length)
{
uint32_t sp;
length -= OSPF_HEADER_SIZE;
sp = stream_get_getp(s);
zlog_debug("Link State Acknowledgment");
ospf_lsa_header_list_dump(s, length);
stream_set_getp(s, sp);
}
static void ospf_header_dump(struct ospf_header *ospfh)
{
char buf[9];
uint16_t auth_type = ntohs(ospfh->auth_type);
zlog_debug("Header");
zlog_debug(" Version %d", ospfh->version);
zlog_debug(" Type %d (%s)", ospfh->type,
lookup_msg(ospf_packet_type_str, ospfh->type, NULL));
zlog_debug(" Packet Len %d", ntohs(ospfh->length));
zlog_debug(" Router ID %pI4", &ospfh->router_id);
zlog_debug(" Area ID %pI4", &ospfh->area_id);
zlog_debug(" Checksum 0x%x", ntohs(ospfh->checksum));
zlog_debug(" AuType %s",
lookup_msg(ospf_auth_type_str, auth_type, NULL));
switch (auth_type) {
case OSPF_AUTH_NULL:
break;
case OSPF_AUTH_SIMPLE:
strlcpy(buf, (char *)ospfh->u.auth_data, sizeof(buf));
zlog_debug(" Simple Password %s", buf);
break;
case OSPF_AUTH_CRYPTOGRAPHIC:
zlog_debug(" Cryptographic Authentication");
zlog_debug(" Key ID %d", ospfh->u.crypt.key_id);
zlog_debug(" Auth Data Len %d", ospfh->u.crypt.auth_data_len);
zlog_debug(" Sequence number %ld",
(unsigned long)ntohl(ospfh->u.crypt.crypt_seqnum));
break;
default:
zlog_debug("* This is not supported authentication type");
break;
}
}
void ospf_packet_dump(struct stream *s)
{
struct ospf_header *ospfh;
unsigned long gp;
/* Preserve pointer. */
gp = stream_get_getp(s);
/* OSPF Header dump. */
ospfh = (struct ospf_header *)stream_pnt(s);
/* Until detail flag is set, return. */
if (!(term_debug_ospf_packet[ospfh->type - 1] & OSPF_DEBUG_DETAIL))
return;
/* Show OSPF header detail. */
ospf_header_dump(ospfh);
stream_forward_getp(s, OSPF_HEADER_SIZE);
switch (ospfh->type) {
case OSPF_MSG_HELLO:
ospf_packet_hello_dump(s, ntohs(ospfh->length));
break;
case OSPF_MSG_DB_DESC:
ospf_packet_db_desc_dump(s, ntohs(ospfh->length));
break;
case OSPF_MSG_LS_REQ:
ospf_packet_ls_req_dump(s, ntohs(ospfh->length));
break;
case OSPF_MSG_LS_UPD:
ospf_packet_ls_upd_dump(s, ntohs(ospfh->length));
break;
case OSPF_MSG_LS_ACK:
ospf_packet_ls_ack_dump(s, ntohs(ospfh->length));
break;
default:
break;
}
stream_set_getp(s, gp);
}
DEFPY (debug_ospf_packet,
debug_ospf_packet_cmd,
"[no$no] debug ospf [(1-65535)$inst] packet <hello|dd|ls-request|ls-update|ls-ack|all>$packet [<send$send [detail$detail]|recv$recv [detail$detail]|detail$detail>]",
NO_STR
DEBUG_STR
OSPF_STR
"Instance ID\n"
"OSPF packets\n"
"OSPF Hello\n"
"OSPF Database Description\n"
"OSPF Link State Request\n"
"OSPF Link State Update\n"
"OSPF Link State Acknowledgment\n"
"OSPF all packets\n"
"Packet sent\n"
"Detail Information\n"
"Packet received\n"
"Detail Information\n"
"Detail Information\n")
{
int type = 0;
int flag = 0;
int i;
if (inst && inst != ospf_instance)
return CMD_NOT_MY_INSTANCE;
/* Check packet type. */
if (strmatch(packet, "hello"))
type = OSPF_DEBUG_HELLO;
else if (strmatch(packet, "dd"))
type = OSPF_DEBUG_DB_DESC;
else if (strmatch(packet, "ls-request"))
type = OSPF_DEBUG_LS_REQ;
else if (strmatch(packet, "ls-update"))
type = OSPF_DEBUG_LS_UPD;
else if (strmatch(packet, "ls-ack"))
type = OSPF_DEBUG_LS_ACK;
else if (strmatch(packet, "all"))
type = OSPF_DEBUG_ALL;
/* Cases:
* (none) = send + recv
* detail = send + recv + detail
* recv = recv
* send = send
* recv detail = recv + detail
* send detail = send + detail
*/
if (!send && !recv) {
flag |= OSPF_DEBUG_SEND;
flag |= OSPF_DEBUG_RECV;
}
flag |= (send) ? OSPF_DEBUG_SEND : 0;
flag |= (recv) ? OSPF_DEBUG_RECV : 0;
flag |= (detail) ? OSPF_DEBUG_DETAIL : 0;
for (i = 0; i < 5; i++)
if (type & (0x01 << i)) {
if (vty->node == CONFIG_NODE) {
if (no)
DEBUG_PACKET_OFF(i, flag);
else
DEBUG_PACKET_ON(i, flag);
} else {
if (no)
TERM_DEBUG_PACKET_OFF(i, flag);
else
TERM_DEBUG_PACKET_ON(i, flag);
}
}
#ifdef DEBUG
/*
for (i = 0; i < 5; i++)
zlog_debug ("flag[%d] = %d", i, ospf_debug_packet[i]);
*/
#endif /* DEBUG */
return CMD_SUCCESS;
}
DEFUN (debug_ospf_ism,
debug_ospf_ism_cmd,
"debug ospf [(1-65535)] ism [<status|events|timers>]",
DEBUG_STR
OSPF_STR
"Instance ID\n"
"OSPF Interface State Machine\n"
"ISM Status Information\n"
"ISM Event Information\n"
"ISM TImer Information\n")
{
int inst = (argv[2]->type == RANGE_TKN);
char *dbgparam = (argc == 4 + inst) ? argv[argc - 1]->text : NULL;
if (inst) // user passed instance ID
{
if (inst != ospf_instance)
return CMD_NOT_MY_INSTANCE;
}
if (vty->node == CONFIG_NODE) {
if (!dbgparam)
DEBUG_ON(ism, ISM);
else {
if (strmatch(dbgparam, "status"))
DEBUG_ON(ism, ISM_STATUS);
else if (strmatch(dbgparam, "events"))
DEBUG_ON(ism, ISM_EVENTS);
else if (strmatch(dbgparam, "timers"))
DEBUG_ON(ism, ISM_TIMERS);
}
return CMD_SUCCESS;
}
/* ENABLE_NODE. */
if (!dbgparam)
TERM_DEBUG_ON(ism, ISM);
else {
if (strmatch(dbgparam, "status"))
TERM_DEBUG_ON(ism, ISM_STATUS);
else if (strmatch(dbgparam, "events"))
TERM_DEBUG_ON(ism, ISM_EVENTS);
else if (strmatch(dbgparam, "timers"))
TERM_DEBUG_ON(ism, ISM_TIMERS);
}
return CMD_SUCCESS;
}
DEFUN (no_debug_ospf_ism,
no_debug_ospf_ism_cmd,
"no debug ospf [(1-65535)] ism [<status|events|timers>]",
NO_STR
DEBUG_STR
OSPF_STR
"Instance ID\n"
"OSPF Interface State Machine\n"
"ISM Status Information\n"
"ISM Event Information\n"
"ISM TImer Information\n")
{
int inst = (argv[3]->type == RANGE_TKN);
char *dbgparam = (argc == 5 + inst) ? argv[argc - 1]->text : NULL;
if (inst) // user passed instance ID
{
if (inst != ospf_instance)
return CMD_NOT_MY_INSTANCE;
}
if (vty->node == CONFIG_NODE) {
if (!dbgparam)
DEBUG_OFF(ism, ISM);
else {
if (strmatch(dbgparam, "status"))
DEBUG_OFF(ism, ISM_STATUS);
else if (strmatch(dbgparam, "events"))
DEBUG_OFF(ism, ISM_EVENTS);
else if (strmatch(dbgparam, "timers"))
DEBUG_OFF(ism, ISM_TIMERS);
}
return CMD_SUCCESS;
}
/* ENABLE_NODE. */
if (!dbgparam)
TERM_DEBUG_OFF(ism, ISM);
else {
if (strmatch(dbgparam, "status"))
TERM_DEBUG_OFF(ism, ISM_STATUS);
else if (strmatch(dbgparam, "events"))
TERM_DEBUG_OFF(ism, ISM_EVENTS);
else if (strmatch(dbgparam, "timers"))
TERM_DEBUG_OFF(ism, ISM_TIMERS);
}
return CMD_SUCCESS;
}
static int debug_ospf_nsm_common(struct vty *vty, int arg_base, int argc,
struct cmd_token **argv)
{
if (vty->node == CONFIG_NODE) {
if (argc == arg_base + 0)
DEBUG_ON(nsm, NSM);
else if (argc == arg_base + 1) {
if (strmatch(argv[arg_base]->text, "status"))
DEBUG_ON(nsm, NSM_STATUS);
else if (strmatch(argv[arg_base]->text, "events"))
DEBUG_ON(nsm, NSM_EVENTS);
else if (strmatch(argv[arg_base]->text, "timers"))
DEBUG_ON(nsm, NSM_TIMERS);
}
return CMD_SUCCESS;
}
/* ENABLE_NODE. */
if (argc == arg_base + 0)
TERM_DEBUG_ON(nsm, NSM);
else if (argc == arg_base + 1) {
if (strmatch(argv[arg_base]->text, "status"))
TERM_DEBUG_ON(nsm, NSM_STATUS);
else if (strmatch(argv[arg_base]->text, "events"))
TERM_DEBUG_ON(nsm, NSM_EVENTS);
else if (strmatch(argv[arg_base]->text, "timers"))
TERM_DEBUG_ON(nsm, NSM_TIMERS);
}
return CMD_SUCCESS;
}
DEFUN (debug_ospf_nsm,
debug_ospf_nsm_cmd,
"debug ospf nsm [<status|events|timers>]",
DEBUG_STR
OSPF_STR
"OSPF Neighbor State Machine\n"
"NSM Status Information\n"
"NSM Event Information\n"
"NSM Timer Information\n")
{
return debug_ospf_nsm_common(vty, 3, argc, argv);
}
DEFUN (debug_ospf_instance_nsm,
debug_ospf_instance_nsm_cmd,
"debug ospf (1-65535) nsm [<status|events|timers>]",
DEBUG_STR
OSPF_STR
"Instance ID\n"
"OSPF Neighbor State Machine\n"
"NSM Status Information\n"
"NSM Event Information\n"
"NSM Timer Information\n")
{
int idx_number = 2;
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
return debug_ospf_nsm_common(vty, 4, argc, argv);
}
static int no_debug_ospf_nsm_common(struct vty *vty, int arg_base, int argc,
struct cmd_token **argv)
{
/* XXX qlyoung */
if (vty->node == CONFIG_NODE) {
if (argc == arg_base + 0)
DEBUG_OFF(nsm, NSM);
else if (argc == arg_base + 1) {
if (strmatch(argv[arg_base]->text, "status"))
DEBUG_OFF(nsm, NSM_STATUS);
else if (strmatch(argv[arg_base]->text, "events"))
DEBUG_OFF(nsm, NSM_EVENTS);
else if (strmatch(argv[arg_base]->text, "timers"))
DEBUG_OFF(nsm, NSM_TIMERS);
}
return CMD_SUCCESS;
}
/* ENABLE_NODE. */
if (argc == arg_base + 0)
TERM_DEBUG_OFF(nsm, NSM);
else if (argc == arg_base + 1) {
if (strmatch(argv[arg_base]->text, "status"))
TERM_DEBUG_OFF(nsm, NSM_STATUS);
else if (strmatch(argv[arg_base]->text, "events"))
TERM_DEBUG_OFF(nsm, NSM_EVENTS);
else if (strmatch(argv[arg_base]->text, "timers"))
TERM_DEBUG_OFF(nsm, NSM_TIMERS);
}
return CMD_SUCCESS;
}
DEFUN (no_debug_ospf_nsm,
no_debug_ospf_nsm_cmd,
"no debug ospf nsm [<status|events|timers>]",
NO_STR
DEBUG_STR
OSPF_STR
"OSPF Neighbor State Machine\n"
"NSM Status Information\n"
"NSM Event Information\n"
"NSM Timer Information\n")
{
return no_debug_ospf_nsm_common(vty, 4, argc, argv);
}
DEFUN (no_debug_ospf_instance_nsm,
no_debug_ospf_instance_nsm_cmd,
"no debug ospf (1-65535) nsm [<status|events|timers>]",
NO_STR
DEBUG_STR
OSPF_STR
"Instance ID\n"
"OSPF Neighbor State Machine\n"
"NSM Status Information\n"
"NSM Event Information\n"
"NSM Timer Information\n")
{
int idx_number = 3;
unsigned short instance = 0;
instance = strtoul(argv[idx_number]->arg, NULL, 10);
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
return no_debug_ospf_nsm_common(vty, 5, argc, argv);
}
static int debug_ospf_lsa_common(struct vty *vty, int arg_base, int argc,
struct cmd_token **argv)
{
if (vty->node == CONFIG_NODE) {
if (argc == arg_base + 0)
DEBUG_ON(lsa, LSA);
else if (argc == arg_base + 1) {
if (strmatch(argv[arg_base]->text, "generate"))
DEBUG_ON(lsa, LSA_GENERATE);
else if (strmatch(argv[arg_base]->text, "flooding"))
DEBUG_ON(lsa, LSA_FLOODING);
else if (strmatch(argv[arg_base]->text, "install"))
DEBUG_ON(lsa, LSA_INSTALL);
else if (strmatch(argv[arg_base]->text, "refresh"))
DEBUG_ON(lsa, LSA_REFRESH);
else if (strmatch(argv[arg_base]->text, "aggregate"))
DEBUG_ON(lsa, EXTNL_LSA_AGGR);
}
return CMD_SUCCESS;
}
/* ENABLE_NODE. */
if (argc == arg_base + 0)
TERM_DEBUG_ON(lsa, LSA);
else if (argc == arg_base + 1) {
if (strmatch(argv[arg_base]->text, "generate"))
TERM_DEBUG_ON(lsa, LSA_GENERATE);
else if (strmatch(argv[arg_base]->text, "flooding"))
TERM_DEBUG_ON(lsa, LSA_FLOODING);
else if (strmatch(argv[arg_base]->text, "install"))
TERM_DEBUG_ON(lsa, LSA_INSTALL);
else if (strmatch(argv[arg_base]->text, "refresh"))
TERM_DEBUG_ON(lsa, LSA_REFRESH);
else if (strmatch(argv[arg_base]->text, "aggregate"))
TERM_DEBUG_ON(lsa, EXTNL_LSA_AGGR);
}
return CMD_SUCCESS;
}
DEFUN (debug_ospf_lsa,
debug_ospf_lsa_cmd,
"debug ospf lsa [<generate|flooding|install|refresh|aggregate>]",
DEBUG_STR
OSPF_STR