ospf6d: Add logic to change the status of router to ASBR

Signed-off-by: Yash Ranjan <ranjany@vmware.com>
This commit is contained in:
Yash Ranjan 2021-02-09 22:44:44 -08:00
parent b19502d3b0
commit b8212e0310
5 changed files with 41 additions and 11 deletions

View file

@ -37,6 +37,7 @@
#include "ospf6_route.h"
#include "ospf6_zebra.h"
#include "ospf6_message.h"
#include "ospf6_spf.h"
#include "ospf6_top.h"
#include "ospf6_area.h"
@ -1051,6 +1052,7 @@ static struct ospf6_redist *ospf6_redist_add(struct ospf6 *ospf6, int type,
ROUTEMAP(red) = NULL;
listnode_add(ospf6->redist[type], red);
ospf6->redistribute++;
return red;
}
@ -1064,6 +1066,7 @@ static void ospf6_redist_del(struct ospf6 *ospf6, struct ospf6_redist *red,
list_delete(&ospf6->redist[type]);
}
XFREE(MTYPE_OSPF6_REDISTRIBUTE, red);
ospf6->redistribute--;
}
}
@ -1131,6 +1134,35 @@ void ospf6_asbr_remove_externals_from_area(struct ospf6_area *oa)
}
}
/* Update ASBR status. */
static void ospf6_asbr_status_update(struct ospf6 *ospf6, uint8_t status)
{
struct listnode *lnode, *lnnode;
struct ospf6_area *oa;
zlog_info("ASBR[%s:Status:%d]: Update", ospf6->name, status);
if (status) {
if (IS_OSPF6_ASBR(ospf6)) {
zlog_info("ASBR[%s:Status:%d]: Already ASBR",
ospf6->name, status);
return;
}
SET_FLAG(ospf6->flag, OSPF6_FLAG_ASBR);
} else {
if (!IS_OSPF6_ASBR(ospf6)) {
zlog_info("ASBR[%s:Status:%d]: Already non ASBR",
ospf6->name, status);
return;
}
UNSET_FLAG(ospf6->flag, OSPF6_FLAG_ASBR);
}
ospf6_spf_schedule(ospf6, OSPF6_SPF_FLAGS_ASBR_STATUS_CHANGE);
for (ALL_LIST_ELEMENTS(ospf6->area_list, lnode, lnnode, oa))
OSPF6_ROUTER_LSA_SCHEDULE(oa);
}
void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
struct prefix *prefix,
unsigned int nexthop_num,
@ -1145,8 +1177,6 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
struct prefix prefix_id;
struct route_node *node;
char ibuf[16];
struct listnode *lnode, *lnnode;
struct ospf6_area *oa;
struct ospf6_redist *red;
red = ospf6_redist_lookup(ospf6, type, 0);
@ -1236,6 +1266,7 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
match->path.origin.id = htonl(info->id);
ospf6_as_external_lsa_originate(match, ospf6);
ospf6_asbr_status_update(ospf6, ospf6->redistribute);
return;
}
@ -1289,10 +1320,7 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
route->path.origin.id = htonl(info->id);
ospf6_as_external_lsa_originate(route, ospf6);
/* Router-Bit (ASBR Flag) may have to be updated */
for (ALL_LIST_ELEMENTS(ospf6->area_list, lnode, lnnode, oa))
OSPF6_ROUTER_LSA_SCHEDULE(oa);
ospf6_asbr_status_update(ospf6, ospf6->redistribute);
}
void ospf6_asbr_redistribute_remove(int type, ifindex_t ifindex,
@ -1304,8 +1332,6 @@ void ospf6_asbr_redistribute_remove(int type, ifindex_t ifindex,
struct ospf6_lsa *lsa;
struct prefix prefix_id;
char ibuf[16];
struct listnode *lnode, *lnnode;
struct ospf6_area *oa;
match = ospf6_route_lookup(prefix, ospf6->external_table);
if (match == NULL) {
@ -1346,9 +1372,7 @@ void ospf6_asbr_redistribute_remove(int type, ifindex_t ifindex,
ospf6_route_remove(match, ospf6->external_table);
XFREE(MTYPE_OSPF6_EXTERNAL_INFO, info);
/* Router-Bit (ASBR Flag) may have to be updated */
for (ALL_LIST_ELEMENTS(ospf6->area_list, lnode, lnnode, oa))
OSPF6_ROUTER_LSA_SCHEDULE(oa);
ospf6_asbr_status_update(ospf6, ospf6->redistribute);
}
DEFUN (ospf6_redistribute,

View file

@ -90,6 +90,7 @@ struct ospf6_vertex {
#define OSPF6_SPF_FLAGS_ROUTER_LSA_ORIGINATED (1 << 6)
#define OSPF6_SPF_FLAGS_NETWORK_LSA_ORIGINATED (1 << 7)
#define OSPF6_SPF_FLAGS_CONFIG_CHANGE (1 << 8)
#define OSPF6_SPF_FLAGS_ASBR_STATUS_CHANGE (1 << 9)
static inline void ospf6_set_spf_reason(struct ospf6 *ospf, unsigned int reason)
{

View file

@ -248,6 +248,7 @@ static struct ospf6 *ospf6_create(const char *name)
o->spf_hold_multiplier = 1;
o->default_originate = DEFAULT_ORIGINATE_NONE;
o->redistribute = 0;
/* LSA timers value init */
o->lsa_minarrival = OSPF_MIN_LS_ARRIVAL;

View file

@ -96,6 +96,8 @@ struct ospf6 {
uint8_t flag;
int redistribute; /* Num of redistributed protocols. */
/* Configuration bitmask, refer to enum above */
uint8_t config_flags;
int default_originate; /* Default information originate. */
@ -150,6 +152,7 @@ DECLARE_QOBJ_TYPE(ospf6);
#define OSPF6_DISABLED 0x01
#define OSPF6_STUB_ROUTER 0x02
#define OSPF6_FLAG_ASBR 0x04
/* global pointer for OSPF top data structure */
extern struct ospf6 *ospf6;

View file

@ -95,6 +95,7 @@ extern struct thread_master *master;
return CMD_SUCCESS; \
}
#define IS_OSPF6_ASBR(O) ((O)->flag & OSPF6_FLAG_ASBR)
extern struct zebra_privs_t ospf6d_privs;
/* Function Prototypes */