Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / netinet / icmp.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: icmp.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)icmp.fth 1.1 04/09/07
43purpose: ICMP support
44copyright: Copyright 2004 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47\ RFC 792: Internet Control Message Protocol
48
49headerless
50
51struct
52 /ip-header field >icmp-iphdr \ IP header, no options
53 /c field >icmp-type \ Message type
54 /c field >icmp-code \ Message type subcode
55 /w field >icmp-cksum \ Checksum
56 0 field >icmp-gwaddr \ Preferred gateway (ICMP_REDIRECT)
57 /w field >icmp-id \ Message id (ICMP_ECHO)
58 /w field >icmp-seq \ Sequence number (ICMP_ECHO)
59 0 field >icmp-ip \ IP header (ICMP_REDIRECT)
60 0 field >icmp-data \ Data (ICMP_ECHO)
61constant /icmpip-header
62
63\ ICMP message types
640 constant ICMP_ECHOREPLY \ Echo reply
65d# 5 constant ICMP_REDIRECT \ Better route available
66d# 8 constant ICMP_ECHO \ Echo request
67
68\ Compute checksum on the ICMP (IP payload) packet
69: icmp-checksum ( ip-pkt -- checksum )
70 0 swap ippkt>payload in-cksum
71;
72
73\ Fill in ICMP checksum and send the packet
74: icmp-output ( ip-pkt -- )
75 0 over >icmp-cksum htonw! ( pkt )
76 dup icmp-checksum over >icmp-cksum htonw! ( pkt )
77 ip-output drop ( )
78;
79
80\ Handle an incoming ICMP redirect. Network redirects and host redirects
81\ are treated identically.
82: icmp-redirect ( ip-pkt -- )
83 dup >icmp-ip >ip-dest swap >icmp-gwaddr RT_HOST route-update
84;
85
86\ Respond to ICMP ECHO requests.
87: icmp-reflect ( ip-pkt -- )
88 dup >ip-src over >ip-dest copy-ip-addr ( pkt )
89 my-ip-addr over >ip-src copy-ip-addr ( pkt )
90 ICMP_ECHOREPLY over >icmp-type c! ( pkt )
91 icmp-output ( )
92;
93
94\ Process incoming ICMP packet
95: icmp-input ( pkt -- )
96 my-ip-addr inaddr-any? 0= if ( pkt )
97 dup icmp-checksum 0= if ( pkt )
98 dup >icmp-type c@ case
99 ICMP_ECHO of icmp-reflect exit endof
100 ICMP_REDIRECT of dup icmp-redirect endof
101 endcase
102 then ( pkt )
103 then ( pkt )
104 pkt-free ( )
105;
106['] icmp-input to (icmp-input)
107
108headers