瀏覽代碼

Added tunctl (since it is difficult to find for many distros).

tags/v0.9.3
Michael Brown 18 年之前
父節點
當前提交
10606e95b3
共有 4 個文件被更改,包括 131 次插入12 次删除
  1. 1
    1
      contrib/bochs/.cvsignore
  2. 5
    2
      contrib/bochs/Makefile
  3. 12
    9
      contrib/bochs/README
  4. 113
    0
      contrib/bochs/tunctl.c

+ 1
- 1
contrib/bochs/.cvsignore 查看文件

2
 parport.out
2
 parport.out
3
 ne2k-tx.log
3
 ne2k-tx.log
4
 ne2k-txdump.txt
4
 ne2k-txdump.txt
5
-
5
+tunctl

+ 5
- 2
contrib/bochs/Makefile 查看文件

1
-all : serial-console.1
1
+all : tunctl serial-console.1
2
 
2
 
3
 %.1 : %
3
 %.1 : %
4
 	pod2man $< > $@
4
 	pod2man $< > $@
5
 
5
 
6
+tunctl : tunctl.c
7
+	$(CC) -o $@ $<
8
+
6
 clean :
9
 clean :
7
-	rm -f serial-console.1
10
+	rm -f serial-console.1 tunctl

+ 12
- 9
contrib/bochs/README 查看文件

14
 
14
 
15
 To get bochs running is fairly simple:
15
 To get bochs running is fairly simple:
16
 
16
 
17
-1.  Get the bochs source code:
17
+1.  Build the utilities in this directory
18
+      make
19
+
20
+2.  Get the bochs source code:
18
       cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/bochs login
21
       cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/bochs login
19
       cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/bochs co bochs
22
       cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/bochs co bochs
20
 
23
 
21
-2.  Configure bochs with
24
+3.  Configure bochs with
22
       pushd bochs
25
       pushd bochs
23
       ./configure --enable-all-optimisations --enable-pci --enable-pnic
26
       ./configure --enable-all-optimisations --enable-pci --enable-pnic
24
                   --enable-debugger --enable-magic-breakpoints --enable-disasm
27
                   --enable-debugger --enable-magic-breakpoints --enable-disasm
25
       popd
28
       popd
26
 
29
 
27
-3.  Build bochs:
30
+4.  Build bochs:
28
       make -C bochs
31
       make -C bochs
29
 
32
 
30
-4.  Set up a TAP virtual network device:
33
+5.  Set up a TAP virtual network device:
31
       modprobe tun
34
       modprobe tun
32
-      tunctl -u <username> -t tap0
35
+      ./tunctl -u <username> -t tap0
33
       ifconfig tap0 up 10.254.254.2 netmask 255.255.255.0
36
       ifconfig tap0 up 10.254.254.2 netmask 255.255.255.0
34
 
37
 
35
-5.  Add the following fragment to /etc/dhcpd.conf:
38
+6.  Add the following fragment to /etc/dhcpd.conf:
36
       subnet 10.254.254.0 netmask 255.255.255.252 {
39
       subnet 10.254.254.0 netmask 255.255.255.252 {
37
         range dynamic-bootp 10.254.254.1 10.254.254.1;
40
         range dynamic-bootp 10.254.254.1 10.254.254.1;
38
       }
41
       }
42
     machine you are using for running Bochs.  If not, then you're on
45
     machine you are using for running Bochs.  If not, then you're on
43
     your own.
46
     your own.
44
 
47
 
45
-6.  Restart dhcpd
48
+7.  Restart dhcpd
46
       /etc/init.d/dhcpd restart
49
       /etc/init.d/dhcpd restart
47
 
50
 
48
-7.  Build Etherboot images
51
+8.  Build Etherboot images
49
       pushd ../../src
52
       pushd ../../src
50
       make bin/pnic.dsk
53
       make bin/pnic.dsk
51
       popd
54
       popd
52
 
55
 
53
-8.  Start Bochs
56
+9.  Start Bochs
54
       ./bochs/bochs -q
57
       ./bochs/bochs -q
55
     You should get to the debugger prompt "<bochs:1>".  Type "c" to
58
     You should get to the debugger prompt "<bochs:1>".  Type "c" to
56
     start running Bochs.
59
     start running Bochs.

+ 113
- 0
contrib/bochs/tunctl.c 查看文件

1
+/* Copyright 2002 Jeff Dike
2
+ * Licensed under the GPL
3
+ */
4
+
5
+#include <stdio.h>
6
+#include <stdlib.h>
7
+#include <string.h>
8
+#include <errno.h>
9
+#include <fcntl.h>
10
+#include <unistd.h>
11
+#include <pwd.h>
12
+#include <net/if.h>
13
+#include <sys/ioctl.h>
14
+#include <linux/if_tun.h>
15
+
16
+static void Usage(char *name)
17
+{
18
+  fprintf(stderr, "Create: %s [-b] [-u owner] [-t device-name] "
19
+	  "[-f tun-clone-device]\n", name);
20
+  fprintf(stderr, "Delete: %s -d device-name [-f tun-clone-device]\n\n", 
21
+	  name);
22
+  fprintf(stderr, "The default tun clone device is /dev/net/tun - some systems"
23
+	  " use\n/dev/misc/net/tun instead\n\n");
24
+  fprintf(stderr, "-b will result in brief output (just the device name)\n");
25
+  exit(1);
26
+}
27
+
28
+int main(int argc, char **argv)
29
+{
30
+  struct ifreq ifr;
31
+  struct passwd *pw;
32
+  long owner = geteuid();
33
+  int tap_fd, opt, delete = 0, brief = 0;
34
+  char *tun = "", *file = "/dev/net/tun", *name = argv[0], *end;
35
+
36
+  while((opt = getopt(argc, argv, "bd:f:t:u:")) > 0){
37
+    switch(opt) {
38
+      case 'b':
39
+        brief = 1;
40
+        break;
41
+      case 'd':
42
+        delete = 1;
43
+	tun = optarg;
44
+        break;
45
+      case 'f':
46
+	file = optarg;
47
+	break;
48
+      case 'u':
49
+	pw = getpwnam(optarg);
50
+	if(pw != NULL){
51
+	  owner = pw->pw_uid;
52
+	  break;
53
+	}
54
+        owner = strtol(optarg, &end, 0);
55
+	if(*end != '\0'){
56
+	  fprintf(stderr, "'%s' is neither a username nor a numeric uid.\n",
57
+		  optarg);
58
+	  Usage(name);
59
+	}
60
+        break;
61
+      case 't':
62
+        tun = optarg;
63
+        break;
64
+      case 'h':
65
+      default:
66
+        Usage(name);
67
+    }
68
+  }
69
+
70
+  argv += optind;
71
+  argc -= optind;
72
+
73
+  if(argc > 0)
74
+    Usage(name);
75
+
76
+  if((tap_fd = open(file, O_RDWR)) < 0){
77
+    fprintf(stderr, "Failed to open '%s' : ", file);
78
+    perror("");
79
+    exit(1);
80
+  }
81
+
82
+  memset(&ifr, 0, sizeof(ifr));
83
+
84
+  ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
85
+  strncpy(ifr.ifr_name, tun, sizeof(ifr.ifr_name) - 1);
86
+  if(ioctl(tap_fd, TUNSETIFF, (void *) &ifr) < 0){
87
+    perror("TUNSETIFF");
88
+    exit(1);
89
+  }
90
+
91
+  if(delete){
92
+    if(ioctl(tap_fd, TUNSETPERSIST, 0) < 0){
93
+      perror("TUNSETPERSIST");
94
+      exit(1);
95
+    }    
96
+    printf("Set '%s' nonpersistent\n", ifr.ifr_name);
97
+  }
98
+  else {
99
+    if(ioctl(tap_fd, TUNSETPERSIST, 1) < 0){
100
+      perror("TUNSETPERSIST");
101
+      exit(1);
102
+    }
103
+    if(ioctl(tap_fd, TUNSETOWNER, owner) < 0){
104
+      perror("TUNSETPERSIST");
105
+      exit(1);
106
+    } 
107
+    if(brief)
108
+      printf("%s\n", ifr.ifr_name);
109
+    else printf("Set '%s' persistent and owned by uid %ld\n", ifr.ifr_name, 
110
+		owner);
111
+  }
112
+  return(0);
113
+}

Loading…
取消
儲存