File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / quagga / bgpd / bgp_table.h
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Nov 2 10:09:10 2016 UTC (7 years, 8 months ago) by misho
Branches: quagga, MAIN
CVS tags: v1_0_20160315, HEAD
quagga 1.0.20160315

    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: 
   24: #include "table.h"
   25: 
   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: 
   45:   struct route_table *route_table;
   46: };
   47: 
   48: struct bgp_node
   49: {
   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
   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: 
   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: 
   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 **);
   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: 
  268: /*
  269:  * bgp_node_match_ipv6
  270:  */
  271: static inline struct bgp_node *
  272: bgp_node_match_ipv6 (const struct bgp_table *table, struct in6_addr *addr)
  273: {
  274:   return bgp_node_from_rnode (route_node_match_ipv6 (table->route_table,
  275: 						     addr));
  276: }
  277: 
  278: static inline unsigned long
  279: bgp_table_count (const struct bgp_table *const table)
  280: {
  281:   return route_table_count (table->route_table);
  282: }
  283: 
  284: /*
  285:  * bgp_table_get_next
  286:  */
  287: static inline struct bgp_node *
  288: bgp_table_get_next (const struct bgp_table *table, struct prefix *p)
  289: {
  290:   return bgp_node_from_rnode (route_table_get_next (table->route_table, p));
  291: }
  292: 
  293: /*
  294:  * bgp_table_iter_init
  295:  */
  296: static inline void
  297: bgp_table_iter_init (bgp_table_iter_t * iter, struct bgp_table *table)
  298: {
  299:   bgp_table_lock (table);
  300:   iter->table = table;
  301:   route_table_iter_init (&iter->rt_iter, table->route_table);
  302: }
  303: 
  304: /*
  305:  * bgp_table_iter_next
  306:  */
  307: static inline struct bgp_node *
  308: bgp_table_iter_next (bgp_table_iter_t * iter)
  309: {
  310:   return bgp_node_from_rnode (route_table_iter_next (&iter->rt_iter));
  311: }
  312: 
  313: /*
  314:  * bgp_table_iter_cleanup
  315:  */
  316: static inline void
  317: bgp_table_iter_cleanup (bgp_table_iter_t * iter)
  318: {
  319:   route_table_iter_cleanup (&iter->rt_iter);
  320:   bgp_table_unlock (iter->table);
  321:   iter->table = NULL;
  322: }
  323: 
  324: /*
  325:  * bgp_table_iter_pause
  326:  */
  327: static inline void
  328: bgp_table_iter_pause (bgp_table_iter_t * iter)
  329: {
  330:   route_table_iter_pause (&iter->rt_iter);
  331: }
  332: 
  333: /*
  334:  * bgp_table_iter_is_done
  335:  */
  336: static inline int
  337: bgp_table_iter_is_done (bgp_table_iter_t * iter)
  338: {
  339:   return route_table_iter_is_done (&iter->rt_iter);
  340: }
  341: 
  342: /*
  343:  * bgp_table_iter_started
  344:  */
  345: static inline int
  346: bgp_table_iter_started (bgp_table_iter_t * iter)
  347: {
  348:   return route_table_iter_started (&iter->rt_iter);
  349: }
  350: 
  351: #endif /* _QUAGGA_BGP_TABLE_H */

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