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