1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * This part for NCR UNIX with is from Andrew Maffei (arm@aqua.whoi.edu). It
3*0Sstevel@tonic-gate * assumes TLI throughout. In order to look up endpoint address information
4*0Sstevel@tonic-gate * we must talk to the "timod" streams module. For some reason "timod" wants
5*0Sstevel@tonic-gate * to sit directly on top of the device driver. Therefore we pop off all
6*0Sstevel@tonic-gate * streams modules except the driver, install the "timod" module so that we
7*0Sstevel@tonic-gate * can figure out network addresses, and then restore the original state.
8*0Sstevel@tonic-gate */
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gate #ifndef lint
11*0Sstevel@tonic-gate static char sccsid[] = "@(#) ncr.c 1.1 94/12/28 17:42:34";
12*0Sstevel@tonic-gate #endif
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gate #include <sys/types.h>
15*0Sstevel@tonic-gate #include <stdio.h>
16*0Sstevel@tonic-gate #include <syslog.h>
17*0Sstevel@tonic-gate #include <sys/tiuser.h>
18*0Sstevel@tonic-gate #include <stropts.h>
19*0Sstevel@tonic-gate #include <sys/conf.h>
20*0Sstevel@tonic-gate
21*0Sstevel@tonic-gate #include "tcpd.h"
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gate #define MAX_MODULE_COUNT 10 /* XXX */
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate /* fromhost - tear down the streams stack then rebuild it */
26*0Sstevel@tonic-gate
fromhost(request)27*0Sstevel@tonic-gate void fromhost(request)
28*0Sstevel@tonic-gate struct request_info *request;
29*0Sstevel@tonic-gate {
30*0Sstevel@tonic-gate int i;
31*0Sstevel@tonic-gate int num_mod;
32*0Sstevel@tonic-gate struct str_list str_list;
33*0Sstevel@tonic-gate struct str_mlist mod_buffer[MAX_MODULE_COUNT];
34*0Sstevel@tonic-gate int fd = request->fd;
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate str_list.sl_nmods = MAX_MODULE_COUNT;
37*0Sstevel@tonic-gate str_list.sl_modlist = &mod_buffer[0];
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gate /*
40*0Sstevel@tonic-gate * On systems with WIN streams support we have to be careful about what
41*0Sstevel@tonic-gate * is on the stream we are passed. This code POPs off all modules above
42*0Sstevel@tonic-gate * the pseudo driver, pushes timod, gets the host address information,
43*0Sstevel@tonic-gate * pops timod and then pushes all modules back on the stream.
44*0Sstevel@tonic-gate *
45*0Sstevel@tonic-gate * Some state may be lost in this process. /usr/etc/tlid seems to do special
46*0Sstevel@tonic-gate * things to the stream depending on the TCP port being serviced. (not a
47*0Sstevel@tonic-gate * very nice thing to do!). It is unclear what to do if this code breaks
48*0Sstevel@tonic-gate * - the stream may be left in an unknown condition.
49*0Sstevel@tonic-gate */
50*0Sstevel@tonic-gate if ((num_mod = ioctl(fd, I_LIST, NULL)) < 0)
51*0Sstevel@tonic-gate tcpd_warn("fromhost: LIST failed: %m");
52*0Sstevel@tonic-gate if (ioctl(fd, I_LIST, &str_list) < 0)
53*0Sstevel@tonic-gate tcpd_warn("fromhost: LIST failed: %m");
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate /*
56*0Sstevel@tonic-gate * POP stream modules except for the driver.
57*0Sstevel@tonic-gate */
58*0Sstevel@tonic-gate for (i = 0; i < num_mod - 1; i++)
59*0Sstevel@tonic-gate if (ioctl(fd, I_POP, 0) < 0)
60*0Sstevel@tonic-gate tcpd_warn("fromhost: POP %s: %m", mod_buffer[i].l_name);
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate /*
63*0Sstevel@tonic-gate * PUSH timod so that host address ioctls can be executed.
64*0Sstevel@tonic-gate */
65*0Sstevel@tonic-gate if (ioctl(fd, I_PUSH, "timod") < 0)
66*0Sstevel@tonic-gate tcpd_warn("fromhost: PUSH timod: %m");
67*0Sstevel@tonic-gate tli_host(request);
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate /*
70*0Sstevel@tonic-gate * POP timod, we're done with it now.
71*0Sstevel@tonic-gate */
72*0Sstevel@tonic-gate if (ioctl(fd, I_POP, 0) < 0)
73*0Sstevel@tonic-gate tcpd_warn("fromhost: POP timod: %m");
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate /*
76*0Sstevel@tonic-gate * Restore stream modules.
77*0Sstevel@tonic-gate */
78*0Sstevel@tonic-gate for (i = num_mod - 2; i >= 0; i--)
79*0Sstevel@tonic-gate if (ioctl(fd, I_PUSH, mod_buffer[i].l_name) < 0)
80*0Sstevel@tonic-gate tcpd_warn("fromhost: PUSH %s: %m", mod_buffer[i].l_name);
81*0Sstevel@tonic-gate }
82