File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / quagga / ospfd / ospf_routemap.c
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Nov 2 10:09:12 2016 UTC (7 years, 8 months ago) by misho
Branches: quagga, MAIN
CVS tags: v1_0_20160315, HEAD
quagga 1.0.20160315

    1: /*
    2:  * Route map function of ospfd.
    3:  * Copyright (C) 2000 IP Infusion Inc.
    4:  *
    5:  * Written by Toshiaki Takada.
    6:  *
    7:  * This file is part of GNU Zebra.
    8:  *
    9:  * GNU Zebra is free software; you can redistribute it and/or modify it
   10:  * under the terms of the GNU General Public License as published by the
   11:  * Free Software Foundation; either version 2, or (at your option) any
   12:  * later version.
   13:  *
   14:  * GNU Zebra is distributed in the hope that it will be useful, but
   15:  * WITHOUT ANY WARRANTY; without even the implied warranty of
   16:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   17:  * General Public License for more details.
   18:  *
   19:  * You should have received a copy of the GNU General Public License
   20:  * along with GNU Zebra; see the file COPYING.  If not, write to the Free
   21:  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   22:  * 02111-1307, USA.
   23:  */
   24: 
   25: #include <zebra.h>
   26: 
   27: #include "memory.h"
   28: #include "prefix.h"
   29: #include "table.h"
   30: #include "routemap.h"
   31: #include "command.h"
   32: #include "log.h"
   33: #include "plist.h"
   34: 
   35: #include "ospfd/ospfd.h"
   36: #include "ospfd/ospf_asbr.h"
   37: #include "ospfd/ospf_interface.h"
   38: #include "ospfd/ospf_lsa.h"
   39: #include "ospfd/ospf_route.h"
   40: #include "ospfd/ospf_zebra.h"
   41: 
   42: /* Hook function for updating route_map assignment. */
   43: static void
   44: ospf_route_map_update (const char *name)
   45: {
   46:   struct ospf *ospf;
   47:   int type;
   48: 
   49:   /* If OSPF instatnce does not exist, return right now. */
   50:   ospf = ospf_lookup ();
   51:   if (ospf == NULL)
   52:     return;
   53: 
   54:   /* Update route-map */
   55:   for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
   56:     {
   57:       if (ROUTEMAP_NAME (ospf, type)
   58: 	  && strcmp (ROUTEMAP_NAME (ospf, type), name) == 0)
   59: 	{
   60: 	  /* Keep old route-map. */
   61: 	  struct route_map *old = ROUTEMAP (ospf, type);
   62: 
   63: 	  /* Update route-map. */
   64: 	  ROUTEMAP (ospf, type) =
   65: 	    route_map_lookup_by_name (ROUTEMAP_NAME (ospf, type));
   66: 
   67: 	  /* No update for this distribute type. */
   68: 	  if (old == NULL && ROUTEMAP (ospf, type) == NULL)
   69: 	    continue;
   70: 
   71: 	  ospf_distribute_list_update (ospf, type);
   72: 	}
   73:     }
   74: }
   75: 
   76: static void
   77: ospf_route_map_event (route_map_event_t event, const char *name)
   78: {
   79:   struct ospf *ospf;
   80:   int type;
   81: 
   82:   /* If OSPF instatnce does not exist, return right now. */
   83:   ospf = ospf_lookup ();
   84:   if (ospf == NULL)
   85:     return;
   86: 
   87:   /* Update route-map. */
   88:   for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
   89:     {
   90:       if (ROUTEMAP_NAME (ospf, type) &&  ROUTEMAP (ospf, type)
   91: 	  && !strcmp (ROUTEMAP_NAME (ospf, type), name))
   92:         {
   93:           ospf_distribute_list_update (ospf, type);
   94:         }
   95:     }
   96: }
   97: 
   98: /* Delete rip route map rule. */
   99: static int
  100: ospf_route_match_delete (struct vty *vty, struct route_map_index *index,
  101: 			 const char *command, const char *arg)
  102: {
  103:   int ret;
  104: 
  105:   ret = route_map_delete_match (index, command, arg);
  106:   if (ret)
  107:     {
  108:       switch (ret)
  109:         {
  110:         case RMAP_RULE_MISSING:
  111:           vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  112:           return CMD_WARNING;
  113:         case RMAP_COMPILE_ERROR:
  114:           vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  115:           return CMD_WARNING;
  116:         }
  117:     }
  118: 
  119:   return CMD_SUCCESS;
  120: }
  121: 
  122: static int
  123: ospf_route_match_add (struct vty *vty, struct route_map_index *index,
  124: 		      const char *command, const char *arg)
  125: {                                                                              
  126:   int ret;
  127: 
  128:   ret = route_map_add_match (index, command, arg);
  129:   if (ret)
  130:     {
  131:       switch (ret)
  132:         {
  133:         case RMAP_RULE_MISSING:
  134:           vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  135:           return CMD_WARNING;
  136:         case RMAP_COMPILE_ERROR:
  137:           vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  138:           return CMD_WARNING;
  139:         }
  140:     }
  141: 
  142:   return CMD_SUCCESS;
  143: }
  144: 
  145: static int
  146: ospf_route_set_add (struct vty *vty, struct route_map_index *index,
  147: 		    const char *command, const char *arg)
  148: {
  149:   int ret;
  150: 
  151:   ret = route_map_add_set (index, command, arg);
  152:   if (ret)
  153:     {
  154:       switch (ret)
  155:         {
  156:         case RMAP_RULE_MISSING:
  157:           vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  158:           return CMD_WARNING;
  159:         case RMAP_COMPILE_ERROR:
  160:           vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  161:           return CMD_WARNING;
  162:         }
  163:     }
  164: 
  165:   return CMD_SUCCESS;
  166: }
  167: 
  168: /* Delete rip route map rule. */
  169: static int
  170: ospf_route_set_delete (struct vty *vty, struct route_map_index *index,
  171: 		       const char *command, const char *arg)
  172: {                                              
  173:   int ret;
  174: 
  175:   ret = route_map_delete_set (index, command, arg);
  176:   if (ret)
  177:     {
  178:       switch (ret)
  179:         {
  180:         case RMAP_RULE_MISSING:
  181:           vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
  182:           return CMD_WARNING;
  183:         case RMAP_COMPILE_ERROR:
  184:           vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
  185:           return CMD_WARNING;
  186:         }
  187:     }
  188: 
  189:   return CMD_SUCCESS;
  190: }
  191: 
  192: /* `match ip netxthop ' */
  193: /* Match function return 1 if match is success else return zero. */
  194: static route_map_result_t
  195: route_match_ip_nexthop (void *rule, struct prefix *prefix,
  196: 			route_map_object_t type, void *object)
  197: {
  198:   struct access_list *alist;
  199:   struct external_info *ei = object;
  200:   struct prefix_ipv4 p;
  201: 
  202:   if (type == RMAP_OSPF)
  203:     {
  204:       p.family = AF_INET;
  205:       p.prefix = ei->nexthop;
  206:       p.prefixlen = IPV4_MAX_BITLEN;
  207: 
  208:       alist = access_list_lookup (AFI_IP, (char *) rule);
  209:       if (alist == NULL)
  210:         return RMAP_NOMATCH;
  211: 
  212:       return (access_list_apply (alist, &p) == FILTER_DENY ?
  213:               RMAP_NOMATCH : RMAP_MATCH);
  214:     }
  215:   return RMAP_NOMATCH;
  216: }
  217: 
  218: /* Route map `ip next-hop' match statement. `arg' should be
  219:    access-list name. */
  220: static void *
  221: route_match_ip_nexthop_compile (const char *arg)
  222: {
  223:   return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  224: }
  225: 
  226: /* Free route map's compiled `ip address' value. */
  227: static void
  228: route_match_ip_nexthop_free (void *rule)
  229: {
  230:   XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  231: }
  232: 
  233: /* Route map commands for metric matching. */
  234: struct route_map_rule_cmd route_match_ip_nexthop_cmd =
  235: {
  236:   "ip next-hop",
  237:   route_match_ip_nexthop,
  238:   route_match_ip_nexthop_compile,
  239:   route_match_ip_nexthop_free
  240: };
  241: 
  242: /* `match ip next-hop prefix-list PREFIX_LIST' */
  243: 
  244: static route_map_result_t
  245: route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
  246:                                     route_map_object_t type, void *object)
  247: {
  248:   struct prefix_list *plist;
  249:   struct external_info *ei = object;
  250:   struct prefix_ipv4 p;
  251: 
  252:   if (type == RMAP_OSPF)
  253:     {
  254:       p.family = AF_INET;
  255:       p.prefix = ei->nexthop;
  256:       p.prefixlen = IPV4_MAX_BITLEN;
  257: 
  258:       plist = prefix_list_lookup (AFI_IP, (char *) rule);
  259:       if (plist == NULL)
  260:         return RMAP_NOMATCH;
  261: 
  262:       return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
  263:               RMAP_NOMATCH : RMAP_MATCH);
  264:     }
  265:   return RMAP_NOMATCH;
  266: }
  267: 
  268: static void *
  269: route_match_ip_next_hop_prefix_list_compile (const char *arg)
  270: {
  271:   return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  272: }
  273: 
  274: static void
  275: route_match_ip_next_hop_prefix_list_free (void *rule)
  276: {
  277:   XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  278: }
  279: 
  280: struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
  281: {
  282:   "ip next-hop prefix-list",
  283:   route_match_ip_next_hop_prefix_list,
  284:   route_match_ip_next_hop_prefix_list_compile,
  285:   route_match_ip_next_hop_prefix_list_free
  286: };
  287: 
  288: /* `match ip address IP_ACCESS_LIST' */
  289: /* Match function should return 1 if match is success else return
  290:    zero. */
  291: static route_map_result_t
  292: route_match_ip_address (void *rule, struct prefix *prefix,
  293:                         route_map_object_t type, void *object)
  294: {
  295:   struct access_list *alist;
  296:   /* struct prefix_ipv4 match; */
  297: 
  298:   if (type == RMAP_OSPF)
  299:     {
  300:       alist = access_list_lookup (AFI_IP, (char *) rule);
  301:       if (alist == NULL)
  302:         return RMAP_NOMATCH;
  303: 
  304:       return (access_list_apply (alist, prefix) == FILTER_DENY ?
  305:               RMAP_NOMATCH : RMAP_MATCH);
  306:     }
  307:   return RMAP_NOMATCH;
  308: }
  309: 
  310: /* Route map `ip address' match statement.  `arg' should be
  311:    access-list name. */
  312: static void *
  313: route_match_ip_address_compile (const char *arg)
  314: {
  315:   return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  316: }
  317: 
  318: /* Free route map's compiled `ip address' value. */
  319: static void
  320: route_match_ip_address_free (void *rule)
  321: {
  322:   XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  323: }
  324: 
  325: /* Route map commands for ip address matching. */
  326: struct route_map_rule_cmd route_match_ip_address_cmd =
  327: {
  328:   "ip address",
  329:   route_match_ip_address,
  330:   route_match_ip_address_compile,
  331:   route_match_ip_address_free
  332: };
  333: 
  334: /* `match ip address prefix-list PREFIX_LIST' */
  335: static route_map_result_t
  336: route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
  337:                                     route_map_object_t type, void *object)
  338: {
  339:   struct prefix_list *plist;
  340: 
  341:   if (type == RMAP_OSPF)
  342:     {
  343:       plist = prefix_list_lookup (AFI_IP, (char *) rule);
  344:       if (plist == NULL)
  345:         return RMAP_NOMATCH;
  346: 
  347:       return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
  348:               RMAP_NOMATCH : RMAP_MATCH);
  349:     }
  350:   return RMAP_NOMATCH;
  351: }
  352: 
  353: static void *
  354: route_match_ip_address_prefix_list_compile (const char *arg)
  355: {
  356:   return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  357: }
  358: 
  359: static void
  360: route_match_ip_address_prefix_list_free (void *rule)
  361: {
  362:   XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  363: }
  364: 
  365: struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
  366: {
  367:   "ip address prefix-list",
  368:   route_match_ip_address_prefix_list,
  369:   route_match_ip_address_prefix_list_compile,
  370:   route_match_ip_address_prefix_list_free
  371: };
  372: 
  373: /* `match interface IFNAME' */
  374: /* Match function should return 1 if match is success else return
  375:    zero. */
  376: static route_map_result_t
  377: route_match_interface (void *rule, struct prefix *prefix,
  378: 		       route_map_object_t type, void *object)
  379: {
  380:   struct interface *ifp;
  381:   struct external_info *ei;
  382: 
  383:   if (type == RMAP_OSPF)
  384:     {
  385:       ei = object;
  386:       ifp = if_lookup_by_name ((char *)rule);
  387: 
  388:       if (ifp == NULL || ifp->ifindex != ei->ifindex)
  389: 	return RMAP_NOMATCH;
  390: 
  391:       return RMAP_MATCH;
  392:     }
  393:   return RMAP_NOMATCH;
  394: }
  395: 
  396: /* Route map `interface' match statement.  `arg' should be
  397:    interface name. */
  398: static void *
  399: route_match_interface_compile (const char *arg)
  400: {
  401:   return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
  402: }
  403: 
  404: /* Free route map's compiled `interface' value. */
  405: static void
  406: route_match_interface_free (void *rule)
  407: {
  408:   XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  409: }
  410: 
  411: /* Route map commands for ip address matching. */
  412: struct route_map_rule_cmd route_match_interface_cmd =
  413: {
  414:   "interface",
  415:   route_match_interface,
  416:   route_match_interface_compile,
  417:   route_match_interface_free
  418: };
  419: 
  420: /* `set metric METRIC' */
  421: /* Set metric to attribute. */
  422: static route_map_result_t
  423: route_set_metric (void *rule, struct prefix *prefix,
  424:                   route_map_object_t type, void *object)
  425: {
  426:   u_int32_t *metric;
  427:   struct external_info *ei;
  428: 
  429:   if (type == RMAP_OSPF)
  430:     {
  431:       /* Fetch routemap's rule information. */
  432:       metric = rule;
  433:       ei = object;
  434: 
  435:       /* Set metric out value. */
  436:       ei->route_map_set.metric = *metric;
  437:     }
  438:   return RMAP_OKAY;
  439: }
  440: 
  441: /* set metric compilation. */
  442: static void *
  443: route_set_metric_compile (const char *arg)
  444: {
  445:   u_int32_t *metric;
  446:   int32_t ret;
  447: 
  448:   metric = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  449:   ret = atoi (arg);
  450: 
  451:   if (ret >= 0)
  452:     {
  453:       *metric = (u_int32_t)ret;
  454:       return metric;
  455:     }
  456: 
  457:   XFREE (MTYPE_ROUTE_MAP_COMPILED, metric);
  458:   return NULL;
  459: }
  460: 
  461: /* Free route map's compiled `set metric' value. */
  462: static void
  463: route_set_metric_free (void *rule)
  464: {
  465:   XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  466: }
  467: 
  468: /* Set metric rule structure. */
  469: struct route_map_rule_cmd route_set_metric_cmd =
  470: {
  471:   "metric",
  472:   route_set_metric,
  473:   route_set_metric_compile,
  474:   route_set_metric_free,
  475: };
  476: 
  477: /* `set metric-type TYPE' */
  478: /* Set metric-type to attribute. */
  479: static route_map_result_t
  480: route_set_metric_type (void *rule, struct prefix *prefix,
  481: 		       route_map_object_t type, void *object)
  482: {
  483:   u_int32_t *metric_type;
  484:   struct external_info *ei;
  485: 
  486:   if (type == RMAP_OSPF)
  487:     {
  488:       /* Fetch routemap's rule information. */
  489:       metric_type = rule;
  490:       ei = object;
  491: 
  492:       /* Set metric out value. */
  493:       ei->route_map_set.metric_type = *metric_type;
  494:     }
  495:   return RMAP_OKAY;
  496: }
  497: 
  498: /* set metric-type compilation. */
  499: static void *
  500: route_set_metric_type_compile (const char *arg)
  501: {
  502:   u_int32_t *metric_type;
  503: 
  504:   metric_type = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
  505:   if (strcmp (arg, "type-1") == 0)
  506:     *metric_type = EXTERNAL_METRIC_TYPE_1;
  507:   else if (strcmp (arg, "type-2") == 0)
  508:     *metric_type = EXTERNAL_METRIC_TYPE_2;
  509: 
  510:   if (*metric_type == EXTERNAL_METRIC_TYPE_1 ||
  511:       *metric_type == EXTERNAL_METRIC_TYPE_2)
  512:     return metric_type;
  513: 
  514:   XFREE (MTYPE_ROUTE_MAP_COMPILED, metric_type);
  515:   return NULL;
  516: }
  517: 
  518: /* Free route map's compiled `set metric-type' value. */
  519: static void
  520: route_set_metric_type_free (void *rule)
  521: {
  522:   XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  523: }
  524: 
  525: /* Set metric rule structure. */
  526: struct route_map_rule_cmd route_set_metric_type_cmd =
  527: {
  528:   "metric-type",
  529:   route_set_metric_type,
  530:   route_set_metric_type_compile,
  531:   route_set_metric_type_free,
  532: };
  533: 
  534: /* `set ip next-hop IP_ADDRESS' */
  535: /* Set nexthop to object. */
  536: static route_map_result_t
  537: route_set_ip_nexthop (void *rule, struct prefix *prefix,
  538: 		      route_map_object_t type, void *object)
  539: {
  540:   struct in_addr *address;
  541:   struct external_info *ei;
  542: 
  543:   if (type == RMAP_OSPF)
  544:     {
  545:       /* Fetch routemap's rule information. */
  546:       address = rule;
  547:       ei = object;
  548: 
  549:       /* Set metric out value. */
  550:       ei->route_map_set.nexthop = *address;
  551:     }
  552:   return RMAP_OKAY;
  553: }
  554: 
  555: /* set ip next-hop compilation. */
  556: static void *
  557: route_set_ip_nexthop_compile (const char *arg)
  558: {
  559:   struct in_addr *address = NULL;
  560:   int ret;
  561: 
  562:   address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
  563:   ret = inet_aton (arg, address);
  564: 
  565:   if (ret == 0)
  566:     {
  567:       XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
  568:       return NULL;
  569:     }
  570: 
  571:   return address;
  572: }
  573: 
  574: /* Free route map's compiled `set ip next-hop' value. */
  575: static void
  576: route_set_ip_nexthop_free (void *rule)
  577: {
  578:   XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
  579: }
  580: 
  581: /* Set ip next-hop rule structure. */
  582: struct route_map_rule_cmd route_set_ip_nexthop_cmd =
  583: {
  584:   "ip next-hop",
  585:   route_set_ip_nexthop,
  586:   route_set_ip_nexthop_compile,
  587:   route_set_ip_nexthop_free,
  588: };
  589: 
  590: DEFUN (match_ip_nexthop,
  591:        match_ip_nexthop_cmd,
  592:        "match ip next-hop (<1-199>|<1300-2699>|WORD)",
  593:        MATCH_STR
  594:        IP_STR
  595:        "Match next-hop address of route\n"
  596:        "IP access-list number\n"
  597:        "IP access-list number (expanded range)\n"
  598:        "IP access-list name\n")
  599: {
  600:   return ospf_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
  601: }
  602: 
  603: DEFUN (no_match_ip_nexthop,
  604:        no_match_ip_nexthop_cmd,
  605:        "no match ip next-hop",
  606:        NO_STR
  607:        MATCH_STR
  608:        IP_STR
  609:        "Match next-hop address of route\n")
  610: {
  611:   if (argc == 0)
  612:     return ospf_route_match_delete (vty, vty->index, "ip next-hop", NULL);
  613: 
  614:   return ospf_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
  615: }
  616: 
  617: ALIAS (no_match_ip_nexthop,
  618:        no_match_ip_nexthop_val_cmd,
  619:        "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
  620:        NO_STR
  621:        MATCH_STR
  622:        IP_STR
  623:        "Match next-hop address of route\n"
  624:        "IP access-list number\n"
  625:        "IP access-list number (expanded range)\n"
  626:        "IP access-list name\n")
  627: 
  628: DEFUN (match_ip_next_hop_prefix_list,
  629:        match_ip_next_hop_prefix_list_cmd,
  630:        "match ip next-hop prefix-list WORD",
  631:        MATCH_STR
  632:        IP_STR
  633:        "Match next-hop address of route\n"
  634:        "Match entries of prefix-lists\n"
  635:        "IP prefix-list name\n")
  636: {
  637:   return ospf_route_match_add (vty, vty->index, "ip next-hop prefix-list",
  638: 			       argv[0]);
  639: }
  640: 
  641: DEFUN (no_match_ip_next_hop_prefix_list,
  642:        no_match_ip_next_hop_prefix_list_cmd,
  643:        "no match ip next-hop prefix-list",
  644:        NO_STR
  645:        MATCH_STR
  646:        IP_STR
  647:        "Match next-hop address of route\n"
  648:        "Match entries of prefix-lists\n")
  649: {
  650:   if (argc == 0)
  651:     return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list",
  652: 				    NULL);
  653:   return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list",
  654: 				  argv[0]);
  655: }
  656: 
  657: ALIAS (no_match_ip_next_hop_prefix_list,
  658:        no_match_ip_next_hop_prefix_list_val_cmd,
  659:        "no match ip next-hop prefix-list WORD",
  660:        NO_STR
  661:        MATCH_STR
  662:        IP_STR
  663:        "Match next-hop address of route\n"
  664:        "Match entries of prefix-lists\n"
  665:        "IP prefix-list name\n")
  666: 
  667: DEFUN (match_ip_address,
  668:        match_ip_address_cmd,
  669:        "match ip address (<1-199>|<1300-2699>|WORD)",
  670:        MATCH_STR
  671:        IP_STR
  672:        "Match address of route\n"
  673:        "IP access-list number\n"
  674:        "IP access-list number (expanded range)\n"
  675:        "IP access-list name\n")
  676: {
  677:   return ospf_route_match_add (vty, vty->index, "ip address", argv[0]);
  678: }
  679: 
  680: DEFUN (no_match_ip_address,
  681:        no_match_ip_address_cmd,
  682:        "no match ip address",
  683:        NO_STR
  684:        MATCH_STR
  685:        IP_STR
  686:        "Match address of route\n")
  687: {
  688:   if (argc == 0)
  689:     return ospf_route_match_delete (vty, vty->index, "ip address", NULL);
  690: 
  691:   return ospf_route_match_delete (vty, vty->index, "ip address", argv[0]);
  692: }
  693: 
  694: ALIAS (no_match_ip_address,
  695:        no_match_ip_address_val_cmd,
  696:        "no match ip address (<1-199>|<1300-2699>|WORD)",
  697:        NO_STR
  698:        MATCH_STR
  699:        IP_STR
  700:        "Match address of route\n"
  701:        "IP access-list number\n"
  702:        "IP access-list number (expanded range)\n"
  703:        "IP access-list name\n")
  704: 
  705: DEFUN (match_ip_address_prefix_list,
  706:        match_ip_address_prefix_list_cmd,
  707:        "match ip address prefix-list WORD",
  708:        MATCH_STR
  709:        IP_STR
  710:        "Match address of route\n"
  711:        "Match entries of prefix-lists\n"
  712:        "IP prefix-list name\n")
  713: {
  714:   return ospf_route_match_add (vty, vty->index, "ip address prefix-list",
  715: 			       argv[0]);
  716: }
  717: 
  718: DEFUN (no_match_ip_address_prefix_list,
  719:        no_match_ip_address_prefix_list_cmd,
  720:        "no match ip address prefix-list",
  721:        NO_STR
  722:        MATCH_STR
  723:        IP_STR
  724:        "Match address of route\n"
  725:        "Match entries of prefix-lists\n")
  726: {
  727:   if (argc == 0)
  728:     return ospf_route_match_delete (vty, vty->index, "ip address prefix-list",
  729: 				    NULL);
  730:   return ospf_route_match_delete (vty, vty->index, "ip address prefix-list",
  731: 				  argv[0]);
  732: }
  733: 
  734: ALIAS (no_match_ip_address_prefix_list,
  735:        no_match_ip_address_prefix_list_val_cmd,
  736:        "no match ip address prefix-list WORD",
  737:        NO_STR
  738:        MATCH_STR
  739:        IP_STR
  740:        "Match address of route\n"
  741:        "Match entries of prefix-lists\n"
  742:        "IP prefix-list name\n")
  743: 
  744: DEFUN (match_interface,
  745:        match_interface_cmd,
  746:        "match interface WORD",
  747:        MATCH_STR
  748:        "Match first hop interface of route\n"
  749:        "Interface name\n")
  750: {
  751:   return ospf_route_match_add (vty, vty->index, "interface", argv[0]);
  752: }
  753: 
  754: DEFUN (no_match_interface,
  755:        no_match_interface_cmd,
  756:        "no match interface",
  757:        NO_STR
  758:        MATCH_STR
  759:        "Match first hop interface of route\n")
  760: {
  761:   if (argc == 0)
  762:     return ospf_route_match_delete (vty, vty->index, "interface", NULL);
  763: 
  764:   return ospf_route_match_delete (vty, vty->index, "interface", argv[0]);
  765: }
  766: 
  767: ALIAS (no_match_interface,
  768:        no_match_interface_val_cmd,
  769:        "no match interface WORD",
  770:        NO_STR
  771:        MATCH_STR
  772:        "Match first hop interface of route\n"
  773:        "Interface name\n")
  774: 
  775: DEFUN (set_metric,
  776:        set_metric_cmd,
  777:        "set metric <0-4294967295>",
  778:        SET_STR
  779:        "Metric value for destination routing protocol\n"
  780:        "Metric value\n")
  781: {
  782:   return ospf_route_set_add (vty, vty->index, "metric", argv[0]);
  783: }
  784: 
  785: DEFUN (no_set_metric,
  786:        no_set_metric_cmd,
  787:        "no set metric",
  788:        NO_STR
  789:        SET_STR
  790:        "Metric value for destination routing protocol\n")
  791: {
  792:   if (argc == 0)
  793:     return ospf_route_set_delete (vty, vty->index, "metric", NULL);
  794: 
  795:   return ospf_route_set_delete (vty, vty->index, "metric", argv[0]);
  796: }
  797: 
  798: ALIAS (no_set_metric,
  799:        no_set_metric_val_cmd,
  800:        "no set metric <0-4294967295>",
  801:        NO_STR
  802:        SET_STR
  803:        "Metric value for destination routing protocol\n"
  804:        "Metric value\n")
  805: 
  806: DEFUN (set_metric_type,
  807:        set_metric_type_cmd,
  808:        "set metric-type (type-1|type-2)",
  809:        SET_STR
  810:        "Type of metric for destination routing protocol\n"
  811:        "OSPF[6] external type 1 metric\n"
  812:        "OSPF[6] external type 2 metric\n")
  813: {
  814:   if (strcmp (argv[0], "1") == 0)
  815:     return ospf_route_set_add (vty, vty->index, "metric-type", "type-1");
  816:   if (strcmp (argv[0], "2") == 0)
  817:     return ospf_route_set_add (vty, vty->index, "metric-type", "type-2");
  818: 
  819:   return ospf_route_set_add (vty, vty->index, "metric-type", argv[0]);
  820: }
  821: 
  822: DEFUN (no_set_metric_type,
  823:        no_set_metric_type_cmd,
  824:        "no set metric-type",
  825:        NO_STR
  826:        SET_STR
  827:        "Type of metric for destination routing protocol\n")
  828: {
  829:   if (argc == 0)
  830:     return ospf_route_set_delete (vty, vty->index, "metric-type", NULL);
  831: 
  832:   return ospf_route_set_delete (vty, vty->index, "metric-type", argv[0]);
  833: }
  834: 
  835: ALIAS (no_set_metric_type,
  836:        no_set_metric_type_val_cmd,
  837:        "no set metric-type (type-1|type-2)",
  838:        NO_STR
  839:        SET_STR
  840:        "Type of metric for destination routing protocol\n"
  841:        "OSPF[6] external type 1 metric\n"
  842:        "OSPF[6] external type 2 metric\n")
  843: 
  844: DEFUN (set_ip_nexthop,
  845:        set_ip_nexthop_cmd,
  846:        "set ip next-hop A.B.C.D",
  847:        SET_STR
  848:        IP_STR
  849:        "Next hop address\n"
  850:        "IP address of next hop\n")
  851: {
  852:   union sockunion su;
  853:   int ret;
  854: 
  855:   ret = str2sockunion (argv[0], &su);
  856:   if (ret < 0)
  857:     {
  858:       vty_out (vty, "%% Malformed Next-hop address%s", VTY_NEWLINE);
  859:       return CMD_WARNING;
  860:     }
  861: 
  862:   return ospf_route_set_add (vty, vty->index, "ip next-hop", argv[0]);
  863: }
  864: 
  865: DEFUN (no_set_ip_nexthop,
  866:        no_set_ip_nexthop_cmd,
  867:        "no set ip next-hop",
  868:        NO_STR
  869:        SET_STR
  870:        "Next hop address\n")
  871: {
  872:   if (argc == 0)
  873:     return ospf_route_set_delete (vty, vty->index, "ip next-hop", NULL);
  874: 
  875:   return ospf_route_set_delete (vty, vty->index, "ip next-hop", argv[0]);
  876: }
  877: 
  878: ALIAS (no_set_ip_nexthop,
  879:        no_set_ip_nexthop_val_cmd,
  880:        "no set ip next-hop A.B.C.D",
  881:        NO_STR
  882:        SET_STR
  883:        IP_STR
  884:        "Next hop address\n"
  885:        "IP address of next hop\n")
  886: 
  887: /* Route-map init */
  888: void
  889: ospf_route_map_init (void)
  890: {
  891:   route_map_init ();
  892:   route_map_init_vty ();
  893: 
  894:   route_map_add_hook (ospf_route_map_update);
  895:   route_map_delete_hook (ospf_route_map_update);
  896:   route_map_event_hook (ospf_route_map_event);
  897:   
  898:   route_map_install_match (&route_match_ip_nexthop_cmd);
  899:   route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
  900:   route_map_install_match (&route_match_ip_address_cmd);
  901:   route_map_install_match (&route_match_ip_address_prefix_list_cmd);
  902:   route_map_install_match (&route_match_interface_cmd);
  903: 
  904:   route_map_install_set (&route_set_metric_cmd);
  905:   route_map_install_set (&route_set_metric_type_cmd);
  906:   route_map_install_set (&route_set_ip_nexthop_cmd);
  907: 
  908:   install_element (RMAP_NODE, &match_ip_nexthop_cmd);
  909:   install_element (RMAP_NODE, &no_match_ip_nexthop_cmd);
  910:   install_element (RMAP_NODE, &no_match_ip_nexthop_val_cmd);
  911:   install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
  912:   install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
  913:   install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
  914:   install_element (RMAP_NODE, &match_ip_address_cmd);
  915:   install_element (RMAP_NODE, &no_match_ip_address_cmd);
  916:   install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
  917:   install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
  918:   install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
  919:   install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
  920:   install_element (RMAP_NODE, &match_interface_cmd);
  921:   install_element (RMAP_NODE, &no_match_interface_cmd);
  922:   install_element (RMAP_NODE, &no_match_interface_val_cmd);
  923: 
  924:   install_element (RMAP_NODE, &set_metric_cmd);
  925:   install_element (RMAP_NODE, &no_set_metric_cmd);
  926:   install_element (RMAP_NODE, &no_set_metric_val_cmd);
  927:   install_element (RMAP_NODE, &set_metric_type_cmd);
  928:   install_element (RMAP_NODE, &no_set_metric_type_cmd);
  929:   install_element (RMAP_NODE, &no_set_metric_type_val_cmd);
  930:   install_element (RMAP_NODE, &set_ip_nexthop_cmd);
  931:   install_element (RMAP_NODE, &no_set_ip_nexthop_cmd);
  932:   install_element (RMAP_NODE, &no_set_ip_nexthop_val_cmd);
  933: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>