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