ospf_interface.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * OSPF Interface functions.
  3. * Copyright (C) 1999 Toshiaki Takada
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published
  9. * by the Free Software Foundation; either version 2, or (at your
  10. * option) any 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
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. */
  22. #ifndef _ZEBRA_OSPF_INTERFACE_H
  23. #define _ZEBRA_OSPF_INTERFACE_H
  24. #include "ospfd/ospf_packet.h"
  25. #include "ospfd/ospf_spf.h"
  26. #define IF_OSPF_IF_INFO(I) ((struct ospf_if_info *)((I)->info))
  27. #define IF_DEF_PARAMS(I) (IF_OSPF_IF_INFO (I)->def_params)
  28. #define IF_OIFS(I) (IF_OSPF_IF_INFO (I)->oifs)
  29. #define IF_OIFS_PARAMS(I) (IF_OSPF_IF_INFO (I)->params)
  30. /* Despite the name, this macro probably is for specialist use only */
  31. #define OSPF_IF_PARAM_CONFIGURED(S, P) ((S) && (S)->P##__config)
  32. /* Test whether an OSPF interface parameter is set, generally, given some
  33. * existing ospf interface
  34. */
  35. #define OSPF_IF_PARAM_IS_SET(O,P) \
  36. (OSPF_IF_PARAM_CONFIGURED ((O)->params, P) || \
  37. OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS((O)->ifp)->P))
  38. #define OSPF_IF_PARAM(O, P) \
  39. (OSPF_IF_PARAM_CONFIGURED ((O)->params, P)?\
  40. (O)->params->P:IF_DEF_PARAMS((O)->ifp)->P)
  41. #define DECLARE_IF_PARAM(T, P) T P; u_char P##__config:1
  42. #define UNSET_IF_PARAM(S, P) ((S)->P##__config) = 0
  43. #define SET_IF_PARAM(S, P) ((S)->P##__config) = 1
  44. struct ospf_if_params
  45. {
  46. DECLARE_IF_PARAM (u_int32_t, transmit_delay); /* Interface Transmisson Delay */
  47. DECLARE_IF_PARAM (u_int32_t, output_cost_cmd);/* Command Interface Output Cost */
  48. DECLARE_IF_PARAM (u_int32_t, retransmit_interval); /* Retransmission Interval */
  49. DECLARE_IF_PARAM (u_char, passive_interface); /* OSPF Interface is passive: no sending or receiving (no need to join multicast groups) */
  50. DECLARE_IF_PARAM (u_char, priority); /* OSPF Interface priority */
  51. DECLARE_IF_PARAM (struct in_addr, if_area); /* Enable OSPF on this interface with area if_area */
  52. DECLARE_IF_PARAM (u_char, type); /* type of interface */
  53. #define OSPF_IF_ACTIVE 0
  54. #define OSPF_IF_PASSIVE 1
  55. #define OSPF_IF_PASSIVE_STATUS(O) \
  56. (OSPF_IF_PARAM_CONFIGURED((O)->params, passive_interface) ? \
  57. (O)->params->passive_interface : \
  58. (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS((O)->ifp), passive_interface) ? \
  59. IF_DEF_PARAMS((O)->ifp)->passive_interface : \
  60. (O)->ospf->passive_interface_default))
  61. DECLARE_IF_PARAM (u_int32_t, v_hello); /* Hello Interval */
  62. DECLARE_IF_PARAM (u_int32_t, v_wait); /* Router Dead Interval */
  63. /* MTU mismatch check (see RFC2328, chap 10.6) */
  64. DECLARE_IF_PARAM (u_char, mtu_ignore);
  65. /* Fast-Hellos */
  66. DECLARE_IF_PARAM (u_char, fast_hello);
  67. /* Authentication data. */
  68. u_char auth_simple[OSPF_AUTH_SIMPLE_SIZE + 1]; /* Simple password. */
  69. u_char auth_simple__config:1;
  70. DECLARE_IF_PARAM (struct list *, auth_crypt); /* List of Auth cryptographic data. */
  71. DECLARE_IF_PARAM (int, auth_type); /* OSPF authentication type */
  72. /* Other, non-configuration state */
  73. u_int32_t network_lsa_seqnum; /* Network LSA seqnum */
  74. };
  75. enum
  76. {
  77. MEMBER_ALLROUTERS = 0,
  78. MEMBER_DROUTERS,
  79. MEMBER_MAX,
  80. };
  81. struct ospf_if_info
  82. {
  83. struct ospf_if_params *def_params;
  84. struct route_table *params;
  85. struct route_table *oifs;
  86. unsigned int membership_counts[MEMBER_MAX]; /* multicast group refcnts */
  87. };
  88. struct ospf_interface;
  89. struct ospf_vl_data
  90. {
  91. struct in_addr vl_peer; /* Router-ID of the peer for VLs. */
  92. struct in_addr vl_area_id; /* Transit area for this VL. */
  93. int format; /* area ID format */
  94. struct ospf_interface *vl_oi; /* Interface data structure for the VL. */
  95. struct vertex_nexthop nexthop; /* Nexthop router and oi to use */
  96. struct in_addr peer_addr; /* Address used to reach the peer. */
  97. u_char flags;
  98. };
  99. #define OSPF_VL_MAX_COUNT 256
  100. #define OSPF_VL_MTU 1500
  101. #define OSPF_VL_FLAG_APPROVED 0x01
  102. struct crypt_key
  103. {
  104. u_char key_id;
  105. u_char auth_key[OSPF_AUTH_MD5_SIZE + 1];
  106. };
  107. /* OSPF interface structure. */
  108. struct ospf_interface
  109. {
  110. /* This interface's parent ospf instance. */
  111. struct ospf *ospf;
  112. /* OSPF Area. */
  113. struct ospf_area *area;
  114. /* Position range in Router LSA */
  115. uint16_t lsa_pos_beg; /* inclusive, >= */
  116. uint16_t lsa_pos_end; /* exclusive, < */
  117. /* Interface data from zebra. */
  118. struct interface *ifp;
  119. struct ospf_vl_data *vl_data; /* Data for Virtual Link */
  120. /* Packet send buffer. */
  121. struct ospf_fifo *obuf; /* Output queue */
  122. /* OSPF Network Type. */
  123. u_char type;
  124. /* State of Interface State Machine. */
  125. u_char state;
  126. /* To which multicast groups do we currently belong? */
  127. u_char multicast_memberships;
  128. #define OI_MEMBER_FLAG(M) (1 << (M))
  129. #define OI_MEMBER_COUNT(O,M) (IF_OSPF_IF_INFO(oi->ifp)->membership_counts[(M)])
  130. #define OI_MEMBER_CHECK(O,M) \
  131. (CHECK_FLAG((O)->multicast_memberships, OI_MEMBER_FLAG(M)))
  132. #define OI_MEMBER_JOINED(O,M) \
  133. do { \
  134. SET_FLAG ((O)->multicast_memberships, OI_MEMBER_FLAG(M)); \
  135. IF_OSPF_IF_INFO((O)->ifp)->membership_counts[(M)]++; \
  136. } while (0)
  137. #define OI_MEMBER_LEFT(O,M) \
  138. do { \
  139. UNSET_FLAG ((O)->multicast_memberships, OI_MEMBER_FLAG(M)); \
  140. IF_OSPF_IF_INFO((O)->ifp)->membership_counts[(M)]--; \
  141. } while (0)
  142. struct prefix *address; /* Interface prefix */
  143. struct connected *connected; /* Pointer to connected */
  144. /* Configured varables. */
  145. struct ospf_if_params *params;
  146. u_int32_t crypt_seqnum; /* Cryptographic Sequence Number */
  147. u_int32_t output_cost; /* Acutual Interface Output Cost */
  148. /* Neighbor information. */
  149. struct route_table *nbrs; /* OSPF Neighbor List */
  150. struct ospf_neighbor *nbr_self; /* Neighbor Self */
  151. #define DR(I) ((I)->nbr_self->d_router)
  152. #define BDR(I) ((I)->nbr_self->bd_router)
  153. #define OPTIONS(I) ((I)->nbr_self->options)
  154. #define PRIORITY(I) ((I)->nbr_self->priority)
  155. /* List of configured NBMA neighbor. */
  156. struct list *nbr_nbma;
  157. /* self-originated LSAs. */
  158. struct ospf_lsa *network_lsa_self; /* network-LSA. */
  159. struct list *opaque_lsa_self; /* Type-9 Opaque-LSAs */
  160. struct route_table *ls_upd_queue;
  161. struct list *ls_ack; /* Link State Acknowledgment list. */
  162. struct
  163. {
  164. struct list *ls_ack;
  165. struct in_addr dst;
  166. } ls_ack_direct;
  167. /* Timer values. */
  168. u_int32_t v_ls_ack; /* Delayed Link State Acknowledgment */
  169. /* Threads. */
  170. struct thread *t_hello; /* timer */
  171. struct thread *t_wait; /* timer */
  172. struct thread *t_ls_ack; /* timer */
  173. struct thread *t_ls_ack_direct; /* event */
  174. struct thread *t_ls_upd_event; /* event */
  175. struct thread *t_opaque_lsa_self; /* Type-9 Opaque-LSAs */
  176. int on_write_q;
  177. /* Statistics fields. */
  178. u_int32_t hello_in; /* Hello message input count. */
  179. u_int32_t hello_out; /* Hello message output count. */
  180. u_int32_t db_desc_in; /* database desc. message input count. */
  181. u_int32_t db_desc_out; /* database desc. message output count. */
  182. u_int32_t ls_req_in; /* LS request message input count. */
  183. u_int32_t ls_req_out; /* LS request message output count. */
  184. u_int32_t ls_upd_in; /* LS update message input count. */
  185. u_int32_t ls_upd_out; /* LS update message output count. */
  186. u_int32_t ls_ack_in; /* LS Ack message input count. */
  187. u_int32_t ls_ack_out; /* LS Ack message output count. */
  188. u_int32_t discarded; /* discarded input count by error. */
  189. u_int32_t state_change; /* Number of status change. */
  190. u_int32_t full_nbrs;
  191. };
  192. /* Prototypes. */
  193. extern char *ospf_if_name (struct ospf_interface *);
  194. extern struct ospf_interface *ospf_if_new (struct ospf *, struct interface *,
  195. struct prefix *);
  196. extern void ospf_if_cleanup (struct ospf_interface *);
  197. extern void ospf_if_free (struct ospf_interface *);
  198. extern int ospf_if_up (struct ospf_interface *);
  199. extern int ospf_if_down (struct ospf_interface *);
  200. extern int ospf_if_is_up (struct ospf_interface *);
  201. extern struct ospf_interface *ospf_if_exists (struct ospf_interface *);
  202. extern struct ospf_interface *ospf_if_lookup_by_lsa_pos (struct ospf_area *,
  203. int);
  204. extern struct ospf_interface *ospf_if_lookup_by_local_addr (struct ospf *,
  205. struct interface
  206. *,
  207. struct in_addr);
  208. extern struct ospf_interface *ospf_if_lookup_by_prefix (struct ospf *,
  209. struct prefix_ipv4 *);
  210. extern struct ospf_interface *ospf_if_table_lookup (struct interface *,
  211. struct prefix *);
  212. extern struct ospf_interface *ospf_if_addr_local (struct in_addr);
  213. extern struct ospf_interface *ospf_if_lookup_recv_if (struct ospf *,
  214. struct in_addr,
  215. struct interface *);
  216. extern struct ospf_interface *ospf_if_is_configured (struct ospf *,
  217. struct in_addr *);
  218. extern struct ospf_if_params *ospf_lookup_if_params (struct interface *,
  219. struct in_addr);
  220. extern struct ospf_if_params *ospf_get_if_params (struct interface *,
  221. struct in_addr);
  222. extern void ospf_del_if_params (struct ospf_if_params *);
  223. extern void ospf_free_if_params (struct interface *, struct in_addr);
  224. extern void ospf_if_update_params (struct interface *, struct in_addr);
  225. extern int ospf_if_new_hook (struct interface *);
  226. extern void ospf_if_init (void);
  227. extern void ospf_if_stream_set (struct ospf_interface *);
  228. extern void ospf_if_stream_unset (struct ospf_interface *);
  229. extern void ospf_if_reset_variables (struct ospf_interface *);
  230. extern void ospf_if_reset_type (struct interface *, u_char type);
  231. extern int ospf_if_is_enable (struct ospf_interface *);
  232. extern int ospf_if_get_output_cost (struct ospf_interface *);
  233. extern void ospf_if_recalculate_output_cost (struct interface *);
  234. /* Simulate down/up on the interface. */
  235. extern void ospf_if_reset (struct interface *);
  236. extern struct ospf_interface *ospf_vl_new (struct ospf *,
  237. struct ospf_vl_data *);
  238. extern struct ospf_vl_data *ospf_vl_data_new (struct ospf_area *,
  239. struct in_addr);
  240. extern struct ospf_vl_data *ospf_vl_lookup (struct ospf *, struct ospf_area *,
  241. struct in_addr);
  242. extern void ospf_vl_data_free (struct ospf_vl_data *);
  243. extern void ospf_vl_add (struct ospf *, struct ospf_vl_data *);
  244. extern void ospf_vl_delete (struct ospf *, struct ospf_vl_data *);
  245. extern void ospf_vl_up_check (struct ospf_area *, struct in_addr,
  246. struct vertex *);
  247. extern void ospf_vl_unapprove (struct ospf *);
  248. extern void ospf_vl_shut_unapproved (struct ospf *);
  249. extern int ospf_full_virtual_nbrs (struct ospf_area *);
  250. extern int ospf_vls_in_area (struct ospf_area *);
  251. extern struct crypt_key *ospf_crypt_key_lookup (struct list *, u_char);
  252. extern struct crypt_key *ospf_crypt_key_new (void);
  253. extern void ospf_crypt_key_add (struct list *, struct crypt_key *);
  254. extern int ospf_crypt_key_delete (struct list *, u_char);
  255. extern u_char ospf_default_iftype (struct interface *ifp);
  256. /* Set all multicast memberships appropriately based on the type and
  257. state of the interface. */
  258. extern void ospf_if_set_multicast (struct ospf_interface *);
  259. #endif /* _ZEBRA_OSPF_INTERFACE_H */