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