;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 123.110
;;; Reason:
;;;  If you try to send a Chaos packet to a host on another subnet to which we cannot
;;;  route, the packet ends up being broadcast.  It should be dropped.
;;; Written 13-Nov-87 12:39:26 by pld at site LMI Cambridge
;;; while running on Jack Flanders from band 2
;;; with Experimental System 123.109, 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 Boot Tape 3.12, SDU ROM 8.



; From modified file DJ: L.NETWORK.CHAOS; CHSNCP.LISP#400 at 13-Nov-87 12:39:32
#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)
  (unless (net:check-packet (net:original-array int-pkt))
    (error "Attempt to transmit non-interrupt packet ~A." int-pkt))

  (when (null host)
    (setq host (pkt-dest-address int-pkt)))
  (when (null subnet)
    (setq subnet (pkt-dest-subnet int-pkt)))
  
  (unless (or (= subnet my-subnet) (member subnet my-other-subnets))
    (when (>= subnet (array-length routing-table))
      (setq subnet 0))
    (setq host (aref routing-table subnet)))
  
  (setq byte-count (* 2 (pkt-nwords int-pkt)))
  
  (when (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))

	((zerop host)				;Couldn't route this packet
	 (incf (chaos-packets-sent-discarded *chaos-stream*))
	 (incf (chaos-bytes-sent-discarded *chaos-stream*) byte-count)
	 (net:free-packet int-pkt))

	;;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)))
  )

;;;; KLUDGES and assorted random functions

))
