.TITLE RDRECT Redirect processing .NLIST BEX .ENABL LC ; ; Pdp11/dcn - redirect processing ; ; External symbols ; .GLOBL ADRMAP,ADRPTR,NETEST ;routing functions .GLOBL DATSUM ;checksum function ; ; Entry symbols ; .GLOBL RDRIN ;process received redirect .GLOBL RDROT ;construct redirect ; ; System definitions ; .ASECT .MCALL .COM,.PSA,.GAT,.SMF ;dcnlib definitions .MCALL $DFIH,$DFGH,$DFTBL,$DFTIM ;moslib definitions .MCALL .PSEM,.VSEM ;moslib macros .COM ;define common data .PSA ;define process storage areas .GAT ;define gateway/bridge storage areas .SMF ;define semaphore ids $DFIH ;define internet header $DFGH ;define icmp header $DFTBL ;define host/gateway table formats $DFTIM ;define timer values .PAGE ; ; Module definitions ; TX.RDR = 600. ;redirect cache timeout (sec) ; ; Procedure segment ; ; Process-state procedure ; Dsects: r3 = par, r5 = psa ; .PSECT $SUPI,RO,I ; ; Process received redirect ; R4 = packet pointer ; RDRIN: CMPB IH.PRO(R4),#P.IMP ;is this icmp redirect message BNE 3$ ;branch if not icmp BIT #IH.MF+IH.OFF,IH.FRG(R4) BNE 3$ ;branch if not first fragment CMP PH.LNG(R4),#GH.HDR BLO 3$ ;branch if bad format MOV R4,R1 JSR PC,DATSUM BNE 3$ ;branch if bad checksum MOV R4,R2 ADD PH.OFS(R4),R2 CMPB GH.TYP(R2),#GC.RDR BNE 3$ ;branch if wrong code MOV R2,R1 ;yes. is new gateway on same net ADD #GH.ID,R1 JSR PC,NETEST BNE 2$ ;branch if no (protocol error) CMP (R1)+,PARADR(R3) ;yes. is the bugger us BNE 1$ ;branch if no CMP (R1)+,PARADR+2(R3) BEQ 2$ ;branch if yes (routing loop) 1$: JSR PC,NTSRCH ;no. update routing tables 2$: SEC ;drop packet RTS PC ; 3$: CLC ;forward packet RTS PC ; ; Subroutine to update routing table ; R2 = icmp header pointer ; NTSRCH: MOV R2,R1 ;find net entry ADD #GH.HDR-BUFLDR+IH.DST,R1 JSR PC,ADRPTR ;find ip address mask MOV 2(R0),-(SP) ;save mask MOV @R0,-(SP) MOV 2(R1),-(SP) ;save address MOV @R1,-(SP) BIC @R0,@SP ;mask address BIC 2(R0),2(SP) .PSEM #SF.RUT ;lock routing tables MOV SP,R1 ;find entry JSR PC,ADRMAP BCS 7$ ;branch if not found BITB #1,HOSLNA(R1) BNE 7$ ;branch if multicast BITB #GT.END,GATFLG(R0) BEQ 5$ ;branch if no default 1$: SUB #GATLEN,R0 ;find free cache entry BITB #GT.CAC,GATFLG(R0) BEQ 7$ ;branch if cant TSTB GATTTL(R0) BNE 1$ ;branch if not free CLR R1 ;find free hid BISB $HOSAD-1,R1 MOVB R1,-(SP) MUL #HOSLEN,R1 ADD #$HOSAD,R1 2$: CMPB @SP,$HOSAD-2 ;is hid available BHIS 3$ ;branch if no TSTB HOSPID(R1) ;yes. is it free BEQ 4$ ;branch if yes ADD #HOSLEN,R1 ;no. advance to next one INCB @SP BR 2$ ; 3$: TSTB (SP)+ ;no hid available BR 7$ ; 4$: MOVB (SP)+,GATHID(R0) ;found free hid. initialize net entry MOV (SP)+,GATNET(R0) MOV (SP)+,GATNET+2(R0) MOV (SP)+,GATMSK(R0) MOV (SP)+,GATMSK+2(R0) MOVB #GT.CAC,GATFLG(R0) CLRB GATHOP(R0) MOVB PARPID(R3),HOSPID(R1) ;initialize routing entry CLRB HOSTTL(R1) CLR HOSTIM(R1) ;(fake time) CLR HOSTIM+2(R1) MOV #TM.MIN*2,HOSDLY(R1) CLR HOSOFS(R1) BR 6$ ; 5$: BITB #GT.HLO,GATFLG(R0) ;not default BNE 7$ ;branch if hello ADD #10,SP ;discard junk 6$: CLR HOSLNA(R1) ;force arp update CLR HOSLNA+2(R1) CLR HOSLNA+4(R1) MOV GH.ID(R2),GATLDR(R0) ;refresh old entry MOV GH.ID+2(R2),GATLDR+2(R0) BITB #GT.CAC,GATFLG(R0) ;is it cached BEQ 8$ ;branch if no MOVB #TX.RDR/30.,GATTTL(R0) ;yes. tickle ttl BR 8$ ; 7$: ADD #10,SP ;discard junk 8$: .VSEM #SF.RUT ;unlock routing tables RTS PC ; ; Construct redirect ; r2 = icmp header pointer, r4 = data packet pointer ; RDROT: MOV R1,-(SP) ;save MOV R4,R1 ;is source on neighbor net ADD #IH.SRC,R1 JSR PC,NETEST BNE 1$ ;branch if no (protocol error) MOV R4,R1 ;find destination address (again) ADD #IH.DST,R1 JSR PC,ADRMAP BCS 1$ ;branch if cant MOV R0,R1 ADD #GATLDR,R1 JSR PC,NETEST BNE 1$ ;branch if not neighbor net MOV (R1)+,GH.ID(R2) ;okay. insert gateway address MOV (R1)+,GH.ID+2(R2) CLC ;send redirect BR 2$ ; 1$: SEC ;suppress redirect 2$: MOV (SP)+,R1 ;evas RTS PC ; .END