From: Ben Pfaff Date: Tue, 7 Jun 2011 16:22:24 +0000 (-0700) Subject: ofp-parse: Add support for dl_dst masks in flow match parsing. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb8ca532a6636d20c9d7e4a5323489cad9c3eeb7;p=openvswitch 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 CC: Amar Padmanabhan --- diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index 5e488a6e..3f3ce62e 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -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 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, 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_be32 ip, mask; struct in6_addr ipv6, ipv6_mask; @@ -625,8 +646,8 @@ parse_field_value(struct cls_rule *rule, enum field_index index, break; case F_DL_DST: - str_to_mac(value, mac); - cls_rule_set_dl_dst(rule, mac); + str_to_eth_dst(value, mac, mac_mask); + cls_rule_set_dl_dst_masked(rule, mac, mac_mask); break; case F_DL_TYPE: diff --git a/tests/ovs-ofctl.at b/tests/ovs-ofctl.at index 6d636c1d..a7d3b84f 100644 --- a/tests/ovs-ofctl.at +++ b/tests/ovs-ofctl.at @@ -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 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([[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 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 diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in index 7150bfce..2e866dc5 100644 --- a/utilities/ovs-ofctl.8.in +++ b/utilities/ovs-ofctl.8.in @@ -290,6 +290,26 @@ Matches an Ethernet source (or destination) address specified as 6 pairs of hexadecimal digits delimited by colons (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 Matches Ethernet protocol type \fIethertype\fR, which is specified as an integer between 0 and 65535, inclusive, either in decimal or as a