]> xenbits.xensource.com Git - libvirt.git/commitdiff
Refactor processing of incoming packets to remove dead code
authorDaniel P. Berrange <berrange@redhat.com>
Sat, 17 Nov 2007 11:17:48 +0000 (11:17 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Sat, 17 Nov 2007 11:17:48 +0000 (11:17 +0000)
ChangeLog
qemud/Makefile.am
qemud/internal.h
qemud/protocol.c [deleted file]
qemud/protocol.h [deleted file]
qemud/protocol.x [deleted file]
qemud/qemud.c
qemud/remote.c
qemud/remote_protocol.h
qemud/remote_protocol.x
src/Makefile.am

index e019150fac8ed43a016fabe3fb82ef23c212437a..a23c3cd8ac79e140334ed211957cd3fbe78322d1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Sat Nov 17 11:04:33 UTC 2007 Daniel P. Berrange <berrange@redhat.com>
+
+        * qemud/Makefile.am: Remove protocol.[chx] from EXTRA_DIST.
+          Remove protocol.h and protocol.c from libvirtd_SOURCES.
+          Remove protocol.c dependency.
+        * qemud/protocol.c, qemud/protocol.h, qemud/protocol.x: Remove files.
+        * qemud/internal.h: Don't include "protocol.h".
+        * qemud/qemud.c: Clean up qemudDispatchClientRead.
+        s/QEMUD_PKT_HEADER_XDR_LEN/REMOTE_MESSAGE_HEADER_XDR_LEN/
+        * qemud/remote.c: In remoteDispatchClientRequest, reflect that the
+        client buffer no longer starts with the 4-byte XDR header length.
+        * qemud/remote_protocol.h: Regenerate.
+        * qemud/remote_protocol.x: Define REMOTE_MESSAGE_HEADER_XDR_LEN.
+        * src/Makefile.am: Remove protocol.h, protocol.c from SERVER_SOURCES.
+
 Thu Nov 15 17:43:00 UTC 2007 Richard W.M. Jones <rjones@redhat.com>
 
        * src/stats_linux.c: Fix parsing of short interface names
index 6aedf8c3d66d07521e8837327a926c9a51e00b00..7422e44ec205a74ff3335aa9f556e18508956683 100644 (file)
@@ -10,8 +10,7 @@ conf_DATA = libvirtd.conf
 # Distribute the generated files so that rpcgen isn't required on the
 # target machine (although almost any Unix machine will have it).
 EXTRA_DIST = libvirtd.init.in libvirtd.sysconf default-network.xml \
-       protocol.x remote_protocol.x \
-       protocol.c protocol.h \
+       remote_protocol.x \
        remote_protocol.c remote_protocol.h \
        remote_generate_stubs.pl rpcgen_fix.pl \
        remote_dispatch_prototypes.h \
@@ -22,7 +21,6 @@ EXTRA_DIST = libvirtd.init.in libvirtd.sysconf default-network.xml \
 
 libvirtd_SOURCES = \
                qemud.c internal.h \
-               protocol.h protocol.c \
                remote_protocol.h remote_protocol.c \
                remote.c \
                event.c event.h
@@ -80,7 +78,6 @@ uninstall-local: uninstall-init
        rm -f $@
        rpcgen -h -o $@ $<
 
-protocol.c: protocol.h
 remote_protocol.c: remote_protocol.h
 
 remote.c: remote_dispatch_prototypes.h \
index 9b1b72125e685cdd10fc86c519684b39ac9bbbf0..29ef14b8cebdc7f6a4114aaa35f8c27aeb20d634 100644 (file)
@@ -29,7 +29,6 @@
 #include <gnutls/x509.h>
 #include "../src/gnutls_1_0_compat.h"
 
-#include "protocol.h"
 #include "remote_protocol.h"
 #include "../config.h"
 
diff --git a/qemud/protocol.c b/qemud/protocol.c
deleted file mode 100644 (file)
index 5e81365..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Please do not edit this file.
- * It was generated using rpcgen.
- */
-
-#include "protocol.h"
-
-bool_t
-xdr_qemud_packet_header (XDR *xdrs, qemud_packet_header *objp)
-{
-
-        if (!xdr_uint32_t (xdrs, &objp->length))
-                return FALSE;
-        if (!xdr_uint32_t (xdrs, &objp->prog))
-                return FALSE;
-       return TRUE;
-}
diff --git a/qemud/protocol.h b/qemud/protocol.h
deleted file mode 100644 (file)
index 2bdc860..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Please do not edit this file.
- * It was generated using rpcgen.
- */
-
-#ifndef _PROTOCOL_H_RPCGEN
-#define _PROTOCOL_H_RPCGEN
-
-#include <rpc/rpc.h>
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define QEMUD_PROGRAM 0x20001A64
-#define QEMUD_PKT_HEADER_XDR_LEN 8
-
-struct qemud_packet_header {
-       uint32_t length;
-       uint32_t prog;
-};
-typedef struct qemud_packet_header qemud_packet_header;
-
-/* the xdr functions */
-
-#if defined(__STDC__) || defined(__cplusplus)
-extern  bool_t xdr_qemud_packet_header (XDR *, qemud_packet_header*);
-
-#else /* K&R C */
-extern bool_t xdr_qemud_packet_header ();
-
-#endif /* K&R C */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !_PROTOCOL_H_RPCGEN */
diff --git a/qemud/protocol.x b/qemud/protocol.x
deleted file mode 100644 (file)
index e2b86b1..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- c -*-
- * protocol_xdr.x: wire protocol message format & data structures
- *
- * Copyright (C) 2006, 2007 Red Hat, Inc.
- * Copyright (C) 2006 Daniel P. Berrange
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
- *
- * Author: Daniel P. Berrange <berrange@redhat.com>
- */
-
-
-/* The first two words in the messages are length and program number
- * (previously called "magic").  This makes the protocol compatible
- * with the remote protocol, although beyond the first two words
- * the protocols are completely different.
- *
- * Note the length is the total number of bytes in the message
- * _including_ the length and program number.
- */
-
-const QEMUD_PROGRAM = 0x20001A64;
-const QEMUD_PKT_HEADER_XDR_LEN = 8;
-
-struct qemud_packet_header {
-  uint32_t length;
-  uint32_t prog;
-};
index ee6f6ce4e4ddb3a9cb30b93bc2bb25877831f439..55bd805a3a2458711479f2ad1292432290b9dee5 100644 (file)
@@ -1051,7 +1051,7 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket
 
     if (!client->tls) {
         client->mode = QEMUD_MODE_RX_HEADER;
-        client->bufferLength = QEMUD_PKT_HEADER_XDR_LEN;
+        client->bufferLength = REMOTE_MESSAGE_HEADER_XDR_LEN;
 
         if (qemudRegisterClientEvent (server, client, 0) < 0)
             goto cleanup;
@@ -1180,7 +1180,7 @@ static void qemudDispatchClientRead(struct qemud_server *server, struct qemud_cl
     switch (client->mode) {
     case QEMUD_MODE_RX_HEADER: {
         XDR x;
-        qemud_packet_header h;
+        unsigned int len;
 
         if (qemudClientRead(server, client) < 0)
             return; /* Error, or blocking */
@@ -1190,33 +1190,32 @@ static void qemudDispatchClientRead(struct qemud_server *server, struct qemud_cl
 
         xdrmem_create(&x, client->buffer, client->bufferLength, XDR_DECODE);
 
-        if (!xdr_qemud_packet_header(&x, &h)) {
-            qemudDebug("Failed to decode packet header");
+        if (!xdr_u_int(&x, &len)) {
+            xdr_destroy (&x);
+            qemudDebug("Failed to decode packet length");
             qemudDispatchClientFailure(server, client);
             return;
         }
+        xdr_destroy (&x);
 
-        if (h.prog != REMOTE_PROGRAM) {
-            qemudDebug("Header magic %x mismatch", h.prog);
+        if (len > REMOTE_MESSAGE_MAX) {
+            qemudDebug("Packet length %u too large", len);
             qemudDispatchClientFailure(server, client);
             return;
         }
 
-        /* NB: h.length is unsigned. */
-        if (h.length > REMOTE_MESSAGE_MAX) {
-            qemudDebug("Packet length %u too large", h.length);
+        /* Length include length of the length field itself, so
+         * check minimum size requirements */
+        if (len <= REMOTE_MESSAGE_HEADER_XDR_LEN) {
+            qemudDebug("Packet length %u too small", len);
             qemudDispatchClientFailure(server, client);
             return;
         }
 
         client->mode = QEMUD_MODE_RX_PAYLOAD;
-        client->bufferLength = h.length;
+        client->bufferLength = len - REMOTE_MESSAGE_HEADER_XDR_LEN;
+        client->bufferOffset = 0;
         if (client->tls) client->direction = QEMUD_TLS_DIRECTION_READ;
-        /* Note that we don't reset bufferOffset here because we want
-         * to retain the whole message, including header.
-         */
-
-        xdr_destroy (&x);
 
         if (qemudRegisterClientEvent(server, client, 1) < 0) {
             qemudDispatchClientFailure(server, client);
@@ -1227,35 +1226,15 @@ static void qemudDispatchClientRead(struct qemud_server *server, struct qemud_cl
     }
 
     case QEMUD_MODE_RX_PAYLOAD: {
-        XDR x;
-        qemud_packet_header h;
-
         if (qemudClientRead(server, client) < 0)
             return; /* Error, or blocking */
 
         if (client->bufferOffset < client->bufferLength)
             return; /* Not read enough */
 
-        /* Reparse the header to decide if this is for qemud or remote. */
-        xdrmem_create(&x, client->buffer, client->bufferLength, XDR_DECODE);
-
-        if (!xdr_qemud_packet_header(&x, &h)) {
-            qemudDebug("Failed to decode packet header");
+        remoteDispatchClientRequest (server, client);
+        if (qemudRegisterClientEvent(server, client, 1) < 0)
             qemudDispatchClientFailure(server, client);
-            return;
-        }
-
-        if (h.prog == REMOTE_PROGRAM) {
-            remoteDispatchClientRequest (server, client);
-            if (qemudRegisterClientEvent(server, client, 1) < 0)
-                qemudDispatchClientFailure(server, client);
-        } else {
-            /* An internal error. */
-            qemudDebug ("Not REMOTE_PROGRAM");
-            qemudDispatchClientFailure(server, client);
-        }
-
-        xdr_destroy (&x);
 
         break;
     }
@@ -1336,7 +1315,7 @@ static void qemudDispatchClientWrite(struct qemud_server *server, struct qemud_c
         if (client->bufferOffset == client->bufferLength) {
             /* Done writing, switch back to receive */
             client->mode = QEMUD_MODE_RX_HEADER;
-            client->bufferLength = QEMUD_PKT_HEADER_XDR_LEN;
+            client->bufferLength = REMOTE_MESSAGE_HEADER_XDR_LEN;
             client->bufferOffset = 0;
             if (client->tls) client->direction = QEMUD_TLS_DIRECTION_READ;
 
index 7bbe51024e860b25c2befe56abad32abd3106bce..f4d76a1754f91cc2476611883afb3e66d7b93c5c 100644 (file)
@@ -83,7 +83,7 @@ remoteDispatchClientRequest (struct qemud_server *server ATTRIBUTE_UNUSED,
 #include "remote_dispatch_localvars.h"
 
     /* Parse the header. */
-    xdrmem_create (&xdr, client->buffer+4, client->bufferLength-4, XDR_DECODE);
+    xdrmem_create (&xdr, client->buffer, client->bufferLength, XDR_DECODE);
 
     if (!xdr_remote_message_header (&xdr, &req)) {
         remoteDispatchError (client, NULL, "xdr_remote_message_header");
index a17a0d733fc528a445bf9883e3c4eb51037a34fc..908f97c694cbc634233986369e4ee90961374205 100644 (file)
@@ -743,6 +743,7 @@ enum remote_message_status {
        REMOTE_ERROR = 1,
 };
 typedef enum remote_message_status remote_message_status;
+#define REMOTE_MESSAGE_HEADER_XDR_LEN 4
 
 struct remote_message_header {
        u_int prog;
index 3120d0be1c0d8a9a5901f5f51820c86f4174de94..6874af8182300fb3f0c5eed2c88185fd9b077569 100644 (file)
@@ -717,6 +717,9 @@ enum remote_message_status {
     REMOTE_ERROR = 1
 };
 
+/* 4 byte length word per header */
+const REMOTE_MESSAGE_HEADER_XDR_LEN = 4;
+
 struct remote_message_header {
     unsigned prog;              /* REMOTE_PROGRAM */
     unsigned vers;              /* REMOTE_PROTOCOL_VERSION */
index c69f9153edf0f049c9370e5305f3a7f0d832bfe4..5eeddac2e9a99d5ea5d5c09388c1a312e7a60d1c 100644 (file)
@@ -61,7 +61,6 @@ CLIENT_SOURCES =                                              \
                util.c util.h
 
 SERVER_SOURCES =                                               \
-               ../qemud/protocol.h ../qemud/protocol.c         \
                ../qemud/remote_protocol.c ../qemud/remote_protocol.h
 
 libvirt_la_SOURCES = $(CLIENT_SOURCES) $(SERVER_SOURCES)