aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArjan van de Ven <arjan@linux.intel.com>2011-10-30 02:46:30 -0400
committerDavid S. Miller <davem@davemloft.net>2011-11-01 17:56:14 -0400
commit73cb88ecb950ee67906d02354f781ea293bcf895 (patch)
treefbb4a777410d5a5653537bcd3ee7e954bc9ba5a0
parent98f41f694f46085fda475cdee8cc0b6d2c5e6f1f (diff)
net: make the tcp and udp file_operations for the /proc stuff const
the tcp and udp code creates a set of struct file_operations at runtime while it can also be done at compile time, with the added benefit of then having these file operations be const. the trickiest part was to get the "THIS_MODULE" reference right; the naive method of declaring a struct in the place of registration would not work for this reason. Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/tcp.h10
-rw-r--r--include/net/udp.h12
-rw-r--r--net/ipv4/tcp_ipv4.c22
-rw-r--r--net/ipv4/udp.c22
-rw-r--r--net/ipv4/udplite.c13
-rw-r--r--net/ipv6/tcp_ipv6.c12
-rw-r--r--net/ipv6/udp.c12
-rw-r--r--net/ipv6/udplite.c13
8 files changed, 75 insertions, 41 deletions
diff --git a/include/net/tcp.h b/include/net/tcp.h
index e147f42d643d..bb18c4d69aba 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1403,11 +1403,13 @@ enum tcp_seq_states {
1403 TCP_SEQ_STATE_TIME_WAIT, 1403 TCP_SEQ_STATE_TIME_WAIT,
1404}; 1404};
1405 1405
1406int tcp_seq_open(struct inode *inode, struct file *file);
1407
1406struct tcp_seq_afinfo { 1408struct tcp_seq_afinfo {
1407 char *name; 1409 char *name;
1408 sa_family_t family; 1410 sa_family_t family;
1409 struct file_operations seq_fops; 1411 const struct file_operations *seq_fops;
1410 struct seq_operations seq_ops; 1412 struct seq_operations seq_ops;
1411}; 1413};
1412 1414
1413struct tcp_iter_state { 1415struct tcp_iter_state {
diff --git a/include/net/udp.h b/include/net/udp.h
index 67ea6fcb3ec0..3b285f402f48 100644
--- a/include/net/udp.h
+++ b/include/net/udp.h
@@ -230,12 +230,14 @@ extern struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *sadd
230#endif 230#endif
231 231
232/* /proc */ 232/* /proc */
233int udp_seq_open(struct inode *inode, struct file *file);
234
233struct udp_seq_afinfo { 235struct udp_seq_afinfo {
234 char *name; 236 char *name;
235 sa_family_t family; 237 sa_family_t family;
236 struct udp_table *udp_table; 238 struct udp_table *udp_table;
237 struct file_operations seq_fops; 239 const struct file_operations *seq_fops;
238 struct seq_operations seq_ops; 240 struct seq_operations seq_ops;
239}; 241};
240 242
241struct udp_iter_state { 243struct udp_iter_state {
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 0ea10eefa60f..939c55eceb5b 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2339,7 +2339,7 @@ static void tcp_seq_stop(struct seq_file *seq, void *v)
2339 } 2339 }
2340} 2340}
2341 2341
2342static int tcp_seq_open(struct inode *inode, struct file *file) 2342int tcp_seq_open(struct inode *inode, struct file *file)
2343{ 2343{
2344 struct tcp_seq_afinfo *afinfo = PDE(inode)->data; 2344 struct tcp_seq_afinfo *afinfo = PDE(inode)->data;
2345 struct tcp_iter_state *s; 2345 struct tcp_iter_state *s;
@@ -2355,23 +2355,19 @@ static int tcp_seq_open(struct inode *inode, struct file *file)
2355 s->last_pos = 0; 2355 s->last_pos = 0;
2356 return 0; 2356 return 0;
2357} 2357}
2358EXPORT_SYMBOL(tcp_seq_open);
2358 2359
2359int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo) 2360int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo)
2360{ 2361{
2361 int rc = 0; 2362 int rc = 0;
2362 struct proc_dir_entry *p; 2363 struct proc_dir_entry *p;
2363 2364
2364 afinfo->seq_fops.open = tcp_seq_open;
2365 afinfo->seq_fops.read = seq_read;
2366 afinfo->seq_fops.llseek = seq_lseek;
2367 afinfo->seq_fops.release = seq_release_net;
2368
2369 afinfo->seq_ops.start = tcp_seq_start; 2365 afinfo->seq_ops.start = tcp_seq_start;
2370 afinfo->seq_ops.next = tcp_seq_next; 2366 afinfo->seq_ops.next = tcp_seq_next;
2371 afinfo->seq_ops.stop = tcp_seq_stop; 2367 afinfo->seq_ops.stop = tcp_seq_stop;
2372 2368
2373 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net, 2369 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
2374 &afinfo->seq_fops, afinfo); 2370 afinfo->seq_fops, afinfo);
2375 if (!p) 2371 if (!p)
2376 rc = -ENOMEM; 2372 rc = -ENOMEM;
2377 return rc; 2373 return rc;
@@ -2520,12 +2516,18 @@ out:
2520 return 0; 2516 return 0;
2521} 2517}
2522 2518
2519static const struct file_operations tcp_afinfo_seq_fops = {
2520 .owner = THIS_MODULE,
2521 .open = tcp_seq_open,
2522 .read = seq_read,
2523 .llseek = seq_lseek,
2524 .release = seq_release_net
2525};
2526
2523static struct tcp_seq_afinfo tcp4_seq_afinfo = { 2527static struct tcp_seq_afinfo tcp4_seq_afinfo = {
2524 .name = "tcp", 2528 .name = "tcp",
2525 .family = AF_INET, 2529 .family = AF_INET,
2526 .seq_fops = { 2530 .seq_fops = &tcp_afinfo_seq_fops,
2527 .owner = THIS_MODULE,
2528 },
2529 .seq_ops = { 2531 .seq_ops = {
2530 .show = tcp4_seq_show, 2532 .show = tcp4_seq_show,
2531 }, 2533 },
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index ebaa96bd3464..131d8a720086 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2037,7 +2037,7 @@ static void udp_seq_stop(struct seq_file *seq, void *v)
2037 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock); 2037 spin_unlock_bh(&state->udp_table->hash[state->bucket].lock);
2038} 2038}
2039 2039
2040static int udp_seq_open(struct inode *inode, struct file *file) 2040int udp_seq_open(struct inode *inode, struct file *file)
2041{ 2041{
2042 struct udp_seq_afinfo *afinfo = PDE(inode)->data; 2042 struct udp_seq_afinfo *afinfo = PDE(inode)->data;
2043 struct udp_iter_state *s; 2043 struct udp_iter_state *s;
@@ -2053,6 +2053,7 @@ static int udp_seq_open(struct inode *inode, struct file *file)
2053 s->udp_table = afinfo->udp_table; 2053 s->udp_table = afinfo->udp_table;
2054 return err; 2054 return err;
2055} 2055}
2056EXPORT_SYMBOL(udp_seq_open);
2056 2057
2057/* ------------------------------------------------------------------------ */ 2058/* ------------------------------------------------------------------------ */
2058int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo) 2059int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)
@@ -2060,17 +2061,12 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)
2060 struct proc_dir_entry *p; 2061 struct proc_dir_entry *p;
2061 int rc = 0; 2062 int rc = 0;
2062 2063
2063 afinfo->seq_fops.open = udp_seq_open;
2064 afinfo->seq_fops.read = seq_read;
2065 afinfo->seq_fops.llseek = seq_lseek;
2066 afinfo->seq_fops.release = seq_release_net;
2067
2068 afinfo->seq_ops.start = udp_seq_start; 2064 afinfo->seq_ops.start = udp_seq_start;
2069 afinfo->seq_ops.next = udp_seq_next; 2065 afinfo->seq_ops.next = udp_seq_next;
2070 afinfo->seq_ops.stop = udp_seq_stop; 2066 afinfo->seq_ops.stop = udp_seq_stop;
2071 2067
2072 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net, 2068 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
2073 &afinfo->seq_fops, afinfo); 2069 afinfo->seq_fops, afinfo);
2074 if (!p) 2070 if (!p)
2075 rc = -ENOMEM; 2071 rc = -ENOMEM;
2076 return rc; 2072 return rc;
@@ -2120,14 +2116,20 @@ int udp4_seq_show(struct seq_file *seq, void *v)
2120 return 0; 2116 return 0;
2121} 2117}
2122 2118
2119static const struct file_operations udp_afinfo_seq_fops = {
2120 .owner = THIS_MODULE,
2121 .open = udp_seq_open,
2122 .read = seq_read,
2123 .llseek = seq_lseek,
2124 .release = seq_release_net
2125};
2126
2123/* ------------------------------------------------------------------------ */ 2127/* ------------------------------------------------------------------------ */
2124static struct udp_seq_afinfo udp4_seq_afinfo = { 2128static struct udp_seq_afinfo udp4_seq_afinfo = {
2125 .name = "udp", 2129 .name = "udp",
2126 .family = AF_INET, 2130 .family = AF_INET,
2127 .udp_table = &udp_table, 2131 .udp_table = &udp_table,
2128 .seq_fops = { 2132 .seq_fops = &udp_afinfo_seq_fops,
2129 .owner = THIS_MODULE,
2130 },
2131 .seq_ops = { 2133 .seq_ops = {
2132 .show = udp4_seq_show, 2134 .show = udp4_seq_show,
2133 }, 2135 },
diff --git a/net/ipv4/udplite.c b/net/ipv4/udplite.c
index aee9963f7f5a..08383eb54208 100644
--- a/net/ipv4/udplite.c
+++ b/net/ipv4/udplite.c
@@ -71,13 +71,20 @@ static struct inet_protosw udplite4_protosw = {
71}; 71};
72 72
73#ifdef CONFIG_PROC_FS 73#ifdef CONFIG_PROC_FS
74
75static const struct file_operations udplite_afinfo_seq_fops = {
76 .owner = THIS_MODULE,
77 .open = udp_seq_open,
78 .read = seq_read,
79 .llseek = seq_lseek,
80 .release = seq_release_net
81};
82
74static struct udp_seq_afinfo udplite4_seq_afinfo = { 83static struct udp_seq_afinfo udplite4_seq_afinfo = {
75 .name = "udplite", 84 .name = "udplite",
76 .family = AF_INET, 85 .family = AF_INET,
77 .udp_table = &udplite_table, 86 .udp_table = &udplite_table,
78 .seq_fops = { 87 .seq_fops = &udplite_afinfo_seq_fops,
79 .owner = THIS_MODULE,
80 },
81 .seq_ops = { 88 .seq_ops = {
82 .show = udp4_seq_show, 89 .show = udp4_seq_show,
83 }, 90 },
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 10b2b3165a1a..36131d122a6f 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -2161,12 +2161,18 @@ out:
2161 return 0; 2161 return 0;
2162} 2162}
2163 2163
2164static const struct file_operations tcp6_afinfo_seq_fops = {
2165 .owner = THIS_MODULE,
2166 .open = tcp_seq_open,
2167 .read = seq_read,
2168 .llseek = seq_lseek,
2169 .release = seq_release_net
2170};
2171
2164static struct tcp_seq_afinfo tcp6_seq_afinfo = { 2172static struct tcp_seq_afinfo tcp6_seq_afinfo = {
2165 .name = "tcp6", 2173 .name = "tcp6",
2166 .family = AF_INET6, 2174 .family = AF_INET6,
2167 .seq_fops = { 2175 .seq_fops = &tcp6_afinfo_seq_fops,
2168 .owner = THIS_MODULE,
2169 },
2170 .seq_ops = { 2176 .seq_ops = {
2171 .show = tcp6_seq_show, 2177 .show = tcp6_seq_show,
2172 }, 2178 },
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index f4ca0a5b3457..846f4757eb8d 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -1424,13 +1424,19 @@ int udp6_seq_show(struct seq_file *seq, void *v)
1424 return 0; 1424 return 0;
1425} 1425}
1426 1426
1427static const struct file_operations udp6_afinfo_seq_fops = {
1428 .owner = THIS_MODULE,
1429 .open = udp_seq_open,
1430 .read = seq_read,
1431 .llseek = seq_lseek,
1432 .release = seq_release_net
1433};
1434
1427static struct udp_seq_afinfo udp6_seq_afinfo = { 1435static struct udp_seq_afinfo udp6_seq_afinfo = {
1428 .name = "udp6", 1436 .name = "udp6",
1429 .family = AF_INET6, 1437 .family = AF_INET6,
1430 .udp_table = &udp_table, 1438 .udp_table = &udp_table,
1431 .seq_fops = { 1439 .seq_fops = &udp6_afinfo_seq_fops,
1432 .owner = THIS_MODULE,
1433 },
1434 .seq_ops = { 1440 .seq_ops = {
1435 .show = udp6_seq_show, 1441 .show = udp6_seq_show,
1436 }, 1442 },
diff --git a/net/ipv6/udplite.c b/net/ipv6/udplite.c
index 986c4de5292e..8889aa22ed47 100644
--- a/net/ipv6/udplite.c
+++ b/net/ipv6/udplite.c
@@ -93,13 +93,20 @@ void udplitev6_exit(void)
93} 93}
94 94
95#ifdef CONFIG_PROC_FS 95#ifdef CONFIG_PROC_FS
96
97static const struct file_operations udplite6_afinfo_seq_fops = {
98 .owner = THIS_MODULE,
99 .open = udp_seq_open,
100 .read = seq_read,
101 .llseek = seq_lseek,
102 .release = seq_release_net
103};
104
96static struct udp_seq_afinfo udplite6_seq_afinfo = { 105static struct udp_seq_afinfo udplite6_seq_afinfo = {
97 .name = "udplite6", 106 .name = "udplite6",
98 .family = AF_INET6, 107 .family = AF_INET6,
99 .udp_table = &udplite_table, 108 .udp_table = &udplite_table,
100 .seq_fops = { 109 .seq_fops = &udplite6_afinfo_seq_fops,
101 .owner = THIS_MODULE,
102 },
103 .seq_ops = { 110 .seq_ops = {
104 .show = udp6_seq_show, 111 .show = udp6_seq_show,
105 }, 112 },