]> git.proxmox.com Git - mirror_frr.git/blobdiff - ripngd/ripng_routemap.c
Merge pull request #3422 from pguibert6WIND/license_gplv3_rule
[mirror_frr.git] / ripngd / ripng_routemap.c
index 3080801fb3537db541946a05f757e08fed8c5908..9a9e346a5931c33f0684e0f756f1778cd763da83 100644 (file)
 
 struct rip_metric_modifier {
        enum { metric_increment, metric_decrement, metric_absolute } type;
-
-       u_char metric;
+       bool used;
+       uint8_t metric;
 };
 
 /* `match metric METRIC' */
 /* Match function return 1 if match is success else return zero. */
-static route_map_result_t route_match_metric(void *rule, struct prefix *prefix,
+static route_map_result_t route_match_metric(void *rule,
+                                            const struct prefix *prefix,
                                             route_map_object_t type,
                                             void *object)
 {
-       u_int32_t *metric;
+       uint32_t *metric;
        struct ripng_info *rinfo;
 
        if (type == RMAP_RIPNG) {
@@ -60,9 +61,9 @@ static route_map_result_t route_match_metric(void *rule, struct prefix *prefix,
 /* Route map `match metric' match statement. `arg' is METRIC value */
 static void *route_match_metric_compile(const char *arg)
 {
-       u_int32_t *metric;
+       uint32_t *metric;
 
-       metric = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_int32_t));
+       metric = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t));
        *metric = atoi(arg);
 
        if (*metric > 0)
@@ -86,7 +87,7 @@ static struct route_map_rule_cmd route_match_metric_cmd = {
 /* `match interface IFNAME' */
 /* Match function return 1 if match is success else return zero. */
 static route_map_result_t route_match_interface(void *rule,
-                                               struct prefix *prefix,
+                                               const struct prefix *prefix,
                                                route_map_object_t type,
                                                void *object)
 {
@@ -128,7 +129,8 @@ static struct route_map_rule_cmd route_match_interface_cmd = {
 
 /* `match tag TAG' */
 /* Match function return 1 if match is success else return zero. */
-static route_map_result_t route_match_tag(void *rule, struct prefix *prefix,
+static route_map_result_t route_match_tag(void *rule,
+                                         const struct prefix *prefix,
                                          route_map_object_t type, void *object)
 {
        route_tag_t *tag;
@@ -157,7 +159,8 @@ static struct route_map_rule_cmd route_match_tag_cmd = {
 /* `set metric METRIC' */
 
 /* Set metric to attribute. */
-static route_map_result_t route_set_metric(void *rule, struct prefix *prefix,
+static route_map_result_t route_set_metric(void *rule,
+                                          const struct prefix *prefix,
                                           route_map_object_t type,
                                           void *object)
 {
@@ -168,6 +171,9 @@ static route_map_result_t route_set_metric(void *rule, struct prefix *prefix,
                mod = rule;
                rinfo = object;
 
+               if (!mod->used)
+                       return RMAP_OKAY;
+
                if (mod->type == metric_increment)
                        rinfo->metric_out += mod->metric;
                else if (mod->type == metric_decrement)
@@ -190,7 +196,6 @@ static void *route_set_metric_compile(const char *arg)
 {
        int len;
        const char *pnt;
-       int type;
        long metric;
        char *endptr = NULL;
        struct rip_metric_modifier *mod;
@@ -198,38 +203,42 @@ static void *route_set_metric_compile(const char *arg)
        len = strlen(arg);
        pnt = arg;
 
+       mod = XMALLOC(MTYPE_ROUTE_MAP_COMPILED,
+                     sizeof(struct rip_metric_modifier));
+       mod->used = false;
+
        if (len == 0)
-               return NULL;
+               return mod;
 
        /* Examine first character. */
        if (arg[0] == '+') {
-               type = metric_increment;
+               mod->type = metric_increment;
                pnt++;
        } else if (arg[0] == '-') {
-               type = metric_decrement;
+               mod->type = metric_decrement;
                pnt++;
        } else
-               type = metric_absolute;
+               mod->type = metric_absolute;
 
        /* Check beginning with digit string. */
        if (*pnt < '0' || *pnt > '9')
-               return NULL;
+               return mod;
 
        /* Convert string to integer. */
        metric = strtol(pnt, &endptr, 10);
 
-       if (metric == LONG_MAX || *endptr != '\0')
-               return NULL;
-       /* Commented out by Hasso Tepper, to avoid problems in vtysh. */
-       /* if (metric < 0 || metric > RIPNG_METRIC_INFINITY) */
-       if (metric < 0)
-               return NULL;
+       if (*endptr != '\0' || metric < 0)
+               return mod;
 
-       mod = XMALLOC(MTYPE_ROUTE_MAP_COMPILED,
-                     sizeof(struct rip_metric_modifier));
-       mod->type = type;
-       mod->metric = metric;
+       if (metric > RIPNG_METRIC_INFINITY) {
+               zlog_info("%s: Metric specified: %ld is being converted into METRIC_INFINITY",
+                         __PRETTY_FUNCTION__,
+                         metric);
+               mod->metric = RIPNG_METRIC_INFINITY;
+       } else
+               mod->metric = metric;
 
+       mod->used = true;
        return mod;
 }
 
@@ -248,7 +257,7 @@ static struct route_map_rule_cmd route_set_metric_cmd = {
 
 /* Set nexthop to object.  ojbect must be pointer to struct attr. */
 static route_map_result_t route_set_ipv6_nexthop_local(void *rule,
-                                                      struct prefix *prefix,
+                                                      const struct prefix *p,
                                                       route_map_object_t type,
                                                       void *object)
 {
@@ -301,7 +310,8 @@ static struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd = {
 /* `set tag TAG' */
 
 /* Set tag to object.  ojbect must be pointer to struct attr. */
-static route_map_result_t route_set_tag(void *rule, struct prefix *prefix,
+static route_map_result_t route_set_tag(void *rule,
+                                       const struct prefix *prefix,
                                        route_map_object_t type, void *object)
 {
        route_tag_t *tag;
@@ -327,12 +337,6 @@ static struct route_map_rule_cmd route_set_tag_cmd = {
 #define MATCH_STR "Match values from routing table\n"
 #define SET_STR "Set values in destination routing protocol\n"
 
-void ripng_route_map_reset()
-{
-       /* XXX ??? */
-       ;
-}
-
 void ripng_route_map_init()
 {
        route_map_init();