diff mbox

[PATCHv5,3/3] promisc mode manipulation functions

Message ID 1416473054-10656-4-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Nov. 20, 2014, 8:44 a.m. UTC
Define API and implement promisc functions:
 odp_pktio_set_promisc()
 odp_pktio_promisc()

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Reviewed-by Mike Holmes <mike.holmes@linaro.org>
---
 platform/linux-generic/include/api/odp_packet_io.h | 25 +++++++
 platform/linux-generic/odp_packet_io.c             | 77 ++++++++++++++++++++++
 2 files changed, 102 insertions(+)

Comments

Anders Roxell Nov. 21, 2014, 10:39 a.m. UTC | #1
On 2014-11-20 11:44, Maxim Uvarov wrote:
> Define API and implement promisc functions:
>  odp_pktio_set_promisc()
>  odp_pktio_promisc()
> 
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> Reviewed-by Mike Holmes <mike.holmes@linaro.org>

Fix.

> ---
>  platform/linux-generic/include/api/odp_packet_io.h | 25 +++++++
>  platform/linux-generic/odp_packet_io.c             | 77 ++++++++++++++++++++++
>  2 files changed, 102 insertions(+)
> 
> diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h
> index 667395c..c84c14e 100644
> --- a/platform/linux-generic/include/api/odp_packet_io.h
> +++ b/platform/linux-generic/include/api/odp_packet_io.h
> @@ -149,6 +149,31 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu);
>  int odp_pktio_mtu(odp_pktio_t id);
>  
>  /**
> + * 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 a bad pktio id
> + * @retval -1 ilegal enable value
> + * @retval -1 any other error
> + */
> +int odp_pktio_set_promisc(odp_pktio_t id, int enable);

You didn't address my comments on patch v4!

As I see this, either we should have two functions
odp_pktio_set_promisc(odp_pktio_t hdl)
odp_pktio_clear_promisc(odp_pktio_t hdl)

or we should introduce boolean
odp_pktio_set_promisc(odp_pktio_t hdl, boolean enable)


If we decide that we will keep it like you've done it then we should be
consistent between other set functions in our API, and use "int val" as
input variable instead of "int enable".


Cheers,
Anders


> +
> +/**
> + * 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 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 c523350..a4d6cd1 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
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
diff mbox

Patch

diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h
index 667395c..c84c14e 100644
--- a/platform/linux-generic/include/api/odp_packet_io.h
+++ b/platform/linux-generic/include/api/odp_packet_io.h
@@ -149,6 +149,31 @@  int odp_pktio_set_mtu(odp_pktio_t id, int mtu);
 int odp_pktio_mtu(odp_pktio_t id);
 
 /**
+ * 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 a bad pktio id
+ * @retval -1 ilegal enable value
+ * @retval -1 any other error
+ */
+int odp_pktio_set_promisc(odp_pktio_t id, int 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 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 c523350..a4d6cd1 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;
+}