ripd.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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 25
  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. /* For redistribute route map. */
  115. struct
  116. {
  117. char *name;
  118. struct route_map *map;
  119. int metric_config;
  120. u_int32_t metric;
  121. } route_map[ZEBRA_ROUTE_MAX];
  122. };
  123. /* RIP routing table entry which belong to rip_packet. */
  124. struct rte
  125. {
  126. u_int16_t family; /* Address family of this route. */
  127. u_int16_t tag; /* Route Tag which included in RIP2 packet. */
  128. struct in_addr prefix; /* Prefix of rip route. */
  129. struct in_addr mask; /* Netmask of rip route. */
  130. struct in_addr nexthop; /* Next hop of rip route. */
  131. u_int32_t metric; /* Metric value of rip route. */
  132. };
  133. /* RIP packet structure. */
  134. struct rip_packet
  135. {
  136. unsigned char command; /* Command type of RIP packet. */
  137. unsigned char version; /* RIP version which coming from peer. */
  138. unsigned char pad1; /* Padding of RIP packet header. */
  139. unsigned char pad2; /* Same as above. */
  140. struct rte rte[1]; /* Address structure. */
  141. };
  142. /* Buffer to read RIP packet. */
  143. union rip_buf
  144. {
  145. struct rip_packet rip_packet;
  146. char buf[RIP_PACKET_MAXSIZ];
  147. };
  148. /* RIP route information. */
  149. struct rip_info
  150. {
  151. /* This route's type. */
  152. int type;
  153. /* Sub type. */
  154. int sub_type;
  155. /* RIP nexthop. */
  156. struct in_addr nexthop;
  157. struct in_addr from;
  158. /* Which interface does this route come from. */
  159. unsigned int ifindex;
  160. /* Metric of this route. */
  161. u_int32_t metric;
  162. /* External metric of this route.
  163. if learnt from an externalm proto */
  164. u_int32_t external_metric;
  165. /* Tag information of this route. */
  166. u_int16_t tag;
  167. /* Flags of RIP route. */
  168. #define RIP_RTF_FIB 1
  169. #define RIP_RTF_CHANGED 2
  170. u_char flags;
  171. /* Garbage collect timer. */
  172. struct thread *t_timeout;
  173. struct thread *t_garbage_collect;
  174. /* Route-map futures - this variables can be changed. */
  175. struct in_addr nexthop_out;
  176. u_char metric_set;
  177. u_int32_t metric_out;
  178. u_short tag_out;
  179. unsigned int ifindex_out;
  180. struct route_node *rp;
  181. u_char distance;
  182. #ifdef NEW_RIP_TABLE
  183. struct rip_info *next;
  184. struct rip_info *prev;
  185. #endif /* NEW_RIP_TABLE */
  186. };
  187. typedef enum {
  188. RIP_NO_SPLIT_HORIZON = 0,
  189. RIP_SPLIT_HORIZON,
  190. RIP_SPLIT_HORIZON_POISONED_REVERSE
  191. } split_horizon_policy_t;
  192. /* RIP specific interface configuration. */
  193. struct rip_interface
  194. {
  195. /* RIP is enabled on this interface. */
  196. int enable_network;
  197. int enable_interface;
  198. /* RIP is running on this interface. */
  199. int running;
  200. /* RIP version control. */
  201. int ri_send;
  202. int ri_receive;
  203. /* RIPv2 authentication type. */
  204. int auth_type;
  205. /* RIPv2 authentication string. */
  206. char *auth_str;
  207. /* RIPv2 authentication key chain. */
  208. char *key_chain;
  209. /* value to use for md5->auth_len */
  210. u_int8_t md5_auth_len;
  211. /* Split horizon flag. */
  212. split_horizon_policy_t split_horizon;
  213. split_horizon_policy_t split_horizon_default;
  214. /* For filter type slot. */
  215. #define RIP_FILTER_IN 0
  216. #define RIP_FILTER_OUT 1
  217. #define RIP_FILTER_MAX 2
  218. /* Access-list. */
  219. struct access_list *list[RIP_FILTER_MAX];
  220. /* Prefix-list. */
  221. struct prefix_list *prefix[RIP_FILTER_MAX];
  222. /* Route-map. */
  223. struct route_map *routemap[RIP_FILTER_MAX];
  224. /* Wake up thread. */
  225. struct thread *t_wakeup;
  226. /* Interface statistics. */
  227. int recv_badpackets;
  228. int recv_badroutes;
  229. int sent_updates;
  230. /* Passive interface. */
  231. int passive;
  232. };
  233. /* RIP peer information. */
  234. struct rip_peer
  235. {
  236. /* Peer address. */
  237. struct in_addr addr;
  238. /* Peer RIP tag value. */
  239. int domain;
  240. /* Last update time. */
  241. time_t uptime;
  242. /* Peer RIP version. */
  243. u_char version;
  244. /* Statistics. */
  245. int recv_badpackets;
  246. int recv_badroutes;
  247. /* Timeout thread. */
  248. struct thread *t_timeout;
  249. };
  250. struct rip_md5_info
  251. {
  252. u_int16_t family;
  253. u_int16_t type;
  254. u_int16_t packet_len;
  255. u_char keyid;
  256. u_char auth_len;
  257. u_int32_t sequence;
  258. u_int32_t reserv1;
  259. u_int32_t reserv2;
  260. };
  261. struct rip_md5_data
  262. {
  263. u_int16_t family;
  264. u_int16_t type;
  265. u_char digest[16];
  266. };
  267. /* RIP accepet/announce methods. */
  268. #define RI_RIP_UNSPEC 0
  269. #define RI_RIP_VERSION_1 1
  270. #define RI_RIP_VERSION_2 2
  271. #define RI_RIP_VERSION_1_AND_2 3
  272. /* N.B. stuff will break if
  273. (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
  274. /* Default value for "default-metric" command. */
  275. #define RIP_DEFAULT_METRIC_DEFAULT 1
  276. /* RIP event. */
  277. enum rip_event
  278. {
  279. RIP_READ,
  280. RIP_UPDATE_EVENT,
  281. RIP_TRIGGERED_UPDATE,
  282. };
  283. /* Macro for timer turn on. */
  284. #define RIP_TIMER_ON(T,F,V) \
  285. do { \
  286. if (!(T)) \
  287. (T) = thread_add_timer (master, (F), rinfo, (V)); \
  288. } while (0)
  289. /* Macro for timer turn off. */
  290. #define RIP_TIMER_OFF(X) \
  291. do { \
  292. if (X) \
  293. { \
  294. thread_cancel (X); \
  295. (X) = NULL; \
  296. } \
  297. } while (0)
  298. /* Prototypes. */
  299. extern void rip_init (void);
  300. extern void rip_reset (void);
  301. extern void rip_clean (void);
  302. extern void rip_clean_network (void);
  303. extern void rip_interface_clean (void);
  304. extern void rip_interface_reset (void);
  305. extern void rip_passive_nondefault_clean (void);
  306. extern void rip_if_init (void);
  307. extern void rip_if_down_all (void);
  308. extern void rip_route_map_init (void);
  309. extern void rip_route_map_reset (void);
  310. extern void rip_snmp_init (void);
  311. extern void rip_zclient_init (void);
  312. extern void rip_zclient_start (void);
  313. extern void rip_zclient_reset (void);
  314. extern void rip_offset_init (void);
  315. extern int if_check_address (struct in_addr addr);
  316. extern int if_valid_neighbor (struct in_addr addr);
  317. extern int rip_request_send (struct sockaddr_in *, struct interface *, u_char,
  318. struct connected *);
  319. extern int rip_neighbor_lookup (struct sockaddr_in *);
  320. extern void rip_redistribute_add (int, int, struct prefix_ipv4 *, unsigned int,
  321. struct in_addr *, unsigned int, unsigned char);
  322. extern void rip_redistribute_delete (int, int, struct prefix_ipv4 *, unsigned int);
  323. extern void rip_redistribute_withdraw (int);
  324. extern void rip_zebra_ipv4_add (struct prefix_ipv4 *, struct in_addr *, u_int32_t, u_char);
  325. extern void rip_zebra_ipv4_delete (struct prefix_ipv4 *, struct in_addr *, u_int32_t);
  326. extern void rip_interface_multicast_set (int, struct connected *);
  327. extern void rip_distribute_update_interface (struct interface *);
  328. extern void rip_if_rmap_update_interface (struct interface *);
  329. extern int config_write_rip_network (struct vty *, int);
  330. extern int config_write_rip_offset_list (struct vty *);
  331. extern int config_write_rip_redistribute (struct vty *, int);
  332. extern void rip_peer_init (void);
  333. extern void rip_peer_update (struct sockaddr_in *, u_char);
  334. extern void rip_peer_bad_route (struct sockaddr_in *);
  335. extern void rip_peer_bad_packet (struct sockaddr_in *);
  336. extern void rip_peer_display (struct vty *);
  337. extern struct rip_peer *rip_peer_lookup (struct in_addr *);
  338. extern struct rip_peer *rip_peer_lookup_next (struct in_addr *);
  339. extern int rip_offset_list_apply_in (struct prefix_ipv4 *, struct interface *, u_int32_t *);
  340. extern int rip_offset_list_apply_out (struct prefix_ipv4 *, struct interface *, u_int32_t *);
  341. extern void rip_offset_clean (void);
  342. extern void rip_info_free (struct rip_info *);
  343. extern u_char rip_distance_apply (struct rip_info *);
  344. extern void rip_redistribute_clean (void);
  345. extern void rip_ifaddr_add (struct interface *, struct connected *);
  346. extern void rip_ifaddr_delete (struct interface *, struct connected *);
  347. /* There is only one rip strucutre. */
  348. extern struct rip *rip;
  349. /* Master thread strucutre. */
  350. extern struct thread_master *master;
  351. /* RIP statistics for SNMP. */
  352. extern long rip_global_route_changes;
  353. extern long rip_global_queries;
  354. #endif /* _ZEBRA_RIP_H */