ripngd.h 11 KB

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