Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / netinet / ip-output.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: ip-output.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: @(#)ip-output.fth 1.1 04/09/07
43purpose: IP output routines
44copyright: Copyright 2004 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47headerless
48
49\ Fill in the IP header checksum and send the packet.
50: (ip-output) ( ippkt nexthop -- #sent )
51 swap 0 over >ip-cksum htonw! ( nexthop ippkt )
52 dup ip-checksum over >ip-cksum htonw! ( nexthop ippkt )
53 tuck swap arp-resolve if ( ippkt hwaddr )
54 over ip-len@ swap IP_TYPE if-output ( #sent )
55 else ( ippkt )
56 drop 0 ( 0 )
57 then ( #sent )
58;
59
60: ipf-copydata ( dgram fragoff fraglen fragpkt -- )
61 /ip-header ca+ swap >r >r /ip-header + ca+ r> r> move
62;
63
64\ Construct a fragment.
65: ip-make-fragment ( dgram fragoff fraglen -- fragpkt )
66 pkt-alloc ?dup 0= if ( dgram offset len )
67 3drop 0 exit ( 0 )
68 then ( dgram offset len pkt )
69 3 pick over /ip-header move ( dgram offset len pkt )
70 over /ip-header + over ip-len! ( dgram offset len pkt )
71 2over 2over ipf-copydata ( dgram offset len pkt )
72 >r ( dgram offset len ) ( r: pkt )
73 over + rot ip-datalen@ <> if ( offset )
74 IP_MF ( offset ipf-flags )
75 else ( offset )
76 0 ( offset ipf-flags )
77 then ( offset ipf-flags )
78 swap 3 rshift or r@ >ip-fraginfo htonw! ( )
79 r> ( pkt ) ( r: )
80;
81
82\ Create and send a single fragment.
83: ipf-send ( dgram fragoff fraglen nexthop -- #sent )
84 >r ip-make-fragment r> over if (ip-output) else 2drop 0 then
85;
86
87\ Transmit datagram, fragmenting it if necessary.
88: ip-send-datagram ( dgram nexthop -- #sent )
89 over ip-len@ if-mtu@ <= if ( dgram nexthop )
90 (ip-output) ( #sent )
91 else ( dgram nexthop )
92 >r ( dgram ) ( r: nexthop )
93 0 begin ( dgram nsent )
94 over ip-datalen@ over - ( dgram nsent rem )
95 ?dup while ( dgram nsent rem )
96 dup /ip-header + if-mtu@ > if ( dgram nsent rem )
97 drop if-mtu@ /ip-header - h# fff8 and ( dgram nsent fragsize )
98 then ( dgram nsent fragsize )
99 3dup r@ ipf-send 0= if ( dgram nsent fragsize )
100 r> 3drop pkt-free 0 exit ( 0 ) ( r: )
101 then ( dgram nsent fragsize )
102 + ( dgram nsent' )
103 repeat ( dgram nsent' )
104 /ip-header + ( dgram #sent )
105 swap pkt-free ( #sent )
106 r> drop ( #sent ) ( r: )
107 then ( #sent )
108;
109
110instance variable ip-sequence
111
112\ Determine next hop, complete the IP header and send the datagram. Most
113\ of the fields in the IP header are initialized by the transport layer
114\ protocol. Only the IP version, header length, datagram identifier and
115\ the checksum are filled in here.
116
117: ip-output ( ippkt -- #sent | error# )
118 dup >ip-dest ipdest>nexthop ?dup 0= if ( pkt )
119 pkt-free EHOSTUNREACH exit ( error# )
120 then swap ( nexthop pkt )
121
122 h# 45 over >ip-ver,hlen c!
123 ip-sequence @ over >ip-id htonw! 1 ip-sequence +!
124 0 over >ip-fraginfo htonw!
125
126 swap ip-send-datagram ( #sent )
127;
128
129headers