;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 123.15
;;; Reason:
;;;  If no Internet Address, don't enable IP, TCP, etc.
;;; Written 18-Sep-87 17:17:04 by naha at site LMI Cambridge
;;; while running on Love from band 1
;;; with Experimental System 123.13, Experimental Local-File 73.0, Experimental FILE-Server 22.0, Experimental Unix-Interface 11.0, Experimental Tape 18.0, Experimental KERMIT 34.0, Experimental ZMail 71.0, Experimental Lambda-Diag 15.0, Experimental Site Data Editor 6.0, microcode 1754, SDU Boot Tape 3.13, SDU ROM 102.



; From modified file DJ: L.NETWORK.KERNEL; CONFIGURE.LISP#79 at 18-Sep-87 17:17:08
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERNEL; CONFIGURE  "


(defun configure ()
  ;; If we are in the cold load, do a mini-configuration
  (when si:*in-cold-load-p*
    (cold-load-configure)
    (return-from configure t))

  ;; Clear out current network configuration
  (deconfigure)

  ;;Put the network clock function onto the clock list
  (without-interrupts
    (pushnew 'net:network-clock sys:clock-function-list))
  
  ;; Start the device drivers
  (setup-loopback "LOOPBACK")
  (select-processor
    (:lambda
      (si:set-processor-owning-ethernet :find :3com)
      (cond ((eq ethernet:*3com-owner* si:*my-op*)
	     (ethernet:setup-3com "ONE")
	     (si:set-processor-owning-ethernet :give-up :excelan))
	    (t
	     (si:set-processor-owning-ethernet :find :excelan)
	     (if (eq ethernet:*excelan-owner* si:*my-op*)
		 (ethernet:setup-excelan "ONE"))))
      (si:setup-share-interface "SHARE"))
    (:explorer
      (ethernet:setup-explorer-ethernet "ONE"))
    (:cadr
      (chaos:setup-cadr-network "ONE")))
  
  ;; Start the protocol modules
  (when (eq si:*my-op* si:*ethernet-hardware-controller*)
    (arp:setup-arp))
  (chaos:setup-chaos)

  (let ((ip-address-p (ip:setup-ip)))
    (when ip-address-p
      (icmp:setup-icmp)
      (udp:setup-udp)
      (tcp:setup-tcp))
  
    (select-processor
      (:lambda
	;;KLUDGE: share interface must be set up before chaos, as chaos enables itself on share device --
	;;but share interface sets %processor-conf-chaos-address, so must reset it after chaos
	;;has set its address
	(send si:share-interface :reset)
	;; for all of our other processors, set up ARP translation for share interface
	(setq *processor-forwarding-alist* nil)
	(dolist (op si:*other-processors*)
	  (push (cons op nil) *processor-forwarding-alist*)
	  (dolist (domain '(:chaos :internet))
	    (let ((address (find-network-address-for-other-processor op domain)))
	      (when address
		(add-address-info address domain si:share-interface op))))))
      ((:cadr :explorer)))

    (dolist (x (ni-address-alist *loopback-interface*))
      ;;For all protocols enabled on the loopback interface, set up address translations
      (when (second x)
	(add-address-info (second x) (first x) *loopback-interface* nil)))

    (when ip-address-p
      ;;Start the TCP/UDP server process and enable network services
      (tcp-application:initialize-tcp-server-process)
      (tcp-application:enable-all-network-services)
      (tcp-application:initialize-udp-rwho-server-process)))

  ;;Start the network receiver process
  (start-receiver)

  (setup-network-gauges)			;If Fancy-Landscape enabled, populate screen with gauges

  t)

))

; From modified file DJ: L.NETWORK.IP-TCP.KERNEL; IP.LISP#268 at 18-Sep-87 17:17:19
#10R INTERNET#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "INTERNET")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; IP-TCP; KERNEL; IP  "


(defun setup-ip ()
  (multiple-value-bind (internet-address-list subnet-mask-list)
      (setup-my-internet-address)
    (when internet-address-list
      (let ((my-internet-address (first internet-address-list))
	    (my-subnet-mask (first subnet-mask-list)))
	;;;***Ideally, there should be a way to match multiple internet addresses with
	;;;***multiple network interfaces -- Internet Gateway functions!
	(setq *ip-stream*
	      (make-ip-network-protocol :keyword :internet
					:protocol `((:ethernet . ,ip-ethernet-type)
						    (:loopback . ,ip-ethernet-type)
						    (:backplane . ,ip-ethernet-type))
					:address-length 4
					:big-endian-address-p t
					:interrupt-function 'receive-ip-packet
					:address-printer 'canonical-ip
					:get-header-function 'make-ip-header
					:free-header-function 'free-ip-header
					:send-packet-function 'send-ip-packet
					:broadcast-packet-function 'broadcast-ip-packet
					:special-address-function 'ip-special-addresses
					:packet-length-function 'ip-length
					:gauge-name "IP"
					:default-address my-internet-address
					))
	(send *ip-stream* :open
	      `(("ONE" (,my-internet-address ,my-subnet-mask) ,my-internet-address)
		("LOOPBACK" (#x7f000000 #xff000000) #x7f000000)
		("SHARE" nil ,my-internet-address)
		)))
      (initialize-route-table internet-address-list))
    (initialize-ip-background-process)
    (send *ip-stream* :enable)
    t))

))
