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