From: Ben Pfaff Date: Fri, 28 Mar 2008 21:12:15 +0000 (-0700) Subject: Get rid of mac.h, migrating its users to packets.h. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d927b51cb493cfd169a3c9dd70531b19a06892b1;p=openvswitch Get rid of mac.h, migrating its users to packets.h. As a consequence, this fixes tests for multicast and local Ethernet addresses, which formerly tested for the high bits but should have tested for the low bits of the first octet. --- diff --git a/controller/controller.c b/controller/controller.c index eae2f0a4..7d2b77aa 100644 --- a/controller/controller.c +++ b/controller/controller.c @@ -48,9 +48,9 @@ #include "flow.h" #include "hash.h" #include "list.h" -#include "mac.h" #include "ofp-print.h" #include "openflow.h" +#include "packets.h" #include "poll-loop.h" #include "queue.h" #include "time.h" @@ -462,7 +462,7 @@ process_switch(struct switch_ *sw, struct ofp_packet_in *opi) flow_extract(&pkt, ntohs(opi->in_port), &flow); /* Learn the source. */ - if (!mac_is_multicast(flow.dl_src)) { + if (!eth_addr_is_multicast(flow.dl_src)) { struct mac_source *src; struct list *bucket; bool found; @@ -471,7 +471,7 @@ process_switch(struct switch_ *sw, struct ofp_packet_in *opi) found = false; LIST_FOR_EACH (src, struct mac_source, hash_list, bucket) { if (src->datapath_id == sw->datapath_id - && mac_equals(src->mac, flow.dl_src)) { + && eth_addr_equals(src->mac, flow.dl_src)) { found = true; break; } @@ -506,24 +506,26 @@ process_switch(struct switch_ *sw, struct ofp_packet_in *opi) if (ntohs(flow.in_port) != src->port) { src->port = ntohs(flow.in_port); - VLOG_DBG("learned that "MAC_FMT" is on datapath %"PRIx64" port %d", - MAC_ARGS(src->mac), ntohll(src->datapath_id), + VLOG_DBG("learned that "ETH_ADDR_FMT" is on datapath %" + PRIx64" port %d", + ETH_ADDR_ARGS(src->mac), ntohll(src->datapath_id), src->port); } } else { - VLOG_DBG("multicast packet source "MAC_FMT, MAC_ARGS(flow.dl_src)); + VLOG_DBG("multicast packet source "ETH_ADDR_FMT, + ETH_ADDR_ARGS(flow.dl_src)); } /* Figure out the destination. */ out_port = OFPP_FLOOD; - if (!mac_is_multicast(flow.dl_dst)) { + if (!eth_addr_is_multicast(flow.dl_dst)) { struct mac_source *dst; struct list *bucket; bucket = mac_table_bucket(sw->datapath_id, flow.dl_dst); LIST_FOR_EACH (dst, struct mac_source, hash_list, bucket) { if (dst->datapath_id == sw->datapath_id - && mac_equals(dst->mac, flow.dl_dst)) { + && eth_addr_equals(dst->mac, flow.dl_dst)) { out_port = dst->port; break; } diff --git a/include/Makefile.am b/include/Makefile.am index 60999183..c9d3bd41 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -10,7 +10,6 @@ noinst_HEADERS = \ hash.h \ ip.h \ list.h \ - mac.h \ netlink.h \ ofp-print.h \ openflow.h \ diff --git a/include/mac.h b/include/mac.h deleted file mode 100644 index 4d0f758c..00000000 --- a/include/mac.h +++ /dev/null @@ -1,73 +0,0 @@ -/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford - * Junior University - * - * We are making the OpenFlow specification and associated documentation - * (Software) available for public use and benefit with the expectation - * that others will use, modify and enhance the Software and contribute - * those enhancements back to the community. However, since we would - * like to make the Software available for broadest use, with as few - * restrictions as possible permission is hereby granted, free of - * charge, to any person obtaining a copy of this Software to deal in - * the Software under the copyrights without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * The name and trademarks of copyright holder(s) may NOT be used in - * advertising or publicity pertaining to the Software or any - * derivatives without specific, written prior permission. - */ -#ifndef MAC_H -#define MAC_H 1 - -#include -#include -#include -#include "packets.h" - -static inline bool mac_is_multicast(const uint8_t mac[ETH_ADDR_LEN]) -{ - return mac[0] & 0x80; -} - -static inline bool mac_is_private(const uint8_t mac[ETH_ADDR_LEN]) -{ - return mac[0] & 0x40; -} - -static inline bool mac_is_broadcast(const uint8_t mac[ETH_ADDR_LEN]) -{ - return (mac[0] & mac[1] & mac[2] & mac[3] & mac[4] & mac[5]) == 0xff; -} - -static inline bool mac_is_zero(const uint8_t mac[ETH_ADDR_LEN]) -{ - return (mac[0] | mac[1] | mac[2] | mac[3] | mac[4] | mac[5]) == 0; -} - -static inline bool mac_equals(const uint8_t a[ETH_ADDR_LEN], - const uint8_t b[ETH_ADDR_LEN]) -{ - return !memcmp(a, b, ETH_ADDR_LEN); -} - -#define MAC_FMT \ - "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8 -#define MAC_ARGS(mac) \ - (mac)[0], (mac)[1], (mac)[2], (mac)[3], (mac)[4], (mac)[5] - - -#endif /* mac.h */ diff --git a/include/packets.h b/include/packets.h index cf2dc279..4b517703 100644 --- a/include/packets.h +++ b/include/packets.h @@ -34,6 +34,7 @@ #define PACKETS_H 1 #include +#include #include "util.h" #define ETH_ADDR_LEN 6 @@ -50,6 +51,15 @@ static inline bool eth_addr_is_local(const uint8_t ea[6]) { return ea[0] & 2; } +static inline bool eth_addr_equals(const uint8_t a[ETH_ADDR_LEN], + const uint8_t b[ETH_ADDR_LEN]) +{ + return !memcmp(a, b, ETH_ADDR_LEN); +} +#define ETH_ADDR_FMT \ + "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8 +#define ETH_ADDR_ARGS(ea) \ + (ea)[0], (ea)[1], (ea)[2], (ea)[3], (ea)[4], (ea)[5] #define ETH_TYPE_IP 0x0800 #define ETH_TYPE_ARP 0x0806 diff --git a/lib/dpif.c b/lib/dpif.c index 7a5577e3..b36df5f4 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -41,11 +41,11 @@ #include #include "buffer.h" -#include "mac.h" #include "netlink.h" #include "ofp-print.h" #include "openflow-netlink.h" #include "openflow.h" +#include "packets.h" #include "util.h" #include "xtoxll.h" diff --git a/lib/flow.c b/lib/flow.c index e3b3685d..937ce947 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -38,7 +38,6 @@ #include "buffer.h" #include "hash.h" #include "ip.h" -#include "mac.h" #include "openflow.h" #include "packets.h" @@ -145,10 +144,10 @@ void flow_print(FILE *stream, const struct flow *flow) { fprintf(stream, - "port%04x:vlan%04x mac"MAC_FMT"->"MAC_FMT" " + "port%04x:vlan%04x mac"ETH_ADDR_FMT"->"ETH_ADDR_FMT" " "proto%04x ip"IP_FMT"->"IP_FMT" port%d->%d", ntohs(flow->in_port), ntohs(flow->dl_vlan), - MAC_ARGS(flow->dl_src), MAC_ARGS(flow->dl_dst), + ETH_ADDR_ARGS(flow->dl_src), ETH_ADDR_ARGS(flow->dl_dst), ntohs(flow->dl_type), IP_ARGS(&flow->nw_src), IP_ARGS(&flow->nw_dst), ntohs(flow->tp_src), ntohs(flow->tp_dst)); diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 7007b20e..a35c2548 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -43,10 +43,10 @@ #include #include "ip.h" -#include "mac.h" #include "compiler.h" #include "util.h" #include "openflow.h" +#include "packets.h" /* Dumps the contents of the Ethernet frame in the 'len' bytes starting at * 'data' to 'stream' using tcpdump. 'total_len' specifies the full length of @@ -257,10 +257,10 @@ void ofp_print_phy_port(FILE *stream, const struct ofp_phy_port *port) } name[j] = '\0'; - fprintf(stream, " %2d(%s): addr:"MAC_FMT", speed:%d, flags:%#x, " + fprintf(stream, " %2d(%s): addr:"ETH_ADDR_FMT", speed:%d, flags:%#x, " "feat:%#x\n", ntohs(port->port_no), name, - MAC_ARGS(port->hw_addr), ntohl(port->speed), ntohl(port->flags), - ntohl(port->features)); + ETH_ADDR_ARGS(port->hw_addr), ntohl(port->speed), + ntohl(port->flags), ntohl(port->features)); } /* Pretty-print the OFPT_DATA_HELLO packet of 'len' bytes at 'oh' to 'stream' @@ -321,8 +321,10 @@ static void ofp_print_match(FILE *f, const struct ofp_match *om) print_wild(f, "inport", w & OFPFW_IN_PORT, "%04x", ntohs(om->in_port)); print_wild(f, ":vlan", w & OFPFW_DL_VLAN, "%04x", ntohs(om->dl_vlan)); - print_wild(f, " mac[", w & OFPFW_DL_SRC, MAC_FMT, MAC_ARGS(om->dl_src)); - print_wild(f, "->", w & OFPFW_DL_DST, MAC_FMT, MAC_ARGS(om->dl_dst)); + print_wild(f, " mac[", w & OFPFW_DL_SRC, + ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src)); + print_wild(f, "->", w & OFPFW_DL_DST, + ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst)); print_wild(f, "] type", w & OFPFW_DL_TYPE, "%04x", ntohs(om->dl_type)); print_wild(f, " ip[", w & OFPFW_NW_SRC, IP_FMT, IP_ARGS(&om->nw_src)); print_wild(f, "->", w & OFPFW_NW_DST, IP_FMT, IP_ARGS(&om->nw_dst));