struct ospf_area_range *range = rn->info;
if (range->specifics != 0)
- ospf_delete_discard_route(area->ospf->new_table,
+ ospf_delete_discard_route(area->ospf, area->ospf->new_table,
(struct prefix_ipv4 *)&rn->p);
ospf_area_range_free(range);
if (CHECK_FLAG(range->flags,
OSPF_AREA_RANGE_ADVERTISE)) {
if (range->specifics)
- ospf_add_discard_route(
+ ospf_add_discard_route(ospf,
ospf->new_table, area,
(struct prefix_ipv4
*)&rn->p);
else
- ospf_delete_discard_route(
+ ospf_delete_discard_route(ospf,
ospf->new_table,
(struct prefix_ipv4
*)&rn->p);
{
struct listnode *node, *nnode;
struct ospf_interface *oi;
- struct ospf *ospf;
+ struct ospf *ospf = NULL;
- if (!(ospf = ospf_lookup()))
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (!ospf)
return NULL;
for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi))
{
struct listnode *node, *nnode;
struct ospf_interface *oi;
- struct ospf *ospf;
+ struct ospf *ospf = NULL;
- if (!(ospf = ospf_lookup()))
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (!ospf)
return NULL;
for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi))
struct ospf_interface *oi;
struct registered_opaque_type *r;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi)) {
/* Check if this interface is indeed ready for type 9 */
struct ospf *ospf;
struct ospf_area *area;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) {
struct registered_opaque_type *r;
struct ospf *ospf;
struct registered_opaque_type *r;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
/* Can type 11 be originated? */
if (!ospf_apiserver_is_ready_type11(ospf))
struct ospf *ospf;
struct ospf_area *area;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
/* Get request sequence number */
seqnum = msg_get_seq(msg);
struct ospf *ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
assert(ospf);
/* Create a stream for internal opaque LSA */
new->area = area;
new->oi = oi;
+ new->vrf_id = oi->ospf->vrf_id;
SET_FLAG(new->flags, OSPF_LSA_SELF);
memcpy(new->data, newlsa, length);
int ready = 0;
int rc = 0;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
/* Extract opaque LSA data from message */
omsg = (struct msg_originate_request *)STREAM_DATA(msg->s);
case OSPF_OPAQUE_AS_LSA: {
struct ospf *ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
assert(ospf);
/* Increment counters? XXX */
{
struct ospf *ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
assert(ospf);
/* Install this LSA into LSDB. */
struct ospf_lsa *new = NULL;
struct ospf *ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
assert(ospf);
apiserv = lookup_apiserver_by_lsa(lsa);
int rc = 0;
struct ospf *ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
assert(ospf);
/* Extract opaque LSA from message */
* the LSDB until it is finally handled by the maxage remover thread.
* Therefore, the lookup function below may return non-NULL result.
*/
- old = ospf_lsa_lookup(area, dmsg->lsa_type, id, ospf->router_id);
+ old = ospf_lsa_lookup(ospf, area, dmsg->lsa_type, id, ospf->router_id);
if (!old) {
zlog_warn(
"ospf_apiserver_lsa_delete: LSA[Type%d:%s] not in LSDB",
struct ospf *ospf;
struct ospf_area *area;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
assert(ospf);
/* Set parameter struct. */
/* Remove route from zebra. */
if (or->type == OSPF_DESTINATION_NETWORK)
- ospf_zebra_delete((struct prefix_ipv4 *)&rn->p,
+ ospf_zebra_delete(ospf,
+ (struct prefix_ipv4 *)&rn->p,
or);
ospf_route_free(or);
return 1;
}
-static int ospf_ase_compare_tables(struct route_table *new_external_route,
+static int ospf_ase_compare_tables(struct ospf *ospf,
+ struct route_table *new_external_route,
struct route_table *old_external_route)
{
struct route_node *rn, *new_rn;
if ((or = rn->info)) {
if (!(new_rn = route_node_lookup(new_external_route,
&rn->p)))
- ospf_zebra_delete((struct prefix_ipv4 *)&rn->p,
+ ospf_zebra_delete(ospf,
+ (struct prefix_ipv4 *)&rn->p,
or);
else
route_unlock_node(new_rn);
if ((or = rn->info) != NULL)
if (!ospf_ase_route_match_same(old_external_route,
&rn->p, or))
- ospf_zebra_add((struct prefix_ipv4 *)&rn->p,
+ ospf_zebra_add(ospf,
+ (struct prefix_ipv4 *)&rn->p,
or);
return 0;
/* Compare old and new external routing table and install the
difference info zebra/kernel */
- ospf_ase_compare_tables(ospf->new_external_route,
+ ospf_ase_compare_tables(ospf, ospf->new_external_route,
ospf->old_external_route);
/* Delete old external routing table */
}
/* install changes to zebra */
- ospf_ase_compare_tables(ospf->new_external_route, tmp_old);
+ ospf_ase_compare_tables(ospf, ospf->new_external_route, tmp_old);
/* update ospf->old_external_route table */
if (rn && rn->info)
bfd_info = (struct bfd_info *)params->bfd_info;
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
- zlog_debug("%s nbr (%s) with BFD",
+ zlog_debug("%s nbr (%s) with BFD. OSPF vrf %s",
bfd_get_command_dbg_str(command),
- inet_ntoa(nbr->src));
+ inet_ntoa(nbr->src),
+ ospf_vrf_id_to_name(oi->ospf->vrf_id));
bfd_peer_sendmsg(zclient, bfd_info, AF_INET, &nbr->src, NULL, ifp->name,
- 0, 0, command, 0, VRF_DEFAULT);
+ 0, 0, command, 0, oi->ospf->vrf_id);
}
/*
/* Send the client registration */
bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER);
- /* Replay the neighbor, if BFD is enabled in BGP */
+ /* Replay the neighbor, if BFD is enabled in OSPF */
for (ALL_LIST_ELEMENTS(om->ospf, node, onode, ospf)) {
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, inode, oi)) {
if ((nbrs = oi->nbrs) == NULL)
DEBUG_STR
OSPF_STR)
{
- struct ospf *ospf;
+ struct ospf *ospf = NULL;
- if ((ospf = ospf_lookup()) == NULL)
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL)
return CMD_SUCCESS;
return show_debugging_ospf_common(vty, ospf);
char str[16];
memset(str, 0, 16);
- if ((ospf = ospf_lookup()) == NULL)
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL)
return CMD_SUCCESS;
if (ospf->instance)
}
/* Check LSA is related to external info. */
-struct external_info *ospf_external_info_check(struct ospf_lsa *lsa)
+struct external_info *ospf_external_info_check(struct ospf *ospf,
+ struct ospf_lsa *lsa)
{
struct as_external_lsa *al;
struct prefix_ipv4 p;
redist_on =
is_prefix_default(&p)
? vrf_bitmap_check(zclient->default_information,
- VRF_DEFAULT)
+ ospf->vrf_id)
: (zclient->mi_redist[AFI_IP][type].enabled
|| vrf_bitmap_check(
zclient->redist[AFI_IP][type],
- VRF_DEFAULT));
+ ospf->vrf_id));
// Pending: check for MI above.
if (redist_on) {
struct list *ext_list;
ospf_translated_nssa_refresh(ospf, NULL, new);
return;
}
- ei = ospf_external_info_check(new);
+ ei = ospf_external_info_check(ospf, new);
if (ei)
ospf_external_lsa_refresh(ospf, new, ei,
LSA_REFRESH_FORCE);
extern void ospf_lsa_flush_area(struct ospf_lsa *, struct ospf_area *);
extern void ospf_lsa_flush_as(struct ospf *, struct ospf_lsa *);
extern void ospf_lsa_flush(struct ospf *, struct ospf_lsa *);
-extern struct external_info *ospf_external_info_check(struct ospf_lsa *);
+extern struct external_info *ospf_external_info_check(struct ospf *,
+ struct ospf_lsa *);
extern void ospf_lsdb_init(struct ospf_lsdb *);
oi->ospf = ospf;
QOBJ_REG(oi, ospf_interface);
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: ospf interface %s vrf %s id %u created",
+ __PRETTY_FUNCTION__, ifp->name,
+ ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id);
+
return oi;
}
list_free(oi->ls_ack);
list_free(oi->ls_ack_direct.ls_ack);
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: ospf interface %s vrf %s id %u deleted",
+ __PRETTY_FUNCTION__, oi->ifp->name,
+ ospf_vrf_id_to_name(oi->ifp->vrf_id),
+ oi->ifp->vrf_id);
+
ospf_delete_from_if(oi->ifp, oi);
listnode_delete(oi->ospf->oiflist, oi);
struct ospf *ospf;
struct ospf_interface *oi;
- if ((ospf = ospf_lookup()) == NULL)
+ if (!oic)
+ return NULL;
+
+ ospf = oic->ospf;
+ if (ospf == NULL)
return NULL;
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi))
}
if (IS_DEBUG_OSPF_EVENT)
- zlog_debug("ospf_vl_new(): creating pseudo zebra interface");
+ zlog_debug("ospf_vl_new(): creating pseudo zebra interface vrf id %u",
+ ospf->vrf_id);
snprintf(ifname, sizeof(ifname), "VLINK%d", vlink_count);
- vi = if_create(ifname, strnlen(ifname, sizeof(ifname)), VRF_DEFAULT);
+ vi = if_create(ifname, strnlen(ifname, sizeof(ifname)), ospf->vrf_id);
/*
* if_create sets ZEBRA_INTERFACE_LINKDETECTION
* virtual links don't need this.
monotime(&new->tv_recv);
new->tv_orig = new->tv_recv;
new->refresh_list = -1;
+ new->vrf_id = VRF_DEFAULT;
return new;
}
new->area = area;
SET_FLAG(new->flags, OSPF_LSA_SELF | OSPF_LSA_SELF_CHECKED);
+ new->vrf_id = area->ospf->vrf_id;
/* Copy LSA data to store, discard stream. */
new->data = ospf_lsa_data_new(length);
new->area = oi->area;
SET_FLAG(new->flags, OSPF_LSA_SELF | OSPF_LSA_SELF_CHECKED);
+ new->vrf_id = oi->ospf->vrf_id;
/* Copy LSA to store. */
new->data = ospf_lsa_data_new(length);
new = ospf_lsa_new();
new->area = area;
SET_FLAG(new->flags, OSPF_LSA_SELF | OSPF_LSA_SELF_CHECKED);
+ new->vrf_id = area->ospf->vrf_id;
/* Copy LSA to store. */
new->data = ospf_lsa_data_new(length);
new = ospf_lsa_new();
new->area = area;
SET_FLAG(new->flags, OSPF_LSA_SELF | OSPF_LSA_SELF_CHECKED);
+ new->vrf_id = area->ospf->vrf_id;
/* Copy LSA to store. */
new->data = ospf_lsa_data_new(length);
new->area = NULL;
SET_FLAG(new->flags,
OSPF_LSA_SELF | OSPF_LSA_APPROVED | OSPF_LSA_SELF_CHECKED);
+ new->vrf_id = ospf->vrf_id;
/* Copy LSA data to store, discard stream. */
new->data = ospf_lsa_data_new(length);
void ospf_nssa_lsa_flush(struct ospf *ospf, struct prefix_ipv4 *p)
{
struct listnode *node, *nnode;
- struct ospf_lsa *lsa;
+ struct ospf_lsa *lsa = NULL;
struct ospf_area *area;
for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) {
if (area->external_routing == OSPF_AREA_NSSA) {
- if (!(lsa = ospf_lsa_lookup(area, OSPF_AS_NSSA_LSA,
- p->prefix,
- ospf->router_id))) {
+ lsa = ospf_lsa_lookup(ospf, area,
+ OSPF_AS_NSSA_LSA, p->prefix,
+ ospf->router_id);
+ if (!lsa) {
if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
zlog_debug(
"LSA: There is no such AS-NSSA-LSA %s/%d in LSDB",
return lsa;
}
-struct ospf_lsa *ospf_lsa_lookup(struct ospf_area *area, u_int32_t type,
- struct in_addr id, struct in_addr adv_router)
+struct ospf_lsa *ospf_lsa_lookup(struct ospf *ospf, struct ospf_area *area,
+ u_int32_t type, struct in_addr id,
+ struct in_addr adv_router)
{
- struct ospf *ospf = ospf_lookup();
- assert(ospf);
+ if (!ospf)
+ return NULL;
switch (type) {
case OSPF_ROUTER_LSA:
* they two were forming a unique LSA-ID.
*/
- match = ospf_lsa_lookup(area, lsah->type, lsah->id, lsah->adv_router);
+ match = ospf_lsa_lookup(area->ospf, area, lsah->type, lsah->id,
+ lsah->adv_router);
if (match == NULL)
if (IS_DEBUG_OSPF(lsa, LSA) == OSPF_DEBUG_LSA)
*/
if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
break;
- ei = ospf_external_info_check(lsa);
+ ei = ospf_external_info_check(ospf, lsa);
if (ei)
new = ospf_external_lsa_refresh(ospf, lsa, ei,
LSA_REFRESH_FORCE);
/* For Type-9 Opaque-LSAs */
struct ospf_interface *oi;
+
+ /* VRF Id */
+ vrf_id_t vrf_id;
};
/* OSPF LSA Link Type. */
struct external_info *);
extern int ospf_external_lsa_originate_timer(struct thread *);
extern int ospf_default_originate_timer(struct thread *);
-extern struct ospf_lsa *ospf_lsa_lookup(struct ospf_area *, u_int32_t,
- struct in_addr, struct in_addr);
+extern struct ospf_lsa *ospf_lsa_lookup(struct ospf *ospf, struct ospf_area *,
+ u_int32_t, struct in_addr,
+ struct in_addr);
extern struct ospf_lsa *ospf_lsa_lookup_by_id(struct ospf_area *, u_int32_t,
struct in_addr);
extern struct ospf_lsa *ospf_lsa_lookup_by_header(struct ospf_area *,
/* Library inits. */
debug_init();
- vrf_init(NULL, NULL, NULL, NULL);
+ ospf_vrf_init();
access_list_init();
prefix_list_init();
listnode_add(new->area->opaque_lsa_self, oipt);
break;
case OSPF_OPAQUE_AS_LSA:
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(new->vrf_id);
if (new->area != NULL && (top = new->area->ospf) == NULL) {
free_opaque_info_per_type((void *)oipt);
oipt = NULL;
"Type-10 Opaque-LSA: Reference to AREA is missing?");
break;
case OSPF_OPAQUE_AS_LSA:
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(lsa->vrf_id);
if ((area = lsa->area) != NULL && (top = area->ospf) == NULL) {
zlog_warn(
"Type-11 Opaque-LSA: Reference to OSPF is missing?");
}
break;
case OSPF_OPAQUE_AS_LSA:
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(lsa->vrf_id);
if (lsa->area != NULL && (top = lsa->area->ospf) == NULL) {
/* Above conditions must have passed. */
zlog_warn("ospf_opaque_lsa_install: Sonmething wrong?");
struct ospf_opaque_functab *functab;
struct ospf_lsa *new = NULL;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(lsa->vrf_id);
if ((functab = ospf_opaque_functab_lookup(lsa)) == NULL
|| functab->lsa_refresher == NULL) {
void ospf_opaque_lsa_reoriginate_schedule(void *lsa_type_dependent,
u_char lsa_type, u_char opaque_type)
{
- struct ospf *top;
+ struct ospf *top = NULL;
struct ospf_area dummy, *area = NULL;
struct ospf_interface *oi = NULL;
/* Generate a dummy lsa to be passed for a lookup function. */
lsa = pseudo_lsa(oi, area, lsa_type, opaque_type);
+ lsa->vrf_id = top->vrf_id;
if ((oipt = lookup_opaque_info_by_type(lsa)) == NULL) {
struct ospf_opaque_functab *functab;
lsa.oi = oi;
lsa.area = area;
lsa.data = &lsah;
+ lsa.vrf_id = VRF_DEFAULT;
lsah.type = lsa_type;
tmp = SET_OPAQUE_LSID(opaque_type, 0); /* Opaque-ID is unused here. */
ospf_ls_retransmit_delete_nbr_area(lsa->area, lsa);
break;
case OSPF_OPAQUE_AS_LSA:
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(lsa0->vrf_id);
if ((lsa0->area != NULL) && (lsa0->area->ospf != NULL))
top = lsa0->area->ospf;
ospf_ls_retransmit_delete_nbr_as(top, lsa);
struct ospf_lsa *lsa;
struct ospf *top;
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(lsa0->vrf_id);
if ((oipt = lookup_opaque_info_by_type(lsa0)) == NULL
|| (oipi = lookup_opaque_info_by_id(oipt, lsa0)) == NULL) {
}
if (IS_DEBUG_OSPF_EVENT)
- zlog_debug("Packet %s [Hello:RECV]: Options %s",
+ zlog_debug("Packet %s [Hello:RECV]: Options %s vrf %s",
inet_ntoa(ospfh->router_id),
- ospf_options_dump(hello->options));
+ ospf_options_dump(hello->options),
+ ospf_vrf_id_to_name(oi->ospf->vrf_id));
/* Compare options. */
#define REJECT_IF_TBIT_ON 1 /* XXX */
}
/* Search proper LSA in LSDB. */
- find = ospf_lsa_lookup(oi->area, ls_type, ls_id, adv_router);
+ find = ospf_lsa_lookup(oi->ospf, oi->area, ls_type, ls_id,
+ adv_router);
if (find == NULL) {
OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_BadLSReq);
list_delete(ls_upd);
/* Create OSPF LSA instance. */
lsa = ospf_lsa_new();
+ lsa->vrf_id = oi->ospf->vrf_id;
/* We may wish to put some error checking if type NSSA comes in
and area not in NSSA mode */
switch (lsah->type) {
lsa = ospf_lsa_new();
lsa->data = (struct lsa_header *)STREAM_PNT(s);
+ lsa->vrf_id = oi->ospf->vrf_id;
/* lsah = (struct lsa_header *) STREAM_PNT (s); */
size -= OSPF_LSA_HEADER_SIZE;
return;
}
-static struct stream *ospf_recv_packet(int fd, struct interface **ifp,
+static struct stream *ospf_recv_packet(struct ospf *ospf, int fd,
+ struct interface **ifp,
struct stream *ibuf)
{
int ret;
ifindex = getsockopt_ifindex(AF_INET, &msgh);
- *ifp = if_lookup_by_index(ifindex, VRF_DEFAULT);
+ *ifp = if_lookup_by_index(ifindex, ospf->vrf_id);
if (ret != ip_len) {
zlog_warn(
struct ip *iph;
struct ospf_header *ospfh;
u_int16_t length;
- struct interface *ifp;
+ struct interface *ifp = NULL;
struct connected *c;
/* first of all get interface pointer. */
thread_add_read(master, ospf_read, ospf, ospf->fd, &ospf->t_read);
stream_reset(ospf->ibuf);
- if (!(ibuf = ospf_recv_packet(ospf->fd, &ifp, ospf->ibuf)))
+ ibuf = ospf_recv_packet(ospf, ospf->fd, &ifp, ospf->ibuf);
+ if (ibuf == NULL)
return -1;
/* This raw packet is known to be at least as big as its IP header. */
ifindex
retrieval but do not. */
c = if_lookup_address((void *)&iph->ip_src, AF_INET,
- VRF_DEFAULT);
+ ospf->vrf_id);
if (c)
ifp = c->ifp;
if (ifp == NULL)
op->dst.s_addr = addr;
+ if (IS_DEBUG_OSPF_EVENT) {
+ if (oi->ospf->vrf_id)
+ zlog_debug("%s: Hello Tx interface %s ospf vrf %s id %u",
+ __PRETTY_FUNCTION__, oi->ifp->name,
+ ospf_vrf_id_to_name(oi->ospf->vrf_id),
+ oi->ospf->vrf_id);
+ }
/* Add packet to the top of the interface output queue, so that they
* can't get delayed by things like long queues of LS Update packets
*/
/* If Area address is not null and exist, retrieve corresponding
* structure */
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
zlog_info("RI-> Initialize Router Info for %s scope within area %s",
OspfRI.scope == OSPF_OPAQUE_AREA_LSA ? "Area" : "AS",
inet_ntoa(OspfRI.area_id));
"LSA[Type%d:%s]: Create an Opaque-LSA/ROUTER INFORMATION instance",
lsa_type, inet_ntoa(lsa_id));
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
/* Set opaque-LSA header fields. */
lsa_header_set(s, options, lsa_type, lsa_id, top->router_id);
new->area = OspfRI.area; /* Area must be null if the Opaque type is AS
scope, fulfill otherwise */
+ if (new->area && new->area->ospf)
+ new->vrf_id = new->area->ospf->vrf_id;
+ else
+ new->vrf_id = VRF_DEFAULT;
+
SET_FLAG(new->flags, OSPF_LSA_SELF);
memcpy(new->data, lsah, length);
stream_free(s);
struct ospf *top;
struct ospf_area *area;
int rc = -1;
+ vrf_id_t vrf_id = VRF_DEFAULT;
/* First check if the area is known if flooding scope is Area */
if (OspfRI.scope == OSPF_OPAQUE_AREA_LSA) {
return rc;
}
OspfRI.area = area;
+ if (area->ospf)
+ vrf_id = area->ospf->vrf_id;
}
/* Create new Opaque-LSA/ROUTER INFORMATION instance. */
"ospf_router_info_lsa_originate1: ospf_router_info_lsa_new() ?");
return rc;
}
+ new->vrf_id = vrf_id;
/* Get ospf info */
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(vrf_id);
+ if (top == NULL) {
+ zlog_debug("%s: ospf instance not found for vrf id %u",
+ __PRETTY_FUNCTION__, vrf_id);
+ return rc;
+ }
/* Install this LSA into LSDB. */
if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
return NULL;
}
new->data->ls_seqnum = lsa_seqnum_increment(lsa);
+ new->vrf_id = lsa->vrf_id;
/* Install this LSA into LSDB. */
/* Given "lsa" will be freed in the next function. */
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(lsa->vrf_id);
if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
zlog_warn("ospf_router_info_lsa_refresh: ospf_lsa_install() ?");
ospf_lsa_unlock(&new);
if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) && (opcode == REORIGINATE_THIS_LSA))
opcode = REFRESH_THIS_LSA;
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if ((OspfRI.scope == OSPF_OPAQUE_AREA_LSA) && (OspfRI.area == NULL)) {
zlog_warn(
"ospf_router_info_lsa_schedule(): Router Info is Area scope flooding but area is not set");
XFREE(MTYPE_OSPF_PATH, op);
}
-void ospf_route_delete(struct route_table *rt)
+void ospf_route_delete(struct ospf *ospf, struct route_table *rt)
{
struct route_node *rn;
struct ospf_route * or ;
for (rn = route_top(rt); rn; rn = route_next(rn))
if ((or = rn->info) != NULL) {
if (or->type == OSPF_DESTINATION_NETWORK)
- ospf_zebra_delete((struct prefix_ipv4 *)&rn->p,
+ ospf_zebra_delete(ospf,
+ (struct prefix_ipv4 *)&rn->p,
or);
else if (or->type == OSPF_DESTINATION_DISCARD)
- ospf_zebra_delete_discard(
+ ospf_zebra_delete_discard(ospf,
(struct prefix_ipv4 *)&rn->p);
}
}
/* delete routes generated from AS-External routes if there is a inter/intra
* area route
*/
-static void ospf_route_delete_same_ext(struct route_table *external_routes,
+static void ospf_route_delete_same_ext(struct ospf *ospf,
+ struct route_table *external_routes,
struct route_table *routes)
{
struct route_node *rn, *ext_rn;
if ((ext_rn = route_node_lookup(external_routes,
(struct prefix *)p))) {
if (ext_rn->info) {
- ospf_zebra_delete(p, ext_rn->info);
+ ospf_zebra_delete(ospf, p,
+ ext_rn->info);
ospf_route_free(ext_rn->info);
ext_rn->info = NULL;
}
}
/* rt: Old, cmprt: New */
-static void ospf_route_delete_uniq(struct route_table *rt,
+static void ospf_route_delete_uniq(struct ospf *ospf, struct route_table *rt,
struct route_table *cmprt)
{
struct route_node *rn;
cmprt,
(struct prefix_ipv4 *)&rn
->p))
- ospf_zebra_delete(
+ ospf_zebra_delete(ospf,
(struct prefix_ipv4
*)&rn->p,
or);
cmprt,
(struct prefix_ipv4 *)&rn
->p))
- ospf_zebra_delete_discard(
+ ospf_zebra_delete_discard(ospf,
(struct prefix_ipv4
*)&rn->p);
}
/* Delete old routes. */
if (ospf->old_table)
- ospf_route_delete_uniq(ospf->old_table, rt);
+ ospf_route_delete_uniq(ospf, ospf->old_table, rt);
if (ospf->old_external_route)
- ospf_route_delete_same_ext(ospf->old_external_route, rt);
+ ospf_route_delete_same_ext(ospf, ospf->old_external_route, rt);
/* Install new routes. */
for (rn = route_top(rt); rn; rn = route_next(rn))
if (!ospf_route_match_same(
ospf->old_table,
(struct prefix_ipv4 *)&rn->p, or))
- ospf_zebra_add(
+ ospf_zebra_add(ospf,
(struct prefix_ipv4 *)&rn->p,
or);
} else if (or->type == OSPF_DESTINATION_DISCARD)
if (!ospf_route_match_same(
ospf->old_table,
(struct prefix_ipv4 *)&rn->p, or))
- ospf_zebra_add_discard(
+ ospf_zebra_add_discard(ospf,
(struct prefix_ipv4 *)&rn->p);
}
}
}
}
-int ospf_add_discard_route(struct route_table *rt, struct ospf_area *area,
+int ospf_add_discard_route(struct ospf *ospf, struct route_table *rt,
+ struct ospf_area *area,
struct prefix_ipv4 *p)
{
struct route_node *rn;
new_or->path_type = OSPF_PATH_INTER_AREA;
rn->info = new_or;
- ospf_zebra_add_discard(p);
+ ospf_zebra_add_discard(ospf, p);
return 1;
}
-void ospf_delete_discard_route(struct route_table *rt, struct prefix_ipv4 *p)
+void ospf_delete_discard_route(struct ospf *ospf, struct route_table *rt,
+ struct prefix_ipv4 *p)
{
struct route_node *rn;
struct ospf_route * or ;
route_unlock_node(rn);
/* remove the discard entry from the rib */
- ospf_zebra_delete_discard(p);
+ ospf_zebra_delete_discard(ospf, p);
return;
}
extern struct ospf_path *ospf_path_lookup(struct list *, struct ospf_path *);
extern struct ospf_route *ospf_route_new(void);
extern void ospf_route_free(struct ospf_route *);
-extern void ospf_route_delete(struct route_table *);
+extern void ospf_route_delete(struct ospf *, struct route_table *);
extern void ospf_route_table_free(struct route_table *);
extern void ospf_route_install(struct ospf *, struct route_table *);
extern void ospf_route_subst_nexthops(struct ospf_route *, struct list *);
extern void ospf_prune_unreachable_networks(struct route_table *);
extern void ospf_prune_unreachable_routers(struct route_table *);
-extern int ospf_add_discard_route(struct route_table *, struct ospf_area *,
- struct prefix_ipv4 *);
-extern void ospf_delete_discard_route(struct route_table *,
+extern int ospf_add_discard_route(struct ospf *, struct route_table *,
+ struct ospf_area *, struct prefix_ipv4 *);
+extern void ospf_delete_discard_route(struct ospf *, struct route_table *,
struct prefix_ipv4 *);
extern int ospf_route_match_same(struct route_table *, struct prefix_ipv4 *,
struct ospf_route *);
{
struct ospf *ospf;
int type;
+ struct listnode *n1 = NULL;
/* If OSPF instatnce does not exist, return right now. */
- ospf = ospf_lookup();
- if (ospf == NULL)
+ if (listcount(om->ospf) == 0)
return;
- /* Update route-map */
- for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
- struct list *red_list;
- struct listnode *node;
- struct ospf_redist *red;
-
- red_list = ospf->redist[type];
- if (!red_list)
- continue;
-
- for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
- if (ROUTEMAP_NAME(red)
- && strcmp(ROUTEMAP_NAME(red), name) == 0) {
- /* Keep old route-map. */
- struct route_map *old = ROUTEMAP(red);
-
- /* Update route-map. */
- ROUTEMAP(red) = route_map_lookup_by_name(
- ROUTEMAP_NAME(red));
-
- /* No update for this distribute type. */
- if (old == NULL && ROUTEMAP(red) == NULL)
- continue;
-
- ospf_distribute_list_update(ospf, type,
- red->instance);
+ for (ALL_LIST_ELEMENTS_RO (om->ospf, n1, ospf)) {
+ /* Update route-map */
+ for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
+ struct list *red_list;
+ struct listnode *node;
+ struct ospf_redist *red;
+
+ red_list = ospf->redist[type];
+ if (!red_list)
+ continue;
+
+ for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
+ if (ROUTEMAP_NAME(red)
+ && strcmp(ROUTEMAP_NAME(red), name) == 0) {
+ /* Keep old route-map. */
+ struct route_map *old = ROUTEMAP(red);
+
+ /* Update route-map. */
+ ROUTEMAP(red) = route_map_lookup_by_name(
+ ROUTEMAP_NAME(red));
+
+ /* No update for this distribute type. */
+ if (old == NULL && ROUTEMAP(red) == NULL)
+ continue;
+
+ ospf_distribute_list_update(ospf, type,
+ red->instance);
+ }
}
}
}
{
struct ospf *ospf;
int type;
-
- /* If OSPF instatnce does not exist, return right now. */
- ospf = ospf_lookup();
- if (ospf == NULL)
- return;
-
- for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
- struct list *red_list;
- struct listnode *node;
- struct ospf_redist *red;
-
- red_list = ospf->redist[type];
- if (!red_list)
- continue;
-
- for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
- if (ROUTEMAP_NAME(red) && ROUTEMAP(red)
- && !strcmp(ROUTEMAP_NAME(red), name)) {
- ospf_distribute_list_update(ospf, type,
- red->instance);
+ struct listnode *n1 = NULL;
+
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) {
+ for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
+ struct list *red_list;
+ struct listnode *node;
+ struct ospf_redist *red;
+
+ red_list = ospf->redist[type];
+ if (!red_list)
+ continue;
+
+ for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
+ if (ROUTEMAP_NAME(red) && ROUTEMAP(red)
+ && !strcmp(ROUTEMAP_NAME(red), name)) {
+ ospf_distribute_list_update(ospf, type,
+ red->instance);
+ }
}
}
}
if (type == RMAP_OSPF) {
ei = object;
- ifp = if_lookup_by_name((char *)rule, VRF_DEFAULT);
+ ifp = if_lookup_by_name_all_vrf((char *)rule);
if (ifp == NULL || ifp->ifindex != ei->ifindex)
return RMAP_NOMATCH;
{
struct ospf *ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
/* Check whether the instance identifier is valid */
if (smux_header_generic(v, name, length, exact, var_len, write_method)
struct ospf_area *area;
int len;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
struct listnode *node;
struct ospf *ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
struct ospf_area *area;
int len;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
oid *offset;
int offsetlen;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
#define OSPF_LSDB_ENTRY_OFFSET (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
memset(&router_id, 0, sizeof(struct in_addr));
/* Check OSPF instance. */
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
p.family = AF_INET;
p.prefixlen = IPV4_MAX_BITLEN;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (exact) {
/* Area ID + Range Network. */
return NULL;
/* Check OSPF instance. */
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
struct ospf_nbr_nbma *nbr_nbma;
struct ospf *ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
return NULL;
/* Check OSPF instance. */
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
struct listnode *node;
struct ospf_snmp_if *osif;
struct ospf_interface *oi = NULL;
- struct ospf *ospf = ospf_lookup();
+ struct ospf *ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
for (ALL_LIST_ELEMENTS_RO(ospf_snmp_iflist, node, osif)) {
if (ifaddr->s_addr) {
{
struct ospf_snmp_if *osif;
struct listnode *nn;
- struct ospf *ospf = ospf_lookup();
+ struct ospf *ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
struct ospf_interface *oi = NULL;
if (ospf == NULL)
memset(&ifaddr, 0, sizeof(struct in_addr));
/* Check OSPF instance. */
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
memset(&ifaddr, 0, sizeof(struct in_addr));
/* Check OSPF instance. */
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
struct ospf_neighbor *min = NULL;
struct ospf *ospf = ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, nn, oi)) {
for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
struct ospf_neighbor *nbr;
struct ospf *ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (!ospf)
return NULL;
memset(&neighbor, 0, sizeof(struct in_addr));
/* Check OSPF instance. */
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
struct ospf_lsa *lsa;
struct ospf *ospf;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (exact) {
if (*length != v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
return NULL;
memset(&router_id, 0, sizeof(struct in_addr));
/* Check OSPF instance. */
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL)
return NULL;
* of candidates with any vertices not already on the list. If a lower-cost
* path is found to a vertex already on the candidate list, store the new cost.
*/
-static void ospf_spf_next(struct vertex *v, struct ospf_area *area,
+static void ospf_spf_next(struct vertex *v, struct ospf *ospf,
+ struct ospf_area *area,
struct pqueue *candidate)
{
struct ospf_lsa *w_lsa = NULL;
inet_ntoa(l->link_id));
}
- w_lsa = ospf_lsa_lookup(area, OSPF_ROUTER_LSA,
+ w_lsa = ospf_lsa_lookup(ospf, area,
+ OSPF_ROUTER_LSA,
l->link_id, l->link_id);
if (w_lsa) {
if (IS_DEBUG_OSPF_EVENT)
#endif
/* Calculating the shortest-path tree for an area. */
-static void ospf_spf_calculate(struct ospf_area *area,
+static void ospf_spf_calculate(struct ospf *ospf, struct ospf_area *area,
struct route_table *new_table,
struct route_table *new_rtrs)
{
for (;;) {
/* RFC2328 16.1. (2). */
- ospf_spf_next(v, area, candidate);
+ ospf_spf_next(v, ospf, area, candidate);
/* RFC2328 16.1. (3). */
/* If at this step the candidate list is empty, the shortest-
if (ospf->backbone && ospf->backbone == area)
continue;
- ospf_spf_calculate(area, new_table, new_rtrs);
+ ospf_spf_calculate(ospf, area, new_table, new_rtrs);
areas_processed++;
}
/* SPF for backbone, if required */
if (ospf->backbone) {
- ospf_spf_calculate(ospf->backbone, new_table, new_rtrs);
+ ospf_spf_calculate(ospf, ospf->backbone, new_table, new_rtrs);
areas_processed++;
}
ospf_ase_calculate_timer_add(ospf);
+
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: ospf install new route, vrf %s id %u new_table count %lu",
+ __PRETTY_FUNCTION__,
+ ospf_vrf_id_to_name(ospf->vrf_id),
+ ospf->vrf_id, new_table->count);
/* Update routing table. */
monotime(&start_time);
ospf_route_install(ospf, new_table);
else {
lp->flags = INTER_AS | FLOOD_AREA;
lp->area = ospf_area_lookup_by_area_id(
- ospf_lookup(),
+ ospf_lookup_by_vrf_id(VRF_DEFAULT),
OspfMplsTE.interas_areaid);
}
}
}
/* Create new opaque-LSA. */
-static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf_area *area,
+static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf *ospf,
+ struct ospf_area *area,
struct mpls_te_link *lp)
{
struct stream *s;
tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA, lp->instance);
lsa_id.s_addr = htonl(tmp);
- struct ospf *top = ospf_lookup();
+ if (!ospf)
+ return NULL;
- lsa_header_set(s, options, lsa_type, lsa_id, top->router_id);
+ lsa_header_set(s, options, lsa_type, lsa_id, ospf->router_id);
} else {
options |= LSA_OPTIONS_GET(area); /* Get area default option */
options |= LSA_OPTIONS_NSSA_GET(area);
return new;
}
+ new->vrf_id = ospf->vrf_id;
+ if (area && area->ospf)
+ new->vrf_id = area->ospf->vrf_id;
new->area = area;
SET_FLAG(new->flags, OSPF_LSA_SELF);
memcpy(new->data, lsah, length);
static int ospf_mpls_te_lsa_originate1(struct ospf_area *area,
struct mpls_te_link *lp)
{
- struct ospf_lsa *new;
+ struct ospf_lsa *new = NULL;
int rc = -1;
/* Create new Opaque-LSA/MPLS-TE instance. */
- if ((new = ospf_mpls_te_lsa_new(area, lp)) == NULL) {
+ new = ospf_mpls_te_lsa_new(area->ospf, area, lp);
+ if (new == NULL) {
zlog_warn(
"ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?");
return rc;
int rc = -1;
/* Create new Opaque-LSA/Inter-AS instance. */
- if ((new = ospf_mpls_te_lsa_new(NULL, lp)) == NULL) {
+ new = ospf_mpls_te_lsa_new(top, NULL, lp);
+ if (new == NULL) {
zlog_warn(
"ospf_mpls_te_lsa_originate2: ospf_router_info_lsa_new() ?");
return rc;
}
+ new->vrf_id = top->vrf_id;
/* Install this LSA into LSDB. */
if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
ospf_opaque_lsa_flush_schedule(lsa);
return NULL;
}
-
+ top = ospf_lookup_by_vrf_id(lsa->vrf_id);
/* Create new Opaque-LSA/MPLS-TE instance. */
- if ((new = ospf_mpls_te_lsa_new(area, lp)) == NULL) {
+ new = ospf_mpls_te_lsa_new(top, area, lp);
+ if (new == NULL) {
zlog_warn("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?");
return NULL;
}
* ospf_lookup() to get ospf instance */
if (area)
top = area->ospf;
- else
- top = ospf_lookup();
if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
zlog_warn("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?");
memset(&lsa, 0, sizeof(lsa));
memset(&lsah, 0, sizeof(lsah));
- top = ospf_lookup();
+ top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
/* Check if the pseudo link is ready to flood */
if (!(CHECK_FLAG(lp->flags, LPFLG_LSA_ACTIVE))
DEFUN (show_ip_ospf_mpls_te_link,
show_ip_ospf_mpls_te_link_cmd,
- "show ip ospf mpls-te interface [INTERFACE]",
+ "show ip ospf [vrf <NAME|all>] mpls-te interface [INTERFACE]",
SHOW_STR
IP_STR
OSPF_STR
+ VRF_CMD_HELP_STR
+ "All VRFs\n"
"MPLS-TE information\n"
"Interface information\n"
"Interface name\n")
{
int idx_interface = 5;
struct interface *ifp;
- struct listnode *node, *nnode;
-
+ struct listnode *node, *nnode, *n1;
+ char *vrf_name = NULL;
+ bool all_vrf;
+ int inst = 0;
+ int idx_vrf = 0;
+ struct ospf *ospf = NULL;
+
+ if (argv_find(argv, argc, "vrf", &idx_vrf)) {
+ vrf_name = argv[idx_vrf + 1]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
+
+ /* vrf input is provided could be all or specific vrf*/
+ if (vrf_name) {
+ if (all_vrf) {
+ 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);
+ }
+ return CMD_SUCCESS;
+ }
+ ospf = ospf_lookup_by_inst_name (inst, vrf_name);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ for (ALL_LIST_ELEMENTS(vrf_iflist(ospf->vrf_id), node,
+ nnode, ifp))
+ show_mpls_te_link_sub(vty, ifp);
+ return CMD_SUCCESS;
+ }
/* Show All Interfaces. */
if (argc == 5) {
- for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT), node, nnode,
+ 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);
}
/* Interface name is specified. */
else {
- if ((ifp = if_lookup_by_name(argv[idx_interface]->arg,
- VRF_DEFAULT))
- == NULL)
+ ifp = if_lookup_by_name_all_vrf(argv[idx_interface]->arg);
+ if (ifp == NULL)
vty_out(vty, "No such interface name\n");
else
show_mpls_te_link_sub(vty, ifp);
DEFUN_NOSH (router_ospf,
router_ospf_cmd,
- "router ospf [(1-65535)]",
+ "router ospf [(1-65535)] [vrf NAME]",
"Enable a routing process\n"
"Start OSPF configuration\n"
- "Instance ID\n")
+ "Instance ID\n"
+ VRF_CMD_HELP_STR)
{
- struct ospf *ospf;
+ 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);
+ } 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;
+ }
- ospf = ospf_lookup();
- if (!ospf) {
- vty_out(vty, "There isn't active ospf instance \n");
- return CMD_WARNING_CONFIG_FAILED;
+ if (argc > 2)
+ instance = strtoul(argv[2]->arg, NULL, 10);
}
- if (argc > 2)
- instance = strtoul(argv[2]->arg, NULL, 10);
-
/* 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. */
if (ospf->instance != instance) {
VTY_PUSH_CONTEXT_NULL(OSPF_NODE);
ret = CMD_NOT_MY_INSTANCE;
} else {
+ if (ospf->vrf_id != VRF_UNKNOWN)
+ ospf->oi_running = 1;
if (IS_DEBUG_OSPF_EVENT)
- zlog_debug("Config command 'router ospf %d' received",
- instance);
- ospf->oi_running = 1;
+ zlog_debug("Config command 'router ospf %d' received, vrf %s id %d oi_running %u",
+ instance, ospf->name ? ospf->name : "NIL",
+ ospf->vrf_id, ospf->oi_running);
VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
ospf_router_id_update(ospf);
}
DEFUN (no_router_ospf,
no_router_ospf_cmd,
- "no router ospf [(1-65535)]",
+ "no router ospf [(1-65535)] [vrf NAME]",
NO_STR
"Enable a routing process\n"
"Start OSPF configuration\n"
- "Instance ID\n")
+ "Instance ID\n"
+ VRF_CMD_HELP_STR)
{
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);
- if (argc > 3)
- instance = strtoul(argv[3]->arg, NULL, 10);
-
- ospf = ospf_lookup_instance(instance);
- if (ospf == NULL)
- return CMD_NOT_MY_INSTANCE;
+ ospf = ospf_lookup_instance(instance);
+ if (ospf == NULL)
+ return CMD_NOT_MY_INSTANCE;
+ }
ospf_finish(ospf);
ospf->passive_interface_default = newval;
- for (ALL_LIST_ELEMENTS_RO(om->iflist, ln, ifp)) {
+ for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), ln, ifp)) {
if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp),
passive_interface))
UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface);
return CMD_SUCCESS;
}
- ifp = if_get_by_name(argv[1]->arg, VRF_DEFAULT);
+ 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;
+ }
params = IF_DEF_PARAMS(ifp);
return CMD_SUCCESS;
}
- ifp = if_get_by_name(argv[2]->arg, VRF_DEFAULT);
+ ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id);
+ if (ifp == NULL) {
+ vty_out(vty, "interface %s not found.\n",
+ (char *)argv[1]->arg);
+ return CMD_WARNING;
+ }
params = IF_DEF_PARAMS(ifp);
return CMD_SUCCESS;
ospf->ref_bandwidth = refbw;
- for (ALL_LIST_ELEMENTS_RO(om->iflist, node, ifp))
+ for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), node, ifp))
ospf_if_recalculate_output_cost(ifp);
return CMD_SUCCESS;
vty_out(vty,
" Please ensure reference bandwidth is consistent across all routers\n");
- for (ALL_LIST_ELEMENTS(om->iflist, node, nnode, ifp))
+ for (ALL_LIST_ELEMENTS(vrf_iflist(ospf->vrf_id), node, nnode, ifp))
ospf_if_recalculate_output_cost(ifp);
return CMD_SUCCESS;
DEFUN (show_ip_ospf,
show_ip_ospf_cmd,
- "show ip ospf [json]",
+ "show ip ospf [vrf <NAME|all>] [json]",
SHOW_STR
IP_STR
"OSPF information\n"
+ VRF_CMD_HELP_STR
+ "All VRFs\n"
JSON_STR)
{
struct ospf *ospf;
u_char uj = use_json(argc, argv);
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
+ int idx_vrf = 0;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
+ if (listcount(om->ospf) == 0)
return CMD_SUCCESS;
- return (show_ip_ospf_common(vty, ospf, uj));
+ if (argv_find(argv, argc, "vrf", &idx_vrf)) {
+ vrf_name = argv[idx_vrf + 1]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
+
+ /* vrf input is provided could be all or specific vrf*/
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_common(vty, ospf, uj);
+ }
+ return ret;
+ }
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if ((ospf == NULL) || !ospf->oi_running)
+ return CMD_SUCCESS;
+ } else {
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ /* Display default ospf (instance 0) info */
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ }
+
+ if (ospf)
+ show_ip_ospf_common(vty, ospf, uj);
+
+ return ret;
}
DEFUN (show_ip_ospf_instance,
if (argc == iface_argv) {
/* Show All Interfaces.*/
- for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) {
+ for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id),
+ node, ifp)) {
if (ospf_oi_count(ifp)) {
if (use_json)
json_interface_sub =
} else {
/* Interface name is specified. */
if ((ifp = if_lookup_by_name(argv[iface_argv]->arg,
- VRF_DEFAULT))
+ ospf->vrf_id))
== NULL) {
if (use_json)
json_object_boolean_true_add(json,
DEFUN (show_ip_ospf_interface,
show_ip_ospf_interface_cmd,
- "show ip ospf interface [INTERFACE] [json]",
+ "show ip ospf [vrf NAME] interface [INTERFACE] [json]",
SHOW_STR
IP_STR
"OSPF information\n"
+ VRF_CMD_HELP_STR
"Interface information\n"
"Interface name\n"
JSON_STR)
{
struct ospf *ospf;
u_char uj = use_json(argc, argv);
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
+ int idx_vrf = 0;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
-
+ if (argv_find(argv, argc, "vrf", &idx_vrf)) {
+ vrf_name = argv[idx_vrf + 1]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
if (uj)
argc--;
- return show_ip_ospf_interface_common(vty, ospf, argc, argv, 4, uj);
+ /* vrf input is provided could be all or specific vrf*/
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_interface_common(vty,
+ ospf, argc,
+ argv, 6,
+ uj);
+ }
+ return ret;
+ }
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ ret = show_ip_ospf_interface_common(vty, ospf,
+ argc, argv, 6, uj);
+
+ } else {
+ /* Display default ospf (instance 0) info */
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ ret = show_ip_ospf_interface_common(vty, ospf,
+ argc, argv, 4, uj);
+ }
+
+ return ret;
}
DEFUN (show_ip_ospf_instance_interface,
if (use_json)
json = json_object_new_object();
- else
- show_ip_ospf_neighbour_header(vty);
if (ospf->instance) {
if (use_json)
DEFUN (show_ip_ospf_neighbor,
show_ip_ospf_neighbor_cmd,
- "show ip ospf neighbor [json]",
+ "show ip ospf [vrf <NAME|all>] neighbor [json]",
SHOW_STR
IP_STR
"OSPF information\n"
+ VRF_CMD_HELP_STR
+ "All VRFs\n"
"Neighbor list\n"
JSON_STR)
{
struct ospf *ospf;
u_char uj = use_json(argc, argv);
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
+ int idx_vrf = 0;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
+ if (argv_find(argv, argc, "vrf", &idx_vrf)) {
+ vrf_name = argv[idx_vrf + 1]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
- return show_ip_ospf_neighbor_common(vty, ospf, uj);
+ if (!uj)
+ show_ip_ospf_neighbour_header(vty);
+
+ /* vrf input is provided could be all or specific vrf*/
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_neighbor_common(vty, ospf,
+ uj);
+ }
+ return ret;
+ }
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ } else {
+ /* Display default ospf (instance 0) info */
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ }
+
+ if (ospf)
+ ret = show_ip_ospf_neighbor_common(vty, ospf, uj);
+
+ return ret;
}
if (!ospf->oi_running)
return CMD_SUCCESS;
+ if (!uj)
+ show_ip_ospf_neighbour_header(vty);
+
return show_ip_ospf_neighbor_common(vty, ospf, uj);
}
if (use_json) {
json = json_object_new_object();
json_neighbor_sub = json_object_new_object();
- } else
- show_ip_ospf_neighbour_header(vty);
+ }
if (ospf->instance) {
if (use_json)
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
}
+ if (ospf->name) {
+ if (use_json) {
+ json_object_int_add(json, "vrfId",
+ (ospf->vrf_id == VRF_UNKNOWN)
+ ? -1 : ospf->vrf_id);
+ json_object_string_add(json, "vrfName",
+ (ospf->vrf_id == VRF_DEFAULT)
+ ? "Default" : ospf->name);
+ } else {
+ vty_out(vty, "\nOSPF vrf: %s\n\n",
+ ospf->vrf_id == VRF_DEFAULT
+ ? "Default" : ospf->name);
+ }
+ }
+
+
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
struct listnode *nbr_node;
struct ospf_nbr_nbma *nbr_nbma;
DEFUN (show_ip_ospf_neighbor_all,
show_ip_ospf_neighbor_all_cmd,
- "show ip ospf neighbor all [json]",
+ "show ip ospf [vrf <NAME|all>] neighbor all [json]",
SHOW_STR
IP_STR
"OSPF information\n"
+ VRF_CMD_HELP_STR
+ "All VRFs\n"
"Neighbor list\n"
"include down status neighbor\n"
JSON_STR)
{
struct ospf *ospf;
u_char uj = use_json(argc, argv);
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
+ int idx_vrf = 0;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
+ if (argv_find(argv, argc, "vrf", &idx_vrf)) {
+ vrf_name = argv[idx_vrf + 1]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
- return show_ip_ospf_neighbor_all_common(vty, ospf, uj);
+ if (!uj)
+ show_ip_ospf_neighbour_header(vty);
+
+ /* vrf input is provided could be all or specific vrf*/
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_neighbor_all_common(vty,
+ ospf,
+ uj);
+ }
+ return ret;
+ }
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ } else {
+ /* Display default ospf (instance 0) info */
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ }
+
+ if (ospf)
+ ret = show_ip_ospf_neighbor_all_common(vty, ospf, uj);
+
+ return ret;
}
DEFUN (show_ip_ospf_instance_neighbor_all,
if (use_json)
json = json_object_new_object();
- else
- show_ip_ospf_neighbour_header(vty);
if (ospf->instance) {
if (use_json)
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
}
- ifp = if_lookup_by_name(argv[arg_base]->arg, VRF_DEFAULT);
+ /*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/
+ ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg);
if (!ifp) {
if (use_json)
json_object_boolean_true_add(json, "noSuchIface");
struct ospf *ospf;
int idx_ifname = 4;
u_char uj = use_json(argc, argv);
+ struct listnode *node = NULL;
+ int ret = CMD_SUCCESS;
+ struct interface *ifp = NULL;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
+ if (!uj)
+ show_ip_ospf_neighbour_header(vty);
- return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj);
+ ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg);
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ if (!ifp || ifp->vrf_id != ospf->vrf_id)
+ continue;
+ ret = show_ip_ospf_neighbor_int_common(vty, ospf,
+ idx_ifname, argv, uj);
+ }
+
+ return ret;
}
DEFUN (show_ip_ospf_instance_neighbor_int,
u_short instance = 0;
u_char uj = use_json(argc, argv);
+ if (!uj)
+ show_ip_ospf_neighbour_header(vty);
+
instance = strtoul(argv[idx_number]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
if (!ospf->oi_running)
return CMD_SUCCESS;
+ if (!uj)
+ show_ip_ospf_neighbour_header(vty);
+
return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj);
}
JSON_STR)
{
struct ospf *ospf;
- int idx_router_id = 4;
u_char uj = use_json(argc, argv);
+ struct listnode *node = NULL;
+ int ret = CMD_SUCCESS;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_neighbor_id_common(vty, ospf, 0, argv, uj);
+ }
- return show_ip_ospf_neighbor_id_common(vty, ospf, idx_router_id, argv, uj);
+ return ret;
}
DEFUN (show_ip_ospf_instance_neighbor_id,
DEFUN (show_ip_ospf_neighbor_detail,
show_ip_ospf_neighbor_detail_cmd,
- "show ip ospf neighbor detail [json]",
+ "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
SHOW_STR
IP_STR
"OSPF information\n"
+ VRF_CMD_HELP_STR
+ "All VRFs\n"
"Neighbor list\n"
"detail of all neighbors\n"
JSON_STR)
{
struct ospf *ospf;
u_char uj = use_json(argc, argv);
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
+ int idx_vrf = 0;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
+ if (argv_find(argv, argc, "vrf", &idx_vrf)) {
+ vrf_name = argv[idx_vrf + 1]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
- return show_ip_ospf_neighbor_detail_common(vty, ospf, uj);
+ /* vrf input is provided could be all or specific vrf*/
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_neighbor_detail_common(vty,
+ ospf,
+ uj);
+ }
+ return ret;
+ }
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ } else {
+ /* Display default ospf (instance 0) info */
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ }
+
+ if (ospf)
+ ret = show_ip_ospf_neighbor_detail_common(vty, ospf, uj);
+
+ return ret;
}
DEFUN (show_ip_ospf_instance_neighbor_detail,
DEFUN (show_ip_ospf_neighbor_detail_all,
show_ip_ospf_neighbor_detail_all_cmd,
- "show ip ospf neighbor detail all [json]",
+ "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
SHOW_STR
IP_STR
"OSPF information\n"
+ VRF_CMD_HELP_STR
+ "All VRFs\n"
"Neighbor list\n"
"detail of all neighbors\n"
"include down status neighbor\n"
{
struct ospf *ospf;
u_char uj = use_json(argc, argv);
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
+ int idx_vrf = 0;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
+ if (argv_find(argv, argc, "vrf", &idx_vrf)) {
+ vrf_name = argv[idx_vrf + 1]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
- return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj);
+ /* vrf input is provided could be all or specific vrf*/
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_neighbor_detail_all_common(vty,
+ ospf,
+ uj);
+ }
+ return ret;
+ }
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ } else {
+ /* Display default ospf (instance 0) info */
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ }
+
+ if (ospf)
+ ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj);
+
+ return ret;
}
DEFUN (show_ip_ospf_instance_neighbor_detail_all,
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
}
- ifp = if_lookup_by_name(argv[arg_base]->arg, VRF_DEFAULT);
+ ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg);
if (!ifp) {
if (!use_json)
vty_out(vty, "No such interface.\n");
JSON_STR)
{
struct ospf *ospf;
- int idx_ifname = 4;
u_char uj = use_json(argc, argv);
+ struct listnode *node = NULL;
+ int ret = CMD_SUCCESS;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0,
+ argv, uj);
+ }
- return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, argv, uj);
+ return ret;
}
DEFUN (show_ip_ospf_instance_neighbor_int_detail,
DEFUN (show_ip_ospf_database_max,
show_ip_ospf_database_max_cmd,
- "show ip ospf database <max-age|self-originate>",
+ "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
SHOW_STR
IP_STR
"OSPF information\n"
+ VRF_CMD_HELP_STR
+ "All VRFs\n"
"Database summary\n"
"LSAs in MaxAge list\n"
"Self-originated link states\n")
{
- struct ospf *ospf;
+ struct ospf *ospf = NULL;
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
+ int idx_vrf = 0;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
+ if (argv_find(argv, argc, "vrf", &idx_vrf)) {
+ vrf_name = argv[idx_vrf + 1]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
- return (show_ip_ospf_database_common(vty, ospf, 0, argc, argv));
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_database_common(vty, ospf,
+ idx_vrf ? 2
+ : 0, argc,
+ argv);
+ }
+ } else {
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ ret = (show_ip_ospf_database_common(vty, ospf, idx_vrf ?
+ 2 : 0, argc, argv));
+ }
+ } else {
+ /* Display default ospf (instance 0) info */
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv);
+ }
+
+ return ret;
}
DEFUN (show_ip_ospf_instance_database,
show_ip_ospf_instance_database_cmd,
- "show ip ospf [(1-65535)] 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"
"Instance ID\n"
+ VRF_CMD_HELP_STR
"Database summary\n"
OSPF_LSA_TYPES_DESC
"Link State ID (as an IP address)\n"
{
struct ospf *ospf;
u_short instance = 0;
-
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
int idx = 0;
+
if (argv_find(argv, argc, "(1-65535)", &idx)) {
instance = strtoul(argv[idx]->arg, NULL, 10);
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
return CMD_NOT_MY_INSTANCE;
- } else {
- ospf = ospf_lookup();
+ if (!ospf->oi_running)
+ return CMD_SUCCESS;
+
+ return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0,
+ argc, argv));
+ } else if (argv_find(argv, argc, "vrf", &idx)) {
+ vrf_name = argv[++idx]->arg;
+ all_vrf = strmatch(vrf_name, "all");
}
- if (!ospf || !ospf->oi_running)
- return CMD_SUCCESS;
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = (show_ip_ospf_database_common(vty, ospf,
+ idx ? 2 : 0,
+ argc, argv));
+ }
+ } else {
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if ((ospf == NULL) || !ospf->oi_running)
+ return CMD_SUCCESS;
+ ret = (show_ip_ospf_database_common(vty, ospf, idx ? 2 :
+ 0, argc, argv));
+ }
+ } else {
+ /* Display default ospf (instance 0) info */
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv));
+ }
- return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, argc,
- argv));
+ return ret;
}
DEFUN (show_ip_ospf_instance_database_max,
DEFUN (show_ip_ospf_instance_database_type_adv_router,
show_ip_ospf_instance_database_type_adv_router_cmd,
- "show ip ospf [(1-65535)] 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"
"Instance ID\n"
+ VRF_CMD_HELP_STR
"Database summary\n"
OSPF_LSA_TYPES_DESC
"Advertising Router link states\n"
"Advertising Router (as an IP address)\n"
"Self-originated link states\n")
{
- struct ospf *ospf;
+ struct ospf *ospf = NULL;
u_short instance = 0;
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
int idx = 0;
if (argv_find(argv, argc, "(1-65535)", &idx)) {
ospf = ospf_lookup_instance(instance);
if (ospf == NULL)
return CMD_NOT_MY_INSTANCE;
- } else
- ospf = ospf_lookup();
-
- if (!ospf || !ospf->oi_running)
- return CMD_SUCCESS;
-
- return (show_ip_ospf_database_type_adv_router_common(
- vty, ospf, idx ? 1 : 0, argc, argv));
+ if (!ospf->oi_running)
+ return CMD_SUCCESS;
+ return (show_ip_ospf_database_type_adv_router_common(vty, ospf,
+ idx ? 1 : 0,
+ argc,
+ argv));
+ }
+ if (argv_find(argv, argc, "vrf", &idx)) {
+ vrf_name = argv[++idx]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_database_type_adv_router_common(vty,
+ ospf, idx ? 1 : 0, argc, argv);
+ }
+ } else {
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if ((ospf == NULL) || !ospf->oi_running)
+ return CMD_SUCCESS;
+ ret = show_ip_ospf_database_type_adv_router_common(vty,
+ ospf, idx ? 1 : 0, argc, argv);
+ }
+ } else {
+ /* Display default ospf (instance 0) info */
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ ret = show_ip_ospf_database_type_adv_router_common(vty, ospf,
+ idx ? 1 : 0,
+ argc, argv);
+ }
+ return ret;
+ /*return (show_ip_ospf_database_type_adv_router_common(
+ vty, ospf, idx ? 1 : 0, argc, argv));*/
}
DEFUN (ip_ospf_authentication_args,
/* Update timer values in neighbor structure. */
if (nbr_str) {
- struct ospf *ospf;
- if ((ospf = ospf_lookup())) {
+ struct ospf *ospf = NULL;
+
+ ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ if (ospf) {
oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
if (oi)
ospf_nbr_timer_update(oi);
/* Update timer values in neighbor structure. */
if (argc == 1) {
- struct ospf *ospf;
+ struct ospf *ospf = NULL;
- if ((ospf = ospf_lookup())) {
+ ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ if (ospf) {
oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
if (oi)
ospf_nbr_timer_update(oi);
struct in_addr addr;
struct ospf_if_params *params;
struct route_node *rn;
- struct ospf *ospf;
+ struct ospf *ospf = NULL;
u_short instance = 0;
char *areaid;
argv_find(argv, argc, "area", &idx);
areaid = argv[idx + 1]->arg;
- ospf = ospf_lookup_instance(instance);
+ if (ifp->vrf_id && !instance)
+ ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ else
+ ospf = ospf_lookup_instance(instance);
+
if (ospf == NULL) {
params = IF_DEF_PARAMS(ifp);
if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
UNSET_IF_PARAM(params, if_area);
- ospf_interface_area_unset(ifp);
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ ospf_interface_area_unset(ospf, ifp);
ospf->if_ospf_cli_count--;
}
return CMD_NOT_MY_INSTANCE;
SET_IF_PARAM(params, if_area);
params->if_area = area_id;
params->if_area_id_fmt = format;
- ospf_interface_area_set(ifp);
+ ospf_interface_area_set(ospf, ifp);
ospf->if_ospf_cli_count++;
return CMD_SUCCESS;
if (argv_find(argv, argc, "(1-65535)", &idx))
instance = strtol(argv[idx]->arg, NULL, 10);
- ospf = ospf_lookup_instance(instance);
+ if (ifp->vrf_id && !instance)
+ ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ else
+ ospf = ospf_lookup_instance(instance);
+
if (ospf == NULL)
return CMD_NOT_MY_INSTANCE;
ospf_if_update_params((ifp), (addr));
}
- ospf_interface_area_unset(ifp);
+ ospf_interface_area_unset(ospf, ifp);
ospf->if_ospf_cli_count--;
return CMD_SUCCESS;
}
int idx_number = 3;
unsigned int seconds;
- if (argc != 1) {
+ if (argc < 4) {
vty_out(vty, "%% Must supply stub-router period");
return CMD_WARNING_CONFIG_FAILED;
}
int idx_number = 3;
unsigned int seconds;
- if (argc != 1) {
+ if (argc < 4) {
vty_out(vty, "%% Must supply stub-router shutdown period");
return CMD_WARNING_CONFIG_FAILED;
}
return;
}
-static void show_ip_ospf_route_network(struct vty *vty, struct route_table *rt)
+static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
+ struct route_table *rt)
{
struct route_node *rn;
struct ospf_route * or ;
for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
path)) {
if (if_lookup_by_index(path->ifindex,
- VRF_DEFAULT)) {
+ ospf->vrf_id)) {
if (path->nexthop.s_addr == 0)
vty_out(vty,
"%24s directly attached to %s\n",
"",
ifindex2ifname(
path->ifindex,
- VRF_DEFAULT));
+ ospf->vrf_id));
else
vty_out(vty,
"%24s via %s, %s\n",
path->nexthop),
ifindex2ifname(
path->ifindex,
- VRF_DEFAULT));
+ ospf->vrf_id));
}
}
}
vty_out(vty, "\n");
}
-static void show_ip_ospf_route_router(struct vty *vty, struct route_table *rtrs)
+static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
+ struct route_table *rtrs)
{
struct route_node *rn;
struct ospf_route * or ;
struct listnode *node;
struct ospf_path *path;
- vty_out(vty, "============ OSPF router routing table =============\n");
+ /*vty_out(vty, "============ OSPF router routing table =============\n");*/
for (rn = route_top(rtrs); rn; rn = route_next(rn))
if (rn->info) {
int flag = 0;
for (ALL_LIST_ELEMENTS_RO(or->paths, pnode,
path)) {
if (if_lookup_by_index(path->ifindex,
- VRF_DEFAULT)) {
+ ospf->vrf_id)) {
if (path->nexthop.s_addr == 0)
vty_out(vty,
"%24s directly attached to %s\n",
"",
ifindex2ifname(
path->ifindex,
- VRF_DEFAULT));
+ ospf->vrf_id));
else
vty_out(vty,
"%24s via %s, %s\n",
path->nexthop),
ifindex2ifname(
path->ifindex,
- VRF_DEFAULT));
+ ospf->vrf_id));
}
}
}
vty_out(vty, "\n");
}
-static void show_ip_ospf_route_external(struct vty *vty, struct route_table *rt)
+static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
+ struct route_table *rt)
{
struct route_node *rn;
struct ospf_route *er;
for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode,
path)) {
if (if_lookup_by_index(path->ifindex,
- VRF_DEFAULT)) {
+ ospf->vrf_id)) {
if (path->nexthop.s_addr == 0)
vty_out(vty,
"%24s directly attached to %s\n",
"",
ifindex2ifname(
path->ifindex,
- VRF_DEFAULT));
+ ospf->vrf_id));
else
vty_out(vty,
"%24s via %s, %s\n",
path->nexthop),
ifindex2ifname(
path->ifindex,
- VRF_DEFAULT));
+ ospf->vrf_id));
}
}
}
show_ip_ospf_route_network (vty, ospf->new_table); */
/* Show Router routes. */
- show_ip_ospf_route_router(vty, ospf->new_rtrs);
+ show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs);
vty_out(vty, "\n");
DEFUN (show_ip_ospf_border_routers,
show_ip_ospf_border_routers_cmd,
- "show ip ospf border-routers",
+ "show ip ospf [vrf <NAME|all>] border-routers",
SHOW_STR
IP_STR
"OSPF information\n"
+ VRF_CMD_HELP_STR
+ "All VRFs\n"
"Show all the ABR's and ASBR's\n")
{
- struct ospf *ospf;
+ struct ospf *ospf = NULL;
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
+ int idx_vrf = 0;
+ int count = 0;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
+ if (argv_find(argv, argc, "vrf", &idx_vrf)) {
+ vrf_name = argv[idx_vrf + 1]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
- return show_ip_ospf_border_routers_common(vty, ospf);
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ count++;
+ if (count == 1)
+ vty_out(vty,
+ "============ OSPF router routing table =============\n");
+
+ ret = show_ip_ospf_border_routers_common(vty,
+ ospf);
+ }
+ } else {
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+
+ vty_out(vty, "============ OSPF router routing table =============\n");
+ ret = show_ip_ospf_border_routers_common(vty, ospf);
+ }
+ } else {
+ /* Display default ospf (instance 0) info */
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ vty_out(vty, "============ OSPF router routing table =============\n");
+ ret = show_ip_ospf_border_routers_common(vty, ospf);
+ }
+
+ return ret;
}
DEFUN (show_ip_ospf_instance_border_routers,
}
/* Show Network routes. */
- show_ip_ospf_route_network(vty, ospf->new_table);
+ show_ip_ospf_route_network(vty, ospf, ospf->new_table);
/* Show Router routes. */
- show_ip_ospf_route_router(vty, ospf->new_rtrs);
+ show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs);
/* Show AS External routes. */
- show_ip_ospf_route_external(vty, ospf->old_external_route);
+ show_ip_ospf_route_external(vty, ospf, ospf->old_external_route);
vty_out(vty, "\n");
DEFUN (show_ip_ospf_route,
show_ip_ospf_route_cmd,
- "show ip ospf route",
- SHOW_STR
- IP_STR
- "OSPF information\n"
- "OSPF routing table\n")
-{
- struct ospf *ospf;
+ "show ip ospf [vrf <NAME|all>] route",
+ SHOW_STR
+ IP_STR
+ "OSPF information\n"
+ VRF_CMD_HELP_STR
+ "All VRFs\n"
+ "OSPF routing table\n")
+{
+ struct ospf *ospf = NULL;
+ struct listnode *node = NULL;
+ char *vrf_name = NULL;
+ bool all_vrf = FALSE;
+ int ret = CMD_SUCCESS;
+ int inst = 0;
+ int idx_vrf = 0;
- if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
- return CMD_SUCCESS;
+ if (argv_find (argv, argc, "vrf", &idx_vrf)) {
+ vrf_name = argv[idx_vrf + 1]->arg;
+ all_vrf = strmatch(vrf_name, "all");
+ }
- return show_ip_ospf_route_common(vty, ospf);
+ /* vrf input is provided could be all or specific vrf*/
+ if (vrf_name) {
+ if (all_vrf) {
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ if (!ospf->oi_running)
+ continue;
+ ret = show_ip_ospf_route_common(vty, ospf);
+ }
+ return ret;
+ }
+ ospf = ospf_lookup_by_inst_name(inst, vrf_name);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ } else {
+ /* Display default ospf (instance 0) info */
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+ if (ospf == NULL || !ospf->oi_running)
+ return CMD_SUCCESS;
+ }
+
+ if (ospf)
+ ret = show_ip_ospf_route_common(vty, ospf);
+
+ return ret;
}
DEFUN (show_ip_ospf_instance_route,
return show_ip_ospf_route_common(vty, ospf);
}
+
+DEFUN (show_ip_ospf_vrfs,
+ show_ip_ospf_vrfs_cmd,
+ "show ip ospf vrfs [json]",
+ SHOW_STR
+ IP_STR
+ "OSPF information\n"
+ "Show OSPF VRFs \n"
+ JSON_STR)
+{
+ u_char uj = use_json(argc, argv);
+ json_object *json = NULL;
+ json_object *json_vrfs = NULL;
+ struct ospf *ospf = NULL;
+ struct listnode *node = NULL;
+ int count = 0;
+ static char header[] = "Name Id RouterId ";
+
+ if (uj) {
+ json = json_object_new_object();
+ json_vrfs = json_object_new_object();
+ }
+
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
+ json_object *json_vrf = NULL;
+ const char *name = NULL;
+ int vrf_id_ui = 0;
+
+ count++;
+
+ if (!uj && count == 1)
+ vty_out(vty, "%s\n", header);
+ if (uj)
+ json_vrf = json_object_new_object();
+
+ if (ospf->vrf_id == 0)
+ name = VRF_DEFAULT_NAME;
+ else
+ name = ospf->name;
+
+ vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) ? -1 : ospf->vrf_id;
+
+ if (uj) {
+ json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
+ json_object_string_add(json_vrf, "routerId",
+ inet_ntoa(ospf->router_id));
+
+ json_object_object_add(json_vrfs, name, json_vrf);
+
+ } else {
+ vty_out(vty, "%-25s %-5d %-16s \n",
+ name, ospf->vrf_id, inet_ntoa(ospf->router_id));
+ }
+ }
+
+ if (uj) {
+ json_object_object_add(json, "vrfs", json_vrfs);
+ json_object_int_add(json, "totalVrfs", count);
+
+ vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
+ JSON_C_TO_STRING_PRETTY));
+ json_object_free(json);
+ } else {
+ if (count)
+ vty_out(vty, "\nTotal number of OSPF VRFs (including default): %d\n",
+ count);
+ }
+
+ return CMD_SUCCESS;
+}
+
const char *ospf_abr_type_str[] = {"unknown", "standard", "ibm", "cisco",
"shortcut"};
int write = 0;
struct route_node *rn = NULL;
struct ospf_if_params *params;
- struct ospf *ospf = ospf_lookup();
+ struct ospf *ospf = NULL;
+ struct listnode *node = NULL;
- for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), n1, ifp)) {
- if (memcmp(ifp->name, "VLINK", 5) == 0)
- continue;
+ /* Traverse all ospf [vrf] instances */
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
- if (ifp->ifindex == IFINDEX_DELETED)
- continue;
+ for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), n1, ifp)) {
+ if (memcmp(ifp->name, "VLINK", 5) == 0)
+ continue;
- vty_frame(vty, "!\n");
- vty_frame(vty, "interface %s\n", ifp->name);
- if (ifp->desc)
- vty_out(vty, " description %s\n", ifp->desc);
+ if (ifp->ifindex == IFINDEX_DELETED)
+ continue;
- write++;
+ vty_frame(vty, "!\n");
+ vty_frame(vty, "interface %s\n", ifp->name);
+ if (ifp->desc)
+ vty_out(vty, " description %s\n", ifp->desc);
- params = IF_DEF_PARAMS(ifp);
+ 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
+ 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",
+ if (params != IF_DEF_PARAMS(ifp))
+ vty_out(vty, " %s",
inet_ntoa(
rn->p.u.prefix4));
- vty_out(vty, "\n");
+ 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;
+ /* 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) {
+ /* Translation tables are not that much help
+ * here due to syntax
+ * of the simple option */
+ switch (params->auth_type) {
- case OSPF_AUTH_NULL:
- auth_str = " null";
- break;
+ case OSPF_AUTH_NULL:
+ auth_str = " null";
+ break;
- case OSPF_AUTH_SIMPLE:
- auth_str = "";
- break;
+ case OSPF_AUTH_SIMPLE:
+ auth_str = "";
+ break;
- case OSPF_AUTH_CRYPTOGRAPHIC:
- auth_str = " message-digest";
- break;
+ case OSPF_AUTH_CRYPTOGRAPHIC:
+ auth_str = " message-digest";
+ break;
- default:
- auth_str = "";
- break;
+ default:
+ auth_str = "";
+ 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");
}
- 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");
- }
+ /* 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");
+ }
- /* 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");
- }
+ /* 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");
+ }
- /* 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");
- }
+ /* 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");
+ }
- /* 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");
+ }
- /* 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 ");
- /* 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);
- /* 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);
+ 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");
- }
+ /* 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");
+ }
- /* 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");
- }
+ /* 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");
+ }
- /* 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");
- }
+ /* 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");
+ }
- /* 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");
- /* 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];
+ 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");
+ }
- /* 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");
- }
+ /* bfd print. */
+ ospf_bfd_write_config(vty, params);
+ /* 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");
+ }
- while (1) {
- if (rn == NULL)
- rn = route_top(IF_OIFS_PARAMS(ifp));
- else
- rn = route_next(rn);
- if (rn == NULL)
- break;
- params = rn->info;
- if (params != NULL)
- break;
- }
- } while (rn);
+ while (1) {
+ if (rn == NULL)
+ rn = route_top(IF_OIFS_PARAMS(ifp));
+ else
+ rn = route_next(rn);
- ospf_opaque_config_write_if(vty, ifp);
+ if (rn == NULL)
+ break;
+ params = rn->info;
+ if (params != NULL)
+ break;
+ }
+ } while (rn);
- vty_endframe(vty, NULL);
- }
+ ospf_opaque_config_write_if(vty, ifp);
+ vty_endframe(vty, NULL);
+ }
+ }
return write;
}
struct ospf *ospf;
struct interface *ifp;
struct ospf_interface *oi;
- struct listnode *node;
+ struct listnode *node, *ospf_node = NULL;
int write = 0;
- ospf = ospf_lookup();
- if (ospf != NULL && ospf->oi_running) {
- /* `router ospf' print. */
- if (ospf->instance)
- vty_out(vty, "router ospf %d\n", ospf->instance);
- else
- vty_out(vty, "router ospf\n");
-
- write++;
-
- if (!ospf->networks)
- return write;
-
- /* 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");
- }
+ if (listcount(om->ospf) == 0)
+ 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");
- /* RFC1583 compatibility flag print -- Compatible with CISCO
- * 12.1. */
- if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
- vty_out(vty, " compatible rfc1583\n");
+ if (!ospf->networks) {
+ write++;
+ 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);
- }
+ /* 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");
+ }
+
+ /* RFC1583 compatibility flag print -- Compatible with CISCO
+ * 12.1. */
+ if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
+ vty_out(vty, " compatible rfc1583\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);
+ }
- /* 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
+ /* 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)
+ 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;
- } else if (oi->params->passive_interface
- == ospf->passive_interface_default)
- continue;
- vty_out(vty, " %spassive-interface %s %s\n",
- oi->params->passive_interface ? "" : "no ",
- oi->ifp->name,
- inet_ntoa(oi->address->u.prefix4));
- }
+ vty_out(vty, " %spassive-interface %s %s\n",
+ oi->params->passive_interface ? "" : "no ",
+ oi->ifp->name,
+ inet_ntoa(oi->address->u.prefix4));
+ }
- /* Network area print. */
- config_write_network_area(vty, ospf);
+ /* Network area print. */
+ config_write_network_area(vty, ospf);
- /* Area config print. */
- config_write_ospf_area(vty, ospf);
+ /* Area config print. */
+ config_write_ospf_area(vty, ospf);
- /* static neighbor print. */
- config_write_ospf_nbr_nbma(vty, ospf);
+ /* static neighbor print. */
+ config_write_ospf_nbr_nbma(vty, ospf);
- /* Virtual-Link print. */
- config_write_virtual_link(vty, ospf);
+ /* Virtual-Link print. */
+ config_write_virtual_link(vty, ospf);
- /* Default metric configuration. */
- config_write_ospf_default_metric(vty, ospf);
+ /* Default metric configuration. */
+ config_write_ospf_default_metric(vty, ospf);
- /* Distribute-list and default-information print. */
- config_write_ospf_distribute(vty, ospf);
+ /* Distribute-list and default-information print. */
+ config_write_ospf_distribute(vty, ospf);
- /* Distance configuration. */
- config_write_ospf_distance(vty, ospf);
+ /* Distance configuration. */
+ config_write_ospf_distance(vty, ospf);
- ospf_opaque_config_write_router(vty, ospf);
- }
+ ospf_opaque_config_write_router(vty, ospf);
+ write++;
+ }
+ }
return write;
}
install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
+
+ /* "show ip ospf vrfs" commands. */
+ install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd);
}
{
int idx_ifname = 4;
struct interface *ifp;
- struct listnode *node;
+ struct listnode *node, *n1;
+ struct ospf *ospf = NULL;
if (argc == 4) /* Clear all the ospfv2 interfaces. */
{
- for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
- ospf_interface_clear(ifp);
- } else /* Interface name is specified. */
- {
- if ((ifp = if_lookup_by_name(argv[idx_ifname]->arg,
- VRF_DEFAULT))
- == NULL)
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) {
+ for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id),
+ node, ifp))
+ ospf_interface_clear(ifp);
+ }
+ } else {
+ /* Interface name is specified. */
+ ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg);
+ if (ifp == NULL)
vty_out(vty, "No such interface name\n");
else
ospf_interface_clear(ifp);
DEFINE_MTYPE_STATIC(OSPFD, OSPF_EXTERNAL, "OSPF External route table")
DEFINE_MTYPE_STATIC(OSPFD, OSPF_REDISTRIBUTE, "OSPF Redistriute")
+DEFINE_MTYPE_STATIC(OSPFD, OSPF_DIST_ARGS, "OSPF Distribute arguments")
DEFINE_HOOK(ospf_if_update, (struct interface * ifp), (ifp))
DEFINE_HOOK(ospf_if_delete, (struct interface * ifp), (ifp))
static int ospf_router_id_update_zebra(int command, struct zclient *zclient,
zebra_size_t length, vrf_id_t vrf_id)
{
- struct ospf *ospf;
+ struct ospf *ospf = NULL;
struct prefix router_id;
zebra_router_id_update_read(zclient->ibuf, &router_id);
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) {
char buf[PREFIX2STR_BUFFER];
prefix2str(&router_id, buf, sizeof(buf));
- zlog_debug("Zebra rcvd: router id update %s", buf);
+ zlog_debug("Zebra rcvd: router id update %s vrf %s id %u",
+ buf, ospf_vrf_id_to_name(vrf_id), vrf_id);
}
router_id_zebra = router_id.u.prefix4;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(vrf_id);
if (ospf != NULL)
ospf_router_id_update(ospf);
-
+ else {
+ if (IS_DEBUG_OSPF_EVENT) {
+ char buf[PREFIX2STR_BUFFER];
+
+ prefix2str(&router_id, buf, sizeof(buf));
+ zlog_debug("%s: ospf instance not found for vrf %s id %u router_id %s",
+ __PRETTY_FUNCTION__,
+ ospf_vrf_id_to_name(vrf_id), vrf_id, buf);
+ }
+ }
return 0;
}
static int ospf_interface_add(int command, struct zclient *zclient,
zebra_size_t length, vrf_id_t vrf_id)
{
- struct interface *ifp;
+ struct interface *ifp = NULL;
+ struct ospf *ospf = NULL;
ifp = zebra_interface_add_read(zclient->ibuf, vrf_id);
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
zlog_debug(
- "Zebra: interface add %s[%u] index %d flags %llx metric %d mtu %d",
- ifp->name, ifp->vrf_id, ifp->ifindex,
+ "Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d",
+ ifp->name, ospf_vrf_id_to_name(ifp->vrf_id),
+ ifp->vrf_id, ifp->ifindex,
(unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
assert(ifp->info);
IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
}
- ospf_if_update(NULL, ifp);
+ ospf = ospf_lookup_by_vrf_id(vrf_id);
+
+ ospf_if_update(ospf, ifp);
hook_call(ospf_if_update, ifp);
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
zlog_debug(
- "Zebra: interface delete %s[%u] index %d flags %llx metric %d mtu %d",
- ifp->name, ifp->vrf_id, ifp->ifindex,
+ "Zebra: interface delete %s vrf %s[%u] index %d flags %llx metric %d mtu %d",
+ ifp->name, ospf_vrf_id_to_name(ifp->vrf_id),
+ ifp->vrf_id, ifp->ifindex,
(unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
hook_call(ospf_if_delete, ifp);
/* And look it up. */
return if_lookup_by_name_len(
- ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), VRF_DEFAULT);
+ ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), vrf_id);
}
static int ospf_interface_state_up(int command, struct zclient *zclient,
zebra_size_t length, vrf_id_t vrf_id)
{
struct connected *c;
+ struct ospf *ospf = NULL;
+
c = zebra_interface_address_read(command, zclient->ibuf, vrf_id);
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) {
char buf[PREFIX2STR_BUFFER];
prefix2str(c->address, buf, sizeof(buf));
- zlog_debug("Zebra: interface %s address add %s", c->ifp->name,
- buf);
+ zlog_debug("Zebra: interface %s address add %s vrf %s id %u",
+ c->ifp->name, buf, ospf_vrf_id_to_name(vrf_id),
+ vrf_id);
}
- ospf_if_update(NULL, c->ifp);
+ ospf = ospf_lookup_by_vrf_id(vrf_id);
+
+ ospf_if_update(ospf, c->ifp);
hook_call(ospf_if_update, c->ifp);
return 0;
}
+/* VRF update for an interface. */
+static int ospf_interface_vrf_update(int command, struct zclient *zclient,
+ zebra_size_t length, vrf_id_t vrf_id)
+{
+ struct interface *ifp = NULL;
+ vrf_id_t new_vrf_id;
-void ospf_zebra_add(struct prefix_ipv4 *p, struct ospf_route * or)
+ ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id,
+ &new_vrf_id);
+ if (!ifp)
+ return 0;
+
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: Rx Interface %s VRF change vrf_id %u New vrf %s id %u",
+ __PRETTY_FUNCTION__, ifp->name, vrf_id,
+ ospf_vrf_id_to_name(new_vrf_id), new_vrf_id);
+
+ /*if_update(ifp, ifp->name, strlen(ifp->name), new_vrf_id);*/
+ if_update_to_new_vrf(ifp, new_vrf_id);
+
+ return 0;
+}
+
+void ospf_zebra_add(struct ospf *ospf, struct prefix_ipv4 *p,
+ struct ospf_route *or)
{
struct zapi_route api;
struct zapi_nexthop *api_nh;
u_char distance;
struct ospf_path *path;
struct listnode *node;
- struct ospf *ospf = ospf_lookup();
int count = 0;
memset(&api, 0, sizeof(api));
- api.vrf_id = VRF_DEFAULT;
+ api.vrf_id = ospf->vrf_id;
api.type = ZEBRA_ROUTE_OSPF;
api.instance = ospf->instance;
api.safi = SAFI_UNICAST;
}
/* Distance value. */
- distance = ospf_distance_apply(p, or);
+ distance = ospf_distance_apply(ospf, p, or);
if (distance) {
SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
api.distance = distance;
zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
}
-void ospf_zebra_delete(struct prefix_ipv4 *p, struct ospf_route * or)
+void ospf_zebra_delete(struct ospf *ospf, struct prefix_ipv4 *p,
+ struct ospf_route *or)
{
struct zapi_route api;
- struct ospf *ospf = ospf_lookup();
memset(&api, 0, sizeof(api));
- api.vrf_id = VRF_DEFAULT;
+ api.vrf_id = ospf->vrf_id;
api.type = ZEBRA_ROUTE_OSPF;
api.instance = ospf->instance;
api.safi = SAFI_UNICAST;
zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
}
-void ospf_zebra_add_discard(struct prefix_ipv4 *p)
+void ospf_zebra_add_discard(struct ospf *ospf, struct prefix_ipv4 *p)
{
struct zapi_route api;
- struct ospf *ospf = ospf_lookup();
memset(&api, 0, sizeof(api));
- api.vrf_id = VRF_DEFAULT;
+ api.vrf_id = ospf->vrf_id;
api.type = ZEBRA_ROUTE_OSPF;
api.instance = ospf->instance;
api.safi = SAFI_UNICAST;
inet_ntoa(p->prefix), p->prefixlen);
}
-void ospf_zebra_delete_discard(struct prefix_ipv4 *p)
+void ospf_zebra_delete_discard(struct ospf *ospf, struct prefix_ipv4 *p)
{
struct zapi_route api;
- struct ospf *ospf = ospf_lookup();
memset(&api, 0, sizeof(api));
- api.vrf_id = VRF_DEFAULT;
+ api.vrf_id = ospf->vrf_id;
api.type = ZEBRA_ROUTE_OSPF;
api.instance = ospf->instance;
api.safi = SAFI_UNICAST;
}
-int ospf_is_type_redistributed(int type, u_short instance)
+int ospf_is_type_redistributed(struct ospf *ospf, int type, u_short instance)
{
return (DEFAULT_ROUTE_TYPE(type)
? vrf_bitmap_check(zclient->default_information,
- VRF_DEFAULT)
+ ospf->vrf_id)
: ((instance
&& redist_check_instance(
&zclient->mi_redist[AFI_IP][type],
|| (!instance
&& vrf_bitmap_check(
zclient->redist[AFI_IP][type],
- VRF_DEFAULT))));
+ ospf->vrf_id))));
}
int ospf_redistribute_set(struct ospf *ospf, int type, u_short instance,
struct ospf_redist *red;
red = ospf_redist_lookup(ospf, type, instance);
- if (ospf_is_type_redistributed(type, instance)) {
+ if (ospf_is_type_redistributed(ospf, type, instance)) {
if (mtype != red->dmetric.type) {
red->dmetric.type = mtype;
force = LSA_REFRESH_FORCE;
ospf_external_add(type, instance);
zclient_redistribute(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, type,
- instance, VRF_DEFAULT);
+ instance, ospf->vrf_id);
if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
- zlog_debug("Redistribute[%s][%d]: Start Type[%d], Metric[%d]",
- ospf_redist_string(type), instance,
+ zlog_debug("Redistribute[%s][%d] vrf id %u: Start Type[%d], Metric[%d]",
+ ospf_redist_string(type), instance, ospf->vrf_id,
metric_type(ospf, type, instance),
metric_value(ospf, type, instance));
if (type == zclient->redist_default && instance == zclient->instance)
return CMD_SUCCESS;
- if (!ospf_is_type_redistributed(type, instance))
+ if (!ospf_is_type_redistributed(ospf, type, instance))
return CMD_SUCCESS;
zclient_redistribute(ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type,
- instance, VRF_DEFAULT);
+ instance, ospf->vrf_id);
if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
- zlog_debug("Redistribute[%s][%d]: Stop",
- ospf_redist_string(type), instance);
+ zlog_debug("Redistribute[%s][%d] vrf id %u: Stop",
+ ospf_redist_string(type), instance, ospf->vrf_id);
ospf_redist_del(ospf, type, instance);
ospf_external_add(DEFAULT_ROUTE, 0);
- if (ospf_is_type_redistributed(DEFAULT_ROUTE, 0)) {
+ if (ospf_is_type_redistributed(ospf, DEFAULT_ROUTE, 0)) {
/* if ospf->default_originate changes value, is calling
ospf_external_lsa_refresh_default sufficient to implement
the change? */
}
zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient,
- VRF_DEFAULT);
+ ospf->vrf_id);
if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
zlog_debug("Redistribute[DEFAULT]: Start Type[%d], Metric[%d]",
int ospf_redistribute_default_unset(struct ospf *ospf)
{
- if (!ospf_is_type_redistributed(DEFAULT_ROUTE, 0))
+ if (!ospf_is_type_redistributed(ospf, DEFAULT_ROUTE, 0))
return CMD_SUCCESS;
ospf->default_originate = DEFAULT_ORIGINATE_NONE;
ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient,
- VRF_DEFAULT);
+ ospf->vrf_id);
if (IS_DEBUG_OSPF(zebra, ZEBRA_REDISTRIBUTE))
zlog_debug("Redistribute[DEFAULT]: Stop");
struct ospf *ospf;
int i;
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(vrf_id);
if (ospf == NULL)
return 0;
struct external_info *ei;
struct route_table *rt;
struct ospf_lsa *lsa;
- int type, default_refresh = 0;
- struct ospf *ospf;
+ int type, default_refresh = 0, arg_type;
+ struct ospf *ospf = NULL;
+ void **arg = THREAD_ARG (thread);
+
+ ospf = (struct ospf *)arg[0];
+ arg_type = (int)(intptr_t)arg[1];
- ospf = ospf_lookup();
if (ospf == NULL)
return 0;
zlog_info("Zebra[Redistribute]: distribute-list update timer fired!");
+ if (IS_DEBUG_OSPF_EVENT) {
+ zlog_debug("%s: ospf distribute-list update arg_type %d vrf %s id %d",
+ __PRETTY_FUNCTION__, arg_type,
+ ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id);
+ }
+
/* foreach all external info. */
for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
struct list *ext_list;
}
if (default_refresh)
ospf_external_lsa_refresh_default(ospf);
+
+ XFREE(MTYPE_OSPF_DIST_ARGS, arg);
return 0;
}
/* Update distribute-list and set timer to apply access-list. */
-void ospf_distribute_list_update(struct ospf *ospf, uintptr_t type,
+void ospf_distribute_list_update(struct ospf *ospf, int type,
u_short instance)
{
struct route_table *rt;
struct ospf_external *ext;
+ void **args = XCALLOC(MTYPE_OSPF_DIST_ARGS, sizeof (void * )*2);
+ args[0] = ospf;
+ args[1] = (void *)((ptrdiff_t) type);
+
/* External info does not exist. */
ext = ospf_external_lookup(type, instance);
if (!ext || !(rt = EXTERNAL_INFO(ext)))
/* Set timer. */
ospf->t_distribute_update = NULL;
thread_add_timer_msec(master, ospf_distribute_list_update_timer,
- (void *)type, ospf->min_ls_interval,
+ (void **)args, ospf->min_ls_interval,
&ospf->t_distribute_update);
}
int type;
int abr_inv = 0;
struct ospf_area *area;
- struct listnode *node;
+ struct listnode *node, *n1;
/* If OSPF instance does not exist, return right now. */
- ospf = ospf_lookup();
- if (ospf == NULL)
+ if (listcount(om->ospf) == 0)
return;
- /* Update distribute-list, and apply filter. */
- for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
- struct list *red_list;
- struct listnode *node;
- struct ospf_redist *red;
-
- red_list = ospf->redist[type];
- if (red_list)
- for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
- if (ROUTEMAP(red)) {
- /* if route-map is not NULL it may be
- * using this access list */
- ospf_distribute_list_update(
- ospf, type, red->instance);
+ /* Iterate all ospf [VRF] instances */
+ 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;
+ struct listnode *node;
+ struct ospf_redist *red;
+
+ red_list = ospf->redist[type];
+ if (red_list)
+ for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
+ if (ROUTEMAP(red)) {
+ /* if route-map is not NULL it may be
+ * using this access list */
+ ospf_distribute_list_update(
+ ospf,
+ type, red->instance);
+ }
}
- }
- /* There is place for route-map for default-information
- * (ZEBRA_ROUTE_MAX),
- * but no distribute list. */
- if (type == ZEBRA_ROUTE_MAX)
- break;
-
- if (DISTRIBUTE_NAME(ospf, type)) {
- /* Keep old access-list for distribute-list. */
- struct access_list *old = DISTRIBUTE_LIST(ospf, type);
-
- /* Update access-list for distribute-list. */
- DISTRIBUTE_LIST(ospf, type) = access_list_lookup(
- AFI_IP, DISTRIBUTE_NAME(ospf, type));
-
- /* No update for this distribute type. */
- if (old == NULL && DISTRIBUTE_LIST(ospf, type) == NULL)
- continue;
-
- /* Schedule distribute-list update timer. */
- if (DISTRIBUTE_LIST(ospf, type) == NULL
- || strcmp(DISTRIBUTE_NAME(ospf, type), access->name)
- == 0)
- ospf_distribute_list_update(ospf, type, 0);
+ /* There is place for route-map for default-information
+ * (ZEBRA_ROUTE_MAX),
+ * but no distribute list. */
+ if (type == ZEBRA_ROUTE_MAX)
+ break;
+
+ if (DISTRIBUTE_NAME(ospf, type)) {
+ /* Keep old access-list for distribute-list. */
+ struct access_list *old = DISTRIBUTE_LIST(ospf,
+ type);
+
+ /* Update access-list for distribute-list. */
+ DISTRIBUTE_LIST(ospf, type) = access_list_lookup(
+ AFI_IP, DISTRIBUTE_NAME(ospf, type));
+
+ /* No update for this distribute type. */
+ if (old == NULL && DISTRIBUTE_LIST(ospf, type) == NULL)
+ continue;
+
+ /* Schedule distribute-list update timer. */
+ if (DISTRIBUTE_LIST(ospf, type) == NULL
+ || strcmp(DISTRIBUTE_NAME(ospf, type), access->name)
+ == 0)
+ ospf_distribute_list_update(ospf, type, 0);
+ }
}
- }
- /* Update Area access-list. */
- for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
- if (EXPORT_NAME(area)) {
- EXPORT_LIST(area) = NULL;
- abr_inv++;
- }
+ /* Update Area access-list. */
+ for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
+ if (EXPORT_NAME(area)) {
+ EXPORT_LIST(area) = NULL;
+ abr_inv++;
+ }
- if (IMPORT_NAME(area)) {
- IMPORT_LIST(area) = NULL;
- abr_inv++;
+ if (IMPORT_NAME(area)) {
+ IMPORT_LIST(area) = NULL;
+ abr_inv++;
+ }
}
- }
- /* Schedule ABR tasks -- this will be changed -- takada. */
- if (IS_OSPF_ABR(ospf) && abr_inv)
- ospf_schedule_abr_task(ospf);
+ /* Schedule ABR tasks -- this will be changed -- takada. */
+ if (IS_OSPF_ABR(ospf) && abr_inv)
+ ospf_schedule_abr_task(ospf);
+ }
}
/* If prefix-list is updated, do some updates. */
void ospf_prefix_list_update(struct prefix_list *plist)
{
- struct ospf *ospf;
+ struct ospf *ospf = NULL;
int type;
int abr_inv = 0;
struct ospf_area *area;
- struct listnode *node;
+ struct listnode *node, *n1;
/* If OSPF instatnce does not exist, return right now. */
- ospf = ospf_lookup();
- if (ospf == NULL)
+ if (listcount(om->ospf) == 0)
return;
- /* Update all route-maps which are used as redistribution filters.
- * They might use prefix-list.
- */
- for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
- struct list *red_list;
- struct listnode *node;
- struct ospf_redist *red;
-
- red_list = ospf->redist[type];
- if (red_list)
- for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
- if (ROUTEMAP(red)) {
- /* if route-map is not NULL it may be
- * using this prefix list */
- ospf_distribute_list_update(
- ospf, type, red->instance);
+ /* Iterate all ospf [VRF] instances */
+ for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) {
+
+ /* Update all route-maps which are used
+ * as redistribution filters.
+ * They might use prefix-list.
+ */
+ for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) {
+ struct list *red_list;
+ struct listnode *node;
+ struct ospf_redist *red;
+
+ red_list = ospf->redist[type];
+ if (red_list) {
+ for (ALL_LIST_ELEMENTS_RO(red_list,
+ node, red)) {
+ if (ROUTEMAP(red)) {
+ /* if route-map is not NULL
+ * it may be using
+ * this prefix list */
+ ospf_distribute_list_update(
+ ospf, type,
+ red->instance);
+ }
}
}
- }
+ }
- /* Update area filter-lists. */
- for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
- /* Update filter-list in. */
- if (PREFIX_NAME_IN(area))
- if (strcmp(PREFIX_NAME_IN(area),
- prefix_list_name(plist))
- == 0) {
- PREFIX_LIST_IN(area) = prefix_list_lookup(
- AFI_IP, PREFIX_NAME_IN(area));
- abr_inv++;
- }
+ /* Update area filter-lists. */
+ for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
+ /* Update filter-list in. */
+ if (PREFIX_NAME_IN(area))
+ if (strcmp(PREFIX_NAME_IN(area),
+ prefix_list_name(plist)) == 0) {
+ PREFIX_LIST_IN(area) =
+ prefix_list_lookup(
+ AFI_IP,
+ PREFIX_NAME_IN(area));
+ abr_inv++;
+ }
- /* Update filter-list out. */
- if (PREFIX_NAME_OUT(area))
- if (strcmp(PREFIX_NAME_OUT(area),
- prefix_list_name(plist))
- == 0) {
- PREFIX_LIST_IN(area) = prefix_list_lookup(
- AFI_IP, PREFIX_NAME_OUT(area));
- abr_inv++;
- }
- }
+ /* Update filter-list out. */
+ if (PREFIX_NAME_OUT(area))
+ if (strcmp(PREFIX_NAME_OUT(area),
+ prefix_list_name(plist)) == 0) {
+ PREFIX_LIST_IN(area) =
+ prefix_list_lookup(
+ AFI_IP,
+ PREFIX_NAME_OUT(area));
+ abr_inv++;
+ }
+ }
- /* Schedule ABR task. */
- if (IS_OSPF_ABR(ospf) && abr_inv)
- ospf_schedule_abr_task(ospf);
+ /* Schedule ABR task. */
+ if (IS_OSPF_ABR(ospf) && abr_inv)
+ ospf_schedule_abr_task(ospf);
+ }
}
static struct ospf_distance *ospf_distance_new(void)
}
}
-u_char ospf_distance_apply(struct prefix_ipv4 *p, struct ospf_route * or)
+u_char ospf_distance_apply(struct ospf *ospf, struct prefix_ipv4 *p,
+ struct ospf_route *or)
{
- struct ospf *ospf;
- ospf = ospf_lookup();
if (ospf == NULL)
return 0;
return 0;
}
+void ospf_zebra_vrf_register(struct ospf *ospf)
+{
+ if (!zclient || zclient->sock < 0 || !ospf)
+ return;
+
+ if (ospf->vrf_id != VRF_DEFAULT && ospf->vrf_id != VRF_UNKNOWN) {
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: Register VRF %s id %u",
+ __PRETTY_FUNCTION__,
+ ospf_vrf_id_to_name(ospf->vrf_id),
+ ospf->vrf_id);
+ zclient_send_reg_requests(zclient, ospf->vrf_id);
+ }
+}
+
+void ospf_zebra_vrf_deregister(struct ospf *ospf)
+{
+ if (!zclient || zclient->sock < 0 || !ospf)
+ return;
+
+ if (ospf->vrf_id != VRF_DEFAULT && ospf->vrf_id != VRF_UNKNOWN) {
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: De-Register VRF %s id %u",
+ __PRETTY_FUNCTION__,
+ ospf_vrf_id_to_name(ospf->vrf_id),
+ ospf->vrf_id);
+ /* Deregister for router-id, interfaces,
+ * redistributed routes. */
+ zclient_send_dereg_requests(zclient, ospf->vrf_id);
+ }
+}
static void ospf_zebra_connected(struct zclient *zclient)
{
/* Send the client registration */
zclient->interface_address_add = ospf_interface_address_add;
zclient->interface_address_delete = ospf_interface_address_delete;
zclient->interface_link_params = ospf_interface_link_params;
+ zclient->interface_vrf_update = ospf_interface_vrf_update;
zclient->redistribute_route_add = ospf_zebra_read_route;
zclient->redistribute_route_del = ospf_zebra_read_route;
};
/* Prototypes */
-extern void ospf_zebra_add(struct prefix_ipv4 *, struct ospf_route *);
-extern void ospf_zebra_delete(struct prefix_ipv4 *, struct ospf_route *);
+extern void ospf_zebra_add(struct ospf *ospf, struct prefix_ipv4 *,
+ struct ospf_route *);
+extern void ospf_zebra_delete(struct ospf *ospf, struct prefix_ipv4 *,
+ struct ospf_route *);
-extern void ospf_zebra_add_discard(struct prefix_ipv4 *);
-extern void ospf_zebra_delete_discard(struct prefix_ipv4 *);
+extern void ospf_zebra_add_discard(struct ospf *ospf, struct prefix_ipv4 *);
+extern void ospf_zebra_delete_discard(struct ospf *ospf, struct prefix_ipv4 *);
extern int ospf_redistribute_check(struct ospf *, struct external_info *,
int *);
extern int ospf_distribute_check_connected(struct ospf *,
struct external_info *);
-extern void ospf_distribute_list_update(struct ospf *, uintptr_t, u_short);
+extern void ospf_distribute_list_update(struct ospf *, int, u_short);
-extern int ospf_is_type_redistributed(int, u_short);
+extern int ospf_is_type_redistributed(struct ospf *, int, u_short);
extern void ospf_distance_reset(struct ospf *);
-extern u_char ospf_distance_apply(struct prefix_ipv4 *, struct ospf_route *);
+extern u_char ospf_distance_apply(struct ospf *ospf, struct prefix_ipv4 *,
+ struct ospf_route *);
extern struct ospf_external *ospf_external_lookup(u_char, u_short);
extern struct ospf_external *ospf_external_add(u_char, u_short);
extern void ospf_external_del(u_char, u_short);
extern int ospf_distance_unset(struct vty *, struct ospf *, const char *,
const char *, const char *);
extern void ospf_zebra_init(struct thread_master *, u_short);
+extern void ospf_zebra_vrf_register(struct ospf *ospf);
+extern void ospf_zebra_vrf_deregister(struct ospf *ospf);
DECLARE_HOOK(ospf_if_update, (struct interface * ifp), (ifp))
DECLARE_HOOK(ospf_if_delete, (struct interface * ifp), (ifp))
else
router_id = router_id_zebra;
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("Router-ID[OLD:%s]: Update to %s",
+ inet_ntoa(ospf->router_id),
+ inet_ntoa(router_id_old));
if (!IPV4_ADDR_SAME(&router_id_old, &router_id)) {
ospf_router_lsa_update(ospf);
/* update ospf_interface's */
- for (ALL_LIST_ELEMENTS_RO(om->iflist, node, ifp))
+ for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), node, ifp))
ospf_if_update(ospf, ifp);
}
}
}
/* Allocate new ospf structure. */
-static struct ospf *ospf_new(u_short instance)
+static struct ospf *ospf_new(u_short instance, const char *name)
{
int i;
+ struct vrf *vrf = NULL;
struct ospf *new = XCALLOC(MTYPE_OSPF_TOP, sizeof(struct ospf));
new->router_id.s_addr = htonl(0);
new->router_id_static.s_addr = htonl(0);
+ if (name) {
+ new->vrf_id = VRF_UNKNOWN;
+ /* Freed in ospf_finish_final */
+ new->name = XSTRDUP(MTYPE_OSPF_TOP, name);
+ vrf = vrf_lookup_by_name(new->name);
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: Create new ospf instance with vrf_name %s vrf_id %d",
+ __PRETTY_FUNCTION__, name, new->vrf_id);
+ if (vrf)
+ ospf_vrf_link(new, vrf);
+ } else {
+ new->vrf_id = VRF_DEFAULT;
+ vrf = vrf_lookup_by_id(VRF_DEFAULT);
+ ospf_vrf_link(new, vrf);
+ }
+ ospf_zebra_vrf_register(new);
+
new->abr_type = OSPF_ABR_DEFAULT;
new->oiflist = list_new();
new->vlinks = list_new();
return new;
}
-struct ospf *ospf_lookup()
-{
- if (listcount(om->ospf) == 0)
- return NULL;
-
- return listgetdata((struct listnode *)listhead(om->ospf));
-}
-
struct ospf *ospf_lookup_instance(u_short instance)
{
struct ospf *ospf;
listnode_delete(om->ospf, ospf);
}
-struct ospf *ospf_get()
+struct ospf *ospf_lookup_by_inst_name(u_short instance, const char *name)
+{
+ struct ospf *ospf = NULL;
+ struct listnode *node, *nnode;
+
+ for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf)) {
+ if ((ospf->instance == instance) &&
+ ((ospf->name == NULL && name == NULL) ||
+ (ospf->name && name && strcmp(ospf->name, name) == 0)))
+ return ospf;
+ }
+ return NULL;
+}
+
+struct ospf *ospf_get(u_short instance, const char *name)
{
struct ospf *ospf;
- ospf = ospf_lookup();
+ /* vrf name provided call inst and name based api
+ * in case of no name pass default ospf instance */
+ if (name)
+ ospf = ospf_lookup_by_inst_name(instance, name);
+ else
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+
if (ospf == NULL) {
- ospf = ospf_new(0);
+ ospf = ospf_new(instance, name);
ospf_add(ospf);
if (ospf->router_id_static.s_addr == 0)
ospf = ospf_lookup_instance(instance);
if (ospf == NULL) {
- ospf = ospf_new(instance);
+ ospf = ospf_new(instance, NULL /* VRF_DEFAULT*/);
ospf_add(ospf);
- if (ospf->router_id_static.s_addr == 0)
+ if (ospf->router_id_static.s_addr == 0) {
+ if (vrf_lookup_by_id(ospf->vrf_id))
+ ospf_router_id_update(ospf);
+ else {
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: ospf VRF (id %d) is not active yet, skip router id update"
+ , __PRETTY_FUNCTION__,
+ ospf->vrf_id);
+ }
ospf_router_id_update(ospf);
+ }
ospf_opaque_type11_lsa_init(ospf);
}
return ospf;
}
+struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id)
+{
+ struct vrf *vrf = NULL;
+
+ vrf = vrf_lookup_by_id(vrf_id);
+ if (!vrf)
+ return NULL;
+ return (vrf->info) ? (struct ospf *)vrf->info : NULL;
+
+}
+
+struct ospf *ospf_lookup_by_name(const char *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))
+ return ospf;
+ return NULL;
+}
+
/* Handle the second half of deferred shutdown. This is called either
* from the deferred-shutdown timer thread, or directly through
* ospf_deferred_shutdown_check.
struct listnode *node, *nnode;
int i;
u_short instance = 0;
+ struct vrf *vrf = NULL;
QOBJ_UNREG(ospf);
list_delete(ospf->vlinks);
/* Remove any ospf interface config params */
- for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) {
+ for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), node, ifp)) {
struct ospf_if_params *params;
params = IF_DEF_PARAMS(ifp);
for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi))
ospf_if_free(oi);
+ /* De-Register VRF */
+ ospf_zebra_vrf_deregister(ospf);
+
/* Clear static neighbors */
for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
if ((nbr_nbma = rn->info)) {
if (ospf->old_table)
ospf_route_table_free(ospf->old_table);
if (ospf->new_table) {
- ospf_route_delete(ospf->new_table);
+ ospf_route_delete(ospf, ospf->new_table);
ospf_route_table_free(ospf->new_table);
}
if (ospf->old_rtrs)
if (ospf->new_rtrs)
ospf_rtrs_free(ospf->new_rtrs);
if (ospf->new_external_route) {
- ospf_route_delete(ospf->new_external_route);
+ ospf_route_delete(ospf, ospf->new_external_route);
ospf_route_table_free(ospf->new_external_route);
}
if (ospf->old_external_route) {
- ospf_route_delete(ospf->old_external_route);
+ ospf_route_delete(ospf, ospf->old_external_route);
ospf_route_table_free(ospf->old_external_route);
}
if (ospf->external_lsas) {
ospf_delete(ospf);
+ if (ospf->name) {
+ vrf = vrf_lookup_by_name(ospf->name);
+ if (vrf)
+ ospf_vrf_unlink(ospf, vrf);
+ XFREE(MTYPE_OSPF_TOP, ospf->name);
+ } else {
+ vrf = vrf_lookup_by_id(VRF_DEFAULT);
+ if (vrf)
+ ospf_vrf_unlink(ospf, vrf);
+ }
+
XFREE(MTYPE_OSPF_TOP, ospf);
if (!CHECK_FLAG(om->options, OSPF_MASTER_SHUTDOWN))
struct external_info *ei;
struct ospf_external *ext;
- if (ospf_is_type_redistributed(ZEBRA_ROUTE_CONNECT, 0))
+ if (ospf_is_type_redistributed(ospf, ZEBRA_ROUTE_CONNECT, 0))
if ((ext = ospf_external_lookup(ZEBRA_ROUTE_CONNECT, 0))
&& EXTERNAL_INFO(ext)) {
for (rn = route_top(EXTERNAL_INFO(ext)); rn;
*
* Otherwise, doesn't do anything different to ospf_if_update for now
*/
-void ospf_interface_area_set(struct interface *ifp)
+void ospf_interface_area_set(struct ospf *ospf, struct interface *ifp)
{
- struct ospf *ospf = ospf_get();
+ if (!ospf)
+ return;
ospf_if_update(ospf, ifp);
/* if_update does a update_redistributed */
return;
}
-void ospf_interface_area_unset(struct interface *ifp)
+void ospf_interface_area_unset(struct ospf *ospf, struct interface *ifp)
{
struct route_node *rn_oi;
- struct ospf *ospf;
- ospf = ospf_lookup();
if (!ospf)
return; /* Ospf not ready yet */
/* Find interfaces that may need to be removed. */
for (rn_oi = route_top(IF_OIFS(ifp)); rn_oi;
rn_oi = route_next(rn_oi)) {
- struct ospf_interface *oi;
+ struct ospf_interface *oi = NULL;
if ((oi = rn_oi->info) == NULL)
continue;
void ospf_if_update(struct ospf *ospf, struct interface *ifp)
{
if (!ospf)
- ospf = ospf_lookup();
+ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
+
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: interface %s ifp->vrf_id %u ospf vrf %s vrf_id %u router_id %s",
+ __PRETTY_FUNCTION__, ifp->name, ifp->vrf_id,
+ ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id,
+ inet_ntoa(ospf->router_id));
/* OSPF must be ready. */
if (!ospf_is_ready(ospf))
om->ospf = list_new();
om->master = master;
}
+
+/* Link OSPF instance to VRF. */
+void ospf_vrf_link(struct ospf *ospf, struct vrf *vrf)
+{
+ ospf->vrf_id = vrf->vrf_id;
+ if (vrf->info != (void *)ospf)
+ vrf->info = (void *)ospf;
+}
+
+/* Unlink OSPF instance from VRF. */
+void ospf_vrf_unlink(struct ospf *ospf, struct vrf *vrf)
+{
+ if (vrf->info == (void *)ospf)
+ vrf->info = NULL;
+ ospf->vrf_id = VRF_UNKNOWN;
+}
+
+/* This is hook function for vrf create called as part of vrf_init */
+static int ospf_vrf_new(struct vrf *vrf)
+{
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: VRF Created: %s(%d)", __PRETTY_FUNCTION__,
+ vrf->name, vrf->vrf_id);
+
+ return 0;
+}
+
+/* This is hook function for vrf delete call as part of vrf_init */
+static int ospf_vrf_delete(struct vrf *vrf)
+{
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: VRF Deletion: %s(%d)", __PRETTY_FUNCTION__,
+ vrf->name, vrf->vrf_id);
+
+ return 0;
+}
+
+/* Enable OSPF VRF instance */
+static int ospf_vrf_enable(struct vrf *vrf)
+{
+ struct ospf *ospf = NULL;
+ vrf_id_t old_vrf_id = VRF_DEFAULT;
+
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: VRF %s id %d enabled",
+ __PRETTY_FUNCTION__, vrf->name, vrf->vrf_id);
+
+ ospf = ospf_lookup_by_name(vrf->name);
+ if (ospf) {
+ old_vrf_id = ospf->vrf_id;
+ /* We have instance configured, link to VRF and make it "up". */
+ ospf_vrf_link(ospf, vrf);
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: ospf linked to vrf %s vrf_id %d (old id %d)",
+ __PRETTY_FUNCTION__, vrf->name, ospf->vrf_id,
+ old_vrf_id);
+
+ if (old_vrf_id != ospf->vrf_id) {
+ ospf->oi_running = 1;
+ ospf_router_id_update(ospf);
+ }
+ }
+
+ return 0;
+}
+
+/* Disable OSPF VRF instance */
+static int ospf_vrf_disable(struct vrf *vrf)
+{
+ struct ospf *ospf = NULL;
+ vrf_id_t old_vrf_id = VRF_UNKNOWN;
+
+ if (vrf->vrf_id == VRF_DEFAULT)
+ return 0;
+
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: VRF %s id %d disabled.",
+ __PRETTY_FUNCTION__, vrf->name, vrf->vrf_id);
+
+ ospf = ospf_lookup_by_name(vrf->name);
+ if (ospf) {
+ old_vrf_id = ospf->vrf_id;
+
+ /* We have instance configured, unlink
+ * from VRF and make it "down".
+ */
+ ospf_vrf_unlink(ospf, vrf);
+ ospf->oi_running = 0;
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug("%s: ospf old_vrf_id %d unlinked",
+ __PRETTY_FUNCTION__, old_vrf_id);
+ }
+
+ /* Note: This is a callback, the VRF will be deleted by the caller. */
+ return 0;
+}
+
+void ospf_vrf_init(void)
+{
+ vrf_init(ospf_vrf_new, ospf_vrf_enable,
+ ospf_vrf_disable, ospf_vrf_delete);
+}
+
+void ospf_vrf_terminate(void)
+{
+ vrf_terminate();
+}
+
+const char *ospf_vrf_id_to_name(vrf_id_t vrf_id)
+{
+ struct vrf *vrf = vrf_lookup_by_id(vrf_id);
+
+ return vrf ? vrf->name : "NIL";
+}
#include "filter.h"
#include "log.h"
+#include "vrf.h"
#include "ospf_memory.h"
#include "ospf_dump_api.h"
struct in_addr router_id; /* Configured automatically. */
struct in_addr router_id_static; /* Configured manually. */
+ vrf_id_t vrf_id; /* VRF Id */
+ char *name; /* VRF name */
+
/* ABR/ASBR internal flags. */
u_char flags;
#define OSPF_FLAG_ABR 0x0001
/* Prototypes. */
extern const char *ospf_redist_string(u_int route_type);
-extern struct ospf *ospf_lookup(void);
extern struct ospf *ospf_lookup_instance(u_short);
-extern struct ospf *ospf_get(void);
+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,
extern void ospf_area_add_if(struct ospf_area *, struct ospf_interface *);
extern void ospf_area_del_if(struct ospf_area *, struct ospf_interface *);
-extern void ospf_interface_area_set(struct interface *);
-extern void ospf_interface_area_unset(struct interface *);
+extern void ospf_interface_area_set(struct ospf *, struct interface *);
+extern void ospf_interface_area_unset(struct ospf *, struct interface *);
extern void ospf_route_map_init(void);
extern void ospf_master_init(struct thread_master *master);
-
+extern void ospf_vrf_init(void);
+extern void ospf_vrf_terminate(void);
+extern void ospf_vrf_link(struct ospf *ospf, struct vrf *vrf);
+extern void ospf_vrf_unlink(struct ospf *ospf, struct vrf *vrf);
+const char *ospf_vrf_id_to_name(vrf_id_t vrf_id);
#endif /* _ZEBRA_OSPFD_H */
return CMD_SUCCESS;
}
-DEFUNSH(VTYSH_OSPFD, router_ospf, router_ospf_cmd, "router ospf [(1-65535)]",
+DEFUNSH(VTYSH_OSPFD, router_ospf, router_ospf_cmd,
+ "router ospf [(1-65535)] [vrf NAME]",
"Enable a routing process\n"
"Start OSPF configuration\n"
- "Instance ID\n")
+ "Instance ID\n"
+ VRF_CMD_HELP_STR)
{
vty->node = OSPF_NODE;
return CMD_SUCCESS;