ospf6_route.h
上传用户:xiaozhuqw
上传日期:2009-11-15
资源大小:1338k
文件大小:9k
源码类别:

网络

开发平台:

Unix_Linux

  1. /*
  2.  * Copyright (C) 2003 Yasuhiro Ohara
  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 
  18.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
  19.  * Boston, MA 02111-1307, USA.  
  20.  */
  21. #ifndef OSPF6_ROUTE_H
  22. #define OSPF6_ROUTE_H
  23. #define OSPF6_MULTI_PATH_LIMIT    4
  24. /* Debug option */
  25. extern unsigned char conf_debug_ospf6_route;
  26. #define OSPF6_DEBUG_ROUTE_TABLE   0x01
  27. #define OSPF6_DEBUG_ROUTE_INTRA   0x02
  28. #define OSPF6_DEBUG_ROUTE_INTER   0x04
  29. #define OSPF6_DEBUG_ROUTE_ON(level) 
  30.   (conf_debug_ospf6_route |= (level))
  31. #define OSPF6_DEBUG_ROUTE_OFF(level) 
  32.   (conf_debug_ospf6_route &= ~(level))
  33. #define IS_OSPF6_DEBUG_ROUTE(e) 
  34.   (conf_debug_ospf6_route & OSPF6_DEBUG_ROUTE_ ## e)
  35. /* Nexthop */
  36. struct ospf6_nexthop
  37. {
  38.   /* Interface index */
  39.   unsigned int ifindex;
  40.   /* IP address, if any */
  41.   struct in6_addr address;
  42. };
  43. #define ospf6_nexthop_is_set(x)                                
  44.   ((x)->ifindex || ! IN6_IS_ADDR_UNSPECIFIED (&(x)->address))
  45. #define ospf6_nexthop_is_same(a,b)                             
  46.   ((a)->ifindex == (b)->ifindex &&                            
  47.    IN6_ARE_ADDR_EQUAL (&(a)->address, &(b)->address))
  48. #define ospf6_nexthop_clear(x)                                
  49.   do {                                                        
  50.     (x)->ifindex = 0;                                         
  51.     memset (&(x)->address, 0, sizeof (struct in6_addr));      
  52.   } while (0)
  53. #define ospf6_nexthop_copy(a, b)                              
  54.   do {                                                        
  55.     (a)->ifindex = (b)->ifindex;                              
  56.     memcpy (&(a)->address, &(b)->address,                     
  57.             sizeof (struct in6_addr));                        
  58.   } while (0)
  59. /* Path */
  60. struct ospf6_ls_origin
  61. {
  62.   u_int16_t type;
  63.   u_int32_t id;
  64.   u_int32_t adv_router;
  65. };
  66. struct ospf6_path
  67. {
  68.   /* Link State Origin */
  69.   struct ospf6_ls_origin origin;
  70.   /* Router bits */
  71.   u_char router_bits;
  72.   /* Optional Capabilities */
  73.   u_char options[3];
  74.   /* Prefix Options */
  75.   u_char prefix_options;
  76.   /* Associated Area */
  77.   u_int32_t area_id;
  78.   /* Path-type */
  79.   u_char type;
  80.   u_char subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */
  81.   /* Cost */
  82.   u_int8_t metric_type;
  83.   u_int32_t cost;
  84.   u_int32_t cost_e2;
  85. };
  86. #define OSPF6_PATH_TYPE_NONE         0
  87. #define OSPF6_PATH_TYPE_INTRA        1
  88. #define OSPF6_PATH_TYPE_INTER        2
  89. #define OSPF6_PATH_TYPE_EXTERNAL1    3
  90. #define OSPF6_PATH_TYPE_EXTERNAL2    4
  91. #define OSPF6_PATH_TYPE_REDISTRIBUTE 5
  92. #define OSPF6_PATH_TYPE_MAX          6
  93. #include "prefix.h"
  94. #include "table.h"
  95. struct ospf6_route
  96. {
  97.   struct route_node *rnode;
  98.   struct ospf6_route *prev;
  99.   struct ospf6_route *next;
  100.   unsigned int lock;
  101.   /* Destination Type */
  102.   u_char type;
  103.   /* Destination ID */
  104.   struct prefix prefix;
  105.   /* Time */
  106.   struct timeval installed;
  107.   struct timeval changed;
  108.   /* flag */
  109.   u_char flag;
  110.   /* path */
  111.   struct ospf6_path path;
  112.   /* nexthop */
  113.   struct ospf6_nexthop nexthop[OSPF6_MULTI_PATH_LIMIT];
  114.   /* route option */
  115.   void *route_option;
  116.   /* link state id for advertising */
  117.   u_int32_t linkstate_id;
  118. };
  119. #define OSPF6_DEST_TYPE_NONE       0
  120. #define OSPF6_DEST_TYPE_ROUTER     1
  121. #define OSPF6_DEST_TYPE_NETWORK    2
  122. #define OSPF6_DEST_TYPE_DISCARD    3
  123. #define OSPF6_DEST_TYPE_LINKSTATE  4
  124. #define OSPF6_DEST_TYPE_RANGE      5
  125. #define OSPF6_DEST_TYPE_MAX        6
  126. #define OSPF6_ROUTE_CHANGE           0x01
  127. #define OSPF6_ROUTE_ADD              0x02
  128. #define OSPF6_ROUTE_REMOVE           0x04
  129. #define OSPF6_ROUTE_BEST             0x08
  130. #define OSPF6_ROUTE_ACTIVE_SUMMARY   0x10
  131. #define OSPF6_ROUTE_DO_NOT_ADVERTISE 0x20
  132. #define OSPF6_ROUTE_WAS_REMOVED      0x40
  133. struct ospf6_route_table
  134. {
  135.   /* patricia tree */
  136.   struct route_table *table;
  137.   u_int32_t count;
  138.   /* hooks */
  139.   void (*hook_add) (struct ospf6_route *);
  140.   void (*hook_change) (struct ospf6_route *);
  141.   void (*hook_remove) (struct ospf6_route *);
  142. };
  143. extern char *ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX];
  144. extern char *ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX];
  145. #define OSPF6_DEST_TYPE_NAME(x)                       
  146.   (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ?             
  147.    ospf6_dest_type_str[(x)] : ospf6_dest_type_str[0])
  148. #define OSPF6_DEST_TYPE_SUBSTR(x)                           
  149.   (0 < (x) && (x) < OSPF6_DEST_TYPE_MAX ?                   
  150.    ospf6_dest_type_substr[(x)] : ospf6_dest_type_substr[0])
  151. extern char *ospf6_path_type_str[OSPF6_PATH_TYPE_MAX];
  152. extern char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX];
  153. #define OSPF6_PATH_TYPE_NAME(x)                       
  154.   (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ?             
  155.    ospf6_path_type_str[(x)] : ospf6_path_type_str[0])
  156. #define OSPF6_PATH_TYPE_SUBSTR(x)                           
  157.   (0 < (x) && (x) < OSPF6_PATH_TYPE_MAX ?                   
  158.    ospf6_path_type_substr[(x)] : ospf6_path_type_substr[0])
  159. #define OSPF6_ROUTE_ADDRESS_STR "Display the route bestmatches the addressn"
  160. #define OSPF6_ROUTE_PREFIX_STR  "Display the routen"
  161. #define OSPF6_ROUTE_MATCH_STR   "Display the route matches the prefixn"
  162. #define ospf6_route_is_prefix(p, r) 
  163.   (memcmp (p, &(r)->prefix, sizeof (struct prefix)) == 0)
  164. #define ospf6_route_is_same(ra, rb) 
  165.   (prefix_same (&(ra)->prefix, &(rb)->prefix))
  166. #define ospf6_route_is_same_origin(ra, rb) 
  167.   ((ra)->path.area_id == (rb)->path.area_id && 
  168.    memcmp (&(ra)->path.origin, &(rb)->path.origin, 
  169.            sizeof (struct ospf6_ls_origin)) == 0)
  170. #define ospf6_route_is_identical(ra, rb) 
  171.   ((ra)->type == (rb)->type && 
  172.    memcmp (&(ra)->prefix, &(rb)->prefix, sizeof (struct prefix)) == 0 && 
  173.    memcmp (&(ra)->path, &(rb)->path, sizeof (struct ospf6_path)) == 0 && 
  174.    memcmp (&(ra)->nexthop, &(rb)->nexthop,                               
  175.            sizeof (struct ospf6_nexthop) * OSPF6_MULTI_PATH_LIMIT) == 0)
  176. #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST))
  177. #define ospf6_linkstate_prefix_adv_router(x) 
  178.   (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[0]))
  179. #define ospf6_linkstate_prefix_id(x) 
  180.   (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[4]))
  181. #define ADV_ROUTER_IN_PREFIX(x) 
  182.   (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[0]))
  183. #define ID_IN_PREFIX(x) 
  184.   (*(u_int32_t *)(&(x)->u.prefix6.s6_addr[4]))
  185. /* Function prototype */
  186. void ospf6_linkstate_prefix (u_int32_t adv_router, u_int32_t id,
  187.                              struct prefix *prefix);
  188. void ospf6_linkstate_prefix2str (struct prefix *prefix, char *buf, int size);
  189. struct ospf6_route *ospf6_route_create ();
  190. void ospf6_route_delete (struct ospf6_route *);
  191. struct ospf6_route *ospf6_route_copy (struct ospf6_route *route);
  192. void ospf6_route_lock (struct ospf6_route *route);
  193. void ospf6_route_unlock (struct ospf6_route *route);
  194. struct ospf6_route *
  195. ospf6_route_lookup (struct prefix *prefix,
  196.                     struct ospf6_route_table *table);
  197. struct ospf6_route *
  198. ospf6_route_lookup_identical (struct ospf6_route *route,
  199.                               struct ospf6_route_table *table);
  200. struct ospf6_route *
  201. ospf6_route_lookup_bestmatch (struct prefix *prefix,
  202.                               struct ospf6_route_table *table);
  203. struct ospf6_route *
  204. ospf6_route_add (struct ospf6_route *route, struct ospf6_route_table *table);
  205. void
  206. ospf6_route_remove (struct ospf6_route *route, struct ospf6_route_table *table);
  207. struct ospf6_route *ospf6_route_head (struct ospf6_route_table *table);
  208. struct ospf6_route *ospf6_route_next (struct ospf6_route *route);
  209. struct ospf6_route *ospf6_route_best_next (struct ospf6_route *route);
  210. struct ospf6_route *ospf6_route_match_head (struct prefix *prefix,
  211.                                             struct ospf6_route_table *table);
  212. struct ospf6_route *ospf6_route_match_next (struct prefix *prefix,
  213.                                             struct ospf6_route *route);
  214. void ospf6_route_remove_all (struct ospf6_route_table *);
  215. struct ospf6_route_table *ospf6_route_table_create ();
  216. void ospf6_route_table_delete (struct ospf6_route_table *);
  217. void ospf6_route_dump (struct ospf6_route_table *table);
  218. void ospf6_route_show (struct vty *vty, struct ospf6_route *route);
  219. void ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route);
  220. int ospf6_route_table_show (struct vty *, int, char **,
  221.                             struct ospf6_route_table *);
  222. int ospf6_linkstate_table_show (struct vty *vty, int argc, char **argv,
  223.                             struct ospf6_route_table *table);
  224. void ospf6_brouter_show_header (struct vty *vty);
  225. void ospf6_brouter_show (struct vty *vty, struct ospf6_route *route);
  226. int config_write_ospf6_debug_route (struct vty *vty);
  227. void install_element_ospf6_debug_route ();
  228. void ospf6_route_init ();
  229. #endif /* OSPF6_ROUTE_H */