blob: a2163a4f2650557b282c7e4e8dfa1ead4bb232fe [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;
paul41200852005-11-03 12:52:18 +0000115
paul718e3742002-12-13 20:15:29 +0000116 damp->t_reuse = NULL;
117 damp->t_reuse =
118 thread_add_timer (master, bgp_reuse_timer, NULL, DELTA_REUSE);
119
paul718e3742002-12-13 20:15:29 +0000120 t_now = time (NULL);
121
122 /* 1. save a pointer to the current zeroth queue head and zero the
123 list head entry. */
124 bdi = damp->reuse_list[damp->reuse_offset];
125 damp->reuse_list[damp->reuse_offset] = NULL;
126
127 /* 2. set offset = modulo reuse-list-size ( offset + 1 ), thereby
128 rotating the circular queue of list-heads. */
129 damp->reuse_offset = (damp->reuse_offset + 1) % damp->reuse_list_size;
130
131 /* 3. if ( the saved list head pointer is non-empty ) */
132 for (; bdi; bdi = next)
133 {
paul41200852005-11-03 12:52:18 +0000134 struct bgp *bgp = bdi->binfo->peer->bgp;
135
paul718e3742002-12-13 20:15:29 +0000136 next = bdi->next;
137
138 /* Set t-diff = t-now - t-updated. */
139 t_diff = t_now - bdi->t_updated;
140
141 /* Set figure-of-merit = figure-of-merit * decay-array-ok [t-diff] */
142 bdi->penalty = bgp_damp_decay (t_diff, bdi->penalty);
143
144 /* Set t-updated = t-now. */
145 bdi->t_updated = t_now;
146
147 /* if (figure-of-merit < reuse). */
148 if (bdi->penalty < damp->reuse_limit)
149 {
150 /* Reuse the route. */
151 UNSET_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED);
152 bdi->suppress_time = 0;
153
154 if (bdi->lastrecord == BGP_RECORD_UPDATE)
155 {
156 UNSET_FLAG (bdi->binfo->flags, BGP_INFO_HISTORY);
157 bgp_aggregate_increment (bgp, &bdi->rn->p, bdi->binfo,
158 bdi->afi, bdi->safi);
159 bgp_process (bgp, bdi->rn, bdi->afi, bdi->safi);
160 }
161
162 if (bdi->penalty <= damp->reuse_limit / 2.0)
163 bgp_damp_info_free (bdi, 1);
164 else
165 BGP_DAMP_LIST_ADD (damp, bdi);
166 }
167 else
168 /* Re-insert into another list (See RFC2439 Section 4.8.6). */
169 bgp_reuse_list_add (bdi);
170 }
171
172 return 0;
173}
174
175/* A route becomes unreachable (RFC2439 Section 4.8.2). */
176int
177bgp_damp_withdraw (struct bgp_info *binfo, struct bgp_node *rn,
178 afi_t afi, safi_t safi, int attr_change)
179{
180 time_t t_now;
181 struct bgp_damp_info *bdi;
182 double last_penalty = 0;
183
184 t_now = time (NULL);
185
186 /* Processing Unreachable Messages. */
187 bdi = binfo->damp_info;
188
189 if (bdi == NULL)
190 {
191 /* If there is no previous stability history. */
192
193 /* RFC2439 said:
194 1. allocate a damping structure.
195 2. set figure-of-merit = 1.
196 3. withdraw the route. */
197
198 bdi = XCALLOC (MTYPE_BGP_DAMP_INFO, sizeof (struct bgp_damp_info));
199 bdi->binfo = binfo;
200 bdi->rn = rn;
201 bdi->penalty = (attr_change ? DEFAULT_PENALTY / 2 : DEFAULT_PENALTY);
202 bdi->flap = 1;
203 bdi->start_time = t_now;
204 bdi->suppress_time = 0;
205 bdi->index = -1;
206 bdi->afi = afi;
207 bdi->safi = safi;
208 binfo->damp_info = bdi;
209 BGP_DAMP_LIST_ADD (damp, bdi);
210 }
211 else
212 {
213 last_penalty = bdi->penalty;
214
215 /* 1. Set t-diff = t-now - t-updated. */
216 bdi->penalty =
217 (bgp_damp_decay (t_now - bdi->t_updated, bdi->penalty)
218 + (attr_change ? DEFAULT_PENALTY / 2 : DEFAULT_PENALTY));
219
220 if (bdi->penalty > damp->ceiling)
221 bdi->penalty = damp->ceiling;
222
223 bdi->flap++;
224 }
225
226 bdi->lastrecord = BGP_RECORD_WITHDRAW;
227 bdi->t_updated = t_now;
228
229 /* Make this route as historical status. */
230 SET_FLAG (binfo->flags, BGP_INFO_HISTORY);
231
232 /* Remove the route from a reuse list if it is on one. */
233 if (CHECK_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED))
234 {
235 /* If decay rate isn't equal to 0, reinsert brn. */
236 if (bdi->penalty != last_penalty)
237 {
238 bgp_reuse_list_delete (bdi);
239 bgp_reuse_list_add (bdi);
240 }
241 return BGP_DAMP_SUPPRESSED;
242 }
243
244 /* If not suppressed before, do annonunce this withdraw and
245 insert into reuse_list. */
246 if (bdi->penalty >= damp->suppress_value)
247 {
248 SET_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED);
249 bdi->suppress_time = t_now;
250 BGP_DAMP_LIST_DEL (damp, bdi);
251 bgp_reuse_list_add (bdi);
252 }
253
254 return BGP_DAMP_USED;
255}
256
257int
258bgp_damp_update (struct bgp_info *binfo, struct bgp_node *rn,
259 afi_t afi, safi_t safi)
260{
261 time_t t_now;
262 struct bgp_damp_info *bdi;
263 int status;
264
265 bdi = binfo->damp_info;
266 if (! bdi)
267 return BGP_DAMP_USED;
268
269 t_now = time (NULL);
270 UNSET_FLAG (binfo->flags, BGP_INFO_HISTORY);
271
272 bdi->lastrecord = BGP_RECORD_UPDATE;
273 bdi->penalty = bgp_damp_decay (t_now - bdi->t_updated, bdi->penalty);
274
275 if (! CHECK_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED)
276 && (bdi->penalty < damp->suppress_value))
277 status = BGP_DAMP_USED;
278 else if (CHECK_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED)
279 && (bdi->penalty < damp->reuse_limit) )
280 {
281 UNSET_FLAG (bdi->binfo->flags, BGP_INFO_DAMPED);
282 bgp_reuse_list_delete (bdi);
283 BGP_DAMP_LIST_ADD (damp, bdi);
284 bdi->suppress_time = 0;
285 status = BGP_DAMP_USED;
286 }
287 else
288 status = BGP_DAMP_SUPPRESSED;
289
290 if (bdi->penalty > damp->reuse_limit / 2.0)
291 bdi->t_updated = t_now;
292 else
293 bgp_damp_info_free (bdi, 0);
294
295 return status;
296}
297
298/* Remove dampening information and history route. */
299int
300bgp_damp_scan (struct bgp_info *binfo, afi_t afi, safi_t safi)
301{
302 time_t t_now, t_diff;
303 struct bgp_damp_info *bdi;
304
305 t_now = time (NULL);
306 bdi = binfo->damp_info;
307
308 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
309 {
310 t_diff = t_now - bdi->suppress_time;
311
312 if (t_diff >= damp->max_suppress_time)
313 {
314 UNSET_FLAG (binfo->flags, BGP_INFO_DAMPED);
315 bgp_reuse_list_delete (bdi);
316 BGP_DAMP_LIST_ADD (damp, bdi);
317 bdi->penalty = damp->reuse_limit;
318 bdi->suppress_time = 0;
319 bdi->t_updated = t_now;
320
321 /* Need to announce UPDATE once this binfo is usable again. */
322 if (bdi->lastrecord == BGP_RECORD_UPDATE)
323 return 1;
324 else
325 return 0;
326 }
327 }
328 else
329 {
330 t_diff = t_now - bdi->t_updated;
331 bdi->penalty = bgp_damp_decay (t_diff, bdi->penalty);
332
333 if (bdi->penalty <= damp->reuse_limit / 2.0)
334 {
335 /* release the bdi, bdi->binfo. */
336 bgp_damp_info_free (bdi, 1);
337 return 0;
338 }
339 else
340 bdi->t_updated = t_now;
341 }
342 return 0;
343}
344
345void
346bgp_damp_info_free (struct bgp_damp_info *bdi, int withdraw)
347{
348 struct bgp_info *binfo;
paul718e3742002-12-13 20:15:29 +0000349
350 if (! bdi)
351 return;
352
353 binfo = bdi->binfo;
354 binfo->damp_info = NULL;
355
356 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
357 bgp_reuse_list_delete (bdi);
358 else
359 BGP_DAMP_LIST_DEL (damp, bdi);
360
361 UNSET_FLAG (binfo->flags, BGP_INFO_DAMPED);
362 UNSET_FLAG (binfo->flags, BGP_INFO_HISTORY);
363
364 if (bdi->lastrecord == BGP_RECORD_WITHDRAW && withdraw)
paul200df112005-06-01 11:17:05 +0000365 bgp_info_delete (bdi->rn, binfo);
366
paul718e3742002-12-13 20:15:29 +0000367 XFREE (MTYPE_BGP_DAMP_INFO, bdi);
368}
369
paul94f2b392005-06-28 12:44:16 +0000370static void
paul718e3742002-12-13 20:15:29 +0000371bgp_damp_parameter_set (int hlife, int reuse, int sup, int maxsup)
372{
373 double reuse_max_ratio;
paulfd79ac92004-10-13 05:06:08 +0000374 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000375 double j;
376
377 damp->suppress_value = sup;
378 damp->half_life = hlife;
379 damp->reuse_limit = reuse;
380 damp->max_suppress_time = maxsup;
381
382 /* Initialize params per bgp_damp_config. */
383 damp->reuse_index_size = REUSE_ARRAY_SIZE;
384
385 damp->ceiling = (int)(damp->reuse_limit * (pow(2, (double)damp->max_suppress_time/damp->half_life)));
386
387 /* Decay-array computations */
388 damp->decay_array_size = ceil ((double) damp->max_suppress_time / DELTA_T);
389 damp->decay_array = XMALLOC (MTYPE_BGP_DAMP_ARRAY,
390 sizeof(double) * (damp->decay_array_size));
391 damp->decay_array[0] = 1.0;
392 damp->decay_array[1] = exp ((1.0/((double)damp->half_life/DELTA_T)) * log(0.5));
393
394 /* Calculate decay values for all possible times */
395 for (i = 2; i < damp->decay_array_size; i++)
396 damp->decay_array[i] = damp->decay_array[i-1] * damp->decay_array[1];
397
398 /* Reuse-list computations */
399 i = ceil ((double)damp->max_suppress_time / DELTA_REUSE) + 1;
400 if (i > REUSE_LIST_SIZE || i == 0)
401 i = REUSE_LIST_SIZE;
402 damp->reuse_list_size = i;
403
404 damp->reuse_list = XCALLOC (MTYPE_BGP_DAMP_ARRAY,
405 damp->reuse_list_size
406 * sizeof (struct bgp_reuse_node *));
407 memset (damp->reuse_list, 0x00,
408 damp->reuse_list_size * sizeof (struct bgp_reuse_node *));
409
410 /* Reuse-array computations */
411 damp->reuse_index = XMALLOC (MTYPE_BGP_DAMP_ARRAY,
412 sizeof(int) * damp->reuse_index_size);
413 memset (damp->reuse_index, 0x00,
414 damp->reuse_list_size * sizeof (int));
415
416 reuse_max_ratio = (double)damp->ceiling/damp->reuse_limit;
417 j = (exp((double)damp->max_suppress_time/damp->half_life) * log10(2.0));
418 if ( reuse_max_ratio > j && j != 0 )
419 reuse_max_ratio = j;
420
421 damp->scale_factor = (double)damp->reuse_index_size/(reuse_max_ratio - 1);
422
423 for (i = 0; i < damp->reuse_index_size; i++)
424 {
425 damp->reuse_index[i] =
426 (int)(((double)damp->half_life / DELTA_REUSE)
427 * log10 (1.0 / (damp->reuse_limit * ( 1.0 + ((double)i/damp->scale_factor)))) / log10(0.5));
428 }
429}
430
431int
paulfd79ac92004-10-13 05:06:08 +0000432bgp_damp_enable (struct bgp *bgp, afi_t afi, safi_t safi, time_t half,
433 unsigned int reuse, unsigned int suppress, time_t max)
paul718e3742002-12-13 20:15:29 +0000434{
435 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING))
436 {
437 if (damp->half_life == half
438 && damp->reuse_limit == reuse
439 && damp->suppress_value == suppress
440 && damp->max_suppress_time == max)
441 return 0;
442 bgp_damp_disable (bgp, afi, safi);
443 }
444
445 SET_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING);
446 bgp_damp_parameter_set (half, reuse, suppress, max);
447
448 /* Register reuse timer. */
449 if (! damp->t_reuse)
450 damp->t_reuse =
451 thread_add_timer (master, bgp_reuse_timer, NULL, DELTA_REUSE);
452
453 return 0;
454}
455
paul94f2b392005-06-28 12:44:16 +0000456static void
paul718e3742002-12-13 20:15:29 +0000457bgp_damp_config_clean (struct bgp_damp_config *damp)
458{
459 /* Free decay array */
460 XFREE (MTYPE_BGP_DAMP_ARRAY, damp->decay_array);
461
462 /* Free reuse index array */
463 XFREE (MTYPE_BGP_DAMP_ARRAY, damp->reuse_index);
464
465 /* Free reuse list array. */
466 XFREE (MTYPE_BGP_DAMP_ARRAY, damp->reuse_list);
467}
468
469/* Clean all the bgp_damp_info stored in reuse_list. */
470void
paul94f2b392005-06-28 12:44:16 +0000471bgp_damp_info_clean (void)
paul718e3742002-12-13 20:15:29 +0000472{
paulfd79ac92004-10-13 05:06:08 +0000473 unsigned int i;
paul718e3742002-12-13 20:15:29 +0000474 struct bgp_damp_info *bdi, *next;
475
476 damp->reuse_offset = 0;
477
478 for (i = 0; i < damp->reuse_list_size; i++)
479 {
480 if (! damp->reuse_list[i])
481 continue;
482
483 for (bdi = damp->reuse_list[i]; bdi; bdi = next)
484 {
485 next = bdi->next;
486 bgp_damp_info_free (bdi, 1);
487 }
488 damp->reuse_list[i] = NULL;
489 }
490
491 for (bdi = damp->no_reuse_list; bdi; bdi = next)
492 {
493 next = bdi->next;
494 bgp_damp_info_free (bdi, 1);
495 }
496 damp->no_reuse_list = NULL;
497}
498
499int
500bgp_damp_disable (struct bgp *bgp, afi_t afi, safi_t safi)
501{
502 /* Cancel reuse thread. */
503 if (damp->t_reuse )
504 thread_cancel (damp->t_reuse);
505 damp->t_reuse = NULL;
506
507 /* Clean BGP dampening information. */
508 bgp_damp_info_clean ();
509
510 /* Clear configuration */
511 bgp_damp_config_clean (&bgp_damp_cfg);
512
513 UNSET_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING);
514 return 0;
515}
516
517int
518bgp_config_write_damp (struct vty *vty)
519{
520 if (&bgp_damp_cfg)
521 {
522 if (bgp_damp_cfg.half_life == DEFAULT_HALF_LIFE*60
523 && bgp_damp_cfg.reuse_limit == DEFAULT_REUSE
524 && bgp_damp_cfg.suppress_value == DEFAULT_SUPPRESS
525 && bgp_damp_cfg.max_suppress_time == bgp_damp_cfg.half_life*4)
526 vty_out (vty, " bgp dampening%s", VTY_NEWLINE);
527 else if (bgp_damp_cfg.half_life != DEFAULT_HALF_LIFE*60
528 && bgp_damp_cfg.reuse_limit == DEFAULT_REUSE
529 && bgp_damp_cfg.suppress_value == DEFAULT_SUPPRESS
530 && bgp_damp_cfg.max_suppress_time == bgp_damp_cfg.half_life*4)
paulfd79ac92004-10-13 05:06:08 +0000531 vty_out (vty, " bgp dampening %ld%s",
paul718e3742002-12-13 20:15:29 +0000532 bgp_damp_cfg.half_life/60,
533 VTY_NEWLINE);
534 else
paulfd79ac92004-10-13 05:06:08 +0000535 vty_out (vty, " bgp dampening %ld %d %d %ld%s",
paul718e3742002-12-13 20:15:29 +0000536 bgp_damp_cfg.half_life/60,
537 bgp_damp_cfg.reuse_limit,
538 bgp_damp_cfg.suppress_value,
539 bgp_damp_cfg.max_suppress_time/60,
540 VTY_NEWLINE);
541 return 1;
542 }
543 return 0;
544}
545
546#define BGP_UPTIME_LEN 25
547
548char *
paulfd79ac92004-10-13 05:06:08 +0000549bgp_get_reuse_time (unsigned int penalty, char *buf, size_t len)
paul718e3742002-12-13 20:15:29 +0000550{
551 time_t reuse_time = 0;
552 struct tm *tm = NULL;
553
554 if (penalty > damp->reuse_limit)
555 {
556 reuse_time = (int) (DELTA_T * ((log((double)damp->reuse_limit/penalty))/(log(damp->decay_array[1]))));
557
558 if (reuse_time > damp->max_suppress_time)
559 reuse_time = damp->max_suppress_time;
560
561 tm = gmtime (&reuse_time);
562 }
563 else
564 reuse_time = 0;
565
566 /* Making formatted timer strings. */
567#define ONE_DAY_SECOND 60*60*24
568#define ONE_WEEK_SECOND 60*60*24*7
569 if (reuse_time == 0)
570 snprintf (buf, len, "00:00:00");
571 else if (reuse_time < ONE_DAY_SECOND)
572 snprintf (buf, len, "%02d:%02d:%02d",
573 tm->tm_hour, tm->tm_min, tm->tm_sec);
574 else if (reuse_time < ONE_WEEK_SECOND)
575 snprintf (buf, len, "%dd%02dh%02dm",
576 tm->tm_yday, tm->tm_hour, tm->tm_min);
577 else
578 snprintf (buf, len, "%02dw%dd%02dh",
579 tm->tm_yday/7, tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
580
581 return buf;
582}
583
584void
585bgp_damp_info_vty (struct vty *vty, struct bgp_info *binfo)
586{
587 struct bgp_damp_info *bdi;
588 time_t t_now, t_diff;
589 char timebuf[BGP_UPTIME_LEN];
590 int penalty;
591
592 /* BGP dampening information. */
593 bdi = binfo->damp_info;
594
595 /* If dampening is not enabled or there is no dampening information,
596 return immediately. */
597 if (! damp || ! bdi)
598 return;
599
600 /* Calculate new penalty. */
601 t_now = time (NULL);
602 t_diff = t_now - bdi->t_updated;
603 penalty = bgp_damp_decay (t_diff, bdi->penalty);
604
605 vty_out (vty, " Dampinfo: penalty %d, flapped %d times in %s",
606 penalty, bdi->flap,
607 peer_uptime (bdi->start_time, timebuf, BGP_UPTIME_LEN));
608
609 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
610 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
611 vty_out (vty, ", reuse in %s",
612 bgp_get_reuse_time (penalty, timebuf, BGP_UPTIME_LEN));
613
614 vty_out (vty, "%s", VTY_NEWLINE);
615}
616
617char *
618bgp_damp_reuse_time_vty (struct vty *vty, struct bgp_info *binfo)
619{
620 struct bgp_damp_info *bdi;
621 time_t t_now, t_diff;
622 char timebuf[BGP_UPTIME_LEN];
623 int penalty;
624
625 /* BGP dampening information. */
626 bdi = binfo->damp_info;
627
628 /* If dampening is not enabled or there is no dampening information,
629 return immediately. */
630 if (! damp || ! bdi)
631 return NULL;
632
633 /* Calculate new penalty. */
634 t_now = time (NULL);
635 t_diff = t_now - bdi->t_updated;
636 penalty = bgp_damp_decay (t_diff, bdi->penalty);
637
638 return bgp_get_reuse_time (penalty, timebuf, BGP_UPTIME_LEN);
639}