2009-06-15 15:11:30 -07:00
|
|
|
/*
|
2012-05-21 21:51:03 -07:00
|
|
|
* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
|
2009-06-15 15:11:30 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
#include <config.h>
|
|
|
|
#include "flow.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-11-22 10:10:14 -08:00
|
|
|
#include "classifier.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "openflow/openflow.h"
|
|
|
|
#include "timeval.h"
|
|
|
|
#include "ofpbuf.h"
|
|
|
|
#include "ofp-print.h"
|
2010-11-22 10:10:14 -08:00
|
|
|
#include "ofp-util.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "pcap.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "vlog.h"
|
|
|
|
|
|
|
|
#undef NDEBUG
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
int
|
2010-02-11 10:59:47 -08:00
|
|
|
main(int argc OVS_UNUSED, char *argv[])
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
2012-05-21 21:51:03 -07:00
|
|
|
struct ofp10_match expected_match;
|
2009-07-08 13:19:16 -07:00
|
|
|
FILE *flows, *pcap;
|
|
|
|
int retval;
|
|
|
|
int n = 0, errors = 0;
|
|
|
|
|
|
|
|
set_program_name(argv[0]);
|
|
|
|
|
|
|
|
flows = stdin;
|
|
|
|
pcap = fdopen(3, "rb");
|
|
|
|
if (!pcap) {
|
|
|
|
ovs_fatal(errno, "failed to open fd 3 for reading");
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = pcap_read_header(pcap);
|
|
|
|
if (retval) {
|
|
|
|
ovs_fatal(retval > 0 ? retval : 0, "reading pcap header failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fread(&expected_match, sizeof expected_match, 1, flows)) {
|
|
|
|
struct ofpbuf *packet;
|
2012-05-21 21:51:03 -07:00
|
|
|
struct ofp10_match extracted_match;
|
2012-08-07 15:28:18 -07:00
|
|
|
struct match match;
|
2010-09-03 11:30:02 -07:00
|
|
|
struct flow flow;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
n++;
|
|
|
|
|
|
|
|
retval = pcap_read(pcap, &packet);
|
|
|
|
if (retval == EOF) {
|
|
|
|
ovs_fatal(0, "unexpected end of file reading pcap file");
|
|
|
|
} else if (retval) {
|
|
|
|
ovs_fatal(retval, "error reading pcap file");
|
|
|
|
}
|
|
|
|
|
2012-11-13 19:19:36 +02:00
|
|
|
flow_extract(packet, 0, 0, NULL, 1, &flow);
|
2012-08-07 15:28:18 -07:00
|
|
|
match_init_exact(&match, &flow);
|
|
|
|
ofputil_match_to_ofp10_match(&match, &extracted_match);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
if (memcmp(&expected_match, &extracted_match, sizeof expected_match)) {
|
2012-05-21 21:51:03 -07:00
|
|
|
char *exp_s = ofp10_match_to_string(&expected_match, 2);
|
|
|
|
char *got_s = ofp10_match_to_string(&extracted_match, 2);
|
2009-07-08 13:19:16 -07:00
|
|
|
errors++;
|
|
|
|
printf("mismatch on packet #%d (1-based).\n", n);
|
|
|
|
printf("Packet:\n");
|
2011-12-22 17:47:15 -08:00
|
|
|
ofp_print_packet(stdout, packet->data, packet->size);
|
datapath: Fix handling of 802.1Q and SNAP headers.
The kernel and user datapaths have code that assumes that 802.1Q headers
are used only inside Ethernet II frames, not inside SNAP-encapsulated
frames. But the kernel and user flow_extract() implementations would
interpret 802.1Q headers inside SNAP headers as being valid VLANs. This
would cause packet corruption if any VLAN-related actions were to be taken,
so change the two flow_extract() implementations only to accept 802.1Q as
an Ethernet II frame type, not as a SNAP-encoded frame type.
802.1Q-2005 says that this is correct anyhow:
Where the ISS instance used to transmit and receive tagged frames is
provided by a media access control method that can support Ethernet
Type encoding directly (e.g., is an IEEE 802.3 or IEEE 802.11 MAC) or
is media access method independent (e.g., 6.6), the TPID is Ethernet
Type encoded, i.e., is two octets in length and comprises solely the
assigned Ethernet Type value.
Where the ISS instance is provided by a media access method that
cannot directly support Ethernet Type encoding (e.g., is an IEEE
802.5 or FDDI MAC), the TPID is encoded according to the rule for
a Subnetwork Access Protocol (Clause 10 of IEEE Std 802) that
encapsulates Ethernet frames over LLC, and comprises the SNAP
header (AA-AA-03) followed by the SNAP PID (00-00-00) followed by
the two octets of the assigned Ethernet Type value.
All of the media that OVS handles supports Ethernet Type fields, so to me
that means that we don't have to handle 802.1Q-inside-SNAP.
On the other hand, we *do* have to handle SNAP-inside-802.1Q, because this
is actually allowed by the standards. So this commit also adds that
support.
I verified that, with this change, both SNAP and Ethernet packets are
properly recognized both with and without 802.1Q encapsulation.
I was a bit surprised to find out that Linux does not accept
SNAP-encapsulated IP frames on Ethernet.
Here's a summary of how frames are handled before and after this commit:
Common cases
------------
Ethernet
+------------+
1. |dst|src|TYPE|
+------------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
2. |dst|src| len| |aa|aa|03| |000000|TYPE|
+------------+ +--------+ +-----------+
Ethernet 802.1Q
+------------+ +---------+
3. |dst|src|8100| |VLAN|TYPE|
+------------+ +---------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
4. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |000000|TYPE|
+------------+ +---------+ +--------+ +-----------+
Unusual cases
-------------
Ethernet LLC SNAP 802.1Q
+------------+ +--------+ +-----------+ +---------+
5. |dst|src| len| |aa|aa|03| |000000|8100| |VLAN|TYPE|
+------------+ +--------+ +-----------+ +---------+
Ethernet LLC
+------------+ +--------+
6. |dst|src| len| |xx|xx|xx|
+------------+ +--------+
Ethernet LLC SNAP
+------------+ +--------+ +-----------+
7. |dst|src| len| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +--------+ +-----------+
Ethernet 802.1Q LLC
+------------+ +---------+ +--------+
8. |dst|src|8100| |VLAN| LEN| |xx|xx|xx|
+------------+ +---------+ +--------+
Ethernet 802.1Q LLC SNAP
+------------+ +---------+ +--------+ +-----------+
9. |dst|src|8100| |VLAN| LEN| |aa|aa|03| |xxxxxx|xxxx|
+------------+ +---------+ +--------+ +-----------+
Behavior
--------
--------------- --------------- -------------------------------------
Before After
this commit this commit
dl_type dl_vlan dl_type dl_vlan Notes
------- ------- ------- ------- -------------------------------------
1. TYPE ffff TYPE ffff no change
2. TYPE ffff TYPE ffff no change
3. TYPE VLAN TYPE VLAN no change
4. LEN VLAN TYPE VLAN proposal fixes behavior
5. TYPE VLAN 8100 ffff 802.1Q says this is invalid framing
6. 05ff ffff 05ff ffff no change
7. 05ff ffff 05ff ffff no change
8. LEN VLAN 05ff VLAN proposal fixes behavior
9. LEN VLAN 05ff VLAN proposal fixes behavior
Signed-off-by: Ben Pfaff <blp@nicira.com>
2010-08-10 11:35:46 -07:00
|
|
|
ovs_hex_dump(stdout, packet->data, packet->size, 0, true);
|
2012-08-07 15:28:18 -07:00
|
|
|
match_print(&match);
|
2009-07-08 13:19:16 -07:00
|
|
|
printf("Expected flow:\n%s\n", exp_s);
|
|
|
|
printf("Actually extracted flow:\n%s\n", got_s);
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
ovs_hex_dump(stdout, &expected_match, sizeof expected_match, 0, false);
|
|
|
|
ovs_hex_dump(stdout, &extracted_match, sizeof extracted_match, 0, false);
|
2009-07-08 13:19:16 -07:00
|
|
|
printf("\n");
|
|
|
|
free(exp_s);
|
|
|
|
free(got_s);
|
|
|
|
}
|
|
|
|
|
|
|
|
ofpbuf_delete(packet);
|
|
|
|
}
|
|
|
|
printf("checked %d packets, %d errors\n", n, errors);
|
|
|
|
return errors != 0;
|
|
|
|
}
|
|
|
|
|