From 0c1625e834bd48f9f6f49cdea475dcd4dfb46b0a Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Wed, 12 Feb 2014 10:13:02 +0900 Subject: [PATCH] packets: Always set ethertype in push_mpls() There are two different MPLS ethertypes, 0x8847 and 0x8848 and a push MPLS action applied to an MPLS packet may cause the ethertype to change from one to the other. To ensure that this happens update the ethertype in push_mpls() regardless of if the packet is already MPLS or not. Test based on a similar test by Joe Stringer. Cc: Joe Stringer Signed-off-by: Simon Horman Signed-off-by: Ben Pfaff --- lib/packets.c | 5 +++-- tests/ofproto-dpif.at | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/packets.c b/lib/packets.c index 6c5e973b7..7238f42e8 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -329,9 +329,10 @@ push_mpls(struct ofpbuf *packet, ovs_be16 ethtype, ovs_be32 lse) return; } + set_ethertype(packet, ethtype); + if (!is_mpls(packet)) { - /* Set ethtype and MPLS label stack entry. */ - set_ethertype(packet, ethtype); + /* Set MPLS label stack entry. */ packet->l2_5 = packet->l3; } diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index bc7a7c174..06c4046ab 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -1122,6 +1122,7 @@ AT_CAPTURE_FILE([ofctl_monitor.log]) AT_DATA([flows.txt], [dnl dl_src=40:44:44:44:00:00 actions=push_mpls:0x8847,controller dl_src=40:44:44:44:00:01,mpls actions=push_mpls:0x8847,controller +dl_src=40:44:44:44:00:02,mpls actions=push_mpls:0x8848,controller ]) AT_CHECK([ovs-ofctl --protocols=OpenFlow12 add-flows br0 flows.txt]) @@ -1188,6 +1189,40 @@ mpls,metadata=0,in_port=0,vlan_tci=0x0000,dl_src=40:44:44:44:00:01,dl_dst=50:54: 00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ]) +dnl In this test, we push an MPLS tag to an MPLS packet. The LSE should be +dnl copied exactly, except for the BOS bit. The ethertype should be updated +dnl to the MPLS ethertype of the MPLS push action which differs to that +dnl of the input packet. +AT_CHECK([ovs-ofctl --protocols=OpenFlow12 monitor br0 65534 -m -P nxm --detach --pidfile 2> ofctl_monitor.log]) + +for i in 1 2 3; do + ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=40:44:44:44:00:02,dst=50:54:00:00:00:07),eth_type(0x8847),mpls(label=10,tc=0,ttl=64,bos=1)' +done +OVS_WAIT_UNTIL([ovs-appctl -t ovs-ofctl exit]) + +AT_CHECK([cat ofctl_monitor.log | ofctl_strip], [0], [dnl +OFPT_PACKET_IN (OF1.2): total_len=64 in_port=1 (via action) data_len=64 (unbuffered) +mplsm,metadata=0,in_port=0,vlan_tci=0x0000,dl_src=40:44:44:44:00:02,dl_dst=50:54:00:00:00:07,mpls_label=10,mpls_tc=0,mpls_ttl=64,mpls_bos=0,mpls_lse1=41280 +00000000 50 54 00 00 00 07 40 44-44 44 00 02 88 48 00 00 +00000010 a0 40 00 00 a1 40 00 00-00 00 00 00 00 00 00 00 +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 +dnl +OFPT_PACKET_IN (OF1.2): total_len=64 in_port=1 (via action) data_len=64 (unbuffered) +mplsm,metadata=0,in_port=0,vlan_tci=0x0000,dl_src=40:44:44:44:00:02,dl_dst=50:54:00:00:00:07,mpls_label=10,mpls_tc=0,mpls_ttl=64,mpls_bos=0,mpls_lse1=41280 +00000000 50 54 00 00 00 07 40 44-44 44 00 02 88 48 00 00 +00000010 a0 40 00 00 a1 40 00 00-00 00 00 00 00 00 00 00 +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 +dnl +OFPT_PACKET_IN (OF1.2): total_len=64 in_port=1 (via action) data_len=64 (unbuffered) +mplsm,metadata=0,in_port=0,vlan_tci=0x0000,dl_src=40:44:44:44:00:02,dl_dst=50:54:00:00:00:07,mpls_label=10,mpls_tc=0,mpls_ttl=64,mpls_bos=0,mpls_lse1=41280 +00000000 50 54 00 00 00 07 40 44-44 44 00 02 88 48 00 00 +00000010 a0 40 00 00 a1 40 00 00-00 00 00 00 00 00 00 00 +00000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 +00000030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 +]) + OVS_VSWITCHD_STOP AT_CLEANUP -- 2.43.0