Commit: b06fa48416
Author: Gaetan Rivet <[email protected]>
Subject: netdev: Add netdev_get_policing

This patch introduces a new function netdev_get_policing to read the
current input policing policy of netdev instances, with implementations
for both Linux and DPDK interfaces.

> diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
> index 687e1196b5..9ec5abbf33 100644
> --- a/lib/netdev-dpdk.c
> +++ b/lib/netdev-dpdk.c
> @@ -4253,6 +4253,25 @@ netdev_dpdk_set_policing(struct netdev* netdev, 
> uint32_t policer_rate,
>      return 0;
>  }
>  
> +static int
> +netdev_dpdk_get_policing(struct netdev *netdev,
> +                         uint32_t *kbits_rate, uint32_t *kbits_burst,
> +                         uint32_t *kpkts_rate, uint32_t *kpkts_burst)
> +{
> +    struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
> +
> +    ovs_mutex_lock(&dev->mutex);
> +
> +    *kbits_rate = dev->policer_rate;
> +    *kbits_burst = dev->policer_burst;
> +    *kpkts_rate = 0;
> +    *kpkts_burst = 0;
> +
> +    ovs_mutex_unlock(&dev->mutex);
> +
> +    return 0;
> +}

Should the function validate that the output parameters are non-NULL
before dereferencing them in netdev_dpdk_get_policing?

> diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
> index 8bf1a29a0f..849f6ba821 100644
> --- a/lib/netdev-linux.c
> +++ b/lib/netdev-linux.c
> @@ -3129,6 +3129,25 @@ out:
>      return error;
>  }
>  
> +static int
> +netdev_linux_get_policing(struct netdev *netdev_,
> +                          uint32_t *kbits_rate, uint32_t *kbits_burst,
> +                          uint32_t *kpkts_rate, uint32_t *kpkts_burst)
> +{
> +    struct netdev_linux *netdev = netdev_linux_cast(netdev_);
> +
> +    ovs_mutex_lock(&netdev->mutex);
> +
> +    *kbits_rate = netdev->kbits_rate;
> +    *kbits_burst = netdev->kbits_burst;
> +    *kpkts_rate = netdev->kpkts_rate;
> +    *kpkts_burst = netdev->kpkts_burst;
> +
> +    ovs_mutex_unlock(&netdev->mutex);
> +
> +    return 0;
> +}

Same concern - does netdev_linux_get_policing need to check if the
output parameters are NULL before dereferencing them?

> diff --git a/lib/netdev.c b/lib/netdev.c
> index 6a05e9a7e5..edd79d52f5 100644
> --- a/lib/netdev.c
> +++ b/lib/netdev.c
> @@ -1784,6 +1784,24 @@ netdev_set_policing(struct netdev *netdev, uint32_t 
> kbits_rate,
>              : EOPNOTSUPP);
>  }
>  
> +
> +/* Read the input rate limiting (policing) policy, if possible. */
> +int
> +netdev_get_policing(struct netdev *netdev,
> +                    uint32_t *kbits_rate, uint32_t *kbits_burst,
> +                    uint32_t *kpkts_rate, uint32_t *kpkts_burst)
> +{
> +    *kbits_rate = 0;
> +    *kbits_burst = 0;
> +    *kpkts_rate = 0;
> +    *kpkts_burst = 0;
> +
> +    return (netdev->netdev_class->get_policing
> +            ? netdev->netdev_class->get_policing(netdev,
> +                    kbits_rate, kbits_burst, kpkts_rate, kpkts_burst)
> +            : EOPNOTSUPP);
> +}

Can this code crash if the output parameters are NULL in
netdev_get_policing? The function initializes the values through
dereferencing without checking first.

[ ... ]
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to