Line data Source code
1 : /*
2 : * Copyright (C) 2003 Yasuhiro Ohara
3 : *
4 : * This file is part of GNU Zebra.
5 : *
6 : * GNU Zebra is free software; you can redistribute it and/or modify it
7 : * under the terms of the GNU General Public License as published by the
8 : * Free Software Foundation; either version 2, or (at your option) any
9 : * later version.
10 : *
11 : * GNU Zebra is distributed in the hope that it will be useful, but
12 : * WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : * General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU General Public License along
17 : * with this program; see the file COPYING; if not, write to the Free Software
18 : * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 : */
20 :
21 : #ifndef OSPF6_NEIGHBOR_H
22 : #define OSPF6_NEIGHBOR_H
23 :
24 : #include "typesafe.h"
25 : #include "hook.h"
26 :
27 : #include "ospf6_message.h"
28 :
29 : /* Forward declaration(s). */
30 : struct ospf6_area;
31 :
32 : /* Debug option */
33 : extern unsigned char conf_debug_ospf6_neighbor;
34 : #define OSPF6_DEBUG_NEIGHBOR_STATE 0x01
35 : #define OSPF6_DEBUG_NEIGHBOR_EVENT 0x02
36 : #define OSPF6_DEBUG_NEIGHBOR_ON(level) (conf_debug_ospf6_neighbor |= (level))
37 : #define OSPF6_DEBUG_NEIGHBOR_OFF(level) (conf_debug_ospf6_neighbor &= ~(level))
38 : #define IS_OSPF6_DEBUG_NEIGHBOR(level) \
39 : (conf_debug_ospf6_neighbor & OSPF6_DEBUG_NEIGHBOR_##level)
40 :
41 : struct ospf6_helper_info {
42 :
43 : /* Grace interval received from
44 : * Restarting Router.
45 : */
46 : uint32_t recvd_grace_period;
47 :
48 : /* Grace interval used for grace
49 : * gracetimer.
50 : */
51 : uint32_t actual_grace_period;
52 :
53 : /* Grace timer,This Router acts as
54 : * helper until this timer until
55 : * this timer expires.
56 : */
57 : struct thread *t_grace_timer;
58 :
59 : /* Helper status */
60 : uint32_t gr_helper_status;
61 :
62 : /* Helper exit reason*/
63 : uint32_t helper_exit_reason;
64 :
65 : /* Planned/Unplanned restart*/
66 : uint32_t gr_restart_reason;
67 :
68 :
69 : /* Helper rejected reason */
70 : uint32_t rejected_reason;
71 : };
72 :
73 : struct ospf6_if_p2xp_neighcfg;
74 : struct ospf6_virtual_link;
75 :
76 : /* Neighbor structure */
77 : struct ospf6_neighbor {
78 : /* Neighbor Router ID String */
79 : char name[36];
80 :
81 : /* OSPFv3 Interface this neighbor belongs to */
82 : struct ospf6_interface *ospf6_if;
83 :
84 : /* set if this is a virtual link neighbor */
85 : struct ospf6_virtual_link *vlink;
86 :
87 : /* P2P/P2MP config for this neighbor.
88 : * can be NULL if not explicitly configured!
89 : */
90 : struct ospf6_if_p2xp_neighcfg *p2xp_cfg;
91 :
92 : /* Neighbor state */
93 : uint8_t state;
94 :
95 : /* timestamp of last changing state */
96 : uint32_t state_change;
97 : struct timeval last_changed;
98 :
99 : /* last received hello */
100 : struct timeval last_hello;
101 : uint32_t hello_in;
102 :
103 : /* Neighbor Router ID */
104 : in_addr_t router_id;
105 :
106 : /* Neighbor Interface ID */
107 : ifindex_t ifindex;
108 :
109 : /* Router Priority of this neighbor */
110 : uint8_t priority;
111 :
112 : in_addr_t drouter;
113 : in_addr_t bdrouter;
114 : in_addr_t prev_drouter;
115 : in_addr_t prev_bdrouter;
116 :
117 : /* Options field (Capability) */
118 : char options[3];
119 :
120 : /* IPaddr of I/F on neighbour's link */
121 : struct in6_addr linklocal_addr;
122 :
123 : /* For Database Exchange */
124 : uint8_t dbdesc_bits;
125 : uint32_t dbdesc_seqnum;
126 : /* Last received Database Description packet */
127 : struct ospf6_dbdesc dbdesc_last;
128 :
129 : /* LS-list */
130 : struct ospf6_lsdb *summary_list;
131 : struct ospf6_lsdb *request_list;
132 : struct ospf6_lsdb *retrans_list;
133 :
134 : /* LSA list for message transmission */
135 : struct ospf6_lsdb *dbdesc_list;
136 : struct ospf6_lsdb *lsreq_list;
137 : struct ospf6_lsdb *lsupdate_list;
138 : struct ospf6_lsdb *lsack_list;
139 :
140 : struct ospf6_lsa *last_ls_req;
141 :
142 : /* Inactivity timer */
143 : struct thread *inactivity_timer;
144 :
145 : /* Timer to release the last dbdesc packet */
146 : struct thread *last_dbdesc_release_timer;
147 :
148 : /* Thread for sending message */
149 : struct thread *thread_send_dbdesc;
150 : struct thread *thread_send_lsreq;
151 : struct thread *thread_send_lsupdate;
152 : struct thread *thread_send_lsack;
153 : struct thread *thread_exchange_done;
154 : struct thread *thread_adj_ok;
155 :
156 : /* BFD information */
157 : struct bfd_session_params *bfd_session;
158 :
159 : /* ospf6 graceful restart HELPER info */
160 : struct ospf6_helper_info gr_helper_info;
161 :
162 : /* seqnum_h/l is used to compare sequence
163 : * number in received packet Auth header
164 : */
165 : uint32_t seqnum_h[OSPF6_MESSAGE_TYPE_MAX];
166 : uint32_t seqnum_l[OSPF6_MESSAGE_TYPE_MAX];
167 : bool auth_present;
168 : bool lls_present;
169 : };
170 :
171 : PREDECL_RBTREE_UNIQ(ospf6_if_p2xp_neighcfgs);
172 :
173 : struct ospf6_if_p2xp_neighcfg {
174 : struct ospf6_if_p2xp_neighcfgs_item item;
175 :
176 : struct ospf6_interface *ospf6_if;
177 : struct in6_addr addr;
178 :
179 : bool cfg_cost : 1;
180 :
181 : uint32_t cost;
182 : uint16_t poll_interval;
183 :
184 : /* NULL if down */
185 : struct ospf6_neighbor *active;
186 :
187 : struct thread *t_unicast_hello;
188 : };
189 :
190 : /* Neighbor state */
191 : #define OSPF6_NEIGHBOR_DOWN 1
192 : #define OSPF6_NEIGHBOR_ATTEMPT 2
193 : #define OSPF6_NEIGHBOR_INIT 3
194 : #define OSPF6_NEIGHBOR_TWOWAY 4
195 : #define OSPF6_NEIGHBOR_EXSTART 5
196 : #define OSPF6_NEIGHBOR_EXCHANGE 6
197 : #define OSPF6_NEIGHBOR_LOADING 7
198 : #define OSPF6_NEIGHBOR_FULL 8
199 :
200 : /* Neighbor Events */
201 : #define OSPF6_NEIGHBOR_EVENT_NO_EVENT 0
202 : #define OSPF6_NEIGHBOR_EVENT_HELLO_RCVD 1
203 : #define OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD 2
204 : #define OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE 3
205 : #define OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE 4
206 : #define OSPF6_NEIGHBOR_EVENT_LOADING_DONE 5
207 : #define OSPF6_NEIGHBOR_EVENT_ADJ_OK 6
208 : #define OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH 7
209 : #define OSPF6_NEIGHBOR_EVENT_BAD_LSREQ 8
210 : #define OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD 9
211 : #define OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER 10
212 : #define OSPF6_NEIGHBOR_EVENT_VLINK_UNREACHABLE 11
213 : #define OSPF6_NEIGHBOR_EVENT_VLINK_REACHABLE 12
214 : #define OSPF6_NEIGHBOR_EVENT_MAX_EVENT 13
215 :
216 : extern const char *const ospf6_neighbor_event_str[];
217 :
218 26 : static inline const char *ospf6_neighbor_event_string(int event)
219 : {
220 : #define OSPF6_NEIGHBOR_UNKNOWN_EVENT_STRING "UnknownEvent"
221 :
222 26 : if (event < OSPF6_NEIGHBOR_EVENT_MAX_EVENT)
223 26 : return ospf6_neighbor_event_str[event];
224 : return OSPF6_NEIGHBOR_UNKNOWN_EVENT_STRING;
225 : }
226 :
227 : extern const char *const ospf6_neighbor_state_str[];
228 :
229 :
230 : /* Function Prototypes */
231 : int ospf6_neighbor_cmp(void *va, void *vb);
232 : void ospf6_neighbor_dbex_init(struct ospf6_neighbor *on);
233 :
234 : struct ospf6_neighbor *ospf6_neighbor_lookup(uint32_t router_id,
235 : struct ospf6_interface *oi);
236 : struct ospf6_neighbor *ospf6_area_neighbor_lookup(struct ospf6_area *area,
237 : uint32_t router_id);
238 : struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id,
239 : struct ospf6_interface *oi);
240 : void ospf6_neighbor_delete(struct ospf6_neighbor *on);
241 :
242 : void ospf6_neighbor_lladdr_set(struct ospf6_neighbor *on,
243 : const struct in6_addr *addr);
244 : struct ospf6_if_p2xp_neighcfg *ospf6_if_p2xp_find(struct ospf6_interface *oi,
245 : const struct in6_addr *addr);
246 : void ospf6_if_p2xp_up(struct ospf6_interface *oi);
247 :
248 : uint32_t ospf6_neighbor_cost(struct ospf6_neighbor *on);
249 :
250 : /* Neighbor event */
251 : extern void hello_received(struct thread *thread);
252 : extern void twoway_received(struct thread *thread);
253 : extern void negotiation_done(struct thread *thread);
254 : extern void exchange_done(struct thread *thread);
255 : extern void loading_done(struct thread *thread);
256 : extern void adj_ok(struct thread *thread);
257 : extern void seqnumber_mismatch(struct thread *thread);
258 : extern void bad_lsreq(struct thread *thread);
259 : extern void oneway_received(struct thread *thread);
260 : extern void inactivity_timer(struct thread *thread);
261 : extern void ospf6_check_nbr_loading(struct ospf6_neighbor *on);
262 : extern void ospf6_neighbor_vlink_change(struct ospf6_neighbor *nbr, bool up);
263 :
264 : extern void ospf6_neighbor_init(void);
265 : extern int config_write_ospf6_debug_neighbor(struct vty *vty);
266 : extern int config_write_ospf6_p2xp_neighbor(struct vty *vty,
267 : struct ospf6_interface *oi);
268 : extern void install_element_ospf6_debug_neighbor(void);
269 :
270 : DECLARE_HOOK(ospf6_neighbor_change,
271 : (struct ospf6_neighbor * on, int state, int next_state),
272 : (on, state, next_state));
273 :
274 : #endif /* OSPF6_NEIGHBOR_H */
|