source: src/router/quagga/nhrpd/nhrpd.h @ 31640

Last change on this file since 31640 was 31640, checked in by brainslayer, 5 months ago

update quagga

File size: 12.0 KB
Line 
1/* NHRP daemon internal structures and function prototypes
2 * Copyright (c) 2014-2015 Timo TerÀs
3 *
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.
8 */
9
10#ifndef NHRPD_H
11#define NHRPD_H
12
13#include "list.h"
14
15#include "zbuf.h"
16#include "zclient.h"
17#include "debug.h"
18
19#define NHRPD_DEFAULT_HOLDTIME  7200
20
21#define NHRP_VTY_PORT           2612
22#define NHRP_DEFAULT_CONFIG     "nhrpd.conf"
23
24extern struct thread_master *master;
25
26enum {
27        NHRP_OK = 0,
28        NHRP_ERR_FAIL,
29        NHRP_ERR_NO_MEMORY,
30        NHRP_ERR_UNSUPPORTED_INTERFACE,
31        NHRP_ERR_NHRP_NOT_ENABLED,
32        NHRP_ERR_ENTRY_EXISTS,
33        NHRP_ERR_ENTRY_NOT_FOUND,
34        NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH,
35};
36
37struct notifier_block;
38
39typedef void (*notifier_fn_t)(struct notifier_block *, unsigned long);
40
41struct notifier_block {
42        struct list_head notifier_entry;
43        notifier_fn_t action;
44};
45
46struct notifier_list {
47        struct list_head notifier_head;
48};
49
50#define NOTIFIER_LIST_INITIALIZER(l) \
51        { .notifier_head = LIST_INITIALIZER((l)->notifier_head) }
52
53static inline void notifier_init(struct notifier_list *l)
54{
55        list_init(&l->notifier_head);
56}
57
58static inline void notifier_add(struct notifier_block *n, struct notifier_list *l, notifier_fn_t action)
59{
60        n->action = action;
61        list_add_tail(&n->notifier_entry, &l->notifier_head);
62}
63
64static inline void notifier_del(struct notifier_block *n)
65{
66        list_del(&n->notifier_entry);
67}
68
69static inline void notifier_call(struct notifier_list *l, int cmd)
70{
71        struct notifier_block *n, *nn;
72        list_for_each_entry_safe(n, nn, &l->notifier_head, notifier_entry)
73                n->action(n, cmd);
74}
75
76static inline int notifier_active(struct notifier_list *l)
77{
78        return !list_empty(&l->notifier_head);
79}
80
81struct resolver_query {
82        void (*callback)(struct resolver_query *, int n, union sockunion *);
83};
84
85void resolver_init(void);
86void resolver_resolve(struct resolver_query *query, int af, const char *hostname, void (*cb)(struct resolver_query *, int, union sockunion *));
87
88void nhrp_zebra_init(void);
89void nhrp_zebra_terminate(void);
90
91struct zbuf;
92struct nhrp_vc;
93struct nhrp_cache;
94struct nhrp_nhs;
95struct nhrp_interface;
96
97#define MAX_ID_LENGTH                   64
98#define MAX_CERT_LENGTH                 2048
99
100enum nhrp_notify_type {
101        NOTIFY_INTERFACE_UP,
102        NOTIFY_INTERFACE_DOWN,
103        NOTIFY_INTERFACE_CHANGED,
104        NOTIFY_INTERFACE_ADDRESS_CHANGED,
105        NOTIFY_INTERFACE_NBMA_CHANGED,
106        NOTIFY_INTERFACE_MTU_CHANGED,
107
108        NOTIFY_VC_IPSEC_CHANGED,
109        NOTIFY_VC_IPSEC_UPDATE_NBMA,
110
111        NOTIFY_PEER_UP,
112        NOTIFY_PEER_DOWN,
113        NOTIFY_PEER_IFCONFIG_CHANGED,
114        NOTIFY_PEER_MTU_CHANGED,
115        NOTIFY_PEER_NBMA_CHANGING,
116
117        NOTIFY_CACHE_UP,
118        NOTIFY_CACHE_DOWN,
119        NOTIFY_CACHE_DELETE,
120        NOTIFY_CACHE_USED,
121        NOTIFY_CACHE_BINDING_CHANGE,
122};
123
124struct nhrp_vc {
125        struct notifier_list notifier_list;
126        uint8_t ipsec;
127        uint8_t updating;
128        uint8_t abort_migration;
129
130        struct nhrp_vc_peer {
131                union sockunion nbma;
132                char id[MAX_ID_LENGTH];
133                uint16_t certlen;
134                uint8_t cert[MAX_CERT_LENGTH];
135        } local, remote;
136};
137
138enum nhrp_route_type {
139        NHRP_ROUTE_BLACKHOLE,
140        NHRP_ROUTE_LOCAL,
141        NHRP_ROUTE_NBMA_NEXTHOP,
142        NHRP_ROUTE_OFF_NBMA,
143};
144
145struct nhrp_peer {
146        unsigned int ref;
147        unsigned online : 1;
148        unsigned requested : 1;
149        unsigned fallback_requested : 1;
150        unsigned prio : 1;
151        struct notifier_list notifier_list;
152        struct interface *ifp;
153        struct nhrp_vc *vc;
154        struct thread *t_fallback;
155        struct notifier_block vc_notifier, ifp_notifier;
156};
157
158struct nhrp_packet_parser {
159        struct interface *ifp;
160        struct nhrp_afi_data *if_ad;
161        struct nhrp_peer *peer;
162        struct zbuf *pkt;
163        struct zbuf payload;
164        struct zbuf extensions;
165        struct nhrp_packet_header *hdr;
166        enum nhrp_route_type route_type;
167        struct prefix route_prefix;
168        union sockunion src_nbma, src_proto, dst_proto;
169};
170
171struct nhrp_reqid_pool {
172        struct hash *reqid_hash;
173        uint32_t next_request_id;
174};
175
176struct nhrp_reqid {
177        uint32_t request_id;
178        void (*cb)(struct nhrp_reqid *, void *);
179};
180
181extern struct nhrp_reqid_pool nhrp_packet_reqid;
182extern struct nhrp_reqid_pool nhrp_event_reqid;
183
184enum nhrp_cache_type {
185        NHRP_CACHE_INVALID = 0,
186        NHRP_CACHE_INCOMPLETE,
187        NHRP_CACHE_NEGATIVE,
188        NHRP_CACHE_CACHED,
189        NHRP_CACHE_DYNAMIC,
190        NHRP_CACHE_NHS,
191        NHRP_CACHE_STATIC,
192        NHRP_CACHE_LOCAL,
193        NHRP_CACHE_NUM_TYPES
194};
195
196extern const char * const nhrp_cache_type_str[];
197extern unsigned long nhrp_cache_counts[NHRP_CACHE_NUM_TYPES];
198
199struct nhrp_cache {
200        struct interface *ifp;
201        union sockunion remote_addr;
202
203        unsigned map : 1;
204        unsigned used : 1;
205        unsigned route_installed : 1;
206        unsigned nhrp_route_installed : 1;
207
208        struct notifier_block peer_notifier;
209        struct notifier_block newpeer_notifier;
210        struct notifier_list notifier_list;
211        struct nhrp_reqid eventid;
212        struct thread *t_timeout;
213        struct thread *t_auth;
214
215        struct {
216                enum nhrp_cache_type type;
217                union sockunion remote_nbma_natoa;
218                struct nhrp_peer *peer;
219                time_t expires;
220                uint32_t mtu;
221        } cur, new;
222};
223
224struct nhrp_shortcut {
225        struct prefix *p;
226        union sockunion addr;
227
228        struct nhrp_reqid reqid;
229        struct thread *t_timer;
230
231        enum nhrp_cache_type type;
232        unsigned int holding_time;
233        unsigned route_installed : 1;
234        unsigned expiring : 1;
235
236        struct nhrp_cache *cache;
237        struct notifier_block cache_notifier;
238};
239
240struct nhrp_nhs {
241        struct interface *ifp;
242        struct list_head nhslist_entry;
243
244        unsigned hub : 1;
245        afi_t afi;
246        union sockunion proto_addr;
247        const char *nbma_fqdn;                  /* IP-address or FQDN */
248
249        struct thread *t_resolve;
250        struct resolver_query dns_resolve;
251        struct list_head reglist_head;
252};
253
254#define NHRP_IFF_SHORTCUT               0x0001
255#define NHRP_IFF_REDIRECT               0x0002
256#define NHRP_IFF_REG_NO_UNIQUE          0x0100
257
258struct nhrp_interface {
259        struct interface *ifp;
260
261        unsigned enabled : 1;
262
263        char *ipsec_profile, *ipsec_fallback_profile, *source;
264        union sockunion nbma;
265        union sockunion nat_nbma;
266        unsigned int linkidx;
267        uint32_t grekey;
268
269        struct hash *peer_hash;
270        struct hash *cache_hash;
271
272        struct notifier_list notifier_list;
273
274        struct interface *nbmaifp;
275        struct notifier_block nbmanifp_notifier;
276
277        struct nhrp_afi_data {
278                unsigned flags;
279                unsigned short configured : 1;
280                union sockunion addr;
281                uint32_t network_id;
282                short configured_mtu;
283                unsigned short mtu;
284                unsigned int holdtime;
285                struct list_head nhslist_head;
286        } afi[AFI_MAX];
287};
288
289int sock_open_unix(const char *path);
290
291void nhrp_interface_init(void);
292void nhrp_interface_update(struct interface *ifp);
293void nhrp_interface_update_mtu(struct interface *ifp, afi_t afi);
294
295int nhrp_interface_add(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
296int nhrp_interface_delete(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
297int nhrp_interface_up(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
298int nhrp_interface_down(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
299int nhrp_interface_address_add(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
300int nhrp_interface_address_delete(int cmd, struct zclient *client, zebra_size_t length, vrf_id_t vrf_id);
301
302void nhrp_interface_notify_add(struct interface *ifp, struct notifier_block *n, notifier_fn_t fn);
303void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n);
304void nhrp_interface_set_protection(struct interface *ifp, const char *profile, const char *fallback_profile);
305void nhrp_interface_set_source(struct interface *ifp, const char *ifname);
306
307int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, const char *nbma_fqdn);
308int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr, const char *nbma_fqdn);
309int nhrp_nhs_free(struct nhrp_nhs *nhs);
310void nhrp_nhs_terminate(void);
311
312void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp);
313void nhrp_route_announce(int add, enum nhrp_cache_type type, const struct prefix *p, struct interface *ifp, const union sockunion *nexthop, uint32_t mtu);
314int nhrp_route_read(int command, struct zclient *zclient, zebra_size_t length, vrf_id_t vrf_id);
315int nhrp_route_get_nexthop(const union sockunion *addr, struct prefix *p, union sockunion *via, struct interface **ifp);
316enum nhrp_route_type nhrp_route_address(struct interface *in_ifp, union sockunion *addr, struct prefix *p, struct nhrp_peer **peer);
317
318void nhrp_config_init(void);
319
320void nhrp_shortcut_init(void);
321void nhrp_shortcut_terminate(void);
322void nhrp_shortcut_initiate(union sockunion *addr);
323void nhrp_shortcut_foreach(afi_t afi, void (*cb)(struct nhrp_shortcut *, void *), void *ctx);
324void nhrp_shortcut_purge(struct nhrp_shortcut *s, int force);
325void nhrp_shortcut_prefix_change(const struct prefix *p, int deleted);
326
327struct nhrp_cache *nhrp_cache_get(struct interface *ifp, union sockunion *remote_addr, int create);
328void nhrp_cache_foreach(struct interface *ifp, void (*cb)(struct nhrp_cache *, void *), void *ctx);
329void nhrp_cache_set_used(struct nhrp_cache *, int);
330int 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);
331void nhrp_cache_notify_add(struct nhrp_cache *c, struct notifier_block *, notifier_fn_t);
332void nhrp_cache_notify_del(struct nhrp_cache *c, struct notifier_block *);
333
334void nhrp_vc_init(void);
335void nhrp_vc_terminate(void);
336struct nhrp_vc *nhrp_vc_get(const union sockunion *src, const union sockunion *dst, int create);
337int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc);
338void nhrp_vc_notify_add(struct nhrp_vc *, struct notifier_block *, notifier_fn_t);
339void nhrp_vc_notify_del(struct nhrp_vc *, struct notifier_block *);
340void nhrp_vc_foreach(void (*cb)(struct nhrp_vc *, void *), void *ctx);
341void nhrp_vc_reset(void);
342
343void vici_init(void);
344void vici_terminate(void);
345void vici_request_vc(const char *profile, union sockunion *src, union sockunion *dst, int prio);
346
347extern const char *nhrp_event_socket_path;
348
349void evmgr_init(void);
350void evmgr_terminate(void);
351void evmgr_set_socket(const char *socket);
352void evmgr_notify(const char *name, struct nhrp_cache *c, void (*cb)(struct nhrp_reqid *, void *));
353
354struct nhrp_packet_header *nhrp_packet_push(
355        struct zbuf *zb, uint8_t type,
356        const union sockunion *src_nbma,
357        const union sockunion *src_proto,
358        const union sockunion *dst_proto);
359void nhrp_packet_complete(struct zbuf *zb, struct nhrp_packet_header *hdr);
360uint16_t nhrp_packet_calculate_checksum(const uint8_t *pdu, uint16_t len);
361
362struct nhrp_packet_header *nhrp_packet_pull(
363        struct zbuf *zb,
364        union sockunion *src_nbma,
365        union sockunion *src_proto,
366        union sockunion *dst_proto);
367
368struct nhrp_cie_header *nhrp_cie_push(
369        struct zbuf *zb, uint8_t code,
370        const union sockunion *nbma,
371        const union sockunion *proto);
372struct nhrp_cie_header *nhrp_cie_pull(
373        struct zbuf *zb,
374        struct nhrp_packet_header *hdr,
375        union sockunion *nbma,
376        union sockunion *proto);
377
378struct nhrp_extension_header *nhrp_ext_push(struct zbuf *zb, struct nhrp_packet_header *hdr, uint16_t type);
379void nhrp_ext_complete(struct zbuf *zb, struct nhrp_extension_header *ext);
380struct nhrp_extension_header *nhrp_ext_pull(struct zbuf *zb, struct zbuf *payload);
381void nhrp_ext_request(struct zbuf *zb, struct nhrp_packet_header *hdr, struct interface *);
382int nhrp_ext_reply(struct zbuf *zb, struct nhrp_packet_header *hdr, struct interface *ifp, struct nhrp_extension_header *ext, struct zbuf *extpayload);
383
384uint32_t nhrp_reqid_alloc(struct nhrp_reqid_pool *, struct nhrp_reqid *r, void (*cb)(struct nhrp_reqid *, void *));
385void nhrp_reqid_free(struct nhrp_reqid_pool *, struct nhrp_reqid *r);
386struct nhrp_reqid *nhrp_reqid_lookup(struct nhrp_reqid_pool *, uint32_t reqid);
387
388int nhrp_packet_init(void);
389
390struct nhrp_peer *nhrp_peer_get(struct interface *ifp, const union sockunion *remote_nbma);
391struct nhrp_peer *nhrp_peer_ref(struct nhrp_peer *p);
392void nhrp_peer_unref(struct nhrp_peer *p);
393int nhrp_peer_check(struct nhrp_peer *p, int establish);
394void nhrp_peer_notify_add(struct nhrp_peer *p, struct notifier_block *, notifier_fn_t);
395void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *);
396void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb);
397void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb);
398void nhrp_peer_send_indication(struct interface *ifp, uint16_t, struct zbuf *);
399
400#endif
Note: See TracBrowser for help on using the repository browser.