interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / aienux / allen / net.om

1845 lines · 31161 bytes Raw Blame History
1note Native bounded single HTTPS client. RFC826/791/768/2131/2132/1035/9293/6298.
2note Caller provides Ethernet frames without FCS, checked monotonic milliseconds,
3note six-byte unicast Nmac before netinit, and 32 fresh EFI entropy bytes in
4note Nrand before every netconnect. netconnect consumes and wipes Nrand: DHCP xid,
5note IPv4 id, DNS id/port, TCP port and ISN are never reused across connections.
6note netwrite true transfers a copy, not a peer ACK. netsent is firmware acceptance.
7note Public state 0idle 1DHCP 2DNS 3SYN 4open 5EOF/closed 6error.
8note Errors: 1clock 2MAC/entropy 3DHCPtimeout 4DHCPnak 5config 6conflict
9note 7ARPtimeout 8DNStimeout 9DNSrefused/truncated 10DNSinvalid/empty
10note 11TCPtimeout 12peerreset 13unsupportedTCP 14leaseexpired 15transmit
11note 16establishdeadline 17callerbounds. Invalid unrelated packets are ignored.
12note Limits: untagged Ethernet MTU1500, IPv4 without options/fragments,
13note DHCP lease without renewal, 120s establishment, DNS A/CNAME <=8 links,
14note 64 DNS records/UDP message, one stop-and-wait TCP segment, receive64KiB.
15note No DNS-over-TCP or EDNS: truncation fails; lease expiry fails explicitly.
16note A bound lease is reused by later netconnect calls; anything else restarts DHCP.
17note Internal Ncfg slots: now,dhcp,ip,mask,router,dns,server,offer,xid,leaseMS,
18note leaseAt,initAt,dhcpDue,dhcpTries,probeCount,want,connectAt,generation,
19note ipid,dnsid,dnsport,tcpport,dnsDue,dnsTries,cnameHops,qnameLen,
20note arpWanted,arpCached,arpDue,arpTries,arpAt,initialized.
21global Nrx uchar 2048
22global Ntx uchar 2048
23global Ntxlen ulong 1
24global Nmac uchar 6
25global Nrand uchar 32
26global Tcpin uchar 65536
27global Tcpout uchar 65536
28global Tcpn ulong 1
29global Tcpstate ulong 8
30global Ncfg ulong 32
31note Nct: una,next,rcvnxt,ringHead,peerwin,wl1,wl2,mss,ackPending,
32note flightLen,flightKind(1syn2data3fin),flightSent,flightSeq,sentAt,rto,
33note retries,sendTotal,sendOffset,closeWanted,finAcked,peerFin,finPending,
34note finSeq,activity,timewaitAt,iss,srtt,rttvar,rttValid,zeroAt,synRetried.
35global Nct ulong 32
36global Nsbuf uchar 65536
37global Nrbuf uchar 65536
38global Nrmap uchar 65536
39global Nhop uchar 6
40global Narp uchar 6
41global Napip ulong 1
42note Queue kind 1DHCP 2ARPquery 3ARPreply 4DNS 5TCPflight 6TCPack 7courierUDP.
43note Kind 7 (look-chat.om, netudpsend) is fire-and-forget: netsent only clears it,
44note no retry bookkeeping; the courier scheduler resends on its own clock.
45note Q1 failures Q2 queuedAt Q3 DHCP/ARP phase Q4 seq Q5 ack Q6 window Q7 generation.
46global Nq ulong 8
47note Parsed packet: frameLen,ipHlen,ipLen,src,dst,l4off,l4len,seq,ack,
48note flags,dataOff,dataLen,window,tcpHlen.
49global Npk ulong 16
50note Ndrop: reason code of the last segment refused before the payload path. Diagnosis only.
51global Ndrop ulong 1
52note Ndropt/Ndropd/Ndropw: length, start offset and window of the last accepted segment.
53global Ndropt ulong 1
54global Ndropd ulong 1
55global Ndropw ulong 1
56global Nopt ulong 8
57note DNS decoder base,end,next,nameLen,answerStart,answerCount,rrNext,rrData.
58global Nd ulong 8
59global Nname uchar 256
60global Nwant uchar 256
61global Nrr ulong 4
62note Courier UDP hooks (look-chat.om): one datagram body out in Chtx, one in
63note Chrx/Chrxn (0 = empty slot); a second arrival before chstep consumed the
64note slot is dropped and counted in Chdrop. Port 47033 both ways, like the C
65note kernel (x86/courier_udp.h CK_COURIER_PORT); source 0.0.0.0 before a lease.
66global Chtx uchar 1600
67global Chrx uchar 1600
68global Chrxn ulong 1
69global Chdrop ulong 1
70text Nhost "api.github.com"
71fn nr16 p ulong to ulong
72ret add shl ulong get Nrx p 8 ulong get Nrx add p 1
73end
74fn nr32 p ulong to ulong
75ret add shl nr16 p 16 nr16 add p 2
76end
77fn nt16 p ulong v ulong to void
78put Ntx p uchar and shr v 8 255
79put Ntx add p 1 uchar and v 255
80end
81fn nt32 p ulong v ulong to void
82nt16 p shr v 16
83nt16 add p 2 and v 65535
84end
85fn nadd a ulong b ulong to ulong
86ret and add a b 4294967295
87end
88fn ndiff a ulong b ulong to ulong
89ret and sub add a 4294967296 b 4294967295
90end
91fn nlt a ulong b ulong to bool
92ret gt ndiff a b 2147483647
93end
94fn nfold s ulong to ulong
95while gt s 65535 bound 8
96s = add and s 65535 shr s 16
97end
98ret xor s 65535
99end
100fn nrsum p ulong n ulong to ulong
101s = ulong 0
102while ge n 2 bound 1024
103s = add s nr16 p
104p = add p 2
105n = sub n 2
106end
107if eq n 1
108s = add s shl ulong get Nrx p 8
109end
110ret s
111end
112fn ntsum p ulong n ulong to ulong
113s = ulong 0
114while ge n 2 bound 1024
115s = add s shl ulong get Ntx p 8
116s = add s ulong get Ntx add p 1
117p = add p 2
118n = sub n 2
119end
120if eq n 1
121s = add s shl ulong get Ntx p 8
122end
123ret s
124end
125fn npssum a ulong b ulong proto ulong n ulong to ulong
126s = add shr a 16 and a 65535
127s = add s shr b 16
128s = add s and b 65535
129ret add add s proto n
130end
131fn nipok ip ulong to bool
132if or eq ip 0 eq ip 4294967295
133ret false
134end
135x = shr ip 24
136ret and ne x 0 and ne x 127 lt x 224
137end
138fn nmacrx p ulong to bool
139v = uchar 0
140for i ulong 6
141v = or v get Nrx add p i
142end
143ret and ne v 0 eq and get Nrx p 1 0
144end
145fn nmaceq p ulong to bool
146for i ulong 6
147if ne get Nrx add p i get Nmac i
148ret false
149end
150end
151ret true
152end
153fn nwipe to void
154for i ulong 65536
155put Tcpin i uchar 0
156put Tcpout i uchar 0
157put Nsbuf i uchar 0
158put Nrbuf i uchar 0
159put Nrmap i uchar 0
160end
161put Tcpn 0 0
162end
163fn nfail code ulong to void
164put Tcpstate 0 6
165put Tcpstate 1 code
166put Ntxlen 0 0
167for i ulong 2048
168put Ntx i uchar 0
169end
170for i ulong 32
171put Nrand i uchar 0
172put Nct i 0
173end
174nwipe
175end
176fn nclock now ulong to bool
177if or lt now get Ncfg 0 gt now 1000000000000000000
178nfail 1
179ret false
180end
181put Ncfg 0 now
182ret true
183end
184fn ntxzero to void
185for i ulong 1514
186put Ntx i uchar 0
187end
188end
189fn neth typ ulong broad bool to void
190for i ulong 6
191if broad
192put Ntx i uchar 255
193else
194put Ntx i get Nhop i
195end
196put Ntx add i 6 get Nmac i
197end
198nt16 12 typ
199end
200fn nqueue kind ulong n ulong to void
201if lt n 60
202n = 60
203end
204put Ntxlen 0 n
205put Nq 0 kind
206put Nq 1 0
207put Nq 2 get Ncfg 0
208put Nq 7 get Ncfg 17
209end
210fn nipbuild dest ulong proto ulong n ulong broad bool to void
211neth 2048 broad
212put Ntx 14 uchar 69
213nt16 16 add n 20
214nt16 18 get Ncfg 18
215put Ncfg 18 and add get Ncfg 18 1 65535
216nt16 20 16384
217put Ntx 22 uchar 64
218put Ntx 23 uchar proto
219nt32 26 get Ncfg 2
220nt32 30 dest
221nt16 24 nfold ntsum 14 20
222end
223fn nudp dest ulong srcp ulong dstp ulong n ulong broad bool to void
224nt16 34 srcp
225nt16 36 dstp
226nt16 38 add n 8
227s = npssum get Ncfg 2 dest 17 add n 8
228s = nfold add s ntsum 34 add n 8
229if eq s 0
230s = 65535
231end
232nt16 40 s
233nipbuild dest 17 add n 8 broad
234end
235note Courier datagram out: Chtx[0..n) to 255.255.255.255:47033 from Ncfg2:47033
236note in a broadcast frame, queued as kind 7 only when nothing else is in flight.
237note Error state 6 does not refuse it: the courier has no TCP, DHCP or DNS
238note dependency, so Allen keeps answering after a failed repository session.
239note false: not queued, the courier scheduler offers the same datagram again on
240note its own clock.
241fn netudpsend n ulong to bool
242if ne get Ntxlen 0 0
243ret false
244end
245if or eq n 0 gt n 1472
246ret false
247end
248ntxzero
249for i ulong n
250put Ntx add 42 i get Chtx i
251end
252nudp 4294967295 47033 47033 n true
253nqueue 7 add 42 n
254ret true
255end
256fn narpout target ulong probe bool to void
257ntxzero
258neth 2054 true
259nt16 14 1
260nt16 16 2048
261put Ntx 18 uchar 6
262put Ntx 19 uchar 4
263nt16 20 1
264for i ulong 6
265put Ntx add i 22 get Nmac i
266end
267if not probe
268nt32 28 get Ncfg 2
269end
270nt32 38 target
271put Nq 3 get Ncfg 1
272nqueue 2 42
273end
274fn narprepl to void
275ntxzero
276neth 2054 false
277for i ulong 6
278put Ntx i get Narp i
279put Ntx add i 32 get Narp i
280put Ntx add i 22 get Nmac i
281end
282nt16 14 1
283nt16 16 2048
284put Ntx 18 uchar 6
285put Ntx 19 uchar 4
286nt16 20 2
287nt32 28 get Ncfg 2
288nt32 38 get Napip 0
289put Napip 0 0
290nqueue 3 42
291end
292fn nroute dest ulong to bool
293if ne and dest get Ncfg 3 and get Ncfg 2 get Ncfg 3
294dest = get Ncfg 4
295end
296if eq dest 0
297nfail 5
298ret false
299end
300if eq get Ncfg 27 dest
301if lt sub get Ncfg 0 get Ncfg 30 60000
302ret true
303end
304put Ncfg 27 0
305end
306if ne get Ncfg 26 dest
307put Ncfg 26 dest
308put Ncfg 29 0
309put Ncfg 28 get Ncfg 0
310end
311if ge get Ncfg 0 get Ncfg 28
312if ge get Ncfg 29 5
313nfail 7
314ret false
315end
316narpout dest false
317end
318ret false
319end
320fn ndhcpout to void
321ntxzero
322put Ntx 42 uchar 1
323put Ntx 43 uchar 1
324put Ntx 44 uchar 6
325nt32 46 get Ncfg 8
326nt16 50 div sub get Ncfg 0 get Ncfg 11 1000
327nt16 52 32768
328for i ulong 6
329put Ntx add i 70 get Nmac i
330end
331nt32 278 1669485411
332put Ntx 282 uchar 53
333put Ntx 283 uchar 1
334mt = uchar 1
335if eq get Ncfg 1 2
336mt = 3
337end
338if eq get Ncfg 1 5
339mt = 4
340end
341put Ntx 284 mt
342p = ulong 285
343if ne mt 1
344put Ntx p uchar 50
345put Ntx add p 1 uchar 4
346nt32 add p 2 get Ncfg 7
347put Ntx add p 6 uchar 54
348put Ntx add p 7 uchar 4
349nt32 add p 8 get Ncfg 6
350p = add p 12
351end
352put Ntx p uchar 61
353put Ntx add p 1 uchar 7
354put Ntx add p 2 uchar 1
355for i ulong 6
356put Ntx add add p 3 i get Nmac i
357end
358p = add p 9
359note RFC2131 table 5: DHCPDECLINE carries no parameter list or size option.
360if ne mt 4
361put Ntx p uchar 55
362put Ntx add p 1 uchar 6
363put Ntx add p 2 uchar 1
364put Ntx add p 3 uchar 3
365put Ntx add p 4 uchar 6
366put Ntx add p 5 uchar 51
367put Ntx add p 6 uchar 58
368put Ntx add p 7 uchar 59
369put Ntx add p 8 uchar 57
370put Ntx add p 9 uchar 2
371nt16 add p 10 1472
372p = add p 12
373end
374put Ntx p uchar 255
375p = add p 1
376if lt p 342
377p = 342
378end
379nudp 4294967295 68 67 sub p 42 true
380put Nq 3 get Ncfg 1
381nqueue 1 p
382end
383fn ndnsout to void
384ntxzero
385nt16 42 get Ncfg 19
386nt16 44 256
387nt16 46 1
388for i ulong get Ncfg 25
389put Ntx add i 54 get Nwant i
390end
391p = add 54 get Ncfg 25
392nt16 p 1
393nt16 add p 2 1
394nudp get Ncfg 5 get Ncfg 20 53 sub add p 4 42 false
395nqueue 4 add p 4
396end
397fn nwindow to ulong
398ret sub 65535 get Tcpn 0
399end
400fn ntcpout flight bool to void
401ntxzero
402nt16 34 get Ncfg 21
403nt16 36 443
404nt32 38 get Nct 1
405nt32 42 get Nct 2
406put Ntx 46 uchar 80
407put Ntx 47 uchar 16
408nt16 48 nwindow
409n = ulong 20
410if flight
411nt32 38 get Nct 12
412if eq get Nct 10 1
413put Ntx 46 uchar 96
414put Ntx 47 uchar 2
415nt32 42 0
416put Ntx 54 uchar 2
417put Ntx 55 uchar 4
418nt16 56 1460
419n = 24
420else
421if eq get Nct 10 3
422put Ntx 47 uchar 17
423else
424put Ntx 47 uchar 24
425n = add n get Nct 9
426for i ulong get Nct 9
427put Ntx add i 54 get Nsbuf add get Nct 17 i
428end
429end
430end
431end
432s = npssum get Ncfg 2 get Tcpstate 2 6 n
433nt16 50 nfold add s ntsum 34 n
434nipbuild get Tcpstate 2 6 n false
435put Nq 4 get Nct 12
436put Nq 5 get Nct 2
437put Nq 6 nwindow
438if flight
439nqueue 5 add n 34
440else
441nqueue 6 add n 34
442end
443end
444note DHCP option fields are parsed atomically before changing lease state.
445fn ndopt code ulong p ulong n ulong to bool
446slot = ulong 8
447if eq code 53
448slot = 0
449end
450if eq code 54
451slot = 1
452end
453if eq code 1
454slot = 2
455end
456if eq code 3
457slot = 3
458end
459if eq code 6
460slot = 4
461end
462if eq code 51
463slot = 5
464end
465if eq code 52
466slot = 7
467end
468if eq slot 8
469ret true
470end
471if ne and get Nopt 6 shl ulong 1 slot 0
472ret false
473end
474put Nopt 6 or get Nopt 6 shl ulong 1 slot
475if or eq slot 0 eq slot 7
476if ne n 1
477ret false
478end
479put Nopt slot ulong get Nrx p
480ret true
481end
482if or eq slot 3 eq slot 4
483if or lt n 4 ne rem n 4 0
484ret false
485end
486else
487if ne n 4
488ret false
489end
490end
491put Nopt slot nr32 p
492ret true
493end
494fn ndopts p ulong stop ulong to bool
495while lt p stop bound 2048
496code = ulong get Nrx p
497p = add p 1
498if eq code 255
499ret true
500end
501if ne code 0
502if ge p stop
503ret false
504end
505n = ulong get Nrx p
506p = add p 1
507if gt n sub stop p
508ret false
509end
510if not ndopt code p n
511ret false
512end
513p = add p n
514end
515end
516ret false
517end
518fn ndconf to bool
519m = get Ncfg 3
520if or eq m 0 eq m 4294967295
521ret false
522end
523v = xor m 4294967295
524if ne and v add v 1 0
525ret false
526end
527v = and get Ncfg 7 xor m 4294967295
528if or eq v 0 eq v xor m 4294967295
529ret false
530end
531if not nipok get Ncfg 4
532ret false
533end
534if ne and get Ncfg 4 m and get Ncfg 7 m
535ret false
536end
537if not nipok get Ncfg 5
538ret false
539end
540ret ge get Ncfg 9 10000
541end
542fn ndcopy to void
543if ne get Nopt 2 0
544put Ncfg 3 get Nopt 2
545end
546if ne get Nopt 3 0
547put Ncfg 4 get Nopt 3
548end
549if ne get Nopt 4 0
550put Ncfg 5 get Nopt 4
551end
552if ne get Nopt 5 0
553put Ncfg 9 mul get Nopt 5 1000
554end
555end
556fn ndhcpin to void
557p = add get Npk 5 8
558n = sub get Npk 6 8
559if lt n 240
560ret
561end
562if or ne get Nrx p 2 ne get Nrx add p 1 1
563ret
564end
565if ne get Nrx add p 2 6
566ret
567end
568if ne nr32 add p 4 get Ncfg 8
569ret
570end
571if not nmaceq add p 28
572ret
573end
574if ne nr32 add p 236 1669485411
575ret
576end
577for i ulong 8
578put Nopt i 0
579end
580if not ndopts add p 240 add p n
581ret
582end
583if gt get Nopt 7 3
584ret
585end
586if ne and get Nopt 7 1 0
587if not ndopts add p 108 add p 236
588ret
589end
590end
591if ne and get Nopt 7 2 0
592if not ndopts add p 44 add p 108
593ret
594end
595end
596if not nipok get Nopt 1
597ret
598end
599if eq get Ncfg 1 1
600if ne get Nopt 0 2
601ret
602end
603if not nipok nr32 add p 16
604ret
605end
606put Ncfg 7 nr32 add p 16
607put Ncfg 6 get Nopt 1
608ndcopy
609put Ncfg 1 2
610put Ncfg 13 0
611put Ncfg 12 get Ncfg 0
612ret
613end
614if ne get Ncfg 1 2
615ret
616end
617if ne get Nopt 1 get Ncfg 6
618ret
619end
620if eq get Nopt 0 6
621nfail 4
622ret
623end
624if ne get Nopt 0 5
625ret
626end
627if ne nr32 add p 16 get Ncfg 7
628ret
629end
630ndcopy
631if not ndconf
632nfail 5
633ret
634end
635put Ncfg 10 get Ncfg 0
636put Ncfg 1 3
637put Ncfg 14 0
638put Ncfg 12 add get Ncfg 0 rem get Ncfg 8 1000
639end
640fn narpin to void
641if lt get Npk 0 42
642ret
643end
644if or ne nr16 14 1 ne nr16 16 2048
645ret
646end
647if or ne get Nrx 18 6 ne get Nrx 19 4
648ret
649end
650if or lt nr16 20 1 gt nr16 20 2
651ret
652end
653if not nmacrx 22
654ret
655end
656for i ulong 6
657if ne get Nrx add i 6 get Nrx add i 22
658ret
659end
660end
661if nmaceq 22
662ret
663end
664if eq get Ncfg 1 3
665if or eq nr32 28 get Ncfg 7 and eq nr32 28 0 eq nr32 38 get Ncfg 7
666put Ncfg 1 5
667put Ncfg 12 get Ncfg 0
668end
669ret
670end
671if ne get Ncfg 1 4
672ret
673end
674if eq nr32 28 get Ncfg 2
675nfail 6
676ret
677end
678if ne nr32 38 get Ncfg 2
679ret
680end
681if eq nr16 20 2
682if not nmaceq 32
683ret
684end
685if or eq get Ncfg 26 0 ne nr32 28 get Ncfg 26
686ret
687end
688for i ulong 6
689put Nhop i get Nrx add i 22
690end
691put Ncfg 27 get Ncfg 26
692put Ncfg 26 0
693put Ncfg 30 get Ncfg 0
694ret
695end
696if nipok nr32 28
697if eq get Napip 0 0
698for i ulong 6
699put Narp i get Nrx add i 22
700end
701put Napip 0 nr32 28
702end
703end
704end
705note DNS names expand to lowercase wire labels, never textual pointer arithmetic.
706note Compression pointers must point backward into this message, with <=128 hops.
707fn ndname p ulong to bool
708used = ulong 0
709next = ulong 0
710for hop ulong 256
711if ge p get Nd 1
712ret false
713end
714c = ulong get Nrx p
715if eq and c 192 192
716if ge add p 1 get Nd 1
717ret false
718end
719q = add get Nd 0 and nr16 p 16383
720if or ge q p lt q add get Nd 0 12
721ret false
722end
723if eq next 0
724next = add p 2
725end
726p = q
727else
728if ne and c 192 0
729ret false
730end
731p = add p 1
732if or gt add used add c 1 255 gt c sub get Nd 1 p
733ret false
734end
735put Nname used uchar c
736used = add used 1
737if eq c 0
738if eq next 0
739next = p
740end
741put Nd 2 next
742put Nd 3 used
743ret true
744end
745for i ulong c
746v = get Nrx add p i
747if and ge v 65 le v 90
748v = add v 32
749end
750put Nname used v
751used = add used 1
752end
753p = add p c
754end
755end
756ret false
757end
758fn ndmatch to bool
759if ne get Nd 3 get Ncfg 25
760ret false
761end
762for i ulong get Nd 3
763if ne get Nname i get Nwant i
764ret false
765end
766end
767ret true
768end
769fn ndrr p ulong to bool
770if not ndname p
771ret false
772end
773p = get Nd 2
774if gt add p 10 get Nd 1
775ret false
776end
777put Nrr 0 nr16 p
778put Nrr 1 nr16 add p 2
779put Nrr 2 nr16 add p 8
780put Nrr 3 nr32 add p 4
781p = add p 10
782if gt get Nrr 2 sub get Nd 1 p
783ret false
784end
785put Nd 7 p
786put Nd 6 add p get Nrr 2
787ret true
788end
789fn ndtarget to void
790for i ulong get Nd 3
791put Nwant i get Nname i
792end
793put Ncfg 25 get Nd 3
794put Ncfg 24 add get Ncfg 24 1
795end
796fn ndanswer to void
797for pass ulong 9
798p = get Nd 4
799changed = false
800for i ulong get Nd 5
801if not ndrr p
802nfail 10
803ret
804end
805p = get Nd 6
806if and eq get Nrr 1 1 ndmatch
807if eq get Nrr 0 1
808if ne get Nrr 2 4
809nfail 10
810ret
811end
812if not nipok nr32 get Nd 7
813nfail 10
814ret
815end
816put Tcpstate 2 nr32 get Nd 7
817put Tcpstate 0 3
818put Nct 9 1
819put Nct 10 1
820put Nct 11 0
821put Nct 12 get Nct 25
822put Nct 0 get Nct 25
823put Nct 1 get Nct 25
824put Nct 14 1000
825put Nct 15 0
826ret
827end
828if eq get Nrr 0 5
829if ge get Ncfg 24 8
830nfail 10
831ret
832end
833if not ndname get Nd 7
834nfail 10
835ret
836end
837if ne get Nd 2 p
838nfail 10
839ret
840end
841if ndmatch
842nfail 10
843ret
844end
845ndtarget
846changed = true
847break
848end
849end
850end
851if not changed
852if eq pass 0
853nfail 10
854ret
855end
856put Ncfg 19 and add get Ncfg 19 1 65535
857put Ncfg 22 get Ncfg 0
858put Ncfg 23 0
859ret
860end
861end
862nfail 10
863end
864fn ndnsin to void
865p = add get Npk 5 8
866if lt get Npk 6 20
867ret
868end
869if ne nr16 p get Ncfg 19
870ret
871end
872if ne and nr16 add p 2 63488 32768
873ret
874end
875if ne nr16 add p 4 1
876ret
877end
878put Nd 0 p
879put Nd 1 add get Npk 5 get Npk 6
880if not ndname add p 12
881ret
882end
883if not ndmatch
884ret
885end
886q = get Nd 2
887if gt add q 4 get Nd 1
888ret
889end
890if or ne nr16 q 1 ne nr16 add q 2 1
891ret
892end
893if ne and nr16 add p 2 527 0
894nfail 9
895ret
896end
897put Nd 4 add q 4
898put Nd 5 nr16 add p 6
899n = add get Nd 5 nr16 add p 8
900n = add n nr16 add p 10
901if gt n 64
902nfail 10
903ret
904end
905q = get Nd 4
906for i ulong n
907if not ndrr q
908nfail 10
909ret
910end
911q = get Nd 6
912end
913if ne q get Nd 1
914nfail 10
915ret
916end
917ndanswer
918end
919fn nrtt to void
920if ne get Nct 15 0
921ret
922end
923r = sub get Ncfg 0 get Nct 13
924if eq r 0
925r = 1
926end
927if eq get Nct 28 0
928put Nct 26 r
929put Nct 27 div r 2
930put Nct 28 1
931else
932d = get Nct 26
933if ge d r
934d = sub d r
935else
936d = sub r d
937end
938put Nct 27 div add mul get Nct 27 3 d 4
939put Nct 26 div add mul get Nct 26 7 r 8
940end
941r = add get Nct 26 mul get Nct 27 4
942if lt r 1000
943r = 1000
944end
945if gt r 60000
946r = 60000
947end
948if and ne get Nct 30 0 lt r 3000
949r = 3000
950end
951put Nct 14 r
952end
953fn ntopts p ulong stop ulong to bool
954while lt p stop bound 40
955kind = ulong get Nrx p
956if eq kind 0
957ret true
958end
959if eq kind 1
960p = add p 1
961else
962if ge add p 1 stop
963ret false
964end
965n = ulong get Nrx add p 1
966if or lt n 2 gt n sub stop p
967ret false
968end
969if eq kind 2
970if ne n 4
971ret false
972end
973n = nr16 add p 2
974if eq n 0
975ret false
976end
977if gt n 1460
978n = 1460
979end
980put Nct 7 n
981n = 4
982end
983p = add p n
984end
985end
986ret true
987end
988fn ntaccept to bool
989n = get Npk 11
990if ne and get Npk 9 1 0
991n = add n 1
992end
993w = nwindow
994if eq n 0
995if eq w 0
996ret eq get Npk 7 get Nct 2
997end
998ret lt ndiff get Npk 7 get Nct 2 w
999end
1000if eq w 0
1001ret false
1002end
1003if lt ndiff get Npk 7 get Nct 2 w
1004ret true
1005end
1006ret lt ndiff nadd get Npk 7 sub n 1 get Nct 2 w
1007end
1008fn ntack to bool
1009a = get Npk 8
1010if nlt get Nct 1 a
1011put Nct 8 1
1012ret false
1013end
1014if nlt a get Nct 0
1015ret true
1016end
1017if or nlt get Nct 5 get Npk 7 and eq get Nct 5 get Npk 7 not nlt a get Nct 6
1018put Nct 4 get Npk 12
1019put Nct 5 get Npk 7
1020put Nct 6 a
1021end
1022if eq a get Nct 0
1023ret true
1024end
1025if or eq get Nct 9 0 eq get Nct 11 0
1026ret false
1027end
1028n = ndiff a get Nct 0
1029if gt n get Nct 9
1030ret false
1031end
1032if eq n get Nct 9
1033nrtt
1034end
1035if eq get Nct 10 2
1036for i ulong n
1037put Nsbuf add get Nct 17 i uchar 0
1038end
1039put Nct 17 add get Nct 17 n
1040end
1041put Nct 0 a
1042put Nct 12 a
1043put Nct 9 sub get Nct 9 n
1044put Nct 13 get Ncfg 0
1045if ne get Nct 9 0
1046note Partial ACK retains Karn ambiguity for the remaining bytes.
1047put Nct 15 1
1048ret true
1049end
1050if eq get Nct 10 3
1051put Nct 19 1
1052end
1053put Nct 10 0
1054put Nct 11 0
1055put Nct 15 0
1056if eq get Nct 17 get Nct 16
1057put Nct 17 0
1058put Nct 16 0
1059end
1060ret true
1061end
1062fn ntfinish to void
1063if and ne get Nct 19 0 ne get Nct 20 0
1064if eq get Nct 24 0
1065put Nct 24 add get Ncfg 0 1
1066end
1067put Tcpstate 0 5
1068end
1069end
1070fn ntdrain to void
1071while ne get Nrmap get Nct 3 0 bound 65536
1072if ge get Tcpn 0 65535
1073break
1074end
1075if ne get Nct 20 0
1076break
1077end
1078if and ne get Nct 21 0 eq get Nct 22 get Nct 2
1079break
1080end
1081put Tcpin get Tcpn 0 get Nrbuf get Nct 3
1082put Tcpn 0 add get Tcpn 0 1
1083put Nrmap get Nct 3 uchar 0
1084put Nrbuf get Nct 3 uchar 0
1085put Nct 3 and add get Nct 3 1 65535
1086put Nct 2 nadd get Nct 2 1
1087end
1088if and ne get Nct 21 0 eq get Nct 22 get Nct 2
1089put Nct 2 nadd get Nct 2 1
1090put Nct 21 0
1091put Nct 20 1
1092put Nct 18 1
1093put Nct 8 1
1094put Tcpstate 0 5
1095end
1096ntfinish
1097end
1098fn ntdata to void
1099if ne get Nct 20 0
1100put Nct 8 1
1101ret
1102end
1103note Out-of-order bytes are stored directly in the ring and drained once the gap fills.
1104note This deliberately does not borrow Nct 21/22, which hold the peer FIN state: doing so
1105note made a retransmitted in-order segment look like a FIN and stalled the stream.
1106for i ulong get Npk 11
1107s = nadd get Npk 7 i
1108d = ndiff s get Nct 2
1109if lt d nwindow
1110p = and add get Nct 3 d 65535
1111v = get Nrx add get Npk 10 i
1112if eq get Nrmap p 0
1113put Nrbuf p v
1114put Nrmap p uchar 1
1115else
1116if ne get Nrbuf p v
1117nfail 13
1118ret
1119end
1120end
1121end
1122end
1123if or ne get Npk 11 0 ne and get Npk 9 1 0
1124put Nct 8 1
1125end
1126ntdrain
1127end
1128fn ntsynin to void
1129if eq get Nct 11 0
1130ret
1131end
1132if ne get Npk 8 nadd get Nct 25 1
1133ret
1134end
1135if eq and get Npk 9 20 20
1136nfail 12
1137ret
1138end
1139if ne and get Npk 9 23 18
1140ret
1141end
1142if ne get Npk 11 0
1143nfail 13
1144ret
1145end
1146if not ntopts add get Npk 5 20 get Npk 10
1147ret
1148end
1149nrtt
1150put Nct 0 get Npk 8
1151put Nct 1 get Npk 8
1152put Nct 2 nadd get Npk 7 1
1153put Nct 4 get Npk 12
1154put Nct 5 get Npk 7
1155put Nct 6 get Npk 8
1156put Nct 9 0
1157put Nct 10 0
1158put Nct 11 0
1159put Nct 15 0
1160put Nct 8 1
1161put Nct 23 get Ncfg 0
1162put Tcpstate 0 4
1163end
1164fn ntcpin to void
1165p = get Npk 5
1166if lt get Npk 6 20
1167ret
1168end
1169if or ne nr16 p 443 ne nr16 add p 2 get Ncfg 21
1170ret
1171end
1172if ne get Npk 3 get Tcpstate 2
1173put Ndrop 0 12
1174ret
1175end
1176s = npssum get Npk 3 get Npk 4 6 get Npk 6
1177if ne nfold add s nrsum p get Npk 6 0
1178put Ndrop 0 13
1179ret
1180end
1181put Npk 13 mul ulong shr get Nrx add p 12 4 4
1182if or lt get Npk 13 20 gt get Npk 13 get Npk 6
1183put Ndrop 0 14
1184ret
1185end
1186note RFC9293: the four reserved header bits are ignored on receipt.
1187put Npk 7 nr32 add p 4
1188put Npk 8 nr32 add p 8
1189put Npk 9 ulong get Nrx add p 13
1190put Npk 10 add p get Npk 13
1191put Npk 11 sub get Npk 6 get Npk 13
1192put Npk 12 nr16 add p 14
1193if eq get Tcpstate 0 3
1194ntsynin
1195ret
1196end
1197if or lt get Tcpstate 0 4 gt get Tcpstate 0 5
1198put Ndrop 0 15
1199ret
1200end
1201if ne get Nct 31 0
1202put Ndrop 0 16
1203ret
1204end
1205if ne and get Npk 9 4 0
1206if eq get Npk 7 get Nct 2
1207nfail 12
1208else
1209if ntaccept
1210put Nct 8 1
1211end
1212end
1213ret
1214end
1215if not ntaccept
1216put Nct 8 1
1217if and ne get Nct 24 0 ne and get Npk 9 1 0
1218if eq nadd get Npk 7 add get Npk 11 1 get Nct 2
1219put Nct 24 add get Ncfg 0 1
1220end
1221end
1222ret
1223end
1224if ne and get Npk 9 2 0
1225put Nct 8 1
1226ret
1227end
1228if eq and get Npk 9 16 0
1229ret
1230end
1231note CWR/ECE are ignored (ECN was not offered); urgent data is refused.
1232if ne and get Npk 9 32 0
1233nfail 13
1234ret
1235end
1236if not ntack
1237put Ndrop 0 1
1238ret
1239end
1240put Ndropt 0 get Npk 11
1241put Ndropd 0 ndiff get Npk 7 get Nct 2
1242put Ndropw 0 nwindow
1243put Nct 23 get Ncfg 0
1244ntdata
1245if ne and get Npk 9 1 0
1246note FIN occupies one sequence number after the payload. Latch it; ntdrain completes it when
1247note the stream reaches it, in order or after the gap fills.
1248put Nct 21 1
1249put Nct 22 nadd get Npk 7 get Npk 11
1250ntdrain
1251end
1252end
1253note Courier datagram in (UDP to port 47033, checksum already verified). Like
1254note the C kernel (courier_udp_x86.c pump) the frame is ours by its Ethernet
1255note destination (netinput: our MAC or ff:ff:ff:ff:ff:ff) and the port alone:
1256note any IPv4 destination is taken, so the relay's --udp-answer 192.168.1.255
1257note reaches a kernel that has no lease yet. Copied into Chrx when the slot is
1258note free, else dropped and counted. Any source port.
1259fn netudpin p ulong to void
1260n = sub get Npk 6 8
1261if or eq n 0 gt n len Chrx
1262ret
1263end
1264if ne get Chrxn 0 0
1265put Chdrop 0 add get Chdrop 0 1
1266ret
1267end
1268for i ulong n
1269put Chrx i get Nrx add add p 8 i
1270end
1271put Chrxn 0 n
1272end
1273fn nipin to void
1274if lt get Npk 0 34
1275ret
1276end
1277if ne shr get Nrx 14 4 4
1278ret
1279end
1280put Npk 1 mul ulong and get Nrx 14 15 4
1281if lt get Npk 1 20
1282ret
1283end
1284put Npk 2 nr16 16
1285if or lt get Npk 2 get Npk 1 gt add get Npk 2 14 get Npk 0
1286ret
1287end
1288if ne and nr16 20 49151 0
1289ret
1290end
1291if eq get Nrx 22 0
1292ret
1293end
1294if ne nfold nrsum 14 get Npk 1 0
1295ret
1296end
1297note All IPv4 options are refused; no source-route or hidden forwarding path.
1298if ne get Npk 1 20
1299ret
1300end
1301put Npk 3 nr32 26
1302put Npk 4 nr32 30
1303if not nipok get Npk 3
1304ret
1305end
1306put Npk 5 add 14 get Npk 1
1307put Npk 6 sub get Npk 2 get Npk 1
1308if eq get Nrx 23 6
1309if ne get Tcpstate 0 6
1310if and eq get Ncfg 1 4 eq get Npk 4 get Ncfg 2
1311ntcpin
1312end
1313end
1314ret
1315end
1316if ne get Nrx 23 17
1317ret
1318end
1319p = get Npk 5
1320if lt get Npk 6 8
1321ret
1322end
1323if ne nr16 add p 4 get Npk 6
1324ret
1325end
1326if ne nr16 add p 6 0
1327s = npssum get Npk 3 get Npk 4 17 get Npk 6
1328if ne nfold add s nrsum p get Npk 6 0
1329ret
1330end
1331end
1332if and eq nr16 p 67 eq nr16 add p 2 68
1333if ne get Tcpstate 0 6
1334if or eq get Ncfg 1 1 eq get Ncfg 1 2
1335note Any destination: chaddr, random xid and server-id gate acceptance.
1336ndhcpin
1337end
1338end
1339ret
1340end
1341if eq nr16 add p 2 47033
1342netudpin p
1343ret
1344end
1345if ne get Tcpstate 0 2
1346ret
1347end
1348if or ne get Npk 4 get Ncfg 2 ne get Npk 3 get Ncfg 5
1349ret
1350end
1351if or ne nr16 p 53 ne nr16 add p 2 get Ncfg 20
1352ret
1353end
1354ndnsin
1355end
1356fn nrnd32 p ulong to ulong
1357v = ulong 0
1358for i ulong 4
1359v = add shl v 8 ulong get Nrand add p i
1360end
1361ret v
1362end
1363fn nqhost to void
1364put Nwant 0 uchar 3
1365put Nwant 4 uchar 6
1366put Nwant 11 uchar 3
1367put Nwant 15 uchar 0
1368for i ulong 3
1369put Nwant add i 1 get Nhost i
1370put Nwant add i 12 get Nhost add i 11
1371end
1372for i ulong 6
1373put Nwant add i 5 get Nhost add i 4
1374end
1375put Ncfg 25 16
1376end
1377fn netinit now ulong to void
1378put Ntxlen 0 0
1379nwipe
1380for i ulong 32
1381put Ncfg i 0
1382put Nct i 0
1383put Nrand i uchar 0
1384end
1385for i ulong 8
1386put Tcpstate i 0
1387put Nq i 0
1388end
1389put Napip 0 0
1390for i ulong 6
1391put Nhop i uchar 0
1392put Narp i uchar 0
1393end
1394if not nclock now
1395ret
1396end
1397v = uchar 0
1398for i ulong 6
1399v = or v get Nmac i
1400end
1401if or eq v 0 ne and get Nmac 0 1 0
1402nfail 2
1403ret
1404end
1405put Ncfg 31 1
1406end
1407fn nbound to bool
1408if or ne get Ncfg 1 4 lt get Ncfg 14 5
1409ret false
1410end
1411ret lt sub get Ncfg 0 get Ncfg 10 get Ncfg 9
1412end
1413fn ndhcpnew to void
1414for i ulong 14
1415put Ncfg add i 1 0
1416end
1417for i ulong 5
1418put Ncfg add i 26 0
1419end
1420put Ncfg 8 nrnd32 0
1421put Ncfg 1 1
1422put Ncfg 11 get Ncfg 0
1423put Ncfg 12 get Ncfg 0
1424end
1425fn netconnect now ulong to void
1426if not nclock now
1427ret
1428end
1429if eq get Ncfg 31 0
1430nfail 17
1431ret
1432end
1433if and ge get Tcpstate 0 1 le get Tcpstate 0 4
1434ret
1435end
1436v = uchar 0
1437for i ulong 32
1438v = or v get Nrand i
1439end
1440if eq v 0
1441nfail 2
1442ret
1443end
1444note A queued frame from an older generation is completed, never reinterpreted.
1445g = add get Ncfg 17 1
1446nwipe
1447for i ulong 32
1448put Nct i 0
1449end
1450for i ulong 8
1451put Tcpstate i 0
1452end
1453for i ulong 10
1454put Ncfg add i 15 0
1455end
1456put Napip 0 0
1457put Ncfg 17 g
1458put Ncfg 18 and nrnd32 20 65535
1459put Ncfg 19 and nrnd32 4 65535
1460put Ncfg 20 add 49152 rem nrnd32 8 16384
1461put Ncfg 21 add 49152 rem nrnd32 16 16384
1462put Nct 25 nrnd32 12
1463put Nct 7 536
1464put Nct 14 1000
1465if nbound
1466put Tcpstate 0 2
1467put Ncfg 22 now
1468else
1469ndhcpnew
1470put Tcpstate 0 1
1471end
1472for i ulong 32
1473put Nrand i uchar 0
1474end
1475put Ncfg 15 1
1476put Ncfg 16 now
1477nqhost
1478end
1479note Error state 6 freezes DHCP, DNS and TCP until the next netconnect. Courier
1480note datagrams on port 47033 still arrive, and ARP for a bound lease is still
1481note answered so a relay's unicast answer to the leased address can reach us.
1482fn netinput n ulong now ulong to void
1483if not nclock now
1484ret
1485end
1486if or lt n 14 gt n 1514
1487ret
1488end
1489if not nmacrx 6
1490ret
1491end
1492if nmaceq 6
1493ret
1494end
1495note Any frame for us counts as activity: the mode-3 idle check in netstep must not be a
1496note connection-lifetime cap, or a long transfer dies mid-body with failure 14.
1497put Ncfg 10 now
1498if not nmaceq 0
1499for i ulong 6
1500if ne get Nrx i 255
1501ret
1502end
1503end
1504end
1505put Npk 0 n
1506if eq nr16 12 2054
1507if or ne get Tcpstate 0 6 eq get Ncfg 1 4
1508narpin
1509end
1510end
1511if eq nr16 12 2048
1512nipin
1513end
1514end
1515fn netwrite n ulong now ulong to bool
1516if not nclock now
1517ret false
1518end
1519if gt n 65536
1520nfail 17
1521ret false
1522end
1523if or ne get Tcpstate 0 4 ne get Nct 18 0
1524ret false
1525end
1526if ne get Nct 16 0
1527ret false
1528end
1529if eq n 0
1530ret true
1531end
1532for i ulong n
1533put Nsbuf i get Tcpout i
1534end
1535put Nct 16 n
1536put Nct 17 0
1537put Nct 29 now
1538ret true
1539end
1540fn netconsume n ulong to void
1541if gt n get Tcpn 0
1542nfail 17
1543ret
1544end
1545if eq n 0
1546ret
1547end
1548left = sub get Tcpn 0 n
1549for i ulong left
1550put Tcpin i get Tcpin add i n
1551end
1552for i ulong n
1553put Tcpin add left i uchar 0
1554end
1555put Tcpn 0 left
1556put Nct 8 1
1557ntdrain
1558end
1559fn netclose now ulong to void
1560if not nclock now
1561ret
1562end
1563if eq get Tcpstate 0 6
1564ret
1565end
1566if lt get Tcpstate 0 4
1567put Tcpstate 0 5
1568put Nct 31 1
1569nwipe
1570ret
1571end
1572put Nct 18 1
1573put Tcpstate 0 5
1574end
1575fn nstepset to void
1576if eq get Ncfg 1 5
1577ndhcpout
1578ret
1579end
1580if or eq get Ncfg 1 1 eq get Ncfg 1 2
1581if ge sub get Ncfg 0 get Ncfg 11 60000
1582nfail 3
1583ret
1584end
1585if ge get Ncfg 0 get Ncfg 12
1586if ge get Ncfg 13 5
1587nfail 3
1588else
1589ndhcpout
1590end
1591end
1592ret
1593end
1594if eq get Ncfg 1 3
1595if lt get Ncfg 0 get Ncfg 12
1596ret
1597end
1598if lt get Ncfg 14 3
1599narpout get Ncfg 7 true
1600ret
1601end
1602put Ncfg 2 get Ncfg 7
1603put Ncfg 1 4
1604end
1605if ne get Ncfg 1 4
1606ret
1607end
1608if lt get Ncfg 14 5
1609if ge get Ncfg 0 get Ncfg 12
1610narpout get Ncfg 2 false
1611put Nq 3 6
1612end
1613ret
1614end
1615if eq get Tcpstate 0 1
1616put Tcpstate 0 2
1617put Ncfg 22 get Ncfg 0
1618end
1619end
1620fn nstepdns to void
1621if lt get Ncfg 0 get Ncfg 22
1622ret
1623end
1624if ge get Ncfg 23 4
1625nfail 8
1626ret
1627end
1628if nroute get Ncfg 5
1629ndnsout
1630end
1631end
1632fn nflight kind ulong n ulong to void
1633put Nct 9 n
1634put Nct 10 kind
1635put Nct 11 0
1636put Nct 12 get Nct 1
1637put Nct 15 0
1638end
1639fn nsteptcp to void
1640if ne get Nct 24 0
1641if ge sub add get Ncfg 0 1 get Nct 24 120000
1642put Nct 31 1
1643put Nct 8 0
1644ret
1645end
1646end
1647if ne get Nct 31 0
1648ret
1649end
1650note FIN-WAIT-2 is bounded: our FIN is acknowledged, the peer stays silent.
1651if and ne get Nct 19 0 eq get Nct 20 0
1652if ge sub get Ncfg 0 get Nct 23 60000
1653put Nct 31 1
1654ret
1655end
1656end
1657if ne get Nct 8 0
1658if nroute get Tcpstate 2
1659ntcpout false
1660end
1661ret
1662end
1663if ne get Nct 9 0
1664if ne get Nct 11 0
1665if lt sub get Ncfg 0 get Nct 13 get Nct 14
1666ret
1667end
1668if ge get Nct 15 6
1669nfail 11
1670ret
1671end
1672end
1673if nroute get Tcpstate 2
1674ntcpout true
1675end
1676ret
1677end
1678if eq get Tcpstate 0 3
1679ret
1680end
1681if ne get Nct 16 0
1682n = sub get Nct 16 get Nct 17
1683if gt n get Nct 7
1684n = get Nct 7
1685end
1686if gt n get Nct 4
1687n = get Nct 4
1688end
1689if eq n 0
1690if lt sub get Ncfg 0 get Nct 29 1000
1691ret
1692end
1693note A one-byte persist probe is retained and retransmitted, never discarded.
1694n = 1
1695end
1696nflight 2 n
1697else
1698if and ne get Nct 18 0 eq get Nct 19 0
1699nflight 3 1
1700else
1701ret
1702end
1703end
1704if nroute get Tcpstate 2
1705ntcpout true
1706end
1707end
1708fn netstep now ulong to void
1709if not nclock now
1710ret
1711end
1712if or eq get Tcpstate 0 6 ne get Nct 31 0
1713ret
1714end
1715if ge get Ncfg 1 3
1716if and ne get Ncfg 9 0 ge sub now get Ncfg 10 get Ncfg 9
1717nfail 14
1718ret
1719end
1720end
1721if and ne get Ncfg 15 0 lt get Tcpstate 0 4
1722if ge sub now get Ncfg 16 120000
1723nfail 16
1724ret
1725end
1726end
1727if ne get Ntxlen 0 0
1728if ge sub now get Nq 2 10000
1729nfail 15
1730end
1731ret
1732end
1733nstepset
1734if or eq get Tcpstate 0 6 ne get Ntxlen 0 0
1735ret
1736end
1737if lt get Ncfg 14 5
1738ret
1739end
1740if ne get Napip 0 0
1741narprepl
1742ret
1743end
1744if eq get Tcpstate 0 2
1745nstepdns
1746end
1747if and ge get Tcpstate 0 3 le get Tcpstate 0 5
1748nsteptcp
1749end
1750end
1751fn nqdhcp to void
1752if ne get Nq 3 get Ncfg 1
1753ret
1754end
1755if eq get Ncfg 1 5
1756nfail 6
1757ret
1758end
1759d = add 3000 rem get Ncfg 8 2001
1760d = mul d shl ulong 1 get Ncfg 13
1761if gt d 16000
1762d = 16000
1763end
1764put Ncfg 13 add get Ncfg 13 1
1765put Ncfg 12 add get Ncfg 0 d
1766end
1767fn nqarp to void
1768if eq get Nq 3 3
1769if ne get Ncfg 1 3
1770ret
1771end
1772put Ncfg 14 add get Ncfg 14 1
1773d = add 1000 rem get Ncfg 8 1001
1774if eq get Ncfg 14 3
1775d = 2000
1776end
1777put Ncfg 12 add get Ncfg 0 d
1778ret
1779end
1780if eq get Nq 3 6
1781put Ncfg 14 add get Ncfg 14 1
1782put Ncfg 12 add get Ncfg 0 2000
1783ret
1784end
1785put Ncfg 28 add get Ncfg 0 mul 1000 shl ulong 1 get Ncfg 29
1786put Ncfg 29 add get Ncfg 29 1
1787end
1788fn nqflight to void
1789if or eq get Nct 9 0 ne get Nq 4 get Nct 12
1790ret
1791end
1792if ne get Nct 11 0
1793put Nct 15 add get Nct 15 1
1794r = mul get Nct 14 2
1795if gt r 60000
1796r = 60000
1797end
1798put Nct 14 r
1799if eq get Nct 10 1
1800put Nct 30 1
1801end
1802end
1803put Nct 11 1
1804put Nct 13 get Ncfg 0
1805put Nct 1 nadd get Nct 12 get Nct 9
1806end
1807fn netsent ok bool now ulong to void
1808if not nclock now
1809ret
1810end
1811if eq get Ntxlen 0 0
1812ret
1813end
1814if not ok
1815put Nq 1 add get Nq 1 1
1816if ge get Nq 1 8
1817nfail 15
1818end
1819ret
1820end
1821put Ntxlen 0 0
1822note Kind 7 (courier UDP) ends here: nothing to retry or acknowledge.
1823if ne get Nq 7 get Ncfg 17
1824ret
1825end
1826if eq get Nq 0 1
1827nqdhcp
1828end
1829if eq get Nq 0 2
1830nqarp
1831end
1832if eq get Nq 0 4
1833d = mul 2000 shl ulong 1 get Ncfg 23
1834put Ncfg 23 add get Ncfg 23 1
1835put Ncfg 22 add now d
1836end
1837if eq get Nq 0 5
1838nqflight
1839end
1840if or eq get Nq 0 5 eq get Nq 0 6
1841if and eq get Nq 5 get Nct 2 eq get Nq 6 nwindow
1842put Nct 8 0
1843end
1844end
1845end