Author: lwalter Date: 2007-08-28 00:44:27 +0200 (Tue, 28 Aug 2007) New Revision: 579
Modified: ofw/inetv6/dhcpv6.fth ofw/inetv6/ipv6.fth ofw/inetv6/udpv6.fth Log: Get DNS ipv6 address from stateless DHCPv6 server if the router does not provide the info
Modified: ofw/inetv6/dhcpv6.fth =================================================================== --- ofw/inetv6/dhcpv6.fth 2007-08-24 00:08:52 UTC (rev 578) +++ ofw/inetv6/dhcpv6.fth 2007-08-27 22:44:27 UTC (rev 579) @@ -36,7 +36,7 @@ 0 sfield do6-data \ Option data constant /do6-hdr
-d# 1024 constant /dhcpv6-packet +d# 1024 constant max-dhcpv6-packet
\ do6-code values \ 1 client ID @@ -55,14 +55,22 @@ d# 256 buffer: 'root-path d# 256 buffer: 'client-name d# 256 buffer: 'vendor-options + headers ' 'client-name " client-name" chosen-string ' 'vendor-options " vendor-options" chosen-string ' 'root-path " root-path" chosen-string : domain-name ( -- adr len ) 'domain-name cscount ; + +headerless +instance variable xid [then]
-0 instance value dhcpv6-packet +headers + +0 instance value dhcp-pref \ DHCPv6 server preference +0 instance value dhcpv6-packet \ DHCPv6 packet to send +0 instance value dhcpv6-reply \ DHCPv6 packet received 0 instance value dhcpv6-len \ Actual length of received DHCPv6 packet 0 instance value dhcpv6-option \ Pointer to option field in dhcpv6-packet
@@ -75,15 +83,13 @@ : op$! ( $ -- ) tuck dhcpv6-option swap move +dhcpv6-option ;
: allocate-dhcpv6 ( size -- ) - allocate-udp dup is dhcpv6-packet set-struct + allocate-udpv6 dup is dhcpv6-packet set-struct set-dhcpv6-option
- get-msecs start-time ! - \ Set "random" transaction ID and random number generator seed my-en-addr 2 + xl@ get-msecs xor dup xid ! rn ! ; -: free-dhcpv6 ( size -- ) dhcpv6-packet swap free-udp ; +: free-dhcpv6 ( size -- ) dhcpv6-packet swap free-udpv6 ;
: init-dhcpv6 ( -- ) [ifndef] include-ipv4 @@ -101,23 +107,53 @@ ; previous definitions
-: send-dhcpv6-packet ( size op -- ) - dh6-op c! - xid dh6-xid! - dhcpv6-packet swap client-port dhcpv6-port send-udpv6-packet +: .dhcpv6-err ( status -- ) + ?dup 0= if exit then + ." DHCPv6: " + case + 1 of ." unspecified failure" endof + 2 of ." no address available" endof + 3 of ." no binding" endof + 4 of ." not on-link" endof + 5 of ." use multicast" endof + ( otherwise ) ." unknown error: " dup u. + endcase + cr ;
-: detect-dhcpv6-packet ( op -- timeout? ) +: process-dhcpv6-options ( adr len -- error? ) + begin dup 0> while + over be-w@ case \ Option code + 7 of over 4 + c@ to dhcp-pref endof \ Preference + d# 13 of over 4 + be-w@ dup .dhcpv6-err \ Reply status + if 2drop true exit then endof + d# 25 of over 4 + name-server-ipv6 copy-ipv6-addr endof \ RDNSS + endcase + over 2 + be-w@ 4 + /string \ Advance to next option + repeat 2drop false +; + +: receive-dhcpv6-packet ( op -- timeout? ) >r dhcpv6-timeout set-timeout begin client-port receive-udp-packet 0= while ( adr,len src-port ) - drop to dhcpv6-len set-struct -the-struct dhcpv6-len dump cr - dh6-xid@ xid @ h# ff.ffff = dh6-op c@ r@ = and if r> drop false exit then + drop to dhcpv6-len dup set-struct to dhcpv6-reply + dh6-xid@ xid @ h# ff.ffff and = dh6-op c@ r@ = and if r> drop false exit then repeat r> drop true ;
+: detect-dhcpv6-packet ( op -- error? ) + receive-dhcpv6-packet ?dup if exit then + dh6-options dhcpv6-len /dhcpv6-hdr - process-dhcpv6-options +; + +: send-dhcpv6-packet ( size op -- ) + dh6-op c! + xid @ dh6-xid! + dhcpv6-packet swap client-port dhcpv6-port send-udpv6-packet +; + : option-client-id ( -- ) 1 opw! \ Client ID option /e 4 + opw! \ Option len @@ -151,16 +187,14 @@ ;
: do-dhcpv6-stateless ( -- ) - ." DHCPv6 stateless auto configuration not supported yet" cr exit - bootnet-debug if - ." DHCPv6 protocol: Getting network information" cr + ." DHCPv6 protocol: Information Request" cr then - /dhcpv6-packet allocate-dhcpv6 + max-dhcpv6-packet allocate-dhcpv6
- ['] dhcpv6-req-info catch drop + ['] dhcpv6-req-info catch if indent ." Timeout waiting for requested info" cr then
- /dhcpv6-packet free-dhcpv6 + max-dhcpv6-packet free-dhcpv6 ;
: do-dhcpv6-stateful ( -- )
Modified: ofw/inetv6/ipv6.fth =================================================================== --- ofw/inetv6/ipv6.fth 2007-08-24 00:08:52 UTC (rev 578) +++ ofw/inetv6/ipv6.fth 2007-08-27 22:44:27 UTC (rev 579) @@ -78,7 +78,6 @@ /ipv6 buffer: my-ipv6-addr-global /ipv6 buffer: router-ipv6-addr /ipv6 buffer: name-server-ipv6 -/ipv6 buffer: dhcp-ipv6-addr
headerless
@@ -107,6 +106,7 @@ >r r@ his-ipv6-addr-mc-sol-node ipv6= \ His solicited node address? r@ ipv6-addr-mc-all-nodes ipv6= or \ Multicast all-nodes? + r@ ipv6-addr-mc-all-dhcp ipv6= or \ Multicast all-dhcp? r> ipv6-addr-mc-all-routers ipv6= or \ Multicast all-routers? ; : my-ipv6-addr-mc? ( adr-buf -- flag )
Modified: ofw/inetv6/udpv6.fth =================================================================== --- ofw/inetv6/udpv6.fth 2007-08-24 00:08:52 UTC (rev 578) +++ ofw/inetv6/udpv6.fth 2007-08-27 22:44:27 UTC (rev 579) @@ -29,18 +29,18 @@ /udpv6-pseudo-hdr instance buffer: udpv6-pseudo-hdr
\ Assumes the-struct is the UDP packet. -: fill-udpv6-pseudo-hdr ( -- ) +: fill-udpv6-pseudo-hdr ( his-ipv6 my-ipv6 -- ) /ipv6-header negate +struct udpv6-pseudo-hdr ( udp-pseudo-addr ) - my-ipv6-addr over udpv6-src-addr copy-ipv6-addr ( udp-pseudo-addr ) - his-ipv6-addr over udpv6-dst-addr copy-ipv6-addr ( udp-pseudo-addr ) + tuck ( my-ipv6-addr ) udpv6-src-addr copy-ipv6-addr ( udp-pseudo-addr ) + tuck ( his-ipv6-addr ) udpv6-dst-addr copy-ipv6-addr ( udp-pseudo-addr ) IP_HDR_UDP over udpv6-protocol-id xl! ( udp-pseudo-addr ) /ipv6-header +struct ( udp-pseudo-addr ) udp-length xw@ swap udpv6-len-copy xl! ( ) ;
\ Assumes the-struct is the UDP packet. -: calc-udpv6-checksum ( -- checksum ) +: calc-udpv6-checksum ( his-ipv6 my-ipv6 -- checksum ) fill-udpv6-pseudo-hdr 0 udpv6-pseudo-hdr /udpv6-pseudo-hdr (oc-checksum) ( cksum ) 0 udp-checksum xw! @@ -54,7 +54,8 @@ /udp-header + dup udp-length xw! ( udp-len ) 0 udp-checksum xw! ( udp-len )
- calc-udpv6-checksum udp-checksum xw! ( udp-len ) + his-ipv6-addr my-ipv6-addr calc-udpv6-checksum udp-checksum xw! + ( udp-len )
the-struct swap IP_HDR_UDP send-ipv6-packet ( ) ; @@ -76,10 +77,15 @@ ; headerless
+\ XXX Assume no extra IPv6 headers : bad-udpv6-checksum? ( -- bad? ) - udp-checksum xw@ dup if ( checksum ) - calc-udpv6-checksum <> ( bad? ) - then ( bad? ) + udp-checksum xw@ dup if ( checksum ) + the-struct dup >r ( checksum ) ( R: udp ) + /ipv6-header - set-struct ( checksum ) ( R: udp ) + ipv6-source-addr ipv6-dest-addr ( checksum his-ipv6 my-ipv6 ) ( R: udp ) + r> set-struct ( checksum his-ipv6 my-ipv6 ) + calc-udpv6-checksum <> ( bad? ) + then ( bad? ) ;
: lock-udpv6-address ( -- ) lock-ipv6-address ;