static inline int rte_is_same_ether_addr(const struct rte_ether_addr *ea1,
const struct rte_ether_addr *ea2)
{
- int i;
- for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
- if (ea1->addr_bytes[i] != ea2->addr_bytes[i])
- return 0;
- return 1;
+ const unaligned_uint16_t *w1 = (const uint16_t *)ea1;
+ const unaligned_uint16_t *w2 = (const uint16_t *)ea2;
+
+ return ((w1[0] ^ w2[0]) | (w1[1] ^ w2[1]) | (w1[2] ^ w2[2])) == 0;
}
/**
*/
static inline int rte_is_zero_ether_addr(const struct rte_ether_addr *ea)
{
- int i;
- for (i = 0; i < RTE_ETHER_ADDR_LEN; i++)
- if (ea->addr_bytes[i] != 0x00)
- return 0;
- return 1;
+ const unaligned_uint16_t *w = (const uint16_t *)ea;
+
+ return (w[0] | w[1] | w[2]) == 0;
}
/**
* @param addr
* A pointer to Ethernet address.
*/
-static inline void rte_eth_random_addr(uint8_t *addr)
-{
- uint64_t rand = rte_rand();
- uint8_t *p = (uint8_t *)&rand;
-
- rte_memcpy(addr, p, RTE_ETHER_ADDR_LEN);
- addr[0] &= (uint8_t)~RTE_ETHER_GROUP_ADDR; /* clear multicast bit */
- addr[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR; /* set local assignment bit */
-}
+void
+rte_eth_random_addr(uint8_t *addr);
/**
* Fast copy an Ethernet address.
* @param eth_addr
* A pointer to a ether_addr structure.
*/
-static inline void
+void
rte_ether_format_addr(char *buf, uint16_t size,
- const struct rte_ether_addr *eth_addr)
-{
- snprintf(buf, size, "%02X:%02X:%02X:%02X:%02X:%02X",
- eth_addr->addr_bytes[0],
- eth_addr->addr_bytes[1],
- eth_addr->addr_bytes[2],
- eth_addr->addr_bytes[3],
- eth_addr->addr_bytes[4],
- eth_addr->addr_bytes[5]);
-}
+ const struct rte_ether_addr *eth_addr);
+/**
+ * Convert string with Ethernet address to an ether_addr.
+ *
+ * @param str
+ * A pointer to buffer contains the formatted MAC address.
+ * The supported formats are:
+ * XX:XX:XX:XX:XX:XX or XXXX:XXXX:XXXX
+ * where XX is a hex digit: 0-9, a-f, or A-F.
+ * @param eth_addr
+ * A pointer to a ether_addr structure.
+ * @return
+ * 0 if successful
+ * -1 and sets rte_errno if invalid string
+ */
+__rte_experimental
+int
+rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
/**
* Ethernet header: Contains the destination address, source address
struct rte_vlan_hdr *vh;
/* Can't insert header if mbuf is shared */
- if (rte_mbuf_refcnt_read(*m) > 1) {
- struct rte_mbuf *copy;
-
- copy = rte_pktmbuf_clone(*m, (*m)->pool);
- if (unlikely(copy == NULL))
- return -ENOMEM;
- rte_pktmbuf_free(*m);
- *m = copy;
- }
+ if (!RTE_MBUF_DIRECT(*m) || rte_mbuf_refcnt_read(*m) > 1)
+ return -EINVAL;
oh = rte_pktmbuf_mtod(*m, struct rte_ether_hdr *);
nh = (struct rte_ether_hdr *)
(*m)->ol_flags &= ~(PKT_RX_VLAN_STRIPPED | PKT_TX_VLAN);
+ if ((*m)->ol_flags & PKT_TX_TUNNEL_MASK)
+ (*m)->outer_l2_len += sizeof(struct rte_vlan_hdr);
+ else
+ (*m)->l2_len += sizeof(struct rte_vlan_hdr);
+
return 0;
}