diff options
Diffstat (limited to 'net/tipc/port.c')
-rw-r--r-- | net/tipc/port.c | 764 |
1 files changed, 207 insertions, 557 deletions
diff --git a/net/tipc/port.c b/net/tipc/port.c index 0737680e9266..c68dc956a423 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * net/tipc/port.c: TIPC port code | 2 | * net/tipc/port.c: TIPC port code |
3 | * | 3 | * |
4 | * Copyright (c) 1992-2007, Ericsson AB | 4 | * Copyright (c) 1992-2007, Ericsson AB |
5 | * Copyright (c) 2004-2008, Wind River Systems | 5 | * Copyright (c) 2004-2008, 2010-2011, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
@@ -36,15 +36,8 @@ | |||
36 | 36 | ||
37 | #include "core.h" | 37 | #include "core.h" |
38 | #include "config.h" | 38 | #include "config.h" |
39 | #include "dbg.h" | ||
40 | #include "port.h" | 39 | #include "port.h" |
41 | #include "addr.h" | ||
42 | #include "link.h" | ||
43 | #include "node.h" | ||
44 | #include "name_table.h" | 40 | #include "name_table.h" |
45 | #include "user_reg.h" | ||
46 | #include "msg.h" | ||
47 | #include "bcast.h" | ||
48 | 41 | ||
49 | /* Connection management: */ | 42 | /* Connection management: */ |
50 | #define PROBING_INTERVAL 3600000 /* [ms] => 1 h */ | 43 | #define PROBING_INTERVAL 3600000 /* [ms] => 1 h */ |
@@ -53,55 +46,42 @@ | |||
53 | 46 | ||
54 | #define MAX_REJECT_SIZE 1024 | 47 | #define MAX_REJECT_SIZE 1024 |
55 | 48 | ||
56 | static struct sk_buff *msg_queue_head = NULL; | 49 | static struct sk_buff *msg_queue_head; |
57 | static struct sk_buff *msg_queue_tail = NULL; | 50 | static struct sk_buff *msg_queue_tail; |
58 | 51 | ||
59 | DEFINE_SPINLOCK(tipc_port_list_lock); | 52 | DEFINE_SPINLOCK(tipc_port_list_lock); |
60 | static DEFINE_SPINLOCK(queue_lock); | 53 | static DEFINE_SPINLOCK(queue_lock); |
61 | 54 | ||
62 | static LIST_HEAD(ports); | 55 | static LIST_HEAD(ports); |
63 | static void port_handle_node_down(unsigned long ref); | 56 | static void port_handle_node_down(unsigned long ref); |
64 | static struct sk_buff* port_build_self_abort_msg(struct port *,u32 err); | 57 | static struct sk_buff *port_build_self_abort_msg(struct tipc_port *, u32 err); |
65 | static struct sk_buff* port_build_peer_abort_msg(struct port *,u32 err); | 58 | static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *, u32 err); |
66 | static void port_timeout(unsigned long ref); | 59 | static void port_timeout(unsigned long ref); |
67 | 60 | ||
68 | 61 | ||
69 | static u32 port_peernode(struct port *p_ptr) | 62 | static u32 port_peernode(struct tipc_port *p_ptr) |
70 | { | 63 | { |
71 | return msg_destnode(&p_ptr->publ.phdr); | 64 | return msg_destnode(&p_ptr->phdr); |
72 | } | 65 | } |
73 | 66 | ||
74 | static u32 port_peerport(struct port *p_ptr) | 67 | static u32 port_peerport(struct tipc_port *p_ptr) |
75 | { | 68 | { |
76 | return msg_destport(&p_ptr->publ.phdr); | 69 | return msg_destport(&p_ptr->phdr); |
77 | } | ||
78 | |||
79 | static u32 port_out_seqno(struct port *p_ptr) | ||
80 | { | ||
81 | return msg_transp_seqno(&p_ptr->publ.phdr); | ||
82 | } | ||
83 | |||
84 | static void port_incr_out_seqno(struct port *p_ptr) | ||
85 | { | ||
86 | struct tipc_msg *m = &p_ptr->publ.phdr; | ||
87 | |||
88 | if (likely(!msg_routed(m))) | ||
89 | return; | ||
90 | msg_set_transp_seqno(m, (msg_transp_seqno(m) + 1)); | ||
91 | } | 70 | } |
92 | 71 | ||
93 | /** | 72 | /** |
94 | * tipc_multicast - send a multicast message to local and remote destinations | 73 | * tipc_multicast - send a multicast message to local and remote destinations |
95 | */ | 74 | */ |
96 | 75 | ||
97 | int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain, | 76 | int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, |
98 | u32 num_sect, struct iovec const *msg_sect) | 77 | u32 num_sect, struct iovec const *msg_sect, |
78 | unsigned int total_len) | ||
99 | { | 79 | { |
100 | struct tipc_msg *hdr; | 80 | struct tipc_msg *hdr; |
101 | struct sk_buff *buf; | 81 | struct sk_buff *buf; |
102 | struct sk_buff *ibuf = NULL; | 82 | struct sk_buff *ibuf = NULL; |
103 | struct port_list dports = {0, NULL, }; | 83 | struct port_list dports = {0, NULL, }; |
104 | struct port *oport = tipc_port_deref(ref); | 84 | struct tipc_port *oport = tipc_port_deref(ref); |
105 | int ext_targets; | 85 | int ext_targets; |
106 | int res; | 86 | int res; |
107 | 87 | ||
@@ -110,13 +90,16 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain, | |||
110 | 90 | ||
111 | /* Create multicast message */ | 91 | /* Create multicast message */ |
112 | 92 | ||
113 | hdr = &oport->publ.phdr; | 93 | hdr = &oport->phdr; |
114 | msg_set_type(hdr, TIPC_MCAST_MSG); | 94 | msg_set_type(hdr, TIPC_MCAST_MSG); |
95 | msg_set_lookup_scope(hdr, TIPC_CLUSTER_SCOPE); | ||
96 | msg_set_destport(hdr, 0); | ||
97 | msg_set_destnode(hdr, 0); | ||
115 | msg_set_nametype(hdr, seq->type); | 98 | msg_set_nametype(hdr, seq->type); |
116 | msg_set_namelower(hdr, seq->lower); | 99 | msg_set_namelower(hdr, seq->lower); |
117 | msg_set_nameupper(hdr, seq->upper); | 100 | msg_set_nameupper(hdr, seq->upper); |
118 | msg_set_hdr_sz(hdr, MCAST_H_SIZE); | 101 | msg_set_hdr_sz(hdr, MCAST_H_SIZE); |
119 | res = tipc_msg_build(hdr, msg_sect, num_sect, MAX_MSG_SIZE, | 102 | res = tipc_msg_build(hdr, msg_sect, num_sect, total_len, MAX_MSG_SIZE, |
120 | !oport->user_port, &buf); | 103 | !oport->user_port, &buf); |
121 | if (unlikely(!buf)) | 104 | if (unlikely(!buf)) |
122 | return res; | 105 | return res; |
@@ -138,9 +121,8 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain, | |||
138 | } | 121 | } |
139 | } | 122 | } |
140 | res = tipc_bclink_send_msg(buf); | 123 | res = tipc_bclink_send_msg(buf); |
141 | if ((res < 0) && (dports.count != 0)) { | 124 | if ((res < 0) && (dports.count != 0)) |
142 | buf_discard(ibuf); | 125 | buf_discard(ibuf); |
143 | } | ||
144 | } else { | 126 | } else { |
145 | ibuf = buf; | 127 | ibuf = buf; |
146 | } | 128 | } |
@@ -162,7 +144,7 @@ int tipc_multicast(u32 ref, struct tipc_name_seq const *seq, u32 domain, | |||
162 | 144 | ||
163 | void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp) | 145 | void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp) |
164 | { | 146 | { |
165 | struct tipc_msg* msg; | 147 | struct tipc_msg *msg; |
166 | struct port_list dports = {0, NULL, }; | 148 | struct port_list dports = {0, NULL, }; |
167 | struct port_list *item = dp; | 149 | struct port_list *item = dp; |
168 | int cnt = 0; | 150 | int cnt = 0; |
@@ -183,6 +165,7 @@ void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp) | |||
183 | /* Deliver a copy of message to each destination port */ | 165 | /* Deliver a copy of message to each destination port */ |
184 | 166 | ||
185 | if (dp->count != 0) { | 167 | if (dp->count != 0) { |
168 | msg_set_destnode(msg, tipc_own_addr); | ||
186 | if (dp->count == 1) { | 169 | if (dp->count == 1) { |
187 | msg_set_destport(msg, dp->ports[0]); | 170 | msg_set_destport(msg, dp->ports[0]); |
188 | tipc_port_recv_msg(buf); | 171 | tipc_port_recv_msg(buf); |
@@ -195,13 +178,11 @@ void tipc_port_recv_mcast(struct sk_buff *buf, struct port_list *dp) | |||
195 | 178 | ||
196 | if (b == NULL) { | 179 | if (b == NULL) { |
197 | warn("Unable to deliver multicast message(s)\n"); | 180 | warn("Unable to deliver multicast message(s)\n"); |
198 | msg_dbg(msg, "LOST:"); | ||
199 | goto exit; | 181 | goto exit; |
200 | } | 182 | } |
201 | if ((index == 0) && (cnt != 0)) { | 183 | if ((index == 0) && (cnt != 0)) |
202 | item = item->next; | 184 | item = item->next; |
203 | } | 185 | msg_set_destport(buf_msg(b), item->ports[index]); |
204 | msg_set_destport(buf_msg(b),item->ports[index]); | ||
205 | tipc_port_recv_msg(b); | 186 | tipc_port_recv_msg(b); |
206 | } | 187 | } |
207 | } | 188 | } |
@@ -221,7 +202,7 @@ struct tipc_port *tipc_createport_raw(void *usr_handle, | |||
221 | void (*wakeup)(struct tipc_port *), | 202 | void (*wakeup)(struct tipc_port *), |
222 | const u32 importance) | 203 | const u32 importance) |
223 | { | 204 | { |
224 | struct port *p_ptr; | 205 | struct tipc_port *p_ptr; |
225 | struct tipc_msg *msg; | 206 | struct tipc_msg *msg; |
226 | u32 ref; | 207 | u32 ref; |
227 | 208 | ||
@@ -230,21 +211,19 @@ struct tipc_port *tipc_createport_raw(void *usr_handle, | |||
230 | warn("Port creation failed, no memory\n"); | 211 | warn("Port creation failed, no memory\n"); |
231 | return NULL; | 212 | return NULL; |
232 | } | 213 | } |
233 | ref = tipc_ref_acquire(p_ptr, &p_ptr->publ.lock); | 214 | ref = tipc_ref_acquire(p_ptr, &p_ptr->lock); |
234 | if (!ref) { | 215 | if (!ref) { |
235 | warn("Port creation failed, reference table exhausted\n"); | 216 | warn("Port creation failed, reference table exhausted\n"); |
236 | kfree(p_ptr); | 217 | kfree(p_ptr); |
237 | return NULL; | 218 | return NULL; |
238 | } | 219 | } |
239 | 220 | ||
240 | p_ptr->publ.usr_handle = usr_handle; | 221 | p_ptr->usr_handle = usr_handle; |
241 | p_ptr->publ.max_pkt = MAX_PKT_DEFAULT; | 222 | p_ptr->max_pkt = MAX_PKT_DEFAULT; |
242 | p_ptr->publ.ref = ref; | 223 | p_ptr->ref = ref; |
243 | msg = &p_ptr->publ.phdr; | 224 | msg = &p_ptr->phdr; |
244 | tipc_msg_init(msg, importance, TIPC_NAMED_MSG, LONG_H_SIZE, 0); | 225 | tipc_msg_init(msg, importance, TIPC_NAMED_MSG, LONG_H_SIZE, 0); |
245 | msg_set_origport(msg, ref); | 226 | msg_set_origport(msg, ref); |
246 | p_ptr->last_in_seqno = 41; | ||
247 | p_ptr->sent = 1; | ||
248 | INIT_LIST_HEAD(&p_ptr->wait_list); | 227 | INIT_LIST_HEAD(&p_ptr->wait_list); |
249 | INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); | 228 | INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); |
250 | p_ptr->dispatcher = dispatcher; | 229 | p_ptr->dispatcher = dispatcher; |
@@ -256,12 +235,12 @@ struct tipc_port *tipc_createport_raw(void *usr_handle, | |||
256 | INIT_LIST_HEAD(&p_ptr->port_list); | 235 | INIT_LIST_HEAD(&p_ptr->port_list); |
257 | list_add_tail(&p_ptr->port_list, &ports); | 236 | list_add_tail(&p_ptr->port_list, &ports); |
258 | spin_unlock_bh(&tipc_port_list_lock); | 237 | spin_unlock_bh(&tipc_port_list_lock); |
259 | return &(p_ptr->publ); | 238 | return p_ptr; |
260 | } | 239 | } |
261 | 240 | ||
262 | int tipc_deleteport(u32 ref) | 241 | int tipc_deleteport(u32 ref) |
263 | { | 242 | { |
264 | struct port *p_ptr; | 243 | struct tipc_port *p_ptr; |
265 | struct sk_buff *buf = NULL; | 244 | struct sk_buff *buf = NULL; |
266 | 245 | ||
267 | tipc_withdraw(ref, 0, NULL); | 246 | tipc_withdraw(ref, 0, NULL); |
@@ -273,14 +252,11 @@ int tipc_deleteport(u32 ref) | |||
273 | tipc_port_unlock(p_ptr); | 252 | tipc_port_unlock(p_ptr); |
274 | 253 | ||
275 | k_cancel_timer(&p_ptr->timer); | 254 | k_cancel_timer(&p_ptr->timer); |
276 | if (p_ptr->publ.connected) { | 255 | if (p_ptr->connected) { |
277 | buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT); | 256 | buf = port_build_peer_abort_msg(p_ptr, TIPC_ERR_NO_PORT); |
278 | tipc_nodesub_unsubscribe(&p_ptr->subscription); | 257 | tipc_nodesub_unsubscribe(&p_ptr->subscription); |
279 | } | 258 | } |
280 | if (p_ptr->user_port) { | 259 | kfree(p_ptr->user_port); |
281 | tipc_reg_remove_port(p_ptr->user_port); | ||
282 | kfree(p_ptr->user_port); | ||
283 | } | ||
284 | 260 | ||
285 | spin_lock_bh(&tipc_port_list_lock); | 261 | spin_lock_bh(&tipc_port_list_lock); |
286 | list_del(&p_ptr->port_list); | 262 | list_del(&p_ptr->port_list); |
@@ -288,47 +264,18 @@ int tipc_deleteport(u32 ref) | |||
288 | spin_unlock_bh(&tipc_port_list_lock); | 264 | spin_unlock_bh(&tipc_port_list_lock); |
289 | k_term_timer(&p_ptr->timer); | 265 | k_term_timer(&p_ptr->timer); |
290 | kfree(p_ptr); | 266 | kfree(p_ptr); |
291 | dbg("Deleted port %u\n", ref); | ||
292 | tipc_net_route_msg(buf); | 267 | tipc_net_route_msg(buf); |
293 | return 0; | 268 | return 0; |
294 | } | 269 | } |
295 | 270 | ||
296 | /** | 271 | static int port_unreliable(struct tipc_port *p_ptr) |
297 | * tipc_get_port() - return port associated with 'ref' | ||
298 | * | ||
299 | * Note: Port is not locked. | ||
300 | */ | ||
301 | |||
302 | struct tipc_port *tipc_get_port(const u32 ref) | ||
303 | { | 272 | { |
304 | return (struct tipc_port *)tipc_ref_deref(ref); | 273 | return msg_src_droppable(&p_ptr->phdr); |
305 | } | ||
306 | |||
307 | /** | ||
308 | * tipc_get_handle - return user handle associated to port 'ref' | ||
309 | */ | ||
310 | |||
311 | void *tipc_get_handle(const u32 ref) | ||
312 | { | ||
313 | struct port *p_ptr; | ||
314 | void * handle; | ||
315 | |||
316 | p_ptr = tipc_port_lock(ref); | ||
317 | if (!p_ptr) | ||
318 | return NULL; | ||
319 | handle = p_ptr->publ.usr_handle; | ||
320 | tipc_port_unlock(p_ptr); | ||
321 | return handle; | ||
322 | } | ||
323 | |||
324 | static int port_unreliable(struct port *p_ptr) | ||
325 | { | ||
326 | return msg_src_droppable(&p_ptr->publ.phdr); | ||
327 | } | 274 | } |
328 | 275 | ||
329 | int tipc_portunreliable(u32 ref, unsigned int *isunreliable) | 276 | int tipc_portunreliable(u32 ref, unsigned int *isunreliable) |
330 | { | 277 | { |
331 | struct port *p_ptr; | 278 | struct tipc_port *p_ptr; |
332 | 279 | ||
333 | p_ptr = tipc_port_lock(ref); | 280 | p_ptr = tipc_port_lock(ref); |
334 | if (!p_ptr) | 281 | if (!p_ptr) |
@@ -340,24 +287,24 @@ int tipc_portunreliable(u32 ref, unsigned int *isunreliable) | |||
340 | 287 | ||
341 | int tipc_set_portunreliable(u32 ref, unsigned int isunreliable) | 288 | int tipc_set_portunreliable(u32 ref, unsigned int isunreliable) |
342 | { | 289 | { |
343 | struct port *p_ptr; | 290 | struct tipc_port *p_ptr; |
344 | 291 | ||
345 | p_ptr = tipc_port_lock(ref); | 292 | p_ptr = tipc_port_lock(ref); |
346 | if (!p_ptr) | 293 | if (!p_ptr) |
347 | return -EINVAL; | 294 | return -EINVAL; |
348 | msg_set_src_droppable(&p_ptr->publ.phdr, (isunreliable != 0)); | 295 | msg_set_src_droppable(&p_ptr->phdr, (isunreliable != 0)); |
349 | tipc_port_unlock(p_ptr); | 296 | tipc_port_unlock(p_ptr); |
350 | return 0; | 297 | return 0; |
351 | } | 298 | } |
352 | 299 | ||
353 | static int port_unreturnable(struct port *p_ptr) | 300 | static int port_unreturnable(struct tipc_port *p_ptr) |
354 | { | 301 | { |
355 | return msg_dest_droppable(&p_ptr->publ.phdr); | 302 | return msg_dest_droppable(&p_ptr->phdr); |
356 | } | 303 | } |
357 | 304 | ||
358 | int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable) | 305 | int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable) |
359 | { | 306 | { |
360 | struct port *p_ptr; | 307 | struct tipc_port *p_ptr; |
361 | 308 | ||
362 | p_ptr = tipc_port_lock(ref); | 309 | p_ptr = tipc_port_lock(ref); |
363 | if (!p_ptr) | 310 | if (!p_ptr) |
@@ -369,12 +316,12 @@ int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable) | |||
369 | 316 | ||
370 | int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable) | 317 | int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable) |
371 | { | 318 | { |
372 | struct port *p_ptr; | 319 | struct tipc_port *p_ptr; |
373 | 320 | ||
374 | p_ptr = tipc_port_lock(ref); | 321 | p_ptr = tipc_port_lock(ref); |
375 | if (!p_ptr) | 322 | if (!p_ptr) |
376 | return -EINVAL; | 323 | return -EINVAL; |
377 | msg_set_dest_droppable(&p_ptr->publ.phdr, (isunrejectable != 0)); | 324 | msg_set_dest_droppable(&p_ptr->phdr, (isunrejectable != 0)); |
378 | tipc_port_unlock(p_ptr); | 325 | tipc_port_unlock(p_ptr); |
379 | return 0; | 326 | return 0; |
380 | } | 327 | } |
@@ -387,12 +334,12 @@ int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable) | |||
387 | static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode, | 334 | static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode, |
388 | u32 origport, u32 orignode, | 335 | u32 origport, u32 orignode, |
389 | u32 usr, u32 type, u32 err, | 336 | u32 usr, u32 type, u32 err, |
390 | u32 seqno, u32 ack) | 337 | u32 ack) |
391 | { | 338 | { |
392 | struct sk_buff *buf; | 339 | struct sk_buff *buf; |
393 | struct tipc_msg *msg; | 340 | struct tipc_msg *msg; |
394 | 341 | ||
395 | buf = buf_acquire(LONG_H_SIZE); | 342 | buf = tipc_buf_acquire(LONG_H_SIZE); |
396 | if (buf) { | 343 | if (buf) { |
397 | msg = buf_msg(buf); | 344 | msg = buf_msg(buf); |
398 | tipc_msg_init(msg, usr, type, LONG_H_SIZE, destnode); | 345 | tipc_msg_init(msg, usr, type, LONG_H_SIZE, destnode); |
@@ -400,9 +347,7 @@ static struct sk_buff *port_build_proto_msg(u32 destport, u32 destnode, | |||
400 | msg_set_destport(msg, destport); | 347 | msg_set_destport(msg, destport); |
401 | msg_set_origport(msg, origport); | 348 | msg_set_origport(msg, origport); |
402 | msg_set_orignode(msg, orignode); | 349 | msg_set_orignode(msg, orignode); |
403 | msg_set_transp_seqno(msg, seqno); | ||
404 | msg_set_msgcnt(msg, ack); | 350 | msg_set_msgcnt(msg, ack); |
405 | msg_dbg(msg, "PORT>SEND>:"); | ||
406 | } | 351 | } |
407 | return buf; | 352 | return buf; |
408 | } | 353 | } |
@@ -420,7 +365,6 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) | |||
420 | data_sz = MAX_REJECT_SIZE; | 365 | data_sz = MAX_REJECT_SIZE; |
421 | if (msg_connected(msg) && (imp < TIPC_CRITICAL_IMPORTANCE)) | 366 | if (msg_connected(msg) && (imp < TIPC_CRITICAL_IMPORTANCE)) |
422 | imp++; | 367 | imp++; |
423 | msg_dbg(msg, "port->rej: "); | ||
424 | 368 | ||
425 | /* discard rejected message if it shouldn't be returned to sender */ | 369 | /* discard rejected message if it shouldn't be returned to sender */ |
426 | if (msg_errcode(msg) || msg_dest_droppable(msg)) { | 370 | if (msg_errcode(msg) || msg_dest_droppable(msg)) { |
@@ -433,7 +377,7 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) | |||
433 | hdr_sz = MCAST_H_SIZE; | 377 | hdr_sz = MCAST_H_SIZE; |
434 | else | 378 | else |
435 | hdr_sz = LONG_H_SIZE; | 379 | hdr_sz = LONG_H_SIZE; |
436 | rbuf = buf_acquire(data_sz + hdr_sz); | 380 | rbuf = tipc_buf_acquire(data_sz + hdr_sz); |
437 | if (rbuf == NULL) { | 381 | if (rbuf == NULL) { |
438 | buf_discard(buf); | 382 | buf_discard(buf); |
439 | return data_sz; | 383 | return data_sz; |
@@ -457,10 +401,10 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) | |||
457 | /* send self-abort message when rejecting on a connected port */ | 401 | /* send self-abort message when rejecting on a connected port */ |
458 | if (msg_connected(msg)) { | 402 | if (msg_connected(msg)) { |
459 | struct sk_buff *abuf = NULL; | 403 | struct sk_buff *abuf = NULL; |
460 | struct port *p_ptr = tipc_port_lock(msg_destport(msg)); | 404 | struct tipc_port *p_ptr = tipc_port_lock(msg_destport(msg)); |
461 | 405 | ||
462 | if (p_ptr) { | 406 | if (p_ptr) { |
463 | if (p_ptr->publ.connected) | 407 | if (p_ptr->connected) |
464 | abuf = port_build_self_abort_msg(p_ptr, err); | 408 | abuf = port_build_self_abort_msg(p_ptr, err); |
465 | tipc_port_unlock(p_ptr); | 409 | tipc_port_unlock(p_ptr); |
466 | } | 410 | } |
@@ -473,14 +417,14 @@ int tipc_reject_msg(struct sk_buff *buf, u32 err) | |||
473 | return data_sz; | 417 | return data_sz; |
474 | } | 418 | } |
475 | 419 | ||
476 | int tipc_port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr, | 420 | int tipc_port_reject_sections(struct tipc_port *p_ptr, struct tipc_msg *hdr, |
477 | struct iovec const *msg_sect, u32 num_sect, | 421 | struct iovec const *msg_sect, u32 num_sect, |
478 | int err) | 422 | unsigned int total_len, int err) |
479 | { | 423 | { |
480 | struct sk_buff *buf; | 424 | struct sk_buff *buf; |
481 | int res; | 425 | int res; |
482 | 426 | ||
483 | res = tipc_msg_build(hdr, msg_sect, num_sect, MAX_MSG_SIZE, | 427 | res = tipc_msg_build(hdr, msg_sect, num_sect, total_len, MAX_MSG_SIZE, |
484 | !p_ptr->user_port, &buf); | 428 | !p_ptr->user_port, &buf); |
485 | if (!buf) | 429 | if (!buf) |
486 | return res; | 430 | return res; |
@@ -490,13 +434,13 @@ int tipc_port_reject_sections(struct port *p_ptr, struct tipc_msg *hdr, | |||
490 | 434 | ||
491 | static void port_timeout(unsigned long ref) | 435 | static void port_timeout(unsigned long ref) |
492 | { | 436 | { |
493 | struct port *p_ptr = tipc_port_lock(ref); | 437 | struct tipc_port *p_ptr = tipc_port_lock(ref); |
494 | struct sk_buff *buf = NULL; | 438 | struct sk_buff *buf = NULL; |
495 | 439 | ||
496 | if (!p_ptr) | 440 | if (!p_ptr) |
497 | return; | 441 | return; |
498 | 442 | ||
499 | if (!p_ptr->publ.connected) { | 443 | if (!p_ptr->connected) { |
500 | tipc_port_unlock(p_ptr); | 444 | tipc_port_unlock(p_ptr); |
501 | return; | 445 | return; |
502 | } | 446 | } |
@@ -507,14 +451,12 @@ static void port_timeout(unsigned long ref) | |||
507 | } else { | 451 | } else { |
508 | buf = port_build_proto_msg(port_peerport(p_ptr), | 452 | buf = port_build_proto_msg(port_peerport(p_ptr), |
509 | port_peernode(p_ptr), | 453 | port_peernode(p_ptr), |
510 | p_ptr->publ.ref, | 454 | p_ptr->ref, |
511 | tipc_own_addr, | 455 | tipc_own_addr, |
512 | CONN_MANAGER, | 456 | CONN_MANAGER, |
513 | CONN_PROBE, | 457 | CONN_PROBE, |
514 | TIPC_OK, | 458 | TIPC_OK, |
515 | port_out_seqno(p_ptr), | ||
516 | 0); | 459 | 0); |
517 | port_incr_out_seqno(p_ptr); | ||
518 | p_ptr->probing_state = PROBING; | 460 | p_ptr->probing_state = PROBING; |
519 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); | 461 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); |
520 | } | 462 | } |
@@ -525,8 +467,8 @@ static void port_timeout(unsigned long ref) | |||
525 | 467 | ||
526 | static void port_handle_node_down(unsigned long ref) | 468 | static void port_handle_node_down(unsigned long ref) |
527 | { | 469 | { |
528 | struct port *p_ptr = tipc_port_lock(ref); | 470 | struct tipc_port *p_ptr = tipc_port_lock(ref); |
529 | struct sk_buff* buf = NULL; | 471 | struct sk_buff *buf = NULL; |
530 | 472 | ||
531 | if (!p_ptr) | 473 | if (!p_ptr) |
532 | return; | 474 | return; |
@@ -536,84 +478,71 @@ static void port_handle_node_down(unsigned long ref) | |||
536 | } | 478 | } |
537 | 479 | ||
538 | 480 | ||
539 | static struct sk_buff *port_build_self_abort_msg(struct port *p_ptr, u32 err) | 481 | static struct sk_buff *port_build_self_abort_msg(struct tipc_port *p_ptr, u32 err) |
540 | { | 482 | { |
541 | u32 imp = msg_importance(&p_ptr->publ.phdr); | 483 | u32 imp = msg_importance(&p_ptr->phdr); |
542 | 484 | ||
543 | if (!p_ptr->publ.connected) | 485 | if (!p_ptr->connected) |
544 | return NULL; | 486 | return NULL; |
545 | if (imp < TIPC_CRITICAL_IMPORTANCE) | 487 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
546 | imp++; | 488 | imp++; |
547 | return port_build_proto_msg(p_ptr->publ.ref, | 489 | return port_build_proto_msg(p_ptr->ref, |
548 | tipc_own_addr, | 490 | tipc_own_addr, |
549 | port_peerport(p_ptr), | 491 | port_peerport(p_ptr), |
550 | port_peernode(p_ptr), | 492 | port_peernode(p_ptr), |
551 | imp, | 493 | imp, |
552 | TIPC_CONN_MSG, | 494 | TIPC_CONN_MSG, |
553 | err, | 495 | err, |
554 | p_ptr->last_in_seqno + 1, | ||
555 | 0); | 496 | 0); |
556 | } | 497 | } |
557 | 498 | ||
558 | 499 | ||
559 | static struct sk_buff *port_build_peer_abort_msg(struct port *p_ptr, u32 err) | 500 | static struct sk_buff *port_build_peer_abort_msg(struct tipc_port *p_ptr, u32 err) |
560 | { | 501 | { |
561 | u32 imp = msg_importance(&p_ptr->publ.phdr); | 502 | u32 imp = msg_importance(&p_ptr->phdr); |
562 | 503 | ||
563 | if (!p_ptr->publ.connected) | 504 | if (!p_ptr->connected) |
564 | return NULL; | 505 | return NULL; |
565 | if (imp < TIPC_CRITICAL_IMPORTANCE) | 506 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
566 | imp++; | 507 | imp++; |
567 | return port_build_proto_msg(port_peerport(p_ptr), | 508 | return port_build_proto_msg(port_peerport(p_ptr), |
568 | port_peernode(p_ptr), | 509 | port_peernode(p_ptr), |
569 | p_ptr->publ.ref, | 510 | p_ptr->ref, |
570 | tipc_own_addr, | 511 | tipc_own_addr, |
571 | imp, | 512 | imp, |
572 | TIPC_CONN_MSG, | 513 | TIPC_CONN_MSG, |
573 | err, | 514 | err, |
574 | port_out_seqno(p_ptr), | ||
575 | 0); | 515 | 0); |
576 | } | 516 | } |
577 | 517 | ||
578 | void tipc_port_recv_proto_msg(struct sk_buff *buf) | 518 | void tipc_port_recv_proto_msg(struct sk_buff *buf) |
579 | { | 519 | { |
580 | struct tipc_msg *msg = buf_msg(buf); | 520 | struct tipc_msg *msg = buf_msg(buf); |
581 | struct port *p_ptr = tipc_port_lock(msg_destport(msg)); | 521 | struct tipc_port *p_ptr = tipc_port_lock(msg_destport(msg)); |
582 | u32 err = TIPC_OK; | 522 | u32 err = TIPC_OK; |
583 | struct sk_buff *r_buf = NULL; | 523 | struct sk_buff *r_buf = NULL; |
584 | struct sk_buff *abort_buf = NULL; | 524 | struct sk_buff *abort_buf = NULL; |
585 | 525 | ||
586 | msg_dbg(msg, "PORT<RECV<:"); | ||
587 | |||
588 | if (!p_ptr) { | 526 | if (!p_ptr) { |
589 | err = TIPC_ERR_NO_PORT; | 527 | err = TIPC_ERR_NO_PORT; |
590 | } else if (p_ptr->publ.connected) { | 528 | } else if (p_ptr->connected) { |
591 | if (port_peernode(p_ptr) != msg_orignode(msg)) | 529 | if ((port_peernode(p_ptr) != msg_orignode(msg)) || |
592 | err = TIPC_ERR_NO_PORT; | 530 | (port_peerport(p_ptr) != msg_origport(msg))) { |
593 | if (port_peerport(p_ptr) != msg_origport(msg)) | ||
594 | err = TIPC_ERR_NO_PORT; | 531 | err = TIPC_ERR_NO_PORT; |
595 | if (!err && msg_routed(msg)) { | 532 | } else if (msg_type(msg) == CONN_ACK) { |
596 | u32 seqno = msg_transp_seqno(msg); | ||
597 | u32 myno = ++p_ptr->last_in_seqno; | ||
598 | if (seqno != myno) { | ||
599 | err = TIPC_ERR_NO_PORT; | ||
600 | abort_buf = port_build_self_abort_msg(p_ptr, err); | ||
601 | } | ||
602 | } | ||
603 | if (msg_type(msg) == CONN_ACK) { | ||
604 | int wakeup = tipc_port_congested(p_ptr) && | 533 | int wakeup = tipc_port_congested(p_ptr) && |
605 | p_ptr->publ.congested && | 534 | p_ptr->congested && |
606 | p_ptr->wakeup; | 535 | p_ptr->wakeup; |
607 | p_ptr->acked += msg_msgcnt(msg); | 536 | p_ptr->acked += msg_msgcnt(msg); |
608 | if (tipc_port_congested(p_ptr)) | 537 | if (tipc_port_congested(p_ptr)) |
609 | goto exit; | 538 | goto exit; |
610 | p_ptr->publ.congested = 0; | 539 | p_ptr->congested = 0; |
611 | if (!wakeup) | 540 | if (!wakeup) |
612 | goto exit; | 541 | goto exit; |
613 | p_ptr->wakeup(&p_ptr->publ); | 542 | p_ptr->wakeup(p_ptr); |
614 | goto exit; | 543 | goto exit; |
615 | } | 544 | } |
616 | } else if (p_ptr->publ.published) { | 545 | } else if (p_ptr->published) { |
617 | err = TIPC_ERR_NO_PORT; | 546 | err = TIPC_ERR_NO_PORT; |
618 | } | 547 | } |
619 | if (err) { | 548 | if (err) { |
@@ -624,7 +553,6 @@ void tipc_port_recv_proto_msg(struct sk_buff *buf) | |||
624 | TIPC_HIGH_IMPORTANCE, | 553 | TIPC_HIGH_IMPORTANCE, |
625 | TIPC_CONN_MSG, | 554 | TIPC_CONN_MSG, |
626 | err, | 555 | err, |
627 | 0, | ||
628 | 0); | 556 | 0); |
629 | goto exit; | 557 | goto exit; |
630 | } | 558 | } |
@@ -638,11 +566,9 @@ void tipc_port_recv_proto_msg(struct sk_buff *buf) | |||
638 | CONN_MANAGER, | 566 | CONN_MANAGER, |
639 | CONN_PROBE_REPLY, | 567 | CONN_PROBE_REPLY, |
640 | TIPC_OK, | 568 | TIPC_OK, |
641 | port_out_seqno(p_ptr), | ||
642 | 0); | 569 | 0); |
643 | } | 570 | } |
644 | p_ptr->probing_state = CONFIRMED; | 571 | p_ptr->probing_state = CONFIRMED; |
645 | port_incr_out_seqno(p_ptr); | ||
646 | exit: | 572 | exit: |
647 | if (p_ptr) | 573 | if (p_ptr) |
648 | tipc_port_unlock(p_ptr); | 574 | tipc_port_unlock(p_ptr); |
@@ -651,30 +577,29 @@ exit: | |||
651 | buf_discard(buf); | 577 | buf_discard(buf); |
652 | } | 578 | } |
653 | 579 | ||
654 | static void port_print(struct port *p_ptr, struct print_buf *buf, int full_id) | 580 | static void port_print(struct tipc_port *p_ptr, struct print_buf *buf, int full_id) |
655 | { | 581 | { |
656 | struct publication *publ; | 582 | struct publication *publ; |
657 | 583 | ||
658 | if (full_id) | 584 | if (full_id) |
659 | tipc_printf(buf, "<%u.%u.%u:%u>:", | 585 | tipc_printf(buf, "<%u.%u.%u:%u>:", |
660 | tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), | 586 | tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), |
661 | tipc_node(tipc_own_addr), p_ptr->publ.ref); | 587 | tipc_node(tipc_own_addr), p_ptr->ref); |
662 | else | 588 | else |
663 | tipc_printf(buf, "%-10u:", p_ptr->publ.ref); | 589 | tipc_printf(buf, "%-10u:", p_ptr->ref); |
664 | 590 | ||
665 | if (p_ptr->publ.connected) { | 591 | if (p_ptr->connected) { |
666 | u32 dport = port_peerport(p_ptr); | 592 | u32 dport = port_peerport(p_ptr); |
667 | u32 destnode = port_peernode(p_ptr); | 593 | u32 destnode = port_peernode(p_ptr); |
668 | 594 | ||
669 | tipc_printf(buf, " connected to <%u.%u.%u:%u>", | 595 | tipc_printf(buf, " connected to <%u.%u.%u:%u>", |
670 | tipc_zone(destnode), tipc_cluster(destnode), | 596 | tipc_zone(destnode), tipc_cluster(destnode), |
671 | tipc_node(destnode), dport); | 597 | tipc_node(destnode), dport); |
672 | if (p_ptr->publ.conn_type != 0) | 598 | if (p_ptr->conn_type != 0) |
673 | tipc_printf(buf, " via {%u,%u}", | 599 | tipc_printf(buf, " via {%u,%u}", |
674 | p_ptr->publ.conn_type, | 600 | p_ptr->conn_type, |
675 | p_ptr->publ.conn_instance); | 601 | p_ptr->conn_instance); |
676 | } | 602 | } else if (p_ptr->published) { |
677 | else if (p_ptr->publ.published) { | ||
678 | tipc_printf(buf, " bound to"); | 603 | tipc_printf(buf, " bound to"); |
679 | list_for_each_entry(publ, &p_ptr->publications, pport_list) { | 604 | list_for_each_entry(publ, &p_ptr->publications, pport_list) { |
680 | if (publ->lower == publ->upper) | 605 | if (publ->lower == publ->upper) |
@@ -695,7 +620,7 @@ struct sk_buff *tipc_port_get_ports(void) | |||
695 | struct sk_buff *buf; | 620 | struct sk_buff *buf; |
696 | struct tlv_desc *rep_tlv; | 621 | struct tlv_desc *rep_tlv; |
697 | struct print_buf pb; | 622 | struct print_buf pb; |
698 | struct port *p_ptr; | 623 | struct tipc_port *p_ptr; |
699 | int str_len; | 624 | int str_len; |
700 | 625 | ||
701 | buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_PORT_QUERY)); | 626 | buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_PORT_QUERY)); |
@@ -706,9 +631,9 @@ struct sk_buff *tipc_port_get_ports(void) | |||
706 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), MAX_PORT_QUERY); | 631 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), MAX_PORT_QUERY); |
707 | spin_lock_bh(&tipc_port_list_lock); | 632 | spin_lock_bh(&tipc_port_list_lock); |
708 | list_for_each_entry(p_ptr, &ports, port_list) { | 633 | list_for_each_entry(p_ptr, &ports, port_list) { |
709 | spin_lock_bh(p_ptr->publ.lock); | 634 | spin_lock_bh(p_ptr->lock); |
710 | port_print(p_ptr, &pb, 0); | 635 | port_print(p_ptr, &pb, 0); |
711 | spin_unlock_bh(p_ptr->publ.lock); | 636 | spin_unlock_bh(p_ptr->lock); |
712 | } | 637 | } |
713 | spin_unlock_bh(&tipc_port_list_lock); | 638 | spin_unlock_bh(&tipc_port_list_lock); |
714 | str_len = tipc_printbuf_validate(&pb); | 639 | str_len = tipc_printbuf_validate(&pb); |
@@ -719,58 +644,14 @@ struct sk_buff *tipc_port_get_ports(void) | |||
719 | return buf; | 644 | return buf; |
720 | } | 645 | } |
721 | 646 | ||
722 | #if 0 | ||
723 | |||
724 | #define MAX_PORT_STATS 2000 | ||
725 | |||
726 | struct sk_buff *port_show_stats(const void *req_tlv_area, int req_tlv_space) | ||
727 | { | ||
728 | u32 ref; | ||
729 | struct port *p_ptr; | ||
730 | struct sk_buff *buf; | ||
731 | struct tlv_desc *rep_tlv; | ||
732 | struct print_buf pb; | ||
733 | int str_len; | ||
734 | |||
735 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_PORT_REF)) | ||
736 | return cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | ||
737 | |||
738 | ref = *(u32 *)TLV_DATA(req_tlv_area); | ||
739 | ref = ntohl(ref); | ||
740 | |||
741 | p_ptr = tipc_port_lock(ref); | ||
742 | if (!p_ptr) | ||
743 | return cfg_reply_error_string("port not found"); | ||
744 | |||
745 | buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_PORT_STATS)); | ||
746 | if (!buf) { | ||
747 | tipc_port_unlock(p_ptr); | ||
748 | return NULL; | ||
749 | } | ||
750 | rep_tlv = (struct tlv_desc *)buf->data; | ||
751 | |||
752 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), MAX_PORT_STATS); | ||
753 | port_print(p_ptr, &pb, 1); | ||
754 | /* NEED TO FILL IN ADDITIONAL PORT STATISTICS HERE */ | ||
755 | tipc_port_unlock(p_ptr); | ||
756 | str_len = tipc_printbuf_validate(&pb); | ||
757 | |||
758 | skb_put(buf, TLV_SPACE(str_len)); | ||
759 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); | ||
760 | |||
761 | return buf; | ||
762 | } | ||
763 | |||
764 | #endif | ||
765 | |||
766 | void tipc_port_reinit(void) | 647 | void tipc_port_reinit(void) |
767 | { | 648 | { |
768 | struct port *p_ptr; | 649 | struct tipc_port *p_ptr; |
769 | struct tipc_msg *msg; | 650 | struct tipc_msg *msg; |
770 | 651 | ||
771 | spin_lock_bh(&tipc_port_list_lock); | 652 | spin_lock_bh(&tipc_port_list_lock); |
772 | list_for_each_entry(p_ptr, &ports, port_list) { | 653 | list_for_each_entry(p_ptr, &ports, port_list) { |
773 | msg = &p_ptr->publ.phdr; | 654 | msg = &p_ptr->phdr; |
774 | if (msg_orignode(msg) == tipc_own_addr) | 655 | if (msg_orignode(msg) == tipc_own_addr) |
775 | break; | 656 | break; |
776 | msg_set_prevnode(msg, tipc_own_addr); | 657 | msg_set_prevnode(msg, tipc_own_addr); |
@@ -795,7 +676,7 @@ static void port_dispatcher_sigh(void *dummy) | |||
795 | spin_unlock_bh(&queue_lock); | 676 | spin_unlock_bh(&queue_lock); |
796 | 677 | ||
797 | while (buf) { | 678 | while (buf) { |
798 | struct port *p_ptr; | 679 | struct tipc_port *p_ptr; |
799 | struct user_port *up_ptr; | 680 | struct user_port *up_ptr; |
800 | struct tipc_portid orig; | 681 | struct tipc_portid orig; |
801 | struct tipc_name_seq dseq; | 682 | struct tipc_name_seq dseq; |
@@ -820,8 +701,8 @@ static void port_dispatcher_sigh(void *dummy) | |||
820 | orig.node = msg_orignode(msg); | 701 | orig.node = msg_orignode(msg); |
821 | up_ptr = p_ptr->user_port; | 702 | up_ptr = p_ptr->user_port; |
822 | usr_handle = up_ptr->usr_handle; | 703 | usr_handle = up_ptr->usr_handle; |
823 | connected = p_ptr->publ.connected; | 704 | connected = p_ptr->connected; |
824 | published = p_ptr->publ.published; | 705 | published = p_ptr->published; |
825 | 706 | ||
826 | if (unlikely(msg_errcode(msg))) | 707 | if (unlikely(msg_errcode(msg))) |
827 | goto err; | 708 | goto err; |
@@ -832,6 +713,7 @@ static void port_dispatcher_sigh(void *dummy) | |||
832 | tipc_conn_msg_event cb = up_ptr->conn_msg_cb; | 713 | tipc_conn_msg_event cb = up_ptr->conn_msg_cb; |
833 | u32 peer_port = port_peerport(p_ptr); | 714 | u32 peer_port = port_peerport(p_ptr); |
834 | u32 peer_node = port_peernode(p_ptr); | 715 | u32 peer_node = port_peernode(p_ptr); |
716 | u32 dsz; | ||
835 | 717 | ||
836 | tipc_port_unlock(p_ptr); | 718 | tipc_port_unlock(p_ptr); |
837 | if (unlikely(!cb)) | 719 | if (unlikely(!cb)) |
@@ -842,13 +724,14 @@ static void port_dispatcher_sigh(void *dummy) | |||
842 | } else if ((msg_origport(msg) != peer_port) || | 724 | } else if ((msg_origport(msg) != peer_port) || |
843 | (msg_orignode(msg) != peer_node)) | 725 | (msg_orignode(msg) != peer_node)) |
844 | goto reject; | 726 | goto reject; |
845 | if (unlikely(++p_ptr->publ.conn_unacked >= | 727 | dsz = msg_data_sz(msg); |
846 | TIPC_FLOW_CONTROL_WIN)) | 728 | if (unlikely(dsz && |
729 | (++p_ptr->conn_unacked >= | ||
730 | TIPC_FLOW_CONTROL_WIN))) | ||
847 | tipc_acknowledge(dref, | 731 | tipc_acknowledge(dref, |
848 | p_ptr->publ.conn_unacked); | 732 | p_ptr->conn_unacked); |
849 | skb_pull(buf, msg_hdr_sz(msg)); | 733 | skb_pull(buf, msg_hdr_sz(msg)); |
850 | cb(usr_handle, dref, &buf, msg_data(msg), | 734 | cb(usr_handle, dref, &buf, msg_data(msg), dsz); |
851 | msg_data_sz(msg)); | ||
852 | break; | 735 | break; |
853 | } | 736 | } |
854 | case TIPC_DIRECT_MSG:{ | 737 | case TIPC_DIRECT_MSG:{ |
@@ -972,7 +855,7 @@ static u32 port_dispatcher(struct tipc_port *dummy, struct sk_buff *buf) | |||
972 | 855 | ||
973 | static void port_wakeup_sh(unsigned long ref) | 856 | static void port_wakeup_sh(unsigned long ref) |
974 | { | 857 | { |
975 | struct port *p_ptr; | 858 | struct tipc_port *p_ptr; |
976 | struct user_port *up_ptr; | 859 | struct user_port *up_ptr; |
977 | tipc_continue_event cb = NULL; | 860 | tipc_continue_event cb = NULL; |
978 | void *uh = NULL; | 861 | void *uh = NULL; |
@@ -998,14 +881,14 @@ static void port_wakeup(struct tipc_port *p_ptr) | |||
998 | 881 | ||
999 | void tipc_acknowledge(u32 ref, u32 ack) | 882 | void tipc_acknowledge(u32 ref, u32 ack) |
1000 | { | 883 | { |
1001 | struct port *p_ptr; | 884 | struct tipc_port *p_ptr; |
1002 | struct sk_buff *buf = NULL; | 885 | struct sk_buff *buf = NULL; |
1003 | 886 | ||
1004 | p_ptr = tipc_port_lock(ref); | 887 | p_ptr = tipc_port_lock(ref); |
1005 | if (!p_ptr) | 888 | if (!p_ptr) |
1006 | return; | 889 | return; |
1007 | if (p_ptr->publ.connected) { | 890 | if (p_ptr->connected) { |
1008 | p_ptr->publ.conn_unacked -= ack; | 891 | p_ptr->conn_unacked -= ack; |
1009 | buf = port_build_proto_msg(port_peerport(p_ptr), | 892 | buf = port_build_proto_msg(port_peerport(p_ptr), |
1010 | port_peernode(p_ptr), | 893 | port_peernode(p_ptr), |
1011 | ref, | 894 | ref, |
@@ -1013,7 +896,6 @@ void tipc_acknowledge(u32 ref, u32 ack) | |||
1013 | CONN_MANAGER, | 896 | CONN_MANAGER, |
1014 | CONN_ACK, | 897 | CONN_ACK, |
1015 | TIPC_OK, | 898 | TIPC_OK, |
1016 | port_out_seqno(p_ptr), | ||
1017 | ack); | 899 | ack); |
1018 | } | 900 | } |
1019 | tipc_port_unlock(p_ptr); | 901 | tipc_port_unlock(p_ptr); |
@@ -1021,12 +903,10 @@ void tipc_acknowledge(u32 ref, u32 ack) | |||
1021 | } | 903 | } |
1022 | 904 | ||
1023 | /* | 905 | /* |
1024 | * tipc_createport(): user level call. Will add port to | 906 | * tipc_createport(): user level call. |
1025 | * registry if non-zero user_ref. | ||
1026 | */ | 907 | */ |
1027 | 908 | ||
1028 | int tipc_createport(u32 user_ref, | 909 | int tipc_createport(void *usr_handle, |
1029 | void *usr_handle, | ||
1030 | unsigned int importance, | 910 | unsigned int importance, |
1031 | tipc_msg_err_event error_cb, | 911 | tipc_msg_err_event error_cb, |
1032 | tipc_named_msg_err_event named_error_cb, | 912 | tipc_named_msg_err_event named_error_cb, |
@@ -1038,14 +918,14 @@ int tipc_createport(u32 user_ref, | |||
1038 | u32 *portref) | 918 | u32 *portref) |
1039 | { | 919 | { |
1040 | struct user_port *up_ptr; | 920 | struct user_port *up_ptr; |
1041 | struct port *p_ptr; | 921 | struct tipc_port *p_ptr; |
1042 | 922 | ||
1043 | up_ptr = kmalloc(sizeof(*up_ptr), GFP_ATOMIC); | 923 | up_ptr = kmalloc(sizeof(*up_ptr), GFP_ATOMIC); |
1044 | if (!up_ptr) { | 924 | if (!up_ptr) { |
1045 | warn("Port creation failed, no memory\n"); | 925 | warn("Port creation failed, no memory\n"); |
1046 | return -ENOMEM; | 926 | return -ENOMEM; |
1047 | } | 927 | } |
1048 | p_ptr = (struct port *)tipc_createport_raw(NULL, port_dispatcher, | 928 | p_ptr = (struct tipc_port *)tipc_createport_raw(NULL, port_dispatcher, |
1049 | port_wakeup, importance); | 929 | port_wakeup, importance); |
1050 | if (!p_ptr) { | 930 | if (!p_ptr) { |
1051 | kfree(up_ptr); | 931 | kfree(up_ptr); |
@@ -1053,9 +933,8 @@ int tipc_createport(u32 user_ref, | |||
1053 | } | 933 | } |
1054 | 934 | ||
1055 | p_ptr->user_port = up_ptr; | 935 | p_ptr->user_port = up_ptr; |
1056 | up_ptr->user_ref = user_ref; | ||
1057 | up_ptr->usr_handle = usr_handle; | 936 | up_ptr->usr_handle = usr_handle; |
1058 | up_ptr->ref = p_ptr->publ.ref; | 937 | up_ptr->ref = p_ptr->ref; |
1059 | up_ptr->err_cb = error_cb; | 938 | up_ptr->err_cb = error_cb; |
1060 | up_ptr->named_err_cb = named_error_cb; | 939 | up_ptr->named_err_cb = named_error_cb; |
1061 | up_ptr->conn_err_cb = conn_error_cb; | 940 | up_ptr->conn_err_cb = conn_error_cb; |
@@ -1063,35 +942,26 @@ int tipc_createport(u32 user_ref, | |||
1063 | up_ptr->named_msg_cb = named_msg_cb; | 942 | up_ptr->named_msg_cb = named_msg_cb; |
1064 | up_ptr->conn_msg_cb = conn_msg_cb; | 943 | up_ptr->conn_msg_cb = conn_msg_cb; |
1065 | up_ptr->continue_event_cb = continue_event_cb; | 944 | up_ptr->continue_event_cb = continue_event_cb; |
1066 | INIT_LIST_HEAD(&up_ptr->uport_list); | 945 | *portref = p_ptr->ref; |
1067 | tipc_reg_add_port(up_ptr); | ||
1068 | *portref = p_ptr->publ.ref; | ||
1069 | tipc_port_unlock(p_ptr); | 946 | tipc_port_unlock(p_ptr); |
1070 | return 0; | 947 | return 0; |
1071 | } | 948 | } |
1072 | 949 | ||
1073 | int tipc_ownidentity(u32 ref, struct tipc_portid *id) | ||
1074 | { | ||
1075 | id->ref = ref; | ||
1076 | id->node = tipc_own_addr; | ||
1077 | return 0; | ||
1078 | } | ||
1079 | |||
1080 | int tipc_portimportance(u32 ref, unsigned int *importance) | 950 | int tipc_portimportance(u32 ref, unsigned int *importance) |
1081 | { | 951 | { |
1082 | struct port *p_ptr; | 952 | struct tipc_port *p_ptr; |
1083 | 953 | ||
1084 | p_ptr = tipc_port_lock(ref); | 954 | p_ptr = tipc_port_lock(ref); |
1085 | if (!p_ptr) | 955 | if (!p_ptr) |
1086 | return -EINVAL; | 956 | return -EINVAL; |
1087 | *importance = (unsigned int)msg_importance(&p_ptr->publ.phdr); | 957 | *importance = (unsigned int)msg_importance(&p_ptr->phdr); |
1088 | tipc_port_unlock(p_ptr); | 958 | tipc_port_unlock(p_ptr); |
1089 | return 0; | 959 | return 0; |
1090 | } | 960 | } |
1091 | 961 | ||
1092 | int tipc_set_portimportance(u32 ref, unsigned int imp) | 962 | int tipc_set_portimportance(u32 ref, unsigned int imp) |
1093 | { | 963 | { |
1094 | struct port *p_ptr; | 964 | struct tipc_port *p_ptr; |
1095 | 965 | ||
1096 | if (imp > TIPC_CRITICAL_IMPORTANCE) | 966 | if (imp > TIPC_CRITICAL_IMPORTANCE) |
1097 | return -EINVAL; | 967 | return -EINVAL; |
@@ -1099,7 +969,7 @@ int tipc_set_portimportance(u32 ref, unsigned int imp) | |||
1099 | p_ptr = tipc_port_lock(ref); | 969 | p_ptr = tipc_port_lock(ref); |
1100 | if (!p_ptr) | 970 | if (!p_ptr) |
1101 | return -EINVAL; | 971 | return -EINVAL; |
1102 | msg_set_importance(&p_ptr->publ.phdr, (u32)imp); | 972 | msg_set_importance(&p_ptr->phdr, (u32)imp); |
1103 | tipc_port_unlock(p_ptr); | 973 | tipc_port_unlock(p_ptr); |
1104 | return 0; | 974 | return 0; |
1105 | } | 975 | } |
@@ -1107,7 +977,7 @@ int tipc_set_portimportance(u32 ref, unsigned int imp) | |||
1107 | 977 | ||
1108 | int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) | 978 | int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) |
1109 | { | 979 | { |
1110 | struct port *p_ptr; | 980 | struct tipc_port *p_ptr; |
1111 | struct publication *publ; | 981 | struct publication *publ; |
1112 | u32 key; | 982 | u32 key; |
1113 | int res = -EINVAL; | 983 | int res = -EINVAL; |
@@ -1116,10 +986,7 @@ int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) | |||
1116 | if (!p_ptr) | 986 | if (!p_ptr) |
1117 | return -EINVAL; | 987 | return -EINVAL; |
1118 | 988 | ||
1119 | dbg("tipc_publ %u, p_ptr = %x, conn = %x, scope = %x, " | 989 | if (p_ptr->connected) |
1120 | "lower = %u, upper = %u\n", | ||
1121 | ref, p_ptr, p_ptr->publ.connected, scope, seq->lower, seq->upper); | ||
1122 | if (p_ptr->publ.connected) | ||
1123 | goto exit; | 990 | goto exit; |
1124 | if (seq->lower > seq->upper) | 991 | if (seq->lower > seq->upper) |
1125 | goto exit; | 992 | goto exit; |
@@ -1131,11 +998,11 @@ int tipc_publish(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) | |||
1131 | goto exit; | 998 | goto exit; |
1132 | } | 999 | } |
1133 | publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, | 1000 | publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, |
1134 | scope, p_ptr->publ.ref, key); | 1001 | scope, p_ptr->ref, key); |
1135 | if (publ) { | 1002 | if (publ) { |
1136 | list_add(&publ->pport_list, &p_ptr->publications); | 1003 | list_add(&publ->pport_list, &p_ptr->publications); |
1137 | p_ptr->pub_count++; | 1004 | p_ptr->pub_count++; |
1138 | p_ptr->publ.published = 1; | 1005 | p_ptr->published = 1; |
1139 | res = 0; | 1006 | res = 0; |
1140 | } | 1007 | } |
1141 | exit: | 1008 | exit: |
@@ -1145,7 +1012,7 @@ exit: | |||
1145 | 1012 | ||
1146 | int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) | 1013 | int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) |
1147 | { | 1014 | { |
1148 | struct port *p_ptr; | 1015 | struct tipc_port *p_ptr; |
1149 | struct publication *publ; | 1016 | struct publication *publ; |
1150 | struct publication *tpubl; | 1017 | struct publication *tpubl; |
1151 | int res = -EINVAL; | 1018 | int res = -EINVAL; |
@@ -1178,49 +1045,46 @@ int tipc_withdraw(u32 ref, unsigned int scope, struct tipc_name_seq const *seq) | |||
1178 | } | 1045 | } |
1179 | } | 1046 | } |
1180 | if (list_empty(&p_ptr->publications)) | 1047 | if (list_empty(&p_ptr->publications)) |
1181 | p_ptr->publ.published = 0; | 1048 | p_ptr->published = 0; |
1182 | tipc_port_unlock(p_ptr); | 1049 | tipc_port_unlock(p_ptr); |
1183 | return res; | 1050 | return res; |
1184 | } | 1051 | } |
1185 | 1052 | ||
1186 | int tipc_connect2port(u32 ref, struct tipc_portid const *peer) | 1053 | int tipc_connect2port(u32 ref, struct tipc_portid const *peer) |
1187 | { | 1054 | { |
1188 | struct port *p_ptr; | 1055 | struct tipc_port *p_ptr; |
1189 | struct tipc_msg *msg; | 1056 | struct tipc_msg *msg; |
1190 | int res = -EINVAL; | 1057 | int res = -EINVAL; |
1191 | 1058 | ||
1192 | p_ptr = tipc_port_lock(ref); | 1059 | p_ptr = tipc_port_lock(ref); |
1193 | if (!p_ptr) | 1060 | if (!p_ptr) |
1194 | return -EINVAL; | 1061 | return -EINVAL; |
1195 | if (p_ptr->publ.published || p_ptr->publ.connected) | 1062 | if (p_ptr->published || p_ptr->connected) |
1196 | goto exit; | 1063 | goto exit; |
1197 | if (!peer->ref) | 1064 | if (!peer->ref) |
1198 | goto exit; | 1065 | goto exit; |
1199 | 1066 | ||
1200 | msg = &p_ptr->publ.phdr; | 1067 | msg = &p_ptr->phdr; |
1201 | msg_set_destnode(msg, peer->node); | 1068 | msg_set_destnode(msg, peer->node); |
1202 | msg_set_destport(msg, peer->ref); | 1069 | msg_set_destport(msg, peer->ref); |
1203 | msg_set_orignode(msg, tipc_own_addr); | 1070 | msg_set_orignode(msg, tipc_own_addr); |
1204 | msg_set_origport(msg, p_ptr->publ.ref); | 1071 | msg_set_origport(msg, p_ptr->ref); |
1205 | msg_set_transp_seqno(msg, 42); | ||
1206 | msg_set_type(msg, TIPC_CONN_MSG); | 1072 | msg_set_type(msg, TIPC_CONN_MSG); |
1207 | if (!may_route(peer->node)) | 1073 | msg_set_lookup_scope(msg, 0); |
1208 | msg_set_hdr_sz(msg, SHORT_H_SIZE); | 1074 | msg_set_hdr_sz(msg, SHORT_H_SIZE); |
1209 | else | ||
1210 | msg_set_hdr_sz(msg, LONG_H_SIZE); | ||
1211 | 1075 | ||
1212 | p_ptr->probing_interval = PROBING_INTERVAL; | 1076 | p_ptr->probing_interval = PROBING_INTERVAL; |
1213 | p_ptr->probing_state = CONFIRMED; | 1077 | p_ptr->probing_state = CONFIRMED; |
1214 | p_ptr->publ.connected = 1; | 1078 | p_ptr->connected = 1; |
1215 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); | 1079 | k_start_timer(&p_ptr->timer, p_ptr->probing_interval); |
1216 | 1080 | ||
1217 | tipc_nodesub_subscribe(&p_ptr->subscription,peer->node, | 1081 | tipc_nodesub_subscribe(&p_ptr->subscription, peer->node, |
1218 | (void *)(unsigned long)ref, | 1082 | (void *)(unsigned long)ref, |
1219 | (net_ev_handler)port_handle_node_down); | 1083 | (net_ev_handler)port_handle_node_down); |
1220 | res = 0; | 1084 | res = 0; |
1221 | exit: | 1085 | exit: |
1222 | tipc_port_unlock(p_ptr); | 1086 | tipc_port_unlock(p_ptr); |
1223 | p_ptr->publ.max_pkt = tipc_link_get_max_pkt(peer->node, ref); | 1087 | p_ptr->max_pkt = tipc_link_get_max_pkt(peer->node, ref); |
1224 | return res; | 1088 | return res; |
1225 | } | 1089 | } |
1226 | 1090 | ||
@@ -1238,7 +1102,7 @@ int tipc_disconnect_port(struct tipc_port *tp_ptr) | |||
1238 | tp_ptr->connected = 0; | 1102 | tp_ptr->connected = 0; |
1239 | /* let timer expire on it's own to avoid deadlock! */ | 1103 | /* let timer expire on it's own to avoid deadlock! */ |
1240 | tipc_nodesub_unsubscribe( | 1104 | tipc_nodesub_unsubscribe( |
1241 | &((struct port *)tp_ptr)->subscription); | 1105 | &((struct tipc_port *)tp_ptr)->subscription); |
1242 | res = 0; | 1106 | res = 0; |
1243 | } else { | 1107 | } else { |
1244 | res = -ENOTCONN; | 1108 | res = -ENOTCONN; |
@@ -1253,7 +1117,7 @@ int tipc_disconnect_port(struct tipc_port *tp_ptr) | |||
1253 | 1117 | ||
1254 | int tipc_disconnect(u32 ref) | 1118 | int tipc_disconnect(u32 ref) |
1255 | { | 1119 | { |
1256 | struct port *p_ptr; | 1120 | struct tipc_port *p_ptr; |
1257 | int res; | 1121 | int res; |
1258 | 1122 | ||
1259 | p_ptr = tipc_port_lock(ref); | 1123 | p_ptr = tipc_port_lock(ref); |
@@ -1269,15 +1133,15 @@ int tipc_disconnect(u32 ref) | |||
1269 | */ | 1133 | */ |
1270 | int tipc_shutdown(u32 ref) | 1134 | int tipc_shutdown(u32 ref) |
1271 | { | 1135 | { |
1272 | struct port *p_ptr; | 1136 | struct tipc_port *p_ptr; |
1273 | struct sk_buff *buf = NULL; | 1137 | struct sk_buff *buf = NULL; |
1274 | 1138 | ||
1275 | p_ptr = tipc_port_lock(ref); | 1139 | p_ptr = tipc_port_lock(ref); |
1276 | if (!p_ptr) | 1140 | if (!p_ptr) |
1277 | return -EINVAL; | 1141 | return -EINVAL; |
1278 | 1142 | ||
1279 | if (p_ptr->publ.connected) { | 1143 | if (p_ptr->connected) { |
1280 | u32 imp = msg_importance(&p_ptr->publ.phdr); | 1144 | u32 imp = msg_importance(&p_ptr->phdr); |
1281 | if (imp < TIPC_CRITICAL_IMPORTANCE) | 1145 | if (imp < TIPC_CRITICAL_IMPORTANCE) |
1282 | imp++; | 1146 | imp++; |
1283 | buf = port_build_proto_msg(port_peerport(p_ptr), | 1147 | buf = port_build_proto_msg(port_peerport(p_ptr), |
@@ -1287,7 +1151,6 @@ int tipc_shutdown(u32 ref) | |||
1287 | imp, | 1151 | imp, |
1288 | TIPC_CONN_MSG, | 1152 | TIPC_CONN_MSG, |
1289 | TIPC_CONN_SHUTDOWN, | 1153 | TIPC_CONN_SHUTDOWN, |
1290 | port_out_seqno(p_ptr), | ||
1291 | 0); | 1154 | 0); |
1292 | } | 1155 | } |
1293 | tipc_port_unlock(p_ptr); | 1156 | tipc_port_unlock(p_ptr); |
@@ -1295,55 +1158,19 @@ int tipc_shutdown(u32 ref) | |||
1295 | return tipc_disconnect(ref); | 1158 | return tipc_disconnect(ref); |
1296 | } | 1159 | } |
1297 | 1160 | ||
1298 | int tipc_isconnected(u32 ref, int *isconnected) | ||
1299 | { | ||
1300 | struct port *p_ptr; | ||
1301 | |||
1302 | p_ptr = tipc_port_lock(ref); | ||
1303 | if (!p_ptr) | ||
1304 | return -EINVAL; | ||
1305 | *isconnected = p_ptr->publ.connected; | ||
1306 | tipc_port_unlock(p_ptr); | ||
1307 | return 0; | ||
1308 | } | ||
1309 | |||
1310 | int tipc_peer(u32 ref, struct tipc_portid *peer) | ||
1311 | { | ||
1312 | struct port *p_ptr; | ||
1313 | int res; | ||
1314 | |||
1315 | p_ptr = tipc_port_lock(ref); | ||
1316 | if (!p_ptr) | ||
1317 | return -EINVAL; | ||
1318 | if (p_ptr->publ.connected) { | ||
1319 | peer->ref = port_peerport(p_ptr); | ||
1320 | peer->node = port_peernode(p_ptr); | ||
1321 | res = 0; | ||
1322 | } else | ||
1323 | res = -ENOTCONN; | ||
1324 | tipc_port_unlock(p_ptr); | ||
1325 | return res; | ||
1326 | } | ||
1327 | |||
1328 | int tipc_ref_valid(u32 ref) | ||
1329 | { | ||
1330 | /* Works irrespective of type */ | ||
1331 | return !!tipc_ref_deref(ref); | ||
1332 | } | ||
1333 | |||
1334 | |||
1335 | /* | 1161 | /* |
1336 | * tipc_port_recv_sections(): Concatenate and deliver sectioned | 1162 | * tipc_port_recv_sections(): Concatenate and deliver sectioned |
1337 | * message for this node. | 1163 | * message for this node. |
1338 | */ | 1164 | */ |
1339 | 1165 | ||
1340 | int tipc_port_recv_sections(struct port *sender, unsigned int num_sect, | 1166 | static int tipc_port_recv_sections(struct tipc_port *sender, unsigned int num_sect, |
1341 | struct iovec const *msg_sect) | 1167 | struct iovec const *msg_sect, |
1168 | unsigned int total_len) | ||
1342 | { | 1169 | { |
1343 | struct sk_buff *buf; | 1170 | struct sk_buff *buf; |
1344 | int res; | 1171 | int res; |
1345 | 1172 | ||
1346 | res = tipc_msg_build(&sender->publ.phdr, msg_sect, num_sect, | 1173 | res = tipc_msg_build(&sender->phdr, msg_sect, num_sect, total_len, |
1347 | MAX_MSG_SIZE, !sender->user_port, &buf); | 1174 | MAX_MSG_SIZE, !sender->user_port, &buf); |
1348 | if (likely(buf)) | 1175 | if (likely(buf)) |
1349 | tipc_port_recv_msg(buf); | 1176 | tipc_port_recv_msg(buf); |
@@ -1354,352 +1181,175 @@ int tipc_port_recv_sections(struct port *sender, unsigned int num_sect, | |||
1354 | * tipc_send - send message sections on connection | 1181 | * tipc_send - send message sections on connection |
1355 | */ | 1182 | */ |
1356 | 1183 | ||
1357 | int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect) | 1184 | int tipc_send(u32 ref, unsigned int num_sect, struct iovec const *msg_sect, |
1185 | unsigned int total_len) | ||
1358 | { | 1186 | { |
1359 | struct port *p_ptr; | 1187 | struct tipc_port *p_ptr; |
1360 | u32 destnode; | 1188 | u32 destnode; |
1361 | int res; | 1189 | int res; |
1362 | 1190 | ||
1363 | p_ptr = tipc_port_deref(ref); | 1191 | p_ptr = tipc_port_deref(ref); |
1364 | if (!p_ptr || !p_ptr->publ.connected) | 1192 | if (!p_ptr || !p_ptr->connected) |
1365 | return -EINVAL; | 1193 | return -EINVAL; |
1366 | 1194 | ||
1367 | p_ptr->publ.congested = 1; | 1195 | p_ptr->congested = 1; |
1368 | if (!tipc_port_congested(p_ptr)) { | 1196 | if (!tipc_port_congested(p_ptr)) { |
1369 | destnode = port_peernode(p_ptr); | 1197 | destnode = port_peernode(p_ptr); |
1370 | if (likely(destnode != tipc_own_addr)) | 1198 | if (likely(destnode != tipc_own_addr)) |
1371 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, | 1199 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, |
1372 | destnode); | 1200 | total_len, destnode); |
1373 | else | 1201 | else |
1374 | res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect); | 1202 | res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect, |
1203 | total_len); | ||
1375 | 1204 | ||
1376 | if (likely(res != -ELINKCONG)) { | 1205 | if (likely(res != -ELINKCONG)) { |
1377 | port_incr_out_seqno(p_ptr); | 1206 | p_ptr->congested = 0; |
1378 | p_ptr->publ.congested = 0; | 1207 | if (res > 0) |
1379 | p_ptr->sent++; | 1208 | p_ptr->sent++; |
1380 | return res; | 1209 | return res; |
1381 | } | 1210 | } |
1382 | } | 1211 | } |
1383 | if (port_unreliable(p_ptr)) { | 1212 | if (port_unreliable(p_ptr)) { |
1384 | p_ptr->publ.congested = 0; | 1213 | p_ptr->congested = 0; |
1385 | /* Just calculate msg length and return */ | 1214 | return total_len; |
1386 | return tipc_msg_calc_data_size(msg_sect, num_sect); | ||
1387 | } | 1215 | } |
1388 | return -ELINKCONG; | 1216 | return -ELINKCONG; |
1389 | } | 1217 | } |
1390 | 1218 | ||
1391 | /** | 1219 | /** |
1392 | * tipc_send_buf - send message buffer on connection | 1220 | * tipc_send2name - send message sections to port name |
1393 | */ | ||
1394 | |||
1395 | int tipc_send_buf(u32 ref, struct sk_buff *buf, unsigned int dsz) | ||
1396 | { | ||
1397 | struct port *p_ptr; | ||
1398 | struct tipc_msg *msg; | ||
1399 | u32 destnode; | ||
1400 | u32 hsz; | ||
1401 | u32 sz; | ||
1402 | u32 res; | ||
1403 | |||
1404 | p_ptr = tipc_port_deref(ref); | ||
1405 | if (!p_ptr || !p_ptr->publ.connected) | ||
1406 | return -EINVAL; | ||
1407 | |||
1408 | msg = &p_ptr->publ.phdr; | ||
1409 | hsz = msg_hdr_sz(msg); | ||
1410 | sz = hsz + dsz; | ||
1411 | msg_set_size(msg, sz); | ||
1412 | if (skb_cow(buf, hsz)) | ||
1413 | return -ENOMEM; | ||
1414 | |||
1415 | skb_push(buf, hsz); | ||
1416 | skb_copy_to_linear_data(buf, msg, hsz); | ||
1417 | destnode = msg_destnode(msg); | ||
1418 | p_ptr->publ.congested = 1; | ||
1419 | if (!tipc_port_congested(p_ptr)) { | ||
1420 | if (likely(destnode != tipc_own_addr)) | ||
1421 | res = tipc_send_buf_fast(buf, destnode); | ||
1422 | else { | ||
1423 | tipc_port_recv_msg(buf); | ||
1424 | res = sz; | ||
1425 | } | ||
1426 | if (likely(res != -ELINKCONG)) { | ||
1427 | port_incr_out_seqno(p_ptr); | ||
1428 | p_ptr->sent++; | ||
1429 | p_ptr->publ.congested = 0; | ||
1430 | return res; | ||
1431 | } | ||
1432 | } | ||
1433 | if (port_unreliable(p_ptr)) { | ||
1434 | p_ptr->publ.congested = 0; | ||
1435 | return dsz; | ||
1436 | } | ||
1437 | return -ELINKCONG; | ||
1438 | } | ||
1439 | |||
1440 | /** | ||
1441 | * tipc_forward2name - forward message sections to port name | ||
1442 | */ | 1221 | */ |
1443 | 1222 | ||
1444 | int tipc_forward2name(u32 ref, | 1223 | int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain, |
1445 | struct tipc_name const *name, | 1224 | unsigned int num_sect, struct iovec const *msg_sect, |
1446 | u32 domain, | 1225 | unsigned int total_len) |
1447 | u32 num_sect, | ||
1448 | struct iovec const *msg_sect, | ||
1449 | struct tipc_portid const *orig, | ||
1450 | unsigned int importance) | ||
1451 | { | 1226 | { |
1452 | struct port *p_ptr; | 1227 | struct tipc_port *p_ptr; |
1453 | struct tipc_msg *msg; | 1228 | struct tipc_msg *msg; |
1454 | u32 destnode = domain; | 1229 | u32 destnode = domain; |
1455 | u32 destport; | 1230 | u32 destport; |
1456 | int res; | 1231 | int res; |
1457 | 1232 | ||
1458 | p_ptr = tipc_port_deref(ref); | 1233 | p_ptr = tipc_port_deref(ref); |
1459 | if (!p_ptr || p_ptr->publ.connected) | 1234 | if (!p_ptr || p_ptr->connected) |
1460 | return -EINVAL; | 1235 | return -EINVAL; |
1461 | 1236 | ||
1462 | msg = &p_ptr->publ.phdr; | 1237 | msg = &p_ptr->phdr; |
1463 | msg_set_type(msg, TIPC_NAMED_MSG); | 1238 | msg_set_type(msg, TIPC_NAMED_MSG); |
1464 | msg_set_orignode(msg, orig->node); | 1239 | msg_set_orignode(msg, tipc_own_addr); |
1465 | msg_set_origport(msg, orig->ref); | 1240 | msg_set_origport(msg, ref); |
1466 | msg_set_hdr_sz(msg, LONG_H_SIZE); | 1241 | msg_set_hdr_sz(msg, LONG_H_SIZE); |
1467 | msg_set_nametype(msg, name->type); | 1242 | msg_set_nametype(msg, name->type); |
1468 | msg_set_nameinst(msg, name->instance); | 1243 | msg_set_nameinst(msg, name->instance); |
1469 | msg_set_lookup_scope(msg, tipc_addr_scope(domain)); | 1244 | msg_set_lookup_scope(msg, tipc_addr_scope(domain)); |
1470 | if (importance <= TIPC_CRITICAL_IMPORTANCE) | ||
1471 | msg_set_importance(msg,importance); | ||
1472 | destport = tipc_nametbl_translate(name->type, name->instance, &destnode); | 1245 | destport = tipc_nametbl_translate(name->type, name->instance, &destnode); |
1473 | msg_set_destnode(msg, destnode); | 1246 | msg_set_destnode(msg, destnode); |
1474 | msg_set_destport(msg, destport); | 1247 | msg_set_destport(msg, destport); |
1475 | 1248 | ||
1476 | if (likely(destport || destnode)) { | 1249 | if (likely(destport)) { |
1477 | p_ptr->sent++; | ||
1478 | if (likely(destnode == tipc_own_addr)) | 1250 | if (likely(destnode == tipc_own_addr)) |
1479 | return tipc_port_recv_sections(p_ptr, num_sect, msg_sect); | 1251 | res = tipc_port_recv_sections(p_ptr, num_sect, |
1480 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, | 1252 | msg_sect, total_len); |
1481 | destnode); | 1253 | else |
1482 | if (likely(res != -ELINKCONG)) | 1254 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, |
1255 | num_sect, total_len, | ||
1256 | destnode); | ||
1257 | if (likely(res != -ELINKCONG)) { | ||
1258 | if (res > 0) | ||
1259 | p_ptr->sent++; | ||
1483 | return res; | 1260 | return res; |
1261 | } | ||
1484 | if (port_unreliable(p_ptr)) { | 1262 | if (port_unreliable(p_ptr)) { |
1485 | /* Just calculate msg length and return */ | 1263 | return total_len; |
1486 | return tipc_msg_calc_data_size(msg_sect, num_sect); | ||
1487 | } | 1264 | } |
1488 | return -ELINKCONG; | 1265 | return -ELINKCONG; |
1489 | } | 1266 | } |
1490 | return tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect, | 1267 | return tipc_port_reject_sections(p_ptr, msg, msg_sect, num_sect, |
1491 | TIPC_ERR_NO_NAME); | 1268 | total_len, TIPC_ERR_NO_NAME); |
1492 | } | ||
1493 | |||
1494 | /** | ||
1495 | * tipc_send2name - send message sections to port name | ||
1496 | */ | ||
1497 | |||
1498 | int tipc_send2name(u32 ref, | ||
1499 | struct tipc_name const *name, | ||
1500 | unsigned int domain, | ||
1501 | unsigned int num_sect, | ||
1502 | struct iovec const *msg_sect) | ||
1503 | { | ||
1504 | struct tipc_portid orig; | ||
1505 | |||
1506 | orig.ref = ref; | ||
1507 | orig.node = tipc_own_addr; | ||
1508 | return tipc_forward2name(ref, name, domain, num_sect, msg_sect, &orig, | ||
1509 | TIPC_PORT_IMPORTANCE); | ||
1510 | } | 1269 | } |
1511 | 1270 | ||
1512 | /** | 1271 | /** |
1513 | * tipc_forward_buf2name - forward message buffer to port name | 1272 | * tipc_send2port - send message sections to port identity |
1514 | */ | ||
1515 | |||
1516 | int tipc_forward_buf2name(u32 ref, | ||
1517 | struct tipc_name const *name, | ||
1518 | u32 domain, | ||
1519 | struct sk_buff *buf, | ||
1520 | unsigned int dsz, | ||
1521 | struct tipc_portid const *orig, | ||
1522 | unsigned int importance) | ||
1523 | { | ||
1524 | struct port *p_ptr; | ||
1525 | struct tipc_msg *msg; | ||
1526 | u32 destnode = domain; | ||
1527 | u32 destport; | ||
1528 | int res; | ||
1529 | |||
1530 | p_ptr = (struct port *)tipc_ref_deref(ref); | ||
1531 | if (!p_ptr || p_ptr->publ.connected) | ||
1532 | return -EINVAL; | ||
1533 | |||
1534 | msg = &p_ptr->publ.phdr; | ||
1535 | if (importance <= TIPC_CRITICAL_IMPORTANCE) | ||
1536 | msg_set_importance(msg, importance); | ||
1537 | msg_set_type(msg, TIPC_NAMED_MSG); | ||
1538 | msg_set_orignode(msg, orig->node); | ||
1539 | msg_set_origport(msg, orig->ref); | ||
1540 | msg_set_nametype(msg, name->type); | ||
1541 | msg_set_nameinst(msg, name->instance); | ||
1542 | msg_set_lookup_scope(msg, tipc_addr_scope(domain)); | ||
1543 | msg_set_hdr_sz(msg, LONG_H_SIZE); | ||
1544 | msg_set_size(msg, LONG_H_SIZE + dsz); | ||
1545 | destport = tipc_nametbl_translate(name->type, name->instance, &destnode); | ||
1546 | msg_set_destnode(msg, destnode); | ||
1547 | msg_set_destport(msg, destport); | ||
1548 | msg_dbg(msg, "forw2name ==> "); | ||
1549 | if (skb_cow(buf, LONG_H_SIZE)) | ||
1550 | return -ENOMEM; | ||
1551 | skb_push(buf, LONG_H_SIZE); | ||
1552 | skb_copy_to_linear_data(buf, msg, LONG_H_SIZE); | ||
1553 | msg_dbg(buf_msg(buf),"PREP:"); | ||
1554 | if (likely(destport || destnode)) { | ||
1555 | p_ptr->sent++; | ||
1556 | if (destnode == tipc_own_addr) | ||
1557 | return tipc_port_recv_msg(buf); | ||
1558 | res = tipc_send_buf_fast(buf, destnode); | ||
1559 | if (likely(res != -ELINKCONG)) | ||
1560 | return res; | ||
1561 | if (port_unreliable(p_ptr)) | ||
1562 | return dsz; | ||
1563 | return -ELINKCONG; | ||
1564 | } | ||
1565 | return tipc_reject_msg(buf, TIPC_ERR_NO_NAME); | ||
1566 | } | ||
1567 | |||
1568 | /** | ||
1569 | * tipc_send_buf2name - send message buffer to port name | ||
1570 | */ | ||
1571 | |||
1572 | int tipc_send_buf2name(u32 ref, | ||
1573 | struct tipc_name const *dest, | ||
1574 | u32 domain, | ||
1575 | struct sk_buff *buf, | ||
1576 | unsigned int dsz) | ||
1577 | { | ||
1578 | struct tipc_portid orig; | ||
1579 | |||
1580 | orig.ref = ref; | ||
1581 | orig.node = tipc_own_addr; | ||
1582 | return tipc_forward_buf2name(ref, dest, domain, buf, dsz, &orig, | ||
1583 | TIPC_PORT_IMPORTANCE); | ||
1584 | } | ||
1585 | |||
1586 | /** | ||
1587 | * tipc_forward2port - forward message sections to port identity | ||
1588 | */ | 1273 | */ |
1589 | 1274 | ||
1590 | int tipc_forward2port(u32 ref, | 1275 | int tipc_send2port(u32 ref, struct tipc_portid const *dest, |
1591 | struct tipc_portid const *dest, | 1276 | unsigned int num_sect, struct iovec const *msg_sect, |
1592 | unsigned int num_sect, | 1277 | unsigned int total_len) |
1593 | struct iovec const *msg_sect, | ||
1594 | struct tipc_portid const *orig, | ||
1595 | unsigned int importance) | ||
1596 | { | 1278 | { |
1597 | struct port *p_ptr; | 1279 | struct tipc_port *p_ptr; |
1598 | struct tipc_msg *msg; | 1280 | struct tipc_msg *msg; |
1599 | int res; | 1281 | int res; |
1600 | 1282 | ||
1601 | p_ptr = tipc_port_deref(ref); | 1283 | p_ptr = tipc_port_deref(ref); |
1602 | if (!p_ptr || p_ptr->publ.connected) | 1284 | if (!p_ptr || p_ptr->connected) |
1603 | return -EINVAL; | 1285 | return -EINVAL; |
1604 | 1286 | ||
1605 | msg = &p_ptr->publ.phdr; | 1287 | msg = &p_ptr->phdr; |
1606 | msg_set_type(msg, TIPC_DIRECT_MSG); | 1288 | msg_set_type(msg, TIPC_DIRECT_MSG); |
1607 | msg_set_orignode(msg, orig->node); | 1289 | msg_set_lookup_scope(msg, 0); |
1608 | msg_set_origport(msg, orig->ref); | 1290 | msg_set_orignode(msg, tipc_own_addr); |
1291 | msg_set_origport(msg, ref); | ||
1609 | msg_set_destnode(msg, dest->node); | 1292 | msg_set_destnode(msg, dest->node); |
1610 | msg_set_destport(msg, dest->ref); | 1293 | msg_set_destport(msg, dest->ref); |
1611 | msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); | 1294 | msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); |
1612 | if (importance <= TIPC_CRITICAL_IMPORTANCE) | 1295 | |
1613 | msg_set_importance(msg, importance); | ||
1614 | p_ptr->sent++; | ||
1615 | if (dest->node == tipc_own_addr) | 1296 | if (dest->node == tipc_own_addr) |
1616 | return tipc_port_recv_sections(p_ptr, num_sect, msg_sect); | 1297 | res = tipc_port_recv_sections(p_ptr, num_sect, msg_sect, |
1617 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, dest->node); | 1298 | total_len); |
1618 | if (likely(res != -ELINKCONG)) | 1299 | else |
1300 | res = tipc_link_send_sections_fast(p_ptr, msg_sect, num_sect, | ||
1301 | total_len, dest->node); | ||
1302 | if (likely(res != -ELINKCONG)) { | ||
1303 | if (res > 0) | ||
1304 | p_ptr->sent++; | ||
1619 | return res; | 1305 | return res; |
1306 | } | ||
1620 | if (port_unreliable(p_ptr)) { | 1307 | if (port_unreliable(p_ptr)) { |
1621 | /* Just calculate msg length and return */ | 1308 | return total_len; |
1622 | return tipc_msg_calc_data_size(msg_sect, num_sect); | ||
1623 | } | 1309 | } |
1624 | return -ELINKCONG; | 1310 | return -ELINKCONG; |
1625 | } | 1311 | } |
1626 | 1312 | ||
1627 | /** | 1313 | /** |
1628 | * tipc_send2port - send message sections to port identity | 1314 | * tipc_send_buf2port - send message buffer to port identity |
1629 | */ | 1315 | */ |
1630 | 1316 | ||
1631 | int tipc_send2port(u32 ref, | 1317 | int tipc_send_buf2port(u32 ref, struct tipc_portid const *dest, |
1632 | struct tipc_portid const *dest, | 1318 | struct sk_buff *buf, unsigned int dsz) |
1633 | unsigned int num_sect, | ||
1634 | struct iovec const *msg_sect) | ||
1635 | { | 1319 | { |
1636 | struct tipc_portid orig; | 1320 | struct tipc_port *p_ptr; |
1637 | |||
1638 | orig.ref = ref; | ||
1639 | orig.node = tipc_own_addr; | ||
1640 | return tipc_forward2port(ref, dest, num_sect, msg_sect, &orig, | ||
1641 | TIPC_PORT_IMPORTANCE); | ||
1642 | } | ||
1643 | |||
1644 | /** | ||
1645 | * tipc_forward_buf2port - forward message buffer to port identity | ||
1646 | */ | ||
1647 | int tipc_forward_buf2port(u32 ref, | ||
1648 | struct tipc_portid const *dest, | ||
1649 | struct sk_buff *buf, | ||
1650 | unsigned int dsz, | ||
1651 | struct tipc_portid const *orig, | ||
1652 | unsigned int importance) | ||
1653 | { | ||
1654 | struct port *p_ptr; | ||
1655 | struct tipc_msg *msg; | 1321 | struct tipc_msg *msg; |
1656 | int res; | 1322 | int res; |
1657 | 1323 | ||
1658 | p_ptr = (struct port *)tipc_ref_deref(ref); | 1324 | p_ptr = (struct tipc_port *)tipc_ref_deref(ref); |
1659 | if (!p_ptr || p_ptr->publ.connected) | 1325 | if (!p_ptr || p_ptr->connected) |
1660 | return -EINVAL; | 1326 | return -EINVAL; |
1661 | 1327 | ||
1662 | msg = &p_ptr->publ.phdr; | 1328 | msg = &p_ptr->phdr; |
1663 | msg_set_type(msg, TIPC_DIRECT_MSG); | 1329 | msg_set_type(msg, TIPC_DIRECT_MSG); |
1664 | msg_set_orignode(msg, orig->node); | 1330 | msg_set_orignode(msg, tipc_own_addr); |
1665 | msg_set_origport(msg, orig->ref); | 1331 | msg_set_origport(msg, ref); |
1666 | msg_set_destnode(msg, dest->node); | 1332 | msg_set_destnode(msg, dest->node); |
1667 | msg_set_destport(msg, dest->ref); | 1333 | msg_set_destport(msg, dest->ref); |
1668 | msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); | 1334 | msg_set_hdr_sz(msg, DIR_MSG_H_SIZE); |
1669 | if (importance <= TIPC_CRITICAL_IMPORTANCE) | ||
1670 | msg_set_importance(msg, importance); | ||
1671 | msg_set_size(msg, DIR_MSG_H_SIZE + dsz); | 1335 | msg_set_size(msg, DIR_MSG_H_SIZE + dsz); |
1672 | if (skb_cow(buf, DIR_MSG_H_SIZE)) | 1336 | if (skb_cow(buf, DIR_MSG_H_SIZE)) |
1673 | return -ENOMEM; | 1337 | return -ENOMEM; |
1674 | 1338 | ||
1675 | skb_push(buf, DIR_MSG_H_SIZE); | 1339 | skb_push(buf, DIR_MSG_H_SIZE); |
1676 | skb_copy_to_linear_data(buf, msg, DIR_MSG_H_SIZE); | 1340 | skb_copy_to_linear_data(buf, msg, DIR_MSG_H_SIZE); |
1677 | msg_dbg(msg, "buf2port: "); | 1341 | |
1678 | p_ptr->sent++; | ||
1679 | if (dest->node == tipc_own_addr) | 1342 | if (dest->node == tipc_own_addr) |
1680 | return tipc_port_recv_msg(buf); | 1343 | res = tipc_port_recv_msg(buf); |
1681 | res = tipc_send_buf_fast(buf, dest->node); | 1344 | else |
1682 | if (likely(res != -ELINKCONG)) | 1345 | res = tipc_send_buf_fast(buf, dest->node); |
1346 | if (likely(res != -ELINKCONG)) { | ||
1347 | if (res > 0) | ||
1348 | p_ptr->sent++; | ||
1683 | return res; | 1349 | return res; |
1350 | } | ||
1684 | if (port_unreliable(p_ptr)) | 1351 | if (port_unreliable(p_ptr)) |
1685 | return dsz; | 1352 | return dsz; |
1686 | return -ELINKCONG; | 1353 | return -ELINKCONG; |
1687 | } | 1354 | } |
1688 | 1355 | ||
1689 | /** | ||
1690 | * tipc_send_buf2port - send message buffer to port identity | ||
1691 | */ | ||
1692 | |||
1693 | int tipc_send_buf2port(u32 ref, | ||
1694 | struct tipc_portid const *dest, | ||
1695 | struct sk_buff *buf, | ||
1696 | unsigned int dsz) | ||
1697 | { | ||
1698 | struct tipc_portid orig; | ||
1699 | |||
1700 | orig.ref = ref; | ||
1701 | orig.node = tipc_own_addr; | ||
1702 | return tipc_forward_buf2port(ref, dest, buf, dsz, &orig, | ||
1703 | TIPC_PORT_IMPORTANCE); | ||
1704 | } | ||
1705 | |||