ripngd.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. /* RIPng ECMP flag */
  109. unsigned int ecmp;
  110. /* For redistribute route map. */
  111. struct
  112. {
  113. char *name;
  114. struct route_map *map;
  115. int metric_config;
  116. u_int32_t metric;
  117. } route_map[ZEBRA_ROUTE_MAX];
  118. };
  119. /* Routing table entry. */
  120. struct rte
  121. {
  122. struct in6_addr addr; /* RIPng destination prefix */
  123. u_short tag; /* RIPng tag */
  124. u_char prefixlen; /* Length of the RIPng prefix */
  125. u_char metric; /* Metric of the RIPng route */
  126. /* The nexthop is stored by the structure
  127. * ripng_nexthop within ripngd.c */
  128. };
  129. /* RIPNG send packet. */
  130. struct ripng_packet
  131. {
  132. u_char command;
  133. u_char version;
  134. u_int16_t zero;
  135. struct rte rte[1];
  136. };
  137. /* Each route's information. */
  138. struct ripng_info
  139. {
  140. /* This route's type. Static, ripng or aggregate. */
  141. u_char type;
  142. /* Sub type for static route. */
  143. u_char sub_type;
  144. /* RIPng specific information */
  145. struct in6_addr nexthop;
  146. struct in6_addr from;
  147. /* Which interface does this route come from. */
  148. ifindex_t ifindex;
  149. /* Metric of this route. */
  150. u_char metric;
  151. /* Tag field of RIPng packet.*/
  152. u_int16_t tag;
  153. /* For aggregation. */
  154. unsigned int suppress;
  155. /* Flags of RIPng route. */
  156. #define RIPNG_RTF_FIB 1
  157. #define RIPNG_RTF_CHANGED 2
  158. u_char flags;
  159. /* Garbage collect timer. */
  160. struct thread *t_timeout;
  161. struct thread *t_garbage_collect;
  162. /* Route-map features - this variables can be changed. */
  163. struct in6_addr nexthop_out;
  164. u_char metric_set;
  165. u_char metric_out;
  166. u_short tag_out;
  167. struct route_node *rp;
  168. };
  169. #ifdef notyet
  170. #if 0
  171. /* RIPng tag structure. */
  172. struct ripng_tag
  173. {
  174. /* Tag value. */
  175. u_int16_t tag;
  176. /* Port. */
  177. u_int16_t port;
  178. /* Multicast group. */
  179. struct in6_addr maddr;
  180. /* Table number. */
  181. int table;
  182. /* Distance. */
  183. int distance;
  184. /* Split horizon. */
  185. u_char split_horizon;
  186. /* Poison reverse. */
  187. u_char poison_reverse;
  188. };
  189. #endif /* 0 */
  190. #endif /* not yet */
  191. typedef enum {
  192. RIPNG_NO_SPLIT_HORIZON = 0,
  193. RIPNG_SPLIT_HORIZON,
  194. RIPNG_SPLIT_HORIZON_POISONED_REVERSE
  195. } split_horizon_policy_t;
  196. /* RIPng specific interface configuration. */
  197. struct ripng_interface
  198. {
  199. /* RIPng is enabled on this interface. */
  200. int enable_network;
  201. int enable_interface;
  202. /* RIPng is running on this interface. */
  203. int running;
  204. /* Split horizon flag. */
  205. split_horizon_policy_t split_horizon;
  206. split_horizon_policy_t split_horizon_default;
  207. /* For filter type slot. */
  208. #define RIPNG_FILTER_IN 0
  209. #define RIPNG_FILTER_OUT 1
  210. #define RIPNG_FILTER_MAX 2
  211. /* Access-list. */
  212. struct access_list *list[RIPNG_FILTER_MAX];
  213. /* Prefix-list. */
  214. struct prefix_list *prefix[RIPNG_FILTER_MAX];
  215. /* Route-map. */
  216. struct route_map *routemap[RIPNG_FILTER_MAX];
  217. #ifdef notyet
  218. #if 0
  219. /* RIPng tag configuration. */
  220. struct ripng_tag *rtag;
  221. #endif /* 0 */
  222. #endif /* notyet */
  223. /* Default information originate. */
  224. u_char default_originate;
  225. /* Default information only. */
  226. u_char default_only;
  227. /* Wake up thread. */
  228. struct thread *t_wakeup;
  229. /* Passive interface. */
  230. int passive;
  231. };
  232. /* RIPng peer information. */
  233. struct ripng_peer
  234. {
  235. /* Peer address. */
  236. struct in6_addr addr;
  237. /* Peer RIPng tag value. */
  238. int domain;
  239. /* Last update time. */
  240. time_t uptime;
  241. /* Peer RIP version. */
  242. u_char version;
  243. /* Statistics. */
  244. int recv_badpackets;
  245. int recv_badroutes;
  246. /* Timeout thread. */
  247. struct thread *t_timeout;
  248. };
  249. /* All RIPng events. */
  250. enum ripng_event
  251. {
  252. RIPNG_READ,
  253. RIPNG_ZEBRA,
  254. RIPNG_REQUEST_EVENT,
  255. RIPNG_UPDATE_EVENT,
  256. RIPNG_TRIGGERED_UPDATE,
  257. };
  258. /* RIPng timer on/off macro. */
  259. #define RIPNG_TIMER_ON(T,F,V) \
  260. do { \
  261. if (!(T)) \
  262. (T) = thread_add_timer (master, (F), rinfo, (V)); \
  263. } while (0)
  264. #define RIPNG_TIMER_OFF(T) \
  265. do { \
  266. if (T) \
  267. { \
  268. thread_cancel(T); \
  269. (T) = NULL; \
  270. } \
  271. } while (0)
  272. /* Count prefix size from mask length */
  273. #define PSIZE(a) (((a) + 7) / (8))
  274. /* Extern variables. */
  275. extern struct ripng *ripng;
  276. extern struct thread_master *master;
  277. /* Prototypes. */
  278. extern void ripng_init (void);
  279. extern void ripng_reset (void);
  280. extern void ripng_clean (void);
  281. extern void ripng_clean_network (void);
  282. extern void ripng_interface_clean (void);
  283. extern void ripng_interface_reset (void);
  284. extern void ripng_passive_interface_clean (void);
  285. extern void ripng_if_init (void);
  286. extern void ripng_route_map_init (void);
  287. extern void ripng_route_map_reset (void);
  288. extern void ripng_terminate (void);
  289. /* zclient_init() is done by ripng_zebra.c:zebra_init() */
  290. extern void zebra_init (struct thread_master *);
  291. extern void ripng_zclient_start (void);
  292. extern void ripng_zclient_reset (void);
  293. extern void ripng_offset_init (void);
  294. extern int config_write_ripng_offset_list (struct vty *);
  295. extern void ripng_peer_init (void);
  296. extern void ripng_peer_update (struct sockaddr_in6 *, u_char);
  297. extern void ripng_peer_bad_route (struct sockaddr_in6 *);
  298. extern void ripng_peer_bad_packet (struct sockaddr_in6 *);
  299. extern void ripng_peer_display (struct vty *);
  300. extern struct ripng_peer *ripng_peer_lookup (struct in6_addr *);
  301. extern struct ripng_peer *ripng_peer_lookup_next (struct in6_addr *);
  302. extern int ripng_offset_list_apply_in (struct prefix_ipv6 *,
  303. struct interface *, u_char *);
  304. extern int ripng_offset_list_apply_out (struct prefix_ipv6 *,
  305. struct interface *, u_char *);
  306. extern void ripng_offset_clean (void);
  307. extern struct ripng_info * ripng_info_new (void);
  308. extern void ripng_info_free (struct ripng_info *rinfo);
  309. extern void ripng_event (enum ripng_event, int);
  310. extern int ripng_request (struct interface *ifp);
  311. extern void ripng_redistribute_add (int, int, struct prefix_ipv6 *,
  312. ifindex_t, struct in6_addr *);
  313. extern void ripng_redistribute_delete (int, int, struct prefix_ipv6 *,
  314. ifindex_t);
  315. extern void ripng_redistribute_withdraw (int type);
  316. extern void ripng_distribute_update_interface (struct interface *);
  317. extern void ripng_if_rmap_update_interface (struct interface *);
  318. extern void ripng_zebra_ipv6_add (struct route_node *);
  319. extern void ripng_zebra_ipv6_delete (struct route_node *);
  320. extern void ripng_redistribute_clean (void);
  321. extern int ripng_redistribute_check (int);
  322. extern void ripng_redistribute_write (struct vty *, int);
  323. extern int ripng_write_rte (int num, struct stream *s, struct prefix_ipv6 *p,
  324. struct in6_addr *nexthop,
  325. u_int16_t tag, u_char metric);
  326. extern int ripng_send_packet (caddr_t buf, int bufsize,
  327. struct sockaddr_in6 *to, struct interface *ifp);
  328. extern void ripng_packet_dump (struct ripng_packet *packet, int size,
  329. const char *sndrcv);
  330. extern int ripng_interface_up (int command, struct zclient *, zebra_size_t,
  331. vrf_id_t);
  332. extern int ripng_interface_down (int command, struct zclient *, zebra_size_t,
  333. vrf_id_t);
  334. extern int ripng_interface_add (int command, struct zclient *, zebra_size_t,
  335. vrf_id_t);
  336. extern int ripng_interface_delete (int command, struct zclient *, zebra_size_t,
  337. vrf_id_t);
  338. extern int ripng_interface_address_add (int command, struct zclient *, zebra_size_t,
  339. vrf_id_t);
  340. extern int ripng_interface_address_delete (int command, struct zclient *, zebra_size_t,
  341. vrf_id_t);
  342. extern int ripng_network_write (struct vty *, int);
  343. extern struct ripng_info *ripng_ecmp_add (struct ripng_info *);
  344. extern struct ripng_info *ripng_ecmp_replace (struct ripng_info *);
  345. extern struct ripng_info *ripng_ecmp_delete (struct ripng_info *);
  346. #endif /* _ZEBRA_RIPNG_RIPNGD_H */