home *** CD-ROM | disk | FTP | other *** search
/ PC Press: Internet / PC_PRESS.ISO / software / dos / misc / inar-100.exe / SRC / PCROUTE / CONFIG.INC < prev    next >
Encoding:
Text File  |  1995-05-21  |  8.3 KB  |  285 lines

  1. ;; types of interfaces
  2. CONF_GENERIC    =   1       ;; interface that requires no special config data
  3.  
  4. CONF_ROUTE      =   10      ;; static route configuration data
  5. CONF_BOOTP      =   20      ;; Bootp configration data (forwarding host)
  6. CONF_ADMIN      =   21      ;; administrative data (admin host)
  7. CONF_SYSLOG     =   22      ;; host to send syslog messages to
  8.  
  9.  
  10. ;;************************************************************************
  11. ;; CONFIG reads in the configuration data from p?.cfg, and configures 
  12. ;; all the router objects.  If it is not successful it jumps to 'fail'.
  13. ;; 'dlog' is the Disk logger object to log errors to
  14. ;;
  15. CONFIG MACRO fail, dlog
  16.     local config_failed, open_failed, read_failed, done
  17.  
  18.     .DATA
  19.     config_data     DW 64 dup (0)
  20.  
  21.     .CODE
  22.     TIMER_DEFINE %mytimer
  23.  
  24.     CONFIG_OPEN_DATA open_failed, 64
  25.  
  26.     irp idx,<1,2,3,4,5,6,7,8>   ;; config the ethernets
  27.         CONF_DEFINE_ARP idx, dlog, fail, read_failed, config_failed
  28.     endm
  29.  
  30.     RIP_DEFINE %myrip
  31.  
  32.     IP_DEFINE %myip
  33.  
  34.         ;; All ethernet types have to be defined at this point so we can
  35.         ;; now register them with the packet drivers.
  36.  
  37.     irp idx,<1,2,3,4,5,6,7,8>   ;; config the packet drivers
  38.         CONF_DEFINE_PKT idx, dlog, fail
  39.     endm
  40.  
  41.     CONF_DEFINE_ROUTE %myrip, dlog, fail, read_failed, config_failed
  42.  
  43.     ICMP_DEFINE %myicmp
  44.  
  45.     UDP_DEFINE %myudp
  46.  
  47.     CONF_DEFINE_BOOTP %mybootp, dlog, fail, read_failed, config_failed
  48.  
  49.     CONF_DEFINE_SYSLOG %mylog, dlog, fail, read_failed, config_failed
  50.     jmp done
  51.  
  52.     open_failed:
  53.         DLOG_PRINT dlog, <Could not open config file>
  54.         jmp fail
  55.     read_failed:
  56.         DLOG_PRINT dlog, <Error reading config file>
  57.         jmp fail
  58.     config_failed:
  59.         DLOG_PRINT dlog, <Config file corrupt or out of sync>
  60.         jmp fail
  61.     done:
  62. ENDM
  63.  
  64. ;;**************************************************************************
  65. CONF_DEFINE_PKT MACRO name, dlog, fail
  66.     local around, pktfail
  67.     .errb <name>
  68.     .errb <dlog>
  69.     .errb <fail>
  70.  
  71.     ifdef pkt_&name&_declared
  72.         PKT_DEFINE name, pktfail
  73.         jmp around
  74.         pktfail:
  75.             DLOG_PRINT dlog, <No packet driver for interface name !?>
  76.         jmp fail
  77.     around:
  78.     endif
  79.  
  80. ENDM
  81.  
  82.  
  83.  
  84. ;;**************************************************************************
  85. ;; If the ARP DL_IP 'name' object exists, then CONF_DECLARE_ARP defines 
  86. ;; the flag that will tell the configuration program that configuration 
  87. ;; information  for a ARP DL_IP object is needed.
  88. ;;
  89. CONF_DECLARE_ARP MACRO name
  90.     .errb <name>
  91.  
  92.     ifdef arp_&name&_declared
  93.         DB CONF_GENERIC, 3          ;; type and version
  94.     endif
  95.     ifdef pps_&name&_declared
  96.         DB CONF_GENERIC, 3          ;; type and version
  97.     endif
  98. ENDM
  99.  
  100. ;;**************************************************************************
  101. ;; If the ARP object 'name' exists CONF_DEFINE_ARP reads in the configuration
  102. ;; data and initializes the ARP object.
  103. ;;
  104. CONF_DEFINE_ARP MACRO name, dlog, fail, read_failed, config_failed
  105.     .errb <config_failed>
  106.  
  107. ifdef eth_&name&_declared
  108.     ETH_DEFINE name
  109. endif
  110.  
  111. ifdef arp_&name&_declared
  112.  
  113.     mov DX, offset config_data
  114.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  115.     cmp word ptr config_data, (CONF_GENERIC)+256*3  ;; type generic, version 3
  116.     jnz config_failed
  117.  
  118.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 18, read_failed
  119.  
  120.     mov AX, word ptr config_data+12
  121.     mov word ptr dl_ip_&name&_flags, AX
  122.     mov AX, word ptr config_data+14
  123.     mov word ptr dl_ip_&name&_metric, AX
  124.     mov AX, word ptr config_data+16
  125.     mov word ptr dl_ip_&name&_id, AX
  126.  
  127.     ARP_DEFINE name, config_data, (config_data+4), (config_data+8)
  128. endif
  129. ifdef pps_&name&_declared
  130.  
  131.     mov DX, offset config_data
  132.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  133.     cmp word ptr config_data, (CONF_GENERIC)+256*3  ;; type generic, version 3
  134.     jnz config_failed
  135.  
  136.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 18, read_failed
  137.  
  138.     mov AX, word ptr config_data+12
  139.     mov word ptr dl_ip_&name&_flags, AX
  140.     mov AX, word ptr config_data+14
  141.     mov word ptr dl_ip_&name&_metric, AX
  142.     mov AX, word ptr config_data+16
  143.     mov word ptr dl_ip_&name&_id, AX
  144.  
  145.     PP_DEFINE name, config_data, (config_data+4), (config_data+8)
  146. endif
  147. ENDM
  148.  
  149.  
  150. ;;**************************************************************************
  151. ;; CONF_DEFINE_ROUTE reads in the routing information on the disk and 
  152. ;; initializes the static routes.
  153. ;;
  154. CONF_DEFINE_ROUTE MACRO rip, dlog, fail, read_failed, config_failed
  155.     local route_loop, route_done
  156.     .errb <config_failed>
  157.  
  158.     mov DX, offset config_data
  159.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  160.     cmp word ptr config_data, (CONF_ROUTE)+256*2    ;; type rip, version 2
  161.     jnz config_failed
  162.  
  163.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 2, read_failed
  164.     mov CX, config_data
  165.     cmp CX, 1200
  166.     ja config_failed
  167.  
  168.     mov AX, DS
  169.     mov ES, AX
  170.     mov DI, offset config_data+8
  171.  
  172.     route_loop:
  173.         or CX, CX
  174.         jz route_done
  175.  
  176.         mov SI, CX                  ;; save CX without changing stack
  177.         mov DX, offset config_data
  178.         CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 16, read_failed
  179.         push SI                     ;; save CX on the stack
  180.  
  181.         mov SI, offset config_data
  182.         mov DX, offset config_data+4
  183.         mov CX, word ptr config_data+12
  184.         mov AX, word ptr config_data+14
  185.         ROUTE_ADD_in_AX_CX_DX_SI_DI_ES_const_DI_ES rip
  186.         pop CX
  187.         dec CX
  188.     jmp route_loop
  189.     route_done:
  190. ENDM
  191.  
  192.  
  193. ;;**************************************************************************
  194. ;; CONF_DEFINE_BOOTP reads in the bootp information on the disk and initializes
  195. ;; the BOOTP object
  196. ;;
  197. CONF_DEFINE_BOOTP MACRO mybootp, dlog, fail, read_failed, config_failed
  198.     .errb <config_failed>
  199.  
  200.     mov DX, offset config_data
  201.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  202.     cmp word ptr config_data, (CONF_BOOTP)+256*1    ;; type bootp, version 1
  203.     jnz config_failed
  204.  
  205.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  206.  
  207.     BOOTP_DEFINE mybootp, config_data
  208. ENDM
  209.  
  210.  
  211. ;;**************************************************************************
  212. ;; CONF_DEFINE_SYSLOG reads in the bootp information on the disk and initializes
  213. ;; the BOOTP object
  214. ;;
  215. CONF_DEFINE_SYSLOG MACRO mylog, dlog, fail, read_failed, config_failed
  216.     .errb <config_failed>
  217.  
  218.     mov DX, offset config_data
  219.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 4, read_failed
  220.     cmp word ptr config_data, (CONF_SYSLOG)+256*1    ;; type syslog, version 1
  221.     jnz config_failed
  222.  
  223.     CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI 8, read_failed
  224.  
  225.     mov AX, word ptr config_data+4
  226.     mov BX, word ptr config_data+6
  227.     LOG_DEFINE_in_AX_BX mylog, config_data
  228. ENDM
  229.  
  230.  
  231. ;;**************************************************************************
  232. ;; CONFIG_OPEN_DATA opens 'p?.cfg' for reading.  It enforces a limit
  233. ;; on a read of 'max_size'.  If the open fails it jumps to 'fail'
  234. ;;
  235. CONFIG_OPEN_DATA MACRO fail, max_size
  236.     .errb <max_size>
  237.  
  238.     .DATA
  239.     config_file     db 'p', '0'+num_dls, '.cfg', 0
  240.     config_handle   dw ?
  241.     config_max_size = max_size
  242.  
  243.     .CODE
  244.     mov DX, offset config_file
  245.     mov AH, 3DH                                     ;; open the file
  246.     mov AL, 0                                       ;; open for reading
  247.     int 21H
  248.     jc fail
  249.     mov config_handle, AX                           ;; save handle
  250. ENDM
  251.  
  252.  
  253. ;;**************************************************************************
  254. ;; CONFIG_GET_DATA reads in the next 'len' bytes from the file open with
  255. ;; CONFIG_OPEN_DATA.  It puts the info in the buffer DX:DS.  If there 
  256. ;; is a error it jumps to 'fail'
  257. ;;
  258. CONFIG_GET_DATA_in_DX_const_DX_BP_SI_DI MACRO len, fail
  259.     .errb <fail>
  260.  
  261.     if len gt config_max_size
  262.         .err                                    ;; length to big!!
  263.     endif
  264.  
  265.     mov CX, len
  266.     CONFIG_GET_DATA_in_CX_DX_const_CX_DX_BP_SI_DI fail
  267. ENDM
  268.  
  269. ;;**************************************************************************
  270. ;; CONFIG_GET_DATA reads in the next 'CX' bytes from the file open with
  271. ;; CONFIG_OPEN_DATA.  It puts the info in the buffer DX:DS.  If there 
  272. ;; is a error it jumps to 'fail'
  273. ;;
  274. CONFIG_GET_DATA_in_CX_DX_const_CX_DX_BP_SI_DI MACRO fail
  275.     .errb <fail>
  276.  
  277.     mov AH, 3FH                                 ;; Read a block
  278.     mov BX, config_handle
  279.     int 21H                                     ;; read the ip info
  280.     jc fail
  281.     cmp AX, CX
  282.     jnz fail
  283. ENDM
  284.  
  285.