From c2b478d7a4fae2eb2f7f895b80d36af9c8e73ab0 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Thu, 30 Mar 2006 14:16:11 +0000 Subject: [ospfd] Fix incorrect byte-order conversion of OSPF_MAX_SEQUENCE_NUMBER 2006-03-23 Steve Lawson * ospf_lsa.c: (ospf_lsa_install) Fix incorrect byte-order conversion of OSPF_MAX_SEQUENCE_NUMBER --- ospfd/ospf_lsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 8ef4da66..12959f04 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -2786,7 +2786,7 @@ ospf_lsa_install (struct ospf *ospf, struct ospf_interface *oi, can be originated. " */ - if (ntohl(lsa->data->ls_seqnum) - 1 == htonl(OSPF_MAX_SEQUENCE_NUMBER)) + if (ntohl(lsa->data->ls_seqnum) - 1 == OSPF_MAX_SEQUENCE_NUMBER) { if (ospf_lsa_is_self_originated(ospf, lsa)) { -- cgit v1.2.3 From 075c2011bbec618934637ead3fd6dec65cd30a45 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Thu, 30 Mar 2006 14:34:31 +0000 Subject: [ospfd] Fix failure of Fletcher checksum with certain compilers 2006-03-27 Paul Jakma * ospf_lsa.c: (ospf_lsa_checksum) Add an explicit cast to avoid the ambiguities of ANSI and C99 C with respect to type conversion. Detailed problem report and test case with example data supplied by Dmitry Ivanov . --- ospfd/ospf_lsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 12959f04..faae4376 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -202,7 +202,7 @@ ospf_lsa_checksum (struct lsa_header *lsa) c1 %= 255; } - x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255; + x = (((int)length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255; if (x <= 0) x += 255; y = 510 - c0 - x; -- cgit v1.2.3 From 4021b60aad57f71f5d3d5c105127f93bd77bf800 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Fri, 12 May 2006 22:55:41 +0000 Subject: [ospfd] Squash another ospf_lookup call 2006-05-11 Paul Jakma * ospf_lsa.c: (ospf_default_originate_timer) Let the thread take (struct ospf *) as thread argument, rather than (struct ospf *)->default_originate, thus avoiding having to call ospf_lookup. * ospf_zebra.c: (ospf_redistribute_default_set) change setup of ospf_default_originate_timer thread to match. * ospfd.c: (ospf_router_id_update) ditto. --- ospfd/ospf_lsa.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index faae4376..9a887459 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -2243,22 +2243,18 @@ ospf_default_external_info (struct ospf *ospf) int ospf_default_originate_timer (struct thread *thread) { - int *origin; struct prefix_ipv4 p; struct in_addr nexthop; struct external_info *ei; struct ospf *ospf; - ospf = ospf_lookup (); - - /* Get originate flags. */ - origin = THREAD_ARG (thread); + ospf = THREAD_ARG (thread); p.family = AF_INET; p.prefix.s_addr = 0; p.prefixlen = 0; - if (*origin == DEFAULT_ORIGINATE_ALWAYS) + if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) { /* If there is no default route via redistribute, then originate AS-external-LSA with nexthop 0 (self). */ -- cgit v1.2.3 From 70461d793444002cc2ce99e4e62df3c367d9dd50 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Fri, 12 May 2006 22:57:57 +0000 Subject: [ospfd] CID #29, fix missing NULL check by removing unused code. 2006-05-12 Paul Jakma * ospf_lsa.c: (ospf_lsa_action) Get rid of the ospf_lookup call, which is not checked for NULL return, by stripping out functionality which is never used, hence fixing Coverity CID #29. (struct lsa_action) remove unused member. --- ospfd/ospf_lsa.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 9a887459..9ef5a6ae 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -3615,18 +3615,13 @@ ospf_lsa_unique_id (struct ospf *ospf, } -#define LSA_ACTION_ORIGN_RTR 1 -#define LSA_ACTION_ORIGN_NET 2 -#define LSA_ACTION_FLOOD_AREA 3 -#define LSA_ACTION_FLOOD_AS 4 -#define LSA_ACTION_FLUSH_AREA 5 -#define LSA_ACTION_FLUSH_AS 6 +#define LSA_ACTION_FLOOD_AREA 1 +#define LSA_ACTION_FLUSH_AREA 2 struct lsa_action { u_char action; struct ospf_area *area; - struct ospf_interface *oi; struct ospf_lsa *lsa; }; @@ -3634,9 +3629,6 @@ static int ospf_lsa_action (struct thread *t) { struct lsa_action *data; - struct ospf *ospf; - - ospf = ospf_lookup (); data = THREAD_ARG (t); @@ -3646,24 +3638,12 @@ ospf_lsa_action (struct thread *t) switch (data->action) { - case LSA_ACTION_ORIGN_RTR: - ospf_router_lsa_refresh (data->area->router_lsa_self); - break; - case LSA_ACTION_ORIGN_NET: - ospf_network_lsa_originate (data->oi); - break; case LSA_ACTION_FLOOD_AREA: ospf_flood_through_area (data->area, NULL, data->lsa); break; - case LSA_ACTION_FLOOD_AS: - ospf_flood_through_as (ospf, NULL, data->lsa); - break; case LSA_ACTION_FLUSH_AREA: ospf_lsa_flush_area (data->lsa, data->area); break; - case LSA_ACTION_FLUSH_AS: - ospf_lsa_flush_as (ospf, data->lsa); - break; } ospf_lsa_unlock (data->lsa); -- cgit v1.2.3 From e54e6e57205df19efe3023526b7eb53a9d06fa93 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Fri, 12 May 2006 23:11:14 +0000 Subject: [ospfd] CID #13, debug for NULL type7 LSA should not print out data from it 2006-05-12 Paul Jakma * ospf_lsa.c: (ospf_translated_nssa_refresh) Add non-assert sanity check, in case DEBUG isn't defined. Debug message when no type7 exists should print the ID from the type5, not the type7, fixes CID #13. --- ospfd/ospf_lsa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 9ef5a6ae..d2f593e5 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -2002,6 +2002,8 @@ ospf_translated_nssa_refresh (struct ospf *ospf, struct ospf_lsa *type7, /* Sanity checks. */ assert (type7 || type5); + if (!type7 || !type5) + return NULL; if (type7) assert (type7->data); if (type5) @@ -2055,7 +2057,7 @@ ospf_translated_nssa_refresh (struct ospf *ospf, struct ospf_lsa *type7, if (IS_DEBUG_OSPF_NSSA) zlog_debug ("ospf_translated_nssa_refresh(): no Type-7 found for " "Type-5 LSA Id %s", - inet_ntoa (type7->data->id)); + inet_ntoa (type5->data->id)); return NULL; } -- cgit v1.2.3 From ae128056e9bb1b52e3b6c3263f5f7fd83efa5c3a Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Fri, 12 May 2006 23:15:30 +0000 Subject: [ospfd] Fix small error in CID #13 commit 2006-05-13 Paul Jakma * ospf_lsa.c: (ospf_translated_nssa_refresh) fix the sanity check to match the assert, small error in CID #13 fix. --- ospfd/ospf_lsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index d2f593e5..7c3be3d6 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -2002,7 +2002,7 @@ ospf_translated_nssa_refresh (struct ospf *ospf, struct ospf_lsa *type7, /* Sanity checks. */ assert (type7 || type5); - if (!type7 || !type5) + if (!(type7 || type5)) return NULL; if (type7) assert (type7->data); -- cgit v1.2.3 From ac904dec03ce6b1bbd1bab1718085a366d485bd8 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Thu, 15 Jun 2006 12:04:57 +0000 Subject: [ospfd] lsdb_delete/discard_from_db should be more robust to bad args 2006-05-31 Paul Jakma * ospf_lsdb.c: (ospf_lsdb_delete) robustify against NULL arguments, print warning. * ospf_lsa.c: (ospf_discard_from_db) ditto. (ospf_maxage_lsa_remover) Check lsa->lsdb for validity, possible mitigation (but not solution) for bug #269. --- ospfd/ospf_lsa.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 7c3be3d6..a0afbad3 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -2679,6 +2679,17 @@ ospf_discard_from_db (struct ospf *ospf, { struct ospf_lsa *old; + if (!lsdb) + { + zlog_warn ("%s: Called with NULL lsdb!", __func__); + if (!lsa) + zlog_warn ("%s: and NULL LSA!", __func__); + else + zlog_warn ("LSA[Type%d:%s]: not associated with LSDB!", + lsa->data->type, inet_ntoa (lsa->data->id)); + return; + } + old = ospf_lsdb_lookup (lsdb, lsa); if (!old) @@ -3014,8 +3025,14 @@ ospf_maxage_lsa_remover (struct thread *thread) } /* Remove from lsdb. */ - ospf_discard_from_db (ospf, lsa->lsdb, lsa); - ospf_lsdb_delete (lsa->lsdb, lsa); + if (lsa->lsdb) + { + ospf_discard_from_db (ospf, lsa->lsdb, lsa); + ospf_lsdb_delete (lsa->lsdb, lsa); + } + else + zlog_warn ("%s: LSA[Type%d:%s]: No associated LSDB!", __func__, + lsa->data->type, inet_ntoa (lsa->data->id)); } /* A MaxAge LSA must be removed immediately from the router's link -- cgit v1.2.3 From 9560fa8ac994966a8da0ba23c46c0299164b7112 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Mon, 26 Jun 2006 12:50:06 +0000 Subject: [ospfd] NSSA translate-enabled ABR should declare itself as ASBR 2006-06-26 Paul Jakma * ospf_abr.c: (general) NSSA translate-candidate ABRs need to be ASBRs, or other routers may rightfully refuse to install translated type-5s LSAs. reported by dendroot@gmail.com. (ospf_abr_nssa_check_status) Detect change in translator state when ABR, and inc/dec redistribute count as when we leave/enter the disabled state - so that translate-enabled ABR properly sets ASBR bit on non-NSSA areas. Run the resulting function through indent to clean it up. * ospf_lsa.c: (router_lsa_flags) For purposes of ASBR bit, NSSA area is same as stub area. --- ospfd/ospf_lsa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index a0afbad3..509afc8a 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -437,7 +437,8 @@ router_lsa_flags (struct ospf_area *area) SET_FLAG (flags, ROUTER_LSA_SHORTCUT); /* ASBR can't exit in stub area. */ - if (area->external_routing == OSPF_AREA_STUB) + if (area->external_routing == OSPF_AREA_STUB + || area->external_routing == OSPF_AREA_NSSA) UNSET_FLAG (flags, ROUTER_LSA_EXTERNAL); /* If ASBR set External flag */ else if (IS_OSPF_ASBR (area->ospf)) -- cgit v1.2.3 From 5db95bc2dda90dc462f77dd2610c004db685252e Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Tue, 4 Jul 2006 13:52:29 +0000 Subject: [ospfd] CID #13, dont try print out fields of LSA we know to be NULL. 2006-07-02 Paul Jakma * ospf_lsa.c: (ospf_translated_nssa_refresh) CID #13. --- ospfd/ospf_lsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 509afc8a..8b5c6eb8 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -2090,7 +2090,7 @@ ospf_translated_nssa_refresh (struct ospf *ospf, struct ospf_lsa *type7, if (IS_DEBUG_OSPF_NSSA) zlog_debug ("ospf_translated_nssa_refresh(): Could not install " "translated LSA, Id %s", - inet_ntoa (new->data->id)); + inet_ntoa (type7->data->id)); return NULL; } -- cgit v1.2.3 From 1fe6ed38cd0136c514aabae01389653beab27fb9 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Wed, 26 Jul 2006 09:37:26 +0000 Subject: [ospfd] Allow ospf_lsa_unlock to NULL out callers' LSA pointers upon free 2006-07-26 Paul Jakma * ospf_lsa.{c,h}: (ospf_lsa_unlock) Change to take a double pointer to the LSA to be 'unlocked', so that, if the LSA is freed, the callers pointer to the LSA can be NULLed out, allowing any further use of that pointer to provoke a crash sooner rather than later. * ospf_*.c: (general) Adjust callers of ospf_lsa_unlock to match previous. Try annotate 'locking' somewhat to show which 'locks' are protecting what LSA reference, if not obvious. * ospf_opaque.c: (ospf_opaque_lsa_install) Trivial: remove useless goto, replace with return. * ospf_packet.c: (ospf_make_ls_ack) Trivial: merge two list loops, the dual-loop predated the delete-safe list-loop macro. --- ospfd/ospf_lsa.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 8b5c6eb8..b99b931c 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -294,20 +294,21 @@ ospf_lsa_lock (struct ospf_lsa *lsa) /* Unlock LSA. */ void -ospf_lsa_unlock (struct ospf_lsa *lsa) +ospf_lsa_unlock (struct ospf_lsa **lsa) { /* This is sanity check. */ - if (!lsa) + if (!lsa || !*lsa) return; - lsa->lock--; + (*lsa)->lock--; - assert (lsa->lock >= 0); + assert ((*lsa)->lock >= 0); - if (lsa->lock == 0) + if ((*lsa)->lock == 0) { - assert (CHECK_FLAG (lsa->flags, OSPF_LSA_DISCARD)); - ospf_lsa_free (lsa); + assert (CHECK_FLAG ((*lsa)->flags, OSPF_LSA_DISCARD)); + ospf_lsa_free (*lsa); + *lsa = NULL; } } @@ -318,7 +319,7 @@ ospf_lsa_discard (struct ospf_lsa *lsa) if (!CHECK_FLAG (lsa->flags, OSPF_LSA_DISCARD)) { SET_FLAG (lsa->flags, OSPF_LSA_DISCARD); - ospf_lsa_unlock (lsa); + ospf_lsa_unlock (&lsa); } } @@ -1044,7 +1045,7 @@ ospf_router_lsa_update_timer (struct thread *thread) zlog_debug("LSA[Type%d:%s]: Refresh router-LSA for Area %s", lsa->data->type, inet_ntoa (lsa->data->id), area_str); ospf_lsa_flush_area (lsa, area); - ospf_lsa_unlock (area->router_lsa_self); + ospf_lsa_unlock (&area->router_lsa_self); area->router_lsa_self = NULL; /* Refresh router-LSA, (not install) and flood through area. */ @@ -1850,7 +1851,7 @@ ospf_install_flood_nssa (struct ospf *ospf, { if (IS_DEBUG_OSPF_NSSA) zlog_debug ("LSA[Type-7]: Could not build FWD-ADDR"); - ospf_lsa_discard(new); + ospf_lsa_discard (new); return; } } @@ -2518,7 +2519,7 @@ ospf_router_lsa_install (struct ospf *ospf, ospf_router_lsa_timer, OSPF_LS_REFRESH_TIME); /* Set self-originated router-LSA. */ - ospf_lsa_unlock (area->router_lsa_self); + ospf_lsa_unlock (&area->router_lsa_self); area->router_lsa_self = ospf_lsa_lock (new); if (IS_DEBUG_OSPF (lsa, LSA_INSTALL)) @@ -2562,7 +2563,7 @@ ospf_network_lsa_install (struct ospf *ospf, ospf_network_lsa_refresh_timer, OSPF_LS_REFRESH_TIME); - ospf_lsa_unlock (oi->network_lsa_self); + ospf_lsa_unlock (&oi->network_lsa_self); oi->network_lsa_self = ospf_lsa_lock (new); } @@ -3067,7 +3068,7 @@ ospf_lsa_maxage_delete (struct ospf *ospf, struct ospf_lsa *lsa) if ((n = listnode_lookup (ospf->maxage_lsa, lsa))) { list_delete_node (ospf->maxage_lsa, n); - ospf_lsa_unlock (lsa); + ospf_lsa_unlock (&lsa); /* maxage_lsa */ } } @@ -3482,7 +3483,7 @@ ospf_flush_self_originated_lsas_now (struct ospf *ospf) zlog_debug ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id)); ospf_lsa_flush_area (lsa, area); - ospf_lsa_unlock (area->router_lsa_self); + ospf_lsa_unlock (&area->router_lsa_self); area->router_lsa_self = NULL; OSPF_TIMER_OFF (area->t_router_lsa_self); } @@ -3497,7 +3498,7 @@ ospf_flush_self_originated_lsas_now (struct ospf *ospf) zlog_debug ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id)); ospf_lsa_flush_area (oi->network_lsa_self, area); - ospf_lsa_unlock (oi->network_lsa_self); + ospf_lsa_unlock (&oi->network_lsa_self); oi->network_lsa_self = NULL; OSPF_TIMER_OFF (oi->t_network_lsa_self); } @@ -3666,7 +3667,7 @@ ospf_lsa_action (struct thread *t) break; } - ospf_lsa_unlock (data->lsa); + ospf_lsa_unlock (&data->lsa); /* Message */ XFREE (MTYPE_OSPF_MESSAGE, data); return 0; } @@ -3681,7 +3682,7 @@ ospf_schedule_lsa_flood_area (struct ospf_area *area, struct ospf_lsa *lsa) data->action = LSA_ACTION_FLOOD_AREA; data->area = area; - data->lsa = ospf_lsa_lock (lsa); + data->lsa = ospf_lsa_lock (lsa); /* Message / Flood area */ thread_add_event (master, ospf_lsa_action, data, 0); } @@ -3696,7 +3697,7 @@ ospf_schedule_lsa_flush_area (struct ospf_area *area, struct ospf_lsa *lsa) data->action = LSA_ACTION_FLUSH_AREA; data->area = area; - data->lsa = ospf_lsa_lock (lsa); + data->lsa = ospf_lsa_lock (lsa); /* Message / Flush area */ thread_add_event (master, ospf_lsa_action, data, 0); } @@ -3779,7 +3780,8 @@ ospf_refresher_register_lsa (struct ospf *ospf, struct ospf_lsa *lsa) inet_ntoa (lsa->data->id), LS_AGE (lsa), index); if (!ospf->lsa_refresh_queue.qs[index]) ospf->lsa_refresh_queue.qs[index] = list_new (); - listnode_add (ospf->lsa_refresh_queue.qs[index], ospf_lsa_lock (lsa)); + listnode_add (ospf->lsa_refresh_queue.qs[index], + ospf_lsa_lock (lsa)); /* lsa_refresh_queue */ lsa->refresh_list = index; if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) zlog_debug ("LSA[Refresh:%s]: ospf_refresher_register_lsa(): " @@ -3801,7 +3803,7 @@ ospf_refresher_unregister_lsa (struct ospf *ospf, struct ospf_lsa *lsa) list_free (refresh_list); ospf->lsa_refresh_queue.qs[lsa->refresh_list] = NULL; } - ospf_lsa_unlock (lsa); + ospf_lsa_unlock (&lsa); /* lsa_refresh_queue */ lsa->refresh_list = -1; } } @@ -3855,7 +3857,7 @@ ospf_lsa_refresh_walker (struct thread *t) inet_ntoa (lsa->data->id), lsa, i); list_delete_node (refresh_list, node); - ospf_lsa_unlock (lsa); + ospf_lsa_unlock (&lsa); /* lsa_refresh_queue */ lsa->refresh_list = -1; listnode_add (lsa_to_refresh, lsa); } -- cgit v1.2.3 From 2518efd15b75687d4791a5eb4b0d7febc36cffbc Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Sun, 27 Aug 2006 06:49:29 +0000 Subject: [ospfd] Bug #134, ospfd should be more robust to backward time change 2006-08-25 Paul Jakma * (general) Bug #134. Be more robust to backward time changes, use the newly added libzebra time functions. In most cases: recent_time -> recent_relative_time() gettimeofday -> quagga_gettime (QUAGGA_CLK_MONOTONIC, ..) time -> quagga_time. (ospf_make_md5_digest) time() call deliberately not changed. (ospf_external_lsa_refresh) remove useless gettimeofday, LSA tv_orig time was already set in ospf_lsa_new, called via ospf_external_lsa_new. --- ospfd/ospf_lsa.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index b99b931c..05eed35e 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -141,7 +141,7 @@ ospf_lsa_refresh_delay (struct ospf_lsa *lsa) struct timeval delta, now; int delay = 0; - gettimeofday (&now, NULL); + quagga_gettime (QUAGGA_CLK_MONOTONIC, &now); delta = tv_sub (now, lsa->tv_orig); if (tv_cmp (delta, int2tv (OSPF_MIN_LS_INTERVAL)) < 0) @@ -163,10 +163,9 @@ int get_age (struct ospf_lsa *lsa) { int age; - struct timeval now; - gettimeofday (&now, NULL); - age = ntohs (lsa->data->ls_age) + tv_floor (tv_sub (now, lsa->tv_recv)); + age = ntohs (lsa->data->ls_age) + + tv_floor (tv_sub (recent_relative_time (), lsa->tv_recv)); return age; } @@ -229,7 +228,7 @@ ospf_lsa_new () new->flags = 0; new->lock = 1; new->retransmit_counter = 0; - gettimeofday (&new->tv_recv, NULL); + new->tv_recv = recent_relative_time (); new->tv_orig = new->tv_recv; new->refresh_list = -1; @@ -2460,9 +2459,6 @@ ospf_external_lsa_refresh (struct ospf *ospf, struct ospf_lsa *lsa, new->data->ls_seqnum = lsa_seqnum_increment (lsa); - /* Record timestamp. */ - gettimeofday (&new->tv_orig, NULL); - /* Re-calculate checksum. */ ospf_lsa_checksum (new->data); @@ -3770,7 +3766,7 @@ ospf_refresher_register_lsa (struct ospf *ospf, struct ospf_lsa *lsa) delay = 0; current_index = ospf->lsa_refresh_queue.index + - (time (NULL) - ospf->lsa_refresher_started)/OSPF_LSA_REFRESHER_GRANULARITY; + (quagga_time (NULL) - ospf->lsa_refresher_started)/OSPF_LSA_REFRESHER_GRANULARITY; index = (current_index + delay/OSPF_LSA_REFRESHER_GRANULARITY) % (OSPF_LSA_REFRESHER_SLOTS); @@ -3829,7 +3825,7 @@ ospf_lsa_refresh_walker (struct thread *t) modulus. */ ospf->lsa_refresh_queue.index = ((unsigned long)(ospf->lsa_refresh_queue.index + - (time (NULL) - ospf->lsa_refresher_started) / + (quagga_time (NULL) - ospf->lsa_refresher_started) / OSPF_LSA_REFRESHER_GRANULARITY)) % OSPF_LSA_REFRESHER_SLOTS; if (IS_DEBUG_OSPF (lsa, LSA_REFRESH)) @@ -3867,7 +3863,7 @@ ospf_lsa_refresh_walker (struct thread *t) ospf->t_lsa_refresher = thread_add_timer (master, ospf_lsa_refresh_walker, ospf, ospf->lsa_refresh_interval); - ospf->lsa_refresher_started = time (NULL); + ospf->lsa_refresher_started = quagga_time (NULL); for (ALL_LIST_ELEMENTS (lsa_to_refresh, node, nnode, lsa)) ospf_lsa_refresh (ospf, lsa); -- cgit v1.2.3 From e4529636b77124285cca96a62799d0ff6a7addeb Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Tue, 12 Dec 2006 19:18:21 +0000 Subject: [PtP over ethernet] New peer flag allows much more addressing flexibility 2006-12-12 Andrew J. Schorr * if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating whether a peer address has been configured. Comment now shows the new interpretation of the destination addr: if ZEBRA_IFA_PEER is set, then it must contain the destination address, otherwise it may contain the broadcast address or be NULL. (CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete macros that were specific to IPv4 and not fully general. (CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag. (CONNECTED_PREFIX) New macro giving the prefix to insert into the RIB: if CONNECTED_PEER, then use the destination (peer) address, else use the address field. (CONNECTED_ID) New macro to come up with an identifying address for the struct connected. * if.c: (if_lookup_address, connected_lookup_address) Streamline logic with new CONNECTED_PREFIX macro. * prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros for better performance than the general prefix_copy function. * zclient.c: (zebra_interface_address_read) For non-null destination addresses, set prefixlen to equal the address prefixlen. This is needed to get the new CONNECTED_PREFIX macro to work properly. * connected.c: (connected_up_ipv4, connected_down_ipv4, connected_up_ipv6, connected_down_ipv6) Simplify logic using the new CONNECTED_PREFIX macro. (connected_add_ipv4) Set prefixlen in destination addresses (required by the CONNECTED_PREFIX macro). Use CONNECTED_PEER macro instead of testing for IFF_POINTOPOINT. Delete invalid warning message. Warn about cases where the ZEBRA_IFA_PEER is set but no destination address has been supplied (and turn off the flag). (connected_add_ipv6) Add new flags argument so callers may set the ZEBRA_IFA_PEER flag. If peer/broadcast address satisfies IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning. Set prefixlen in destination address so CONNECTED_PREFIX will work. * connected.h: (connected_add_ipv6) Add new flags argument so callers may set the ZEBRA_IFA_PEER flag. * interface.c: (connected_dump_vty) Use CONNECTED_PEER macro to decide whether the destination address is a peer or broadcast address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT). * if_ioctl.c: (if_getaddrs) Instead of setting a peer address only when the IFF_POINTOPOINT is set, we now accept a peer address whenever it is available and not the same as the local address. Otherwise (no peer address assigned), we check for a broadcast address (regardless of the IFF_BROADCAST flag). And must now pass a flags value of ZEBRA_IFA_PEER to connected_add_ipv4 when a peer address is assigned. The same new logic is used with the IPv6 code as well (and we pass the new flags argument to connected_add_ipv6). (if_get_addr) Do not bother to check IFF_POINTOPOINT: just issue the SIOCGIFDSTADDR ioctl and see if we get back a peer address not matching the local address (and set the ZEBRA_IFA_PEER in that case). If there's no peer address, try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set. * if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl without bothering to check the IFF_POINTOPOINT flag. And if no peer address was found, just try the SIOCGLIFBRDADDR ioctl without checking the IFF_BROADCAST flag. Call connected_add_ipv4 and connected_add_ipv6 with appropriate flags. * if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to connected_add_ipv6. * kernel_socket.c: (ifam_read) Must pass new flags argument to connected_add_ipv6. * rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2 to determine local and possible peer address (so there's no longer a test for IFF_POINTOPOINT). Set ZEBRA_IFA_PEER flag appropriately. Pass new flags argument to connected_add_ipv6. (netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast to determine whether the connected destination address is a broadcast address. * bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete) Simplify logic by using new CONNECTED_PREFIX macro. * ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix, ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX macro. * ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX macro, both options collapse into the same code. * ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new CONNECTED_ID macro. (ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX macro. * ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro instead of testing the IFF_POINTOPOINT flag. * ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro instead of testing with if_is_pointopoint. And add commented-out code to implement alternative (in my opinion) more elegant behavior that has no special-case treatment for PtP addresses. (ospf_network_run) Use new CONNECTED_ID macro to simplify logic. * rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID macro to simplify logic. (rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does not give a useful result if prefixlen is 32 (we require a peer address in such cases). * ripd.c: (rip_update_interface) Fix same bug as above. --- ospfd/ospf_lsa.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 05eed35e..b9a70a66 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -543,7 +543,7 @@ link_info_set (struct stream *s, struct in_addr id, return 1; } -/* Describe Point-to-Point link. */ +/* Describe Point-to-Point link (Section 12.4.1.1). */ static int lsa_link_ptop_set (struct stream *s, struct ospf_interface *oi) { @@ -564,28 +564,13 @@ lsa_link_ptop_set (struct stream *s, struct ospf_interface *oi) LSA_LINK_TYPE_POINTOPOINT, 0, cost); } - if (CONNECTED_DEST_HOST(oi->connected)) - { - /* Option 1: - link_type = LSA_LINK_TYPE_STUB; - link_id = nbr->address.u.prefix4; - link_data.s_addr = 0xffffffff; - link_cost = o->output_cost; */ - - id.s_addr = oi->connected->destination->u.prefix4.s_addr; - mask.s_addr = 0xffffffff; - links += link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, - oi->output_cost); - } - else - { - /* Option 2: We need to include link to a stub - network regardless of the state of the neighbor */ - masklen2ip (oi->address->prefixlen, &mask); - id.s_addr = oi->address->u.prefix4.s_addr & mask.s_addr; - links += link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, - oi->output_cost); - } + /* Regardless of the state of the neighboring router, we must + add a Type 3 link (stub network). + N.B. Options 1 & 2 share basically the same logic. */ + masklen2ip (oi->address->prefixlen, &mask); + id.s_addr = CONNECTED_PREFIX(oi->connected)->u.prefix4.s_addr & mask.s_addr; + links += link_info_set (s, id, mask, LSA_LINK_TYPE_STUB, 0, + oi->output_cost); return links; } -- cgit v1.2.3 From 5b02255a671a5eee7c1736f6f9d0bab19a65cb2a Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Mon, 6 Aug 2007 15:27:12 +0000 Subject: [ospfd] Bug #331, NSSA ASBR regression - failure to set E-bit in NSSA areas 2007-08-06 Paul Jakma * ospf_lsa.c: (router_lsa_flags) Bug #331, NSSA regression caused caused ASBRs to not advertise E-bit into NSSA areas. --- ospfd/ospf_lsa.c | 1 - 1 file changed, 1 deletion(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index b9a70a66..c37ab325 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -438,7 +438,6 @@ router_lsa_flags (struct ospf_area *area) /* ASBR can't exit in stub area. */ if (area->external_routing == OSPF_AREA_STUB - || area->external_routing == OSPF_AREA_NSSA) UNSET_FLAG (flags, ROUTER_LSA_EXTERNAL); /* If ASBR set External flag */ else if (IS_OSPF_ASBR (area->ospf)) -- cgit v1.2.3 From fc787e873dff0091069742b34fb3631ac529c92a Mon Sep 17 00:00:00 2001 From: Greg Troxel Date: Mon, 6 Aug 2007 15:50:20 +0000 Subject: Fix last commit - add back in closing paren which was apparently uninentionally deleted along with a test. --- ospfd/ospf_lsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index c37ab325..243928f4 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -437,7 +437,7 @@ router_lsa_flags (struct ospf_area *area) SET_FLAG (flags, ROUTER_LSA_SHORTCUT); /* ASBR can't exit in stub area. */ - if (area->external_routing == OSPF_AREA_STUB + if (area->external_routing == OSPF_AREA_STUB) UNSET_FLAG (flags, ROUTER_LSA_EXTERNAL); /* If ASBR set External flag */ else if (IS_OSPF_ASBR (area->ospf)) -- cgit v1.2.3 From 6a270cd93d02a88709e7292684db47552b630abf Mon Sep 17 00:00:00 2001 From: Jingjing Duan Date: Wed, 13 Aug 2008 19:09:10 +0100 Subject: [ospfd/isisd] Switch to lib/ Fletcher checksum, fixing bug in isisd 2008-08-13 Jingjing Duan * ospfd/: Remove the old checksum implementation and use the consolidated version. * isisd/: ditto, thus fixing isisd checksuming on big-endian. Signed-off-by: Paul Jakma --- ospfd/ospf_lsa.c | 44 +++++++++++--------------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) (limited to 'ospfd/ospf_lsa.c') diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 243928f4..f453353d 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -32,6 +32,7 @@ #include "thread.h" #include "hash.h" #include "sockunion.h" /* for inet_aton() */ +#include "checksum.h" #include "ospfd/ospfd.h" #include "ospfd/ospf_interface.h" @@ -172,46 +173,23 @@ get_age (struct ospf_lsa *lsa) /* Fletcher Checksum -- Refer to RFC1008. */ -#define MODX 4102 -#define LSA_CHECKSUM_OFFSET 15 +/* All the offsets are zero-based. The offsets in the RFC1008 are + one-based. */ u_int16_t ospf_lsa_checksum (struct lsa_header *lsa) { - u_char *sp, *ep, *p, *q; - int c0 = 0, c1 = 0; - int x, y; - u_int16_t length; - - lsa->checksum = 0; - length = ntohs (lsa->length) - 2; - sp = (u_char *) &lsa->options; - - for (ep = sp + length; sp < ep; sp = q) - { - q = sp + MODX; - if (q > ep) - q = ep; - for (p = sp; p < q; p++) - { - c0 += *p; - c1 += c0; - } - c0 %= 255; - c1 %= 255; - } + u_char *buffer = (u_char *) &lsa->options; + int options_offset = buffer - (u_char *) &lsa->ls_age; /* should be 2 */ - x = (((int)length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255; - if (x <= 0) - x += 255; - y = 510 - c0 - x; - if (y > 255) - y -= 255; + /* Skip the AGE field */ + u_int16_t len = ntohs(lsa->length) - options_offset; - /* take care endian issue. */ - lsa->checksum = htons ((x << 8) + y); + /* Checksum offset starts from "options" field, not the beginning of the + lsa_header struct. The offset is 14, rather than 16. */ + int checksum_offset = (u_char *) &lsa->checksum - buffer; - return (lsa->checksum); + return fletcher_checksum(buffer, len, checksum_offset); } -- cgit v1.2.3