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

Re: Getting domU vif's MAC address from dom0


  • To: xen-users@xxxxxxxxxxxxxxxxxxxx
  • From: Andy Smith <andy@xxxxxxxxxxxxxx>
  • Date: Sat, 28 Sep 2024 02:56:06 +0000
  • Delivery-date: Sat, 28 Sep 2024 02:57:35 +0000
  • List-id: Xen user discussion <xen-users.lists.xenproject.org>
  • Openpgp: id=BF15490B; url=http://strugglers.net/~andy/pubkey.asc

On Wed, Sep 25, 2024 at 10:37:22PM +0000, Andy Smith wrote:
> Is there an easy way of programmatically obtaining the domU-side MAC of
> a vif, from the dom0?

(Yes)

I did realise it was in xenstore:

> $ sudo xenstore-read /local/domain/0/backend/vif/60/0/mac
> 00:16:5e:00:02:39

What I did not know was how to construct the path to it as I did not
know if the domain ID was available there. It turns out that the vif-nat
script in /etc/xen/scripts already uses the MAC from xenstore and it is
as simple as:

mac=$(xenstore_read "$XENBUS_PATH/mac")

> The purpose of this is in order to add a route via the IPv6 link-local
> address inside the domU, which can be calculated from the MAC address
> of the domU's interface.

So putting that together:

mac_to_v6_ll () {
    local mac=$1
    lladdr=fe80::$(printf %02x $((0x${mac%%:*} ^ 2)))
    mac=${mac#*:}
    lladdr=$lladdr${mac%:*:*:*}ff:fe
    mac=${mac#*:*:}
    lladdr=$lladdr${mac%:*}${mac##*:}
}

mac=$(xenstore_read "$XENBUS_PATH/mac")
mac_to_v6_ll $mac
ip route add $some_v6_network via $lladdr dev $dev

Thanks,
Andy



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.