@@ -46,6 +46,9 @@ static int seq_open_net(struct inode *inode, struct file *file)
46
46
47
47
WARN_ON_ONCE (state_size < sizeof (* p ));
48
48
49
+ if (file -> f_mode & FMODE_WRITE && !PDE (inode )-> write )
50
+ return - EACCES ;
51
+
49
52
net = get_proc_net (inode );
50
53
if (!net )
51
54
return - ENXIO ;
@@ -73,6 +76,7 @@ static int seq_release_net(struct inode *ino, struct file *f)
73
76
static const struct file_operations proc_net_seq_fops = {
74
77
.open = seq_open_net ,
75
78
.read = seq_read ,
79
+ .write = proc_simple_write ,
76
80
.llseek = seq_lseek ,
77
81
.release = seq_release_net ,
78
82
};
@@ -93,6 +97,50 @@ struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
93
97
}
94
98
EXPORT_SYMBOL_GPL (proc_create_net_data );
95
99
100
+ /**
101
+ * proc_create_net_data_write - Create a writable net_ns-specific proc file
102
+ * @name: The name of the file.
103
+ * @mode: The file's access mode.
104
+ * @parent: The parent directory in which to create.
105
+ * @ops: The seq_file ops with which to read the file.
106
+ * @write: The write method which which to 'modify' the file.
107
+ * @data: Data for retrieval by PDE_DATA().
108
+ *
109
+ * Create a network namespaced proc file in the @parent directory with the
110
+ * specified @name and @mode that allows reading of a file that displays a
111
+ * series of elements and also provides for the file accepting writes that have
112
+ * some arbitrary effect.
113
+ *
114
+ * The functions in the @ops table are used to iterate over items to be
115
+ * presented and extract the readable content using the seq_file interface.
116
+ *
117
+ * The @write function is called with the data copied into a kernel space
118
+ * scratch buffer and has a NUL appended for convenience. The buffer may be
119
+ * modified by the @write function. @write should return 0 on success.
120
+ *
121
+ * The @data value is accessible from the @show and @write functions by calling
122
+ * PDE_DATA() on the file inode. The network namespace must be accessed by
123
+ * calling seq_file_net() on the seq_file struct.
124
+ */
125
+ struct proc_dir_entry * proc_create_net_data_write (const char * name , umode_t mode ,
126
+ struct proc_dir_entry * parent ,
127
+ const struct seq_operations * ops ,
128
+ proc_write_t write ,
129
+ unsigned int state_size , void * data )
130
+ {
131
+ struct proc_dir_entry * p ;
132
+
133
+ p = proc_create_reg (name , mode , & parent , data );
134
+ if (!p )
135
+ return NULL ;
136
+ p -> proc_fops = & proc_net_seq_fops ;
137
+ p -> seq_ops = ops ;
138
+ p -> state_size = state_size ;
139
+ p -> write = write ;
140
+ return proc_register (parent , p );
141
+ }
142
+ EXPORT_SYMBOL_GPL (proc_create_net_data_write );
143
+
96
144
static int single_open_net (struct inode * inode , struct file * file )
97
145
{
98
146
struct proc_dir_entry * de = PDE (inode );
@@ -119,6 +167,7 @@ static int single_release_net(struct inode *ino, struct file *f)
119
167
static const struct file_operations proc_net_single_fops = {
120
168
.open = single_open_net ,
121
169
.read = seq_read ,
170
+ .write = proc_simple_write ,
122
171
.llseek = seq_lseek ,
123
172
.release = single_release_net ,
124
173
};
@@ -138,6 +187,49 @@ struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
138
187
}
139
188
EXPORT_SYMBOL_GPL (proc_create_net_single );
140
189
190
+ /**
191
+ * proc_create_net_single_write - Create a writable net_ns-specific proc file
192
+ * @name: The name of the file.
193
+ * @mode: The file's access mode.
194
+ * @parent: The parent directory in which to create.
195
+ * @show: The seqfile show method with which to read the file.
196
+ * @write: The write method which which to 'modify' the file.
197
+ * @data: Data for retrieval by PDE_DATA().
198
+ *
199
+ * Create a network-namespaced proc file in the @parent directory with the
200
+ * specified @name and @mode that allows reading of a file that displays a
201
+ * single element rather than a series and also provides for the file accepting
202
+ * writes that have some arbitrary effect.
203
+ *
204
+ * The @show function is called to extract the readable content via the
205
+ * seq_file interface.
206
+ *
207
+ * The @write function is called with the data copied into a kernel space
208
+ * scratch buffer and has a NUL appended for convenience. The buffer may be
209
+ * modified by the @write function. @write should return 0 on success.
210
+ *
211
+ * The @data value is accessible from the @show and @write functions by calling
212
+ * PDE_DATA() on the file inode. The network namespace must be accessed by
213
+ * calling seq_file_single_net() on the seq_file struct.
214
+ */
215
+ struct proc_dir_entry * proc_create_net_single_write (const char * name , umode_t mode ,
216
+ struct proc_dir_entry * parent ,
217
+ int (* show )(struct seq_file * , void * ),
218
+ proc_write_t write ,
219
+ void * data )
220
+ {
221
+ struct proc_dir_entry * p ;
222
+
223
+ p = proc_create_reg (name , mode , & parent , data );
224
+ if (!p )
225
+ return NULL ;
226
+ p -> proc_fops = & proc_net_single_fops ;
227
+ p -> single_show = show ;
228
+ p -> write = write ;
229
+ return proc_register (parent , p );
230
+ }
231
+ EXPORT_SYMBOL_GPL (proc_create_net_single_write );
232
+
141
233
static struct net * get_proc_task_net (struct inode * dir )
142
234
{
143
235
struct task_struct * task ;
0 commit comments