Subversion Repositories Kolibri OS

Rev

Rev 7678 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3545 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
9816 Boppan 3
;; Copyright (C) KolibriOS team 2004-2022. All rights reserved.    ;;
3545 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  ICMP.INC                                                       ;;
7
;;                                                                 ;;
8
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
9
;;                                                                 ;;
10
;;  Based on the work of [Johnny_B] and [smb]                      ;;
11
;;                                                                 ;;
12
;;    Written by hidnplayr@kolibrios.org                           ;;
13
;;                                                                 ;;
14
;;          GNU GENERAL PUBLIC LICENSE                             ;;
15
;;             Version 2, June 1991                                ;;
16
;;                                                                 ;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18
 
4850 mario79 19
$Revision: 9816 $
3545 hidnplayr 20
 
21
; ICMP types & codes
22
 
6011 hidnplayr 23
ICMP_ECHOREPLY                  = 0             ; echo reply message
3545 hidnplayr 24
 
25
ICMP_UNREACH                    = 3
6011 hidnplayr 26
ICMP_UNREACH_NET                = 0             ; bad net
27
ICMP_UNREACH_HOST               = 1             ; bad host
28
ICMP_UNREACH_PROTOCOL           = 2             ; bad protocol
29
ICMP_UNREACH_PORT               = 3             ; bad port
30
ICMP_UNREACH_NEEDFRAG           = 4             ; IP_DF caused drop
31
ICMP_UNREACH_SRCFAIL            = 5             ; src route failed
32
ICMP_UNREACH_NET_UNKNOWN        = 6             ; unknown net
33
ICMP_UNREACH_HOST_UNKNOWN       = 7             ; unknown host
34
ICMP_UNREACH_ISOLATED           = 8             ; src host isolated
35
ICMP_UNREACH_NET_PROHIB         = 9             ; prohibited access
36
ICMP_UNREACH_HOST_PROHIB        = 10            ; ditto
37
ICMP_UNREACH_TOSNET             = 11            ; bad tos for net
38
ICMP_UNREACH_TOSHOST            = 12            ; bad tos for host
39
ICMP_UNREACH_FILTER_PROHIB      = 13            ; admin prohib
40
ICMP_UNREACH_HOST_PRECEDENCE    = 14            ; host prec vio.
41
ICMP_UNREACH_PRECEDENCE_CUTOFF  = 15            ; prec cutoff
3545 hidnplayr 42
 
6011 hidnplayr 43
ICMP_SOURCEQUENCH               = 4             ; Packet lost, slow down
3545 hidnplayr 44
 
6011 hidnplayr 45
ICMP_REDIRECT                   = 5             ; shorter route, codes:
46
ICMP_REDIRECT_NET               = 0             ; for network
47
ICMP_REDIRECT_HOST              = 1             ; for host
48
ICMP_REDIRECT_TOSNET            = 2             ; for tos and net
49
ICMP_REDIRECT_TOSHOST           = 3             ; for tos and host
3545 hidnplayr 50
 
6011 hidnplayr 51
ICMP_ALTHOSTADDR                = 6             ; alternate host address
52
ICMP_ECHO                       = 8             ; echo service
53
ICMP_ROUTERADVERT               = 9             ; router advertisement
54
ICMP_ROUTERADVERT_NORMAL        = 0             ; normal advertisement
55
ICMP_ROUTERADVERT_NOROUTE_COMMON= 16            ; selective routing
3545 hidnplayr 56
 
6011 hidnplayr 57
ICMP_ROUTERSOLICIT              = 10            ; router solicitation
58
ICMP_TIMXCEED                   = 11            ; time exceeded, code:
59
ICMP_TIMXCEED_INTRANS           = 0             ; ttl==0 in transit
60
ICMP_TIMXCEED_REASS             = 1             ; ttl==0 in reass
3545 hidnplayr 61
 
6011 hidnplayr 62
ICMP_PARAMPROB                  = 12            ; ip header bad
63
ICMP_PARAMPROB_ERRATPTR         = 0             ; error at param ptr
64
ICMP_PARAMPROB_OPTABSENT        = 1             ; req. opt. absent
65
ICMP_PARAMPROB_LENGTH           = 2             ; bad length
3545 hidnplayr 66
 
6011 hidnplayr 67
ICMP_TSTAMP                     = 13            ; timestamp request
68
ICMP_TSTAMPREPLY                = 14            ; timestamp reply
69
ICMP_IREQ                       = 15            ; information request
70
ICMP_IREQREPLY                  = 16            ; information reply
71
ICMP_MASKREQ                    = 17            ; address mask request
72
ICMP_MASKREPLY                  = 18            ; address mask reply
73
ICMP_TRACEROUTE                 = 30            ; traceroute
74
ICMP_DATACONVERR                = 31            ; data conversion error
75
ICMP_MOBILE_REDIRECT            = 32            ; mobile host redirect
76
ICMP_IPV6_WHEREAREYOU           = 33            ; IPv6 where-are-you
77
ICMP_IPV6_IAMHERE               = 34            ; IPv6 i-am-here
78
ICMP_MOBILE_REGREQUEST          = 35            ; mobile registration req
79
ICMP_MOBILE_REGREPLY            = 36            ; mobile registreation reply
80
ICMP_SKIP                       = 39            ; SKIP
3545 hidnplayr 81
 
6011 hidnplayr 82
ICMP_PHOTURIS                   = 40            ; Photuris
83
ICMP_PHOTURIS_UNKNOWN_INDEX     = 1             ; unknown sec index
84
ICMP_PHOTURIS_AUTH_FAILED       = 2             ; auth failed
85
ICMP_PHOTURIS_DECRYPT_FAILED    = 3             ; decrypt failed
3545 hidnplayr 86
 
87
 
88
struct  ICMP_header
89
 
90
        Type                    db ?
91
        Code                    db ?
92
        Checksum                dw ?
93
        Identifier              dw ?
94
        SequenceNumber          dw ?
95
 
96
ends
97
 
98
 
3698 hidnplayr 99
uglobal
3545 hidnplayr 100
align 4
3698 hidnplayr 101
 
7678 hidnplayr 102
        ICMP_packets_tx         rd NET_DEVICES_MAX
103
        ICMP_packets_rx         rd NET_DEVICES_MAX
3698 hidnplayr 104
 
3545 hidnplayr 105
endg
106
 
107
 
108
 
6011 hidnplayr 109
;-----------------------------------------------------------------;
110
;                                                                 ;
111
; ICMP_init                                                       ;
112
;                                                                 ;
113
;-----------------------------------------------------------------;
3545 hidnplayr 114
 
6011 hidnplayr 115
macro icmp_init {
3545 hidnplayr 116
 
117
        xor     eax, eax
7678 hidnplayr 118
        mov     edi, ICMP_packets_tx
3600 hidnplayr 119
        mov     ecx, 2*NET_DEVICES_MAX
3711 clevermous 120
        rep stosd
3545 hidnplayr 121
 
122
}
123
 
124
 
6011 hidnplayr 125
;-----------------------------------------------------------------;
126
;                                                                 ;
127
; icmp_input: Send a reply's to an ICMP echo or insert packets    ;
128
; into socket.                                                    ;
129
;                                                                 ;
130
;  IN:  [esp] = ptr to buffer                                     ;
131
;       ebx = ptr to device struct                                ;
132
;       ecx = ICMP Packet size                                    ;
133
;       edx = ptr to IPv4 header                                  ;
134
;       esi = ptr to ICMP Packet data                             ;
135
;       edi = interface number*4                                  ;
136
;                                                                 ;
137
;  OUT: /                                                         ;
138
;                                                                 ;
139
;-----------------------------------------------------------------;
3545 hidnplayr 140
align 4
6011 hidnplayr 141
icmp_input:
3545 hidnplayr 142
 
5522 hidnplayr 143
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ICMP_input\n"
3545 hidnplayr 144
 
5842 hidnplayr 145
; Dump all multicasts and broadcasts
7678 hidnplayr 146
        mov     eax, [IPv4_address + edi]
5842 hidnplayr 147
        cmp     eax, [edx + IPv4_header.DestinationAddress]
148
        jne     .dump
149
 
5522 hidnplayr 150
; Check the checksum
5842 hidnplayr 151
        push    esi ecx edx
3545 hidnplayr 152
        push    [esi + ICMP_header.Checksum]
153
        mov     [esi + ICMP_header.Checksum], 0
154
        xor     edx, edx
155
        call    checksum_1
156
        call    checksum_2
157
        pop     si
158
        cmp     dx, si
5842 hidnplayr 159
        pop     edx ecx esi
3545 hidnplayr 160
        jne     .checksum_mismatch
161
 
5522 hidnplayr 162
        DEBUGF  DEBUG_NETWORK_VERBOSE, "ICMP_input: Checksum OK\n"
3643 hidnplayr 163
 
5522 hidnplayr 164
; Update stats
7678 hidnplayr 165
        inc     [ICMP_packets_rx + edi]
3643 hidnplayr 166
 
5522 hidnplayr 167
; Is this an echo request?
168
        cmp     [esi + ICMP_header.Type], ICMP_ECHO
169
        je      .echo_request
3545 hidnplayr 170
 
5522 hidnplayr 171
; Look for an open ICMP socket
3647 hidnplayr 172
        pusha
173
        mov     ecx, socket_mutex
174
        call    mutex_lock
175
        popa
176
 
5842 hidnplayr 177
        add     ecx, esi
178
        sub     ecx, edx
179
        mov     esi, edx
3545 hidnplayr 180
        mov     eax, net_sockets
181
  .next_socket:
182
        mov     eax, [eax + SOCKET.NextPtr]
183
        or      eax, eax
3647 hidnplayr 184
        jz      .dump_
3545 hidnplayr 185
 
186
        cmp     [eax + SOCKET.Domain], AF_INET4
187
        jne     .next_socket
188
 
189
        cmp     [eax + SOCKET.Protocol], IP_PROTO_ICMP
190
        jne     .next_socket
191
 
3647 hidnplayr 192
        pusha
193
        mov     ecx, socket_mutex
194
        call    mutex_unlock
195
        popa
196
 
3556 hidnplayr 197
        DEBUGF  DEBUG_NETWORK_VERBOSE, "socket=%x\n", eax
3545 hidnplayr 198
 
199
        pusha
200
        lea     ecx, [eax + SOCKET.mutex]
201
        call    mutex_lock
202
        popa
203
 
6011 hidnplayr 204
        jmp     socket_input</