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