[ovs-dev,v2] OVN: add ICMP time exceeded support to OVN logical router
diff mbox series

Message ID 2f13b78874d8cf6637b69ab29182ac77f945301a.1528988813.git.lorenzo.bianconi@redhat.com
State Accepted
Headers show
Series
  • [ovs-dev,v2] OVN: add ICMP time exceeded support to OVN logical router
Related show

Commit Message

Lorenzo Bianconi June 14, 2018, 3:27 p.m. UTC
Using icmp4 action, send an ICMP time exceeded frame whenever
an OVN logical router receives an IPv4 packets whose TTL has
expired (ip.ttl == {0, 1})

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
Changes since v1:
- use ovn-nbctl --wait=hv sync instead of sleep in automatic test
---
 ovn/northd/ovn-northd.8.xml |  4 --
 ovn/northd/ovn-northd.c     | 26 +++++++++++--
 tests/ovn.at                | 77 +++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 7 deletions(-)

Comments

Ben Pfaff June 14, 2018, 8:11 p.m. UTC | #1
On Thu, Jun 14, 2018 at 05:27:18PM +0200, Lorenzo Bianconi wrote:
> Using icmp4 action, send an ICMP time exceeded frame whenever
> an OVN logical router receives an IPv4 packets whose TTL has
> expired (ip.ttl == {0, 1})
> 
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> ---
> Changes since v1:
> - use ovn-nbctl --wait=hv sync instead of sleep in automatic test

Thanks.  I applied this to master.

Do you plan to add the same feature for IPv6 logical routers?
Lorenzo Bianconi June 15, 2018, 1:25 p.m. UTC | #2
> On Thu, Jun 14, 2018 at 05:27:18PM +0200, Lorenzo Bianconi wrote:
>> Using icmp4 action, send an ICMP time exceeded frame whenever
>> an OVN logical router receives an IPv4 packets whose TTL has
>> expired (ip.ttl == {0, 1})
>>
>> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
>> ---
>> Changes since v1:
>> - use ovn-nbctl --wait=hv sync instead of sleep in automatic test
>
> Thanks.  I applied this to master.
>
> Do you plan to add the same feature for IPv6 logical routers?

Yes, I will work on it
Regards,

Lorenzo

Patch
diff mbox series

diff --git a/ovn/northd/ovn-northd.8.xml b/ovn/northd/ovn-northd.8.xml
index 1d68f1aab..759d3dace 100644
--- a/ovn/northd/ovn-northd.8.xml
+++ b/ovn/northd/ovn-northd.8.xml
@@ -1401,10 +1401,6 @@  icmp4 {
     next;
 };
         </pre>
-
-        <p>
-          Not yet implemented.
-        </p>
       </li>
 
       <li>
diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
index aa6a18f16..74eefc6ca 100644
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -4858,9 +4858,7 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
         ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_INPUT, 50,
                       "eth.bcast", "drop;");
 
-        /* TTL discard.
-         *
-         * XXX Need to send ICMP time exceeded if !ip.later_frag. */
+        /* TTL discard */
         ds_clear(&match);
         ds_put_cstr(&match, "ip4 && ip.ttl == {0, 1}");
         ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_INPUT, 30,
@@ -4926,6 +4924,28 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
                           ds_cstr(&match), ds_cstr(&actions));
         }
 
+        /* ICMP time exceeded */
+        for (int i = 0; i < op->lrp_networks.n_ipv4_addrs; i++) {
+            ds_clear(&match);
+            ds_clear(&actions);
+
+            ds_put_format(&match,
+                          "inport == %s && ip4 && "
+                          "ip.ttl == {0, 1} && !ip.later_frag", op->json_key);
+            ds_put_format(&actions,
+                          "icmp4 {"
+                          "eth.dst <-> eth.src; "
+                          "icmp4.type = 11; /* Time exceeded */ "
+                          "icmp4.code = 0; /* TTL exceeded in transit */ "
+                          "ip4.dst = ip4.src; "
+                          "ip4.src = %s; "
+                          "ip.ttl = 255; "
+                          "next; };",
+                          op->lrp_networks.ipv4_addrs[i].addr_s);
+            ovn_lflow_add(lflows, op->od, S_ROUTER_IN_IP_INPUT, 40,
+                          ds_cstr(&match), ds_cstr(&actions));
+        }
+
         /* ARP reply.  These flows reply to ARP requests for the router's own
          * IP address. */
         for (int i = 0; i < op->lrp_networks.n_ipv4_addrs; i++) {
diff --git a/tests/ovn.at b/tests/ovn.at
index 155150e02..b586afb4e 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -10267,3 +10267,80 @@  $PYTHON "$top_srcdir/utilities/ovs-pcap.in" hv1/vif2-tx.pcap > 2.packets
 AT_CHECK([cat 2.packets], [0], [])
 
 AT_CLEANUP
+
+AT_SETUP([ovn -- TTL exceeded])
+AT_KEYWORDS([ttl-exceeded])
+AT_SKIP_IF([test $HAVE_PYTHON = no])
+ovn_start
+
+# test_ip_packet INPORT HV ETH_SRC ETH_DST IPV4_SRC IPV4_DST IPV4_ROUTER IP_CHKSUM EXP_IP_CHKSUM EXP_ICMP_CHKSUM
+#
+# Causes a packet to be received on INPORT of the hypervisor HV. The packet is an IPv4 packet with
+# ETH_SRC, ETH_DST, IPV4_SRC, IPV4_DST, IP_CHKSUM as specified and TTL set to 1.
+# EXP_IP_CHKSUM and EXP_ICMP_CHKSUM are the ip and icmp checksums of the icmp time exceeded frame
+# generated by OVN logical router
+#
+# INPORT is a lport number, e.g. 11 for vif11.
+# HV is a hypervisor number
+# ETH_SRC and ETH_DST are each 12 hex digits.
+# IPV4_SRC, IPV4_DST and IPV4_ROUTER are each 8 hex digits.
+# IP_CHKSUM, EXP_IP_CHSUM and EXP_ICMP_CHKSUM are each 4 hex digits
+test_ip_packet() {
+    local inport=$1 hv=$2 eth_src=$3 eth_dst=$4 ipv4_src=$5 ipv4_dst=$6 ip_router=$7 ip_chksum=$8
+    local exp_ip_chksum=$9 exp_icmp_chksum=${10}
+    shift 10
+
+    local ip_ttl=01
+    local packet=${eth_dst}${eth_src}08004500001400004000${ip_ttl}01${ip_chksum}${ipv4_src}${ipv4_dst}
+
+    local reply_icmp_ttl=fe
+    local icmp_type_code_response=0b00
+    local icmp_data=00000000
+    local reply_icmp_payload=${icmp_type_code_response}${exp_icmp_chksum}${icmp_data}
+    local reply=${eth_src}${eth_dst}08004500001c00004000${reply_icmp_ttl}01${exp_ip_chksum}${ip_router}${ipv4_src}${reply_icmp_payload}
+    echo $reply >> vif$inport.expected
+
+    as hv$hv ovs-appctl netdev-dummy/receive vif$inport $packet
+}
+
+ip_to_hex() {
+    printf "%02x%02x%02x%02x" "$@"
+}
+
+for i in 1 2; do
+    net_add n$i
+    ovn-nbctl ls-add sw$i
+
+    sim_add hv$i
+    as hv$i
+    ovs-vsctl add-br br-phys
+    ovn_attach n$i br-phys 192.168.$i.1
+
+    ovn-nbctl lsp-add sw$i sw$i-p${i}0 -- \
+        lsp-set-addresses sw$i-p${i}0 "00:00:00:00:00:0$i 192.168.$i.1"
+
+    ovs-vsctl -- add-port br-int vif$i -- \
+        set interface vif$i \
+        external-ids:iface-id=sw$i-p${i}0 \
+            options:tx_pcap=hv$i/vif$i-tx.pcap \
+            options:rxq_pcap=hv$i/vif$i-rx.pcap \
+            ofport-request=$i
+done
+
+ovn-nbctl lr-add lr0
+for i in 1 2; do
+    ovn-nbctl lrp-add lr0 lrp$i 00:00:00:00:ff:0$i 192.168.$i.254/24
+    ovn-nbctl -- lsp-add sw$i lrp$i-attachment \
+              -- set Logical_Switch_Port lrp$i-attachment type=router \
+                options:router-port=lrp$i addresses='"00:00:00:00:ff:'0$i'"'
+done
+
+OVN_POPULATE_ARP
+# allow some time for ovn-northd and ovn-controller to catch up.
+ovn-nbctl --wait=hv sync
+
+test_ip_packet 1 1 000000000001 00000000ff01 $(ip_to_hex 192 168 1 1) $(ip_to_hex 192 168 2 1) $(ip_to_hex 192 168 1 254) 0000 7dae f4ff
+OVN_CHECK_PACKETS([hv1/vif1-tx.pcap], [vif1.expected])
+
+OVN_CLEANUP([hv1], [hv2])
+AT_CLEANUP