<br><tt><font size=2>Scott Feldman <scofeldm@cisco.com> wrote on
05/20/2010 03:22:12 PM:<br>
<br>
> <br>
> Next steps for V3, etc:<br>
> <br>
> 1) merge with Stefan's latest patch, as much as possible</font></tt>
<br>
<br><tt><font size=2>Yes. Try to make it a patch on top of my V5 patch...</font></tt>
<br><tt><font size=2><br>
> 2) assign VM device mac addr to eth and set macvtap mac addr to random</font></tt>
<br>
<br><tt><font size=2>Hm, why is this necessary? I have tested the macvtap
device and always set it to the address that libvirt assigned to it and
that happened to be the same as the one inside the VM? Is this something
specific to your underlying driver?</font></tt>
<br><tt><font size=2><br>
> 3) figure out where host_uuid lives</font></tt>
<br>
<br><tt><font size=2>I posted a message a while ago. It's not anywhere
right now and should probably be provided via libvirt.conf overriding dmidecode,
but dmidecode being used if its output is valid and resorting to a temporary
(between libvirt restart) host uuid if everything fails...</font></tt>
<br><tt><font size=2><br>
<br>
> diff --git a/src/util/macvtap.c b/src/util/macvtap.c<br>
> index 1f8dd29..7803bc8 100644<br>
> --- a/src/util/macvtap.c<br>
> +++ b/src/util/macvtap.c<br>
> @@ -85,14 +85,14 @@ static void nlClose(int fd)<br>
>   * buffer will be returned.<br>
>   */<br>
>  static<br>
> -int nlComm(struct nlmsghdr *nlmsg,<br>
> +int nlComm(struct nlmsghdr *nlmsg, int nlgroups,<br>
>             char **respbuf, int *respbuflen)<br>
>  {<br>
>      int rc = 0;<br>
>      struct sockaddr_nl nladdr = {<br>
>              .nl_family = AF_NETLINK,<br>
>              .nl_pid    =
0,<br>
> -            .nl_groups = 0,<br>
> +            .nl_groups = nlgroups,</font></tt>
<br>
<br><tt><font size=2>I think if only you use this function, nlgroups can
be 0 here. I would use different code to use multicast for talking to lldpad.</font></tt>
<br><tt><font size=2><br>
>      };<br>
>      int rcvChunkSize = 1024; // expecting less than
that<br>
>      int rcvoffset = 0;<br>
> @@ -192,6 +192,27 @@ nlAppend(struct nlmsghdr *nlm, int totlen, <br>
> const void *data, int datalen)<br>
>      return pos;<br>
>  }<br>
>  <br>
> +#define NLMSG_TAIL(nmsg) \<br>
> +  ((struct rtattr *) (((char *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))<br>
> +<br>
> +static struct rtattr *nlNest(struct nlmsghdr *nlm, int totlen, int
type)<br>
> +{<br>
> +    struct rtattr *nest = NLMSG_TAIL(nlm);<br>
> +<br>
> +    if (nlm->nlmsg_len + NLMSG_ALIGN(sizeof(*nest))
> totlen)<br>
> +   return NULL;<br>
> +    nest->rta_type = type;<br>
> +    nest->rta_len = RTA_LENGTH(0);<br>
> +    nlm->nlmsg_len += sizeof(*nest);<br>
> +    nlAlign(nlm);<br>
> +    return nest;<br>
> +}<br>
> +<br>
> +static int nlNestEnd(struct nlmsghdr *nlm, struct rtattr *nest)<br>
> +{<br>
> +    nest->rta_len = (char *)NLMSG_TAIL(nlm) - (char
*)nest;<br>
> +    return nlm->nlmsg_len;<br>
> +}<br>
>  </font></tt>
<br>
<br><tt><font size=2>At some point in the future someone may want to change
all this netlink stuff to use libnl -- except for maybe in the case of
the multicast message that I am sending in one of my patches and using
select with a timeout to wait for a response from (future) lldpad where
I am not sure whether an equivalent function exists in libnl...</font></tt>
<br><tt><font size=2><br>
> +#if 0<br>
> +static int<br>
> +get_host_uuid(char *host_uuid, int len)</font></tt>
<br>
<br><tt><font size=2>this is not active code ... skipping it</font></tt>
<br><tt><font size=2><br>
> +<br>
> +static int<br>
> +portProfileIdMcast(const char *linkdev,<br>
> +                   const
char request,<br>
> +                   const
char *profileid,<br>
> +                   const
unsigned short *instance_uuid,<br>
> +                   const
unsigned short *host_uuid)<br>
> +{<br>
> +    struct rtattr *port_self;<br>
> +    char nlmsgbuf[512];<br>
> +    struct nlmsghdr *nlm = (struct nlmsghdr *)nlmsgbuf,
*resp;<br>
> +    struct ifinfomsg infomsg = { .ifi_family = AF_UNSPEC
};<br>
> +    char rtattbuf[256];<br>
> +    struct rtattr *rta;<br>
> +    char *recvbuf = NULL;<br>
> +    int recvbuflen;<br>
> +    struct nlmsgerr *err;<br>
> +    int rc = 0;<br>
> +<br>
> +    memset(&nlmsgbuf, 0, sizeof(nlmsgbuf));<br>
> +    nlInit(nlm, NLM_F_REQUEST, RTM_SETLINK);<br>
> +<br>
> +    if (!nlAppend(nlm, sizeof(nlmsgbuf), &infomsg,
sizeof(infomsg)))<br>
> +        goto buffer_too_small;<br>
> +<br>
> +    rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_IFNAME,<br>
> +                    
  linkdev, strlen(linkdev) + 1);<br>
> +    if (!rta)<br>
> +        goto buffer_too_small;<br>
> +<br>
> +    if (!nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))<br>
> +        goto buffer_too_small;<br>
> +<br>
> +    port_self = nlNest(nlm, sizeof(nlmsgbuf), IFLA_PORT_SELF);<br>
> +    if (!port_self)<br>
> +        return -1;<br>
> +<br>
> +    switch (request) {<br>
> +    case PORT_REQUEST_ASSOCIATE:<br>
> +        if (profileid && strlen(profileid))
{<br>
> +            rta = rtattrCreate(rtattbuf,
sizeof(rtattbuf),<br>
> +                    
          IFLA_PORT_PROFILE,<br>
> +                    
          profileid, strlen(profileid) + 1);<br>
> +            if (!rta)<br>
> +                goto buffer_too_small;<br>
> +<br>
> +            if (!nlAppend(nlm, sizeof(nlmsgbuf),
rtattbuf, rta->rta_len))<br>
> +                goto buffer_too_small;<br>
> +        }<br>
> +        if (instance_uuid) {<br>
> +            rta = rtattrCreate(rtattbuf,
sizeof(rtattbuf),<br>
> +                    
          IFLA_PORT_INSTANCE_UUID,<br>
> +                    
          instance_uuid, PORT_UUID_MAX);<br>
> +            if (!rta)<br>
> +                goto buffer_too_small;<br>
> +<br>
> +            if (!nlAppend(nlm, sizeof(nlmsgbuf),
rtattbuf, rta->rta_len))<br>
> +                goto buffer_too_small;<br>
> +        }<br>
> +        if (host_uuid) {<br>
> +            rta = rtattrCreate(rtattbuf,
sizeof(rtattbuf),<br>
> +                    
          IFLA_PORT_HOST_UUID,<br>
> +                    
          host_uuid, PORT_UUID_MAX);<br>
> +            if (!rta)<br>
> +                goto buffer_too_small;<br>
> +<br>
> +            if (!nlAppend(nlm, sizeof(nlmsgbuf),
rtattbuf, rta->rta_len))<br>
> +                goto buffer_too_small;<br>
> +        }<br>
> +        break;<br>
> +    case PORT_REQUEST_DISASSOCIATE:<br>
> +        break;<br>
> +    }<br>
> +<br>
> +    rta = rtattrCreate(rtattbuf, sizeof(rtattbuf), IFLA_PORT_REQUEST,<br>
> +                    
  &request, 1);<br>
> +    if (!rta)<br>
> +        goto buffer_too_small;<br>
> +<br>
> +    if (!nlAppend(nlm, sizeof(nlmsgbuf), rtattbuf, rta->rta_len))<br>
> +        goto buffer_too_small;<br>
> +<br>
> +    nlNestEnd(nlm, port_self);<br>
> +<br>
> +    if (nlComm(nlm, RTNLGRP_LINK, &recvbuf, &recvbuflen)
< 0)<br>
> +        return -1;<br>
> +<br>
</font></tt>
<br><tt><font size=2>I know that it doesn't work like this in the netlink
multicast case where libvirt will receive an error from the kernel and
hopefully some time later a response from lldpad. Still it would be nice
if we could use common code here for both technologies, but the unicast
vs. multicast receiver code makes it quite different. Have a look at my
patches.</font></tt>
<br>
<br><tt><font size=2>    Stefan</font></tt>
<br>