Line data Source code
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 : #include <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 : DECLARE_MGROUP(RIPNGD);
90 :
91 : /* RIPng structure. */
92 : struct ripng {
93 : RB_ENTRY(ripng) entry;
94 :
95 : /* VRF this routing instance is associated with. */
96 : char *vrf_name;
97 :
98 : /* VRF backpointer (might be NULL if the VRF doesn't exist). */
99 : struct vrf *vrf;
100 :
101 : /* Status of the routing instance. */
102 : bool enabled;
103 :
104 : /* RIPng socket. */
105 : int sock;
106 :
107 : /* RIPng Parameters.*/
108 : uint8_t command;
109 : uint8_t version;
110 : uint16_t update_time;
111 : uint16_t timeout_time;
112 : uint16_t garbage_time;
113 : int max_mtu;
114 : uint8_t default_metric;
115 :
116 : /* Input/output buffer of RIPng. */
117 : struct stream *ibuf;
118 : struct stream *obuf;
119 :
120 : /* RIPng routing information base. */
121 : struct agg_table *table;
122 :
123 : /* Linked list of RIPng peers. */
124 : struct list *peer_list;
125 :
126 : /* RIPng enabled interfaces. */
127 : vector enable_if;
128 :
129 : /* RIPng enabled networks. */
130 : struct agg_table *enable_network;
131 :
132 : /* Vector to store passive-interface name. */
133 : vector passive_interface;
134 :
135 : /* RIPng offset-lists. */
136 : struct list *offset_list_master;
137 :
138 : /* RIPng threads. */
139 : struct thread *t_read;
140 : struct thread *t_update;
141 :
142 : /* Triggered update hack. */
143 : int trigger;
144 : struct thread *t_triggered_update;
145 : struct thread *t_triggered_interval;
146 :
147 : /* RIPng ECMP flag */
148 : bool ecmp;
149 :
150 : /* RIPng redistribute configuration. */
151 : struct {
152 : bool enabled;
153 : struct {
154 : char *name;
155 : struct route_map *map;
156 : } route_map;
157 : bool metric_config;
158 : uint8_t metric;
159 : } redist[ZEBRA_ROUTE_MAX];
160 :
161 : /* For distribute-list container */
162 : struct distribute_ctx *distribute_ctx;
163 :
164 : /* For if_rmap container */
165 : struct if_rmap_ctx *if_rmap_ctx;
166 : };
167 : RB_HEAD(ripng_instance_head, ripng);
168 6 : RB_PROTOTYPE(ripng_instance_head, ripng, entry, ripng_instance_compare)
169 :
170 : /* Routing table entry. */
171 : struct rte {
172 : struct in6_addr addr; /* RIPng destination prefix */
173 : uint16_t tag; /* RIPng tag */
174 : uint8_t prefixlen; /* Length of the RIPng prefix */
175 : uint8_t metric; /* Metric of the RIPng route */
176 : /* The nexthop is stored by the structure
177 : * ripng_nexthop within ripngd.c */
178 : };
179 :
180 : /* RIPNG send packet. */
181 : struct ripng_packet {
182 : uint8_t command;
183 : uint8_t version;
184 : uint16_t zero;
185 : struct rte rte[1];
186 : };
187 :
188 : /* Each route's information. */
189 : struct ripng_info {
190 : /* This route's type. Static, ripng or aggregate. */
191 : uint8_t type;
192 :
193 : /* Sub type for static route. */
194 : uint8_t sub_type;
195 :
196 : /* RIPng specific information */
197 : struct in6_addr nexthop;
198 : struct in6_addr from;
199 :
200 : /* Which interface does this route come from. */
201 : ifindex_t ifindex;
202 :
203 : /* Metric of this route. */
204 : uint8_t metric;
205 :
206 : /* Tag field of RIPng packet.*/
207 : uint16_t tag;
208 :
209 : /* For aggregation. */
210 : unsigned int suppress;
211 :
212 : /* Flags of RIPng route. */
213 : #define RIPNG_RTF_FIB 1
214 : #define RIPNG_RTF_CHANGED 2
215 : uint8_t flags;
216 :
217 : /* Garbage collect timer. */
218 : struct thread *t_timeout;
219 : struct thread *t_garbage_collect;
220 :
221 : /* Route-map features - this variables can be changed. */
222 : struct in6_addr nexthop_out;
223 : uint8_t metric_set;
224 : uint8_t metric_out;
225 : uint16_t tag_out;
226 :
227 : struct agg_node *rp;
228 : };
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 : /* Parent routing instance. */
239 : struct ripng *ripng;
240 :
241 : /* RIPng is enabled on this interface. */
242 : int enable_network;
243 : int enable_interface;
244 :
245 : /* RIPng is running on this interface. */
246 : int running;
247 :
248 : /* Split horizon flag. */
249 : split_horizon_policy_t split_horizon;
250 :
251 : /* For filter type slot. */
252 : #define RIPNG_FILTER_IN 0
253 : #define RIPNG_FILTER_OUT 1
254 : #define RIPNG_FILTER_MAX 2
255 :
256 : /* Access-list. */
257 : struct access_list *list[RIPNG_FILTER_MAX];
258 :
259 : /* Prefix-list. */
260 : struct prefix_list *prefix[RIPNG_FILTER_MAX];
261 :
262 : /* Route-map. */
263 : struct route_map *routemap[RIPNG_FILTER_MAX];
264 :
265 : /* Default information originate. */
266 : uint8_t default_originate;
267 :
268 : /* Default information only. */
269 : uint8_t default_only;
270 :
271 : /* Wake up thread. */
272 : struct thread *t_wakeup;
273 :
274 : /* Passive interface. */
275 : int passive;
276 : };
277 :
278 : /* RIPng peer information. */
279 : struct ripng_peer {
280 : /* Parent routing instance. */
281 : struct ripng *ripng;
282 :
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_OFFSET_LIST_IN 0
316 : #define RIPNG_OFFSET_LIST_OUT 1
317 : #define RIPNG_OFFSET_LIST_MAX 2
318 :
319 : struct ripng_offset_list {
320 : /* Parent routing instance. */
321 : struct ripng *ripng;
322 :
323 : char *ifname;
324 :
325 : struct {
326 : char *alist_name;
327 : /* struct access_list *alist; */
328 : uint8_t metric;
329 : } direct[RIPNG_OFFSET_LIST_MAX];
330 : };
331 :
332 : /* Extern variables. */
333 : extern struct zebra_privs_t ripngd_privs;
334 : extern struct thread_master *master;
335 : extern struct ripng_instance_head ripng_instances;
336 :
337 : /* Prototypes. */
338 : extern void ripng_init(void);
339 : extern void ripng_clean(struct ripng *ripng);
340 : extern void ripng_clean_network(struct ripng *ripng);
341 : extern void ripng_interface_clean(struct ripng *ripng);
342 : extern int ripng_enable_network_add(struct ripng *ripng, struct prefix *p);
343 : extern int ripng_enable_network_delete(struct ripng *ripng, struct prefix *p);
344 : extern int ripng_enable_if_add(struct ripng *ripng, const char *ifname);
345 : extern int ripng_enable_if_delete(struct ripng *ripng, const char *ifname);
346 : extern int ripng_passive_interface_set(struct ripng *ripng, const char *ifname);
347 : extern int ripng_passive_interface_unset(struct ripng *ripng,
348 : const char *ifname);
349 : extern void ripng_passive_interface_clean(struct ripng *ripng);
350 : extern void ripng_if_init(void);
351 : extern void ripng_route_map_init(void);
352 : extern void ripng_zebra_vrf_register(struct vrf *vrf);
353 : extern void ripng_zebra_vrf_deregister(struct vrf *vrf);
354 : extern void ripng_terminate(void);
355 : /* zclient_init() is done by ripng_zebra.c:zebra_init() */
356 : extern void zebra_init(struct thread_master *);
357 : extern void ripng_zebra_stop(void);
358 : extern void ripng_redistribute_conf_update(struct ripng *ripng, int type);
359 : extern void ripng_redistribute_conf_delete(struct ripng *ripng, int type);
360 :
361 : extern void ripng_peer_update(struct ripng *ripng, struct sockaddr_in6 *from,
362 : uint8_t version);
363 : extern void ripng_peer_bad_route(struct ripng *ripng,
364 : struct sockaddr_in6 *from);
365 : extern void ripng_peer_bad_packet(struct ripng *ripng,
366 : struct sockaddr_in6 *from);
367 : extern void ripng_peer_display(struct vty *vty, struct ripng *ripng);
368 : extern struct ripng_peer *ripng_peer_lookup(struct ripng *ripng,
369 : struct in6_addr *addr);
370 : extern struct ripng_peer *ripng_peer_lookup_next(struct ripng *ripng,
371 : struct in6_addr *addr);
372 : extern int ripng_peer_list_cmp(struct ripng_peer *p1, struct ripng_peer *p2);
373 : extern void ripng_peer_list_del(void *arg);
374 :
375 : extern struct ripng_offset_list *ripng_offset_list_new(struct ripng *ripng,
376 : const char *ifname);
377 : extern void ripng_offset_list_del(struct ripng_offset_list *offset);
378 : extern void ripng_offset_list_free(struct ripng_offset_list *offset);
379 : extern struct ripng_offset_list *ripng_offset_list_lookup(struct ripng *ripng,
380 : const char *ifname);
381 : extern int ripng_offset_list_apply_in(struct ripng *ripng,
382 : struct prefix_ipv6 *p,
383 : struct interface *ifp, uint8_t *metric);
384 : extern int ripng_offset_list_apply_out(struct ripng *ripng,
385 : struct prefix_ipv6 *p,
386 : struct interface *ifp, uint8_t *metric);
387 : extern int offset_list_cmp(struct ripng_offset_list *o1,
388 : struct ripng_offset_list *o2);
389 :
390 : extern int ripng_route_rte(struct ripng_info *rinfo);
391 : extern struct ripng_info *ripng_info_new(void);
392 : extern void ripng_info_free(struct ripng_info *rinfo);
393 : extern struct ripng *ripng_info_get_instance(const struct ripng_info *rinfo);
394 : extern void ripng_event(struct ripng *ripng, enum ripng_event event, int sock);
395 : extern int ripng_request(struct interface *ifp);
396 : extern void ripng_redistribute_add(struct ripng *ripng, int type, int sub_type,
397 : struct prefix_ipv6 *p, ifindex_t ifindex,
398 : struct in6_addr *nexthop, route_tag_t tag);
399 : extern void ripng_redistribute_delete(struct ripng *ripng, int type,
400 : int sub_type, struct prefix_ipv6 *p,
401 : ifindex_t ifindex);
402 : extern void ripng_redistribute_withdraw(struct ripng *ripng, int type);
403 :
404 : extern void ripng_ecmp_disable(struct ripng *ripng);
405 : extern void ripng_distribute_update_interface(struct interface *);
406 : extern void ripng_if_rmap_update_interface(struct interface *);
407 :
408 : extern void ripng_zebra_ipv6_add(struct ripng *ripng, struct agg_node *node);
409 : extern void ripng_zebra_ipv6_delete(struct ripng *ripng, struct agg_node *node);
410 :
411 : extern void ripng_redistribute_enable(struct ripng *ripng);
412 : extern void ripng_redistribute_disable(struct ripng *ripng);
413 : extern int ripng_redistribute_check(struct ripng *ripng, int type);
414 : extern void ripng_redistribute_write(struct vty *vty, struct ripng *ripng);
415 :
416 : extern int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p,
417 : struct in6_addr *nexthop, uint16_t tag,
418 : uint8_t metric);
419 : extern int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to,
420 : struct interface *ifp);
421 :
422 : extern void ripng_packet_dump(struct ripng_packet *packet, int size,
423 : const char *sndrcv);
424 :
425 : extern int ripng_interface_up(ZAPI_CALLBACK_ARGS);
426 : extern int ripng_interface_down(ZAPI_CALLBACK_ARGS);
427 : extern int ripng_interface_add(ZAPI_CALLBACK_ARGS);
428 : extern int ripng_interface_delete(ZAPI_CALLBACK_ARGS);
429 : extern int ripng_interface_address_add(ZAPI_CALLBACK_ARGS);
430 : extern int ripng_interface_address_delete(ZAPI_CALLBACK_ARGS);
431 : extern int ripng_interface_vrf_update(ZAPI_CALLBACK_ARGS);
432 : extern void ripng_interface_sync(struct interface *ifp);
433 :
434 : extern struct ripng *ripng_lookup_by_vrf_id(vrf_id_t vrf_id);
435 : extern struct ripng *ripng_lookup_by_vrf_name(const char *vrf_name);
436 : extern struct ripng *ripng_create(const char *vrf_name, struct vrf *vrf,
437 : int socket);
438 : extern int ripng_make_socket(struct vrf *vrf);
439 : extern int ripng_network_write(struct vty *vty, struct ripng *ripng);
440 :
441 : extern struct ripng_info *ripng_ecmp_add(struct ripng *ripng,
442 : struct ripng_info *rinfo);
443 : extern struct ripng_info *ripng_ecmp_replace(struct ripng *ripng,
444 : struct ripng_info *rinfo);
445 : extern struct ripng_info *ripng_ecmp_delete(struct ripng *ripng,
446 : struct ripng_info *rinfo);
447 :
448 : extern void ripng_vrf_init(void);
449 : extern void ripng_vrf_terminate(void);
450 : extern void ripng_cli_init(void);
451 :
452 : #endif /* _ZEBRA_RIPNG_RIPNGD_H */
|