/kernel/branches/net/network/ARP.inc |
---|
18,19 → 18,19 |
$Revision$ |
ARP_NO_ENTRY equ 0 |
ARP_VALID_MAPPING equ 1 |
ARP_AWAITING_RESPONSE equ 2 |
ARP_RESPONSE_TIMEOUT equ 3 |
ARP_NO_ENTRY = 0 |
ARP_VALID_MAPPING = 1 |
ARP_AWAITING_RESPONSE = 2 |
ARP_RESPONSE_TIMEOUT = 3 |
ARP_REQUEST_TTL equ 31 ; 20 s |
ARP_ENTRY_TTL equ 937 ; 600 s |
ARP_STATIC_ENTRY equ -1 |
ARP_REQUEST_TTL = 31 ; 20 s |
ARP_ENTRY_TTL = 937 ; 600 s |
ARP_STATIC_ENTRY = -1 |
ARP_REQ_OPCODE equ 0x0100 ; request |
ARP_REP_OPCODE equ 0x0200 ; reply |
ARP_REQ_OPCODE = 0x0100 ; request |
ARP_REP_OPCODE = 0x0200 ; reply |
ARP_TABLE_SIZE equ 20 ; Size of table |
ARP_TABLE_SIZE = 20 ; Size of table |
struct ARP_entry |
570,37 → 570,35 |
; |
;----------------------------------------------------------------- |
align 4 |
ARP_API: |
ARP_api: |
movzx eax, bh |
shl eax, 2 |
test bl, bl |
jz .packets_tx ; 0 |
dec bl |
jz .packets_rx ; 1 |
dec bl |
jz .entries ; 2 |
dec bl |
jz .read ; 3 |
dec bl |
jz .write ; 4 |
dec bl |
jz .remove ; 5 |
dec bl |
and ebx, 0xff |
cmp ebx, .number |
ja .error |
jmp dword [.table + 4*ebx] |
.table: |
dd .packets_tx ; 0 |
dd .packets_rx ; 1 |
dd .entries ; 2 |
dd .read ; 3 |
dd .write ; 4 |
dd .remove ; 5 |
.number = ($ - .table) / 4 - 1 |
.error: |
mov eax, -1 |
ret |
.packets_tx: |
add eax, ARP_PACKETS_TX |
mov eax, [eax] |
mov eax, [ARP_PACKETS_TX + eax] |
ret |
.packets_rx: |
add eax, ARP_PACKETS_RX |
mov eax, [eax] |
mov eax, [ARP_PACKETS_RX + eax] |
ret |
.entries: |
/kernel/branches/net/network/IPv4.inc |
---|
18,9 → 18,9 |
$Revision$ |
MAX_FRAGMENTS equ 64 |
MAX_IP equ MAX_NET_DEVICES |
IP_MAX_INTERFACES equ MAX_IP |
MAX_FRAGMENTS = 64 |
MAX_IP = MAX_NET_DEVICES |
IP_MAX_INTERFACES = MAX_IP |
struct IPv4_header |
194,7 → 194,8 |
; IN: Pointer to buffer in [esp] |
; size of buffer in [esp+4] |
; pointer to device struct in ebx |
; pointer to IP Packet data in edx |
; pointer to IP header in edx |
; size of IP packet in ecx |
; OUT: / |
; |
;----------------------------------------------------------------- |
943,86 → 944,72 |
; |
;--------------------------------------------------------------------------- |
align 4 |
IPv4_API: |
IPv4_api: |
movzx eax, bh |
shl eax, 2 |
test bl, bl |
jz .packets_tx ; 0 |
dec bl |
jz .packets_rx ; 1 |
dec bl |
jz .read_ip ; 2 |
dec bl |
jz .write_ip ; 3 |
dec bl |
jz .read_dns ; 4 |
dec bl |
jz .write_dns ; 5 |
dec bl |
jz .read_subnet ; 6 |
dec bl |
jz .write_subnet ; 7 |
dec bl |
jz .read_gateway ; 8 |
dec bl |
jz .write_gateway ; 9 |
and ebx, 0xff |
cmp ebx, .number |
ja .error |
jmp dword [.table + 4*ebx] |
.table: |
dd .packets_tx ; 0 |
dd .packets_rx ; 1 |
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: |
add eax, IP_PACKETS_TX |
mov eax, [eax] |
mov eax, [IP_PACKETS_TX + eax] |
ret |
.packets_rx: |
add eax, IP_PACKETS_RX |
mov eax, [eax] |
mov eax, [IP_PACKETS_RX + eax] |
ret |
.read_ip: |
add eax, IP_LIST |
mov eax, [eax] |
mov eax, [IP_LIST + eax] |
ret |
.write_ip: |
add eax, IP_LIST |
mov [eax], ecx |
mov [IP_LIST + eax], ecx |
xor eax, eax |
ret |
.read_dns: |
add eax, DNS_LIST |
mov eax, [eax] |
mov eax, [DNS_LIST + eax] |
ret |
.write_dns: |
add eax, DNS_LIST |
mov [eax], ecx |
mov [DNS_LIST + eax], ecx |
xor eax, eax |
ret |
.read_subnet: |
add eax, SUBNET_LIST |
mov eax, [eax] |
mov eax, [SUBNET_LIST + eax] |
ret |
.write_subnet: |
add eax, SUBNET_LIST |
mov [eax], ecx |
mov [SUBNET_LIST + eax], ecx |
xor eax, eax |
ret |
.read_gateway: |
add eax, GATEWAY_LIST |
mov eax, [eax] |
mov eax, [GATEWAY_LIST + eax] |
ret |
.write_gateway: |
add eax, GATEWAY_LIST |
mov [eax], ecx |
mov [GATEWAY_LIST + eax], ecx |
xor eax, eax |
ret |
/kernel/branches/net/network/PPPoE.inc |
---|
0,0 → 1,286 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; ;; |
;; Copyright (C) KolibriOS team 2009-2012. All rights reserved. ;; |
;; Distributed under terms of the GNU General Public License ;; |
;; ;; |
;; Clevermouse & hidnplayr ;; |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
struct PPPoE_header |
VersionAndType db ? |
Code db ? |
SessionID dw ? |
Length dw ? ; Length of payload, does NOT include the length PPPoE header. |
ends |
struct PPPoE_connection |
next dd ? ; pointer to next connection |
prev dd ? ; pointer to previous connection |
pid dd ? ; identifier of base application |
datalen dd ? ; length of received data |
recvbuf rb 1500 ; buffer for received data |
sendbuf rb 1500 ; buffer for data to send |
ends |
iglobal |
align 4 |
PPPoE.head dd PPPoE.head |
PPPoE.tail dd PPPoE.head |
endg |
uglobal |
PPPoE.cur_receiver dd ? |
PPPoE.cur_receiver_ptr dd ? |
PPPoE.cur_receiver_len dd ? |
endg |
; Allocates internal structure for future PPPoE actions. |
align 4 |
PPPoE_alloc_connection: |
; 1. Allocate memory in the kernel area. |
stdcall kernel_alloc, sizeof.PPPoE_connection |
; 1a. If memory allocation failed, return NULL. |
test eax, eax |
jz .nothing |
; 2. Copy PID of caller to the structure. |
mov edx, [CURRENT_TASK] |
mov [eax + PPPoE_connection.pid], edx |
; 3. Insert the structure to the list of all connections. |
mov [eax + PPPoE_connection.next], PPPoE.head |
mov edx, [PPPoE.tail] |
mov [eax + PPPoE_connection.prev], edx |
mov [edx + PPPoE_connection.next], eax |
mov [PPPoE.tail], eax |
.nothing: |
ret |
align 4 |
PPPoE_free_connection: |
; 1. Check that the caller is the owner of this connection. |
mov eax, [CURRENT_TASK] |
cmp [ebx+PPPoE_connection.pid], eax |
jnz .nothing |
; 2. Delete the structure from the list of all connections. |
mov eax, [ebx+PPPoE_connection.next] |
mov edx, [ebx+PPPoE_connection.prev] |
mov [eax+PPPoE_connection.prev], edx |
mov [edx+PPPoE_connection.next], eax |
; 3. Free the memory. |
stdcall kernel_free, ebx |
.nothing: |
ret |
; Send PADI packet |
; ebx (ecx in app) = size of buffer for PPPoE offers, must be at least 1514 |
; ecx (edx in app) = size of tags, 0 means "use default" |
; edx (esi in app) = pointer to buffer for PPPoE offers |
; esi (edi in app) = pointer to tags, ignored if 'size of tags' == 0 |
align 4 |
PPPoE_send_init: |
; 1. Check length. |
cmp ebi, 1514 |
jb .bad |
; RFC2516: An entire PADI packet (including the PPPoE header) MUST NOT |
; exceed 1484 octets. |
; PPPoE header is 6 bytes long, so maximum length of tags is 1478. |
cmp ecx, 1478 |
ja .bad |
; 2. Check that no one listen for offers. |
cmp [PPPoE.cur_receiver], 0 |
jnz .bad |
; 3. Remember PID and data pointer of current listener. |
push [CURRENT_TASK] |
pop [PPPoE.cur_receiver] |
mov [PPPoE.cur_receiver_ptr], edx |
mov [PPPoE.cur_receiver_len], ebx |
and dword [edx], 0 ; no offers yet |
; 4. Create packet. |
test ecx, ecx |
jnz @f |
mov esi, .default_payload |
mov ecx, .default_payload_length |
@@: |
mov edx, [NET_DRV_LIST] ;;;; FIXME |
lea eax, [ebx + ETH_DEVICE.mac] ; Source Address |
mov edx, ETH_BROADCAST ; Destination Address |
add ecx, sizeof.PPPoE_header ; Data size |
mov di, ETHER_PPP_DISCOVERY ; Protocol |
call ETH_output |
jz .eth_error |
push edx eax |
; 4b. Set ver=1, type=1 (=> first byte 0x11), code=9 (PADI packet), session=0 |
mov dword [edi], (0x09 shl 8) + 0x11 |
; 4c. Set payload length. |
mov [edi+4], ch |
mov [edi+5], cl |
; 4e. Copy given tags. |
rep movsb |
; 5. Send packet. |
call [ebx + NET_DEVICE.transmit] |
; 6. Return. |
xor eax, eax |
ret |
.bad: |
or eax, -1 |
ret |
.default_payload: |
; Service-Name tag with zero length |
dw 0x0101, 0x0000 |
.default_payload_length = $ - .default_payload |
; Stop receiving PADO packets |
align 4 |
PPPoE_stop_offers: |
; Only the listener can stop listen. ;;; TODO: make sure this function is called when process gets terminated |
mov eax, [CURRENT_TASK] |
cmp [PPPoE.cur_receiver], eax |
jnz .bad |
xor eax, eax |
mov [PPPoE.cur_receiver_ptr], eax |
mov [PPPoE.cur_receiver], eax |
ret |
.bad: |
or eax, -1 |
ret |
; Send PPPoE data in Discovery stage |
align 4 |
PPPoE_send_discovery: |
ret |
; Receive PPPoE data in Discovery stage |
align 4 |
PPPoE_receive_discovery: |
ret |
;----------------------------------------------------------------- |
; |
; PPPoE discovery input |
; |
; Handler of received Ethernet packet with type = Discovery |
; |
; |
; IN: Pointer to buffer in [esp] |
; size of buffer in [esp+4] |
; pointer to device struct in ebx |
; pointer to PPP header in edx |
; size of PPP packet in ecx |
; OUT: / |
; |
;----------------------------------------------------------------- |
align 4 |
PPPoE_discovery_input: |
; 1. Minimum 6 bytes for PPPoE header. |
cmp ecx, sizeof.PPPoE_header |
jb .bad |
; 1. Ignore packets with ver<>1 and/or type<>1. |
cmp [edx + PPPoE_header.VersionAndType], 0x11 |
jnz .bad |
; 2. Code must be either 7 for Offer, |
; or 0x65 for Session-Confirmation, or 0xa7 for Terminate. |
; Because only Initiation/Offers are supported, we expect only value 7. |
cmp [edx + PPPoE_header.Code], 7 |
jnz .bad |
; 3. Session ID must be zero for Offers. |
cmp [edx + PPPoE_header.SessionID], 0 |
jnz .bad |
; 4. Payload length |
rol [edx + PPPoE_header.Length], 8 ; Convert INET byte order to intel |
; 5. Ignore packet if nobody is listening. |
cmp [PPPoE.cur_receiver], 0 |
jz .bad |
; 6. Good, now copy the received packet to the buffer of listener. |
;;; TODO |
.bad: |
DEBUGF 1,'K : PPPoE - dumped\n' |
call kernel_free |
add esp, 4 ; pop (balance stack) |
ret |
;--------------------------------------------------------------------------- |
; |
; PPPoE 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 |
PPPoE_api: |
movzx eax, bh |
shl eax, 2 |
and ebx, 0xff |
cmp ebx, .number |
ja .error |
jmp dword [.table + 4*ebx] |
.table: |
dd PPPoE_send_init ; 0 |
dd PPPoE_stop_offers ; 1 |
dd PPPoE_alloc_connection ; 3 |
dd PPPoE_free_connection ; 4 |
dd PPPoE_send_discovery ; 5 |
dd PPPoE_receive_discovery ; 6 |
.number = ($ - .table) / 4 - 1 |
.error: |
mov eax, -1 |
ret |
/kernel/branches/net/network/ethernet.inc |
---|
24,7 → 24,7 |
ends |
ETH_FRAME_MINIMUM equ 60 |
ETH_FRAME_MINIMUM = 60 |
struct ETH_DEVICE NET_DEVICE |
78,7 → 78,7 |
je ARP_input |
; cmp ax, ETHER_PPP_DISCOVERY |
; je PPPOE_discovery |
; je PPPoE_discovery_input |
DEBUGF 2,"Unknown ethernet packet type %x\n", ax |
173,30 → 173,29 |
; |
;----------------------------------------------------------------- |
align 4 |
ETH_API: |
ETH_api: |
cmp bh, MAX_NET_DEVICES |
ja .error |
movzx eax, bh |
shl eax, 2 |
mov eax, dword [NET_DRV_LIST + eax] |
mov eax, dword [NET_DRV_LIST + 4*eax] |
cmp [eax + NET_DEVICE.type], NET_TYPE_ETH |
jne .error |
test bl, bl |
jz .packets_tx ; 0 |
dec bl |
jz .packets_rx ; 1 |
dec bl |
jz .bytes_tx ; 2 |
dec bl |
jz .bytes_rx ; 3 |
dec bl |
jz .read_mac ; 4 |
dec bl |
jz .write_mac ; 5 |
and ebx, 0xff |
cmp ebx, .number |
ja .error |
jmp dword [.table + 4*ebx] |
.table: |
dd .packets_tx ; 0 |
dd .packets_rx ; 1 |
dd .bytes_tx ; 2 |
dd .bytes_rx ; 3 |
dd .read_mac ; 4 |
dd .write_mac ; 5 |
.number = ($ - .table) / 4 - 1 |
.error: |
DEBUGF 2,"Device is not ethernet type\n" |
or eax, -1 |
/kernel/branches/net/network/icmp.inc |
---|
21,69 → 21,69 |
; ICMP types & codes |
ICMP_ECHOREPLY equ 0 ; echo reply message |
ICMP_ECHOREPLY = 0 ; echo reply message |
ICMP_UNREACH equ 3 |
ICMP_UNREACH_NET equ 0 ; bad net |
ICMP_UNREACH_HOST equ 1 ; bad host |
ICMP_UNREACH_PROTOCOL equ 2 ; bad protocol |
ICMP_UNREACH_PORT equ 3 ; bad port |
ICMP_UNREACH_NEEDFRAG equ 4 ; IP_DF caused drop |
ICMP_UNREACH_SRCFAIL equ 5 ; src route failed |
ICMP_UNREACH_NET_UNKNOWN equ 6 ; unknown net |
ICMP_UNREACH_HOST_UNKNOWN equ 7 ; unknown host |
ICMP_UNREACH_ISOLATED equ 8 ; src host isolated |
ICMP_UNREACH_NET_PROHIB equ 9 ; prohibited access |
ICMP_UNREACH_HOST_PROHIB equ 10 ; ditto |
ICMP_UNREACH_TOSNET equ 11 ; bad tos for net |
ICMP_UNREACH_TOSHOST equ 12 ; bad tos for host |
ICMP_UNREACH_FILTER_PROHIB equ 13 ; admin prohib |
ICMP_UNREACH_HOST_PRECEDENCE equ 14 ; host prec vio. |
ICMP_UNREACH_PRECEDENCE_CUTOFF equ 15 ; prec cutoff |
ICMP_UNREACH = 3 |
ICMP_UNREACH_NET = 0 ; bad net |
ICMP_UNREACH_HOST = 1 ; bad host |
ICMP_UNREACH_PROTOCOL = 2 ; bad protocol |
ICMP_UNREACH_PORT = 3 ; bad port |
ICMP_UNREACH_NEEDFRAG = 4 ; IP_DF caused drop |
ICMP_UNREACH_SRCFAIL = 5 ; src route failed |
ICMP_UNREACH_NET_UNKNOWN = 6 ; unknown net |
ICMP_UNREACH_HOST_UNKNOWN = 7 ; unknown host |
ICMP_UNREACH_ISOLATED = 8 ; src host isolated |
ICMP_UNREACH_NET_PROHIB = 9 ; prohibited access |
ICMP_UNREACH_HOST_PROHIB = 10 ; ditto |
ICMP_UNREACH_TOSNET = 11 ; bad tos for net |
ICMP_UNREACH_TOSHOST = 12 ; bad tos for host |
ICMP_UNREACH_FILTER_PROHIB = 13 ; admin prohib |
ICMP_UNREACH_HOST_PRECEDENCE = 14 ; host prec vio. |
ICMP_UNREACH_PRECEDENCE_CUTOFF = 15 ; prec cutoff |
ICMP_SOURCEQUENCH equ 4 ; Packet lost, slow down |
ICMP_SOURCEQUENCH = 4 ; Packet lost, slow down |
ICMP_REDIRECT equ 5 ; shorter route, codes: |
ICMP_REDIRECT_NET equ 0 ; for network |
ICMP_REDIRECT_HOST equ 1 ; for host |
ICMP_REDIRECT_TOSNET equ 2 ; for tos and net |
ICMP_REDIRECT_TOSHOST equ 3 ; for tos and host |
ICMP_REDIRECT = 5 ; shorter route, codes: |
ICMP_REDIRECT_NET = 0 ; for network |
ICMP_REDIRECT_HOST = 1 ; for host |
ICMP_REDIRECT_TOSNET = 2 ; for tos and net |
ICMP_REDIRECT_TOSHOST = 3 ; for tos and host |
ICMP_ALTHOSTADDR equ 6 ; alternate host address |
ICMP_ECHO equ 8 ; echo service |
ICMP_ROUTERADVERT equ 9 ; router advertisement |
ICMP_ROUTERADVERT_NORMAL equ 0 ; normal advertisement |
ICMP_ROUTERADVERT_NOROUTE_COMMON equ 16 ; selective routing |
ICMP_ALTHOSTADDR = 6 ; alternate host address |
ICMP_ECHO = 8 ; echo service |
ICMP_ROUTERADVERT = 9 ; router advertisement |
ICMP_ROUTERADVERT_NORMAL = 0 ; normal advertisement |
ICMP_ROUTERADVERT_NOROUTE_COMMON= 16 ; selective routing |
ICMP_ROUTERSOLICIT equ 10 ; router solicitation |
ICMP_TIMXCEED equ 11 ; time exceeded, code: |
ICMP_TIMXCEED_INTRANS equ 0 ; ttl==0 in transit |
ICMP_TIMXCEED_REASS equ 1 ; ttl==0 in reass |
ICMP_ROUTERSOLICIT = 10 ; router solicitation |
ICMP_TIMXCEED = 11 ; time exceeded, code: |
ICMP_TIMXCEED_INTRANS = 0 ; ttl==0 in transit |
ICMP_TIMXCEED_REASS = 1 ; ttl==0 in reass |
ICMP_PARAMPROB equ 12 ; ip header bad |
ICMP_PARAMPROB_ERRATPTR equ 0 ; error at param ptr |
ICMP_PARAMPROB_OPTABSENT equ 1 ; req. opt. absent |
ICMP_PARAMPROB_LENGTH equ 2 ; bad length |
ICMP_PARAMPROB = 12 ; ip header bad |
ICMP_PARAMPROB_ERRATPTR = 0 ; error at param ptr |
ICMP_PARAMPROB_OPTABSENT = 1 ; req. opt. absent |
ICMP_PARAMPROB_LENGTH = 2 ; bad length |
ICMP_TSTAMP equ 13 ; timestamp request |
ICMP_TSTAMPREPLY equ 14 ; timestamp reply |
ICMP_IREQ equ 15 ; information request |
ICMP_IREQREPLY equ 16 ; information reply |
ICMP_MASKREQ equ 17 ; address mask request |
ICMP_MASKREPLY equ 18 ; address mask reply |
ICMP_TRACEROUTE equ 30 ; traceroute |
ICMP_DATACONVERR equ 31 ; data conversion error |
ICMP_MOBILE_REDIRECT equ 32 ; mobile host redirect |
ICMP_IPV6_WHEREAREYOU equ 33 ; IPv6 where-are-you |
ICMP_IPV6_IAMHERE equ 34 ; IPv6 i-am-here |
ICMP_MOBILE_REGREQUEST equ 35 ; mobile registration req |
ICMP_MOBILE_REGREPLY equ 36 ; mobile registreation reply |
ICMP_SKIP equ 39 ; SKIP |
ICMP_TSTAMP = 13 ; timestamp request |
ICMP_TSTAMPREPLY = 14 ; timestamp reply |
ICMP_IREQ = 15 ; information request |
ICMP_IREQREPLY = 16 ; information reply |
ICMP_MASKREQ = 17 ; address mask request |
ICMP_MASKREPLY = 18 ; address mask reply |
ICMP_TRACEROUTE = 30 ; traceroute |
ICMP_DATACONVERR = 31 ; data conversion error |
ICMP_MOBILE_REDIRECT = 32 ; mobile host redirect |
ICMP_IPV6_WHEREAREYOU = 33 ; IPv6 where-are-you |
ICMP_IPV6_IAMHERE = 34 ; IPv6 i-am-here |
ICMP_MOBILE_REGREQUEST = 35 ; mobile registration req |
ICMP_MOBILE_REGREPLY = 36 ; mobile registreation reply |
ICMP_SKIP = 39 ; SKIP |
ICMP_PHOTURIS equ 40 ; Photuris |
ICMP_PHOTURIS_UNKNOWN_INDEX equ 1 ; unknown sec index |
ICMP_PHOTURIS_AUTH_FAILED equ 2 ; auth failed |
ICMP_PHOTURIS_DECRYPT_FAILED equ 3 ; decrypt failed |
ICMP_PHOTURIS = 40 ; Photuris |
ICMP_PHOTURIS_UNKNOWN_INDEX = 1 ; unknown sec index |
ICMP_PHOTURIS_AUTH_FAILED = 2 ; auth failed |
ICMP_PHOTURIS_DECRYPT_FAILED = 3 ; decrypt failed |
410,7 → 410,7 |
; |
;----------------------------------------------------------------- |
align 4 |
ICMP_API: |
ICMP_api: |
movzx eax, bh |
shl eax, 2 |
425,11 → 425,9 |
ret |
.packets_tx: |
add eax, ICMP_PACKETS_TX |
mov eax, [eax] |
mov eax, [ICMP_PACKETS_TX + eax] |
ret |
.packets_rx: |
add eax, ICMP_PACKETS_RX |
mov eax, [eax] |
mov eax, [ICMP_PACKETS_RX + eax] |
ret |
/kernel/branches/net/network/socket.inc |
---|
171,11 → 171,11 |
ends |
SOCKETBUFFSIZE equ 4096 ; in bytes |
SOCKETBUFFSIZE = 4096 ; in bytes |
SOCKET_QUEUE_SIZE equ 10 ; maximum number ofincoming packets queued for 1 socket |
SOCKET_QUEUE_SIZE = 10 ; maximum number ofincoming packets queued for 1 socket |
; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start |
SOCKET_QUEUE_LOCATION equ (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue) |
SOCKET_QUEUE_LOCATION = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue) |
uglobal |
net_sockets rd 4 |
221,8 → 221,17 |
; Socket API (function 74) |
; |
;----------------------------------------------------------------- |
align 16 |
sock_sysfn_table: |
align 4 |
sys_socket: |
cmp ebx, 255 |
jz SOCKET_debug |
cmp ebx, .number |
ja s_error |
jmp dword [.table + 4*ebx] |
.table: |
dd SOCKET_open ; 0 |
dd SOCKET_close ; 1 |
dd SOCKET_bind ; 2 |
233,19 → 242,8 |
dd SOCKET_receive ; 7 |
dd SOCKET_set_opt ; 8 |
dd SOCKET_get_opt ; 9 |
.number = ($ - .table) / 4 - 1 |
SOCKET_SYSFUNCS = ($ - sock_sysfn_table)/4 |
align 4 |
sys_socket: |
cmp ebx, SOCKET_SYSFUNCS-1 |
ja @f |
jmp dword [sock_sysfn_table + 4*ebx] |
@@: |
cmp ebx, 255 |
jz SOCKET_debug |
s_error: |
DEBUGF 1,"socket error\n" |
mov dword [esp+32], -1 |
/kernel/branches/net/network/stack.inc |
---|
31,77 → 31,77 |
net_tmr_count dw ? |
endg |
MAX_NET_DEVICES equ 16 |
MAX_NET_DEVICES = 16 |
MIN_EPHEMERAL_PORT equ 49152 |
MAX_EPHEMERAL_PORT equ 61000 |
MIN_EPHEMERAL_PORT = 49152 |
MAX_EPHEMERAL_PORT = 61000 |
; Ethernet protocol numbers |
ETHER_ARP equ 0x0608 |
ETHER_IPv4 equ 0x0008 |
ETHER_PPP_DISCOVERY equ 0x6388 |
ETHER_PPP_SESSION equ 0x6488 |
ETHER_ARP = 0x0608 |
ETHER_IPv4 = 0x0008 |
ETHER_PPP_DISCOVERY = 0x6388 |
ETHER_PPP_SESSION = 0x6488 |
;Protocol family |
AF_UNSPEC equ 0 |
AF_UNIX equ 1 |
AF_INET4 equ 2 |
AF_INET6 equ 10 |
AF_UNSPEC = 0 |
AF_UNIX = 1 |
AF_INET4 = 2 |
AF_INET6 = 10 |
; Internet protocol numbers |
IP_PROTO_IP equ 0 |
IP_PROTO_ICMP equ 1 |
IP_PROTO_TCP equ 6 |
IP_PROTO_UDP equ 17 |
IP_PROTO_IP = 0 |
IP_PROTO_ICMP = 1 |
IP_PROTO_TCP = 6 |
IP_PROTO_UDP = 17 |
; Socket types |
SOCK_STREAM equ 1 |
SOCK_DGRAM equ 2 |
SOCK_RAW equ 3 |
SOCK_STREAM = 1 |
SOCK_DGRAM = 2 |
SOCK_RAW = 3 |
; Socket options |
SO_ACCEPTCON equ 1 shl 0 |
SO_BROADCAST equ 1 shl 1 |
SO_DEBUG equ 1 shl 2 |
SO_DONTROUTE equ 1 shl 3 |
SO_KEEPALIVE equ 1 shl 4 |
SO_OOBINLINE equ 1 shl 5 |
SO_REUSEADDR equ 1 shl 6 |
SO_REUSEPORT equ 1 shl 7 |
SO_USELOOPBACK equ 1 shl 8 |
SO_ACCEPTCON = 1 shl 0 |
SO_BROADCAST = 1 shl 1 |
SO_DEBUG = 1 shl 2 |
SO_DONTROUTE = 1 shl 3 |
SO_KEEPALIVE = 1 shl 4 |
SO_OOBINLINE = 1 shl 5 |
SO_REUSEADDR = 1 shl 6 |
SO_REUSEPORT = 1 shl 7 |
SO_USELOOPBACK = 1 shl 8 |
; Socket States |
SS_NOFDREF equ 0x001 ; no file table ref any more |
SS_ISCONNECTED equ 0x002 ; socket connected to a peer |
SS_ISCONNECTING equ 0x004 ; in process of connecting to peer |
SS_ISDISCONNECTING equ 0x008 ; in process of disconnecting |
SS_CANTSENDMORE equ 0x010 ; can't send more data to peer |
SS_CANTRCVMORE equ 0x020 ; can't receive more data from peer |
SS_RCVATMARK equ 0x040 ; at mark on input |
SS_ISABORTING equ 0x080 ; aborting fd references - close() |
SS_RESTARTSYS equ 0x100 ; restart blocked system calls |
SS_ISDISCONNECTED equ 0x800 ; socket disconnected from peer |
SS_NOFDREF = 0x001 ; no file table ref any more |
SS_ISCONNECTED = 0x002 ; socket connected to a peer |
SS_ISCONNECTING = 0x004 ; in process of connecting to peer |
SS_ISDISCONNECTING = 0x008 ; in process of disconnecting |
SS_CANTSENDMORE = 0x010 ; can't send more data to peer |
SS_CANTRCVMORE = 0x020 ; can't receive more data from peer |
SS_RCVATMARK = 0x040 ; at mark on input |
SS_ISABORTING = 0x080 ; aborting fd references - close() |
SS_RESTARTSYS = 0x100 ; restart blocked system calls |
SS_ISDISCONNECTED = 0x800 ; socket disconnected from peer |
SS_ASYNC equ 0x100 ; async i/o notify |
SS_ISCONFIRMING equ 0x200 ; deciding to accept connection req |
SS_MORETOCOME equ 0x400 |
SS_ASYNC = 0x100 ; async i/o notify |
SS_ISCONFIRMING = 0x200 ; deciding to accept connection req |
SS_MORETOCOME = 0x400 |
SOCKET_MAXDATA equ 4096*32 ; must be 4096*(power of 2) where 'power of 2' is at least 8 |
SOCKET_MAXDATA = 4096*32 ; must be 4096*(power of 2) where 'power of 2' is at least 8 |
; Network driver types |
NET_TYPE_ETH equ 1 |
NET_TYPE_SLIP equ 2 |
NET_TYPE_ETH = 1 |
NET_TYPE_SLIP = 2 |
MAX_backlog equ 20 ; maximum backlog for stream sockets |
MAX_backlog = 20 ; maximum backlog for stream sockets |
; Error Codes |
ENOBUFS equ 55 |
ECONNREFUSED equ 61 |
ECONNRESET equ 52 |
ETIMEDOUT equ 60 |
ECONNABORTED equ 53 |
ENOBUFS = 55 |
ECONNREFUSED = 61 |
ECONNRESET = 52 |
ETIMEDOUT = 60 |
ECONNABORTED = 53 |
155,8 → 155,7 |
include "ethernet.inc" |
;include "slip.inc" |
;include "pppoe.inc" |
;include "PPPoE.inc" |
include "ARP.inc" |
include "IPv4.inc" |
691,23 → 690,26 |
shr eax, 16 ; |
cmp ax , IP_PROTO_IP |
je IPv4_API |
je IPv4_api |
cmp ax , IP_PROTO_ICMP |
je ICMP_API |
je ICMP_api |
cmp ax , IP_PROTO_UDP |
je UDP_API |
je UDP_api |
cmp ax , IP_PROTO_TCP |
je TCP_API |
je TCP_api |
cmp ax , ETHER_ARP |
je ARP_API |
je ARP_api |
cmp ax , 1337 ;;;;; |
je ETH_API |
je ETH_api |
; cmp ax, API_PPPoE |
; je PPPoE_api |
add esp, 4 ; if we reached here, no function was called, so we need to balance stack |
.doesnt_exist: |
715,7 → 717,7 |
mov eax, -1 |
.return: |
mov [esp+28+4], eax |
mov [esp+28+4], eax ; return eax value to the program |
ret |
/kernel/branches/net/network/tcp.inc |
---|
17,68 → 17,68 |
$Revision$ |
; Socket states |
TCPS_CLOSED equ 0 |
TCPS_LISTEN equ 1 |
TCPS_SYN_SENT equ 2 |
TCPS_SYN_RECEIVED equ 3 |
TCPS_ESTABLISHED equ 4 |
TCPS_CLOSE_WAIT equ 5 |
TCPS_FIN_WAIT_1 equ 6 |
TCPS_CLOSING equ 7 |
TCPS_LAST_ACK equ 8 |
TCPS_FIN_WAIT_2 equ 9 |
TCPS_TIMED_WAIT equ 10 |
TCPS_CLOSED = 0 |
TCPS_LISTEN = 1 |
TCPS_SYN_SENT = 2 |
TCPS_SYN_RECEIVED = 3 |
TCPS_ESTABLISHED = 4 |
TCPS_CLOSE_WAIT = 5 |
TCPS_FIN_WAIT_1 = 6 |
TCPS_CLOSING = 7 |
TCPS_LAST_ACK = 8 |
TCPS_FIN_WAIT_2 = 9 |
TCPS_TIMED_WAIT = 10 |
; Socket Flags |
TF_ACKNOW equ 1 shl 0 ; ack peer immediately |
TF_DELACK equ 1 shl 1 ; ack, but try to delay it |
TF_NODELAY equ 1 shl 2 ; don't delay packets to coalesce |
TF_NOOPT equ 1 shl 3 ; don't use tcp options |
TF_SENTFIN equ 1 shl 4 ; have sent FIN |
TF_REQ_SCALE equ 1 shl 5 ; have/will request window scaling |
TF_RCVD_SCALE equ 1 shl 6 ; other side has requested scaling |
TF_REQ_TSTMP equ 1 shl 7 ; have/will request timestamps |
TF_RCVD_TSTMP equ 1 shl 8 ; a timestamp was received in SYN |
TF_SACK_PERMIT equ 1 shl 9 ; other side said I could SACK |
TF_ACKNOW = 1 shl 0 ; ack peer immediately |
TF_DELACK = 1 shl 1 ; ack, but try to delay it |
TF_NODELAY = 1 shl 2 ; don't delay packets to coalesce |
TF_NOOPT = 1 shl 3 ; don't use tcp options |
TF_SENTFIN = 1 shl 4 ; have sent FIN |
TF_REQ_SCALE = 1 shl 5 ; have/will request window scaling |
TF_RCVD_SCALE = 1 shl 6 ; other side has requested scaling |
TF_REQ_TSTMP = 1 shl 7 ; have/will request timestamps |
TF_RCVD_TSTMP = 1 shl 8 ; a timestamp was received in SYN |
TF_SACK_PERMIT = 1 shl 9 ; other side said I could SACK |
; Segment flags |
TH_FIN equ 1 shl 0 |
TH_SYN equ 1 shl 1 |
TH_RST equ 1 shl 2 |
TH_PUSH equ 1 shl 3 |
TH_ACK equ 1 shl 4 |
TH_URG equ 1 shl 5 |
TH_FIN = 1 shl 0 |
TH_SYN = 1 shl 1 |
TH_RST = 1 shl 2 |
TH_PUSH = 1 shl 3 |
TH_ACK = 1 shl 4 |
TH_URG = 1 shl 5 |
; Segment header options |
TCP_OPT_EOL equ 0 ; End of option list. |
TCP_OPT_NOP equ 1 ; No-Operation. |
TCP_OPT_MAXSEG equ 2 ; Maximum Segment Size. |
TCP_OPT_WINDOW equ 3 ; window scale |
TCP_OPT_TIMESTAMP equ 8 |
TCP_OPT_EOL = 0 ; End of option list. |
TCP_OPT_NOP = 1 ; No-Operation. |
TCP_OPT_MAXSEG = 2 ; Maximum Segment Size. |
TCP_OPT_WINDOW = 3 ; window scale |
TCP_OPT_TIMESTAMP = 8 |
; Fundamental timer values |
TCP_time_MSL equ 47 ; max segment lifetime (30s) |
TCP_time_re_min equ 2 ; min retransmission (1,28s) |
TCP_time_re_max equ 100 ; max retransmission (64s) |
TCP_time_pers_min equ 8 ; min persist (5,12s) |
TCP_time_pers_max equ 94 ; max persist (60,16s) |
TCP_time_keep_init equ 118 ; connectione stablishment (75,52s) |
TCP_time_keep_idle equ 4608 ; idle time before 1st probe (2h) |
TCP_time_keep_interval equ 118 ; between probes when no response (75,52s) |
TCP_time_rtt_default equ 5 ; default Round Trip Time (3,2s) |
TCP_time_srtt_default equ 0 ; |
TCP_time_MSL = 47 ; max segment lifetime (30s) |
TCP_time_re_min = 2 ; min retransmission (1,28s) |
TCP_time_re_max = 100 ; max retransmission (64s) |
TCP_time_pers_min = 8 ; min persist (5,12s) |
TCP_time_pers_max = 94 ; max persist (60,16s) |
TCP_time_keep_init = 118 ; connectione stablishment (75,52s) |
TCP_time_keep_idle = 4608 ; idle time before 1st probe (2h) |
TCP_time_keep_interval = 118 ; between probes when no response (75,52s) |
TCP_time_rtt_default = 5 ; default Round Trip Time (3,2s) |
TCP_time_srtt_default = 0 ; |
; timer constants |
TCP_max_rxtshift equ 12 ; max retransmissions waiting for ACK |
TCP_max_keepcnt equ 8 ; max keepalive probes |
TCP_max_rxtshift = 12 ; max retransmissions waiting for ACK |
TCP_max_keepcnt = 8 ; max keepalive probes |
; |
TCP_max_winshift equ 14 |
TCP_max_win equ 65535 |
TCP_max_winshift = 14 |
TCP_max_win = 65535 |
TCP_re_xmit_thresh equ 3 |
TCP_re_xmit_thresh = 3 |
TCP_mss_default equ 1480 ; default max segment size |
TCP_mss_default = 1480 ; default max segment size |
struct TCP_header |
96,8 → 96,8 |
align 4 |
uglobal |
TCP_headers_tx rd IP_MAX_INTERFACES |
TCP_headers_rx rd IP_MAX_INTERFACES |
TCP_segments_tx rd IP_MAX_INTERFACES |
TCP_segments_rx rd IP_MAX_INTERFACES |
TCP_bytes_rx rq IP_MAX_INTERFACES |
TCP_bytes_tx rq IP_MAX_INTERFACES |
TCP_sequence_num dd ? |
114,7 → 114,7 |
macro TCP_init { |
xor eax, eax |
mov edi, TCP_headers_tx |
mov edi, TCP_segments_tx |
mov ecx, (6*IP_MAX_INTERFACES) |
rep stosd |
144,7 → 144,7 |
; |
;--------------------------------------------------------------------------- |
align 4 |
TCP_API: |
TCP_api: |
movzx eax, bh |
shl eax, 2 |
159,11 → 159,9 |
ret |
.packets_tx: |
add eax, TCP_headers_tx |
mov eax, [eax] |
mov eax, [TCP_segments_tx + eax] |
ret |
.packets_rx: |
add eax, TCP_headers_rx |
mov eax, [eax] |
mov eax, [TCP_segments_rx + eax] |
ret |
/kernel/branches/net/network/udp.inc |
---|
308,7 → 308,7 |
;--------------------------------------------------------------------------- |
align 4 |
UDP_API: |
UDP_api: |
movzx eax, bh |
shl eax, 2 |