87,6 → 87,10 |
} |
|
|
include "tcp.inc" |
include "udp.inc" |
include "icmp.inc" |
|
;*************************************************************************** |
; Function |
; ip_rx |
114,11 → 118,13 |
|
mov ebx, eax ; ebx=pointer to IP_PACKET |
|
; DEBUGF 1, "K : ip_rx - proto: %u\n", [ebx + IP_PACKET.Protocol]:1 |
|
; Validate the IP checksum |
mov dx, word[ebx + IP_PACKET.HeaderChecksum] |
xchg dh,dl ; Get the checksum in intel format |
|
mov [ebx + IP_PACKET.HeaderChecksum], word 0 ; clear checksum field - need to when |
mov [ebx + IP_PACKET.HeaderChecksum], 0 ; clear checksum field - need to when |
; recalculating checksum |
; this needs two data pointers and two size #. |
; 2nd pointer can be of length 0 |
127,9 → 133,13 |
stdcall checksum_jb, ebx, ecx ;buf_ptr, buf_size |
cmp dx, ax |
|
; DEBUGF 1, "K : ip_rx - checksums: %x - %x\n", dx, ax |
|
jnz .dump.1 ;if CHECKSUM isn't valid then dump packet |
mov edx, ebx ; EDX (IP-BUFFER POINTER) WILL BE USED FOR *_rx HANDLERS BELOW!!! |
jnz .dump ;if CHECKSUM isn't valid then dump packet |
|
; DEBUGF 1, "K : ip_rx - dest: %x - %x\n", [ebx + IP_PACKET.DestinationAddress], [stack_ip] |
|
; Validate the IP address, if it isn't broadcast |
mov eax, [stack_ip] |
cmp dword[ebx + IP_PACKET.DestinationAddress], eax |
137,22 → 147,37 |
|
; If the IP address is 255.255.255.255, accept it |
; - it is a broadcast packet, which we need for dhcp |
cmp dword[ebx + IP_PACKET.DestinationAddress], 0xffffffff |
jne .dump |
|
mov eax, [ebx + IP_PACKET.DestinationAddress] |
cmp eax, 0xffffffff |
;je @f |
;mov ecx, [stack_ip] |
;and eax, [subnet_mask] |
;and ecx, [subnet_mask] |
;cmp eax, ecx |
;jne .dump.2 |
;mov eax, [ebx + IP_PACKET.DestinationAddress] |
;or eax, [subnet_mask] |
;cmp eax, 0xffffffff |
jne .dump.2 |
|
@@: |
mov al, [ebx + IP_PACKET.VersionAndIHL] |
and al, 0x0f ;get IHL(header length) |
cmp al, 0x05 ;if IHL!= 5*4(20 bytes) |
jnz .dump ;then dump it |
; DEBUGF 1, "K : ip_rx - ihl: %x - 05\n", al |
jnz .dump.3 ;then dump it |
|
cmp byte[ebx + IP_PACKET.TimeToLive], byte 0 |
je .dump ;if TTL==0 then dump it |
; DEBUGF 1, "K : ip_rx - ttl: %x - 00\n", [ebx + IP_PACKET.TimeToLive]:2 |
|
mov ax, word[ebx + IP_PACKET.FlagsAndFragmentOffset] |
cmp [ebx + IP_PACKET.TimeToLive], 0 |
je .dump.4 ;if TTL==0 then dump it |
|
mov ax, [ebx + IP_PACKET.FlagsAndFragmentOffset] |
and ax, 0xFFBF ;get flags |
; DEBUGF 1, "K : ip_rx - flags: %x - 0000\n", ax |
cmp ax, 0 ;if some flags was set then we dump this packet |
jnz .dump ;the flags should be used for fragmented packets |
jnz .dump.5 ;the flags should be used for fragmented packets |
|
; Check the protocol, and call the appropriate handler |
; Each handler will re-use or free the queue buffer as appropriate |
161,7 → 186,7 |
|
cmp al , PROTOCOL_TCP |
jne .not_tcp |
DEBUGF 1,"K : ip_rx - TCP packet\n" |
; DEBUGF 1,"K : ip_rx - TCP packet\n" |
mov eax, dword[buffer_number] |
call tcp_rx |
jmp .exit |
169,7 → 194,7 |
.not_tcp: |
cmp al, PROTOCOL_UDP |
jne .not_udp |
DEBUGF 1,"K : ip_rx - UDP packet\n" |
; DEBUGF 1,"K : ip_rx - UDP packet\n" |
mov eax, dword[buffer_number] |
call udp_rx |
jmp .exit |
176,9 → 201,9 |
|
.not_udp: |
cmp al , PROTOCOL_ICMP |
jne .dump ;protocol ain't supported |
jne .dump.6 ;protocol ain't supported |
|
DEBUGF 1,"K : ip_rx - ICMP packet\n" |
; DEBUGF 1,"K : ip_rx - ICMP packet\n" |
;GET_IHL ecx, ebx + IP_PACKET.VersionAndIHL ;get packet length in ecx |
mov eax, dword[buffer_number] |
stdcall icmp_rx,eax,ebx,ecx ;buffer_number,IPPacketBase,IPHeaderLength |
185,13 → 210,32 |
jmp .exit |
|
|
.dump: |
; No protocol handler available, so |
; silently dump the packet, freeing up the queue buffer |
.dump.1: |
DEBUGF 1, "K : ip_rx - dumped (checksum: 0x%x-0x%x)\n", dx, ax |
jmp .dump.x |
|
.dump.2: |
DEBUGF 1, "K : ip_rx - dumped (ip: %u.%u.%u.%u)\n", [ebx + IP_PACKET.DestinationAddress + 0]:1, [ebx + IP_PACKET.DestinationAddress + 1]:1, [ebx + IP_PACKET.DestinationAddress + 2]:1, [ebx + IP_PACKET.DestinationAddress + 3]:1 |
jmp .dump.x |
|
.dump.3: |
DEBUGF 1, "K : ip_rx - dumped (ihl: %u)\n", al |
jmp .dump.x |
|
.dump.4: |
DEBUGF 1, "K : ip_rx - dumped (ihl: %u)\n", [ebx + IP_PACKET.TimeToLive] |
jmp .dump.x |
|
.dump.5: |
DEBUGF 1, "K : ip_rx - dumped (flags: 0x%x)\n", ax |
jmp .dump.x |
|
.dump.6: |
DEBUGF 1, "K : ip_rx - dumped (proto: %u)\n", [ebx + IP_PACKET.Protocol]:1 |
|
.dump.x: |
inc dword [dumped_rx_count] |
|
mov eax, dword[buffer_number] |
mov eax, [buffer_number] |
call freeBuff |
|
.exit: |