~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/rxrpc/net_ns.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /* rxrpc network namespace handling.
  3  *
  4  * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
  5  * Written by David Howells (dhowells@redhat.com)
  6  */
  7 
  8 #include <linux/proc_fs.h>
  9 #include "ar-internal.h"
 10 
 11 unsigned int rxrpc_net_id;
 12 
 13 static void rxrpc_service_conn_reap_timeout(struct timer_list *timer)
 14 {
 15         struct rxrpc_net *rxnet =
 16                 container_of(timer, struct rxrpc_net, service_conn_reap_timer);
 17 
 18         if (rxnet->live)
 19                 rxrpc_queue_work(&rxnet->service_conn_reaper);
 20 }
 21 
 22 static void rxrpc_peer_keepalive_timeout(struct timer_list *timer)
 23 {
 24         struct rxrpc_net *rxnet =
 25                 container_of(timer, struct rxrpc_net, peer_keepalive_timer);
 26 
 27         if (rxnet->live)
 28                 rxrpc_queue_work(&rxnet->peer_keepalive_work);
 29 }
 30 
 31 /*
 32  * Initialise a per-network namespace record.
 33  */
 34 static __net_init int rxrpc_init_net(struct net *net)
 35 {
 36         struct rxrpc_net *rxnet = rxrpc_net(net);
 37         int ret, i;
 38 
 39         rxnet->live = true;
 40         get_random_bytes(&rxnet->epoch, sizeof(rxnet->epoch));
 41         rxnet->epoch |= RXRPC_RANDOM_EPOCH;
 42 
 43         INIT_LIST_HEAD(&rxnet->calls);
 44         spin_lock_init(&rxnet->call_lock);
 45         atomic_set(&rxnet->nr_calls, 1);
 46 
 47         atomic_set(&rxnet->nr_conns, 1);
 48         INIT_LIST_HEAD(&rxnet->bundle_proc_list);
 49         INIT_LIST_HEAD(&rxnet->conn_proc_list);
 50         INIT_LIST_HEAD(&rxnet->service_conns);
 51         rwlock_init(&rxnet->conn_lock);
 52         INIT_WORK(&rxnet->service_conn_reaper,
 53                   rxrpc_service_connection_reaper);
 54         timer_setup(&rxnet->service_conn_reap_timer,
 55                     rxrpc_service_conn_reap_timeout, 0);
 56 
 57         atomic_set(&rxnet->nr_client_conns, 0);
 58 
 59         INIT_HLIST_HEAD(&rxnet->local_endpoints);
 60         mutex_init(&rxnet->local_mutex);
 61 
 62         hash_init(rxnet->peer_hash);
 63         spin_lock_init(&rxnet->peer_hash_lock);
 64         for (i = 0; i < ARRAY_SIZE(rxnet->peer_keepalive); i++)
 65                 INIT_LIST_HEAD(&rxnet->peer_keepalive[i]);
 66         INIT_LIST_HEAD(&rxnet->peer_keepalive_new);
 67         timer_setup(&rxnet->peer_keepalive_timer,
 68                     rxrpc_peer_keepalive_timeout, 0);
 69         INIT_WORK(&rxnet->peer_keepalive_work, rxrpc_peer_keepalive_worker);
 70         rxnet->peer_keepalive_base = ktime_get_seconds();
 71 
 72         ret = -ENOMEM;
 73         rxnet->proc_net = proc_net_mkdir(net, "rxrpc", net->proc_net);
 74         if (!rxnet->proc_net)
 75                 goto err_proc;
 76 
 77         proc_create_net("calls", 0444, rxnet->proc_net, &rxrpc_call_seq_ops,
 78                         sizeof(struct seq_net_private));
 79         proc_create_net("conns", 0444, rxnet->proc_net,
 80                         &rxrpc_connection_seq_ops,
 81                         sizeof(struct seq_net_private));
 82         proc_create_net("bundles", 0444, rxnet->proc_net,
 83                         &rxrpc_bundle_seq_ops,
 84                         sizeof(struct seq_net_private));
 85         proc_create_net("peers", 0444, rxnet->proc_net,
 86                         &rxrpc_peer_seq_ops,
 87                         sizeof(struct seq_net_private));
 88         proc_create_net("locals", 0444, rxnet->proc_net,
 89                         &rxrpc_local_seq_ops,
 90                         sizeof(struct seq_net_private));
 91         proc_create_net_single_write("stats", S_IFREG | 0644, rxnet->proc_net,
 92                                      rxrpc_stats_show, rxrpc_stats_clear, NULL);
 93         return 0;
 94 
 95 err_proc:
 96         rxnet->live = false;
 97         return ret;
 98 }
 99 
100 /*
101  * Clean up a per-network namespace record.
102  */
103 static __net_exit void rxrpc_exit_net(struct net *net)
104 {
105         struct rxrpc_net *rxnet = rxrpc_net(net);
106 
107         rxnet->live = false;
108         del_timer_sync(&rxnet->peer_keepalive_timer);
109         cancel_work_sync(&rxnet->peer_keepalive_work);
110         /* Remove the timer again as the worker may have restarted it. */
111         del_timer_sync(&rxnet->peer_keepalive_timer);
112         rxrpc_destroy_all_calls(rxnet);
113         rxrpc_destroy_all_connections(rxnet);
114         rxrpc_destroy_all_peers(rxnet);
115         rxrpc_destroy_all_locals(rxnet);
116         proc_remove(rxnet->proc_net);
117 }
118 
119 struct pernet_operations rxrpc_net_ops = {
120         .init   = rxrpc_init_net,
121         .exit   = rxrpc_exit_net,
122         .id     = &rxrpc_net_id,
123         .size   = sizeof(struct rxrpc_net),
124 };
125 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php