diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2009-12-09 17:28:48 +0000 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2010-02-04 22:37:31 +0100 |
commit | a8c48bb76f291c673438d2061753d05a0d9b3276 (patch) | |
tree | aa392be05e955ad5684f2d35463fd45380070780 | |
parent | 6c9463d3f240f79fd46665c3b21e5152e51804f5 (diff) | |
download | quagga-a8c48bb76f291c673438d2061753d05a0d9b3276.tar.bz2 quagga-a8c48bb76f291c673438d2061753d05a0d9b3276.tar.xz |
bgp: move cleanup fifo code
This patch started while looking at the compiler aliasing warnings
from FIFO_HEAD() in BGP. Then I realized the FIFO code was only
being used in BGP, so it made sense to move it from zebra to
BGP. In the process convert from macro's to inline and add more
type safety.
-rw-r--r-- | bgpd/bgp_advertise.c | 4 | ||||
-rw-r--r-- | bgpd/bgp_advertise.h | 32 | ||||
-rw-r--r-- | lib/zebra.h | 39 |
3 files changed, 34 insertions, 41 deletions
diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c index 87eb7ac7..4163ab96 100644 --- a/bgpd/bgp_advertise.c +++ b/bgpd/bgp_advertise.c @@ -263,7 +263,7 @@ bgp_adj_out_set (struct bgp_node *rn, struct peer *peer, struct prefix *p, /* Add new advertisement to advertisement attribute list. */ bgp_advertise_add (adv->baa, adv); - FIFO_ADD (&peer->sync[afi][safi]->update, &adv->fifo); + FIFO_ADD (&peer->sync[afi][safi]->update, adv); } void @@ -297,7 +297,7 @@ bgp_adj_out_unset (struct bgp_node *rn, struct peer *peer, struct prefix *p, adv->adj = adj; /* Add to synchronization entry for withdraw announcement. */ - FIFO_ADD (&peer->sync[afi][safi]->withdraw, &adv->fifo); + FIFO_ADD (&peer->sync[afi][safi]->withdraw, adv); /* Schedule packet write. */ BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd); diff --git a/bgpd/bgp_advertise.h b/bgpd/bgp_advertise.h index 4ebde907..53427eb3 100644 --- a/bgpd/bgp_advertise.h +++ b/bgpd/bgp_advertise.h @@ -102,6 +102,38 @@ struct bgp_synchronize struct bgp_advertise_fifo withdraw_low; }; +static inline void FIFO_INIT(struct bgp_advertise_fifo *fifo) +{ + fifo->next = fifo->prev = (struct bgp_advertise *) fifo; +} + +static inline void FIFO_ADD(struct bgp_advertise_fifo *fifo, + struct bgp_advertise *node) +{ + node->fifo.next = (struct bgp_advertise *) fifo; + node->fifo.prev = fifo->prev; + fifo->prev = fifo->prev->next = node; +} + +static inline void FIFO_DEL(struct bgp_advertise *node) +{ + struct bgp_advertise_fifo *fifo = &node->fifo; + + fifo->prev->next = fifo->next; + fifo->next->prev = fifo->prev; +} + +static inline int FIFO_EMPTY(const struct bgp_advertise_fifo *fifo) +{ + return (fifo->next == (const struct bgp_advertise *) fifo); +} + +static inline struct bgp_advertise *FIFO_HEAD(struct bgp_advertise_fifo *fifo) +{ + return FIFO_EMPTY(fifo) ? NULL : fifo->next; +} + + /* BGP adjacency linked list. */ #define BGP_INFO_ADD(N,A,TYPE) \ do { \ diff --git a/lib/zebra.h b/lib/zebra.h index 2dc84514..5d863599 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -538,43 +538,4 @@ typedef u_int8_t safi_t; typedef u_int16_t zebra_size_t; typedef u_int16_t zebra_command_t; -/* FIFO -- first in first out structure and macros. */ -struct fifo -{ - struct fifo *next; - struct fifo *prev; -}; - -#define FIFO_INIT(F) \ - do { \ - struct fifo *Xfifo = (struct fifo *)(F); \ - Xfifo->next = Xfifo->prev = Xfifo; \ - } while (0) - -#define FIFO_ADD(F,N) \ - do { \ - struct fifo *Xfifo = (struct fifo *)(F); \ - struct fifo *Xnode = (struct fifo *)(N); \ - Xnode->next = Xfifo; \ - Xnode->prev = Xfifo->prev; \ - Xfifo->prev = Xfifo->prev->next = Xnode; \ - } while (0) - -#define FIFO_DEL(N) \ - do { \ - struct fifo *Xnode = (struct fifo *)(N); \ - Xnode->prev->next = Xnode->next; \ - Xnode->next->prev = Xnode->prev; \ - } while (0) - -#define FIFO_HEAD(F) \ - ((((struct fifo *)(F))->next == (struct fifo *)(F)) \ - ? NULL : (F)->next) - -#define FIFO_EMPTY(F) \ - (((struct fifo *)(F))->next == (struct fifo *)(F)) - -#define FIFO_TOP(F) \ - (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next) - #endif /* _ZEBRA_H */ |