Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ospfd/ospf_apiserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1940,8 +1940,7 @@ struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa)
if (!apiserv) {
zlog_warn("%s: LSA[%s]: No apiserver?", __func__,
dump_lsa_key(lsa));
lsa->data->ls_age =
htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE); /* Flush it anyway. */
goto out;
}

Expand Down
12 changes: 6 additions & 6 deletions ospfd/ospf_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
"EXT (%s): Segment Routing functionality is Disabled",
__func__);
/* Flush it anyway. */
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);
}

/* Lookup this lsa corresponding Extended parameters */
Expand All @@ -1427,7 +1427,7 @@ static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
"EXT (%s): Invalid parameter LSA ID", __func__);
/* Flush it anyway. */
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);
}

/* Check if Interface was not disable in the interval */
Expand All @@ -1436,7 +1436,7 @@ static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
"EXT (%s): Interface was Disabled: Flush it!",
__func__);
/* Flush it anyway. */
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);
}

/* If the lsa's age reached to MaxAge, start flushing procedure. */
Expand Down Expand Up @@ -1504,7 +1504,7 @@ static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
zlog_info("EXT (%s): Segment Routing functionality is Disabled",
__func__);
/* Flush it anyway. */
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);
}

/* Lookup this LSA corresponding Extended parameters */
Expand All @@ -1513,15 +1513,15 @@ static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
"EXT (%s): Invalid parameter LSA ID", __func__);
/* Flush it anyway. */
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);
}

/* Check if Interface was not disable in the interval */
if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
"EXT (%s): Interface was Disabled: Flush it!",
__func__);
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);
}

/* If the lsa's age reached to MaxAge, start flushing procedure */
Expand Down
20 changes: 9 additions & 11 deletions ospfd/ospf_flood.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ void ospf_refresh_dna_type5_and_type7_lsas(struct ospf *ospf)
struct ospf_lsa *lsa = NULL;

LSDB_LOOP (EXTERNAL_LSDB(ospf), rn, lsa)
if (IS_LSA_SELF(lsa) &&
CHECK_FLAG(lsa->data->ls_age, DO_NOT_AGE))
if (IS_LSA_SELF(lsa) && IS_LSA_AGE_DNA(lsa))
ospf_lsa_refresh(ospf, lsa);

LSDB_LOOP (NSSA_LSDB(ospf), rn, lsa)
if (IS_LSA_SELF(lsa) &&
CHECK_FLAG(lsa->data->ls_age, DO_NOT_AGE))
if (IS_LSA_SELF(lsa) && IS_LSA_AGE_DNA(lsa))
ospf_lsa_refresh(ospf, lsa);
}

Expand Down Expand Up @@ -404,9 +402,9 @@ int ospf_flood(struct ospf *ospf, struct ospf_neighbor *nbr,
if (current != NULL) /* -- endo. */
{
if (IS_LSA_SELF(current)
&& (ntohs(current->data->ls_age) == 0
&& ntohl(current->data->ls_seqnum)
== OSPF_INITIAL_SEQUENCE_NUMBER)) {
&& LS_AGE_RAW(current) == OSPF_LSA_INITIAL_AGE
&& ntohl(current->data->ls_seqnum)
== OSPF_INITIAL_SEQUENCE_NUMBER) {
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"%s:LSA[Flooding]: Got a self-originated LSA, while local one is initial instance.",
Expand Down Expand Up @@ -617,7 +615,7 @@ int ospf_flood_through_interface(struct ospf_interface *oi,
* self lsas.
*/
if (oi->area->fr_info.enabled)
SET_FLAG(lsa->data->ls_age, DO_NOT_AGE);
SET_FLAG(lsa->data->ls_age, htons(DO_NOT_AGE));
}

/* Remember if new LSA is added to a retransmit list. */
Expand Down Expand Up @@ -1345,7 +1343,7 @@ void ospf_lsa_flush_area(struct ospf_lsa *lsa, struct ospf_area *area)
/* Reset the lsa origination time such that it gives
more time for the ACK to be received and avoid
retransmissions */
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: MaxAge set to LSA[%s]", __func__,
dump_lsa_key(lsa));
Expand All @@ -1370,7 +1368,7 @@ void ospf_lsa_flush_as(struct ospf *ospf, struct ospf_lsa *lsa)
/* Reset the lsa origination time such that it gives
more time for the ACK to be received and avoid
retransmissions */
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: MaxAge set to LSA[%s]", __func__,
dump_lsa_key(lsa));
Expand All @@ -1382,7 +1380,7 @@ void ospf_lsa_flush_as(struct ospf *ospf, struct ospf_lsa *lsa)

void ospf_lsa_flush(struct ospf *ospf, struct ospf_lsa *lsa)
{
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);

switch (lsa->data->type) {
case OSPF_ROUTER_LSA:
Expand Down
4 changes: 2 additions & 2 deletions ospfd/ospf_gr_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,11 @@ int ospf_process_grace_lsa(struct ospf *ospf, struct ospf_lsa *lsa,
}

/*LSA age must be less than the grace period */
if (ntohs(lsa->data->ls_age) >= grace_interval) {
if (LS_AGE_RAW(lsa) >= grace_interval) {
if (IS_DEBUG_OSPF_GR)
zlog_debug(
"%s, Grace LSA age(%d) is more than the grace interval(%d)",
__func__, lsa->data->ls_age, grace_interval);
__func__, LS_AGE_RAW(lsa), grace_interval);
restarter->gr_helper_info.rejected_reason =
OSPF_HELPER_LSA_AGE_MORE;
return OSPF_GR_NOT_HELPER;
Expand Down
14 changes: 6 additions & 8 deletions ospfd/ospf_lsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ uint32_t get_metric(uint8_t *metric)
*/
bool ospf_check_dna_lsa(const struct ospf_lsa *lsa)
{
return ((IS_LSA_SELF(lsa) && CHECK_FLAG(lsa->data->ls_age, DO_NOT_AGE))
? true
: false);
return ((IS_LSA_SELF(lsa) && IS_LSA_AGE_DNA(lsa)) ? true : false);
}

struct timeval msec2tv(int a)
Expand Down Expand Up @@ -145,11 +143,11 @@ int get_age(struct ospf_lsa *lsa)
*/

/* If LSA is marked as donotage */
if (CHECK_FLAG(lsa->data->ls_age, DO_NOT_AGE) && !IS_LSA_SELF(lsa))
return ntohs(lsa->data->ls_age);
if (IS_LSA_AGE_DNA(lsa) && !IS_LSA_SELF(lsa))
return LS_AGE_RAW(lsa);

monotime_since(&lsa->tv_recv, &rel);
return ntohs(lsa->data->ls_age) + rel.tv_sec;
return LS_AGE_RAW(lsa) + rel.tv_sec;
}


Expand Down Expand Up @@ -3043,7 +3041,7 @@ struct ospf_lsa *ospf_lsa_install(struct ospf *ospf, struct ospf_interface *oi,

if (!IS_LSA_MAXAGE(lsa))
lsa->flags |= OSPF_LSA_PREMATURE_AGE;
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);

if (IS_DEBUG_OSPF(lsa, LSA_REFRESH)) {
zlog_debug(
Expand Down Expand Up @@ -3701,7 +3699,7 @@ int ospf_lsa_flush_schedule(struct ospf *ospf, struct ospf_lsa *lsa)
lsa->data->type, &lsa->data->id);

/* Force given lsa's age to MaxAge. */
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);

switch (lsa->data->type) {
/* Opaque wants to be notified of flushes */
Expand Down
9 changes: 6 additions & 3 deletions ospfd/ospf_lsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,13 @@ enum lsid_status { LSID_AVAILABLE = 0, LSID_CHANGE, LSID_NOT_AVAILABLE };
#define GET_METRIC(x) get_metric(x)
#define IS_EXTERNAL_METRIC(x) ((x) & 0x80)

#define GET_AGE(x) (ntohs ((x)->data->ls_age) + time (NULL) - (x)->tv_recv)
#define LS_AGE(x) (OSPF_LSA_MAXAGE < get_age(x) ? OSPF_LSA_MAXAGE : get_age(x))
#define IS_LSA_SELF(L) (CHECK_FLAG ((L)->flags, OSPF_LSA_SELF))
#define IS_LSA_MAXAGE(L) (LS_AGE ((L)) == OSPF_LSA_MAXAGE)
#define LS_AGE_RAW(L) (ntohs((L)->data->ls_age) & ~DO_NOT_AGE)
#define LS_AGE_SET(L, age) ((L)->data->ls_age = \
IS_LSA_AGE_DNA((L)) | htons(age))
#define IS_LSA_SELF(L) (CHECK_FLAG((L)->flags, OSPF_LSA_SELF))
#define IS_LSA_MAXAGE(L) (LS_AGE((L)) == OSPF_LSA_MAXAGE)
#define IS_LSA_AGE_DNA(L) (CHECK_FLAG((L)->data->ls_age, htons(DO_NOT_AGE)))
#define IS_LSA_MAX_SEQ(L) \
((L)->data->ls_seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER))

Expand Down
6 changes: 3 additions & 3 deletions ospfd/ospf_opaque.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ void ospf_opaque_type9_lsa_if_cleanup(struct ospf_interface *oi)
GET_OPAQUE_ID(ntohl(
lsa->data->id.s_addr)));
ospf_lsdb_delete(lsdb, lsa);
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);

/*
* Invoke the delete hook directly since it bypasses the normal MAXAGE
Expand Down Expand Up @@ -1735,7 +1735,7 @@ struct ospf_lsa *ospf_opaque_lsa_refresh(struct ospf_lsa *lsa)
zlog_debug("LSA[Type%d:%pI4]: Flush stray Opaque-LSA",
lsa->data->type, &lsa->data->id);

lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);
ospf_lsa_flush(ospf, lsa);
} else
new = (*functab->lsa_refresher)(lsa);
Expand Down Expand Up @@ -2224,7 +2224,7 @@ void ospf_opaque_self_originated_lsa_received(struct ospf_neighbor *nbr,
* registered when opaque LSAs are originated (which is not the case
* for stale LSAs).
*/
lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);
ospf_lsa_install(
top, (lsa->data->type == OSPF_OPAQUE_LINK_LSA) ? nbr->oi : NULL,
lsa);
Expand Down
74 changes: 70 additions & 4 deletions ospfd/ospf_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1596,8 +1596,10 @@ static struct list *ospf_ls_upd_list_lsa(struct ospf_neighbor *nbr,
* What if the received LSA's age is greater than MaxAge?
* Treat it as a MaxAge case -- endo.
*/
if (ntohs(lsah->ls_age) > OSPF_LSA_MAXAGE)
lsah->ls_age = htons(OSPF_LSA_MAXAGE);
uint16_t ls_age = ntohs(lsah->ls_age);

if ((ls_age & ~DO_NOT_AGE) > OSPF_LSA_MAXAGE)
lsah->ls_age = htons(OSPF_LSA_MAXAGE | (ls_age & DO_NOT_AGE));

if (CHECK_FLAG(nbr->options, OSPF_OPTION_O)) {
#ifdef STRICT_OBIT_USAGE_CHECK
Expand Down Expand Up @@ -1935,6 +1937,61 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
if (Flag)
continue;
}
/* Make sure that this is not a stale LSA (after a reboot) that originated from this
* router. If that is the case, refresh the local LSA.
* RFC 2328 Section 13.4:
* https://datatracker.ietf.org/doc/html/rfc2328#page-151
*
* Opaque LSAs are handled above and via ospf_process_self_originated_lsa().
*/
if (IPV4_ADDR_SAME(&lsa->data->adv_router, &oi->ospf->router_id) &&
!IS_OPAQUE_LSA(lsa->data->type)) {
if (current == NULL) {
/* RFC 2328 Section 13.4:
* It may be the case the router no longer wishes to originate the
* received LSA. ... Instead of updating the LSA, the LSA should be
* flushed from the routing domain by incrementing the received
* LSA's LS age to MaxAge and reflooding.
*/
struct ospf_lsa *ls_req;

if (IS_DEBUG_OSPF(lsa, LSA))
zlog_debug("%s: Link State Update[%s]: router-id is local, but no current LSA - setting to MaxAge",
__func__, dump_lsa_key(lsa));

/* Immediately Ack to stop retransmitting the LSA */
ospf_ls_ack_send_direct(nbr, lsa);
/* Remove from request list, we are overriding */
ls_req = ospf_ls_request_lookup(nbr, lsa);
if (ls_req != NULL) {
ospf_ls_request_delete(nbr, ls_req);
ospf_check_nbr_loading(nbr);
}

/* Set LSA age to MaxAge to flush this stale instance. */
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE);

} else if (ospf_lsa_more_recent(lsa, current) > 0) {
/* RFC 2328 Section 13.4:
* If the received self-originated LSA is newer than the
* last instance that the router actually originated, the router
* must take special action. ... the router must then advance the LSA's LS
* sequence number one past the received LS sequence number, and
* originate a new instance of the LSA.
*/
if (IS_DEBUG_OSPF(lsa, LSA))
zlog_debug("%s: Link State Update[%s]: router-id is local, but has higher seq num",
__func__, dump_lsa_key(lsa));
current->data->ls_seqnum = lsa->data->ls_seqnum;
ospf_lsa_refresh(oi->ospf, current);
/* Discarding without ACK may cause neighbor to retransmit the stale LSA
* until the refreshed LSA arrives, make sure that doesn't happen.
*/
ospf_ls_ack_send_direct(nbr, lsa);
DISCARD_LSA(lsa, 10);
continue;
}
}

/* (5) Find the instance of this LSA that is currently contained
in the router's link state database. If there is no
Expand Down Expand Up @@ -3186,6 +3243,8 @@ static int ospf_make_db_desc(struct ospf_interface *oi,

/* Set LS age. */
ls_age = LS_AGE(lsa);
if (IS_LSA_AGE_DNA(lsa))
SET_FLAG(ls_age, DO_NOT_AGE);
lsah->ls_age = htons(ls_age);
}

Expand Down Expand Up @@ -3268,9 +3327,16 @@ static int ls_age_increment(struct ospf_lsa *lsa, int delay)
{
int age;

age = IS_LSA_MAXAGE(lsa) ? OSPF_LSA_MAXAGE : LS_AGE(lsa) + delay;
age = LS_AGE(lsa) + delay;

if (age > OSPF_LSA_MAXAGE)
age = OSPF_LSA_MAXAGE;

/* Preserve DNA bit on age increment */
if (IS_LSA_AGE_DNA(lsa))
SET_FLAG(age, DO_NOT_AGE);

return (age > OSPF_LSA_MAXAGE ? OSPF_LSA_MAXAGE : age);
return age;
}

static int ospf_make_ls_upd(struct ospf_interface *oi, struct list *update,
Expand Down
3 changes: 1 addition & 2 deletions ospfd/ospf_ri.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,7 @@ static struct ospf_lsa *ospf_router_info_lsa_refresh(struct ospf_lsa *lsa)
*/
zlog_info("RI (%s): ROUTER INFORMATION is disabled now.",
__func__);
lsa->data->ls_age =
htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE); /* Flush it anyway. */
}

/* Verify that the Router Information ID is supported */
Expand Down
7 changes: 2 additions & 5 deletions ospfd/ospf_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,11 +994,8 @@ void ospf_prune_unreachable_routers(struct route_table *rtrs)
* which generated this lsa is no longer
* reachabele.
*/
(CHECK_FLAG(or->u.std.origin->ls_age,
DO_NOT_AGE))
? UNSET_FLAG(or->u.std.origin->ls_age,
DO_NOT_AGE)
: 0;
if (CHECK_FLAG(or->u.std.origin->ls_age, htons(DO_NOT_AGE)))
UNSET_FLAG(or->u.std.origin->ls_age, htons(DO_NOT_AGE));

listnode_delete(paths, or);
ospf_route_free(or);
Expand Down
9 changes: 3 additions & 6 deletions ospfd/ospf_te.c
Original file line number Diff line number Diff line change
Expand Up @@ -1453,16 +1453,14 @@ static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa)
* It seems a slip among routers in the routing domain.
*/
ote_debug("MPLS-TE (%s): MPLS-TE is disabled now", __func__);
lsa->data->ls_age =
htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE); /* Flush it anyway. */
}

/* At first, resolve lsa/lp relationship. */
if ((lp = lookup_linkparams_by_instance(lsa)) == NULL) {
flog_warn(EC_OSPF_TE_UNEXPECTED,
"MPLS-TE (%s): Invalid parameter?", __func__);
lsa->data->ls_age =
htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE); /* Flush it anyway. */
ospf_opaque_lsa_flush_schedule(lsa);
return NULL;
}
Expand All @@ -1471,8 +1469,7 @@ static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa)
if (!CHECK_FLAG(lp->flags, LPFLG_LSA_ACTIVE)) {
flog_warn(EC_OSPF_TE_UNEXPECTED,
"MPLS-TE (%s): lp was disabled: Flush it!", __func__);
lsa->data->ls_age =
htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */
LS_AGE_SET(lsa, OSPF_LSA_MAXAGE); /* Flush it anyway. */
}

/* If the lsa's age reached to MaxAge, start flushing procedure. */
Expand Down
Loading
Loading