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