diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2023-03-08 01:13:53 +0100 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2023-04-01 00:28:15 +0200 |
commit | 4312d66f9f3dc948f1aa4716b5a6af4e3bbd861f (patch) | |
tree | 427cb768679507fd46a20086eed22b1ed8348959 /ospfd | |
parent | ospfd: use the ospf_area_range_active() helper function more consistently (diff) | |
download | frr-4312d66f9f3dc948f1aa4716b5a6af4e3bbd861f.tar.xz frr-4312d66f9f3dc948f1aa4716b5a6af4e3bbd861f.zip |
ospfd: refactor range commands
* Update the "range" helpers to accept an area pointer instead of
an area ID;
* Always call ospf_area_display_format_set() after every "range"
command to ensure consistency.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'ospfd')
-rw-r--r-- | ospfd/ospf_abr.c | 32 | ||||
-rw-r--r-- | ospfd/ospf_abr.h | 10 | ||||
-rw-r--r-- | ospfd/ospf_vty.c | 43 |
3 files changed, 38 insertions, 47 deletions
diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c index 784496bac..72d231a31 100644 --- a/ospfd/ospf_abr.c +++ b/ospfd/ospf_abr.c @@ -169,16 +169,11 @@ static int ospf_area_actively_attached(struct ospf_area *area) return area->act_ints; } -int ospf_area_range_set(struct ospf *ospf, struct in_addr area_id, +int ospf_area_range_set(struct ospf *ospf, struct ospf_area *area, struct prefix_ipv4 *p, int advertise) { - struct ospf_area *area; struct ospf_area_range *range; - area = ospf_area_get(ospf, area_id); - if (area == NULL) - return 0; - range = ospf_area_range_lookup(area, p); if (range != NULL) { if (!CHECK_FLAG(advertise, OSPF_AREA_RANGE_ADVERTISE)) @@ -204,16 +199,11 @@ int ospf_area_range_set(struct ospf *ospf, struct in_addr area_id, return 1; } -int ospf_area_range_cost_set(struct ospf *ospf, struct in_addr area_id, +int ospf_area_range_cost_set(struct ospf *ospf, struct ospf_area *area, struct prefix_ipv4 *p, uint32_t cost) { - struct ospf_area *area; struct ospf_area_range *range; - area = ospf_area_get(ospf, area_id); - if (area == NULL) - return 0; - range = ospf_area_range_lookup(area, p); if (range == NULL) return 0; @@ -227,16 +217,11 @@ int ospf_area_range_cost_set(struct ospf *ospf, struct in_addr area_id, return 1; } -int ospf_area_range_unset(struct ospf *ospf, struct in_addr area_id, +int ospf_area_range_unset(struct ospf *ospf, struct ospf_area *area, struct prefix_ipv4 *p) { - struct ospf_area *area; struct route_node *rn; - area = ospf_area_lookup_by_area_id(ospf, area_id); - if (area == NULL) - return 0; - rn = route_node_lookup(area->ranges, (struct prefix *)p); if (rn == NULL) return 0; @@ -249,13 +234,11 @@ int ospf_area_range_unset(struct ospf *ospf, struct in_addr area_id, return 1; } -int ospf_area_range_substitute_set(struct ospf *ospf, struct in_addr area_id, +int ospf_area_range_substitute_set(struct ospf *ospf, struct ospf_area *area, struct prefix_ipv4 *p, struct prefix_ipv4 *s) { - struct ospf_area *area; struct ospf_area_range *range; - area = ospf_area_get(ospf, area_id); range = ospf_area_range_lookup(area, p); if (range != NULL) { @@ -276,16 +259,11 @@ int ospf_area_range_substitute_set(struct ospf *ospf, struct in_addr area_id, return 1; } -int ospf_area_range_substitute_unset(struct ospf *ospf, struct in_addr area_id, +int ospf_area_range_substitute_unset(struct ospf *ospf, struct ospf_area *area, struct prefix_ipv4 *p) { - struct ospf_area *area; struct ospf_area_range *range; - area = ospf_area_lookup_by_area_id(ospf, area_id); - if (area == NULL) - return 0; - range = ospf_area_range_lookup(area, p); if (range == NULL) return 0; diff --git a/ospfd/ospf_abr.h b/ospfd/ospf_abr.h index b1ff76f8f..d3a82bf85 100644 --- a/ospfd/ospf_abr.h +++ b/ospfd/ospf_abr.h @@ -51,16 +51,16 @@ extern struct ospf_area_range *ospf_some_area_range_match(struct prefix_ipv4 *); extern struct ospf_area_range * ospf_area_range_lookup_next(struct ospf_area *, struct in_addr *, int); -extern int ospf_area_range_set(struct ospf *, struct in_addr, +extern int ospf_area_range_set(struct ospf *, struct ospf_area *, struct prefix_ipv4 *, int); -extern int ospf_area_range_cost_set(struct ospf *, struct in_addr, +extern int ospf_area_range_cost_set(struct ospf *, struct ospf_area *, struct prefix_ipv4 *, uint32_t); -extern int ospf_area_range_unset(struct ospf *, struct in_addr, +extern int ospf_area_range_unset(struct ospf *, struct ospf_area *, struct prefix_ipv4 *); -extern int ospf_area_range_substitute_set(struct ospf *, struct in_addr, +extern int ospf_area_range_substitute_set(struct ospf *, struct ospf_area *, struct prefix_ipv4 *, struct prefix_ipv4 *); -extern int ospf_area_range_substitute_unset(struct ospf *, struct in_addr, +extern int ospf_area_range_substitute_unset(struct ospf *, struct ospf_area *, struct prefix_ipv4 *); extern struct ospf_area_range *ospf_area_range_match_any(struct ospf *, struct prefix_ipv4 *); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 8a6a91380..85a907765 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -611,6 +611,7 @@ DEFUN (ospf_area_range, "Advertised metric for this range\n") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); + struct ospf_area *area; int idx_ipv4_number = 1; int idx_ipv4_prefixlen = 3; int idx_cost = 6; @@ -622,12 +623,13 @@ DEFUN (ospf_area_range, 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); + area = ospf_area_get(ospf, area_id); + ospf_area_display_format_set(ospf, area, format); + + ospf_area_range_set(ospf, area, &p, OSPF_AREA_RANGE_ADVERTISE); if (argc > 5) { cost = strtoul(argv[idx_cost]->arg, NULL, 10); - ospf_area_range_cost_set(ospf, area_id, &p, cost); + ospf_area_range_cost_set(ospf, area, &p, cost); } return CMD_SUCCESS; @@ -647,6 +649,7 @@ DEFUN (ospf_area_range_cost, "Network prefix to be announced instead of range\n") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); + struct ospf_area *area; int idx_ipv4_number = 1; int idx_ipv4_prefixlen = 3; int idx = 4; @@ -658,19 +661,19 @@ DEFUN (ospf_area_range_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); + area = ospf_area_get(ospf, area_id); + ospf_area_display_format_set(ospf, area, format); + ospf_area_range_set(ospf, area, &p, OSPF_AREA_RANGE_ADVERTISE); if (argv_find(argv, argc, "cost", &idx)) { cost = strtoul(argv[idx + 1]->arg, NULL, 10); - ospf_area_range_cost_set(ospf, area_id, &p, cost); + ospf_area_range_cost_set(ospf, area, &p, cost); } idx = 4; if (argv_find(argv, argc, "substitute", &idx)) { str2prefix_ipv4(argv[idx + 1]->arg, &s); - ospf_area_range_substitute_set(ospf, area_id, &p, &s); + ospf_area_range_substitute_set(ospf, area, &p, &s); } return CMD_SUCCESS; @@ -687,6 +690,7 @@ DEFUN (ospf_area_range_not_advertise, "DoNotAdvertise this range\n") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); + struct ospf_area *area; int idx_ipv4_number = 1; int idx_ipv4_prefixlen = 3; struct prefix_ipv4 p; @@ -696,10 +700,11 @@ DEFUN (ospf_area_range_not_advertise, 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); + area = ospf_area_get(ospf, area_id); + ospf_area_display_format_set(ospf, area, format); + + ospf_area_range_set(ospf, area, &p, 0); + ospf_area_range_substitute_unset(ospf, area, &p); return CMD_SUCCESS; } @@ -721,6 +726,7 @@ DEFUN (no_ospf_area_range, "DoNotAdvertise this range\n") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); + struct ospf_area *area; int idx_ipv4_number = 2; int idx_ipv4_prefixlen = 4; struct prefix_ipv4 p; @@ -730,7 +736,10 @@ DEFUN (no_ospf_area_range, 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); + area = ospf_area_get(ospf, area_id); + ospf_area_display_format_set(ospf, area, format); + + ospf_area_range_unset(ospf, area, &p); return CMD_SUCCESS; } @@ -748,6 +757,7 @@ DEFUN (no_ospf_area_range_substitute, "Network prefix to be announced instead of range\n") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); + struct ospf_area *area; int idx_ipv4_number = 2; int idx_ipv4_prefixlen = 4; int idx_ipv4_prefixlen_2 = 6; @@ -759,7 +769,10 @@ DEFUN (no_ospf_area_range_substitute, 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); + area = ospf_area_get(ospf, area_id); + ospf_area_display_format_set(ospf, area, format); + + ospf_area_range_substitute_unset(ospf, area, &p); return CMD_SUCCESS; } |