forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathospf_vty.c
12993 lines (11150 loc) · 343 KB
/
ospf_vty.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
/* OSPF VTY interface.
* Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
* Copyright (C) 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 <string.h>
#include "printfrr.h"
#include "monotime.h"
#include "memory.h"
#include "thread.h"
#include "prefix.h"
#include "table.h"
#include "vty.h"
#include "command.h"
#include "plist.h"
#include "log.h"
#include "zclient.h"
#include <lib/json.h>
#include "defaults.h"
#include "lib/printfrr.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_asbr.h"
#include "ospfd/ospf_lsa.h"
#include "ospfd/ospf_lsdb.h"
#include "ospfd/ospf_ism.h"
#include "ospfd/ospf_interface.h"
#include "ospfd/ospf_nsm.h"
#include "ospfd/ospf_neighbor.h"
#include "ospfd/ospf_flood.h"
#include "ospfd/ospf_abr.h"
#include "ospfd/ospf_spf.h"
#include "ospfd/ospf_route.h"
#include "ospfd/ospf_zebra.h"
/*#include "ospfd/ospf_routemap.h" */
#include "ospfd/ospf_vty.h"
#include "ospfd/ospf_dump.h"
#include "ospfd/ospf_bfd.h"
#include "ospfd/ospf_ldp_sync.h"
FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES,
{ .val_bool = true, .match_profile = "datacenter", },
{ .val_bool = false },
);
static const char *const ospf_network_type_str[] = {
"Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
"VIRTUALLINK", "LOOPBACK"};
/* Utility functions. */
int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt)
{
char *ep;
area_id->s_addr = htonl(strtoul(str, &ep, 10));
if (*ep && !inet_aton(str, area_id))
return -1;
*area_id_fmt =
*ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL;
return 0;
}
static void area_id2str(char *buf, int length, struct in_addr *area_id,
int area_id_fmt)
{
if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
inet_ntop(AF_INET, area_id, buf, length);
else
snprintf(buf, length, "%lu",
(unsigned long)ntohl(area_id->s_addr));
}
static int str2metric(const char *str, int *metric)
{
/* Sanity check. */
if (str == NULL)
return 0;
*metric = strtol(str, NULL, 10);
if (*metric < 0 || *metric > 16777214) {
/* vty_out (vty, "OSPF metric value is invalid\n"); */
return 0;
}
return 1;
}
static int str2metric_type(const char *str, int *metric_type)
{
/* Sanity check. */
if (str == NULL)
return 0;
if (strncmp(str, "1", 1) == 0)
*metric_type = EXTERNAL_METRIC_TYPE_1;
else if (strncmp(str, "2", 1) == 0)
*metric_type = EXTERNAL_METRIC_TYPE_2;
else
return 0;
return 1;
}
int ospf_oi_count(struct interface *ifp)
{
struct route_node *rn;
int i = 0;
for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
if (rn->info)
i++;
return i;
}
#define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
vrf_name = argv[idx_vrf + 1]->arg; \
all_vrf = strmatch(vrf_name, "all"); \
}
static int ospf_router_cmd_parse(struct vty *vty, struct cmd_token *argv[],
const int argc, unsigned short *instance,
const char **vrf_name)
{
int idx_vrf = 0, idx_inst = 0;
*instance = 0;
if (argv_find(argv, argc, "(1-65535)", &idx_inst)) {
if (ospf_instance == 0) {
vty_out(vty,
"%% OSPF is not running in instance mode\n");
return CMD_WARNING_CONFIG_FAILED;
}
*instance = strtoul(argv[idx_inst]->arg, NULL, 10);
}
*vrf_name = NULL;
if (argv_find(argv, argc, "vrf", &idx_vrf)) {
if (ospf_instance != 0) {
vty_out(vty,
"%% VRF is not supported in instance mode\n");
return CMD_WARNING_CONFIG_FAILED;
}
*vrf_name = argv[idx_vrf + 1]->arg;
if (*vrf_name && strmatch(*vrf_name, VRF_DEFAULT_NAME))
*vrf_name = NULL;
}
return CMD_SUCCESS;
}
static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty,
json_object *json, uint8_t use_vrf)
{
if (use_vrf) {
if (json) {
if (ospf->vrf_id == VRF_DEFAULT)
json_object_string_add(json, "vrfName",
"default");
else
json_object_string_add(json, "vrfName",
ospf->name);
json_object_int_add(json, "vrfId", ospf->vrf_id);
} else {
if (ospf->vrf_id == VRF_DEFAULT)
vty_out(vty, "VRF Name: %s\n", "default");
else if (ospf->name)
vty_out(vty, "VRF Name: %s\n", ospf->name);
}
}
}
#ifndef VTYSH_EXTRACT_PL
#include "ospfd/ospf_vty_clippy.c"
#endif
DEFUN_NOSH (router_ospf,
router_ospf_cmd,
"router ospf [{(1-65535)|vrf NAME}]",
"Enable a routing process\n"
"Start OSPF configuration\n"
"Instance ID\n"
VRF_CMD_HELP_STR)
{
unsigned short instance;
const char *vrf_name;
bool created = false;
struct ospf *ospf;
int ret;
ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
if (ret != CMD_SUCCESS)
return ret;
if (instance != ospf_instance) {
VTY_PUSH_CONTEXT_NULL(OSPF_NODE);
return CMD_NOT_MY_INSTANCE;
}
ospf = ospf_get(instance, vrf_name, &created);
if (created)
if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
ospf->instance, ospf->name ? ospf->name : "NIL",
ospf->vrf_id, ospf->oi_running);
VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
return ret;
}
DEFUN (no_router_ospf,
no_router_ospf_cmd,
"no router ospf [{(1-65535)|vrf NAME}]",
NO_STR
"Enable a routing process\n"
"Start OSPF configuration\n"
"Instance ID\n"
VRF_CMD_HELP_STR)
{
unsigned short instance;
const char *vrf_name;
struct ospf *ospf;
int ret;
ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
if (ret != CMD_SUCCESS)
return ret;
if (instance != ospf_instance)
return CMD_NOT_MY_INSTANCE;
ospf = ospf_lookup(instance, vrf_name);
if (ospf)
ospf_finish(ospf);
else
ret = CMD_WARNING_CONFIG_FAILED;
return ret;
}
DEFPY (ospf_router_id,
ospf_router_id_cmd,
"ospf router-id A.B.C.D",
"OSPF specific commands\n"
"router-id for the OSPF process\n"
"OSPF router-id in IP address format\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
struct listnode *node;
struct ospf_area *area;
ospf->router_id_static = router_id;
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
if (area->full_nbrs) {
vty_out(vty,
"For this router-id change to take effect, use \"clear ip ospf process\" command\n");
return CMD_SUCCESS;
}
ospf_router_id_update(ospf);
return CMD_SUCCESS;
}
DEFUN_HIDDEN (ospf_router_id_old,
ospf_router_id_old_cmd,
"router-id A.B.C.D",
"router-id for the OSPF process\n"
"OSPF router-id in IP address format\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4 = 1;
struct listnode *node;
struct ospf_area *area;
struct in_addr router_id;
int ret;
ret = inet_aton(argv[idx_ipv4]->arg, &router_id);
if (!ret) {
vty_out(vty, "Please specify Router ID by A.B.C.D\n");
return CMD_WARNING_CONFIG_FAILED;
}
ospf->router_id_static = router_id;
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
if (area->full_nbrs) {
vty_out(vty,
"For this router-id change to take effect, use \"clear ip ospf process\" command\n");
return CMD_SUCCESS;
}
ospf_router_id_update(ospf);
return CMD_SUCCESS;
}
DEFPY (no_ospf_router_id,
no_ospf_router_id_cmd,
"no ospf router-id [A.B.C.D]",
NO_STR
"OSPF specific commands\n"
"router-id for the OSPF process\n"
"OSPF router-id in IP address format\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
struct listnode *node;
struct ospf_area *area;
if (router_id_str) {
if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) {
vty_out(vty, "%% OSPF router-id doesn't match\n");
return CMD_WARNING_CONFIG_FAILED;
}
}
ospf->router_id_static.s_addr = 0;
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
if (area->full_nbrs) {
vty_out(vty,
"For this router-id change to take effect, use \"clear ip ospf process\" command\n");
return CMD_SUCCESS;
}
ospf_router_id_update(ospf);
return CMD_SUCCESS;
}
static void ospf_passive_interface_default_update(struct ospf *ospf,
uint8_t newval)
{
struct listnode *ln;
struct ospf_interface *oi;
ospf->passive_interface_default = newval;
/* update multicast memberships */
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi))
ospf_if_set_multicast(oi);
}
static void ospf_passive_interface_update(struct interface *ifp,
struct ospf_if_params *params,
struct in_addr addr, uint8_t newval)
{
struct route_node *rn;
if (OSPF_IF_PARAM_CONFIGURED(params, passive_interface)) {
if (params->passive_interface == newval)
return;
params->passive_interface = newval;
UNSET_IF_PARAM(params, passive_interface);
if (params != IF_DEF_PARAMS(ifp)) {
ospf_free_if_params(ifp, addr);
ospf_if_update_params(ifp, addr);
}
} else {
params->passive_interface = newval;
SET_IF_PARAM(params, passive_interface);
}
/*
* XXX We should call ospf_if_set_multicast on exactly those
* interfaces for which the passive property changed. It is too much
* work to determine this set, so we do this for every interface.
* This is safe and reasonable because ospf_if_set_multicast uses a
* record of joined groups to avoid systems calls if the desired
* memberships match the current memership.
*/
for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
struct ospf_interface *oi = rn->info;
if (oi)
ospf_if_set_multicast(oi);
}
/*
* XXX It is not clear what state transitions the interface needs to
* undergo when going from active to passive and vice versa. Fixing
* this will require precise identification of interfaces having such a
* transition.
*/
}
DEFUN (ospf_passive_interface_default,
ospf_passive_interface_default_cmd,
"passive-interface default",
"Suppress routing updates on an interface\n"
"Suppress routing updates on interfaces by default\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
ospf_passive_interface_default_update(ospf, OSPF_IF_PASSIVE);
return CMD_SUCCESS;
}
DEFUN_HIDDEN (ospf_passive_interface_addr,
ospf_passive_interface_addr_cmd,
"passive-interface IFNAME [A.B.C.D]",
"Suppress routing updates on an interface\n"
"Interface's name\n"
"IPv4 address\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4 = 2;
struct interface *ifp = NULL;
struct in_addr addr = {.s_addr = INADDR_ANY};
struct ospf_if_params *params;
int ret;
vty_out(vty,
"This command is deprecated, because it is not VRF-aware.\n");
vty_out(vty,
"Please, use \"ip ospf passive\" on an interface instead.\n");
if (ospf->vrf_id != VRF_UNKNOWN)
ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id);
if (ifp == NULL) {
vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
if (argc == 3) {
ret = inet_aton(argv[idx_ipv4]->arg, &addr);
if (!ret) {
vty_out(vty,
"Please specify interface address by A.B.C.D\n");
return CMD_WARNING_CONFIG_FAILED;
}
params = ospf_get_if_params(ifp, addr);
ospf_if_update_params(ifp, addr);
} else {
params = IF_DEF_PARAMS(ifp);
}
ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE);
return CMD_SUCCESS;
}
DEFUN (no_ospf_passive_interface_default,
no_ospf_passive_interface_default_cmd,
"no passive-interface default",
NO_STR
"Allow routing updates on an interface\n"
"Allow routing updates on interfaces by default\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
ospf_passive_interface_default_update(ospf, OSPF_IF_ACTIVE);
return CMD_SUCCESS;
}
DEFUN_HIDDEN (no_ospf_passive_interface,
no_ospf_passive_interface_addr_cmd,
"no passive-interface IFNAME [A.B.C.D]",
NO_STR
"Allow routing updates on an interface\n"
"Interface's name\n"
"IPv4 address\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4 = 3;
struct interface *ifp = NULL;
struct in_addr addr = {.s_addr = INADDR_ANY};
struct ospf_if_params *params;
int ret;
vty_out(vty,
"This command is deprecated, because it is not VRF-aware.\n");
vty_out(vty,
"Please, use \"no ip ospf passive\" on an interface instead.\n");
if (ospf->vrf_id != VRF_UNKNOWN)
ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id);
if (ifp == NULL) {
vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
if (argc == 4) {
ret = inet_aton(argv[idx_ipv4]->arg, &addr);
if (!ret) {
vty_out(vty,
"Please specify interface address by A.B.C.D\n");
return CMD_WARNING_CONFIG_FAILED;
}
params = ospf_lookup_if_params(ifp, addr);
if (params == NULL)
return CMD_SUCCESS;
} else {
params = IF_DEF_PARAMS(ifp);
}
ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE);
return CMD_SUCCESS;
}
DEFUN (ospf_network_area,
ospf_network_area_cmd,
"network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
"Enable routing on an IP network\n"
"OSPF network prefix\n"
"Set the OSPF area ID\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4_prefixlen = 1;
int idx_ipv4_number = 3;
struct prefix_ipv4 p;
struct in_addr area_id;
int ret, format;
uint32_t count;
if (ospf->instance) {
vty_out(vty,
"The network command is not supported in multi-instance ospf\n");
return CMD_WARNING_CONFIG_FAILED;
}
count = ospf_count_area_params(ospf);
if (count > 0) {
vty_out(vty,
"Please remove all ip ospf area x.x.x.x commands first.\n");
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"%s ospf vrf %s num of %u ip ospf area x config",
__func__, ospf->name ? ospf->name : "NIL",
count);
return CMD_WARNING_CONFIG_FAILED;
}
/* Get network prefix and Area ID. */
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
ret = ospf_network_set(ospf, &p, area_id, format);
if (ret == 0) {
vty_out(vty, "There is already same network statement.\n");
return CMD_WARNING_CONFIG_FAILED;
}
return CMD_SUCCESS;
}
DEFUN (no_ospf_network_area,
no_ospf_network_area_cmd,
"no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
NO_STR
"Enable routing on an IP network\n"
"OSPF network prefix\n"
"Set the OSPF area ID\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4_prefixlen = 2;
int idx_ipv4_number = 4;
struct prefix_ipv4 p;
struct in_addr area_id;
int ret, format;
if (ospf->instance) {
vty_out(vty,
"The network command is not supported in multi-instance ospf\n");
return CMD_WARNING_CONFIG_FAILED;
}
/* Get network prefix and Area ID. */
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
ret = ospf_network_unset(ospf, &p, area_id);
if (ret == 0) {
vty_out(vty,
"Can't find specified network area configuration.\n");
return CMD_WARNING_CONFIG_FAILED;
}
return CMD_SUCCESS;
}
DEFUN (ospf_area_range,
ospf_area_range_cmd,
"area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
"Summarize routes matching address/mask (border routers only)\n"
"Area range prefix\n"
"Advertise this range (default)\n"
"User specified metric for this range\n"
"Advertised metric for this range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4_number = 1;
int idx_ipv4_prefixlen = 3;
int idx_cost = 6;
struct prefix_ipv4 p;
struct in_addr area_id;
int format;
uint32_t cost;
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
format);
if (argc > 5) {
cost = strtoul(argv[idx_cost]->arg, NULL, 10);
ospf_area_range_cost_set(ospf, area_id, &p, cost);
}
return CMD_SUCCESS;
}
DEFUN (ospf_area_range_cost,
ospf_area_range_cost_cmd,
"area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
"Summarize routes matching address/mask (border routers only)\n"
"Area range prefix\n"
"User specified metric for this range\n"
"Advertised metric for this range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4_number = 1;
int idx_ipv4_prefixlen = 3;
int idx_cost = 5;
struct prefix_ipv4 p;
struct in_addr area_id;
int format;
uint32_t cost;
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
format);
cost = strtoul(argv[idx_cost]->arg, NULL, 10);
ospf_area_range_cost_set(ospf, area_id, &p, cost);
return CMD_SUCCESS;
}
DEFUN (ospf_area_range_not_advertise,
ospf_area_range_not_advertise_cmd,
"area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
"Summarize routes matching address/mask (border routers only)\n"
"Area range prefix\n"
"DoNotAdvertise this range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4_number = 1;
int idx_ipv4_prefixlen = 3;
struct prefix_ipv4 p;
struct in_addr area_id;
int format;
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
ospf_area_range_set(ospf, area_id, &p, 0);
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
format);
ospf_area_range_substitute_unset(ospf, area_id, &p);
return CMD_SUCCESS;
}
DEFUN (no_ospf_area_range,
no_ospf_area_range_cmd,
"no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
NO_STR
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
"Summarize routes matching address/mask (border routers only)\n"
"Area range prefix\n"
"User specified metric for this range\n"
"Advertised metric for this range\n"
"Advertise this range (default)\n"
"User specified metric for this range\n"
"Advertised metric for this range\n"
"DoNotAdvertise this range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4_number = 2;
int idx_ipv4_prefixlen = 4;
struct prefix_ipv4 p;
struct in_addr area_id;
int format;
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
ospf_area_range_unset(ospf, area_id, &p);
return CMD_SUCCESS;
}
DEFUN (ospf_area_range_substitute,
ospf_area_range_substitute_cmd,
"area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
"Summarize routes matching address/mask (border routers only)\n"
"Area range prefix\n"
"Announce area range as another prefix\n"
"Network prefix to be announced instead of range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4_number = 1;
int idx_ipv4_prefixlen = 3;
int idx_ipv4_prefixlen_2 = 5;
struct prefix_ipv4 p, s;
struct in_addr area_id;
int format;
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s);
ospf_area_range_substitute_set(ospf, area_id, &p, &s);
ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
format);
return CMD_SUCCESS;
}
DEFUN (no_ospf_area_range_substitute,
no_ospf_area_range_substitute_cmd,
"no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
NO_STR
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
"Summarize routes matching address/mask (border routers only)\n"
"Area range prefix\n"
"Announce area range as another prefix\n"
"Network prefix to be announced instead of range\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
int idx_ipv4_number = 2;
int idx_ipv4_prefixlen = 4;
int idx_ipv4_prefixlen_2 = 6;
struct prefix_ipv4 p, s;
struct in_addr area_id;
int format;
VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s);
ospf_area_range_substitute_unset(ospf, area_id, &p);
return CMD_SUCCESS;
}
/* Command Handler Logic in VLink stuff is delicate!!
ALTER AT YOUR OWN RISK!!!!
Various dummy values are used to represent 'NoChange' state for
VLink configuration NOT being changed by a VLink command, and
special syntax is used within the command strings so that the
typed in command verbs can be seen in the configuration command
bacckend handler. This is to drastically reduce the verbeage
required to coe up with a reasonably compatible Cisco VLink command
- Matthew Grant <grantma@anathoth.gen.nz>
Wed, 21 Feb 2001 15:13:52 +1300
*/
/* Configuration data for virtual links
*/
struct ospf_vl_config_data {
struct vty *vty; /* vty stuff */
struct in_addr area_id; /* area ID from command line */
int area_id_fmt; /* command line area ID format */
struct in_addr vl_peer; /* command line vl_peer */
int auth_type; /* Authehntication type, if given */
char *auth_key; /* simple password if present */
int crypto_key_id; /* Cryptographic key ID */
char *md5_key; /* MD5 authentication key */
int hello_interval; /* Obvious what these are... */
int retransmit_interval;
int transmit_delay;
int dead_interval;
};
static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config,
struct vty *vty)
{
memset(vl_config, 0, sizeof(struct ospf_vl_config_data));
vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN;
vl_config->vty = vty;
}
static struct ospf_vl_data *
ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config)
{
struct ospf_area *area;
struct ospf_vl_data *vl_data;
struct vty *vty;
struct in_addr area_id;
vty = vl_config->vty;
area_id = vl_config->area_id;
if (area_id.s_addr == OSPF_AREA_BACKBONE) {
vty_out(vty,
"Configuring VLs over the backbone is not allowed\n");
return NULL;
}
area = ospf_area_get(ospf, area_id);
ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt);
if (area->external_routing != OSPF_AREA_DEFAULT) {
if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
vty_out(vty, "Area %pI4 is %s\n", &area_id,
area->external_routing == OSPF_AREA_NSSA
? "nssa"
: "stub");
else
vty_out(vty, "Area %ld is %s\n",
(unsigned long)ntohl(area_id.s_addr),
area->external_routing == OSPF_AREA_NSSA
? "nssa"
: "stub");
return NULL;
}
if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer))
== NULL) {
vl_data = ospf_vl_data_new(area, vl_config->vl_peer);
if (vl_data->vl_oi == NULL) {
vl_data->vl_oi = ospf_vl_new(ospf, vl_data);
ospf_vl_add(ospf, vl_data);
ospf_spf_calculate_schedule(ospf,
SPF_FLAG_CONFIG_CHANGE);
}
}
return vl_data;
}
static int ospf_vl_set_security(struct ospf_vl_data *vl_data,
struct ospf_vl_config_data *vl_config)
{
struct crypt_key *ck;
struct vty *vty;
struct interface *ifp = vl_data->vl_oi->ifp;
vty = vl_config->vty;
if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) {
SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type);
IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type;
}
if (vl_config->auth_key) {
memset(IF_DEF_PARAMS(ifp)->auth_simple, 0,
OSPF_AUTH_SIMPLE_SIZE + 1);
strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple,
vl_config->auth_key,
sizeof(IF_DEF_PARAMS(ifp)->auth_simple));
} else if (vl_config->md5_key) {
if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt,
vl_config->crypto_key_id)
!= NULL) {
vty_out(vty, "OSPF: Key %d already exists\n",
vl_config->crypto_key_id);
return CMD_WARNING;
}
ck = ospf_crypt_key_new();
ck->key_id = vl_config->crypto_key_id;
memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
strlcpy((char *)ck->auth_key, vl_config->md5_key,
sizeof(ck->auth_key));
ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck);
} else if (vl_config->crypto_key_id != 0) {
/* Delete a key */
if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt,
vl_config->crypto_key_id)
== NULL) {
vty_out(vty, "OSPF: Key %d does not exist\n",
vl_config->crypto_key_id);
return CMD_WARNING_CONFIG_FAILED;
}
ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt,
vl_config->crypto_key_id);
}
return CMD_SUCCESS;
}
static int ospf_vl_set_timers(struct ospf_vl_data *vl_data,
struct ospf_vl_config_data *vl_config)
{
struct interface *ifp = vl_data->vl_oi->ifp;
/* Virtual Link data initialised to defaults, so only set
if a value given */
if (vl_config->hello_interval) {
SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello);
IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval;
}
if (vl_config->dead_interval) {
SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait);
IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval;
}
if (vl_config->retransmit_interval) {
SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval);
IF_DEF_PARAMS(ifp)->retransmit_interval =
vl_config->retransmit_interval;
}
if (vl_config->transmit_delay) {
SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay);
IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay;
}
return CMD_SUCCESS;
}
/* The business end of all of the above */
static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config)
{
struct ospf_vl_data *vl_data;
int ret;
vl_data = ospf_find_vl_data(ospf, vl_config);
if (!vl_data)
return CMD_WARNING_CONFIG_FAILED;
/* Process this one first as it can have a fatal result, which can
only logically occur if the virtual link exists already
Thus a command error does not result in a change to the