hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/net/tipc/node.c
....@@ -43,6 +43,8 @@
4343 #include "monitor.h"
4444 #include "discover.h"
4545 #include "netlink.h"
46
+#include "trace.h"
47
+#include "crypto.h"
4648
4749 #define INVALID_NODE_SIG 0x10000
4850 #define NODE_CLEANUP_AFTER 300000
....@@ -73,6 +75,8 @@
7375 struct sk_buff_head arrvq;
7476 struct sk_buff_head inputq2;
7577 struct sk_buff_head namedq;
78
+ u16 named_rcv_nxt;
79
+ bool named_open;
7680 };
7781
7882 /**
....@@ -88,6 +92,7 @@
8892 * @links: array containing references to all links to node
8993 * @action_flags: bit mask of different types of node actions
9094 * @state: connectivity state vs peer node
95
+ * @preliminary: a preliminary node or not
9196 * @sync_point: sequence number where synch/failover is finished
9297 * @list: links to adjacent nodes in sorted list of cluster's nodes
9398 * @working_links: number of working links to node (both active and standby)
....@@ -98,6 +103,7 @@
98103 * @publ_list: list of publications
99104 * @rcu: rcu struct for tipc_node
100105 * @delete_at: indicates the time for deleting a down node
106
+ * @crypto_rx: RX crypto handler
101107 */
102108 struct tipc_node {
103109 u32 addr;
....@@ -111,6 +117,7 @@
111117 int action_flags;
112118 struct list_head list;
113119 int state;
120
+ bool preliminary;
114121 bool failover_sent;
115122 u16 sync_point;
116123 int link_cnt;
....@@ -119,12 +126,18 @@
119126 u32 signature;
120127 u32 link_id;
121128 u8 peer_id[16];
129
+ char peer_id_string[NODE_ID_STR_LEN];
122130 struct list_head publ_list;
123131 struct list_head conn_sks;
124132 unsigned long keepalive_intv;
125133 struct timer_list timer;
126134 struct rcu_head rcu;
127135 unsigned long delete_at;
136
+ struct net *peer_net;
137
+ u32 peer_hash_mix;
138
+#ifdef CONFIG_TIPC_CRYPTO
139
+ struct tipc_crypto *crypto_rx;
140
+#endif
128141 };
129142
130143 /* Node FSM states and events:
....@@ -162,7 +175,6 @@
162175 static void tipc_node_fsm_evt(struct tipc_node *n, int evt);
163176 static struct tipc_node *tipc_node_find(struct net *net, u32 addr);
164177 static struct tipc_node *tipc_node_find_by_id(struct net *net, u8 *id);
165
-static void tipc_node_put(struct tipc_node *node);
166178 static bool node_is_up(struct tipc_node *n);
167179 static void tipc_node_delete_from_list(struct tipc_node *node);
168180
....@@ -183,7 +195,7 @@
183195 return n->links[bearer_id].link;
184196 }
185197
186
-int tipc_node_get_mtu(struct net *net, u32 addr, u32 sel)
198
+int tipc_node_get_mtu(struct net *net, u32 addr, u32 sel, bool connected)
187199 {
188200 struct tipc_node *n;
189201 int bearer_id;
....@@ -192,6 +204,14 @@
192204 n = tipc_node_find(net, addr);
193205 if (unlikely(!n))
194206 return mtu;
207
+
208
+ /* Allow MAX_MSG_SIZE when building connection oriented message
209
+ * if they are in the same core network
210
+ */
211
+ if (n->peer_net && connected) {
212
+ tipc_node_put(n);
213
+ return mtu;
214
+ }
195215
196216 bearer_id = n->active_links[sel & 1];
197217 if (likely(bearer_id != INVALID_BEARER_ID))
....@@ -234,20 +254,64 @@
234254 return caps;
235255 }
236256
257
+u32 tipc_node_get_addr(struct tipc_node *node)
258
+{
259
+ return (node) ? node->addr : 0;
260
+}
261
+
262
+char *tipc_node_get_id_str(struct tipc_node *node)
263
+{
264
+ return node->peer_id_string;
265
+}
266
+
267
+#ifdef CONFIG_TIPC_CRYPTO
268
+/**
269
+ * tipc_node_crypto_rx - Retrieve crypto RX handle from node
270
+ * Note: node ref counter must be held first!
271
+ */
272
+struct tipc_crypto *tipc_node_crypto_rx(struct tipc_node *__n)
273
+{
274
+ return (__n) ? __n->crypto_rx : NULL;
275
+}
276
+
277
+struct tipc_crypto *tipc_node_crypto_rx_by_list(struct list_head *pos)
278
+{
279
+ return container_of(pos, struct tipc_node, list)->crypto_rx;
280
+}
281
+
282
+struct tipc_crypto *tipc_node_crypto_rx_by_addr(struct net *net, u32 addr)
283
+{
284
+ struct tipc_node *n;
285
+
286
+ n = tipc_node_find(net, addr);
287
+ return (n) ? n->crypto_rx : NULL;
288
+}
289
+#endif
290
+
291
+static void tipc_node_free(struct rcu_head *rp)
292
+{
293
+ struct tipc_node *n = container_of(rp, struct tipc_node, rcu);
294
+
295
+#ifdef CONFIG_TIPC_CRYPTO
296
+ tipc_crypto_stop(&n->crypto_rx);
297
+#endif
298
+ kfree(n);
299
+}
300
+
237301 static void tipc_node_kref_release(struct kref *kref)
238302 {
239303 struct tipc_node *n = container_of(kref, struct tipc_node, kref);
240304
241305 kfree(n->bc_entry.link);
242
- kfree_rcu(n, rcu);
306
+ call_rcu(&n->rcu, tipc_node_free);
243307 }
244308
245
-static void tipc_node_put(struct tipc_node *node)
309
+void tipc_node_put(struct tipc_node *node)
246310 {
247311 kref_put(&node->kref, tipc_node_kref_release);
248312 }
249313
250
-static void tipc_node_get(struct tipc_node *node)
314
+void tipc_node_get(struct tipc_node *node)
251315 {
252316 kref_get(&node->kref);
253317 }
....@@ -263,7 +327,7 @@
263327
264328 rcu_read_lock();
265329 hlist_for_each_entry_rcu(node, &tn->node_htable[thash], hash) {
266
- if (node->addr != addr)
330
+ if (node->addr != addr || node->preliminary)
267331 continue;
268332 if (!kref_get_unless_zero(&node->kref))
269333 node = NULL;
....@@ -342,10 +406,10 @@
342406 write_unlock_bh(&n->lock);
343407
344408 if (flags & TIPC_NOTIFY_NODE_DOWN)
345
- tipc_publ_notify(net, publ_list, addr);
409
+ tipc_publ_notify(net, publ_list, addr, n->capabilities);
346410
347411 if (flags & TIPC_NOTIFY_NODE_UP)
348
- tipc_named_node_up(net, addr);
412
+ tipc_named_node_up(net, addr, n->capabilities);
349413
350414 if (flags & TIPC_NOTIFY_LINK_UP) {
351415 tipc_mon_peer_up(net, addr, bearer_id);
....@@ -359,29 +423,102 @@
359423 }
360424 }
361425
362
-static struct tipc_node *tipc_node_create(struct net *net, u32 addr,
363
- u8 *peer_id, u16 capabilities)
426
+static void tipc_node_assign_peer_net(struct tipc_node *n, u32 hash_mixes)
427
+{
428
+ int net_id = tipc_netid(n->net);
429
+ struct tipc_net *tn_peer;
430
+ struct net *tmp;
431
+ u32 hash_chk;
432
+
433
+ if (n->peer_net)
434
+ return;
435
+
436
+ for_each_net_rcu(tmp) {
437
+ tn_peer = tipc_net(tmp);
438
+ if (!tn_peer)
439
+ continue;
440
+ /* Integrity checking whether node exists in namespace or not */
441
+ if (tn_peer->net_id != net_id)
442
+ continue;
443
+ if (memcmp(n->peer_id, tn_peer->node_id, NODE_ID_LEN))
444
+ continue;
445
+ hash_chk = tipc_net_hash_mixes(tmp, tn_peer->random);
446
+ if (hash_mixes ^ hash_chk)
447
+ continue;
448
+ n->peer_net = tmp;
449
+ n->peer_hash_mix = hash_mixes;
450
+ break;
451
+ }
452
+}
453
+
454
+struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
455
+ u16 capabilities, u32 hash_mixes,
456
+ bool preliminary)
364457 {
365458 struct tipc_net *tn = net_generic(net, tipc_net_id);
459
+ struct tipc_link *l, *snd_l = tipc_bc_sndlink(net);
366460 struct tipc_node *n, *temp_node;
367
- struct tipc_link *l;
461
+ unsigned long intv;
368462 int bearer_id;
369463 int i;
370464
371465 spin_lock_bh(&tn->node_list_lock);
372
- n = tipc_node_find(net, addr);
466
+ n = tipc_node_find(net, addr) ?:
467
+ tipc_node_find_by_id(net, peer_id);
373468 if (n) {
469
+ if (!n->preliminary)
470
+ goto update;
471
+ if (preliminary)
472
+ goto exit;
473
+ /* A preliminary node becomes "real" now, refresh its data */
474
+ tipc_node_write_lock(n);
475
+ if (!tipc_link_bc_create(net, tipc_own_addr(net), addr, peer_id, U16_MAX,
476
+ tipc_link_min_win(snd_l), tipc_link_max_win(snd_l),
477
+ n->capabilities, &n->bc_entry.inputq1,
478
+ &n->bc_entry.namedq, snd_l, &n->bc_entry.link)) {
479
+ pr_warn("Broadcast rcv link refresh failed, no memory\n");
480
+ tipc_node_write_unlock_fast(n);
481
+ tipc_node_put(n);
482
+ n = NULL;
483
+ goto exit;
484
+ }
485
+ n->preliminary = false;
486
+ n->addr = addr;
487
+ hlist_del_rcu(&n->hash);
488
+ hlist_add_head_rcu(&n->hash,
489
+ &tn->node_htable[tipc_hashfn(addr)]);
490
+ list_del_rcu(&n->list);
491
+ list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
492
+ if (n->addr < temp_node->addr)
493
+ break;
494
+ }
495
+ list_add_tail_rcu(&n->list, &temp_node->list);
496
+ tipc_node_write_unlock_fast(n);
497
+
498
+update:
499
+ if (n->peer_hash_mix ^ hash_mixes)
500
+ tipc_node_assign_peer_net(n, hash_mixes);
374501 if (n->capabilities == capabilities)
375502 goto exit;
376503 /* Same node may come back with new capabilities */
377
- write_lock_bh(&n->lock);
504
+ tipc_node_write_lock(n);
378505 n->capabilities = capabilities;
379506 for (bearer_id = 0; bearer_id < MAX_BEARERS; bearer_id++) {
380507 l = n->links[bearer_id].link;
381508 if (l)
382509 tipc_link_update_caps(l, capabilities);
383510 }
384
- write_unlock_bh(&n->lock);
511
+ tipc_node_write_unlock_fast(n);
512
+
513
+ /* Calculate cluster capabilities */
514
+ tn->capabilities = TIPC_NODE_CAPABILITIES;
515
+ list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
516
+ tn->capabilities &= temp_node->capabilities;
517
+ }
518
+
519
+ tipc_bcast_toggle_rcast(net,
520
+ (tn->capabilities & TIPC_BCAST_RCAST));
521
+
385522 goto exit;
386523 }
387524 n = kzalloc(sizeof(*n), GFP_ATOMIC);
....@@ -389,9 +526,23 @@
389526 pr_warn("Node creation failed, no memory\n");
390527 goto exit;
391528 }
529
+ tipc_nodeid2string(n->peer_id_string, peer_id);
530
+#ifdef CONFIG_TIPC_CRYPTO
531
+ if (unlikely(tipc_crypto_start(&n->crypto_rx, net, n))) {
532
+ pr_warn("Failed to start crypto RX(%s)!\n", n->peer_id_string);
533
+ kfree(n);
534
+ n = NULL;
535
+ goto exit;
536
+ }
537
+#endif
392538 n->addr = addr;
539
+ n->preliminary = preliminary;
393540 memcpy(&n->peer_id, peer_id, 16);
394541 n->net = net;
542
+ n->peer_net = NULL;
543
+ n->peer_hash_mix = 0;
544
+ /* Assign kernel local namespace if exists */
545
+ tipc_node_assign_peer_net(n, hash_mixes);
395546 n->capabilities = capabilities;
396547 kref_init(&n->kref);
397548 rwlock_init(&n->lock);
....@@ -410,28 +561,36 @@
410561 n->signature = INVALID_NODE_SIG;
411562 n->active_links[0] = INVALID_BEARER_ID;
412563 n->active_links[1] = INVALID_BEARER_ID;
413
- if (!tipc_link_bc_create(net, tipc_own_addr(net),
414
- addr, U16_MAX,
415
- tipc_link_window(tipc_bc_sndlink(net)),
416
- n->capabilities,
417
- &n->bc_entry.inputq1,
418
- &n->bc_entry.namedq,
419
- tipc_bc_sndlink(net),
420
- &n->bc_entry.link)) {
564
+ if (!preliminary &&
565
+ !tipc_link_bc_create(net, tipc_own_addr(net), addr, peer_id, U16_MAX,
566
+ tipc_link_min_win(snd_l), tipc_link_max_win(snd_l),
567
+ n->capabilities, &n->bc_entry.inputq1,
568
+ &n->bc_entry.namedq, snd_l, &n->bc_entry.link)) {
421569 pr_warn("Broadcast rcv link creation failed, no memory\n");
422
- kfree(n);
570
+ tipc_node_put(n);
423571 n = NULL;
424572 goto exit;
425573 }
426574 tipc_node_get(n);
427575 timer_setup(&n->timer, tipc_node_timeout, 0);
428
- n->keepalive_intv = U32_MAX;
576
+ /* Start a slow timer anyway, crypto needs it */
577
+ n->keepalive_intv = 10000;
578
+ intv = jiffies + msecs_to_jiffies(n->keepalive_intv);
579
+ if (!mod_timer(&n->timer, intv))
580
+ tipc_node_get(n);
429581 hlist_add_head_rcu(&n->hash, &tn->node_htable[tipc_hashfn(addr)]);
430582 list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
431583 if (n->addr < temp_node->addr)
432584 break;
433585 }
434586 list_add_tail_rcu(&n->list, &temp_node->list);
587
+ /* Calculate cluster capabilities */
588
+ tn->capabilities = TIPC_NODE_CAPABILITIES;
589
+ list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
590
+ tn->capabilities &= temp_node->capabilities;
591
+ }
592
+ tipc_bcast_toggle_rcast(net, (tn->capabilities & TIPC_BCAST_RCAST));
593
+ trace_tipc_node_create(n, true, " ");
435594 exit:
436595 spin_unlock_bh(&tn->node_list_lock);
437596 return n;
....@@ -452,6 +611,9 @@
452611
453612 static void tipc_node_delete_from_list(struct tipc_node *node)
454613 {
614
+#ifdef CONFIG_TIPC_CRYPTO
615
+ tipc_crypto_key_flush(node->crypto_rx);
616
+#endif
455617 list_del_rcu(&node->list);
456618 hlist_del_rcu(&node->hash);
457619 tipc_node_put(node);
....@@ -459,6 +621,7 @@
459621
460622 static void tipc_node_delete(struct tipc_node *node)
461623 {
624
+ trace_tipc_node_delete(node, true, " ");
462625 tipc_node_delete_from_list(node);
463626
464627 del_timer_sync(&node->timer);
....@@ -586,6 +749,7 @@
586749 */
587750 static bool tipc_node_cleanup(struct tipc_node *peer)
588751 {
752
+ struct tipc_node *temp_node;
589753 struct tipc_net *tn = tipc_net(peer->net);
590754 bool deleted = false;
591755
....@@ -601,6 +765,19 @@
601765 deleted = true;
602766 }
603767 tipc_node_write_unlock(peer);
768
+
769
+ if (!deleted) {
770
+ spin_unlock_bh(&tn->node_list_lock);
771
+ return deleted;
772
+ }
773
+
774
+ /* Calculate cluster capabilities */
775
+ tn->capabilities = TIPC_NODE_CAPABILITIES;
776
+ list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
777
+ tn->capabilities &= temp_node->capabilities;
778
+ }
779
+ tipc_bcast_toggle_rcast(peer->net,
780
+ (tn->capabilities & TIPC_BCAST_RCAST));
604781 spin_unlock_bh(&tn->node_list_lock);
605782 return deleted;
606783 }
....@@ -616,12 +793,17 @@
616793 int bearer_id;
617794 int rc = 0;
618795
796
+ trace_tipc_node_timeout(n, false, " ");
619797 if (!node_is_up(n) && tipc_node_cleanup(n)) {
620798 /*Removing the reference of Timer*/
621799 tipc_node_put(n);
622800 return;
623801 }
624802
803
+#ifdef CONFIG_TIPC_CRYPTO
804
+ /* Take any crypto key related actions first */
805
+ tipc_crypto_timeout(n->crypto_rx);
806
+#endif
625807 __skb_queue_head_init(&xmitq);
626808
627809 /* Initial node interval to value larger (10 seconds), then it will be
....@@ -642,7 +824,7 @@
642824 remains--;
643825 }
644826 tipc_node_read_unlock(n);
645
- tipc_bearer_xmit(n->net, bearer_id, &xmitq, &le->maddr);
827
+ tipc_bearer_xmit(n->net, bearer_id, &xmitq, &le->maddr, n);
646828 if (rc & TIPC_LINK_DOWN_EVT)
647829 tipc_node_link_down(n, bearer_id, false);
648830 }
....@@ -674,13 +856,14 @@
674856 n->link_id = tipc_link_id(nl);
675857
676858 /* Leave room for tunnel header when returning 'mtu' to users: */
677
- n->links[bearer_id].mtu = tipc_link_mtu(nl) - INT_H_SIZE;
859
+ n->links[bearer_id].mtu = tipc_link_mss(nl);
678860
679861 tipc_bearer_add_dest(n->net, bearer_id, n->addr);
680862 tipc_bcast_inc_bearer_dst_cnt(n->net, bearer_id);
681863
682864 pr_debug("Established link <%s> on network plane %c\n",
683865 tipc_link_name(nl), tipc_link_plane(nl));
866
+ trace_tipc_node_link_up(n, true, " ");
684867
685868 /* Ensure that a STATE message goes first */
686869 tipc_link_build_state_msg(nl, xmitq);
....@@ -690,7 +873,6 @@
690873 *slot0 = bearer_id;
691874 *slot1 = bearer_id;
692875 tipc_node_fsm_evt(n, SELF_ESTABL_CONTACT_EVT);
693
- n->failover_sent = false;
694876 n->action_flags |= TIPC_NOTIFY_NODE_UP;
695877 tipc_link_set_active(nl, true);
696878 tipc_bcast_add_peer(n->net, nl, xmitq);
....@@ -728,8 +910,51 @@
728910 tipc_node_write_lock(n);
729911 __tipc_node_link_up(n, bearer_id, xmitq);
730912 maddr = &n->links[bearer_id].maddr;
731
- tipc_bearer_xmit(n->net, bearer_id, xmitq, maddr);
913
+ tipc_bearer_xmit(n->net, bearer_id, xmitq, maddr, n);
732914 tipc_node_write_unlock(n);
915
+}
916
+
917
+/**
918
+ * tipc_node_link_failover() - start failover in case "half-failover"
919
+ *
920
+ * This function is only called in a very special situation where link
921
+ * failover can be already started on peer node but not on this node.
922
+ * This can happen when e.g.
923
+ * 1. Both links <1A-2A>, <1B-2B> down
924
+ * 2. Link endpoint 2A up, but 1A still down (e.g. due to network
925
+ * disturbance, wrong session, etc.)
926
+ * 3. Link <1B-2B> up
927
+ * 4. Link endpoint 2A down (e.g. due to link tolerance timeout)
928
+ * 5. Node 2 starts failover onto link <1B-2B>
929
+ *
930
+ * ==> Node 1 does never start link/node failover!
931
+ *
932
+ * @n: tipc node structure
933
+ * @l: link peer endpoint failingover (- can be NULL)
934
+ * @tnl: tunnel link
935
+ * @xmitq: queue for messages to be xmited on tnl link later
936
+ */
937
+static void tipc_node_link_failover(struct tipc_node *n, struct tipc_link *l,
938
+ struct tipc_link *tnl,
939
+ struct sk_buff_head *xmitq)
940
+{
941
+ /* Avoid to be "self-failover" that can never end */
942
+ if (!tipc_link_is_up(tnl))
943
+ return;
944
+
945
+ /* Don't rush, failure link may be in the process of resetting */
946
+ if (l && !tipc_link_is_reset(l))
947
+ return;
948
+
949
+ tipc_link_fsm_evt(tnl, LINK_SYNCH_END_EVT);
950
+ tipc_node_fsm_evt(n, NODE_SYNCH_END_EVT);
951
+
952
+ n->sync_point = tipc_link_rcv_nxt(tnl) + (U16_MAX / 2 - 1);
953
+ tipc_link_failover_prepare(l, tnl, xmitq);
954
+
955
+ if (l)
956
+ tipc_link_fsm_evt(l, LINK_FAILOVER_BEGIN_EVT);
957
+ tipc_node_fsm_evt(n, NODE_FAILOVER_BEGIN_EVT);
733958 }
734959
735960 /**
....@@ -783,6 +1008,7 @@
7831008 if (tipc_link_peer_is_down(l))
7841009 tipc_node_fsm_evt(n, PEER_LOST_CONTACT_EVT);
7851010 tipc_node_fsm_evt(n, SELF_LOST_CONTACT_EVT);
1011
+ trace_tipc_link_reset(l, TIPC_DUMP_ALL, "link down!");
7861012 tipc_link_fsm_evt(l, LINK_RESET_EVT);
7871013 tipc_link_reset(l);
7881014 tipc_link_build_reset_msg(l, xmitq);
....@@ -800,6 +1026,7 @@
8001026 tipc_node_fsm_evt(n, NODE_SYNCH_END_EVT);
8011027 n->sync_point = tipc_link_rcv_nxt(tnl) + (U16_MAX / 2 - 1);
8021028 tipc_link_tnl_prepare(l, tnl, FAILOVER_MSG, xmitq);
1029
+ trace_tipc_link_reset(l, TIPC_DUMP_ALL, "link down -> failover!");
8031030 tipc_link_reset(l);
8041031 tipc_link_fsm_evt(l, LINK_RESET_EVT);
8051032 tipc_link_fsm_evt(l, LINK_FAILOVER_BEGIN_EVT);
....@@ -823,20 +1050,22 @@
8231050 tipc_node_write_lock(n);
8241051 if (!tipc_link_is_establishing(l)) {
8251052 __tipc_node_link_down(n, &bearer_id, &xmitq, &maddr);
826
- if (delete) {
827
- kfree(l);
828
- le->link = NULL;
829
- n->link_cnt--;
830
- }
8311053 } else {
8321054 /* Defuse pending tipc_node_link_up() */
1055
+ tipc_link_reset(l);
8331056 tipc_link_fsm_evt(l, LINK_RESET_EVT);
8341057 }
1058
+ if (delete) {
1059
+ kfree(l);
1060
+ le->link = NULL;
1061
+ n->link_cnt--;
1062
+ }
1063
+ trace_tipc_node_link_down(n, true, "node link down or deleted!");
8351064 tipc_node_write_unlock(n);
8361065 if (delete)
8371066 tipc_mon_remove_peer(n->net, n->addr, old_bearer_id);
8381067 if (!skb_queue_empty(&xmitq))
839
- tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
1068
+ tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr, n);
8401069 tipc_sk_rcv(n->net, &le->inputq);
8411070 }
8421071
....@@ -880,6 +1109,8 @@
8801109 {
8811110 struct tipc_net *tn = tipc_net(net);
8821111 struct tipc_node *n;
1112
+ bool preliminary;
1113
+ u32 sugg_addr;
8831114
8841115 /* Suggest new address if some other peer is using this one */
8851116 n = tipc_node_find(net, addr);
....@@ -895,9 +1126,11 @@
8951126 /* Suggest previously used address if peer is known */
8961127 n = tipc_node_find_by_id(net, id);
8971128 if (n) {
898
- addr = n->addr;
1129
+ sugg_addr = n->addr;
1130
+ preliminary = n->preliminary;
8991131 tipc_node_put(n);
900
- return addr;
1132
+ if (!preliminary)
1133
+ return sugg_addr;
9011134 }
9021135
9031136 /* Even this node may be in conflict */
....@@ -909,7 +1142,7 @@
9091142
9101143 void tipc_node_check_dest(struct net *net, u32 addr,
9111144 u8 *peer_id, struct tipc_bearer *b,
912
- u16 capabilities, u32 signature,
1145
+ u16 capabilities, u32 signature, u32 hash_mixes,
9131146 struct tipc_media_addr *maddr,
9141147 bool *respond, bool *dupl_addr)
9151148 {
....@@ -919,8 +1152,9 @@
9191152 bool addr_match = false;
9201153 bool sign_match = false;
9211154 bool link_up = false;
1155
+ bool link_is_reset = false;
9221156 bool accept_addr = false;
923
- bool reset = true;
1157
+ bool reset = false;
9241158 char *if_name;
9251159 unsigned long intv;
9261160 u16 session;
....@@ -928,7 +1162,8 @@
9281162 *dupl_addr = false;
9291163 *respond = false;
9301164
931
- n = tipc_node_create(net, addr, peer_id, capabilities);
1165
+ n = tipc_node_create(net, addr, peer_id, capabilities, hash_mixes,
1166
+ false);
9321167 if (!n)
9331168 return;
9341169
....@@ -939,14 +1174,17 @@
9391174 /* Prepare to validate requesting node's signature and media address */
9401175 l = le->link;
9411176 link_up = l && tipc_link_is_up(l);
1177
+ link_is_reset = l && tipc_link_is_reset(l);
9421178 addr_match = l && !memcmp(&le->maddr, maddr, sizeof(*maddr));
9431179 sign_match = (signature == n->signature);
9441180
9451181 /* These three flags give us eight permutations: */
9461182
9471183 if (sign_match && addr_match && link_up) {
948
- /* All is fine. Do nothing. */
949
- reset = false;
1184
+ /* All is fine. Ignore requests. */
1185
+ /* Peer node is not a container/local namespace */
1186
+ if (!n->peer_hash_mix)
1187
+ n->peer_hash_mix = hash_mixes;
9501188 } else if (sign_match && addr_match && !link_up) {
9511189 /* Respond. The link will come up in due time */
9521190 *respond = true;
....@@ -968,6 +1206,7 @@
9681206 */
9691207 accept_addr = true;
9701208 *respond = true;
1209
+ reset = true;
9711210 } else if (!sign_match && addr_match && link_up) {
9721211 /* Peer node rebooted. Two possibilities:
9731212 * - Delayed re-discovery; this link endpoint has already
....@@ -999,6 +1238,7 @@
9991238 n->signature = signature;
10001239 accept_addr = true;
10011240 *respond = true;
1241
+ reset = true;
10021242 }
10031243
10041244 if (!accept_addr)
....@@ -1013,7 +1253,7 @@
10131253 get_random_bytes(&session, sizeof(u16));
10141254 if (!tipc_link_create(net, if_name, b->identity, b->tolerance,
10151255 b->net_plane, b->mtu, b->priority,
1016
- b->window, session,
1256
+ b->min_win, b->max_win, session,
10171257 tipc_own_addr(net), addr, peer_id,
10181258 n->capabilities,
10191259 tipc_bc_sndlink(n->net), n->bc_entry.link,
....@@ -1022,10 +1262,12 @@
10221262 *respond = false;
10231263 goto exit;
10241264 }
1265
+ trace_tipc_link_reset(l, TIPC_DUMP_ALL, "link created!");
10251266 tipc_link_reset(l);
10261267 tipc_link_fsm_evt(l, LINK_RESET_EVT);
10271268 if (n->state == NODE_FAILINGOVER)
10281269 tipc_link_fsm_evt(l, LINK_FAILOVER_BEGIN_EVT);
1270
+ link_is_reset = tipc_link_is_reset(l);
10291271 le->link = l;
10301272 n->link_cnt++;
10311273 tipc_node_calculate_timer(n, l);
....@@ -1038,7 +1280,7 @@
10381280 memcpy(&le->maddr, maddr, sizeof(*maddr));
10391281 exit:
10401282 tipc_node_write_unlock(n);
1041
- if (reset && l && !tipc_link_is_reset(l))
1283
+ if (reset && !link_is_reset)
10421284 tipc_node_link_down(n, b->identity, false);
10431285 tipc_node_put(n);
10441286 }
....@@ -1061,6 +1303,7 @@
10611303
10621304 pr_warn("Resetting all links to %x\n", n->addr);
10631305
1306
+ trace_tipc_node_reset_links(n, true, " ");
10641307 for (i = 0; i < MAX_BEARERS; i++) {
10651308 tipc_node_link_down(n, i, false);
10661309 }
....@@ -1236,11 +1479,13 @@
12361479 pr_err("Unknown node fsm state %x\n", state);
12371480 break;
12381481 }
1482
+ trace_tipc_node_fsm(n->peer_id, n->state, state, evt);
12391483 n->state = state;
12401484 return;
12411485
12421486 illegal_evt:
12431487 pr_err("Illegal node fsm evt %x in state %x\n", evt, state);
1488
+ trace_tipc_node_fsm(n->peer_id, n->state, state, evt);
12441489 }
12451490
12461491 static void node_lost_contact(struct tipc_node *n,
....@@ -1254,9 +1499,11 @@
12541499
12551500 pr_debug("Lost contact with %x\n", n->addr);
12561501 n->delete_at = jiffies + msecs_to_jiffies(NODE_CLEANUP_AFTER);
1502
+ trace_tipc_node_lost_contact(n, true, " ");
12571503
12581504 /* Clean up broadcast state */
12591505 tipc_bcast_remove_peer(n->net, n->bc_entry.link);
1506
+ skb_queue_purge(&n->bc_entry.namedq);
12601507
12611508 /* Abort any ongoing link failover */
12621509 for (i = 0; i < MAX_BEARERS; i++) {
....@@ -1267,7 +1514,8 @@
12671514
12681515 /* Notify publications from this node */
12691516 n->action_flags |= TIPC_NOTIFY_NODE_DOWN;
1270
-
1517
+ n->peer_net = NULL;
1518
+ n->peer_hash_mix = 0;
12711519 /* Notify sockets connected to node */
12721520 list_for_each_entry_safe(conn, safe, conns, list) {
12731521 skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG,
....@@ -1285,7 +1533,7 @@
12851533 * tipc_node_get_linkname - get the name of a link
12861534 *
12871535 * @bearer_id: id of the bearer
1288
- * @node: peer node address
1536
+ * @addr: peer node address
12891537 * @linkname: link name output buffer
12901538 *
12911539 * Returns 0 on success
....@@ -1326,7 +1574,7 @@
13261574 if (!hdr)
13271575 return -EMSGSIZE;
13281576
1329
- attrs = nla_nest_start(msg->skb, TIPC_NLA_NODE);
1577
+ attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_NODE);
13301578 if (!attrs)
13311579 goto msg_full;
13321580
....@@ -1349,6 +1597,57 @@
13491597 return -EMSGSIZE;
13501598 }
13511599
1600
+static void tipc_lxc_xmit(struct net *peer_net, struct sk_buff_head *list)
1601
+{
1602
+ struct tipc_msg *hdr = buf_msg(skb_peek(list));
1603
+ struct sk_buff_head inputq;
1604
+
1605
+ switch (msg_user(hdr)) {
1606
+ case TIPC_LOW_IMPORTANCE:
1607
+ case TIPC_MEDIUM_IMPORTANCE:
1608
+ case TIPC_HIGH_IMPORTANCE:
1609
+ case TIPC_CRITICAL_IMPORTANCE:
1610
+ if (msg_connected(hdr) || msg_named(hdr) ||
1611
+ msg_direct(hdr)) {
1612
+ tipc_loopback_trace(peer_net, list);
1613
+ spin_lock_init(&list->lock);
1614
+ tipc_sk_rcv(peer_net, list);
1615
+ return;
1616
+ }
1617
+ if (msg_mcast(hdr)) {
1618
+ tipc_loopback_trace(peer_net, list);
1619
+ skb_queue_head_init(&inputq);
1620
+ tipc_sk_mcast_rcv(peer_net, list, &inputq);
1621
+ __skb_queue_purge(list);
1622
+ skb_queue_purge(&inputq);
1623
+ return;
1624
+ }
1625
+ return;
1626
+ case MSG_FRAGMENTER:
1627
+ if (tipc_msg_assemble(list)) {
1628
+ tipc_loopback_trace(peer_net, list);
1629
+ skb_queue_head_init(&inputq);
1630
+ tipc_sk_mcast_rcv(peer_net, list, &inputq);
1631
+ __skb_queue_purge(list);
1632
+ skb_queue_purge(&inputq);
1633
+ }
1634
+ return;
1635
+ case GROUP_PROTOCOL:
1636
+ case CONN_MANAGER:
1637
+ tipc_loopback_trace(peer_net, list);
1638
+ spin_lock_init(&list->lock);
1639
+ tipc_sk_rcv(peer_net, list);
1640
+ return;
1641
+ case LINK_PROTOCOL:
1642
+ case NAME_DISTRIBUTOR:
1643
+ case TUNNEL_PROTOCOL:
1644
+ case BCAST_PROTOCOL:
1645
+ return;
1646
+ default:
1647
+ return;
1648
+ };
1649
+}
1650
+
13521651 /**
13531652 * tipc_node_xmit() is the general link level function for message sending
13541653 * @net: the applicable net namespace
....@@ -1364,10 +1663,13 @@
13641663 struct tipc_link_entry *le = NULL;
13651664 struct tipc_node *n;
13661665 struct sk_buff_head xmitq;
1666
+ bool node_up = false;
1667
+ struct net *peer_net;
13671668 int bearer_id;
13681669 int rc;
13691670
13701671 if (in_own_node(net, dnode)) {
1672
+ tipc_loopback_trace(net, list);
13711673 spin_lock_init(&list->lock);
13721674 tipc_sk_rcv(net, list);
13731675 return 0;
....@@ -1378,6 +1680,22 @@
13781680 __skb_queue_purge(list);
13791681 return -EHOSTUNREACH;
13801682 }
1683
+
1684
+ rcu_read_lock();
1685
+ tipc_node_read_lock(n);
1686
+ node_up = node_is_up(n);
1687
+ peer_net = n->peer_net;
1688
+ tipc_node_read_unlock(n);
1689
+ if (node_up && peer_net && check_net(peer_net)) {
1690
+ /* xmit inner linux container */
1691
+ tipc_lxc_xmit(peer_net, list);
1692
+ if (likely(skb_queue_empty(list))) {
1693
+ rcu_read_unlock();
1694
+ tipc_node_put(n);
1695
+ return 0;
1696
+ }
1697
+ }
1698
+ rcu_read_unlock();
13811699
13821700 tipc_node_read_lock(n);
13831701 bearer_id = n->active_links[selector & 1];
....@@ -1398,7 +1716,7 @@
13981716 if (unlikely(rc == -ENOBUFS))
13991717 tipc_node_link_down(n, bearer_id, false);
14001718 else
1401
- tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
1719
+ tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr, n);
14021720
14031721 tipc_node_put(n);
14041722
....@@ -1438,12 +1756,23 @@
14381756 return 0;
14391757 }
14401758
1441
-void tipc_node_broadcast(struct net *net, struct sk_buff *skb)
1759
+void tipc_node_broadcast(struct net *net, struct sk_buff *skb, int rc_dests)
14421760 {
1761
+ struct sk_buff_head xmitq;
14431762 struct sk_buff *txskb;
14441763 struct tipc_node *n;
1764
+ u16 dummy;
14451765 u32 dst;
14461766
1767
+ /* Use broadcast if all nodes support it */
1768
+ if (!rc_dests && tipc_bcast_get_mode(net) != BCLINK_MODE_RCAST) {
1769
+ __skb_queue_head_init(&xmitq);
1770
+ __skb_queue_tail(&xmitq, skb);
1771
+ tipc_bcast_xmit(net, &xmitq, &dummy);
1772
+ return;
1773
+ }
1774
+
1775
+ /* Otherwise use legacy replicast method */
14471776 rcu_read_lock();
14481777 list_for_each_entry_rcu(n, tipc_nodes(net), list) {
14491778 dst = n->addr;
....@@ -1458,7 +1787,6 @@
14581787 tipc_node_xmit_skb(net, txskb, dst, 0);
14591788 }
14601789 rcu_read_unlock();
1461
-
14621790 kfree_skb(skb);
14631791 }
14641792
....@@ -1481,7 +1809,7 @@
14811809 struct tipc_link *ucl;
14821810 int rc;
14831811
1484
- rc = tipc_bcast_sync_rcv(n->net, n->bc_entry.link, hdr);
1812
+ rc = tipc_bcast_sync_rcv(n->net, n->bc_entry.link, hdr, xmitq);
14851813
14861814 if (rc & TIPC_LINK_DOWN_EVT) {
14871815 tipc_node_reset_links(n);
....@@ -1546,10 +1874,16 @@
15461874 }
15471875
15481876 if (!skb_queue_empty(&xmitq))
1549
- tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
1877
+ tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr, n);
15501878
15511879 if (!skb_queue_empty(&be->inputq1))
15521880 tipc_node_mcast_rcv(n);
1881
+
1882
+ /* Handle NAME_DISTRIBUTOR messages sent from 1.7 nodes */
1883
+ if (!skb_queue_empty(&n->bc_entry.namedq))
1884
+ tipc_named_rcv(net, &n->bc_entry.namedq,
1885
+ &n->bc_entry.named_rcv_nxt,
1886
+ &n->bc_entry.named_open);
15531887
15541888 /* If reassembly or retransmission failure => reset all links to peer */
15551889 if (rc & TIPC_LINK_DOWN_EVT)
....@@ -1571,7 +1905,6 @@
15711905 int usr = msg_user(hdr);
15721906 int mtyp = msg_type(hdr);
15731907 u16 oseqno = msg_seqno(hdr);
1574
- u16 iseqno = msg_seqno(msg_get_wrapped(hdr));
15751908 u16 exp_pkts = msg_msgcnt(hdr);
15761909 u16 rcv_nxt, syncpt, dlv_nxt, inputq_len;
15771910 int state = n->state;
....@@ -1579,6 +1912,10 @@
15791912 struct tipc_media_addr *maddr;
15801913 int pb_id;
15811914
1915
+ if (trace_tipc_node_check_state_enabled()) {
1916
+ trace_tipc_skb_dump(skb, false, "skb for node state check");
1917
+ trace_tipc_node_check_state(n, true, " ");
1918
+ }
15821919 l = n->links[bearer_id].link;
15831920 if (!l)
15841921 return false;
....@@ -1596,8 +1933,11 @@
15961933 }
15971934 }
15981935
1599
- if (!tipc_link_validate_msg(l, hdr))
1936
+ if (!tipc_link_validate_msg(l, hdr)) {
1937
+ trace_tipc_skb_dump(skb, false, "PROTO invalid (2)!");
1938
+ trace_tipc_link_dump(l, TIPC_DUMP_NONE, "PROTO invalid (2)!");
16001939 return false;
1940
+ }
16011941
16021942 /* Check and update node accesibility if applicable */
16031943 if (state == SELF_UP_PEER_COMING) {
....@@ -1625,19 +1965,23 @@
16251965 /* Initiate or update failover mode if applicable */
16261966 if ((usr == TUNNEL_PROTOCOL) && (mtyp == FAILOVER_MSG)) {
16271967 syncpt = oseqno + exp_pkts - 1;
1628
- if (pl && tipc_link_is_up(pl)) {
1968
+ if (pl && !tipc_link_is_reset(pl)) {
16291969 __tipc_node_link_down(n, &pb_id, xmitq, &maddr);
1970
+ trace_tipc_node_link_down(n, true,
1971
+ "node link down <- failover!");
16301972 tipc_skb_queue_splice_tail_init(tipc_link_inputq(pl),
16311973 tipc_link_inputq(l));
16321974 }
1975
+
16331976 /* If parallel link was already down, and this happened before
1634
- * the tunnel link came up, FAILOVER was never sent. Ensure that
1635
- * FAILOVER is sent to get peer out of NODE_FAILINGOVER state.
1977
+ * the tunnel link came up, node failover was never started.
1978
+ * Ensure that a FAILOVER_MSG is sent to get peer out of
1979
+ * NODE_FAILINGOVER state, also this node must accept
1980
+ * TUNNEL_MSGs from peer.
16361981 */
1637
- if (n->state != NODE_FAILINGOVER && !n->failover_sent) {
1638
- tipc_link_create_dummy_tnl_msg(l, xmitq);
1639
- n->failover_sent = true;
1640
- }
1982
+ if (n->state != NODE_FAILINGOVER)
1983
+ tipc_node_link_failover(n, pl, l, xmitq);
1984
+
16411985 /* If pkts arrive out of order, use lowest calculated syncpt */
16421986 if (less(syncpt, n->sync_point))
16431987 n->sync_point = syncpt;
....@@ -1659,7 +2003,10 @@
16592003
16602004 /* Initiate synch mode if applicable */
16612005 if ((usr == TUNNEL_PROTOCOL) && (mtyp == SYNCH_MSG) && (oseqno == 1)) {
1662
- syncpt = iseqno + exp_pkts - 1;
2006
+ if (n->capabilities & TIPC_TUNNEL_ENHANCED)
2007
+ syncpt = msg_syncpt(hdr);
2008
+ else
2009
+ syncpt = msg_seqno(msg_inner_hdr(hdr)) + exp_pkts - 1;
16632010 if (!tipc_link_is_up(l))
16642011 __tipc_node_link_up(n, bearer_id, xmitq);
16652012 if (n->state == SELF_UP_PEER_UP) {
....@@ -1699,7 +2046,7 @@
16992046 * tipc_rcv - process TIPC packets/messages arriving from off-node
17002047 * @net: the applicable net namespace
17012048 * @skb: TIPC packet
1702
- * @bearer: pointer to bearer message arrived on
2049
+ * @b: pointer to bearer message arrived on
17032050 *
17042051 * Invoked with no locks held. Bearer pointer must point to a valid bearer
17052052 * structure (i.e. cannot be NULL), but bearer can be inactive.
....@@ -1707,19 +2054,38 @@
17072054 void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
17082055 {
17092056 struct sk_buff_head xmitq;
1710
- struct tipc_node *n;
1711
- struct tipc_msg *hdr;
1712
- int bearer_id = b->identity;
17132057 struct tipc_link_entry *le;
2058
+ struct tipc_msg *hdr;
2059
+ struct tipc_node *n;
2060
+ int bearer_id = b->identity;
17142061 u32 self = tipc_own_addr(net);
17152062 int usr, rc = 0;
17162063 u16 bc_ack;
2064
+#ifdef CONFIG_TIPC_CRYPTO
2065
+ struct tipc_ehdr *ehdr;
17172066
1718
- __skb_queue_head_init(&xmitq);
2067
+ /* Check if message must be decrypted first */
2068
+ if (TIPC_SKB_CB(skb)->decrypted || !tipc_ehdr_validate(skb))
2069
+ goto rcv;
17192070
2071
+ ehdr = (struct tipc_ehdr *)skb->data;
2072
+ if (likely(ehdr->user != LINK_CONFIG)) {
2073
+ n = tipc_node_find(net, ntohl(ehdr->addr));
2074
+ if (unlikely(!n))
2075
+ goto discard;
2076
+ } else {
2077
+ n = tipc_node_find_by_id(net, ehdr->id);
2078
+ }
2079
+ tipc_crypto_rcv(net, (n) ? n->crypto_rx : NULL, &skb, b);
2080
+ if (!skb)
2081
+ return;
2082
+
2083
+rcv:
2084
+#endif
17202085 /* Ensure message is well-formed before touching the header */
17212086 if (unlikely(!tipc_msg_validate(&skb)))
17222087 goto discard;
2088
+ __skb_queue_head_init(&xmitq);
17232089 hdr = buf_msg(skb);
17242090 usr = msg_user(hdr);
17252091 bc_ack = msg_bcast_ack(hdr);
....@@ -1743,10 +2109,16 @@
17432109 le = &n->links[bearer_id];
17442110
17452111 /* Ensure broadcast reception is in synch with peer's send state */
1746
- if (unlikely(usr == LINK_PROTOCOL))
2112
+ if (unlikely(usr == LINK_PROTOCOL)) {
2113
+ if (unlikely(skb_linearize(skb))) {
2114
+ tipc_node_put(n);
2115
+ goto discard;
2116
+ }
2117
+ hdr = buf_msg(skb);
17472118 tipc_node_bc_sync_rcv(n, hdr, bearer_id, &xmitq);
1748
- else if (unlikely(tipc_link_acked(n->bc_entry.link) != bc_ack))
2119
+ } else if (unlikely(tipc_link_acked(n->bc_entry.link) != bc_ack)) {
17492120 tipc_bcast_ack_rcv(net, n->bc_entry.link, hdr);
2121
+ }
17502122
17512123 /* Receive packet directly if conditions permit */
17522124 tipc_node_read_lock(n);
....@@ -1763,7 +2135,7 @@
17632135 /* Check/update node state before receiving */
17642136 if (unlikely(skb)) {
17652137 if (unlikely(skb_linearize(skb)))
1766
- goto discard;
2138
+ goto out_node_put;
17672139 tipc_node_write_lock(n);
17682140 if (tipc_node_check_state(n, skb, bearer_id, &xmitq)) {
17692141 if (le->link) {
....@@ -1781,7 +2153,9 @@
17812153 tipc_node_link_down(n, bearer_id, false);
17822154
17832155 if (unlikely(!skb_queue_empty(&n->bc_entry.namedq)))
1784
- tipc_named_rcv(net, &n->bc_entry.namedq);
2156
+ tipc_named_rcv(net, &n->bc_entry.namedq,
2157
+ &n->bc_entry.named_rcv_nxt,
2158
+ &n->bc_entry.named_open);
17852159
17862160 if (unlikely(!skb_queue_empty(&n->bc_entry.inputq1)))
17872161 tipc_node_mcast_rcv(n);
....@@ -1790,8 +2164,9 @@
17902164 tipc_sk_rcv(net, &le->inputq);
17912165
17922166 if (!skb_queue_empty(&xmitq))
1793
- tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
2167
+ tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr, n);
17942168
2169
+out_node_put:
17952170 tipc_node_put(n);
17962171 discard:
17972172 kfree_skb(skb);
....@@ -1819,9 +2194,13 @@
18192194 &xmitq);
18202195 else if (prop == TIPC_NLA_PROP_MTU)
18212196 tipc_link_set_mtu(e->link, b->mtu);
2197
+
2198
+ /* Update MTU for node link entry */
2199
+ e->mtu = tipc_link_mss(e->link);
18222200 }
2201
+
18232202 tipc_node_write_unlock(n);
1824
- tipc_bearer_xmit(net, bearer_id, &xmitq, &e->maddr);
2203
+ tipc_bearer_xmit(net, bearer_id, &xmitq, &e->maddr, NULL);
18252204 }
18262205
18272206 rcu_read_unlock();
....@@ -1832,7 +2211,7 @@
18322211 struct net *net = sock_net(skb->sk);
18332212 struct tipc_net *tn = net_generic(net, tipc_net_id);
18342213 struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
1835
- struct tipc_node *peer;
2214
+ struct tipc_node *peer, *temp_node;
18362215 u32 addr;
18372216 int err;
18382217
....@@ -1840,9 +2219,9 @@
18402219 if (!info->attrs[TIPC_NLA_NET])
18412220 return -EINVAL;
18422221
1843
- err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
1844
- info->attrs[TIPC_NLA_NET], tipc_nl_net_policy,
1845
- info->extack);
2222
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_NET_MAX,
2223
+ info->attrs[TIPC_NLA_NET],
2224
+ tipc_nl_net_policy, info->extack);
18462225 if (err)
18472226 return err;
18482227
....@@ -1873,6 +2252,12 @@
18732252 tipc_node_write_unlock(peer);
18742253 tipc_node_delete(peer);
18752254
2255
+ /* Calculate cluster capabilities */
2256
+ tn->capabilities = TIPC_NODE_CAPABILITIES;
2257
+ list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
2258
+ tn->capabilities &= temp_node->capabilities;
2259
+ }
2260
+ tipc_bcast_toggle_rcast(net, (tn->capabilities & TIPC_BCAST_RCAST));
18762261 err = 0;
18772262 err_out:
18782263 tipc_node_put(peer);
....@@ -1917,6 +2302,8 @@
19172302 }
19182303
19192304 list_for_each_entry_rcu(node, &tn->node_list, list) {
2305
+ if (node->preliminary)
2306
+ continue;
19202307 if (last_addr) {
19212308 if (node->addr == last_addr)
19222309 last_addr = 0;
....@@ -1998,9 +2385,9 @@
19982385 if (!info->attrs[TIPC_NLA_LINK])
19992386 return -EINVAL;
20002387
2001
- err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
2002
- info->attrs[TIPC_NLA_LINK],
2003
- tipc_nl_link_policy, info->extack);
2388
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_LINK_MAX,
2389
+ info->attrs[TIPC_NLA_LINK],
2390
+ tipc_nl_link_policy, info->extack);
20042391 if (err)
20052392 return err;
20062393
....@@ -2027,8 +2414,7 @@
20272414 if (attrs[TIPC_NLA_LINK_PROP]) {
20282415 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
20292416
2030
- err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP],
2031
- props);
2417
+ err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP], props);
20322418 if (err) {
20332419 res = err;
20342420 goto out;
....@@ -2047,16 +2433,19 @@
20472433 tipc_link_set_prio(link, prio, &xmitq);
20482434 }
20492435 if (props[TIPC_NLA_PROP_WIN]) {
2050
- u32 win;
2436
+ u32 max_win;
20512437
2052
- win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
2053
- tipc_link_set_queue_limits(link, win);
2438
+ max_win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
2439
+ tipc_link_set_queue_limits(link,
2440
+ tipc_link_min_win(link),
2441
+ max_win);
20542442 }
20552443 }
20562444
20572445 out:
20582446 tipc_node_read_unlock(node);
2059
- tipc_bearer_xmit(net, bearer_id, &xmitq, &node->links[bearer_id].maddr);
2447
+ tipc_bearer_xmit(net, bearer_id, &xmitq, &node->links[bearer_id].maddr,
2448
+ NULL);
20602449 return res;
20612450 }
20622451
....@@ -2074,9 +2463,9 @@
20742463 if (!info->attrs[TIPC_NLA_LINK])
20752464 return -EINVAL;
20762465
2077
- err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
2078
- info->attrs[TIPC_NLA_LINK],
2079
- tipc_nl_link_policy, info->extack);
2466
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_LINK_MAX,
2467
+ info->attrs[TIPC_NLA_LINK],
2468
+ tipc_nl_link_policy, info->extack);
20802469 if (err)
20812470 return err;
20822471
....@@ -2090,7 +2479,7 @@
20902479 return -ENOMEM;
20912480
20922481 if (strcmp(name, tipc_bclink_name) == 0) {
2093
- err = tipc_nl_add_bc_link(net, &msg);
2482
+ err = tipc_nl_add_bc_link(net, &msg, tipc_net(net)->bcl);
20942483 if (err)
20952484 goto err_free;
20962485 } else {
....@@ -2134,14 +2523,15 @@
21342523 struct tipc_node *node;
21352524 struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
21362525 struct net *net = sock_net(skb->sk);
2526
+ struct tipc_net *tn = tipc_net(net);
21372527 struct tipc_link_entry *le;
21382528
21392529 if (!info->attrs[TIPC_NLA_LINK])
21402530 return -EINVAL;
21412531
2142
- err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
2143
- info->attrs[TIPC_NLA_LINK],
2144
- tipc_nl_link_policy, info->extack);
2532
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_LINK_MAX,
2533
+ info->attrs[TIPC_NLA_LINK],
2534
+ tipc_nl_link_policy, info->extack);
21452535 if (err)
21462536 return err;
21472537
....@@ -2150,11 +2540,26 @@
21502540
21512541 link_name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
21522542
2153
- if (strcmp(link_name, tipc_bclink_name) == 0) {
2154
- err = tipc_bclink_reset_stats(net);
2543
+ err = -EINVAL;
2544
+ if (!strcmp(link_name, tipc_bclink_name)) {
2545
+ err = tipc_bclink_reset_stats(net, tipc_bc_sndlink(net));
21552546 if (err)
21562547 return err;
21572548 return 0;
2549
+ } else if (strstr(link_name, tipc_bclink_name)) {
2550
+ rcu_read_lock();
2551
+ list_for_each_entry_rcu(node, &tn->node_list, list) {
2552
+ tipc_node_read_lock(node);
2553
+ link = node->bc_entry.link;
2554
+ if (link && !strcmp(link_name, tipc_link_name(link))) {
2555
+ err = tipc_bclink_reset_stats(net, link);
2556
+ tipc_node_read_unlock(node);
2557
+ break;
2558
+ }
2559
+ tipc_node_read_unlock(node);
2560
+ }
2561
+ rcu_read_unlock();
2562
+ return err;
21582563 }
21592564
21602565 node = tipc_node_find_by_name(net, link_name, &bearer_id);
....@@ -2178,7 +2583,8 @@
21782583
21792584 /* Caller should hold node lock */
21802585 static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
2181
- struct tipc_node *node, u32 *prev_link)
2586
+ struct tipc_node *node, u32 *prev_link,
2587
+ bool bc_link)
21822588 {
21832589 u32 i;
21842590 int err;
....@@ -2194,6 +2600,14 @@
21942600 if (err)
21952601 return err;
21962602 }
2603
+
2604
+ if (bc_link) {
2605
+ *prev_link = i;
2606
+ err = tipc_nl_add_bc_link(net, msg, node->bc_entry.link);
2607
+ if (err)
2608
+ return err;
2609
+ }
2610
+
21972611 *prev_link = 0;
21982612
21992613 return 0;
....@@ -2202,16 +2616,35 @@
22022616 int tipc_nl_node_dump_link(struct sk_buff *skb, struct netlink_callback *cb)
22032617 {
22042618 struct net *net = sock_net(skb->sk);
2619
+ struct nlattr **attrs = genl_dumpit_info(cb)->attrs;
2620
+ struct nlattr *link[TIPC_NLA_LINK_MAX + 1];
22052621 struct tipc_net *tn = net_generic(net, tipc_net_id);
22062622 struct tipc_node *node;
22072623 struct tipc_nl_msg msg;
22082624 u32 prev_node = cb->args[0];
22092625 u32 prev_link = cb->args[1];
22102626 int done = cb->args[2];
2627
+ bool bc_link = cb->args[3];
22112628 int err;
22122629
22132630 if (done)
22142631 return 0;
2632
+
2633
+ if (!prev_node) {
2634
+ /* Check if broadcast-receiver links dumping is needed */
2635
+ if (attrs && attrs[TIPC_NLA_LINK]) {
2636
+ err = nla_parse_nested_deprecated(link,
2637
+ TIPC_NLA_LINK_MAX,
2638
+ attrs[TIPC_NLA_LINK],
2639
+ tipc_nl_link_policy,
2640
+ NULL);
2641
+ if (unlikely(err))
2642
+ return err;
2643
+ if (unlikely(!link[TIPC_NLA_LINK_BROADCAST]))
2644
+ return -EINVAL;
2645
+ bc_link = true;
2646
+ }
2647
+ }
22152648
22162649 msg.skb = skb;
22172650 msg.portid = NETLINK_CB(cb->skb).portid;
....@@ -2236,7 +2669,7 @@
22362669 list) {
22372670 tipc_node_read_lock(node);
22382671 err = __tipc_nl_add_node_links(net, &msg, node,
2239
- &prev_link);
2672
+ &prev_link, bc_link);
22402673 tipc_node_read_unlock(node);
22412674 if (err)
22422675 goto out;
....@@ -2244,14 +2677,14 @@
22442677 prev_node = node->addr;
22452678 }
22462679 } else {
2247
- err = tipc_nl_add_bc_link(net, &msg);
2680
+ err = tipc_nl_add_bc_link(net, &msg, tn->bcl);
22482681 if (err)
22492682 goto out;
22502683
22512684 list_for_each_entry_rcu(node, &tn->node_list, list) {
22522685 tipc_node_read_lock(node);
22532686 err = __tipc_nl_add_node_links(net, &msg, node,
2254
- &prev_link);
2687
+ &prev_link, bc_link);
22552688 tipc_node_read_unlock(node);
22562689 if (err)
22572690 goto out;
....@@ -2266,6 +2699,7 @@
22662699 cb->args[0] = prev_node;
22672700 cb->args[1] = prev_link;
22682701 cb->args[2] = done;
2702
+ cb->args[3] = bc_link;
22692703
22702704 return skb->len;
22712705 }
....@@ -2279,9 +2713,10 @@
22792713 if (!info->attrs[TIPC_NLA_MON])
22802714 return -EINVAL;
22812715
2282
- err = nla_parse_nested(attrs, TIPC_NLA_MON_MAX,
2283
- info->attrs[TIPC_NLA_MON],
2284
- tipc_nl_monitor_policy, info->extack);
2716
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_MON_MAX,
2717
+ info->attrs[TIPC_NLA_MON],
2718
+ tipc_nl_monitor_policy,
2719
+ info->extack);
22852720 if (err)
22862721 return err;
22872722
....@@ -2308,7 +2743,7 @@
23082743 if (!hdr)
23092744 return -EMSGSIZE;
23102745
2311
- attrs = nla_nest_start(msg->skb, TIPC_NLA_MON);
2746
+ attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_MON);
23122747 if (!attrs)
23132748 goto msg_full;
23142749
....@@ -2389,19 +2824,16 @@
23892824 int err;
23902825
23912826 if (!prev_node) {
2392
- struct nlattr **attrs;
2827
+ struct nlattr **attrs = genl_dumpit_info(cb)->attrs;
23932828 struct nlattr *mon[TIPC_NLA_MON_MAX + 1];
2394
-
2395
- err = tipc_nlmsg_parse(cb->nlh, &attrs);
2396
- if (err)
2397
- return err;
23982829
23992830 if (!attrs[TIPC_NLA_MON])
24002831 return -EINVAL;
24012832
2402
- err = nla_parse_nested(mon, TIPC_NLA_MON_MAX,
2403
- attrs[TIPC_NLA_MON],
2404
- tipc_nl_monitor_policy, NULL);
2833
+ err = nla_parse_nested_deprecated(mon, TIPC_NLA_MON_MAX,
2834
+ attrs[TIPC_NLA_MON],
2835
+ tipc_nl_monitor_policy,
2836
+ NULL);
24052837 if (err)
24062838 return err;
24072839
....@@ -2433,3 +2865,256 @@
24332865
24342866 return skb->len;
24352867 }
2868
+
2869
+#ifdef CONFIG_TIPC_CRYPTO
2870
+static int tipc_nl_retrieve_key(struct nlattr **attrs,
2871
+ struct tipc_aead_key **pkey)
2872
+{
2873
+ struct nlattr *attr = attrs[TIPC_NLA_NODE_KEY];
2874
+ struct tipc_aead_key *key;
2875
+
2876
+ if (!attr)
2877
+ return -ENODATA;
2878
+
2879
+ if (nla_len(attr) < sizeof(*key))
2880
+ return -EINVAL;
2881
+ key = (struct tipc_aead_key *)nla_data(attr);
2882
+ if (key->keylen > TIPC_AEAD_KEYLEN_MAX ||
2883
+ nla_len(attr) < tipc_aead_key_size(key))
2884
+ return -EINVAL;
2885
+
2886
+ *pkey = key;
2887
+ return 0;
2888
+}
2889
+
2890
+static int tipc_nl_retrieve_nodeid(struct nlattr **attrs, u8 **node_id)
2891
+{
2892
+ struct nlattr *attr = attrs[TIPC_NLA_NODE_ID];
2893
+
2894
+ if (!attr)
2895
+ return -ENODATA;
2896
+
2897
+ if (nla_len(attr) < TIPC_NODEID_LEN)
2898
+ return -EINVAL;
2899
+
2900
+ *node_id = (u8 *)nla_data(attr);
2901
+ return 0;
2902
+}
2903
+
2904
+static int tipc_nl_retrieve_rekeying(struct nlattr **attrs, u32 *intv)
2905
+{
2906
+ struct nlattr *attr = attrs[TIPC_NLA_NODE_REKEYING];
2907
+
2908
+ if (!attr)
2909
+ return -ENODATA;
2910
+
2911
+ *intv = nla_get_u32(attr);
2912
+ return 0;
2913
+}
2914
+
2915
+static int __tipc_nl_node_set_key(struct sk_buff *skb, struct genl_info *info)
2916
+{
2917
+ struct nlattr *attrs[TIPC_NLA_NODE_MAX + 1];
2918
+ struct net *net = sock_net(skb->sk);
2919
+ struct tipc_crypto *tx = tipc_net(net)->crypto_tx, *c = tx;
2920
+ struct tipc_node *n = NULL;
2921
+ struct tipc_aead_key *ukey;
2922
+ bool rekeying = true, master_key = false;
2923
+ u8 *id, *own_id, mode;
2924
+ u32 intv = 0;
2925
+ int rc = 0;
2926
+
2927
+ if (!info->attrs[TIPC_NLA_NODE])
2928
+ return -EINVAL;
2929
+
2930
+ rc = nla_parse_nested(attrs, TIPC_NLA_NODE_MAX,
2931
+ info->attrs[TIPC_NLA_NODE],
2932
+ tipc_nl_node_policy, info->extack);
2933
+ if (rc)
2934
+ return rc;
2935
+
2936
+ own_id = tipc_own_id(net);
2937
+ if (!own_id) {
2938
+ GENL_SET_ERR_MSG(info, "not found own node identity (set id?)");
2939
+ return -EPERM;
2940
+ }
2941
+
2942
+ rc = tipc_nl_retrieve_rekeying(attrs, &intv);
2943
+ if (rc == -ENODATA)
2944
+ rekeying = false;
2945
+
2946
+ rc = tipc_nl_retrieve_key(attrs, &ukey);
2947
+ if (rc == -ENODATA && rekeying)
2948
+ goto rekeying;
2949
+ else if (rc)
2950
+ return rc;
2951
+
2952
+ rc = tipc_aead_key_validate(ukey, info);
2953
+ if (rc)
2954
+ return rc;
2955
+
2956
+ rc = tipc_nl_retrieve_nodeid(attrs, &id);
2957
+ switch (rc) {
2958
+ case -ENODATA:
2959
+ mode = CLUSTER_KEY;
2960
+ master_key = !!(attrs[TIPC_NLA_NODE_KEY_MASTER]);
2961
+ break;
2962
+ case 0:
2963
+ mode = PER_NODE_KEY;
2964
+ if (memcmp(id, own_id, NODE_ID_LEN)) {
2965
+ n = tipc_node_find_by_id(net, id) ?:
2966
+ tipc_node_create(net, 0, id, 0xffffu, 0, true);
2967
+ if (unlikely(!n))
2968
+ return -ENOMEM;
2969
+ c = n->crypto_rx;
2970
+ }
2971
+ break;
2972
+ default:
2973
+ return rc;
2974
+ }
2975
+
2976
+ /* Initiate the TX/RX key */
2977
+ rc = tipc_crypto_key_init(c, ukey, mode, master_key);
2978
+ if (n)
2979
+ tipc_node_put(n);
2980
+
2981
+ if (unlikely(rc < 0)) {
2982
+ GENL_SET_ERR_MSG(info, "unable to initiate or attach new key");
2983
+ return rc;
2984
+ } else if (c == tx) {
2985
+ /* Distribute TX key but not master one */
2986
+ if (!master_key && tipc_crypto_key_distr(tx, rc, NULL))
2987
+ GENL_SET_ERR_MSG(info, "failed to replicate new key");
2988
+rekeying:
2989
+ /* Schedule TX rekeying if needed */
2990
+ tipc_crypto_rekeying_sched(tx, rekeying, intv);
2991
+ }
2992
+
2993
+ return 0;
2994
+}
2995
+
2996
+int tipc_nl_node_set_key(struct sk_buff *skb, struct genl_info *info)
2997
+{
2998
+ int err;
2999
+
3000
+ rtnl_lock();
3001
+ err = __tipc_nl_node_set_key(skb, info);
3002
+ rtnl_unlock();
3003
+
3004
+ return err;
3005
+}
3006
+
3007
+static int __tipc_nl_node_flush_key(struct sk_buff *skb,
3008
+ struct genl_info *info)
3009
+{
3010
+ struct net *net = sock_net(skb->sk);
3011
+ struct tipc_net *tn = tipc_net(net);
3012
+ struct tipc_node *n;
3013
+
3014
+ tipc_crypto_key_flush(tn->crypto_tx);
3015
+ rcu_read_lock();
3016
+ list_for_each_entry_rcu(n, &tn->node_list, list)
3017
+ tipc_crypto_key_flush(n->crypto_rx);
3018
+ rcu_read_unlock();
3019
+
3020
+ return 0;
3021
+}
3022
+
3023
+int tipc_nl_node_flush_key(struct sk_buff *skb, struct genl_info *info)
3024
+{
3025
+ int err;
3026
+
3027
+ rtnl_lock();
3028
+ err = __tipc_nl_node_flush_key(skb, info);
3029
+ rtnl_unlock();
3030
+
3031
+ return err;
3032
+}
3033
+#endif
3034
+
3035
+/**
3036
+ * tipc_node_dump - dump TIPC node data
3037
+ * @n: tipc node to be dumped
3038
+ * @more: dump more?
3039
+ * - false: dump only tipc node data
3040
+ * - true: dump node link data as well
3041
+ * @buf: returned buffer of dump data in format
3042
+ */
3043
+int tipc_node_dump(struct tipc_node *n, bool more, char *buf)
3044
+{
3045
+ int i = 0;
3046
+ size_t sz = (more) ? NODE_LMAX : NODE_LMIN;
3047
+
3048
+ if (!n) {
3049
+ i += scnprintf(buf, sz, "node data: (null)\n");
3050
+ return i;
3051
+ }
3052
+
3053
+ i += scnprintf(buf, sz, "node data: %x", n->addr);
3054
+ i += scnprintf(buf + i, sz - i, " %x", n->state);
3055
+ i += scnprintf(buf + i, sz - i, " %d", n->active_links[0]);
3056
+ i += scnprintf(buf + i, sz - i, " %d", n->active_links[1]);
3057
+ i += scnprintf(buf + i, sz - i, " %x", n->action_flags);
3058
+ i += scnprintf(buf + i, sz - i, " %u", n->failover_sent);
3059
+ i += scnprintf(buf + i, sz - i, " %u", n->sync_point);
3060
+ i += scnprintf(buf + i, sz - i, " %d", n->link_cnt);
3061
+ i += scnprintf(buf + i, sz - i, " %u", n->working_links);
3062
+ i += scnprintf(buf + i, sz - i, " %x", n->capabilities);
3063
+ i += scnprintf(buf + i, sz - i, " %lu\n", n->keepalive_intv);
3064
+
3065
+ if (!more)
3066
+ return i;
3067
+
3068
+ i += scnprintf(buf + i, sz - i, "link_entry[0]:\n");
3069
+ i += scnprintf(buf + i, sz - i, " mtu: %u\n", n->links[0].mtu);
3070
+ i += scnprintf(buf + i, sz - i, " media: ");
3071
+ i += tipc_media_addr_printf(buf + i, sz - i, &n->links[0].maddr);
3072
+ i += scnprintf(buf + i, sz - i, "\n");
3073
+ i += tipc_link_dump(n->links[0].link, TIPC_DUMP_NONE, buf + i);
3074
+ i += scnprintf(buf + i, sz - i, " inputq: ");
3075
+ i += tipc_list_dump(&n->links[0].inputq, false, buf + i);
3076
+
3077
+ i += scnprintf(buf + i, sz - i, "link_entry[1]:\n");
3078
+ i += scnprintf(buf + i, sz - i, " mtu: %u\n", n->links[1].mtu);
3079
+ i += scnprintf(buf + i, sz - i, " media: ");
3080
+ i += tipc_media_addr_printf(buf + i, sz - i, &n->links[1].maddr);
3081
+ i += scnprintf(buf + i, sz - i, "\n");
3082
+ i += tipc_link_dump(n->links[1].link, TIPC_DUMP_NONE, buf + i);
3083
+ i += scnprintf(buf + i, sz - i, " inputq: ");
3084
+ i += tipc_list_dump(&n->links[1].inputq, false, buf + i);
3085
+
3086
+ i += scnprintf(buf + i, sz - i, "bclink:\n ");
3087
+ i += tipc_link_dump(n->bc_entry.link, TIPC_DUMP_NONE, buf + i);
3088
+
3089
+ return i;
3090
+}
3091
+
3092
+void tipc_node_pre_cleanup_net(struct net *exit_net)
3093
+{
3094
+ struct tipc_node *n;
3095
+ struct tipc_net *tn;
3096
+ struct net *tmp;
3097
+
3098
+ rcu_read_lock();
3099
+ for_each_net_rcu(tmp) {
3100
+ if (tmp == exit_net)
3101
+ continue;
3102
+ tn = tipc_net(tmp);
3103
+ if (!tn)
3104
+ continue;
3105
+ spin_lock_bh(&tn->node_list_lock);
3106
+ list_for_each_entry_rcu(n, &tn->node_list, list) {
3107
+ if (!n->peer_net)
3108
+ continue;
3109
+ if (n->peer_net != exit_net)
3110
+ continue;
3111
+ tipc_node_write_lock(n);
3112
+ n->peer_net = NULL;
3113
+ n->peer_hash_mix = 0;
3114
+ tipc_node_write_unlock_fast(n);
3115
+ break;
3116
+ }
3117
+ spin_unlock_bh(&tn->node_list_lock);
3118
+ }
3119
+ rcu_read_unlock();
3120
+}