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 PREDECL_DLIST(notifier_list
);
47 struct notifier_block
{
48 struct notifier_list_item notifier_entry
;
52 DECLARE_DLIST(notifier_list
, struct notifier_block
, notifier_entry
);
54 struct notifier_list
{
55 struct notifier_list_head head
;
58 #define NOTIFIER_LIST_INITIALIZER(l) \
60 .head = INIT_DLIST((l)->head) \
63 static inline void notifier_init(struct notifier_list
*l
)
65 notifier_list_init(&l
->head
);
68 static inline void notifier_add(struct notifier_block
*n
,
69 struct notifier_list
*l
, notifier_fn_t action
)
72 notifier_list_add_tail(&l
->head
, n
);
75 static inline void notifier_del(struct notifier_block
*n
,
76 struct notifier_list
*l
)
78 notifier_list_del(&l
->head
, n
);
81 static inline void notifier_call(struct notifier_list
*l
, int cmd
)
83 struct notifier_block
*n
;
85 frr_each_safe (notifier_list
, &l
->head
, n
)
89 static inline int notifier_active(struct notifier_list
*l
)
91 return notifier_list_count(&l
->head
) > 0;
94 extern struct hash
*nhrp_gre_list
;
96 void nhrp_zebra_init(void);
97 void nhrp_zebra_terminate(void);
98 void nhrp_send_zebra_configure_arp(struct interface
*ifp
, int family
);
99 void nhrp_send_zebra_nbr(union sockunion
*in
,
100 union sockunion
*out
,
101 struct interface
*ifp
);
103 void nhrp_send_zebra_gre_source_set(struct interface
*ifp
,
104 unsigned int link_idx
,
105 vrf_id_t link_vrf_id
);
107 extern int nhrp_send_zebra_gre_request(struct interface
*ifp
);
108 extern struct nhrp_gre_info
*nhrp_gre_info_alloc(struct nhrp_gre_info
*p
);
114 struct nhrp_interface
;
116 #define MAX_ID_LENGTH 64
117 #define MAX_CERT_LENGTH 2048
119 enum nhrp_notify_type
{
121 NOTIFY_INTERFACE_DOWN
,
122 NOTIFY_INTERFACE_CHANGED
,
123 NOTIFY_INTERFACE_ADDRESS_CHANGED
,
124 NOTIFY_INTERFACE_NBMA_CHANGED
,
125 NOTIFY_INTERFACE_MTU_CHANGED
,
126 NOTIFY_INTERFACE_IPSEC_CHANGED
,
128 NOTIFY_VC_IPSEC_CHANGED
,
129 NOTIFY_VC_IPSEC_UPDATE_NBMA
,
133 NOTIFY_PEER_IFCONFIG_CHANGED
,
134 NOTIFY_PEER_MTU_CHANGED
,
135 NOTIFY_PEER_NBMA_CHANGING
,
141 NOTIFY_CACHE_BINDING_CHANGE
,
145 struct notifier_list notifier_list
;
147 uint32_t ike_uniqueid
;
149 uint8_t abort_migration
;
151 struct nhrp_vc_peer
{
152 union sockunion nbma
;
153 char id
[MAX_ID_LENGTH
];
155 uint8_t cert
[MAX_CERT_LENGTH
];
159 enum nhrp_route_type
{
160 NHRP_ROUTE_BLACKHOLE
,
162 NHRP_ROUTE_NBMA_NEXTHOP
,
169 unsigned requested
: 1;
170 unsigned fallback_requested
: 1;
172 struct notifier_list notifier_list
;
173 struct interface
*ifp
;
175 struct thread
*t_fallback
;
176 struct notifier_block vc_notifier
, ifp_notifier
;
177 struct thread
*t_timer
;
180 struct nhrp_packet_parser
{
181 struct interface
*ifp
;
182 struct nhrp_afi_data
*if_ad
;
183 struct nhrp_peer
*peer
;
186 struct zbuf extensions
;
187 struct nhrp_packet_header
*hdr
;
188 enum nhrp_route_type route_type
;
189 struct prefix route_prefix
;
190 union sockunion src_nbma
, src_proto
, dst_proto
;
193 struct nhrp_reqid_pool
{
194 struct hash
*reqid_hash
;
195 uint32_t next_request_id
;
200 void (*cb
)(struct nhrp_reqid
*, void *);
203 extern struct nhrp_reqid_pool nhrp_packet_reqid
;
204 extern struct nhrp_reqid_pool nhrp_event_reqid
;
206 enum nhrp_cache_type
{
207 NHRP_CACHE_INVALID
= 0,
208 NHRP_CACHE_INCOMPLETE
,
218 extern const char *const nhrp_cache_type_str
[];
219 extern unsigned long nhrp_cache_counts
[NHRP_CACHE_NUM_TYPES
];
221 struct nhrp_cache_config
{
222 struct interface
*ifp
;
223 union sockunion remote_addr
;
224 enum nhrp_cache_type type
;
225 union sockunion nbma
;
229 struct interface
*ifp
;
230 union sockunion remote_addr
;
234 unsigned route_installed
: 1;
235 unsigned nhrp_route_installed
: 1;
237 struct notifier_block peer_notifier
;
238 struct notifier_block newpeer_notifier
;
239 struct notifier_list notifier_list
;
240 struct nhrp_reqid eventid
;
241 struct thread
*t_timeout
;
242 struct thread
*t_auth
;
245 enum nhrp_cache_type type
;
246 union sockunion remote_nbma_natoa
;
247 union sockunion remote_nbma_claimed
;
248 struct nhrp_peer
*peer
;
255 struct nhrp_shortcut
{
257 union sockunion addr
;
259 struct nhrp_reqid reqid
;
260 struct thread
*t_timer
;
262 enum nhrp_cache_type type
;
263 unsigned int holding_time
;
264 unsigned route_installed
: 1;
265 unsigned expiring
: 1;
267 struct nhrp_cache
*cache
;
268 struct notifier_block cache_notifier
;
271 PREDECL_DLIST(nhrp_nhslist
);
272 PREDECL_DLIST(nhrp_mcastlist
);
273 PREDECL_DLIST(nhrp_reglist
);
276 struct interface
*ifp
;
277 struct nhrp_nhslist_item nhslist_entry
;
281 union sockunion proto_addr
;
282 const char *nbma_fqdn
; /* IP-address or FQDN */
284 struct thread
*t_resolve
;
285 struct resolver_query dns_resolve
;
286 struct nhrp_reglist_head reglist_head
;
289 DECLARE_DLIST(nhrp_nhslist
, struct nhrp_nhs
, nhslist_entry
);
291 struct nhrp_multicast
{
292 struct interface
*ifp
;
293 struct nhrp_mcastlist_item mcastlist_entry
;
295 union sockunion nbma_addr
; /* IP-address */
298 DECLARE_DLIST(nhrp_mcastlist
, struct nhrp_multicast
, mcastlist_entry
);
300 struct nhrp_registration
{
301 struct nhrp_reglist_item reglist_entry
;
302 struct thread
*t_register
;
303 struct nhrp_nhs
*nhs
;
304 struct nhrp_reqid reqid
;
305 unsigned int timeout
;
307 union sockunion proto_addr
;
308 struct nhrp_peer
*peer
;
309 struct notifier_block peer_notifier
;
312 DECLARE_DLIST(nhrp_reglist
, struct nhrp_registration
, reglist_entry
);
314 #define NHRP_IFF_SHORTCUT 0x0001
315 #define NHRP_IFF_REDIRECT 0x0002
316 #define NHRP_IFF_REG_NO_UNIQUE 0x0100
318 struct nhrp_interface
{
319 struct interface
*ifp
;
321 unsigned enabled
: 1;
323 char *ipsec_profile
, *ipsec_fallback_profile
, *source
;
324 union sockunion nbma
;
325 union sockunion nat_nbma
;
326 unsigned int link_idx
;
327 unsigned int link_vrf_id
;
331 struct hash
*peer_hash
;
332 struct hash
*cache_config_hash
;
333 struct hash
*cache_hash
;
335 struct notifier_list notifier_list
;
337 struct interface
*nbmaifp
;
338 struct notifier_block nbmanifp_notifier
;
340 struct nhrp_afi_data
{
342 unsigned short configured
: 1;
343 union sockunion addr
;
345 short configured_mtu
;
347 unsigned int holdtime
;
348 struct nhrp_nhslist_head nhslist_head
;
349 struct nhrp_mcastlist_head mcastlist_head
;
353 struct nhrp_gre_info
{
355 struct in_addr vtep_ip
; /* IFLA_GRE_LOCAL */
356 struct in_addr vtep_ip_remote
; /* IFLA_GRE_REMOTE */
359 ifindex_t ifindex_link
; /* Interface index of interface
365 extern struct zebra_privs_t nhrpd_privs
;
367 int sock_open_unix(const char *path
);
369 void nhrp_interface_init(void);
370 void nhrp_interface_update(struct interface
*ifp
);
371 void nhrp_interface_update_mtu(struct interface
*ifp
, afi_t afi
);
372 void nhrp_interface_update_nbma(struct interface
*ifp
,
373 struct nhrp_gre_info
*gre_info
);
375 int nhrp_interface_add(ZAPI_CALLBACK_ARGS
);
376 int nhrp_interface_delete(ZAPI_CALLBACK_ARGS
);
377 int nhrp_interface_up(ZAPI_CALLBACK_ARGS
);
378 int nhrp_interface_down(ZAPI_CALLBACK_ARGS
);
379 int nhrp_interface_address_add(ZAPI_CALLBACK_ARGS
);
380 int nhrp_interface_address_delete(ZAPI_CALLBACK_ARGS
);
381 void nhrp_neighbor_operation(ZAPI_CALLBACK_ARGS
);
382 void nhrp_gre_update(ZAPI_CALLBACK_ARGS
);
384 void nhrp_interface_notify_add(struct interface
*ifp
, struct notifier_block
*n
,
386 void nhrp_interface_notify_del(struct interface
*ifp
, struct notifier_block
*n
);
387 void nhrp_interface_set_protection(struct interface
*ifp
, const char *profile
,
388 const char *fallback_profile
);
389 void nhrp_interface_set_source(struct interface
*ifp
, const char *ifname
);
390 extern int nhrp_ifp_create(struct interface
*ifp
);
391 extern int nhrp_ifp_up(struct interface
*ifp
);
392 extern int nhrp_ifp_down(struct interface
*ifp
);
393 extern int nhrp_ifp_destroy(struct interface
*ifp
);
395 int nhrp_nhs_add(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
,
396 const char *nbma_fqdn
);
397 int nhrp_nhs_del(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
,
398 const char *nbma_fqdn
);
399 int nhrp_nhs_free(struct nhrp_interface
*nifp
, afi_t afi
, struct nhrp_nhs
*nhs
);
400 void nhrp_nhs_terminate(void);
401 void nhrp_nhs_foreach(struct interface
*ifp
, afi_t afi
,
402 void (*cb
)(struct nhrp_nhs
*, struct nhrp_registration
*,
405 void nhrp_nhs_interface_del(struct interface
*ifp
);
407 int nhrp_multicast_add(struct interface
*ifp
, afi_t afi
,
408 union sockunion
*nbma_addr
);
409 int nhrp_multicast_del(struct interface
*ifp
, afi_t afi
,
410 union sockunion
*nbma_addr
);
411 void nhrp_multicast_interface_del(struct interface
*ifp
);
412 void nhrp_multicast_foreach(struct interface
*ifp
, afi_t afi
,
413 void (*cb
)(struct nhrp_multicast
*, void *),
415 void netlink_mcast_set_nflog_group(int nlgroup
);
417 void nhrp_route_update_nhrp(const struct prefix
*p
, struct interface
*ifp
);
418 void nhrp_route_announce(int add
, enum nhrp_cache_type type
,
419 const struct prefix
*p
, struct interface
*ifp
,
420 const union sockunion
*nexthop
, uint32_t mtu
);
421 int nhrp_route_read(ZAPI_CALLBACK_ARGS
);
422 int nhrp_route_get_nexthop(const union sockunion
*addr
, struct prefix
*p
,
423 union sockunion
*via
, struct interface
**ifp
);
424 enum nhrp_route_type
nhrp_route_address(struct interface
*in_ifp
,
425 union sockunion
*addr
, struct prefix
*p
,
426 struct nhrp_peer
**peer
);
428 void nhrp_config_init(void);
430 void nhrp_shortcut_init(void);
431 void nhrp_shortcut_terminate(void);
432 void nhrp_shortcut_initiate(union sockunion
*addr
);
433 void nhrp_shortcut_foreach(afi_t afi
,
434 void (*cb
)(struct nhrp_shortcut
*, void *),
436 void nhrp_shortcut_purge(struct nhrp_shortcut
*s
, int force
);
437 void nhrp_shortcut_prefix_change(const struct prefix
*p
, int deleted
);
439 void nhrp_cache_interface_del(struct interface
*ifp
);
440 void nhrp_cache_config_free(struct nhrp_cache_config
*c
);
441 struct nhrp_cache_config
*nhrp_cache_config_get(struct interface
*ifp
,
442 union sockunion
*remote_addr
,
444 struct nhrp_cache
*nhrp_cache_get(struct interface
*ifp
,
445 union sockunion
*remote_addr
, int create
);
446 void nhrp_cache_foreach(struct interface
*ifp
,
447 void (*cb
)(struct nhrp_cache
*, void *), void *ctx
);
448 void nhrp_cache_config_foreach(struct interface
*ifp
,
449 void (*cb
)(struct nhrp_cache_config
*, void *), void *ctx
);
450 void nhrp_cache_set_used(struct nhrp_cache
*, int);
451 int nhrp_cache_update_binding(struct nhrp_cache
*, enum nhrp_cache_type type
,
452 int holding_time
, struct nhrp_peer
*p
,
453 uint32_t mtu
, union sockunion
*nbma_natoa
,
454 union sockunion
*claimed_nbma
);
455 void nhrp_cache_notify_add(struct nhrp_cache
*c
, struct notifier_block
*,
457 void nhrp_cache_notify_del(struct nhrp_cache
*c
, struct notifier_block
*);
459 void nhrp_vc_init(void);
460 void nhrp_vc_terminate(void);
461 struct nhrp_vc
*nhrp_vc_get(const union sockunion
*src
,
462 const union sockunion
*dst
, int create
);
463 int nhrp_vc_ipsec_updown(uint32_t child_id
, struct nhrp_vc
*vc
);
464 void nhrp_vc_notify_add(struct nhrp_vc
*, struct notifier_block
*,
466 void nhrp_vc_notify_del(struct nhrp_vc
*, struct notifier_block
*);
467 void nhrp_vc_foreach(void (*cb
)(struct nhrp_vc
*, void *), void *ctx
);
468 void nhrp_vc_reset(void);
470 void vici_init(void);
471 void vici_terminate(void);
472 void vici_terminate_vc_by_profile_name(char *profile_name
);
473 void vici_terminate_vc_by_ike_id(unsigned int ike_id
);
474 void vici_request_vc(const char *profile
, union sockunion
*src
,
475 union sockunion
*dst
, int prio
);
477 extern const char *nhrp_event_socket_path
;
479 void evmgr_init(void);
480 void evmgr_terminate(void);
481 void evmgr_set_socket(const char *socket
);
482 void evmgr_notify(const char *name
, struct nhrp_cache
*c
,
483 void (*cb
)(struct nhrp_reqid
*, void *));
485 struct nhrp_packet_header
*nhrp_packet_push(struct zbuf
*zb
, uint8_t type
,
486 const union sockunion
*src_nbma
,
487 const union sockunion
*src_proto
,
488 const union sockunion
*dst_proto
);
489 void nhrp_packet_complete(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
);
490 uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu
, uint16_t len
);
492 struct nhrp_packet_header
*nhrp_packet_pull(struct zbuf
*zb
,
493 union sockunion
*src_nbma
,
494 union sockunion
*src_proto
,
495 union sockunion
*dst_proto
);
497 struct nhrp_cie_header
*nhrp_cie_push(struct zbuf
*zb
, uint8_t code
,
498 const union sockunion
*nbma
,
499 const union sockunion
*proto
);
500 struct nhrp_cie_header
*nhrp_cie_pull(struct zbuf
*zb
,
501 struct nhrp_packet_header
*hdr
,
502 union sockunion
*nbma
,
503 union sockunion
*proto
);
505 struct nhrp_extension_header
*
506 nhrp_ext_push(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
, uint16_t type
);
507 void nhrp_ext_complete(struct zbuf
*zb
, struct nhrp_extension_header
*ext
);
508 struct nhrp_extension_header
*nhrp_ext_pull(struct zbuf
*zb
,
509 struct zbuf
*payload
);
510 void nhrp_ext_request(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
,
512 int nhrp_ext_reply(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
,
513 struct interface
*ifp
, struct nhrp_extension_header
*ext
,
514 struct zbuf
*extpayload
);
516 uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
,
517 void (*cb
)(struct nhrp_reqid
*, void *));
518 void nhrp_reqid_free(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
);
519 struct nhrp_reqid
*nhrp_reqid_lookup(struct nhrp_reqid_pool
*, uint32_t reqid
);
521 int nhrp_packet_init(void);
523 void nhrp_peer_interface_del(struct interface
*ifp
);
524 struct nhrp_peer
*nhrp_peer_get(struct interface
*ifp
,
525 const union sockunion
*remote_nbma
);
526 struct nhrp_peer
*nhrp_peer_ref(struct nhrp_peer
*p
);
527 void nhrp_peer_unref(struct nhrp_peer
*p
);
528 int nhrp_peer_check(struct nhrp_peer
*p
, int establish
);
529 void nhrp_peer_notify_add(struct nhrp_peer
*p
, struct notifier_block
*,
531 void nhrp_peer_notify_del(struct nhrp_peer
*p
, struct notifier_block
*);
532 void nhrp_peer_recv(struct nhrp_peer
*p
, struct zbuf
*zb
);
533 void nhrp_peer_send(struct nhrp_peer
*p
, struct zbuf
*zb
);
534 void nhrp_peer_send_indication(struct interface
*ifp
, uint16_t, struct zbuf
*);
536 int nhrp_nhs_match_ip(union sockunion
*in_ip
, struct nhrp_interface
*nifp
);