]> git.proxmox.com Git - mirror_frr.git/blob - nhrpd/nhrpd.h
nhrpd: convert reg list to DLIST
[mirror_frr.git] / nhrpd / nhrpd.h
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"
18 #include "memory.h"
19 #include "resolver.h"
20
21 DECLARE_MGROUP(NHRPD);
22
23 #define NHRPD_DEFAULT_HOLDTIME 7200
24
25 #define NHRP_VTY_PORT 2610
26 #define NHRP_DEFAULT_CONFIG "nhrpd.conf"
27
28 extern struct thread_master *master;
29
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 };
39 #define NHRP_ERR_MAX (__NHRP_ERR_MAX - 1)
40
41 struct notifier_block;
42
43 typedef void (*notifier_fn_t)(struct notifier_block *, unsigned long);
44
45 PREDECL_DLIST(notifier_list);
46
47 struct notifier_block {
48 struct notifier_list_item notifier_entry;
49 notifier_fn_t action;
50 };
51
52 DECLARE_DLIST(notifier_list, struct notifier_block, notifier_entry);
53
54 struct notifier_list {
55 struct notifier_list_head head;
56 };
57
58 #define NOTIFIER_LIST_INITIALIZER(l) \
59 { \
60 .head = INIT_DLIST((l)->head) \
61 }
62
63 static inline void notifier_init(struct notifier_list *l)
64 {
65 notifier_list_init(&l->head);
66 }
67
68 static inline void notifier_add(struct notifier_block *n,
69 struct notifier_list *l, notifier_fn_t action)
70 {
71 n->action = action;
72 notifier_list_add_tail(&l->head, n);
73 }
74
75 static inline void notifier_del(struct notifier_block *n,
76 struct notifier_list *l)
77 {
78 notifier_list_del(&l->head, n);
79 }
80
81 static inline void notifier_call(struct notifier_list *l, int cmd)
82 {
83 struct notifier_block *n;
84
85 frr_each_safe (notifier_list, &l->head, n)
86 n->action(n, cmd);
87 }
88
89 static inline int notifier_active(struct notifier_list *l)
90 {
91 return notifier_list_count(&l->head) > 0;
92 }
93
94 extern struct hash *nhrp_gre_list;
95
96 void nhrp_zebra_init(void);
97 void nhrp_zebra_terminate(void);
98 void nhrp_send_zebra_configure_arp(struct interface *ifp, int family);
99 void nhrp_send_zebra_nbr(union sockunion *in,
100 union sockunion *out,
101 struct interface *ifp);
102
103 void nhrp_send_zebra_gre_source_set(struct interface *ifp,
104 unsigned int link_idx,
105 vrf_id_t link_vrf_id);
106
107 extern int nhrp_send_zebra_gre_request(struct interface *ifp);
108 extern struct nhrp_gre_info *nhrp_gre_info_alloc(struct nhrp_gre_info *p);
109
110 struct zbuf;
111 struct nhrp_vc;
112 struct nhrp_cache;
113 struct nhrp_nhs;
114 struct nhrp_interface;
115
116 #define MAX_ID_LENGTH 64
117 #define MAX_CERT_LENGTH 2048
118
119 enum nhrp_notify_type {
120 NOTIFY_INTERFACE_UP,
121 NOTIFY_INTERFACE_DOWN,
122 NOTIFY_INTERFACE_CHANGED,
123 NOTIFY_INTERFACE_ADDRESS_CHANGED,
124 NOTIFY_INTERFACE_NBMA_CHANGED,
125 NOTIFY_INTERFACE_MTU_CHANGED,
126 NOTIFY_INTERFACE_IPSEC_CHANGED,
127
128 NOTIFY_VC_IPSEC_CHANGED,
129 NOTIFY_VC_IPSEC_UPDATE_NBMA,
130
131 NOTIFY_PEER_UP,
132 NOTIFY_PEER_DOWN,
133 NOTIFY_PEER_IFCONFIG_CHANGED,
134 NOTIFY_PEER_MTU_CHANGED,
135 NOTIFY_PEER_NBMA_CHANGING,
136
137 NOTIFY_CACHE_UP,
138 NOTIFY_CACHE_DOWN,
139 NOTIFY_CACHE_DELETE,
140 NOTIFY_CACHE_USED,
141 NOTIFY_CACHE_BINDING_CHANGE,
142 };
143
144 struct nhrp_vc {
145 struct notifier_list notifier_list;
146 uint32_t ipsec;
147 uint32_t ike_uniqueid;
148 uint8_t updating;
149 uint8_t abort_migration;
150
151 struct nhrp_vc_peer {
152 union sockunion nbma;
153 char id[MAX_ID_LENGTH];
154 uint16_t certlen;
155 uint8_t cert[MAX_CERT_LENGTH];
156 } local, remote;
157 };
158
159 enum nhrp_route_type {
160 NHRP_ROUTE_BLACKHOLE,
161 NHRP_ROUTE_LOCAL,
162 NHRP_ROUTE_NBMA_NEXTHOP,
163 NHRP_ROUTE_OFF_NBMA,
164 };
165
166 struct nhrp_peer {
167 unsigned int ref;
168 unsigned online : 1;
169 unsigned requested : 1;
170 unsigned fallback_requested : 1;
171 unsigned prio : 1;
172 struct notifier_list notifier_list;
173 struct interface *ifp;
174 struct nhrp_vc *vc;
175 struct thread *t_fallback;
176 struct notifier_block vc_notifier, ifp_notifier;
177 struct thread *t_timer;
178 };
179
180 struct nhrp_packet_parser {
181 struct interface *ifp;
182 struct nhrp_afi_data *if_ad;
183 struct nhrp_peer *peer;
184 struct zbuf *pkt;
185 struct zbuf payload;
186 struct zbuf extensions;
187 struct nhrp_packet_header *hdr;
188 enum nhrp_route_type route_type;
189 struct prefix route_prefix;
190 union sockunion src_nbma, src_proto, dst_proto;
191 };
192
193 struct nhrp_reqid_pool {
194 struct hash *reqid_hash;
195 uint32_t next_request_id;
196 };
197
198 struct nhrp_reqid {
199 uint32_t request_id;
200 void (*cb)(struct nhrp_reqid *, void *);
201 };
202
203 extern struct nhrp_reqid_pool nhrp_packet_reqid;
204 extern struct nhrp_reqid_pool nhrp_event_reqid;
205
206 enum nhrp_cache_type {
207 NHRP_CACHE_INVALID = 0,
208 NHRP_CACHE_INCOMPLETE,
209 NHRP_CACHE_NEGATIVE,
210 NHRP_CACHE_CACHED,
211 NHRP_CACHE_DYNAMIC,
212 NHRP_CACHE_NHS,
213 NHRP_CACHE_STATIC,
214 NHRP_CACHE_LOCAL,
215 NHRP_CACHE_NUM_TYPES
216 };
217
218 extern const char *const nhrp_cache_type_str[];
219 extern unsigned long nhrp_cache_counts[NHRP_CACHE_NUM_TYPES];
220
221 struct nhrp_cache_config {
222 struct interface *ifp;
223 union sockunion remote_addr;
224 enum nhrp_cache_type type;
225 union sockunion nbma;
226 };
227
228 struct nhrp_cache {
229 struct interface *ifp;
230 union sockunion remote_addr;
231
232 unsigned map : 1;
233 unsigned used : 1;
234 unsigned route_installed : 1;
235 unsigned nhrp_route_installed : 1;
236
237 struct notifier_block peer_notifier;
238 struct notifier_block newpeer_notifier;
239 struct notifier_list notifier_list;
240 struct nhrp_reqid eventid;
241 struct thread *t_timeout;
242 struct thread *t_auth;
243
244 struct {
245 enum nhrp_cache_type type;
246 union sockunion remote_nbma_natoa;
247 union sockunion remote_nbma_claimed;
248 struct nhrp_peer *peer;
249 time_t expires;
250 uint32_t mtu;
251 int holding_time;
252 } cur, new;
253 };
254
255 struct nhrp_shortcut {
256 struct prefix *p;
257 union sockunion addr;
258
259 struct nhrp_reqid reqid;
260 struct thread *t_timer;
261
262 enum nhrp_cache_type type;
263 unsigned int holding_time;
264 unsigned route_installed : 1;
265 unsigned expiring : 1;
266
267 struct nhrp_cache *cache;
268 struct notifier_block cache_notifier;
269 };
270
271 PREDECL_DLIST(nhrp_nhslist);
272 PREDECL_DLIST(nhrp_mcastlist);
273 PREDECL_DLIST(nhrp_reglist);
274
275 struct nhrp_nhs {
276 struct interface *ifp;
277 struct nhrp_nhslist_item nhslist_entry;
278
279 unsigned hub : 1;
280 afi_t afi;
281 union sockunion proto_addr;
282 const char *nbma_fqdn; /* IP-address or FQDN */
283
284 struct thread *t_resolve;
285 struct resolver_query dns_resolve;
286 struct nhrp_reglist_head reglist_head;
287 };
288
289 DECLARE_DLIST(nhrp_nhslist, struct nhrp_nhs, nhslist_entry);
290
291 struct nhrp_multicast {
292 struct interface *ifp;
293 struct nhrp_mcastlist_item mcastlist_entry;
294 afi_t afi;
295 union sockunion nbma_addr; /* IP-address */
296 };
297
298 DECLARE_DLIST(nhrp_mcastlist, struct nhrp_multicast, mcastlist_entry);
299
300 struct nhrp_registration {
301 struct nhrp_reglist_item reglist_entry;
302 struct thread *t_register;
303 struct nhrp_nhs *nhs;
304 struct nhrp_reqid reqid;
305 unsigned int timeout;
306 unsigned mark : 1;
307 union sockunion proto_addr;
308 struct nhrp_peer *peer;
309 struct notifier_block peer_notifier;
310 };
311
312 DECLARE_DLIST(nhrp_reglist, struct nhrp_registration, reglist_entry);
313
314 #define NHRP_IFF_SHORTCUT 0x0001
315 #define NHRP_IFF_REDIRECT 0x0002
316 #define NHRP_IFF_REG_NO_UNIQUE 0x0100
317
318 struct nhrp_interface {
319 struct interface *ifp;
320
321 unsigned enabled : 1;
322
323 char *ipsec_profile, *ipsec_fallback_profile, *source;
324 union sockunion nbma;
325 union sockunion nat_nbma;
326 unsigned int link_idx;
327 unsigned int link_vrf_id;
328 uint32_t i_grekey;
329 uint32_t o_grekey;
330
331 struct hash *peer_hash;
332 struct hash *cache_config_hash;
333 struct hash *cache_hash;
334
335 struct notifier_list notifier_list;
336
337 struct interface *nbmaifp;
338 struct notifier_block nbmanifp_notifier;
339
340 struct nhrp_afi_data {
341 unsigned flags;
342 unsigned short configured : 1;
343 union sockunion addr;
344 uint32_t network_id;
345 short configured_mtu;
346 unsigned short mtu;
347 unsigned int holdtime;
348 struct nhrp_nhslist_head nhslist_head;
349 struct nhrp_mcastlist_head mcastlist_head;
350 } afi[AFI_MAX];
351 };
352
353 struct nhrp_gre_info {
354 ifindex_t ifindex;
355 struct in_addr vtep_ip; /* IFLA_GRE_LOCAL */
356 struct in_addr vtep_ip_remote; /* IFLA_GRE_REMOTE */
357 uint32_t ikey;
358 uint32_t okey;
359 ifindex_t ifindex_link; /* Interface index of interface
360 * linked with GRE
361 */
362 vrf_id_t vrfid_link;
363 };
364
365 extern struct zebra_privs_t nhrpd_privs;
366
367 int sock_open_unix(const char *path);
368
369 void nhrp_interface_init(void);
370 void nhrp_interface_update(struct interface *ifp);
371 void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi);
372 void nhrp_interface_update_nbma(struct interface *ifp,
373 struct nhrp_gre_info *gre_info);
374
375 int nhrp_interface_add(ZAPI_CALLBACK_ARGS);
376 int nhrp_interface_delete(ZAPI_CALLBACK_ARGS);
377 int nhrp_interface_up(ZAPI_CALLBACK_ARGS);
378 int nhrp_interface_down(ZAPI_CALLBACK_ARGS);
379 int nhrp_interface_address_add(ZAPI_CALLBACK_ARGS);
380 int nhrp_interface_address_delete(ZAPI_CALLBACK_ARGS);
381 void nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS);
382 void nhrp_gre_update(ZAPI_CALLBACK_ARGS);
383
384 void nhrp_interface_notify_add(struct interface *ifp, struct notifier_block *n,
385 notifier_fn_t fn);
386 void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n);
387 void nhrp_interface_set_protection(struct interface *ifp, const char *profile,
388 const char *fallback_profile);
389 void nhrp_interface_set_source(struct interface *ifp, const char *ifname);
390 extern int nhrp_ifp_create(struct interface *ifp);
391 extern int nhrp_ifp_up(struct interface *ifp);
392 extern int nhrp_ifp_down(struct interface *ifp);
393 extern int nhrp_ifp_destroy(struct interface *ifp);
394
395 int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr,
396 const char *nbma_fqdn);
397 int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr,
398 const char *nbma_fqdn);
399 int nhrp_nhs_free(struct nhrp_interface *nifp, afi_t afi, struct nhrp_nhs *nhs);
400 void nhrp_nhs_terminate(void);
401 void nhrp_nhs_foreach(struct interface *ifp, afi_t afi,
402 void (*cb)(struct nhrp_nhs *, struct nhrp_registration *,
403 void *),
404 void *ctx);
405 void nhrp_nhs_interface_del(struct interface *ifp);
406
407 int nhrp_multicast_add(struct interface *ifp, afi_t afi,
408 union sockunion *nbma_addr);
409 int nhrp_multicast_del(struct interface *ifp, afi_t afi,
410 union sockunion *nbma_addr);
411 void nhrp_multicast_interface_del(struct interface *ifp);
412 void nhrp_multicast_foreach(struct interface *ifp, afi_t afi,
413 void (*cb)(struct nhrp_multicast *, void *),
414 void *ctx);
415 void netlink_mcast_set_nflog_group(int nlgroup);
416
417 void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp);
418 void nhrp_route_announce(int add, enum nhrp_cache_type type,
419 const struct prefix *p, struct interface *ifp,
420 const union sockunion *nexthop, uint32_t mtu);
421 int nhrp_route_read(ZAPI_CALLBACK_ARGS);
422 int nhrp_route_get_nexthop(const union sockunion *addr, struct prefix *p,
423 union sockunion *via, struct interface **ifp);
424 enum nhrp_route_type nhrp_route_address(struct interface *in_ifp,
425 union sockunion *addr, struct prefix *p,
426 struct nhrp_peer **peer);
427
428 void nhrp_config_init(void);
429
430 void nhrp_shortcut_init(void);
431 void nhrp_shortcut_terminate(void);
432 void nhrp_shortcut_initiate(union sockunion *addr);
433 void nhrp_shortcut_foreach(afi_t afi,
434 void (*cb)(struct nhrp_shortcut *, void *),
435 void *ctx);
436 void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force);
437 void nhrp_shortcut_prefix_change(const struct prefix *p, int deleted);
438
439 void nhrp_cache_interface_del(struct interface *ifp);
440 void nhrp_cache_config_free(struct nhrp_cache_config *c);
441 struct nhrp_cache_config *nhrp_cache_config_get(struct interface *ifp,
442 union sockunion *remote_addr,
443 int create);
444 struct nhrp_cache *nhrp_cache_get(struct interface *ifp,
445 union sockunion *remote_addr, int create);
446 void nhrp_cache_foreach(struct interface *ifp,
447 void (*cb)(struct nhrp_cache *, void *), void *ctx);
448 void nhrp_cache_config_foreach(struct interface *ifp,
449 void (*cb)(struct nhrp_cache_config *, void *), void *ctx);
450 void nhrp_cache_set_used(struct nhrp_cache *, int);
451 int nhrp_cache_update_binding(struct nhrp_cache *, enum nhrp_cache_type type,
452 int holding_time, struct nhrp_peer *p,
453 uint32_t mtu, union sockunion *nbma_natoa,
454 union sockunion *claimed_nbma);
455 void nhrp_cache_notify_add(struct nhrp_cache *c, struct notifier_block *,
456 notifier_fn_t);
457 void nhrp_cache_notify_del(struct nhrp_cache *c, struct notifier_block *);
458
459 void nhrp_vc_init(void);
460 void nhrp_vc_terminate(void);
461 struct nhrp_vc *nhrp_vc_get(const union sockunion *src,
462 const union sockunion *dst, int create);
463 int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc);
464 void nhrp_vc_notify_add(struct nhrp_vc *, struct notifier_block *,
465 notifier_fn_t);
466 void nhrp_vc_notify_del(struct nhrp_vc *, struct notifier_block *);
467 void nhrp_vc_foreach(void (*cb)(struct nhrp_vc *, void *), void *ctx);
468 void nhrp_vc_reset(void);
469
470 void vici_init(void);
471 void vici_terminate(void);
472 void vici_terminate_vc_by_profile_name(char *profile_name);
473 void vici_terminate_vc_by_ike_id(unsigned int ike_id);
474 void vici_request_vc(const char *profile, union sockunion *src,
475 union sockunion *dst, int prio);
476
477 extern const char *nhrp_event_socket_path;
478
479 void evmgr_init(void);
480 void evmgr_terminate(void);
481 void evmgr_set_socket(const char *socket);
482 void evmgr_notify(const char *name, struct nhrp_cache *c,
483 void (*cb)(struct nhrp_reqid *, void *));
484
485 struct nhrp_packet_header *nhrp_packet_push(struct zbuf *zb, uint8_t type,
486 const union sockunion *src_nbma,
487 const union sockunion *src_proto,
488 const union sockunion *dst_proto);
489 void nhrp_packet_complete(struct zbuf *zb, struct nhrp_packet_header *hdr);
490 uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu, uint16_t len);
491
492 struct nhrp_packet_header *nhrp_packet_pull(struct zbuf *zb,
493 union sockunion *src_nbma,
494 union sockunion *src_proto,
495 union sockunion *dst_proto);
496
497 struct nhrp_cie_header *nhrp_cie_push(struct zbuf *zb, uint8_t code,
498 const union sockunion *nbma,
499 const union sockunion *proto);
500 struct nhrp_cie_header *nhrp_cie_pull(struct zbuf *zb,
501 struct nhrp_packet_header *hdr,
502 union sockunion *nbma,
503 union sockunion *proto);
504
505 struct nhrp_extension_header *
506 nhrp_ext_push(struct zbuf *zb, struct nhrp_packet_header *hdr, uint16_t type);
507 void nhrp_ext_complete(struct zbuf *zb, struct nhrp_extension_header *ext);
508 struct nhrp_extension_header *nhrp_ext_pull(struct zbuf *zb,
509 struct zbuf *payload);
510 void nhrp_ext_request(struct zbuf *zb, struct nhrp_packet_header *hdr,
511 struct interface *);
512 int nhrp_ext_reply(struct zbuf *zb, struct nhrp_packet_header *hdr,
513 struct interface *ifp, struct nhrp_extension_header *ext,
514 struct zbuf *extpayload);
515
516 uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *, struct nhrp_reqid *r,
517 void (*cb)(struct nhrp_reqid *, void *));
518 void nhrp_reqid_free(struct nhrp_reqid_pool *, struct nhrp_reqid *r);
519 struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *, uint32_t reqid);
520
521 int nhrp_packet_init(void);
522
523 void nhrp_peer_interface_del(struct interface *ifp);
524 struct nhrp_peer *nhrp_peer_get(struct interface *ifp,
525 const union sockunion *remote_nbma);
526 struct nhrp_peer *nhrp_peer_ref(struct nhrp_peer *p);
527 void nhrp_peer_unref(struct nhrp_peer *p);
528 int nhrp_peer_check(struct nhrp_peer *p, int establish);
529 void nhrp_peer_notify_add(struct nhrp_peer *p, struct notifier_block *,
530 notifier_fn_t);
531 void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *);
532 void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb);
533 void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb);
534 void nhrp_peer_send_indication(struct interface *ifp, uint16_t, struct zbuf *);
535
536 int nhrp_nhs_match_ip(union sockunion *in_ip, struct nhrp_interface *nifp);
537
538 #endif