;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 123.92
;;; Reason:
;;;  chaos:transmit-int-pkt now sets the header version number to 0.  Without this,
;;;  if the int-pkt didn't happen to have a zero in that byte, the destination will
;;;  silently drop the (otherwise perfectly good) packet.
;;; Written 4-Nov-87 12:21:42 by pld at site LMI Cambridge
;;; while running on Djinn from band 2
;;; with Experimental System 123.90, 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, microcode 1754, SDU ROM 8.



; From modified file DJ: L.NETWORK.CHAOS; CHSNCP.LISP#397 at 4-Nov-87 12:21:44
#10R CHAOS#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "CHAOS")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; CHAOS; CHSNCP  "

(defun transmit-int-pkt (int-pkt &optional host subnet (broadcast-if-necessary t)
			 &aux byte-count address interface)
  (if (null host) (setq host (pkt-dest-address int-pkt)))
  (if (null subnet) (setq subnet (pkt-dest-subnet int-pkt)))
  
  (COND ((AND (NOT (= SUBNET MY-SUBNET))
	      (NOT (MEMBER SUBNET MY-OTHER-SUBNETS)))
	 (AND ( SUBNET (ARRAY-LENGTH ROUTING-TABLE))
	      (SETQ SUBNET 0))
	 (SETQ HOST (aref ROUTING-TABLE SUBNET))))
  
  (setq byte-count (* 2 (pkt-nwords int-pkt)))
  
  (unless (net:check-packet (net:original-array int-pkt))
    (ferror "Attempt to transmit non-interrupt packet ~A." INT-PKT))
  
  (if (BIT-TEST #o200 (PKT-OPCODE INT-PKT))
      (incf DATA-PKTS-OUT))
  
  (setf (ldb (byte 8 0) (aref int-pkt 0)) 0)	;Set header version to 0

  (cond ((and broadcast-if-necessary
	      (zerop host)
	      (zerop (pkt-dest-address int-pkt)))
	 (incf pkts-transmitted)		;Increment counter looked at by Hostat
	 (send *chaos-stream*
	       :broadcast
	       int-pkt
	       byte-count))
	
	;;Maybe this case should be handled by some sort of "default gateway" mechanism.
	((and si:*ethernet-hardware-controller*
	      (not (eq si:*ethernet-hardware-controller* si:*my-op*))
	      (si:share-mode-active-p))
	 ;;Here if there is Ethernet hardware and it is owned by another processor
	 (incf pkts-transmitted)		;Increment counter looked at by Hostat
	 (send *chaos-stream*
	       :send
	       int-pkt
	       byte-count
	       si:share-interface
	       si:*ethernet-hardware-controller*))
	
	((multiple-value-setq (address interface)
	   (send *chaos-stream* :translate-address host nil (pkt-source-address int-pkt)))
	 ;;Here if there is no Ethernet hardware, but packet goes to processor on our backplane,
	 ;;OR there is Ethernet hardware and we own it,
	 ;;OR the packet is addressed to this host
	 (incf pkts-transmitted)		;Increment counter looked at by Hostat
	 (send *chaos-stream*
	       :send
	       int-pkt
	       byte-count
	       interface
	       address))
	
	(t
	 (incf (chaos-packets-sent-discarded *chaos-stream*))
	 (incf (chaos-bytes-sent-discarded *chaos-stream*) byte-count)
	 (net:free-packet int-pkt)))
  )

))
