paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 |
| 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 | |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 26 | #include "ospfd/ospf_packet.h" |
Paul Jakma | 9c27ef9 | 2006-05-04 07:32:57 +0000 | [diff] [blame] | 27 | #include "ospfd/ospf_spf.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 28 | |
| 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) |
| 33 | |
| 34 | #define OSPF_IF_PARAM_CONFIGURED(S, P) ((S) && (S)->P##__config) |
| 35 | #define OSPF_IF_PARAM(O, P) \ |
| 36 | (OSPF_IF_PARAM_CONFIGURED ((O)->params, P)?\ |
| 37 | (O)->params->P:IF_DEF_PARAMS((O)->ifp)->P) |
| 38 | |
| 39 | #define DECLARE_IF_PARAM(T, P) T P; u_char P##__config:1 |
| 40 | #define UNSET_IF_PARAM(S, P) ((S)->P##__config) = 0 |
| 41 | #define SET_IF_PARAM(S, P) ((S)->P##__config) = 1 |
| 42 | |
| 43 | struct ospf_if_params |
| 44 | { |
| 45 | DECLARE_IF_PARAM (u_int32_t, transmit_delay); /* Interface Transmisson Delay */ |
| 46 | DECLARE_IF_PARAM (u_int32_t, output_cost_cmd);/* Command Interface Output Cost */ |
| 47 | DECLARE_IF_PARAM (u_int32_t, retransmit_interval); /* Retransmission Interval */ |
ajs | ba6454e | 2005-02-08 15:37:30 +0000 | [diff] [blame] | 48 | DECLARE_IF_PARAM (u_char, passive_interface); /* OSPF Interface is passive: no sending or receiving (no need to join multicast groups) */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 49 | DECLARE_IF_PARAM (u_char, priority); /* OSPF Interface priority */ |
| 50 | DECLARE_IF_PARAM (u_char, type); /* type of interface */ |
| 51 | #define OSPF_IF_ACTIVE 0 |
| 52 | #define OSPF_IF_PASSIVE 1 |
Paul Jakma | 7ffa8fa | 2006-10-22 20:07:53 +0000 | [diff] [blame^] | 53 | |
| 54 | #define OSPF_IF_PASSIVE_STATUS(O) \ |
| 55 | (OSPF_IF_PARAM_CONFIGURED((O)->params, passive_interface) ? \ |
| 56 | (O)->params->passive_interface : \ |
| 57 | (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS((O)->ifp), passive_interface) ? \ |
| 58 | IF_DEF_PARAMS((O)->ifp)->passive_interface : \ |
| 59 | (O)->ospf->passive_interface_default)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 60 | |
| 61 | DECLARE_IF_PARAM (u_int32_t, v_hello); /* Hello Interval */ |
| 62 | DECLARE_IF_PARAM (u_int32_t, v_wait); /* Router Dead Interval */ |
| 63 | |
vincent | ba68253 | 2005-09-29 13:52:57 +0000 | [diff] [blame] | 64 | /* MTU mismatch check (see RFC2328, chap 10.6) */ |
| 65 | DECLARE_IF_PARAM (u_char, mtu_ignore); |
paul | f9ad937 | 2005-10-21 00:45:17 +0000 | [diff] [blame] | 66 | |
| 67 | /* Fast-Hellos */ |
| 68 | DECLARE_IF_PARAM (u_char, fast_hello); |
| 69 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 70 | /* Authentication data. */ |
| 71 | u_char auth_simple[OSPF_AUTH_SIMPLE_SIZE + 1]; /* Simple password. */ |
| 72 | u_char auth_simple__config:1; |
| 73 | |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 74 | DECLARE_IF_PARAM (struct list *, auth_crypt); /* List of Auth cryptographic data. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 75 | DECLARE_IF_PARAM (int, auth_type); /* OSPF authentication type */ |
| 76 | }; |
| 77 | |
Paul Jakma | 429ac78 | 2006-06-15 18:40:49 +0000 | [diff] [blame] | 78 | enum |
| 79 | { |
| 80 | MEMBER_ALLROUTERS = 0, |
| 81 | MEMBER_DROUTERS, |
| 82 | MEMBER_MAX, |
| 83 | }; |
| 84 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 85 | struct ospf_if_info |
| 86 | { |
| 87 | struct ospf_if_params *def_params; |
| 88 | struct route_table *params; |
| 89 | struct route_table *oifs; |
Paul Jakma | 429ac78 | 2006-06-15 18:40:49 +0000 | [diff] [blame] | 90 | unsigned int membership_counts[MEMBER_MAX]; /* multicast group refcnts */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | struct ospf_interface; |
| 94 | |
| 95 | struct ospf_vl_data |
| 96 | { |
| 97 | struct in_addr vl_peer; /* Router-ID of the peer for VLs. */ |
| 98 | struct in_addr vl_area_id; /* Transit area for this VL. */ |
| 99 | int format; /* area ID format */ |
| 100 | struct ospf_interface *vl_oi; /* Interface data structure for the VL. */ |
Paul Jakma | 9c27ef9 | 2006-05-04 07:32:57 +0000 | [diff] [blame] | 101 | struct vertex_nexthop nexthop; /* Nexthop router and oi to use */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 102 | struct in_addr peer_addr; /* Address used to reach the peer. */ |
| 103 | u_char flags; |
| 104 | }; |
| 105 | |
| 106 | |
| 107 | #define OSPF_VL_MAX_COUNT 256 |
| 108 | #define OSPF_VL_MTU 1500 |
| 109 | |
| 110 | #define OSPF_VL_FLAG_APPROVED 0x01 |
| 111 | |
| 112 | struct crypt_key |
| 113 | { |
| 114 | u_char key_id; |
| 115 | u_char auth_key[OSPF_AUTH_MD5_SIZE + 1]; |
| 116 | }; |
| 117 | |
| 118 | /* OSPF interface structure. */ |
| 119 | struct ospf_interface |
| 120 | { |
| 121 | /* This interface's parent ospf instance. */ |
| 122 | struct ospf *ospf; |
| 123 | |
| 124 | /* OSPF Area. */ |
| 125 | struct ospf_area *area; |
| 126 | |
| 127 | /* Interface data from zebra. */ |
| 128 | struct interface *ifp; |
| 129 | struct ospf_vl_data *vl_data; /* Data for Virtual Link */ |
| 130 | |
| 131 | /* Packet send buffer. */ |
| 132 | struct ospf_fifo *obuf; /* Output queue */ |
| 133 | |
| 134 | /* OSPF Network Type. */ |
| 135 | u_char type; |
| 136 | #define OSPF_IFTYPE_NONE 0 |
| 137 | #define OSPF_IFTYPE_POINTOPOINT 1 |
| 138 | #define OSPF_IFTYPE_BROADCAST 2 |
| 139 | #define OSPF_IFTYPE_NBMA 3 |
| 140 | #define OSPF_IFTYPE_POINTOMULTIPOINT 4 |
| 141 | #define OSPF_IFTYPE_VIRTUALLINK 5 |
| 142 | #define OSPF_IFTYPE_LOOPBACK 6 |
| 143 | #define OSPF_IFTYPE_MAX 7 |
| 144 | |
| 145 | /* State of Interface State Machine. */ |
| 146 | u_char state; |
| 147 | |
ajs | ba6454e | 2005-02-08 15:37:30 +0000 | [diff] [blame] | 148 | /* To which multicast groups do we currently belong? */ |
| 149 | u_char multicast_memberships; |
Paul Jakma | 429ac78 | 2006-06-15 18:40:49 +0000 | [diff] [blame] | 150 | #define OI_MEMBER_FLAG(M) (1 << (M)) |
| 151 | #define OI_MEMBER_COUNT(O,M) (IF_OSPF_IF_INFO(oi->ifp)->membership_counts[(M)]) |
| 152 | #define OI_MEMBER_CHECK(O,M) \ |
| 153 | (CHECK_FLAG((O)->multicast_memberships, OI_MEMBER_FLAG(M))) |
| 154 | #define OI_MEMBER_JOINED(O,M) \ |
| 155 | do { \ |
| 156 | SET_FLAG ((O)->multicast_memberships, OI_MEMBER_FLAG(M)); \ |
| 157 | IF_OSPF_IF_INFO((O)->ifp)->membership_counts[(M)]++; \ |
| 158 | } while (0) |
| 159 | #define OI_MEMBER_LEFT(O,M) \ |
| 160 | do { \ |
| 161 | UNSET_FLAG ((O)->multicast_memberships, OI_MEMBER_FLAG(M)); \ |
| 162 | IF_OSPF_IF_INFO((O)->ifp)->membership_counts[(M)]--; \ |
| 163 | } while (0) |
ajs | ba6454e | 2005-02-08 15:37:30 +0000 | [diff] [blame] | 164 | |
ajs | 8cfde37 | 2005-02-08 15:59:16 +0000 | [diff] [blame] | 165 | struct prefix *address; /* Interface prefix */ |
| 166 | struct connected *connected; /* Pointer to connected */ |
| 167 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 168 | /* Configured varables. */ |
| 169 | struct ospf_if_params *params; |
| 170 | u_int32_t crypt_seqnum; /* Cryptographic Sequence Number */ |
| 171 | u_int32_t output_cost; /* Acutual Interface Output Cost */ |
| 172 | |
| 173 | /* Neighbor information. */ |
| 174 | struct route_table *nbrs; /* OSPF Neighbor List */ |
| 175 | struct ospf_neighbor *nbr_self; /* Neighbor Self */ |
| 176 | #define DR(I) ((I)->nbr_self->d_router) |
| 177 | #define BDR(I) ((I)->nbr_self->bd_router) |
| 178 | #define OPTIONS(I) ((I)->nbr_self->options) |
| 179 | #define PRIORITY(I) ((I)->nbr_self->priority) |
| 180 | |
| 181 | /* List of configured NBMA neighbor. */ |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 182 | struct list *nbr_nbma; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 183 | |
| 184 | /* self-originated LSAs. */ |
| 185 | struct ospf_lsa *network_lsa_self; /* network-LSA. */ |
| 186 | #ifdef HAVE_OPAQUE_LSA |
paul | 87d6f87 | 2004-09-24 08:01:38 +0000 | [diff] [blame] | 187 | struct list *opaque_lsa_self; /* Type-9 Opaque-LSAs */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 188 | #endif /* HAVE_OPAQUE_LSA */ |
| 189 | |
| 190 | struct route_table *ls_upd_queue; |
| 191 | |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 192 | struct list *ls_ack; /* Link State Acknowledgment list. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 193 | |
| 194 | struct |
| 195 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 196 | struct list *ls_ack; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 197 | struct in_addr dst; |
| 198 | } ls_ack_direct; |
| 199 | |
| 200 | /* Timer values. */ |
| 201 | u_int32_t v_ls_ack; /* Delayed Link State Acknowledgment */ |
| 202 | |
| 203 | /* Threads. */ |
| 204 | struct thread *t_hello; /* timer */ |
| 205 | struct thread *t_wait; /* timer */ |
| 206 | struct thread *t_ls_ack; /* timer */ |
| 207 | struct thread *t_ls_ack_direct; /* event */ |
| 208 | struct thread *t_ls_upd_event; /* event */ |
| 209 | struct thread *t_network_lsa_self; /* self-originated network-LSA |
| 210 | reflesh thread. timer */ |
| 211 | #ifdef HAVE_OPAQUE_LSA |
| 212 | struct thread *t_opaque_lsa_self; /* Type-9 Opaque-LSAs */ |
| 213 | #endif /* HAVE_OPAQUE_LSA */ |
| 214 | |
| 215 | int on_write_q; |
| 216 | |
| 217 | /* Statistics fields. */ |
| 218 | u_int32_t hello_in; /* Hello message input count. */ |
| 219 | u_int32_t hello_out; /* Hello message output count. */ |
| 220 | u_int32_t db_desc_in; /* database desc. message input count. */ |
| 221 | u_int32_t db_desc_out; /* database desc. message output count. */ |
| 222 | u_int32_t ls_req_in; /* LS request message input count. */ |
| 223 | u_int32_t ls_req_out; /* LS request message output count. */ |
| 224 | u_int32_t ls_upd_in; /* LS update message input count. */ |
| 225 | u_int32_t ls_upd_out; /* LS update message output count. */ |
| 226 | u_int32_t ls_ack_in; /* LS Ack message input count. */ |
| 227 | u_int32_t ls_ack_out; /* LS Ack message output count. */ |
| 228 | u_int32_t discarded; /* discarded input count by error. */ |
| 229 | u_int32_t state_change; /* Number of status change. */ |
| 230 | |
hasso | 2db3d05 | 2004-02-11 21:52:13 +0000 | [diff] [blame] | 231 | u_int32_t full_nbrs; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | /* Prototypes. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 235 | extern char *ospf_if_name (struct ospf_interface *); |
| 236 | extern struct ospf_interface *ospf_if_new (struct ospf *, struct interface *, |
| 237 | struct prefix *); |
| 238 | extern void ospf_if_cleanup (struct ospf_interface *); |
| 239 | extern void ospf_if_free (struct ospf_interface *); |
| 240 | extern int ospf_if_up (struct ospf_interface *); |
| 241 | extern int ospf_if_down (struct ospf_interface *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 242 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 243 | extern int ospf_if_is_up (struct ospf_interface *); |
| 244 | extern struct ospf_interface *ospf_if_exists (struct ospf_interface *); |
| 245 | extern struct ospf_interface *ospf_if_lookup_by_local_addr (struct ospf *, |
| 246 | struct interface |
| 247 | *, |
| 248 | struct in_addr); |
| 249 | extern struct ospf_interface *ospf_if_lookup_by_prefix (struct ospf *, |
| 250 | struct prefix_ipv4 *); |
| 251 | extern struct ospf_interface *ospf_if_addr_local (struct in_addr); |
| 252 | extern struct ospf_interface *ospf_if_lookup_recv_if (struct ospf *, |
| 253 | struct in_addr); |
| 254 | extern struct ospf_interface *ospf_if_is_configured (struct ospf *, |
| 255 | struct in_addr *); |
| 256 | |
| 257 | extern struct ospf_if_params *ospf_lookup_if_params (struct interface *, |
hasso | 2db3d05 | 2004-02-11 21:52:13 +0000 | [diff] [blame] | 258 | struct in_addr); |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 259 | extern struct ospf_if_params *ospf_get_if_params (struct interface *, |
| 260 | struct in_addr); |
| 261 | extern void ospf_del_if_params (struct ospf_if_params *); |
| 262 | extern void ospf_free_if_params (struct interface *, struct in_addr); |
| 263 | extern void ospf_if_update_params (struct interface *, struct in_addr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 264 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 265 | extern int ospf_if_new_hook (struct interface *); |
| 266 | extern void ospf_if_init (void); |
| 267 | extern void ospf_if_stream_set (struct ospf_interface *); |
| 268 | extern void ospf_if_stream_unset (struct ospf_interface *); |
| 269 | extern void ospf_if_reset_variables (struct ospf_interface *); |
| 270 | extern int ospf_if_is_enable (struct ospf_interface *); |
| 271 | extern int ospf_if_get_output_cost (struct ospf_interface *); |
| 272 | extern void ospf_if_recalculate_output_cost (struct interface *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 273 | |
ajs | a608bbf | 2005-03-29 17:03:49 +0000 | [diff] [blame] | 274 | /* Simulate down/up on the interface. */ |
| 275 | extern void ospf_if_reset (struct interface *); |
| 276 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 277 | extern struct ospf_interface *ospf_vl_new (struct ospf *, |
| 278 | struct ospf_vl_data *); |
| 279 | extern struct ospf_vl_data *ospf_vl_data_new (struct ospf_area *, |
| 280 | struct in_addr); |
Paul Jakma | 9c27ef9 | 2006-05-04 07:32:57 +0000 | [diff] [blame] | 281 | extern struct ospf_vl_data *ospf_vl_lookup (struct ospf *, struct ospf_area *, |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 282 | struct in_addr); |
| 283 | extern void ospf_vl_data_free (struct ospf_vl_data *); |
| 284 | extern void ospf_vl_add (struct ospf *, struct ospf_vl_data *); |
| 285 | extern void ospf_vl_delete (struct ospf *, struct ospf_vl_data *); |
| 286 | extern void ospf_vl_up_check (struct ospf_area *, struct in_addr, |
| 287 | struct vertex *); |
| 288 | extern void ospf_vl_unapprove (struct ospf *); |
| 289 | extern void ospf_vl_shut_unapproved (struct ospf *); |
| 290 | extern int ospf_full_virtual_nbrs (struct ospf_area *); |
| 291 | extern int ospf_vls_in_area (struct ospf_area *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 292 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 293 | extern struct crypt_key *ospf_crypt_key_lookup (struct list *, u_char); |
| 294 | extern struct crypt_key *ospf_crypt_key_new (void); |
| 295 | extern void ospf_crypt_key_add (struct list *, struct crypt_key *); |
| 296 | extern int ospf_crypt_key_delete (struct list *, u_char); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 297 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 298 | extern u_char ospf_default_iftype (struct interface *ifp); |
ajs | bc18d61 | 2004-12-15 15:07:19 +0000 | [diff] [blame] | 299 | |
ajs | ba6454e | 2005-02-08 15:37:30 +0000 | [diff] [blame] | 300 | /* Set all multicast memberships appropriately based on the type and |
| 301 | state of the interface. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame] | 302 | extern void ospf_if_set_multicast (struct ospf_interface *); |
ajs | ba6454e | 2005-02-08 15:37:30 +0000 | [diff] [blame] | 303 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 304 | #endif /* _ZEBRA_OSPF_INTERFACE_H */ |