Skip to content

Commit

Permalink
lldp: fix strict-aliasing errors when compiling with O3
Browse files Browse the repository at this point in the history
Signed-off-by: ywc689 <[email protected]>
  • Loading branch information
ywc689 committed Aug 5, 2024
1 parent 9baec6d commit 72bd6d2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/lldp.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ static int lldp_on_change_ttl(const struct lldp_entry *e)
{
struct lldp_port *port = e->port;
uint16_t ttl;
const void *ptr;

/* Lifespan of local lldp caches is not decided by ttl. Actually, they are
* updated periodically in every DPVS_LLDP_UPDATE_INTERVAL second. If not updated
Expand All @@ -588,7 +589,8 @@ static int lldp_on_change_ttl(const struct lldp_entry *e)
if (port->neigh == DPVS_LLDP_NODE_LOCAL)
return EDPVS_OK;

ttl = rte_be_to_cpu_16(*((uint16_t *)e->value));
ptr = &e->value[0];
ttl = rte_be_to_cpu_16(*((uint16_t *)ptr));
if (ttl != port->timeout) {
RTE_LOG(INFO, LLDP, "%s: update neigh lldp ttl %u -> %u\n", __func__, port->timeout, ttl);
port->timeout = ttl;
Expand Down Expand Up @@ -762,11 +764,14 @@ static int lldp_dump_sys_cap(const struct lldp_entry *e, char *buf, size_t len)
uint16_t capacities, enables;
int pos = 0;
char tbuf[256];
const void *ptr;

if (e->len != 4)
return EDPVS_INVPKT;
capacities = rte_be_to_cpu_16(*((uint16_t *)&e->value[0]));
enables = rte_be_to_cpu_16(*((uint16_t *)&e->value[2]));
ptr = &e->value[0];
capacities = rte_be_to_cpu_16(*((uint16_t *)ptr));
ptr = &e->value[2];
enables = rte_be_to_cpu_16(*((uint16_t *)ptr));

lldp_dump_snprintf(tbuf, pos, "System Capabilities TLV (%d)\n", e->type.type);

Expand Down Expand Up @@ -832,6 +837,7 @@ static int lldp_local_pdu_mng_addr(const struct netif_port *dev, uint32_t subtyp
uint8_t *ptr;
struct sockaddr_storage addr;
char ifname[IFNAMSIZ];
uint16_t typlen;

ptr = tbuf + 2;
*(ptr + 1) = subtype;
Expand Down Expand Up @@ -884,7 +890,8 @@ static int lldp_local_pdu_mng_addr(const struct netif_port *dev, uint32_t subtyp
ptr += 4; /* OID String Length */
*ptr++ = 0;

*((uint16_t *)tbuf) = DPVS_LLDP_TL(LLDP_TYPE_MNG_ADDR, ptr - tbuf - 2);
typlen = DPVS_LLDP_TL(LLDP_TYPE_MNG_ADDR, ptr - tbuf - 2);
rte_memcpy(tbuf, &typlen, 2);

if (ptr - tbuf > len)
rte_memcpy(buf, tbuf, len);
Expand Down Expand Up @@ -1625,8 +1632,9 @@ static int lldp_rcv_msg_cb(struct dpvs_msg *msg)
portid_t pid, start, end;
struct netif_port *dev;
struct rte_mbuf *mbuf;
void *msgdata = msg->data;

mbuf = *(struct rte_mbuf **)(msg->data);
mbuf = *(struct rte_mbuf **)msgdata;

pid = mbuf->port;
netif_bond_port_range(&start, &end);
Expand Down

0 comments on commit 72bd6d2

Please sign in to comment.