4 * Phonet /proc/sys/net/phonet interface implementation
6 * Copyright (C) 2008 Nokia Corporation.
8 * Contact: Remi Denis-Courmont <remi.denis-courmont@nokia.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 #include <linux/seqlock.h>
26 #include <linux/sysctl.h>
27 #include <linux/errno.h>
28 #include <linux/init.h>
30 #define DYNAMIC_PORT_MIN 0x40
31 #define DYNAMIC_PORT_MAX 0x7f
33 static DEFINE_SEQLOCK(local_port_range_lock);
34 static int local_port_range_min[2] = {0, 0};
35 static int local_port_range_max[2] = {1023, 1023};
36 static int local_port_range[2] = {DYNAMIC_PORT_MIN, DYNAMIC_PORT_MAX};
37 static struct ctl_table_header *phonet_table_hrd;
39 static void set_local_port_range(int range[2])
41 write_seqlock(&local_port_range_lock);
42 local_port_range[0] = range[0];
43 local_port_range[1] = range[1];
44 write_sequnlock(&local_port_range_lock);
47 void phonet_get_local_port_range(int *min, int *max)
51 seq = read_seqbegin(&local_port_range_lock);
53 *min = local_port_range[0];
55 *max = local_port_range[1];
56 } while (read_seqretry(&local_port_range_lock, seq));
59 static int proc_local_port_range(ctl_table *table, int write, struct file *filp,
61 size_t *lenp, loff_t *ppos)
64 int range[2] = {local_port_range[0], local_port_range[1]};
67 .maxlen = sizeof(range),
69 .extra1 = &local_port_range_min,
70 .extra2 = &local_port_range_max,
73 ret = proc_dointvec_minmax(&tmp, write, filp, buffer, lenp, ppos);
75 if (write && ret == 0) {
76 if (range[1] < range[0])
79 set_local_port_range(range);
85 static struct ctl_table phonet_table[] = {
87 .ctl_name = CTL_UNNUMBERED,
88 .procname = "local_port_range",
89 .data = &local_port_range,
90 .maxlen = sizeof(local_port_range),
92 .proc_handler = proc_local_port_range,
98 static struct ctl_path phonet_ctl_path[] = {
99 { .procname = "net", .ctl_name = CTL_NET, },
100 { .procname = "phonet", .ctl_name = CTL_UNNUMBERED, },
104 int __init phonet_sysctl_init(void)
106 phonet_table_hrd = register_sysctl_paths(phonet_ctl_path, phonet_table);
107 return phonet_table_hrd == NULL ? -ENOMEM : 0;
110 void phonet_sysctl_exit(void)
112 unregister_sysctl_table(phonet_table_hrd);