forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpim_cmd_common.c
5801 lines (4855 loc) · 149 KB
/
pim_cmd_common.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
/*
* PIM for IPv6 FRR
* Copyright (C) 2022 Vmware, Inc.
* Mobashshera Rasool <[email protected]>
*/
#include <zebra.h>
#include <sys/ioctl.h>
#include "lib/json.h"
#include "command.h"
#include "if.h"
#include "prefix.h"
#include "zclient.h"
#include "plist.h"
#include "hash.h"
#include "nexthop.h"
#include "vrf.h"
#include "ferr.h"
#include "lib/srcdest_table.h"
#include "lib/linklist.h"
#include "termtable.h"
#include "pimd.h"
#include "pim_instance.h"
#include "pim_vty.h"
#include "lib/northbound_cli.h"
#include "pim_errors.h"
#include "pim_nb.h"
#include "pim_mroute.h"
#include "pim_cmd.h"
#include "pim6_cmd.h"
#include "pim_cmd_common.h"
#include "pim_time.h"
#include "pim_zebra.h"
#include "pim_zlookup.h"
#include "pim_iface.h"
#include "pim_macro.h"
#include "pim_neighbor.h"
#include "pim_nht.h"
#include "pim_sock.h"
#include "pim_ssm.h"
#include "pim_static.h"
#include "pim_addr.h"
#include "pim_static.h"
#include "pim_util.h"
#include "pim6_mld.h"
/**
* Get current node VRF name.
*
* NOTE:
* In case of failure it will print error message to user.
*
* \returns name or NULL if failed to get VRF.
*/
const char *pim_cli_get_vrf_name(struct vty *vty)
{
const struct lyd_node *vrf_node;
/* Not inside any VRF context. */
if (vty->xpath_index == 0)
return VRF_DEFAULT_NAME;
vrf_node = yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH);
if (vrf_node == NULL) {
vty_out(vty, "%% Failed to get vrf dnode in configuration\n");
return NULL;
}
return yang_dnode_get_string(vrf_node, "name");
}
int pim_process_join_prune_cmd(struct vty *vty, const char *jpi_str)
{
char xpath[XPATH_MAXLEN];
snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH,
FRR_PIM_AF_XPATH_VAL);
strlcat(xpath, "/join-prune-interval", sizeof(xpath));
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, jpi_str);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_no_join_prune_cmd(struct vty *vty)
{
char xpath[XPATH_MAXLEN];
snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH,
FRR_PIM_AF_XPATH_VAL);
strlcat(xpath, "/join-prune-interval", sizeof(xpath));
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_spt_switchover_infinity_cmd(struct vty *vty)
{
char spt_plist_xpath[XPATH_MAXLEN + 40];
char spt_action_xpath[XPATH_MAXLEN + 26];
snprintf(spt_plist_xpath, sizeof(spt_plist_xpath),
"%s/spt-switchover/spt-infinity-prefix-list", VTY_CURR_XPATH);
snprintf(spt_action_xpath, sizeof(spt_action_xpath),
"%s/spt-switchover/spt-action", VTY_CURR_XPATH);
if (yang_dnode_exists(vty->candidate_config->dnode, spt_plist_xpath))
nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_DESTROY,
NULL);
nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY,
"PIM_SPT_INFINITY");
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_spt_switchover_prefixlist_cmd(struct vty *vty,
const char *plist)
{
char spt_plist_xpath[XPATH_MAXLEN];
char spt_action_xpath[XPATH_MAXLEN];
snprintf(spt_plist_xpath, sizeof(spt_plist_xpath),
"./spt-switchover/spt-infinity-prefix-list");
snprintf(spt_action_xpath, sizeof(spt_action_xpath),
"./spt-switchover/spt-action");
nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY,
"PIM_SPT_INFINITY");
nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_MODIFY, plist);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_no_spt_switchover_cmd(struct vty *vty)
{
char spt_plist_xpath[XPATH_MAXLEN];
char spt_action_xpath[XPATH_MAXLEN];
snprintf(spt_plist_xpath, sizeof(spt_plist_xpath),
"./spt-switchover/spt-infinity-prefix-list");
snprintf(spt_action_xpath, sizeof(spt_action_xpath),
"./spt-switchover/spt-action");
nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_DESTROY, NULL);
nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY,
"PIM_SPT_IMMEDIATE");
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_pim_packet_cmd(struct vty *vty, const char *packet)
{
char xpath[XPATH_MAXLEN];
snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH,
FRR_PIM_AF_XPATH_VAL);
strlcat(xpath, "/packets", sizeof(xpath));
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, packet);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_no_pim_packet_cmd(struct vty *vty)
{
char xpath[XPATH_MAXLEN];
snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH,
FRR_PIM_AF_XPATH_VAL);
strlcat(xpath, "/packets", sizeof(xpath));
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_keepalivetimer_cmd(struct vty *vty, const char *kat)
{
char ka_timer_xpath[XPATH_MAXLEN];
snprintf(ka_timer_xpath, sizeof(ka_timer_xpath), "./keep-alive-timer");
nb_cli_enqueue_change(vty, ka_timer_xpath, NB_OP_MODIFY, kat);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_no_keepalivetimer_cmd(struct vty *vty)
{
char ka_timer_xpath[XPATH_MAXLEN];
snprintf(ka_timer_xpath, sizeof(ka_timer_xpath), "./keep-alive-timer");
nb_cli_enqueue_change(vty, ka_timer_xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_rp_kat_cmd(struct vty *vty, const char *rpkat)
{
char rp_ka_timer_xpath[XPATH_MAXLEN];
snprintf(rp_ka_timer_xpath, sizeof(rp_ka_timer_xpath),
"./rp-keep-alive-timer");
nb_cli_enqueue_change(vty, rp_ka_timer_xpath, NB_OP_MODIFY, rpkat);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_no_rp_kat_cmd(struct vty *vty)
{
char rp_ka_timer[6];
char rp_ka_timer_xpath[XPATH_MAXLEN];
uint v;
char rs_timer_xpath[XPATH_MAXLEN];
snprintf(rs_timer_xpath, sizeof(rs_timer_xpath), FRR_PIM_ROUTER_XPATH,
FRR_PIM_AF_XPATH_VAL);
strlcat(rs_timer_xpath, "/register-suppress-time",
sizeof(rs_timer_xpath));
/* RFC4601 */
/* Check if register suppress time is configured or assigned
* the default register suppress time.
*/
if (yang_dnode_exists(vty->candidate_config->dnode, rs_timer_xpath))
v = yang_dnode_get_uint16(vty->candidate_config->dnode, "%s",
rs_timer_xpath);
else
v = PIM_REGISTER_SUPPRESSION_TIME_DEFAULT;
v = 3 * v + PIM_REGISTER_PROBE_TIME_DEFAULT;
if (v > UINT16_MAX)
v = UINT16_MAX;
snprintf(rp_ka_timer, sizeof(rp_ka_timer), "%u", v);
snprintf(rp_ka_timer_xpath, sizeof(rp_ka_timer_xpath),
"./rp-keep-alive-timer");
nb_cli_enqueue_change(vty, rp_ka_timer_xpath, NB_OP_MODIFY, rp_ka_timer);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_register_suppress_cmd(struct vty *vty, const char *rst)
{
char xpath[XPATH_MAXLEN];
snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH,
FRR_PIM_AF_XPATH_VAL);
strlcat(xpath, "/register-suppress-time", sizeof(xpath));
nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, rst);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_no_register_suppress_cmd(struct vty *vty)
{
char xpath[XPATH_MAXLEN];
snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH,
FRR_PIM_AF_XPATH_VAL);
strlcat(xpath, "/register-suppress-time", sizeof(xpath));
nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_ip_pim_cmd(struct vty *vty)
{
nb_cli_enqueue_change(vty, "./pim-enable", NB_OP_MODIFY, "true");
return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH,
FRR_PIM_AF_XPATH_VAL);
}
int pim_process_ip_pim_passive_cmd(struct vty *vty, bool enable)
{
if (enable)
nb_cli_enqueue_change(vty, "./pim-passive-enable", NB_OP_MODIFY,
"true");
else
nb_cli_enqueue_change(vty, "./pim-passive-enable", NB_OP_MODIFY,
"false");
return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH,
FRR_PIM_AF_XPATH_VAL);
}
int pim_process_no_ip_pim_cmd(struct vty *vty)
{
const struct lyd_node *mld_enable_dnode;
char mld_if_xpath[XPATH_MAXLEN];
int printed =
snprintf(mld_if_xpath, sizeof(mld_if_xpath),
"%s/frr-gmp:gmp/address-family[address-family='%s']",
VTY_CURR_XPATH, FRR_PIM_AF_XPATH_VAL);
if (printed >= (int)(sizeof(mld_if_xpath))) {
vty_out(vty, "Xpath too long (%d > %u)", printed + 1,
XPATH_MAXLEN);
return CMD_WARNING_CONFIG_FAILED;
}
mld_enable_dnode = yang_dnode_getf(vty->candidate_config->dnode,
FRR_GMP_ENABLE_XPATH, VTY_CURR_XPATH,
FRR_PIM_AF_XPATH_VAL);
if (!mld_enable_dnode) {
nb_cli_enqueue_change(vty, mld_if_xpath, NB_OP_DESTROY, NULL);
nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
} else {
if (!yang_dnode_get_bool(mld_enable_dnode, ".")) {
nb_cli_enqueue_change(vty, mld_if_xpath, NB_OP_DESTROY,
NULL);
nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
} else
nb_cli_enqueue_change(vty, "./pim-enable", NB_OP_MODIFY,
"false");
}
return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH,
FRR_PIM_AF_XPATH_VAL);
}
int pim_process_ip_pim_drprio_cmd(struct vty *vty, const char *drpriority_str)
{
nb_cli_enqueue_change(vty, "./dr-priority", NB_OP_MODIFY,
drpriority_str);
return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH,
FRR_PIM_AF_XPATH_VAL);
}
int pim_process_no_ip_pim_drprio_cmd(struct vty *vty)
{
nb_cli_enqueue_change(vty, "./dr-priority", NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH,
FRR_PIM_AF_XPATH_VAL);
}
int pim_process_ip_pim_hello_cmd(struct vty *vty, const char *hello_str,
const char *hold_str)
{
const struct lyd_node *mld_enable_dnode;
mld_enable_dnode = yang_dnode_getf(vty->candidate_config->dnode,
FRR_GMP_ENABLE_XPATH, VTY_CURR_XPATH,
FRR_PIM_AF_XPATH_VAL);
if (!mld_enable_dnode) {
nb_cli_enqueue_change(vty, "./pim-enable", NB_OP_MODIFY,
"true");
} else {
if (!yang_dnode_get_bool(mld_enable_dnode, "."))
nb_cli_enqueue_change(vty, "./pim-enable", NB_OP_MODIFY,
"true");
}
nb_cli_enqueue_change(vty, "./hello-interval", NB_OP_MODIFY, hello_str);
if (hold_str)
nb_cli_enqueue_change(vty, "./hello-holdtime", NB_OP_MODIFY,
hold_str);
return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH,
FRR_PIM_AF_XPATH_VAL);
}
int pim_process_no_ip_pim_hello_cmd(struct vty *vty)
{
nb_cli_enqueue_change(vty, "./hello-interval", NB_OP_DESTROY, NULL);
nb_cli_enqueue_change(vty, "./hello-holdtime", NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH,
FRR_PIM_AF_XPATH_VAL);
}
int pim_process_ip_pim_activeactive_cmd(struct vty *vty, const char *no)
{
if (no)
nb_cli_enqueue_change(vty, "./active-active", NB_OP_MODIFY,
"false");
else {
nb_cli_enqueue_change(vty, "./pim-enable", NB_OP_MODIFY,
"true");
nb_cli_enqueue_change(vty, "./active-active", NB_OP_MODIFY,
"true");
}
return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH,
FRR_PIM_AF_XPATH_VAL);
}
int pim_process_ip_pim_boundary_oil_cmd(struct vty *vty, const char *oil)
{
nb_cli_enqueue_change(vty, "./multicast-boundary-oil", NB_OP_MODIFY,
oil);
return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH,
FRR_PIM_AF_XPATH_VAL);
}
int pim_process_no_ip_pim_boundary_oil_cmd(struct vty *vty)
{
nb_cli_enqueue_change(vty, "./multicast-boundary-oil", NB_OP_DESTROY,
NULL);
return nb_cli_apply_changes(vty, FRR_PIM_INTERFACE_XPATH,
FRR_PIM_AF_XPATH_VAL);
}
int pim_process_ip_mroute_cmd(struct vty *vty, const char *interface,
const char *group_str, const char *source_str)
{
nb_cli_enqueue_change(vty, "./oif", NB_OP_MODIFY, interface);
if (!source_str) {
char buf[SRCDEST2STR_BUFFER];
inet_ntop(AF_INET6, &in6addr_any, buf, sizeof(buf));
return nb_cli_apply_changes(vty, FRR_PIM_MROUTE_XPATH,
FRR_PIM_AF_XPATH_VAL, buf,
group_str);
}
return nb_cli_apply_changes(vty, FRR_PIM_MROUTE_XPATH,
FRR_PIM_AF_XPATH_VAL, source_str,
group_str);
}
int pim_process_no_ip_mroute_cmd(struct vty *vty, const char *interface,
const char *group_str, const char *source_str)
{
nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
if (!source_str) {
char buf[SRCDEST2STR_BUFFER];
inet_ntop(AF_INET6, &in6addr_any, buf, sizeof(buf));
return nb_cli_apply_changes(vty, FRR_PIM_MROUTE_XPATH,
FRR_PIM_AF_XPATH_VAL, buf,
group_str);
}
return nb_cli_apply_changes(vty, FRR_PIM_MROUTE_XPATH,
FRR_PIM_AF_XPATH_VAL, source_str,
group_str);
}
int pim_process_rp_cmd(struct vty *vty, const char *rp_str,
const char *group_str)
{
char group_xpath[XPATH_MAXLEN];
int printed;
int result = 0;
struct prefix group;
pim_addr rp_addr;
result = str2prefix(group_str, &group);
if (result) {
struct prefix temp;
prefix_copy(&temp, &group);
apply_mask(&temp);
if (!prefix_same(&group, &temp)) {
vty_out(vty, "%% Inconsistent address and mask: %s\n",
group_str);
return CMD_WARNING_CONFIG_FAILED;
}
}
if (!result) {
vty_out(vty, "%% Bad group address specified: %s\n", group_str);
return CMD_WARNING_CONFIG_FAILED;
}
result = inet_pton(PIM_AF, rp_str, &rp_addr);
if (result <= 0) {
vty_out(vty, "%% Bad RP address specified: %s\n", rp_str);
return CMD_WARNING_CONFIG_FAILED;
}
if (pim_addr_is_any(rp_addr) || pim_addr_is_multicast(rp_addr)) {
vty_out(vty, "%% Bad RP address specified: %s\n", rp_str);
return CMD_WARNING_CONFIG_FAILED;
}
#if PIM_IPV == 6
if (IN6_IS_ADDR_LINKLOCAL(&rp_addr)) {
vty_out(vty, "%% Bad RP address specified: %s\n", rp_str);
return CMD_WARNING_CONFIG_FAILED;
}
#endif
printed = snprintf(group_xpath, sizeof(group_xpath),
"./" FRR_PIM_STATIC_RP_XPATH "/group-list[.='%s']",
rp_str, group_str);
if (printed >= (int)(sizeof(group_xpath))) {
vty_out(vty, "Xpath too long (%d > %u)", printed + 1,
XPATH_MAXLEN);
return CMD_WARNING_CONFIG_FAILED;
}
nb_cli_enqueue_change(vty, group_xpath, NB_OP_CREATE, NULL);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_no_rp_cmd(struct vty *vty, const char *rp_str,
const char *group_str)
{
char group_xpath[XPATH_MAXLEN];
char rp_xpath[XPATH_MAXLEN + 47];
int printed;
const struct lyd_node *group_dnode;
snprintf(rp_xpath, sizeof(rp_xpath), "%s/" FRR_PIM_STATIC_RP_XPATH,
VTY_CURR_XPATH, rp_str);
printed = snprintf(group_xpath, sizeof(group_xpath),
"%s/group-list[.='%s']", rp_xpath, group_str);
if (printed >= (int)(sizeof(group_xpath))) {
vty_out(vty, "Xpath too long (%d > %u)", printed + 1,
XPATH_MAXLEN);
return CMD_WARNING_CONFIG_FAILED;
}
group_dnode = yang_dnode_get(vty->candidate_config->dnode, group_xpath);
if (!group_dnode) {
vty_out(vty, "%% Unable to find specified RP\n");
return NB_OK;
}
if (yang_is_last_list_dnode(group_dnode))
nb_cli_enqueue_change(vty, rp_xpath, NB_OP_DESTROY, NULL);
else
nb_cli_enqueue_change(vty, group_xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_rp_plist_cmd(struct vty *vty, const char *rp_str,
const char *prefix_list)
{
char rp_plist_xpath[XPATH_MAXLEN];
snprintf(rp_plist_xpath, sizeof(rp_plist_xpath),
"./" FRR_PIM_STATIC_RP_XPATH, rp_str);
strlcat(rp_plist_xpath, "/prefix-list", sizeof(rp_plist_xpath));
nb_cli_enqueue_change(vty, rp_plist_xpath, NB_OP_MODIFY, prefix_list);
return nb_cli_apply_changes(vty, NULL);
}
int pim_process_no_rp_plist_cmd(struct vty *vty, const char *rp_str,
const char *prefix_list)
{
char rp_xpath[XPATH_MAXLEN + 47];
char plist_xpath[XPATH_MAXLEN + 1070];
const struct lyd_node *plist_dnode;
const char *plist;
snprintf(rp_xpath, sizeof(rp_xpath), "%s/" FRR_PIM_STATIC_RP_XPATH,
VTY_CURR_XPATH, rp_str);
snprintf(plist_xpath, sizeof(plist_xpath), "%s", rp_xpath);
strlcat(plist_xpath, "/prefix-list", sizeof(plist_xpath));
plist_dnode = yang_dnode_get(vty->candidate_config->dnode, plist_xpath);
if (!plist_dnode) {
vty_out(vty, "%% Unable to find specified RP\n");
return NB_OK;
}
plist = yang_dnode_get_string(plist_dnode, NULL);
if (strcmp(prefix_list, plist)) {
vty_out(vty, "%% Unable to find specified RP\n");
return NB_OK;
}
nb_cli_enqueue_change(vty, rp_xpath, NB_OP_DESTROY, NULL);
return nb_cli_apply_changes(vty, NULL);
}
bool pim_sgaddr_match(pim_sgaddr item, pim_sgaddr match)
{
return (pim_addr_is_any(match.grp) ||
!pim_addr_cmp(match.grp, item.grp)) &&
(pim_addr_is_any(match.src) ||
!pim_addr_cmp(match.src, item.src));
}
void json_object_pim_ifp_add(struct json_object *json, struct interface *ifp)
{
struct pim_interface *pim_ifp;
pim_ifp = ifp->info;
json_object_string_add(json, "name", ifp->name);
json_object_string_add(json, "state", if_is_up(ifp) ? "up" : "down");
json_object_string_addf(json, "address", "%pPA",
&pim_ifp->primary_address);
json_object_int_add(json, "index", ifp->ifindex);
if (if_is_multicast(ifp))
json_object_boolean_true_add(json, "flagMulticast");
if (if_is_broadcast(ifp))
json_object_boolean_true_add(json, "flagBroadcast");
if (ifp->flags & IFF_ALLMULTI)
json_object_boolean_true_add(json, "flagAllMulticast");
if (ifp->flags & IFF_PROMISC)
json_object_boolean_true_add(json, "flagPromiscuous");
if (PIM_IF_IS_DELETED(ifp))
json_object_boolean_true_add(json, "flagDeleted");
if (pim_if_lan_delay_enabled(ifp))
json_object_boolean_true_add(json, "lanDelayEnabled");
}
void pim_print_ifp_flags(struct vty *vty, struct interface *ifp)
{
vty_out(vty, "Flags\n");
vty_out(vty, "-----\n");
vty_out(vty, "All Multicast : %s\n",
(ifp->flags & IFF_ALLMULTI) ? "yes" : "no");
vty_out(vty, "Broadcast : %s\n",
if_is_broadcast(ifp) ? "yes" : "no");
vty_out(vty, "Deleted : %s\n",
PIM_IF_IS_DELETED(ifp) ? "yes" : "no");
vty_out(vty, "Interface Index : %d\n", ifp->ifindex);
vty_out(vty, "Multicast : %s\n",
if_is_multicast(ifp) ? "yes" : "no");
vty_out(vty, "Promiscuous : %s\n",
(ifp->flags & IFF_PROMISC) ? "yes" : "no");
vty_out(vty, "\n");
vty_out(vty, "\n");
}
void json_object_pim_upstream_add(json_object *json, struct pim_upstream *up)
{
json_object_boolean_add(
json, "drJoinDesired",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED));
json_object_boolean_add(
json, "drJoinDesiredUpdated",
CHECK_FLAG(up->flags,
PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED_UPDATED));
json_object_boolean_add(
json, "firstHopRouter",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_FHR));
json_object_boolean_add(
json, "sourceIgmp",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_SRC_IGMP));
json_object_boolean_add(
json, "sourcePim",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_SRC_PIM));
json_object_boolean_add(
json, "sourceStream",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_SRC_STREAM));
/* XXX: need to print ths flag in the plain text display as well */
json_object_boolean_add(
json, "sourceMsdp",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_SRC_MSDP));
json_object_boolean_add(
json, "sendSGRptPrune",
CHECK_FLAG(up->flags,
PIM_UPSTREAM_FLAG_MASK_SEND_SG_RPT_PRUNE));
json_object_boolean_add(
json, "lastHopRouter",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_SRC_LHR));
json_object_boolean_add(
json, "disableKATExpiry",
CHECK_FLAG(up->flags,
PIM_UPSTREAM_FLAG_MASK_DISABLE_KAT_EXPIRY));
json_object_boolean_add(
json, "staticIncomingInterface",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_STATIC_IIF));
json_object_boolean_add(
json, "allowIncomingInterfaceinOil",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_ALLOW_IIF_IN_OIL));
json_object_boolean_add(
json, "noPimRegistrationData",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_NO_PIMREG_DATA));
json_object_boolean_add(
json, "forcePimRegistration",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_FORCE_PIMREG));
json_object_boolean_add(
json, "sourceVxlanOrigination",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_ORIG));
json_object_boolean_add(
json, "sourceVxlanTermination",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM));
json_object_boolean_add(
json, "mlagVxlan",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_MLAG_VXLAN));
json_object_boolean_add(
json, "mlagNonDesignatedForwarder",
CHECK_FLAG(up->flags, PIM_UPSTREAM_FLAG_MASK_MLAG_NON_DF));
}
static const char *
pim_upstream_state2brief_str(enum pim_upstream_state join_state,
char *state_str, size_t state_str_len)
{
switch (join_state) {
case PIM_UPSTREAM_NOTJOINED:
strlcpy(state_str, "NotJ", state_str_len);
break;
case PIM_UPSTREAM_JOINED:
strlcpy(state_str, "J", state_str_len);
break;
default:
strlcpy(state_str, "Unk", state_str_len);
}
return state_str;
}
static const char *pim_reg_state2brief_str(enum pim_reg_state reg_state,
char *state_str,
size_t state_str_len)
{
switch (reg_state) {
case PIM_REG_NOINFO:
strlcpy(state_str, "RegNI", state_str_len);
break;
case PIM_REG_JOIN:
strlcpy(state_str, "RegJ", state_str_len);
break;
case PIM_REG_JOIN_PENDING:
case PIM_REG_PRUNE:
strlcpy(state_str, "RegP", state_str_len);
break;
}
return state_str;
}
void pim_show_rpf_refresh_stats(struct vty *vty, struct pim_instance *pim,
time_t now, json_object *json)
{
char refresh_uptime[10];
pim_time_uptime_begin(refresh_uptime, sizeof(refresh_uptime), now,
pim->rpf_cache_refresh_last);
if (json) {
json_object_int_add(json, "rpfCacheRefreshDelayMsecs",
router->rpf_cache_refresh_delay_msec);
json_object_int_add(
json, "rpfCacheRefreshTimer",
pim_time_timer_remain_msec(pim->rpf_cache_refresher));
json_object_int_add(json, "rpfCacheRefreshRequests",
pim->rpf_cache_refresh_requests);
json_object_int_add(json, "rpfCacheRefreshEvents",
pim->rpf_cache_refresh_events);
json_object_string_add(json, "rpfCacheRefreshLast",
refresh_uptime);
json_object_int_add(json, "nexthopLookups",
pim->nexthop_lookups);
json_object_int_add(json, "nexthopLookupsAvoided",
pim->nexthop_lookups_avoided);
} else {
vty_out(vty,
"RPF Cache Refresh Delay: %ld msecs\n"
"RPF Cache Refresh Timer: %ld msecs\n"
"RPF Cache Refresh Requests: %lld\n"
"RPF Cache Refresh Events: %lld\n"
"RPF Cache Refresh Last: %s\n"
"Nexthop Lookups: %lld\n"
"Nexthop Lookups Avoided: %lld\n",
router->rpf_cache_refresh_delay_msec,
pim_time_timer_remain_msec(pim->rpf_cache_refresher),
(long long)pim->rpf_cache_refresh_requests,
(long long)pim->rpf_cache_refresh_events,
refresh_uptime, (long long)pim->nexthop_lookups,
(long long)pim->nexthop_lookups_avoided);
}
}
void pim_show_rpf(struct pim_instance *pim, struct vty *vty, json_object *json)
{
struct pim_upstream *up;
time_t now = pim_time_monotonic_sec();
struct ttable *tt = NULL;
char *table = NULL;
json_object *json_group = NULL;
json_object *json_row = NULL;
pim_show_rpf_refresh_stats(vty, pim, now, json);
if (!json) {
vty_out(vty, "\n");
/* Prepare table. */
tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
ttable_add_row(
tt,
"Source|Group|RpfIface|RpfAddress|RibNextHop|Metric|Pref");
tt->style.cell.rpad = 2;
tt->style.corner = '+';
ttable_restyle(tt);
}
frr_each (rb_pim_upstream, &pim->upstream_head, up) {
const char *rpf_ifname;
struct pim_rpf *rpf = &up->rpf;
rpf_ifname =
rpf->source_nexthop.interface ? rpf->source_nexthop
.interface->name
: "<ifname?>";
if (json) {
char grp_str[PIM_ADDRSTRLEN];
char src_str[PIM_ADDRSTRLEN];
snprintfrr(grp_str, sizeof(grp_str), "%pPAs",
&up->sg.grp);
snprintfrr(src_str, sizeof(src_str), "%pPAs",
&up->sg.src);
json_object_object_get_ex(json, grp_str, &json_group);
if (!json_group) {
json_group = json_object_new_object();
json_object_object_add(json, grp_str,
json_group);
}
json_row = json_object_new_object();
json_object_string_add(json_row, "source", src_str);
json_object_string_add(json_row, "group", grp_str);
json_object_string_add(json_row, "rpfInterface",
rpf_ifname);
json_object_string_addf(json_row, "rpfAddress", "%pPA",
&rpf->rpf_addr);
json_object_string_addf(
json_row, "ribNexthop", "%pPAs",
&rpf->source_nexthop.mrib_nexthop_addr);
json_object_int_add(
json_row, "routeMetric",
rpf->source_nexthop.mrib_route_metric);
json_object_int_add(
json_row, "routePreference",
rpf->source_nexthop.mrib_metric_preference);
json_object_object_add(json_group, src_str, json_row);
} else {
ttable_add_row(
tt, "%pPAs|%pPAs|%s|%pPA|%pPAs|%d|%d",
&up->sg.src, &up->sg.grp, rpf_ifname,
&rpf->rpf_addr,
&rpf->source_nexthop.mrib_nexthop_addr,
rpf->source_nexthop.mrib_route_metric,
rpf->source_nexthop.mrib_metric_preference);
}
}
/* Dump the generated table. */
if (!json) {
table = ttable_dump(tt, "\n");
vty_out(vty, "%s\n", table);
XFREE(MTYPE_TMP_TTABLE, table);
ttable_del(tt);
}
}
void pim_show_neighbors_secondary(struct pim_instance *pim, struct vty *vty)
{
struct interface *ifp;
struct ttable *tt = NULL;
char *table = NULL;
/* Prepare table. */
tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
ttable_add_row(tt, "Interface|Address|Neighbor|Secondary");
tt->style.cell.rpad = 2;
tt->style.corner = '+';
ttable_restyle(tt);
FOR_ALL_INTERFACES (pim->vrf, ifp) {
struct pim_interface *pim_ifp;
pim_addr ifaddr;
struct listnode *neighnode;
struct pim_neighbor *neigh;
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
if (pim_ifp->pim_sock_fd < 0)
continue;
ifaddr = pim_ifp->primary_address;
for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode,
neigh)) {
struct listnode *prefix_node;
struct prefix *p;
if (!neigh->prefix_list)
continue;
for (ALL_LIST_ELEMENTS_RO(neigh->prefix_list,
prefix_node, p))
ttable_add_row(tt, "%s|%pPAs|%pPAs|%pFX",
ifp->name, &ifaddr,
&neigh->source_addr, p);
}
}
/* Dump the generated table. */
table = ttable_dump(tt, "\n");
vty_out(vty, "%s\n", table);
XFREE(MTYPE_TMP_TTABLE, table);
ttable_del(tt);
}
void pim_show_state(struct pim_instance *pim, struct vty *vty,
const char *src_or_group, const char *group,
json_object *json)
{
struct channel_oil *c_oil;
#if PIM_IPV != 4
struct ttable *tt = NULL;
char *table = NULL;
#endif
char flag[50];
json_object *json_group = NULL;
json_object *json_ifp_in = NULL;
json_object *json_ifp_out = NULL;
json_object *json_source = NULL;
time_t now;
int first_oif;
now = pim_time_monotonic_sec();
if (!json) {
vty_out(vty,
"Codes: J -> Pim Join, I -> " GM " Report, S -> Source, * -> Inherited from (*,G), V -> VxLAN, M -> Muted\n");
#if PIM_IPV == 4
vty_out(vty,
"Active Source Group RPT IIF OIL\n");
#else
/* Prepare table. */
tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
ttable_add_row(tt, "Active|Source|Group|RPT|IIF|OIL");
tt->style.cell.rpad = 2;
tt->style.corner = '+';
ttable_restyle(tt);
#endif
}
frr_each (rb_pim_oil, &pim->channel_oil_head, c_oil) {
char src_str[PIM_ADDRSTRLEN];
char grp_str[PIM_ADDRSTRLEN];
char in_ifname[IFNAMSIZ + 1];
char out_ifname[IFNAMSIZ + 1];
int oif_vif_index;
struct interface *ifp_in;
bool isRpt;
first_oif = 1;
if ((c_oil->up &&
PIM_UPSTREAM_FLAG_TEST_USE_RPT(c_oil->up->flags)) ||
pim_addr_is_any(*oil_origin(c_oil)))
isRpt = true;
else
isRpt = false;
snprintfrr(grp_str, sizeof(grp_str), "%pPAs",
oil_mcastgrp(c_oil));
snprintfrr(src_str, sizeof(src_str), "%pPAs",
oil_origin(c_oil));
ifp_in = pim_if_find_by_vif_index(pim, *oil_incoming_vif(c_oil));
if (ifp_in)
strlcpy(in_ifname, ifp_in->name, sizeof(in_ifname));
else
strlcpy(in_ifname, "<iif?>", sizeof(in_ifname));
if (src_or_group) {
if (strcmp(src_or_group, src_str) &&
strcmp(src_or_group, grp_str))
continue;