ripngd.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /*
  2. * RIPng related value and structure.
  3. * Copyright (C) 1998 Kunihiro Ishiguro
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2, or (at your option) any
  10. * later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. */
  22. #ifndef _ZEBRA_RIPNG_RIPNGD_H
  23. #define _ZEBRA_RIPNG_RIPNGD_H
  24. /* RIPng version and port number. */
  25. #define RIPNG_V1 1
  26. #define RIPNG_PORT_DEFAULT 521
  27. #define RIPNG_VTY_PORT 2603
  28. #define RIPNG_MAX_PACKET_SIZE 1500
  29. #define RIPNG_PRIORITY_DEFAULT 0
  30. /* RIPng commands. */
  31. #define RIPNG_REQUEST 1
  32. #define RIPNG_RESPONSE 2
  33. /* RIPng metric and multicast group address. */
  34. #define RIPNG_METRIC_INFINITY 16
  35. #define RIPNG_METRIC_NEXTHOP 0xff
  36. #define RIPNG_GROUP "ff02::9"
  37. /* RIPng timers. */
  38. #define RIPNG_UPDATE_TIMER_DEFAULT 30
  39. #define RIPNG_TIMEOUT_TIMER_DEFAULT 180
  40. #define RIPNG_GARBAGE_TIMER_DEFAULT 120
  41. /* RIPng peer timeout value. */
  42. #define RIPNG_PEER_TIMER_DEFAULT 180
  43. /* Default config file name. */
  44. #define RIPNG_DEFAULT_CONFIG "ripngd.conf"
  45. /* RIPng route types. */
  46. #define RIPNG_ROUTE_RTE 0
  47. #define RIPNG_ROUTE_STATIC 1
  48. #define RIPNG_ROUTE_DEFAULT 2
  49. #define RIPNG_ROUTE_REDISTRIBUTE 3
  50. #define RIPNG_ROUTE_INTERFACE 4
  51. #define RIPNG_ROUTE_AGGREGATE 5
  52. /* Interface send/receive configuration. */
  53. #define RIPNG_SEND_UNSPEC 0
  54. #define RIPNG_SEND_OFF 1
  55. #define RIPNG_RECEIVE_UNSPEC 0
  56. #define RIPNG_RECEIVE_OFF 1
  57. /* RIP default route's accept/announce methods. */
  58. #define RIPNG_DEFAULT_ADVERTISE_UNSPEC 0
  59. #define RIPNG_DEFAULT_ADVERTISE_NONE 1
  60. #define RIPNG_DEFAULT_ADVERTISE 2
  61. #define RIPNG_DEFAULT_ACCEPT_UNSPEC 0
  62. #define RIPNG_DEFAULT_ACCEPT_NONE 1
  63. #define RIPNG_DEFAULT_ACCEPT 2
  64. /* Default value for "default-metric" command. */
  65. #define RIPNG_DEFAULT_METRIC_DEFAULT 1
  66. /* For max RTE calculation. */
  67. #ifndef IPV6_HDRLEN
  68. #define IPV6_HDRLEN 40
  69. #endif /* IPV6_HDRLEN */
  70. #ifndef IFMINMTU
  71. #define IFMINMTU 576
  72. #endif /* IFMINMTU */
  73. /* RIPng structure. */
  74. struct ripng
  75. {
  76. /* RIPng socket. */
  77. int sock;
  78. /* RIPng Parameters.*/
  79. u_char command;
  80. u_char version;
  81. unsigned long update_time;
  82. unsigned long timeout_time;
  83. unsigned long garbage_time;
  84. int max_mtu;
  85. int default_metric;
  86. int default_information;
  87. /* Input/output buffer of RIPng. */
  88. struct stream *ibuf;
  89. struct stream *obuf;
  90. /* RIPng routing information base. */
  91. struct route_table *table;
  92. /* RIPng only static route information. */
  93. struct route_table *route;
  94. /* RIPng aggregate route information. */
  95. struct route_table *aggregate;
  96. /* RIPng threads. */
  97. struct thread *t_read;
  98. struct thread *t_write;
  99. struct thread *t_update;
  100. struct thread *t_garbage;
  101. struct thread *t_zebra;
  102. /* Triggered update hack. */
  103. int trigger;
  104. struct thread *t_triggered_update;
  105. struct thread *t_triggered_interval;
  106. /* For redistribute route map. */
  107. struct
  108. {
  109. char *name;
  110. struct route_map *map;
  111. int metric_config;
  112. u_int32_t metric;
  113. } route_map[ZEBRA_ROUTE_MAX];
  114. };
  115. /* Routing table entry. */
  116. struct rte
  117. {
  118. struct in6_addr addr; /* RIPng destination prefix */
  119. u_short tag; /* RIPng tag */
  120. u_char prefixlen; /* Length of the RIPng prefix */
  121. u_char metric; /* Metric of the RIPng route */
  122. /* The nexthop is stored by the structure
  123. * ripng_nexthop within ripngd.c */
  124. };
  125. /* RIPNG send packet. */
  126. struct ripng_packet
  127. {
  128. u_char command;
  129. u_char version;
  130. u_int16_t zero;
  131. struct rte rte[1];
  132. };
  133. /* Each route's information. */
  134. struct ripng_info
  135. {
  136. /* This route's type. Static, ripng or aggregate. */
  137. u_char type;
  138. /* Sub type for static route. */
  139. u_char sub_type;
  140. /* RIPng specific information */
  141. struct in6_addr nexthop;
  142. struct in6_addr from;
  143. /* Which interface does this route come from. */
  144. unsigned int ifindex;
  145. /* Metric of this route. */
  146. u_char metric;
  147. /* Tag field of RIPng packet.*/
  148. u_int16_t tag;
  149. /* For aggregation. */
  150. unsigned int suppress;
  151. /* Flags of RIPng route. */
  152. #define RIPNG_RTF_FIB 1
  153. #define RIPNG_RTF_CHANGED 2
  154. u_char flags;
  155. /* Garbage collect timer. */
  156. struct thread *t_timeout;
  157. struct thread *t_garbage_collect;
  158. /* Route-map features - this variables can be changed. */
  159. struct in6_addr nexthop_out;
  160. u_char metric_set;
  161. u_char metric_out;
  162. u_short tag_out;
  163. struct route_node *rp;
  164. };
  165. #ifdef notyet
  166. #if 0
  167. /* RIPng tag structure. */
  168. struct ripng_tag
  169. {
  170. /* Tag value. */
  171. u_int16_t tag;
  172. /* Port. */
  173. u_int16_t port;
  174. /* Multicast group. */
  175. struct in6_addr maddr;
  176. /* Table number. */
  177. int table;
  178. /* Distance. */
  179. int distance;
  180. /* Split horizon. */
  181. u_char split_horizon;
  182. /* Poison reverse. */
  183. u_char poison_reverse;
  184. };
  185. #endif /* 0 */
  186. #endif /* not yet */
  187. typedef enum {
  188. RIPNG_NO_SPLIT_HORIZON = 0,
  189. RIPNG_SPLIT_HORIZON,
  190. RIPNG_SPLIT_HORIZON_POISONED_REVERSE
  191. } split_horizon_policy_t;
  192. /* RIPng specific interface configuration. */
  193. struct ripng_interface
  194. {
  195. /* RIPng is enabled on this interface. */
  196. int enable_network;
  197. int enable_interface;
  198. /* RIPng is running on this interface. */
  199. int running;
  200. /* Split horizon flag. */
  201. split_horizon_policy_t split_horizon;
  202. split_horizon_policy_t split_horizon_default;
  203. /* For filter type slot. */
  204. #define RIPNG_FILTER_IN 0
  205. #define RIPNG_FILTER_OUT 1
  206. #define RIPNG_FILTER_MAX 2
  207. /* Access-list. */
  208. struct access_list *list[RIPNG_FILTER_MAX];
  209. /* Prefix-list. */
  210. struct prefix_list *prefix[RIPNG_FILTER_MAX];
  211. /* Route-map. */
  212. struct route_map *routemap[RIPNG_FILTER_MAX];
  213. #ifdef notyet
  214. #if 0
  215. /* RIPng tag configuration. */
  216. struct ripng_tag *rtag;
  217. #endif /* 0 */
  218. #endif /* notyet */
  219. /* Default information originate. */
  220. u_char default_originate;
  221. /* Default information only. */
  222. u_char default_only;
  223. /* Wake up thread. */
  224. struct thread *t_wakeup;
  225. /* Passive interface. */
  226. int passive;
  227. };
  228. /* RIPng peer information. */
  229. struct ripng_peer
  230. {
  231. /* Peer address. */
  232. struct in6_addr addr;
  233. /* Peer RIPng tag value. */
  234. int domain;
  235. /* Last update time. */
  236. time_t uptime;
  237. /* Peer RIP version. */
  238. u_char version;
  239. /* Statistics. */
  240. int recv_badpackets;
  241. int recv_badroutes;
  242. /* Timeout thread. */
  243. struct thread *t_timeout;
  244. };
  245. /* All RIPng events. */
  246. enum ripng_event
  247. {
  248. RIPNG_READ,
  249. RIPNG_ZEBRA,
  250. RIPNG_REQUEST_EVENT,
  251. RIPNG_UPDATE_EVENT,
  252. RIPNG_TRIGGERED_UPDATE,
  253. };
  254. /* RIPng timer on/off macro. */
  255. #define RIPNG_TIMER_ON(T,F,V) \
  256. do { \
  257. if (!(T)) \
  258. (T) = thread_add_timer (master, (F), rinfo, (V)); \
  259. } while (0)
  260. #define RIPNG_TIMER_OFF(T) \
  261. do { \
  262. if (T) \
  263. { \
  264. thread_cancel(T); \
  265. (T) = NULL; \
  266. } \
  267. } while (0)
  268. /* Count prefix size from mask length */
  269. #define PSIZE(a) (((a) + 7) / (8))
  270. /* Extern variables. */
  271. extern struct ripng *ripng;
  272. extern struct thread_master *master;
  273. /* Prototypes. */
  274. void ripng_init ();
  275. void ripng_reset ();
  276. void ripng_clean ();
  277. void ripng_clean_network ();
  278. void ripng_interface_clean ();
  279. void ripng_interface_reset ();
  280. void ripng_passive_interface_clean ();
  281. void ripng_if_init ();
  282. void ripng_route_map_init ();
  283. void ripng_route_map_reset ();
  284. void ripng_terminate ();
  285. /* zclient_init() is done by ripng_zebra.c:zebra_init() */
  286. void zebra_init ();
  287. void ripng_zclient_start ();
  288. void ripng_zclient_reset ();
  289. void ripng_offset_init ();
  290. int config_write_ripng_offset_list (struct vty *);
  291. void ripng_peer_init ();
  292. void ripng_peer_update (struct sockaddr_in6 *, u_char);
  293. void ripng_peer_bad_route (struct sockaddr_in6 *);
  294. void ripng_peer_bad_packet (struct sockaddr_in6 *);
  295. void ripng_peer_display (struct vty *);
  296. struct ripng_peer *ripng_peer_lookup (struct in6_addr *);
  297. struct ripng_peer *ripng_peer_lookup_next (struct in6_addr *);
  298. int ripng_offset_list_apply_in (struct prefix_ipv6 *, struct interface *, u_char *);
  299. int ripng_offset_list_apply_out (struct prefix_ipv6 *, struct interface *, u_char *);
  300. void ripng_offset_clean ();
  301. struct ripng_info * ripng_info_new ();
  302. void ripng_info_free (struct ripng_info *rinfo);
  303. void ripng_event (enum ripng_event, int);
  304. int ripng_request (struct interface *ifp);
  305. void ripng_redistribute_add (int, int, struct prefix_ipv6 *, unsigned int,
  306. struct in6_addr *);
  307. void ripng_redistribute_delete (int, int, struct prefix_ipv6 *, unsigned int);
  308. void ripng_redistribute_withdraw (int type);
  309. void ripng_distribute_update_interface (struct interface *);
  310. void ripng_if_rmap_update_interface (struct interface *);
  311. void ripng_zebra_ipv6_add (struct prefix_ipv6 *p, struct in6_addr *nexthop, unsigned int ifindex, u_char metric);
  312. void ripng_zebra_ipv6_delete (struct prefix_ipv6 *p, struct in6_addr *nexthop, unsigned int ifindex);
  313. void ripng_redistribute_clean ();
  314. int ripng_write_rte (int num, struct stream *s, struct prefix_ipv6 *p,
  315. struct in6_addr *nexthop, u_int16_t tag, u_char metric);
  316. int ripng_send_packet (caddr_t buf, int bufsize, struct sockaddr_in6 *to,
  317. struct interface *ifp);
  318. void ripng_packet_dump (struct ripng_packet *packet, int size, const char *sndrcv);
  319. #endif /* _ZEBRA_RIPNG_RIPNGD_H */