Skip to content

Commit

Permalink
Make usage() as noreturn, move exit flag to vpn.h
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed Jul 25, 2019
1 parent 9fdcee3 commit b6ee5f0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
2 changes: 2 additions & 0 deletions include/vpn.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@
#define endian_swap64(x) (x)
#endif

extern volatile sig_atomic_t exit_signal_received;

#endif
90 changes: 44 additions & 46 deletions src/os.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "os.h"
#include "vpn.h"

extern volatile sig_atomic_t exit_signal_received;

ssize_t safe_read(const int fd, void *const buf_, size_t count, const int timeout)
{
struct pollfd pfd;
Expand Down Expand Up @@ -440,58 +438,58 @@ Cmds firewall_rules_cmds(int is_server)
{
if (is_server) {
#ifdef __linux__
static const char *set_cmds
[] = { "sysctl net.ipv4.ip_forward=1",
"ip addr add $LOCAL_TUN_IP peer $REMOTE_TUN_IP dev $IF_NAME",
"ip -6 addr add $LOCAL_TUN_IP6 peer $REMOTE_TUN_IP6/96 dev $IF_NAME",
"ip link set dev $IF_NAME up",
"iptables -t nat -A POSTROUTING -o $EXT_IF_NAME -s $REMOTE_TUN_IP -j MASQUERADE",
"iptables -t filter -A FORWARD -i $EXT_IF_NAME -o $IF_NAME -m state --state "
"RELATED,ESTABLISHED -j ACCEPT",
"iptables -t filter -A FORWARD -i $IF_NAME -o $EXT_IF_NAME -j ACCEPT",
NULL },
*unset_cmds[] = {
"iptables -t nat -D POSTROUTING -o $EXT_IF_NAME -s $REMOTE_TUN_IP -j MASQUERADE",
"iptables -t filter -D FORWARD -i $EXT_IF_NAME -o $IF_NAME -m state --state "
"RELATED,ESTABLISHED -j ACCEPT",
"iptables -t filter -D FORWARD -i $IF_NAME -o $EXT_IF_NAME -j ACCEPT", NULL
};
static const char
*set_cmds[] =
{ "sysctl net.ipv4.ip_forward=1",
"ip addr add $LOCAL_TUN_IP peer $REMOTE_TUN_IP dev $IF_NAME",
"ip -6 addr add $LOCAL_TUN_IP6 peer $REMOTE_TUN_IP6/96 dev $IF_NAME",
"ip link set dev $IF_NAME up",
"iptables -t nat -A POSTROUTING -o $EXT_IF_NAME -s $REMOTE_TUN_IP -j MASQUERADE",
"iptables -t filter -A FORWARD -i $EXT_IF_NAME -o $IF_NAME -m state --state "
"RELATED,ESTABLISHED -j ACCEPT",
"iptables -t filter -A FORWARD -i $IF_NAME -o $EXT_IF_NAME -j ACCEPT",
NULL },
*unset_cmds[] = {
"iptables -t nat -D POSTROUTING -o $EXT_IF_NAME -s $REMOTE_TUN_IP -j MASQUERADE",
"iptables -t filter -D FORWARD -i $EXT_IF_NAME -o $IF_NAME -m state --state "
"RELATED,ESTABLISHED -j ACCEPT",
"iptables -t filter -D FORWARD -i $IF_NAME -o $EXT_IF_NAME -j ACCEPT", NULL
};
#elif defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__)
static const char *set_cmds
[] = { "sysctl -w net.inet.ip.forwarding=1",
"ifconfig $IF_NAME $LOCAL_TUN_IP $REMOTE_TUN_IP up",
"ifconfig $IF_NAME inet6 $LOCAL_TUN_IP6 $REMOTE_TUN_IP6 prefixlen 128 up",
NULL },
*unset_cmds[] = { NULL, NULL };
static const char *set_cmds[] =
{ "sysctl -w net.inet.ip.forwarding=1",
"ifconfig $IF_NAME $LOCAL_TUN_IP $REMOTE_TUN_IP up",
"ifconfig $IF_NAME inet6 $LOCAL_TUN_IP6 $REMOTE_TUN_IP6 prefixlen 128 up", NULL },
*unset_cmds[] = { NULL, NULL };
#else
static const char *const *set_cmds = NULL, *const *unset_cmds = NULL;
#endif
return (Cmds){ set_cmds, unset_cmds };
} else {
#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__)
static const char *set_cmds
[] = { "ifconfig $IF_NAME $LOCAL_TUN_IP $REMOTE_TUN_IP up",
"ifconfig $IF_NAME inet6 $LOCAL_TUN_IP6 $REMOTE_TUN_IP6 prefixlen 128 up",
"route add $EXT_IP $EXT_GW_IP",
"route add 0/1 $REMOTE_TUN_IP",
"route add 128/1 $REMOTE_TUN_IP",
"route add -inet6 -blackhole 0000::/1 $REMOTE_TUN_IP6",
"route add -inet6 -blackhole 8000::/1 $REMOTE_TUN_IP6",
NULL },
*unset_cmds[] = { "route delete $EXT_IP $EXT_GW_IP", NULL };
static const char *set_cmds[] =
{ "ifconfig $IF_NAME $LOCAL_TUN_IP $REMOTE_TUN_IP up",
"ifconfig $IF_NAME inet6 $LOCAL_TUN_IP6 $REMOTE_TUN_IP6 prefixlen 128 up",
"route add $EXT_IP $EXT_GW_IP",
"route add 0/1 $REMOTE_TUN_IP",
"route add 128/1 $REMOTE_TUN_IP",
"route add -inet6 -blackhole 0000::/1 $REMOTE_TUN_IP6",
"route add -inet6 -blackhole 8000::/1 $REMOTE_TUN_IP6",
NULL },
*unset_cmds[] = { "route delete $EXT_IP $EXT_GW_IP", NULL };
#elif defined(__linux__)
static const char
*set_cmds[] = { "sysctl net.ipv4.tcp_congestion_control=bbr",
"ip link set dev $IF_NAME up",
"ip addr add $LOCAL_TUN_IP peer $REMOTE_TUN_IP dev $IF_NAME",
"ip -6 addr add $LOCAL_TUN_IP6 peer $REMOTE_TUN_IP6/96 dev $IF_NAME",
"ip route add $EXT_IP via $EXT_GW_IP",
"ip route add 0/1 via $REMOTE_TUN_IP",
"ip route add 128/1 via $REMOTE_TUN_IP",
"ip -6 route add 0000::/1 via $REMOTE_TUN_IP6",
"ip -6 route add 8000::/1 via $REMOTE_TUN_IP6",
NULL },
*unset_cmds[] = { "ip route del $EXT_IP via $EXT_GW_IP", NULL };
static const char *set_cmds[] =
{ "sysctl net.ipv4.tcp_congestion_control=bbr",
"ip link set dev $IF_NAME up",
"ip addr add $LOCAL_TUN_IP peer $REMOTE_TUN_IP dev $IF_NAME",
"ip -6 addr add $LOCAL_TUN_IP6 peer $REMOTE_TUN_IP6/96 dev $IF_NAME",
"ip route add $EXT_IP via $EXT_GW_IP",
"ip route add 0/1 via $REMOTE_TUN_IP",
"ip route add 128/1 via $REMOTE_TUN_IP",
"ip -6 route add 0000::/1 via $REMOTE_TUN_IP6",
"ip -6 route add 8000::/1 via $REMOTE_TUN_IP6",
NULL },
*unset_cmds[] = { "ip route del $EXT_IP via $EXT_GW_IP", NULL };
#else
static const char *const *set_cmds = NULL, *const *unset_cmds = NULL;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/vpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ static int load_key_file(Context *context, const char *file)
return close(fd);
}

static void usage(void)
__attribute__((noreturn)) static void usage(void)
{
puts("DSVPN " VERSION_STRING
" usage:\n"
Expand Down

0 comments on commit b6ee5f0

Please sign in to comment.