Compare commits
14 Commits
v0.0.81-mu
...
v0.0.86-mu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0664fc3b21 | ||
|
|
2cb24c0523 | ||
|
|
65be22202c | ||
|
|
6cc32bafd9 | ||
|
|
6c268e658f | ||
|
|
33e24632d0 | ||
|
|
e1b4c6aafc | ||
|
|
09d1932588 | ||
|
|
4988479df4 | ||
|
|
7779e61c15 | ||
|
|
2cc8caec35 | ||
|
|
8c8715187b | ||
|
|
c591a4d3cc | ||
|
|
76cd7ed4b8 |
@@ -11,5 +11,8 @@ cd ..
|
||||
[ -x glorytun ] || exit 1
|
||||
|
||||
mkdir -p deploy
|
||||
|
||||
cp glorytun deploy/glorytun-$(cat VERSION)-$(uname -m).debug.bin
|
||||
|
||||
strip -s glorytun
|
||||
mv glorytun deploy/glorytun-$(cat VERSION)-$(uname -m).bin
|
||||
cp glorytun deploy/glorytun-$(cat VERSION)-$(uname -m).bin
|
||||
|
||||
@@ -17,7 +17,6 @@ glorytun_SOURCES = \
|
||||
src/db.c \
|
||||
src/db.h
|
||||
|
||||
glorytun_CFLAGS += -I$(srcdir)/mud
|
||||
glorytun_SOURCES += \
|
||||
mud/mud.h \
|
||||
mud/mud.c
|
||||
|
||||
2
mud
2
mud
Submodule mud updated: fd1a1285ac...f6b6610980
9
src/ip.h
9
src/ip.h
@@ -10,8 +10,8 @@ struct ip_common {
|
||||
uint16_t size;
|
||||
};
|
||||
|
||||
_pure_
|
||||
static inline uint8_t ip_get_version (const uint8_t *data, size_t size)
|
||||
_pure_ static inline uint8_t
|
||||
ip_get_version(const uint8_t *data, size_t size)
|
||||
{
|
||||
if (size < 20)
|
||||
return 0;
|
||||
@@ -19,7 +19,8 @@ static inline uint8_t ip_get_version (const uint8_t *data, size_t size)
|
||||
return data[0] >> 4;
|
||||
}
|
||||
|
||||
static inline int ip_get_common (struct ip_common *ic, const uint8_t *data, size_t size)
|
||||
static inline int
|
||||
ip_get_common(struct ip_common *ic, const uint8_t *data, size_t size)
|
||||
{
|
||||
ic->version = ip_get_version(data, size);
|
||||
|
||||
@@ -29,7 +30,9 @@ static inline int ip_get_common (struct ip_common *ic, const uint8_t *data, size
|
||||
ic->proto = data[9];
|
||||
ic->hdr_size = (data[0] & 0xF) << 2;
|
||||
ic->size = ((data[2] << 8) | data[3]);
|
||||
if (ic->size >= 20)
|
||||
return 0;
|
||||
break;
|
||||
case 6:
|
||||
ic->tc = ((data[0] & 0xF) << 4) | (data[1] >> 4);
|
||||
ic->proto = data[6];
|
||||
|
||||
18
src/main.c
18
src/main.c
@@ -18,7 +18,7 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "mud.h"
|
||||
#include "../mud/mud.h"
|
||||
|
||||
#ifndef O_CLOEXEC
|
||||
#define O_CLOEXEC 0
|
||||
@@ -50,6 +50,7 @@ static struct {
|
||||
.bind = {
|
||||
.port = 5000,
|
||||
},
|
||||
.mtu = 1500,
|
||||
.timeout = 5000,
|
||||
.ipv4 = 1,
|
||||
#ifdef __linux__
|
||||
@@ -385,10 +386,10 @@ main(int argc, char **argv)
|
||||
if (FD_ISSET(tun_fd, &rfds)) {
|
||||
size_t size = 0;
|
||||
|
||||
while (sizeof(buf) - size > gt.mtu) {
|
||||
const ssize_t r = tun_read(tun_fd, &buf[size],
|
||||
sizeof(buf) - size);
|
||||
if (r <= 0)
|
||||
while (sizeof(buf) - size >= gt.mtu) {
|
||||
const int r = tun_read(tun_fd, &buf[size], sizeof(buf) - size);
|
||||
|
||||
if (r <= 0 || r > gt.mtu)
|
||||
break;
|
||||
|
||||
struct ip_common ic;
|
||||
@@ -409,10 +410,8 @@ main(int argc, char **argv)
|
||||
struct ip_common ic;
|
||||
|
||||
if ((ip_get_common(&ic, &buf[q], size - q)) ||
|
||||
(ic.size > size - q)) {
|
||||
size = q;
|
||||
(ic.size > size - q))
|
||||
break;
|
||||
}
|
||||
|
||||
if (q + ic.size > p + gt.mtu)
|
||||
break;
|
||||
@@ -423,6 +422,9 @@ main(int argc, char **argv)
|
||||
tc = ic.tc & 0xFC;
|
||||
}
|
||||
|
||||
if (p >= q)
|
||||
break;
|
||||
|
||||
int r = mud_send(mud, &buf[p], q - p, tc);
|
||||
|
||||
if (r == -1 && errno == EMSGSIZE) {
|
||||
|
||||
18
src/str.h
18
src/str.h
@@ -2,7 +2,8 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
static inline size_t str_cpy (char *restrict dst, const char *restrict src, size_t len)
|
||||
static inline size_t
|
||||
str_cpy(char *restrict dst, const char *restrict src, size_t len)
|
||||
{
|
||||
if (!dst || !src)
|
||||
return 0;
|
||||
@@ -17,14 +18,14 @@ static inline size_t str_cpy (char *restrict dst, const char *restrict src, size
|
||||
return i;
|
||||
}
|
||||
|
||||
_pure_
|
||||
static inline int str_empty (const char *restrict str)
|
||||
_pure_ static inline int
|
||||
str_empty(const char *restrict str)
|
||||
{
|
||||
return !str || !str[0];
|
||||
}
|
||||
|
||||
_pure_
|
||||
static inline size_t str_cmp (const char *restrict sa, const char *restrict sb)
|
||||
_pure_ static inline size_t
|
||||
str_cmp(const char *restrict sa, const char *restrict sb)
|
||||
{
|
||||
if (!sa || !sb)
|
||||
return 1;
|
||||
@@ -38,8 +39,8 @@ static inline size_t str_cmp (const char *restrict sa, const char *restrict sb)
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
_pure_
|
||||
static inline size_t str_len (const char *restrict str)
|
||||
_pure_ static inline size_t
|
||||
str_len(const char *restrict str)
|
||||
{
|
||||
if (!str)
|
||||
return 0;
|
||||
@@ -47,7 +48,8 @@ static inline size_t str_len (const char *restrict str)
|
||||
return strlen(str);
|
||||
}
|
||||
|
||||
static inline char *str_cat (const char **strs, size_t count)
|
||||
static inline char *
|
||||
str_cat(const char **strs, size_t count)
|
||||
{
|
||||
size_t size = 1;
|
||||
|
||||
|
||||
55
src/tun.c
55
src/tun.c
@@ -45,7 +45,9 @@ tun_create_by_id(char *name, size_t size, unsigned id)
|
||||
str_cpy(ci.ctl_name, UTUN_CONTROL_NAME, sizeof(ci.ctl_name) - 1);
|
||||
|
||||
if (ioctl(fd, CTLIOCGINFO, &ci)) {
|
||||
int err = errno;
|
||||
close(fd);
|
||||
errno = err;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -58,7 +60,9 @@ tun_create_by_id(char *name, size_t size, unsigned id)
|
||||
};
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&sc, sizeof(sc))) {
|
||||
int err = errno;
|
||||
close(fd);
|
||||
errno = err;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -72,8 +76,10 @@ tun_create_by_name(char *name, size_t size, char *dev_name)
|
||||
{
|
||||
unsigned id = 0;
|
||||
|
||||
if (sscanf(dev_name, "utun%u", &id) != 1)
|
||||
if (sscanf(dev_name, "utun%u", &id) != 1) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return tun_create_by_id(name, size, id);
|
||||
}
|
||||
@@ -152,11 +158,11 @@ tun_create(char *dev_name, char **ret_name)
|
||||
return fd;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
int
|
||||
tun_read(int fd, void *data, size_t size)
|
||||
{
|
||||
if (!size)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
#ifdef GT_BSD_TUN
|
||||
uint32_t family;
|
||||
@@ -173,35 +179,24 @@ tun_read(int fd, void *data, size_t size)
|
||||
};
|
||||
|
||||
ssize_t ret = readv(fd, iov, 2);
|
||||
#else
|
||||
ssize_t ret = read(fd, data, size);
|
||||
#endif
|
||||
|
||||
if (ret == -1) {
|
||||
if (errno == EAGAIN || errno == EINTR)
|
||||
return -1;
|
||||
if (ret <= (ssize_t)0)
|
||||
return ret;
|
||||
|
||||
if (errno)
|
||||
perror("tun read");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef GT_BSD_TUN
|
||||
if (ret < (ssize_t)sizeof(family))
|
||||
if (ret <= (ssize_t)sizeof(family))
|
||||
return 0;
|
||||
|
||||
return ret - sizeof(family);
|
||||
#else
|
||||
return ret;
|
||||
return read(fd, data, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
ssize_t
|
||||
int
|
||||
tun_write(int fd, const void *data, size_t size)
|
||||
{
|
||||
if (!size)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
#ifdef GT_BSD_TUN
|
||||
uint32_t family;
|
||||
@@ -214,6 +209,7 @@ tun_write(int fd, const void *data, size_t size)
|
||||
family = htonl(AF_INET6);
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -229,27 +225,16 @@ tun_write(int fd, const void *data, size_t size)
|
||||
};
|
||||
|
||||
ssize_t ret = writev(fd, iov, 2);
|
||||
#else
|
||||
ssize_t ret = write(fd, data, size);
|
||||
#endif
|
||||
|
||||
if (ret == -1) {
|
||||
if (errno == EAGAIN || errno == EINTR)
|
||||
return -1;
|
||||
if (ret <= (ssize_t)0)
|
||||
return ret;
|
||||
|
||||
if (errno)
|
||||
perror("tun write");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef GT_BSD_TUN
|
||||
if (ret < (ssize_t)sizeof(family))
|
||||
if (ret <= (ssize_t)sizeof(family))
|
||||
return 0;
|
||||
|
||||
return ret - sizeof(family);
|
||||
#else
|
||||
return ret;
|
||||
return write(fd, data, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int tun_create (char *, char **);
|
||||
ssize_t tun_read (int, void *, size_t);
|
||||
ssize_t tun_write (int, const void *, size_t);
|
||||
int tun_read (int, void *, size_t);
|
||||
int tun_write (int, const void *, size_t);
|
||||
int tun_set_mtu (char *, int);
|
||||
|
||||
Reference in New Issue
Block a user