Author: lwalter Date: 2007-08-14 18:05:09 +0200 (Tue, 14 Aug 2007) New Revision: 534
Modified: ofw/inetv6/arp.fth ofw/inetv6/dhcp.fth ofw/inetv6/dns.fth ofw/inetv6/dnsv6.fth ofw/inetv6/ethernet.fth ofw/inetv6/ip.fth ofw/inetv6/ipv6.fth ofw/inetv6/neighdis.fth ofw/inetv6/netload.fth Log: Use IPv4 DNS server to get IPv6 address; Use gateway when his-ip-addr is not local
Modified: ofw/inetv6/arp.fth =================================================================== --- ofw/inetv6/arp.fth 2007-08-10 10:36:53 UTC (rev 533) +++ ofw/inetv6/arp.fth 2007-08-14 16:05:09 UTC (rev 534) @@ -158,7 +158,11 @@ broadcast-en-addr his-en-addr copy-en-addr ( ip-type ) else ( ip-type 'ip-adr ) his-ip-addr copy-ip-addr ( ip-type ) - his-en-addr broadcast-en-addr en= if do-arp then ( ip-type ) + his-ip-addr my-ip-addr ip-prefix=? if + his-en-addr broadcast-en-addr en= if do-arp then ( ip-type ) + else + router-en-addr his-en-addr copy-en-addr \ Not local, go through the gateway + then then his-en-addr swap exit then ( 'dest-adr type )
Modified: ofw/inetv6/dhcp.fth =================================================================== --- ofw/inetv6/dhcp.fth 2007-08-10 10:36:53 UTC (rev 533) +++ ofw/inetv6/dhcp.fth 2007-08-14 16:05:09 UTC (rev 534) @@ -249,6 +249,7 @@ 0 file-name-buf c! unknown-ip-addr name-server-ip copy-ip-addr unknown-ip-addr dhcp-server-ip copy-ip-addr + unknown-ip-addr name-server-ip-slave copy-ip-addr ;
also forth definitions @@ -483,7 +484,9 @@ then then
- d# 6 find-option if drop name-server-ip copy-ip-addr then + d# 6 find-option if over name-server-ip copy-ip-addr + 4 > if 4 + name-server-ip-slave copy-ip-addr else drop then + then d# 28 find-option if drop broadcast-ip-addr copy-ip-addr then d# 15 find-option if 'domain-name place-cstr drop then d# 12 find-option if 'client-name place-cstr drop then @@ -493,8 +496,11 @@ bootnet-debug if indent ." Received DHCP ACK" cr name-server-ip known? if - indent indent ." Name server: " name-server-ip .ipaddr cr + indent indent ." Master name server: " name-server-ip .ipaddr cr then + name-server-ip-slave known? if + indent indent ." Slave name server: " name-server-ip-slave .ipaddr cr + then broadcast-ip-addr if indent indent ." IP broadcast: " broadcast-ip-addr (.ipaddr) cr then
Modified: ofw/inetv6/dns.fth =================================================================== --- ofw/inetv6/dns.fth 2007-08-10 10:36:53 UTC (rev 533) +++ ofw/inetv6/dns.fth 2007-08-14 16:05:09 UTC (rev 534) @@ -13,10 +13,20 @@
\ DNS question format: QNAME-variable_length, QTYPE(/w), QCLASS(/w) \ QTYPE value for "A" (host name) is 1 +\ QTYPE value for "AAAA" (IPv6 hostname) is h# 1c \ QCLASS value for "IN" (Internet) is 1
-d# 1022 value fw-port# +\ d# 1022 value fw-port# \ It's been assigned by IANA. +h# 800a constant fw-port# \ It's unassigned as of 8/13/2007.
+d# 2000 constant dns-timeout + +2 value #retries-a +2 value #retries-aaaa + +0 value qtype +1 constant qclass + \ Encode/decode various DNS data types : +dnsw ( w -- ) wbsplit +xb +xb ; : -dnsw ( -- w ) -xb -xb swap bwjoin ; @@ -109,7 +119,7 @@ \ ID flags #questions #answers #namesrvrs #additional dns-xid +dnsw h# 100 +dnsw 1 +dnsw 0 +dnsw 0 +dnsw 0 +dnsw +dns-host - 1 +dnsw 1 +dnsw + qtype +dnsw qclass +dnsw x$ fw-port# dns-port# send-udp-packet r> /dns-query free-udp ; @@ -164,7 +174,7 @@
-dnsw -dnsw wljoin ( class.type ) -dnsl drop ( class.type ) \ Discard TTL - h# 1.0001 = if ( ) + qtype qclass wljoin = if ( ) -dnsw drop \ Discard RDLENGTH (it better be 4!) x$ drop true ( 'ip true ) else ( ) @@ -192,21 +202,25 @@ \ The host name can be either a simple name (e.g. "pi") or a \ fully-qualified domain name (e.g. "pi.firmworks.com"). : try-resolve ( hostname$ -- 'ip ) - name-server-ip set-dest-ip ( hostname$ ) - d# 2000 set-timeout ( hostname$ ) - send-dns-query ( ) - dns-xid dns-port# fw-port# receive-dns-reply ( error? ) - 1 and throw ( ) - get-host-addr ( answer-ip ) + dns-timeout set-timeout ( hostname$ ) + send-dns-query ( ) + dns-xid dns-port# fw-port# receive-dns-reply ( error? ) + 1 and throw ( ) + get-host-addr ( answer-ip ) ; -: (resolve) ( hostname$ -- ) - bootnet-debug if ( hostname$ ) - ." Using DNS to find the IP address of " ( hostname$ ) - 2dup type cr ( hostname$ ) - then ( hostname$ ) +: resolve-a ( hostname$ -- 'ip ) + bootnet-debug if ( hostname$ ) + ." Using DNS to find the IP address of " ( hostname$ ) + 2dup type cr ( hostname$ ) + then ( hostname$ )
- d# 20 0 do \ Try 20 times at 2 seconds per try - 2dup ['] try-resolve catch ?dup if ( hostname$ x x err ) + 1 to qtype + #retries-a 0 do \ Try 20 times at 2 seconds per try + name-server-ip set-dest-ip + i 1 and if + name-server-ip-slave known? if name-server-ip-slave set-dest-ip then + then + 2dup ['] try-resolve catch ?dup if ( hostname$ x x err ) nip nip ( hostname$ err ) 1 <> if ( hostname$ ) bootnet-debug if ( hostname$ ) @@ -214,21 +228,66 @@ then ( hostname$ ) true abort" Unknown hostname" then ( hostname$ ) - else ( hostname$ 'ip ) - bootnet-debug if ( hostname$ 'ip ) - ." Got IP address " dup .ipaddr cr ( hostname$ 'ip ) - then ( hostname$ 'ip ) + else ( hostname$ 'ip ) + bootnet-debug if ( hostname$ 'ip ) + indent ." Got IP address " dup .ipaddr cr ( hostname$ 'ip ) + then ( hostname$ 'ip )
- nip nip ( 'ip ) + nip nip ( 'ip ) unloop exit - then ( hostname$ ) - loop ( hostname$ ) + then ( hostname$ ) + loop ( hostname$ )
- bootnet-debug if ." No answer to DNS request" cr then ( hostname$ ) + bootnet-debug if ." No answer to DNS A request" cr then ( hostname$ ) true abort" DNS: No answer" ; -\ : resolve ( 'ip hostname$ -- ) (resolve) swap copy-ip-addr ;
+[ifdef] include-ipv6 +: resolve-aaaa ( hostname$ -- ) + bootnet-debug if ( hostname$ ) + ." Using DNS AAAA to find the IPv6 address of " ( hostname$ ) + 2dup type cr ( hostname$ ) + then + + h# 1c to qtype + #retries-aaaa 0 do \ Try 20 times at 2 seconds per try + name-server-ip set-dest-ip + i 1 and if + name-server-ip-slave known? if name-server-ip-slave set-dest-ip then + then + 2dup ['] try-resolve catch ?dup if ( hostname$ x x err ) + nip nip ( hostname$ err ) + 1 <> if ( hostname$ ) + bootnet-debug if ( hostname$ ) + indent ." Unknown IPv6 hostname: " 2dup type cr ( hostname ) + then ( hostname$ ) + true abort" Unknown IPv6 hostname" + then ( hostname$ ) + else ( hostname$ 'ip ) + bootnet-debug if ( hostname$ 'ip ) + indent ." Got IPv6 address " dup .ipv6 cr ( hostname$ 'ip ) + then ( hostname$ 'ip ) + + set-dest-ipv6 2drop ( ) + unloop exit + then ( hostname$ ) + loop ( hostname$ ) + + bootnet-debug if indent ." No answer to DNS AAAA request" cr then ( hostname$ ) + true abort" DNS AAAA: No answer" +; +[else] +: resolve-aaaa ( hostname$ -- ) abort" IPv4 AAAA DNS not supported" ; +[then] + +false value resolve-flag +: resolvev4 ( hostname$ -- ) + false to resolve-flag + 2dup ['] resolve-a catch if 2drop else true to resolve-flag set-dest-ip then + ['] resolve-aaaa catch if 2drop else true to resolve-flag then + resolve-flag not abort" DNS: No answer" +; + headerless : ?bad-ip ( flag -- ) abort" Bad host name or address" ; 4 buffer: ip-buf @@ -245,8 +304,7 @@ headers : $set-host ( hostname$ -- ) dup 0= ?bad-ip - over c@ [char] 0 [char] 9 between if $>ip else (resolve) then - set-dest-ip + over c@ [char] 0 [char] 9 between if $>ip set-dest-ip else resolvev4 then ; \ LICENSE_BEGIN \ Copyright (c) 2006 FirmWorks
Modified: ofw/inetv6/dnsv6.fth =================================================================== --- ofw/inetv6/dnsv6.fth 2007-08-10 10:36:53 UTC (rev 533) +++ ofw/inetv6/dnsv6.fth 2007-08-14 16:05:09 UTC (rev 534) @@ -7,26 +7,46 @@
[ifndef] include-ipv4 : $>ip ( hostname$ -- 'ip ) .ipv4-not-supported ; -: (resolve) ( hostname$ -- 'ip ) .ipv4-not-supported ; +: resolvev4 ( hostname$ -- ) .ipv4-not-supported ; : set-dest-ip ( buf -- ) .ipv4-not-supported ; : ?bad-ip ( flag -- ) abort" Bad host name or address" ; [then]
+: resolvev6 ( hostname$ -- ) + true to use-ipv6? + unknown-ipv6-addr his-ipv6-addr copy-ipv6-addr + abort" IPv6 DNS not supported yet" +; + headers -: (resolvev6) ( hostname$ -- 'ip ) ;
\ XXX Try (resolve) or (resolve6) first. If fail, try the other one. -: (resolve) ( hostname$ -- 'ip ) - use-ipv6? if (resolvev6) true else (resolve) false then - dup to use-ipv6? - if set-dest-ipv6 else set-dest-ip then +: (resolve) ( hostname$ -- ) + 2dup ['] resolvev6 catch if + 2drop + false to use-ipv6? + resolvev4 + else + 2drop + then + use-ipv6-ok? dup to use-ipv6? if \ Make sure all the addresses are set properly + his-ipv6-addr (set-dest-ipv6) + bootnet-debug if ." Use IPv6 protocol" cr then + else + his-ip-addr (set-dest-ip) + bootnet-debug if ." Use IP protocol" cr then + then ;
: $set-host ( hostname$ -- ) dup 0= ?bad-ip 2dup ['] $>ip catch if 2drop else false to use-ipv6? set-dest-ip 2drop exit then - 2dup ipv6-buf ['] $ipv6# catch nip nip not if true to use-ipv6? ipv6-buf set-dest-ipv6 exit then - (resolve) + 2dup ipv6-buf ['] $ipv6# catch if + 3drop (resolve) + else + 2drop + true to use-ipv6? ipv6-buf set-dest-ipv6 + then ;
\ LICENSE_BEGIN
Modified: ofw/inetv6/ethernet.fth =================================================================== --- ofw/inetv6/ethernet.fth 2007-08-10 10:36:53 UTC (rev 533) +++ ofw/inetv6/ethernet.fth 2007-08-14 16:05:09 UTC (rev 534) @@ -39,11 +39,13 @@
/e buffer: my-en-addr /e buffer: his-en-addr -/e buffer: routerv6-en-addr +/e buffer: router-en-addr \ IPv4 gateway/router +/e buffer: routerv6-en-addr \ IPv6 router /e buffer: mc-en-addr
-: .my-link-addr ( -- ) ." My MAC: " my-en-addr .enaddr ; -: .his-link-addr ( -- ) ." His MAC: " his-en-addr .enaddr ; +: .my-link-addr ( -- ) ." My MAC: " my-en-addr .enaddr ; +: .his-link-addr ( -- ) ." His MAC: " his-en-addr .enaddr ; +: .router-en-addr ( -- ) ." Gateway MAC: " router-en-addr .enaddr ; : .routerv6-en-addr ( -- ) ." IPv6 router MAC: " routerv6-en-addr .enaddr ;
create mc-en-addr-all-nodes h# 33 c, h# 33 c, h# 00 c, 0 c, 0 c, 1 c,
Modified: ofw/inetv6/ip.fth =================================================================== --- ofw/inetv6/ip.fth 2007-08-10 10:36:53 UTC (rev 533) +++ ofw/inetv6/ip.fth 2007-08-14 16:05:09 UTC (rev 534) @@ -42,6 +42,7 @@ headers /i buffer: his-ip-addr /i buffer: name-server-ip +/i buffer: name-server-ip-slave ' 'domain-name " domain-name" chosen-string
headerless @@ -125,13 +126,12 @@ 0 instance value last-ip-packet
headers +: (set-dest-ip) ( buf -- ) + his-ip-addr copy-ip-addr + unlock-link-addr +; : set-dest-ip ( buf -- ) - dup his-ip-addr ip= if - drop - else - his-ip-addr copy-ip-addr - unlock-link-addr - then + dup his-ip-addr ip= if drop else (set-dest-ip) then ;
: lock-ip-address ( -- )
Modified: ofw/inetv6/ipv6.fth =================================================================== --- ofw/inetv6/ipv6.fth 2007-08-10 10:36:53 UTC (rev 533) +++ ofw/inetv6/ipv6.fth 2007-08-14 16:05:09 UTC (rev 534) @@ -135,6 +135,10 @@ : ipv6-addr-local? ( adr-buf -- flag ) c@ h# e0 and h# 20 <> ;
: use-routerv6? ( -- flag ) routerv6-en-addr unknown-en-addr? not ; +: use-ipv6-ok? ( -- flag ) + his-ipv6-addr knownv6? + his-ipv6-addr ipv6-addr-local? not if use-routerv6? and then +;
/ipv6 buffer: server-ipv6-addr : use-serverv6? ( -- flag ) server-ipv6-addr knownv6? ; @@ -174,22 +178,21 @@ [then]
headers -: set-dest-ipv6 ( buf -- ) - dup his-ipv6-addr ipv6= if - drop +: (set-dest-ipv6) ( buf -- ) + his-ipv6-addr copy-ipv6-addr + set-his-ipv6-addr-mc + his-ipv6-addr ipv6-addr-local? if + unlock-link-addr + my-ipv6-addr-link-local else - his-ipv6-addr copy-ipv6-addr - set-his-ipv6-addr-mc - his-ipv6-addr ipv6-addr-local? if - unlock-link-addr - my-ipv6-addr-link-local - else - use-routerv6? if routerv6-en-addr his-en-addr copy-en-addr then - my-ipv6-addr-global - then - my-ipv6-addr copy-ipv6-addr + use-routerv6? if routerv6-en-addr his-en-addr copy-en-addr then + my-ipv6-addr-global then + my-ipv6-addr copy-ipv6-addr ; +: set-dest-ipv6 ( buf -- ) + dup his-ipv6-addr ipv6= if drop else (set-dest-ipv6) then +;
: lock-ipv6-address ( -- ) the-struct >r last-ip-packet set-struct
Modified: ofw/inetv6/neighdis.fth =================================================================== --- ofw/inetv6/neighdis.fth 2007-08-10 10:36:53 UTC (rev 533) +++ ofw/inetv6/neighdis.fth 2007-08-14 16:05:09 UTC (rev 534) @@ -27,8 +27,8 @@ /ipv6 buffer: his-ipv6-addr-temp : do-neighbor-discovery ( -- ) bootnet-debug if - ." ICMPv6 ND protocol: Getting MAC address for IP address: " - his-ipv6-addr .ipv6 cr + ." ICMPv6 ND protocol: Getting MAC address for IPv6 address: " cr + indent his-ipv6-addr .ipv6 cr then
his-ipv6-addr his-ipv6-addr-temp copy-ipv6-addr @@ -56,7 +56,11 @@ broadcast-en-addr his-en-addr copy-en-addr ( ip-type ) else ( ip-type 'ip-adr ) his-ip-addr copy-ip-addr ( ip-type ) - his-en-addr broadcast-en-addr en= if do-arp then ( ip-type ) + his-ip-addr my-ip-addr ip-prefix=? if + his-en-addr broadcast-en-addr en= if do-arp then ( ip-type ) + else + router-en-addr his-en-addr copy-en-addr + then then his-en-addr swap [then] @@ -76,7 +80,7 @@ bootnet-debug if ." My IPv6 configuration (stateless autoconfiguration): " cr indent .my-ipv6-addr-link-local cr - my-ipv6-addr-global unknown-ipv6-addr? not if + my-ipv6-addr-global knownv6? if indent .my-ipv6-addr-global cr indent .my-prefix cr then
Modified: ofw/inetv6/netload.fth =================================================================== --- ofw/inetv6/netload.fth 2007-08-10 10:36:53 UTC (rev 533) +++ ofw/inetv6/netload.fth 2007-08-14 16:05:09 UTC (rev 534) @@ -26,7 +26,9 @@ ;
: show-router-addr ( -- ) - bootnet-debug if ." Router IP: = " router-ip-addr .ipaddr cr then + bootnet-debug if + .router-en-addr ." Router IP: = " router-ip-addr .ipaddr cr + then ;
: show-all-en-ip-address ( -- ) @@ -102,6 +104,7 @@ indent ." Boot server: " server-ip-addr .ipaddr cr then use-router? if + indent .router-en-addr cr indent ." Router: " router-ip-addr .ipaddr cr then then @@ -400,6 +403,12 @@ 2drop false ;
+: resolve-router-en-addr ( -- ) + router-ip-addr his-ip-addr copy-ip-addr + do-arp + his-en-addr router-en-addr copy-en-addr +; + defer configured ' noop to configured : configure ( -- ) use-last? if configured exit then @@ -430,6 +439,7 @@ server-ip-addr set-dest-ip then then + use-router? if resolve-router-en-addr then \ Find router's MAC address show-all-en-ip-address configured ;