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