[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCHv4 4/6] Add a function virDomainNetFind



On 2011年12月29日 15:33, Hu Tao wrote:
> Add a function virDomainNetFind to find a domain's net def.
> ---
>   src/conf/domain_conf.c   |   39 +++++++++++++++++++++++++++++++++++++++
>   src/conf/domain_conf.h   |    3 +++
>   src/libvirt_private.syms |    1 +
>   3 files changed, 43 insertions(+), 0 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 2897b4a..7fa4adb 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -13726,3 +13726,42 @@ virDomainGraphicsListenSetNetwork(virDomainGraphicsDefPtr def,
> 
>       return 0;
>   }
> +
> +/**
> + * virDomainNetFind:
> + * @def: domain's def
> + * @device: could be the interface name or MAC address
> + *
> + * Finds a domain's net def, given the interface name or MAC address
> + *
> + * Returns a pointer to the net def or NULL if not found.
> + */
> +virDomainNetDefPtr
> +virDomainNetFind(virDomainDefPtr def, const char *device)
> +{
> +    bool isMac = false;
> +    virDomainNetDefPtr net = NULL;
> +    unsigned char mac[VIR_MAC_BUFLEN];
> +    int i;
> +
> +    if (virParseMacAddr(device, mac) == 0)
> +        isMac = true;
> +
> +    if (isMac) {
> +        for (i = 0; i<  def->nnets; i++) {
> +            if (memcmp(mac, def->nets[i]->mac, VIR_MAC_BUFLEN) == 0) {
> +                net = def->nets[i];
> +                break;
> +            }
> +        }
> +    } else { /* ifname */
> +        for (i = 0; i<  def->nnets; i++) {
> +            if (STREQ(device, def->nets[i]->ifname)) {

Oh, I missed this, this can cause libvirtd to crash if
def->nets[i]->ifname is NULL.

s/STREQ/STREQ_NULLABLE/

No need to post v5, I will squash the change in when
pushing.

Regards,
Osier


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]