Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HevIFwd: Add support for iptables forwarding #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
28 changes: 27 additions & 1 deletion src/hev-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
Expand All @@ -17,6 +18,7 @@
#include "hev-conf.h"

static int mode = SOCK_STREAM;
static int method = HEV_FWD_DEFAULT;
static int type = AF_UNSPEC;
static int keep;
static int dmon;
Expand All @@ -35,6 +37,18 @@ static const char *taddr;
static const char *tport;
static const char *iface;

static int
to_method(char *m)
{
if (strcmp(m, "default") == 0) {
return HEV_FWD_DEFAULT;
}
if (strcmp(m, "iptables") == 0) {
return HEV_FWD_IPTABLES;
}
return HEV_FWD_UNKNOWN;
}

const char *
hev_conf_help (void)
{
Expand All @@ -49,6 +63,7 @@ hev_conf_help (void)
" -d run as daemon\n"
" -i <interface> network interface\n"
" -k <interval> seconds between each keep-alive\n"
" -m <method> forward method\n"
" -s <addr>[:port] domain name or address to STUN server\n"
" -h <addr>[:port] domain name or address to HTTP server\n"
" -e <path> script path for notify mapped address\n"
Expand All @@ -69,7 +84,7 @@ hev_conf_init (int argc, char *argv[])
{
int opt;

while ((opt = getopt (argc, argv, "46udk:s:h:e:b:T:t:p:i:")) != -1) {
while ((opt = getopt (argc, argv, "46udk:m:s:h:e:b:T:t:p:i:")) != -1) {
switch (opt) {
case '4':
type = AF_INET;
Expand All @@ -86,6 +101,11 @@ hev_conf_init (int argc, char *argv[])
case 'k':
keep = strtoul (optarg, NULL, 10) * 1000;
break;
case 'm':
method = to_method(optarg);
if (method == HEV_FWD_UNKNOWN)
return -1;
break;
case 's':
sscanf (optarg, "%255[^:]:%5[0123456789]", stun, sport);
break;
Expand Down Expand Up @@ -243,3 +263,9 @@ hev_conf_hport (void)
{
return hport;
}

int
hev_conf_method (void)
{
return method;
}
24 changes: 24 additions & 0 deletions src/hev-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
#ifndef __HEV_CONF_H__
#define __HEV_CONF_H__

/**
* HevFwdMethod:
* @HEV_FWD_UNKNOWN: Unknown forward method.
* @HEV_FWD_DEFAULT: Default forward method.
* @HEV_FWD_IPTABLES: Forward using iptables.
*
* Since: 1.0
*/
typedef enum
{
HEV_FWD_UNKNOWN,
HEV_FWD_DEFAULT,
HEV_FWD_IPTABLES
} HevFwdMethod;

/**
* hev_conf_help:
*
Expand Down Expand Up @@ -175,4 +190,13 @@ const char *hev_conf_sport (void);
*/
const char *hev_conf_hport (void);

/**
* hev_conf_method:
*
* Get forward method.
*
* Returns: returns integer number.
*/
int hev_conf_method (void);

#endif /* __HEV_CONF_H__ */
6 changes: 3 additions & 3 deletions src/hev-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

#include "hev-exec.h"

static void
signal_handler (int signum)
void
hev_exec_signal_handler (int signum)
{
waitpid (-1, NULL, WNOHANG);
}
Expand All @@ -43,7 +43,7 @@ hev_exec_run (int family, unsigned int maddr[4], unsigned short mport,
pid_t pid;

path = hev_conf_path ();
signal (SIGCHLD, signal_handler);
signal (SIGCHLD, hev_exec_signal_handler);

q = (unsigned char *)maddr;
p = (unsigned char *)&mport;
Expand Down
8 changes: 8 additions & 0 deletions src/hev-exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
#ifndef __HEV_EXEC_H__
#define __HEV_EXEC_H__

/**
* hev_exec_signal_handler:
* @signum: signal number
*
* Handler of SIGCHLD signal.
*/
void hev_exec_signal_handler (int signum);

/**
* hev_exec_run:
* @family: network family
Expand Down
Loading