Message ID | 1418147090-29055-3-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 and implement promisc functions for linux-generic. > > 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 | 22 +++++ > platform/linux-generic/odp_packet_io.c | 101 +++++++++++++++++++++ > 2 files changed, 123 insertions(+) > > diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h > index 5f7ba7c..742ea59 100644 > --- a/platform/linux-generic/include/api/odp_packet_io.h > +++ b/platform/linux-generic/include/api/odp_packet_io.h > @@ -153,6 +153,28 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu); > int odp_pktio_mtu(odp_pktio_t id); > > /** > + * Enable/Disable promiscuous mode on a packet IO interface. > + * > + * @param[in] id ODP packet IO handle. > + * @param[in] enable 1 to enable, 0 to disable. > + * > + * @retval 0 on success. > + * @retval non-zero on any error. > + */ > +int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable); > + > +/** > + * Determine if promiscuous mode is enabled for a packet IO interface. > + * > + * @param[in] id ODP packet IO handle. > + * > + * @retval 1 if promiscuous mode is enabled. > + * @retval 0 if promiscuous mode is disabled. > + * @retval -1 on any error. > +*/ > +int odp_pktio_promisc_mode(odp_pktio_t id); > + > +/** > * @} > */ > > diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c > index faa197f..43cf641 100644 > --- a/platform/linux-generic/odp_packet_io.c > +++ b/platform/linux-generic/odp_packet_io.c > @@ -486,6 +486,20 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) > return nbr; > } > > +/** function should be called with locked entry */ > +static int sockfd_from_pktio_entry(pktio_entry_t *entry) > +{ > + switch (entry->s.type) { > + case ODP_PKTIO_TYPE_SOCKET_BASIC: > + case ODP_PKTIO_TYPE_SOCKET_MMSG: > + return entry->s.pkt_sock.sockfd; > + case ODP_PKTIO_TYPE_SOCKET_MMAP: > + return entry->s.pkt_sock_mmap.sockfd; > + default: > + ODP_ABORT("Wrong socket type %d\n", entry->s.type); > + } > +} > + > int odp_pktio_set_mtu(odp_pktio_t id, int mtu) > { > pktio_entry_t *entry; > @@ -549,3 +563,90 @@ int odp_pktio_mtu(odp_pktio_t id) > > return ifr.ifr_mtu; > } > + > +int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable) > +{ > + pktio_entry_t *entry; > + int sockfd; > + struct ifreq ifr; > + int ret; > + > + entry = get_entry(id); > + if (entry == NULL) { > + ODP_DBG("pktio entry %d does not exist\n", id); > + return -1; > + } > + > + lock_entry(entry); > + > + if (odp_unlikely(is_free(entry))) { > + unlock_entry(entry); > + ODP_DBG("already freed pktio\n"); > + return -1; > + } > + > + sockfd = sockfd_from_pktio_entry(entry); > + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); > + ifr.ifr_name[IFNAMSIZ - 1] = 0; > + > + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); > + if (ret < 0) { > + unlock_entry(entry); > + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); > + return -1; > + } > + > + if (enable) > + ifr.ifr_flags |= IFF_PROMISC; > + else > + ifr.ifr_flags &= ~(IFF_PROMISC); > + > + ret = ioctl(sockfd, SIOCSIFFLAGS, &ifr); > + if (ret < 0) { > + unlock_entry(entry); > + ODP_DBG("ioctl SIOCSIFFLAGS error\n"); > + return -1; > + } > + > + unlock_entry(entry); > + return 0; > +} > + > +int odp_pktio_promisc_mode(odp_pktio_t id) > +{ > + pktio_entry_t *entry; > + int sockfd; > + struct ifreq ifr; > + int ret; > + > + entry = get_entry(id); > + if (entry == NULL) { > + ODP_DBG("pktio entry %d does not exist\n", id); > + return -1; > + } > + > + lock_entry(entry); > + > + if (odp_unlikely(is_free(entry))) { > + unlock_entry(entry); > + ODP_DBG("already freed pktio\n"); > + return -1; > + } > + > + sockfd = sockfd_from_pktio_entry(entry); > + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); > + ifr.ifr_name[IFNAMSIZ - 1] = 0; > + > + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); > + if (ret < 0) { > + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); > + unlock_entry(entry); > + return -1; > + } > + unlock_entry(entry); > + > + if (ifr.ifr_flags & IFF_PROMISC) > + return 1; > + else > + return 0; > +} > -- > 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:01 PM, Victor Kamensky <victor.kamensky@linaro.org> wrote: > On 9 December 2014 at 09:44, Maxim Uvarov <maxim.uvarov@linaro.org> wrote: >> Define API and implement promisc functions for linux-generic. >> >> 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 | 22 +++++ >> platform/linux-generic/odp_packet_io.c | 101 +++++++++++++++++++++ >> 2 files changed, 123 insertions(+) >> >> diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h >> index 5f7ba7c..742ea59 100644 >> --- a/platform/linux-generic/include/api/odp_packet_io.h >> +++ b/platform/linux-generic/include/api/odp_packet_io.h >> @@ -153,6 +153,28 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu); >> int odp_pktio_mtu(odp_pktio_t id); >> >> /** >> + * Enable/Disable promiscuous mode on a packet IO interface. >> + * >> + * @param[in] id ODP packet IO handle. >> + * @param[in] enable 1 to enable, 0 to disable. >> + * >> + * @retval 0 on success. >> + * @retval non-zero on any error. >> + */ >> +int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable); >> + >> +/** >> + * Determine if promiscuous mode is enabled for a packet IO interface. >> + * >> + * @param[in] id ODP packet IO handle. >> + * >> + * @retval 1 if promiscuous mode is enabled. >> + * @retval 0 if promiscuous mode is disabled. >> + * @retval -1 on any error. >> +*/ >> +int odp_pktio_promisc_mode(odp_pktio_t id); >> + >> +/** >> * @} >> */ >> >> diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c >> index faa197f..43cf641 100644 >> --- a/platform/linux-generic/odp_packet_io.c >> +++ b/platform/linux-generic/odp_packet_io.c >> @@ -486,6 +486,20 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) >> return nbr; >> } >> >> +/** function should be called with locked entry */ >> +static int sockfd_from_pktio_entry(pktio_entry_t *entry) >> +{ >> + switch (entry->s.type) { >> + case ODP_PKTIO_TYPE_SOCKET_BASIC: >> + case ODP_PKTIO_TYPE_SOCKET_MMSG: >> + return entry->s.pkt_sock.sockfd; >> + case ODP_PKTIO_TYPE_SOCKET_MMAP: >> + return entry->s.pkt_sock_mmap.sockfd; >> + default: >> + ODP_ABORT("Wrong socket type %d\n", entry->s.type); >> + } >> +} >> + >> int odp_pktio_set_mtu(odp_pktio_t id, int mtu) >> { >> pktio_entry_t *entry; >> @@ -549,3 +563,90 @@ int odp_pktio_mtu(odp_pktio_t id) >> >> return ifr.ifr_mtu; >> } >> + >> +int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable) >> +{ >> + pktio_entry_t *entry; >> + int sockfd; >> + struct ifreq ifr; >> + int ret; >> + >> + entry = get_entry(id); >> + if (entry == NULL) { >> + ODP_DBG("pktio entry %d does not exist\n", id); >> + return -1; >> + } >> + >> + lock_entry(entry); >> + >> + if (odp_unlikely(is_free(entry))) { >> + unlock_entry(entry); >> + ODP_DBG("already freed pktio\n"); >> + return -1; >> + } >> + >> + sockfd = sockfd_from_pktio_entry(entry); >> + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); >> + ifr.ifr_name[IFNAMSIZ - 1] = 0; >> + >> + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); >> + if (ret < 0) { >> + unlock_entry(entry); >> + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); >> + return -1; >> + } >> + >> + if (enable) >> + ifr.ifr_flags |= IFF_PROMISC; >> + else >> + ifr.ifr_flags &= ~(IFF_PROMISC); >> + >> + ret = ioctl(sockfd, SIOCSIFFLAGS, &ifr); >> + if (ret < 0) { >> + unlock_entry(entry); >> + ODP_DBG("ioctl SIOCSIFFLAGS error\n"); >> + return -1; >> + } >> + >> + unlock_entry(entry); >> + return 0; >> +} >> + >> +int odp_pktio_promisc_mode(odp_pktio_t id) >> +{ >> + pktio_entry_t *entry; >> + int sockfd; >> + struct ifreq ifr; >> + int ret; >> + >> + entry = get_entry(id); >> + if (entry == NULL) { >> + ODP_DBG("pktio entry %d does not exist\n", id); >> + return -1; >> + } >> + >> + lock_entry(entry); >> + >> + if (odp_unlikely(is_free(entry))) { >> + unlock_entry(entry); >> + ODP_DBG("already freed pktio\n"); >> + return -1; >> + } >> + >> + sockfd = sockfd_from_pktio_entry(entry); >> + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); >> + ifr.ifr_name[IFNAMSIZ - 1] = 0; >> + >> + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); >> + if (ret < 0) { >> + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); >> + unlock_entry(entry); >> + return -1; >> + } >> + unlock_entry(entry); >> + >> + if (ifr.ifr_flags & IFF_PROMISC) >> + return 1; >> + else >> + return 0; >> +} >> -- >> 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 5f7ba7c..742ea59 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -153,6 +153,28 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu); int odp_pktio_mtu(odp_pktio_t id); /** + * Enable/Disable promiscuous mode on a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * @param[in] enable 1 to enable, 0 to disable. + * + * @retval 0 on success. + * @retval non-zero on any error. + */ +int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable); + +/** + * Determine if promiscuous mode is enabled for a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * + * @retval 1 if promiscuous mode is enabled. + * @retval 0 if promiscuous mode is disabled. + * @retval -1 on any error. +*/ +int odp_pktio_promisc_mode(odp_pktio_t id); + +/** * @} */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index faa197f..43cf641 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -486,6 +486,20 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) return nbr; } +/** function should be called with locked entry */ +static int sockfd_from_pktio_entry(pktio_entry_t *entry) +{ + switch (entry->s.type) { + case ODP_PKTIO_TYPE_SOCKET_BASIC: + case ODP_PKTIO_TYPE_SOCKET_MMSG: + return entry->s.pkt_sock.sockfd; + case ODP_PKTIO_TYPE_SOCKET_MMAP: + return entry->s.pkt_sock_mmap.sockfd; + default: + ODP_ABORT("Wrong socket type %d\n", entry->s.type); + } +} + int odp_pktio_set_mtu(odp_pktio_t id, int mtu) { pktio_entry_t *entry; @@ -549,3 +563,90 @@ int odp_pktio_mtu(odp_pktio_t id) return ifr.ifr_mtu; } + +int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + lock_entry(entry); + + if (odp_unlikely(is_free(entry))) { + unlock_entry(entry); + ODP_DBG("already freed pktio\n"); + return -1; + } + + sockfd = sockfd_from_pktio_entry(entry); + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = 0; + + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + unlock_entry(entry); + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); + return -1; + } + + if (enable) + ifr.ifr_flags |= IFF_PROMISC; + else + ifr.ifr_flags &= ~(IFF_PROMISC); + + ret = ioctl(sockfd, SIOCSIFFLAGS, &ifr); + if (ret < 0) { + unlock_entry(entry); + ODP_DBG("ioctl SIOCSIFFLAGS error\n"); + return -1; + } + + unlock_entry(entry); + return 0; +} + +int odp_pktio_promisc_mode(odp_pktio_t id) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + lock_entry(entry); + + if (odp_unlikely(is_free(entry))) { + unlock_entry(entry); + ODP_DBG("already freed pktio\n"); + return -1; + } + + sockfd = sockfd_from_pktio_entry(entry); + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = 0; + + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); + unlock_entry(entry); + return -1; + } + unlock_entry(entry); + + if (ifr.ifr_flags & IFF_PROMISC) + return 1; + else + return 0; +}