12aef6930SMark Murray /*
22aef6930SMark Murray * This part for NCR UNIX with is from Andrew Maffei (arm@aqua.whoi.edu). It
32aef6930SMark Murray * assumes TLI throughout. In order to look up endpoint address information
42aef6930SMark Murray * we must talk to the "timod" streams module. For some reason "timod" wants
52aef6930SMark Murray * to sit directly on top of the device driver. Therefore we pop off all
62aef6930SMark Murray * streams modules except the driver, install the "timod" module so that we
72aef6930SMark Murray * can figure out network addresses, and then restore the original state.
82aef6930SMark Murray */
92aef6930SMark Murray
102aef6930SMark Murray #ifndef lint
112aef6930SMark Murray static char sccsid[] = "@(#) ncr.c 1.1 94/12/28 17:42:34";
122aef6930SMark Murray #endif
132aef6930SMark Murray
142aef6930SMark Murray #include <sys/types.h>
152aef6930SMark Murray #include <stdio.h>
162aef6930SMark Murray #include <syslog.h>
172aef6930SMark Murray #include <sys/tiuser.h>
182aef6930SMark Murray #include <stropts.h>
192aef6930SMark Murray #include <sys/conf.h>
202aef6930SMark Murray
212aef6930SMark Murray #include "tcpd.h"
222aef6930SMark Murray
232aef6930SMark Murray #define MAX_MODULE_COUNT 10 /* XXX */
242aef6930SMark Murray
252aef6930SMark Murray /* fromhost - tear down the streams stack then rebuild it */
262aef6930SMark Murray
fromhost(struct request_info * request)27*14f102eaSEd Maste void fromhost(struct request_info *request)
282aef6930SMark Murray {
292aef6930SMark Murray int i;
302aef6930SMark Murray int num_mod;
312aef6930SMark Murray struct str_list str_list;
322aef6930SMark Murray struct str_mlist mod_buffer[MAX_MODULE_COUNT];
332aef6930SMark Murray int fd = request->fd;
342aef6930SMark Murray
352aef6930SMark Murray str_list.sl_nmods = MAX_MODULE_COUNT;
362aef6930SMark Murray str_list.sl_modlist = &mod_buffer[0];
372aef6930SMark Murray
382aef6930SMark Murray /*
392aef6930SMark Murray * On systems with WIN streams support we have to be careful about what
402aef6930SMark Murray * is on the stream we are passed. This code POPs off all modules above
412aef6930SMark Murray * the pseudo driver, pushes timod, gets the host address information,
422aef6930SMark Murray * pops timod and then pushes all modules back on the stream.
432aef6930SMark Murray *
442aef6930SMark Murray * Some state may be lost in this process. /usr/etc/tlid seems to do special
452aef6930SMark Murray * things to the stream depending on the TCP port being serviced. (not a
462aef6930SMark Murray * very nice thing to do!). It is unclear what to do if this code breaks
472aef6930SMark Murray * - the stream may be left in an unknown condition.
482aef6930SMark Murray */
492aef6930SMark Murray if ((num_mod = ioctl(fd, I_LIST, NULL)) < 0)
502aef6930SMark Murray tcpd_warn("fromhost: LIST failed: %m");
512aef6930SMark Murray if (ioctl(fd, I_LIST, &str_list) < 0)
522aef6930SMark Murray tcpd_warn("fromhost: LIST failed: %m");
532aef6930SMark Murray
542aef6930SMark Murray /*
552aef6930SMark Murray * POP stream modules except for the driver.
562aef6930SMark Murray */
572aef6930SMark Murray for (i = 0; i < num_mod - 1; i++)
582aef6930SMark Murray if (ioctl(fd, I_POP, 0) < 0)
592aef6930SMark Murray tcpd_warn("fromhost: POP %s: %m", mod_buffer[i].l_name);
602aef6930SMark Murray
612aef6930SMark Murray /*
622aef6930SMark Murray * PUSH timod so that host address ioctls can be executed.
632aef6930SMark Murray */
642aef6930SMark Murray if (ioctl(fd, I_PUSH, "timod") < 0)
652aef6930SMark Murray tcpd_warn("fromhost: PUSH timod: %m");
662aef6930SMark Murray tli_host(request);
672aef6930SMark Murray
682aef6930SMark Murray /*
692aef6930SMark Murray * POP timod, we're done with it now.
702aef6930SMark Murray */
712aef6930SMark Murray if (ioctl(fd, I_POP, 0) < 0)
722aef6930SMark Murray tcpd_warn("fromhost: POP timod: %m");
732aef6930SMark Murray
742aef6930SMark Murray /*
752aef6930SMark Murray * Restore stream modules.
762aef6930SMark Murray */
772aef6930SMark Murray for (i = num_mod - 2; i >= 0; i--)
782aef6930SMark Murray if (ioctl(fd, I_PUSH, mod_buffer[i].l_name) < 0)
792aef6930SMark Murray tcpd_warn("fromhost: PUSH %s: %m", mod_buffer[i].l_name);
802aef6930SMark Murray }
81