Add flag to the clif command structure in preparation for adding
VN2VN support.

Signed-off-by: Mark Rustad <[email protected]>
Tested-by: Jack Morgan <[email protected]>
---

 fcoe_clif.h          |    5 +++++
 fcoeadm.c            |   13 ++++++++-----
 fcoemon.c            |   25 +++++++++++++++++--------
 include/fcoe_utils.h |    1 +
 4 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/fcoe_clif.h b/fcoe_clif.h
index 0c3d099..7f8db34 100644
--- a/fcoe_clif.h
+++ b/fcoe_clif.h
@@ -54,12 +54,17 @@ struct clif_sock_info {
        struct sockaddr_un dest;
 };
 
+enum clif_flags {
+       CLIF_FLAGS_NONE = 0,
+};
+
 /*
  * Description of fcoemon and fcoeadm socket data structure interface
  */
 struct clif_data {
        enum clif_action cmd;
        char ifname[IFNAMSIZ];
+       enum clif_flags flags;
 };
 
 #endif /* _FCOE_CLIF_H_ */
diff --git a/fcoeadm.c b/fcoeadm.c
index b88a648..c6dbac6 100644
--- a/fcoeadm.c
+++ b/fcoeadm.c
@@ -177,7 +177,8 @@ err_close:
 /*
  * Send request to fcoemon
  */
-static enum fcoe_status fcoeadm_action(enum clif_action cmd, char *ifname)
+static enum fcoe_status
+fcoeadm_action(enum clif_action cmd, char *ifname, enum clif_flags flags)
 {
        struct clif_data data;
        struct clif_sock_info clif_info;
@@ -188,6 +189,7 @@ static enum fcoe_status fcoeadm_action(enum clif_action 
cmd, char *ifname)
        else
                data.ifname[0] = '\0';
        data.cmd = cmd;
+       data.flags = flags;
 
        rc = fcoeadm_open_cli(&clif_info);
        if (!rc) {
@@ -250,7 +252,7 @@ int main(int argc, char *argv[])
                        }
 
                        ifname = optarg;
-                       rc = fcoeadm_action(cmd, ifname);
+                       rc = fcoeadm_action(cmd, ifname, CLIF_FLAGS_NONE);
 
                        break;
                case 'r':
@@ -269,8 +271,8 @@ int main(int argc, char *argv[])
                        rc = fcoe_validate_fcoe_conn(ifname);
 
                        if (!rc)
-                               rc = fcoeadm_action(cmd, ifname);
-
+                               rc = fcoeadm_action(cmd, ifname,
+                                                   CLIF_FLAGS_NONE);
                        break;
 
                case 'i':
@@ -375,7 +377,8 @@ int main(int argc, char *argv[])
                                rc = display_port_stats(ifname, stat_interval);
                        break;
                case 'p':
-                       rc = fcoeadm_action(CLIF_PID_CMD, NULL);
+                       rc = fcoeadm_action(CLIF_PID_CMD, NULL,
+                                           CLIF_FLAGS_NONE);
                        break;
 
                case 'b':
diff --git a/fcoemon.c b/fcoemon.c
index d7022ee..47d214a 100644
--- a/fcoemon.c
+++ b/fcoemon.c
@@ -3213,7 +3213,7 @@ static void fcm_srv_receive(void *arg)
        socklen_t fromlen = sizeof(struct sockaddr_un);
        struct sock_info *reply = NULL;
        char buf[MAX_MSGBUF], rbuf[MAX_MSGBUF];
-       char *ifname = NULL;
+       char ifname[sizeof(data->ifname) + 1];
        enum fcoe_status rc = EFAIL;
        int res, cmd, snum;
 
@@ -3226,13 +3226,26 @@ static void fcm_srv_receive(void *arg)
                return;
        }
 
-       buf[res] = '\0';
        data = (struct clif_data *)buf;
+       if (res < sizeof(*data)) {
+               if (res < sizeof(*data) - sizeof(data->flags)) {
+                       FCM_LOG_ERR(EMSGSIZE,
+                                   "Message too short from socket %d", snum);
+                       rc = EBADCLIFMSG;
+                       goto err;
+               }
+               data->flags = 0;
+       } else if (res > sizeof(*data)) {
+               FCM_LOG_ERR(EMSGSIZE, "Message too long from socket %d", snum);
+               rc = EBADCLIFMSG;
+               goto err;
+       }
 
        cmd = data->cmd;
-       if (cmd != CLIF_PID_CMD) {
-               ifname = strdup(data->ifname);
+       strncpy(ifname, data->ifname, sizeof(data->ifname));
+       ifname[sizeof(data->ifname)] = 0;
 
+       if (cmd != CLIF_PID_CMD) {
                rc = fcoe_validate_interface(ifname);
                if (rc)
                        goto err;
@@ -3278,13 +3291,9 @@ static void fcm_srv_receive(void *arg)
                goto err_out;
        }
 
-       if (ifname)
-               free(ifname);
        return;
 
 err_out:
-       if (ifname)
-               free(ifname);
        free(reply);
 err:
        snprintf(rbuf, MSG_RBUF, "%d", rc);
diff --git a/include/fcoe_utils.h b/include/fcoe_utils.h
index 037feab..531acab 100644
--- a/include/fcoe_utils.h
+++ b/include/fcoe_utils.h
@@ -78,6 +78,7 @@ enum fcoe_status {
        ENOMONCONN,   /* Not connected to fcoemon */
        ECONNTMOUT,   /* Connection to fcoemon timed out */
        EHBAAPIERR,   /* Error using HBAAPI/libhbalinux */
+       EBADCLIFMSG,  /* Messaging error */
 };
 
 enum fcoe_status fcoe_validate_interface(char *ifname);

_______________________________________________
fcoe-devel mailing list
[email protected]
http://lists.open-fcoe.org/mailman/listinfo/fcoe-devel

Reply via email to