summaryrefslogtreecommitdiff
path: root/ripngd/ripng_zebra.c
blob: 4d8a48d314121f972c9ac67bfe1338649bc4acb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
/*
 * RIPngd and zebra interface.
 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
 *
 * This file is part of GNU Zebra.
 *
 * GNU Zebra is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * GNU Zebra is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Zebra; see the file COPYING.  If not, write to the Free
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.  
 */

#include <zebra.h>

#include "command.h"
#include "prefix.h"
#include "stream.h"
#include "routemap.h"
#include "zclient.h"
#include "log.h"

#include "ripngd/ripngd.h"

/* All information about zebra. */
struct zclient *zclient = NULL;

/* Callback prototypes for zebra client service. */
int ripng_interface_up (int, struct zclient *, zebra_size_t);
int ripng_interface_down (int, struct zclient *, zebra_size_t);
int ripng_interface_add (int, struct zclient *, zebra_size_t);
int ripng_interface_delete (int, struct zclient *, zebra_size_t);
int ripng_interface_address_add (int, struct zclient *, zebra_size_t);
int ripng_interface_address_delete (int, struct zclient *, zebra_size_t);

void
ripng_zebra_ipv6_add (struct prefix_ipv6 *p, struct in6_addr *nexthop,
		      unsigned int ifindex)
{
  struct zapi_ipv6 api;

  if (zclient->redist[ZEBRA_ROUTE_RIPNG])
    {
      api.type = ZEBRA_ROUTE_RIPNG;
      api.flags = 0;
      api.message = 0;
      SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
      api.nexthop_num = 1;
      api.nexthop = &nexthop;
      SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
      api.ifindex_num = 1;
      api.ifindex = &ifindex;

      zapi_ipv6_add (zclient, p, &api);
    }
}

void
ripng_zebra_ipv6_delete (struct prefix_ipv6 *p, struct in6_addr *nexthop,
			 unsigned int ifindex)
{
  struct zapi_ipv6 api;

  if (zclient->redist[ZEBRA_ROUTE_RIPNG])
    {
      api.type = ZEBRA_ROUTE_RIPNG;
      api.flags = 0;
      api.message = 0;
      SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
      api.nexthop_num = 1;
      api.nexthop = &nexthop;
      SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
      api.ifindex_num = 1;
      api.ifindex = &ifindex;

      zapi_ipv6_delete (zclient, p, &api);
    }
}

/* Zebra route add and delete treatment. */
int
ripng_zebra_read_ipv6 (int command, struct zclient *zclient,
		       zebra_size_t length)
{
  struct stream *s;
  struct zapi_ipv6 api;
  unsigned long ifindex;
  struct in6_addr nexthop;
  struct prefix_ipv6 p;

  s = zclient->ibuf;
  ifindex = 0;
  memset (&nexthop, 0, sizeof (struct in6_addr));

  /* Type, flags, message. */
  api.type = stream_getc (s);
  api.flags = stream_getc (s);
  api.message = stream_getc (s);

  /* IPv6 prefix. */
  memset (&p, 0, sizeof (struct prefix_ipv6));
  p.family = AF_INET6;
  p.prefixlen = stream_getc (s);
  stream_get (&p.prefix, s, PSIZE (p.prefixlen));

  /* Nexthop, ifindex, distance, metric. */
  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
    {
      api.nexthop_num = stream_getc (s);
      stream_get (&nexthop, s, 16);
    }
  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
    {
      api.ifindex_num = stream_getc (s);
      ifindex = stream_getl (s);
    }
  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
    api.distance = stream_getc (s);
  else
    api.distance = 0;
  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
    api.metric = stream_getl (s);
  else
    api.metric = 0;

  if (command == ZEBRA_IPV6_ROUTE_ADD)
    ripng_redistribute_add (api.type, 0, &p, ifindex);
  else
    ripng_redistribute_delete (api.type, 0, &p, ifindex);

  return 0;
}

int
ripng_redistribute_unset (int type)
{
  if (! zclient->redist[type])
    return CMD_SUCCESS;

  zclient->redist[type] = 0;

  if (zclient->sock > 0)
    zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient->sock, type);

  ripng_redistribute_withdraw (type);
  
  return CMD_SUCCESS;
}

void
ripng_redistribute_metric_set (int type, int metric)
{
  ripng->route_map[type].metric_config = 1;
  ripng->route_map[type].metric = metric;
}

void
ripng_redistribute_metric_unset (int type)
{
  ripng->route_map[type].metric_config = 0;
  ripng->route_map[type].metric = 0;
}

void
ripng_redistribute_routemap_set (int type, char *name)
{
  if (ripng->route_map[type].name)
    free (ripng->route_map[type].name);

  ripng->route_map[type].name = strdup (name);
  ripng->route_map[type].map = route_map_lookup_by_name (name);
}

void
ripng_redistribute_routemap_unset (int type)
{
  if (ripng->route_map[type].name)
    free (ripng->route_map[type].name);

  ripng->route_map[type].name = NULL;
  ripng->route_map[type].map = NULL;
}


DEFUN (router_zebra,
       router_zebra_cmd,
       "router zebra",
       "Enable a routing process\n"
       "Make connection to zebra daemon\n")
{
  vty->node = ZEBRA_NODE;
  zclient->enable = 1;
  zclient_start (zclient);
  return CMD_SUCCESS;
}

DEFUN (no_router_zebra,
       no_router_zebra_cmd,
       "no router zebra",
       NO_STR
       "Disable a routing process\n"
       "Stop connection to zebra daemon\n")
{
  zclient->enable = 0;
  zclient_stop (zclient);
  return CMD_SUCCESS;
}

DEFUN (ripng_redistribute_ripng,
       ripng_redistribute_ripng_cmd,
       "redistribute ripng",
       "Redistribute information from another routing protocol\n"
       "RIPng route\n")
{
  zclient->redist[ZEBRA_ROUTE_RIPNG] = 1;
  return CMD_SUCCESS;
}

DEFUN (no_ripng_redistribute_ripng,
       no_ripng_redistribute_ripng_cmd,
       "no redistribute ripng",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "RIPng route\n")
{
  zclient->redist[ZEBRA_ROUTE_RIPNG] = 0;
  return CMD_SUCCESS;
}

DEFUN (ripng_redistribute_static,
       ripng_redistribute_static_cmd,
       "redistribute static",
       "Redistribute information from another routing protocol\n"
       "Static routes\n")
{
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC);
  return CMD_SUCCESS;
}

DEFUN (no_ripng_redistribute_static,
       no_ripng_redistribute_static_cmd,
       "no redistribute static",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Static routes\n")
{
  ripng_redistribute_metric_unset (ZEBRA_ROUTE_STATIC);
  ripng_redistribute_routemap_unset (ZEBRA_ROUTE_STATIC);
  return ripng_redistribute_unset (ZEBRA_ROUTE_STATIC);
}

DEFUN (ripng_redistribute_kernel,
       ripng_redistribute_kernel_cmd,
       "redistribute kernel",
       "Redistribute information from another routing protocol\n"
       "Kernel routes\n")
{
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL);
  return CMD_SUCCESS;
}

DEFUN (no_ripng_redistribute_kernel,
       no_ripng_redistribute_kernel_cmd,
       "no redistribute kernel",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Kernel routes\n")
{
  ripng_redistribute_metric_unset (ZEBRA_ROUTE_KERNEL);
  ripng_redistribute_routemap_unset (ZEBRA_ROUTE_KERNEL);
  return ripng_redistribute_unset (ZEBRA_ROUTE_KERNEL);
}

DEFUN (ripng_redistribute_connected,
       ripng_redistribute_connected_cmd,
       "redistribute connected",
       "Redistribute information from another routing protocol\n"
       "Connected\n")
{
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT);
  return CMD_SUCCESS;
}

DEFUN (no_ripng_redistribute_connected,
       no_ripng_redistribute_connected_cmd,
       "no redistribute connected",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Connected\n")
{
  ripng_redistribute_metric_unset (ZEBRA_ROUTE_CONNECT);
  ripng_redistribute_routemap_unset (ZEBRA_ROUTE_CONNECT);
  return ripng_redistribute_unset (ZEBRA_ROUTE_CONNECT);
}

DEFUN (ripng_redistribute_bgp,
       ripng_redistribute_bgp_cmd,
       "redistribute bgp",
       "Redistribute information from another routing protocol\n"
       "Border Gateway Protocol (BGP)\n")
{
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP);
  return CMD_SUCCESS;
}

DEFUN (no_ripng_redistribute_bgp,
       no_ripng_redistribute_bgp_cmd,
       "no redistribute bgp",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Border Gateway Protocol (BGP)\n")
{
  ripng_redistribute_metric_unset (ZEBRA_ROUTE_BGP);
  ripng_redistribute_routemap_unset (ZEBRA_ROUTE_BGP);
  return ripng_redistribute_unset (ZEBRA_ROUTE_BGP);
}

DEFUN (ripng_redistribute_ospf6,
       ripng_redistribute_ospf6_cmd,
       "redistribute ospf6",
       "Redistribute information from another routing protocol\n"
       "IPv6 Open Shortest Path First (OSPFv3)\n")
{
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6);
  return CMD_SUCCESS;
}

DEFUN (no_ripng_redistribute_ospf6,
       no_ripng_redistribute_ospf6_cmd,
       "no redistribute ospf6",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "IPv6 Open Shortest Path First (OSPFv3)\n")
{
  ripng_redistribute_metric_unset (ZEBRA_ROUTE_OSPF6);
  ripng_redistribute_routemap_unset (ZEBRA_ROUTE_OSPF6);
  return ripng_redistribute_unset (ZEBRA_ROUTE_OSPF6);
}

DEFUN (ripng_redistribute_kernel_metric,
       ripng_redistribute_kernel_metric_cmd,
       "redistribute kernel metric <0-16>",
       "Redistribute information from another routing protocol\n"
       "Kernel routes\n"
       "Metric\n"
       "Metric value\n")
{
  ripng_redistribute_metric_set (ZEBRA_ROUTE_KERNEL, atoi (argv[0]));
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_kernel,
       no_ripng_redistribute_kernel_metric_cmd,
       "no redistribute kernel metric",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Kernel routes\n"
       "Metric\n")

ALIAS (no_ripng_redistribute_kernel,
       no_ripng_redistribute_kernel_metric_val_cmd,
       "no redistribute kernel metric <0-16>",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Kernel routes\n"
       "Metric\n"
       "Metric value\n")

DEFUN (ripng_redistribute_connected_metric,
       ripng_redistribute_connected_metric_cmd,
       "redistribute connected metric <0-16>",
       "Redistribute information from another routing protocol\n"
       "Connected\n"
       "Metric\n"
       "Metric value\n")
{
  ripng_redistribute_metric_set (ZEBRA_ROUTE_CONNECT, atoi (argv[0]));
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_connected,
       no_ripng_redistribute_connected_metric_cmd,
       "no redistribute connected metric",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Connected\n"
       "Metric\n")

ALIAS (no_ripng_redistribute_connected,
       no_ripng_redistribute_connected_metric_val_cmd,
       "no redistribute connected metric <0-16>",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Connected\n"
       "Metric\n"
       "Metric value\n")

DEFUN (ripng_redistribute_static_metric,
       ripng_redistribute_static_metric_cmd,
       "redistribute static metric <0-16>",
       "Redistribute information from another routing protocol\n"
       "Static routes\n"
       "Metric\n"
       "Metric value\n")
{
  ripng_redistribute_metric_set (ZEBRA_ROUTE_STATIC, atoi (argv[0]));
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_static,
       no_ripng_redistribute_static_metric_cmd,
       "no redistribute static metric",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Static routes\n"
       "Metric\n")

ALIAS (no_ripng_redistribute_static,
       no_ripng_redistribute_static_metric_val_cmd,
       "no redistribute static metric <0-16>",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Static routes\n"
       "Metric\n"
       "Metric value\n")

DEFUN (ripng_redistribute_ospf6_metric,
       ripng_redistribute_ospf6_metric_cmd,
       "redistribute ospf6 metric <0-16>",
       "Redistribute information from another routing protocol\n"
       "IPv6 Open Shortest Path First (OSPFv3)\n"
       "Metric\n"
       "Metric value\n")
{
  ripng_redistribute_metric_set (ZEBRA_ROUTE_OSPF6, atoi (argv[0]));
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_ospf6,
       no_ripng_redistribute_ospf6_metric_cmd,
       "no redistribute ospf6 metric",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "IPv6 Open Shortest Path First (OSPFv3)\n"
       "Metric\n")

ALIAS (no_ripng_redistribute_ospf6,
       no_ripng_redistribute_ospf6_metric_val_cmd,
       "no redistribute ospf6 metric <0-16>",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "IPv6 Open Shortest Path First (OSPFv3)\n"
       "Metric\n"
       "Metric value\n")

DEFUN (ripng_redistribute_bgp_metric,
       ripng_redistribute_bgp_metric_cmd,
       "redistribute bgp metric <0-16>",
       "Redistribute information from another routing protocol\n"
       "Border Gateway Protocol (BGP)\n"
       "Metric\n"
       "Metric value\n")
{
  ripng_redistribute_metric_set (ZEBRA_ROUTE_BGP, atoi (argv[0]));
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_bgp,
       no_ripng_redistribute_bgp_metric_cmd,
       "no redistribute bgp metric",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Border Gateway Protocol (BGP)\n"
       "Metric\n")

ALIAS (no_ripng_redistribute_bgp,
       no_ripng_redistribute_bgp_metric_val_cmd,
       "no redistribute bgp metric <0-16>",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Border Gateway Protocol (BGP)\n"
       "Metric\n"
       "Metric value\n")

DEFUN (ripng_redistribute_kernel_routemap,
       ripng_redistribute_kernel_routemap_cmd,
       "redistribute kernel route-map WORD",
       "Redistribute information from another routing protocol\n"
       "Kernel routes\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")
{
  ripng_redistribute_routemap_set (ZEBRA_ROUTE_KERNEL, argv[0]);
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_kernel,
       no_ripng_redistribute_kernel_routemap_cmd,
       "no redistribute kernel route-map WORD",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Kernel routes\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")

DEFUN (ripng_redistribute_connected_routemap,
       ripng_redistribute_connected_routemap_cmd,
       "redistribute connected route-map WORD",
       "Redistribute information from another routing protocol\n"
       "Connected\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")
{
  ripng_redistribute_routemap_set (ZEBRA_ROUTE_CONNECT, argv[0]);
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_connected,
       no_ripng_redistribute_connected_routemap_cmd,
       "no redistribute connected route-map WORD",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Connected\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")

DEFUN (ripng_redistribute_static_routemap,
       ripng_redistribute_static_routemap_cmd,
       "redistribute static route-map WORD",
       "Redistribute information from another routing protocol\n"
       "Static routes\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")
{
  ripng_redistribute_routemap_set (ZEBRA_ROUTE_STATIC, argv[0]);
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_static,
       no_ripng_redistribute_static_routemap_cmd,
       "no redistribute static route-map WORD",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Static routes\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")

DEFUN (ripng_redistribute_ospf6_routemap,
       ripng_redistribute_ospf6_routemap_cmd,
       "redistribute ospf6 route-map WORD",
       "Redistribute information from another routing protocol\n"
       "IPv6 Open Shortest Path First (OSPFv3)\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")
{
  ripng_redistribute_routemap_set (ZEBRA_ROUTE_OSPF6, argv[0]);
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_ospf6,
       no_ripng_redistribute_ospf6_routemap_cmd,
       "no redistribute ospf6 route-map WORD",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "IPv6 Open Shortest Path First (OSPFv3)\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")

DEFUN (ripng_redistribute_bgp_routemap,
       ripng_redistribute_bgp_routemap_cmd,
       "redistribute bgp route-map WORD",
       "Redistribute information from another routing protocol\n"
       "Border Gateway Protocol (BGP)\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")
{
  ripng_redistribute_routemap_set (ZEBRA_ROUTE_BGP, argv[0]);
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_bgp,
       no_ripng_redistribute_bgp_routemap_cmd,
       "no redistribute bgp route-map WORD",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Border Gateway Protocol (BGP)\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")

DEFUN (ripng_redistribute_kernel_metric_routemap,
       ripng_redistribute_kernel_metric_routemap_cmd,
       "redistribute kernel metric <0-16> route-map WORD",
       "Redistribute information from another routing protocol\n"
       "Kernel routes\n"
       "Metric\n"
       "Metric value\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")
{
  ripng_redistribute_metric_set (ZEBRA_ROUTE_KERNEL, atoi (argv[0]));
  ripng_redistribute_routemap_set (ZEBRA_ROUTE_KERNEL, argv[1]);
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_KERNEL);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_kernel,
       no_ripng_redistribute_kernel_metric_routemap_cmd,
       "no redistribute kernel metric <0-16> route-map WORD",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Kernel routes\n"
       "Metric\n"
       "Metric value\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")

DEFUN (ripng_redistribute_connected_metric_routemap,
       ripng_redistribute_connected_metric_routemap_cmd,
       "redistribute connected metric <0-16> route-map WORD",
       "Redistribute information from another routing protocol\n"
       "Connected\n"
       "Metric\n"
       "Metric value\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")
{
  ripng_redistribute_metric_set (ZEBRA_ROUTE_CONNECT, atoi (argv[0]));
  ripng_redistribute_routemap_set (ZEBRA_ROUTE_CONNECT, argv[1]);
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_CONNECT);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_connected,
       no_ripng_redistribute_connected_metric_routemap_cmd,
       "no redistribute connected metric <0-16> route-map WORD",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Connected\n"
       "Metric\n"
       "Metric value\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")

DEFUN (ripng_redistribute_static_metric_routemap,
       ripng_redistribute_static_metric_routemap_cmd,
       "redistribute static metric <0-16> route-map WORD",
       "Redistribute information from another routing protocol\n"
       "Static routes\n"
       "Metric\n"
       "Metric value\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")
{
  ripng_redistribute_metric_set (ZEBRA_ROUTE_STATIC, atoi (argv[0]));
  ripng_redistribute_routemap_set (ZEBRA_ROUTE_STATIC, argv[1]);
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_STATIC);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_static,
       no_ripng_redistribute_static_metric_routemap_cmd,
       "no redistribute static metric <0-16> route-map WORD",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Static routes\n"
       "Metric\n"
       "Metric value\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")

DEFUN (ripng_redistribute_ospf6_metric_routemap,
       ripng_redistribute_ospf6_metric_routemap_cmd,
       "redistribute ospf6 metric <0-16> route-map WORD",
       "Redistribute information from another routing protocol\n"
       "IPv6 Open Shortest Path First (OSPFv3)\n"
       "Metric\n"
       "Metric value\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")
{
  ripng_redistribute_metric_set (ZEBRA_ROUTE_OSPF6, atoi (argv[0]));
  ripng_redistribute_routemap_set (ZEBRA_ROUTE_OSPF6, argv[1]);
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_OSPF6);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_ospf6,
       no_ripng_redistribute_ospf6_metric_routemap_cmd,
       "no redistribute ospf6 metric <0-16> route-map WORD",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "IPv6 Open Shortest Path First (OSPFv3)\n"
       "Metric\n"
       "Metric value\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")

DEFUN (ripng_redistribute_bgp_metric_routemap,
       ripng_redistribute_bgp_metric_routemap_cmd,
       "redistribute bgp metric <0-16> route-map WORD",
       "Redistribute information from another routing protocol\n"
       "Border Gateway Protocol (BGP)\n"
       "Metric\n"
       "Metric value\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")
{
  ripng_redistribute_metric_set (ZEBRA_ROUTE_BGP, atoi (argv[0]));
  ripng_redistribute_routemap_set (ZEBRA_ROUTE_BGP, argv[1]);
  zclient_redistribute_set (zclient, ZEBRA_ROUTE_BGP);
  return CMD_SUCCESS;
}

ALIAS (no_ripng_redistribute_bgp,
       no_ripng_redistribute_bgp_metric_routemap_cmd,
       "no redistribute bgp metric <0-16> route-map WORD",
       NO_STR
       "Redistribute information from another routing protocol\n"
       "Border Gateway Protocol (BGP)\n"
       "Metric\n"
       "Metric value\n"
       "Route map reference\n"
       "Pointer to route-map entries\n")

void
ripng_redistribute_write (struct vty *vty)
{
  int i;
  char *str[] = { "system", "kernel", "connected", "static", "rip",
		  "ripng", "ospf", "ospf6", "bgp"};

  for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
    if (i != zclient->redist_default && zclient->redist[i])
      {
	if (ripng->route_map[i].metric_config)
	  {
	    if (ripng->route_map[i].name)
	      vty_out (vty, " redistribute %s metric %d route-map %s%s",
		       str[i], ripng->route_map[i].metric,
		       ripng->route_map[i].name, VTY_NEWLINE);
	    else
	      vty_out (vty, " redistribute %s metric %d%s",
		       str[i], ripng->route_map[i].metric, VTY_NEWLINE);
	  }
	else
	  {
	    if (ripng->route_map[i].name)
	      vty_out (vty, " redistribute %s route-map %s%s",
		       str[i], ripng->route_map[i].name, VTY_NEWLINE);
	    else
	      vty_out (vty, " redistribute %s%s", str[i], VTY_NEWLINE);
	  }
      }
}

/* RIPng configuration write function. */
int
zebra_config_write (struct vty *vty)
{
  if (! zclient->enable)
    {
      vty_out (vty, "no router zebra%s", VTY_NEWLINE);
      return 1;
    }
  else if (! zclient->redist[ZEBRA_ROUTE_RIPNG])
    {
      vty_out (vty, "router zebra%s", VTY_NEWLINE);
      vty_out (vty, " no redistribute ripng%s", VTY_NEWLINE);
      return 1;
    }
  return 0;
}

/* Zebra node structure. */
struct cmd_node zebra_node =
{
  ZEBRA_NODE,
  "%s(config-router)# ",
};

/* Initialize zebra structure and it's commands. */
void
zebra_init ()
{
  /* Allocate zebra structure. */
  zclient = zclient_new ();
  zclient_init (zclient, ZEBRA_ROUTE_RIPNG);

  zclient->interface_up = ripng_interface_up;
  zclient->interface_down = ripng_interface_down;
  zclient->interface_add = ripng_interface_add;
  zclient->interface_delete = ripng_interface_delete;
  zclient->interface_address_add = ripng_interface_address_add;
  zclient->interface_address_delete = ripng_interface_address_delete;
  zclient->ipv6_route_add = ripng_zebra_read_ipv6;
  zclient->ipv6_route_delete = ripng_zebra_read_ipv6;
  
  /* Install zebra node. */
  install_node (&zebra_node, zebra_config_write);

  /* Install command element for zebra node. */ 
  install_element (CONFIG_NODE, &router_zebra_cmd);
  install_element (CONFIG_NODE, &no_router_zebra_cmd);
  install_default (ZEBRA_NODE);
  install_element (ZEBRA_NODE, &ripng_redistribute_ripng_cmd);
  install_element (ZEBRA_NODE, &no_ripng_redistribute_ripng_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_static_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_static_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_kernel_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_connected_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_connected_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_bgp_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_ospf6_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_kernel_metric_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_metric_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_metric_val_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_connected_metric_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_connected_metric_cmd);
  install_element (RIPNG_NODE,
		   &no_ripng_redistribute_connected_metric_val_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_static_metric_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_static_metric_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_static_metric_val_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_ospf6_metric_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_metric_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_metric_val_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_bgp_metric_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_metric_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_metric_val_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_kernel_routemap_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_kernel_routemap_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_connected_routemap_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_connected_routemap_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_static_routemap_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_static_routemap_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_ospf6_routemap_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_ospf6_routemap_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_bgp_routemap_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_routemap_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_kernel_metric_routemap_cmd);
  install_element (RIPNG_NODE,
		   &no_ripng_redistribute_kernel_metric_routemap_cmd);
  install_element (RIPNG_NODE,
		   &ripng_redistribute_connected_metric_routemap_cmd);
  install_element (RIPNG_NODE,
		   &no_ripng_redistribute_connected_metric_routemap_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_static_metric_routemap_cmd);
  install_element (RIPNG_NODE,
		   &no_ripng_redistribute_static_metric_routemap_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_ospf6_metric_routemap_cmd);
  install_element (RIPNG_NODE,
		   &no_ripng_redistribute_ospf6_metric_routemap_cmd);
  install_element (RIPNG_NODE, &ripng_redistribute_bgp_metric_routemap_cmd);
  install_element (RIPNG_NODE, &no_ripng_redistribute_bgp_metric_routemap_cmd);
}