summaryrefslogtreecommitdiffstats
path: root/usbmuxd/device.c
diff options
context:
space:
mode:
authorGravatar Hector Martin2009-08-16 16:18:02 +0200
committerGravatar Hector Martin2009-08-16 16:18:02 +0200
commita82a04f2c12b5ac5da8f9cb16c17ed4c4f6402a7 (patch)
tree8f619474fc7f91df13f70e197eade4496fa11e09 /usbmuxd/device.c
parentf97da6c050df57e640c080a46d8792bf87a7b651 (diff)
downloadusbmuxd-a82a04f2c12b5ac5da8f9cb16c17ed4c4f6402a7.tar.gz
usbmuxd-a82a04f2c12b5ac5da8f9cb16c17ed4c4f6402a7.tar.bz2
Send RST when unknown packets are received to kill any stale connections
Diffstat (limited to 'usbmuxd/device.c')
-rw-r--r--usbmuxd/device.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/usbmuxd/device.c b/usbmuxd/device.c
index 9296ea2..cddf718 100644
--- a/usbmuxd/device.c
+++ b/usbmuxd/device.c
@@ -198,6 +198,22 @@ static uint16_t find_sport(struct mux_device *dev)
}
}
+static int send_anon_rst(struct mux_device *dev, uint16_t sport, uint16_t dport, uint32_t ack)
+{
+ struct tcphdr th;
+ memset(&th, 0, sizeof(th));
+ th.th_sport = htons(sport);
+ th.th_dport = htons(dport);
+ th.th_ack = htonl(ack);
+ th.th_flags = TH_RST;
+ th.th_off = sizeof(th) / 4;
+
+ usbmuxd_log(LL_DEBUG, "[OUT] dev=%d sport=%d dport=%d flags=0x%x", dev->id, sport, dport, th.th_flags);
+
+ int res = send_packet(dev, MUX_PROTO_TCP, &th, NULL, 0);
+ return res;
+}
+
static int send_tcp(struct mux_connection *conn, uint8_t flags, const unsigned char *data, int length)
{
struct tcphdr th;
@@ -460,6 +476,10 @@ static void device_tcp_input(struct mux_device *dev, struct tcphdr *th, unsigned
if(!conn) {
usbmuxd_log(LL_WARNING, "No connection for device %d incoming packet %d->%d", dev->id, dport, sport);
+ if(!(th->th_flags & TH_RST)) {
+ if(send_anon_rst(dev, sport, dport, ntohl(th->th_seq)) < 0)
+ usbmuxd_log(LL_ERROR, "Error sending TCP RST to device %d (%d->%d)", conn->dev->id, sport, dport);
+ }
return;
}