]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/commitdiff
added tunctl (tool for setup local tun/tap devices)
authorarne_f <arne_f@ea5c0bd1-69bd-2848-81d8-4f18e57aeed8>
Mon, 17 Mar 2008 18:45:06 +0000 (18:45 +0000)
committerarne_f <arne_f@ea5c0bd1-69bd-2848-81d8-4f18e57aeed8>
Mon, 17 Mar 2008 18:45:06 +0000 (18:45 +0000)
started core11

git-svn-id: http://svn.ipfire.org/svn/ipfire/branches/2.1/trunk@1276 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8

config/rootfiles/cdrom_corever
config/rootfiles/common/tunctl [new file with mode: 0644]
config/rootfiles/core/11/files [new file with mode: 0644]
config/rootfiles/core/11/meta [new file with mode: 0644]
config/rootfiles/core/11/update.sh [new file with mode: 0644]
doc/packages-list.txt
lfs/tunctl [new file with mode: 0644]
make.sh
src/tunctl/tunctl.c [new file with mode: 0755]

index ec635144f60048986bc560c5576355344005e6e7..f599e28b8ab0d8c9c57a486c89c4a5132dcbd3b2 100644 (file)
@@ -1 +1 @@
-9
+10
diff --git a/config/rootfiles/common/tunctl b/config/rootfiles/common/tunctl
new file mode 100644 (file)
index 0000000..f05749c
--- /dev/null
@@ -0,0 +1 @@
+usr/bin/tunctl
diff --git a/config/rootfiles/core/11/files b/config/rootfiles/core/11/files
new file mode 100644 (file)
index 0000000..f05749c
--- /dev/null
@@ -0,0 +1 @@
+usr/bin/tunctl
diff --git a/config/rootfiles/core/11/meta b/config/rootfiles/core/11/meta
new file mode 100644 (file)
index 0000000..d547fa8
--- /dev/null
@@ -0,0 +1 @@
+DEPS=""
diff --git a/config/rootfiles/core/11/update.sh b/config/rootfiles/core/11/update.sh
new file mode 100644 (file)
index 0000000..1bb84f9
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash
+. /opt/pakfire/lib/functions.sh
+/usr/local/bin/backupctrl exclude >/dev/null 2>&1
+extract_files
index 947c04f8f014ebd3fde31230503f0a5438752edd..57ffe9af496749e98c65b846046d6b56e8fde396 100644 (file)
 * tiff-3.8.2
 * traceroute-1.4a12
 * tripwire-2.4.1.2
+* tunctl
 * udev-096
 * udev-096-klibc
 * unzip552
diff --git a/lfs/tunctl b/lfs/tunctl
new file mode 100644 (file)
index 0000000..b6645df
--- /dev/null
@@ -0,0 +1,54 @@
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+###############################################################################
+# Definitions
+###############################################################################
+
+include Config
+
+VER        = ipfire
+
+THISAPP    = tunctl
+TARGET     = $(DIR_INFO)/$(THISAPP)
+
+###############################################################################
+# Top-level Rules
+###############################################################################
+
+install : $(TARGET)
+
+check : 
+
+download :
+
+md5 : 
+
+###############################################################################
+# Installation Details
+###############################################################################
+
+$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
+       @$(PREBUILD)
+       @rm -rf $(DIR_SRC)/br2684ctl
+       cd $(DIR_SRC) && gcc $(CFLAGS) -latm $(DIR_SRC)/src/tunctl/tunctl.c -o tunctl
+       cd $(DIR_SRC) && install -v -m 755 tunctl /usr/bin/tunctl
+       @rm -rf $(DIR_SRC)/tunctl
+       @$(POSTBUILD)
diff --git a/make.sh b/make.sh
index 0d123fbc25289f6701fbd709d976feeb0ac98c01..913c7c52302310af6909e78b358c46faa101be55 100755 (executable)
--- a/make.sh
+++ b/make.sh
@@ -546,6 +546,7 @@ buildipfire() {
   ipfiremake sane
   ipfiremake netpbm
   ipfiremake phpSANE
+  ipfiremake tunctl
 }
 
 buildinstaller() {
diff --git a/src/tunctl/tunctl.c b/src/tunctl/tunctl.c
new file mode 100755 (executable)
index 0000000..6e43906
--- /dev/null
@@ -0,0 +1,113 @@
+/* Copyright 2002 Jeff Dike
+ * Licensed under the GPL
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <linux/if_tun.h>
+
+static void Usage(char *name)
+{
+  fprintf(stderr, "Create: %s [-b] [-u owner] [-t device-name] "
+         "[-f tun-clone-device]\n", name);
+  fprintf(stderr, "Delete: %s -d device-name [-f tun-clone-device]\n\n", 
+         name);
+  fprintf(stderr, "The default tun clone device is /dev/net/tun - some systems"
+         " use\n/dev/misc/net/tun instead\n\n");
+  fprintf(stderr, "-b will result in brief output (just the device name)\n");
+  exit(1);
+}
+
+int main(int argc, char **argv)
+{
+  struct ifreq ifr;
+  struct passwd *pw;
+  long owner = geteuid();
+  int tap_fd, opt, delete = 0, brief = 0;
+  char *tun = "", *file = "/dev/net/tun", *name = argv[0], *end;
+
+  while((opt = getopt(argc, argv, "bd:f:t:u:")) > 0){
+    switch(opt) {
+      case 'b':
+        brief = 1;
+        break;
+      case 'd':
+        delete = 1;
+       tun = optarg;
+        break;
+      case 'f':
+       file = optarg;
+       break;
+      case 'u':
+       pw = getpwnam(optarg);
+       if(pw != NULL){
+         owner = pw->pw_uid;
+         break;
+       }
+        owner = strtol(optarg, &end, 0);
+       if(*end != '\0'){
+         fprintf(stderr, "'%s' is neither a username nor a numeric uid.\n",
+                 optarg);
+         Usage(name);
+       }
+        break;
+      case 't':
+        tun = optarg;
+        break;
+      case 'h':
+      default:
+        Usage(name);
+    }
+  }
+
+  argv += optind;
+  argc -= optind;
+
+  if(argc > 0)
+    Usage(name);
+
+  if((tap_fd = open(file, O_RDWR)) < 0){
+    fprintf(stderr, "Failed to open '%s' : ", file);
+    perror("");
+    exit(1);
+  }
+
+  memset(&ifr, 0, sizeof(ifr));
+
+  ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+  strncpy(ifr.ifr_name, tun, sizeof(ifr.ifr_name) - 1);
+  if(ioctl(tap_fd, TUNSETIFF, (void *) &ifr) < 0){
+    perror("TUNSETIFF");
+    exit(1);
+  }
+
+  if(delete){
+    if(ioctl(tap_fd, TUNSETPERSIST, 0) < 0){
+      perror("TUNSETPERSIST");
+      exit(1);
+    }    
+    printf("Set '%s' nonpersistent\n", ifr.ifr_name);
+  }
+  else {
+    if(ioctl(tap_fd, TUNSETPERSIST, 1) < 0){
+      perror("TUNSETPERSIST");
+      exit(1);
+    }
+    if(ioctl(tap_fd, TUNSETOWNER, owner) < 0){
+      perror("TUNSETPERSIST");
+      exit(1);
+    } 
+    if(brief)
+      printf("%s\n", ifr.ifr_name);
+    else printf("Set '%s' persistent and owned by uid %ld\n", ifr.ifr_name, 
+               owner);
+  }
+  return(0);
+}