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.
21 DECLARE_MGROUP(NHRPD
);
23 #define NHRPD_DEFAULT_HOLDTIME 7200
25 #define NHRP_VTY_PORT 2610
26 #define NHRP_DEFAULT_CONFIG "nhrpd.conf"
28 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
,
39 #define NHRP_ERR_MAX (__NHRP_ERR_MAX - 1)
41 struct notifier_block
;
43 typedef void (*notifier_fn_t
)(struct notifier_block
*, unsigned long);
45 struct notifier_block
{
46 struct list_head notifier_entry
;
50 struct notifier_list
{
51 struct list_head notifier_head
;
54 #define NOTIFIER_LIST_INITIALIZER(l) \
56 .notifier_head = LIST_INITIALIZER((l)->notifier_head) \
59 static inline void notifier_init(struct notifier_list
*l
)
61 list_init(&l
->notifier_head
);
64 static inline void notifier_add(struct notifier_block
*n
,
65 struct notifier_list
*l
, notifier_fn_t action
)
68 list_add_tail(&n
->notifier_entry
, &l
->notifier_head
);
71 static inline void notifier_del(struct notifier_block
*n
)
73 list_del(&n
->notifier_entry
);
76 static inline void notifier_call(struct notifier_list
*l
, int cmd
)
78 struct notifier_block
*n
, *nn
;
79 list_for_each_entry_safe(n
, nn
, &l
->notifier_head
, notifier_entry
) {
84 static inline int notifier_active(struct notifier_list
*l
)
86 return !list_empty(&l
->notifier_head
);
89 extern struct hash
*nhrp_gre_list
;
91 void nhrp_zebra_init(void);
92 void nhrp_zebra_terminate(void);
93 void nhrp_send_zebra_configure_arp(struct interface
*ifp
, int family
);
94 void nhrp_send_zebra_nbr(union sockunion
*in
,
96 struct interface
*ifp
);
98 void nhrp_send_zebra_gre_source_set(struct interface
*ifp
,
99 unsigned int link_idx
,
100 vrf_id_t link_vrf_id
);
102 extern int nhrp_send_zebra_gre_request(struct interface
*ifp
);
103 extern struct nhrp_gre_info
*nhrp_gre_info_alloc(struct nhrp_gre_info
*p
);
109 struct nhrp_interface
;
111 #define MAX_ID_LENGTH 64
112 #define MAX_CERT_LENGTH 2048
114 enum nhrp_notify_type
{
116 NOTIFY_INTERFACE_DOWN
,
117 NOTIFY_INTERFACE_CHANGED
,
118 NOTIFY_INTERFACE_ADDRESS_CHANGED
,
119 NOTIFY_INTERFACE_NBMA_CHANGED
,
120 NOTIFY_INTERFACE_MTU_CHANGED
,
121 NOTIFY_INTERFACE_IPSEC_CHANGED
,
123 NOTIFY_VC_IPSEC_CHANGED
,
124 NOTIFY_VC_IPSEC_UPDATE_NBMA
,
128 NOTIFY_PEER_IFCONFIG_CHANGED
,
129 NOTIFY_PEER_MTU_CHANGED
,
130 NOTIFY_PEER_NBMA_CHANGING
,
136 NOTIFY_CACHE_BINDING_CHANGE
,
140 struct notifier_list notifier_list
;
142 uint32_t ike_uniqueid
;
144 uint8_t abort_migration
;
146 struct nhrp_vc_peer
{
147 union sockunion nbma
;
148 char id
[MAX_ID_LENGTH
];
150 uint8_t cert
[MAX_CERT_LENGTH
];
154 enum nhrp_route_type
{
155 NHRP_ROUTE_BLACKHOLE
,
157 NHRP_ROUTE_NBMA_NEXTHOP
,
164 unsigned requested
: 1;
165 unsigned fallback_requested
: 1;
167 struct notifier_list notifier_list
;
168 struct interface
*ifp
;
170 struct thread
*t_fallback
;
171 struct notifier_block vc_notifier
, ifp_notifier
;
172 struct thread
*t_timer
;
175 struct nhrp_packet_parser
{
176 struct interface
*ifp
;
177 struct nhrp_afi_data
*if_ad
;
178 struct nhrp_peer
*peer
;
181 struct zbuf extensions
;
182 struct nhrp_packet_header
*hdr
;
183 enum nhrp_route_type route_type
;
184 struct prefix route_prefix
;
185 union sockunion src_nbma
, src_proto
, dst_proto
;
188 struct nhrp_reqid_pool
{
189 struct hash
*reqid_hash
;
190 uint32_t next_request_id
;
195 void (*cb
)(struct nhrp_reqid
*, void *);
198 extern struct nhrp_reqid_pool nhrp_packet_reqid
;
199 extern struct nhrp_reqid_pool nhrp_event_reqid
;
201 enum nhrp_cache_type
{
202 NHRP_CACHE_INVALID
= 0,
203 NHRP_CACHE_INCOMPLETE
,
213 extern const char *const nhrp_cache_type_str
[];
214 extern unsigned long nhrp_cache_counts
[NHRP_CACHE_NUM_TYPES
];
216 struct nhrp_cache_config
{
217 struct interface
*ifp
;
218 union sockunion remote_addr
;
219 enum nhrp_cache_type type
;
220 union sockunion nbma
;
224 struct interface
*ifp
;
225 union sockunion remote_addr
;
229 unsigned route_installed
: 1;
230 unsigned nhrp_route_installed
: 1;
232 struct notifier_block peer_notifier
;
233 struct notifier_block newpeer_notifier
;
234 struct notifier_list notifier_list
;
235 struct nhrp_reqid eventid
;
236 struct thread
*t_timeout
;
237 struct thread
*t_auth
;
240 enum nhrp_cache_type type
;
241 union sockunion remote_nbma_natoa
;
242 union sockunion remote_nbma_claimed
;
243 struct nhrp_peer
*peer
;
250 struct nhrp_shortcut
{
252 union sockunion addr
;
254 struct nhrp_reqid reqid
;
255 struct thread
*t_timer
;
257 enum nhrp_cache_type type
;
258 unsigned int holding_time
;
259 unsigned route_installed
: 1;
260 unsigned expiring
: 1;
262 struct nhrp_cache
*cache
;
263 struct notifier_block cache_notifier
;
267 struct interface
*ifp
;
268 struct list_head nhslist_entry
;
272 union sockunion proto_addr
;
273 const char *nbma_fqdn
; /* IP-address or FQDN */
275 struct thread
*t_resolve
;
276 struct resolver_query dns_resolve
;
277 struct list_head reglist_head
;
280 struct nhrp_multicast
{
281 struct interface
*ifp
;
282 struct list_head list_entry
;
284 union sockunion nbma_addr
; /* IP-address */
287 struct nhrp_registration
{
288 struct list_head reglist_entry
;
289 struct thread
*t_register
;
290 struct nhrp_nhs
*nhs
;
291 struct nhrp_reqid reqid
;
292 unsigned int timeout
;
294 union sockunion proto_addr
;
295 struct nhrp_peer
*peer
;
296 struct notifier_block peer_notifier
;
299 #define NHRP_IFF_SHORTCUT 0x0001
300 #define NHRP_IFF_REDIRECT 0x0002
301 #define NHRP_IFF_REG_NO_UNIQUE 0x0100
303 struct nhrp_interface
{
304 struct interface
*ifp
;
306 unsigned enabled
: 1;
308 char *ipsec_profile
, *ipsec_fallback_profile
, *source
;
309 union sockunion nbma
;
310 union sockunion nat_nbma
;
311 unsigned int link_idx
;
312 unsigned int link_vrf_id
;
316 struct hash
*peer_hash
;
317 struct hash
*cache_config_hash
;
318 struct hash
*cache_hash
;
320 struct notifier_list notifier_list
;
322 struct interface
*nbmaifp
;
323 struct notifier_block nbmanifp_notifier
;
325 struct nhrp_afi_data
{
327 unsigned short configured
: 1;
328 union sockunion addr
;
330 short configured_mtu
;
332 unsigned int holdtime
;
333 struct list_head nhslist_head
;
334 struct list_head mcastlist_head
;
338 struct nhrp_gre_info
{
340 struct in_addr vtep_ip
; /* IFLA_GRE_LOCAL */
341 struct in_addr vtep_ip_remote
; /* IFLA_GRE_REMOTE */
344 ifindex_t ifindex_link
; /* Interface index of interface
350 extern struct zebra_privs_t nhrpd_privs
;
352 int sock_open_unix(const char *path
);
354 void nhrp_interface_init(void);
355 void nhrp_interface_update(struct interface
*ifp
);
356 void nhrp_interface_update_mtu(struct interface
*ifp
, afi_t afi
);
357 void nhrp_interface_update_nbma(struct interface
*ifp
,
358 struct nhrp_gre_info
*gre_info
);
360 int nhrp_interface_add(ZAPI_CALLBACK_ARGS
);
361 int nhrp_interface_delete(ZAPI_CALLBACK_ARGS
);
362 int nhrp_interface_up(ZAPI_CALLBACK_ARGS
);
363 int nhrp_interface_down(ZAPI_CALLBACK_ARGS
);
364 int nhrp_interface_address_add(ZAPI_CALLBACK_ARGS
);
365 int nhrp_interface_address_delete(ZAPI_CALLBACK_ARGS
);
366 void nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS
);
367 void nhrp_gre_update(ZAPI_CALLBACK_ARGS
);
369 void nhrp_interface_notify_add(struct interface
*ifp
, struct notifier_block
*n
,
371 void nhrp_interface_notify_del(struct interface
*ifp
, struct notifier_block
*n
);
372 void nhrp_interface_set_protection(struct interface
*ifp
, const char *profile
,
373 const char *fallback_profile
);
374 void nhrp_interface_set_source(struct interface
*ifp
, const char *ifname
);
375 extern int nhrp_ifp_create(struct interface
*ifp
);
376 extern int nhrp_ifp_up(struct interface
*ifp
);
377 extern int nhrp_ifp_down(struct interface
*ifp
);
378 extern int nhrp_ifp_destroy(struct interface
*ifp
);
380 int nhrp_nhs_add(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
,
381 const char *nbma_fqdn
);
382 int nhrp_nhs_del(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
,
383 const char *nbma_fqdn
);
384 int nhrp_nhs_free(struct nhrp_nhs
*nhs
);
385 void nhrp_nhs_terminate(void);
386 void nhrp_nhs_foreach(struct interface
*ifp
, afi_t afi
,
387 void (*cb
)(struct nhrp_nhs
*, struct nhrp_registration
*,
390 void nhrp_nhs_interface_del(struct interface
*ifp
);
392 int nhrp_multicast_add(struct interface
*ifp
, afi_t afi
,
393 union sockunion
*nbma_addr
);
394 int nhrp_multicast_del(struct interface
*ifp
, afi_t afi
,
395 union sockunion
*nbma_addr
);
396 void nhrp_multicast_interface_del(struct interface
*ifp
);
397 void nhrp_multicast_foreach(struct interface
*ifp
, afi_t afi
,
398 void (*cb
)(struct nhrp_multicast
*, void *),
400 void netlink_mcast_set_nflog_group(int nlgroup
);
402 void nhrp_route_update_nhrp(const struct prefix
*p
, struct interface
*ifp
);
403 void nhrp_route_announce(int add
, enum nhrp_cache_type type
,
404 const struct prefix
*p
, struct interface
*ifp
,
405 const union sockunion
*nexthop
, uint32_t mtu
);
406 int nhrp_route_read(ZAPI_CALLBACK_ARGS
);
407 int nhrp_route_get_nexthop(const union sockunion
*addr
, struct prefix
*p
,
408 union sockunion
*via
, struct interface
**ifp
);
409 enum nhrp_route_type
nhrp_route_address(struct interface
*in_ifp
,
410 union sockunion
*addr
, struct prefix
*p
,
411 struct nhrp_peer
**peer
);
413 void nhrp_config_init(void);
415 void nhrp_shortcut_init(void);
416 void nhrp_shortcut_terminate(void);
417 void nhrp_shortcut_initiate(union sockunion
*addr
);
418 void nhrp_shortcut_foreach(afi_t afi
,
419 void (*cb
)(struct nhrp_shortcut
*, void *),
421 void nhrp_shortcut_purge(struct nhrp_shortcut
*s
, int force
);
422 void nhrp_shortcut_prefix_change(const struct prefix
*p
, int deleted
);
424 void nhrp_cache_interface_del(struct interface
*ifp
);
425 void nhrp_cache_config_free(struct nhrp_cache_config
*c
);
426 struct nhrp_cache_config
*nhrp_cache_config_get(struct interface
*ifp
,
427 union sockunion
*remote_addr
,
429 struct nhrp_cache
*nhrp_cache_get(struct interface
*ifp
,
430 union sockunion
*remote_addr
, int create
);
431 void nhrp_cache_foreach(struct interface
*ifp
,
432 void (*cb
)(struct nhrp_cache
*, void *), void *ctx
);
433 void nhrp_cache_config_foreach(struct interface
*ifp
,
434 void (*cb
)(struct nhrp_cache_config
*, void *), void *ctx
);
435 void nhrp_cache_set_used(struct nhrp_cache
*, int);
436 int nhrp_cache_update_binding(struct nhrp_cache
*, enum nhrp_cache_type type
,
437 int holding_time
, struct nhrp_peer
*p
,
438 uint32_t mtu
, union sockunion
*nbma_natoa
,
439 union sockunion
*claimed_nbma
);
440 void nhrp_cache_notify_add(struct nhrp_cache
*c
, struct notifier_block
*,
442 void nhrp_cache_notify_del(struct nhrp_cache
*c
, struct notifier_block
*);
444 void nhrp_vc_init(void);
445 void nhrp_vc_terminate(void);
446 struct nhrp_vc
*nhrp_vc_get(const union sockunion
*src
,
447 const union sockunion
*dst
, int create
);
448 int nhrp_vc_ipsec_updown(uint32_t child_id
, struct nhrp_vc
*vc
);
449 void nhrp_vc_notify_add(struct nhrp_vc
*, struct notifier_block
*,
451 void nhrp_vc_notify_del(struct nhrp_vc
*, struct notifier_block
*);
452 void nhrp_vc_foreach(void (*cb
)(struct nhrp_vc
*, void *), void *ctx
);
453 void nhrp_vc_reset(void);
455 void vici_init(void);
456 void vici_terminate(void);
457 void vici_terminate_vc_by_profile_name(char *profile_name
);
458 void vici_terminate_vc_by_ike_id(unsigned int ike_id
);
459 void vici_request_vc(const char *profile
, union sockunion
*src
,
460 union sockunion
*dst
, int prio
);
462 extern const char *nhrp_event_socket_path
;
464 void evmgr_init(void);
465 void evmgr_terminate(void);
466 void evmgr_set_socket(const char *socket
);
467 void evmgr_notify(const char *name
, struct nhrp_cache
*c
,
468 void (*cb
)(struct nhrp_reqid
*, void *));
470 struct nhrp_packet_header
*nhrp_packet_push(struct zbuf
*zb
, uint8_t type
,
471 const union sockunion
*src_nbma
,
472 const union sockunion
*src_proto
,
473 const union sockunion
*dst_proto
);
474 void nhrp_packet_complete(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
);
475 uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu
, uint16_t len
);
477 struct nhrp_packet_header
*nhrp_packet_pull(struct zbuf
*zb
,
478 union sockunion
*src_nbma
,
479 union sockunion
*src_proto
,
480 union sockunion
*dst_proto
);
482 struct nhrp_cie_header
*nhrp_cie_push(struct zbuf
*zb
, uint8_t code
,
483 const union sockunion
*nbma
,
484 const union sockunion
*proto
);
485 struct nhrp_cie_header
*nhrp_cie_pull(struct zbuf
*zb
,
486 struct nhrp_packet_header
*hdr
,
487 union sockunion
*nbma
,
488 union sockunion
*proto
);
490 struct nhrp_extension_header
*
491 nhrp_ext_push(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
, uint16_t type
);
492 void nhrp_ext_complete(struct zbuf
*zb
, struct nhrp_extension_header
*ext
);
493 struct nhrp_extension_header
*nhrp_ext_pull(struct zbuf
*zb
,
494 struct zbuf
*payload
);
495 void nhrp_ext_request(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
,
497 int nhrp_ext_reply(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
,
498 struct interface
*ifp
, struct nhrp_extension_header
*ext
,
499 struct zbuf
*extpayload
);
501 uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
,
502 void (*cb
)(struct nhrp_reqid
*, void *));
503 void nhrp_reqid_free(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
);
504 struct nhrp_reqid
*nhrp_reqid_lookup(struct nhrp_reqid_pool
*, uint32_t reqid
);
506 int nhrp_packet_init(void);
508 void nhrp_peer_interface_del(struct interface
*ifp
);
509 struct nhrp_peer
*nhrp_peer_get(struct interface
*ifp
,
510 const union sockunion
*remote_nbma
);
511 struct nhrp_peer
*nhrp_peer_ref(struct nhrp_peer
*p
);
512 void nhrp_peer_unref(struct nhrp_peer
*p
);
513 int nhrp_peer_check(struct nhrp_peer
*p
, int establish
);
514 void nhrp_peer_notify_add(struct nhrp_peer
*p
, struct notifier_block
*,
516 void nhrp_peer_notify_del(struct nhrp_peer
*p
, struct notifier_block
*);
517 void nhrp_peer_recv(struct nhrp_peer
*p
, struct zbuf
*zb
);
518 void nhrp_peer_send(struct nhrp_peer
*p
, struct zbuf
*zb
);
519 void nhrp_peer_send_indication(struct interface
*ifp
, uint16_t, struct zbuf
*);
521 int nhrp_nhs_match_ip(union sockunion
*in_ip
, struct nhrp_interface
*nifp
);