diff options
Diffstat (limited to 'net/tipc')
| -rw-r--r-- | net/tipc/Kconfig | 12 | ||||
| -rw-r--r-- | net/tipc/addr.c | 45 | ||||
| -rw-r--r-- | net/tipc/addr.h | 45 | ||||
| -rw-r--r-- | net/tipc/bcast.c | 372 | ||||
| -rw-r--r-- | net/tipc/bcast.h | 113 | ||||
| -rw-r--r-- | net/tipc/bearer.c | 141 | ||||
| -rw-r--r-- | net/tipc/bearer.h | 46 | ||||
| -rw-r--r-- | net/tipc/config.c | 90 | ||||
| -rw-r--r-- | net/tipc/config.h | 6 | ||||
| -rw-r--r-- | net/tipc/core.c | 144 | ||||
| -rw-r--r-- | net/tipc/core.h | 170 | ||||
| -rw-r--r-- | net/tipc/discover.c | 84 | ||||
| -rw-r--r-- | net/tipc/discover.h | 8 | ||||
| -rw-r--r-- | net/tipc/link.c | 344 | ||||
| -rw-r--r-- | net/tipc/link.h | 36 | ||||
| -rw-r--r-- | net/tipc/msg.c | 71 | ||||
| -rw-r--r-- | net/tipc/msg.h | 60 | ||||
| -rw-r--r-- | net/tipc/name_distr.c | 115 | ||||
| -rw-r--r-- | net/tipc/name_distr.h | 16 | ||||
| -rw-r--r-- | net/tipc/name_table.c | 180 | ||||
| -rw-r--r-- | net/tipc/name_table.h | 33 | ||||
| -rw-r--r-- | net/tipc/net.c | 54 | ||||
| -rw-r--r-- | net/tipc/net.h | 4 | ||||
| -rw-r--r-- | net/tipc/netlink.c | 17 | ||||
| -rw-r--r-- | net/tipc/netlink.h | 3 | ||||
| -rw-r--r-- | net/tipc/node.c | 181 | ||||
| -rw-r--r-- | net/tipc/node.h | 35 | ||||
| -rw-r--r-- | net/tipc/server.c | 6 | ||||
| -rw-r--r-- | net/tipc/server.h | 17 | ||||
| -rw-r--r-- | net/tipc/socket.c | 664 | ||||
| -rw-r--r-- | net/tipc/socket.h | 19 | ||||
| -rw-r--r-- | net/tipc/subscr.c | 131 | ||||
| -rw-r--r-- | net/tipc/subscr.h | 14 |
33 files changed, 1668 insertions, 1608 deletions
diff --git a/net/tipc/Kconfig b/net/tipc/Kconfig index c890848f9d56..91c8a8e031db 100644 --- a/net/tipc/Kconfig +++ b/net/tipc/Kconfig | |||
| @@ -20,18 +20,6 @@ menuconfig TIPC | |||
| 20 | 20 | ||
| 21 | If in doubt, say N. | 21 | If in doubt, say N. |
| 22 | 22 | ||
| 23 | config TIPC_PORTS | ||
| 24 | int "Maximum number of ports in a node" | ||
| 25 | depends on TIPC | ||
| 26 | range 127 65535 | ||
| 27 | default "8191" | ||
| 28 | help | ||
| 29 | Specifies how many ports can be supported by a node. | ||
| 30 | Can range from 127 to 65535 ports; default is 8191. | ||
| 31 | |||
| 32 | Setting this to a smaller value saves some memory, | ||
| 33 | setting it to higher allows for more ports. | ||
| 34 | |||
| 35 | config TIPC_MEDIA_IB | 23 | config TIPC_MEDIA_IB |
| 36 | bool "InfiniBand media type support" | 24 | bool "InfiniBand media type support" |
| 37 | depends on TIPC && INFINIBAND_IPOIB | 25 | depends on TIPC && INFINIBAND_IPOIB |
diff --git a/net/tipc/addr.c b/net/tipc/addr.c index 357b74b26f9e..48fd3b5a73fb 100644 --- a/net/tipc/addr.c +++ b/net/tipc/addr.c | |||
| @@ -34,8 +34,51 @@ | |||
| 34 | * POSSIBILITY OF SUCH DAMAGE. | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #include "core.h" | 37 | #include <linux/kernel.h> |
| 38 | #include "addr.h" | 38 | #include "addr.h" |
| 39 | #include "core.h" | ||
| 40 | |||
| 41 | /** | ||
| 42 | * in_own_cluster - test for cluster inclusion; <0.0.0> always matches | ||
| 43 | */ | ||
| 44 | int in_own_cluster(struct net *net, u32 addr) | ||
| 45 | { | ||
| 46 | return in_own_cluster_exact(net, addr) || !addr; | ||
| 47 | } | ||
| 48 | |||
| 49 | int in_own_cluster_exact(struct net *net, u32 addr) | ||
| 50 | { | ||
| 51 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 52 | |||
| 53 | return !((addr ^ tn->own_addr) >> 12); | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * in_own_node - test for node inclusion; <0.0.0> always matches | ||
| 58 | */ | ||
| 59 | int in_own_node(struct net *net, u32 addr) | ||
| 60 | { | ||
| 61 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 62 | |||
| 63 | return (addr == tn->own_addr) || !addr; | ||
| 64 | } | ||
| 65 | |||
| 66 | /** | ||
| 67 | * addr_domain - convert 2-bit scope value to equivalent message lookup domain | ||
| 68 | * | ||
| 69 | * Needed when address of a named message must be looked up a second time | ||
| 70 | * after a network hop. | ||
| 71 | */ | ||
| 72 | u32 addr_domain(struct net *net, u32 sc) | ||
| 73 | { | ||
| 74 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 75 | |||
| 76 | if (likely(sc == TIPC_NODE_SCOPE)) | ||
| 77 | return tn->own_addr; | ||
| 78 | if (sc == TIPC_CLUSTER_SCOPE) | ||
| 79 | return tipc_cluster_mask(tn->own_addr); | ||
| 80 | return tipc_zone_mask(tn->own_addr); | ||
| 81 | } | ||
| 39 | 82 | ||
| 40 | /** | 83 | /** |
| 41 | * tipc_addr_domain_valid - validates a network domain address | 84 | * tipc_addr_domain_valid - validates a network domain address |
diff --git a/net/tipc/addr.h b/net/tipc/addr.h index a74acf9ee804..c700c2d28e09 100644 --- a/net/tipc/addr.h +++ b/net/tipc/addr.h | |||
| @@ -37,7 +37,10 @@ | |||
| 37 | #ifndef _TIPC_ADDR_H | 37 | #ifndef _TIPC_ADDR_H |
| 38 | #define _TIPC_ADDR_H | 38 | #define _TIPC_ADDR_H |
| 39 | 39 | ||
| 40 | #include "core.h" | 40 | #include <linux/types.h> |
| 41 | #include <linux/tipc.h> | ||
| 42 | #include <net/net_namespace.h> | ||
| 43 | #include <net/netns/generic.h> | ||
| 41 | 44 | ||
| 42 | #define TIPC_ZONE_MASK 0xff000000u | 45 | #define TIPC_ZONE_MASK 0xff000000u |
| 43 | #define TIPC_CLUSTER_MASK 0xfffff000u | 46 | #define TIPC_CLUSTER_MASK 0xfffff000u |
| @@ -52,42 +55,10 @@ static inline u32 tipc_cluster_mask(u32 addr) | |||
| 52 | return addr & TIPC_CLUSTER_MASK; | 55 | return addr & TIPC_CLUSTER_MASK; |
| 53 | } | 56 | } |
| 54 | 57 | ||
| 55 | static inline int in_own_cluster_exact(u32 addr) | 58 | int in_own_cluster(struct net *net, u32 addr); |
| 56 | { | 59 | int in_own_cluster_exact(struct net *net, u32 addr); |
| 57 | return !((addr ^ tipc_own_addr) >> 12); | 60 | int in_own_node(struct net *net, u32 addr); |
| 58 | } | 61 | u32 addr_domain(struct net *net, u32 sc); |
| 59 | |||
| 60 | /** | ||
| 61 | * in_own_node - test for node inclusion; <0.0.0> always matches | ||
| 62 | */ | ||
| 63 | static inline int in_own_node(u32 addr) | ||
| 64 | { | ||
| 65 | return (addr == tipc_own_addr) || !addr; | ||
| 66 | } | ||
| 67 | |||
| 68 | /** | ||
| 69 | * in_own_cluster - test for cluster inclusion; <0.0.0> always matches | ||
| 70 | */ | ||
| 71 | static inline int in_own_cluster(u32 addr) | ||
| 72 | { | ||
| 73 | return in_own_cluster_exact(addr) || !addr; | ||
| 74 | } | ||
| 75 | |||
| 76 | /** | ||
| 77 | * addr_domain - convert 2-bit scope value to equivalent message lookup domain | ||
| 78 | * | ||
| 79 | * Needed when address of a named message must be looked up a second time | ||
| 80 | * after a network hop. | ||
| 81 | */ | ||
| 82 | static inline u32 addr_domain(u32 sc) | ||
| 83 | { | ||
| 84 | if (likely(sc == TIPC_NODE_SCOPE)) | ||
| 85 | return tipc_own_addr; | ||
| 86 | if (sc == TIPC_CLUSTER_SCOPE) | ||
| 87 | return tipc_cluster_mask(tipc_own_addr); | ||
| 88 | return tipc_zone_mask(tipc_own_addr); | ||
| 89 | } | ||
| 90 | |||
| 91 | int tipc_addr_domain_valid(u32); | 62 | int tipc_addr_domain_valid(u32); |
| 92 | int tipc_addr_node_valid(u32 addr); | 63 | int tipc_addr_node_valid(u32 addr); |
| 93 | int tipc_in_scope(u32 domain, u32 addr); | 64 | int tipc_in_scope(u32 domain, u32 addr); |
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c index 96ceefeb9daf..53f8bf059fec 100644 --- a/net/tipc/bcast.c +++ b/net/tipc/bcast.c | |||
| @@ -35,77 +35,14 @@ | |||
| 35 | * POSSIBILITY OF SUCH DAMAGE. | 35 | * POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ | 36 | */ |
| 37 | 37 | ||
| 38 | #include "core.h" | ||
| 39 | #include "link.h" | ||
| 40 | #include "socket.h" | 38 | #include "socket.h" |
| 41 | #include "msg.h" | 39 | #include "msg.h" |
| 42 | #include "bcast.h" | 40 | #include "bcast.h" |
| 43 | #include "name_distr.h" | 41 | #include "name_distr.h" |
| 42 | #include "core.h" | ||
| 44 | 43 | ||
| 45 | #define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */ | 44 | #define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */ |
| 46 | #define BCLINK_WIN_DEFAULT 20 /* bcast link window size (default) */ | 45 | #define BCLINK_WIN_DEFAULT 20 /* bcast link window size (default) */ |
| 47 | #define BCBEARER MAX_BEARERS | ||
| 48 | |||
| 49 | /** | ||
| 50 | * struct tipc_bcbearer_pair - a pair of bearers used by broadcast link | ||
| 51 | * @primary: pointer to primary bearer | ||
| 52 | * @secondary: pointer to secondary bearer | ||
| 53 | * | ||
| 54 | * Bearers must have same priority and same set of reachable destinations | ||
| 55 | * to be paired. | ||
| 56 | */ | ||
| 57 | |||
| 58 | struct tipc_bcbearer_pair { | ||
| 59 | struct tipc_bearer *primary; | ||
| 60 | struct tipc_bearer *secondary; | ||
| 61 | }; | ||
| 62 | |||
| 63 | /** | ||
| 64 | * struct tipc_bcbearer - bearer used by broadcast link | ||
| 65 | * @bearer: (non-standard) broadcast bearer structure | ||
| 66 | * @media: (non-standard) broadcast media structure | ||
| 67 | * @bpairs: array of bearer pairs | ||
| 68 | * @bpairs_temp: temporary array of bearer pairs used by tipc_bcbearer_sort() | ||
| 69 | * @remains: temporary node map used by tipc_bcbearer_send() | ||
| 70 | * @remains_new: temporary node map used tipc_bcbearer_send() | ||
| 71 | * | ||
| 72 | * Note: The fields labelled "temporary" are incorporated into the bearer | ||
| 73 | * to avoid consuming potentially limited stack space through the use of | ||
| 74 | * large local variables within multicast routines. Concurrent access is | ||
| 75 | * prevented through use of the spinlock "bclink_lock". | ||
| 76 | */ | ||
| 77 | struct tipc_bcbearer { | ||
| 78 | struct tipc_bearer bearer; | ||
| 79 | struct tipc_media media; | ||
| 80 | struct tipc_bcbearer_pair bpairs[MAX_BEARERS]; | ||
| 81 | struct tipc_bcbearer_pair bpairs_temp[TIPC_MAX_LINK_PRI + 1]; | ||
| 82 | struct tipc_node_map remains; | ||
| 83 | struct tipc_node_map remains_new; | ||
| 84 | }; | ||
| 85 | |||
| 86 | /** | ||
| 87 | * struct tipc_bclink - link used for broadcast messages | ||
| 88 | * @lock: spinlock governing access to structure | ||
| 89 | * @link: (non-standard) broadcast link structure | ||
| 90 | * @node: (non-standard) node structure representing b'cast link's peer node | ||
| 91 | * @flags: represent bclink states | ||
| 92 | * @bcast_nodes: map of broadcast-capable nodes | ||
| 93 | * @retransmit_to: node that most recently requested a retransmit | ||
| 94 | * | ||
| 95 | * Handles sequence numbering, fragmentation, bundling, etc. | ||
| 96 | */ | ||
| 97 | struct tipc_bclink { | ||
| 98 | spinlock_t lock; | ||
| 99 | struct tipc_link link; | ||
| 100 | struct tipc_node node; | ||
| 101 | unsigned int flags; | ||
| 102 | struct tipc_node_map bcast_nodes; | ||
| 103 | struct tipc_node *retransmit_to; | ||
| 104 | }; | ||
| 105 | |||
| 106 | static struct tipc_bcbearer *bcbearer; | ||
| 107 | static struct tipc_bclink *bclink; | ||
| 108 | static struct tipc_link *bcl; | ||
| 109 | 46 | ||
| 110 | const char tipc_bclink_name[] = "broadcast-link"; | 47 | const char tipc_bclink_name[] = "broadcast-link"; |
| 111 | 48 | ||
| @@ -115,25 +52,28 @@ static void tipc_nmap_diff(struct tipc_node_map *nm_a, | |||
| 115 | static void tipc_nmap_add(struct tipc_node_map *nm_ptr, u32 node); | 52 | static void tipc_nmap_add(struct tipc_node_map *nm_ptr, u32 node); |
| 116 | static void tipc_nmap_remove(struct tipc_node_map *nm_ptr, u32 node); | 53 | static void tipc_nmap_remove(struct tipc_node_map *nm_ptr, u32 node); |
| 117 | 54 | ||
| 118 | static void tipc_bclink_lock(void) | 55 | static void tipc_bclink_lock(struct net *net) |
| 119 | { | 56 | { |
| 120 | spin_lock_bh(&bclink->lock); | 57 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 58 | |||
| 59 | spin_lock_bh(&tn->bclink->lock); | ||
| 121 | } | 60 | } |
| 122 | 61 | ||
| 123 | static void tipc_bclink_unlock(void) | 62 | static void tipc_bclink_unlock(struct net *net) |
| 124 | { | 63 | { |
| 64 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 125 | struct tipc_node *node = NULL; | 65 | struct tipc_node *node = NULL; |
| 126 | 66 | ||
| 127 | if (likely(!bclink->flags)) { | 67 | if (likely(!tn->bclink->flags)) { |
| 128 | spin_unlock_bh(&bclink->lock); | 68 | spin_unlock_bh(&tn->bclink->lock); |
| 129 | return; | 69 | return; |
| 130 | } | 70 | } |
| 131 | 71 | ||
| 132 | if (bclink->flags & TIPC_BCLINK_RESET) { | 72 | if (tn->bclink->flags & TIPC_BCLINK_RESET) { |
| 133 | bclink->flags &= ~TIPC_BCLINK_RESET; | 73 | tn->bclink->flags &= ~TIPC_BCLINK_RESET; |
| 134 | node = tipc_bclink_retransmit_to(); | 74 | node = tipc_bclink_retransmit_to(net); |
| 135 | } | 75 | } |
| 136 | spin_unlock_bh(&bclink->lock); | 76 | spin_unlock_bh(&tn->bclink->lock); |
| 137 | 77 | ||
| 138 | if (node) | 78 | if (node) |
| 139 | tipc_link_reset_all(node); | 79 | tipc_link_reset_all(node); |
| @@ -144,9 +84,11 @@ uint tipc_bclink_get_mtu(void) | |||
| 144 | return MAX_PKT_DEFAULT_MCAST; | 84 | return MAX_PKT_DEFAULT_MCAST; |
| 145 | } | 85 | } |
| 146 | 86 | ||
| 147 | void tipc_bclink_set_flags(unsigned int flags) | 87 | void tipc_bclink_set_flags(struct net *net, unsigned int flags) |
| 148 | { | 88 | { |
| 149 | bclink->flags |= flags; | 89 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 90 | |||
| 91 | tn->bclink->flags |= flags; | ||
| 150 | } | 92 | } |
| 151 | 93 | ||
| 152 | static u32 bcbuf_acks(struct sk_buff *buf) | 94 | static u32 bcbuf_acks(struct sk_buff *buf) |
| @@ -164,31 +106,40 @@ static void bcbuf_decr_acks(struct sk_buff *buf) | |||
| 164 | bcbuf_set_acks(buf, bcbuf_acks(buf) - 1); | 106 | bcbuf_set_acks(buf, bcbuf_acks(buf) - 1); |
| 165 | } | 107 | } |
| 166 | 108 | ||
| 167 | void tipc_bclink_add_node(u32 addr) | 109 | void tipc_bclink_add_node(struct net *net, u32 addr) |
| 168 | { | 110 | { |
| 169 | tipc_bclink_lock(); | 111 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 170 | tipc_nmap_add(&bclink->bcast_nodes, addr); | 112 | |
| 171 | tipc_bclink_unlock(); | 113 | tipc_bclink_lock(net); |
| 114 | tipc_nmap_add(&tn->bclink->bcast_nodes, addr); | ||
| 115 | tipc_bclink_unlock(net); | ||
| 172 | } | 116 | } |
| 173 | 117 | ||
| 174 | void tipc_bclink_remove_node(u32 addr) | 118 | void tipc_bclink_remove_node(struct net *net, u32 addr) |
| 175 | { | 119 | { |
| 176 | tipc_bclink_lock(); | 120 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 177 | tipc_nmap_remove(&bclink->bcast_nodes, addr); | 121 | |
| 178 | tipc_bclink_unlock(); | 122 | tipc_bclink_lock(net); |
| 123 | tipc_nmap_remove(&tn->bclink->bcast_nodes, addr); | ||
| 124 | tipc_bclink_unlock(net); | ||
| 179 | } | 125 | } |
| 180 | 126 | ||
| 181 | static void bclink_set_last_sent(void) | 127 | static void bclink_set_last_sent(struct net *net) |
| 182 | { | 128 | { |
| 129 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 130 | struct tipc_link *bcl = tn->bcl; | ||
| 131 | |||
| 183 | if (bcl->next_out) | 132 | if (bcl->next_out) |
| 184 | bcl->fsm_msg_cnt = mod(buf_seqno(bcl->next_out) - 1); | 133 | bcl->fsm_msg_cnt = mod(buf_seqno(bcl->next_out) - 1); |
| 185 | else | 134 | else |
| 186 | bcl->fsm_msg_cnt = mod(bcl->next_out_no - 1); | 135 | bcl->fsm_msg_cnt = mod(bcl->next_out_no - 1); |
| 187 | } | 136 | } |
| 188 | 137 | ||
| 189 | u32 tipc_bclink_get_last_sent(void) | 138 | u32 tipc_bclink_get_last_sent(struct net *net) |
| 190 | { | 139 | { |
| 191 | return bcl->fsm_msg_cnt; | 140 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 141 | |||
| 142 | return tn->bcl->fsm_msg_cnt; | ||
| 192 | } | 143 | } |
| 193 | 144 | ||
| 194 | static void bclink_update_last_sent(struct tipc_node *node, u32 seqno) | 145 | static void bclink_update_last_sent(struct tipc_node *node, u32 seqno) |
| @@ -203,9 +154,11 @@ static void bclink_update_last_sent(struct tipc_node *node, u32 seqno) | |||
| 203 | * | 154 | * |
| 204 | * Called with bclink_lock locked | 155 | * Called with bclink_lock locked |
| 205 | */ | 156 | */ |
| 206 | struct tipc_node *tipc_bclink_retransmit_to(void) | 157 | struct tipc_node *tipc_bclink_retransmit_to(struct net *net) |
| 207 | { | 158 | { |
| 208 | return bclink->retransmit_to; | 159 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 160 | |||
| 161 | return tn->bclink->retransmit_to; | ||
| 209 | } | 162 | } |
| 210 | 163 | ||
| 211 | /** | 164 | /** |
| @@ -215,15 +168,17 @@ struct tipc_node *tipc_bclink_retransmit_to(void) | |||
| 215 | * | 168 | * |
| 216 | * Called with bclink_lock locked | 169 | * Called with bclink_lock locked |
| 217 | */ | 170 | */ |
| 218 | static void bclink_retransmit_pkt(u32 after, u32 to) | 171 | static void bclink_retransmit_pkt(struct tipc_net *tn, u32 after, u32 to) |
| 219 | { | 172 | { |
| 220 | struct sk_buff *skb; | 173 | struct sk_buff *skb; |
| 174 | struct tipc_link *bcl = tn->bcl; | ||
| 221 | 175 | ||
| 222 | skb_queue_walk(&bcl->outqueue, skb) { | 176 | skb_queue_walk(&bcl->outqueue, skb) { |
| 223 | if (more(buf_seqno(skb), after)) | 177 | if (more(buf_seqno(skb), after)) { |
| 178 | tipc_link_retransmit(bcl, skb, mod(to - after)); | ||
| 224 | break; | 179 | break; |
| 180 | } | ||
| 225 | } | 181 | } |
| 226 | tipc_link_retransmit(bcl, skb, mod(to - after)); | ||
| 227 | } | 182 | } |
| 228 | 183 | ||
| 229 | /** | 184 | /** |
| @@ -231,13 +186,13 @@ static void bclink_retransmit_pkt(u32 after, u32 to) | |||
| 231 | * | 186 | * |
| 232 | * Called with no locks taken | 187 | * Called with no locks taken |
| 233 | */ | 188 | */ |
| 234 | void tipc_bclink_wakeup_users(void) | 189 | void tipc_bclink_wakeup_users(struct net *net) |
| 235 | { | 190 | { |
| 191 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 236 | struct sk_buff *skb; | 192 | struct sk_buff *skb; |
| 237 | 193 | ||
| 238 | while ((skb = skb_dequeue(&bclink->link.waiting_sks))) | 194 | while ((skb = skb_dequeue(&tn->bclink->link.waiting_sks))) |
| 239 | tipc_sk_rcv(skb); | 195 | tipc_sk_rcv(net, skb); |
| 240 | |||
| 241 | } | 196 | } |
| 242 | 197 | ||
| 243 | /** | 198 | /** |
| @@ -252,10 +207,12 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked) | |||
| 252 | struct sk_buff *skb, *tmp; | 207 | struct sk_buff *skb, *tmp; |
| 253 | struct sk_buff *next; | 208 | struct sk_buff *next; |
| 254 | unsigned int released = 0; | 209 | unsigned int released = 0; |
| 210 | struct net *net = n_ptr->net; | ||
| 211 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 255 | 212 | ||
| 256 | tipc_bclink_lock(); | 213 | tipc_bclink_lock(net); |
| 257 | /* Bail out if tx queue is empty (no clean up is required) */ | 214 | /* Bail out if tx queue is empty (no clean up is required) */ |
| 258 | skb = skb_peek(&bcl->outqueue); | 215 | skb = skb_peek(&tn->bcl->outqueue); |
| 259 | if (!skb) | 216 | if (!skb) |
| 260 | goto exit; | 217 | goto exit; |
| 261 | 218 | ||
| @@ -266,43 +223,43 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked) | |||
| 266 | * acknowledge sent messages only (if other nodes still exist) | 223 | * acknowledge sent messages only (if other nodes still exist) |
| 267 | * or both sent and unsent messages (otherwise) | 224 | * or both sent and unsent messages (otherwise) |
| 268 | */ | 225 | */ |
| 269 | if (bclink->bcast_nodes.count) | 226 | if (tn->bclink->bcast_nodes.count) |
| 270 | acked = bcl->fsm_msg_cnt; | 227 | acked = tn->bcl->fsm_msg_cnt; |
| 271 | else | 228 | else |
| 272 | acked = bcl->next_out_no; | 229 | acked = tn->bcl->next_out_no; |
| 273 | } else { | 230 | } else { |
| 274 | /* | 231 | /* |
| 275 | * Bail out if specified sequence number does not correspond | 232 | * Bail out if specified sequence number does not correspond |
| 276 | * to a message that has been sent and not yet acknowledged | 233 | * to a message that has been sent and not yet acknowledged |
| 277 | */ | 234 | */ |
| 278 | if (less(acked, buf_seqno(skb)) || | 235 | if (less(acked, buf_seqno(skb)) || |
| 279 | less(bcl->fsm_msg_cnt, acked) || | 236 | less(tn->bcl->fsm_msg_cnt, acked) || |
| 280 | less_eq(acked, n_ptr->bclink.acked)) | 237 | less_eq(acked, n_ptr->bclink.acked)) |
| 281 | goto exit; | 238 | goto exit; |
| 282 | } | 239 | } |
| 283 | 240 | ||
| 284 | /* Skip over packets that node has previously acknowledged */ | 241 | /* Skip over packets that node has previously acknowledged */ |
| 285 | skb_queue_walk(&bcl->outqueue, skb) { | 242 | skb_queue_walk(&tn->bcl->outqueue, skb) { |
| 286 | if (more(buf_seqno(skb), n_ptr->bclink.acked)) | 243 | if (more(buf_seqno(skb), n_ptr->bclink.acked)) |
| 287 | break; | 244 | break; |
| 288 | } | 245 | } |
| 289 | 246 | ||
| 290 | /* Update packets that node is now acknowledging */ | 247 | /* Update packets that node is now acknowledging */ |
| 291 | skb_queue_walk_from_safe(&bcl->outqueue, skb, tmp) { | 248 | skb_queue_walk_from_safe(&tn->bcl->outqueue, skb, tmp) { |
| 292 | if (more(buf_seqno(skb), acked)) | 249 | if (more(buf_seqno(skb), acked)) |
| 293 | break; | 250 | break; |
| 294 | 251 | ||
| 295 | next = tipc_skb_queue_next(&bcl->outqueue, skb); | 252 | next = tipc_skb_queue_next(&tn->bcl->outqueue, skb); |
| 296 | if (skb != bcl->next_out) { | 253 | if (skb != tn->bcl->next_out) { |
| 297 | bcbuf_decr_acks(skb); | 254 | bcbuf_decr_acks(skb); |
| 298 | } else { | 255 | } else { |
| 299 | bcbuf_set_acks(skb, 0); | 256 | bcbuf_set_acks(skb, 0); |
| 300 | bcl->next_out = next; | 257 | tn->bcl->next_out = next; |
| 301 | bclink_set_last_sent(); | 258 | bclink_set_last_sent(net); |
| 302 | } | 259 | } |
| 303 | 260 | ||
| 304 | if (bcbuf_acks(skb) == 0) { | 261 | if (bcbuf_acks(skb) == 0) { |
| 305 | __skb_unlink(skb, &bcl->outqueue); | 262 | __skb_unlink(skb, &tn->bcl->outqueue); |
| 306 | kfree_skb(skb); | 263 | kfree_skb(skb); |
| 307 | released = 1; | 264 | released = 1; |
| 308 | } | 265 | } |
| @@ -310,15 +267,15 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked) | |||
| 310 | n_ptr->bclink.acked = acked; | 267 | n_ptr->bclink.acked = acked; |
| 311 | 268 | ||
| 312 | /* Try resolving broadcast link congestion, if necessary */ | 269 | /* Try resolving broadcast link congestion, if necessary */ |
| 313 | if (unlikely(bcl->next_out)) { | 270 | if (unlikely(tn->bcl->next_out)) { |
| 314 | tipc_link_push_packets(bcl); | 271 | tipc_link_push_packets(tn->bcl); |
| 315 | bclink_set_last_sent(); | 272 | bclink_set_last_sent(net); |
| 316 | } | 273 | } |
| 317 | if (unlikely(released && !skb_queue_empty(&bcl->waiting_sks))) | 274 | if (unlikely(released && !skb_queue_empty(&tn->bcl->waiting_sks))) |
| 318 | n_ptr->action_flags |= TIPC_WAKEUP_BCAST_USERS; | 275 | n_ptr->action_flags |= TIPC_WAKEUP_BCAST_USERS; |
| 319 | 276 | ||
| 320 | exit: | 277 | exit: |
| 321 | tipc_bclink_unlock(); | 278 | tipc_bclink_unlock(net); |
| 322 | } | 279 | } |
| 323 | 280 | ||
| 324 | /** | 281 | /** |
| @@ -326,9 +283,11 @@ exit: | |||
| 326 | * | 283 | * |
| 327 | * RCU and node lock set | 284 | * RCU and node lock set |
| 328 | */ | 285 | */ |
| 329 | void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent) | 286 | void tipc_bclink_update_link_state(struct net *net, struct tipc_node *n_ptr, |
| 287 | u32 last_sent) | ||
| 330 | { | 288 | { |
| 331 | struct sk_buff *buf; | 289 | struct sk_buff *buf; |
| 290 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 332 | 291 | ||
| 333 | /* Ignore "stale" link state info */ | 292 | /* Ignore "stale" link state info */ |
| 334 | if (less_eq(last_sent, n_ptr->bclink.last_in)) | 293 | if (less_eq(last_sent, n_ptr->bclink.last_in)) |
| @@ -358,18 +317,18 @@ void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent) | |||
| 358 | struct sk_buff *skb = skb_peek(&n_ptr->bclink.deferred_queue); | 317 | struct sk_buff *skb = skb_peek(&n_ptr->bclink.deferred_queue); |
| 359 | u32 to = skb ? buf_seqno(skb) - 1 : n_ptr->bclink.last_sent; | 318 | u32 to = skb ? buf_seqno(skb) - 1 : n_ptr->bclink.last_sent; |
| 360 | 319 | ||
| 361 | tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, | 320 | tipc_msg_init(net, msg, BCAST_PROTOCOL, STATE_MSG, |
| 362 | INT_H_SIZE, n_ptr->addr); | 321 | INT_H_SIZE, n_ptr->addr); |
| 363 | msg_set_non_seq(msg, 1); | 322 | msg_set_non_seq(msg, 1); |
| 364 | msg_set_mc_netid(msg, tipc_net_id); | 323 | msg_set_mc_netid(msg, tn->net_id); |
| 365 | msg_set_bcast_ack(msg, n_ptr->bclink.last_in); | 324 | msg_set_bcast_ack(msg, n_ptr->bclink.last_in); |
| 366 | msg_set_bcgap_after(msg, n_ptr->bclink.last_in); | 325 | msg_set_bcgap_after(msg, n_ptr->bclink.last_in); |
| 367 | msg_set_bcgap_to(msg, to); | 326 | msg_set_bcgap_to(msg, to); |
| 368 | 327 | ||
| 369 | tipc_bclink_lock(); | 328 | tipc_bclink_lock(net); |
| 370 | tipc_bearer_send(MAX_BEARERS, buf, NULL); | 329 | tipc_bearer_send(net, MAX_BEARERS, buf, NULL); |
| 371 | bcl->stats.sent_nacks++; | 330 | tn->bcl->stats.sent_nacks++; |
| 372 | tipc_bclink_unlock(); | 331 | tipc_bclink_unlock(net); |
| 373 | kfree_skb(buf); | 332 | kfree_skb(buf); |
| 374 | 333 | ||
| 375 | n_ptr->bclink.oos_state++; | 334 | n_ptr->bclink.oos_state++; |
| @@ -382,9 +341,9 @@ void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent) | |||
| 382 | * Delay any upcoming NACK by this node if another node has already | 341 | * Delay any upcoming NACK by this node if another node has already |
| 383 | * requested the first message this node is going to ask for. | 342 | * requested the first message this node is going to ask for. |
| 384 | */ | 343 | */ |
| 385 | static void bclink_peek_nack(struct tipc_msg *msg) | 344 | static void bclink_peek_nack(struct net *net, struct tipc_msg *msg) |
| 386 | { | 345 | { |
| 387 | struct tipc_node *n_ptr = tipc_node_find(msg_destnode(msg)); | 346 | struct tipc_node *n_ptr = tipc_node_find(net, msg_destnode(msg)); |
| 388 | 347 | ||
| 389 | if (unlikely(!n_ptr)) | 348 | if (unlikely(!n_ptr)) |
| 390 | return; | 349 | return; |
| @@ -401,12 +360,16 @@ static void bclink_peek_nack(struct tipc_msg *msg) | |||
| 401 | 360 | ||
| 402 | /* tipc_bclink_xmit - broadcast buffer chain to all nodes in cluster | 361 | /* tipc_bclink_xmit - broadcast buffer chain to all nodes in cluster |
| 403 | * and to identified node local sockets | 362 | * and to identified node local sockets |
| 363 | * @net: the applicable net namespace | ||
| 404 | * @list: chain of buffers containing message | 364 | * @list: chain of buffers containing message |
| 405 | * Consumes the buffer chain, except when returning -ELINKCONG | 365 | * Consumes the buffer chain, except when returning -ELINKCONG |
| 406 | * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE | 366 | * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE |
| 407 | */ | 367 | */ |
| 408 | int tipc_bclink_xmit(struct sk_buff_head *list) | 368 | int tipc_bclink_xmit(struct net *net, struct sk_buff_head *list) |
| 409 | { | 369 | { |
| 370 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 371 | struct tipc_link *bcl = tn->bcl; | ||
| 372 | struct tipc_bclink *bclink = tn->bclink; | ||
| 410 | int rc = 0; | 373 | int rc = 0; |
| 411 | int bc = 0; | 374 | int bc = 0; |
| 412 | struct sk_buff *skb; | 375 | struct sk_buff *skb; |
| @@ -420,19 +383,19 @@ int tipc_bclink_xmit(struct sk_buff_head *list) | |||
| 420 | 383 | ||
| 421 | /* Broadcast to all other nodes */ | 384 | /* Broadcast to all other nodes */ |
| 422 | if (likely(bclink)) { | 385 | if (likely(bclink)) { |
| 423 | tipc_bclink_lock(); | 386 | tipc_bclink_lock(net); |
| 424 | if (likely(bclink->bcast_nodes.count)) { | 387 | if (likely(bclink->bcast_nodes.count)) { |
| 425 | rc = __tipc_link_xmit(bcl, list); | 388 | rc = __tipc_link_xmit(net, bcl, list); |
| 426 | if (likely(!rc)) { | 389 | if (likely(!rc)) { |
| 427 | u32 len = skb_queue_len(&bcl->outqueue); | 390 | u32 len = skb_queue_len(&bcl->outqueue); |
| 428 | 391 | ||
| 429 | bclink_set_last_sent(); | 392 | bclink_set_last_sent(net); |
| 430 | bcl->stats.queue_sz_counts++; | 393 | bcl->stats.queue_sz_counts++; |
| 431 | bcl->stats.accu_queue_sz += len; | 394 | bcl->stats.accu_queue_sz += len; |
| 432 | } | 395 | } |
| 433 | bc = 1; | 396 | bc = 1; |
| 434 | } | 397 | } |
| 435 | tipc_bclink_unlock(); | 398 | tipc_bclink_unlock(net); |
| 436 | } | 399 | } |
| 437 | 400 | ||
| 438 | if (unlikely(!bc)) | 401 | if (unlikely(!bc)) |
| @@ -440,7 +403,7 @@ int tipc_bclink_xmit(struct sk_buff_head *list) | |||
| 440 | 403 | ||
| 441 | /* Deliver message clone */ | 404 | /* Deliver message clone */ |
| 442 | if (likely(!rc)) | 405 | if (likely(!rc)) |
| 443 | tipc_sk_mcast_rcv(skb); | 406 | tipc_sk_mcast_rcv(net, skb); |
| 444 | else | 407 | else |
| 445 | kfree_skb(skb); | 408 | kfree_skb(skb); |
| 446 | 409 | ||
| @@ -454,19 +417,21 @@ int tipc_bclink_xmit(struct sk_buff_head *list) | |||
| 454 | */ | 417 | */ |
| 455 | static void bclink_accept_pkt(struct tipc_node *node, u32 seqno) | 418 | static void bclink_accept_pkt(struct tipc_node *node, u32 seqno) |
| 456 | { | 419 | { |
| 420 | struct tipc_net *tn = net_generic(node->net, tipc_net_id); | ||
| 421 | |||
| 457 | bclink_update_last_sent(node, seqno); | 422 | bclink_update_last_sent(node, seqno); |
| 458 | node->bclink.last_in = seqno; | 423 | node->bclink.last_in = seqno; |
| 459 | node->bclink.oos_state = 0; | 424 | node->bclink.oos_state = 0; |
| 460 | bcl->stats.recv_info++; | 425 | tn->bcl->stats.recv_info++; |
| 461 | 426 | ||
| 462 | /* | 427 | /* |
| 463 | * Unicast an ACK periodically, ensuring that | 428 | * Unicast an ACK periodically, ensuring that |
| 464 | * all nodes in the cluster don't ACK at the same time | 429 | * all nodes in the cluster don't ACK at the same time |
| 465 | */ | 430 | */ |
| 466 | if (((seqno - tipc_own_addr) % TIPC_MIN_LINK_WIN) == 0) { | 431 | if (((seqno - tn->own_addr) % TIPC_MIN_LINK_WIN) == 0) { |
| 467 | tipc_link_proto_xmit(node->active_links[node->addr & 1], | 432 | tipc_link_proto_xmit(node->active_links[node->addr & 1], |
| 468 | STATE_MSG, 0, 0, 0, 0, 0); | 433 | STATE_MSG, 0, 0, 0, 0, 0); |
| 469 | bcl->stats.sent_acks++; | 434 | tn->bcl->stats.sent_acks++; |
| 470 | } | 435 | } |
| 471 | } | 436 | } |
| 472 | 437 | ||
| @@ -475,8 +440,10 @@ static void bclink_accept_pkt(struct tipc_node *node, u32 seqno) | |||
| 475 | * | 440 | * |
| 476 | * RCU is locked, no other locks set | 441 | * RCU is locked, no other locks set |
| 477 | */ | 442 | */ |
| 478 | void tipc_bclink_rcv(struct sk_buff *buf) | 443 | void tipc_bclink_rcv(struct net *net, struct sk_buff *buf) |
| 479 | { | 444 | { |
| 445 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 446 | struct tipc_link *bcl = tn->bcl; | ||
| 480 | struct tipc_msg *msg = buf_msg(buf); | 447 | struct tipc_msg *msg = buf_msg(buf); |
| 481 | struct tipc_node *node; | 448 | struct tipc_node *node; |
| 482 | u32 next_in; | 449 | u32 next_in; |
| @@ -484,10 +451,10 @@ void tipc_bclink_rcv(struct sk_buff *buf) | |||
| 484 | int deferred = 0; | 451 | int deferred = 0; |
| 485 | 452 | ||
| 486 | /* Screen out unwanted broadcast messages */ | 453 | /* Screen out unwanted broadcast messages */ |
| 487 | if (msg_mc_netid(msg) != tipc_net_id) | 454 | if (msg_mc_netid(msg) != tn->net_id) |
| 488 | goto exit; | 455 | goto exit; |
| 489 | 456 | ||
| 490 | node = tipc_node_find(msg_prevnode(msg)); | 457 | node = tipc_node_find(net, msg_prevnode(msg)); |
| 491 | if (unlikely(!node)) | 458 | if (unlikely(!node)) |
| 492 | goto exit; | 459 | goto exit; |
| 493 | 460 | ||
| @@ -499,18 +466,18 @@ void tipc_bclink_rcv(struct sk_buff *buf) | |||
| 499 | if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) { | 466 | if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) { |
| 500 | if (msg_type(msg) != STATE_MSG) | 467 | if (msg_type(msg) != STATE_MSG) |
| 501 | goto unlock; | 468 | goto unlock; |
| 502 | if (msg_destnode(msg) == tipc_own_addr) { | 469 | if (msg_destnode(msg) == tn->own_addr) { |
| 503 | tipc_bclink_acknowledge(node, msg_bcast_ack(msg)); | 470 | tipc_bclink_acknowledge(node, msg_bcast_ack(msg)); |
| 504 | tipc_node_unlock(node); | 471 | tipc_node_unlock(node); |
| 505 | tipc_bclink_lock(); | 472 | tipc_bclink_lock(net); |
| 506 | bcl->stats.recv_nacks++; | 473 | bcl->stats.recv_nacks++; |
| 507 | bclink->retransmit_to = node; | 474 | tn->bclink->retransmit_to = node; |
| 508 | bclink_retransmit_pkt(msg_bcgap_after(msg), | 475 | bclink_retransmit_pkt(tn, msg_bcgap_after(msg), |
| 509 | msg_bcgap_to(msg)); | 476 | msg_bcgap_to(msg)); |
| 510 | tipc_bclink_unlock(); | 477 | tipc_bclink_unlock(net); |
| 511 | } else { | 478 | } else { |
| 512 | tipc_node_unlock(node); | 479 | tipc_node_unlock(node); |
| 513 | bclink_peek_nack(msg); | 480 | bclink_peek_nack(net, msg); |
| 514 | } | 481 | } |
| 515 | goto exit; | 482 | goto exit; |
| 516 | } | 483 | } |
| @@ -523,47 +490,47 @@ void tipc_bclink_rcv(struct sk_buff *buf) | |||
| 523 | receive: | 490 | receive: |
| 524 | /* Deliver message to destination */ | 491 | /* Deliver message to destination */ |
| 525 | if (likely(msg_isdata(msg))) { | 492 | if (likely(msg_isdata(msg))) { |
| 526 | tipc_bclink_lock(); | 493 | tipc_bclink_lock(net); |
| 527 | bclink_accept_pkt(node, seqno); | 494 | bclink_accept_pkt(node, seqno); |
| 528 | tipc_bclink_unlock(); | 495 | tipc_bclink_unlock(net); |
| 529 | tipc_node_unlock(node); | 496 | tipc_node_unlock(node); |
| 530 | if (likely(msg_mcast(msg))) | 497 | if (likely(msg_mcast(msg))) |
| 531 | tipc_sk_mcast_rcv(buf); | 498 | tipc_sk_mcast_rcv(net, buf); |
| 532 | else | 499 | else |
| 533 | kfree_skb(buf); | 500 | kfree_skb(buf); |
| 534 | } else if (msg_user(msg) == MSG_BUNDLER) { | 501 | } else if (msg_user(msg) == MSG_BUNDLER) { |
| 535 | tipc_bclink_lock(); | 502 | tipc_bclink_lock(net); |
| 536 | bclink_accept_pkt(node, seqno); | 503 | bclink_accept_pkt(node, seqno); |
| 537 | bcl->stats.recv_bundles++; | 504 | bcl->stats.recv_bundles++; |
| 538 | bcl->stats.recv_bundled += msg_msgcnt(msg); | 505 | bcl->stats.recv_bundled += msg_msgcnt(msg); |
| 539 | tipc_bclink_unlock(); | 506 | tipc_bclink_unlock(net); |
| 540 | tipc_node_unlock(node); | 507 | tipc_node_unlock(node); |
| 541 | tipc_link_bundle_rcv(buf); | 508 | tipc_link_bundle_rcv(net, buf); |
| 542 | } else if (msg_user(msg) == MSG_FRAGMENTER) { | 509 | } else if (msg_user(msg) == MSG_FRAGMENTER) { |
| 543 | tipc_buf_append(&node->bclink.reasm_buf, &buf); | 510 | tipc_buf_append(&node->bclink.reasm_buf, &buf); |
| 544 | if (unlikely(!buf && !node->bclink.reasm_buf)) | 511 | if (unlikely(!buf && !node->bclink.reasm_buf)) |
| 545 | goto unlock; | 512 | goto unlock; |
| 546 | tipc_bclink_lock(); | 513 | tipc_bclink_lock(net); |
| 547 | bclink_accept_pkt(node, seqno); | 514 | bclink_accept_pkt(node, seqno); |
| 548 | bcl->stats.recv_fragments++; | 515 | bcl->stats.recv_fragments++; |
| 549 | if (buf) { | 516 | if (buf) { |
| 550 | bcl->stats.recv_fragmented++; | 517 | bcl->stats.recv_fragmented++; |
| 551 | msg = buf_msg(buf); | 518 | msg = buf_msg(buf); |
| 552 | tipc_bclink_unlock(); | 519 | tipc_bclink_unlock(net); |
| 553 | goto receive; | 520 | goto receive; |
| 554 | } | 521 | } |
| 555 | tipc_bclink_unlock(); | 522 | tipc_bclink_unlock(net); |
| 556 | tipc_node_unlock(node); | 523 | tipc_node_unlock(node); |
| 557 | } else if (msg_user(msg) == NAME_DISTRIBUTOR) { | 524 | } else if (msg_user(msg) == NAME_DISTRIBUTOR) { |
| 558 | tipc_bclink_lock(); | 525 | tipc_bclink_lock(net); |
| 559 | bclink_accept_pkt(node, seqno); | 526 | bclink_accept_pkt(node, seqno); |
| 560 | tipc_bclink_unlock(); | 527 | tipc_bclink_unlock(net); |
| 561 | tipc_node_unlock(node); | 528 | tipc_node_unlock(node); |
| 562 | tipc_named_rcv(buf); | 529 | tipc_named_rcv(net, buf); |
| 563 | } else { | 530 | } else { |
| 564 | tipc_bclink_lock(); | 531 | tipc_bclink_lock(net); |
| 565 | bclink_accept_pkt(node, seqno); | 532 | bclink_accept_pkt(node, seqno); |
| 566 | tipc_bclink_unlock(); | 533 | tipc_bclink_unlock(net); |
| 567 | tipc_node_unlock(node); | 534 | tipc_node_unlock(node); |
| 568 | kfree_skb(buf); | 535 | kfree_skb(buf); |
| 569 | } | 536 | } |
| @@ -601,14 +568,14 @@ receive: | |||
| 601 | buf = NULL; | 568 | buf = NULL; |
| 602 | } | 569 | } |
| 603 | 570 | ||
| 604 | tipc_bclink_lock(); | 571 | tipc_bclink_lock(net); |
| 605 | 572 | ||
| 606 | if (deferred) | 573 | if (deferred) |
| 607 | bcl->stats.deferred_recv++; | 574 | bcl->stats.deferred_recv++; |
| 608 | else | 575 | else |
| 609 | bcl->stats.duplicates++; | 576 | bcl->stats.duplicates++; |
| 610 | 577 | ||
| 611 | tipc_bclink_unlock(); | 578 | tipc_bclink_unlock(net); |
| 612 | 579 | ||
| 613 | unlock: | 580 | unlock: |
| 614 | tipc_node_unlock(node); | 581 | tipc_node_unlock(node); |
| @@ -619,7 +586,7 @@ exit: | |||
| 619 | u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr) | 586 | u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr) |
| 620 | { | 587 | { |
| 621 | return (n_ptr->bclink.recv_permitted && | 588 | return (n_ptr->bclink.recv_permitted && |
| 622 | (tipc_bclink_get_last_sent() != n_ptr->bclink.acked)); | 589 | (tipc_bclink_get_last_sent(n_ptr->net) != n_ptr->bclink.acked)); |
| 623 | } | 590 | } |
| 624 | 591 | ||
| 625 | 592 | ||
| @@ -632,11 +599,15 @@ u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr) | |||
| 632 | * Returns 0 (packet sent successfully) under all circumstances, | 599 | * Returns 0 (packet sent successfully) under all circumstances, |
| 633 | * since the broadcast link's pseudo-bearer never blocks | 600 | * since the broadcast link's pseudo-bearer never blocks |
| 634 | */ | 601 | */ |
| 635 | static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1, | 602 | static int tipc_bcbearer_send(struct net *net, struct sk_buff *buf, |
| 603 | struct tipc_bearer *unused1, | ||
| 636 | struct tipc_media_addr *unused2) | 604 | struct tipc_media_addr *unused2) |
| 637 | { | 605 | { |
| 638 | int bp_index; | 606 | int bp_index; |
| 639 | struct tipc_msg *msg = buf_msg(buf); | 607 | struct tipc_msg *msg = buf_msg(buf); |
| 608 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 609 | struct tipc_bcbearer *bcbearer = tn->bcbearer; | ||
| 610 | struct tipc_bclink *bclink = tn->bclink; | ||
| 640 | 611 | ||
| 641 | /* Prepare broadcast link message for reliable transmission, | 612 | /* Prepare broadcast link message for reliable transmission, |
| 642 | * if first time trying to send it; | 613 | * if first time trying to send it; |
| @@ -646,8 +617,8 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1, | |||
| 646 | if (likely(!msg_non_seq(buf_msg(buf)))) { | 617 | if (likely(!msg_non_seq(buf_msg(buf)))) { |
| 647 | bcbuf_set_acks(buf, bclink->bcast_nodes.count); | 618 | bcbuf_set_acks(buf, bclink->bcast_nodes.count); |
| 648 | msg_set_non_seq(msg, 1); | 619 | msg_set_non_seq(msg, 1); |
| 649 | msg_set_mc_netid(msg, tipc_net_id); | 620 | msg_set_mc_netid(msg, tn->net_id); |
| 650 | bcl->stats.sent_info++; | 621 | tn->bcl->stats.sent_info++; |
| 651 | 622 | ||
| 652 | if (WARN_ON(!bclink->bcast_nodes.count)) { | 623 | if (WARN_ON(!bclink->bcast_nodes.count)) { |
| 653 | dump_stack(); | 624 | dump_stack(); |
| @@ -676,13 +647,14 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1, | |||
| 676 | 647 | ||
| 677 | if (bp_index == 0) { | 648 | if (bp_index == 0) { |
| 678 | /* Use original buffer for first bearer */ | 649 | /* Use original buffer for first bearer */ |
| 679 | tipc_bearer_send(b->identity, buf, &b->bcast_addr); | 650 | tipc_bearer_send(net, b->identity, buf, &b->bcast_addr); |
| 680 | } else { | 651 | } else { |
| 681 | /* Avoid concurrent buffer access */ | 652 | /* Avoid concurrent buffer access */ |
| 682 | tbuf = pskb_copy_for_clone(buf, GFP_ATOMIC); | 653 | tbuf = pskb_copy_for_clone(buf, GFP_ATOMIC); |
| 683 | if (!tbuf) | 654 | if (!tbuf) |
| 684 | break; | 655 | break; |
| 685 | tipc_bearer_send(b->identity, tbuf, &b->bcast_addr); | 656 | tipc_bearer_send(net, b->identity, tbuf, |
| 657 | &b->bcast_addr); | ||
| 686 | kfree_skb(tbuf); /* Bearer keeps a clone */ | 658 | kfree_skb(tbuf); /* Bearer keeps a clone */ |
| 687 | } | 659 | } |
| 688 | if (bcbearer->remains_new.count == 0) | 660 | if (bcbearer->remains_new.count == 0) |
| @@ -697,15 +669,18 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1, | |||
| 697 | /** | 669 | /** |
| 698 | * tipc_bcbearer_sort - create sets of bearer pairs used by broadcast bearer | 670 | * tipc_bcbearer_sort - create sets of bearer pairs used by broadcast bearer |
| 699 | */ | 671 | */ |
| 700 | void tipc_bcbearer_sort(struct tipc_node_map *nm_ptr, u32 node, bool action) | 672 | void tipc_bcbearer_sort(struct net *net, struct tipc_node_map *nm_ptr, |
| 673 | u32 node, bool action) | ||
| 701 | { | 674 | { |
| 675 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 676 | struct tipc_bcbearer *bcbearer = tn->bcbearer; | ||
| 702 | struct tipc_bcbearer_pair *bp_temp = bcbearer->bpairs_temp; | 677 | struct tipc_bcbearer_pair *bp_temp = bcbearer->bpairs_temp; |
| 703 | struct tipc_bcbearer_pair *bp_curr; | 678 | struct tipc_bcbearer_pair *bp_curr; |
| 704 | struct tipc_bearer *b; | 679 | struct tipc_bearer *b; |
| 705 | int b_index; | 680 | int b_index; |
| 706 | int pri; | 681 | int pri; |
| 707 | 682 | ||
| 708 | tipc_bclink_lock(); | 683 | tipc_bclink_lock(net); |
| 709 | 684 | ||
| 710 | if (action) | 685 | if (action) |
| 711 | tipc_nmap_add(nm_ptr, node); | 686 | tipc_nmap_add(nm_ptr, node); |
| @@ -717,7 +692,7 @@ void tipc_bcbearer_sort(struct tipc_node_map *nm_ptr, u32 node, bool action) | |||
| 717 | 692 | ||
| 718 | rcu_read_lock(); | 693 | rcu_read_lock(); |
| 719 | for (b_index = 0; b_index < MAX_BEARERS; b_index++) { | 694 | for (b_index = 0; b_index < MAX_BEARERS; b_index++) { |
| 720 | b = rcu_dereference_rtnl(bearer_list[b_index]); | 695 | b = rcu_dereference_rtnl(tn->bearer_list[b_index]); |
| 721 | if (!b || !b->nodes.count) | 696 | if (!b || !b->nodes.count) |
| 722 | continue; | 697 | continue; |
| 723 | 698 | ||
| @@ -752,7 +727,7 @@ void tipc_bcbearer_sort(struct tipc_node_map *nm_ptr, u32 node, bool action) | |||
| 752 | bp_curr++; | 727 | bp_curr++; |
| 753 | } | 728 | } |
| 754 | 729 | ||
| 755 | tipc_bclink_unlock(); | 730 | tipc_bclink_unlock(net); |
| 756 | } | 731 | } |
| 757 | 732 | ||
| 758 | static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb, | 733 | static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb, |
| @@ -806,17 +781,19 @@ msg_full: | |||
| 806 | return -EMSGSIZE; | 781 | return -EMSGSIZE; |
| 807 | } | 782 | } |
| 808 | 783 | ||
| 809 | int tipc_nl_add_bc_link(struct tipc_nl_msg *msg) | 784 | int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg) |
| 810 | { | 785 | { |
| 811 | int err; | 786 | int err; |
| 812 | void *hdr; | 787 | void *hdr; |
| 813 | struct nlattr *attrs; | 788 | struct nlattr *attrs; |
| 814 | struct nlattr *prop; | 789 | struct nlattr *prop; |
| 790 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 791 | struct tipc_link *bcl = tn->bcl; | ||
| 815 | 792 | ||
| 816 | if (!bcl) | 793 | if (!bcl) |
| 817 | return 0; | 794 | return 0; |
| 818 | 795 | ||
| 819 | tipc_bclink_lock(); | 796 | tipc_bclink_lock(net); |
| 820 | 797 | ||
| 821 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, | 798 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, |
| 822 | NLM_F_MULTI, TIPC_NL_LINK_GET); | 799 | NLM_F_MULTI, TIPC_NL_LINK_GET); |
| @@ -851,7 +828,7 @@ int tipc_nl_add_bc_link(struct tipc_nl_msg *msg) | |||
| 851 | if (err) | 828 | if (err) |
| 852 | goto attr_msg_full; | 829 | goto attr_msg_full; |
| 853 | 830 | ||
| 854 | tipc_bclink_unlock(); | 831 | tipc_bclink_unlock(net); |
| 855 | nla_nest_end(msg->skb, attrs); | 832 | nla_nest_end(msg->skb, attrs); |
| 856 | genlmsg_end(msg->skb, hdr); | 833 | genlmsg_end(msg->skb, hdr); |
| 857 | 834 | ||
| @@ -862,21 +839,23 @@ prop_msg_full: | |||
| 862 | attr_msg_full: | 839 | attr_msg_full: |
| 863 | nla_nest_cancel(msg->skb, attrs); | 840 | nla_nest_cancel(msg->skb, attrs); |
| 864 | msg_full: | 841 | msg_full: |
| 865 | tipc_bclink_unlock(); | 842 | tipc_bclink_unlock(net); |
| 866 | genlmsg_cancel(msg->skb, hdr); | 843 | genlmsg_cancel(msg->skb, hdr); |
| 867 | 844 | ||
| 868 | return -EMSGSIZE; | 845 | return -EMSGSIZE; |
| 869 | } | 846 | } |
| 870 | 847 | ||
| 871 | int tipc_bclink_stats(char *buf, const u32 buf_size) | 848 | int tipc_bclink_stats(struct net *net, char *buf, const u32 buf_size) |
| 872 | { | 849 | { |
| 873 | int ret; | 850 | int ret; |
| 874 | struct tipc_stats *s; | 851 | struct tipc_stats *s; |
| 852 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 853 | struct tipc_link *bcl = tn->bcl; | ||
| 875 | 854 | ||
| 876 | if (!bcl) | 855 | if (!bcl) |
| 877 | return 0; | 856 | return 0; |
| 878 | 857 | ||
| 879 | tipc_bclink_lock(); | 858 | tipc_bclink_lock(net); |
| 880 | 859 | ||
| 881 | s = &bcl->stats; | 860 | s = &bcl->stats; |
| 882 | 861 | ||
| @@ -905,36 +884,47 @@ int tipc_bclink_stats(char *buf, const u32 buf_size) | |||
| 905 | s->queue_sz_counts ? | 884 | s->queue_sz_counts ? |
| 906 | (s->accu_queue_sz / s->queue_sz_counts) : 0); | 885 | (s->accu_queue_sz / s->queue_sz_counts) : 0); |
| 907 | 886 | ||
| 908 | tipc_bclink_unlock(); | 887 | tipc_bclink_unlock(net); |
| 909 | return ret; | 888 | return ret; |
| 910 | } | 889 | } |
| 911 | 890 | ||
| 912 | int tipc_bclink_reset_stats(void) | 891 | int tipc_bclink_reset_stats(struct net *net) |
| 913 | { | 892 | { |
| 893 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 894 | struct tipc_link *bcl = tn->bcl; | ||
| 895 | |||
| 914 | if (!bcl) | 896 | if (!bcl) |
| 915 | return -ENOPROTOOPT; | 897 | return -ENOPROTOOPT; |
| 916 | 898 | ||
| 917 | tipc_bclink_lock(); | 899 | tipc_bclink_lock(net); |
| 918 | memset(&bcl->stats, 0, sizeof(bcl->stats)); | 900 | memset(&bcl->stats, 0, sizeof(bcl->stats)); |
| 919 | tipc_bclink_unlock(); | 901 | tipc_bclink_unlock(net); |
| 920 | return 0; | 902 | return 0; |
| 921 | } | 903 | } |
| 922 | 904 | ||
| 923 | int tipc_bclink_set_queue_limits(u32 limit) | 905 | int tipc_bclink_set_queue_limits(struct net *net, u32 limit) |
| 924 | { | 906 | { |
| 907 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 908 | struct tipc_link *bcl = tn->bcl; | ||
| 909 | |||
| 925 | if (!bcl) | 910 | if (!bcl) |
| 926 | return -ENOPROTOOPT; | 911 | return -ENOPROTOOPT; |
| 927 | if ((limit < TIPC_MIN_LINK_WIN) || (limit > TIPC_MAX_LINK_WIN)) | 912 | if ((limit < TIPC_MIN_LINK_WIN) || (limit > TIPC_MAX_LINK_WIN)) |
| 928 | return -EINVAL; | 913 | return -EINVAL; |
| 929 | 914 | ||
| 930 | tipc_bclink_lock(); | 915 | tipc_bclink_lock(net); |
| 931 | tipc_link_set_queue_limits(bcl, limit); | 916 | tipc_link_set_queue_limits(bcl, limit); |
| 932 | tipc_bclink_unlock(); | 917 | tipc_bclink_unlock(net); |
| 933 | return 0; | 918 | return 0; |
| 934 | } | 919 | } |
| 935 | 920 | ||
| 936 | int tipc_bclink_init(void) | 921 | int tipc_bclink_init(struct net *net) |
| 937 | { | 922 | { |
| 923 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 924 | struct tipc_bcbearer *bcbearer; | ||
| 925 | struct tipc_bclink *bclink; | ||
| 926 | struct tipc_link *bcl; | ||
| 927 | |||
| 938 | bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC); | 928 | bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC); |
| 939 | if (!bcbearer) | 929 | if (!bcbearer) |
| 940 | return -ENOMEM; | 930 | return -ENOMEM; |
| @@ -958,25 +948,31 @@ int tipc_bclink_init(void) | |||
| 958 | spin_lock_init(&bclink->node.lock); | 948 | spin_lock_init(&bclink->node.lock); |
| 959 | __skb_queue_head_init(&bclink->node.waiting_sks); | 949 | __skb_queue_head_init(&bclink->node.waiting_sks); |
| 960 | bcl->owner = &bclink->node; | 950 | bcl->owner = &bclink->node; |
| 951 | bcl->owner->net = net; | ||
| 961 | bcl->max_pkt = MAX_PKT_DEFAULT_MCAST; | 952 | bcl->max_pkt = MAX_PKT_DEFAULT_MCAST; |
| 962 | tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT); | 953 | tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT); |
| 963 | bcl->bearer_id = MAX_BEARERS; | 954 | bcl->bearer_id = MAX_BEARERS; |
| 964 | rcu_assign_pointer(bearer_list[MAX_BEARERS], &bcbearer->bearer); | 955 | rcu_assign_pointer(tn->bearer_list[MAX_BEARERS], &bcbearer->bearer); |
| 965 | bcl->state = WORKING_WORKING; | 956 | bcl->state = WORKING_WORKING; |
| 966 | strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME); | 957 | strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME); |
| 958 | tn->bcbearer = bcbearer; | ||
| 959 | tn->bclink = bclink; | ||
| 960 | tn->bcl = bcl; | ||
| 967 | return 0; | 961 | return 0; |
| 968 | } | 962 | } |
| 969 | 963 | ||
| 970 | void tipc_bclink_stop(void) | 964 | void tipc_bclink_stop(struct net *net) |
| 971 | { | 965 | { |
| 972 | tipc_bclink_lock(); | 966 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 973 | tipc_link_purge_queues(bcl); | 967 | |
| 974 | tipc_bclink_unlock(); | 968 | tipc_bclink_lock(net); |
| 969 | tipc_link_purge_queues(tn->bcl); | ||
| 970 | tipc_bclink_unlock(net); | ||
| 975 | 971 | ||
| 976 | RCU_INIT_POINTER(bearer_list[BCBEARER], NULL); | 972 | RCU_INIT_POINTER(tn->bearer_list[BCBEARER], NULL); |
| 977 | synchronize_net(); | 973 | synchronize_net(); |
| 978 | kfree(bcbearer); | 974 | kfree(tn->bcbearer); |
| 979 | kfree(bclink); | 975 | kfree(tn->bclink); |
| 980 | } | 976 | } |
| 981 | 977 | ||
| 982 | /** | 978 | /** |
diff --git a/net/tipc/bcast.h b/net/tipc/bcast.h index 644d79129fba..a4583a109486 100644 --- a/net/tipc/bcast.h +++ b/net/tipc/bcast.h | |||
| @@ -37,23 +37,13 @@ | |||
| 37 | #ifndef _TIPC_BCAST_H | 37 | #ifndef _TIPC_BCAST_H |
| 38 | #define _TIPC_BCAST_H | 38 | #define _TIPC_BCAST_H |
| 39 | 39 | ||
| 40 | #include "netlink.h" | 40 | #include <linux/tipc_config.h> |
| 41 | #include "link.h" | ||
| 42 | #include "node.h" | ||
| 41 | 43 | ||
| 42 | #define MAX_NODES 4096 | 44 | #define TIPC_BCLINK_RESET 1 |
| 43 | #define WSIZE 32 | 45 | #define PLSIZE 32 |
| 44 | #define TIPC_BCLINK_RESET 1 | 46 | #define BCBEARER MAX_BEARERS |
| 45 | |||
| 46 | /** | ||
| 47 | * struct tipc_node_map - set of node identifiers | ||
| 48 | * @count: # of nodes in set | ||
| 49 | * @map: bitmap of node identifiers that are in the set | ||
| 50 | */ | ||
| 51 | struct tipc_node_map { | ||
| 52 | u32 count; | ||
| 53 | u32 map[MAX_NODES / WSIZE]; | ||
| 54 | }; | ||
| 55 | |||
| 56 | #define PLSIZE 32 | ||
| 57 | 47 | ||
| 58 | /** | 48 | /** |
| 59 | * struct tipc_port_list - set of node local destination ports | 49 | * struct tipc_port_list - set of node local destination ports |
| @@ -67,9 +57,64 @@ struct tipc_port_list { | |||
| 67 | u32 ports[PLSIZE]; | 57 | u32 ports[PLSIZE]; |
| 68 | }; | 58 | }; |
| 69 | 59 | ||
| 60 | /** | ||
| 61 | * struct tipc_bcbearer_pair - a pair of bearers used by broadcast link | ||
| 62 | * @primary: pointer to primary bearer | ||
| 63 | * @secondary: pointer to secondary bearer | ||
| 64 | * | ||
| 65 | * Bearers must have same priority and same set of reachable destinations | ||
| 66 | * to be paired. | ||
| 67 | */ | ||
| 70 | 68 | ||
| 71 | struct tipc_node; | 69 | struct tipc_bcbearer_pair { |
| 70 | struct tipc_bearer *primary; | ||
| 71 | struct tipc_bearer *secondary; | ||
| 72 | }; | ||
| 72 | 73 | ||
| 74 | /** | ||
| 75 | * struct tipc_bcbearer - bearer used by broadcast link | ||
| 76 | * @bearer: (non-standard) broadcast bearer structure | ||
| 77 | * @media: (non-standard) broadcast media structure | ||
| 78 | * @bpairs: array of bearer pairs | ||
| 79 | * @bpairs_temp: temporary array of bearer pairs used by tipc_bcbearer_sort() | ||
| 80 | * @remains: temporary node map used by tipc_bcbearer_send() | ||
| 81 | * @remains_new: temporary node map used tipc_bcbearer_send() | ||
| 82 | * | ||
| 83 | * Note: The fields labelled "temporary" are incorporated into the bearer | ||
| 84 | * to avoid consuming potentially limited stack space through the use of | ||
| 85 | * large local variables within multicast routines. Concurrent access is | ||
| 86 | * prevented through use of the spinlock "bclink_lock". | ||
| 87 | */ | ||
| 88 | struct tipc_bcbearer { | ||
| 89 | struct tipc_bearer bearer; | ||
| 90 | struct tipc_media media; | ||
| 91 | struct tipc_bcbearer_pair bpairs[MAX_BEARERS]; | ||
| 92 | struct tipc_bcbearer_pair bpairs_temp[TIPC_MAX_LINK_PRI + 1]; | ||
| 93 | struct tipc_node_map remains; | ||
| 94 | struct tipc_node_map remains_new; | ||
| 95 | }; | ||
| 96 | |||
| 97 | /** | ||
| 98 | * struct tipc_bclink - link used for broadcast messages | ||
| 99 | * @lock: spinlock governing access to structure | ||
| 100 | * @link: (non-standard) broadcast link structure | ||
| 101 | * @node: (non-standard) node structure representing b'cast link's peer node | ||
| 102 | * @flags: represent bclink states | ||
| 103 | * @bcast_nodes: map of broadcast-capable nodes | ||
| 104 | * @retransmit_to: node that most recently requested a retransmit | ||
| 105 | * | ||
| 106 | * Handles sequence numbering, fragmentation, bundling, etc. | ||
| 107 | */ | ||
| 108 | struct tipc_bclink { | ||
| 109 | spinlock_t lock; | ||
| 110 | struct tipc_link link; | ||
| 111 | struct tipc_node node; | ||
| 112 | unsigned int flags; | ||
| 113 | struct tipc_node_map bcast_nodes; | ||
| 114 | struct tipc_node *retransmit_to; | ||
| 115 | }; | ||
| 116 | |||
| 117 | struct tipc_node; | ||
| 73 | extern const char tipc_bclink_name[]; | 118 | extern const char tipc_bclink_name[]; |
| 74 | 119 | ||
| 75 | /** | 120 | /** |
| @@ -84,24 +129,26 @@ static inline int tipc_nmap_equal(struct tipc_node_map *nm_a, | |||
| 84 | void tipc_port_list_add(struct tipc_port_list *pl_ptr, u32 port); | 129 | void tipc_port_list_add(struct tipc_port_list *pl_ptr, u32 port); |
| 85 | void tipc_port_list_free(struct tipc_port_list *pl_ptr); | 130 | void tipc_port_list_free(struct tipc_port_list *pl_ptr); |
| 86 | 131 | ||
| 87 | int tipc_bclink_init(void); | 132 | int tipc_bclink_init(struct net *net); |
| 88 | void tipc_bclink_stop(void); | 133 | void tipc_bclink_stop(struct net *net); |
| 89 | void tipc_bclink_set_flags(unsigned int flags); | 134 | void tipc_bclink_set_flags(struct net *tn, unsigned int flags); |
| 90 | void tipc_bclink_add_node(u32 addr); | 135 | void tipc_bclink_add_node(struct net *net, u32 addr); |
| 91 | void tipc_bclink_remove_node(u32 addr); | 136 | void tipc_bclink_remove_node(struct net *net, u32 addr); |
| 92 | struct tipc_node *tipc_bclink_retransmit_to(void); | 137 | struct tipc_node *tipc_bclink_retransmit_to(struct net *tn); |
| 93 | void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked); | 138 | void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked); |
| 94 | void tipc_bclink_rcv(struct sk_buff *buf); | 139 | void tipc_bclink_rcv(struct net *net, struct sk_buff *buf); |
| 95 | u32 tipc_bclink_get_last_sent(void); | 140 | u32 tipc_bclink_get_last_sent(struct net *net); |
| 96 | u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr); | 141 | u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr); |
| 97 | void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent); | 142 | void tipc_bclink_update_link_state(struct net *net, struct tipc_node *n_ptr, |
| 98 | int tipc_bclink_stats(char *stats_buf, const u32 buf_size); | 143 | u32 last_sent); |
| 99 | int tipc_bclink_reset_stats(void); | 144 | int tipc_bclink_stats(struct net *net, char *stats_buf, const u32 buf_size); |
| 100 | int tipc_bclink_set_queue_limits(u32 limit); | 145 | int tipc_bclink_reset_stats(struct net *net); |
| 101 | void tipc_bcbearer_sort(struct tipc_node_map *nm_ptr, u32 node, bool action); | 146 | int tipc_bclink_set_queue_limits(struct net *net, u32 limit); |
| 147 | void tipc_bcbearer_sort(struct net *net, struct tipc_node_map *nm_ptr, | ||
| 148 | u32 node, bool action); | ||
| 102 | uint tipc_bclink_get_mtu(void); | 149 | uint tipc_bclink_get_mtu(void); |
| 103 | int tipc_bclink_xmit(struct sk_buff_head *list); | 150 | int tipc_bclink_xmit(struct net *net, struct sk_buff_head *list); |
| 104 | void tipc_bclink_wakeup_users(void); | 151 | void tipc_bclink_wakeup_users(struct net *net); |
| 105 | int tipc_nl_add_bc_link(struct tipc_nl_msg *msg); | 152 | int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg); |
| 106 | 153 | ||
| 107 | #endif | 154 | #endif |
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 463db5b15b8b..33dc3486d16c 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
| @@ -34,11 +34,13 @@ | |||
| 34 | * POSSIBILITY OF SUCH DAMAGE. | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #include <net/sock.h> | ||
| 37 | #include "core.h" | 38 | #include "core.h" |
| 38 | #include "config.h" | 39 | #include "config.h" |
| 39 | #include "bearer.h" | 40 | #include "bearer.h" |
| 40 | #include "link.h" | 41 | #include "link.h" |
| 41 | #include "discover.h" | 42 | #include "discover.h" |
| 43 | #include "bcast.h" | ||
| 42 | 44 | ||
| 43 | #define MAX_ADDR_STR 60 | 45 | #define MAX_ADDR_STR 60 |
| 44 | 46 | ||
| @@ -67,9 +69,8 @@ static const struct nla_policy tipc_nl_media_policy[TIPC_NLA_MEDIA_MAX + 1] = { | |||
| 67 | [TIPC_NLA_MEDIA_PROP] = { .type = NLA_NESTED } | 69 | [TIPC_NLA_MEDIA_PROP] = { .type = NLA_NESTED } |
| 68 | }; | 70 | }; |
| 69 | 71 | ||
| 70 | struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1]; | 72 | static void bearer_disable(struct net *net, struct tipc_bearer *b_ptr, |
| 71 | 73 | bool shutting_down); | |
| 72 | static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down); | ||
| 73 | 74 | ||
| 74 | /** | 75 | /** |
| 75 | * tipc_media_find - locates specified media object by name | 76 | * tipc_media_find - locates specified media object by name |
| @@ -190,13 +191,14 @@ static int bearer_name_validate(const char *name, | |||
| 190 | /** | 191 | /** |
| 191 | * tipc_bearer_find - locates bearer object with matching bearer name | 192 | * tipc_bearer_find - locates bearer object with matching bearer name |
| 192 | */ | 193 | */ |
| 193 | struct tipc_bearer *tipc_bearer_find(const char *name) | 194 | struct tipc_bearer *tipc_bearer_find(struct net *net, const char *name) |
| 194 | { | 195 | { |
| 196 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 195 | struct tipc_bearer *b_ptr; | 197 | struct tipc_bearer *b_ptr; |
| 196 | u32 i; | 198 | u32 i; |
| 197 | 199 | ||
| 198 | for (i = 0; i < MAX_BEARERS; i++) { | 200 | for (i = 0; i < MAX_BEARERS; i++) { |
| 199 | b_ptr = rtnl_dereference(bearer_list[i]); | 201 | b_ptr = rtnl_dereference(tn->bearer_list[i]); |
| 200 | if (b_ptr && (!strcmp(b_ptr->name, name))) | 202 | if (b_ptr && (!strcmp(b_ptr->name, name))) |
| 201 | return b_ptr; | 203 | return b_ptr; |
| 202 | } | 204 | } |
| @@ -206,8 +208,9 @@ struct tipc_bearer *tipc_bearer_find(const char *name) | |||
| 206 | /** | 208 | /** |
| 207 | * tipc_bearer_get_names - record names of bearers in buffer | 209 | * tipc_bearer_get_names - record names of bearers in buffer |
| 208 | */ | 210 | */ |
| 209 | struct sk_buff *tipc_bearer_get_names(void) | 211 | struct sk_buff *tipc_bearer_get_names(struct net *net) |
| 210 | { | 212 | { |
| 213 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 211 | struct sk_buff *buf; | 214 | struct sk_buff *buf; |
| 212 | struct tipc_bearer *b; | 215 | struct tipc_bearer *b; |
| 213 | int i, j; | 216 | int i, j; |
| @@ -218,7 +221,7 @@ struct sk_buff *tipc_bearer_get_names(void) | |||
| 218 | 221 | ||
| 219 | for (i = 0; media_info_array[i] != NULL; i++) { | 222 | for (i = 0; media_info_array[i] != NULL; i++) { |
| 220 | for (j = 0; j < MAX_BEARERS; j++) { | 223 | for (j = 0; j < MAX_BEARERS; j++) { |
| 221 | b = rtnl_dereference(bearer_list[j]); | 224 | b = rtnl_dereference(tn->bearer_list[j]); |
| 222 | if (!b) | 225 | if (!b) |
| 223 | continue; | 226 | continue; |
| 224 | if (b->media == media_info_array[i]) { | 227 | if (b->media == media_info_array[i]) { |
| @@ -231,27 +234,29 @@ struct sk_buff *tipc_bearer_get_names(void) | |||
| 231 | return buf; | 234 | return buf; |
| 232 | } | 235 | } |
| 233 | 236 | ||
| 234 | void tipc_bearer_add_dest(u32 bearer_id, u32 dest) | 237 | void tipc_bearer_add_dest(struct net *net, u32 bearer_id, u32 dest) |
| 235 | { | 238 | { |
| 239 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 236 | struct tipc_bearer *b_ptr; | 240 | struct tipc_bearer *b_ptr; |
| 237 | 241 | ||
| 238 | rcu_read_lock(); | 242 | rcu_read_lock(); |
| 239 | b_ptr = rcu_dereference_rtnl(bearer_list[bearer_id]); | 243 | b_ptr = rcu_dereference_rtnl(tn->bearer_list[bearer_id]); |
| 240 | if (b_ptr) { | 244 | if (b_ptr) { |
| 241 | tipc_bcbearer_sort(&b_ptr->nodes, dest, true); | 245 | tipc_bcbearer_sort(net, &b_ptr->nodes, dest, true); |
| 242 | tipc_disc_add_dest(b_ptr->link_req); | 246 | tipc_disc_add_dest(b_ptr->link_req); |
| 243 | } | 247 | } |
| 244 | rcu_read_unlock(); | 248 | rcu_read_unlock(); |
| 245 | } | 249 | } |
| 246 | 250 | ||
| 247 | void tipc_bearer_remove_dest(u32 bearer_id, u32 dest) | 251 | void tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest) |
| 248 | { | 252 | { |
| 253 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 249 | struct tipc_bearer *b_ptr; | 254 | struct tipc_bearer *b_ptr; |
| 250 | 255 | ||
| 251 | rcu_read_lock(); | 256 | rcu_read_lock(); |
| 252 | b_ptr = rcu_dereference_rtnl(bearer_list[bearer_id]); | 257 | b_ptr = rcu_dereference_rtnl(tn->bearer_list[bearer_id]); |
| 253 | if (b_ptr) { | 258 | if (b_ptr) { |
| 254 | tipc_bcbearer_sort(&b_ptr->nodes, dest, false); | 259 | tipc_bcbearer_sort(net, &b_ptr->nodes, dest, false); |
| 255 | tipc_disc_remove_dest(b_ptr->link_req); | 260 | tipc_disc_remove_dest(b_ptr->link_req); |
| 256 | } | 261 | } |
| 257 | rcu_read_unlock(); | 262 | rcu_read_unlock(); |
| @@ -260,8 +265,10 @@ void tipc_bearer_remove_dest(u32 bearer_id, u32 dest) | |||
| 260 | /** | 265 | /** |
| 261 | * tipc_enable_bearer - enable bearer with the given name | 266 | * tipc_enable_bearer - enable bearer with the given name |
| 262 | */ | 267 | */ |
| 263 | int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority) | 268 | int tipc_enable_bearer(struct net *net, const char *name, u32 disc_domain, |
| 269 | u32 priority) | ||
| 264 | { | 270 | { |
| 271 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 265 | struct tipc_bearer *b_ptr; | 272 | struct tipc_bearer *b_ptr; |
| 266 | struct tipc_media *m_ptr; | 273 | struct tipc_media *m_ptr; |
| 267 | struct tipc_bearer_names b_names; | 274 | struct tipc_bearer_names b_names; |
| @@ -271,7 +278,7 @@ int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority) | |||
| 271 | u32 i; | 278 | u32 i; |
| 272 | int res = -EINVAL; | 279 | int res = -EINVAL; |
| 273 | 280 | ||
| 274 | if (!tipc_own_addr) { | 281 | if (!tn->own_addr) { |
| 275 | pr_warn("Bearer <%s> rejected, not supported in standalone mode\n", | 282 | pr_warn("Bearer <%s> rejected, not supported in standalone mode\n", |
| 276 | name); | 283 | name); |
| 277 | return -ENOPROTOOPT; | 284 | return -ENOPROTOOPT; |
| @@ -281,11 +288,11 @@ int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority) | |||
| 281 | return -EINVAL; | 288 | return -EINVAL; |
| 282 | } | 289 | } |
| 283 | if (tipc_addr_domain_valid(disc_domain) && | 290 | if (tipc_addr_domain_valid(disc_domain) && |
| 284 | (disc_domain != tipc_own_addr)) { | 291 | (disc_domain != tn->own_addr)) { |
| 285 | if (tipc_in_scope(disc_domain, tipc_own_addr)) { | 292 | if (tipc_in_scope(disc_domain, tn->own_addr)) { |
| 286 | disc_domain = tipc_own_addr & TIPC_CLUSTER_MASK; | 293 | disc_domain = tn->own_addr & TIPC_CLUSTER_MASK; |
| 287 | res = 0; /* accept any node in own cluster */ | 294 | res = 0; /* accept any node in own cluster */ |
| 288 | } else if (in_own_cluster_exact(disc_domain)) | 295 | } else if (in_own_cluster_exact(net, disc_domain)) |
| 289 | res = 0; /* accept specified node in own cluster */ | 296 | res = 0; /* accept specified node in own cluster */ |
| 290 | } | 297 | } |
| 291 | if (res) { | 298 | if (res) { |
| @@ -313,7 +320,7 @@ restart: | |||
| 313 | bearer_id = MAX_BEARERS; | 320 | bearer_id = MAX_BEARERS; |
| 314 | with_this_prio = 1; | 321 | with_this_prio = 1; |
| 315 | for (i = MAX_BEARERS; i-- != 0; ) { | 322 | for (i = MAX_BEARERS; i-- != 0; ) { |
| 316 | b_ptr = rtnl_dereference(bearer_list[i]); | 323 | b_ptr = rtnl_dereference(tn->bearer_list[i]); |
| 317 | if (!b_ptr) { | 324 | if (!b_ptr) { |
| 318 | bearer_id = i; | 325 | bearer_id = i; |
| 319 | continue; | 326 | continue; |
| @@ -347,7 +354,7 @@ restart: | |||
| 347 | 354 | ||
| 348 | strcpy(b_ptr->name, name); | 355 | strcpy(b_ptr->name, name); |
| 349 | b_ptr->media = m_ptr; | 356 | b_ptr->media = m_ptr; |
| 350 | res = m_ptr->enable_media(b_ptr); | 357 | res = m_ptr->enable_media(net, b_ptr); |
| 351 | if (res) { | 358 | if (res) { |
| 352 | pr_warn("Bearer <%s> rejected, enable failure (%d)\n", | 359 | pr_warn("Bearer <%s> rejected, enable failure (%d)\n", |
| 353 | name, -res); | 360 | name, -res); |
| @@ -361,15 +368,15 @@ restart: | |||
| 361 | b_ptr->net_plane = bearer_id + 'A'; | 368 | b_ptr->net_plane = bearer_id + 'A'; |
| 362 | b_ptr->priority = priority; | 369 | b_ptr->priority = priority; |
| 363 | 370 | ||
| 364 | res = tipc_disc_create(b_ptr, &b_ptr->bcast_addr); | 371 | res = tipc_disc_create(net, b_ptr, &b_ptr->bcast_addr); |
| 365 | if (res) { | 372 | if (res) { |
| 366 | bearer_disable(b_ptr, false); | 373 | bearer_disable(net, b_ptr, false); |
| 367 | pr_warn("Bearer <%s> rejected, discovery object creation failed\n", | 374 | pr_warn("Bearer <%s> rejected, discovery object creation failed\n", |
| 368 | name); | 375 | name); |
| 369 | return -EINVAL; | 376 | return -EINVAL; |
| 370 | } | 377 | } |
| 371 | 378 | ||
| 372 | rcu_assign_pointer(bearer_list[bearer_id], b_ptr); | 379 | rcu_assign_pointer(tn->bearer_list[bearer_id], b_ptr); |
| 373 | 380 | ||
| 374 | pr_info("Enabled bearer <%s>, discovery domain %s, priority %u\n", | 381 | pr_info("Enabled bearer <%s>, discovery domain %s, priority %u\n", |
| 375 | name, | 382 | name, |
| @@ -380,11 +387,11 @@ restart: | |||
| 380 | /** | 387 | /** |
| 381 | * tipc_reset_bearer - Reset all links established over this bearer | 388 | * tipc_reset_bearer - Reset all links established over this bearer |
| 382 | */ | 389 | */ |
| 383 | static int tipc_reset_bearer(struct tipc_bearer *b_ptr) | 390 | static int tipc_reset_bearer(struct net *net, struct tipc_bearer *b_ptr) |
| 384 | { | 391 | { |
| 385 | pr_info("Resetting bearer <%s>\n", b_ptr->name); | 392 | pr_info("Resetting bearer <%s>\n", b_ptr->name); |
| 386 | tipc_link_reset_list(b_ptr->identity); | 393 | tipc_link_reset_list(net, b_ptr->identity); |
| 387 | tipc_disc_reset(b_ptr); | 394 | tipc_disc_reset(net, b_ptr); |
| 388 | return 0; | 395 | return 0; |
| 389 | } | 396 | } |
| 390 | 397 | ||
| @@ -393,49 +400,51 @@ static int tipc_reset_bearer(struct tipc_bearer *b_ptr) | |||
| 393 | * | 400 | * |
| 394 | * Note: This routine assumes caller holds RTNL lock. | 401 | * Note: This routine assumes caller holds RTNL lock. |
| 395 | */ | 402 | */ |
| 396 | static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down) | 403 | static void bearer_disable(struct net *net, struct tipc_bearer *b_ptr, |
| 404 | bool shutting_down) | ||
| 397 | { | 405 | { |
| 406 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 398 | u32 i; | 407 | u32 i; |
| 399 | 408 | ||
| 400 | pr_info("Disabling bearer <%s>\n", b_ptr->name); | 409 | pr_info("Disabling bearer <%s>\n", b_ptr->name); |
| 401 | b_ptr->media->disable_media(b_ptr); | 410 | b_ptr->media->disable_media(b_ptr); |
| 402 | 411 | ||
| 403 | tipc_link_delete_list(b_ptr->identity, shutting_down); | 412 | tipc_link_delete_list(net, b_ptr->identity, shutting_down); |
| 404 | if (b_ptr->link_req) | 413 | if (b_ptr->link_req) |
| 405 | tipc_disc_delete(b_ptr->link_req); | 414 | tipc_disc_delete(b_ptr->link_req); |
| 406 | 415 | ||
| 407 | for (i = 0; i < MAX_BEARERS; i++) { | 416 | for (i = 0; i < MAX_BEARERS; i++) { |
| 408 | if (b_ptr == rtnl_dereference(bearer_list[i])) { | 417 | if (b_ptr == rtnl_dereference(tn->bearer_list[i])) { |
| 409 | RCU_INIT_POINTER(bearer_list[i], NULL); | 418 | RCU_INIT_POINTER(tn->bearer_list[i], NULL); |
| 410 | break; | 419 | break; |
| 411 | } | 420 | } |
| 412 | } | 421 | } |
| 413 | kfree_rcu(b_ptr, rcu); | 422 | kfree_rcu(b_ptr, rcu); |
| 414 | } | 423 | } |
| 415 | 424 | ||
| 416 | int tipc_disable_bearer(const char *name) | 425 | int tipc_disable_bearer(struct net *net, const char *name) |
| 417 | { | 426 | { |
| 418 | struct tipc_bearer *b_ptr; | 427 | struct tipc_bearer *b_ptr; |
| 419 | int res; | 428 | int res; |
| 420 | 429 | ||
| 421 | b_ptr = tipc_bearer_find(name); | 430 | b_ptr = tipc_bearer_find(net, name); |
| 422 | if (b_ptr == NULL) { | 431 | if (b_ptr == NULL) { |
| 423 | pr_warn("Attempt to disable unknown bearer <%s>\n", name); | 432 | pr_warn("Attempt to disable unknown bearer <%s>\n", name); |
| 424 | res = -EINVAL; | 433 | res = -EINVAL; |
| 425 | } else { | 434 | } else { |
| 426 | bearer_disable(b_ptr, false); | 435 | bearer_disable(net, b_ptr, false); |
| 427 | res = 0; | 436 | res = 0; |
| 428 | } | 437 | } |
| 429 | return res; | 438 | return res; |
| 430 | } | 439 | } |
| 431 | 440 | ||
| 432 | int tipc_enable_l2_media(struct tipc_bearer *b) | 441 | int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b) |
| 433 | { | 442 | { |
| 434 | struct net_device *dev; | 443 | struct net_device *dev; |
| 435 | char *driver_name = strchr((const char *)b->name, ':') + 1; | 444 | char *driver_name = strchr((const char *)b->name, ':') + 1; |
| 436 | 445 | ||
| 437 | /* Find device with specified name */ | 446 | /* Find device with specified name */ |
| 438 | dev = dev_get_by_name(&init_net, driver_name); | 447 | dev = dev_get_by_name(net, driver_name); |
| 439 | if (!dev) | 448 | if (!dev) |
| 440 | return -ENODEV; | 449 | return -ENODEV; |
| 441 | 450 | ||
| @@ -474,8 +483,8 @@ void tipc_disable_l2_media(struct tipc_bearer *b) | |||
| 474 | * @b_ptr: the bearer through which the packet is to be sent | 483 | * @b_ptr: the bearer through which the packet is to be sent |
| 475 | * @dest: peer destination address | 484 | * @dest: peer destination address |
| 476 | */ | 485 | */ |
| 477 | int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b, | 486 | int tipc_l2_send_msg(struct net *net, struct sk_buff *buf, |
| 478 | struct tipc_media_addr *dest) | 487 | struct tipc_bearer *b, struct tipc_media_addr *dest) |
| 479 | { | 488 | { |
| 480 | struct sk_buff *clone; | 489 | struct sk_buff *clone; |
| 481 | struct net_device *dev; | 490 | struct net_device *dev; |
| @@ -511,15 +520,16 @@ int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b, | |||
| 511 | * The media send routine must not alter the buffer being passed in | 520 | * The media send routine must not alter the buffer being passed in |
| 512 | * as it may be needed for later retransmission! | 521 | * as it may be needed for later retransmission! |
| 513 | */ | 522 | */ |
| 514 | void tipc_bearer_send(u32 bearer_id, struct sk_buff *buf, | 523 | void tipc_bearer_send(struct net *net, u32 bearer_id, struct sk_buff *buf, |
| 515 | struct tipc_media_addr *dest) | 524 | struct tipc_media_addr *dest) |
| 516 | { | 525 | { |
| 526 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 517 | struct tipc_bearer *b_ptr; | 527 | struct tipc_bearer *b_ptr; |
| 518 | 528 | ||
| 519 | rcu_read_lock(); | 529 | rcu_read_lock(); |
| 520 | b_ptr = rcu_dereference_rtnl(bearer_list[bearer_id]); | 530 | b_ptr = rcu_dereference_rtnl(tn->bearer_list[bearer_id]); |
| 521 | if (likely(b_ptr)) | 531 | if (likely(b_ptr)) |
| 522 | b_ptr->media->send_msg(buf, b_ptr, dest); | 532 | b_ptr->media->send_msg(net, buf, b_ptr, dest); |
| 523 | rcu_read_unlock(); | 533 | rcu_read_unlock(); |
| 524 | } | 534 | } |
| 525 | 535 | ||
| @@ -539,17 +549,12 @@ static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev, | |||
| 539 | { | 549 | { |
| 540 | struct tipc_bearer *b_ptr; | 550 | struct tipc_bearer *b_ptr; |
| 541 | 551 | ||
| 542 | if (!net_eq(dev_net(dev), &init_net)) { | ||
| 543 | kfree_skb(buf); | ||
| 544 | return NET_RX_DROP; | ||
| 545 | } | ||
| 546 | |||
| 547 | rcu_read_lock(); | 552 | rcu_read_lock(); |
| 548 | b_ptr = rcu_dereference_rtnl(dev->tipc_ptr); | 553 | b_ptr = rcu_dereference_rtnl(dev->tipc_ptr); |
| 549 | if (likely(b_ptr)) { | 554 | if (likely(b_ptr)) { |
| 550 | if (likely(buf->pkt_type <= PACKET_BROADCAST)) { | 555 | if (likely(buf->pkt_type <= PACKET_BROADCAST)) { |
| 551 | buf->next = NULL; | 556 | buf->next = NULL; |
| 552 | tipc_rcv(buf, b_ptr); | 557 | tipc_rcv(dev_net(dev), buf, b_ptr); |
| 553 | rcu_read_unlock(); | 558 | rcu_read_unlock(); |
| 554 | return NET_RX_SUCCESS; | 559 | return NET_RX_SUCCESS; |
| 555 | } | 560 | } |
| @@ -572,11 +577,9 @@ static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev, | |||
| 572 | static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, | 577 | static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, |
| 573 | void *ptr) | 578 | void *ptr) |
| 574 | { | 579 | { |
| 575 | struct tipc_bearer *b_ptr; | ||
| 576 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); | 580 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
| 577 | 581 | struct net *net = dev_net(dev); | |
| 578 | if (!net_eq(dev_net(dev), &init_net)) | 582 | struct tipc_bearer *b_ptr; |
| 579 | return NOTIFY_DONE; | ||
| 580 | 583 | ||
| 581 | b_ptr = rtnl_dereference(dev->tipc_ptr); | 584 | b_ptr = rtnl_dereference(dev->tipc_ptr); |
| 582 | if (!b_ptr) | 585 | if (!b_ptr) |
| @@ -590,16 +593,16 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, | |||
| 590 | break; | 593 | break; |
| 591 | case NETDEV_DOWN: | 594 | case NETDEV_DOWN: |
| 592 | case NETDEV_CHANGEMTU: | 595 | case NETDEV_CHANGEMTU: |
| 593 | tipc_reset_bearer(b_ptr); | 596 | tipc_reset_bearer(net, b_ptr); |
| 594 | break; | 597 | break; |
| 595 | case NETDEV_CHANGEADDR: | 598 | case NETDEV_CHANGEADDR: |
| 596 | b_ptr->media->raw2addr(b_ptr, &b_ptr->addr, | 599 | b_ptr->media->raw2addr(b_ptr, &b_ptr->addr, |
| 597 | (char *)dev->dev_addr); | 600 | (char *)dev->dev_addr); |
| 598 | tipc_reset_bearer(b_ptr); | 601 | tipc_reset_bearer(net, b_ptr); |
| 599 | break; | 602 | break; |
| 600 | case NETDEV_UNREGISTER: | 603 | case NETDEV_UNREGISTER: |
| 601 | case NETDEV_CHANGENAME: | 604 | case NETDEV_CHANGENAME: |
| 602 | bearer_disable(b_ptr, false); | 605 | bearer_disable(dev_net(dev), b_ptr, false); |
| 603 | break; | 606 | break; |
| 604 | } | 607 | } |
| 605 | return NOTIFY_OK; | 608 | return NOTIFY_OK; |
| @@ -632,16 +635,17 @@ void tipc_bearer_cleanup(void) | |||
| 632 | dev_remove_pack(&tipc_packet_type); | 635 | dev_remove_pack(&tipc_packet_type); |
| 633 | } | 636 | } |
| 634 | 637 | ||
| 635 | void tipc_bearer_stop(void) | 638 | void tipc_bearer_stop(struct net *net) |
| 636 | { | 639 | { |
| 640 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 637 | struct tipc_bearer *b_ptr; | 641 | struct tipc_bearer *b_ptr; |
| 638 | u32 i; | 642 | u32 i; |
| 639 | 643 | ||
| 640 | for (i = 0; i < MAX_BEARERS; i++) { | 644 | for (i = 0; i < MAX_BEARERS; i++) { |
| 641 | b_ptr = rtnl_dereference(bearer_list[i]); | 645 | b_ptr = rtnl_dereference(tn->bearer_list[i]); |
| 642 | if (b_ptr) { | 646 | if (b_ptr) { |
| 643 | bearer_disable(b_ptr, true); | 647 | bearer_disable(net, b_ptr, true); |
| 644 | bearer_list[i] = NULL; | 648 | tn->bearer_list[i] = NULL; |
| 645 | } | 649 | } |
| 646 | } | 650 | } |
| 647 | } | 651 | } |
| @@ -698,6 +702,8 @@ int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 698 | int i = cb->args[0]; | 702 | int i = cb->args[0]; |
| 699 | struct tipc_bearer *bearer; | 703 | struct tipc_bearer *bearer; |
| 700 | struct tipc_nl_msg msg; | 704 | struct tipc_nl_msg msg; |
| 705 | struct net *net = sock_net(skb->sk); | ||
| 706 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 701 | 707 | ||
| 702 | if (i == MAX_BEARERS) | 708 | if (i == MAX_BEARERS) |
| 703 | return 0; | 709 | return 0; |
| @@ -708,7 +714,7 @@ int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 708 | 714 | ||
| 709 | rtnl_lock(); | 715 | rtnl_lock(); |
| 710 | for (i = 0; i < MAX_BEARERS; i++) { | 716 | for (i = 0; i < MAX_BEARERS; i++) { |
| 711 | bearer = rtnl_dereference(bearer_list[i]); | 717 | bearer = rtnl_dereference(tn->bearer_list[i]); |
| 712 | if (!bearer) | 718 | if (!bearer) |
| 713 | continue; | 719 | continue; |
| 714 | 720 | ||
| @@ -730,6 +736,7 @@ int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info) | |||
| 730 | struct tipc_bearer *bearer; | 736 | struct tipc_bearer *bearer; |
| 731 | struct tipc_nl_msg msg; | 737 | struct tipc_nl_msg msg; |
| 732 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; | 738 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; |
| 739 | struct net *net = genl_info_net(info); | ||
| 733 | 740 | ||
| 734 | if (!info->attrs[TIPC_NLA_BEARER]) | 741 | if (!info->attrs[TIPC_NLA_BEARER]) |
| 735 | return -EINVAL; | 742 | return -EINVAL; |
| @@ -753,7 +760,7 @@ int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info) | |||
| 753 | msg.seq = info->snd_seq; | 760 | msg.seq = info->snd_seq; |
| 754 | 761 | ||
| 755 | rtnl_lock(); | 762 | rtnl_lock(); |
| 756 | bearer = tipc_bearer_find(name); | 763 | bearer = tipc_bearer_find(net, name); |
| 757 | if (!bearer) { | 764 | if (!bearer) { |
| 758 | err = -EINVAL; | 765 | err = -EINVAL; |
| 759 | goto err_out; | 766 | goto err_out; |
| @@ -778,6 +785,7 @@ int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info) | |||
| 778 | char *name; | 785 | char *name; |
| 779 | struct tipc_bearer *bearer; | 786 | struct tipc_bearer *bearer; |
| 780 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; | 787 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; |
| 788 | struct net *net = genl_info_net(info); | ||
| 781 | 789 | ||
| 782 | if (!info->attrs[TIPC_NLA_BEARER]) | 790 | if (!info->attrs[TIPC_NLA_BEARER]) |
| 783 | return -EINVAL; | 791 | return -EINVAL; |
| @@ -794,13 +802,13 @@ int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info) | |||
| 794 | name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); | 802 | name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); |
| 795 | 803 | ||
| 796 | rtnl_lock(); | 804 | rtnl_lock(); |
| 797 | bearer = tipc_bearer_find(name); | 805 | bearer = tipc_bearer_find(net, name); |
| 798 | if (!bearer) { | 806 | if (!bearer) { |
| 799 | rtnl_unlock(); | 807 | rtnl_unlock(); |
| 800 | return -EINVAL; | 808 | return -EINVAL; |
| 801 | } | 809 | } |
| 802 | 810 | ||
| 803 | bearer_disable(bearer, false); | 811 | bearer_disable(net, bearer, false); |
| 804 | rtnl_unlock(); | 812 | rtnl_unlock(); |
| 805 | 813 | ||
| 806 | return 0; | 814 | return 0; |
| @@ -808,6 +816,8 @@ int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info) | |||
| 808 | 816 | ||
| 809 | int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) | 817 | int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) |
| 810 | { | 818 | { |
| 819 | struct net *net = genl_info_net(info); | ||
| 820 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 811 | int err; | 821 | int err; |
| 812 | char *bearer; | 822 | char *bearer; |
| 813 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; | 823 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; |
| @@ -815,7 +825,7 @@ int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) | |||
| 815 | u32 prio; | 825 | u32 prio; |
| 816 | 826 | ||
| 817 | prio = TIPC_MEDIA_LINK_PRI; | 827 | prio = TIPC_MEDIA_LINK_PRI; |
| 818 | domain = tipc_own_addr & TIPC_CLUSTER_MASK; | 828 | domain = tn->own_addr & TIPC_CLUSTER_MASK; |
| 819 | 829 | ||
| 820 | if (!info->attrs[TIPC_NLA_BEARER]) | 830 | if (!info->attrs[TIPC_NLA_BEARER]) |
| 821 | return -EINVAL; | 831 | return -EINVAL; |
| @@ -847,7 +857,7 @@ int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) | |||
| 847 | } | 857 | } |
| 848 | 858 | ||
| 849 | rtnl_lock(); | 859 | rtnl_lock(); |
| 850 | err = tipc_enable_bearer(bearer, domain, prio); | 860 | err = tipc_enable_bearer(net, bearer, domain, prio); |
| 851 | if (err) { | 861 | if (err) { |
| 852 | rtnl_unlock(); | 862 | rtnl_unlock(); |
| 853 | return err; | 863 | return err; |
| @@ -863,6 +873,7 @@ int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info) | |||
| 863 | char *name; | 873 | char *name; |
| 864 | struct tipc_bearer *b; | 874 | struct tipc_bearer *b; |
| 865 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; | 875 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; |
| 876 | struct net *net = genl_info_net(info); | ||
| 866 | 877 | ||
| 867 | if (!info->attrs[TIPC_NLA_BEARER]) | 878 | if (!info->attrs[TIPC_NLA_BEARER]) |
| 868 | return -EINVAL; | 879 | return -EINVAL; |
| @@ -878,7 +889,7 @@ int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info) | |||
| 878 | name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); | 889 | name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); |
| 879 | 890 | ||
| 880 | rtnl_lock(); | 891 | rtnl_lock(); |
| 881 | b = tipc_bearer_find(name); | 892 | b = tipc_bearer_find(net, name); |
| 882 | if (!b) { | 893 | if (!b) { |
| 883 | rtnl_unlock(); | 894 | rtnl_unlock(); |
| 884 | return -EINVAL; | 895 | return -EINVAL; |
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 2c1230ac5dfe..c035e3e24764 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h | |||
| @@ -37,12 +37,13 @@ | |||
| 37 | #ifndef _TIPC_BEARER_H | 37 | #ifndef _TIPC_BEARER_H |
| 38 | #define _TIPC_BEARER_H | 38 | #define _TIPC_BEARER_H |
| 39 | 39 | ||
| 40 | #include "bcast.h" | ||
| 41 | #include "netlink.h" | 40 | #include "netlink.h" |
| 42 | #include <net/genetlink.h> | 41 | #include <net/genetlink.h> |
| 43 | 42 | ||
| 44 | #define MAX_BEARERS 2 | 43 | #define MAX_BEARERS 2 |
| 45 | #define MAX_MEDIA 2 | 44 | #define MAX_MEDIA 2 |
| 45 | #define MAX_NODES 4096 | ||
| 46 | #define WSIZE 32 | ||
| 46 | 47 | ||
| 47 | /* Identifiers associated with TIPC message header media address info | 48 | /* Identifiers associated with TIPC message header media address info |
| 48 | * - address info field is 32 bytes long | 49 | * - address info field is 32 bytes long |
| @@ -59,6 +60,16 @@ | |||
| 59 | #define TIPC_MEDIA_TYPE_IB 2 | 60 | #define TIPC_MEDIA_TYPE_IB 2 |
| 60 | 61 | ||
| 61 | /** | 62 | /** |
| 63 | * struct tipc_node_map - set of node identifiers | ||
| 64 | * @count: # of nodes in set | ||
| 65 | * @map: bitmap of node identifiers that are in the set | ||
| 66 | */ | ||
| 67 | struct tipc_node_map { | ||
| 68 | u32 count; | ||
| 69 | u32 map[MAX_NODES / WSIZE]; | ||
| 70 | }; | ||
| 71 | |||
| 72 | /** | ||
| 62 | * struct tipc_media_addr - destination address used by TIPC bearers | 73 | * struct tipc_media_addr - destination address used by TIPC bearers |
| 63 | * @value: address info (format defined by media) | 74 | * @value: address info (format defined by media) |
| 64 | * @media_id: TIPC media type identifier | 75 | * @media_id: TIPC media type identifier |
| @@ -89,10 +100,10 @@ struct tipc_bearer; | |||
| 89 | * @name: media name | 100 | * @name: media name |
| 90 | */ | 101 | */ |
| 91 | struct tipc_media { | 102 | struct tipc_media { |
| 92 | int (*send_msg)(struct sk_buff *buf, | 103 | int (*send_msg)(struct net *net, struct sk_buff *buf, |
| 93 | struct tipc_bearer *b_ptr, | 104 | struct tipc_bearer *b_ptr, |
| 94 | struct tipc_media_addr *dest); | 105 | struct tipc_media_addr *dest); |
| 95 | int (*enable_media)(struct tipc_bearer *b_ptr); | 106 | int (*enable_media)(struct net *net, struct tipc_bearer *b_ptr); |
| 96 | void (*disable_media)(struct tipc_bearer *b_ptr); | 107 | void (*disable_media)(struct tipc_bearer *b_ptr); |
| 97 | int (*addr2str)(struct tipc_media_addr *addr, | 108 | int (*addr2str)(struct tipc_media_addr *addr, |
| 98 | char *strbuf, | 109 | char *strbuf, |
| @@ -157,17 +168,14 @@ struct tipc_bearer_names { | |||
| 157 | char if_name[TIPC_MAX_IF_NAME]; | 168 | char if_name[TIPC_MAX_IF_NAME]; |
| 158 | }; | 169 | }; |
| 159 | 170 | ||
| 160 | struct tipc_link; | ||
| 161 | |||
| 162 | extern struct tipc_bearer __rcu *bearer_list[]; | ||
| 163 | |||
| 164 | /* | 171 | /* |
| 165 | * TIPC routines available to supported media types | 172 | * TIPC routines available to supported media types |
| 166 | */ | 173 | */ |
| 167 | 174 | ||
| 168 | void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *tb_ptr); | 175 | void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr); |
| 169 | int tipc_enable_bearer(const char *bearer_name, u32 disc_domain, u32 priority); | 176 | int tipc_enable_bearer(struct net *net, const char *bearer_name, |
| 170 | int tipc_disable_bearer(const char *name); | 177 | u32 disc_domain, u32 priority); |
| 178 | int tipc_disable_bearer(struct net *net, const char *name); | ||
| 171 | 179 | ||
| 172 | /* | 180 | /* |
| 173 | * Routines made available to TIPC by supported media types | 181 | * Routines made available to TIPC by supported media types |
| @@ -192,20 +200,20 @@ int tipc_media_set_priority(const char *name, u32 new_value); | |||
| 192 | int tipc_media_set_window(const char *name, u32 new_value); | 200 | int tipc_media_set_window(const char *name, u32 new_value); |
| 193 | void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); | 201 | void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); |
| 194 | struct sk_buff *tipc_media_get_names(void); | 202 | struct sk_buff *tipc_media_get_names(void); |
| 195 | int tipc_enable_l2_media(struct tipc_bearer *b); | 203 | int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b); |
| 196 | void tipc_disable_l2_media(struct tipc_bearer *b); | 204 | void tipc_disable_l2_media(struct tipc_bearer *b); |
| 197 | int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b, | 205 | int tipc_l2_send_msg(struct net *net, struct sk_buff *buf, |
| 198 | struct tipc_media_addr *dest); | 206 | struct tipc_bearer *b, struct tipc_media_addr *dest); |
| 199 | 207 | ||
| 200 | struct sk_buff *tipc_bearer_get_names(void); | 208 | struct sk_buff *tipc_bearer_get_names(struct net *net); |
| 201 | void tipc_bearer_add_dest(u32 bearer_id, u32 dest); | 209 | void tipc_bearer_add_dest(struct net *net, u32 bearer_id, u32 dest); |
| 202 | void tipc_bearer_remove_dest(u32 bearer_id, u32 dest); | 210 | void tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest); |
| 203 | struct tipc_bearer *tipc_bearer_find(const char *name); | 211 | struct tipc_bearer *tipc_bearer_find(struct net *net, const char *name); |
| 204 | struct tipc_media *tipc_media_find(const char *name); | 212 | struct tipc_media *tipc_media_find(const char *name); |
| 205 | int tipc_bearer_setup(void); | 213 | int tipc_bearer_setup(void); |
| 206 | void tipc_bearer_cleanup(void); | 214 | void tipc_bearer_cleanup(void); |
| 207 | void tipc_bearer_stop(void); | 215 | void tipc_bearer_stop(struct net *net); |
| 208 | void tipc_bearer_send(u32 bearer_id, struct sk_buff *buf, | 216 | void tipc_bearer_send(struct net *net, u32 bearer_id, struct sk_buff *buf, |
| 209 | struct tipc_media_addr *dest); | 217 | struct tipc_media_addr *dest); |
| 210 | 218 | ||
| 211 | #endif /* _TIPC_BEARER_H */ | 219 | #endif /* _TIPC_BEARER_H */ |
diff --git a/net/tipc/config.c b/net/tipc/config.c index 876f4c6a2631..6873360cda53 100644 --- a/net/tipc/config.c +++ b/net/tipc/config.c | |||
| @@ -134,7 +134,7 @@ static struct sk_buff *tipc_show_stats(void) | |||
| 134 | return buf; | 134 | return buf; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | static struct sk_buff *cfg_enable_bearer(void) | 137 | static struct sk_buff *cfg_enable_bearer(struct net *net) |
| 138 | { | 138 | { |
| 139 | struct tipc_bearer_config *args; | 139 | struct tipc_bearer_config *args; |
| 140 | 140 | ||
| @@ -142,7 +142,7 @@ static struct sk_buff *cfg_enable_bearer(void) | |||
| 142 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 142 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
| 143 | 143 | ||
| 144 | args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area); | 144 | args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area); |
| 145 | if (tipc_enable_bearer(args->name, | 145 | if (tipc_enable_bearer(net, args->name, |
| 146 | ntohl(args->disc_domain), | 146 | ntohl(args->disc_domain), |
| 147 | ntohl(args->priority))) | 147 | ntohl(args->priority))) |
| 148 | return tipc_cfg_reply_error_string("unable to enable bearer"); | 148 | return tipc_cfg_reply_error_string("unable to enable bearer"); |
| @@ -150,78 +150,66 @@ static struct sk_buff *cfg_enable_bearer(void) | |||
| 150 | return tipc_cfg_reply_none(); | 150 | return tipc_cfg_reply_none(); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | static struct sk_buff *cfg_disable_bearer(void) | 153 | static struct sk_buff *cfg_disable_bearer(struct net *net) |
| 154 | { | 154 | { |
| 155 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME)) | 155 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME)) |
| 156 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 156 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
| 157 | 157 | ||
| 158 | if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area))) | 158 | if (tipc_disable_bearer(net, (char *)TLV_DATA(req_tlv_area))) |
| 159 | return tipc_cfg_reply_error_string("unable to disable bearer"); | 159 | return tipc_cfg_reply_error_string("unable to disable bearer"); |
| 160 | 160 | ||
| 161 | return tipc_cfg_reply_none(); | 161 | return tipc_cfg_reply_none(); |
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | static struct sk_buff *cfg_set_own_addr(void) | 164 | static struct sk_buff *cfg_set_own_addr(struct net *net) |
| 165 | { | 165 | { |
| 166 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 166 | u32 addr; | 167 | u32 addr; |
| 167 | 168 | ||
| 168 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) | 169 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) |
| 169 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 170 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
| 170 | 171 | ||
| 171 | addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 172 | addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
| 172 | if (addr == tipc_own_addr) | 173 | if (addr == tn->own_addr) |
| 173 | return tipc_cfg_reply_none(); | 174 | return tipc_cfg_reply_none(); |
| 174 | if (!tipc_addr_node_valid(addr)) | 175 | if (!tipc_addr_node_valid(addr)) |
| 175 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 176 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 176 | " (node address)"); | 177 | " (node address)"); |
| 177 | if (tipc_own_addr) | 178 | if (tn->own_addr) |
| 178 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 179 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 179 | " (cannot change node address once assigned)"); | 180 | " (cannot change node address once assigned)"); |
| 180 | if (!tipc_net_start(addr)) | 181 | if (!tipc_net_start(net, addr)) |
| 181 | return tipc_cfg_reply_none(); | 182 | return tipc_cfg_reply_none(); |
| 182 | 183 | ||
| 183 | return tipc_cfg_reply_error_string("cannot change to network mode"); | 184 | return tipc_cfg_reply_error_string("cannot change to network mode"); |
| 184 | } | 185 | } |
| 185 | 186 | ||
| 186 | static struct sk_buff *cfg_set_max_ports(void) | 187 | static struct sk_buff *cfg_set_netid(struct net *net) |
| 187 | { | 188 | { |
| 189 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 188 | u32 value; | 190 | u32 value; |
| 189 | 191 | ||
| 190 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 192 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
| 191 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 193 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
| 192 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 194 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
| 193 | if (value == tipc_max_ports) | 195 | if (value == tn->net_id) |
| 194 | return tipc_cfg_reply_none(); | ||
| 195 | if (value < 127 || value > 65535) | ||
| 196 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | ||
| 197 | " (max ports must be 127-65535)"); | ||
| 198 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | ||
| 199 | " (cannot change max ports while TIPC is active)"); | ||
| 200 | } | ||
| 201 | |||
| 202 | static struct sk_buff *cfg_set_netid(void) | ||
| 203 | { | ||
| 204 | u32 value; | ||
| 205 | |||
| 206 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | ||
| 207 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | ||
| 208 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | ||
| 209 | if (value == tipc_net_id) | ||
| 210 | return tipc_cfg_reply_none(); | 196 | return tipc_cfg_reply_none(); |
| 211 | if (value < 1 || value > 9999) | 197 | if (value < 1 || value > 9999) |
| 212 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 198 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 213 | " (network id must be 1-9999)"); | 199 | " (network id must be 1-9999)"); |
| 214 | if (tipc_own_addr) | 200 | if (tn->own_addr) |
| 215 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 201 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 216 | " (cannot change network id once TIPC has joined a network)"); | 202 | " (cannot change network id once TIPC has joined a network)"); |
| 217 | tipc_net_id = value; | 203 | tn->net_id = value; |
| 218 | return tipc_cfg_reply_none(); | 204 | return tipc_cfg_reply_none(); |
| 219 | } | 205 | } |
| 220 | 206 | ||
| 221 | struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area, | 207 | struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd, |
| 222 | int request_space, int reply_headroom) | 208 | const void *request_area, int request_space, |
| 209 | int reply_headroom) | ||
| 223 | { | 210 | { |
| 224 | struct sk_buff *rep_tlv_buf; | 211 | struct sk_buff *rep_tlv_buf; |
| 212 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 225 | 213 | ||
| 226 | rtnl_lock(); | 214 | rtnl_lock(); |
| 227 | 215 | ||
| @@ -231,7 +219,7 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area | |||
| 231 | rep_headroom = reply_headroom; | 219 | rep_headroom = reply_headroom; |
| 232 | 220 | ||
| 233 | /* Check command authorization */ | 221 | /* Check command authorization */ |
| 234 | if (likely(in_own_node(orig_node))) { | 222 | if (likely(in_own_node(net, orig_node))) { |
| 235 | /* command is permitted */ | 223 | /* command is permitted */ |
| 236 | } else { | 224 | } else { |
| 237 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 225 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| @@ -245,28 +233,33 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area | |||
| 245 | rep_tlv_buf = tipc_cfg_reply_none(); | 233 | rep_tlv_buf = tipc_cfg_reply_none(); |
| 246 | break; | 234 | break; |
| 247 | case TIPC_CMD_GET_NODES: | 235 | case TIPC_CMD_GET_NODES: |
| 248 | rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space); | 236 | rep_tlv_buf = tipc_node_get_nodes(net, req_tlv_area, |
| 237 | req_tlv_space); | ||
| 249 | break; | 238 | break; |
| 250 | case TIPC_CMD_GET_LINKS: | 239 | case TIPC_CMD_GET_LINKS: |
| 251 | rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space); | 240 | rep_tlv_buf = tipc_node_get_links(net, req_tlv_area, |
| 241 | req_tlv_space); | ||
| 252 | break; | 242 | break; |
| 253 | case TIPC_CMD_SHOW_LINK_STATS: | 243 | case TIPC_CMD_SHOW_LINK_STATS: |
| 254 | rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space); | 244 | rep_tlv_buf = tipc_link_cmd_show_stats(net, req_tlv_area, |
| 245 | req_tlv_space); | ||
| 255 | break; | 246 | break; |
| 256 | case TIPC_CMD_RESET_LINK_STATS: | 247 | case TIPC_CMD_RESET_LINK_STATS: |
| 257 | rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space); | 248 | rep_tlv_buf = tipc_link_cmd_reset_stats(net, req_tlv_area, |
| 249 | req_tlv_space); | ||
| 258 | break; | 250 | break; |
| 259 | case TIPC_CMD_SHOW_NAME_TABLE: | 251 | case TIPC_CMD_SHOW_NAME_TABLE: |
| 260 | rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space); | 252 | rep_tlv_buf = tipc_nametbl_get(net, req_tlv_area, |
| 253 | req_tlv_space); | ||
| 261 | break; | 254 | break; |
| 262 | case TIPC_CMD_GET_BEARER_NAMES: | 255 | case TIPC_CMD_GET_BEARER_NAMES: |
| 263 | rep_tlv_buf = tipc_bearer_get_names(); | 256 | rep_tlv_buf = tipc_bearer_get_names(net); |
| 264 | break; | 257 | break; |
| 265 | case TIPC_CMD_GET_MEDIA_NAMES: | 258 | case TIPC_CMD_GET_MEDIA_NAMES: |
| 266 | rep_tlv_buf = tipc_media_get_names(); | 259 | rep_tlv_buf = tipc_media_get_names(); |
| 267 | break; | 260 | break; |
| 268 | case TIPC_CMD_SHOW_PORTS: | 261 | case TIPC_CMD_SHOW_PORTS: |
| 269 | rep_tlv_buf = tipc_sk_socks_show(); | 262 | rep_tlv_buf = tipc_sk_socks_show(net); |
| 270 | break; | 263 | break; |
| 271 | case TIPC_CMD_SHOW_STATS: | 264 | case TIPC_CMD_SHOW_STATS: |
| 272 | rep_tlv_buf = tipc_show_stats(); | 265 | rep_tlv_buf = tipc_show_stats(); |
| @@ -274,28 +267,23 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area | |||
| 274 | case TIPC_CMD_SET_LINK_TOL: | 267 | case TIPC_CMD_SET_LINK_TOL: |
| 275 | case TIPC_CMD_SET_LINK_PRI: | 268 | case TIPC_CMD_SET_LINK_PRI: |
| 276 | case TIPC_CMD_SET_LINK_WINDOW: | 269 | case TIPC_CMD_SET_LINK_WINDOW: |
| 277 | rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd); | 270 | rep_tlv_buf = tipc_link_cmd_config(net, req_tlv_area, |
| 271 | req_tlv_space, cmd); | ||
| 278 | break; | 272 | break; |
| 279 | case TIPC_CMD_ENABLE_BEARER: | 273 | case TIPC_CMD_ENABLE_BEARER: |
| 280 | rep_tlv_buf = cfg_enable_bearer(); | 274 | rep_tlv_buf = cfg_enable_bearer(net); |
| 281 | break; | 275 | break; |
| 282 | case TIPC_CMD_DISABLE_BEARER: | 276 | case TIPC_CMD_DISABLE_BEARER: |
| 283 | rep_tlv_buf = cfg_disable_bearer(); | 277 | rep_tlv_buf = cfg_disable_bearer(net); |
| 284 | break; | 278 | break; |
| 285 | case TIPC_CMD_SET_NODE_ADDR: | 279 | case TIPC_CMD_SET_NODE_ADDR: |
| 286 | rep_tlv_buf = cfg_set_own_addr(); | 280 | rep_tlv_buf = cfg_set_own_addr(net); |
| 287 | break; | ||
| 288 | case TIPC_CMD_SET_MAX_PORTS: | ||
| 289 | rep_tlv_buf = cfg_set_max_ports(); | ||
| 290 | break; | 281 | break; |
| 291 | case TIPC_CMD_SET_NETID: | 282 | case TIPC_CMD_SET_NETID: |
| 292 | rep_tlv_buf = cfg_set_netid(); | 283 | rep_tlv_buf = cfg_set_netid(net); |
| 293 | break; | ||
| 294 | case TIPC_CMD_GET_MAX_PORTS: | ||
| 295 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports); | ||
| 296 | break; | 284 | break; |
| 297 | case TIPC_CMD_GET_NETID: | 285 | case TIPC_CMD_GET_NETID: |
| 298 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id); | 286 | rep_tlv_buf = tipc_cfg_reply_unsigned(tn->net_id); |
| 299 | break; | 287 | break; |
| 300 | case TIPC_CMD_NOT_NET_ADMIN: | 288 | case TIPC_CMD_NOT_NET_ADMIN: |
| 301 | rep_tlv_buf = | 289 | rep_tlv_buf = |
| @@ -317,6 +305,8 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area | |||
| 317 | case TIPC_CMD_SET_REMOTE_MNG: | 305 | case TIPC_CMD_SET_REMOTE_MNG: |
| 318 | case TIPC_CMD_GET_REMOTE_MNG: | 306 | case TIPC_CMD_GET_REMOTE_MNG: |
| 319 | case TIPC_CMD_DUMP_LOG: | 307 | case TIPC_CMD_DUMP_LOG: |
| 308 | case TIPC_CMD_SET_MAX_PORTS: | ||
| 309 | case TIPC_CMD_GET_MAX_PORTS: | ||
| 320 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 310 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 321 | " (obsolete command)"); | 311 | " (obsolete command)"); |
| 322 | break; | 312 | break; |
diff --git a/net/tipc/config.h b/net/tipc/config.h index 47b1bf181612..9e9b575fc429 100644 --- a/net/tipc/config.h +++ b/net/tipc/config.h | |||
| @@ -37,10 +37,10 @@ | |||
| 37 | #ifndef _TIPC_CONFIG_H | 37 | #ifndef _TIPC_CONFIG_H |
| 38 | #define _TIPC_CONFIG_H | 38 | #define _TIPC_CONFIG_H |
| 39 | 39 | ||
| 40 | /* ---------------------------------------------------------------------- */ | ||
| 41 | |||
| 42 | #include "link.h" | 40 | #include "link.h" |
| 43 | 41 | ||
| 42 | #define ULTRA_STRING_MAX_LEN 32768 | ||
| 43 | |||
| 44 | struct sk_buff *tipc_cfg_reply_alloc(int payload_size); | 44 | struct sk_buff *tipc_cfg_reply_alloc(int payload_size); |
| 45 | int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type, | 45 | int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type, |
| 46 | void *tlv_data, int tlv_data_size); | 46 | void *tlv_data, int tlv_data_size); |
| @@ -61,7 +61,7 @@ static inline struct sk_buff *tipc_cfg_reply_ultra_string(char *string) | |||
| 61 | return tipc_cfg_reply_string_type(TIPC_TLV_ULTRA_STRING, string); | 61 | return tipc_cfg_reply_string_type(TIPC_TLV_ULTRA_STRING, string); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, | 64 | struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd, |
| 65 | const void *req_tlv_area, int req_tlv_space, | 65 | const void *req_tlv_area, int req_tlv_space, |
| 66 | int headroom); | 66 | int headroom); |
| 67 | #endif | 67 | #endif |
diff --git a/net/tipc/core.c b/net/tipc/core.c index a5737b8407dd..674bd2698528 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c | |||
| @@ -34,6 +34,8 @@ | |||
| 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" |
| @@ -42,69 +44,68 @@ | |||
| 42 | 44 | ||
| 43 | #include <linux/module.h> | 45 | #include <linux/module.h> |
| 44 | 46 | ||
| 45 | /* global variables used by multiple sub-systems within TIPC */ | ||
| 46 | int tipc_random __read_mostly; | ||
| 47 | |||
| 48 | /* configurable TIPC parameters */ | 47 | /* configurable TIPC parameters */ |
| 49 | u32 tipc_own_addr __read_mostly; | ||
| 50 | int tipc_max_ports __read_mostly; | ||
| 51 | int tipc_net_id __read_mostly; | 48 | int tipc_net_id __read_mostly; |
| 52 | int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */ | 49 | int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */ |
| 53 | 50 | ||
| 54 | /** | 51 | 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 | { | 52 | { |
| 65 | struct sk_buff *skb; | 53 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 66 | unsigned int buf_size = (BUF_HEADROOM + size + 3) & ~3u; | 54 | int err; |
| 67 | 55 | ||
| 68 | skb = alloc_skb_fclone(buf_size, GFP_ATOMIC); | 56 | tn->net_id = 4711; |
| 69 | if (skb) { | 57 | tn->own_addr = 0; |
| 70 | skb_reserve(skb, BUF_HEADROOM); | 58 | get_random_bytes(&tn->random, sizeof(int)); |
| 71 | skb_put(skb, size); | 59 | INIT_LIST_HEAD(&tn->node_list); |
| 72 | skb->next = NULL; | 60 | spin_lock_init(&tn->node_list_lock); |
| 73 | } | 61 | |
| 74 | return skb; | 62 | err = tipc_sk_rht_init(net); |
| 63 | if (err) | ||
| 64 | goto out_sk_rht; | ||
| 65 | |||
| 66 | err = tipc_nametbl_init(net); | ||
| 67 | if (err) | ||
| 68 | goto out_nametbl; | ||
| 69 | |||
| 70 | err = tipc_subscr_start(net); | ||
| 71 | if (err) | ||
| 72 | goto out_subscr; | ||
| 73 | return 0; | ||
| 74 | |||
| 75 | out_subscr: | ||
| 76 | tipc_nametbl_stop(net); | ||
| 77 | out_nametbl: | ||
| 78 | tipc_sk_rht_destroy(net); | ||
| 79 | out_sk_rht: | ||
| 80 | return err; | ||
| 75 | } | 81 | } |
| 76 | 82 | ||
| 77 | /** | 83 | 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 | { | 84 | { |
| 82 | tipc_net_stop(); | 85 | tipc_subscr_stop(net); |
| 83 | tipc_bearer_cleanup(); | 86 | tipc_net_stop(net); |
| 84 | tipc_netlink_stop(); | 87 | tipc_nametbl_stop(net); |
| 85 | tipc_subscr_stop(); | 88 | tipc_sk_rht_destroy(net); |
| 86 | tipc_nametbl_stop(); | ||
| 87 | tipc_sk_ref_table_stop(); | ||
| 88 | tipc_socket_stop(); | ||
| 89 | tipc_unregister_sysctl(); | ||
| 90 | } | 89 | } |
| 91 | 90 | ||
| 92 | /** | 91 | static struct pernet_operations tipc_net_ops = { |
| 93 | * tipc_core_start - switch TIPC from NOT RUNNING to SINGLE NODE mode | 92 | .init = tipc_init_net, |
| 94 | */ | 93 | .exit = tipc_exit_net, |
| 95 | static int tipc_core_start(void) | 94 | .id = &tipc_net_id, |
| 95 | .size = sizeof(struct tipc_net), | ||
| 96 | }; | ||
| 97 | |||
| 98 | static int __init tipc_init(void) | ||
| 96 | { | 99 | { |
| 97 | int err; | 100 | int err; |
| 98 | 101 | ||
| 99 | get_random_bytes(&tipc_random, sizeof(tipc_random)); | 102 | 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 | 103 | ||
| 105 | err = tipc_nametbl_init(); | 104 | sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 << |
| 106 | if (err) | 105 | TIPC_LOW_IMPORTANCE; |
| 107 | goto out_nametbl; | 106 | sysctl_tipc_rmem[1] = TIPC_CONN_OVERLOAD_LIMIT >> 4 << |
| 107 | TIPC_CRITICAL_IMPORTANCE; | ||
| 108 | sysctl_tipc_rmem[2] = TIPC_CONN_OVERLOAD_LIMIT; | ||
| 108 | 109 | ||
| 109 | err = tipc_netlink_start(); | 110 | err = tipc_netlink_start(); |
| 110 | if (err) | 111 | if (err) |
| @@ -118,58 +119,37 @@ static int tipc_core_start(void) | |||
| 118 | if (err) | 119 | if (err) |
| 119 | goto out_sysctl; | 120 | goto out_sysctl; |
| 120 | 121 | ||
| 121 | err = tipc_subscr_start(); | 122 | err = register_pernet_subsys(&tipc_net_ops); |
| 122 | if (err) | 123 | if (err) |
| 123 | goto out_subscr; | 124 | goto out_pernet; |
| 124 | 125 | ||
| 125 | err = tipc_bearer_setup(); | 126 | err = tipc_bearer_setup(); |
| 126 | if (err) | 127 | if (err) |
| 127 | goto out_bearer; | 128 | goto out_bearer; |
| 128 | 129 | ||
| 130 | pr_info("Started in single node mode\n"); | ||
| 129 | return 0; | 131 | return 0; |
| 130 | out_bearer: | 132 | out_bearer: |
| 131 | tipc_subscr_stop(); | 133 | unregister_pernet_subsys(&tipc_net_ops); |
| 132 | out_subscr: | 134 | out_pernet: |
| 133 | tipc_unregister_sysctl(); | 135 | tipc_unregister_sysctl(); |
| 134 | out_sysctl: | 136 | out_sysctl: |
| 135 | tipc_socket_stop(); | 137 | tipc_socket_stop(); |
| 136 | out_socket: | 138 | out_socket: |
| 137 | tipc_netlink_stop(); | 139 | tipc_netlink_stop(); |
| 138 | out_netlink: | 140 | out_netlink: |
| 139 | tipc_nametbl_stop(); | 141 | 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; | 142 | return err; |
| 144 | } | 143 | } |
| 145 | 144 | ||
| 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) | 145 | static void __exit tipc_exit(void) |
| 171 | { | 146 | { |
| 172 | tipc_core_stop(); | 147 | tipc_bearer_cleanup(); |
| 148 | tipc_netlink_stop(); | ||
| 149 | tipc_socket_stop(); | ||
| 150 | tipc_unregister_sysctl(); | ||
| 151 | unregister_pernet_subsys(&tipc_net_ops); | ||
| 152 | |||
| 173 | pr_info("Deactivated\n"); | 153 | pr_info("Deactivated\n"); |
| 174 | } | 154 | } |
| 175 | 155 | ||
diff --git a/net/tipc/core.h b/net/tipc/core.h index 84602137ce20..817b2e9d4227 100644 --- a/net/tipc/core.h +++ b/net/tipc/core.h | |||
| @@ -37,8 +37,6 @@ | |||
| 37 | #ifndef _TIPC_CORE_H | 37 | #ifndef _TIPC_CORE_H |
| 38 | #define _TIPC_CORE_H | 38 | #define _TIPC_CORE_H |
| 39 | 39 | ||
| 40 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 41 | |||
| 42 | #include <linux/tipc.h> | 40 | #include <linux/tipc.h> |
| 43 | #include <linux/tipc_config.h> | 41 | #include <linux/tipc_config.h> |
| 44 | #include <linux/tipc_netlink.h> | 42 | #include <linux/tipc_netlink.h> |
| @@ -59,47 +57,56 @@ | |||
| 59 | #include <linux/vmalloc.h> | 57 | #include <linux/vmalloc.h> |
| 60 | #include <linux/rtnetlink.h> | 58 | #include <linux/rtnetlink.h> |
| 61 | #include <linux/etherdevice.h> | 59 | #include <linux/etherdevice.h> |
| 60 | #include <net/netns/generic.h> | ||
| 61 | #include <linux/rhashtable.h> | ||
| 62 | 62 | ||
| 63 | #define TIPC_MOD_VER "2.0.0" | 63 | #include "node.h" |
| 64 | 64 | #include "bearer.h" | |
| 65 | #define ULTRA_STRING_MAX_LEN 32768 | 65 | #include "bcast.h" |
| 66 | #define TIPC_MAX_SUBSCRIPTIONS 65535 | 66 | #include "netlink.h" |
| 67 | #define TIPC_MAX_PUBLICATIONS 65535 | 67 | #include "link.h" |
| 68 | #include "node.h" | ||
| 69 | #include "msg.h" | ||
| 68 | 70 | ||
| 69 | struct tipc_msg; /* msg.h */ | 71 | #define TIPC_MOD_VER "2.0.0" |
| 70 | 72 | ||
| 71 | int tipc_snprintf(char *buf, int len, const char *fmt, ...); | 73 | int tipc_snprintf(char *buf, int len, const char *fmt, ...); |
| 72 | 74 | ||
| 73 | /* | ||
| 74 | * TIPC-specific error codes | ||
| 75 | */ | ||
| 76 | #define ELINKCONG EAGAIN /* link congestion <=> resource unavailable */ | ||
| 77 | |||
| 78 | /* | ||
| 79 | * Global configuration variables | ||
| 80 | */ | ||
| 81 | extern u32 tipc_own_addr __read_mostly; | ||
| 82 | extern int tipc_max_ports __read_mostly; | ||
| 83 | extern int tipc_net_id __read_mostly; | 75 | extern int tipc_net_id __read_mostly; |
| 84 | extern int sysctl_tipc_rmem[3] __read_mostly; | 76 | extern int sysctl_tipc_rmem[3] __read_mostly; |
| 85 | extern int sysctl_tipc_named_timeout __read_mostly; | 77 | extern int sysctl_tipc_named_timeout __read_mostly; |
| 86 | 78 | ||
| 87 | /* | 79 | struct tipc_net { |
| 88 | * Other global variables | 80 | u32 own_addr; |
| 89 | */ | 81 | int net_id; |
| 90 | extern int tipc_random __read_mostly; | 82 | int random; |
| 91 | 83 | ||
| 92 | /* | 84 | /* Node table and node list */ |
| 93 | * Routines available to privileged subsystems | 85 | spinlock_t node_list_lock; |
| 94 | */ | 86 | struct hlist_head node_htable[NODE_HTABLE_SIZE]; |
| 95 | int tipc_netlink_start(void); | 87 | struct list_head node_list; |
| 96 | void tipc_netlink_stop(void); | 88 | u32 num_nodes; |
| 97 | int tipc_socket_init(void); | 89 | u32 num_links; |
| 98 | void tipc_socket_stop(void); | 90 | |
| 99 | int tipc_sock_create_local(int type, struct socket **res); | 91 | /* Bearer list */ |
| 100 | void tipc_sock_release_local(struct socket *sock); | 92 | struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1]; |
| 101 | int tipc_sock_accept_local(struct socket *sock, struct socket **newsock, | 93 | |
| 102 | int flags); | 94 | /* Broadcast link */ |
| 95 | struct tipc_bcbearer *bcbearer; | ||
| 96 | struct tipc_bclink *bclink; | ||
| 97 | struct tipc_link *bcl; | ||
| 98 | |||
| 99 | /* Socket hash table */ | ||
| 100 | struct rhashtable sk_rht; | ||
| 101 | |||
| 102 | /* Name table */ | ||
| 103 | spinlock_t nametbl_lock; | ||
| 104 | struct name_table *nametbl; | ||
| 105 | |||
| 106 | /* Topology subscription server */ | ||
| 107 | struct tipc_server *topsrv; | ||
| 108 | atomic_t subscription_count; | ||
| 109 | }; | ||
| 103 | 110 | ||
| 104 | #ifdef CONFIG_SYSCTL | 111 | #ifdef CONFIG_SYSCTL |
| 105 | int tipc_register_sysctl(void); | 112 | int tipc_register_sysctl(void); |
| @@ -109,101 +116,4 @@ void tipc_unregister_sysctl(void); | |||
| 109 | #define tipc_unregister_sysctl() | 116 | #define tipc_unregister_sysctl() |
| 110 | #endif | 117 | #endif |
| 111 | 118 | ||
| 112 | /* | ||
| 113 | * TIPC timer code | ||
| 114 | */ | ||
| 115 | typedef void (*Handler) (unsigned long); | ||
| 116 | |||
| 117 | /** | ||
| 118 | * k_init_timer - initialize a timer | ||
| 119 | * @timer: pointer to timer structure | ||
| 120 | * @routine: pointer to routine to invoke when timer expires | ||
| 121 | * @argument: value to pass to routine when timer expires | ||
| 122 | * | ||
| 123 | * Timer must be initialized before use (and terminated when no longer needed). | ||
| 124 | */ | ||
| 125 | static inline void k_init_timer(struct timer_list *timer, Handler routine, | ||
| 126 | unsigned long argument) | ||
| 127 | { | ||
| 128 | setup_timer(timer, routine, argument); | ||
| 129 | } | ||
| 130 | |||
| 131 | /** | ||
| 132 | * k_start_timer - start a timer | ||
| 133 | * @timer: pointer to timer structure | ||
| 134 | * @msec: time to delay (in ms) | ||
| 135 | * | ||
| 136 | * Schedules a previously initialized timer for later execution. | ||
| 137 | * If timer is already running, the new timeout overrides the previous request. | ||
| 138 | * | ||
| 139 | * To ensure the timer doesn't expire before the specified delay elapses, | ||
| 140 | * the amount of delay is rounded up when converting to the jiffies | ||
| 141 | * then an additional jiffy is added to account for the fact that | ||
| 142 | * the starting time may be in the middle of the current jiffy. | ||
| 143 | */ | ||
| 144 | static inline void k_start_timer(struct timer_list *timer, unsigned long msec) | ||
| 145 | { | ||
| 146 | mod_timer(timer, jiffies + msecs_to_jiffies(msec) + 1); | ||
| 147 | } | ||
| 148 | |||
| 149 | /** | ||
| 150 | * k_cancel_timer - cancel a timer | ||
| 151 | * @timer: pointer to timer structure | ||
| 152 | * | ||
| 153 | * Cancels a previously initialized timer. | ||
| 154 | * Can be called safely even if the timer is already inactive. | ||
| 155 | * | ||
| 156 | * WARNING: Must not be called when holding locks required by the timer's | ||
| 157 | * timeout routine, otherwise deadlock can occur on SMP systems! | ||
| 158 | */ | ||
| 159 | static inline void k_cancel_timer(struct timer_list *timer) | ||
| 160 | { | ||
| 161 | del_timer_sync(timer); | ||
| 162 | } | ||
| 163 | |||
| 164 | /** | ||
| 165 | * k_term_timer - terminate a timer | ||
| 166 | * @timer: pointer to timer structure | ||
| 167 | * | ||
| 168 | * Prevents further use of a previously initialized timer. | ||
| 169 | * | ||
| 170 | * WARNING: Caller must ensure timer isn't currently running. | ||
| 171 | * | ||
| 172 | * (Do not "enhance" this routine to automatically cancel an active timer, | ||
| 173 | * otherwise deadlock can arise when a timeout routine calls k_term_timer.) | ||
| 174 | */ | ||
| 175 | static inline void k_term_timer(struct timer_list *timer) | ||
| 176 | { | ||
| 177 | } | ||
| 178 | |||
| 179 | /* | ||
| 180 | * TIPC message buffer code | ||
| 181 | * | ||
| 182 | * TIPC message buffer headroom reserves space for the worst-case | ||
| 183 | * link-level device header (in case the message is sent off-node). | ||
| 184 | * | ||
| 185 | * Note: Headroom should be a multiple of 4 to ensure the TIPC header fields | ||
| 186 | * are word aligned for quicker access | ||
| 187 | */ | ||
| 188 | #define BUF_HEADROOM LL_MAX_HEADER | ||
| 189 | |||
| 190 | struct tipc_skb_cb { | ||
| 191 | void *handle; | ||
| 192 | struct sk_buff *tail; | ||
| 193 | bool deferred; | ||
| 194 | bool wakeup_pending; | ||
| 195 | bool bundling; | ||
| 196 | u16 chain_sz; | ||
| 197 | u16 chain_imp; | ||
| 198 | }; | ||
| 199 | |||
| 200 | #define TIPC_SKB_CB(__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0])) | ||
| 201 | |||
| 202 | static inline struct tipc_msg *buf_msg(struct sk_buff *skb) | ||
| 203 | { | ||
| 204 | return (struct tipc_msg *)skb->data; | ||
| 205 | } | ||
| 206 | |||
| 207 | struct sk_buff *tipc_buf_acquire(u32 size); | ||
| 208 | |||
| 209 | #endif | 119 | #endif |
diff --git a/net/tipc/discover.c b/net/tipc/discover.c index aa722a42ef8b..5b40cb89ff0a 100644 --- a/net/tipc/discover.c +++ b/net/tipc/discover.c | |||
| @@ -38,15 +38,20 @@ | |||
| 38 | #include "link.h" | 38 | #include "link.h" |
| 39 | #include "discover.h" | 39 | #include "discover.h" |
| 40 | 40 | ||
| 41 | #define TIPC_LINK_REQ_INIT 125 /* min delay during bearer start up */ | 41 | /* min delay during bearer start up */ |
| 42 | #define TIPC_LINK_REQ_FAST 1000 /* max delay if bearer has no links */ | 42 | #define TIPC_LINK_REQ_INIT msecs_to_jiffies(125) |
| 43 | #define TIPC_LINK_REQ_SLOW 60000 /* max delay if bearer has links */ | 43 | /* max delay if bearer has no links */ |
| 44 | #define TIPC_LINK_REQ_INACTIVE 0xffffffff /* indicates no timer in use */ | 44 | #define TIPC_LINK_REQ_FAST msecs_to_jiffies(1000) |
| 45 | /* max delay if bearer has links */ | ||
| 46 | #define TIPC_LINK_REQ_SLOW msecs_to_jiffies(60000) | ||
| 47 | /* indicates no timer in use */ | ||
| 48 | #define TIPC_LINK_REQ_INACTIVE 0xffffffff | ||
| 45 | 49 | ||
| 46 | 50 | ||
| 47 | /** | 51 | /** |
| 48 | * struct tipc_link_req - information about an ongoing link setup request | 52 | * struct tipc_link_req - information about an ongoing link setup request |
| 49 | * @bearer_id: identity of bearer issuing requests | 53 | * @bearer_id: identity of bearer issuing requests |
| 54 | * @net: network namespace instance | ||
| 50 | * @dest: destination address for request messages | 55 | * @dest: destination address for request messages |
| 51 | * @domain: network domain to which links can be established | 56 | * @domain: network domain to which links can be established |
| 52 | * @num_nodes: number of nodes currently discovered (i.e. with an active link) | 57 | * @num_nodes: number of nodes currently discovered (i.e. with an active link) |
| @@ -58,31 +63,34 @@ | |||
| 58 | struct tipc_link_req { | 63 | struct tipc_link_req { |
| 59 | u32 bearer_id; | 64 | u32 bearer_id; |
| 60 | struct tipc_media_addr dest; | 65 | struct tipc_media_addr dest; |
| 66 | struct net *net; | ||
| 61 | u32 domain; | 67 | u32 domain; |
| 62 | int num_nodes; | 68 | int num_nodes; |
| 63 | spinlock_t lock; | 69 | spinlock_t lock; |
| 64 | struct sk_buff *buf; | 70 | struct sk_buff *buf; |
| 65 | struct timer_list timer; | 71 | struct timer_list timer; |
| 66 | unsigned int timer_intv; | 72 | unsigned long timer_intv; |
| 67 | }; | 73 | }; |
| 68 | 74 | ||
| 69 | /** | 75 | /** |
| 70 | * tipc_disc_init_msg - initialize a link setup message | 76 | * tipc_disc_init_msg - initialize a link setup message |
| 77 | * @net: the applicable net namespace | ||
| 71 | * @type: message type (request or response) | 78 | * @type: message type (request or response) |
| 72 | * @b_ptr: ptr to bearer issuing message | 79 | * @b_ptr: ptr to bearer issuing message |
| 73 | */ | 80 | */ |
| 74 | static void tipc_disc_init_msg(struct sk_buff *buf, u32 type, | 81 | static void tipc_disc_init_msg(struct net *net, struct sk_buff *buf, u32 type, |
| 75 | struct tipc_bearer *b_ptr) | 82 | struct tipc_bearer *b_ptr) |
| 76 | { | 83 | { |
| 84 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 77 | struct tipc_msg *msg; | 85 | struct tipc_msg *msg; |
| 78 | u32 dest_domain = b_ptr->domain; | 86 | u32 dest_domain = b_ptr->domain; |
| 79 | 87 | ||
| 80 | msg = buf_msg(buf); | 88 | msg = buf_msg(buf); |
| 81 | tipc_msg_init(msg, LINK_CONFIG, type, INT_H_SIZE, dest_domain); | 89 | tipc_msg_init(net, msg, LINK_CONFIG, type, INT_H_SIZE, dest_domain); |
| 82 | msg_set_non_seq(msg, 1); | 90 | msg_set_non_seq(msg, 1); |
| 83 | msg_set_node_sig(msg, tipc_random); | 91 | msg_set_node_sig(msg, tn->random); |
| 84 | msg_set_dest_domain(msg, dest_domain); | 92 | msg_set_dest_domain(msg, dest_domain); |
| 85 | msg_set_bc_netid(msg, tipc_net_id); | 93 | msg_set_bc_netid(msg, tn->net_id); |
| 86 | b_ptr->media->addr2msg(msg_media_addr(msg), &b_ptr->addr); | 94 | b_ptr->media->addr2msg(msg_media_addr(msg), &b_ptr->addr); |
| 87 | } | 95 | } |
| 88 | 96 | ||
| @@ -107,11 +115,14 @@ static void disc_dupl_alert(struct tipc_bearer *b_ptr, u32 node_addr, | |||
| 107 | 115 | ||
| 108 | /** | 116 | /** |
| 109 | * tipc_disc_rcv - handle incoming discovery message (request or response) | 117 | * tipc_disc_rcv - handle incoming discovery message (request or response) |
| 118 | * @net: the applicable net namespace | ||
| 110 | * @buf: buffer containing message | 119 | * @buf: buffer containing message |
| 111 | * @bearer: bearer that message arrived on | 120 | * @bearer: bearer that message arrived on |
| 112 | */ | 121 | */ |
| 113 | void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | 122 | void tipc_disc_rcv(struct net *net, struct sk_buff *buf, |
| 123 | struct tipc_bearer *bearer) | ||
| 114 | { | 124 | { |
| 125 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 115 | struct tipc_node *node; | 126 | struct tipc_node *node; |
| 116 | struct tipc_link *link; | 127 | struct tipc_link *link; |
| 117 | struct tipc_media_addr maddr; | 128 | struct tipc_media_addr maddr; |
| @@ -133,7 +144,7 @@ void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | |||
| 133 | kfree_skb(buf); | 144 | kfree_skb(buf); |
| 134 | 145 | ||
| 135 | /* Ensure message from node is valid and communication is permitted */ | 146 | /* Ensure message from node is valid and communication is permitted */ |
| 136 | if (net_id != tipc_net_id) | 147 | if (net_id != tn->net_id) |
| 137 | return; | 148 | return; |
| 138 | if (maddr.broadcast) | 149 | if (maddr.broadcast) |
| 139 | return; | 150 | return; |
| @@ -142,20 +153,20 @@ void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | |||
| 142 | if (!tipc_addr_node_valid(onode)) | 153 | if (!tipc_addr_node_valid(onode)) |
| 143 | return; | 154 | return; |
| 144 | 155 | ||
| 145 | if (in_own_node(onode)) { | 156 | if (in_own_node(net, onode)) { |
| 146 | if (memcmp(&maddr, &bearer->addr, sizeof(maddr))) | 157 | if (memcmp(&maddr, &bearer->addr, sizeof(maddr))) |
| 147 | disc_dupl_alert(bearer, tipc_own_addr, &maddr); | 158 | disc_dupl_alert(bearer, tn->own_addr, &maddr); |
| 148 | return; | 159 | return; |
| 149 | } | 160 | } |
| 150 | if (!tipc_in_scope(ddom, tipc_own_addr)) | 161 | if (!tipc_in_scope(ddom, tn->own_addr)) |
| 151 | return; | 162 | return; |
| 152 | if (!tipc_in_scope(bearer->domain, onode)) | 163 | if (!tipc_in_scope(bearer->domain, onode)) |
| 153 | return; | 164 | return; |
| 154 | 165 | ||
| 155 | /* Locate, or if necessary, create, node: */ | 166 | /* Locate, or if necessary, create, node: */ |
| 156 | node = tipc_node_find(onode); | 167 | node = tipc_node_find(net, onode); |
| 157 | if (!node) | 168 | if (!node) |
| 158 | node = tipc_node_create(onode); | 169 | node = tipc_node_create(net, onode); |
| 159 | if (!node) | 170 | if (!node) |
| 160 | return; | 171 | return; |
| 161 | 172 | ||
| @@ -244,8 +255,8 @@ void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | |||
| 244 | if (respond && (mtyp == DSC_REQ_MSG)) { | 255 | if (respond && (mtyp == DSC_REQ_MSG)) { |
| 245 | rbuf = tipc_buf_acquire(INT_H_SIZE); | 256 | rbuf = tipc_buf_acquire(INT_H_SIZE); |
| 246 | if (rbuf) { | 257 | if (rbuf) { |
| 247 | tipc_disc_init_msg(rbuf, DSC_RESP_MSG, bearer); | 258 | tipc_disc_init_msg(net, rbuf, DSC_RESP_MSG, bearer); |
| 248 | tipc_bearer_send(bearer->identity, rbuf, &maddr); | 259 | tipc_bearer_send(net, bearer->identity, rbuf, &maddr); |
| 249 | kfree_skb(rbuf); | 260 | kfree_skb(rbuf); |
| 250 | } | 261 | } |
| 251 | } | 262 | } |
| @@ -265,7 +276,7 @@ static void disc_update(struct tipc_link_req *req) | |||
| 265 | if ((req->timer_intv == TIPC_LINK_REQ_INACTIVE) || | 276 | if ((req->timer_intv == TIPC_LINK_REQ_INACTIVE) || |
| 266 | (req->timer_intv > TIPC_LINK_REQ_FAST)) { | 277 | (req->timer_intv > TIPC_LINK_REQ_FAST)) { |
| 267 | req->timer_intv = TIPC_LINK_REQ_INIT; | 278 | req->timer_intv = TIPC_LINK_REQ_INIT; |
| 268 | k_start_timer(&req->timer, req->timer_intv); | 279 | mod_timer(&req->timer, jiffies + req->timer_intv); |
| 269 | } | 280 | } |
| 270 | } | 281 | } |
| 271 | } | 282 | } |
| @@ -295,12 +306,13 @@ void tipc_disc_remove_dest(struct tipc_link_req *req) | |||
| 295 | 306 | ||
| 296 | /** | 307 | /** |
| 297 | * disc_timeout - send a periodic link setup request | 308 | * disc_timeout - send a periodic link setup request |
| 298 | * @req: ptr to link request structure | 309 | * @data: ptr to link request structure |
| 299 | * | 310 | * |
| 300 | * Called whenever a link setup request timer associated with a bearer expires. | 311 | * Called whenever a link setup request timer associated with a bearer expires. |
| 301 | */ | 312 | */ |
| 302 | static void disc_timeout(struct tipc_link_req *req) | 313 | static void disc_timeout(unsigned long data) |
| 303 | { | 314 | { |
| 315 | struct tipc_link_req *req = (struct tipc_link_req *)data; | ||
| 304 | int max_delay; | 316 | int max_delay; |
| 305 | 317 | ||
| 306 | spin_lock_bh(&req->lock); | 318 | spin_lock_bh(&req->lock); |
| @@ -318,7 +330,7 @@ static void disc_timeout(struct tipc_link_req *req) | |||
| 318 | * hold at fast polling rate if don't have any associated nodes, | 330 | * hold at fast polling rate if don't have any associated nodes, |
| 319 | * otherwise hold at slow polling rate | 331 | * otherwise hold at slow polling rate |
| 320 | */ | 332 | */ |
| 321 | tipc_bearer_send(req->bearer_id, req->buf, &req->dest); | 333 | tipc_bearer_send(req->net, req->bearer_id, req->buf, &req->dest); |
| 322 | 334 | ||
| 323 | 335 | ||
| 324 | req->timer_intv *= 2; | 336 | req->timer_intv *= 2; |
| @@ -329,20 +341,22 @@ static void disc_timeout(struct tipc_link_req *req) | |||
| 329 | if (req->timer_intv > max_delay) | 341 | if (req->timer_intv > max_delay) |
| 330 | req->timer_intv = max_delay; | 342 | req->timer_intv = max_delay; |
| 331 | 343 | ||
| 332 | k_start_timer(&req->timer, req->timer_intv); | 344 | mod_timer(&req->timer, jiffies + req->timer_intv); |
| 333 | exit: | 345 | exit: |
| 334 | spin_unlock_bh(&req->lock); | 346 | spin_unlock_bh(&req->lock); |
| 335 | } | 347 | } |
| 336 | 348 | ||
| 337 | /** | 349 | /** |
| 338 | * tipc_disc_create - create object to send periodic link setup requests | 350 | * tipc_disc_create - create object to send periodic link setup requests |
| 351 | * @net: the applicable net namespace | ||
| 339 | * @b_ptr: ptr to bearer issuing requests | 352 | * @b_ptr: ptr to bearer issuing requests |
| 340 | * @dest: destination address for request messages | 353 | * @dest: destination address for request messages |
| 341 | * @dest_domain: network domain to which links can be established | 354 | * @dest_domain: network domain to which links can be established |
| 342 | * | 355 | * |
| 343 | * Returns 0 if successful, otherwise -errno. | 356 | * Returns 0 if successful, otherwise -errno. |
| 344 | */ | 357 | */ |
| 345 | int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest) | 358 | int tipc_disc_create(struct net *net, struct tipc_bearer *b_ptr, |
| 359 | struct tipc_media_addr *dest) | ||
| 346 | { | 360 | { |
| 347 | struct tipc_link_req *req; | 361 | struct tipc_link_req *req; |
| 348 | 362 | ||
| @@ -356,17 +370,18 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest) | |||
| 356 | return -ENOMEM; | 370 | return -ENOMEM; |
| 357 | } | 371 | } |
| 358 | 372 | ||
| 359 | tipc_disc_init_msg(req->buf, DSC_REQ_MSG, b_ptr); | 373 | tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b_ptr); |
| 360 | memcpy(&req->dest, dest, sizeof(*dest)); | 374 | memcpy(&req->dest, dest, sizeof(*dest)); |
| 375 | req->net = net; | ||
| 361 | req->bearer_id = b_ptr->identity; | 376 | req->bearer_id = b_ptr->identity; |
| 362 | req->domain = b_ptr->domain; | 377 | req->domain = b_ptr->domain; |
| 363 | req->num_nodes = 0; | 378 | req->num_nodes = 0; |
| 364 | req->timer_intv = TIPC_LINK_REQ_INIT; | 379 | req->timer_intv = TIPC_LINK_REQ_INIT; |
| 365 | spin_lock_init(&req->lock); | 380 | spin_lock_init(&req->lock); |
| 366 | k_init_timer(&req->timer, (Handler)disc_timeout, (unsigned long)req); | 381 | setup_timer(&req->timer, disc_timeout, (unsigned long)req); |
| 367 | k_start_timer(&req->timer, req->timer_intv); | 382 | mod_timer(&req->timer, jiffies + req->timer_intv); |
| 368 | b_ptr->link_req = req; | 383 | b_ptr->link_req = req; |
| 369 | tipc_bearer_send(req->bearer_id, req->buf, &req->dest); | 384 | tipc_bearer_send(net, req->bearer_id, req->buf, &req->dest); |
| 370 | return 0; | 385 | return 0; |
| 371 | } | 386 | } |
| 372 | 387 | ||
| @@ -376,28 +391,29 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest) | |||
| 376 | */ | 391 | */ |
| 377 | void tipc_disc_delete(struct tipc_link_req *req) | 392 | void tipc_disc_delete(struct tipc_link_req *req) |
| 378 | { | 393 | { |
| 379 | k_cancel_timer(&req->timer); | 394 | del_timer_sync(&req->timer); |
| 380 | k_term_timer(&req->timer); | ||
| 381 | kfree_skb(req->buf); | 395 | kfree_skb(req->buf); |
| 382 | kfree(req); | 396 | kfree(req); |
| 383 | } | 397 | } |
| 384 | 398 | ||
| 385 | /** | 399 | /** |
| 386 | * tipc_disc_reset - reset object to send periodic link setup requests | 400 | * tipc_disc_reset - reset object to send periodic link setup requests |
| 401 | * @net: the applicable net namespace | ||
| 387 | * @b_ptr: ptr to bearer issuing requests | 402 | * @b_ptr: ptr to bearer issuing requests |
| 388 | * @dest_domain: network domain to which links can be established | 403 | * @dest_domain: network domain to which links can be established |
| 389 | */ | 404 | */ |
| 390 | void tipc_disc_reset(struct tipc_bearer *b_ptr) | 405 | void tipc_disc_reset(struct net *net, struct tipc_bearer *b_ptr) |
| 391 | { | 406 | { |
| 392 | struct tipc_link_req *req = b_ptr->link_req; | 407 | struct tipc_link_req *req = b_ptr->link_req; |
| 393 | 408 | ||
| 394 | spin_lock_bh(&req->lock); | 409 | spin_lock_bh(&req->lock); |
| 395 | tipc_disc_init_msg(req->buf, DSC_REQ_MSG, b_ptr); | 410 | tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b_ptr); |
| 411 | req->net = net; | ||
| 396 | req->bearer_id = b_ptr->identity; | 412 | req->bearer_id = b_ptr->identity; |
| 397 | req->domain = b_ptr->domain; | 413 | req->domain = b_ptr->domain; |
| 398 | req->num_nodes = 0; | 414 | req->num_nodes = 0; |
| 399 | req->timer_intv = TIPC_LINK_REQ_INIT; | 415 | req->timer_intv = TIPC_LINK_REQ_INIT; |
| 400 | k_start_timer(&req->timer, req->timer_intv); | 416 | mod_timer(&req->timer, jiffies + req->timer_intv); |
| 401 | tipc_bearer_send(req->bearer_id, req->buf, &req->dest); | 417 | tipc_bearer_send(net, req->bearer_id, req->buf, &req->dest); |
| 402 | spin_unlock_bh(&req->lock); | 418 | spin_unlock_bh(&req->lock); |
| 403 | } | 419 | } |
diff --git a/net/tipc/discover.h b/net/tipc/discover.h index 515b57392f4d..c9b12770c5ed 100644 --- a/net/tipc/discover.h +++ b/net/tipc/discover.h | |||
| @@ -39,11 +39,13 @@ | |||
| 39 | 39 | ||
| 40 | struct tipc_link_req; | 40 | struct tipc_link_req; |
| 41 | 41 | ||
| 42 | int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest); | 42 | int tipc_disc_create(struct net *net, struct tipc_bearer *b_ptr, |
| 43 | struct tipc_media_addr *dest); | ||
| 43 | void tipc_disc_delete(struct tipc_link_req *req); | 44 | void tipc_disc_delete(struct tipc_link_req *req); |
| 44 | void tipc_disc_reset(struct tipc_bearer *b_ptr); | 45 | void tipc_disc_reset(struct net *net, struct tipc_bearer *b_ptr); |
| 45 | void tipc_disc_add_dest(struct tipc_link_req *req); | 46 | void tipc_disc_add_dest(struct tipc_link_req *req); |
| 46 | void tipc_disc_remove_dest(struct tipc_link_req *req); | 47 | void tipc_disc_remove_dest(struct tipc_link_req *req); |
| 47 | void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *b_ptr); | 48 | void tipc_disc_rcv(struct net *net, struct sk_buff *buf, |
| 49 | struct tipc_bearer *b_ptr); | ||
| 48 | 50 | ||
| 49 | #endif | 51 | #endif |
diff --git a/net/tipc/link.c b/net/tipc/link.c index 23bcc1132365..2846ad802e43 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c | |||
| @@ -101,19 +101,23 @@ static const struct nla_policy tipc_nl_prop_policy[TIPC_NLA_PROP_MAX + 1] = { | |||
| 101 | */ | 101 | */ |
| 102 | #define START_CHANGEOVER 100000u | 102 | #define START_CHANGEOVER 100000u |
| 103 | 103 | ||
| 104 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, | 104 | static void link_handle_out_of_seq_msg(struct net *net, |
| 105 | struct tipc_link *l_ptr, | ||
| 105 | struct sk_buff *buf); | 106 | struct sk_buff *buf); |
| 106 | static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf); | 107 | static void tipc_link_proto_rcv(struct net *net, struct tipc_link *l_ptr, |
| 107 | static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr, | 108 | struct sk_buff *buf); |
| 109 | static int tipc_link_tunnel_rcv(struct net *net, struct tipc_node *n_ptr, | ||
| 108 | struct sk_buff **buf); | 110 | struct sk_buff **buf); |
| 109 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance); | 111 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tol); |
| 110 | static void link_state_event(struct tipc_link *l_ptr, u32 event); | 112 | static void link_state_event(struct tipc_link *l_ptr, u32 event); |
| 111 | static void link_reset_statistics(struct tipc_link *l_ptr); | 113 | static void link_reset_statistics(struct tipc_link *l_ptr); |
| 112 | static void link_print(struct tipc_link *l_ptr, const char *str); | 114 | static void link_print(struct tipc_link *l_ptr, const char *str); |
| 113 | static void tipc_link_sync_xmit(struct tipc_link *l); | 115 | static void tipc_link_sync_xmit(struct tipc_link *l); |
| 114 | static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf); | 116 | static void tipc_link_sync_rcv(struct tipc_node *n, struct sk_buff *buf); |
| 115 | static int tipc_link_input(struct tipc_link *l, struct sk_buff *buf); | 117 | static int tipc_link_input(struct net *net, struct tipc_link *l, |
| 116 | static int tipc_link_prepare_input(struct tipc_link *l, struct sk_buff **buf); | 118 | struct sk_buff *buf); |
| 119 | static int tipc_link_prepare_input(struct net *net, struct tipc_link *l, | ||
| 120 | struct sk_buff **buf); | ||
| 117 | 121 | ||
| 118 | /* | 122 | /* |
| 119 | * Simple link routines | 123 | * Simple link routines |
| @@ -125,11 +129,13 @@ static unsigned int align(unsigned int i) | |||
| 125 | 129 | ||
| 126 | static void link_init_max_pkt(struct tipc_link *l_ptr) | 130 | static void link_init_max_pkt(struct tipc_link *l_ptr) |
| 127 | { | 131 | { |
| 132 | struct tipc_node *node = l_ptr->owner; | ||
| 133 | struct tipc_net *tn = net_generic(node->net, tipc_net_id); | ||
| 128 | struct tipc_bearer *b_ptr; | 134 | struct tipc_bearer *b_ptr; |
| 129 | u32 max_pkt; | 135 | u32 max_pkt; |
| 130 | 136 | ||
| 131 | rcu_read_lock(); | 137 | rcu_read_lock(); |
| 132 | b_ptr = rcu_dereference_rtnl(bearer_list[l_ptr->bearer_id]); | 138 | b_ptr = rcu_dereference_rtnl(tn->bearer_list[l_ptr->bearer_id]); |
| 133 | if (!b_ptr) { | 139 | if (!b_ptr) { |
| 134 | rcu_read_unlock(); | 140 | rcu_read_unlock(); |
| 135 | return; | 141 | return; |
| @@ -169,8 +175,9 @@ int tipc_link_is_active(struct tipc_link *l_ptr) | |||
| 169 | * link_timeout - handle expiration of link timer | 175 | * link_timeout - handle expiration of link timer |
| 170 | * @l_ptr: pointer to link | 176 | * @l_ptr: pointer to link |
| 171 | */ | 177 | */ |
| 172 | static void link_timeout(struct tipc_link *l_ptr) | 178 | static void link_timeout(unsigned long data) |
| 173 | { | 179 | { |
| 180 | struct tipc_link *l_ptr = (struct tipc_link *)data; | ||
| 174 | struct sk_buff *skb; | 181 | struct sk_buff *skb; |
| 175 | 182 | ||
| 176 | tipc_node_lock(l_ptr->owner); | 183 | tipc_node_lock(l_ptr->owner); |
| @@ -217,9 +224,9 @@ static void link_timeout(struct tipc_link *l_ptr) | |||
| 217 | tipc_node_unlock(l_ptr->owner); | 224 | tipc_node_unlock(l_ptr->owner); |
| 218 | } | 225 | } |
| 219 | 226 | ||
| 220 | static void link_set_timer(struct tipc_link *l_ptr, u32 time) | 227 | static void link_set_timer(struct tipc_link *link, unsigned long time) |
| 221 | { | 228 | { |
| 222 | k_start_timer(&l_ptr->timer, time); | 229 | mod_timer(&link->timer, jiffies + time); |
| 223 | } | 230 | } |
| 224 | 231 | ||
| 225 | /** | 232 | /** |
| @@ -234,6 +241,7 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, | |||
| 234 | struct tipc_bearer *b_ptr, | 241 | struct tipc_bearer *b_ptr, |
| 235 | const struct tipc_media_addr *media_addr) | 242 | const struct tipc_media_addr *media_addr) |
| 236 | { | 243 | { |
| 244 | struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id); | ||
| 237 | struct tipc_link *l_ptr; | 245 | struct tipc_link *l_ptr; |
| 238 | struct tipc_msg *msg; | 246 | struct tipc_msg *msg; |
| 239 | char *if_name; | 247 | char *if_name; |
| @@ -263,8 +271,8 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, | |||
| 263 | l_ptr->addr = peer; | 271 | l_ptr->addr = peer; |
| 264 | if_name = strchr(b_ptr->name, ':') + 1; | 272 | if_name = strchr(b_ptr->name, ':') + 1; |
| 265 | sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown", | 273 | sprintf(l_ptr->name, "%u.%u.%u:%s-%u.%u.%u:unknown", |
| 266 | tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), | 274 | tipc_zone(tn->own_addr), tipc_cluster(tn->own_addr), |
| 267 | tipc_node(tipc_own_addr), | 275 | tipc_node(tn->own_addr), |
| 268 | if_name, | 276 | if_name, |
| 269 | tipc_zone(peer), tipc_cluster(peer), tipc_node(peer)); | 277 | tipc_zone(peer), tipc_cluster(peer), tipc_node(peer)); |
| 270 | /* note: peer i/f name is updated by reset/activate message */ | 278 | /* note: peer i/f name is updated by reset/activate message */ |
| @@ -278,9 +286,10 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, | |||
| 278 | 286 | ||
| 279 | l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg; | 287 | l_ptr->pmsg = (struct tipc_msg *)&l_ptr->proto_msg; |
| 280 | msg = l_ptr->pmsg; | 288 | msg = l_ptr->pmsg; |
| 281 | tipc_msg_init(msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, l_ptr->addr); | 289 | tipc_msg_init(n_ptr->net, msg, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, |
| 290 | l_ptr->addr); | ||
| 282 | msg_set_size(msg, sizeof(l_ptr->proto_msg)); | 291 | msg_set_size(msg, sizeof(l_ptr->proto_msg)); |
| 283 | msg_set_session(msg, (tipc_random & 0xffff)); | 292 | msg_set_session(msg, (tn->random & 0xffff)); |
| 284 | msg_set_bearer_id(msg, b_ptr->identity); | 293 | msg_set_bearer_id(msg, b_ptr->identity); |
| 285 | strcpy((char *)msg_data(msg), if_name); | 294 | strcpy((char *)msg_data(msg), if_name); |
| 286 | 295 | ||
| @@ -299,21 +308,22 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, | |||
| 299 | 308 | ||
| 300 | tipc_node_attach_link(n_ptr, l_ptr); | 309 | tipc_node_attach_link(n_ptr, l_ptr); |
| 301 | 310 | ||
| 302 | k_init_timer(&l_ptr->timer, (Handler)link_timeout, | 311 | setup_timer(&l_ptr->timer, link_timeout, (unsigned long)l_ptr); |
| 303 | (unsigned long)l_ptr); | ||
| 304 | 312 | ||
| 305 | link_state_event(l_ptr, STARTING_EVT); | 313 | link_state_event(l_ptr, STARTING_EVT); |
| 306 | 314 | ||
| 307 | return l_ptr; | 315 | return l_ptr; |
| 308 | } | 316 | } |
| 309 | 317 | ||
| 310 | void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down) | 318 | void tipc_link_delete_list(struct net *net, unsigned int bearer_id, |
| 319 | bool shutting_down) | ||
| 311 | { | 320 | { |
| 321 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 312 | struct tipc_link *l_ptr; | 322 | struct tipc_link *l_ptr; |
| 313 | struct tipc_node *n_ptr; | 323 | struct tipc_node *n_ptr; |
| 314 | 324 | ||
| 315 | rcu_read_lock(); | 325 | rcu_read_lock(); |
| 316 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | 326 | list_for_each_entry_rcu(n_ptr, &tn->node_list, list) { |
| 317 | tipc_node_lock(n_ptr); | 327 | tipc_node_lock(n_ptr); |
| 318 | l_ptr = n_ptr->links[bearer_id]; | 328 | l_ptr = n_ptr->links[bearer_id]; |
| 319 | if (l_ptr) { | 329 | if (l_ptr) { |
| @@ -350,10 +360,12 @@ void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down) | |||
| 350 | static bool link_schedule_user(struct tipc_link *link, u32 oport, | 360 | static bool link_schedule_user(struct tipc_link *link, u32 oport, |
| 351 | uint chain_sz, uint imp) | 361 | uint chain_sz, uint imp) |
| 352 | { | 362 | { |
| 363 | struct net *net = link->owner->net; | ||
| 364 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 353 | struct sk_buff *buf; | 365 | struct sk_buff *buf; |
| 354 | 366 | ||
| 355 | buf = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0, tipc_own_addr, | 367 | buf = tipc_msg_create(net, SOCK_WAKEUP, 0, INT_H_SIZE, 0, tn->own_addr, |
| 356 | tipc_own_addr, oport, 0, 0); | 368 | tn->own_addr, oport, 0, 0); |
| 357 | if (!buf) | 369 | if (!buf) |
| 358 | return false; | 370 | return false; |
| 359 | TIPC_SKB_CB(buf)->chain_sz = chain_sz; | 371 | TIPC_SKB_CB(buf)->chain_sz = chain_sz; |
| @@ -425,7 +437,7 @@ void tipc_link_reset(struct tipc_link *l_ptr) | |||
| 425 | return; | 437 | return; |
| 426 | 438 | ||
| 427 | tipc_node_link_down(l_ptr->owner, l_ptr); | 439 | tipc_node_link_down(l_ptr->owner, l_ptr); |
| 428 | tipc_bearer_remove_dest(l_ptr->bearer_id, l_ptr->addr); | 440 | tipc_bearer_remove_dest(owner->net, l_ptr->bearer_id, l_ptr->addr); |
| 429 | 441 | ||
| 430 | if (was_active_link && tipc_node_active_links(l_ptr->owner)) { | 442 | if (was_active_link && tipc_node_active_links(l_ptr->owner)) { |
| 431 | l_ptr->reset_checkpoint = checkpoint; | 443 | l_ptr->reset_checkpoint = checkpoint; |
| @@ -448,13 +460,14 @@ void tipc_link_reset(struct tipc_link *l_ptr) | |||
| 448 | link_reset_statistics(l_ptr); | 460 | link_reset_statistics(l_ptr); |
| 449 | } | 461 | } |
| 450 | 462 | ||
| 451 | void tipc_link_reset_list(unsigned int bearer_id) | 463 | void tipc_link_reset_list(struct net *net, unsigned int bearer_id) |
| 452 | { | 464 | { |
| 465 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 453 | struct tipc_link *l_ptr; | 466 | struct tipc_link *l_ptr; |
| 454 | struct tipc_node *n_ptr; | 467 | struct tipc_node *n_ptr; |
| 455 | 468 | ||
| 456 | rcu_read_lock(); | 469 | rcu_read_lock(); |
| 457 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | 470 | list_for_each_entry_rcu(n_ptr, &tn->node_list, list) { |
| 458 | tipc_node_lock(n_ptr); | 471 | tipc_node_lock(n_ptr); |
| 459 | l_ptr = n_ptr->links[bearer_id]; | 472 | l_ptr = n_ptr->links[bearer_id]; |
| 460 | if (l_ptr) | 473 | if (l_ptr) |
| @@ -464,11 +477,14 @@ void tipc_link_reset_list(unsigned int bearer_id) | |||
| 464 | rcu_read_unlock(); | 477 | rcu_read_unlock(); |
| 465 | } | 478 | } |
| 466 | 479 | ||
| 467 | static void link_activate(struct tipc_link *l_ptr) | 480 | static void link_activate(struct tipc_link *link) |
| 468 | { | 481 | { |
| 469 | l_ptr->next_in_no = l_ptr->stats.recv_info = 1; | 482 | struct tipc_node *node = link->owner; |
| 470 | tipc_node_link_up(l_ptr->owner, l_ptr); | 483 | |
| 471 | tipc_bearer_add_dest(l_ptr->bearer_id, l_ptr->addr); | 484 | link->next_in_no = 1; |
| 485 | link->stats.recv_info = 1; | ||
| 486 | tipc_node_link_up(node, link); | ||
| 487 | tipc_bearer_add_dest(node->net, link->bearer_id, link->addr); | ||
| 472 | } | 488 | } |
| 473 | 489 | ||
| 474 | /** | 490 | /** |
| @@ -479,7 +495,7 @@ static void link_activate(struct tipc_link *l_ptr) | |||
| 479 | static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | 495 | static void link_state_event(struct tipc_link *l_ptr, unsigned int event) |
| 480 | { | 496 | { |
| 481 | struct tipc_link *other; | 497 | struct tipc_link *other; |
| 482 | u32 cont_intv = l_ptr->continuity_interval; | 498 | unsigned long cont_intv = l_ptr->cont_intv; |
| 483 | 499 | ||
| 484 | if (l_ptr->flags & LINK_STOPPED) | 500 | if (l_ptr->flags & LINK_STOPPED) |
| 485 | return; | 501 | return; |
| @@ -522,8 +538,8 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 522 | link_set_timer(l_ptr, cont_intv / 4); | 538 | link_set_timer(l_ptr, cont_intv / 4); |
| 523 | break; | 539 | break; |
| 524 | case RESET_MSG: | 540 | case RESET_MSG: |
| 525 | pr_info("%s<%s>, requested by peer\n", link_rst_msg, | 541 | pr_debug("%s<%s>, requested by peer\n", |
| 526 | l_ptr->name); | 542 | link_rst_msg, l_ptr->name); |
| 527 | tipc_link_reset(l_ptr); | 543 | tipc_link_reset(l_ptr); |
| 528 | l_ptr->state = RESET_RESET; | 544 | l_ptr->state = RESET_RESET; |
| 529 | l_ptr->fsm_msg_cnt = 0; | 545 | l_ptr->fsm_msg_cnt = 0; |
| @@ -533,7 +549,7 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 533 | link_set_timer(l_ptr, cont_intv); | 549 | link_set_timer(l_ptr, cont_intv); |
| 534 | break; | 550 | break; |
| 535 | default: | 551 | default: |
| 536 | pr_err("%s%u in WW state\n", link_unk_evt, event); | 552 | pr_debug("%s%u in WW state\n", link_unk_evt, event); |
| 537 | } | 553 | } |
| 538 | break; | 554 | break; |
| 539 | case WORKING_UNKNOWN: | 555 | case WORKING_UNKNOWN: |
| @@ -545,8 +561,8 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 545 | link_set_timer(l_ptr, cont_intv); | 561 | link_set_timer(l_ptr, cont_intv); |
| 546 | break; | 562 | break; |
| 547 | case RESET_MSG: | 563 | case RESET_MSG: |
| 548 | pr_info("%s<%s>, requested by peer while probing\n", | 564 | pr_debug("%s<%s>, requested by peer while probing\n", |
| 549 | link_rst_msg, l_ptr->name); | 565 | link_rst_msg, l_ptr->name); |
| 550 | tipc_link_reset(l_ptr); | 566 | tipc_link_reset(l_ptr); |
| 551 | l_ptr->state = RESET_RESET; | 567 | l_ptr->state = RESET_RESET; |
| 552 | l_ptr->fsm_msg_cnt = 0; | 568 | l_ptr->fsm_msg_cnt = 0; |
| @@ -572,8 +588,8 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event) | |||
| 572 | l_ptr->fsm_msg_cnt++; | 588 | l_ptr->fsm_msg_cnt++; |
| 573 | link_set_timer(l_ptr, cont_intv / 4); | 589 | link_set_timer(l_ptr, cont_intv / 4); |
| 574 | } else { /* Link has failed */ | 590 | } else { /* Link has failed */ |
| 575 | pr_warn("%s<%s>, peer not responding\n", | 591 | pr_debug("%s<%s>, peer not responding\n", |
| 576 | link_rst_msg, l_ptr->name); | 592 | link_rst_msg, l_ptr->name); |
| 577 | tipc_link_reset(l_ptr); | 593 | tipc_link_reset(l_ptr); |
| 578 | l_ptr->state = RESET_UNKNOWN; | 594 | l_ptr->state = RESET_UNKNOWN; |
| 579 | l_ptr->fsm_msg_cnt = 0; | 595 | l_ptr->fsm_msg_cnt = 0; |
| @@ -700,7 +716,8 @@ drop: | |||
| 700 | * Only the socket functions tipc_send_stream() and tipc_send_packet() need | 716 | * Only the socket functions tipc_send_stream() and tipc_send_packet() need |
| 701 | * to act on the return value, since they may need to do more send attempts. | 717 | * to act on the return value, since they may need to do more send attempts. |
| 702 | */ | 718 | */ |
| 703 | int __tipc_link_xmit(struct tipc_link *link, struct sk_buff_head *list) | 719 | int __tipc_link_xmit(struct net *net, struct tipc_link *link, |
| 720 | struct sk_buff_head *list) | ||
| 704 | { | 721 | { |
| 705 | struct tipc_msg *msg = buf_msg(skb_peek(list)); | 722 | struct tipc_msg *msg = buf_msg(skb_peek(list)); |
| 706 | uint psz = msg_size(msg); | 723 | uint psz = msg_size(msg); |
| @@ -733,13 +750,14 @@ int __tipc_link_xmit(struct tipc_link *link, struct sk_buff_head *list) | |||
| 733 | 750 | ||
| 734 | if (skb_queue_len(outqueue) < sndlim) { | 751 | if (skb_queue_len(outqueue) < sndlim) { |
| 735 | __skb_queue_tail(outqueue, skb); | 752 | __skb_queue_tail(outqueue, skb); |
| 736 | tipc_bearer_send(link->bearer_id, skb, addr); | 753 | tipc_bearer_send(net, link->bearer_id, |
| 754 | skb, addr); | ||
| 737 | link->next_out = NULL; | 755 | link->next_out = NULL; |
| 738 | link->unacked_window = 0; | 756 | link->unacked_window = 0; |
| 739 | } else if (tipc_msg_bundle(outqueue, skb, mtu)) { | 757 | } else if (tipc_msg_bundle(outqueue, skb, mtu)) { |
| 740 | link->stats.sent_bundled++; | 758 | link->stats.sent_bundled++; |
| 741 | continue; | 759 | continue; |
| 742 | } else if (tipc_msg_make_bundle(outqueue, skb, mtu, | 760 | } else if (tipc_msg_make_bundle(net, outqueue, skb, mtu, |
| 743 | link->addr)) { | 761 | link->addr)) { |
| 744 | link->stats.sent_bundled++; | 762 | link->stats.sent_bundled++; |
| 745 | link->stats.sent_bundles++; | 763 | link->stats.sent_bundles++; |
| @@ -767,19 +785,21 @@ static int __tipc_link_xmit_skb(struct tipc_link *link, struct sk_buff *skb) | |||
| 767 | struct sk_buff_head head; | 785 | struct sk_buff_head head; |
| 768 | 786 | ||
| 769 | skb2list(skb, &head); | 787 | skb2list(skb, &head); |
| 770 | return __tipc_link_xmit(link, &head); | 788 | return __tipc_link_xmit(link->owner->net, link, &head); |
| 771 | } | 789 | } |
| 772 | 790 | ||
| 773 | int tipc_link_xmit_skb(struct sk_buff *skb, u32 dnode, u32 selector) | 791 | int tipc_link_xmit_skb(struct net *net, struct sk_buff *skb, u32 dnode, |
| 792 | u32 selector) | ||
| 774 | { | 793 | { |
| 775 | struct sk_buff_head head; | 794 | struct sk_buff_head head; |
| 776 | 795 | ||
| 777 | skb2list(skb, &head); | 796 | skb2list(skb, &head); |
| 778 | return tipc_link_xmit(&head, dnode, selector); | 797 | return tipc_link_xmit(net, &head, dnode, selector); |
| 779 | } | 798 | } |
| 780 | 799 | ||
| 781 | /** | 800 | /** |
| 782 | * tipc_link_xmit() is the general link level function for message sending | 801 | * tipc_link_xmit() is the general link level function for message sending |
| 802 | * @net: the applicable net namespace | ||
| 783 | * @list: chain of buffers containing message | 803 | * @list: chain of buffers containing message |
| 784 | * @dsz: amount of user data to be sent | 804 | * @dsz: amount of user data to be sent |
| 785 | * @dnode: address of destination node | 805 | * @dnode: address of destination node |
| @@ -787,30 +807,31 @@ int tipc_link_xmit_skb(struct sk_buff *skb, u32 dnode, u32 selector) | |||
| 787 | * Consumes the buffer chain, except when returning -ELINKCONG | 807 | * Consumes the buffer chain, except when returning -ELINKCONG |
| 788 | * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE | 808 | * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE |
| 789 | */ | 809 | */ |
| 790 | int tipc_link_xmit(struct sk_buff_head *list, u32 dnode, u32 selector) | 810 | int tipc_link_xmit(struct net *net, struct sk_buff_head *list, u32 dnode, |
| 811 | u32 selector) | ||
| 791 | { | 812 | { |
| 792 | struct tipc_link *link = NULL; | 813 | struct tipc_link *link = NULL; |
| 793 | struct tipc_node *node; | 814 | struct tipc_node *node; |
| 794 | int rc = -EHOSTUNREACH; | 815 | int rc = -EHOSTUNREACH; |
| 795 | 816 | ||
| 796 | node = tipc_node_find(dnode); | 817 | node = tipc_node_find(net, dnode); |
| 797 | if (node) { | 818 | if (node) { |
| 798 | tipc_node_lock(node); | 819 | tipc_node_lock(node); |
| 799 | link = node->active_links[selector & 1]; | 820 | link = node->active_links[selector & 1]; |
| 800 | if (link) | 821 | if (link) |
| 801 | rc = __tipc_link_xmit(link, list); | 822 | rc = __tipc_link_xmit(net, link, list); |
| 802 | tipc_node_unlock(node); | 823 | tipc_node_unlock(node); |
| 803 | } | 824 | } |
| 804 | 825 | ||
| 805 | if (link) | 826 | if (link) |
| 806 | return rc; | 827 | return rc; |
| 807 | 828 | ||
| 808 | if (likely(in_own_node(dnode))) { | 829 | if (likely(in_own_node(net, dnode))) { |
| 809 | /* As a node local message chain never contains more than one | 830 | /* As a node local message chain never contains more than one |
| 810 | * buffer, we just need to dequeue one SKB buffer from the | 831 | * buffer, we just need to dequeue one SKB buffer from the |
| 811 | * head list. | 832 | * head list. |
| 812 | */ | 833 | */ |
| 813 | return tipc_sk_rcv(__skb_dequeue(list)); | 834 | return tipc_sk_rcv(net, __skb_dequeue(list)); |
| 814 | } | 835 | } |
| 815 | __skb_queue_purge(list); | 836 | __skb_queue_purge(list); |
| 816 | 837 | ||
| @@ -835,7 +856,8 @@ static void tipc_link_sync_xmit(struct tipc_link *link) | |||
| 835 | return; | 856 | return; |
| 836 | 857 | ||
| 837 | msg = buf_msg(skb); | 858 | msg = buf_msg(skb); |
| 838 | tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE, link->addr); | 859 | tipc_msg_init(link->owner->net, msg, BCAST_PROTOCOL, STATE_MSG, |
| 860 | INT_H_SIZE, link->addr); | ||
| 839 | msg_set_last_bcast(msg, link->owner->bclink.acked); | 861 | msg_set_last_bcast(msg, link->owner->bclink.acked); |
| 840 | __tipc_link_xmit_skb(link, skb); | 862 | __tipc_link_xmit_skb(link, skb); |
| 841 | } | 863 | } |
| @@ -890,7 +912,8 @@ void tipc_link_push_packets(struct tipc_link *l_ptr) | |||
| 890 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); | 912 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
| 891 | if (msg_user(msg) == MSG_BUNDLER) | 913 | if (msg_user(msg) == MSG_BUNDLER) |
| 892 | TIPC_SKB_CB(skb)->bundling = false; | 914 | TIPC_SKB_CB(skb)->bundling = false; |
| 893 | tipc_bearer_send(l_ptr->bearer_id, skb, | 915 | tipc_bearer_send(l_ptr->owner->net, |
| 916 | l_ptr->bearer_id, skb, | ||
| 894 | &l_ptr->media_addr); | 917 | &l_ptr->media_addr); |
| 895 | l_ptr->next_out = tipc_skb_queue_next(outqueue, skb); | 918 | l_ptr->next_out = tipc_skb_queue_next(outqueue, skb); |
| 896 | } else { | 919 | } else { |
| @@ -923,6 +946,7 @@ static void link_retransmit_failure(struct tipc_link *l_ptr, | |||
| 923 | struct sk_buff *buf) | 946 | struct sk_buff *buf) |
| 924 | { | 947 | { |
| 925 | struct tipc_msg *msg = buf_msg(buf); | 948 | struct tipc_msg *msg = buf_msg(buf); |
| 949 | struct net *net = l_ptr->owner->net; | ||
| 926 | 950 | ||
| 927 | pr_warn("Retransmission failure on link <%s>\n", l_ptr->name); | 951 | pr_warn("Retransmission failure on link <%s>\n", l_ptr->name); |
| 928 | 952 | ||
| @@ -940,7 +964,7 @@ static void link_retransmit_failure(struct tipc_link *l_ptr, | |||
| 940 | pr_cont("Outstanding acks: %lu\n", | 964 | pr_cont("Outstanding acks: %lu\n", |
| 941 | (unsigned long) TIPC_SKB_CB(buf)->handle); | 965 | (unsigned long) TIPC_SKB_CB(buf)->handle); |
| 942 | 966 | ||
| 943 | n_ptr = tipc_bclink_retransmit_to(); | 967 | n_ptr = tipc_bclink_retransmit_to(net); |
| 944 | tipc_node_lock(n_ptr); | 968 | tipc_node_lock(n_ptr); |
| 945 | 969 | ||
| 946 | tipc_addr_string_fill(addr_string, n_ptr->addr); | 970 | tipc_addr_string_fill(addr_string, n_ptr->addr); |
| @@ -955,7 +979,7 @@ static void link_retransmit_failure(struct tipc_link *l_ptr, | |||
| 955 | 979 | ||
| 956 | tipc_node_unlock(n_ptr); | 980 | tipc_node_unlock(n_ptr); |
| 957 | 981 | ||
| 958 | tipc_bclink_set_flags(TIPC_BCLINK_RESET); | 982 | tipc_bclink_set_flags(net, TIPC_BCLINK_RESET); |
| 959 | l_ptr->stale_count = 0; | 983 | l_ptr->stale_count = 0; |
| 960 | } | 984 | } |
| 961 | } | 985 | } |
| @@ -987,7 +1011,8 @@ void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *skb, | |||
| 987 | msg = buf_msg(skb); | 1011 | msg = buf_msg(skb); |
| 988 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); | 1012 | msg_set_ack(msg, mod(l_ptr->next_in_no - 1)); |
| 989 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); | 1013 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
| 990 | tipc_bearer_send(l_ptr->bearer_id, skb, &l_ptr->media_addr); | 1014 | tipc_bearer_send(l_ptr->owner->net, l_ptr->bearer_id, skb, |
| 1015 | &l_ptr->media_addr); | ||
| 991 | retransmits--; | 1016 | retransmits--; |
| 992 | l_ptr->stats.retransmitted++; | 1017 | l_ptr->stats.retransmitted++; |
| 993 | } | 1018 | } |
| @@ -1063,14 +1088,16 @@ static int link_recv_buf_validate(struct sk_buff *buf) | |||
| 1063 | 1088 | ||
| 1064 | /** | 1089 | /** |
| 1065 | * tipc_rcv - process TIPC packets/messages arriving from off-node | 1090 | * tipc_rcv - process TIPC packets/messages arriving from off-node |
| 1091 | * @net: the applicable net namespace | ||
| 1066 | * @skb: TIPC packet | 1092 | * @skb: TIPC packet |
| 1067 | * @b_ptr: pointer to bearer message arrived on | 1093 | * @b_ptr: pointer to bearer message arrived on |
| 1068 | * | 1094 | * |
| 1069 | * Invoked with no locks held. Bearer pointer must point to a valid bearer | 1095 | * Invoked with no locks held. Bearer pointer must point to a valid bearer |
| 1070 | * structure (i.e. cannot be NULL), but bearer can be inactive. | 1096 | * structure (i.e. cannot be NULL), but bearer can be inactive. |
| 1071 | */ | 1097 | */ |
| 1072 | void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *b_ptr) | 1098 | void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr) |
| 1073 | { | 1099 | { |
| 1100 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 1074 | struct sk_buff_head head; | 1101 | struct sk_buff_head head; |
| 1075 | struct tipc_node *n_ptr; | 1102 | struct tipc_node *n_ptr; |
| 1076 | struct tipc_link *l_ptr; | 1103 | struct tipc_link *l_ptr; |
| @@ -1096,19 +1123,19 @@ void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *b_ptr) | |||
| 1096 | 1123 | ||
| 1097 | if (unlikely(msg_non_seq(msg))) { | 1124 | if (unlikely(msg_non_seq(msg))) { |
| 1098 | if (msg_user(msg) == LINK_CONFIG) | 1125 | if (msg_user(msg) == LINK_CONFIG) |
| 1099 | tipc_disc_rcv(skb, b_ptr); | 1126 | tipc_disc_rcv(net, skb, b_ptr); |
| 1100 | else | 1127 | else |
| 1101 | tipc_bclink_rcv(skb); | 1128 | tipc_bclink_rcv(net, skb); |
| 1102 | continue; | 1129 | continue; |
| 1103 | } | 1130 | } |
| 1104 | 1131 | ||
| 1105 | /* Discard unicast link messages destined for another node */ | 1132 | /* Discard unicast link messages destined for another node */ |
| 1106 | if (unlikely(!msg_short(msg) && | 1133 | if (unlikely(!msg_short(msg) && |
| 1107 | (msg_destnode(msg) != tipc_own_addr))) | 1134 | (msg_destnode(msg) != tn->own_addr))) |
| 1108 | goto discard; | 1135 | goto discard; |
| 1109 | 1136 | ||
| 1110 | /* Locate neighboring node that sent message */ | 1137 | /* Locate neighboring node that sent message */ |
| 1111 | n_ptr = tipc_node_find(msg_prevnode(msg)); | 1138 | n_ptr = tipc_node_find(net, msg_prevnode(msg)); |
| 1112 | if (unlikely(!n_ptr)) | 1139 | if (unlikely(!n_ptr)) |
| 1113 | goto discard; | 1140 | goto discard; |
| 1114 | tipc_node_lock(n_ptr); | 1141 | tipc_node_lock(n_ptr); |
| @@ -1159,7 +1186,7 @@ void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *b_ptr) | |||
| 1159 | /* Process the incoming packet */ | 1186 | /* Process the incoming packet */ |
| 1160 | if (unlikely(!link_working_working(l_ptr))) { | 1187 | if (unlikely(!link_working_working(l_ptr))) { |
| 1161 | if (msg_user(msg) == LINK_PROTOCOL) { | 1188 | if (msg_user(msg) == LINK_PROTOCOL) { |
| 1162 | tipc_link_proto_rcv(l_ptr, skb); | 1189 | tipc_link_proto_rcv(net, l_ptr, skb); |
| 1163 | link_retrieve_defq(l_ptr, &head); | 1190 | link_retrieve_defq(l_ptr, &head); |
| 1164 | tipc_node_unlock(n_ptr); | 1191 | tipc_node_unlock(n_ptr); |
| 1165 | continue; | 1192 | continue; |
| @@ -1179,7 +1206,7 @@ void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *b_ptr) | |||
| 1179 | 1206 | ||
| 1180 | /* Link is now in state WORKING_WORKING */ | 1207 | /* Link is now in state WORKING_WORKING */ |
| 1181 | if (unlikely(seq_no != mod(l_ptr->next_in_no))) { | 1208 | if (unlikely(seq_no != mod(l_ptr->next_in_no))) { |
| 1182 | link_handle_out_of_seq_msg(l_ptr, skb); | 1209 | link_handle_out_of_seq_msg(net, l_ptr, skb); |
| 1183 | link_retrieve_defq(l_ptr, &head); | 1210 | link_retrieve_defq(l_ptr, &head); |
| 1184 | tipc_node_unlock(n_ptr); | 1211 | tipc_node_unlock(n_ptr); |
| 1185 | continue; | 1212 | continue; |
| @@ -1193,13 +1220,13 @@ void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *b_ptr) | |||
| 1193 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); | 1220 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); |
| 1194 | } | 1221 | } |
| 1195 | 1222 | ||
| 1196 | if (tipc_link_prepare_input(l_ptr, &skb)) { | 1223 | if (tipc_link_prepare_input(net, l_ptr, &skb)) { |
| 1197 | tipc_node_unlock(n_ptr); | 1224 | tipc_node_unlock(n_ptr); |
| 1198 | continue; | 1225 | continue; |
| 1199 | } | 1226 | } |
| 1200 | tipc_node_unlock(n_ptr); | 1227 | tipc_node_unlock(n_ptr); |
| 1201 | 1228 | ||
| 1202 | if (tipc_link_input(l_ptr, skb) != 0) | 1229 | if (tipc_link_input(net, l_ptr, skb) != 0) |
| 1203 | goto discard; | 1230 | goto discard; |
| 1204 | continue; | 1231 | continue; |
| 1205 | unlock_discard: | 1232 | unlock_discard: |
| @@ -1216,7 +1243,8 @@ discard: | |||
| 1216 | * | 1243 | * |
| 1217 | * Node lock must be held | 1244 | * Node lock must be held |
| 1218 | */ | 1245 | */ |
| 1219 | static int tipc_link_prepare_input(struct tipc_link *l, struct sk_buff **buf) | 1246 | static int tipc_link_prepare_input(struct net *net, struct tipc_link *l, |
| 1247 | struct sk_buff **buf) | ||
| 1220 | { | 1248 | { |
| 1221 | struct tipc_node *n; | 1249 | struct tipc_node *n; |
| 1222 | struct tipc_msg *msg; | 1250 | struct tipc_msg *msg; |
| @@ -1226,7 +1254,7 @@ static int tipc_link_prepare_input(struct tipc_link *l, struct sk_buff **buf) | |||
| 1226 | msg = buf_msg(*buf); | 1254 | msg = buf_msg(*buf); |
| 1227 | switch (msg_user(msg)) { | 1255 | switch (msg_user(msg)) { |
| 1228 | case CHANGEOVER_PROTOCOL: | 1256 | case CHANGEOVER_PROTOCOL: |
| 1229 | if (tipc_link_tunnel_rcv(n, buf)) | 1257 | if (tipc_link_tunnel_rcv(net, n, buf)) |
| 1230 | res = 0; | 1258 | res = 0; |
| 1231 | break; | 1259 | break; |
| 1232 | case MSG_FRAGMENTER: | 1260 | case MSG_FRAGMENTER: |
| @@ -1258,7 +1286,8 @@ static int tipc_link_prepare_input(struct tipc_link *l, struct sk_buff **buf) | |||
| 1258 | /** | 1286 | /** |
| 1259 | * tipc_link_input - Deliver message too higher layers | 1287 | * tipc_link_input - Deliver message too higher layers |
| 1260 | */ | 1288 | */ |
| 1261 | static int tipc_link_input(struct tipc_link *l, struct sk_buff *buf) | 1289 | static int tipc_link_input(struct net *net, struct tipc_link *l, |
| 1290 | struct sk_buff *buf) | ||
| 1262 | { | 1291 | { |
| 1263 | struct tipc_msg *msg = buf_msg(buf); | 1292 | struct tipc_msg *msg = buf_msg(buf); |
| 1264 | int res = 0; | 1293 | int res = 0; |
| @@ -1269,13 +1298,13 @@ static int tipc_link_input(struct tipc_link *l, struct sk_buff *buf) | |||
| 1269 | case TIPC_HIGH_IMPORTANCE: | 1298 | case TIPC_HIGH_IMPORTANCE: |
| 1270 | case TIPC_CRITICAL_IMPORTANCE: | 1299 | case TIPC_CRITICAL_IMPORTANCE: |
| 1271 | case CONN_MANAGER: | 1300 | case CONN_MANAGER: |
| 1272 | tipc_sk_rcv(buf); | 1301 | tipc_sk_rcv(net, buf); |
| 1273 | break; | 1302 | break; |
| 1274 | case NAME_DISTRIBUTOR: | 1303 | case NAME_DISTRIBUTOR: |
| 1275 | tipc_named_rcv(buf); | 1304 | tipc_named_rcv(net, buf); |
| 1276 | break; | 1305 | break; |
| 1277 | case MSG_BUNDLER: | 1306 | case MSG_BUNDLER: |
| 1278 | tipc_link_bundle_rcv(buf); | 1307 | tipc_link_bundle_rcv(net, buf); |
| 1279 | break; | 1308 | break; |
| 1280 | default: | 1309 | default: |
| 1281 | res = -EINVAL; | 1310 | res = -EINVAL; |
| @@ -1325,13 +1354,14 @@ u32 tipc_link_defer_pkt(struct sk_buff_head *list, struct sk_buff *skb) | |||
| 1325 | /* | 1354 | /* |
| 1326 | * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet | 1355 | * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet |
| 1327 | */ | 1356 | */ |
| 1328 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, | 1357 | static void link_handle_out_of_seq_msg(struct net *net, |
| 1358 | struct tipc_link *l_ptr, | ||
| 1329 | struct sk_buff *buf) | 1359 | struct sk_buff *buf) |
| 1330 | { | 1360 | { |
| 1331 | u32 seq_no = buf_seqno(buf); | 1361 | u32 seq_no = buf_seqno(buf); |
| 1332 | 1362 | ||
| 1333 | if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) { | 1363 | if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) { |
| 1334 | tipc_link_proto_rcv(l_ptr, buf); | 1364 | tipc_link_proto_rcv(net, l_ptr, buf); |
| 1335 | return; | 1365 | return; |
| 1336 | } | 1366 | } |
| 1337 | 1367 | ||
| @@ -1381,7 +1411,7 @@ void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg, | |||
| 1381 | msg_set_type(msg, msg_typ); | 1411 | msg_set_type(msg, msg_typ); |
| 1382 | msg_set_net_plane(msg, l_ptr->net_plane); | 1412 | msg_set_net_plane(msg, l_ptr->net_plane); |
| 1383 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); | 1413 | msg_set_bcast_ack(msg, l_ptr->owner->bclink.last_in); |
| 1384 | msg_set_last_bcast(msg, tipc_bclink_get_last_sent()); | 1414 | msg_set_last_bcast(msg, tipc_bclink_get_last_sent(l_ptr->owner->net)); |
| 1385 | 1415 | ||
| 1386 | if (msg_typ == STATE_MSG) { | 1416 | if (msg_typ == STATE_MSG) { |
| 1387 | u32 next_sent = mod(l_ptr->next_out_no); | 1417 | u32 next_sent = mod(l_ptr->next_out_no); |
| @@ -1445,7 +1475,8 @@ void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg, | |||
| 1445 | skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg)); | 1475 | skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg)); |
| 1446 | buf->priority = TC_PRIO_CONTROL; | 1476 | buf->priority = TC_PRIO_CONTROL; |
| 1447 | 1477 | ||
| 1448 | tipc_bearer_send(l_ptr->bearer_id, buf, &l_ptr->media_addr); | 1478 | tipc_bearer_send(l_ptr->owner->net, l_ptr->bearer_id, buf, |
| 1479 | &l_ptr->media_addr); | ||
| 1449 | l_ptr->unacked_window = 0; | 1480 | l_ptr->unacked_window = 0; |
| 1450 | kfree_skb(buf); | 1481 | kfree_skb(buf); |
| 1451 | } | 1482 | } |
| @@ -1455,8 +1486,10 @@ void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int probe_msg, | |||
| 1455 | * Note that network plane id propagates through the network, and may | 1486 | * Note that network plane id propagates through the network, and may |
| 1456 | * change at any time. The node with lowest address rules | 1487 | * change at any time. The node with lowest address rules |
| 1457 | */ | 1488 | */ |
| 1458 | static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf) | 1489 | static void tipc_link_proto_rcv(struct net *net, struct tipc_link *l_ptr, |
| 1490 | struct sk_buff *buf) | ||
| 1459 | { | 1491 | { |
| 1492 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 1460 | u32 rec_gap = 0; | 1493 | u32 rec_gap = 0; |
| 1461 | u32 max_pkt_info; | 1494 | u32 max_pkt_info; |
| 1462 | u32 max_pkt_ack; | 1495 | u32 max_pkt_ack; |
| @@ -1468,7 +1501,7 @@ static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
| 1468 | goto exit; | 1501 | goto exit; |
| 1469 | 1502 | ||
| 1470 | if (l_ptr->net_plane != msg_net_plane(msg)) | 1503 | if (l_ptr->net_plane != msg_net_plane(msg)) |
| 1471 | if (tipc_own_addr > msg_prevnode(msg)) | 1504 | if (tn->own_addr > msg_prevnode(msg)) |
| 1472 | l_ptr->net_plane = msg_net_plane(msg); | 1505 | l_ptr->net_plane = msg_net_plane(msg); |
| 1473 | 1506 | ||
| 1474 | switch (msg_type(msg)) { | 1507 | switch (msg_type(msg)) { |
| @@ -1535,9 +1568,9 @@ static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
| 1535 | 1568 | ||
| 1536 | if (msg_linkprio(msg) && | 1569 | if (msg_linkprio(msg) && |
| 1537 | (msg_linkprio(msg) != l_ptr->priority)) { | 1570 | (msg_linkprio(msg) != l_ptr->priority)) { |
| 1538 | pr_warn("%s<%s>, priority change %u->%u\n", | 1571 | pr_debug("%s<%s>, priority change %u->%u\n", |
| 1539 | link_rst_msg, l_ptr->name, l_ptr->priority, | 1572 | link_rst_msg, l_ptr->name, |
| 1540 | msg_linkprio(msg)); | 1573 | l_ptr->priority, msg_linkprio(msg)); |
| 1541 | l_ptr->priority = msg_linkprio(msg); | 1574 | l_ptr->priority = msg_linkprio(msg); |
| 1542 | tipc_link_reset(l_ptr); /* Enforce change to take effect */ | 1575 | tipc_link_reset(l_ptr); /* Enforce change to take effect */ |
| 1543 | break; | 1576 | break; |
| @@ -1571,7 +1604,7 @@ static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
| 1571 | 1604 | ||
| 1572 | /* Protocol message before retransmits, reduce loss risk */ | 1605 | /* Protocol message before retransmits, reduce loss risk */ |
| 1573 | if (l_ptr->owner->bclink.recv_permitted) | 1606 | if (l_ptr->owner->bclink.recv_permitted) |
| 1574 | tipc_bclink_update_link_state(l_ptr->owner, | 1607 | tipc_bclink_update_link_state(net, l_ptr->owner, |
| 1575 | msg_last_bcast(msg)); | 1608 | msg_last_bcast(msg)); |
| 1576 | 1609 | ||
| 1577 | if (rec_gap || (msg_probe(msg))) { | 1610 | if (rec_gap || (msg_probe(msg))) { |
| @@ -1636,8 +1669,8 @@ void tipc_link_failover_send_queue(struct tipc_link *l_ptr) | |||
| 1636 | if (!tunnel) | 1669 | if (!tunnel) |
| 1637 | return; | 1670 | return; |
| 1638 | 1671 | ||
| 1639 | tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, | 1672 | tipc_msg_init(l_ptr->owner->net, &tunnel_hdr, CHANGEOVER_PROTOCOL, |
| 1640 | ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr); | 1673 | ORIGINAL_MSG, INT_H_SIZE, l_ptr->addr); |
| 1641 | msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); | 1674 | msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); |
| 1642 | msg_set_msgcnt(&tunnel_hdr, msgcount); | 1675 | msg_set_msgcnt(&tunnel_hdr, msgcount); |
| 1643 | 1676 | ||
| @@ -1694,8 +1727,8 @@ void tipc_link_dup_queue_xmit(struct tipc_link *l_ptr, | |||
| 1694 | struct sk_buff *skb; | 1727 | struct sk_buff *skb; |
| 1695 | struct tipc_msg tunnel_hdr; | 1728 | struct tipc_msg tunnel_hdr; |
| 1696 | 1729 | ||
| 1697 | tipc_msg_init(&tunnel_hdr, CHANGEOVER_PROTOCOL, | 1730 | tipc_msg_init(l_ptr->owner->net, &tunnel_hdr, CHANGEOVER_PROTOCOL, |
| 1698 | DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr); | 1731 | DUPLICATE_MSG, INT_H_SIZE, l_ptr->addr); |
| 1699 | msg_set_msgcnt(&tunnel_hdr, skb_queue_len(&l_ptr->outqueue)); | 1732 | msg_set_msgcnt(&tunnel_hdr, skb_queue_len(&l_ptr->outqueue)); |
| 1700 | msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); | 1733 | msg_set_bearer_id(&tunnel_hdr, l_ptr->peer_bearer_id); |
| 1701 | skb_queue_walk(&l_ptr->outqueue, skb) { | 1734 | skb_queue_walk(&l_ptr->outqueue, skb) { |
| @@ -1748,7 +1781,7 @@ static struct sk_buff *buf_extract(struct sk_buff *skb, u32 from_pos) | |||
| 1748 | /* tipc_link_dup_rcv(): Receive a tunnelled DUPLICATE_MSG packet. | 1781 | /* tipc_link_dup_rcv(): Receive a tunnelled DUPLICATE_MSG packet. |
| 1749 | * Owner node is locked. | 1782 | * Owner node is locked. |
| 1750 | */ | 1783 | */ |
| 1751 | static void tipc_link_dup_rcv(struct tipc_link *l_ptr, | 1784 | static void tipc_link_dup_rcv(struct net *net, struct tipc_link *l_ptr, |
| 1752 | struct sk_buff *t_buf) | 1785 | struct sk_buff *t_buf) |
| 1753 | { | 1786 | { |
| 1754 | struct sk_buff *buf; | 1787 | struct sk_buff *buf; |
| @@ -1763,7 +1796,7 @@ static void tipc_link_dup_rcv(struct tipc_link *l_ptr, | |||
| 1763 | } | 1796 | } |
| 1764 | 1797 | ||
| 1765 | /* Add buffer to deferred queue, if applicable: */ | 1798 | /* Add buffer to deferred queue, if applicable: */ |
| 1766 | link_handle_out_of_seq_msg(l_ptr, buf); | 1799 | link_handle_out_of_seq_msg(net, l_ptr, buf); |
| 1767 | } | 1800 | } |
| 1768 | 1801 | ||
| 1769 | /* tipc_link_failover_rcv(): Receive a tunnelled ORIGINAL_MSG packet | 1802 | /* tipc_link_failover_rcv(): Receive a tunnelled ORIGINAL_MSG packet |
| @@ -1817,7 +1850,7 @@ exit: | |||
| 1817 | * returned to the active link for delivery upwards. | 1850 | * returned to the active link for delivery upwards. |
| 1818 | * Owner node is locked. | 1851 | * Owner node is locked. |
| 1819 | */ | 1852 | */ |
| 1820 | static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr, | 1853 | static int tipc_link_tunnel_rcv(struct net *net, struct tipc_node *n_ptr, |
| 1821 | struct sk_buff **buf) | 1854 | struct sk_buff **buf) |
| 1822 | { | 1855 | { |
| 1823 | struct sk_buff *t_buf = *buf; | 1856 | struct sk_buff *t_buf = *buf; |
| @@ -1835,7 +1868,7 @@ static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr, | |||
| 1835 | goto exit; | 1868 | goto exit; |
| 1836 | 1869 | ||
| 1837 | if (msg_type(t_msg) == DUPLICATE_MSG) | 1870 | if (msg_type(t_msg) == DUPLICATE_MSG) |
| 1838 | tipc_link_dup_rcv(l_ptr, t_buf); | 1871 | tipc_link_dup_rcv(net, l_ptr, t_buf); |
| 1839 | else if (msg_type(t_msg) == ORIGINAL_MSG) | 1872 | else if (msg_type(t_msg) == ORIGINAL_MSG) |
| 1840 | *buf = tipc_link_failover_rcv(l_ptr, t_buf); | 1873 | *buf = tipc_link_failover_rcv(l_ptr, t_buf); |
| 1841 | else | 1874 | else |
| @@ -1848,7 +1881,7 @@ exit: | |||
| 1848 | /* | 1881 | /* |
| 1849 | * Bundler functionality: | 1882 | * Bundler functionality: |
| 1850 | */ | 1883 | */ |
| 1851 | void tipc_link_bundle_rcv(struct sk_buff *buf) | 1884 | void tipc_link_bundle_rcv(struct net *net, struct sk_buff *buf) |
| 1852 | { | 1885 | { |
| 1853 | u32 msgcount = msg_msgcnt(buf_msg(buf)); | 1886 | u32 msgcount = msg_msgcnt(buf_msg(buf)); |
| 1854 | u32 pos = INT_H_SIZE; | 1887 | u32 pos = INT_H_SIZE; |
| @@ -1865,13 +1898,13 @@ void tipc_link_bundle_rcv(struct sk_buff *buf) | |||
| 1865 | pos += align(msg_size(omsg)); | 1898 | pos += align(msg_size(omsg)); |
| 1866 | if (msg_isdata(omsg)) { | 1899 | if (msg_isdata(omsg)) { |
| 1867 | if (unlikely(msg_type(omsg) == TIPC_MCAST_MSG)) | 1900 | if (unlikely(msg_type(omsg) == TIPC_MCAST_MSG)) |
| 1868 | tipc_sk_mcast_rcv(obuf); | 1901 | tipc_sk_mcast_rcv(net, obuf); |
| 1869 | else | 1902 | else |
| 1870 | tipc_sk_rcv(obuf); | 1903 | tipc_sk_rcv(net, obuf); |
| 1871 | } else if (msg_user(omsg) == CONN_MANAGER) { | 1904 | } else if (msg_user(omsg) == CONN_MANAGER) { |
| 1872 | tipc_sk_rcv(obuf); | 1905 | tipc_sk_rcv(net, obuf); |
| 1873 | } else if (msg_user(omsg) == NAME_DISTRIBUTOR) { | 1906 | } else if (msg_user(omsg) == NAME_DISTRIBUTOR) { |
| 1874 | tipc_named_rcv(obuf); | 1907 | tipc_named_rcv(net, obuf); |
| 1875 | } else { | 1908 | } else { |
| 1876 | pr_warn("Illegal bundled msg: %u\n", msg_user(omsg)); | 1909 | pr_warn("Illegal bundled msg: %u\n", msg_user(omsg)); |
| 1877 | kfree_skb(obuf); | 1910 | kfree_skb(obuf); |
| @@ -1880,15 +1913,16 @@ void tipc_link_bundle_rcv(struct sk_buff *buf) | |||
| 1880 | kfree_skb(buf); | 1913 | kfree_skb(buf); |
| 1881 | } | 1914 | } |
| 1882 | 1915 | ||
| 1883 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tolerance) | 1916 | static void link_set_supervision_props(struct tipc_link *l_ptr, u32 tol) |
| 1884 | { | 1917 | { |
| 1885 | if ((tolerance < TIPC_MIN_LINK_TOL) || (tolerance > TIPC_MAX_LINK_TOL)) | 1918 | unsigned long intv = ((tol / 4) > 500) ? 500 : tol / 4; |
| 1919 | |||
| 1920 | if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL)) | ||
| 1886 | return; | 1921 | return; |
| 1887 | 1922 | ||
| 1888 | l_ptr->tolerance = tolerance; | 1923 | l_ptr->tolerance = tol; |
| 1889 | l_ptr->continuity_interval = | 1924 | l_ptr->cont_intv = msecs_to_jiffies(intv); |
| 1890 | ((tolerance / 4) > 500) ? 500 : tolerance / 4; | 1925 | l_ptr->abort_limit = tol / (jiffies_to_msecs(l_ptr->cont_intv) / 4); |
| 1891 | l_ptr->abort_limit = tolerance / (l_ptr->continuity_interval / 4); | ||
| 1892 | } | 1926 | } |
| 1893 | 1927 | ||
| 1894 | void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window) | 1928 | void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window) |
| @@ -1911,22 +1945,25 @@ void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window) | |||
| 1911 | } | 1945 | } |
| 1912 | 1946 | ||
| 1913 | /* tipc_link_find_owner - locate owner node of link by link's name | 1947 | /* tipc_link_find_owner - locate owner node of link by link's name |
| 1948 | * @net: the applicable net namespace | ||
| 1914 | * @name: pointer to link name string | 1949 | * @name: pointer to link name string |
| 1915 | * @bearer_id: pointer to index in 'node->links' array where the link was found. | 1950 | * @bearer_id: pointer to index in 'node->links' array where the link was found. |
| 1916 | * | 1951 | * |
| 1917 | * Returns pointer to node owning the link, or 0 if no matching link is found. | 1952 | * Returns pointer to node owning the link, or 0 if no matching link is found. |
| 1918 | */ | 1953 | */ |
| 1919 | static struct tipc_node *tipc_link_find_owner(const char *link_name, | 1954 | static struct tipc_node *tipc_link_find_owner(struct net *net, |
| 1955 | const char *link_name, | ||
| 1920 | unsigned int *bearer_id) | 1956 | unsigned int *bearer_id) |
| 1921 | { | 1957 | { |
| 1958 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 1922 | struct tipc_link *l_ptr; | 1959 | struct tipc_link *l_ptr; |
| 1923 | struct tipc_node *n_ptr; | 1960 | struct tipc_node *n_ptr; |
| 1924 | struct tipc_node *found_node = 0; | 1961 | struct tipc_node *found_node = NULL; |
| 1925 | int i; | 1962 | int i; |
| 1926 | 1963 | ||
| 1927 | *bearer_id = 0; | 1964 | *bearer_id = 0; |
| 1928 | rcu_read_lock(); | 1965 | rcu_read_lock(); |
| 1929 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | 1966 | list_for_each_entry_rcu(n_ptr, &tn->node_list, list) { |
| 1930 | tipc_node_lock(n_ptr); | 1967 | tipc_node_lock(n_ptr); |
| 1931 | for (i = 0; i < MAX_BEARERS; i++) { | 1968 | for (i = 0; i < MAX_BEARERS; i++) { |
| 1932 | l_ptr = n_ptr->links[i]; | 1969 | l_ptr = n_ptr->links[i]; |
| @@ -1970,6 +2007,7 @@ static int link_value_is_valid(u16 cmd, u32 new_value) | |||
| 1970 | 2007 | ||
| 1971 | /** | 2008 | /** |
| 1972 | * link_cmd_set_value - change priority/tolerance/window for link/bearer/media | 2009 | * link_cmd_set_value - change priority/tolerance/window for link/bearer/media |
| 2010 | * @net: the applicable net namespace | ||
| 1973 | * @name: ptr to link, bearer, or media name | 2011 | * @name: ptr to link, bearer, or media name |
| 1974 | * @new_value: new value of link, bearer, or media setting | 2012 | * @new_value: new value of link, bearer, or media setting |
| 1975 | * @cmd: which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*) | 2013 | * @cmd: which link, bearer, or media attribute to set (TIPC_CMD_SET_LINK_*) |
| @@ -1978,7 +2016,8 @@ static int link_value_is_valid(u16 cmd, u32 new_value) | |||
| 1978 | * | 2016 | * |
| 1979 | * Returns 0 if value updated and negative value on error. | 2017 | * Returns 0 if value updated and negative value on error. |
| 1980 | */ | 2018 | */ |
| 1981 | static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd) | 2019 | static int link_cmd_set_value(struct net *net, const char *name, u32 new_value, |
| 2020 | u16 cmd) | ||
| 1982 | { | 2021 | { |
| 1983 | struct tipc_node *node; | 2022 | struct tipc_node *node; |
| 1984 | struct tipc_link *l_ptr; | 2023 | struct tipc_link *l_ptr; |
| @@ -1987,7 +2026,7 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd) | |||
| 1987 | int bearer_id; | 2026 | int bearer_id; |
| 1988 | int res = 0; | 2027 | int res = 0; |
| 1989 | 2028 | ||
| 1990 | node = tipc_link_find_owner(name, &bearer_id); | 2029 | node = tipc_link_find_owner(net, name, &bearer_id); |
| 1991 | if (node) { | 2030 | if (node) { |
| 1992 | tipc_node_lock(node); | 2031 | tipc_node_lock(node); |
| 1993 | l_ptr = node->links[bearer_id]; | 2032 | l_ptr = node->links[bearer_id]; |
| @@ -2016,7 +2055,7 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd) | |||
| 2016 | return res; | 2055 | return res; |
| 2017 | } | 2056 | } |
| 2018 | 2057 | ||
| 2019 | b_ptr = tipc_bearer_find(name); | 2058 | b_ptr = tipc_bearer_find(net, name); |
| 2020 | if (b_ptr) { | 2059 | if (b_ptr) { |
| 2021 | switch (cmd) { | 2060 | switch (cmd) { |
| 2022 | case TIPC_CMD_SET_LINK_TOL: | 2061 | case TIPC_CMD_SET_LINK_TOL: |
| @@ -2055,8 +2094,8 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd) | |||
| 2055 | return res; | 2094 | return res; |
| 2056 | } | 2095 | } |
| 2057 | 2096 | ||
| 2058 | struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space, | 2097 | struct sk_buff *tipc_link_cmd_config(struct net *net, const void *req_tlv_area, |
| 2059 | u16 cmd) | 2098 | int req_tlv_space, u16 cmd) |
| 2060 | { | 2099 | { |
| 2061 | struct tipc_link_config *args; | 2100 | struct tipc_link_config *args; |
| 2062 | u32 new_value; | 2101 | u32 new_value; |
| @@ -2074,13 +2113,13 @@ struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space | |||
| 2074 | 2113 | ||
| 2075 | if (!strcmp(args->name, tipc_bclink_name)) { | 2114 | if (!strcmp(args->name, tipc_bclink_name)) { |
| 2076 | if ((cmd == TIPC_CMD_SET_LINK_WINDOW) && | 2115 | if ((cmd == TIPC_CMD_SET_LINK_WINDOW) && |
| 2077 | (tipc_bclink_set_queue_limits(new_value) == 0)) | 2116 | (tipc_bclink_set_queue_limits(net, new_value) == 0)) |
| 2078 | return tipc_cfg_reply_none(); | 2117 | return tipc_cfg_reply_none(); |
| 2079 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 2118 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 2080 | " (cannot change setting on broadcast link)"); | 2119 | " (cannot change setting on broadcast link)"); |
| 2081 | } | 2120 | } |
| 2082 | 2121 | ||
| 2083 | res = link_cmd_set_value(args->name, new_value, cmd); | 2122 | res = link_cmd_set_value(net, args->name, new_value, cmd); |
| 2084 | if (res) | 2123 | if (res) |
| 2085 | return tipc_cfg_reply_error_string("cannot change link setting"); | 2124 | return tipc_cfg_reply_error_string("cannot change link setting"); |
| 2086 | 2125 | ||
| @@ -2098,7 +2137,9 @@ static void link_reset_statistics(struct tipc_link *l_ptr) | |||
| 2098 | l_ptr->stats.recv_info = l_ptr->next_in_no; | 2137 | l_ptr->stats.recv_info = l_ptr->next_in_no; |
| 2099 | } | 2138 | } |
| 2100 | 2139 | ||
| 2101 | struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_space) | 2140 | struct sk_buff *tipc_link_cmd_reset_stats(struct net *net, |
| 2141 | const void *req_tlv_area, | ||
| 2142 | int req_tlv_space) | ||
| 2102 | { | 2143 | { |
| 2103 | char *link_name; | 2144 | char *link_name; |
| 2104 | struct tipc_link *l_ptr; | 2145 | struct tipc_link *l_ptr; |
| @@ -2110,11 +2151,11 @@ struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, int req_tlv_ | |||
| 2110 | 2151 | ||
| 2111 | link_name = (char *)TLV_DATA(req_tlv_area); | 2152 | link_name = (char *)TLV_DATA(req_tlv_area); |
| 2112 | if (!strcmp(link_name, tipc_bclink_name)) { | 2153 | if (!strcmp(link_name, tipc_bclink_name)) { |
| 2113 | if (tipc_bclink_reset_stats()) | 2154 | if (tipc_bclink_reset_stats(net)) |
| 2114 | return tipc_cfg_reply_error_string("link not found"); | 2155 | return tipc_cfg_reply_error_string("link not found"); |
| 2115 | return tipc_cfg_reply_none(); | 2156 | return tipc_cfg_reply_none(); |
| 2116 | } | 2157 | } |
| 2117 | node = tipc_link_find_owner(link_name, &bearer_id); | 2158 | node = tipc_link_find_owner(net, link_name, &bearer_id); |
| 2118 | if (!node) | 2159 | if (!node) |
| 2119 | return tipc_cfg_reply_error_string("link not found"); | 2160 | return tipc_cfg_reply_error_string("link not found"); |
| 2120 | 2161 | ||
| @@ -2139,13 +2180,15 @@ static u32 percent(u32 count, u32 total) | |||
| 2139 | 2180 | ||
| 2140 | /** | 2181 | /** |
| 2141 | * tipc_link_stats - print link statistics | 2182 | * tipc_link_stats - print link statistics |
| 2183 | * @net: the applicable net namespace | ||
| 2142 | * @name: link name | 2184 | * @name: link name |
| 2143 | * @buf: print buffer area | 2185 | * @buf: print buffer area |
| 2144 | * @buf_size: size of print buffer area | 2186 | * @buf_size: size of print buffer area |
| 2145 | * | 2187 | * |
| 2146 | * Returns length of print buffer data string (or 0 if error) | 2188 | * Returns length of print buffer data string (or 0 if error) |
| 2147 | */ | 2189 | */ |
| 2148 | static int tipc_link_stats(const char *name, char *buf, const u32 buf_size) | 2190 | static int tipc_link_stats(struct net *net, const char *name, char *buf, |
| 2191 | const u32 buf_size) | ||
| 2149 | { | 2192 | { |
| 2150 | struct tipc_link *l; | 2193 | struct tipc_link *l; |
| 2151 | struct tipc_stats *s; | 2194 | struct tipc_stats *s; |
| @@ -2156,9 +2199,9 @@ static int tipc_link_stats(const char *name, char *buf, const u32 buf_size) | |||
| 2156 | int ret; | 2199 | int ret; |
| 2157 | 2200 | ||
| 2158 | if (!strcmp(name, tipc_bclink_name)) | 2201 | if (!strcmp(name, tipc_bclink_name)) |
| 2159 | return tipc_bclink_stats(buf, buf_size); | 2202 | return tipc_bclink_stats(net, buf, buf_size); |
| 2160 | 2203 | ||
| 2161 | node = tipc_link_find_owner(name, &bearer_id); | 2204 | node = tipc_link_find_owner(net, name, &bearer_id); |
| 2162 | if (!node) | 2205 | if (!node) |
| 2163 | return 0; | 2206 | return 0; |
| 2164 | 2207 | ||
| @@ -2235,7 +2278,9 @@ static int tipc_link_stats(const char *name, char *buf, const u32 buf_size) | |||
| 2235 | return ret; | 2278 | return ret; |
| 2236 | } | 2279 | } |
| 2237 | 2280 | ||
| 2238 | struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_space) | 2281 | struct sk_buff *tipc_link_cmd_show_stats(struct net *net, |
| 2282 | const void *req_tlv_area, | ||
| 2283 | int req_tlv_space) | ||
| 2239 | { | 2284 | { |
| 2240 | struct sk_buff *buf; | 2285 | struct sk_buff *buf; |
| 2241 | struct tlv_desc *rep_tlv; | 2286 | struct tlv_desc *rep_tlv; |
| @@ -2253,7 +2298,7 @@ struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_s | |||
| 2253 | rep_tlv = (struct tlv_desc *)buf->data; | 2298 | rep_tlv = (struct tlv_desc *)buf->data; |
| 2254 | pb = TLV_DATA(rep_tlv); | 2299 | pb = TLV_DATA(rep_tlv); |
| 2255 | pb_len = ULTRA_STRING_MAX_LEN; | 2300 | pb_len = ULTRA_STRING_MAX_LEN; |
| 2256 | str_len = tipc_link_stats((char *)TLV_DATA(req_tlv_area), | 2301 | str_len = tipc_link_stats(net, (char *)TLV_DATA(req_tlv_area), |
| 2257 | pb, pb_len); | 2302 | pb, pb_len); |
| 2258 | if (!str_len) { | 2303 | if (!str_len) { |
| 2259 | kfree_skb(buf); | 2304 | kfree_skb(buf); |
| @@ -2266,39 +2311,13 @@ struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, int req_tlv_s | |||
| 2266 | return buf; | 2311 | return buf; |
| 2267 | } | 2312 | } |
| 2268 | 2313 | ||
| 2269 | /** | ||
| 2270 | * tipc_link_get_max_pkt - get maximum packet size to use when sending to destination | ||
| 2271 | * @dest: network address of destination node | ||
| 2272 | * @selector: used to select from set of active links | ||
| 2273 | * | ||
| 2274 | * If no active link can be found, uses default maximum packet size. | ||
| 2275 | */ | ||
| 2276 | u32 tipc_link_get_max_pkt(u32 dest, u32 selector) | ||
| 2277 | { | ||
| 2278 | struct tipc_node *n_ptr; | ||
| 2279 | struct tipc_link *l_ptr; | ||
| 2280 | u32 res = MAX_PKT_DEFAULT; | ||
| 2281 | |||
| 2282 | if (dest == tipc_own_addr) | ||
| 2283 | return MAX_MSG_SIZE; | ||
| 2284 | |||
| 2285 | n_ptr = tipc_node_find(dest); | ||
| 2286 | if (n_ptr) { | ||
| 2287 | tipc_node_lock(n_ptr); | ||
| 2288 | l_ptr = n_ptr->active_links[selector & 1]; | ||
| 2289 | if (l_ptr) | ||
| 2290 | res = l_ptr->max_pkt; | ||
| 2291 | tipc_node_unlock(n_ptr); | ||
| 2292 | } | ||
| 2293 | return res; | ||
| 2294 | } | ||
| 2295 | |||
| 2296 | static void link_print(struct tipc_link *l_ptr, const char *str) | 2314 | static void link_print(struct tipc_link *l_ptr, const char *str) |
| 2297 | { | 2315 | { |
| 2316 | struct tipc_net *tn = net_generic(l_ptr->owner->net, tipc_net_id); | ||
| 2298 | struct tipc_bearer *b_ptr; | 2317 | struct tipc_bearer *b_ptr; |
| 2299 | 2318 | ||
| 2300 | rcu_read_lock(); | 2319 | rcu_read_lock(); |
| 2301 | b_ptr = rcu_dereference_rtnl(bearer_list[l_ptr->bearer_id]); | 2320 | b_ptr = rcu_dereference_rtnl(tn->bearer_list[l_ptr->bearer_id]); |
| 2302 | if (b_ptr) | 2321 | if (b_ptr) |
| 2303 | pr_info("%s Link %x<%s>:", str, l_ptr->addr, b_ptr->name); | 2322 | pr_info("%s Link %x<%s>:", str, l_ptr->addr, b_ptr->name); |
| 2304 | rcu_read_unlock(); | 2323 | rcu_read_unlock(); |
| @@ -2362,6 +2381,7 @@ int tipc_nl_link_set(struct sk_buff *skb, struct genl_info *info) | |||
| 2362 | struct tipc_link *link; | 2381 | struct tipc_link *link; |
| 2363 | struct tipc_node *node; | 2382 | struct tipc_node *node; |
| 2364 | struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1]; | 2383 | struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1]; |
| 2384 | struct net *net = genl_info_net(info); | ||
| 2365 | 2385 | ||
| 2366 | if (!info->attrs[TIPC_NLA_LINK]) | 2386 | if (!info->attrs[TIPC_NLA_LINK]) |
| 2367 | return -EINVAL; | 2387 | return -EINVAL; |
| @@ -2377,7 +2397,7 @@ int tipc_nl_link_set(struct sk_buff *skb, struct genl_info *info) | |||
| 2377 | 2397 | ||
| 2378 | name = nla_data(attrs[TIPC_NLA_LINK_NAME]); | 2398 | name = nla_data(attrs[TIPC_NLA_LINK_NAME]); |
| 2379 | 2399 | ||
| 2380 | node = tipc_link_find_owner(name, &bearer_id); | 2400 | node = tipc_link_find_owner(net, name, &bearer_id); |
| 2381 | if (!node) | 2401 | if (!node) |
| 2382 | return -EINVAL; | 2402 | return -EINVAL; |
| 2383 | 2403 | ||
| @@ -2493,12 +2513,14 @@ msg_full: | |||
| 2493 | } | 2513 | } |
| 2494 | 2514 | ||
| 2495 | /* Caller should hold appropriate locks to protect the link */ | 2515 | /* Caller should hold appropriate locks to protect the link */ |
| 2496 | static int __tipc_nl_add_link(struct tipc_nl_msg *msg, struct tipc_link *link) | 2516 | static int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg, |
| 2517 | struct tipc_link *link) | ||
| 2497 | { | 2518 | { |
| 2498 | int err; | 2519 | int err; |
| 2499 | void *hdr; | 2520 | void *hdr; |
| 2500 | struct nlattr *attrs; | 2521 | struct nlattr *attrs; |
| 2501 | struct nlattr *prop; | 2522 | struct nlattr *prop; |
| 2523 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 2502 | 2524 | ||
| 2503 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, | 2525 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, |
| 2504 | NLM_F_MULTI, TIPC_NL_LINK_GET); | 2526 | NLM_F_MULTI, TIPC_NL_LINK_GET); |
| @@ -2512,7 +2534,7 @@ static int __tipc_nl_add_link(struct tipc_nl_msg *msg, struct tipc_link *link) | |||
| 2512 | if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name)) | 2534 | if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name)) |
| 2513 | goto attr_msg_full; | 2535 | goto attr_msg_full; |
| 2514 | if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, | 2536 | if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, |
| 2515 | tipc_cluster_mask(tipc_own_addr))) | 2537 | tipc_cluster_mask(tn->own_addr))) |
| 2516 | goto attr_msg_full; | 2538 | goto attr_msg_full; |
| 2517 | if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->max_pkt)) | 2539 | if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->max_pkt)) |
| 2518 | goto attr_msg_full; | 2540 | goto attr_msg_full; |
| @@ -2562,9 +2584,8 @@ msg_full: | |||
| 2562 | } | 2584 | } |
| 2563 | 2585 | ||
| 2564 | /* Caller should hold node lock */ | 2586 | /* Caller should hold node lock */ |
| 2565 | static int __tipc_nl_add_node_links(struct tipc_nl_msg *msg, | 2587 | static int __tipc_nl_add_node_links(struct net *net, struct tipc_nl_msg *msg, |
| 2566 | struct tipc_node *node, | 2588 | struct tipc_node *node, u32 *prev_link) |
| 2567 | u32 *prev_link) | ||
| 2568 | { | 2589 | { |
| 2569 | u32 i; | 2590 | u32 i; |
| 2570 | int err; | 2591 | int err; |
| @@ -2575,7 +2596,7 @@ static int __tipc_nl_add_node_links(struct tipc_nl_msg *msg, | |||
| 2575 | if (!node->links[i]) | 2596 | if (!node->links[i]) |
| 2576 | continue; | 2597 | continue; |
| 2577 | 2598 | ||
| 2578 | err = __tipc_nl_add_link(msg, node->links[i]); | 2599 | err = __tipc_nl_add_link(net, msg, node->links[i]); |
| 2579 | if (err) | 2600 | if (err) |
| 2580 | return err; | 2601 | return err; |
| 2581 | } | 2602 | } |
| @@ -2586,6 +2607,8 @@ static int __tipc_nl_add_node_links(struct tipc_nl_msg *msg, | |||
| 2586 | 2607 | ||
| 2587 | int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb) | 2608 | int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb) |
| 2588 | { | 2609 | { |
| 2610 | struct net *net = sock_net(skb->sk); | ||
| 2611 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 2589 | struct tipc_node *node; | 2612 | struct tipc_node *node; |
| 2590 | struct tipc_nl_msg msg; | 2613 | struct tipc_nl_msg msg; |
| 2591 | u32 prev_node = cb->args[0]; | 2614 | u32 prev_node = cb->args[0]; |
| @@ -2603,7 +2626,7 @@ int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 2603 | rcu_read_lock(); | 2626 | rcu_read_lock(); |
| 2604 | 2627 | ||
| 2605 | if (prev_node) { | 2628 | if (prev_node) { |
| 2606 | node = tipc_node_find(prev_node); | 2629 | node = tipc_node_find(net, prev_node); |
| 2607 | if (!node) { | 2630 | if (!node) { |
| 2608 | /* We never set seq or call nl_dump_check_consistent() | 2631 | /* We never set seq or call nl_dump_check_consistent() |
| 2609 | * this means that setting prev_seq here will cause the | 2632 | * this means that setting prev_seq here will cause the |
| @@ -2615,9 +2638,11 @@ int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 2615 | goto out; | 2638 | goto out; |
| 2616 | } | 2639 | } |
| 2617 | 2640 | ||
| 2618 | list_for_each_entry_continue_rcu(node, &tipc_node_list, list) { | 2641 | list_for_each_entry_continue_rcu(node, &tn->node_list, |
| 2642 | list) { | ||
| 2619 | tipc_node_lock(node); | 2643 | tipc_node_lock(node); |
| 2620 | err = __tipc_nl_add_node_links(&msg, node, &prev_link); | 2644 | err = __tipc_nl_add_node_links(net, &msg, node, |
| 2645 | &prev_link); | ||
| 2621 | tipc_node_unlock(node); | 2646 | tipc_node_unlock(node); |
| 2622 | if (err) | 2647 | if (err) |
| 2623 | goto out; | 2648 | goto out; |
| @@ -2625,13 +2650,14 @@ int tipc_nl_link_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 2625 | prev_node = node->addr; | 2650 | prev_node = node->addr; |
| 2626 | } | 2651 | } |
| 2627 | } else { | 2652 | } else { |
| 2628 | err = tipc_nl_add_bc_link(&msg); | 2653 | err = tipc_nl_add_bc_link(net, &msg); |
| 2629 | if (err) | 2654 | if (err) |
| 2630 | goto out; | 2655 | goto out; |
| 2631 | 2656 | ||
| 2632 | list_for_each_entry_rcu(node, &tipc_node_list, list) { | 2657 | list_for_each_entry_rcu(node, &tn->node_list, list) { |
| 2633 | tipc_node_lock(node); | 2658 | tipc_node_lock(node); |
| 2634 | err = __tipc_nl_add_node_links(&msg, node, &prev_link); | 2659 | err = __tipc_nl_add_node_links(net, &msg, node, |
| 2660 | &prev_link); | ||
| 2635 | tipc_node_unlock(node); | 2661 | tipc_node_unlock(node); |
| 2636 | if (err) | 2662 | if (err) |
| 2637 | goto out; | 2663 | goto out; |
| @@ -2652,6 +2678,7 @@ out: | |||
| 2652 | 2678 | ||
| 2653 | int tipc_nl_link_get(struct sk_buff *skb, struct genl_info *info) | 2679 | int tipc_nl_link_get(struct sk_buff *skb, struct genl_info *info) |
| 2654 | { | 2680 | { |
| 2681 | struct net *net = genl_info_net(info); | ||
| 2655 | struct sk_buff *ans_skb; | 2682 | struct sk_buff *ans_skb; |
| 2656 | struct tipc_nl_msg msg; | 2683 | struct tipc_nl_msg msg; |
| 2657 | struct tipc_link *link; | 2684 | struct tipc_link *link; |
| @@ -2664,7 +2691,7 @@ int tipc_nl_link_get(struct sk_buff *skb, struct genl_info *info) | |||
| 2664 | return -EINVAL; | 2691 | return -EINVAL; |
| 2665 | 2692 | ||
| 2666 | name = nla_data(info->attrs[TIPC_NLA_LINK_NAME]); | 2693 | name = nla_data(info->attrs[TIPC_NLA_LINK_NAME]); |
| 2667 | node = tipc_link_find_owner(name, &bearer_id); | 2694 | node = tipc_link_find_owner(net, name, &bearer_id); |
| 2668 | if (!node) | 2695 | if (!node) |
| 2669 | return -EINVAL; | 2696 | return -EINVAL; |
| 2670 | 2697 | ||
| @@ -2683,7 +2710,7 @@ int tipc_nl_link_get(struct sk_buff *skb, struct genl_info *info) | |||
| 2683 | goto err_out; | 2710 | goto err_out; |
| 2684 | } | 2711 | } |
| 2685 | 2712 | ||
| 2686 | err = __tipc_nl_add_link(&msg, link); | 2713 | err = __tipc_nl_add_link(net, &msg, link); |
| 2687 | if (err) | 2714 | if (err) |
| 2688 | goto err_out; | 2715 | goto err_out; |
| 2689 | 2716 | ||
| @@ -2706,6 +2733,7 @@ int tipc_nl_link_reset_stats(struct sk_buff *skb, struct genl_info *info) | |||
| 2706 | struct tipc_link *link; | 2733 | struct tipc_link *link; |
| 2707 | struct tipc_node *node; | 2734 | struct tipc_node *node; |
| 2708 | struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1]; | 2735 | struct nlattr *attrs[TIPC_NLA_LINK_MAX + 1]; |
| 2736 | struct net *net = genl_info_net(info); | ||
| 2709 | 2737 | ||
| 2710 | if (!info->attrs[TIPC_NLA_LINK]) | 2738 | if (!info->attrs[TIPC_NLA_LINK]) |
| 2711 | return -EINVAL; | 2739 | return -EINVAL; |
| @@ -2722,13 +2750,13 @@ int tipc_nl_link_reset_stats(struct sk_buff *skb, struct genl_info *info) | |||
| 2722 | link_name = nla_data(attrs[TIPC_NLA_LINK_NAME]); | 2750 | link_name = nla_data(attrs[TIPC_NLA_LINK_NAME]); |
| 2723 | 2751 | ||
| 2724 | if (strcmp(link_name, tipc_bclink_name) == 0) { | 2752 | if (strcmp(link_name, tipc_bclink_name) == 0) { |
| 2725 | err = tipc_bclink_reset_stats(); | 2753 | err = tipc_bclink_reset_stats(net); |
| 2726 | if (err) | 2754 | if (err) |
| 2727 | return err; | 2755 | return err; |
| 2728 | return 0; | 2756 | return 0; |
| 2729 | } | 2757 | } |
| 2730 | 2758 | ||
| 2731 | node = tipc_link_find_owner(link_name, &bearer_id); | 2759 | node = tipc_link_find_owner(net, link_name, &bearer_id); |
| 2732 | if (!node) | 2760 | if (!node) |
| 2733 | return -EINVAL; | 2761 | return -EINVAL; |
| 2734 | 2762 | ||
diff --git a/net/tipc/link.h b/net/tipc/link.h index 55812e87ca1e..9df7fa4d3bdd 100644 --- a/net/tipc/link.h +++ b/net/tipc/link.h | |||
| @@ -41,6 +41,10 @@ | |||
| 41 | #include "msg.h" | 41 | #include "msg.h" |
| 42 | #include "node.h" | 42 | #include "node.h" |
| 43 | 43 | ||
| 44 | /* TIPC-specific error codes | ||
| 45 | */ | ||
| 46 | #define ELINKCONG EAGAIN /* link congestion <=> resource unavailable */ | ||
| 47 | |||
| 44 | /* Out-of-range value for link sequence numbers | 48 | /* Out-of-range value for link sequence numbers |
| 45 | */ | 49 | */ |
| 46 | #define INVALID_LINK_SEQ 0x10000 | 50 | #define INVALID_LINK_SEQ 0x10000 |
| @@ -105,7 +109,7 @@ struct tipc_stats { | |||
| 105 | * @peer_bearer_id: bearer id used by link's peer endpoint | 109 | * @peer_bearer_id: bearer id used by link's peer endpoint |
| 106 | * @bearer_id: local bearer id used by link | 110 | * @bearer_id: local bearer id used by link |
| 107 | * @tolerance: minimum link continuity loss needed to reset link [in ms] | 111 | * @tolerance: minimum link continuity loss needed to reset link [in ms] |
| 108 | * @continuity_interval: link continuity testing interval [in ms] | 112 | * @cont_intv: link continuity testing interval |
| 109 | * @abort_limit: # of unacknowledged continuity probes needed to reset link | 113 | * @abort_limit: # of unacknowledged continuity probes needed to reset link |
| 110 | * @state: current state of link FSM | 114 | * @state: current state of link FSM |
| 111 | * @fsm_msg_cnt: # of protocol messages link FSM has sent in current state | 115 | * @fsm_msg_cnt: # of protocol messages link FSM has sent in current state |
| @@ -146,7 +150,7 @@ struct tipc_link { | |||
| 146 | u32 peer_bearer_id; | 150 | u32 peer_bearer_id; |
| 147 | u32 bearer_id; | 151 | u32 bearer_id; |
| 148 | u32 tolerance; | 152 | u32 tolerance; |
| 149 | u32 continuity_interval; | 153 | unsigned long cont_intv; |
| 150 | u32 abort_limit; | 154 | u32 abort_limit; |
| 151 | int state; | 155 | int state; |
| 152 | u32 fsm_msg_cnt; | 156 | u32 fsm_msg_cnt; |
| @@ -196,28 +200,32 @@ struct tipc_port; | |||
| 196 | struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, | 200 | struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, |
| 197 | struct tipc_bearer *b_ptr, | 201 | struct tipc_bearer *b_ptr, |
| 198 | const struct tipc_media_addr *media_addr); | 202 | const struct tipc_media_addr *media_addr); |
| 199 | void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down); | 203 | void tipc_link_delete_list(struct net *net, unsigned int bearer_id, |
| 204 | bool shutting_down); | ||
| 200 | void tipc_link_failover_send_queue(struct tipc_link *l_ptr); | 205 | void tipc_link_failover_send_queue(struct tipc_link *l_ptr); |
| 201 | void tipc_link_dup_queue_xmit(struct tipc_link *l_ptr, struct tipc_link *dest); | 206 | void tipc_link_dup_queue_xmit(struct tipc_link *l_ptr, struct tipc_link *dest); |
| 202 | void tipc_link_reset_fragments(struct tipc_link *l_ptr); | 207 | void tipc_link_reset_fragments(struct tipc_link *l_ptr); |
| 203 | int tipc_link_is_up(struct tipc_link *l_ptr); | 208 | int tipc_link_is_up(struct tipc_link *l_ptr); |
| 204 | int tipc_link_is_active(struct tipc_link *l_ptr); | 209 | int tipc_link_is_active(struct tipc_link *l_ptr); |
| 205 | void tipc_link_purge_queues(struct tipc_link *l_ptr); | 210 | void tipc_link_purge_queues(struct tipc_link *l_ptr); |
| 206 | struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, | 211 | struct sk_buff *tipc_link_cmd_config(struct net *net, const void *req_tlv_area, |
| 207 | int req_tlv_space, | 212 | int req_tlv_space, u16 cmd); |
| 208 | u16 cmd); | 213 | struct sk_buff *tipc_link_cmd_show_stats(struct net *net, |
| 209 | struct sk_buff *tipc_link_cmd_show_stats(const void *req_tlv_area, | 214 | const void *req_tlv_area, |
| 210 | int req_tlv_space); | 215 | int req_tlv_space); |
| 211 | struct sk_buff *tipc_link_cmd_reset_stats(const void *req_tlv_area, | 216 | struct sk_buff *tipc_link_cmd_reset_stats(struct net *net, |
| 217 | const void *req_tlv_area, | ||
| 212 | int req_tlv_space); | 218 | int req_tlv_space); |
| 213 | void tipc_link_reset_all(struct tipc_node *node); | 219 | void tipc_link_reset_all(struct tipc_node *node); |
| 214 | void tipc_link_reset(struct tipc_link *l_ptr); | 220 | void tipc_link_reset(struct tipc_link *l_ptr); |
| 215 | void tipc_link_reset_list(unsigned int bearer_id); | 221 | void tipc_link_reset_list(struct net *net, unsigned int bearer_id); |
| 216 | int tipc_link_xmit_skb(struct sk_buff *skb, u32 dest, u32 selector); | 222 | int tipc_link_xmit_skb(struct net *net, struct sk_buff *skb, u32 dest, |
| 217 | int tipc_link_xmit(struct sk_buff_head *list, u32 dest, u32 selector); | 223 | u32 selector); |
| 218 | int __tipc_link_xmit(struct tipc_link *link, struct sk_buff_head *list); | 224 | int tipc_link_xmit(struct net *net, struct sk_buff_head *list, u32 dest, |
| 219 | u32 tipc_link_get_max_pkt(u32 dest, u32 selector); | 225 | u32 selector); |
| 220 | void tipc_link_bundle_rcv(struct sk_buff *buf); | 226 | int __tipc_link_xmit(struct net *net, struct tipc_link *link, |
| 227 | struct sk_buff_head *list); | ||
| 228 | void tipc_link_bundle_rcv(struct net *net, struct sk_buff *buf); | ||
| 221 | void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int prob, | 229 | void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int prob, |
| 222 | u32 gap, u32 tolerance, u32 priority, u32 acked_mtu); | 230 | u32 gap, u32 tolerance, u32 priority, u32 acked_mtu); |
| 223 | void tipc_link_push_packets(struct tipc_link *l_ptr); | 231 | void tipc_link_push_packets(struct tipc_link *l_ptr); |
diff --git a/net/tipc/msg.c b/net/tipc/msg.c index a687b30a699c..18aba9e99345 100644 --- a/net/tipc/msg.c +++ b/net/tipc/msg.c | |||
| @@ -34,6 +34,7 @@ | |||
| 34 | * POSSIBILITY OF SUCH DAMAGE. | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #include <net/sock.h> | ||
| 37 | #include "core.h" | 38 | #include "core.h" |
| 38 | #include "msg.h" | 39 | #include "msg.h" |
| 39 | #include "addr.h" | 40 | #include "addr.h" |
| @@ -46,25 +47,50 @@ static unsigned int align(unsigned int i) | |||
| 46 | return (i + 3) & ~3u; | 47 | return (i + 3) & ~3u; |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type, u32 hsize, | 50 | /** |
| 50 | u32 destnode) | 51 | * tipc_buf_acquire - creates a TIPC message buffer |
| 52 | * @size: message size (including TIPC header) | ||
| 53 | * | ||
| 54 | * Returns a new buffer with data pointers set to the specified size. | ||
| 55 | * | ||
| 56 | * NOTE: Headroom is reserved to allow prepending of a data link header. | ||
| 57 | * There may also be unrequested tailroom present at the buffer's end. | ||
| 58 | */ | ||
| 59 | struct sk_buff *tipc_buf_acquire(u32 size) | ||
| 51 | { | 60 | { |
| 61 | struct sk_buff *skb; | ||
| 62 | unsigned int buf_size = (BUF_HEADROOM + size + 3) & ~3u; | ||
| 63 | |||
| 64 | skb = alloc_skb_fclone(buf_size, GFP_ATOMIC); | ||
| 65 | if (skb) { | ||
| 66 | skb_reserve(skb, BUF_HEADROOM); | ||
| 67 | skb_put(skb, size); | ||
| 68 | skb->next = NULL; | ||
| 69 | } | ||
| 70 | return skb; | ||
| 71 | } | ||
| 72 | |||
| 73 | void tipc_msg_init(struct net *net, struct tipc_msg *m, u32 user, u32 type, | ||
| 74 | u32 hsize, u32 destnode) | ||
| 75 | { | ||
| 76 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 77 | |||
| 52 | memset(m, 0, hsize); | 78 | memset(m, 0, hsize); |
| 53 | msg_set_version(m); | 79 | msg_set_version(m); |
| 54 | msg_set_user(m, user); | 80 | msg_set_user(m, user); |
| 55 | msg_set_hdr_sz(m, hsize); | 81 | msg_set_hdr_sz(m, hsize); |
| 56 | msg_set_size(m, hsize); | 82 | msg_set_size(m, hsize); |
| 57 | msg_set_prevnode(m, tipc_own_addr); | 83 | msg_set_prevnode(m, tn->own_addr); |
| 58 | msg_set_type(m, type); | 84 | msg_set_type(m, type); |
| 59 | if (hsize > SHORT_H_SIZE) { | 85 | if (hsize > SHORT_H_SIZE) { |
| 60 | msg_set_orignode(m, tipc_own_addr); | 86 | msg_set_orignode(m, tn->own_addr); |
| 61 | msg_set_destnode(m, destnode); | 87 | msg_set_destnode(m, destnode); |
| 62 | } | 88 | } |
| 63 | } | 89 | } |
| 64 | 90 | ||
| 65 | struct sk_buff *tipc_msg_create(uint user, uint type, uint hdr_sz, | 91 | struct sk_buff *tipc_msg_create(struct net *net, uint user, uint type, |
| 66 | uint data_sz, u32 dnode, u32 onode, | 92 | uint hdr_sz, uint data_sz, u32 dnode, |
| 67 | u32 dport, u32 oport, int errcode) | 93 | u32 onode, u32 dport, u32 oport, int errcode) |
| 68 | { | 94 | { |
| 69 | struct tipc_msg *msg; | 95 | struct tipc_msg *msg; |
| 70 | struct sk_buff *buf; | 96 | struct sk_buff *buf; |
| @@ -74,7 +100,7 @@ struct sk_buff *tipc_msg_create(uint user, uint type, uint hdr_sz, | |||
| 74 | return NULL; | 100 | return NULL; |
| 75 | 101 | ||
| 76 | msg = buf_msg(buf); | 102 | msg = buf_msg(buf); |
| 77 | tipc_msg_init(msg, user, type, hdr_sz, dnode); | 103 | tipc_msg_init(net, msg, user, type, hdr_sz, dnode); |
| 78 | msg_set_size(msg, hdr_sz + data_sz); | 104 | msg_set_size(msg, hdr_sz + data_sz); |
| 79 | msg_set_prevnode(msg, onode); | 105 | msg_set_prevnode(msg, onode); |
| 80 | msg_set_origport(msg, oport); | 106 | msg_set_origport(msg, oport); |
| @@ -170,8 +196,8 @@ err: | |||
| 170 | * | 196 | * |
| 171 | * Returns message data size or errno: -ENOMEM, -EFAULT | 197 | * Returns message data size or errno: -ENOMEM, -EFAULT |
| 172 | */ | 198 | */ |
| 173 | int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, | 199 | int tipc_msg_build(struct net *net, struct tipc_msg *mhdr, struct msghdr *m, |
| 174 | int dsz, int pktmax, struct sk_buff_head *list) | 200 | int offset, int dsz, int pktmax, struct sk_buff_head *list) |
| 175 | { | 201 | { |
| 176 | int mhsz = msg_hdr_sz(mhdr); | 202 | int mhsz = msg_hdr_sz(mhdr); |
| 177 | int msz = mhsz + dsz; | 203 | int msz = mhsz + dsz; |
| @@ -191,6 +217,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, | |||
| 191 | skb = tipc_buf_acquire(msz); | 217 | skb = tipc_buf_acquire(msz); |
| 192 | if (unlikely(!skb)) | 218 | if (unlikely(!skb)) |
| 193 | return -ENOMEM; | 219 | return -ENOMEM; |
| 220 | skb_orphan(skb); | ||
| 194 | __skb_queue_tail(list, skb); | 221 | __skb_queue_tail(list, skb); |
| 195 | skb_copy_to_linear_data(skb, mhdr, mhsz); | 222 | skb_copy_to_linear_data(skb, mhdr, mhsz); |
| 196 | pktpos = skb->data + mhsz; | 223 | pktpos = skb->data + mhsz; |
| @@ -202,8 +229,8 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, | |||
| 202 | } | 229 | } |
| 203 | 230 | ||
| 204 | /* Prepare reusable fragment header */ | 231 | /* Prepare reusable fragment header */ |
| 205 | tipc_msg_init(&pkthdr, MSG_FRAGMENTER, FIRST_FRAGMENT, | 232 | tipc_msg_init(net, &pkthdr, MSG_FRAGMENTER, FIRST_FRAGMENT, INT_H_SIZE, |
| 206 | INT_H_SIZE, msg_destnode(mhdr)); | 233 | msg_destnode(mhdr)); |
| 207 | msg_set_size(&pkthdr, pktmax); | 234 | msg_set_size(&pkthdr, pktmax); |
| 208 | msg_set_fragm_no(&pkthdr, pktno); | 235 | msg_set_fragm_no(&pkthdr, pktno); |
| 209 | 236 | ||
| @@ -211,6 +238,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, | |||
| 211 | skb = tipc_buf_acquire(pktmax); | 238 | skb = tipc_buf_acquire(pktmax); |
| 212 | if (!skb) | 239 | if (!skb) |
| 213 | return -ENOMEM; | 240 | return -ENOMEM; |
| 241 | skb_orphan(skb); | ||
| 214 | __skb_queue_tail(list, skb); | 242 | __skb_queue_tail(list, skb); |
| 215 | pktpos = skb->data; | 243 | pktpos = skb->data; |
| 216 | skb_copy_to_linear_data(skb, &pkthdr, INT_H_SIZE); | 244 | skb_copy_to_linear_data(skb, &pkthdr, INT_H_SIZE); |
| @@ -244,6 +272,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, | |||
| 244 | rc = -ENOMEM; | 272 | rc = -ENOMEM; |
| 245 | goto error; | 273 | goto error; |
| 246 | } | 274 | } |
| 275 | skb_orphan(skb); | ||
| 247 | __skb_queue_tail(list, skb); | 276 | __skb_queue_tail(list, skb); |
| 248 | msg_set_type(&pkthdr, FRAGMENT); | 277 | msg_set_type(&pkthdr, FRAGMENT); |
| 249 | msg_set_size(&pkthdr, pktsz); | 278 | msg_set_size(&pkthdr, pktsz); |
| @@ -312,8 +341,8 @@ bool tipc_msg_bundle(struct sk_buff_head *list, struct sk_buff *skb, u32 mtu) | |||
| 312 | * Replaces buffer if successful | 341 | * Replaces buffer if successful |
| 313 | * Returns true if success, otherwise false | 342 | * Returns true if success, otherwise false |
| 314 | */ | 343 | */ |
| 315 | bool tipc_msg_make_bundle(struct sk_buff_head *list, struct sk_buff *skb, | 344 | bool tipc_msg_make_bundle(struct net *net, struct sk_buff_head *list, |
| 316 | u32 mtu, u32 dnode) | 345 | struct sk_buff *skb, u32 mtu, u32 dnode) |
| 317 | { | 346 | { |
| 318 | struct sk_buff *bskb; | 347 | struct sk_buff *bskb; |
| 319 | struct tipc_msg *bmsg; | 348 | struct tipc_msg *bmsg; |
| @@ -336,7 +365,7 @@ bool tipc_msg_make_bundle(struct sk_buff_head *list, struct sk_buff *skb, | |||
| 336 | 365 | ||
| 337 | skb_trim(bskb, INT_H_SIZE); | 366 | skb_trim(bskb, INT_H_SIZE); |
| 338 | bmsg = buf_msg(bskb); | 367 | bmsg = buf_msg(bskb); |
| 339 | tipc_msg_init(bmsg, MSG_BUNDLER, 0, INT_H_SIZE, dnode); | 368 | tipc_msg_init(net, bmsg, MSG_BUNDLER, 0, INT_H_SIZE, dnode); |
| 340 | msg_set_seqno(bmsg, msg_seqno(msg)); | 369 | msg_set_seqno(bmsg, msg_seqno(msg)); |
| 341 | msg_set_ack(bmsg, msg_ack(msg)); | 370 | msg_set_ack(bmsg, msg_ack(msg)); |
| 342 | msg_set_bcast_ack(bmsg, msg_bcast_ack(msg)); | 371 | msg_set_bcast_ack(bmsg, msg_bcast_ack(msg)); |
| @@ -353,8 +382,10 @@ bool tipc_msg_make_bundle(struct sk_buff_head *list, struct sk_buff *skb, | |||
| 353 | * Consumes buffer if failure | 382 | * Consumes buffer if failure |
| 354 | * Returns true if success, otherwise false | 383 | * Returns true if success, otherwise false |
| 355 | */ | 384 | */ |
| 356 | bool tipc_msg_reverse(struct sk_buff *buf, u32 *dnode, int err) | 385 | bool tipc_msg_reverse(struct net *net, struct sk_buff *buf, u32 *dnode, |
| 386 | int err) | ||
| 357 | { | 387 | { |
| 388 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 358 | struct tipc_msg *msg = buf_msg(buf); | 389 | struct tipc_msg *msg = buf_msg(buf); |
| 359 | uint imp = msg_importance(msg); | 390 | uint imp = msg_importance(msg); |
| 360 | struct tipc_msg ohdr; | 391 | struct tipc_msg ohdr; |
| @@ -374,7 +405,7 @@ bool tipc_msg_reverse(struct sk_buff *buf, u32 *dnode, int err) | |||
| 374 | msg_set_errcode(msg, err); | 405 | msg_set_errcode(msg, err); |
| 375 | msg_set_origport(msg, msg_destport(&ohdr)); | 406 | msg_set_origport(msg, msg_destport(&ohdr)); |
| 376 | msg_set_destport(msg, msg_origport(&ohdr)); | 407 | msg_set_destport(msg, msg_origport(&ohdr)); |
| 377 | msg_set_prevnode(msg, tipc_own_addr); | 408 | msg_set_prevnode(msg, tn->own_addr); |
| 378 | if (!msg_short(msg)) { | 409 | if (!msg_short(msg)) { |
| 379 | msg_set_orignode(msg, msg_destnode(&ohdr)); | 410 | msg_set_orignode(msg, msg_destnode(&ohdr)); |
| 380 | msg_set_destnode(msg, msg_orignode(&ohdr)); | 411 | msg_set_destnode(msg, msg_orignode(&ohdr)); |
| @@ -399,7 +430,7 @@ exit: | |||
| 399 | * Returns 0 (TIPC_OK) if message ok and we can try again, -TIPC error | 430 | * Returns 0 (TIPC_OK) if message ok and we can try again, -TIPC error |
| 400 | * code if message to be rejected | 431 | * code if message to be rejected |
| 401 | */ | 432 | */ |
| 402 | int tipc_msg_eval(struct sk_buff *buf, u32 *dnode) | 433 | int tipc_msg_eval(struct net *net, struct sk_buff *buf, u32 *dnode) |
| 403 | { | 434 | { |
| 404 | struct tipc_msg *msg = buf_msg(buf); | 435 | struct tipc_msg *msg = buf_msg(buf); |
| 405 | u32 dport; | 436 | u32 dport; |
| @@ -413,8 +444,8 @@ int tipc_msg_eval(struct sk_buff *buf, u32 *dnode) | |||
| 413 | if (msg_reroute_cnt(msg) > 0) | 444 | if (msg_reroute_cnt(msg) > 0) |
| 414 | return -TIPC_ERR_NO_NAME; | 445 | return -TIPC_ERR_NO_NAME; |
| 415 | 446 | ||
| 416 | *dnode = addr_domain(msg_lookup_scope(msg)); | 447 | *dnode = addr_domain(net, msg_lookup_scope(msg)); |
| 417 | dport = tipc_nametbl_translate(msg_nametype(msg), | 448 | dport = tipc_nametbl_translate(net, msg_nametype(msg), |
| 418 | msg_nameinst(msg), | 449 | msg_nameinst(msg), |
| 419 | dnode); | 450 | dnode); |
| 420 | if (!dport) | 451 | if (!dport) |
diff --git a/net/tipc/msg.h b/net/tipc/msg.h index d5c83d7ecb47..526ef345b70e 100644 --- a/net/tipc/msg.h +++ b/net/tipc/msg.h | |||
| @@ -37,7 +37,7 @@ | |||
| 37 | #ifndef _TIPC_MSG_H | 37 | #ifndef _TIPC_MSG_H |
| 38 | #define _TIPC_MSG_H | 38 | #define _TIPC_MSG_H |
| 39 | 39 | ||
| 40 | #include "bearer.h" | 40 | #include <linux/tipc.h> |
| 41 | 41 | ||
| 42 | /* | 42 | /* |
| 43 | * Constants and routines used to read and write TIPC payload message headers | 43 | * Constants and routines used to read and write TIPC payload message headers |
| @@ -77,11 +77,37 @@ | |||
| 77 | 77 | ||
| 78 | #define TIPC_MEDIA_ADDR_OFFSET 5 | 78 | #define TIPC_MEDIA_ADDR_OFFSET 5 |
| 79 | 79 | ||
| 80 | /** | ||
| 81 | * TIPC message buffer code | ||
| 82 | * | ||
| 83 | * TIPC message buffer headroom reserves space for the worst-case | ||
| 84 | * link-level device header (in case the message is sent off-node). | ||
| 85 | * | ||
| 86 | * Note: Headroom should be a multiple of 4 to ensure the TIPC header fields | ||
| 87 | * are word aligned for quicker access | ||
| 88 | */ | ||
| 89 | #define BUF_HEADROOM LL_MAX_HEADER | ||
| 90 | |||
| 91 | struct tipc_skb_cb { | ||
| 92 | void *handle; | ||
| 93 | struct sk_buff *tail; | ||
| 94 | bool deferred; | ||
| 95 | bool wakeup_pending; | ||
| 96 | bool bundling; | ||
| 97 | u16 chain_sz; | ||
| 98 | u16 chain_imp; | ||
| 99 | }; | ||
| 100 | |||
| 101 | #define TIPC_SKB_CB(__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0])) | ||
| 80 | 102 | ||
| 81 | struct tipc_msg { | 103 | struct tipc_msg { |
| 82 | __be32 hdr[15]; | 104 | __be32 hdr[15]; |
| 83 | }; | 105 | }; |
| 84 | 106 | ||
| 107 | static inline struct tipc_msg *buf_msg(struct sk_buff *skb) | ||
| 108 | { | ||
| 109 | return (struct tipc_msg *)skb->data; | ||
| 110 | } | ||
| 85 | 111 | ||
| 86 | static inline u32 msg_word(struct tipc_msg *m, u32 pos) | 112 | static inline u32 msg_word(struct tipc_msg *m, u32 pos) |
| 87 | { | 113 | { |
| @@ -721,27 +747,21 @@ static inline u32 msg_tot_origport(struct tipc_msg *m) | |||
| 721 | return msg_origport(m); | 747 | return msg_origport(m); |
| 722 | } | 748 | } |
| 723 | 749 | ||
| 724 | bool tipc_msg_reverse(struct sk_buff *buf, u32 *dnode, int err); | 750 | struct sk_buff *tipc_buf_acquire(u32 size); |
| 725 | 751 | bool tipc_msg_reverse(struct net *net, struct sk_buff *buf, u32 *dnode, | |
| 726 | int tipc_msg_eval(struct sk_buff *buf, u32 *dnode); | 752 | int err); |
| 727 | 753 | int tipc_msg_eval(struct net *net, struct sk_buff *buf, u32 *dnode); | |
| 728 | void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type, u32 hsize, | 754 | void tipc_msg_init(struct net *net, struct tipc_msg *m, u32 user, u32 type, |
| 729 | u32 destnode); | 755 | u32 hsize, u32 destnode); |
| 730 | 756 | struct sk_buff *tipc_msg_create(struct net *net, uint user, uint type, | |
| 731 | struct sk_buff *tipc_msg_create(uint user, uint type, uint hdr_sz, | 757 | uint hdr_sz, uint data_sz, u32 dnode, |
| 732 | uint data_sz, u32 dnode, u32 onode, | 758 | u32 onode, u32 dport, u32 oport, int errcode); |
| 733 | u32 dport, u32 oport, int errcode); | ||
| 734 | |||
| 735 | int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf); | 759 | int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf); |
| 736 | |||
| 737 | bool tipc_msg_bundle(struct sk_buff_head *list, struct sk_buff *skb, u32 mtu); | 760 | bool tipc_msg_bundle(struct sk_buff_head *list, struct sk_buff *skb, u32 mtu); |
| 738 | 761 | bool tipc_msg_make_bundle(struct net *net, struct sk_buff_head *list, | |
| 739 | bool tipc_msg_make_bundle(struct sk_buff_head *list, struct sk_buff *skb, | 762 | struct sk_buff *skb, u32 mtu, u32 dnode); |
| 740 | u32 mtu, u32 dnode); | 763 | int tipc_msg_build(struct net *net, struct tipc_msg *mhdr, struct msghdr *m, |
| 741 | 764 | int offset, int dsz, int mtu, struct sk_buff_head *list); | |
| 742 | int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, | ||
| 743 | int dsz, int mtu, struct sk_buff_head *list); | ||
| 744 | |||
| 745 | struct sk_buff *tipc_msg_reassemble(struct sk_buff_head *list); | 765 | struct sk_buff *tipc_msg_reassemble(struct sk_buff_head *list); |
| 746 | 766 | ||
| 747 | #endif | 767 | #endif |
diff --git a/net/tipc/name_distr.c b/net/tipc/name_distr.c index ba6083dca95b..7f31cd4badc4 100644 --- a/net/tipc/name_distr.c +++ b/net/tipc/name_distr.c | |||
| @@ -68,29 +68,32 @@ static void publ_to_item(struct distr_item *i, struct publication *p) | |||
| 68 | /** | 68 | /** |
| 69 | * named_prepare_buf - allocate & initialize a publication message | 69 | * named_prepare_buf - allocate & initialize a publication message |
| 70 | */ | 70 | */ |
| 71 | static struct sk_buff *named_prepare_buf(u32 type, u32 size, u32 dest) | 71 | static struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size, |
| 72 | u32 dest) | ||
| 72 | { | 73 | { |
| 73 | struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size); | 74 | struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size); |
| 74 | struct tipc_msg *msg; | 75 | struct tipc_msg *msg; |
| 75 | 76 | ||
| 76 | if (buf != NULL) { | 77 | if (buf != NULL) { |
| 77 | msg = buf_msg(buf); | 78 | msg = buf_msg(buf); |
| 78 | tipc_msg_init(msg, NAME_DISTRIBUTOR, type, INT_H_SIZE, dest); | 79 | tipc_msg_init(net, msg, NAME_DISTRIBUTOR, type, INT_H_SIZE, |
| 80 | dest); | ||
| 79 | msg_set_size(msg, INT_H_SIZE + size); | 81 | msg_set_size(msg, INT_H_SIZE + size); |
| 80 | } | 82 | } |
| 81 | return buf; | 83 | return buf; |
| 82 | } | 84 | } |
| 83 | 85 | ||
| 84 | void named_cluster_distribute(struct sk_buff *skb) | 86 | void named_cluster_distribute(struct net *net, struct sk_buff *skb) |
| 85 | { | 87 | { |
| 88 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 86 | struct sk_buff *oskb; | 89 | struct sk_buff *oskb; |
| 87 | struct tipc_node *node; | 90 | struct tipc_node *node; |
| 88 | u32 dnode; | 91 | u32 dnode; |
| 89 | 92 | ||
| 90 | rcu_read_lock(); | 93 | rcu_read_lock(); |
| 91 | list_for_each_entry_rcu(node, &tipc_node_list, list) { | 94 | list_for_each_entry_rcu(node, &tn->node_list, list) { |
| 92 | dnode = node->addr; | 95 | dnode = node->addr; |
| 93 | if (in_own_node(dnode)) | 96 | if (in_own_node(net, dnode)) |
| 94 | continue; | 97 | continue; |
| 95 | if (!tipc_node_active_links(node)) | 98 | if (!tipc_node_active_links(node)) |
| 96 | continue; | 99 | continue; |
| @@ -98,7 +101,7 @@ void named_cluster_distribute(struct sk_buff *skb) | |||
| 98 | if (!oskb) | 101 | if (!oskb) |
| 99 | break; | 102 | break; |
| 100 | msg_set_destnode(buf_msg(oskb), dnode); | 103 | msg_set_destnode(buf_msg(oskb), dnode); |
| 101 | tipc_link_xmit_skb(oskb, dnode, dnode); | 104 | tipc_link_xmit_skb(net, oskb, dnode, dnode); |
| 102 | } | 105 | } |
| 103 | rcu_read_unlock(); | 106 | rcu_read_unlock(); |
| 104 | 107 | ||
| @@ -108,18 +111,19 @@ void named_cluster_distribute(struct sk_buff *skb) | |||
| 108 | /** | 111 | /** |
| 109 | * tipc_named_publish - tell other nodes about a new publication by this node | 112 | * tipc_named_publish - tell other nodes about a new publication by this node |
| 110 | */ | 113 | */ |
| 111 | struct sk_buff *tipc_named_publish(struct publication *publ) | 114 | struct sk_buff *tipc_named_publish(struct net *net, struct publication *publ) |
| 112 | { | 115 | { |
| 116 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 113 | struct sk_buff *buf; | 117 | struct sk_buff *buf; |
| 114 | struct distr_item *item; | 118 | struct distr_item *item; |
| 115 | 119 | ||
| 116 | list_add_tail_rcu(&publ->local_list, | 120 | list_add_tail_rcu(&publ->local_list, |
| 117 | &tipc_nametbl->publ_list[publ->scope]); | 121 | &tn->nametbl->publ_list[publ->scope]); |
| 118 | 122 | ||
| 119 | if (publ->scope == TIPC_NODE_SCOPE) | 123 | if (publ->scope == TIPC_NODE_SCOPE) |
| 120 | return NULL; | 124 | return NULL; |
| 121 | 125 | ||
| 122 | buf = named_prepare_buf(PUBLICATION, ITEM_SIZE, 0); | 126 | buf = named_prepare_buf(net, PUBLICATION, ITEM_SIZE, 0); |
| 123 | if (!buf) { | 127 | if (!buf) { |
| 124 | pr_warn("Publication distribution failure\n"); | 128 | pr_warn("Publication distribution failure\n"); |
| 125 | return NULL; | 129 | return NULL; |
| @@ -133,7 +137,7 @@ struct sk_buff *tipc_named_publish(struct publication *publ) | |||
| 133 | /** | 137 | /** |
| 134 | * tipc_named_withdraw - tell other nodes about a withdrawn publication by this node | 138 | * tipc_named_withdraw - tell other nodes about a withdrawn publication by this node |
| 135 | */ | 139 | */ |
| 136 | struct sk_buff *tipc_named_withdraw(struct publication *publ) | 140 | struct sk_buff *tipc_named_withdraw(struct net *net, struct publication *publ) |
| 137 | { | 141 | { |
| 138 | struct sk_buff *buf; | 142 | struct sk_buff *buf; |
| 139 | struct distr_item *item; | 143 | struct distr_item *item; |
| @@ -143,7 +147,7 @@ struct sk_buff *tipc_named_withdraw(struct publication *publ) | |||
| 143 | if (publ->scope == TIPC_NODE_SCOPE) | 147 | if (publ->scope == TIPC_NODE_SCOPE) |
| 144 | return NULL; | 148 | return NULL; |
| 145 | 149 | ||
| 146 | buf = named_prepare_buf(WITHDRAWAL, ITEM_SIZE, 0); | 150 | buf = named_prepare_buf(net, WITHDRAWAL, ITEM_SIZE, 0); |
| 147 | if (!buf) { | 151 | if (!buf) { |
| 148 | pr_warn("Withdrawal distribution failure\n"); | 152 | pr_warn("Withdrawal distribution failure\n"); |
| 149 | return NULL; | 153 | return NULL; |
| @@ -160,19 +164,21 @@ struct sk_buff *tipc_named_withdraw(struct publication *publ) | |||
| 160 | * @dnode: node to be updated | 164 | * @dnode: node to be updated |
| 161 | * @pls: linked list of publication items to be packed into buffer chain | 165 | * @pls: linked list of publication items to be packed into buffer chain |
| 162 | */ | 166 | */ |
| 163 | static void named_distribute(struct sk_buff_head *list, u32 dnode, | 167 | static void named_distribute(struct net *net, struct sk_buff_head *list, |
| 164 | struct list_head *pls) | 168 | u32 dnode, struct list_head *pls) |
| 165 | { | 169 | { |
| 166 | struct publication *publ; | 170 | struct publication *publ; |
| 167 | struct sk_buff *skb = NULL; | 171 | struct sk_buff *skb = NULL; |
| 168 | struct distr_item *item = NULL; | 172 | struct distr_item *item = NULL; |
| 169 | uint msg_dsz = (tipc_node_get_mtu(dnode, 0) / ITEM_SIZE) * ITEM_SIZE; | 173 | uint msg_dsz = (tipc_node_get_mtu(net, dnode, 0) / ITEM_SIZE) * |
| 174 | ITEM_SIZE; | ||
| 170 | uint msg_rem = msg_dsz; | 175 | uint msg_rem = msg_dsz; |
| 171 | 176 | ||
| 172 | list_for_each_entry(publ, pls, local_list) { | 177 | list_for_each_entry(publ, pls, local_list) { |
| 173 | /* Prepare next buffer: */ | 178 | /* Prepare next buffer: */ |
| 174 | if (!skb) { | 179 | if (!skb) { |
| 175 | skb = named_prepare_buf(PUBLICATION, msg_rem, dnode); | 180 | skb = named_prepare_buf(net, PUBLICATION, msg_rem, |
| 181 | dnode); | ||
| 176 | if (!skb) { | 182 | if (!skb) { |
| 177 | pr_warn("Bulk publication failure\n"); | 183 | pr_warn("Bulk publication failure\n"); |
| 178 | return; | 184 | return; |
| @@ -202,30 +208,32 @@ static void named_distribute(struct sk_buff_head *list, u32 dnode, | |||
| 202 | /** | 208 | /** |
| 203 | * tipc_named_node_up - tell specified node about all publications by this node | 209 | * tipc_named_node_up - tell specified node about all publications by this node |
| 204 | */ | 210 | */ |
| 205 | void tipc_named_node_up(u32 dnode) | 211 | void tipc_named_node_up(struct net *net, u32 dnode) |
| 206 | { | 212 | { |
| 213 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 207 | struct sk_buff_head head; | 214 | struct sk_buff_head head; |
| 208 | 215 | ||
| 209 | __skb_queue_head_init(&head); | 216 | __skb_queue_head_init(&head); |
| 210 | 217 | ||
| 211 | rcu_read_lock(); | 218 | rcu_read_lock(); |
| 212 | named_distribute(&head, dnode, | 219 | named_distribute(net, &head, dnode, |
| 213 | &tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]); | 220 | &tn->nametbl->publ_list[TIPC_CLUSTER_SCOPE]); |
| 214 | named_distribute(&head, dnode, | 221 | named_distribute(net, &head, dnode, |
| 215 | &tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]); | 222 | &tn->nametbl->publ_list[TIPC_ZONE_SCOPE]); |
| 216 | rcu_read_unlock(); | 223 | rcu_read_unlock(); |
| 217 | 224 | ||
| 218 | tipc_link_xmit(&head, dnode, dnode); | 225 | tipc_link_xmit(net, &head, dnode, dnode); |
| 219 | } | 226 | } |
| 220 | 227 | ||
| 221 | static void tipc_publ_subscribe(struct publication *publ, u32 addr) | 228 | static void tipc_publ_subscribe(struct net *net, struct publication *publ, |
| 229 | u32 addr) | ||
| 222 | { | 230 | { |
| 223 | struct tipc_node *node; | 231 | struct tipc_node *node; |
| 224 | 232 | ||
| 225 | if (in_own_node(addr)) | 233 | if (in_own_node(net, addr)) |
| 226 | return; | 234 | return; |
| 227 | 235 | ||
| 228 | node = tipc_node_find(addr); | 236 | node = tipc_node_find(net, addr); |
| 229 | if (!node) { | 237 | if (!node) { |
| 230 | pr_warn("Node subscription rejected, unknown node 0x%x\n", | 238 | pr_warn("Node subscription rejected, unknown node 0x%x\n", |
| 231 | addr); | 239 | addr); |
| @@ -237,11 +245,12 @@ static void tipc_publ_subscribe(struct publication *publ, u32 addr) | |||
| 237 | tipc_node_unlock(node); | 245 | tipc_node_unlock(node); |
| 238 | } | 246 | } |
| 239 | 247 | ||
| 240 | static void tipc_publ_unsubscribe(struct publication *publ, u32 addr) | 248 | static void tipc_publ_unsubscribe(struct net *net, struct publication *publ, |
| 249 | u32 addr) | ||
| 241 | { | 250 | { |
| 242 | struct tipc_node *node; | 251 | struct tipc_node *node; |
| 243 | 252 | ||
| 244 | node = tipc_node_find(addr); | 253 | node = tipc_node_find(net, addr); |
| 245 | if (!node) | 254 | if (!node) |
| 246 | return; | 255 | return; |
| 247 | 256 | ||
| @@ -256,16 +265,17 @@ static void tipc_publ_unsubscribe(struct publication *publ, u32 addr) | |||
| 256 | * Invoked for each publication issued by a newly failed node. | 265 | * Invoked for each publication issued by a newly failed node. |
| 257 | * Removes publication structure from name table & deletes it. | 266 | * Removes publication structure from name table & deletes it. |
| 258 | */ | 267 | */ |
| 259 | static void tipc_publ_purge(struct publication *publ, u32 addr) | 268 | static void tipc_publ_purge(struct net *net, struct publication *publ, u32 addr) |
| 260 | { | 269 | { |
| 270 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 261 | struct publication *p; | 271 | struct publication *p; |
| 262 | 272 | ||
| 263 | spin_lock_bh(&tipc_nametbl_lock); | 273 | spin_lock_bh(&tn->nametbl_lock); |
| 264 | p = tipc_nametbl_remove_publ(publ->type, publ->lower, | 274 | p = tipc_nametbl_remove_publ(net, publ->type, publ->lower, |
| 265 | publ->node, publ->ref, publ->key); | 275 | publ->node, publ->ref, publ->key); |
| 266 | if (p) | 276 | if (p) |
| 267 | tipc_publ_unsubscribe(p, addr); | 277 | tipc_publ_unsubscribe(net, p, addr); |
| 268 | spin_unlock_bh(&tipc_nametbl_lock); | 278 | spin_unlock_bh(&tn->nametbl_lock); |
| 269 | 279 | ||
| 270 | if (p != publ) { | 280 | if (p != publ) { |
| 271 | pr_err("Unable to remove publication from failed node\n" | 281 | pr_err("Unable to remove publication from failed node\n" |
| @@ -277,12 +287,12 @@ static void tipc_publ_purge(struct publication *publ, u32 addr) | |||
| 277 | kfree_rcu(p, rcu); | 287 | kfree_rcu(p, rcu); |
| 278 | } | 288 | } |
| 279 | 289 | ||
| 280 | void tipc_publ_notify(struct list_head *nsub_list, u32 addr) | 290 | void tipc_publ_notify(struct net *net, struct list_head *nsub_list, u32 addr) |
| 281 | { | 291 | { |
| 282 | struct publication *publ, *tmp; | 292 | struct publication *publ, *tmp; |
| 283 | 293 | ||
| 284 | list_for_each_entry_safe(publ, tmp, nsub_list, nodesub_list) | 294 | list_for_each_entry_safe(publ, tmp, nsub_list, nodesub_list) |
| 285 | tipc_publ_purge(publ, addr); | 295 | tipc_publ_purge(net, publ, addr); |
| 286 | } | 296 | } |
| 287 | 297 | ||
| 288 | /** | 298 | /** |
| @@ -292,25 +302,28 @@ void tipc_publ_notify(struct list_head *nsub_list, u32 addr) | |||
| 292 | * tipc_nametbl_lock must be held. | 302 | * tipc_nametbl_lock must be held. |
| 293 | * Returns the publication item if successful, otherwise NULL. | 303 | * Returns the publication item if successful, otherwise NULL. |
| 294 | */ | 304 | */ |
| 295 | static bool tipc_update_nametbl(struct distr_item *i, u32 node, u32 dtype) | 305 | static bool tipc_update_nametbl(struct net *net, struct distr_item *i, |
| 306 | u32 node, u32 dtype) | ||
| 296 | { | 307 | { |
| 297 | struct publication *publ = NULL; | 308 | struct publication *publ = NULL; |
| 298 | 309 | ||
| 299 | if (dtype == PUBLICATION) { | 310 | if (dtype == PUBLICATION) { |
| 300 | publ = tipc_nametbl_insert_publ(ntohl(i->type), ntohl(i->lower), | 311 | publ = tipc_nametbl_insert_publ(net, ntohl(i->type), |
| 312 | ntohl(i->lower), | ||
| 301 | ntohl(i->upper), | 313 | ntohl(i->upper), |
| 302 | TIPC_CLUSTER_SCOPE, node, | 314 | TIPC_CLUSTER_SCOPE, node, |
| 303 | ntohl(i->ref), ntohl(i->key)); | 315 | ntohl(i->ref), ntohl(i->key)); |
| 304 | if (publ) { | 316 | if (publ) { |
| 305 | tipc_publ_subscribe(publ, node); | 317 | tipc_publ_subscribe(net, publ, node); |
| 306 | return true; | 318 | return true; |
| 307 | } | 319 | } |
| 308 | } else if (dtype == WITHDRAWAL) { | 320 | } else if (dtype == WITHDRAWAL) { |
| 309 | publ = tipc_nametbl_remove_publ(ntohl(i->type), ntohl(i->lower), | 321 | publ = tipc_nametbl_remove_publ(net, ntohl(i->type), |
| 322 | ntohl(i->lower), | ||
| 310 | node, ntohl(i->ref), | 323 | node, ntohl(i->ref), |
| 311 | ntohl(i->key)); | 324 | ntohl(i->key)); |
| 312 | if (publ) { | 325 | if (publ) { |
| 313 | tipc_publ_unsubscribe(publ, node); | 326 | tipc_publ_unsubscribe(net, publ, node); |
| 314 | kfree_rcu(publ, rcu); | 327 | kfree_rcu(publ, rcu); |
| 315 | return true; | 328 | return true; |
| 316 | } | 329 | } |
| @@ -343,7 +356,7 @@ static void tipc_named_add_backlog(struct distr_item *i, u32 type, u32 node) | |||
| 343 | * tipc_named_process_backlog - try to process any pending name table updates | 356 | * tipc_named_process_backlog - try to process any pending name table updates |
| 344 | * from the network. | 357 | * from the network. |
| 345 | */ | 358 | */ |
| 346 | void tipc_named_process_backlog(void) | 359 | void tipc_named_process_backlog(struct net *net) |
| 347 | { | 360 | { |
| 348 | struct distr_queue_item *e, *tmp; | 361 | struct distr_queue_item *e, *tmp; |
| 349 | char addr[16]; | 362 | char addr[16]; |
| @@ -351,7 +364,7 @@ void tipc_named_process_backlog(void) | |||
| 351 | 364 | ||
| 352 | list_for_each_entry_safe(e, tmp, &tipc_dist_queue, next) { | 365 | list_for_each_entry_safe(e, tmp, &tipc_dist_queue, next) { |
| 353 | if (time_after(e->expires, now)) { | 366 | if (time_after(e->expires, now)) { |
| 354 | if (!tipc_update_nametbl(&e->i, e->node, e->dtype)) | 367 | if (!tipc_update_nametbl(net, &e->i, e->node, e->dtype)) |
| 355 | continue; | 368 | continue; |
| 356 | } else { | 369 | } else { |
| 357 | tipc_addr_string_fill(addr, e->node); | 370 | tipc_addr_string_fill(addr, e->node); |
| @@ -369,21 +382,22 @@ void tipc_named_process_backlog(void) | |||
| 369 | /** | 382 | /** |
| 370 | * tipc_named_rcv - process name table update message sent by another node | 383 | * tipc_named_rcv - process name table update message sent by another node |
| 371 | */ | 384 | */ |
| 372 | void tipc_named_rcv(struct sk_buff *buf) | 385 | void tipc_named_rcv(struct net *net, struct sk_buff *buf) |
| 373 | { | 386 | { |
| 387 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 374 | struct tipc_msg *msg = buf_msg(buf); | 388 | struct tipc_msg *msg = buf_msg(buf); |
| 375 | struct distr_item *item = (struct distr_item *)msg_data(msg); | 389 | struct distr_item *item = (struct distr_item *)msg_data(msg); |
| 376 | u32 count = msg_data_sz(msg) / ITEM_SIZE; | 390 | u32 count = msg_data_sz(msg) / ITEM_SIZE; |
| 377 | u32 node = msg_orignode(msg); | 391 | u32 node = msg_orignode(msg); |
| 378 | 392 | ||
| 379 | spin_lock_bh(&tipc_nametbl_lock); | 393 | spin_lock_bh(&tn->nametbl_lock); |
| 380 | while (count--) { | 394 | while (count--) { |
| 381 | if (!tipc_update_nametbl(item, node, msg_type(msg))) | 395 | if (!tipc_update_nametbl(net, item, node, msg_type(msg))) |
| 382 | tipc_named_add_backlog(item, msg_type(msg), node); | 396 | tipc_named_add_backlog(item, msg_type(msg), node); |
| 383 | item++; | 397 | item++; |
| 384 | } | 398 | } |
| 385 | tipc_named_process_backlog(); | 399 | tipc_named_process_backlog(net); |
| 386 | spin_unlock_bh(&tipc_nametbl_lock); | 400 | spin_unlock_bh(&tn->nametbl_lock); |
| 387 | kfree_skb(buf); | 401 | kfree_skb(buf); |
| 388 | } | 402 | } |
| 389 | 403 | ||
| @@ -394,17 +408,18 @@ void tipc_named_rcv(struct sk_buff *buf) | |||
| 394 | * All name table entries published by this node are updated to reflect | 408 | * All name table entries published by this node are updated to reflect |
| 395 | * the node's new network address. | 409 | * the node's new network address. |
| 396 | */ | 410 | */ |
| 397 | void tipc_named_reinit(void) | 411 | void tipc_named_reinit(struct net *net) |
| 398 | { | 412 | { |
| 413 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 399 | struct publication *publ; | 414 | struct publication *publ; |
| 400 | int scope; | 415 | int scope; |
| 401 | 416 | ||
| 402 | spin_lock_bh(&tipc_nametbl_lock); | 417 | spin_lock_bh(&tn->nametbl_lock); |
| 403 | 418 | ||
| 404 | for (scope = TIPC_ZONE_SCOPE; scope <= TIPC_NODE_SCOPE; scope++) | 419 | for (scope = TIPC_ZONE_SCOPE; scope <= TIPC_NODE_SCOPE; scope++) |
| 405 | list_for_each_entry_rcu(publ, &tipc_nametbl->publ_list[scope], | 420 | list_for_each_entry_rcu(publ, &tn->nametbl->publ_list[scope], |
| 406 | local_list) | 421 | local_list) |
| 407 | publ->node = tipc_own_addr; | 422 | publ->node = tn->own_addr; |
| 408 | 423 | ||
| 409 | spin_unlock_bh(&tipc_nametbl_lock); | 424 | spin_unlock_bh(&tn->nametbl_lock); |
| 410 | } | 425 | } |
diff --git a/net/tipc/name_distr.h b/net/tipc/name_distr.h index cef55cedcfb2..5ec10b59527b 100644 --- a/net/tipc/name_distr.h +++ b/net/tipc/name_distr.h | |||
| @@ -67,13 +67,13 @@ struct distr_item { | |||
| 67 | __be32 key; | 67 | __be32 key; |
| 68 | }; | 68 | }; |
| 69 | 69 | ||
| 70 | struct sk_buff *tipc_named_publish(struct publication *publ); | 70 | struct sk_buff *tipc_named_publish(struct net *net, struct publication *publ); |
| 71 | struct sk_buff *tipc_named_withdraw(struct publication *publ); | 71 | struct sk_buff *tipc_named_withdraw(struct net *net, struct publication *publ); |
| 72 | void named_cluster_distribute(struct sk_buff *buf); | 72 | void named_cluster_distribute(struct net *net, struct sk_buff *buf); |
| 73 | void tipc_named_node_up(u32 dnode); | 73 | void tipc_named_node_up(struct net *net, u32 dnode); |
| 74 | void tipc_named_rcv(struct sk_buff *buf); | 74 | void tipc_named_rcv(struct net *net, struct sk_buff *buf); |
| 75 | void tipc_named_reinit(void); | 75 | void tipc_named_reinit(struct net *net); |
| 76 | void tipc_named_process_backlog(void); | 76 | void tipc_named_process_backlog(struct net *net); |
| 77 | void tipc_publ_notify(struct list_head *nsub_list, u32 addr); | 77 | void tipc_publ_notify(struct net *net, struct list_head *nsub_list, u32 addr); |
| 78 | 78 | ||
| 79 | #endif | 79 | #endif |
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c index c8df0223371a..ce09b863528c 100644 --- a/net/tipc/name_table.c +++ b/net/tipc/name_table.c | |||
| @@ -34,11 +34,13 @@ | |||
| 34 | * POSSIBILITY OF SUCH DAMAGE. | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #include <net/sock.h> | ||
| 37 | #include "core.h" | 38 | #include "core.h" |
| 38 | #include "config.h" | 39 | #include "config.h" |
| 39 | #include "name_table.h" | 40 | #include "name_table.h" |
| 40 | #include "name_distr.h" | 41 | #include "name_distr.h" |
| 41 | #include "subscr.h" | 42 | #include "subscr.h" |
| 43 | #include "bcast.h" | ||
| 42 | 44 | ||
| 43 | #define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ | 45 | #define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ |
| 44 | 46 | ||
| @@ -105,9 +107,6 @@ struct name_seq { | |||
| 105 | struct rcu_head rcu; | 107 | struct rcu_head rcu; |
| 106 | }; | 108 | }; |
| 107 | 109 | ||
| 108 | struct name_table *tipc_nametbl; | ||
| 109 | DEFINE_SPINLOCK(tipc_nametbl_lock); | ||
| 110 | |||
| 111 | static int hash(int x) | 110 | static int hash(int x) |
| 112 | { | 111 | { |
| 113 | return x & (TIPC_NAMETBL_SIZE - 1); | 112 | return x & (TIPC_NAMETBL_SIZE - 1); |
| @@ -228,9 +227,11 @@ static u32 nameseq_locate_subseq(struct name_seq *nseq, u32 instance) | |||
| 228 | /** | 227 | /** |
| 229 | * tipc_nameseq_insert_publ | 228 | * tipc_nameseq_insert_publ |
| 230 | */ | 229 | */ |
| 231 | static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, | 230 | static struct publication *tipc_nameseq_insert_publ(struct net *net, |
| 232 | u32 type, u32 lower, u32 upper, | 231 | struct name_seq *nseq, |
| 233 | u32 scope, u32 node, u32 port, u32 key) | 232 | u32 type, u32 lower, |
| 233 | u32 upper, u32 scope, | ||
| 234 | u32 node, u32 port, u32 key) | ||
| 234 | { | 235 | { |
| 235 | struct tipc_subscription *s; | 236 | struct tipc_subscription *s; |
| 236 | struct tipc_subscription *st; | 237 | struct tipc_subscription *st; |
| @@ -315,12 +316,12 @@ static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, | |||
| 315 | list_add(&publ->zone_list, &info->zone_list); | 316 | list_add(&publ->zone_list, &info->zone_list); |
| 316 | info->zone_list_size++; | 317 | info->zone_list_size++; |
| 317 | 318 | ||
| 318 | if (in_own_cluster(node)) { | 319 | if (in_own_cluster(net, node)) { |
| 319 | list_add(&publ->cluster_list, &info->cluster_list); | 320 | list_add(&publ->cluster_list, &info->cluster_list); |
| 320 | info->cluster_list_size++; | 321 | info->cluster_list_size++; |
| 321 | } | 322 | } |
| 322 | 323 | ||
| 323 | if (in_own_node(node)) { | 324 | if (in_own_node(net, node)) { |
| 324 | list_add(&publ->node_list, &info->node_list); | 325 | list_add(&publ->node_list, &info->node_list); |
| 325 | info->node_list_size++; | 326 | info->node_list_size++; |
| 326 | } | 327 | } |
| @@ -349,8 +350,10 @@ static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, | |||
| 349 | * A failed withdraw request simply returns a failure indication and lets the | 350 | * A failed withdraw request simply returns a failure indication and lets the |
| 350 | * caller issue any error or warning messages associated with such a problem. | 351 | * caller issue any error or warning messages associated with such a problem. |
| 351 | */ | 352 | */ |
| 352 | static struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 inst, | 353 | static struct publication *tipc_nameseq_remove_publ(struct net *net, |
| 353 | u32 node, u32 ref, u32 key) | 354 | struct name_seq *nseq, |
| 355 | u32 inst, u32 node, | ||
| 356 | u32 ref, u32 key) | ||
| 354 | { | 357 | { |
| 355 | struct publication *publ; | 358 | struct publication *publ; |
| 356 | struct sub_seq *sseq = nameseq_find_subseq(nseq, inst); | 359 | struct sub_seq *sseq = nameseq_find_subseq(nseq, inst); |
| @@ -378,13 +381,13 @@ found: | |||
| 378 | info->zone_list_size--; | 381 | info->zone_list_size--; |
| 379 | 382 | ||
| 380 | /* Remove publication from cluster scope list, if present */ | 383 | /* Remove publication from cluster scope list, if present */ |
| 381 | if (in_own_cluster(node)) { | 384 | if (in_own_cluster(net, node)) { |
| 382 | list_del(&publ->cluster_list); | 385 | list_del(&publ->cluster_list); |
| 383 | info->cluster_list_size--; | 386 | info->cluster_list_size--; |
| 384 | } | 387 | } |
| 385 | 388 | ||
| 386 | /* Remove publication from node scope list, if present */ | 389 | /* Remove publication from node scope list, if present */ |
| 387 | if (in_own_node(node)) { | 390 | if (in_own_node(net, node)) { |
| 388 | list_del(&publ->node_list); | 391 | list_del(&publ->node_list); |
| 389 | info->node_list_size--; | 392 | info->node_list_size--; |
| 390 | } | 393 | } |
| @@ -447,12 +450,13 @@ static void tipc_nameseq_subscribe(struct name_seq *nseq, | |||
| 447 | } | 450 | } |
| 448 | } | 451 | } |
| 449 | 452 | ||
| 450 | static struct name_seq *nametbl_find_seq(u32 type) | 453 | static struct name_seq *nametbl_find_seq(struct net *net, u32 type) |
| 451 | { | 454 | { |
| 455 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 452 | struct hlist_head *seq_head; | 456 | struct hlist_head *seq_head; |
| 453 | struct name_seq *ns; | 457 | struct name_seq *ns; |
| 454 | 458 | ||
| 455 | seq_head = &tipc_nametbl->seq_hlist[hash(type)]; | 459 | seq_head = &tn->nametbl->seq_hlist[hash(type)]; |
| 456 | hlist_for_each_entry_rcu(ns, seq_head, ns_list) { | 460 | hlist_for_each_entry_rcu(ns, seq_head, ns_list) { |
| 457 | if (ns->type == type) | 461 | if (ns->type == type) |
| 458 | return ns; | 462 | return ns; |
| @@ -461,11 +465,13 @@ static struct name_seq *nametbl_find_seq(u32 type) | |||
| 461 | return NULL; | 465 | return NULL; |
| 462 | }; | 466 | }; |
| 463 | 467 | ||
| 464 | struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper, | 468 | struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type, |
| 465 | u32 scope, u32 node, u32 port, u32 key) | 469 | u32 lower, u32 upper, u32 scope, |
| 470 | u32 node, u32 port, u32 key) | ||
| 466 | { | 471 | { |
| 472 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 467 | struct publication *publ; | 473 | struct publication *publ; |
| 468 | struct name_seq *seq = nametbl_find_seq(type); | 474 | struct name_seq *seq = nametbl_find_seq(net, type); |
| 469 | int index = hash(type); | 475 | int index = hash(type); |
| 470 | 476 | ||
| 471 | if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) || | 477 | if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) || |
| @@ -476,29 +482,29 @@ struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper, | |||
| 476 | } | 482 | } |
| 477 | 483 | ||
| 478 | if (!seq) | 484 | if (!seq) |
| 479 | seq = tipc_nameseq_create(type, | 485 | seq = tipc_nameseq_create(type, &tn->nametbl->seq_hlist[index]); |
| 480 | &tipc_nametbl->seq_hlist[index]); | ||
| 481 | if (!seq) | 486 | if (!seq) |
| 482 | return NULL; | 487 | return NULL; |
| 483 | 488 | ||
| 484 | spin_lock_bh(&seq->lock); | 489 | spin_lock_bh(&seq->lock); |
| 485 | publ = tipc_nameseq_insert_publ(seq, type, lower, upper, | 490 | publ = tipc_nameseq_insert_publ(net, seq, type, lower, upper, |
| 486 | scope, node, port, key); | 491 | scope, node, port, key); |
| 487 | spin_unlock_bh(&seq->lock); | 492 | spin_unlock_bh(&seq->lock); |
| 488 | return publ; | 493 | return publ; |
| 489 | } | 494 | } |
| 490 | 495 | ||
| 491 | struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, | 496 | struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type, |
| 492 | u32 node, u32 ref, u32 key) | 497 | u32 lower, u32 node, u32 ref, |
| 498 | u32 key) | ||
| 493 | { | 499 | { |
| 494 | struct publication *publ; | 500 | struct publication *publ; |
| 495 | struct name_seq *seq = nametbl_find_seq(type); | 501 | struct name_seq *seq = nametbl_find_seq(net, type); |
| 496 | 502 | ||
| 497 | if (!seq) | 503 | if (!seq) |
| 498 | return NULL; | 504 | return NULL; |
| 499 | 505 | ||
| 500 | spin_lock_bh(&seq->lock); | 506 | spin_lock_bh(&seq->lock); |
| 501 | publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); | 507 | publ = tipc_nameseq_remove_publ(net, seq, lower, node, ref, key); |
| 502 | if (!seq->first_free && list_empty(&seq->subscriptions)) { | 508 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
| 503 | hlist_del_init_rcu(&seq->ns_list); | 509 | hlist_del_init_rcu(&seq->ns_list); |
| 504 | kfree(seq->sseqs); | 510 | kfree(seq->sseqs); |
| @@ -523,8 +529,10 @@ struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, | |||
| 523 | * - if name translation is attempted and fails, sets 'destnode' to 0 | 529 | * - if name translation is attempted and fails, sets 'destnode' to 0 |
| 524 | * and returns 0 | 530 | * and returns 0 |
| 525 | */ | 531 | */ |
| 526 | u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode) | 532 | u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, |
| 533 | u32 *destnode) | ||
| 527 | { | 534 | { |
| 535 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 528 | struct sub_seq *sseq; | 536 | struct sub_seq *sseq; |
| 529 | struct name_info *info; | 537 | struct name_info *info; |
| 530 | struct publication *publ; | 538 | struct publication *publ; |
| @@ -532,11 +540,11 @@ u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode) | |||
| 532 | u32 ref = 0; | 540 | u32 ref = 0; |
| 533 | u32 node = 0; | 541 | u32 node = 0; |
| 534 | 542 | ||
| 535 | if (!tipc_in_scope(*destnode, tipc_own_addr)) | 543 | if (!tipc_in_scope(*destnode, tn->own_addr)) |
| 536 | return 0; | 544 | return 0; |
| 537 | 545 | ||
| 538 | rcu_read_lock(); | 546 | rcu_read_lock(); |
| 539 | seq = nametbl_find_seq(type); | 547 | seq = nametbl_find_seq(net, type); |
| 540 | if (unlikely(!seq)) | 548 | if (unlikely(!seq)) |
| 541 | goto not_found; | 549 | goto not_found; |
| 542 | spin_lock_bh(&seq->lock); | 550 | spin_lock_bh(&seq->lock); |
| @@ -569,13 +577,13 @@ u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode) | |||
| 569 | } | 577 | } |
| 570 | 578 | ||
| 571 | /* Round-Robin Algorithm */ | 579 | /* Round-Robin Algorithm */ |
| 572 | else if (*destnode == tipc_own_addr) { | 580 | else if (*destnode == tn->own_addr) { |
| 573 | if (list_empty(&info->node_list)) | 581 | if (list_empty(&info->node_list)) |
| 574 | goto no_match; | 582 | goto no_match; |
| 575 | publ = list_first_entry(&info->node_list, struct publication, | 583 | publ = list_first_entry(&info->node_list, struct publication, |
| 576 | node_list); | 584 | node_list); |
| 577 | list_move_tail(&publ->node_list, &info->node_list); | 585 | list_move_tail(&publ->node_list, &info->node_list); |
| 578 | } else if (in_own_cluster_exact(*destnode)) { | 586 | } else if (in_own_cluster_exact(net, *destnode)) { |
| 579 | if (list_empty(&info->cluster_list)) | 587 | if (list_empty(&info->cluster_list)) |
| 580 | goto no_match; | 588 | goto no_match; |
| 581 | publ = list_first_entry(&info->cluster_list, struct publication, | 589 | publ = list_first_entry(&info->cluster_list, struct publication, |
| @@ -609,8 +617,8 @@ not_found: | |||
| 609 | * | 617 | * |
| 610 | * Returns non-zero if any off-node ports overlap | 618 | * Returns non-zero if any off-node ports overlap |
| 611 | */ | 619 | */ |
| 612 | int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, | 620 | int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper, |
| 613 | struct tipc_port_list *dports) | 621 | u32 limit, struct tipc_port_list *dports) |
| 614 | { | 622 | { |
| 615 | struct name_seq *seq; | 623 | struct name_seq *seq; |
| 616 | struct sub_seq *sseq; | 624 | struct sub_seq *sseq; |
| @@ -619,7 +627,7 @@ int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, | |||
| 619 | int res = 0; | 627 | int res = 0; |
| 620 | 628 | ||
| 621 | rcu_read_lock(); | 629 | rcu_read_lock(); |
| 622 | seq = nametbl_find_seq(type); | 630 | seq = nametbl_find_seq(net, type); |
| 623 | if (!seq) | 631 | if (!seq) |
| 624 | goto exit; | 632 | goto exit; |
| 625 | 633 | ||
| @@ -650,50 +658,55 @@ exit: | |||
| 650 | /* | 658 | /* |
| 651 | * tipc_nametbl_publish - add name publication to network name tables | 659 | * tipc_nametbl_publish - add name publication to network name tables |
| 652 | */ | 660 | */ |
| 653 | struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, | 661 | struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, |
| 654 | u32 scope, u32 port_ref, u32 key) | 662 | u32 upper, u32 scope, u32 port_ref, |
| 663 | u32 key) | ||
| 655 | { | 664 | { |
| 656 | struct publication *publ; | 665 | struct publication *publ; |
| 657 | struct sk_buff *buf = NULL; | 666 | struct sk_buff *buf = NULL; |
| 667 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 658 | 668 | ||
| 659 | spin_lock_bh(&tipc_nametbl_lock); | 669 | spin_lock_bh(&tn->nametbl_lock); |
| 660 | if (tipc_nametbl->local_publ_count >= TIPC_MAX_PUBLICATIONS) { | 670 | if (tn->nametbl->local_publ_count >= TIPC_MAX_PUBLICATIONS) { |
| 661 | pr_warn("Publication failed, local publication limit reached (%u)\n", | 671 | pr_warn("Publication failed, local publication limit reached (%u)\n", |
| 662 | TIPC_MAX_PUBLICATIONS); | 672 | TIPC_MAX_PUBLICATIONS); |
| 663 | spin_unlock_bh(&tipc_nametbl_lock); | 673 | spin_unlock_bh(&tn->nametbl_lock); |
| 664 | return NULL; | 674 | return NULL; |
| 665 | } | 675 | } |
| 666 | 676 | ||
| 667 | publ = tipc_nametbl_insert_publ(type, lower, upper, scope, | 677 | publ = tipc_nametbl_insert_publ(net, type, lower, upper, scope, |
| 668 | tipc_own_addr, port_ref, key); | 678 | tn->own_addr, port_ref, key); |
| 669 | if (likely(publ)) { | 679 | if (likely(publ)) { |
| 670 | tipc_nametbl->local_publ_count++; | 680 | tn->nametbl->local_publ_count++; |
| 671 | buf = tipc_named_publish(publ); | 681 | buf = tipc_named_publish(net, publ); |
| 672 | /* Any pending external events? */ | 682 | /* Any pending external events? */ |
| 673 | tipc_named_process_backlog(); | 683 | tipc_named_process_backlog(net); |
| 674 | } | 684 | } |
| 675 | spin_unlock_bh(&tipc_nametbl_lock); | 685 | spin_unlock_bh(&tn->nametbl_lock); |
| 676 | 686 | ||
| 677 | if (buf) | 687 | if (buf) |
| 678 | named_cluster_distribute(buf); | 688 | named_cluster_distribute(net, buf); |
| 679 | return publ; | 689 | return publ; |
| 680 | } | 690 | } |
| 681 | 691 | ||
| 682 | /** | 692 | /** |
| 683 | * tipc_nametbl_withdraw - withdraw name publication from network name tables | 693 | * tipc_nametbl_withdraw - withdraw name publication from network name tables |
| 684 | */ | 694 | */ |
| 685 | int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) | 695 | int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 ref, |
| 696 | u32 key) | ||
| 686 | { | 697 | { |
| 687 | struct publication *publ; | 698 | struct publication *publ; |
| 688 | struct sk_buff *skb = NULL; | 699 | struct sk_buff *skb = NULL; |
| 700 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 689 | 701 | ||
| 690 | spin_lock_bh(&tipc_nametbl_lock); | 702 | spin_lock_bh(&tn->nametbl_lock); |
| 691 | publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key); | 703 | publ = tipc_nametbl_remove_publ(net, type, lower, tn->own_addr, |
| 704 | ref, key); | ||
| 692 | if (likely(publ)) { | 705 | if (likely(publ)) { |
| 693 | tipc_nametbl->local_publ_count--; | 706 | tn->nametbl->local_publ_count--; |
| 694 | skb = tipc_named_withdraw(publ); | 707 | skb = tipc_named_withdraw(net, publ); |
| 695 | /* Any pending external events? */ | 708 | /* Any pending external events? */ |
| 696 | tipc_named_process_backlog(); | 709 | tipc_named_process_backlog(net); |
| 697 | list_del_init(&publ->pport_list); | 710 | list_del_init(&publ->pport_list); |
| 698 | kfree_rcu(publ, rcu); | 711 | kfree_rcu(publ, rcu); |
| 699 | } else { | 712 | } else { |
| @@ -701,10 +714,10 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) | |||
| 701 | "(type=%u, lower=%u, ref=%u, key=%u)\n", | 714 | "(type=%u, lower=%u, ref=%u, key=%u)\n", |
| 702 | type, lower, ref, key); | 715 | type, lower, ref, key); |
| 703 | } | 716 | } |
| 704 | spin_unlock_bh(&tipc_nametbl_lock); | 717 | spin_unlock_bh(&tn->nametbl_lock); |
| 705 | 718 | ||
| 706 | if (skb) { | 719 | if (skb) { |
| 707 | named_cluster_distribute(skb); | 720 | named_cluster_distribute(net, skb); |
| 708 | return 1; | 721 | return 1; |
| 709 | } | 722 | } |
| 710 | return 0; | 723 | return 0; |
| @@ -715,15 +728,15 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) | |||
| 715 | */ | 728 | */ |
| 716 | void tipc_nametbl_subscribe(struct tipc_subscription *s) | 729 | void tipc_nametbl_subscribe(struct tipc_subscription *s) |
| 717 | { | 730 | { |
| 731 | struct tipc_net *tn = net_generic(s->net, tipc_net_id); | ||
| 718 | u32 type = s->seq.type; | 732 | u32 type = s->seq.type; |
| 719 | int index = hash(type); | 733 | int index = hash(type); |
| 720 | struct name_seq *seq; | 734 | struct name_seq *seq; |
| 721 | 735 | ||
| 722 | spin_lock_bh(&tipc_nametbl_lock); | 736 | spin_lock_bh(&tn->nametbl_lock); |
| 723 | seq = nametbl_find_seq(type); | 737 | seq = nametbl_find_seq(s->net, type); |
| 724 | if (!seq) | 738 | if (!seq) |
| 725 | seq = tipc_nameseq_create(type, | 739 | seq = tipc_nameseq_create(type, &tn->nametbl->seq_hlist[index]); |
| 726 | &tipc_nametbl->seq_hlist[index]); | ||
| 727 | if (seq) { | 740 | if (seq) { |
| 728 | spin_lock_bh(&seq->lock); | 741 | spin_lock_bh(&seq->lock); |
| 729 | tipc_nameseq_subscribe(seq, s); | 742 | tipc_nameseq_subscribe(seq, s); |
| @@ -732,7 +745,7 @@ void tipc_nametbl_subscribe(struct tipc_subscription *s) | |||
| 732 | pr_warn("Failed to create subscription for {%u,%u,%u}\n", | 745 | pr_warn("Failed to create subscription for {%u,%u,%u}\n", |
| 733 | s->seq.type, s->seq.lower, s->seq.upper); | 746 | s->seq.type, s->seq.lower, s->seq.upper); |
| 734 | } | 747 | } |
| 735 | spin_unlock_bh(&tipc_nametbl_lock); | 748 | spin_unlock_bh(&tn->nametbl_lock); |
| 736 | } | 749 | } |
| 737 | 750 | ||
| 738 | /** | 751 | /** |
| @@ -740,10 +753,11 @@ void tipc_nametbl_subscribe(struct tipc_subscription *s) | |||
| 740 | */ | 753 | */ |
| 741 | void tipc_nametbl_unsubscribe(struct tipc_subscription *s) | 754 | void tipc_nametbl_unsubscribe(struct tipc_subscription *s) |
| 742 | { | 755 | { |
| 756 | struct tipc_net *tn = net_generic(s->net, tipc_net_id); | ||
| 743 | struct name_seq *seq; | 757 | struct name_seq *seq; |
| 744 | 758 | ||
| 745 | spin_lock_bh(&tipc_nametbl_lock); | 759 | spin_lock_bh(&tn->nametbl_lock); |
| 746 | seq = nametbl_find_seq(s->seq.type); | 760 | seq = nametbl_find_seq(s->net, s->seq.type); |
| 747 | if (seq != NULL) { | 761 | if (seq != NULL) { |
| 748 | spin_lock_bh(&seq->lock); | 762 | spin_lock_bh(&seq->lock); |
| 749 | list_del_init(&s->nameseq_list); | 763 | list_del_init(&s->nameseq_list); |
| @@ -756,7 +770,7 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription *s) | |||
| 756 | spin_unlock_bh(&seq->lock); | 770 | spin_unlock_bh(&seq->lock); |
| 757 | } | 771 | } |
| 758 | } | 772 | } |
| 759 | spin_unlock_bh(&tipc_nametbl_lock); | 773 | spin_unlock_bh(&tn->nametbl_lock); |
| 760 | } | 774 | } |
| 761 | 775 | ||
| 762 | /** | 776 | /** |
| @@ -858,9 +872,10 @@ static int nametbl_header(char *buf, int len, u32 depth) | |||
| 858 | /** | 872 | /** |
| 859 | * nametbl_list - print specified name table contents into the given buffer | 873 | * nametbl_list - print specified name table contents into the given buffer |
| 860 | */ | 874 | */ |
| 861 | static int nametbl_list(char *buf, int len, u32 depth_info, | 875 | static int nametbl_list(struct net *net, char *buf, int len, u32 depth_info, |
| 862 | u32 type, u32 lowbound, u32 upbound) | 876 | u32 type, u32 lowbound, u32 upbound) |
| 863 | { | 877 | { |
| 878 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 864 | struct hlist_head *seq_head; | 879 | struct hlist_head *seq_head; |
| 865 | struct name_seq *seq; | 880 | struct name_seq *seq; |
| 866 | int all_types; | 881 | int all_types; |
| @@ -880,7 +895,7 @@ static int nametbl_list(char *buf, int len, u32 depth_info, | |||
| 880 | lowbound = 0; | 895 | lowbound = 0; |
| 881 | upbound = ~0; | 896 | upbound = ~0; |
| 882 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { | 897 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { |
| 883 | seq_head = &tipc_nametbl->seq_hlist[i]; | 898 | seq_head = &tn->nametbl->seq_hlist[i]; |
| 884 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { | 899 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
| 885 | ret += nameseq_list(seq, buf + ret, len - ret, | 900 | ret += nameseq_list(seq, buf + ret, len - ret, |
| 886 | depth, seq->type, | 901 | depth, seq->type, |
| @@ -896,7 +911,7 @@ static int nametbl_list(char *buf, int len, u32 depth_info, | |||
| 896 | } | 911 | } |
| 897 | ret += nametbl_header(buf + ret, len - ret, depth); | 912 | ret += nametbl_header(buf + ret, len - ret, depth); |
| 898 | i = hash(type); | 913 | i = hash(type); |
| 899 | seq_head = &tipc_nametbl->seq_hlist[i]; | 914 | seq_head = &tn->nametbl->seq_hlist[i]; |
| 900 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { | 915 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
| 901 | if (seq->type == type) { | 916 | if (seq->type == type) { |
| 902 | ret += nameseq_list(seq, buf + ret, len - ret, | 917 | ret += nameseq_list(seq, buf + ret, len - ret, |
| @@ -909,7 +924,8 @@ static int nametbl_list(char *buf, int len, u32 depth_info, | |||
| 909 | return ret; | 924 | return ret; |
| 910 | } | 925 | } |
| 911 | 926 | ||
| 912 | struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) | 927 | struct sk_buff *tipc_nametbl_get(struct net *net, const void *req_tlv_area, |
| 928 | int req_tlv_space) | ||
| 913 | { | 929 | { |
| 914 | struct sk_buff *buf; | 930 | struct sk_buff *buf; |
| 915 | struct tipc_name_table_query *argv; | 931 | struct tipc_name_table_query *argv; |
| @@ -930,7 +946,7 @@ struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) | |||
| 930 | pb_len = ULTRA_STRING_MAX_LEN; | 946 | pb_len = ULTRA_STRING_MAX_LEN; |
| 931 | argv = (struct tipc_name_table_query *)TLV_DATA(req_tlv_area); | 947 | argv = (struct tipc_name_table_query *)TLV_DATA(req_tlv_area); |
| 932 | rcu_read_lock(); | 948 | rcu_read_lock(); |
| 933 | str_len = nametbl_list(pb, pb_len, ntohl(argv->depth), | 949 | str_len = nametbl_list(net, pb, pb_len, ntohl(argv->depth), |
| 934 | ntohl(argv->type), | 950 | ntohl(argv->type), |
| 935 | ntohl(argv->lowbound), ntohl(argv->upbound)); | 951 | ntohl(argv->lowbound), ntohl(argv->upbound)); |
| 936 | rcu_read_unlock(); | 952 | rcu_read_unlock(); |
| @@ -941,8 +957,10 @@ struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) | |||
| 941 | return buf; | 957 | return buf; |
| 942 | } | 958 | } |
| 943 | 959 | ||
| 944 | int tipc_nametbl_init(void) | 960 | int tipc_nametbl_init(struct net *net) |
| 945 | { | 961 | { |
| 962 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 963 | struct name_table *tipc_nametbl; | ||
| 946 | int i; | 964 | int i; |
| 947 | 965 | ||
| 948 | tipc_nametbl = kzalloc(sizeof(*tipc_nametbl), GFP_ATOMIC); | 966 | tipc_nametbl = kzalloc(sizeof(*tipc_nametbl), GFP_ATOMIC); |
| @@ -955,6 +973,8 @@ int tipc_nametbl_init(void) | |||
| 955 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]); | 973 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]); |
| 956 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]); | 974 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]); |
| 957 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_NODE_SCOPE]); | 975 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_NODE_SCOPE]); |
| 976 | tn->nametbl = tipc_nametbl; | ||
| 977 | spin_lock_init(&tn->nametbl_lock); | ||
| 958 | return 0; | 978 | return 0; |
| 959 | } | 979 | } |
| 960 | 980 | ||
| @@ -963,7 +983,7 @@ int tipc_nametbl_init(void) | |||
| 963 | * | 983 | * |
| 964 | * tipc_nametbl_lock must be held when calling this function | 984 | * tipc_nametbl_lock must be held when calling this function |
| 965 | */ | 985 | */ |
| 966 | static void tipc_purge_publications(struct name_seq *seq) | 986 | static void tipc_purge_publications(struct net *net, struct name_seq *seq) |
| 967 | { | 987 | { |
| 968 | struct publication *publ, *safe; | 988 | struct publication *publ, *safe; |
| 969 | struct sub_seq *sseq; | 989 | struct sub_seq *sseq; |
| @@ -973,8 +993,8 @@ static void tipc_purge_publications(struct name_seq *seq) | |||
| 973 | sseq = seq->sseqs; | 993 | sseq = seq->sseqs; |
| 974 | info = sseq->info; | 994 | info = sseq->info; |
| 975 | list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) { | 995 | list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) { |
| 976 | tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node, | 996 | tipc_nametbl_remove_publ(net, publ->type, publ->lower, |
| 977 | publ->ref, publ->key); | 997 | publ->node, publ->ref, publ->key); |
| 978 | kfree_rcu(publ, rcu); | 998 | kfree_rcu(publ, rcu); |
| 979 | } | 999 | } |
| 980 | hlist_del_init_rcu(&seq->ns_list); | 1000 | hlist_del_init_rcu(&seq->ns_list); |
| @@ -984,25 +1004,27 @@ static void tipc_purge_publications(struct name_seq *seq) | |||
| 984 | kfree_rcu(seq, rcu); | 1004 | kfree_rcu(seq, rcu); |
| 985 | } | 1005 | } |
| 986 | 1006 | ||
| 987 | void tipc_nametbl_stop(void) | 1007 | void tipc_nametbl_stop(struct net *net) |
| 988 | { | 1008 | { |
| 989 | u32 i; | 1009 | u32 i; |
| 990 | struct name_seq *seq; | 1010 | struct name_seq *seq; |
| 991 | struct hlist_head *seq_head; | 1011 | struct hlist_head *seq_head; |
| 1012 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 1013 | struct name_table *tipc_nametbl = tn->nametbl; | ||
| 992 | 1014 | ||
| 993 | /* Verify name table is empty and purge any lingering | 1015 | /* Verify name table is empty and purge any lingering |
| 994 | * publications, then release the name table | 1016 | * publications, then release the name table |
| 995 | */ | 1017 | */ |
| 996 | spin_lock_bh(&tipc_nametbl_lock); | 1018 | spin_lock_bh(&tn->nametbl_lock); |
| 997 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { | 1019 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { |
| 998 | if (hlist_empty(&tipc_nametbl->seq_hlist[i])) | 1020 | if (hlist_empty(&tipc_nametbl->seq_hlist[i])) |
| 999 | continue; | 1021 | continue; |
| 1000 | seq_head = &tipc_nametbl->seq_hlist[i]; | 1022 | seq_head = &tipc_nametbl->seq_hlist[i]; |
| 1001 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { | 1023 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
| 1002 | tipc_purge_publications(seq); | 1024 | tipc_purge_publications(net, seq); |
| 1003 | } | 1025 | } |
| 1004 | } | 1026 | } |
| 1005 | spin_unlock_bh(&tipc_nametbl_lock); | 1027 | spin_unlock_bh(&tn->nametbl_lock); |
| 1006 | 1028 | ||
| 1007 | synchronize_net(); | 1029 | synchronize_net(); |
| 1008 | kfree(tipc_nametbl); | 1030 | kfree(tipc_nametbl); |
| @@ -1106,9 +1128,10 @@ static int __tipc_nl_subseq_list(struct tipc_nl_msg *msg, struct name_seq *seq, | |||
| 1106 | return 0; | 1128 | return 0; |
| 1107 | } | 1129 | } |
| 1108 | 1130 | ||
| 1109 | static int __tipc_nl_seq_list(struct tipc_nl_msg *msg, u32 *last_type, | 1131 | static int tipc_nl_seq_list(struct net *net, struct tipc_nl_msg *msg, |
| 1110 | u32 *last_lower, u32 *last_publ) | 1132 | u32 *last_type, u32 *last_lower, u32 *last_publ) |
| 1111 | { | 1133 | { |
| 1134 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 1112 | struct hlist_head *seq_head; | 1135 | struct hlist_head *seq_head; |
| 1113 | struct name_seq *seq = NULL; | 1136 | struct name_seq *seq = NULL; |
| 1114 | int err; | 1137 | int err; |
| @@ -1120,10 +1143,10 @@ static int __tipc_nl_seq_list(struct tipc_nl_msg *msg, u32 *last_type, | |||
| 1120 | i = 0; | 1143 | i = 0; |
| 1121 | 1144 | ||
| 1122 | for (; i < TIPC_NAMETBL_SIZE; i++) { | 1145 | for (; i < TIPC_NAMETBL_SIZE; i++) { |
| 1123 | seq_head = &tipc_nametbl->seq_hlist[i]; | 1146 | seq_head = &tn->nametbl->seq_hlist[i]; |
| 1124 | 1147 | ||
| 1125 | if (*last_type) { | 1148 | if (*last_type) { |
| 1126 | seq = nametbl_find_seq(*last_type); | 1149 | seq = nametbl_find_seq(net, *last_type); |
| 1127 | if (!seq) | 1150 | if (!seq) |
| 1128 | return -EPIPE; | 1151 | return -EPIPE; |
| 1129 | } else { | 1152 | } else { |
| @@ -1157,6 +1180,7 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 1157 | u32 last_type = cb->args[0]; | 1180 | u32 last_type = cb->args[0]; |
| 1158 | u32 last_lower = cb->args[1]; | 1181 | u32 last_lower = cb->args[1]; |
| 1159 | u32 last_publ = cb->args[2]; | 1182 | u32 last_publ = cb->args[2]; |
| 1183 | struct net *net = sock_net(skb->sk); | ||
| 1160 | struct tipc_nl_msg msg; | 1184 | struct tipc_nl_msg msg; |
| 1161 | 1185 | ||
| 1162 | if (done) | 1186 | if (done) |
| @@ -1167,7 +1191,7 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 1167 | msg.seq = cb->nlh->nlmsg_seq; | 1191 | msg.seq = cb->nlh->nlmsg_seq; |
| 1168 | 1192 | ||
| 1169 | rcu_read_lock(); | 1193 | rcu_read_lock(); |
| 1170 | err = __tipc_nl_seq_list(&msg, &last_type, &last_lower, &last_publ); | 1194 | err = tipc_nl_seq_list(net, &msg, &last_type, &last_lower, &last_publ); |
| 1171 | if (!err) { | 1195 | if (!err) { |
| 1172 | done = 1; | 1196 | done = 1; |
| 1173 | } else if (err != -EMSGSIZE) { | 1197 | } else if (err != -EMSGSIZE) { |
diff --git a/net/tipc/name_table.h b/net/tipc/name_table.h index 5f0dee92010d..f67b3d8d4b2f 100644 --- a/net/tipc/name_table.h +++ b/net/tipc/name_table.h | |||
| @@ -95,26 +95,27 @@ struct name_table { | |||
| 95 | u32 local_publ_count; | 95 | u32 local_publ_count; |
| 96 | }; | 96 | }; |
| 97 | 97 | ||
| 98 | extern spinlock_t tipc_nametbl_lock; | ||
| 99 | extern struct name_table *tipc_nametbl; | ||
| 100 | |||
| 101 | int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb); | 98 | int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb); |
| 102 | 99 | ||
| 103 | struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space); | 100 | struct sk_buff *tipc_nametbl_get(struct net *net, const void *req_tlv_area, |
| 104 | u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *node); | 101 | int req_tlv_space); |
| 105 | int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, | 102 | u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, u32 *node); |
| 106 | struct tipc_port_list *dports); | 103 | int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper, |
| 107 | struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, | 104 | u32 limit, struct tipc_port_list *dports); |
| 108 | u32 scope, u32 port_ref, u32 key); | 105 | struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, |
| 109 | int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key); | 106 | u32 upper, u32 scope, u32 port_ref, |
| 110 | struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper, | 107 | u32 key); |
| 111 | u32 scope, u32 node, u32 ref, | 108 | int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 ref, |
| 109 | u32 key); | ||
| 110 | struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type, | ||
| 111 | u32 lower, u32 upper, u32 scope, | ||
| 112 | u32 node, u32 ref, u32 key); | ||
| 113 | struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type, | ||
| 114 | u32 lower, u32 node, u32 ref, | ||
| 112 | u32 key); | 115 | u32 key); |
| 113 | struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, u32 node, | ||
| 114 | u32 ref, u32 key); | ||
| 115 | void tipc_nametbl_subscribe(struct tipc_subscription *s); | 116 | void tipc_nametbl_subscribe(struct tipc_subscription *s); |
| 116 | void tipc_nametbl_unsubscribe(struct tipc_subscription *s); | 117 | void tipc_nametbl_unsubscribe(struct tipc_subscription *s); |
| 117 | int tipc_nametbl_init(void); | 118 | int tipc_nametbl_init(struct net *net); |
| 118 | void tipc_nametbl_stop(void); | 119 | void tipc_nametbl_stop(struct net *net); |
| 119 | 120 | ||
| 120 | #endif | 121 | #endif |
diff --git a/net/tipc/net.c b/net/tipc/net.c index cf13df3cde8f..263267e0e7fe 100644 --- a/net/tipc/net.c +++ b/net/tipc/net.c | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | #include "socket.h" | 41 | #include "socket.h" |
| 42 | #include "node.h" | 42 | #include "node.h" |
| 43 | #include "config.h" | 43 | #include "config.h" |
| 44 | #include "bcast.h" | ||
| 44 | 45 | ||
| 45 | static const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = { | 46 | static const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = { |
| 46 | [TIPC_NLA_NET_UNSPEC] = { .type = NLA_UNSPEC }, | 47 | [TIPC_NLA_NET_UNSPEC] = { .type = NLA_UNSPEC }, |
| @@ -108,44 +109,50 @@ static const struct nla_policy tipc_nl_net_policy[TIPC_NLA_NET_MAX + 1] = { | |||
| 108 | * - A local spin_lock protecting the queue of subscriber events. | 109 | * - A local spin_lock protecting the queue of subscriber events. |
| 109 | */ | 110 | */ |
| 110 | 111 | ||
| 111 | int tipc_net_start(u32 addr) | 112 | int tipc_net_start(struct net *net, u32 addr) |
| 112 | { | 113 | { |
| 114 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 113 | char addr_string[16]; | 115 | char addr_string[16]; |
| 114 | int res; | 116 | int res; |
| 115 | 117 | ||
| 116 | tipc_own_addr = addr; | 118 | tn->own_addr = addr; |
| 117 | tipc_named_reinit(); | 119 | tipc_named_reinit(net); |
| 118 | tipc_sk_reinit(); | 120 | tipc_sk_reinit(net); |
| 119 | res = tipc_bclink_init(); | 121 | res = tipc_bclink_init(net); |
| 120 | if (res) | 122 | if (res) |
| 121 | return res; | 123 | return res; |
| 122 | 124 | ||
| 123 | tipc_nametbl_publish(TIPC_CFG_SRV, tipc_own_addr, tipc_own_addr, | 125 | tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr, |
| 124 | TIPC_ZONE_SCOPE, 0, tipc_own_addr); | 126 | TIPC_ZONE_SCOPE, 0, tn->own_addr); |
| 125 | 127 | ||
| 126 | pr_info("Started in network mode\n"); | 128 | pr_info("Started in network mode\n"); |
| 127 | pr_info("Own node address %s, network identity %u\n", | 129 | pr_info("Own node address %s, network identity %u\n", |
| 128 | tipc_addr_string_fill(addr_string, tipc_own_addr), tipc_net_id); | 130 | tipc_addr_string_fill(addr_string, tn->own_addr), |
| 131 | tn->net_id); | ||
| 129 | return 0; | 132 | return 0; |
| 130 | } | 133 | } |
| 131 | 134 | ||
| 132 | void tipc_net_stop(void) | 135 | void tipc_net_stop(struct net *net) |
| 133 | { | 136 | { |
| 134 | if (!tipc_own_addr) | 137 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 138 | |||
| 139 | if (!tn->own_addr) | ||
| 135 | return; | 140 | return; |
| 136 | 141 | ||
| 137 | tipc_nametbl_withdraw(TIPC_CFG_SRV, tipc_own_addr, 0, tipc_own_addr); | 142 | tipc_nametbl_withdraw(net, TIPC_CFG_SRV, tn->own_addr, 0, |
| 143 | tn->own_addr); | ||
| 138 | rtnl_lock(); | 144 | rtnl_lock(); |
| 139 | tipc_bearer_stop(); | 145 | tipc_bearer_stop(net); |
| 140 | tipc_bclink_stop(); | 146 | tipc_bclink_stop(net); |
| 141 | tipc_node_stop(); | 147 | tipc_node_stop(net); |
| 142 | rtnl_unlock(); | 148 | rtnl_unlock(); |
| 143 | 149 | ||
| 144 | pr_info("Left network mode\n"); | 150 | pr_info("Left network mode\n"); |
| 145 | } | 151 | } |
| 146 | 152 | ||
| 147 | static int __tipc_nl_add_net(struct tipc_nl_msg *msg) | 153 | static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg) |
| 148 | { | 154 | { |
| 155 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 149 | void *hdr; | 156 | void *hdr; |
| 150 | struct nlattr *attrs; | 157 | struct nlattr *attrs; |
| 151 | 158 | ||
| @@ -158,7 +165,7 @@ static int __tipc_nl_add_net(struct tipc_nl_msg *msg) | |||
| 158 | if (!attrs) | 165 | if (!attrs) |
| 159 | goto msg_full; | 166 | goto msg_full; |
| 160 | 167 | ||
| 161 | if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tipc_net_id)) | 168 | if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tn->net_id)) |
| 162 | goto attr_msg_full; | 169 | goto attr_msg_full; |
| 163 | 170 | ||
| 164 | nla_nest_end(msg->skb, attrs); | 171 | nla_nest_end(msg->skb, attrs); |
| @@ -176,6 +183,7 @@ msg_full: | |||
| 176 | 183 | ||
| 177 | int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb) | 184 | int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb) |
| 178 | { | 185 | { |
| 186 | struct net *net = sock_net(skb->sk); | ||
| 179 | int err; | 187 | int err; |
| 180 | int done = cb->args[0]; | 188 | int done = cb->args[0]; |
| 181 | struct tipc_nl_msg msg; | 189 | struct tipc_nl_msg msg; |
| @@ -187,7 +195,7 @@ int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 187 | msg.portid = NETLINK_CB(cb->skb).portid; | 195 | msg.portid = NETLINK_CB(cb->skb).portid; |
| 188 | msg.seq = cb->nlh->nlmsg_seq; | 196 | msg.seq = cb->nlh->nlmsg_seq; |
| 189 | 197 | ||
| 190 | err = __tipc_nl_add_net(&msg); | 198 | err = __tipc_nl_add_net(net, &msg); |
| 191 | if (err) | 199 | if (err) |
| 192 | goto out; | 200 | goto out; |
| 193 | 201 | ||
| @@ -200,8 +208,10 @@ out: | |||
| 200 | 208 | ||
| 201 | int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) | 209 | int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) |
| 202 | { | 210 | { |
| 203 | int err; | 211 | struct net *net = genl_info_net(info); |
| 212 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 204 | struct nlattr *attrs[TIPC_NLA_NET_MAX + 1]; | 213 | struct nlattr *attrs[TIPC_NLA_NET_MAX + 1]; |
| 214 | int err; | ||
| 205 | 215 | ||
| 206 | if (!info->attrs[TIPC_NLA_NET]) | 216 | if (!info->attrs[TIPC_NLA_NET]) |
| 207 | return -EINVAL; | 217 | return -EINVAL; |
| @@ -216,21 +226,21 @@ int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) | |||
| 216 | u32 val; | 226 | u32 val; |
| 217 | 227 | ||
| 218 | /* Can't change net id once TIPC has joined a network */ | 228 | /* Can't change net id once TIPC has joined a network */ |
| 219 | if (tipc_own_addr) | 229 | if (tn->own_addr) |
| 220 | return -EPERM; | 230 | return -EPERM; |
| 221 | 231 | ||
| 222 | val = nla_get_u32(attrs[TIPC_NLA_NET_ID]); | 232 | val = nla_get_u32(attrs[TIPC_NLA_NET_ID]); |
| 223 | if (val < 1 || val > 9999) | 233 | if (val < 1 || val > 9999) |
| 224 | return -EINVAL; | 234 | return -EINVAL; |
| 225 | 235 | ||
| 226 | tipc_net_id = val; | 236 | tn->net_id = val; |
| 227 | } | 237 | } |
| 228 | 238 | ||
| 229 | if (attrs[TIPC_NLA_NET_ADDR]) { | 239 | if (attrs[TIPC_NLA_NET_ADDR]) { |
| 230 | u32 addr; | 240 | u32 addr; |
| 231 | 241 | ||
| 232 | /* Can't change net addr once TIPC has joined a network */ | 242 | /* Can't change net addr once TIPC has joined a network */ |
| 233 | if (tipc_own_addr) | 243 | if (tn->own_addr) |
| 234 | return -EPERM; | 244 | return -EPERM; |
| 235 | 245 | ||
| 236 | addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]); | 246 | addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]); |
| @@ -238,7 +248,7 @@ int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) | |||
| 238 | return -EINVAL; | 248 | return -EINVAL; |
| 239 | 249 | ||
| 240 | rtnl_lock(); | 250 | rtnl_lock(); |
| 241 | tipc_net_start(addr); | 251 | tipc_net_start(net, addr); |
| 242 | rtnl_unlock(); | 252 | rtnl_unlock(); |
| 243 | } | 253 | } |
| 244 | 254 | ||
diff --git a/net/tipc/net.h b/net/tipc/net.h index a81c1b9eb150..77a7a118911d 100644 --- a/net/tipc/net.h +++ b/net/tipc/net.h | |||
| @@ -39,9 +39,9 @@ | |||
| 39 | 39 | ||
| 40 | #include <net/genetlink.h> | 40 | #include <net/genetlink.h> |
| 41 | 41 | ||
| 42 | int tipc_net_start(u32 addr); | 42 | int tipc_net_start(struct net *net, u32 addr); |
| 43 | 43 | ||
| 44 | void tipc_net_stop(void); | 44 | void tipc_net_stop(struct net *net); |
| 45 | 45 | ||
| 46 | int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb); | 46 | int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb); |
| 47 | int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info); | 47 | int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info); |
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c index b891e3905bc4..fe0f5134ce15 100644 --- a/net/tipc/netlink.c +++ b/net/tipc/netlink.c | |||
| @@ -46,6 +46,7 @@ | |||
| 46 | 46 | ||
| 47 | static int handle_cmd(struct sk_buff *skb, struct genl_info *info) | 47 | static int handle_cmd(struct sk_buff *skb, struct genl_info *info) |
| 48 | { | 48 | { |
| 49 | struct net *net = genl_info_net(info); | ||
| 49 | struct sk_buff *rep_buf; | 50 | struct sk_buff *rep_buf; |
| 50 | struct nlmsghdr *rep_nlh; | 51 | struct nlmsghdr *rep_nlh; |
| 51 | struct nlmsghdr *req_nlh = info->nlhdr; | 52 | struct nlmsghdr *req_nlh = info->nlhdr; |
| @@ -53,22 +54,24 @@ static int handle_cmd(struct sk_buff *skb, struct genl_info *info) | |||
| 53 | int hdr_space = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN); | 54 | int hdr_space = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN); |
| 54 | u16 cmd; | 55 | u16 cmd; |
| 55 | 56 | ||
| 56 | if ((req_userhdr->cmd & 0xC000) && (!netlink_capable(skb, CAP_NET_ADMIN))) | 57 | if ((req_userhdr->cmd & 0xC000) && |
| 58 | (!netlink_net_capable(skb, CAP_NET_ADMIN))) | ||
| 57 | cmd = TIPC_CMD_NOT_NET_ADMIN; | 59 | cmd = TIPC_CMD_NOT_NET_ADMIN; |
| 58 | else | 60 | else |
| 59 | cmd = req_userhdr->cmd; | 61 | cmd = req_userhdr->cmd; |
| 60 | 62 | ||
| 61 | rep_buf = tipc_cfg_do_cmd(req_userhdr->dest, cmd, | 63 | rep_buf = tipc_cfg_do_cmd(net, req_userhdr->dest, cmd, |
| 62 | nlmsg_data(req_nlh) + GENL_HDRLEN + TIPC_GENL_HDRLEN, | 64 | nlmsg_data(req_nlh) + GENL_HDRLEN + |
| 63 | nlmsg_attrlen(req_nlh, GENL_HDRLEN + TIPC_GENL_HDRLEN), | 65 | TIPC_GENL_HDRLEN, |
| 64 | hdr_space); | 66 | nlmsg_attrlen(req_nlh, GENL_HDRLEN + |
| 67 | TIPC_GENL_HDRLEN), hdr_space); | ||
| 65 | 68 | ||
| 66 | if (rep_buf) { | 69 | if (rep_buf) { |
| 67 | skb_push(rep_buf, hdr_space); | 70 | skb_push(rep_buf, hdr_space); |
| 68 | rep_nlh = nlmsg_hdr(rep_buf); | 71 | rep_nlh = nlmsg_hdr(rep_buf); |
| 69 | memcpy(rep_nlh, req_nlh, hdr_space); | 72 | memcpy(rep_nlh, req_nlh, hdr_space); |
| 70 | rep_nlh->nlmsg_len = rep_buf->len; | 73 | rep_nlh->nlmsg_len = rep_buf->len; |
| 71 | genlmsg_unicast(&init_net, rep_buf, NETLINK_CB(skb).portid); | 74 | genlmsg_unicast(net, rep_buf, NETLINK_CB(skb).portid); |
| 72 | } | 75 | } |
| 73 | 76 | ||
| 74 | return 0; | 77 | return 0; |
| @@ -93,6 +96,7 @@ static struct genl_family tipc_genl_family = { | |||
| 93 | .version = TIPC_GENL_VERSION, | 96 | .version = TIPC_GENL_VERSION, |
| 94 | .hdrsize = TIPC_GENL_HDRLEN, | 97 | .hdrsize = TIPC_GENL_HDRLEN, |
| 95 | .maxattr = 0, | 98 | .maxattr = 0, |
| 99 | .netnsok = true, | ||
| 96 | }; | 100 | }; |
| 97 | 101 | ||
| 98 | /* Legacy ASCII API */ | 102 | /* Legacy ASCII API */ |
| @@ -112,6 +116,7 @@ struct genl_family tipc_genl_v2_family = { | |||
| 112 | .version = TIPC_GENL_V2_VERSION, | 116 | .version = TIPC_GENL_V2_VERSION, |
| 113 | .hdrsize = 0, | 117 | .hdrsize = 0, |
| 114 | .maxattr = TIPC_NLA_MAX, | 118 | .maxattr = TIPC_NLA_MAX, |
| 119 | .netnsok = true, | ||
| 115 | }; | 120 | }; |
| 116 | 121 | ||
| 117 | static const struct genl_ops tipc_genl_v2_ops[] = { | 122 | static const struct genl_ops tipc_genl_v2_ops[] = { |
diff --git a/net/tipc/netlink.h b/net/tipc/netlink.h index 1425c6869de0..ae2f2d923a15 100644 --- a/net/tipc/netlink.h +++ b/net/tipc/netlink.h | |||
| @@ -45,4 +45,7 @@ struct tipc_nl_msg { | |||
| 45 | u32 seq; | 45 | u32 seq; |
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | int tipc_netlink_start(void); | ||
| 49 | void tipc_netlink_stop(void); | ||
| 50 | |||
| 48 | #endif | 51 | #endif |
diff --git a/net/tipc/node.c b/net/tipc/node.c index 8d353ec77a66..ee5d33cfcf80 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c | |||
| @@ -40,17 +40,9 @@ | |||
| 40 | #include "name_distr.h" | 40 | #include "name_distr.h" |
| 41 | #include "socket.h" | 41 | #include "socket.h" |
| 42 | 42 | ||
| 43 | #define NODE_HTABLE_SIZE 512 | ||
| 44 | |||
| 45 | static void node_lost_contact(struct tipc_node *n_ptr); | 43 | static void node_lost_contact(struct tipc_node *n_ptr); |
| 46 | static void node_established_contact(struct tipc_node *n_ptr); | 44 | static void node_established_contact(struct tipc_node *n_ptr); |
| 47 | 45 | ||
| 48 | static struct hlist_head node_htable[NODE_HTABLE_SIZE]; | ||
| 49 | LIST_HEAD(tipc_node_list); | ||
| 50 | static u32 tipc_num_nodes; | ||
| 51 | static u32 tipc_num_links; | ||
| 52 | static DEFINE_SPINLOCK(node_list_lock); | ||
| 53 | |||
| 54 | struct tipc_sock_conn { | 46 | struct tipc_sock_conn { |
| 55 | u32 port; | 47 | u32 port; |
| 56 | u32 peer_port; | 48 | u32 peer_port; |
| @@ -78,15 +70,17 @@ static unsigned int tipc_hashfn(u32 addr) | |||
| 78 | /* | 70 | /* |
| 79 | * tipc_node_find - locate specified node object, if it exists | 71 | * tipc_node_find - locate specified node object, if it exists |
| 80 | */ | 72 | */ |
| 81 | struct tipc_node *tipc_node_find(u32 addr) | 73 | struct tipc_node *tipc_node_find(struct net *net, u32 addr) |
| 82 | { | 74 | { |
| 75 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 83 | struct tipc_node *node; | 76 | struct tipc_node *node; |
| 84 | 77 | ||
| 85 | if (unlikely(!in_own_cluster_exact(addr))) | 78 | if (unlikely(!in_own_cluster_exact(net, addr))) |
| 86 | return NULL; | 79 | return NULL; |
| 87 | 80 | ||
| 88 | rcu_read_lock(); | 81 | rcu_read_lock(); |
| 89 | hlist_for_each_entry_rcu(node, &node_htable[tipc_hashfn(addr)], hash) { | 82 | hlist_for_each_entry_rcu(node, &tn->node_htable[tipc_hashfn(addr)], |
| 83 | hash) { | ||
| 90 | if (node->addr == addr) { | 84 | if (node->addr == addr) { |
| 91 | rcu_read_unlock(); | 85 | rcu_read_unlock(); |
| 92 | return node; | 86 | return node; |
| @@ -96,20 +90,22 @@ struct tipc_node *tipc_node_find(u32 addr) | |||
| 96 | return NULL; | 90 | return NULL; |
| 97 | } | 91 | } |
| 98 | 92 | ||
| 99 | struct tipc_node *tipc_node_create(u32 addr) | 93 | struct tipc_node *tipc_node_create(struct net *net, u32 addr) |
| 100 | { | 94 | { |
| 95 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 101 | struct tipc_node *n_ptr, *temp_node; | 96 | struct tipc_node *n_ptr, *temp_node; |
| 102 | 97 | ||
| 103 | spin_lock_bh(&node_list_lock); | 98 | spin_lock_bh(&tn->node_list_lock); |
| 104 | 99 | ||
| 105 | n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC); | 100 | n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC); |
| 106 | if (!n_ptr) { | 101 | if (!n_ptr) { |
| 107 | spin_unlock_bh(&node_list_lock); | 102 | spin_unlock_bh(&tn->node_list_lock); |
| 108 | pr_warn("Node creation failed, no memory\n"); | 103 | pr_warn("Node creation failed, no memory\n"); |
| 109 | return NULL; | 104 | return NULL; |
| 110 | } | 105 | } |
| 111 | 106 | ||
| 112 | n_ptr->addr = addr; | 107 | n_ptr->addr = addr; |
| 108 | n_ptr->net = net; | ||
| 113 | spin_lock_init(&n_ptr->lock); | 109 | spin_lock_init(&n_ptr->lock); |
| 114 | INIT_HLIST_NODE(&n_ptr->hash); | 110 | INIT_HLIST_NODE(&n_ptr->hash); |
| 115 | INIT_LIST_HEAD(&n_ptr->list); | 111 | INIT_LIST_HEAD(&n_ptr->list); |
| @@ -118,9 +114,9 @@ struct tipc_node *tipc_node_create(u32 addr) | |||
| 118 | skb_queue_head_init(&n_ptr->waiting_sks); | 114 | skb_queue_head_init(&n_ptr->waiting_sks); |
| 119 | __skb_queue_head_init(&n_ptr->bclink.deferred_queue); | 115 | __skb_queue_head_init(&n_ptr->bclink.deferred_queue); |
| 120 | 116 | ||
| 121 | hlist_add_head_rcu(&n_ptr->hash, &node_htable[tipc_hashfn(addr)]); | 117 | hlist_add_head_rcu(&n_ptr->hash, &tn->node_htable[tipc_hashfn(addr)]); |
| 122 | 118 | ||
| 123 | list_for_each_entry_rcu(temp_node, &tipc_node_list, list) { | 119 | list_for_each_entry_rcu(temp_node, &tn->node_list, list) { |
| 124 | if (n_ptr->addr < temp_node->addr) | 120 | if (n_ptr->addr < temp_node->addr) |
| 125 | break; | 121 | break; |
| 126 | } | 122 | } |
| @@ -128,40 +124,41 @@ struct tipc_node *tipc_node_create(u32 addr) | |||
| 128 | n_ptr->action_flags = TIPC_WAIT_PEER_LINKS_DOWN; | 124 | n_ptr->action_flags = TIPC_WAIT_PEER_LINKS_DOWN; |
| 129 | n_ptr->signature = INVALID_NODE_SIG; | 125 | n_ptr->signature = INVALID_NODE_SIG; |
| 130 | 126 | ||
| 131 | tipc_num_nodes++; | 127 | tn->num_nodes++; |
| 132 | 128 | ||
| 133 | spin_unlock_bh(&node_list_lock); | 129 | spin_unlock_bh(&tn->node_list_lock); |
| 134 | return n_ptr; | 130 | return n_ptr; |
| 135 | } | 131 | } |
| 136 | 132 | ||
| 137 | static void tipc_node_delete(struct tipc_node *n_ptr) | 133 | static void tipc_node_delete(struct tipc_net *tn, struct tipc_node *n_ptr) |
| 138 | { | 134 | { |
| 139 | list_del_rcu(&n_ptr->list); | 135 | list_del_rcu(&n_ptr->list); |
| 140 | hlist_del_rcu(&n_ptr->hash); | 136 | hlist_del_rcu(&n_ptr->hash); |
| 141 | kfree_rcu(n_ptr, rcu); | 137 | kfree_rcu(n_ptr, rcu); |
| 142 | 138 | ||
| 143 | tipc_num_nodes--; | 139 | tn->num_nodes--; |
| 144 | } | 140 | } |
| 145 | 141 | ||
| 146 | void tipc_node_stop(void) | 142 | void tipc_node_stop(struct net *net) |
| 147 | { | 143 | { |
| 144 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 148 | struct tipc_node *node, *t_node; | 145 | struct tipc_node *node, *t_node; |
| 149 | 146 | ||
| 150 | spin_lock_bh(&node_list_lock); | 147 | spin_lock_bh(&tn->node_list_lock); |
| 151 | list_for_each_entry_safe(node, t_node, &tipc_node_list, list) | 148 | list_for_each_entry_safe(node, t_node, &tn->node_list, list) |
| 152 | tipc_node_delete(node); | 149 | tipc_node_delete(tn, node); |
| 153 | spin_unlock_bh(&node_list_lock); | 150 | spin_unlock_bh(&tn->node_list_lock); |
| 154 | } | 151 | } |
| 155 | 152 | ||
| 156 | int tipc_node_add_conn(u32 dnode, u32 port, u32 peer_port) | 153 | int tipc_node_add_conn(struct net *net, u32 dnode, u32 port, u32 peer_port) |
| 157 | { | 154 | { |
| 158 | struct tipc_node *node; | 155 | struct tipc_node *node; |
| 159 | struct tipc_sock_conn *conn; | 156 | struct tipc_sock_conn *conn; |
| 160 | 157 | ||
| 161 | if (in_own_node(dnode)) | 158 | if (in_own_node(net, dnode)) |
| 162 | return 0; | 159 | return 0; |
| 163 | 160 | ||
| 164 | node = tipc_node_find(dnode); | 161 | node = tipc_node_find(net, dnode); |
| 165 | if (!node) { | 162 | if (!node) { |
| 166 | pr_warn("Connecting sock to node 0x%x failed\n", dnode); | 163 | pr_warn("Connecting sock to node 0x%x failed\n", dnode); |
| 167 | return -EHOSTUNREACH; | 164 | return -EHOSTUNREACH; |
| @@ -179,15 +176,15 @@ int tipc_node_add_conn(u32 dnode, u32 port, u32 peer_port) | |||
| 179 | return 0; | 176 | return 0; |
| 180 | } | 177 | } |
| 181 | 178 | ||
| 182 | void tipc_node_remove_conn(u32 dnode, u32 port) | 179 | void tipc_node_remove_conn(struct net *net, u32 dnode, u32 port) |
| 183 | { | 180 | { |
| 184 | struct tipc_node *node; | 181 | struct tipc_node *node; |
| 185 | struct tipc_sock_conn *conn, *safe; | 182 | struct tipc_sock_conn *conn, *safe; |
| 186 | 183 | ||
| 187 | if (in_own_node(dnode)) | 184 | if (in_own_node(net, dnode)) |
| 188 | return; | 185 | return; |
| 189 | 186 | ||
| 190 | node = tipc_node_find(dnode); | 187 | node = tipc_node_find(net, dnode); |
| 191 | if (!node) | 188 | if (!node) |
| 192 | return; | 189 | return; |
| 193 | 190 | ||
| @@ -201,18 +198,20 @@ void tipc_node_remove_conn(u32 dnode, u32 port) | |||
| 201 | tipc_node_unlock(node); | 198 | tipc_node_unlock(node); |
| 202 | } | 199 | } |
| 203 | 200 | ||
| 204 | void tipc_node_abort_sock_conns(struct list_head *conns) | 201 | void tipc_node_abort_sock_conns(struct net *net, struct list_head *conns) |
| 205 | { | 202 | { |
| 203 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 206 | struct tipc_sock_conn *conn, *safe; | 204 | struct tipc_sock_conn *conn, *safe; |
| 207 | struct sk_buff *buf; | 205 | struct sk_buff *buf; |
| 208 | 206 | ||
| 209 | list_for_each_entry_safe(conn, safe, conns, list) { | 207 | list_for_each_entry_safe(conn, safe, conns, list) { |
| 210 | buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, | 208 | buf = tipc_msg_create(net, TIPC_CRITICAL_IMPORTANCE, |
| 211 | SHORT_H_SIZE, 0, tipc_own_addr, | 209 | TIPC_CONN_MSG, SHORT_H_SIZE, 0, |
| 212 | conn->peer_node, conn->port, | 210 | tn->own_addr, conn->peer_node, |
| 213 | conn->peer_port, TIPC_ERR_NO_NODE); | 211 | conn->port, conn->peer_port, |
| 212 | TIPC_ERR_NO_NODE); | ||
| 214 | if (likely(buf)) | 213 | if (likely(buf)) |
| 215 | tipc_sk_rcv(buf); | 214 | tipc_sk_rcv(net, buf); |
| 216 | list_del(&conn->list); | 215 | list_del(&conn->list); |
| 217 | kfree(conn); | 216 | kfree(conn); |
| 218 | } | 217 | } |
| @@ -231,8 +230,8 @@ void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
| 231 | n_ptr->action_flags |= TIPC_NOTIFY_LINK_UP; | 230 | n_ptr->action_flags |= TIPC_NOTIFY_LINK_UP; |
| 232 | n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id; | 231 | n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id; |
| 233 | 232 | ||
| 234 | pr_info("Established link <%s> on network plane %c\n", | 233 | pr_debug("Established link <%s> on network plane %c\n", |
| 235 | l_ptr->name, l_ptr->net_plane); | 234 | l_ptr->name, l_ptr->net_plane); |
| 236 | 235 | ||
| 237 | if (!active[0]) { | 236 | if (!active[0]) { |
| 238 | active[0] = active[1] = l_ptr; | 237 | active[0] = active[1] = l_ptr; |
| @@ -240,7 +239,7 @@ void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
| 240 | goto exit; | 239 | goto exit; |
| 241 | } | 240 | } |
| 242 | if (l_ptr->priority < active[0]->priority) { | 241 | if (l_ptr->priority < active[0]->priority) { |
| 243 | pr_info("New link <%s> becomes standby\n", l_ptr->name); | 242 | pr_debug("New link <%s> becomes standby\n", l_ptr->name); |
| 244 | goto exit; | 243 | goto exit; |
| 245 | } | 244 | } |
| 246 | tipc_link_dup_queue_xmit(active[0], l_ptr); | 245 | tipc_link_dup_queue_xmit(active[0], l_ptr); |
| @@ -248,9 +247,9 @@ void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
| 248 | active[0] = l_ptr; | 247 | active[0] = l_ptr; |
| 249 | goto exit; | 248 | goto exit; |
| 250 | } | 249 | } |
| 251 | pr_info("Old link <%s> becomes standby\n", active[0]->name); | 250 | pr_debug("Old link <%s> becomes standby\n", active[0]->name); |
| 252 | if (active[1] != active[0]) | 251 | if (active[1] != active[0]) |
| 253 | pr_info("Old link <%s> becomes standby\n", active[1]->name); | 252 | pr_debug("Old link <%s> becomes standby\n", active[1]->name); |
| 254 | active[0] = active[1] = l_ptr; | 253 | active[0] = active[1] = l_ptr; |
| 255 | exit: | 254 | exit: |
| 256 | /* Leave room for changeover header when returning 'mtu' to users: */ | 255 | /* Leave room for changeover header when returning 'mtu' to users: */ |
| @@ -290,6 +289,7 @@ static void node_select_active_links(struct tipc_node *n_ptr) | |||
| 290 | */ | 289 | */ |
| 291 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | 290 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
| 292 | { | 291 | { |
| 292 | struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id); | ||
| 293 | struct tipc_link **active; | 293 | struct tipc_link **active; |
| 294 | 294 | ||
| 295 | n_ptr->working_links--; | 295 | n_ptr->working_links--; |
| @@ -297,12 +297,12 @@ void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
| 297 | n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id; | 297 | n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id; |
| 298 | 298 | ||
| 299 | if (!tipc_link_is_active(l_ptr)) { | 299 | if (!tipc_link_is_active(l_ptr)) { |
| 300 | pr_info("Lost standby link <%s> on network plane %c\n", | 300 | pr_debug("Lost standby link <%s> on network plane %c\n", |
| 301 | l_ptr->name, l_ptr->net_plane); | 301 | l_ptr->name, l_ptr->net_plane); |
| 302 | return; | 302 | return; |
| 303 | } | 303 | } |
| 304 | pr_info("Lost link <%s> on network plane %c\n", | 304 | pr_debug("Lost link <%s> on network plane %c\n", |
| 305 | l_ptr->name, l_ptr->net_plane); | 305 | l_ptr->name, l_ptr->net_plane); |
| 306 | 306 | ||
| 307 | active = &n_ptr->active_links[0]; | 307 | active = &n_ptr->active_links[0]; |
| 308 | if (active[0] == l_ptr) | 308 | if (active[0] == l_ptr) |
| @@ -324,7 +324,7 @@ void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | |||
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | /* Loopback link went down? No fragmentation needed from now on. */ | 326 | /* Loopback link went down? No fragmentation needed from now on. */ |
| 327 | if (n_ptr->addr == tipc_own_addr) { | 327 | if (n_ptr->addr == tn->own_addr) { |
| 328 | n_ptr->act_mtus[0] = MAX_MSG_SIZE; | 328 | n_ptr->act_mtus[0] = MAX_MSG_SIZE; |
| 329 | n_ptr->act_mtus[1] = MAX_MSG_SIZE; | 329 | n_ptr->act_mtus[1] = MAX_MSG_SIZE; |
| 330 | } | 330 | } |
| @@ -342,24 +342,27 @@ int tipc_node_is_up(struct tipc_node *n_ptr) | |||
| 342 | 342 | ||
| 343 | void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | 343 | void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
| 344 | { | 344 | { |
| 345 | struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id); | ||
| 346 | |||
| 345 | n_ptr->links[l_ptr->bearer_id] = l_ptr; | 347 | n_ptr->links[l_ptr->bearer_id] = l_ptr; |
| 346 | spin_lock_bh(&node_list_lock); | 348 | spin_lock_bh(&tn->node_list_lock); |
| 347 | tipc_num_links++; | 349 | tn->num_links++; |
| 348 | spin_unlock_bh(&node_list_lock); | 350 | spin_unlock_bh(&tn->node_list_lock); |
| 349 | n_ptr->link_cnt++; | 351 | n_ptr->link_cnt++; |
| 350 | } | 352 | } |
| 351 | 353 | ||
| 352 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) | 354 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr) |
| 353 | { | 355 | { |
| 356 | struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id); | ||
| 354 | int i; | 357 | int i; |
| 355 | 358 | ||
| 356 | for (i = 0; i < MAX_BEARERS; i++) { | 359 | for (i = 0; i < MAX_BEARERS; i++) { |
| 357 | if (l_ptr != n_ptr->links[i]) | 360 | if (l_ptr != n_ptr->links[i]) |
| 358 | continue; | 361 | continue; |
| 359 | n_ptr->links[i] = NULL; | 362 | n_ptr->links[i] = NULL; |
| 360 | spin_lock_bh(&node_list_lock); | 363 | spin_lock_bh(&tn->node_list_lock); |
| 361 | tipc_num_links--; | 364 | tn->num_links--; |
| 362 | spin_unlock_bh(&node_list_lock); | 365 | spin_unlock_bh(&tn->node_list_lock); |
| 363 | n_ptr->link_cnt--; | 366 | n_ptr->link_cnt--; |
| 364 | } | 367 | } |
| 365 | } | 368 | } |
| @@ -368,8 +371,8 @@ static void node_established_contact(struct tipc_node *n_ptr) | |||
| 368 | { | 371 | { |
| 369 | n_ptr->action_flags |= TIPC_NOTIFY_NODE_UP; | 372 | n_ptr->action_flags |= TIPC_NOTIFY_NODE_UP; |
| 370 | n_ptr->bclink.oos_state = 0; | 373 | n_ptr->bclink.oos_state = 0; |
| 371 | n_ptr->bclink.acked = tipc_bclink_get_last_sent(); | 374 | n_ptr->bclink.acked = tipc_bclink_get_last_sent(n_ptr->net); |
| 372 | tipc_bclink_add_node(n_ptr->addr); | 375 | tipc_bclink_add_node(n_ptr->net, n_ptr->addr); |
| 373 | } | 376 | } |
| 374 | 377 | ||
| 375 | static void node_lost_contact(struct tipc_node *n_ptr) | 378 | static void node_lost_contact(struct tipc_node *n_ptr) |
| @@ -377,8 +380,8 @@ static void node_lost_contact(struct tipc_node *n_ptr) | |||
| 377 | char addr_string[16]; | 380 | char addr_string[16]; |
| 378 | u32 i; | 381 | u32 i; |
| 379 | 382 | ||
| 380 | pr_info("Lost contact with %s\n", | 383 | pr_debug("Lost contact with %s\n", |
| 381 | tipc_addr_string_fill(addr_string, n_ptr->addr)); | 384 | tipc_addr_string_fill(addr_string, n_ptr->addr)); |
| 382 | 385 | ||
| 383 | /* Flush broadcast link info associated with lost node */ | 386 | /* Flush broadcast link info associated with lost node */ |
| 384 | if (n_ptr->bclink.recv_permitted) { | 387 | if (n_ptr->bclink.recv_permitted) { |
| @@ -389,7 +392,7 @@ static void node_lost_contact(struct tipc_node *n_ptr) | |||
| 389 | n_ptr->bclink.reasm_buf = NULL; | 392 | n_ptr->bclink.reasm_buf = NULL; |
| 390 | } | 393 | } |
| 391 | 394 | ||
| 392 | tipc_bclink_remove_node(n_ptr->addr); | 395 | tipc_bclink_remove_node(n_ptr->net, n_ptr->addr); |
| 393 | tipc_bclink_acknowledge(n_ptr, INVALID_LINK_SEQ); | 396 | tipc_bclink_acknowledge(n_ptr, INVALID_LINK_SEQ); |
| 394 | 397 | ||
| 395 | n_ptr->bclink.recv_permitted = false; | 398 | n_ptr->bclink.recv_permitted = false; |
| @@ -414,8 +417,10 @@ static void node_lost_contact(struct tipc_node *n_ptr) | |||
| 414 | TIPC_NOTIFY_NODE_DOWN; | 417 | TIPC_NOTIFY_NODE_DOWN; |
| 415 | } | 418 | } |
| 416 | 419 | ||
| 417 | struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) | 420 | struct sk_buff *tipc_node_get_nodes(struct net *net, const void *req_tlv_area, |
| 421 | int req_tlv_space) | ||
| 418 | { | 422 | { |
| 423 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 419 | u32 domain; | 424 | u32 domain; |
| 420 | struct sk_buff *buf; | 425 | struct sk_buff *buf; |
| 421 | struct tipc_node *n_ptr; | 426 | struct tipc_node *n_ptr; |
| @@ -430,20 +435,20 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) | |||
| 430 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 435 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 431 | " (network address)"); | 436 | " (network address)"); |
| 432 | 437 | ||
| 433 | spin_lock_bh(&node_list_lock); | 438 | spin_lock_bh(&tn->node_list_lock); |
| 434 | if (!tipc_num_nodes) { | 439 | if (!tn->num_nodes) { |
| 435 | spin_unlock_bh(&node_list_lock); | 440 | spin_unlock_bh(&tn->node_list_lock); |
| 436 | return tipc_cfg_reply_none(); | 441 | return tipc_cfg_reply_none(); |
| 437 | } | 442 | } |
| 438 | 443 | ||
| 439 | /* For now, get space for all other nodes */ | 444 | /* For now, get space for all other nodes */ |
| 440 | payload_size = TLV_SPACE(sizeof(node_info)) * tipc_num_nodes; | 445 | payload_size = TLV_SPACE(sizeof(node_info)) * tn->num_nodes; |
| 441 | if (payload_size > 32768u) { | 446 | if (payload_size > 32768u) { |
| 442 | spin_unlock_bh(&node_list_lock); | 447 | spin_unlock_bh(&tn->node_list_lock); |
| 443 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 448 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 444 | " (too many nodes)"); | 449 | " (too many nodes)"); |
| 445 | } | 450 | } |
| 446 | spin_unlock_bh(&node_list_lock); | 451 | spin_unlock_bh(&tn->node_list_lock); |
| 447 | 452 | ||
| 448 | buf = tipc_cfg_reply_alloc(payload_size); | 453 | buf = tipc_cfg_reply_alloc(payload_size); |
| 449 | if (!buf) | 454 | if (!buf) |
| @@ -451,7 +456,7 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) | |||
| 451 | 456 | ||
| 452 | /* Add TLVs for all nodes in scope */ | 457 | /* Add TLVs for all nodes in scope */ |
| 453 | rcu_read_lock(); | 458 | rcu_read_lock(); |
| 454 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | 459 | list_for_each_entry_rcu(n_ptr, &tn->node_list, list) { |
| 455 | if (!tipc_in_scope(domain, n_ptr->addr)) | 460 | if (!tipc_in_scope(domain, n_ptr->addr)) |
| 456 | continue; | 461 | continue; |
| 457 | node_info.addr = htonl(n_ptr->addr); | 462 | node_info.addr = htonl(n_ptr->addr); |
| @@ -463,8 +468,10 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) | |||
| 463 | return buf; | 468 | return buf; |
| 464 | } | 469 | } |
| 465 | 470 | ||
| 466 | struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | 471 | struct sk_buff *tipc_node_get_links(struct net *net, const void *req_tlv_area, |
| 472 | int req_tlv_space) | ||
| 467 | { | 473 | { |
| 474 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 468 | u32 domain; | 475 | u32 domain; |
| 469 | struct sk_buff *buf; | 476 | struct sk_buff *buf; |
| 470 | struct tipc_node *n_ptr; | 477 | struct tipc_node *n_ptr; |
| @@ -479,32 +486,32 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | |||
| 479 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 486 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 480 | " (network address)"); | 487 | " (network address)"); |
| 481 | 488 | ||
| 482 | if (!tipc_own_addr) | 489 | if (!tn->own_addr) |
| 483 | return tipc_cfg_reply_none(); | 490 | return tipc_cfg_reply_none(); |
| 484 | 491 | ||
| 485 | spin_lock_bh(&node_list_lock); | 492 | spin_lock_bh(&tn->node_list_lock); |
| 486 | /* Get space for all unicast links + broadcast link */ | 493 | /* Get space for all unicast links + broadcast link */ |
| 487 | payload_size = TLV_SPACE((sizeof(link_info)) * (tipc_num_links + 1)); | 494 | payload_size = TLV_SPACE((sizeof(link_info)) * (tn->num_links + 1)); |
| 488 | if (payload_size > 32768u) { | 495 | if (payload_size > 32768u) { |
| 489 | spin_unlock_bh(&node_list_lock); | 496 | spin_unlock_bh(&tn->node_list_lock); |
| 490 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 497 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 491 | " (too many links)"); | 498 | " (too many links)"); |
| 492 | } | 499 | } |
| 493 | spin_unlock_bh(&node_list_lock); | 500 | spin_unlock_bh(&tn->node_list_lock); |
| 494 | 501 | ||
| 495 | buf = tipc_cfg_reply_alloc(payload_size); | 502 | buf = tipc_cfg_reply_alloc(payload_size); |
| 496 | if (!buf) | 503 | if (!buf) |
| 497 | return NULL; | 504 | return NULL; |
| 498 | 505 | ||
| 499 | /* Add TLV for broadcast link */ | 506 | /* Add TLV for broadcast link */ |
| 500 | link_info.dest = htonl(tipc_cluster_mask(tipc_own_addr)); | 507 | link_info.dest = htonl(tipc_cluster_mask(tn->own_addr)); |
| 501 | link_info.up = htonl(1); | 508 | link_info.up = htonl(1); |
| 502 | strlcpy(link_info.str, tipc_bclink_name, TIPC_MAX_LINK_NAME); | 509 | strlcpy(link_info.str, tipc_bclink_name, TIPC_MAX_LINK_NAME); |
| 503 | tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info)); | 510 | tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info)); |
| 504 | 511 | ||
| 505 | /* Add TLVs for any other links in scope */ | 512 | /* Add TLVs for any other links in scope */ |
| 506 | rcu_read_lock(); | 513 | rcu_read_lock(); |
| 507 | list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { | 514 | list_for_each_entry_rcu(n_ptr, &tn->node_list, list) { |
| 508 | u32 i; | 515 | u32 i; |
| 509 | 516 | ||
| 510 | if (!tipc_in_scope(domain, n_ptr->addr)) | 517 | if (!tipc_in_scope(domain, n_ptr->addr)) |
| @@ -534,10 +541,11 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | |||
| 534 | * | 541 | * |
| 535 | * Returns 0 on success | 542 | * Returns 0 on success |
| 536 | */ | 543 | */ |
| 537 | int tipc_node_get_linkname(u32 bearer_id, u32 addr, char *linkname, size_t len) | 544 | int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr, |
| 545 | char *linkname, size_t len) | ||
| 538 | { | 546 | { |
| 539 | struct tipc_link *link; | 547 | struct tipc_link *link; |
| 540 | struct tipc_node *node = tipc_node_find(addr); | 548 | struct tipc_node *node = tipc_node_find(net, addr); |
| 541 | 549 | ||
| 542 | if ((bearer_id >= MAX_BEARERS) || !node) | 550 | if ((bearer_id >= MAX_BEARERS) || !node) |
| 543 | return -EINVAL; | 551 | return -EINVAL; |
| @@ -554,6 +562,7 @@ int tipc_node_get_linkname(u32 bearer_id, u32 addr, char *linkname, size_t len) | |||
| 554 | 562 | ||
| 555 | void tipc_node_unlock(struct tipc_node *node) | 563 | void tipc_node_unlock(struct tipc_node *node) |
| 556 | { | 564 | { |
| 565 | struct net *net = node->net; | ||
| 557 | LIST_HEAD(nsub_list); | 566 | LIST_HEAD(nsub_list); |
| 558 | LIST_HEAD(conn_sks); | 567 | LIST_HEAD(conn_sks); |
| 559 | struct sk_buff_head waiting_sks; | 568 | struct sk_buff_head waiting_sks; |
| @@ -585,26 +594,26 @@ void tipc_node_unlock(struct tipc_node *node) | |||
| 585 | spin_unlock_bh(&node->lock); | 594 | spin_unlock_bh(&node->lock); |
| 586 | 595 | ||
| 587 | while (!skb_queue_empty(&waiting_sks)) | 596 | while (!skb_queue_empty(&waiting_sks)) |
| 588 | tipc_sk_rcv(__skb_dequeue(&waiting_sks)); | 597 | tipc_sk_rcv(net, __skb_dequeue(&waiting_sks)); |
| 589 | 598 | ||
| 590 | if (!list_empty(&conn_sks)) | 599 | if (!list_empty(&conn_sks)) |
| 591 | tipc_node_abort_sock_conns(&conn_sks); | 600 | tipc_node_abort_sock_conns(net, &conn_sks); |
| 592 | 601 | ||
| 593 | if (!list_empty(&nsub_list)) | 602 | if (!list_empty(&nsub_list)) |
| 594 | tipc_publ_notify(&nsub_list, addr); | 603 | tipc_publ_notify(net, &nsub_list, addr); |
| 595 | 604 | ||
| 596 | if (flags & TIPC_WAKEUP_BCAST_USERS) | 605 | if (flags & TIPC_WAKEUP_BCAST_USERS) |
| 597 | tipc_bclink_wakeup_users(); | 606 | tipc_bclink_wakeup_users(net); |
| 598 | 607 | ||
| 599 | if (flags & TIPC_NOTIFY_NODE_UP) | 608 | if (flags & TIPC_NOTIFY_NODE_UP) |
| 600 | tipc_named_node_up(addr); | 609 | tipc_named_node_up(net, addr); |
| 601 | 610 | ||
| 602 | if (flags & TIPC_NOTIFY_LINK_UP) | 611 | if (flags & TIPC_NOTIFY_LINK_UP) |
| 603 | tipc_nametbl_publish(TIPC_LINK_STATE, addr, addr, | 612 | tipc_nametbl_publish(net, TIPC_LINK_STATE, addr, addr, |
| 604 | TIPC_NODE_SCOPE, link_id, addr); | 613 | TIPC_NODE_SCOPE, link_id, addr); |
| 605 | 614 | ||
| 606 | if (flags & TIPC_NOTIFY_LINK_DOWN) | 615 | if (flags & TIPC_NOTIFY_LINK_DOWN) |
| 607 | tipc_nametbl_withdraw(TIPC_LINK_STATE, addr, | 616 | tipc_nametbl_withdraw(net, TIPC_LINK_STATE, addr, |
| 608 | link_id, addr); | 617 | link_id, addr); |
| 609 | } | 618 | } |
| 610 | 619 | ||
| @@ -645,6 +654,8 @@ msg_full: | |||
| 645 | int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb) | 654 | int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb) |
| 646 | { | 655 | { |
| 647 | int err; | 656 | int err; |
| 657 | struct net *net = sock_net(skb->sk); | ||
| 658 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 648 | int done = cb->args[0]; | 659 | int done = cb->args[0]; |
| 649 | int last_addr = cb->args[1]; | 660 | int last_addr = cb->args[1]; |
| 650 | struct tipc_node *node; | 661 | struct tipc_node *node; |
| @@ -659,7 +670,7 @@ int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 659 | 670 | ||
| 660 | rcu_read_lock(); | 671 | rcu_read_lock(); |
| 661 | 672 | ||
| 662 | if (last_addr && !tipc_node_find(last_addr)) { | 673 | if (last_addr && !tipc_node_find(net, last_addr)) { |
| 663 | rcu_read_unlock(); | 674 | rcu_read_unlock(); |
| 664 | /* We never set seq or call nl_dump_check_consistent() this | 675 | /* We never set seq or call nl_dump_check_consistent() this |
| 665 | * means that setting prev_seq here will cause the consistence | 676 | * means that setting prev_seq here will cause the consistence |
| @@ -671,7 +682,7 @@ int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 671 | return -EPIPE; | 682 | return -EPIPE; |
| 672 | } | 683 | } |
| 673 | 684 | ||
| 674 | list_for_each_entry_rcu(node, &tipc_node_list, list) { | 685 | list_for_each_entry_rcu(node, &tn->node_list, list) { |
| 675 | if (last_addr) { | 686 | if (last_addr) { |
| 676 | if (node->addr == last_addr) | 687 | if (node->addr == last_addr) |
| 677 | last_addr = 0; | 688 | last_addr = 0; |
diff --git a/net/tipc/node.h b/net/tipc/node.h index cbe0e950f1cc..43ef88ef3035 100644 --- a/net/tipc/node.h +++ b/net/tipc/node.h | |||
| @@ -42,10 +42,10 @@ | |||
| 42 | #include "bearer.h" | 42 | #include "bearer.h" |
| 43 | #include "msg.h" | 43 | #include "msg.h" |
| 44 | 44 | ||
| 45 | /* | 45 | /* Out-of-range value for node signature */ |
| 46 | * Out-of-range value for node signature | 46 | #define INVALID_NODE_SIG 0x10000 |
| 47 | */ | 47 | |
| 48 | #define INVALID_NODE_SIG 0x10000 | 48 | #define NODE_HTABLE_SIZE 512 |
| 49 | 49 | ||
| 50 | /* Flags used to take different actions according to flag type | 50 | /* Flags used to take different actions according to flag type |
| 51 | * TIPC_WAIT_PEER_LINKS_DOWN: wait to see that peer's links are down | 51 | * TIPC_WAIT_PEER_LINKS_DOWN: wait to see that peer's links are down |
| @@ -90,6 +90,7 @@ struct tipc_node_bclink { | |||
| 90 | * struct tipc_node - TIPC node structure | 90 | * struct tipc_node - TIPC node structure |
| 91 | * @addr: network address of node | 91 | * @addr: network address of node |
| 92 | * @lock: spinlock governing access to structure | 92 | * @lock: spinlock governing access to structure |
| 93 | * @net: the applicable net namespace | ||
| 93 | * @hash: links to adjacent nodes in unsorted hash chain | 94 | * @hash: links to adjacent nodes in unsorted hash chain |
| 94 | * @active_links: pointers to active links to node | 95 | * @active_links: pointers to active links to node |
| 95 | * @links: pointers to all links to node | 96 | * @links: pointers to all links to node |
| @@ -106,6 +107,7 @@ struct tipc_node_bclink { | |||
| 106 | struct tipc_node { | 107 | struct tipc_node { |
| 107 | u32 addr; | 108 | u32 addr; |
| 108 | spinlock_t lock; | 109 | spinlock_t lock; |
| 110 | struct net *net; | ||
| 109 | struct hlist_node hash; | 111 | struct hlist_node hash; |
| 110 | struct tipc_link *active_links[2]; | 112 | struct tipc_link *active_links[2]; |
| 111 | u32 act_mtus[2]; | 113 | u32 act_mtus[2]; |
| @@ -123,23 +125,24 @@ struct tipc_node { | |||
| 123 | struct rcu_head rcu; | 125 | struct rcu_head rcu; |
| 124 | }; | 126 | }; |
| 125 | 127 | ||
| 126 | extern struct list_head tipc_node_list; | 128 | struct tipc_node *tipc_node_find(struct net *net, u32 addr); |
| 127 | 129 | struct tipc_node *tipc_node_create(struct net *net, u32 addr); | |
| 128 | struct tipc_node *tipc_node_find(u32 addr); | 130 | void tipc_node_stop(struct net *net); |
| 129 | struct tipc_node *tipc_node_create(u32 addr); | ||
| 130 | void tipc_node_stop(void); | ||
| 131 | void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); | 131 | void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); |
| 132 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); | 132 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr); |
| 133 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr); | 133 | void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr); |
| 134 | void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr); | 134 | void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr); |
| 135 | int tipc_node_active_links(struct tipc_node *n_ptr); | 135 | int tipc_node_active_links(struct tipc_node *n_ptr); |
| 136 | int tipc_node_is_up(struct tipc_node *n_ptr); | 136 | int tipc_node_is_up(struct tipc_node *n_ptr); |
| 137 | struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space); | 137 | struct sk_buff *tipc_node_get_links(struct net *net, const void *req_tlv_area, |
| 138 | struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space); | 138 | int req_tlv_space); |
| 139 | int tipc_node_get_linkname(u32 bearer_id, u32 node, char *linkname, size_t len); | 139 | struct sk_buff *tipc_node_get_nodes(struct net *net, const void *req_tlv_area, |
| 140 | int req_tlv_space); | ||
| 141 | int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 node, | ||
| 142 | char *linkname, size_t len); | ||
| 140 | void tipc_node_unlock(struct tipc_node *node); | 143 | void tipc_node_unlock(struct tipc_node *node); |
| 141 | int tipc_node_add_conn(u32 dnode, u32 port, u32 peer_port); | 144 | int tipc_node_add_conn(struct net *net, u32 dnode, u32 port, u32 peer_port); |
| 142 | void tipc_node_remove_conn(u32 dnode, u32 port); | 145 | void tipc_node_remove_conn(struct net *net, u32 dnode, u32 port); |
| 143 | 146 | ||
| 144 | int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb); | 147 | int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb); |
| 145 | 148 | ||
| @@ -154,12 +157,12 @@ static inline bool tipc_node_blocked(struct tipc_node *node) | |||
| 154 | TIPC_NOTIFY_NODE_DOWN | TIPC_WAIT_OWN_LINKS_DOWN)); | 157 | TIPC_NOTIFY_NODE_DOWN | TIPC_WAIT_OWN_LINKS_DOWN)); |
| 155 | } | 158 | } |
| 156 | 159 | ||
| 157 | static inline uint tipc_node_get_mtu(u32 addr, u32 selector) | 160 | static inline uint tipc_node_get_mtu(struct net *net, u32 addr, u32 selector) |
| 158 | { | 161 | { |
| 159 | struct tipc_node *node; | 162 | struct tipc_node *node; |
| 160 | u32 mtu; | 163 | u32 mtu; |
| 161 | 164 | ||
| 162 | node = tipc_node_find(addr); | 165 | node = tipc_node_find(net, addr); |
| 163 | 166 | ||
| 164 | if (likely(node)) | 167 | if (likely(node)) |
| 165 | mtu = node->act_mtus[selector & 1]; | 168 | mtu = node->act_mtus[selector & 1]; |
diff --git a/net/tipc/server.c b/net/tipc/server.c index a538a02f869b..eadd4ed45905 100644 --- a/net/tipc/server.c +++ b/net/tipc/server.c | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | 35 | ||
| 36 | #include "server.h" | 36 | #include "server.h" |
| 37 | #include "core.h" | 37 | #include "core.h" |
| 38 | #include "socket.h" | ||
| 38 | #include <net/sock.h> | 39 | #include <net/sock.h> |
| 39 | 40 | ||
| 40 | /* Number of messages to send before rescheduling */ | 41 | /* Number of messages to send before rescheduling */ |
| @@ -255,7 +256,8 @@ static int tipc_receive_from_sock(struct tipc_conn *con) | |||
| 255 | goto out_close; | 256 | goto out_close; |
| 256 | } | 257 | } |
| 257 | 258 | ||
| 258 | s->tipc_conn_recvmsg(con->conid, &addr, con->usr_data, buf, ret); | 259 | s->tipc_conn_recvmsg(sock_net(con->sock->sk), con->conid, &addr, |
| 260 | con->usr_data, buf, ret); | ||
| 259 | 261 | ||
| 260 | kmem_cache_free(s->rcvbuf_cache, buf); | 262 | kmem_cache_free(s->rcvbuf_cache, buf); |
| 261 | 263 | ||
| @@ -307,7 +309,7 @@ static struct socket *tipc_create_listen_sock(struct tipc_conn *con) | |||
| 307 | struct socket *sock = NULL; | 309 | struct socket *sock = NULL; |
| 308 | int ret; | 310 | int ret; |
| 309 | 311 | ||
| 310 | ret = tipc_sock_create_local(s->type, &sock); | 312 | ret = tipc_sock_create_local(s->net, s->type, &sock); |
| 311 | if (ret < 0) | 313 | if (ret < 0) |
| 312 | return NULL; | 314 | return NULL; |
| 313 | ret = kernel_setsockopt(sock, SOL_TIPC, TIPC_IMPORTANCE, | 315 | ret = kernel_setsockopt(sock, SOL_TIPC, TIPC_IMPORTANCE, |
diff --git a/net/tipc/server.h b/net/tipc/server.h index be817b0b547e..9015faedb1b0 100644 --- a/net/tipc/server.h +++ b/net/tipc/server.h | |||
| @@ -36,7 +36,9 @@ | |||
| 36 | #ifndef _TIPC_SERVER_H | 36 | #ifndef _TIPC_SERVER_H |
| 37 | #define _TIPC_SERVER_H | 37 | #define _TIPC_SERVER_H |
| 38 | 38 | ||
| 39 | #include "core.h" | 39 | #include <linux/idr.h> |
| 40 | #include <linux/tipc.h> | ||
| 41 | #include <net/net_namespace.h> | ||
| 40 | 42 | ||
| 41 | #define TIPC_SERVER_NAME_LEN 32 | 43 | #define TIPC_SERVER_NAME_LEN 32 |
| 42 | 44 | ||
| @@ -45,6 +47,7 @@ | |||
| 45 | * @conn_idr: identifier set of connection | 47 | * @conn_idr: identifier set of connection |
| 46 | * @idr_lock: protect the connection identifier set | 48 | * @idr_lock: protect the connection identifier set |
| 47 | * @idr_in_use: amount of allocated identifier entry | 49 | * @idr_in_use: amount of allocated identifier entry |
| 50 | * @net: network namspace instance | ||
| 48 | * @rcvbuf_cache: memory cache of server receive buffer | 51 | * @rcvbuf_cache: memory cache of server receive buffer |
| 49 | * @rcv_wq: receive workqueue | 52 | * @rcv_wq: receive workqueue |
| 50 | * @send_wq: send workqueue | 53 | * @send_wq: send workqueue |
| @@ -61,16 +64,18 @@ struct tipc_server { | |||
| 61 | struct idr conn_idr; | 64 | struct idr conn_idr; |
| 62 | spinlock_t idr_lock; | 65 | spinlock_t idr_lock; |
| 63 | int idr_in_use; | 66 | int idr_in_use; |
| 67 | struct net *net; | ||
| 64 | struct kmem_cache *rcvbuf_cache; | 68 | struct kmem_cache *rcvbuf_cache; |
| 65 | struct workqueue_struct *rcv_wq; | 69 | struct workqueue_struct *rcv_wq; |
| 66 | struct workqueue_struct *send_wq; | 70 | struct workqueue_struct *send_wq; |
| 67 | int max_rcvbuf_size; | 71 | int max_rcvbuf_size; |
| 68 | void *(*tipc_conn_new) (int conid); | 72 | void *(*tipc_conn_new)(int conid); |
| 69 | void (*tipc_conn_shutdown) (int conid, void *usr_data); | 73 | void (*tipc_conn_shutdown)(int conid, void *usr_data); |
| 70 | void (*tipc_conn_recvmsg) (int conid, struct sockaddr_tipc *addr, | 74 | void (*tipc_conn_recvmsg)(struct net *net, int conid, |
| 71 | void *usr_data, void *buf, size_t len); | 75 | struct sockaddr_tipc *addr, void *usr_data, |
| 76 | void *buf, size_t len); | ||
| 72 | struct sockaddr_tipc *saddr; | 77 | struct sockaddr_tipc *saddr; |
| 73 | const char name[TIPC_SERVER_NAME_LEN]; | 78 | char name[TIPC_SERVER_NAME_LEN]; |
| 74 | int imp; | 79 | int imp; |
| 75 | int type; | 80 | int type; |
| 76 | }; | 81 | }; |
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 4731cad99d1c..679a22082fcb 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
| @@ -34,22 +34,25 @@ | |||
| 34 | * POSSIBILITY OF SUCH DAMAGE. | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #include <linux/rhashtable.h> | ||
| 38 | #include <linux/jhash.h> | ||
| 37 | #include "core.h" | 39 | #include "core.h" |
| 38 | #include "name_table.h" | 40 | #include "name_table.h" |
| 39 | #include "node.h" | 41 | #include "node.h" |
| 40 | #include "link.h" | 42 | #include "link.h" |
| 41 | #include <linux/export.h> | ||
| 42 | #include "config.h" | 43 | #include "config.h" |
| 43 | #include "socket.h" | 44 | #include "socket.h" |
| 44 | 45 | ||
| 45 | #define SS_LISTENING -1 /* socket is listening */ | 46 | #define SS_LISTENING -1 /* socket is listening */ |
| 46 | #define SS_READY -2 /* socket is connectionless */ | 47 | #define SS_READY -2 /* socket is connectionless */ |
| 47 | 48 | ||
| 48 | #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ | 49 | #define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ |
| 49 | #define CONN_PROBING_INTERVAL 3600000 /* [ms] => 1 h */ | 50 | #define CONN_PROBING_INTERVAL msecs_to_jiffies(3600000) /* [ms] => 1 h */ |
| 50 | #define TIPC_FWD_MSG 1 | 51 | #define TIPC_FWD_MSG 1 |
| 51 | #define TIPC_CONN_OK 0 | 52 | #define TIPC_CONN_OK 0 |
| 52 | #define TIPC_CONN_PROBING 1 | 53 | #define TIPC_CONN_PROBING 1 |
| 54 | #define TIPC_MAX_PORT 0xffffffff | ||
| 55 | #define TIPC_MIN_PORT 1 | ||
| 53 | 56 | ||
| 54 | /** | 57 | /** |
| 55 | * struct tipc_sock - TIPC socket structure | 58 | * struct tipc_sock - TIPC socket structure |
| @@ -59,14 +62,13 @@ | |||
| 59 | * @conn_instance: TIPC instance used when connection was established | 62 | * @conn_instance: TIPC instance used when connection was established |
| 60 | * @published: non-zero if port has one or more associated names | 63 | * @published: non-zero if port has one or more associated names |
| 61 | * @max_pkt: maximum packet size "hint" used when building messages sent by port | 64 | * @max_pkt: maximum packet size "hint" used when building messages sent by port |
| 62 | * @ref: unique reference to port in TIPC object registry | 65 | * @portid: unique port identity in TIPC socket hash table |
| 63 | * @phdr: preformatted message header used when sending messages | 66 | * @phdr: preformatted message header used when sending messages |
| 64 | * @port_list: adjacent ports in TIPC's global list of ports | 67 | * @port_list: adjacent ports in TIPC's global list of ports |
| 65 | * @publications: list of publications for port | 68 | * @publications: list of publications for port |
| 66 | * @pub_count: total # of publications port has made during its lifetime | 69 | * @pub_count: total # of publications port has made during its lifetime |
| 67 | * @probing_state: | 70 | * @probing_state: |
| 68 | * @probing_interval: | 71 | * @probing_intv: |
| 69 | * @timer: | ||
| 70 | * @port: port - interacts with 'sk' and with the rest of the TIPC stack | 72 | * @port: port - interacts with 'sk' and with the rest of the TIPC stack |
| 71 | * @peer_name: the peer of the connection, if any | 73 | * @peer_name: the peer of the connection, if any |
| 72 | * @conn_timeout: the time we can wait for an unresponded setup request | 74 | * @conn_timeout: the time we can wait for an unresponded setup request |
| @@ -74,6 +76,8 @@ | |||
| 74 | * @link_cong: non-zero if owner must sleep because of link congestion | 76 | * @link_cong: non-zero if owner must sleep because of link congestion |
| 75 | * @sent_unacked: # messages sent by socket, and not yet acked by peer | 77 | * @sent_unacked: # messages sent by socket, and not yet acked by peer |
| 76 | * @rcv_unacked: # messages read by user, but not yet acked back to peer | 78 | * @rcv_unacked: # messages read by user, but not yet acked back to peer |
| 79 | * @node: hash table node | ||
| 80 | * @rcu: rcu struct for tipc_sock | ||
| 77 | */ | 81 | */ |
| 78 | struct tipc_sock { | 82 | struct tipc_sock { |
| 79 | struct sock sk; | 83 | struct sock sk; |
| @@ -82,19 +86,20 @@ struct tipc_sock { | |||
| 82 | u32 conn_instance; | 86 | u32 conn_instance; |
| 83 | int published; | 87 | int published; |
| 84 | u32 max_pkt; | 88 | u32 max_pkt; |
| 85 | u32 ref; | 89 | u32 portid; |
| 86 | struct tipc_msg phdr; | 90 | struct tipc_msg phdr; |
| 87 | struct list_head sock_list; | 91 | struct list_head sock_list; |
| 88 | struct list_head publications; | 92 | struct list_head publications; |
| 89 | u32 pub_count; | 93 | u32 pub_count; |
| 90 | u32 probing_state; | 94 | u32 probing_state; |
| 91 | u32 probing_interval; | 95 | unsigned long probing_intv; |
| 92 | struct timer_list timer; | ||
| 93 | uint conn_timeout; | 96 | uint conn_timeout; |
| 94 | atomic_t dupl_rcvcnt; | 97 | atomic_t dupl_rcvcnt; |
| 95 | bool link_cong; | 98 | bool link_cong; |
| 96 | uint sent_unacked; | 99 | uint sent_unacked; |
| 97 | uint rcv_unacked; | 100 | uint rcv_unacked; |
| 101 | struct rhash_head node; | ||
| 102 | struct rcu_head rcu; | ||
| 98 | }; | 103 | }; |
| 99 | 104 | ||
| 100 | static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb); | 105 | static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb); |
| @@ -103,16 +108,14 @@ static void tipc_write_space(struct sock *sk); | |||
| 103 | static int tipc_release(struct socket *sock); | 108 | static int tipc_release(struct socket *sock); |
| 104 | static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags); | 109 | static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags); |
| 105 | static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p); | 110 | static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p); |
| 106 | static void tipc_sk_timeout(unsigned long ref); | 111 | static void tipc_sk_timeout(unsigned long data); |
| 107 | static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, | 112 | static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, |
| 108 | struct tipc_name_seq const *seq); | 113 | struct tipc_name_seq const *seq); |
| 109 | static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, | 114 | static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, |
| 110 | struct tipc_name_seq const *seq); | 115 | struct tipc_name_seq const *seq); |
| 111 | static u32 tipc_sk_ref_acquire(struct tipc_sock *tsk); | 116 | static struct tipc_sock *tipc_sk_lookup(struct net *net, u32 portid); |
| 112 | static void tipc_sk_ref_discard(u32 ref); | 117 | static int tipc_sk_insert(struct tipc_sock *tsk); |
| 113 | static struct tipc_sock *tipc_sk_get(u32 ref); | 118 | static void tipc_sk_remove(struct tipc_sock *tsk); |
| 114 | static struct tipc_sock *tipc_sk_get_next(u32 *ref); | ||
| 115 | static void tipc_sk_put(struct tipc_sock *tsk); | ||
| 116 | 119 | ||
| 117 | static const struct proto_ops packet_ops; | 120 | static const struct proto_ops packet_ops; |
| 118 | static const struct proto_ops stream_ops; | 121 | static const struct proto_ops stream_ops; |
| @@ -246,10 +249,11 @@ static void tsk_rej_rx_queue(struct sock *sk) | |||
| 246 | { | 249 | { |
| 247 | struct sk_buff *skb; | 250 | struct sk_buff *skb; |
| 248 | u32 dnode; | 251 | u32 dnode; |
| 252 | struct net *net = sock_net(sk); | ||
| 249 | 253 | ||
| 250 | while ((skb = __skb_dequeue(&sk->sk_receive_queue))) { | 254 | while ((skb = __skb_dequeue(&sk->sk_receive_queue))) { |
| 251 | if (tipc_msg_reverse(skb, &dnode, TIPC_ERR_NO_PORT)) | 255 | if (tipc_msg_reverse(net, skb, &dnode, TIPC_ERR_NO_PORT)) |
| 252 | tipc_link_xmit_skb(skb, dnode, 0); | 256 | tipc_link_xmit_skb(net, skb, dnode, 0); |
| 253 | } | 257 | } |
| 254 | } | 258 | } |
| 255 | 259 | ||
| @@ -260,6 +264,7 @@ static void tsk_rej_rx_queue(struct sock *sk) | |||
| 260 | */ | 264 | */ |
| 261 | static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) | 265 | static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) |
| 262 | { | 266 | { |
| 267 | struct tipc_net *tn = net_generic(sock_net(&tsk->sk), tipc_net_id); | ||
| 263 | u32 peer_port = tsk_peer_port(tsk); | 268 | u32 peer_port = tsk_peer_port(tsk); |
| 264 | u32 orig_node; | 269 | u32 orig_node; |
| 265 | u32 peer_node; | 270 | u32 peer_node; |
| @@ -276,10 +281,10 @@ static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) | |||
| 276 | if (likely(orig_node == peer_node)) | 281 | if (likely(orig_node == peer_node)) |
| 277 | return true; | 282 | return true; |
| 278 | 283 | ||
| 279 | if (!orig_node && (peer_node == tipc_own_addr)) | 284 | if (!orig_node && (peer_node == tn->own_addr)) |
| 280 | return true; | 285 | return true; |
| 281 | 286 | ||
| 282 | if (!peer_node && (orig_node == tipc_own_addr)) | 287 | if (!peer_node && (orig_node == tn->own_addr)) |
| 283 | return true; | 288 | return true; |
| 284 | 289 | ||
| 285 | return false; | 290 | return false; |
| @@ -305,7 +310,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock, | |||
| 305 | struct sock *sk; | 310 | struct sock *sk; |
| 306 | struct tipc_sock *tsk; | 311 | struct tipc_sock *tsk; |
| 307 | struct tipc_msg *msg; | 312 | struct tipc_msg *msg; |
| 308 | u32 ref; | ||
| 309 | 313 | ||
| 310 | /* Validate arguments */ | 314 | /* Validate arguments */ |
| 311 | if (unlikely(protocol != 0)) | 315 | if (unlikely(protocol != 0)) |
| @@ -339,24 +343,22 @@ static int tipc_sk_create(struct net *net, struct socket *sock, | |||
| 339 | return -ENOMEM; | 343 | return -ENOMEM; |
| 340 | 344 | ||
| 341 | tsk = tipc_sk(sk); | 345 | tsk = tipc_sk(sk); |
| 342 | ref = tipc_sk_ref_acquire(tsk); | ||
| 343 | if (!ref) { | ||
| 344 | pr_warn("Socket create failed; reference table exhausted\n"); | ||
| 345 | return -ENOMEM; | ||
| 346 | } | ||
| 347 | tsk->max_pkt = MAX_PKT_DEFAULT; | 346 | tsk->max_pkt = MAX_PKT_DEFAULT; |
| 348 | tsk->ref = ref; | ||
| 349 | INIT_LIST_HEAD(&tsk->publications); | 347 | INIT_LIST_HEAD(&tsk->publications); |
| 350 | msg = &tsk->phdr; | 348 | msg = &tsk->phdr; |
| 351 | tipc_msg_init(msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG, | 349 | tipc_msg_init(net, msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG, |
| 352 | NAMED_H_SIZE, 0); | 350 | NAMED_H_SIZE, 0); |
| 353 | msg_set_origport(msg, ref); | ||
| 354 | 351 | ||
| 355 | /* Finish initializing socket data structures */ | 352 | /* Finish initializing socket data structures */ |
| 356 | sock->ops = ops; | 353 | sock->ops = ops; |
| 357 | sock->state = state; | 354 | sock->state = state; |
| 358 | sock_init_data(sock, sk); | 355 | sock_init_data(sock, sk); |
| 359 | k_init_timer(&tsk->timer, (Handler)tipc_sk_timeout, ref); | 356 | if (tipc_sk_insert(tsk)) { |
| 357 | pr_warn("Socket create failed; port numbrer exhausted\n"); | ||
| 358 | return -EINVAL; | ||
| 359 | } | ||
| 360 | msg_set_origport(msg, tsk->portid); | ||
| 361 | setup_timer(&sk->sk_timer, tipc_sk_timeout, (unsigned long)tsk); | ||
| 360 | sk->sk_backlog_rcv = tipc_backlog_rcv; | 362 | sk->sk_backlog_rcv = tipc_backlog_rcv; |
| 361 | sk->sk_rcvbuf = sysctl_tipc_rmem[1]; | 363 | sk->sk_rcvbuf = sysctl_tipc_rmem[1]; |
| 362 | sk->sk_data_ready = tipc_data_ready; | 364 | sk->sk_data_ready = tipc_data_ready; |
| @@ -384,7 +386,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock, | |||
| 384 | * | 386 | * |
| 385 | * Returns 0 on success, errno otherwise | 387 | * Returns 0 on success, errno otherwise |
| 386 | */ | 388 | */ |
| 387 | int tipc_sock_create_local(int type, struct socket **res) | 389 | int tipc_sock_create_local(struct net *net, int type, struct socket **res) |
| 388 | { | 390 | { |
| 389 | int rc; | 391 | int rc; |
| 390 | 392 | ||
| @@ -393,7 +395,7 @@ int tipc_sock_create_local(int type, struct socket **res) | |||
| 393 | pr_err("Failed to create kernel socket\n"); | 395 | pr_err("Failed to create kernel socket\n"); |
| 394 | return rc; | 396 | return rc; |
| 395 | } | 397 | } |
| 396 | tipc_sk_create(&init_net, *res, 0, 1); | 398 | tipc_sk_create(net, *res, 0, 1); |
| 397 | 399 | ||
| 398 | return 0; | 400 | return 0; |
| 399 | } | 401 | } |
| @@ -442,6 +444,13 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock, | |||
| 442 | return ret; | 444 | return ret; |
| 443 | } | 445 | } |
| 444 | 446 | ||
| 447 | static void tipc_sk_callback(struct rcu_head *head) | ||
| 448 | { | ||
| 449 | struct tipc_sock *tsk = container_of(head, struct tipc_sock, rcu); | ||
| 450 | |||
| 451 | sock_put(&tsk->sk); | ||
| 452 | } | ||
| 453 | |||
| 445 | /** | 454 | /** |
| 446 | * tipc_release - destroy a TIPC socket | 455 | * tipc_release - destroy a TIPC socket |
| 447 | * @sock: socket to destroy | 456 | * @sock: socket to destroy |
| @@ -461,9 +470,11 @@ int tipc_sock_accept_local(struct socket *sock, struct socket **newsock, | |||
| 461 | static int tipc_release(struct socket *sock) | 470 | static int tipc_release(struct socket *sock) |
| 462 | { | 471 | { |
| 463 | struct sock *sk = sock->sk; | 472 | struct sock *sk = sock->sk; |
| 473 | struct net *net; | ||
| 474 | struct tipc_net *tn; | ||
| 464 | struct tipc_sock *tsk; | 475 | struct tipc_sock *tsk; |
| 465 | struct sk_buff *skb; | 476 | struct sk_buff *skb; |
| 466 | u32 dnode; | 477 | u32 dnode, probing_state; |
| 467 | 478 | ||
| 468 | /* | 479 | /* |
| 469 | * Exit if socket isn't fully initialized (occurs when a failed accept() | 480 | * Exit if socket isn't fully initialized (occurs when a failed accept() |
| @@ -472,6 +483,9 @@ static int tipc_release(struct socket *sock) | |||
| 472 | if (sk == NULL) | 483 | if (sk == NULL) |
| 473 | return 0; | 484 | return 0; |
| 474 | 485 | ||
| 486 | net = sock_net(sk); | ||
| 487 | tn = net_generic(net, tipc_net_id); | ||
| 488 | |||
| 475 | tsk = tipc_sk(sk); | 489 | tsk = tipc_sk(sk); |
| 476 | lock_sock(sk); | 490 | lock_sock(sk); |
| 477 | 491 | ||
| @@ -491,26 +505,29 @@ static int tipc_release(struct socket *sock) | |||
| 491 | (sock->state == SS_CONNECTED)) { | 505 | (sock->state == SS_CONNECTED)) { |
| 492 | sock->state = SS_DISCONNECTING; | 506 | sock->state = SS_DISCONNECTING; |
| 493 | tsk->connected = 0; | 507 | tsk->connected = 0; |
| 494 | tipc_node_remove_conn(dnode, tsk->ref); | 508 | tipc_node_remove_conn(net, dnode, tsk->portid); |
| 495 | } | 509 | } |
| 496 | if (tipc_msg_reverse(skb, &dnode, TIPC_ERR_NO_PORT)) | 510 | if (tipc_msg_reverse(net, skb, &dnode, |
| 497 | tipc_link_xmit_skb(skb, dnode, 0); | 511 | TIPC_ERR_NO_PORT)) |
| 512 | tipc_link_xmit_skb(net, skb, dnode, 0); | ||
| 498 | } | 513 | } |
| 499 | } | 514 | } |
| 500 | 515 | ||
| 501 | tipc_sk_withdraw(tsk, 0, NULL); | 516 | tipc_sk_withdraw(tsk, 0, NULL); |
| 502 | tipc_sk_ref_discard(tsk->ref); | 517 | probing_state = tsk->probing_state; |
| 503 | k_cancel_timer(&tsk->timer); | 518 | if (del_timer_sync(&sk->sk_timer) && |
| 519 | probing_state != TIPC_CONN_PROBING) | ||
| 520 | sock_put(sk); | ||
| 521 | tipc_sk_remove(tsk); | ||
| 504 | if (tsk->connected) { | 522 | if (tsk->connected) { |
| 505 | skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, | 523 | skb = tipc_msg_create(net, TIPC_CRITICAL_IMPORTANCE, |
| 506 | SHORT_H_SIZE, 0, dnode, tipc_own_addr, | 524 | TIPC_CONN_MSG, SHORT_H_SIZE, 0, dnode, |
| 507 | tsk_peer_port(tsk), | 525 | tn->own_addr, tsk_peer_port(tsk), |
| 508 | tsk->ref, TIPC_ERR_NO_PORT); | 526 | tsk->portid, TIPC_ERR_NO_PORT); |
| 509 | if (skb) | 527 | if (skb) |
| 510 | tipc_link_xmit_skb(skb, dnode, tsk->ref); | 528 | tipc_link_xmit_skb(net, skb, dnode, tsk->portid); |
| 511 | tipc_node_remove_conn(dnode, tsk->ref); | 529 | tipc_node_remove_conn(net, dnode, tsk->portid); |
| 512 | } | 530 | } |
| 513 | k_term_timer(&tsk->timer); | ||
| 514 | 531 | ||
| 515 | /* Discard any remaining (connection-based) messages in receive queue */ | 532 | /* Discard any remaining (connection-based) messages in receive queue */ |
| 516 | __skb_queue_purge(&sk->sk_receive_queue); | 533 | __skb_queue_purge(&sk->sk_receive_queue); |
| @@ -518,7 +535,8 @@ static int tipc_release(struct socket *sock) | |||
| 518 | /* Reject any messages that accumulated in backlog queue */ | 535 | /* Reject any messages that accumulated in backlog queue */ |
| 519 | sock->state = SS_DISCONNECTING; | 536 | sock->state = SS_DISCONNECTING; |
| 520 | release_sock(sk); | 537 | release_sock(sk); |
| 521 | sock_put(sk); | 538 | |
| 539 | call_rcu(&tsk->rcu, tipc_sk_callback); | ||
| 522 | sock->sk = NULL; | 540 | sock->sk = NULL; |
| 523 | 541 | ||
| 524 | return 0; | 542 | return 0; |
| @@ -602,6 +620,7 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, | |||
| 602 | { | 620 | { |
| 603 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; | 621 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; |
| 604 | struct tipc_sock *tsk = tipc_sk(sock->sk); | 622 | struct tipc_sock *tsk = tipc_sk(sock->sk); |
| 623 | struct tipc_net *tn = net_generic(sock_net(sock->sk), tipc_net_id); | ||
| 605 | 624 | ||
| 606 | memset(addr, 0, sizeof(*addr)); | 625 | memset(addr, 0, sizeof(*addr)); |
| 607 | if (peer) { | 626 | if (peer) { |
| @@ -611,8 +630,8 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, | |||
| 611 | addr->addr.id.ref = tsk_peer_port(tsk); | 630 | addr->addr.id.ref = tsk_peer_port(tsk); |
| 612 | addr->addr.id.node = tsk_peer_node(tsk); | 631 | addr->addr.id.node = tsk_peer_node(tsk); |
| 613 | } else { | 632 | } else { |
| 614 | addr->addr.id.ref = tsk->ref; | 633 | addr->addr.id.ref = tsk->portid; |
| 615 | addr->addr.id.node = tipc_own_addr; | 634 | addr->addr.id.node = tn->own_addr; |
| 616 | } | 635 | } |
| 617 | 636 | ||
| 618 | *uaddr_len = sizeof(*addr); | 637 | *uaddr_len = sizeof(*addr); |
| @@ -711,6 +730,7 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq, | |||
| 711 | struct msghdr *msg, size_t dsz, long timeo) | 730 | struct msghdr *msg, size_t dsz, long timeo) |
| 712 | { | 731 | { |
| 713 | struct sock *sk = sock->sk; | 732 | struct sock *sk = sock->sk; |
| 733 | struct net *net = sock_net(sk); | ||
| 714 | struct tipc_msg *mhdr = &tipc_sk(sk)->phdr; | 734 | struct tipc_msg *mhdr = &tipc_sk(sk)->phdr; |
| 715 | struct sk_buff_head head; | 735 | struct sk_buff_head head; |
| 716 | uint mtu; | 736 | uint mtu; |
| @@ -728,12 +748,12 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq, | |||
| 728 | new_mtu: | 748 | new_mtu: |
| 729 | mtu = tipc_bclink_get_mtu(); | 749 | mtu = tipc_bclink_get_mtu(); |
| 730 | __skb_queue_head_init(&head); | 750 | __skb_queue_head_init(&head); |
| 731 | rc = tipc_msg_build(mhdr, msg, 0, dsz, mtu, &head); | 751 | rc = tipc_msg_build(net, mhdr, msg, 0, dsz, mtu, &head); |
| 732 | if (unlikely(rc < 0)) | 752 | if (unlikely(rc < 0)) |
| 733 | return rc; | 753 | return rc; |
| 734 | 754 | ||
| 735 | do { | 755 | do { |
| 736 | rc = tipc_bclink_xmit(&head); | 756 | rc = tipc_bclink_xmit(net, &head); |
| 737 | if (likely(rc >= 0)) { | 757 | if (likely(rc >= 0)) { |
| 738 | rc = dsz; | 758 | rc = dsz; |
| 739 | break; | 759 | break; |
| @@ -752,7 +772,7 @@ new_mtu: | |||
| 752 | 772 | ||
| 753 | /* tipc_sk_mcast_rcv - Deliver multicast message to all destination sockets | 773 | /* tipc_sk_mcast_rcv - Deliver multicast message to all destination sockets |
| 754 | */ | 774 | */ |
| 755 | void tipc_sk_mcast_rcv(struct sk_buff *buf) | 775 | void tipc_sk_mcast_rcv(struct net *net, struct sk_buff *buf) |
| 756 | { | 776 | { |
| 757 | struct tipc_msg *msg = buf_msg(buf); | 777 | struct tipc_msg *msg = buf_msg(buf); |
| 758 | struct tipc_port_list dports = {0, NULL, }; | 778 | struct tipc_port_list dports = {0, NULL, }; |
| @@ -761,15 +781,12 @@ void tipc_sk_mcast_rcv(struct sk_buff *buf) | |||
| 761 | uint i, last, dst = 0; | 781 | uint i, last, dst = 0; |
| 762 | u32 scope = TIPC_CLUSTER_SCOPE; | 782 | u32 scope = TIPC_CLUSTER_SCOPE; |
| 763 | 783 | ||
| 764 | if (in_own_node(msg_orignode(msg))) | 784 | if (in_own_node(net, msg_orignode(msg))) |
| 765 | scope = TIPC_NODE_SCOPE; | 785 | scope = TIPC_NODE_SCOPE; |
| 766 | 786 | ||
| 767 | /* Create destination port list: */ | 787 | /* Create destination port list: */ |
| 768 | tipc_nametbl_mc_translate(msg_nametype(msg), | 788 | tipc_nametbl_mc_translate(net, msg_nametype(msg), msg_namelower(msg), |
| 769 | msg_namelower(msg), | 789 | msg_nameupper(msg), scope, &dports); |
| 770 | msg_nameupper(msg), | ||
| 771 | scope, | ||
| 772 | &dports); | ||
| 773 | last = dports.count; | 790 | last = dports.count; |
| 774 | if (!last) { | 791 | if (!last) { |
| 775 | kfree_skb(buf); | 792 | kfree_skb(buf); |
| @@ -784,7 +801,7 @@ void tipc_sk_mcast_rcv(struct sk_buff *buf) | |||
| 784 | continue; | 801 | continue; |
| 785 | } | 802 | } |
| 786 | msg_set_destport(msg, item->ports[i]); | 803 | msg_set_destport(msg, item->ports[i]); |
| 787 | tipc_sk_rcv(b); | 804 | tipc_sk_rcv(net, b); |
| 788 | } | 805 | } |
| 789 | } | 806 | } |
| 790 | tipc_port_list_free(&dports); | 807 | tipc_port_list_free(&dports); |
| @@ -816,7 +833,7 @@ static int tipc_sk_proto_rcv(struct tipc_sock *tsk, u32 *dnode, | |||
| 816 | if (conn_cong) | 833 | if (conn_cong) |
| 817 | tsk->sk.sk_write_space(&tsk->sk); | 834 | tsk->sk.sk_write_space(&tsk->sk); |
| 818 | } else if (msg_type(msg) == CONN_PROBE) { | 835 | } else if (msg_type(msg) == CONN_PROBE) { |
| 819 | if (!tipc_msg_reverse(buf, dnode, TIPC_OK)) | 836 | if (!tipc_msg_reverse(sock_net(&tsk->sk), buf, dnode, TIPC_OK)) |
| 820 | return TIPC_OK; | 837 | return TIPC_OK; |
| 821 | msg_set_type(msg, CONN_PROBE_REPLY); | 838 | msg_set_type(msg, CONN_PROBE_REPLY); |
| 822 | return TIPC_FWD_MSG; | 839 | return TIPC_FWD_MSG; |
| @@ -872,6 +889,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock, | |||
| 872 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); | 889 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); |
| 873 | struct sock *sk = sock->sk; | 890 | struct sock *sk = sock->sk; |
| 874 | struct tipc_sock *tsk = tipc_sk(sk); | 891 | struct tipc_sock *tsk = tipc_sk(sk); |
| 892 | struct net *net = sock_net(sk); | ||
| 875 | struct tipc_msg *mhdr = &tsk->phdr; | 893 | struct tipc_msg *mhdr = &tsk->phdr; |
| 876 | u32 dnode, dport; | 894 | u32 dnode, dport; |
| 877 | struct sk_buff_head head; | 895 | struct sk_buff_head head; |
| @@ -929,7 +947,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock, | |||
| 929 | msg_set_nametype(mhdr, type); | 947 | msg_set_nametype(mhdr, type); |
| 930 | msg_set_nameinst(mhdr, inst); | 948 | msg_set_nameinst(mhdr, inst); |
| 931 | msg_set_lookup_scope(mhdr, tipc_addr_scope(domain)); | 949 | msg_set_lookup_scope(mhdr, tipc_addr_scope(domain)); |
| 932 | dport = tipc_nametbl_translate(type, inst, &dnode); | 950 | dport = tipc_nametbl_translate(net, type, inst, &dnode); |
| 933 | msg_set_destnode(mhdr, dnode); | 951 | msg_set_destnode(mhdr, dnode); |
| 934 | msg_set_destport(mhdr, dport); | 952 | msg_set_destport(mhdr, dport); |
| 935 | if (unlikely(!dport && !dnode)) { | 953 | if (unlikely(!dport && !dnode)) { |
| @@ -946,16 +964,16 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock, | |||
| 946 | } | 964 | } |
| 947 | 965 | ||
| 948 | new_mtu: | 966 | new_mtu: |
| 949 | mtu = tipc_node_get_mtu(dnode, tsk->ref); | 967 | mtu = tipc_node_get_mtu(net, dnode, tsk->portid); |
| 950 | __skb_queue_head_init(&head); | 968 | __skb_queue_head_init(&head); |
| 951 | rc = tipc_msg_build(mhdr, m, 0, dsz, mtu, &head); | 969 | rc = tipc_msg_build(net, mhdr, m, 0, dsz, mtu, &head); |
| 952 | if (rc < 0) | 970 | if (rc < 0) |
| 953 | goto exit; | 971 | goto exit; |
| 954 | 972 | ||
| 955 | do { | 973 | do { |
| 956 | skb = skb_peek(&head); | 974 | skb = skb_peek(&head); |
| 957 | TIPC_SKB_CB(skb)->wakeup_pending = tsk->link_cong; | 975 | TIPC_SKB_CB(skb)->wakeup_pending = tsk->link_cong; |
| 958 | rc = tipc_link_xmit(&head, dnode, tsk->ref); | 976 | rc = tipc_link_xmit(net, &head, dnode, tsk->portid); |
| 959 | if (likely(rc >= 0)) { | 977 | if (likely(rc >= 0)) { |
| 960 | if (sock->state != SS_READY) | 978 | if (sock->state != SS_READY) |
| 961 | sock->state = SS_CONNECTING; | 979 | sock->state = SS_CONNECTING; |
| @@ -1024,11 +1042,12 @@ static int tipc_send_stream(struct kiocb *iocb, struct socket *sock, | |||
| 1024 | struct msghdr *m, size_t dsz) | 1042 | struct msghdr *m, size_t dsz) |
| 1025 | { | 1043 | { |
| 1026 | struct sock *sk = sock->sk; | 1044 | struct sock *sk = sock->sk; |
| 1045 | struct net *net = sock_net(sk); | ||
| 1027 | struct tipc_sock *tsk = tipc_sk(sk); | 1046 | struct tipc_sock *tsk = tipc_sk(sk); |
| 1028 | struct tipc_msg *mhdr = &tsk->phdr; | 1047 | struct tipc_msg *mhdr = &tsk->phdr; |
| 1029 | struct sk_buff_head head; | 1048 | struct sk_buff_head head; |
| 1030 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); | 1049 | DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); |
| 1031 | u32 ref = tsk->ref; | 1050 | u32 portid = tsk->portid; |
| 1032 | int rc = -EINVAL; | 1051 | int rc = -EINVAL; |
| 1033 | long timeo; | 1052 | long timeo; |
| 1034 | u32 dnode; | 1053 | u32 dnode; |
| @@ -1062,12 +1081,12 @@ next: | |||
| 1062 | mtu = tsk->max_pkt; | 1081 | mtu = tsk->max_pkt; |
| 1063 | send = min_t(uint, dsz - sent, TIPC_MAX_USER_MSG_SIZE); | 1082 | send = min_t(uint, dsz - sent, TIPC_MAX_USER_MSG_SIZE); |
| 1064 | __skb_queue_head_init(&head); | 1083 | __skb_queue_head_init(&head); |
| 1065 | rc = tipc_msg_build(mhdr, m, sent, send, mtu, &head); | 1084 | rc = tipc_msg_build(net, mhdr, m, sent, send, mtu, &head); |
| 1066 | if (unlikely(rc < 0)) | 1085 | if (unlikely(rc < 0)) |
| 1067 | goto exit; | 1086 | goto exit; |
| 1068 | do { | 1087 | do { |
| 1069 | if (likely(!tsk_conn_cong(tsk))) { | 1088 | if (likely(!tsk_conn_cong(tsk))) { |
| 1070 | rc = tipc_link_xmit(&head, dnode, ref); | 1089 | rc = tipc_link_xmit(net, &head, dnode, portid); |
| 1071 | if (likely(!rc)) { | 1090 | if (likely(!rc)) { |
| 1072 | tsk->sent_unacked++; | 1091 | tsk->sent_unacked++; |
| 1073 | sent += send; | 1092 | sent += send; |
| @@ -1076,7 +1095,8 @@ next: | |||
| 1076 | goto next; | 1095 | goto next; |
| 1077 | } | 1096 | } |
| 1078 | if (rc == -EMSGSIZE) { | 1097 | if (rc == -EMSGSIZE) { |
| 1079 | tsk->max_pkt = tipc_node_get_mtu(dnode, ref); | 1098 | tsk->max_pkt = tipc_node_get_mtu(net, dnode, |
| 1099 | portid); | ||
| 1080 | goto next; | 1100 | goto next; |
| 1081 | } | 1101 | } |
| 1082 | if (rc != -ELINKCONG) | 1102 | if (rc != -ELINKCONG) |
| @@ -1118,6 +1138,8 @@ static int tipc_send_packet(struct kiocb *iocb, struct socket *sock, | |||
| 1118 | static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port, | 1138 | static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port, |
| 1119 | u32 peer_node) | 1139 | u32 peer_node) |
| 1120 | { | 1140 | { |
| 1141 | struct sock *sk = &tsk->sk; | ||
| 1142 | struct net *net = sock_net(sk); | ||
| 1121 | struct tipc_msg *msg = &tsk->phdr; | 1143 | struct tipc_msg *msg = &tsk->phdr; |
| 1122 | 1144 | ||
| 1123 | msg_set_destnode(msg, peer_node); | 1145 | msg_set_destnode(msg, peer_node); |
| @@ -1126,12 +1148,12 @@ static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port, | |||
| 1126 | msg_set_lookup_scope(msg, 0); | 1148 | msg_set_lookup_scope(msg, 0); |
| 1127 | msg_set_hdr_sz(msg, SHORT_H_SIZE); | 1149 | msg_set_hdr_sz(msg, SHORT_H_SIZE); |
| 1128 | 1150 | ||
| 1129 | tsk->probing_interval = CONN_PROBING_INTERVAL; | 1151 | tsk->probing_intv = CONN_PROBING_INTERVAL; |
| 1130 | tsk->probing_state = TIPC_CONN_OK; | 1152 | tsk->probing_state = TIPC_CONN_OK; |
| 1131 | tsk->connected = 1; | 1153 | tsk->connected = 1; |
| 1132 | k_start_timer(&tsk->timer, tsk->probing_interval); | 1154 | sk_reset_timer(sk, &sk->sk_timer, jiffies + tsk->probing_intv); |
| 1133 | tipc_node_add_conn(peer_node, tsk->ref, peer_port); | 1155 | tipc_node_add_conn(net, peer_node, tsk->portid, peer_port); |
| 1134 | tsk->max_pkt = tipc_node_get_mtu(peer_node, tsk->ref); | 1156 | tsk->max_pkt = tipc_node_get_mtu(net, peer_node, tsk->portid); |
| 1135 | } | 1157 | } |
| 1136 | 1158 | ||
| 1137 | /** | 1159 | /** |
| @@ -1230,6 +1252,8 @@ static int tipc_sk_anc_data_recv(struct msghdr *m, struct tipc_msg *msg, | |||
| 1230 | 1252 | ||
| 1231 | static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack) | 1253 | static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack) |
| 1232 | { | 1254 | { |
| 1255 | struct net *net = sock_net(&tsk->sk); | ||
| 1256 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 1233 | struct sk_buff *skb = NULL; | 1257 | struct sk_buff *skb = NULL; |
| 1234 | struct tipc_msg *msg; | 1258 | struct tipc_msg *msg; |
| 1235 | u32 peer_port = tsk_peer_port(tsk); | 1259 | u32 peer_port = tsk_peer_port(tsk); |
| @@ -1237,13 +1261,14 @@ static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack) | |||
| 1237 | 1261 | ||
| 1238 | if (!tsk->connected) | 1262 | if (!tsk->connected) |
| 1239 | return; | 1263 | return; |
| 1240 | skb = tipc_msg_create(CONN_MANAGER, CONN_ACK, INT_H_SIZE, 0, dnode, | 1264 | skb = tipc_msg_create(net, CONN_MANAGER, CONN_ACK, INT_H_SIZE, 0, |
| 1241 | tipc_own_addr, peer_port, tsk->ref, TIPC_OK); | 1265 | dnode, tn->own_addr, peer_port, tsk->portid, |
| 1266 | TIPC_OK); | ||
| 1242 | if (!skb) | 1267 | if (!skb) |
| 1243 | return; | 1268 | return; |
| 1244 | msg = buf_msg(skb); | 1269 | msg = buf_msg(skb); |
| 1245 | msg_set_msgcnt(msg, ack); | 1270 | msg_set_msgcnt(msg, ack); |
| 1246 | tipc_link_xmit_skb(skb, dnode, msg_link_selector(msg)); | 1271 | tipc_link_xmit_skb(net, skb, dnode, msg_link_selector(msg)); |
| 1247 | } | 1272 | } |
| 1248 | 1273 | ||
| 1249 | static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop) | 1274 | static int tipc_wait_for_rcvmsg(struct socket *sock, long *timeop) |
| @@ -1536,6 +1561,7 @@ static void tipc_data_ready(struct sock *sk) | |||
| 1536 | static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf) | 1561 | static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf) |
| 1537 | { | 1562 | { |
| 1538 | struct sock *sk = &tsk->sk; | 1563 | struct sock *sk = &tsk->sk; |
| 1564 | struct net *net = sock_net(sk); | ||
| 1539 | struct socket *sock = sk->sk_socket; | 1565 | struct socket *sock = sk->sk_socket; |
| 1540 | struct tipc_msg *msg = buf_msg(*buf); | 1566 | struct tipc_msg *msg = buf_msg(*buf); |
| 1541 | int retval = -TIPC_ERR_NO_PORT; | 1567 | int retval = -TIPC_ERR_NO_PORT; |
| @@ -1551,8 +1577,8 @@ static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf) | |||
| 1551 | sock->state = SS_DISCONNECTING; | 1577 | sock->state = SS_DISCONNECTING; |
| 1552 | tsk->connected = 0; | 1578 | tsk->connected = 0; |
| 1553 | /* let timer expire on it's own */ | 1579 | /* let timer expire on it's own */ |
| 1554 | tipc_node_remove_conn(tsk_peer_node(tsk), | 1580 | tipc_node_remove_conn(net, tsk_peer_node(tsk), |
| 1555 | tsk->ref); | 1581 | tsk->portid); |
| 1556 | } | 1582 | } |
| 1557 | retval = TIPC_OK; | 1583 | retval = TIPC_OK; |
| 1558 | } | 1584 | } |
| @@ -1709,6 +1735,7 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb) | |||
| 1709 | int rc; | 1735 | int rc; |
| 1710 | u32 onode; | 1736 | u32 onode; |
| 1711 | struct tipc_sock *tsk = tipc_sk(sk); | 1737 | struct tipc_sock *tsk = tipc_sk(sk); |
| 1738 | struct net *net = sock_net(sk); | ||
| 1712 | uint truesize = skb->truesize; | 1739 | uint truesize = skb->truesize; |
| 1713 | 1740 | ||
| 1714 | rc = filter_rcv(sk, skb); | 1741 | rc = filter_rcv(sk, skb); |
| @@ -1719,10 +1746,10 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb) | |||
| 1719 | return 0; | 1746 | return 0; |
| 1720 | } | 1747 | } |
| 1721 | 1748 | ||
| 1722 | if ((rc < 0) && !tipc_msg_reverse(skb, &onode, -rc)) | 1749 | if ((rc < 0) && !tipc_msg_reverse(net, skb, &onode, -rc)) |
| 1723 | return 0; | 1750 | return 0; |
| 1724 | 1751 | ||
| 1725 | tipc_link_xmit_skb(skb, onode, 0); | 1752 | tipc_link_xmit_skb(net, skb, onode, 0); |
| 1726 | 1753 | ||
| 1727 | return 0; | 1754 | return 0; |
| 1728 | } | 1755 | } |
| @@ -1733,7 +1760,7 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb) | |||
| 1733 | * Consumes buffer | 1760 | * Consumes buffer |
| 1734 | * Returns 0 if success, or errno: -EHOSTUNREACH | 1761 | * Returns 0 if success, or errno: -EHOSTUNREACH |
| 1735 | */ | 1762 | */ |
| 1736 | int tipc_sk_rcv(struct sk_buff *skb) | 1763 | int tipc_sk_rcv(struct net *net, struct sk_buff *skb) |
| 1737 | { | 1764 | { |
| 1738 | struct tipc_sock *tsk; | 1765 | struct tipc_sock *tsk; |
| 1739 | struct sock *sk; | 1766 | struct sock *sk; |
| @@ -1743,9 +1770,9 @@ int tipc_sk_rcv(struct sk_buff *skb) | |||
| 1743 | u32 dnode; | 1770 | u32 dnode; |
| 1744 | 1771 | ||
| 1745 | /* Validate destination and message */ | 1772 | /* Validate destination and message */ |
| 1746 | tsk = tipc_sk_get(dport); | 1773 | tsk = tipc_sk_lookup(net, dport); |
| 1747 | if (unlikely(!tsk)) { | 1774 | if (unlikely(!tsk)) { |
| 1748 | rc = tipc_msg_eval(skb, &dnode); | 1775 | rc = tipc_msg_eval(net, skb, &dnode); |
| 1749 | goto exit; | 1776 | goto exit; |
| 1750 | } | 1777 | } |
| 1751 | sk = &tsk->sk; | 1778 | sk = &tsk->sk; |
| @@ -1763,14 +1790,14 @@ int tipc_sk_rcv(struct sk_buff *skb) | |||
| 1763 | rc = -TIPC_ERR_OVERLOAD; | 1790 | rc = -TIPC_ERR_OVERLOAD; |
| 1764 | } | 1791 | } |
| 1765 | spin_unlock_bh(&sk->sk_lock.slock); | 1792 | spin_unlock_bh(&sk->sk_lock.slock); |
| 1766 | tipc_sk_put(tsk); | 1793 | sock_put(sk); |
| 1767 | if (likely(!rc)) | 1794 | if (likely(!rc)) |
| 1768 | return 0; | 1795 | return 0; |
| 1769 | exit: | 1796 | exit: |
| 1770 | if ((rc < 0) && !tipc_msg_reverse(skb, &dnode, -rc)) | 1797 | if ((rc < 0) && !tipc_msg_reverse(net, skb, &dnode, -rc)) |
| 1771 | return -EHOSTUNREACH; | 1798 | return -EHOSTUNREACH; |
| 1772 | 1799 | ||
| 1773 | tipc_link_xmit_skb(skb, dnode, 0); | 1800 | tipc_link_xmit_skb(net, skb, dnode, 0); |
| 1774 | return (rc < 0) ? -EHOSTUNREACH : 0; | 1801 | return (rc < 0) ? -EHOSTUNREACH : 0; |
| 1775 | } | 1802 | } |
| 1776 | 1803 | ||
| @@ -2027,6 +2054,8 @@ exit: | |||
| 2027 | static int tipc_shutdown(struct socket *sock, int how) | 2054 | static int tipc_shutdown(struct socket *sock, int how) |
| 2028 | { | 2055 | { |
| 2029 | struct sock *sk = sock->sk; | 2056 | struct sock *sk = sock->sk; |
| 2057 | struct net *net = sock_net(sk); | ||
| 2058 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 2030 | struct tipc_sock *tsk = tipc_sk(sk); | 2059 | struct tipc_sock *tsk = tipc_sk(sk); |
| 2031 | struct sk_buff *skb; | 2060 | struct sk_buff *skb; |
| 2032 | u32 dnode; | 2061 | u32 dnode; |
| @@ -2049,21 +2078,23 @@ restart: | |||
| 2049 | kfree_skb(skb); | 2078 | kfree_skb(skb); |
| 2050 | goto restart; | 2079 | goto restart; |
| 2051 | } | 2080 | } |
| 2052 | if (tipc_msg_reverse(skb, &dnode, TIPC_CONN_SHUTDOWN)) | 2081 | if (tipc_msg_reverse(net, skb, &dnode, |
| 2053 | tipc_link_xmit_skb(skb, dnode, tsk->ref); | 2082 | TIPC_CONN_SHUTDOWN)) |
| 2054 | tipc_node_remove_conn(dnode, tsk->ref); | 2083 | tipc_link_xmit_skb(net, skb, dnode, |
| 2084 | tsk->portid); | ||
| 2085 | tipc_node_remove_conn(net, dnode, tsk->portid); | ||
| 2055 | } else { | 2086 | } else { |
| 2056 | dnode = tsk_peer_node(tsk); | 2087 | dnode = tsk_peer_node(tsk); |
| 2057 | skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, | 2088 | skb = tipc_msg_create(net, TIPC_CRITICAL_IMPORTANCE, |
| 2058 | TIPC_CONN_MSG, SHORT_H_SIZE, | 2089 | TIPC_CONN_MSG, SHORT_H_SIZE, |
| 2059 | 0, dnode, tipc_own_addr, | 2090 | 0, dnode, tn->own_addr, |
| 2060 | tsk_peer_port(tsk), | 2091 | tsk_peer_port(tsk), |
| 2061 | tsk->ref, TIPC_CONN_SHUTDOWN); | 2092 | tsk->portid, TIPC_CONN_SHUTDOWN); |
| 2062 | tipc_link_xmit_skb(skb, dnode, tsk->ref); | 2093 | tipc_link_xmit_skb(net, skb, dnode, tsk->portid); |
| 2063 | } | 2094 | } |
| 2064 | tsk->connected = 0; | 2095 | tsk->connected = 0; |
| 2065 | sock->state = SS_DISCONNECTING; | 2096 | sock->state = SS_DISCONNECTING; |
| 2066 | tipc_node_remove_conn(dnode, tsk->ref); | 2097 | tipc_node_remove_conn(net, dnode, tsk->portid); |
| 2067 | /* fall through */ | 2098 | /* fall through */ |
| 2068 | 2099 | ||
| 2069 | case SS_DISCONNECTING: | 2100 | case SS_DISCONNECTING: |
| @@ -2084,18 +2115,15 @@ restart: | |||
| 2084 | return res; | 2115 | return res; |
| 2085 | } | 2116 | } |
| 2086 | 2117 | ||
| 2087 | static void tipc_sk_timeout(unsigned long ref) | 2118 | static void tipc_sk_timeout(unsigned long data) |
| 2088 | { | 2119 | { |
| 2089 | struct tipc_sock *tsk; | 2120 | struct tipc_sock *tsk = (struct tipc_sock *)data; |
| 2090 | struct sock *sk; | 2121 | struct sock *sk = &tsk->sk; |
| 2122 | struct net *net = sock_net(sk); | ||
| 2123 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 2091 | struct sk_buff *skb = NULL; | 2124 | struct sk_buff *skb = NULL; |
| 2092 | u32 peer_port, peer_node; | 2125 | u32 peer_port, peer_node; |
| 2093 | 2126 | ||
| 2094 | tsk = tipc_sk_get(ref); | ||
| 2095 | if (!tsk) | ||
| 2096 | return; | ||
| 2097 | |||
| 2098 | sk = &tsk->sk; | ||
| 2099 | bh_lock_sock(sk); | 2127 | bh_lock_sock(sk); |
| 2100 | if (!tsk->connected) { | 2128 | if (!tsk->connected) { |
| 2101 | bh_unlock_sock(sk); | 2129 | bh_unlock_sock(sk); |
| @@ -2106,38 +2134,39 @@ static void tipc_sk_timeout(unsigned long ref) | |||
| 2106 | 2134 | ||
| 2107 | if (tsk->probing_state == TIPC_CONN_PROBING) { | 2135 | if (tsk->probing_state == TIPC_CONN_PROBING) { |
| 2108 | /* Previous probe not answered -> self abort */ | 2136 | /* Previous probe not answered -> self abort */ |
| 2109 | skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, | 2137 | skb = tipc_msg_create(net, TIPC_CRITICAL_IMPORTANCE, |
| 2110 | SHORT_H_SIZE, 0, tipc_own_addr, | 2138 | TIPC_CONN_MSG, SHORT_H_SIZE, 0, |
| 2111 | peer_node, ref, peer_port, | 2139 | tn->own_addr, peer_node, tsk->portid, |
| 2112 | TIPC_ERR_NO_PORT); | 2140 | peer_port, TIPC_ERR_NO_PORT); |
| 2113 | } else { | 2141 | } else { |
| 2114 | skb = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE, | 2142 | skb = tipc_msg_create(net, CONN_MANAGER, CONN_PROBE, INT_H_SIZE, |
| 2115 | 0, peer_node, tipc_own_addr, | 2143 | 0, peer_node, tn->own_addr, |
| 2116 | peer_port, ref, TIPC_OK); | 2144 | peer_port, tsk->portid, TIPC_OK); |
| 2117 | tsk->probing_state = TIPC_CONN_PROBING; | 2145 | tsk->probing_state = TIPC_CONN_PROBING; |
| 2118 | k_start_timer(&tsk->timer, tsk->probing_interval); | 2146 | sk_reset_timer(sk, &sk->sk_timer, jiffies + tsk->probing_intv); |
| 2119 | } | 2147 | } |
| 2120 | bh_unlock_sock(sk); | 2148 | bh_unlock_sock(sk); |
| 2121 | if (skb) | 2149 | if (skb) |
| 2122 | tipc_link_xmit_skb(skb, peer_node, ref); | 2150 | tipc_link_xmit_skb(sock_net(sk), skb, peer_node, tsk->portid); |
| 2123 | exit: | 2151 | exit: |
| 2124 | tipc_sk_put(tsk); | 2152 | sock_put(sk); |
| 2125 | } | 2153 | } |
| 2126 | 2154 | ||
| 2127 | static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, | 2155 | static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, |
| 2128 | struct tipc_name_seq const *seq) | 2156 | struct tipc_name_seq const *seq) |
| 2129 | { | 2157 | { |
| 2158 | struct net *net = sock_net(&tsk->sk); | ||
| 2130 | struct publication *publ; | 2159 | struct publication *publ; |
| 2131 | u32 key; | 2160 | u32 key; |
| 2132 | 2161 | ||
| 2133 | if (tsk->connected) | 2162 | if (tsk->connected) |
| 2134 | return -EINVAL; | 2163 | return -EINVAL; |
| 2135 | key = tsk->ref + tsk->pub_count + 1; | 2164 | key = tsk->portid + tsk->pub_count + 1; |
| 2136 | if (key == tsk->ref) | 2165 | if (key == tsk->portid) |
| 2137 | return -EADDRINUSE; | 2166 | return -EADDRINUSE; |
| 2138 | 2167 | ||
| 2139 | publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper, | 2168 | publ = tipc_nametbl_publish(net, seq->type, seq->lower, seq->upper, |
| 2140 | scope, tsk->ref, key); | 2169 | scope, tsk->portid, key); |
| 2141 | if (unlikely(!publ)) | 2170 | if (unlikely(!publ)) |
| 2142 | return -EINVAL; | 2171 | return -EINVAL; |
| 2143 | 2172 | ||
| @@ -2150,6 +2179,7 @@ static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, | |||
| 2150 | static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, | 2179 | static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, |
| 2151 | struct tipc_name_seq const *seq) | 2180 | struct tipc_name_seq const *seq) |
| 2152 | { | 2181 | { |
| 2182 | struct net *net = sock_net(&tsk->sk); | ||
| 2153 | struct publication *publ; | 2183 | struct publication *publ; |
| 2154 | struct publication *safe; | 2184 | struct publication *safe; |
| 2155 | int rc = -EINVAL; | 2185 | int rc = -EINVAL; |
| @@ -2164,12 +2194,12 @@ static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, | |||
| 2164 | continue; | 2194 | continue; |
| 2165 | if (publ->upper != seq->upper) | 2195 | if (publ->upper != seq->upper) |
| 2166 | break; | 2196 | break; |
| 2167 | tipc_nametbl_withdraw(publ->type, publ->lower, | 2197 | tipc_nametbl_withdraw(net, publ->type, publ->lower, |
| 2168 | publ->ref, publ->key); | 2198 | publ->ref, publ->key); |
| 2169 | rc = 0; | 2199 | rc = 0; |
| 2170 | break; | 2200 | break; |
| 2171 | } | 2201 | } |
| 2172 | tipc_nametbl_withdraw(publ->type, publ->lower, | 2202 | tipc_nametbl_withdraw(net, publ->type, publ->lower, |
| 2173 | publ->ref, publ->key); | 2203 | publ->ref, publ->key); |
| 2174 | rc = 0; | 2204 | rc = 0; |
| 2175 | } | 2205 | } |
| @@ -2181,16 +2211,18 @@ static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, | |||
| 2181 | static int tipc_sk_show(struct tipc_sock *tsk, char *buf, | 2211 | static int tipc_sk_show(struct tipc_sock *tsk, char *buf, |
| 2182 | int len, int full_id) | 2212 | int len, int full_id) |
| 2183 | { | 2213 | { |
| 2214 | struct net *net = sock_net(&tsk->sk); | ||
| 2215 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 2184 | struct publication *publ; | 2216 | struct publication *publ; |
| 2185 | int ret; | 2217 | int ret; |
| 2186 | 2218 | ||
| 2187 | if (full_id) | 2219 | if (full_id) |
| 2188 | ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:", | 2220 | ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:", |
| 2189 | tipc_zone(tipc_own_addr), | 2221 | tipc_zone(tn->own_addr), |
| 2190 | tipc_cluster(tipc_own_addr), | 2222 | tipc_cluster(tn->own_addr), |
| 2191 | tipc_node(tipc_own_addr), tsk->ref); | 2223 | tipc_node(tn->own_addr), tsk->portid); |
| 2192 | else | 2224 | else |
| 2193 | ret = tipc_snprintf(buf, len, "%-10u:", tsk->ref); | 2225 | ret = tipc_snprintf(buf, len, "%-10u:", tsk->portid); |
| 2194 | 2226 | ||
| 2195 | if (tsk->connected) { | 2227 | if (tsk->connected) { |
| 2196 | u32 dport = tsk_peer_port(tsk); | 2228 | u32 dport = tsk_peer_port(tsk); |
| @@ -2222,15 +2254,18 @@ static int tipc_sk_show(struct tipc_sock *tsk, char *buf, | |||
| 2222 | return ret; | 2254 | return ret; |
| 2223 | } | 2255 | } |
| 2224 | 2256 | ||
| 2225 | struct sk_buff *tipc_sk_socks_show(void) | 2257 | struct sk_buff *tipc_sk_socks_show(struct net *net) |
| 2226 | { | 2258 | { |
| 2259 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 2260 | const struct bucket_table *tbl; | ||
| 2261 | struct rhash_head *pos; | ||
| 2227 | struct sk_buff *buf; | 2262 | struct sk_buff *buf; |
| 2228 | struct tlv_desc *rep_tlv; | 2263 | struct tlv_desc *rep_tlv; |
| 2229 | char *pb; | 2264 | char *pb; |
| 2230 | int pb_len; | 2265 | int pb_len; |
| 2231 | struct tipc_sock *tsk; | 2266 | struct tipc_sock *tsk; |
| 2232 | int str_len = 0; | 2267 | int str_len = 0; |
| 2233 | u32 ref = 0; | 2268 | int i; |
| 2234 | 2269 | ||
| 2235 | buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN)); | 2270 | buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN)); |
| 2236 | if (!buf) | 2271 | if (!buf) |
| @@ -2239,14 +2274,18 @@ struct sk_buff *tipc_sk_socks_show(void) | |||
| 2239 | pb = TLV_DATA(rep_tlv); | 2274 | pb = TLV_DATA(rep_tlv); |
| 2240 | pb_len = ULTRA_STRING_MAX_LEN; | 2275 | pb_len = ULTRA_STRING_MAX_LEN; |
| 2241 | 2276 | ||
| 2242 | tsk = tipc_sk_get_next(&ref); | 2277 | rcu_read_lock(); |
| 2243 | for (; tsk; tsk = tipc_sk_get_next(&ref)) { | 2278 | tbl = rht_dereference_rcu((&tn->sk_rht)->tbl, &tn->sk_rht); |
| 2244 | lock_sock(&tsk->sk); | 2279 | for (i = 0; i < tbl->size; i++) { |
| 2245 | str_len += tipc_sk_show(tsk, pb + str_len, | 2280 | rht_for_each_entry_rcu(tsk, pos, tbl, i, node) { |
| 2246 | pb_len - str_len, 0); | 2281 | spin_lock_bh(&tsk->sk.sk_lock.slock); |
| 2247 | release_sock(&tsk->sk); | 2282 | str_len += tipc_sk_show(tsk, pb + str_len, |
| 2248 | tipc_sk_put(tsk); | 2283 | pb_len - str_len, 0); |
| 2284 | spin_unlock_bh(&tsk->sk.sk_lock.slock); | ||
| 2285 | } | ||
| 2249 | } | 2286 | } |
| 2287 | rcu_read_unlock(); | ||
| 2288 | |||
| 2250 | str_len += 1; /* for "\0" */ | 2289 | str_len += 1; /* for "\0" */ |
| 2251 | skb_put(buf, TLV_SPACE(str_len)); | 2290 | skb_put(buf, TLV_SPACE(str_len)); |
| 2252 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); | 2291 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| @@ -2257,257 +2296,102 @@ struct sk_buff *tipc_sk_socks_show(void) | |||
| 2257 | /* tipc_sk_reinit: set non-zero address in all existing sockets | 2296 | /* tipc_sk_reinit: set non-zero address in all existing sockets |
| 2258 | * when we go from standalone to network mode. | 2297 | * when we go from standalone to network mode. |
| 2259 | */ | 2298 | */ |
| 2260 | void tipc_sk_reinit(void) | 2299 | void tipc_sk_reinit(struct net *net) |
| 2261 | { | 2300 | { |
| 2301 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 2302 | const struct bucket_table *tbl; | ||
| 2303 | struct rhash_head *pos; | ||
| 2304 | struct tipc_sock *tsk; | ||
| 2262 | struct tipc_msg *msg; | 2305 | struct tipc_msg *msg; |
| 2263 | u32 ref = 0; | 2306 | int i; |
| 2264 | struct tipc_sock *tsk = tipc_sk_get_next(&ref); | ||
| 2265 | 2307 | ||
| 2266 | for (; tsk; tsk = tipc_sk_get_next(&ref)) { | 2308 | rcu_read_lock(); |
| 2267 | lock_sock(&tsk->sk); | 2309 | tbl = rht_dereference_rcu((&tn->sk_rht)->tbl, &tn->sk_rht); |
| 2268 | msg = &tsk->phdr; | 2310 | for (i = 0; i < tbl->size; i++) { |
| 2269 | msg_set_prevnode(msg, tipc_own_addr); | 2311 | rht_for_each_entry_rcu(tsk, pos, tbl, i, node) { |
| 2270 | msg_set_orignode(msg, tipc_own_addr); | 2312 | spin_lock_bh(&tsk->sk.sk_lock.slock); |
| 2271 | release_sock(&tsk->sk); | 2313 | msg = &tsk->phdr; |
| 2272 | tipc_sk_put(tsk); | 2314 | msg_set_prevnode(msg, tn->own_addr); |
| 2315 | msg_set_orignode(msg, tn->own_addr); | ||
| 2316 | spin_unlock_bh(&tsk->sk.sk_lock.slock); | ||
| 2317 | } | ||
| 2273 | } | 2318 | } |
| 2319 | rcu_read_unlock(); | ||
| 2274 | } | 2320 | } |
| 2275 | 2321 | ||
| 2276 | /** | 2322 | static struct tipc_sock *tipc_sk_lookup(struct net *net, u32 portid) |
| 2277 | * struct reference - TIPC socket reference entry | ||
| 2278 | * @tsk: pointer to socket associated with reference entry | ||
| 2279 | * @ref: reference value for socket (combines instance & array index info) | ||
| 2280 | */ | ||
| 2281 | struct reference { | ||
| 2282 | struct tipc_sock *tsk; | ||
| 2283 | u32 ref; | ||
| 2284 | }; | ||
| 2285 | |||
| 2286 | /** | ||
| 2287 | * struct tipc_ref_table - table of TIPC socket reference entries | ||
| 2288 | * @entries: pointer to array of reference entries | ||
| 2289 | * @capacity: array index of first unusable entry | ||
| 2290 | * @init_point: array index of first uninitialized entry | ||
| 2291 | * @first_free: array index of first unused socket reference entry | ||
| 2292 | * @last_free: array index of last unused socket reference entry | ||
| 2293 | * @index_mask: bitmask for array index portion of reference values | ||
| 2294 | * @start_mask: initial value for instance value portion of reference values | ||
| 2295 | */ | ||
| 2296 | struct ref_table { | ||
| 2297 | struct reference *entries; | ||
| 2298 | u32 capacity; | ||
| 2299 | u32 init_point; | ||
| 2300 | u32 first_free; | ||
| 2301 | u32 last_free; | ||
| 2302 | u32 index_mask; | ||
| 2303 | u32 start_mask; | ||
| 2304 | }; | ||
| 2305 | |||
| 2306 | /* Socket reference table consists of 2**N entries. | ||
| 2307 | * | ||
| 2308 | * State Socket ptr Reference | ||
| 2309 | * ----- ---------- --------- | ||
| 2310 | * In use non-NULL XXXX|own index | ||
| 2311 | * (XXXX changes each time entry is acquired) | ||
| 2312 | * Free NULL YYYY|next free index | ||
| 2313 | * (YYYY is one more than last used XXXX) | ||
| 2314 | * Uninitialized NULL 0 | ||
| 2315 | * | ||
| 2316 | * Entry 0 is not used; this allows index 0 to denote the end of the free list. | ||
| 2317 | * | ||
| 2318 | * Note that a reference value of 0 does not necessarily indicate that an | ||
| 2319 | * entry is uninitialized, since the last entry in the free list could also | ||
| 2320 | * have a reference value of 0 (although this is unlikely). | ||
| 2321 | */ | ||
| 2322 | |||
| 2323 | static struct ref_table tipc_ref_table; | ||
| 2324 | |||
| 2325 | static DEFINE_RWLOCK(ref_table_lock); | ||
| 2326 | |||
| 2327 | /** | ||
| 2328 | * tipc_ref_table_init - create reference table for sockets | ||
| 2329 | */ | ||
| 2330 | int tipc_sk_ref_table_init(u32 req_sz, u32 start) | ||
| 2331 | { | 2323 | { |
| 2332 | struct reference *table; | 2324 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 2333 | u32 actual_sz; | 2325 | struct tipc_sock *tsk; |
| 2334 | |||
| 2335 | /* account for unused entry, then round up size to a power of 2 */ | ||
| 2336 | |||
| 2337 | req_sz++; | ||
| 2338 | for (actual_sz = 16; actual_sz < req_sz; actual_sz <<= 1) { | ||
| 2339 | /* do nothing */ | ||
| 2340 | }; | ||
| 2341 | |||
| 2342 | /* allocate table & mark all entries as uninitialized */ | ||
| 2343 | table = vzalloc(actual_sz * sizeof(struct reference)); | ||
| 2344 | if (table == NULL) | ||
| 2345 | return -ENOMEM; | ||
| 2346 | |||
| 2347 | tipc_ref_table.entries = table; | ||
| 2348 | tipc_ref_table.capacity = req_sz; | ||
| 2349 | tipc_ref_table.init_point = 1; | ||
| 2350 | tipc_ref_table.first_free = 0; | ||
| 2351 | tipc_ref_table.last_free = 0; | ||
| 2352 | tipc_ref_table.index_mask = actual_sz - 1; | ||
| 2353 | tipc_ref_table.start_mask = start & ~tipc_ref_table.index_mask; | ||
| 2354 | 2326 | ||
| 2355 | return 0; | 2327 | rcu_read_lock(); |
| 2356 | } | 2328 | tsk = rhashtable_lookup(&tn->sk_rht, &portid); |
| 2329 | if (tsk) | ||
| 2330 | sock_hold(&tsk->sk); | ||
| 2331 | rcu_read_unlock(); | ||
| 2357 | 2332 | ||
| 2358 | /** | 2333 | return tsk; |
| 2359 | * tipc_ref_table_stop - destroy reference table for sockets | ||
| 2360 | */ | ||
| 2361 | void tipc_sk_ref_table_stop(void) | ||
| 2362 | { | ||
| 2363 | if (!tipc_ref_table.entries) | ||
| 2364 | return; | ||
| 2365 | vfree(tipc_ref_table.entries); | ||
| 2366 | tipc_ref_table.entries = NULL; | ||
| 2367 | } | 2334 | } |
| 2368 | 2335 | ||
| 2369 | /* tipc_ref_acquire - create reference to a socket | 2336 | static int tipc_sk_insert(struct tipc_sock *tsk) |
| 2370 | * | ||
| 2371 | * Register an socket pointer in the reference table. | ||
| 2372 | * Returns a unique reference value that is used from then on to retrieve the | ||
| 2373 | * socket pointer, or to determine if the socket has been deregistered. | ||
| 2374 | */ | ||
| 2375 | u32 tipc_sk_ref_acquire(struct tipc_sock *tsk) | ||
| 2376 | { | 2337 | { |
| 2377 | u32 index; | 2338 | struct sock *sk = &tsk->sk; |
| 2378 | u32 index_mask; | 2339 | struct net *net = sock_net(sk); |
| 2379 | u32 next_plus_upper; | 2340 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 2380 | u32 ref = 0; | 2341 | u32 remaining = (TIPC_MAX_PORT - TIPC_MIN_PORT) + 1; |
| 2381 | struct reference *entry; | 2342 | u32 portid = prandom_u32() % remaining + TIPC_MIN_PORT; |
| 2382 | 2343 | ||
| 2383 | if (unlikely(!tsk)) { | 2344 | while (remaining--) { |
| 2384 | pr_err("Attempt to acquire ref. to non-existent obj\n"); | 2345 | portid++; |
| 2385 | return 0; | 2346 | if ((portid < TIPC_MIN_PORT) || (portid > TIPC_MAX_PORT)) |
| 2386 | } | 2347 | portid = TIPC_MIN_PORT; |
| 2387 | if (unlikely(!tipc_ref_table.entries)) { | 2348 | tsk->portid = portid; |
| 2388 | pr_err("Ref. table not found in acquisition attempt\n"); | 2349 | sock_hold(&tsk->sk); |
| 2389 | return 0; | 2350 | if (rhashtable_lookup_insert(&tn->sk_rht, &tsk->node)) |
| 2390 | } | 2351 | return 0; |
| 2391 | 2352 | sock_put(&tsk->sk); | |
| 2392 | /* Take a free entry, if available; otherwise initialize a new one */ | ||
| 2393 | write_lock_bh(&ref_table_lock); | ||
| 2394 | index = tipc_ref_table.first_free; | ||
| 2395 | entry = &tipc_ref_table.entries[index]; | ||
| 2396 | |||
| 2397 | if (likely(index)) { | ||
| 2398 | index = tipc_ref_table.first_free; | ||
| 2399 | entry = &tipc_ref_table.entries[index]; | ||
| 2400 | index_mask = tipc_ref_table.index_mask; | ||
| 2401 | next_plus_upper = entry->ref; | ||
| 2402 | tipc_ref_table.first_free = next_plus_upper & index_mask; | ||
| 2403 | ref = (next_plus_upper & ~index_mask) + index; | ||
| 2404 | entry->tsk = tsk; | ||
| 2405 | } else if (tipc_ref_table.init_point < tipc_ref_table.capacity) { | ||
| 2406 | index = tipc_ref_table.init_point++; | ||
| 2407 | entry = &tipc_ref_table.entries[index]; | ||
| 2408 | ref = tipc_ref_table.start_mask + index; | ||
| 2409 | } | 2353 | } |
| 2410 | 2354 | ||
| 2411 | if (ref) { | 2355 | return -1; |
| 2412 | entry->ref = ref; | ||
| 2413 | entry->tsk = tsk; | ||
| 2414 | } | ||
| 2415 | write_unlock_bh(&ref_table_lock); | ||
| 2416 | return ref; | ||
| 2417 | } | 2356 | } |
| 2418 | 2357 | ||
| 2419 | /* tipc_sk_ref_discard - invalidate reference to an socket | 2358 | static void tipc_sk_remove(struct tipc_sock *tsk) |
| 2420 | * | ||
| 2421 | * Disallow future references to an socket and free up the entry for re-use. | ||
| 2422 | */ | ||
| 2423 | void tipc_sk_ref_discard(u32 ref) | ||
| 2424 | { | 2359 | { |
| 2425 | struct reference *entry; | 2360 | struct sock *sk = &tsk->sk; |
| 2426 | u32 index; | 2361 | struct tipc_net *tn = net_generic(sock_net(sk), tipc_net_id); |
| 2427 | u32 index_mask; | ||
| 2428 | |||
| 2429 | if (unlikely(!tipc_ref_table.entries)) { | ||
| 2430 | pr_err("Ref. table not found during discard attempt\n"); | ||
| 2431 | return; | ||
| 2432 | } | ||
| 2433 | |||
| 2434 | index_mask = tipc_ref_table.index_mask; | ||
| 2435 | index = ref & index_mask; | ||
| 2436 | entry = &tipc_ref_table.entries[index]; | ||
| 2437 | |||
| 2438 | write_lock_bh(&ref_table_lock); | ||
| 2439 | 2362 | ||
| 2440 | if (unlikely(!entry->tsk)) { | 2363 | if (rhashtable_remove(&tn->sk_rht, &tsk->node)) { |
| 2441 | pr_err("Attempt to discard ref. to non-existent socket\n"); | 2364 | WARN_ON(atomic_read(&sk->sk_refcnt) == 1); |
| 2442 | goto exit; | 2365 | __sock_put(sk); |
| 2443 | } | 2366 | } |
| 2444 | if (unlikely(entry->ref != ref)) { | ||
| 2445 | pr_err("Attempt to discard non-existent reference\n"); | ||
| 2446 | goto exit; | ||
| 2447 | } | ||
| 2448 | |||
| 2449 | /* Mark entry as unused; increment instance part of entry's | ||
| 2450 | * reference to invalidate any subsequent references | ||
| 2451 | */ | ||
| 2452 | |||
| 2453 | entry->tsk = NULL; | ||
| 2454 | entry->ref = (ref & ~index_mask) + (index_mask + 1); | ||
| 2455 | |||
| 2456 | /* Append entry to free entry list */ | ||
| 2457 | if (unlikely(tipc_ref_table.first_free == 0)) | ||
| 2458 | tipc_ref_table.first_free = index; | ||
| 2459 | else | ||
| 2460 | tipc_ref_table.entries[tipc_ref_table.last_free].ref |= index; | ||
| 2461 | tipc_ref_table.last_free = index; | ||
| 2462 | exit: | ||
| 2463 | write_unlock_bh(&ref_table_lock); | ||
| 2464 | } | 2367 | } |
| 2465 | 2368 | ||
| 2466 | /* tipc_sk_get - find referenced socket and return pointer to it | 2369 | int tipc_sk_rht_init(struct net *net) |
| 2467 | */ | ||
| 2468 | struct tipc_sock *tipc_sk_get(u32 ref) | ||
| 2469 | { | 2370 | { |
| 2470 | struct reference *entry; | 2371 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 2471 | struct tipc_sock *tsk; | 2372 | struct rhashtable_params rht_params = { |
| 2373 | .nelem_hint = 192, | ||
| 2374 | .head_offset = offsetof(struct tipc_sock, node), | ||
| 2375 | .key_offset = offsetof(struct tipc_sock, portid), | ||
| 2376 | .key_len = sizeof(u32), /* portid */ | ||
| 2377 | .hashfn = jhash, | ||
| 2378 | .max_shift = 20, /* 1M */ | ||
| 2379 | .min_shift = 8, /* 256 */ | ||
| 2380 | .grow_decision = rht_grow_above_75, | ||
| 2381 | .shrink_decision = rht_shrink_below_30, | ||
| 2382 | }; | ||
| 2472 | 2383 | ||
| 2473 | if (unlikely(!tipc_ref_table.entries)) | 2384 | return rhashtable_init(&tn->sk_rht, &rht_params); |
| 2474 | return NULL; | ||
| 2475 | read_lock_bh(&ref_table_lock); | ||
| 2476 | entry = &tipc_ref_table.entries[ref & tipc_ref_table.index_mask]; | ||
| 2477 | tsk = entry->tsk; | ||
| 2478 | if (likely(tsk && (entry->ref == ref))) | ||
| 2479 | sock_hold(&tsk->sk); | ||
| 2480 | else | ||
| 2481 | tsk = NULL; | ||
| 2482 | read_unlock_bh(&ref_table_lock); | ||
| 2483 | return tsk; | ||
| 2484 | } | 2385 | } |
| 2485 | 2386 | ||
| 2486 | /* tipc_sk_get_next - lock & return next socket after referenced one | 2387 | void tipc_sk_rht_destroy(struct net *net) |
| 2487 | */ | ||
| 2488 | struct tipc_sock *tipc_sk_get_next(u32 *ref) | ||
| 2489 | { | 2388 | { |
| 2490 | struct reference *entry; | 2389 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 2491 | struct tipc_sock *tsk = NULL; | ||
| 2492 | uint index = *ref & tipc_ref_table.index_mask; | ||
| 2493 | 2390 | ||
| 2494 | read_lock_bh(&ref_table_lock); | 2391 | /* Wait for socket readers to complete */ |
| 2495 | while (++index < tipc_ref_table.capacity) { | 2392 | synchronize_net(); |
| 2496 | entry = &tipc_ref_table.entries[index]; | ||
| 2497 | if (!entry->tsk) | ||
| 2498 | continue; | ||
| 2499 | tsk = entry->tsk; | ||
| 2500 | sock_hold(&tsk->sk); | ||
| 2501 | *ref = entry->ref; | ||
| 2502 | break; | ||
| 2503 | } | ||
| 2504 | read_unlock_bh(&ref_table_lock); | ||
| 2505 | return tsk; | ||
| 2506 | } | ||
| 2507 | 2393 | ||
| 2508 | static void tipc_sk_put(struct tipc_sock *tsk) | 2394 | rhashtable_destroy(&tn->sk_rht); |
| 2509 | { | ||
| 2510 | sock_put(&tsk->sk); | ||
| 2511 | } | 2395 | } |
| 2512 | 2396 | ||
| 2513 | /** | 2397 | /** |
| @@ -2639,8 +2523,9 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt, | |||
| 2639 | return put_user(sizeof(value), ol); | 2523 | return put_user(sizeof(value), ol); |
| 2640 | } | 2524 | } |
| 2641 | 2525 | ||
| 2642 | static int tipc_ioctl(struct socket *sk, unsigned int cmd, unsigned long arg) | 2526 | static int tipc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) |
| 2643 | { | 2527 | { |
| 2528 | struct sock *sk = sock->sk; | ||
| 2644 | struct tipc_sioc_ln_req lnr; | 2529 | struct tipc_sioc_ln_req lnr; |
| 2645 | void __user *argp = (void __user *)arg; | 2530 | void __user *argp = (void __user *)arg; |
| 2646 | 2531 | ||
| @@ -2648,7 +2533,8 @@ static int tipc_ioctl(struct socket *sk, unsigned int cmd, unsigned long arg) | |||
| 2648 | case SIOCGETLINKNAME: | 2533 | case SIOCGETLINKNAME: |
| 2649 | if (copy_from_user(&lnr, argp, sizeof(lnr))) | 2534 | if (copy_from_user(&lnr, argp, sizeof(lnr))) |
| 2650 | return -EFAULT; | 2535 | return -EFAULT; |
| 2651 | if (!tipc_node_get_linkname(lnr.bearer_id & 0xffff, lnr.peer, | 2536 | if (!tipc_node_get_linkname(sock_net(sk), |
| 2537 | lnr.bearer_id & 0xffff, lnr.peer, | ||
| 2652 | lnr.linkname, TIPC_MAX_LINK_NAME)) { | 2538 | lnr.linkname, TIPC_MAX_LINK_NAME)) { |
| 2653 | if (copy_to_user(argp, &lnr, sizeof(lnr))) | 2539 | if (copy_to_user(argp, &lnr, sizeof(lnr))) |
| 2654 | return -EFAULT; | 2540 | return -EFAULT; |
| @@ -2820,6 +2706,8 @@ static int __tipc_nl_add_sk(struct sk_buff *skb, struct netlink_callback *cb, | |||
| 2820 | int err; | 2706 | int err; |
| 2821 | void *hdr; | 2707 | void *hdr; |
| 2822 | struct nlattr *attrs; | 2708 | struct nlattr *attrs; |
| 2709 | struct net *net = sock_net(skb->sk); | ||
| 2710 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 2823 | 2711 | ||
| 2824 | hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, | 2712 | hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, |
| 2825 | &tipc_genl_v2_family, NLM_F_MULTI, TIPC_NL_SOCK_GET); | 2713 | &tipc_genl_v2_family, NLM_F_MULTI, TIPC_NL_SOCK_GET); |
| @@ -2829,9 +2717,9 @@ static int __tipc_nl_add_sk(struct sk_buff *skb, struct netlink_callback *cb, | |||
| 2829 | attrs = nla_nest_start(skb, TIPC_NLA_SOCK); | 2717 | attrs = nla_nest_start(skb, TIPC_NLA_SOCK); |
| 2830 | if (!attrs) | 2718 | if (!attrs) |
| 2831 | goto genlmsg_cancel; | 2719 | goto genlmsg_cancel; |
| 2832 | if (nla_put_u32(skb, TIPC_NLA_SOCK_REF, tsk->ref)) | 2720 | if (nla_put_u32(skb, TIPC_NLA_SOCK_REF, tsk->portid)) |
| 2833 | goto attr_msg_cancel; | 2721 | goto attr_msg_cancel; |
| 2834 | if (nla_put_u32(skb, TIPC_NLA_SOCK_ADDR, tipc_own_addr)) | 2722 | if (nla_put_u32(skb, TIPC_NLA_SOCK_ADDR, tn->own_addr)) |
| 2835 | goto attr_msg_cancel; | 2723 | goto attr_msg_cancel; |
| 2836 | 2724 | ||
| 2837 | if (tsk->connected) { | 2725 | if (tsk->connected) { |
| @@ -2859,22 +2747,37 @@ int tipc_nl_sk_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 2859 | { | 2747 | { |
| 2860 | int err; | 2748 | int err; |
| 2861 | struct tipc_sock *tsk; | 2749 | struct tipc_sock *tsk; |
| 2862 | u32 prev_ref = cb->args[0]; | 2750 | const struct bucket_table *tbl; |
| 2863 | u32 ref = prev_ref; | 2751 | struct rhash_head *pos; |
| 2864 | 2752 | struct net *net = sock_net(skb->sk); | |
| 2865 | tsk = tipc_sk_get_next(&ref); | 2753 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 2866 | for (; tsk; tsk = tipc_sk_get_next(&ref)) { | 2754 | u32 tbl_id = cb->args[0]; |
| 2867 | lock_sock(&tsk->sk); | 2755 | u32 prev_portid = cb->args[1]; |
| 2868 | err = __tipc_nl_add_sk(skb, cb, tsk); | ||
| 2869 | release_sock(&tsk->sk); | ||
| 2870 | tipc_sk_put(tsk); | ||
| 2871 | if (err) | ||
| 2872 | break; | ||
| 2873 | 2756 | ||
| 2874 | prev_ref = ref; | 2757 | rcu_read_lock(); |
| 2875 | } | 2758 | tbl = rht_dereference_rcu((&tn->sk_rht)->tbl, &tn->sk_rht); |
| 2759 | for (; tbl_id < tbl->size; tbl_id++) { | ||
| 2760 | rht_for_each_entry_rcu(tsk, pos, tbl, tbl_id, node) { | ||
| 2761 | spin_lock_bh(&tsk->sk.sk_lock.slock); | ||
| 2762 | if (prev_portid && prev_portid != tsk->portid) { | ||
| 2763 | spin_unlock_bh(&tsk->sk.sk_lock.slock); | ||
| 2764 | continue; | ||
| 2765 | } | ||
| 2876 | 2766 | ||
| 2877 | cb->args[0] = prev_ref; | 2767 | err = __tipc_nl_add_sk(skb, cb, tsk); |
| 2768 | if (err) { | ||
| 2769 | prev_portid = tsk->portid; | ||
| 2770 | spin_unlock_bh(&tsk->sk.sk_lock.slock); | ||
| 2771 | goto out; | ||
| 2772 | } | ||
| 2773 | prev_portid = 0; | ||
| 2774 | spin_unlock_bh(&tsk->sk.sk_lock.slock); | ||
| 2775 | } | ||
| 2776 | } | ||
| 2777 | out: | ||
| 2778 | rcu_read_unlock(); | ||
| 2779 | cb->args[0] = tbl_id; | ||
| 2780 | cb->args[1] = prev_portid; | ||
| 2878 | 2781 | ||
| 2879 | return skb->len; | 2782 | return skb->len; |
| 2880 | } | 2783 | } |
| @@ -2962,12 +2865,13 @@ static int __tipc_nl_list_sk_publ(struct sk_buff *skb, | |||
| 2962 | int tipc_nl_publ_dump(struct sk_buff *skb, struct netlink_callback *cb) | 2865 | int tipc_nl_publ_dump(struct sk_buff *skb, struct netlink_callback *cb) |
| 2963 | { | 2866 | { |
| 2964 | int err; | 2867 | int err; |
| 2965 | u32 tsk_ref = cb->args[0]; | 2868 | u32 tsk_portid = cb->args[0]; |
| 2966 | u32 last_publ = cb->args[1]; | 2869 | u32 last_publ = cb->args[1]; |
| 2967 | u32 done = cb->args[2]; | 2870 | u32 done = cb->args[2]; |
| 2871 | struct net *net = sock_net(skb->sk); | ||
| 2968 | struct tipc_sock *tsk; | 2872 | struct tipc_sock *tsk; |
| 2969 | 2873 | ||
| 2970 | if (!tsk_ref) { | 2874 | if (!tsk_portid) { |
| 2971 | struct nlattr **attrs; | 2875 | struct nlattr **attrs; |
| 2972 | struct nlattr *sock[TIPC_NLA_SOCK_MAX + 1]; | 2876 | struct nlattr *sock[TIPC_NLA_SOCK_MAX + 1]; |
| 2973 | 2877 | ||
| @@ -2984,13 +2888,13 @@ int tipc_nl_publ_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 2984 | if (!sock[TIPC_NLA_SOCK_REF]) | 2888 | if (!sock[TIPC_NLA_SOCK_REF]) |
| 2985 | return -EINVAL; | 2889 | return -EINVAL; |
| 2986 | 2890 | ||
| 2987 | tsk_ref = nla_get_u32(sock[TIPC_NLA_SOCK_REF]); | 2891 | tsk_portid = nla_get_u32(sock[TIPC_NLA_SOCK_REF]); |
| 2988 | } | 2892 | } |
| 2989 | 2893 | ||
| 2990 | if (done) | 2894 | if (done) |
| 2991 | return 0; | 2895 | return 0; |
| 2992 | 2896 | ||
| 2993 | tsk = tipc_sk_get(tsk_ref); | 2897 | tsk = tipc_sk_lookup(net, tsk_portid); |
| 2994 | if (!tsk) | 2898 | if (!tsk) |
| 2995 | return -EINVAL; | 2899 | return -EINVAL; |
| 2996 | 2900 | ||
| @@ -2999,9 +2903,9 @@ int tipc_nl_publ_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 2999 | if (!err) | 2903 | if (!err) |
| 3000 | done = 1; | 2904 | done = 1; |
| 3001 | release_sock(&tsk->sk); | 2905 | release_sock(&tsk->sk); |
| 3002 | tipc_sk_put(tsk); | 2906 | sock_put(&tsk->sk); |
| 3003 | 2907 | ||
| 3004 | cb->args[0] = tsk_ref; | 2908 | cb->args[0] = tsk_portid; |
| 3005 | cb->args[1] = last_publ; | 2909 | cb->args[1] = last_publ; |
| 3006 | cb->args[2] = done; | 2910 | cb->args[2] = done; |
| 3007 | 2911 | ||
diff --git a/net/tipc/socket.h b/net/tipc/socket.h index d34089387006..f56c3fded51f 100644 --- a/net/tipc/socket.h +++ b/net/tipc/socket.h | |||
| @@ -42,12 +42,19 @@ | |||
| 42 | #define TIPC_FLOWCTRL_WIN (TIPC_CONNACK_INTV * 2) | 42 | #define TIPC_FLOWCTRL_WIN (TIPC_CONNACK_INTV * 2) |
| 43 | #define TIPC_CONN_OVERLOAD_LIMIT ((TIPC_FLOWCTRL_WIN * 2 + 1) * \ | 43 | #define TIPC_CONN_OVERLOAD_LIMIT ((TIPC_FLOWCTRL_WIN * 2 + 1) * \ |
| 44 | SKB_TRUESIZE(TIPC_MAX_USER_MSG_SIZE)) | 44 | SKB_TRUESIZE(TIPC_MAX_USER_MSG_SIZE)) |
| 45 | int tipc_sk_rcv(struct sk_buff *buf); | 45 | |
| 46 | struct sk_buff *tipc_sk_socks_show(void); | 46 | int tipc_socket_init(void); |
| 47 | void tipc_sk_mcast_rcv(struct sk_buff *buf); | 47 | void tipc_socket_stop(void); |
| 48 | void tipc_sk_reinit(void); | 48 | int tipc_sock_create_local(struct net *net, int type, struct socket **res); |
| 49 | int tipc_sk_ref_table_init(u32 requested_size, u32 start); | 49 | void tipc_sock_release_local(struct socket *sock); |
| 50 | void tipc_sk_ref_table_stop(void); | 50 | int tipc_sock_accept_local(struct socket *sock, struct socket **newsock, |
| 51 | int flags); | ||
| 52 | int tipc_sk_rcv(struct net *net, struct sk_buff *buf); | ||
| 53 | struct sk_buff *tipc_sk_socks_show(struct net *net); | ||
| 54 | void tipc_sk_mcast_rcv(struct net *net, struct sk_buff *buf); | ||
| 55 | void tipc_sk_reinit(struct net *net); | ||
| 56 | int tipc_sk_rht_init(struct net *net); | ||
| 57 | void tipc_sk_rht_destroy(struct net *net); | ||
| 51 | int tipc_nl_sk_dump(struct sk_buff *skb, struct netlink_callback *cb); | 58 | int tipc_nl_sk_dump(struct sk_buff *skb, struct netlink_callback *cb); |
| 52 | int tipc_nl_publ_dump(struct sk_buff *skb, struct netlink_callback *cb); | 59 | int tipc_nl_publ_dump(struct sk_buff *skb, struct netlink_callback *cb); |
| 53 | 60 | ||
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c index 0344206b984f..72c339e432aa 100644 --- a/net/tipc/subscr.c +++ b/net/tipc/subscr.c | |||
| @@ -50,33 +50,6 @@ struct tipc_subscriber { | |||
| 50 | struct list_head subscription_list; | 50 | struct list_head subscription_list; |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 53 | static void subscr_conn_msg_event(int conid, struct sockaddr_tipc *addr, | ||
| 54 | void *usr_data, void *buf, size_t len); | ||
| 55 | static void *subscr_named_msg_event(int conid); | ||
| 56 | static void subscr_conn_shutdown_event(int conid, void *usr_data); | ||
| 57 | |||
| 58 | static atomic_t subscription_count = ATOMIC_INIT(0); | ||
| 59 | |||
| 60 | static struct sockaddr_tipc topsrv_addr __read_mostly = { | ||
| 61 | .family = AF_TIPC, | ||
| 62 | .addrtype = TIPC_ADDR_NAMESEQ, | ||
| 63 | .addr.nameseq.type = TIPC_TOP_SRV, | ||
| 64 | .addr.nameseq.lower = TIPC_TOP_SRV, | ||
| 65 | .addr.nameseq.upper = TIPC_TOP_SRV, | ||
| 66 | .scope = TIPC_NODE_SCOPE | ||
| 67 | }; | ||
| 68 | |||
| 69 | static struct tipc_server topsrv __read_mostly = { | ||
| 70 | .saddr = &topsrv_addr, | ||
| 71 | .imp = TIPC_CRITICAL_IMPORTANCE, | ||
| 72 | .type = SOCK_SEQPACKET, | ||
| 73 | .max_rcvbuf_size = sizeof(struct tipc_subscr), | ||
| 74 | .name = "topology_server", | ||
| 75 | .tipc_conn_recvmsg = subscr_conn_msg_event, | ||
| 76 | .tipc_conn_new = subscr_named_msg_event, | ||
| 77 | .tipc_conn_shutdown = subscr_conn_shutdown_event, | ||
| 78 | }; | ||
| 79 | |||
| 80 | /** | 53 | /** |
| 81 | * htohl - convert value to endianness used by destination | 54 | * htohl - convert value to endianness used by destination |
| 82 | * @in: value to convert | 55 | * @in: value to convert |
| @@ -93,6 +66,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower, | |||
| 93 | u32 found_upper, u32 event, u32 port_ref, | 66 | u32 found_upper, u32 event, u32 port_ref, |
| 94 | u32 node) | 67 | u32 node) |
| 95 | { | 68 | { |
| 69 | struct tipc_net *tn = net_generic(sub->net, tipc_net_id); | ||
| 96 | struct tipc_subscriber *subscriber = sub->subscriber; | 70 | struct tipc_subscriber *subscriber = sub->subscriber; |
| 97 | struct kvec msg_sect; | 71 | struct kvec msg_sect; |
| 98 | 72 | ||
| @@ -103,8 +77,8 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower, | |||
| 103 | sub->evt.found_upper = htohl(found_upper, sub->swap); | 77 | sub->evt.found_upper = htohl(found_upper, sub->swap); |
| 104 | sub->evt.port.ref = htohl(port_ref, sub->swap); | 78 | sub->evt.port.ref = htohl(port_ref, sub->swap); |
| 105 | sub->evt.port.node = htohl(node, sub->swap); | 79 | sub->evt.port.node = htohl(node, sub->swap); |
| 106 | tipc_conn_sendmsg(&topsrv, subscriber->conid, NULL, msg_sect.iov_base, | 80 | tipc_conn_sendmsg(tn->topsrv, subscriber->conid, NULL, |
| 107 | msg_sect.iov_len); | 81 | msg_sect.iov_base, msg_sect.iov_len); |
| 108 | } | 82 | } |
| 109 | 83 | ||
| 110 | /** | 84 | /** |
| @@ -141,9 +115,11 @@ void tipc_subscr_report_overlap(struct tipc_subscription *sub, u32 found_lower, | |||
| 141 | subscr_send_event(sub, found_lower, found_upper, event, port_ref, node); | 115 | subscr_send_event(sub, found_lower, found_upper, event, port_ref, node); |
| 142 | } | 116 | } |
| 143 | 117 | ||
| 144 | static void subscr_timeout(struct tipc_subscription *sub) | 118 | static void subscr_timeout(unsigned long data) |
| 145 | { | 119 | { |
| 120 | struct tipc_subscription *sub = (struct tipc_subscription *)data; | ||
| 146 | struct tipc_subscriber *subscriber = sub->subscriber; | 121 | struct tipc_subscriber *subscriber = sub->subscriber; |
| 122 | struct tipc_net *tn = net_generic(sub->net, tipc_net_id); | ||
| 147 | 123 | ||
| 148 | /* The spin lock per subscriber is used to protect its members */ | 124 | /* The spin lock per subscriber is used to protect its members */ |
| 149 | spin_lock_bh(&subscriber->lock); | 125 | spin_lock_bh(&subscriber->lock); |
| @@ -167,9 +143,8 @@ static void subscr_timeout(struct tipc_subscription *sub) | |||
| 167 | TIPC_SUBSCR_TIMEOUT, 0, 0); | 143 | TIPC_SUBSCR_TIMEOUT, 0, 0); |
| 168 | 144 | ||
| 169 | /* Now destroy subscription */ | 145 | /* Now destroy subscription */ |
| 170 | k_term_timer(&sub->timer); | ||
| 171 | kfree(sub); | 146 | kfree(sub); |
| 172 | atomic_dec(&subscription_count); | 147 | atomic_dec(&tn->subscription_count); |
| 173 | } | 148 | } |
| 174 | 149 | ||
| 175 | /** | 150 | /** |
| @@ -179,10 +154,12 @@ static void subscr_timeout(struct tipc_subscription *sub) | |||
| 179 | */ | 154 | */ |
| 180 | static void subscr_del(struct tipc_subscription *sub) | 155 | static void subscr_del(struct tipc_subscription *sub) |
| 181 | { | 156 | { |
| 157 | struct tipc_net *tn = net_generic(sub->net, tipc_net_id); | ||
| 158 | |||
| 182 | tipc_nametbl_unsubscribe(sub); | 159 | tipc_nametbl_unsubscribe(sub); |
| 183 | list_del(&sub->subscription_list); | 160 | list_del(&sub->subscription_list); |
| 184 | kfree(sub); | 161 | kfree(sub); |
| 185 | atomic_dec(&subscription_count); | 162 | atomic_dec(&tn->subscription_count); |
| 186 | } | 163 | } |
| 187 | 164 | ||
| 188 | /** | 165 | /** |
| @@ -190,9 +167,12 @@ static void subscr_del(struct tipc_subscription *sub) | |||
| 190 | * | 167 | * |
| 191 | * Note: Must call it in process context since it might sleep. | 168 | * Note: Must call it in process context since it might sleep. |
| 192 | */ | 169 | */ |
| 193 | static void subscr_terminate(struct tipc_subscriber *subscriber) | 170 | static void subscr_terminate(struct tipc_subscription *sub) |
| 194 | { | 171 | { |
| 195 | tipc_conn_terminate(&topsrv, subscriber->conid); | 172 | struct tipc_subscriber *subscriber = sub->subscriber; |
| 173 | struct tipc_net *tn = net_generic(sub->net, tipc_net_id); | ||
| 174 | |||
| 175 | tipc_conn_terminate(tn->topsrv, subscriber->conid); | ||
| 196 | } | 176 | } |
| 197 | 177 | ||
| 198 | static void subscr_release(struct tipc_subscriber *subscriber) | 178 | static void subscr_release(struct tipc_subscriber *subscriber) |
| @@ -207,8 +187,7 @@ static void subscr_release(struct tipc_subscriber *subscriber) | |||
| 207 | subscription_list) { | 187 | subscription_list) { |
| 208 | if (sub->timeout != TIPC_WAIT_FOREVER) { | 188 | if (sub->timeout != TIPC_WAIT_FOREVER) { |
| 209 | spin_unlock_bh(&subscriber->lock); | 189 | spin_unlock_bh(&subscriber->lock); |
| 210 | k_cancel_timer(&sub->timer); | 190 | del_timer_sync(&sub->timer); |
| 211 | k_term_timer(&sub->timer); | ||
| 212 | spin_lock_bh(&subscriber->lock); | 191 | spin_lock_bh(&subscriber->lock); |
| 213 | } | 192 | } |
| 214 | subscr_del(sub); | 193 | subscr_del(sub); |
| @@ -250,8 +229,7 @@ static void subscr_cancel(struct tipc_subscr *s, | |||
| 250 | if (sub->timeout != TIPC_WAIT_FOREVER) { | 229 | if (sub->timeout != TIPC_WAIT_FOREVER) { |
| 251 | sub->timeout = TIPC_WAIT_FOREVER; | 230 | sub->timeout = TIPC_WAIT_FOREVER; |
| 252 | spin_unlock_bh(&subscriber->lock); | 231 | spin_unlock_bh(&subscriber->lock); |
| 253 | k_cancel_timer(&sub->timer); | 232 | del_timer_sync(&sub->timer); |
| 254 | k_term_timer(&sub->timer); | ||
| 255 | spin_lock_bh(&subscriber->lock); | 233 | spin_lock_bh(&subscriber->lock); |
| 256 | } | 234 | } |
| 257 | subscr_del(sub); | 235 | subscr_del(sub); |
| @@ -262,9 +240,11 @@ static void subscr_cancel(struct tipc_subscr *s, | |||
| 262 | * | 240 | * |
| 263 | * Called with subscriber lock held. | 241 | * Called with subscriber lock held. |
| 264 | */ | 242 | */ |
| 265 | static int subscr_subscribe(struct tipc_subscr *s, | 243 | static int subscr_subscribe(struct net *net, struct tipc_subscr *s, |
| 266 | struct tipc_subscriber *subscriber, | 244 | struct tipc_subscriber *subscriber, |
| 267 | struct tipc_subscription **sub_p) { | 245 | struct tipc_subscription **sub_p) |
| 246 | { | ||
| 247 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
| 268 | struct tipc_subscription *sub; | 248 | struct tipc_subscription *sub; |
| 269 | int swap; | 249 | int swap; |
| 270 | 250 | ||
| @@ -279,7 +259,7 @@ static int subscr_subscribe(struct tipc_subscr *s, | |||
| 279 | } | 259 | } |
| 280 | 260 | ||
| 281 | /* Refuse subscription if global limit exceeded */ | 261 | /* Refuse subscription if global limit exceeded */ |
| 282 | if (atomic_read(&subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) { | 262 | if (atomic_read(&tn->subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) { |
| 283 | pr_warn("Subscription rejected, limit reached (%u)\n", | 263 | pr_warn("Subscription rejected, limit reached (%u)\n", |
| 284 | TIPC_MAX_SUBSCRIPTIONS); | 264 | TIPC_MAX_SUBSCRIPTIONS); |
| 285 | return -EINVAL; | 265 | return -EINVAL; |
| @@ -293,10 +273,11 @@ static int subscr_subscribe(struct tipc_subscr *s, | |||
| 293 | } | 273 | } |
| 294 | 274 | ||
| 295 | /* Initialize subscription object */ | 275 | /* Initialize subscription object */ |
| 276 | sub->net = net; | ||
| 296 | sub->seq.type = htohl(s->seq.type, swap); | 277 | sub->seq.type = htohl(s->seq.type, swap); |
| 297 | sub->seq.lower = htohl(s->seq.lower, swap); | 278 | sub->seq.lower = htohl(s->seq.lower, swap); |
| 298 | sub->seq.upper = htohl(s->seq.upper, swap); | 279 | sub->seq.upper = htohl(s->seq.upper, swap); |
| 299 | sub->timeout = htohl(s->timeout, swap); | 280 | sub->timeout = msecs_to_jiffies(htohl(s->timeout, swap)); |
| 300 | sub->filter = htohl(s->filter, swap); | 281 | sub->filter = htohl(s->filter, swap); |
| 301 | if ((!(sub->filter & TIPC_SUB_PORTS) == | 282 | if ((!(sub->filter & TIPC_SUB_PORTS) == |
| 302 | !(sub->filter & TIPC_SUB_SERVICE)) || | 283 | !(sub->filter & TIPC_SUB_SERVICE)) || |
| @@ -309,11 +290,10 @@ static int subscr_subscribe(struct tipc_subscr *s, | |||
| 309 | sub->subscriber = subscriber; | 290 | sub->subscriber = subscriber; |
| 310 | sub->swap = swap; | 291 | sub->swap = swap; |
| 311 | memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr)); | 292 | memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr)); |
| 312 | atomic_inc(&subscription_count); | 293 | atomic_inc(&tn->subscription_count); |
| 313 | if (sub->timeout != TIPC_WAIT_FOREVER) { | 294 | if (sub->timeout != TIPC_WAIT_FOREVER) { |
| 314 | k_init_timer(&sub->timer, | 295 | setup_timer(&sub->timer, subscr_timeout, (unsigned long)sub); |
| 315 | (Handler)subscr_timeout, (unsigned long)sub); | 296 | mod_timer(&sub->timer, jiffies + sub->timeout); |
| 316 | k_start_timer(&sub->timer, sub->timeout); | ||
| 317 | } | 297 | } |
| 318 | *sub_p = sub; | 298 | *sub_p = sub; |
| 319 | return 0; | 299 | return 0; |
| @@ -326,16 +306,18 @@ static void subscr_conn_shutdown_event(int conid, void *usr_data) | |||
| 326 | } | 306 | } |
| 327 | 307 | ||
| 328 | /* Handle one request to create a new subscription for the subscriber */ | 308 | /* Handle one request to create a new subscription for the subscriber */ |
| 329 | static void subscr_conn_msg_event(int conid, struct sockaddr_tipc *addr, | 309 | static void subscr_conn_msg_event(struct net *net, int conid, |
| 330 | void *usr_data, void *buf, size_t len) | 310 | struct sockaddr_tipc *addr, void *usr_data, |
| 311 | void *buf, size_t len) | ||
| 331 | { | 312 | { |
| 332 | struct tipc_subscriber *subscriber = usr_data; | 313 | struct tipc_subscriber *subscriber = usr_data; |
| 333 | struct tipc_subscription *sub = NULL; | 314 | struct tipc_subscription *sub = NULL; |
| 334 | 315 | ||
| 335 | spin_lock_bh(&subscriber->lock); | 316 | spin_lock_bh(&subscriber->lock); |
| 336 | if (subscr_subscribe((struct tipc_subscr *)buf, subscriber, &sub) < 0) { | 317 | if (subscr_subscribe(net, (struct tipc_subscr *)buf, subscriber, |
| 318 | &sub) < 0) { | ||
| 337 | spin_unlock_bh(&subscriber->lock); | 319 | spin_unlock_bh(&subscriber->lock); |
| 338 | subscr_terminate(subscriber); | 320 | subscr_terminate(sub); |
| 339 | return; | 321 | return; |
| 340 | } | 322 | } |
| 341 | if (sub) | 323 | if (sub) |
| @@ -343,7 +325,6 @@ static void subscr_conn_msg_event(int conid, struct sockaddr_tipc *addr, | |||
| 343 | spin_unlock_bh(&subscriber->lock); | 325 | spin_unlock_bh(&subscriber->lock); |
| 344 | } | 326 | } |
| 345 | 327 | ||
| 346 | |||
| 347 | /* Handle one request to establish a new subscriber */ | 328 | /* Handle one request to establish a new subscriber */ |
| 348 | static void *subscr_named_msg_event(int conid) | 329 | static void *subscr_named_msg_event(int conid) |
| 349 | { | 330 | { |
| @@ -362,12 +343,50 @@ static void *subscr_named_msg_event(int conid) | |||
| 362 | return (void *)subscriber; | 343 | return (void *)subscriber; |
| 363 | } | 344 | } |
| 364 | 345 | ||
| 365 | int tipc_subscr_start(void) | 346 | int tipc_subscr_start(struct net *net) |
| 366 | { | 347 | { |
| 367 | return tipc_server_start(&topsrv); | 348 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 349 | const char name[] = "topology_server"; | ||
| 350 | struct tipc_server *topsrv; | ||
| 351 | struct sockaddr_tipc *saddr; | ||
| 352 | |||
| 353 | saddr = kzalloc(sizeof(*saddr), GFP_ATOMIC); | ||
| 354 | if (!saddr) | ||
| 355 | return -ENOMEM; | ||
| 356 | saddr->family = AF_TIPC; | ||
| 357 | saddr->addrtype = TIPC_ADDR_NAMESEQ; | ||
| 358 | saddr->addr.nameseq.type = TIPC_TOP_SRV; | ||
| 359 | saddr->addr.nameseq.lower = TIPC_TOP_SRV; | ||
| 360 | saddr->addr.nameseq.upper = TIPC_TOP_SRV; | ||
| 361 | saddr->scope = TIPC_NODE_SCOPE; | ||
| 362 | |||
| 363 | topsrv = kzalloc(sizeof(*topsrv), GFP_ATOMIC); | ||
| 364 | if (!topsrv) { | ||
| 365 | kfree(saddr); | ||
| 366 | return -ENOMEM; | ||
| 367 | } | ||
| 368 | topsrv->net = net; | ||
| 369 | topsrv->saddr = saddr; | ||
| 370 | topsrv->imp = TIPC_CRITICAL_IMPORTANCE; | ||
| 371 | topsrv->type = SOCK_SEQPACKET; | ||
| 372 | topsrv->max_rcvbuf_size = sizeof(struct tipc_subscr); | ||
| 373 | topsrv->tipc_conn_recvmsg = subscr_conn_msg_event; | ||
| 374 | topsrv->tipc_conn_new = subscr_named_msg_event; | ||
| 375 | topsrv->tipc_conn_shutdown = subscr_conn_shutdown_event; | ||
| 376 | |||
| 377 | strncpy(topsrv->name, name, strlen(name) + 1); | ||
| 378 | tn->topsrv = topsrv; | ||
| 379 | atomic_set(&tn->subscription_count, 0); | ||
| 380 | |||
| 381 | return tipc_server_start(topsrv); | ||
| 368 | } | 382 | } |
| 369 | 383 | ||
| 370 | void tipc_subscr_stop(void) | 384 | void tipc_subscr_stop(struct net *net) |
| 371 | { | 385 | { |
| 372 | tipc_server_stop(&topsrv); | 386 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 387 | struct tipc_server *topsrv = tn->topsrv; | ||
| 388 | |||
| 389 | tipc_server_stop(topsrv); | ||
| 390 | kfree(topsrv->saddr); | ||
| 391 | kfree(topsrv); | ||
| 373 | } | 392 | } |
diff --git a/net/tipc/subscr.h b/net/tipc/subscr.h index 393e417bee3f..33488bd9fe3c 100644 --- a/net/tipc/subscr.h +++ b/net/tipc/subscr.h | |||
| @@ -39,6 +39,9 @@ | |||
| 39 | 39 | ||
| 40 | #include "server.h" | 40 | #include "server.h" |
| 41 | 41 | ||
| 42 | #define TIPC_MAX_SUBSCRIPTIONS 65535 | ||
| 43 | #define TIPC_MAX_PUBLICATIONS 65535 | ||
| 44 | |||
| 42 | struct tipc_subscription; | 45 | struct tipc_subscription; |
| 43 | struct tipc_subscriber; | 46 | struct tipc_subscriber; |
| 44 | 47 | ||
| @@ -46,6 +49,7 @@ struct tipc_subscriber; | |||
| 46 | * struct tipc_subscription - TIPC network topology subscription object | 49 | * struct tipc_subscription - TIPC network topology subscription object |
| 47 | * @subscriber: pointer to its subscriber | 50 | * @subscriber: pointer to its subscriber |
| 48 | * @seq: name sequence associated with subscription | 51 | * @seq: name sequence associated with subscription |
| 52 | * @net: point to network namespace | ||
| 49 | * @timeout: duration of subscription (in ms) | 53 | * @timeout: duration of subscription (in ms) |
| 50 | * @filter: event filtering to be done for subscription | 54 | * @filter: event filtering to be done for subscription |
| 51 | * @timer: timer governing subscription duration (optional) | 55 | * @timer: timer governing subscription duration (optional) |
| @@ -58,7 +62,8 @@ struct tipc_subscriber; | |||
| 58 | struct tipc_subscription { | 62 | struct tipc_subscription { |
| 59 | struct tipc_subscriber *subscriber; | 63 | struct tipc_subscriber *subscriber; |
| 60 | struct tipc_name_seq seq; | 64 | struct tipc_name_seq seq; |
| 61 | u32 timeout; | 65 | struct net *net; |
| 66 | unsigned long timeout; | ||
| 62 | u32 filter; | 67 | u32 filter; |
| 63 | struct timer_list timer; | 68 | struct timer_list timer; |
| 64 | struct list_head nameseq_list; | 69 | struct list_head nameseq_list; |
| @@ -69,13 +74,10 @@ struct tipc_subscription { | |||
| 69 | 74 | ||
| 70 | int tipc_subscr_overlap(struct tipc_subscription *sub, u32 found_lower, | 75 | int tipc_subscr_overlap(struct tipc_subscription *sub, u32 found_lower, |
| 71 | u32 found_upper); | 76 | u32 found_upper); |
| 72 | |||
| 73 | void tipc_subscr_report_overlap(struct tipc_subscription *sub, u32 found_lower, | 77 | void tipc_subscr_report_overlap(struct tipc_subscription *sub, u32 found_lower, |
| 74 | u32 found_upper, u32 event, u32 port_ref, | 78 | u32 found_upper, u32 event, u32 port_ref, |
| 75 | u32 node, int must); | 79 | u32 node, int must); |
| 76 | 80 | int tipc_subscr_start(struct net *net); | |
| 77 | int tipc_subscr_start(void); | 81 | void tipc_subscr_stop(struct net *net); |
| 78 | |||
| 79 | void tipc_subscr_stop(void); | ||
| 80 | 82 | ||
| 81 | #endif | 83 | #endif |
