Rev 837 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 837 | Rev 914 | ||
---|---|---|---|
Line 10... | Line 10... | ||
10 | ;; ;; |
10 | ;; ;; |
11 | ;; See file COPYING for details ;; |
11 | ;; See file COPYING for details ;; |
12 | ;; ;; |
12 | ;; ;; |
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 14... | Line 14... | ||
14 | 14 | ||
Line 15... | Line 15... | ||
15 | $Revision: 593 $ |
15 | $Revision: 914 $ |
16 | 16 | ||
17 | 17 | ||
Line 85... | Line 85... | ||
85 | ; IHL keeps number of octets, so we need to << 2 'reg' |
85 | ; IHL keeps number of octets, so we need to << 2 'reg' |
86 | shl reg, 2 |
86 | shl reg, 2 |
87 | } |
87 | } |
Line -... | Line 88... | ||
- | 88 | ||
- | 89 | ||
- | 90 | include "tcp.inc" |
|
- | 91 | include "udp.inc" |
|
88 | 92 | include "icmp.inc" |
|
89 | 93 | ||
90 | ;*************************************************************************** |
94 | ;*************************************************************************** |
91 | ; Function |
95 | ; Function |
92 | ; ip_rx |
96 | ; ip_rx |
Line 112... | Line 116... | ||
112 | imul eax, IPBUFFSIZE |
116 | imul eax, IPBUFFSIZE |
113 | add eax, IPbuffs |
117 | add eax, IPbuffs |
Line 114... | Line 118... | ||
114 | 118 | ||
Line -... | Line 119... | ||
- | 119 | mov ebx, eax ; ebx=pointer to IP_PACKET |
|
- | 120 | ||
115 | mov ebx, eax ; ebx=pointer to IP_PACKET |
121 | ; DEBUGF 1, "K : ip_rx - proto: %u\n", [ebx + IP_PACKET.Protocol]:1 |
116 | 122 | ||
117 | ; Validate the IP checksum |
123 | ; Validate the IP checksum |
Line 118... | Line 124... | ||
118 | mov dx, word[ebx + IP_PACKET.HeaderChecksum] |
124 | mov dx, word[ebx + IP_PACKET.HeaderChecksum] |
119 | xchg dh,dl ; Get the checksum in intel format |
125 | xchg dh,dl ; Get the checksum in intel format |
120 | 126 | ||
121 | mov [ebx + IP_PACKET.HeaderChecksum], word 0 ; clear checksum field - need to when |
127 | mov [ebx + IP_PACKET.HeaderChecksum], 0 ; clear checksum field - need to when |
Line 122... | Line 128... | ||
122 | ; recalculating checksum |
128 | ; recalculating checksum |
123 | ; this needs two data pointers and two size #. |
129 | ; this needs two data pointers and two size #. |
124 | ; 2nd pointer can be of length 0 |
130 | ; 2nd pointer can be of length 0 |
Line -... | Line 131... | ||
- | 131 | ||
- | 132 | GET_IHL ecx, ebx + IP_PACKET.VersionAndIHL ;get packet length in ecx |
|
- | 133 | stdcall checksum_jb, ebx, ecx ;buf_ptr, buf_size |
|
125 | 134 | cmp dx, ax |
|
- | 135 | ||
126 | GET_IHL ecx, ebx + IP_PACKET.VersionAndIHL ;get packet length in ecx |
136 | ; DEBUGF 1, "K : ip_rx - checksums: %x - %x\n", dx, ax |
Line 127... | Line 137... | ||
127 | stdcall checksum_jb, ebx, ecx ;buf_ptr, buf_size |
137 | |
128 | cmp dx, ax |
138 | jnz .dump.1 ;if CHECKSUM isn't valid then dump packet |
129 | 139 | mov edx, ebx ; EDX (IP-BUFFER POINTER) WILL BE USED FOR *_rx HANDLERS BELOW!!! |
|
130 | mov edx, ebx ; EDX (IP-BUFFER POINTER) WILL BE USED FOR *_rx HANDLERS BELOW!!! |
140 | |
Line 131... | Line 141... | ||
131 | jnz .dump ;if CHECKSUM isn't valid then dump packet |
141 | ; DEBUGF 1, "K : ip_rx - dest: %x - %x\n", [ebx + IP_PACKET.DestinationAddress], [stack_ip] |
132 | 142 | ||
- | 143 | ; Validate the IP address, if it isn't broadcast |
|
133 | ; Validate the IP address, if it isn't broadcast |
144 | mov eax, [stack_ip] |
- | 145 | cmp dword[ebx + IP_PACKET.DestinationAddress], eax |
|
- | 146 | je @f |
|
- | 147 | ||
- | 148 | ; If the IP address is 255.255.255.255, accept it |
|
- | 149 | ; - it is a broadcast packet, which we need for dhcp |
|
- | 150 | ||
134 | mov eax, [stack_ip] |
151 | mov eax, [ebx + IP_PACKET.DestinationAddress] |
- | 152 | cmp eax, 0xffffffff |
|
- | 153 | ;je @f |
|
- | 154 | ;mov ecx, [stack_ip] |
|
- | 155 | ;and eax, [subnet_mask] |
|
Line 135... | Line 156... | ||
135 | cmp dword[ebx + IP_PACKET.DestinationAddress], eax |
156 | ;and ecx, [subnet_mask] |
136 | je @f |
157 | ;cmp eax, ecx |
137 | 158 | ;jne .dump.2 |
|
138 | ; If the IP address is 255.255.255.255, accept it |
159 | ;mov eax, [ebx + IP_PACKET.DestinationAddress] |
- | 160 | ;or eax, [subnet_mask] |
|
139 | ; - it is a broadcast packet, which we need for dhcp |
161 | ;cmp eax, 0xffffffff |
Line 140... | Line 162... | ||
140 | cmp dword[ebx + IP_PACKET.DestinationAddress], 0xffffffff |
162 | jne .dump.2 |
141 | jne .dump |
- | |
Line -... | Line 163... | ||
- | 163 | ||
- | 164 | @@: |
|
- | 165 | mov al, [ebx + IP_PACKET.VersionAndIHL] |
|
142 | 166 | and al, 0x0f ;get IHL(header length) |
|
143 | @@: |
167 | cmp al, 0x05 ;if IHL!= 5*4(20 bytes) |
- | 168 | ; DEBUGF 1, "K : ip_rx - ihl: %x - 05\n", al |
|
144 | mov al, [ebx + IP_PACKET.VersionAndIHL] |
169 | jnz .dump.3 ;then dump it |
145 | and al, 0x0f ;get IHL(header length) |
170 | |
Line 146... | Line 171... | ||
146 | cmp al, 0x05 ;if IHL!= 5*4(20 bytes) |
171 | ; DEBUGF 1, "K : ip_rx - ttl: %x - 00\n", [ebx + IP_PACKET.TimeToLive]:2 |
147 | jnz .dump ;then dump it |
172 | |
Line 148... | Line 173... | ||
148 | 173 | cmp [ebx + IP_PACKET.TimeToLive], 0 |
|
Line 149... | Line 174... | ||
149 | cmp byte[ebx + IP_PACKET.TimeToLive], byte 0 |
174 | je .dump.4 ;if TTL==0 then dump it |
150 | je .dump ;if TTL==0 then dump it |
175 | |
151 | 176 | mov ax, [ebx + IP_PACKET.FlagsAndFragmentOffset] |
|
152 | mov ax, word[ebx + IP_PACKET.FlagsAndFragmentOffset] |
177 | and ax, 0xFFBF ;get flags |
153 | and ax, 0xFFBF ;get flags |
178 | ; DEBUGF 1, "K : ip_rx - flags: %x - 0000\n", ax |
154 | cmp ax, 0 ;if some flags was set then we dump this packet |
179 | cmp ax, 0 ;if some flags was set then we dump this packet |
Line 155... | Line 180... | ||
155 | jnz .dump ;the flags should be used for fragmented packets |
180 | jnz .dump.5 ;the flags should be used for fragmented packets |
156 | 181 | ||
157 | ; Check the protocol, and call the appropriate handler |
182 | ; Check the protocol, and call the appropriate handler |
158 | ; Each handler will re-use or free the queue buffer as appropriate |
183 | ; Each handler will re-use or free the queue buffer as appropriate |
159 | 184 | ||
160 | mov al, [ebx + IP_PACKET.Protocol] |
185 | mov al, [ebx + IP_PACKET.Protocol] |
161 | 186 | ||
Line 162... | Line 187... | ||
162 | cmp al , PROTOCOL_TCP |
187 | cmp al , PROTOCOL_TCP |
163 | jne .not_tcp |
188 | jne .not_tcp |
164 | DEBUGF 1,"K : ip_rx - TCP packet\n" |
189 | ; DEBUGF 1,"K : ip_rx - TCP packet\n" |
Line 165... | Line 190... | ||
165 | mov eax, dword[buffer_number] |
190 | mov eax, dword[buffer_number] |
166 | call tcp_rx |
191 | call tcp_rx |
167 | jmp .exit |
192 | jmp .exit |
168 | 193 | ||
169 | .not_tcp: |
194 | .not_tcp: |
Line -... | Line 195... | ||
- | 195 | cmp al, PROTOCOL_UDP |
|
- | 196 | jne .not_udp |
|
- | 197 | ; DEBUGF 1,"K : ip_rx - UDP packet\n" |
|
- | 198 | mov eax, dword[buffer_number] |
|
170 | cmp al, PROTOCOL_UDP |
199 | call udp_rx |
- | 200 | jmp .exit |
|
- | 201 | ||
- | 202 | .not_udp: |
|
- | 203 | cmp al, PROTOCOL_ICMP |
|
171 | jne .not_udp |
204 | jne .dump.6 ;protocol ain't supported |
- | 205 | ||
- | 206 | ; DEBUGF 1,"K : ip_rx - ICMP packet\n" |
|
- | 207 | ;GET_IHL ecx, ebx + IP_PACKET.VersionAndIHL ;get packet length in ecx |
|
172 | DEBUGF 1,"K : ip_rx - UDP packet\n" |
208 | mov eax, dword[buffer_number] |
- | 209 | stdcall icmp_rx,eax,ebx,ecx ;buffer_number,IPPacketBase,IPHeaderLength |
|
- | 210 | jmp .exit |
|
- | 211 | ||
- | 212 | ||
- | 213 | .dump.1: |
|
Line -... | Line 214... | ||
- | 214 | DEBUGF 1, "K : ip_rx - dumped (checksum: 0x%x-0x%x)\n", dx, ax |
|
173 | mov eax, dword[buffer_number] |
215 | jmp .dump.x |
Line -... | Line 216... | ||
- | 216 | ||
- | 217 | .dump.2: |
|
174 | call udp_rx |
218 | 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 |
175 | jmp .exit |
219 | jmp .dump.x |
Line 176... | Line 220... | ||
176 | 220 | ||
177 | .not_udp: |
221 | .dump.3: |
178 | cmp al , PROTOCOL_ICMP |
222 | DEBUGF 1, "K : ip_rx - dumped (ihl: %u)\n", al |