[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: Getting domU vif's MAC address from dom0
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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |