Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/iscsid Handle invalid messages more gracefully, handle ...



details:   https://anonhg.NetBSD.org/src/rev/b1e6bb442e7e
branches:  trunk
changeset: 783559:b1e6bb442e7e
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sat Dec 29 08:28:20 2012 +0000

description:
Handle invalid messages more gracefully, handle sessions with no valid
connections, and be more verbose about errors.

diffstat:

 sbin/iscsid/iscsid_driverif.c |  12 +++++++++---
 sbin/iscsid/iscsid_lists.c    |  40 ++++++++++++++++++++++++++++------------
 sbin/iscsid/iscsid_main.c     |  12 +++++++++---
 sbin/iscsid/iscsid_targets.c  |   5 ++---
 4 files changed, 48 insertions(+), 21 deletions(-)

diffs (156 lines):

diff -r d7f1625e9559 -r b1e6bb442e7e sbin/iscsid/iscsid_driverif.c
--- a/sbin/iscsid/iscsid_driverif.c     Sat Dec 29 05:36:57 2012 +0000
+++ b/sbin/iscsid/iscsid_driverif.c     Sat Dec 29 08:28:20 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_driverif.c,v 1.5 2012/05/27 20:05:04 christos Exp $     */
+/*     $NetBSD: iscsid_driverif.c,v 1.6 2012/12/29 08:28:20 mlelstv Exp $      */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -559,7 +559,7 @@
 
        serverAddress.sin_family = host->h_addrtype;
        serverAddress.sin_port = htons((addr->port)
-                                                                       ? addr->port : ISCSI_DEFAULT_PORT);
+               ? addr->port : ISCSI_DEFAULT_PORT);
        serverAddress.sin_len = host->h_length;
        memcpy(&serverAddress.sin_addr, host->h_addr_list[0], host->h_length);
 
@@ -927,13 +927,19 @@
                        rc = ioctl(driver, ISCSI_POLL_EVENT, &evtp);
                else
                        rc = ioctl(driver, ISCSI_WAIT_EVENT, &evtp);
-               if (rc || evtp.status)
+
+               if (rc != 0) {
+                       perror("ioctl");
                        break;
+               }
 
                DEB(1, ("Got Event: kind %d, status %d, sid %d, cid %d, reason %d\n",
                                evtp.event_kind, evtp.status, evtp.session_id,
                                evtp.connection_id, evtp.reason));
 
+               if (evtp.status)
+                       break;
+
                switch (evtp.event_kind) {
                case ISCSI_SESSION_TERMINATED:
                        event_kill_session(evtp.session_id);
diff -r d7f1625e9559 -r b1e6bb442e7e sbin/iscsid/iscsid_lists.c
--- a/sbin/iscsid/iscsid_lists.c        Sat Dec 29 05:36:57 2012 +0000
+++ b/sbin/iscsid/iscsid_lists.c        Sat Dec 29 08:28:20 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_lists.c,v 1.7 2012/05/28 00:37:55 riz Exp $     */
+/*     $NetBSD: iscsid_lists.c,v 1.8 2012/12/29 08:28:20 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -543,10 +543,16 @@
                conn = (connection_t *)(void *)TAILQ_FIRST(&sess->connections);
 
                ent->session_id = sess->entry.sid;
-               ent->first_connection_id = conn->entry.sid.id;
                ent->num_connections = sess->num_connections;
-               ent->portal_id = conn->portal.sid.id;
-               ent->initiator_id = conn->initiator_id;
+               if (conn) {
+                       ent->first_connection_id = conn->entry.sid.id;
+                       ent->portal_id = conn->portal.sid.id;
+                       ent->initiator_id = conn->initiator_id;
+               } else {
+                       ent->first_connection_id = 0;
+                       ent->portal_id = 0;
+                       ent->initiator_id = 0;
+               }
                ent++;
        }
        UNLOCK_SESSIONS;
@@ -652,19 +658,29 @@
                return;
        }
 
-       if (conn->initiator_id)
+       if (conn && conn->initiator_id)
                init = find_initiator_id(conn->initiator_id);
 
        res = (iscsid_get_connection_info_rsp_t *)(void *)rsp->parameter;
 
        res->session_id = sess->entry.sid;
-       res->connection_id = conn->entry.sid;
-       res->target_portal_id = conn->portal.sid;
-       res->target_portal = conn->portal.addr;
-       strlcpy((char *)res->TargetName, (char *)conn->target.TargetName,
-               sizeof(res->TargetName));
-       strlcpy((char *)res->TargetAlias, (char *)conn->target.TargetAlias,
-               sizeof(res->TargetAlias));
+       if (conn) {
+               res->connection_id = conn->entry.sid;
+               res->target_portal_id = conn->portal.sid;
+               res->target_portal = conn->portal.addr;
+               strlcpy((char *)res->TargetName, (char *)conn->target.TargetName,
+                       sizeof(res->TargetName));
+               strlcpy((char *)res->TargetAlias, (char *)conn->target.TargetAlias,
+                       sizeof(res->TargetAlias));
+       } else {
+               res->connection_id.id = 0;
+               res->connection_id.name[0] = '\0';
+               res->target_portal_id.id = 0;
+               res->target_portal_id.name[0] = '\0';
+               memset(&res->target_portal, 0, sizeof(res->target_portal));
+               memset(&res->TargetName, 0, sizeof(res->TargetName));
+               memset(&res->TargetAlias, 0, sizeof(res->TargetAlias));
+       }
        if (init != NULL) {
                res->initiator_id = init->entry.sid;
                strlcpy((char *)res->initiator_address, (char *)init->address,
diff -r d7f1625e9559 -r b1e6bb442e7e sbin/iscsid/iscsid_main.c
--- a/sbin/iscsid/iscsid_main.c Sat Dec 29 05:36:57 2012 +0000
+++ b/sbin/iscsid/iscsid_main.c Sat Dec 29 08:28:20 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_main.c,v 1.7 2012/05/28 00:13:19 riz Exp $      */
+/*     $NetBSD: iscsid_main.c,v 1.8 2012/12/29 08:28:20 mlelstv Exp $  */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -621,13 +621,19 @@
                /* no return path? then we can't send a reply, */
                /* so don't process the command */
                if (!from.sun_path[0]) {
+                       if (req_temp)
+                               free(req);
                        DEBOUT(("No Return Address!\n"));
                        continue;
                }
                /* process the request */
                process_message(req, &rsp, &rsp_temp);
-               if (rsp == NULL)
-                       break;
+               if (rsp == NULL) {
+                       if (req_temp)
+                               free(req);
+                       DEBOUT(("Invalid message!\n"));
+                       continue;
+               }
 
                DEB(98, ("Sending reply: status %d, len %d\n",
                                rsp->status, rsp->parameter_length));
diff -r d7f1625e9559 -r b1e6bb442e7e sbin/iscsid/iscsid_targets.c
--- a/sbin/iscsid/iscsid_targets.c      Sat Dec 29 05:36:57 2012 +0000
+++ b/sbin/iscsid/iscsid_targets.c      Sat Dec 29 08:28:20 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_targets.c,v 1.4 2012/05/27 16:50:32 riz Exp $   */
+/*     $NetBSD: iscsid_targets.c,v 1.5 2012/12/29 08:28:20 mlelstv Exp $       */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -872,8 +872,7 @@
                                                &addr, PORTAL_TYPE_SENDTARGET,
                                                id);
                                } else {
-                                       DEBOUT(("Syntax error in returned target address <%s>\n",
-                                                       tp));
+                                       DEBOUT(("Syntax error in returned target address <%s>\n", sp));
                                        break;
                                }
                        }



Home | Main Index | Thread Index | Old Index