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