summaryrefslogtreecommitdiff
path: root/lib/lldp
diff options
context:
space:
mode:
authorJarno Rajahalme <jrajahalme@nicira.com>2015-08-28 14:55:11 -0700
committerJarno Rajahalme <jrajahalme@nicira.com>2015-08-28 14:55:11 -0700
commit74ff3298c8806bb09d0c7e40a25b889ab7564769 (patch)
treeeb79e22f9460a0699825569a14710e393ee3358d /lib/lldp
parentd8ef07e70995e56005e3bc55b86cdb7d0e2066e5 (diff)
downloadopenvswitch-74ff3298c8806bb09d0c7e40a25b889ab7564769.tar.gz
userspace: Define and use struct eth_addr.
Define struct eth_addr and use it instead of a uint8_t array for all ethernet addresses in OVS userspace. The struct is always the right size, and it can be assigned without an explicit memcpy, which makes code more readable. "struct eth_addr" is a good type name for this as many utility functions are already named accordingly. struct eth_addr can be accessed as bytes as well as ovs_be16's, which makes the struct 16-bit aligned. All use seems to be 16-bit aligned, so some algorithms on the ethernet addresses can be made a bit more efficient making use of this fact. As the struct fits into a register (in 64-bit systems) we pass it by value when possible. This patch also changes the few uses of Linux specific ETH_ALEN to OVS's own ETH_ADDR_LEN, and removes the OFP_ETH_ALEN, as it is no longer needed. This work stemmed from a desire to make all struct flow members assignable for unrelated exploration purposes. However, I think this might be a nice code readability improvement by itself. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Diffstat (limited to 'lib/lldp')
-rw-r--r--lib/lldp/aa-structs.h2
-rw-r--r--lib/lldp/lldp-tlv.h4
-rw-r--r--lib/lldp/lldp.c4
-rw-r--r--lib/lldp/lldpd-structs.h2
-rw-r--r--lib/lldp/lldpd.c4
-rw-r--r--lib/lldp/lldpd.h4
6 files changed, 9 insertions, 11 deletions
diff --git a/lib/lldp/aa-structs.h b/lib/lldp/aa-structs.h
index 983c74c31..473031ef3 100644
--- a/lib/lldp/aa-structs.h
+++ b/lib/lldp/aa-structs.h
@@ -24,7 +24,7 @@
#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];
diff --git a/lib/lldp/lldp-tlv.h b/lib/lldp/lldp-tlv.h
index 2b948281f..f54493d19 100644
--- a/lib/lldp/lldp-tlv.h
+++ b/lib/lldp/lldp-tlv.h
@@ -18,8 +18,8 @@
#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
diff --git a/lib/lldp/lldp.c b/lib/lldp/lldp.c
index 493c2ffa9..0340f676a 100644
--- a/lib/lldp/lldp.c
+++ b/lib/lldp/lldp.c
@@ -349,7 +349,7 @@ lldp_decode(struct lldpd *cfg OVS_UNUSED, char *frame, int s,
{
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;
@@ -384,7 +384,7 @@ lldp_decode(struct lldpd *cfg OVS_UNUSED, char *frame, int s,
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;
diff --git a/lib/lldp/lldpd-structs.h b/lib/lldp/lldpd-structs.h
index 59d239c3e..15e5ce8fa 100644
--- a/lib/lldp/lldpd-structs.h
+++ b/lib/lldp/lldpd-structs.h
@@ -182,7 +182,7 @@ struct lldpd_hardware {
* 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;
diff --git a/lib/lldp/lldpd.c b/lib/lldp/lldpd.c
index 71d3938d1..71f7e44b6 100644
--- a/lib/lldp/lldpd.c
+++ b/lib/lldp/lldpd.c
@@ -50,7 +50,7 @@ static struct protocol protos[] =
{ 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)
@@ -209,7 +209,7 @@ lldpd_guess_type(struct lldpd *cfg, char *frame, int s)
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;
diff --git a/lib/lldp/lldpd.h b/lib/lldp/lldpd.h
index 6bd4b055c..c295ab413 100644
--- a/lib/lldp/lldpd.h
+++ b/lib/lldp/lldpd.h
@@ -54,9 +54,7 @@ struct protocol {
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)