Skip to content
Snippets Groups Projects
  1. Apr 08, 2021
  2. Mar 15, 2021
  3. Oct 09, 2020
  4. Jul 15, 2020
    • Laurent Vivier's avatar
      net: check if the file descriptor is valid before using it · 894022e6
      Laurent Vivier authored
      
      qemu_set_nonblock() checks that the file descriptor can be used and, if
      not, crashes QEMU. An assert() is used for that. The use of assert() is
      used to detect programming error and the coredump will allow to debug
      the problem.
      
      But in the case of the tap device, this assert() can be triggered by
      a misconfiguration by the user. At startup, it's not a real problem, but it
      can also happen during the hot-plug of a new device, and here it's a
      problem because we can crash a perfectly healthy system.
      
      For instance:
       # ip link add link virbr0 name macvtap0 type macvtap mode bridge
       # ip link set macvtap0 up
       # TAP=/dev/tap$(ip -o link show macvtap0 | cut -d: -f1)
       # qemu-system-x86_64 -machine q35 -device pcie-root-port,id=pcie-root-port-0 -monitor stdio 9<> $TAP
       (qemu) netdev_add type=tap,id=hostnet0,vhost=on,fd=9
       (qemu) device_add driver=virtio-net-pci,netdev=hostnet0,id=net0,bus=pcie-root-port-0
       (qemu) device_del net0
       (qemu) netdev_del hostnet0
       (qemu) netdev_add type=tap,id=hostnet1,vhost=on,fd=9
       qemu-system-x86_64: .../util/oslib-posix.c:247: qemu_set_nonblock: Assertion `f != -1' failed.
       Aborted (core dumped)
      
      To avoid that, add a function, qemu_try_set_nonblock(), that allows to report the
      problem without crashing.
      
      In the same way, we also update the function for vhostfd in net_init_tap_one() and
      for fd in net_init_socket() (both descriptors are provided by the user and can
      be wrong).
      
      Signed-off-by: default avatarLaurent Vivier <lvivier@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
      894022e6
  5. Mar 29, 2019
    • Marc-André Lureau's avatar
      net/socket: learn to talk with a unix dgram socket · fdec16e3
      Marc-André Lureau authored
      
      -net socket has a fd argument, and may be passed pre-opened sockets.
      
      TCP sockets use framing.
      UDP sockets have datagram boundaries.
      
      When given a unix dgram socket, it will be able to read from it, but
      will attempt to send on the dgram_dst, which is unset. The other end
      will not receive the data.
      
      Let's teach -net socket to recognize a UNIX DGRAM socket, and use the
      regular send() command (without dgram_dst).
      
      This makes running slirp out-of-process possible that
      way (python pseudo-code):
      
      a, b = socket.socketpair(socket.AF_UNIX, socket.SOCK_DGRAM)
      
      subprocess.Popen('qemu -net socket,fd=%d -net user' % a.fileno(), shell=True)
      subprocess.Popen('qemu ... -net nic -net socket,fd=%d' % b.fileno(), shell=True)
      
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
      fdec16e3
  6. Oct 19, 2018
  7. Nov 13, 2017
  8. Sep 08, 2017
  9. Aug 09, 2017
  10. Jul 17, 2017
  11. Jun 07, 2017
    • Daniel P. Berrangé's avatar
      Revert "Change net/socket.c to use socket_*() functions" again · 6701e551
      Daniel P. Berrangé authored
      
      This reverts commit 883e4f76.
      
      This code changed net/socket.c from using socket()+connect(),
      to using socket_connect(). In theory this is great, but in
      practice this has completely broken the ability to connect
      the frontend and backend:
      
        $ ./x86_64-softmmu/qemu-system-x86_64 \
             -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05 \
             -netdev socket,id=hn0,connect=localhost:1234
        qemu-system-x86_64: -device e1000,id=e0,netdev=hn0,mac=DE:AD:BE:EF:AF:05: Property 'e1000.netdev' can't find value 'hn0'
      
      The old code would call net_socket_fd_init() synchronously,
      while letting the connect() complete in the backgorund. The
      new code moved net_socket_fd_init() so that it is only called
      after connect() completes in the background.
      
      Thus at the time we initialize the NIC frontend, the backend
      does not exist.
      
      The socket_connect() conversion as done is a bad fit for the
      current code, since it did not try to change the way it deals
      with async connection completion. Rather than try to fix this,
      just revert the socket_connect() conversion entirely.
      
      The code is about to be converted to use QIOChannel which
      will let the problem be solved in a cleaner manner. This
      revert is more suitable for stable branches in the meantime.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
      6701e551
  12. May 09, 2017
  13. Apr 24, 2017
  14. Nov 15, 2016
    • Daniel P. Berrangé's avatar
      net: fix sending of data with -net socket, listen backend · e79cd406
      Daniel P. Berrangé authored
      
      The use of -net socket,listen was broken in the following
      commit
      
        commit 16a3df40
        Author: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
        Date:   Fri May 13 15:35:19 2016 +0800
      
          net/net: Add SocketReadState for reuse codes
      
          This function is from net/socket.c, move it to net.c and net.h.
          Add SocketReadState to make others reuse net_fill_rstate().
          suggestion from jason.
      
      This refactored the state out of NetSocketState into a
      separate SocketReadState. This refactoring requires
      that a callback is provided to be triggered upon
      completion of a packet receive from the guest.
      
      The patch only registered this callback in the codepaths
      hit by -net socket,connect, not -net socket,listen. So
      as a result packets sent by the guest in the latter case
      get dropped on the floor.
      
      This bug is hidden because net_fill_rstate() silently
      does nothing if the callback is not set.
      
      This patch adds in the middle callback registration
      and also adds an assert so that QEMU aborts if there
      are any other codepaths hit which are missing the
      callback.
      
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: default avatarZhang Chen <zhangchen.fnst@cn.fujitsu.com>
      Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
      e79cd406
  15. Sep 14, 2016
  16. Aug 30, 2016
  17. Jul 19, 2016
    • Eric Blake's avatar
      qapi: Change Netdev into a flat union · f394b2e2
      Eric Blake authored
      
      This is a mostly-mechanical conversion that creates a new flat
      union 'Netdev' QAPI type that covers all the branches of the
      former 'NetClientOptions' simple union, where the branches are
      now listed in a new 'NetClientDriver' enum rather than generated
      from the simple union.  The existence of a flat union has no
      change to the command line syntax accepted for new code, and
      will make it possible for a future patch to switch the QMP
      command to parse a boxed union for no change to valid QMP; but
      it does have some ripple effect on the C code when dealing with
      the new types.
      
      While making the conversion, note that the 'NetLegacy' type
      remains unchanged: it applies only to legacy command line options,
      and will not be ported to QMP, so it should remain a wrapper
      around a simple union; to avoid confusion, the type named
      'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions'
      in its place.  Then, in the C code, we convert from NetLegacy to
      Netdev as soon as possible, so that the bulk of the net stack
      only has to deal with one QAPI type, not two.  Note that since
      the old legacy code always rejected 'hubport', we can just omit
      that branch from the new 'NetLegacyOptions' simple union.
      
      Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>:
      Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com>
      although the sed script in that patch no longer applies due to
      other changes in the tree since then, and I also did some manual
      cleanups (such as fixing whitespace to keep checkpatch happy).
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com>
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      [Fixup from Eric squashed in]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      f394b2e2
    • Kővágó, Zoltán's avatar
      net: use Netdev instead of NetClientOptions in client init · cebea510
      Kővágó, Zoltán authored
      
      This way we no longer need NetClientOptions and can convert Netdev
      into a flat union.
      
      Signed-off-by: default avatarKővágó, Zoltán <DirtY.iCE.hu@gmail.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <93ffdfed7054529635e6acb935150d95dc173a12.1441627176.git.DirtY.iCE.hu@gmail.com>
      
      [rework net_client_init1() to pass Netdev by copying from NetdevLegacy,
      rather than merging the two types - which means that we still need
      NetClientOptions after all.  Rebase to qapi changes. The bulk of the
      patch is mechanical, replacing 'opts' by 'netdev->opts', while
      net_client_init1() takes care of converting between legacy and modern
      types.]
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <1468468228-27827-2-git-send-email-eblake@redhat.com>
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      cebea510
  18. Jun 28, 2016
  19. Jun 01, 2016
  20. Mar 22, 2016
    • Markus Armbruster's avatar
      include/qemu/osdep.h: Don't include qapi/error.h · da34e65c
      Markus Armbruster authored
      
      Commit 57cb38b3 included qapi/error.h into qemu/osdep.h to get the
      Error typedef.  Since then, we've moved to include qemu/osdep.h
      everywhere.  Its file comment explains: "To avoid getting into
      possible circular include dependencies, this file should not include
      any other QEMU headers, with the exceptions of config-host.h,
      compiler.h, os-posix.h and os-win32.h, all of which are doing a
      similar job to this file and are under similar constraints."
      qapi/error.h doesn't do a similar job, and it doesn't adhere to
      similar constraints: it includes qapi-types.h.  That's in excess of
      100KiB of crap most .c files don't actually need.
      
      Add the typedef to qemu/typedefs.h, and include that instead of
      qapi/error.h.  Include qapi/error.h in .c files that need it and don't
      get it now.  Include qapi-types.h in qom/object.h for uint16List.
      
      Update scripts/clean-includes accordingly.  Update it further to match
      reality: replace config.h by config-target.h, add sysemu/os-posix.h,
      sysemu/os-win32.h.  Update the list of includes in the qemu/osdep.h
      comment quoted above similarly.
      
      This reduces the number of objects depending on qapi/error.h from "all
      of them" to less than a third.  Unfortunately, the number depending on
      qapi-types.h shrinks only a little.  More work is needed for that one.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      [Fix compilation without the spice devel packages. - Paolo]
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      da34e65c
  21. Mar 18, 2016
    • Eric Blake's avatar
      qapi: Don't special-case simple union wrappers · 32bafa8f
      Eric Blake authored
      
      Simple unions were carrying a special case that hid their 'data'
      QMP member from the resulting C struct, via the hack method
      QAPISchemaObjectTypeVariant.simple_union_type().  But by using
      the work we started by unboxing flat union and alternate
      branches, coupled with the ability to visit the members of an
      implicit type, we can now expose the simple union's implicit
      type in qapi-types.h:
      
      | struct q_obj_ImageInfoSpecificQCow2_wrapper {
      |     ImageInfoSpecificQCow2 *data;
      | };
      |
      | struct q_obj_ImageInfoSpecificVmdk_wrapper {
      |     ImageInfoSpecificVmdk *data;
      | };
      ...
      | struct ImageInfoSpecific {
      |     ImageInfoSpecificKind type;
      |     union { /* union tag is @type */
      |         void *data;
      |-        ImageInfoSpecificQCow2 *qcow2;
      |-        ImageInfoSpecificVmdk *vmdk;
      |+        q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
      |+        q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
      |     } u;
      | };
      
      Doing this removes asymmetry between QAPI's QMP side and its
      C side (both sides now expose 'data'), and means that the
      treatment of a simple union as sugar for a flat union is now
      equivalent in both languages (previously the two approaches used
      a different layer of dereferencing, where the simple union could
      be converted to a flat union with equivalent C layout but
      different {} on the wire, or to an equivalent QMP wire form
      but with different C representation).  Using the implicit type
      also lets us get rid of the simple_union_type() hack.
      
      Of course, now all clients of simple unions have to adjust from
      using su->u.member to using su->u.member.data; while this touches
      a number of files in the tree, some earlier cleanup patches
      helped minimize the change to the initialization of a temporary
      variable rather than every single member access.  The generated
      qapi-visit.c code is also affected by the layout change:
      
      |@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
      |     }
      |     switch (obj->type) {
      |     case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
      |-        visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
      |+        visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
      |         break;
      |     case IMAGE_INFO_SPECIFIC_KIND_VMDK:
      |-        visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
      |+        visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
      |         break;
      |     default:
      |         abort();
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <1458254921-17042-13-git-send-email-eblake@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      32bafa8f
  22. Mar 10, 2016
  23. Feb 04, 2016
    • Peter Maydell's avatar
      net: Clean up includes · 2744d920
      Peter Maydell authored
      
      Clean up includes so that osdep.h is included first and headers
      which it implies are not included manually.
      
      This commit was created with scripts/clean-includes.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Message-id: 1454089805-5470-11-git-send-email-peter.maydell@linaro.org
      2744d920
  24. Nov 02, 2015
    • Eric Blake's avatar
      net: Convert to new qapi union layout · 8d0bcba8
      Eric Blake authored
      
      We have two issues with our qapi union layout:
      1) Even though the QMP wire format spells the tag 'type', the
      C code spells it 'kind', requiring some hacks in the generator.
      2) The C struct uses an anonymous union, which places all tag
      values in the same namespace as all non-variant members. This
      leads to spurious collisions if a tag value matches a non-variant
      member's name.
      
      Make the conversion to the new layout for net-related code.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <1445898903-12082-18-git-send-email-eblake@redhat.com>
      [Commit message tweaked slightly]
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      8d0bcba8
  25. Jul 20, 2015
  26. Jun 12, 2015
  27. May 27, 2015
    • Markus Armbruster's avatar
      net: Permit incremental conversion of init functions to Error · a30ecde6
      Markus Armbruster authored
      
      Error reporting for netdev_add is broken: the net_client_init_fun[]
      report the actual errors with (at best) error_report(), and their
      caller net_client_init1() makes up a generic error on top.
      
      For command line and HMP, this produces an mildly ugly error cascade.
      
      In QMP, the actual errors go to stderr, and the generic error becomes
      the command's error reply.
      
      To fix this, we need to convert the net_client_init_fun[] to Error.
      
      To permit fixing them one by one, add an Error ** parameter to the
      net_client_init_fun[].  If the call fails without returning an Error,
      make up the same generic Error as before.  But if it returns one, use
      that instead.  Since none of them does so far, no functional change.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Message-id: 1431691143-1015-3-git-send-email-armbru@redhat.com
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      a30ecde6
  28. Feb 18, 2015
    • Markus Armbruster's avatar
      monitor: Clean up around monitor_handle_fd_param() · 1677f4c6
      Markus Armbruster authored
      
      monitor_handle_fd_param() is a wrapper around
      monitor_handle_fd_param2() that feeds errors to qerror_report_err()
      instead of returning them.  qerror_report_err() is inappropriate in
      many contexts.  monitor_handle_fd_param() looks simpler than
      monitor_handle_fd_param2(), which tempts use.  Remove the temptation:
      drop the wrapper and open-code the (trivial) error handling instead.
      
      Replace the open-coded qerror_report_err() by error_report_err() in
      places that already use error_report().  Turns out that's everywhere.
      
      While there, rename monitor_handle_fd_param2() to monitor_fd_param().
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      1677f4c6
  29. Nov 21, 2014
Loading