build.zig

This commit is contained in:
Motiejus Jakštys 2024-10-10 11:01:53 -04:00
parent b54bab7e5b
commit 8c923f4a1b
11 changed files with 4781 additions and 4 deletions

6
.gitignore vendored
View File

@ -2,9 +2,9 @@
*~
Makefile
autom4te.cache
cfg_file.lex.c
cfg_file.tab.c
cfg_file.tab.h
#cfg_file.lex.c
#cfg_file.tab.c
#cfg_file.tab.h
config.guess
config.h
config.h.in

View File

@ -1,3 +1,11 @@
This is a fork of [Frank's VTUN](https://github.com/jedisct1/vtun) with the
following changes:
* `zig build` support, currently tested only on Linux.
Original README
---------------
This is a fork of [VTUN](http://vtun.sourceforge.net/), with the
following changes:

119
build.zig Normal file
View File

@ -0,0 +1,119 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const libsodium_dep = b.dependency(
"libsodium",
.{
.target = target,
.optimize = optimize,
.static = true,
.shared = false,
},
);
const exe = b.addExecutable(.{
.name = "vtund",
.target = target,
.optimize = optimize,
});
exe.linkLibrary(libsodium_dep.artifact("sodium"));
exe.linkLibC();
exe.addCSourceFiles(.{
.files = &.{
"auth.c",
"client.c",
//"freebsd/tun_dev.c",
"generic/pipe_dev.c",
"generic/pty_dev.c",
//"generic/tap_dev.c",
"generic/tcp_proto.c",
//"generic/tun_dev.c",
"generic/udp_proto.c",
"lfd_encrypt.c",
"lfd_lzo.c",
"lfd_shaper.c",
"lfd_zlib.c",
"lib.c",
"linkfd.c",
"linux/tap_dev.c",
"linux/tun_dev.c",
"llist.c",
"lock.c",
"main.c",
"netlib.c",
//"openbsd/tun_dev.c",
"server.c",
//"svr4/tap_dev.c",
//"svr4/tun_dev.c",
"tunnel.c",
"cfg_file.c",
"cfg_file.lex.c",
},
.flags = &.{
"-D_GNU_SOURCE",
"-fstack-protector-all",
"-fno-strict-overflow",
"-fno-strict-aliasing",
},
});
exe.addConfigHeader(b.addConfigHeader(.{
.include_path = "config.h",
}, .{
.VTUN_CONFIG_FILE = "/etc/vtund.conf",
.VTUN_PID_FILE = "/var/run/vtund.pid",
.VTUN_STAT_DIR = "/var/log/vtund",
.VTUN_LOCK_DIR = "/var/lock/vtund",
.ENABLE_NAT_HACK = 0,
.HAVE_ARPA_INET_H = 1,
.HAVE_FORK = 1,
//.HAVE_GETPT = 1, // pty tunnels
//.HAVE_GRANTPT = 1, // pty tunnels
.HAVE_INTTYPES_H = 1,
.HAVE_LINUX_IF_TUN_H = 1,
.HAVE_NETDB_H = 1,
.HAVE_NETINET_IN_H = 1,
.HAVE_NETINET_IN_SYSTM_H = 1,
.HAVE_NETINET_IP_H = 1,
.HAVE_NETINET_TCP_H = 1,
//.HAVE_PTSNAME = 1, // pty tunnels
.HAVE_RESOLV_H = 1,
.HAVE_SCHED_H = 1,
.HAVE_SHAPER = 1,
.HAVE_SODIUM = 1,
.HAVE_STDINT_H = 1,
.HAVE_STDIO_H = 1,
.HAVE_STDLIB_H = 1,
.HAVE_STRINGS_H = 1,
.HAVE_STRING_H = 1,
.HAVE_SYS_RESOURCE_H = 1,
.HAVE_SYS_STAT_H = 1,
.HAVE_SYS_TYPES_H = 1,
.HAVE_UNISTD_H = 1,
//.HAVE_UNLOCKPT = 1, // pty tunnels
.HAVE_VFORK = 1,
.HAVE_WORKING_FORK = 1,
.HAVE_WORKING_VFORK = 1,
.PACKAGE_BUGREPORT = "",
.PACKAGE_NAME = "vtun",
.PACKAGE_STRING = "vtun = 3",
.PACKAGE_TARNAME = "vtun",
.PACKAGE_URL = "",
.PACKAGE_VERSION = "3",
.STDC_HEADERS = 1,
.VTUN_VER = "3.X = 10/10/2024",
.YYTEXT_POINTER = 1,
}));
exe.addIncludePath(b.path("."));
b.installArtifact(exe);
}

81
build.zig.zon Normal file
View File

@ -0,0 +1,81 @@
.{
.name = "vtun",
.version = "1.1.0",
.minimum_zig_version = "0.12.0",
.dependencies = .{
.libsodium = .{
.url = "git+https://github.com/jedisct1/libsodium.git?ref=1.0.20-RELEASE#9511c982fb1d046470a8b42aa36556cdb7da15de",
.hash = "1220d265dc673167ffe4a3cefe2840893d2910cfd773cfb1893ff768d5f1351d2a1f",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
".cvsignore",
".gitignore",
"ChangeLog",
"Credits",
"Makefile.in",
"README",
"README.md",
"TODO",
"aclocal.m4",
"auth.c",
"auth.h",
"autogen.sh",
"build.zig",
"cfg_file.l",
"cfg_file.y",
"cfg_kwords.h",
"client.c",
"compat.h",
"configure.ac",
"driver.h",
"freebsd/tun_dev.c",
"generic/pipe_dev.c",
"generic/pty_dev.c",
"generic/tap_dev.c",
"generic/tcp_proto.c",
"generic/tun_dev.c",
"generic/udp_proto.c",
"lfd_encrypt.c",
"lfd_lzo.c",
"lfd_shaper.c",
"lfd_zlib.c",
"lib.c",
"lib.h",
"linkfd.c",
"linkfd.h",
"linux/tap_dev.c",
"linux/tun_dev.c",
"llist.c",
"llist.h",
"lock.c",
"lock.h",
"main.c",
"netlib.c",
"netlib.h",
"openbsd/tun_dev.c",
"packages/vtun.bsd.pkg",
"packages/vtun.solaris.info",
"packages/vtun.spec",
"scripts/reroute",
"scripts/vtund.rc.debian",
"server.c",
"svr4/tap_dev.c",
"svr4/tun_dev.c",
"tunnel.c",
"vtun.drivers",
"vtun.h",
"vtun_socks.h",
"vtund.8",
"vtund.conf",
"vtund.conf.5",
// generated
"cfg_file.c",
"cfg_file.lex.c",
"cfg_file.tab.h",
},
}

2406
cfg_file.c Normal file

File diff suppressed because it is too large Load Diff

1997
cfg_file.lex.c Normal file

File diff suppressed because it is too large Load Diff

163
cfg_file.tab.h Normal file
View File

@ -0,0 +1,163 @@
/* A Bison parser, made by GNU Bison 3.8.2. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
#ifndef YY_YY_CFG_FILE_TAB_H_INCLUDED
# define YY_YY_CFG_FILE_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token kinds. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
YYEMPTY = -2,
YYEOF = 0, /* "end of file" */
YYerror = 256, /* error */
YYUNDEF = 257, /* "invalid token" */
K_OPTIONS = 258, /* K_OPTIONS */
K_DEFAULT = 259, /* K_DEFAULT */
K_PORT = 260, /* K_PORT */
K_BINDADDR = 261, /* K_BINDADDR */
K_PERSIST = 262, /* K_PERSIST */
K_TIMEOUT = 263, /* K_TIMEOUT */
K_PASSWD = 264, /* K_PASSWD */
K_PROG = 265, /* K_PROG */
K_PPP = 266, /* K_PPP */
K_SPEED = 267, /* K_SPEED */
K_IFCFG = 268, /* K_IFCFG */
K_FWALL = 269, /* K_FWALL */
K_ROUTE = 270, /* K_ROUTE */
K_DEVICE = 271, /* K_DEVICE */
K_MULTI = 272, /* K_MULTI */
K_SRCADDR = 273, /* K_SRCADDR */
K_IFACE = 274, /* K_IFACE */
K_ADDR = 275, /* K_ADDR */
K_TYPE = 276, /* K_TYPE */
K_PROT = 277, /* K_PROT */
K_NAT_HACK = 278, /* K_NAT_HACK */
K_COMPRESS = 279, /* K_COMPRESS */
K_ENCRYPT = 280, /* K_ENCRYPT */
K_KALIVE = 281, /* K_KALIVE */
K_STAT = 282, /* K_STAT */
K_UP = 283, /* K_UP */
K_DOWN = 284, /* K_DOWN */
K_SYSLOG = 285, /* K_SYSLOG */
K_IPROUTE = 286, /* K_IPROUTE */
K_HOST = 287, /* K_HOST */
K_ERROR = 288, /* K_ERROR */
WORD = 289, /* WORD */
PATH = 290, /* PATH */
STRING = 291, /* STRING */
NUM = 292, /* NUM */
DNUM = 293 /* DNUM */
};
typedef enum yytokentype yytoken_kind_t;
#endif
/* Token kinds. */
#define YYEMPTY -2
#define YYEOF 0
#define YYerror 256
#define YYUNDEF 257
#define K_OPTIONS 258
#define K_DEFAULT 259
#define K_PORT 260
#define K_BINDADDR 261
#define K_PERSIST 262
#define K_TIMEOUT 263
#define K_PASSWD 264
#define K_PROG 265
#define K_PPP 266
#define K_SPEED 267
#define K_IFCFG 268
#define K_FWALL 269
#define K_ROUTE 270
#define K_DEVICE 271
#define K_MULTI 272
#define K_SRCADDR 273
#define K_IFACE 274
#define K_ADDR 275
#define K_TYPE 276
#define K_PROT 277
#define K_NAT_HACK 278
#define K_COMPRESS 279
#define K_ENCRYPT 280
#define K_KALIVE 281
#define K_STAT 282
#define K_UP 283
#define K_DOWN 284
#define K_SYSLOG 285
#define K_IPROUTE 286
#define K_HOST 287
#define K_ERROR 288
#define WORD 289
#define PATH 290
#define STRING 291
#define NUM 292
#define DNUM 293
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 68 "cfg_file.y"
char *str;
int num;
struct { int num1; int num2; } dnum;
#line 149 "cfg_file.tab.h"
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_CFG_FILE_TAB_H_INCLUDED */

View File

@ -25,6 +25,7 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <syslog.h>

1
lib.c
View File

@ -33,6 +33,7 @@
#include <sys/time.h>
#include <sys/wait.h>
#include <syslog.h>
#include <time.h>
#include <errno.h>
#include "vtun.h"

1
lib.h
View File

@ -27,6 +27,7 @@
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <sys/uio.h>
#ifdef HAVE_LIBUTIL_H
#include <libutil.h>

2
lock.c
View File

@ -27,7 +27,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <syslog.h>
#include <sys/types.h>
#include <signal.h>