|
|
1.1 root 1: #include <sys/param.h>
2: #include <stdio.h>
3: #include <errno.h>
4: #include <signal.h>
5: #include <sys/ttyio.h>
6: #include <sys/inio.h>
7: #include <sys/filio.h>
8: #include <sys/inet/in.h>
9: #include <ipc.h>
10:
11:
12: #define RESETTIME 15*60
13: #define DEFMTU 1500
14:
15: static char *cmdname;
16: static in_addr myaddr;
17: static in_addr hisaddr;
18:
19: int dontcheck;
20: FILE *fp;
21: char measnum[32];
22: char himasnum[32];
23:
24: #define GOSTR "OK - send me your poor, your wretched, your huddled packets waiting to be free\n"
25:
26: extern char *optarg;
27: extern int optind;
28:
29: usage(cmd)
30: char *cmd;
31: {
32: fprintf(stderr, "Usage: %s [-d] [-m #] dk-address my-ip-addr his-ip-addr\n",
33: cmd);
34: }
35:
36: main(argc, argv)
37: char *argv[];
38: {
39: int other_end, my_pid, c;
40: char buf[256];
41: unsigned int mtu;
42: int n;
43:
44: signal(SIGHUP, SIG_IGN);
45: cmdname = argv[0];
46:
47: mtu = DEFMTU;
48: while((c=getopt(argc, argv, "dm:")) != -1)
49: switch(c){
50: case 'd':
51: dontcheck = 1;
52: break;
53: case 'm':
54: mtu = atoi(optarg);
55: break;
56: default:
57: usage(cmdname);
58: break;
59: }
60:
61: switch(argc-optind){
62: case 2:
63: close(2);
64: translate(argv[optind], argv[optind+1]);
65: ipconfig(0, mtu);
66: write(0, GOSTR, sizeof(GOSTR));
67: waitforhup(0);
68: break;
69: case 3:
70: detach("dkipconfig");
71: translate(argv[optind+1], argv[optind+2]);
72: while(1) {
73: other_end = callup(argv[optind], himasnum, measnum, mtu);
74: if (other_end < 0) {
75: logevent("%s: %s\n", argv[optind], errstr);
76: sleep(60);
77: continue;
78: }
79: if (ioctl(other_end, TIOCSPGRP, 0) < 0) {
80: logevent("TIOCSPGRP %d\n", errno);
81: close(other_end);
82: sleep(60);
83: continue;
84: }
85: while((n=read(other_end, buf, sizeof(buf)))>0){
86: if(n == sizeof(GOSTR) && strcmp(GOSTR, buf) == 0)
87: break;
88: }
89: ipconfig(other_end, mtu);
90: waitforhup(other_end);
91: close(other_end);
92: }
93: break;
94: default:
95: usage(cmdname);
96: exit(1);
97: }
98: }
99:
100: /*
101: * translate names to ip addresses
102: */
103: translate(me, it)
104: char *me;
105: char *it;
106: {
107: fp = fopen("/usr/ipc/log/dkip", "a");
108: if(fp==0){
109: fprintf(stderr, "dkipconfig: can't open log\n", it);
110: fp = stderr;
111: }
112: hisaddr = in_address(it);
113: if(hisaddr == 0){
114: logevent("dkipconfig: unknown host/net %s\n", it);
115: fclose(fp);
116: exit(1);
117: }
118: strcpy(himasnum, in_ntoa(hisaddr));
119: if(dontcheck)
120: myaddr = in_address(me);
121: else
122: myaddr = in_addronnet(me, hisaddr, 0);
123: if(myaddr == 0){
124: logevent("unknown host %s on net %s\n", me,
125: in_ntoa(hisaddr));
126: exit(1);
127: }
128: strcpy(measnum, in_ntoa(myaddr));
129: logevent("connecting as %s to %s\n", measnum, himasnum);
130: fclose(fp);
131: }
132:
133: static int
134: ipconfig(ipfd, mtu)
135: int ipfd;
136: unsigned int mtu;
137: {
138: extern int ip_ld;
139:
140: if(ioctl(ipfd, FIOPUSHLD, &ip_ld) < 0){
141: logevent("can't push ip\n");
142: exit(1);
143: }
144: if(ioctl(ipfd, IPIOLOCAL, &myaddr) < 0){
145: logevent("can't set local address\n");
146: exit(1);
147: }
148: ioctl(ipfd, IPIOMTU, &mtu);
149: if(in_netof(hisaddr) != hisaddr){
150: if(ioctl(ipfd, IPIOHOST, &hisaddr) < 0){
151: logevent("can't set remote address\n");
152: exit(1);
153: }
154: } else {
155: if(ioctl(ipfd, IPIONET, &hisaddr) < 0){
156: logevent("can't set network address");
157: exit(1);
158: }
159: }
160: }
161:
162: static int
163: callup(host, a1, a2, mtu)
164: char *host, *a1, *a2;
165: unsigned int mtu;
166: {
167: char cmd[512];
168: int fd;
169:
170: fd=ipcopen(ipcpath(host, "dk", "dkip"), "heavy");
171: if(fd<0)
172: return(fd);
173: sprintf(cmd, "-m %d %s %s", mtu, a1, a2);
174: write(fd, cmd, strlen(cmd)+1);
175: return(fd);
176: }
177:
178: waitforhup(fd)
179: {
180: char buf[128];
181:
182: while(read(fd, buf, sizeof(buf))>0)
183: ;
184: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.