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