Check ip address of incoming packet

This commit is contained in:
Erik Ekman 2006-11-18 16:19:39 +00:00
parent 1c7f63e97a
commit cf3ca7e5d0
1 changed files with 44 additions and 29 deletions

View File

@ -150,6 +150,11 @@ tunnel(int tun_fd, int dns_fd)
dnsd_send(dns_fd, &q, out, 8);
}
} else if(in[0] == 'L' || in[0] == 'l') {
// Check sending ip number
if (q.fromlen != u.addrlen ||
memcmp(&(u.host), &(q.from), q.fromlen) != 0) {
dnsd_send(dns_fd, &q, "BADIP", 5);
} else {
// Login phase, handle auth
login_calculate(logindata, 16, password, seed);
if (read >= 17 && (memcmp(logindata, in+1, 16) == 0)) {
@ -171,6 +176,7 @@ tunnel(int tun_fd, int dns_fd)
} else {
dnsd_send(dns_fd, &q, "LNAK", 4);
}
}
} else if((in[0] >= '0' && in[0] <= '9')
|| (in[0] >= 'a' && in[0] <= 'f')
|| (in[0] >= 'A' && in[0] <= 'F')) {
@ -181,6 +187,11 @@ tunnel(int tun_fd, int dns_fd)
if ((in[0] >= 'A' && in[0] <= 'F'))
code = in[0] - 'A' + 10;
// Check sending ip number
if (q.fromlen != u.addrlen ||
memcmp(&(u.host), &(q.from), q.fromlen) != 0) {
dnsd_send(dns_fd, &q, "BADIP", 5);
} else {
memcpy(packetbuf.data + packetbuf.offset, in + 1, read - 1);
packetbuf.len += read - 1;
packetbuf.offset += read - 1;
@ -194,7 +205,11 @@ tunnel(int tun_fd, int dns_fd)
packetbuf.len = packetbuf.offset = 0;
}
}
if (outpacket.len > 0) {
}
if (q.fromlen == u.addrlen &&
memcmp(&(u.host), &(q.from), q.fromlen) == 0 &&
outpacket.len > 0) {
dnsd_send(dns_fd, &q, outpacket.data, outpacket.len);
outpacket.len = 0;
q.id = 0;