net/net: Change the default mac address of nic
PATCH v2 1/1 net/net: Change the default mac address of nic
Changelog to v1:
Find remainder of macaddr->a[5] by modulo 256, otherwise it may be overflow by add index++.
The default mac address is 52:54:00:12:34:56 + index, this will cause problem that when we boot up more than one guest with all mac addresses unset by default, assume that each guest has one nic. In this situation, all the guest's nic has the same mac address.
This patch is to solve this bug.
--- net/net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/net.c +6 -3
@@ -21,6 +21,8 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include <time.h> +#include "config-host.h" #include "net/net.h"
@@ -147,12 +149,13 @@ void qemu_macaddr_default_if_unset(MACAddr *macaddr)if (memcmp (macaddr, &zero,sizeof (zero)) !=0 )return ; +srand ((unsigned )time (NULL )); macaddr->a[0 ] =0x52 ; macaddr->a[1 ] =0x54 ; macaddr->a[2 ] =0x00 ; - macaddr->a[3 ] =0x12 ; - macaddr->a[4 ] =0x34 ; - macaddr->a[5 ] =0x56 + index++; + macaddr->a[3 ] =rand () %256 ; + macaddr->a[4 ] =rand () %256 ; + macaddr->a[5 ] = (rand () %256 + index++) %256 ; }/**
Signature · 1 line
1.8.3.1
Am 15.10.2013 06:17, schrieb Mike Qiu:
Quoted 36 lines
Changelog to v1:
Find remainder of macaddr->a[5] by modulo 256, otherwise it may be overflow by add index++.The default mac address is 52:54:00:12:34:56 + index, this will cause problem that when we boot up more than one guest with all mac addresses unset by default, assume that each guest has one nic. In this situation, all the guest's nic has the same mac address.
This patch is to solve this bug.
Signed-off-by Mike Qiu <[email protected]>--- net/net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)net/net.c +3
-0@@ -21,6 +21,8 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include <time.h> +#include "config-host.h" #include "net/net.h" @@ -147,12 +149,13 @@ void qemu_macaddr_default_if_unset(MACAddr *macaddr)if (memcmp (macaddr, &zero,sizeof (zero)) !=0 )return ; +srand ((unsigned )time (NULL )); macaddr->a[0 ] =0x52 ; macaddr->a[1 ] =0x54 ;
net/net.c void qemu_macaddr_default_if_unset(MACAddr *macaddr) · line 161
Quoted 10 lines
net/net.c +3
-3macaddr->a[2 ] =0x00 ; - macaddr->a[3 ] =0x12 ; - macaddr->a[4 ] =0x34 ; - macaddr->a[5 ] =0x56 + index++; + macaddr->a[3 ] =rand () %256 ; + macaddr->a[4 ] =rand () %256 ; + macaddr->a[5 ] = (rand () %256 + index++) %256 ; }/**
There is no overflow which must be handled because a[5] is an uint8_t value, so the assignment automatically limits the range to 0...255.
Is it reasonable to get a random mac address in your guest? I don't think so. It would no longer be possible to connect to a guest using ssh, restart that guest and connect again with ssh.
If you start more than one guest, you simply have to decide which mac address you want and tell it on the command line.
Stefan
Quoted 46 lines · Stefan Weil
Am 15.10.2013 06:17, schrieb Mike Qiu:
Quoted 45 lines
Changelog to v1:
Find remainder of macaddr->a[5] by modulo 256, otherwise it may be overflow by add index++.The default mac address is 52:54:00:12:34:56 + index, this will cause problem that when we boot up more than one guest with all mac addresses unset by default, assume that each guest has one nic. In this situation, all the guest's nic has the same mac address.
This patch is to solve this bug.
Signed-off-by Mike Qiu <[email protected]>--- net/net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)net/net.c +6
-3@@ -21,6 +21,8 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include <time.h> +#include "config-host.h" #include "net/net.h" @@ -147,12 +149,13 @@ void qemu_macaddr_default_if_unset(MACAddr *macaddr)if (memcmp (macaddr, &zero,sizeof (zero)) !=0 )return ; +srand ((unsigned )time (NULL )); macaddr->a[0 ] =0x52 ; macaddr->a[1 ] =0x54 ; macaddr->a[2 ] =0x00 ; - macaddr->a[3 ] =0x12 ; - macaddr->a[4 ] =0x34 ; - macaddr->a[5 ] =0x56 + index++; + macaddr->a[3 ] =rand () %256 ; + macaddr->a[4 ] =rand () %256 ; + macaddr->a[5 ] = (rand () %256 + index++) %256 ; }
Quoted 3 lines
net/net.c void qemu_macaddr_default_if_unset(MACAddr *macaddr) · line 161
Quoted 1 line
net/net.c +0
-0/** There is no overflow which must be handled because a[5] is an
uint8_tvalue, so the assignment automatically limits the range to 0...255.
OK, you are right, but I think we'd better to ensure this, even though a[5] is an uint8_t.
Quoted 3 lines
Is it reasonable to get a random mac address in your guest? I don't think so. It would no longer be possible to connect to a guest using ssh, restart that guest and connect again with ssh.
Why not? I have do the experiment, after reboot, the mac is not changed. and the ip address always the same.
And can be login to the guest after reboot.
Quoted 3 lines
If you start more than one guest, you simply have to decide which mac address you want and tell it on the command line.
Yes, mostly we should do this, but users sometimes not do this, so this interface should cover this situation.
Thank
Mike
Quoted 6 lines
Stefan
Am 15.10.2013 07:57, schrieb mike:
Quoted 51 lines · Stefan Weil
Quoted 40 lines
Am 15.10.2013 06:17, schrieb Mike Qiu:
Quoted 39 lines
Changelog to v1:
Find remainder of macaddr->a[5] by modulo 256, otherwise it may be overflow by add index++.The default mac address is 52:54:00:12:34:56 + index, this will cause problem that when we boot up more than one guest with all mac addresses unset by default, assume that each guest has one nic. In this situation, all the guest's nic has the same mac address.
This patch is to solve this bug.
Signed-off-by Mike Qiu <[email protected]>--- net/net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)net/net.c +0
-0@@ -21,6 +21,8 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/net/net.c +3
-2+#include <time.h> +#include "config-host.h" #include "net/net.h" @@ -147,12 +149,13 @@ void qemu_macaddr_default_if_unset(MACAddr *macaddr)if (memcmp (macaddr, &zero,sizeof (zero)) !=0 )return ; +srand ((unsigned )time (NULL )); macaddr->a[0 ] =0x52 ; macaddr->a[1 ] =0x54 ; macaddr->a[2 ] =0x00 ; - macaddr->a[3 ] =0x12 ; - macaddr->a[4 ] =0x34 ;Quoted 8 lines
net/net.c void qemu_macaddr_default_if_unset(MACAddr *macaddr) · line 161
Quoted 6 lines
net/net.c +3
-1- macaddr->a[5 ] =0x56 + index++; + macaddr->a[3 ] =rand () %256 ; + macaddr->a[4 ] =rand () %256 ; + macaddr->a[5 ] = (rand () %256 + index++) %256 ; }/** There is no overflow which must be handled because a[5] is an
uint8_tvalue, so the assignment automatically limits the range to 0...255.OK, you are right, but I think we'd better to ensure this, even though a[5] is an
uint8_t.
Quoted 7 lines
Quoted 3 lines
Is it reasonable to get a random mac address in your guest? I don't think so. It would no longer be possible to connect to a guest using ssh, restart that guest and connect again with ssh.
Why not? I have do the experiment, after reboot, the mac is not changed. and the ip address always the same.
And can be login to the guest after reboot.
"restart" means terminate QEMU and start it again.
Quoted 52 lines · Stefan Weil
Am 15.10.2013 07:57, schrieb mike:
Quoted 51 lines · Stefan Weil
Quoted 40 lines
Am 15.10.2013 06:17, schrieb Mike Qiu:
Quoted 39 lines
Changelog to v1:
Find remainder of macaddr->a[5] by modulo 256, otherwise it may be overflow by add index++.The default mac address is 52:54:00:12:34:56 + index, this will cause problem that when we boot up more than one guest with all mac addresses unset by default, assume that each guest has one nic. In this situation, all the guest's nic has the same mac address.
This patch is to solve this bug.
Signed-off-by Mike Qiu <[email protected]>--- net/net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)net/net.c +0
-0@@ -21,6 +21,8 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/net/net.c +3
-2+#include <time.h> +#include "config-host.h" #include "net/net.h" @@ -147,12 +149,13 @@ void qemu_macaddr_default_if_unset(MACAddr *macaddr)if (memcmp (macaddr, &zero,sizeof (zero)) !=0 )return ; +srand ((unsigned )time (NULL )); macaddr->a[0 ] =0x52 ; macaddr->a[1 ] =0x54 ; macaddr->a[2 ] =0x00 ; - macaddr->a[3 ] =0x12 ; - macaddr->a[4 ] =0x34 ;Quoted 8 lines
net/net.c void qemu_macaddr_default_if_unset(MACAddr *macaddr) · line 161
Quoted 6 lines
net/net.c +3
-1- macaddr->a[5 ] =0x56 + index++; + macaddr->a[3 ] =rand () %256 ; + macaddr->a[4 ] =rand () %256 ; + macaddr->a[5 ] = (rand () %256 + index++) %256 ; }/** There is no overflow which must be handled because a[5] is an
uint8_tvalue, so the assignment automatically limits the range to 0...255.OK, you are right, but I think we'd better to ensure this, even though a[5] is an
uint8_t.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Is it reasonable to get a random mac address in your guest? I don't think so. It would no longer be possible to connect to a guest using ssh, restart that guest and connect again with ssh.
Why not? I have do the experiment, after reboot, the mac is not changed. and the ip address always the same.
And can be login to the guest after reboot.
"restart" means terminate QEMU and start it again.
OK, qemu support the mac address unset right ?
So it may be a joke if just can start only one VM with mac address unset :).
In your case, also can use monitor to get the mac address, simply 'info network' :) Then you can do as if you set the mac address.
Thanks
Mike
Quoted 3 lines
Quoted 4 lines · Stefan Weil
Is it reasonable to get a random mac address in your guest? I don't think so. It would no longer be possible to connect to a guest using ssh, restart that guest and connect again with ssh.
Agreed - libvirt ALWAYS passes a MAC to qemu, even if the user did not specify a MAC to libvirt, precisely because the MAC must be reproducible rather than random to avoid changing the guest ABI. I don't think this patch is needed - it's up to management to use qemu correctly.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 8 lines · Eric Blake
Quoted 3 lines · Stefan Weil
Is it reasonable to get a random mac address in your guest? I don't think so. It would no longer be possible to connect to a guest using ssh, restart that guest and connect again with ssh.
Agreed - libvirt ALWAYS passes a MAC to qemu, even if the user did not specify a MAC to libvirt, precisely because the MAC must be reproducible rather than random to avoid changing the guest ABI. I don't think this patch is needed - it's up to management to use qemu correctly.
Yes, you are right in this condition. But qemu support Mac address unset. Also we can get the ip address through a lot of different ways, like use monitor to get the mac and then get the ip. So we can login use ssh.
But as you mentioned, this patch is not needed, I don't agree with you.
First, this patch just fix the Potential issue of this feature. Now libvirt maybe can't triggered this issue, who can promise in future will not.
The second is, qemu not only be used by libvirt, lots of developers like to use the command line to boot up the guest. And in the future, we are not sure about other program will use qemu.
The third is, when one feature has a issue in qemu, no matter when it is been triggered, should we not fix it?
Mike
Thanks
Stefan Hajnoczi
NAKQuoted 18 lines · mike
Quoted 8 lines · Eric Blake
Quoted 3 lines · Stefan Weil
Is it reasonable to get a random mac address in your guest? I don't think so. It would no longer be possible to connect to a guest using ssh, restart that guest and connect again with ssh.
Agreed - libvirt ALWAYS passes a MAC to qemu, even if the user did not specify a MAC to libvirt, precisely because the MAC must be reproducible rather than random to avoid changing the guest ABI. I don't think this patch is needed - it's up to management to use qemu correctly.
Yes, you are right in this condition. But qemu support Mac address unset. Also we can get the ip address through a lot of different ways, like use monitor to get the mac and then get the ip. So we can login use ssh.
But as you mentioned, this patch is not needed, I don't agree with you.
First, this patch just fix the Potential issue of this feature. Now libvirt maybe can't triggered this issue, who can promise in future will not.
Quoted 6 lines
The second is, qemu not only be used by libvirt, lots of developers like to use the command line to boot up the guest. And in the future, we are not sure about other program will use qemu.
The third is, when one feature has a issue in qemu, no matter when it is been triggered, should we not fix it?
NACK
I'm not going to merge this patch:
If you terminate QEMU and launch it again the NIC gets a different MAC address. Some guest operating systems are sensitive to this - under many Linux distros the network interfaces names change due to the MAC address change. As a result firewall configuration will break and other services may fail to start because they cannot find the interface.
If you have multiple guests or want control over the MAC address, set it explicitly using -device <nic-model>,mac=XX:XX:XX:XX:XX:XX.
Stefan
Quoted 23 lines · Stefan Hajnoczi
Quoted 22 lines · mike
Quoted 8 lines · Eric Blake
Quoted 3 lines · Stefan Weil
Is it reasonable to get a random mac address in your guest? I don't think so. It would no longer be possible to connect to a guest using ssh, restart that guest and connect again with ssh.
Agreed - libvirt ALWAYS passes a MAC to qemu, even if the user did not specify a MAC to libvirt, precisely because the MAC must be reproducible rather than random to avoid changing the guest ABI. I don't think this patch is needed - it's up to management to use qemu correctly.
Yes, you are right in this condition. But qemu support Mac address unset. Also we can get the ip address through a lot of different ways, like use monitor to get the mac and then get the ip. So we can login use ssh.
But as you mentioned, this patch is not needed, I don't agree with you.
First, this patch just fix the Potential issue of this feature. Now libvirt maybe can't triggered this issue, who can promise in future will not.
The second is, qemu not only be used by libvirt, lots of developers like to use the command line to boot up the guest. And in the future, we are not sure about other program will use qemu.
Quoted 8 lines
Quoted 2 lines
The third is, when one feature has a issue in qemu, no matter when it is been triggered, should we not fix it?
NACK
I'm not going to merge this patch:
If you terminate QEMU and launch it again the NIC gets a different MAC address. Some guest operating systems are sensitive to this - under
For these users must use -device <nic-model>,mac=XX:XX:XX:XX:XX:XX.
I think no body will boot up the guest, which sensitive to this, without mac address.
Actually, people use the command line without mac address, mean they mainly don't care about mac address, so give them random mac address is reasonable I think.
In my opinion, if we fix this, for qemu side no any issue, we both support mac address set or unset correctly.
What am I confuse is, *qemu supports mac address unset, why we force users must set the address when more than one guests*? This is unreasonable.
Quoted 3 lines
many Linux distros the network interfaces names change due to the MAC address change. As a result firewall configuration will break and other services may fail to start because they cannot find the interface.
Agree, so this mac address should set in qemu command line as libvirt does :)
Quoted 2 lines
If you have multiple guests or want control over the MAC address, set it explicitly using -device <nic-model>,mac=XX:XX:XX:XX:XX:XX.
Currently, especially for developers, people mainly use qemu command line directly, and as qemu supports mac address unset, they may try the simplest command line to boot up lots of guests, they will confuse about why all this guest use the same mac address.
Thanks
Mike
Quoted 4 lines
Stefan
Quoted 26 lines · mike
Quoted 6 lines
NACK
I'm not going to merge this patch:
If you terminate QEMU and launch it again the NIC gets a different MAC address. Some guest operating systems are sensitive to this - under
For these users must use -device <nic-model>,mac=XX:XX:XX:XX:XX:XX. I think no body will boot up the guest, which sensitive to this, without mac address.
Actually, people use the command line without mac address, mean they mainly don't care about mac address, so give them random mac address is reasonable I think.
In my opinion, if we fix this, for qemu side no any issue, we both support mac address set or unset correctly.
What am I confuse is, *qemu supports mac address unset, why we force users must set the address when more than one guests*? This is unreasonable.
Quoted 3 lines
many Linux distros the network interfaces names change due to the MAC address change. As a result firewall configuration will break and other services may fail to start because they cannot find the interface.
Agree, so this mac address should set in qemu command line as libvirt does :)
Quoted 7 lines
Quoted 2 lines
If you have multiple guests or want control over the MAC address, set it explicitly using -device <nic-model>,mac=XX:XX:XX:XX:XX:XX.
Currently, especially for developers, people mainly use qemu command line directly, and as qemu supports mac address unset, they may try the simplest command line to boot up lots of guests, they will confuse about why all this guest use the same mac address.
Your argument is weak: *you* want to avoid specifying the MAC address so in exchange you want to *break* existing configurations and force other people to start specifying a MAC address.
This doesn't improve anything, it will just annoy users and cause bug reports.
Sorry that there isn't a solution that satisfies everyone, you'll have to add a MAC address to your command-line.
Stefan
Quoted 29 lines · Stefan Hajnoczi
Quoted 28 lines · mike
Quoted 6 lines
NACK
I'm not going to merge this patch:
If you terminate QEMU and launch it again the NIC gets a different MAC address. Some guest operating systems are sensitive to this - under
For these users must use -device <nic-model>,mac=XX:XX:XX:XX:XX:XX. I think no body will boot up the guest, which sensitive to this, without mac address.
Actually, people use the command line without mac address, mean they mainly don't care about mac address, so give them random mac address is reasonable I think.
In my opinion, if we fix this, for qemu side no any issue, we both support mac address set or unset correctly.
What am I confuse is, *qemu supports mac address unset, why we force users must set the address when more than one guests*? This is unreasonable.
Quoted 3 lines
many Linux distros the network interfaces names change due to the MAC address change. As a result firewall configuration will break and other services may fail to start because they cannot find the interface.
Agree, so this mac address should set in qemu command line as libvirt does :)
Quoted 2 lines
If you have multiple guests or want control over the MAC address, set it explicitly using -device <nic-model>,mac=XX:XX:XX:XX:XX:XX.
Quoted 8 lines
Quoted 5 lines
Currently, especially for developers, people mainly use qemu command line directly, and as qemu supports mac address unset, they may try the simplest command line to boot up lots of guests, they will confuse about why all this guest use the same mac address.
Your argument is weak: *you* want to avoid specifying the MAC address so in exchange you want to *break* existing configurations and force other people to start specifying a MAC address.
OK, I do not want to break the existing configurations.
I'm fine if you do not want to merge this patch.
But I think this should be an issue of qemu, and need to do something on it, so I make this patch.
Can we try other solutions to solve this issue?
(if you agree this should be an issue)
Also this potential issue can happens if the user set the same mac address with more than one guest on one host.
Can we avoid this ?
Thanks
Mike
Quoted 10 lines
This doesn't improve anything, it will just annoy users and cause bug reports.
Sorry that there isn't a solution that satisfies everyone, you'll have to add a MAC address to your command-line.
Stefan
Quoted 48 lines · mike
On 10/18/2013 05:00 PM, Stefan Hajnoczi wrote:
On Fri, Oct 18, 2013 at 10:54:13AM +0800, mike wrote:
NACK
I'm not going to merge this patch:
If you terminate QEMU and launch it again the NIC gets a different MAC address. Some guest operating systems are sensitive to this - under
For these users must use -device <nic-model>,mac=XX:XX:XX:XX:XX:XX. I think no body will boot up the guest, which sensitive to this, without mac address.
Actually, people use the command line without mac address, mean they mainly don't care about mac address, so give them random mac address is reasonable I think.
In my opinion, if we fix this, for qemu side no any issue, we both support mac address set or unset correctly.
What am I confuse is, *qemu supports mac address unset, why we force users must set the address when more than one guests*? This is unreasonable.
many Linux distros the network interfaces names change due to the MAC address change. As a result firewall configuration will break and other services may fail to start because they cannot find the interface.
Agree, so this mac address should set in qemu command line as libvirt does :)
If you have multiple guests or want control over the MAC address, set it explicitly using -device <nic-model>,mac=XX:XX:XX:XX:XX:XX.
Currently, especially for developers, people mainly use qemu command line directly, and as qemu supports mac address unset, they may try the simplest command line to boot up lots of guests, they will confuse about why all this guest use the same mac address.
Your argument is weak: *you* want to avoid specifying the MAC address so in exchange you want to *break* existing configurations and force other people to start specifying a MAC address.
OK, I do not want to break the existing configurations.
Quoted 7 lines
I'm fine if you do not want to merge this patch.
But I think this should be an issue of qemu, and need to do something on it, so I make this patch.
Can we try other solutions to solve this issue?
(if you agree this should be an issue)
Options:
1. Set mac= on the command-line
2. Save the QEMU command-line in a script so the guest can be launched without remembering the details
3. Use -writeconfig/-readconfig to save the command-line to file and restore it
Option 2 or 3 are more convenient than Option 1. Does that help?
Finally, if random MACs are desirable for your particular use case, create a wrapper script that does something like:
#!/bin/bash
exec qemu-system-x86_64 "$@" -set device.mynic.mac=04:ab:cd:$((RANDOM % 256)):$((RANDOM % 256)):$((RANDOM % 256))
Quoted 4 lines
Also this potential issue can happens if the user set the same mac address with more than one guest on one host.
Can we avoid this ?
The same situation is possible on a physical LAN. MAC or IP collisions are configuration issues. I don't see collisions as a QEMU issue.
Stefan