blob: 2ed426f97940ea0546e59e3f65750642d3c2dd6e [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)
Paul Jakma8a667cf2009-08-27 16:51:42 +010033
34/* Despite the name, this macro probably is for specialist use only */
paul718e3742002-12-13 20:15:29 +000035#define OSPF_IF_PARAM_CONFIGURED(S, P) ((S) && (S)->P##__config)
Paul Jakma8a667cf2009-08-27 16:51:42 +010036
37/* Test whether an OSPF interface parameter is set, generally, given some
38 * existing ospf interface
39 */
40#define OSPF_IF_PARAM_IS_SET(O,P) \
41 (OSPF_IF_PARAM_CONFIGURED ((O)->params, P) || \
42 OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS((O)->ifp)->P))
43
paul718e3742002-12-13 20:15:29 +000044#define OSPF_IF_PARAM(O, P) \
45 (OSPF_IF_PARAM_CONFIGURED ((O)->params, P)?\
46 (O)->params->P:IF_DEF_PARAMS((O)->ifp)->P)
47
48#define DECLARE_IF_PARAM(T, P) T P; u_char P##__config:1
49#define UNSET_IF_PARAM(S, P) ((S)->P##__config) = 0
50#define SET_IF_PARAM(S, P) ((S)->P##__config) = 1
51
52struct ospf_if_params
53{
54 DECLARE_IF_PARAM (u_int32_t, transmit_delay); /* Interface Transmisson Delay */
55 DECLARE_IF_PARAM (u_int32_t, output_cost_cmd);/* Command Interface Output Cost */
56 DECLARE_IF_PARAM (u_int32_t, retransmit_interval); /* Retransmission Interval */
ajsba6454e2005-02-08 15:37:30 +000057 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 +000058 DECLARE_IF_PARAM (u_char, priority); /* OSPF Interface priority */
Joakim Tjernlund738bce72009-08-07 13:48:15 +020059 DECLARE_IF_PARAM (struct in_addr, if_area); /* Enable OSPF on this interface with area if_area */
paul718e3742002-12-13 20:15:29 +000060 DECLARE_IF_PARAM (u_char, type); /* type of interface */
61#define OSPF_IF_ACTIVE 0
62#define OSPF_IF_PASSIVE 1
Paul Jakma7ffa8fa2006-10-22 20:07:53 +000063
64#define OSPF_IF_PASSIVE_STATUS(O) \
65 (OSPF_IF_PARAM_CONFIGURED((O)->params, passive_interface) ? \
66 (O)->params->passive_interface : \
67 (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS((O)->ifp), passive_interface) ? \
68 IF_DEF_PARAMS((O)->ifp)->passive_interface : \
69 (O)->ospf->passive_interface_default))
paul718e3742002-12-13 20:15:29 +000070
71 DECLARE_IF_PARAM (u_int32_t, v_hello); /* Hello Interval */
72 DECLARE_IF_PARAM (u_int32_t, v_wait); /* Router Dead Interval */
73
vincentba682532005-09-29 13:52:57 +000074 /* MTU mismatch check (see RFC2328, chap 10.6) */
75 DECLARE_IF_PARAM (u_char, mtu_ignore);
paulf9ad9372005-10-21 00:45:17 +000076
77 /* Fast-Hellos */
78 DECLARE_IF_PARAM (u_char, fast_hello);
79
paul718e3742002-12-13 20:15:29 +000080 /* Authentication data. */
81 u_char auth_simple[OSPF_AUTH_SIMPLE_SIZE + 1]; /* Simple password. */
82 u_char auth_simple__config:1;
83
hasso52dc7ee2004-09-23 19:18:23 +000084 DECLARE_IF_PARAM (struct list *, auth_crypt); /* List of Auth cryptographic data. */
paul718e3742002-12-13 20:15:29 +000085 DECLARE_IF_PARAM (int, auth_type); /* OSPF authentication type */
Paul Jakma7eb5b472009-10-13 16:13:13 +010086
87 /* Other, non-configuration state */
88 u_int32_t network_lsa_seqnum; /* Network LSA seqnum */
paul718e3742002-12-13 20:15:29 +000089};
90
Paul Jakma429ac782006-06-15 18:40:49 +000091enum
92{
93 MEMBER_ALLROUTERS = 0,
94 MEMBER_DROUTERS,
95 MEMBER_MAX,
96};
97
paul718e3742002-12-13 20:15:29 +000098struct ospf_if_info
99{
100 struct ospf_if_params *def_params;
101 struct route_table *params;
102 struct route_table *oifs;
Paul Jakma429ac782006-06-15 18:40:49 +0000103 unsigned int membership_counts[MEMBER_MAX]; /* multicast group refcnts */
paul718e3742002-12-13 20:15:29 +0000104};
105
106struct ospf_interface;
107
108struct ospf_vl_data
109{
110 struct in_addr vl_peer; /* Router-ID of the peer for VLs. */
111 struct in_addr vl_area_id; /* Transit area for this VL. */
112 int format; /* area ID format */
113 struct ospf_interface *vl_oi; /* Interface data structure for the VL. */
Paul Jakma9c27ef92006-05-04 07:32:57 +0000114 struct vertex_nexthop nexthop; /* Nexthop router and oi to use */
paul718e3742002-12-13 20:15:29 +0000115 struct in_addr peer_addr; /* Address used to reach the peer. */
116 u_char flags;
117};
118
119
120#define OSPF_VL_MAX_COUNT 256
121#define OSPF_VL_MTU 1500
122
123#define OSPF_VL_FLAG_APPROVED 0x01
124
125struct crypt_key
126{
127 u_char key_id;
128 u_char auth_key[OSPF_AUTH_MD5_SIZE + 1];
129};
130
131/* OSPF interface structure. */
132struct ospf_interface
133{
134 /* This interface's parent ospf instance. */
135 struct ospf *ospf;
136
137 /* OSPF Area. */
138 struct ospf_area *area;
139
Joakim Tjernlundc81ee5c2012-07-07 17:06:11 +0200140 /* Position range in Router LSA */
141 uint16_t lsa_pos_beg; /* inclusive, >= */
142 uint16_t lsa_pos_end; /* exclusive, < */
143
paul718e3742002-12-13 20:15:29 +0000144 /* Interface data from zebra. */
145 struct interface *ifp;
146 struct ospf_vl_data *vl_data; /* Data for Virtual Link */
147
148 /* Packet send buffer. */
149 struct ospf_fifo *obuf; /* Output queue */
150
151 /* OSPF Network Type. */
152 u_char type;
paul718e3742002-12-13 20:15:29 +0000153
154 /* State of Interface State Machine. */
155 u_char state;
156
ajsba6454e2005-02-08 15:37:30 +0000157 /* To which multicast groups do we currently belong? */
158 u_char multicast_memberships;
Paul Jakma429ac782006-06-15 18:40:49 +0000159#define OI_MEMBER_FLAG(M) (1 << (M))
160#define OI_MEMBER_COUNT(O,M) (IF_OSPF_IF_INFO(oi->ifp)->membership_counts[(M)])
161#define OI_MEMBER_CHECK(O,M) \
162 (CHECK_FLAG((O)->multicast_memberships, OI_MEMBER_FLAG(M)))
163#define OI_MEMBER_JOINED(O,M) \
164 do { \
165 SET_FLAG ((O)->multicast_memberships, OI_MEMBER_FLAG(M)); \
166 IF_OSPF_IF_INFO((O)->ifp)->membership_counts[(M)]++; \
167 } while (0)
168#define OI_MEMBER_LEFT(O,M) \
169 do { \
170 UNSET_FLAG ((O)->multicast_memberships, OI_MEMBER_FLAG(M)); \
171 IF_OSPF_IF_INFO((O)->ifp)->membership_counts[(M)]--; \
172 } while (0)
ajsba6454e2005-02-08 15:37:30 +0000173
ajs8cfde372005-02-08 15:59:16 +0000174 struct prefix *address; /* Interface prefix */
175 struct connected *connected; /* Pointer to connected */
176
paul718e3742002-12-13 20:15:29 +0000177 /* Configured varables. */
178 struct ospf_if_params *params;
Paul Jakma7eb5b472009-10-13 16:13:13 +0100179
paul718e3742002-12-13 20:15:29 +0000180 u_int32_t crypt_seqnum; /* Cryptographic Sequence Number */
181 u_int32_t output_cost; /* Acutual Interface Output Cost */
182
183 /* Neighbor information. */
184 struct route_table *nbrs; /* OSPF Neighbor List */
185 struct ospf_neighbor *nbr_self; /* Neighbor Self */
186#define DR(I) ((I)->nbr_self->d_router)
187#define BDR(I) ((I)->nbr_self->bd_router)
188#define OPTIONS(I) ((I)->nbr_self->options)
189#define PRIORITY(I) ((I)->nbr_self->priority)
190
191 /* List of configured NBMA neighbor. */
hasso52dc7ee2004-09-23 19:18:23 +0000192 struct list *nbr_nbma;
paul718e3742002-12-13 20:15:29 +0000193
194 /* self-originated LSAs. */
195 struct ospf_lsa *network_lsa_self; /* network-LSA. */
196#ifdef HAVE_OPAQUE_LSA
paul87d6f872004-09-24 08:01:38 +0000197 struct list *opaque_lsa_self; /* Type-9 Opaque-LSAs */
paul718e3742002-12-13 20:15:29 +0000198#endif /* HAVE_OPAQUE_LSA */
199
200 struct route_table *ls_upd_queue;
201
hasso52dc7ee2004-09-23 19:18:23 +0000202 struct list *ls_ack; /* Link State Acknowledgment list. */
paul718e3742002-12-13 20:15:29 +0000203
204 struct
205 {
hasso52dc7ee2004-09-23 19:18:23 +0000206 struct list *ls_ack;
paul718e3742002-12-13 20:15:29 +0000207 struct in_addr dst;
208 } ls_ack_direct;
209
210 /* Timer values. */
211 u_int32_t v_ls_ack; /* Delayed Link State Acknowledgment */
212
213 /* Threads. */
214 struct thread *t_hello; /* timer */
215 struct thread *t_wait; /* timer */
216 struct thread *t_ls_ack; /* timer */
217 struct thread *t_ls_ack_direct; /* event */
218 struct thread *t_ls_upd_event; /* event */
paul718e3742002-12-13 20:15:29 +0000219#ifdef HAVE_OPAQUE_LSA
220 struct thread *t_opaque_lsa_self; /* Type-9 Opaque-LSAs */
221#endif /* HAVE_OPAQUE_LSA */
222
223 int on_write_q;
224
225 /* Statistics fields. */
226 u_int32_t hello_in; /* Hello message input count. */
227 u_int32_t hello_out; /* Hello message output count. */
228 u_int32_t db_desc_in; /* database desc. message input count. */
229 u_int32_t db_desc_out; /* database desc. message output count. */
230 u_int32_t ls_req_in; /* LS request message input count. */
231 u_int32_t ls_req_out; /* LS request message output count. */
232 u_int32_t ls_upd_in; /* LS update message input count. */
233 u_int32_t ls_upd_out; /* LS update message output count. */
234 u_int32_t ls_ack_in; /* LS Ack message input count. */
235 u_int32_t ls_ack_out; /* LS Ack message output count. */
236 u_int32_t discarded; /* discarded input count by error. */
237 u_int32_t state_change; /* Number of status change. */
238
hasso2db3d052004-02-11 21:52:13 +0000239 u_int32_t full_nbrs;
paul718e3742002-12-13 20:15:29 +0000240};
241
242/* Prototypes. */
paul4dadc292005-05-06 21:37:42 +0000243extern char *ospf_if_name (struct ospf_interface *);
244extern struct ospf_interface *ospf_if_new (struct ospf *, struct interface *,
245 struct prefix *);
246extern void ospf_if_cleanup (struct ospf_interface *);
247extern void ospf_if_free (struct ospf_interface *);
248extern int ospf_if_up (struct ospf_interface *);
249extern int ospf_if_down (struct ospf_interface *);
paul718e3742002-12-13 20:15:29 +0000250
paul4dadc292005-05-06 21:37:42 +0000251extern int ospf_if_is_up (struct ospf_interface *);
252extern struct ospf_interface *ospf_if_exists (struct ospf_interface *);
Joakim Tjernlundc81ee5c2012-07-07 17:06:11 +0200253extern struct ospf_interface *ospf_if_lookup_by_lsa_pos (struct ospf_area *,
254 int);
paul4dadc292005-05-06 21:37:42 +0000255extern struct ospf_interface *ospf_if_lookup_by_local_addr (struct ospf *,
256 struct interface
257 *,
258 struct in_addr);
259extern struct ospf_interface *ospf_if_lookup_by_prefix (struct ospf *,
260 struct prefix_ipv4 *);
Joakim Tjernlundf0f63842009-07-27 12:42:29 +0200261extern struct ospf_interface *ospf_if_table_lookup (struct interface *,
262 struct prefix *);
paul4dadc292005-05-06 21:37:42 +0000263extern struct ospf_interface *ospf_if_addr_local (struct in_addr);
264extern struct ospf_interface *ospf_if_lookup_recv_if (struct ospf *,
Joakim Tjernlund05cf46b2009-07-27 12:42:30 +0200265 struct in_addr,
266 struct interface *);
paul4dadc292005-05-06 21:37:42 +0000267extern struct ospf_interface *ospf_if_is_configured (struct ospf *,
268 struct in_addr *);
269
270extern struct ospf_if_params *ospf_lookup_if_params (struct interface *,
hasso2db3d052004-02-11 21:52:13 +0000271 struct in_addr);
paul4dadc292005-05-06 21:37:42 +0000272extern struct ospf_if_params *ospf_get_if_params (struct interface *,
273 struct in_addr);
274extern void ospf_del_if_params (struct ospf_if_params *);
275extern void ospf_free_if_params (struct interface *, struct in_addr);
276extern void ospf_if_update_params (struct interface *, struct in_addr);
paul718e3742002-12-13 20:15:29 +0000277
paul4dadc292005-05-06 21:37:42 +0000278extern int ospf_if_new_hook (struct interface *);
279extern void ospf_if_init (void);
280extern void ospf_if_stream_set (struct ospf_interface *);
281extern void ospf_if_stream_unset (struct ospf_interface *);
282extern void ospf_if_reset_variables (struct ospf_interface *);
283extern int ospf_if_is_enable (struct ospf_interface *);
284extern int ospf_if_get_output_cost (struct ospf_interface *);
285extern void ospf_if_recalculate_output_cost (struct interface *);
paul718e3742002-12-13 20:15:29 +0000286
ajsa608bbf2005-03-29 17:03:49 +0000287/* Simulate down/up on the interface. */
288extern void ospf_if_reset (struct interface *);
289
paul4dadc292005-05-06 21:37:42 +0000290extern struct ospf_interface *ospf_vl_new (struct ospf *,
291 struct ospf_vl_data *);
292extern struct ospf_vl_data *ospf_vl_data_new (struct ospf_area *,
293 struct in_addr);
Paul Jakma9c27ef92006-05-04 07:32:57 +0000294extern struct ospf_vl_data *ospf_vl_lookup (struct ospf *, struct ospf_area *,
paul4dadc292005-05-06 21:37:42 +0000295 struct in_addr);
296extern void ospf_vl_data_free (struct ospf_vl_data *);
297extern void ospf_vl_add (struct ospf *, struct ospf_vl_data *);
298extern void ospf_vl_delete (struct ospf *, struct ospf_vl_data *);
299extern void ospf_vl_up_check (struct ospf_area *, struct in_addr,
300 struct vertex *);
301extern void ospf_vl_unapprove (struct ospf *);
302extern void ospf_vl_shut_unapproved (struct ospf *);
303extern int ospf_full_virtual_nbrs (struct ospf_area *);
304extern int ospf_vls_in_area (struct ospf_area *);
paul718e3742002-12-13 20:15:29 +0000305
paul4dadc292005-05-06 21:37:42 +0000306extern struct crypt_key *ospf_crypt_key_lookup (struct list *, u_char);
307extern struct crypt_key *ospf_crypt_key_new (void);
308extern void ospf_crypt_key_add (struct list *, struct crypt_key *);
309extern int ospf_crypt_key_delete (struct list *, u_char);
paul718e3742002-12-13 20:15:29 +0000310
paul4dadc292005-05-06 21:37:42 +0000311extern u_char ospf_default_iftype (struct interface *ifp);
ajsbc18d612004-12-15 15:07:19 +0000312
ajsba6454e2005-02-08 15:37:30 +0000313/* Set all multicast memberships appropriately based on the type and
314 state of the interface. */
paul4dadc292005-05-06 21:37:42 +0000315extern void ospf_if_set_multicast (struct ospf_interface *);
ajsba6454e2005-02-08 15:37:30 +0000316
paul718e3742002-12-13 20:15:29 +0000317#endif /* _ZEBRA_OSPF_INTERFACE_H */