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
;
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
,
40 #define NHRP_ERR_MAX (__NHRP_ERR_MAX - 1)
42 struct notifier_block
;
44 typedef void (*notifier_fn_t
)(struct notifier_block
*, unsigned long);
46 struct notifier_block
{
47 struct list_head notifier_entry
;
51 struct notifier_list
{
52 struct list_head notifier_head
;
55 #define NOTIFIER_LIST_INITIALIZER(l) \
56 { .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
, struct notifier_list
*l
, notifier_fn_t action
)
66 list_add_tail(&n
->notifier_entry
, &l
->notifier_head
);
69 static inline void notifier_del(struct notifier_block
*n
)
71 list_del(&n
->notifier_entry
);
74 static inline void notifier_call(struct notifier_list
*l
, int cmd
)
76 struct notifier_block
*n
, *nn
;
77 list_for_each_entry_safe(n
, nn
, &l
->notifier_head
, notifier_entry
)
81 static inline int notifier_active(struct notifier_list
*l
)
83 return !list_empty(&l
->notifier_head
);
86 struct resolver_query
{
87 void (*callback
)(struct resolver_query
*, int n
, union sockunion
*);
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
*));
93 void nhrp_zebra_init(void);
94 void nhrp_zebra_terminate(void);
100 struct nhrp_interface
;
102 #define MAX_ID_LENGTH 64
103 #define MAX_CERT_LENGTH 2048
105 enum nhrp_notify_type
{
107 NOTIFY_INTERFACE_DOWN
,
108 NOTIFY_INTERFACE_CHANGED
,
109 NOTIFY_INTERFACE_ADDRESS_CHANGED
,
110 NOTIFY_INTERFACE_NBMA_CHANGED
,
111 NOTIFY_INTERFACE_MTU_CHANGED
,
113 NOTIFY_VC_IPSEC_CHANGED
,
114 NOTIFY_VC_IPSEC_UPDATE_NBMA
,
118 NOTIFY_PEER_IFCONFIG_CHANGED
,
119 NOTIFY_PEER_MTU_CHANGED
,
120 NOTIFY_PEER_NBMA_CHANGING
,
126 NOTIFY_CACHE_BINDING_CHANGE
,
130 struct notifier_list notifier_list
;
133 uint8_t abort_migration
;
135 struct nhrp_vc_peer
{
136 union sockunion nbma
;
137 char id
[MAX_ID_LENGTH
];
139 uint8_t cert
[MAX_CERT_LENGTH
];
143 enum nhrp_route_type
{
144 NHRP_ROUTE_BLACKHOLE
,
146 NHRP_ROUTE_NBMA_NEXTHOP
,
153 unsigned requested
: 1;
154 unsigned fallback_requested
: 1;
156 struct notifier_list notifier_list
;
157 struct interface
*ifp
;
159 struct thread
*t_fallback
;
160 struct notifier_block vc_notifier
, ifp_notifier
;
163 struct nhrp_packet_parser
{
164 struct interface
*ifp
;
165 struct nhrp_afi_data
*if_ad
;
166 struct nhrp_peer
*peer
;
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
;
176 struct nhrp_reqid_pool
{
177 struct hash
*reqid_hash
;
178 uint32_t next_request_id
;
183 void (*cb
)(struct nhrp_reqid
*, void *);
186 extern struct nhrp_reqid_pool nhrp_packet_reqid
;
187 extern struct nhrp_reqid_pool nhrp_event_reqid
;
189 enum nhrp_cache_type
{
190 NHRP_CACHE_INVALID
= 0,
191 NHRP_CACHE_INCOMPLETE
,
201 extern const char * const nhrp_cache_type_str
[];
202 extern unsigned long nhrp_cache_counts
[NHRP_CACHE_NUM_TYPES
];
205 struct interface
*ifp
;
206 union sockunion remote_addr
;
210 unsigned route_installed
: 1;
211 unsigned nhrp_route_installed
: 1;
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
;
221 enum nhrp_cache_type type
;
222 union sockunion remote_nbma_natoa
;
223 struct nhrp_peer
*peer
;
229 struct nhrp_shortcut
{
231 union sockunion addr
;
233 struct nhrp_reqid reqid
;
234 struct thread
*t_timer
;
236 enum nhrp_cache_type type
;
237 unsigned int holding_time
;
238 unsigned route_installed
: 1;
239 unsigned expiring
: 1;
241 struct nhrp_cache
*cache
;
242 struct notifier_block cache_notifier
;
246 struct interface
*ifp
;
247 struct list_head nhslist_entry
;
251 union sockunion proto_addr
;
252 const char *nbma_fqdn
; /* IP-address or FQDN */
254 struct thread
*t_resolve
;
255 struct resolver_query dns_resolve
;
256 struct list_head reglist_head
;
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
;
266 union sockunion proto_addr
;
267 struct nhrp_peer
*peer
;
268 struct notifier_block peer_notifier
;
271 #define NHRP_IFF_SHORTCUT 0x0001
272 #define NHRP_IFF_REDIRECT 0x0002
273 #define NHRP_IFF_REG_NO_UNIQUE 0x0100
275 struct nhrp_interface
{
276 struct interface
*ifp
;
278 unsigned enabled
: 1;
280 char *ipsec_profile
, *ipsec_fallback_profile
, *source
;
281 union sockunion nbma
;
282 union sockunion nat_nbma
;
283 unsigned int linkidx
;
286 struct hash
*peer_hash
;
287 struct hash
*cache_hash
;
289 struct notifier_list notifier_list
;
291 struct interface
*nbmaifp
;
292 struct notifier_block nbmanifp_notifier
;
294 struct nhrp_afi_data
{
296 unsigned short configured
: 1;
297 union sockunion addr
;
299 short configured_mtu
;
301 unsigned int holdtime
;
302 struct list_head nhslist_head
;
306 extern struct zebra_privs_t nhrpd_privs
;
308 int sock_open_unix(const char *path
);
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
);
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
);
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
);
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
);
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
);
338 void nhrp_config_init(void);
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
);
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
*);
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);
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
);
367 extern const char *nhrp_event_socket_path
;
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 *));
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
);
382 struct nhrp_packet_header
*nhrp_packet_pull(
384 union sockunion
*src_nbma
,
385 union sockunion
*src_proto
,
386 union sockunion
*dst_proto
);
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(
394 struct nhrp_packet_header
*hdr
,
395 union sockunion
*nbma
,
396 union sockunion
*proto
);
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
);
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
);
408 int nhrp_packet_init(void);
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
*);