]>
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 MS |
79 | list_for_each_entry_safe(n, nn, &l->notifier_head, notifier_entry) { |
80 | if (n) | |
81 | n->action(n, cmd); | |
82 | } | |
2fb975da TT |
83 | } |
84 | ||
85 | static inline int notifier_active(struct notifier_list *l) | |
86 | { | |
87 | return !list_empty(&l->notifier_head); | |
88 | } | |
89 | ||
2fb975da TT |
90 | void nhrp_zebra_init(void); |
91 | void nhrp_zebra_terminate(void); | |
92 | ||
93 | struct zbuf; | |
94 | struct nhrp_vc; | |
95 | struct nhrp_cache; | |
96 | struct nhrp_nhs; | |
97 | struct nhrp_interface; | |
98 | ||
99 | #define MAX_ID_LENGTH 64 | |
100 | #define MAX_CERT_LENGTH 2048 | |
101 | ||
102 | enum nhrp_notify_type { | |
103 | NOTIFY_INTERFACE_UP, | |
104 | NOTIFY_INTERFACE_DOWN, | |
105 | NOTIFY_INTERFACE_CHANGED, | |
106 | NOTIFY_INTERFACE_ADDRESS_CHANGED, | |
107 | NOTIFY_INTERFACE_NBMA_CHANGED, | |
108 | NOTIFY_INTERFACE_MTU_CHANGED, | |
109 | ||
110 | NOTIFY_VC_IPSEC_CHANGED, | |
111 | NOTIFY_VC_IPSEC_UPDATE_NBMA, | |
112 | ||
113 | NOTIFY_PEER_UP, | |
114 | NOTIFY_PEER_DOWN, | |
115 | NOTIFY_PEER_IFCONFIG_CHANGED, | |
116 | NOTIFY_PEER_MTU_CHANGED, | |
117 | NOTIFY_PEER_NBMA_CHANGING, | |
118 | ||
119 | NOTIFY_CACHE_UP, | |
120 | NOTIFY_CACHE_DOWN, | |
121 | NOTIFY_CACHE_DELETE, | |
122 | NOTIFY_CACHE_USED, | |
123 | NOTIFY_CACHE_BINDING_CHANGE, | |
124 | }; | |
125 | ||
126 | struct nhrp_vc { | |
127 | struct notifier_list notifier_list; | |
128 | uint8_t ipsec; | |
129 | uint8_t updating; | |
130 | uint8_t abort_migration; | |
131 | ||
132 | struct nhrp_vc_peer { | |
133 | union sockunion nbma; | |
134 | char id[MAX_ID_LENGTH]; | |
135 | uint16_t certlen; | |
136 | uint8_t cert[MAX_CERT_LENGTH]; | |
137 | } local, remote; | |
138 | }; | |
139 | ||
140 | enum nhrp_route_type { | |
141 | NHRP_ROUTE_BLACKHOLE, | |
142 | NHRP_ROUTE_LOCAL, | |
143 | NHRP_ROUTE_NBMA_NEXTHOP, | |
144 | NHRP_ROUTE_OFF_NBMA, | |
145 | }; | |
146 | ||
147 | struct nhrp_peer { | |
148 | unsigned int ref; | |
149 | unsigned online : 1; | |
150 | unsigned requested : 1; | |
151 | unsigned fallback_requested : 1; | |
152 | unsigned prio : 1; | |
153 | struct notifier_list notifier_list; | |
154 | struct interface *ifp; | |
155 | struct nhrp_vc *vc; | |
156 | struct thread *t_fallback; | |
157 | struct notifier_block vc_notifier, ifp_notifier; | |
158 | }; | |
159 | ||
160 | struct nhrp_packet_parser { | |
161 | struct interface *ifp; | |
162 | struct nhrp_afi_data *if_ad; | |
163 | struct nhrp_peer *peer; | |
164 | struct zbuf *pkt; | |
165 | struct zbuf payload; | |
166 | struct zbuf extensions; | |
167 | struct nhrp_packet_header *hdr; | |
168 | enum nhrp_route_type route_type; | |
169 | struct prefix route_prefix; | |
170 | union sockunion src_nbma, src_proto, dst_proto; | |
171 | }; | |
172 | ||
173 | struct nhrp_reqid_pool { | |
174 | struct hash *reqid_hash; | |
175 | uint32_t next_request_id; | |
176 | }; | |
177 | ||
178 | struct nhrp_reqid { | |
179 | uint32_t request_id; | |
180 | void (*cb)(struct nhrp_reqid *, void *); | |
181 | }; | |
182 | ||
183 | extern struct nhrp_reqid_pool nhrp_packet_reqid; | |
184 | extern struct nhrp_reqid_pool nhrp_event_reqid; | |
185 | ||
186 | enum nhrp_cache_type { | |
187 | NHRP_CACHE_INVALID = 0, | |
188 | NHRP_CACHE_INCOMPLETE, | |
189 | NHRP_CACHE_NEGATIVE, | |
190 | NHRP_CACHE_CACHED, | |
191 | NHRP_CACHE_DYNAMIC, | |
192 | NHRP_CACHE_NHS, | |
193 | NHRP_CACHE_STATIC, | |
194 | NHRP_CACHE_LOCAL, | |
195 | NHRP_CACHE_NUM_TYPES | |
196 | }; | |
197 | ||
996c9314 | 198 | extern const char *const nhrp_cache_type_str[]; |
2fb975da TT |
199 | extern unsigned long nhrp_cache_counts[NHRP_CACHE_NUM_TYPES]; |
200 | ||
201 | struct nhrp_cache { | |
202 | struct interface *ifp; | |
203 | union sockunion remote_addr; | |
204 | ||
205 | unsigned map : 1; | |
206 | unsigned used : 1; | |
207 | unsigned route_installed : 1; | |
208 | unsigned nhrp_route_installed : 1; | |
209 | ||
210 | struct notifier_block peer_notifier; | |
211 | struct notifier_block newpeer_notifier; | |
212 | struct notifier_list notifier_list; | |
213 | struct nhrp_reqid eventid; | |
214 | struct thread *t_timeout; | |
215 | struct thread *t_auth; | |
216 | ||
217 | struct { | |
218 | enum nhrp_cache_type type; | |
219 | union sockunion remote_nbma_natoa; | |
220 | struct nhrp_peer *peer; | |
221 | time_t expires; | |
222 | uint32_t mtu; | |
223 | } cur, new; | |
224 | }; | |
225 | ||
226 | struct nhrp_shortcut { | |
227 | struct prefix *p; | |
228 | union sockunion addr; | |
229 | ||
230 | struct nhrp_reqid reqid; | |
231 | struct thread *t_timer; | |
232 | ||
233 | enum nhrp_cache_type type; | |
234 | unsigned int holding_time; | |
235 | unsigned route_installed : 1; | |
236 | unsigned expiring : 1; | |
237 | ||
238 | struct nhrp_cache *cache; | |
239 | struct notifier_block cache_notifier; | |
240 | }; | |
241 | ||
242 | struct nhrp_nhs { | |
243 | struct interface *ifp; | |
244 | struct list_head nhslist_entry; | |
245 | ||
246 | unsigned hub : 1; | |
247 | afi_t afi; | |
248 | union sockunion proto_addr; | |
996c9314 | 249 | const char *nbma_fqdn; /* IP-address or FQDN */ |
2fb975da TT |
250 | |
251 | struct thread *t_resolve; | |
252 | struct resolver_query dns_resolve; | |
253 | struct list_head reglist_head; | |
254 | }; | |
255 | ||
0ca036b4 TT |
256 | struct nhrp_registration { |
257 | struct list_head reglist_entry; | |
258 | struct thread *t_register; | |
259 | struct nhrp_nhs *nhs; | |
260 | struct nhrp_reqid reqid; | |
261 | unsigned int timeout; | |
262 | unsigned mark : 1; | |
263 | union sockunion proto_addr; | |
264 | struct nhrp_peer *peer; | |
265 | struct notifier_block peer_notifier; | |
266 | }; | |
267 | ||
2fb975da TT |
268 | #define NHRP_IFF_SHORTCUT 0x0001 |
269 | #define NHRP_IFF_REDIRECT 0x0002 | |
270 | #define NHRP_IFF_REG_NO_UNIQUE 0x0100 | |
271 | ||
272 | struct nhrp_interface { | |
273 | struct interface *ifp; | |
274 | ||
275 | unsigned enabled : 1; | |
276 | ||
277 | char *ipsec_profile, *ipsec_fallback_profile, *source; | |
278 | union sockunion nbma; | |
279 | union sockunion nat_nbma; | |
280 | unsigned int linkidx; | |
281 | uint32_t grekey; | |
282 | ||
283 | struct hash *peer_hash; | |
284 | struct hash *cache_hash; | |
285 | ||
286 | struct notifier_list notifier_list; | |
287 | ||
288 | struct interface *nbmaifp; | |
289 | struct notifier_block nbmanifp_notifier; | |
290 | ||
291 | struct nhrp_afi_data { | |
292 | unsigned flags; | |
293 | unsigned short configured : 1; | |
294 | union sockunion addr; | |
295 | uint32_t network_id; | |
296 | short configured_mtu; | |
297 | unsigned short mtu; | |
298 | unsigned int holdtime; | |
299 | struct list_head nhslist_head; | |
300 | } afi[AFI_MAX]; | |
301 | }; | |
302 | ||
26efbc7b DS |
303 | extern struct zebra_privs_t nhrpd_privs; |
304 | ||
2fb975da TT |
305 | int sock_open_unix(const char *path); |
306 | ||
307 | void nhrp_interface_init(void); | |
308 | void nhrp_interface_update(struct interface *ifp); | |
309 | void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi); | |
310 | ||
121f9dee QY |
311 | int nhrp_interface_add(ZAPI_CALLBACK_ARGS); |
312 | int nhrp_interface_delete(ZAPI_CALLBACK_ARGS); | |
313 | int nhrp_interface_up(ZAPI_CALLBACK_ARGS); | |
314 | int nhrp_interface_down(ZAPI_CALLBACK_ARGS); | |
315 | int nhrp_interface_address_add(ZAPI_CALLBACK_ARGS); | |
316 | int nhrp_interface_address_delete(ZAPI_CALLBACK_ARGS); | |
996c9314 LB |
317 | |
318 | void nhrp_interface_notify_add(struct interface *ifp, struct notifier_block *n, | |
319 | notifier_fn_t fn); | |
2fb975da | 320 | void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n); |
996c9314 LB |
321 | void nhrp_interface_set_protection(struct interface *ifp, const char *profile, |
322 | const char *fallback_profile); | |
2fb975da | 323 | void nhrp_interface_set_source(struct interface *ifp, const char *ifname); |
138c5a74 DS |
324 | extern int nhrp_ifp_create(struct interface *ifp); |
325 | extern int nhrp_ifp_up(struct interface *ifp); | |
326 | extern int nhrp_ifp_down(struct interface *ifp); | |
327 | extern int nhrp_ifp_destroy(struct interface *ifp); | |
2fb975da | 328 | |
996c9314 LB |
329 | int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, |
330 | const char *nbma_fqdn); | |
331 | int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr, | |
332 | const char *nbma_fqdn); | |
2fb975da TT |
333 | int nhrp_nhs_free(struct nhrp_nhs *nhs); |
334 | void nhrp_nhs_terminate(void); | |
996c9314 LB |
335 | void nhrp_nhs_foreach(struct interface *ifp, afi_t afi, |
336 | void (*cb)(struct nhrp_nhs *, struct nhrp_registration *, | |
337 | void *), | |
338 | void *ctx); | |
2fb975da TT |
339 | |
340 | void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp); | |
996c9314 LB |
341 | void nhrp_route_announce(int add, enum nhrp_cache_type type, |
342 | const struct prefix *p, struct interface *ifp, | |
343 | const union sockunion *nexthop, uint32_t mtu); | |
121f9dee | 344 | int nhrp_route_read(ZAPI_CALLBACK_ARGS); |
996c9314 LB |
345 | int nhrp_route_get_nexthop(const union sockunion *addr, struct prefix *p, |
346 | union sockunion *via, struct interface **ifp); | |
347 | enum nhrp_route_type nhrp_route_address(struct interface *in_ifp, | |
348 | union sockunion *addr, struct prefix *p, | |
349 | struct nhrp_peer **peer); | |
2fb975da TT |
350 | |
351 | void nhrp_config_init(void); | |
352 | ||
353 | void nhrp_shortcut_init(void); | |
354 | void nhrp_shortcut_terminate(void); | |
355 | void nhrp_shortcut_initiate(union sockunion *addr); | |
996c9314 LB |
356 | void nhrp_shortcut_foreach(afi_t afi, |
357 | void (*cb)(struct nhrp_shortcut *, void *), | |
358 | void *ctx); | |
2fb975da TT |
359 | void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force); |
360 | void nhrp_shortcut_prefix_change(const struct prefix *p, int deleted); | |
361 | ||
996c9314 LB |
362 | struct nhrp_cache *nhrp_cache_get(struct interface *ifp, |
363 | union sockunion *remote_addr, int create); | |
364 | void nhrp_cache_foreach(struct interface *ifp, | |
365 | void (*cb)(struct nhrp_cache *, void *), void *ctx); | |
2fb975da | 366 | void nhrp_cache_set_used(struct nhrp_cache *, int); |
996c9314 LB |
367 | int nhrp_cache_update_binding(struct nhrp_cache *, enum nhrp_cache_type type, |
368 | int holding_time, struct nhrp_peer *p, | |
369 | uint32_t mtu, union sockunion *nbma_natoa); | |
370 | void nhrp_cache_notify_add(struct nhrp_cache *c, struct notifier_block *, | |
371 | notifier_fn_t); | |
2fb975da TT |
372 | void nhrp_cache_notify_del(struct nhrp_cache *c, struct notifier_block *); |
373 | ||
374 | void nhrp_vc_init(void); | |
375 | void nhrp_vc_terminate(void); | |
996c9314 LB |
376 | struct nhrp_vc *nhrp_vc_get(const union sockunion *src, |
377 | const union sockunion *dst, int create); | |
2fb975da | 378 | int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc); |
996c9314 LB |
379 | void nhrp_vc_notify_add(struct nhrp_vc *, struct notifier_block *, |
380 | notifier_fn_t); | |
2fb975da TT |
381 | void nhrp_vc_notify_del(struct nhrp_vc *, struct notifier_block *); |
382 | void nhrp_vc_foreach(void (*cb)(struct nhrp_vc *, void *), void *ctx); | |
383 | void nhrp_vc_reset(void); | |
384 | ||
385 | void vici_init(void); | |
386 | void vici_terminate(void); | |
996c9314 LB |
387 | void vici_request_vc(const char *profile, union sockunion *src, |
388 | union sockunion *dst, int prio); | |
2fb975da TT |
389 | |
390 | extern const char *nhrp_event_socket_path; | |
391 | ||
392 | void evmgr_init(void); | |
393 | void evmgr_terminate(void); | |
394 | void evmgr_set_socket(const char *socket); | |
996c9314 LB |
395 | void evmgr_notify(const char *name, struct nhrp_cache *c, |
396 | void (*cb)(struct nhrp_reqid *, void *)); | |
2fb975da | 397 | |
996c9314 LB |
398 | struct nhrp_packet_header *nhrp_packet_push(struct zbuf *zb, uint8_t type, |
399 | const union sockunion *src_nbma, | |
400 | const union sockunion *src_proto, | |
401 | const union sockunion *dst_proto); | |
2fb975da TT |
402 | void nhrp_packet_complete(struct zbuf *zb, struct nhrp_packet_header *hdr); |
403 | uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu, uint16_t len); | |
404 | ||
996c9314 LB |
405 | struct nhrp_packet_header *nhrp_packet_pull(struct zbuf *zb, |
406 | union sockunion *src_nbma, | |
407 | union sockunion *src_proto, | |
408 | union sockunion *dst_proto); | |
409 | ||
410 | struct nhrp_cie_header *nhrp_cie_push(struct zbuf *zb, uint8_t code, | |
411 | const union sockunion *nbma, | |
412 | const union sockunion *proto); | |
413 | struct nhrp_cie_header *nhrp_cie_pull(struct zbuf *zb, | |
414 | struct nhrp_packet_header *hdr, | |
415 | union sockunion *nbma, | |
416 | union sockunion *proto); | |
417 | ||
418 | struct nhrp_extension_header * | |
419 | nhrp_ext_push(struct zbuf *zb, struct nhrp_packet_header *hdr, uint16_t type); | |
2fb975da | 420 | void nhrp_ext_complete(struct zbuf *zb, struct nhrp_extension_header *ext); |
996c9314 LB |
421 | struct nhrp_extension_header *nhrp_ext_pull(struct zbuf *zb, |
422 | struct zbuf *payload); | |
423 | void nhrp_ext_request(struct zbuf *zb, struct nhrp_packet_header *hdr, | |
424 | struct interface *); | |
425 | int nhrp_ext_reply(struct zbuf *zb, struct nhrp_packet_header *hdr, | |
426 | struct interface *ifp, struct nhrp_extension_header *ext, | |
427 | struct zbuf *extpayload); | |
428 | ||
429 | uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *, struct nhrp_reqid *r, | |
430 | void (*cb)(struct nhrp_reqid *, void *)); | |
2fb975da TT |
431 | void nhrp_reqid_free(struct nhrp_reqid_pool *, struct nhrp_reqid *r); |
432 | struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *, uint32_t reqid); | |
433 | ||
434 | int nhrp_packet_init(void); | |
435 | ||
996c9314 LB |
436 | struct nhrp_peer *nhrp_peer_get(struct interface *ifp, |
437 | const union sockunion *remote_nbma); | |
2fb975da TT |
438 | struct nhrp_peer *nhrp_peer_ref(struct nhrp_peer *p); |
439 | void nhrp_peer_unref(struct nhrp_peer *p); | |
440 | int nhrp_peer_check(struct nhrp_peer *p, int establish); | |
996c9314 LB |
441 | void nhrp_peer_notify_add(struct nhrp_peer *p, struct notifier_block *, |
442 | notifier_fn_t); | |
2fb975da TT |
443 | void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *); |
444 | void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb); | |
445 | void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb); | |
446 | void nhrp_peer_send_indication(struct interface *ifp, uint16_t, struct zbuf *); | |
447 | ||
448 | #endif |