types['ovs_be32'] = {"size": 4, "alignment": 4}
types['ovs_be64'] = {"size": 8, "alignment": 8}
types['ovs_32aligned_be64'] = {"size": 8, "alignment": 4}
+types['struct eth_addr'] = {"size": 6, "alignment": 1}
token = None
line = ""
#include "OvsDpInterfaceExt.h"\
#endif\
+# Use OVS's own struct eth_addr instead of a 6-byte char array.
+s,<linux/types\.h>,"openvswitch/types.h",
+s,#.*<linux/if_ether\.h>,,
+s/__u8[ \t]*\([a-zA-Z0-9_]*\)[ \t]*\[[ \t]*ETH_ALEN[ \t]*\]/struct eth_addr \1/
# Transform most Linux-specific __u<N> types into C99 uint<N>_t types,
# and most Linux-specific __be<N> into Open vSwitch ovs_be<N>,
# and use the appropriate userspace header.
-s,<linux/types\.h>,"openvswitch/types.h",
s/__u32/uint32_t/g
s/__u16/uint16_t/g
s/__u8/uint8_t/g
# boundary.
s/__u64/ovs_32aligned_u64/g
s/__be64/ovs_32aligned_be64/g
-
-# Use OVS's own ETH_ADDR_LEN instead of Linux-specific ETH_ALEN.
-s,<linux/if_ether\.h>,"packets.h",
-s/ETH_ALEN/ETH_ADDR_LEN/
/* Description of a physical port */
struct ofp10_phy_port {
ovs_be16 port_no;
- uint8_t hw_addr[OFP_ETH_ALEN];
+ struct eth_addr hw_addr;
char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
ovs_be32 config; /* Bitmap of OFPPC_* and OFPPC10_* flags. */
/* Modify behavior of the physical port */
struct ofp10_port_mod {
ovs_be16 port_no;
- uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
- configurable. This is used to
- sanity-check the request, so it must
- be the same as returned in an
- ofp10_phy_port struct. */
+ struct eth_addr hw_addr; /* The hardware address is not configurable. This
+ is used to sanity-check the request, so it must
+ be the same as returned in an ofp10_phy_port
+ struct. */
ovs_be32 config; /* Bitmap of OFPPC_* flags. */
ovs_be32 mask; /* Bitmap of OFPPC_* flags to be changed. */
struct ofp10_match {
ovs_be32 wildcards; /* Wildcard fields. */
ovs_be16 in_port; /* Input switch port. */
- uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
- uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
+ struct eth_addr dl_src; /* Ethernet source address. */
+ struct eth_addr dl_dst; /* Ethernet destination address. */
ovs_be16 dl_vlan; /* Input VLAN. */
uint8_t dl_vlan_pcp; /* Input VLAN priority. */
uint8_t pad1[1]; /* Align to 64-bits. */
struct ofp11_port {
ovs_be32 port_no;
uint8_t pad[4];
- uint8_t hw_addr[OFP_ETH_ALEN];
+ struct eth_addr hw_addr;
uint8_t pad2[2]; /* Align to 64 bits. */
char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
struct ofp11_port_mod {
ovs_be32 port_no;
uint8_t pad[4];
- uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
- configurable. This is used to
- sanity-check the request, so it must
- be the same as returned in an
- ofp11_port struct. */
+ struct eth_addr hw_addr; /* The hardware address is not configurable. This
+ is used to sanity-check the request, so it must
+ be the same as returned in an ofp11_port
+ struct. */
uint8_t pad2[2]; /* Pad to 64 bits. */
ovs_be32 config; /* Bitmap of OFPPC_* flags. */
ovs_be32 mask; /* Bitmap of OFPPC_* flags to be changed. */
struct ofp11_match_header omh;
ovs_be32 in_port; /* Input switch port. */
ovs_be32 wildcards; /* Wildcard fields. */
- uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
- uint8_t dl_src_mask[OFP_ETH_ALEN]; /* Ethernet source address mask. */
- uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
- uint8_t dl_dst_mask[OFP_ETH_ALEN]; /* Ethernet destination address mask. */
+ struct eth_addr dl_src; /* Ethernet source address. */
+ struct eth_addr dl_src_mask; /* Ethernet source address mask. */
+ struct eth_addr dl_dst; /* Ethernet destination address. */
+ struct eth_addr dl_dst_mask; /* Ethernet destination address mask. */
ovs_be16 dl_vlan; /* Input VLAN id. */
uint8_t dl_vlan_pcp; /* Input VLAN priority. */
uint8_t pad1[1]; /* Align to 32-bits */
ovs_be32 port_no;
ovs_be16 length;
uint8_t pad[2];
- uint8_t hw_addr[OFP_ETH_ALEN];
+ struct eth_addr hw_addr;
uint8_t pad2[2]; /* Align to 64 bits. */
char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
struct ofp14_port_mod {
ovs_be32 port_no;
uint8_t pad[4];
- uint8_t hw_addr[OFP_ETH_ALEN];
+ struct eth_addr hw_addr;
uint8_t pad2[2];
ovs_be32 config; /* Bitmap of OFPPC_* flags. */
ovs_be32 mask; /* Bitmap of OFPPC_* flags to be changed. */
#define OFP_OLD_PORT 6633
#define OFP_PORT 6653
-#define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
-
#define OFP_DEFAULT_MISS_SEND_LEN 128
/* Values below this cutoff are 802.3 packets and the two bytes
#define ODP_PORT_C(X) ((OVS_FORCE odp_port_t) (X))
#define OFP11_PORT_C(X) ((OVS_FORCE ofp11_port_t) (X))
+/* Using this stuct instead of a bare array makes an ethernet address field
+ * assignable. The size of the array is also part of the type, so it is easier
+ * to deal with. */
+struct eth_addr {
+ union {
+ uint8_t ea[6];
+ ovs_be16 be16[3];
+ };
+};
+
#endif /* openvswitch/types.h */
uint32_t rmt_disc; /* bfd.RemoteDiscr. */
- uint8_t local_eth_src[ETH_ADDR_LEN]; /* Local eth src address. */
- uint8_t local_eth_dst[ETH_ADDR_LEN]; /* Local eth dst address. */
+ struct eth_addr local_eth_src; /* Local eth src address. */
+ struct eth_addr local_eth_dst; /* Local eth dst address. */
- uint8_t rmt_eth_dst[ETH_ADDR_LEN]; /* Remote eth dst address. */
+ struct eth_addr rmt_eth_dst; /* Remote eth dst address. */
ovs_be32 ip_src; /* IPv4 source address. */
ovs_be32 ip_dst; /* IPv4 destination address. */
bool cpath_down, forwarding_if_rx;
const char *hwaddr, *ip_src, *ip_dst;
struct in_addr in_addr;
- uint8_t ea[ETH_ADDR_LEN];
+ struct eth_addr ea;
if (!cfg || !smap_get_bool(cfg, "enable", false)) {
bfd_unref(bfd);
}
hwaddr = smap_get(cfg, "bfd_local_src_mac");
- if (hwaddr && eth_addr_from_string(hwaddr, ea)) {
- memcpy(bfd->local_eth_src, ea, ETH_ADDR_LEN);
+ if (hwaddr && eth_addr_from_string(hwaddr, &ea)) {
+ bfd->local_eth_src = ea;
} else {
- memset(bfd->local_eth_src, 0, ETH_ADDR_LEN);
+ bfd->local_eth_src = eth_addr_zero;
}
hwaddr = smap_get(cfg, "bfd_local_dst_mac");
- if (hwaddr && eth_addr_from_string(hwaddr, ea)) {
- memcpy(bfd->local_eth_dst, ea, ETH_ADDR_LEN);
+ if (hwaddr && eth_addr_from_string(hwaddr, &ea)) {
+ bfd->local_eth_dst = ea;
} else {
- memset(bfd->local_eth_dst, 0, ETH_ADDR_LEN);
+ bfd->local_eth_dst = eth_addr_zero;
}
hwaddr = smap_get(cfg, "bfd_remote_dst_mac");
- if (hwaddr && eth_addr_from_string(hwaddr, ea)) {
- memcpy(bfd->rmt_eth_dst, ea, ETH_ADDR_LEN);
+ if (hwaddr && eth_addr_from_string(hwaddr, &ea)) {
+ bfd->rmt_eth_dst = ea;
} else {
- memset(bfd->rmt_eth_dst, 0, ETH_ADDR_LEN);
+ bfd->rmt_eth_dst = eth_addr_zero;
}
ip_src = smap_get(cfg, "bfd_src_ip");
void
bfd_put_packet(struct bfd *bfd, struct dp_packet *p,
- uint8_t eth_src[ETH_ADDR_LEN]) OVS_EXCLUDED(mutex)
+ const struct eth_addr eth_src) OVS_EXCLUDED(mutex)
{
long long int min_tx, min_rx;
struct udp_header *udp;
dp_packet_reserve(p, 2); /* Properly align after the ethernet header. */
eth = dp_packet_put_uninit(p, sizeof *eth);
- memcpy(eth->eth_src,
- eth_addr_is_zero(bfd->local_eth_src) ? eth_src
- : bfd->local_eth_src,
- ETH_ADDR_LEN);
- memcpy(eth->eth_dst,
- eth_addr_is_zero(bfd->local_eth_dst) ? eth_addr_bfd
- : bfd->local_eth_dst,
- ETH_ADDR_LEN);
+ eth->eth_src = eth_addr_is_zero(bfd->local_eth_src)
+ ? eth_src : bfd->local_eth_src;
+ eth->eth_dst = eth_addr_is_zero(bfd->local_eth_dst)
+ ? eth_addr_bfd : bfd->local_eth_dst;
eth->eth_type = htons(ETH_TYPE_IP);
ip = dp_packet_put_zeros(p, sizeof *ip);
if (!eth_addr_is_zero(bfd->rmt_eth_dst)) {
memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
- if (memcmp(bfd->rmt_eth_dst, flow->dl_dst, ETH_ADDR_LEN)) {
+ if (!eth_addr_equals(bfd->rmt_eth_dst, flow->dl_dst)) {
return false;
}
}
bool bfd_should_send_packet(const struct bfd *);
void bfd_put_packet(struct bfd *bfd, struct dp_packet *packet,
- uint8_t eth_src[ETH_ADDR_LEN]);
+ const struct eth_addr eth_src);
bool bfd_should_process_flow(const struct bfd *, const struct flow *,
struct flow_wildcards *);
#define CFM_MAX_RMPS 256
/* Ethernet destination address of CCM packets. */
-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
-};
+static const struct eth_addr eth_addr_ccm = {
+ { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x30 } } };
+static const struct eth_addr eth_addr_ccm_x = {
+ { { 0x01, 0x23, 0x20, 0x00, 0x00, 0x30 } } };
#define ETH_TYPE_CFM 0x8902
}
}
-static const uint8_t *
+static struct eth_addr
cfm_ccm_addr(struct cfm *cfm)
{
bool extended;
* should be sent whenever cfm_should_send_ccm() indicates. */
void
cfm_compose_ccm(struct cfm *cfm, struct dp_packet *packet,
- const uint8_t eth_src[ETH_ADDR_LEN]) OVS_EXCLUDED(mutex)
+ const struct eth_addr eth_src) OVS_EXCLUDED(mutex)
{
uint16_t ccm_vlan;
struct ccm *ccm;
void cfm_run(struct cfm *);
bool cfm_should_send_ccm(struct cfm *);
void cfm_compose_ccm(struct cfm *, struct dp_packet *,
- const uint8_t eth_src[ETH_ADDR_LEN]);
+ const struct eth_addr eth_src);
long long int cfm_wait(struct cfm *);
bool cfm_configure(struct cfm *, const struct cfm_settings *);
void cfm_set_netdev(struct cfm *, const struct netdev *);
/* Returns the new checksum for a packet in which the checksum field previously
* contained 'old_csum' and in which a field that contained the 6 bytes at
- * 'old_bytes' was changed to contain the 6 bytes at 'new_bytes'. */
+ * 'old_mac' was changed to contain the 6 bytes at 'new_mac'. */
ovs_be16
-recalc_csum48(ovs_be16 old_csum, const void *old_bytes,
- const void *new_bytes)
+recalc_csum48(ovs_be16 old_csum, const struct eth_addr old_mac,
+ const struct eth_addr new_mac)
{
ovs_be16 new_csum = old_csum;
- const uint16_t *p16_old = old_bytes,
- *p16_new = new_bytes;
- int i;
- for (i = 0; i < 3; ++i) {
- new_csum = recalc_csum16(new_csum, get_unaligned_be16(&p16_old[i]),
- get_unaligned_be16(&p16_new[i]));
+ for (int i = 0; i < 3; ++i) {
+ new_csum = recalc_csum16(new_csum, old_mac.be16[i], new_mac.be16[i]);
}
return new_csum;
ovs_be16 csum_finish(uint32_t partial);
ovs_be16 recalc_csum16(ovs_be16 old_csum, ovs_be16 old_u16, ovs_be16 new_u16);
ovs_be16 recalc_csum32(ovs_be16 old_csum, ovs_be32 old_u32, ovs_be32 new_u32);
-ovs_be16 recalc_csum48(ovs_be16 old_csum, const void *old_bytes,
- const void *new_bytes);
+ovs_be16 recalc_csum48(ovs_be16 old_csum, const struct eth_addr old_mac,
+ const struct eth_addr new_mac);
ovs_be16 recalc_csum128(ovs_be16 old_csum, ovs_16aligned_be32 old_u32[4],
const ovs_be32 new_u32[4]);
static inline void
parse_icmpv6(const void **datap, size_t *sizep, const struct icmp6_hdr *icmp,
const struct in6_addr **nd_target,
- uint8_t arp_buf[2][ETH_ADDR_LEN])
+ struct eth_addr arp_buf[2])
{
if (icmp->icmp6_code == 0 &&
(icmp->icmp6_type == ND_NEIGHBOR_SOLICIT ||
while (*sizep >= 8) {
/* The minimum size of an option is 8 bytes, which also is
* the size of Ethernet link-layer options. */
- const struct nd_opt_hdr *nd_opt = *datap;
- int opt_len = nd_opt->nd_opt_len * 8;
+ const struct ovs_nd_opt *nd_opt = *datap;
+ int opt_len = nd_opt->nd_opt_len * ND_OPT_LEN;
if (!opt_len || opt_len > *sizep) {
return;
* provided. It is considered an error if the same link
* layer option is specified twice. */
if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LINKADDR
- && opt_len == 8) {
+ && opt_len == 8) {
if (OVS_LIKELY(eth_addr_is_zero(arp_buf[0]))) {
- memcpy(arp_buf[0], nd_opt + 1, ETH_ADDR_LEN);
+ arp_buf[0] = nd_opt->nd_opt_mac;
} else {
goto invalid;
}
} else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LINKADDR
- && opt_len == 8) {
+ && opt_len == 8) {
if (OVS_LIKELY(eth_addr_is_zero(arp_buf[1]))) {
- memcpy(arp_buf[1], nd_opt + 1, ETH_ADDR_LEN);
+ arp_buf[1] = nd_opt->nd_opt_mac;
} else {
goto invalid;
}
invalid:
*nd_target = NULL;
- memset(arp_buf[0], 0, ETH_ADDR_LEN);
- memset(arp_buf[1], 0, ETH_ADDR_LEN);
- return;
+ arp_buf[0] = eth_addr_zero;
+ arp_buf[1] = eth_addr_zero;
}
/* Initializes 'flow' members from 'packet' and 'md'
} else {
if (dl_type == htons(ETH_TYPE_ARP) ||
dl_type == htons(ETH_TYPE_RARP)) {
- uint8_t arp_buf[2][ETH_ADDR_LEN];
+ struct eth_addr arp_buf[2];
const struct arp_eth_header *arp = (const struct arp_eth_header *)
data_try_pull(&data, &size, ARP_ETH_HEADER_LEN);
/* Must be adjacent. */
ASSERT_SEQUENTIAL(arp_sha, arp_tha);
- memcpy(arp_buf[0], arp->ar_sha, ETH_ADDR_LEN);
- memcpy(arp_buf[1], arp->ar_tha, ETH_ADDR_LEN);
+ arp_buf[0] = arp->ar_sha;
+ arp_buf[1] = arp->ar_tha;
miniflow_push_macs(mf, arp_sha, arp_buf);
miniflow_pad_to_64(mf, tcp_flags);
}
if (OVS_LIKELY(size >= TCP_HEADER_LEN)) {
const struct tcp_header *tcp = data;
- miniflow_push_be32(mf, arp_tha[2], 0);
+ miniflow_push_be32(mf, arp_tha.ea[2], 0);
miniflow_push_be32(mf, tcp_flags,
TCP_FLAGS_BE32(tcp->tcp_ctl));
miniflow_push_be16(mf, tp_src, tcp->tcp_src);
} else if (OVS_LIKELY(nw_proto == IPPROTO_ICMPV6)) {
if (OVS_LIKELY(size >= sizeof(struct icmp6_hdr))) {
const struct in6_addr *nd_target = NULL;
- uint8_t arp_buf[2][ETH_ADDR_LEN];
+ struct eth_addr arp_buf[2] = { };
const struct icmp6_hdr *icmp = data_pull(&data, &size,
sizeof *icmp);
- memset(arp_buf, 0, sizeof arp_buf);
parse_icmpv6(&data, &size, icmp, &nd_target, arp_buf);
if (nd_target) {
miniflow_push_words(mf, nd_target, nd_target,
- sizeof *nd_target / 8);
+ sizeof *nd_target / sizeof(uint64_t));
}
miniflow_push_macs(mf, arp_sha, arp_buf);
miniflow_pad_to_64(mf, tcp_flags);
ovs_be16 eth_type;
ovs_be16 vlan_tci;
ovs_be16 tp_port;
- uint8_t eth_addr[ETH_ADDR_LEN];
+ struct eth_addr eth_addr;
uint8_t ip_proto;
} fields;
int i;
memset(&fields, 0, sizeof fields);
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- fields.eth_addr[i] = flow->dl_src[i] ^ flow->dl_dst[i];
+ for (i = 0; i < ARRAY_SIZE(fields.eth_addr.be16); i++) {
+ fields.eth_addr.be16[i] = flow->dl_src.be16[i] ^ flow->dl_dst.be16[i];
}
fields.vlan_tci = flow->vlan_tci & htons(VLAN_VID_MASK);
fields.eth_type = flow->dl_type;
/* Initialize to all zeros. */
memset(flow, 0, sizeof *flow);
- eth_addr_random(flow->dl_src);
- eth_addr_random(flow->dl_dst);
+ eth_addr_random(&flow->dl_src);
+ eth_addr_random(&flow->dl_dst);
flow->vlan_tci = (OVS_FORCE ovs_be16) (random_uint16() & VLAN_VID_MASK);
switch (fields) {
case NX_HASH_FIELDS_ETH_SRC:
- return jhash_bytes(flow->dl_src, sizeof flow->dl_src, basis);
+ return jhash_bytes(&flow->dl_src, sizeof flow->dl_src, basis);
case NX_HASH_FIELDS_SYMMETRIC_L4:
return flow_hash_symmetric_l4(flow, basis);
(icmp->icmp6_type == ND_NEIGHBOR_SOLICIT ||
icmp->icmp6_type == ND_NEIGHBOR_ADVERT)) {
struct in6_addr *nd_target;
- struct nd_opt_hdr *nd_opt;
+ struct ovs_nd_opt *nd_opt;
l4_len += sizeof *nd_target;
nd_target = dp_packet_put_zeros(p, sizeof *nd_target);
nd_opt = dp_packet_put_zeros(p, 8);
nd_opt->nd_opt_len = 1;
nd_opt->nd_opt_type = ND_OPT_SOURCE_LINKADDR;
- memcpy(nd_opt + 1, flow->arp_sha, ETH_ADDR_LEN);
+ nd_opt->nd_opt_mac = flow->arp_sha;
}
if (!eth_addr_is_zero(flow->arp_tha)) {
l4_len += 8;
nd_opt = dp_packet_put_zeros(p, 8);
nd_opt->nd_opt_len = 1;
nd_opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
- memcpy(nd_opt + 1, flow->arp_tha, ETH_ADDR_LEN);
+ nd_opt->nd_opt_mac = flow->arp_tha;
}
}
icmp->icmp6_cksum = (OVS_FORCE uint16_t)
flow->nw_proto == ARP_OP_REPLY) {
put_16aligned_be32(&arp->ar_spa, flow->nw_src);
put_16aligned_be32(&arp->ar_tpa, flow->nw_dst);
- memcpy(arp->ar_sha, flow->arp_sha, ETH_ADDR_LEN);
- memcpy(arp->ar_tha, flow->arp_tha, ETH_ADDR_LEN);
+ arp->ar_sha = flow->arp_sha;
+ arp->ar_tha = flow->arp_tha;
}
}
uint8_t pad1[6]; /* Pad to 64 bits. */
/* L2, Order the same as in the Ethernet header! (64-bit aligned) */
- uint8_t dl_dst[ETH_ADDR_LEN]; /* Ethernet destination address. */
- uint8_t dl_src[ETH_ADDR_LEN]; /* Ethernet source address. */
+ struct eth_addr dl_dst; /* Ethernet destination address. */
+ struct eth_addr dl_src; /* 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[ROUND_UP(FLOW_MAX_MPLS_LABELS, 2)]; /* MPLS label stack
uint8_t nw_ttl; /* IP TTL/Hop Limit. */
uint8_t nw_proto; /* IP protocol or low 8 bits of ARP opcode. */
struct in6_addr nd_target; /* IPv6 neighbor discovery (ND) target. */
- 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 eth_addr arp_sha; /* ARP/ND source hardware address. */
+ struct eth_addr arp_tha; /* ARP/ND target hardware address. */
ovs_be16 tcp_flags; /* TCP flags. With L3 to avoid matching L4. */
ovs_be16 pad2; /* Pad to 64 bits. */
OVS_PACKED(
struct lacp_info {
ovs_be16 sys_priority; /* System priority. */
- uint8_t sys_id[ETH_ADDR_LEN]; /* System ID. */
+ struct eth_addr sys_id; /* System ID. */
ovs_be16 key; /* Operational key. */
ovs_be16 port_priority; /* Port priority. */
ovs_be16 port_id; /* Port ID. */
struct lacp {
struct ovs_list node; /* Node in all_lacps list. */
char *name; /* Name of this lacp object. */
- uint8_t sys_id[ETH_ADDR_LEN]; /* System ID. */
+ struct eth_addr sys_id; /* System ID. */
uint16_t sys_priority; /* System Priority. */
bool active; /* Active or Passive. */
if (!eth_addr_equals(lacp->sys_id, s->id)
|| lacp->sys_priority != s->priority) {
- memcpy(lacp->sys_id, s->id, ETH_ADDR_LEN);
+ lacp->sys_id = s->id;
lacp->sys_priority = s->priority;
lacp->update = true;
}
actor->port_priority = htons(slave->port_priority);
actor->port_id = htons(slave->port_id);
actor->sys_priority = htons(lacp->sys_priority);
- memcpy(&actor->sys_id, lacp->sys_id, ETH_ADDR_LEN);
+ actor->sys_id = lacp->sys_id;
}
/* Given 'slave', populates 'priority' with data representing its LACP link
if (slave) {
ret = true;
slave_get_actor(slave, &actor);
- memcpy(&stats->dot3adAggPortActorSystemID,
- actor.sys_id,
- ETH_ADDR_LEN);
- memcpy(&stats->dot3adAggPortPartnerOperSystemID,
- slave->partner.sys_id,
- ETH_ADDR_LEN);
+ stats->dot3adAggPortActorSystemID = actor.sys_id;
+ stats->dot3adAggPortPartnerOperSystemID = slave->partner.sys_id;
stats->dot3adAggPortAttachedAggID = (lacp->key_slave->key ?
lacp->key_slave->key :
lacp->key_slave->port_id);
struct lacp_settings {
char *name; /* Name (for debugging). */
- uint8_t id[ETH_ADDR_LEN]; /* System ID. Must be nonzero. */
+ struct eth_addr id; /* System ID. Must be nonzero. */
uint16_t priority; /* System priority. */
bool active; /* Active or passive mode? */
bool fast; /* Fast or slow probe interval. */
struct lacp_slave_stats {
/* id */
- uint8_t dot3adAggPortActorSystemID[ETH_ADDR_LEN];
- uint8_t dot3adAggPortPartnerOperSystemID[ETH_ADDR_LEN];
+ struct eth_addr dot3adAggPortActorSystemID;
+ struct eth_addr dot3adAggPortPartnerOperSystemID;
uint32_t dot3adAggPortAttachedAggID;
/* state */
uint8_t dot3adAggPortActorAdminState;
#include "list.h"
struct lldp_aa_element_system_id {
- uint8_t system_mac[6];
+ struct eth_addr system_mac;
uint16_t conn_type;
uint16_t rsvd;
uint8_t rsvd2[2];
#ifndef _LLDP_TLV_H
#define _LLDP_TLV_H
-#define LLDP_MULTICAST_ADDR { \
- 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e \
+#define LLDP_MULTICAST_ADDR { \
+ { { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e } } \
}
#define LLDP_TLV_END 0
{
struct lldpd_chassis *chassis;
struct lldpd_port *port;
- const char lldpaddr[] = LLDP_MULTICAST_ADDR;
+ const struct eth_addr lldpaddr = LLDP_MULTICAST_ADDR;
const char dot1[] = LLDP_TLV_ORG_DOT1;
const char dot3[] = LLDP_TLV_ORG_DOT3;
const char med[] = LLDP_TLV_ORG_MED;
VLOG_WARN("too short frame received on %s", hardware->h_ifname);
goto malformed;
}
- if (PEEK_CMP(lldpaddr, ETH_ADDR_LEN) != 0) {
+ if (PEEK_CMP(&lldpaddr, ETH_ADDR_LEN) != 0) {
VLOG_INFO("frame not targeted at LLDP multicast address "
"received on %s", hardware->h_ifname);
goto malformed;
* to 0. */
int h_ifindex; /* Interface index, used by SNMP */
char h_ifname[IFNAMSIZ]; /* Should be unique */
- u_int8_t h_lladdr[ETH_ADDR_LEN];
+ struct eth_addr h_lladdr;
u_int64_t h_tx_cnt;
u_int64_t h_rx_cnt;
{ LLDPD_MODE_LLDP, 1, "LLDP", 'l', lldp_send, lldp_decode, NULL,
LLDP_MULTICAST_ADDR },
{ 0, 0, "any", ' ', NULL, NULL, NULL,
- { 0,0,0,0,0,0 } }
+ { { { 0,0,0,0,0,0 } } } }
};
void lldpd_assign_cfg_to_protocols(struct lldpd *cfg)
continue;
}
if (cfg->g_protocols[i].guess == NULL) {
- if (memcmp(frame, cfg->g_protocols[i].mac, ETH_ADDR_LEN) == 0) {
+ if (memcmp(frame, &cfg->g_protocols[i].mac, ETH_ADDR_LEN) == 0) {
VLOG_DBG("guessed protocol is %s (from MAC address)",
cfg->g_protocols[i].name);
return cfg->g_protocols[i].mode;
int(*guess)(PROTO_GUESS_SIG); /* Can be NULL, use MAC address in this
* case
*/
- u_int8_t mac[ETH_ADDR_LEN]; /* Destination MAC address used by this
- * protocol
- */
+ struct eth_addr mac; /* Destination MAC address used by this protocol */
};
#define SMART_HIDDEN(port) (port->p_hidden_in)
}
static uint32_t
-mac_table_hash(const struct mac_learning *ml, const uint8_t mac[ETH_ADDR_LEN],
+mac_table_hash(const struct mac_learning *ml, const struct eth_addr mac,
uint16_t vlan)
{
return hash_mac(mac, vlan, ml->secret);
static struct mac_entry *
mac_entry_lookup(const struct mac_learning *ml,
- const uint8_t mac[ETH_ADDR_LEN], uint16_t vlan)
+ const struct eth_addr mac, uint16_t vlan)
{
struct mac_entry *e;
* 'vlan' is configured on 'ml' to flood all packets. */
bool
mac_learning_may_learn(const struct mac_learning *ml,
- const uint8_t src_mac[ETH_ADDR_LEN], uint16_t vlan)
+ const struct eth_addr src_mac, uint16_t vlan)
{
return ml && is_learning_vlan(ml, vlan) && !eth_addr_is_multicast(src_mac);
}
* the new entry's port to a nonnull value with mac_entry_set_port(). */
struct mac_entry *
mac_learning_insert(struct mac_learning *ml,
- const uint8_t src_mac[ETH_ADDR_LEN], uint16_t vlan)
+ const struct eth_addr src_mac, uint16_t vlan)
{
struct mac_entry *e;
e = xmalloc(sizeof *e);
hmap_insert(&ml->table, &e->hmap_node, hash);
- memcpy(e->mac, src_mac, ETH_ADDR_LEN);
+ e->mac = src_mac;
e->vlan = vlan;
e->grat_arp_lock = TIME_MIN;
e->mlport = NULL;
* learning entry, if any. */
struct mac_entry *
mac_learning_lookup(const struct mac_learning *ml,
- const uint8_t dst[ETH_ADDR_LEN], uint16_t vlan)
+ const struct eth_addr dst, uint16_t vlan)
{
if (eth_addr_is_multicast(dst)) {
/* No tag because the treatment of multicast destinations never
struct hmap_node hmap_node; /* Node in a mac_learning hmap. */
time_t expires; /* Expiration time. */
time_t grat_arp_lock; /* Gratuitous ARP lock expiration time. */
- uint8_t mac[ETH_ADDR_LEN]; /* Known MAC address. */
+ struct eth_addr mac; /* Known MAC address. */
uint16_t vlan; /* VLAN tag. */
/* The following are marked guarded to prevent users from iterating over or
/* Learning. */
bool mac_learning_may_learn(const struct mac_learning *ml,
- const uint8_t src_mac[ETH_ADDR_LEN],
+ const struct eth_addr src_mac,
uint16_t vlan)
OVS_REQ_RDLOCK(ml->rwlock);
struct mac_entry *mac_learning_insert(struct mac_learning *ml,
- const uint8_t src[ETH_ADDR_LEN],
+ const struct eth_addr src,
uint16_t vlan)
OVS_REQ_WRLOCK(ml->rwlock);
/* Lookup. */
struct mac_entry *mac_learning_lookup(const struct mac_learning *ml,
- const uint8_t dst[ETH_ADDR_LEN],
+ const struct eth_addr dst,
uint16_t vlan)
OVS_REQ_RDLOCK(ml->rwlock);
/* Modifies 'value_src' so that the Ethernet address must match 'value_dst'
* exactly. 'mask_dst' is set to all 1s. */
static void
-set_eth(const uint8_t value_src[ETH_ADDR_LEN],
- uint8_t value_dst[ETH_ADDR_LEN],
- uint8_t mask_dst[ETH_ADDR_LEN])
+set_eth(const struct eth_addr value_src,
+ struct eth_addr *value_dst,
+ struct eth_addr *mask_dst)
{
- memcpy(value_dst, value_src, ETH_ADDR_LEN);
- memset(mask_dst, 0xff, ETH_ADDR_LEN);
+ *value_dst = value_src;
+ *mask_dst = eth_addr_exact;
}
/* Modifies 'value_src' so that the Ethernet address must match 'value_src'
* after each byte is ANDed with the appropriate byte in 'mask_src'.
* 'mask_dst' is set to 'mask_src' */
static void
-set_eth_masked(const uint8_t value_src[ETH_ADDR_LEN],
- const uint8_t mask_src[ETH_ADDR_LEN],
- uint8_t value_dst[ETH_ADDR_LEN],
- uint8_t mask_dst[ETH_ADDR_LEN])
+set_eth_masked(const struct eth_addr value_src,
+ const struct eth_addr mask_src,
+ struct eth_addr *value_dst, struct eth_addr *mask_dst)
{
size_t i;
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- value_dst[i] = value_src[i] & mask_src[i];
- mask_dst[i] = mask_src[i];
+ for (i = 0; i < ARRAY_SIZE(value_dst->be16); i++) {
+ value_dst->be16[i] = value_src.be16[i] & mask_src.be16[i];
}
+ *mask_dst = mask_src;
}
/* Modifies 'rule' so that the source Ethernet address must match 'dl_src'
* exactly. */
void
-match_set_dl_src(struct match *match, const uint8_t dl_src[ETH_ADDR_LEN])
+match_set_dl_src(struct match *match, const struct eth_addr dl_src)
{
- set_eth(dl_src, match->flow.dl_src, match->wc.masks.dl_src);
+ set_eth(dl_src, &match->flow.dl_src, &match->wc.masks.dl_src);
}
/* Modifies 'rule' so that the source Ethernet address must match 'dl_src'
* after each byte is ANDed with the appropriate byte in 'mask'. */
void
match_set_dl_src_masked(struct match *match,
- const uint8_t dl_src[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN])
+ const struct eth_addr dl_src,
+ const struct eth_addr mask)
{
- set_eth_masked(dl_src, mask, match->flow.dl_src, match->wc.masks.dl_src);
+ set_eth_masked(dl_src, mask, &match->flow.dl_src, &match->wc.masks.dl_src);
}
/* Modifies 'match' so that the Ethernet address must match 'dl_dst'
* exactly. */
void
-match_set_dl_dst(struct match *match, const uint8_t dl_dst[ETH_ADDR_LEN])
+match_set_dl_dst(struct match *match, const struct eth_addr dl_dst)
{
- set_eth(dl_dst, match->flow.dl_dst, match->wc.masks.dl_dst);
+ set_eth(dl_dst, &match->flow.dl_dst, &match->wc.masks.dl_dst);
}
/* Modifies 'match' so that the Ethernet address must match 'dl_dst' after each
* accepted by flow_wildcards_is_dl_dst_mask_valid() are allowed. */
void
match_set_dl_dst_masked(struct match *match,
- const uint8_t dl_dst[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN])
+ const struct eth_addr dl_dst,
+ const struct eth_addr mask)
{
- set_eth_masked(dl_dst, mask, match->flow.dl_dst, match->wc.masks.dl_dst);
+ set_eth_masked(dl_dst, mask, &match->flow.dl_dst, &match->wc.masks.dl_dst);
}
void
}
void
-match_set_arp_sha(struct match *match, const uint8_t sha[ETH_ADDR_LEN])
+match_set_arp_sha(struct match *match, const struct eth_addr sha)
{
- memcpy(match->flow.arp_sha, sha, ETH_ADDR_LEN);
- memset(match->wc.masks.arp_sha, UINT8_MAX, ETH_ADDR_LEN);
+ match->flow.arp_sha = sha;
+ match->wc.masks.arp_sha = eth_addr_exact;
}
void
match_set_arp_sha_masked(struct match *match,
- const uint8_t arp_sha[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN])
+ const struct eth_addr arp_sha,
+ const struct eth_addr mask)
{
set_eth_masked(arp_sha, mask,
- match->flow.arp_sha, match->wc.masks.arp_sha);
+ &match->flow.arp_sha, &match->wc.masks.arp_sha);
}
void
-match_set_arp_tha(struct match *match, const uint8_t tha[ETH_ADDR_LEN])
+match_set_arp_tha(struct match *match, const struct eth_addr tha)
{
- memcpy(match->flow.arp_tha, tha, ETH_ADDR_LEN);
- memset(match->wc.masks.arp_tha, UINT8_MAX, ETH_ADDR_LEN);
+ match->flow.arp_tha = tha;
+ match->wc.masks.arp_tha = eth_addr_exact;
}
void
match_set_arp_tha_masked(struct match *match,
- const uint8_t arp_tha[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN])
+ const struct eth_addr arp_tha,
+ const struct eth_addr mask)
{
set_eth_masked(arp_tha, mask,
- match->flow.arp_tha, match->wc.masks.arp_tha);
+ &match->flow.arp_tha, &match->wc.masks.arp_tha);
}
void
static void
format_eth_masked(struct ds *s, const char *name,
- const uint8_t eth[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN])
+ const struct eth_addr eth, const struct eth_addr mask)
{
if (!eth_addr_is_zero(mask)) {
ds_put_format(s, "%s=", name);
- eth_format_masked(eth, mask, s);
+ eth_format_masked(eth, &mask, s);
ds_put_char(s, ',');
}
}
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[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_src(struct match *, const struct eth_addr );
+void match_set_dl_src_masked(struct match *, const struct eth_addr dl_src,
+ const struct eth_addr mask);
+void match_set_dl_dst(struct match *, const struct eth_addr);
+void match_set_dl_dst_masked(struct match *, const struct eth_addr dl_dst,
+ const struct eth_addr mask);
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 *);
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[ETH_ADDR_LEN]);
+void match_set_arp_sha(struct match *, const struct eth_addr);
void match_set_arp_sha_masked(struct match *,
- 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]);
+ const struct eth_addr arp_sha,
+ const struct eth_addr mask);
+void match_set_arp_tha(struct match *, const struct eth_addr);
void match_set_arp_tha_masked(struct match *,
- const uint8_t arp_tha[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN]);
+ const struct eth_addr arp_tha,
+ const struct eth_addr mask);
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 *);
break;
case MFF_ETH_SRC:
- memcpy(value->mac, flow->dl_src, ETH_ADDR_LEN);
+ value->mac = flow->dl_src;
break;
case MFF_ETH_DST:
- memcpy(value->mac, flow->dl_dst, ETH_ADDR_LEN);
+ value->mac = flow->dl_dst;
break;
case MFF_ETH_TYPE:
case MFF_ARP_SHA:
case MFF_ND_SLL:
- memcpy(value->mac, flow->arp_sha, ETH_ADDR_LEN);
+ value->mac = flow->arp_sha;
break;
case MFF_ARP_THA:
case MFF_ND_TLL:
- memcpy(value->mac, flow->arp_tha, ETH_ADDR_LEN);
+ value->mac = flow->arp_tha;
break;
case MFF_TCP_SRC:
break;
case MFF_ETH_SRC:
- memcpy(flow->dl_src, value->mac, ETH_ADDR_LEN);
+ flow->dl_src = value->mac;
break;
case MFF_ETH_DST:
- memcpy(flow->dl_dst, value->mac, ETH_ADDR_LEN);
+ flow->dl_dst = value->mac;
break;
case MFF_ETH_TYPE:
case MFF_ARP_SHA:
case MFF_ND_SLL:
- memcpy(flow->arp_sha, value->mac, ETH_ADDR_LEN);
+ flow->arp_sha = value->mac;
break;
case MFF_ARP_THA:
case MFF_ND_TLL:
- memcpy(flow->arp_tha, value->mac, ETH_ADDR_LEN);
+ flow->arp_tha = value->mac;
break;
case MFF_TCP_SRC:
break;
case MFF_ETH_SRC:
- memset(match->flow.dl_src, 0, ETH_ADDR_LEN);
- memset(match->wc.masks.dl_src, 0, ETH_ADDR_LEN);
+ match->flow.dl_src = eth_addr_zero;
+ match->wc.masks.dl_src = eth_addr_zero;
break;
case MFF_ETH_DST:
- memset(match->flow.dl_dst, 0, ETH_ADDR_LEN);
- memset(match->wc.masks.dl_dst, 0, ETH_ADDR_LEN);
+ match->flow.dl_dst = eth_addr_zero;
+ match->wc.masks.dl_dst = eth_addr_zero;
break;
case MFF_ETH_TYPE:
case MFF_ARP_SHA:
case MFF_ND_SLL:
- memset(match->flow.arp_sha, 0, ETH_ADDR_LEN);
- memset(match->wc.masks.arp_sha, 0, ETH_ADDR_LEN);
+ match->flow.arp_sha = eth_addr_zero;
+ match->wc.masks.arp_sha = eth_addr_zero;
break;
case MFF_ARP_THA:
case MFF_ND_TLL:
- memset(match->flow.arp_tha, 0, ETH_ADDR_LEN);
- memset(match->wc.masks.arp_tha, 0, ETH_ADDR_LEN);
+ match->flow.arp_tha = eth_addr_zero;
+ match->wc.masks.arp_tha = eth_addr_zero;
break;
case MFF_TCP_SRC:
static char *
mf_from_ethernet_string(const struct mf_field *mf, const char *s,
- uint8_t mac[ETH_ADDR_LEN],
- uint8_t mask[ETH_ADDR_LEN])
+ struct eth_addr *mac, struct eth_addr *mask)
{
int n;
ovs_assert(mf->n_bytes == ETH_ADDR_LEN);
n = -1;
- if (ovs_scan(s, ETH_ADDR_SCAN_FMT"%n", ETH_ADDR_SCAN_ARGS(mac), &n)
+ if (ovs_scan(s, ETH_ADDR_SCAN_FMT"%n", ETH_ADDR_SCAN_ARGS(*mac), &n)
&& n == strlen(s)) {
- memset(mask, 0xff, ETH_ADDR_LEN);
+ *mask = eth_addr_exact;
return NULL;
}
n = -1;
if (ovs_scan(s, ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT"%n",
- ETH_ADDR_SCAN_ARGS(mac), ETH_ADDR_SCAN_ARGS(mask), &n)
+ ETH_ADDR_SCAN_ARGS(*mac), ETH_ADDR_SCAN_ARGS(*mask), &n)
&& n == strlen(s)) {
return NULL;
}
break;
case MFS_ETHERNET:
- error = mf_from_ethernet_string(mf, s, value->mac, mask->mac);
+ error = mf_from_ethernet_string(mf, s, &value->mac, &mask->mac);
break;
case MFS_IPV4:
break;
case MFS_ETHERNET:
- eth_format_masked(value->mac, mask->mac, s);
+ eth_format_masked(value->mac, mask ? &mask->mac : NULL, s);
break;
case MFS_IPV4:
union mf_value {
uint8_t tun_metadata[128];
struct in6_addr ipv6;
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
ovs_be64 be64;
ovs_be32 be32;
ovs_be16 be16;
};
struct {
uint8_t dummy_mac[122];
- uint8_t mac[6];
+ struct eth_addr mac;
};
struct {
ovs_be32 dummy_ipv4[31];
unsigned int cache_valid;
int ifindex;
- uint8_t etheraddr[ETH_ADDR_LEN];
+ struct eth_addr etheraddr;
struct in_addr in4;
struct in_addr netmask;
struct in6_addr in6;
static int do_set_addr(struct netdev *netdev,
unsigned long ioctl_nr, const char *ioctl_name,
struct in_addr addr);
-static int get_etheraddr(const char *netdev_name, uint8_t ea[ETH_ADDR_LEN]);
+static int get_etheraddr(const char *netdev_name, struct eth_addr *ea);
static int set_etheraddr(const char *netdev_name, int hwaddr_family,
- int hwaddr_len, const uint8_t[ETH_ADDR_LEN]);
+ int hwaddr_len, const struct eth_addr);
static int get_ifindex(const struct netdev *, int *ifindexp);
static int ifr_get_flags(const struct ifreq *);
*/
static int
netdev_bsd_set_etheraddr(struct netdev *netdev_,
- const uint8_t mac[ETH_ADDR_LEN])
+ const struct eth_addr mac)
{
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
int error = 0;
ETH_ADDR_LEN, mac);
if (!error) {
netdev->cache_valid |= VALID_ETHERADDR;
- memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN);
+ netdev->etheraddr = mac;
netdev_change_seq_changed(netdev_);
}
}
* free the returned buffer.
*/
static int
-netdev_bsd_get_etheraddr(const struct netdev *netdev_,
- uint8_t mac[ETH_ADDR_LEN])
+netdev_bsd_get_etheraddr(const struct netdev *netdev_, struct eth_addr *mac)
{
struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
int error = 0;
ovs_mutex_lock(&netdev->mutex);
if (!(netdev->cache_valid & VALID_ETHERADDR)) {
error = get_etheraddr(netdev_get_kernel_name(netdev_),
- netdev->etheraddr);
+ &netdev->etheraddr);
if (!error) {
netdev->cache_valid |= VALID_ETHERADDR;
}
}
if (!error) {
- memcpy(mac, netdev->etheraddr, ETH_ADDR_LEN);
+ *mac = netdev->etheraddr;
}
ovs_mutex_unlock(&netdev->mutex);
static int
netdev_bsd_arp_lookup(const struct netdev *netdev OVS_UNUSED,
ovs_be32 ip OVS_UNUSED,
- uint8_t mac[ETH_ADDR_LEN] OVS_UNUSED)
+ struct eth_addr *mac OVS_UNUSED)
{
#if defined(__NetBSD__)
const struct rt_msghdr *rtm;
}
static int
-get_etheraddr(const char *netdev_name, uint8_t ea[ETH_ADDR_LEN])
+get_etheraddr(const char *netdev_name, struct eth_addr *ea)
{
struct ifaddrs *head;
struct ifaddrs *ifa;
static int
set_etheraddr(const char *netdev_name OVS_UNUSED, int hwaddr_family OVS_UNUSED,
int hwaddr_len OVS_UNUSED,
- const uint8_t mac[ETH_ADDR_LEN] OVS_UNUSED)
+ const struct eth_addr mac OVS_UNUSED)
{
#if defined(__FreeBSD__)
struct ifreq ifr;
ovs_strlcpy(ifr.ifr_name, netdev_name, sizeof ifr.ifr_name);
ifr.ifr_addr.sa_family = hwaddr_family;
ifr.ifr_addr.sa_len = hwaddr_len;
- memcpy(ifr.ifr_addr.sa_data, mac, hwaddr_len);
+ memcpy(ifr.ifr_addr.sa_data, &mac, hwaddr_len);
error = af_inet_ioctl(SIOCSIFLLADDR, &ifr);
if (error) {
VLOG_ERR("ioctl(SIOCSIFLLADDR) on %s device failed: %s",
/* Protects stats */
rte_spinlock_t stats_lock;
- uint8_t hwaddr[ETH_ADDR_LEN];
+ struct eth_addr hwaddr;
enum netdev_flags flags;
struct rte_eth_link link;
}
static int
-netdev_dpdk_set_etheraddr(struct netdev *netdev,
- const uint8_t mac[ETH_ADDR_LEN])
+netdev_dpdk_set_etheraddr(struct netdev *netdev, const struct eth_addr mac)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
ovs_mutex_lock(&dev->mutex);
if (!eth_addr_equals(dev->hwaddr, mac)) {
- memcpy(dev->hwaddr, mac, ETH_ADDR_LEN);
+ dev->hwaddr = mac;
netdev_change_seq_changed(netdev);
}
ovs_mutex_unlock(&dev->mutex);
}
static int
-netdev_dpdk_get_etheraddr(const struct netdev *netdev,
- uint8_t mac[ETH_ADDR_LEN])
+netdev_dpdk_get_etheraddr(const struct netdev *netdev, struct eth_addr *mac)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
ovs_mutex_lock(&dev->mutex);
- memcpy(mac, dev->hwaddr, ETH_ADDR_LEN);
+ *mac = dev->hwaddr;
ovs_mutex_unlock(&dev->mutex);
return 0;
/* Protects all members below. */
struct ovs_mutex mutex OVS_ACQ_AFTER(dummy_list_mutex);
- uint8_t hwaddr[ETH_ADDR_LEN] OVS_GUARDED;
+ struct eth_addr hwaddr OVS_GUARDED;
int mtu OVS_GUARDED;
struct netdev_stats stats OVS_GUARDED;
enum netdev_flags flags OVS_GUARDED;
ovs_mutex_init(&netdev->mutex);
ovs_mutex_lock(&netdev->mutex);
- netdev->hwaddr[0] = 0xaa;
- netdev->hwaddr[1] = 0x55;
- netdev->hwaddr[2] = n >> 24;
- netdev->hwaddr[3] = n >> 16;
- netdev->hwaddr[4] = n >> 8;
- netdev->hwaddr[5] = n;
+ netdev->hwaddr.ea[0] = 0xaa;
+ netdev->hwaddr.ea[1] = 0x55;
+ netdev->hwaddr.ea[2] = n >> 24;
+ netdev->hwaddr.ea[3] = n >> 16;
+ netdev->hwaddr.ea[4] = n >> 8;
+ netdev->hwaddr.ea[5] = n;
netdev->mtu = 1500;
netdev->flags = 0;
netdev->ifindex = -EOPNOTSUPP;
}
static int
-netdev_dummy_set_etheraddr(struct netdev *netdev,
- const uint8_t mac[ETH_ADDR_LEN])
+netdev_dummy_set_etheraddr(struct netdev *netdev, const struct eth_addr mac)
{
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
ovs_mutex_lock(&dev->mutex);
if (!eth_addr_equals(dev->hwaddr, mac)) {
- memcpy(dev->hwaddr, mac, ETH_ADDR_LEN);
+ dev->hwaddr = mac;
netdev_change_seq_changed(netdev);
}
ovs_mutex_unlock(&dev->mutex);
}
static int
-netdev_dummy_get_etheraddr(const struct netdev *netdev,
- uint8_t mac[ETH_ADDR_LEN])
+netdev_dummy_get_etheraddr(const struct netdev *netdev, struct eth_addr *mac)
{
struct netdev_dummy *dev = netdev_dummy_cast(netdev);
ovs_mutex_lock(&dev->mutex);
- memcpy(mac, dev->hwaddr, ETH_ADDR_LEN);
+ *mac = dev->hwaddr;
ovs_mutex_unlock(&dev->mutex);
return 0;
/* The following are figured out "on demand" only. They are only valid
* when the corresponding VALID_* bit in 'cache_valid' is set. */
int ifindex;
- uint8_t etheraddr[ETH_ADDR_LEN];
+ struct eth_addr etheraddr;
struct in_addr address, netmask;
struct in6_addr in6;
int mtu;
static int do_set_addr(struct netdev *netdev,
int ioctl_nr, const char *ioctl_name,
struct in_addr addr);
-static int get_etheraddr(const char *netdev_name, uint8_t ea[ETH_ADDR_LEN]);
-static int set_etheraddr(const char *netdev_name, const uint8_t[ETH_ADDR_LEN]);
+static int get_etheraddr(const char *netdev_name, struct eth_addr *ea);
+static int set_etheraddr(const char *netdev_name, const struct eth_addr);
static int get_stats_via_netlink(const struct netdev *, struct netdev_stats *);
static int af_packet_sock(void);
static bool netdev_linux_miimon_enabled(void);
dev->netdev_mtu_error = 0;
}
- if (!eth_addr_is_zero(change->addr)) {
- memcpy(dev->etheraddr, change->addr, ETH_ADDR_LEN);
+ if (!eth_addr_is_zero(change->mac)) {
+ dev->etheraddr = change->mac;
dev->cache_valid |= VALID_ETHERADDR;
dev->ether_addr_error = 0;
}
/* Attempts to set 'netdev''s MAC address to 'mac'. Returns 0 if successful,
* otherwise a positive errno value. */
static int
-netdev_linux_set_etheraddr(struct netdev *netdev_,
- const uint8_t mac[ETH_ADDR_LEN])
+netdev_linux_set_etheraddr(struct netdev *netdev_, const struct eth_addr mac)
{
struct netdev_linux *netdev = netdev_linux_cast(netdev_);
enum netdev_flags old_flags = 0;
netdev->ether_addr_error = error;
netdev->cache_valid |= VALID_ETHERADDR;
if (!error) {
- memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN);
+ netdev->etheraddr = mac;
}
}
/* Copies 'netdev''s MAC address to 'mac' which is passed as param. */
static int
-netdev_linux_get_etheraddr(const struct netdev *netdev_,
- uint8_t mac[ETH_ADDR_LEN])
+netdev_linux_get_etheraddr(const struct netdev *netdev_, struct eth_addr *mac)
{
struct netdev_linux *netdev = netdev_linux_cast(netdev_);
int error;
ovs_mutex_lock(&netdev->mutex);
if (!(netdev->cache_valid & VALID_ETHERADDR)) {
netdev->ether_addr_error = get_etheraddr(netdev_get_name(netdev_),
- netdev->etheraddr);
+ &netdev->etheraddr);
netdev->cache_valid |= VALID_ETHERADDR;
}
error = netdev->ether_addr_error;
if (!error) {
- memcpy(mac, netdev->etheraddr, ETH_ADDR_LEN);
+ *mac = netdev->etheraddr;
}
ovs_mutex_unlock(&netdev->mutex);
* ENXIO indicates that there is not ARP table entry for 'ip' on 'netdev'. */
static int
netdev_linux_arp_lookup(const struct netdev *netdev,
- ovs_be32 ip, uint8_t mac[ETH_ADDR_LEN])
+ ovs_be32 ip, struct eth_addr *mac)
{
struct arpreq r;
struct sockaddr_in sin;
}
static int
-get_etheraddr(const char *netdev_name, uint8_t ea[ETH_ADDR_LEN])
+get_etheraddr(const char *netdev_name, struct eth_addr *ea)
{
struct ifreq ifr;
int hwaddr_family;
}
static int
-set_etheraddr(const char *netdev_name,
- const uint8_t mac[ETH_ADDR_LEN])
+set_etheraddr(const char *netdev_name, const struct eth_addr mac)
{
struct ifreq ifr;
int error;
memset(&ifr, 0, sizeof ifr);
ovs_strzcpy(ifr.ifr_name, netdev_name, sizeof ifr.ifr_name);
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
- memcpy(ifr.ifr_hwaddr.sa_data, mac, ETH_ADDR_LEN);
+ memcpy(ifr.ifr_hwaddr.sa_data, &mac, ETH_ADDR_LEN);
COVERAGE_INC(netdev_set_hwaddr);
error = af_inet_ioctl(SIOCSIFHWADDR, &ifr);
if (error) {
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[ETH_ADDR_LEN]);
+ int (*set_etheraddr)(struct netdev *netdev, const struct eth_addr mac);
/* 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[ETH_ADDR_LEN]);
+ int (*get_etheraddr)(const struct netdev *netdev, struct eth_addr *mac);
/* Retrieves 'netdev''s MTU into '*mtup'.
*
* 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[ETH_ADDR_LEN]);
+ struct eth_addr *mac);
/* 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
/* Protects all members below. */
struct ovs_mutex mutex;
- uint8_t etheraddr[ETH_ADDR_LEN];
+ struct eth_addr etheraddr;
struct netdev_stats stats;
/* Tunnels. */
const char *type = netdev_get_type(netdev_);
ovs_mutex_init(&dev->mutex);
- eth_addr_random(dev->etheraddr);
+ eth_addr_random(&dev->etheraddr);
/* Add a default destination port for tunnel ports if none specified. */
if (!strcmp(type, "geneve")) {
}
static int
-netdev_vport_set_etheraddr(struct netdev *netdev_,
- const uint8_t mac[ETH_ADDR_LEN])
+netdev_vport_set_etheraddr(struct netdev *netdev_, const struct eth_addr mac)
{
struct netdev_vport *netdev = netdev_vport_cast(netdev_);
ovs_mutex_lock(&netdev->mutex);
- memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN);
+ netdev->etheraddr = mac;
ovs_mutex_unlock(&netdev->mutex);
netdev_change_seq_changed(netdev_);
}
static int
-netdev_vport_get_etheraddr(const struct netdev *netdev_,
- uint8_t mac[ETH_ADDR_LEN])
+netdev_vport_get_etheraddr(const struct netdev *netdev_, struct eth_addr *mac)
{
struct netdev_vport *netdev = netdev_vport_cast(netdev_);
ovs_mutex_lock(&netdev->mutex);
- memcpy(mac, netdev->etheraddr, ETH_ADDR_LEN);
+ *mac = netdev->etheraddr;
ovs_mutex_unlock(&netdev->mutex);
return 0;
unsigned int cache_valid;
int ifindex;
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
uint32_t mtu;
unsigned int ifi_flags;
};
/* General information of a network device. */
const char *name;
- uint8_t mac_address[ETH_ADDR_LEN];
+ struct eth_addr mac_address;
uint32_t mtu;
uint32_t ifi_flags;
};
netdev_windows_system_construct(struct netdev *netdev_)
{
struct netdev_windows *netdev = netdev_windows_cast(netdev_);
- uint8_t mac[ETH_ADDR_LEN];
struct netdev_windows_netdev_info info;
struct ofpbuf *buf;
int ret;
netdev->dev_type = info.ovs_type;
netdev->port_no = info.port_no;
- memcpy(netdev->mac, info.mac_address, ETH_ADDR_LEN);
+ netdev->mac = info.mac_address;
netdev->cache_valid = VALID_ETHERADDR;
netdev->ifindex = -EOPNOTSUPP;
static int
netdev_windows_get_etheraddr(const struct netdev *netdev_,
- uint8_t mac[ETH_ADDR_LEN])
+ struct eth_addr *mac)
{
struct netdev_windows *netdev = netdev_windows_cast(netdev_);
ovs_assert((netdev->cache_valid & VALID_ETHERADDR) != 0);
if (netdev->cache_valid & VALID_ETHERADDR) {
- memcpy(mac, netdev->mac, ETH_ADDR_LEN);
+ *mac = netdev->mac;
} else {
return EINVAL;
}
* But vswitchd bringup expects this to be implemented. */
static int
netdev_windows_set_etheraddr(const struct netdev *netdev_,
- uint8_t mac[ETH_ADDR_LEN])
+ const struct eth_addr mac)
{
return 0;
}
*/
static int
netdev_windows_arp_lookup(const struct netdev *netdev,
- ovs_be32 ip, uint8_t mac[ETH_ADDR_LEN])
+ ovs_be32 ip, struct eth_addr *mac)
{
PMIB_IPNETTABLE arp_table = NULL;
/* The buffer length of all ARP entries */
/* Attempts to set 'netdev''s MAC address to 'mac'. Returns 0 if successful,
* otherwise a positive errno value. */
int
-netdev_set_etheraddr(struct netdev *netdev, const uint8_t mac[ETH_ADDR_LEN])
+netdev_set_etheraddr(struct netdev *netdev, const struct eth_addr mac)
{
return netdev->netdev_class->set_etheraddr(netdev, mac);
}
* the MAC address into 'mac'. On failure, returns a positive errno value and
* clears 'mac' to all-zeros. */
int
-netdev_get_etheraddr(const struct netdev *netdev, uint8_t mac[ETH_ADDR_LEN])
+netdev_get_etheraddr(const struct netdev *netdev, struct eth_addr *mac)
{
return netdev->netdev_class->get_etheraddr(netdev, mac);
}
* ENXIO indicates that there is no ARP table entry for 'ip' on 'netdev'. */
int
netdev_arp_lookup(const struct netdev *netdev,
- ovs_be32 ip, uint8_t mac[ETH_ADDR_LEN])
+ ovs_be32 ip, struct eth_addr *mac)
{
int error = (netdev->netdev_class->arp_lookup
? netdev->netdev_class->arp_lookup(netdev, ip, mac)
: EOPNOTSUPP);
if (error) {
- memset(mac, 0, ETH_ADDR_LEN);
+ *mac = eth_addr_zero;
}
return error;
}
int cnt);
/* Hardware address. */
-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]);
+int netdev_set_etheraddr(struct netdev *, const struct eth_addr mac);
+int netdev_get_etheraddr(const struct netdev *, struct eth_addr *mac);
/* PHY interface. */
bool netdev_get_carrier(const struct netdev *);
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[ETH_ADDR_LEN]);
+ struct eth_addr *mac);
struct netdev *netdev_find_dev_by_in4(const struct in_addr *);
static void
nxm_put_eth_masked(struct ofpbuf *b,
enum mf_field_id field, enum ofp_version version,
- const uint8_t value[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN])
+ const struct eth_addr value, const struct eth_addr mask)
{
- nxm_put(b, field, version, value, mask, ETH_ADDR_LEN);
+ nxm_put(b, field, version, value.ea, mask.ea, ETH_ADDR_LEN);
}
static void
/* Masked copy of an ethernet address. 'src' is already properly masked. */
static void
-ether_addr_copy_masked(uint8_t *dst, const uint8_t *src,
- const uint8_t *mask)
+ether_addr_copy_masked(struct eth_addr *dst, const struct eth_addr src,
+ const struct eth_addr mask)
{
int i;
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- dst[i] = src[i] | (dst[i] & ~mask[i]);
+ for (i = 0; i < ARRAY_SIZE(dst->be16); i++) {
+ dst->be16[i] = src.be16[i] | (dst->be16[i] & ~mask.be16[i]);
}
}
if (eh) {
if (!mask) {
- memcpy(eh->eth_src, key->eth_src, sizeof eh->eth_src);
- memcpy(eh->eth_dst, key->eth_dst, sizeof eh->eth_dst);
+ eh->eth_src = key->eth_src;
+ eh->eth_dst = key->eth_dst;
} else {
- ether_addr_copy_masked(eh->eth_src, key->eth_src, mask->eth_src);
- ether_addr_copy_masked(eh->eth_dst, key->eth_dst, mask->eth_dst);
+ ether_addr_copy_masked(&eh->eth_src, key->eth_src, mask->eth_src);
+ ether_addr_copy_masked(&eh->eth_dst, key->eth_dst, mask->eth_dst);
}
}
}
if (!mask) {
arp->ar_op = key->arp_op;
- memcpy(arp->ar_sha, key->arp_sha, ETH_ADDR_LEN);
+ arp->ar_sha = key->arp_sha;
put_16aligned_be32(&arp->ar_spa, key->arp_sip);
- memcpy(arp->ar_tha, key->arp_tha, ETH_ADDR_LEN);
+ arp->ar_tha = key->arp_tha;
put_16aligned_be32(&arp->ar_tpa, key->arp_tip);
} else {
ovs_be32 ar_spa = get_16aligned_be32(&arp->ar_spa);
ovs_be32 ar_tpa = get_16aligned_be32(&arp->ar_tpa);
arp->ar_op = key->arp_op | (arp->ar_op & ~mask->arp_op);
- ether_addr_copy_masked(arp->ar_sha, key->arp_sha, mask->arp_sha);
+ ether_addr_copy_masked(&arp->ar_sha, key->arp_sha, mask->arp_sha);
put_16aligned_be32(&arp->ar_spa,
key->arp_sip | (ar_spa & ~mask->arp_sip));
- ether_addr_copy_masked(arp->ar_tha, key->arp_tha, mask->arp_tha);
+ ether_addr_copy_masked(&arp->ar_tha, key->arp_tha, mask->arp_tha);
put_16aligned_be32(&arp->ar_tpa,
key->arp_tip | (ar_tpa & ~mask->arp_tip));
}
if (OVS_LIKELY(ns && nd_opt)) {
int bytes_remain = dp_packet_l4_size(packet) - sizeof(*ns);
ovs_be32 tgt_buf[4];
- uint8_t sll_buf[ETH_ADDR_LEN] = {0};
- uint8_t tll_buf[ETH_ADDR_LEN] = {0};
+ struct eth_addr sll_buf = eth_addr_zero;
+ struct eth_addr tll_buf = eth_addr_zero;
while (bytes_remain >= ND_OPT_LEN && nd_opt->nd_opt_len != 0) {
if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LINKADDR
&& nd_opt->nd_opt_len == 1) {
- memcpy(sll_buf, nd_opt->nd_opt_data, ETH_ADDR_LEN);
- ether_addr_copy_masked(sll_buf, key->nd_sll, mask->nd_sll);
+ sll_buf = nd_opt->nd_opt_mac;
+ ether_addr_copy_masked(&sll_buf, key->nd_sll, mask->nd_sll);
/* A packet can only contain one SLL or TLL option */
break;
} else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LINKADDR
&& nd_opt->nd_opt_len == 1) {
- memcpy(tll_buf, nd_opt->nd_opt_data, ETH_ADDR_LEN);
- ether_addr_copy_masked(tll_buf, key->nd_tll, mask->nd_tll);
+ tll_buf = nd_opt->nd_opt_mac;
+ ether_addr_copy_masked(&tll_buf, key->nd_tll, mask->nd_tll);
/* A packet can only contain one SLL or TLL option */
break;
if (OVS_LIKELY(dp_packet_get_nd_payload(packet))) {
const struct ovs_key_nd *nd_key
= nl_attr_get_unspec(a, sizeof(struct ovs_key_nd));
- packet_set_nd(packet, nd_key->nd_target,
- nd_key->nd_sll, nd_key->nd_tll);
+ packet_set_nd(packet, nd_key->nd_target, nd_key->nd_sll,
+ nd_key->nd_tll);
}
break;
/* Format helpers. */
static void
-format_eth(struct ds *ds, const char *name, const uint8_t key[ETH_ADDR_LEN],
- const uint8_t (*mask)[ETH_ADDR_LEN], bool verbose)
+format_eth(struct ds *ds, const char *name, const struct eth_addr key,
+ const struct eth_addr *mask, bool verbose)
{
bool mask_empty = mask && eth_addr_is_zero(*mask);
ds_put_format(ds, "%s="ETH_ADDR_FMT",", name, ETH_ADDR_ARGS(key));
} else {
ds_put_format(ds, "%s=", name);
- eth_format_masked(key, *mask, ds);
+ eth_format_masked(key, mask, ds);
ds_put_char(ds, ',');
}
}
/* Parsing. */
static int
-scan_eth(const char *s, uint8_t (*key)[ETH_ADDR_LEN],
- uint8_t (*mask)[ETH_ADDR_LEN])
+scan_eth(const char *s, struct eth_addr *key, struct eth_addr *mask)
{
int n;
- if (ovs_scan(s, ETH_ADDR_SCAN_FMT"%n", ETH_ADDR_SCAN_ARGS(*key), &n)) {
+ if (ovs_scan(s, ETH_ADDR_SCAN_FMT"%n",
+ ETH_ADDR_SCAN_ARGS(*key), &n)) {
int len = n;
if (mask) {
sizeof *nd_key);
memcpy(nd_key->nd_target, &data->nd_target,
sizeof nd_key->nd_target);
- memcpy(nd_key->nd_sll, data->arp_sha, ETH_ADDR_LEN);
- memcpy(nd_key->nd_tll, data->arp_tha, ETH_ADDR_LEN);
+ nd_key->nd_sll = data->arp_sha;
+ nd_key->nd_tll = data->arp_tha;
}
}
}
nd_key = nl_attr_get(attrs[OVS_KEY_ATTR_ND]);
memcpy(&flow->nd_target, nd_key->nd_target,
sizeof flow->nd_target);
- memcpy(flow->arp_sha, nd_key->nd_sll, ETH_ADDR_LEN);
- memcpy(flow->arp_tha, nd_key->nd_tll, ETH_ADDR_LEN);
+ flow->arp_sha = nd_key->nd_sll;
+ flow->arp_tha = nd_key->nd_tll;
if (is_mask) {
if (!is_all_zeros(nd_key, sizeof *nd_key) &&
(flow->tp_src != htons(0xffff) ||
static void
get_ethernet_key(const struct flow *flow, struct ovs_key_ethernet *eth)
{
- memcpy(eth->eth_src, flow->dl_src, ETH_ADDR_LEN);
- memcpy(eth->eth_dst, flow->dl_dst, ETH_ADDR_LEN);
+ eth->eth_src = flow->dl_src;
+ eth->eth_dst = flow->dl_dst;
}
static void
put_ethernet_key(const struct ovs_key_ethernet *eth, struct flow *flow)
{
- memcpy(flow->dl_src, eth->eth_src, ETH_ADDR_LEN);
- memcpy(flow->dl_dst, eth->eth_dst, ETH_ADDR_LEN);
+ flow->dl_src = eth->eth_src;
+ flow->dl_dst = eth->eth_dst;
}
static void
arp->arp_sip = flow->nw_src;
arp->arp_tip = flow->nw_dst;
arp->arp_op = htons(flow->nw_proto);
- memcpy(arp->arp_sha, flow->arp_sha, ETH_ADDR_LEN);
- memcpy(arp->arp_tha, flow->arp_tha, ETH_ADDR_LEN);
+ arp->arp_sha = flow->arp_sha;
+ arp->arp_tha = flow->arp_tha;
}
static void
flow->nw_src = arp->arp_sip;
flow->nw_dst = arp->arp_tip;
flow->nw_proto = ntohs(arp->arp_op);
- memcpy(flow->arp_sha, arp->arp_sha, ETH_ADDR_LEN);
- memcpy(flow->arp_tha, arp->arp_tha, ETH_ADDR_LEN);
+ flow->arp_sha = arp->arp_sha;
+ flow->arp_tha = arp->arp_tha;
}
static enum slow_path_reason
{
memcpy(nd->nd_target, &flow->nd_target, sizeof flow->nd_target);
/* nd_sll and nd_tll are stored in arp_sha and arp_tha, respectively */
- memcpy(nd->nd_sll, flow->arp_sha, ETH_ADDR_LEN);
- memcpy(nd->nd_tll, flow->arp_tha, ETH_ADDR_LEN);
+ nd->nd_sll = flow->arp_sha;
+ nd->nd_tll = flow->arp_tha;
}
static void
{
memcpy(&flow->nd_target, nd->nd_target, sizeof flow->nd_target);
/* nd_sll and nd_tll are stored in arp_sha and arp_tha, respectively */
- memcpy(flow->arp_sha, nd->nd_sll, ETH_ADDR_LEN);
- memcpy(flow->arp_tha, nd->nd_tll, ETH_ADDR_LEN);
+ flow->arp_sha = nd->nd_sll;
+ flow->arp_tha = nd->nd_tll;
}
static enum slow_path_reason
struct ofp_action_dl_addr {
ovs_be16 type; /* Type. */
ovs_be16 len; /* Length is 16. */
- uint8_t dl_addr[OFP_ETH_ALEN]; /* Ethernet address. */
+ struct eth_addr dl_addr; /* Ethernet address. */
uint8_t pad[6];
};
OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16);
decode_OFPAT_RAW_SET_DL_SRC(const struct ofp_action_dl_addr *a,
struct ofpbuf *out)
{
- memcpy(ofpact_put_SET_ETH_SRC(out)->mac, a->dl_addr, ETH_ADDR_LEN);
+ ofpact_put_SET_ETH_SRC(out)->mac = a->dl_addr;
return 0;
}
decode_OFPAT_RAW_SET_DL_DST(const struct ofp_action_dl_addr *a,
struct ofpbuf *out)
{
- memcpy(ofpact_put_SET_ETH_DST(out)->mac, a->dl_addr, ETH_ADDR_LEN);
+ ofpact_put_SET_ETH_DST(out)->mac = a->dl_addr;
return 0;
}
enum ofp_raw_action_type raw, enum mf_field_id field,
struct ofpbuf *out)
{
- const uint8_t *addr = mac->mac;
-
if (ofp_version < OFP12_VERSION) {
struct ofp_action_dl_addr *oada;
oada = ofpact_put_raw(out, ofp_version, raw, 0);
- memcpy(oada->dl_addr, addr, ETH_ADDR_LEN);
+ oada->dl_addr = mac->mac;
} else {
ofpact_put_set_field(out, ofp_version, field,
- eth_addr_to_uint64(addr));
+ eth_addr_to_uint64(mac->mac));
}
}
parse_SET_ETH_SRC(char *arg, struct ofpbuf *ofpacts,
enum ofputil_protocol *usable_protocols OVS_UNUSED)
{
- return str_to_mac(arg, ofpact_put_SET_ETH_SRC(ofpacts)->mac);
+ return str_to_mac(arg, &ofpact_put_SET_ETH_SRC(ofpacts)->mac);
}
static char * OVS_WARN_UNUSED_RESULT
parse_SET_ETH_DST(char *arg, struct ofpbuf *ofpacts,
enum ofputil_protocol *usable_protocols OVS_UNUSED)
{
- return str_to_mac(arg, ofpact_put_SET_ETH_DST(ofpacts)->mac);
+ return str_to_mac(arg, &ofpact_put_SET_ETH_DST(ofpacts)->mac);
}
static void
break;
case MFF_ETH_SRC:
- memcpy(put_OFPAT_SET_DL_SRC(out, ofp_version)->dl_addr,
- sf->value.mac, ETH_ADDR_LEN);
+ put_OFPAT_SET_DL_SRC(out, ofp_version)->dl_addr = sf->value.mac;
break;
case MFF_ETH_DST:
- memcpy(put_OFPAT_SET_DL_DST(out, ofp_version)->dl_addr,
- sf->value.mac, ETH_ADDR_LEN);
+ put_OFPAT_SET_DL_DST(out, ofp_version)->dl_addr = sf->value.mac;
break;
case MFF_IPV4_SRC:
* Used for OFPAT10_SET_DL_SRC, OFPAT10_SET_DL_DST. */
struct ofpact_mac {
struct ofpact ofpact;
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
};
/* OFPACT_SET_IPV4_SRC, OFPACT_SET_IPV4_DST.
* Returns NULL if successful, otherwise a malloc()'d string describing the
* error. The caller is responsible for freeing the returned string. */
char * OVS_WARN_UNUSED_RESULT
-str_to_mac(const char *str, uint8_t mac[ETH_ADDR_LEN])
+str_to_mac(const char *str, struct eth_addr *mac)
{
- if (!ovs_scan(str, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))) {
+ if (!ovs_scan(str, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(*mac))) {
return xasprintf("invalid mac address %s", str);
}
return NULL;
char *str_to_u32(const char *str, uint32_t *valuep) OVS_WARN_UNUSED_RESULT;
char *str_to_u64(const char *str, uint64_t *valuep) OVS_WARN_UNUSED_RESULT;
char *str_to_be64(const char *str, ovs_be64 *valuep) OVS_WARN_UNUSED_RESULT;
-char *str_to_mac(const char *str, uint8_t mac[ETH_ADDR_LEN]) OVS_WARN_UNUSED_RESULT;
+char *str_to_mac(const char *str, struct eth_addr *mac) OVS_WARN_UNUSED_RESULT;
char *str_to_ip(const char *str, ovs_be32 *ip) OVS_WARN_UNUSED_RESULT;
#endif /* ofp-parse.h */
}
if (!(ofpfw & OFPFW10_DL_SRC)) {
- memset(wc->masks.dl_src, 0xff, ETH_ADDR_LEN);
+ WC_MASK_FIELD(wc, dl_src);
}
if (!(ofpfw & OFPFW10_DL_DST)) {
- memset(wc->masks.dl_dst, 0xff, ETH_ADDR_LEN);
+ WC_MASK_FIELD(wc, dl_dst);
}
if (!(ofpfw & OFPFW10_DL_TYPE)) {
wc->masks.dl_type = OVS_BE16_MAX;
match->flow.dl_type = ofputil_dl_type_from_openflow(ofmatch->dl_type);
match->flow.tp_src = ofmatch->tp_src;
match->flow.tp_dst = ofmatch->tp_dst;
- memcpy(match->flow.dl_src, ofmatch->dl_src, ETH_ADDR_LEN);
- memcpy(match->flow.dl_dst, ofmatch->dl_dst, ETH_ADDR_LEN);
+ match->flow.dl_src = ofmatch->dl_src;
+ match->flow.dl_dst = ofmatch->dl_dst;
match->flow.nw_tos = ofmatch->nw_tos & IP_DSCP_MASK;
match->flow.nw_proto = ofmatch->nw_proto;
/* Compose most of the match structure. */
ofmatch->wildcards = htonl(ofpfw);
ofmatch->in_port = htons(ofp_to_u16(match->flow.in_port.ofp_port));
- memcpy(ofmatch->dl_src, match->flow.dl_src, ETH_ADDR_LEN);
- memcpy(ofmatch->dl_dst, match->flow.dl_dst, ETH_ADDR_LEN);
+ ofmatch->dl_src = match->flow.dl_src;
+ ofmatch->dl_dst = match->flow.dl_dst;
ofmatch->dl_type = ofputil_dl_type_to_openflow(match->flow.dl_type);
ofmatch->nw_src = match->flow.nw_src;
ofmatch->nw_dst = match->flow.nw_dst;
struct match *match)
{
uint16_t wc = ntohl(ofmatch->wildcards);
- uint8_t dl_src_mask[ETH_ADDR_LEN];
- uint8_t dl_dst_mask[ETH_ADDR_LEN];
bool ipv4, arp, rarp;
- int i;
match_init_catchall(match);
match_set_in_port(match, ofp_port);
}
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- dl_src_mask[i] = ~ofmatch->dl_src_mask[i];
- }
- match_set_dl_src_masked(match, ofmatch->dl_src, dl_src_mask);
-
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- dl_dst_mask[i] = ~ofmatch->dl_dst_mask[i];
- }
- match_set_dl_dst_masked(match, ofmatch->dl_dst, dl_dst_mask);
+ match_set_dl_src_masked(match, ofmatch->dl_src,
+ eth_addr_invert(ofmatch->dl_src_mask));
+ match_set_dl_dst_masked(match, ofmatch->dl_dst,
+ eth_addr_invert(ofmatch->dl_dst_mask));
if (!(wc & OFPFW11_DL_VLAN)) {
if (ofmatch->dl_vlan == htons(OFPVID11_NONE)) {
struct ofp11_match *ofmatch)
{
uint32_t wc = 0;
- int i;
memset(ofmatch, 0, sizeof *ofmatch);
ofmatch->omh.type = htons(OFPMT_STANDARD);
ofmatch->in_port = ofputil_port_to_ofp11(match->flow.in_port.ofp_port);
}
- memcpy(ofmatch->dl_src, match->flow.dl_src, ETH_ADDR_LEN);
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- ofmatch->dl_src_mask[i] = ~match->wc.masks.dl_src[i];
- }
-
- memcpy(ofmatch->dl_dst, match->flow.dl_dst, ETH_ADDR_LEN);
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- ofmatch->dl_dst_mask[i] = ~match->wc.masks.dl_dst[i];
- }
+ ofmatch->dl_src = match->flow.dl_src;
+ ofmatch->dl_src_mask = eth_addr_invert(match->wc.masks.dl_src);
+ ofmatch->dl_dst = match->flow.dl_dst;
+ ofmatch->dl_dst_mask = eth_addr_invert(match->wc.masks.dl_dst);
if (match->wc.masks.vlan_tci == htons(0)) {
wc |= OFPFW11_DL_VLAN | OFPFW11_DL_VLAN_PCP;
const struct ofp10_phy_port *opp)
{
pp->port_no = u16_to_ofp(ntohs(opp->port_no));
- memcpy(pp->hw_addr, opp->hw_addr, OFP_ETH_ALEN);
+ pp->hw_addr = opp->hw_addr;
ovs_strlcpy(pp->name, opp->name, OFP_MAX_PORT_NAME_LEN);
pp->config = ntohl(opp->config) & OFPPC10_ALL;
if (error) {
return error;
}
- memcpy(pp->hw_addr, op->hw_addr, OFP_ETH_ALEN);
+ pp->hw_addr = op->hw_addr;
ovs_strlcpy(pp->name, op->name, OFP_MAX_PORT_NAME_LEN);
pp->config = ntohl(op->config) & OFPPC11_ALL;
if (error) {
return error;
}
- memcpy(pp->hw_addr, op->hw_addr, OFP_ETH_ALEN);
+ pp->hw_addr = op->hw_addr;
ovs_strlcpy(pp->name, op->name, OFP_MAX_PORT_NAME_LEN);
pp->config = ntohl(op->config) & OFPPC11_ALL;
memset(opp, 0, sizeof *opp);
opp->port_no = htons(ofp_to_u16(pp->port_no));
- memcpy(opp->hw_addr, pp->hw_addr, ETH_ADDR_LEN);
+ opp->hw_addr = pp->hw_addr;
ovs_strlcpy(opp->name, pp->name, OFP_MAX_PORT_NAME_LEN);
opp->config = htonl(pp->config & OFPPC10_ALL);
memset(op, 0, sizeof *op);
op->port_no = ofputil_port_to_ofp11(pp->port_no);
- memcpy(op->hw_addr, pp->hw_addr, ETH_ADDR_LEN);
+ op->hw_addr = pp->hw_addr;
ovs_strlcpy(op->name, pp->name, OFP_MAX_PORT_NAME_LEN);
op->config = htonl(pp->config & OFPPC11_ALL);
op = ofpbuf_put_zeros(b, sizeof *op);
op->port_no = ofputil_port_to_ofp11(pp->port_no);
op->length = htons(sizeof *op + sizeof *eth);
- memcpy(op->hw_addr, pp->hw_addr, ETH_ADDR_LEN);
+ op->hw_addr = pp->hw_addr;
ovs_strlcpy(op->name, pp->name, sizeof op->name);
op->config = htonl(pp->config & OFPPC11_ALL);
op->state = htonl(pp->state & OFPPS11_ALL);
const struct ofp10_port_mod *opm = b.data;
pm->port_no = u16_to_ofp(ntohs(opm->port_no));
- memcpy(pm->hw_addr, opm->hw_addr, ETH_ADDR_LEN);
+ pm->hw_addr = opm->hw_addr;
pm->config = ntohl(opm->config) & OFPPC10_ALL;
pm->mask = ntohl(opm->mask) & OFPPC10_ALL;
pm->advertise = netdev_port_features_from_ofp10(opm->advertise);
return error;
}
- memcpy(pm->hw_addr, opm->hw_addr, ETH_ADDR_LEN);
+ pm->hw_addr = opm->hw_addr;
pm->config = ntohl(opm->config) & OFPPC11_ALL;
pm->mask = ntohl(opm->mask) & OFPPC11_ALL;
pm->advertise = netdev_port_features_from_ofp11(opm->advertise);
return error;
}
- memcpy(pm->hw_addr, opm->hw_addr, ETH_ADDR_LEN);
+ pm->hw_addr = opm->hw_addr;
pm->config = ntohl(opm->config) & OFPPC11_ALL;
pm->mask = ntohl(opm->mask) & OFPPC11_ALL;
b = ofpraw_alloc(OFPRAW_OFPT10_PORT_MOD, ofp_version, 0);
opm = ofpbuf_put_zeros(b, sizeof *opm);
opm->port_no = htons(ofp_to_u16(pm->port_no));
- memcpy(opm->hw_addr, pm->hw_addr, ETH_ADDR_LEN);
+ opm->hw_addr = pm->hw_addr;
opm->config = htonl(pm->config & OFPPC10_ALL);
opm->mask = htonl(pm->mask & OFPPC10_ALL);
opm->advertise = netdev_port_features_to_ofp10(pm->advertise);
b = ofpraw_alloc(OFPRAW_OFPT11_PORT_MOD, ofp_version, 0);
opm = ofpbuf_put_zeros(b, sizeof *opm);
opm->port_no = ofputil_port_to_ofp11(pm->port_no);
- memcpy(opm->hw_addr, pm->hw_addr, ETH_ADDR_LEN);
+ opm->hw_addr = pm->hw_addr;
opm->config = htonl(pm->config & OFPPC11_ALL);
opm->mask = htonl(pm->mask & OFPPC11_ALL);
opm->advertise = netdev_port_features_to_ofp11(pm->advertise);
b = ofpraw_alloc(OFPRAW_OFPT14_PORT_MOD, ofp_version, sizeof *eth);
opm = ofpbuf_put_zeros(b, sizeof *opm);
opm->port_no = ofputil_port_to_ofp11(pm->port_no);
- memcpy(opm->hw_addr, pm->hw_addr, ETH_ADDR_LEN);
+ opm->hw_addr = pm->hw_addr;
opm->config = htonl(pm->config & OFPPC11_ALL);
opm->mask = htonl(pm->mask & OFPPC11_ALL);
wc.masks.nw_ttl = 0;
}
if (!(may_match & MAY_ARP_SHA)) {
- memset(wc.masks.arp_sha, 0, ETH_ADDR_LEN);
+ WC_UNMASK_FIELD(&wc, arp_sha);
}
if (!(may_match & MAY_ARP_THA)) {
- memset(wc.masks.arp_tha, 0, ETH_ADDR_LEN);
+ WC_UNMASK_FIELD(&wc, arp_tha);
}
if (!(may_match & MAY_IPV6)) {
wc.masks.ipv6_src = wc.masks.ipv6_dst = in6addr_any;
/* Abstract ofp10_phy_port or ofp11_port. */
struct ofputil_phy_port {
ofp_port_t port_no;
- uint8_t hw_addr[OFP_ETH_ALEN];
+ struct eth_addr hw_addr;
char name[OFP_MAX_PORT_NAME_LEN];
enum ofputil_port_config config;
enum ofputil_port_state state;
/* Abstract ofp_port_mod. */
struct ofputil_port_mod {
ofp_port_t port_no;
- uint8_t hw_addr[OFP_ETH_ALEN];
+ struct eth_addr hw_addr;
enum ofputil_port_config config;
enum ofputil_port_config mask;
enum netdev_features advertise;
*/
void
lldp_put_packet(struct lldp *lldp, struct dp_packet *packet,
- uint8_t eth_src[ETH_ADDR_LEN]) OVS_EXCLUDED(mutex)
+ const struct eth_addr eth_src) OVS_EXCLUDED(mutex)
{
struct lldpd *mylldpd = lldp->lldpd;
struct lldpd_hardware *hw = lldpd_first_hardware(mylldpd);
- static const uint8_t eth_addr_lldp[6] =
- {0x01, 0x80, 0xC2, 0x00, 0x00, 0x0e};
+ static const struct eth_addr eth_addr_lldp =
+ { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0e } } };
ovs_mutex_lock(&mutex);
lchassis->c_cap_enabled = LLDP_CAP_BRIDGE;
lchassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
lchassis->c_id_len = ETH_ADDR_LEN;
- lchassis->c_id = xmalloc(ETH_ADDR_LEN);
- netdev_get_etheraddr(netdev, lchassis->c_id);
+
+ struct eth_addr *mac = xmalloc(ETH_ADDR_LEN);
+ netdev_get_etheraddr(netdev, mac);
+ lchassis->c_id = &mac->ea[0];
list_init(&lchassis->c_mgmt);
lchassis->c_ttl = lldp->lldpd->g_config.c_tx_interval *
bool lldp_configure(struct lldp *lldp, const struct smap *cfg);
void lldp_process_packet(struct lldp *cfg, const struct dp_packet *);
void lldp_put_packet(struct lldp *lldp, struct dp_packet *packet,
- uint8_t eth_src[ETH_ADDR_LEN]);
+ const struct eth_addr eth_src);
void lldpd_assign_cfg_to_protocols(struct lldpd *cfg);
struct lldp * lldp_create(const struct netdev *netdev, const uint32_t mtu,
const struct smap *cfg);
* If you change this function's behavior, please update corresponding
* documentation in vswitch.xml at the same time. */
bool
-eth_addr_is_reserved(const uint8_t ea[ETH_ADDR_LEN])
+eth_addr_is_reserved(const struct eth_addr ea)
{
struct eth_addr_node {
struct hmap_node hmap_node;
}
bool
-eth_addr_from_string(const char *s, uint8_t ea[ETH_ADDR_LEN])
+eth_addr_from_string(const char *s, struct eth_addr *ea)
{
- if (ovs_scan(s, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(ea))) {
+ if (ovs_scan(s, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(*ea))) {
return true;
} else {
- memset(ea, 0, ETH_ADDR_LEN);
+ *ea = eth_addr_zero;
return false;
}
}
* The returned packet has enough headroom to insert an 802.1Q VLAN header if
* desired. */
void
-compose_rarp(struct dp_packet *b, const uint8_t eth_src[ETH_ADDR_LEN])
+compose_rarp(struct dp_packet *b, const struct eth_addr eth_src)
{
struct eth_header *eth;
struct arp_eth_header *arp;
+ ARP_ETH_HEADER_LEN);
dp_packet_reserve(b, 2 + VLAN_HEADER_LEN);
eth = dp_packet_put_uninit(b, sizeof *eth);
- memcpy(eth->eth_dst, eth_addr_broadcast, ETH_ADDR_LEN);
- memcpy(eth->eth_src, eth_src, ETH_ADDR_LEN);
+ eth->eth_dst = eth_addr_broadcast;
+ eth->eth_src = eth_src;
eth->eth_type = htons(ETH_TYPE_RARP);
arp = dp_packet_put_uninit(b, sizeof *arp);
arp->ar_hln = sizeof arp->ar_sha;
arp->ar_pln = sizeof arp->ar_spa;
arp->ar_op = htons(ARP_OP_RARP);
- memcpy(arp->ar_sha, eth_src, ETH_ADDR_LEN);
+ arp->ar_sha = eth_src;
put_16aligned_be32(&arp->ar_spa, htonl(0));
- memcpy(arp->ar_tha, eth_src, ETH_ADDR_LEN);
+ arp->ar_tha = eth_src;
put_16aligned_be32(&arp->ar_tpa, htonl(0));
dp_packet_reset_offsets(b);
}
void
-eth_format_masked(const uint8_t eth[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN], struct ds *s)
+eth_format_masked(const struct eth_addr eth,
+ const struct eth_addr *mask, struct ds *s)
{
ds_put_format(s, ETH_ADDR_FMT, ETH_ADDR_ARGS(eth));
- if (mask && !eth_mask_is_exact(mask)) {
- ds_put_format(s, "/"ETH_ADDR_FMT, ETH_ADDR_ARGS(mask));
- }
-}
-
-void
-eth_addr_bitand(const uint8_t src[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN],
- uint8_t dst[ETH_ADDR_LEN])
-{
- int i;
-
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- dst[i] = src[i] & mask[i];
+ if (mask && !eth_mask_is_exact(*mask)) {
+ ds_put_format(s, "/"ETH_ADDR_FMT, ETH_ADDR_ARGS(*mask));
}
}
* The returned packet has enough headroom to insert an 802.1Q VLAN header if
* desired. */
void *
-eth_compose(struct dp_packet *b, const uint8_t eth_dst[ETH_ADDR_LEN],
- const uint8_t eth_src[ETH_ADDR_LEN], uint16_t eth_type,
+eth_compose(struct dp_packet *b, const struct eth_addr eth_dst,
+ const struct eth_addr eth_src, uint16_t eth_type,
size_t size)
{
void *data;
eth = dp_packet_put_uninit(b, ETH_HEADER_LEN);
data = dp_packet_put_uninit(b, size);
- memcpy(eth->eth_dst, eth_dst, ETH_ADDR_LEN);
- memcpy(eth->eth_src, eth_src, ETH_ADDR_LEN);
+ eth->eth_dst = eth_dst;
+ eth->eth_src = eth_src;
eth->eth_type = htons(eth_type);
dp_packet_reset_offsets(b);
void
packet_set_nd(struct dp_packet *packet, const ovs_be32 target[4],
- const uint8_t sll[ETH_ADDR_LEN],
- const uint8_t tll[ETH_ADDR_LEN]) {
+ const struct eth_addr sll, const struct eth_addr tll) {
struct ovs_nd_msg *ns;
struct ovs_nd_opt *nd_opt;
int bytes_remain = dp_packet_l4_size(packet);
while (bytes_remain >= ND_OPT_LEN && nd_opt->nd_opt_len != 0) {
if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LINKADDR
&& nd_opt->nd_opt_len == 1) {
- if (memcmp(nd_opt->nd_opt_data, sll, ETH_ADDR_LEN)) {
+ if (!eth_addr_equals(nd_opt->nd_opt_mac, sll)) {
ovs_be16 *csum = &(ns->icmph.icmp6_cksum);
- *csum = recalc_csum48(*csum, nd_opt->nd_opt_data, sll);
- memcpy(nd_opt->nd_opt_data, sll, ETH_ADDR_LEN);
+ *csum = recalc_csum48(*csum, nd_opt->nd_opt_mac, sll);
+ nd_opt->nd_opt_mac = sll;
}
/* A packet can only contain one SLL or TLL option */
break;
} else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LINKADDR
&& nd_opt->nd_opt_len == 1) {
- if (memcmp(nd_opt->nd_opt_data, tll, ETH_ADDR_LEN)) {
+ if (!eth_addr_equals(nd_opt->nd_opt_mac, tll)) {
ovs_be16 *csum = &(ns->icmph.icmp6_cksum);
- *csum = recalc_csum48(*csum, nd_opt->nd_opt_data, tll);
- memcpy(nd_opt->nd_opt_data, tll, ETH_ADDR_LEN);
+ *csum = recalc_csum48(*csum, nd_opt->nd_opt_mac, tll);
+ nd_opt->nd_opt_mac = tll;
}
/* A packet can only contain one SLL or TLL option */
* 'broadcast' is true. */
void
compose_arp(struct dp_packet *b, uint16_t arp_op,
- const uint8_t arp_sha[ETH_ADDR_LEN],
- const uint8_t arp_tha[ETH_ADDR_LEN], bool broadcast,
- ovs_be32 arp_spa, ovs_be32 arp_tpa)
+ const struct eth_addr arp_sha, const struct eth_addr arp_tha,
+ bool broadcast, ovs_be32 arp_spa, ovs_be32 arp_tpa)
{
struct eth_header *eth;
struct arp_eth_header *arp;
dp_packet_reserve(b, 2 + VLAN_HEADER_LEN);
eth = dp_packet_put_uninit(b, sizeof *eth);
- memcpy(eth->eth_dst, broadcast ? eth_addr_broadcast : arp_tha,
- ETH_ADDR_LEN);
- memcpy(eth->eth_src, arp_sha, ETH_ADDR_LEN);
+ eth->eth_dst = broadcast ? eth_addr_broadcast : arp_tha;
+ eth->eth_src = arp_sha;
eth->eth_type = htons(ETH_TYPE_ARP);
arp = dp_packet_put_uninit(b, sizeof *arp);
arp->ar_hln = sizeof arp->ar_sha;
arp->ar_pln = sizeof arp->ar_spa;
arp->ar_op = htons(arp_op);
- memcpy(arp->ar_sha, arp_sha, ETH_ADDR_LEN);
- memcpy(arp->ar_tha, arp_tha, ETH_ADDR_LEN);
+ arp->ar_sha = arp_sha;
+ arp->ar_tha = arp_tha;
put_16aligned_be32(&arp->ar_spa, arp_spa);
put_16aligned_be32(&arp->ar_tpa, arp_tpa);
#define ETH_ADDR_LEN 6
-static const uint8_t eth_addr_broadcast[ETH_ADDR_LEN] OVS_UNUSED
- = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+static const struct eth_addr eth_addr_broadcast OVS_UNUSED
+ = { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } };
-static const uint8_t eth_addr_zero[ETH_ADDR_LEN] OVS_UNUSED
- = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+static const struct eth_addr eth_addr_exact OVS_UNUSED
+ = { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } };
-static const uint8_t eth_addr_stp[ETH_ADDR_LEN] OVS_UNUSED
- = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x00 };
+static const struct eth_addr eth_addr_zero OVS_UNUSED
+ = { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } };
-static const uint8_t eth_addr_lacp[ETH_ADDR_LEN] OVS_UNUSED
- = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x02 };
+static const struct eth_addr eth_addr_stp OVS_UNUSED
+ = { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x00 } } };
-static const uint8_t eth_addr_bfd[ETH_ADDR_LEN] OVS_UNUSED
- = { 0x00, 0x23, 0x20, 0x00, 0x00, 0x01 };
+static const struct eth_addr eth_addr_lacp OVS_UNUSED
+ = { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x02 } } };
-static inline bool eth_addr_is_broadcast(const uint8_t ea[ETH_ADDR_LEN])
+static const struct eth_addr eth_addr_bfd OVS_UNUSED
+ = { { { 0x00, 0x23, 0x20, 0x00, 0x00, 0x01 } } };
+
+static inline bool eth_addr_is_broadcast(const struct eth_addr a)
{
- return (ea[0] & ea[1] & ea[2] & ea[3] & ea[4] & ea[5]) == 0xff;
+ return (a.be16[0] & a.be16[1] & a.be16[2]) == htons(0xffff);
}
-static inline bool eth_addr_is_multicast(const uint8_t ea[ETH_ADDR_LEN])
+static inline bool eth_addr_is_multicast(const struct eth_addr a)
{
- return ea[0] & 1;
+ return a.ea[0] & 1;
}
-static inline bool eth_addr_is_local(const uint8_t ea[ETH_ADDR_LEN])
+
+static inline bool eth_addr_is_local(const struct eth_addr a)
{
/* 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);
+ return a.ea[0] & 2
+ || (a.be16[0] == htons(0x0023)
+ && (a.be16[1] & htons(0xff80)) == htons(0x2080));
}
-static inline bool eth_addr_is_zero(const uint8_t ea[ETH_ADDR_LEN])
+static inline bool eth_addr_is_zero(const struct eth_addr a)
{
- return !(ea[0] | ea[1] | ea[2] | ea[3] | ea[4] | ea[5]);
+ return !(a.be16[0] | a.be16[1] | a.be16[2]);
}
-static inline int eth_mask_is_exact(const uint8_t ea[ETH_ADDR_LEN])
+static inline int eth_mask_is_exact(const struct eth_addr a)
{
- return (ea[0] & ea[1] & ea[2] & ea[3] & ea[4] & ea[5]) == 0xff;
+ return (a.be16[0] & a.be16[1] & a.be16[2]) == htons(0xffff);
}
-static inline int eth_addr_compare_3way(const uint8_t a[ETH_ADDR_LEN],
- const uint8_t b[ETH_ADDR_LEN])
+static inline int eth_addr_compare_3way(const struct eth_addr a,
+ const struct eth_addr b)
{
- return memcmp(a, b, ETH_ADDR_LEN);
+ return memcmp(&a, &b, sizeof a);
}
-static inline bool eth_addr_equals(const uint8_t a[ETH_ADDR_LEN],
- const uint8_t b[ETH_ADDR_LEN])
+
+static inline bool eth_addr_equals(const struct eth_addr a,
+ const struct eth_addr b)
{
return !eth_addr_compare_3way(a, b);
}
-static inline bool eth_addr_equal_except(const uint8_t a[ETH_ADDR_LEN],
- const uint8_t b[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN])
+
+static inline bool eth_addr_equal_except(const struct eth_addr a,
+ const struct eth_addr b,
+ const struct eth_addr mask)
{
- return !(((a[0] ^ b[0]) & mask[0])
- || ((a[1] ^ b[1]) & mask[1])
- || ((a[2] ^ b[2]) & mask[2])
- || ((a[3] ^ b[3]) & mask[3])
- || ((a[4] ^ b[4]) & mask[4])
- || ((a[5] ^ b[5]) & mask[5]));
+ return !(((a.be16[0] ^ b.be16[0]) & mask.be16[0])
+ || ((a.be16[1] ^ b.be16[1]) & mask.be16[1])
+ || ((a.be16[2] ^ b.be16[2]) & mask.be16[2]));
}
-static inline uint64_t eth_addr_to_uint64(const uint8_t ea[ETH_ADDR_LEN])
+
+static inline uint64_t eth_addr_to_uint64(const struct eth_addr ea)
{
- return (((uint64_t) ea[0] << 40)
- | ((uint64_t) ea[1] << 32)
- | ((uint64_t) ea[2] << 24)
- | ((uint64_t) ea[3] << 16)
- | ((uint64_t) ea[4] << 8)
- | ea[5]);
+ return (((uint64_t) ntohs(ea.be16[0]) << 32)
+ | ((uint64_t) ntohs(ea.be16[1]) << 16)
+ | ntohs(ea.be16[2]));
}
-static inline uint64_t eth_addr_vlan_to_uint64(const uint8_t ea[ETH_ADDR_LEN],
+
+static inline uint64_t eth_addr_vlan_to_uint64(const struct eth_addr ea,
uint16_t vlan)
{
return (((uint64_t)vlan << 48) | eth_addr_to_uint64(ea));
}
-static inline void eth_addr_from_uint64(uint64_t x, uint8_t ea[ETH_ADDR_LEN])
+
+static inline void eth_addr_from_uint64(uint64_t x, struct eth_addr *ea)
+{
+ ea->be16[0] = htons(x >> 32);
+ ea->be16[1] = htons(x >> 16);
+ ea->be16[2] = htons(x);
+}
+
+static inline struct eth_addr eth_addr_invert(const struct eth_addr src)
{
- ea[0] = x >> 40;
- ea[1] = x >> 32;
- ea[2] = x >> 24;
- ea[3] = x >> 16;
- ea[4] = x >> 8;
- ea[5] = x;
+ struct eth_addr dst;
+
+ for (int i = 0; i < ARRAY_SIZE(src.be16); i++) {
+ dst.be16[i] = ~src.be16[i];
+ }
+
+ return dst;
}
-static inline void eth_addr_mark_random(uint8_t ea[ETH_ADDR_LEN])
+
+static inline void eth_addr_mark_random(struct eth_addr *ea)
{
- ea[0] &= ~1; /* Unicast. */
- ea[0] |= 2; /* Private. */
+ ea->ea[0] &= ~1; /* Unicast. */
+ ea->ea[0] |= 2; /* Private. */
}
-static inline void eth_addr_random(uint8_t ea[ETH_ADDR_LEN])
+
+static inline void eth_addr_random(struct eth_addr *ea)
{
- random_bytes(ea, ETH_ADDR_LEN);
+ random_bytes((uint8_t *)ea, sizeof *ea);
eth_addr_mark_random(ea);
}
-static inline void eth_addr_nicira_random(uint8_t ea[ETH_ADDR_LEN])
+
+static inline void eth_addr_nicira_random(struct eth_addr *ea)
{
eth_addr_random(ea);
/* Set the OUI to the Nicira one. */
- ea[0] = 0x00;
- ea[1] = 0x23;
- ea[2] = 0x20;
+ ea->ea[0] = 0x00;
+ ea->ea[1] = 0x23;
+ ea->ea[2] = 0x20;
/* Set the top bit to indicate random Nicira address. */
- ea[3] |= 0x80;
+ ea->ea[3] |= 0x80;
}
-static inline uint32_t hash_mac(const uint8_t ea[ETH_ADDR_LEN],
+static inline uint32_t hash_mac(const struct eth_addr ea,
const uint16_t vlan, const uint32_t basis)
{
return hash_uint64_basis(eth_addr_vlan_to_uint64(ea, vlan), basis);
}
-bool eth_addr_is_reserved(const uint8_t ea[ETH_ADDR_LEN]);
-bool eth_addr_from_string(const char *, uint8_t ea[ETH_ADDR_LEN]);
+bool eth_addr_is_reserved(const struct eth_addr);
+bool eth_addr_from_string(const char *, struct eth_addr *);
-void compose_rarp(struct dp_packet *, const uint8_t eth_src[ETH_ADDR_LEN]);
+void compose_rarp(struct dp_packet *, const struct eth_addr);
void eth_push_vlan(struct dp_packet *, ovs_be16 tpid, ovs_be16 tci);
void eth_pop_vlan(struct dp_packet *);
const char *eth_from_hex(const char *hex, struct dp_packet **packetp);
-void eth_format_masked(const uint8_t eth[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN], struct ds *s);
-void eth_addr_bitand(const uint8_t src[ETH_ADDR_LEN],
- const uint8_t mask[ETH_ADDR_LEN],
- uint8_t dst[ETH_ADDR_LEN]);
+void eth_format_masked(const struct eth_addr ea,
+ const struct eth_addr *mask, struct ds *s);
void set_mpls_lse(struct dp_packet *, ovs_be32 label);
void push_mpls(struct dp_packet *packet, ovs_be16 ethtype, ovs_be32 lse);
/* Example:
*
- * uint8_t mac[ETH_ADDR_LEN];
+ * struct eth_addr mac;
* [...]
* printf("The Ethernet address is "ETH_ADDR_FMT"\n", ETH_ADDR_ARGS(mac));
*
*/
#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_ADDR_ARGS(EA) \
+ (EA).ea[0], (EA).ea[1], (EA).ea[2], (EA).ea[3], (EA).ea[4], (EA).ea[5]
/* Example:
*
* char *string = "1 00:11:22:33:44:55 2";
- * uint8_t mac[ETH_ADDR_LEN];
+ * struct eth_addr mac;
* int a, b;
*
* if (ovs_scan(string, "%d"ETH_ADDR_SCAN_FMT"%d",
* }
*/
#define ETH_ADDR_SCAN_FMT "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8
-#define ETH_ADDR_SCAN_ARGS(ea) \
- &(ea)[0], &(ea)[1], &(ea)[2], &(ea)[3], &(ea)[4], &(ea)[5]
+#define ETH_ADDR_SCAN_ARGS(EA) \
+ &(EA).ea[0], &(EA).ea[1], &(EA).ea[2], &(EA).ea[3], &(EA).ea[4], &(EA).ea[5]
#define ETH_TYPE_IP 0x0800
#define ETH_TYPE_ARP 0x0806
#define ETH_VLAN_TOTAL_MAX (ETH_HEADER_LEN + VLAN_HEADER_LEN + ETH_PAYLOAD_MAX)
OVS_PACKED(
struct eth_header {
- uint8_t eth_dst[ETH_ADDR_LEN];
- uint8_t eth_src[ETH_ADDR_LEN];
+ struct eth_addr eth_dst;
+ struct eth_addr eth_src;
ovs_be16 eth_type;
});
BUILD_ASSERT_DECL(ETH_HEADER_LEN == sizeof(struct eth_header));
#define VLAN_ETH_HEADER_LEN (ETH_HEADER_LEN + VLAN_HEADER_LEN)
OVS_PACKED(
struct vlan_eth_header {
- uint8_t veth_dst[ETH_ADDR_LEN];
- uint8_t veth_src[ETH_ADDR_LEN];
+ struct eth_addr veth_dst;
+ struct eth_addr veth_src;
ovs_be16 veth_type; /* Always htons(ETH_TYPE_VLAN). */
ovs_be16 veth_tci; /* Lowest 12 bits are VLAN ID. */
ovs_be16 veth_next_type;
ovs_be16 ar_op; /* Opcode. */
/* Ethernet+IPv4 specific members. */
- uint8_t ar_sha[ETH_ADDR_LEN]; /* Sender hardware address. */
- ovs_16aligned_be32 ar_spa; /* Sender protocol address. */
- uint8_t ar_tha[ETH_ADDR_LEN]; /* Target hardware address. */
- ovs_16aligned_be32 ar_tpa; /* Target protocol address. */
+ struct eth_addr ar_sha; /* Sender hardware address. */
+ ovs_16aligned_be32 ar_spa; /* Sender protocol address. */
+ struct eth_addr ar_tha; /* Target hardware address. */
+ ovs_16aligned_be32 ar_tpa; /* Target protocol address. */
};
BUILD_ASSERT_DECL(ARP_ETH_HEADER_LEN == sizeof(struct arp_eth_header));
struct ovs_nd_opt {
uint8_t nd_opt_type; /* Values defined in icmp6.h */
uint8_t nd_opt_len; /* in units of 8 octets (the size of this struct) */
- uint8_t nd_opt_data[6]; /* Ethernet address in the case of SLL or TLL options */
+ struct eth_addr nd_opt_mac; /* Ethernet address in the case of SLL or TLL options */
};
BUILD_ASSERT_DECL(ND_OPT_LEN == sizeof(struct ovs_nd_opt));
int ipv6_count_cidr_bits(const struct in6_addr *netmask);
bool ipv6_is_cidr(const struct in6_addr *netmask);
-void *eth_compose(struct dp_packet *, const uint8_t eth_dst[ETH_ADDR_LEN],
- const uint8_t eth_src[ETH_ADDR_LEN], uint16_t eth_type,
+void *eth_compose(struct dp_packet *, const struct eth_addr eth_dst,
+ const struct eth_addr eth_src, uint16_t eth_type,
size_t size);
-void *snap_compose(struct dp_packet *, const uint8_t eth_dst[ETH_ADDR_LEN],
- const uint8_t eth_src[ETH_ADDR_LEN],
+void *snap_compose(struct dp_packet *, const struct eth_addr eth_dst,
+ const struct eth_addr eth_src,
unsigned int oui, uint16_t snap_type, size_t size);
void packet_set_ipv4(struct dp_packet *, ovs_be32 src, ovs_be32 dst, uint8_t tos,
uint8_t ttl);
void packet_set_udp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
void packet_set_sctp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
void packet_set_nd(struct dp_packet *, const ovs_be32 target[4],
- const uint8_t sll[6], const uint8_t tll[6]);
+ const struct eth_addr sll, const struct eth_addr tll);
void packet_format_tcp_flags(struct ds *, uint16_t);
const char *packet_tcp_flag_to_string(uint32_t flag);
void compose_arp(struct dp_packet *, uint16_t arp_op,
- const uint8_t arp_sha[ETH_ADDR_LEN],
- const uint8_t arp_tha[ETH_ADDR_LEN], bool broadcast,
+ const struct eth_addr arp_sha,
+ const struct eth_addr arp_tha, bool broadcast,
ovs_be32 arp_spa, ovs_be32 arp_tpa);
uint32_t packet_csum_pseudoheader(const struct ip_header *);
dp_packet_set_l3(pkt, dp_packet_put(pkt, bpdu, bpdu_size));
/* 802.2 header. */
- memcpy(eth->eth_dst, eth_addr_stp, ETH_ADDR_LEN);
+ eth->eth_dst = eth_addr_stp;
/* p->rstp->send_bpdu() must fill in source address. */
eth->eth_type = htons(dp_packet_size(pkt) - ETH_HEADER_LEN);
: 0);
if (attrs[IFLA_ADDRESS] &&
- nl_attr_get_size(attrs[IFLA_ADDRESS]) == ETH_ALEN) {
- memcpy(change->addr, nl_attr_get(attrs[IFLA_ADDRESS]),
- ETH_ALEN);
+ nl_attr_get_size(attrs[IFLA_ADDRESS]) == ETH_ADDR_LEN) {
+ memcpy(&change->mac, nl_attr_get(attrs[IFLA_ADDRESS]),
+ ETH_ADDR_LEN);
} else {
- memset(change->addr, 0, ETH_ALEN);
+ memset(&change->mac, 0, ETH_ADDR_LEN);
}
}
} else if (rtnetlink_type_is_rtnlgrp_addr(nlmsg->nlmsg_type)) {
#include <stdint.h>
#include <linux/if_ether.h>
+#include "openvswitch/types.h"
+
struct ofpbuf;
struct nln_notifier;
/* Network device link status. */
int master_ifindex; /* Ifindex of datapath master (0 if none). */
int mtu; /* Current MTU. */
- uint8_t addr[ETH_ALEN];
+ struct eth_addr mac;
unsigned int ifi_flags; /* Flags of network device. */
/* Network device address status. */
#include "windefs.h"
#endif
+#include "openvswitch/types.h"
+
typedef enum {
SFL_DSCLASS_IFINDEX = 0,
SFL_DSCLASS_VLAN = 1,
typedef struct _SFLSampled_ethernet {
u_int32_t eth_len; /* The length of the MAC packet excluding
lower layer encapsulations */
- u_int8_t src_mac[8]; /* 6 bytes + 2 pad */
- u_int8_t dst_mac[8];
+ struct eth_addr src_mac; /* 6 bytes */
+ u_int8_t pad1[2]; /* 2 pad */
+ struct eth_addr dst_mac;
+ u_int8_t pad2[2];
u_int32_t eth_type;
} SFLSampled_ethernet;
} SFLLACP_portState;
typedef struct _SFLLACP_counters {
- uint8_t actorSystemID[8]; /* 6 bytes + 2 pad */
- uint8_t partnerSystemID[8]; /* 6 bytes + 2 pad */
+ struct eth_addr actorSystemID; /* 6 bytes */
+ uint8_t pad1[2];
+ struct eth_addr partnerSystemID; /* 6 bytes */
+ uint8_t pad2[2];
uint32_t attachedAggID;
SFLLACP_portState portState;
uint32_t LACPDUsRx;
return (addr->type == SFLADDRESSTYPE_IP_V6) ? 20 : 8; // type + address (unspecified == IPV4)
}
-inline static void putMACAddress(SFLReceiver *receiver, u_int8_t *mac)
+inline static void putMACAddress(SFLReceiver *receiver,
+ const struct eth_addr mac)
{
- memcpy(receiver->sampleCollector.datap, mac, 6);
+ memcpy(receiver->sampleCollector.datap, &mac, 6);
receiver->sampleCollector.datap += 2;
}
dp_packet_set_l3(pkt, dp_packet_put(pkt, bpdu, bpdu_size));
/* 802.2 header. */
- memcpy(eth->eth_dst, eth_addr_stp, ETH_ADDR_LEN);
+ eth->eth_dst = eth_addr_stp;
/* p->stp->send_bpdu() must fill in source address. */
eth->eth_type = htons(dp_packet_size(pkt) - ETH_HEADER_LEN);
struct tnl_arp_entry {
struct cmap_node cmap_node;
ovs_be32 ip;
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
time_t expires; /* Expiration time. */
char br_name[IFNAMSIZ];
};
int
tnl_arp_lookup(const char br_name[IFNAMSIZ], ovs_be32 dst,
- uint8_t mac[ETH_ADDR_LEN])
+ struct eth_addr *mac)
{
struct tnl_arp_entry *arp;
int res = ENOENT;
arp = tnl_arp_lookup__(br_name, dst);
if (arp) {
- memcpy(mac, arp->mac, ETH_ADDR_LEN);
+ *mac = arp->mac;
res = 0;
}
ovs_mutex_lock(&mutex);
arp = tnl_arp_lookup__(name, flow->nw_src);
if (arp) {
- if (!memcmp(arp->mac, flow->arp_sha, ETH_ADDR_LEN)) {
+ if (eth_addr_equals(arp->mac, flow->arp_sha)) {
arp->expires = time_now() + ARP_ENTRY_DEFAULT_IDLE_TIME;
ovs_mutex_unlock(&mutex);
return 0;
arp = xmalloc(sizeof *arp);
arp->ip = flow->nw_src;
- memcpy(arp->mac, flow->arp_sha, ETH_ADDR_LEN);
+ arp->mac = flow->arp_sha;
arp->expires = time_now() + ARP_ENTRY_DEFAULT_IDLE_TIME;
ovs_strlcpy(arp->br_name, name, sizeof arp->br_name);
cmap_insert(&table, &arp->cmap_node, (OVS_FORCE uint32_t) arp->ip);
int tnl_arp_snoop(const struct flow *flow, struct flow_wildcards *wc,
const char dev_name[]);
-int tnl_arp_lookup(const char dev_name[], ovs_be32 dst, uint8_t mac[ETH_ADDR_LEN]);
+int tnl_arp_lookup(const char dev_name[], ovs_be32 dst, struct eth_addr *mac);
void tnl_arp_cache_init(void);
void tnl_arp_cache_run(void);
/* Interface name may not be persistent across an OS reboot, use
* MAC address for identifing the active slave */
- uint8_t active_slave_mac[ETH_ADDR_LEN];
+ struct eth_addr active_slave_mac;
/* The MAC address of the active interface. */
/* Legacy compatibility. */
bool lacp_fallback_ab; /* Fallback to active-backup on LACP failure. */
OVS_REQ_WRLOCK(rwlock);
static void bond_choose_active_slave(struct bond *)
OVS_REQ_WRLOCK(rwlock);
-static unsigned int bond_hash_src(const uint8_t mac[ETH_ADDR_LEN],
+static unsigned int bond_hash_src(const struct eth_addr mac,
uint16_t vlan, uint32_t basis);
static unsigned int bond_hash_tcp(const struct flow *, uint16_t vlan,
uint32_t basis);
bond_entry_reset(bond);
}
- memcpy(bond->active_slave_mac, s->active_slave_mac,
- sizeof s->active_slave_mac);
-
+ bond->active_slave_mac = s->active_slave_mac;
bond->active_slave_changed = false;
ovs_rwlock_unlock(&rwlock);
}
static struct bond_slave *
-bond_find_slave_by_mac(const struct bond *bond, const uint8_t mac[ETH_ADDR_LEN])
+bond_find_slave_by_mac(const struct bond *bond, const struct eth_addr mac)
{
struct bond_slave *slave;
/* Find the last active slave */
HMAP_FOR_EACH(slave, hmap_node, &bond->slaves) {
- uint8_t slave_mac[ETH_ADDR_LEN];
+ struct eth_addr slave_mac;
- if (netdev_get_etheraddr(slave->netdev, slave_mac)) {
+ if (netdev_get_etheraddr(slave->netdev, &slave_mac)) {
continue;
}
- if (!memcmp(slave_mac, mac, sizeof(slave_mac))) {
+ if (eth_addr_equals(slave_mac, mac)) {
return slave;
}
}
static void
bond_active_slave_changed(struct bond *bond)
{
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
- netdev_get_etheraddr(bond->active_slave->netdev, mac);
- memcpy(bond->active_slave_mac, mac, sizeof bond->active_slave_mac);
+ netdev_get_etheraddr(bond->active_slave->netdev, &mac);
+ bond->active_slave_mac = mac;
bond->active_slave_changed = true;
seq_change(connectivity_seq_get());
}
* caller should send the composed packet on the port associated with
* port_aux and takes ownership of the returned ofpbuf. */
struct dp_packet *
-bond_compose_learning_packet(struct bond *bond,
- const uint8_t eth_src[ETH_ADDR_LEN],
+bond_compose_learning_packet(struct bond *bond, const struct eth_addr eth_src,
uint16_t vlan, void **port_aux)
{
struct bond_slave *slave;
ovs_rwlock_rdlock(&rwlock);
ovs_assert(may_send_learning_packets(bond));
memset(&flow, 0, sizeof flow);
- memcpy(flow.dl_src, eth_src, ETH_ADDR_LEN);
+ flow.dl_src = eth_src;
slave = choose_output_slave(bond, &flow, NULL, vlan);
packet = dp_packet_new(0);
*/
enum bond_verdict
bond_check_admissibility(struct bond *bond, const void *slave_,
- const uint8_t eth_dst[ETH_ADDR_LEN])
+ const struct eth_addr eth_dst)
{
enum bond_verdict verdict = BV_DROP;
struct bond_slave *slave;
const char *mac_s = argv[1];
const char *vlan_s = argc > 2 ? argv[2] : NULL;
const char *basis_s = argc > 3 ? argv[3] : NULL;
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
uint8_t hash;
char *hash_cstr;
unsigned int vlan;
}
static unsigned int
-bond_hash_src(const uint8_t mac[ETH_ADDR_LEN], uint16_t vlan, uint32_t basis)
+bond_hash_src(const struct eth_addr mac, uint16_t vlan, uint32_t basis)
{
return hash_mac(mac, vlan, basis);
}
* If return true, 'mac' will store the bond's current active slave's
* MAC address. */
bool
-bond_get_changed_active_slave(const char *name, uint8_t* mac, bool force)
+bond_get_changed_active_slave(const char *name, struct eth_addr *mac,
+ bool force)
{
struct bond *bond;
bond = bond_find(name);
if (bond) {
if (bond->active_slave_changed || force) {
- memcpy(mac, bond->active_slave_mac, ETH_ADDR_LEN);
+ *mac = bond->active_slave_mac;
bond->active_slave_changed = false;
ovs_rwlock_unlock(&rwlock);
return true;
bool lacp_fallback_ab_cfg; /* Fallback to active-backup on LACP failure. */
- uint8_t active_slave_mac[ETH_ADDR_LEN];
+ struct eth_addr active_slave_mac;
/* The MAC address of the interface
that was active during the last
ovs run. */
/* Special MAC learning support for SLB bonding. */
bool bond_should_send_learning_packets(struct bond *);
struct dp_packet *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[ETH_ADDR_LEN],
+ const struct eth_addr eth_src,
+ uint16_t vlan, void **port_aux);
+bool bond_get_changed_active_slave(const char *name, struct eth_addr *mac,
bool force);
/* Packet processing. */
BV_DROP_IF_MOVED /* Drop if we've learned a different port. */
};
enum bond_verdict bond_check_admissibility(struct bond *, const void *slave_,
- const uint8_t dst[ETH_ADDR_LEN]);
+ const struct eth_addr dst);
void *bond_choose_output_slave(struct bond *, const struct flow *,
struct flow_wildcards *, uint16_t vlan);
send_bogus_packet_ins(struct fail_open *fo)
{
struct ofproto_packet_in pin;
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
struct dp_packet b;
dp_packet_init(&b, 128);
- eth_addr_nicira_random(mac);
+ eth_addr_nicira_random(&mac);
compose_rarp(&b, mac);
memset(&pin, 0, sizeof pin);
/* Track one remote IP and next hop information. */
struct in_band_remote {
- struct sockaddr_in remote_addr; /* IP address, in network byte order. */
- uint8_t remote_mac[ETH_ADDR_LEN]; /* Next-hop MAC, all-zeros if unknown. */
- uint8_t last_remote_mac[ETH_ADDR_LEN]; /* Previous nonzero next-hop MAC. */
- struct netdev *remote_netdev; /* Device to send to next-hop MAC. */
+ struct sockaddr_in remote_addr; /* IP address, in network byte order. */
+ struct eth_addr remote_mac; /* Next-hop MAC, all-zeros if unknown. */
+ struct eth_addr last_remote_mac; /* Previous nonzero next-hop MAC. */
+ struct netdev *remote_netdev; /* Device to send to next-hop MAC. */
};
/* What to do to an in_band_rule. */
/* Local information. */
time_t next_local_refresh; /* Refresh timer. */
- uint8_t local_mac[ETH_ADDR_LEN]; /* Current MAC. */
+ struct eth_addr local_mac; /* Current MAC. */
struct netdev *local_netdev; /* Local port's network device. */
/* Flow tracking. */
int retval;
/* Find the next-hop IP address. */
- memset(r->remote_mac, 0, sizeof r->remote_mac);
+ r->remote_mac = eth_addr_zero;
retval = netdev_get_next_hop(ib->local_netdev, &r->remote_addr.sin_addr,
&next_hop_inaddr, &next_hop_dev);
if (retval) {
/* Look up the MAC address of the next-hop IP address. */
retval = netdev_arp_lookup(r->remote_netdev, next_hop_inaddr.s_addr,
- r->remote_mac);
+ &r->remote_mac);
if (retval) {
VLOG_DBG_RL(&rl, "%s: cannot look up remote MAC address ("IP_FMT"): %s",
ib->ofproto->name, IP_ARGS(next_hop_inaddr.s_addr),
any_changes = false;
ib->next_remote_refresh = TIME_MAX;
for (r = ib->remotes; r < &ib->remotes[ib->n_remotes]; r++) {
- uint8_t old_remote_mac[ETH_ADDR_LEN];
+ struct eth_addr old_remote_mac;
time_t next_refresh;
/* Save old MAC. */
- memcpy(old_remote_mac, r->remote_mac, ETH_ADDR_LEN);
+ old_remote_mac = r->remote_mac;
/* Refresh remote information. */
next_refresh = refresh_remote(ib, r) + time_now();
ib->ofproto->name,
ETH_ADDR_ARGS(r->last_remote_mac),
ETH_ADDR_ARGS(r->remote_mac));
- memcpy(r->last_remote_mac, r->remote_mac, ETH_ADDR_LEN);
+ r->last_remote_mac = r->remote_mac;
}
}
}
static bool
refresh_local(struct in_band *ib)
{
- uint8_t ea[ETH_ADDR_LEN];
+ struct eth_addr ea;
time_t now;
now = time_now();
}
ib->next_local_refresh = now + 1;
- if (netdev_get_etheraddr(ib->local_netdev, ea)
+ if (netdev_get_etheraddr(ib->local_netdev, &ea)
|| eth_addr_equals(ea, ib->local_mac)) {
return false;
}
- memcpy(ib->local_mac, ea, ETH_ADDR_LEN);
+ ib->local_mac = ea;
return true;
}
}
for (r = ib->remotes; r < &ib->remotes[ib->n_remotes]; r++) {
- const uint8_t *remote_mac = r->remote_mac;
-
- if (eth_addr_is_zero(remote_mac)) {
+ if (eth_addr_is_zero(r->remote_mac)) {
continue;
}
/* (d) Allow ARP replies to the next hop's MAC address. */
match_init_catchall(&match);
match_set_dl_type(&match, htons(ETH_TYPE_ARP));
- match_set_dl_dst(&match, remote_mac);
+ match_set_dl_dst(&match, r->remote_mac);
match_set_nw_proto(&match, ARP_OP_REPLY);
add_rule(ib, &match, IBR_TO_NEXT_HOP_ARP);
/* (e) Allow ARP requests from the next hop's MAC address. */
match_init_catchall(&match);
match_set_dl_type(&match, htons(ETH_TYPE_ARP));
- match_set_dl_src(&match, remote_mac);
+ match_set_dl_src(&match, r->remote_mac);
match_set_nw_proto(&match, ARP_OP_REQUEST);
add_rule(ib, &match, IBR_FROM_NEXT_HOP_ARP);
}
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[ETH_ADDR_LEN]; /* SOURCE_MAC_ADDRESS */
- uint8_t destination_mac_address[ETH_ADDR_LEN]; /* DESTINATION_MAC_ADDRESS */
+ struct eth_addr source_mac_address; /* SOURCE_MAC_ADDRESS */
+ struct eth_addr destination_mac_address; /* DESTINATION_MAC_ADDRESS */
ovs_be16 ethernet_type; /* ETHERNET_TYPE */
uint8_t ethernet_header_length; /* ETHERNET_HEADER_LENGTH */
});
data_common->observation_point_id = htonl(obs_point_id);
data_common->flow_direction =
(output_odp_port == ODPP_NONE) ? INGRESS_FLOW : EGRESS_FLOW;
- memcpy(data_common->source_mac_address, flow->dl_src,
- sizeof flow->dl_src);
- memcpy(data_common->destination_mac_address, flow->dl_dst,
- sizeof flow->dl_dst);
+ data_common->source_mac_address = flow->dl_src;
+ data_common->destination_mac_address = flow->dl_dst;
data_common->ethernet_type = flow->dl_type;
data_common->ethernet_header_length = ethernet_header_length;
}
struct cfm *cfm; /* Reference to cfm. */
struct bfd *bfd; /* Reference to bfd. */
struct lldp *lldp; /* Reference to lldp. */
- uint8_t hw_addr[OFP_ETH_ALEN]; /* Hardware address. */
+ struct eth_addr hw_addr; /* Hardware address. */
};
/* Entry of the 'send_soon' list. Contains the pointer to the
static void monitor_mport_run(struct mport *, struct dp_packet *);
static void mport_register(const struct ofport_dpif *, struct bfd *,
- struct cfm *, struct lldp *, uint8_t[ETH_ADDR_LEN])
+ struct cfm *, struct lldp *,
+ const struct eth_addr *)
OVS_REQUIRES(monitor_mutex);
static void mport_unregister(const struct ofport_dpif *)
OVS_REQUIRES(monitor_mutex);
static void mport_update(struct mport *, struct bfd *, struct cfm *,
- struct lldp *, uint8_t[ETH_ADDR_LEN])
+ struct lldp *, const struct eth_addr *)
OVS_REQUIRES(monitor_mutex);
static struct mport *mport_find(const struct ofport_dpif *)
OVS_REQUIRES(monitor_mutex);
* if it doesn't exist. Otherwise, just updates its fields. */
static void
mport_register(const struct ofport_dpif *ofport, struct bfd *bfd,
- struct cfm *cfm, struct lldp *lldp, uint8_t *hw_addr)
+ struct cfm *cfm, struct lldp *lldp,
+ const struct eth_addr *hw_addr)
OVS_REQUIRES(monitor_mutex)
{
struct mport *mport = mport_find(ofport);
/* Updates the fields of an existing mport struct. */
static void
mport_update(struct mport *mport, struct bfd *bfd, struct cfm *cfm,
- struct lldp *lldp, uint8_t hw_addr[ETH_ADDR_LEN])
+ struct lldp *lldp, const struct eth_addr *hw_addr)
OVS_REQUIRES(monitor_mutex)
{
ovs_assert(mport);
lldp_unref(mport->lldp);
mport->lldp = lldp_ref(lldp);
}
- if (hw_addr && memcmp(mport->hw_addr, hw_addr, ETH_ADDR_LEN)) {
- memcpy(mport->hw_addr, hw_addr, ETH_ADDR_LEN);
+ if (hw_addr && !eth_addr_equals(mport->hw_addr, *hw_addr)) {
+ mport->hw_addr = *hw_addr;
}
/* If bfd/cfm/lldp is added or reconfigured, move the mport on top of the heap
* so that the monitor thread can run the mport next time it wakes up. */
ofproto_dpif_monitor_port_update(const struct ofport_dpif *ofport,
struct bfd *bfd, struct cfm *cfm,
struct lldp *lldp,
- uint8_t hw_addr[ETH_ADDR_LEN])
+ const struct eth_addr *hw_addr)
{
ovs_mutex_lock(&monitor_mutex);
if (!cfm && !bfd && !lldp) {
void ofproto_dpif_monitor_port_update(const struct ofport_dpif *,
struct bfd *, struct cfm *,
- struct lldp *, uint8_t[OFP_ETH_ALEN]);
+ struct lldp *, const struct eth_addr *);
#endif /* ofproto-dpif-monitor.h */
if (ofproto_port_get_lacp_stats(dsp->ofport, &lacp_stats) == 0) {
memset(&lacp_elem, 0, sizeof lacp_elem);
lacp_elem.tag = SFLCOUNTERS_LACP;
- memcpy(&lacp_elem.counterBlock.lacp.actorSystemID,
- lacp_stats.dot3adAggPortActorSystemID,
- ETH_ADDR_LEN);
- memcpy(&lacp_elem.counterBlock.lacp.partnerSystemID,
- lacp_stats.dot3adAggPortPartnerOperSystemID,
- ETH_ADDR_LEN);
+ lacp_elem.counterBlock.lacp.actorSystemID =
+ lacp_stats.dot3adAggPortActorSystemID;
+ lacp_elem.counterBlock.lacp.partnerSystemID =
+ lacp_stats.dot3adAggPortPartnerOperSystemID;
lacp_elem.counterBlock.lacp.attachedAggID =
lacp_stats.dot3adAggPortAttachedAggID;
lacp_elem.counterBlock.lacp.portState.v.actorAdmin =
}
static void
-tnl_send_arp_request(const struct xport *out_dev, const uint8_t eth_src[ETH_ADDR_LEN],
+tnl_send_arp_request(const struct xport *out_dev,
+ const struct eth_addr eth_src,
ovs_be32 ip_src, ovs_be32 ip_dst)
{
struct xbridge *xbridge = out_dev->xbridge;
struct ovs_action_push_tnl tnl_push_data;
struct xport *out_dev = NULL;
ovs_be32 s_ip, d_ip = 0;
- uint8_t smac[ETH_ADDR_LEN];
- uint8_t dmac[ETH_ADDR_LEN];
+ struct eth_addr smac;
+ struct eth_addr dmac;
int err;
err = tnl_route_lookup_flow(flow, &d_ip, &out_dev);
IP_ARGS(d_ip), netdev_get_name(out_dev->netdev));
/* Use mac addr of bridge port of the peer. */
- err = netdev_get_etheraddr(out_dev->netdev, smac);
+ err = netdev_get_etheraddr(out_dev->netdev, &smac);
if (err) {
xlate_report(ctx, "tunnel output device lacks Ethernet address");
return err;
return err;
}
- err = tnl_arp_lookup(out_dev->xbridge->name, d_ip, dmac);
+ err = tnl_arp_lookup(out_dev->xbridge->name, d_ip, &dmac);
if (err) {
xlate_report(ctx, "ARP cache miss for "IP_FMT" on bridge %s, "
"sending ARP request",
break;
case OFPACT_SET_ETH_SRC:
- memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
- memcpy(flow->dl_src, ofpact_get_SET_ETH_SRC(a)->mac, ETH_ADDR_LEN);
+ WC_MASK_FIELD(wc, dl_src);
+ flow->dl_src = ofpact_get_SET_ETH_SRC(a)->mac;
break;
case OFPACT_SET_ETH_DST:
- memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
- memcpy(flow->dl_dst, ofpact_get_SET_ETH_DST(a)->mac, ETH_ADDR_LEN);
+ WC_MASK_FIELD(wc, dl_dst);
+ flow->dl_dst = ofpact_get_SET_ETH_DST(a)->mac;
break;
case OFPACT_SET_IPV4_SRC:
{
struct xc_entry *entry;
struct ofpbuf entries = xcache->entries;
- uint8_t dmac[ETH_ADDR_LEN];
+ struct eth_addr dmac;
if (!stats->n_packets) {
return;
break;
case XC_TNL_ARP:
/* Lookup arp to avoid arp timeout. */
- tnl_arp_lookup(entry->u.tnl_arp_cache.br_name, entry->u.tnl_arp_cache.d_ip, dmac);
+ tnl_arp_lookup(entry->u.tnl_arp_cache.br_name,
+ entry->u.tnl_arp_cache.d_ip, &dmac);
break;
default:
OVS_NOT_REACHED();
}
ofproto_dpif_monitor_port_update(port, port->bfd, port->cfm,
- port->lldp, port->up.pp.hw_addr);
+ port->lldp, &port->up.pp.hw_addr);
dp_port_name = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf);
ofproto->backer->need_revalidate = REV_RECONFIGURE;
}
ofproto_dpif_monitor_port_update(ofport, ofport->bfd, ofport->cfm,
- ofport->lldp, ofport->up.pp.hw_addr);
+ ofport->lldp, &ofport->up.pp.hw_addr);
return error;
}
ofproto->backer->need_revalidate = REV_RECONFIGURE;
}
ofproto_dpif_monitor_port_update(ofport, ofport->bfd, ofport->cfm,
- ofport->lldp, ofport->up.pp.hw_addr);
+ ofport->lldp, &ofport->up.pp.hw_addr);
return 0;
}
ofport->bfd,
ofport->cfm,
ofport->lldp,
- ofport->up.pp.hw_addr);
+ &ofport->up.pp.hw_addr);
return error;
}
struct ofport_dpif *ofport = ofport_;
struct eth_header *eth = dp_packet_l2(pkt);
- netdev_get_etheraddr(ofport->up.netdev, eth->eth_src);
+ netdev_get_etheraddr(ofport->up.netdev, ð->eth_src);
if (eth_addr_is_zero(eth->eth_src)) {
VLOG_WARN_RL(&rl, "%s port %d: cannot send RSTP BPDU on a port which "
"does not have a configured source MAC address.",
} else {
struct eth_header *eth = dp_packet_l2(pkt);
- netdev_get_etheraddr(ofport->up.netdev, eth->eth_src);
+ netdev_get_etheraddr(ofport->up.netdev, ð->eth_src);
if (eth_addr_is_zero(eth->eth_src)) {
VLOG_WARN_RL(&rl, "%s: cannot send BPDU on port %d "
"with unknown MAC", ofproto->up.name, port_num);
{
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 10);
struct ofport_dpif *port = port_;
- uint8_t ea[ETH_ADDR_LEN];
+ struct eth_addr ea;
int error;
- error = netdev_get_etheraddr(port->up.netdev, ea);
+ error = netdev_get_etheraddr(port->up.netdev, &ea);
if (!error) {
struct dp_packet packet;
void *packet_pdu;
}
}
pp->port_no = ofproto_port->ofp_port;
- netdev_get_etheraddr(netdev, pp->hw_addr);
+ netdev_get_etheraddr(netdev, &pp->hw_addr);
ovs_strlcpy(pp->name, ofproto_port->name, sizeof pp->name);
netdev_get_flags(netdev, &flags);
pp->config = flags & NETDEV_UP ? 0 : OFPUTIL_PC_PORT_DOWN;
static void
ofport_modified(struct ofport *port, struct ofputil_phy_port *pp)
{
- memcpy(port->pp.hw_addr, pp->hw_addr, ETH_ADDR_LEN);
+ port->pp.hw_addr = pp->hw_addr;
port->pp.config = ((port->pp.config & ~OFPUTIL_PC_PORT_DOWN)
| (pp->config & OFPUTIL_PC_PORT_DOWN));
port->pp.state = ((port->pp.state & ~OFPUTIL_PS_LINK_DOWN)
port = ofproto_get_port(ofproto, OFPP_LOCAL);
if (port) {
- uint8_t ea[ETH_ADDR_LEN];
+ struct eth_addr ea;
int error;
- error = netdev_get_etheraddr(port->netdev, ea);
+ error = netdev_get_etheraddr(port->netdev, &ea);
if (!error) {
return eth_addr_to_uint64(ea);
}
static uint64_t
pick_fallback_dpid(void)
{
- uint8_t ea[ETH_ADDR_LEN];
- eth_addr_nicira_random(ea);
+ struct eth_addr ea;
+ eth_addr_nicira_random(&ea);
return eth_addr_to_uint64(ea);
}
\f
int
tnl_port_build_header(const struct ofport_dpif *ofport,
const struct flow *tnl_flow,
- uint8_t dmac[ETH_ADDR_LEN],
- uint8_t smac[ETH_ADDR_LEN],
+ const struct eth_addr dmac,
+ const struct eth_addr smac,
ovs_be32 ip_src, struct ovs_action_push_tnl *data)
{
struct tnl_port *tnl_port;
memset(data->header, 0, sizeof data->header);
eth = (struct eth_header *)data->header;
- memcpy(eth->eth_dst, dmac, ETH_ADDR_LEN);
- memcpy(eth->eth_src, smac, ETH_ADDR_LEN);
+ eth->eth_dst = dmac;
+ eth->eth_src = smac;
eth->eth_type = htons(ETH_TYPE_IP);
l3 = (eth + 1);
int tnl_port_build_header(const struct ofport_dpif *ofport,
const struct flow *tnl_flow,
- uint8_t dmac[ETH_ADDR_LEN],
- uint8_t smac[ETH_ADDR_LEN],
+ const struct eth_addr dmac,
+ const struct eth_addr smac,
ovs_be32 ip_src, struct ovs_action_push_tnl *data);
#endif /* tunnel.h */
size_t len = end - start;
int n;
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
if (!len) {
lex_error(token, "Integer constant expected.");
&& ovs_scan(start, ETH_ADDR_SCAN_FMT"%n",
ETH_ADDR_SCAN_ARGS(mac), &n)
&& n == len) {
- memcpy(token->value.mac, mac, sizeof token->value.mac);
+ token->value.mac = mac;
token->format = LEX_F_ETHERNET;
} else if (start + strspn(start, "0123456789") == end) {
if (p[0] == '0' && len > 1) {
size_t n = 0;
for (size_t i = 0; i < n_port_security; i++) {
- uint8_t ea[ETH_ADDR_LEN];
+ struct eth_addr ea;
- if (eth_addr_from_string(port_security[i], ea)) {
+ if (eth_addr_from_string(port_security[i], &ea)) {
ds_put_format(match, ETH_ADDR_FMT, ETH_ADDR_ARGS(ea));
ds_put_char(match, ' ');
n++;
/* Ingress table 1: Destination lookup, unicast handling (priority 50), */
HMAP_FOR_EACH (op, key_node, ports) {
for (size_t i = 0; i < op->nb->n_macs; i++) {
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
- if (eth_addr_from_string(op->nb->macs[i], mac)) {
+ if (eth_addr_from_string(op->nb->macs[i], &mac)) {
struct ds match, actions;
ds_init(&match);
#define ETH_TYPE_LLDP 0x88cc
/* Dummy MAC addresses */
-static uint8_t chassis_mac[ETH_ADDR_LEN] = { 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad };
-static uint8_t eth_src[ETH_ADDR_LEN] = { 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad };
+static const struct eth_addr chassis_mac = { { { 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad } } };
+static const struct eth_addr eth_src = { { { 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad } } };
/* LLDP multicast address */
-static const uint8_t eth_addr_lldp[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x0e};
+static const struct eth_addr eth_addr_lldp = { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0e } } };
/* Count of tests run */
static int num_tests = 0;
assert(rport->p_element.type == sport->p_element.type);
assert(rport->p_element.mgmt_vlan == sport->p_element.mgmt_vlan);
- assert(rport->p_element.system_id.system_mac[0] ==
- sport->p_element.system_id.system_mac[0]);
- assert(rport->p_element.system_id.system_mac[1] ==
- sport->p_element.system_id.system_mac[1]);
- assert(rport->p_element.system_id.system_mac[2] ==
- sport->p_element.system_id.system_mac[2]);
- assert(rport->p_element.system_id.system_mac[3] ==
- sport->p_element.system_id.system_mac[3]);
- assert(rport->p_element.system_id.system_mac[4] ==
- sport->p_element.system_id.system_mac[4]);
- assert(rport->p_element.system_id.system_mac[5] ==
- sport->p_element.system_id.system_mac[5]);
+ assert(eth_addr_equals(rport->p_element.system_id.system_mac,
+ sport->p_element.system_id.system_mac));
assert(rport->p_element.system_id.conn_type ==
sport->p_element.system_id.conn_type);
assert(rport->p_element.system_id.rsvd ==
hardware.h_lport.p_element.type =
LLDP_TLV_AA_ELEM_TYPE_CLIENT_VIRTUAL_SWITCH;
hardware.h_lport.p_element.mgmt_vlan = 0xCDC;
- hardware.h_lport.p_element.system_id.system_mac[0] = 0x1;
- hardware.h_lport.p_element.system_id.system_mac[1] = 0x2;
- hardware.h_lport.p_element.system_id.system_mac[2] = 0x3;
- hardware.h_lport.p_element.system_id.system_mac[3] = 0x4;
- hardware.h_lport.p_element.system_id.system_mac[4] = 0x5;
- hardware.h_lport.p_element.system_id.system_mac[5] = 0x6;
+ eth_addr_from_uint64(0x010203040506,
+ &hardware.h_lport.p_element.system_id.system_mac);
hardware.h_lport.p_element.system_id.conn_type = 0x5;
hardware.h_lport.p_element.system_id.rsvd = 0x3CC;
/* Local chassis info */
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
- chassis.c_id = chassis_mac;
+ chassis.c_id = CONST_CAST(uint8_t *, chassis_mac.ea);
chassis.c_id_len = ETH_ADDR_LEN;
chassis.c_name = "Dummy chassis";
chassis.c_descr = "Long dummy chassis description";
hw->h_lport.p_element.type = hardware.h_lport.p_element.type;
hw->h_lport.p_element.mgmt_vlan = hardware.h_lport.p_element.mgmt_vlan;
- hw->h_lport.p_element.system_id.system_mac[0] =
- hardware.h_lport.p_element.system_id.system_mac[0];
- hw->h_lport.p_element.system_id.system_mac[1] =
- hardware.h_lport.p_element.system_id.system_mac[1];
- hw->h_lport.p_element.system_id.system_mac[2] =
- hardware.h_lport.p_element.system_id.system_mac[2];
- hw->h_lport.p_element.system_id.system_mac[3] =
- hardware.h_lport.p_element.system_id.system_mac[3];
- hw->h_lport.p_element.system_id.system_mac[4] =
- hardware.h_lport.p_element.system_id.system_mac[4];
- hw->h_lport.p_element.system_id.system_mac[5] =
- hardware.h_lport.p_element.system_id.system_mac[5];
+ hw->h_lport.p_element.system_id.system_mac =
+ hardware.h_lport.p_element.system_id.system_mac;
hw->h_lport.p_element.system_id.conn_type =
hardware.h_lport.p_element.system_id.conn_type;
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[][ETH_ADDR_LEN] = {
- { 0x00, 0x02, 0xe3, 0x0f, 0x80, 0xa4 },
- { 0x5e, 0x33, 0x7f, 0x5f, 0x1e, 0x99 } };
-static uint8_t dl_dst_values[][ETH_ADDR_LEN] = {
- { 0x4a, 0x27, 0x71, 0xae, 0x64, 0xc1 },
- { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
+static struct eth_addr dl_src_values[] = {
+ { { { 0x00, 0x02, 0xe3, 0x0f, 0x80, 0xa4 } } },
+ { { { 0x5e, 0x33, 0x7f, 0x5f, 0x1e, 0x99 } } } };
+static struct eth_addr dl_dst_values[] = {
+ { { { 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 };
values[CLS_F_IDX_VLAN_TCI][0] = &vlan_tci_values[0];
values[CLS_F_IDX_VLAN_TCI][1] = &vlan_tci_values[1];
- values[CLS_F_IDX_DL_SRC][0] = dl_src_values[0];
- values[CLS_F_IDX_DL_SRC][1] = dl_src_values[1];
+ values[CLS_F_IDX_DL_SRC][0] = &dl_src_values[0];
+ values[CLS_F_IDX_DL_SRC][1] = &dl_src_values[1];
- values[CLS_F_IDX_DL_DST][0] = dl_dst_values[0];
- values[CLS_F_IDX_DL_DST][1] = dl_dst_values[1];
+ values[CLS_F_IDX_DL_DST][0] = &dl_dst_values[0];
+ values[CLS_F_IDX_DL_DST][1] = &dl_dst_values[1];
values[CLS_F_IDX_DL_TYPE][0] = &dl_type_values[0];
values[CLS_F_IDX_DL_TYPE][1] = &dl_type_values[1];
flow.dl_type = dl_type_values[get_value(&x, N_DL_TYPE_VALUES)];
flow.tp_src = tp_src_values[get_value(&x, N_TP_SRC_VALUES)];
flow.tp_dst = tp_dst_values[get_value(&x, N_TP_DST_VALUES)];
- memcpy(flow.dl_src, dl_src_values[get_value(&x, N_DL_SRC_VALUES)],
- ETH_ADDR_LEN);
- memcpy(flow.dl_dst, dl_dst_values[get_value(&x, N_DL_DST_VALUES)],
- ETH_ADDR_LEN);
+ flow.dl_src = dl_src_values[get_value(&x, N_DL_SRC_VALUES)];
+ flow.dl_dst = dl_dst_values[get_value(&x, N_DL_DST_VALUES)];
flow.nw_proto = nw_proto_values[get_value(&x, N_NW_PROTO_VALUES)];
flow.nw_tos = nw_dscp_values[get_value(&x, N_NW_DSCP_VALUES)];
} else if (f_idx == CLS_F_IDX_TP_DST) {
match.wc.masks.tp_dst = OVS_BE16_MAX;
} else if (f_idx == CLS_F_IDX_DL_SRC) {
- memset(match.wc.masks.dl_src, 0xff, ETH_ADDR_LEN);
+ WC_MASK_FIELD(&match.wc, dl_src);
} else if (f_idx == CLS_F_IDX_DL_DST) {
- memset(match.wc.masks.dl_dst, 0xff, ETH_ADDR_LEN);
+ WC_MASK_FIELD(&match.wc, dl_dst);
} else if (f_idx == CLS_F_IDX_VLAN_TCI) {
match.wc.masks.vlan_tci = OVS_BE16_MAX;
} else if (f_idx == CLS_F_IDX_TUN_ID) {
flow->dl_type = dl_type_values[get_value(&x, N_DL_TYPE_VALUES)];
flow->tp_src = tp_src_values[get_value(&x, N_TP_SRC_VALUES)];
flow->tp_dst = tp_dst_values[get_value(&x, N_TP_DST_VALUES)];
- memcpy(flow->dl_src, dl_src_values[get_value(&x, N_DL_SRC_VALUES)],
- ETH_ADDR_LEN);
- memcpy(flow->dl_dst, dl_dst_values[get_value(&x, N_DL_DST_VALUES)],
- ETH_ADDR_LEN);
+ flow->dl_src = dl_src_values[get_value(&x, N_DL_SRC_VALUES)];
+ flow->dl_dst = dl_dst_values[get_value(&x, N_DL_DST_VALUES)];
flow->nw_proto = nw_proto_values[get_value(&x, N_NW_PROTO_VALUES)];
flow->nw_tos = nw_dscp_values[get_value(&x, N_NW_DSCP_VALUES)];
}
printf("\n");
}
if (x->offset.LACPCOUNTERS) {
- uint8_t *mac;
+ struct eth_addr *mac;
union {
ovs_be32 all;
struct {
sflowxdr_setc(x, x->offset.LACPCOUNTERS);
printf("LACPCOUNTERS");
- mac = (uint8_t *)sflowxdr_str(x);
- printf(" sysID="ETH_ADDR_FMT, ETH_ADDR_ARGS(mac));
+ mac = (void *)sflowxdr_str(x);
+ printf(" sysID="ETH_ADDR_FMT, ETH_ADDR_ARGS(*mac));
sflowxdr_skip(x, 2);
- mac = (uint8_t *)sflowxdr_str(x);
- printf(" partnerID="ETH_ADDR_FMT, ETH_ADDR_ARGS(mac));
+ mac = (void *)sflowxdr_str(x);
+ printf(" partnerID="ETH_ADDR_FMT, ETH_ADDR_ARGS(*mac));
sflowxdr_skip(x, 2);
printf(" aggID=%"PRIu32, sflowxdr_next(x));
state.all = sflowxdr_next_n(x);
fetch_ofputil_phy_port(ctx->argv[1], ctx->argv[2], &pp);
pm.port_no = pp.port_no;
- memcpy(pm.hw_addr, pp.hw_addr, ETH_ADDR_LEN);
+ pm.hw_addr = pp.hw_addr;
pm.config = 0;
pm.mask = 0;
pm.advertise = 0;
struct hmap_node node; /* In 'all_bridges'. */
char *name; /* User-specified arbitrary name. */
char *type; /* Datapath type. */
- uint8_t ea[ETH_ADDR_LEN]; /* Bridge Ethernet Address. */
- uint8_t default_ea[ETH_ADDR_LEN]; /* Default MAC. */
+ struct eth_addr ea; /* Bridge Ethernet Address. */
+ struct eth_addr default_ea; /* Default MAC. */
const struct ovsrec_bridge *cfg;
/* OpenFlow switch processing. */
static void bridge_configure_remotes(struct bridge *,
const struct sockaddr_in *managers,
size_t n_managers);
-static void bridge_pick_local_hw_addr(struct bridge *,
- uint8_t ea[ETH_ADDR_LEN],
+static void bridge_pick_local_hw_addr(struct bridge *, struct eth_addr *ea,
struct iface **hw_addr_iface);
static uint64_t bridge_pick_datapath_id(struct bridge *,
- const uint8_t bridge_ea[ETH_ADDR_LEN],
+ const struct eth_addr bridge_ea,
struct iface *hw_addr_iface);
static uint64_t dpid_from_hash(const void *, size_t nbytes);
static bool bridge_has_bond_fake_iface(const struct bridge *,
static void
bridge_configure_datapath_id(struct bridge *br)
{
- uint8_t ea[ETH_ADDR_LEN];
+ struct eth_addr ea;
uint64_t dpid;
struct iface *local_iface;
struct iface *hw_addr_iface;
char *dpid_string;
- bridge_pick_local_hw_addr(br, ea, &hw_addr_iface);
+ bridge_pick_local_hw_addr(br, &ea, &hw_addr_iface);
local_iface = iface_from_ofp_port(br, OFPP_LOCAL);
if (local_iface) {
int error = netdev_set_etheraddr(local_iface->netdev, ea);
br->name, ovs_strerror(error));
}
}
- memcpy(br->ea, ea, ETH_ADDR_LEN);
+ br->ea = ea;
dpid = bridge_pick_datapath_id(br, ea, hw_addr_iface);
if (dpid != ofproto_get_datapath_id(br->ofproto)) {
config_str = smap_get(&br->cfg->other_config, "stp-system-id");
if (config_str) {
- uint8_t ea[ETH_ADDR_LEN];
+ struct eth_addr ea;
- if (eth_addr_from_string(config_str, ea)) {
+ if (eth_addr_from_string(config_str, &ea)) {
br_s.system_id = eth_addr_to_uint64(ea);
} else {
br_s.system_id = eth_addr_to_uint64(br->ea);
config_str = smap_get(&br->cfg->other_config, "rstp-address");
if (config_str) {
- uint8_t ea[ETH_ADDR_LEN];
+ struct eth_addr ea;
- if (eth_addr_from_string(config_str, ea)) {
+ if (eth_addr_from_string(config_str, &ea)) {
br_s.address = eth_addr_to_uint64(ea);
}
else {
}
static void
-find_local_hw_addr(const struct bridge *br, uint8_t ea[ETH_ADDR_LEN],
+find_local_hw_addr(const struct bridge *br, struct eth_addr *ea,
const struct port *fake_br, struct iface **hw_addr_iface)
{
struct hmapx mirror_output_ports;
/* Otherwise choose the minimum non-local MAC address among all of the
* interfaces. */
HMAP_FOR_EACH (port, hmap_node, &br->ports) {
- uint8_t iface_ea[ETH_ADDR_LEN];
+ struct eth_addr iface_ea;
struct iface *candidate;
struct iface *iface;
/* Choose the MAC address to represent the port. */
iface = NULL;
- if (port->cfg->mac && eth_addr_from_string(port->cfg->mac, iface_ea)) {
+ if (port->cfg->mac && eth_addr_from_string(port->cfg->mac,
+ &iface_ea)) {
/* Find the interface with this Ethernet address (if any) so that
* we can provide the correct devname to the caller. */
LIST_FOR_EACH (candidate, port_elem, &port->ifaces) {
- uint8_t candidate_ea[ETH_ADDR_LEN];
- if (!netdev_get_etheraddr(candidate->netdev, candidate_ea)
+ struct eth_addr candidate_ea;
+ if (!netdev_get_etheraddr(candidate->netdev, &candidate_ea)
&& eth_addr_equals(iface_ea, candidate_ea)) {
iface = candidate;
}
}
/* Grab MAC. */
- error = netdev_get_etheraddr(iface->netdev, iface_ea);
+ error = netdev_get_etheraddr(iface->netdev, &iface_ea);
if (error) {
continue;
}
!eth_addr_is_local(iface_ea) &&
!eth_addr_is_reserved(iface_ea) &&
!eth_addr_is_zero(iface_ea) &&
- (!found_addr || eth_addr_compare_3way(iface_ea, ea) < 0))
+ (!found_addr || eth_addr_compare_3way(iface_ea, *ea) < 0))
{
- memcpy(ea, iface_ea, ETH_ADDR_LEN);
+ *ea = iface_ea;
*hw_addr_iface = iface;
found_addr = true;
}
}
if (!found_addr) {
- memcpy(ea, br->default_ea, ETH_ADDR_LEN);
+ *ea = br->default_ea;
*hw_addr_iface = NULL;
}
}
static void
-bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN],
+bridge_pick_local_hw_addr(struct bridge *br, struct eth_addr *ea,
struct iface **hw_addr_iface)
{
const char *hwaddr;
/* Did the user request a particular MAC? */
hwaddr = smap_get(&br->cfg->other_config, "hwaddr");
if (hwaddr && eth_addr_from_string(hwaddr, ea)) {
- if (eth_addr_is_multicast(ea)) {
+ if (eth_addr_is_multicast(*ea)) {
VLOG_ERR("bridge %s: cannot set MAC address to multicast "
- "address "ETH_ADDR_FMT, br->name, ETH_ADDR_ARGS(ea));
- } else if (eth_addr_is_zero(ea)) {
+ "address "ETH_ADDR_FMT, br->name, ETH_ADDR_ARGS(*ea));
+ } else if (eth_addr_is_zero(*ea)) {
VLOG_ERR("bridge %s: cannot set MAC address to zero", br->name);
} else {
return;
* 'hw_addr_iface' must be passed in as a null pointer. */
static uint64_t
bridge_pick_datapath_id(struct bridge *br,
- const uint8_t bridge_ea[ETH_ADDR_LEN],
+ const struct eth_addr bridge_ea,
struct iface *hw_addr_iface)
{
/*
static uint64_t
dpid_from_hash(const void *data, size_t n)
{
- uint8_t hash[SHA1_DIGEST_SIZE];
-
- BUILD_ASSERT_DECL(sizeof hash >= ETH_ADDR_LEN);
- sha1_bytes(data, n, hash);
- eth_addr_mark_random(hash);
- return eth_addr_to_uint64(hash);
+ union {
+ uint8_t bytes[SHA1_DIGEST_SIZE];
+ struct eth_addr ea;
+ } hash;
+
+ sha1_bytes(data, n, hash.bytes);
+ eth_addr_mark_random(&hash.ea);
+ return eth_addr_to_uint64(hash.ea);
}
static void
enum netdev_features current;
enum netdev_flags flags;
const char *link_state;
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
int64_t bps, mtu_64, ifindex64, link_resets;
int mtu, error;
ovsrec_interface_set_mtu(iface->cfg, NULL, 0);
}
- error = netdev_get_etheraddr(iface->netdev, mac);
+ error = netdev_get_etheraddr(iface->netdev, &mac);
if (!error) {
char mac_string[32];
static void
port_refresh_bond_status(struct port *port, bool force_update)
{
- uint8_t mac[ETH_ADDR_LEN];
+ struct eth_addr mac;
/* Return if port is not a bond */
if (list_is_singleton(&port->ifaces)) {
return;
}
- if (bond_get_changed_active_slave(port->name, mac, force_update)) {
+ if (bond_get_changed_active_slave(port->name, &mac, force_update)) {
struct ds mac_s;
ds_init(&mac_s);
/* Derive the default Ethernet address from the bridge's UUID. This should
* be unique and it will be stable between ovs-vswitchd runs. */
- memcpy(br->default_ea, &br_cfg->header_.uuid, ETH_ADDR_LEN);
- eth_addr_mark_random(br->default_ea);
+ memcpy(&br->default_ea, &br_cfg->header_.uuid, ETH_ADDR_LEN);
+ eth_addr_mark_random(&br->default_ea);
hmap_init(&br->ports);
hmap_init(&br->ifaces);
return NULL;
}
} else {
- memcpy(s->id, port->bridge->ea, ETH_ADDR_LEN);
+ s->id = port->bridge->ea;
}
if (eth_addr_is_zero(s->id)) {
if (!mac_s || !ovs_scan(mac_s, ETH_ADDR_SCAN_FMT,
ETH_ADDR_SCAN_ARGS(s->active_slave_mac))) {
/* OVSDB did not store the last active interface */
- memset(s->active_slave_mac, 0, sizeof(s->active_slave_mac));
+ s->active_slave_mac = eth_addr_zero;
}
}
static void
iface_set_mac(const struct bridge *br, const struct port *port, struct iface *iface)
{
- uint8_t ea[ETH_ADDR_LEN], *mac = NULL;
+ struct eth_addr ea, *mac = NULL;
struct iface *hw_addr_iface;
if (strcmp(iface->type, "internal")) {
return;
}
- if (iface->cfg->mac && eth_addr_from_string(iface->cfg->mac, ea)) {
- mac = ea;
+ if (iface->cfg->mac && eth_addr_from_string(iface->cfg->mac, &ea)) {
+ mac = &ea;
} else if (port->cfg->fake_bridge) {
/* Fake bridge and no MAC set in the configuration. Pick a local one. */
- find_local_hw_addr(br, ea, port, &hw_addr_iface);
- mac = ea;
+ find_local_hw_addr(br, &ea, port, &hw_addr_iface);
+ mac = &ea;
}
if (mac) {
VLOG_ERR("interface %s: ignoring mac in Interface record "
"(use Bridge record to set local port's mac)",
iface->name);
- } else if (eth_addr_is_multicast(mac)) {
+ } else if (eth_addr_is_multicast(*mac)) {
VLOG_ERR("interface %s: cannot set MAC to multicast address",
iface->name);
} else {
- int error = netdev_set_etheraddr(iface->netdev, mac);
+ int error = netdev_set_etheraddr(iface->netdev, *mac);
if (error) {
VLOG_ERR("interface %s: setting MAC failed (%s)",
iface->name, ovs_strerror(error));