linux/net/tipc/net.c
<<
v2 /spa3.1 /form.1 a v2 href="../linux+v3.7.2/net/tipc/net.c"> v2 img src="../.static/gfx/right.png" alt=">>"> /spa3.1 spa3 class="lxr_search"> v2 v2 input typ.13hidden" nam.13navtarget" 6.33.13"> v2 input typ.13text" nam.13search" id13search"> v2 buttv2.typ.13submit">Search v2 Prefs1 /a> /spa3.1v2 /div.1v2 form ac6.33="ajax+*" method="post" onsubmit="return false;"> input typ.13hidden" nam.13ajax_lookup" id13ajax_lookup" 6.33.13"> v2 /form.1 v2 div class="headingbottvm">1 div id13file_contents".
   1 /a> spa3 class="comment">/* /spa3.1   2 /a> spa3 class="comment"> * net/tipc/net.c: TIPC network routing code /spa3.1   3 /a> spa3 class="comment"> * /spa3.1   4 /a> spa3 class="comment"> * Copyright (c) 1995-2006, Ericssv2.AB /spa3.1   5 /a> spa3 class="comment"> * Copyright (c) 2005, 2010-2011, Wind River Systems /spa3.1   6 /a> spa3 class="comment"> * All rights reserved. /spa3.1   7 /a> spa3 class="comment"> * /spa3.1   8 /a> spa3 class="comment"> * Redistribut v2.and use in source.and binary forms, with or without /spa3.1   9 /a> spa3 class="comment"> * modificat v2, are permitted provided that the following condit v2s are met: /spa3.1   spa3 class="comment"> * /spa3.1  11 /a> spa3 class="comment"> * 1. Redistribut v2s of source.code must retain the above.copyright /spa3.1  12 /a> spa3 class="comment"> *    notice, this list of condit v2s and the following disclaimer. /spa3.1  13 /a> spa3 class="comment"> * 2. Redistribut v2s in binary form must reproduce.the above.copyright /spa3.1  14 /a> spa3 class="comment"> *    notice, this list of condit v2s and the following disclaimer in the /spa3.1  15 /a> spa3 class="comment"> *    documentat v2.and/or other materials provided with the distribut v2. /spa3.1  16 /a> spa3 class="comment"> * 3. Neither the nam.s of the copyright holders nor the nam.s of its /spa3.1  17 /a> spa3 class="comment"> *    contributors may be used to endorse or promote products derived from /spa3.1  18 /a> spa3 class="comment"> *    this software without specific prior written permiss v2. /spa3.1  19 /a> spa3 class="comment"> * /spa3.1  2opta> spa3 class="comment"> * Alternat vely, this software may be distributed under the terms of the /spa3.1  21 /a> spa3 class="comment"> * GNU General Public License ("GPL") vers v2 2 as published by the Free /spa3.1  22 /a> spa3 class="comment"> * Software Foundat v2. /spa3.1  23 /a> spa3 class="comment"> * /spa3.1  24 /a> spa3 class="comment"> * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" /spa3.1  25 /a> spa3 class="comment"> * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE /spa3.1  26 /a> spa3 class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE /spa3.1  27 /a> spa3 class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE /spa3.1  28 /a> spa3 class="comment"> * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR /spa3.1  29 /a> spa3 class="comment"> * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF /spa3.1  3opta> spa3 class="comment"> * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS /spa3.1  31 /a> spa3 class="comment"> * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN /spa3.1  32 /a> spa3 class="comment"> * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) /spa3.1  33 /a> spa3 class="comment"> * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE /spa3.1  34 /a> spa3 class="comment"> * POSSIBILITY OF SUCH DAMAGE. /spa3.1  35 /a> spa3 class="comment"> */ /spa3.1  36 /a>1  37 /a>#include " a href="net/tipc/core.h" class="fref">core.h /a>"1  38 /a>#include " a href="net/tipc/net.h" class="fref">net.h /a>"1  39 /a>#include " a href="net/tipc/nam._distr.h" class="fref">nam._distr.h /a>"1  40 /a>#include " a href="net/tipc/subscr.h" class="fref">subscr.h /a>"1  41 /a>#include " a href="net/tipc/port.h" class="fref">port.h /a>"1  42 /a>#include " a href="net/tipc/node.h" class="fref">node.h /a>"1  43 /a>#include " a href="net/tipc/config.h" class="fref">config.h /a>"1  44 /a>1  45 /a> spa3 class="comment">/* /spa3.1  46 /a> spa3 class="comment"> * The TIPC locking policy is designed to ensure a very fine locking /spa3.1  47 /a> spa3 class="comment"> * granularity, permitting complete parallel access to individual /spa3.1  48 /a> spa3 class="comment"> * port and node/link instances. The code consists of three major /spa3.1  49 /a> spa3 class="comment"> * locking domains, each protected with their own disjunct set of locks. /spa3.1  5opta> spa3 class="comment"> * /spa3.1  51 /a> spa3 class="comment"> * 1: The routing hierarchy. /spa3.1  52 /a> spa3 class="comment"> *    Comprises the structures 'zone', 'cluster', 'node', 'link' /spa3.1  53 /a> spa3 class="comment"> *    and 'bearer'. The whole hierarchy is protected by a big /spa3.1  54 /a> spa3 class="comment"> *    read/write lock, tipc_net_lock, to enssure that nothing is added /spa3.1  55 /a> spa3 class="comment"> *    or removed while code is accessing any of these structures. /spa3.1  56 /a> spa3 class="comment"> *    This layer must not be called from the two others while they /spa3.1  57 /a> spa3 class="comment"> *    hold any of their own locks. /spa3.1  58 /a> spa3 class="comment"> *    Neither must it itself do any upcalls to the other two before /spa3.1  59 /a> spa3 class="comment"> *    it has released tipc_net_lock and other protective locks. /spa3.1  6opta> spa3 class="comment"> * /spa3.1  61 /a> spa3 class="comment"> *   Within the tipc_net_lock domain there are two sub-domains;'node' and /spa3.1  62 /a> spa3 class="comment"> *   'bearer', where local write operat v2s are permitted, /spa3.1  63 /a> spa3 class="comment"> *   provided that those are protected by individual spin_locks /spa3.1  64 /a> spa3 class="comment"> *   per instance. Code holding tipc_net_lock(read) and a node spin_lock /spa3.1  65 /a> spa3 class="comment"> *   is permitted to poke around in both the node itself and its /spa3.1  66 /a> spa3 class="comment"> *   subordinate links. I.e, it ca3 update link counters and queues, /spa3.1  67 /a> spa3 class="comment"> *   change link state, send protocol messages, and alter the /spa3.1  68 /a> spa3 class="comment"> *   "active_links" array in the node; but it ca3 _not_ remove a link /spa3.1  69 /a> spa3 class="comment"> *   or a node from the overall structure. /spa3.1  7opta> spa3 class="comment"> *   Correspondingly, individual bearers may change status within a /spa3.1  71 /a> spa3 class="comment"> *   tipc_net_lock(read), protected by an individual spin_lock ber bearer /spa3.1  72 /a> spa3 class="comment"> *   instance, but it needs tipc_net_lock(write) to remove/add any bearers. /spa3.1  73 /a> spa3 class="comment"> * /spa3.1  74 /a> spa3 class="comment"> * /spa3.1  75 /a> spa3 class="comment"> *  2: The transport level of the protocol. /spa3.1  76 /a> spa3 class="comment"> *     This consists of the structures port, (and its user level /spa3.1  77 /a> spa3 class="comment"> *     representat v2s, such as user_port and tipc_sock), reference.and /spa3.1  78 /a> spa3 class="comment"> *     tipc_user (port.c, reg.c, socket.c). /spa3.1  79 /a> spa3 class="comment"> * /spa3.1  8opta> spa3 class="comment"> *     This layer has four different locks: /spa3.1  81 /a> spa3 class="comment"> *     - The tipc_port spin_lock. This is protecting each port instance /spa3.1  82 /a> spa3 class="comment"> *       from parallel data access and removal. Since.we ca3 not place /spa3.1  83 /a> spa3 class="comment"> *       this lock in the port itself, it has been placed in the /spa3.1  84 /a> spa3 class="comment"> *       corresponding reference.table entry, which has the sam. life /spa3.1  85 /a> spa3 class="comment"> *       cycle as the module. This entry is difficult to access from /spa3.1  86 /a> spa3 class="comment"> *       outside the TIPC core, however, so a pointer to the lock has /spa3.1  87 /a> spa3 class="comment"> *       been added in the port instance, -to be used for unlocking /spa3.1  88 /a> spa3 class="comment"> *       only. /spa3.1  89 /a> spa3 class="comment"> *     - A read/write lock to protect the reference.table itself (teg.c). /spa3.1  9opta> spa3 class="comment"> *       (Nobody is using read-only access to this, so it ca3 just as /spa3.1  91 /a> spa3 class="comment"> *      .well be changed to a spin_lock) /spa3.1  92 /a> spa3 class="comment"> *     - A spin lock to protect the registry of kernel/driver users (reg.c) /spa3.1  93 /a> spa3 class="comment"> *     - A global spin_lock (tipc_port_lock), which only task is to ensure /spa3.1  94 /a> spa3 class="comment"> *       consistency where more than one port is involved in an operat v2, /spa3.1  95 /a> spa3 class="comment"> *       i.e., whe a port is part of a linked list of ports. /spa3.1  96 /a> spa3 class="comment"> *       There are two such lists; 'port_list', which is used for management, /spa3.1  97 /a> spa3 class="comment"> *       and 'wait_list', which is used to queue ports during congest v2. /spa3.1  98 /a> spa3 class="comment"> * /spa3.1  99 /a> spa3 class="comment"> *  3: The nam..table (nam._table.c, nam._distr.c, subscri.6.33.c) /spa3.1 100 /a> spa3 class="comment"> *     - There is one big read/write-lock (tipc_nam.tbl_lock) protecting the /spa3.1 101 /a> spa3 class="comment"> *      .overall nam..table structure. Nothing must be added/removed to /spa3.1 102 /a> spa3 class="comment"> *       this structure without holding write access to it. /spa3.1 103 /a> spa3 class="comment"> *     - There is one local spin_lock per sub_sequence, which ca3 be seen /spa3.1 104 /a> spa3 class="comment"> *       as a sub-domain to the tipc_nam.tbl_lock domain. It is used only /spa3.1 105 /a> spa3 class="comment"> *       for translat v2.operat v2s, and is needed because a translat v2 /spa3.1 106 /a> spa3 class="comment"> *       steps the root of the 'publicat v2' linked list between each lookup. /spa3.1 107 /a> spa3 class="comment"> *       This is always used within the scope of a tipc_nam.tbl_lock(read). /spa3.1 108 /a> spa3 class="comment"> *     - A local spin_lock protecting the queue of subscriber events. /spa3.1 109 /a> spa3 class="comment">*/ /spa3.1 11 111 /a> a href="+code=DEFINE_RWLOCK" class="sref">DEFINE_RWLOCK /a>( a href="+code=tipc_net_lock" class="sref">tipc_net_lock /a>);1 112 /a>1 113 /a>static void  a href="+code=net_route_nam.d_msg" class="sref">net_route_nam.d_msg /a>(struct  a href="+code=sk_buff" class="sref">sk_buff /a> * a href="+code=buf" class="sref">buf /a>)1 114 /a>{1 115 /a>        struct  a href="+code=tipc_msg" class="sref">tipc_msg /a> * a href="+code=msg" class="sref">msg /a> =  a href="+code=buf_msg" class="sref">buf_msg /a>( a href="+code=buf" class="sref">buf /a>);1 116 /a>         a href="+code=u32" class="sref">u32 /a>  a href="+code=dnode" class="sref">dnode /a>;1 117 /a>         a href="+code=u32" class="sref">u32 /a>  a href="+code=dport" class="sref">dport /a>;1 118 /a>1 119 /a>        if (! a href="+code=msg_nam.d" class="sref">msg_nam.d /a>( a href="+code=msg" class="sref">msg /a>)) {1 12opta>                 a href="+code=kfree_skb" class="sref">kfree_skb /a>( a href="+code=buf" class="sref">buf /a>);1 121 /a>                return;1 122 /a>        }1 123 /a>1 124 /a>         a href="+code=dnode" class="sref">dnode /a> =  a href="+code=addr_domain" class="sref">addr_domain /a>( a href="+code=msg_lookup_scope" class="sref">msg_lookup_scope /a>( a href="+code=msg" class="sref">msg /a>));1 125 /a>         a href="+code=dport" class="sref">dport /a> =  a href="+code=tipc_nam.tbl_translate" class="sref">tipc_nam.tbl_translate /a>( a href="+code=msg_nam.type" class="sref">msg_nam.type /a>( a href="+code=msg" class="sref">msg /a>),  a href="+code=msg_nam.inst" class="sref">msg_nam.inst /a>( a href="+code=msg" class="sref">msg /a>), & a href="+code=dnode" class="sref">dnode /a>);1 126 /a>        if ( a href="+code=dport" class="sref">dport /a>) {1 127pta>                 a href="+code=msg_set_destnode" class="sref">msg_set_destnode /a>( a href="+code=msg" class="sref">msg /a>,  a href="+code=dnode" class="sref">dnode /a>);1 128 /a>                 a href="+code=msg_set_destport" class="sref">msg_set_destport /a>( a href="+code=msg" class="sref">msg /a>,  a href="+code=dport" class="sref">dport /a>);1 129 /a>                 a href="+code=tipc_net_route_msg" class="sref">tipc_net_route_msg /a>( a href="+code=buf" class="sref">buf /a>);1 13opta>                return;1 131 /a>        }1 132 /a>         a href="+code=tipc_reject_msg" class="sref">tipc_reject_msg /a>( a href="+code=buf" class="sref">buf /a>,  a href="+code=TIPC_ERR_NO_NAME" class="sref">TIPC_ERR_NO_NAME /a>);1 133 /a>}1 134 /a>1 135 /a>void  a href="+code=tipc_net_route_msg" class="sref">tipc_net_route_msg /a>(struct  a href="+code=sk_buff" class="sref">sk_buff /a> * a href="+code=buf" class="sref">buf /a>)1 136 /a>{1 137pta>        struct  a href="+code=tipc_msg" class="sref">tipc_msg /a> * a href="+code=msg" class="sref">msg /a>;1 138 /a>         a href="+code=u32" class="sref">u32 /a>  a href="+code=dnode" class="sref">dnode /a>;1 139 /a>1 14opta>        if (! a href="+code=buf" class="sref">buf /a>)1 141 /a>                return;1 142 /a>         a href="+code=msg" class="sref">msg /a> =  a href="+code=buf_msg" class="sref">buf_msg /a>( a href="+code=buf" class="sref">buf /a>);1 143 /a>1 144 /a>         spa3 class="comment">/* Handle message for this node */ /spa3.1 145 /a>         a href="+code=dnode" class="sref">dnode /a> =  a href="+code=msg_short" class="sref">msg_short /a>( a href="+code=msg" class="sref">msg /a>) ?  a href="+code=tipc_own_addr" class="sref">tipc_own_addr /a> :  a href="+code=msg_destnode" class="sref">msg_destnode /a>( a href="+code=msg" class="sref">msg /a>);1 146 /a>        if ( a href="+code=tipc_in_scope" class="sref">tipc_in_scope /a>( a href="+code=dnode" class="sref">dnode /a>,  a href="+code=tipc_own_addr" class="sref">tipc_own_addr /a>)) {1 147pta>                if ( a href="+code=msg_isdata" class="sref">msg_isdata /a>( a href="+code=msg" class="sref">msg /a>)) {1 148 /a>                        if ( a href="+code=msg_mcast" class="sref">msg_mcast /a>( a href="+code=msg" class="sref">msg /a>))1 149 /a>                                 a href="+code=tipc_port_recv_mcast" class="sref">tipc_port_recv_mcast /a>( a href="+code=buf" class="sref">buf /a>,  a href="+code=NULL" class="sref">NULL /a>);1 15opta>                        else if ( a href="+code=msg_destport" class="sref">msg_destport /a>( a href="+code=msg" class="sref">msg /a>))1 151 /a>                                 a href="+code=tipc_port_recv_msg" class="sref">tipc_port_recv_msg /a>( a href="+code=buf" class="sref">buf /a>);1 152pta>                        else1 153 /a>                                 a href="+code=net_route_nam.d_msg" class="sref">net_route_nam.d_msg /a>( a href="+code=buf" class="sref">buf /a>);1 154 /a>                        return;1 155 /a>                }1 156 /a>                switch ( a href="+code=msg_user" class="sref">msg_user /a>( a href="+code=msg" class="sref">msg /a>)) {1 157pta>                case  a href="+code=NAME_DISTRIBUTOR" class="sref">NAME_DISTRIBUTORpta>:1 158 /a>                         a href="+code=tipc_nam.d_recv" class="sref">tipc_nam.d_recv /a>( a href="+code=buf" class="sref">buf /a>);1 159 /a>                        break;1 16opta>                case  a href="+code=CONN_MANAGER" class="sref">CONN_MANAGERpta>:1 161 /a>                         a href="+code=tipc_port_recv_proto_msg" class="sref">tipc_port_recv_proto_msg /a>( a href="+code=buf" class="sref">buf /a>);1 162pta>                        break;1 163 /a>                default:1 164 /a>                         a href="+code=kfree_skb" class="sref">kfree_skb /a>( a href="+code=buf" class="sref">buf /a>);1 165 /a>                }1 166 /a>                return;1 167pta>        }1 168 /a>1 169 /a>         spa3 class="comment">/* Handle message for another node */ /spa3.1 17opta>         a href="+code=skb_trim" class="sref">skb_trim /a>( a href="+code=buf" class="sref">buf /a>,  a href="+code=msg_size" class="sref">msg_size /a>( a href="+code=msg" class="sref">msg /a>));1 171pta>         a href="+code=tipc_link_send" class="sref">tipc_link_send /a>( a href="+code=buf" class="sref">buf /a>,  a href="+code=dnode" class="sref">dnode /a>,  a href="+code=msg_link_selector" class="sref">msg_link_selector /a>( a href="+code=msg" class="sref">msg /a>));1 172 /a>}1 173 /a>1 174 /a>void  a href="+code=tipc_net_start" class="sref">tipc_net_start /a>( a href="+code=u32" class="sref">u32 /a>  a href="+code=addr" class="sref">addr /a>)1 175 /a>{1 176 /a>        char  a href="+code=addr_string" class="sref">addr_string /a>[16];1 177 /a>1 178 /a>         a href="+code=write_lock_bh" class="sref">write_lock_bh /a>(& a href="+code=tipc_net_lock" class="sref">tipc_net_lock /a>);1 179pta>         a href="+code=tipc_own_addr" class="sref">tipc_own_addr /a> =  a href="+code=addr" class="sref">addr /a>;1 18opta>         a href="+code=tipc_nam.d_reinit" class="sref">tipc_nam.d_reinit /a>();1 181pta>         a href="+code=tipc_port_reinit" class="sref">tipc_port_reinit /a>();1 182 /a>         a href="+code=tipc_bclink_init" class="sref">tipc_bclink_init /a>();1 183 /a>         a href="+code=write_unlock_bh" class="sref">write_unlock_bh /a>(& a href="+code=tipc_net_lock" class="sref">tipc_net_lock /a>);1 184 /a>1 185 /a>         a href="+code=tipc_cfg_reinit" class="sref">tipc_cfg_reinit /a>();1 186 /a>1 187 /a>         a href="+code=pr_info" class="sref">pr_info /a>( spa3 class="string">"Started in network mode\n" /spa3.);1 188 /a>         a href="+code=pr_info" class="sref">pr_info /a>( spa3 class="string">"Own node address %s, network identity %u\n" /spa3.,1 189 /a>                 a href="+code=tipc_addr_string_fill" class="sref">tipc_addr_string_fill /a>( a href="+code=addr_string" class="sref">addr_string /a>,  a href="+code=tipc_own_addr" class="sref">tipc_own_addr /a>),  a href="+code=tipc_net_id" class="sref">tipc_net_id /a>);1 19opta>}1 191 /a>1 192 /a>void  a href="+code=tipc_net_stop" class="sref">tipc_net_stop /a>(void)1 193 /a>{1 194 /a>        struct  a href="+code=tipc_node" class="sref">tipc_node /a> * a href="+code=node" class="sref">node /a>, * a href="+code=t_node" class="sref">t_node /a>;1 195 /a>1 196 /a>        if (! a href="+code=tipc_own_addr" class="sref">tipc_own_addr /a>)1 197pta>                return;1 198 /a>         a href="+code=write_lock_bh" class="sref">write_lock_bh /a>(& a href="+code=tipc_net_lock" class="sref">tipc_net_lock /a>);1 199pta>         a href="+code=tipc_bearer_stop" class="sref">tipc_bearer_stop /a>();1 20opta>         a href="+code=tipc_bclink_stop" class="sref">tipc_bclink_stop /a>();1 201pta>         a href="+code=list_for_each_entry_safe" class="sref">list_for_each_entry_safe /a>( a href="+code=node" class="sref">node /a>,  a href="+code=t_node" class="sref">t_node /a>, & a href="+code=tipc_node_list" class="sref">tipc_node_list /a>,  a href="+code=list" class="sref">list /a>)1 202pta>                 a href="+code=tipc_node_delete" class="sref">tipc_node_delete /a>( a href="+code=node" class="sref">node /a>);1 203 /a>         a href="+code=write_unlock_bh" class="sref">write_unlock_bh /a>(& a href="+code=tipc_net_lock" class="sref">tipc_net_lock /a>);1 204 /a>         a href="+code=pr_info" class="sref">pr_info /a>( spa3 class="string">"Left network mode\n" /spa3.);1 205 /a>}1 206 /a> /pre> /div>


 /div>