]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_interface.h
pathd: some traces are added to 'debug pathd ted' command.
[mirror_frr.git] / ospfd / ospf_interface.h
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 along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef _ZEBRA_OSPF_INTERFACE_H
23 #define _ZEBRA_OSPF_INTERFACE_H
24
25 #include "lib/bfd.h"
26 #include "qobj.h"
27 #include "hook.h"
28 #include "ospfd/ospf_packet.h"
29 #include "ospfd/ospf_spf.h"
30
31 #define IF_OSPF_IF_INFO(I) ((struct ospf_if_info *)((I)->info))
32 #define IF_DEF_PARAMS(I) (IF_OSPF_IF_INFO (I)->def_params)
33 #define IF_OIFS(I) (IF_OSPF_IF_INFO (I)->oifs)
34 #define IF_OIFS_PARAMS(I) (IF_OSPF_IF_INFO (I)->params)
35
36 /* Despite the name, this macro probably is for specialist use only */
37 #define OSPF_IF_PARAM_CONFIGURED(S, P) ((S) && (S)->P##__config)
38
39 /* Test whether an OSPF interface parameter is set, generally, given some
40 * existing ospf interface
41 */
42 #define OSPF_IF_PARAM_IS_SET(O, P) \
43 (OSPF_IF_PARAM_CONFIGURED((O)->params, P) \
44 || OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS((O)->ifp)->P))
45
46 #define OSPF_IF_PARAM(O, P) \
47 (OSPF_IF_PARAM_CONFIGURED((O)->params, P) \
48 ? (O)->params->P \
49 : IF_DEF_PARAMS((O)->ifp)->P)
50
51 #define DECLARE_IF_PARAM(T, P) \
52 T P; \
53 uint8_t P##__config : 1
54 #define UNSET_IF_PARAM(S, P) ((S)->P##__config) = 0
55 #define SET_IF_PARAM(S, P) ((S)->P##__config) = 1
56
57 struct ospf_if_params {
58 DECLARE_IF_PARAM(uint32_t,
59 transmit_delay); /* Interface Transmisson Delay */
60 DECLARE_IF_PARAM(uint32_t,
61 output_cost_cmd); /* Command Interface Output Cost */
62 DECLARE_IF_PARAM(uint32_t,
63 retransmit_interval); /* Retransmission Interval */
64 DECLARE_IF_PARAM(uint8_t, passive_interface); /* OSPF Interface is
65 passive: no sending or
66 receiving (no need to
67 join multicast groups)
68 */
69 DECLARE_IF_PARAM(uint8_t, priority); /* OSPF Interface priority */
70 /* Enable OSPF on this interface with area if_area */
71 DECLARE_IF_PARAM(struct in_addr, if_area);
72 uint32_t if_area_id_fmt;
73
74 DECLARE_IF_PARAM(uint8_t, type); /* type of interface */
75 #define OSPF_IF_ACTIVE 0
76 #define OSPF_IF_PASSIVE 1
77
78 #define OSPF_IF_PASSIVE_STATUS(O) \
79 (OSPF_IF_PARAM_CONFIGURED((O)->params, passive_interface) \
80 ? (O)->params->passive_interface \
81 : (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS((O)->ifp), \
82 passive_interface) \
83 ? IF_DEF_PARAMS((O)->ifp)->passive_interface \
84 : (O)->ospf->passive_interface_default))
85
86 DECLARE_IF_PARAM(uint32_t, v_hello); /* Hello Interval */
87 DECLARE_IF_PARAM(uint32_t, v_wait); /* Router Dead Interval */
88 bool is_v_wait_set; /* Check for Dead Interval set */
89
90 /* MTU mismatch check (see RFC2328, chap 10.6) */
91 DECLARE_IF_PARAM(uint8_t, mtu_ignore);
92
93 /* Fast-Hellos */
94 DECLARE_IF_PARAM(uint8_t, fast_hello);
95
96 /* Authentication data. */
97 uint8_t auth_simple[OSPF_AUTH_SIMPLE_SIZE + 1]; /* Simple password. */
98 uint8_t auth_simple__config : 1;
99
100 DECLARE_IF_PARAM(struct list *,
101 auth_crypt); /* List of Auth cryptographic data. */
102 DECLARE_IF_PARAM(int, auth_type); /* OSPF authentication type */
103
104 /* Other, non-configuration state */
105 uint32_t network_lsa_seqnum; /* Network LSA seqnum */
106
107 /* BFD configuration */
108 struct bfd_configuration {
109 /** BFD session detection multiplier. */
110 uint8_t detection_multiplier;
111 /** BFD session minimum required receive interval. */
112 uint32_t min_rx;
113 /** BFD session minimum required transmission interval. */
114 uint32_t min_tx;
115 /** BFD profile. */
116 char profile[BFD_PROFILE_NAME_LEN];
117 } *bfd_config;
118
119 /* MPLS LDP-IGP Sync configuration */
120 struct ldp_sync_info *ldp_sync_info;
121
122 /* point-to-point DMVPN configuration */
123 uint8_t ptp_dmvpn;
124 };
125
126 enum { MEMBER_ALLROUTERS = 0,
127 MEMBER_DROUTERS,
128 MEMBER_MAX,
129 };
130
131 struct ospf_if_info {
132 struct ospf_if_params *def_params;
133 struct route_table *params;
134 struct route_table *oifs;
135 unsigned int
136 membership_counts[MEMBER_MAX]; /* multicast group refcnts */
137
138 uint32_t curr_mtu;
139 };
140
141 struct ospf_interface;
142
143 struct ospf_vl_data {
144 struct in_addr vl_peer; /* Router-ID of the peer */
145 struct in_addr vl_area_id; /* Transit area */
146 int vl_area_id_fmt; /* Area ID format */
147 struct ospf_interface *vl_oi; /* Interface data structure */
148 struct vertex_nexthop nexthop; /* Nexthop router and oi to use */
149 struct in_addr peer_addr; /* Address used to reach the peer */
150 uint8_t flags;
151 };
152
153
154 #define OSPF_VL_MAX_COUNT 256
155 #define OSPF_VL_MTU 1500
156
157 #define OSPF_VL_FLAG_APPROVED 0x01
158
159 struct crypt_key {
160 uint8_t key_id;
161 uint8_t auth_key[OSPF_AUTH_MD5_SIZE + 1];
162 };
163
164 /* OSPF interface structure. */
165 struct ospf_interface {
166 /* This interface's parent ospf instance. */
167 struct ospf *ospf;
168
169 /* OSPF Area. */
170 struct ospf_area *area;
171
172 /* Position range in Router LSA */
173 uint16_t lsa_pos_beg; /* inclusive, >= */
174 uint16_t lsa_pos_end; /* exclusive, < */
175
176 /* Interface data from zebra. */
177 struct interface *ifp;
178 struct ospf_vl_data *vl_data; /* Data for Virtual Link */
179
180 /* Packet send buffer. */
181 struct ospf_fifo *obuf; /* Output queue */
182
183 /* OSPF Network Type. */
184 uint8_t type;
185
186 /* point-to-point DMVPN configuration */
187 uint8_t ptp_dmvpn;
188
189 /* State of Interface State Machine. */
190 uint8_t state;
191
192 /* To which multicast groups do we currently belong? */
193 uint8_t multicast_memberships;
194 #define OI_MEMBER_FLAG(M) (1 << (M))
195 #define OI_MEMBER_COUNT(O,M) (IF_OSPF_IF_INFO(oi->ifp)->membership_counts[(M)])
196 #define OI_MEMBER_CHECK(O, M) \
197 (CHECK_FLAG((O)->multicast_memberships, OI_MEMBER_FLAG(M)))
198 #define OI_MEMBER_JOINED(O, M) \
199 do { \
200 SET_FLAG((O)->multicast_memberships, OI_MEMBER_FLAG(M)); \
201 IF_OSPF_IF_INFO((O)->ifp)->membership_counts[(M)]++; \
202 } while (0)
203 #define OI_MEMBER_LEFT(O, M) \
204 do { \
205 UNSET_FLAG((O)->multicast_memberships, OI_MEMBER_FLAG(M)); \
206 IF_OSPF_IF_INFO((O)->ifp)->membership_counts[(M)]--; \
207 } while (0)
208
209 struct prefix *address; /* Interface prefix */
210 struct connected *connected; /* Pointer to connected */
211
212 /* Configured varables. */
213 struct ospf_if_params *params;
214
215 uint32_t crypt_seqnum; /* Cryptographic Sequence Number */
216 uint32_t output_cost; /* Acutual Interface Output Cost */
217
218 /* Neighbor information. */
219 struct route_table *nbrs; /* OSPF Neighbor List */
220 struct ospf_neighbor *nbr_self; /* Neighbor Self */
221 #define DR(I) ((I)->nbr_self->d_router)
222 #define BDR(I) ((I)->nbr_self->bd_router)
223 #define OPTIONS(I) ((I)->nbr_self->options)
224 #define PRIORITY(I) ((I)->nbr_self->priority)
225
226 /* List of configured NBMA neighbor. */
227 struct list *nbr_nbma;
228
229 /* self-originated LSAs. */
230 struct ospf_lsa *network_lsa_self; /* network-LSA. */
231 struct list *opaque_lsa_self; /* Type-9 Opaque-LSAs */
232
233 struct route_table *ls_upd_queue;
234
235 struct list *ls_ack; /* Link State Acknowledgment list. */
236
237 struct {
238 struct list *ls_ack;
239 struct in_addr dst;
240 } ls_ack_direct;
241
242 /* Timer values. */
243 uint32_t v_ls_ack; /* Delayed Link State Acknowledgment */
244
245 /* Threads. */
246 struct thread *t_hello; /* timer */
247 struct thread *t_wait; /* timer */
248 struct thread *t_ls_ack; /* timer */
249 struct thread *t_ls_ack_direct; /* event */
250 struct thread *t_ls_upd_event; /* event */
251 struct thread *t_opaque_lsa_self; /* Type-9 Opaque-LSAs */
252
253 int on_write_q;
254
255 /* Statistics fields. */
256 uint32_t hello_in; /* Hello message input count. */
257 uint32_t hello_out; /* Hello message output count. */
258 uint32_t db_desc_in; /* database desc. message input count. */
259 uint32_t db_desc_out; /* database desc. message output count. */
260 uint32_t ls_req_in; /* LS request message input count. */
261 uint32_t ls_req_out; /* LS request message output count. */
262 uint32_t ls_upd_in; /* LS update message input count. */
263 uint32_t ls_upd_out; /* LS update message output count. */
264 uint32_t ls_ack_in; /* LS Ack message input count. */
265 uint32_t ls_ack_out; /* LS Ack message output count. */
266 uint32_t discarded; /* discarded input count by error. */
267 uint32_t state_change; /* Number of status change. */
268
269 uint32_t full_nbrs;
270
271 QOBJ_FIELDS;
272 };
273 DECLARE_QOBJ_TYPE(ospf_interface);
274
275 /* Prototypes. */
276 extern char *ospf_if_name(struct ospf_interface *oi);
277 extern struct ospf_interface *
278 ospf_if_new(struct ospf *ospf, struct interface *ifp, struct prefix *p);
279 extern void ospf_if_cleanup(struct ospf_interface *oi);
280 extern void ospf_if_free(struct ospf_interface *oi);
281 extern int ospf_if_up(struct ospf_interface *oi);
282 extern int ospf_if_down(struct ospf_interface *oi);
283
284 extern int ospf_if_is_up(struct ospf_interface *oi);
285 extern struct ospf_interface *ospf_if_exists(struct ospf_interface *oi);
286 extern struct ospf_interface *ospf_if_lookup_by_lsa_pos(struct ospf_area *area,
287 int lsa_pos);
288 extern struct ospf_interface *
289 ospf_if_lookup_by_local_addr(struct ospf *ospf, struct interface *ifp,
290 struct in_addr addr);
291 extern struct ospf_interface *ospf_if_lookup_by_prefix(struct ospf *ospf,
292 struct prefix_ipv4 *p);
293 extern struct ospf_interface *ospf_if_table_lookup(struct interface *ifp,
294 struct prefix *p);
295 extern struct ospf_interface *ospf_if_addr_local(struct in_addr addr);
296 extern struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
297 struct in_addr addr,
298 struct interface *ifp);
299 extern struct ospf_interface *ospf_if_is_configured(struct ospf *ospf,
300 struct in_addr *addr);
301
302 extern struct ospf_if_params *ospf_lookup_if_params(struct interface *ifp,
303 struct in_addr addr);
304 extern struct ospf_if_params *ospf_get_if_params(struct interface *ifp,
305 struct in_addr addr);
306 extern void ospf_free_if_params(struct interface *ifp, struct in_addr addr);
307 extern void ospf_if_update_params(struct interface *ifp, struct in_addr addr);
308
309 extern int ospf_if_new_hook(struct interface *ifp);
310 extern void ospf_if_init(void);
311 extern void ospf_if_stream_unset(struct ospf_interface *oi);
312 extern void ospf_if_reset_variables(struct ospf_interface *oi);
313 extern int ospf_if_is_enable(struct ospf_interface *oi);
314 extern int ospf_if_get_output_cost(struct ospf_interface *oi);
315 extern void ospf_if_recalculate_output_cost(struct interface *ifp);
316
317 /* Simulate down/up on the interface. */
318 extern void ospf_if_reset(struct interface *ifp);
319
320 extern struct ospf_interface *ospf_vl_new(struct ospf *ospf,
321 struct ospf_vl_data *vl_data);
322 extern struct ospf_vl_data *ospf_vl_data_new(struct ospf_area *area,
323 struct in_addr addr);
324 extern struct ospf_vl_data *
325 ospf_vl_lookup(struct ospf *ospf, struct ospf_area *area, struct in_addr addr);
326 extern int ospf_vl_count(struct ospf *ospf, struct ospf_area *area);
327 extern void ospf_vl_data_free(struct ospf_vl_data *vl_data);
328 extern void ospf_vl_add(struct ospf *ospf, struct ospf_vl_data *vl_data);
329 extern void ospf_vl_delete(struct ospf *ospf, struct ospf_vl_data *vl_data);
330 extern void ospf_vl_up_check(struct ospf_area *area, struct in_addr addr,
331 struct vertex *vertex);
332 extern void ospf_vl_unapprove(struct ospf *ospf);
333 extern void ospf_vl_shut_unapproved(struct ospf *ospf);
334 extern int ospf_full_virtual_nbrs(struct ospf_area *area);
335 extern int ospf_vls_in_area(struct ospf_area *area);
336
337 extern struct crypt_key *ospf_crypt_key_lookup(struct list *list,
338 uint8_t key_id);
339 extern struct crypt_key *ospf_crypt_key_new(void);
340 extern void ospf_crypt_key_add(struct list *list, struct crypt_key *key);
341 extern int ospf_crypt_key_delete(struct list *list, uint8_t key_id);
342 extern uint8_t ospf_default_iftype(struct interface *ifp);
343 extern int ospf_interface_neighbor_count(struct ospf_interface *oi);
344
345 /* Set all multicast memberships appropriately based on the type and
346 state of the interface. */
347 extern void ospf_if_set_multicast(struct ospf_interface *oi);
348
349 extern void ospf_if_interface(struct interface *ifp);
350
351 extern uint32_t ospf_if_count_area_params(struct interface *ifp);
352 extern void ospf_reset_hello_timer(struct interface *ifp, struct in_addr addr,
353 bool is_addr);
354
355 extern void ospf_interface_fifo_flush(struct ospf_interface *oi);
356 DECLARE_HOOK(ospf_vl_add, (struct ospf_vl_data * vd), (vd));
357 DECLARE_HOOK(ospf_vl_delete, (struct ospf_vl_data * vd), (vd));
358
359 DECLARE_HOOK(ospf_if_update, (struct interface * ifp), (ifp));
360 DECLARE_HOOK(ospf_if_delete, (struct interface * ifp), (ifp));
361
362 #endif /* _ZEBRA_OSPF_INTERFACE_H */