forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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,14 +561,11 @@
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");
422570 kfree(n);
423571 n = NULL;
....@@ -425,13 +573,24 @@
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 {
....@@ -928,7 +1161,8 @@
9281161 *dupl_addr = false;
9291162 *respond = false;
9301163
931
- n = tipc_node_create(net, addr, peer_id, capabilities);
1164
+ n = tipc_node_create(net, addr, peer_id, capabilities, hash_mixes,
1165
+ false);
9321166 if (!n)
9331167 return;
9341168
....@@ -947,6 +1181,9 @@
9471181 if (sign_match && addr_match && link_up) {
9481182 /* All is fine. Do nothing. */
9491183 reset = false;
1184
+ /* Peer node is not a container/local namespace */
1185
+ if (!n->peer_hash_mix)
1186
+ n->peer_hash_mix = hash_mixes;
9501187 } else if (sign_match && addr_match && !link_up) {
9511188 /* Respond. The link will come up in due time */
9521189 *respond = true;
....@@ -1013,7 +1250,7 @@
10131250 get_random_bytes(&session, sizeof(u16));
10141251 if (!tipc_link_create(net, if_name, b->identity, b->tolerance,
10151252 b->net_plane, b->mtu, b->priority,
1016
- b->window, session,
1253
+ b->min_win, b->max_win, session,
10171254 tipc_own_addr(net), addr, peer_id,
10181255 n->capabilities,
10191256 tipc_bc_sndlink(n->net), n->bc_entry.link,
....@@ -1022,6 +1259,7 @@
10221259 *respond = false;
10231260 goto exit;
10241261 }
1262
+ trace_tipc_link_reset(l, TIPC_DUMP_ALL, "link created!");
10251263 tipc_link_reset(l);
10261264 tipc_link_fsm_evt(l, LINK_RESET_EVT);
10271265 if (n->state == NODE_FAILINGOVER)
....@@ -1061,6 +1299,7 @@
10611299
10621300 pr_warn("Resetting all links to %x\n", n->addr);
10631301
1302
+ trace_tipc_node_reset_links(n, true, " ");
10641303 for (i = 0; i < MAX_BEARERS; i++) {
10651304 tipc_node_link_down(n, i, false);
10661305 }
....@@ -1236,11 +1475,13 @@
12361475 pr_err("Unknown node fsm state %x\n", state);
12371476 break;
12381477 }
1478
+ trace_tipc_node_fsm(n->peer_id, n->state, state, evt);
12391479 n->state = state;
12401480 return;
12411481
12421482 illegal_evt:
12431483 pr_err("Illegal node fsm evt %x in state %x\n", evt, state);
1484
+ trace_tipc_node_fsm(n->peer_id, n->state, state, evt);
12441485 }
12451486
12461487 static void node_lost_contact(struct tipc_node *n,
....@@ -1254,9 +1495,11 @@
12541495
12551496 pr_debug("Lost contact with %x\n", n->addr);
12561497 n->delete_at = jiffies + msecs_to_jiffies(NODE_CLEANUP_AFTER);
1498
+ trace_tipc_node_lost_contact(n, true, " ");
12571499
12581500 /* Clean up broadcast state */
12591501 tipc_bcast_remove_peer(n->net, n->bc_entry.link);
1502
+ skb_queue_purge(&n->bc_entry.namedq);
12601503
12611504 /* Abort any ongoing link failover */
12621505 for (i = 0; i < MAX_BEARERS; i++) {
....@@ -1267,7 +1510,8 @@
12671510
12681511 /* Notify publications from this node */
12691512 n->action_flags |= TIPC_NOTIFY_NODE_DOWN;
1270
-
1513
+ n->peer_net = NULL;
1514
+ n->peer_hash_mix = 0;
12711515 /* Notify sockets connected to node */
12721516 list_for_each_entry_safe(conn, safe, conns, list) {
12731517 skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG,
....@@ -1285,7 +1529,7 @@
12851529 * tipc_node_get_linkname - get the name of a link
12861530 *
12871531 * @bearer_id: id of the bearer
1288
- * @node: peer node address
1532
+ * @addr: peer node address
12891533 * @linkname: link name output buffer
12901534 *
12911535 * Returns 0 on success
....@@ -1326,7 +1570,7 @@
13261570 if (!hdr)
13271571 return -EMSGSIZE;
13281572
1329
- attrs = nla_nest_start(msg->skb, TIPC_NLA_NODE);
1573
+ attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_NODE);
13301574 if (!attrs)
13311575 goto msg_full;
13321576
....@@ -1349,6 +1593,57 @@
13491593 return -EMSGSIZE;
13501594 }
13511595
1596
+static void tipc_lxc_xmit(struct net *peer_net, struct sk_buff_head *list)
1597
+{
1598
+ struct tipc_msg *hdr = buf_msg(skb_peek(list));
1599
+ struct sk_buff_head inputq;
1600
+
1601
+ switch (msg_user(hdr)) {
1602
+ case TIPC_LOW_IMPORTANCE:
1603
+ case TIPC_MEDIUM_IMPORTANCE:
1604
+ case TIPC_HIGH_IMPORTANCE:
1605
+ case TIPC_CRITICAL_IMPORTANCE:
1606
+ if (msg_connected(hdr) || msg_named(hdr) ||
1607
+ msg_direct(hdr)) {
1608
+ tipc_loopback_trace(peer_net, list);
1609
+ spin_lock_init(&list->lock);
1610
+ tipc_sk_rcv(peer_net, list);
1611
+ return;
1612
+ }
1613
+ if (msg_mcast(hdr)) {
1614
+ tipc_loopback_trace(peer_net, list);
1615
+ skb_queue_head_init(&inputq);
1616
+ tipc_sk_mcast_rcv(peer_net, list, &inputq);
1617
+ __skb_queue_purge(list);
1618
+ skb_queue_purge(&inputq);
1619
+ return;
1620
+ }
1621
+ return;
1622
+ case MSG_FRAGMENTER:
1623
+ if (tipc_msg_assemble(list)) {
1624
+ tipc_loopback_trace(peer_net, list);
1625
+ skb_queue_head_init(&inputq);
1626
+ tipc_sk_mcast_rcv(peer_net, list, &inputq);
1627
+ __skb_queue_purge(list);
1628
+ skb_queue_purge(&inputq);
1629
+ }
1630
+ return;
1631
+ case GROUP_PROTOCOL:
1632
+ case CONN_MANAGER:
1633
+ tipc_loopback_trace(peer_net, list);
1634
+ spin_lock_init(&list->lock);
1635
+ tipc_sk_rcv(peer_net, list);
1636
+ return;
1637
+ case LINK_PROTOCOL:
1638
+ case NAME_DISTRIBUTOR:
1639
+ case TUNNEL_PROTOCOL:
1640
+ case BCAST_PROTOCOL:
1641
+ return;
1642
+ default:
1643
+ return;
1644
+ };
1645
+}
1646
+
13521647 /**
13531648 * tipc_node_xmit() is the general link level function for message sending
13541649 * @net: the applicable net namespace
....@@ -1364,10 +1659,13 @@
13641659 struct tipc_link_entry *le = NULL;
13651660 struct tipc_node *n;
13661661 struct sk_buff_head xmitq;
1662
+ bool node_up = false;
1663
+ struct net *peer_net;
13671664 int bearer_id;
13681665 int rc;
13691666
13701667 if (in_own_node(net, dnode)) {
1668
+ tipc_loopback_trace(net, list);
13711669 spin_lock_init(&list->lock);
13721670 tipc_sk_rcv(net, list);
13731671 return 0;
....@@ -1378,6 +1676,22 @@
13781676 __skb_queue_purge(list);
13791677 return -EHOSTUNREACH;
13801678 }
1679
+
1680
+ rcu_read_lock();
1681
+ tipc_node_read_lock(n);
1682
+ node_up = node_is_up(n);
1683
+ peer_net = n->peer_net;
1684
+ tipc_node_read_unlock(n);
1685
+ if (node_up && peer_net && check_net(peer_net)) {
1686
+ /* xmit inner linux container */
1687
+ tipc_lxc_xmit(peer_net, list);
1688
+ if (likely(skb_queue_empty(list))) {
1689
+ rcu_read_unlock();
1690
+ tipc_node_put(n);
1691
+ return 0;
1692
+ }
1693
+ }
1694
+ rcu_read_unlock();
13811695
13821696 tipc_node_read_lock(n);
13831697 bearer_id = n->active_links[selector & 1];
....@@ -1398,7 +1712,7 @@
13981712 if (unlikely(rc == -ENOBUFS))
13991713 tipc_node_link_down(n, bearer_id, false);
14001714 else
1401
- tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
1715
+ tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr, n);
14021716
14031717 tipc_node_put(n);
14041718
....@@ -1438,12 +1752,23 @@
14381752 return 0;
14391753 }
14401754
1441
-void tipc_node_broadcast(struct net *net, struct sk_buff *skb)
1755
+void tipc_node_broadcast(struct net *net, struct sk_buff *skb, int rc_dests)
14421756 {
1757
+ struct sk_buff_head xmitq;
14431758 struct sk_buff *txskb;
14441759 struct tipc_node *n;
1760
+ u16 dummy;
14451761 u32 dst;
14461762
1763
+ /* Use broadcast if all nodes support it */
1764
+ if (!rc_dests && tipc_bcast_get_mode(net) != BCLINK_MODE_RCAST) {
1765
+ __skb_queue_head_init(&xmitq);
1766
+ __skb_queue_tail(&xmitq, skb);
1767
+ tipc_bcast_xmit(net, &xmitq, &dummy);
1768
+ return;
1769
+ }
1770
+
1771
+ /* Otherwise use legacy replicast method */
14471772 rcu_read_lock();
14481773 list_for_each_entry_rcu(n, tipc_nodes(net), list) {
14491774 dst = n->addr;
....@@ -1458,7 +1783,6 @@
14581783 tipc_node_xmit_skb(net, txskb, dst, 0);
14591784 }
14601785 rcu_read_unlock();
1461
-
14621786 kfree_skb(skb);
14631787 }
14641788
....@@ -1481,7 +1805,7 @@
14811805 struct tipc_link *ucl;
14821806 int rc;
14831807
1484
- rc = tipc_bcast_sync_rcv(n->net, n->bc_entry.link, hdr);
1808
+ rc = tipc_bcast_sync_rcv(n->net, n->bc_entry.link, hdr, xmitq);
14851809
14861810 if (rc & TIPC_LINK_DOWN_EVT) {
14871811 tipc_node_reset_links(n);
....@@ -1546,10 +1870,16 @@
15461870 }
15471871
15481872 if (!skb_queue_empty(&xmitq))
1549
- tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
1873
+ tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr, n);
15501874
15511875 if (!skb_queue_empty(&be->inputq1))
15521876 tipc_node_mcast_rcv(n);
1877
+
1878
+ /* Handle NAME_DISTRIBUTOR messages sent from 1.7 nodes */
1879
+ if (!skb_queue_empty(&n->bc_entry.namedq))
1880
+ tipc_named_rcv(net, &n->bc_entry.namedq,
1881
+ &n->bc_entry.named_rcv_nxt,
1882
+ &n->bc_entry.named_open);
15531883
15541884 /* If reassembly or retransmission failure => reset all links to peer */
15551885 if (rc & TIPC_LINK_DOWN_EVT)
....@@ -1571,7 +1901,6 @@
15711901 int usr = msg_user(hdr);
15721902 int mtyp = msg_type(hdr);
15731903 u16 oseqno = msg_seqno(hdr);
1574
- u16 iseqno = msg_seqno(msg_get_wrapped(hdr));
15751904 u16 exp_pkts = msg_msgcnt(hdr);
15761905 u16 rcv_nxt, syncpt, dlv_nxt, inputq_len;
15771906 int state = n->state;
....@@ -1579,6 +1908,10 @@
15791908 struct tipc_media_addr *maddr;
15801909 int pb_id;
15811910
1911
+ if (trace_tipc_node_check_state_enabled()) {
1912
+ trace_tipc_skb_dump(skb, false, "skb for node state check");
1913
+ trace_tipc_node_check_state(n, true, " ");
1914
+ }
15821915 l = n->links[bearer_id].link;
15831916 if (!l)
15841917 return false;
....@@ -1596,8 +1929,11 @@
15961929 }
15971930 }
15981931
1599
- if (!tipc_link_validate_msg(l, hdr))
1932
+ if (!tipc_link_validate_msg(l, hdr)) {
1933
+ trace_tipc_skb_dump(skb, false, "PROTO invalid (2)!");
1934
+ trace_tipc_link_dump(l, TIPC_DUMP_NONE, "PROTO invalid (2)!");
16001935 return false;
1936
+ }
16011937
16021938 /* Check and update node accesibility if applicable */
16031939 if (state == SELF_UP_PEER_COMING) {
....@@ -1625,19 +1961,23 @@
16251961 /* Initiate or update failover mode if applicable */
16261962 if ((usr == TUNNEL_PROTOCOL) && (mtyp == FAILOVER_MSG)) {
16271963 syncpt = oseqno + exp_pkts - 1;
1628
- if (pl && tipc_link_is_up(pl)) {
1964
+ if (pl && !tipc_link_is_reset(pl)) {
16291965 __tipc_node_link_down(n, &pb_id, xmitq, &maddr);
1966
+ trace_tipc_node_link_down(n, true,
1967
+ "node link down <- failover!");
16301968 tipc_skb_queue_splice_tail_init(tipc_link_inputq(pl),
16311969 tipc_link_inputq(l));
16321970 }
1971
+
16331972 /* 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.
1973
+ * the tunnel link came up, node failover was never started.
1974
+ * Ensure that a FAILOVER_MSG is sent to get peer out of
1975
+ * NODE_FAILINGOVER state, also this node must accept
1976
+ * TUNNEL_MSGs from peer.
16361977 */
1637
- if (n->state != NODE_FAILINGOVER && !n->failover_sent) {
1638
- tipc_link_create_dummy_tnl_msg(l, xmitq);
1639
- n->failover_sent = true;
1640
- }
1978
+ if (n->state != NODE_FAILINGOVER)
1979
+ tipc_node_link_failover(n, pl, l, xmitq);
1980
+
16411981 /* If pkts arrive out of order, use lowest calculated syncpt */
16421982 if (less(syncpt, n->sync_point))
16431983 n->sync_point = syncpt;
....@@ -1659,7 +1999,10 @@
16591999
16602000 /* Initiate synch mode if applicable */
16612001 if ((usr == TUNNEL_PROTOCOL) && (mtyp == SYNCH_MSG) && (oseqno == 1)) {
1662
- syncpt = iseqno + exp_pkts - 1;
2002
+ if (n->capabilities & TIPC_TUNNEL_ENHANCED)
2003
+ syncpt = msg_syncpt(hdr);
2004
+ else
2005
+ syncpt = msg_seqno(msg_inner_hdr(hdr)) + exp_pkts - 1;
16632006 if (!tipc_link_is_up(l))
16642007 __tipc_node_link_up(n, bearer_id, xmitq);
16652008 if (n->state == SELF_UP_PEER_UP) {
....@@ -1699,7 +2042,7 @@
16992042 * tipc_rcv - process TIPC packets/messages arriving from off-node
17002043 * @net: the applicable net namespace
17012044 * @skb: TIPC packet
1702
- * @bearer: pointer to bearer message arrived on
2045
+ * @b: pointer to bearer message arrived on
17032046 *
17042047 * Invoked with no locks held. Bearer pointer must point to a valid bearer
17052048 * structure (i.e. cannot be NULL), but bearer can be inactive.
....@@ -1707,19 +2050,38 @@
17072050 void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
17082051 {
17092052 struct sk_buff_head xmitq;
1710
- struct tipc_node *n;
1711
- struct tipc_msg *hdr;
1712
- int bearer_id = b->identity;
17132053 struct tipc_link_entry *le;
2054
+ struct tipc_msg *hdr;
2055
+ struct tipc_node *n;
2056
+ int bearer_id = b->identity;
17142057 u32 self = tipc_own_addr(net);
17152058 int usr, rc = 0;
17162059 u16 bc_ack;
2060
+#ifdef CONFIG_TIPC_CRYPTO
2061
+ struct tipc_ehdr *ehdr;
17172062
1718
- __skb_queue_head_init(&xmitq);
2063
+ /* Check if message must be decrypted first */
2064
+ if (TIPC_SKB_CB(skb)->decrypted || !tipc_ehdr_validate(skb))
2065
+ goto rcv;
17192066
2067
+ ehdr = (struct tipc_ehdr *)skb->data;
2068
+ if (likely(ehdr->user != LINK_CONFIG)) {
2069
+ n = tipc_node_find(net, ntohl(ehdr->addr));
2070
+ if (unlikely(!n))
2071
+ goto discard;
2072
+ } else {
2073
+ n = tipc_node_find_by_id(net, ehdr->id);
2074
+ }
2075
+ tipc_crypto_rcv(net, (n) ? n->crypto_rx : NULL, &skb, b);
2076
+ if (!skb)
2077
+ return;
2078
+
2079
+rcv:
2080
+#endif
17202081 /* Ensure message is well-formed before touching the header */
17212082 if (unlikely(!tipc_msg_validate(&skb)))
17222083 goto discard;
2084
+ __skb_queue_head_init(&xmitq);
17232085 hdr = buf_msg(skb);
17242086 usr = msg_user(hdr);
17252087 bc_ack = msg_bcast_ack(hdr);
....@@ -1743,10 +2105,16 @@
17432105 le = &n->links[bearer_id];
17442106
17452107 /* Ensure broadcast reception is in synch with peer's send state */
1746
- if (unlikely(usr == LINK_PROTOCOL))
2108
+ if (unlikely(usr == LINK_PROTOCOL)) {
2109
+ if (unlikely(skb_linearize(skb))) {
2110
+ tipc_node_put(n);
2111
+ goto discard;
2112
+ }
2113
+ hdr = buf_msg(skb);
17472114 tipc_node_bc_sync_rcv(n, hdr, bearer_id, &xmitq);
1748
- else if (unlikely(tipc_link_acked(n->bc_entry.link) != bc_ack))
2115
+ } else if (unlikely(tipc_link_acked(n->bc_entry.link) != bc_ack)) {
17492116 tipc_bcast_ack_rcv(net, n->bc_entry.link, hdr);
2117
+ }
17502118
17512119 /* Receive packet directly if conditions permit */
17522120 tipc_node_read_lock(n);
....@@ -1763,7 +2131,7 @@
17632131 /* Check/update node state before receiving */
17642132 if (unlikely(skb)) {
17652133 if (unlikely(skb_linearize(skb)))
1766
- goto discard;
2134
+ goto out_node_put;
17672135 tipc_node_write_lock(n);
17682136 if (tipc_node_check_state(n, skb, bearer_id, &xmitq)) {
17692137 if (le->link) {
....@@ -1781,7 +2149,9 @@
17812149 tipc_node_link_down(n, bearer_id, false);
17822150
17832151 if (unlikely(!skb_queue_empty(&n->bc_entry.namedq)))
1784
- tipc_named_rcv(net, &n->bc_entry.namedq);
2152
+ tipc_named_rcv(net, &n->bc_entry.namedq,
2153
+ &n->bc_entry.named_rcv_nxt,
2154
+ &n->bc_entry.named_open);
17852155
17862156 if (unlikely(!skb_queue_empty(&n->bc_entry.inputq1)))
17872157 tipc_node_mcast_rcv(n);
....@@ -1790,8 +2160,9 @@
17902160 tipc_sk_rcv(net, &le->inputq);
17912161
17922162 if (!skb_queue_empty(&xmitq))
1793
- tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
2163
+ tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr, n);
17942164
2165
+out_node_put:
17952166 tipc_node_put(n);
17962167 discard:
17972168 kfree_skb(skb);
....@@ -1819,9 +2190,13 @@
18192190 &xmitq);
18202191 else if (prop == TIPC_NLA_PROP_MTU)
18212192 tipc_link_set_mtu(e->link, b->mtu);
2193
+
2194
+ /* Update MTU for node link entry */
2195
+ e->mtu = tipc_link_mss(e->link);
18222196 }
2197
+
18232198 tipc_node_write_unlock(n);
1824
- tipc_bearer_xmit(net, bearer_id, &xmitq, &e->maddr);
2199
+ tipc_bearer_xmit(net, bearer_id, &xmitq, &e->maddr, NULL);
18252200 }
18262201
18272202 rcu_read_unlock();
....@@ -1832,7 +2207,7 @@
18322207 struct net *net = sock_net(skb->sk);
18332208 struct tipc_net *tn = net_generic(net, tipc_net_id);
18342209 struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
1835
- struct tipc_node *peer;
2210
+ struct tipc_node *peer, *temp_node;
18362211 u32 addr;
18372212 int err;
18382213
....@@ -1840,9 +2215,9 @@
18402215 if (!info->attrs[TIPC_NLA_NET])
18412216 return -EINVAL;
18422217
1843
- err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
1844
- info->attrs[TIPC_NLA_NET], tipc_nl_net_policy,
1845
- info->extack);
2218
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_NET_MAX,
2219
+ info->attrs[TIPC_NLA_NET],
2220
+ tipc_nl_net_policy, info->extack);
18462221 if (err)
18472222 return err;
18482223
....@@ -1873,6 +2248,12 @@
18732248 tipc_node_write_unlock(peer);
18742249 tipc_node_delete(peer);
18752250
2251
+ /* Calculate cluster capabilities */
2252
+ tn->capabilities = TIPC_NODE_CAPABILITIES;
2253
+ list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
2254
+ tn->capabilities &= temp_node->capabilities;
2255
+ }
2256
+ tipc_bcast_toggle_rcast(net, (tn->capabilities & TIPC_BCAST_RCAST));
18762257 err = 0;
18772258 err_out:
18782259 tipc_node_put(peer);
....@@ -1917,6 +2298,8 @@
19172298 }
19182299
19192300 list_for_each_entry_rcu(node, &tn->node_list, list) {
2301
+ if (node->preliminary)
2302
+ continue;
19202303 if (last_addr) {
19212304 if (node->addr == last_addr)
19222305 last_addr = 0;
....@@ -1998,9 +2381,9 @@
19982381 if (!info->attrs[TIPC_NLA_LINK])
19992382 return -EINVAL;
20002383
2001
- err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
2002
- info->attrs[TIPC_NLA_LINK],
2003
- tipc_nl_link_policy, info->extack);
2384
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_LINK_MAX,
2385
+ info->attrs[TIPC_NLA_LINK],
2386
+ tipc_nl_link_policy, info->extack);
20042387 if (err)
20052388 return err;
20062389
....@@ -2027,8 +2410,7 @@
20272410 if (attrs[TIPC_NLA_LINK_PROP]) {
20282411 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
20292412
2030
- err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP],
2031
- props);
2413
+ err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP], props);
20322414 if (err) {
20332415 res = err;
20342416 goto out;
....@@ -2047,16 +2429,19 @@
20472429 tipc_link_set_prio(link, prio, &xmitq);
20482430 }
20492431 if (props[TIPC_NLA_PROP_WIN]) {
2050
- u32 win;
2432
+ u32 max_win;
20512433
2052
- win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
2053
- tipc_link_set_queue_limits(link, win);
2434
+ max_win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
2435
+ tipc_link_set_queue_limits(link,
2436
+ tipc_link_min_win(link),
2437
+ max_win);
20542438 }
20552439 }
20562440
20572441 out:
20582442 tipc_node_read_unlock(node);
2059
- tipc_bearer_xmit(net, bearer_id, &xmitq, &node->links[bearer_id].maddr);
2443
+ tipc_bearer_xmit(net, bearer_id, &xmitq, &node->links[bearer_id].maddr,
2444
+ NULL);
20602445 return res;
20612446 }
20622447
....@@ -2074,9 +2459,9 @@
20742459 if (!info->attrs[TIPC_NLA_LINK])
20752460 return -EINVAL;
20762461
2077
- err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
2078
- info->attrs[TIPC_NLA_LINK],
2079
- tipc_nl_link_policy, info->extack);
2462
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_LINK_MAX,
2463
+ info->attrs[TIPC_NLA_LINK],
2464
+ tipc_nl_link_policy, info->extack);
20802465 if (err)
20812466 return err;
20822467
....@@ -2090,7 +2475,7 @@
20902475 return -ENOMEM;
20912476
20922477 if (strcmp(name, tipc_bclink_name) == 0) {
2093
- err = tipc_nl_add_bc_link(net, &msg);
2478
+ err = tipc_nl_add_bc_link(net, &msg, tipc_net(net)->bcl);
20942479 if (err)
20952480 goto err_free;
20962481 } else {
....@@ -2134,14 +2519,15 @@
21342519 struct tipc_node *node;
21352520 struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1];
21362521 struct net *net = sock_net(skb->sk);
2522
+ struct tipc_net *tn = tipc_net(net);
21372523 struct tipc_link_entry *le;
21382524
21392525 if (!info->attrs[TIPC_NLA_LINK])
21402526 return -EINVAL;
21412527
2142
- err = nla_parse_nested(attrs, TIPC_NLA_LINK_MAX,
2143
- info->attrs[TIPC_NLA_LINK],
2144
- tipc_nl_link_policy, info->extack);
2528
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_LINK_MAX,
2529
+ info->attrs[TIPC_NLA_LINK],
2530
+ tipc_nl_link_policy, info->extack);
21452531 if (err)
21462532 return err;
21472533
....@@ -2150,11 +2536,26 @@
21502536
21512537 link_name = nla_data(attrs[TIPC_NLA_LINK_NAME]);
21522538
2153
- if (strcmp(link_name, tipc_bclink_name) == 0) {
2154
- err = tipc_bclink_reset_stats(net);
2539
+ err = -EINVAL;
2540
+ if (!strcmp(link_name, tipc_bclink_name)) {
2541
+ err = tipc_bclink_reset_stats(net, tipc_bc_sndlink(net));
21552542 if (err)
21562543 return err;
21572544 return 0;
2545
+ } else if (strstr(link_name, tipc_bclink_name)) {
2546
+ rcu_read_lock();
2547
+ list_for_each_entry_rcu(node, &tn->node_list, list) {
2548
+ tipc_node_read_lock(node);
2549
+ link = node->bc_entry.link;
2550
+ if (link && !strcmp(link_name, tipc_link_name(link))) {
2551
+ err = tipc_bclink_reset_stats(net, link);
2552
+ tipc_node_read_unlock(node);
2553
+ break;
2554
+ }
2555
+ tipc_node_read_unlock(node);
2556
+ }
2557
+ rcu_read_unlock();
2558
+ return err;
21582559 }
21592560
21602561 node = tipc_node_find_by_name(net, link_name, &bearer_id);
....@@ -2178,7 +2579,8 @@
21782579
21792580 /* Caller should hold node lock */
21802581 static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg,
2181
- struct tipc_node *node, u32 *prev_link)
2582
+ struct tipc_node *node, u32 *prev_link,
2583
+ bool bc_link)
21822584 {
21832585 u32 i;
21842586 int err;
....@@ -2194,6 +2596,14 @@
21942596 if (err)
21952597 return err;
21962598 }
2599
+
2600
+ if (bc_link) {
2601
+ *prev_link = i;
2602
+ err = tipc_nl_add_bc_link(net, msg, node->bc_entry.link);
2603
+ if (err)
2604
+ return err;
2605
+ }
2606
+
21972607 *prev_link = 0;
21982608
21992609 return 0;
....@@ -2202,16 +2612,35 @@
22022612 int tipc_nl_node_dump_link(struct sk_buff *skb, struct netlink_callback *cb)
22032613 {
22042614 struct net *net = sock_net(skb->sk);
2615
+ struct nlattr **attrs = genl_dumpit_info(cb)->attrs;
2616
+ struct nlattr *link[TIPC_NLA_LINK_MAX + 1];
22052617 struct tipc_net *tn = net_generic(net, tipc_net_id);
22062618 struct tipc_node *node;
22072619 struct tipc_nl_msg msg;
22082620 u32 prev_node = cb->args[0];
22092621 u32 prev_link = cb->args[1];
22102622 int done = cb->args[2];
2623
+ bool bc_link = cb->args[3];
22112624 int err;
22122625
22132626 if (done)
22142627 return 0;
2628
+
2629
+ if (!prev_node) {
2630
+ /* Check if broadcast-receiver links dumping is needed */
2631
+ if (attrs && attrs[TIPC_NLA_LINK]) {
2632
+ err = nla_parse_nested_deprecated(link,
2633
+ TIPC_NLA_LINK_MAX,
2634
+ attrs[TIPC_NLA_LINK],
2635
+ tipc_nl_link_policy,
2636
+ NULL);
2637
+ if (unlikely(err))
2638
+ return err;
2639
+ if (unlikely(!link[TIPC_NLA_LINK_BROADCAST]))
2640
+ return -EINVAL;
2641
+ bc_link = true;
2642
+ }
2643
+ }
22152644
22162645 msg.skb = skb;
22172646 msg.portid = NETLINK_CB(cb->skb).portid;
....@@ -2236,7 +2665,7 @@
22362665 list) {
22372666 tipc_node_read_lock(node);
22382667 err = __tipc_nl_add_node_links(net, &msg, node,
2239
- &prev_link);
2668
+ &prev_link, bc_link);
22402669 tipc_node_read_unlock(node);
22412670 if (err)
22422671 goto out;
....@@ -2244,14 +2673,14 @@
22442673 prev_node = node->addr;
22452674 }
22462675 } else {
2247
- err = tipc_nl_add_bc_link(net, &msg);
2676
+ err = tipc_nl_add_bc_link(net, &msg, tn->bcl);
22482677 if (err)
22492678 goto out;
22502679
22512680 list_for_each_entry_rcu(node, &tn->node_list, list) {
22522681 tipc_node_read_lock(node);
22532682 err = __tipc_nl_add_node_links(net, &msg, node,
2254
- &prev_link);
2683
+ &prev_link, bc_link);
22552684 tipc_node_read_unlock(node);
22562685 if (err)
22572686 goto out;
....@@ -2266,6 +2695,7 @@
22662695 cb->args[0] = prev_node;
22672696 cb->args[1] = prev_link;
22682697 cb->args[2] = done;
2698
+ cb->args[3] = bc_link;
22692699
22702700 return skb->len;
22712701 }
....@@ -2279,9 +2709,10 @@
22792709 if (!info->attrs[TIPC_NLA_MON])
22802710 return -EINVAL;
22812711
2282
- err = nla_parse_nested(attrs, TIPC_NLA_MON_MAX,
2283
- info->attrs[TIPC_NLA_MON],
2284
- tipc_nl_monitor_policy, info->extack);
2712
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_MON_MAX,
2713
+ info->attrs[TIPC_NLA_MON],
2714
+ tipc_nl_monitor_policy,
2715
+ info->extack);
22852716 if (err)
22862717 return err;
22872718
....@@ -2308,7 +2739,7 @@
23082739 if (!hdr)
23092740 return -EMSGSIZE;
23102741
2311
- attrs = nla_nest_start(msg->skb, TIPC_NLA_MON);
2742
+ attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_MON);
23122743 if (!attrs)
23132744 goto msg_full;
23142745
....@@ -2389,19 +2820,16 @@
23892820 int err;
23902821
23912822 if (!prev_node) {
2392
- struct nlattr **attrs;
2823
+ struct nlattr **attrs = genl_dumpit_info(cb)->attrs;
23932824 struct nlattr *mon[TIPC_NLA_MON_MAX + 1];
2394
-
2395
- err = tipc_nlmsg_parse(cb->nlh, &attrs);
2396
- if (err)
2397
- return err;
23982825
23992826 if (!attrs[TIPC_NLA_MON])
24002827 return -EINVAL;
24012828
2402
- err = nla_parse_nested(mon, TIPC_NLA_MON_MAX,
2403
- attrs[TIPC_NLA_MON],
2404
- tipc_nl_monitor_policy, NULL);
2829
+ err = nla_parse_nested_deprecated(mon, TIPC_NLA_MON_MAX,
2830
+ attrs[TIPC_NLA_MON],
2831
+ tipc_nl_monitor_policy,
2832
+ NULL);
24052833 if (err)
24062834 return err;
24072835
....@@ -2433,3 +2861,256 @@
24332861
24342862 return skb->len;
24352863 }
2864
+
2865
+#ifdef CONFIG_TIPC_CRYPTO
2866
+static int tipc_nl_retrieve_key(struct nlattr **attrs,
2867
+ struct tipc_aead_key **pkey)
2868
+{
2869
+ struct nlattr *attr = attrs[TIPC_NLA_NODE_KEY];
2870
+ struct tipc_aead_key *key;
2871
+
2872
+ if (!attr)
2873
+ return -ENODATA;
2874
+
2875
+ if (nla_len(attr) < sizeof(*key))
2876
+ return -EINVAL;
2877
+ key = (struct tipc_aead_key *)nla_data(attr);
2878
+ if (key->keylen > TIPC_AEAD_KEYLEN_MAX ||
2879
+ nla_len(attr) < tipc_aead_key_size(key))
2880
+ return -EINVAL;
2881
+
2882
+ *pkey = key;
2883
+ return 0;
2884
+}
2885
+
2886
+static int tipc_nl_retrieve_nodeid(struct nlattr **attrs, u8 **node_id)
2887
+{
2888
+ struct nlattr *attr = attrs[TIPC_NLA_NODE_ID];
2889
+
2890
+ if (!attr)
2891
+ return -ENODATA;
2892
+
2893
+ if (nla_len(attr) < TIPC_NODEID_LEN)
2894
+ return -EINVAL;
2895
+
2896
+ *node_id = (u8 *)nla_data(attr);
2897
+ return 0;
2898
+}
2899
+
2900
+static int tipc_nl_retrieve_rekeying(struct nlattr **attrs, u32 *intv)
2901
+{
2902
+ struct nlattr *attr = attrs[TIPC_NLA_NODE_REKEYING];
2903
+
2904
+ if (!attr)
2905
+ return -ENODATA;
2906
+
2907
+ *intv = nla_get_u32(attr);
2908
+ return 0;
2909
+}
2910
+
2911
+static int __tipc_nl_node_set_key(struct sk_buff *skb, struct genl_info *info)
2912
+{
2913
+ struct nlattr *attrs[TIPC_NLA_NODE_MAX + 1];
2914
+ struct net *net = sock_net(skb->sk);
2915
+ struct tipc_crypto *tx = tipc_net(net)->crypto_tx, *c = tx;
2916
+ struct tipc_node *n = NULL;
2917
+ struct tipc_aead_key *ukey;
2918
+ bool rekeying = true, master_key = false;
2919
+ u8 *id, *own_id, mode;
2920
+ u32 intv = 0;
2921
+ int rc = 0;
2922
+
2923
+ if (!info->attrs[TIPC_NLA_NODE])
2924
+ return -EINVAL;
2925
+
2926
+ rc = nla_parse_nested(attrs, TIPC_NLA_NODE_MAX,
2927
+ info->attrs[TIPC_NLA_NODE],
2928
+ tipc_nl_node_policy, info->extack);
2929
+ if (rc)
2930
+ return rc;
2931
+
2932
+ own_id = tipc_own_id(net);
2933
+ if (!own_id) {
2934
+ GENL_SET_ERR_MSG(info, "not found own node identity (set id?)");
2935
+ return -EPERM;
2936
+ }
2937
+
2938
+ rc = tipc_nl_retrieve_rekeying(attrs, &intv);
2939
+ if (rc == -ENODATA)
2940
+ rekeying = false;
2941
+
2942
+ rc = tipc_nl_retrieve_key(attrs, &ukey);
2943
+ if (rc == -ENODATA && rekeying)
2944
+ goto rekeying;
2945
+ else if (rc)
2946
+ return rc;
2947
+
2948
+ rc = tipc_aead_key_validate(ukey, info);
2949
+ if (rc)
2950
+ return rc;
2951
+
2952
+ rc = tipc_nl_retrieve_nodeid(attrs, &id);
2953
+ switch (rc) {
2954
+ case -ENODATA:
2955
+ mode = CLUSTER_KEY;
2956
+ master_key = !!(attrs[TIPC_NLA_NODE_KEY_MASTER]);
2957
+ break;
2958
+ case 0:
2959
+ mode = PER_NODE_KEY;
2960
+ if (memcmp(id, own_id, NODE_ID_LEN)) {
2961
+ n = tipc_node_find_by_id(net, id) ?:
2962
+ tipc_node_create(net, 0, id, 0xffffu, 0, true);
2963
+ if (unlikely(!n))
2964
+ return -ENOMEM;
2965
+ c = n->crypto_rx;
2966
+ }
2967
+ break;
2968
+ default:
2969
+ return rc;
2970
+ }
2971
+
2972
+ /* Initiate the TX/RX key */
2973
+ rc = tipc_crypto_key_init(c, ukey, mode, master_key);
2974
+ if (n)
2975
+ tipc_node_put(n);
2976
+
2977
+ if (unlikely(rc < 0)) {
2978
+ GENL_SET_ERR_MSG(info, "unable to initiate or attach new key");
2979
+ return rc;
2980
+ } else if (c == tx) {
2981
+ /* Distribute TX key but not master one */
2982
+ if (!master_key && tipc_crypto_key_distr(tx, rc, NULL))
2983
+ GENL_SET_ERR_MSG(info, "failed to replicate new key");
2984
+rekeying:
2985
+ /* Schedule TX rekeying if needed */
2986
+ tipc_crypto_rekeying_sched(tx, rekeying, intv);
2987
+ }
2988
+
2989
+ return 0;
2990
+}
2991
+
2992
+int tipc_nl_node_set_key(struct sk_buff *skb, struct genl_info *info)
2993
+{
2994
+ int err;
2995
+
2996
+ rtnl_lock();
2997
+ err = __tipc_nl_node_set_key(skb, info);
2998
+ rtnl_unlock();
2999
+
3000
+ return err;
3001
+}
3002
+
3003
+static int __tipc_nl_node_flush_key(struct sk_buff *skb,
3004
+ struct genl_info *info)
3005
+{
3006
+ struct net *net = sock_net(skb->sk);
3007
+ struct tipc_net *tn = tipc_net(net);
3008
+ struct tipc_node *n;
3009
+
3010
+ tipc_crypto_key_flush(tn->crypto_tx);
3011
+ rcu_read_lock();
3012
+ list_for_each_entry_rcu(n, &tn->node_list, list)
3013
+ tipc_crypto_key_flush(n->crypto_rx);
3014
+ rcu_read_unlock();
3015
+
3016
+ return 0;
3017
+}
3018
+
3019
+int tipc_nl_node_flush_key(struct sk_buff *skb, struct genl_info *info)
3020
+{
3021
+ int err;
3022
+
3023
+ rtnl_lock();
3024
+ err = __tipc_nl_node_flush_key(skb, info);
3025
+ rtnl_unlock();
3026
+
3027
+ return err;
3028
+}
3029
+#endif
3030
+
3031
+/**
3032
+ * tipc_node_dump - dump TIPC node data
3033
+ * @n: tipc node to be dumped
3034
+ * @more: dump more?
3035
+ * - false: dump only tipc node data
3036
+ * - true: dump node link data as well
3037
+ * @buf: returned buffer of dump data in format
3038
+ */
3039
+int tipc_node_dump(struct tipc_node *n, bool more, char *buf)
3040
+{
3041
+ int i = 0;
3042
+ size_t sz = (more) ? NODE_LMAX : NODE_LMIN;
3043
+
3044
+ if (!n) {
3045
+ i += scnprintf(buf, sz, "node data: (null)\n");
3046
+ return i;
3047
+ }
3048
+
3049
+ i += scnprintf(buf, sz, "node data: %x", n->addr);
3050
+ i += scnprintf(buf + i, sz - i, " %x", n->state);
3051
+ i += scnprintf(buf + i, sz - i, " %d", n->active_links[0]);
3052
+ i += scnprintf(buf + i, sz - i, " %d", n->active_links[1]);
3053
+ i += scnprintf(buf + i, sz - i, " %x", n->action_flags);
3054
+ i += scnprintf(buf + i, sz - i, " %u", n->failover_sent);
3055
+ i += scnprintf(buf + i, sz - i, " %u", n->sync_point);
3056
+ i += scnprintf(buf + i, sz - i, " %d", n->link_cnt);
3057
+ i += scnprintf(buf + i, sz - i, " %u", n->working_links);
3058
+ i += scnprintf(buf + i, sz - i, " %x", n->capabilities);
3059
+ i += scnprintf(buf + i, sz - i, " %lu\n", n->keepalive_intv);
3060
+
3061
+ if (!more)
3062
+ return i;
3063
+
3064
+ i += scnprintf(buf + i, sz - i, "link_entry[0]:\n");
3065
+ i += scnprintf(buf + i, sz - i, " mtu: %u\n", n->links[0].mtu);
3066
+ i += scnprintf(buf + i, sz - i, " media: ");
3067
+ i += tipc_media_addr_printf(buf + i, sz - i, &n->links[0].maddr);
3068
+ i += scnprintf(buf + i, sz - i, "\n");
3069
+ i += tipc_link_dump(n->links[0].link, TIPC_DUMP_NONE, buf + i);
3070
+ i += scnprintf(buf + i, sz - i, " inputq: ");
3071
+ i += tipc_list_dump(&n->links[0].inputq, false, buf + i);
3072
+
3073
+ i += scnprintf(buf + i, sz - i, "link_entry[1]:\n");
3074
+ i += scnprintf(buf + i, sz - i, " mtu: %u\n", n->links[1].mtu);
3075
+ i += scnprintf(buf + i, sz - i, " media: ");
3076
+ i += tipc_media_addr_printf(buf + i, sz - i, &n->links[1].maddr);
3077
+ i += scnprintf(buf + i, sz - i, "\n");
3078
+ i += tipc_link_dump(n->links[1].link, TIPC_DUMP_NONE, buf + i);
3079
+ i += scnprintf(buf + i, sz - i, " inputq: ");
3080
+ i += tipc_list_dump(&n->links[1].inputq, false, buf + i);
3081
+
3082
+ i += scnprintf(buf + i, sz - i, "bclink:\n ");
3083
+ i += tipc_link_dump(n->bc_entry.link, TIPC_DUMP_NONE, buf + i);
3084
+
3085
+ return i;
3086
+}
3087
+
3088
+void tipc_node_pre_cleanup_net(struct net *exit_net)
3089
+{
3090
+ struct tipc_node *n;
3091
+ struct tipc_net *tn;
3092
+ struct net *tmp;
3093
+
3094
+ rcu_read_lock();
3095
+ for_each_net_rcu(tmp) {
3096
+ if (tmp == exit_net)
3097
+ continue;
3098
+ tn = tipc_net(tmp);
3099
+ if (!tn)
3100
+ continue;
3101
+ spin_lock_bh(&tn->node_list_lock);
3102
+ list_for_each_entry_rcu(n, &tn->node_list, list) {
3103
+ if (!n->peer_net)
3104
+ continue;
3105
+ if (n->peer_net != exit_net)
3106
+ continue;
3107
+ tipc_node_write_lock(n);
3108
+ n->peer_net = NULL;
3109
+ n->peer_hash_mix = 0;
3110
+ tipc_node_write_unlock_fast(n);
3111
+ break;
3112
+ }
3113
+ spin_unlock_bh(&tn->node_list_lock);
3114
+ }
3115
+ rcu_read_unlock();
3116
+}