Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Denis V. Lunev | c0f3932 | 2008-04-02 00:10:28 -0700 | [diff] [blame] | 2 | #ifndef __SEQ_FILE_NET_H__ |
| 3 | #define __SEQ_FILE_NET_H__ |
| 4 | |
| 5 | #include <linux/seq_file.h> |
| 6 | |
| 7 | struct net; |
| 8 | extern struct net init_net; |
| 9 | |
| 10 | struct seq_net_private { |
| 11 | #ifdef CONFIG_NET_NS |
| 12 | struct net *net; |
| 13 | #endif |
| 14 | }; |
| 15 | |
Pavel Emelyanov | de05c55 | 2008-07-18 04:07:21 -0700 | [diff] [blame] | 16 | int single_open_net(struct inode *, struct file *file, |
| 17 | int (*show)(struct seq_file *, void *)); |
Pavel Emelyanov | b6fcbdb | 2008-07-18 04:07:44 -0700 | [diff] [blame] | 18 | int single_release_net(struct inode *, struct file *); |
Denis V. Lunev | c0f3932 | 2008-04-02 00:10:28 -0700 | [diff] [blame] | 19 | static 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 Hellwig | a2dcdee | 2018-04-11 12:32:45 +0200 | [diff] [blame] | 28 | /* |
| 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 | */ |
| 32 | static 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. Lunev | c0f3932 | 2008-04-02 00:10:28 -0700 | [diff] [blame] | 41 | #endif |