]> git.proxmox.com Git - mirror_frr.git/blame - nhrpd/nhrpd.h
tools: enable stylechecker to handle new files
[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
DL
18#include "memory.h"
19
20DECLARE_MGROUP(NHRPD)
2fb975da
TT
21
22#define NHRPD_DEFAULT_HOLDTIME 7200
23
442deed8 24#define NHRP_VTY_PORT 2610
2fb975da
TT
25#define NHRP_DEFAULT_CONFIG "nhrpd.conf"
26
27extern struct thread_master *master;
28
29enum {
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,
6c8ca260 38 __NHRP_ERR_MAX
2fb975da 39};
6c8ca260 40#define NHRP_ERR_MAX (__NHRP_ERR_MAX - 1)
2fb975da
TT
41
42struct notifier_block;
43
44typedef void (*notifier_fn_t)(struct notifier_block *, unsigned long);
45
46struct notifier_block {
47 struct list_head notifier_entry;
48 notifier_fn_t action;
49};
50
51struct 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
58static inline void notifier_init(struct notifier_list *l)
59{
60 list_init(&l->notifier_head);
61}
62
63static 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
69static inline void notifier_del(struct notifier_block *n)
70{
71 list_del(&n->notifier_entry);
72}
73
74static 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
81static inline int notifier_active(struct notifier_list *l)
82{
83 return !list_empty(&l->notifier_head);
84}
85
86struct resolver_query {
87 void (*callback)(struct resolver_query *, int n, union sockunion *);
88};
89
90void resolver_init(void);
91void resolver_resolve(struct resolver_query *query, int af, const char *hostname, void (*cb)(struct resolver_query *, int, union sockunion *));
92
93void nhrp_zebra_init(void);
94void nhrp_zebra_terminate(void);
95
96struct zbuf;
97struct nhrp_vc;
98struct nhrp_cache;
99struct nhrp_nhs;
100struct nhrp_interface;
101
102#define MAX_ID_LENGTH 64
103#define MAX_CERT_LENGTH 2048
104
105enum 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
129struct 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
143enum nhrp_route_type {
144 NHRP_ROUTE_BLACKHOLE,
145 NHRP_ROUTE_LOCAL,
146 NHRP_ROUTE_NBMA_NEXTHOP,
147 NHRP_ROUTE_OFF_NBMA,
148};
149
150struct 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
163struct 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
176struct nhrp_reqid_pool {
177 struct hash *reqid_hash;
178 uint32_t next_request_id;
179};
180
181struct nhrp_reqid {
182 uint32_t request_id;
183 void (*cb)(struct nhrp_reqid *, void *);
184};
185
186extern struct nhrp_reqid_pool nhrp_packet_reqid;
187extern struct nhrp_reqid_pool nhrp_event_reqid;
188
189enum 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
201extern const char * const nhrp_cache_type_str[];
202extern unsigned long nhrp_cache_counts[NHRP_CACHE_NUM_TYPES];
203
204struct 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
229struct 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
245struct 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
0ca036b4
TT
259struct 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
2fb975da
TT
271#define NHRP_IFF_SHORTCUT 0x0001
272#define NHRP_IFF_REDIRECT 0x0002
273#define NHRP_IFF_REG_NO_UNIQUE 0x0100
274
275struct 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
26efbc7b
DS
306extern struct zebra_privs_t nhrpd_privs;
307
2fb975da
TT
308int sock_open_unix(const char *path);
309
310void nhrp_interface_init(void);
311void nhrp_interface_update(struct interface *ifp);
312void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi);
313
314int nhrp_interface_add(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
315int nhrp_interface_delete(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
316int nhrp_interface_up(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
317int nhrp_interface_down(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
318int nhrp_interface_address_add(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
319int nhrp_interface_address_delete(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
320
321void nhrp_interface_notify_add(struct interface *ifp, struct notifier_block *n, notifier_fn_t fn);
322void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n);
323void nhrp_interface_set_protection(struct interface *ifp, const char *profile, const char *fallback_profile);
324void nhrp_interface_set_source(struct interface *ifp, const char *ifname);
325
326int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, const char *nbma_fqdn);
327int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr, const char *nbma_fqdn);
328int nhrp_nhs_free(struct nhrp_nhs *nhs);
329void nhrp_nhs_terminate(void);
0ca036b4 330void nhrp_nhs_foreach(struct interface *ifp, afi_t afi, void (*cb)(struct nhrp_nhs *, struct nhrp_registration *, void *), void *ctx);
2fb975da
TT
331
332void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp);
333void nhrp_route_announce(int add, enum nhrp_cache_type type, const struct prefix *p, struct interface *ifp, const union sockunion *nexthop, uint32_t mtu);
334int nhrp_route_read(int command, struct zclient *zclient, zebra_size_t length, vrf_id_t vrf_id);
335int nhrp_route_get_nexthop(const union sockunion *addr, struct prefix *p, union sockunion *via, struct interface **ifp);
336enum nhrp_route_type nhrp_route_address(struct interface *in_ifp, union sockunion *addr, struct prefix *p, struct nhrp_peer **peer);
337
338void nhrp_config_init(void);
339
340void nhrp_shortcut_init(void);
341void nhrp_shortcut_terminate(void);
342void nhrp_shortcut_initiate(union sockunion *addr);
343void nhrp_shortcut_foreach(afi_t afi, void (*cb)(struct nhrp_shortcut *, void *), void *ctx);
344void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force);
345void nhrp_shortcut_prefix_change(const struct prefix *p, int deleted);
346
347struct nhrp_cache *nhrp_cache_get(struct interface *ifp, union sockunion *remote_addr, int create);
348void nhrp_cache_foreach(struct interface *ifp, void (*cb)(struct nhrp_cache *, void *), void *ctx);
349void nhrp_cache_set_used(struct nhrp_cache *, int);
350int 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);
351void nhrp_cache_notify_add(struct nhrp_cache *c, struct notifier_block *, notifier_fn_t);
352void nhrp_cache_notify_del(struct nhrp_cache *c, struct notifier_block *);
353
354void nhrp_vc_init(void);
355void nhrp_vc_terminate(void);
356struct nhrp_vc *nhrp_vc_get(const union sockunion *src, const union sockunion *dst, int create);
357int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc);
358void nhrp_vc_notify_add(struct nhrp_vc *, struct notifier_block *, notifier_fn_t);
359void nhrp_vc_notify_del(struct nhrp_vc *, struct notifier_block *);
360void nhrp_vc_foreach(void (*cb)(struct nhrp_vc *, void *), void *ctx);
361void nhrp_vc_reset(void);
362
363void vici_init(void);
364void vici_terminate(void);
365void vici_request_vc(const char *profile, union sockunion *src, union sockunion *dst, int prio);
366
367extern const char *nhrp_event_socket_path;
368
369void evmgr_init(void);
370void evmgr_terminate(void);
371void evmgr_set_socket(const char *socket);
372void evmgr_notify(const char *name, struct nhrp_cache *c, void (*cb)(struct nhrp_reqid *, void *));
373
374struct 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);
379void nhrp_packet_complete(struct zbuf *zb, struct nhrp_packet_header *hdr);
380uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu, uint16_t len);
381
382struct 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
388struct nhrp_cie_header *nhrp_cie_push(
389 struct zbuf *zb, uint8_t code,
390 const union sockunion *nbma,
391 const union sockunion *proto);
392struct 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
398struct nhrp_extension_header *nhrp_ext_push(struct zbuf *zb, struct nhrp_packet_header *hdr, uint16_t type);
399void nhrp_ext_complete(struct zbuf *zb, struct nhrp_extension_header *ext);
400struct nhrp_extension_header *nhrp_ext_pull(struct zbuf *zb, struct zbuf *payload);
401void nhrp_ext_request(struct zbuf *zb, struct nhrp_packet_header *hdr, struct interface *);
402int nhrp_ext_reply(struct zbuf *zb, struct nhrp_packet_header *hdr, struct interface *ifp, struct nhrp_extension_header *ext, struct zbuf *extpayload);
403
404uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *, struct nhrp_reqid *r, void (*cb)(struct nhrp_reqid *, void *));
405void nhrp_reqid_free(struct nhrp_reqid_pool *, struct nhrp_reqid *r);
406struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *, uint32_t reqid);
407
408int nhrp_packet_init(void);
409
410struct nhrp_peer *nhrp_peer_get(struct interface *ifp, const union sockunion *remote_nbma);
411struct nhrp_peer *nhrp_peer_ref(struct nhrp_peer *p);
412void nhrp_peer_unref(struct nhrp_peer *p);
413int nhrp_peer_check(struct nhrp_peer *p, int establish);
414void nhrp_peer_notify_add(struct nhrp_peer *p, struct notifier_block *, notifier_fn_t);
415void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *);
416void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb);
417void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb);
418void nhrp_peer_send_indication(struct interface *ifp, uint16_t, struct zbuf *);
419
420#endif