Added some experimental IPv6 code to net branch.

git-svn-id: svn://kolibrios.org@3185 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-01-18 14:32:05 +00:00
parent 81ba3134e6
commit 382dde4fed
3 changed files with 229 additions and 36 deletions

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2012. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2012-2013. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; IPv6.INC ;; ;; IPv6.INC ;;
@ -25,10 +25,41 @@ struct IPv6_header
HopLimit db ? ; Decremented by every node, packet is discarded when it reaches 0 HopLimit db ? ; Decremented by every node, packet is discarded when it reaches 0
SourceAddress rd 4 ; 128-bit addresses SourceAddress rd 4 ; 128-bit addresses
DestinationAddress rd 4 ; DestinationAddress rd 4 ;
Payload rb 0
ends ends
align 4
uglobal
IPv6:
.addresses rd 4*MAX_NET_DEVICES
.subnet rd 4*MAX_NET_DEVICES
.dns rd 4*MAX_NET_DEVICES
.gateway rd 4*MAX_NET_DEVICES
.packets_tx rd MAX_NET_DEVICES
.packets_rx rd MAX_NET_DEVICES
endg
;-----------------------------------------------------------------
;
; IPv6_init
;
; This function resets all IP variables
;
;-----------------------------------------------------------------
macro IPv6_init {
xor eax, eax
mov edi, IPv6
mov ecx, (4*4*4+2*4)MAX_IP
rep stosd
}
@ -52,43 +83,56 @@ ends
align 4 align 4
IPv6_input: IPv6_input:
DEBUGF 1,"IPv6_input\nfrom: %x:%x:%x:%x:%x:%x:%x:%x\n",\ DEBUGF 1,"IPv6_input from: %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x\n",\
[edx + IPv6_header.SourceAddress + 0]:4,[edx + IPv6_header.SourceAddress + 2]:4,\ [edx + IPv6_header.SourceAddress + 0]:2,[edx + IPv6_header.SourceAddress + 1]:2,\
[edx + IPv6_header.SourceAddress + 4]:4,[edx + IPv6_header.SourceAddress + 6]:4,\ [edx + IPv6_header.SourceAddress + 2]:2,[edx + IPv6_header.SourceAddress + 3]:2,\
[edx + IPv6_header.SourceAddress + 8]:4,[edx + IPv6_header.SourceAddress + 10]:4,\ [edx + IPv6_header.SourceAddress + 4]:2,[edx + IPv6_header.SourceAddress + 5]:2,\
[edx + IPv6_header.SourceAddress + 12]:4,[edx + IPv6_header.SourceAddress + 14]:4 [edx + IPv6_header.SourceAddress + 6]:2,[edx + IPv6_header.SourceAddress + 7]:2,\
DEBUGF 1,"to: %x:%x:%x:%x:%x:%x:%x:%x\n",\ [edx + IPv6_header.SourceAddress + 8]:2,[edx + IPv6_header.SourceAddress + 9]:2,\
[edx + IPv6_header.DestinationAddress + 0]:4,[edx + IPv6_header.DestinationAddress + 2]:4,\ [edx + IPv6_header.SourceAddress + 10]:2,[edx + IPv6_header.SourceAddress + 11]:2,\
[edx + IPv6_header.DestinationAddress + 4]:4,[edx + IPv6_header.DestinationAddress + 6]:4,\ [edx + IPv6_header.SourceAddress + 12]:2,[edx + IPv6_header.SourceAddress + 13]:2,\
[edx + IPv6_header.DestinationAddress + 8]:4,[edx + IPv6_header.DestinationAddress + 10]:4,\ [edx + IPv6_header.SourceAddress + 14]:2,[edx + IPv6_header.SourceAddress + 15]:2
[edx + IPv6_header.DestinationAddress + 12]:4,[edx + IPv6_header.DestinationAddress + 14]:4
DEBUGF 1,"IPv6_input to: %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x\n",\
[edx + IPv6_header.DestinationAddress + 0]:2,[edx + IPv6_header.DestinationAddress + 1]:2,\
[edx + IPv6_header.DestinationAddress + 2]:2,[edx + IPv6_header.DestinationAddress + 3]:2,\
[edx + IPv6_header.DestinationAddress + 4]:2,[edx + IPv6_header.DestinationAddress + 5]:2,\
[edx + IPv6_header.DestinationAddress + 6]:2,[edx + IPv6_header.DestinationAddress + 7]:2,\
[edx + IPv6_header.DestinationAddress + 8]:2,[edx + IPv6_header.DestinationAddress + 9]:2,\
[edx + IPv6_header.DestinationAddress + 10]:2,[edx + IPv6_header.DestinationAddress + 11]:2,\
[edx + IPv6_header.DestinationAddress + 12]:2,[edx + IPv6_header.DestinationAddress + 13]:2,\
[edx + IPv6_header.DestinationAddress + 14]:2,[edx + IPv6_header.DestinationAddress + 15]:2
sub ecx, sizeof.IPv6_header sub ecx, sizeof.IPv6_header
jb .dump jb .dump
movzx eax, [edx + IPv6.PayloadLength] cmp cx, [edx + IPv6_header.PayloadLength]
xchg al, ah
cmp eax, ecx
jb .dump jb .dump
;------------------------------------------------------------------- ;-------------------------------------------------------------------
; No, it's just a regular IP packet, pass it to the higher protocols ; No, it's just a regular IP packet, pass it to the higher protocols
.handle_it: .handle_it:
movzx ecx, [edx + IPv6_header.PayloadLength]
movzx esi, [edx + IPv6_header.VersionAndIHL] ; Calculate Header length by using IHL field
and esi, 0x0000000f ;
shl esi, 2 ;
movzx ecx, [edx + IPv6_header.TotalLength] ; Calculate length of encapsulated Packet
xchg cl, ch ;
sub ecx, esi ;
lea edi, [edx + IPv6_header.SourceAddress] ; make edi ptr to source and dest IPv6 address lea edi, [edx + IPv6_header.SourceAddress] ; make edi ptr to source and dest IPv6 address
mov al, [edx + IPv6_header.Protocol] lea esi, [edx + IPv6_header.Payload] ; make esi ptr to data
add esi, edx ; make esi ptr to data mov al, [edx + IPv6_header.NextHeader]
.scan:
cmp al, 59 ; no next
je .dump
cmp al, 0
je .hop_by_hop
cmp al, 43
je .routing
cmp al, 44
je .fragment
cmp al, 60
je .dest_opts
; cmp al, IP_PROTO_TCP ; cmp al, IP_PROTO_TCP
; je TCP_input ; je TCP_input
@ -96,14 +140,159 @@ IPv6_input:
; cmp al, IP_PROTO_UDP ; cmp al, IP_PROTO_UDP
; je UDP_input ; je UDP_input
; cmp al, IP_PROTO_ICMP ; cmp al, 58
; je ICMP_input ; je ICMP6_input
DEBUGF 2,"IPv6_input - unknown protocol: %u\n", al DEBUGF 2,"IPv6_input - unknown protocol: %u\n", al
.dump: .dump:
DEBUGF 2,"IPv6_input - dumping\n" DEBUGF 2,"IPv6_input - dumping\n"
call kernel_free
add esp, 4 add esp, 4
call KernelFree
ret ret
.dump_options:
add esp, 2+4+4
jmp .dump
.nextheader:
pop esi
pop ecx
pop ax
jmp .scan
;-------------------------
; Hop-by-Hop
.hop_by_hop:
DEBUGF 2,"IPv6_input - hop by hop\n"
pushw [esi] ; 8 bit identifier for option type
movzx eax, byte[esi + 1] ; Hdr Ext Len
inc eax ; first 8 octets not counted
shl eax, 3 ; * 8
sub ecx, eax
push ecx
add eax, esi
push eax
inc esi
inc esi
mov al, [esi]
cmp al, 0
je .pad_1
cmp al, 1
je .pad_n
; TODO: check with other known options
; unknown option.. discard packet or not?
; check highest two bits
test al, 0xc0 ; discard packet
jnz .dump_options
.pad_n:
movzx eax, byte[esi + 1]
DEBUGF 2,"IPv6_input - pad %u\n", eax
inc esi
inc esi
add esi, eax
sub ecx, eax
jmp .hop_by_hop
.pad_1:
DEBUGF 2,"IPv6_input - pad 1\n"
inc esi
dec ecx
jmp .hop_by_hop
.dest_opts:
DEBUGF 2,"IPv6_input - dest opts\n"
jmp .nextheader
.routing:
DEBUGF 2,"IPv6_input - routing\n"
pushw [esi] ; 8 bit identifier for option type
movzx eax, byte[esi + 1] ; Hdr Ext Len
inc eax ; first 8 octets not counted
shl eax, 3 ; * 8
sub ecx, eax
push ecx
add eax, esi
push eax
inc esi
inc esi
cmp al, 0
je .pad_1
cmp al, 1
je .pad_n
mov al, [esi] ; routing type
jmp .nextheader
.fragment:
DEBUGF 2,"IPv6_input - fragment\n"
jmp .nextheader
;---------------------------------------------------------------------------
;
; IPv6_API
;
; This function is called by system function 75
;
; IN: subfunction number in bl
; device number in bh
; ecx, edx, .. depends on subfunction
;
; OUT:
;
;---------------------------------------------------------------------------
align 4
IPv6_api:
movzx eax, bh
shl eax, 2
and ebx, 0x000000ff
cmp ebx, .number
ja .error
jmp dword [.table + 4*ebx]
.table:
dd .packets_tx ; 0
dd .packets_rx ; 1
; dd .read_ip ; 2
; dd .write_ip ; 3
; dd .read_dns ; 4
; dd .write_dns ; 5
; dd .read_subnet ; 6
; dd .write_subnet ; 7
; dd .read_gateway ; 8
; dd .write_gateway ; 9
.number = ($ - .table) / 4 - 1
.error:
mov eax, -1
ret
.packets_tx:
mov eax, [IPv6.packets_tx + eax]
ret
.packets_rx:
mov eax, [IPv6.packets_rx + eax]
ret

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; ETHERNET.INC ;; ;; ETHERNET.INC ;;
@ -77,8 +77,8 @@ ETH_input:
cmp ax, ETHER_ARP cmp ax, ETHER_ARP
je ARP_input je ARP_input
; cmp ax, ETHER_IPv6 cmp ax, ETHER_IPv6
; je IPv6_input je IPv6_input
cmp ax, ETHER_PPP_DISCOVERY cmp ax, ETHER_PPP_DISCOVERY
je PPPoE_discovery_input je PPPoE_discovery_input

View File

@ -129,6 +129,7 @@ API_UDP = 3
API_TCP = 4 API_TCP = 4
API_ARP = 5 API_ARP = 5
API_PPPOE = 6 API_PPPOE = 6
API_IPv6 = 7
HWACC_TCP_IPv4 = 1 shl 0 HWACC_TCP_IPv4 = 1 shl 0
@ -187,7 +188,7 @@ include "PPPoE.inc"
include "ARP.inc" include "ARP.inc"
include "IPv4.inc" include "IPv4.inc"
;include "IPv6.inc" include "IPv6.inc"
include "icmp.inc" include "icmp.inc"
include "udp.inc" include "udp.inc"
@ -729,6 +730,9 @@ sys_protocols:
cmp ax, API_PPPOE cmp ax, API_PPPOE
je PPPoE_api je PPPoE_api
cmp ax, API_IPv6
je IPv6_api
add esp, 4 ; if we reached here, no function was called, so we need to balance stack add esp, 4 ; if we reached here, no function was called, so we need to balance stack
.doesnt_exist: .doesnt_exist: