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 struct notifier_block
;
42 typedef void (*notifier_fn_t
)(struct notifier_block
*, unsigned long);
44 struct notifier_block
{
45 struct list_head notifier_entry
;
49 struct notifier_list
{
50 struct list_head notifier_head
;
53 #define NOTIFIER_LIST_INITIALIZER(l) \
54 { .notifier_head = LIST_INITIALIZER((l)->notifier_head) }
56 static inline void notifier_init(struct notifier_list
*l
)
58 list_init(&l
->notifier_head
);
61 static inline void notifier_add(struct notifier_block
*n
, struct notifier_list
*l
, notifier_fn_t action
)
64 list_add_tail(&n
->notifier_entry
, &l
->notifier_head
);
67 static inline void notifier_del(struct notifier_block
*n
)
69 list_del(&n
->notifier_entry
);
72 static inline void notifier_call(struct notifier_list
*l
, int cmd
)
74 struct notifier_block
*n
, *nn
;
75 list_for_each_entry_safe(n
, nn
, &l
->notifier_head
, notifier_entry
)
79 static inline int notifier_active(struct notifier_list
*l
)
81 return !list_empty(&l
->notifier_head
);
84 struct resolver_query
{
85 void (*callback
)(struct resolver_query
*, int n
, union sockunion
*);
88 void resolver_init(void);
89 void resolver_resolve(struct resolver_query
*query
, int af
, const char *hostname
, void (*cb
)(struct resolver_query
*, int, union sockunion
*));
91 void nhrp_zebra_init(void);
92 void nhrp_zebra_terminate(void);
98 struct nhrp_interface
;
100 #define MAX_ID_LENGTH 64
101 #define MAX_CERT_LENGTH 2048
103 enum nhrp_notify_type
{
105 NOTIFY_INTERFACE_DOWN
,
106 NOTIFY_INTERFACE_CHANGED
,
107 NOTIFY_INTERFACE_ADDRESS_CHANGED
,
108 NOTIFY_INTERFACE_NBMA_CHANGED
,
109 NOTIFY_INTERFACE_MTU_CHANGED
,
111 NOTIFY_VC_IPSEC_CHANGED
,
112 NOTIFY_VC_IPSEC_UPDATE_NBMA
,
116 NOTIFY_PEER_IFCONFIG_CHANGED
,
117 NOTIFY_PEER_MTU_CHANGED
,
118 NOTIFY_PEER_NBMA_CHANGING
,
124 NOTIFY_CACHE_BINDING_CHANGE
,
128 struct notifier_list notifier_list
;
131 uint8_t abort_migration
;
133 struct nhrp_vc_peer
{
134 union sockunion nbma
;
135 char id
[MAX_ID_LENGTH
];
137 uint8_t cert
[MAX_CERT_LENGTH
];
141 enum nhrp_route_type
{
142 NHRP_ROUTE_BLACKHOLE
,
144 NHRP_ROUTE_NBMA_NEXTHOP
,
151 unsigned requested
: 1;
152 unsigned fallback_requested
: 1;
154 struct notifier_list notifier_list
;
155 struct interface
*ifp
;
157 struct thread
*t_fallback
;
158 struct notifier_block vc_notifier
, ifp_notifier
;
161 struct nhrp_packet_parser
{
162 struct interface
*ifp
;
163 struct nhrp_afi_data
*if_ad
;
164 struct nhrp_peer
*peer
;
167 struct zbuf extensions
;
168 struct nhrp_packet_header
*hdr
;
169 enum nhrp_route_type route_type
;
170 struct prefix route_prefix
;
171 union sockunion src_nbma
, src_proto
, dst_proto
;
174 struct nhrp_reqid_pool
{
175 struct hash
*reqid_hash
;
176 uint32_t next_request_id
;
181 void (*cb
)(struct nhrp_reqid
*, void *);
184 extern struct nhrp_reqid_pool nhrp_packet_reqid
;
185 extern struct nhrp_reqid_pool nhrp_event_reqid
;
187 enum nhrp_cache_type
{
188 NHRP_CACHE_INVALID
= 0,
189 NHRP_CACHE_INCOMPLETE
,
199 extern const char * const nhrp_cache_type_str
[];
200 extern unsigned long nhrp_cache_counts
[NHRP_CACHE_NUM_TYPES
];
203 struct interface
*ifp
;
204 union sockunion remote_addr
;
208 unsigned route_installed
: 1;
209 unsigned nhrp_route_installed
: 1;
211 struct notifier_block peer_notifier
;
212 struct notifier_block newpeer_notifier
;
213 struct notifier_list notifier_list
;
214 struct nhrp_reqid eventid
;
215 struct thread
*t_timeout
;
216 struct thread
*t_auth
;
219 enum nhrp_cache_type type
;
220 union sockunion remote_nbma_natoa
;
221 struct nhrp_peer
*peer
;
227 struct nhrp_shortcut
{
229 union sockunion addr
;
231 struct nhrp_reqid reqid
;
232 struct thread
*t_timer
;
234 enum nhrp_cache_type type
;
235 unsigned int holding_time
;
236 unsigned route_installed
: 1;
237 unsigned expiring
: 1;
239 struct nhrp_cache
*cache
;
240 struct notifier_block cache_notifier
;
244 struct interface
*ifp
;
245 struct list_head nhslist_entry
;
249 union sockunion proto_addr
;
250 const char *nbma_fqdn
; /* IP-address or FQDN */
252 struct thread
*t_resolve
;
253 struct resolver_query dns_resolve
;
254 struct list_head reglist_head
;
257 #define NHRP_IFF_SHORTCUT 0x0001
258 #define NHRP_IFF_REDIRECT 0x0002
259 #define NHRP_IFF_REG_NO_UNIQUE 0x0100
261 struct nhrp_interface
{
262 struct interface
*ifp
;
264 unsigned enabled
: 1;
266 char *ipsec_profile
, *ipsec_fallback_profile
, *source
;
267 union sockunion nbma
;
268 union sockunion nat_nbma
;
269 unsigned int linkidx
;
272 struct hash
*peer_hash
;
273 struct hash
*cache_hash
;
275 struct notifier_list notifier_list
;
277 struct interface
*nbmaifp
;
278 struct notifier_block nbmanifp_notifier
;
280 struct nhrp_afi_data
{
282 unsigned short configured
: 1;
283 union sockunion addr
;
285 short configured_mtu
;
287 unsigned int holdtime
;
288 struct list_head nhslist_head
;
292 int sock_open_unix(const char *path
);
294 void nhrp_interface_init(void);
295 void nhrp_interface_update(struct interface
*ifp
);
296 void nhrp_interface_update_mtu(struct interface
*ifp
, afi_t afi
);
298 int nhrp_interface_add(int cmd
, struct zclient
*client
, zebra_size_t length
, vrf_id_t vrf_id
);
299 int nhrp_interface_delete(int cmd
, struct zclient
*client
, zebra_size_t length
, vrf_id_t vrf_id
);
300 int nhrp_interface_up(int cmd
, struct zclient
*client
, zebra_size_t length
, vrf_id_t vrf_id
);
301 int nhrp_interface_down(int cmd
, struct zclient
*client
, zebra_size_t length
, vrf_id_t vrf_id
);
302 int nhrp_interface_address_add(int cmd
, struct zclient
*client
, zebra_size_t length
, vrf_id_t vrf_id
);
303 int nhrp_interface_address_delete(int cmd
, struct zclient
*client
, zebra_size_t length
, vrf_id_t vrf_id
);
305 void nhrp_interface_notify_add(struct interface
*ifp
, struct notifier_block
*n
, notifier_fn_t fn
);
306 void nhrp_interface_notify_del(struct interface
*ifp
, struct notifier_block
*n
);
307 void nhrp_interface_set_protection(struct interface
*ifp
, const char *profile
, const char *fallback_profile
);
308 void nhrp_interface_set_source(struct interface
*ifp
, const char *ifname
);
310 int nhrp_nhs_add(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
, const char *nbma_fqdn
);
311 int nhrp_nhs_del(struct interface
*ifp
, afi_t afi
, union sockunion
*proto_addr
, const char *nbma_fqdn
);
312 int nhrp_nhs_free(struct nhrp_nhs
*nhs
);
313 void nhrp_nhs_terminate(void);
315 void nhrp_route_update_nhrp(const struct prefix
*p
, struct interface
*ifp
);
316 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
);
317 int nhrp_route_read(int command
, struct zclient
*zclient
, zebra_size_t length
, vrf_id_t vrf_id
);
318 int nhrp_route_get_nexthop(const union sockunion
*addr
, struct prefix
*p
, union sockunion
*via
, struct interface
**ifp
);
319 enum nhrp_route_type
nhrp_route_address(struct interface
*in_ifp
, union sockunion
*addr
, struct prefix
*p
, struct nhrp_peer
**peer
);
321 void nhrp_config_init(void);
323 void nhrp_shortcut_init(void);
324 void nhrp_shortcut_terminate(void);
325 void nhrp_shortcut_initiate(union sockunion
*addr
);
326 void nhrp_shortcut_foreach(afi_t afi
, void (*cb
)(struct nhrp_shortcut
*, void *), void *ctx
);
327 void nhrp_shortcut_purge(struct nhrp_shortcut
*s
, int force
);
328 void nhrp_shortcut_prefix_change(const struct prefix
*p
, int deleted
);
330 struct nhrp_cache
*nhrp_cache_get(struct interface
*ifp
, union sockunion
*remote_addr
, int create
);
331 void nhrp_cache_foreach(struct interface
*ifp
, void (*cb
)(struct nhrp_cache
*, void *), void *ctx
);
332 void nhrp_cache_set_used(struct nhrp_cache
*, int);
333 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
);
334 void nhrp_cache_notify_add(struct nhrp_cache
*c
, struct notifier_block
*, notifier_fn_t
);
335 void nhrp_cache_notify_del(struct nhrp_cache
*c
, struct notifier_block
*);
337 void nhrp_vc_init(void);
338 void nhrp_vc_terminate(void);
339 struct nhrp_vc
*nhrp_vc_get(const union sockunion
*src
, const union sockunion
*dst
, int create
);
340 int nhrp_vc_ipsec_updown(uint32_t child_id
, struct nhrp_vc
*vc
);
341 void nhrp_vc_notify_add(struct nhrp_vc
*, struct notifier_block
*, notifier_fn_t
);
342 void nhrp_vc_notify_del(struct nhrp_vc
*, struct notifier_block
*);
343 void nhrp_vc_foreach(void (*cb
)(struct nhrp_vc
*, void *), void *ctx
);
344 void nhrp_vc_reset(void);
346 void vici_init(void);
347 void vici_terminate(void);
348 void vici_request_vc(const char *profile
, union sockunion
*src
, union sockunion
*dst
, int prio
);
350 extern const char *nhrp_event_socket_path
;
352 void evmgr_init(void);
353 void evmgr_terminate(void);
354 void evmgr_set_socket(const char *socket
);
355 void evmgr_notify(const char *name
, struct nhrp_cache
*c
, void (*cb
)(struct nhrp_reqid
*, void *));
357 struct nhrp_packet_header
*nhrp_packet_push(
358 struct zbuf
*zb
, uint8_t type
,
359 const union sockunion
*src_nbma
,
360 const union sockunion
*src_proto
,
361 const union sockunion
*dst_proto
);
362 void nhrp_packet_complete(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
);
363 uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu
, uint16_t len
);
365 struct nhrp_packet_header
*nhrp_packet_pull(
367 union sockunion
*src_nbma
,
368 union sockunion
*src_proto
,
369 union sockunion
*dst_proto
);
371 struct nhrp_cie_header
*nhrp_cie_push(
372 struct zbuf
*zb
, uint8_t code
,
373 const union sockunion
*nbma
,
374 const union sockunion
*proto
);
375 struct nhrp_cie_header
*nhrp_cie_pull(
377 struct nhrp_packet_header
*hdr
,
378 union sockunion
*nbma
,
379 union sockunion
*proto
);
381 struct nhrp_extension_header
*nhrp_ext_push(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
, uint16_t type
);
382 void nhrp_ext_complete(struct zbuf
*zb
, struct nhrp_extension_header
*ext
);
383 struct nhrp_extension_header
*nhrp_ext_pull(struct zbuf
*zb
, struct zbuf
*payload
);
384 void nhrp_ext_request(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
, struct interface
*);
385 int nhrp_ext_reply(struct zbuf
*zb
, struct nhrp_packet_header
*hdr
, struct interface
*ifp
, struct nhrp_extension_header
*ext
, struct zbuf
*extpayload
);
387 uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
, void (*cb
)(struct nhrp_reqid
*, void *));
388 void nhrp_reqid_free(struct nhrp_reqid_pool
*, struct nhrp_reqid
*r
);
389 struct nhrp_reqid
*nhrp_reqid_lookup(struct nhrp_reqid_pool
*, uint32_t reqid
);
391 int nhrp_packet_init(void);
393 struct nhrp_peer
*nhrp_peer_get(struct interface
*ifp
, const union sockunion
*remote_nbma
);
394 struct nhrp_peer
*nhrp_peer_ref(struct nhrp_peer
*p
);
395 void nhrp_peer_unref(struct nhrp_peer
*p
);
396 int nhrp_peer_check(struct nhrp_peer
*p
, int establish
);
397 void nhrp_peer_notify_add(struct nhrp_peer
*p
, struct notifier_block
*, notifier_fn_t
);
398 void nhrp_peer_notify_del(struct nhrp_peer
*p
, struct notifier_block
*);
399 void nhrp_peer_recv(struct nhrp_peer
*p
, struct zbuf
*zb
);
400 void nhrp_peer_send(struct nhrp_peer
*p
, struct zbuf
*zb
);
401 void nhrp_peer_send_indication(struct interface
*ifp
, uint16_t, struct zbuf
*);