diff options
author | Russ White <russ@riw.us> | 2022-01-18 15:08:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-18 15:08:38 +0100 |
commit | 05786ac7744a6077a7f5aff9d2bfe1c92e54e17c (patch) | |
tree | 7b25f5cda483135e144e490d3e8ac970b5781d7f /ospfd | |
parent | Merge pull request #10276 from patrasar/mld_northbound (diff) | |
parent | tests: check if OSPF opaque attributes are installed in the RIB (diff) | |
download | frr-05786ac7744a6077a7f5aff9d2bfe1c92e54e17c.tar.xz frr-05786ac7744a6077a7f5aff9d2bfe1c92e54e17c.zip |
Merge pull request #9644 from opensourcerouting/ospf-opaque-attrs
OSPF opaque route attributes
Diffstat (limited to 'ospfd')
-rw-r--r-- | ospfd/ospf_route.c | 16 | ||||
-rw-r--r-- | ospfd/ospf_route.h | 1 | ||||
-rw-r--r-- | ospfd/ospf_vty.c | 54 | ||||
-rw-r--r-- | ospfd/ospf_zebra.c | 36 | ||||
-rw-r--r-- | ospfd/ospfd.c | 2 | ||||
-rw-r--r-- | ospfd/ospfd.h | 1 |
6 files changed, 110 insertions, 0 deletions
diff --git a/ospfd/ospf_route.c b/ospfd/ospf_route.c index 502a4a08c..ec0c5524c 100644 --- a/ospfd/ospf_route.c +++ b/ospfd/ospf_route.c @@ -39,6 +39,22 @@ #include "ospfd/ospf_zebra.h" #include "ospfd/ospf_dump.h" +const char *ospf_path_type_name(int path_type) +{ + switch (path_type) { + case OSPF_PATH_INTRA_AREA: + return "Intra-Area"; + case OSPF_PATH_INTER_AREA: + return "Inter-Area"; + case OSPF_PATH_TYPE1_EXTERNAL: + return "External-1"; + case OSPF_PATH_TYPE2_EXTERNAL: + return "External-2"; + default: + return "Unknown"; + } +} + struct ospf_route *ospf_route_new(void) { struct ospf_route *new; diff --git a/ospfd/ospf_route.h b/ospfd/ospf_route.h index c2ce0569d..5463e70ff 100644 --- a/ospfd/ospf_route.h +++ b/ospfd/ospf_route.h @@ -128,6 +128,7 @@ struct ospf_route { bool changed; }; +extern const char *ospf_path_type_name(int path_type); extern struct ospf_path *ospf_path_new(void); extern void ospf_path_free(struct ospf_path *); extern struct ospf_path *ospf_path_lookup(struct list *, struct ospf_path *); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 1a20eb515..3d0804b01 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -2218,6 +2218,53 @@ ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, "OSPF specific commands\n" "Disable the RFC1583Compatibility flag\n") +static void ospf_table_reinstall_routes(struct ospf *ospf, + struct route_table *rt) +{ + struct route_node *rn; + + for (rn = route_top(rt); rn; rn = route_next(rn)) { + struct ospf_route *or; + + or = rn->info; + if (!or) + continue; + + if (or->type == OSPF_DESTINATION_NETWORK) + ospf_zebra_add(ospf, (struct prefix_ipv4 *)&rn->p, or); + else if (or->type == OSPF_DESTINATION_DISCARD) + ospf_zebra_add_discard(ospf, + (struct prefix_ipv4 *)&rn->p); + } +} + +static void ospf_reinstall_routes(struct ospf *ospf) +{ + ospf_table_reinstall_routes(ospf, ospf->new_table); + ospf_table_reinstall_routes(ospf, ospf->new_external_route); +} + +DEFPY (ospf_send_extra_data, + ospf_send_extra_data_cmd, + "[no] ospf send-extra-data zebra", + NO_STR + OSPF_STR + "Extra data to Zebra for display/use\n" + "To zebra\n") +{ + VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); + + if (no && CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) { + UNSET_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA); + ospf_reinstall_routes(ospf); + } else if (!CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) { + SET_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA); + ospf_reinstall_routes(ospf); + } + + return CMD_SUCCESS; +} + static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, unsigned int hold, unsigned int max) { @@ -12212,6 +12259,10 @@ static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) vty_out(vty, " ospf router-id %pI4\n", &ospf->router_id_static); + /* zebra opaque attributes configuration. */ + if (!CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) + vty_out(vty, " no ospf send-extra-data zebra\n"); + /* ABR type print. */ if (ospf->abr_type != OSPF_ABR_DEFAULT) vty_out(vty, " ospf abr-type %s\n", @@ -12663,6 +12714,9 @@ void ospf_vty_init(void) install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); + /* "ospf send-extra-data zebra" commands. */ + install_element(OSPF_NODE, &ospf_send_extra_data_cmd); + /* "network area" commands. */ install_element(OSPF_NODE, &ospf_network_area_cmd); install_element(OSPF_NODE, &no_ospf_network_area_cmd); diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index b0ed66da5..7834b7d93 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -33,6 +33,7 @@ #include "filter.h" #include "plist.h" #include "log.h" +#include "route_opaque.h" #include "lib/bfd.h" #include "nexthop.h" @@ -255,6 +256,38 @@ static void ospf_zebra_add_nexthop(struct ospf *ospf, struct ospf_path *path, api->nexthop_num++; } +static void ospf_zebra_append_opaque_attr(struct ospf_route *or, + struct zapi_route *api) +{ + struct ospf_zebra_opaque ospf_opaque = {}; + + /* OSPF path type */ + snprintf(ospf_opaque.path_type, sizeof(ospf_opaque.path_type), "%s", + ospf_path_type_name(or->path_type)); + + switch (or->path_type) { + case OSPF_PATH_INTRA_AREA: + case OSPF_PATH_INTER_AREA: + /* OSPF area ID */ + (void)inet_ntop(AF_INET, &or->u.std.area_id, + ospf_opaque.area_id, + sizeof(ospf_opaque.area_id)); + break; + case OSPF_PATH_TYPE1_EXTERNAL: + case OSPF_PATH_TYPE2_EXTERNAL: + /* OSPF route tag */ + snprintf(ospf_opaque.tag, sizeof(ospf_opaque.tag), "%u", + or->u.ext.tag); + break; + default: + break; + } + + SET_FLAG(api->message, ZAPI_MESSAGE_OPAQUE); + api->opaque.length = sizeof(struct ospf_zebra_opaque); + memcpy(api->opaque.data, &ospf_opaque, api->opaque.length); +} + void ospf_zebra_add(struct ospf *ospf, struct prefix_ipv4 *p, struct ospf_route * or) { @@ -322,6 +355,9 @@ void ospf_zebra_add(struct ospf *ospf, struct prefix_ipv4 *p, } } + if (CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) + ospf_zebra_append_opaque_attr(or, &api); + zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); } diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index e5f3eec60..726ce329e 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -406,6 +406,8 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name) ospf_opaque_type11_lsa_init(new); + SET_FLAG(new->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA); + QOBJ_REG(new, ospf); new->fd = -1; diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index d64a044e1..3369429eb 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -125,6 +125,7 @@ enum { OSPF_OPAQUE_CAPABLE = (1 << 2), OSPF_LOG_ADJACENCY_CHANGES = (1 << 3), OSPF_LOG_ADJACENCY_DETAIL = (1 << 4), + OSPF_SEND_EXTRA_DATA_TO_ZEBRA = (1 << 5), }; /* TI-LFA */ |