Annotation of embedaddon/quagga/bgpd/bgp_table.h, revision 1.1.1.2

1.1       misho       1: /* BGP routing table
                      2:    Copyright (C) 1998, 2001 Kunihiro Ishiguro
                      3: 
                      4: This file is part of GNU Zebra.
                      5: 
                      6: GNU Zebra is free software; you can redistribute it and/or modify it
                      7: under the terms of the GNU General Public License as published by the
                      8: Free Software Foundation; either version 2, or (at your option) any
                      9: later version.
                     10: 
                     11: GNU Zebra is distributed in the hope that it will be useful, but
                     12: WITHOUT ANY WARRANTY; without even the implied warranty of
                     13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     14: General Public License for more details.
                     15: 
                     16: You should have received a copy of the GNU General Public License
                     17: along with GNU Zebra; see the file COPYING.  If not, write to the Free
                     18: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
                     19: 02111-1307, USA.  */
                     20: 
                     21: #ifndef _QUAGGA_BGP_TABLE_H
                     22: #define _QUAGGA_BGP_TABLE_H
                     23: 
1.1.1.2 ! misho      24: #include "table.h"
        !            25: 
1.1       misho      26: typedef enum
                     27: {
                     28:   BGP_TABLE_MAIN,
                     29:   BGP_TABLE_RSCLIENT,
                     30: } bgp_table_t;
                     31: 
                     32: struct bgp_table
                     33: {
                     34:   bgp_table_t type;
                     35:   
                     36:   /* afi/safi of this table */
                     37:   afi_t afi;
                     38:   safi_t safi;
                     39:   
                     40:   int lock;
                     41: 
                     42:   /* The owner of this 'bgp_table' structure. */
                     43:   struct peer *owner;
                     44: 
1.1.1.2 ! misho      45:   struct route_table *route_table;
1.1       misho      46: };
                     47: 
                     48: struct bgp_node
                     49: {
1.1.1.2 ! misho      50:   /*
        !            51:    * CAUTION
        !            52:    *
        !            53:    * These fields must be the very first fields in this structure.
        !            54:    *
        !            55:    * @see bgp_node_to_rnode
        !            56:    * @see bgp_node_from_rnode
        !            57:    */
        !            58:   ROUTE_NODE_FIELDS;
1.1       misho      59: 
                     60:   struct bgp_adj_out *adj_out;
                     61: 
                     62:   struct bgp_adj_in *adj_in;
                     63: 
                     64:   struct bgp_node *prn;
                     65: 
                     66:   u_char flags;
                     67: #define BGP_NODE_PROCESS_SCHEDULED     (1 << 0)
                     68: };
                     69: 
1.1.1.2 ! misho      70: /*
        !            71:  * bgp_table_iter_t
        !            72:  * 
        !            73:  * Structure that holds state for iterating over a bgp table.
        !            74:  */
        !            75: typedef struct bgp_table_iter_t_
        !            76: {
        !            77:   struct bgp_table *table;
        !            78:   route_table_iter_t rt_iter;
        !            79: } bgp_table_iter_t;
        !            80: 
1.1       misho      81: extern struct bgp_table *bgp_table_init (afi_t, safi_t);
                     82: extern void bgp_table_lock (struct bgp_table *);
                     83: extern void bgp_table_unlock (struct bgp_table *);
                     84: extern void bgp_table_finish (struct bgp_table **);
1.1.1.2 ! misho      85: 
        !            86: 
        !            87: /*
        !            88:  * bgp_node_from_rnode
        !            89:  *
        !            90:  * Returns the bgp_node structure corresponding to a route_node.
        !            91:  */
        !            92: static inline struct bgp_node *
        !            93: bgp_node_from_rnode (struct route_node *rnode)
        !            94: {
        !            95:   return (struct bgp_node *) rnode;
        !            96: }
        !            97: 
        !            98: /*
        !            99:  * bgp_node_to_rnode
        !           100:  *
        !           101:  * Returns the route_node structure corresponding to a bgp_node.
        !           102:  */
        !           103: static inline struct route_node *
        !           104: bgp_node_to_rnode (struct bgp_node *node)
        !           105: {
        !           106:   return (struct route_node *) node;
        !           107: }
        !           108: 
        !           109: /*
        !           110:  * bgp_node_table
        !           111:  *
        !           112:  * Returns the bgp_table that the given node is in.
        !           113:  */
        !           114: static inline struct bgp_table *
        !           115: bgp_node_table (struct bgp_node *node)
        !           116: {
        !           117:   return bgp_node_to_rnode (node)->table->info;
        !           118: }
        !           119: 
        !           120: /*
        !           121:  * bgp_node_info
        !           122:  *
        !           123:  * Returns the 'info' pointer corresponding to a bgp node.
        !           124:  */
        !           125: static inline void *
        !           126: bgp_node_info (const struct bgp_node *node)
        !           127: {
        !           128:   return node->info;
        !           129: }
        !           130: 
        !           131: /*
        !           132:  * bgp_node_set_info
        !           133:  */
        !           134: static inline void
        !           135: bgp_node_set_info (struct bgp_node *node, void *info)
        !           136: {
        !           137:   node->info = info;
        !           138: }
        !           139: 
        !           140: /*
        !           141:  * bgp_node_prefix
        !           142:  */
        !           143: static inline struct prefix *
        !           144: bgp_node_prefix (struct bgp_node *node)
        !           145: {
        !           146:   return &node->p;
        !           147: }
        !           148: 
        !           149: /*
        !           150:  * bgp_node_prefixlen
        !           151:  */
        !           152: static inline u_char
        !           153: bgp_node_prefixlen (struct bgp_node *node)
        !           154: {
        !           155:   return bgp_node_prefix (node)->prefixlen;
        !           156: }
        !           157: 
        !           158: /*
        !           159:  * bgp_node_parent_nolock
        !           160:  *
        !           161:  * Gets the parent node of the given node without locking it.
        !           162:  */
        !           163: static inline struct bgp_node *
        !           164: bgp_node_parent_nolock (struct bgp_node *node)
        !           165: {
        !           166:   return bgp_node_from_rnode (node->parent);
        !           167: }
        !           168: 
        !           169: /*
        !           170:  * bgp_unlock_node
        !           171:  */
        !           172: static inline void
        !           173: bgp_unlock_node (struct bgp_node *node)
        !           174: {
        !           175:   route_unlock_node (bgp_node_to_rnode (node));
        !           176: }
        !           177: 
        !           178: /*
        !           179:  * bgp_table_top_nolock
        !           180:  *
        !           181:  * Gets the top node in the table without locking it.
        !           182:  *
        !           183:  * @see bgp_table_top
        !           184:  */
        !           185: static inline struct bgp_node *
        !           186: bgp_table_top_nolock (const struct bgp_table *const table)
        !           187: {
        !           188:   return bgp_node_from_rnode (table->route_table->top);
        !           189: }
        !           190: 
        !           191: /*
        !           192:  * bgp_table_top
        !           193:  */
        !           194: static inline struct bgp_node *
        !           195: bgp_table_top (const struct bgp_table *const table)
        !           196: {
        !           197:   return bgp_node_from_rnode (route_top (table->route_table));
        !           198: }
        !           199: 
        !           200: /*
        !           201:  * bgp_route_next
        !           202:  */
        !           203: static inline struct bgp_node *
        !           204: bgp_route_next (struct bgp_node *node)
        !           205: {
        !           206:   return bgp_node_from_rnode (route_next (bgp_node_to_rnode (node)));
        !           207: }
        !           208: 
        !           209: /*
        !           210:  * bgp_route_next_until
        !           211:  */
        !           212: static inline struct bgp_node *
        !           213: bgp_route_next_until (struct bgp_node *node, struct bgp_node *limit)
        !           214: {
        !           215:   struct route_node *rnode;
        !           216: 
        !           217:   rnode = route_next_until (bgp_node_to_rnode (node),
        !           218:                            bgp_node_to_rnode (limit));
        !           219:   return bgp_node_from_rnode (rnode);
        !           220: }
        !           221: 
        !           222: /*
        !           223:  * bgp_node_get
        !           224:  */
        !           225: static inline struct bgp_node *
        !           226: bgp_node_get (struct bgp_table *const table, struct prefix *p)
        !           227: {
        !           228:   return bgp_node_from_rnode (route_node_get (table->route_table, p));
        !           229: }
        !           230: 
        !           231: /*
        !           232:  * bgp_node_lookup
        !           233:  */
        !           234: static inline struct bgp_node *
        !           235: bgp_node_lookup (const struct bgp_table *const table, struct prefix *p)
        !           236: {
        !           237:   return bgp_node_from_rnode (route_node_lookup (table->route_table, p));
        !           238: }
        !           239: 
        !           240: /*
        !           241:  * bgp_lock_node
        !           242:  */
        !           243: static inline struct bgp_node *
        !           244: bgp_lock_node (struct bgp_node *node)
        !           245: {
        !           246:   return bgp_node_from_rnode (route_lock_node (bgp_node_to_rnode (node)));
        !           247: }
        !           248: 
        !           249: /*
        !           250:  * bgp_node_match
        !           251:  */
        !           252: static inline struct bgp_node *
        !           253: bgp_node_match (const struct bgp_table *table, struct prefix *p)
        !           254: {
        !           255:   return bgp_node_from_rnode (route_node_match (table->route_table, p));
        !           256: }
        !           257: 
        !           258: /*
        !           259:  * bgp_node_match_ipv4
        !           260:  */
        !           261: static inline struct bgp_node *
        !           262: bgp_node_match_ipv4 (const struct bgp_table *table, struct in_addr *addr)
        !           263: {
        !           264:   return bgp_node_from_rnode (route_node_match_ipv4 (table->route_table, 
        !           265:                                                     addr));
        !           266: }
        !           267: 
1.1       misho     268: #ifdef HAVE_IPV6
1.1.1.2 ! misho     269: 
        !           270: /*
        !           271:  * bgp_node_match_ipv6
        !           272:  */
        !           273: static inline struct bgp_node *
        !           274: bgp_node_match_ipv6 (const struct bgp_table *table, struct in6_addr *addr)
        !           275: {
        !           276:   return bgp_node_from_rnode (route_node_match_ipv6 (table->route_table,
        !           277:                                                     addr));
        !           278: }
        !           279: 
1.1       misho     280: #endif /* HAVE_IPV6 */
1.1.1.2 ! misho     281: 
        !           282: static inline unsigned long
        !           283: bgp_table_count (const struct bgp_table *const table)
        !           284: {
        !           285:   return route_table_count (table->route_table);
        !           286: }
        !           287: 
        !           288: /*
        !           289:  * bgp_table_get_next
        !           290:  */
        !           291: static inline struct bgp_node *
        !           292: bgp_table_get_next (const struct bgp_table *table, struct prefix *p)
        !           293: {
        !           294:   return bgp_node_from_rnode (route_table_get_next (table->route_table, p));
        !           295: }
        !           296: 
        !           297: /*
        !           298:  * bgp_table_iter_init
        !           299:  */
        !           300: static inline void
        !           301: bgp_table_iter_init (bgp_table_iter_t * iter, struct bgp_table *table)
        !           302: {
        !           303:   bgp_table_lock (table);
        !           304:   iter->table = table;
        !           305:   route_table_iter_init (&iter->rt_iter, table->route_table);
        !           306: }
        !           307: 
        !           308: /*
        !           309:  * bgp_table_iter_next
        !           310:  */
        !           311: static inline struct bgp_node *
        !           312: bgp_table_iter_next (bgp_table_iter_t * iter)
        !           313: {
        !           314:   return bgp_node_from_rnode (route_table_iter_next (&iter->rt_iter));
        !           315: }
        !           316: 
        !           317: /*
        !           318:  * bgp_table_iter_cleanup
        !           319:  */
        !           320: static inline void
        !           321: bgp_table_iter_cleanup (bgp_table_iter_t * iter)
        !           322: {
        !           323:   route_table_iter_cleanup (&iter->rt_iter);
        !           324:   bgp_table_unlock (iter->table);
        !           325:   iter->table = NULL;
        !           326: }
        !           327: 
        !           328: /*
        !           329:  * bgp_table_iter_pause
        !           330:  */
        !           331: static inline void
        !           332: bgp_table_iter_pause (bgp_table_iter_t * iter)
        !           333: {
        !           334:   route_table_iter_pause (&iter->rt_iter);
        !           335: }
        !           336: 
        !           337: /*
        !           338:  * bgp_table_iter_is_done
        !           339:  */
        !           340: static inline int
        !           341: bgp_table_iter_is_done (bgp_table_iter_t * iter)
        !           342: {
        !           343:   return route_table_iter_is_done (&iter->rt_iter);
        !           344: }
        !           345: 
        !           346: /*
        !           347:  * bgp_table_iter_started
        !           348:  */
        !           349: static inline int
        !           350: bgp_table_iter_started (bgp_table_iter_t * iter)
        !           351: {
        !           352:   return route_table_iter_started (&iter->rt_iter);
        !           353: }
        !           354: 
1.1       misho     355: #endif /* _QUAGGA_BGP_TABLE_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>