Message ID | 1418147090-29055-4-git-send-email-maxim.uvarov@linaro.org |
---|---|
State | New |
Headers | show |
On 9 December 2014 at 09:44, Maxim Uvarov <maxim.uvarov@linaro.org> wrote: > 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> > Reviewed-by: Petri Savolainen <petri.savolainen@linaro.org> Reviewed-by: Victor Kamensky <victor.kamensky@linaro.org> > --- > platform/linux-generic/include/api/odp_packet_io.h | 12 +++++++ > platform/linux-generic/odp_packet_io.c | 42 ++++++++++++++++++++++ > 2 files changed, 54 insertions(+) > > diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h > index 742ea59..63c047c 100644 > --- a/platform/linux-generic/include/api/odp_packet_io.h > +++ b/platform/linux-generic/include/api/odp_packet_io.h > @@ -175,6 +175,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 id ODP packet IO handle. > + * @param[out] mac_addr Storage for MAC address of the packet IO interface. > + * @param 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, void *mac_addr, > + size_t addr_size); > + > +/** > * @} > */ > > diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c > index 43cf641..541072b 100644 > --- a/platform/linux-generic/odp_packet_io.c > +++ b/platform/linux-generic/odp_packet_io.c > @@ -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]; > @@ -650,3 +651,44 @@ int odp_pktio_promisc_mode(odp_pktio_t id) > else > return 0; > } > + > +size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, > + size_t addr_size) > +{ > + pktio_entry_t *entry; > + > + 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); > + > + if (odp_unlikely(is_free(entry))) { > + unlock_entry(entry); > + ODP_DBG("already freed pktio\n"); > + return -1; > + } > + > + switch (entry->s.type) { > + case ODP_PKTIO_TYPE_SOCKET_BASIC: > + case ODP_PKTIO_TYPE_SOCKET_MMSG: > + memcpy(mac_addr, entry->s.pkt_sock.if_mac, > + ETH_ALEN); > + break; > + case ODP_PKTIO_TYPE_SOCKET_MMAP: > + memcpy(mac_addr, entry->s.pkt_sock_mmap.if_mac, > + ETH_ALEN); > + break; > + default: > + ODP_ABORT("Wrong socket type %d\n", entry->s.type); > + } > + > + unlock_entry(entry); > + > + return ETH_ALEN; > +} > -- > 1.8.5.1.163.gd7aced9 > > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org > http://lists.linaro.org/mailman/listinfo/lng-odp
On Tue, Dec 9, 2014 at 8:09 PM, Victor Kamensky <victor.kamensky@linaro.org> wrote: > On 9 December 2014 at 09:44, Maxim Uvarov <maxim.uvarov@linaro.org> wrote: >> 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> >> Reviewed-by: Petri Savolainen <petri.savolainen@linaro.org> > > Reviewed-by: Victor Kamensky <victor.kamensky@linaro.org> Reviewed-by: Ciprian Barbu <ciprian.barbu@linaro.org> > >> --- >> platform/linux-generic/include/api/odp_packet_io.h | 12 +++++++ >> platform/linux-generic/odp_packet_io.c | 42 ++++++++++++++++++++++ >> 2 files changed, 54 insertions(+) >> >> diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h >> index 742ea59..63c047c 100644 >> --- a/platform/linux-generic/include/api/odp_packet_io.h >> +++ b/platform/linux-generic/include/api/odp_packet_io.h >> @@ -175,6 +175,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 id ODP packet IO handle. >> + * @param[out] mac_addr Storage for MAC address of the packet IO interface. >> + * @param 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, void *mac_addr, >> + size_t addr_size); >> + >> +/** >> * @} >> */ >> >> diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c >> index 43cf641..541072b 100644 >> --- a/platform/linux-generic/odp_packet_io.c >> +++ b/platform/linux-generic/odp_packet_io.c >> @@ -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]; >> @@ -650,3 +651,44 @@ int odp_pktio_promisc_mode(odp_pktio_t id) >> else >> return 0; >> } >> + >> +size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, >> + size_t addr_size) >> +{ >> + pktio_entry_t *entry; >> + >> + 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); >> + >> + if (odp_unlikely(is_free(entry))) { >> + unlock_entry(entry); >> + ODP_DBG("already freed pktio\n"); >> + return -1; >> + } >> + >> + switch (entry->s.type) { >> + case ODP_PKTIO_TYPE_SOCKET_BASIC: >> + case ODP_PKTIO_TYPE_SOCKET_MMSG: >> + memcpy(mac_addr, entry->s.pkt_sock.if_mac, >> + ETH_ALEN); >> + break; >> + case ODP_PKTIO_TYPE_SOCKET_MMAP: >> + memcpy(mac_addr, entry->s.pkt_sock_mmap.if_mac, >> + ETH_ALEN); >> + break; >> + default: >> + ODP_ABORT("Wrong socket type %d\n", entry->s.type); >> + } >> + >> + unlock_entry(entry); >> + >> + return ETH_ALEN; >> +} >> -- >> 1.8.5.1.163.gd7aced9 >> >> >> _______________________________________________ >> lng-odp mailing list >> lng-odp@lists.linaro.org >> http://lists.linaro.org/mailman/listinfo/lng-odp > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org > http://lists.linaro.org/mailman/listinfo/lng-odp
diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index 742ea59..63c047c 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -175,6 +175,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 id ODP packet IO handle. + * @param[out] mac_addr Storage for MAC address of the packet IO interface. + * @param 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, void *mac_addr, + size_t addr_size); + +/** * @} */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 43cf641..541072b 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -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]; @@ -650,3 +651,44 @@ int odp_pktio_promisc_mode(odp_pktio_t id) else return 0; } + +size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, + size_t addr_size) +{ + pktio_entry_t *entry; + + 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); + + if (odp_unlikely(is_free(entry))) { + unlock_entry(entry); + ODP_DBG("already freed pktio\n"); + return -1; + } + + switch (entry->s.type) { + case ODP_PKTIO_TYPE_SOCKET_BASIC: + case ODP_PKTIO_TYPE_SOCKET_MMSG: + memcpy(mac_addr, entry->s.pkt_sock.if_mac, + ETH_ALEN); + break; + case ODP_PKTIO_TYPE_SOCKET_MMAP: + memcpy(mac_addr, entry->s.pkt_sock_mmap.if_mac, + ETH_ALEN); + break; + default: + ODP_ABORT("Wrong socket type %d\n", entry->s.type); + } + + unlock_entry(entry); + + return ETH_ALEN; +}