Skip to content

Commit

Permalink
externals/vtun: Notify vtun status for usrsock daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
SPRESENSE committed Dec 13, 2021
1 parent 83c291e commit f54051c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
2 changes: 1 addition & 1 deletion externals/vtun/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ LEXFLAGS := -t
YACC := yacc
YACCFLAGS := -d

VTUN_SH1 := c519f003072029efab49fad75efd7e6c7ea28c16
VTUN_SH1 := cbc46c9ad44e6c02196d5ea632fb41536331a200
VTUN_DIR := VTun-$(VTUN_SH1)
VTUN_URL := "https://codeload.github.com/SPRESENSE/VTun/zip/$(VTUN_SH1)"
VTUN_DL_NAME := archive.zip
Expand Down
55 changes: 43 additions & 12 deletions externals/vtun/compat_nuttx.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/blowfish.h>
#include <syslog.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <time.h>
#include <string.h>
Expand All @@ -54,12 +55,6 @@

#include "compat_nuttx.h"

/****************************************************************************
* Private Data
****************************************************************************/

static int session_established = 0;

/****************************************************************************
* Public Functions
****************************************************************************/
Expand All @@ -86,10 +81,51 @@ int getpriority(int which, id_t who)

int setpriority(int which, id_t who, int prio)
{
session_established = (prio == LINKFD_PRIO) ? 1 : 0;
return 0;
}

int update_vtun_state(int enable)
{
static int sockfd = -1;
int ret = 0;
uint8_t sock_type = 0;

if (sockfd < 0)
{
sockfd = socket(AF_INET, SOCK_STREAM, 0);
}

if (sockfd < 0)
{
return -1;
}

if (enable)
{
/* VTUN established */

sock_type = DENY_INET_SOCK_ENABLE;
}
else
{
/* VTUN abolished */

sock_type = DENY_INET_SOCK_DISABLE;
}

ret = ioctl(sockfd, SIOCDENYINETSOCK, (unsigned long) &sock_type);

if (!enable)
{
/* Close socket */

close(sockfd);
sockfd = -1;
}

return ret;
}

unsigned char *MD5(char *msg, size_t msg_len, char *out)
{
static mbedtls_md5_context ctx;
Expand Down Expand Up @@ -640,8 +676,3 @@ ssize_t vtun_udp_readv(int fd, const struct iovec *iov, int iovcnt)
return recv_len;
}

int vtun_session_established(void)
{
return session_established;
}

2 changes: 2 additions & 0 deletions externals/vtun/compat_nuttx.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void closelog(void);
int getpriority(int which, id_t who);
int setpriority(int which, id_t who, int prio);

int update_vtun_state(int enable);

pid_t setsid(void);

ssize_t vtun_udp_readv(int fd, const struct iovec *iov, int iovcnt);
Expand Down

0 comments on commit f54051c

Please sign in to comment.