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