diff options
author | H. Peter Anvin <hpa@linux.intel.com> | 2014-02-07 14:27:30 -0500 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2014-02-07 14:27:30 -0500 |
commit | a3b072cd180c12e8fe0ece9487b9065808327640 (patch) | |
tree | 62b982041be84748852d77cdf6ca5639ef40858f /net/tipc | |
parent | 75a1ba5b2c529db60ca49626bcaf0bddf4548438 (diff) | |
parent | 081cd62a010f97b5bc1d2b0cd123c5abc692b68a (diff) |
Merge tag 'efi-urgent' into x86/urgent
* Avoid WARN_ON() when mapping BGRT on Baytrail (EFI 32-bit).
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'net/tipc')
-rw-r--r-- | net/tipc/bcast.c | 8 | ||||
-rw-r--r-- | net/tipc/bearer.c | 342 | ||||
-rw-r--r-- | net/tipc/bearer.h | 56 | ||||
-rw-r--r-- | net/tipc/core.c | 8 | ||||
-rw-r--r-- | net/tipc/core.h | 2 | ||||
-rw-r--r-- | net/tipc/discover.c | 28 | ||||
-rw-r--r-- | net/tipc/eth_media.c | 326 | ||||
-rw-r--r-- | net/tipc/ib_media.c | 319 | ||||
-rw-r--r-- | net/tipc/link.c | 222 | ||||
-rw-r--r-- | net/tipc/link.h | 25 | ||||
-rw-r--r-- | net/tipc/name_table.c | 3 | ||||
-rw-r--r-- | net/tipc/node.c | 15 | ||||
-rw-r--r-- | net/tipc/node.h | 3 | ||||
-rw-r--r-- | net/tipc/port.c | 9 | ||||
-rw-r--r-- | net/tipc/server.c | 2 | ||||
-rw-r--r-- | net/tipc/socket.c | 330 | ||||
-rw-r--r-- | net/tipc/subscr.c | 2 |
17 files changed, 607 insertions, 1093 deletions
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c index 0d4402587fdf..bf860d9e75af 100644 --- a/net/tipc/bcast.c +++ b/net/tipc/bcast.c | |||
@@ -621,12 +621,6 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1, | |||
621 | if (!p) | 621 | if (!p) |
622 | break; /* No more bearers to try */ | 622 | break; /* No more bearers to try */ |
623 | 623 | ||
624 | if (tipc_bearer_blocked(p)) { | ||
625 | if (!s || tipc_bearer_blocked(s)) | ||
626 | continue; /* Can't use either bearer */ | ||
627 | b = s; | ||
628 | } | ||
629 | |||
630 | tipc_nmap_diff(&bcbearer->remains, &b->nodes, | 624 | tipc_nmap_diff(&bcbearer->remains, &b->nodes, |
631 | &bcbearer->remains_new); | 625 | &bcbearer->remains_new); |
632 | if (bcbearer->remains_new.count == bcbearer->remains.count) | 626 | if (bcbearer->remains_new.count == bcbearer->remains.count) |
@@ -800,7 +794,7 @@ void tipc_bclink_init(void) | |||
800 | void tipc_bclink_stop(void) | 794 | void tipc_bclink_stop(void) |
801 | { | 795 | { |
802 | spin_lock_bh(&bc_lock); | 796 | spin_lock_bh(&bc_lock); |
803 | tipc_link_stop(bcl); | 797 | tipc_link_purge_queues(bcl); |
804 | spin_unlock_bh(&bc_lock); | 798 | spin_unlock_bh(&bc_lock); |
805 | 799 | ||
806 | memset(bclink, 0, sizeof(*bclink)); | 800 | memset(bclink, 0, sizeof(*bclink)); |
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 3f9707a16d06..a38c89969c68 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
@@ -1,8 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/bearer.c: TIPC bearer code | 2 | * net/tipc/bearer.c: TIPC bearer code |
3 | * | 3 | * |
4 | * Copyright (c) 1996-2006, Ericsson AB | 4 | * Copyright (c) 1996-2006, 2013, Ericsson AB |
5 | * Copyright (c) 2004-2006, 2010-2011, Wind River Systems | 5 | * Copyright (c) 2004-2006, 2010-2013, 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 |
@@ -41,8 +41,13 @@ | |||
41 | 41 | ||
42 | #define MAX_ADDR_STR 60 | 42 | #define MAX_ADDR_STR 60 |
43 | 43 | ||
44 | static struct tipc_media *media_list[MAX_MEDIA]; | 44 | static struct tipc_media * const media_info_array[] = { |
45 | static u32 media_count; | 45 | ð_media_info, |
46 | #ifdef CONFIG_TIPC_MEDIA_IB | ||
47 | &ib_media_info, | ||
48 | #endif | ||
49 | NULL | ||
50 | }; | ||
46 | 51 | ||
47 | struct tipc_bearer tipc_bearers[MAX_BEARERS]; | 52 | struct tipc_bearer tipc_bearers[MAX_BEARERS]; |
48 | 53 | ||
@@ -55,11 +60,11 @@ struct tipc_media *tipc_media_find(const char *name) | |||
55 | { | 60 | { |
56 | u32 i; | 61 | u32 i; |
57 | 62 | ||
58 | for (i = 0; i < media_count; i++) { | 63 | for (i = 0; media_info_array[i] != NULL; i++) { |
59 | if (!strcmp(media_list[i]->name, name)) | 64 | if (!strcmp(media_info_array[i]->name, name)) |
60 | return media_list[i]; | 65 | break; |
61 | } | 66 | } |
62 | return NULL; | 67 | return media_info_array[i]; |
63 | } | 68 | } |
64 | 69 | ||
65 | /** | 70 | /** |
@@ -69,44 +74,11 @@ static struct tipc_media *media_find_id(u8 type) | |||
69 | { | 74 | { |
70 | u32 i; | 75 | u32 i; |
71 | 76 | ||
72 | for (i = 0; i < media_count; i++) { | 77 | for (i = 0; media_info_array[i] != NULL; i++) { |
73 | if (media_list[i]->type_id == type) | 78 | if (media_info_array[i]->type_id == type) |
74 | return media_list[i]; | 79 | break; |
75 | } | 80 | } |
76 | return NULL; | 81 | return media_info_array[i]; |
77 | } | ||
78 | |||
79 | /** | ||
80 | * tipc_register_media - register a media type | ||
81 | * | ||
82 | * Bearers for this media type must be activated separately at a later stage. | ||
83 | */ | ||
84 | int tipc_register_media(struct tipc_media *m_ptr) | ||
85 | { | ||
86 | int res = -EINVAL; | ||
87 | |||
88 | write_lock_bh(&tipc_net_lock); | ||
89 | |||
90 | if ((strlen(m_ptr->name) + 1) > TIPC_MAX_MEDIA_NAME) | ||
91 | goto exit; | ||
92 | if (m_ptr->priority > TIPC_MAX_LINK_PRI) | ||
93 | goto exit; | ||
94 | if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) || | ||
95 | (m_ptr->tolerance > TIPC_MAX_LINK_TOL)) | ||
96 | goto exit; | ||
97 | if (media_count >= MAX_MEDIA) | ||
98 | goto exit; | ||
99 | if (tipc_media_find(m_ptr->name) || media_find_id(m_ptr->type_id)) | ||
100 | goto exit; | ||
101 | |||
102 | media_list[media_count] = m_ptr; | ||
103 | media_count++; | ||
104 | res = 0; | ||
105 | exit: | ||
106 | write_unlock_bh(&tipc_net_lock); | ||
107 | if (res) | ||
108 | pr_warn("Media <%s> registration error\n", m_ptr->name); | ||
109 | return res; | ||
110 | } | 82 | } |
111 | 83 | ||
112 | /** | 84 | /** |
@@ -144,13 +116,11 @@ struct sk_buff *tipc_media_get_names(void) | |||
144 | if (!buf) | 116 | if (!buf) |
145 | return NULL; | 117 | return NULL; |
146 | 118 | ||
147 | read_lock_bh(&tipc_net_lock); | 119 | for (i = 0; media_info_array[i] != NULL; i++) { |
148 | for (i = 0; i < media_count; i++) { | ||
149 | tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, | 120 | tipc_cfg_append_tlv(buf, TIPC_TLV_MEDIA_NAME, |
150 | media_list[i]->name, | 121 | media_info_array[i]->name, |
151 | strlen(media_list[i]->name) + 1); | 122 | strlen(media_info_array[i]->name) + 1); |
152 | } | 123 | } |
153 | read_unlock_bh(&tipc_net_lock); | ||
154 | return buf; | 124 | return buf; |
155 | } | 125 | } |
156 | 126 | ||
@@ -215,31 +185,12 @@ struct tipc_bearer *tipc_bearer_find(const char *name) | |||
215 | } | 185 | } |
216 | 186 | ||
217 | /** | 187 | /** |
218 | * tipc_bearer_find_interface - locates bearer object with matching interface name | ||
219 | */ | ||
220 | struct tipc_bearer *tipc_bearer_find_interface(const char *if_name) | ||
221 | { | ||
222 | struct tipc_bearer *b_ptr; | ||
223 | char *b_if_name; | ||
224 | u32 i; | ||
225 | |||
226 | for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) { | ||
227 | if (!b_ptr->active) | ||
228 | continue; | ||
229 | b_if_name = strchr(b_ptr->name, ':') + 1; | ||
230 | if (!strcmp(b_if_name, if_name)) | ||
231 | return b_ptr; | ||
232 | } | ||
233 | return NULL; | ||
234 | } | ||
235 | |||
236 | /** | ||
237 | * tipc_bearer_get_names - record names of bearers in buffer | 188 | * tipc_bearer_get_names - record names of bearers in buffer |
238 | */ | 189 | */ |
239 | struct sk_buff *tipc_bearer_get_names(void) | 190 | struct sk_buff *tipc_bearer_get_names(void) |
240 | { | 191 | { |
241 | struct sk_buff *buf; | 192 | struct sk_buff *buf; |
242 | struct tipc_bearer *b_ptr; | 193 | struct tipc_bearer *b; |
243 | int i, j; | 194 | int i, j; |
244 | 195 | ||
245 | buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME)); | 196 | buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME)); |
@@ -247,13 +198,13 @@ struct sk_buff *tipc_bearer_get_names(void) | |||
247 | return NULL; | 198 | return NULL; |
248 | 199 | ||
249 | read_lock_bh(&tipc_net_lock); | 200 | read_lock_bh(&tipc_net_lock); |
250 | for (i = 0; i < media_count; i++) { | 201 | for (i = 0; media_info_array[i] != NULL; i++) { |
251 | for (j = 0; j < MAX_BEARERS; j++) { | 202 | for (j = 0; j < MAX_BEARERS; j++) { |
252 | b_ptr = &tipc_bearers[j]; | 203 | b = &tipc_bearers[j]; |
253 | if (b_ptr->active && (b_ptr->media == media_list[i])) { | 204 | if (b->active && (b->media == media_info_array[i])) { |
254 | tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, | 205 | tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME, |
255 | b_ptr->name, | 206 | b->name, |
256 | strlen(b_ptr->name) + 1); | 207 | strlen(b->name) + 1); |
257 | } | 208 | } |
258 | } | 209 | } |
259 | } | 210 | } |
@@ -275,31 +226,6 @@ void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest) | |||
275 | tipc_disc_remove_dest(b_ptr->link_req); | 226 | tipc_disc_remove_dest(b_ptr->link_req); |
276 | } | 227 | } |
277 | 228 | ||
278 | /* | ||
279 | * Interrupt enabling new requests after bearer blocking: | ||
280 | * See bearer_send(). | ||
281 | */ | ||
282 | void tipc_continue(struct tipc_bearer *b) | ||
283 | { | ||
284 | spin_lock_bh(&b->lock); | ||
285 | b->blocked = 0; | ||
286 | spin_unlock_bh(&b->lock); | ||
287 | } | ||
288 | |||
289 | /* | ||
290 | * tipc_bearer_blocked - determines if bearer is currently blocked | ||
291 | */ | ||
292 | int tipc_bearer_blocked(struct tipc_bearer *b) | ||
293 | { | ||
294 | int res; | ||
295 | |||
296 | spin_lock_bh(&b->lock); | ||
297 | res = b->blocked; | ||
298 | spin_unlock_bh(&b->lock); | ||
299 | |||
300 | return res; | ||
301 | } | ||
302 | |||
303 | /** | 229 | /** |
304 | * tipc_enable_bearer - enable bearer with the given name | 230 | * tipc_enable_bearer - enable bearer with the given name |
305 | */ | 231 | */ |
@@ -387,6 +313,7 @@ restart: | |||
387 | 313 | ||
388 | b_ptr = &tipc_bearers[bearer_id]; | 314 | b_ptr = &tipc_bearers[bearer_id]; |
389 | strcpy(b_ptr->name, name); | 315 | strcpy(b_ptr->name, name); |
316 | b_ptr->media = m_ptr; | ||
390 | res = m_ptr->enable_media(b_ptr); | 317 | res = m_ptr->enable_media(b_ptr); |
391 | if (res) { | 318 | if (res) { |
392 | pr_warn("Bearer <%s> rejected, enable failure (%d)\n", | 319 | pr_warn("Bearer <%s> rejected, enable failure (%d)\n", |
@@ -395,7 +322,6 @@ restart: | |||
395 | } | 322 | } |
396 | 323 | ||
397 | b_ptr->identity = bearer_id; | 324 | b_ptr->identity = bearer_id; |
398 | b_ptr->media = m_ptr; | ||
399 | b_ptr->tolerance = m_ptr->tolerance; | 325 | b_ptr->tolerance = m_ptr->tolerance; |
400 | b_ptr->window = m_ptr->window; | 326 | b_ptr->window = m_ptr->window; |
401 | b_ptr->net_plane = bearer_id + 'A'; | 327 | b_ptr->net_plane = bearer_id + 'A'; |
@@ -420,17 +346,16 @@ exit: | |||
420 | } | 346 | } |
421 | 347 | ||
422 | /** | 348 | /** |
423 | * tipc_block_bearer - Block the bearer, and reset all its links | 349 | * tipc_reset_bearer - Reset all links established over this bearer |
424 | */ | 350 | */ |
425 | int tipc_block_bearer(struct tipc_bearer *b_ptr) | 351 | static int tipc_reset_bearer(struct tipc_bearer *b_ptr) |
426 | { | 352 | { |
427 | struct tipc_link *l_ptr; | 353 | struct tipc_link *l_ptr; |
428 | struct tipc_link *temp_l_ptr; | 354 | struct tipc_link *temp_l_ptr; |
429 | 355 | ||
430 | read_lock_bh(&tipc_net_lock); | 356 | read_lock_bh(&tipc_net_lock); |
431 | pr_info("Blocking bearer <%s>\n", b_ptr->name); | 357 | pr_info("Resetting bearer <%s>\n", b_ptr->name); |
432 | spin_lock_bh(&b_ptr->lock); | 358 | spin_lock_bh(&b_ptr->lock); |
433 | b_ptr->blocked = 1; | ||
434 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { | 359 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { |
435 | struct tipc_node *n_ptr = l_ptr->owner; | 360 | struct tipc_node *n_ptr = l_ptr->owner; |
436 | 361 | ||
@@ -456,7 +381,6 @@ static void bearer_disable(struct tipc_bearer *b_ptr) | |||
456 | 381 | ||
457 | pr_info("Disabling bearer <%s>\n", b_ptr->name); | 382 | pr_info("Disabling bearer <%s>\n", b_ptr->name); |
458 | spin_lock_bh(&b_ptr->lock); | 383 | spin_lock_bh(&b_ptr->lock); |
459 | b_ptr->blocked = 1; | ||
460 | b_ptr->media->disable_media(b_ptr); | 384 | b_ptr->media->disable_media(b_ptr); |
461 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { | 385 | list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { |
462 | tipc_link_delete(l_ptr); | 386 | tipc_link_delete(l_ptr); |
@@ -490,6 +414,211 @@ int tipc_disable_bearer(const char *name) | |||
490 | } | 414 | } |
491 | 415 | ||
492 | 416 | ||
417 | /* tipc_l2_media_addr_set - initialize Ethernet media address structure | ||
418 | * | ||
419 | * Media-dependent "value" field stores MAC address in first 6 bytes | ||
420 | * and zeroes out the remaining bytes. | ||
421 | */ | ||
422 | void tipc_l2_media_addr_set(const struct tipc_bearer *b, | ||
423 | struct tipc_media_addr *a, char *mac) | ||
424 | { | ||
425 | int len = b->media->hwaddr_len; | ||
426 | |||
427 | if (unlikely(sizeof(a->value) < len)) { | ||
428 | WARN_ONCE(1, "Media length invalid\n"); | ||
429 | return; | ||
430 | } | ||
431 | |||
432 | memcpy(a->value, mac, len); | ||
433 | memset(a->value + len, 0, sizeof(a->value) - len); | ||
434 | a->media_id = b->media->type_id; | ||
435 | a->broadcast = !memcmp(mac, b->bcast_addr.value, len); | ||
436 | } | ||
437 | |||
438 | int tipc_enable_l2_media(struct tipc_bearer *b) | ||
439 | { | ||
440 | struct net_device *dev; | ||
441 | char *driver_name = strchr((const char *)b->name, ':') + 1; | ||
442 | |||
443 | /* Find device with specified name */ | ||
444 | dev = dev_get_by_name(&init_net, driver_name); | ||
445 | if (!dev) | ||
446 | return -ENODEV; | ||
447 | |||
448 | /* Associate TIPC bearer with Ethernet bearer */ | ||
449 | b->media_ptr = dev; | ||
450 | memset(b->bcast_addr.value, 0, sizeof(b->bcast_addr.value)); | ||
451 | memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len); | ||
452 | b->bcast_addr.media_id = b->media->type_id; | ||
453 | b->bcast_addr.broadcast = 1; | ||
454 | b->mtu = dev->mtu; | ||
455 | tipc_l2_media_addr_set(b, &b->addr, (char *)dev->dev_addr); | ||
456 | rcu_assign_pointer(dev->tipc_ptr, b); | ||
457 | return 0; | ||
458 | } | ||
459 | |||
460 | /* tipc_disable_l2_media - detach TIPC bearer from an Ethernet interface | ||
461 | * | ||
462 | * Mark Ethernet bearer as inactive so that incoming buffers are thrown away, | ||
463 | * then get worker thread to complete bearer cleanup. (Can't do cleanup | ||
464 | * here because cleanup code needs to sleep and caller holds spinlocks.) | ||
465 | */ | ||
466 | void tipc_disable_l2_media(struct tipc_bearer *b) | ||
467 | { | ||
468 | struct net_device *dev = (struct net_device *)b->media_ptr; | ||
469 | RCU_INIT_POINTER(dev->tipc_ptr, NULL); | ||
470 | dev_put(dev); | ||
471 | } | ||
472 | |||
473 | /** | ||
474 | * tipc_l2_send_msg - send a TIPC packet out over an Ethernet interface | ||
475 | * @buf: the packet to be sent | ||
476 | * @b_ptr: the bearer through which the packet is to be sent | ||
477 | * @dest: peer destination address | ||
478 | */ | ||
479 | int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b, | ||
480 | struct tipc_media_addr *dest) | ||
481 | { | ||
482 | struct sk_buff *clone; | ||
483 | int delta; | ||
484 | struct net_device *dev = (struct net_device *)b->media_ptr; | ||
485 | |||
486 | clone = skb_clone(buf, GFP_ATOMIC); | ||
487 | if (!clone) | ||
488 | return 0; | ||
489 | |||
490 | delta = dev->hard_header_len - skb_headroom(buf); | ||
491 | if ((delta > 0) && | ||
492 | pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) { | ||
493 | kfree_skb(clone); | ||
494 | return 0; | ||
495 | } | ||
496 | |||
497 | skb_reset_network_header(clone); | ||
498 | clone->dev = dev; | ||
499 | clone->protocol = htons(ETH_P_TIPC); | ||
500 | dev_hard_header(clone, dev, ETH_P_TIPC, dest->value, | ||
501 | dev->dev_addr, clone->len); | ||
502 | dev_queue_xmit(clone); | ||
503 | return 0; | ||
504 | } | ||
505 | |||
506 | /* tipc_bearer_send- sends buffer to destination over bearer | ||
507 | * | ||
508 | * IMPORTANT: | ||
509 | * The media send routine must not alter the buffer being passed in | ||
510 | * as it may be needed for later retransmission! | ||
511 | */ | ||
512 | void tipc_bearer_send(struct tipc_bearer *b, struct sk_buff *buf, | ||
513 | struct tipc_media_addr *dest) | ||
514 | { | ||
515 | b->media->send_msg(buf, b, dest); | ||
516 | } | ||
517 | |||
518 | /** | ||
519 | * tipc_l2_rcv_msg - handle incoming TIPC message from an interface | ||
520 | * @buf: the received packet | ||
521 | * @dev: the net device that the packet was received on | ||
522 | * @pt: the packet_type structure which was used to register this handler | ||
523 | * @orig_dev: the original receive net device in case the device is a bond | ||
524 | * | ||
525 | * Accept only packets explicitly sent to this node, or broadcast packets; | ||
526 | * ignores packets sent using interface multicast, and traffic sent to other | ||
527 | * nodes (which can happen if interface is running in promiscuous mode). | ||
528 | */ | ||
529 | static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev, | ||
530 | struct packet_type *pt, struct net_device *orig_dev) | ||
531 | { | ||
532 | struct tipc_bearer *b_ptr; | ||
533 | |||
534 | if (!net_eq(dev_net(dev), &init_net)) { | ||
535 | kfree_skb(buf); | ||
536 | return NET_RX_DROP; | ||
537 | } | ||
538 | |||
539 | rcu_read_lock(); | ||
540 | b_ptr = rcu_dereference(dev->tipc_ptr); | ||
541 | if (likely(b_ptr)) { | ||
542 | if (likely(buf->pkt_type <= PACKET_BROADCAST)) { | ||
543 | buf->next = NULL; | ||
544 | tipc_rcv(buf, b_ptr); | ||
545 | rcu_read_unlock(); | ||
546 | return NET_RX_SUCCESS; | ||
547 | } | ||
548 | } | ||
549 | rcu_read_unlock(); | ||
550 | |||
551 | kfree_skb(buf); | ||
552 | return NET_RX_DROP; | ||
553 | } | ||
554 | |||
555 | /** | ||
556 | * tipc_l2_device_event - handle device events from network device | ||
557 | * @nb: the context of the notification | ||
558 | * @evt: the type of event | ||
559 | * @ptr: the net device that the event was on | ||
560 | * | ||
561 | * This function is called by the Ethernet driver in case of link | ||
562 | * change event. | ||
563 | */ | ||
564 | static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, | ||
565 | void *ptr) | ||
566 | { | ||
567 | struct tipc_bearer *b_ptr; | ||
568 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); | ||
569 | |||
570 | if (!net_eq(dev_net(dev), &init_net)) | ||
571 | return NOTIFY_DONE; | ||
572 | |||
573 | rcu_read_lock(); | ||
574 | b_ptr = rcu_dereference(dev->tipc_ptr); | ||
575 | if (!b_ptr) { | ||
576 | rcu_read_unlock(); | ||
577 | return NOTIFY_DONE; | ||
578 | } | ||
579 | |||
580 | b_ptr->mtu = dev->mtu; | ||
581 | |||
582 | switch (evt) { | ||
583 | case NETDEV_CHANGE: | ||
584 | if (netif_carrier_ok(dev)) | ||
585 | break; | ||
586 | case NETDEV_DOWN: | ||
587 | case NETDEV_CHANGEMTU: | ||
588 | case NETDEV_CHANGEADDR: | ||
589 | tipc_reset_bearer(b_ptr); | ||
590 | break; | ||
591 | case NETDEV_UNREGISTER: | ||
592 | case NETDEV_CHANGENAME: | ||
593 | tipc_disable_bearer(b_ptr->name); | ||
594 | break; | ||
595 | } | ||
596 | rcu_read_unlock(); | ||
597 | |||
598 | return NOTIFY_OK; | ||
599 | } | ||
600 | |||
601 | static struct packet_type tipc_packet_type __read_mostly = { | ||
602 | .type = __constant_htons(ETH_P_TIPC), | ||
603 | .func = tipc_l2_rcv_msg, | ||
604 | }; | ||
605 | |||
606 | static struct notifier_block notifier = { | ||
607 | .notifier_call = tipc_l2_device_event, | ||
608 | .priority = 0, | ||
609 | }; | ||
610 | |||
611 | int tipc_bearer_setup(void) | ||
612 | { | ||
613 | dev_add_pack(&tipc_packet_type); | ||
614 | return register_netdevice_notifier(¬ifier); | ||
615 | } | ||
616 | |||
617 | void tipc_bearer_cleanup(void) | ||
618 | { | ||
619 | unregister_netdevice_notifier(¬ifier); | ||
620 | dev_remove_pack(&tipc_packet_type); | ||
621 | } | ||
493 | 622 | ||
494 | void tipc_bearer_stop(void) | 623 | void tipc_bearer_stop(void) |
495 | { | 624 | { |
@@ -499,5 +628,4 @@ void tipc_bearer_stop(void) | |||
499 | if (tipc_bearers[i].active) | 628 | if (tipc_bearers[i].active) |
500 | bearer_disable(&tipc_bearers[i]); | 629 | bearer_disable(&tipc_bearers[i]); |
501 | } | 630 | } |
502 | media_count = 0; | ||
503 | } | 631 | } |
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index e5e04be6fffa..4f5db9ad5bf6 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/bearer.h: Include file for TIPC bearer code | 2 | * net/tipc/bearer.h: Include file for TIPC bearer code |
3 | * | 3 | * |
4 | * Copyright (c) 1996-2006, Ericsson AB | 4 | * Copyright (c) 1996-2006, 2013, Ericsson AB |
5 | * Copyright (c) 2005, 2010-2011, Wind River Systems | 5 | * Copyright (c) 2005, 2010-2011, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
@@ -73,18 +73,18 @@ struct tipc_media_addr { | |||
73 | struct tipc_bearer; | 73 | struct tipc_bearer; |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * struct tipc_media - TIPC media information available to internal users | 76 | * struct tipc_media - Media specific info exposed to generic bearer layer |
77 | * @send_msg: routine which handles buffer transmission | 77 | * @send_msg: routine which handles buffer transmission |
78 | * @enable_media: routine which enables a media | 78 | * @enable_media: routine which enables a media |
79 | * @disable_media: routine which disables a media | 79 | * @disable_media: routine which disables a media |
80 | * @addr2str: routine which converts media address to string | 80 | * @addr2str: routine which converts media address to string |
81 | * @addr2msg: routine which converts media address to protocol message area | 81 | * @addr2msg: routine which converts media address to protocol message area |
82 | * @msg2addr: routine which converts media address from protocol message area | 82 | * @msg2addr: routine which converts media address from protocol message area |
83 | * @bcast_addr: media address used in broadcasting | ||
84 | * @priority: default link (and bearer) priority | 83 | * @priority: default link (and bearer) priority |
85 | * @tolerance: default time (in ms) before declaring link failure | 84 | * @tolerance: default time (in ms) before declaring link failure |
86 | * @window: default window (in packets) before declaring link congestion | 85 | * @window: default window (in packets) before declaring link congestion |
87 | * @type_id: TIPC media identifier | 86 | * @type_id: TIPC media identifier |
87 | * @hwaddr_len: TIPC media address len | ||
88 | * @name: media name | 88 | * @name: media name |
89 | */ | 89 | */ |
90 | struct tipc_media { | 90 | struct tipc_media { |
@@ -101,18 +101,20 @@ struct tipc_media { | |||
101 | u32 tolerance; | 101 | u32 tolerance; |
102 | u32 window; | 102 | u32 window; |
103 | u32 type_id; | 103 | u32 type_id; |
104 | u32 hwaddr_len; | ||
104 | char name[TIPC_MAX_MEDIA_NAME]; | 105 | char name[TIPC_MAX_MEDIA_NAME]; |
105 | }; | 106 | }; |
106 | 107 | ||
107 | /** | 108 | /** |
108 | * struct tipc_bearer - TIPC bearer structure | 109 | * struct tipc_bearer - Generic TIPC bearer structure |
110 | * @dev: ptr to associated network device | ||
109 | * @usr_handle: pointer to additional media-specific information about bearer | 111 | * @usr_handle: pointer to additional media-specific information about bearer |
110 | * @mtu: max packet size bearer can support | 112 | * @mtu: max packet size bearer can support |
111 | * @blocked: non-zero if bearer is blocked | ||
112 | * @lock: spinlock for controlling access to bearer | 113 | * @lock: spinlock for controlling access to bearer |
113 | * @addr: media-specific address associated with bearer | 114 | * @addr: media-specific address associated with bearer |
114 | * @name: bearer name (format = media:interface) | 115 | * @name: bearer name (format = media:interface) |
115 | * @media: ptr to media structure associated with bearer | 116 | * @media: ptr to media structure associated with bearer |
117 | * @bcast_addr: media address used in broadcasting | ||
116 | * @priority: default link priority for bearer | 118 | * @priority: default link priority for bearer |
117 | * @window: default window size for bearer | 119 | * @window: default window size for bearer |
118 | * @tolerance: default link tolerance for bearer | 120 | * @tolerance: default link tolerance for bearer |
@@ -128,9 +130,8 @@ struct tipc_media { | |||
128 | * care of initializing all other fields. | 130 | * care of initializing all other fields. |
129 | */ | 131 | */ |
130 | struct tipc_bearer { | 132 | struct tipc_bearer { |
131 | void *usr_handle; /* initalized by media */ | 133 | void *media_ptr; /* initalized by media */ |
132 | u32 mtu; /* initalized by media */ | 134 | u32 mtu; /* initalized by media */ |
133 | int blocked; /* initalized by media */ | ||
134 | struct tipc_media_addr addr; /* initalized by media */ | 135 | struct tipc_media_addr addr; /* initalized by media */ |
135 | char name[TIPC_MAX_BEARER_NAME]; | 136 | char name[TIPC_MAX_BEARER_NAME]; |
136 | spinlock_t lock; | 137 | spinlock_t lock; |
@@ -159,55 +160,40 @@ extern struct tipc_bearer tipc_bearers[]; | |||
159 | /* | 160 | /* |
160 | * TIPC routines available to supported media types | 161 | * TIPC routines available to supported media types |
161 | */ | 162 | */ |
162 | int tipc_register_media(struct tipc_media *m_ptr); | ||
163 | |||
164 | void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr); | ||
165 | |||
166 | int tipc_block_bearer(struct tipc_bearer *b_ptr); | ||
167 | void tipc_continue(struct tipc_bearer *tb_ptr); | ||
168 | 163 | ||
164 | void tipc_rcv(struct sk_buff *buf, struct tipc_bearer *tb_ptr); | ||
169 | int tipc_enable_bearer(const char *bearer_name, u32 disc_domain, u32 priority); | 165 | int tipc_enable_bearer(const char *bearer_name, u32 disc_domain, u32 priority); |
170 | int tipc_disable_bearer(const char *name); | 166 | int tipc_disable_bearer(const char *name); |
171 | 167 | ||
172 | /* | 168 | /* |
173 | * Routines made available to TIPC by supported media types | 169 | * Routines made available to TIPC by supported media types |
174 | */ | 170 | */ |
175 | int tipc_eth_media_start(void); | 171 | extern struct tipc_media eth_media_info; |
176 | void tipc_eth_media_stop(void); | ||
177 | 172 | ||
178 | #ifdef CONFIG_TIPC_MEDIA_IB | 173 | #ifdef CONFIG_TIPC_MEDIA_IB |
179 | int tipc_ib_media_start(void); | 174 | extern struct tipc_media ib_media_info; |
180 | void tipc_ib_media_stop(void); | ||
181 | #else | ||
182 | static inline int tipc_ib_media_start(void) { return 0; } | ||
183 | static inline void tipc_ib_media_stop(void) { return; } | ||
184 | #endif | 175 | #endif |
185 | 176 | ||
186 | int tipc_media_set_priority(const char *name, u32 new_value); | 177 | int tipc_media_set_priority(const char *name, u32 new_value); |
187 | int tipc_media_set_window(const char *name, u32 new_value); | 178 | int tipc_media_set_window(const char *name, u32 new_value); |
188 | void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); | 179 | void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); |
189 | struct sk_buff *tipc_media_get_names(void); | 180 | struct sk_buff *tipc_media_get_names(void); |
181 | void tipc_l2_media_addr_set(const struct tipc_bearer *b, | ||
182 | struct tipc_media_addr *a, char *mac); | ||
183 | int tipc_enable_l2_media(struct tipc_bearer *b); | ||
184 | void tipc_disable_l2_media(struct tipc_bearer *b); | ||
185 | int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b, | ||
186 | struct tipc_media_addr *dest); | ||
190 | 187 | ||
191 | struct sk_buff *tipc_bearer_get_names(void); | 188 | struct sk_buff *tipc_bearer_get_names(void); |
192 | void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest); | 189 | void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest); |
193 | void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest); | 190 | void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest); |
194 | struct tipc_bearer *tipc_bearer_find(const char *name); | 191 | struct tipc_bearer *tipc_bearer_find(const char *name); |
195 | struct tipc_bearer *tipc_bearer_find_interface(const char *if_name); | ||
196 | struct tipc_media *tipc_media_find(const char *name); | 192 | struct tipc_media *tipc_media_find(const char *name); |
197 | int tipc_bearer_blocked(struct tipc_bearer *b_ptr); | 193 | int tipc_bearer_setup(void); |
194 | void tipc_bearer_cleanup(void); | ||
198 | void tipc_bearer_stop(void); | 195 | void tipc_bearer_stop(void); |
199 | 196 | void tipc_bearer_send(struct tipc_bearer *b, struct sk_buff *buf, | |
200 | /** | 197 | struct tipc_media_addr *dest); |
201 | * tipc_bearer_send- sends buffer to destination over bearer | ||
202 | * | ||
203 | * IMPORTANT: | ||
204 | * The media send routine must not alter the buffer being passed in | ||
205 | * as it may be needed for later retransmission! | ||
206 | */ | ||
207 | static inline void tipc_bearer_send(struct tipc_bearer *b, struct sk_buff *buf, | ||
208 | struct tipc_media_addr *dest) | ||
209 | { | ||
210 | b->media->send_msg(buf, b, dest); | ||
211 | } | ||
212 | 198 | ||
213 | #endif /* _TIPC_BEARER_H */ | 199 | #endif /* _TIPC_BEARER_H */ |
diff --git a/net/tipc/core.c b/net/tipc/core.c index c6d3f75a9e1b..f9e88d8b04ca 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c | |||
@@ -82,8 +82,7 @@ struct sk_buff *tipc_buf_acquire(u32 size) | |||
82 | static void tipc_core_stop_net(void) | 82 | static void tipc_core_stop_net(void) |
83 | { | 83 | { |
84 | tipc_net_stop(); | 84 | tipc_net_stop(); |
85 | tipc_eth_media_stop(); | 85 | tipc_bearer_cleanup(); |
86 | tipc_ib_media_stop(); | ||
87 | } | 86 | } |
88 | 87 | ||
89 | /** | 88 | /** |
@@ -94,10 +93,7 @@ int tipc_core_start_net(unsigned long addr) | |||
94 | int res; | 93 | int res; |
95 | 94 | ||
96 | tipc_net_start(addr); | 95 | tipc_net_start(addr); |
97 | res = tipc_eth_media_start(); | 96 | res = tipc_bearer_setup(); |
98 | if (res < 0) | ||
99 | goto err; | ||
100 | res = tipc_ib_media_start(); | ||
101 | if (res < 0) | 97 | if (res < 0) |
102 | goto err; | 98 | goto err; |
103 | return res; | 99 | return res; |
diff --git a/net/tipc/core.h b/net/tipc/core.h index 94895d4e86ab..1ff477b0450d 100644 --- a/net/tipc/core.h +++ b/net/tipc/core.h | |||
@@ -47,7 +47,7 @@ | |||
47 | #include <linux/mm.h> | 47 | #include <linux/mm.h> |
48 | #include <linux/timer.h> | 48 | #include <linux/timer.h> |
49 | #include <linux/string.h> | 49 | #include <linux/string.h> |
50 | #include <asm/uaccess.h> | 50 | #include <linux/uaccess.h> |
51 | #include <linux/interrupt.h> | 51 | #include <linux/interrupt.h> |
52 | #include <linux/atomic.h> | 52 | #include <linux/atomic.h> |
53 | #include <asm/hardirq.h> | 53 | #include <asm/hardirq.h> |
diff --git a/net/tipc/discover.c b/net/tipc/discover.c index ecc758c6eacf..412ff41b8611 100644 --- a/net/tipc/discover.c +++ b/net/tipc/discover.c | |||
@@ -50,6 +50,7 @@ | |||
50 | * @dest: destination address for request messages | 50 | * @dest: destination address for request messages |
51 | * @domain: network domain to which links can be established | 51 | * @domain: network domain to which links can be established |
52 | * @num_nodes: number of nodes currently discovered (i.e. with an active link) | 52 | * @num_nodes: number of nodes currently discovered (i.e. with an active link) |
53 | * @lock: spinlock for controlling access to requests | ||
53 | * @buf: request message to be (repeatedly) sent | 54 | * @buf: request message to be (repeatedly) sent |
54 | * @timer: timer governing period between requests | 55 | * @timer: timer governing period between requests |
55 | * @timer_intv: current interval between requests (in ms) | 56 | * @timer_intv: current interval between requests (in ms) |
@@ -59,6 +60,7 @@ struct tipc_link_req { | |||
59 | struct tipc_media_addr dest; | 60 | struct tipc_media_addr dest; |
60 | u32 domain; | 61 | u32 domain; |
61 | int num_nodes; | 62 | int num_nodes; |
63 | spinlock_t lock; | ||
62 | struct sk_buff *buf; | 64 | struct sk_buff *buf; |
63 | struct timer_list timer; | 65 | struct timer_list timer; |
64 | unsigned int timer_intv; | 66 | unsigned int timer_intv; |
@@ -239,7 +241,7 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr) | |||
239 | /* Accept discovery message & send response, if necessary */ | 241 | /* Accept discovery message & send response, if necessary */ |
240 | link_fully_up = link_working_working(link); | 242 | link_fully_up = link_working_working(link); |
241 | 243 | ||
242 | if ((type == DSC_REQ_MSG) && !link_fully_up && !b_ptr->blocked) { | 244 | if ((type == DSC_REQ_MSG) && !link_fully_up) { |
243 | rbuf = tipc_disc_init_msg(DSC_RESP_MSG, orig, b_ptr); | 245 | rbuf = tipc_disc_init_msg(DSC_RESP_MSG, orig, b_ptr); |
244 | if (rbuf) { | 246 | if (rbuf) { |
245 | tipc_bearer_send(b_ptr, rbuf, &media_addr); | 247 | tipc_bearer_send(b_ptr, rbuf, &media_addr); |
@@ -274,7 +276,9 @@ static void disc_update(struct tipc_link_req *req) | |||
274 | */ | 276 | */ |
275 | void tipc_disc_add_dest(struct tipc_link_req *req) | 277 | void tipc_disc_add_dest(struct tipc_link_req *req) |
276 | { | 278 | { |
279 | spin_lock_bh(&req->lock); | ||
277 | req->num_nodes++; | 280 | req->num_nodes++; |
281 | spin_unlock_bh(&req->lock); | ||
278 | } | 282 | } |
279 | 283 | ||
280 | /** | 284 | /** |
@@ -283,18 +287,10 @@ void tipc_disc_add_dest(struct tipc_link_req *req) | |||
283 | */ | 287 | */ |
284 | void tipc_disc_remove_dest(struct tipc_link_req *req) | 288 | void tipc_disc_remove_dest(struct tipc_link_req *req) |
285 | { | 289 | { |
290 | spin_lock_bh(&req->lock); | ||
286 | req->num_nodes--; | 291 | req->num_nodes--; |
287 | disc_update(req); | 292 | disc_update(req); |
288 | } | 293 | spin_unlock_bh(&req->lock); |
289 | |||
290 | /** | ||
291 | * disc_send_msg - send link setup request message | ||
292 | * @req: ptr to link request structure | ||
293 | */ | ||
294 | static void disc_send_msg(struct tipc_link_req *req) | ||
295 | { | ||
296 | if (!req->bearer->blocked) | ||
297 | tipc_bearer_send(req->bearer, req->buf, &req->dest); | ||
298 | } | 294 | } |
299 | 295 | ||
300 | /** | 296 | /** |
@@ -307,7 +303,7 @@ static void disc_timeout(struct tipc_link_req *req) | |||
307 | { | 303 | { |
308 | int max_delay; | 304 | int max_delay; |
309 | 305 | ||
310 | spin_lock_bh(&req->bearer->lock); | 306 | spin_lock_bh(&req->lock); |
311 | 307 | ||
312 | /* Stop searching if only desired node has been found */ | 308 | /* Stop searching if only desired node has been found */ |
313 | if (tipc_node(req->domain) && req->num_nodes) { | 309 | if (tipc_node(req->domain) && req->num_nodes) { |
@@ -322,7 +318,8 @@ static void disc_timeout(struct tipc_link_req *req) | |||
322 | * hold at fast polling rate if don't have any associated nodes, | 318 | * hold at fast polling rate if don't have any associated nodes, |
323 | * otherwise hold at slow polling rate | 319 | * otherwise hold at slow polling rate |
324 | */ | 320 | */ |
325 | disc_send_msg(req); | 321 | tipc_bearer_send(req->bearer, req->buf, &req->dest); |
322 | |||
326 | 323 | ||
327 | req->timer_intv *= 2; | 324 | req->timer_intv *= 2; |
328 | if (req->num_nodes) | 325 | if (req->num_nodes) |
@@ -334,7 +331,7 @@ static void disc_timeout(struct tipc_link_req *req) | |||
334 | 331 | ||
335 | k_start_timer(&req->timer, req->timer_intv); | 332 | k_start_timer(&req->timer, req->timer_intv); |
336 | exit: | 333 | exit: |
337 | spin_unlock_bh(&req->bearer->lock); | 334 | spin_unlock_bh(&req->lock); |
338 | } | 335 | } |
339 | 336 | ||
340 | /** | 337 | /** |
@@ -365,10 +362,11 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest, | |||
365 | req->domain = dest_domain; | 362 | req->domain = dest_domain; |
366 | req->num_nodes = 0; | 363 | req->num_nodes = 0; |
367 | req->timer_intv = TIPC_LINK_REQ_INIT; | 364 | req->timer_intv = TIPC_LINK_REQ_INIT; |
365 | spin_lock_init(&req->lock); | ||
368 | k_init_timer(&req->timer, (Handler)disc_timeout, (unsigned long)req); | 366 | k_init_timer(&req->timer, (Handler)disc_timeout, (unsigned long)req); |
369 | k_start_timer(&req->timer, req->timer_intv); | 367 | k_start_timer(&req->timer, req->timer_intv); |
370 | b_ptr->link_req = req; | 368 | b_ptr->link_req = req; |
371 | disc_send_msg(req); | 369 | tipc_bearer_send(req->bearer, req->buf, &req->dest); |
372 | return 0; | 370 | return 0; |
373 | } | 371 | } |
374 | 372 | ||
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c index f80d59f5a161..67cf3f935dba 100644 --- a/net/tipc/eth_media.c +++ b/net/tipc/eth_media.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/eth_media.c: Ethernet bearer support for TIPC | 2 | * net/tipc/eth_media.c: Ethernet bearer support for TIPC |
3 | * | 3 | * |
4 | * Copyright (c) 2001-2007, Ericsson AB | 4 | * Copyright (c) 2001-2007, 2013, Ericsson AB |
5 | * Copyright (c) 2005-2008, 2011-2013, Wind River Systems | 5 | * Copyright (c) 2005-2008, 2011-2013, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
@@ -37,259 +37,11 @@ | |||
37 | #include "core.h" | 37 | #include "core.h" |
38 | #include "bearer.h" | 38 | #include "bearer.h" |
39 | 39 | ||
40 | #define MAX_ETH_MEDIA MAX_BEARERS | ||
41 | |||
42 | #define ETH_ADDR_OFFSET 4 /* message header offset of MAC address */ | 40 | #define ETH_ADDR_OFFSET 4 /* message header offset of MAC address */ |
43 | 41 | ||
44 | /** | 42 | /* convert Ethernet address to string */ |
45 | * struct eth_media - Ethernet bearer data structure | 43 | static int tipc_eth_addr2str(struct tipc_media_addr *a, char *str_buf, |
46 | * @bearer: ptr to associated "generic" bearer structure | 44 | int str_size) |
47 | * @dev: ptr to associated Ethernet network device | ||
48 | * @tipc_packet_type: used in binding TIPC to Ethernet driver | ||
49 | * @setup: work item used when enabling bearer | ||
50 | * @cleanup: work item used when disabling bearer | ||
51 | */ | ||
52 | struct eth_media { | ||
53 | struct tipc_bearer *bearer; | ||
54 | struct net_device *dev; | ||
55 | struct packet_type tipc_packet_type; | ||
56 | struct work_struct setup; | ||
57 | struct work_struct cleanup; | ||
58 | }; | ||
59 | |||
60 | static struct tipc_media eth_media_info; | ||
61 | static struct eth_media eth_media_array[MAX_ETH_MEDIA]; | ||
62 | static int eth_started; | ||
63 | |||
64 | static int recv_notification(struct notifier_block *nb, unsigned long evt, | ||
65 | void *dv); | ||
66 | /* | ||
67 | * Network device notifier info | ||
68 | */ | ||
69 | static struct notifier_block notifier = { | ||
70 | .notifier_call = recv_notification, | ||
71 | .priority = 0 | ||
72 | }; | ||
73 | |||
74 | /** | ||
75 | * eth_media_addr_set - initialize Ethernet media address structure | ||
76 | * | ||
77 | * Media-dependent "value" field stores MAC address in first 6 bytes | ||
78 | * and zeroes out the remaining bytes. | ||
79 | */ | ||
80 | static void eth_media_addr_set(const struct tipc_bearer *tb_ptr, | ||
81 | struct tipc_media_addr *a, char *mac) | ||
82 | { | ||
83 | memcpy(a->value, mac, ETH_ALEN); | ||
84 | memset(a->value + ETH_ALEN, 0, sizeof(a->value) - ETH_ALEN); | ||
85 | a->media_id = TIPC_MEDIA_TYPE_ETH; | ||
86 | a->broadcast = !memcmp(mac, tb_ptr->bcast_addr.value, ETH_ALEN); | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * send_msg - send a TIPC message out over an Ethernet interface | ||
91 | */ | ||
92 | static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr, | ||
93 | struct tipc_media_addr *dest) | ||
94 | { | ||
95 | struct sk_buff *clone; | ||
96 | struct net_device *dev; | ||
97 | int delta; | ||
98 | |||
99 | clone = skb_clone(buf, GFP_ATOMIC); | ||
100 | if (!clone) | ||
101 | return 0; | ||
102 | |||
103 | dev = ((struct eth_media *)(tb_ptr->usr_handle))->dev; | ||
104 | delta = dev->hard_header_len - skb_headroom(buf); | ||
105 | |||
106 | if ((delta > 0) && | ||
107 | pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) { | ||
108 | kfree_skb(clone); | ||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | skb_reset_network_header(clone); | ||
113 | clone->dev = dev; | ||
114 | clone->protocol = htons(ETH_P_TIPC); | ||
115 | dev_hard_header(clone, dev, ETH_P_TIPC, dest->value, | ||
116 | dev->dev_addr, clone->len); | ||
117 | dev_queue_xmit(clone); | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | /** | ||
122 | * recv_msg - handle incoming TIPC message from an Ethernet interface | ||
123 | * | ||
124 | * Accept only packets explicitly sent to this node, or broadcast packets; | ||
125 | * ignores packets sent using Ethernet multicast, and traffic sent to other | ||
126 | * nodes (which can happen if interface is running in promiscuous mode). | ||
127 | */ | ||
128 | static int recv_msg(struct sk_buff *buf, struct net_device *dev, | ||
129 | struct packet_type *pt, struct net_device *orig_dev) | ||
130 | { | ||
131 | struct eth_media *eb_ptr = (struct eth_media *)pt->af_packet_priv; | ||
132 | |||
133 | if (!net_eq(dev_net(dev), &init_net)) { | ||
134 | kfree_skb(buf); | ||
135 | return NET_RX_DROP; | ||
136 | } | ||
137 | |||
138 | if (likely(eb_ptr->bearer)) { | ||
139 | if (likely(buf->pkt_type <= PACKET_BROADCAST)) { | ||
140 | buf->next = NULL; | ||
141 | tipc_recv_msg(buf, eb_ptr->bearer); | ||
142 | return NET_RX_SUCCESS; | ||
143 | } | ||
144 | } | ||
145 | kfree_skb(buf); | ||
146 | return NET_RX_DROP; | ||
147 | } | ||
148 | |||
149 | /** | ||
150 | * setup_media - setup association between Ethernet bearer and interface | ||
151 | */ | ||
152 | static void setup_media(struct work_struct *work) | ||
153 | { | ||
154 | struct eth_media *eb_ptr = | ||
155 | container_of(work, struct eth_media, setup); | ||
156 | |||
157 | dev_add_pack(&eb_ptr->tipc_packet_type); | ||
158 | } | ||
159 | |||
160 | /** | ||
161 | * enable_media - attach TIPC bearer to an Ethernet interface | ||
162 | */ | ||
163 | static int enable_media(struct tipc_bearer *tb_ptr) | ||
164 | { | ||
165 | struct net_device *dev; | ||
166 | struct eth_media *eb_ptr = ð_media_array[0]; | ||
167 | struct eth_media *stop = ð_media_array[MAX_ETH_MEDIA]; | ||
168 | char *driver_name = strchr((const char *)tb_ptr->name, ':') + 1; | ||
169 | int pending_dev = 0; | ||
170 | |||
171 | /* Find unused Ethernet bearer structure */ | ||
172 | while (eb_ptr->dev) { | ||
173 | if (!eb_ptr->bearer) | ||
174 | pending_dev++; | ||
175 | if (++eb_ptr == stop) | ||
176 | return pending_dev ? -EAGAIN : -EDQUOT; | ||
177 | } | ||
178 | |||
179 | /* Find device with specified name */ | ||
180 | dev = dev_get_by_name(&init_net, driver_name); | ||
181 | if (!dev) | ||
182 | return -ENODEV; | ||
183 | |||
184 | /* Create Ethernet bearer for device */ | ||
185 | eb_ptr->dev = dev; | ||
186 | eb_ptr->tipc_packet_type.type = htons(ETH_P_TIPC); | ||
187 | eb_ptr->tipc_packet_type.dev = dev; | ||
188 | eb_ptr->tipc_packet_type.func = recv_msg; | ||
189 | eb_ptr->tipc_packet_type.af_packet_priv = eb_ptr; | ||
190 | INIT_LIST_HEAD(&(eb_ptr->tipc_packet_type.list)); | ||
191 | INIT_WORK(&eb_ptr->setup, setup_media); | ||
192 | schedule_work(&eb_ptr->setup); | ||
193 | |||
194 | /* Associate TIPC bearer with Ethernet bearer */ | ||
195 | eb_ptr->bearer = tb_ptr; | ||
196 | tb_ptr->usr_handle = (void *)eb_ptr; | ||
197 | memset(tb_ptr->bcast_addr.value, 0, sizeof(tb_ptr->bcast_addr.value)); | ||
198 | memcpy(tb_ptr->bcast_addr.value, dev->broadcast, ETH_ALEN); | ||
199 | tb_ptr->bcast_addr.media_id = TIPC_MEDIA_TYPE_ETH; | ||
200 | tb_ptr->bcast_addr.broadcast = 1; | ||
201 | tb_ptr->mtu = dev->mtu; | ||
202 | tb_ptr->blocked = 0; | ||
203 | eth_media_addr_set(tb_ptr, &tb_ptr->addr, (char *)dev->dev_addr); | ||
204 | return 0; | ||
205 | } | ||
206 | |||
207 | /** | ||
208 | * cleanup_media - break association between Ethernet bearer and interface | ||
209 | * | ||
210 | * This routine must be invoked from a work queue because it can sleep. | ||
211 | */ | ||
212 | static void cleanup_media(struct work_struct *work) | ||
213 | { | ||
214 | struct eth_media *eb_ptr = | ||
215 | container_of(work, struct eth_media, cleanup); | ||
216 | |||
217 | dev_remove_pack(&eb_ptr->tipc_packet_type); | ||
218 | dev_put(eb_ptr->dev); | ||
219 | eb_ptr->dev = NULL; | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * disable_media - detach TIPC bearer from an Ethernet interface | ||
224 | * | ||
225 | * Mark Ethernet bearer as inactive so that incoming buffers are thrown away, | ||
226 | * then get worker thread to complete bearer cleanup. (Can't do cleanup | ||
227 | * here because cleanup code needs to sleep and caller holds spinlocks.) | ||
228 | */ | ||
229 | static void disable_media(struct tipc_bearer *tb_ptr) | ||
230 | { | ||
231 | struct eth_media *eb_ptr = (struct eth_media *)tb_ptr->usr_handle; | ||
232 | |||
233 | eb_ptr->bearer = NULL; | ||
234 | INIT_WORK(&eb_ptr->cleanup, cleanup_media); | ||
235 | schedule_work(&eb_ptr->cleanup); | ||
236 | } | ||
237 | |||
238 | /** | ||
239 | * recv_notification - handle device updates from OS | ||
240 | * | ||
241 | * Change the state of the Ethernet bearer (if any) associated with the | ||
242 | * specified device. | ||
243 | */ | ||
244 | static int recv_notification(struct notifier_block *nb, unsigned long evt, | ||
245 | void *ptr) | ||
246 | { | ||
247 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); | ||
248 | struct eth_media *eb_ptr = ð_media_array[0]; | ||
249 | struct eth_media *stop = ð_media_array[MAX_ETH_MEDIA]; | ||
250 | |||
251 | if (!net_eq(dev_net(dev), &init_net)) | ||
252 | return NOTIFY_DONE; | ||
253 | |||
254 | while ((eb_ptr->dev != dev)) { | ||
255 | if (++eb_ptr == stop) | ||
256 | return NOTIFY_DONE; /* couldn't find device */ | ||
257 | } | ||
258 | if (!eb_ptr->bearer) | ||
259 | return NOTIFY_DONE; /* bearer had been disabled */ | ||
260 | |||
261 | eb_ptr->bearer->mtu = dev->mtu; | ||
262 | |||
263 | switch (evt) { | ||
264 | case NETDEV_CHANGE: | ||
265 | if (netif_carrier_ok(dev)) | ||
266 | tipc_continue(eb_ptr->bearer); | ||
267 | else | ||
268 | tipc_block_bearer(eb_ptr->bearer); | ||
269 | break; | ||
270 | case NETDEV_UP: | ||
271 | tipc_continue(eb_ptr->bearer); | ||
272 | break; | ||
273 | case NETDEV_DOWN: | ||
274 | tipc_block_bearer(eb_ptr->bearer); | ||
275 | break; | ||
276 | case NETDEV_CHANGEMTU: | ||
277 | case NETDEV_CHANGEADDR: | ||
278 | tipc_block_bearer(eb_ptr->bearer); | ||
279 | tipc_continue(eb_ptr->bearer); | ||
280 | break; | ||
281 | case NETDEV_UNREGISTER: | ||
282 | case NETDEV_CHANGENAME: | ||
283 | tipc_disable_bearer(eb_ptr->bearer->name); | ||
284 | break; | ||
285 | } | ||
286 | return NOTIFY_OK; | ||
287 | } | ||
288 | |||
289 | /** | ||
290 | * eth_addr2str - convert Ethernet address to string | ||
291 | */ | ||
292 | static int eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size) | ||
293 | { | 45 | { |
294 | if (str_size < 18) /* 18 = strlen("aa:bb:cc:dd:ee:ff\0") */ | 46 | if (str_size < 18) /* 18 = strlen("aa:bb:cc:dd:ee:ff\0") */ |
295 | return 1; | 47 | return 1; |
@@ -298,10 +50,8 @@ static int eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size) | |||
298 | return 0; | 50 | return 0; |
299 | } | 51 | } |
300 | 52 | ||
301 | /** | 53 | /* convert Ethernet address format to message header format */ |
302 | * eth_str2addr - convert Ethernet address format to message header format | 54 | static int tipc_eth_addr2msg(struct tipc_media_addr *a, char *msg_area) |
303 | */ | ||
304 | static int eth_addr2msg(struct tipc_media_addr *a, char *msg_area) | ||
305 | { | 55 | { |
306 | memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE); | 56 | memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE); |
307 | msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_ETH; | 57 | msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_ETH; |
@@ -309,68 +59,30 @@ static int eth_addr2msg(struct tipc_media_addr *a, char *msg_area) | |||
309 | return 0; | 59 | return 0; |
310 | } | 60 | } |
311 | 61 | ||
312 | /** | 62 | /* convert message header address format to Ethernet format */ |
313 | * eth_str2addr - convert message header address format to Ethernet format | 63 | static int tipc_eth_msg2addr(const struct tipc_bearer *tb_ptr, |
314 | */ | 64 | struct tipc_media_addr *a, char *msg_area) |
315 | static int eth_msg2addr(const struct tipc_bearer *tb_ptr, | ||
316 | struct tipc_media_addr *a, char *msg_area) | ||
317 | { | 65 | { |
318 | if (msg_area[TIPC_MEDIA_TYPE_OFFSET] != TIPC_MEDIA_TYPE_ETH) | 66 | if (msg_area[TIPC_MEDIA_TYPE_OFFSET] != TIPC_MEDIA_TYPE_ETH) |
319 | return 1; | 67 | return 1; |
320 | 68 | ||
321 | eth_media_addr_set(tb_ptr, a, msg_area + ETH_ADDR_OFFSET); | 69 | tipc_l2_media_addr_set(tb_ptr, a, msg_area + ETH_ADDR_OFFSET); |
322 | return 0; | 70 | return 0; |
323 | } | 71 | } |
324 | 72 | ||
325 | /* | 73 | /* Ethernet media registration info */ |
326 | * Ethernet media registration info | 74 | struct tipc_media eth_media_info = { |
327 | */ | 75 | .send_msg = tipc_l2_send_msg, |
328 | static struct tipc_media eth_media_info = { | 76 | .enable_media = tipc_enable_l2_media, |
329 | .send_msg = send_msg, | 77 | .disable_media = tipc_disable_l2_media, |
330 | .enable_media = enable_media, | 78 | .addr2str = tipc_eth_addr2str, |
331 | .disable_media = disable_media, | 79 | .addr2msg = tipc_eth_addr2msg, |
332 | .addr2str = eth_addr2str, | 80 | .msg2addr = tipc_eth_msg2addr, |
333 | .addr2msg = eth_addr2msg, | ||
334 | .msg2addr = eth_msg2addr, | ||
335 | .priority = TIPC_DEF_LINK_PRI, | 81 | .priority = TIPC_DEF_LINK_PRI, |
336 | .tolerance = TIPC_DEF_LINK_TOL, | 82 | .tolerance = TIPC_DEF_LINK_TOL, |
337 | .window = TIPC_DEF_LINK_WIN, | 83 | .window = TIPC_DEF_LINK_WIN, |
338 | .type_id = TIPC_MEDIA_TYPE_ETH, | 84 | .type_id = TIPC_MEDIA_TYPE_ETH, |
85 | .hwaddr_len = ETH_ALEN, | ||
339 | .name = "eth" | 86 | .name = "eth" |
340 | }; | 87 | }; |
341 | 88 | ||
342 | /** | ||
343 | * tipc_eth_media_start - activate Ethernet bearer support | ||
344 | * | ||
345 | * Register Ethernet media type with TIPC bearer code. Also register | ||
346 | * with OS for notifications about device state changes. | ||
347 | */ | ||
348 | int tipc_eth_media_start(void) | ||
349 | { | ||
350 | int res; | ||
351 | |||
352 | if (eth_started) | ||
353 | return -EINVAL; | ||
354 | |||
355 | res = tipc_register_media(ð_media_info); | ||
356 | if (res) | ||
357 | return res; | ||
358 | |||
359 | res = register_netdevice_notifier(¬ifier); | ||
360 | if (!res) | ||
361 | eth_started = 1; | ||
362 | return res; | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * tipc_eth_media_stop - deactivate Ethernet bearer support | ||
367 | */ | ||
368 | void tipc_eth_media_stop(void) | ||
369 | { | ||
370 | if (!eth_started) | ||
371 | return; | ||
372 | |||
373 | flush_scheduled_work(); | ||
374 | unregister_netdevice_notifier(¬ifier); | ||
375 | eth_started = 0; | ||
376 | } | ||
diff --git a/net/tipc/ib_media.c b/net/tipc/ib_media.c index c13989297464..844a77e25828 100644 --- a/net/tipc/ib_media.c +++ b/net/tipc/ib_media.c | |||
@@ -42,252 +42,9 @@ | |||
42 | #include "core.h" | 42 | #include "core.h" |
43 | #include "bearer.h" | 43 | #include "bearer.h" |
44 | 44 | ||
45 | #define MAX_IB_MEDIA MAX_BEARERS | 45 | /* convert InfiniBand address to string */ |
46 | 46 | static int tipc_ib_addr2str(struct tipc_media_addr *a, char *str_buf, | |
47 | /** | 47 | int str_size) |
48 | * struct ib_media - Infiniband media data structure | ||
49 | * @bearer: ptr to associated "generic" bearer structure | ||
50 | * @dev: ptr to associated Infiniband network device | ||
51 | * @tipc_packet_type: used in binding TIPC to Infiniband driver | ||
52 | * @cleanup: work item used when disabling bearer | ||
53 | */ | ||
54 | |||
55 | struct ib_media { | ||
56 | struct tipc_bearer *bearer; | ||
57 | struct net_device *dev; | ||
58 | struct packet_type tipc_packet_type; | ||
59 | struct work_struct setup; | ||
60 | struct work_struct cleanup; | ||
61 | }; | ||
62 | |||
63 | static struct tipc_media ib_media_info; | ||
64 | static struct ib_media ib_media_array[MAX_IB_MEDIA]; | ||
65 | static int ib_started; | ||
66 | |||
67 | /** | ||
68 | * ib_media_addr_set - initialize Infiniband media address structure | ||
69 | * | ||
70 | * Media-dependent "value" field stores MAC address in first 6 bytes | ||
71 | * and zeroes out the remaining bytes. | ||
72 | */ | ||
73 | static void ib_media_addr_set(const struct tipc_bearer *tb_ptr, | ||
74 | struct tipc_media_addr *a, char *mac) | ||
75 | { | ||
76 | BUILD_BUG_ON(sizeof(a->value) < INFINIBAND_ALEN); | ||
77 | memcpy(a->value, mac, INFINIBAND_ALEN); | ||
78 | a->media_id = TIPC_MEDIA_TYPE_IB; | ||
79 | a->broadcast = !memcmp(mac, tb_ptr->bcast_addr.value, INFINIBAND_ALEN); | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * send_msg - send a TIPC message out over an InfiniBand interface | ||
84 | */ | ||
85 | static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr, | ||
86 | struct tipc_media_addr *dest) | ||
87 | { | ||
88 | struct sk_buff *clone; | ||
89 | struct net_device *dev; | ||
90 | int delta; | ||
91 | |||
92 | clone = skb_clone(buf, GFP_ATOMIC); | ||
93 | if (!clone) | ||
94 | return 0; | ||
95 | |||
96 | dev = ((struct ib_media *)(tb_ptr->usr_handle))->dev; | ||
97 | delta = dev->hard_header_len - skb_headroom(buf); | ||
98 | |||
99 | if ((delta > 0) && | ||
100 | pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) { | ||
101 | kfree_skb(clone); | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | skb_reset_network_header(clone); | ||
106 | clone->dev = dev; | ||
107 | clone->protocol = htons(ETH_P_TIPC); | ||
108 | dev_hard_header(clone, dev, ETH_P_TIPC, dest->value, | ||
109 | dev->dev_addr, clone->len); | ||
110 | dev_queue_xmit(clone); | ||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * recv_msg - handle incoming TIPC message from an InfiniBand interface | ||
116 | * | ||
117 | * Accept only packets explicitly sent to this node, or broadcast packets; | ||
118 | * ignores packets sent using InfiniBand multicast, and traffic sent to other | ||
119 | * nodes (which can happen if interface is running in promiscuous mode). | ||
120 | */ | ||
121 | static int recv_msg(struct sk_buff *buf, struct net_device *dev, | ||
122 | struct packet_type *pt, struct net_device *orig_dev) | ||
123 | { | ||
124 | struct ib_media *ib_ptr = (struct ib_media *)pt->af_packet_priv; | ||
125 | |||
126 | if (!net_eq(dev_net(dev), &init_net)) { | ||
127 | kfree_skb(buf); | ||
128 | return NET_RX_DROP; | ||
129 | } | ||
130 | |||
131 | if (likely(ib_ptr->bearer)) { | ||
132 | if (likely(buf->pkt_type <= PACKET_BROADCAST)) { | ||
133 | buf->next = NULL; | ||
134 | tipc_recv_msg(buf, ib_ptr->bearer); | ||
135 | return NET_RX_SUCCESS; | ||
136 | } | ||
137 | } | ||
138 | kfree_skb(buf); | ||
139 | return NET_RX_DROP; | ||
140 | } | ||
141 | |||
142 | /** | ||
143 | * setup_bearer - setup association between InfiniBand bearer and interface | ||
144 | */ | ||
145 | static void setup_media(struct work_struct *work) | ||
146 | { | ||
147 | struct ib_media *ib_ptr = | ||
148 | container_of(work, struct ib_media, setup); | ||
149 | |||
150 | dev_add_pack(&ib_ptr->tipc_packet_type); | ||
151 | } | ||
152 | |||
153 | /** | ||
154 | * enable_media - attach TIPC bearer to an InfiniBand interface | ||
155 | */ | ||
156 | static int enable_media(struct tipc_bearer *tb_ptr) | ||
157 | { | ||
158 | struct net_device *dev; | ||
159 | struct ib_media *ib_ptr = &ib_media_array[0]; | ||
160 | struct ib_media *stop = &ib_media_array[MAX_IB_MEDIA]; | ||
161 | char *driver_name = strchr((const char *)tb_ptr->name, ':') + 1; | ||
162 | int pending_dev = 0; | ||
163 | |||
164 | /* Find unused InfiniBand bearer structure */ | ||
165 | while (ib_ptr->dev) { | ||
166 | if (!ib_ptr->bearer) | ||
167 | pending_dev++; | ||
168 | if (++ib_ptr == stop) | ||
169 | return pending_dev ? -EAGAIN : -EDQUOT; | ||
170 | } | ||
171 | |||
172 | /* Find device with specified name */ | ||
173 | dev = dev_get_by_name(&init_net, driver_name); | ||
174 | if (!dev) | ||
175 | return -ENODEV; | ||
176 | |||
177 | /* Create InfiniBand bearer for device */ | ||
178 | ib_ptr->dev = dev; | ||
179 | ib_ptr->tipc_packet_type.type = htons(ETH_P_TIPC); | ||
180 | ib_ptr->tipc_packet_type.dev = dev; | ||
181 | ib_ptr->tipc_packet_type.func = recv_msg; | ||
182 | ib_ptr->tipc_packet_type.af_packet_priv = ib_ptr; | ||
183 | INIT_LIST_HEAD(&(ib_ptr->tipc_packet_type.list)); | ||
184 | INIT_WORK(&ib_ptr->setup, setup_media); | ||
185 | schedule_work(&ib_ptr->setup); | ||
186 | |||
187 | /* Associate TIPC bearer with InfiniBand bearer */ | ||
188 | ib_ptr->bearer = tb_ptr; | ||
189 | tb_ptr->usr_handle = (void *)ib_ptr; | ||
190 | memset(tb_ptr->bcast_addr.value, 0, sizeof(tb_ptr->bcast_addr.value)); | ||
191 | memcpy(tb_ptr->bcast_addr.value, dev->broadcast, INFINIBAND_ALEN); | ||
192 | tb_ptr->bcast_addr.media_id = TIPC_MEDIA_TYPE_IB; | ||
193 | tb_ptr->bcast_addr.broadcast = 1; | ||
194 | tb_ptr->mtu = dev->mtu; | ||
195 | tb_ptr->blocked = 0; | ||
196 | ib_media_addr_set(tb_ptr, &tb_ptr->addr, (char *)dev->dev_addr); | ||
197 | return 0; | ||
198 | } | ||
199 | |||
200 | /** | ||
201 | * cleanup_bearer - break association between InfiniBand bearer and interface | ||
202 | * | ||
203 | * This routine must be invoked from a work queue because it can sleep. | ||
204 | */ | ||
205 | static void cleanup_bearer(struct work_struct *work) | ||
206 | { | ||
207 | struct ib_media *ib_ptr = | ||
208 | container_of(work, struct ib_media, cleanup); | ||
209 | |||
210 | dev_remove_pack(&ib_ptr->tipc_packet_type); | ||
211 | dev_put(ib_ptr->dev); | ||
212 | ib_ptr->dev = NULL; | ||
213 | } | ||
214 | |||
215 | /** | ||
216 | * disable_media - detach TIPC bearer from an InfiniBand interface | ||
217 | * | ||
218 | * Mark InfiniBand bearer as inactive so that incoming buffers are thrown away, | ||
219 | * then get worker thread to complete bearer cleanup. (Can't do cleanup | ||
220 | * here because cleanup code needs to sleep and caller holds spinlocks.) | ||
221 | */ | ||
222 | static void disable_media(struct tipc_bearer *tb_ptr) | ||
223 | { | ||
224 | struct ib_media *ib_ptr = (struct ib_media *)tb_ptr->usr_handle; | ||
225 | |||
226 | ib_ptr->bearer = NULL; | ||
227 | INIT_WORK(&ib_ptr->cleanup, cleanup_bearer); | ||
228 | schedule_work(&ib_ptr->cleanup); | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * recv_notification - handle device updates from OS | ||
233 | * | ||
234 | * Change the state of the InfiniBand bearer (if any) associated with the | ||
235 | * specified device. | ||
236 | */ | ||
237 | static int recv_notification(struct notifier_block *nb, unsigned long evt, | ||
238 | void *ptr) | ||
239 | { | ||
240 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); | ||
241 | struct ib_media *ib_ptr = &ib_media_array[0]; | ||
242 | struct ib_media *stop = &ib_media_array[MAX_IB_MEDIA]; | ||
243 | |||
244 | if (!net_eq(dev_net(dev), &init_net)) | ||
245 | return NOTIFY_DONE; | ||
246 | |||
247 | while ((ib_ptr->dev != dev)) { | ||
248 | if (++ib_ptr == stop) | ||
249 | return NOTIFY_DONE; /* couldn't find device */ | ||
250 | } | ||
251 | if (!ib_ptr->bearer) | ||
252 | return NOTIFY_DONE; /* bearer had been disabled */ | ||
253 | |||
254 | ib_ptr->bearer->mtu = dev->mtu; | ||
255 | |||
256 | switch (evt) { | ||
257 | case NETDEV_CHANGE: | ||
258 | if (netif_carrier_ok(dev)) | ||
259 | tipc_continue(ib_ptr->bearer); | ||
260 | else | ||
261 | tipc_block_bearer(ib_ptr->bearer); | ||
262 | break; | ||
263 | case NETDEV_UP: | ||
264 | tipc_continue(ib_ptr->bearer); | ||
265 | break; | ||
266 | case NETDEV_DOWN: | ||
267 | tipc_block_bearer(ib_ptr->bearer); | ||
268 | break; | ||
269 | case NETDEV_CHANGEMTU: | ||
270 | case NETDEV_CHANGEADDR: | ||
271 | tipc_block_bearer(ib_ptr->bearer); | ||
272 | tipc_continue(ib_ptr->bearer); | ||
273 | break; | ||
274 | case NETDEV_UNREGISTER: | ||
275 | case NETDEV_CHANGENAME: | ||
276 | tipc_disable_bearer(ib_ptr->bearer->name); | ||
277 | break; | ||
278 | } | ||
279 | return NOTIFY_OK; | ||
280 | } | ||
281 | |||
282 | static struct notifier_block notifier = { | ||
283 | .notifier_call = recv_notification, | ||
284 | .priority = 0, | ||
285 | }; | ||
286 | |||
287 | /** | ||
288 | * ib_addr2str - convert InfiniBand address to string | ||
289 | */ | ||
290 | static int ib_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size) | ||
291 | { | 48 | { |
292 | if (str_size < 60) /* 60 = 19 * strlen("xx:") + strlen("xx\0") */ | 49 | if (str_size < 60) /* 60 = 19 * strlen("xx:") + strlen("xx\0") */ |
293 | return 1; | 50 | return 1; |
@@ -297,10 +54,8 @@ static int ib_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size) | |||
297 | return 0; | 54 | return 0; |
298 | } | 55 | } |
299 | 56 | ||
300 | /** | 57 | /* convert InfiniBand address format to message header format */ |
301 | * ib_addr2msg - convert InfiniBand address format to message header format | 58 | static int tipc_ib_addr2msg(struct tipc_media_addr *a, char *msg_area) |
302 | */ | ||
303 | static int ib_addr2msg(struct tipc_media_addr *a, char *msg_area) | ||
304 | { | 59 | { |
305 | memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE); | 60 | memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE); |
306 | msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_IB; | 61 | msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_IB; |
@@ -308,65 +63,27 @@ static int ib_addr2msg(struct tipc_media_addr *a, char *msg_area) | |||
308 | return 0; | 63 | return 0; |
309 | } | 64 | } |
310 | 65 | ||
311 | /** | 66 | /* convert message header address format to InfiniBand format */ |
312 | * ib_msg2addr - convert message header address format to InfiniBand format | 67 | static int tipc_ib_msg2addr(const struct tipc_bearer *tb_ptr, |
313 | */ | 68 | struct tipc_media_addr *a, char *msg_area) |
314 | static int ib_msg2addr(const struct tipc_bearer *tb_ptr, | ||
315 | struct tipc_media_addr *a, char *msg_area) | ||
316 | { | 69 | { |
317 | ib_media_addr_set(tb_ptr, a, msg_area); | 70 | tipc_l2_media_addr_set(tb_ptr, a, msg_area); |
318 | return 0; | 71 | return 0; |
319 | } | 72 | } |
320 | 73 | ||
321 | /* | 74 | /* InfiniBand media registration info */ |
322 | * InfiniBand media registration info | 75 | struct tipc_media ib_media_info = { |
323 | */ | 76 | .send_msg = tipc_l2_send_msg, |
324 | static struct tipc_media ib_media_info = { | 77 | .enable_media = tipc_enable_l2_media, |
325 | .send_msg = send_msg, | 78 | .disable_media = tipc_disable_l2_media, |
326 | .enable_media = enable_media, | 79 | .addr2str = tipc_ib_addr2str, |
327 | .disable_media = disable_media, | 80 | .addr2msg = tipc_ib_addr2msg, |
328 | .addr2str = ib_addr2str, | 81 | .msg2addr = tipc_ib_msg2addr, |
329 | .addr2msg = ib_addr2msg, | ||
330 | .msg2addr = ib_msg2addr, | ||
331 | .priority = TIPC_DEF_LINK_PRI, | 82 | .priority = TIPC_DEF_LINK_PRI, |
332 | .tolerance = TIPC_DEF_LINK_TOL, | 83 | .tolerance = TIPC_DEF_LINK_TOL, |
333 | .window = TIPC_DEF_LINK_WIN, | 84 | .window = TIPC_DEF_LINK_WIN, |
334 | .type_id = TIPC_MEDIA_TYPE_IB, | 85 | .type_id = TIPC_MEDIA_TYPE_IB, |
86 | .hwaddr_len = INFINIBAND_ALEN, | ||
335 | .name = "ib" | 87 | .name = "ib" |
336 | }; | 88 | }; |
337 | 89 | ||
338 | /** | ||
339 | * tipc_ib_media_start - activate InfiniBand bearer support | ||
340 | * | ||
341 | * Register InfiniBand media type with TIPC bearer code. Also register | ||
342 | * with OS for notifications about device state changes. | ||
343 | */ | ||
344 | int tipc_ib_media_start(void) | ||
345 | { | ||
346 | int res; | ||
347 | |||
348 | if (ib_started) | ||
349 | return -EINVAL; | ||
350 | |||
351 | res = tipc_register_media(&ib_media_info); | ||
352 | if (res) | ||
353 | return res; | ||
354 | |||
355 | res = register_netdevice_notifier(¬ifier); | ||
356 | if (!res) | ||
357 | ib_started = 1; | ||
358 | return res; | ||
359 | } | ||
360 | |||
361 | /** | ||
362 | * tipc_ib_media_stop - deactivate InfiniBand bearer support | ||
363 | */ | ||
364 | void tipc_ib_media_stop(void) | ||
365 | { | ||
366 | if (!ib_started) | ||
367 | return; | ||
368 | |||
369 | flush_scheduled_work(); | ||
370 | unregister_netdevice_notifier(¬ifier); | ||
371 | ib_started = 0; | ||
372 | } | ||
diff --git a/net/tipc/link.c b/net/tipc/link.c index 13b987745820..d4b5de41b682 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/link.c: TIPC link code | 2 | * net/tipc/link.c: TIPC link code |
3 | * | 3 | * |
4 | * Copyright (c) 1996-2007, 2012, Ericsson AB | 4 | * Copyright (c) 1996-2007, 2012-2014, Ericsson AB |
5 | * Copyright (c) 2004-2007, 2010-2013, Wind River Systems | 5 | * Copyright (c) 2004-2007, 2010-2013, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
@@ -78,8 +78,8 @@ static const char *link_unk_evt = "Unknown link event "; | |||
78 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, | 78 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, |
79 | struct sk_buff *buf); | 79 | struct sk_buff *buf); |
80 | static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf); | 80 | static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf); |
81 | static int link_recv_changeover_msg(struct tipc_link **l_ptr, | 81 | static int tipc_link_tunnel_rcv(struct tipc_link **l_ptr, |
82 | struct sk_buff **buf); | 82 | struct sk_buff **buf); |
83 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance); | 83 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance); |
84 | static int link_send_sections_long(struct tipc_port *sender, | 84 | static int link_send_sections_long(struct tipc_port *sender, |
85 | struct iovec const *msg_sect, | 85 | struct iovec const *msg_sect, |
@@ -87,7 +87,6 @@ static int link_send_sections_long(struct tipc_port *sender, | |||
87 | static void link_state_event(struct tipc_link *l_ptr, u32 event); | 87 | static void link_state_event(struct tipc_link *l_ptr, u32 event); |
88 | static void link_reset_statistics(struct tipc_link *l_ptr); | 88 | static void link_reset_statistics(struct tipc_link *l_ptr); |
89 | static void link_print(struct tipc_link *l_ptr, const char *str); | 89 | static void link_print(struct tipc_link *l_ptr, const char *str); |
90 | static void link_start(struct tipc_link *l_ptr); | ||
91 | static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf); | 90 | static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf); |
92 | static void tipc_link_send_sync(struct tipc_link *l); | 91 | static void tipc_link_send_sync(struct tipc_link *l); |
93 | static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf); | 92 | static void tipc_link_recv_sync(struct tipc_node *n, struct sk_buff *buf); |
@@ -278,9 +277,11 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, | |||
278 | 277 | ||
279 | tipc_node_attach_link(n_ptr, l_ptr); | 278 | tipc_node_attach_link(n_ptr, l_ptr); |
280 | 279 | ||
281 | k_init_timer(&l_ptr->timer, (Handler)link_timeout, (unsigned long)l_ptr); | 280 | k_init_timer(&l_ptr->timer, (Handler)link_timeout, |
281 | (unsigned long)l_ptr); | ||
282 | list_add_tail(&l_ptr->link_list, &b_ptr->links); | 282 | list_add_tail(&l_ptr->link_list, &b_ptr->links); |
283 | tipc_k_signal((Handler)link_start, (unsigned long)l_ptr); | 283 | |
284 | link_state_event(l_ptr, STARTING_EVT); | ||
284 | 285 | ||
285 | return l_ptr; | 286 | return l_ptr; |
286 | } | 287 | } |
@@ -305,19 +306,13 @@ void tipc_link_delete(struct tipc_link *l_ptr) | |||
305 | tipc_node_lock(l_ptr->owner); | 306 | tipc_node_lock(l_ptr->owner); |
306 | tipc_link_reset(l_ptr); | 307 | tipc_link_reset(l_ptr); |
307 | tipc_node_detach_link(l_ptr->owner, l_ptr); | 308 | tipc_node_detach_link(l_ptr->owner, l_ptr); |
308 | tipc_link_stop(l_ptr); | 309 | tipc_link_purge_queues(l_ptr); |
309 | list_del_init(&l_ptr->link_list); | 310 | list_del_init(&l_ptr->link_list); |
310 | tipc_node_unlock(l_ptr->owner); | 311 | tipc_node_unlock(l_ptr->owner); |
311 | k_term_timer(&l_ptr->timer); | 312 | k_term_timer(&l_ptr->timer); |
312 | kfree(l_ptr); | 313 | kfree(l_ptr); |
313 | } | 314 | } |
314 | 315 | ||
315 | static void link_start(struct tipc_link *l_ptr) | ||
316 | { | ||
317 | tipc_node_lock(l_ptr->owner); | ||
318 | link_state_event(l_ptr, STARTING_EVT); | ||
319 | tipc_node_unlock(l_ptr->owner); | ||
320 | } | ||
321 | 316 | ||
322 | /** | 317 | /** |
323 | * link_schedule_port - schedule port for deferred sending | 318 | * link_schedule_port - schedule port for deferred sending |
@@ -386,14 +381,7 @@ exit: | |||
386 | */ | 381 | */ |
387 | static void link_release_outqueue(struct tipc_link *l_ptr) | 382 | static void link_release_outqueue(struct tipc_link *l_ptr) |
388 | { | 383 | { |
389 | struct sk_buff *buf = l_ptr->first_out; | 384 | kfree_skb_list(l_ptr->first_out); |
390 | struct sk_buff *next; | ||
391 | |||
392 | while (buf) { | ||
393 | next = buf->next; | ||
394 | kfree_skb(buf); | ||
395 | buf = next; | ||
396 | } | ||
397 | l_ptr->first_out = NULL; | 385 | l_ptr->first_out = NULL; |
398 | l_ptr->out_queue_size = 0; | 386 | l_ptr->out_queue_size = 0; |
399 | } | 387 | } |
@@ -410,37 +398,20 @@ void tipc_link_reset_fragments(struct tipc_link *l_ptr) | |||
410 | } | 398 | } |
411 | 399 | ||
412 | /** | 400 | /** |
413 | * tipc_link_stop - purge all inbound and outbound messages associated with link | 401 | * tipc_link_purge_queues - purge all pkt queues associated with link |
414 | * @l_ptr: pointer to link | 402 | * @l_ptr: pointer to link |
415 | */ | 403 | */ |
416 | void tipc_link_stop(struct tipc_link *l_ptr) | 404 | void tipc_link_purge_queues(struct tipc_link *l_ptr) |
417 | { | 405 | { |
418 | struct sk_buff *buf; | 406 | kfree_skb_list(l_ptr->oldest_deferred_in); |
419 | struct sk_buff *next; | 407 | kfree_skb_list(l_ptr->first_out); |
420 | |||
421 | buf = l_ptr->oldest_deferred_in; | ||
422 | while (buf) { | ||
423 | next = buf->next; | ||
424 | kfree_skb(buf); | ||
425 | buf = next; | ||
426 | } | ||
427 | |||
428 | buf = l_ptr->first_out; | ||
429 | while (buf) { | ||
430 | next = buf->next; | ||
431 | kfree_skb(buf); | ||
432 | buf = next; | ||
433 | } | ||
434 | |||
435 | tipc_link_reset_fragments(l_ptr); | 408 | tipc_link_reset_fragments(l_ptr); |
436 | |||
437 | kfree_skb(l_ptr->proto_msg_queue); | 409 | kfree_skb(l_ptr->proto_msg_queue); |
438 | l_ptr->proto_msg_queue = NULL; | 410 | l_ptr->proto_msg_queue = NULL; |
439 | } | 411 | } |
440 | 412 | ||
441 | void tipc_link_reset(struct tipc_link *l_ptr) | 413 | void tipc_link_reset(struct tipc_link *l_ptr) |
442 | { | 414 | { |
443 | struct sk_buff *buf; | ||
444 | u32 prev_state = l_ptr->state; | 415 | u32 prev_state = l_ptr->state; |
445 | u32 checkpoint = l_ptr->next_in_no; | 416 | u32 checkpoint = l_ptr->next_in_no; |
446 | int was_active_link = tipc_link_is_active(l_ptr); | 417 | int was_active_link = tipc_link_is_active(l_ptr); |
@@ -461,8 +432,7 @@ void tipc_link_reset(struct tipc_link *l_ptr) | |||
461 | tipc_node_link_down(l_ptr->owner, l_ptr); | 432 | tipc_node_link_down(l_ptr->owner, l_ptr); |
462 | tipc_bearer_remove_dest(l_ptr->b_ptr, l_ptr->addr); | 433 | tipc_bearer_remove_dest(l_ptr->b_ptr, l_ptr->addr); |
463 | 434 | ||
464 | if (was_active_link && tipc_node_active_links(l_ptr->owner) && | 435 | if (was_active_link && tipc_node_active_links(l_ptr->owner)) { |
465 | l_ptr->owner->permit_changeover) { | ||
466 | l_ptr->reset_checkpoint = checkpoint; | 436 | l_ptr->reset_checkpoint = checkpoint; |
467 | l_ptr->exp_msg_count = START_CHANGEOVER; | 437 | l_ptr->exp_msg_count = START_CHANGEOVER; |
468 | } | 438 | } |
@@ -471,12 +441,7 @@ void tipc_link_reset(struct tipc_link *l_ptr) | |||
471 | link_release_outqueue(l_ptr); | 441 | link_release_outqueue(l_ptr); |
472 | kfree_skb(l_ptr->proto_msg_queue); | 442 | kfree_skb(l_ptr->proto_msg_queue); |
473 | l_ptr->proto_msg_queue = NULL; | 443 | l_ptr->proto_msg_queue = NULL; |
474 | buf = l_ptr->oldest_deferred_in; | 444 | kfree_skb_list(l_ptr->oldest_deferred_in); |
475 | while (buf) { | ||
476 | struct sk_buff *next = buf->next; | ||
477 | kfree_skb(buf); | ||
478 | buf = next; | ||
479 | } | ||
480 | if (!list_empty(&l_ptr->waiting_ports)) | 445 | if (!list_empty(&l_ptr->waiting_ports)) |
481 | tipc_link_wakeup_ports(l_ptr, 1); | 446 | tipc_link_wakeup_ports(l_ptr, 1); |
482 | 447 | ||
@@ -517,10 +482,11 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
517 | if (!l_ptr->started && (event != STARTING_EVT)) | 482 | if (!l_ptr->started && (event != STARTING_EVT)) |
518 | return; /* Not yet. */ | 483 | return; /* Not yet. */ |
519 | 484 | ||
520 | if (link_blocked(l_ptr)) { | 485 | /* Check whether changeover is going on */ |
486 | if (l_ptr->exp_msg_count) { | ||
521 | if (event == TIMEOUT_EVT) | 487 | if (event == TIMEOUT_EVT) |
522 | link_set_timer(l_ptr, cont_intv); | 488 | link_set_timer(l_ptr, cont_intv); |
523 | return; /* Changeover going on */ | 489 | return; |
524 | } | 490 | } |
525 | 491 | ||
526 | switch (l_ptr->state) { | 492 | switch (l_ptr->state) { |
@@ -790,8 +756,7 @@ int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
790 | return link_send_long_buf(l_ptr, buf); | 756 | return link_send_long_buf(l_ptr, buf); |
791 | 757 | ||
792 | /* Packet can be queued or sent. */ | 758 | /* Packet can be queued or sent. */ |
793 | if (likely(!tipc_bearer_blocked(l_ptr->b_ptr) && | 759 | if (likely(!link_congested(l_ptr))) { |
794 | !link_congested(l_ptr))) { | ||
795 | link_add_to_outqueue(l_ptr, buf, msg); | 760 | link_add_to_outqueue(l_ptr, buf, msg); |
796 | 761 | ||
797 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); | 762 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
@@ -957,14 +922,13 @@ static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf, | |||
957 | 922 | ||
958 | if (likely(!link_congested(l_ptr))) { | 923 | if (likely(!link_congested(l_ptr))) { |
959 | if (likely(msg_size(msg) <= l_ptr->max_pkt)) { | 924 | if (likely(msg_size(msg) <= l_ptr->max_pkt)) { |
960 | if (likely(!tipc_bearer_blocked(l_ptr->b_ptr))) { | 925 | link_add_to_outqueue(l_ptr, buf, msg); |
961 | link_add_to_outqueue(l_ptr, buf, msg); | 926 | tipc_bearer_send(l_ptr->b_ptr, buf, |
962 | tipc_bearer_send(l_ptr->b_ptr, buf, | 927 | &l_ptr->media_addr); |
963 | &l_ptr->media_addr); | 928 | l_ptr->unacked_window = 0; |
964 | l_ptr->unacked_window = 0; | 929 | return res; |
965 | return res; | 930 | } |
966 | } | 931 | else |
967 | } else | ||
968 | *used_max_pkt = l_ptr->max_pkt; | 932 | *used_max_pkt = l_ptr->max_pkt; |
969 | } | 933 | } |
970 | return tipc_link_send_buf(l_ptr, buf); /* All other cases */ | 934 | return tipc_link_send_buf(l_ptr, buf); /* All other cases */ |
@@ -1013,8 +977,7 @@ exit: | |||
1013 | } | 977 | } |
1014 | 978 | ||
1015 | /* Exit if link (or bearer) is congested */ | 979 | /* Exit if link (or bearer) is congested */ |
1016 | if (link_congested(l_ptr) || | 980 | if (link_congested(l_ptr)) { |
1017 | tipc_bearer_blocked(l_ptr->b_ptr)) { | ||
1018 | res = link_schedule_port(l_ptr, | 981 | res = link_schedule_port(l_ptr, |
1019 | sender->ref, res); | 982 | sender->ref, res); |
1020 | goto exit; | 983 | goto exit; |
@@ -1127,10 +1090,7 @@ again: | |||
1127 | if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) { | 1090 | if (copy_from_user(buf->data + fragm_crs, sect_crs, sz)) { |
1128 | res = -EFAULT; | 1091 | res = -EFAULT; |
1129 | error: | 1092 | error: |
1130 | for (; buf_chain; buf_chain = buf) { | 1093 | kfree_skb_list(buf_chain); |
1131 | buf = buf_chain->next; | ||
1132 | kfree_skb(buf_chain); | ||
1133 | } | ||
1134 | return res; | 1094 | return res; |
1135 | } | 1095 | } |
1136 | sect_crs += sz; | 1096 | sect_crs += sz; |
@@ -1180,18 +1140,12 @@ error: | |||
1180 | if (l_ptr->max_pkt < max_pkt) { | 1140 | if (l_ptr->max_pkt < max_pkt) { |
1181 | sender->max_pkt = l_ptr->max_pkt; | 1141 | sender->max_pkt = l_ptr->max_pkt; |
1182 | tipc_node_unlock(node); | 1142 | tipc_node_unlock(node); |
1183 | for (; buf_chain; buf_chain = buf) { | 1143 | kfree_skb_list(buf_chain); |
1184 | buf = buf_chain->next; | ||
1185 | kfree_skb(buf_chain); | ||
1186 | } | ||
1187 | goto again; | 1144 | goto again; |
1188 | } | 1145 | } |
1189 | } else { | 1146 | } else { |
1190 | reject: | 1147 | reject: |
1191 | for (; buf_chain; buf_chain = buf) { | 1148 | kfree_skb_list(buf_chain); |
1192 | buf = buf_chain->next; | ||
1193 | kfree_skb(buf_chain); | ||
1194 | } | ||
1195 | return tipc_port_reject_sections(sender, hdr, msg_sect, | 1149 | return tipc_port_reject_sections(sender, hdr, msg_sect, |
1196 | len, TIPC_ERR_NO_NODE); | 1150 | len, TIPC_ERR_NO_NODE); |
1197 | } | 1151 | } |
@@ -1209,7 +1163,7 @@ reject: | |||
1209 | /* | 1163 | /* |
1210 | * tipc_link_push_packet: Push one unsent packet to the media | 1164 | * tipc_link_push_packet: Push one unsent packet to the media |
1211 | */ | 1165 | */ |
1212 | u32 tipc_link_push_packet(struct tipc_link *l_ptr) | 1166 | static u32 tipc_link_push_packet(struct tipc_link *l_ptr) |
1213 | { | 1167 | { |
1214 | struct sk_buff *buf = l_ptr->first_out; | 1168 | struct sk_buff *buf = l_ptr->first_out; |
1215 | u32 r_q_size = l_ptr->retransm_queue_size; | 1169 | u32 r_q_size = l_ptr->retransm_queue_size; |
@@ -1281,9 +1235,6 @@ void tipc_link_push_queue(struct tipc_link *l_ptr) | |||
1281 | { | 1235 | { |
1282 | u32 res; | 1236 | u32 res; |
1283 | 1237 | ||
1284 | if (tipc_bearer_blocked(l_ptr->b_ptr)) | ||
1285 | return; | ||
1286 | |||
1287 | do { | 1238 | do { |
1288 | res = tipc_link_push_packet(l_ptr); | 1239 | res = tipc_link_push_packet(l_ptr); |
1289 | } while (!res); | 1240 | } while (!res); |
@@ -1370,26 +1321,15 @@ void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *buf, | |||
1370 | 1321 | ||
1371 | msg = buf_msg(buf); | 1322 | msg = buf_msg(buf); |
1372 | 1323 | ||
1373 | if (tipc_bearer_blocked(l_ptr->b_ptr)) { | 1324 | /* Detect repeated retransmit failures */ |
1374 | if (l_ptr->retransm_queue_size == 0) { | 1325 | if (l_ptr->last_retransmitted == msg_seqno(msg)) { |
1375 | l_ptr->retransm_queue_head = msg_seqno(msg); | 1326 | if (++l_ptr->stale_count > 100) { |
1376 | l_ptr->retransm_queue_size = retransmits; | 1327 | link_retransmit_failure(l_ptr, buf); |
1377 | } else { | 1328 | return; |
1378 | pr_err("Unexpected retransmit on link %s (qsize=%d)\n", | ||
1379 | l_ptr->name, l_ptr->retransm_queue_size); | ||
1380 | } | 1329 | } |
1381 | return; | ||
1382 | } else { | 1330 | } else { |
1383 | /* Detect repeated retransmit failures on unblocked bearer */ | 1331 | l_ptr->last_retransmitted = msg_seqno(msg); |
1384 | if (l_ptr->last_retransmitted == msg_seqno(msg)) { | 1332 | l_ptr->stale_count = 1; |
1385 | if (++l_ptr->stale_count > 100) { | ||
1386 | link_retransmit_failure(l_ptr, buf); | ||
1387 | return; | ||
1388 | } | ||
1389 | } else { | ||
1390 | l_ptr->last_retransmitted = msg_seqno(msg); | ||
1391 | l_ptr->stale_count = 1; | ||
1392 | } | ||
1393 | } | 1333 | } |
1394 | 1334 | ||
1395 | while (retransmits && (buf != l_ptr->next_out) && buf) { | 1335 | while (retransmits && (buf != l_ptr->next_out) && buf) { |
@@ -1476,14 +1416,14 @@ static int link_recv_buf_validate(struct sk_buff *buf) | |||
1476 | } | 1416 | } |
1477 | 1417 | ||
1478 | /** | 1418 | /** |
1479 | * tipc_recv_msg - process TIPC messages arriving from off-node | 1419 | * tipc_rcv - process TIPC packets/messages arriving from off-node |
1480 | * @head: pointer to message buffer chain | 1420 | * @head: pointer to message buffer chain |
1481 | * @tb_ptr: pointer to bearer message arrived on | 1421 | * @tb_ptr: pointer to bearer message arrived on |
1482 | * | 1422 | * |
1483 | * Invoked with no locks held. Bearer pointer must point to a valid bearer | 1423 | * Invoked with no locks held. Bearer pointer must point to a valid bearer |
1484 | * structure (i.e. cannot be NULL), but bearer can be inactive. | 1424 | * structure (i.e. cannot be NULL), but bearer can be inactive. |
1485 | */ | 1425 | */ |
1486 | void tipc_recv_msg(struct sk_buff *head, struct tipc_bearer *b_ptr) | 1426 | void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr) |
1487 | { | 1427 | { |
1488 | read_lock_bh(&tipc_net_lock); | 1428 | read_lock_bh(&tipc_net_lock); |
1489 | while (head) { | 1429 | while (head) { |
@@ -1658,7 +1598,7 @@ deliver: | |||
1658 | continue; | 1598 | continue; |
1659 | case CHANGEOVER_PROTOCOL: | 1599 | case CHANGEOVER_PROTOCOL: |
1660 | type = msg_type(msg); | 1600 | type = msg_type(msg); |
1661 | if (link_recv_changeover_msg(&l_ptr, &buf)) { | 1601 | if (tipc_link_tunnel_rcv(&l_ptr, &buf)) { |
1662 | msg = buf_msg(buf); | 1602 | msg = buf_msg(buf); |
1663 | seq_no = msg_seqno(msg); | 1603 | seq_no = msg_seqno(msg); |
1664 | if (type == ORIGINAL_MSG) | 1604 | if (type == ORIGINAL_MSG) |
@@ -1787,7 +1727,8 @@ void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ, | |||
1787 | l_ptr->proto_msg_queue = NULL; | 1727 | l_ptr->proto_msg_queue = NULL; |
1788 | } | 1728 | } |
1789 | 1729 | ||
1790 | if (link_blocked(l_ptr)) | 1730 | /* Don't send protocol message during link changeover */ |
1731 | if (l_ptr->exp_msg_count) | ||
1791 | return; | 1732 | return; |
1792 | 1733 | ||
1793 | /* Abort non-RESET send if communication with node is prohibited */ | 1734 | /* Abort non-RESET send if communication with node is prohibited */ |
@@ -1862,12 +1803,6 @@ void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ, | |||
1862 | skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg)); | 1803 | skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg)); |
1863 | buf->priority = TC_PRIO_CONTROL; | 1804 | buf->priority = TC_PRIO_CONTROL; |
1864 | 1805 | ||
1865 | /* Defer message if bearer is already blocked */ | ||
1866 | if (tipc_bearer_blocked(l_ptr->b_ptr)) { | ||
1867 | l_ptr->proto_msg_queue = buf; | ||
1868 | return; | ||
1869 | } | ||
1870 | |||
1871 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); | 1806 | tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr); |
1872 | l_ptr->unacked_window = 0; | 1807 | l_ptr->unacked_window = 0; |
1873 | kfree_skb(buf); | 1808 | kfree_skb(buf); |
@@ -1886,7 +1821,8 @@ static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
1886 | u32 msg_tol; | 1821 | u32 msg_tol; |
1887 | struct tipc_msg *msg = buf_msg(buf); | 1822 | struct tipc_msg *msg = buf_msg(buf); |
1888 | 1823 | ||
1889 | if (link_blocked(l_ptr)) | 1824 | /* Discard protocol message during link changeover */ |
1825 | if (l_ptr->exp_msg_count) | ||
1890 | goto exit; | 1826 | goto exit; |
1891 | 1827 | ||
1892 | /* record unnumbered packet arrival (force mismatch on next timeout) */ | 1828 | /* record unnumbered packet arrival (force mismatch on next timeout) */ |
@@ -1896,8 +1832,6 @@ static void link_recv_proto_msg(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
1896 | if (tipc_own_addr > msg_prevnode(msg)) | 1832 | if (tipc_own_addr > msg_prevnode(msg)) |
1897 | l_ptr->b_ptr->net_plane = msg_net_plane(msg); | 1833 | l_ptr->b_ptr->net_plane = msg_net_plane(msg); |
1898 | 1834 | ||
1899 | l_ptr->owner->permit_changeover = msg_redundant_link(msg); | ||
1900 | |||
1901 | switch (msg_type(msg)) { | 1835 | switch (msg_type(msg)) { |
1902 | 1836 | ||
1903 | case RESET_MSG: | 1837 | case RESET_MSG: |
@@ -2013,13 +1947,13 @@ exit: | |||
2013 | } | 1947 | } |
2014 | 1948 | ||
2015 | 1949 | ||
2016 | /* | 1950 | /* tipc_link_tunnel_xmit(): Tunnel one packet via a link belonging to |
2017 | * tipc_link_tunnel(): Send one message via a link belonging to | 1951 | * a different bearer. Owner node is locked. |
2018 | * another bearer. Owner node is locked. | ||
2019 | */ | 1952 | */ |
2020 | static void tipc_link_tunnel(struct tipc_link *l_ptr, | 1953 | static void tipc_link_tunnel_xmit(struct tipc_link *l_ptr, |
2021 | struct tipc_msg *tunnel_hdr, struct tipc_msg *msg, | 1954 | struct tipc_msg *tunnel_hdr, |
2022 | u32 selector) | 1955 | struct tipc_msg *msg, |
1956 | u32 selector) | ||
2023 | { | 1957 | { |
2024 | struct tipc_link *tunnel; | 1958 | struct tipc_link *tunnel; |
2025 | struct sk_buff *buf; | 1959 | struct sk_buff *buf; |
@@ -2042,12 +1976,13 @@ static void tipc_link_tunnel(struct tipc_link *l_ptr, | |||
2042 | } | 1976 | } |
2043 | 1977 | ||
2044 | 1978 | ||
2045 | 1979 | /* tipc_link_failover_send_queue(): A link has gone down, but a second | |
2046 | /* | 1980 | * link is still active. We can do failover. Tunnel the failing link's |
2047 | * changeover(): Send whole message queue via the remaining link | 1981 | * whole send queue via the remaining link. This way, we don't lose |
2048 | * Owner node is locked. | 1982 | * any packets, and sequence order is preserved for subsequent traffic |
1983 | * sent over the remaining link. Owner node is locked. | ||
2049 | */ | 1984 | */ |
2050 | void tipc_link_changeover(struct tipc_link *l_ptr) | 1985 | void tipc_link_failover_send_queue(struct tipc_link *l_ptr) |
2051 | { | 1986 | { |
2052 | u32 msgcount = l_ptr->out_queue_size; | 1987 | u32 msgcount = l_ptr->out_queue_size; |
2053 | struct sk_buff *crs = l_ptr->first_out; | 1988 | struct sk_buff *crs = l_ptr->first_out; |
@@ -2058,11 +1993,6 @@ void tipc_link_changeover(struct tipc_link *l_ptr) | |||
2058 | if (!tunnel) | 1993 | if (!tunnel) |
2059 | return; | 1994 | return; |
2060 | 1995 | ||
2061 | if (!l_ptr->owner->permit_changeover) { | ||
2062 | pr_warn("%speer did not permit changeover\n", link_co_err); | ||
2063 | return; | ||
2064 | } | ||
2065 | |||
2066 | tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, | 1996 | tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, |
2067 | ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr); | 1997 | ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr); |
2068 | msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); | 1998 | msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); |
@@ -2096,20 +2026,30 @@ void tipc_link_changeover(struct tipc_link *l_ptr) | |||
2096 | msgcount = msg_msgcnt(msg); | 2026 | msgcount = msg_msgcnt(msg); |
2097 | while (msgcount--) { | 2027 | while (msgcount--) { |
2098 | msg_set_seqno(m, msg_seqno(msg)); | 2028 | msg_set_seqno(m, msg_seqno(msg)); |
2099 | tipc_link_tunnel(l_ptr, &tunnel_hdr, m, | 2029 | tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, m, |
2100 | msg_link_selector(m)); | 2030 | msg_link_selector(m)); |
2101 | pos += align(msg_size(m)); | 2031 | pos += align(msg_size(m)); |
2102 | m = (struct tipc_msg *)pos; | 2032 | m = (struct tipc_msg *)pos; |
2103 | } | 2033 | } |
2104 | } else { | 2034 | } else { |
2105 | tipc_link_tunnel(l_ptr, &tunnel_hdr, msg, | 2035 | tipc_link_tunnel_xmit(l_ptr, &tunnel_hdr, msg, |
2106 | msg_link_selector(msg)); | 2036 | msg_link_selector(msg)); |
2107 | } | 2037 | } |
2108 | crs = crs->next; | 2038 | crs = crs->next; |
2109 | } | 2039 | } |
2110 | } | 2040 | } |
2111 | 2041 | ||
2112 | void tipc_link_send_duplicate(struct tipc_link *l_ptr, struct tipc_link *tunnel) | 2042 | /* tipc_link_dup_send_queue(): A second link has become active. Tunnel a |
2043 | * duplicate of the first link's send queue via the new link. This way, we | ||
2044 | * are guaranteed that currently queued packets from a socket are delivered | ||
2045 | * before future traffic from the same socket, even if this is using the | ||
2046 | * new link. The last arriving copy of each duplicate packet is dropped at | ||
2047 | * the receiving end by the regular protocol check, so packet cardinality | ||
2048 | * and sequence order is preserved per sender/receiver socket pair. | ||
2049 | * Owner node is locked. | ||
2050 | */ | ||
2051 | void tipc_link_dup_send_queue(struct tipc_link *l_ptr, | ||
2052 | struct tipc_link *tunnel) | ||
2113 | { | 2053 | { |
2114 | struct sk_buff *iter; | 2054 | struct sk_buff *iter; |
2115 | struct tipc_msg tunnel_hdr; | 2055 | struct tipc_msg tunnel_hdr; |
@@ -2165,12 +2105,14 @@ static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos) | |||
2165 | return eb; | 2105 | return eb; |
2166 | } | 2106 | } |
2167 | 2107 | ||
2168 | /* | 2108 | /* tipc_link_tunnel_rcv(): Receive a tunneled packet, sent |
2169 | * link_recv_changeover_msg(): Receive tunneled packet sent | 2109 | * via other link as result of a failover (ORIGINAL_MSG) or |
2170 | * via other link. Node is locked. Return extracted buffer. | 2110 | * a new active link (DUPLICATE_MSG). Failover packets are |
2111 | * returned to the active link for delivery upwards. | ||
2112 | * Owner node is locked. | ||
2171 | */ | 2113 | */ |
2172 | static int link_recv_changeover_msg(struct tipc_link **l_ptr, | 2114 | static int tipc_link_tunnel_rcv(struct tipc_link **l_ptr, |
2173 | struct sk_buff **buf) | 2115 | struct sk_buff **buf) |
2174 | { | 2116 | { |
2175 | struct sk_buff *tunnel_buf = *buf; | 2117 | struct sk_buff *tunnel_buf = *buf; |
2176 | struct tipc_link *dest_link; | 2118 | struct tipc_link *dest_link; |
@@ -2307,11 +2249,7 @@ static int link_send_long_buf(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
2307 | fragm = tipc_buf_acquire(fragm_sz + INT_H_SIZE); | 2249 | fragm = tipc_buf_acquire(fragm_sz + INT_H_SIZE); |
2308 | if (fragm == NULL) { | 2250 | if (fragm == NULL) { |
2309 | kfree_skb(buf); | 2251 | kfree_skb(buf); |
2310 | while (buf_chain) { | 2252 | kfree_skb_list(buf_chain); |
2311 | buf = buf_chain; | ||
2312 | buf_chain = buf_chain->next; | ||
2313 | kfree_skb(buf); | ||
2314 | } | ||
2315 | return -ENOMEM; | 2253 | return -ENOMEM; |
2316 | } | 2254 | } |
2317 | msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE); | 2255 | msg_set_size(&fragm_hdr, fragm_sz + INT_H_SIZE); |
diff --git a/net/tipc/link.h b/net/tipc/link.h index 8a6c1026644d..3b6aa65b608c 100644 --- a/net/tipc/link.h +++ b/net/tipc/link.h | |||
@@ -112,7 +112,6 @@ struct tipc_stats { | |||
112 | * @continuity_interval: link continuity testing interval [in ms] | 112 | * @continuity_interval: link continuity testing interval [in ms] |
113 | * @abort_limit: # of unacknowledged continuity probes needed to reset link | 113 | * @abort_limit: # of unacknowledged continuity probes needed to reset link |
114 | * @state: current state of link FSM | 114 | * @state: current state of link FSM |
115 | * @blocked: indicates if link has been administratively blocked | ||
116 | * @fsm_msg_cnt: # of protocol messages link FSM has sent in current state | 115 | * @fsm_msg_cnt: # of protocol messages link FSM has sent in current state |
117 | * @proto_msg: template for control messages generated by link | 116 | * @proto_msg: template for control messages generated by link |
118 | * @pmsg: convenience pointer to "proto_msg" field | 117 | * @pmsg: convenience pointer to "proto_msg" field |
@@ -162,7 +161,6 @@ struct tipc_link { | |||
162 | u32 continuity_interval; | 161 | u32 continuity_interval; |
163 | u32 abort_limit; | 162 | u32 abort_limit; |
164 | int state; | 163 | int state; |
165 | int blocked; | ||
166 | u32 fsm_msg_cnt; | 164 | u32 fsm_msg_cnt; |
167 | struct { | 165 | struct { |
168 | unchar hdr[INT_H_SIZE]; | 166 | unchar hdr[INT_H_SIZE]; |
@@ -218,16 +216,20 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, | |||
218 | struct tipc_bearer *b_ptr, | 216 | struct tipc_bearer *b_ptr, |
219 | const struct tipc_media_addr *media_addr); | 217 | const struct tipc_media_addr *media_addr); |
220 | void tipc_link_delete(struct tipc_link *l_ptr); | 218 | void tipc_link_delete(struct tipc_link *l_ptr); |
221 | void tipc_link_changeover(struct tipc_link *l_ptr); | 219 | void tipc_link_failover_send_queue(struct tipc_link *l_ptr); |
222 | void tipc_link_send_duplicate(struct tipc_link *l_ptr, struct tipc_link *dest); | 220 | void tipc_link_dup_send_queue(struct tipc_link *l_ptr, |
221 | struct tipc_link *dest); | ||
223 | void tipc_link_reset_fragments(struct tipc_link *l_ptr); | 222 | void tipc_link_reset_fragments(struct tipc_link *l_ptr); |
224 | int tipc_link_is_up(struct tipc_link *l_ptr); | 223 | int tipc_link_is_up(struct tipc_link *l_ptr); |
225 | int tipc_link_is_active(struct tipc_link *l_ptr); | 224 | int tipc_link_is_active(struct tipc_link *l_ptr); |
226 | u32 tipc_link_push_packet(struct tipc_link *l_ptr); | 225 | void tipc_link_purge_queues(struct tipc_link *l_ptr); |
227 | void tipc_link_stop(struct tipc_link *l_ptr); | 226 | struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, |
228 | struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space, u16 cmd); | 227 | int req_tlv_space, |
229 | struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space); | 228 | u16 cmd); |
230 | struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space); | 229 | struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, |
230 | int req_tlv_space); | ||
231 | struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, | ||
232 | int req_tlv_space); | ||
231 | void tipc_link_reset(struct tipc_link *l_ptr); | 233 | void tipc_link_reset(struct tipc_link *l_ptr); |
232 | int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector); | 234 | int tipc_link_send(struct sk_buff *buf, u32 dest, u32 selector); |
233 | void tipc_link_send_names(struct list_head *message_list, u32 dest); | 235 | void tipc_link_send_names(struct list_head *message_list, u32 dest); |
@@ -312,11 +314,6 @@ static inline int link_reset_reset(struct tipc_link *l_ptr) | |||
312 | return l_ptr->state == RESET_RESET; | 314 | return l_ptr->state == RESET_RESET; |
313 | } | 315 | } |
314 | 316 | ||
315 | static inline int link_blocked(struct tipc_link *l_ptr) | ||
316 | { | ||
317 | return l_ptr->exp_msg_count || l_ptr->blocked; | ||
318 | } | ||
319 | |||
320 | static inline int link_congested(struct tipc_link *l_ptr) | 317 | static inline int link_congested(struct tipc_link *l_ptr) |
321 | { | 318 | { |
322 | return l_ptr->out_queue_size >= l_ptr->queue_limit[0]; | 319 | return l_ptr->out_queue_size >= l_ptr->queue_limit[0]; |
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c index 09dcd54b04e1..92a1533af4e0 100644 --- a/net/tipc/name_table.c +++ b/net/tipc/name_table.c | |||
@@ -148,8 +148,7 @@ static struct publication *publ_create(u32 type, u32 lower, u32 upper, | |||
148 | */ | 148 | */ |
149 | static struct sub_seq *tipc_subseq_alloc(u32 cnt) | 149 | static struct sub_seq *tipc_subseq_alloc(u32 cnt) |
150 | { | 150 | { |
151 | struct sub_seq *sseq = kcalloc(cnt, sizeof(struct sub_seq), GFP_ATOMIC); | 151 | return kcalloc(cnt, sizeof(struct sub_seq), GFP_ATOMIC); |
152 | return sseq; | ||
153 | } | 152 | } |
154 | 153 | ||
155 | /** | 154 | /** |
diff --git a/net/tipc/node.c b/net/tipc/node.c index 25100c0a6fe8..efe4d41bf11b 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c | |||
@@ -162,7 +162,7 @@ void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
162 | pr_info("New link <%s> becomes standby\n", l_ptr->name); | 162 | pr_info("New link <%s> becomes standby\n", l_ptr->name); |
163 | return; | 163 | return; |
164 | } | 164 | } |
165 | tipc_link_send_duplicate(active[0], l_ptr); | 165 | tipc_link_dup_send_queue(active[0], l_ptr); |
166 | if (l_ptr->priority == active[0]->priority) { | 166 | if (l_ptr->priority == active[0]->priority) { |
167 | active[0] = l_ptr; | 167 | active[0] = l_ptr; |
168 | return; | 168 | return; |
@@ -225,7 +225,7 @@ void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
225 | if (active[0] == l_ptr) | 225 | if (active[0] == l_ptr) |
226 | node_select_active_links(n_ptr); | 226 | node_select_active_links(n_ptr); |
227 | if (tipc_node_is_up(n_ptr)) | 227 | if (tipc_node_is_up(n_ptr)) |
228 | tipc_link_changeover(l_ptr); | 228 | tipc_link_failover_send_queue(l_ptr); |
229 | else | 229 | else |
230 | node_lost_contact(n_ptr); | 230 | node_lost_contact(n_ptr); |
231 | } | 231 | } |
@@ -235,11 +235,6 @@ int tipc_node_active_links(struct tipc_node *n_ptr) | |||
235 | return n_ptr->active_links[0] != NULL; | 235 | return n_ptr->active_links[0] != NULL; |
236 | } | 236 | } |
237 | 237 | ||
238 | int tipc_node_redundant_links(struct tipc_node *n_ptr) | ||
239 | { | ||
240 | return n_ptr->working_links > 1; | ||
241 | } | ||
242 | |||
243 | int tipc_node_is_up(struct tipc_node *n_ptr) | 238 | int tipc_node_is_up(struct tipc_node *n_ptr) |
244 | { | 239 | { |
245 | return tipc_node_active_links(n_ptr); | 240 | return tipc_node_active_links(n_ptr); |
@@ -291,11 +286,7 @@ static void node_lost_contact(struct tipc_node *n_ptr) | |||
291 | 286 | ||
292 | /* Flush broadcast link info associated with lost node */ | 287 | /* Flush broadcast link info associated with lost node */ |
293 | if (n_ptr->bclink.recv_permitted) { | 288 | if (n_ptr->bclink.recv_permitted) { |
294 | while (n_ptr->bclink.deferred_head) { | 289 | kfree_skb_list(n_ptr->bclink.deferred_head); |
295 | struct sk_buff *buf = n_ptr->bclink.deferred_head; | ||
296 | n_ptr->bclink.deferred_head = buf->next; | ||
297 | kfree_skb(buf); | ||
298 | } | ||
299 | n_ptr->bclink.deferred_size = 0; | 290 | n_ptr->bclink.deferred_size = 0; |
300 | 291 | ||
301 | if (n_ptr->bclink.reasm_head) { | 292 | if (n_ptr->bclink.reasm_head) { |
diff --git a/net/tipc/node.h b/net/tipc/node.h index e5e96c04e167..63e2e8ead2fe 100644 --- a/net/tipc/node.h +++ b/net/tipc/node.h | |||
@@ -64,7 +64,6 @@ | |||
64 | * @working_links: number of working links to node (both active and standby) | 64 | * @working_links: number of working links to node (both active and standby) |
65 | * @block_setup: bit mask of conditions preventing link establishment to node | 65 | * @block_setup: bit mask of conditions preventing link establishment to node |
66 | * @link_cnt: number of links to node | 66 | * @link_cnt: number of links to node |
67 | * @permit_changeover: non-zero if node has redundant links to this system | ||
68 | * @signature: node instance identifier | 67 | * @signature: node instance identifier |
69 | * @bclink: broadcast-related info | 68 | * @bclink: broadcast-related info |
70 | * @acked: sequence # of last outbound b'cast message acknowledged by node | 69 | * @acked: sequence # of last outbound b'cast message acknowledged by node |
@@ -89,7 +88,6 @@ struct tipc_node { | |||
89 | int link_cnt; | 88 | int link_cnt; |
90 | int working_links; | 89 | int working_links; |
91 | int block_setup; | 90 | int block_setup; |
92 | int permit_changeover; | ||
93 | u32 signature; | 91 | u32 signature; |
94 | struct { | 92 | struct { |
95 | u32 acked; | 93 | u32 acked; |
@@ -115,7 +113,6 @@ void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); | |||
115 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr); | 113 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr); |
116 | void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr); | 114 | void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr); |
117 | int tipc_node_active_links(struct tipc_node *n_ptr); | 115 | int tipc_node_active_links(struct tipc_node *n_ptr); |
118 | int tipc_node_redundant_links(struct tipc_node *n_ptr); | ||
119 | int tipc_node_is_up(struct tipc_node *n_ptr); | 116 | int tipc_node_is_up(struct tipc_node *n_ptr); |
120 | struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space); | 117 | struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space); |
121 | struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space); | 118 | struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space); |
diff --git a/net/tipc/port.c b/net/tipc/port.c index d43f3182b1d4..b742b2654525 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c | |||
@@ -817,17 +817,14 @@ exit: | |||
817 | */ | 817 | */ |
818 | int __tipc_disconnect(struct tipc_port *tp_ptr) | 818 | int __tipc_disconnect(struct tipc_port *tp_ptr) |
819 | { | 819 | { |
820 | int res; | ||
821 | |||
822 | if (tp_ptr->connected) { | 820 | if (tp_ptr->connected) { |
823 | tp_ptr->connected = 0; | 821 | tp_ptr->connected = 0; |
824 | /* let timer expire on it's own to avoid deadlock! */ | 822 | /* let timer expire on it's own to avoid deadlock! */ |
825 | tipc_nodesub_unsubscribe(&tp_ptr->subscription); | 823 | tipc_nodesub_unsubscribe(&tp_ptr->subscription); |
826 | res = 0; | 824 | return 0; |
827 | } else { | ||
828 | res = -ENOTCONN; | ||
829 | } | 825 | } |
830 | return res; | 826 | |
827 | return -ENOTCONN; | ||
831 | } | 828 | } |
832 | 829 | ||
833 | /* | 830 | /* |
diff --git a/net/tipc/server.c b/net/tipc/server.c index fd3fa57a410e..b635ca347a87 100644 --- a/net/tipc/server.c +++ b/net/tipc/server.c | |||
@@ -55,7 +55,7 @@ | |||
55 | * @usr_data: user-specified field | 55 | * @usr_data: user-specified field |
56 | * @rx_action: what to do when connection socket is active | 56 | * @rx_action: what to do when connection socket is active |
57 | * @outqueue: pointer to first outbound message in queue | 57 | * @outqueue: pointer to first outbound message in queue |
58 | * @outqueue_lock: controll access to the outqueue | 58 | * @outqueue_lock: control access to the outqueue |
59 | * @outqueue: list of connection objects for its server | 59 | * @outqueue: list of connection objects for its server |
60 | * @swork: send work item | 60 | * @swork: send work item |
61 | */ | 61 | */ |
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index e741416d1d24..aab4948f0aff 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -55,9 +55,6 @@ struct tipc_sock { | |||
55 | #define tipc_sk(sk) ((struct tipc_sock *)(sk)) | 55 | #define tipc_sk(sk) ((struct tipc_sock *)(sk)) |
56 | #define tipc_sk_port(sk) (tipc_sk(sk)->p) | 56 | #define tipc_sk_port(sk) (tipc_sk(sk)->p) |
57 | 57 | ||
58 | #define tipc_rx_ready(sock) (!skb_queue_empty(&sock->sk->sk_receive_queue) || \ | ||
59 | (sock->state == SS_DISCONNECTING)) | ||
60 | |||
61 | static int backlog_rcv(struct sock *sk, struct sk_buff *skb); | 58 | static int backlog_rcv(struct sock *sk, struct sk_buff *skb); |
62 | static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf); | 59 | static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf); |
63 | static void wakeupdispatch(struct tipc_port *tport); | 60 | static void wakeupdispatch(struct tipc_port *tport); |
@@ -239,7 +236,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol, | |||
239 | int tipc_sock_create_local(int type, struct socket **res) | 236 | int tipc_sock_create_local(int type, struct socket **res) |
240 | { | 237 | { |
241 | int rc; | 238 | int rc; |
242 | struct sock *sk; | ||
243 | 239 | ||
244 | rc = sock_create_lite(AF_TIPC, type, 0, res); | 240 | rc = sock_create_lite(AF_TIPC, type, 0, res); |
245 | if (rc < 0) { | 241 | if (rc < 0) { |
@@ -248,8 +244,6 @@ int tipc_sock_create_local(int type, struct socket **res) | |||
248 | } | 244 | } |
249 | tipc_sk_create(&init_net, *res, 0, 1); | 245 | tipc_sk_create(&init_net, *res, 0, 1); |
250 | 246 | ||
251 | sk = (*res)->sk; | ||
252 | |||
253 | return 0; | 247 | return 0; |
254 | } | 248 | } |
255 | 249 | ||
@@ -570,6 +564,31 @@ static int dest_name_check(struct sockaddr_tipc *dest, struct msghdr *m) | |||
570 | return 0; | 564 | return 0; |
571 | } | 565 | } |
572 | 566 | ||
567 | static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p) | ||
568 | { | ||
569 | struct sock *sk = sock->sk; | ||
570 | struct tipc_port *tport = tipc_sk_port(sk); | ||
571 | DEFINE_WAIT(wait); | ||
572 | int done; | ||
573 | |||
574 | do { | ||
575 | int err = sock_error(sk); | ||
576 | if (err) | ||
577 | return err; | ||
578 | if (sock->state == SS_DISCONNECTING) | ||
579 | return -EPIPE; | ||
580 | if (!*timeo_p) | ||
581 | return -EAGAIN; | ||
582 | if (signal_pending(current)) | ||
583 | return sock_intr_errno(*timeo_p); | ||
584 | |||
585 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); | ||
586 | done = sk_wait_event(sk, timeo_p, !tport->congested); | ||
587 | finish_wait(sk_sleep(sk), &wait); | ||
588 | } while (!done); | ||
589 | return 0; | ||
590 | } | ||
591 | |||
573 | /** | 592 | /** |
574 | * send_msg - send message in connectionless manner | 593 | * send_msg - send message in connectionless manner |
575 | * @iocb: if NULL, indicates that socket lock is already held | 594 | * @iocb: if NULL, indicates that socket lock is already held |
@@ -589,9 +608,9 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, | |||
589 | { | 608 | { |
590 | struct sock *sk = sock->sk; | 609 | struct sock *sk = sock->sk; |
591 | struct tipc_port *tport = tipc_sk_port(sk); | 610 | struct tipc_port *tport = tipc_sk_port(sk); |
592 | struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; | 611 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); |
593 | int needs_conn; | 612 | int needs_conn; |
594 | long timeout_val; | 613 | long timeo; |
595 | int res = -EINVAL; | 614 | int res = -EINVAL; |
596 | 615 | ||
597 | if (unlikely(!dest)) | 616 | if (unlikely(!dest)) |
@@ -628,8 +647,7 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, | |||
628 | reject_rx_queue(sk); | 647 | reject_rx_queue(sk); |
629 | } | 648 | } |
630 | 649 | ||
631 | timeout_val = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); | 650 | timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); |
632 | |||
633 | do { | 651 | do { |
634 | if (dest->addrtype == TIPC_ADDR_NAME) { | 652 | if (dest->addrtype == TIPC_ADDR_NAME) { |
635 | res = dest_name_check(dest, m); | 653 | res = dest_name_check(dest, m); |
@@ -663,14 +681,9 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, | |||
663 | sock->state = SS_CONNECTING; | 681 | sock->state = SS_CONNECTING; |
664 | break; | 682 | break; |
665 | } | 683 | } |
666 | if (timeout_val <= 0L) { | 684 | res = tipc_wait_for_sndmsg(sock, &timeo); |
667 | res = timeout_val ? timeout_val : -EWOULDBLOCK; | 685 | if (res) |
668 | break; | 686 | break; |
669 | } | ||
670 | release_sock(sk); | ||
671 | timeout_val = wait_event_interruptible_timeout(*sk_sleep(sk), | ||
672 | !tport->congested, timeout_val); | ||
673 | lock_sock(sk); | ||
674 | } while (1); | 687 | } while (1); |
675 | 688 | ||
676 | exit: | 689 | exit: |
@@ -679,6 +692,34 @@ exit: | |||
679 | return res; | 692 | return res; |
680 | } | 693 | } |
681 | 694 | ||
695 | static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p) | ||
696 | { | ||
697 | struct sock *sk = sock->sk; | ||
698 | struct tipc_port *tport = tipc_sk_port(sk); | ||
699 | DEFINE_WAIT(wait); | ||
700 | int done; | ||
701 | |||
702 | do { | ||
703 | int err = sock_error(sk); | ||
704 | if (err) | ||
705 | return err; | ||
706 | if (sock->state == SS_DISCONNECTING) | ||
707 | return -EPIPE; | ||
708 | else if (sock->state != SS_CONNECTED) | ||
709 | return -ENOTCONN; | ||
710 | if (!*timeo_p) | ||
711 | return -EAGAIN; | ||
712 | if (signal_pending(current)) | ||
713 | return sock_intr_errno(*timeo_p); | ||
714 | |||
715 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); | ||
716 | done = sk_wait_event(sk, timeo_p, | ||
717 | (!tport->congested || !tport->connected)); | ||
718 | finish_wait(sk_sleep(sk), &wait); | ||
719 | } while (!done); | ||
720 | return 0; | ||
721 | } | ||
722 | |||
682 | /** | 723 | /** |
683 | * send_packet - send a connection-oriented message | 724 | * send_packet - send a connection-oriented message |
684 | * @iocb: if NULL, indicates that socket lock is already held | 725 | * @iocb: if NULL, indicates that socket lock is already held |
@@ -695,9 +736,9 @@ static int send_packet(struct kiocb *iocb, struct socket *sock, | |||
695 | { | 736 | { |
696 | struct sock *sk = sock->sk; | 737 | struct sock *sk = sock->sk; |
697 | struct tipc_port *tport = tipc_sk_port(sk); | 738 | struct tipc_port *tport = tipc_sk_port(sk); |
698 | struct sockaddr_tipc *dest = (struct sockaddr_tipc *)m->msg_name; | 739 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); |
699 | long timeout_val; | 740 | int res = -EINVAL; |
700 | int res; | 741 | long timeo; |
701 | 742 | ||
702 | /* Handle implied connection establishment */ | 743 | /* Handle implied connection establishment */ |
703 | if (unlikely(dest)) | 744 | if (unlikely(dest)) |
@@ -709,30 +750,24 @@ static int send_packet(struct kiocb *iocb, struct socket *sock, | |||
709 | if (iocb) | 750 | if (iocb) |
710 | lock_sock(sk); | 751 | lock_sock(sk); |
711 | 752 | ||
712 | timeout_val = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); | 753 | if (unlikely(sock->state != SS_CONNECTED)) { |
754 | if (sock->state == SS_DISCONNECTING) | ||
755 | res = -EPIPE; | ||
756 | else | ||
757 | res = -ENOTCONN; | ||
758 | goto exit; | ||
759 | } | ||
713 | 760 | ||
761 | timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); | ||
714 | do { | 762 | do { |
715 | if (unlikely(sock->state != SS_CONNECTED)) { | ||
716 | if (sock->state == SS_DISCONNECTING) | ||
717 | res = -EPIPE; | ||
718 | else | ||
719 | res = -ENOTCONN; | ||
720 | break; | ||
721 | } | ||
722 | |||
723 | res = tipc_send(tport->ref, m->msg_iov, total_len); | 763 | res = tipc_send(tport->ref, m->msg_iov, total_len); |
724 | if (likely(res != -ELINKCONG)) | 764 | if (likely(res != -ELINKCONG)) |
725 | break; | 765 | break; |
726 | if (timeout_val <= 0L) { | 766 | res = tipc_wait_for_sndpkt(sock, &timeo); |
727 | res = timeout_val ? timeout_val : -EWOULDBLOCK; | 767 | if (res) |
728 | break; | 768 | break; |
729 | } | ||
730 | release_sock(sk); | ||
731 | timeout_val = wait_event_interruptible_timeout(*sk_sleep(sk), | ||
732 | (!tport->congested || !tport->connected), timeout_val); | ||
733 | lock_sock(sk); | ||
734 | } while (1); | 769 | } while (1); |
735 | 770 | exit: | |
736 | if (iocb) | 771 | if (iocb) |
737 | release_sock(sk); | 772 | release_sock(sk); |
738 | return res; | 773 | return res; |
@@ -770,16 +805,11 @@ static int send_stream(struct kiocb *iocb, struct socket *sock, | |||
770 | 805 | ||
771 | /* Handle special cases where there is no connection */ | 806 | /* Handle special cases where there is no connection */ |
772 | if (unlikely(sock->state != SS_CONNECTED)) { | 807 | if (unlikely(sock->state != SS_CONNECTED)) { |
773 | if (sock->state == SS_UNCONNECTED) { | 808 | if (sock->state == SS_UNCONNECTED) |
774 | res = send_packet(NULL, sock, m, total_len); | 809 | res = send_packet(NULL, sock, m, total_len); |
775 | goto exit; | 810 | else |
776 | } else if (sock->state == SS_DISCONNECTING) { | 811 | res = sock->state == SS_DISCONNECTING ? -EPIPE : -ENOTCONN; |
777 | res = -EPIPE; | 812 | goto exit; |
778 | goto exit; | ||
779 | } else { | ||
780 | res = -ENOTCONN; | ||
781 | goto exit; | ||
782 | } | ||
783 | } | 813 | } |
784 | 814 | ||
785 | if (unlikely(m->msg_name)) { | 815 | if (unlikely(m->msg_name)) { |
@@ -876,7 +906,7 @@ static int auto_connect(struct socket *sock, struct tipc_msg *msg) | |||
876 | */ | 906 | */ |
877 | static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) | 907 | static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) |
878 | { | 908 | { |
879 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)m->msg_name; | 909 | DECLARE_SOCKADDR(struct sockaddr_tipc *, addr, m->msg_name); |
880 | 910 | ||
881 | if (addr) { | 911 | if (addr) { |
882 | addr->family = AF_TIPC; | 912 | addr->family = AF_TIPC; |
@@ -961,6 +991,37 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | |||
961 | return 0; | 991 | return 0; |
962 | } | 992 | } |
963 | 993 | ||
994 | static int tipc_wait_for_rcvmsg(struct socket *sock, long timeo) | ||
995 | { | ||
996 | struct sock *sk = sock->sk; | ||
997 | DEFINE_WAIT(wait); | ||
998 | int err; | ||
999 | |||
1000 | for (;;) { | ||
1001 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); | ||
1002 | if (skb_queue_empty(&sk->sk_receive_queue)) { | ||
1003 | if (sock->state == SS_DISCONNECTING) { | ||
1004 | err = -ENOTCONN; | ||
1005 | break; | ||
1006 | } | ||
1007 | release_sock(sk); | ||
1008 | timeo = schedule_timeout(timeo); | ||
1009 | lock_sock(sk); | ||
1010 | } | ||
1011 | err = 0; | ||
1012 | if (!skb_queue_empty(&sk->sk_receive_queue)) | ||
1013 | break; | ||
1014 | err = sock_intr_errno(timeo); | ||
1015 | if (signal_pending(current)) | ||
1016 | break; | ||
1017 | err = -EAGAIN; | ||
1018 | if (!timeo) | ||
1019 | break; | ||
1020 | } | ||
1021 | finish_wait(sk_sleep(sk), &wait); | ||
1022 | return err; | ||
1023 | } | ||
1024 | |||
964 | /** | 1025 | /** |
965 | * recv_msg - receive packet-oriented message | 1026 | * recv_msg - receive packet-oriented message |
966 | * @iocb: (unused) | 1027 | * @iocb: (unused) |
@@ -980,7 +1041,7 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock, | |||
980 | struct tipc_port *tport = tipc_sk_port(sk); | 1041 | struct tipc_port *tport = tipc_sk_port(sk); |
981 | struct sk_buff *buf; | 1042 | struct sk_buff *buf; |
982 | struct tipc_msg *msg; | 1043 | struct tipc_msg *msg; |
983 | long timeout; | 1044 | long timeo; |
984 | unsigned int sz; | 1045 | unsigned int sz; |
985 | u32 err; | 1046 | u32 err; |
986 | int res; | 1047 | int res; |
@@ -996,25 +1057,13 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock, | |||
996 | goto exit; | 1057 | goto exit; |
997 | } | 1058 | } |
998 | 1059 | ||
999 | timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); | 1060 | timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); |
1000 | restart: | 1061 | restart: |
1001 | 1062 | ||
1002 | /* Look for a message in receive queue; wait if necessary */ | 1063 | /* Look for a message in receive queue; wait if necessary */ |
1003 | while (skb_queue_empty(&sk->sk_receive_queue)) { | 1064 | res = tipc_wait_for_rcvmsg(sock, timeo); |
1004 | if (sock->state == SS_DISCONNECTING) { | 1065 | if (res) |
1005 | res = -ENOTCONN; | 1066 | goto exit; |
1006 | goto exit; | ||
1007 | } | ||
1008 | if (timeout <= 0L) { | ||
1009 | res = timeout ? timeout : -EWOULDBLOCK; | ||
1010 | goto exit; | ||
1011 | } | ||
1012 | release_sock(sk); | ||
1013 | timeout = wait_event_interruptible_timeout(*sk_sleep(sk), | ||
1014 | tipc_rx_ready(sock), | ||
1015 | timeout); | ||
1016 | lock_sock(sk); | ||
1017 | } | ||
1018 | 1067 | ||
1019 | /* Look at first message in receive queue */ | 1068 | /* Look at first message in receive queue */ |
1020 | buf = skb_peek(&sk->sk_receive_queue); | 1069 | buf = skb_peek(&sk->sk_receive_queue); |
@@ -1086,7 +1135,7 @@ static int recv_stream(struct kiocb *iocb, struct socket *sock, | |||
1086 | struct tipc_port *tport = tipc_sk_port(sk); | 1135 | struct tipc_port *tport = tipc_sk_port(sk); |
1087 | struct sk_buff *buf; | 1136 | struct sk_buff *buf; |
1088 | struct tipc_msg *msg; | 1137 | struct tipc_msg *msg; |
1089 | long timeout; | 1138 | long timeo; |
1090 | unsigned int sz; | 1139 | unsigned int sz; |
1091 | int sz_to_copy, target, needed; | 1140 | int sz_to_copy, target, needed; |
1092 | int sz_copied = 0; | 1141 | int sz_copied = 0; |
@@ -1099,31 +1148,19 @@ static int recv_stream(struct kiocb *iocb, struct socket *sock, | |||
1099 | 1148 | ||
1100 | lock_sock(sk); | 1149 | lock_sock(sk); |
1101 | 1150 | ||
1102 | if (unlikely((sock->state == SS_UNCONNECTED))) { | 1151 | if (unlikely(sock->state == SS_UNCONNECTED)) { |
1103 | res = -ENOTCONN; | 1152 | res = -ENOTCONN; |
1104 | goto exit; | 1153 | goto exit; |
1105 | } | 1154 | } |
1106 | 1155 | ||
1107 | target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len); | 1156 | target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len); |
1108 | timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); | 1157 | timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); |
1109 | 1158 | ||
1110 | restart: | 1159 | restart: |
1111 | /* Look for a message in receive queue; wait if necessary */ | 1160 | /* Look for a message in receive queue; wait if necessary */ |
1112 | while (skb_queue_empty(&sk->sk_receive_queue)) { | 1161 | res = tipc_wait_for_rcvmsg(sock, timeo); |
1113 | if (sock->state == SS_DISCONNECTING) { | 1162 | if (res) |
1114 | res = -ENOTCONN; | 1163 | goto exit; |
1115 | goto exit; | ||
1116 | } | ||
1117 | if (timeout <= 0L) { | ||
1118 | res = timeout ? timeout : -EWOULDBLOCK; | ||
1119 | goto exit; | ||
1120 | } | ||
1121 | release_sock(sk); | ||
1122 | timeout = wait_event_interruptible_timeout(*sk_sleep(sk), | ||
1123 | tipc_rx_ready(sock), | ||
1124 | timeout); | ||
1125 | lock_sock(sk); | ||
1126 | } | ||
1127 | 1164 | ||
1128 | /* Look at first message in receive queue */ | 1165 | /* Look at first message in receive queue */ |
1129 | buf = skb_peek(&sk->sk_receive_queue); | 1166 | buf = skb_peek(&sk->sk_receive_queue); |
@@ -1327,14 +1364,12 @@ static u32 filter_connect(struct tipc_sock *tsock, struct sk_buff **buf) | |||
1327 | static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf) | 1364 | static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf) |
1328 | { | 1365 | { |
1329 | struct tipc_msg *msg = buf_msg(buf); | 1366 | struct tipc_msg *msg = buf_msg(buf); |
1330 | unsigned int limit; | ||
1331 | 1367 | ||
1332 | if (msg_connected(msg)) | 1368 | if (msg_connected(msg)) |
1333 | limit = sysctl_tipc_rmem[2]; | 1369 | return sysctl_tipc_rmem[2]; |
1334 | else | 1370 | |
1335 | limit = sk->sk_rcvbuf >> TIPC_CRITICAL_IMPORTANCE << | 1371 | return sk->sk_rcvbuf >> TIPC_CRITICAL_IMPORTANCE << |
1336 | msg_importance(msg); | 1372 | msg_importance(msg); |
1337 | return limit; | ||
1338 | } | 1373 | } |
1339 | 1374 | ||
1340 | /** | 1375 | /** |
@@ -1448,6 +1483,28 @@ static void wakeupdispatch(struct tipc_port *tport) | |||
1448 | sk->sk_write_space(sk); | 1483 | sk->sk_write_space(sk); |
1449 | } | 1484 | } |
1450 | 1485 | ||
1486 | static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) | ||
1487 | { | ||
1488 | struct sock *sk = sock->sk; | ||
1489 | DEFINE_WAIT(wait); | ||
1490 | int done; | ||
1491 | |||
1492 | do { | ||
1493 | int err = sock_error(sk); | ||
1494 | if (err) | ||
1495 | return err; | ||
1496 | if (!*timeo_p) | ||
1497 | return -ETIMEDOUT; | ||
1498 | if (signal_pending(current)) | ||
1499 | return sock_intr_errno(*timeo_p); | ||
1500 | |||
1501 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); | ||
1502 | done = sk_wait_event(sk, timeo_p, sock->state != SS_CONNECTING); | ||
1503 | finish_wait(sk_sleep(sk), &wait); | ||
1504 | } while (!done); | ||
1505 | return 0; | ||
1506 | } | ||
1507 | |||
1451 | /** | 1508 | /** |
1452 | * connect - establish a connection to another TIPC port | 1509 | * connect - establish a connection to another TIPC port |
1453 | * @sock: socket structure | 1510 | * @sock: socket structure |
@@ -1463,7 +1520,8 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1463 | struct sock *sk = sock->sk; | 1520 | struct sock *sk = sock->sk; |
1464 | struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest; | 1521 | struct sockaddr_tipc *dst = (struct sockaddr_tipc *)dest; |
1465 | struct msghdr m = {NULL,}; | 1522 | struct msghdr m = {NULL,}; |
1466 | unsigned int timeout; | 1523 | long timeout = (flags & O_NONBLOCK) ? 0 : tipc_sk(sk)->conn_timeout; |
1524 | socket_state previous; | ||
1467 | int res; | 1525 | int res; |
1468 | 1526 | ||
1469 | lock_sock(sk); | 1527 | lock_sock(sk); |
@@ -1485,8 +1543,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1485 | goto exit; | 1543 | goto exit; |
1486 | } | 1544 | } |
1487 | 1545 | ||
1488 | timeout = (flags & O_NONBLOCK) ? 0 : tipc_sk(sk)->conn_timeout; | 1546 | previous = sock->state; |
1489 | |||
1490 | switch (sock->state) { | 1547 | switch (sock->state) { |
1491 | case SS_UNCONNECTED: | 1548 | case SS_UNCONNECTED: |
1492 | /* Send a 'SYN-' to destination */ | 1549 | /* Send a 'SYN-' to destination */ |
@@ -1508,43 +1565,22 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, | |||
1508 | * case is EINPROGRESS, rather than EALREADY. | 1565 | * case is EINPROGRESS, rather than EALREADY. |
1509 | */ | 1566 | */ |
1510 | res = -EINPROGRESS; | 1567 | res = -EINPROGRESS; |
1511 | break; | ||
1512 | case SS_CONNECTING: | 1568 | case SS_CONNECTING: |
1513 | res = -EALREADY; | 1569 | if (previous == SS_CONNECTING) |
1570 | res = -EALREADY; | ||
1571 | if (!timeout) | ||
1572 | goto exit; | ||
1573 | timeout = msecs_to_jiffies(timeout); | ||
1574 | /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */ | ||
1575 | res = tipc_wait_for_connect(sock, &timeout); | ||
1514 | break; | 1576 | break; |
1515 | case SS_CONNECTED: | 1577 | case SS_CONNECTED: |
1516 | res = -EISCONN; | 1578 | res = -EISCONN; |
1517 | break; | 1579 | break; |
1518 | default: | 1580 | default: |
1519 | res = -EINVAL; | 1581 | res = -EINVAL; |
1520 | goto exit; | 1582 | break; |
1521 | } | ||
1522 | |||
1523 | if (sock->state == SS_CONNECTING) { | ||
1524 | if (!timeout) | ||
1525 | goto exit; | ||
1526 | |||
1527 | /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */ | ||
1528 | release_sock(sk); | ||
1529 | res = wait_event_interruptible_timeout(*sk_sleep(sk), | ||
1530 | sock->state != SS_CONNECTING, | ||
1531 | timeout ? (long)msecs_to_jiffies(timeout) | ||
1532 | : MAX_SCHEDULE_TIMEOUT); | ||
1533 | lock_sock(sk); | ||
1534 | if (res <= 0) { | ||
1535 | if (res == 0) | ||
1536 | res = -ETIMEDOUT; | ||
1537 | else | ||
1538 | ; /* leave "res" unchanged */ | ||
1539 | goto exit; | ||
1540 | } | ||
1541 | } | 1583 | } |
1542 | |||
1543 | if (unlikely(sock->state == SS_DISCONNECTING)) | ||
1544 | res = sock_error(sk); | ||
1545 | else | ||
1546 | res = 0; | ||
1547 | |||
1548 | exit: | 1584 | exit: |
1549 | release_sock(sk); | 1585 | release_sock(sk); |
1550 | return res; | 1586 | return res; |
@@ -1575,6 +1611,42 @@ static int listen(struct socket *sock, int len) | |||
1575 | return res; | 1611 | return res; |
1576 | } | 1612 | } |
1577 | 1613 | ||
1614 | static int tipc_wait_for_accept(struct socket *sock, long timeo) | ||
1615 | { | ||
1616 | struct sock *sk = sock->sk; | ||
1617 | DEFINE_WAIT(wait); | ||
1618 | int err; | ||
1619 | |||
1620 | /* True wake-one mechanism for incoming connections: only | ||
1621 | * one process gets woken up, not the 'whole herd'. | ||
1622 | * Since we do not 'race & poll' for established sockets | ||
1623 | * anymore, the common case will execute the loop only once. | ||
1624 | */ | ||
1625 | for (;;) { | ||
1626 | prepare_to_wait_exclusive(sk_sleep(sk), &wait, | ||
1627 | TASK_INTERRUPTIBLE); | ||
1628 | if (skb_queue_empty(&sk->sk_receive_queue)) { | ||
1629 | release_sock(sk); | ||
1630 | timeo = schedule_timeout(timeo); | ||
1631 | lock_sock(sk); | ||
1632 | } | ||
1633 | err = 0; | ||
1634 | if (!skb_queue_empty(&sk->sk_receive_queue)) | ||
1635 | break; | ||
1636 | err = -EINVAL; | ||
1637 | if (sock->state != SS_LISTENING) | ||
1638 | break; | ||
1639 | err = sock_intr_errno(timeo); | ||
1640 | if (signal_pending(current)) | ||
1641 | break; | ||
1642 | err = -EAGAIN; | ||
1643 | if (!timeo) | ||
1644 | break; | ||
1645 | } | ||
1646 | finish_wait(sk_sleep(sk), &wait); | ||
1647 | return err; | ||
1648 | } | ||
1649 | |||
1578 | /** | 1650 | /** |
1579 | * accept - wait for connection request | 1651 | * accept - wait for connection request |
1580 | * @sock: listening socket | 1652 | * @sock: listening socket |
@@ -1591,7 +1663,7 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags) | |||
1591 | struct tipc_port *new_tport; | 1663 | struct tipc_port *new_tport; |
1592 | struct tipc_msg *msg; | 1664 | struct tipc_msg *msg; |
1593 | u32 new_ref; | 1665 | u32 new_ref; |
1594 | 1666 | long timeo; | |
1595 | int res; | 1667 | int res; |
1596 | 1668 | ||
1597 | lock_sock(sk); | 1669 | lock_sock(sk); |
@@ -1601,18 +1673,10 @@ static int accept(struct socket *sock, struct socket *new_sock, int flags) | |||
1601 | goto exit; | 1673 | goto exit; |
1602 | } | 1674 | } |
1603 | 1675 | ||
1604 | while (skb_queue_empty(&sk->sk_receive_queue)) { | 1676 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
1605 | if (flags & O_NONBLOCK) { | 1677 | res = tipc_wait_for_accept(sock, timeo); |
1606 | res = -EWOULDBLOCK; | 1678 | if (res) |
1607 | goto exit; | 1679 | goto exit; |
1608 | } | ||
1609 | release_sock(sk); | ||
1610 | res = wait_event_interruptible(*sk_sleep(sk), | ||
1611 | (!skb_queue_empty(&sk->sk_receive_queue))); | ||
1612 | lock_sock(sk); | ||
1613 | if (res) | ||
1614 | goto exit; | ||
1615 | } | ||
1616 | 1680 | ||
1617 | buf = skb_peek(&sk->sk_receive_queue); | 1681 | buf = skb_peek(&sk->sk_receive_queue); |
1618 | 1682 | ||
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c index d38bb45d82e9..7cb0bd5b1176 100644 --- a/net/tipc/subscr.c +++ b/net/tipc/subscr.c | |||
@@ -42,7 +42,7 @@ | |||
42 | /** | 42 | /** |
43 | * struct tipc_subscriber - TIPC network topology subscriber | 43 | * struct tipc_subscriber - TIPC network topology subscriber |
44 | * @conid: connection identifier to server connecting to subscriber | 44 | * @conid: connection identifier to server connecting to subscriber |
45 | * @lock: controll access to subscriber | 45 | * @lock: control access to subscriber |
46 | * @subscription_list: list of subscription objects for this subscriber | 46 | * @subscription_list: list of subscription objects for this subscriber |
47 | */ | 47 | */ |
48 | struct tipc_subscriber { | 48 | struct tipc_subscriber { |