2 * net/tipc/port.h: Include file for TIPC port code
4 * Copyright (c) 2003-2005, Ericsson Research Canada
5 * Copyright (c) 2004-2005, Wind River Systems
6 * Copyright (c) 2005-2006, Ericsson AB
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
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.
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.
37 #include <net/tipc/tipc_port.h>
42 #include "node_subscr.h"
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
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;
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
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
86 * @subscription: "node down" subscription used to terminate failed connections
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;
100 struct list_head publications;
104 u32 probing_interval;
106 struct timer_list timer;
107 struct node_subscr subscription;
110 extern spinlock_t port_list_lock;
113 int port_recv_sections(struct port *p_ptr, u32 num_sect,
114 struct iovec const *msg_sect);
115 int port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr,
116 struct iovec const *msg_sect, u32 num_sect,
118 struct sk_buff *port_get_ports(void);
119 struct sk_buff *port_show_stats(const void *req_tlv_area, int req_tlv_space);
120 void port_recv_proto_msg(struct sk_buff *buf);
121 void port_recv_mcast(struct sk_buff *buf, struct port_list *dp);
122 void port_reinit(void);
125 * port_lock - lock port instance referred to and return its pointer
128 static inline struct port *port_lock(u32 ref)
130 return (struct port *)ref_lock(ref);
134 * port_unlock - unlock a port instance
136 * Can use pointer instead of ref_unlock() since port is already locked.
139 static inline void port_unlock(struct port *p_ptr)
141 spin_unlock_bh(p_ptr->publ.lock);
144 static inline struct port* port_deref(u32 ref)
146 return (struct port *)ref_deref(ref);
149 static inline u32 peer_port(struct port *p_ptr)
151 return msg_destport(&p_ptr->publ.phdr);
154 static inline u32 peer_node(struct port *p_ptr)
156 return msg_destnode(&p_ptr->publ.phdr);
159 static inline int port_congested(struct port *p_ptr)
161 return((p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2));
165 * port_recv_msg - receive message from lower layer and deliver to port user
168 static inline int port_recv_msg(struct sk_buff *buf)
171 struct tipc_msg *msg = buf_msg(buf);
172 u32 destport = msg_destport(msg);
173 u32 dsz = msg_data_sz(msg);
176 /* forward unresolved named message */
177 if (unlikely(!destport)) {
182 /* validate destination & pass to port, otherwise reject message */
183 p_ptr = port_lock(destport);
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;
194 err = p_ptr->dispatcher(&p_ptr->publ, buf);
199 err = TIPC_ERR_NO_PORT;
202 dbg("port->rejecting, err = %x..\n",err);
203 return tipc_reject_msg(buf, err);