Use magic ETH_ADDR_LEN instead of 6 for Ethernet address length.
authorWang Sheng-Hui <shhuiw@gmail.com>
Wed, 22 Oct 2014 06:58:43 +0000 (14:58 +0800)
committerBen Pfaff <blp@nicira.com>
Wed, 22 Oct 2014 15:46:52 +0000 (08:46 -0700)
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 <shhuiw@gmail.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
17 files changed:
lib/bfd.h
lib/cfm.c
lib/cfm.h
lib/flow.h
lib/match.c
lib/match.h
lib/netdev-provider.h
lib/netdev-windows.c
lib/netdev.h
lib/ofp-parse.c
lib/ofp-parse.h
lib/packets.h
ofproto/bond.c
ofproto/bond.h
ofproto/ofproto-dpif-ipfix.c
tests/test-classifier.c
vswitchd/bridge.c

index 039b4dd..d803bf9 100644 (file)
--- a/lib/bfd.h
+++ b/lib/bfd.h
@@ -21,6 +21,8 @@
 #include <stdbool.h>
 #include <inttypes.h>
 
+#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 *);
index e3ae271..bc8be71 100644 (file)
--- 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
 };
 
index a5d4cdf..b3a2d45 100644 (file)
--- 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 *);
index 09988f6..14bc414 100644 (file)
@@ -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. */
index 0eb11f0..1a28396 100644 (file)
@@ -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);
index ce9fb28..af08fc0 100644 (file)
@@ -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 *);
index af9ea3c..7862c2d 100644 (file)
@@ -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
index f9f96ec..75380e4 100644 (file)
@@ -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;
 }
index fc4180a..79b21a0 100644 (file)
@@ -21,6 +21,7 @@
 #include <stddef.h>
 #include <stdint.h>
 #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 *);
 
index eed5a08..729139f 100644 (file)
@@ -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);
index 4636dff..789febf 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #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 */
index 26c6ff1..fc7e602 100644 (file)
@@ -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]);
 }
index dbbc5e7..b487bf4 100644 (file)
@@ -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);
index c783eed..c7b6308 100644 (file)
@@ -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 {
index 848c650..9dff0ef 100644 (file)
@@ -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 */
 });
index 0dfa910..1726171 100644 (file)
@@ -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 };
index 872820b..5f6000e 100644 (file)
@@ -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)) {