Skip to content

Commit

Permalink
added dentry size as a sum of packets len
Browse files Browse the repository at this point in the history
  • Loading branch information
beraldoleal committed Feb 13, 2013
1 parent efb1fc4 commit a2bc652
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
18 changes: 18 additions & 0 deletions inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/highmem.h>
#include <linux/time.h>
#include <linux/namei.h>
#include <linux/atomic.h>
#include <linux/init.h>
#include <linux/string.h>
#include <linux/sched.h>
Expand Down Expand Up @@ -59,6 +60,23 @@ const match_table_t tokens = {
};


extern void netsfs_inc_inode_size(struct inode *inode, loff_t inc)
{
loff_t oldsize, newsize;

printk(KERN_INFO "%s: Updating inode %lu size to %lld\n",
THIS_MODULE->name,
inode->i_ino,
inc);

spin_lock(&inode->i_lock);
oldsize = i_size_read(inode);
newsize = oldsize + inc;
i_size_write(inode, newsize);
spin_unlock(&inode->i_lock);
}


struct inode *netsfs_get_inode(struct super_block *sb,
const struct inode *dir, int mode, dev_t dev)
{
Expand Down
2 changes: 2 additions & 0 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ extern int netsfs_create_by_name(const char *name, mode_t mode, struct dentry *p
struct dentry **dentry, void *data);


extern void netsfs_inc_inode_size(struct inode *inode, loff_t inc);

struct netsfs_mount_opts {
umode_t mode;
};
Expand Down
50 changes: 24 additions & 26 deletions proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,50 +34,48 @@ int netsfs_packet_handler(struct sk_buff *skb, struct net_device *dev, struct pa
if (len > ETH_DATA_LEN) {
printk(KERN_INFO "%s:len > ETH_DATA_LEN!\n", THIS_MODULE->name);
err = -ENOMEM;
goto fail;
goto free;
}
/* check for ip header, in this case never will get nothing different of ETH_P_IP, but this switch
* * is here just in case you change netsfs_pseudo_proto.type
* */
* is here just in case you change netsfs_pseudo_proto.type
*/
switch (ntohs(eth_hdr(skb)->h_proto))
{
case ETH_P_IP:
sprintf(mac_name, "0x%.4x", ntohs(eth_hdr(skb)->h_proto));
sprintf(network_name, "0x%.2x", ip_hdr(skb)->protocol);
printk(KERN_INFO "%s: (%s %d, %s, %s) Packet\n",
THIS_MODULE->name,
skb->dev->name,
skb->dev->type,
mac_name, network_name);
netsfs_create_by_name(mac_name, S_IFDIR, NULL, &de_mac, NULL);
if (de_mac)
netsfs_create_by_name(network_name, S_IFDIR, de_mac, &de_network, NULL);
break;
case ETH_P_IPV6:
sprintf(mac_name, "0x%.4x", ntohs(eth_hdr(skb)->h_proto));
sprintf(network_name, "0x%.2x", ipv6_hdr(skb)->nexthdr);
printk(KERN_INFO "%s: (%s %d %s, %s) Packet\n",
THIS_MODULE->name,
skb->dev->name,
skb->dev->type,
mac_name,
network_name);
netsfs_create_by_name(mac_name, S_IFDIR, NULL, &de_mac, NULL);
if (de_mac)
netsfs_create_by_name(network_name, S_IFDIR, de_mac, &de_network, NULL);
break;

default:
printk(KERN_INFO "%s: Unknow packet (0x%.4X, 0x%.4X)\n", THIS_MODULE->name, ntohs(pkt->type), ntohs(eth_hdr(skb)->h_proto));
printk(KERN_INFO "%s: Unknow packet (0x%.4X, 0x%.4X)\n",
THIS_MODULE->name,
ntohs(pkt->type),
ntohs(eth_hdr(skb)->h_proto));
err = -ENOMEM;
goto free;
break;
}
printk(KERN_INFO "%s: (%s %d %s, %s %d) Packet\n",
THIS_MODULE->name,
skb->dev->name,
skb->dev->type,
mac_name,
network_name,
skb->len);

/* We need free the skb, this is a copy! */
dev_kfree_skb(skb);
netsfs_create_by_name(mac_name, S_IFDIR, NULL, &de_mac, NULL);
if (de_mac) {
printk("de_mac found name = %s\n", de_mac->d_iname);
netsfs_inc_inode_size(de_mac->d_inode, skb->len);
netsfs_create_by_name(network_name, S_IFDIR, de_mac, &de_network, NULL);
}

return 0;
err = 0;

fail:
free:
dev_kfree_skb(skb);
return err;
}

0 comments on commit a2bc652

Please sign in to comment.