qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Mark McLoughlin <markmc@redhat.com>
To: qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH 3/3] Add support for fd=msgfd for tap and socket networking
Date: Mon, 06 Jul 2009 18:32:13 +0100	[thread overview]
Message-ID: <1246901533.12086.23.camel@blaa> (raw)
In-Reply-To: <1246901495.12086.22.camel@blaa>

This allows a program to initialize a host networking device using a
file descriptor passed over a unix monitor socket.

If the programs does e.g. "host_net_add tap fd=msgfd" it must pass
a file descriptor as part of that same message via SCM_RIGHTS ancillary
data.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 net.c |   39 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/net.c b/net.c
index 001ebcb..0bb8b52 100644
--- a/net.c
+++ b/net.c
@@ -2388,6 +2388,30 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
     exit(exit_status);
 }
 
+static int net_handle_fd_param(Monitor *mon, const char *param)
+{
+    if (!strcmp(param, "msgfd")) {
+        int fd;
+
+        fd = monitor_get_msgfd(mon);
+        if (fd == -1) {
+            config_error(mon, "No file descriptor found in ancillary data\n");
+            return -1;
+        }
+
+        fd = dup(fd);
+        if (fd == -1) {
+            config_error(mon, "Failed to dup() file descriptor: %s\n",
+                         strerror(errno));
+            return -1;
+        }
+
+        return fd;
+    } else {
+        return strtol(param, NULL, 0);
+    }
+}
+
 int net_client_init(Monitor *mon, const char *device, const char *p)
 {
     char buf[1024];
@@ -2625,12 +2649,15 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
             static const char * const fd_params[] = {
                 "vlan", "name", "fd", "sndbuf", NULL
             };
+            ret = -1;
             if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {
                 config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
-                ret = -1;
                 goto out;
             }
-            fd = strtol(buf, NULL, 0);
+            fd = net_handle_fd_param(mon, buf);
+            if (fd == -1) {
+                goto out;
+            }
             fcntl(fd, F_SETFL, O_NONBLOCK);
             s = net_tap_fd_init(vlan, device, name, fd);
         } else {
@@ -2670,13 +2697,15 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
                 "vlan", "name", "fd", NULL
             };
             int fd;
+            ret = -1;
             if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {
                 config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
-                ret = -1;
                 goto out;
             }
-            fd = strtol(buf, NULL, 0);
-            ret = -1;
+            fd = net_handle_fd_param(mon, buf);
+            if (fd == -1) {
+                goto out;
+            }
             if (net_socket_fd_init(vlan, device, name, fd, 1))
                 ret = 0;
         } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {
-- 
1.6.2.5

  reply	other threads:[~2009-07-06 17:32 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-06 17:30 [Qemu-devel] [PATCH 0/3] Allow host_net_add monitor command accept file descriptors Mark McLoughlin
2009-07-06 17:30 ` [Qemu-devel] [PATCH 1/3] Make tcp_chr_read() use recvmsg() Mark McLoughlin
2009-07-06 17:31   ` [Qemu-devel] [PATCH 2/3] Add SCM_RIGHTS support to unix socket character devices Mark McLoughlin
2009-07-06 17:32     ` Mark McLoughlin [this message]
2009-07-07  5:28 ` [Qemu-devel] [PATCH 0/3] Allow host_net_add monitor command accept file descriptors Avi Kivity
2009-07-07  7:43   ` Mark McLoughlin
2009-07-07  7:52     ` Avi Kivity
2009-07-07  8:13       ` Mark McLoughlin
2009-07-07  9:03         ` Avi Kivity
2009-07-07 10:06           ` Daniel P. Berrange
2009-07-08 14:56             ` Mark McLoughlin
2009-07-08 14:57               ` [Qemu-devel] [PATCH 1/5] Make tcp_chr_read() use recvmsg() Mark McLoughlin
2009-07-08 14:57                 ` [Qemu-devel] [PATCH 2/5] Add SCM_RIGHTS support to unix socket character devices Mark McLoughlin
2009-07-08 14:57                   ` [Qemu-devel] [PATCH 3/5] Add getfd and closefd monitor commands Mark McLoughlin
2009-07-08 14:57                     ` [Qemu-devel] [PATCH 4/5] Add monitor_get_fd() command for fetching named fds Mark McLoughlin
2009-07-08 14:57                       ` [Qemu-devel] [PATCH 5/5] Add support for fd=name to tap and socket networking Mark McLoughlin
2009-07-08 15:26                     ` [Qemu-devel] [PATCH 3/5] Add getfd and closefd monitor commands Avi Kivity
2009-07-08 16:03                       ` Mark McLoughlin
2009-07-08 16:15                         ` Avi Kivity
2009-07-08 18:08                           ` Anthony Liguori
2009-07-08 18:11                             ` Avi Kivity
2009-07-08 18:21                               ` Anthony Liguori
2009-07-08 18:32                                 ` Avi Kivity
2009-07-08 18:50                                   ` Anthony Liguori
2009-07-08 19:52                                     ` Avi Kivity
2009-07-11  1:12                                       ` Jamie Lokier
2009-07-21 16:40                                       ` Mark McLoughlin
2009-07-21 16:53                                         ` [Qemu-devel] [PATCH] Make tcp_chr_read() use recvmsg() Mark McLoughlin
2009-07-21 17:13                                           ` Blue Swirl
2009-07-22  0:00                                             ` Jamie Lokier
2009-07-22  8:10                                             ` Mark McLoughlin
2009-07-22  8:11                                               ` [Qemu-devel] [PATCH 1/5] " Mark McLoughlin
2009-07-22  8:11                                               ` [Qemu-devel] [PATCH 2/5] Add SCM_RIGHTS support to unix socket character devices Mark McLoughlin
2009-08-13 16:20                                                 ` Cam Macdonell
2009-08-14  6:38                                                   ` Mark McLoughlin
2009-07-22  8:11                                               ` [Qemu-devel] [PATCH 3/5] Add getfd and closefd monitor commands Mark McLoughlin
2009-07-22  8:11                                               ` [Qemu-devel] [PATCH 4/5] Add monitor_get_fd() command for fetching named fds Mark McLoughlin
2009-07-22  8:11                                               ` [Qemu-devel] [PATCH 5/5] Add support for fd=name to tap and socket networking Mark McLoughlin
2009-07-23 13:37                                                 ` Mark McLoughlin
2009-07-21 16:53                                         ` [Qemu-devel] [PATCH] Add SCM_RIGHTS support to unix socket character devices Mark McLoughlin
2009-07-21 16:53                                         ` [Qemu-devel] [PATCH] Add getfd and closefd monitor commands Mark McLoughlin
2009-07-21 16:53                                         ` [Qemu-devel] [PATCH] Add monitor_get_fd() command for fetching named fds Mark McLoughlin
2009-07-21 16:53                                         ` [Qemu-devel] [PATCH] Add support for fd=name to tap and socket networking Mark McLoughlin
2009-07-22  2:20                                         ` [Qemu-devel] [PATCH 3/5] Add getfd and closefd monitor commands Anthony Liguori
2009-07-22  8:09                                           ` Mark McLoughlin
2009-07-23  7:00                                             ` [Qemu-devel] " Jan Kiszka
2009-07-23  7:51                                               ` Mark McLoughlin
2009-07-08 15:25                   ` [Qemu-devel] [PATCH 2/5] Add SCM_RIGHTS support to unix socket character devices Avi Kivity
2009-07-08 16:04                     ` Mark McLoughlin
2009-07-08 16:17                       ` Avi Kivity
2009-07-08 18:11                       ` Anthony Liguori
2009-07-08 18:17                         ` Avi Kivity
2009-07-11  1:15                           ` Jamie Lokier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1246901533.12086.23.camel@blaa \
    --to=markmc@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).