2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-03 15:55:19 +00:00

ofp-parse: Add support for dl_dst masks in flow match parsing.

This makes it possible to add flows that match on the Ethernet multicast
bit with ovs-ofctl.

CC: Paul Ingram <paul@nicira.com>
CC: Amar Padmanabhan <amar@nicira.com>
This commit is contained in:
Ben Pfaff
2011-06-07 09:22:24 -07:00
parent db7f828182
commit cb8ca532a6
3 changed files with 52 additions and 3 deletions

View File

@@ -83,6 +83,27 @@ str_to_mac(const char *str, uint8_t mac[6])
} }
} }
static void
str_to_eth_dst(const char *str,
uint8_t mac[ETH_ADDR_LEN], uint8_t mask[ETH_ADDR_LEN])
{
if (sscanf(str, ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT,
ETH_ADDR_SCAN_ARGS(mac), ETH_ADDR_SCAN_ARGS(mask))
== ETH_ADDR_SCAN_COUNT * 2) {
if (!flow_wildcards_is_dl_dst_mask_valid(mask)) {
ovs_fatal(0, "%s: invalid Ethernet destination mask (only "
"00:00:00:00:00:00, 01:00:00:00:00:00, "
"fe:ff:ff:ff:ff:ff, and ff:ff:ff:ff:ff:ff are allowed)",
str);
}
} else if (sscanf(str, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))
== ETH_ADDR_SCAN_COUNT) {
memset(mask, 0xff, ETH_ADDR_LEN);
} else {
ovs_fatal(0, "invalid mac address %s", str);
}
}
static void static void
str_to_ip(const char *str_, ovs_be32 *ip, ovs_be32 *maskp) str_to_ip(const char *str_, ovs_be32 *ip, ovs_be32 *maskp)
{ {
@@ -592,7 +613,7 @@ static void
parse_field_value(struct cls_rule *rule, enum field_index index, parse_field_value(struct cls_rule *rule, enum field_index index,
const char *value) const char *value)
{ {
uint8_t mac[ETH_ADDR_LEN]; uint8_t mac[ETH_ADDR_LEN], mac_mask[ETH_ADDR_LEN];
ovs_be64 tun_id, tun_mask; ovs_be64 tun_id, tun_mask;
ovs_be32 ip, mask; ovs_be32 ip, mask;
struct in6_addr ipv6, ipv6_mask; struct in6_addr ipv6, ipv6_mask;
@@ -625,8 +646,8 @@ parse_field_value(struct cls_rule *rule, enum field_index index,
break; break;
case F_DL_DST: case F_DL_DST:
str_to_mac(value, mac); str_to_eth_dst(value, mac, mac_mask);
cls_rule_set_dl_dst(rule, mac); cls_rule_set_dl_dst_masked(rule, mac, mac_mask);
break; break;
case F_DL_TYPE: case F_DL_TYPE:

View File

@@ -62,6 +62,10 @@ actions=note:41.42.43,note:00.01.02.03.04.05.06.07,note
tun_id=0x1234,cookie=0x5678,actions=flood tun_id=0x1234,cookie=0x5678,actions=flood
actions=drop actions=drop
tun_id=0x1234000056780000/0xffff0000ffff0000,actions=drop tun_id=0x1234000056780000/0xffff0000ffff0000,actions=drop
dl_dst=01:00:00:00:00:00/01:00:00:00:00:00,actions=drop
dl_dst=00:00:00:00:00:00/01:00:00:00:00:00,actions=drop
dl_dst=aa:bb:cc:dd:ee:ff/fe:ff:ff:ff:ff:ff,actions=drop
dl_dst=aa:bb:cc:dd:ee:ff/00:00:00:00:00:00,actions=drop
]) ])
AT_CHECK([ovs-ofctl -F nxm parse-flows flows.txt], [0], [stdout]) AT_CHECK([ovs-ofctl -F nxm parse-flows flows.txt], [0], [stdout])
AT_CHECK([[sed 's/ (xid=0x[0-9a-fA-F]*)//' stdout]], [0], [dnl AT_CHECK([[sed 's/ (xid=0x[0-9a-fA-F]*)//' stdout]], [0], [dnl
@@ -86,6 +90,10 @@ NXT_FLOW_MOD: ADD actions=note:41.42.43.00.00.00,note:00.01.02.03.04.05.06.07.00
NXT_FLOW_MOD: ADD tun_id=0x1234 cookie:0x5678 actions=FLOOD NXT_FLOW_MOD: ADD tun_id=0x1234 cookie:0x5678 actions=FLOOD
NXT_FLOW_MOD: ADD actions=drop NXT_FLOW_MOD: ADD actions=drop
NXT_FLOW_MOD: ADD tun_id=0x1234000056780000/0xffff0000ffff0000 actions=drop NXT_FLOW_MOD: ADD tun_id=0x1234000056780000/0xffff0000ffff0000 actions=drop
NXT_FLOW_MOD: ADD dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=drop
NXT_FLOW_MOD: ADD dl_dst=00:00:00:00:00:00/01:00:00:00:00:00 actions=drop
NXT_FLOW_MOD: ADD dl_dst=aa:bb:cc:dd:ee:ff/fe:ff:ff:ff:ff:ff actions=drop
NXT_FLOW_MOD: ADD actions=drop
]) ])
AT_CLEANUP AT_CLEANUP

View File

@@ -290,6 +290,26 @@ Matches an Ethernet source (or destination) address specified as 6
pairs of hexadecimal digits delimited by colons pairs of hexadecimal digits delimited by colons
(e.g. \fB00:0A:E4:25:6B:B0\fR). (e.g. \fB00:0A:E4:25:6B:B0\fR).
. .
.IP \fBdl_dst=\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fB/\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fB:\fIxx\fR
Matches an Ethernet destination address specified as 6 pairs of
hexadecimal digits delimited by colons (e.g. \fB00:0A:E4:25:6B:B0\fR),
with a wildcard mask following the slash. Only
the following masks are allowed:
.RS
.IP \fB01:00:00:00:00:00\fR
Match only the multicast bit. Thus,
\fBdl_dst=01:00:00:00:00:00/01:00:00:00:00:00\fR matches all multicast
(including broadcast) Ethernet packets, and
\fBdl_dst=00:00:00:00:00:00/01:00:00:00:00:00\fR matches all unicast
Ethernet packets.
.IP \fBfe:ff:ff:ff:ff:ff\fR
Match all bits except the multicast bit. This is probably not useful.
.IP \fBff:ff:ff:ff:ff:ff\fR
Exact match (equivalent to omitting the mask).
.IP \fB00:00:00:00:00:00\fR
Wildcard all bits (equivalent to \fBdl_dst=*\fR.)
.RE
.
.IP \fBdl_type=\fIethertype\fR .IP \fBdl_type=\fIethertype\fR
Matches Ethernet protocol type \fIethertype\fR, which is specified as an Matches Ethernet protocol type \fIethertype\fR, which is specified as an
integer between 0 and 65535, inclusive, either in decimal or as a integer between 0 and 65535, inclusive, either in decimal or as a