aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/port.h
diff options
context:
space:
mode:
authorPer Liden <per.liden@nospam.ericsson.com>2006-01-02 13:04:38 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-01-12 17:06:31 -0500
commitb97bf3fd8f6a16966d4f18983b2c40993ff937d4 (patch)
tree59959f8a0f3087455efdcb430846686f303c5991 /net/tipc/port.h
parent58cba4650a7a414eabd2b40cc9d8e45fcdf192d9 (diff)
[TIPC] Initial merge
TIPC (Transparent Inter Process Communication) is a protocol designed for intra cluster communication. For more information see http://tipc.sourceforge.net Signed-off-by: Per Liden <per.liden@nospam.ericsson.com>
Diffstat (limited to 'net/tipc/port.h')
-rw-r--r--net/tipc/port.h206
1 files changed, 206 insertions, 0 deletions
diff --git a/net/tipc/port.h b/net/tipc/port.h
new file mode 100644
index 000000000000..e40235ef92fe
--- /dev/null
+++ b/net/tipc/port.h
@@ -0,0 +1,206 @@
1/*
2 * net/tipc/port.h: Include file for TIPC port code
3 *
4 * Copyright (c) 2003-2005, Ericsson Research Canada
5 * Copyright (c) 2004-2005, Wind River Systems
6 * Copyright (c) 2005-2006, Ericsson AB
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * Redistributions of source code must retain the above copyright notice, this
13 * list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef _TIPC_PORT_H
35#define _TIPC_PORT_H
36
37#include <net/tipc/tipc_port.h>
38#include "ref.h"
39#include "net.h"
40#include "msg.h"
41#include "dbg.h"
42#include "node_subscr.h"
43
44/**
45 * struct user_port - TIPC user port (used with native API)
46 * @user_ref: id of user who created user port
47 * @usr_handle: user-specified field
48 * @ref: object reference to associated TIPC port
49 * <various callback routines>
50 * @uport_list: adjacent user ports in list of ports held by user
51 */
52
53struct user_port {
54 u32 user_ref;
55 void *usr_handle;
56 u32 ref;
57 tipc_msg_err_event err_cb;
58 tipc_named_msg_err_event named_err_cb;
59 tipc_conn_shutdown_event conn_err_cb;
60 tipc_msg_event msg_cb;
61 tipc_named_msg_event named_msg_cb;
62 tipc_conn_msg_event conn_msg_cb;
63 tipc_continue_event continue_event_cb;
64 struct list_head uport_list;
65};
66
67/**
68 * struct port - TIPC port structure
69 * @publ: TIPC port info available to privileged users
70 * @port_list: adjacent ports in TIPC's global list of ports
71 * @dispatcher: ptr to routine which handles received messages
72 * @wakeup: ptr to routine to call when port is no longer congested
73 * @user_port: ptr to user port associated with port (if any)
74 * @wait_list: adjacent ports in list of ports waiting on link congestion
75 * @congested_link: ptr to congested link port is waiting on
76 * @waiting_pkts:
77 * @sent:
78 * @acked:
79 * @publications: list of publications for port
80 * @pub_count: total # of publications port has made during its lifetime
81 * @max_pkt: maximum packet size "hint" used when building messages sent by port
82 * @probing_state:
83 * @probing_interval:
84 * @last_in_seqno:
85 * @timer_ref:
86 * @subscription: "node down" subscription used to terminate failed connections
87 */
88
89struct port {
90 struct tipc_port publ;
91 struct list_head port_list;
92 u32 (*dispatcher)(struct tipc_port *, struct sk_buff *);
93 void (*wakeup)(struct tipc_port *);
94 struct user_port *user_port;
95 struct list_head wait_list;
96 struct link *congested_link;
97 u32 waiting_pkts;
98 u32 sent;
99 u32 acked;
100 struct list_head publications;
101 u32 pub_count;
102 u32 max_pkt;
103 u32 probing_state;
104 u32 probing_interval;
105 u32 last_in_seqno;
106 struct timer_list timer;
107 struct node_subscr subscription;
108};
109
110extern spinlock_t port_list_lock;
111struct port_list;
112
113int port_recv_sections(struct port *p_ptr, u32 num_sect,
114 struct iovec const *msg_sect);
115int port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr,
116 struct iovec const *msg_sect, u32 num_sect,
117 int err);
118struct sk_buff *port_get_ports(void);
119struct sk_buff *port_show_stats(const void *req_tlv_area, int req_tlv_space);
120void port_recv_proto_msg(struct sk_buff *buf);
121void port_recv_mcast(struct sk_buff *buf, struct port_list *dp);
122void port_reinit(void);
123
124/**
125 * port_lock - lock port instance referred to and return its pointer
126 */
127
128static inline struct port *port_lock(u32 ref)
129{
130 return (struct port *)ref_lock(ref);
131}
132
133/**
134 * port_unlock - unlock a port instance
135 *
136 * Can use pointer instead of ref_unlock() since port is already locked.
137 */
138
139static inline void port_unlock(struct port *p_ptr)
140{
141 spin_unlock_bh(p_ptr->publ.lock);
142}
143
144static inline struct port* port_deref(u32 ref)
145{
146 return (struct port *)ref_deref(ref);
147}
148
149static inline u32 peer_port(struct port *p_ptr)
150{
151 return msg_destport(&p_ptr->publ.phdr);
152}
153
154static inline u32 peer_node(struct port *p_ptr)
155{
156 return msg_destnode(&p_ptr->publ.phdr);
157}
158
159static inline int port_congested(struct port *p_ptr)
160{
161 return((p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2));
162}
163
164/**
165 * port_recv_msg - receive message from lower layer and deliver to port user
166 */
167
168static inline int port_recv_msg(struct sk_buff *buf)
169{
170 struct port *p_ptr;
171 struct tipc_msg *msg = buf_msg(buf);
172 u32 destport = msg_destport(msg);
173 u32 dsz = msg_data_sz(msg);
174 u32 err;
175
176 /* forward unresolved named message */
177 if (unlikely(!destport)) {
178 net_route_msg(buf);
179 return dsz;
180 }
181
182 /* validate destination & pass to port, otherwise reject message */
183 p_ptr = port_lock(destport);
184 if (likely(p_ptr)) {
185 if (likely(p_ptr->publ.connected)) {
186 if ((unlikely(msg_origport(msg) != peer_port(p_ptr))) ||
187 (unlikely(msg_orignode(msg) != peer_node(p_ptr))) ||
188 (unlikely(!msg_connected(msg)))) {
189 err = TIPC_ERR_NO_PORT;
190 port_unlock(p_ptr);
191 goto reject;
192 }
193 }
194 err = p_ptr->dispatcher(&p_ptr->publ, buf);
195 port_unlock(p_ptr);
196 if (likely(!err))
197 return dsz;
198 } else {
199 err = TIPC_ERR_NO_PORT;
200 }
201reject:
202 dbg("port->rejecting, err = %x..\n",err);
203 return tipc_reject_msg(buf, err);
204}
205
206#endif