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