It is more convenient to support "both" as a keyword to indicate both
directions instead of having to create two mirror objects to mirror both
directions.

Signed-off-by: Han Zhou <[email protected]>
---
 NEWS                      |  3 ++-
 controller/mirror.c       | 14 ++++++++++----
 ovn-nb.ovsschema          |  7 ++++---
 ovn-nb.xml                |  1 +
 ovn-sb.ovsschema          |  7 ++++---
 ovn-sb.xml                |  3 +++
 tests/ovn.at              |  7 +++++++
 utilities/ovn-nbctl.8.xml |  3 ++-
 utilities/ovn-nbctl.c     |  8 +++++---
 9 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/NEWS b/NEWS
index f49d4049c332..9c850c7fa914 100644
--- a/NEWS
+++ b/NEWS
@@ -14,7 +14,8 @@ Post v23.03.0
     existing behaviour of flooding these arp requests to all attached Ports.
   - Always allow IPv6 Router Discovery, Neighbor Discovery, and Multicast
     Listener Discovery protocols, regardless of ACLs defined.
-  - Support using local OVS port as port-mirroring target.
+  - Support using local OVS port as port-mirroring target, and also support
+    'both' directions for the 'filter' field.
 
 OVN v23.03.0 - 03 Mar 2023
 --------------------------
diff --git a/controller/mirror.c b/controller/mirror.c
index fd36c7650c41..1ed8b5eef3f7 100644
--- a/controller/mirror.c
+++ b/controller/mirror.c
@@ -264,11 +264,17 @@ ovn_mirror_delete(struct ovn_mirror *m)
 static void
 ovn_mirror_add_lport(struct ovn_mirror *m, struct local_binding *lbinding)
 {
-    struct mirror_lport *m_lport = xzalloc(sizeof *m_lport);
-    m_lport->lbinding = lbinding;
-    if (!strcmp(m->sb_mirror->filter, "from-lport")) {
+    if (!strcmp(m->sb_mirror->filter, "from-lport") ||
+        !strcmp(m->sb_mirror->filter, "both")) {
+        struct mirror_lport *m_lport = xzalloc(sizeof *m_lport);
+        m_lport->lbinding = lbinding;
         ovs_list_push_back(&m->mirror_src_lports, &m_lport->list_node);
-    } else {
+    }
+
+    if (!strcmp(m->sb_mirror->filter, "to-lport") ||
+        !strcmp(m->sb_mirror->filter, "both")) {
+        struct mirror_lport *m_lport = xzalloc(sizeof *m_lport);
+        m_lport->lbinding = lbinding;
         ovs_list_push_back(&m->mirror_dst_lports, &m_lport->list_node);
     }
 }
diff --git a/ovn-nb.ovsschema b/ovn-nb.ovsschema
index dd5632562578..ff30266648d1 100644
--- a/ovn-nb.ovsschema
+++ b/ovn-nb.ovsschema
@@ -1,7 +1,7 @@
 {
     "name": "OVN_Northbound",
-    "version": "7.0.1",
-    "cksum": "441625132 33536",
+    "version": "7.0.2",
+    "cksum": "190109735 33605",
     "tables": {
         "NB_Global": {
             "columns": {
@@ -311,7 +311,8 @@
                 "name": {"type": "string"},
                 "filter": {"type": {"key": {"type": "string",
                                             "enum": ["set", ["from-lport",
-                                                             "to-lport"]]}}},
+                                                             "to-lport",
+                                                             "both"]]}}},
                 "sink":{"type": "string"},
                 "type": {"type": {"key": {"type": "string",
                                           "enum": ["set", ["gre",
diff --git a/ovn-nb.xml b/ovn-nb.xml
index 20b59df48f4e..efc2a054da82 100644
--- a/ovn-nb.xml
+++ b/ovn-nb.xml
@@ -2687,6 +2687,7 @@ or
         The value of this field represents selection criteria of the mirror.
         <code>to-lport</code> mirrors the packets coming into logical port.
         <code>from-lport</code> mirrors the packets going out of logical port.
+        <code>both</code> mirrors for both directions.
       </p>
     </column>
 
diff --git a/ovn-sb.ovsschema b/ovn-sb.ovsschema
index d5ac393f9210..f59af8cc5e0f 100644
--- a/ovn-sb.ovsschema
+++ b/ovn-sb.ovsschema
@@ -1,7 +1,7 @@
 {
     "name": "OVN_Southbound",
-    "version": "20.27.1",
-    "cksum": "1439763681 30400",
+    "version": "20.27.2",
+    "cksum": "1291808617 30462",
     "tables": {
         "SB_Global": {
             "columns": {
@@ -148,7 +148,8 @@
                 "filter": {"type": {"key": {"type": "string",
                                             "enum": ["set",
                                                      ["from-lport",
-                                                      "to-lport"]]}}},
+                                                      "to-lport",
+                                                      "both"]]}}},
                 "sink":{"type": "string"},
                 "type": {"type": {"key": {"type": "string",
                                           "enum": ["set", ["gre",
diff --git a/ovn-sb.xml b/ovn-sb.xml
index 9599e55f44e5..ff29c79a452f 100644
--- a/ovn-sb.xml
+++ b/ovn-sb.xml
@@ -2901,6 +2901,9 @@ tcp.flags = RST;
     <column name="filter">
       <p>
         The value of this field represents selection criteria of the mirror.
+        <code>to-lport</code> mirrors the packets coming into logical port.
+        <code>from-lport</code> mirrors the packets going out of logical port.
+        <code>both</code> mirrors for both directions.
       </p>
     </column>
 
diff --git a/tests/ovn.at b/tests/ovn.at
index 4c124e0e58d9..7fa43d55ec7d 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -16746,6 +16746,13 @@ OVS_WAIT_UNTIL([
 AT_CHECK([cat mirror1.packets | sort], [0], [expout])
 AT_CHECK([cat mirror2.packets | sort], [0], [expout])
 
+port_src_old=$(ovs-vsctl get mirror mirror-from-lp1 select_src_port)
+check ovn-nbctl set mirror $uuid1 filter=both
+port_src_new=$(ovs-vsctl get mirror mirror-from-lp1 select_src_port)
+port_dst_new=$(ovs-vsctl get mirror mirror-from-lp1 select_dst_port)
+AT_CHECK([test $port_src_old = $port_src_new], [0], [])
+AT_CHECK([test $port_src_old = $port_dst_new], [0], [])
+
 OVN_CLEANUP([hv1])
 AT_CLEANUP
 ])
diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml
index c450b9a5ba7d..8b4c3f29ac52 100644
--- a/utilities/ovn-nbctl.8.xml
+++ b/utilities/ovn-nbctl.8.xml
@@ -1567,7 +1567,8 @@
 
         <p>
           <var>filter</var> specifies the mirror source selection.
-          Can be <code>from-lport</code> or <code>to-lport</code>.
+          Can be <code>from-lport</code>, <code>to-lport</code> or
+          <code>both</code>.
         </p>
 
         <p>
diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c
index 5f2fbfecfe5b..51e063a4d6e3 100644
--- a/utilities/ovn-nbctl.c
+++ b/utilities/ovn-nbctl.c
@@ -280,7 +280,7 @@ Mirror commands:\n\
                                 (indicates key if GRE\n\
                                  erpsan_idx if ERSPAN)\n\
                             specify FILTER for mirroring selection\n\
-                                'to-lport' / 'from-lport'\n\
+                                'to-lport' / 'from-lport' / 'both'\n\
                             specify Sink / Destination i.e. Remote IP, or a\n\
                                 local interface with external-ids:mirror-id\n\
                                 matching MIRROR-ID\n\
@@ -7399,10 +7399,12 @@ parse_mirror_filter(const char *arg, const char 
**selection_p)
         *selection_p = "to-lport";
     } else if (arg[0] == 'f') {
         *selection_p = "from-lport";
+    } else if (arg[0] == 'b') {
+        *selection_p = "both";
     } else {
         *selection_p = NULL;
-        return xasprintf("%s: selection must be \"to-lport\" or "
-                         "\"from-lport\"", arg);
+        return xasprintf("%s: selection must be \"to-lport\", "
+                         "\"from-lport\", or \"both\"", arg);
     }
     return NULL;
 }
-- 
2.30.2

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

Reply via email to