1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* NHRP daemon internal structures and function prototypes
3 * Copyright (c) 2014-2015 Timo Teräs
15 DECLARE_MGROUP(NHRPD
);
17 #define NHRPD_DEFAULT_HOLDTIME 7200
19 #define NHRP_VTY_PORT 2610
20 #define NHRP_DEFAULT_CONFIG "nhrpd.conf"
22 extern struct thread_master
*master
;
27 NHRP_ERR_UNSUPPORTED_INTERFACE
,
28 NHRP_ERR_NHRP_NOT_ENABLED
,
29 NHRP_ERR_ENTRY_EXISTS
,
30 NHRP_ERR_ENTRY_NOT_FOUND
,
31 NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH
,
33 #define NHRP_ERR_MAX (__NHRP_ERR_MAX - 1)
35 struct notifier_block
;
37 typedef void (*notifier_fn_t
)(struct notifier_block
*, unsigned long);
39 PREDECL_DLIST(notifier_list
);
41 struct notifier_block
{
42 struct notifier_list_item notifier_entry
;
46 DECLARE_DLIST(notifier_list
, struct notifier_block
, notifier_entry
);
48 struct notifier_list
{
49 struct notifier_list_head head
;
52 #define NOTIFIER_LIST_INITIALIZER(l) \
54 .head = INIT_DLIST((l)->head) \
57 static inline void notifier_init(struct notifier_list
*l
)
59 notifier_list_init(&l
->head
);
62 static inline void notifier_add(struct notifier_block
*n
,
63 struct notifier_list
*l
, notifier_fn_t action
)
66 notifier_list_add_tail(&l
->head
, n
);
69 static inline void notifier_del(struct notifier_block
*n
,
70 struct notifier_list
*l
)
72 notifier_list_del(&l
->head
, n
);
75 static inline void notifier_call(struct notifier_list
*l
, int cmd
)
77 struct notifier_block
*n
;
79 frr_each_safe (notifier_list
, &l
->head
, n
)
83 static inline int notifier_active(struct notifier_list
*l
)
85 return notifier_list_count(&l
->head
) > 0;
88 extern struct hash
*nhrp_gre_list
;
90 void nhrp_zebra_init(void);
91 void nhrp_zebra_terminate(void);
92 void nhrp_send_zebra_configure_arp(struct interface
*ifp
, int family
);
93 void nhrp_send_zebra_nbr(union sockunion
*in
,
95 struct interface
*ifp
);
97 void nhrp_send_zebra_gre_source_set(struct interface
*ifp
,
98 unsigned int link_idx
,
99 vrf_id_t link_vrf_id
);
101 extern int nhrp_send_zebra_gre_request(struct interface
*ifp
);
102 extern struct nhrp_gre_info
*nhrp_gre_info_alloc(struct nhrp_gre_info
*p
);
108 struct nhrp_interface
;
110 #define MAX_ID_LENGTH 64
111 #define MAX_CERT_LENGTH 2048
113 enum nhrp_notify_type
{
115 NOTIFY_INTERFACE_DOWN
,
116 NOTIFY_INTERFACE_CHANGED
,
117 NOTIFY_INTERFACE_ADDRESS_CHANGED
,
118 NOTIFY_INTERFACE_NBMA_CHANGED
,
119 NOTIFY_INTERFACE_MTU_CHANGED
,
120 NOTIFY_INTERFACE_IPSEC_CHANGED
,
122 NOTIFY_VC_IPSEC_CHANGED
,
123 NOTIFY_VC_IPSEC_UPDATE_NBMA
,
127 NOTIFY_PEER_IFCONFIG_CHANGED
,
128 NOTIFY_PEER_MTU_CHANGED
,
129 NOTIFY_PEER_NBMA_CHANGING
,
135 NOTIFY_CACHE_BINDING_CHANGE
,
139 struct notifier_list notifier_list
;
141 uint32_t ike_uniqueid
;
143 uint8_t abort_migration
;
145 struct nhrp_vc_peer
{
146 union sockunion nbma
;
147 char id
[MAX_ID_LENGTH
];
149 uint8_t cert
[MAX_CERT_LENGTH
];
153 enum nhrp_route_type
{
154 NHRP_ROUTE_BLACKHOLE
,
156 NHRP_ROUTE_NBMA_NEXTHOP
,
163 unsigned requested
: 1;
164 unsigned fallback_requested
: 1;
166 struct notifier_list notifier_list
;
167 struct interface
*ifp
;
169 struct thread
*t_fallback
;
170 struct notifier_block vc_notifier
, ifp_notifier
;
171 struct thread
*t_timer
;
174 struct nhrp_packet_parser
{
175 struct interface
*ifp
;
176 struct nhrp_afi_data
*if_ad
;
177 struct nhrp_peer
*peer
;
180 struct zbuf extensions
;
181 struct nhrp_packet_header
*hdr
;
182 enum nhrp_route_type route_type
;
183 struct prefix route_prefix
;
184 union sockunion src_nbma
, src_proto
, dst_proto
;
187 struct nhrp_reqid_pool
{
188 struct hash
*reqid_hash
;
189 uint32_t next_request_id
;
194 void (*cb
)(struct nhrp_reqid
*, void *);
197 extern struct nhrp_reqid_pool nhrp_packet_reqid
;
198 extern struct nhrp_reqid_pool nhrp_event_reqid
;
200 enum nhrp_cache_type
{
201 NHRP_CACHE_INVALID
= 0,
202 NHRP_CACHE_INCOMPLETE
,
212 extern const char *const nhrp_cache_type_str
[];
213 extern unsigned long nhrp_cache_counts
[NHRP_CACHE_NUM_TYPES
];
215 struct nhrp_cache_config
{
216 struct interface
*ifp
;
217 union sockunion remote_addr
;
218 enum nhrp_cache_type type
;
219 union sockunion nbma
;
223 struct interface
*ifp
;
224 union sockunion remote_addr
;
228 unsigned route_installed
: 1;
229 unsigned nhrp_route_installed
: 1;
231 struct notifier_block peer_notifier
;
232 struct notifier_block newpeer_notifier
;
233 struct notifier_list notifier_list
;
234 struct nhrp_reqid eventid
;
235 struct thread
*t_timeout
;
236 struct thread
*t_auth
;
239 enum nhrp_cache_type type
;
240 union sockunion remote_nbma_natoa
;
241 union sockunion remote_nbma_claimed
;
242 struct nhrp_peer
*peer
;
249 struct nhrp_shortcut
{
251 union sockunion addr
;
253 struct nhrp_reqid reqid
;
254 struct thread
*t_timer
;
256 enum nhrp_cache_type type
;
257 unsigned int holding_time
;
258 unsigned route_installed
: 1;
259 unsigned expiring
: 1;
261 struct nhrp_cache
*cache
;
262 struct notifier_block cache_notifier
;
265 PREDECL_DLIST(nhrp_nhslist
);
266 PREDECL_DLIST(nhrp_mcastlist
);
267 PREDECL_DLIST(nhrp_reglist
);
270 struct interface
*ifp
;
271 struct nhrp_nhslist_item nhslist_entry
;
275 union sockunion proto_addr
;
276 const char *nbma_fqdn
; /* IP-address or FQDN */
278 struct thread
*t_resolve
;
279 struct resolver_query dns_resolve
;
280 struct nhrp_reglist_head reglist_head
;
283 DECLARE_DLIST(nhrp_nhslist
, struct nhrp_nhs
, nhslist_entry
);
285 struct nhrp_multicast
{
286 struct interface
*ifp
;
287 struct nhrp_mcastlist_item mcastlist_entry
;
289 union sockunion nbma_addr
; /* IP-address */
292 DECLARE_DLIST(nhrp_mcastlist
, struct nhrp_multicast
, mcastlist_entry
);
294 struct nhrp_registration
{
295 struct nhrp_reglist_item reglist_entry
;
296 struct thread
*t_register
;
297 struct nhrp_nhs
*nhs
;
298 struct nhrp_reqid reqid
;
299 unsigned int timeout
;
301 union sockunion proto_addr
;
302 struct nhrp_peer
*peer
;
303 struct notifier_block peer_notifier
;
306 DECLARE_DLIST(nhrp_reglist
, struct nhrp_registration
, reglist_entry
);
308 #define NHRP_IFF_SHORTCUT 0x0001
309 #define NHRP_IFF_REDIRECT 0x0002
310 #define NHRP_IFF_REG_NO_UNIQUE 0x0100
312 struct nhrp_interface
{
313 struct interface
*ifp
;
315 unsigned enabled
: 1;
317 char *ipsec_profile
, *ipsec_fallback_profile
, *source
;
318 union sockunion nbma
;
319 union sockunion nat_nbma
;
320 unsigned int link_idx
;
321 unsigned int link_vrf_id
;
325 struct hash
*peer_hash
;
326 struct hash
*cache_config_hash
;
327 struct hash
*cache_hash
;
329 struct notifier_list notifier_list
;
331 struct interface
*nbmaifp
;
332 struct notifier_block nbmanifp_notifier
;
334 struct nhrp_afi_data
{
336 unsigned short configured
: 1;
337 union sockunion addr
;
339 short configured_mtu
;
341 unsigned int holdtime
;
342 struct nhrp_nhslist_head nhslist_head
;
343 struct nhrp_mcastlist_head mcastlist_head
;
347 struct nhrp_gre_info
{
349 struct in_addr vtep_ip
; /* IFLA_GRE_LOCAL */
350 struct in_addr vtep_ip_remote
; /* IFLA_GRE_REMOTE */
353 ifindex_t ifindex_link
; /* Interface index of interface
359 extern struct zebra_privs_t nhrpd_privs
;
361 int sock_open_unix(const char *path
);
363 void nhrp_interface_init(void);
364 void nhrp_interface_update(struct interface
*ifp
);
365 void nhrp_interface_update_mtu(struct interface
*ifp
, afi_t afi
);
366 void nhrp_interface_update_nbma(struct interface
*ifp
,
367 struct nhrp_gre_info
*gre_info
);
369 int nhrp_interface_add(ZAPI_CALLBACK_ARGS
);
370 int nhrp_interface_delete(ZAPI_CALLBACK_ARGS
);
371 int nhrp_interface_up(ZAPI_CALLBACK_ARGS
);
372 int nhrp_interface_down(ZAPI_CALLBACK_ARGS
);
373 int nhrp_interface_address_add(ZAPI_CALLBACK_ARGS
);
374 int nhrp_interface_address_delete(ZAPI_CALLBACK_ARGS
);
375 int nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS
);
376 int nhrp_gre_update(ZAPI_CALLBACK_ARGS
);
378 void nhrp_interface_notify_add(struct interface
*ifp
, struct notifier_block
*n
,
380 void nhrp_interface_notify_del(struct interface
*ifp
, struct notifier_block
*n
);
381 void nhrp_interface_set_protection(struct interface
*ifp
, const char *profile
,
382 const char *fallback_profile
);
383 void nhrp_interface_set_source(struct interface
*ifp
, const char *ifname
);
384 extern int nhrp_ifp_create(struct interface
*ifp
);
385 extern int nhrp_ifp_up(struct interface
*ifp
);
386 extern int nhrp_ifp_down(struct interface
*ifp
);
387 extern int nhrp_ifp_destroy(struct interface
*ifp
);
389 int nhrp_nhs_add(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
,
390 const char *nbma_fqdn
);
391 int nhrp_nhs_del(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
,
392 const char *nbma_fqdn
);
393 int nhrp_nhs_free(struct nhrp_interface
*nifp
, afi_t afi
, struct nhrp_nhs
*nhs
);
394 void nhrp_nhs_terminate(void);
395 void nhrp_nhs_foreach(struct interface
*ifp
, afi_t afi
,
396 void (*cb
)(struct nhrp_nhs
*, struct nhrp_registration
*,
399 void nhrp_nhs_interface_del(struct interface
*ifp
);
401 int nhrp_multicast_add(struct interface
*ifp
, afi_t afi
,
402 union sockunion
*nbma_addr
);
403 int nhrp_multicast_del(struct interface
*ifp
, afi_t afi
,
404 union sockunion
*nbma_addr
);
405 void nhrp_multicast_interface_del(struct interface
*ifp
);
406 void nhrp_multicast_foreach(struct interface
*ifp
, afi_t afi
,
407 void (*cb
)(struct nhrp_multicast
*, void *),
409 void netlink_mcast_set_nflog_group(int nlgroup
);
411 void nhrp_route_update_nhrp(const struct prefix
*p
, struct interface
*ifp
);
412 void nhrp_route_announce(int add
, enum nhrp_cache_type type
,
413 const struct prefix
*p
, struct interface
*ifp
,
414 const union sockunion
*nexthop
, uint32_t mtu
);
415 int nhrp_route_read(ZAPI_CALLBACK_ARGS
);
416 int nhrp_route_get_nexthop(const union sockunion
*addr
, struct prefix
*p
,
417 union sockunion
*via
, struct interface
**ifp
);
418 enum nhrp_route_type
nhrp_route_address(struct interface
*in_ifp
,
419 union sockunion
*addr
, struct prefix
*p
,
420 struct nhrp_peer
**peer
);
422 void nhrp_config_init(void);
424 void nhrp_shortcut_init(void);
425 void nhrp_shortcut_terminate(void);
426 void nhrp_shortcut_initiate(union sockunion
*addr
);
427 void nhrp_shortcut_foreach(afi_t afi
,
428 void (*cb
)(struct nhrp_shortcut
*, void *),
430 void nhrp_shortcut_purge(struct nhrp_shortcut
*s
, int force
);
431 void nhrp_shortcut_prefix_change(const struct prefix
*p
, int deleted
);
433 void nhrp_cache_interface_del(struct interface
*ifp
);
434 void nhrp_cache_config_free(struct nhrp_cache_config
*c
);
435 struct nhrp_cache_config
*nhrp_cache_config_get(struct interface
*ifp
,
436 union sockunion
*remote_addr
,
438 struct nhrp_cache
*nhrp_cache_get(struct interface
*ifp
,
439 union sockunion
*remote_addr
, int create
);
440 void nhrp_cache_foreach(struct interface
*ifp
,
441 void (*cb
)(struct nhrp_cache
*, void *), void *ctx
);
442 void nhrp_cache_config_foreach(struct interface
*ifp
,
443 void (*cb
)(struct nhrp_cache_config
*, void *), void *ctx
);
444 void nhrp_cache_set_used(struct nhrp_cache
*, int);
445 int nhrp_cache_update_binding(struct nhrp_cache
*, enum nhrp_cache_type type
,
446 int holding_time
, struct nhrp_peer
*p
,
447 uint32_t mtu
, union sockunion
*nbma_natoa
,
448 union sockunion
*claimed_nbma
);
449 void nhrp_cache_notify_add(struct nhrp_cache
*c
, struct notifier_block
*,
451 void nhrp_cache_notify_del(struct nhrp_cache
*c
, struct notifier_block
*);
453 void nhrp_vc_init(void);
454 void nhrp_vc_terminate(void);
455 struct nhrp_vc
*nhrp_vc_get(const union sockunion
*src
,
456 const union sockunion
*dst
, int create
);
457 int nhrp_vc_ipsec_updown(uint32_t child_id
, struct nhrp_vc
*vc
);
458 void nhrp_vc_notify_add(struct nhrp_vc
*, struct notifier_block
*,
460 void nhrp_vc_notify_del(struct nhrp_vc
*, struct notifier_block
*);
461 void nhrp_vc_foreach(void (*cb
)(struct nhrp_vc
*, void *), void *ctx
);
462 void nhrp_vc_reset(void);
464 void vici_init(void);
465 void vici_terminate(void);
466 void vici_terminate_vc_by_profile_name(char *profile_name
);
467 void vici_terminate_vc_by_ike_id(unsigned int ike_id
);
468 void vici_request_vc(const char *profile
, union sockunion
*src
,
469 union sockunion
*dst
, int prio
);
471 extern const char *nhrp_event_socket_path
;
473 void evmgr_init(void);
474 void evmgr_terminate(void);
475 void evmgr_set_socket(const char *socket
);
476 void evmgr_notify(const char *name
, struct nhrp_cache
*c
,
477 void (*cb
)(struct nhrp_reqid
*, void *));
479 struct nhrp_packet_header
*nhrp_packet_push(struct zbuf
*zb
, uint8_t type
,
480 const union sockunion
*src_nbma
,
481 const union sockunion
*src_proto
,
482 const union sockunion
*dst_proto
);
483 void nhrp_packet_complete(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
);
484 uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu
, uint16_t len
);
486 struct nhrp_packet_header
*nhrp_packet_pull(struct zbuf
*zb
,
487 union sockunion
*src_nbma
,
488 union sockunion
*src_proto
,
489 union sockunion
*dst_proto
);
491 struct nhrp_cie_header
*nhrp_cie_push(struct zbuf
*zb
, uint8_t code
,
492 const union sockunion
*nbma
,
493 const union sockunion
*proto
);
494 struct nhrp_cie_header
*nhrp_cie_pull(struct zbuf
*zb
,
495 struct nhrp_packet_header
*hdr
,
496 union sockunion
*nbma
,
497 union sockunion
*proto
);
499 struct nhrp_extension_header
*
500 nhrp_ext_push(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
, uint16_t type
);
501 void nhrp_ext_complete(struct zbuf
*zb
, struct nhrp_extension_header
*ext
);
502 struct nhrp_extension_header
*nhrp_ext_pull(struct zbuf
*zb
,
503 struct zbuf
*payload
);
504 void nhrp_ext_request(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
,
506 int nhrp_ext_reply(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
,
507 struct interface
*ifp
, struct nhrp_extension_header
*ext
,
508 struct zbuf
*extpayload
);
510 uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
,
511 void (*cb
)(struct nhrp_reqid
*, void *));
512 void nhrp_reqid_free(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
);
513 struct nhrp_reqid
*nhrp_reqid_lookup(struct nhrp_reqid_pool
*, uint32_t reqid
);
515 int nhrp_packet_init(void);
517 void nhrp_peer_interface_del(struct interface
*ifp
);
518 struct nhrp_peer
*nhrp_peer_get(struct interface
*ifp
,
519 const union sockunion
*remote_nbma
);
520 struct nhrp_peer
*nhrp_peer_ref(struct nhrp_peer
*p
);
521 void nhrp_peer_unref(struct nhrp_peer
*p
);
522 int nhrp_peer_check(struct nhrp_peer
*p
, int establish
);
523 void nhrp_peer_notify_add(struct nhrp_peer
*p
, struct notifier_block
*,
525 void nhrp_peer_notify_del(struct nhrp_peer
*p
, struct notifier_block
*);
526 void nhrp_peer_recv(struct nhrp_peer
*p
, struct zbuf
*zb
);
527 void nhrp_peer_send(struct nhrp_peer
*p
, struct zbuf
*zb
);
528 void nhrp_peer_send_indication(struct interface
*ifp
, uint16_t, struct zbuf
*);
530 int nhrp_nhs_match_ip(union sockunion
*in_ip
, struct nhrp_interface
*nifp
);