;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 123.211
;;; Reason:
;;;  The 3com owner wants to forward Chaos and Internet packets for other processors on
;;;  the Nubus that don't have an Ethernet interface (i.e. Excelan).  This includes any
;;;  Unix processor, and at least the 3rd processor in a 3X3.  Add hair to
;;;  (net:configure) to try to initialize net:*processor-forwarding-alist* properly.
;;; Written 8-Mar-88 13:22:09 by pld at site Gigamos Cambridge
;;; while running on Jack Flanders from band 2
;;; with Experimental System 123.210, Experimental Local-File 73.3, Experimental FILE-Server 22.1, Experimental Unix-Interface 11.0, Experimental KERMIT 34.3, Experimental ZMail 71.0, Experimental Lambda-Diag 15.0, Experimental Tape 21.1, microcode 1755, SDU Boot Tape 3.12, SDU ROM 8.



; From modified file DJ: L.NETWORK.KERNEL; LIBRARY.LISP#54 at 8-Mar-88 13:34:51
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERNEL; LIBRARY  "

(defun find-host-for-other-processor (op)
  (let* ((host-name (nth (si:op-proc-number op) (multiple-value-list (si:get-pack-name))))
	 (host (si:parse-host host-name t nil)))
    host))

))

; From modified file DJ: L.NETWORK.KERNEL; LIBRARY.LISP#54 at 8-Mar-88 13:38:33
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERNEL; LIBRARY  "

(defun find-network-address-for-other-processor (op domain)
  (let ((host (find-host-for-other-processor op)))
    (cond (host
	   (send host :network-address domain))
	  ((eq domain :chaos)
	   ;;***Kludge -- system either isn't in pack name or isn't in site files.
	   ;;***Get the chaos address the old way
	   (let* ((conf (si:op-proc-conf op))
		  (address (and conf (si:%processor-conf-chaos-address conf))))
	     (cond ((null address)		;No configuration structure or no address
		    nil)
		   ((zerop address)		;Bad address -- not set up yet
		    nil)
		   (t				;Good address
		    address))))
	  (t nil))))

))

; From modified file DJ: L.NETWORK.KERNEL; CONFIGURE.LISP#96 at 8-Mar-88 13:38:46
#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)

  ;; Reset the int-pkts
  (initialize-network-buffers)
  
  ;; Put the network clock function onto the clock list
  (without-interrupts
    (pushnew 'net:network-clock sys:clock-function-list))
  
  ;; Start the device drivers
  (initializations 'network-driver-initialization-list t)
  
  ;; 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)))
    (cond (ip-address-p
	   (icmp:setup-icmp)
	   (udp:setup-udp)
	   (tcp:setup-tcp))
	  (t
	   (tv:careful-notify nil t "This processor has no Internet Address")))
  
    (initialize-share-interface)		;Set up address translations and forwarding
    (initialize-loopback-interface)		;Set up address translations

    (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.KERNEL; CONFIGURE.LISP#96 at 8-Mar-88 13:38:54
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERNEL; CONFIGURE  "

(defun cold-load-configure ()
  ;; Start the device drivers
  (si:set-processor-owning-ethernet :give-up)	;Just find out who owns the various ethernet boards...
  (setup-loopback "LOOPBACK")
  (si:setup-share-interface "SHARE")
  
  ;; Start the protocol modules
  (chaos:setup-chaos)
  
  (initialize-share-interface)			;Set up address translations and forwarding
  (initialize-loopback-interface)		;Set up address translations

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

))

; From modified file DJ: L.NETWORK.KERNEL; CONFIGURE.LISP#96 at 8-Mar-88 13:38:59
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERNEL; CONFIGURE  "

(defun initialize-loopback-interface ()
  (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))))

))

; From modified file DJ: L.NETWORK.KERNEL; CONFIGURE.LISP#96 at 8-Mar-88 13:45:24
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERNEL; CONFIGURE  "

(defun initialize-share-interface ()
  (when si:*other-processors*
    ;;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)
    (flet ((forward-p (op)
	     (when (eq ethernet:*3com-owner* si:*my-op*)
	       ;;We forward for other processer IFF we own 3com and they can't take an Excelan
	       (let* ((device (fs:parse-pathname "EXCELAN-NETWORK-INTERFACE:"))
		      (host (and device (send device :host)))
		      (current-owner (and host (send host :owner))))
		 (cond ((eq current-owner :not-on-bus)	;no Excelan
			t)
		       ((> (si:op-proc-number op) 1)
			;;There is an Excelan and the other processor is the 3rd Lisp Machine on a 3X3, or is the
			;;Unix procssor of a 2X2+.  We forward in either case...
			t)
		       ((typep (find-host-for-other-processor op) '(or null fs:unix-host))
			;;There is an Excelan, the other processor is the 2nd on the bus, and is either Unix or
			;;is unknown.  Assume we forward for it.
			t)
		       (t
			;;There is an Excelan and the other processor is the 2nd Lisp Machine.
			;;Wait until it asks us to forward for it...
			nil))))))
      (dolist (op si:*other-processors*)
	(push (cons op (forward-p op)) *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))))))
    ))

))
