]>
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 DL |
18 | #include "memory.h" |
19 | ||
20 | DECLARE_MGROUP(NHRPD) | |
2fb975da TT |
21 | |
22 | #define NHRPD_DEFAULT_HOLDTIME 7200 | |
23 | ||
442deed8 | 24 | #define NHRP_VTY_PORT 2610 |
2fb975da TT |
25 | #define NHRP_DEFAULT_CONFIG "nhrpd.conf" |
26 | ||
27 | extern struct thread_master *master; | |
28 | ||
996c9314 LB |
29 | enum { NHRP_OK = 0, |
30 | NHRP_ERR_FAIL, | |
31 | NHRP_ERR_NO_MEMORY, | |
32 | NHRP_ERR_UNSUPPORTED_INTERFACE, | |
33 | NHRP_ERR_NHRP_NOT_ENABLED, | |
34 | NHRP_ERR_ENTRY_EXISTS, | |
35 | NHRP_ERR_ENTRY_NOT_FOUND, | |
36 | NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH, | |
37 | __NHRP_ERR_MAX }; | |
6c8ca260 | 38 | #define NHRP_ERR_MAX (__NHRP_ERR_MAX - 1) |
2fb975da TT |
39 | |
40 | struct notifier_block; | |
41 | ||
42 | typedef void (*notifier_fn_t)(struct notifier_block *, unsigned long); | |
43 | ||
44 | struct notifier_block { | |
45 | struct list_head notifier_entry; | |
46 | notifier_fn_t action; | |
47 | }; | |
48 | ||
49 | struct notifier_list { | |
50 | struct list_head notifier_head; | |
51 | }; | |
52 | ||
996c9314 LB |
53 | #define NOTIFIER_LIST_INITIALIZER(l) \ |
54 | { \ | |
55 | .notifier_head = LIST_INITIALIZER((l)->notifier_head) \ | |
56 | } | |
2fb975da TT |
57 | |
58 | static inline void notifier_init(struct notifier_list *l) | |
59 | { | |
60 | list_init(&l->notifier_head); | |
61 | } | |
62 | ||
996c9314 LB |
63 | static inline void notifier_add(struct notifier_block *n, |
64 | struct notifier_list *l, notifier_fn_t action) | |
2fb975da TT |
65 | { |
66 | n->action = action; | |
67 | list_add_tail(&n->notifier_entry, &l->notifier_head); | |
68 | } | |
69 | ||
70 | static inline void notifier_del(struct notifier_block *n) | |
71 | { | |
72 | list_del(&n->notifier_entry); | |
73 | } | |
74 | ||
75 | static inline void notifier_call(struct notifier_list *l, int cmd) | |
76 | { | |
77 | struct notifier_block *n, *nn; | |
78 | list_for_each_entry_safe(n, nn, &l->notifier_head, notifier_entry) | |
79 | n->action(n, cmd); | |
80 | } | |
81 | ||
82 | static inline int notifier_active(struct notifier_list *l) | |
83 | { | |
84 | return !list_empty(&l->notifier_head); | |
85 | } | |
86 | ||
87 | struct resolver_query { | |
88 | void (*callback)(struct resolver_query *, int n, union sockunion *); | |
89 | }; | |
90 | ||
91 | void resolver_init(void); | |
996c9314 LB |
92 | void resolver_resolve(struct resolver_query *query, int af, |
93 | const char *hostname, void (*cb)(struct resolver_query *, | |
94 | int, union sockunion *)); | |
2fb975da TT |
95 | |
96 | void nhrp_zebra_init(void); | |
97 | void nhrp_zebra_terminate(void); | |
98 | ||
99 | struct zbuf; | |
100 | struct nhrp_vc; | |
101 | struct nhrp_cache; | |
102 | struct nhrp_nhs; | |
103 | struct nhrp_interface; | |
104 | ||
105 | #define MAX_ID_LENGTH 64 | |
106 | #define MAX_CERT_LENGTH 2048 | |
107 | ||
108 | enum nhrp_notify_type { | |
109 | NOTIFY_INTERFACE_UP, | |
110 | NOTIFY_INTERFACE_DOWN, | |
111 | NOTIFY_INTERFACE_CHANGED, | |
112 | NOTIFY_INTERFACE_ADDRESS_CHANGED, | |
113 | NOTIFY_INTERFACE_NBMA_CHANGED, | |
114 | NOTIFY_INTERFACE_MTU_CHANGED, | |
115 | ||
116 | NOTIFY_VC_IPSEC_CHANGED, | |
117 | NOTIFY_VC_IPSEC_UPDATE_NBMA, | |
118 | ||
119 | NOTIFY_PEER_UP, | |
120 | NOTIFY_PEER_DOWN, | |
121 | NOTIFY_PEER_IFCONFIG_CHANGED, | |
122 | NOTIFY_PEER_MTU_CHANGED, | |
123 | NOTIFY_PEER_NBMA_CHANGING, | |
124 | ||
125 | NOTIFY_CACHE_UP, | |
126 | NOTIFY_CACHE_DOWN, | |
127 | NOTIFY_CACHE_DELETE, | |
128 | NOTIFY_CACHE_USED, | |
129 | NOTIFY_CACHE_BINDING_CHANGE, | |
130 | }; | |
131 | ||
132 | struct nhrp_vc { | |
133 | struct notifier_list notifier_list; | |
134 | uint8_t ipsec; | |
135 | uint8_t updating; | |
136 | uint8_t abort_migration; | |
137 | ||
138 | struct nhrp_vc_peer { | |
139 | union sockunion nbma; | |
140 | char id[MAX_ID_LENGTH]; | |
141 | uint16_t certlen; | |
142 | uint8_t cert[MAX_CERT_LENGTH]; | |
143 | } local, remote; | |
144 | }; | |
145 | ||
146 | enum nhrp_route_type { | |
147 | NHRP_ROUTE_BLACKHOLE, | |
148 | NHRP_ROUTE_LOCAL, | |
149 | NHRP_ROUTE_NBMA_NEXTHOP, | |
150 | NHRP_ROUTE_OFF_NBMA, | |
151 | }; | |
152 | ||
153 | struct nhrp_peer { | |
154 | unsigned int ref; | |
155 | unsigned online : 1; | |
156 | unsigned requested : 1; | |
157 | unsigned fallback_requested : 1; | |
158 | unsigned prio : 1; | |
159 | struct notifier_list notifier_list; | |
160 | struct interface *ifp; | |
161 | struct nhrp_vc *vc; | |
162 | struct thread *t_fallback; | |
163 | struct notifier_block vc_notifier, ifp_notifier; | |
164 | }; | |
165 | ||
166 | struct nhrp_packet_parser { | |
167 | struct interface *ifp; | |
168 | struct nhrp_afi_data *if_ad; | |
169 | struct nhrp_peer *peer; | |
170 | struct zbuf *pkt; | |
171 | struct zbuf payload; | |
172 | struct zbuf extensions; | |
173 | struct nhrp_packet_header *hdr; | |
174 | enum nhrp_route_type route_type; | |
175 | struct prefix route_prefix; | |
176 | union sockunion src_nbma, src_proto, dst_proto; | |
177 | }; | |
178 | ||
179 | struct nhrp_reqid_pool { | |
180 | struct hash *reqid_hash; | |
181 | uint32_t next_request_id; | |
182 | }; | |
183 | ||
184 | struct nhrp_reqid { | |
185 | uint32_t request_id; | |
186 | void (*cb)(struct nhrp_reqid *, void *); | |
187 | }; | |
188 | ||
189 | extern struct nhrp_reqid_pool nhrp_packet_reqid; | |
190 | extern struct nhrp_reqid_pool nhrp_event_reqid; | |
191 | ||
192 | enum nhrp_cache_type { | |
193 | NHRP_CACHE_INVALID = 0, | |
194 | NHRP_CACHE_INCOMPLETE, | |
195 | NHRP_CACHE_NEGATIVE, | |
196 | NHRP_CACHE_CACHED, | |
197 | NHRP_CACHE_DYNAMIC, | |
198 | NHRP_CACHE_NHS, | |
199 | NHRP_CACHE_STATIC, | |
200 | NHRP_CACHE_LOCAL, | |
201 | NHRP_CACHE_NUM_TYPES | |
202 | }; | |
203 | ||
996c9314 | 204 | extern const char *const nhrp_cache_type_str[]; |
2fb975da TT |
205 | extern unsigned long nhrp_cache_counts[NHRP_CACHE_NUM_TYPES]; |
206 | ||
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; | |
290 | struct hash *cache_hash; | |
291 | ||
292 | struct notifier_list notifier_list; | |
293 | ||
294 | struct interface *nbmaifp; | |
295 | struct notifier_block nbmanifp_notifier; | |
296 | ||
297 | struct nhrp_afi_data { | |
298 | unsigned flags; | |
299 | unsigned short configured : 1; | |
300 | union sockunion addr; | |
301 | uint32_t network_id; | |
302 | short configured_mtu; | |
303 | unsigned short mtu; | |
304 | unsigned int holdtime; | |
305 | struct list_head nhslist_head; | |
306 | } afi[AFI_MAX]; | |
307 | }; | |
308 | ||
26efbc7b DS |
309 | extern struct zebra_privs_t nhrpd_privs; |
310 | ||
2fb975da TT |
311 | int sock_open_unix(const char *path); |
312 | ||
313 | void nhrp_interface_init(void); | |
314 | void nhrp_interface_update(struct interface *ifp); | |
315 | void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi); | |
316 | ||
996c9314 LB |
317 | int nhrp_interface_add(int cmd, struct zclient *client, zebra_size_t length, |
318 | vrf_id_t vrf_id); | |
319 | int nhrp_interface_delete(int cmd, struct zclient *client, zebra_size_t length, | |
320 | vrf_id_t vrf_id); | |
321 | int nhrp_interface_up(int cmd, struct zclient *client, zebra_size_t length, | |
322 | vrf_id_t vrf_id); | |
323 | int nhrp_interface_down(int cmd, struct zclient *client, zebra_size_t length, | |
324 | vrf_id_t vrf_id); | |
325 | int nhrp_interface_address_add(int cmd, struct zclient *client, | |
326 | zebra_size_t length, vrf_id_t vrf_id); | |
327 | int nhrp_interface_address_delete(int cmd, struct zclient *client, | |
328 | zebra_size_t length, vrf_id_t vrf_id); | |
329 | ||
330 | void nhrp_interface_notify_add(struct interface *ifp, struct notifier_block *n, | |
331 | notifier_fn_t fn); | |
2fb975da | 332 | void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n); |
996c9314 LB |
333 | void nhrp_interface_set_protection(struct interface *ifp, const char *profile, |
334 | const char *fallback_profile); | |
2fb975da TT |
335 | void nhrp_interface_set_source(struct interface *ifp, const char *ifname); |
336 | ||
996c9314 LB |
337 | int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, |
338 | const char *nbma_fqdn); | |
339 | int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr, | |
340 | const char *nbma_fqdn); | |
2fb975da TT |
341 | int nhrp_nhs_free(struct nhrp_nhs *nhs); |
342 | void nhrp_nhs_terminate(void); | |
996c9314 LB |
343 | void nhrp_nhs_foreach(struct interface *ifp, afi_t afi, |
344 | void (*cb)(struct nhrp_nhs *, struct nhrp_registration *, | |
345 | void *), | |
346 | void *ctx); | |
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); | |
352 | int nhrp_route_read(int command, struct zclient *zclient, zebra_size_t length, | |
353 | vrf_id_t vrf_id); | |
354 | int nhrp_route_get_nexthop(const union sockunion *addr, struct prefix *p, | |
355 | union sockunion *via, struct interface **ifp); | |
356 | enum nhrp_route_type nhrp_route_address(struct interface *in_ifp, | |
357 | union sockunion *addr, struct prefix *p, | |
358 | struct nhrp_peer **peer); | |
2fb975da TT |
359 | |
360 | void nhrp_config_init(void); | |
361 | ||
362 | void nhrp_shortcut_init(void); | |
363 | void nhrp_shortcut_terminate(void); | |
364 | void nhrp_shortcut_initiate(union sockunion *addr); | |
996c9314 LB |
365 | void nhrp_shortcut_foreach(afi_t afi, |
366 | void (*cb)(struct nhrp_shortcut *, void *), | |
367 | void *ctx); | |
2fb975da TT |
368 | void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force); |
369 | void nhrp_shortcut_prefix_change(const struct prefix *p, int deleted); | |
370 | ||
996c9314 LB |
371 | struct nhrp_cache *nhrp_cache_get(struct interface *ifp, |
372 | union sockunion *remote_addr, int create); | |
373 | void nhrp_cache_foreach(struct interface *ifp, | |
374 | void (*cb)(struct nhrp_cache *, void *), void *ctx); | |
2fb975da | 375 | void nhrp_cache_set_used(struct nhrp_cache *, int); |
996c9314 LB |
376 | int nhrp_cache_update_binding(struct nhrp_cache *, enum nhrp_cache_type type, |
377 | int holding_time, struct nhrp_peer *p, | |
378 | uint32_t mtu, union sockunion *nbma_natoa); | |
379 | void nhrp_cache_notify_add(struct nhrp_cache *c, struct notifier_block *, | |
380 | notifier_fn_t); | |
2fb975da TT |
381 | void nhrp_cache_notify_del(struct nhrp_cache *c, struct notifier_block *); |
382 | ||
383 | void nhrp_vc_init(void); | |
384 | void nhrp_vc_terminate(void); | |
996c9314 LB |
385 | struct nhrp_vc *nhrp_vc_get(const union sockunion *src, |
386 | const union sockunion *dst, int create); | |
2fb975da | 387 | int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc); |
996c9314 LB |
388 | void nhrp_vc_notify_add(struct nhrp_vc *, struct notifier_block *, |
389 | notifier_fn_t); | |
2fb975da TT |
390 | void nhrp_vc_notify_del(struct nhrp_vc *, struct notifier_block *); |
391 | void nhrp_vc_foreach(void (*cb)(struct nhrp_vc *, void *), void *ctx); | |
392 | void nhrp_vc_reset(void); | |
393 | ||
394 | void vici_init(void); | |
395 | void vici_terminate(void); | |
996c9314 LB |
396 | void vici_request_vc(const char *profile, union sockunion *src, |
397 | union sockunion *dst, int prio); | |
2fb975da TT |
398 | |
399 | extern const char *nhrp_event_socket_path; | |
400 | ||
401 | void evmgr_init(void); | |
402 | void evmgr_terminate(void); | |
403 | void evmgr_set_socket(const char *socket); | |
996c9314 LB |
404 | void evmgr_notify(const char *name, struct nhrp_cache *c, |
405 | void (*cb)(struct nhrp_reqid *, void *)); | |
2fb975da | 406 | |
996c9314 LB |
407 | struct nhrp_packet_header *nhrp_packet_push(struct zbuf *zb, uint8_t type, |
408 | const union sockunion *src_nbma, | |
409 | const union sockunion *src_proto, | |
410 | const union sockunion *dst_proto); | |
2fb975da TT |
411 | void nhrp_packet_complete(struct zbuf *zb, struct nhrp_packet_header *hdr); |
412 | uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu, uint16_t len); | |
413 | ||
996c9314 LB |
414 | struct nhrp_packet_header *nhrp_packet_pull(struct zbuf *zb, |
415 | union sockunion *src_nbma, | |
416 | union sockunion *src_proto, | |
417 | union sockunion *dst_proto); | |
418 | ||
419 | struct nhrp_cie_header *nhrp_cie_push(struct zbuf *zb, uint8_t code, | |
420 | const union sockunion *nbma, | |
421 | const union sockunion *proto); | |
422 | struct nhrp_cie_header *nhrp_cie_pull(struct zbuf *zb, | |
423 | struct nhrp_packet_header *hdr, | |
424 | union sockunion *nbma, | |
425 | union sockunion *proto); | |
426 | ||
427 | struct nhrp_extension_header * | |
428 | nhrp_ext_push(struct zbuf *zb, struct nhrp_packet_header *hdr, uint16_t type); | |
2fb975da | 429 | void nhrp_ext_complete(struct zbuf *zb, struct nhrp_extension_header *ext); |
996c9314 LB |
430 | struct nhrp_extension_header *nhrp_ext_pull(struct zbuf *zb, |
431 | struct zbuf *payload); | |
432 | void nhrp_ext_request(struct zbuf *zb, struct nhrp_packet_header *hdr, | |
433 | struct interface *); | |
434 | int nhrp_ext_reply(struct zbuf *zb, struct nhrp_packet_header *hdr, | |
435 | struct interface *ifp, struct nhrp_extension_header *ext, | |
436 | struct zbuf *extpayload); | |
437 | ||
438 | uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *, struct nhrp_reqid *r, | |
439 | void (*cb)(struct nhrp_reqid *, void *)); | |
2fb975da TT |
440 | void nhrp_reqid_free(struct nhrp_reqid_pool *, struct nhrp_reqid *r); |
441 | struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *, uint32_t reqid); | |
442 | ||
443 | int nhrp_packet_init(void); | |
444 | ||
996c9314 LB |
445 | struct nhrp_peer *nhrp_peer_get(struct interface *ifp, |
446 | const union sockunion *remote_nbma); | |
2fb975da TT |
447 | struct nhrp_peer *nhrp_peer_ref(struct nhrp_peer *p); |
448 | void nhrp_peer_unref(struct nhrp_peer *p); | |
449 | int nhrp_peer_check(struct nhrp_peer *p, int establish); | |
996c9314 LB |
450 | void nhrp_peer_notify_add(struct nhrp_peer *p, struct notifier_block *, |
451 | notifier_fn_t); | |
2fb975da TT |
452 | void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *); |
453 | void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb); | |
454 | void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb); | |
455 | void nhrp_peer_send_indication(struct interface *ifp, uint16_t, struct zbuf *); | |
456 | ||
457 | #endif |