1. 23 7月, 2012 3 次提交
    • L
      convert net_init_nic() to NetClientOptions · 2456f36f
      Laszlo Ersek 提交于
      v1->v2:
      - NetLegacyNicOptions::vectors is of type uint32
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
      2456f36f
    • L
      convert net_client_init() to OptsVisitor · 6687b79d
      Laszlo Ersek 提交于
      The net_client_init() prototype is kept intact.
      
      Based on "is_netdev", the QemuOpts-rooted QemuOpt-list is parsed as a
      Netdev or a NetLegacy. The original meat of net_client_init() is moved to
      and simplified in net_client_init1():
      
      Fields not common between -net and -netdev are clearly separated. Getting
      the name for the init functions is cleaner: Netdev::id is mandatory, and
      all init functions handle a NULL NetLegacy::name. NetLegacy::vlan
      explicitly depends on -net (see below).
      
      Verifying the "type=" option for -netdev can be turned into a switch.
      
      Format validation with qemu_opts_validate() can be removed because the
      visitor covers it. Relatedly, the "net_client_types" array is reduced to
      an array of init functions that can be directly indexed by opts->kind.
      (Help text is available in the schema JSON.)
      
      The outermost negation in the condition around qemu_find_vlan() was
      flattened, because it expresses the dependent code's requirements more
      clearly.
      
      VLAN lookup is avoided if there's no init function to pass the VLAN to.
      
      Whenever the value of type=... is needed, we substitute
      NetClientOptionsKind_lookup[kind].
      
      The individual init functions are not converted yet, thus the original
      QemuOpts instance is passed transparently.
      
      v1->v2:
      - NetLegacy::name is optional. Tracked it through all init functions: they
        all handle a NULL name. Updated commit message accordingly.
      
      v2->v3:
      - NetLegacy::id is allowed and takes precedence over NetLegacy::name.
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
      6687b79d
    • L
      hw, net: "net_client_type" -> "NetClientOptionsKind" (qapi-generated) · 2be64a68
      Laszlo Ersek 提交于
      NET_CLIENT_TYPE_ -> NET_CLIENT_OPTIONS_KIND_
      Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
      Signed-off-by: NStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
      2be64a68
  2. 08 6月, 2012 1 次提交
    • M
      change iov_* function prototypes to be more appropriate · dcf6f5e1
      Michael Tokarev 提交于
      Reorder arguments to be more natural, readable and
      consistent with other iov_* functions, and change
      argument names, from:
       iov_from_buf(iov, iov_cnt, buf, iov_off, size)
      to
       iov_from_buf(iov, iov_cnt, offset, buf, bytes)
      
      The result becomes natural English:
      
       copy data to this `iov' vector with `iov_cnt'
       elements starting at byte offset `offset'
       from memory buffer `buf', processing `bytes'
       bytes max.
      
      (Try to read the original prototype this way).
      
      Also change iov_clear() to more general iov_memset()
      (it uses memset() internally anyway).
      
      While at it, add comments to the header file
      describing what the routines actually does.
      
      The patch only renames argumens in the header, but
      keeps old names in the implementation.  The next
      patch will touch actual code to match.
      
      Now, it might look wrong to pay so much attention
      to so small things.  But we've so many badly designed
      interfaces already so the whole thing becomes rather
      confusing or error prone.  One example of this is
      previous commit and small discussion which emerged
      from it, with an outcome that the utility functions
      like these aren't well-understdandable, leading to
      strange usage cases.  That's why I paid quite some
      attention to this set of functions and a few
      others in subsequent patches.
      Signed-off-by: NMichael Tokarev <mjt@tls.msk.ru>
      dcf6f5e1
  3. 05 6月, 2012 6 次提交
  4. 16 3月, 2012 1 次提交
  5. 04 2月, 2012 1 次提交
  6. 02 2月, 2012 1 次提交
    • C
      Add support for net bridge · a7c36ee4
      Corey Bryant 提交于
      The most common use of -net tap is to connect a tap device to a bridge.  This
      requires the use of a script and running qemu as root in order to allocate a
      tap device to pass to the script.
      
      This model is great for portability and flexibility but it's incredibly
      difficult to eliminate the need to run qemu as root.  The only really viable
      mechanism is to use tunctl to create a tap device, attach it to a bridge as
      root, and then hand that tap device to qemu.  The problem with this mechanism
      is that it requires administrator intervention whenever a user wants to create
      a guest.
      
      By essentially writing a helper that implements the most common qemu-ifup
      script that can be safely given cap_net_admin, we can dramatically simplify
      things for non-privileged users.  We still support existing -net tap options
      as a mechanism for advanced users and backwards compatibility.
      
      Currently, this is very Linux centric but there's really no reason why it
      couldn't be extended for other Unixes.
      
      A typical invocation would be similar to one of the following:
      
        qemu linux.img -net bridge -net nic,model=virtio
      
        qemu linux.img -net tap,helper="/usr/local/libexec/qemu-bridge-helper"
                       -net nic,model=virtio
      
        qemu linux.img -netdev bridge,id=hn0
                       -device virtio-net-pci,netdev=hn0,id=nic1
      
        qemu linux.img -netdev tap,helper="/usr/local/libexec/qemu-bridge-helper",id=hn0
                       -device virtio-net-pci,netdev=hn0,id=nic1
      
      The default bridge that we attach to is br0.  The thinking is that a distro
      could preconfigure such an interface to allow out-of-the-box bridged networking.
      
      Alternatively, if a user wants to use a different bridge, a typical invocation
      would be simliar to one of the following:
      
        qemu linux.img -net bridge,br=qemubr0 -net nic,model=virtio
      
        qemu linux.img -net tap,helper="/usr/local/libexec/qemu-bridge-helper --br=qemubr0"
                       -net nic,model=virtio
      
        qemu linux.img -netdev bridge,br=qemubr0,id=hn0
                       -device virtio-net-pci,netdev=hn0,id=nic1
      
        qemu linux.img -netdev tap,helper="/usr/local/libexec/qemu-bridge-helper --br=qemubr0",id=hn0
                       -device virtio-net-pci,netdev=hn0,id=nic1
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      Signed-off-by: NRicha Marwaha <rmarwah@linux.vnet.ibm.com>
      Signed-off-by: NCorey Bryant <coreyb@linux.vnet.ibm.com>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      a7c36ee4
  7. 13 1月, 2012 1 次提交
  8. 06 12月, 2011 1 次提交
  9. 02 11月, 2011 1 次提交
  10. 21 8月, 2011 1 次提交
  11. 23 7月, 2011 4 次提交
    • J
      net: Consistently use qemu_macaddr_default_if_unset · 6eed1856
      Jan Kiszka 提交于
      Drop the open-coded MAC assignment from net_init_nic and replace it with
      standard qemu_macaddr_default_if_unset which is also used by qdev. That
      avoid creating colliding MACs when instantiating NICs via different
      mechanisms.
      
      This change requires to store the MAC as MACAddr in NICInfo, and the
      remaining nd_table users need to be updated.
      
      Based on suggestion by Peter Maydell.
      
      CC: Markus Armbruster <armbru@redhat.com>
      CC: Peter Maydell <peter.maydell@linaro.org>
      Signed-off-by: NJan Kiszka <jan.kiszka@siemens.com>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      6eed1856
    • J
      net: Dump client type 'info network' · 44e798d3
      Jan Kiszka 提交于
      Include the client type name into the output of 'info network'. The
      result looks like this:
      
      (qemu) info network
      VLAN 0 devices:
        rtl8139.0: type=nic,model=rtl8139,macaddr=52:54:00:12:34:57
      Devices not on any VLAN:
        virtio-net-pci.0: type=nic,model=virtio-net-pci,macaddr=52:54:00:12:34:56
         \ network1: type=tap,fd=5
      
      CC: Markus Armbruster <armbru@redhat.com>
      Signed-off-by: NJan Kiszka <jan.kiszka@siemens.com>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      44e798d3
    • J
      net: Refactor net_client_types · 6f7b3b1b
      Jan Kiszka 提交于
      Position entries of net_client_types according to the corresponding
      values of NET_CLIENT_TYPE_*. The array size is now defined by
      NET_CLIENT_TYPE_MAX. This will allow to obtain entries based on type
      value in later patches.
      
      At this chance rename NET_CLIENT_TYPE_SLIRP to NET_CLIENT_TYPE_USER for
      the sake of consistency.
      
      CC: Markus Armbruster <armbru@redhat.com>
      Signed-off-by: NJan Kiszka <jan.kiszka@siemens.com>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      6f7b3b1b
    • J
      net: Improve layout of 'info network' · 19061e63
      Jan Kiszka 提交于
      Improve the layout when listing non-vlan clients via 'info network'. The
      result looks like this:
      
      (qemu) info network
      Devices not on any VLAN:
        orphan: net=10.0.2.0, restricted=n
        virtio-net-pci.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56
         \ network2: fd=5
        e1000.0: model=e1000,macaddr=52:54:00:12:34:57
         \ network1: net=10.0.2.0, restricted=n
        rtl8139.0: model=rtl8139,macaddr=52:54:00:12:34:58
      
      ie. peers are grouped, orphans are listed as before.
      
      CC: Markus Armbruster <armbru@redhat.com>
      Signed-off-by: NJan Kiszka <jan.kiszka@siemens.com>
      Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
      19061e63
  12. 19 7月, 2011 2 次提交
    • M
      Fix netdev name lookup in -device, device_add, netdev_del · 85dde9a9
      Markus Armbruster 提交于
      qemu_find_netdev() looks up members of non_vlan_clients by name.  It
      happily returns the first match.  Trouble is the names need not be
      unique.
      
      non_vlan_clients contains host parts (netdevs) and guest parts (NICs).
      
      Netdevs have unique names: a netdev's name is a (mandatory)
      qemu_netdev_opts ID, and these are unique.
      
      NIC names are not unique.  If a NIC has a qdev ID (which is unique),
      that's its name.  Else, we make up a name.  The made-up names are
      unique, but they can clash with qdev IDs.  Even if NICs had unique
      names, they could still clash with netdev names.
      
      Callers of qemu_find_netdev():
      
      * net_init_nic() wants a netdev.  It happens to work because it runs
        before NICs get added to non_vlan_clients.
      
      * do_netdev_del() wants a netdev.  If it gets a NIC, it complains and
        fails.  Bug: a netdev with the same name that comes later in
        non_vlan_clients can't be deleted:
      
          $ qemu-system-x86_64 -nodefaults -vnc :0 -S -monitor stdio -netdev user,id=hostnet0 -device virtio-net-pci,netdev=hostnet0,id=virtio1
          [...]
          (qemu) netdev_add user,id=virtio1
          (qemu) info network
          Devices not on any VLAN:
            hostnet0: net=10.0.2.0, restricted=n peer=virtio1
            virtio1: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=hostnet0
            virtio1: net=10.0.2.0, restricted=n
          (qemu) netdev_del virtio1
          Device 'virtio1' not found
      
      * parse_netdev() wants a netdev.  If it gets a NIC, it gets confused.
        With the test setup above:
      
          (qemu) device_add virtio-net-pci,netdev=virtio1
          Property 'virtio-net-pci.netdev' can't take value 'virtio1', it's in use
      
        You can even connect two NICs to each other:
      
          $ qemu-system-x86_64 -nodefaults -vnc :0 -S -monitor stdio -device virtio-net-pci,id=virtio1 -device e1000,netdev=virtio1
          [...]
          Devices not on any VLAN:
            virtio1: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=e1000.0
            e1000.0: model=e1000,macaddr=52:54:00:12:34:57 peer=virtio1
          (qemu) q
          Segmentation fault (core dumped)
      
      * do_set_link() works fine for both netdevs and NICs.  Whether it
        really makes sense for netdevs is debatable, but that's outside this
        patch's scope.
      
      Change qemu_find_netdev() to return only netdevs.  This fixes the
      netdev_del and device_add/-device bugs demonstrated above.
      
      To avoid changing set_link, make do_set_link() search non_vlan_clients
      by hand instead of calling qemu_find_netdev().
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      85dde9a9
    • M
      Fix automatically assigned network names for netdev · 53e51d85
      Markus Armbruster 提交于
      If a network client doesn't have a name, we make one up, with
      assign_name().  assign_name() creates a name MODEL.NUM, where MODEL is
      the client's model, and NUM is the number of MODELs that already
      exist.
      
      Bug: it misses clients that are not on a VLAN, i.e. netdevs and the
      NICs using them:
      
          $ qemu-system-x86_64 -nodefaults -vnc :0 -S -monitor stdio -netdev user,id=hostnet0 -net nic,netdev=hostnet0 -netdev user,id=hostnet1 -net nic,netdev=hostnet1
          QEMU 0.14.50 monitor - type 'help' for more information
          (qemu) info network
          Devices not on any VLAN:
            hostnet0: net=10.0.2.0, restricted=n peer=e1000.0
            hostnet1: net=10.0.2.0, restricted=n peer=e1000.0
            e1000.0: model=e1000,macaddr=52:54:00:12:34:56 peer=hostnet0
            e1000.0: model=e1000,macaddr=52:54:00:12:34:57 peer=hostnet1
      
      Fix that.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      53e51d85
  13. 24 6月, 2011 1 次提交
  14. 22 6月, 2011 3 次提交
  15. 16 4月, 2011 1 次提交
  16. 02 4月, 2011 2 次提交
  17. 07 3月, 2011 3 次提交
  18. 05 3月, 2011 1 次提交
    • V
      net: fix qemu_can_send_packet logic · 60c07d93
      Vincent Palatin 提交于
      If any of the clients is not ready to receive (ie it has a can_receive
      callback and can_receive() returns false), we don't want to start
      sending, else this client may miss/discard the packet.
      
      I got this behaviour with the following setup :
      the emulated machine is using an USB-ethernet adapter, it is connected
      to the network using SLIRP and I'm dumping the traffic in a .pcap file.
      As per the following command line :
      -net nic,model=usb,vlan=1 -net user,vlan=1 -net dump,vlan=1,file=/tmp/pkt.pcap
      Every time that two packets are coming in a row from the host, the
      usb-net code will receive the first one, then returns 0 to can_receive
      call since it has a 1 packet long queue. But as the dump code is always
      ready to receive, qemu_can_send_packet will return true and the next
      packet will discard the previous one in the usb-net code.
      Signed-off-by: NVincent Palatin <vpalatin@chromium.org>
      Signed-off-by: NBlue Swirl <blauwirbel@gmail.com>
      60c07d93
  19. 21 2月, 2011 1 次提交
  20. 09 12月, 2010 1 次提交
    • M
      net/sock: option to specify local address · 3a75e74c
      Mike Ryan 提交于
      Add an option to specify the host IP to send multicast packets from,
      when using a multicast socket for networking. The option takes an IP
      address and sets the IP_MULTICAST_IF socket option, which causes the
      packets to use that IP's interface as an egress.
      
      This is useful if the host machine has several interfaces with several
      virtual networks across disparate interfaces.
      Signed-off-by: NMike Ryan <mikeryan@ISI.EDU>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      3a75e74c
  21. 28 10月, 2010 1 次提交
  22. 07 10月, 2010 1 次提交
    • M
      net: delay freeing peer host device · a083a89d
      Michael S. Tsirkin 提交于
      With -netdev, virtio devices present offload
      features to guest, depending on the backend used.
      Thus, removing host netdev peer while guest is
      active leads to guest-visible inconsistency and/or crashes.
      
      As a solution, while guest (NIC) peer device exists,
      we prevent the host peer from being deleted.
      This patch does this by adding peer_deleted flag in nic state:
      if host device is going away while guest device
      is around, set this flag and keep a shell of
      the host device around for as long as guest device exists.
      
      The link is put down so all packets will get discarded.
      
      At the moment, management can detect that device deletion
      is delayed by doing info net. As a next step, we shall add
      commands that control hotplug/unplug without
      removing the device, and an event to report that
      guest has responded to the hotplug event.
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      Acked-by: NAlex Williamson <alex.williamson@redhat.com>
      a083a89d
  23. 23 8月, 2010 1 次提交
  24. 02 7月, 2010 1 次提交