diff options
Diffstat (limited to 'net/tipc/core.c')
| -rw-r--r-- | net/tipc/core.c | 154 |
1 files changed, 71 insertions, 83 deletions
diff --git a/net/tipc/core.c b/net/tipc/core.c index a5737b8407dd..935205e6bcfe 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c | |||
| @@ -34,82 +34,88 @@ | |||
| 34 | * POSSIBILITY OF SUCH DAMAGE. | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 38 | |||
| 37 | #include "core.h" | 39 | #include "core.h" |
| 38 | #include "name_table.h" | 40 | #include "name_table.h" |
| 39 | #include "subscr.h" | 41 | #include "subscr.h" |
| 40 | #include "config.h" | 42 | #include "bearer.h" |
| 43 | #include "net.h" | ||
| 41 | #include "socket.h" | 44 | #include "socket.h" |
| 42 | 45 | ||
| 43 | #include <linux/module.h> | 46 | #include <linux/module.h> |
| 44 | 47 | ||
| 45 | /* global variables used by multiple sub-systems within TIPC */ | ||
| 46 | int tipc_random __read_mostly; | ||
| 47 | |||
| 48 | /* configurable TIPC parameters */ | 48 | /* configurable TIPC parameters */ |
| 49 | u32 tipc_own_addr __read_mostly; | ||
| 50 | int tipc_max_ports __read_mostly; | ||
| 51 | int tipc_net_id __read_mostly; | 49 | int tipc_net_id __read_mostly; |
| 52 | int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */ | 50 | int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */ |
| 53 | 51 | ||
| 54 | /** | 52 | static int __net_init tipc_init_net(struct net *net) |
| 55 | * tipc_buf_acquire - creates a TIPC message buffer | ||
| 56 | * @size: message size (including TIPC header) | ||
| 57 | * | ||
| 58 | * Returns a new buffer with data pointers set to the specified size. | ||
| 59 | * | ||
| 60 | * NOTE: Headroom is reserved to allow prepending of a data link header. | ||
| 61 | * There may also be unrequested tailroom present at the buffer's end. | ||
| 62 | */ | ||
| 63 | struct sk_buff *tipc_buf_acquire(u32 size) | ||
| 64 | { | 53 | { |
| 65 | struct sk_buff *skb; | 54 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 66 | unsigned int buf_size = (BUF_HEADROOM + size + 3) & ~3u; | 55 | int err; |
| 67 | 56 | ||
| 68 | skb = alloc_skb_fclone(buf_size, GFP_ATOMIC); | 57 | tn->net_id = 4711; |
| 69 | if (skb) { | 58 | tn->own_addr = 0; |
| 70 | skb_reserve(skb, BUF_HEADROOM); | 59 | get_random_bytes(&tn->random, sizeof(int)); |
| 71 | skb_put(skb, size); | 60 | INIT_LIST_HEAD(&tn->node_list); |
| 72 | skb->next = NULL; | 61 | spin_lock_init(&tn->node_list_lock); |
| 73 | } | 62 | |
| 74 | return skb; | 63 | err = tipc_sk_rht_init(net); |
| 64 | if (err) | ||
| 65 | goto out_sk_rht; | ||
| 66 | |||
| 67 | err = tipc_nametbl_init(net); | ||
| 68 | if (err) | ||
| 69 | goto out_nametbl; | ||
| 70 | |||
| 71 | err = tipc_subscr_start(net); | ||
| 72 | if (err) | ||
| 73 | goto out_subscr; | ||
| 74 | return 0; | ||
| 75 | |||
| 76 | out_subscr: | ||
| 77 | tipc_nametbl_stop(net); | ||
| 78 | out_nametbl: | ||
| 79 | tipc_sk_rht_destroy(net); | ||
| 80 | out_sk_rht: | ||
| 81 | return err; | ||
| 75 | } | 82 | } |
| 76 | 83 | ||
| 77 | /** | 84 | static void __net_exit tipc_exit_net(struct net *net) |
| 78 | * tipc_core_stop - switch TIPC from SINGLE NODE to NOT RUNNING mode | ||
| 79 | */ | ||
| 80 | static void tipc_core_stop(void) | ||
| 81 | { | 85 | { |
| 82 | tipc_net_stop(); | 86 | tipc_subscr_stop(net); |
| 83 | tipc_bearer_cleanup(); | 87 | tipc_net_stop(net); |
| 84 | tipc_netlink_stop(); | 88 | tipc_nametbl_stop(net); |
| 85 | tipc_subscr_stop(); | 89 | tipc_sk_rht_destroy(net); |
| 86 | tipc_nametbl_stop(); | ||
| 87 | tipc_sk_ref_table_stop(); | ||
| 88 | tipc_socket_stop(); | ||
| 89 | tipc_unregister_sysctl(); | ||
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | /** | 92 | static struct pernet_operations tipc_net_ops = { |
| 93 | * tipc_core_start - switch TIPC from NOT RUNNING to SINGLE NODE mode | 93 | .init = tipc_init_net, |
| 94 | */ | 94 | .exit = tipc_exit_net, |
| 95 | static int tipc_core_start(void) | 95 | .id = &tipc_net_id, |
| 96 | .size = sizeof(struct tipc_net), | ||
| 97 | }; | ||
| 98 | |||
| 99 | static int __init tipc_init(void) | ||
| 96 | { | 100 | { |
| 97 | int err; | 101 | int err; |
| 98 | 102 | ||
| 99 | get_random_bytes(&tipc_random, sizeof(tipc_random)); | 103 | pr_info("Activated (version " TIPC_MOD_VER ")\n"); |
| 100 | |||
| 101 | err = tipc_sk_ref_table_init(tipc_max_ports, tipc_random); | ||
| 102 | if (err) | ||
| 103 | goto out_reftbl; | ||
| 104 | 104 | ||
| 105 | err = tipc_nametbl_init(); | 105 | sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 << |
| 106 | if (err) | 106 | TIPC_LOW_IMPORTANCE; |
| 107 | goto out_nametbl; | 107 | sysctl_tipc_rmem[1] = TIPC_CONN_OVERLOAD_LIMIT >> 4 << |
| 108 | TIPC_CRITICAL_IMPORTANCE; | ||
| 109 | sysctl_tipc_rmem[2] = TIPC_CONN_OVERLOAD_LIMIT; | ||
| 108 | 110 | ||
| 109 | err = tipc_netlink_start(); | 111 | err = tipc_netlink_start(); |
| 110 | if (err) | 112 | if (err) |
| 111 | goto out_netlink; | 113 | goto out_netlink; |
| 112 | 114 | ||
| 115 | err = tipc_netlink_compat_start(); | ||
| 116 | if (err) | ||
| 117 | goto out_netlink_compat; | ||
| 118 | |||
| 113 | err = tipc_socket_init(); | 119 | err = tipc_socket_init(); |
| 114 | if (err) | 120 | if (err) |
| 115 | goto out_socket; | 121 | goto out_socket; |
| @@ -118,58 +124,40 @@ static int tipc_core_start(void) | |||
| 118 | if (err) | 124 | if (err) |
| 119 | goto out_sysctl; | 125 | goto out_sysctl; |
| 120 | 126 | ||
| 121 | err = tipc_subscr_start(); | 127 | err = register_pernet_subsys(&tipc_net_ops); |
| 122 | if (err) | 128 | if (err) |
| 123 | goto out_subscr; | 129 | goto out_pernet; |
| 124 | 130 | ||
| 125 | err = tipc_bearer_setup(); | 131 | err = tipc_bearer_setup(); |
| 126 | if (err) | 132 | if (err) |
| 127 | goto out_bearer; | 133 | goto out_bearer; |
| 128 | 134 | ||
| 135 | pr_info("Started in single node mode\n"); | ||
| 129 | return 0; | 136 | return 0; |
| 130 | out_bearer: | 137 | out_bearer: |
| 131 | tipc_subscr_stop(); | 138 | unregister_pernet_subsys(&tipc_net_ops); |
| 132 | out_subscr: | 139 | out_pernet: |
| 133 | tipc_unregister_sysctl(); | 140 | tipc_unregister_sysctl(); |
| 134 | out_sysctl: | 141 | out_sysctl: |
| 135 | tipc_socket_stop(); | 142 | tipc_socket_stop(); |
| 136 | out_socket: | 143 | out_socket: |
| 144 | tipc_netlink_compat_stop(); | ||
| 145 | out_netlink_compat: | ||
| 137 | tipc_netlink_stop(); | 146 | tipc_netlink_stop(); |
| 138 | out_netlink: | 147 | out_netlink: |
| 139 | tipc_nametbl_stop(); | 148 | pr_err("Unable to start in single node mode\n"); |
| 140 | out_nametbl: | ||
| 141 | tipc_sk_ref_table_stop(); | ||
| 142 | out_reftbl: | ||
| 143 | return err; | 149 | return err; |
| 144 | } | 150 | } |
| 145 | 151 | ||
| 146 | static int __init tipc_init(void) | ||
| 147 | { | ||
| 148 | int res; | ||
| 149 | |||
| 150 | pr_info("Activated (version " TIPC_MOD_VER ")\n"); | ||
| 151 | |||
| 152 | tipc_own_addr = 0; | ||
| 153 | tipc_max_ports = CONFIG_TIPC_PORTS; | ||
| 154 | tipc_net_id = 4711; | ||
| 155 | |||
| 156 | sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 << | ||
| 157 | TIPC_LOW_IMPORTANCE; | ||
| 158 | sysctl_tipc_rmem[1] = TIPC_CONN_OVERLOAD_LIMIT >> 4 << | ||
| 159 | TIPC_CRITICAL_IMPORTANCE; | ||
| 160 | sysctl_tipc_rmem[2] = TIPC_CONN_OVERLOAD_LIMIT; | ||
| 161 | |||
| 162 | res = tipc_core_start(); | ||
| 163 | if (res) | ||
| 164 | pr_err("Unable to start in single node mode\n"); | ||
| 165 | else | ||
| 166 | pr_info("Started in single node mode\n"); | ||
| 167 | return res; | ||
| 168 | } | ||
| 169 | |||
| 170 | static void __exit tipc_exit(void) | 152 | static void __exit tipc_exit(void) |
| 171 | { | 153 | { |
| 172 | tipc_core_stop(); | 154 | tipc_bearer_cleanup(); |
| 155 | tipc_netlink_stop(); | ||
| 156 | tipc_netlink_compat_stop(); | ||
| 157 | tipc_socket_stop(); | ||
| 158 | tipc_unregister_sysctl(); | ||
| 159 | unregister_pernet_subsys(&tipc_net_ops); | ||
| 160 | |||
| 173 | pr_info("Deactivated\n"); | 161 | pr_info("Deactivated\n"); |
| 174 | } | 162 | } |
| 175 | 163 | ||
