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