Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * net/tipc/core.c: TIPC module code
0003  *
0004  * Copyright (c) 2003-2006, 2013, Ericsson AB
0005  * Copyright (c) 2005-2006, 2010-2013, Wind River Systems
0006  * All rights reserved.
0007  *
0008  * Redistribution and use in source and binary forms, with or without
0009  * modification, are permitted provided that the following conditions are met:
0010  *
0011  * 1. Redistributions of source code must retain the above copyright
0012  *    notice, this list of conditions and the following disclaimer.
0013  * 2. Redistributions in binary form must reproduce the above copyright
0014  *    notice, this list of conditions and the following disclaimer in the
0015  *    documentation and/or other materials provided with the distribution.
0016  * 3. Neither the names of the copyright holders nor the names of its
0017  *    contributors may be used to endorse or promote products derived from
0018  *    this software without specific prior written permission.
0019  *
0020  * Alternatively, this software may be distributed under the terms of the
0021  * GNU General Public License ("GPL") version 2 as published by the Free
0022  * Software Foundation.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #include "core.h"
0038 #include "name_table.h"
0039 #include "subscr.h"
0040 #include "bearer.h"
0041 #include "net.h"
0042 #include "socket.h"
0043 #include "bcast.h"
0044 #include "node.h"
0045 #include "crypto.h"
0046 
0047 #include <linux/module.h>
0048 
0049 /* configurable TIPC parameters */
0050 unsigned int tipc_net_id __read_mostly;
0051 int sysctl_tipc_rmem[3] __read_mostly;  /* min/default/max */
0052 
0053 static int __net_init tipc_init_net(struct net *net)
0054 {
0055     struct tipc_net *tn = net_generic(net, tipc_net_id);
0056     int err;
0057 
0058     tn->net_id = 4711;
0059     tn->node_addr = 0;
0060     tn->trial_addr = 0;
0061     tn->addr_trial_end = 0;
0062     tn->capabilities = TIPC_NODE_CAPABILITIES;
0063     INIT_WORK(&tn->work, tipc_net_finalize_work);
0064     memset(tn->node_id, 0, sizeof(tn->node_id));
0065     memset(tn->node_id_string, 0, sizeof(tn->node_id_string));
0066     tn->mon_threshold = TIPC_DEF_MON_THRESHOLD;
0067     get_random_bytes(&tn->random, sizeof(int));
0068     INIT_LIST_HEAD(&tn->node_list);
0069     spin_lock_init(&tn->node_list_lock);
0070 
0071 #ifdef CONFIG_TIPC_CRYPTO
0072     err = tipc_crypto_start(&tn->crypto_tx, net, NULL);
0073     if (err)
0074         goto out_crypto;
0075 #endif
0076     err = tipc_sk_rht_init(net);
0077     if (err)
0078         goto out_sk_rht;
0079 
0080     err = tipc_nametbl_init(net);
0081     if (err)
0082         goto out_nametbl;
0083 
0084     err = tipc_bcast_init(net);
0085     if (err)
0086         goto out_bclink;
0087 
0088     err = tipc_attach_loopback(net);
0089     if (err)
0090         goto out_bclink;
0091 
0092     return 0;
0093 
0094 out_bclink:
0095     tipc_nametbl_stop(net);
0096 out_nametbl:
0097     tipc_sk_rht_destroy(net);
0098 out_sk_rht:
0099 
0100 #ifdef CONFIG_TIPC_CRYPTO
0101     tipc_crypto_stop(&tn->crypto_tx);
0102 out_crypto:
0103 #endif
0104     return err;
0105 }
0106 
0107 static void __net_exit tipc_exit_net(struct net *net)
0108 {
0109     struct tipc_net *tn = tipc_net(net);
0110 
0111     tipc_detach_loopback(net);
0112     tipc_net_stop(net);
0113     /* Make sure the tipc_net_finalize_work() finished */
0114     cancel_work_sync(&tn->work);
0115     tipc_bcast_stop(net);
0116     tipc_nametbl_stop(net);
0117     tipc_sk_rht_destroy(net);
0118 #ifdef CONFIG_TIPC_CRYPTO
0119     tipc_crypto_stop(&tipc_net(net)->crypto_tx);
0120 #endif
0121     while (atomic_read(&tn->wq_count))
0122         cond_resched();
0123 }
0124 
0125 static void __net_exit tipc_pernet_pre_exit(struct net *net)
0126 {
0127     tipc_node_pre_cleanup_net(net);
0128 }
0129 
0130 static struct pernet_operations tipc_pernet_pre_exit_ops = {
0131     .pre_exit = tipc_pernet_pre_exit,
0132 };
0133 
0134 static struct pernet_operations tipc_net_ops = {
0135     .init = tipc_init_net,
0136     .exit = tipc_exit_net,
0137     .id   = &tipc_net_id,
0138     .size = sizeof(struct tipc_net),
0139 };
0140 
0141 static struct pernet_operations tipc_topsrv_net_ops = {
0142     .init = tipc_topsrv_init_net,
0143     .exit = tipc_topsrv_exit_net,
0144 };
0145 
0146 static int __init tipc_init(void)
0147 {
0148     int err;
0149 
0150     pr_info("Activated (version " TIPC_MOD_VER ")\n");
0151 
0152     sysctl_tipc_rmem[0] = RCVBUF_MIN;
0153     sysctl_tipc_rmem[1] = RCVBUF_DEF;
0154     sysctl_tipc_rmem[2] = RCVBUF_MAX;
0155 
0156     err = tipc_register_sysctl();
0157     if (err)
0158         goto out_sysctl;
0159 
0160     err = register_pernet_device(&tipc_net_ops);
0161     if (err)
0162         goto out_pernet;
0163 
0164     err = tipc_socket_init();
0165     if (err)
0166         goto out_socket;
0167 
0168     err = register_pernet_device(&tipc_topsrv_net_ops);
0169     if (err)
0170         goto out_pernet_topsrv;
0171 
0172     err = register_pernet_subsys(&tipc_pernet_pre_exit_ops);
0173     if (err)
0174         goto out_register_pernet_subsys;
0175 
0176     err = tipc_bearer_setup();
0177     if (err)
0178         goto out_bearer;
0179 
0180     err = tipc_netlink_start();
0181     if (err)
0182         goto out_netlink;
0183 
0184     err = tipc_netlink_compat_start();
0185     if (err)
0186         goto out_netlink_compat;
0187 
0188     pr_info("Started in single node mode\n");
0189     return 0;
0190 
0191 out_netlink_compat:
0192     tipc_netlink_stop();
0193 out_netlink:
0194     tipc_bearer_cleanup();
0195 out_bearer:
0196     unregister_pernet_subsys(&tipc_pernet_pre_exit_ops);
0197 out_register_pernet_subsys:
0198     unregister_pernet_device(&tipc_topsrv_net_ops);
0199 out_pernet_topsrv:
0200     tipc_socket_stop();
0201 out_socket:
0202     unregister_pernet_device(&tipc_net_ops);
0203 out_pernet:
0204     tipc_unregister_sysctl();
0205 out_sysctl:
0206     pr_err("Unable to start in single node mode\n");
0207     return err;
0208 }
0209 
0210 static void __exit tipc_exit(void)
0211 {
0212     tipc_netlink_compat_stop();
0213     tipc_netlink_stop();
0214     tipc_bearer_cleanup();
0215     unregister_pernet_subsys(&tipc_pernet_pre_exit_ops);
0216     unregister_pernet_device(&tipc_topsrv_net_ops);
0217     tipc_socket_stop();
0218     unregister_pernet_device(&tipc_net_ops);
0219     tipc_unregister_sysctl();
0220 
0221     pr_info("Deactivated\n");
0222 }
0223 
0224 module_init(tipc_init);
0225 module_exit(tipc_exit);
0226 
0227 MODULE_DESCRIPTION("TIPC: Transparent Inter Process Communication");
0228 MODULE_LICENSE("Dual BSD/GPL");
0229 MODULE_VERSION(TIPC_MOD_VER);