Package: nstx
Version: 1.1-beta6-5
Tags: patch
Followup-For: Bug #398356

A patch is attached. Apply to source package.

It adds a "-n" option to name tun device. Init.d script uses if_tun as name.

-- System Information:
Debian Release: 5.0.1
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-2-686 (SMP w/2 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages nstx depends on:
ii  adduser                       3.110      add and remove users and groups
ii  libc6                         2.7-18     GNU C Library: Shared libraries

nstx recommends no packages.

nstx suggests no packages.

-- no debconf information
diff -aur nstx-1.1-beta6.orig/debian/changelog nstx-1.1-beta6/debian/changelog
--- nstx-1.1-beta6.orig/debian/changelog	2009-05-23 13:43:05.000000000 +0200
+++ nstx-1.1-beta6/debian/changelog	2009-05-24 00:11:54.476099823 +0200
@@ -1,3 +1,9 @@
+nstx (1.1-beta6-5.1~dmanso) unstable; urgency=low
+
+  * Add option -n to name tun devices (Closes: #398356).
+
+ -- David Manso <david.ma...@epistolae.com>  Sat, 23 May 2008 15:02:03 +0200
+
 nstx (1.1-beta6-5) unstable; urgency=low
 
   * Non-maintainer upload to solve release goal.
diff -aur nstx-1.1-beta6.orig/debian/nstx.default nstx-1.1-beta6/debian/nstx.default
--- nstx-1.1-beta6.orig/debian/nstx.default	2009-05-23 14:59:47.000000000 +0200
+++ nstx-1.1-beta6/debian/nstx.default	2009-05-24 00:13:14.776119728 +0200
@@ -18,8 +18,8 @@
 # uncomment to start nstxcd on system startup
 #start_nstxcd=yes
 
-# uncomment to bring up tun0 automatically
-#ifup_tun=tun0
+# uncomment to bring up tun-nstx automatically
+#ifup_tun=tun-nstx
 
 # uncomment to tell nstx to bind to a specific interface
 #NSTX_IFACE="1.2.3.4"
diff -aur nstx-1.1-beta6.orig/debian/nstx.nstxcd.init nstx-1.1-beta6/debian/nstx.nstxcd.init
--- nstx-1.1-beta6.orig/debian/nstx.nstxcd.init	2009-05-23 14:59:47.000000000 +0200
+++ nstx-1.1-beta6/debian/nstx.nstxcd.init	2009-05-24 00:11:54.480116582 +0200
@@ -39,8 +39,9 @@
   start)
   if check_start_nstxcd_option; then
 	echo -n "Starting $DESC: "
+        OPTIONS="${NSTX_IFACE:+-i $NSTX_IFACE} ${ifup_tun:+-n $ifup_tun} $NSTX_DOMAIN $NSTX_DNS_SERVER"
 	start-stop-daemon --start -b -m --quiet --pidfile /var/run/$NAME.pid \
-		--exec $DAEMON -- $NSTX_DOMAIN $NSTX_DNS_SERVER
+		--exec $DAEMON -- $OPTIONS
 	sleep 1;
 	if [ -n "$ifup_tun" ]; then
 	    ifup "$ifup_tun"
diff -aur nstx-1.1-beta6.orig/debian/nstx.nstxd.init nstx-1.1-beta6/debian/nstx.nstxd.init
--- nstx-1.1-beta6.orig/debian/nstx.nstxd.init	2009-05-23 14:59:47.000000000 +0200
+++ nstx-1.1-beta6/debian/nstx.nstxd.init	2009-05-24 00:11:54.480116582 +0200
@@ -38,11 +38,7 @@
   start)
   if check_start_nstxd_option; then
 	echo -n "Starting $DESC: "
-	if [ -n "$NSTX_IFACE" ]; then
-		OPTIONS="-i $NSTX_IFACE $NSTX_OPTIONS $NSTX_DOMAIN"
-	else
-		OPTIONS="$NSTX_OPTIONS $NSTX_DOMAIN"
-	fi
+	OPTIONS="${NSTX_IFACE:+-i $NSTX_IFACE} ${ifup_tun:+-n $ifup_tun} $NSTX_OPTIONS $NSTX_DOMAIN"
 	start-stop-daemon --start -b -m --quiet --pidfile /var/run/$NAME.pid \
 		--exec $DAEMON -- $OPTIONS 
 	sleep 1;
diff -aur nstx-1.1-beta6.orig/nstxcd.8 nstx-1.1-beta6/nstxcd.8
--- nstx-1.1-beta6.orig/nstxcd.8	2009-05-23 14:59:47.000000000 +0200
+++ nstx-1.1-beta6/nstxcd.8	2009-05-24 00:11:54.480116582 +0200
@@ -3,7 +3,7 @@
 nstxcd \- IP over DNS tunneling client
 
 .SH SYNOPSIS
-.B "nstxcd \fIDOMAIN\fR \fIIPADDRESS\fR"
+.B "nstxcd \fIOPTIONS\fR \fIDOMAIN\fR \fIIPADDRESS\fR"
 
 .SH DESCRIPTION
 .B nstxcd
@@ -13,6 +13,10 @@
 .SH OPTIONS
 .B nstxcd
 takes the following options:
+.IP \-d tun-device
+Use this tun device instead of /dev/net/tun
+.IP \-n tun-name
+Use this tun name instead of tun0
 .IP "domain"
 The domain that nstxcd will send requests to. This domain must be delegated
 to a machine that is running nstxd.
diff -aur nstx-1.1-beta6.orig/nstxcd.c nstx-1.1-beta6/nstxcd.c
--- nstx-1.1-beta6.orig/nstxcd.c	2009-05-23 14:59:47.000000000 +0200
+++ nstx-1.1-beta6/nstxcd.c	2009-05-24 00:11:54.480116582 +0200
@@ -55,14 +55,14 @@
 static void
 usage(const char *prog, int code)
 {
-	fprintf(stderr, "Usage: %s [-d tun-device] <domainname> <dns-server>\n"
+	fprintf(stderr, "Usage: %s [-d tun-device] [-n tun-name] <domainname> <dns-server>\n"
 	    "Example: %s tun.yomama.com 125.23.53.12\n", prog, prog);
 	exit(code);
 }
 
 int main (int argc, char * argv[]) {
   struct nstxmsg *msg;
-  const char	*device = NULL;
+  const char	*device = NULL, *name = NULL;
   int 		 ch;
 
   nsid = time(NULL);
@@ -70,11 +70,14 @@
   if (argc < 3)
 	usage(argv[0], EX_USAGE);
 
-  while ((ch = getopt(argc, argv, "hd:")) != -1) {
+  while ((ch = getopt(argc, argv, "hd:n:")) != -1) {
 	switch (ch) {
 	case 'd':
 		device = optarg;
 		break;
+	case 'n':
+		name = optarg;
+		break;
 	case 'h':
 		usage(argv[0], 0);
 	default:
@@ -85,7 +88,7 @@
   dns_setsuffix(argv[optind]);
 
   qsettimeout(10);
-  open_tuntap(device);
+  open_tuntap(device, name);
   open_ns(argv[optind + 1]);
 
   for (;;) {
diff -aur nstx-1.1-beta6.orig/nstxd.8 nstx-1.1-beta6/nstxd.8
--- nstx-1.1-beta6.orig/nstxd.8	2009-05-23 14:59:47.000000000 +0200
+++ nstx-1.1-beta6/nstxd.8	2009-05-24 00:11:54.480116582 +0200
@@ -15,7 +15,9 @@
 .B nstxd
 takes the following option:
 .IP \-d tun-device
-Use this tun device instead of tun0
+Use this tun device instead of /dev/net/tun
+.IP \-n tun-name
+Use this tun name instead of tun0
 .IP \-i ipaddr
 Bind to this IP address rather than every available address
 .IP \-C dir
diff -aur nstx-1.1-beta6.orig/nstxd.c nstx-1.1-beta6/nstxd.c
--- nstx-1.1-beta6.orig/nstxd.c	2009-05-23 14:59:47.000000000 +0200
+++ nstx-1.1-beta6/nstxd.c	2009-05-24 00:11:54.484098001 +0200
@@ -55,7 +55,8 @@
 {
 	fprintf (stderr, "usage: %s [options] <domainname>\n"
 	    "Where options are:\n"
-	    "\t-d tun-device (use this tun/tap device instead of default\n"
+	    "\t-d tun-device (use this tun/tap device instead of default)\n"
+	    "\t-n tun-name (use this tun/tap name instead of default)\n"
 	    "\t-i ip.to.bi.nd (bind to port 53 on this IP only)\n"
 	    "\t-C dir (chroot() to this directory after initialization)\n"
 	    "\t-D (call daemon(3) to detach from terminal)\n"
@@ -68,13 +69,13 @@
 
 int main (int argc, char *argv[]) {
    signed char	 ch;
-   const char	*device = NULL, *dir = NULL;
+   const char	*device = NULL, *name = NULL, *dir = NULL;
    in_addr_t	 bindto = INADDR_ANY;
    uid_t	 uid = 0;
    int		 daemonize = 0;
    int		 logmask = LOG_UPTO(LOG_INFO);
    
-   while ((ch = getopt(argc, argv, "gDC:u:hd:i:")) != -1) {
+   while ((ch = getopt(argc, argv, "gDC:u:hd:n:i:")) != -1) {
 	switch(ch) {
 	case 'i':
 		bindto = inet_addr(optarg);
@@ -87,6 +88,9 @@
 	case 'd':
 		device = optarg;
 		break;
+	case 'n':
+		name = optarg;
+		break;
 	case 'D':
 		daemonize = 1;
 		break;
@@ -121,7 +125,7 @@
 
    dns_setsuffix(argv[optind]);
    
-   open_tuntap(device);
+   open_tuntap(device, name);
    open_ns_bind(bindto);
    
    if (dir) {
diff -aur nstx-1.1-beta6.orig/nstxfun.h nstx-1.1-beta6/nstxfun.h
--- nstx-1.1-beta6.orig/nstxfun.h	2004-06-27 23:43:34.000000000 +0200
+++ nstx-1.1-beta6/nstxfun.h	2009-05-24 00:11:54.484098001 +0200
@@ -52,7 +52,7 @@
 
 /* DNS */
 
-void open_tuntap (const char *device);
+void open_tuntap (const char *device, const char *name);
 void open_ns (const char *ip);
 void open_ns_bind(in_addr_t ip);
 
diff -aur nstx-1.1-beta6.orig/nstx_tuntap.c nstx-1.1-beta6/nstx_tuntap.c
--- nstx-1.1-beta6.orig/nstx_tuntap.c	2009-05-23 14:59:47.000000000 +0200
+++ nstx-1.1-beta6/nstx_tuntap.c	2009-05-24 00:11:54.484098001 +0200
@@ -44,7 +44,7 @@
 #endif
 
 void
-open_tuntap(const char *device)
+open_tuntap(const char *device, const char *name)
 {
    int	tunerr;
 #ifdef linux
@@ -52,6 +52,8 @@
 #endif
    
    fprintf(stderr, "Opening tun/tap-device... ");
+   if (name)
+     strncpy(dev, name, IFNAMSIZ);
    if ((tunerr = tun_alloc(device ? device : TUNDEV))
 #ifdef linux
 	&& (taperr = tap_alloc(device ? device : TAPDEV))
@@ -120,7 +122,10 @@
    memset(&ifr, 0, sizeof(ifr));
    
    ifr.ifr_flags = IFF_TUN|IFF_NO_PI;
-   
+
+   if (*dev)
+     strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+ 
    if (ioctl(tfd, TUNSETIFF, (void *) &ifr) < 0)
      {
 	close(tfd);

Reply via email to