summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--device.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/device.c b/device.c
index ead8b9e..c6ef75b 100644
--- a/device.c
+++ b/device.c
@@ -59,6 +59,7 @@ enum mux_dev_state {
59enum mux_conn_state { 59enum mux_conn_state {
60 CONN_CONNECTING, // SYN 60 CONN_CONNECTING, // SYN
61 CONN_CONNECTED, // SYN/SYNACK/ACK -> active 61 CONN_CONNECTED, // SYN/SYNACK/ACK -> active
62 CONN_REFUSED, // RST received during SYN
62 CONN_DYING, // RST received 63 CONN_DYING, // RST received
63 CONN_DEAD // being freed; used to prevent infinite recursion between client<->device freeing 64 CONN_DEAD // being freed; used to prevent infinite recursion between client<->device freeing
64}; 65};
@@ -227,13 +228,13 @@ static void connection_teardown(struct mux_connection *conn)
227 if(conn->state == CONN_DEAD) 228 if(conn->state == CONN_DEAD)
228 return; 229 return;
229 usbmuxd_log(LL_DEBUG, "connection_teardown dev %d sport %d dport %d", conn->dev->id, conn->sport, conn->dport); 230 usbmuxd_log(LL_DEBUG, "connection_teardown dev %d sport %d dport %d", conn->dev->id, conn->sport, conn->dport);
230 if(conn->dev->state != MUXDEV_DEAD && conn->state != CONN_DYING) { 231 if(conn->dev->state != MUXDEV_DEAD && conn->state != CONN_DYING && conn->state != CONN_REFUSED) {
231 res = send_tcp(conn, TH_RST, NULL, 0); 232 res = send_tcp(conn, TH_RST, NULL, 0);
232 if(res < 0) 233 if(res < 0)
233 usbmuxd_log(LL_ERROR, "Error sending TCP RST to device %d (%d->%d)", conn->dev->id, conn->sport, conn->dport); 234 usbmuxd_log(LL_ERROR, "Error sending TCP RST to device %d (%d->%d)", conn->dev->id, conn->sport, conn->dport);
234 } 235 }
235 if(conn->client) { 236 if(conn->client) {
236 if(conn->state == CONN_CONNECTING) { 237 if(conn->state == CONN_REFUSED || conn->state == CONN_CONNECTING) {
237 client_notify_connect(conn->client, RESULT_CONNREFUSED); 238 client_notify_connect(conn->client, RESULT_CONNREFUSED);
238 } else { 239 } else {
239 conn->state = CONN_DEAD; 240 conn->state = CONN_DEAD;
@@ -479,7 +480,7 @@ static void device_tcp_input(struct mux_device *dev, struct tcphdr *th, unsigned
479 if(conn->state == CONN_CONNECTING) { 480 if(conn->state == CONN_CONNECTING) {
480 if(th->th_flags != (TH_SYN|TH_ACK)) { 481 if(th->th_flags != (TH_SYN|TH_ACK)) {
481 if(th->th_flags & TH_RST) 482 if(th->th_flags & TH_RST)
482 conn->state = CONN_DYING; 483 conn->state = CONN_REFUSED;
483 usbmuxd_log(LL_INFO, "Connection refused by device %d (%d->%d)", dev->id, sport, dport); 484 usbmuxd_log(LL_INFO, "Connection refused by device %d (%d->%d)", dev->id, sport, dport);
484 connection_teardown(conn); //this also sends the notification to the client 485 connection_teardown(conn); //this also sends the notification to the client
485 } else { 486 } else {