Skip to content

Commit

Permalink
fixed dir names to protocol names
Browse files Browse the repository at this point in the history
  • Loading branch information
beraldoleal committed Jun 2, 2013
1 parent 2292d00 commit bfedf30
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 51 deletions.
84 changes: 39 additions & 45 deletions inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ static ssize_t netsfs_file_read(struct file *file, char __user *buf,
return length;
}

/*
printk("AQUI: %lld\n",
((struct netsfs_dir_private *) file->f_dentry->d_parent->d_inode->i_private)->bytes);
*/


return 0;
}

Expand Down Expand Up @@ -109,10 +103,10 @@ extern void netsfs_inc_inode_size(struct inode *inode, loff_t inc)
loff_t oldsize, newsize;
struct netsfs_dir_private *private;

printk(KERN_INFO "%s: Updating inode %lu size to %lld\n",
THIS_MODULE->name,
inode->i_ino,
inc);
//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);
Expand Down Expand Up @@ -176,10 +170,10 @@ extern int netsfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
int error = -ENOSPC;

if (dentry->d_inode) {
printk("%s:%s:%d - dentry->d_inode != NULL, aborting.\n",
THIS_MODULE->name,
__FUNCTION__,
__LINE__);
//printk("%s:%s:%d - dentry->d_inode != NULL, aborting.\n",
// THIS_MODULE->name,
// __FUNCTION__,
// __LINE__);
return -EEXIST;
}

Expand All @@ -197,23 +191,23 @@ extern int netsfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
{
int retval;

printk("%s:%s:%d - Start. dir->i_ino == %lu, dentry->d_iname == %s\n",
THIS_MODULE->name,
__FUNCTION__,
__LINE__,
dir->i_ino,
dentry->d_iname);
//printk("%s:%s:%d - Start. dir->i_ino == %lu, dentry->d_iname == %s\n",
// THIS_MODULE->name,
// __FUNCTION__,
// __LINE__,
// dir->i_ino,
// dentry->d_iname);

retval = netsfs_mknod(dir, dentry, mode | S_IFDIR, 0);

if (!retval) {
inc_nlink(dir);
printk("%s:%s:%d - End. inode->i_ino == %lu, dentry->d_iname == %s\n",
THIS_MODULE->name,
__FUNCTION__,
__LINE__,
dir->i_ino,
dentry->d_iname);
//printk("%s:%s:%d - End. inode->i_ino == %lu, dentry->d_iname == %s\n",
// THIS_MODULE->name,
// __FUNCTION__,
// __LINE__,
// dir->i_ino,
// dentry->d_iname);
}

return retval;
Expand Down Expand Up @@ -283,10 +277,10 @@ extern int netsfs_create_by_name(const char *name, mode_t mode, struct dentry *p
{
int error = 0;

printk("%s:%s:%d - Start.\n",
THIS_MODULE->name,
__FUNCTION__,
__LINE__);
//printk("%s:%s:%d - Start.\n",
// THIS_MODULE->name,
// __FUNCTION__,
// __LINE__);

/* If the parent is not specified, we create it in the root.
* We need the root dentry to do this, which is in the super
Expand All @@ -303,10 +297,10 @@ extern int netsfs_create_by_name(const char *name, mode_t mode, struct dentry *p
if (!IS_ERR(*dentry)) {
switch (mode & S_IFMT) {
case S_IFDIR:
printk("%s:%s:%d - Is a dir, creating...\n",
THIS_MODULE->name,
__FUNCTION__,
__LINE__);
//printk("%s:%s:%d - Is a dir, creating...\n",
// THIS_MODULE->name,
// __FUNCTION__,
// __LINE__);
error = netsfs_mkdir(parent->d_inode, *dentry, mode);
break;
case S_IFLNK:
Expand All @@ -330,10 +324,10 @@ extern int netsfs_create_by_name(const char *name, mode_t mode, struct dentry *p
error = PTR_ERR(*dentry);

mutex_unlock(&parent->d_inode->i_mutex);
printk("%s:%s:%d - End.\n",
THIS_MODULE->name,
__FUNCTION__,
__LINE__);
//printk("%s:%s:%d - End.\n",
// THIS_MODULE->name,
// __FUNCTION__,
// __LINE__);

return error;
}
Expand Down Expand Up @@ -391,7 +385,7 @@ struct dentry *netsfs_mount(struct file_system_type *fs_type,
{
struct dentry *root;

printk("%s:%s:%d - Start.\n", THIS_MODULE->name, __FUNCTION__, __LINE__);
// printk("%s:%s:%d - Start.\n", THIS_MODULE->name, __FUNCTION__, __LINE__);
root = mount_nodev(fs_type, flags, data, netsfs_fill_super);
if (IS_ERR(root))
goto out;
Expand All @@ -404,13 +398,13 @@ struct dentry *netsfs_mount(struct file_system_type *fs_type,
netsfs_pseudo_proto.func = netsfs_packet_handler;
dev_add_pack(&netsfs_pseudo_proto);

printk("%s:%s:%d - End.\n", THIS_MODULE->name, __FUNCTION__, __LINE__);
// printk("%s:%s:%d - End.\n", THIS_MODULE->name, __FUNCTION__, __LINE__);

printk("%s:%s:%d - netsfs_root->d_inode->i_ino == %lu\n",
THIS_MODULE->name,
__FUNCTION__,
__LINE__,
netsfs_root->d_inode->i_ino);
// printk("%s:%s:%d - netsfs_root->d_inode->i_ino == %lu\n",
// THIS_MODULE->name,
// __FUNCTION__,
// __LINE__,
// netsfs_root->d_inode->i_ino);

out:
return root;
Expand Down
81 changes: 75 additions & 6 deletions proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/module.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <net/ipv6.h>
#include <linux/workqueue.h>
#include <linux/export.h>

Expand All @@ -37,7 +38,7 @@ static void netsfs_go(struct work_struct *work)

netsfsinfo = container_of(work, struct netsfs_skb_info, my_work);

printk("Worker: %s %s %d\n", netsfsinfo->mac_name, netsfsinfo->network_name, netsfsinfo->len);
//printk("Worker: %s %s %d\n", netsfsinfo->mac_name, netsfsinfo->network_name, netsfsinfo->len);

/* Create mac dir */
netsfs_create_by_name(netsfsinfo->mac_name, S_IFDIR, NULL, &mac_dentry, NULL, NETSFS_DIR);
Expand Down Expand Up @@ -72,7 +73,7 @@ int netsfs_packet_handler(struct sk_buff *skb, struct net_device *dev, struct pa
{
int len, err;
struct netsfs_skb_info *netsfsinfo;
char mac_name[8], network_name[6];
char mac_name[8], network_name[10];

len = skb->len;

Expand All @@ -82,18 +83,85 @@ int netsfs_packet_handler(struct sk_buff *skb, struct net_device *dev, struct pa
goto free;
}

printk("** BEGIN: 0x%.2x, 0x%.2x\n", ntohs(eth_hdr(skb)->h_proto), ip_hdr(skb)->protocol);

/* 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
*/
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);
//sprintf(mac_name, "0x%.4x", ntohs(eth_hdr(skb)->h_proto));
sprintf(mac_name, "ipv4");
// TODO: FIX this switch
switch (ip_hdr(skb)->protocol)
{
case IPPROTO_IP:
sprintf(network_name, "ip");
break;
case IPPROTO_ICMP:
sprintf(network_name, "icmp");
break;
case IPPROTO_IGMP:
sprintf(network_name, "igmp");
break;
case IPPROTO_IPIP:
sprintf(network_name, "ipip");
break;
case IPPROTO_TCP:
sprintf(network_name, "tcp");
break;
case IPPROTO_EGP:
sprintf(network_name, "egp");
break;
case IPPROTO_PUP:
sprintf(network_name, "pup");
break;
case IPPROTO_UDP:
sprintf(network_name, "udp");
break;
case IPPROTO_IPV6:
sprintf(network_name, "ipv6");
break;
case IPPROTO_SCTP:
sprintf(network_name, "sctp");
break;
case IPPROTO_RAW:
sprintf(network_name, "raw");
break;
default:
sprintf(network_name, "0x%.2x", ip_hdr(skb)->protocol);
break;
}
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);
//sprintf(mac_name, "0x%.4x", ntohs(eth_hdr(skb)->h_proto));
sprintf(mac_name, "ipv6");
switch (ipv6_hdr(skb)->nexthdr)
{
case NEXTHDR_HOP:
sprintf(network_name, "hop");
break;
case NEXTHDR_TCP:
sprintf(network_name, "tcp");
break;
case NEXTHDR_UDP:
sprintf(network_name, "udp");
break;
case NEXTHDR_IPV6:
sprintf(network_name, "ipv6");
break;
case NEXTHDR_ICMP:
sprintf(network_name, "icmp");
break;
default:
sprintf(network_name, "0x%.2x", ipv6_hdr(skb)->nexthdr);
break;
}
break;
case ETH_P_ARP:
sprintf(mac_name, "arp");
sprintf(network_name, "0x%.2x", ip_hdr(skb)->protocol);
break;
default:
printk(KERN_INFO "%s: Unknow packet (0x%.4X, 0x%.4X)\n",
Expand All @@ -120,5 +188,6 @@ int netsfs_packet_handler(struct sk_buff *skb, struct net_device *dev, struct pa

free:
dev_kfree_skb(skb);
printk("** END\n");
return err;
}

0 comments on commit bfedf30

Please sign in to comment.