Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,24 @@ fi

CFLAGS="$CFLAGS -DQT_VERSION=\"`cat version`\""

echo Building combined binary...
$cc $CFLAGS -c -DCOMBINED_BINARY src/proto.raw.c -o obj/proto.raw.o
$cc $CFLAGS -c -DCOMBINED_BINARY src/proto.nacl0.c -o obj/proto.nacl0.o
$cc $CFLAGS -c -DCOMBINED_BINARY src/proto.nacltai.c -o obj/proto.nacltai.o
$cc $CFLAGS -c -DCOMBINED_BINARY src/proto.salty.c -o obj/proto.salty.o
$cc $CFLAGS -c -DCOMBINED_BINARY src/run.combined.c -o obj/run.combined.o
$cc $CFLAGS -c src/common.c -o obj/common.o
$cc $CFLAGS -o out/quicktun.combined obj/common.o obj/run.combined.o obj/proto.raw.o obj/proto.nacl0.o obj/proto.nacltai.o obj/proto.salty.o -l$CRYPTLIB $LDFLAGS
ln out/quicktun.combined out/quicktun
echo Building binaries...
$cc $CFLAGS -c src/proto.raw.c -o obj/proto.raw.o
$cc $CFLAGS -c src/proto.nacl0.c -o obj/proto.nacl0.o
$cc $CFLAGS -c src/proto.nacltai.c -o obj/proto.nacltai.o
$cc $CFLAGS -c src/proto.salty.c -o obj/proto.salty.o
$cc $CFLAGS -c src/main.c -o obj/main.o
$cc $CFLAGS -c src/common.c -o obj/common.o
$cc $CFLAGS -o out/quicktun obj/common.o obj/main.o obj/proto.raw.o obj/proto.nacl0.o obj/proto.nacltai.o obj/proto.salty.o -l$CRYPTLIB $LDFLAGS
$cc $CFLAGS -o out/quicktun.keypair src/keypair.c obj/common.o -l$CRYPTLIB $LDFLAGS

echo Building single protocol binaries...
$cc $CFLAGS -o out/quicktun.raw src/proto.raw.c $LDFLAGS
$cc $CFLAGS -o out/quicktun.nacl0 src/proto.nacl0.c -l$CRYPTLIB $LDFLAGS
$cc $CFLAGS -o out/quicktun.nacltai src/proto.nacltai.c -l$CRYPTLIB $LDFLAGS
$cc $CFLAGS -o out/quicktun.salty src/proto.salty.c -l$CRYPTLIB $LDFLAGS
$cc $CFLAGS -o out/quicktun.keypair src/keypair.c -l$CRYPTLIB $LDFLAGS
echo Creating compatibility symlinks...
for proto in combined raw nacl0 nacltai salty; do
ln -s quicktun out/quicktun.$proto
done

if [ -f /etc/network/interfaces ]; then
echo Building debian binary...
$cc $CFLAGS -c -DCOMBINED_BINARY -DDEBIAN_BINARY src/run.combined.c -o obj/run.debian.o
$cc $CFLAGS -c -DDEBIAN_BINARY src/main.c -o obj/run.debian.o
$cc $CFLAGS -o out/quicktun.debian obj/common.o obj/run.debian.o obj/proto.raw.o obj/proto.nacl0.o obj/proto.nacltai.o obj/proto.salty.o -l$CRYPTLIB $LDFLAGS
if [ -x /usr/bin/dpkg-deb -a -x /usr/bin/fakeroot ]; then
echo -n Building debian package...
Expand Down
70 changes: 2 additions & 68 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,78 +23,14 @@
authors and should not be interpreted as representing official policies, either expressed
or implied, of Ivo Smits.*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include "common.h"

#include <pwd.h>
#include <grp.h>
#ifndef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <poll.h>
#include <netdb.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <net/if.h>
#ifdef linux
#include <linux/if_tun.h>
#include <linux/if_ether.h>
#else
#define ETH_FRAME_LEN 1514
#include <net/if_tun.h>
#ifdef SOLARIS
#include <sys/stropts.h>
#include <sys/sockio.h>
#endif
#endif

#define MAX_PACKET_LEN (ETH_FRAME_LEN+4) //Some space for optional packet information

typedef union {
struct sockaddr any;
struct sockaddr_in ip4;
struct sockaddr_in6 ip6;
} sockaddr_any;

struct qtsession;
struct qtproto {
int encrypted;
int buffersize_raw;
int buffersize_enc;
int offset_raw;
int offset_enc;
int (*encode)(struct qtsession* sess, char* raw, char* enc, int len);
int (*decode)(struct qtsession* sess, char* enc, char* raw, int len);
int (*init)(struct qtsession* sess);
int protocol_data_size;
void (*idle)(struct qtsession* sess);
};
struct qtsession {
struct qtproto protocol;
void* protocol_data;
int fd_socket;
int fd_dev;
int remote_float;
sockaddr_any remote_addr;
int use_pi;
int poll_timeout;
void (*sendnetworkpacket)(struct qtsession* sess, char* msg, int len);
};

#ifdef COMBINED_BINARY
extern char* (*getconf)(const char*);
extern int errorexit(const char*);
extern int errorexitp(const char*);
extern void print_header();
extern void hex2bin(unsigned char*, const char*, const int);
extern int debug;
extern int qtrun(struct qtproto* p);
extern int qtprocessargs(int argc, char** argv);
#else

char* (*getconf)(const char*) = getenv;
int debug = 0;
Expand Down Expand Up @@ -435,5 +371,3 @@ int qtprocessargs(int argc, char** argv) {
}
return 0;
}
#endif

93 changes: 93 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* Copyright 2010 Ivo Smits <Ivo@UCIS.nl>. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of Ivo Smits.*/

#ifndef QT_COMMON_H_
#define QT_COMMON_H_

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <net/if.h>
#ifdef linux
#include <linux/if_tun.h>
#include <linux/if_ether.h>
#else
#define ETH_FRAME_LEN 1514
#include <net/if_tun.h>
#ifdef SOLARIS
#include <sys/stropts.h>
#include <sys/sockio.h>
#endif
#endif

#define MAX_PACKET_LEN (ETH_FRAME_LEN+4) //Some space for optional packet information

typedef union {
struct sockaddr any;
struct sockaddr_in ip4;
struct sockaddr_in6 ip6;
} sockaddr_any;

struct qtsession;
struct qtproto {
int encrypted;
int buffersize_raw;
int buffersize_enc;
int offset_raw;
int offset_enc;
int (*encode)(struct qtsession* sess, char* raw, char* enc, int len);
int (*decode)(struct qtsession* sess, char* enc, char* raw, int len);
int (*init)(struct qtsession* sess);
int protocol_data_size;
void (*idle)(struct qtsession* sess);
};
struct qtsession {
struct qtproto protocol;
void* protocol_data;
int fd_socket;
int fd_dev;
int remote_float;
sockaddr_any remote_addr;
int use_pi;
int poll_timeout;
void (*sendnetworkpacket)(struct qtsession* sess, char* msg, int len);
};

char* (*getconf)(const char*);
int errorexit(const char*);
int errorexitp(const char*);
void print_header();
void hex2bin(unsigned char*, const char*, const int);
int debug;
int qtrun(struct qtproto* p);
int qtprocessargs(int argc, char** argv);

#endif
2 changes: 1 addition & 1 deletion src/keypair.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
authors and should not be interpreted as representing official policies, either expressed
or implied, of Ivo Smits.*/

#include "common.c"
#include "common.h"
#include "crypto_box_curve25519xsalsa20poly1305.h"
#include "crypto_scalarmult_curve25519.h"
#include <time.h>
Expand Down
40 changes: 32 additions & 8 deletions src/run.combined.c → src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
authors and should not be interpreted as representing official policies, either expressed
or implied, of Ivo Smits.*/

#include "common.c"
#include "common.h"

extern struct qtproto qtproto_raw;
extern struct qtproto qtproto_nacl0;
Expand All @@ -43,6 +43,24 @@ char* getenvdeb(const char* name) {
}
#endif

const char *execproto(const char *path)
{
const char* last_dot;
const char* last_slash;

if (!path) return NULL;

last_dot = strrchr(path, '.');
last_slash = strrchr(path, '/');
if (last_dot && (!last_slash || last_slash < last_dot)) {
if (strcmp(last_dot + 1, "combined") == 0) {
return NULL;
}
return last_dot + 1;
}
return NULL;
}

int main(int argc, char** argv) {
print_header();
#ifdef DEBIAN_BINARY
Expand All @@ -51,15 +69,22 @@ int main(int argc, char** argv) {
getconf = getenv;
#endif
if (qtprocessargs(argc, argv) < 0) return -1;
char* envval;
if ((envval = getconf("PROTOCOL"))) {
if (strcmp(envval, "raw") == 0) {
const char* proto = execproto(argv[0]);
const char* envval = getconf("PROTOCOL");
if (proto && envval) {
fprintf(stderr, "Warning: ignoring PROTOCOL setting '%s' in favor single-protocol compatibility '%s'\n",
envval, proto);
} else if (!proto) {
proto = envval;
}
if (proto) {
if (strcmp(proto, "raw") == 0) {
return qtrun(&qtproto_raw);
} else if (strcmp(envval, "nacl0") == 0) {
} else if (strcmp(proto, "nacl0") == 0) {
return qtrun(&qtproto_nacl0);
} else if (strcmp(envval, "nacltai") == 0) {
} else if (strcmp(proto, "nacltai") == 0) {
return qtrun(&qtproto_nacltai);
} else if (strcmp(envval, "salty") == 0) {
} else if (strcmp(proto, "salty") == 0) {
return qtrun(&qtproto_salty);
} else {
return errorexit("Unknown PROTOCOL specified");
Expand All @@ -72,4 +97,3 @@ int main(int argc, char** argv) {
return qtrun(&qtproto_raw);
}
}

10 changes: 1 addition & 9 deletions src/proto.nacl0.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
authors and should not be interpreted as representing official policies, either expressed
or implied, of Ivo Smits.*/

#include "common.c"
#include "common.h"
#include "crypto_box_curve25519xsalsa20poly1305.h"

struct qt_proto_data_nacl0 {
Expand Down Expand Up @@ -95,11 +95,3 @@ struct qtproto qtproto_nacl0 = {
init,
sizeof(struct qt_proto_data_nacl0),
};

#ifndef COMBINED_BINARY
int main(int argc, char** argv) {
print_header();
if (qtprocessargs(argc, argv) < 0) return -1;
return qtrun(&qtproto_nacl0);
}
#endif
10 changes: 1 addition & 9 deletions src/proto.nacltai.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
authors and should not be interpreted as representing official policies, either expressed
or implied, of Ivo Smits.*/

#include "common.c"
#include "common.h"
#include "crypto_box_curve25519xsalsa20poly1305.h"
#include "crypto_scalarmult_curve25519.h"
#include <sys/types.h>
Expand Down Expand Up @@ -172,11 +172,3 @@ struct qtproto qtproto_nacltai = {
init,
sizeof(struct qt_proto_data_nacltai),
};

#ifndef COMBINED_BINARY
int main(int argc, char** argv) {
print_header();
if (qtprocessargs(argc, argv) < 0) return -1;
return qtrun(&qtproto_nacltai);
}
#endif
10 changes: 1 addition & 9 deletions src/proto.raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
authors and should not be interpreted as representing official policies, either expressed
or implied, of Ivo Smits.*/

#include "common.c"
#include "common.h"

static int encode(struct qtsession* sess, char* raw, char* enc, int len) {
memcpy(enc, raw, len);
Expand All @@ -46,11 +46,3 @@ struct qtproto qtproto_raw = {
NULL,
0,
};

#ifndef COMBINED_BINARY
int main(int argc, char** argv) {
print_header();
if (qtprocessargs(argc, argv) < 0) return -1;
return qtrun(&qtproto_raw);
}
#endif
10 changes: 1 addition & 9 deletions src/proto.salty.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ When receiving packet:
Write packet to tunnel
*/

#include "common.c"
#include "common.h"
#include "crypto_box_curve25519xsalsa20poly1305.h"
#include "crypto_scalarmult_curve25519.h"
#include <sys/types.h>
Expand Down Expand Up @@ -460,11 +460,3 @@ struct qtproto qtproto_salty = {
sizeof(struct qt_proto_data_salty),
idle,
};

#ifndef COMBINED_BINARY
int main(int argc, char** argv) {
print_header();
if (qtprocessargs(argc, argv) < 0) return -1;
return qtrun(&qtproto_salty);
}
#endif