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

TOMOYO Linux Cross Reference
Linux/net/phonet/sysctl.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-only
  2 /*
  3  * File: sysctl.c
  4  *
  5  * Phonet /proc/sys/net/phonet interface implementation
  6  *
  7  * Copyright (C) 2008 Nokia Corporation.
  8  *
  9  * Author: RĂ©mi Denis-Courmont
 10  */
 11 
 12 #include <linux/seqlock.h>
 13 #include <linux/sysctl.h>
 14 #include <linux/errno.h>
 15 #include <linux/init.h>
 16 
 17 #include <net/sock.h>
 18 #include <linux/phonet.h>
 19 #include <net/phonet/phonet.h>
 20 
 21 #define DYNAMIC_PORT_MIN        0x40
 22 #define DYNAMIC_PORT_MAX        0x7f
 23 
 24 static DEFINE_SEQLOCK(local_port_range_lock);
 25 static int local_port_range_min[2] = {0, 0};
 26 static int local_port_range_max[2] = {1023, 1023};
 27 static int local_port_range[2] = {DYNAMIC_PORT_MIN, DYNAMIC_PORT_MAX};
 28 static struct ctl_table_header *phonet_table_hrd;
 29 
 30 static void set_local_port_range(int range[2])
 31 {
 32         write_seqlock(&local_port_range_lock);
 33         local_port_range[0] = range[0];
 34         local_port_range[1] = range[1];
 35         write_sequnlock(&local_port_range_lock);
 36 }
 37 
 38 void phonet_get_local_port_range(int *min, int *max)
 39 {
 40         unsigned int seq;
 41 
 42         do {
 43                 seq = read_seqbegin(&local_port_range_lock);
 44                 if (min)
 45                         *min = local_port_range[0];
 46                 if (max)
 47                         *max = local_port_range[1];
 48         } while (read_seqretry(&local_port_range_lock, seq));
 49 }
 50 
 51 static int proc_local_port_range(const struct ctl_table *table, int write,
 52                                  void *buffer, size_t *lenp, loff_t *ppos)
 53 {
 54         int ret;
 55         int range[2] = {local_port_range[0], local_port_range[1]};
 56         struct ctl_table tmp = {
 57                 .data = &range,
 58                 .maxlen = sizeof(range),
 59                 .mode = table->mode,
 60                 .extra1 = &local_port_range_min,
 61                 .extra2 = &local_port_range_max,
 62         };
 63 
 64         ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
 65 
 66         if (write && ret == 0) {
 67                 if (range[1] < range[0])
 68                         ret = -EINVAL;
 69                 else
 70                         set_local_port_range(range);
 71         }
 72 
 73         return ret;
 74 }
 75 
 76 static struct ctl_table phonet_table[] = {
 77         {
 78                 .procname       = "local_port_range",
 79                 .data           = &local_port_range,
 80                 .maxlen         = sizeof(local_port_range),
 81                 .mode           = 0644,
 82                 .proc_handler   = proc_local_port_range,
 83         },
 84 };
 85 
 86 int __init phonet_sysctl_init(void)
 87 {
 88         phonet_table_hrd = register_net_sysctl(&init_net, "net/phonet", phonet_table);
 89         return phonet_table_hrd == NULL ? -ENOMEM : 0;
 90 }
 91 
 92 void phonet_sysctl_exit(void)
 93 {
 94         unregister_net_sysctl_table(phonet_table_hrd);
 95 }
 96 

~ [ 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