blob: 5a825ea5c819d0ada8f27e6d7846b68d95180bca [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
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
23#ifndef _ZEBRA_OSPF_INTERFACE_H
24#define _ZEBRA_OSPF_INTERFACE_H
25
paul6c835672004-10-11 11:00:30 +000026#include "ospfd/ospf_packet.h"
Paul Jakma9c27ef92006-05-04 07:32:57 +000027#include "ospfd/ospf_spf.h"
paul718e3742002-12-13 20:15:29 +000028
29#define IF_OSPF_IF_INFO(I) ((struct ospf_if_info *)((I)->info))
30#define IF_DEF_PARAMS(I) (IF_OSPF_IF_INFO (I)->def_params)
31#define IF_OIFS(I) (IF_OSPF_IF_INFO (I)->oifs)
32#define IF_OIFS_PARAMS(I) (IF_OSPF_IF_INFO (I)->params)
33
34#define OSPF_IF_PARAM_CONFIGURED(S, P) ((S) && (S)->P##__config)
35#define OSPF_IF_PARAM(O, P) \
36 (OSPF_IF_PARAM_CONFIGURED ((O)->params, P)?\
37 (O)->params->P:IF_DEF_PARAMS((O)->ifp)->P)
38
39#define DECLARE_IF_PARAM(T, P) T P; u_char P##__config:1
40#define UNSET_IF_PARAM(S, P) ((S)->P##__config) = 0
41#define SET_IF_PARAM(S, P) ((S)->P##__config) = 1
42
43struct ospf_if_params
44{
45 DECLARE_IF_PARAM (u_int32_t, transmit_delay); /* Interface Transmisson Delay */
46 DECLARE_IF_PARAM (u_int32_t, output_cost_cmd);/* Command Interface Output Cost */
47 DECLARE_IF_PARAM (u_int32_t, retransmit_interval); /* Retransmission Interval */
ajsba6454e2005-02-08 15:37:30 +000048 DECLARE_IF_PARAM (u_char, passive_interface); /* OSPF Interface is passive: no sending or receiving (no need to join multicast groups) */
paul718e3742002-12-13 20:15:29 +000049 DECLARE_IF_PARAM (u_char, priority); /* OSPF Interface priority */
50 DECLARE_IF_PARAM (u_char, type); /* type of interface */
51#define OSPF_IF_ACTIVE 0
52#define OSPF_IF_PASSIVE 1
53
54 DECLARE_IF_PARAM (u_int32_t, v_hello); /* Hello Interval */
55 DECLARE_IF_PARAM (u_int32_t, v_wait); /* Router Dead Interval */
56
vincentba682532005-09-29 13:52:57 +000057 /* MTU mismatch check (see RFC2328, chap 10.6) */
58 DECLARE_IF_PARAM (u_char, mtu_ignore);
paulf9ad9372005-10-21 00:45:17 +000059
60 /* Fast-Hellos */
61 DECLARE_IF_PARAM (u_char, fast_hello);
62
paul718e3742002-12-13 20:15:29 +000063 /* Authentication data. */
64 u_char auth_simple[OSPF_AUTH_SIMPLE_SIZE + 1]; /* Simple password. */
65 u_char auth_simple__config:1;
66
hasso52dc7ee2004-09-23 19:18:23 +000067 DECLARE_IF_PARAM (struct list *, auth_crypt); /* List of Auth cryptographic data. */
paul718e3742002-12-13 20:15:29 +000068 DECLARE_IF_PARAM (int, auth_type); /* OSPF authentication type */
69};
70
Paul Jakma429ac782006-06-15 18:40:49 +000071enum
72{
73 MEMBER_ALLROUTERS = 0,
74 MEMBER_DROUTERS,
75 MEMBER_MAX,
76};
77
paul718e3742002-12-13 20:15:29 +000078struct ospf_if_info
79{
80 struct ospf_if_params *def_params;
81 struct route_table *params;
82 struct route_table *oifs;
Paul Jakma429ac782006-06-15 18:40:49 +000083 unsigned int membership_counts[MEMBER_MAX]; /* multicast group refcnts */
paul718e3742002-12-13 20:15:29 +000084};
85
86struct ospf_interface;
87
88struct ospf_vl_data
89{
90 struct in_addr vl_peer; /* Router-ID of the peer for VLs. */
91 struct in_addr vl_area_id; /* Transit area for this VL. */
92 int format; /* area ID format */
93 struct ospf_interface *vl_oi; /* Interface data structure for the VL. */
Paul Jakma9c27ef92006-05-04 07:32:57 +000094 struct vertex_nexthop nexthop; /* Nexthop router and oi to use */
paul718e3742002-12-13 20:15:29 +000095 struct in_addr peer_addr; /* Address used to reach the peer. */
96 u_char flags;
97};
98
99
100#define OSPF_VL_MAX_COUNT 256
101#define OSPF_VL_MTU 1500
102
103#define OSPF_VL_FLAG_APPROVED 0x01
104
105struct crypt_key
106{
107 u_char key_id;
108 u_char auth_key[OSPF_AUTH_MD5_SIZE + 1];
109};
110
111/* OSPF interface structure. */
112struct ospf_interface
113{
114 /* This interface's parent ospf instance. */
115 struct ospf *ospf;
116
117 /* OSPF Area. */
118 struct ospf_area *area;
119
120 /* Interface data from zebra. */
121 struct interface *ifp;
122 struct ospf_vl_data *vl_data; /* Data for Virtual Link */
123
124 /* Packet send buffer. */
125 struct ospf_fifo *obuf; /* Output queue */
126
127 /* OSPF Network Type. */
128 u_char type;
129#define OSPF_IFTYPE_NONE 0
130#define OSPF_IFTYPE_POINTOPOINT 1
131#define OSPF_IFTYPE_BROADCAST 2
132#define OSPF_IFTYPE_NBMA 3
133#define OSPF_IFTYPE_POINTOMULTIPOINT 4
134#define OSPF_IFTYPE_VIRTUALLINK 5
135#define OSPF_IFTYPE_LOOPBACK 6
136#define OSPF_IFTYPE_MAX 7
137
138 /* State of Interface State Machine. */
139 u_char state;
140
ajsba6454e2005-02-08 15:37:30 +0000141 /* To which multicast groups do we currently belong? */
142 u_char multicast_memberships;
Paul Jakma429ac782006-06-15 18:40:49 +0000143#define OI_MEMBER_FLAG(M) (1 << (M))
144#define OI_MEMBER_COUNT(O,M) (IF_OSPF_IF_INFO(oi->ifp)->membership_counts[(M)])
145#define OI_MEMBER_CHECK(O,M) \
146 (CHECK_FLAG((O)->multicast_memberships, OI_MEMBER_FLAG(M)))
147#define OI_MEMBER_JOINED(O,M) \
148 do { \
149 SET_FLAG ((O)->multicast_memberships, OI_MEMBER_FLAG(M)); \
150 IF_OSPF_IF_INFO((O)->ifp)->membership_counts[(M)]++; \
151 } while (0)
152#define OI_MEMBER_LEFT(O,M) \
153 do { \
154 UNSET_FLAG ((O)->multicast_memberships, OI_MEMBER_FLAG(M)); \
155 IF_OSPF_IF_INFO((O)->ifp)->membership_counts[(M)]--; \
156 } while (0)
ajsba6454e2005-02-08 15:37:30 +0000157
ajs8cfde372005-02-08 15:59:16 +0000158 struct prefix *address; /* Interface prefix */
159 struct connected *connected; /* Pointer to connected */
160
paul718e3742002-12-13 20:15:29 +0000161 /* Configured varables. */
162 struct ospf_if_params *params;
163 u_int32_t crypt_seqnum; /* Cryptographic Sequence Number */
164 u_int32_t output_cost; /* Acutual Interface Output Cost */
165
166 /* Neighbor information. */
167 struct route_table *nbrs; /* OSPF Neighbor List */
168 struct ospf_neighbor *nbr_self; /* Neighbor Self */
169#define DR(I) ((I)->nbr_self->d_router)
170#define BDR(I) ((I)->nbr_self->bd_router)
171#define OPTIONS(I) ((I)->nbr_self->options)
172#define PRIORITY(I) ((I)->nbr_self->priority)
173
174 /* List of configured NBMA neighbor. */
hasso52dc7ee2004-09-23 19:18:23 +0000175 struct list *nbr_nbma;
paul718e3742002-12-13 20:15:29 +0000176
177 /* self-originated LSAs. */
178 struct ospf_lsa *network_lsa_self; /* network-LSA. */
179#ifdef HAVE_OPAQUE_LSA
paul87d6f872004-09-24 08:01:38 +0000180 struct list *opaque_lsa_self; /* Type-9 Opaque-LSAs */
paul718e3742002-12-13 20:15:29 +0000181#endif /* HAVE_OPAQUE_LSA */
182
183 struct route_table *ls_upd_queue;
184
hasso52dc7ee2004-09-23 19:18:23 +0000185 struct list *ls_ack; /* Link State Acknowledgment list. */
paul718e3742002-12-13 20:15:29 +0000186
187 struct
188 {
hasso52dc7ee2004-09-23 19:18:23 +0000189 struct list *ls_ack;
paul718e3742002-12-13 20:15:29 +0000190 struct in_addr dst;
191 } ls_ack_direct;
192
193 /* Timer values. */
194 u_int32_t v_ls_ack; /* Delayed Link State Acknowledgment */
195
196 /* Threads. */
197 struct thread *t_hello; /* timer */
198 struct thread *t_wait; /* timer */
199 struct thread *t_ls_ack; /* timer */
200 struct thread *t_ls_ack_direct; /* event */
201 struct thread *t_ls_upd_event; /* event */
202 struct thread *t_network_lsa_self; /* self-originated network-LSA
203 reflesh thread. timer */
204#ifdef HAVE_OPAQUE_LSA
205 struct thread *t_opaque_lsa_self; /* Type-9 Opaque-LSAs */
206#endif /* HAVE_OPAQUE_LSA */
207
208 int on_write_q;
209
210 /* Statistics fields. */
211 u_int32_t hello_in; /* Hello message input count. */
212 u_int32_t hello_out; /* Hello message output count. */
213 u_int32_t db_desc_in; /* database desc. message input count. */
214 u_int32_t db_desc_out; /* database desc. message output count. */
215 u_int32_t ls_req_in; /* LS request message input count. */
216 u_int32_t ls_req_out; /* LS request message output count. */
217 u_int32_t ls_upd_in; /* LS update message input count. */
218 u_int32_t ls_upd_out; /* LS update message output count. */
219 u_int32_t ls_ack_in; /* LS Ack message input count. */
220 u_int32_t ls_ack_out; /* LS Ack message output count. */
221 u_int32_t discarded; /* discarded input count by error. */
222 u_int32_t state_change; /* Number of status change. */
223
hasso2db3d052004-02-11 21:52:13 +0000224 u_int32_t full_nbrs;
paul718e3742002-12-13 20:15:29 +0000225};
226
227/* Prototypes. */
paul4dadc292005-05-06 21:37:42 +0000228extern char *ospf_if_name (struct ospf_interface *);
229extern struct ospf_interface *ospf_if_new (struct ospf *, struct interface *,
230 struct prefix *);
231extern void ospf_if_cleanup (struct ospf_interface *);
232extern void ospf_if_free (struct ospf_interface *);
233extern int ospf_if_up (struct ospf_interface *);
234extern int ospf_if_down (struct ospf_interface *);
paul718e3742002-12-13 20:15:29 +0000235
paul4dadc292005-05-06 21:37:42 +0000236extern int ospf_if_is_up (struct ospf_interface *);
237extern struct ospf_interface *ospf_if_exists (struct ospf_interface *);
238extern struct ospf_interface *ospf_if_lookup_by_local_addr (struct ospf *,
239 struct interface
240 *,
241 struct in_addr);
242extern struct ospf_interface *ospf_if_lookup_by_prefix (struct ospf *,
243 struct prefix_ipv4 *);
244extern struct ospf_interface *ospf_if_addr_local (struct in_addr);
245extern struct ospf_interface *ospf_if_lookup_recv_if (struct ospf *,
246 struct in_addr);
247extern struct ospf_interface *ospf_if_is_configured (struct ospf *,
248 struct in_addr *);
249
250extern struct ospf_if_params *ospf_lookup_if_params (struct interface *,
hasso2db3d052004-02-11 21:52:13 +0000251 struct in_addr);
paul4dadc292005-05-06 21:37:42 +0000252extern struct ospf_if_params *ospf_get_if_params (struct interface *,
253 struct in_addr);
254extern void ospf_del_if_params (struct ospf_if_params *);
255extern void ospf_free_if_params (struct interface *, struct in_addr);
256extern void ospf_if_update_params (struct interface *, struct in_addr);
paul718e3742002-12-13 20:15:29 +0000257
paul4dadc292005-05-06 21:37:42 +0000258extern int ospf_if_new_hook (struct interface *);
259extern void ospf_if_init (void);
260extern void ospf_if_stream_set (struct ospf_interface *);
261extern void ospf_if_stream_unset (struct ospf_interface *);
262extern void ospf_if_reset_variables (struct ospf_interface *);
263extern int ospf_if_is_enable (struct ospf_interface *);
264extern int ospf_if_get_output_cost (struct ospf_interface *);
265extern void ospf_if_recalculate_output_cost (struct interface *);
paul718e3742002-12-13 20:15:29 +0000266
ajsa608bbf2005-03-29 17:03:49 +0000267/* Simulate down/up on the interface. */
268extern void ospf_if_reset (struct interface *);
269
paul4dadc292005-05-06 21:37:42 +0000270extern struct ospf_interface *ospf_vl_new (struct ospf *,
271 struct ospf_vl_data *);
272extern struct ospf_vl_data *ospf_vl_data_new (struct ospf_area *,
273 struct in_addr);
Paul Jakma9c27ef92006-05-04 07:32:57 +0000274extern struct ospf_vl_data *ospf_vl_lookup (struct ospf *, struct ospf_area *,
paul4dadc292005-05-06 21:37:42 +0000275 struct in_addr);
276extern void ospf_vl_data_free (struct ospf_vl_data *);
277extern void ospf_vl_add (struct ospf *, struct ospf_vl_data *);
278extern void ospf_vl_delete (struct ospf *, struct ospf_vl_data *);
279extern void ospf_vl_up_check (struct ospf_area *, struct in_addr,
280 struct vertex *);
281extern void ospf_vl_unapprove (struct ospf *);
282extern void ospf_vl_shut_unapproved (struct ospf *);
283extern int ospf_full_virtual_nbrs (struct ospf_area *);
284extern int ospf_vls_in_area (struct ospf_area *);
paul718e3742002-12-13 20:15:29 +0000285
paul4dadc292005-05-06 21:37:42 +0000286extern struct crypt_key *ospf_crypt_key_lookup (struct list *, u_char);
287extern struct crypt_key *ospf_crypt_key_new (void);
288extern void ospf_crypt_key_add (struct list *, struct crypt_key *);
289extern int ospf_crypt_key_delete (struct list *, u_char);
paul718e3742002-12-13 20:15:29 +0000290
paul4dadc292005-05-06 21:37:42 +0000291extern u_char ospf_default_iftype (struct interface *ifp);
ajsbc18d612004-12-15 15:07:19 +0000292
ajsba6454e2005-02-08 15:37:30 +0000293/* Set all multicast memberships appropriately based on the type and
294 state of the interface. */
paul4dadc292005-05-06 21:37:42 +0000295extern void ospf_if_set_multicast (struct ospf_interface *);
ajsba6454e2005-02-08 15:37:30 +0000296
paul718e3742002-12-13 20:15:29 +0000297#endif /* _ZEBRA_OSPF_INTERFACE_H */