lib: put route_types.txt to real use

this replaces most occurences of routing protocol lists by preprocessor
defines from route_types.h. the latter is autogenerated from
route_types.txt by a perl script (previously awk). adding a routing
protocol now is mostly a matter of changing route_types.txt and log.c.

Conflicts:

	lib/route_types.awk
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 439aeeb..f65bb15 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -8373,57 +8373,16 @@
 
 /* Redistribute VTY commands.  */
 
-/* Utility function to convert user input route type string to route
-   type.  */
-static int
-bgp_str2route_type (int afi, const char *str)
-{
-  if (! str)
-    return 0;
-
-  if (afi == AFI_IP)
-    {
-      if (strncmp (str, "k", 1) == 0)
-	return ZEBRA_ROUTE_KERNEL;
-      else if (strncmp (str, "c", 1) == 0)
-	return ZEBRA_ROUTE_CONNECT;
-      else if (strncmp (str, "s", 1) == 0)
-	return ZEBRA_ROUTE_STATIC;
-      else if (strncmp (str, "r", 1) == 0)
-	return ZEBRA_ROUTE_RIP;
-      else if (strncmp (str, "o", 1) == 0)
-	return ZEBRA_ROUTE_OSPF;
-    }
-  if (afi == AFI_IP6)
-    {
-      if (strncmp (str, "k", 1) == 0)
-	return ZEBRA_ROUTE_KERNEL;
-      else if (strncmp (str, "c", 1) == 0)
-	return ZEBRA_ROUTE_CONNECT;
-      else if (strncmp (str, "s", 1) == 0)
-	return ZEBRA_ROUTE_STATIC;
-      else if (strncmp (str, "r", 1) == 0)
-	return ZEBRA_ROUTE_RIPNG;
-      else if (strncmp (str, "o", 1) == 0)
-	return ZEBRA_ROUTE_OSPF6;
-    }
-  return 0;
-}
-
 DEFUN (bgp_redistribute_ipv4,
        bgp_redistribute_ipv4_cmd,
-       "redistribute (connected|kernel|ospf|rip|static)",
+       "redistribute " QUAGGA_IP_REDIST_STR_BGPD,
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n")
+       QUAGGA_IP_REDIST_HELP_STR_BGPD)
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8433,20 +8392,16 @@
 
 DEFUN (bgp_redistribute_ipv4_rmap,
        bgp_redistribute_ipv4_rmap_cmd,
-       "redistribute (connected|kernel|ospf|rip|static) route-map WORD",
+       "redistribute " QUAGGA_IP_REDIST_STR_BGPD " route-map WORD",
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n"
+       QUAGGA_IP_REDIST_HELP_STR_BGPD
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8458,21 +8413,17 @@
 
 DEFUN (bgp_redistribute_ipv4_metric,
        bgp_redistribute_ipv4_metric_cmd,
-       "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>",
+       "redistribute " QUAGGA_IP_REDIST_STR_BGPD " metric <0-4294967295>",
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n"
+       QUAGGA_IP_REDIST_HELP_STR_BGPD
        "Metric for redistributed routes\n"
        "Default metric\n")
 {
   int type;
   u_int32_t metric;
 
-  type = bgp_str2route_type (AFI_IP, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8485,13 +8436,9 @@
 
 DEFUN (bgp_redistribute_ipv4_rmap_metric,
        bgp_redistribute_ipv4_rmap_metric_cmd,
-       "redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>",
+       "redistribute " QUAGGA_IP_REDIST_STR_BGPD " route-map WORD metric <0-4294967295>",
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n"
+       QUAGGA_IP_REDIST_HELP_STR_BGPD
        "Route map reference\n"
        "Pointer to route-map entries\n"
        "Metric for redistributed routes\n"
@@ -8500,8 +8447,8 @@
   int type;
   u_int32_t metric;
 
-  type = bgp_str2route_type (AFI_IP, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8515,13 +8462,9 @@
 
 DEFUN (bgp_redistribute_ipv4_metric_rmap,
        bgp_redistribute_ipv4_metric_rmap_cmd,
-       "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD",
+       "redistribute " QUAGGA_IP_REDIST_STR_BGPD " metric <0-4294967295> route-map WORD",
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n"
+       QUAGGA_IP_REDIST_HELP_STR_BGPD
        "Metric for redistributed routes\n"
        "Default metric\n"
        "Route map reference\n"
@@ -8530,8 +8473,8 @@
   int type;
   u_int32_t metric;
 
-  type = bgp_str2route_type (AFI_IP, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8545,19 +8488,15 @@
 
 DEFUN (no_bgp_redistribute_ipv4,
        no_bgp_redistribute_ipv4_cmd,
-       "no redistribute (connected|kernel|ospf|rip|static)",
+       "no redistribute " QUAGGA_IP_REDIST_STR_BGPD,
        NO_STR
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n")
+       QUAGGA_IP_REDIST_HELP_STR_BGPD)
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8568,21 +8507,17 @@
 
 DEFUN (no_bgp_redistribute_ipv4_rmap,
        no_bgp_redistribute_ipv4_rmap_cmd,
-       "no redistribute (connected|kernel|ospf|rip|static) route-map WORD",
+       "no redistribute " QUAGGA_IP_REDIST_STR_BGPD " route-map WORD",
        NO_STR
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n"
+       QUAGGA_IP_REDIST_HELP_STR_BGPD
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8594,21 +8529,17 @@
 
 DEFUN (no_bgp_redistribute_ipv4_metric,
        no_bgp_redistribute_ipv4_metric_cmd,
-       "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>",
+       "no redistribute " QUAGGA_IP_REDIST_STR_BGPD " metric <0-4294967295>",
        NO_STR
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n"
+       QUAGGA_IP_REDIST_HELP_STR_BGPD
        "Metric for redistributed routes\n"
        "Default metric\n")
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8620,14 +8551,10 @@
 
 DEFUN (no_bgp_redistribute_ipv4_rmap_metric,
        no_bgp_redistribute_ipv4_rmap_metric_cmd,
-       "no redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>",
+       "no redistribute " QUAGGA_IP_REDIST_STR_BGPD " route-map WORD metric <0-4294967295>",
        NO_STR
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n"
+       QUAGGA_IP_REDIST_HELP_STR_BGPD
        "Route map reference\n"
        "Pointer to route-map entries\n"
        "Metric for redistributed routes\n"
@@ -8635,8 +8562,8 @@
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8649,14 +8576,10 @@
 
 ALIAS (no_bgp_redistribute_ipv4_rmap_metric,
        no_bgp_redistribute_ipv4_metric_rmap_cmd,
-       "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD",
+       "no redistribute " QUAGGA_IP_REDIST_STR_BGPD " metric <0-4294967295> route-map WORD",
        NO_STR
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n"
+       QUAGGA_IP_REDIST_HELP_STR_BGPD
        "Metric for redistributed routes\n"
        "Default metric\n"
        "Route map reference\n"
@@ -8665,18 +8588,14 @@
 #ifdef HAVE_IPV6
 DEFUN (bgp_redistribute_ipv6,
        bgp_redistribute_ipv6_cmd,
-       "redistribute (connected|kernel|ospf6|ripng|static)",
+       "redistribute " QUAGGA_IP6_REDIST_STR_BGPD,
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n")
+       QUAGGA_IP6_REDIST_HELP_STR_BGPD)
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP6, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8687,20 +8606,16 @@
 
 DEFUN (bgp_redistribute_ipv6_rmap,
        bgp_redistribute_ipv6_rmap_cmd,
-       "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD",
+       "redistribute " QUAGGA_IP6_REDIST_STR_BGPD " route-map WORD",
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n"
+       QUAGGA_IP6_REDIST_HELP_STR_BGPD
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP6, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8712,21 +8627,17 @@
 
 DEFUN (bgp_redistribute_ipv6_metric,
        bgp_redistribute_ipv6_metric_cmd,
-       "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>",
+       "redistribute " QUAGGA_IP6_REDIST_STR_BGPD " metric <0-4294967295>",
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n"
+       QUAGGA_IP6_REDIST_HELP_STR_BGPD
        "Metric for redistributed routes\n"
        "Default metric\n")
 {
   int type;
   u_int32_t metric;
 
-  type = bgp_str2route_type (AFI_IP6, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8739,13 +8650,9 @@
 
 DEFUN (bgp_redistribute_ipv6_rmap_metric,
        bgp_redistribute_ipv6_rmap_metric_cmd,
-       "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
+       "redistribute " QUAGGA_IP6_REDIST_STR_BGPD " route-map WORD metric <0-4294967295>",
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n"
+       QUAGGA_IP6_REDIST_HELP_STR_BGPD
        "Route map reference\n"
        "Pointer to route-map entries\n"
        "Metric for redistributed routes\n"
@@ -8754,8 +8661,8 @@
   int type;
   u_int32_t metric;
 
-  type = bgp_str2route_type (AFI_IP6, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8769,13 +8676,9 @@
 
 DEFUN (bgp_redistribute_ipv6_metric_rmap,
        bgp_redistribute_ipv6_metric_rmap_cmd,
-       "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD",
+       "redistribute " QUAGGA_IP6_REDIST_STR_BGPD " metric <0-4294967295> route-map WORD",
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n"
+       QUAGGA_IP6_REDIST_HELP_STR_BGPD
        "Metric for redistributed routes\n"
        "Default metric\n"
        "Route map reference\n"
@@ -8784,8 +8687,8 @@
   int type;
   u_int32_t metric;
 
-  type = bgp_str2route_type (AFI_IP6, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8799,19 +8702,15 @@
 
 DEFUN (no_bgp_redistribute_ipv6,
        no_bgp_redistribute_ipv6_cmd,
-       "no redistribute (connected|kernel|ospf6|ripng|static)",
+       "no redistribute " QUAGGA_IP6_REDIST_STR_BGPD,
        NO_STR
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n")
+       QUAGGA_IP6_REDIST_HELP_STR_BGPD)
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP6, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8822,21 +8721,17 @@
 
 DEFUN (no_bgp_redistribute_ipv6_rmap,
        no_bgp_redistribute_ipv6_rmap_cmd,
-       "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD",
+       "no redistribute " QUAGGA_IP6_REDIST_STR_BGPD " route-map WORD",
        NO_STR
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n"
+       QUAGGA_IP6_REDIST_HELP_STR_BGPD
        "Route map reference\n"
        "Pointer to route-map entries\n")
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP6, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8848,21 +8743,17 @@
 
 DEFUN (no_bgp_redistribute_ipv6_metric,
        no_bgp_redistribute_ipv6_metric_cmd,
-       "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>",
+       "no redistribute " QUAGGA_IP6_REDIST_STR_BGPD " metric <0-4294967295>",
        NO_STR
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n"
+       QUAGGA_IP6_REDIST_HELP_STR_BGPD
        "Metric for redistributed routes\n"
        "Default metric\n")
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP6, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8874,14 +8765,10 @@
 
 DEFUN (no_bgp_redistribute_ipv6_rmap_metric,
        no_bgp_redistribute_ipv6_rmap_metric_cmd,
-       "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
+       "no redistribute " QUAGGA_IP6_REDIST_STR_BGPD " route-map WORD metric <0-4294967295>",
        NO_STR
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n"
+       QUAGGA_IP6_REDIST_HELP_STR_BGPD
        "Route map reference\n"
        "Pointer to route-map entries\n"
        "Metric for redistributed routes\n"
@@ -8889,8 +8776,8 @@
 {
   int type;
 
-  type = bgp_str2route_type (AFI_IP6, argv[0]);
-  if (! type)
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_BGP)
     {
       vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8903,14 +8790,10 @@
 
 ALIAS (no_bgp_redistribute_ipv6_rmap_metric,
        no_bgp_redistribute_ipv6_metric_rmap_cmd,
-       "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD",
+       "no redistribute " QUAGGA_IP6_REDIST_STR_BGPD " metric <0-4294967295> route-map WORD",
        NO_STR
        "Redistribute information from another routing protocol\n"
-       "Connected\n"
-       "Kernel routes\n"
-       "Open Shurtest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n"
+       QUAGGA_IP6_REDIST_HELP_STR_BGPD
        "Metric for redistributed routes\n"
        "Default metric\n"
        "Route map reference\n"
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 315e919..890cc5c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -29,10 +29,10 @@
 	privs.h sigevent.h pqueue.h jhash.h zassert.h memtypes.h \
 	workqueue.h route_types.h
 
-EXTRA_DIST = regex.c regex-gnu.h memtypes.awk route_types.awk route_types.txt
+EXTRA_DIST = regex.c regex-gnu.h memtypes.awk route_types.pl route_types.txt
 
 memtypes.h: $(srcdir)/memtypes.c $(srcdir)/memtypes.awk
 	($(GAWK) -f $(srcdir)/memtypes.awk $(srcdir)/memtypes.c > $@)
 
-route_types.h: $(srcdir)/route_types.txt $(srcdir)/route_types.awk
-	($(GAWK) -f $(srcdir)/route_types.awk $(srcdir)/route_types.txt > $@)
+route_types.h: $(srcdir)/route_types.txt $(srcdir)/route_types.pl
+	@PERL@ $(srcdir)/route_types.pl < $(srcdir)/route_types.txt > $@
diff --git a/lib/log.c b/lib/log.c
index 4afe922..7edc5c4 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -20,6 +20,8 @@
  * 02111-1307, USA.  
  */
 
+#define QUAGGA_DEFINE_DESC_TABLE
+
 #include <zebra.h>
 
 #include "log.h"
@@ -817,29 +819,6 @@
   return (s != NULL) ? s : "Unknown error";
 }
 
-struct zebra_desc_table
-{
-  unsigned int type;
-  const char *string;
-  char chr;
-};
-
-#define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
-static const struct zebra_desc_table route_types[] = {
-  DESC_ENTRY	(ZEBRA_ROUTE_SYSTEM,	"system",	'X' ),
-  DESC_ENTRY	(ZEBRA_ROUTE_KERNEL,	"kernel",	'K' ),
-  DESC_ENTRY	(ZEBRA_ROUTE_CONNECT,	"connected",	'C' ),
-  DESC_ENTRY	(ZEBRA_ROUTE_STATIC,	"static",	'S' ),
-  DESC_ENTRY	(ZEBRA_ROUTE_RIP,	"rip",		'R' ),
-  DESC_ENTRY	(ZEBRA_ROUTE_RIPNG,	"ripng",	'R' ),
-  DESC_ENTRY	(ZEBRA_ROUTE_OSPF,	"ospf",		'O' ),
-  DESC_ENTRY	(ZEBRA_ROUTE_OSPF6,	"ospf6",	'O' ),
-  DESC_ENTRY	(ZEBRA_ROUTE_ISIS,	"isis",		'I' ),
-  DESC_ENTRY	(ZEBRA_ROUTE_BGP,	"bgp",		'B' ),
-  DESC_ENTRY	(ZEBRA_ROUTE_HSLS,	"hsls",		'H' ),
-};
-#undef DESC_ENTRY
-
 #define DESC_ENTRY(T) [(T)] = { (T), (#T), '\0' }
 static const struct zebra_desc_table command_types[] = {
   DESC_ENTRY	(ZEBRA_INTERFACE_ADD),
@@ -929,4 +908,48 @@
        return route_types[i].type;
    return -1;
 }
+
 #undef RTSIZE
+
+int
+proto_redistnum(int afi, const char *s)
+{
+  if (! s)
+    return -1;
+
+  if (afi == AFI_IP)
+    {
+      if (strncmp (s, "k", 1) == 0)
+	return ZEBRA_ROUTE_KERNEL;
+      else if (strncmp (s, "c", 1) == 0)
+	return ZEBRA_ROUTE_CONNECT;
+      else if (strncmp (s, "s", 1) == 0)
+	return ZEBRA_ROUTE_STATIC;
+      else if (strncmp (s, "r", 1) == 0)
+	return ZEBRA_ROUTE_RIP;
+      else if (strncmp (s, "o", 1) == 0)
+	return ZEBRA_ROUTE_OSPF;
+      else if (strncmp (s, "i", 1) == 0)
+	return ZEBRA_ROUTE_ISIS;
+      else if (strncmp (s, "b", 1) == 0)
+	return ZEBRA_ROUTE_BGP;
+    }
+  if (afi == AFI_IP6)
+    {
+      if (strncmp (s, "k", 1) == 0)
+	return ZEBRA_ROUTE_KERNEL;
+      else if (strncmp (s, "c", 1) == 0)
+	return ZEBRA_ROUTE_CONNECT;
+      else if (strncmp (s, "s", 1) == 0)
+	return ZEBRA_ROUTE_STATIC;
+      else if (strncmp (s, "r", 1) == 0)
+	return ZEBRA_ROUTE_RIPNG;
+      else if (strncmp (s, "o", 1) == 0)
+	return ZEBRA_ROUTE_OSPF6;
+      else if (strncmp (s, "i", 1) == 0)
+	return ZEBRA_ROUTE_ISIS;
+      else if (strncmp (s, "b", 1) == 0)
+	return ZEBRA_ROUTE_BGP;
+    }
+  return -1;
+}
diff --git a/lib/route_types.awk b/lib/route_types.awk
deleted file mode 100644
index 6cfd537..0000000
--- a/lib/route_types.awk
+++ /dev/null
@@ -1,185 +0,0 @@
-# Scan a file of route-type definitions (see eg route_types.txt) and
-# generate a corresponding header file with:
-#
-# - enum of Zserv route-types
-# - redistribute strings for the various Quagga daemons
-#
-# See route_types.txt for the format.
-#
-#
-
-BEGIN {
-	FS="[,]";
-	
-	# globals
-	exitret = 0;
-	tcount = 0;
-	
-	# formats for output
-	## the define format
-	redist_def_fmt = "#define QUAGGA_REDIST_STR_%s \\\n";
-	## DEFUN/vty route-type argument
-	redist_str_fmt = "\"(%s)\"\n";
-	redist_help_def_fmt = "#define QUAGGA_REDIST_HELP_STR_%s";
-	redist_help_str_fmt = " \\\n  \"%s\\n\"";
-	
-	# header
-	header = "/* Auto-generated from route_types.txt by " ARGV[0] ". */\n";
-	header = header "/* Do not edit! */\n";
-	header = header "\n#ifndef _QUAGGA_ROUTE_TYPES_H\n";
-	header = header "#define _QUAGGA_ROUTE_TYPES_H\n";
-	footer = "#endif /* _QUAGGA_ROUTE_TYPES_H */\n";
-	printf ("%s\n", header);
-}
-
-# Chomp comment lines
-($0 ~ /^#/) { 
-	next;
-}
-
-# get rid of the commas, leading/trailling whitespace and
-# quotes
-{
-	for (i = 1; i <= NF; i++) {
-		#print "before:" $i;
-		$i = gensub(/^[[:blank:]]*(.*)[,]*.*/, "\\1", "g",$i);
-		$i = gensub(/^["](.*)["]$/, "\\1", "g", $i);
-		#print "after :" $i;
-	}
-}
-
-# 7 field format:
-#  type                 cname      daemon  C    4  6  short help
-(NF >= 7) {
-	#print "7", $1, $0;
-	
-	if ($1 in types) {
-		print "error: attempt to redefine", $1;
-		exitret = 1;
-		exit exitret;
-	}
-	
-	typesbynum[tcount] = $1;
-	types[$1,"num"] = tcount++; 
-	types[$1,"cname"] = $2;
-	types[$1,"daemon"] = $3;
-	types[$1,"C"] = $4;
-	types[$1,"4"] = strtonum($5);
-	types[$1,"6"] = strtonum($6);
-	types[$1,"shelp"] = $7;
-	
-	#print "num   :", types[$1,"num"]
-	#print "cname :", types[$1,"cname"]
-	#print "daemon:", types[$1,"daemon"];
-	#print "char  :", types[$1,"C"];
-};
-
-# 2 field: type "long description"
-(NF == 2) {
-	#print "2", $1, $2;
-	
-	if (!(($1 SUBSEP "num") in types)) {
-		print "error: type", $1, "must be defined before help str";
-		exitret = 2;
-		exit exitret;
-	}
-	
-	types[$1,"lhelp"] = $2;
-}
-
-END {
-	if (exitret)
-		exit exitret;
-	
-	# The enums
-	# not yet...
-	#printf("enum\n{\n");
-	#for (i = 0; i < tcount; i++) {
-	#	type = typesbynum[i];
-	#	if (type != "" && types[type,"num"] == i)
-	#		printf ("  %s,\n", type);
-	#}
-	#printf ("  ZEBRA_ROUTE_MAX,\n};\n\n");
-	
-	# the redistribute defines
-	for (i = 0; i < tcount; i++) {
-		type = typesbynum[i];
-		
-		# must be a type, and must cross-check against recorded type
-		if (type == "" || types[type,"num"] != i)
-			continue;
-		
-		# ignore route types that can't be redistributed
-		if (!(types[type,"4"] || types[type,"6"]))
-			continue;
-		
-		# must have a daemon name
-		if (!((type SUBSEP "daemon") in types))
-			continue;
-		if (!(daemon = types[type,"daemon"]))
-			continue;
-		
-		# might have done this daemon already?
-		if (daemon in seen_daemons)
-			continue;
-		
-		cname = types[type,"cname"];
-		all = all "|" cname;
-		rstr = "";
-		hstr = "";
-		
-		# add it to the others
-		for (j = 0; j < tcount; j++) {
-			# ignore self
-			if (i == j)
-				continue;
-			
-			type2 = typesbynum[j];
-			
-			# type2 must be valid, and self-check.
-			if (type2 == "" || types[type2,"num"] != j)
-				continue;
-			
-			# ignore different route types for the same daemon
-			# (eg system/kernel/connected)
-			if (types[type2,"daemon"] == daemon)
-				continue;
-			
-			if ((types[type2,"4"] && types[type,"4"]) \
-			    || (types[type2,"6"] && types[type,"6"])) {
-			    	
-			    	if (rstr == "")
-			    		rstr = types[type2,"cname"];
-				else
-					rstr = rstr "|" types[type2,"cname"];
-				
-				if ((type2 SUBSEP "lhelp") in types)
-				  hstr2 = types[type2,"lhelp"];
-				else if ((type2 SUBSEP "shelp") in types)
-				  hstr2 = types[type2,"shelp"];
-				else
-				  hstr2 = types[type2,"cname"];
-				
-				hstr = hstr sprintf(redist_help_str_fmt, hstr2);
-			}
-		}
-		
-		# dont double-process daemons.
-		seen_daemons[daemon] = 1;
-		
-		printf("/* %s */\n", daemon);
-		printf(redist_def_fmt, toupper(daemon));
-		printf(redist_str_fmt, rstr);
-		printf(redist_help_def_fmt, toupper(daemon));
-		printf("%s", hstr);
-		printf("\n\n");
-	}
-	
-	#printf("#define QUAGGA_REDIST_STR_ALL %s\n",all);
-			
-#	for (i = 0; i < lcount; i++) {
-#		if (mlists[i] != "")
-#			printf (mlistformat "\n", mlists[i]);
-#	}
-	printf (footer);
-}
diff --git a/lib/route_types.pl b/lib/route_types.pl
new file mode 100755
index 0000000..e1595af
--- /dev/null
+++ b/lib/route_types.pl
@@ -0,0 +1,199 @@
+#!/usr/bin/perl
+##
+## Scan a file of route-type definitions (see eg route_types.txt) and
+## generate a corresponding header file with:
+##
+## - enum of Zserv route-types
+## - redistribute strings for the various Quagga daemons
+##
+## See route_types.txt for the format.
+##
+##
+## Copyright (C) 2009 David Lamparter.
+## 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.
+##
+
+use strict;
+
+# input processing
+#
+my @protos;
+my %protodetail;
+
+my %daemons;
+
+while (<STDIN>) {
+	# skip comments and empty lines
+	next if (/^\s*(#|$)/);
+
+	# strip whitespace
+	chomp;
+	$_ =~ s/^\s*//;
+	$_ =~ s/\s*$//;
+
+	# match help strings
+	if (/^(ZEBRA_ROUTE_[^\s]+)\s*,\s*"(.*)"$/) {
+		$protodetail{$1}->{'longhelp'} = $2;
+		next;
+	}
+
+	$_ =~ s/\s*,\s*/,/g;
+
+	# else: 7-field line
+	my @f = split(/,/, $_);
+	unless (@f == 7) {
+		die "invalid input on route_types line $.\n";
+	}
+
+	my $proto = $f[0];
+	$f[3] = $1 if ($f[3] =~ /^'(.*)'$/);
+	$f[6] = $1 if ($f[6] =~ /^"(.*)"$/);
+
+	$protodetail{$proto} = {
+		"number" => scalar @protos,
+		"type" => $f[0],
+		"cname" => $f[1],
+		"daemon" => $f[2],
+		"char" => $f[3],
+		"ipv4" => int($f[4]),
+		"ipv6" => int($f[5]),
+		"shorthelp" => $f[6],
+	};
+	push @protos, $proto;
+	$daemons{$f[2]} = {
+		"ipv4" => int($f[4]),
+		"ipv6" => int($f[5])
+	} unless ($f[2] eq "NULL");
+}
+
+# output
+printf <<EOF, $ARGV[0];
+/* Auto-generated from route_types.txt by %s. */
+/* Do not edit! */
+
+#ifndef _QUAGGA_ROUTE_TYPES_H
+#define _QUAGGA_ROUTE_TYPES_H
+
+/* Zebra route's types. */
+EOF
+
+push @protos, "ZEBRA_ROUTE_MAX";
+my (@protosv4, @protosv6) = ((), ());
+for (my $c = 0; $c < @protos; $c++) {
+	my $p = $protos[$c];
+	printf "#define %-32s %d\n", $p, $c;
+	push @protosv4, $p if ($protodetail{$p}->{"ipv4"});
+	push @protosv6, $p if ($protodetail{$p}->{"ipv6"});
+}
+pop @protos;
+
+sub codelist {
+	my (@protos) = @_;
+	my (@lines) = ();
+	my $str = "  \"Codes: ";
+	for my $p (@protos) {
+		my $s = sprintf("%s - %s, ",
+			$protodetail{$p}->{"char"},
+			$protodetail{$p}->{"shorthelp"});
+		if (length($str . $s) > 70) {
+			$str =~ s/ $//;
+			push @lines, $str . "%s\" \\\n";
+			$str = "  \"       ";
+		}
+		$str .= $s;
+	}
+	$str =~ s/ $//;
+	push @lines, $str . "%s\" \\\n";
+	push @lines, "  \"       > - selected route, * - FIB route%s%s\", \\\n";
+	my @nl = ();
+	for (my $c = 0; $c < @lines + 1; $c++) {
+		push @nl, "VTY_NEWLINE"
+	}
+	return join("", @lines) ."  ". join(", ", @nl);
+}
+
+print "\n";
+printf "#define SHOW_ROUTE_V4_HEADER \\\n%s\n", codelist(@protosv4);
+printf "#define SHOW_ROUTE_V6_HEADER \\\n%s\n", codelist(@protosv6);
+print "\n";
+
+sub collect {
+	my ($daemon, $ipv4, $ipv6) = @_;
+	my (@names, @help) = ((), ());
+	for my $p (@protos) {
+		next if ($protodetail{$p}->{"daemon"} eq $daemon && $daemon ne "zebra");
+		next unless (($ipv4 && $protodetail{$p}->{"ipv4"})
+				|| ($ipv6 && $protodetail{$p}->{"ipv6"}));
+		push @names, $protodetail{$p}->{"cname"};
+		push @help, "  \"".$protodetail{$p}->{"longhelp"}."\\n\"";
+	}
+	return ("\"(" . join("|", @names) . ")\"", join(" \\\n", @help));
+}
+
+for my $daemon (sort keys %daemons) {
+	next unless ($daemons{$daemon}->{"ipv4"} || $daemons{$daemon}->{"ipv6"});
+	printf "/* %s */\n", $daemon;
+	if ($daemons{$daemon}->{"ipv4"} && $daemons{$daemon}->{"ipv6"}) {
+		my ($names, $help) = collect($daemon, 1, 1);
+		printf "#define QUAGGA_REDIST_STR_%s \\\n  %s\n", uc $daemon, $names;
+		printf "#define QUAGGA_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
+		($names, $help) = collect($daemon, 1, 0);
+		printf "#define QUAGGA_IP_REDIST_STR_%s \\\n  %s\n", uc $daemon, $names;
+		printf "#define QUAGGA_IP_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
+		($names, $help) = collect($daemon, 0, 1);
+		printf "#define QUAGGA_IP6_REDIST_STR_%s \\\n  %s\n", uc $daemon, $names;
+		printf "#define QUAGGA_IP6_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
+	} else {
+		my ($names, $help) = collect($daemon,
+			$daemons{$daemon}->{"ipv4"}, $daemons{$daemon}->{"ipv6"});
+		printf "#define QUAGGA_REDIST_STR_%s \\\n  %s\n", uc $daemon, $names;
+		printf "#define QUAGGA_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
+	}
+	print "\n";
+}
+
+print <<EOF;
+
+#ifdef QUAGGA_DEFINE_DESC_TABLE
+
+struct zebra_desc_table
+{
+  unsigned int type;
+  const char *string;
+  char chr;
+};
+
+#define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
+static const struct zebra_desc_table route_types[] = {
+EOF
+
+for (my $c = 0; $c < @protos; $c++) {
+	my $p = $protos[$c];
+	printf "  DESC_ENTRY\t(%s\t \"%s\",\t'%s' ),\n",
+	       $p.",", $protodetail{$p}->{"cname"}, $protodetail{$p}->{"char"};
+}
+
+print <<EOF;
+};
+#undef DESC_ENTRY
+
+#endif /* QUAGGA_DEFINE_DESC_TABLE */
+
+#endif /* _QUAGGA_ROUTE_TYPES_H */
+EOF
+
diff --git a/lib/route_types.txt b/lib/route_types.txt
index e99cacd..fde0bc8 100644
--- a/lib/route_types.txt
+++ b/lib/route_types.txt
@@ -42,13 +42,13 @@
 
 ##  type                cname      daemon  C    4  6  short help
 ZEBRA_ROUTE_SYSTEM,     system,    NULL,   'X', 0, 0, "Reserved"
-ZEBRA_ROUTE_KERNEL,     kernel,    zebra,  'K', 1, 1, NULL
-ZEBRA_ROUTE_CONNECT,    connected, zebra,  'C', 1, 1, NULL
-ZEBRA_ROUTE_STATIC,     static,    zebra,  'S', 1, 1, NULL
+ZEBRA_ROUTE_KERNEL,     kernel,    zebra,  'K', 1, 1, "kernel route"
+ZEBRA_ROUTE_CONNECT,    connected, zebra,  'C', 1, 1, "connected"
+ZEBRA_ROUTE_STATIC,     static,    zebra,  'S', 1, 1, "static"
 ZEBRA_ROUTE_RIP,        rip,       ripd,   'R', 1, 0, "RIP"
 ZEBRA_ROUTE_RIPNG,      ripng,     ripngd, 'R', 0, 1, "RIPng"
 ZEBRA_ROUTE_OSPF,       ospf,      ospfd,  'O', 1, 0, "OSPF"
-ZEBRA_ROUTE_OSPF6,      ospf6,     ospf6d, 'O', 0, 1, "OSPF"
+ZEBRA_ROUTE_OSPF6,      ospf6,     ospf6d, 'O', 0, 1, "OSPFv6"
 ZEBRA_ROUTE_ISIS,       isis,      isisd,  'I', 1, 1, "IS-IS"
 ZEBRA_ROUTE_BGP,        bgp,       bgpd,   'B', 1, 1, "BGP"
 # HSLS and OLSR both are AFI independent (so: 1, 1), however
@@ -57,7 +57,7 @@
 # to 'switch on' redist support (direct numeric entry remaining
 # possible).
 ZEBRA_ROUTE_HSLS,       hsls,      hslsd,  'H', 0, 0, "HSLS"
-ZEBRA_ROUTE_OLSR,       olsr,      oslrd,  'o', 0, 0, "OLSR"
+ZEBRA_ROUTE_OLSR,       olsr,      olsrd,  'o', 0, 0, "OLSR"
 
 ## help strings
 ZEBRA_ROUTE_SYSTEM, "Reserved route type, for internal use only"
diff --git a/lib/zebra.h b/lib/zebra.h
index c4c69d3..4b4c7c0 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -425,19 +425,8 @@
  */
 #define ZEBRA_HEADER_MARKER              255
 
-/* Zebra route's types. */
-#define ZEBRA_ROUTE_SYSTEM               0
-#define ZEBRA_ROUTE_KERNEL               1
-#define ZEBRA_ROUTE_CONNECT              2
-#define ZEBRA_ROUTE_STATIC               3
-#define ZEBRA_ROUTE_RIP                  4
-#define ZEBRA_ROUTE_RIPNG                5
-#define ZEBRA_ROUTE_OSPF                 6
-#define ZEBRA_ROUTE_OSPF6                7
-#define ZEBRA_ROUTE_ISIS                 8
-#define ZEBRA_ROUTE_BGP                  9
-#define ZEBRA_ROUTE_HSLS		 10
-#define ZEBRA_ROUTE_MAX                  11
+/* Zebra route's types are defined in route_types.h */
+#include "route_types.h"
 
 /* Note: whenever a new route-type or zserv-command is added the
  * corresponding {command,route}_types[] table in lib/log.c MUST be
@@ -451,6 +440,10 @@
  * e.g. ZEBRA_INTERFACE_ADD -> "ZEBRA_INTERFACE_ADD" */
 /* Map a protocol name to its number. e.g. ZEBRA_ROUTE_BGP->9*/
 extern int proto_name2num(const char *s);
+/* Map redistribute X argument to protocol number.
+ * unlike proto_name2num, this accepts shorthands and takes
+ * an AFI value to restrict input */
+extern int proto_redistnum(int afi, const char *s);
 
 extern const char *zserv_command_string (unsigned int command);
 
diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c
index 922e1c0..ae0a286 100644
--- a/ospf6d/ospf6_asbr.c
+++ b/ospf6d/ospf6_asbr.c
@@ -617,27 +617,16 @@
 
 DEFUN (ospf6_redistribute,
        ospf6_redistribute_cmd,
-       "redistribute (static|kernel|connected|ripng|bgp)",
+       "redistribute " QUAGGA_REDIST_STR_OSPF6D,
        "Redistribute\n"
-       "Static route\n"
-       "Kernel route\n"
-       "Connected route\n"
-       "RIPng route\n"
-       "BGP route\n"
+       QUAGGA_REDIST_HELP_STR_OSPF6D
       )
 {
-  int type = 0;
+  int type;
 
-  if (strncmp (argv[0], "sta", 3) == 0)
-    type = ZEBRA_ROUTE_STATIC;
-  else if (strncmp (argv[0], "ker", 3) == 0)
-    type = ZEBRA_ROUTE_KERNEL;
-  else if (strncmp (argv[0], "con", 3) == 0)
-    type = ZEBRA_ROUTE_CONNECT;
-  else if (strncmp (argv[0], "rip", 3) == 0)
-    type = ZEBRA_ROUTE_RIPNG;
-  else if (strncmp (argv[0], "bgp", 3) == 0)
-    type = ZEBRA_ROUTE_BGP;
+  type = proto_redistnum(AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
+    return CMD_WARNING;
 
   ospf6_asbr_redistribute_unset (type);
   ospf6_asbr_routemap_unset (type);
@@ -647,29 +636,18 @@
 
 DEFUN (ospf6_redistribute_routemap,
        ospf6_redistribute_routemap_cmd,
-       "redistribute (static|kernel|connected|ripng|bgp) route-map WORD",
+       "redistribute " QUAGGA_REDIST_STR_OSPF6D " route-map WORD",
        "Redistribute\n"
-       "Static routes\n"
-       "Kernel route\n"
-       "Connected route\n"
-       "RIPng route\n"
-       "BGP route\n"
+       QUAGGA_REDIST_HELP_STR_OSPF6D
        "Route map reference\n"
        "Route map name\n"
       )
 {
-  int type = 0;
+  int type;
 
-  if (strncmp (argv[0], "sta", 3) == 0)
-    type = ZEBRA_ROUTE_STATIC;
-  else if (strncmp (argv[0], "ker", 3) == 0)
-    type = ZEBRA_ROUTE_KERNEL;
-  else if (strncmp (argv[0], "con", 3) == 0)
-    type = ZEBRA_ROUTE_CONNECT;
-  else if (strncmp (argv[0], "rip", 3) == 0)
-    type = ZEBRA_ROUTE_RIPNG;
-  else if (strncmp (argv[0], "bgp", 3) == 0)
-    type = ZEBRA_ROUTE_BGP;
+  type = proto_redistnum(AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
+    return CMD_WARNING;
 
   ospf6_asbr_redistribute_unset (type);
   ospf6_asbr_routemap_set (type, argv[1]);
@@ -679,28 +657,17 @@
 
 DEFUN (no_ospf6_redistribute,
        no_ospf6_redistribute_cmd,
-       "no redistribute (static|kernel|connected|ripng|bgp)",
+       "no redistribute " QUAGGA_REDIST_STR_OSPF6D,
        NO_STR
        "Redistribute\n"
-       "Static route\n"
-       "Kernel route\n"
-       "Connected route\n"
-       "RIPng route\n"
-       "BGP route\n"
+       QUAGGA_REDIST_HELP_STR_OSPF6D
       )
 {
-  int type = 0;
+  int type;
 
-  if (strncmp (argv[0], "sta", 3) == 0)
-    type = ZEBRA_ROUTE_STATIC;
-  else if (strncmp (argv[0], "ker", 3) == 0)
-    type = ZEBRA_ROUTE_KERNEL;
-  else if (strncmp (argv[0], "con", 3) == 0)
-    type = ZEBRA_ROUTE_CONNECT;
-  else if (strncmp (argv[0], "rip", 3) == 0)
-    type = ZEBRA_ROUTE_RIPNG;
-  else if (strncmp (argv[0], "bgp", 3) == 0)
-    type = ZEBRA_ROUTE_BGP;
+  type = proto_redistnum(AFI_IP6, argv[0]);
+  if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
+    return CMD_WARNING;
 
   ospf6_asbr_redistribute_unset (type);
   ospf6_asbr_routemap_unset (type);
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 59f5fb6..c928e81 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -93,29 +93,6 @@
 
 
 static int
-str2distribute_source (const char *str, int *source)
-{
-  /* Sanity check. */
-  if (str == NULL)
-    return 0;
-
-  if (strncmp (str, "k", 1) == 0)
-    *source = ZEBRA_ROUTE_KERNEL;
-  else if (strncmp (str, "c", 1) == 0)
-    *source = ZEBRA_ROUTE_CONNECT;
-  else if (strncmp (str, "s", 1) == 0)
-    *source = ZEBRA_ROUTE_STATIC;
-  else if (strncmp (str, "r", 1) == 0)
-    *source = ZEBRA_ROUTE_RIP;
-  else if (strncmp (str, "b", 1) == 0)
-    *source = ZEBRA_ROUTE_BGP;
-  else
-    return 0;
-
-  return 1;
-}
-
-static int
 str2metric (const char *str, int *metric)
 {
   /* Sanity check. */
@@ -5825,7 +5802,8 @@
   int metric = -1;
 
   /* Get distribute source. */
-  if (!str2distribute_source (argv[0], &source))
+  source = proto_redistnum(AFI_IP, argv[0]);
+  if (source < 0 || source == ZEBRA_ROUTE_OSPF)
     return CMD_WARNING;
 
   /* Get metric value. */
@@ -5886,7 +5864,8 @@
   int metric = -1;
 
   /* Get distribute source. */
-  if (!str2distribute_source (argv[0], &source))
+  source = proto_redistnum(AFI_IP, argv[0]);
+  if (source < 0 || source == ZEBRA_ROUTE_OSPF)
     return CMD_WARNING;
 
   /* Get metric value. */
@@ -5950,7 +5929,8 @@
   int metric = -1;
 
   /* Get distribute source. */
-  if (!str2distribute_source (argv[0], &source))
+  source = proto_redistnum(AFI_IP, argv[0]);
+  if (source < 0 || source == ZEBRA_ROUTE_OSPF)
     return CMD_WARNING;
 
   /* Get metric value. */
@@ -5983,7 +5963,8 @@
   int type = -1;
 
   /* Get distribute source. */
-  if (!str2distribute_source (argv[0], &source))
+  source = proto_redistnum(AFI_IP, argv[0]);
+  if (source < 0 || source == ZEBRA_ROUTE_OSPF)
     return CMD_WARNING;
 
   /* Get metric value. */
@@ -6011,7 +5992,8 @@
   int source;
 
   /* Get distribute source. */
-  if (!str2distribute_source (argv[0], &source))
+  source = proto_redistnum(AFI_IP, argv[0]);
+  if (source < 0 || source == ZEBRA_ROUTE_OSPF)
     return CMD_WARNING;
 
   if (argc == 2)
@@ -6032,7 +6014,8 @@
   struct ospf *ospf = vty->index;
   int source;
 
-  if (!str2distribute_source (argv[0], &source))
+  source = proto_redistnum(AFI_IP, argv[0]);
+  if (source < 0 || source == ZEBRA_ROUTE_OSPF)
     return CMD_WARNING;
 
   ospf_routemap_unset (ospf, source);
@@ -6051,7 +6034,8 @@
   int source;
 
   /* Get distribute source. */
-  if (!str2distribute_source (argv[1], &source))
+  source = proto_redistnum(AFI_IP, argv[0]);
+  if (source < 0 || source == ZEBRA_ROUTE_OSPF)
     return CMD_WARNING;
 
   return ospf_distribute_list_out_set (ospf, source, argv[0]);
@@ -6069,7 +6053,8 @@
   struct ospf *ospf = vty->index;
   int source;
 
-  if (!str2distribute_source (argv[1], &source))
+  source = proto_redistnum(AFI_IP, argv[0]);
+  if (source < 0 || source == ZEBRA_ROUTE_OSPF)
     return CMD_WARNING;
 
   return ospf_distribute_list_out_unset (ospf, source, argv[0]);
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index ecb5d10..05485a1 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -802,10 +802,6 @@
     }
 }
 
-#define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, " \
-  "S - static, R - RIP, O - OSPF,%s       I - ISIS, B - BGP, " \
-  "> - selected route, * - FIB route%s%s"
-
 DEFUN (show_ip_route,
        show_ip_route_cmd,
        "show ip route",
@@ -828,8 +824,7 @@
       {
 	if (first)
 	  {
-	    vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE,
-		     VTY_NEWLINE);
+	    vty_out (vty, SHOW_ROUTE_V4_HEADER);
 	    first = 0;
 	  }
 	vty_show_ip_route (vty, rn, rib);
@@ -871,8 +866,7 @@
 	{
 	  if (first)
 	    {
-	      vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE,
-		       VTY_NEWLINE, VTY_NEWLINE);
+	      vty_out (vty, SHOW_ROUTE_V4_HEADER);
 	      first = 0;
 	    }
 	  vty_show_ip_route (vty, rn, rib);
@@ -910,8 +904,7 @@
 	  {
 	    if (first)
 	      {
-		vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE,
-			 VTY_NEWLINE, VTY_NEWLINE);
+		vty_out (vty, SHOW_ROUTE_V4_HEADER);
 		first = 0;
 	      }
 	    vty_show_ip_route (vty, rn, rib);
@@ -922,17 +915,11 @@
 
 DEFUN (show_ip_route_protocol,
        show_ip_route_protocol_cmd,
-       "show ip route (bgp|connected|isis|kernel|ospf|rip|static)",
+       "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
        SHOW_STR
        IP_STR
        "IP routing table\n"
-       "Border Gateway Protocol (BGP)\n"
-       "Connected\n"
-       "ISO IS-IS (ISIS)\n"
-       "Kernel\n"
-       "Open Shortest Path First (OSPF)\n"
-       "Routing Information Protocol (RIP)\n"
-       "Static routes\n")
+       QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
 {
   int type;
   struct route_table *table;
@@ -940,21 +927,8 @@
   struct rib *rib;
   int first = 1;
 
-  if (strncmp (argv[0], "b", 1) == 0)
-    type = ZEBRA_ROUTE_BGP;
-  else if (strncmp (argv[0], "c", 1) == 0)
-    type = ZEBRA_ROUTE_CONNECT;
-  else if (strncmp (argv[0], "k", 1) ==0)
-    type = ZEBRA_ROUTE_KERNEL;
-  else if (strncmp (argv[0], "o", 1) == 0)
-    type = ZEBRA_ROUTE_OSPF;
-  else if (strncmp (argv[0], "i", 1) == 0)
-    type = ZEBRA_ROUTE_ISIS;
-  else if (strncmp (argv[0], "r", 1) == 0)
-    type = ZEBRA_ROUTE_RIP;
-  else if (strncmp (argv[0], "s", 1) == 0)
-    type = ZEBRA_ROUTE_STATIC;
-  else 
+  type = proto_redistnum (AFI_IP, argv[0]);
+  if (type < 0)
     {
       vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -971,8 +945,7 @@
 	{
 	  if (first)
 	    {
-	      vty_out (vty, SHOW_ROUTE_V4_HEADER,
-		       VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+	      vty_out (vty, SHOW_ROUTE_V4_HEADER);
 	      first = 0;
 	    }
 	  vty_show_ip_route (vty, rn, rib);
@@ -1766,8 +1739,6 @@
     }
 }
 
-#define SHOW_ROUTE_V6_HEADER "Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3,%s       I - ISIS, B - BGP, * - FIB route.%s%s"
-
 DEFUN (show_ipv6_route,
        show_ipv6_route_cmd,
        "show ipv6 route",
@@ -1790,7 +1761,7 @@
       {
 	if (first)
 	  {
-	    vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+	    vty_out (vty, SHOW_ROUTE_V6_HEADER);
 	    first = 0;
 	  }
 	vty_show_ipv6_route (vty, rn, rib);
@@ -1832,7 +1803,7 @@
 	{
 	  if (first)
 	    {
-	      vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+	      vty_out (vty, SHOW_ROUTE_V6_HEADER);
 	      first = 0;
 	    }
 	  vty_show_ipv6_route (vty, rn, rib);
@@ -1842,17 +1813,11 @@
 
 DEFUN (show_ipv6_route_protocol,
        show_ipv6_route_protocol_cmd,
-       "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|static)",
+       "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
        SHOW_STR
        IP_STR
        "IP routing table\n"
-       "Border Gateway Protocol (BGP)\n"
-       "Connected\n"
-       "ISO IS-IS (ISIS)\n"
-       "Kernel\n"
-       "Open Shortest Path First (OSPFv3)\n"
-       "Routing Information Protocol (RIPng)\n"
-       "Static routes\n")
+	QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
 {
   int type;
   struct route_table *table;
@@ -1860,21 +1825,8 @@
   struct rib *rib;
   int first = 1;
 
-  if (strncmp (argv[0], "b", 1) == 0)
-    type = ZEBRA_ROUTE_BGP;
-  else if (strncmp (argv[0], "c", 1) == 0)
-    type = ZEBRA_ROUTE_CONNECT;
-  else if (strncmp (argv[0], "k", 1) ==0)
-    type = ZEBRA_ROUTE_KERNEL;
-  else if (strncmp (argv[0], "o", 1) == 0)
-    type = ZEBRA_ROUTE_OSPF6;
-  else if (strncmp (argv[0], "i", 1) == 0)
-    type = ZEBRA_ROUTE_ISIS;
-  else if (strncmp (argv[0], "r", 1) == 0)
-    type = ZEBRA_ROUTE_RIPNG;
-  else if (strncmp (argv[0], "s", 1) == 0)
-    type = ZEBRA_ROUTE_STATIC;
-  else 
+  type = proto_redistnum (AFI_IP6, argv[0]);
+  if (type < 0)
     {
       vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -1891,7 +1843,7 @@
 	{
 	  if (first)
 	    {
-	      vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+	      vty_out (vty, SHOW_ROUTE_V6_HEADER);
 	      first = 0;
 	    }
 	  vty_show_ipv6_route (vty, rn, rib);