[libvirt] Report guest IPs as XML or struct?

Michal Privoznik mprivozn at redhat.com
Tue Nov 20 10:38:46 UTC 2012


Seems like we agree on struct. So this is my proposal:

typedef enum {
    VIR_INTERFACE_TYPE_UNKNOWN = 0,
    VIR_INTERFACE_TYPE_ETHER = 1,
    VIR_INTERFACE_TYPE_PPP = 2,
    /* we can add things here */
#idef VIR_ENUM_SENTINELS
    VIR_INTERFACE_TYPE_LAST
#endif
} virDomainInterfaceType;

typedef enum {
    VIR_IP_ADDR_TYPE_IPV4,
    VIR_IP_ADDR_TYPE_IPV6,

#ifdef VIR_ENUM_SENTINELS
    VIR_IP_ADDR_TYPE_LAST
#endif
} virIPAddrType;


typedef struct _virDomainInterfaceIPAddress virDomainIPAddress;
typedef virDomainIPAddress *virDomainIPAddressPtr;
struct _virDomainInterfaceIPAddress {
    int type;       /* virIPAddrType */
    char *addr;     /* IP address */
    int prefix;     /* IP address prefix */
};

typedef struct _virDomainInterface virDomainInterface;
typedef virDomainInterface *virDomainInterfacePtr;
struct _virDomainInterface {
    char *name;                     /* interface name */
    int type;                       /* virDomainInterfaceType */
    char *hwaddr;                   /* hardware address */
    unsigned int ip_addrs_count;    /* number of items in @ip_addr */
    virDomainIPAddressPtr ip_addrs; /* array of IP addresses */
    void *padding[20];              /* maybe we need this? */
};

typedef enum {
    VIR_DOMAIN_INTERFACE_ADDRS_DEFAULT      = 0, /* hypervisor choice */
    VIR_DOMAIN_INTERFACE_ADDRS_GUEST_AGENT  = 1, /* use guest agent */
    VIR_DOMAIN_INTERFACE_ADDRS_NWFILTER     = 2, /* use nwfilter learning code */
   /* etc ... */
} virDomainInterfacesAddressesMethod;

int virDomainInterfacesAddresses(virDomainPtr dom,
                                 virDomainInterfacePtr ifaces,
				 unsigned int method
                                 unsigned int flags);


This API would dynamically allocate return array for all interfaces presented in @dom.
We are already doing this in some places, so I think it's okay. With @method users
can choose desired way to get info. I guess if we misuse @flags for that it would be
just a waste of space, since methods are mutually exclusive. Hence, @flags are currently unused.

Michal




More information about the libvir-list mailing list