forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbgp_debug.c
2802 lines (2441 loc) · 74 KB
/
bgp_debug.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
// SPDX-License-Identifier: GPL-2.0-or-later
/* BGP-4, BGP-4+ packet debug routine
* Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
*/
#include <zebra.h>
#include "lib/bfd.h"
#include "lib/printfrr.h"
#include "prefix.h"
#include "linklist.h"
#include "stream.h"
#include "command.h"
#include "log.h"
#include "sockunion.h"
#include "memory.h"
#include "queue.h"
#include "filter.h"
#include "hook.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_aspath.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_debug.h"
#include "bgpd/bgp_community.h"
#include "bgpd/bgp_lcommunity.h"
#include "bgpd/bgp_updgrp.h"
#include "bgpd/bgp_mplsvpn.h"
#include "bgpd/bgp_ecommunity.h"
#include "bgpd/bgp_label.h"
#include "bgpd/bgp_evpn.h"
#include "bgpd/bgp_evpn_private.h"
#include "bgpd/bgp_evpn_vty.h"
#include "bgpd/bgp_vty.h"
#include "bgpd/bgp_flowspec.h"
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_debug_clippy.c"
DEFINE_HOOK(bgp_hook_config_write_debug, (struct vty *vty, bool running),
(vty, running));
unsigned long conf_bgp_debug_as4;
unsigned long conf_bgp_debug_neighbor_events;
unsigned long conf_bgp_debug_events;
unsigned long conf_bgp_debug_packet;
unsigned long conf_bgp_debug_filter;
unsigned long conf_bgp_debug_keepalive;
unsigned long conf_bgp_debug_update;
unsigned long conf_bgp_debug_bestpath;
unsigned long conf_bgp_debug_zebra;
unsigned long conf_bgp_debug_nht;
unsigned long conf_bgp_debug_update_groups;
unsigned long conf_bgp_debug_vpn;
unsigned long conf_bgp_debug_flowspec;
unsigned long conf_bgp_debug_labelpool;
unsigned long conf_bgp_debug_pbr;
unsigned long conf_bgp_debug_graceful_restart;
unsigned long conf_bgp_debug_evpn_mh;
unsigned long conf_bgp_debug_bfd;
unsigned long conf_bgp_debug_cond_adv;
unsigned long term_bgp_debug_as4;
unsigned long term_bgp_debug_neighbor_events;
unsigned long term_bgp_debug_events;
unsigned long term_bgp_debug_packet;
unsigned long term_bgp_debug_filter;
unsigned long term_bgp_debug_keepalive;
unsigned long term_bgp_debug_update;
unsigned long term_bgp_debug_bestpath;
unsigned long term_bgp_debug_zebra;
unsigned long term_bgp_debug_nht;
unsigned long term_bgp_debug_update_groups;
unsigned long term_bgp_debug_vpn;
unsigned long term_bgp_debug_flowspec;
unsigned long term_bgp_debug_labelpool;
unsigned long term_bgp_debug_pbr;
unsigned long term_bgp_debug_graceful_restart;
unsigned long term_bgp_debug_evpn_mh;
unsigned long term_bgp_debug_bfd;
unsigned long term_bgp_debug_cond_adv;
struct list *bgp_debug_neighbor_events_peers = NULL;
struct list *bgp_debug_keepalive_peers = NULL;
struct list *bgp_debug_update_out_peers = NULL;
struct list *bgp_debug_update_in_peers = NULL;
struct list *bgp_debug_update_prefixes = NULL;
struct list *bgp_debug_bestpath_prefixes = NULL;
struct list *bgp_debug_zebra_prefixes = NULL;
/* messages for BGP-4 status */
const struct message bgp_status_msg[] = {{Idle, "Idle"},
{Connect, "Connect"},
{Active, "Active"},
{OpenSent, "OpenSent"},
{OpenConfirm, "OpenConfirm"},
{Established, "Established"},
{Clearing, "Clearing"},
{Deleted, "Deleted"},
{0}};
/* BGP message type string. */
const char *const bgp_type_str[] = {NULL, "OPEN", "UPDATE",
"NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
"CAPABILITY"};
/* message for BGP-4 Notify */
static const struct message bgp_notify_msg[] = {
{BGP_NOTIFY_HEADER_ERR, "Message Header Error"},
{BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"},
{BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"},
{BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"},
{BGP_NOTIFY_FSM_ERR, "Neighbor Events Error"},
{BGP_NOTIFY_CEASE, "Cease"},
{BGP_NOTIFY_ROUTE_REFRESH_ERR, "ROUTE-REFRESH Message Error"},
{BGP_NOTIFY_SEND_HOLD_ERR, "Send Hold Timer Expired"},
{0}};
static const struct message bgp_notify_head_msg[] = {
{BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
{BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
{BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"},
{0}};
static const struct message bgp_notify_open_msg[] = {
{BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
{BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number"},
{BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"},
{BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"},
{BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"},
{BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
{BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
{BGP_NOTIFY_OPEN_ROLE_MISMATCH, "/Role Mismatch"},
{0}};
static const struct message bgp_notify_update_msg[] = {
{BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
{BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"},
{BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"},
{BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"},
{BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"},
{BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"},
{BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"},
{BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"},
{BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
{BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
{BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
{0}};
static const struct message bgp_notify_cease_msg[] = {
{BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
{BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"},
{BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administrative Shutdown"},
{BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer De-configured"},
{BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administrative Reset"},
{BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"},
{BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
{BGP_NOTIFY_CEASE_COLLISION_RESOLUTION,
"/Connection Collision Resolution"},
{BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resources"},
{BGP_NOTIFY_CEASE_HARD_RESET, "/Hard Reset"},
{BGP_NOTIFY_CEASE_BFD_DOWN, "/BFD Down"},
{0}};
static const struct message bgp_notify_route_refresh_msg[] = {
{BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
{BGP_NOTIFY_ROUTE_REFRESH_INVALID_MSG_LEN, "/Invalid Message Length"},
{0}};
static const struct message bgp_notify_fsm_msg[] = {
{BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC, "/Unspecific"},
{BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT,
"/Receive Unexpected Message in OpenSent State"},
{BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM,
"/Receive Unexpected Message in OpenConfirm State"},
{BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED,
"/Receive Unexpected Message in Established State"},
{0}};
/* Origin strings. */
const char *const bgp_origin_str[] = {"i", "e", "?"};
const char *const bgp_origin_long_str[] = {"IGP", "EGP", "incomplete"};
static void bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc,
struct prefix *p);
/* Given a string return a pointer the corresponding peer structure */
static struct peer *bgp_find_peer(struct vty *vty, const char *peer_str)
{
struct bgp *bgp = VTY_GET_CONTEXT(bgp);
int ret;
union sockunion su;
struct peer *peer;
if (!bgp) {
return NULL;
}
ret = str2sockunion(peer_str, &su);
/* 'swpX' string */
if (ret < 0) {
peer = peer_lookup_by_conf_if(bgp, peer_str);
if (!peer)
peer = peer_lookup_by_hostname(bgp, peer_str);
return peer;
} else
return peer_lookup(bgp, &su);
}
static void bgp_debug_list_free(struct list *list)
{
struct bgp_debug_filter *filter;
struct listnode *node, *nnode;
if (list)
for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
listnode_delete(list, filter);
prefix_free(&filter->p);
XFREE(MTYPE_BGP_DEBUG_STR, filter->host);
XFREE(MTYPE_BGP_DEBUG_STR, filter->plist_name);
XFREE(MTYPE_BGP_DEBUG_FILTER, filter);
}
}
/*
* Print the desc along with a list of peers/prefixes this debug is
* enabled for
*/
static void bgp_debug_list_print(struct vty *vty, const char *desc,
struct list *list)
{
struct bgp_debug_filter *filter;
struct listnode *node, *nnode;
vty_out(vty, "%s", desc);
if (list && !list_isempty(list)) {
vty_out(vty, " for:\n");
for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
if (filter->host)
vty_out(vty, " %s", filter->host);
if (filter->plist_name)
vty_out(vty, " with prefix-list %s",
filter->plist_name);
if (filter->p && filter->p->family == AF_EVPN)
bgp_debug_print_evpn_prefix(vty, "", filter->p);
else if (filter->p)
vty_out(vty, " %pFX", filter->p);
vty_out(vty, "\n");
}
}
vty_out(vty, "\n");
}
/*
* Print the command to enable the debug for each peer/prefix this debug is
* enabled for
*/
static int bgp_debug_list_conf_print(struct vty *vty, const char *desc,
struct list *list)
{
struct bgp_debug_filter *filter;
struct listnode *node, *nnode;
int write = 0;
if (list && !list_isempty(list)) {
for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
if (filter->host && filter->plist_name) {
vty_out(vty, "%s %s prefix-list %s\n", desc,
filter->host, filter->plist_name);
write++;
} else if (filter->host) {
vty_out(vty, "%s %s\n", desc, filter->host);
write++;
}
if (filter->p && filter->p->family == AF_EVPN) {
bgp_debug_print_evpn_prefix(vty, desc,
filter->p);
write++;
} else if (filter->p) {
vty_out(vty, "%s %pFX\n", desc, filter->p);
write++;
}
}
}
if (!write) {
vty_out(vty, "%s\n", desc);
write++;
}
return write;
}
static void bgp_debug_list_add_entry(struct list *list, const char *host,
const struct prefix *p,
const char *plist_name)
{
struct bgp_debug_filter *filter;
filter = XCALLOC(MTYPE_BGP_DEBUG_FILTER,
sizeof(struct bgp_debug_filter));
if (host) {
filter->host = XSTRDUP(MTYPE_BGP_DEBUG_STR, host);
filter->plist_name = NULL;
filter->plist_v4 = NULL;
filter->plist_v6 = NULL;
filter->p = NULL;
} else if (p) {
filter->host = NULL;
filter->plist_name = NULL;
filter->plist_v4 = NULL;
filter->plist_v6 = NULL;
filter->p = prefix_new();
prefix_copy(filter->p, p);
}
if (plist_name) {
filter->plist_name = XSTRDUP(MTYPE_BGP_DEBUG_STR, plist_name);
filter->plist_v4 = prefix_list_lookup(AFI_IP,
filter->plist_name);
filter->plist_v6 = prefix_list_lookup(AFI_IP6,
filter->plist_name);
}
listnode_add(list, filter);
}
static bool bgp_debug_list_remove_entry(struct list *list, const char *host,
const struct prefix *p)
{
struct bgp_debug_filter *filter;
struct listnode *node, *nnode;
for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
if (host && strcmp(filter->host, host) == 0) {
listnode_delete(list, filter);
XFREE(MTYPE_BGP_DEBUG_STR, filter->host);
XFREE(MTYPE_BGP_DEBUG_STR, filter->plist_name);
XFREE(MTYPE_BGP_DEBUG_FILTER, filter);
return true;
} else if (p && filter->p->prefixlen == p->prefixlen
&& prefix_match(filter->p, p)) {
listnode_delete(list, filter);
prefix_free(&filter->p);
XFREE(MTYPE_BGP_DEBUG_FILTER, filter);
return true;
}
}
return false;
}
static bool bgp_debug_list_has_entry(struct list *list, const char *host,
const struct prefix *p,
const char *plist_name)
{
struct bgp_debug_filter *filter;
struct listnode *node, *nnode;
for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
if (host && plist_name) {
if (strmatch(filter->host, host) && filter->plist_name &&
strmatch(filter->plist_name, plist_name))
return true;
} else if (host) {
if (strmatch(filter->host, host))
return true;
} else if (p) {
if (filter->p->prefixlen == p->prefixlen
&& prefix_match(filter->p, p)) {
return true;
}
}
}
return false;
}
bool bgp_debug_peer_updout_enabled(char *host)
{
return (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host, NULL,
NULL));
}
/* Dump attribute. */
bool bgp_dump_attr(struct attr *attr, char *buf, size_t size)
{
if (!attr)
return false;
buf[0] = '\0';
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)))
snprintfrr(buf, size, "nexthop %pI4", &attr->nexthop);
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN)))
snprintf(buf + strlen(buf), size - strlen(buf), ", origin %s",
bgp_origin_str[attr->origin]);
/* Add MP case. */
if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL
|| attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
snprintfrr(buf + strlen(buf), size - strlen(buf),
", mp_nexthop %pI6", &attr->mp_nexthop_global);
if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
snprintfrr(buf + strlen(buf), size - strlen(buf), "(%pI6)",
&attr->mp_nexthop_local);
if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4)
snprintfrr(buf, size, "nexthop %pI4", &attr->nexthop);
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)))
snprintf(buf + strlen(buf), size - strlen(buf),
", localpref %u", attr->local_pref);
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP)))
snprintf(buf + strlen(buf), size - strlen(buf),
", aigp-metric %" PRIu64,
(unsigned long long)bgp_attr_get_aigp_metric(attr));
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)))
snprintf(buf + strlen(buf), size - strlen(buf), ", metric %u",
attr->med);
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)))
snprintf(buf + strlen(buf), size - strlen(buf),
", community %s",
community_str(bgp_attr_get_community(attr), false,
true));
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)))
snprintf(buf + strlen(buf), size - strlen(buf),
", large-community %s",
lcommunity_str(bgp_attr_get_lcommunity(attr), false,
true));
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
snprintf(buf + strlen(buf), size - strlen(buf),
", extcommunity %s",
ecommunity_str(bgp_attr_get_ecommunity(attr)));
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)))
snprintf(buf + strlen(buf), size - strlen(buf),
", atomic-aggregate");
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)))
snprintfrr(buf + strlen(buf), size - strlen(buf),
", aggregated by %u %pI4", attr->aggregator_as,
&attr->aggregator_addr);
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)))
snprintfrr(buf + strlen(buf), size - strlen(buf),
", originator %pI4", &attr->originator_id);
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) {
struct cluster_list *cluster;
int i;
snprintf(buf + strlen(buf), size - strlen(buf),
", clusterlist");
cluster = bgp_attr_get_cluster(attr);
for (i = 0; i < cluster->length / 4; i++)
snprintfrr(buf + strlen(buf), size - strlen(buf),
" %pI4", &cluster->list[i]);
}
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL)))
snprintf(buf + strlen(buf), size - strlen(buf),
", pmsi tnltype %u", bgp_attr_get_pmsi_tnl_type(attr));
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)))
snprintf(buf + strlen(buf), size - strlen(buf), ", path %s",
aspath_print(attr->aspath));
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID))) {
if (attr->label_index != BGP_INVALID_LABEL_INDEX)
snprintf(buf + strlen(buf), size - strlen(buf),
", label-index %u", attr->label_index);
}
if (strlen(buf) > 1)
return true;
else
return false;
}
const char *bgp_notify_code_str(char code)
{
return lookup_msg(bgp_notify_msg, code, "Unrecognized Error Code");
}
const char *bgp_notify_subcode_str(char code, char subcode)
{
switch (code) {
case BGP_NOTIFY_HEADER_ERR:
return lookup_msg(bgp_notify_head_msg, subcode,
"Unrecognized Error Subcode");
case BGP_NOTIFY_OPEN_ERR:
return lookup_msg(bgp_notify_open_msg, subcode,
"Unrecognized Error Subcode");
case BGP_NOTIFY_UPDATE_ERR:
return lookup_msg(bgp_notify_update_msg, subcode,
"Unrecognized Error Subcode");
case BGP_NOTIFY_HOLD_ERR:
case BGP_NOTIFY_SEND_HOLD_ERR:
break;
case BGP_NOTIFY_FSM_ERR:
return lookup_msg(bgp_notify_fsm_msg, subcode,
"Unrecognized Error Subcode");
case BGP_NOTIFY_CEASE:
return lookup_msg(bgp_notify_cease_msg, subcode,
"Unrecognized Error Subcode");
case BGP_NOTIFY_ROUTE_REFRESH_ERR:
return lookup_msg(bgp_notify_route_refresh_msg, subcode,
"Unrecognized Error Subcode");
}
return "";
}
/* extract notify admin reason if correctly present */
const char *bgp_notify_admin_message(char *buf, size_t bufsz, uint8_t *data,
size_t datalen)
{
memset(buf, 0, bufsz);
if (!data || datalen < 1)
return buf;
uint8_t len = data[0];
if (!len || len > datalen - 1)
return buf;
return zlog_sanitize(buf, bufsz, data + 1, len);
}
/* dump notify packet */
void bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
const char *direct, bool hard_reset)
{
const char *subcode_str;
const char *code_str;
const char *msg_str = NULL;
char msg_buf[1024];
if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)
|| CHECK_FLAG(peer->bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) {
code_str = bgp_notify_code_str(bgp_notify->code);
subcode_str = bgp_notify_subcode_str(bgp_notify->code,
bgp_notify->subcode);
if (bgp_notify->code == BGP_NOTIFY_CEASE
&& (bgp_notify->subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
|| bgp_notify->subcode
== BGP_NOTIFY_CEASE_ADMIN_RESET)) {
msg_str = bgp_notify_admin_message(
msg_buf, sizeof(msg_buf), bgp_notify->raw_data,
bgp_notify->length);
}
if (msg_str) {
zlog_info(
"%%NOTIFICATION%s: %s neighbor %s %d/%d (%s%s) \"%s\"",
hard_reset ? "(Hard Reset)" : "",
strcmp(direct, "received") == 0
? "received from"
: "sent to",
peer->host, bgp_notify->code,
bgp_notify->subcode, code_str, subcode_str,
msg_str);
} else {
msg_str = bgp_notify->data ? bgp_notify->data : "";
zlog_info(
"%%NOTIFICATION%s: %s neighbor %s %d/%d (%s%s) %d bytes %s",
hard_reset ? "(Hard Reset)" : "",
strcmp(direct, "received") == 0
? "received from"
: "sent to",
peer->host, bgp_notify->code,
bgp_notify->subcode, code_str, subcode_str,
bgp_notify->length, msg_str);
}
}
}
static void bgp_debug_clear_updgrp_update_dbg(struct bgp *bgp)
{
if (!bgp)
bgp = bgp_get_default();
update_group_walk(bgp, update_group_clear_update_dbg, NULL);
}
static void bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc,
struct prefix *p)
{
char evpn_desc[PREFIX2STR_BUFFER + INET_ADDRSTRLEN];
char buf[PREFIX2STR_BUFFER];
char buf2[ETHER_ADDR_STRLEN];
if (p->u.prefix_evpn.route_type == BGP_EVPN_MAC_IP_ROUTE) {
if (is_evpn_prefix_ipaddr_none((struct prefix_evpn *)p)) {
snprintf(
evpn_desc, sizeof(evpn_desc),
"l2vpn evpn type macip mac %s",
prefix_mac2str(&p->u.prefix_evpn.macip_addr.mac,
buf2, sizeof(buf2)));
} else {
uint8_t family = is_evpn_prefix_ipaddr_v4(
(struct prefix_evpn *)p) ?
AF_INET : AF_INET6;
snprintf(
evpn_desc, sizeof(evpn_desc),
"l2vpn evpn type macip mac %s ip %s",
prefix_mac2str(&p->u.prefix_evpn.macip_addr.mac,
buf2, sizeof(buf2)),
inet_ntop(
family,
&p->u.prefix_evpn.macip_addr.ip.ip.addr,
buf, PREFIX2STR_BUFFER));
}
} else if (p->u.prefix_evpn.route_type == BGP_EVPN_IMET_ROUTE) {
snprintfrr(evpn_desc, sizeof(evpn_desc),
"l2vpn evpn type multicast ip %pI4",
&p->u.prefix_evpn.imet_addr.ip.ipaddr_v4);
} else if (p->u.prefix_evpn.route_type == BGP_EVPN_IP_PREFIX_ROUTE) {
uint8_t family = is_evpn_prefix_ipaddr_v4(
(struct prefix_evpn *)p) ? AF_INET
: AF_INET6;
snprintf(evpn_desc, sizeof(evpn_desc),
"l2vpn evpn type prefix ip %s/%d",
inet_ntop(family,
&p->u.prefix_evpn.prefix_addr.ip.ip.addr,
buf, PREFIX2STR_BUFFER),
p->u.prefix_evpn.prefix_addr.ip_prefix_length);
}
vty_out(vty, "%s %s\n", desc, evpn_desc);
}
static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv,
int argc, struct prefix *argv_p)
{
struct ethaddr mac = {};
struct ipaddr ip = {};
int evpn_type = 0;
int mac_idx = 0;
int ip_idx = 0;
if (bgp_evpn_cli_parse_type(&evpn_type, argv, argc) < 0)
return CMD_WARNING;
if (evpn_type == BGP_EVPN_MAC_IP_ROUTE) {
memset(&ip, 0, sizeof(ip));
if (argv_find(argv, argc, "mac", &mac_idx))
if (!prefix_str2mac(argv[mac_idx + 1]->arg, &mac)) {
vty_out(vty, "%% Malformed MAC address\n");
return CMD_WARNING;
}
if (argv_find(argv, argc, "ip", &ip_idx))
if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) {
vty_out(vty, "%% Malformed IP address\n");
return CMD_WARNING;
}
build_evpn_type2_prefix((struct prefix_evpn *)argv_p,
&mac, &ip);
} else if (evpn_type == BGP_EVPN_IMET_ROUTE) {
memset(&ip, 0, sizeof(ip));
if (argv_find(argv, argc, "ip", &ip_idx))
if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) {
vty_out(vty, "%% Malformed IP address\n");
return CMD_WARNING;
}
build_evpn_type3_prefix((struct prefix_evpn *)argv_p,
ip.ipaddr_v4);
} else if (evpn_type == BGP_EVPN_IP_PREFIX_ROUTE) {
struct prefix ip_prefix;
memset(&ip_prefix, 0, sizeof(ip_prefix));
if (argv_find(argv, argc, "ip", &ip_idx)) {
(void)str2prefix(argv[ip_idx + 1]->arg, &ip_prefix);
apply_mask(&ip_prefix);
}
build_type5_prefix_from_ip_prefix(
(struct prefix_evpn *)argv_p,
&ip_prefix);
}
return CMD_SUCCESS;
}
/* Debug option setting interface. */
unsigned long bgp_debug_option = 0;
int debug(unsigned int option)
{
return bgp_debug_option & option;
}
DEFUN (debug_bgp_as4,
debug_bgp_as4_cmd,
"debug bgp as4",
DEBUG_STR
BGP_STR
"BGP AS4 actions\n")
{
if (vty->node == CONFIG_NODE)
DEBUG_ON(as4, AS4);
else {
TERM_DEBUG_ON(as4, AS4);
vty_out(vty, "BGP as4 debugging is on\n");
}
return CMD_SUCCESS;
}
DEFUN (no_debug_bgp_as4,
no_debug_bgp_as4_cmd,
"no debug bgp as4",
NO_STR
DEBUG_STR
BGP_STR
"BGP AS4 actions\n")
{
if (vty->node == CONFIG_NODE)
DEBUG_OFF(as4, AS4);
else {
TERM_DEBUG_OFF(as4, AS4);
vty_out(vty, "BGP as4 debugging is off\n");
}
return CMD_SUCCESS;
}
DEFUN (debug_bgp_as4_segment,
debug_bgp_as4_segment_cmd,
"debug bgp as4 segment",
DEBUG_STR
BGP_STR
"BGP AS4 actions\n"
"BGP AS4 aspath segment handling\n")
{
if (vty->node == CONFIG_NODE)
DEBUG_ON(as4, AS4_SEGMENT);
else {
TERM_DEBUG_ON(as4, AS4_SEGMENT);
vty_out(vty, "BGP as4 segment debugging is on\n");
}
return CMD_SUCCESS;
}
DEFUN (no_debug_bgp_as4_segment,
no_debug_bgp_as4_segment_cmd,
"no debug bgp as4 segment",
NO_STR
DEBUG_STR
BGP_STR
"BGP AS4 actions\n"
"BGP AS4 aspath segment handling\n")
{
if (vty->node == CONFIG_NODE)
DEBUG_OFF(as4, AS4_SEGMENT);
else {
TERM_DEBUG_OFF(as4, AS4_SEGMENT);
vty_out(vty, "BGP as4 segment debugging is off\n");
}
return CMD_SUCCESS;
}
/* debug bgp neighbor_events */
DEFUN (debug_bgp_neighbor_events,
debug_bgp_neighbor_events_cmd,
"debug bgp neighbor-events",
DEBUG_STR
BGP_STR
"BGP Neighbor Events\n")
{
bgp_debug_list_free(bgp_debug_neighbor_events_peers);
if (vty->node == CONFIG_NODE)
DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
else {
TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
vty_out(vty, "BGP neighbor-events debugging is on\n");
}
return CMD_SUCCESS;
}
DEFUN (debug_bgp_neighbor_events_peer,
debug_bgp_neighbor_events_peer_cmd,
"debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
DEBUG_STR
BGP_STR
"BGP Neighbor Events\n"
"BGP neighbor IP address to debug\n"
"BGP IPv6 neighbor to debug\n"
"BGP neighbor on interface to debug\n")
{
int idx_peer = 3;
const char *host = argv[idx_peer]->arg;
if (!bgp_debug_neighbor_events_peers)
bgp_debug_neighbor_events_peers = list_new();
if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers, host,
NULL, NULL)) {
vty_out(vty,
"BGP neighbor-events debugging is already enabled for %s\n",
host);
return CMD_SUCCESS;
}
bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers, host, NULL,
NULL);
if (vty->node == CONFIG_NODE)
DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
else {
TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
vty_out(vty, "BGP neighbor-events debugging is on for %s\n",
host);
}
return CMD_SUCCESS;
}
DEFUN (no_debug_bgp_neighbor_events,
no_debug_bgp_neighbor_events_cmd,
"no debug bgp neighbor-events",
NO_STR
DEBUG_STR
BGP_STR
"Neighbor Events\n")
{
bgp_debug_list_free(bgp_debug_neighbor_events_peers);
if (vty->node == CONFIG_NODE)
DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
else {
TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
vty_out(vty, "BGP neighbor-events debugging is off\n");
}
return CMD_SUCCESS;
}
DEFUN (no_debug_bgp_neighbor_events_peer,
no_debug_bgp_neighbor_events_peer_cmd,
"no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
NO_STR
DEBUG_STR
BGP_STR
"Neighbor Events\n"
"BGP neighbor IP address to debug\n"
"BGP IPv6 neighbor to debug\n"
"BGP neighbor on interface to debug\n")
{
int idx_peer = 4;
int found_peer = 0;
const char *host = argv[idx_peer]->arg;
if (bgp_debug_neighbor_events_peers
&& !list_isempty(bgp_debug_neighbor_events_peers)) {
found_peer = bgp_debug_list_remove_entry(
bgp_debug_neighbor_events_peers, host, NULL);
if (list_isempty(bgp_debug_neighbor_events_peers)) {
if (vty->node == CONFIG_NODE)
DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
else
TERM_DEBUG_OFF(neighbor_events,
NEIGHBOR_EVENTS);
}
}
if (found_peer)
vty_out(vty, "BGP neighbor-events debugging is off for %s\n",
host);
else
vty_out(vty,
"BGP neighbor-events debugging was not enabled for %s\n",
host);
return CMD_SUCCESS;
}
/* debug bgp nht */
DEFUN (debug_bgp_nht,
debug_bgp_nht_cmd,
"debug bgp nht",
DEBUG_STR
BGP_STR
"BGP nexthop tracking events\n")
{
if (vty->node == CONFIG_NODE)
DEBUG_ON(nht, NHT);
else {
TERM_DEBUG_ON(nht, NHT);
vty_out(vty, "BGP nexthop tracking debugging is on\n");
}
return CMD_SUCCESS;
}
DEFUN (no_debug_bgp_nht,
no_debug_bgp_nht_cmd,
"no debug bgp nht",
NO_STR
DEBUG_STR
BGP_STR
"BGP nexthop tracking events\n")
{
if (vty->node == CONFIG_NODE)
DEBUG_OFF(nht, NHT);
else {
TERM_DEBUG_OFF(nht, NHT);
vty_out(vty, "BGP nexthop tracking debugging is off\n");
}
return CMD_SUCCESS;
}
/* debug bgp keepalives */
DEFUN (debug_bgp_keepalive,
debug_bgp_keepalive_cmd,
"debug bgp keepalives",
DEBUG_STR
BGP_STR
"BGP keepalives\n")
{
bgp_debug_list_free(bgp_debug_keepalive_peers);
if (vty->node == CONFIG_NODE)
DEBUG_ON(keepalive, KEEPALIVE);
else {
TERM_DEBUG_ON(keepalive, KEEPALIVE);
vty_out(vty, "BGP keepalives debugging is on\n");
}
return CMD_SUCCESS;
}
DEFUN (debug_bgp_keepalive_peer,
debug_bgp_keepalive_peer_cmd,
"debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
DEBUG_STR
BGP_STR
"BGP keepalives\n"
"BGP IPv4 neighbor to debug\n"
"BGP IPv6 neighbor to debug\n"
"BGP neighbor on interface to debug\n")
{
int idx_peer = 3;
const char *host = argv[idx_peer]->arg;
if (!bgp_debug_keepalive_peers)
bgp_debug_keepalive_peers = list_new();
if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers, host, NULL,
NULL)) {
vty_out(vty,
"BGP keepalive debugging is already enabled for %s\n",
host);
return CMD_SUCCESS;
}
bgp_debug_list_add_entry(bgp_debug_keepalive_peers, host, NULL, NULL);
if (vty->node == CONFIG_NODE)
DEBUG_ON(keepalive, KEEPALIVE);
else {
TERM_DEBUG_ON(keepalive, KEEPALIVE);
vty_out(vty, "BGP keepalives debugging is on for %s\n", host);
}
return CMD_SUCCESS;
}
DEFUN (no_debug_bgp_keepalive,
no_debug_bgp_keepalive_cmd,
"no debug bgp keepalives",
NO_STR
DEBUG_STR
BGP_STR
"BGP keepalives\n")
{
bgp_debug_list_free(bgp_debug_keepalive_peers);
if (vty->node == CONFIG_NODE)
DEBUG_OFF(keepalive, KEEPALIVE);
else {
TERM_DEBUG_OFF(keepalive, KEEPALIVE);
vty_out(vty, "BGP keepalives debugging is off\n");
}