1/*
2 * RIPngd and zebra interface.
3 * Copyright (C) 1998, 1999 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
18 * along with GNU Zebra; see the file COPYING.  If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25#include "command.h"
26#include "prefix.h"
27#include "stream.h"
28#include "routemap.h"
29#include "zclient.h"
30#include "log.h"
31
32#include "ripngd/ripngd.h"
33
34/* All information about zebra. */
35struct zclient *zclient = NULL;
36
37/* Callback prototypes for zebra client service. */
38int ripng_interface_up (int, struct zclient *, zebra_size_t);
39int ripng_interface_down (int, struct zclient *, zebra_size_t);
40int ripng_interface_add (int, struct zclient *, zebra_size_t);
41int ripng_interface_delete (int, struct zclient *, zebra_size_t);
42int ripng_interface_address_add (int, struct zclient *, zebra_size_t);
43int ripng_interface_address_delete (int, struct zclient *, zebra_size_t);
44
45void
46ripng_zebra_ipv6_add (struct prefix_ipv6 *p, struct in6_addr *nexthop,
47		      unsigned int ifindex)
48{
49  struct zapi_ipv6 api;
50
51  if (zclient->redist[ZEBRA_ROUTE_RIPNG])
52    {
53      api.type = ZEBRA_ROUTE_RIPNG;
54      api.flags = 0;
55      api.message = 0;
56      SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
57      api.nexthop_num = 1;
58      api.nexthop = &nexthop;
59      SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
60      api.ifindex_num = 1;
61      api.ifindex = &ifindex;
62
63      zapi_ipv6_add (zclient, p, &api);
64    }
65}
66
67void
68ripng_zebra_ipv6_delete (struct prefix_ipv6 *p, struct in6_addr *nexthop,
69			 unsigned int ifindex)
70{
71  struct zapi_ipv6 api;
72
73  if (zclient->redist[ZEBRA_ROUTE_RIPNG])
74    {
75      api.type = ZEBRA_ROUTE_RIPNG;
76      api.flags = 0;
77      api.message = 0;
78      SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
79      api.nexthop_num = 1;
80      api.nexthop = &nexthop;
81      SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
82      api.ifindex_num = 1;
83      api.ifindex = &ifindex;
84
85      zapi_ipv6_delete (zclient, p, &api);
86    }
87}
88
89/* Zebra route add and delete treatment. */
90int
91ripng_zebra_read_ipv6 (int command, struct zclient *zclient,
92		       zebra_size_t length)
93{
94  struct stream *s;
95  struct zapi_ipv6 api;
96  unsigned long ifindex;
97  struct in6_addr nexthop;
98  struct prefix_ipv6 p;
99
100  s = zclient->ibuf;
101  ifindex = 0;
102  memset (&nexthop, 0, sizeof (struct in6_addr));
103
104  /* Type, flags, message. */
105  api.type = stream_getc (s);
106  api.flags = stream_getc (s);
107  api.message = stream_getc (s);
108
109  /* IPv6 prefix. */
110  memset (&p, 0, sizeof (struct prefix_ipv6));
111  p.family = AF_INET6;
112  p.prefixlen = stream_getc (s);
113  stream_get (&p.prefix, s, PSIZE (p.prefixlen));
114
115  /* Nexthop, ifindex, distance, metric. */
116  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
117    {
118      api.nexthop_num = stream_getc (s);
119      stream_get (&nexthop, s, 16);
120    }
121  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
122    {
123      api.ifindex_num = stream_getc (s);
124      ifindex = stream_getl (s);
125    }
126  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
127    api.distance = stream_getc (s);
128  else
129    api.distance = 0;
130  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
131    api.metric = stream_getl (s);
132  else
133    api.metric = 0;
134
135  if (command == ZEBRA_IPV6_ROUTE_ADD)
136    ripng_redistribute_add (api.type, 0, &p, ifindex);
137  else
138    ripng_redistribute_delete (api.type, 0, &p, ifindex);
139
140  return 0;
141}
142
143int
144ripng_redistribute_unset (int type)
145{
146  if (! zclient->redist[type])
147    return CMD_SUCCESS;
148
149  zclient->redist[type] = 0;
150
151  if (zclient->sock > 0)
152    zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient->sock, type);
153
154  ripng_redistribute_withdraw (type);
155
156  return CMD_SUCCESS;
157}
158
159void
160ripng_redistribute_metric_set (int type, int metric)
161{
162  ripng->route_map[type].metric_config = 1;
163  ripng->route_map[type].metric = metric;
164}
165
166void
167ripng_redistribute_metric_unset (int type)
168{
169  ripng->route_map[type].metric_config = 0;
170  ripng->route_map[type].metric = 0;
171}
172
173void
174ripng_redistribute_routemap_set (int type, char *name)
175{
176  if (ripng->route_map[type].name)
177    free (ripng->route_map[type].name);
178
179  ripng->route_map[type].name = strdup (name);
180  ripng->route_map[type].map = route_map_lookup_by_name (name);
181}
182
183void
184ripng_redistribute_routemap_unset (int type)
185{
186  if (ripng->route_map[type].name)
187    free (ripng->route_map[type].name);
188
189  ripng->route_map[type].name = NULL;
190  ripng->route_map[type].map = NULL;
191}
192
193
194DEFUN (router_zebra,
195       router_zebra_cmd,
196       "router zebra",
197       "Enable a routing process\n"
198       "Make connection to zebra daemon\n")
199{
200  vty->node = ZEBRA_NODE;
201  zclient->enable = 1;
202  zclient_start (zclient);
203  return CMD_SUCCESS;
204}
205
206DEFUN (no_router_zebra,
207       no_router_zebra_cmd,
208       "no router zebra",
209       NO_STR
210       "Disable a routing process\n"
211       "Stop connection to zebra daemon\n")
212{
213  zclient->enable = 0;
214  zclient_stop (zclient);
215  return CMD_SUCCESS;
216}
217
218DEFUN (ripng_redistribute_ripng,
219       ripng_redistribute_ripng_cmd,
220       "redistribute ripng",
221       "Redistribute information from another routing protocol\n"
222       "RIPng route\n")
223{
224  zclient->redist[ZEBRA_ROUTE_RIPNG] = 1;
225  return CMD_SUCCESS;
226}
227
228DEFUN (no_ripng_redistribute_ripng,
229       no_ripng_redistribute_ripng_cmd,
230       "no redistribute ripng",
231       NO_STR
232       "Redistribute information from another routing protocol\n"
233       "RIPng route\n")
234{
235  zclient->redist[ZEBRA_ROUTE_RIPNG] = 0;
236  return CMD_SUCCESS;
237}
238
239DEFUN (ripng_redistribute_static,
240       ripng_redistribute_static_cmd,
241       "redistribute static",
242       "Redistribute information from another routing protocol\n"
243       "Static routes\n")
244{
245  zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC);
246  return CMD_SUCCESS;
247}
248
249DEFUN (no_ripng_redistribute_static,
250       no_ripng_redistribute_static_cmd,
251       "no redistribute static",
252       NO_STR
253       "Redistribute information from another routing protocol\n"
254       "Static routes\n")
255{
256  ripng_redistribute_metric_unset (ZEBRA_ROUTE_STATIC);
257  ripng_redistribute_routemap_unset (ZEBRA_ROUTE_STATIC);
258  return ripng_redistribute_unset (ZEBRA_ROUTE_STATIC);
259}
260
261DEFUN (ripng_redistribute_kernel,
262       ripng_redistribute_kernel_cmd,
263       "redistribute kernel",
264       "Redistribute information from another routing protocol\n"
265       "Kernel routes\n")
266{
267  zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL);
268  return CMD_SUCCESS;
269}
270
271DEFUN (no_ripng_redistribute_kernel,
272       no_ripng_redistribute_kernel_cmd,
273       "no redistribute kernel",
274       NO_STR
275       "Redistribute information from another routing protocol\n"
276       "Kernel routes\n")
277{
278  ripng_redistribute_metric_unset (ZEBRA_ROUTE_KERNEL);
279  ripng_redistribute_routemap_unset (ZEBRA_ROUTE_KERNEL);
280  return ripng_redistribute_unset (ZEBRA_ROUTE_KERNEL);
281}
282
283DEFUN (ripng_redistribute_connected,
284       ripng_redistribute_connected_cmd,
285       "redistribute connected",
286       "Redistribute information from another routing protocol\n"
287       "Connected\n")
288{
289  zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT);
290  return CMD_SUCCESS;
291}
292
293DEFUN (no_ripng_redistribute_connected,
294       no_ripng_redistribute_connected_cmd,
295       "no redistribute connected",
296       NO_STR
297       "Redistribute information from another routing protocol\n"
298       "Connected\n")
299{
300  ripng_redistribute_metric_unset (ZEBRA_ROUTE_CONNECT);
301  ripng_redistribute_routemap_unset (ZEBRA_ROUTE_CONNECT);
302  return ripng_redistribute_unset (ZEBRA_ROUTE_CONNECT);
303}
304
305DEFUN (ripng_redistribute_bgp,
306       ripng_redistribute_bgp_cmd,
307       "redistribute bgp",
308       "Redistribute information from another routing protocol\n"
309       "Border Gateway Protocol (BGP)\n")
310{
311  zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP);
312  return CMD_SUCCESS;
313}
314
315DEFUN (no_ripng_redistribute_bgp,
316       no_ripng_redistribute_bgp_cmd,
317       "no redistribute bgp",
318       NO_STR
319       "Redistribute information from another routing protocol\n"
320       "Border Gateway Protocol (BGP)\n")
321{
322  ripng_redistribute_metric_unset (ZEBRA_ROUTE_BGP);
323  ripng_redistribute_routemap_unset (ZEBRA_ROUTE_BGP);
324  return ripng_redistribute_unset (ZEBRA_ROUTE_BGP);
325}
326
327DEFUN (ripng_redistribute_ospf6,
328       ripng_redistribute_ospf6_cmd,
329       "redistribute ospf6",
330       "Redistribute information from another routing protocol\n"
331       "IPv6 Open Shortest Path First (OSPFv3)\n")
332{
333  zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6);
334  return CMD_SUCCESS;
335}
336
337DEFUN (no_ripng_redistribute_ospf6,
338       no_ripng_redistribute_ospf6_cmd,
339       "no redistribute ospf6",
340       NO_STR
341       "Redistribute information from another routing protocol\n"
342       "IPv6 Open Shortest Path First (OSPFv3)\n")
343{
344  ripng_redistribute_metric_unset (ZEBRA_ROUTE_OSPF6);
345  ripng_redistribute_routemap_unset (ZEBRA_ROUTE_OSPF6);
346  return ripng_redistribute_unset (ZEBRA_ROUTE_OSPF6);
347}
348
349DEFUN (ripng_redistribute_kernel_metric,
350       ripng_redistribute_kernel_metric_cmd,
351       "redistribute kernel metric <0-16>",
352       "Redistribute information from another routing protocol\n"
353       "Kernel routes\n"
354       "Metric\n"
355       "Metric value\n")
356{
357  ripng_redistribute_metric_set (ZEBRA_ROUTE_KERNEL, atoi (argv[0]));
358  zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL);
359  return CMD_SUCCESS;
360}
361
362ALIAS (no_ripng_redistribute_kernel,
363       no_ripng_redistribute_kernel_metric_cmd,
364       "no redistribute kernel metric",
365       NO_STR
366       "Redistribute information from another routing protocol\n"
367       "Kernel routes\n"
368       "Metric\n")
369
370ALIAS (no_ripng_redistribute_kernel,
371       no_ripng_redistribute_kernel_metric_val_cmd,
372       "no redistribute kernel metric <0-16>",
373       NO_STR
374       "Redistribute information from another routing protocol\n"
375       "Kernel routes\n"
376       "Metric\n"
377       "Metric value\n")
378
379DEFUN (ripng_redistribute_connected_metric,
380       ripng_redistribute_connected_metric_cmd,
381       "redistribute connected metric <0-16>",
382       "Redistribute information from another routing protocol\n"
383       "Connected\n"
384       "Metric\n"
385       "Metric value\n")
386{
387  ripng_redistribute_metric_set (ZEBRA_ROUTE_CONNECT, atoi (argv[0]));
388  zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT);
389  return CMD_SUCCESS;
390}
391
392ALIAS (no_ripng_redistribute_connected,
393       no_ripng_redistribute_connected_metric_cmd,
394       "no redistribute connected metric",
395       NO_STR
396       "Redistribute information from another routing protocol\n"
397       "Connected\n"
398       "Metric\n")
399
400ALIAS (no_ripng_redistribute_connected,
401       no_ripng_redistribute_connected_metric_val_cmd,
402       "no redistribute connected metric <0-16>",
403       NO_STR
404       "Redistribute information from another routing protocol\n"
405       "Connected\n"
406       "Metric\n"
407       "Metric value\n")
408
409DEFUN (ripng_redistribute_static_metric,
410       ripng_redistribute_static_metric_cmd,
411       "redistribute static metric <0-16>",
412       "Redistribute information from another routing protocol\n"
413       "Static routes\n"
414       "Metric\n"
415       "Metric value\n")
416{
417  ripng_redistribute_metric_set (ZEBRA_ROUTE_STATIC, atoi (argv[0]));
418  zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC);
419  return CMD_SUCCESS;
420}
421
422ALIAS (no_ripng_redistribute_static,
423       no_ripng_redistribute_static_metric_cmd,
424       "no redistribute static metric",
425       NO_STR
426       "Redistribute information from another routing protocol\n"
427       "Static routes\n"
428       "Metric\n")
429
430ALIAS (no_ripng_redistribute_static,
431       no_ripng_redistribute_static_metric_val_cmd,
432       "no redistribute static metric <0-16>",
433       NO_STR
434       "Redistribute information from another routing protocol\n"
435       "Static routes\n"
436       "Metric\n"
437       "Metric value\n")
438
439DEFUN (ripng_redistribute_ospf6_metric,
440       ripng_redistribute_ospf6_metric_cmd,
441       "redistribute ospf6 metric <0-16>",
442       "Redistribute information from another routing protocol\n"
443       "IPv6 Open Shortest Path First (OSPFv3)\n"
444       "Metric\n"
445       "Metric value\n")
446{
447  ripng_redistribute_metric_set (ZEBRA_ROUTE_OSPF6, atoi (argv[0]));
448  zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6);
449  return CMD_SUCCESS;
450}
451
452ALIAS (no_ripng_redistribute_ospf6,
453       no_ripng_redistribute_ospf6_metric_cmd,
454       "no redistribute ospf6 metric",
455       NO_STR
456       "Redistribute information from another routing protocol\n"
457       "IPv6 Open Shortest Path First (OSPFv3)\n"
458       "Metric\n")
459
460ALIAS (no_ripng_redistribute_ospf6,
461       no_ripng_redistribute_ospf6_metric_val_cmd,
462       "no redistribute ospf6 metric <0-16>",
463       NO_STR
464       "Redistribute information from another routing protocol\n"
465       "IPv6 Open Shortest Path First (OSPFv3)\n"
466       "Metric\n"
467       "Metric value\n")
468
469DEFUN (ripng_redistribute_bgp_metric,
470       ripng_redistribute_bgp_metric_cmd,
471       "redistribute bgp metric <0-16>",
472       "Redistribute information from another routing protocol\n"
473       "Border Gateway Protocol (BGP)\n"
474       "Metric\n"
475       "Metric value\n")
476{
477  ripng_redistribute_metric_set (ZEBRA_ROUTE_BGP, atoi (argv[0]));
478  zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP);
479  return CMD_SUCCESS;
480}
481
482ALIAS (no_ripng_redistribute_bgp,
483       no_ripng_redistribute_bgp_metric_cmd,
484       "no redistribute bgp metric",
485       NO_STR
486       "Redistribute information from another routing protocol\n"
487       "Border Gateway Protocol (BGP)\n"
488       "Metric\n")
489
490ALIAS (no_ripng_redistribute_bgp,
491       no_ripng_redistribute_bgp_metric_val_cmd,
492       "no redistribute bgp metric <0-16>",
493       NO_STR
494       "Redistribute information from another routing protocol\n"
495       "Border Gateway Protocol (BGP)\n"
496       "Metric\n"
497       "Metric value\n")
498
499DEFUN (ripng_redistribute_kernel_routemap,
500       ripng_redistribute_kernel_routemap_cmd,
501       "redistribute kernel route-map WORD",
502       "Redistribute information from another routing protocol\n"
503       "Kernel routes\n"
504       "Route map reference\n"
505       "Pointer to route-map entries\n")
506{
507  ripng_redistribute_routemap_set (ZEBRA_ROUTE_KERNEL, argv[0]);
508  zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL);
509  return CMD_SUCCESS;
510}
511
512ALIAS (no_ripng_redistribute_kernel,
513       no_ripng_redistribute_kernel_routemap_cmd,
514       "no redistribute kernel route-map WORD",
515       NO_STR
516       "Redistribute information from another routing protocol\n"
517       "Kernel routes\n"
518       "Route map reference\n"
519       "Pointer to route-map entries\n")
520
521DEFUN (ripng_redistribute_connected_routemap,
522       ripng_redistribute_connected_routemap_cmd,
523       "redistribute connected route-map WORD",
524       "Redistribute information from another routing protocol\n"
525       "Connected\n"
526       "Route map reference\n"
527       "Pointer to route-map entries\n")
528{
529  ripng_redistribute_routemap_set (ZEBRA_ROUTE_CONNECT, argv[0]);
530  zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT);
531  return CMD_SUCCESS;
532}
533
534ALIAS (no_ripng_redistribute_connected,
535       no_ripng_redistribute_connected_routemap_cmd,
536       "no redistribute connected route-map WORD",
537       NO_STR
538       "Redistribute information from another routing protocol\n"
539       "Connected\n"
540       "Route map reference\n"
541       "Pointer to route-map entries\n")
542
543DEFUN (ripng_redistribute_static_routemap,
544       ripng_redistribute_static_routemap_cmd,
545       "redistribute static route-map WORD",
546       "Redistribute information from another routing protocol\n"
547       "Static routes\n"
548       "Route map reference\n"
549       "Pointer to route-map entries\n")
550{
551  ripng_redistribute_routemap_set (ZEBRA_ROUTE_STATIC, argv[0]);
552  zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC);
553  return CMD_SUCCESS;
554}
555
556ALIAS (no_ripng_redistribute_static,
557       no_ripng_redistribute_static_routemap_cmd,
558       "no redistribute static route-map WORD",
559       NO_STR
560       "Redistribute information from another routing protocol\n"
561       "Static routes\n"
562       "Route map reference\n"
563       "Pointer to route-map entries\n")
564
565DEFUN (ripng_redistribute_ospf6_routemap,
566       ripng_redistribute_ospf6_routemap_cmd,
567       "redistribute ospf6 route-map WORD",
568       "Redistribute information from another routing protocol\n"
569       "IPv6 Open Shortest Path First (OSPFv3)\n"
570       "Route map reference\n"
571       "Pointer to route-map entries\n")
572{
573  ripng_redistribute_routemap_set (ZEBRA_ROUTE_OSPF6, argv[0]);
574  zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6);
575  return CMD_SUCCESS;
576}
577
578ALIAS (no_ripng_redistribute_ospf6,
579       no_ripng_redistribute_ospf6_routemap_cmd,
580       "no redistribute ospf6 route-map WORD",
581       NO_STR
582       "Redistribute information from another routing protocol\n"
583       "IPv6 Open Shortest Path First (OSPFv3)\n"
584       "Route map reference\n"
585       "Pointer to route-map entries\n")
586
587DEFUN (ripng_redistribute_bgp_routemap,
588       ripng_redistribute_bgp_routemap_cmd,
589       "redistribute bgp route-map WORD",
590       "Redistribute information from another routing protocol\n"
591       "Border Gateway Protocol (BGP)\n"
592       "Route map reference\n"
593       "Pointer to route-map entries\n")
594{
595  ripng_redistribute_routemap_set (ZEBRA_ROUTE_BGP, argv[0]);
596  zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP);
597  return CMD_SUCCESS;
598}
599
600ALIAS (no_ripng_redistribute_bgp,
601       no_ripng_redistribute_bgp_routemap_cmd,
602       "no redistribute bgp route-map WORD",
603       NO_STR
604       "Redistribute information from another routing protocol\n"
605       "Border Gateway Protocol (BGP)\n"
606       "Route map reference\n"
607       "Pointer to route-map entries\n")
608
609DEFUN (ripng_redistribute_kernel_metric_routemap,
610       ripng_redistribute_kernel_metric_routemap_cmd,
611       "redistribute kernel metric <0-16> route-map WORD",
612       "Redistribute information from another routing protocol\n"
613       "Kernel routes\n"
614       "Metric\n"
615       "Metric value\n"
616       "Route map reference\n"
617       "Pointer to route-map entries\n")
618{
619  ripng_redistribute_metric_set (ZEBRA_ROUTE_KERNEL, atoi (argv[0]));
620  ripng_redistribute_routemap_set (ZEBRA_ROUTE_KERNEL, argv[1]);
621  zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL);
622  return CMD_SUCCESS;
623}
624
625ALIAS (no_ripng_redistribute_kernel,
626       no_ripng_redistribute_kernel_metric_routemap_cmd,
627       "no redistribute kernel metric <0-16> route-map WORD",
628       NO_STR
629       "Redistribute information from another routing protocol\n"
630       "Kernel routes\n"
631       "Metric\n"
632       "Metric value\n"
633       "Route map reference\n"
634       "Pointer to route-map entries\n")
635
636DEFUN (ripng_redistribute_connected_metric_routemap,
637       ripng_redistribute_connected_metric_routemap_cmd,
638       "redistribute connected metric <0-16> route-map WORD",
639       "Redistribute information from another routing protocol\n"
640       "Connected\n"
641       "Metric\n"
642       "Metric value\n"
643       "Route map reference\n"
644       "Pointer to route-map entries\n")
645{
646  ripng_redistribute_metric_set (ZEBRA_ROUTE_CONNECT, atoi (argv[0]));
647  ripng_redistribute_routemap_set (ZEBRA_ROUTE_CONNECT, argv[1]);
648  zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT);
649  return CMD_SUCCESS;
650}
651
652ALIAS (no_ripng_redistribute_connected,
653       no_ripng_redistribute_connected_metric_routemap_cmd,
654       "no redistribute connected metric <0-16> route-map WORD",
655       NO_STR
656       "Redistribute information from another routing protocol\n"
657       "Connected\n"
658       "Metric\n"
659       "Metric value\n"
660       "Route map reference\n"
661       "Pointer to route-map entries\n")
662
663DEFUN (ripng_redistribute_static_metric_routemap,
664       ripng_redistribute_static_metric_routemap_cmd,
665       "redistribute static metric <0-16> route-map WORD",
666       "Redistribute information from another routing protocol\n"
667       "Static routes\n"
668       "Metric\n"
669       "Metric value\n"
670       "Route map reference\n"
671       "Pointer to route-map entries\n")
672{
673  ripng_redistribute_metric_set (ZEBRA_ROUTE_STATIC, atoi (argv[0]));
674  ripng_redistribute_routemap_set (ZEBRA_ROUTE_STATIC, argv[1]);
675  zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC);
676  return CMD_SUCCESS;
677}
678
679ALIAS (no_ripng_redistribute_static,
680       no_ripng_redistribute_static_metric_routemap_cmd,
681       "no redistribute static metric <0-16> route-map WORD",
682       NO_STR
683       "Redistribute information from another routing protocol\n"
684       "Static routes\n"
685       "Metric\n"
686       "Metric value\n"
687       "Route map reference\n"
688       "Pointer to route-map entries\n")
689
690DEFUN (ripng_redistribute_ospf6_metric_routemap,
691       ripng_redistribute_ospf6_metric_routemap_cmd,
692       "redistribute ospf6 metric <0-16> route-map WORD",
693       "Redistribute information from another routing protocol\n"
694       "IPv6 Open Shortest Path First (OSPFv3)\n"
695       "Metric\n"
696       "Metric value\n"
697       "Route map reference\n"
698       "Pointer to route-map entries\n")
699{
700  ripng_redistribute_metric_set (ZEBRA_ROUTE_OSPF6, atoi (argv[0]));
701  ripng_redistribute_routemap_set (ZEBRA_ROUTE_OSPF6, argv[1]);
702  zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6);
703  return CMD_SUCCESS;
704}
705
706ALIAS (no_ripng_redistribute_ospf6,
707       no_ripng_redistribute_ospf6_metric_routemap_cmd,
708       "no redistribute ospf6 metric <0-16> route-map WORD",
709       NO_STR
710       "Redistribute information from another routing protocol\n"
711       "IPv6 Open Shortest Path First (OSPFv3)\n"
712       "Metric\n"
713       "Metric value\n"
714       "Route map reference\n"
715       "Pointer to route-map entries\n")
716
717DEFUN (ripng_redistribute_bgp_metric_routemap,
718       ripng_redistribute_bgp_metric_routemap_cmd,
719       "redistribute bgp metric <0-16> route-map WORD",
720       "Redistribute information from another routing protocol\n"
721       "Border Gateway Protocol (BGP)\n"
722       "Metric\n"
723       "Metric value\n"
724       "Route map reference\n"
725       "Pointer to route-map entries\n")
726{
727  ripng_redistribute_metric_set (ZEBRA_ROUTE_BGP, atoi (argv[0]));
728  ripng_redistribute_routemap_set (ZEBRA_ROUTE_BGP, argv[1]);
729  zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP);
730  return CMD_SUCCESS;
731}
732
733ALIAS (no_ripng_redistribute_bgp,
734       no_ripng_redistribute_bgp_metric_routemap_cmd,
735       "no redistribute bgp metric <0-16> route-map WORD",
736       NO_STR
737       "Redistribute information from another routing protocol\n"
738       "Border Gateway Protocol (BGP)\n"
739       "Metric\n"
740       "Metric value\n"
741       "Route map reference\n"
742       "Pointer to route-map entries\n")
743
744void
745ripng_redistribute_write (struct vty *vty)
746{
747  int i;
748  char *str[] = { "system", "kernel", "connected", "static", "rip",
749		  "ripng", "ospf", "ospf6", "bgp"};
750
751  for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
752    if (i != zclient->redist_default && zclient->redist[i])
753      {
754	if (ripng->route_map[i].metric_config)
755	  {
756	    if (ripng->route_map[i].name)
757	      vty_out (vty, " redistribute %s metric %d route-map %s%s",
758		       str[i], ripng->route_map[i].metric,
759		       ripng->route_map[i].name, VTY_NEWLINE);
760	    else
761	      vty_out (vty, " redistribute %s metric %d%s",
762		       str[i], ripng->route_map[i].metric, VTY_NEWLINE);
763	  }
764	else
765	  {
766	    if (ripng->route_map[i].name)
767	      vty_out (vty, " redistribute %s route-map %s%s",
768		       str[i], ripng->route_map[i].name, VTY_NEWLINE);
769	    else
770	      vty_out (vty, " redistribute %s%s", str[i], VTY_NEWLINE);
771	  }
772      }
773}
774
775/* RIPng configuration write function. */
776int
777zebra_config_write (struct vty *vty)
778{
779  if (! zclient->enable)
780    {
781      vty_out (vty, "no router zebra%s", VTY_NEWLINE);
782      return 1;
783    }
784  else if (! zclient->redist[ZEBRA_ROUTE_RIPNG])
785    {
786      vty_out (vty, "router zebra%s", VTY_NEWLINE);
787      vty_out (vty, " no redistribute ripng%s", VTY_NEWLINE);
788      return 1;
789    }
790  return 0;
791}
792
793/* Zebra node structure. */
794struct cmd_node zebra_node =
795{
796  ZEBRA_NODE,
797  "%s(config-router)# ",
798};
799
800/* Initialize zebra structure and it's commands. */
801void
802zebra_init ()
803{
804  /* Allocate zebra structure. */
805  zclient = zclient_new ();
806  zclient_init (zclient, ZEBRA_ROUTE_RIPNG);
807
808  zclient->interface_up = ripng_interface_up;
809  zclient->interface_down = ripng_interface_down;
810  zclient->interface_add = ripng_interface_add;
811  zclient->interface_delete = ripng_interface_delete;
812  zclient->interface_address_add = ripng_interface_address_add;
813  zclient->interface_address_delete = ripng_interface_address_delete;
814  zclient->ipv6_route_add = ripng_zebra_read_ipv6;
815  zclient->ipv6_route_delete = ripng_zebra_read_ipv6;
816
817  /* Install zebra node. */
818  install_node (&zebra_node, zebra_config_write);
819
820  /* Install command element for zebra node. */
821  install_element (CONFIG_NODE, &router_zebra_cmd);
822  install_element (CONFIG_NODE, &no_router_zebra_cmd);
823  install_default (ZEBRA_NODE);
824  install_element (ZEBRA_NODE, &ripng_redistribute_ripng_cmd);
825  install_element (ZEBRA_NODE, &no_ripng_redistribute_ripng_cmd);
826  install_element (RIPNG_NODE, &ripng_redistribute_static_cmd);
827  install_element (RIPNG_NODE, &no_ripng_redistribute_static_cmd);
828  install_element (RIPNG_NODE, &ripng_redistribute_kernel_cmd);
829  install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_cmd);
830  install_element (RIPNG_NODE, &ripng_redistribute_connected_cmd);
831  install_element (RIPNG_NODE, &no_ripng_redistribute_connected_cmd);
832  install_element (RIPNG_NODE, &ripng_redistribute_bgp_cmd);
833  install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_cmd);
834  install_element (RIPNG_NODE, &ripng_redistribute_ospf6_cmd);
835  install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_cmd);
836  install_element (RIPNG_NODE, &ripng_redistribute_kernel_metric_cmd);
837  install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_metric_cmd);
838  install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_metric_val_cmd);
839  install_element (RIPNG_NODE, &ripng_redistribute_connected_metric_cmd);
840  install_element (RIPNG_NODE, &no_ripng_redistribute_connected_metric_cmd);
841  install_element (RIPNG_NODE,
842		   &no_ripng_redistribute_connected_metric_val_cmd);
843  install_element (RIPNG_NODE, &ripng_redistribute_static_metric_cmd);
844  install_element (RIPNG_NODE, &no_ripng_redistribute_static_metric_cmd);
845  install_element (RIPNG_NODE, &no_ripng_redistribute_static_metric_val_cmd);
846  install_element (RIPNG_NODE, &ripng_redistribute_ospf6_metric_cmd);
847  install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_metric_cmd);
848  install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_metric_val_cmd);
849  install_element (RIPNG_NODE, &ripng_redistribute_bgp_metric_cmd);
850  install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_metric_cmd);
851  install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_metric_val_cmd);
852  install_element (RIPNG_NODE, &ripng_redistribute_kernel_routemap_cmd);
853  install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_routemap_cmd);
854  install_element (RIPNG_NODE, &ripng_redistribute_connected_routemap_cmd);
855  install_element (RIPNG_NODE, &no_ripng_redistribute_connected_routemap_cmd);
856  install_element (RIPNG_NODE, &ripng_redistribute_static_routemap_cmd);
857  install_element (RIPNG_NODE, &no_ripng_redistribute_static_routemap_cmd);
858  install_element (RIPNG_NODE, &ripng_redistribute_ospf6_routemap_cmd);
859  install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_routemap_cmd);
860  install_element (RIPNG_NODE, &ripng_redistribute_bgp_routemap_cmd);
861  install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_routemap_cmd);
862  install_element (RIPNG_NODE, &ripng_redistribute_kernel_metric_routemap_cmd);
863  install_element (RIPNG_NODE,
864		   &no_ripng_redistribute_kernel_metric_routemap_cmd);
865  install_element (RIPNG_NODE,
866		   &ripng_redistribute_connected_metric_routemap_cmd);
867  install_element (RIPNG_NODE,
868		   &no_ripng_redistribute_connected_metric_routemap_cmd);
869  install_element (RIPNG_NODE, &ripng_redistribute_static_metric_routemap_cmd);
870  install_element (RIPNG_NODE,
871		   &no_ripng_redistribute_static_metric_routemap_cmd);
872  install_element (RIPNG_NODE, &ripng_redistribute_ospf6_metric_routemap_cmd);
873  install_element (RIPNG_NODE,
874		   &no_ripng_redistribute_ospf6_metric_routemap_cmd);
875  install_element (RIPNG_NODE, &ripng_redistribute_bgp_metric_routemap_cmd);
876  install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_metric_routemap_cmd);
877}
878