diff options
| author | 2009-05-05 00:36:34 +0200 | |
|---|---|---|
| committer | 2009-05-05 00:36:34 +0200 | |
| commit | bcf6842e29b6cdaf71a8043fb0a0e42c032f1ed6 (patch) | |
| tree | 12aacaf09d16b5ce0768dc12d4c1a39d259fc661 /device.c | |
| parent | ad2e0ee9e0dc6750514c009a93dcf925f996baeb (diff) | |
| download | usbmuxd-bcf6842e29b6cdaf71a8043fb0a0e42c032f1ed6.tar.gz usbmuxd-bcf6842e29b6cdaf71a8043fb0a0e42c032f1ed6.tar.bz2 | |
Fix connection refused handling
Diffstat (limited to 'device.c')
| -rw-r--r-- | device.c | 7 |
1 files changed, 4 insertions, 3 deletions
| @@ -59,6 +59,7 @@ enum mux_dev_state { | |||
| 59 | enum mux_conn_state { | 59 | enum 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 { |
