Skip to content

Commit

Permalink
discard non-IPv4 packet
Browse files Browse the repository at this point in the history
  • Loading branch information
lparam committed Aug 30, 2017
1 parent c365383 commit 88e42dc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ poll_cb(uv_poll_t *watcher, int status, int events) {
int mlen = read(ctx->tunfd, m, tun->mtu);
if (mlen <= 0) {
logger_log(LOG_ERR, "tun read error");
free(tunbuf);
return;
return free(tunbuf);
}

struct iphdr *iphdr = (struct iphdr *) m;
if (iphdr->version != 4) {
logger_log(LOG_WARNING, "Discard non-IPv4 packet");
return free(tunbuf);
}

if (mode == xTUN_SERVER) {
uv_rwlock_rdlock(&rwlock);
Expand Down Expand Up @@ -152,10 +155,10 @@ poll_cb(uv_poll_t *watcher, int status, int events) {
tcp_client_send(ctx, tunbuf, PRIMITIVE_BYTES + mlen);

} else {
free(tunbuf);
if (ctx->connect == DISCONNECTED) {
tcp_client_connect(ctx);
}
return free(tunbuf);
}

} else {
Expand Down

0 comments on commit 88e42dc

Please sign in to comment.