From a70db7bcb21ebc13f319bac695142dd5ee40b184 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Mon, 23 Nov 2015 08:29:05 +0000 Subject: [PATCH] Control protocol cleanups. --- control-cmds.h | 2 +- control.cc | 15 ++++----------- control.h | 3 ++- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/control-cmds.h b/control-cmds.h index f948060..f0d2e76 100644 --- a/control-cmds.h +++ b/control-cmds.h @@ -14,7 +14,7 @@ constexpr static int DINIT_CP_ROLLBACKALL = 2; // Reply: ACK/NAK to request constexpr static int DINIT_RP_ACK = 50; -//constexpr static int DINIT_RP_NAK = 51; +constexpr static int DINIT_RP_NAK = 51; // Request was bad (connection will be closed) constexpr static int DINIT_RP_BADREQ = 52; diff --git a/control.cc b/control.cc index df992fa..fd1c366 100644 --- a/control.cc +++ b/control.cc @@ -18,7 +18,8 @@ void ControlConn::processPacket() uint16_t svcSize; memcpy(&svcSize, iobuf + 1, 2); - if (svcSize <= 0) { + chklen = svcSize + 3; + if (svcSize <= 0 || chklen > 1024) { // Queue error response mark connection bad char badreqRep[] = { DINIT_RP_BADREQ }; if (! queuePacket(badreqRep, 1)) return; @@ -27,15 +28,6 @@ void ControlConn::processPacket() return; } - chklen = svcSize + 3; - if (chklen > 1024) { - // We can't have a service name this long - // TODO error response - bad_conn_close = true; - ev_io_set(&iob, iob.fd, EV_WRITE); - return; - } - if (bufidx < chklen) { // packet not complete yet; read more return; @@ -78,7 +70,8 @@ void ControlConn::processPacket() if (! queuePacket(ackBuf, 1)) return; } else { - // TODO send NAK + char nakBuf[] = { DINIT_RP_NAK }; + if (! queuePacket(nakBuf, 1)) return; } // Clear the packet from the buffer diff --git a/control.h b/control.h index 845f3c7..42ba5a7 100644 --- a/control.h +++ b/control.h @@ -11,6 +11,8 @@ // Control connection for dinit +// TODO: Use the input buffer as a circular buffer, instead of chomping data from +// the front using a data move. // forward-declaration of callback: static void control_conn_cb(struct ev_loop * loop, ev_io * w, int revents); @@ -43,7 +45,6 @@ class ControlConn int bufidx; bool bad_conn_close; // close when finished output? - //bool bad_conn_wrerr; // write error has occurred bool oom_close; // send final 'out of memory' indicator template using list = std::list; -- 2.25.1