summaryrefslogtreecommitdiffstats
path: root/net/tipc/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r--net/tipc/socket.c83
1 files changed, 1 insertions, 82 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 934947f038b6..813847d25a49 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -121,9 +121,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dsz);
121static const struct proto_ops packet_ops; 121static const struct proto_ops packet_ops;
122static const struct proto_ops stream_ops; 122static const struct proto_ops stream_ops;
123static const struct proto_ops msg_ops; 123static const struct proto_ops msg_ops;
124
125static struct proto tipc_proto; 124static struct proto tipc_proto;
126static struct proto tipc_proto_kern;
127 125
128static const struct nla_policy tipc_nl_sock_policy[TIPC_NLA_SOCK_MAX + 1] = { 126static const struct nla_policy tipc_nl_sock_policy[TIPC_NLA_SOCK_MAX + 1] = {
129 [TIPC_NLA_SOCK_UNSPEC] = { .type = NLA_UNSPEC }, 127 [TIPC_NLA_SOCK_UNSPEC] = { .type = NLA_UNSPEC },
@@ -341,11 +339,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
341 } 339 }
342 340
343 /* Allocate socket's protocol area */ 341 /* Allocate socket's protocol area */
344 if (!kern) 342 sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto);
345 sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto);
346 else
347 sk = sk_alloc(net, AF_TIPC, GFP_KERNEL, &tipc_proto_kern);
348
349 if (sk == NULL) 343 if (sk == NULL)
350 return -ENOMEM; 344 return -ENOMEM;
351 345
@@ -383,75 +377,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
383 return 0; 377 return 0;
384} 378}
385 379
386/**
387 * tipc_sock_create_local - create TIPC socket from inside TIPC module
388 * @type: socket type - SOCK_RDM or SOCK_SEQPACKET
389 *
390 * We cannot use sock_creat_kern here because it bumps module user count.
391 * Since socket owner and creator is the same module we must make sure
392 * that module count remains zero for module local sockets, otherwise
393 * we cannot do rmmod.
394 *
395 * Returns 0 on success, errno otherwise
396 */
397int tipc_sock_create_local(struct net *net, int type, struct socket **res)
398{
399 int rc;
400
401 rc = sock_create_lite(AF_TIPC, type, 0, res);
402 if (rc < 0) {
403 pr_err("Failed to create kernel socket\n");
404 return rc;
405 }
406 tipc_sk_create(net, *res, 0, 1);
407
408 return 0;
409}
410
411/**
412 * tipc_sock_release_local - release socket created by tipc_sock_create_local
413 * @sock: the socket to be released.
414 *
415 * Module reference count is not incremented when such sockets are created,
416 * so we must keep it from being decremented when they are released.
417 */
418void tipc_sock_release_local(struct socket *sock)
419{
420 tipc_release(sock);
421 sock->ops = NULL;
422 sock_release(sock);
423}
424
425/**
426 * tipc_sock_accept_local - accept a connection on a socket created
427 * with tipc_sock_create_local. Use this function to avoid that
428 * module reference count is inadvertently incremented.
429 *
430 * @sock: the accepting socket
431 * @newsock: reference to the new socket to be created
432 * @flags: socket flags
433 */
434
435int tipc_sock_accept_local(struct socket *sock, struct socket **newsock,
436 int flags)
437{
438 struct sock *sk = sock->sk;
439 int ret;
440
441 ret = sock_create_lite(sk->sk_family, sk->sk_type,
442 sk->sk_protocol, newsock);
443 if (ret < 0)
444 return ret;
445
446 ret = tipc_accept(sock, *newsock, flags);
447 if (ret < 0) {
448 sock_release(*newsock);
449 return ret;
450 }
451 (*newsock)->ops = sock->ops;
452 return ret;
453}
454
455static void tipc_sk_callback(struct rcu_head *head) 380static void tipc_sk_callback(struct rcu_head *head)
456{ 381{
457 struct tipc_sock *tsk = container_of(head, struct tipc_sock, rcu); 382 struct tipc_sock *tsk = container_of(head, struct tipc_sock, rcu);
@@ -2608,12 +2533,6 @@ static struct proto tipc_proto = {
2608 .sysctl_rmem = sysctl_tipc_rmem 2533 .sysctl_rmem = sysctl_tipc_rmem
2609}; 2534};
2610 2535
2611static struct proto tipc_proto_kern = {
2612 .name = "TIPC",
2613 .obj_size = sizeof(struct tipc_sock),
2614 .sysctl_rmem = sysctl_tipc_rmem
2615};
2616
2617/** 2536/**
2618 * tipc_socket_init - initialize TIPC socket interface 2537 * tipc_socket_init - initialize TIPC socket interface
2619 * 2538 *