ipv4: fix checkpatch errors
[deliverable/linux.git] / net / phonet / sysctl.c
CommitLineData
87ab4e20
RDC
1/*
2 * File: sysctl.c
3 *
4 * Phonet /proc/sys/net/phonet interface implementation
5 *
6 * Copyright (C) 2008 Nokia Corporation.
7 *
8 * Contact: Remi Denis-Courmont <remi.denis-courmont@nokia.com>
9 *
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.
13 *
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.
18 *
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
22 * 02110-1301 USA
23 */
24
25#include <linux/seqlock.h>
26#include <linux/sysctl.h>
27#include <linux/errno.h>
28#include <linux/init.h>
29
8e052e52
RDC
30#include <net/sock.h>
31#include <linux/phonet.h>
32#include <net/phonet/phonet.h>
33
87ab4e20
RDC
34#define DYNAMIC_PORT_MIN 0x40
35#define DYNAMIC_PORT_MAX 0x7f
36
37static DEFINE_SEQLOCK(local_port_range_lock);
38static int local_port_range_min[2] = {0, 0};
39static int local_port_range_max[2] = {1023, 1023};
40static int local_port_range[2] = {DYNAMIC_PORT_MIN, DYNAMIC_PORT_MAX};
41static struct ctl_table_header *phonet_table_hrd;
42
43static void set_local_port_range(int range[2])
44{
45 write_seqlock(&local_port_range_lock);
46 local_port_range[0] = range[0];
47 local_port_range[1] = range[1];
48 write_sequnlock(&local_port_range_lock);
49}
50
51void phonet_get_local_port_range(int *min, int *max)
52{
53 unsigned seq;
54 do {
55 seq = read_seqbegin(&local_port_range_lock);
56 if (min)
57 *min = local_port_range[0];
58 if (max)
59 *max = local_port_range[1];
60 } while (read_seqretry(&local_port_range_lock, seq));
61}
62
8d65af78 63static int proc_local_port_range(ctl_table *table, int write,
87ab4e20
RDC
64 void __user *buffer,
65 size_t *lenp, loff_t *ppos)
66{
67 int ret;
68 int range[2] = {local_port_range[0], local_port_range[1]};
69 ctl_table tmp = {
70 .data = &range,
71 .maxlen = sizeof(range),
72 .mode = table->mode,
73 .extra1 = &local_port_range_min,
74 .extra2 = &local_port_range_max,
75 };
76
8d65af78 77 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
87ab4e20
RDC
78
79 if (write && ret == 0) {
80 if (range[1] < range[0])
81 ret = -EINVAL;
82 else
83 set_local_port_range(range);
84 }
85
86 return ret;
87}
88
89static struct ctl_table phonet_table[] = {
90 {
87ab4e20
RDC
91 .procname = "local_port_range",
92 .data = &local_port_range,
93 .maxlen = sizeof(local_port_range),
94 .mode = 0644,
6d9f239a 95 .proc_handler = proc_local_port_range,
87ab4e20 96 },
f8572d8f 97 { }
87ab4e20
RDC
98};
99
5eaa65b2 100static struct ctl_path phonet_ctl_path[] = {
f8572d8f
EB
101 { .procname = "net", },
102 { .procname = "phonet", },
87ab4e20
RDC
103 { },
104};
105
106int __init phonet_sysctl_init(void)
107{
108 phonet_table_hrd = register_sysctl_paths(phonet_ctl_path, phonet_table);
109 return phonet_table_hrd == NULL ? -ENOMEM : 0;
110}
111
112void phonet_sysctl_exit(void)
113{
114 unregister_sysctl_table(phonet_table_hrd);
115}
This page took 0.244796 seconds and 5 git commands to generate.