After introducing multi-table routing, all local routing entries now
resides in a dedicated table CLS_LOCAL. There is no need to keep a
per-entry flag to distinguish local from non-local entry any longer, so
drop it. This is the case because we're not considering any routes that
are not unicast or local, i.e. we're not considering broadcast routes
that would also normally reside in the local table.

A 'user' flag is added in place of the removed 'local' flag to simplify
identification of user-added routes. Previously, it was done by
comparing 'priority' and 'plen' fields, which was confusing in some
cases.

Signed-off-by: Dima Chumak <[email protected]>
---
 lib/netdev-dummy.c  | 12 ++++++------
 lib/ovs-router.c    | 44 ++++++++++++++++++--------------------------
 lib/ovs-router.h    |  5 ++---
 lib/route-table.c   |  3 +--
 tests/ovs-router.at |  2 +-
 5 files changed, 28 insertions(+), 38 deletions(-)

diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index a3ba8710919e..3083791b7042 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -2302,11 +2302,11 @@ netdev_dummy_ip4addr(struct unixctl_conn *conn, int 
argc OVS_UNUSED,
 
             in6_addr_set_mapped_ipv4(&ip6, ip.s_addr);
             /* Insert local route entry for the new address. */
-            ovs_router_force_insert(CLS_LOCAL, 0, &ip6, 32 + 96, true,
-                                    argv[1], &in6addr_any, &ip6);
+            ovs_router_force_insert(CLS_LOCAL, 0, &ip6, 32 + 96, argv[1],
+                                    &in6addr_any, &ip6);
             /* Insert network route entry for the new address. */
-            ovs_router_force_insert(CLS_MAIN, 0, &ip6, plen + 96, false,
-                                    argv[1], &in6addr_any, &ip6);
+            ovs_router_force_insert(CLS_MAIN, 0, &ip6, plen + 96, argv[1],
+                                    &in6addr_any, &ip6);
 
             unixctl_command_reply(conn, "OK");
         } else {
@@ -2339,10 +2339,10 @@ netdev_dummy_ip6addr(struct unixctl_conn *conn, int 
argc OVS_UNUSED,
             netdev_dummy_add_in6(netdev, &ip6, &mask);
 
             /* Insert local route entry for the new address. */
-            ovs_router_force_insert(CLS_LOCAL, 0, &ip6, 128, true, argv[1],
+            ovs_router_force_insert(CLS_LOCAL, 0, &ip6, 128, argv[1],
                                     &in6addr_any, &ip6);
             /* Insert network route entry for the new address. */
-            ovs_router_force_insert(CLS_MAIN, 0, &ip6, plen, false, argv[1],
+            ovs_router_force_insert(CLS_MAIN, 0, &ip6, plen, argv[1],
                                     &in6addr_any, &ip6);
 
             unixctl_command_reply(conn, "OK");
diff --git a/lib/ovs-router.c b/lib/ovs-router.c
index b3131ae1a4d4..4c5713307e93 100644
--- a/lib/ovs-router.c
+++ b/lib/ovs-router.c
@@ -85,7 +85,7 @@ struct ovs_router_entry {
     struct in6_addr src_addr;
     uint8_t plen;
     uint8_t priority;
-    bool local;
+    bool user;
     uint32_t mark;
 };
 
@@ -126,7 +126,7 @@ cls_flush(struct classifier *cls, bool flush_all)
 
     classifier_defer(cls);
     CLS_FOR_EACH (rt, cr, cls) {
-        if (flush_all || rt->priority == rt->plen || rt->local) {
+        if (flush_all || !rt->user) {
             rt_entry_delete__(&rt->cr, cls);
         }
     }
@@ -188,12 +188,7 @@ ovs_router_lookup(uint32_t mark, const struct in6_addr 
*ip6_dst,
 
         cr_src = classifier_lookup(cls_local, OVS_VERSION_MAX, &flow_src,
                                    NULL, NULL);
-        if (cr_src) {
-            struct ovs_router_entry *p_src = ovs_router_entry_cast(cr_src);
-            if (!p_src->local) {
-                return false;
-            }
-        } else {
+        if (!cr_src) {
             return false;
         }
     }
@@ -373,7 +368,7 @@ out:
 
 static int
 ovs_router_insert__(uint32_t table, uint32_t mark, uint8_t priority,
-                    bool local, const struct in6_addr *ip6_dst,
+                    bool user, const struct in6_addr *ip6_dst,
                     uint8_t plen, const char output_netdev[],
                     const struct in6_addr *gw,
                     const struct in6_addr *ip6_src)
@@ -397,7 +392,7 @@ ovs_router_insert__(uint32_t table, uint32_t mark, uint8_t 
priority,
     p->mark = mark;
     p->nw_addr = match.flow.ipv6_dst;
     p->plen = plen;
-    p->local = local;
+    p->user = user;
     p->priority = priority;
 
     if (ipv6_addr_is_set(ip6_src)) {
@@ -442,12 +437,11 @@ ovs_router_insert__(uint32_t table, uint32_t mark, 
uint8_t priority,
 
 void
 ovs_router_insert(uint32_t table, uint32_t mark, const struct in6_addr *ip_dst,
-                  uint8_t plen, bool local, const char output_netdev[],
+                  uint8_t plen, bool user, const char output_netdev[],
                   const struct in6_addr *gw, const struct in6_addr *prefsrc)
 {
     if (use_system_routing_table) {
-        uint8_t priority = local ? plen + 64 : plen;
-        ovs_router_insert__(table, mark, priority, local, ip_dst, plen,
+        ovs_router_insert__(table, mark, plen, user, ip_dst, plen,
                             output_netdev, gw, prefsrc);
     }
 }
@@ -457,14 +451,12 @@ ovs_router_insert(uint32_t table, uint32_t mark, const 
struct in6_addr *ip_dst,
 void
 ovs_router_force_insert(uint32_t table, uint32_t mark,
                         const struct in6_addr *ip_dst,
-                        uint8_t plen, bool local, const char output_netdev[],
+                        uint8_t plen, const char output_netdev[],
                         const struct in6_addr *gw,
                         const struct in6_addr *prefsrc)
 {
-    uint8_t priority = local ? plen + 64 : plen;
-
-    ovs_router_insert__(table, mark, priority, local, ip_dst, plen,
-                        output_netdev, gw, prefsrc);
+    ovs_router_insert__(table, mark, plen, false, ip_dst, plen, output_netdev,
+                        gw, prefsrc);
 }
 
 static void
@@ -595,7 +587,7 @@ ovs_router_add(struct unixctl_conn *conn, int argc,
         in6_addr_set_mapped_ipv4(&src6, src);
     }
 
-    err = ovs_router_insert__(CLS_MAIN, mark, plen + 32, false, &ip6, plen,
+    err = ovs_router_insert__(CLS_MAIN, mark, plen + 32, true, &ip6, plen,
                               argv[2], &gw6, &src6);
     if (err) {
         unixctl_command_reply_error(conn, "Error while inserting route.");
@@ -647,7 +639,6 @@ ovs_router_show_json(struct json *json_routes, const struct 
classifier *cls,
     }
 
     CLS_FOR_EACH (rt, cr, cls) {
-        bool user = rt->priority != rt->plen && !rt->local;
         uint8_t plen = rt->plen;
         struct json *json, *nh;
 
@@ -659,8 +650,9 @@ ovs_router_show_json(struct json *json_routes, const struct 
classifier *cls,
         }
 
         json_object_put(json, "table", json_integer_create(table));
-        json_object_put(json, "user", json_boolean_create(user));
-        json_object_put(json, "local", json_boolean_create(rt->local));
+        json_object_put(json, "user", json_boolean_create(rt->user));
+        json_object_put(json, "local",
+                        json_boolean_create(table == CLS_LOCAL && !rt->user));
         json_object_put(json, "priority", json_integer_create(rt->priority));
         json_object_put(json, "prefix", json_integer_create(plen));
         json_object_put_string(nh, "dev", rt->output_netdev);
@@ -718,10 +710,10 @@ ovs_router_show_text(struct ds *ds, const struct 
classifier *cls,
 
     CLS_FOR_EACH (rt, cr, cls) {
         uint8_t plen;
-        if (rt->priority == rt->plen || rt->local) {
-            ds_put_format(ds, "Cached: ");
-        } else {
+        if (rt->user) {
             ds_put_format(ds, "User: ");
+        } else {
+            ds_put_format(ds, "Cached: ");
         }
         ipv6_format_mapped(&rt->nw_addr, ds);
         plen = rt->plen;
@@ -740,7 +732,7 @@ ovs_router_show_text(struct ds *ds, const struct classifier 
*cls,
         }
         ds_put_format(ds, " SRC ");
         ipv6_format_mapped(&rt->src_addr, ds);
-        if (rt->local) {
+        if (table == CLS_LOCAL && !rt->user) {
             ds_put_format(ds, " local");
         }
         if (!is_standard_table(table) && !show_header) {
diff --git a/lib/ovs-router.h b/lib/ovs-router.h
index 62d306423ce6..f9c1d90d39b0 100644
--- a/lib/ovs-router.h
+++ b/lib/ovs-router.h
@@ -40,13 +40,12 @@ void ovs_router_init(void);
 bool ovs_router_is_referenced(uint32_t table);
 void ovs_router_insert(uint32_t table, uint32_t mark,
                        const struct in6_addr *ip_dst,
-                       uint8_t plen, bool local,
+                       uint8_t plen, bool user,
                        const char output_netdev[], const struct in6_addr *gw,
                        const struct in6_addr *prefsrc);
 void ovs_router_force_insert(uint32_t table, uint32_t mark,
                              const struct in6_addr *ip_dst,
-                             uint8_t plen, bool local,
-                             const char output_netdev[],
+                             uint8_t plen, const char output_netdev[],
                              const struct in6_addr *gw,
                              const struct in6_addr *prefsrc);
 void ovs_router_rule_add(uint32_t prio, bool invert, uint8_t src_len,
diff --git a/lib/route-table.c b/lib/route-table.c
index 9174696427a6..53bf5a8d5561 100644
--- a/lib/route-table.c
+++ b/lib/route-table.c
@@ -753,8 +753,7 @@ route_table_handle_msg(const struct route_table_msg *change,
         ovs_router_insert(table, rd->rta_mark, &rd->rta_dst,
                           IN6_IS_ADDR_V4MAPPED(&rd->rta_dst)
                           ? rd->rtm_dst_len + 96 : rd->rtm_dst_len,
-                          rd->rtn_local, rdnh->ifname, &rdnh->addr,
-                          &rd->rta_prefsrc);
+                          false, rdnh->ifname, &rdnh->addr, &rd->rta_prefsrc);
     }
 }
 
diff --git a/tests/ovs-router.at b/tests/ovs-router.at
index 4e5e26688b14..5837ff24bb34 100644
--- a/tests/ovs-router.at
+++ b/tests/ovs-router.at
@@ -38,7 +38,7 @@ AT_CHECK([ovs-appctl --format=json --pretty ovs/route/show], 
[0], [dnl
         "dev": "br0"}],
     "prefix": 32,
     "prefsrc": "2.2.2.2",
-    "priority": 192,
+    "priority": 128,
     "table": 255,
     "user": false},
   {
-- 
2.52.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to