Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 262765 | Differences between
and this patch

Collapse All | Expand All

(-)nstx-1.1-beta6.orig/nstx_tuntap.c (-91 / +101 lines)
Lines 19-31 Link Here
19
19
20
#ifdef linux
20
#ifdef linux
21
#include <linux/if_tun.h>
21
#include <linux/if_tun.h>
22
#define TUNDEV "/dev/net/tun"
22
#define TUNINT "tun0"
23
#define TUNDEVNODE "/dev/net/tun"
23
#else
24
#else
24
#	include <net/if_tun.h>
25
#	include <net/if_tun.h>
26
#	define TUNINT "NULL?"
25
#	if __FreeBSD_version < 500000
27
#	if __FreeBSD_version < 500000
26
#		define TUNDEV "/dev/tun2"
28
#		define TUNDEVNODE "/dev/tun2"
27
#	else
29
#	else
28
#		define TUNDEV "/dev/tun"
30
#		define TUNDEVNODE "/dev/tun"
29
#	endif
31
#	endif
30
#endif
32
#endif
31
33
Lines 33-159 Link Here
33
35
34
#define MAXPKT 2000
36
#define MAXPKT 2000
35
37
36
#define TAPDEV "/dev/tap0"
38
#define TAPINT "tap0"
39
#define TAPDEVNODE "/dev/net/tun"
37
40
38
int tfd = -1, nfd = -1;
41
int tfd = -1, nfd = -1;
39
static char dev[IFNAMSIZ+1];
42
static char dev[IFNAMSIZ+1];
40
43
41
static int tun_alloc (const char *path);
44
static int tun_alloc (const char * interface, const char * device_node);
45
static int tap_alloc (const char * interface, const char * device_node);
46
42
#ifdef linux
47
#ifdef linux
43
static int tap_alloc (const char *path);
48
static int tuntap_alloc_linux(const char * interface, const char * device_node,
49
        int mode);
50
#else
51
static int tun_alloc_bsd(const char * interface, const char * device_node);
44
#endif
52
#endif
45
53
46
void
54
void
47
open_tuntap(const char *device)
55
open_tuntap(const char * interface, const char * device_node, int tun)
48
{
56
{
49
   int	tunerr;
57
   int err;
50
#ifdef linux
58
51
   int	taperr;
59
   if (!interface)
52
#endif
60
       interface = (tun ? TUNINT : TAPINT);
61
62
   if (!device_node)
63
       device_node = (tun ? TUNDEVNODE : TAPDEVNODE);
64
65
   fprintf(stderr, "Opening %s interface %s at %s... ", tun ? "tun" : "tap",
66
           interface, device_node);
67
68
   err = (tun ? tun_alloc(interface, device_node) : tap_alloc(interface,
69
               device_node));
70
71
   if (!err) {
72
       fprintf(stderr, "using interface %s\n", dev);
73
74
       if (tun)
75
           fprintf(stderr, "you will now need to assign an ip and routing to "
76
                   "this interface\n");
77
       else
78
           fprintf(stderr, "you will now need to add bridging or other rules "
79
                   "to this interface\n");
80
       return;
81
   }
53
   
82
   
54
   fprintf(stderr, "Opening tun/tap-device... ");
83
   fprintf(stderr, "failed! (%s)\n", strerror(err));
55
   if ((tunerr = tun_alloc(device ? device : TUNDEV))
84
85
   fprintf(stderr, "Diagnostics: ");
86
87
   if (err == EPERM)
88
       fprintf(stderr, "you usually have to be root to use nstx.\n");
89
   else if (err == ENOENT)
90
       fprintf(stderr, "maybe you need kernel support -- did you modprobe "
91
               "tap?\n");
92
   else if (err == ENODEV)
93
       fprintf(stderr, "maybe you need kernel support -- did you modprobe "
94
               "tap?\n");
56
#ifdef linux
95
#ifdef linux
57
	&& (taperr = tap_alloc(device ? device : TAPDEV))
96
#else
97
   else if ((err == EINVAL) && !tun)
98
       fprintf(stderr, "tap support is only available under linux\n");
58
#endif
99
#endif
59
   ) {
100
   else
60
      fprintf(stderr, "failed!\n"
101
       fprintf(stderr, "none, sorry\n");
61
	              "Diagnostics:\nTun ("TUNDEV"): ");
102
62
      switch (tunerr) {
103
   exit(EXIT_FAILURE);
63
       case EPERM:
104
}
64
	 fprintf(stderr, "Permission denied. You usually have to "
105
65
		         "be root to use nstx.\n");
106
int tun_alloc(const char * interface, const char * device_node) 
66
	 break;
107
{
67
       case ENOENT:
68
	 fprintf(stderr, TUNDEV " not found. Please create /dev/net/ and\n"
69
		 "     mknod /dev/net/tun c 10 200 to use the tun-device\n");
70
	 break;
71
       case ENODEV:
72
	 fprintf(stderr, "Device not available. Make sure you have "
73
		 "kernel-support\n     for the tun-device. Under linux, you "
74
		 "need tun.o (Universal tun/tap-device)\n");
75
	 break;
76
       default:
77
	 perror("Unexpected error");
78
	 break;
79
      }
80
      fprintf(stderr, "Tap ("TAPDEV"):\n(only available under linux)\n");
81
#ifdef linux
108
#ifdef linux
82
      switch (taperr) {
109
    return tuntap_alloc_linux(interface, device_node, IFF_TUN);
83
       case EPERM:
110
#else
84
	 fprintf(stderr, "Permission denied. You generally have to "
111
    return tun_alloc_bsd(interface, device_node);
85
		 "be root to use nstx.\n");
86
	 break;
87
       case ENOENT:
88
	 fprintf(stderr, TAPDEV " not found. Please\n"
89
		 "     mknod /dev/tap0 c 36 16 to use the tap-device\n");
90
	 break;
91
       case ENODEV:
92
	 fprintf(stderr, "Device not available. Make sure you have kernel-support\n"
93
		 "     for the tap-device. Under linux, you need netlink_dev.o and ethertap.o\n");
94
	 break;
95
       default:
96
	 fprintf(stderr, "Unexpected error: %s\n", strerror(taperr));
97
	 break;
98
      }
99
#endif
112
#endif
100
      exit(EXIT_FAILURE);
101
   }
102
   
103
   fprintf(stderr, "using device %s\n"
104
	  "Please configure this device appropriately (IP, routes, etc.)\n", dev);
105
}
113
}
106
114
107
int
115
int tap_alloc(const char * interface, const char * device_node) 
108
tun_alloc (const char *path) 
109
{
116
{
110
#ifdef linux
117
#ifdef linux
111
   struct ifreq ifr;
118
    return tuntap_alloc_linux(interface, device_node, IFF_TAP);
112
#else
119
#else
113
   struct stat st;
120
    return EINVAL;
114
#endif
121
#endif
115
 
122
}
116
   if ((tfd = open(path, O_RDWR)) < 0)
117
     return errno;
118
123
119
#ifdef linux
124
#ifdef linux
120
   memset(&ifr, 0, sizeof(ifr));
125
126
int tuntap_alloc_linux(const char * interface, const char * device_node,
127
        int mode)
128
{
129
    struct ifreq ifr;
130
131
    if ((tfd = open(device_node, O_RDWR)) < 0)
132
        return errno;
133
134
    memset(&ifr, 0, sizeof(ifr));
121
   
135
   
122
   ifr.ifr_flags = IFF_TUN|IFF_NO_PI;
136
    ifr.ifr_flags = mode | IFF_NO_PI;
137
    strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
138
    ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = 0;
123
   
139
   
124
   if (ioctl(tfd, TUNSETIFF, (void *) &ifr) < 0)
140
    if (ioctl(tfd, TUNSETIFF, (void *) &ifr) < 0) {
125
     {
141
        close(tfd);
126
	close(tfd);
142
        tfd = -1;
127
	tfd = -1;
143
        return errno;
128
	return errno;
144
    }
129
     }
145
130
   strncpy(dev, ifr.ifr_name, IFNAMSIZ+1);
146
    strncpy(dev, ifr.ifr_name, IFNAMSIZ+1);
131
#else
132
   fstat(tfd, &st);
133
   strncpy(dev, devname(st.st_rdev, S_IFCHR), IFNAMSIZ+1);
134
#endif
135
   
147
   
136
   return 0;
148
    return 0;
137
}
149
}
138
150
151
#else /* bsd */
139
152
140
#ifdef linux
153
int tun_alloc_bsd(const char * interface, const char * device_node)
141
int
142
tap_alloc(const char *path)
143
{
154
{
144
   char *ptr;
155
   struct stat st;
145
   
156
146
   if ((tfd = open(path, O_RDWR)) < 0)
157
   if ((tfd = open(device_node, O_RDWR)) < 0)
147
     return errno;
158
     return errno;
148
   
159
149
   if ((ptr = strrchr(path, '/')))
160
   fstat(tfd, &st);
150
     strncpy(dev, ptr+1, IFNAMSIZ+1);
161
   strncpy(dev, devname(st.st_rdev, S_IFCHR), IFNAMSIZ+1);
151
   else
152
     strncpy(dev, path, IFNAMSIZ+1);
153
   
162
   
154
   return 0;
163
   return 0;
155
}
164
}
156
#endif
165
166
#endif /* linux/bsd */
157
167
158
void
168
void
159
open_ns(const char *ip)
169
open_ns(const char *ip)
(-)nstx-1.1-beta6.orig/nstxcd.8 (-4 / +12 lines)
Lines 3-9 Link Here
3
nstxcd \- IP over DNS tunneling client
3
nstxcd \- IP over DNS tunneling client
4
4
5
.SH SYNOPSIS
5
.SH SYNOPSIS
6
.B "nstxcd \fIDOMAIN\fR \fIIPADDRESS\fR"
6
.B "nstxcd \fIOPTIONS\fR \fIDOMAIN\fR \fIIPADDRESS\fR"
7
7
8
.SH DESCRIPTION
8
.SH DESCRIPTION
9
.B nstxcd
9
.B nstxcd
Lines 13-18 Link Here
13
.SH OPTIONS
13
.SH OPTIONS
14
.B nstxcd
14
.B nstxcd
15
takes the following options:
15
takes the following options:
16
.IP \-I tun/tap interface
17
Use this tun/tap interface instead of the default (tun0/tap0)
18
.IP \-d tun/tap device node
19
Use this tun/tap device node instead of the default (/dev/net/tun on Linux)
20
.IP \-t
21
Tun mode (default)
22
.IP \-T
23
Tap mode
16
.IP "domain"
24
.IP "domain"
17
The domain that nstxcd will send requests to. This domain must be delegated
25
The domain that nstxcd will send requests to. This domain must be delegated
18
to a machine that is running nstxd.
26
to a machine that is running nstxd.
Lines 22-30 Link Here
22
.SH USAGE
30
.SH USAGE
23
.Bnstxcd
31
.Bnstxcd
24
should be run against a domain that has been delegated to a machine running
32
should be run against a domain that has been delegated to a machine running
25
nstxd. It will then take any packets that are sent to the tun0 interface and
33
nstxd. It will then take any packets that are sent to the tun/tap interface and
26
send them over DNS to the other tunnel endpoint. Responses will appear on 
34
send them over DNS to the other tunnel endpoint. Responses will appear on the
27
the tun0 interface.
35
tun/tap interface.
28
36
29
.SH AUTHORS
37
.SH AUTHORS
30
38
(-)nstx-1.1-beta6.orig/nstxcd.c (-6 / +25 lines)
Lines 55-79 Link Here
55
static void
55
static void
56
usage(const char *prog, int code)
56
usage(const char *prog, int code)
57
{
57
{
58
	fprintf(stderr, "Usage: %s [-d tun-device] <domainname> <dns-server>\n"
58
	fprintf(stderr, "Usage: %s [options] <domainname> <dns-server>\n"
59
	    "Example: %s tun.yomama.com 125.23.53.12\n", prog, prog);
59
	    "Where options are:\n"
60
	    "\t-d path (use this tun/tap device node instead of default)\n"
61
	    "\t-I interface (use this tun/tap interface instead of default)\n"
62
#ifdef linux
63
	    "\t-t (tun mode, default)\n"
64
	    "\t-T (tap mode)\n"
65
#endif
66
	    "example:\n"
67
	    "%s tun.yomama.com 125.23.53.12\n", prog, prog);
60
	exit(code);
68
	exit(code);
61
}
69
}
62
70
63
int main (int argc, char * argv[]) {
71
int main (int argc, char * argv[]) {
64
  struct nstxmsg *msg;
72
  struct nstxmsg *msg;
65
  const char	*device = NULL;
73
  const char	*interface = NULL;
74
  const char	*device_node = NULL;
66
  int 		 ch;
75
  int 		 ch;
76
  int tun = 1;
67
77
68
  nsid = time(NULL);
78
  nsid = time(NULL);
69
 
79
 
70
  if (argc < 3)
80
  if (argc < 3)
71
	usage(argv[0], EX_USAGE);
81
	usage(argv[0], EX_USAGE);
72
82
73
  while ((ch = getopt(argc, argv, "hd:")) != -1) {
83
  while ((ch = getopt(argc, argv, "hd:I:tT")) != -1) {
74
	switch (ch) {
84
	switch (ch) {
85
	case 'I':
86
		interface = optarg;
87
		break;
75
	case 'd':
88
	case 'd':
76
		device = optarg;
89
		device_node = optarg;
90
		break;
91
	case 't':
92
        tun = 1;
93
		break;
94
	case 'T':
95
        tun = 0;
77
		break;
96
		break;
78
	case 'h':
97
	case 'h':
79
		usage(argv[0], 0);
98
		usage(argv[0], 0);
Lines 85-91 Link Here
85
  dns_setsuffix(argv[optind]);
104
  dns_setsuffix(argv[optind]);
86
105
87
  qsettimeout(10);
106
  qsettimeout(10);
88
  open_tuntap(device);
107
  open_tuntap(interface, device_node, tun);
89
  open_ns(argv[optind + 1]);
108
  open_ns(argv[optind + 1]);
90
109
91
  for (;;) {
110
  for (;;) {
(-)nstx-1.1-beta6.orig/nstxd.8 (-6 / +12 lines)
Lines 3-9 Link Here
3
nstxd \- IP over DNS tunneling daemon
3
nstxd \- IP over DNS tunneling daemon
4
4
5
.SH SYNOPSIS
5
.SH SYNOPSIS
6
.B "nstxd \fIOPTION\fR \fIDOMAIN\fR"
6
.B "nstxd \fIOPTIONS\fR \fIDOMAIN\fR"
7
7
8
.SH DESCRIPTION
8
.SH DESCRIPTION
9
.B nstxd
9
.B nstxd
Lines 14-21 Link Here
14
.SH OPTIONS
14
.SH OPTIONS
15
.B nstxd
15
.B nstxd
16
takes the following option:
16
takes the following option:
17
.IP \-d tun-device
17
.IP \-I tun/tap interface
18
Use this tun device instead of tun0
18
Use this tun/tap interface instead of the default (tun0/tap0)
19
.IP \-d tun/tap device node
20
Use this tun/tap device node instead of the default (/dev/net/tun on linux)
21
.IP \-t
22
Tun mode (default)
23
.IP \-T
24
Tap mode
19
.IP \-i ipaddr
25
.IP \-i ipaddr
20
Bind to this IP address rather than every available address
26
Bind to this IP address rather than every available address
21
.IP \-C dir
27
.IP \-C dir
Lines 33-41 Link Here
33
.SH USAGE
39
.SH USAGE
34
A domain should be delegated to the machine that will run nstxd. nstxd should
40
A domain should be delegated to the machine that will run nstxd. nstxd should
35
then be run giving that domain as the only argument. nstxd will then listen
41
then be run giving that domain as the only argument. nstxd will then listen
36
for requests and translate them into IP packets that will appear on the tun0
42
for requests and translate them into IP packets that will appear on the given
37
interface. Packets sent to the tun0 interface will be transferred back to
43
tun/tap interface. Packets sent to the tun/tap interface will be transferred
38
the client as DNS answers.
44
back to the client as DNS answers.
39
45
40
.SH AUTHORS
46
.SH AUTHORS
41
47
(-)nstx-1.1-beta6.orig/nstxd.c (-5 / +21 lines)
Lines 55-61 Link Here
55
{
55
{
56
	fprintf (stderr, "usage: %s [options] <domainname>\n"
56
	fprintf (stderr, "usage: %s [options] <domainname>\n"
57
	    "Where options are:\n"
57
	    "Where options are:\n"
58
	    "\t-d tun-device (use this tun/tap device instead of default\n"
58
	    "\t-d path (use this tun/tap device node instead of default)\n"
59
	    "\t-I interface (use this tun/tap interface instead of default)\n"
60
#ifdef linux
61
	    "\t-t (tun mode, default)\n"
62
	    "\t-T (tap mode)\n"
63
#endif
59
	    "\t-i ip.to.bi.nd (bind to port 53 on this IP only)\n"
64
	    "\t-i ip.to.bi.nd (bind to port 53 on this IP only)\n"
60
	    "\t-C dir (chroot() to this directory after initialization)\n"
65
	    "\t-C dir (chroot() to this directory after initialization)\n"
61
	    "\t-D (call daemon(3) to detach from terminal)\n"
66
	    "\t-D (call daemon(3) to detach from terminal)\n"
Lines 68-80 Link Here
68
73
69
int main (int argc, char *argv[]) {
74
int main (int argc, char *argv[]) {
70
   signed char	 ch;
75
   signed char	 ch;
71
   const char	*device = NULL, *dir = NULL;
76
   const char	*interface = NULL, *dir = NULL;
77
   const char	*device_node = NULL;
72
   in_addr_t	 bindto = INADDR_ANY;
78
   in_addr_t	 bindto = INADDR_ANY;
73
   uid_t	 uid = 0;
79
   uid_t	 uid = 0;
74
   int		 daemonize = 0;
80
   int		 daemonize = 0;
75
   int		 logmask = LOG_UPTO(LOG_INFO);
81
   int		 logmask = LOG_UPTO(LOG_INFO);
82
   int tun = 1;
76
   
83
   
77
   while ((ch = getopt(argc, argv, "gDC:u:hd:i:")) != -1) {
84
   while ((ch = getopt(argc, argv, "gDC:u:hd:I:i:tT")) != -1) {
78
	switch(ch) {
85
	switch(ch) {
79
	case 'i':
86
	case 'i':
80
		bindto = inet_addr(optarg);
87
		bindto = inet_addr(optarg);
Lines 84-91 Link Here
84
			exit(EX_USAGE);
91
			exit(EX_USAGE);
85
		}
92
		}
86
		break;
93
		break;
94
	case 'I':
95
		interface = optarg;
96
		break;
87
	case 'd':
97
	case 'd':
88
		device = optarg;
98
		device_node = optarg;
99
		break;
100
	case 't':
101
        tun = 1;
102
		break;
103
	case 'T':
104
        tun = 0;
89
		break;
105
		break;
90
	case 'D':
106
	case 'D':
91
		daemonize = 1;
107
		daemonize = 1;
Lines 121-127 Link Here
121
137
122
   dns_setsuffix(argv[optind]);
138
   dns_setsuffix(argv[optind]);
123
   
139
   
124
   open_tuntap(device);
140
   open_tuntap(interface, device_node, tun);
125
   open_ns_bind(bindto);
141
   open_ns_bind(bindto);
126
   
142
   
127
   if (dir) {
143
   if (dir) {
(-)nstx-1.1-beta6.orig/nstxfun.h (-1 / +1 lines)
Lines 52-58 Link Here
52
52
53
/* DNS */
53
/* DNS */
54
54
55
void open_tuntap (const char *device);
55
void open_tuntap (const char * interface, const char * device_node, int tun);
56
void open_ns (const char *ip);
56
void open_ns (const char *ip);
57
void open_ns_bind(in_addr_t ip);
57
void open_ns_bind(in_addr_t ip);
58
58

Return to bug 262765