Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / netinet / inpcb.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: inpcb.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: @(#)inpcb.fth 1.1 04/09/07
43purpose: Internet protocol control block representation
44copyright: Copyright 2004 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47\ An Internet Protocol Control Block (INPCB) is associated with each
48\ socket. It holds information about local and remote endpoints for
49\ this connection and pointers to the associated socket and protocol
50\ specific control block structures.
51\
52\ TCP maintains state information for a connection in TCP Control
53\ Blocks (TCBs). UDP maintains a queue of datagrams addressed to
54\ the socket in UDP Control Blocks (UCBs).
55\
56\ All INPCBs for a particular protocol are held in doubly linked lists
57\ maintained by that protocol.
58
59headerless
60
61struct
62 /queue-entry field >in-pcblist \ Doubly linked INPCB list
63 /n field >in-socket \ Back pointer to socket
64 /n field >in-ppcb \ Pointer to per-protocol PCB
65 /ip-addr field >in-faddr \ Remote IP, network byte ordered
66 /w field >in-fport \ Remote port, network byte ordered
67 /ip-addr field >in-laddr \ Local IP, network byte ordered
68 /w field >in-lport \ Local port, network byte ordered
69constant /inpcb
70
71: inpcb>so ( inpcb -- sockaddr ) >in-socket @ ;
72
73: in-lport@ ( inpcb -- port ) >in-lport ntohw@ ;
74: in-fport@ ( inpcb -- port ) >in-fport ntohw@ ;
75
76\ Allocate an INPCB for a protocol.
77: inpcb-alloc ( qhead -- inpcb )
78 /inpcb dup alloc-mem tuck swap erase ( qhead inpcb )
79 tuck enqueue ( inpcb )
80;
81
82\ Deallocate an INPCB.
83: inpcb-free ( inpcb -- )
84 dup remqueue ( inpcb )
85 /inpcb free-mem ( )
86;
87
88\ Bind local address and port number to a socket.
89: inpcb-bind ( inpcb laddr lport -- )
90 nip over >in-lport htonw! my-ip-addr swap >in-laddr copy-ip-addr
91;
92
93\ Record remote IP address and port number for a socket.
94: inpcb-connect ( inpcb faddr fport -- )
95 swap dup inaddr-any? if drop inaddr-broadcast then
96 rot tuck >in-faddr copy-ip-addr >in-fport htonw!
97;
98
99\ Disconnect from remote address and port number.
100: inpcb-disconnect ( inpcb -- )
101 0 over >in-fport htonw! inaddr-any swap >in-faddr copy-ip-addr
102;
103
104\ Return local address and port number.
105: in-getsockaddr ( inpcb insock -- )
106 swap dup >in-laddr swap in-lport@ insock-init
107;
108
109\ Return foreign address and port number.
110: in-getpeeraddr ( inpcb insock -- )
111 swap dup >in-faddr swap in-fport@ insock-init
112;
113
114[ifdef] DEBUG
115: .inpcb ( inpcb -- )
116 dup >in-laddr .ipaddr 2 spaces dup in-lport@ .d 2 spaces
117 dup >in-faddr .ipaddr 2 spaces in-fport@ .d cr
118;
119[then]
120
121headers