[libvirt] [ 3/3] assign peer address if it provided in network

Daniel P. Berrange berrange at redhat.com
Wed Mar 23 11:52:38 UTC 2016


On Fri, Mar 18, 2016 at 10:19:43PM +0000, Vasiliy Tolstov wrote:
> Assign peer address if it provided

[snip]

> @@ -1039,21 +1039,28 @@ virNetDevCreateNetlinkAddressMessage(int messageType,
>                                       const char *ifname,
>                                       virSocketAddr *addr,
>                                       unsigned int prefix,
> -                                     virSocketAddr *broadcast)
> +                                     virSocketAddr *broadcast,
> +                                     virSocketAddr *peer)
>  {
>      struct nl_msg *nlmsg = NULL;
>      struct ifaddrmsg ifa;
>      unsigned int ifindex;
>      void *addrData = NULL;
> +    void *peerData = NULL;
>      void *broadcastData = NULL;
>      size_t addrDataLen;
>  
>      if (virNetDevGetIPAddressBinary(addr, &addrData, &addrDataLen) < 0)
>          return NULL;
>  
> -    if (broadcast && virNetDevGetIPAddressBinary(broadcast, &broadcastData,
> -                                                 &addrDataLen) < 0)
> -        return NULL;
> +    if (peer && VIR_SOCKET_ADDR_VALID(peer)) {
> +        if (virNetDevGetIPAddressBinary(peer, &peerData, &addrDataLen) < 0)
> +            return NULL;
> +    } else if (broadcast) {
> +        if (virNetDevGetIPAddressBinary(broadcast, &broadcastData,
> +                                        &addrDataLen) < 0)
> +            return NULL;
> +    }
>  
>      /* Get the interface index */
>      if ((ifindex = if_nametoindex(ifname)) == 0)
> @@ -1078,12 +1085,15 @@ virNetDevCreateNetlinkAddressMessage(int messageType,
>      if (nla_put(nlmsg, IFA_LOCAL, addrDataLen, addrData) < 0)
>          goto buffer_too_small;
>  
> -    if (nla_put(nlmsg, IFA_ADDRESS, addrDataLen, addrData) < 0)
> -        goto buffer_too_small;
> +    if (peerData) {
> +        if (nla_put(nlmsg, IFA_ADDRESS, addrDataLen, peerData) < 0)
> +            goto buffer_too_small;
> +    }
>  
> -    if (broadcastData &&
> -        nla_put(nlmsg, IFA_BROADCAST, addrDataLen, broadcastData) < 0)
> -        goto buffer_too_small;
> +    if (broadcastData) {
> +        if (nla_put(nlmsg, IFA_BROADCAST, addrDataLen, broadcastData) < 0)
> +            goto buffer_too_small;
> +    }
>  
>      return nlmsg;

Ok, I took me a while to understand what the point of this is. I eventually
found this comment in /usr/include/linux/if_addr.h

 * IFA_ADDRESS is prefix address, rather than local interface address.
 * It makes no difference for normally configured broadcast interfaces,
 * but for point-to-point IFA_ADDRESS is DESTINATION address,
 * local address is supplied in IFA_LOCAL attribute.

Likewise in ip-address(8) manpage


       peer ADDRESS
              the address of the remote endpoint for pointopoint inter‐
              faces.  Again, the ADDRESS may be followed by a slash and a
              decimal number, encoding the network prefix length. If a
              peer address is specified, the local address cannot have a
              prefix length. The network prefix is associated with the
              peer rather than with the local address.


So, if we accept ip, broader & route info, it makes sense that we also
accept a peer address.

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list