]>
Commit | Line | Data |
---|---|---|
2fb975da TT |
1 | /* NHRP daemon internal structures and function prototypes |
2 | * Copyright (c) 2014-2015 Timo Teräs | |
3 | * | |
4 | * This file is free software: you may copy, redistribute and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation, either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | */ | |
9 | ||
10 | #ifndef NHRPD_H | |
11 | #define NHRPD_H | |
12 | ||
13 | #include "list.h" | |
14 | ||
15 | #include "zbuf.h" | |
16 | #include "zclient.h" | |
17 | #include "debug.h" | |
819dc8bb | 18 | #include "memory.h" |
fe9e7b71 | 19 | #include "resolver.h" |
819dc8bb DL |
20 | |
21 | DECLARE_MGROUP(NHRPD) | |
2fb975da TT |
22 | |
23 | #define NHRPD_DEFAULT_HOLDTIME 7200 | |
24 | ||
442deed8 | 25 | #define NHRP_VTY_PORT 2610 |
2fb975da TT |
26 | #define NHRP_DEFAULT_CONFIG "nhrpd.conf" |
27 | ||
28 | extern struct thread_master *master; | |
29 | ||
996c9314 LB |
30 | enum { NHRP_OK = 0, |
31 | NHRP_ERR_FAIL, | |
32 | NHRP_ERR_NO_MEMORY, | |
33 | NHRP_ERR_UNSUPPORTED_INTERFACE, | |
34 | NHRP_ERR_NHRP_NOT_ENABLED, | |
35 | NHRP_ERR_ENTRY_EXISTS, | |
36 | NHRP_ERR_ENTRY_NOT_FOUND, | |
37 | NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH, | |
38 | __NHRP_ERR_MAX }; | |
6c8ca260 | 39 | #define NHRP_ERR_MAX (__NHRP_ERR_MAX - 1) |
2fb975da TT |
40 | |
41 | struct notifier_block; | |
42 | ||
43 | typedef void (*notifier_fn_t)(struct notifier_block *, unsigned long); | |
44 | ||
45 | struct notifier_block { | |
46 | struct list_head notifier_entry; | |
47 | notifier_fn_t action; | |
48 | }; | |
49 | ||
50 | struct notifier_list { | |
51 | struct list_head notifier_head; | |
52 | }; | |
53 | ||
996c9314 LB |
54 | #define NOTIFIER_LIST_INITIALIZER(l) \ |
55 | { \ | |
56 | .notifier_head = LIST_INITIALIZER((l)->notifier_head) \ | |
57 | } | |
2fb975da TT |
58 | |
59 | static inline void notifier_init(struct notifier_list *l) | |
60 | { | |
61 | list_init(&l->notifier_head); | |
62 | } | |
63 | ||
996c9314 LB |
64 | static inline void notifier_add(struct notifier_block *n, |
65 | struct notifier_list *l, notifier_fn_t action) | |
2fb975da TT |
66 | { |
67 | n->action = action; | |
68 | list_add_tail(&n->notifier_entry, &l->notifier_head); | |
69 | } | |
70 | ||
71 | static inline void notifier_del(struct notifier_block *n) | |
72 | { | |
73 | list_del(&n->notifier_entry); | |
74 | } | |
75 | ||
76 | static inline void notifier_call(struct notifier_list *l, int cmd) | |
77 | { | |
78 | struct notifier_block *n, *nn; | |
bd2b75a2 | 79 | list_for_each_entry_safe(n, nn, &l->notifier_head, notifier_entry) { |
123ea351 | 80 | n->action(n, cmd); |
bd2b75a2 | 81 | } |
2fb975da TT |
82 | } |
83 | ||
84 | static inline int notifier_active(struct notifier_list *l) | |
85 | { | |
86 | return !list_empty(&l->notifier_head); | |
87 | } | |
88 | ||
2fb975da TT |
89 | void nhrp_zebra_init(void); |
90 | void nhrp_zebra_terminate(void); | |
91 | ||
92 | struct zbuf; | |
93 | struct nhrp_vc; | |
94 | struct nhrp_cache; | |
95 | struct nhrp_nhs; | |
96 | struct nhrp_interface; | |
97 | ||
98 | #define MAX_ID_LENGTH 64 | |
99 | #define MAX_CERT_LENGTH 2048 | |
100 | ||
101 | enum nhrp_notify_type { | |
102 | NOTIFY_INTERFACE_UP, | |
103 | NOTIFY_INTERFACE_DOWN, | |
104 | NOTIFY_INTERFACE_CHANGED, | |
105 | NOTIFY_INTERFACE_ADDRESS_CHANGED, | |
106 | NOTIFY_INTERFACE_NBMA_CHANGED, | |
107 | NOTIFY_INTERFACE_MTU_CHANGED, | |
108 | ||
109 | NOTIFY_VC_IPSEC_CHANGED, | |
110 | NOTIFY_VC_IPSEC_UPDATE_NBMA, | |
111 | ||
112 | NOTIFY_PEER_UP, | |
113 | NOTIFY_PEER_DOWN, | |
114 | NOTIFY_PEER_IFCONFIG_CHANGED, | |
115 | NOTIFY_PEER_MTU_CHANGED, | |
116 | NOTIFY_PEER_NBMA_CHANGING, | |
117 | ||
118 | NOTIFY_CACHE_UP, | |
119 | NOTIFY_CACHE_DOWN, | |
120 | NOTIFY_CACHE_DELETE, | |
121 | NOTIFY_CACHE_USED, | |
122 | NOTIFY_CACHE_BINDING_CHANGE, | |
123 | }; | |
124 | ||
125 | struct nhrp_vc { | |
126 | struct notifier_list notifier_list; | |
6cfd90f3 | 127 | uint32_t ipsec; |
2fb975da TT |
128 | uint8_t updating; |
129 | uint8_t abort_migration; | |
130 | ||
131 | struct nhrp_vc_peer { | |
132 | union sockunion nbma; | |
133 | char id[MAX_ID_LENGTH]; | |
134 | uint16_t certlen; | |
135 | uint8_t cert[MAX_CERT_LENGTH]; | |
136 | } local, remote; | |
137 | }; | |
138 | ||
139 | enum nhrp_route_type { | |
140 | NHRP_ROUTE_BLACKHOLE, | |
141 | NHRP_ROUTE_LOCAL, | |
142 | NHRP_ROUTE_NBMA_NEXTHOP, | |
143 | NHRP_ROUTE_OFF_NBMA, | |
144 | }; | |
145 | ||
146 | struct nhrp_peer { | |
147 | unsigned int ref; | |
148 | unsigned online : 1; | |
149 | unsigned requested : 1; | |
150 | unsigned fallback_requested : 1; | |
151 | unsigned prio : 1; | |
152 | struct notifier_list notifier_list; | |
153 | struct interface *ifp; | |
154 | struct nhrp_vc *vc; | |
155 | struct thread *t_fallback; | |
156 | struct notifier_block vc_notifier, ifp_notifier; | |
157 | }; | |
158 | ||
159 | struct nhrp_packet_parser { | |
160 | struct interface *ifp; | |
161 | struct nhrp_afi_data *if_ad; | |
162 | struct nhrp_peer *peer; | |
163 | struct zbuf *pkt; | |
164 | struct zbuf payload; | |
165 | struct zbuf extensions; | |
166 | struct nhrp_packet_header *hdr; | |
167 | enum nhrp_route_type route_type; | |
168 | struct prefix route_prefix; | |
169 | union sockunion src_nbma, src_proto, dst_proto; | |
170 | }; | |
171 | ||
172 | struct nhrp_reqid_pool { | |
173 | struct hash *reqid_hash; | |
174 | uint32_t next_request_id; | |
175 | }; | |
176 | ||
177 | struct nhrp_reqid { | |
178 | uint32_t request_id; | |
179 | void (*cb)(struct nhrp_reqid *, void *); | |
180 | }; | |
181 | ||
182 | extern struct nhrp_reqid_pool nhrp_packet_reqid; | |
183 | extern struct nhrp_reqid_pool nhrp_event_reqid; | |
184 | ||
185 | enum nhrp_cache_type { | |
186 | NHRP_CACHE_INVALID = 0, | |
187 | NHRP_CACHE_INCOMPLETE, | |
188 | NHRP_CACHE_NEGATIVE, | |
189 | NHRP_CACHE_CACHED, | |
190 | NHRP_CACHE_DYNAMIC, | |
191 | NHRP_CACHE_NHS, | |
192 | NHRP_CACHE_STATIC, | |
193 | NHRP_CACHE_LOCAL, | |
194 | NHRP_CACHE_NUM_TYPES | |
195 | }; | |
196 | ||
996c9314 | 197 | extern const char *const nhrp_cache_type_str[]; |
2fb975da TT |
198 | extern unsigned long nhrp_cache_counts[NHRP_CACHE_NUM_TYPES]; |
199 | ||
fef2ed13 PG |
200 | struct nhrp_cache_config { |
201 | struct interface *ifp; | |
202 | union sockunion remote_addr; | |
203 | enum nhrp_cache_type type; | |
204 | union sockunion nbma; | |
205 | }; | |
206 | ||
2fb975da TT |
207 | struct nhrp_cache { |
208 | struct interface *ifp; | |
209 | union sockunion remote_addr; | |
210 | ||
211 | unsigned map : 1; | |
212 | unsigned used : 1; | |
213 | unsigned route_installed : 1; | |
214 | unsigned nhrp_route_installed : 1; | |
215 | ||
216 | struct notifier_block peer_notifier; | |
217 | struct notifier_block newpeer_notifier; | |
218 | struct notifier_list notifier_list; | |
219 | struct nhrp_reqid eventid; | |
220 | struct thread *t_timeout; | |
221 | struct thread *t_auth; | |
222 | ||
223 | struct { | |
224 | enum nhrp_cache_type type; | |
225 | union sockunion remote_nbma_natoa; | |
226 | struct nhrp_peer *peer; | |
227 | time_t expires; | |
228 | uint32_t mtu; | |
229 | } cur, new; | |
230 | }; | |
231 | ||
232 | struct nhrp_shortcut { | |
233 | struct prefix *p; | |
234 | union sockunion addr; | |
235 | ||
236 | struct nhrp_reqid reqid; | |
237 | struct thread *t_timer; | |
238 | ||
239 | enum nhrp_cache_type type; | |
240 | unsigned int holding_time; | |
241 | unsigned route_installed : 1; | |
242 | unsigned expiring : 1; | |
243 | ||
244 | struct nhrp_cache *cache; | |
245 | struct notifier_block cache_notifier; | |
246 | }; | |
247 | ||
248 | struct nhrp_nhs { | |
249 | struct interface *ifp; | |
250 | struct list_head nhslist_entry; | |
251 | ||
252 | unsigned hub : 1; | |
253 | afi_t afi; | |
254 | union sockunion proto_addr; | |
996c9314 | 255 | const char *nbma_fqdn; /* IP-address or FQDN */ |
2fb975da TT |
256 | |
257 | struct thread *t_resolve; | |
258 | struct resolver_query dns_resolve; | |
259 | struct list_head reglist_head; | |
260 | }; | |
261 | ||
0ca036b4 TT |
262 | struct nhrp_registration { |
263 | struct list_head reglist_entry; | |
264 | struct thread *t_register; | |
265 | struct nhrp_nhs *nhs; | |
266 | struct nhrp_reqid reqid; | |
267 | unsigned int timeout; | |
268 | unsigned mark : 1; | |
269 | union sockunion proto_addr; | |
270 | struct nhrp_peer *peer; | |
271 | struct notifier_block peer_notifier; | |
272 | }; | |
273 | ||
2fb975da TT |
274 | #define NHRP_IFF_SHORTCUT 0x0001 |
275 | #define NHRP_IFF_REDIRECT 0x0002 | |
276 | #define NHRP_IFF_REG_NO_UNIQUE 0x0100 | |
277 | ||
278 | struct nhrp_interface { | |
279 | struct interface *ifp; | |
280 | ||
281 | unsigned enabled : 1; | |
282 | ||
283 | char *ipsec_profile, *ipsec_fallback_profile, *source; | |
284 | union sockunion nbma; | |
285 | union sockunion nat_nbma; | |
286 | unsigned int linkidx; | |
287 | uint32_t grekey; | |
288 | ||
289 | struct hash *peer_hash; | |
fef2ed13 | 290 | struct hash *cache_config_hash; |
2fb975da TT |
291 | struct hash *cache_hash; |
292 | ||
293 | struct notifier_list notifier_list; | |
294 | ||
295 | struct interface *nbmaifp; | |
296 | struct notifier_block nbmanifp_notifier; | |
297 | ||
298 | struct nhrp_afi_data { | |
299 | unsigned flags; | |
300 | unsigned short configured : 1; | |
301 | union sockunion addr; | |
302 | uint32_t network_id; | |
303 | short configured_mtu; | |
304 | unsigned short mtu; | |
305 | unsigned int holdtime; | |
306 | struct list_head nhslist_head; | |
307 | } afi[AFI_MAX]; | |
308 | }; | |
309 | ||
26efbc7b DS |
310 | extern struct zebra_privs_t nhrpd_privs; |
311 | ||
2fb975da TT |
312 | int sock_open_unix(const char *path); |
313 | ||
314 | void nhrp_interface_init(void); | |
315 | void nhrp_interface_update(struct interface *ifp); | |
316 | void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi); | |
317 | ||
121f9dee QY |
318 | int nhrp_interface_add(ZAPI_CALLBACK_ARGS); |
319 | int nhrp_interface_delete(ZAPI_CALLBACK_ARGS); | |
320 | int nhrp_interface_up(ZAPI_CALLBACK_ARGS); | |
321 | int nhrp_interface_down(ZAPI_CALLBACK_ARGS); | |
322 | int nhrp_interface_address_add(ZAPI_CALLBACK_ARGS); | |
323 | int nhrp_interface_address_delete(ZAPI_CALLBACK_ARGS); | |
996c9314 LB |
324 | |
325 | void nhrp_interface_notify_add(struct interface *ifp, struct notifier_block *n, | |
326 | notifier_fn_t fn); | |
2fb975da | 327 | void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n); |
996c9314 LB |
328 | void nhrp_interface_set_protection(struct interface *ifp, const char *profile, |
329 | const char *fallback_profile); | |
2fb975da | 330 | void nhrp_interface_set_source(struct interface *ifp, const char *ifname); |
138c5a74 DS |
331 | extern int nhrp_ifp_create(struct interface *ifp); |
332 | extern int nhrp_ifp_up(struct interface *ifp); | |
333 | extern int nhrp_ifp_down(struct interface *ifp); | |
334 | extern int nhrp_ifp_destroy(struct interface *ifp); | |
2fb975da | 335 | |
996c9314 LB |
336 | int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, |
337 | const char *nbma_fqdn); | |
338 | int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr, | |
339 | const char *nbma_fqdn); | |
2fb975da TT |
340 | int nhrp_nhs_free(struct nhrp_nhs *nhs); |
341 | void nhrp_nhs_terminate(void); | |
996c9314 LB |
342 | void nhrp_nhs_foreach(struct interface *ifp, afi_t afi, |
343 | void (*cb)(struct nhrp_nhs *, struct nhrp_registration *, | |
344 | void *), | |
345 | void *ctx); | |
ee72f0a0 | 346 | void nhrp_nhs_interface_del(struct interface *ifp); |
2fb975da TT |
347 | |
348 | void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp); | |
996c9314 LB |
349 | void nhrp_route_announce(int add, enum nhrp_cache_type type, |
350 | const struct prefix *p, struct interface *ifp, | |
351 | const union sockunion *nexthop, uint32_t mtu); | |
121f9dee | 352 | int nhrp_route_read(ZAPI_CALLBACK_ARGS); |
996c9314 LB |
353 | int nhrp_route_get_nexthop(const union sockunion *addr, struct prefix *p, |
354 | union sockunion *via, struct interface **ifp); | |
355 | enum nhrp_route_type nhrp_route_address(struct interface *in_ifp, | |
356 | union sockunion *addr, struct prefix *p, | |
357 | struct nhrp_peer **peer); | |
2fb975da TT |
358 | |
359 | void nhrp_config_init(void); | |
360 | ||
361 | void nhrp_shortcut_init(void); | |
362 | void nhrp_shortcut_terminate(void); | |
363 | void nhrp_shortcut_initiate(union sockunion *addr); | |
996c9314 LB |
364 | void nhrp_shortcut_foreach(afi_t afi, |
365 | void (*cb)(struct nhrp_shortcut *, void *), | |
366 | void *ctx); | |
2fb975da TT |
367 | void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force); |
368 | void nhrp_shortcut_prefix_change(const struct prefix *p, int deleted); | |
369 | ||
ee72f0a0 | 370 | void nhrp_cache_interface_del(struct interface *ifp); |
fef2ed13 PG |
371 | void nhrp_cache_config_free(struct nhrp_cache_config *c); |
372 | struct nhrp_cache_config *nhrp_cache_config_get(struct interface *ifp, | |
373 | union sockunion *remote_addr, | |
374 | int create); | |
996c9314 LB |
375 | struct nhrp_cache *nhrp_cache_get(struct interface *ifp, |
376 | union sockunion *remote_addr, int create); | |
377 | void nhrp_cache_foreach(struct interface *ifp, | |
378 | void (*cb)(struct nhrp_cache *, void *), void *ctx); | |
fef2ed13 PG |
379 | void nhrp_cache_config_foreach(struct interface *ifp, |
380 | void (*cb)(struct nhrp_cache_config *, void *), void *ctx); | |
2fb975da | 381 | void nhrp_cache_set_used(struct nhrp_cache *, int); |
996c9314 LB |
382 | int nhrp_cache_update_binding(struct nhrp_cache *, enum nhrp_cache_type type, |
383 | int holding_time, struct nhrp_peer *p, | |
384 | uint32_t mtu, union sockunion *nbma_natoa); | |
385 | void nhrp_cache_notify_add(struct nhrp_cache *c, struct notifier_block *, | |
386 | notifier_fn_t); | |
2fb975da TT |
387 | void nhrp_cache_notify_del(struct nhrp_cache *c, struct notifier_block *); |
388 | ||
389 | void nhrp_vc_init(void); | |
390 | void nhrp_vc_terminate(void); | |
996c9314 LB |
391 | struct nhrp_vc *nhrp_vc_get(const union sockunion *src, |
392 | const union sockunion *dst, int create); | |
2fb975da | 393 | int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc); |
996c9314 LB |
394 | void nhrp_vc_notify_add(struct nhrp_vc *, struct notifier_block *, |
395 | notifier_fn_t); | |
2fb975da TT |
396 | void nhrp_vc_notify_del(struct nhrp_vc *, struct notifier_block *); |
397 | void nhrp_vc_foreach(void (*cb)(struct nhrp_vc *, void *), void *ctx); | |
398 | void nhrp_vc_reset(void); | |
399 | ||
400 | void vici_init(void); | |
401 | void vici_terminate(void); | |
996c9314 LB |
402 | void vici_request_vc(const char *profile, union sockunion *src, |
403 | union sockunion *dst, int prio); | |
2fb975da TT |
404 | |
405 | extern const char *nhrp_event_socket_path; | |
406 | ||
407 | void evmgr_init(void); | |
408 | void evmgr_terminate(void); | |
409 | void evmgr_set_socket(const char *socket); | |
996c9314 LB |
410 | void evmgr_notify(const char *name, struct nhrp_cache *c, |
411 | void (*cb)(struct nhrp_reqid *, void *)); | |
2fb975da | 412 | |
996c9314 LB |
413 | struct nhrp_packet_header *nhrp_packet_push(struct zbuf *zb, uint8_t type, |
414 | const union sockunion *src_nbma, | |
415 | const union sockunion *src_proto, | |
416 | const union sockunion *dst_proto); | |
2fb975da TT |
417 | void nhrp_packet_complete(struct zbuf *zb, struct nhrp_packet_header *hdr); |
418 | uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu, uint16_t len); | |
419 | ||
996c9314 LB |
420 | struct nhrp_packet_header *nhrp_packet_pull(struct zbuf *zb, |
421 | union sockunion *src_nbma, | |
422 | union sockunion *src_proto, | |
423 | union sockunion *dst_proto); | |
424 | ||
425 | struct nhrp_cie_header *nhrp_cie_push(struct zbuf *zb, uint8_t code, | |
426 | const union sockunion *nbma, | |
427 | const union sockunion *proto); | |
428 | struct nhrp_cie_header *nhrp_cie_pull(struct zbuf *zb, | |
429 | struct nhrp_packet_header *hdr, | |
430 | union sockunion *nbma, | |
431 | union sockunion *proto); | |
432 | ||
433 | struct nhrp_extension_header * | |
434 | nhrp_ext_push(struct zbuf *zb, struct nhrp_packet_header *hdr, uint16_t type); | |
2fb975da | 435 | void nhrp_ext_complete(struct zbuf *zb, struct nhrp_extension_header *ext); |
996c9314 LB |
436 | struct nhrp_extension_header *nhrp_ext_pull(struct zbuf *zb, |
437 | struct zbuf *payload); | |
438 | void nhrp_ext_request(struct zbuf *zb, struct nhrp_packet_header *hdr, | |
439 | struct interface *); | |
440 | int nhrp_ext_reply(struct zbuf *zb, struct nhrp_packet_header *hdr, | |
441 | struct interface *ifp, struct nhrp_extension_header *ext, | |
442 | struct zbuf *extpayload); | |
443 | ||
444 | uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *, struct nhrp_reqid *r, | |
445 | void (*cb)(struct nhrp_reqid *, void *)); | |
2fb975da TT |
446 | void nhrp_reqid_free(struct nhrp_reqid_pool *, struct nhrp_reqid *r); |
447 | struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *, uint32_t reqid); | |
448 | ||
449 | int nhrp_packet_init(void); | |
450 | ||
ee72f0a0 | 451 | void nhrp_peer_interface_del(struct interface *ifp); |
996c9314 LB |
452 | struct nhrp_peer *nhrp_peer_get(struct interface *ifp, |
453 | const union sockunion *remote_nbma); | |
2fb975da TT |
454 | struct nhrp_peer *nhrp_peer_ref(struct nhrp_peer *p); |
455 | void nhrp_peer_unref(struct nhrp_peer *p); | |
456 | int nhrp_peer_check(struct nhrp_peer *p, int establish); | |
996c9314 LB |
457 | void nhrp_peer_notify_add(struct nhrp_peer *p, struct notifier_block *, |
458 | notifier_fn_t); | |
2fb975da TT |
459 | void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *); |
460 | void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb); | |
461 | void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb); | |
462 | void nhrp_peer_send_indication(struct interface *ifp, uint16_t, struct zbuf *); | |
463 | ||
464 | #endif |