Bläddra i källkod

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

tags/v0.9.3
Michael Brown 18 år sedan
förälder
incheckning
10606e95b3
4 ändrade filer med 131 tillägg och 12 borttagningar
  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 Visa fil

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

+ 5
- 2
contrib/bochs/Makefile Visa fil

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

+ 12
- 9
contrib/bochs/README Visa fil

@@ -14,25 +14,28 @@ but it doesn't seem to quite work.)
14 14
 
15 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 21
       cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/bochs login
19 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 25
       pushd bochs
23 26
       ./configure --enable-all-optimisations --enable-pci --enable-pnic
24 27
                   --enable-debugger --enable-magic-breakpoints --enable-disasm
25 28
       popd
26 29
 
27
-3.  Build bochs:
30
+4.  Build bochs:
28 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 34
       modprobe tun
32
-      tunctl -u <username> -t tap0
35
+      ./tunctl -u <username> -t tap0
33 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 39
       subnet 10.254.254.0 netmask 255.255.255.252 {
37 40
         range dynamic-bootp 10.254.254.1 10.254.254.1;
38 41
       }
@@ -42,15 +45,15 @@ To get bochs running is fairly simple:
42 45
     machine you are using for running Bochs.  If not, then you're on
43 46
     your own.
44 47
 
45
-6.  Restart dhcpd
48
+7.  Restart dhcpd
46 49
       /etc/init.d/dhcpd restart
47 50
 
48
-7.  Build Etherboot images
51
+8.  Build Etherboot images
49 52
       pushd ../../src
50 53
       make bin/pnic.dsk
51 54
       popd
52 55
 
53
-8.  Start Bochs
56
+9.  Start Bochs
54 57
       ./bochs/bochs -q
55 58
     You should get to the debugger prompt "<bochs:1>".  Type "c" to
56 59
     start running Bochs.

+ 113
- 0
contrib/bochs/tunctl.c Visa fil

@@ -0,0 +1,113 @@
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
+}

Laddar…
Avbryt
Spara