Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
967a2af0
Commit
967a2af0
authored
Sep 01, 2003
by
Stephen Hemminger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NET]: Convert af_netlink.c over to seq_file.
parent
8ab34cfc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
46 deletions
+93
-46
net/netlink/af_netlink.c
net/netlink/af_netlink.c
+93
-46
No files found.
net/netlink/af_netlink.c
View file @
967a2af0
...
...
@@ -40,6 +40,7 @@
#include <linux/netdevice.h>
#include <linux/rtnetlink.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/smp_lock.h>
#include <linux/notifier.h>
#include <linux/security.h>
...
...
@@ -964,62 +965,108 @@ int netlink_post(int unit, struct sk_buff *skb)
#endif
#ifdef CONFIG_PROC_FS
static
int
netlink_read_proc
(
char
*
buffer
,
char
**
start
,
off_t
offset
,
int
length
,
int
*
eof
,
void
*
data
)
static
struct
sock
*
netlink_seq_socket_idx
(
struct
seq_file
*
seq
,
loff_t
pos
)
{
off_t
pos
=
0
;
off_t
begin
=
0
;
int
len
=
0
;
int
i
;
struct
sock
*
s
;
struct
hlist_node
*
node
;
len
+=
sprintf
(
buffer
,
"sk Eth Pid Groups "
"Rmem Wmem Dump Locks
\n
"
);
loff_t
off
=
0
;
for
(
i
=
0
;
i
<
MAX_LINKS
;
i
++
)
{
read_lock
(
&
nl_table_lock
);
sk_for_each
(
s
,
node
,
&
nl_table
[
i
])
{
struct
netlink_opt
*
nlk
=
nlk_sk
(
s
);
len
+=
sprintf
(
buffer
+
len
,
"%p %-3d %-6d %08x %-8d %-8d %p %d"
,
s
,
s
->
sk_protocol
,
nlk
->
pid
,
nlk
->
groups
,
atomic_read
(
&
s
->
sk_rmem_alloc
),
atomic_read
(
&
s
->
sk_wmem_alloc
),
nlk
->
cb
,
atomic_read
(
&
s
->
sk_refcnt
)
);
buffer
[
len
++
]
=
'\n'
;
pos
=
begin
+
len
;
if
(
pos
<
offset
)
{
len
=
0
;
begin
=
pos
;
if
(
off
==
pos
)
{
seq
->
private
=
(
void
*
)
i
;
return
s
;
}
if
(
pos
>
offset
+
length
)
{
read_unlock
(
&
nl_table_lock
);
goto
done
;
++
off
;
}
}
return
NULL
;
}
static
void
*
netlink_seq_start
(
struct
seq_file
*
seq
,
loff_t
*
pos
)
{
read_lock
(
&
nl_table_lock
);
return
*
pos
?
netlink_seq_socket_idx
(
seq
,
*
pos
-
1
)
:
(
void
*
)
1
;
}
static
void
*
netlink_seq_next
(
struct
seq_file
*
seq
,
void
*
v
,
loff_t
*
pos
)
{
struct
sock
*
s
;
++*
pos
;
if
(
v
==
(
void
*
)
1
)
return
netlink_seq_socket_idx
(
seq
,
0
);
s
=
sk_next
(
v
);
if
(
!
s
)
{
int
i
=
(
int
)
seq
->
private
;
while
(
++
i
<
MAX_LINKS
)
{
s
=
sk_head
(
&
nl_table
[
i
]);
if
(
s
)
{
seq
->
private
=
(
void
*
)
i
;
break
;
}
}
read_unlock
(
&
nl_table_lock
);
}
*
eof
=
1
;
done:
*
start
=
buffer
+
(
offset
-
begin
);
len
-=
(
offset
-
begin
);
if
(
len
>
length
)
len
=
length
;
if
(
len
<
0
)
len
=
0
;
return
len
;
return
s
;
}
static
void
netlink_seq_stop
(
struct
seq_file
*
seq
,
void
*
v
)
{
read_unlock
(
&
nl_table_lock
);
}
static
int
netlink_seq_show
(
struct
seq_file
*
seq
,
void
*
v
)
{
if
(
v
==
(
void
*
)
1
)
seq_puts
(
seq
,
"sk Eth Pid Groups "
"Rmem Wmem Dump Locks
\n
"
);
else
{
struct
sock
*
s
=
v
;
struct
netlink_opt
*
nlk
=
nlk_sk
(
s
);
seq_printf
(
seq
,
"%p %-3d %-6d %08x %-8d %-8d %p %d
\n
"
,
s
,
s
->
sk_protocol
,
nlk
->
pid
,
nlk
->
groups
,
atomic_read
(
&
s
->
sk_rmem_alloc
),
atomic_read
(
&
s
->
sk_wmem_alloc
),
nlk
->
cb
,
atomic_read
(
&
s
->
sk_refcnt
)
);
}
return
0
;
}
struct
seq_operations
netlink_seq_ops
=
{
.
start
=
netlink_seq_start
,
.
next
=
netlink_seq_next
,
.
stop
=
netlink_seq_stop
,
.
show
=
netlink_seq_show
,
};
static
int
netlink_seq_open
(
struct
inode
*
inode
,
struct
file
*
file
)
{
return
seq_open
(
file
,
&
netlink_seq_ops
);
}
static
struct
file_operations
netlink_seq_fops
=
{
.
owner
=
THIS_MODULE
,
.
open
=
netlink_seq_open
,
.
read
=
seq_read
,
.
llseek
=
seq_lseek
,
.
release
=
seq_release
,
};
#endif
int
netlink_register_notifier
(
struct
notifier_block
*
nb
)
...
...
@@ -1069,7 +1116,7 @@ static int __init netlink_proto_init(void)
}
sock_register
(
&
netlink_family_ops
);
#ifdef CONFIG_PROC_FS
create_proc_read_entry
(
"net/netlink"
,
0
,
0
,
netlink_read_proc
,
NULL
);
proc_net_fops_create
(
"netlink"
,
0
,
&
netlink_seq_fops
);
#endif
/* The netlink device handler may be needed early. */
rtnetlink_init
();
...
...
@@ -1079,7 +1126,7 @@ static int __init netlink_proto_init(void)
static
void
__exit
netlink_proto_exit
(
void
)
{
sock_unregister
(
PF_NETLINK
);
remove_proc_entry
(
"net/netlink"
,
NULL
);
proc_net_remove
(
"netlink"
);
}
core_initcall
(
netlink_proto_init
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment