Message ID | 1418147090-29055-5-git-send-email-maxim.uvarov@linaro.org |
---|---|
State | New |
Headers | show |
On Tue, Dec 9, 2014 at 7:44 PM, Maxim Uvarov <maxim.uvarov@linaro.org> wrote: > Implement pktio device loop device suitable for testing. > Note: sometimes lo0 can not be used in case if you need > change / get mac, promisc, mtu for specific device. > Environment variable is added to bind loop to specific device, example: > export ODP_PKTIO_LOOPDEV=eth0 > > Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> Reviewed-by: Ciprian Barbu <ciprian.barbu@linaro.org> > --- > platform/linux-generic/odp_packet_io.c | 32 ++++++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c > index 541072b..3b7869f 100644 > --- a/platform/linux-generic/odp_packet_io.c > +++ b/platform/linux-generic/odp_packet_io.c > @@ -22,6 +22,7 @@ > #include <string.h> > #include <sys/ioctl.h> > #include <linux/if_arp.h> > +#include <ifaddrs.h> > > typedef struct { > pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; > @@ -160,6 +161,37 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool) > pktio_entry_t *pktio_entry; > int res; > int fanout = 1; > + char loop[IFNAMSIZ] = {0}; > + char *loop_hint; > + > + if (strlen(dev) >= IFNAMSIZ) { > + /* ioctl names limitation */ > + ODP_ERR("pktio name %s is too big, limit is %d bytes\n", > + dev, IFNAMSIZ); > + return ODP_PKTIO_INVALID; > + } > + > + if (!strcmp(dev, "loop")) { > + /* If hint with ODP_PKTIO_LOOPDEV is provided, use hint, > + * if not try to find usable device. > + */ > + loop_hint = getenv("ODP_PKTIO_LOOPDEV"); > + if (!loop_hint || (strlen(loop_hint) == 0)) { > + ODP_ERR("Set loop with ODP_PKTIO_LOOPDEV=ethX\n"); > + return ODP_PKTIO_INVALID; > + } > + > + if (strlen(loop_hint) >= IFNAMSIZ) { > + ODP_ERR("pktio name %s is too big, limit is %d bytes\n", > + loop_hint, IFNAMSIZ); > + return ODP_PKTIO_INVALID; > + } > + > + memset(loop, 0, IFNAMSIZ); > + memcpy(loop, loop_hint, strlen(loop_hint)); > + dev = loop; > + ODP_DBG("pktio using %s as loopback device\n", loop_hint); > + } > > id = alloc_lock_pktio_entry(); > if (id == ODP_PKTIO_INVALID) { > -- > 1.8.5.1.163.gd7aced9 > > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org > http://lists.linaro.org/mailman/listinfo/lng-odp
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 541072b..3b7869f 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -22,6 +22,7 @@ #include <string.h> #include <sys/ioctl.h> #include <linux/if_arp.h> +#include <ifaddrs.h> typedef struct { pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; @@ -160,6 +161,37 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool) pktio_entry_t *pktio_entry; int res; int fanout = 1; + char loop[IFNAMSIZ] = {0}; + char *loop_hint; + + if (strlen(dev) >= IFNAMSIZ) { + /* ioctl names limitation */ + ODP_ERR("pktio name %s is too big, limit is %d bytes\n", + dev, IFNAMSIZ); + return ODP_PKTIO_INVALID; + } + + if (!strcmp(dev, "loop")) { + /* If hint with ODP_PKTIO_LOOPDEV is provided, use hint, + * if not try to find usable device. + */ + loop_hint = getenv("ODP_PKTIO_LOOPDEV"); + if (!loop_hint || (strlen(loop_hint) == 0)) { + ODP_ERR("Set loop with ODP_PKTIO_LOOPDEV=ethX\n"); + return ODP_PKTIO_INVALID; + } + + if (strlen(loop_hint) >= IFNAMSIZ) { + ODP_ERR("pktio name %s is too big, limit is %d bytes\n", + loop_hint, IFNAMSIZ); + return ODP_PKTIO_INVALID; + } + + memset(loop, 0, IFNAMSIZ); + memcpy(loop, loop_hint, strlen(loop_hint)); + dev = loop; + ODP_DBG("pktio using %s as loopback device\n", loop_hint); + } id = alloc_lock_pktio_entry(); if (id == ODP_PKTIO_INVALID) {
Implement pktio device loop device suitable for testing. Note: sometimes lo0 can not be used in case if you need change / get mac, promisc, mtu for specific device. Environment variable is added to bind loop to specific device, example: export ODP_PKTIO_LOOPDEV=eth0 Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> --- platform/linux-generic/odp_packet_io.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)