On 13 November 2014 09:34, Maxim Uvarov <[email protected]> wrote:
> Define API and implement promisc functions: > odp_pktio_set_promisc() > odp_pktio_promisc() > > Signed-off-by: Maxim Uvarov <[email protected]> > --- > platform/linux-generic/include/api/odp_packet_io.h | 23 +++++++ > platform/linux-generic/odp_packet_io.c | 77 > ++++++++++++++++++++++ > 2 files changed, 100 insertions(+) > > diff --git a/platform/linux-generic/include/api/odp_packet_io.h > b/platform/linux-generic/include/api/odp_packet_io.h > index 90d525b..0fc49c6 100644 > --- a/platform/linux-generic/include/api/odp_packet_io.h > +++ b/platform/linux-generic/include/api/odp_packet_io.h > @@ -158,6 +158,29 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu); > */ > int odp_pktio_mtu(odp_pktio_t id); > > +/* > Needs to be /** for doxygen to recognize it > + * Set promiscuous mode on a packet IO interface. > + * > + * @param[in] id ODP packet IO handle. > + * @param[in] enable 1 to enable promiscuous mode, 0 to disable > + * > + * @retval 0 on success. > + * @retval -1 on any error or not existance pktio id. > spelling existence But might be better as @retval -1 on a bad pktio id @retval -1 ilegal enable value @retval -1 any other error > + * @retval -1 illegal enable flag (not 1 or 0). > + */ > +int odp_pktio_set_promisc(odp_pktio_t id, int enable); > + > +/* > Needs to be /** for doxygen to recognize it > + * 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 or not existance pktio id. > spelling existence But might be better as @retval -1 on a bad pktio id @retval -1 any other error > + */ > +int odp_pktio_promisc(odp_pktio_t id); > + > /** > * @} > */ > diff --git a/platform/linux-generic/odp_packet_io.c > b/platform/linux-generic/odp_packet_io.c > index 651815d..31a293e 100644 > --- a/platform/linux-generic/odp_packet_io.c > +++ b/platform/linux-generic/odp_packet_io.c > @@ -542,3 +542,80 @@ int odp_pktio_mtu(odp_pktio_t id) > > return ifr.ifr_mtu; > } > + > +int odp_pktio_set_promisc(odp_pktio_t id, int enable) > +{ > + pktio_entry_t *entry; > + int sockfd; > + struct ifreq ifr; > + int ret; > + > + if (enable < 0 || enable > 1) { > + ODP_DBG("illegal enable value %d\n", enable); > + return -1; > + } > + > + entry = get_entry(id); > + if (entry == NULL) { > + ODP_DBG("pktio entry %d does not exist\n", id); > + return -1; > + } > + > + if (entry->s.pkt_sock_mmap.sockfd) > + sockfd = entry->s.pkt_sock_mmap.sockfd; > + else > + sockfd = entry->s.pkt_sock.sockfd; > + > + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); > + > + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); > + if (ret != 0) { > + 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) { > + ODP_DBG("ioctl SIOCSIFFLAGS error\n"); > + return -1; > + } > + > + return 0; > +} > + > +int odp_pktio_promisc(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; > + } > + > + if (entry->s.pkt_sock_mmap.sockfd) > + sockfd = entry->s.pkt_sock_mmap.sockfd; > + else > + sockfd = entry->s.pkt_sock.sockfd; > + > + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); > + > + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); > + if (ret != 0) { > + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); > + return -1; > + } > + > + if (ifr.ifr_flags & IFF_PROMISC) > + return 1; > + else > + return 0; > +} > -- > 1.8.5.1.163.gd7aced9 > > > _______________________________________________ > lng-odp mailing list > [email protected] > http://lists.linaro.org/mailman/listinfo/lng-odp > -- *Mike Holmes* Linaro Sr Technical Manager LNG - ODP
_______________________________________________ lng-odp mailing list [email protected] http://lists.linaro.org/mailman/listinfo/lng-odp
