node.c (5d7d28e5fff9668ee8ea6a5f1459276330767aa9) | node.c (7b50ee3dad2581dc022b4e32e55964d4fcdccf20) |
---|---|
1/* 2 * net/tipc/node.c: TIPC node management routines 3 * 4 * Copyright (c) 2000-2006, 2012-2016, Ericsson AB 5 * Copyright (c) 2005-2006, 2010-2014, Wind River Systems 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 264 unchanged lines hidden (view full) --- 273{ 274 return (__n) ? __n->crypto_rx : NULL; 275} 276 277struct 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} | 1/* 2 * net/tipc/node.c: TIPC node management routines 3 * 4 * Copyright (c) 2000-2006, 2012-2016, Ericsson AB 5 * Copyright (c) 2005-2006, 2010-2014, Wind River Systems 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 264 unchanged lines hidden (view full) --- 273{ 274 return (__n) ? __n->crypto_rx : NULL; 275} 276 277struct 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 282struct 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 291static 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); --- 9 unchanged lines hidden (view full) --- 306 call_rcu(&n->rcu, tipc_node_free); 307} 308 309void tipc_node_put(struct tipc_node *node) 310{ 311 kref_put(&node->kref, tipc_node_kref_release); 312} 313 | 281#endif 282 283static void tipc_node_free(struct rcu_head *rp) 284{ 285 struct tipc_node *n = container_of(rp, struct tipc_node, rcu); 286 287#ifdef CONFIG_TIPC_CRYPTO 288 tipc_crypto_stop(&n->crypto_rx); --- 9 unchanged lines hidden (view full) --- 298 call_rcu(&n->rcu, tipc_node_free); 299} 300 301void tipc_node_put(struct tipc_node *node) 302{ 303 kref_put(&node->kref, tipc_node_kref_release); 304} 305 |
314void tipc_node_get(struct tipc_node *node) | 306static void tipc_node_get(struct tipc_node *node) |
315{ 316 kref_get(&node->kref); 317} 318 319/* 320 * tipc_node_find - locate specified node object, if it exists 321 */ 322static struct tipc_node *tipc_node_find(struct net *net, u32 addr) --- 264 unchanged lines hidden (view full) --- 587 n->keepalive_intv = intv; 588 589 /* Ensure link's abort limit corresponds to current tolerance */ 590 tipc_link_set_abort_limit(l, tol / n->keepalive_intv); 591} 592 593static void tipc_node_delete_from_list(struct tipc_node *node) 594{ | 307{ 308 kref_get(&node->kref); 309} 310 311/* 312 * tipc_node_find - locate specified node object, if it exists 313 */ 314static struct tipc_node *tipc_node_find(struct net *net, u32 addr) --- 264 unchanged lines hidden (view full) --- 579 n->keepalive_intv = intv; 580 581 /* Ensure link's abort limit corresponds to current tolerance */ 582 tipc_link_set_abort_limit(l, tol / n->keepalive_intv); 583} 584 585static void tipc_node_delete_from_list(struct tipc_node *node) 586{ |
595#ifdef CONFIG_TIPC_CRYPTO 596 tipc_crypto_key_flush(node->crypto_rx); 597#endif | |
598 list_del_rcu(&node->list); 599 hlist_del_rcu(&node->hash); 600 tipc_node_put(node); 601} 602 603static void tipc_node_delete(struct tipc_node *node) 604{ 605 trace_tipc_node_delete(node, true, " "); --- 885 unchanged lines hidden (view full) --- 1491 uint i; 1492 1493 pr_debug("Lost contact with %x\n", n->addr); 1494 n->delete_at = jiffies + msecs_to_jiffies(NODE_CLEANUP_AFTER); 1495 trace_tipc_node_lost_contact(n, true, " "); 1496 1497 /* Clean up broadcast state */ 1498 tipc_bcast_remove_peer(n->net, n->bc_entry.link); | 587 list_del_rcu(&node->list); 588 hlist_del_rcu(&node->hash); 589 tipc_node_put(node); 590} 591 592static void tipc_node_delete(struct tipc_node *node) 593{ 594 trace_tipc_node_delete(node, true, " "); --- 885 unchanged lines hidden (view full) --- 1480 uint i; 1481 1482 pr_debug("Lost contact with %x\n", n->addr); 1483 n->delete_at = jiffies + msecs_to_jiffies(NODE_CLEANUP_AFTER); 1484 trace_tipc_node_lost_contact(n, true, " "); 1485 1486 /* Clean up broadcast state */ 1487 tipc_bcast_remove_peer(n->net, n->bc_entry.link); |
1499 __skb_queue_purge(&n->bc_entry.namedq); | 1488 skb_queue_purge(&n->bc_entry.namedq); |
1500 1501 /* Abort any ongoing link failover */ 1502 for (i = 0; i < MAX_BEARERS; i++) { 1503 l = n->links[i].link; 1504 if (l) 1505 tipc_link_fsm_evt(l, LINK_FAILOVER_END_EVT); 1506 } 1507 --- 1366 unchanged lines hidden (view full) --- 2874 2875 if (nla_len(attr) < TIPC_NODEID_LEN) 2876 return -EINVAL; 2877 2878 *node_id = (u8 *)nla_data(attr); 2879 return 0; 2880} 2881 | 1489 1490 /* Abort any ongoing link failover */ 1491 for (i = 0; i < MAX_BEARERS; i++) { 1492 l = n->links[i].link; 1493 if (l) 1494 tipc_link_fsm_evt(l, LINK_FAILOVER_END_EVT); 1495 } 1496 --- 1366 unchanged lines hidden (view full) --- 2863 2864 if (nla_len(attr) < TIPC_NODEID_LEN) 2865 return -EINVAL; 2866 2867 *node_id = (u8 *)nla_data(attr); 2868 return 0; 2869} 2870 |
2882static int tipc_nl_retrieve_rekeying(struct nlattr **attrs, u32 *intv) 2883{ 2884 struct nlattr *attr = attrs[TIPC_NLA_NODE_REKEYING]; 2885 2886 if (!attr) 2887 return -ENODATA; 2888 2889 *intv = nla_get_u32(attr); 2890 return 0; 2891} 2892 | |
2893static int __tipc_nl_node_set_key(struct sk_buff *skb, struct genl_info *info) 2894{ 2895 struct nlattr *attrs[TIPC_NLA_NODE_MAX + 1]; 2896 struct net *net = sock_net(skb->sk); | 2871static int __tipc_nl_node_set_key(struct sk_buff *skb, struct genl_info *info) 2872{ 2873 struct nlattr *attrs[TIPC_NLA_NODE_MAX + 1]; 2874 struct net *net = sock_net(skb->sk); |
2897 struct tipc_crypto *tx = tipc_net(net)->crypto_tx, *c = tx; | 2875 struct tipc_net *tn = tipc_net(net); |
2898 struct tipc_node *n = NULL; 2899 struct tipc_aead_key *ukey; | 2876 struct tipc_node *n = NULL; 2877 struct tipc_aead_key *ukey; |
2900 bool rekeying = true, master_key = false; 2901 u8 *id, *own_id, mode; 2902 u32 intv = 0; | 2878 struct tipc_crypto *c; 2879 u8 *id, *own_id; |
2903 int rc = 0; 2904 2905 if (!info->attrs[TIPC_NLA_NODE]) 2906 return -EINVAL; 2907 2908 rc = nla_parse_nested(attrs, TIPC_NLA_NODE_MAX, 2909 info->attrs[TIPC_NLA_NODE], 2910 tipc_nl_node_policy, info->extack); 2911 if (rc) | 2880 int rc = 0; 2881 2882 if (!info->attrs[TIPC_NLA_NODE]) 2883 return -EINVAL; 2884 2885 rc = nla_parse_nested(attrs, TIPC_NLA_NODE_MAX, 2886 info->attrs[TIPC_NLA_NODE], 2887 tipc_nl_node_policy, info->extack); 2888 if (rc) |
2912 return rc; | 2889 goto exit; |
2913 2914 own_id = tipc_own_id(net); 2915 if (!own_id) { | 2890 2891 own_id = tipc_own_id(net); 2892 if (!own_id) { |
2916 GENL_SET_ERR_MSG(info, "not found own node identity (set id?)"); 2917 return -EPERM; | 2893 rc = -EPERM; 2894 goto exit; |
2918 } 2919 | 2895 } 2896 |
2920 rc = tipc_nl_retrieve_rekeying(attrs, &intv); 2921 if (rc == -ENODATA) 2922 rekeying = false; 2923 | |
2924 rc = tipc_nl_retrieve_key(attrs, &ukey); | 2897 rc = tipc_nl_retrieve_key(attrs, &ukey); |
2925 if (rc == -ENODATA && rekeying) 2926 goto rekeying; 2927 else if (rc) 2928 return rc; | 2898 if (rc) 2899 goto exit; |
2929 | 2900 |
2930 rc = tipc_aead_key_validate(ukey, info); | 2901 rc = tipc_aead_key_validate(ukey); |
2931 if (rc) | 2902 if (rc) |
2932 return rc; | 2903 goto exit; |
2933 2934 rc = tipc_nl_retrieve_nodeid(attrs, &id); 2935 switch (rc) { 2936 case -ENODATA: | 2904 2905 rc = tipc_nl_retrieve_nodeid(attrs, &id); 2906 switch (rc) { 2907 case -ENODATA: |
2937 mode = CLUSTER_KEY; 2938 master_key = !!(attrs[TIPC_NLA_NODE_KEY_MASTER]); | 2908 /* Cluster key mode */ 2909 rc = tipc_crypto_key_init(tn->crypto_tx, ukey, CLUSTER_KEY); |
2939 break; 2940 case 0: | 2910 break; 2911 case 0: |
2941 mode = PER_NODE_KEY; 2942 if (memcmp(id, own_id, NODE_ID_LEN)) { | 2912 /* Per-node key mode */ 2913 if (!memcmp(id, own_id, NODE_ID_LEN)) { 2914 c = tn->crypto_tx; 2915 } else { |
2943 n = tipc_node_find_by_id(net, id) ?: 2944 tipc_node_create(net, 0, id, 0xffffu, 0, true); | 2916 n = tipc_node_find_by_id(net, id) ?: 2917 tipc_node_create(net, 0, id, 0xffffu, 0, true); |
2945 if (unlikely(!n)) 2946 return -ENOMEM; | 2918 if (unlikely(!n)) { 2919 rc = -ENOMEM; 2920 break; 2921 } |
2947 c = n->crypto_rx; 2948 } | 2922 c = n->crypto_rx; 2923 } |
2924 2925 rc = tipc_crypto_key_init(c, ukey, PER_NODE_KEY); 2926 if (n) 2927 tipc_node_put(n); |
|
2949 break; 2950 default: | 2928 break; 2929 default: |
2951 return rc; | 2930 break; |
2952 } 2953 | 2931 } 2932 |
2954 /* Initiate the TX/RX key */ 2955 rc = tipc_crypto_key_init(c, ukey, mode, master_key); 2956 if (n) 2957 tipc_node_put(n); 2958 2959 if (unlikely(rc < 0)) { 2960 GENL_SET_ERR_MSG(info, "unable to initiate or attach new key"); 2961 return rc; 2962 } else if (c == tx) { 2963 /* Distribute TX key but not master one */ 2964 if (!master_key && tipc_crypto_key_distr(tx, rc, NULL)) 2965 GENL_SET_ERR_MSG(info, "failed to replicate new key"); 2966rekeying: 2967 /* Schedule TX rekeying if needed */ 2968 tipc_crypto_rekeying_sched(tx, rekeying, intv); 2969 } 2970 2971 return 0; | 2933exit: 2934 return (rc < 0) ? rc : 0; |
2972} 2973 2974int tipc_nl_node_set_key(struct sk_buff *skb, struct genl_info *info) 2975{ 2976 int err; 2977 2978 rtnl_lock(); 2979 err = __tipc_nl_node_set_key(skb, info); --- 10 unchanged lines hidden (view full) --- 2990 struct tipc_node *n; 2991 2992 tipc_crypto_key_flush(tn->crypto_tx); 2993 rcu_read_lock(); 2994 list_for_each_entry_rcu(n, &tn->node_list, list) 2995 tipc_crypto_key_flush(n->crypto_rx); 2996 rcu_read_unlock(); 2997 | 2935} 2936 2937int tipc_nl_node_set_key(struct sk_buff *skb, struct genl_info *info) 2938{ 2939 int err; 2940 2941 rtnl_lock(); 2942 err = __tipc_nl_node_set_key(skb, info); --- 10 unchanged lines hidden (view full) --- 2953 struct tipc_node *n; 2954 2955 tipc_crypto_key_flush(tn->crypto_tx); 2956 rcu_read_lock(); 2957 list_for_each_entry_rcu(n, &tn->node_list, list) 2958 tipc_crypto_key_flush(n->crypto_rx); 2959 rcu_read_unlock(); 2960 |
2961 pr_info("All keys are flushed!\n"); |
|
2998 return 0; 2999} 3000 3001int tipc_nl_node_flush_key(struct sk_buff *skb, struct genl_info *info) 3002{ 3003 int err; 3004 3005 rtnl_lock(); --- 93 unchanged lines hidden --- | 2962 return 0; 2963} 2964 2965int tipc_nl_node_flush_key(struct sk_buff *skb, struct genl_info *info) 2966{ 2967 int err; 2968 2969 rtnl_lock(); --- 93 unchanged lines hidden --- |