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