Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ying Xue and committed by
David S. Miller
c93d3baa 54fef04a

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