Skip to contentSkip to conversation

patch: allow defining MAC address etc

Qemu-devel jamal 5 participants 11 messages Aug 21, 2005 – Aug 26, 2005

lore
Share & tools
lore

jamal

author
#0 lore raw

This attached patch is intended for allowing automated clever scripting for networking (tuntap only). Please read and apply if possible.

It does the following:
a) allow for specifying the guest netdevice interface MAC address (in addition to keeping the old functionality of specifying just the first one and letting qemu decide what subsequent ones should be) So now you can say something along the lines of:
"-nics 2 -macaddr0 00:11:a:0:2:19 -macaddr1 00:11:a:0:1:19" We allow upto 6 such MAC addresses to be specified. Maybe theres a more clever way to achieve this.

b) allows to specify an opaque integer to be passed to the host script. Such an integer is useful if you are creating many NICs and you want to do different things depending on what this extra parameter is; example you may wanna add/del a route for one but not other syntax is of the form: "-ID1 1 -ID2 2"
The IDs are mapped to the NICs. i.e ID1 maps to the first NIC and ID2 to the second etc. If you dont specify an ID, a 0 is used. Just like NICS/MACs we allow upto 6 such IDs to be specified.

c) In addition to receiving the tun device name as $1, the net setup script now receives $2 as the ID value and $3 as the guest MAC address.
I was thinking instead of passing the guest MAC, to allow the user to specify the IP address of the host side if needed but then figured that maybe introducing too many parameters around. The user can instead write a script which will configure the host side IP based on the ID passed. Also i could get rid of passing the MAC if deemed unneeded.

cheers,
jamal

vl.h +2 -1
@@ -238,7 +238,8 @@
 
 typedef struct NetDriverState {
     int index; /* index number in QEMU */
-    uint8_t macaddr[6];
+    uint8_t macaddr[6]; /* MAC of this netdevice */
+    int ID; /* opaque value we pass host scripts */
     char ifname[16];
     void (*send_packet)(struct NetDriverState *nd, 
                         const uint8_t *buf, int size);
vl.c +216 -7

294 lines not on this page · raw message

#1 lore raw
Quoted 11 lines · jamal

This attached patch is intended for allowing automated clever scripting for networking (tuntap only). Please read and apply if possible.

It does the following:
a) allow for specifying the guest netdevice interface MAC address (in addition to keeping the old functionality of specifying just the first one and letting qemu decide what subsequent ones should be) So now you can say something along the lines of:
"-nics 2 -macaddr0 00:11:a:0:2:19 -macaddr1 00:11:a:0:1:19" We allow upto 6 such MAC addresses to be specified. Maybe theres a more clever way to achieve this.

Maybe a comma separated list of MAC addresses. e.g. "-nics 2 macaddr 00:11:a:0:2:19,00:11:a:0:1:19"

Whatever you do, you should really support up to MAX_NICS addresses.

Quoted 8 lines

b) allows to specify an opaque integer to be passed to the host script. Such an integer is useful if you are creating many NICs and you want to do different things depending on what this extra parameter is; example you may wanna add/del a route for one but not other syntax is of the form: "-ID1 1 -ID2 2"
The IDs are mapped to the NICs. i.e ID1 maps to the first NIC and ID2 to the second etc. If you dont specify an ID, a 0 is used. Just like NICS/MACs we allow upto 6 such IDs to be specified.

Wouldn't it make more sense to just pass the mac address and/or the NIC number? Introducing yet another value seems unnecessarily complicated.

Paul

author
#2 lore raw
Quoted 13 lines · Paul Brook
Quoted 11 lines · jamal

This attached patch is intended for allowing automated clever scripting for networking (tuntap only). Please read and apply if possible.

It does the following:
a) allow for specifying the guest netdevice interface MAC address (in addition to keeping the old functionality of specifying just the first one and letting qemu decide what subsequent ones should be) So now you can say something along the lines of:
"-nics 2 -macaddr0 00:11:a:0:2:19 -macaddr1 00:11:a:0:1:19" We allow upto 6 such MAC addresses to be specified. Maybe theres a more clever way to achieve this.

Quoted 3 lines

Maybe a comma separated list of MAC addresses. e.g. "-nics 2 macaddr 00:11:a:0:2:19,00:11:a:0:1:19"

i could do this; macaddr is already being used to imply the start macaddr. Does macaddrs sound better?

Quoted 2 lines

Whatever you do, you should really support up to MAX_NICS addresses.

ok

Quoted 9 lines
Quoted 8 lines

b) allows to specify an opaque integer to be passed to the host script. Such an integer is useful if you are creating many NICs and you want to do different things depending on what this extra parameter is; example you may wanna add/del a route for one but not other syntax is of the form: "-ID1 1 -ID2 2"
The IDs are mapped to the NICs. i.e ID1 maps to the first NIC and ID2 to the second etc. If you dont specify an ID, a 0 is used. Just like NICS/MACs we allow upto 6 such IDs to be specified.

Quoted 3 lines

Wouldn't it make more sense to just pass the mac address and/or the NIC number? Introducing yet another value seems unnecessarily complicated.

The NIC number would not be sufficient for what i want; As an example, I could use the ID to tell me the "type" of processing needed. Example test script:

---
if [ $2 = "0" ]; then
#not really visible from host
/usr/sbin/brctl addif base $1
/sbin/ifconfig $1 up
fi
if [ $2 = "1" ]; then

        .....
        ...
fi
if [ $2 = "2" ]; then
        #visible from host; give it an IP address
        /sbin/ifconfig $1 10.0.3.24 netmask 255.255.255.0 up
        /sbin/route add 10.0.3.25 dev $1

fi
---------

If i was to get rid of anything it probably would be the MAC address of the guest since this is a host side setup. So i would like to keep the ID but could let go of the guest MAC. Thoughts?

cheers,
jamal

#3 lore raw
Quoted 14 lines · jamal
Quoted 13 lines · Paul Brook
Quoted 11 lines · jamal

This attached patch is intended for allowing automated clever scripting for networking (tuntap only). Please read and apply if possible.

It does the following:
a) allow for specifying the guest netdevice interface MAC address (in addition to keeping the old functionality of specifying just the first one and letting qemu decide what subsequent ones should be) So now you can say something along the lines of:
"-nics 2 -macaddr0 00:11:a:0:2:19 -macaddr1 00:11:a:0:1:19" We allow upto 6 such MAC addresses to be specified. Maybe theres a more clever way to achieve this.

Quoted 5 lines
Quoted 2 lines

Maybe a comma separated list of MAC addresses. e.g. "-nics 2 macaddr 00:11:a:0:2:19,00:11:a:0:1:19"

i could do this; macaddr is already being used to imply the start macaddr. Does macaddrs sound better?

Part of the reason I suggested this was because it is an extension of the existing option. A user can either specifies a single address and have qemu assign sequential addresses (the current behaviour), or they can specify a list of addresses, one for each NIC.

Quoted 34 lines
Quoted 1 line

Whatever you do, you should really support up to MAX_NICS addresses.

ok

Quoted 11 lines
Quoted 8 lines

b) allows to specify an opaque integer to be passed to the host script. Such an integer is useful if you are creating many NICs and you want to do different things depending on what this extra parameter is; example you may wanna add/del a route for one but not other syntax is of the form: "-ID1 1 -ID2 2"
The IDs are mapped to the NICs. i.e ID1 maps to the first NIC and ID2 to the second etc. If you dont specify an ID, a 0 is used. Just like NICS/MACs we allow upto 6 such IDs to be specified.

Wouldn't it make more sense to just pass the mac address and/or the NIC number? Introducing yet another value seems unnecessarily complicated.

The NIC number would not be sufficient for what i want; As an example, I could use the ID to tell me the "type" of processing needed. Example test script:

---
if [ $2 = "0" ]; then
#not really visible from host
/usr/sbin/brctl addif base $1
/sbin/ifconfig $1 up
fi
if [ $2 = "1" ]; then

        .....
        ...
fi
if [ $2 = "2" ]; then
        #visible from host; give it an IP address
        /sbin/ifconfig $1 10.0.3.24 netmask 255.255.255.0 up
        /sbin/route add 10.0.3.25 dev $1
Quoted 6 lines

fi
---------

If i was to get rid of anything it probably would be the MAC address of the guest since this is a host side setup. So i would like to keep the ID but could let go of the guest MAC. Thoughts?

Your script should be able to get all the information it needs from the MAC address. You can either hardcode addresses or do pattern matching. The guest MAC address is arbitrary, so you can choose whatever numbering is convenient. For example you could use the last digit of the address to encode your ID field. Your script would then look like:

case $2 in
*0)

   # do something
   ;;
  *1)
  # do something else
   ;;
  [etc]
esac

Paul

author
#4 lore raw
Quoted 10 lines · Paul Brook
Quoted 2 lines · jamal

i could do this; macaddr is already being used to imply the start macaddr. Does macaddrs sound better?

Part of the reason I suggested this was because it is an extension of the existing option. A user can either specifies a single address and have qemu assign sequential addresses (the current behaviour), or they can specify a list of addresses, one for each NIC.

it may be easier parsing to avoid having optional fields. Is there any other parameter that has optional fields?

Quoted 5 lines

Your script should be able to get all the information it needs from the MAC address. You can either hardcode addresses or do pattern matching. The guest MAC address is arbitrary, so you can choose whatever numbering is convenient. For example you could use the last digit of the address to encode your ID field.

The only problem is that would tie the two things (MAC + ID) together. i.e it would not be possible to just pass the ids without specifying macs. Note the Ids syntax would also be comma separated.

cheers,
jamal

author
#5 lore raw
Quoted 2 lines · jamal

Note the Ids syntax would also be comma separated.

Actually no - this would need to have the IDx prefix so that you can pass the ID for non-sequential NICS. Example -ID2 0 , -ID5 3 and the rest get a default which is zero.

cheers,
jamal

#8 lore raw
In reply to jamal
Quoted 10 lines · jamal
Quoted 5 lines

Your script should be able to get all the information it needs from the MAC address. You can either hardcode addresses or do pattern matching. The guest MAC address is arbitrary, so you can choose whatever numbering is convenient. For example you could use the last digit of the address to encode your ID field.

The only problem is that would tie the two things (MAC + ID) together. i.e it would not be possible to just pass the ids without specifying macs.

As it should be. A macaddr identified each NIC in the virtual computer uniquely. Both within the guest and across guests (if you are running multiple qemu VMs with tuntap networking).

A discussion on IRC before lead to the idea that, if a script should handle multiple guests, qemu should pass the macaddr in $2 to allow the script to identify the guest NIC. That is the only thing needed to uniquely identify a guest, there should be no need for a separate ID.

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
#6 lore raw
In reply to jamal
Quoted 11 lines · jamal
Quoted 2 lines · jamal

Note the Ids syntax would also be comma separated.

Actually no - this would need to have the IDx prefix so that you can pass the ID for non-sequential NICS. Example -ID2 0 , -ID5 3 and the rest get a default which is zero.

cheers,
jamal

Nah, you could do something like -ID ,4,3,,,5,,7,,,9 with the spaces between the commas getting the default value. If you have more NICs past the last one you manually specify an ID to, those also get the default ID. (Granted, not the best way to do it if you plan to skip a lot of NICs at the beginning or the middle.)

Of course, since you'd have to specify a macaddr for each NIC anyways, might as well just use that as the ID.

Signature · 2 lines
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.
author
#7 lore raw
Quoted 2 lines · Jim C. Brown

Of course, since you'd have to specify a macaddr for each NIC anyways, might as well just use that as the ID.

Since this seems to be the most popular approach i will create a patch with this approach later on today or early AM tommorow.

cheers,
jamal

#9 lore raw
In reply to Paul Brook
Quoted 15 lines · Paul Brook
Quoted 11 lines · jamal

This attached patch is intended for allowing automated clever scripting for networking (tuntap only). Please read and apply if possible.

It does the following:
a) allow for specifying the guest netdevice interface MAC address (in addition to keeping the old functionality of specifying just the first one and letting qemu decide what subsequent ones should be) So now you can say something along the lines of:
"-nics 2 -macaddr0 00:11:a:0:2:19 -macaddr1 00:11:a:0:1:19" We allow upto 6 such MAC addresses to be specified. Maybe theres a more clever way to achieve this.

Quoted 2 lines

Maybe a comma separated list of MAC addresses. e.g. "-nics 2 macaddr 00:11:a:0:2:19,00:11:a:0:1:19"

I propose:

-nics 2 -macaddr 00:11:a:0:2:19 -macaddr 00:11:a:0:1:19

For the future, I would like to change the networks options to have something like:

-net usernet,macaddr=00:11:a:0:2:19 -net tunfd=10,macaddr=00:11:a:0:1:19

to be consistent with the character devices.

Fabrice.

#10 lore raw
Quoted 5 lines · Fabrice Bellard

For the future, I would like to change the networks options to have something like:

-net usernet,macaddr=00:11:a:0:2:19 -net tunfd=10,macaddr=00:11:a:0:1:19

to be consistent with the character devices.

I like this. May even give it a stab as I have already messed around with this code in my TUN/TAP cleanups announced some months ago (patch reattached here), and the syntax above would make some of what I did there a bit cleaner.

Regards
Henrik