diff mbox

[PATCHv4,02/11] API: promisc mode manipulation functions

Message ID 1417450537-7640-3-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Dec. 1, 2014, 4:15 p.m. UTC
Define API and implement promisc functions for linux-generic.

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

Comments

Zoltan Kiss Dec. 1, 2014, 6:17 p.m. UTC | #1
On 01/12/14 16:15, Maxim Uvarov wrote:
> Define API and implement promisc functions for linux-generic.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>   platform/linux-generic/include/api/odp_packet_io.h | 24 +++++++
>   platform/linux-generic/odp_packet_io.c             | 74 ++++++++++++++++++++++
>   2 files changed, 98 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..c7d1e40 100644
> --- a/platform/linux-generic/include/api/odp_packet_io.h
> +++ b/platform/linux-generic/include/api/odp_packet_io.h
> @@ -149,6 +149,30 @@ 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.
> + * @param[in] enable    1 enabled, 0 disabled.
> + *
> + * @retval  0 on success.
> + * @retval -1 on a bad pktio id
> + * @retval -1 any other error
I would consider choosing 1 (or 2, or any positive value) as a "bad 
pktio id" return value, because in the linux-generic implementation the 
ioctl can return any negative errno, -1 means EPERM. Or INT_MIN.

> + */
> +int odp_pktio_promisc_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 a bad pktio id
> + * @retval -1 any other error
Same here
> +*/
> +int odp_pktio_promisc_enabled(odp_pktio_t id);
> +
> +/**
>    * @}
>    */
>
> diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
> index acc03bb..d97910f 100644
> --- a/platform/linux-generic/odp_packet_io.c
> +++ b/platform/linux-generic/odp_packet_io.c
> @@ -545,3 +545,77 @@ int odp_pktio_mtu(odp_pktio_t id)
>
>   	return ifr.ifr_mtu;
>   }
> +
> +int odp_pktio_promisc_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;
> +	}
> +
> +	if (entry->s.pkt_sock_mmap.sockfd > -1)
> +		sockfd = entry->s.pkt_sock_mmap.sockfd;
> +	else
> +		sockfd = entry->s.pkt_sock.sockfd;
> +
> +	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");
> +		return -1;
I would print out ret, and then return it, same applies to the other ioctl's
> +	}
> +
> +	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_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 > -1)
> +		sockfd = entry->s.pkt_sock_mmap.sockfd;
> +	else
> +		sockfd = entry->s.pkt_sock.sockfd;
> +
> +	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");
> +		return -1;
> +	}
> +
> +	if (ifr.ifr_flags & IFF_PROMISC)
> +		return 1;
> +	else
> +		return 0;
> +}
>
Maxim Uvarov Dec. 1, 2014, 10:12 p.m. UTC | #2
On 12/01/2014 09:17 PM, Zoltan Kiss wrote:
>
>
> On 01/12/14 16:15, Maxim Uvarov wrote:
>> Define API and implement promisc functions for linux-generic.
>>
>> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
>> ---
>>   platform/linux-generic/include/api/odp_packet_io.h | 24 +++++++
>>   platform/linux-generic/odp_packet_io.c             | 74 
>> ++++++++++++++++++++++
>>   2 files changed, 98 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..c7d1e40 100644
>> --- a/platform/linux-generic/include/api/odp_packet_io.h
>> +++ b/platform/linux-generic/include/api/odp_packet_io.h
>> @@ -149,6 +149,30 @@ 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.
>> + * @param[in] enable    1 enabled, 0 disabled.
>> + *
>> + * @retval  0 on success.
>> + * @retval -1 on a bad pktio id
>> + * @retval -1 any other error
> I would consider choosing 1 (or 2, or any positive value) as a "bad 
> pktio id" return value, because in the linux-generic implementation 
> the ioctl can return any negative errno, -1 means EPERM. Or INT_MIN.

In this patch I followed API doc. In patch "[PATCHv4 10/11] API and 
linux-generic: pktio update return codes" I corrected return codes. In 
case if there will be reasons to reject patch 10. Please review patch 
10. Logic is - success and <0 on failure (-ENOENT, -ENOMEM, ret from 
ioctl and etc..)

Maxim.
>
>> + */
>> +int odp_pktio_promisc_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 a bad pktio id
>> + * @retval -1 any other error
> Same here
>> +*/
>> +int odp_pktio_promisc_enabled(odp_pktio_t id);
>> +
>> +/**
>>    * @}
>>    */
>>
>> diff --git a/platform/linux-generic/odp_packet_io.c 
>> b/platform/linux-generic/odp_packet_io.c
>> index acc03bb..d97910f 100644
>> --- a/platform/linux-generic/odp_packet_io.c
>> +++ b/platform/linux-generic/odp_packet_io.c
>> @@ -545,3 +545,77 @@ int odp_pktio_mtu(odp_pktio_t id)
>>
>>       return ifr.ifr_mtu;
>>   }
>> +
>> +int odp_pktio_promisc_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;
>> +    }
>> +
>> +    if (entry->s.pkt_sock_mmap.sockfd > -1)
>> +        sockfd = entry->s.pkt_sock_mmap.sockfd;
>> +    else
>> +        sockfd = entry->s.pkt_sock.sockfd;
>> +
>> +    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");
>> +        return -1;
> I would print out ret, and then return it, same applies to the other 
> ioctl's
>> +    }
>> +
>> +    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_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 > -1)
>> +        sockfd = entry->s.pkt_sock_mmap.sockfd;
>> +    else
>> +        sockfd = entry->s.pkt_sock.sockfd;
>> +
>> +    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");
>> +        return -1;
>> +    }
>> +
>> +    if (ifr.ifr_flags & IFF_PROMISC)
>> +        return 1;
>> +    else
>> +        return 0;
>> +}
>>
Maxim Uvarov Dec. 5, 2014, 4:11 p.m. UTC | #3
On 12/01/2014 09:17 PM, Zoltan Kiss wrote:
>
>
> On 01/12/14 16:15, Maxim Uvarov wrote:
>> Define API and implement promisc functions for linux-generic.
>>
>> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
>> ---
>>   platform/linux-generic/include/api/odp_packet_io.h | 24 +++++++
>>   platform/linux-generic/odp_packet_io.c             | 74 
>> ++++++++++++++++++++++
>>   2 files changed, 98 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..c7d1e40 100644
>> --- a/platform/linux-generic/include/api/odp_packet_io.h
>> +++ b/platform/linux-generic/include/api/odp_packet_io.h
>> @@ -149,6 +149,30 @@ 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.
>> + * @param[in] enable    1 enabled, 0 disabled.
>> + *
>> + * @retval  0 on success.
>> + * @retval -1 on a bad pktio id
>> + * @retval -1 any other error
> I would consider choosing 1 (or 2, or any positive value) as a "bad 
> pktio id" return value, because in the linux-generic implementation 
> the ioctl can return any negative errno, -1 means EPERM. Or INT_MIN.

Zoltan, for 1.0 we stayed with 0 on success and !0 on error. After 1.0 
we will rework all apis for return error codes.

Maxim.

>
>> + */
>> +int odp_pktio_promisc_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 a bad pktio id
>> + * @retval -1 any other error
> Same here
>> +*/
>> +int odp_pktio_promisc_enabled(odp_pktio_t id);
>> +
>> +/**
>>    * @}
>>    */
>>
>> diff --git a/platform/linux-generic/odp_packet_io.c 
>> b/platform/linux-generic/odp_packet_io.c
>> index acc03bb..d97910f 100644
>> --- a/platform/linux-generic/odp_packet_io.c
>> +++ b/platform/linux-generic/odp_packet_io.c
>> @@ -545,3 +545,77 @@ int odp_pktio_mtu(odp_pktio_t id)
>>
>>       return ifr.ifr_mtu;
>>   }
>> +
>> +int odp_pktio_promisc_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;
>> +    }
>> +
>> +    if (entry->s.pkt_sock_mmap.sockfd > -1)
>> +        sockfd = entry->s.pkt_sock_mmap.sockfd;
>> +    else
>> +        sockfd = entry->s.pkt_sock.sockfd;
>> +
>> +    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");
>> +        return -1;
> I would print out ret, and then return it, same applies to the other 
> ioctl's
>> +    }
>> +
>> +    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_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 > -1)
>> +        sockfd = entry->s.pkt_sock_mmap.sockfd;
>> +    else
>> +        sockfd = entry->s.pkt_sock.sockfd;
>> +
>> +    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");
>> +        return -1;
>> +    }
>> +
>> +    if (ifr.ifr_flags & IFF_PROMISC)
>> +        return 1;
>> +    else
>> +        return 0;
>> +}
>>
Ola Liljedahl Dec. 8, 2014, 11:20 a.m. UTC | #4
On 5 December 2014 at 17:11, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
> On 12/01/2014 09:17 PM, Zoltan Kiss wrote:
>>
>>
>>
>> On 01/12/14 16:15, Maxim Uvarov wrote:
>>>
>>> Define API and implement promisc functions for linux-generic.
>>>
>>> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
>>> ---
>>>   platform/linux-generic/include/api/odp_packet_io.h | 24 +++++++
>>>   platform/linux-generic/odp_packet_io.c             | 74
>>> ++++++++++++++++++++++
>>>   2 files changed, 98 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..c7d1e40 100644
>>> --- a/platform/linux-generic/include/api/odp_packet_io.h
>>> +++ b/platform/linux-generic/include/api/odp_packet_io.h
>>> @@ -149,6 +149,30 @@ 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.
>>> + * @param[in] enable    1 enabled, 0 disabled.
>>> + *
>>> + * @retval  0 on success.
>>> + * @retval -1 on a bad pktio id
>>> + * @retval -1 any other error
>>
>> I would consider choosing 1 (or 2, or any positive value) as a "bad pktio
>> id" return value, because in the linux-generic implementation the ioctl can
>> return any negative errno, -1 means EPERM. Or INT_MIN.
>
>
> Zoltan, for 1.0 we stayed with 0 on success and !0 on error. After 1.0 we
> will rework all apis for return error codes.
And then, I don't see any difference in a system call detecting an
error and setting errno and the ODP code detecting an error and
setting errno.
In this case (invalid pktio handle), the function should return -1 and
set errno to e.g. ENXIO or ENODEV.

>
> Maxim.
>
>
>>
>>> + */
>>> +int odp_pktio_promisc_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 a bad pktio id
>>> + * @retval -1 any other error
>>
>> Same here
>>>
>>> +*/
>>> +int odp_pktio_promisc_enabled(odp_pktio_t id);
>>> +
>>> +/**
>>>    * @}
>>>    */
>>>
>>> diff --git a/platform/linux-generic/odp_packet_io.c
>>> b/platform/linux-generic/odp_packet_io.c
>>> index acc03bb..d97910f 100644
>>> --- a/platform/linux-generic/odp_packet_io.c
>>> +++ b/platform/linux-generic/odp_packet_io.c
>>> @@ -545,3 +545,77 @@ int odp_pktio_mtu(odp_pktio_t id)
>>>
>>>       return ifr.ifr_mtu;
>>>   }
>>> +
>>> +int odp_pktio_promisc_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;
>>> +    }
>>> +
>>> +    if (entry->s.pkt_sock_mmap.sockfd > -1)
>>> +        sockfd = entry->s.pkt_sock_mmap.sockfd;
>>> +    else
>>> +        sockfd = entry->s.pkt_sock.sockfd;
>>> +
>>> +    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");
>>> +        return -1;
>>
>> I would print out ret, and then return it, same applies to the other
>> ioctl's
>>>
>>> +    }
>>> +
>>> +    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_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 > -1)
>>> +        sockfd = entry->s.pkt_sock_mmap.sockfd;
>>> +    else
>>> +        sockfd = entry->s.pkt_sock.sockfd;
>>> +
>>> +    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");
>>> +        return -1;
>>> +    }
>>> +
>>> +    if (ifr.ifr_flags & IFF_PROMISC)
>>> +        return 1;
>>> +    else
>>> +        return 0;
>>> +}
>>>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
Maxim Uvarov Dec. 8, 2014, 11:28 a.m. UTC | #5
On 12/08/2014 02:20 PM, Ola Liljedahl wrote:
> On 5 December 2014 at 17:11, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
>> On 12/01/2014 09:17 PM, Zoltan Kiss wrote:
>>>
>>>
>>> On 01/12/14 16:15, Maxim Uvarov wrote:
>>>> Define API and implement promisc functions for linux-generic.
>>>>
>>>> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
>>>> ---
>>>>    platform/linux-generic/include/api/odp_packet_io.h | 24 +++++++
>>>>    platform/linux-generic/odp_packet_io.c             | 74
>>>> ++++++++++++++++++++++
>>>>    2 files changed, 98 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..c7d1e40 100644
>>>> --- a/platform/linux-generic/include/api/odp_packet_io.h
>>>> +++ b/platform/linux-generic/include/api/odp_packet_io.h
>>>> @@ -149,6 +149,30 @@ 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.
>>>> + * @param[in] enable    1 enabled, 0 disabled.
>>>> + *
>>>> + * @retval  0 on success.
>>>> + * @retval -1 on a bad pktio id
>>>> + * @retval -1 any other error
>>> I would consider choosing 1 (or 2, or any positive value) as a "bad pktio
>>> id" return value, because in the linux-generic implementation the ioctl can
>>> return any negative errno, -1 means EPERM. Or INT_MIN.
>>
>> Zoltan, for 1.0 we stayed with 0 on success and !0 on error. After 1.0 we
>> will rework all apis for return error codes.
> And then, I don't see any difference in a system call detecting an
> error and setting errno and the ODP code detecting an error and
> setting errno.
> In this case (invalid pktio handle), the function should return -1 and
> set errno to e.g. ENXIO or ENODEV.

Petri, should I set errno?

Maxim.

>> Maxim.
>>
>>
>>>> + */
>>>> +int odp_pktio_promisc_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 a bad pktio id
>>>> + * @retval -1 any other error
>>> Same here
>>>> +*/
>>>> +int odp_pktio_promisc_enabled(odp_pktio_t id);
>>>> +
>>>> +/**
>>>>     * @}
>>>>     */
>>>>
>>>> diff --git a/platform/linux-generic/odp_packet_io.c
>>>> b/platform/linux-generic/odp_packet_io.c
>>>> index acc03bb..d97910f 100644
>>>> --- a/platform/linux-generic/odp_packet_io.c
>>>> +++ b/platform/linux-generic/odp_packet_io.c
>>>> @@ -545,3 +545,77 @@ int odp_pktio_mtu(odp_pktio_t id)
>>>>
>>>>        return ifr.ifr_mtu;
>>>>    }
>>>> +
>>>> +int odp_pktio_promisc_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;
>>>> +    }
>>>> +
>>>> +    if (entry->s.pkt_sock_mmap.sockfd > -1)
>>>> +        sockfd = entry->s.pkt_sock_mmap.sockfd;
>>>> +    else
>>>> +        sockfd = entry->s.pkt_sock.sockfd;
>>>> +
>>>> +    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");
>>>> +        return -1;
>>> I would print out ret, and then return it, same applies to the other
>>> ioctl's
>>>> +    }
>>>> +
>>>> +    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_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 > -1)
>>>> +        sockfd = entry->s.pkt_sock_mmap.sockfd;
>>>> +    else
>>>> +        sockfd = entry->s.pkt_sock.sockfd;
>>>> +
>>>> +    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");
>>>> +        return -1;
>>>> +    }
>>>> +
>>>> +    if (ifr.ifr_flags & IFF_PROMISC)
>>>> +        return 1;
>>>> +    else
>>>> +        return 0;
>>>> +}
>>>>
>>
>> _______________________________________________
>> 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..c7d1e40 100644
--- a/platform/linux-generic/include/api/odp_packet_io.h
+++ b/platform/linux-generic/include/api/odp_packet_io.h
@@ -149,6 +149,30 @@  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.
+ * @param[in] enable    1 enabled, 0 disabled.
+ *
+ * @retval  0 on success.
+ * @retval -1 on a bad pktio id
+ * @retval -1 any other error
+ */
+int odp_pktio_promisc_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 a bad pktio id
+ * @retval -1 any other error
+*/
+int odp_pktio_promisc_enabled(odp_pktio_t id);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index acc03bb..d97910f 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -545,3 +545,77 @@  int odp_pktio_mtu(odp_pktio_t id)
 
 	return ifr.ifr_mtu;
 }
+
+int odp_pktio_promisc_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;
+	}
+
+	if (entry->s.pkt_sock_mmap.sockfd > -1)
+		sockfd = entry->s.pkt_sock_mmap.sockfd;
+	else
+		sockfd = entry->s.pkt_sock.sockfd;
+
+	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");
+		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_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 > -1)
+		sockfd = entry->s.pkt_sock_mmap.sockfd;
+	else
+		sockfd = entry->s.pkt_sock.sockfd;
+
+	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");
+		return -1;
+	}
+
+	if (ifr.ifr_flags & IFF_PROMISC)
+		return 1;
+	else
+		return 0;
+}