fix the tun driver bugs
This commit is contained in:
parent
2f49e6024d
commit
65b7008378
|
@ -141,6 +141,9 @@ CORE_DECLARE(status_t) tun_set_ipv4(sock_id id,
|
|||
/*
|
||||
* Send/Recv
|
||||
*/
|
||||
CORE_DECLARE(ssize_t) sock_write(sock_id id, const void *buf, size_t len);
|
||||
CORE_DECLARE(ssize_t) sock_read(sock_id id, void *buf, size_t len);
|
||||
|
||||
CORE_DECLARE(ssize_t) core_send(sock_id id,
|
||||
const void *buf, size_t len, int flags);
|
||||
CORE_DECLARE(ssize_t) core_sendto(sock_id id,
|
||||
|
|
|
@ -215,6 +215,40 @@ c_sockaddr_t *sock_remote_addr_get(sock_id id)
|
|||
return &sock->remote_addr;
|
||||
}
|
||||
|
||||
ssize_t sock_write(sock_id id, const void *buf, size_t len)
|
||||
{
|
||||
sock_t *sock = (sock_t *)id;
|
||||
ssize_t size;
|
||||
|
||||
d_assert(id, return -1,);
|
||||
|
||||
size = write(sock->fd, buf, len);
|
||||
if (size < 0)
|
||||
{
|
||||
d_error("sock_write(len:%ld) failed(%d:%s)",
|
||||
len, errno, strerror(errno));
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
ssize_t sock_read(sock_id id, void *buf, size_t len)
|
||||
{
|
||||
sock_t *sock = (sock_t *)id;
|
||||
ssize_t size;
|
||||
|
||||
d_assert(id, return -1,);
|
||||
|
||||
size = read(sock->fd, buf, len);
|
||||
if (size < 0)
|
||||
{
|
||||
d_error("sock_read(len:%ld) failed(%d:%s)",
|
||||
len, errno, strerror(errno));
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
ssize_t core_send(sock_id id, const void *buf, size_t len, int flags)
|
||||
{
|
||||
sock_t *sock = (sock_t *)id;
|
||||
|
@ -225,7 +259,7 @@ ssize_t core_send(sock_id id, const void *buf, size_t len, int flags)
|
|||
size = send(sock->fd, buf, len, flags);
|
||||
if (size < 0)
|
||||
{
|
||||
d_error("sock_send(len:%ld) failed(%d:%s)",
|
||||
d_error("core_send(len:%ld) failed(%d:%s)",
|
||||
len, errno, strerror(errno));
|
||||
}
|
||||
|
||||
|
@ -248,7 +282,7 @@ ssize_t core_sendto(sock_id id,
|
|||
size = sendto(sock->fd, buf, len, flags, &to->sa, addrlen);
|
||||
if (size < 0)
|
||||
{
|
||||
d_error("sock_sendto(len:%ld) failed(%d:%s)",
|
||||
d_error("core_sendto(len:%ld) failed(%d:%s)",
|
||||
len, errno, strerror(errno));
|
||||
}
|
||||
|
||||
|
@ -265,7 +299,7 @@ ssize_t core_recv(sock_id id, void *buf, size_t len, int flags)
|
|||
size = recv(sock->fd, buf, len, flags);
|
||||
if (size < 0)
|
||||
{
|
||||
d_error("sock_recvfrom(len:%ld) failed(%d:%s)",
|
||||
d_error("core_recv(len:%ld) failed(%d:%s)",
|
||||
len, errno, strerror(errno));
|
||||
}
|
||||
|
||||
|
@ -285,7 +319,7 @@ ssize_t core_recvfrom(sock_id id,
|
|||
size = recvfrom(sock->fd, buf, len, flags, &from->sa, &addrlen);
|
||||
if (size < 0)
|
||||
{
|
||||
d_error("sock_recvfrom(len:%ld) failed(%d:%s)",
|
||||
d_error("corek_recvfrom(len:%ld) failed(%d:%s)",
|
||||
len, errno, strerror(errno));
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ static int _gtpv1_tun_recv_cb(sock_id sock, void *data)
|
|||
recvbuf = pkbuf_alloc(GTPV1U_HEADER_LEN, MAX_SDU_LEN);
|
||||
d_assert(recvbuf, return -1, "pkbuf_alloc error");
|
||||
|
||||
n = core_recv(sock, recvbuf->payload, recvbuf->len, 0);
|
||||
n = sock_read(sock, recvbuf->payload, recvbuf->len);
|
||||
if (n <= 0)
|
||||
{
|
||||
pkbuf_free(recvbuf);
|
||||
|
@ -143,8 +143,8 @@ static int _gtpv1_u_recv_cb(sock_id sock, void *data)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (core_send(pgw_self()->ue_network[(c_uintptr_t)data].tun_link,
|
||||
pkbuf->payload, pkbuf->len, 0) <= 0)
|
||||
if (sock_write(pgw_self()->ue_network[(c_uintptr_t)data].tun_link,
|
||||
pkbuf->payload, pkbuf->len) <= 0)
|
||||
{
|
||||
d_error("Can not send packets to tuntap");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue