@@ -1,11 +1,10 @@
|
||||
#include "common.h"
|
||||
|
||||
#include <sodium.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <inttypes.h>
|
||||
#include <sodium.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../argz/argz.h"
|
||||
#include "../mud/aegis256/aegis256.h"
|
||||
|
||||
10
src/bind.c
10
src/bind.c
@@ -2,11 +2,9 @@
|
||||
#include "ctl.h"
|
||||
#include "iface.h"
|
||||
#include "ip.h"
|
||||
#include "str.h"
|
||||
#include "tun.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "../argz/argz.h"
|
||||
@@ -128,7 +126,7 @@ gt_bind(int argc, char **argv)
|
||||
if (argz(bindz, argc, argv))
|
||||
return 1;
|
||||
|
||||
if (str_empty(keyfile)) {
|
||||
if (EMPTY(keyfile)) {
|
||||
gt_log("a keyfile is needed!\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -321,8 +319,7 @@ gt_bind(int argc, char **argv)
|
||||
res.status.bind = bind_addr;
|
||||
res.status.peer = peer_addr;
|
||||
break;
|
||||
case CTL_PATH_STATUS:
|
||||
{
|
||||
case CTL_PATH_STATUS: {
|
||||
unsigned count = 0;
|
||||
struct mud_path *paths = mud_get_paths(mud, &count);
|
||||
|
||||
@@ -342,8 +339,7 @@ gt_bind(int argc, char **argv)
|
||||
|
||||
free(paths);
|
||||
res.ret = 0;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case CTL_BAD:
|
||||
if (mud_get_bad(mud, &res.bad))
|
||||
res.ret = errno;
|
||||
|
||||
23
src/common.h
23
src/common.h
@@ -4,16 +4,17 @@
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifndef PACKAGE_NAME
|
||||
#define PACKAGE_NAME "glorytun"
|
||||
@@ -25,18 +26,8 @@
|
||||
|
||||
#define COUNT(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
#define ALIGN_SIZE (1<<4)
|
||||
#define ALIGN_MASK (ALIGN_SIZE-1)
|
||||
|
||||
#define ALIGN(x) (((x)+ALIGN_MASK)&~ALIGN_MASK)
|
||||
#define ALIGN_DOWN(x) ((x)&~ALIGN_MASK)
|
||||
|
||||
#define PALIGN(x) ((void *)ALIGN((size_t)(x)))
|
||||
#define PALIGN_DOWN(x) ((void *)ALIGN_DOWN((size_t)(x)))
|
||||
|
||||
#define _1_(x) (__builtin_expect((x), 1))
|
||||
#define _0_(x) (__builtin_expect((x), 0))
|
||||
|
||||
#define CLZ(x) (__builtin_clz(x))
|
||||
|
||||
#define _printf_(A, B) __attribute__((format(printf, A, B)))
|
||||
@@ -52,6 +43,8 @@
|
||||
#undef MIN
|
||||
#define MIN(x, y) ({ __typeof__(x) X=(x); __typeof__(y) Y=(y); X < Y ? X : Y; })
|
||||
|
||||
#define EMPTY(x) ({ __typeof__(x) X=(x); !X || !X[0]; })
|
||||
|
||||
#define GT_CIPHER(x) ((x) ? "chacha20poly1305" : "aegis256")
|
||||
|
||||
extern volatile sig_atomic_t gt_alarm;
|
||||
@@ -66,6 +59,7 @@ int gt_fromhex (uint8_t *, size_t, const char *, size_t);
|
||||
|
||||
void gt_set_port (struct sockaddr *, uint16_t);
|
||||
uint16_t gt_get_port (struct sockaddr *);
|
||||
|
||||
int gt_toaddr (char *, size_t, struct sockaddr *);
|
||||
|
||||
int gt_list (int, char **);
|
||||
@@ -75,3 +69,4 @@ int gt_path (int, char **);
|
||||
int gt_keygen (int, char **);
|
||||
int gt_bench (int, char **);
|
||||
int gt_set (int, char **);
|
||||
int gt_version (int, char **);
|
||||
|
||||
10
src/ctl.c
10
src/ctl.c
@@ -1,13 +1,9 @@
|
||||
#include "common.h"
|
||||
#include "ctl.h"
|
||||
#include "str.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <libgen.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
@@ -90,7 +86,7 @@ ctl_bind(int fd, const char *dir, const char *file)
|
||||
char name[10] = {[0] = '.'};
|
||||
struct sockaddr_un sun;
|
||||
|
||||
if (str_empty(file)) {
|
||||
if (EMPTY(file)) {
|
||||
unsigned pid = (unsigned)getpid();
|
||||
|
||||
for (size_t i = 1; i < sizeof(name) - 1; i++, pid >>= 4)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "common.h"
|
||||
#include "iface.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <net/if.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
int
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
int iface_set_mtu (const char *, size_t);
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
|
||||
#include "../argz/argz.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/un.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
gt_list(int argc, char **argv)
|
||||
|
||||
28
src/main.c
28
src/main.c
@@ -1,7 +1,5 @@
|
||||
#include "common.h"
|
||||
#include "str.h"
|
||||
|
||||
#include <sodium.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../argz/argz.h"
|
||||
@@ -46,28 +44,6 @@ gt_set_signal(void)
|
||||
sigaction(SIGUSR2, &sa, NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
gt_version(int argc, char **argv)
|
||||
{
|
||||
struct argz version_argz[] = {
|
||||
{"libsodium", NULL, NULL, argz_option},
|
||||
{NULL}};
|
||||
|
||||
if (argz(version_argz, argc, argv))
|
||||
return 1;
|
||||
|
||||
if (argz_is_set(version_argz, "libsodium")) {
|
||||
printf("%i.%i (%s)\n",
|
||||
sodium_library_version_major(),
|
||||
sodium_library_version_minor(),
|
||||
sodium_version_string());
|
||||
} else {
|
||||
printf("%s\n", PACKAGE_VERSION);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@@ -90,7 +66,7 @@ main(int argc, char **argv)
|
||||
|
||||
if (argv[1]) {
|
||||
for (int k = 0; cmd[k].name; k++) {
|
||||
if (!str_cmp(cmd[k].name, argv[1]))
|
||||
if (!strcmp(cmd[k].name, argv[1]))
|
||||
return cmd[k].call(argc - 1, argv + 1);
|
||||
}
|
||||
}
|
||||
@@ -100,7 +76,7 @@ main(int argc, char **argv)
|
||||
int len = 0;
|
||||
|
||||
for (int k = 0; cmd[k].name; k++)
|
||||
len = MAX(len, (int)str_len(cmd[k].name, 32));
|
||||
len = MAX(len, (int)strlen(cmd[k].name));
|
||||
|
||||
for (int k = 0; cmd[k].name; k++)
|
||||
printf(" %-*s %s\n", len, cmd[k].name, cmd[k].help);
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
#include "common.h"
|
||||
#include "ctl.h"
|
||||
#include "str.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../argz/argz.h"
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#include "common.h"
|
||||
#include "ctl.h"
|
||||
#include "str.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "../argz/argz.h"
|
||||
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
#include "common.h"
|
||||
#include "ctl.h"
|
||||
#include "str.h"
|
||||
|
||||
#include "../argz/argz.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/un.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void
|
||||
gt_show_bad_line(int term, char *name, uint64_t count,
|
||||
|
||||
33
src/str.h
33
src/str.h
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.h"
|
||||
|
||||
_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)
|
||||
{
|
||||
if (!sa || !sb)
|
||||
return 1;
|
||||
|
||||
size_t i = 0;
|
||||
|
||||
while (sa[i] == sb[i])
|
||||
if (!sa[i++])
|
||||
return 0;
|
||||
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
_pure_ static inline size_t
|
||||
str_len(const char *restrict str, size_t len)
|
||||
{
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
return strnlen(str, len);
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
#include "tun.h"
|
||||
#include "common.h"
|
||||
#include "ip.h"
|
||||
#include "str.h"
|
||||
#include "tun.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/uio.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#define IFF_TUN 0x0001
|
||||
@@ -172,7 +171,7 @@ tun_create(char *name, size_t len, const char *dev_name)
|
||||
{
|
||||
int fd = -1;
|
||||
|
||||
if (str_empty(dev_name)) {
|
||||
if (EMPTY(dev_name)) {
|
||||
for (unsigned id = 0; id < 32 && fd == -1; id++)
|
||||
fd = tun_create_by_id(name, len, id);
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
int tun_create (char *, size_t, const char *);
|
||||
int tun_read (int, void *, size_t);
|
||||
int tun_write (int, const void *, size_t);
|
||||
|
||||
27
src/version.c
Normal file
27
src/version.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "common.h"
|
||||
|
||||
#include <sodium.h>
|
||||
|
||||
#include "../argz/argz.h"
|
||||
|
||||
int
|
||||
gt_version(int argc, char **argv)
|
||||
{
|
||||
struct argz version_argz[] = {
|
||||
{"libsodium", NULL, NULL, argz_option},
|
||||
{NULL}};
|
||||
|
||||
if (argz(version_argz, argc, argv))
|
||||
return 1;
|
||||
|
||||
if (argz_is_set(version_argz, "libsodium")) {
|
||||
printf("%i.%i (%s)\n",
|
||||
sodium_library_version_major(),
|
||||
sodium_library_version_minor(),
|
||||
sodium_version_string());
|
||||
} else {
|
||||
printf("%s\n", PACKAGE_VERSION);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user