@@ -177,6 +177,18 @@ int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable);
int odp_pktio_promisc_mode(odp_pktio_t id);
/**
+ * Get the default MAC address of a packet IO interface.
+ *
+ * @param[in] id ODP packet IO handle.
+ * @param[out] mac_addr Storage for MAC address of the packet IO interface.
+ * @param[in] addr_size Storage size for the address
+ *
+ * @retval Number of bytes written on success, 0 on failure.
+ */
+size_t odp_pktio_mac_addr(odp_pktio_t id, unsigned char *mac_addr,
+ size_t addr_size);
+
+/**
* @}
*/
@@ -21,6 +21,7 @@
#include <string.h>
#include <sys/ioctl.h>
+#include <linux/if_arp.h>
typedef struct {
pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES];
@@ -633,3 +634,40 @@ int odp_pktio_promisc_mode(odp_pktio_t id)
else
return 0;
}
+
+size_t odp_pktio_mac_addr(odp_pktio_t id, unsigned char *mac_addr,
+ size_t addr_size)
+{
+ pktio_entry_t *entry;
+ int sockfd;
+ struct ifreq ifr;
+ int ret;
+
+ if (addr_size < ETH_ALEN)
+ return 0;
+
+ entry = get_entry(id);
+ if (entry == NULL) {
+ ODP_DBG("pktio entry %d does not exist\n", id);
+ return 0;
+ }
+
+ lock_entry(entry);
+
+ sockfd = sockfd_from_pktio_entry(entry);
+ strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1);
+ ifr.ifr_name[IFNAMSIZ - 1] = 0;
+
+ ret = ioctl(sockfd, SIOCGIFHWADDR, &ifr);
+ if (ret < 0) {
+ unlock_entry(entry);
+ ODP_DBG("ioctl SIOCGIFHWADDR error\n");
+ return 0;
+ }
+
+ memcpy(mac_addr, (unsigned char *)ifr.ifr_ifru.ifru_hwaddr.sa_data,
+ ETH_ALEN);
+ unlock_entry(entry);
+
+ return ETH_ALEN;
+}
Define API to get MAC address for specific packet i/o and implement linux-generic version. Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> --- platform/linux-generic/include/api/odp_packet_io.h | 12 +++++++ platform/linux-generic/odp_packet_io.c | 38 ++++++++++++++++++++++ 2 files changed, 50 insertions(+)