home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / p / pcrte224.zip / SOURCE.ZIP / CONFIG.INC < prev    next >
Text File  |  1992-06-09  |  16KB  |  499 lines

  1. ;;*****************************************************************************
  2. ;;                      config.inc    config.inc
  3. ;;*****************************************************************************
  4. ;;
  5. ;;  Copyright (C) 1989 Northwestern University, Vance Morrison
  6. ;;
  7. ;;
  8. ;; Permission to view, compile, and modify for LOCAL (intra-organization) 
  9. ;; USE ONLY is hereby granted, provided that this copyright and permission 
  10. ;; notice appear on all copies.  Any other use by permission only.
  11. ;;
  12. ;; Northwestern University makes no representations about the suitability 
  13. ;; of this software for any purpose.  It is provided "as is" without expressed 
  14. ;; or implied warranty.  See the copywrite notice file for complete details.
  15. ;;
  16. ;;******************************************************************************
  17. ;;
  18. ;; AUTHOR:  Vance Morrison
  19. ;; DATE  :  12/88
  20. ;; ADDRESS: morrison@accuvax.nwu.edu
  21. ;;
  22. ;;*****************************************************************************
  23.  
  24.  
  25.  
  26. ;; types of interfaces
  27. CONF_GENERIC    =   1       ;; interface that requires no special config data
  28. CONF_LOCALTALK  =   2       ;; Special localtalk extentions (zone name etc)
  29. CONF_SLIP       =   3       ;; Serial line (SLIP interface) 
  30.  
  31. CONF_ROUTE      =   10      ;; static route configuration data
  32. CONF_BOOTP      =   20      ;; Bootp configration data (forwarding host)
  33. CONF_ADMIN      =   21      ;; administrative data (admin host)
  34. CONF_SYSLOG     =   22      ;; host to send syslog messages to
  35.  
  36.  
  37. ;;************************************************************************
  38. ;; CONFIG reads in the configuration data from pcroute.cfg, and configures 
  39. ;; all the router objects.  If it is not successful it jumps to 'fail'.
  40. ;; 'dlog' is the Disk logger object to log errors to
  41. ;;
  42. CONFIG MACRO fail, dlog
  43.     local config_failed, open_failed, read_failed, done
  44.  
  45.     .DATA
  46.     DB 'CONFIG ->'              ;; flags so we can find this in the
  47.                                 ;; executable (read only)
  48.     irp idx,<1,2,3,4,5,6,7,8>   ;; config all the Ethernets first
  49.         CONF_DECLARE_ARP idx
  50.     endm
  51.     irp idx,<1,2,3,4,5,6,7,8>   ;; config the localtalks next
  52.         CONF_DECLARE_LOCALTALK idx
  53.     endm
  54.     irp idx,<1,2,3,4,5,6,7,8>   ;; config the SLIPs next
  55.         CONF_DECLARE_SLIP idx
  56.     endm
  57.     DB CONF_ROUTE, 1
  58.     DB CONF_BOOTP, 1
  59.     DB CONF_SYSLOG, 1
  60.     DB 0, 0, '<- CONFIG'
  61.  
  62.     config_data     DW 64 dup (0)
  63.  
  64.     .CODE
  65.     TIMER_DEFINE %mytimer
  66.  
  67.     CONFIG_OPEN_DATA open_failed, 64
  68.  
  69.     irp idx,<1,2,3,4,5,6,7,8>   ;; config the ethernets
  70.         CONF_DEFINE_OTHER idx, dlog, fail
  71.     endm
  72.  
  73.     ifdef bdg_1_declared
  74.         BDG_DEFINE 1
  75.     endif
  76.  
  77.     irp idx,<1,2,3,4,5,6,7,8>   ;; config the ethernets
  78.         CONF_DEFINE_ARP idx, dlog, fail, read_failed, config_failed
  79.     endm
  80.  
  81.     irp idx,<1,2,3,4,5,6,7,8>  ;; config the localtalks next
  82.        CONF_DEFINE_LOCALTALK idx, dlog, fail, read_failed, config_failed
  83.     endm
  84.  
  85.     irp idx,<1,2,3,4,5,6,7,8>  ;; config the SLIPs next
  86.        CONF_DEFINE_SLIP idx, dlog, fail, read_failed, config_failed
  87.     endm 
  88.  
  89.     RIP_DEFINE %myrip
  90.  
  91.     IP_DEFINE %myip
  92.  
  93.     CONF_DEFINE_ROUTE %myrip, dlog, fail, read_failed, config_failed
  94.  
  95.     ICMP_DEFINE %myicmp
  96.  
  97.     UDP_DEFINE %myudp
  98.  
  99.     CONF_DEFINE_BOOTP %mybootp, dlog, fail, read_failed, config_failed
  100.  
  101.     CONF_DEFINE_SYSLOG %mylog, dlog, fail, read_failed, config_failed
  102.     jmp done
  103.  
  104.     open_failed:
  105.         DLOG_PRINT dlog, <Could not open configuration file>
  106.         jmp fail
  107.     read_failed:
  108.         DLOG_PRINT dlog, <Error reading configuration file>
  109.         jmp fail
  110.     config_failed:
  111.         DLOG_PRINT dlog, <Configuration file corrupt or out of sync>
  112.         jmp fail
  113.     done:
  114. ENDM
  115.  
  116. ;;**************************************************************************
  117. CONF_DEFINE_OTHER MACRO name, dlog, fail
  118.     local around, pktfail
  119.     .errb <name>
  120.     .errb <dlog>
  121.     .errb <fail>
  122.  
  123.     ifdef wd_&name&_declared
  124.         WD_DEFINE name
  125.     endif
  126.  
  127.     ifdef wde_&name&_declared
  128.         WDE_DEFINE name
  129.     endif
  130.  
  131.     ifdef pkt_&name&_declared
  132.         PKT_DEFINE name, pktfail
  133.         jmp around
  134.         pktfail:
  135.             DLOG_PRINT dlog, <ERROR Packet Driver config failed (driver not installed?)>
  136.         jmp fail
  137.     around:
  138.     endif
  139.  
  140.     ifdef c507_&name&_declared
  141.         C507_DEFINE_out_AX name, fail
  142.     endif
  143.  
  144.     ifdef eth_&name&_declared
  145.         ETH_DEFINE name
  146.     endif
  147.  
  148. ENDM
  149.  
  150.  
  151.  
  152. ;;**************************************************************************
  153. ;; If the ARP DL_IP 'name' object exists, then CONF_DECLARE_ARP defines 
  154. ;; the flag that will tell the configuration program that configuration 
  155. ;; information  for a ARP DL_IP object is needed.
  156. ;;
  157. CONF_DECLARE_ARP MACRO name
  158.     .errb <name>
  159.  
  160.     ifdef arp_&name&_declared
  161.         DB CONF_GENERIC, 2          ;; type and version
  162.     endif
  163. ENDM
  164.  
  165. ;;**************************************************************************
  166. ;; If the ARP object 'name' exists CONF_DEFINE_ARP reads in the configuration
  167. ;; data and initializes the ARP object.
  168. ;;
  169. CONF_DEFINE_ARP MACRO name, dlog, fail, read_failed, config_failed
  170.     .errb <config_failed>
  171.  
  172. ifdef arp_&name&_declared
  173.  
  174.     mov DX, offset config_data
  175.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  176.     cmp word ptr config_data, (CONF_GENERIC)+256*2  ;; type generic, version 2
  177.     jnz config_failed
  178.  
  179.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 12, read_failed
  180.     DLOG_PRINT dlog, <Interface name (ethernet)>
  181.     mov AX, word ptr config_data
  182.     mov BX, word ptr config_data+2
  183.     DLOG_PRINT_INET_in_AX_BX dlog, <    Address >
  184.  
  185.     mov AX, word ptr config_data+4
  186.     mov BX, word ptr config_data+6
  187.     DLOG_PRINT_INET_in_AX_BX dlog, <    NetMask >
  188.  
  189.     mov AX, word ptr config_data+8
  190.     DLOG_PRINT_REG_HEX dlog, <    Flags     >, AX
  191.     mov word ptr dl_ip_&name&_flags, AX
  192.  
  193.     mov BX, word ptr config_data+10
  194.     DLOG_PRINT_REG_HEX dlog, <    Metric    >, BX
  195.     mov word ptr dl_ip_&name&_metric, BX
  196.  
  197.     ARP_DEFINE name, config_data, (config_data+4)
  198.  
  199.     mov SI, offset dl_ip_&name&_haddr
  200.     lodsw
  201.     xchg AH, AL
  202.     DLOG_PRINT_REG_HEX dlog, <    The Ethenet Address >, AX
  203.     lodsw
  204.     xchg AH, AL
  205.     DLOG_PRINT_REG_HEX dlog, <    The Ethenet Address >, AX
  206.     lodsw
  207.     xchg AH, AL
  208.     DLOG_PRINT_REG_HEX dlog, <    The Ethenet Address >, AX
  209. endif
  210. ENDM
  211.  
  212.  
  213. ;;**************************************************************************
  214. ;; If the ATP DL_IP 'name' object exists, then CONF_DECLARE_LOCALTALK defines 
  215. ;; the flag that will tell the configuration program that configuration 
  216. ;; information  for a localtalk DL_IP is needed.
  217. ;;
  218. CONF_DECLARE_LOCALTALK MACRO name
  219.     .errb <name>
  220.     ifdef atp_&name&_declared
  221.         DB CONF_LOCALTALK, 2            ;; type and version
  222.     endif
  223. ENDM
  224.  
  225. ;;**************************************************************************
  226. ;; If the ATP object 'name' exists CONF_DEFINE_LOCALTALK reads in the 
  227. ;; configuration data and initializes the ATP object.
  228. ;;
  229. CONF_DEFINE_LOCALTALK MACRO name, dlog, fail, read_failed, config_failed
  230.     local myfail, done
  231.     .errb <config_failed>
  232. ifdef atp_&name&_declared
  233.  
  234.     mov DX, offset config_data
  235.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 2, read_failed
  236.     cmp word ptr config_data, (CONF_LOCALTALK)+256*2  ;; type generic, version 2
  237.     jnz config_failed
  238.  
  239.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 2, read_failed
  240.     mov CX, config_data
  241.     cmp CX, 128
  242.     
  243.  
  244.     CONFIG_GET_DATA_in_CX_DX_const_CX_DX_BP_SI_DI read_failed
  245.     DLOG_PRINT dlog, <Interface name (localtalk)>
  246.     mov AX, word ptr config_data
  247.     mov BX, word ptr config_data+2
  248.     DLOG_PRINT_INET_in_AX_BX dlog, <    Address >
  249.  
  250.     mov AX, word ptr config_data+4
  251.     mov BX, word ptr config_data+6
  252.     DLOG_PRINT_INET_in_AX_BX dlog, <    NetMask >
  253.  
  254.     mov AX, word ptr config_data+8
  255.     DLOG_PRINT_REG_HEX dlog, <    Flags     >, AX
  256.     mov word ptr dl_ip_&name&_flags, AX
  257.  
  258.     mov BX, word ptr config_data+10
  259.     DLOG_PRINT_REG_HEX dlog, <    Metric    >, BX
  260.     mov word ptr dl_ip_&name&_metric, BX
  261.  
  262.     ATP_DEFINE name, config_data, (config_data+4), (config_data+12),myfail
  263.     mov SI, offset dl_ip_&name&_haddr
  264.     lodsw
  265.     xchg AH, AL
  266.     DLOG_PRINT_REG_HEX dlog, <    The Localtalk Network >, AX
  267.     lodsb
  268.     xor AH, AH
  269.     DLOG_PRINT_REG_HEX dlog, <    The Localtalk Node ID >, AX
  270.  
  271.     jmp done
  272.     myfail:
  273.         DLOG_PRINT dlog, <ERROR Localtalk config failed (driver not installed?)>
  274.         jmp fail
  275.     done:
  276. endif
  277. ENDM
  278.  
  279.  
  280. ;;**************************************************************************
  281. ;; If the SLIP DL_IP 'name' object exists, then CONF_DECLARE_SLIP defines 
  282. ;; the flag that will tell the configuration program that configuration 
  283. ;; information  for a SLIP DL_IP is needed.
  284. ;;
  285. CONF_DECLARE_SLIP MACRO name
  286.     .errb <name>
  287.     ifdef slip_&name&_declared
  288.         DB CONF_SLIP, 1                 ;; type and version
  289.     endif
  290. ENDM
  291.  
  292. ;;**************************************************************************
  293. ;; If the SLIP object 'name' exists CONF_DEFINE_SLIP reads in the 
  294. ;; configuration data and initializes the SLIP object.
  295. ;;
  296. CONF_DEFINE_SLIP MACRO name, dlog, fail, read_failed, config_failed
  297.     local myfail, done
  298.     .errb <config_failed>
  299. ifdef slip_&name&_declared
  300.  
  301.     mov DX, offset config_data
  302.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  303.     cmp word ptr config_data, (CONF_SLIP)+256*1     ;; type generic, version 1
  304.     jnz config_failed
  305.  
  306.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 14, read_failed
  307.     DLOG_PRINT dlog, <Interface name (slip)>
  308.     mov AX, word ptr config_data
  309.     mov BX, word ptr config_data+2
  310.     DLOG_PRINT_INET_in_AX_BX dlog, <    Address >
  311.  
  312.     mov AX, word ptr config_data+4
  313.     mov BX, word ptr config_data+6
  314.     DLOG_PRINT_INET_in_AX_BX dlog, <    NetMask >
  315.  
  316.     mov AX, word ptr config_data+8
  317.     DLOG_PRINT_REG_HEX dlog, <    Flags     >, AX
  318.     mov word ptr dl_ip_&name&_flags, AX
  319.  
  320.     mov BX, word ptr config_data+10
  321.     DLOG_PRINT_REG_HEX dlog, <    Metric    >, BX
  322.     mov word ptr dl_ip_&name&_metric, BX
  323.  
  324.     BUFF_DEFINE %(name*100+1)
  325.     QUEUE_DEFINE %(name*100+2)
  326.     BUFF_DEFINE %(name*100+3)
  327.     QUEUE_DEFINE %(name*100+4)
  328.     Q_IF_DEFINE name     
  329.     SLIP_DEFINE name     
  330.     PP_DEFINE name, config_data, (config_data+4)
  331.     mov BX, word ptr config_data+12
  332.     I8250_DEFINE_in_BX name, myfail
  333.  
  334.     mov AX, word ptr config_data+12
  335.     DLOG_PRINT_REG_HEX dlog, <    The SLIP baud divisor >, AX
  336.  
  337.     jmp done
  338.     myfail:
  339.         DLOG_PRINT dlog, <ERROR SLIP config failed (no serial port)>
  340.         jmp fail
  341.     done:
  342. endif
  343. ENDM
  344.  
  345.  
  346. ;;**************************************************************************
  347. ;; CONF_DEFINE_ROUTE reads in the routing information on the disk and 
  348. ;; initializes the static routes.
  349. ;;
  350. CONF_DEFINE_ROUTE MACRO rip, dlog, fail, read_failed, config_failed
  351.     local route_loop, route_done
  352.     .errb <config_failed>
  353.  
  354.     mov DX, offset config_data
  355.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  356.     cmp word ptr config_data, (CONF_ROUTE)+256*1    ;; type rip, version 1
  357.     jnz config_failed
  358.  
  359.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 2, read_failed
  360.     mov CX, config_data
  361.     cmp CX, 300
  362.     ja config_failed
  363.  
  364.     mov AX, DS
  365.     mov ES, AX
  366.     mov DI, offset config_data+4
  367.  
  368.     DLOG_PRINT dlog, <STATIC ROUTES>
  369.     route_loop:
  370.         or CX, CX
  371.         jz route_done
  372.  
  373.         mov SI, CX                  ;; save CX without changing stack
  374.         mov DX, offset config_data
  375.         CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 10, read_failed
  376.         push SI                     ;; save CX on the stack
  377.  
  378.         mov AX, word ptr config_data
  379.         mov BX, word ptr config_data+2
  380.         DLOG_PRINT_INET_in_AX_BX dlog, <    Route to network >
  381.         mov AX, word ptr config_data+4
  382.         mov BX, word ptr config_data+6
  383.         DLOG_PRINT_INET_in_AX_BX dlog, <    Through gateway  >
  384.         xor AH, AH
  385.         mov AL, byte ptr config_data+8
  386.         DLOG_PRINT_REG_HEX dlog, <    Metric >, AX
  387.         mov AL, byte ptr config_data+9
  388.         DLOG_PRINT_REG_HEX dlog, <    Flags  >, AX
  389.         DLOG_PRINT dlog, < >
  390.  
  391.         mov SI, offset config_data
  392.         mov CX, word ptr config_data+8
  393.         ROUTE_ADD_in_CX_SI_DI_ES_const_DI_ES rip
  394.         pop CX
  395.         dec CX
  396.     jmp route_loop
  397.     route_done:
  398. ENDM
  399.  
  400.  
  401. ;;**************************************************************************
  402. ;; CONF_DEFINE_BOOTP reads in the bootp information on the disk and initializes
  403. ;; the BOOTP object
  404. ;;
  405. CONF_DEFINE_BOOTP MACRO mybootp, dlog, fail, read_failed, config_failed
  406.     .errb <config_failed>
  407.  
  408.     mov DX, offset config_data
  409.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  410.     cmp word ptr config_data, (CONF_BOOTP)+256*1    ;; type bootp, version 1
  411.     jnz config_failed
  412.  
  413.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  414.     mov AX, word ptr config_data
  415.     mov BX, word ptr config_data+2
  416.     DLOG_PRINT_INET_in_AX_BX dlog, <Forwarding BOOTP requests to       >
  417.     BOOTP_DEFINE mybootp, config_data
  418. ENDM
  419.  
  420.  
  421. ;;**************************************************************************
  422. ;; CONF_DEFINE_SYSLOG reads in the bootp information on the disk and initializes
  423. ;; the BOOTP object
  424. ;;
  425. CONF_DEFINE_SYSLOG MACRO mylog, dlog, fail, read_failed, config_failed
  426.     .errb <config_failed>
  427.  
  428.     mov DX, offset config_data
  429.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  430.     cmp word ptr config_data, (CONF_SYSLOG)+256*1    ;; type syslog, version 1
  431.     jnz config_failed
  432.  
  433.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 8, read_failed
  434.     mov AX, word ptr config_data
  435.     mov BX, word ptr config_data+2
  436.     DLOG_PRINT_INET_in_AX_BX dlog, <Logging messages to SYSLOGD on host >
  437.     mov AX, word ptr config_data+4
  438.     mov BX, word ptr config_data+6
  439.     DLOG_PRINT_REG_HEX dlog, <Logging level >, AX
  440.     DLOG_PRINT_REG_HEX dlog, <Logging mask >, BX
  441.     LOG_DEFINE_in_AX_BX mylog, config_data
  442. ENDM
  443.  
  444.  
  445. ;;**************************************************************************
  446. ;; CONFIG_OPEN_DATA opens 'pcroute.cfg' for reading.  It enforces a limit
  447. ;; on a read of 'max_size'.  If the open fails it jumps to 'fail'
  448. ;;
  449. CONFIG_OPEN_DATA MACRO fail, max_size
  450.     .errb <max_size>
  451.  
  452.     .DATA
  453.     config_file     db 'pcroute.cfg', 0
  454.     config_handle   dw ?
  455.     config_max_size = max_size
  456.  
  457.     .CODE
  458.     mov DX, offset config_file
  459.     mov AH, 3DH                                     ;; open the file
  460.     mov AL, 0                                       ;; open for reading
  461.     int 21H
  462.     jc fail
  463.     mov config_handle, AX                           ;; save handle
  464. ENDM
  465.  
  466.  
  467. ;;**************************************************************************
  468. ;; CONFIG_GET_DATA reads in the next 'len' bytes from the file open with
  469. ;; CONFIG_OPEN_DATA.  It puts the info in the buffer DX:DS.  If there 
  470. ;; is a error it jumps to 'fail'
  471. ;;
  472. CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI MACRO len, fail
  473.     .errb <fail>
  474.  
  475.     if len gt config_max_size
  476.         .err                                    ;; length to big!!
  477.     endif
  478.  
  479.     mov CX, len
  480.     CONFIG_GET_DATA_in_CX_DX_const_CX_DX_BP_SI_DI fail
  481. ENDM
  482.  
  483. ;;**************************************************************************
  484. ;; CONFIG_GET_DATA reads in the next 'CX' bytes from the file open with
  485. ;; CONFIG_OPEN_DATA.  It puts the info in the buffer DX:DS.  If there 
  486. ;; is a error it jumps to 'fail'
  487. ;;
  488. CONFIG_GET_DATA_in_CX_DX_const_CX_DX_BP_SI_DI MACRO fail
  489.     .errb <fail>
  490.  
  491.     mov AH, 3FH                                 ;; Read a block
  492.     mov BX, config_handle
  493.     int 21H                                     ;; read the ip info
  494.     jc fail
  495.     cmp AX, CX
  496.     jnz fail
  497. ENDM
  498.  
  499.