diff options
author | Ying Xue <ying.xue@windriver.com> | 2015-01-09 02:27:04 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-01-12 16:24:32 -0500 |
commit | c93d3baa24095887005647984cff5de8c63d3611 (patch) | |
tree | 1c7917d92605991696960243fe97dfef9d14913a /net/tipc | |
parent | 54fef04ad05f15984082c225fe47ce6af8ea1c5c (diff) |
tipc: involve namespace infrastructure
Involve namespace infrastructure, make the "tipc_net_id" global
variable aware of per namespace, and rename it to "net_id". In
order that the conversion can be successfully done, an instance
of networking namespace must be passed to relevant functions,
allowing them to access the "net_id" variable of per namespace.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Tested-by: Tero Aho <Tero.Aho@coriant.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r-- | net/tipc/bcast.c | 15 | ||||
-rw-r--r-- | net/tipc/bcast.h | 5 | ||||
-rw-r--r-- | net/tipc/bearer.c | 29 | ||||
-rw-r--r-- | net/tipc/bearer.h | 5 | ||||
-rw-r--r-- | net/tipc/config.c | 29 | ||||
-rw-r--r-- | net/tipc/config.h | 2 | ||||
-rw-r--r-- | net/tipc/core.c | 28 | ||||
-rw-r--r-- | net/tipc/core.h | 5 | ||||
-rw-r--r-- | net/tipc/discover.c | 26 | ||||
-rw-r--r-- | net/tipc/discover.h | 8 | ||||
-rw-r--r-- | net/tipc/link.c | 47 | ||||
-rw-r--r-- | net/tipc/msg.c | 4 | ||||
-rw-r--r-- | net/tipc/net.c | 22 | ||||
-rw-r--r-- | net/tipc/net.h | 2 | ||||
-rw-r--r-- | net/tipc/netlink.c | 10 |
15 files changed, 151 insertions, 86 deletions
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c index a9e174fc0f91..f98231138916 100644 --- a/net/tipc/bcast.c +++ b/net/tipc/bcast.c | |||
@@ -327,9 +327,11 @@ exit: | |||
327 | * | 327 | * |
328 | * RCU and node lock set | 328 | * RCU and node lock set |
329 | */ | 329 | */ |
330 | void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent) | 330 | void tipc_bclink_update_link_state(struct net *net, struct tipc_node *n_ptr, |
331 | u32 last_sent) | ||
331 | { | 332 | { |
332 | struct sk_buff *buf; | 333 | struct sk_buff *buf; |
334 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
333 | 335 | ||
334 | /* Ignore "stale" link state info */ | 336 | /* Ignore "stale" link state info */ |
335 | if (less_eq(last_sent, n_ptr->bclink.last_in)) | 337 | if (less_eq(last_sent, n_ptr->bclink.last_in)) |
@@ -362,7 +364,7 @@ void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent) | |||
362 | tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, | 364 | tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, |
363 | INT_H_SIZE, n_ptr->addr); | 365 | INT_H_SIZE, n_ptr->addr); |
364 | msg_set_non_seq(msg, 1); | 366 | msg_set_non_seq(msg, 1); |
365 | msg_set_mc_netid(msg, tipc_net_id); | 367 | msg_set_mc_netid(msg, tn->net_id); |
366 | msg_set_bcast_ack(msg, n_ptr->bclink.last_in); | 368 | msg_set_bcast_ack(msg, n_ptr->bclink.last_in); |
367 | msg_set_bcgap_after(msg, n_ptr->bclink.last_in); | 369 | msg_set_bcgap_after(msg, n_ptr->bclink.last_in); |
368 | msg_set_bcgap_to(msg, to); | 370 | msg_set_bcgap_to(msg, to); |
@@ -476,8 +478,9 @@ static void bclink_accept_pkt(struct tipc_node *node, u32 seqno) | |||
476 | * | 478 | * |
477 | * RCU is locked, no other locks set | 479 | * RCU is locked, no other locks set |
478 | */ | 480 | */ |
479 | void tipc_bclink_rcv(struct sk_buff *buf) | 481 | void tipc_bclink_rcv(struct net *net, struct sk_buff *buf) |
480 | { | 482 | { |
483 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
481 | struct tipc_msg *msg = buf_msg(buf); | 484 | struct tipc_msg *msg = buf_msg(buf); |
482 | struct tipc_node *node; | 485 | struct tipc_node *node; |
483 | u32 next_in; | 486 | u32 next_in; |
@@ -485,7 +488,7 @@ void tipc_bclink_rcv(struct sk_buff *buf) | |||
485 | int deferred = 0; | 488 | int deferred = 0; |
486 | 489 | ||
487 | /* Screen out unwanted broadcast messages */ | 490 | /* Screen out unwanted broadcast messages */ |
488 | if (msg_mc_netid(msg) != tipc_net_id) | 491 | if (msg_mc_netid(msg) != tn->net_id) |
489 | goto exit; | 492 | goto exit; |
490 | 493 | ||
491 | node = tipc_node_find(msg_prevnode(msg)); | 494 | node = tipc_node_find(msg_prevnode(msg)); |
@@ -638,6 +641,8 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1, | |||
638 | { | 641 | { |
639 | int bp_index; | 642 | int bp_index; |
640 | struct tipc_msg *msg = buf_msg(buf); | 643 | struct tipc_msg *msg = buf_msg(buf); |
644 | struct net *net = sock_net(buf->sk); | ||
645 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
641 | 646 | ||
642 | /* Prepare broadcast link message for reliable transmission, | 647 | /* Prepare broadcast link message for reliable transmission, |
643 | * if first time trying to send it; | 648 | * if first time trying to send it; |
@@ -647,7 +652,7 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1, | |||
647 | if (likely(!msg_non_seq(buf_msg(buf)))) { | 652 | if (likely(!msg_non_seq(buf_msg(buf)))) { |
648 | bcbuf_set_acks(buf, bclink->bcast_nodes.count); | 653 | bcbuf_set_acks(buf, bclink->bcast_nodes.count); |
649 | msg_set_non_seq(msg, 1); | 654 | msg_set_non_seq(msg, 1); |
650 | msg_set_mc_netid(msg, tipc_net_id); | 655 | msg_set_mc_netid(msg, tn->net_id); |
651 | bcl->stats.sent_info++; | 656 | bcl->stats.sent_info++; |
652 | 657 | ||
653 | if (WARN_ON(!bclink->bcast_nodes.count)) { | 658 | if (WARN_ON(!bclink->bcast_nodes.count)) { |
diff --git a/net/tipc/bcast.h b/net/tipc/bcast.h index 644d79129fba..a5fd22438aed 100644 --- a/net/tipc/bcast.h +++ b/net/tipc/bcast.h | |||
@@ -91,10 +91,11 @@ void tipc_bclink_add_node(u32 addr); | |||
91 | void tipc_bclink_remove_node(u32 addr); | 91 | void tipc_bclink_remove_node(u32 addr); |
92 | struct tipc_node *tipc_bclink_retransmit_to(void); | 92 | struct tipc_node *tipc_bclink_retransmit_to(void); |
93 | void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked); | 93 | void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked); |
94 | void tipc_bclink_rcv(struct sk_buff *buf); | 94 | void tipc_bclink_rcv(struct net *net, struct sk_buff *buf); |
95 | u32 tipc_bclink_get_last_sent(void); | 95 | u32 tipc_bclink_get_last_sent(void); |
96 | u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr); | 96 | 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); | 97 | void tipc_bclink_update_link_state(struct net *net, struct tipc_node *n_ptr, |
98 | u32 last_sent); | ||
98 | int tipc_bclink_stats(char *stats_buf, const u32 buf_size); | 99 | int tipc_bclink_stats(char *stats_buf, const u32 buf_size); |
99 | int tipc_bclink_reset_stats(void); | 100 | int tipc_bclink_reset_stats(void); |
100 | int tipc_bclink_set_queue_limits(u32 limit); | 101 | int tipc_bclink_set_queue_limits(u32 limit); |
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 463db5b15b8b..cdd30337dc5e 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
@@ -260,7 +260,8 @@ void tipc_bearer_remove_dest(u32 bearer_id, u32 dest) | |||
260 | /** | 260 | /** |
261 | * tipc_enable_bearer - enable bearer with the given name | 261 | * tipc_enable_bearer - enable bearer with the given name |
262 | */ | 262 | */ |
263 | int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority) | 263 | int tipc_enable_bearer(struct net *net, const char *name, u32 disc_domain, |
264 | u32 priority) | ||
264 | { | 265 | { |
265 | struct tipc_bearer *b_ptr; | 266 | struct tipc_bearer *b_ptr; |
266 | struct tipc_media *m_ptr; | 267 | struct tipc_media *m_ptr; |
@@ -361,7 +362,7 @@ restart: | |||
361 | b_ptr->net_plane = bearer_id + 'A'; | 362 | b_ptr->net_plane = bearer_id + 'A'; |
362 | b_ptr->priority = priority; | 363 | b_ptr->priority = priority; |
363 | 364 | ||
364 | res = tipc_disc_create(b_ptr, &b_ptr->bcast_addr); | 365 | res = tipc_disc_create(net, b_ptr, &b_ptr->bcast_addr); |
365 | if (res) { | 366 | if (res) { |
366 | bearer_disable(b_ptr, false); | 367 | bearer_disable(b_ptr, false); |
367 | pr_warn("Bearer <%s> rejected, discovery object creation failed\n", | 368 | pr_warn("Bearer <%s> rejected, discovery object creation failed\n", |
@@ -380,11 +381,11 @@ restart: | |||
380 | /** | 381 | /** |
381 | * tipc_reset_bearer - Reset all links established over this bearer | 382 | * tipc_reset_bearer - Reset all links established over this bearer |
382 | */ | 383 | */ |
383 | static int tipc_reset_bearer(struct tipc_bearer *b_ptr) | 384 | static int tipc_reset_bearer(struct net *net, struct tipc_bearer *b_ptr) |
384 | { | 385 | { |
385 | pr_info("Resetting bearer <%s>\n", b_ptr->name); | 386 | pr_info("Resetting bearer <%s>\n", b_ptr->name); |
386 | tipc_link_reset_list(b_ptr->identity); | 387 | tipc_link_reset_list(b_ptr->identity); |
387 | tipc_disc_reset(b_ptr); | 388 | tipc_disc_reset(net, b_ptr); |
388 | return 0; | 389 | return 0; |
389 | } | 390 | } |
390 | 391 | ||
@@ -539,17 +540,12 @@ static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev, | |||
539 | { | 540 | { |
540 | struct tipc_bearer *b_ptr; | 541 | struct tipc_bearer *b_ptr; |
541 | 542 | ||
542 | if (!net_eq(dev_net(dev), &init_net)) { | ||
543 | kfree_skb(buf); | ||
544 | return NET_RX_DROP; | ||
545 | } | ||
546 | |||
547 | rcu_read_lock(); | 543 | rcu_read_lock(); |
548 | b_ptr = rcu_dereference_rtnl(dev->tipc_ptr); | 544 | b_ptr = rcu_dereference_rtnl(dev->tipc_ptr); |
549 | if (likely(b_ptr)) { | 545 | if (likely(b_ptr)) { |
550 | if (likely(buf->pkt_type <= PACKET_BROADCAST)) { | 546 | if (likely(buf->pkt_type <= PACKET_BROADCAST)) { |
551 | buf->next = NULL; | 547 | buf->next = NULL; |
552 | tipc_rcv(buf, b_ptr); | 548 | tipc_rcv(dev_net(dev), buf, b_ptr); |
553 | rcu_read_unlock(); | 549 | rcu_read_unlock(); |
554 | return NET_RX_SUCCESS; | 550 | return NET_RX_SUCCESS; |
555 | } | 551 | } |
@@ -572,11 +568,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, | 568 | static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, |
573 | void *ptr) | 569 | void *ptr) |
574 | { | 570 | { |
575 | struct tipc_bearer *b_ptr; | ||
576 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); | 571 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
577 | 572 | struct net *net = dev_net(dev); | |
578 | if (!net_eq(dev_net(dev), &init_net)) | 573 | struct tipc_bearer *b_ptr; |
579 | return NOTIFY_DONE; | ||
580 | 574 | ||
581 | b_ptr = rtnl_dereference(dev->tipc_ptr); | 575 | b_ptr = rtnl_dereference(dev->tipc_ptr); |
582 | if (!b_ptr) | 576 | if (!b_ptr) |
@@ -590,12 +584,12 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt, | |||
590 | break; | 584 | break; |
591 | case NETDEV_DOWN: | 585 | case NETDEV_DOWN: |
592 | case NETDEV_CHANGEMTU: | 586 | case NETDEV_CHANGEMTU: |
593 | tipc_reset_bearer(b_ptr); | 587 | tipc_reset_bearer(net, b_ptr); |
594 | break; | 588 | break; |
595 | case NETDEV_CHANGEADDR: | 589 | case NETDEV_CHANGEADDR: |
596 | b_ptr->media->raw2addr(b_ptr, &b_ptr->addr, | 590 | b_ptr->media->raw2addr(b_ptr, &b_ptr->addr, |
597 | (char *)dev->dev_addr); | 591 | (char *)dev->dev_addr); |
598 | tipc_reset_bearer(b_ptr); | 592 | tipc_reset_bearer(net, b_ptr); |
599 | break; | 593 | break; |
600 | case NETDEV_UNREGISTER: | 594 | case NETDEV_UNREGISTER: |
601 | case NETDEV_CHANGENAME: | 595 | case NETDEV_CHANGENAME: |
@@ -808,6 +802,7 @@ int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info) | |||
808 | 802 | ||
809 | int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) | 803 | int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) |
810 | { | 804 | { |
805 | struct net *net = genl_info_net(info); | ||
811 | int err; | 806 | int err; |
812 | char *bearer; | 807 | char *bearer; |
813 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; | 808 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; |
@@ -847,7 +842,7 @@ int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) | |||
847 | } | 842 | } |
848 | 843 | ||
849 | rtnl_lock(); | 844 | rtnl_lock(); |
850 | err = tipc_enable_bearer(bearer, domain, prio); | 845 | err = tipc_enable_bearer(net, bearer, domain, prio); |
851 | if (err) { | 846 | if (err) { |
852 | rtnl_unlock(); | 847 | rtnl_unlock(); |
853 | return err; | 848 | return err; |
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 2c1230ac5dfe..43f683aebbbe 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h | |||
@@ -165,8 +165,9 @@ extern struct tipc_bearer __rcu *bearer_list[]; | |||
165 | * TIPC routines available to supported media types | 165 | * TIPC routines available to supported media types |
166 | */ | 166 | */ |
167 | 167 | ||
168 | void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *tb_ptr); | 168 | 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); | 169 | int tipc_enable_bearer(struct net *net, const char *bearer_name, |
170 | u32 disc_domain, u32 priority); | ||
170 | int tipc_disable_bearer(const char *name); | 171 | int tipc_disable_bearer(const char *name); |
171 | 172 | ||
172 | /* | 173 | /* |
diff --git a/net/tipc/config.c b/net/tipc/config.c index 0b3a90ecab6d..28d4272803c4 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"); |
@@ -161,7 +161,7 @@ static struct sk_buff *cfg_disable_bearer(void) | |||
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 | u32 addr; | 166 | u32 addr; |
167 | 167 | ||
@@ -177,20 +177,21 @@ static struct sk_buff *cfg_set_own_addr(void) | |||
177 | if (tipc_own_addr) | 177 | if (tipc_own_addr) |
178 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 178 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
179 | " (cannot change node address once assigned)"); | 179 | " (cannot change node address once assigned)"); |
180 | if (!tipc_net_start(addr)) | 180 | if (!tipc_net_start(net, addr)) |
181 | return tipc_cfg_reply_none(); | 181 | return tipc_cfg_reply_none(); |
182 | 182 | ||
183 | return tipc_cfg_reply_error_string("cannot change to network mode"); | 183 | return tipc_cfg_reply_error_string("cannot change to network mode"); |
184 | } | 184 | } |
185 | 185 | ||
186 | static struct sk_buff *cfg_set_netid(void) | 186 | static struct sk_buff *cfg_set_netid(struct net *net) |
187 | { | 187 | { |
188 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
188 | u32 value; | 189 | u32 value; |
189 | 190 | ||
190 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 191 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
191 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 192 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
192 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 193 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
193 | if (value == tipc_net_id) | 194 | if (value == tn->net_id) |
194 | return tipc_cfg_reply_none(); | 195 | return tipc_cfg_reply_none(); |
195 | if (value < 1 || value > 9999) | 196 | if (value < 1 || value > 9999) |
196 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 197 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
@@ -198,14 +199,16 @@ static struct sk_buff *cfg_set_netid(void) | |||
198 | if (tipc_own_addr) | 199 | if (tipc_own_addr) |
199 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 200 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
200 | " (cannot change network id once TIPC has joined a network)"); | 201 | " (cannot change network id once TIPC has joined a network)"); |
201 | tipc_net_id = value; | 202 | tn->net_id = value; |
202 | return tipc_cfg_reply_none(); | 203 | return tipc_cfg_reply_none(); |
203 | } | 204 | } |
204 | 205 | ||
205 | struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area, | 206 | struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd, |
206 | int request_space, int reply_headroom) | 207 | const void *request_area, int request_space, |
208 | int reply_headroom) | ||
207 | { | 209 | { |
208 | struct sk_buff *rep_tlv_buf; | 210 | struct sk_buff *rep_tlv_buf; |
211 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
209 | 212 | ||
210 | rtnl_lock(); | 213 | rtnl_lock(); |
211 | 214 | ||
@@ -261,19 +264,19 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area | |||
261 | rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd); | 264 | rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd); |
262 | break; | 265 | break; |
263 | case TIPC_CMD_ENABLE_BEARER: | 266 | case TIPC_CMD_ENABLE_BEARER: |
264 | rep_tlv_buf = cfg_enable_bearer(); | 267 | rep_tlv_buf = cfg_enable_bearer(net); |
265 | break; | 268 | break; |
266 | case TIPC_CMD_DISABLE_BEARER: | 269 | case TIPC_CMD_DISABLE_BEARER: |
267 | rep_tlv_buf = cfg_disable_bearer(); | 270 | rep_tlv_buf = cfg_disable_bearer(); |
268 | break; | 271 | break; |
269 | case TIPC_CMD_SET_NODE_ADDR: | 272 | case TIPC_CMD_SET_NODE_ADDR: |
270 | rep_tlv_buf = cfg_set_own_addr(); | 273 | rep_tlv_buf = cfg_set_own_addr(net); |
271 | break; | 274 | break; |
272 | case TIPC_CMD_SET_NETID: | 275 | case TIPC_CMD_SET_NETID: |
273 | rep_tlv_buf = cfg_set_netid(); | 276 | rep_tlv_buf = cfg_set_netid(net); |
274 | break; | 277 | break; |
275 | case TIPC_CMD_GET_NETID: | 278 | case TIPC_CMD_GET_NETID: |
276 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id); | 279 | rep_tlv_buf = tipc_cfg_reply_unsigned(tn->net_id); |
277 | break; | 280 | break; |
278 | case TIPC_CMD_NOT_NET_ADMIN: | 281 | case TIPC_CMD_NOT_NET_ADMIN: |
279 | rep_tlv_buf = | 282 | rep_tlv_buf = |
diff --git a/net/tipc/config.h b/net/tipc/config.h index a41a41c58750..9e9b575fc429 100644 --- a/net/tipc/config.h +++ b/net/tipc/config.h | |||
@@ -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 b6ec3d7c5f51..a2302480d8cf 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c | |||
@@ -52,6 +52,26 @@ u32 tipc_own_addr __read_mostly; | |||
52 | int tipc_net_id __read_mostly; | 52 | int tipc_net_id __read_mostly; |
53 | int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */ | 53 | int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */ |
54 | 54 | ||
55 | static int __net_init tipc_init_net(struct net *net) | ||
56 | { | ||
57 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
58 | |||
59 | tn->net_id = 4711; | ||
60 | |||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | static void __net_exit tipc_exit_net(struct net *net) | ||
65 | { | ||
66 | } | ||
67 | |||
68 | static struct pernet_operations tipc_net_ops = { | ||
69 | .init = tipc_init_net, | ||
70 | .exit = tipc_exit_net, | ||
71 | .id = &tipc_net_id, | ||
72 | .size = sizeof(struct tipc_net), | ||
73 | }; | ||
74 | |||
55 | static int __init tipc_init(void) | 75 | static int __init tipc_init(void) |
56 | { | 76 | { |
57 | int err; | 77 | int err; |
@@ -59,7 +79,6 @@ static int __init tipc_init(void) | |||
59 | pr_info("Activated (version " TIPC_MOD_VER ")\n"); | 79 | pr_info("Activated (version " TIPC_MOD_VER ")\n"); |
60 | 80 | ||
61 | tipc_own_addr = 0; | 81 | tipc_own_addr = 0; |
62 | tipc_net_id = 4711; | ||
63 | 82 | ||
64 | sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 << | 83 | sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 << |
65 | TIPC_LOW_IMPORTANCE; | 84 | TIPC_LOW_IMPORTANCE; |
@@ -69,6 +88,10 @@ static int __init tipc_init(void) | |||
69 | 88 | ||
70 | get_random_bytes(&tipc_random, sizeof(tipc_random)); | 89 | get_random_bytes(&tipc_random, sizeof(tipc_random)); |
71 | 90 | ||
91 | err = register_pernet_subsys(&tipc_net_ops); | ||
92 | if (err) | ||
93 | goto out_pernet; | ||
94 | |||
72 | err = tipc_sk_rht_init(); | 95 | err = tipc_sk_rht_init(); |
73 | if (err) | 96 | if (err) |
74 | goto out_reftbl; | 97 | goto out_reftbl; |
@@ -112,12 +135,15 @@ out_netlink: | |||
112 | out_nametbl: | 135 | out_nametbl: |
113 | tipc_sk_rht_destroy(); | 136 | tipc_sk_rht_destroy(); |
114 | out_reftbl: | 137 | out_reftbl: |
138 | unregister_pernet_subsys(&tipc_net_ops); | ||
139 | out_pernet: | ||
115 | pr_err("Unable to start in single node mode\n"); | 140 | pr_err("Unable to start in single node mode\n"); |
116 | return err; | 141 | return err; |
117 | } | 142 | } |
118 | 143 | ||
119 | static void __exit tipc_exit(void) | 144 | static void __exit tipc_exit(void) |
120 | { | 145 | { |
146 | unregister_pernet_subsys(&tipc_net_ops); | ||
121 | tipc_net_stop(); | 147 | tipc_net_stop(); |
122 | tipc_bearer_cleanup(); | 148 | tipc_bearer_cleanup(); |
123 | tipc_netlink_stop(); | 149 | tipc_netlink_stop(); |
diff --git a/net/tipc/core.h b/net/tipc/core.h index a5b3140f1451..106e8150c3a6 100644 --- a/net/tipc/core.h +++ b/net/tipc/core.h | |||
@@ -57,6 +57,7 @@ | |||
57 | #include <linux/vmalloc.h> | 57 | #include <linux/vmalloc.h> |
58 | #include <linux/rtnetlink.h> | 58 | #include <linux/rtnetlink.h> |
59 | #include <linux/etherdevice.h> | 59 | #include <linux/etherdevice.h> |
60 | #include <net/netns/generic.h> | ||
60 | 61 | ||
61 | #define TIPC_MOD_VER "2.0.0" | 62 | #define TIPC_MOD_VER "2.0.0" |
62 | 63 | ||
@@ -75,6 +76,10 @@ extern int sysctl_tipc_named_timeout __read_mostly; | |||
75 | */ | 76 | */ |
76 | extern int tipc_random __read_mostly; | 77 | extern int tipc_random __read_mostly; |
77 | 78 | ||
79 | struct tipc_net { | ||
80 | int net_id; | ||
81 | }; | ||
82 | |||
78 | #ifdef CONFIG_SYSCTL | 83 | #ifdef CONFIG_SYSCTL |
79 | int tipc_register_sysctl(void); | 84 | int tipc_register_sysctl(void); |
80 | void tipc_unregister_sysctl(void); | 85 | void tipc_unregister_sysctl(void); |
diff --git a/net/tipc/discover.c b/net/tipc/discover.c index 1a3a98582034..246a23788ded 100644 --- a/net/tipc/discover.c +++ b/net/tipc/discover.c | |||
@@ -72,12 +72,14 @@ struct tipc_link_req { | |||
72 | 72 | ||
73 | /** | 73 | /** |
74 | * tipc_disc_init_msg - initialize a link setup message | 74 | * tipc_disc_init_msg - initialize a link setup message |
75 | * @net: the applicable net namespace | ||
75 | * @type: message type (request or response) | 76 | * @type: message type (request or response) |
76 | * @b_ptr: ptr to bearer issuing message | 77 | * @b_ptr: ptr to bearer issuing message |
77 | */ | 78 | */ |
78 | static void tipc_disc_init_msg(struct sk_buff *buf, u32 type, | 79 | static void tipc_disc_init_msg(struct net *net, struct sk_buff *buf, u32 type, |
79 | struct tipc_bearer *b_ptr) | 80 | struct tipc_bearer *b_ptr) |
80 | { | 81 | { |
82 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
81 | struct tipc_msg *msg; | 83 | struct tipc_msg *msg; |
82 | u32 dest_domain = b_ptr->domain; | 84 | u32 dest_domain = b_ptr->domain; |
83 | 85 | ||
@@ -86,7 +88,7 @@ static void tipc_disc_init_msg(struct sk_buff *buf, u32 type, | |||
86 | msg_set_non_seq(msg, 1); | 88 | msg_set_non_seq(msg, 1); |
87 | msg_set_node_sig(msg, tipc_random); | 89 | msg_set_node_sig(msg, tipc_random); |
88 | msg_set_dest_domain(msg, dest_domain); | 90 | msg_set_dest_domain(msg, dest_domain); |
89 | msg_set_bc_netid(msg, tipc_net_id); | 91 | msg_set_bc_netid(msg, tn->net_id); |
90 | b_ptr->media->addr2msg(msg_media_addr(msg), &b_ptr->addr); | 92 | b_ptr->media->addr2msg(msg_media_addr(msg), &b_ptr->addr); |
91 | } | 93 | } |
92 | 94 | ||
@@ -111,11 +113,14 @@ static void disc_dupl_alert(struct tipc_bearer *b_ptr, u32 node_addr, | |||
111 | 113 | ||
112 | /** | 114 | /** |
113 | * tipc_disc_rcv - handle incoming discovery message (request or response) | 115 | * tipc_disc_rcv - handle incoming discovery message (request or response) |
116 | * @net: the applicable net namespace | ||
114 | * @buf: buffer containing message | 117 | * @buf: buffer containing message |
115 | * @bearer: bearer that message arrived on | 118 | * @bearer: bearer that message arrived on |
116 | */ | 119 | */ |
117 | void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | 120 | void tipc_disc_rcv(struct net *net, struct sk_buff *buf, |
121 | struct tipc_bearer *bearer) | ||
118 | { | 122 | { |
123 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
119 | struct tipc_node *node; | 124 | struct tipc_node *node; |
120 | struct tipc_link *link; | 125 | struct tipc_link *link; |
121 | struct tipc_media_addr maddr; | 126 | struct tipc_media_addr maddr; |
@@ -137,7 +142,7 @@ void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | |||
137 | kfree_skb(buf); | 142 | kfree_skb(buf); |
138 | 143 | ||
139 | /* Ensure message from node is valid and communication is permitted */ | 144 | /* Ensure message from node is valid and communication is permitted */ |
140 | if (net_id != tipc_net_id) | 145 | if (net_id != tn->net_id) |
141 | return; | 146 | return; |
142 | if (maddr.broadcast) | 147 | if (maddr.broadcast) |
143 | return; | 148 | return; |
@@ -248,7 +253,7 @@ void tipc_disc_rcv(struct sk_buff *buf, struct tipc_bearer *bearer) | |||
248 | if (respond && (mtyp == DSC_REQ_MSG)) { | 253 | if (respond && (mtyp == DSC_REQ_MSG)) { |
249 | rbuf = tipc_buf_acquire(INT_H_SIZE); | 254 | rbuf = tipc_buf_acquire(INT_H_SIZE); |
250 | if (rbuf) { | 255 | if (rbuf) { |
251 | tipc_disc_init_msg(rbuf, DSC_RESP_MSG, bearer); | 256 | tipc_disc_init_msg(net, rbuf, DSC_RESP_MSG, bearer); |
252 | tipc_bearer_send(bearer->identity, rbuf, &maddr); | 257 | tipc_bearer_send(bearer->identity, rbuf, &maddr); |
253 | kfree_skb(rbuf); | 258 | kfree_skb(rbuf); |
254 | } | 259 | } |
@@ -341,13 +346,15 @@ exit: | |||
341 | 346 | ||
342 | /** | 347 | /** |
343 | * tipc_disc_create - create object to send periodic link setup requests | 348 | * tipc_disc_create - create object to send periodic link setup requests |
349 | * @net: the applicable net namespace | ||
344 | * @b_ptr: ptr to bearer issuing requests | 350 | * @b_ptr: ptr to bearer issuing requests |
345 | * @dest: destination address for request messages | 351 | * @dest: destination address for request messages |
346 | * @dest_domain: network domain to which links can be established | 352 | * @dest_domain: network domain to which links can be established |
347 | * | 353 | * |
348 | * Returns 0 if successful, otherwise -errno. | 354 | * Returns 0 if successful, otherwise -errno. |
349 | */ | 355 | */ |
350 | int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest) | 356 | int tipc_disc_create(struct net *net, struct tipc_bearer *b_ptr, |
357 | struct tipc_media_addr *dest) | ||
351 | { | 358 | { |
352 | struct tipc_link_req *req; | 359 | struct tipc_link_req *req; |
353 | 360 | ||
@@ -361,7 +368,7 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest) | |||
361 | return -ENOMEM; | 368 | return -ENOMEM; |
362 | } | 369 | } |
363 | 370 | ||
364 | tipc_disc_init_msg(req->buf, DSC_REQ_MSG, b_ptr); | 371 | tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b_ptr); |
365 | memcpy(&req->dest, dest, sizeof(*dest)); | 372 | memcpy(&req->dest, dest, sizeof(*dest)); |
366 | req->bearer_id = b_ptr->identity; | 373 | req->bearer_id = b_ptr->identity; |
367 | req->domain = b_ptr->domain; | 374 | req->domain = b_ptr->domain; |
@@ -388,15 +395,16 @@ void tipc_disc_delete(struct tipc_link_req *req) | |||
388 | 395 | ||
389 | /** | 396 | /** |
390 | * tipc_disc_reset - reset object to send periodic link setup requests | 397 | * tipc_disc_reset - reset object to send periodic link setup requests |
398 | * @net: the applicable net namespace | ||
391 | * @b_ptr: ptr to bearer issuing requests | 399 | * @b_ptr: ptr to bearer issuing requests |
392 | * @dest_domain: network domain to which links can be established | 400 | * @dest_domain: network domain to which links can be established |
393 | */ | 401 | */ |
394 | void tipc_disc_reset(struct tipc_bearer *b_ptr) | 402 | void tipc_disc_reset(struct net *net, struct tipc_bearer *b_ptr) |
395 | { | 403 | { |
396 | struct tipc_link_req *req = b_ptr->link_req; | 404 | struct tipc_link_req *req = b_ptr->link_req; |
397 | 405 | ||
398 | spin_lock_bh(&req->lock); | 406 | spin_lock_bh(&req->lock); |
399 | tipc_disc_init_msg(req->buf, DSC_REQ_MSG, b_ptr); | 407 | tipc_disc_init_msg(net, req->buf, DSC_REQ_MSG, b_ptr); |
400 | req->bearer_id = b_ptr->identity; | 408 | req->bearer_id = b_ptr->identity; |
401 | req->domain = b_ptr->domain; | 409 | req->domain = b_ptr->domain; |
402 | req->num_nodes = 0; | 410 | req->num_nodes = 0; |
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 f23105852cb3..248813cb6d68 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c | |||
@@ -101,10 +101,12 @@ 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 tol); | 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); |
@@ -113,7 +115,8 @@ 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 tipc_link *l, struct sk_buff *buf); |
116 | static int tipc_link_prepare_input(struct tipc_link *l, struct sk_buff **buf); | 118 | static int tipc_link_prepare_input(struct net *net, struct tipc_link *l, |
119 | struct sk_buff **buf); | ||
117 | 120 | ||
118 | /* | 121 | /* |
119 | * Simple link routines | 122 | * Simple link routines |
@@ -1063,13 +1066,14 @@ static int link_recv_buf_validate(struct sk_buff *buf) | |||
1063 | 1066 | ||
1064 | /** | 1067 | /** |
1065 | * tipc_rcv - process TIPC packets/messages arriving from off-node | 1068 | * tipc_rcv - process TIPC packets/messages arriving from off-node |
1069 | * @net: net namespace handler | ||
1066 | * @skb: TIPC packet | 1070 | * @skb: TIPC packet |
1067 | * @b_ptr: pointer to bearer message arrived on | 1071 | * @b_ptr: pointer to bearer message arrived on |
1068 | * | 1072 | * |
1069 | * Invoked with no locks held. Bearer pointer must point to a valid bearer | 1073 | * 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. | 1074 | * structure (i.e. cannot be NULL), but bearer can be inactive. |
1071 | */ | 1075 | */ |
1072 | void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *b_ptr) | 1076 | void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr) |
1073 | { | 1077 | { |
1074 | struct sk_buff_head head; | 1078 | struct sk_buff_head head; |
1075 | struct tipc_node *n_ptr; | 1079 | struct tipc_node *n_ptr; |
@@ -1096,9 +1100,9 @@ void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *b_ptr) | |||
1096 | 1100 | ||
1097 | if (unlikely(msg_non_seq(msg))) { | 1101 | if (unlikely(msg_non_seq(msg))) { |
1098 | if (msg_user(msg) == LINK_CONFIG) | 1102 | if (msg_user(msg) == LINK_CONFIG) |
1099 | tipc_disc_rcv(skb, b_ptr); | 1103 | tipc_disc_rcv(net, skb, b_ptr); |
1100 | else | 1104 | else |
1101 | tipc_bclink_rcv(skb); | 1105 | tipc_bclink_rcv(net, skb); |
1102 | continue; | 1106 | continue; |
1103 | } | 1107 | } |
1104 | 1108 | ||
@@ -1159,7 +1163,7 @@ void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *b_ptr) | |||
1159 | /* Process the incoming packet */ | 1163 | /* Process the incoming packet */ |
1160 | if (unlikely(!link_working_working(l_ptr))) { | 1164 | if (unlikely(!link_working_working(l_ptr))) { |
1161 | if (msg_user(msg) == LINK_PROTOCOL) { | 1165 | if (msg_user(msg) == LINK_PROTOCOL) { |
1162 | tipc_link_proto_rcv(l_ptr, skb); | 1166 | tipc_link_proto_rcv(net, l_ptr, skb); |
1163 | link_retrieve_defq(l_ptr, &head); | 1167 | link_retrieve_defq(l_ptr, &head); |
1164 | tipc_node_unlock(n_ptr); | 1168 | tipc_node_unlock(n_ptr); |
1165 | continue; | 1169 | continue; |
@@ -1179,7 +1183,7 @@ void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *b_ptr) | |||
1179 | 1183 | ||
1180 | /* Link is now in state WORKING_WORKING */ | 1184 | /* Link is now in state WORKING_WORKING */ |
1181 | if (unlikely(seq_no != mod(l_ptr->next_in_no))) { | 1185 | if (unlikely(seq_no != mod(l_ptr->next_in_no))) { |
1182 | link_handle_out_of_seq_msg(l_ptr, skb); | 1186 | link_handle_out_of_seq_msg(net, l_ptr, skb); |
1183 | link_retrieve_defq(l_ptr, &head); | 1187 | link_retrieve_defq(l_ptr, &head); |
1184 | tipc_node_unlock(n_ptr); | 1188 | tipc_node_unlock(n_ptr); |
1185 | continue; | 1189 | continue; |
@@ -1193,7 +1197,7 @@ 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); | 1197 | tipc_link_proto_xmit(l_ptr, STATE_MSG, 0, 0, 0, 0, 0); |
1194 | } | 1198 | } |
1195 | 1199 | ||
1196 | if (tipc_link_prepare_input(l_ptr, &skb)) { | 1200 | if (tipc_link_prepare_input(net, l_ptr, &skb)) { |
1197 | tipc_node_unlock(n_ptr); | 1201 | tipc_node_unlock(n_ptr); |
1198 | continue; | 1202 | continue; |
1199 | } | 1203 | } |
@@ -1216,7 +1220,8 @@ discard: | |||
1216 | * | 1220 | * |
1217 | * Node lock must be held | 1221 | * Node lock must be held |
1218 | */ | 1222 | */ |
1219 | static int tipc_link_prepare_input(struct tipc_link *l, struct sk_buff **buf) | 1223 | static int tipc_link_prepare_input(struct net *net, struct tipc_link *l, |
1224 | struct sk_buff **buf) | ||
1220 | { | 1225 | { |
1221 | struct tipc_node *n; | 1226 | struct tipc_node *n; |
1222 | struct tipc_msg *msg; | 1227 | struct tipc_msg *msg; |
@@ -1226,7 +1231,7 @@ static int tipc_link_prepare_input(struct tipc_link *l, struct sk_buff **buf) | |||
1226 | msg = buf_msg(*buf); | 1231 | msg = buf_msg(*buf); |
1227 | switch (msg_user(msg)) { | 1232 | switch (msg_user(msg)) { |
1228 | case CHANGEOVER_PROTOCOL: | 1233 | case CHANGEOVER_PROTOCOL: |
1229 | if (tipc_link_tunnel_rcv(n, buf)) | 1234 | if (tipc_link_tunnel_rcv(net, n, buf)) |
1230 | res = 0; | 1235 | res = 0; |
1231 | break; | 1236 | break; |
1232 | case MSG_FRAGMENTER: | 1237 | case MSG_FRAGMENTER: |
@@ -1325,13 +1330,14 @@ u32 tipc_link_defer_pkt(struct sk_buff_head *list, struct sk_buff *skb) | |||
1325 | /* | 1330 | /* |
1326 | * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet | 1331 | * link_handle_out_of_seq_msg - handle arrival of out-of-sequence packet |
1327 | */ | 1332 | */ |
1328 | static void link_handle_out_of_seq_msg(struct tipc_link *l_ptr, | 1333 | static void link_handle_out_of_seq_msg(struct net *net, |
1334 | struct tipc_link *l_ptr, | ||
1329 | struct sk_buff *buf) | 1335 | struct sk_buff *buf) |
1330 | { | 1336 | { |
1331 | u32 seq_no = buf_seqno(buf); | 1337 | u32 seq_no = buf_seqno(buf); |
1332 | 1338 | ||
1333 | if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) { | 1339 | if (likely(msg_user(buf_msg(buf)) == LINK_PROTOCOL)) { |
1334 | tipc_link_proto_rcv(l_ptr, buf); | 1340 | tipc_link_proto_rcv(net, l_ptr, buf); |
1335 | return; | 1341 | return; |
1336 | } | 1342 | } |
1337 | 1343 | ||
@@ -1455,7 +1461,8 @@ 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 | 1461 | * Note that network plane id propagates through the network, and may |
1456 | * change at any time. The node with lowest address rules | 1462 | * change at any time. The node with lowest address rules |
1457 | */ | 1463 | */ |
1458 | static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf) | 1464 | static void tipc_link_proto_rcv(struct net *net, struct tipc_link *l_ptr, |
1465 | struct sk_buff *buf) | ||
1459 | { | 1466 | { |
1460 | u32 rec_gap = 0; | 1467 | u32 rec_gap = 0; |
1461 | u32 max_pkt_info; | 1468 | u32 max_pkt_info; |
@@ -1571,7 +1578,7 @@ static void tipc_link_proto_rcv(struct tipc_link *l_ptr, struct sk_buff *buf) | |||
1571 | 1578 | ||
1572 | /* Protocol message before retransmits, reduce loss risk */ | 1579 | /* Protocol message before retransmits, reduce loss risk */ |
1573 | if (l_ptr->owner->bclink.recv_permitted) | 1580 | if (l_ptr->owner->bclink.recv_permitted) |
1574 | tipc_bclink_update_link_state(l_ptr->owner, | 1581 | tipc_bclink_update_link_state(net, l_ptr->owner, |
1575 | msg_last_bcast(msg)); | 1582 | msg_last_bcast(msg)); |
1576 | 1583 | ||
1577 | if (rec_gap || (msg_probe(msg))) { | 1584 | if (rec_gap || (msg_probe(msg))) { |
@@ -1748,7 +1755,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. | 1755 | /* tipc_link_dup_rcv(): Receive a tunnelled DUPLICATE_MSG packet. |
1749 | * Owner node is locked. | 1756 | * Owner node is locked. |
1750 | */ | 1757 | */ |
1751 | static void tipc_link_dup_rcv(struct tipc_link *l_ptr, | 1758 | static void tipc_link_dup_rcv(struct net *net, struct tipc_link *l_ptr, |
1752 | struct sk_buff *t_buf) | 1759 | struct sk_buff *t_buf) |
1753 | { | 1760 | { |
1754 | struct sk_buff *buf; | 1761 | struct sk_buff *buf; |
@@ -1763,7 +1770,7 @@ static void tipc_link_dup_rcv(struct tipc_link *l_ptr, | |||
1763 | } | 1770 | } |
1764 | 1771 | ||
1765 | /* Add buffer to deferred queue, if applicable: */ | 1772 | /* Add buffer to deferred queue, if applicable: */ |
1766 | link_handle_out_of_seq_msg(l_ptr, buf); | 1773 | link_handle_out_of_seq_msg(net, l_ptr, buf); |
1767 | } | 1774 | } |
1768 | 1775 | ||
1769 | /* tipc_link_failover_rcv(): Receive a tunnelled ORIGINAL_MSG packet | 1776 | /* tipc_link_failover_rcv(): Receive a tunnelled ORIGINAL_MSG packet |
@@ -1817,7 +1824,7 @@ exit: | |||
1817 | * returned to the active link for delivery upwards. | 1824 | * returned to the active link for delivery upwards. |
1818 | * Owner node is locked. | 1825 | * Owner node is locked. |
1819 | */ | 1826 | */ |
1820 | static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr, | 1827 | static int tipc_link_tunnel_rcv(struct net *net, struct tipc_node *n_ptr, |
1821 | struct sk_buff **buf) | 1828 | struct sk_buff **buf) |
1822 | { | 1829 | { |
1823 | struct sk_buff *t_buf = *buf; | 1830 | struct sk_buff *t_buf = *buf; |
@@ -1835,7 +1842,7 @@ static int tipc_link_tunnel_rcv(struct tipc_node *n_ptr, | |||
1835 | goto exit; | 1842 | goto exit; |
1836 | 1843 | ||
1837 | if (msg_type(t_msg) == DUPLICATE_MSG) | 1844 | if (msg_type(t_msg) == DUPLICATE_MSG) |
1838 | tipc_link_dup_rcv(l_ptr, t_buf); | 1845 | tipc_link_dup_rcv(net, l_ptr, t_buf); |
1839 | else if (msg_type(t_msg) == ORIGINAL_MSG) | 1846 | else if (msg_type(t_msg) == ORIGINAL_MSG) |
1840 | *buf = tipc_link_failover_rcv(l_ptr, t_buf); | 1847 | *buf = tipc_link_failover_rcv(l_ptr, t_buf); |
1841 | else | 1848 | else |
diff --git a/net/tipc/msg.c b/net/tipc/msg.c index 35523fb6668c..a38f6a680df1 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" |
@@ -214,6 +215,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, | |||
214 | skb = tipc_buf_acquire(msz); | 215 | skb = tipc_buf_acquire(msz); |
215 | if (unlikely(!skb)) | 216 | if (unlikely(!skb)) |
216 | return -ENOMEM; | 217 | return -ENOMEM; |
218 | skb_orphan(skb); | ||
217 | __skb_queue_tail(list, skb); | 219 | __skb_queue_tail(list, skb); |
218 | skb_copy_to_linear_data(skb, mhdr, mhsz); | 220 | skb_copy_to_linear_data(skb, mhdr, mhsz); |
219 | pktpos = skb->data + mhsz; | 221 | pktpos = skb->data + mhsz; |
@@ -234,6 +236,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, | |||
234 | skb = tipc_buf_acquire(pktmax); | 236 | skb = tipc_buf_acquire(pktmax); |
235 | if (!skb) | 237 | if (!skb) |
236 | return -ENOMEM; | 238 | return -ENOMEM; |
239 | skb_orphan(skb); | ||
237 | __skb_queue_tail(list, skb); | 240 | __skb_queue_tail(list, skb); |
238 | pktpos = skb->data; | 241 | pktpos = skb->data; |
239 | skb_copy_to_linear_data(skb, &pkthdr, INT_H_SIZE); | 242 | skb_copy_to_linear_data(skb, &pkthdr, INT_H_SIZE); |
@@ -267,6 +270,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, int offset, | |||
267 | rc = -ENOMEM; | 270 | rc = -ENOMEM; |
268 | goto error; | 271 | goto error; |
269 | } | 272 | } |
273 | skb_orphan(skb); | ||
270 | __skb_queue_tail(list, skb); | 274 | __skb_queue_tail(list, skb); |
271 | msg_set_type(&pkthdr, FRAGMENT); | 275 | msg_set_type(&pkthdr, FRAGMENT); |
272 | msg_set_size(&pkthdr, pktsz); | 276 | msg_set_size(&pkthdr, pktsz); |
diff --git a/net/tipc/net.c b/net/tipc/net.c index cf13df3cde8f..5ce9d628f2d0 100644 --- a/net/tipc/net.c +++ b/net/tipc/net.c | |||
@@ -108,8 +108,9 @@ 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. | 108 | * - A local spin_lock protecting the queue of subscriber events. |
109 | */ | 109 | */ |
110 | 110 | ||
111 | int tipc_net_start(u32 addr) | 111 | int tipc_net_start(struct net *net, u32 addr) |
112 | { | 112 | { |
113 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
113 | char addr_string[16]; | 114 | char addr_string[16]; |
114 | int res; | 115 | int res; |
115 | 116 | ||
@@ -125,7 +126,8 @@ int tipc_net_start(u32 addr) | |||
125 | 126 | ||
126 | pr_info("Started in network mode\n"); | 127 | pr_info("Started in network mode\n"); |
127 | pr_info("Own node address %s, network identity %u\n", | 128 | pr_info("Own node address %s, network identity %u\n", |
128 | tipc_addr_string_fill(addr_string, tipc_own_addr), tipc_net_id); | 129 | tipc_addr_string_fill(addr_string, tipc_own_addr), |
130 | tn->net_id); | ||
129 | return 0; | 131 | return 0; |
130 | } | 132 | } |
131 | 133 | ||
@@ -144,8 +146,9 @@ void tipc_net_stop(void) | |||
144 | pr_info("Left network mode\n"); | 146 | pr_info("Left network mode\n"); |
145 | } | 147 | } |
146 | 148 | ||
147 | static int __tipc_nl_add_net(struct tipc_nl_msg *msg) | 149 | static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg) |
148 | { | 150 | { |
151 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
149 | void *hdr; | 152 | void *hdr; |
150 | struct nlattr *attrs; | 153 | struct nlattr *attrs; |
151 | 154 | ||
@@ -158,7 +161,7 @@ static int __tipc_nl_add_net(struct tipc_nl_msg *msg) | |||
158 | if (!attrs) | 161 | if (!attrs) |
159 | goto msg_full; | 162 | goto msg_full; |
160 | 163 | ||
161 | if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tipc_net_id)) | 164 | if (nla_put_u32(msg->skb, TIPC_NLA_NET_ID, tn->net_id)) |
162 | goto attr_msg_full; | 165 | goto attr_msg_full; |
163 | 166 | ||
164 | nla_nest_end(msg->skb, attrs); | 167 | nla_nest_end(msg->skb, attrs); |
@@ -176,6 +179,7 @@ msg_full: | |||
176 | 179 | ||
177 | int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb) | 180 | int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb) |
178 | { | 181 | { |
182 | struct net *net = sock_net(skb->sk); | ||
179 | int err; | 183 | int err; |
180 | int done = cb->args[0]; | 184 | int done = cb->args[0]; |
181 | struct tipc_nl_msg msg; | 185 | struct tipc_nl_msg msg; |
@@ -187,7 +191,7 @@ int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
187 | msg.portid = NETLINK_CB(cb->skb).portid; | 191 | msg.portid = NETLINK_CB(cb->skb).portid; |
188 | msg.seq = cb->nlh->nlmsg_seq; | 192 | msg.seq = cb->nlh->nlmsg_seq; |
189 | 193 | ||
190 | err = __tipc_nl_add_net(&msg); | 194 | err = __tipc_nl_add_net(net, &msg); |
191 | if (err) | 195 | if (err) |
192 | goto out; | 196 | goto out; |
193 | 197 | ||
@@ -200,8 +204,10 @@ out: | |||
200 | 204 | ||
201 | int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) | 205 | int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) |
202 | { | 206 | { |
203 | int err; | 207 | struct net *net = genl_info_net(info); |
208 | struct tipc_net *tn = net_generic(net, tipc_net_id); | ||
204 | struct nlattr *attrs[TIPC_NLA_NET_MAX + 1]; | 209 | struct nlattr *attrs[TIPC_NLA_NET_MAX + 1]; |
210 | int err; | ||
205 | 211 | ||
206 | if (!info->attrs[TIPC_NLA_NET]) | 212 | if (!info->attrs[TIPC_NLA_NET]) |
207 | return -EINVAL; | 213 | return -EINVAL; |
@@ -223,7 +229,7 @@ int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) | |||
223 | if (val < 1 || val > 9999) | 229 | if (val < 1 || val > 9999) |
224 | return -EINVAL; | 230 | return -EINVAL; |
225 | 231 | ||
226 | tipc_net_id = val; | 232 | tn->net_id = val; |
227 | } | 233 | } |
228 | 234 | ||
229 | if (attrs[TIPC_NLA_NET_ADDR]) { | 235 | if (attrs[TIPC_NLA_NET_ADDR]) { |
@@ -238,7 +244,7 @@ int tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) | |||
238 | return -EINVAL; | 244 | return -EINVAL; |
239 | 245 | ||
240 | rtnl_lock(); | 246 | rtnl_lock(); |
241 | tipc_net_start(addr); | 247 | tipc_net_start(net, addr); |
242 | rtnl_unlock(); | 248 | rtnl_unlock(); |
243 | } | 249 | } |
244 | 250 | ||
diff --git a/net/tipc/net.h b/net/tipc/net.h index a81c1b9eb150..2c4812f8408f 100644 --- a/net/tipc/net.h +++ b/net/tipc/net.h | |||
@@ -39,7 +39,7 @@ | |||
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(void); |
45 | 45 | ||
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c index b891e3905bc4..282b59681484 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; |
@@ -58,10 +59,11 @@ static int handle_cmd(struct sk_buff *skb, struct genl_info *info) | |||
58 | else | 59 | else |
59 | cmd = req_userhdr->cmd; | 60 | cmd = req_userhdr->cmd; |
60 | 61 | ||
61 | rep_buf = tipc_cfg_do_cmd(req_userhdr->dest, cmd, | 62 | rep_buf = tipc_cfg_do_cmd(net, req_userhdr->dest, cmd, |
62 | nlmsg_data(req_nlh) + GENL_HDRLEN + TIPC_GENL_HDRLEN, | 63 | nlmsg_data(req_nlh) + GENL_HDRLEN + |
63 | nlmsg_attrlen(req_nlh, GENL_HDRLEN + TIPC_GENL_HDRLEN), | 64 | TIPC_GENL_HDRLEN, |
64 | hdr_space); | 65 | nlmsg_attrlen(req_nlh, GENL_HDRLEN + |
66 | TIPC_GENL_HDRLEN), hdr_space); | ||
65 | 67 | ||
66 | if (rep_buf) { | 68 | if (rep_buf) { |
67 | skb_push(rep_buf, hdr_space); | 69 | skb_push(rep_buf, hdr_space); |