1 From 75090d40ffbd9b4863238e1d62b43f8598da5e5e Mon Sep 17 00:00:00 2001
2 From: Robert Love <rlove@google.com>
3 Date: Thu, 31 Jul 2008 11:12:44 -0400
4 Subject: [PATCH 082/134] sysfs_net_ipv4: Add sysfs-based knobs for controlling TCP window size
6 Add a family of knobs to /sys/kernel/ipv4 for controlling the TCP window size:
15 This six values mirror the sysctl knobs in /proc/sys/net/ipv4/tcp_wmem and
16 /proc/sys/net/ipv4/tcp_rmem.
18 Sysfs, unlike sysctl, allows us to set and manage the files' permissions and
21 Signed-off-by: Robert Love <rlove@google.com>
23 net/ipv4/Makefile | 1 +
24 net/ipv4/sysfs_net_ipv4.c | 88 +++++++++++++++++++++++++++++++++++++++++++++
25 2 files changed, 89 insertions(+), 0 deletions(-)
26 create mode 100644 net/ipv4/sysfs_net_ipv4.c
28 --- a/net/ipv4/Makefile
29 +++ b/net/ipv4/Makefile
30 @@ -14,6 +14,7 @@ obj-y := route.o inetpeer.o protocol
33 obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
34 +obj-$(CONFIG_SYSFS) += sysfs_net_ipv4.o
35 obj-$(CONFIG_IP_FIB_HASH) += fib_hash.o
36 obj-$(CONFIG_IP_FIB_TRIE) += fib_trie.o
37 obj-$(CONFIG_PROC_FS) += proc.o
39 +++ b/net/ipv4/sysfs_net_ipv4.c
42 + * net/ipv4/sysfs_net_ipv4.c
44 + * sysfs-based networking knobs (so we can, unlike with sysctl, control perms)
46 + * Copyright (C) 2008 Google, Inc.
48 + * Robert Love <rlove@google.com>
50 + * This software is licensed under the terms of the GNU General Public
51 + * License version 2, as published by the Free Software Foundation, and
52 + * may be copied, distributed, and modified under those terms.
54 + * This program is distributed in the hope that it will be useful,
55 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
56 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57 + * GNU General Public License for more details.
60 +#include <linux/kobject.h>
61 +#include <linux/string.h>
62 +#include <linux/sysfs.h>
63 +#include <linux/init.h>
66 +#define CREATE_IPV4_FILE(_name, _var) \
67 +static ssize_t _name##_show(struct kobject *kobj, \
68 + struct kobj_attribute *attr, char *buf) \
70 + return sprintf(buf, "%d\n", _var); \
72 +static ssize_t _name##_store(struct kobject *kobj, \
73 + struct kobj_attribute *attr, \
74 + const char *buf, size_t count) \
77 + ret = sscanf(buf, "%d", &val); \
85 +static struct kobj_attribute _name##_attr = \
86 + __ATTR(_name, 0644, _name##_show, _name##_store)
88 +CREATE_IPV4_FILE(tcp_wmem_min, sysctl_tcp_wmem[0]);
89 +CREATE_IPV4_FILE(tcp_wmem_def, sysctl_tcp_wmem[1]);
90 +CREATE_IPV4_FILE(tcp_wmem_max, sysctl_tcp_wmem[2]);
92 +CREATE_IPV4_FILE(tcp_rmem_min, sysctl_tcp_rmem[0]);
93 +CREATE_IPV4_FILE(tcp_rmem_def, sysctl_tcp_rmem[1]);
94 +CREATE_IPV4_FILE(tcp_rmem_max, sysctl_tcp_rmem[2]);
96 +static struct attribute *ipv4_attrs[] = {
97 + &tcp_wmem_min_attr.attr,
98 + &tcp_wmem_def_attr.attr,
99 + &tcp_wmem_max_attr.attr,
100 + &tcp_rmem_min_attr.attr,
101 + &tcp_rmem_def_attr.attr,
102 + &tcp_rmem_max_attr.attr,
106 +static struct attribute_group ipv4_attr_group = {
107 + .attrs = ipv4_attrs,
110 +static __init int sysfs_ipv4_init(void)
112 + struct kobject *ipv4_kobject;
115 + ipv4_kobject = kobject_create_and_add("ipv4", kernel_kobj);
119 + ret = sysfs_create_group(ipv4_kobject, &ipv4_attr_group);
121 + kobject_put(ipv4_kobject);
128 +subsys_initcall(sysfs_ipv4_init);