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