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