From: Wang Sheng-Hui Date: Wed, 22 Oct 2014 06:58:43 +0000 (+0800) Subject: Use magic ETH_ADDR_LEN instead of 6 for Ethernet address length. X-Git-Tag: v2.4.0~1145 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=3bd0fd39ebeaca5f87284704e7606d225d0e1bbb Use magic ETH_ADDR_LEN instead of 6 for Ethernet address length. ETH_ADDR_LEN is defined in lib/packets.h, valued 6. Use this macro instead of magic number 6 to represent the length of eth mac address. Signed-off-by: Wang Sheng-Hui Signed-off-by: Ben Pfaff --- diff --git a/lib/bfd.h b/lib/bfd.h index 039b4dd96..d803bf9ae 100644 --- a/lib/bfd.h +++ b/lib/bfd.h @@ -21,6 +21,8 @@ #include #include +#include "packets.h" + struct bfd; struct dpif_flow_stats; struct flow; @@ -34,7 +36,7 @@ void bfd_run(struct bfd *); bool bfd_should_send_packet(const struct bfd *); void bfd_put_packet(struct bfd *bfd, struct ofpbuf *packet, - uint8_t eth_src[6]); + uint8_t eth_src[ETH_ADDR_LEN]); bool bfd_should_process_flow(const struct bfd *, const struct flow *, struct flow_wildcards *); diff --git a/lib/cfm.c b/lib/cfm.c index e3ae271e3..bc8be7114 100644 --- a/lib/cfm.c +++ b/lib/cfm.c @@ -43,8 +43,9 @@ VLOG_DEFINE_THIS_MODULE(cfm); #define CFM_MAX_RMPS 256 /* Ethernet destination address of CCM packets. */ -static const uint8_t eth_addr_ccm[6] = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x30 }; -static const uint8_t eth_addr_ccm_x[6] = { +static const uint8_t eth_addr_ccm[ETH_ADDR_LEN] = { + 0x01, 0x80, 0xC2, 0x00, 0x00, 0x30 }; +static const uint8_t eth_addr_ccm_x[ETH_ADDR_LEN] = { 0x01, 0x23, 0x20, 0x00, 0x00, 0x30 }; diff --git a/lib/cfm.h b/lib/cfm.h index a5d4cdf62..b3a2d45ff 100644 --- a/lib/cfm.h +++ b/lib/cfm.h @@ -20,6 +20,7 @@ #include "hmap.h" #include "openvswitch/types.h" +#include "packets.h" struct flow; struct ofpbuf; @@ -92,7 +93,7 @@ struct cfm *cfm_ref(const struct cfm *); void cfm_unref(struct cfm *); void cfm_run(struct cfm *); bool cfm_should_send_ccm(struct cfm *); -void cfm_compose_ccm(struct cfm *, struct ofpbuf *packet, uint8_t eth_src[6]); +void cfm_compose_ccm(struct cfm *, struct ofpbuf *packet, uint8_t eth_src[ETH_ADDR_LEN]); void cfm_wait(struct cfm *); bool cfm_configure(struct cfm *, const struct cfm_settings *); void cfm_set_netdev(struct cfm *, const struct netdev *); diff --git a/lib/flow.h b/lib/flow.h index 09988f6cc..14bc41435 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -104,8 +104,8 @@ struct flow { union flow_in_port in_port; /* Input port.*/ /* L2, Order the same as in the Ethernet header! */ - uint8_t dl_dst[6]; /* Ethernet destination address. */ - uint8_t dl_src[6]; /* Ethernet source address. */ + uint8_t dl_dst[ETH_ADDR_LEN]; /* Ethernet destination address. */ + uint8_t dl_src[ETH_ADDR_LEN]; /* Ethernet source address. */ ovs_be16 dl_type; /* Ethernet frame type. */ ovs_be16 vlan_tci; /* If 802.1Q, TCI | VLAN_CFI; otherwise 0. */ ovs_be32 mpls_lse[FLOW_MAX_MPLS_LABELS]; /* MPLS label stack entry. */ @@ -120,8 +120,8 @@ struct flow { uint8_t nw_tos; /* IP ToS (including DSCP and ECN). */ uint8_t nw_ttl; /* IP TTL/Hop Limit. */ uint8_t nw_proto; /* IP protocol or low 8 bits of ARP opcode. */ - uint8_t arp_sha[6]; /* ARP/ND source hardware address. */ - uint8_t arp_tha[6]; /* ARP/ND target hardware address. */ + uint8_t arp_sha[ETH_ADDR_LEN]; /* ARP/ND source hardware address. */ + uint8_t arp_tha[ETH_ADDR_LEN]; /* ARP/ND target hardware address. */ struct in6_addr nd_target; /* IPv6 neighbor discovery (ND) target. */ ovs_be16 tcp_flags; /* TCP flags. With L3 to avoid matching L4. */ ovs_be16 pad; /* Padding. */ diff --git a/lib/match.c b/lib/match.c index 0eb11f08a..1a28396e9 100644 --- a/lib/match.c +++ b/lib/match.c @@ -736,8 +736,9 @@ match_init_hidden_fields(struct match *m) } static void -format_eth_masked(struct ds *s, const char *name, const uint8_t eth[6], - const uint8_t mask[6]) +format_eth_masked(struct ds *s, const char *name, + const uint8_t eth[ETH_ADDR_LEN], + const uint8_t mask[ETH_ADDR_LEN]) { if (!eth_addr_is_zero(mask)) { ds_put_format(s, "%s=", name); diff --git a/lib/match.h b/lib/match.h index ce9fb28b7..af08fc0a2 100644 --- a/lib/match.h +++ b/lib/match.h @@ -18,6 +18,7 @@ #define MATCH_H 1 #include "flow.h" +#include "packets.h" struct ds; @@ -73,12 +74,12 @@ void match_set_pkt_mark(struct match *, uint32_t pkt_mark); void match_set_pkt_mark_masked(struct match *, uint32_t pkt_mark, uint32_t mask); void match_set_skb_priority(struct match *, uint32_t skb_priority); void match_set_dl_type(struct match *, ovs_be16); -void match_set_dl_src(struct match *, const uint8_t[6]); -void match_set_dl_src_masked(struct match *, const uint8_t dl_src[6], - const uint8_t mask[6]); -void match_set_dl_dst(struct match *, const uint8_t[6]); -void match_set_dl_dst_masked(struct match *, const uint8_t dl_dst[6], - const uint8_t mask[6]); +void match_set_dl_src(struct match *, const uint8_t[ETH_ADDR_LEN]); +void match_set_dl_src_masked(struct match *, const uint8_t dl_src[ETH_ADDR_LEN], + const uint8_t mask[ETH_ADDR_LEN]); +void match_set_dl_dst(struct match *, const uint8_t[ETH_ADDR_LEN]); +void match_set_dl_dst_masked(struct match *, const uint8_t dl_dst[ETH_ADDR_LEN], + const uint8_t mask[ETH_ADDR_LEN]); void match_set_dl_tci(struct match *, ovs_be16 tci); void match_set_dl_tci_masked(struct match *, ovs_be16 tci, ovs_be16 mask); void match_set_any_vid(struct match *); @@ -114,14 +115,14 @@ void match_set_nw_frag(struct match *, uint8_t nw_frag); void match_set_nw_frag_masked(struct match *, uint8_t nw_frag, uint8_t mask); void match_set_icmp_type(struct match *, uint8_t); void match_set_icmp_code(struct match *, uint8_t); -void match_set_arp_sha(struct match *, const uint8_t[6]); +void match_set_arp_sha(struct match *, const uint8_t[ETH_ADDR_LEN]); void match_set_arp_sha_masked(struct match *, - const uint8_t arp_sha[6], - const uint8_t mask[6]); -void match_set_arp_tha(struct match *, const uint8_t[6]); + const uint8_t arp_sha[ETH_ADDR_LEN], + const uint8_t mask[ETH_ADDR_LEN]); +void match_set_arp_tha(struct match *, const uint8_t[ETH_ADDR_LEN]); void match_set_arp_tha_masked(struct match *, - const uint8_t arp_tha[6], - const uint8_t mask[6]); + const uint8_t arp_tha[ETH_ADDR_LEN], + const uint8_t mask[ETH_ADDR_LEN]); void match_set_ipv6_src(struct match *, const struct in6_addr *); void match_set_ipv6_src_masked(struct match *, const struct in6_addr *, const struct in6_addr *); diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h index af9ea3c23..7862c2d5d 100644 --- a/lib/netdev-provider.h +++ b/lib/netdev-provider.h @@ -23,6 +23,7 @@ #include "netdev.h" #include "list.h" #include "ovs-numa.h" +#include "packets.h" #include "seq.h" #include "shash.h" #include "smap.h" @@ -309,13 +310,15 @@ struct netdev_class { void (*send_wait)(struct netdev *netdev, int qid); /* Sets 'netdev''s Ethernet address to 'mac' */ - int (*set_etheraddr)(struct netdev *netdev, const uint8_t mac[6]); + int (*set_etheraddr)(struct netdev *netdev, + const uint8_t mac[ETH_ADDR_LEN]); /* Retrieves 'netdev''s Ethernet address into 'mac'. * * This address will be advertised as 'netdev''s MAC address through the * OpenFlow protocol, among other uses. */ - int (*get_etheraddr)(const struct netdev *netdev, uint8_t mac[6]); + int (*get_etheraddr)(const struct netdev *netdev, + uint8_t mac[ETH_ADDR_LEN]); /* Retrieves 'netdev''s MTU into '*mtup'. * @@ -653,7 +656,7 @@ struct netdev_class { * This function may be set to null if it would always return EOPNOTSUPP * anyhow. */ int (*arp_lookup)(const struct netdev *netdev, ovs_be32 ip, - uint8_t mac[6]); + uint8_t mac[ETH_ADDR_LEN]); /* Retrieves the current set of flags on 'netdev' into '*old_flags'. Then, * turns off the flags that are set to 1 in 'off' and turns on the flags diff --git a/lib/netdev-windows.c b/lib/netdev-windows.c index f9f96ecf1..75380e4ad 100644 --- a/lib/netdev-windows.c +++ b/lib/netdev-windows.c @@ -24,6 +24,7 @@ #include "fatal-signal.h" #include "netdev-provider.h" #include "ofpbuf.h" +#include "packets.h" #include "poll-loop.h" #include "shash.h" #include "svec.h" @@ -300,7 +301,8 @@ netdev_windows_dealloc(struct netdev *netdev_) } static int -netdev_windows_get_etheraddr(const struct netdev *netdev_, uint8_t mac[6]) +netdev_windows_get_etheraddr(const struct netdev *netdev_, + uint8_t mac[ETH_ADDR_LEN]) { struct netdev_windows *netdev = netdev_windows_cast(netdev_); @@ -330,7 +332,8 @@ netdev_windows_get_mtu(const struct netdev *netdev_, int *mtup) /* This functionality is not really required by the datapath. * But vswitchd bringup expects this to be implemented. */ static int -netdev_windows_set_etheraddr(const struct netdev *netdev_, uint8_t mac[6]) +netdev_windows_set_etheraddr(const struct netdev *netdev_, + uint8_t mac[ETH_ADDR_LEN]) { return 0; } diff --git a/lib/netdev.h b/lib/netdev.h index fc4180a74..79b21a0d5 100644 --- a/lib/netdev.h +++ b/lib/netdev.h @@ -21,6 +21,7 @@ #include #include #include "openvswitch/types.h" +#include "packets.h" #ifdef __cplusplus extern "C" { @@ -181,8 +182,8 @@ int netdev_send(struct netdev *, int qid, struct dpif_packet **, int cnt, void netdev_send_wait(struct netdev *, int qid); /* Hardware address. */ -int netdev_set_etheraddr(struct netdev *, const uint8_t mac[6]); -int netdev_get_etheraddr(const struct netdev *, uint8_t mac[6]); +int netdev_set_etheraddr(struct netdev *, const uint8_t mac[ETH_ADDR_LEN]); +int netdev_get_etheraddr(const struct netdev *, uint8_t mac[ETH_ADDR_LEN]); /* PHY interface. */ bool netdev_get_carrier(const struct netdev *); @@ -246,7 +247,8 @@ int netdev_add_router(struct netdev *, struct in_addr router); int netdev_get_next_hop(const struct netdev *, const struct in_addr *host, struct in_addr *next_hop, char **); int netdev_get_status(const struct netdev *, struct smap *); -int netdev_arp_lookup(const struct netdev *, ovs_be32 ip, uint8_t mac[6]); +int netdev_arp_lookup(const struct netdev *, ovs_be32 ip, + uint8_t mac[ETH_ADDR_LEN]); struct netdev *netdev_find_dev_by_in4(const struct in_addr *); diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index eed5a0816..729139fcf 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -145,7 +145,7 @@ str_to_be64(const char *str, ovs_be64 *valuep) * Returns NULL if successful, otherwise a malloc()'d string describing the * error. The caller is responsible for freeing the returned string. */ char * WARN_UNUSED_RESULT -str_to_mac(const char *str, uint8_t mac[6]) +str_to_mac(const char *str, uint8_t mac[ETH_ADDR_LEN]) { if (!ovs_scan(str, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))) { return xasprintf("invalid mac address %s", str); diff --git a/lib/ofp-parse.h b/lib/ofp-parse.h index 4636dffd3..789febf28 100644 --- a/lib/ofp-parse.h +++ b/lib/ofp-parse.h @@ -24,6 +24,7 @@ #include #include "compiler.h" #include "openvswitch/types.h" +#include "packets.h" struct flow; struct ofpbuf; @@ -90,7 +91,7 @@ char *str_to_u16(const char *str, const char *name, uint16_t *valuep) char *str_to_u32(const char *str, uint32_t *valuep) WARN_UNUSED_RESULT; char *str_to_u64(const char *str, uint64_t *valuep) WARN_UNUSED_RESULT; char *str_to_be64(const char *str, ovs_be64 *valuep) WARN_UNUSED_RESULT; -char *str_to_mac(const char *str, uint8_t mac[6]) WARN_UNUSED_RESULT; +char *str_to_mac(const char *str, uint8_t mac[ETH_ADDR_LEN]) WARN_UNUSED_RESULT; char *str_to_ip(const char *str, ovs_be32 *ip) WARN_UNUSED_RESULT; #endif /* ofp-parse.h */ diff --git a/lib/packets.h b/lib/packets.h index 26c6ff1b4..fc7e60216 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -83,23 +83,23 @@ static const uint8_t eth_addr_lacp[ETH_ADDR_LEN] OVS_UNUSED static const uint8_t eth_addr_bfd[ETH_ADDR_LEN] OVS_UNUSED = { 0x00, 0x23, 0x20, 0x00, 0x00, 0x01 }; -static inline bool eth_addr_is_broadcast(const uint8_t ea[6]) +static inline bool eth_addr_is_broadcast(const uint8_t ea[ETH_ADDR_LEN]) { return (ea[0] & ea[1] & ea[2] & ea[3] & ea[4] & ea[5]) == 0xff; } -static inline bool eth_addr_is_multicast(const uint8_t ea[6]) +static inline bool eth_addr_is_multicast(const uint8_t ea[ETH_ADDR_LEN]) { return ea[0] & 1; } -static inline bool eth_addr_is_local(const uint8_t ea[6]) +static inline bool eth_addr_is_local(const uint8_t ea[ETH_ADDR_LEN]) { /* Local if it is either a locally administered address or a Nicira random * address. */ return ea[0] & 2 || (ea[0] == 0x00 && ea[1] == 0x23 && ea[2] == 0x20 && ea[3] & 0x80); } -static inline bool eth_addr_is_zero(const uint8_t ea[6]) +static inline bool eth_addr_is_zero(const uint8_t ea[ETH_ADDR_LEN]) { return !(ea[0] | ea[1] | ea[2] | ea[3] | ea[4] | ea[5]); } diff --git a/ofproto/bond.c b/ofproto/bond.c index dbbc5e71e..b487bf417 100644 --- a/ofproto/bond.c +++ b/ofproto/bond.c @@ -465,13 +465,13 @@ bond_reconfigure(struct bond *bond, const struct bond_settings *s) } static struct bond_slave * -bond_find_slave_by_mac(const struct bond *bond, const uint8_t mac[6]) +bond_find_slave_by_mac(const struct bond *bond, const uint8_t mac[ETH_ADDR_LEN]) { struct bond_slave *slave; /* Find the last active slave */ HMAP_FOR_EACH(slave, hmap_node, &bond->slaves) { - uint8_t slave_mac[6]; + uint8_t slave_mac[ETH_ADDR_LEN]; if (netdev_get_etheraddr(slave->netdev, slave_mac)) { continue; @@ -488,7 +488,7 @@ bond_find_slave_by_mac(const struct bond *bond, const uint8_t mac[6]) static void bond_active_slave_changed(struct bond *bond) { - uint8_t mac[6]; + uint8_t mac[ETH_ADDR_LEN]; netdev_get_etheraddr(bond->active_slave->netdev, mac); memcpy(bond->active_slave_mac, mac, sizeof bond->active_slave_mac); diff --git a/ofproto/bond.h b/ofproto/bond.h index c783eed6f..c7b630870 100644 --- a/ofproto/bond.h +++ b/ofproto/bond.h @@ -54,7 +54,8 @@ struct bond_settings { bool lacp_fallback_ab_cfg; /* Fallback to active-backup on LACP failure. */ - uint8_t active_slave_mac[6];/* The MAC address of the interface + uint8_t active_slave_mac[ETH_ADDR_LEN]; + /* The MAC address of the interface that was active during the last ovs run. */ }; @@ -83,8 +84,8 @@ bool bond_should_send_learning_packets(struct bond *); struct ofpbuf *bond_compose_learning_packet(struct bond *, const uint8_t eth_src[ETH_ADDR_LEN], uint16_t vlan, void **port_aux); -bool bond_get_changed_active_slave(const char *name, uint8_t mac[6], - bool force); +bool bond_get_changed_active_slave(const char *name, uint8_t mac[ETH_ADDR_LEN], + bool force); /* Packet processing. */ enum bond_verdict { diff --git a/ofproto/ofproto-dpif-ipfix.c b/ofproto/ofproto-dpif-ipfix.c index 848c65072..9dff0eff4 100644 --- a/ofproto/ofproto-dpif-ipfix.c +++ b/ofproto/ofproto-dpif-ipfix.c @@ -228,8 +228,8 @@ OVS_PACKED( struct ipfix_data_record_flow_key_common { ovs_be32 observation_point_id; /* OBSERVATION_POINT_ID */ uint8_t flow_direction; /* FLOW_DIRECTION */ - uint8_t source_mac_address[6]; /* SOURCE_MAC_ADDRESS */ - uint8_t destination_mac_address[6]; /* DESTINATION_MAC_ADDRESS */ + uint8_t source_mac_address[ETH_ADDR_LEN]; /* SOURCE_MAC_ADDRESS */ + uint8_t destination_mac_address[ETH_ADDR_LEN]; /* DESTINATION_MAC_ADDRESS */ ovs_be16 ethernet_type; /* ETHERNET_TYPE */ uint8_t ethernet_header_length; /* ETHERNET_HEADER_LENGTH */ }); diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 0dfa910a3..17261713c 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -311,9 +311,11 @@ static ovs_be16 dl_type_values[] static ovs_be16 tp_src_values[] = { CONSTANT_HTONS(49362), CONSTANT_HTONS(80) }; static ovs_be16 tp_dst_values[] = { CONSTANT_HTONS(6667), CONSTANT_HTONS(22) }; -static uint8_t dl_src_values[][6] = { { 0x00, 0x02, 0xe3, 0x0f, 0x80, 0xa4 }, +static uint8_t dl_src_values[][ETH_ADDR_LEN] = { + { 0x00, 0x02, 0xe3, 0x0f, 0x80, 0xa4 }, { 0x5e, 0x33, 0x7f, 0x5f, 0x1e, 0x99 } }; -static uint8_t dl_dst_values[][6] = { { 0x4a, 0x27, 0x71, 0xae, 0x64, 0xc1 }, +static uint8_t dl_dst_values[][ETH_ADDR_LEN] = { + { 0x4a, 0x27, 0x71, 0xae, 0x64, 0xc1 }, { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; static uint8_t nw_proto_values[] = { IPPROTO_TCP, IPPROTO_ICMP }; static uint8_t nw_dscp_values[] = { 48, 0 }; diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 872820bf9..5f6000e04 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -2510,7 +2510,7 @@ port_refresh_rstp_status(struct port *port) static void port_refresh_bond_status(struct port *port, bool force_update) { - uint8_t mac[6]; + uint8_t mac[ETH_ADDR_LEN]; /* Return if port is not a bond */ if (list_is_singleton(&port->ifaces)) {