diff options
author | Michele Marchetto <michele@cvs.openbsd.org> | 2007-01-23 21:10:11 +0000 |
---|---|---|
committer | Michele Marchetto <michele@cvs.openbsd.org> | 2007-01-23 21:10:11 +0000 |
commit | d32d3d661b007876e0d8111712385b825cb978e6 (patch) | |
tree | 5f6d1b8c565076d44443fca69c35e4225351586c /usr.sbin | |
parent | 66fbffdbdb7a0e663d3f24b9e097784b056370da (diff) |
add timeout for failed nbr structures
OK claudio@ henning@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ripd/neighbor.c | 69 | ||||
-rw-r--r-- | usr.sbin/ripd/packet.c | 4 | ||||
-rw-r--r-- | usr.sbin/ripd/rip.h | 3 | ||||
-rw-r--r-- | usr.sbin/ripd/ripe.h | 7 |
4 files changed, 59 insertions, 24 deletions
diff --git a/usr.sbin/ripd/neighbor.c b/usr.sbin/ripd/neighbor.c index 5a6a074245c..0d8d262ecc8 100644 --- a/usr.sbin/ripd/neighbor.c +++ b/usr.sbin/ripd/neighbor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: neighbor.c,v 1.5 2006/12/24 15:56:28 michele Exp $ */ +/* $OpenBSD: neighbor.c,v 1.6 2007/01/23 21:10:10 michele Exp $ */ /* * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> @@ -42,6 +42,10 @@ void nbr_set_timer(struct nbr *); void nbr_stop_timer(struct nbr *); +void nbr_failed_new(struct nbr *); +void nbr_failed_timeout(int, short, void *); +void nbr_failed_stop_timer(struct nbr_failed *); + LIST_HEAD(nbr_head, nbr); struct nbr_table { @@ -67,7 +71,7 @@ struct { {NBR_STA_ACTIVE, NBR_EVT_REQUEST_RCVD, NBR_ACT_NOTHING, NBR_STA_ACTIVE}, {NBR_STA_ACTIVE, NBR_EVT_TIMEOUT, NBR_ACT_DEL, NBR_STA_DOWN}, {NBR_STA_REQ_RCVD, NBR_EVT_RESPONSE_SENT, NBR_ACT_DEL, NBR_STA_DOWN}, - {NBR_STA_ACTIVE, NBR_EVT_RESPONSE_SENT, NBR_ACT_NOTHING, NBR_STA_ACTIVE}, + {NBR_STA_ACTIVE, NBR_EVT_RESPONSE_SENT, NBR_ACT_NOTHING, NBR_STA_ACTIVE}, {NBR_STA_ANY, NBR_EVT_KILL_NBR, NBR_ACT_DEL, NBR_STA_DOWN}, {-1, NBR_EVT_NOTHING, NBR_ACT_NOTHING, 0}, }; @@ -202,22 +206,11 @@ nbr_new(u_int32_t nbr_id, struct iface *iface, int self) void nbr_act_del(struct nbr *nbr) { - struct nbr_failed *nbr_failed; - struct iface *iface; - /* If there is no authentication or it is just a route request * there is no need to keep track of the failed neighbors */ if (nbr->iface->auth_type == AUTH_CRYPT && - nbr->state != NBR_STA_REQ_RCVD) { - if ((nbr_failed = calloc(1, sizeof(*nbr_failed))) == NULL) - fatal("nbr_act_del"); - - nbr_failed->addr = nbr->addr; - nbr_failed->auth_seq_num = nbr->auth_seq_num; - iface = nbr->iface; - LIST_INSERT_HEAD(&iface->failed_nbr_list, - nbr_failed, entry); - } + nbr->state != NBR_STA_REQ_RCVD) + nbr_failed_new(nbr); log_debug("nbr_del: neighbor ID %s, peerid %lu", inet_ntoa(nbr->id), nbr->peerid); @@ -265,6 +258,33 @@ nbr_find_ip(struct iface *iface, u_int32_t src_ip) return (NULL); } +/* failed nbr handling */ +void +nbr_failed_new(struct nbr *nbr) +{ + struct timeval tv; + struct iface *iface; + struct nbr_failed *nbr_failed; + + if ((nbr_failed = calloc(1, sizeof(*nbr_failed))) == NULL) + fatal("nbr_failed_new"); + + nbr_failed->addr = nbr->addr; + nbr_failed->auth_seq_num = nbr->auth_seq_num; + iface = nbr->iface; + + timerclear(&tv); + tv.tv_sec = FAILED_NBR_TIMEOUT; + + evtimer_set(&nbr_failed->timeout_timer, nbr_failed_timeout, + nbr_failed); + + if (evtimer_add(&nbr_failed->timeout_timer, &tv) == -1) + fatal("nbr_failed_new"); + + LIST_INSERT_HEAD(&iface->failed_nbr_list, nbr_failed, entry); +} + struct nbr_failed * nbr_failed_find(struct iface *iface, u_int32_t src_ip) { @@ -280,10 +300,13 @@ nbr_failed_find(struct iface *iface, u_int32_t src_ip) } void -nbr_failed_delete(struct iface *iface, struct nbr_failed *nbr_failed) +nbr_failed_delete(struct nbr_failed *nbr_failed) { - LIST_REMOVE(nbr_failed, entry); + if (evtimer_pending(&nbr_failed->timeout_timer, NULL)) + if (evtimer_del(&nbr_failed->timeout_timer) == -1) + fatal("nbr_failed_delete"); + LIST_REMOVE(nbr_failed, entry); free(nbr_failed); } @@ -297,6 +320,18 @@ nbr_timeout_timer(int fd, short event, void *arg) nbr_fsm(nbr, NBR_EVT_TIMEOUT); } +/* ARGSUSED */ +void +nbr_failed_timeout(int fd, short event, void *arg) +{ + struct nbr_failed *nbr_failed = arg; + + log_debug("nbr_failed_timeout: failed neighbor ID %s deleted", + inet_ntoa(nbr_failed->addr)); + + nbr_failed_delete(nbr_failed); +} + /* actions */ void nbr_set_timer(struct nbr *nbr) diff --git a/usr.sbin/ripd/packet.c b/usr.sbin/ripd/packet.c index e39bc20dae0..6639b96a849 100644 --- a/usr.sbin/ripd/packet.c +++ b/usr.sbin/ripd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.4 2006/10/31 23:43:11 michele Exp $ */ +/* $OpenBSD: packet.c,v 1.5 2007/01/23 21:10:10 michele Exp $ */ /* * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> @@ -197,7 +197,7 @@ recv_packet(int fd, short event, void *bula) if (nbr == NULL) { nbr = nbr_new(src.sin_addr.s_addr, iface, 0); if (nbr_failed != NULL) - nbr_failed_delete(iface, nbr_failed); + nbr_failed_delete(nbr_failed); nbr->addr = src.sin_addr; } nbr->auth_seq_num = auth_crypt_num; diff --git a/usr.sbin/ripd/rip.h b/usr.sbin/ripd/rip.h index a32125ff255..2eea491fa2b 100644 --- a/usr.sbin/ripd/rip.h +++ b/usr.sbin/ripd/rip.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rip.h,v 1.2 2007/01/15 18:23:43 michele Exp $ */ +/* $OpenBSD: rip.h,v 1.3 2007/01/23 21:10:10 michele Exp $ */ /* * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> @@ -36,6 +36,7 @@ /* timers */ #define KEEPALIVE 30 #define OFFSET 10 +#define FAILED_NBR_TIMEOUT 86400 #define MAX_RIP_ENTRIES 25 diff --git a/usr.sbin/ripd/ripe.h b/usr.sbin/ripd/ripe.h index 6e46a94add4..acc3cd8b6a1 100644 --- a/usr.sbin/ripd/ripe.h +++ b/usr.sbin/ripd/ripe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ripe.h,v 1.3 2006/11/10 10:28:18 michele Exp $ */ +/* $OpenBSD: ripe.h,v 1.4 2007/01/23 21:10:10 michele Exp $ */ /* * Copyright (c) 2006 Michele Marchetto <mydecay@openbeer.it> @@ -48,6 +48,7 @@ enum nbr_action { }; struct nbr_failed { + struct event timeout_timer; LIST_ENTRY(nbr_failed) entry; struct in_addr addr; u_int32_t auth_seq_num; @@ -132,12 +133,10 @@ void nbr_act_del(struct nbr *); struct nbr *nbr_find_ip(struct iface *, u_int32_t); struct nbr *nbr_find_peerid(u_int32_t); struct nbr_failed *nbr_failed_find(struct iface *, u_int32_t); -void nbr_failed_delete(struct iface *, struct nbr_failed *); +void nbr_failed_delete(struct nbr_failed *); int nbr_fsm(struct nbr *, enum nbr_event); - void nbr_timeout_timer(int, short, void *); - void nbr_act_delete(struct nbr *); const char *nbr_event_name(int); |