blob: 5ea18a16291ab8832a561e718ffac6733db7b15d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Denis V. Lunevc0f39322008-04-02 00:10:28 -07002#ifndef __SEQ_FILE_NET_H__
3#define __SEQ_FILE_NET_H__
4
5#include <linux/seq_file.h>
6
7struct net;
8extern struct net init_net;
9
10struct seq_net_private {
11#ifdef CONFIG_NET_NS
12 struct net *net;
13#endif
14};
15
Pavel Emelyanovde05c552008-07-18 04:07:21 -070016int single_open_net(struct inode *, struct file *file,
17 int (*show)(struct seq_file *, void *));
Pavel Emelyanovb6fcbdb2008-07-18 04:07:44 -070018int single_release_net(struct inode *, struct file *);
Denis V. Lunevc0f39322008-04-02 00:10:28 -070019static inline struct net *seq_file_net(struct seq_file *seq)
20{
21#ifdef CONFIG_NET_NS
22 return ((struct seq_net_private *)seq->private)->net;
23#else
24 return &init_net;
25#endif
26}
27
Christoph Hellwiga2dcdee2018-04-11 12:32:45 +020028/*
29 * This one is needed for single_open_net since net is stored directly in
30 * private not as a struct i.e. seq_file_net can't be used.
31 */
32static inline struct net *seq_file_single_net(struct seq_file *seq)
33{
34#ifdef CONFIG_NET_NS
35 return (struct net *)seq->private;
36#else
37 return &init_net;
38#endif
39}
40
Denis V. Lunevc0f39322008-04-02 00:10:28 -070041#endif