[OpenBIOS] r573 - ofw/inetv6
svn at openbios.org
svn at openbios.org
Wed Aug 22 18:31:41 CEST 2007
Author: lwalter
Date: 2007-08-22 18:31:41 +0200 (Wed, 22 Aug 2007)
New Revision: 573
Modified:
ofw/inetv6/dhcpv6.fth
ofw/inetv6/dnsv6.fth
ofw/inetv6/ipv6.fth
ofw/inetv6/neighdis.fth
Log:
Obtain DNS IPv6 address from router advertisement
Modified: ofw/inetv6/dhcpv6.fth
===================================================================
--- ofw/inetv6/dhcpv6.fth 2007-08-22 01:05:10 UTC (rev 572)
+++ ofw/inetv6/dhcpv6.fth 2007-08-22 16:31:41 UTC (rev 573)
@@ -1,6 +1,56 @@
\ See license at end of file
purpose: Dynamic Host Configuration Protocol for IPv6 (DHCPv6) (RFC 3315)
+d# 1000 constant dhcpv6-timeout \ 1 second timeout
+
+d# 546 constant client-port
+d# 547 constant dhcpv6-port
+
+struct ( dhcpv6 packet )
+ 1 sfield dh6-op \ DHCPv6 message type
+ 3 sfield dh6-xid \ Transaction ID
+ 0 sfield dh6-options \ DHCPv6 options
+constant /dhcpv6-hdr
+
+: dh6-xid@ ( -- xid ) dh6-xid 2 + c@ dh6-xid 1+ c@ dh6-xid c@ 0 bljoin ;
+: dh6-xid! ( xid -- ) lbsplit drop dh6-xid c! dh6-xid 1+ c! dh6-xid 2 + c! ;
+
+\ dh6-op values
+\ 1 SOLICIT Used by clients to locate DHCP servers
+\ 2 ADVERTISE Used by servers as response to SOLICIT
+\ 3 REQUEST Used by clients to get info from servers
+\ 4 CONFIRM Used by clients to verify validity of params
+\ 5 RENEW Used by clients to extend lifetime
+\ 6 REBIND Used by clients to extend lifetime if no reply to RENEW
+\ 7 REPLY Used by servers to respond
+\ 8 RELEASE Used by clients to release their IPv6 addresses
+\ 9 DECLINE Used by clients to decline assigned addresses
+\ 10 RECONFIGURE Used by DHCP servers to inform clients of new cfg
+\ 11 INFO_REQUEST Used by clients to request additional cfg params
+\ 12 RELAY_FORWARD Used by DHCP relays to forward client msgs to servers
+\ 13 RELAY_REPLY Used by DHCP servers to send msgs to clients via a relay
+
+struct ( dhcpv6 option )
+ 2 sfield do6-code \ Option code
+ 2 sfield do6-len \ Option len
+ 0 sfield do6-data \ Option data
+constant /do6-hdr
+
+d# 1024 constant /dhcpv6-packet
+
+\ do6-code values
+\ 1 client ID
+\ 2 server ID
+\ 3 ID association for nontemporary address (IA_NA)
+\ 4 ID association for temporary address (IA_TA)
+\ 5 IA address
+\ 6 option request
+\ 7 preference
+\ 8 elapse time
+\ 9 relay message
+\ 11 authentication
+\ 12 server unicast
+
[ifndef] include-ipv4
d# 256 buffer: 'root-path
d# 256 buffer: 'client-name
@@ -12,9 +62,29 @@
: domain-name ( -- adr len ) 'domain-name cscount ;
[then]
-\ tubes.laptop.org
-create default-name-server-ipv6 h# 20 c, 1 c, h# 48 c, h# 30 c, h# 24 c, h# 46 c, h# ff c, 0 c, 0 l, 0 w, 0 c, 1 c,
+0 instance value dhcpv6-packet
+0 instance value dhcpv6-len \ Actual length of received DHCPv6 packet
+0 instance value dhcpv6-option \ Pointer to option field in dhcpv6-packet
+: /dhcpv6-packet ( -- len ) dhcpv6-option dhcpv6-packet - ;
+: set-dhcpv6-option ( -- ) dh6-options to dhcpv6-option ;
+: +dhcpv6-option ( n -- ) dhcpv6-option + to dhcpv6-option ;
+: opc! ( c -- ) dhcpv6-option c! 1 +dhcpv6-option ;
+: opw! ( w -- ) dhcpv6-option be-w! 2 +dhcpv6-option ;
+: opl! ( l -- ) dhcpv6-option be-l! 4 +dhcpv6-option ;
+: op$! ( $ -- ) tuck dhcpv6-option swap move +dhcpv6-option ;
+
+: allocate-dhcpv6 ( size -- )
+ allocate-udp 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 ;
+
: init-dhcpv6 ( -- )
[ifndef] include-ipv4
0 'domain-name c!
@@ -23,7 +93,6 @@
0 'vendor-options c!
\ 0 file-name-buf c!
[then]
- default-name-server-ipv6 name-server-ipv6 copy-ipv6-addr
;
also forth definitions
@@ -32,9 +101,72 @@
;
previous definitions
-: do-dhcp ( -- )
+: send-dhcpv6-packet ( size op -- )
+ dh6-op c!
+ xid dh6-xid!
+ dhcpv6-packet swap client-port dhcpv6-port send-udpv6-packet
;
+: detect-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
+ repeat
+ r> drop true
+;
+
+: option-client-id ( -- )
+ 1 opw! \ Client ID option
+ /e 4 + opw! \ Option len
+ 3 opw! \ DUID type: link-layer address
+ 1 opw! \ Hardware type: ethernet
+ my-en-addr /e op$! \ My mac address
+;
+
+: option-req-option ( -- )
+ 6 opw! \ Option request option
+ 2 opw! \ Option len
+ d# 23 opw! \ OPTION_DNS_SERVERS
+;
+
+: dhcpv6-solicit ( -- )
+ ipv6-addr-mc-all-dhcp his-ipv6-addr copy-ipv6-addr
+ set-his-en-addr-mc
+ option-client-id
+ \ option-ia to which server will assign addresses
+ option-req-option
+ /dhcpv6-packet d# 11 send-dhcpv6-packet
+ 2 detect-dhcpv6-packet abort" Timeout soliciting DHCPv6 server"
+;
+: dhcpv6-req-info ( -- )
+ ipv6-addr-mc-all-dhcp his-ipv6-addr copy-ipv6-addr
+ set-his-en-addr-mc
+ option-client-id
+ option-req-option
+ /dhcpv6-packet d# 11 send-dhcpv6-packet
+ 7 detect-dhcpv6-packet abort" Timeout waiting for requested info"
+;
+
+: do-dhcpv6-stateless ( -- )
+ ." DHCPv6 stateless auto configuration not supported yet" cr exit
+
+ bootnet-debug if
+ ." DHCPv6 protocol: Getting network information" cr
+ then
+ /dhcpv6-packet allocate-dhcpv6
+
+ ['] dhcpv6-req-info catch drop
+
+ /dhcpv6-packet free-dhcpv6
+;
+
+: do-dhcpv6-stateful ( -- )
+ true abort" Stateful autoconfiguration not supported yet"
+;
+
\ LICENSE_BEGIN
\ Copyright (c) 2007 FirmWorks
\
Modified: ofw/inetv6/dnsv6.fth
===================================================================
--- ofw/inetv6/dnsv6.fth 2007-08-22 01:05:10 UTC (rev 572)
+++ ofw/inetv6/dnsv6.fth 2007-08-22 16:31:41 UTC (rev 573)
@@ -224,6 +224,8 @@
[then]
: resolvev6 ( hostname$ -- )
+ name-server-ipv6 unknown-ipv6-addr? if true abort" Unknown DNS server IPv6 address" then
+
bootnet-debug if ( hostname$ )
." Using IPv6 DNS to find the IPv6 address of " ( hostname$ )
2dup type cr ( hostname$ )
Modified: ofw/inetv6/ipv6.fth
===================================================================
--- ofw/inetv6/ipv6.fth 2007-08-22 01:05:10 UTC (rev 572)
+++ ofw/inetv6/ipv6.fth 2007-08-22 16:31:41 UTC (rev 573)
@@ -78,6 +78,7 @@
/ipv6 buffer: my-ipv6-addr-global
/ipv6 buffer: router-ipv6-addr
/ipv6 buffer: name-server-ipv6
+/ipv6 buffer: dhcp-ipv6-addr
headerless
@@ -86,6 +87,7 @@
create default-ipv6-addr h# fe c, h# 80 c, 0 w, 0 l, 0 w, 0 c, h# ff c, h# fe c, 0 c, 0 w,
create ipv6-addr-mc-all-nodes h# ff c, 2 c, 0 w, 0 l, 0 l, 0 w, 0 c, 1 c,
create ipv6-addr-mc-all-routers h# ff c, 2 c, 0 w, 0 l, 0 l, 0 w, 0 c, 2 c,
+create ipv6-addr-mc-all-dhcp h# ff c, 2 c, 0 w, 0 l, 0 l, 0 c, 1 c, 0 c, 2 c,
create my-ipv6-addr-mc-sol-node h# ff c, 2 c, 0 w, 0 l, 0 w, 0 c, 1 c, h# ff c, 0 c, 0 w,
create his-ipv6-addr-mc-sol-node h# ff c, 2 c, 0 w, 0 l, 0 w, 0 c, 1 c, h# ff c, 0 c, 0 w,
@@ -168,10 +170,11 @@
: .my-ipv6-addr-global ( -- )
." My IPv6 (global): " my-ipv6-addr-global .ipv6
;
-: .his-ipv6-addr ( -- ) ." His IP: " his-ipv6-addr .ipv6 ;
+: .his-ipv6-addr ( -- ) ." His IPv6: " his-ipv6-addr .ipv6 ;
: .my-prefix ( -- )
." My prefix (global): " my-prefix .ipv6 ." /" /prefix .d
;
+: .name-server-ipv6 ( -- ) ." DNS IPv6: " name-server-ipv6 .ipv6 ;
[ifndef] include-ipv4
0 instance value last-ip-packet
Modified: ofw/inetv6/neighdis.fth
===================================================================
--- ofw/inetv6/neighdis.fth 2007-08-22 01:05:10 UTC (rev 572)
+++ ofw/inetv6/neighdis.fth 2007-08-22 16:31:41 UTC (rev 573)
@@ -86,6 +86,7 @@
then
indent .my-link-addr cr
use-routerv6? if indent .routerv6-en-addr cr then
+ name-server-ipv6 knownv6? if indent .name-server-ipv6 cr then
then
;
@@ -98,6 +99,7 @@
;
: set-my-ipv6-addr-link-local ( -- )
\ Duplicate Address Discovery
+ d# 64 to /prefix
unknown-ipv6-addr my-ipv6-addr copy-ipv6-addr
default-ipv6-addr my-ipv6-addr-link-local copy-ipv6-addr
@@ -114,17 +116,33 @@
my-ipv6-addr-link-local my-ipv6-addr copy-ipv6-addr
;
+: discover-me ( -- )
+ ipv6-address " stateless" $= if
+ set-my-ipv6-addr-link-local
+ else
+ do-dhcpv6-stateful
+ then
+;
+: ?discover-dns ( -- )
+ ipv6-address " stateless" $= if
+ name-server-ipv6 unknown-ipv6-addr? if
+ do-dhcpv6-stateless
+ then
+ then
+;
+
: process-rd-options ( adr len -- )
begin dup 0> while
over c@ case
- 1 of over 2 + routerv6-en-addr copy-en-addr endof \ Source link-layer address option
- 3 of over 2 + c@ to /prefix \ Prefix option
+ 1 of over 2 + routerv6-en-addr copy-en-addr endof \ Source link-layer address option
+ 3 of over 2 + c@ to /prefix \ Prefix option
over 3 + c@ to prefix-flag
- over 8 + be-l@ to prefix-lifetime \ XXX lifetime
- over d# 16 + my-prefix copy-ipv6-addr \ Prefix
+ over 8 + be-l@ to prefix-lifetime \ XXX lifetime
+ over d# 16 + my-prefix copy-ipv6-addr \ Prefix
endof
- 5 of over 4 + be-l@ to (link-mtu) endof \ MTU option
+ 5 of over 4 + be-l@ to (link-mtu) endof \ MTU option
+ d# 25 of over 8 + name-server-ipv6 copy-ipv6-addr endof \ RDNSS option
endcase
over 1+ c@ 8 * /string
repeat 2drop
@@ -173,11 +191,12 @@
['] 4drop to icmpv6-err-callback-xt
['] 2drop to icmpv6-info-callback-xt
+ unknown-ipv6-addr name-server-ipv6 copy-ipv6-addr
- d# 64 to /prefix
- set-my-ipv6-addr-link-local
-
+ discover-me
discover-router
+ ?discover-dns
+
to use-ipv6? \ Restore IPv6 flag
;
More information about the OpenBIOS
mailing list