home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / CONFIG.C < prev    next >
C/C++ Source or Header  |  1993-07-16  |  21KB  |  892 lines

  1. /* A collection of stuff heavily dependent on the configuration info
  2.  * in config.h. The idea is that configuration-dependent tables should
  3.  * be located here to avoid having to pepper lots of .c files with #ifdefs,
  4.  * requiring them to include config.h and be recompiled each time config.h
  5.  * is modified.
  6.  *
  7.  * Copyright 1991 Phil Karn, KA9Q
  8.  */
  9.  
  10. /****************************************************************************
  11. *    $Id: config.c 1.6 93/07/16 11:43:23 ROOT_DOS Exp $
  12. *    09 Aug 92    1.2        GT    Experiment with inline dialer.                    *
  13. *    13 Aug 92    1.3        JB    Pegasus mail stuff.                                *
  14. *    24 Aug 92    1.4        GT    Time commands.                                    *
  15. *    08 May 93    1.5        GT    Fix warnings.                                    *
  16. ****************************************************************************/
  17.  
  18. #include <stdio.h>
  19. #include <dos.h>
  20. #include "global.h"
  21. #include "config.h"
  22. #include "mbuf.h"
  23. #include "timer.h"
  24. #include "proc.h"
  25. #include "iface.h"
  26. #include "ip.h"
  27. #include "tcp.h"
  28. #include "udp.h"
  29. #ifdef    ARCNET
  30. #include "arcnet.h"
  31. #endif
  32. #include "lapb.h"
  33. #include "ax25.h"
  34. #include "enet.h"
  35. #include "kiss.h"
  36. #include "nr4.h"
  37. #include "netrom.h"
  38. #include "pktdrvr.h"
  39. #include "ppp.h"
  40. #include "slip.h"
  41. #include "arp.h"
  42. #include "icmp.h"
  43. #include "hardware.h"    /***/
  44. #include "usock.h"
  45. #include "cmdparse.h"
  46. #include "commands.h"
  47. #include "mailbox.h"
  48. #include "ax25mail.h"
  49. #include "nr4mail.h"
  50. #include "tipmail.h"
  51. #include "daemon.h"
  52. #include "bootp.h"
  53.  
  54. int dotest __ARGS((int argc,char *argv[],void *p));    /**/
  55. static int dostart __ARGS((int argc,char *argv[],void *p));
  56. static int dostop __ARGS((int argc,char *argv[],void *p));
  57.  
  58. #ifdef    AX25
  59. static void axip __ARGS((struct iface *iface,struct ax25_cb *axp,char *src,
  60.   char *dest,struct mbuf *bp,int mcast));
  61. static void axarp __ARGS((struct iface *iface,struct ax25_cb *axp,char *src,
  62.   char *dest,struct mbuf *bp,int mcast));
  63. static void axnr __ARGS((struct iface *iface,struct ax25_cb *axp,char *src,
  64.   char *dest,struct mbuf *bp,int mcast));
  65. #endif
  66.  
  67. struct mbuf *Hopper;
  68. unsigned Nsessions = NSESSIONS;
  69.  
  70. /* Free memory threshold, below which things start to happen to conserve
  71.  * memory, like garbage collection, source quenching and refusing connects
  72.  */
  73. int32 Memthresh = MTHRESH;
  74.  
  75. int Nibufs = NIBUFS;        /* Number of interrupt buffers */
  76. unsigned Ibufsize = IBUFSIZE;    /* Size of each interrupt buffer */
  77.  
  78. /* Transport protocols atop IP */
  79. struct iplink Iplink[] = 
  80. {
  81.     { TCP_PTCL,    tcp_input },
  82.     { UDP_PTCL,    udp_input },
  83.     { ICMP_PTCL,    icmp_input },
  84.     { IP_PTCL,    ipip_recv },
  85.     { 0,        0 }
  86. }
  87. ;
  88.  
  89. /* Transport protocols atop ICMP */
  90. struct icmplink Icmplink[] = 
  91. {
  92.     { TCP_PTCL,    tcp_icmp },
  93.     { 0,        0 }
  94. }
  95. ;
  96.  
  97. /* ARP protocol linkages */
  98. struct arp_type Arp_type[NHWTYPES] = 
  99. {
  100. #ifdef    NETROM
  101.     { AXALEN, 0, 0, 0, NULLCHAR, pax25, setcall },    /* ARP_NETROM */
  102. #else
  103.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },
  104. #endif
  105.  
  106. #ifdef    ETHER
  107.     { EADDR_LEN,IP_TYPE,ARP_TYPE,1,Ether_bdcst,pether,gether }, /* ARP_ETHER */
  108. #else
  109.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },
  110. #endif
  111.  
  112.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_EETHER */
  113.  
  114. #ifdef    AX25
  115.     { AXALEN, PID_IP, PID_ARP, 10, Ax25multi[0], pax25, setcall },
  116. #else
  117.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_AX25 */
  118. #endif
  119.  
  120.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_PRONET */
  121.  
  122.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_CHAOS */
  123.  
  124.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_IEEE802 */
  125.  
  126. #ifdef    ARCNET
  127.     { AADDR_LEN, ARC_IP, ARC_ARP, 1, ARC_bdcst, parc, garc }, /* ARP_ARCNET */
  128. #else
  129.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },
  130. #endif
  131.  
  132.     { 0, 0, 0, 0, NULLCHAR,NULL,NULL },            /* ARP_APPLETALK */
  133. }
  134. ;
  135.  
  136. #ifdef    AX25
  137. /* Linkage to network protocols atop ax25 */
  138. struct axlink Axlink[] = 
  139. {
  140.     { PID_IP,        axip },
  141.     { PID_ARP,    axarp },
  142. #    ifdef    NETROM
  143.     { PID_NETROM,    axnr },
  144. #    endif
  145.     { PID_NO_L3,    axnl3 },
  146.     { 0,        NULL },
  147. }
  148. ;
  149. #endif
  150.  
  151. #ifdef    MAILBOX
  152. void (*Listusers) __ARGS((int s)) = listusers;
  153. #else
  154. void (*Listusers) __ARGS((int s)) = NULL;
  155. #endif
  156.  
  157. #ifndef    BOOTP
  158. int WantBootp = 0;
  159.  
  160. int
  161. bootp_validPacket(ip,bpp)
  162. struct ip *ip;
  163. struct mbuf **bpp;
  164. {
  165.     return 0;
  166. }
  167. #endif
  168.  
  169. /* daemons to be run at startup time */
  170. struct daemon Daemons[] = 
  171. {
  172.     { "killer",    512,    killer },
  173.     { "gcollect",    256,    gcollect },
  174.     { "timer",    1024,    timerproc },
  175.     { "network",    1536,    network },
  176.     { "keyboard",    250,    keyboard },
  177.     { NULLCHAR,    0,    NULLVFP }
  178. }
  179. ;
  180.  
  181. struct iftype Iftypes[] = 
  182. {
  183.     /* This entry must be first, since Loopback refers to it */
  184.     { "None",        NULL,        NULL,        NULL,
  185.       NULL,        CL_NONE,    0 },
  186.  
  187. #ifdef    AX25
  188.     { "AX25",        ax_send,    ax_output,    pax25,
  189.       setcall,    CL_AX25,    AXALEN },
  190. #endif
  191.  
  192. #ifdef    SLIP
  193.     { "SLIP",        slip_send,    NULL,        NULL,
  194.       NULL,        CL_NONE,    0 },
  195. #endif
  196.  
  197. #ifdef    ETHER
  198.     /* Note: NULL is specified for the scan function even though
  199.      * gether() exists because the packet drivers don't support
  200.      * address setting.
  201.      */
  202.     { "Ethernet",    enet_send,    enet_output,    pether,
  203.       NULL,        CL_ETHERNET,    EADDR_LEN },
  204. #endif
  205.  
  206. #ifdef    NETROM
  207.     { "NETROM",    nr_send,    NULL,        pax25,
  208.       setcall,    CL_NETROM,    AXALEN },
  209. #endif
  210.  
  211. #ifdef    SLFP
  212.     { "SLFP",        pk_send,    NULL,        NULL,
  213.       NULL,        CL_NONE,    0 },
  214. #endif
  215.  
  216. #ifdef    PPP
  217.     { "PPP",        ppp_send,    ppp_output,    NULL,
  218.       NULL,        CL_PPP,    0 },
  219. #endif
  220.  
  221.     { NULLCHAR }
  222. }
  223. ;
  224.  
  225. /* Command lookup and branch tables */
  226. struct cmds far Cmds[] = 
  227. {
  228.     /* The "go" command must be first */
  229.     { "",        go,        0, 0, NULLCHAR },
  230. #ifndef    AMIGA
  231.     { "!",        doshell,    0, 0, NULLCHAR },
  232. #endif
  233.     { "abort",    doabort,    0, 0, NULLCHAR },
  234. #ifdef    AMIGA
  235.     { "amiga",    doamiga,    0, 0, NULLCHAR },
  236. #endif
  237. #if    (defined(MAC) && defined(APPLETALK))
  238.     { "applestat",    doatstat,    0,    0, NULLCHAR },
  239. #endif
  240. #if    (defined(AX25) || defined(ETHER) || defined(APPLETALK))
  241.     { "arp",        doarp,        0, 0, NULLCHAR },
  242. #endif
  243. #ifdef    ASY
  244.     { "asystat",    doasystat,    0, 0, NULLCHAR },
  245. #endif
  246. #ifdef ATCMD
  247.     { "at",       doat,       0, 0, NULLCHAR },
  248. #endif
  249.     { "attach",    doattach,    0, 2,
  250.     "attach <hardware> <hw specific options>" },
  251. #ifdef    AX25
  252.     { "ax25",        doax25,        0, 0, NULLCHAR },
  253. #endif
  254. #ifdef    BOOTP
  255.     { "bootp",    dobootp,    0, 0, NULLCHAR },
  256.     { "bootpd",    bootpdcmd,    0, 0, NULLCHAR },
  257. #endif
  258. /* This one is out of alpabetical order to allow abbreviation to "c" */
  259. #ifdef    AX25
  260.     { "connect",    doconnect,    1024, 3,
  261.     "connect <interface> <callsign>" },
  262. #endif
  263. #if    !defined(UNIX) && !defined(AMIGA)
  264.     { "cd",        docd,        0, 0, NULLCHAR },
  265. #endif
  266.     { "close",    doclose,    0, 0, NULLCHAR },
  267. /* This one is out of alpabetical order to allow abbreviation to "d" */
  268.     { "disconnect",    doclose,    0, 0, NULLCHAR },
  269.     { "delete",    dodelete,    0, 2, "delete <file>" },
  270.     { "detach",    dodetach,    0, 2, "detach <interface>" },
  271. #ifdef    DIALER
  272.     { "dialer",    dodialer,    512, 2,
  273.     "dialer <iface> [<file> [<seconds> [<pings> [<hostid>]]]]" },
  274. #endif
  275. #ifndef    AMIGA
  276.     { "dir",        dodir,        512, 0, NULLCHAR }, /* note sequence */
  277. #endif
  278.     { "domain",    dodomain,    0, 0, NULLCHAR },
  279. #ifdef    DRSI
  280.     { "drsistat",    dodrstat,    0, 0, NULLCHAR },
  281. #endif
  282. #ifdef    EAGLE
  283.     { "eaglestat",    doegstat,    0, 0, NULLCHAR },
  284. #endif
  285.     { "echo",        doecho,        0, 0, NULLCHAR },
  286.     { "eol",        doeol,        0, 0, NULLCHAR },
  287.     { "escape",    doescape,    0, 0, NULLCHAR },
  288. #ifdef    PC_EC
  289.     { "etherstat",    doetherstat,    0, 0, NULLCHAR },
  290. #endif
  291.     { "exit",        doexit,        0, 0, NULLCHAR },
  292.     { "finger",    dofinger,    1024, 2, "finger name@host" },
  293. #ifdef ALLCMD
  294.     { "fkey",        dofkey,        0, 0, NULLCHAR },
  295. #endif
  296.     { "ftp",        doftp,        2048, 2, "ftp <address>" },
  297. #ifdef HAPN
  298.     { "hapnstat",    dohapnstat,    0, 0, NULLCHAR },
  299. #endif
  300.     { "help",        dohelp,        0, 0, NULLCHAR },
  301. #ifdef    HOPCHECK
  302.     { "hop",        dohop,        0, 0, NULLCHAR },
  303. #endif
  304.     { "hostname",    dohostname,    0, 0, NULLCHAR },
  305. #ifdef    HS
  306.     { "hs",        dohs,        0, 0, NULLCHAR },
  307. #endif
  308.     { "icmp",        doicmp,        0, 0, NULLCHAR },
  309.     { "ifconfig",    doifconfig,    0, 0, NULLCHAR },
  310. #ifdef    DIALER
  311.     { "inline",    do_inline,    0, 0, NULLCHAR },
  312. #endif
  313.     { "ip",        doip,        0, 0, NULLCHAR },
  314. #ifdef    MSDOS
  315.     { "isat",        doisat,        0, 0, NULLCHAR },
  316. #endif
  317.     { "kick",        dokick,        0, 0, NULLCHAR },
  318.     { "log",        dolog,        0, 0, NULLCHAR },
  319. #ifdef    MAILBOX
  320.     { "mbox",        dombox,        0, 0, NULLCHAR },
  321. #endif
  322. #ifndef    UNIX
  323.     { "memory",    domem,        0, 0, NULLCHAR },
  324. #endif
  325.     { "mkdir",    domkd,        0, 2, "mkdir <directory>" },
  326. #ifdef    AX25
  327.     { "mode",        domode,        0, 2, "mode <interface>" },
  328. #endif
  329.     { "more",        domore,        512, 2, "more <filename>" },
  330. #ifdef MULTITASK
  331.     { "multitask",    dobackg,    0, 0, NULLCHAR },
  332. #endif
  333. #ifdef    NETROM
  334.     { "netrom",    donetrom,    0, 0, NULLCHAR },
  335. #endif    /* NETROM */
  336. #ifdef    NNTP
  337.     { "nntp",        donntp,        0, 0, NULLCHAR },
  338. #endif    /* NNTP */
  339.     { "novell",    donovell,    0, 0, NULLCHAR },
  340. #ifdef    NRS
  341.     { "nrstat",    donrstat,    0, 0, NULLCHAR },
  342. #endif    /* NRS */
  343.     { "param",    doparam,    0, 2, "param <interface>" },
  344.     { "ping",        doping,        512, 2,
  345.     "ping <hostid> [<length> [<interval> [incflag]]]" },
  346. #ifdef    PI
  347.     { "pistatus",    dopistat,    0, 0, NULLCHAR },
  348. #endif
  349. #ifdef POP
  350.     { "pop",        dopop,        0, 0, NULLCHAR },
  351. #endif
  352. #ifdef PPP
  353.     { "ppp",        doppp_commands,    0, 0, NULLCHAR },
  354. #endif
  355.     { "ps",        ps,        0, 0, NULLCHAR },
  356. #if    !defined(UNIX) && !defined(AMIGA)
  357.     { "pwd",        docd,        0, 0, NULLCHAR },
  358. #endif
  359.     { "record",    dorecord,    0, 0, NULLCHAR },
  360.     { "remote",    doremote,    0, 3, "remote [-p port] [-k key] [-a kickaddr] <address> exit|reset|kick" },
  361.     { "rename",    dorename,    0, 3, "rename <oldfile> <newfile>" },
  362.     { "reset",    doreset,    0, 0, NULLCHAR },
  363. #ifdef    RIP
  364.     { "rip",        dorip,        0, 0, NULLCHAR },
  365. #endif
  366.     { "rsh",        dorsh,        2048, 3, "rsh <address> <command>" },
  367.     { "rlogin",    dorlogin,    2048, 2, "rlogin <address>" },
  368.     { "rmdir",    dormd,        0, 2, "rmdir <directory>" },
  369.     { "route",    doroute,    0, 0, NULLCHAR },
  370.     { "session",    dosession,    0, 0, NULLCHAR },
  371. #ifdef    SCC
  372.     { "sccstat",    dosccstat,    0, 0, NULLCHAR },
  373. #endif
  374. #if    !defined(AMIGA)
  375.     { "shell",    doshell,    0, 0, NULLCHAR },
  376. #endif
  377.     { "smtp",        dosmtp,        0, 0, NULLCHAR },
  378.     { "socket",    dosock,        0, 0, NULLCHAR },
  379.     { "source",    dosource,    0, 2, "source <filename>" },
  380.     { "sourceb",    dosource,    1024, 2, "source <filename>" },
  381. #ifdef    SERVERS
  382.     { "start",    dostart,    0, 2, "start <servername>" },
  383.     { "stop",        dostop,        0, 2, "stop <servername>" },
  384. #endif
  385.     { "tcp",        dotcp,        0, 0, NULLCHAR },
  386.     { "telnet",    dotelnet,    1024, 2, "telnet <address>" },
  387.     { "test",        dotest,        0, 0, NULLCHAR },
  388.     { "time",        do_time,    0,    1,    "time <server | read | set>" },
  389.     { "tip",        dotip,        256, 2, "tip <iface>" },
  390. #ifdef    TRACE
  391.     { "trace",    dotrace,    0, 0, NULLCHAR },
  392. #endif
  393.     { "udp",        doudp,        0, 0, NULLCHAR },
  394.     { "upload",    doupload,    0, 0, NULLCHAR },
  395. #ifdef    MSDOS
  396.     { "watch",    doswatch,    0, 0, NULLCHAR },
  397. #endif
  398.     { "?",        dohelp,        0, 0, NULLCHAR },
  399.     { NULLCHAR,    NULLFP,        0, 0,
  400.     "Unknown command; type \"?\" for list" },
  401. }
  402. ;
  403.  
  404. /* List of supported hardware devices */
  405. struct cmds Attab[] = 
  406. {
  407. #ifdef    PC_EC
  408.     /* 3-Com Ethernet interface */
  409.     { "3c500", ec_attach, 0, 7,
  410.     "attach 3c500 <address> <vector> arpa <label> <buffers> <mtu> [ip_addr]" },
  411. #endif
  412. #ifdef    ASY
  413.     /* Ordinary PC asynchronous adaptor */
  414.     { "asy", asy_attach, 0, 8,
  415. #    ifndef    AMIGA
  416.     "attach asy <address> <vector> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]" },
  417. #    else
  418.     "attach asy <driver> <unit> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]" },
  419. #    endif    /* AMIGA */
  420. #endif    /* ASY */
  421. #ifdef    PC100
  422.     /* PACCOMM PC-100 8530 HDLC adaptor */
  423.     { "pc100", pc_attach, 0, 8,
  424.     "attach pc100 <address> <vector> ax25 <label> <buffers>\
  425.  <mtu> <speed> [ip_addra] [ip_addrb]" },
  426. #endif
  427. #ifdef    DRSI
  428.     /* DRSI PCPA card in low speed mode */
  429.     { "drsi", dr_attach, 0, 8,
  430.     "attach drsi <address> <vector> ax25 <label> <bufsize> <mtu>\
  431. <chan a speed> <chan b speed> [ip addr a] [ip addr b]" },
  432. #endif
  433. #ifdef    EAGLE
  434.     /* EAGLE RS-232C 8530 HDLC adaptor */
  435.     { "eagle", eg_attach, 0, 8,
  436.     "attach eagle <address> <vector> ax25 <label> <buffers>\
  437.  <mtu> <speed> [ip_addra] [ip_addrb]" },
  438. #endif
  439. #ifdef    PI
  440.     /* PI 8530 HDLC adaptor */
  441.     { "pi", pi_attach, 0, 8,
  442.     "attach pi <address> <vector> <dmachannel> ax25 <label> <buffers>\
  443.  <mtu> <speed> [ip_addra] [ip_addrb]" },
  444. #endif
  445. #ifdef    HAPN
  446.     /* Hamilton Area Packet Radio (HAPN) 8273 HDLC adaptor */
  447.     { "hapn", hapn_attach, 0, 8,
  448.     "attach hapn <address> <vector> ax25 <label> <rx bufsize>\
  449.  <mtu> csma|full [ip_addr]" },
  450. #endif
  451. #ifdef    APPLETALK
  452.     /* Macintosh AppleTalk */
  453.     { "0", at_attach, 0, 7,
  454.     "attach 0 <protocol type> <device> arpa <label> <rx bufsize> <mtu> [ip_addr]" },
  455. #endif
  456. #ifdef NETROM
  457.     /* fake netrom interface */
  458.     { "netrom", nr_attach, 0, 1,
  459.     "attach netrom [ip_addr]" },
  460. #endif
  461. #ifdef    PACKET
  462.     /* FTP Software's packet driver spec */
  463.     { "packet", pk_attach, 0, 4,
  464.     "attach packet <int#> <label> <buffers> <mtu> [ip_addr]" },
  465. #endif
  466. #ifdef    HS
  467.     /* Special high speed driver for DRSI PCPA or Eagle cards */
  468.     { "hs", hs_attach, 0, 7,
  469.     "attach hs <address> <vector> ax25 <label> <buffers> <mtu>\
  470.  <txdelay> <persistence> [ip_addra] [ip_addrb]" },
  471. #endif
  472. #ifdef SCC
  473.     { "scc", scc_attach, 0, 7,
  474.     "attach scc <devices> init <addr> <spacing> <Aoff> <Boff> <Dataoff>\n"
  475.     "   <intack> <vec> [p]<clock> [hdwe] [param]\n"
  476.     "attach scc <chan> slip|kiss|nrs|ax25 <label> <mtu> <speed> <bufsize> [call] " },
  477. #endif
  478.     { NULLCHAR },
  479. }
  480. ;
  481.  
  482. /* Functions to be called on each clock tick */
  483. void (*Cfunc[]) __ARGS((void)) = 
  484. {
  485.     pctick,    /* Call PC-specific stuff to keep time */
  486.     kbint,    /* Necessary because there's no hardware keyboard interrupt */
  487.     refiq,    /* Replenish interrupt pool */
  488. #ifdef    ASY
  489.     asytimer,
  490. #endif
  491. #ifdef    SCC
  492.     scctimer,
  493. #endif
  494.     NULL,
  495. }
  496. ;
  497.  
  498. /* Entry points for garbage collection */
  499. void (*Gcollect[])() = 
  500. {
  501.     tcp_garbage,
  502.     ip_garbage,
  503.     udp_garbage,
  504.     st_garbage,
  505. #ifdef    AX25
  506.     lapb_garbage,
  507. #endif
  508. #ifdef    NETROM
  509.     nr_garbage,
  510. #endif
  511.     NULL
  512. }
  513. ;
  514.  
  515. /* Functions to be called at shutdown */
  516. void (*Shutdown[])() = 
  517. {
  518. #ifdef    SCC
  519.     sccstop,
  520. #endif
  521.     uchtimer,    /* Unlink timer handler from timer chain */
  522.     NULLVFP,
  523. }
  524. ;
  525.  
  526. /* Packet tracing stuff */
  527. #ifdef    TRACE
  528. #include "trace.h"
  529.  
  530. /* Protocol tracing function pointers. Matches list of class definitions
  531.  * in pktdrvr.h.
  532.  */
  533. struct trace Tracef[] = 
  534. {
  535.     { NULLFP,        ip_dump },    /* CL_NONE */
  536.  
  537. #    ifdef    ETHER                /* CL_ETHERNET */
  538.     { ether_forus,    ether_dump },
  539. #    else
  540.     { NULLFP,        NULLVFP },
  541. #    endif    /* ETHER */
  542.  
  543.     { NULLFP,        NULLVFP },    /* CL_PRONET_10 */
  544.     { NULLFP,        NULLVFP },    /* CL_IEEE8025 */
  545.     { NULLFP,        NULLVFP },    /* CL_OMNINET */
  546.  
  547. #    ifdef    APPLETALK
  548.     { at_forus,    at_dump },    /* CL_APPLETALK */
  549. #    else
  550.     { NULLFP,        NULLVFP },
  551. #    endif    /* APPLETALK */
  552.  
  553. #    ifdef VJCOMPRESS
  554.     { NULLFP,        sl_dump },    /* CL_SERIAL_LINE */
  555. #    else
  556.     { NULLFP,        ip_dump },    /* CL_SERIAL_LINE */
  557. #    endif
  558.     { NULLFP,        NULLVFP },    /* CL_STARLAN */
  559.  
  560. #    ifdef    ARCNET
  561.     { arc_forus,    arc_dump },    /* CL_ARCNET */
  562. #    else
  563.     { NULLFP,        NULLVFP },
  564. #    endif    /* ARCNET */
  565.  
  566. #    ifdef    AX25
  567.     { ax_forus,    ax25_dump },    /* CL_AX25 */
  568. #    else
  569.     { NULLFP,        NULLVFP },
  570. #    endif    /* AX25 */
  571.  
  572. #    ifdef    KISS                /* CL_KISS */
  573.     { ki_forus,    ki_dump },
  574. #    else
  575.     { NULLFP,        NULLVFP },
  576. #    endif    /* KISS */
  577.  
  578.     { NULLFP,        NULLVFP },    /* CL_IEEE8023 */
  579.     { NULLFP,        NULLVFP },    /* CL_FDDI */
  580.     { NULLFP,        NULLVFP },    /* CL_INTERNET_X25 */
  581.     { NULLFP,        NULLVFP },    /* CL_LANSTAR */
  582.     { NULLFP,        ip_dump },    /* CL_SLFP */
  583.  
  584. #    ifdef    NETROM                /* CL_NETROM */
  585.     { NULLFP,        ip_dump },
  586. #    else
  587.     { NULLFP,        NULLVFP },
  588. #    endif
  589.  
  590. #    ifdef PPP
  591.     { NULLFP,        ppp_dump },    /* CL_PPP */
  592. #    else
  593.     { NULLFP,        NULLVFP },
  594. #    endif /* PPP */
  595. }
  596. ;
  597.  
  598. #else    /* TRACE */
  599.  
  600. /* Stub for packet dump function */
  601. void
  602. dump(iface,direction,type,bp)
  603. struct iface *iface;
  604. int direction;
  605. unsigned type;
  606. struct mbuf *bp;
  607. {
  608. }
  609. void
  610. raw_dump(iface,direction,bp)
  611. struct iface *iface;
  612. int direction;
  613. struct mbuf *bp;
  614. {
  615. }
  616.  
  617. #endif    /* TRACE */
  618.  
  619.  
  620. #ifdef    AX25
  621. /* Hooks for passing incoming AX.25 data frames to network protocols */
  622. static void
  623. axip(iface,axp,src,dest,bp,mcast)
  624. struct iface *iface;
  625. struct ax25_cb *axp;
  626. char *src;
  627. char *dest;
  628. struct mbuf *bp;
  629. int mcast;
  630. {
  631.     (void)ip_route(iface,bp,mcast);
  632. }
  633.  
  634. static void
  635. axarp(iface,axp,src,dest,bp,mcast)
  636. struct iface *iface;
  637. struct ax25_cb *axp;
  638. char *src;
  639. char *dest;
  640. struct mbuf *bp;
  641. int mcast;
  642. {
  643.     (void)arp_input(iface,bp);
  644. }
  645.  
  646. #    ifdef    NETROM
  647. static void
  648. axnr(iface,axp,src,dest,bp,mcast)
  649. struct iface *iface;
  650. struct ax25_cb *axp;
  651. char *src;
  652. char *dest;
  653. struct mbuf *bp;
  654. int mcast;
  655. {
  656.     if(!mcast)
  657.         nr_route(bp,axp);
  658.     else
  659.         nr_nodercv(iface,src,bp);
  660. }
  661.  
  662. #    endif    /* NETROM */
  663. #endif    /* AX25 */
  664.  
  665. #ifndef    RIP
  666. /* Stub for routing timeout when RIP is not configured -- just remove entry */
  667. void
  668. rt_timeout(s)
  669. void *s;
  670. {
  671.     struct route *stale = (struct route *)s;
  672.  
  673.     rt_drop(stale->target,stale->bits);
  674. }
  675. #endif
  676.  
  677. #ifdef    SERVERS
  678. /* "start" and "stop" subcommands */
  679. static struct cmds Startcmds[] = 
  680. {
  681. #    if    defined(AX25) && defined(MAILBOX)
  682.     { "ax25",        ax25start,    256, 0, NULLCHAR },
  683. #    endif
  684.     { "discard",    dis1,        256, 0, NULLCHAR },
  685.     { "echo",        echo1,        256, 0, NULLCHAR },
  686.     { "finger",    finstart,    256, 0, NULLCHAR },
  687.     { "ftp",        ftpstart,    256, 0, NULLCHAR },
  688. #    if    defined(NETROM) && defined(MAILBOX)
  689.     { "netrom",    nr4start,    256, 0, NULLCHAR },
  690. #    endif
  691. #    ifdef POP
  692.     { "pop",        pop1,        256, 0, NULLCHAR },
  693. #    endif
  694. #    ifdef    RIP
  695.     { "rip",        doripinit,    0,   0, NULLCHAR },
  696. #    endif
  697.     { "smtp",        smtp1,        256, 0, NULLCHAR },
  698. #    if    defined(MAILBOX)
  699.     { "telnet",    telnet1,    256, 0, NULLCHAR },
  700.     { "time",        timestart,    256, 0, NULLCHAR },
  701.     { "tip",        tipstart,    256, 2, "start tip <interface>" },
  702. #    endif
  703.     { "ttylink",    ttylstart,    256, 0, NULLCHAR },
  704.     { "remote",    rem1,        768, 0, NULLCHAR },
  705.     { NULLCHAR },
  706. }
  707. ;
  708. static struct cmds Stopcmds[] = 
  709. {
  710. #    if    defined(AX25) && defined(MAILBOX)
  711.     { "ax25",        ax250,        0, 0, NULLCHAR },
  712. #    endif
  713.     { "discard",    dis0,        0, 0, NULLCHAR },
  714.     { "echo",        echo0,        0, 0, NULLCHAR },
  715.     { "finger",    fin0,        0, 0, NULLCHAR },
  716.     { "ftp",        ftp0,        0, 0, NULLCHAR },
  717. #    if    defined(NETROM) && defined(MAILBOX)
  718.     { "netrom",    nr40,        0, 0, NULLCHAR },
  719. #    endif
  720. #    ifdef    POP
  721.     { "pop",        pop0,        0, 0, NULLCHAR },
  722. #    endif
  723. #    ifdef    RIP
  724.     { "rip",        doripstop,    0, 0, NULLCHAR },
  725. #    endif
  726.     { "smtp",        smtp0,        0, 0, NULLCHAR },
  727. #    ifdef    MAILBOX
  728.     { "telnet",    telnet0,    0, 0, NULLCHAR },
  729.     { "time",        time0,        0, 0, NULLCHAR },
  730.     { "tip",        tip0,        0, 2, "stop tip <interface>" },
  731. #    endif
  732.     { "ttylink",    ttyl0,        0, 0, NULLCHAR },
  733.     { "remote",    rem0,        0, 0, NULLCHAR },
  734.     { NULLCHAR },
  735.  
  736. }
  737. ;
  738. static int
  739. dostart(argc,argv,p)
  740. int argc;
  741. char *argv[];
  742. void *p;
  743. {
  744.     return subcmd(Startcmds,argc,argv,p);
  745. }
  746. static int
  747. dostop(argc,argv,p)
  748. int argc;
  749. char *argv[];
  750. void *p;
  751. {
  752.     return subcmd(Stopcmds,argc,argv,p);
  753. }
  754. #endif    /* SERVERS */
  755.  
  756. /* Various configuration-dependent functions */
  757.  
  758. /* put mbuf into Hopper for network task
  759.  * returns 0 if OK
  760.  */
  761. int
  762. net_route(ifp, type, bp)
  763. struct iface *ifp;
  764. int type;
  765. struct mbuf *bp;
  766. {
  767.     struct mbuf *nbp;
  768.     struct phdr phdr;
  769.  
  770.     phdr.iface = ifp;
  771.     phdr.type = type;
  772.  
  773.     if ((nbp = pushdown(bp,sizeof(phdr))) == NULLBUF )
  774.     {
  775.         return -1;
  776.     }
  777.     memcpy( &nbp->data[0],(char *)&phdr,sizeof(phdr));
  778.     enqueue(&Hopper,nbp);
  779.     /* Especially on slow machines, serial I/O can be quite
  780.      * compute intensive, so release the machine before we
  781.      * do the next packet.  This will allow this packet to
  782.      * go on toward its ultimate destination. [Karn]
  783.      */
  784.     pwait(NULL);
  785.     return 0;
  786. }
  787.  
  788.  
  789. /* Process packets in the Hopper */
  790. static void
  791. network(i,v1,v2)
  792. int i;
  793. void *v1;
  794. void *v2;
  795. {
  796.     struct mbuf *bp;
  797.     struct phdr phdr;
  798.     char i_state;
  799.  
  800. loop:
  801.     refiq();    /* Replenish interrupt buffer pool */
  802.  
  803.     i_state = dirps();
  804.     while(Hopper == NULLBUF)
  805.         pwait(&Hopper);
  806.     restore(i_state);
  807.  
  808.     /* Process the input packet */
  809.     bp = dequeue(&Hopper);
  810.     pullup(&bp,(char *)&phdr,sizeof(phdr));
  811.     if(phdr.iface != NULLIF)
  812.     {
  813.         phdr.iface->rawrecvcnt++;
  814.         phdr.iface->lastrecv = secclock();
  815.     }
  816.     dump(phdr.iface,IF_TRACE_IN,phdr.type,bp);
  817.     switch(phdr.type)
  818.     {
  819. #ifdef    KISS
  820.     case CL_KISS:
  821.         kiss_recv(phdr.iface,bp);
  822.         break;
  823. #endif
  824. #ifdef    AX25
  825.     case CL_AX25:
  826.         ax_recv(phdr.iface,bp);
  827.         break;
  828. #endif
  829. #ifdef    ETHER
  830.     case CL_ETHERNET:
  831.         eproc(phdr.iface,bp);
  832.         break;
  833. #endif
  834. #ifdef ARCNET
  835.     case CL_ARCNET:
  836.         aproc(phdr.iface,bp);
  837.         break;
  838. #endif
  839. #ifdef PPP
  840.     case CL_PPP:
  841.         ppp_proc(phdr.iface,bp);
  842.         break;
  843. #endif
  844.         /* These types have no link layer protocol at the point when they're
  845.          * put in the hopper, so they can be handed directly to IP. The
  846.          * separate types are just for user convenience when running the
  847.          * "iface" command.
  848.          */
  849.     case CL_NONE:
  850.     case CL_SERIAL_LINE:
  851.     case CL_SLFP:
  852.         ip_route(phdr.iface,bp,0);
  853.         break;
  854.     default:
  855.         free_p(bp);
  856.         break;
  857.     }
  858.     /* Let everything else run - this keeps the system from wedging
  859.      * when we're hit by a big burst of packets
  860.      */
  861.     pwait(NULL);
  862.     goto loop;
  863. }
  864.  
  865. int
  866. dotest(argc,argv,p)
  867. int argc;
  868. char *argv[];
  869. void *p;
  870. {
  871.     long i;
  872.     int32 oldtime = 0;
  873.     int32 newtime;
  874.  
  875.     Current->flowmode = 1;
  876.     for(i=0L; i<40000L; i++)
  877.     {
  878.         newtime = msclock();
  879.         if(newtime < oldtime)
  880.         {
  881.             tprintf("Clock slip %ld: %ld - %ld = %ld\n",i,
  882.               newtime,oldtime,newtime-oldtime);
  883.         }
  884.         else
  885.             oldtime = newtime;
  886.     }
  887.     pwait(NULL);
  888.     Current->flowmode = 0;
  889.     return 0;
  890. }
  891.  
  892.