]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripngd.h
Merge pull request #3894 from donaldsharp/install_replace
[mirror_frr.git] / ripngd / ripngd.h
1 /*
2 * RIPng related value and structure.
3 * Copyright (C) 1998 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef _ZEBRA_RIPNG_RIPNGD_H
23 #define _ZEBRA_RIPNG_RIPNGD_H
24
25 #include <zclient.h>
26 #include <vty.h>
27 #include <distribute.h>
28
29 #include "ripng_memory.h"
30
31 /* RIPng version and port number. */
32 #define RIPNG_V1 1
33 #define RIPNG_PORT_DEFAULT 521
34 #define RIPNG_VTY_PORT 2603
35 #define RIPNG_MAX_PACKET_SIZE 1500
36 #define RIPNG_PRIORITY_DEFAULT 0
37
38 /* RIPng commands. */
39 #define RIPNG_REQUEST 1
40 #define RIPNG_RESPONSE 2
41
42 /* RIPng metric and multicast group address. */
43 #define RIPNG_METRIC_INFINITY 16
44 #define RIPNG_METRIC_NEXTHOP 0xff
45 #define RIPNG_GROUP "ff02::9"
46
47 /* RIPng peer timeout value. */
48 #define RIPNG_PEER_TIMER_DEFAULT 180
49
50 /* Default config file name. */
51 #define RIPNG_DEFAULT_CONFIG "ripngd.conf"
52
53 /* RIPng route types. */
54 #define RIPNG_ROUTE_RTE 0
55 #define RIPNG_ROUTE_STATIC 1
56 #define RIPNG_ROUTE_DEFAULT 2
57 #define RIPNG_ROUTE_REDISTRIBUTE 3
58 #define RIPNG_ROUTE_INTERFACE 4
59 #define RIPNG_ROUTE_AGGREGATE 5
60
61 /* Interface send/receive configuration. */
62 #define RIPNG_SEND_UNSPEC 0
63 #define RIPNG_SEND_OFF 1
64 #define RIPNG_RECEIVE_UNSPEC 0
65 #define RIPNG_RECEIVE_OFF 1
66
67 /* RIP default route's accept/announce methods. */
68 #define RIPNG_DEFAULT_ADVERTISE_UNSPEC 0
69 #define RIPNG_DEFAULT_ADVERTISE_NONE 1
70 #define RIPNG_DEFAULT_ADVERTISE 2
71
72 #define RIPNG_DEFAULT_ACCEPT_UNSPEC 0
73 #define RIPNG_DEFAULT_ACCEPT_NONE 1
74 #define RIPNG_DEFAULT_ACCEPT 2
75
76 /* For max RTE calculation. */
77 #ifndef IPV6_HDRLEN
78 #define IPV6_HDRLEN 40
79 #endif /* IPV6_HDRLEN */
80
81 #ifndef IFMINMTU
82 #define IFMINMTU 576
83 #endif /* IFMINMTU */
84
85 /* YANG paths */
86 #define RIPNG_INSTANCE "/frr-ripngd:ripngd/instance"
87 #define RIPNG_IFACE "/frr-interface:lib/interface/frr-ripngd:ripng"
88
89 /* RIPng structure. */
90 struct ripng {
91 /* RIPng socket. */
92 int sock;
93
94 /* RIPng Parameters.*/
95 uint8_t command;
96 uint8_t version;
97 uint16_t update_time;
98 uint16_t timeout_time;
99 uint16_t garbage_time;
100 int max_mtu;
101 uint8_t default_metric;
102
103 /* Input/output buffer of RIPng. */
104 struct stream *ibuf;
105 struct stream *obuf;
106
107 /* RIPng routing information base. */
108 struct agg_table *table;
109
110 /* RIPng threads. */
111 struct thread *t_read;
112 struct thread *t_write;
113 struct thread *t_update;
114 struct thread *t_garbage;
115 struct thread *t_zebra;
116
117 /* Triggered update hack. */
118 int trigger;
119 struct thread *t_triggered_update;
120 struct thread *t_triggered_interval;
121
122 /* RIPng ECMP flag */
123 bool ecmp;
124
125 /* For redistribute route map. */
126 struct {
127 char *name;
128 struct route_map *map;
129 bool metric_config;
130 uint8_t metric;
131 } route_map[ZEBRA_ROUTE_MAX];
132
133 /* For distribute-list container */
134 struct distribute_ctx *distribute_ctx;
135
136 /* For if_rmap container */
137 struct if_rmap_ctx *if_rmap_ctx;
138 };
139
140 /* Routing table entry. */
141 struct rte {
142 struct in6_addr addr; /* RIPng destination prefix */
143 uint16_t tag; /* RIPng tag */
144 uint8_t prefixlen; /* Length of the RIPng prefix */
145 uint8_t metric; /* Metric of the RIPng route */
146 /* The nexthop is stored by the structure
147 * ripng_nexthop within ripngd.c */
148 };
149
150 /* RIPNG send packet. */
151 struct ripng_packet {
152 uint8_t command;
153 uint8_t version;
154 uint16_t zero;
155 struct rte rte[1];
156 };
157
158 /* Each route's information. */
159 struct ripng_info {
160 /* This route's type. Static, ripng or aggregate. */
161 uint8_t type;
162
163 /* Sub type for static route. */
164 uint8_t sub_type;
165
166 /* RIPng specific information */
167 struct in6_addr nexthop;
168 struct in6_addr from;
169
170 /* Which interface does this route come from. */
171 ifindex_t ifindex;
172
173 /* Metric of this route. */
174 uint8_t metric;
175
176 /* Tag field of RIPng packet.*/
177 uint16_t tag;
178
179 /* For aggregation. */
180 unsigned int suppress;
181
182 /* Flags of RIPng route. */
183 #define RIPNG_RTF_FIB 1
184 #define RIPNG_RTF_CHANGED 2
185 uint8_t flags;
186
187 /* Garbage collect timer. */
188 struct thread *t_timeout;
189 struct thread *t_garbage_collect;
190
191 /* Route-map features - this variables can be changed. */
192 struct in6_addr nexthop_out;
193 uint8_t metric_set;
194 uint8_t metric_out;
195 uint16_t tag_out;
196
197 struct agg_node *rp;
198 };
199
200 #ifdef notyet
201 #if 0
202 /* RIPng tag structure. */
203 struct ripng_tag
204 {
205 /* Tag value. */
206 uint16_t tag;
207
208 /* Port. */
209 uint16_t port;
210
211 /* Multicast group. */
212 struct in6_addr maddr;
213
214 /* Table number. */
215 int table;
216
217 /* Distance. */
218 int distance;
219
220 /* Split horizon. */
221 uint8_t split_horizon;
222
223 /* Poison reverse. */
224 uint8_t poison_reverse;
225 };
226 #endif /* 0 */
227 #endif /* not yet */
228
229 typedef enum {
230 RIPNG_NO_SPLIT_HORIZON = 0,
231 RIPNG_SPLIT_HORIZON,
232 RIPNG_SPLIT_HORIZON_POISONED_REVERSE
233 } split_horizon_policy_t;
234
235 /* RIPng specific interface configuration. */
236 struct ripng_interface {
237 /* RIPng is enabled on this interface. */
238 int enable_network;
239 int enable_interface;
240
241 /* RIPng is running on this interface. */
242 int running;
243
244 /* Split horizon flag. */
245 split_horizon_policy_t split_horizon;
246
247 /* For filter type slot. */
248 #define RIPNG_FILTER_IN 0
249 #define RIPNG_FILTER_OUT 1
250 #define RIPNG_FILTER_MAX 2
251
252 /* Access-list. */
253 struct access_list *list[RIPNG_FILTER_MAX];
254
255 /* Prefix-list. */
256 struct prefix_list *prefix[RIPNG_FILTER_MAX];
257
258 /* Route-map. */
259 struct route_map *routemap[RIPNG_FILTER_MAX];
260
261 #ifdef notyet
262 #if 0
263 /* RIPng tag configuration. */
264 struct ripng_tag *rtag;
265 #endif /* 0 */
266 #endif /* notyet */
267
268 /* Default information originate. */
269 uint8_t default_originate;
270
271 /* Default information only. */
272 uint8_t default_only;
273
274 /* Wake up thread. */
275 struct thread *t_wakeup;
276
277 /* Passive interface. */
278 int passive;
279 };
280
281 /* RIPng peer information. */
282 struct ripng_peer {
283 /* Peer address. */
284 struct in6_addr addr;
285
286 /* Peer RIPng tag value. */
287 int domain;
288
289 /* Last update time. */
290 time_t uptime;
291
292 /* Peer RIP version. */
293 uint8_t version;
294
295 /* Statistics. */
296 int recv_badpackets;
297 int recv_badroutes;
298
299 /* Timeout thread. */
300 struct thread *t_timeout;
301 };
302
303 /* All RIPng events. */
304 enum ripng_event {
305 RIPNG_READ,
306 RIPNG_ZEBRA,
307 RIPNG_REQUEST_EVENT,
308 RIPNG_UPDATE_EVENT,
309 RIPNG_TRIGGERED_UPDATE,
310 };
311
312 /* RIPng timer on/off macro. */
313 #define RIPNG_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
314
315 #define RIPNG_TIMER_OFF(T) \
316 do { \
317 if (T) { \
318 thread_cancel(T); \
319 (T) = NULL; \
320 } \
321 } while (0)
322
323 #define RIPNG_OFFSET_LIST_IN 0
324 #define RIPNG_OFFSET_LIST_OUT 1
325 #define RIPNG_OFFSET_LIST_MAX 2
326
327 struct ripng_offset_list {
328 char *ifname;
329
330 struct {
331 char *alist_name;
332 /* struct access_list *alist; */
333 uint8_t metric;
334 } direct[RIPNG_OFFSET_LIST_MAX];
335 };
336
337 /* Extern variables. */
338 extern struct ripng *ripng;
339 extern struct list *peer_list;
340 extern struct zebra_privs_t ripngd_privs;
341 extern struct thread_master *master;
342
343 /* Prototypes. */
344 extern void ripng_init(void);
345 extern void ripng_clean(void);
346 extern void ripng_clean_network(void);
347 extern void ripng_interface_clean(void);
348 extern int ripng_enable_network_add(struct prefix *p);
349 extern int ripng_enable_network_delete(struct prefix *p);
350 extern int ripng_enable_if_add(const char *ifname);
351 extern int ripng_enable_if_delete(const char *ifname);
352 extern int ripng_passive_interface_set(const char *ifname);
353 extern int ripng_passive_interface_unset(const char *ifname);
354 extern void ripng_passive_interface_clean(void);
355 extern void ripng_if_init(void);
356 extern void ripng_route_map_init(void);
357 extern void ripng_terminate(void);
358 /* zclient_init() is done by ripng_zebra.c:zebra_init() */
359 extern void zebra_init(struct thread_master *);
360 extern void ripng_zebra_stop(void);
361 extern void ripng_redistribute_conf_update(int type);
362 extern void ripng_redistribute_conf_delete(int type);
363
364 extern void ripng_peer_init(void);
365 extern void ripng_peer_update(struct sockaddr_in6 *, uint8_t);
366 extern void ripng_peer_bad_route(struct sockaddr_in6 *);
367 extern void ripng_peer_bad_packet(struct sockaddr_in6 *);
368 extern void ripng_peer_display(struct vty *);
369 extern struct ripng_peer *ripng_peer_lookup(struct in6_addr *);
370 extern struct ripng_peer *ripng_peer_lookup_next(struct in6_addr *);
371
372 extern struct ripng_offset_list *ripng_offset_list_new(const char *ifname);
373 extern void ripng_offset_list_del(struct ripng_offset_list *offset);
374 extern struct ripng_offset_list *ripng_offset_list_lookup(const char *ifname);
375 extern struct ripng_offset_list *ripng_offset_list_lookup(const char *ifname);
376 extern int ripng_offset_list_apply_in(struct prefix_ipv6 *, struct interface *,
377 uint8_t *);
378 extern int ripng_offset_list_apply_out(struct prefix_ipv6 *, struct interface *,
379 uint8_t *);
380 extern void ripng_offset_init(void);
381 extern void ripng_offset_clean(void);
382
383 extern int ripng_route_rte(struct ripng_info *rinfo);
384 extern struct ripng_info *ripng_info_new(void);
385 extern void ripng_info_free(struct ripng_info *rinfo);
386 extern void ripng_event(enum ripng_event, int);
387 extern int ripng_request(struct interface *ifp);
388 extern void ripng_redistribute_add(int, int, struct prefix_ipv6 *, ifindex_t,
389 struct in6_addr *, route_tag_t);
390 extern void ripng_redistribute_delete(int, int, struct prefix_ipv6 *,
391 ifindex_t);
392 extern void ripng_redistribute_withdraw(int type);
393
394 extern void ripng_ecmp_disable(void);
395 extern void ripng_distribute_update_interface(struct interface *);
396 extern void ripng_if_rmap_update_interface(struct interface *);
397
398 extern void ripng_zebra_ipv6_add(struct agg_node *node);
399 extern void ripng_zebra_ipv6_delete(struct agg_node *node);
400
401 extern void ripng_redistribute_clean(void);
402 extern int ripng_redistribute_check(int);
403 extern void ripng_redistribute_write(struct vty *);
404
405 extern int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p,
406 struct in6_addr *nexthop, uint16_t tag,
407 uint8_t metric);
408 extern int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to,
409 struct interface *ifp);
410
411 extern void ripng_packet_dump(struct ripng_packet *packet, int size,
412 const char *sndrcv);
413
414 extern int ripng_interface_up(int command, struct zclient *, zebra_size_t,
415 vrf_id_t);
416 extern int ripng_interface_down(int command, struct zclient *, zebra_size_t,
417 vrf_id_t);
418 extern int ripng_interface_add(int command, struct zclient *, zebra_size_t,
419 vrf_id_t);
420 extern int ripng_interface_delete(int command, struct zclient *, zebra_size_t,
421 vrf_id_t);
422 extern int ripng_interface_address_add(int command, struct zclient *,
423 zebra_size_t, vrf_id_t);
424 extern int ripng_interface_address_delete(int command, struct zclient *,
425 zebra_size_t, vrf_id_t);
426
427 extern int ripng_create(int socket);
428 extern int ripng_make_socket(void);
429 extern int ripng_network_write(struct vty *);
430
431 extern struct ripng_info *ripng_ecmp_add(struct ripng_info *);
432 extern struct ripng_info *ripng_ecmp_replace(struct ripng_info *);
433 extern struct ripng_info *ripng_ecmp_delete(struct ripng_info *);
434
435 /* Northbound. */
436 extern void ripng_cli_init(void);
437 extern const struct frr_yang_module_info frr_ripngd_info;
438
439 #endif /* _ZEBRA_RIPNG_RIPNGD_H */