diff mbox

[1/2] promisc mode manipulation functions

Message ID 1416822783-16612-1-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Nov. 24, 2014, 9:53 a.m. UTC
Define API and implement promisc functions:
	odp_pktio_promisc_get_enabled()
	odp_pktio_promisc_enable()
	odp_pktio_promisc_disable()

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/include/api/odp_packet_io.h |  34 +++++++
 platform/linux-generic/odp_packet_io.c             | 108 +++++++++++++++++++++
 2 files changed, 142 insertions(+)

Comments

Bill Fischofer Nov. 24, 2014, 12:53 p.m. UTC | #1
ODP accesssor functions take the general form:

Getter: odp_*attribute*()
Setter: odp_set_*attribute*()

So these routines should be named odp_pktio_promisc() and
odp_pktio_set_promisc(), respectively and return/take a boolean value.
Petri hasn't yes gone through the PktIO spec yet, but this nomenclature
would be consistent with the rest of ODP.

Bill

On Mon, Nov 24, 2014 at 3:53 AM, Maxim Uvarov <maxim.uvarov@linaro.org>
wrote:

> Define API and implement promisc functions:
>         odp_pktio_promisc_get_enabled()
>         odp_pktio_promisc_enable()
>         odp_pktio_promisc_disable()
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>  platform/linux-generic/include/api/odp_packet_io.h |  34 +++++++
>  platform/linux-generic/odp_packet_io.c             | 108
> +++++++++++++++++++++
>  2 files changed, 142 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..c9b0889 100644
> --- a/platform/linux-generic/include/api/odp_packet_io.h
> +++ b/platform/linux-generic/include/api/odp_packet_io.h
> @@ -149,6 +149,40 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu);
>  int odp_pktio_mtu(odp_pktio_t id);
>
>  /**
> + * Enable promiscuous mode on a packet IO interface.
> + *
> + * @param[in] id     ODP packet IO handle.
> + *
> + * @retval  0 on success.
> + * @retval -1 on a bad pktio id
> + * @retval -1 any other error
> + */
> +int odp_pktio_promisc_enable(odp_pktio_t id);
> +
> +/**
> + * Disable promiscuous mode on a packet IO interface.
> + *
> + * @param[in] id     ODP packet IO handle.
> + *
> + * @retval  0 on success.
> + * @retval -1 on a bad pktio id
> + * @retval -1 any other error
> + */
> +int odp_pktio_promisc_disable(odp_pktio_t id);
> +
> +/**
> + * 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_get_enabled(odp_pktio_t id);
> +
> +/**
>   * @}
>   */
>
> diff --git a/platform/linux-generic/odp_packet_io.c
> b/platform/linux-generic/odp_packet_io.c
> index c523350..937f7f0 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -542,3 +542,111 @@ int odp_pktio_mtu(odp_pktio_t id)
>
>         return ifr.ifr_mtu;
>  }
> +
> +int odp_pktio_promisc_enable(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);
> +       ifr.ifr_name[IFNAMSIZ] = 0;
> +
> +       ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr);
> +       if (ret < 0) {
> +               ODP_DBG("ioctl SIOCGIFFLAGS error\n");
> +               return -1;
> +       }
> +
> +       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_disable(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);
> +       ifr.ifr_name[IFNAMSIZ] = 0;
> +
> +       ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr);
> +       if (ret < 0) {
> +               ODP_DBG("ioctl SIOCGIFFLAGS error\n");
> +               return -1;
> +       }
> +
> +       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_get_enabled(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
>
Maxim Uvarov Nov. 24, 2014, 1:07 p.m. UTC | #2
On 11/24/2014 03:53 PM, Bill Fischofer wrote:
> ODP accesssor functions take the general form:
>
> Getter: odp_/attribute/()
> Setter: odp_set_/attribute/()
>
> So these routines should be named odp_pktio_promisc() and 
> odp_pktio_set_promisc(), respectively and return/take a boolean 
> value.  Petri hasn't yes gone through the PktIO spec yet, but this 
> nomenclature would be consistent with the rest of ODP.
>
> Bill

Actually there was some inconsistence in function names and pairs of 
that function names. Speaking with Mike and Anders we
came to such naming:

odp_layer_set_ - to set
odp_layer_get_ - to get some value
odp_layer_is_    - check for flag
odp_layer_has_ - has compatibility
odp_layer_feature_enable
odp_layer_feature_disable

odp_attribute() naming was not clear for us without looking to the doc. 
Is it setter or getter. We looked at dpdk names and came with that naming.

Can we discuss using naming like above?

Maxim.

>
> On Mon, Nov 24, 2014 at 3:53 AM, Maxim Uvarov <maxim.uvarov@linaro.org 
> <mailto:maxim.uvarov@linaro.org>> wrote:
>
>     Define API and implement promisc functions:
>             odp_pktio_promisc_get_enabled()
>             odp_pktio_promisc_enable()
>             odp_pktio_promisc_disable()
>
>     Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org
>     <mailto:maxim.uvarov@linaro.org>>
>     ---
>      platform/linux-generic/include/api/odp_packet_io.h |  34 +++++++
>      platform/linux-generic/odp_packet_io.c             | 108
>     +++++++++++++++++++++
>      2 files changed, 142 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..c9b0889 100644
>     --- a/platform/linux-generic/include/api/odp_packet_io.h
>     +++ b/platform/linux-generic/include/api/odp_packet_io.h
>     @@ -149,6 +149,40 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu);
>      int odp_pktio_mtu(odp_pktio_t id);
>
>      /**
>     + * Enable promiscuous mode on a packet IO interface.
>     + *
>     + * @param[in] id     ODP packet IO handle.
>     + *
>     + * @retval  0 on success.
>     + * @retval -1 on a bad pktio id
>     + * @retval -1 any other error
>     + */
>     +int odp_pktio_promisc_enable(odp_pktio_t id);
>     +
>     +/**
>     + * Disable promiscuous mode on a packet IO interface.
>     + *
>     + * @param[in] id     ODP packet IO handle.
>     + *
>     + * @retval  0 on success.
>     + * @retval -1 on a bad pktio id
>     + * @retval -1 any other error
>     + */
>     +int odp_pktio_promisc_disable(odp_pktio_t id);
>     +
>     +/**
>     + * 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_get_enabled(odp_pktio_t id);
>     +
>     +/**
>       * @}
>       */
>
>     diff --git a/platform/linux-generic/odp_packet_io.c
>     b/platform/linux-generic/odp_packet_io.c
>     index c523350..937f7f0 100644
>     --- a/platform/linux-generic/odp_packet_io.c
>     +++ b/platform/linux-generic/odp_packet_io.c
>     @@ -542,3 +542,111 @@ int odp_pktio_mtu(odp_pktio_t id)
>
>             return ifr.ifr_mtu;
>      }
>     +
>     +int odp_pktio_promisc_enable(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 <http://s.name>,
>     IFNAMSIZ);
>     +       ifr.ifr_name[IFNAMSIZ] = 0;
>     +
>     +       ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr);
>     +       if (ret < 0) {
>     +               ODP_DBG("ioctl SIOCGIFFLAGS error\n");
>     +               return -1;
>     +       }
>     +
>     +       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_disable(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 <http://s.name>,
>     IFNAMSIZ);
>     +       ifr.ifr_name[IFNAMSIZ] = 0;
>     +
>     +       ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr);
>     +       if (ret < 0) {
>     +               ODP_DBG("ioctl SIOCGIFFLAGS error\n");
>     +               return -1;
>     +       }
>     +
>     +       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_get_enabled(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 <http://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 <mailto: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..c9b0889 100644
--- a/platform/linux-generic/include/api/odp_packet_io.h
+++ b/platform/linux-generic/include/api/odp_packet_io.h
@@ -149,6 +149,40 @@  int odp_pktio_set_mtu(odp_pktio_t id, int mtu);
 int odp_pktio_mtu(odp_pktio_t id);
 
 /**
+ * Enable promiscuous mode on a packet IO interface.
+ *
+ * @param[in] id     ODP packet IO handle.
+ *
+ * @retval  0 on success.
+ * @retval -1 on a bad pktio id
+ * @retval -1 any other error
+ */
+int odp_pktio_promisc_enable(odp_pktio_t id);
+
+/**
+ * Disable promiscuous mode on a packet IO interface.
+ *
+ * @param[in] id     ODP packet IO handle.
+ *
+ * @retval  0 on success.
+ * @retval -1 on a bad pktio id
+ * @retval -1 any other error
+ */
+int odp_pktio_promisc_disable(odp_pktio_t id);
+
+/**
+ * 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_get_enabled(odp_pktio_t id);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index c523350..937f7f0 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -542,3 +542,111 @@  int odp_pktio_mtu(odp_pktio_t id)
 
 	return ifr.ifr_mtu;
 }
+
+int odp_pktio_promisc_enable(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);
+	ifr.ifr_name[IFNAMSIZ] = 0;
+
+	ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr);
+	if (ret < 0) {
+		ODP_DBG("ioctl SIOCGIFFLAGS error\n");
+		return -1;
+	}
+
+	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_disable(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);
+	ifr.ifr_name[IFNAMSIZ] = 0;
+
+	ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr);
+	if (ret < 0) {
+		ODP_DBG("ioctl SIOCGIFFLAGS error\n");
+		return -1;
+	}
+
+	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_get_enabled(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;
+}