-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBPQCMD.C
469 lines (431 loc) · 12.4 KB
/
BPQCMD.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
/* code to allow nos to talk directly to bpqcode
*
* by paul h launspach n5faz
* (c) 1993,1994 FazCom
* 4-13-93
*/
/* $Id: bpqcmd.c 1.5 1994/03/23 06:10:54 fz-phl Exp $ */
/* $Log: bpqcmd.c $
* Revision 1.5 1994/03/23 06:10:54 fz-phl
* cleaned up the ifdefs.
* dobpqstat - removed display of values only used by bpq socket code.
* added dobpqtrace to trace unattached bpq ports
* dobpq now uses command mux
* Further modified by N5KNX for Jnos 1.11*
*
* Revision 1.4 1994/03/11 15:25:06 fz-phl
* added ifdef BPQJNOS for printf -> tprintf macro and
* changed display of ifp-rawsndcnt to a %lu in dobpqstat.
*
* Revision 1.3 1994/03/11 15:13:45 Johan
* changed printf's to tprintf's
*
* Revision 1.2 1994/03/11 15:04:33 fz-phl
* added ifdef BPQSOCK and other stuff for jnos.
*
* Revision 1.1 1994/03/11 02:25:10 fz-phl
* Initial revision
*
*/
#include "global.h"
#include "config.h"
#ifdef BPQ
#include "cmdparse.h"
#include "socket.h"
#include "session.h"
#include "usock.h"
#include "bpq.h"
#include "trace.h"
#ifdef BPQJNOS /* change printf to tprintf for jnos etc */
#define printf tprintf
#endif
int dobpqstat (int,char *argv[],void *);
#ifdef TRACE
static int dobpqtrace (int,char *argv[],void *);
#endif
#ifdef BPQSOCK
static int dobpqconn (int,char *argv[],void *);
static int dobpqreset (int,char *argv[],void *);
static int dobpqwindow (int,char *argv[],void *);
#endif
char *Bpqstates[] = {
"Disconn",
"Connect",
"Listen",
"Lis>Con"
};
char *Bpqreasons[] = {
"Normal",
"By Peer",
"Timeout",
"Reset",
"Refused"
} ;
static struct cmds Bpqcmds[] = {
"status", dobpqstat, 0, 0, NULLCHAR,
#ifdef TRACE
#ifdef BPQJNOS
"trace", dobpqtrace, 0, 1, "bpq trace <port> <flags>",
#else
"trace", dobpqtrace, 512, 1, "bpq trace <port> <flags>",
#endif
#endif /* trace */
#ifdef BPQSOCK
"connect", dobpqconn, 1024, 0, NULLCHAR,
"reset", dobpqreset, 0, 2, "bpq reset <bpqcb>",
"window", dobpqwindow, 0, 1, "bpq window <frames>",
#endif /* BPQSOCK */
NULLCHAR,
};
/* Multiplexer for top-level bpq command */
int
dobpq(argc,argv,p)
int argc;
char *argv[];
void *p;
{
if(!Bpqinfo.vec){
printf("Bpq must be initialized with: attach bpq init <vec> <stream>\n");
return 1;
}
if(argc < 2)
return dobpqstat(argc,argv,p);
return subcmd(Bpqcmds,argc,argv,p);
}
/* display bpq info stats */
static int
dobpqstat(argc,argv,p)
int argc;
char *argv[];
void *p;
{
int i;
struct iface *ifp;
#ifdef BPQSOCK
struct bpq_cb *cb;
#endif
char buf[11];
#ifdef BPQSOCK
printf("Vec Stream Ports Window Conn: Tot Max Curr Next\n");
printf(" %2x %2u %2u %2u %3u %3u %3u %3u\n",
Bpqinfo.vec,Bpqinfo.monstream,Bpqinfo.maxport,Bpqinfo.window,
Bpqinfo.maxstream-Bpqinfo.monstream + 1,
Bpqinfo.maxconn,Bpqinfo.curr,Bpqinfo.nextconn+1);
printf("Recvd Sent ");
#else
printf("Vec Stream Ports\n");
printf(" %2x %2u %2u\n",Bpqinfo.vec,
Bpqinfo.monstream,Bpqinfo.maxport);
#endif
printf(" Rx Tx Rxint Txint Ctlint Free Min\n");
#ifdef BPQSOCK
printf("%5lu %5lu ",Bpqinfo.recv,Bpqinfo.send);
#endif
printf("%5lu %5lu %7lu %7lu %7lu",
Bpqinfo.recvcnt,Bpqinfo.sendcnt,Bpqinfo.rxcnt,
Bpqinfo.txcnt,Bpqinfo.contcnt);
i = bpq_int(BPQ_BUF,1,0,NULLCHAR);
Bpqinfo.minfree = min(i,Bpqinfo.minfree);
printf(" %3u %3u\n",i,Bpqinfo.minfree);
/* print any iface info */
if(Bpqinfo.maxport){
printf("\nPort Label Call IP-Address Mtu Rx Tx\n");
for(i=0; i < BPQMAXPORT ; i++)
if((ifp = Bpqinfo.ports[i]) != NULLIF)
printf("%4u %-10.10s %-9.9s %-15.15s %3u %5lu %5lu\n",
ifp->dev,ifp->name,pax25(buf,ifp->hwaddr),
inet_ntoa(ifp->addr),ifp->mtu,ifp->rawrecvcnt,
ifp->rawsndcnt);
}
/* print any connection status */
#ifdef BPQSOCK
if(Bpqinfo.cb != NULLBPQ){
printf("\n&BPQCB Owner Sock St Num Recv Sent Rxq Txq Appl Tot Curr\n");
for(cb = Bpqinfo.cb; cb != NULLBPQ ; cb = cb->next)
st_bpq_cb(cb);
}
#endif
/* print the all stream status */
/* whether we are using it or something else is */
printf("\n St Num State Type/Pt User Recv Unak Maxf Pacl\n");
for(i=1; i <= BPQMAXSTREAM ; i++)
st_bpq(i);
return 0;
}
#ifdef BPQSOCK
void
st_bpq_cb(cb)
struct bpq_cb *cb;
{
struct usock *up;
up = itop(cb->user);
printf("%-8lx %-16.16s %4u %2u %3u %4u %4u %4u %4u",
ptol(cb),up->owner->name,cb->user,cb->stream,cb->conn,
cb->recv,cb->send,len_p(cb->rxq),len_q(cb->txq));
if(cb->serv != NULLBPQS)
if(cb->state == BPQ_ST_LIS)
printf(" %2u %3u %3u",cb->serv->appl,
cb->serv->users,cb->serv->curr);
else
printf(" %3u",cb->sconn);
printf("\n");
}
#endif
void
st_bpq(i)
int i;
{
#ifdef BPQSOCK
struct bpq_cb *cb;
#endif
char buf[11];
uint16 st;
uint16 tp;
/* dont ack the state call. we want who ever is */
/* really using this stream to see any state changes */
/* only display active streams */
#ifdef BPQSOCK
cb = find_bpq(i);
st = bpq_int(BPQ_STATE,i,0,NULLCHAR);
if(!st && cb == NULLBPQ && i != Bpqinfo.monstream)
return;
#else
if(!(st = bpq_int(BPQ_STATE,i,0,NULLCHAR)) && i != Bpqinfo.monstream)
return;
#endif
#ifdef BPQSOCK
if(cb != NULLBPQ){
st |= cb->state;
printf("%s%2u %3u",i == Bpqinfo.monstream ? "*" : " ",
cb->stream,cb->conn);
} else
#endif
printf("%s%2u ",i == Bpqinfo.monstream ? "*" : " ",i);
printf(" %-7s%s",Bpqstates[st & ~BPQ_ST_CHG],
st & BPQ_ST_CHG ? "+" : " ");
if(st & BPQ_ST_CON){
tp = bpq_int(BPQ_USERCALL,i,0,buf);
if(tp & BPQ_HOST)
printf(" Host");
else if(tp & BPQ_SESSION)
printf(" Circuit");
else if(tp & BPQ_UPLINK)
printf(" Uplink");
else if(tp & BPQ_DOWNLK)
printf(" Downlnk");
else if(tp)
printf(" Unk: %2u",tp);
else printf(" ");
if(tp & BPQ_L2)
printf(" %2u",lobyte(tp));
else printf(" ");
#ifdef BPQSOCK
if(cb != NULLBPQ)
printf(" %9.9s %3u %3u %3u %3u",buf,
bpq_int(BPQ_RECVQUE,i,0,NULLCHAR),cb->unack,
cb->maxframe,cb->paclen);
else
#endif
printf(" %9.9s %3u %3u %3u %3u",buf,
bpq_int(BPQ_RECVQUE,i,0,NULLCHAR),
bpq_int(BPQ_UNACK,i,0,NULLCHAR),
bpq_int(BPQ_MAXFR,i,0,buf),
bpq_int(BPQ_PACLEN,i,0,buf));
}
printf("\n");
}
#ifdef TRACE
/* trace an unattached bpq port */
static int
dobpqtrace(argc,argv,p)
int argc;
char *argv[];
void *p;
{
char bpq[]="bpq ";
char hex[]="123456789abcdef";
struct iface *ifp;
struct tracecmd *tp;
#ifdef BPQJNOS
extern int stdoutSock;
#else
struct session *sp;
#endif
int i;
int port;
if(argc < 2){
for(i=0;i <= BPQMAXPORT;i++)
if(Bpqinfo.tport[i] != NULLIF)
showtrace(Bpqinfo.tport[i]);
return 0;
}
port = htoi(argv[1]);
if(port < 1 || port > BPQMAXPORT){
printf("Port must be between 1 and %d.\n",BPQMAXPORT);
return -1;
}
port--;
bpq[3] = hex[port];
if(Bpqinfo.ports[port] != NULLIF){
printf("Port %x is attached!\nUse 'Trace %s <flags>' to trace.\n",
port+1, Bpqinfo.ports[port]->name);
return -1;
}
if(argc == 2){
if(Bpqinfo.tport[port] != NULLIF)
showtrace(Bpqinfo.tport[port]);
else printf("%s: tracing off\n",bpq);
return 0;
}
if(argc >= 3){
if(Bpqinfo.tport[port] == NULLIF){
ifp = (struct iface *)callocw(1,sizeof(struct iface));
ifp->name = strdup(bpq);
ifp->iftype = &Bpqinfo.ift;
#ifdef BPQJNOS
ifp->type = Bpqinfo.ift.type;
#endif
Bpqinfo.tport[port] = ifp;
Bpqinfo.maxtrace++;
} else ifp = Bpqinfo.tport[port];
for(tp = Tracecmd;tp->name != NULLCHAR;tp++)
if(strncmp(tp->name,argv[2],strlen(argv[2])) == 0)
break;
if(tp->name != NULLCHAR)
ifp->trace = (ifp->trace & ~tp->mask) | tp->val;
else
ifp->trace = htoi(argv[2]);
}
if(!Bpqinfo.maxport && ifp->trace != 0)
bpq_int(BPQ_SET,Bpqinfo.monstream,BPQ_MONITOR,NULLCHAR);
#ifdef BPQJNOS
/* we steal code from dotrace() in trace.c */
/* Always default to stdout unless trace file is given */
if(ifp->trsock != stdoutSock)
close_s(ifp->trsock);
ifp->trsock = stdoutSock;
if(ifp->trfile != NULLCHAR)
free(ifp->trfile);
ifp->trfile = NULLCHAR;
if(argc >= 4){
if((ifp->trsock = sockfopen(argv[3],APPEND_TEXT)) == -1){
tprintf("Can't open socket for %s\n",argv[3]);
ifp->trsock = stdoutSock;
} else {
ifp->trfile = strdup(argv[3]);
}
} else {
/* If not from the console, trace to the current output socket! */
if(Curproc->input != Command->input) {
/* this comes from a remote connection, ie a user in
* 'sysop' mode on the bbs or maybe in a TRACESESSION
*/
ifp->trsock = Curproc->output;
/* make sure stopping trace doesn't kill connection */
usesock(ifp->trsock);
}
}
showtrace(ifp);
#else /* BPQJNOS */
if(ifp->trfp != NULLFILE){
/* Close existing trace file */
fclose(ifp->trfp);
ifp->trfp = NULLFILE;
}
if(argc >= 4){
if((ifp->trfp = fopen(argv[3],APPEND_TEXT)) == NULLFILE){
printf("Can't write to %s\n",argv[3]);
}
} else if(ifp->trace != 0){
/* Create trace session */
sp = newsession(Cmdline,ITRACE,1);
sp->cb.p = NULL;
sp->proc = sp->proc1 = sp->proc2 = NULLPROC;
ifp->trfp = sp->output;
showtrace(ifp);
getchar(); /* Wait for the user to hit something */
ifp->trace = 0;
ifp->trfp = NULLFILE;
freesession(sp);
}
#endif /* BPQJNOS */
if(ifp->trace == 0){
free(ifp->name);
free((char *)ifp);
Bpqinfo.tport[port] = NULLIF;
Bpqinfo.maxtrace--;
}
if(!Bpqinfo.maxtrace && !Bpqinfo.maxport)
bpq_int(BPQ_SET,Bpqinfo.monstream,0,NULLCHAR);
return 0;
}
void
bpqshuttrace()
{
int i;
struct iface *ifp;
if(Bpqinfo.vec){ /* must be init'ed */
for(i=0;i <= BPQMAXPORT; i++)
if((ifp=Bpqinfo.tport[i]) != NULLIF){
free(ifp->name);
free((char *)ifp);
Bpqinfo.tport[i] = NULLIF;
Bpqinfo.maxtrace--;
}
if(!Bpqinfo.maxtrace && !Bpqinfo.maxport)
bpq_int(BPQ_SET,Bpqinfo.monstream,0,NULLCHAR);
}
return;
}
#endif /* TRACE */
#ifdef BPQSOCK
static int
dobpqconn(argc,argv,p)
int argc;
char *argv[];
void *p;
{
struct sockaddr_bq fsocket;
struct session *sp;
int s;
if((sp = newsession(Cmdline,BPQSESSION,1)) == NULLSESSION){
printf(TooManySessions);
return 1;
}
if((s = socket(AF_BPQ,SOCK_STREAM,0)) == -1){
printf("Can't create socket\n");
freesession(sp);
keywait(NULLCHAR,1);
return 1;
}
fsocket.bpq_family = AF_BPQ;
memcpy(fsocket.bpq_addr,"SWITCH \0",AXBUF);
sp->network = fdopen(s,"r+t");
setvbuf(sp->network,NULLCHAR,_IOLBF,BUFSIZ);
return tel_connect(sp, (char *)&fsocket, sizeof(struct sockaddr_bq));
}
static int
dobpqreset(argc,argv,p)
int argc;
char *argv[];
void *p;
{
struct bpq_cb *cb;
cb = (struct bpq_cb *)ltop(htol(argv[1]));
if(!bpqval(cb)){
printf(Notval);
return 1;
}
disc_bpq(cb,1);
return 0;
}
static int
dobpqwindow(argc,argv,p)
int argc;
char *argv[];
void *p;
{
return setshort(&Bpqinfo.window,"Bpq window (frames)",argc,argv);
}
#endif /* BPQSOCK */
#endif /* BPQ */