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 DECLARE_MGROUP(NHRPD
);
21 #define NHRPD_DEFAULT_HOLDTIME 7200
23 #define NHRP_VTY_PORT 2610
24 #define NHRP_DEFAULT_CONFIG "nhrpd.conf"
26 extern struct thread_master
*master
;
31 NHRP_ERR_UNSUPPORTED_INTERFACE
,
32 NHRP_ERR_NHRP_NOT_ENABLED
,
33 NHRP_ERR_ENTRY_EXISTS
,
34 NHRP_ERR_ENTRY_NOT_FOUND
,
35 NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH
,
37 #define NHRP_ERR_MAX (__NHRP_ERR_MAX - 1)
39 struct notifier_block
;
41 typedef void (*notifier_fn_t
)(struct notifier_block
*, unsigned long);
43 PREDECL_DLIST(notifier_list
);
45 struct notifier_block
{
46 struct notifier_list_item notifier_entry
;
50 DECLARE_DLIST(notifier_list
, struct notifier_block
, notifier_entry
);
52 struct notifier_list
{
53 struct notifier_list_head head
;
56 #define NOTIFIER_LIST_INITIALIZER(l) \
58 .head = INIT_DLIST((l)->head) \
61 static inline void notifier_init(struct notifier_list
*l
)
63 notifier_list_init(&l
->head
);
66 static inline void notifier_add(struct notifier_block
*n
,
67 struct notifier_list
*l
, notifier_fn_t action
)
70 notifier_list_add_tail(&l
->head
, n
);
73 static inline void notifier_del(struct notifier_block
*n
,
74 struct notifier_list
*l
)
76 notifier_list_del(&l
->head
, n
);
79 static inline void notifier_call(struct notifier_list
*l
, int cmd
)
81 struct notifier_block
*n
;
83 frr_each_safe (notifier_list
, &l
->head
, n
)
87 static inline int notifier_active(struct notifier_list
*l
)
89 return notifier_list_count(&l
->head
) > 0;
92 extern struct hash
*nhrp_gre_list
;
94 void nhrp_zebra_init(void);
95 void nhrp_zebra_terminate(void);
96 void nhrp_send_zebra_configure_arp(struct interface
*ifp
, int family
);
97 void nhrp_send_zebra_nbr(union sockunion
*in
,
99 struct interface
*ifp
);
101 void nhrp_send_zebra_gre_source_set(struct interface
*ifp
,
102 unsigned int link_idx
,
103 vrf_id_t link_vrf_id
);
105 extern int nhrp_send_zebra_gre_request(struct interface
*ifp
);
106 extern struct nhrp_gre_info
*nhrp_gre_info_alloc(struct nhrp_gre_info
*p
);
112 struct nhrp_interface
;
114 #define MAX_ID_LENGTH 64
115 #define MAX_CERT_LENGTH 2048
117 enum nhrp_notify_type
{
119 NOTIFY_INTERFACE_DOWN
,
120 NOTIFY_INTERFACE_CHANGED
,
121 NOTIFY_INTERFACE_ADDRESS_CHANGED
,
122 NOTIFY_INTERFACE_NBMA_CHANGED
,
123 NOTIFY_INTERFACE_MTU_CHANGED
,
124 NOTIFY_INTERFACE_IPSEC_CHANGED
,
126 NOTIFY_VC_IPSEC_CHANGED
,
127 NOTIFY_VC_IPSEC_UPDATE_NBMA
,
131 NOTIFY_PEER_IFCONFIG_CHANGED
,
132 NOTIFY_PEER_MTU_CHANGED
,
133 NOTIFY_PEER_NBMA_CHANGING
,
139 NOTIFY_CACHE_BINDING_CHANGE
,
143 struct notifier_list notifier_list
;
145 uint32_t ike_uniqueid
;
147 uint8_t abort_migration
;
149 struct nhrp_vc_peer
{
150 union sockunion nbma
;
151 char id
[MAX_ID_LENGTH
];
153 uint8_t cert
[MAX_CERT_LENGTH
];
157 enum nhrp_route_type
{
158 NHRP_ROUTE_BLACKHOLE
,
160 NHRP_ROUTE_NBMA_NEXTHOP
,
167 unsigned requested
: 1;
168 unsigned fallback_requested
: 1;
170 struct notifier_list notifier_list
;
171 struct interface
*ifp
;
173 struct thread
*t_fallback
;
174 struct notifier_block vc_notifier
, ifp_notifier
;
175 struct thread
*t_timer
;
178 struct nhrp_packet_parser
{
179 struct interface
*ifp
;
180 struct nhrp_afi_data
*if_ad
;
181 struct nhrp_peer
*peer
;
184 struct zbuf extensions
;
185 struct nhrp_packet_header
*hdr
;
186 enum nhrp_route_type route_type
;
187 struct prefix route_prefix
;
188 union sockunion src_nbma
, src_proto
, dst_proto
;
191 struct nhrp_reqid_pool
{
192 struct hash
*reqid_hash
;
193 uint32_t next_request_id
;
198 void (*cb
)(struct nhrp_reqid
*, void *);
201 extern struct nhrp_reqid_pool nhrp_packet_reqid
;
202 extern struct nhrp_reqid_pool nhrp_event_reqid
;
204 enum nhrp_cache_type
{
205 NHRP_CACHE_INVALID
= 0,
206 NHRP_CACHE_INCOMPLETE
,
216 extern const char *const nhrp_cache_type_str
[];
217 extern unsigned long nhrp_cache_counts
[NHRP_CACHE_NUM_TYPES
];
219 struct nhrp_cache_config
{
220 struct interface
*ifp
;
221 union sockunion remote_addr
;
222 enum nhrp_cache_type type
;
223 union sockunion nbma
;
227 struct interface
*ifp
;
228 union sockunion remote_addr
;
232 unsigned route_installed
: 1;
233 unsigned nhrp_route_installed
: 1;
235 struct notifier_block peer_notifier
;
236 struct notifier_block newpeer_notifier
;
237 struct notifier_list notifier_list
;
238 struct nhrp_reqid eventid
;
239 struct thread
*t_timeout
;
240 struct thread
*t_auth
;
243 enum nhrp_cache_type type
;
244 union sockunion remote_nbma_natoa
;
245 union sockunion remote_nbma_claimed
;
246 struct nhrp_peer
*peer
;
253 struct nhrp_shortcut
{
255 union sockunion addr
;
257 struct nhrp_reqid reqid
;
258 struct thread
*t_timer
;
260 enum nhrp_cache_type type
;
261 unsigned int holding_time
;
262 unsigned route_installed
: 1;
263 unsigned expiring
: 1;
265 struct nhrp_cache
*cache
;
266 struct notifier_block cache_notifier
;
269 PREDECL_DLIST(nhrp_nhslist
);
270 PREDECL_DLIST(nhrp_mcastlist
);
271 PREDECL_DLIST(nhrp_reglist
);
274 struct interface
*ifp
;
275 struct nhrp_nhslist_item nhslist_entry
;
279 union sockunion proto_addr
;
280 const char *nbma_fqdn
; /* IP-address or FQDN */
282 struct thread
*t_resolve
;
283 struct resolver_query dns_resolve
;
284 struct nhrp_reglist_head reglist_head
;
287 DECLARE_DLIST(nhrp_nhslist
, struct nhrp_nhs
, nhslist_entry
);
289 struct nhrp_multicast
{
290 struct interface
*ifp
;
291 struct nhrp_mcastlist_item mcastlist_entry
;
293 union sockunion nbma_addr
; /* IP-address */
296 DECLARE_DLIST(nhrp_mcastlist
, struct nhrp_multicast
, mcastlist_entry
);
298 struct nhrp_registration
{
299 struct nhrp_reglist_item reglist_entry
;
300 struct thread
*t_register
;
301 struct nhrp_nhs
*nhs
;
302 struct nhrp_reqid reqid
;
303 unsigned int timeout
;
305 union sockunion proto_addr
;
306 struct nhrp_peer
*peer
;
307 struct notifier_block peer_notifier
;
310 DECLARE_DLIST(nhrp_reglist
, struct nhrp_registration
, reglist_entry
);
312 #define NHRP_IFF_SHORTCUT 0x0001
313 #define NHRP_IFF_REDIRECT 0x0002
314 #define NHRP_IFF_REG_NO_UNIQUE 0x0100
316 struct nhrp_interface
{
317 struct interface
*ifp
;
319 unsigned enabled
: 1;
321 char *ipsec_profile
, *ipsec_fallback_profile
, *source
;
322 union sockunion nbma
;
323 union sockunion nat_nbma
;
324 unsigned int link_idx
;
325 unsigned int link_vrf_id
;
329 struct hash
*peer_hash
;
330 struct hash
*cache_config_hash
;
331 struct hash
*cache_hash
;
333 struct notifier_list notifier_list
;
335 struct interface
*nbmaifp
;
336 struct notifier_block nbmanifp_notifier
;
338 struct nhrp_afi_data
{
340 unsigned short configured
: 1;
341 union sockunion addr
;
343 short configured_mtu
;
345 unsigned int holdtime
;
346 struct nhrp_nhslist_head nhslist_head
;
347 struct nhrp_mcastlist_head mcastlist_head
;
351 struct nhrp_gre_info
{
353 struct in_addr vtep_ip
; /* IFLA_GRE_LOCAL */
354 struct in_addr vtep_ip_remote
; /* IFLA_GRE_REMOTE */
357 ifindex_t ifindex_link
; /* Interface index of interface
363 extern struct zebra_privs_t nhrpd_privs
;
365 int sock_open_unix(const char *path
);
367 void nhrp_interface_init(void);
368 void nhrp_interface_update(struct interface
*ifp
);
369 void nhrp_interface_update_mtu(struct interface
*ifp
, afi_t afi
);
370 void nhrp_interface_update_nbma(struct interface
*ifp
,
371 struct nhrp_gre_info
*gre_info
);
373 int nhrp_interface_add(ZAPI_CALLBACK_ARGS
);
374 int nhrp_interface_delete(ZAPI_CALLBACK_ARGS
);
375 int nhrp_interface_up(ZAPI_CALLBACK_ARGS
);
376 int nhrp_interface_down(ZAPI_CALLBACK_ARGS
);
377 int nhrp_interface_address_add(ZAPI_CALLBACK_ARGS
);
378 int nhrp_interface_address_delete(ZAPI_CALLBACK_ARGS
);
379 int nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS
);
380 int nhrp_gre_update(ZAPI_CALLBACK_ARGS
);
382 void nhrp_interface_notify_add(struct interface
*ifp
, struct notifier_block
*n
,
384 void nhrp_interface_notify_del(struct interface
*ifp
, struct notifier_block
*n
);
385 void nhrp_interface_set_protection(struct interface
*ifp
, const char *profile
,
386 const char *fallback_profile
);
387 void nhrp_interface_set_source(struct interface
*ifp
, const char *ifname
);
388 extern int nhrp_ifp_create(struct interface
*ifp
);
389 extern int nhrp_ifp_up(struct interface
*ifp
);
390 extern int nhrp_ifp_down(struct interface
*ifp
);
391 extern int nhrp_ifp_destroy(struct interface
*ifp
);
393 int nhrp_nhs_add(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
,
394 const char *nbma_fqdn
);
395 int nhrp_nhs_del(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
,
396 const char *nbma_fqdn
);
397 int nhrp_nhs_free(struct nhrp_interface
*nifp
, afi_t afi
, struct nhrp_nhs
*nhs
);
398 void nhrp_nhs_terminate(void);
399 void nhrp_nhs_foreach(struct interface
*ifp
, afi_t afi
,
400 void (*cb
)(struct nhrp_nhs
*, struct nhrp_registration
*,
403 void nhrp_nhs_interface_del(struct interface
*ifp
);
405 int nhrp_multicast_add(struct interface
*ifp
, afi_t afi
,
406 union sockunion
*nbma_addr
);
407 int nhrp_multicast_del(struct interface
*ifp
, afi_t afi
,
408 union sockunion
*nbma_addr
);
409 void nhrp_multicast_interface_del(struct interface
*ifp
);
410 void nhrp_multicast_foreach(struct interface
*ifp
, afi_t afi
,
411 void (*cb
)(struct nhrp_multicast
*, void *),
413 void netlink_mcast_set_nflog_group(int nlgroup
);
415 void nhrp_route_update_nhrp(const struct prefix
*p
, struct interface
*ifp
);
416 void nhrp_route_announce(int add
, enum nhrp_cache_type type
,
417 const struct prefix
*p
, struct interface
*ifp
,
418 const union sockunion
*nexthop
, uint32_t mtu
);
419 int nhrp_route_read(ZAPI_CALLBACK_ARGS
);
420 int nhrp_route_get_nexthop(const union sockunion
*addr
, struct prefix
*p
,
421 union sockunion
*via
, struct interface
**ifp
);
422 enum nhrp_route_type
nhrp_route_address(struct interface
*in_ifp
,
423 union sockunion
*addr
, struct prefix
*p
,
424 struct nhrp_peer
**peer
);
426 void nhrp_config_init(void);
428 void nhrp_shortcut_init(void);
429 void nhrp_shortcut_terminate(void);
430 void nhrp_shortcut_initiate(union sockunion
*addr
);
431 void nhrp_shortcut_foreach(afi_t afi
,
432 void (*cb
)(struct nhrp_shortcut
*, void *),
434 void nhrp_shortcut_purge(struct nhrp_shortcut
*s
, int force
);
435 void nhrp_shortcut_prefix_change(const struct prefix
*p
, int deleted
);
437 void nhrp_cache_interface_del(struct interface
*ifp
);
438 void nhrp_cache_config_free(struct nhrp_cache_config
*c
);
439 struct nhrp_cache_config
*nhrp_cache_config_get(struct interface
*ifp
,
440 union sockunion
*remote_addr
,
442 struct nhrp_cache
*nhrp_cache_get(struct interface
*ifp
,
443 union sockunion
*remote_addr
, int create
);
444 void nhrp_cache_foreach(struct interface
*ifp
,
445 void (*cb
)(struct nhrp_cache
*, void *), void *ctx
);
446 void nhrp_cache_config_foreach(struct interface
*ifp
,
447 void (*cb
)(struct nhrp_cache_config
*, void *), void *ctx
);
448 void nhrp_cache_set_used(struct nhrp_cache
*, int);
449 int nhrp_cache_update_binding(struct nhrp_cache
*, enum nhrp_cache_type type
,
450 int holding_time
, struct nhrp_peer
*p
,
451 uint32_t mtu
, union sockunion
*nbma_natoa
,
452 union sockunion
*claimed_nbma
);
453 void nhrp_cache_notify_add(struct nhrp_cache
*c
, struct notifier_block
*,
455 void nhrp_cache_notify_del(struct nhrp_cache
*c
, struct notifier_block
*);
457 void nhrp_vc_init(void);
458 void nhrp_vc_terminate(void);
459 struct nhrp_vc
*nhrp_vc_get(const union sockunion
*src
,
460 const union sockunion
*dst
, int create
);
461 int nhrp_vc_ipsec_updown(uint32_t child_id
, struct nhrp_vc
*vc
);
462 void nhrp_vc_notify_add(struct nhrp_vc
*, struct notifier_block
*,
464 void nhrp_vc_notify_del(struct nhrp_vc
*, struct notifier_block
*);
465 void nhrp_vc_foreach(void (*cb
)(struct nhrp_vc
*, void *), void *ctx
);
466 void nhrp_vc_reset(void);
468 void vici_init(void);
469 void vici_terminate(void);
470 void vici_terminate_vc_by_profile_name(char *profile_name
);
471 void vici_terminate_vc_by_ike_id(unsigned int ike_id
);
472 void vici_request_vc(const char *profile
, union sockunion
*src
,
473 union sockunion
*dst
, int prio
);
475 extern const char *nhrp_event_socket_path
;
477 void evmgr_init(void);
478 void evmgr_terminate(void);
479 void evmgr_set_socket(const char *socket
);
480 void evmgr_notify(const char *name
, struct nhrp_cache
*c
,
481 void (*cb
)(struct nhrp_reqid
*, void *));
483 struct nhrp_packet_header
*nhrp_packet_push(struct zbuf
*zb
, uint8_t type
,
484 const union sockunion
*src_nbma
,
485 const union sockunion
*src_proto
,
486 const union sockunion
*dst_proto
);
487 void nhrp_packet_complete(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
);
488 uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu
, uint16_t len
);
490 struct nhrp_packet_header
*nhrp_packet_pull(struct zbuf
*zb
,
491 union sockunion
*src_nbma
,
492 union sockunion
*src_proto
,
493 union sockunion
*dst_proto
);
495 struct nhrp_cie_header
*nhrp_cie_push(struct zbuf
*zb
, uint8_t code
,
496 const union sockunion
*nbma
,
497 const union sockunion
*proto
);
498 struct nhrp_cie_header
*nhrp_cie_pull(struct zbuf
*zb
,
499 struct nhrp_packet_header
*hdr
,
500 union sockunion
*nbma
,
501 union sockunion
*proto
);
503 struct nhrp_extension_header
*
504 nhrp_ext_push(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
, uint16_t type
);
505 void nhrp_ext_complete(struct zbuf
*zb
, struct nhrp_extension_header
*ext
);
506 struct nhrp_extension_header
*nhrp_ext_pull(struct zbuf
*zb
,
507 struct zbuf
*payload
);
508 void nhrp_ext_request(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
,
510 int nhrp_ext_reply(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
,
511 struct interface
*ifp
, struct nhrp_extension_header
*ext
,
512 struct zbuf
*extpayload
);
514 uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
,
515 void (*cb
)(struct nhrp_reqid
*, void *));
516 void nhrp_reqid_free(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
);
517 struct nhrp_reqid
*nhrp_reqid_lookup(struct nhrp_reqid_pool
*, uint32_t reqid
);
519 int nhrp_packet_init(void);
521 void nhrp_peer_interface_del(struct interface
*ifp
);
522 struct nhrp_peer
*nhrp_peer_get(struct interface
*ifp
,
523 const union sockunion
*remote_nbma
);
524 struct nhrp_peer
*nhrp_peer_ref(struct nhrp_peer
*p
);
525 void nhrp_peer_unref(struct nhrp_peer
*p
);
526 int nhrp_peer_check(struct nhrp_peer
*p
, int establish
);
527 void nhrp_peer_notify_add(struct nhrp_peer
*p
, struct notifier_block
*,
529 void nhrp_peer_notify_del(struct nhrp_peer
*p
, struct notifier_block
*);
530 void nhrp_peer_recv(struct nhrp_peer
*p
, struct zbuf
*zb
);
531 void nhrp_peer_send(struct nhrp_peer
*p
, struct zbuf
*zb
);
532 void nhrp_peer_send_indication(struct interface
*ifp
, uint16_t, struct zbuf
*);
534 int nhrp_nhs_match_ip(union sockunion
*in_ip
, struct nhrp_interface
*nifp
);