]> git.proxmox.com Git - mirror_frr.git/blame - nhrpd/nhrpd.h
nhrpd: convert mcast list to DLIST
[mirror_frr.git] / nhrpd / nhrpd.h
CommitLineData
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 20
bf8d3d6a 21DECLARE_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
28extern struct thread_master *master;
29
996c9314
LB
30enum { 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
41struct notifier_block;
42
43typedef void (*notifier_fn_t)(struct notifier_block *, unsigned long);
44
865bf787
DL
45PREDECL_DLIST(notifier_list);
46
2fb975da 47struct notifier_block {
865bf787 48 struct notifier_list_item notifier_entry;
2fb975da
TT
49 notifier_fn_t action;
50};
51
865bf787
DL
52DECLARE_DLIST(notifier_list, struct notifier_block, notifier_entry);
53
2fb975da 54struct notifier_list {
865bf787 55 struct notifier_list_head head;
2fb975da
TT
56};
57
996c9314
LB
58#define NOTIFIER_LIST_INITIALIZER(l) \
59 { \
865bf787 60 .head = INIT_DLIST((l)->head) \
996c9314 61 }
2fb975da
TT
62
63static inline void notifier_init(struct notifier_list *l)
64{
865bf787 65 notifier_list_init(&l->head);
2fb975da
TT
66}
67
996c9314
LB
68static inline void notifier_add(struct notifier_block *n,
69 struct notifier_list *l, notifier_fn_t action)
2fb975da
TT
70{
71 n->action = action;
865bf787 72 notifier_list_add_tail(&l->head, n);
2fb975da
TT
73}
74
865bf787
DL
75static inline void notifier_del(struct notifier_block *n,
76 struct notifier_list *l)
2fb975da 77{
865bf787 78 notifier_list_del(&l->head, n);
2fb975da
TT
79}
80
81static inline void notifier_call(struct notifier_list *l, int cmd)
82{
865bf787
DL
83 struct notifier_block *n;
84
85 frr_each_safe (notifier_list, &l->head, n)
123ea351 86 n->action(n, cmd);
2fb975da
TT
87}
88
89static inline int notifier_active(struct notifier_list *l)
90{
865bf787 91 return notifier_list_count(&l->head) > 0;
2fb975da
TT
92}
93
7f48cfa5
PG
94extern struct hash *nhrp_gre_list;
95
2fb975da
TT
96void nhrp_zebra_init(void);
97void nhrp_zebra_terminate(void);
f468a45a 98void nhrp_send_zebra_configure_arp(struct interface *ifp, int family);
05657ec2
PG
99void nhrp_send_zebra_nbr(union sockunion *in,
100 union sockunion *out,
101 struct interface *ifp);
7f48cfa5
PG
102
103void nhrp_send_zebra_gre_source_set(struct interface *ifp,
104 unsigned int link_idx,
105 vrf_id_t link_vrf_id);
106
107extern int nhrp_send_zebra_gre_request(struct interface *ifp);
108extern struct nhrp_gre_info *nhrp_gre_info_alloc(struct nhrp_gre_info *p);
109
2fb975da
TT
110struct zbuf;
111struct nhrp_vc;
112struct nhrp_cache;
113struct nhrp_nhs;
114struct nhrp_interface;
115
116#define MAX_ID_LENGTH 64
117#define MAX_CERT_LENGTH 2048
118
119enum 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,
58ef1668 126 NOTIFY_INTERFACE_IPSEC_CHANGED,
2fb975da
TT
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
144struct nhrp_vc {
145 struct notifier_list notifier_list;
6cfd90f3 146 uint32_t ipsec;
4cbaf956 147 uint32_t ike_uniqueid;
2fb975da
TT
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
159enum nhrp_route_type {
160 NHRP_ROUTE_BLACKHOLE,
161 NHRP_ROUTE_LOCAL,
162 NHRP_ROUTE_NBMA_NEXTHOP,
163 NHRP_ROUTE_OFF_NBMA,
164};
165
166struct 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;
bb58f442 177 struct thread *t_timer;
2fb975da
TT
178};
179
180struct 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
193struct nhrp_reqid_pool {
194 struct hash *reqid_hash;
195 uint32_t next_request_id;
196};
197
198struct nhrp_reqid {
199 uint32_t request_id;
200 void (*cb)(struct nhrp_reqid *, void *);
201};
202
203extern struct nhrp_reqid_pool nhrp_packet_reqid;
204extern struct nhrp_reqid_pool nhrp_event_reqid;
205
206enum 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
996c9314 218extern const char *const nhrp_cache_type_str[];
2fb975da
TT
219extern unsigned long nhrp_cache_counts[NHRP_CACHE_NUM_TYPES];
220
fef2ed13
PG
221struct nhrp_cache_config {
222 struct interface *ifp;
223 union sockunion remote_addr;
224 enum nhrp_cache_type type;
225 union sockunion nbma;
226};
227
2fb975da
TT
228struct 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;
85365e51 247 union sockunion remote_nbma_claimed;
2fb975da
TT
248 struct nhrp_peer *peer;
249 time_t expires;
250 uint32_t mtu;
bb58f442 251 int holding_time;
2fb975da
TT
252 } cur, new;
253};
254
255struct 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
2ab2a761 271PREDECL_DLIST(nhrp_nhslist);
db4db2bb 272PREDECL_DLIST(nhrp_mcastlist);
2ab2a761 273
2fb975da
TT
274struct nhrp_nhs {
275 struct interface *ifp;
2ab2a761 276 struct nhrp_nhslist_item nhslist_entry;
2fb975da
TT
277
278 unsigned hub : 1;
279 afi_t afi;
280 union sockunion proto_addr;
996c9314 281 const char *nbma_fqdn; /* IP-address or FQDN */
2fb975da
TT
282
283 struct thread *t_resolve;
284 struct resolver_query dns_resolve;
285 struct list_head reglist_head;
286};
287
2ab2a761
DL
288DECLARE_DLIST(nhrp_nhslist, struct nhrp_nhs, nhslist_entry);
289
fa31fcf2
AL
290struct nhrp_multicast {
291 struct interface *ifp;
db4db2bb 292 struct nhrp_mcastlist_item mcastlist_entry;
fa31fcf2
AL
293 afi_t afi;
294 union sockunion nbma_addr; /* IP-address */
295};
296
db4db2bb
DL
297DECLARE_DLIST(nhrp_mcastlist, struct nhrp_multicast, mcastlist_entry);
298
0ca036b4
TT
299struct nhrp_registration {
300 struct list_head reglist_entry;
301 struct thread *t_register;
302 struct nhrp_nhs *nhs;
303 struct nhrp_reqid reqid;
304 unsigned int timeout;
305 unsigned mark : 1;
306 union sockunion proto_addr;
307 struct nhrp_peer *peer;
308 struct notifier_block peer_notifier;
309};
310
2fb975da
TT
311#define NHRP_IFF_SHORTCUT 0x0001
312#define NHRP_IFF_REDIRECT 0x0002
313#define NHRP_IFF_REG_NO_UNIQUE 0x0100
314
315struct nhrp_interface {
316 struct interface *ifp;
317
318 unsigned enabled : 1;
319
320 char *ipsec_profile, *ipsec_fallback_profile, *source;
321 union sockunion nbma;
322 union sockunion nat_nbma;
7f48cfa5
PG
323 unsigned int link_idx;
324 unsigned int link_vrf_id;
325 uint32_t i_grekey;
326 uint32_t o_grekey;
2fb975da
TT
327
328 struct hash *peer_hash;
fef2ed13 329 struct hash *cache_config_hash;
2fb975da
TT
330 struct hash *cache_hash;
331
332 struct notifier_list notifier_list;
333
334 struct interface *nbmaifp;
335 struct notifier_block nbmanifp_notifier;
336
337 struct nhrp_afi_data {
338 unsigned flags;
339 unsigned short configured : 1;
340 union sockunion addr;
341 uint32_t network_id;
342 short configured_mtu;
343 unsigned short mtu;
344 unsigned int holdtime;
2ab2a761 345 struct nhrp_nhslist_head nhslist_head;
db4db2bb 346 struct nhrp_mcastlist_head mcastlist_head;
2fb975da
TT
347 } afi[AFI_MAX];
348};
349
7f48cfa5
PG
350struct nhrp_gre_info {
351 ifindex_t ifindex;
352 struct in_addr vtep_ip; /* IFLA_GRE_LOCAL */
353 struct in_addr vtep_ip_remote; /* IFLA_GRE_REMOTE */
354 uint32_t ikey;
355 uint32_t okey;
356 ifindex_t ifindex_link; /* Interface index of interface
357 * linked with GRE
358 */
359 vrf_id_t vrfid_link;
360};
361
26efbc7b
DS
362extern struct zebra_privs_t nhrpd_privs;
363
2fb975da
TT
364int sock_open_unix(const char *path);
365
366void nhrp_interface_init(void);
367void nhrp_interface_update(struct interface *ifp);
368void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi);
7f48cfa5
PG
369void nhrp_interface_update_nbma(struct interface *ifp,
370 struct nhrp_gre_info *gre_info);
2fb975da 371
121f9dee
QY
372int nhrp_interface_add(ZAPI_CALLBACK_ARGS);
373int nhrp_interface_delete(ZAPI_CALLBACK_ARGS);
374int nhrp_interface_up(ZAPI_CALLBACK_ARGS);
375int nhrp_interface_down(ZAPI_CALLBACK_ARGS);
376int nhrp_interface_address_add(ZAPI_CALLBACK_ARGS);
377int nhrp_interface_address_delete(ZAPI_CALLBACK_ARGS);
b3b75104 378void nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS);
7f48cfa5 379void nhrp_gre_update(ZAPI_CALLBACK_ARGS);
996c9314
LB
380
381void nhrp_interface_notify_add(struct interface *ifp, struct notifier_block *n,
382 notifier_fn_t fn);
2fb975da 383void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n);
996c9314
LB
384void nhrp_interface_set_protection(struct interface *ifp, const char *profile,
385 const char *fallback_profile);
2fb975da 386void nhrp_interface_set_source(struct interface *ifp, const char *ifname);
138c5a74
DS
387extern int nhrp_ifp_create(struct interface *ifp);
388extern int nhrp_ifp_up(struct interface *ifp);
389extern int nhrp_ifp_down(struct interface *ifp);
390extern int nhrp_ifp_destroy(struct interface *ifp);
2fb975da 391
996c9314
LB
392int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr,
393 const char *nbma_fqdn);
394int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr,
395 const char *nbma_fqdn);
2ab2a761 396int nhrp_nhs_free(struct nhrp_interface *nifp, afi_t afi, struct nhrp_nhs *nhs);
2fb975da 397void nhrp_nhs_terminate(void);
996c9314
LB
398void nhrp_nhs_foreach(struct interface *ifp, afi_t afi,
399 void (*cb)(struct nhrp_nhs *, struct nhrp_registration *,
400 void *),
401 void *ctx);
ee72f0a0 402void nhrp_nhs_interface_del(struct interface *ifp);
2fb975da 403
0f8595a9
RD
404int nhrp_multicast_add(struct interface *ifp, afi_t afi,
405 union sockunion *nbma_addr);
406int nhrp_multicast_del(struct interface *ifp, afi_t afi,
407 union sockunion *nbma_addr);
fa31fcf2
AL
408void nhrp_multicast_interface_del(struct interface *ifp);
409void nhrp_multicast_foreach(struct interface *ifp, afi_t afi,
0f8595a9
RD
410 void (*cb)(struct nhrp_multicast *, void *),
411 void *ctx);
9084e209 412void netlink_mcast_set_nflog_group(int nlgroup);
fa31fcf2 413
2fb975da 414void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp);
996c9314
LB
415void nhrp_route_announce(int add, enum nhrp_cache_type type,
416 const struct prefix *p, struct interface *ifp,
417 const union sockunion *nexthop, uint32_t mtu);
121f9dee 418int nhrp_route_read(ZAPI_CALLBACK_ARGS);
996c9314
LB
419int nhrp_route_get_nexthop(const union sockunion *addr, struct prefix *p,
420 union sockunion *via, struct interface **ifp);
421enum nhrp_route_type nhrp_route_address(struct interface *in_ifp,
422 union sockunion *addr, struct prefix *p,
423 struct nhrp_peer **peer);
2fb975da
TT
424
425void nhrp_config_init(void);
426
427void nhrp_shortcut_init(void);
428void nhrp_shortcut_terminate(void);
429void nhrp_shortcut_initiate(union sockunion *addr);
996c9314
LB
430void nhrp_shortcut_foreach(afi_t afi,
431 void (*cb)(struct nhrp_shortcut *, void *),
432 void *ctx);
2fb975da
TT
433void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force);
434void nhrp_shortcut_prefix_change(const struct prefix *p, int deleted);
435
ee72f0a0 436void nhrp_cache_interface_del(struct interface *ifp);
fef2ed13
PG
437void nhrp_cache_config_free(struct nhrp_cache_config *c);
438struct nhrp_cache_config *nhrp_cache_config_get(struct interface *ifp,
439 union sockunion *remote_addr,
440 int create);
996c9314
LB
441struct nhrp_cache *nhrp_cache_get(struct interface *ifp,
442 union sockunion *remote_addr, int create);
443void nhrp_cache_foreach(struct interface *ifp,
444 void (*cb)(struct nhrp_cache *, void *), void *ctx);
fef2ed13
PG
445void nhrp_cache_config_foreach(struct interface *ifp,
446 void (*cb)(struct nhrp_cache_config *, void *), void *ctx);
2fb975da 447void nhrp_cache_set_used(struct nhrp_cache *, int);
996c9314
LB
448int nhrp_cache_update_binding(struct nhrp_cache *, enum nhrp_cache_type type,
449 int holding_time, struct nhrp_peer *p,
85365e51
AL
450 uint32_t mtu, union sockunion *nbma_natoa,
451 union sockunion *claimed_nbma);
996c9314
LB
452void nhrp_cache_notify_add(struct nhrp_cache *c, struct notifier_block *,
453 notifier_fn_t);
2fb975da
TT
454void nhrp_cache_notify_del(struct nhrp_cache *c, struct notifier_block *);
455
456void nhrp_vc_init(void);
457void nhrp_vc_terminate(void);
996c9314
LB
458struct nhrp_vc *nhrp_vc_get(const union sockunion *src,
459 const union sockunion *dst, int create);
2fb975da 460int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc);
996c9314
LB
461void nhrp_vc_notify_add(struct nhrp_vc *, struct notifier_block *,
462 notifier_fn_t);
2fb975da
TT
463void nhrp_vc_notify_del(struct nhrp_vc *, struct notifier_block *);
464void nhrp_vc_foreach(void (*cb)(struct nhrp_vc *, void *), void *ctx);
465void nhrp_vc_reset(void);
466
467void vici_init(void);
468void vici_terminate(void);
083bbfae
GG
469void vici_terminate_vc_by_profile_name(char *profile_name);
470void vici_terminate_vc_by_ike_id(unsigned int ike_id);
996c9314
LB
471void vici_request_vc(const char *profile, union sockunion *src,
472 union sockunion *dst, int prio);
2fb975da
TT
473
474extern const char *nhrp_event_socket_path;
475
476void evmgr_init(void);
477void evmgr_terminate(void);
478void evmgr_set_socket(const char *socket);
996c9314
LB
479void evmgr_notify(const char *name, struct nhrp_cache *c,
480 void (*cb)(struct nhrp_reqid *, void *));
2fb975da 481
996c9314
LB
482struct nhrp_packet_header *nhrp_packet_push(struct zbuf *zb, uint8_t type,
483 const union sockunion *src_nbma,
484 const union sockunion *src_proto,
485 const union sockunion *dst_proto);
2fb975da
TT
486void nhrp_packet_complete(struct zbuf *zb, struct nhrp_packet_header *hdr);
487uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu, uint16_t len);
488
996c9314
LB
489struct nhrp_packet_header *nhrp_packet_pull(struct zbuf *zb,
490 union sockunion *src_nbma,
491 union sockunion *src_proto,
492 union sockunion *dst_proto);
493
494struct nhrp_cie_header *nhrp_cie_push(struct zbuf *zb, uint8_t code,
495 const union sockunion *nbma,
496 const union sockunion *proto);
497struct nhrp_cie_header *nhrp_cie_pull(struct zbuf *zb,
498 struct nhrp_packet_header *hdr,
499 union sockunion *nbma,
500 union sockunion *proto);
501
502struct nhrp_extension_header *
503nhrp_ext_push(struct zbuf *zb, struct nhrp_packet_header *hdr, uint16_t type);
2fb975da 504void nhrp_ext_complete(struct zbuf *zb, struct nhrp_extension_header *ext);
996c9314
LB
505struct nhrp_extension_header *nhrp_ext_pull(struct zbuf *zb,
506 struct zbuf *payload);
507void nhrp_ext_request(struct zbuf *zb, struct nhrp_packet_header *hdr,
508 struct interface *);
509int nhrp_ext_reply(struct zbuf *zb, struct nhrp_packet_header *hdr,
510 struct interface *ifp, struct nhrp_extension_header *ext,
511 struct zbuf *extpayload);
512
513uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *, struct nhrp_reqid *r,
514 void (*cb)(struct nhrp_reqid *, void *));
2fb975da
TT
515void nhrp_reqid_free(struct nhrp_reqid_pool *, struct nhrp_reqid *r);
516struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *, uint32_t reqid);
517
518int nhrp_packet_init(void);
519
ee72f0a0 520void nhrp_peer_interface_del(struct interface *ifp);
996c9314
LB
521struct nhrp_peer *nhrp_peer_get(struct interface *ifp,
522 const union sockunion *remote_nbma);
2fb975da
TT
523struct nhrp_peer *nhrp_peer_ref(struct nhrp_peer *p);
524void nhrp_peer_unref(struct nhrp_peer *p);
525int nhrp_peer_check(struct nhrp_peer *p, int establish);
996c9314
LB
526void nhrp_peer_notify_add(struct nhrp_peer *p, struct notifier_block *,
527 notifier_fn_t);
2fb975da
TT
528void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *);
529void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb);
530void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb);
531void nhrp_peer_send_indication(struct interface *ifp, uint16_t, struct zbuf *);
532
bb58f442
GG
533int nhrp_nhs_match_ip(union sockunion *in_ip, struct nhrp_interface *nifp);
534
2fb975da 535#endif