[ovs-dev,v2,2/3] OVN: add TCP port unreachable support to OVN logical router
diff mbox series

Message ID 75a3a4e16b50df6a036d13c81f39875c93c446cb.1529316047.git.lorenzo.bianconi@redhat.com
State Accepted
Headers show
Series
  • add TCP/UDP port unreachable support to OVN logical router
Related show

Commit Message

Lorenzo Bianconi June 18, 2018, 11:55 a.m. UTC
Add priority-80 flows to generate TCP reset messages in reply to
TCP datagrams directed to the router's IP address since the
logical router doesn't accept any TCP traffic

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 ovn/northd/ovn-northd.8.xml |  4 ----
 ovn/northd/ovn-northd.c     | 29 ++++++++++++++++++++++++++++-
 tests/ovn.at                | 31 +++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/ovn/northd/ovn-northd.8.xml b/ovn/northd/ovn-northd.8.xml
index a33de3d95..18a481b3d 100644
--- a/ovn/northd/ovn-northd.8.xml
+++ b/ovn/northd/ovn-northd.8.xml
@@ -1330,10 +1330,6 @@  nd_na {
         <p>
           These flows should not match IP fragments with nonzero offset.
         </p>
-
-        <p>
-          Details TBD.  Not yet implemented.
-        </p>
       </li>
 
       <li>
diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
index 568d19b7d..27d7aab06 100644
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -5147,7 +5147,7 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
                           ds_cstr(&match), ds_cstr(&actions));
         }
 
-        /* UDP port unreachable */
+        /* UDP/TCP port unreachable */
         for (int i = 0; i < op->lrp_networks.n_ipv4_addrs; i++) {
             const char *action;
 
@@ -5164,6 +5164,17 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
                         "next; };";
             ovn_lflow_add(lflows, op->od, S_ROUTER_IN_IP_INPUT, 80,
                           ds_cstr(&match), action);
+
+            ds_clear(&match);
+            ds_put_format(&match,
+                          "ip4 && ip4.dst == %s && !ip.later_frag && tcp",
+                          op->lrp_networks.ipv4_addrs[i].addr_s);
+            action = "tcp_reset {"
+                        "eth.dst <-> eth.src; "
+                        "ip4.dst <-> ip4.src; "
+                        "next; };";
+            ovn_lflow_add(lflows, op->od, S_ROUTER_IN_IP_INPUT, 80,
+                          ds_cstr(&match), action);
         }
 
         ds_clear(&match);
@@ -5285,6 +5296,22 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
             ovn_lflow_add(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
                           ds_cstr(&match), ds_cstr(&actions));
         }
+
+        /* TCP port unreachable */
+        for (int i = 0; i < op->lrp_networks.n_ipv6_addrs; i++) {
+            const char *action;
+
+            ds_clear(&match);
+            ds_put_format(&match,
+                          "ip6 && ip6.dst == %s && !ip.later_frag && tcp",
+                          op->lrp_networks.ipv6_addrs[i].addr_s);
+            action = "tcp_reset {"
+                        "eth.dst <-> eth.src; "
+                        "ip6.dst <-> ip6.src; "
+                        "next; };";
+            ovn_lflow_add(lflows, op->od, S_ROUTER_IN_IP_INPUT, 80,
+                          ds_cstr(&match), action);
+        }
     }
 
     /* NAT, Defrag and load balancing. */
diff --git a/tests/ovn.at b/tests/ovn.at
index ee807f9c3..4648a303c 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -10379,6 +10379,34 @@  test_ip_packet() {
     as hv$hv ovs-appctl netdev-dummy/receive vif$inport $packet
 }
 
+# test_tcp_syn_packet INPORT HV ETH_SRC ETH_DST IPV4_SRC IPV4_ROUTER IP_CHKSUM TCP_SPORT TCP_DPORT TCP_CHKSUM EXP_IP_CHKSUM EXP_TCP_RST_CHKSUM
+#
+# Causes a packet to be received on INPORT of the hypervisor HV. The packet is an TCP syn segment with
+# ETH_SRC, ETH_DST, IPV4_SRC, IPV4_ROUTER, IP_CHKSUM, TCP_SPORT, TCP_DPORT, TCP_CHKSUM  as specified.
+# EXP_IP_CHKSUM and EXP_TCP_RST_CHKSUM are the ip and tcp checksums of the tcp reset segment generated by OVN logical router
+#
+# INPORT is an lport number, e.g. 11 for vif11.
+# HV is an hypervisor number
+# ETH_SRC and ETH_DST are each 12 hex digits.
+# IPV4_SRC and IPV4_ROUTER are each 8 hex digits.
+# TCP_SPORT and TCP_DPORT are 4 hex digits.
+# IP_CHKSUM, TCP_CHKSUM, EXP_IP_CHSUM and EXP_TCP_RST_CHKSUM are each 4 hex digits
+test_tcp_syn_packet() {
+    local inport=$1 hv=$2 eth_src=$3 eth_dst=$4 ipv4_src=$5 ip_router=$6 ip_chksum=$7
+    local tcp_sport=$8 tcp_dport=$9 tcp_chksum=${10}
+    local exp_ip_chksum=${11} exp_tcp_rst_chksum=${12}
+    shift 12
+
+    local ip_ttl=ff
+    local packet=${eth_dst}${eth_src}08004500002800004000${ip_ttl}06${ip_chksum}${ipv4_src}${ip_router}${tcp_sport}${tcp_dport}000000010000000050027210${tcp_chksum}0000
+
+    local tcp_rst_ttl=fe
+    local reply=${eth_src}${eth_dst}08004500002800004000${tcp_rst_ttl}06${exp_ip_chksum}${ip_router}${ipv4_src}${tcp_dport}${tcp_sport}000000000000000150040000${exp_tcp_rst_chksum}0000
+    echo $reply >> vif$inport.expected
+
+    as hv$hv ovs-appctl netdev-dummy/receive vif$inport $packet
+}
+
 ip_to_hex() {
     printf "%02x%02x%02x%02x" "$@"
 }
@@ -10418,5 +10446,8 @@  ovn-nbctl --wait=hv sync
 test_ip_packet 1 1 000000000001 00000000ff01 $(ip_to_hex 192 168 1 1) $(ip_to_hex 192 168 1 254) 11 0000 7dae fcfc 0303
 OVN_CHECK_PACKETS([hv1/vif1-tx.pcap], [vif1.expected])
 
+test_tcp_syn_packet 2 2 000000000002 00000000ff02 $(ip_to_hex 192 168 2 1) $(ip_to_hex 192 168 2 254) 0000 8b40 3039 0000 7bae 4486
+OVN_CHECK_PACKETS([hv2/vif2-tx.pcap], [vif2.expected])
+
 OVN_CLEANUP([hv1], [hv2])
 AT_CLEANUP