blob: 93f1995fe3e8f4631570ae07423f580397fca371 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP flap dampening
2 Copyright (C) 2001 IP Infusion Inc.
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22#include <math.h>
23
24#include "prefix.h"
25#include "memory.h"
26#include "command.h"
27#include "log.h"
28#include "thread.h"
29
30#include "bgpd/bgpd.h"
31#include "bgpd/bgp_damp.h"
32#include "bgpd/bgp_table.h"
33#include "bgpd/bgp_route.h"
34#include "bgpd/bgp_attr.h"
35#include "bgpd/bgp_advertise.h"
36
37/* Global variable to access damping configuration */
38struct bgp_damp_config bgp_damp_cfg;
39struct bgp_damp_config *damp = &bgp_damp_cfg;
40
41/* Utility macro to add and delete BGP dampening information to no
42 used list. */
43#define BGP_DAMP_LIST_ADD(N,A) BGP_INFO_ADD(N,A,no_reuse_list)
44#define BGP_DAMP_LIST_DEL(N,A) BGP_INFO_DEL(N,A,no_reuse_list)
45
46/* Calculate reuse list index by penalty value. */
47static int
48bgp_reuse_index (int penalty)
49{
paulfd79ac92004-10-13 05:06:08 +000050 unsigned int i;
paul718e3742002-12-13 20:15:29 +000051 int index;
52
53 i = (int)(((double) penalty / damp->reuse_limit - 1.0) * damp->scale_factor);
54
55 if ( i >= damp->reuse_index_size )
56 i = damp->reuse_index_size - 1;
57
58 index = damp->reuse_index[i] - damp->reuse_index[0];
59
60 return (damp->reuse_offset + index) % damp->reuse_list_size;
61}
62
63/* Add BGP dampening information to reuse list. */
64static void
65bgp_reuse_list_add (struct bgp_damp_info *bdi)
66{
67 int index;
68
69 index = bdi->index = bgp_reuse_index (bdi->penalty);
70
71 bdi->prev = NULL;
72 bdi->next = damp->reuse_list[index];
73 if (damp->reuse_list[index])
74 damp->reuse_list[index]->prev = bdi;
75 damp->reuse_list[index] = bdi;
76}
77
78/* Delete BGP dampening information from reuse list. */
79static void
80bgp_reuse_list_delete (struct bgp_damp_info *bdi)
81{
82 if (bdi->next)
83 bdi->next->prev = bdi->prev;
84 if (bdi->prev)
85 bdi->prev->next = bdi->next;
86 else
87 damp->reuse_list[bdi->index] = bdi->next;
88}
89
90/* Return decayed penalty value. */
91int
92bgp_damp_decay (time_t tdiff, int penalty)
93{
paulfd79ac92004-10-13 05:06:08 +000094 unsigned int i;
paul718e3742002-12-13 20:15:29 +000095
96 i = (int) ((double) tdiff / DELTA_T);
97
98 if (i == 0)
99 return penalty;
100
101 if (i >= damp->decay_array_size)
102 return 0;
103
104 return (int) (penalty * damp->decay_array[i]);
105}
106
107/* Handler of reuse timer event. Each route in the current reuse-list
108 is evaluated. RFC2439 Section 4.8.7. */
paul94f2b392005-06-28 12:44:16 +0000109static int
paul718e3742002-12-13 20:15:29 +0000110bgp_reuse_timer (struct thread *t)
111{
112 struct bgp_damp_info *bdi;
113 struct bgp_damp_info *next;
114 time_t t_now, t_diff;
115 struct bgp *bgp;
paul94f2b392005-06-28 12:44:16 +0000116
paul718e3742002-12-13 20:15:29 +0000117 damp->t_reuse = NULL;
118 damp->t_reuse =
119 thread_add_timer (master, bgp_reuse_timer, NULL, DELTA_REUSE);
120
121 bgp = bgp_get_default ();
122 if (! bgp)
123 return 0;
124
125 t_now = time (NULL);
126
127 /* 1. save a pointer to the current zeroth queue head and zero the
128 list head entry. */
129 bdi = damp->reuse_list[damp->reuse_offset];
130 damp->reuse_list[damp->reuse_offset] = NULL;
131
132 /* 2. set offset = modulo reuse-list-size ( offset + 1 ), thereby
133 rotating the circular queue of list-heads. */
134 damp->reuse_offset = (damp->reuse_offset + 1) % damp->reuse_list_size;
135
136 /* 3. if ( the saved list head pointer is non-empty ) */
137 for (; bdi; bdi = next)
138 {
139 next = bdi->next;
140
141 /* Set t-diff = t-now - t-updated. */
142 t_diff = t_now - bdi->t_updated;
143
144 /* Set figure-of-merit = figure-of-merit * decay-array-ok [t-diff] */
145 bdi->penalty = bgp_damp_decay (t_diff, bdi->penalty);
146
147 /* Set t-updated = t-now. */
148 bdi->t_updated = t_now;
149
150 /* if (figure-of-merit < reuse). */
151 if (bdi->penalty < damp->reuse_limit)
152 {
153 /* Reuse the route. */
154 UNSET_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED);
155 bdi->suppress_time = 0;
156
157 if (bdi->lastrecord == BGP_RECORD_UPDATE)
158 {
159 UNSET_FLAG (bdi->binfo->flags, BGP_INFO_HISTORY);
160 bgp_aggregate_increment (bgp, &bdi->rn->p, bdi->binfo,
161 bdi->afi, bdi->safi);
162 bgp_process (bgp, bdi->rn, bdi->afi, bdi->safi);
163 }
164
165 if (bdi->penalty <= damp->reuse_limit / 2.0)
166 bgp_damp_info_free (bdi, 1);
167 else
168 BGP_DAMP_LIST_ADD (damp, bdi);
169 }
170 else
171 /* Re-insert into another list (See RFC2439 Section 4.8.6). */
172 bgp_reuse_list_add (bdi);
173 }
174
175 return 0;
176}
177
178/* A route becomes unreachable (RFC2439 Section 4.8.2). */
179int
180bgp_damp_withdraw (struct bgp_info *binfo, struct bgp_node *rn,
181 afi_t afi, safi_t safi, int attr_change)
182{
183 time_t t_now;
184 struct bgp_damp_info *bdi;
185 double last_penalty = 0;
186
187 t_now = time (NULL);
188
189 /* Processing Unreachable Messages. */
190 bdi = binfo->damp_info;
191
192 if (bdi == NULL)
193 {
194 /* If there is no previous stability history. */
195
196 /* RFC2439 said:
197 1. allocate a damping structure.
198 2. set figure-of-merit = 1.
199 3. withdraw the route. */
200
201 bdi = XCALLOC (MTYPE_BGP_DAMP_INFO, sizeof (struct bgp_damp_info));
202 bdi->binfo = binfo;
203 bdi->rn = rn;
204 bdi->penalty = (attr_change ? DEFAULT_PENALTY / 2 : DEFAULT_PENALTY);
205 bdi->flap = 1;
206 bdi->start_time = t_now;
207 bdi->suppress_time = 0;
208 bdi->index = -1;
209 bdi->afi = afi;
210 bdi->safi = safi;
211 binfo->damp_info = bdi;
212 BGP_DAMP_LIST_ADD (damp, bdi);
213 }
214 else
215 {
216 last_penalty = bdi->penalty;
217
218 /* 1. Set t-diff = t-now - t-updated. */
219 bdi->penalty =
220 (bgp_damp_decay (t_now - bdi->t_updated, bdi->penalty)
221 + (attr_change ? DEFAULT_PENALTY / 2 : DEFAULT_PENALTY));
222
223 if (bdi->penalty > damp->ceiling)
224 bdi->penalty = damp->ceiling;
225
226 bdi->flap++;
227 }
228
229 bdi->lastrecord = BGP_RECORD_WITHDRAW;
230 bdi->t_updated = t_now;
231
232 /* Make this route as historical status. */
233 SET_FLAG (binfo->flags, BGP_INFO_HISTORY);
234
235 /* Remove the route from a reuse list if it is on one. */
236 if (CHECK_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED))
237 {
238 /* If decay rate isn't equal to 0, reinsert brn. */
239 if (bdi->penalty != last_penalty)
240 {
241 bgp_reuse_list_delete (bdi);
242 bgp_reuse_list_add (bdi);
243 }
244 return BGP_DAMP_SUPPRESSED;
245 }
246
247 /* If not suppressed before, do annonunce this withdraw and
248 insert into reuse_list. */
249 if (bdi->penalty >= damp->suppress_value)
250 {
251 SET_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED);
252 bdi->suppress_time = t_now;
253 BGP_DAMP_LIST_DEL (damp, bdi);
254 bgp_reuse_list_add (bdi);
255 }
256
257 return BGP_DAMP_USED;
258}
259
260int
261bgp_damp_update (struct bgp_info *binfo, struct bgp_node *rn,
262 afi_t afi, safi_t safi)
263{
264 time_t t_now;
265 struct bgp_damp_info *bdi;
266 int status;
267
268 bdi = binfo->damp_info;
269 if (! bdi)
270 return BGP_DAMP_USED;
271
272 t_now = time (NULL);
273 UNSET_FLAG (binfo->flags, BGP_INFO_HISTORY);
274
275 bdi->lastrecord = BGP_RECORD_UPDATE;
276 bdi->penalty = bgp_damp_decay (t_now - bdi->t_updated, bdi->penalty);
277
278 if (! CHECK_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED)
279 && (bdi->penalty < damp->suppress_value))
280 status = BGP_DAMP_USED;
281 else if (CHECK_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED)
282 && (bdi->penalty < damp->reuse_limit) )
283 {
284 UNSET_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED);
285 bgp_reuse_list_delete (bdi);
286 BGP_DAMP_LIST_ADD (damp, bdi);
287 bdi->suppress_time = 0;
288 status = BGP_DAMP_USED;
289 }
290 else
291 status = BGP_DAMP_SUPPRESSED;
292
293 if (bdi->penalty > damp->reuse_limit / 2.0)
294 bdi->t_updated = t_now;
295 else
296 bgp_damp_info_free (bdi, 0);
297
298 return status;
299}
300
301/* Remove dampening information and history route. */
302int
303bgp_damp_scan (struct bgp_info *binfo, afi_t afi, safi_t safi)
304{
305 time_t t_now, t_diff;
306 struct bgp_damp_info *bdi;
307
308 t_now = time (NULL);
309 bdi = binfo->damp_info;
310
311 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
312 {
313 t_diff = t_now - bdi->suppress_time;
314
315 if (t_diff >= damp->max_suppress_time)
316 {
317 UNSET_FLAG (binfo->flags, BGP_INFO_DAMPED);
318 bgp_reuse_list_delete (bdi);
319 BGP_DAMP_LIST_ADD (damp, bdi);
320 bdi->penalty = damp->reuse_limit;
321 bdi->suppress_time = 0;
322 bdi->t_updated = t_now;
323
324 /* Need to announce UPDATE once this binfo is usable again. */
325 if (bdi->lastrecord == BGP_RECORD_UPDATE)
326 return 1;
327 else
328 return 0;
329 }
330 }
331 else
332 {
333 t_diff = t_now - bdi->t_updated;
334 bdi->penalty = bgp_damp_decay (t_diff, bdi->penalty);
335
336 if (bdi->penalty <= damp->reuse_limit / 2.0)
337 {
338 /* release the bdi, bdi->binfo. */
339 bgp_damp_info_free (bdi, 1);
340 return 0;
341 }
342 else
343 bdi->t_updated = t_now;
344 }
345 return 0;
346}
347
348void
349bgp_damp_info_free (struct bgp_damp_info *bdi, int withdraw)
350{
351 struct bgp_info *binfo;
paul718e3742002-12-13 20:15:29 +0000352
353 if (! bdi)
354 return;
355
356 binfo = bdi->binfo;
357 binfo->damp_info = NULL;
358
359 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
360 bgp_reuse_list_delete (bdi);
361 else
362 BGP_DAMP_LIST_DEL (damp, bdi);
363
364 UNSET_FLAG (binfo->flags, BGP_INFO_DAMPED);
365 UNSET_FLAG (binfo->flags, BGP_INFO_HISTORY);
366
367 if (bdi->lastrecord == BGP_RECORD_WITHDRAW && withdraw)
paul200df112005-06-01 11:17:05 +0000368 bgp_info_delete (bdi->rn, binfo);
369
paul718e3742002-12-13 20:15:29 +0000370 XFREE (MTYPE_BGP_DAMP_INFO, bdi);
371}
372
paul94f2b392005-06-28 12:44:16 +0000373static void
paul718e3742002-12-13 20:15:29 +0000374bgp_damp_parameter_set (int hlife, int reuse, int sup, int maxsup)
375{
376 double reuse_max_ratio;
paulfd79ac92004-10-13 05:06:08 +0000377 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000378 double j;
379
380 damp->suppress_value = sup;
381 damp->half_life = hlife;
382 damp->reuse_limit = reuse;
383 damp->max_suppress_time = maxsup;
384
385 /* Initialize params per bgp_damp_config. */
386 damp->reuse_index_size = REUSE_ARRAY_SIZE;
387
388 damp->ceiling = (int)(damp->reuse_limit * (pow(2, (double)damp->max_suppress_time/damp->half_life)));
389
390 /* Decay-array computations */
391 damp->decay_array_size = ceil ((double) damp->max_suppress_time / DELTA_T);
392 damp->decay_array = XMALLOC (MTYPE_BGP_DAMP_ARRAY,
393 sizeof(double) * (damp->decay_array_size));
394 damp->decay_array[0] = 1.0;
395 damp->decay_array[1] = exp ((1.0/((double)damp->half_life/DELTA_T)) * log(0.5));
396
397 /* Calculate decay values for all possible times */
398 for (i = 2; i < damp->decay_array_size; i++)
399 damp->decay_array[i] = damp->decay_array[i-1] * damp->decay_array[1];
400
401 /* Reuse-list computations */
402 i = ceil ((double)damp->max_suppress_time / DELTA_REUSE) + 1;
403 if (i > REUSE_LIST_SIZE || i == 0)
404 i = REUSE_LIST_SIZE;
405 damp->reuse_list_size = i;
406
407 damp->reuse_list = XCALLOC (MTYPE_BGP_DAMP_ARRAY,
408 damp->reuse_list_size
409 * sizeof (struct bgp_reuse_node *));
410 memset (damp->reuse_list, 0x00,
411 damp->reuse_list_size * sizeof (struct bgp_reuse_node *));
412
413 /* Reuse-array computations */
414 damp->reuse_index = XMALLOC (MTYPE_BGP_DAMP_ARRAY,
415 sizeof(int) * damp->reuse_index_size);
416 memset (damp->reuse_index, 0x00,
417 damp->reuse_list_size * sizeof (int));
418
419 reuse_max_ratio = (double)damp->ceiling/damp->reuse_limit;
420 j = (exp((double)damp->max_suppress_time/damp->half_life) * log10(2.0));
421 if ( reuse_max_ratio > j && j != 0 )
422 reuse_max_ratio = j;
423
424 damp->scale_factor = (double)damp->reuse_index_size/(reuse_max_ratio - 1);
425
426 for (i = 0; i < damp->reuse_index_size; i++)
427 {
428 damp->reuse_index[i] =
429 (int)(((double)damp->half_life / DELTA_REUSE)
430 * log10 (1.0 / (damp->reuse_limit * ( 1.0 + ((double)i/damp->scale_factor)))) / log10(0.5));
431 }
432}
433
434int
paulfd79ac92004-10-13 05:06:08 +0000435bgp_damp_enable (struct bgp *bgp, afi_t afi, safi_t safi, time_t half,
436 unsigned int reuse, unsigned int suppress, time_t max)
paul718e3742002-12-13 20:15:29 +0000437{
438 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
439 {
440 if (damp->half_life == half
441 && damp->reuse_limit == reuse
442 && damp->suppress_value == suppress
443 && damp->max_suppress_time == max)
444 return 0;
445 bgp_damp_disable (bgp, afi, safi);
446 }
447
448 SET_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING);
449 bgp_damp_parameter_set (half, reuse, suppress, max);
450
451 /* Register reuse timer. */
452 if (! damp->t_reuse)
453 damp->t_reuse =
454 thread_add_timer (master, bgp_reuse_timer, NULL, DELTA_REUSE);
455
456 return 0;
457}
458
paul94f2b392005-06-28 12:44:16 +0000459static void
paul718e3742002-12-13 20:15:29 +0000460bgp_damp_config_clean (struct bgp_damp_config *damp)
461{
462 /* Free decay array */
463 XFREE (MTYPE_BGP_DAMP_ARRAY, damp->decay_array);
464
465 /* Free reuse index array */
466 XFREE (MTYPE_BGP_DAMP_ARRAY, damp->reuse_index);
467
468 /* Free reuse list array. */
469 XFREE (MTYPE_BGP_DAMP_ARRAY, damp->reuse_list);
470}
471
472/* Clean all the bgp_damp_info stored in reuse_list. */
473void
paul94f2b392005-06-28 12:44:16 +0000474bgp_damp_info_clean (void)
paul718e3742002-12-13 20:15:29 +0000475{
paulfd79ac92004-10-13 05:06:08 +0000476 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000477 struct bgp_damp_info *bdi, *next;
478
479 damp->reuse_offset = 0;
480
481 for (i = 0; i < damp->reuse_list_size; i++)
482 {
483 if (! damp->reuse_list[i])
484 continue;
485
486 for (bdi = damp->reuse_list[i]; bdi; bdi = next)
487 {
488 next = bdi->next;
489 bgp_damp_info_free (bdi, 1);
490 }
491 damp->reuse_list[i] = NULL;
492 }
493
494 for (bdi = damp->no_reuse_list; bdi; bdi = next)
495 {
496 next = bdi->next;
497 bgp_damp_info_free (bdi, 1);
498 }
499 damp->no_reuse_list = NULL;
500}
501
502int
503bgp_damp_disable (struct bgp *bgp, afi_t afi, safi_t safi)
504{
505 /* Cancel reuse thread. */
506 if (damp->t_reuse )
507 thread_cancel (damp->t_reuse);
508 damp->t_reuse = NULL;
509
510 /* Clean BGP dampening information. */
511 bgp_damp_info_clean ();
512
513 /* Clear configuration */
514 bgp_damp_config_clean (&bgp_damp_cfg);
515
516 UNSET_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING);
517 return 0;
518}
519
520int
521bgp_config_write_damp (struct vty *vty)
522{
523 if (&bgp_damp_cfg)
524 {
525 if (bgp_damp_cfg.half_life == DEFAULT_HALF_LIFE*60
526 && bgp_damp_cfg.reuse_limit == DEFAULT_REUSE
527 && bgp_damp_cfg.suppress_value == DEFAULT_SUPPRESS
528 && bgp_damp_cfg.max_suppress_time == bgp_damp_cfg.half_life*4)
529 vty_out (vty, " bgp dampening%s", VTY_NEWLINE);
530 else if (bgp_damp_cfg.half_life != DEFAULT_HALF_LIFE*60
531 && bgp_damp_cfg.reuse_limit == DEFAULT_REUSE
532 && bgp_damp_cfg.suppress_value == DEFAULT_SUPPRESS
533 && bgp_damp_cfg.max_suppress_time == bgp_damp_cfg.half_life*4)
paulfd79ac92004-10-13 05:06:08 +0000534 vty_out (vty, " bgp dampening %ld%s",
paul718e3742002-12-13 20:15:29 +0000535 bgp_damp_cfg.half_life/60,
536 VTY_NEWLINE);
537 else
paulfd79ac92004-10-13 05:06:08 +0000538 vty_out (vty, " bgp dampening %ld %d %d %ld%s",
paul718e3742002-12-13 20:15:29 +0000539 bgp_damp_cfg.half_life/60,
540 bgp_damp_cfg.reuse_limit,
541 bgp_damp_cfg.suppress_value,
542 bgp_damp_cfg.max_suppress_time/60,
543 VTY_NEWLINE);
544 return 1;
545 }
546 return 0;
547}
548
549#define BGP_UPTIME_LEN 25
550
551char *
paulfd79ac92004-10-13 05:06:08 +0000552bgp_get_reuse_time (unsigned int penalty, char *buf, size_t len)
paul718e3742002-12-13 20:15:29 +0000553{
554 time_t reuse_time = 0;
555 struct tm *tm = NULL;
556
557 if (penalty > damp->reuse_limit)
558 {
559 reuse_time = (int) (DELTA_T * ((log((double)damp->reuse_limit/penalty))/(log(damp->decay_array[1]))));
560
561 if (reuse_time > damp->max_suppress_time)
562 reuse_time = damp->max_suppress_time;
563
564 tm = gmtime (&reuse_time);
565 }
566 else
567 reuse_time = 0;
568
569 /* Making formatted timer strings. */
570#define ONE_DAY_SECOND 60*60*24
571#define ONE_WEEK_SECOND 60*60*24*7
572 if (reuse_time == 0)
573 snprintf (buf, len, "00:00:00");
574 else if (reuse_time < ONE_DAY_SECOND)
575 snprintf (buf, len, "%02d:%02d:%02d",
576 tm->tm_hour, tm->tm_min, tm->tm_sec);
577 else if (reuse_time < ONE_WEEK_SECOND)
578 snprintf (buf, len, "%dd%02dh%02dm",
579 tm->tm_yday, tm->tm_hour, tm->tm_min);
580 else
581 snprintf (buf, len, "%02dw%dd%02dh",
582 tm->tm_yday/7, tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
583
584 return buf;
585}
586
587void
588bgp_damp_info_vty (struct vty *vty, struct bgp_info *binfo)
589{
590 struct bgp_damp_info *bdi;
591 time_t t_now, t_diff;
592 char timebuf[BGP_UPTIME_LEN];
593 int penalty;
594
595 /* BGP dampening information. */
596 bdi = binfo->damp_info;
597
598 /* If dampening is not enabled or there is no dampening information,
599 return immediately. */
600 if (! damp || ! bdi)
601 return;
602
603 /* Calculate new penalty. */
604 t_now = time (NULL);
605 t_diff = t_now - bdi->t_updated;
606 penalty = bgp_damp_decay (t_diff, bdi->penalty);
607
608 vty_out (vty, " Dampinfo: penalty %d, flapped %d times in %s",
609 penalty, bdi->flap,
610 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN));
611
612 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
613 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
614 vty_out (vty, ", reuse in %s",
615 bgp_get_reuse_time (penalty, timebuf, BGP_UPTIME_LEN));
616
617 vty_out (vty, "%s", VTY_NEWLINE);
618}
619
620char *
621bgp_damp_reuse_time_vty (struct vty *vty, struct bgp_info *binfo)
622{
623 struct bgp_damp_info *bdi;
624 time_t t_now, t_diff;
625 char timebuf[BGP_UPTIME_LEN];
626 int penalty;
627
628 /* BGP dampening information. */
629 bdi = binfo->damp_info;
630
631 /* If dampening is not enabled or there is no dampening information,
632 return immediately. */
633 if (! damp || ! bdi)
634 return NULL;
635
636 /* Calculate new penalty. */
637 t_now = time (NULL);
638 t_diff = t_now - bdi->t_updated;
639 penalty = bgp_damp_decay (t_diff, bdi->penalty);
640
641 return bgp_get_reuse_time (penalty, timebuf, BGP_UPTIME_LEN);
642}