ripd.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. /* RIP related values and structures.
  2. * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
  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 _ZEBRA_RIP_H
  22. #define _ZEBRA_RIP_H
  23. /* RIP version number. */
  24. #define RIPv1 1
  25. #define RIPv2 2
  26. /* N.B. stuff will break if
  27. (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
  28. /* RIP command list. */
  29. #define RIP_REQUEST 1
  30. #define RIP_RESPONSE 2
  31. #define RIP_TRACEON 3 /* Obsolete */
  32. #define RIP_TRACEOFF 4 /* Obsolete */
  33. #define RIP_POLL 5
  34. #define RIP_POLL_ENTRY 6
  35. #define RIP_COMMAND_MAX 7
  36. /* RIP metric infinity value.*/
  37. #define RIP_METRIC_INFINITY 16
  38. /* Normal RIP packet min and max size. */
  39. #define RIP_PACKET_MINSIZ 4
  40. #define RIP_PACKET_MAXSIZ 512
  41. #define RIP_HEADER_SIZE 4
  42. #define RIP_RTE_SIZE 20
  43. /* Max count of routing table entry in one rip packet. */
  44. #define RIP_MAX_RTE ((RIP_PACKET_MAXSIZ - RIP_HEADER_SIZE) / RIP_RTE_SIZE)
  45. /* RIP version 2 multicast address. */
  46. #ifndef INADDR_RIP_GROUP
  47. #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */
  48. #endif
  49. /* RIP timers */
  50. #define RIP_UPDATE_TIMER_DEFAULT 30
  51. #define RIP_TIMEOUT_TIMER_DEFAULT 180
  52. #define RIP_GARBAGE_TIMER_DEFAULT 120
  53. /* RIP peer timeout value. */
  54. #define RIP_PEER_TIMER_DEFAULT 180
  55. /* RIP port number. */
  56. #define RIP_PORT_DEFAULT 520
  57. #define RIP_VTY_PORT 2602
  58. /* Default configuration file name. */
  59. #define RIPD_DEFAULT_CONFIG "ripd.conf"
  60. /* RIP route types. */
  61. #define RIP_ROUTE_RTE 0
  62. #define RIP_ROUTE_STATIC 1
  63. #define RIP_ROUTE_DEFAULT 2
  64. #define RIP_ROUTE_REDISTRIBUTE 3
  65. #define RIP_ROUTE_INTERFACE 4
  66. /* RIPv2 special RTE family types */
  67. #define RIP_FAMILY_AUTH 0xffff
  68. /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
  69. #define RIP_NO_AUTH 0
  70. #define RIP_AUTH_DATA 1
  71. #define RIP_AUTH_SIMPLE_PASSWORD 2
  72. #define RIP_AUTH_MD5 3
  73. /* RIPv2 Simple authentication */
  74. #define RIP_AUTH_SIMPLE_SIZE 16
  75. /* RIPv2 MD5 authentication. */
  76. #define RIP_AUTH_MD5_SIZE 16
  77. #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
  78. /* RIP structure. */
  79. struct rip
  80. {
  81. /* RIP socket. */
  82. int sock;
  83. /* Default version of rip instance. */
  84. int version_send; /* version 1 or 2 (but not both) */
  85. int version_recv; /* version 1 or 2 or both */
  86. /* Output buffer of RIP. */
  87. struct stream *obuf;
  88. /* RIP routing information base. */
  89. struct route_table *table;
  90. /* RIP only static routing information. */
  91. struct route_table *route;
  92. /* RIP neighbor. */
  93. struct route_table *neighbor;
  94. /* RIP threads. */
  95. struct thread *t_read;
  96. /* Update and garbage timer. */
  97. struct thread *t_update;
  98. /* Triggered update hack. */
  99. int trigger;
  100. struct thread *t_triggered_update;
  101. struct thread *t_triggered_interval;
  102. /* RIP timer values. */
  103. unsigned long update_time;
  104. unsigned long timeout_time;
  105. unsigned long garbage_time;
  106. /* RIP default metric. */
  107. int default_metric;
  108. /* RIP default-information originate. */
  109. u_char default_information;
  110. char *default_information_route_map;
  111. /* RIP default distance. */
  112. u_char distance;
  113. struct route_table *distance_table;
  114. /* RIP ECMP flag */
  115. unsigned int ecmp;
  116. /* For redistribute route map. */
  117. struct
  118. {
  119. char *name;
  120. struct route_map *map;
  121. int metric_config;
  122. u_int32_t metric;
  123. } route_map[ZEBRA_ROUTE_MAX];
  124. };
  125. /* RIP routing table entry which belong to rip_packet. */
  126. struct rte
  127. {
  128. u_int16_t family; /* Address family of this route. */
  129. u_int16_t tag; /* Route Tag which included in RIP2 packet. */
  130. struct in_addr prefix; /* Prefix of rip route. */
  131. struct in_addr mask; /* Netmask of rip route. */
  132. struct in_addr nexthop; /* Next hop of rip route. */
  133. u_int32_t metric; /* Metric value of rip route. */
  134. };
  135. /* RIP packet structure. */
  136. struct rip_packet
  137. {
  138. unsigned char command; /* Command type of RIP packet. */
  139. unsigned char version; /* RIP version which coming from peer. */
  140. unsigned char pad1; /* Padding of RIP packet header. */
  141. unsigned char pad2; /* Same as above. */
  142. struct rte rte[1]; /* Address structure. */
  143. };
  144. /* Buffer to read RIP packet. */
  145. union rip_buf
  146. {
  147. struct rip_packet rip_packet;
  148. char buf[RIP_PACKET_MAXSIZ];
  149. };
  150. /* RIP route information. */
  151. struct rip_info
  152. {
  153. /* This route's type. */
  154. int type;
  155. /* Sub type. */
  156. int sub_type;
  157. /* RIP nexthop. */
  158. struct in_addr nexthop;
  159. struct in_addr from;
  160. /* Which interface does this route come from. */
  161. ifindex_t ifindex;
  162. /* Metric of this route. */
  163. u_int32_t metric;
  164. /* External metric of this route.
  165. if learnt from an externalm proto */
  166. u_int32_t external_metric;
  167. /* Tag information of this route. */
  168. u_int16_t tag;
  169. /* Flags of RIP route. */
  170. #define RIP_RTF_FIB 1
  171. #define RIP_RTF_CHANGED 2
  172. u_char flags;
  173. /* Garbage collect timer. */
  174. struct thread *t_timeout;
  175. struct thread *t_garbage_collect;
  176. /* Route-map futures - this variables can be changed. */
  177. struct in_addr nexthop_out;
  178. u_char metric_set;
  179. u_int32_t metric_out;
  180. u_short tag_out;
  181. ifindex_t ifindex_out;
  182. struct route_node *rp;
  183. u_char distance;
  184. #ifdef NEW_RIP_TABLE
  185. struct rip_info *next;
  186. struct rip_info *prev;
  187. #endif /* NEW_RIP_TABLE */
  188. };
  189. typedef enum {
  190. RIP_NO_SPLIT_HORIZON = 0,
  191. RIP_SPLIT_HORIZON,
  192. RIP_SPLIT_HORIZON_POISONED_REVERSE
  193. } split_horizon_policy_t;
  194. /* RIP specific interface configuration. */
  195. struct rip_interface
  196. {
  197. /* RIP is enabled on this interface. */
  198. int enable_network;
  199. int enable_interface;
  200. /* RIP is running on this interface. */
  201. int running;
  202. /* RIP version control. */
  203. int ri_send;
  204. int ri_receive;
  205. /* RIPv2 authentication type. */
  206. int auth_type;
  207. /* RIPv2 authentication string. */
  208. char *auth_str;
  209. /* RIPv2 authentication key chain. */
  210. char *key_chain;
  211. /* value to use for md5->auth_len */
  212. u_int8_t md5_auth_len;
  213. /* Split horizon flag. */
  214. split_horizon_policy_t split_horizon;
  215. split_horizon_policy_t split_horizon_default;
  216. /* For filter type slot. */
  217. #define RIP_FILTER_IN 0
  218. #define RIP_FILTER_OUT 1
  219. #define RIP_FILTER_MAX 2
  220. /* Access-list. */
  221. struct access_list *list[RIP_FILTER_MAX];
  222. /* Prefix-list. */
  223. struct prefix_list *prefix[RIP_FILTER_MAX];
  224. /* Route-map. */
  225. struct route_map *routemap[RIP_FILTER_MAX];
  226. /* Wake up thread. */
  227. struct thread *t_wakeup;
  228. /* Interface statistics. */
  229. int recv_badpackets;
  230. int recv_badroutes;
  231. int sent_updates;
  232. /* Passive interface. */
  233. int passive;
  234. };
  235. /* RIP peer information. */
  236. struct rip_peer
  237. {
  238. /* Peer address. */
  239. struct in_addr addr;
  240. /* Peer RIP tag value. */
  241. int domain;
  242. /* Last update time. */
  243. time_t uptime;
  244. /* Peer RIP version. */
  245. u_char version;
  246. /* Statistics. */
  247. int recv_badpackets;
  248. int recv_badroutes;
  249. /* Timeout thread. */
  250. struct thread *t_timeout;
  251. };
  252. struct rip_md5_info
  253. {
  254. u_int16_t family;
  255. u_int16_t type;
  256. u_int16_t packet_len;
  257. u_char keyid;
  258. u_char auth_len;
  259. u_int32_t sequence;
  260. u_int32_t reserv1;
  261. u_int32_t reserv2;
  262. };
  263. struct rip_md5_data
  264. {
  265. u_int16_t family;
  266. u_int16_t type;
  267. u_char digest[16];
  268. };
  269. /* RIP accepet/announce methods. */
  270. #define RI_RIP_UNSPEC 0
  271. #define RI_RIP_VERSION_1 1
  272. #define RI_RIP_VERSION_2 2
  273. #define RI_RIP_VERSION_1_AND_2 3
  274. /* N.B. stuff will break if
  275. (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
  276. /* Default value for "default-metric" command. */
  277. #define RIP_DEFAULT_METRIC_DEFAULT 1
  278. /* RIP event. */
  279. enum rip_event
  280. {
  281. RIP_READ,
  282. RIP_UPDATE_EVENT,
  283. RIP_TRIGGERED_UPDATE,
  284. };
  285. /* Macro for timer turn on. */
  286. #define RIP_TIMER_ON(T,F,V) \
  287. do { \
  288. if (!(T)) \
  289. (T) = thread_add_timer (master, (F), rinfo, (V)); \
  290. } while (0)
  291. /* Macro for timer turn off. */
  292. #define RIP_TIMER_OFF(X) \
  293. do { \
  294. if (X) \
  295. { \
  296. thread_cancel (X); \
  297. (X) = NULL; \
  298. } \
  299. } while (0)
  300. /* Prototypes. */
  301. extern void rip_init (void);
  302. extern void rip_reset (void);
  303. extern void rip_clean (void);
  304. extern void rip_clean_network (void);
  305. extern void rip_interface_clean (void);
  306. extern void rip_interface_reset (void);
  307. extern void rip_passive_nondefault_clean (void);
  308. extern void rip_if_init (void);
  309. extern void rip_if_down_all (void);
  310. extern void rip_route_map_init (void);
  311. extern void rip_route_map_reset (void);
  312. extern void rip_snmp_init (void);
  313. extern void rip_zclient_init (struct thread_master *);
  314. extern void rip_zclient_start (void);
  315. extern void rip_zclient_reset (void);
  316. extern void rip_offset_init (void);
  317. extern int if_check_address (struct in_addr addr);
  318. extern int rip_request_send (struct sockaddr_in *, struct interface *, u_char,
  319. struct connected *);
  320. extern int rip_neighbor_lookup (struct sockaddr_in *);
  321. extern int rip_redistribute_check (int);
  322. extern void rip_redistribute_add (int, int, struct prefix_ipv4 *, ifindex_t,
  323. struct in_addr *, unsigned int, unsigned char);
  324. extern void rip_redistribute_delete (int, int, struct prefix_ipv4 *, ifindex_t);
  325. extern void rip_redistribute_withdraw (int);
  326. extern void rip_zebra_ipv4_add (struct route_node *);
  327. extern void rip_zebra_ipv4_delete (struct route_node *);
  328. extern void rip_interface_multicast_set (int, struct connected *);
  329. extern void rip_distribute_update_interface (struct interface *);
  330. extern void rip_if_rmap_update_interface (struct interface *);
  331. extern int config_write_rip_network (struct vty *, int);
  332. extern int config_write_rip_offset_list (struct vty *);
  333. extern int config_write_rip_redistribute (struct vty *, int);
  334. extern void rip_peer_init (void);
  335. extern void rip_peer_update (struct sockaddr_in *, u_char);
  336. extern void rip_peer_bad_route (struct sockaddr_in *);
  337. extern void rip_peer_bad_packet (struct sockaddr_in *);
  338. extern void rip_peer_display (struct vty *);
  339. extern struct rip_peer *rip_peer_lookup (struct in_addr *);
  340. extern struct rip_peer *rip_peer_lookup_next (struct in_addr *);
  341. extern int rip_offset_list_apply_in (struct prefix_ipv4 *, struct interface *, u_int32_t *);
  342. extern int rip_offset_list_apply_out (struct prefix_ipv4 *, struct interface *, u_int32_t *);
  343. extern void rip_offset_clean (void);
  344. extern void rip_info_free (struct rip_info *);
  345. extern u_char rip_distance_apply (struct rip_info *);
  346. extern void rip_redistribute_clean (void);
  347. extern void rip_ifaddr_add (struct interface *, struct connected *);
  348. extern void rip_ifaddr_delete (struct interface *, struct connected *);
  349. extern struct rip_info *rip_ecmp_add (struct rip_info *);
  350. extern struct rip_info *rip_ecmp_replace (struct rip_info *);
  351. extern struct rip_info *rip_ecmp_delete (struct rip_info *);
  352. /* There is only one rip strucutre. */
  353. extern struct rip *rip;
  354. /* Master thread strucutre. */
  355. extern struct thread_master *master;
  356. /* RIP statistics for SNMP. */
  357. extern long rip_global_route_changes;
  358. extern long rip_global_queries;
  359. #endif /* _ZEBRA_RIP_H */