summaryrefslogtreecommitdiff
path: root/net.c
AgeCommit message (Collapse)AuthorFilesLines
2009-10-27qdev: add netdev propertyGerd Hoffmann1-1/+1
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-27net: add macaddr type.Gerd Hoffmann1-0/+15
Add new type for mac addresses. Add function which sets the qemu default mac address if it finds the mac address uninitialized (i.e. all zeros). Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: fix multiple NICs causing net opts process to stopMark McLoughlin1-1/+3
For NICs, net_init_client() returns the index into the NICInfo table. qemu_opts_foreach() interprets non-zero as an error return an stops iterating over the options. So, if you have more than one '-net nic' on the command line, subsequent '-net' options do not get processed. Fix this by making net_client_init() only return non-zero if net_init_client() returns an error. Reported-by: Peter Lieven <pl@dlh.net> Patchworks-ID: 35736 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: add queue for peer-to-peer packet forwardingMark McLoughlin1-13/+98
Now that we have re-factored the packet queue code, we can re-use it for peer-to-peer also. Patchworks-ID: 35520 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: refactor packet queueing codeMark McLoughlin1-115/+23
The packet queue code is fairly standalone, has some complex details and easily reusable. It makes sense to split it out on its own. This patch doesn't contain any functional changes. Patchworks-ID: 35511 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: allow NICs to be connected to netdevsMark McLoughlin1-10/+25
Introduce a 'peer' member to VLANClientState as an alternative to a vlan. The idea being that packets are transfered directly from peer clients rather than going through a vlan. Patchworks-ID: 35516 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: add -net nic,netdev= optionMark McLoughlin1-5/+36
Patchworks-ID: 35515 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: maintain a list of vlan-less clientsMark McLoughlin1-2/+11
Allows them to be cleaned up at shutdown. This is pretty lame, but will eventually go away as we make vlans the special case. Patchworks-ID: 35518 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: handle -netdevice optionsMark McLoughlin1-36/+92
Same as for -net except for: - only tap, user, vde and socket types are supported - the vlan parameter is not allowed - the name parameter is not allowed but the id parameter is required Patchworks-ID: 35517 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: add QemuOptsList arg to net_client_parse()Mark McLoughlin1-3/+4
Patchworks-ID: 35505 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: allow clients not associated with a vlanMark McLoughlin1-7/+23
Allow net clients to be created which are not connected to any vlan. This is needed by Gerd in order to allow adding -device nic, where the absence of a vlan parameter will not imply vlan=0. Also needed to allow adding a -netdevice option which doesn't connect the backend to a vlan. Patchworks-ID: 35513 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: use qtailq for vlan and client listsMark McLoughlin1-58/+58
Patchworks-ID: 35507 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: remove id field from NICInfoMark McLoughlin1-4/+0
Just use the name field instead since we now use the id paramater as the name, if supplied. Only implication with this change is that if id is not supplied, the value of the name paramater is used as an id. Patchworks-ID: 35512 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: handle id= parameter for -netMark McLoughlin1-28/+20
Use id= in the same was as the current name= parameter; if both are specified, id= is used. Patchworks-ID: 35514 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-15net: pass monitor handle to client init functionsMark McLoughlin1-1/+1
Needed for e.g. looking up a file descriptor name using monitor_get_fd() in net_init_tap() Patchworks-ID: 35509 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-12slirp: fix !CONFIG_SLIRP compilationJuan Quintela1-1/+4
This moves the code that depens on slirp under CONFIG_SLIRP again. Patchworks-ID: 35372 Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Final net cleanup after conversion to QemuOptsMark McLoughlin1-58/+58
Now that net_client_init() has no users, kill it off and rename net_client_init_from_opts(). There is no further need for the old code in net_client_parse() either. We use qemu_opts_parse() 'firstname' facitity for that. Instead, move the special handling of the 'vmchannel' type there. Simplify the vl.c code into merely call net_client_parse() for each -net command line option and then calling net_init_clients() later to iterate over the options and create the clients. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Port usb net to QemuOptsMark McLoughlin1-1/+1
We need net_client_init_from_opts() exported for this Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Port host_net_add monitor command to QemuOptsMark McLoughlin1-2/+13
Here is where we rely on qemu_opts_parse() to handle an empty string. We could alternatively explicitly handle this here by using qemu_opts_create() when we're not supplied any parameters, but its cleaner this way. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Clean up legacy code in net_client_init()Mark McLoughlin1-44/+14
Now that we've ported everything over to QemuOpts, we can kill off all the cruft in net_client_init(). Note, the 'channel' type requires special handling as it uses a format that QemuOpts can't parse Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Port -net dump to QemuOptsMark McLoughlin1-12/+42
Note, not incrementing nb_host_devs in net_init_dump() is intentional. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Port -net vde to QemuOptsMark McLoughlin1-36/+58
The net_vde_init() change is needed because we now pass NULL pointers instead of empty strings for group/sock if they're not set. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Port -net socket to QemuOptsMark McLoughlin1-59/+109
Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Port -net tap to QemuOptsMark McLoughlin1-90/+140
Some parameters are not valid with fd=. Rather than having a separate parameter description table for validating fd=, it's easir to just check for those invalid parameters later. Note, the need to possible lookup a file descriptor name from the monitor is the reason why all these init functions are passed a Monitor pointer. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Port -net user to QemuOptsMark McLoughlin1-106/+161
The handling of guestfwd and hostfwd requires the previous changes to allow multiple values for each parameter. The only way to access those multiple values is to use qemu_opt_foreach(). Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Port -net none and -net nic to QemuOptsMark McLoughlin1-77/+160
We use a table of network types to look up the initialization function and parameter descriptions in net_client_init(). For now, we use QemuOpts for the 'none' and 'nic' types. Subsequent patches port the other types too and the special casing is removed. We're not parsing the full -net option string here as the type has been stripped from the string, so we do not use qemu_opts_parse() 'firstname' facility. This will also be rectified in subsequent patches. No functional changes are introduced by this patch. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Drop config_error(), use qemu_error() insteadMarkus Armbruster1-72/+55
Diagnostic output goes to stderr, except when we're in a monitor command, when it goes to the monitor instead. config_error() implements this with a monitor argument: if it's non-null, report there, else to stderr. This obliges us to pass the monitor down various call chains, to make it available to config_error(). The recently created qemu_error() doesn't need a monitor argument to route output. Use it. There's one user-visible difference: config_error() prepended "qemu: " to a message bound for stderr. qemu_error() doesn't, which means the prefix goes away with this commit. If such a prefix is desired for stderr, then I figure it should be slapped on all error messages, not just the ones that used to go through config_error(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Don't exit() in config_error()Markus Armbruster1-36/+47
Propagating errors up the call chain is tedious. In startup code, we can take a shortcut: terminate the program. This is wrong elsewhere, the monitor in particular. config_error() tries to cater for both customers: it terminates the program unless its mon parameter tells it it's working for the monitor. Its users need to return status anyway (unless passing a null mon argument, which none do), which their users need to check. So this automatic exit buys us exactly nothing useful. Only the dangerous delusion that we can get away without returning status. Some of its users fell for that. Their callers continue executing after failure when working for the monitor. This bites monitor command host_net_add in two places: * net_slirp_init() continues after slirp_hostfwd(), slirp_guestfwd(), or slirp_smb() failed, and may end up reporting success. This happens for "host_net_add user guestfwd=foo": it complains about the invalid guest forwarding rule, then happily creates the user network without guest forwarding. * net_client_init() can't detect slirp_guestfwd() failure, and gets fooled by net_slirp_init() lying about success. Suppresses its "Could not initialize device" message. Add the missing error reporting, make sure errors are checked, and drop the exit() from config_error(). Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Make net_client_init() consume slirp_configs even on errorMarkus Armbruster1-5/+7
net_slirp_init() walks slirp_configs, and stops when it encounters one that doesn't work. Instead of consuming slirp_configs members there, consume them in the sole caller. This makes sure all are consumed. Before, the tail starting with the non-working one was left in place, where it made the next net_slirp_init() fail again. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Use qemu_strdup() for VLANClientState string fieldsMark McLoughlin1-7/+7
Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Move memset() from net_client_uninit() to net_client_init()Mark McLoughlin1-1/+2
zeroing a structure before using it is more common than zeroing after using it. Also makes the setting of nd->used more obvious. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Make NICInfo string fields non-constMark McLoughlin1-4/+4
We now only assign strdup()ed strings to these fields, never static strings. aliguori: fix build for ppc_prep and mips_jazz Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-06Use qemu_strdup() for NICInfo string fieldsMark McLoughlin1-4/+4
Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-05Fix pci_add nic not to exit on bad modelMarkus Armbruster1-16/+25
Monitor command "pci_add ADDR nic model=MODEL" uses pci_nic_init() to create the NIC. When MODEL is unknown or "?", this prints to stderr and terminates the program. Change pci_nic_init() not to treat "?" specially, and to return NULL on failure. Switch uses during startup to new convenience wrapper pci_nic_init_nofail(), which behaves just like pci_nic_init() used to do. Bonus bug fix: we now check for qdev_init() failing there. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-05Make it obvious that pci_nic_init() can't failMarkus Armbruster1-3/+3
Before this patch, pci_nic_init() returns NULL when it can't find the model in pci_nic_models[]. Except this can't happen, because qemu_check_nic_model_list() just searched for model in pci_nic_models[], and terminated the program on failure. Repeating the search here is pointless. Instead, change qemu_check_nic_model_list() to return the model's array index. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-05Correctly free nd structureGlauber Costa1-2/+7
When we "free" a NICInfo structure, we can leak pointers, since we don't do much more than setting used = 0. We free() the model parameter, but we don't set it to NULL. This means that a new user of this structure will see garbage in there. It was not noticed before because reusing a NICInfo is not that common, but it can be, for users of device pci hotplug. A user hit it, described at https://bugzilla.redhat.com/show_bug.cgi?id=524022 This patch memset's the whole structure, guaranteeing that anyone reusing it will see a fresh NICinfo. Also, we free some other strings that are currently leaking. This codebase is quite old, so this patch should feed all stable trees. Signed-off-by: Glauber Costa <glommer@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-09-30net: fix coding style nitMichael S. Tsirkin1-1/+1
Put space between = and - assigning a negative number to avoid confusion with old-style "-=" (which we also have, and need to be fixed). Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-09-12Fix sys-queue.h conflict for goodBlue Swirl1-26/+25
Problem: Our file sys-queue.h is a copy of the BSD file, but there are some additions and it's not entirely compatible. Because of that, there have been conflicts with system headers on BSD systems. Some hacks have been introduced in the commits 15cc9235840a22c289edbe064a9b3c19c5f49896, f40d753718c72693c5f520f0d9899f6e50395e94, 96555a96d724016e13190b28cffa3bc929ac60dc and 3990d09adf4463eca200ad964cc55643c33feb50 but the fixes were fragile. Solution: Avoid the conflict entirely by renaming the functions and the file. Revert the previous hacks. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-09-11Unexport ticks_per_sec variable. Create get_ticks_per_sec() functionJuan Quintela1-1/+1
Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-09-04Include sys-queue.h early to override system queue definitions on BSDBlue Swirl1-0/+2
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2009-09-04monitor: Port handler_3 to use QDictLuiz Capitulino1-4/+8
This commit ports command handlers that receive three arguments to use the new monitor's dictionary. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-09-04monitor: Port handler_2 to use QDictLuiz Capitulino1-3/+10
This commit ports command handlers that receive two arguments to use the new monitor's dictionary. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-09-04net: Fix send queue orderingJan Kiszka1-17/+12
Ensure that packets enqueued for delayed delivery are dequeued in FIFO order. At least one simplistic guest TCP/IP stack became unhappy due to sporadically reordered packet streams. At this chance, switch the send queue implementation to TAILQ. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-24Add missing linefeed in error messageStefan Weil1-1/+1
The error message for an unknown network device given to monitor command set_link looks better with a terminating linefeed. Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-08-10net: Fix do_set_link() return typeLuiz Capitulino1-4/+2
do_set_link() returns int, but Monitor handler functions should always return void. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Message-Id:
2009-07-27rename HOST_BSD to CONFIG_BSDJuan Quintela1-3/+3
Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-27Remove useless Win32 include files and unused function in net.c.Filip Navara1-29/+0
Signed-off-by: Filip Navara <filip.navara@gmail.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-27slirp: Fix guestfwd for incoming dataJan Kiszka1-5/+6
Unless a virtual server address was explicitly defined (which is impossible with the legacy -net channel format), guestfwd did not properly forwarded host->guest packets. This patch fixes it. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-27Add support for fd=name to tap and socket networkingMark McLoughlin1-7/+35
This allows a program to initialize a host networking device using a file descriptor passed over a unix monitor socket. The program must first pass the file descriptor using SCM_RIGHTS ancillary data with the getfd monitor command. It then may do "host_net_add tap fd=name" to use the named file descriptor. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-16qdev: add id= support for pci nics.Gerd Hoffmann1-1/+4
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>