home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / misc / tcpipsrc / config.c < prev    next >
C/C++ Source or Header  |  1991-01-31  |  18KB  |  766 lines

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