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.
22 #define NHRPD_DEFAULT_HOLDTIME 7200
24 #define NHRP_VTY_PORT 2610
25 #define NHRP_DEFAULT_CONFIG "nhrpd.conf"
27 extern struct thread_master
*master
;
32 NHRP_ERR_UNSUPPORTED_INTERFACE
,
33 NHRP_ERR_NHRP_NOT_ENABLED
,
34 NHRP_ERR_ENTRY_EXISTS
,
35 NHRP_ERR_ENTRY_NOT_FOUND
,
36 NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH
,
38 #define NHRP_ERR_MAX (__NHRP_ERR_MAX - 1)
40 struct notifier_block
;
42 typedef void (*notifier_fn_t
)(struct notifier_block
*, unsigned long);
44 struct notifier_block
{
45 struct list_head notifier_entry
;
49 struct notifier_list
{
50 struct list_head notifier_head
;
53 #define NOTIFIER_LIST_INITIALIZER(l) \
55 .notifier_head = LIST_INITIALIZER((l)->notifier_head) \
58 static inline void notifier_init(struct notifier_list
*l
)
60 list_init(&l
->notifier_head
);
63 static inline void notifier_add(struct notifier_block
*n
,
64 struct notifier_list
*l
, notifier_fn_t action
)
67 list_add_tail(&n
->notifier_entry
, &l
->notifier_head
);
70 static inline void notifier_del(struct notifier_block
*n
)
72 list_del(&n
->notifier_entry
);
75 static inline void notifier_call(struct notifier_list
*l
, int cmd
)
77 struct notifier_block
*n
, *nn
;
78 list_for_each_entry_safe(n
, nn
, &l
->notifier_head
, notifier_entry
)
82 static inline int notifier_active(struct notifier_list
*l
)
84 return !list_empty(&l
->notifier_head
);
87 struct resolver_query
{
88 void (*callback
)(struct resolver_query
*, int n
, union sockunion
*);
91 void resolver_init(void);
92 void resolver_resolve(struct resolver_query
*query
, int af
,
93 const char *hostname
, void (*cb
)(struct resolver_query
*,
94 int, union sockunion
*));
96 void nhrp_zebra_init(void);
97 void nhrp_zebra_terminate(void);
103 struct nhrp_interface
;
105 #define MAX_ID_LENGTH 64
106 #define MAX_CERT_LENGTH 2048
108 enum nhrp_notify_type
{
110 NOTIFY_INTERFACE_DOWN
,
111 NOTIFY_INTERFACE_CHANGED
,
112 NOTIFY_INTERFACE_ADDRESS_CHANGED
,
113 NOTIFY_INTERFACE_NBMA_CHANGED
,
114 NOTIFY_INTERFACE_MTU_CHANGED
,
116 NOTIFY_VC_IPSEC_CHANGED
,
117 NOTIFY_VC_IPSEC_UPDATE_NBMA
,
121 NOTIFY_PEER_IFCONFIG_CHANGED
,
122 NOTIFY_PEER_MTU_CHANGED
,
123 NOTIFY_PEER_NBMA_CHANGING
,
129 NOTIFY_CACHE_BINDING_CHANGE
,
133 struct notifier_list notifier_list
;
136 uint8_t abort_migration
;
138 struct nhrp_vc_peer
{
139 union sockunion nbma
;
140 char id
[MAX_ID_LENGTH
];
142 uint8_t cert
[MAX_CERT_LENGTH
];
146 enum nhrp_route_type
{
147 NHRP_ROUTE_BLACKHOLE
,
149 NHRP_ROUTE_NBMA_NEXTHOP
,
156 unsigned requested
: 1;
157 unsigned fallback_requested
: 1;
159 struct notifier_list notifier_list
;
160 struct interface
*ifp
;
162 struct thread
*t_fallback
;
163 struct notifier_block vc_notifier
, ifp_notifier
;
166 struct nhrp_packet_parser
{
167 struct interface
*ifp
;
168 struct nhrp_afi_data
*if_ad
;
169 struct nhrp_peer
*peer
;
172 struct zbuf extensions
;
173 struct nhrp_packet_header
*hdr
;
174 enum nhrp_route_type route_type
;
175 struct prefix route_prefix
;
176 union sockunion src_nbma
, src_proto
, dst_proto
;
179 struct nhrp_reqid_pool
{
180 struct hash
*reqid_hash
;
181 uint32_t next_request_id
;
186 void (*cb
)(struct nhrp_reqid
*, void *);
189 extern struct nhrp_reqid_pool nhrp_packet_reqid
;
190 extern struct nhrp_reqid_pool nhrp_event_reqid
;
192 enum nhrp_cache_type
{
193 NHRP_CACHE_INVALID
= 0,
194 NHRP_CACHE_INCOMPLETE
,
204 extern const char *const nhrp_cache_type_str
[];
205 extern unsigned long nhrp_cache_counts
[NHRP_CACHE_NUM_TYPES
];
208 struct interface
*ifp
;
209 union sockunion remote_addr
;
213 unsigned route_installed
: 1;
214 unsigned nhrp_route_installed
: 1;
216 struct notifier_block peer_notifier
;
217 struct notifier_block newpeer_notifier
;
218 struct notifier_list notifier_list
;
219 struct nhrp_reqid eventid
;
220 struct thread
*t_timeout
;
221 struct thread
*t_auth
;
224 enum nhrp_cache_type type
;
225 union sockunion remote_nbma_natoa
;
226 struct nhrp_peer
*peer
;
232 struct nhrp_shortcut
{
234 union sockunion addr
;
236 struct nhrp_reqid reqid
;
237 struct thread
*t_timer
;
239 enum nhrp_cache_type type
;
240 unsigned int holding_time
;
241 unsigned route_installed
: 1;
242 unsigned expiring
: 1;
244 struct nhrp_cache
*cache
;
245 struct notifier_block cache_notifier
;
249 struct interface
*ifp
;
250 struct list_head nhslist_entry
;
254 union sockunion proto_addr
;
255 const char *nbma_fqdn
; /* IP-address or FQDN */
257 struct thread
*t_resolve
;
258 struct resolver_query dns_resolve
;
259 struct list_head reglist_head
;
262 struct nhrp_registration
{
263 struct list_head reglist_entry
;
264 struct thread
*t_register
;
265 struct nhrp_nhs
*nhs
;
266 struct nhrp_reqid reqid
;
267 unsigned int timeout
;
269 union sockunion proto_addr
;
270 struct nhrp_peer
*peer
;
271 struct notifier_block peer_notifier
;
274 #define NHRP_IFF_SHORTCUT 0x0001
275 #define NHRP_IFF_REDIRECT 0x0002
276 #define NHRP_IFF_REG_NO_UNIQUE 0x0100
278 struct nhrp_interface
{
279 struct interface
*ifp
;
281 unsigned enabled
: 1;
283 char *ipsec_profile
, *ipsec_fallback_profile
, *source
;
284 union sockunion nbma
;
285 union sockunion nat_nbma
;
286 unsigned int linkidx
;
289 struct hash
*peer_hash
;
290 struct hash
*cache_hash
;
292 struct notifier_list notifier_list
;
294 struct interface
*nbmaifp
;
295 struct notifier_block nbmanifp_notifier
;
297 struct nhrp_afi_data
{
299 unsigned short configured
: 1;
300 union sockunion addr
;
302 short configured_mtu
;
304 unsigned int holdtime
;
305 struct list_head nhslist_head
;
309 extern struct zebra_privs_t nhrpd_privs
;
311 int sock_open_unix(const char *path
);
313 void nhrp_interface_init(void);
314 void nhrp_interface_update(struct interface
*ifp
);
315 void nhrp_interface_update_mtu(struct interface
*ifp
, afi_t afi
);
317 int nhrp_interface_add(int cmd
, struct zclient
*client
, zebra_size_t length
,
319 int nhrp_interface_delete(int cmd
, struct zclient
*client
, zebra_size_t length
,
321 int nhrp_interface_up(int cmd
, struct zclient
*client
, zebra_size_t length
,
323 int nhrp_interface_down(int cmd
, struct zclient
*client
, zebra_size_t length
,
325 int nhrp_interface_address_add(int cmd
, struct zclient
*client
,
326 zebra_size_t length
, vrf_id_t vrf_id
);
327 int nhrp_interface_address_delete(int cmd
, struct zclient
*client
,
328 zebra_size_t length
, vrf_id_t vrf_id
);
330 void nhrp_interface_notify_add(struct interface
*ifp
, struct notifier_block
*n
,
332 void nhrp_interface_notify_del(struct interface
*ifp
, struct notifier_block
*n
);
333 void nhrp_interface_set_protection(struct interface
*ifp
, const char *profile
,
334 const char *fallback_profile
);
335 void nhrp_interface_set_source(struct interface
*ifp
, const char *ifname
);
337 int nhrp_nhs_add(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
,
338 const char *nbma_fqdn
);
339 int nhrp_nhs_del(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
,
340 const char *nbma_fqdn
);
341 int nhrp_nhs_free(struct nhrp_nhs
*nhs
);
342 void nhrp_nhs_terminate(void);
343 void nhrp_nhs_foreach(struct interface
*ifp
, afi_t afi
,
344 void (*cb
)(struct nhrp_nhs
*, struct nhrp_registration
*,
348 void nhrp_route_update_nhrp(const struct prefix
*p
, struct interface
*ifp
);
349 void nhrp_route_announce(int add
, enum nhrp_cache_type type
,
350 const struct prefix
*p
, struct interface
*ifp
,
351 const union sockunion
*nexthop
, uint32_t mtu
);
352 int nhrp_route_read(int command
, struct zclient
*zclient
, zebra_size_t length
,
354 int nhrp_route_get_nexthop(const union sockunion
*addr
, struct prefix
*p
,
355 union sockunion
*via
, struct interface
**ifp
);
356 enum nhrp_route_type
nhrp_route_address(struct interface
*in_ifp
,
357 union sockunion
*addr
, struct prefix
*p
,
358 struct nhrp_peer
**peer
);
360 void nhrp_config_init(void);
362 void nhrp_shortcut_init(void);
363 void nhrp_shortcut_terminate(void);
364 void nhrp_shortcut_initiate(union sockunion
*addr
);
365 void nhrp_shortcut_foreach(afi_t afi
,
366 void (*cb
)(struct nhrp_shortcut
*, void *),
368 void nhrp_shortcut_purge(struct nhrp_shortcut
*s
, int force
);
369 void nhrp_shortcut_prefix_change(const struct prefix
*p
, int deleted
);
371 struct nhrp_cache
*nhrp_cache_get(struct interface
*ifp
,
372 union sockunion
*remote_addr
, int create
);
373 void nhrp_cache_foreach(struct interface
*ifp
,
374 void (*cb
)(struct nhrp_cache
*, void *), void *ctx
);
375 void nhrp_cache_set_used(struct nhrp_cache
*, int);
376 int nhrp_cache_update_binding(struct nhrp_cache
*, enum nhrp_cache_type type
,
377 int holding_time
, struct nhrp_peer
*p
,
378 uint32_t mtu
, union sockunion
*nbma_natoa
);
379 void nhrp_cache_notify_add(struct nhrp_cache
*c
, struct notifier_block
*,
381 void nhrp_cache_notify_del(struct nhrp_cache
*c
, struct notifier_block
*);
383 void nhrp_vc_init(void);
384 void nhrp_vc_terminate(void);
385 struct nhrp_vc
*nhrp_vc_get(const union sockunion
*src
,
386 const union sockunion
*dst
, int create
);
387 int nhrp_vc_ipsec_updown(uint32_t child_id
, struct nhrp_vc
*vc
);
388 void nhrp_vc_notify_add(struct nhrp_vc
*, struct notifier_block
*,
390 void nhrp_vc_notify_del(struct nhrp_vc
*, struct notifier_block
*);
391 void nhrp_vc_foreach(void (*cb
)(struct nhrp_vc
*, void *), void *ctx
);
392 void nhrp_vc_reset(void);
394 void vici_init(void);
395 void vici_terminate(void);
396 void vici_request_vc(const char *profile
, union sockunion
*src
,
397 union sockunion
*dst
, int prio
);
399 extern const char *nhrp_event_socket_path
;
401 void evmgr_init(void);
402 void evmgr_terminate(void);
403 void evmgr_set_socket(const char *socket
);
404 void evmgr_notify(const char *name
, struct nhrp_cache
*c
,
405 void (*cb
)(struct nhrp_reqid
*, void *));
407 struct nhrp_packet_header
*nhrp_packet_push(struct zbuf
*zb
, uint8_t type
,
408 const union sockunion
*src_nbma
,
409 const union sockunion
*src_proto
,
410 const union sockunion
*dst_proto
);
411 void nhrp_packet_complete(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
);
412 uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu
, uint16_t len
);
414 struct nhrp_packet_header
*nhrp_packet_pull(struct zbuf
*zb
,
415 union sockunion
*src_nbma
,
416 union sockunion
*src_proto
,
417 union sockunion
*dst_proto
);
419 struct nhrp_cie_header
*nhrp_cie_push(struct zbuf
*zb
, uint8_t code
,
420 const union sockunion
*nbma
,
421 const union sockunion
*proto
);
422 struct nhrp_cie_header
*nhrp_cie_pull(struct zbuf
*zb
,
423 struct nhrp_packet_header
*hdr
,
424 union sockunion
*nbma
,
425 union sockunion
*proto
);
427 struct nhrp_extension_header
*
428 nhrp_ext_push(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
, uint16_t type
);
429 void nhrp_ext_complete(struct zbuf
*zb
, struct nhrp_extension_header
*ext
);
430 struct nhrp_extension_header
*nhrp_ext_pull(struct zbuf
*zb
,
431 struct zbuf
*payload
);
432 void nhrp_ext_request(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
,
434 int nhrp_ext_reply(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
,
435 struct interface
*ifp
, struct nhrp_extension_header
*ext
,
436 struct zbuf
*extpayload
);
438 uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
,
439 void (*cb
)(struct nhrp_reqid
*, void *));
440 void nhrp_reqid_free(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
);
441 struct nhrp_reqid
*nhrp_reqid_lookup(struct nhrp_reqid_pool
*, uint32_t reqid
);
443 int nhrp_packet_init(void);
445 struct nhrp_peer
*nhrp_peer_get(struct interface
*ifp
,
446 const union sockunion
*remote_nbma
);
447 struct nhrp_peer
*nhrp_peer_ref(struct nhrp_peer
*p
);
448 void nhrp_peer_unref(struct nhrp_peer
*p
);
449 int nhrp_peer_check(struct nhrp_peer
*p
, int establish
);
450 void nhrp_peer_notify_add(struct nhrp_peer
*p
, struct notifier_block
*,
452 void nhrp_peer_notify_del(struct nhrp_peer
*p
, struct notifier_block
*);
453 void nhrp_peer_recv(struct nhrp_peer
*p
, struct zbuf
*zb
);
454 void nhrp_peer_send(struct nhrp_peer
*p
, struct zbuf
*zb
);
455 void nhrp_peer_send_indication(struct interface
*ifp
, uint16_t, struct zbuf
*);