All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v8 5/7] net/vmnet: implement bridged mode (vmnet-bridged)
@ 2022-01-23  4:51 李士林
  2022-01-28 15:02 ` Vladislav Yaroshchuk
  0 siblings, 1 reply; 3+ messages in thread
From: 李士林 @ 2022-01-23  4:51 UTC (permalink / raw)
  To: yaroshchuk2000
  Cc: akihiko.odaki, armbru, eblake, hello, hsp.cat7, jasowang,
	phillip.ennen, phillip, qemu-devel, r.bolshakov

Hi:
    I develop a custom os use qemu and use macos as host, I use the net argument '-net nic,model=pcnet -net tap,ifname=tap0,script=no,downscript=no’ when run the qemu-system-i386,then I can get the network device in my custom os:

    pci_device_dump: vendor id:      0x1022
    pci_device_dump: device id:      0x2000
    pci_device_dump: class code:     0x20000
    pci_device_dump: revision id:    0x10
    pci_device_dump: multi function: 0
    pci_device_dump: card bus CIS pointer: 0
    pci_device_dump: subsystem vendor id: 0
    pci_device_dump: subsystem device id: 0
    pci_device_dump: expansion ROM base address: feb80000
    pci_device_dump: capability list pointer:  0
    pci_device_dump: irq line: 11
    pci_device_dump: irq pin:  1
    pci_device_dump: min Gnt: 6
    pci_device_dump: max Lat:  255
    pci_device_dump: bar 0:
    pci_device_bar_dump: type: io base address
    pci_device_bar_dump: base address: c000
    pci_device_bar_dump: len: 20
    pci_device_dump: bar 1:
    pci_device_bar_dump: type: mem base address
    pci_device_bar_dump: base address: febd1000
    pci_device_bar_dump: len: 20

I can send a message to the host from my custom os in qemu, but can’t receive a message from the host.

so I rebuild the qemu use this patch, then I use the argument '-netdev vmnet-bridged,id=vmnet,ifname=en0’ run the qemu-system-i386 again, this time, I can’t get the network device either, I don’t know why, how to use vmnet-bridged to send message to host from my custom os and receive a message from the host, what should I do? thanks a lot!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v8 5/7] net/vmnet: implement bridged mode (vmnet-bridged)
  2022-01-23  4:51 [PATCH v8 5/7] net/vmnet: implement bridged mode (vmnet-bridged) 李士林
@ 2022-01-28 15:02 ` Vladislav Yaroshchuk
  0 siblings, 0 replies; 3+ messages in thread
From: Vladislav Yaroshchuk @ 2022-01-28 15:02 UTC (permalink / raw)
  To: 李士林
  Cc: Jason Wang, phillip.ennen, Markus Armbruster, qemu-devel,
	Roman Bolshakov, Phillip Tennen, Akihiko Odaki, Howard Spoelstra,
	Alessio Dionisi, Eric Blake

[-- Attachment #1: Type: text/plain, Size: 2463 bytes --]

вс, 23 янв. 2022 г. в 07:51, 李士林 <lslboyfuture@icloud.com>:

> Hi:
>     I develop a custom os use qemu and use macos as host, I use the net
> argument '-net nic,model=pcnet -net
> tap,ifname=tap0,script=no,downscript=no’ when run the qemu-system-i386,then
> I can get the network device in my custom os:
>
>
Please notice that `-net` is a legacy option
https://wiki.qemu.org/Documentation/Networking#The_legacy_-net_option


>     pci_device_dump: vendor id:      0x1022
>     pci_device_dump: device id:      0x2000
>     pci_device_dump: class code:     0x20000
>     pci_device_dump: revision id:    0x10
>     pci_device_dump: multi function: 0
>     pci_device_dump: card bus CIS pointer: 0
>     pci_device_dump: subsystem vendor id: 0
>     pci_device_dump: subsystem device id: 0
>     pci_device_dump: expansion ROM base address: feb80000
>     pci_device_dump: capability list pointer:  0
>     pci_device_dump: irq line: 11
>     pci_device_dump: irq pin:  1
>     pci_device_dump: min Gnt: 6
>     pci_device_dump: max Lat:  255
>     pci_device_dump: bar 0:
>     pci_device_bar_dump: type: io base address
>     pci_device_bar_dump: base address: c000
>     pci_device_bar_dump: len: 20
>     pci_device_dump: bar 1:
>     pci_device_bar_dump: type: mem base address
>     pci_device_bar_dump: base address: febd1000
>     pci_device_bar_dump: len: 20
>
> I can send a message to the host from my custom os in qemu, but can’t
> receive a message from the host.
>
>
This is known issue:
https://gitlab.com/qemu-project/qemu/-/issues/335


> so I rebuild the qemu use this patch, then I use the argument '-netdev
> vmnet-bridged,id=vmnet,ifname=en0’ run the qemu-system-i386 again, this
> time, I can’t get the network device either, I don’t know why, how to use
> vmnet-bridged to send message to host from my custom os and receive a
> message from the host, what should I do? thanks a lot!


It's normal behavior since you've specified a
network backend only. See the corresponding
QEMU documentation section:
https://wiki.qemu.org/Documentation/Networking#Network_Backends

Currently you have:
`-netdev vmnet-bridged,id=vmnet,ifname=en0`
You need add a device:
 `-netdev vmnet-bridged,id=vmnet,ifname=en0 -device pcnet,netdev=vmnet`

Supported devices can be listed with -device help:
`qemu-system-xxx -device help`

--
Best Regards,

Vladislav Yaroshchuk

[-- Attachment #2: Type: text/html, Size: 3708 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v8 5/7] net/vmnet: implement bridged mode (vmnet-bridged)
  2021-12-11 10:44 [PATCH v8 0/7] Add vmnet.framework based network backend Vladislav Yaroshchuk
@ 2021-12-11 10:44 ` Vladislav Yaroshchuk
  0 siblings, 0 replies; 3+ messages in thread
From: Vladislav Yaroshchuk @ 2021-12-11 10:44 UTC (permalink / raw)
  To: qemu-devel
  Cc: Vladislav Yaroshchuk, jasowang, phillip.ennen, armbru,
	r.bolshakov, phillip, akihiko.odaki, hsp.cat7, hello, eblake

Signed-off-by: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
---
 net/vmnet-bridged.m | 98 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 92 insertions(+), 6 deletions(-)

diff --git a/net/vmnet-bridged.m b/net/vmnet-bridged.m
index 4e42a90391..3c9da9dc8b 100644
--- a/net/vmnet-bridged.m
+++ b/net/vmnet-bridged.m
@@ -10,16 +10,102 @@
 
 #include "qemu/osdep.h"
 #include "qapi/qapi-types-net.h"
-#include "vmnet_int.h"
-#include "clients.h"
-#include "qemu/error-report.h"
 #include "qapi/error.h"
+#include "clients.h"
+#include "vmnet_int.h"
 
 #include <vmnet/vmnet.h>
 
+typedef struct VmnetBridgedState {
+  VmnetCommonState cs;
+} VmnetBridgedState;
+
+static bool validate_ifname(const char *ifname)
+{
+    xpc_object_t shared_if_list = vmnet_copy_shared_interface_list();
+    __block bool match = false;
+
+    xpc_array_apply(
+        shared_if_list,
+        ^bool(size_t index, xpc_object_t value) {
+          if (strcmp(xpc_string_get_string_ptr(value), ifname) == 0) {
+              match = true;
+              return false;
+          }
+          return true;
+        });
+
+    return match;
+}
+
+static const char *get_valid_ifnames(void)
+{
+    xpc_object_t shared_if_list = vmnet_copy_shared_interface_list();
+    __block char *if_list = NULL;
+
+    xpc_array_apply(
+        shared_if_list,
+        ^bool(size_t index, xpc_object_t value) {
+          if_list = g_strconcat(xpc_string_get_string_ptr(value),
+                                " ",
+                                if_list,
+                                NULL);
+          return true;
+        });
+
+    if (if_list) {
+        return if_list;
+    }
+    return "[no interfaces]";
+}
+
+static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp)
+{
+    const NetdevVmnetBridgedOptions *options = &(netdev->u.vmnet_bridged);
+    xpc_object_t if_desc = xpc_dictionary_create(NULL, NULL, 0);
+
+    xpc_dictionary_set_uint64(
+        if_desc,
+        vmnet_operation_mode_key,
+        VMNET_BRIDGED_MODE
+    );
+
+    xpc_dictionary_set_bool(
+        if_desc,
+        vmnet_enable_isolation_key,
+        options->isolated
+    );
+
+    if (validate_ifname(options->ifname)) {
+        xpc_dictionary_set_string(if_desc,
+                                  vmnet_shared_interface_name_key,
+                                  options->ifname);
+    } else {
+        return NULL;
+    }
+    return if_desc;
+}
+
+static NetClientInfo net_vmnet_bridged_info = {
+    .type = NET_CLIENT_DRIVER_VMNET_BRIDGED,
+    .size = sizeof(VmnetBridgedState),
+    .receive = vmnet_receive_common,
+    .cleanup = vmnet_cleanup_common,
+};
+
 int net_init_vmnet_bridged(const Netdev *netdev, const char *name,
                            NetClientState *peer, Error **errp)
 {
-  error_setg(errp, "vmnet-bridged is not implemented yet");
-  return -1;
-}
+    NetClientState *nc = qemu_new_net_client(&net_vmnet_bridged_info,
+                                             peer, "vmnet-bridged", name);
+    xpc_object_t if_desc = create_if_desc(netdev, errp);;
+
+    if (!if_desc) {
+        error_setg(errp,
+                   "unsupported ifname, should be one of: %s",
+                   get_valid_ifnames());
+        return -1;
+    }
+
+    return vmnet_if_create(nc, if_desc, errp, NULL);
+}
\ No newline at end of file
-- 
2.23.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-28 15:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-23  4:51 [PATCH v8 5/7] net/vmnet: implement bridged mode (vmnet-bridged) 李士林
2022-01-28 15:02 ` Vladislav Yaroshchuk
  -- strict thread matches above, loose matches on Subject: below --
2021-12-11 10:44 [PATCH v8 0/7] Add vmnet.framework based network backend Vladislav Yaroshchuk
2021-12-11 10:44 ` [PATCH v8 5/7] net/vmnet: implement bridged mode (vmnet-bridged) Vladislav Yaroshchuk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.