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
nexedi
linux
Commits
f205f6ff
Commit
f205f6ff
authored
Jan 04, 2004
by
Stephen Hemminger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AF_PACKET]: Convert to seq_file.
parent
951fc9df
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
45 deletions
+70
-45
net/packet/af_packet.c
net/packet/af_packet.c
+70
-45
No files found.
net/packet/af_packet.c
View file @
f205f6ff
...
...
@@ -64,6 +64,7 @@
#include <asm/uaccess.h>
#include <asm/ioctls.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/poll.h>
#include <linux/module.h>
#include <linux/init.h>
...
...
@@ -1767,61 +1768,86 @@ static struct notifier_block packet_netdev_notifier = {
};
#ifdef CONFIG_PROC_FS
static
int
packet_read_proc
(
char
*
buffer
,
char
**
start
,
off_t
offset
,
int
length
,
int
*
eof
,
void
*
data
)
static
inline
struct
sock
*
packet_seq_idx
(
loff_t
off
)
{
off_t
pos
=
0
;
off_t
begin
=
0
;
int
len
=
0
;
struct
sock
*
s
;
struct
hlist_node
*
node
;
len
+=
sprintf
(
buffer
,
"sk RefCnt Type Proto Iface R Rmem User Inode
\n
"
);
sk_for_each
(
s
,
node
,
&
packet_sklist
)
{
if
(
!
off
--
)
return
s
;
}
return
NULL
;
}
static
void
*
packet_seq_start
(
struct
seq_file
*
seq
,
loff_t
*
pos
)
{
read_lock
(
&
packet_sklist_lock
);
return
*
pos
?
packet_seq_idx
(
*
pos
-
1
)
:
SEQ_START_TOKEN
;
}
sk_for_each
(
s
,
node
,
&
packet_sklist
)
{
struct
packet_opt
*
po
=
pkt_sk
(
s
);
len
+=
sprintf
(
buffer
+
len
,
"%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu"
,
s
,
atomic_read
(
&
s
->
sk_refcnt
),
s
->
sk_type
,
ntohs
(
po
->
num
),
po
->
ifindex
,
po
->
running
,
atomic_read
(
&
s
->
sk_rmem_alloc
),
sock_i_uid
(
s
),
sock_i_ino
(
s
)
);
buffer
[
len
++
]
=
'\n'
;
pos
=
begin
+
len
;
if
(
pos
<
offset
)
{
len
=
0
;
begin
=
pos
;
}
if
(
pos
>
offset
+
length
)
goto
done
;
static
void
*
packet_seq_next
(
struct
seq_file
*
seq
,
void
*
v
,
loff_t
*
pos
)
{
++*
pos
;
return
(
v
==
SEQ_START_TOKEN
)
?
sk_head
(
&
packet_sklist
)
:
sk_next
((
struct
sock
*
)
v
)
;
}
static
void
packet_seq_stop
(
struct
seq_file
*
seq
,
void
*
v
)
{
read_unlock
(
&
packet_sklist_lock
);
}
static
int
packet_seq_show
(
struct
seq_file
*
seq
,
void
*
v
)
{
if
(
v
==
SEQ_START_TOKEN
)
seq_puts
(
seq
,
"sk RefCnt Type Proto Iface R Rmem User Inode
\n
"
);
else
{
struct
sock
*
s
=
v
;
const
struct
packet_opt
*
po
=
pkt_sk
(
s
);
seq_printf
(
seq
,
"%p %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu
\n
"
,
s
,
atomic_read
(
&
s
->
sk_refcnt
),
s
->
sk_type
,
ntohs
(
po
->
num
),
po
->
ifindex
,
po
->
running
,
atomic_read
(
&
s
->
sk_rmem_alloc
),
sock_i_uid
(
s
),
sock_i_ino
(
s
)
);
}
*
eof
=
1
;
done:
read_unlock
(
&
packet_sklist_lock
);
*
start
=
buffer
+
(
offset
-
begin
);
len
-=
(
offset
-
begin
);
if
(
len
>
length
)
len
=
length
;
if
(
len
<
0
)
len
=
0
;
return
len
;
return
0
;
}
static
struct
seq_operations
packet_seq_ops
=
{
.
start
=
packet_seq_start
,
.
next
=
packet_seq_next
,
.
stop
=
packet_seq_stop
,
.
show
=
packet_seq_show
,
};
static
int
packet_seq_open
(
struct
inode
*
inode
,
struct
file
*
file
)
{
return
seq_open
(
file
,
&
packet_seq_ops
);
}
static
struct
file_operations
packet_seq_fops
=
{
.
owner
=
THIS_MODULE
,
.
open
=
packet_seq_open
,
.
read
=
seq_read
,
.
llseek
=
seq_lseek
,
.
release
=
seq_release
,
};
#endif
static
void
__exit
packet_exit
(
void
)
{
remove_proc_entry
(
"net/packet"
,
0
);
proc_net_remove
(
"packet"
);
unregister_netdevice_notifier
(
&
packet_netdev_notifier
);
sock_unregister
(
PF_PACKET
);
return
;
...
...
@@ -1831,9 +1857,8 @@ static int __init packet_init(void)
{
sock_register
(
&
packet_family_ops
);
register_netdevice_notifier
(
&
packet_netdev_notifier
);
#ifdef CONFIG_PROC_FS
create_proc_read_entry
(
"net/packet"
,
0
,
0
,
packet_read_proc
,
NULL
);
#endif
proc_net_fops_create
(
"packet"
,
0
,
&
packet_seq_fops
);
return
0
;
}
...
...
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