Commit 507215f8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont Committed by David S. Miller

Phonet: list subscribed resources via proc_fs

Signed-off-by: default avatarRémi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b6a563b2
...@@ -57,5 +57,6 @@ struct net_device *phonet_route_output(struct net *net, u8 daddr); ...@@ -57,5 +57,6 @@ struct net_device *phonet_route_output(struct net *net, u8 daddr);
#define PN_NO_ADDR 0xff #define PN_NO_ADDR 0xff
extern const struct file_operations pn_sock_seq_fops; extern const struct file_operations pn_sock_seq_fops;
extern const struct file_operations pn_res_seq_fops;
#endif #endif
...@@ -373,6 +373,7 @@ int __init phonet_device_init(void) ...@@ -373,6 +373,7 @@ int __init phonet_device_init(void)
if (err) if (err)
return err; return err;
proc_net_fops_create(&init_net, "pnresource", 0, &pn_res_seq_fops);
register_netdevice_notifier(&phonet_device_notifier); register_netdevice_notifier(&phonet_device_notifier);
err = phonet_netlink_register(); err = phonet_netlink_register();
if (err) if (err)
...@@ -385,6 +386,7 @@ void phonet_device_exit(void) ...@@ -385,6 +386,7 @@ void phonet_device_exit(void)
rtnl_unregister_all(PF_PHONET); rtnl_unregister_all(PF_PHONET);
unregister_netdevice_notifier(&phonet_device_notifier); unregister_netdevice_notifier(&phonet_device_notifier);
unregister_pernet_device(&phonet_net_ops); unregister_pernet_device(&phonet_net_ops);
proc_net_remove(&init_net, "pnresource");
} }
int phonet_route_add(struct net_device *dev, u8 daddr) int phonet_route_add(struct net_device *dev, u8 daddr)
......
...@@ -654,3 +654,99 @@ void pn_sock_unbind_all_res(struct sock *sk) ...@@ -654,3 +654,99 @@ void pn_sock_unbind_all_res(struct sock *sk)
match--; match--;
} }
} }
#ifdef CONFIG_PROC_FS
static struct sock **pn_res_get_idx(struct seq_file *seq, loff_t pos)
{
struct net *net = seq_file_net(seq);
unsigned i;
if (!net_eq(net, &init_net))
return NULL;
for (i = 0; i < 256; i++) {
if (pnres.sk[i] == NULL)
continue;
if (!pos)
return pnres.sk + i;
pos--;
}
return NULL;
}
static struct sock **pn_res_get_next(struct seq_file *seq, struct sock **sk)
{
struct net *net = seq_file_net(seq);
unsigned i;
BUG_ON(!net_eq(net, &init_net));
for (i = (sk - pnres.sk) + 1; i < 256; i++)
if (pnres.sk[i])
return pnres.sk + i;
return NULL;
}
static void *pn_res_seq_start(struct seq_file *seq, loff_t *pos)
__acquires(resource_mutex)
{
mutex_lock(&resource_mutex);
return *pos ? pn_res_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
}
static void *pn_res_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
struct sock **sk;
if (v == SEQ_START_TOKEN)
sk = pn_res_get_idx(seq, 0);
else
sk = pn_res_get_next(seq, v);
(*pos)++;
return sk;
}
static void pn_res_seq_stop(struct seq_file *seq, void *v)
__releases(resource_mutex)
{
mutex_unlock(&resource_mutex);
}
static int pn_res_seq_show(struct seq_file *seq, void *v)
{
int len;
if (v == SEQ_START_TOKEN)
seq_printf(seq, "%s%n", "rs uid inode", &len);
else {
struct sock **psk = v;
struct sock *sk = *psk;
seq_printf(seq, "%02X %5d %lu%n",
psk - pnres.sk, sock_i_uid(sk), sock_i_ino(sk), &len);
}
seq_printf(seq, "%*s\n", 63 - len, "");
return 0;
}
static const struct seq_operations pn_res_seq_ops = {
.start = pn_res_seq_start,
.next = pn_res_seq_next,
.stop = pn_res_seq_stop,
.show = pn_res_seq_show,
};
static int pn_res_open(struct inode *inode, struct file *file)
{
return seq_open_net(inode, file, &pn_res_seq_ops,
sizeof(struct seq_net_private));
}
const struct file_operations pn_res_seq_fops = {
.owner = THIS_MODULE,
.open = pn_res_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_net,
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment