diff options
-rw-r--r-- | ospfd/.gitignore | 1 | ||||
-rw-r--r-- | ospfd/ospf_routemap.c | 2 | ||||
-rw-r--r-- | ospfd/ospf_te.c | 11 | ||||
-rw-r--r-- | ospfd/ospf_vty.c | 875 | ||||
-rw-r--r-- | ospfd/ospf_zebra.c | 10 | ||||
-rw-r--r-- | ospfd/ospfd.c | 14 | ||||
-rw-r--r-- | ospfd/ospfd.h | 5 | ||||
-rw-r--r-- | ospfd/subdir.am | 3 |
8 files changed, 474 insertions, 447 deletions
diff --git a/ospfd/.gitignore b/ospfd/.gitignore index 752c875a6..018a363a9 100644 --- a/ospfd/.gitignore +++ b/ospfd/.gitignore @@ -15,3 +15,4 @@ TAGS *~ *.loT *.a +*.clippy.c diff --git a/ospfd/ospf_routemap.c b/ospfd/ospf_routemap.c index c3ba1d93b..b7a47602d 100644 --- a/ospfd/ospf_routemap.c +++ b/ospfd/ospf_routemap.c @@ -51,7 +51,7 @@ static void ospf_route_map_update(const char *name) if (listcount(om->ospf) == 0) return; - for (ALL_LIST_ELEMENTS_RO (om->ospf, n1, ospf)) { + for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) { /* Update route-map */ for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) { struct list *red_list; diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 4d6fc37e7..294ffe48b 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -2570,10 +2570,13 @@ DEFUN (show_ip_ospf_mpls_te_link, } /* Show All Interfaces. */ if (argc == 5) { - ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); - for (ALL_LIST_ELEMENTS(vrf_iflist(ospf->vrf_id), node, nnode, - ifp)) - show_mpls_te_link_sub(vty, ifp); + for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) { + if (!ospf->oi_running) + continue; + for (ALL_LIST_ELEMENTS(vrf_iflist(ospf->vrf_id), node, + nnode, ifp)) + show_mpls_te_link_sub(vty, ifp); + } } /* Interface name is specified. */ else { diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index d38a4ee73..ebc684f3d 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -126,36 +126,70 @@ int ospf_oi_count(struct interface *ifp) return i; } -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) +#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 struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, + struct cmd_token *argv[], + const int argc, + uint32_t enable, + u_short *instance) { struct ospf *ospf = NULL; - u_short instance = 0; - int ret = CMD_SUCCESS; int idx_vrf = 0; const char *vrf_name = NULL; if (argv_find(argv, argc, "vrf", &idx_vrf)) { - if (argc > 4) - instance = strtoul(argv[2]->arg, NULL, 10); vrf_name = argv[idx_vrf + 1]->arg; - /* Allocate VRF aware instance */ - ospf = ospf_get(instance, vrf_name); + if (enable) { + if (argc > 4) + *instance = strtoul(argv[2]->arg, NULL, 10); + /* Allocate VRF aware instance */ + ospf = ospf_get(*instance, vrf_name); + } else { + if (argc > 5) + *instance = strtoul(argv[3]->arg, NULL, 10); + ospf = ospf_lookup_by_inst_name(*instance, vrf_name); + } } else { - ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); - if (!ospf) { - vty_out(vty, "There isn't active ospf instance\n"); - return CMD_WARNING_CONFIG_FAILED; + if (enable) { + ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); + if (!ospf) + vty_out(vty, + "There isn't active ospf instance\n"); + if (argc > 2) + *instance = strtoul(argv[2]->arg, NULL, 10); + } else { + if (argc > 3) + *instance = strtoul(argv[3]->arg, NULL, 10); + ospf = ospf_lookup_instance(*instance); } - - if (argc > 2) - instance = strtoul(argv[2]->arg, NULL, 10); } + return ospf; +} + +#ifndef VTYSH_EXTRACT_PL +#include "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) +{ + struct ospf *ospf = NULL; + int ret = CMD_SUCCESS; + u_short instance = 0; + + ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance); + if (!ospf) + return CMD_WARNING_CONFIG_FAILED; /* The following logic to set the vty qobj index is in place to be able to ignore the commands which dont belong to this instance. */ @@ -178,7 +212,7 @@ DEFUN_NOSH (router_ospf, DEFUN (no_router_ospf, no_router_ospf_cmd, - "no router ospf [(1-65535)] [vrf NAME]", + "no router ospf [{(1-65535)|vrf NAME}]", NO_STR "Enable a routing process\n" "Start OSPF configuration\n" @@ -187,32 +221,21 @@ DEFUN (no_router_ospf, { struct ospf *ospf; u_short instance = 0; - int idx_vrf = 0; - const char *vrf_name = NULL; - if (argv_find(argv, argc, "vrf", &idx_vrf)) { - if (argc > 5) - instance = strtoul(argv[3]->arg, NULL, 10); - vrf_name = argv[idx_vrf + 1]->arg; - ospf = ospf_lookup_by_inst_name(instance, vrf_name); - if (ospf == NULL) - return CMD_SUCCESS; - } else { - if (argc > 3) - instance = strtoul(argv[3]->arg, NULL, 10); - - ospf = ospf_lookup_instance(instance); - if (ospf == NULL) + ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance); + if (ospf == NULL) { + if (instance) return CMD_NOT_MY_INSTANCE; + else + return CMD_WARNING; } - ospf_finish(ospf); return CMD_SUCCESS; } -DEFUN (ospf_router_id, +DEFPY (ospf_router_id, ospf_router_id_cmd, "ospf router-id A.B.C.D", "OSPF specific commands\n" @@ -220,17 +243,9 @@ DEFUN (ospf_router_id, "OSPF router-id in IP address format\n") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); - int idx_ipv4 = 2; + 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; @@ -281,7 +296,7 @@ DEFUN_HIDDEN (ospf_router_id_old, return CMD_SUCCESS; } -DEFUN (no_ospf_router_id, +DEFPY (no_ospf_router_id, no_ospf_router_id_cmd, "no ospf router-id [A.B.C.D]", NO_STR @@ -293,6 +308,13 @@ DEFUN (no_ospf_router_id, 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)) @@ -3157,10 +3179,7 @@ DEFUN (show_ip_ospf, if (listcount(om->ospf) == 0) return CMD_SUCCESS; - if (argv_find(argv, argc, "vrf", &idx_vrf)) { - vrf_name = argv[idx_vrf + 1]->arg; - all_vrf = strmatch(vrf_name, "all"); - } + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { @@ -3606,11 +3625,12 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, DEFUN (show_ip_ospf_interface, show_ip_ospf_interface_cmd, - "show ip ospf [vrf NAME] interface [INTERFACE] [json]", + "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", SHOW_STR IP_STR "OSPF information\n" VRF_CMD_HELP_STR + "All VRFs\n" "Interface information\n" "Interface name\n" JSON_STR) @@ -3624,10 +3644,8 @@ DEFUN (show_ip_ospf_interface, int inst = 0; int idx_vrf = 0; - if (argv_find(argv, argc, "vrf", &idx_vrf)) { - vrf_name = argv[idx_vrf + 1]->arg; - all_vrf = strmatch(vrf_name, "all"); - } + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (uj) argc--; @@ -3872,10 +3890,7 @@ DEFUN (show_ip_ospf_neighbor, int inst = 0; int idx_vrf = 0; - if (argv_find(argv, argc, "vrf", &idx_vrf)) { - vrf_name = argv[idx_vrf + 1]->arg; - all_vrf = strmatch(vrf_name, "all"); - } + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); if (!uj) show_ip_ospf_neighbour_header(vty); @@ -4051,10 +4066,7 @@ DEFUN (show_ip_ospf_neighbor_all, int inst = 0; int idx_vrf = 0; - if (argv_find(argv, argc, "vrf", &idx_vrf)) { - vrf_name = argv[idx_vrf + 1]->arg; - all_vrf = strmatch(vrf_name, "all"); - } + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); if (!uj) show_ip_ospf_neighbour_header(vty); @@ -4693,10 +4705,7 @@ DEFUN (show_ip_ospf_neighbor_detail, int inst = 0; int idx_vrf = 0; - if (argv_find(argv, argc, "vrf", &idx_vrf)) { - vrf_name = argv[idx_vrf + 1]->arg; - all_vrf = strmatch(vrf_name, "all"); - } + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { @@ -4831,10 +4840,7 @@ DEFUN (show_ip_ospf_neighbor_detail_all, int inst = 0; int idx_vrf = 0; - if (argv_find(argv, argc, "vrf", &idx_vrf)) { - vrf_name = argv[idx_vrf + 1]->arg; - all_vrf = strmatch(vrf_name, "all"); - } + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { @@ -5670,10 +5676,7 @@ DEFUN (show_ip_ospf_database_max, int inst = 0; int idx_vrf = 0; - if (argv_find(argv, argc, "vrf", &idx_vrf)) { - vrf_name = argv[idx_vrf + 1]->arg; - all_vrf = strmatch(vrf_name, "all"); - } + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); if (vrf_name) { if (all_vrf) { @@ -5705,7 +5708,7 @@ DEFUN (show_ip_ospf_database_max, DEFUN (show_ip_ospf_instance_database, show_ip_ospf_instance_database_cmd, - "show ip ospf [(1-65535)] [vrf NAME] database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]]", + "show ip ospf [{(1-65535)|vrf NAME}] database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]]", SHOW_STR IP_STR "OSPF information\n" @@ -5850,7 +5853,7 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, DEFUN (show_ip_ospf_instance_database_type_adv_router, show_ip_ospf_instance_database_type_adv_router_cmd, - "show ip ospf [(1-65535)] [vrf NAME] database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate>", + "show ip ospf [{(1-65535)|vrf NAME}] database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate>", SHOW_STR IP_STR "OSPF information\n" @@ -5869,7 +5872,7 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router, bool all_vrf = FALSE; int ret = CMD_SUCCESS; int inst = 0; - int idx = 0; + int idx = 0, idx_vrf = 0; if (argv_find(argv, argc, "(1-65535)", &idx)) { instance = strtoul(argv[idx]->arg, NULL, 10); @@ -5883,10 +5886,9 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router, argc, argv)); } - if (argv_find(argv, argc, "vrf", &idx)) { - vrf_name = argv[++idx]->arg; - all_vrf = strmatch(vrf_name, "all"); - } + + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (vrf_name) { if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { @@ -8397,10 +8399,7 @@ DEFUN (show_ip_ospf_border_routers, int inst = 0; int idx_vrf = 0; - if (argv_find(argv, argc, "vrf", &idx_vrf)) { - vrf_name = argv[idx_vrf + 1]->arg; - all_vrf = strmatch(vrf_name, "all"); - } + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); if (vrf_name) { if (all_vrf) { @@ -8495,10 +8494,7 @@ DEFUN (show_ip_ospf_route, int inst = 0; int idx_vrf = 0; - if (argv_find (argv, argc, "vrf", &idx_vrf)) { - vrf_name = argv[idx_vrf + 1]->arg; - all_vrf = strmatch(vrf_name, "all"); - } + OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { @@ -8632,252 +8628,260 @@ const char *ospf_int_type_str[] = {"unknown", /* should never be used. */ "virtual-link", /* should never be used. */ "loopback"}; -/* Configuration write function for ospfd. */ -static int config_write_interface(struct vty *vty) +static int config_write_interface_one(struct vty *vty, struct ospf *ospf) { struct listnode *n1, *n2; struct interface *ifp; struct crypt_key *ck; - int write = 0; struct route_node *rn = NULL; struct ospf_if_params *params; - struct ospf *ospf = NULL; - struct listnode *node = NULL; + int write = 0; - /* Traverse all ospf [vrf] instances */ - for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { + for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), n1, ifp)) { + if (memcmp(ifp->name, "VLINK", 5) == 0) + continue; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), n1, ifp)) { - if (memcmp(ifp->name, "VLINK", 5) == 0) - continue; + if (ifp->ifindex == IFINDEX_DELETED) + continue; - if (ifp->ifindex == IFINDEX_DELETED) - continue; + vty_frame(vty, "!\n"); + vty_frame(vty, "interface %s\n", ifp->name); + if (ifp->desc) + vty_out(vty, " description %s\n", ifp->desc); - vty_frame(vty, "!\n"); - vty_frame(vty, "interface %s\n", ifp->name); - if (ifp->desc) - vty_out(vty, " description %s\n", ifp->desc); - - write++; - - params = IF_DEF_PARAMS(ifp); - - do { - /* Interface Network print. */ - if (OSPF_IF_PARAM_CONFIGURED(params, type) - && params->type != OSPF_IFTYPE_LOOPBACK) { - if (params->type != ospf_default_iftype(ifp)) { - vty_out(vty, " ip ospf network %s", - ospf_int_type_str - [params->type]); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", + write++; + + params = IF_DEF_PARAMS(ifp); + + do { + /* Interface Network print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, type) + && params->type != OSPF_IFTYPE_LOOPBACK) { + if (params->type != ospf_default_iftype(ifp)) { + vty_out(vty, " ip ospf network %s", + ospf_int_type_str + [params->type]); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", inet_ntoa( - rn->p.u.prefix4)); - vty_out(vty, "\n"); - } + rn->p.u.prefix4)); + vty_out(vty, "\n"); } + } - /* OSPF interface authentication print */ - if (OSPF_IF_PARAM_CONFIGURED(params, auth_type) - && params->auth_type != OSPF_AUTH_NOTSET) { - const char *auth_str; - - /* Translation tables are not that much help - * here due to syntax - * of the simple option */ - switch (params->auth_type) { + /* OSPF interface authentication print */ + if (OSPF_IF_PARAM_CONFIGURED(params, auth_type) + && params->auth_type != OSPF_AUTH_NOTSET) { + const char *auth_str; - case OSPF_AUTH_NULL: - auth_str = " null"; - break; + /* Translation tables are not that much help + * here due to syntax + * of the simple option */ + switch (params->auth_type) { - case OSPF_AUTH_SIMPLE: - auth_str = ""; - break; + case OSPF_AUTH_NULL: + auth_str = " null"; + break; - case OSPF_AUTH_CRYPTOGRAPHIC: - auth_str = " message-digest"; - break; + case OSPF_AUTH_SIMPLE: + auth_str = ""; + break; - default: - auth_str = ""; - break; - } + case OSPF_AUTH_CRYPTOGRAPHIC: + auth_str = " message-digest"; + break; - vty_out(vty, " ip ospf authentication%s", - auth_str); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); + default: + auth_str = ""; + break; } - /* Simple Authentication Password print. */ - if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) - && params->auth_simple[0] != '\0') { - vty_out(vty, " ip ospf authentication-key %s", - params->auth_simple); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); - } + vty_out(vty, " ip ospf authentication%s", + auth_str); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } - /* Cryptographic Authentication Key print. */ - for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, n2, ck)) { - vty_out(vty, - " ip ospf message-digest-key %d md5 %s", - ck->key_id, ck->auth_key); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); - } + /* Simple Authentication Password print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) + && params->auth_simple[0] != '\0') { + vty_out(vty, " ip ospf authentication-key %s", + params->auth_simple); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } - /* Interface Output Cost print. */ - if (OSPF_IF_PARAM_CONFIGURED(params, - output_cost_cmd)) { - vty_out(vty, " ip ospf cost %u", - params->output_cost_cmd); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); - } + /* Cryptographic Authentication Key print. */ + for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, n2, ck)) { + vty_out(vty, + " ip ospf message-digest-key %d md5 %s", + ck->key_id, ck->auth_key); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } - /* Hello Interval print. */ - if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) - && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { - vty_out(vty, " ip ospf hello-interval %u", - params->v_hello); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); - } + /* Interface Output Cost print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, + output_cost_cmd)) { + vty_out(vty, " ip ospf cost %u", + params->output_cost_cmd); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } + /* Hello Interval print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) + && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { + vty_out(vty, " ip ospf hello-interval %u", + params->v_hello); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } - /* Router Dead Interval print. */ - if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) - && params->v_wait - != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { - vty_out(vty, " ip ospf dead-interval "); - /* fast hello ? */ - if (OSPF_IF_PARAM_CONFIGURED(params, - fast_hello)) - vty_out(vty, - "minimal hello-multiplier %d", - params->fast_hello); - else - vty_out(vty, "%u", params->v_wait); + /* Router Dead Interval print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) + && params->v_wait + != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { + vty_out(vty, " ip ospf dead-interval "); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); - } + /* fast hello ? */ + if (OSPF_IF_PARAM_CONFIGURED(params, + fast_hello)) + vty_out(vty, + "minimal hello-multiplier %d", + params->fast_hello); + else + vty_out(vty, "%u", params->v_wait); - /* Router Priority print. */ - if (OSPF_IF_PARAM_CONFIGURED(params, priority) - && params->priority - != OSPF_ROUTER_PRIORITY_DEFAULT) { - vty_out(vty, " ip ospf priority %u", - params->priority); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); - } + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } - /* Retransmit Interval print. */ - if (OSPF_IF_PARAM_CONFIGURED(params, - retransmit_interval) - && params->retransmit_interval - != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { - vty_out(vty, " ip ospf retransmit-interval %u", - params->retransmit_interval); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); - } + /* Router Priority print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, priority) + && params->priority + != OSPF_ROUTER_PRIORITY_DEFAULT) { + vty_out(vty, " ip ospf priority %u", + params->priority); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } - /* Transmit Delay print. */ - if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) - && params->transmit_delay - != OSPF_TRANSMIT_DELAY_DEFAULT) { - vty_out(vty, " ip ospf transmit-delay %u", - params->transmit_delay); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); - } + /* Retransmit Interval print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, + retransmit_interval) + && params->retransmit_interval + != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { + vty_out(vty, " ip ospf retransmit-interval %u", + params->retransmit_interval); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } - /* Area print. */ - if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { - if (ospf->instance) - vty_out(vty, " ip ospf %d", - ospf->instance); - else - vty_out(vty, " ip ospf"); + /* Transmit Delay print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) + && params->transmit_delay + != OSPF_TRANSMIT_DELAY_DEFAULT) { + vty_out(vty, " ip ospf transmit-delay %u", + params->transmit_delay); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } + /* Area print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { + if (ospf->instance) + vty_out(vty, " ip ospf %d", + ospf->instance); + else + vty_out(vty, " ip ospf"); - size_t buflen = MAX(strlen("4294967295"), - strlen("255.255.255.255")); - char buf[buflen]; - area_id2str(buf, sizeof(buf), - ¶ms->if_area, - params->if_area_id_fmt); - vty_out(vty, " area %s", buf); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); - } - /* bfd print. */ - ospf_bfd_write_config(vty, params); + size_t buflen = MAX(strlen("4294967295"), + strlen("255.255.255.255")); + char buf[buflen]; - /* MTU ignore print. */ - if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) - && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { - if (params->mtu_ignore == 0) - vty_out(vty, " no ip ospf mtu-ignore"); - else - vty_out(vty, " ip ospf mtu-ignore"); - if (params != IF_DEF_PARAMS(ifp)) - vty_out(vty, " %s", - inet_ntoa(rn->p.u.prefix4)); - vty_out(vty, "\n"); - } + area_id2str(buf, sizeof(buf), + ¶ms->if_area, + params->if_area_id_fmt); + vty_out(vty, " area %s", buf); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } + /* bfd print. */ + ospf_bfd_write_config(vty, params); - while (1) { - if (rn == NULL) - rn = route_top(IF_OIFS_PARAMS(ifp)); - else - rn = route_next(rn); + /* MTU ignore print. */ + if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) + && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { + if (params->mtu_ignore == 0) + vty_out(vty, " no ip ospf mtu-ignore"); + else + vty_out(vty, " ip ospf mtu-ignore"); + if (params != IF_DEF_PARAMS(ifp)) + vty_out(vty, " %s", + inet_ntoa(rn->p.u.prefix4)); + vty_out(vty, "\n"); + } - if (rn == NULL) - break; - params = rn->info; - if (params != NULL) - break; - } - } while (rn); - ospf_opaque_config_write_if(vty, ifp); + while (1) { + if (rn == NULL) + rn = route_top(IF_OIFS_PARAMS(ifp)); + else + rn = route_next(rn); - vty_endframe(vty, NULL); - } + if (rn == NULL) + break; + params = rn->info; + if (params != NULL) + break; + } + } while (rn); + + ospf_opaque_config_write_if(vty, ifp); + + vty_endframe(vty, NULL); } return write; } +/* Configuration write function for ospfd. */ +static int config_write_interface(struct vty *vty) +{ + int write = 0; + struct ospf *ospf = NULL; + struct listnode *node = NULL; + + /* Traverse all ospf [vrf] instances */ + for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) + write += config_write_interface_one(vty, ospf); + + return write; +} + static int config_write_network_area(struct vty *vty, struct ospf *ospf) { struct route_node *rn; @@ -9214,164 +9218,173 @@ static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) return 0; } -/* OSPF configuration write function. */ -static int ospf_config_write(struct vty *vty) +static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) { - struct ospf *ospf; struct interface *ifp; struct ospf_interface *oi; - struct listnode *node, *ospf_node = NULL; + struct listnode *node = NULL; int write = 0; - if (listcount(om->ospf) == 0) + /* `router ospf' print. */ + if (ospf->instance && ospf->name) { + vty_out(vty, "router ospf %d vrf %s\n", + ospf->instance, ospf->name); + } else if (ospf->instance) { + vty_out(vty, "router ospf %d\n", + ospf->instance); + } else if (ospf->name) { + vty_out(vty, "router ospf vrf %s\n", + ospf->name); + } else + vty_out(vty, "router ospf\n"); + + if (!ospf->networks) { + write++; return write; - for (ALL_LIST_ELEMENTS_RO (om->ospf, ospf_node, ospf)) { - if (ospf->oi_running) { - /* `router ospf' print. */ - if (ospf->instance && ospf->name) { - vty_out(vty, "router ospf %d vrf %s\n", - ospf->instance, ospf->name); - } else if (ospf->instance) { - vty_out(vty, "router ospf %d\n", - ospf->instance); - } else if (ospf->name) { - vty_out(vty, "router ospf vrf %s\n", - ospf->name); - } else - vty_out(vty, "router ospf\n"); + } - if (!ospf->networks) { - write++; - continue; - } + /* Router ID print. */ + if (ospf->router_id_static.s_addr != 0) + vty_out(vty, " ospf router-id %s\n", + inet_ntoa(ospf->router_id_static)); - /* Router ID print. */ - if (ospf->router_id_static.s_addr != 0) - vty_out(vty, " ospf router-id %s\n", - inet_ntoa(ospf->router_id_static)); - - /* ABR type print. */ - if (ospf->abr_type != OSPF_ABR_DEFAULT) - vty_out(vty, " ospf abr-type %s\n", - ospf_abr_type_str[ospf->abr_type]); - - /* log-adjacency-changes flag print. */ - if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { - if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) - vty_out(vty, " log-adjacency-changes detail\n"); - else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES) - vty_out(vty, " log-adjacency-changes\n"); - } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) { - vty_out(vty, " no log-adjacency-changes\n"); - } + /* ABR type print. */ + if (ospf->abr_type != OSPF_ABR_DEFAULT) + vty_out(vty, " ospf abr-type %s\n", + ospf_abr_type_str[ospf->abr_type]); - /* RFC1583 compatibility flag print -- Compatible with CISCO - * 12.1. */ - if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) - vty_out(vty, " compatible rfc1583\n"); + /* log-adjacency-changes flag print. */ + if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { + if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) + vty_out(vty, " log-adjacency-changes detail\n"); + else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES) + vty_out(vty, " log-adjacency-changes\n"); + } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) { + vty_out(vty, " no log-adjacency-changes\n"); + } - /* auto-cost reference-bandwidth configuration. */ - if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { - vty_out(vty, - "! Important: ensure reference bandwidth " - "is consistent across all routers\n"); - vty_out(vty, " auto-cost reference-bandwidth %d\n", - ospf->ref_bandwidth); - } + /* RFC1583 compatibility flag print -- Compatible with CISCO + * 12.1. */ + if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) + vty_out(vty, " compatible rfc1583\n"); - /* SPF timers print. */ - if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT - || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT - || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) - vty_out(vty, " timers throttle spf %d %d %d\n", - ospf->spf_delay, ospf->spf_holdtime, - ospf->spf_max_holdtime); - - /* LSA timers print. */ - if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) - vty_out(vty, " timers throttle lsa all %d\n", - ospf->min_ls_interval); - if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) - vty_out(vty, " timers lsa min-arrival %d\n", - ospf->min_ls_arrival); - - /* Write multiplier print. */ - if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) - vty_out(vty, " ospf write-multiplier %d\n", - ospf->write_oi_count); - - /* Max-metric router-lsa print */ - config_write_stub_router(vty, ospf); - - /* SPF refresh parameters print. */ - if (ospf->lsa_refresh_interval - != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) - vty_out(vty, " refresh timer %d\n", - ospf->lsa_refresh_interval); - - /* Redistribute information print. */ - config_write_ospf_redistribute(vty, ospf); - - /* passive-interface print. */ - if (ospf->passive_interface_default == OSPF_IF_PASSIVE) - vty_out(vty, " passive-interface default\n"); - - for (ALL_LIST_ELEMENTS_RO(om->iflist, node, ifp)) - if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), - passive_interface) - && IF_DEF_PARAMS(ifp)->passive_interface - != ospf->passive_interface_default) { - vty_out(vty, " %spassive-interface %s\n", - IF_DEF_PARAMS(ifp)->passive_interface - ? "" - : "no ", - ifp->name); - } - for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { - if (!OSPF_IF_PARAM_CONFIGURED(oi->params, - passive_interface)) - continue; - if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), - passive_interface)) { - if (oi->params->passive_interface - == IF_DEF_PARAMS(oi->ifp) - ->passive_interface) - continue; - } else if (oi->params->passive_interface - == ospf->passive_interface_default) - continue; + /* auto-cost reference-bandwidth configuration. */ + if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { + vty_out(vty, + "! Important: ensure reference bandwidth " + "is consistent across all routers\n"); + vty_out(vty, " auto-cost reference-bandwidth %d\n", + ospf->ref_bandwidth); + } - vty_out(vty, " %spassive-interface %s %s\n", - oi->params->passive_interface ? "" : "no ", - oi->ifp->name, - inet_ntoa(oi->address->u.prefix4)); - } + /* SPF timers print. */ + if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT + || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT + || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) + vty_out(vty, " timers throttle spf %d %d %d\n", + ospf->spf_delay, ospf->spf_holdtime, + ospf->spf_max_holdtime); + + /* LSA timers print. */ + if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) + vty_out(vty, " timers throttle lsa all %d\n", + ospf->min_ls_interval); + if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) + vty_out(vty, " timers lsa min-arrival %d\n", + ospf->min_ls_arrival); + + /* Write multiplier print. */ + if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) + vty_out(vty, " ospf write-multiplier %d\n", + ospf->write_oi_count); - /* Network area print. */ - config_write_network_area(vty, ospf); + /* Max-metric router-lsa print */ + config_write_stub_router(vty, ospf); - /* Area config print. */ - config_write_ospf_area(vty, ospf); + /* SPF refresh parameters print. */ + if (ospf->lsa_refresh_interval + != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) + vty_out(vty, " refresh timer %d\n", + ospf->lsa_refresh_interval); - /* static neighbor print. */ - config_write_ospf_nbr_nbma(vty, ospf); + /* Redistribute information print. */ + config_write_ospf_redistribute(vty, ospf); - /* Virtual-Link print. */ - config_write_virtual_link(vty, ospf); + /* passive-interface print. */ + if (ospf->passive_interface_default == OSPF_IF_PASSIVE) + vty_out(vty, " passive-interface default\n"); - /* Default metric configuration. */ - config_write_ospf_default_metric(vty, ospf); + for (ALL_LIST_ELEMENTS_RO(om->iflist, node, ifp)) + if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), + passive_interface) + && IF_DEF_PARAMS(ifp)->passive_interface + != ospf->passive_interface_default) { + vty_out(vty, " %spassive-interface %s\n", + IF_DEF_PARAMS(ifp)->passive_interface + ? "" + : "no ", + ifp->name); + } + for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { + if (!OSPF_IF_PARAM_CONFIGURED(oi->params, + passive_interface)) + continue; + if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), + passive_interface)) { + if (oi->params->passive_interface + == IF_DEF_PARAMS(oi->ifp) + ->passive_interface) + continue; + } else if (oi->params->passive_interface + == ospf->passive_interface_default) + continue; - /* Distribute-list and default-information print. */ - config_write_ospf_distribute(vty, ospf); + vty_out(vty, " %spassive-interface %s %s\n", + oi->params->passive_interface ? "" : "no ", + oi->ifp->name, + inet_ntoa(oi->address->u.prefix4)); + } - /* Distance configuration. */ - config_write_ospf_distance(vty, ospf); + /* Network area print. */ + config_write_network_area(vty, ospf); - ospf_opaque_config_write_router(vty, ospf); + /* Area config print. */ + config_write_ospf_area(vty, ospf); - write++; - } + /* static neighbor print. */ + config_write_ospf_nbr_nbma(vty, ospf); + + /* Virtual-Link print. */ + config_write_virtual_link(vty, ospf); + + /* Default metric configuration. */ + config_write_ospf_default_metric(vty, ospf); + + /* Distribute-list and default-information print. */ + config_write_ospf_distribute(vty, ospf); + + /* Distance configuration. */ + config_write_ospf_distance(vty, ospf); + + ospf_opaque_config_write_router(vty, ospf); + + write++; + return write; +} + +/* OSPF configuration write function. */ +static int ospf_config_write(struct vty *vty) +{ + struct ospf *ospf; + struct listnode *ospf_node = NULL; + int write = 0; + + if (listcount(om->ospf) == 0) + return write; + + for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { + if (ospf->oi_running) + write += ospf_config_write_one(vty, ospf); } return write; } diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index cb6c1338e..d8fd9afbd 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -107,6 +107,8 @@ static int ospf_interface_add(int command, struct zclient *zclient, struct ospf *ospf = NULL; ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); + if (ifp == NULL) + return 0; if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) zlog_debug( @@ -123,6 +125,8 @@ static int ospf_interface_add(int command, struct zclient *zclient, } ospf = ospf_lookup_by_vrf_id(vrf_id); + if (!ospf) + return 0; ospf_if_update(ospf, ifp); @@ -282,6 +286,8 @@ static int ospf_interface_address_add(int command, struct zclient *zclient, } ospf = ospf_lookup_by_vrf_id(vrf_id); + if (!ospf) + return 0; ospf_if_update(ospf, c->ifp); @@ -1123,8 +1129,8 @@ void ospf_distribute_list_update(struct ospf *ospf, int type, { struct route_table *rt; struct ospf_external *ext; + void **args = XCALLOC(MTYPE_OSPF_DIST_ARGS, sizeof(void *)*2); - void **args = XCALLOC(MTYPE_OSPF_DIST_ARGS, sizeof (void * )*2); args[0] = ospf; args[1] = (void *)((ptrdiff_t) type); @@ -1158,7 +1164,7 @@ static void ospf_filter_update(struct access_list *access) return; /* Iterate all ospf [VRF] instances */ - for (ALL_LIST_ELEMENTS_RO (om->ospf, n1, ospf)) { + for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) { /* Update distribute-list, and apply filter. */ for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) { struct list *red_list; diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 85fbe6151..d2097e6f5 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -447,14 +447,19 @@ struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id) } -struct ospf *ospf_lookup_by_name(const char *name) +/* It should only be used when processing incoming info update from zebra. + * Other situations, it is not sufficient to lookup the ospf instance by + * vrf_name only without using the instance number. + */ +static struct ospf *ospf_lookup_by_name(const char *vrf_name) { struct ospf *ospf = NULL; struct listnode *node, *nnode; for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf)) - if ((ospf->name == NULL && name == NULL) - || (ospf->name && name && strcmp(ospf->name, name) == 0)) + if ((ospf->name == NULL && vrf_name == NULL) + || (ospf->name && vrf_name && + strcmp(ospf->name, vrf_name) == 0)) return ospf; return NULL; } @@ -1283,8 +1288,9 @@ void ospf_ls_upd_queue_empty(struct ospf_interface *oi) void ospf_if_update(struct ospf *ospf, struct interface *ifp) { + if (!ospf) - ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); + return; if (IS_DEBUG_OSPF_EVENT) zlog_debug("%s: interface %s ifp->vrf_id %u ospf vrf %s vrf_id %u router_id %s", diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index afc7786c0..fb564ee27 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -510,14 +510,9 @@ extern const char *ospf_redist_string(u_int route_type); extern struct ospf *ospf_lookup_instance(u_short); extern struct ospf *ospf_get(u_short instance, const char *name); extern struct ospf *ospf_get_instance(u_short); -extern struct ospf *ospf_lookup_by_name(const char *name); extern struct ospf *ospf_lookup_by_inst_name(u_short instance, const char *name); extern struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id); -extern struct ospf *ospf_lookup_by_name(const char *name); -extern struct ospf *ospf_lookup_by_inst_name(u_short instance, - const char *name); -extern struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id); extern void ospf_finish(struct ospf *); extern void ospf_router_id_update(struct ospf *ospf); extern int ospf_network_set(struct ospf *, struct prefix_ipv4 *, struct in_addr, diff --git a/ospfd/subdir.am b/ospfd/subdir.am index 12c2313e6..e063415fb 100644 --- a/ospfd/subdir.am +++ b/ospfd/subdir.am @@ -58,6 +58,9 @@ ospfdheader_HEADERS = \ # end endif +ospfd/ospf_vty_clippy.c: $(CLIPPY_DEPS) +ospfd/ospf_vty.$(OBJEXT): ospfd/ospf_vty_clippy.c + noinst_HEADERS += \ ospfd/ospf_abr.h \ ospfd/ospf_apiserver.h \ |