@@ -54,4 +54,10 @@ int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[],
*/
int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[],
unsigned len);
+
+/**
+ * Get mac address
+ */
+void pkt_netmap_mac_addr(pkt_netmap_t * const pkt_nm, void *mac_addr,
+ int addr_size);
#endif
@@ -864,6 +864,10 @@ int odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, int addr_size)
}
switch (entry->s.type) {
+ case ODP_PKTIO_TYPE_NETMAP:
+ pkt_netmap_mac_addr(&entry->s.pkt_nm,
+ mac_addr, addr_size);
+ break;
case ODP_PKTIO_TYPE_SOCKET_BASIC:
case ODP_PKTIO_TYPE_SOCKET_MMSG:
memcpy(mac_addr, entry->s.pkt_sock.if_mac,
@@ -23,6 +23,7 @@
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
+#include <arpa/inet.h>
#include <linux/ethtool.h>
#include <linux/sockios.h>
@@ -47,6 +48,7 @@
*/
typedef struct netmap_dev_t {
char ifname[IFNAMSIZ];
+ unsigned char if_mac[ETH_ALEN];
odp_ticketlock_t rx_lock;
odp_ticketlock_t tx_lock;
} netmap_dev_t;
@@ -141,6 +143,41 @@ done:
return error;
}
+static void ethaddr_copy(unsigned char mac_dst[], unsigned char mac_src[])
+{
+ memcpy(mac_dst, mac_src, ETH_ALEN);
+}
+
+static int get_mac_addr(pkt_netmap_t *pkt_nm)
+{
+ struct ifreq ethreq;
+ int sockfd;
+ int err;
+
+ sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+ if (sockfd == -1) {
+ ODP_ERR("socket(): %s\n", strerror(errno));
+ goto error;
+ }
+
+ memset(ðreq, 0, sizeof(ethreq));
+ snprintf(ethreq.ifr_name, IFNAMSIZ, "%s", pkt_nm->nm_dev->ifname);
+ err = ioctl(sockfd, SIOCGIFHWADDR, ðreq);
+ if (err != 0) {
+ ODP_ERR("ioctl(SIOCGIFHWADDR): %s\n", strerror(errno));
+ goto error;
+ }
+ ethaddr_copy(pkt_nm->nm_dev->if_mac,
+ (unsigned char *)ethreq.ifr_ifru.ifru_hwaddr.sa_data);
+
+ return 0;
+
+error:
+ __odp_errno = errno;
+
+ return -1;
+}
+
int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev,
odp_pool_t pool)
{
@@ -240,6 +277,11 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev,
/*
nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_SRXCSUM);
*/
+ ret = get_mac_addr(pkt_nm);
+ if (ret)
+ ODP_ERR("[%04d] Failed to get MAC addr\n",
+ odp_thread_id());
+
ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_STXCSUM);
if (ret)
ODP_DBG("[%04d] ETHTOOL_STXCSUM not supported\n",
@@ -366,3 +408,12 @@ out:
return nb_tx;
}
+
+inline void pkt_netmap_mac_addr(pkt_netmap_t * const pkt_nm, void *mac_addr,
+ int addr_size)
+{
+ if (addr_size < ETH_ALEN)
+ return;
+
+ memcpy(mac_addr, pkt_nm->nm_dev->if_mac, ETH_ALEN);
+}
Signed-off-by: Ciprian Barbu <ciprian.barbu@linaro.org> --- platform/linux-netmap/include/odp_packet_netmap.h | 6 +++ platform/linux-netmap/odp_packet_io.c | 4 ++ platform/linux-netmap/odp_packet_netmap.c | 51 +++++++++++++++++++++++ 3 files changed, 61 insertions(+)