Skip to content

Commit f54051c

Browse files
committed
externals/vtun: Notify vtun status for usrsock daemon
1 parent 83c291e commit f54051c

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

externals/vtun/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ LEXFLAGS := -t
5454
YACC := yacc
5555
YACCFLAGS := -d
5656

57-
VTUN_SH1 := c519f003072029efab49fad75efd7e6c7ea28c16
57+
VTUN_SH1 := cbc46c9ad44e6c02196d5ea632fb41536331a200
5858
VTUN_DIR := VTun-$(VTUN_SH1)
5959
VTUN_URL := "https://codeload.github.com/SPRESENSE/VTun/zip/$(VTUN_SH1)"
6060
VTUN_DL_NAME := archive.zip

externals/vtun/compat_nuttx.c

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <mbedtls/ctr_drbg.h>
4343
#include <mbedtls/blowfish.h>
4444
#include <syslog.h>
45+
#include <sys/ioctl.h>
4546
#include <sys/uio.h>
4647
#include <time.h>
4748
#include <string.h>
@@ -54,12 +55,6 @@
5455

5556
#include "compat_nuttx.h"
5657

57-
/****************************************************************************
58-
* Private Data
59-
****************************************************************************/
60-
61-
static int session_established = 0;
62-
6358
/****************************************************************************
6459
* Public Functions
6560
****************************************************************************/
@@ -86,10 +81,51 @@ int getpriority(int which, id_t who)
8681

8782
int setpriority(int which, id_t who, int prio)
8883
{
89-
session_established = (prio == LINKFD_PRIO) ? 1 : 0;
9084
return 0;
9185
}
9286

87+
int update_vtun_state(int enable)
88+
{
89+
static int sockfd = -1;
90+
int ret = 0;
91+
uint8_t sock_type = 0;
92+
93+
if (sockfd < 0)
94+
{
95+
sockfd = socket(AF_INET, SOCK_STREAM, 0);
96+
}
97+
98+
if (sockfd < 0)
99+
{
100+
return -1;
101+
}
102+
103+
if (enable)
104+
{
105+
/* VTUN established */
106+
107+
sock_type = DENY_INET_SOCK_ENABLE;
108+
}
109+
else
110+
{
111+
/* VTUN abolished */
112+
113+
sock_type = DENY_INET_SOCK_DISABLE;
114+
}
115+
116+
ret = ioctl(sockfd, SIOCDENYINETSOCK, (unsigned long) &sock_type);
117+
118+
if (!enable)
119+
{
120+
/* Close socket */
121+
122+
close(sockfd);
123+
sockfd = -1;
124+
}
125+
126+
return ret;
127+
}
128+
93129
unsigned char *MD5(char *msg, size_t msg_len, char *out)
94130
{
95131
static mbedtls_md5_context ctx;
@@ -640,8 +676,3 @@ ssize_t vtun_udp_readv(int fd, const struct iovec *iov, int iovcnt)
640676
return recv_len;
641677
}
642678

643-
int vtun_session_established(void)
644-
{
645-
return session_established;
646-
}
647-

externals/vtun/compat_nuttx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ void closelog(void);
108108
int getpriority(int which, id_t who);
109109
int setpriority(int which, id_t who, int prio);
110110

111+
int update_vtun_state(int enable);
112+
111113
pid_t setsid(void);
112114

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

0 commit comments

Comments
 (0)