Skip to content

Commit

Permalink
Use magic ETH_ADDR_LEN instead of 6 for Ethernet address length.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Wang Sheng-Hui authored and blp committed Oct 22, 2014
1 parent d1da766 commit 3bd0fd3
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 47 deletions.
4 changes: 3 additions & 1 deletion lib/bfd.h
Expand Up @@ -21,6 +21,8 @@
#include <stdbool.h>
#include <inttypes.h>

#include "packets.h"

struct bfd;
struct dpif_flow_stats;
struct flow;
Expand All @@ -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 *);
Expand Down
5 changes: 3 additions & 2 deletions lib/cfm.c
Expand Up @@ -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
};

Expand Down
3 changes: 2 additions & 1 deletion lib/cfm.h
Expand Up @@ -20,6 +20,7 @@

#include "hmap.h"
#include "openvswitch/types.h"
#include "packets.h"

struct flow;
struct ofpbuf;
Expand Down Expand Up @@ -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 *);
Expand Down
8 changes: 4 additions & 4 deletions lib/flow.h
Expand Up @@ -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. */
Expand All @@ -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. */
Expand Down
5 changes: 3 additions & 2 deletions lib/match.c
Expand Up @@ -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);
Expand Down
25 changes: 13 additions & 12 deletions lib/match.h
Expand Up @@ -18,6 +18,7 @@
#define MATCH_H 1

#include "flow.h"
#include "packets.h"

struct ds;

Expand Down Expand Up @@ -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 *);
Expand Down Expand Up @@ -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 *);
Expand Down
9 changes: 6 additions & 3 deletions lib/netdev-provider.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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'.
*
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/netdev-windows.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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_);

Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions lib/netdev.h
Expand Up @@ -21,6 +21,7 @@
#include <stddef.h>
#include <stdint.h>
#include "openvswitch/types.h"
#include "packets.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -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 *);
Expand Down Expand Up @@ -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 *);

Expand Down
2 changes: 1 addition & 1 deletion lib/ofp-parse.c
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/ofp-parse.h
Expand Up @@ -24,6 +24,7 @@
#include <stdio.h>
#include "compiler.h"
#include "openvswitch/types.h"
#include "packets.h"

struct flow;
struct ofpbuf;
Expand Down Expand Up @@ -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 */
8 changes: 4 additions & 4 deletions lib/packets.h
Expand Up @@ -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]);
}
Expand Down
6 changes: 3 additions & 3 deletions ofproto/bond.c
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions ofproto/bond.h
Expand Up @@ -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. */
};
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions ofproto/ofproto-dpif-ipfix.c
Expand Up @@ -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 */
});
Expand Down
6 changes: 4 additions & 2 deletions tests/test-classifier.c
Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion vswitchd/bridge.c
Expand Up @@ -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)) {
Expand Down

0 comments on commit 3bd0fd3

Please sign in to comment.