2021-07-03 05:07:57 +01:00
< ! DOCTYPE HTML >
< html >
< head >
< meta http - equiv = " Content-Type " content = " text/html;charset=US-ASCII " >
< meta name = " generator " content = " ZealOS V0.05 " >
< style type = " text/css " >
body { background - color : # 000000 ; }
. cF0 { color : # ffffff ; background - color : # 000000 ; }
. cF1 { color : # 3465 a4 ; background - color : # 000000 ; }
. cF2 { color : # 4e9 a06 ; background - color : # 000000 ; }
. cF3 { color : # 06 989 a ; background - color : # 000000 ; }
. cF4 { color : # a24444 ; background - color : # 000000 ; }
. cF5 { color : # 75507 b ; background - color : # 000000 ; }
. cF6 { color : # ce982f ; background - color : # 000000 ; }
. cF7 { color : # bcc0b9 ; background - color : # 000000 ; }
. cF8 { color : # 555753 ; background - color : # 000000 ; }
. cF9 { color : # 729f cf ; background - color : # 000000 ; }
. cFA { color : # 82 bc49 ; background - color : # 000000 ; }
. cFB { color : # 34e2 e2 ; background - color : # 000000 ; }
. cFC { color : # ac3535 ; background - color : # 000000 ; }
. cFD { color : # ad7fa8 ; background - color : # 000000 ; }
. cFE { color : # fce94f ; background - color : # 000000 ; }
. cFF { color : # 000000 ; background - color : # 000000 ; }
< / style >
< / head >
< body >
2021-07-05 01:12:38 +01:00
< pre style = " font-family:monospace;font-size:12pt " >
2021-07-03 05:07:57 +01:00
< a name = " l1 " > < / a > < span class = cF2 > // Port Control Protocol prototyping.</span><span class=cF0>
< a name = " l2 " > < / a > < / span > < span class = cF2 > // RFC 6887</span><span class=cF0>
< a name = " l3 " > < / a >
< a name = " l4 " > < / a > < / span > < span class = cF1 > class < / span > < span class = cF0 > CPCPRequestHeader
< a name = " l5 " > < / a > {
2021-07-04 23:11:34 +01:00
< a name = " l6 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > version ;
< a name = " l7 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > opcode ; < / span > < span class = cF2 > // includes R bit.</span><span class=cF0>
< a name = " l8 " > < / a > < / span > < span class = cF9 > U16 < / span > < span class = cF0 > reserved ; < / span > < span class = cF2 > // must be all 0 on TX</span><span class=cF0>
< a name = " l9 " > < / a > < / span > < span class = cF9 > U32 < / span > < span class = cF0 > req_lifetime ; < / span > < span class = cF2 > // seconds. 0 interpreted as 'delete'.</span><span class=cF0>
< a name = " l10 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > pcp_client_ip [ < / span > < span class = cFE > 16 < / span > < span class = cF0 > ] ; < / span > < span class = cF2 > // source ipv4 addr converted to ipv4-mapped ipv6 as per spec. 128 bits</span><span class=cF0>
2021-07-03 05:07:57 +01:00
< a name = " l11 " > < / a > } ;
< a name = " l12 " > < / a >
< a name = " l13 " > < / a > < / span > < span class = cF1 > class < / span > < span class = cF0 > CPCPMapRequest
< a name = " l14 " > < / a > {
2021-07-04 23:11:34 +01:00
< a name = " l15 " > < / a > CPCPRequestHeader header ;
< a name = " l16 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > nonce [ < / span > < span class = cFE > 12 < / span > < span class = cF0 > ] ; < / span > < span class = cF2 > // "Mapping Nonce" 96 bits of random vals.</span><span class=cF0>
< a name = " l17 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > protocol ; < / span > < span class = cF2 > // 6 TCP. 17 UDP. 0 'all protocols'.</span><span class=cF0>
< a name = " l18 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > reserved [ < / span > < span class = cFE > 3 < / span > < span class = cF0 > ] ; < / span > < span class = cF2 > // 24 bits, TX must be 0, ignore on RX.</span><span class=cF0>
2021-07-03 05:07:57 +01:00
< a name = " l19 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l20 " > < / a > < / span > < span class = cF9 > U16 < / span > < span class = cF0 > internal_port ;
< a name = " l21 " > < / a > < / span > < span class = cF2 > /*</span><span class=cF0> </span><span class=cF2>internal_port. 0 'all ports' legal only on lifetime 0 (delete) or client req 'all ports'.</span><span class=cF0>
< a name = " l22 " > < / a > < / span > < span class = cF2 > must be ignored on RX . */ < / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = " l23 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l24 " > < / a > < / span > < span class = cF9 > U16 < / span > < span class = cF0 > external_port ;
< a name = " l25 " > < / a > < / span > < span class = cF2 > /*</span><span class=cF0> </span><span class=cF2>external_port. 'suggested'. if client doesnt know it or has no preference it must be 0.*/ < / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = " l26 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l27 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > external_ip [ < / span > < span class = cFE > 16 < / span > < span class = cF0 > ] ;
< a name = " l28 " > < / a > < / span > < span class = cF2 > /*</span><span class=cF0> </span><span class=cF2>external_ip. 'suggested'. if client doesnt know it or no preference,</span><span class=cF0>
< a name = " l29 " > < / a > < / span > < span class = cF2 > it must use ' address - family - specific all - zero address . */ < / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = " l30 " > < / a >
< a name = " l31 " > < / a > } ;
< a name = " l32 " > < / a >
< a name = " l33 " > < / a > < / span > < span class = cF9 > I64 < / span > < span class = cF0 > PCPSendMapRequest ( < / span > < span class = cF9 > U16 < / span > < span class = cF0 > internal_port , < / span > < span class = cF9 > U16 < / span > < span class = cF0 > external_port = < / span > < span class = cF3 > NULL < / span > < span class = cF0 > , < / span > < span class = cF9 > U32 < / span > < span class = cF0 > external_ip = < / span > < span class = cF3 > NULL < / span > < span class = cF0 > )
< a name = " l34 " > < / a > {
2021-07-04 23:11:34 +01:00
< a name = " l35 " > < / a > < / span > < span class = cF1 > U8 < / span > < span class = cF0 > * frame ;
< a name = " l36 " > < / a > CPCPMapRequest * request ;
< a name = " l37 " > < / a > < / span > < span class = cF9 > I64 < / span > < span class = cF0 > de_index ;
< a name = " l38 " > < / a > < / span > < span class = cF9 > I64 < / span > < span class = cF0 > i ;
2021-07-03 05:07:57 +01:00
< a name = " l39 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l40 " > < / a > de_index = UDPPacketAllocate ( & amp ; frame ,
< a name = " l41 " > < / a > IPV4AddressGet ,
< a name = " l42 " > < / a > < / span > < span class = cFE > 5351 < / span > < span class = cF0 > ,
< a name = " l43 " > < / a > ipv4_globals . ipv4_router_address ,
< a name = " l44 " > < / a > < / span > < span class = cFE > 5351 < / span > < span class = cF0 > ,
< a name = " l45 " > < / a > < / span > < span class = cF1 > sizeof < / span > < span class = cF7 > ( < / span > < span class = cF0 > CPCPMapRequest < / span > < span class = cF7 > ) < / span > < span class = cF0 > ) ;
< a name = " l46 " > < / a > < / span > < span class = cF1 > if < / span > < span class = cF0 > ( de_index & lt ; < / span > < span class = cFE > 0 < / span > < span class = cF0 > )
< a name = " l47 " > < / a > < / span > < span class = cF7 > { < / span > < span class = cF0 >
< a name = " l48 " > < / a > NetErr ( < / span > < span class = cF6 > & quot ; PCP SEND MAP REQ : Failed , UDPPacketAllocate returned error . & quot ; < / span > < span class = cF0 > ) ;
< a name = " l49 " > < / a > < / span > < span class = cF1 > return < / span > < span class = cF0 > de_index ;
< a name = " l50 " > < / a > < / span > < span class = cF7 > } < / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = " l51 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l52 " > < / a > request = frame ;
2021-07-03 05:07:57 +01:00
< a name = " l53 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l54 " > < / a > request - & gt ; header . version = < / span > < span class = cFE > 2 < / span > < span class = cF0 > ;
< a name = " l55 " > < / a > request - & gt ; header . opcode = < / span > < span class = cFE > 1 < / span > < span class = cF0 > ; < / span > < span class = cF2 > // MAP</span><span class=cF0>
< a name = " l56 " > < / a > request - & gt ; header . req_lifetime = < / span > < span class = cFE > 60 < / span > < span class = cF0 > ; < / span > < span class = cF2 > // live for 1 min.</span><span class=cF0>
2021-07-03 05:07:57 +01:00
< a name = " l57 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l58 " > < / a > < / span > < span class = cF2 > // force local IPV4 addr into IPV4-mapped-IPV6</span><span class=cF0>
< a name = " l59 " > < / a > < / span > < span class = cF1 > for < / span > < span class = cF0 > ( i = < / span > < span class = cFE > 0 < / span > < span class = cF0 > ; i & lt ; < / span > < span class = cFE > 10 < / span > < span class = cF0 > ; i + + ) < / span > < span class = cF2 > // first 80 bits 0</span><span class=cF0>
< a name = " l60 " > < / a > request - & gt ; header . pcp_client_ip [ i ] = < / span > < span class = cFE > 0 < / span > < span class = cF0 > ;
2021-07-03 05:07:57 +01:00
< a name = " l61 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l62 " > < / a > < / span > < span class = cF1 > for < / span > < span class = cF0 > ( ; i & lt ; < / span > < span class = cFE > 10 < / span > < span class = cF0 > + < / span > < span class = cFE > 2 < / span > < span class = cF0 > ; i + + ) < / span > < span class = cF2 > // next 16 bits 1</span><span class=cF0>
< a name = " l63 " > < / a > request - & gt ; header . pcp_client_ip [ i ] = < / span > < span class = cFE > 0xFF < / span > < span class = cF0 > ;
2021-07-03 05:07:57 +01:00
< a name = " l64 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l65 " > < / a > * ( & amp ; request - & gt ; header . pcp_client_ip [ i ] < / span > < span class = cF7 > ( < / span > < span class = cF9 > U32 < / span > < span class = cF0 > * < / span > < span class = cF7 > ) < / span > < span class = cF0 > ) = < / span > < span class = cF5 > EndianU32 < / span > < span class = cF0 > ( IPV4AddressGet ) ;
< a name = " l66 " > < / a > < / span > < span class = cF2 > //</span><span class=cF0>
2021-07-03 05:07:57 +01:00
< a name = " l67 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l68 " > < / a > < / span > < span class = cF2 > // set random 'nonce'</span><span class=cF0>
< a name = " l69 " > < / a > < / span > < span class = cF1 > for < / span > < span class = cF0 > ( i = < / span > < span class = cFE > 0 < / span > < span class = cF0 > ; i & lt ; < / span > < span class = cFE > 12 < / span > < span class = cF0 > ; i + + )
< a name = " l70 " > < / a > request - & gt ; nonce [ i ] = < / span > < span class = cF5 > RandU8 < / span > < span class = cF0 > ;
2021-07-03 05:07:57 +01:00
< a name = " l71 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l72 " > < / a > request - & gt ; protocol = IP_PROTOCOL_UDP ;
2021-07-03 05:07:57 +01:00
< a name = " l73 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l74 " > < / a > request - & gt ; internal_port = internal_port ;
< a name = " l75 " > < / a > request - & gt ; external_port = external_port ;
2021-07-03 05:07:57 +01:00
< a name = " l76 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l77 " > < / a > < / span > < span class = cF1 > if < / span > < span class = cF0 > ( ! external_ip )
< a name = " l78 " > < / a > < / span > < span class = cF7 > { < / span > < span class = cF0 > < / span > < span class = cF2 > // if no specified ext ip, use specific ipv4-mapped-ipv6 all-zeroes address.</span><span class=cF0>
< a name = " l79 " > < / a > < / span > < span class = cF1 > for < / span > < span class = cF0 > ( i = < / span > < span class = cFE > 0 < / span > < span class = cF0 > ; i & lt ; < / span > < span class = cFE > 10 < / span > < span class = cF0 > ; i + + )
< a name = " l80 " > < / a > request - & gt ; external_ip [ i ] = < / span > < span class = cFE > 0 < / span > < span class = cF0 > ;
< a name = " l81 " > < / a > < / span > < span class = cF1 > for < / span > < span class = cF0 > ( ; i & lt ; < / span > < span class = cFE > 10 < / span > < span class = cF0 > + < / span > < span class = cFE > 2 < / span > < span class = cF0 > ; i + + )
< a name = " l82 " > < / a > request - & gt ; external_ip [ i ] = < / span > < span class = cFE > 0xFF < / span > < span class = cF0 > ;
< a name = " l83 " > < / a > * ( & amp ; request - & gt ; external_ip [ i ] < / span > < span class = cF7 > ( < / span > < span class = cF9 > U32 < / span > < span class = cF0 > * < / span > < span class = cF7 > ) < / span > < span class = cF0 > ) = < / span > < span class = cFE > 0 < / span > < span class = cF0 > ;
< a name = " l84 " > < / a > < / span > < span class = cF7 > } < / span > < span class = cF0 >
< a name = " l85 " > < / a > < / span > < span class = cF1 > else < / span > < span class = cF0 >
< a name = " l86 " > < / a > < / span > < span class = cF7 > { < / span > < span class = cF0 > < / span > < span class = cF2 > // else, map to param ip</span><span class=cF0>
< a name = " l87 " > < / a > < / span > < span class = cF1 > for < / span > < span class = cF0 > ( i = < / span > < span class = cFE > 0 < / span > < span class = cF0 > ; i & lt ; < / span > < span class = cFE > 10 < / span > < span class = cF0 > ; i + + )
< a name = " l88 " > < / a > request - & gt ; external_ip [ i ] = < / span > < span class = cFE > 0 < / span > < span class = cF0 > ;
< a name = " l89 " > < / a > < / span > < span class = cF1 > for < / span > < span class = cF0 > ( ; i & lt ; < / span > < span class = cFE > 10 < / span > < span class = cF0 > + < / span > < span class = cFE > 2 < / span > < span class = cF0 > ; i + + )
< a name = " l90 " > < / a > request - & gt ; external_ip [ i ] = < / span > < span class = cFE > 0xFF < / span > < span class = cF0 > ;
< a name = " l91 " > < / a > * ( & amp ; request - & gt ; external_ip [ i ] < / span > < span class = cF7 > ( < / span > < span class = cF9 > U32 < / span > < span class = cF0 > * < / span > < span class = cF7 > ) < / span > < span class = cF0 > ) = < / span > < span class = cF5 > EndianU32 < / span > < span class = cF0 > ( external_ip ) ;
< a name = " l92 " > < / a > < / span > < span class = cF7 > } < / span > < span class = cF0 >
2021-07-03 05:07:57 +01:00
< a name = " l93 " > < / a >
2021-07-04 23:11:34 +01:00
< a name = " l94 " > < / a > UDPPacketFinish ( de_index ) ;
< a name = " l95 " > < / a > < / span > < span class = cF1 > return < / span > < span class = cF0 > < / span > < span class = cFE > 0 < / span > < span class = cF0 > ;
2021-07-03 05:07:57 +01:00
< a name = " l96 " > < / a >
< a name = " l97 " > < / a > }
< a name = " l98 " > < / a >
< a name = " l99 " > < / a > PCPSendMapRequest ( < / span > < span class = cFE > 0xDEAD < / span > < span class = cF0 > , < / span > < span class = cFE > 0xBEEF < / span > < span class = cF0 > ) ; < / span > < / pre > < / body >
< / html >