Skip to content

Commit

Permalink
now, packet_handler send the job to a worker (using workqueue)
Browse files Browse the repository at this point in the history
  • Loading branch information
beraldoleal committed Feb 17, 2013
1 parent a2bc652 commit ff7fac0
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,37 @@
#include <linux/module.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/workqueue.h>
#include <linux/export.h>

#include "proto.h"
#include "internal.h"

struct netsfs_skb_info {
struct work_struct my_work;
int x;
};

static void netsfs_go(struct work_struct *work)
{
struct netsfs_skb_info *netsfsinfo;

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

printk("Worker: netsfsinfo.x = %d\n", netsfsinfo->x);
kfree( (void *) work);
}

int netsfs_packet_handler(struct sk_buff *skb, struct net_device *dev, struct packet_type *pkt,
struct net_device *dev2)
{

int len, err;
struct dentry *de_mac;
struct dentry *de_network;
struct dentry *de_transport;

struct netsfs_skb_info *netsfsinfo;

char mac_name[8], network_name[6];

len = skb->len;
Expand All @@ -36,6 +53,7 @@ int netsfs_packet_handler(struct sk_buff *skb, struct net_device *dev, struct pa
err = -ENOMEM;
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
*/
Expand All @@ -58,22 +76,17 @@ int netsfs_packet_handler(struct sk_buff *skb, struct net_device *dev, struct pa
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);

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);
/* Put a work in a shared workqueue provided by the kernel */
netsfsinfo = kzalloc(sizeof(struct netsfs_skb_info), GFP_ATOMIC);
if (!netsfsinfo) {
err = -ENOMEM;
goto free;
}

err = 0;
netsfsinfo->x = 10;
INIT_WORK(&netsfsinfo->my_work, netsfs_go);
schedule_work(&netsfsinfo->my_work);

free:
dev_kfree_skb(skb);
Expand Down

0 comments on commit ff7fac0

Please sign in to comment.