1 /* NHRP daemon internal structures and function prototypes
2 * Copyright (c) 2014-2015 Timo Teräs
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.
19 #define NHRPD_DEFAULT_HOLDTIME 7200
21 #define NHRP_VTY_PORT 2612
22 #define NHRP_DEFAULT_CONFIG "nhrpd.conf"
24 extern struct thread_master *master;
30 NHRP_ERR_UNSUPPORTED_INTERFACE,
31 NHRP_ERR_NHRP_NOT_ENABLED,
32 NHRP_ERR_ENTRY_EXISTS,
33 NHRP_ERR_ENTRY_NOT_FOUND,
34 NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH,
37 struct notifier_block;
39 typedef void (*notifier_fn_t)(struct notifier_block *, unsigned long);
41 struct notifier_block {
42 struct list_head notifier_entry;
46 struct notifier_list {
47 struct list_head notifier_head;
50 #define NOTIFIER_LIST_INITIALIZER(l) \
51 { .notifier_head = LIST_INITIALIZER((l)->notifier_head) }
53 static inline void notifier_init(struct notifier_list *l)
55 list_init(&l->notifier_head);
58 static inline void notifier_add(struct notifier_block *n, struct notifier_list *l, notifier_fn_t action)
61 list_add_tail(&n->notifier_entry, &l->notifier_head);
64 static inline void notifier_del(struct notifier_block *n)
66 list_del(&n->notifier_entry);
69 static inline void notifier_call(struct notifier_list *l, int cmd)
71 struct notifier_block *n, *nn;
72 list_for_each_entry_safe(n, nn, &l->notifier_head, notifier_entry)
76 static inline int notifier_active(struct notifier_list *l)
78 return !list_empty(&l->notifier_head);
81 struct resolver_query {
82 void (*callback)(struct resolver_query *, int n, union sockunion *);
85 void resolver_init(void);
86 void resolver_resolve(struct resolver_query *query, int af, const char *hostname, void (*cb)(struct resolver_query *, int, union sockunion *));
88 void nhrp_zebra_init(void);
89 void nhrp_zebra_terminate(void);
95 struct nhrp_interface;
97 #define MAX_ID_LENGTH 64
98 #define MAX_CERT_LENGTH 2048
100 enum nhrp_notify_type {
102 NOTIFY_INTERFACE_DOWN,
103 NOTIFY_INTERFACE_CHANGED,
104 NOTIFY_INTERFACE_ADDRESS_CHANGED,
105 NOTIFY_INTERFACE_NBMA_CHANGED,
106 NOTIFY_INTERFACE_MTU_CHANGED,
108 NOTIFY_VC_IPSEC_CHANGED,
109 NOTIFY_VC_IPSEC_UPDATE_NBMA,
113 NOTIFY_PEER_IFCONFIG_CHANGED,
114 NOTIFY_PEER_MTU_CHANGED,
115 NOTIFY_PEER_NBMA_CHANGING,
121 NOTIFY_CACHE_BINDING_CHANGE,
125 struct notifier_list notifier_list;
128 uint8_t abort_migration;
130 struct nhrp_vc_peer {
131 union sockunion nbma;
132 char id[MAX_ID_LENGTH];
134 uint8_t cert[MAX_CERT_LENGTH];
138 enum nhrp_route_type {
139 NHRP_ROUTE_BLACKHOLE,
141 NHRP_ROUTE_NBMA_NEXTHOP,
148 unsigned requested : 1;
149 unsigned fallback_requested : 1;
151 struct notifier_list notifier_list;
152 struct interface *ifp;
154 struct thread *t_fallback;
155 struct notifier_block vc_notifier, ifp_notifier;
158 struct nhrp_packet_parser {
159 struct interface *ifp;
160 struct nhrp_afi_data *if_ad;
161 struct nhrp_peer *peer;
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;
171 struct nhrp_reqid_pool {
172 struct hash *reqid_hash;
173 uint32_t next_request_id;
178 void (*cb)(struct nhrp_reqid *, void *);
181 extern struct nhrp_reqid_pool nhrp_packet_reqid;
182 extern struct nhrp_reqid_pool nhrp_event_reqid;
184 enum nhrp_cache_type {
185 NHRP_CACHE_INVALID = 0,
186 NHRP_CACHE_INCOMPLETE,
196 extern const char * const nhrp_cache_type_str[];
197 extern unsigned long nhrp_cache_counts[NHRP_CACHE_NUM_TYPES];
200 struct interface *ifp;
201 union sockunion remote_addr;
205 unsigned route_installed : 1;
206 unsigned nhrp_route_installed : 1;
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;
216 enum nhrp_cache_type type;
217 union sockunion remote_nbma_natoa;
218 struct nhrp_peer *peer;
224 struct nhrp_shortcut {
226 union sockunion addr;
228 struct nhrp_reqid reqid;
229 struct thread *t_timer;
231 enum nhrp_cache_type type;
232 unsigned int holding_time;
233 unsigned route_installed : 1;
234 unsigned expiring : 1;
236 struct nhrp_cache *cache;
237 struct notifier_block cache_notifier;
241 struct interface *ifp;
242 struct list_head nhslist_entry;
246 union sockunion proto_addr;
247 const char *nbma_fqdn; /* IP-address or FQDN */
249 struct thread *t_resolve;
250 struct resolver_query dns_resolve;
251 struct list_head reglist_head;
254 struct 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;
261 union sockunion proto_addr;
262 struct nhrp_peer *peer;
263 struct notifier_block peer_notifier;
266 #define NHRP_IFF_SHORTCUT 0x0001
267 #define NHRP_IFF_REDIRECT 0x0002
268 #define NHRP_IFF_REG_NO_UNIQUE 0x0100
270 struct nhrp_interface {
271 struct interface *ifp;
273 unsigned enabled : 1;
275 char *ipsec_profile, *ipsec_fallback_profile, *source;
276 union sockunion nbma;
277 union sockunion nat_nbma;
278 unsigned int linkidx;
281 struct hash *peer_hash;
282 struct hash *cache_hash;
284 struct notifier_list notifier_list;
286 struct interface *nbmaifp;
287 struct notifier_block nbmanifp_notifier;
289 struct nhrp_afi_data {
291 unsigned short configured : 1;
292 union sockunion addr;
294 short configured_mtu;
296 unsigned int holdtime;
297 struct list_head nhslist_head;
301 int sock_open_unix(const char *path);
303 void nhrp_interface_init(void);
304 void nhrp_interface_update(struct interface *ifp);
305 void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi);
307 int nhrp_interface_add(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
308 int nhrp_interface_delete(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
309 int nhrp_interface_up(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
310 int nhrp_interface_down(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
311 int nhrp_interface_address_add(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
312 int nhrp_interface_address_delete(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
314 void nhrp_interface_notify_add(struct interface *ifp, struct notifier_block *n, notifier_fn_t fn);
315 void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n);
316 void nhrp_interface_set_protection(struct interface *ifp, const char *profile, const char *fallback_profile);
317 void nhrp_interface_set_source(struct interface *ifp, const char *ifname);
319 int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, const char *nbma_fqdn);
320 int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr, const char *nbma_fqdn);
321 int nhrp_nhs_free(struct nhrp_nhs *nhs);
322 void nhrp_nhs_terminate(void);
323 void nhrp_nhs_foreach(struct interface *ifp, afi_t afi, void (*cb)(struct nhrp_nhs *, struct nhrp_registration *, void *), void *ctx);
325 void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp);
326 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);
327 int nhrp_route_read(int command, struct zclient *zclient, zebra_size_t length, vrf_id_t vrf_id);
328 int nhrp_route_get_nexthop(const union sockunion *addr, struct prefix *p, union sockunion *via, struct interface **ifp);
329 enum nhrp_route_type nhrp_route_address(struct interface *in_ifp, union sockunion *addr, struct prefix *p, struct nhrp_peer **peer);
331 void nhrp_config_init(void);
333 void nhrp_shortcut_init(void);
334 void nhrp_shortcut_terminate(void);
335 void nhrp_shortcut_initiate(union sockunion *addr);
336 void nhrp_shortcut_foreach(afi_t afi, void (*cb)(struct nhrp_shortcut *, void *), void *ctx);
337 void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force);
338 void nhrp_shortcut_prefix_change(const struct prefix *p, int deleted);
340 struct nhrp_cache *nhrp_cache_get(struct interface *ifp, union sockunion *remote_addr, int create);
341 void nhrp_cache_foreach(struct interface *ifp, void (*cb)(struct nhrp_cache *, void *), void *ctx);
342 void nhrp_cache_set_used(struct nhrp_cache *, int);
343 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);
344 void nhrp_cache_notify_add(struct nhrp_cache *c, struct notifier_block *, notifier_fn_t);
345 void nhrp_cache_notify_del(struct nhrp_cache *c, struct notifier_block *);
347 void nhrp_vc_init(void);
348 void nhrp_vc_terminate(void);
349 struct nhrp_vc *nhrp_vc_get(const union sockunion *src, const union sockunion *dst, int create);
350 int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc);
351 void nhrp_vc_notify_add(struct nhrp_vc *, struct notifier_block *, notifier_fn_t);
352 void nhrp_vc_notify_del(struct nhrp_vc *, struct notifier_block *);
353 void nhrp_vc_foreach(void (*cb)(struct nhrp_vc *, void *), void *ctx);
354 void nhrp_vc_reset(void);
356 void vici_init(void);
357 void vici_terminate(void);
358 void vici_request_vc(const char *profile, union sockunion *src, union sockunion *dst, int prio);
360 extern const char *nhrp_event_socket_path;
362 void evmgr_init(void);
363 void evmgr_terminate(void);
364 void evmgr_set_socket(const char *socket);
365 void evmgr_notify(const char *name, struct nhrp_cache *c, void (*cb)(struct nhrp_reqid *, void *));
367 struct nhrp_packet_header *nhrp_packet_push(
368 struct zbuf *zb, uint8_t type,
369 const union sockunion *src_nbma,
370 const union sockunion *src_proto,
371 const union sockunion *dst_proto);
372 void nhrp_packet_complete(struct zbuf *zb, struct nhrp_packet_header *hdr);
373 uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu, uint16_t len);
375 struct nhrp_packet_header *nhrp_packet_pull(
377 union sockunion *src_nbma,
378 union sockunion *src_proto,
379 union sockunion *dst_proto);
381 struct nhrp_cie_header *nhrp_cie_push(
382 struct zbuf *zb, uint8_t code,
383 const union sockunion *nbma,
384 const union sockunion *proto);
385 struct nhrp_cie_header *nhrp_cie_pull(
387 struct nhrp_packet_header *hdr,
388 union sockunion *nbma,
389 union sockunion *proto);
391 struct nhrp_extension_header *nhrp_ext_push(struct zbuf *zb, struct nhrp_packet_header *hdr, uint16_t type);
392 void nhrp_ext_complete(struct zbuf *zb, struct nhrp_extension_header *ext);
393 struct nhrp_extension_header *nhrp_ext_pull(struct zbuf *zb, struct zbuf *payload);
394 void nhrp_ext_request(struct zbuf *zb, struct nhrp_packet_header *hdr, struct interface *);
395 int nhrp_ext_reply(struct zbuf *zb, struct nhrp_packet_header *hdr, struct interface *ifp, struct nhrp_extension_header *ext, struct zbuf *extpayload);
397 uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *, struct nhrp_reqid *r, void (*cb)(struct nhrp_reqid *, void *));
398 void nhrp_reqid_free(struct nhrp_reqid_pool *, struct nhrp_reqid *r);
399 struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *, uint32_t reqid);
401 int nhrp_packet_init(void);
403 struct nhrp_peer *nhrp_peer_get(struct interface *ifp, const union sockunion *remote_nbma);
404 struct nhrp_peer *nhrp_peer_ref(struct nhrp_peer *p);
405 void nhrp_peer_unref(struct nhrp_peer *p);
406 int nhrp_peer_check(struct nhrp_peer *p, int establish);
407 void nhrp_peer_notify_add(struct nhrp_peer *p, struct notifier_block *, notifier_fn_t);
408 void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *);
409 void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb);
410 void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb);
411 void nhrp_peer_send_indication(struct interface *ifp, uint16_t, struct zbuf *);