Skip to content

Commit

Permalink
refact: 2/2
Browse files Browse the repository at this point in the history
  • Loading branch information
beraldoleal committed Jun 2, 2013
1 parent 157a17b commit 2a4f7f9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
27 changes: 27 additions & 0 deletions inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,33 @@ extern int netsfs_create_by_name(const char *name, mode_t mode, struct dentry *p
return error;
}

/* High-Level function. Use this one.
* Create stats and stream files in parent dir.
* If parent is NULL, create on top netsfs_root.
*/
extern void netsfs_create_files(struct dentry *parent)
{
struct dentry *stats;

if (!parent)
parent = netsfs_root;

netsfs_create_by_name("stats", S_IFREG, parent, &stats, NULL, NETSFS_STATS);
netsfs_create_by_name("stream", S_IFREG, parent, &stats, NULL, NETSFS_STREAM);
}

/* High-Level function. Use this one.
* Create protocol directory in parent dir.
* If parent is NULL, create on top netsfs_root.
*/
extern void netsfs_create_dir(const char *proto_name, struct dentry *parent, struct dentry **dentry)
{
if (!parent)
parent = netsfs_root;

netsfs_create_by_name(proto_name, S_IFDIR, parent, dentry, NULL, NETSFS_DIR);
}

int netsfs_fill_super(struct super_block *sb, void *data, int silent)
{
struct netsfs_fs_info *fsi;
Expand Down
3 changes: 2 additions & 1 deletion internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ extern int netsfs_symlink(struct inode * dir, struct dentry *dentry, const char
extern int netsfs_create_by_name(const char *name, mode_t mode, struct dentry *parent,
struct dentry **dentry, void *data, netsfs_file_type_t type);


extern void netsfs_create_files(struct dentry *parent);
extern void netsfs_create_dir(const char *proto_name, struct dentry *parent, struct dentry **dentry);
extern void netsfs_inc_inode_size(struct inode *inode, loff_t inc);

struct netsfs_mount_opts {
Expand Down
36 changes: 21 additions & 15 deletions proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ struct netsfs_skb_info {

/* Return the Ethernet Packet "Type" field in string.
*/
const char *get_ether_type(struct sk_buff *skb) {
const char *get_ether_type(struct sk_buff *skb)
{
switch (ntohs(eth_hdr(skb)->h_proto))
{
case ETH_P_IP:
Expand All @@ -45,7 +46,8 @@ const char *get_ether_type(struct sk_buff *skb) {
}


const char *get_ipv4_protocol(struct sk_buff *skb) {
const char *get_ipv4_protocol(struct sk_buff *skb)
{
switch (ip_hdr(skb)->protocol)
{
case IPPROTO_IP:
Expand Down Expand Up @@ -81,7 +83,8 @@ const char *get_ipv4_protocol(struct sk_buff *skb) {
}
}

const char *get_ipv6_protocol(struct sk_buff *skb) {
const char *get_ipv6_protocol(struct sk_buff *skb)
{
switch (ipv6_hdr(skb)->nexthdr)
{
case NEXTHDR_HOP:
Expand All @@ -107,7 +110,8 @@ const char *get_ipv6_protocol(struct sk_buff *skb) {

/* Return the IP "protocol" field in string.
*/
const char *get_ip_protocol(struct sk_buff *skb) {
const char *get_ip_protocol(struct sk_buff *skb)
{

switch (ntohs(eth_hdr(skb)->h_proto))
{
Expand All @@ -123,34 +127,36 @@ const char *get_ip_protocol(struct sk_buff *skb) {

/* Return skb len.
*/
unsigned int get_skb_len(struct sk_buff *skb) {
unsigned int get_skb_len(struct sk_buff *skb)
{
return skb->len;
}

/* Top Halve.
* Work scheduled earlier is done now, here.
*/
// TODO: REFACT
static void netsfs_go(struct work_struct *work)
{
struct netsfs_skb_info *netsfsinfo;
struct dentry *mac_dentry, *network_dentry, *stats_dentry;
struct dentry *mac_dentry, *network_dentry;
unsigned int len;

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

/* Create top level files */
netsfs_create_files(NULL);

netsfs_create_by_name(get_ether_type(netsfsinfo->skb), S_IFDIR, NULL, &mac_dentry, NULL, NETSFS_DIR);
netsfs_create_by_name("stats", S_IFREG, NULL, &stats_dentry, NULL, NETSFS_STATS);
netsfs_create_by_name("stream", S_IFREG, NULL, &stats_dentry, NULL, NETSFS_STREAM);
/* Create L3 dir */
netsfs_create_dir(get_ether_type(netsfsinfo->skb), NULL, &mac_dentry);

if (mac_dentry) {
netsfs_create_by_name("stats", S_IFREG, mac_dentry, &stats_dentry, NULL, NETSFS_STATS);
netsfs_create_by_name("stream", S_IFREG, mac_dentry, &stats_dentry, NULL, NETSFS_STREAM);
netsfs_create_by_name(get_ip_protocol(netsfsinfo->skb), S_IFDIR, mac_dentry, &network_dentry, NULL, NETSFS_DIR);
/* Create L3 files */
netsfs_create_files(mac_dentry);
/* Create L4 dir */
netsfs_create_dir(get_ip_protocol(netsfsinfo->skb), mac_dentry, &network_dentry);
if (network_dentry) {
netsfs_create_by_name("stats", S_IFREG, network_dentry, &stats_dentry, NULL, NETSFS_STATS);
netsfs_create_by_name("stream", S_IFREG, network_dentry, &stats_dentry, NULL, NETSFS_STREAM);
/* Create L4 files */
netsfs_create_files(network_dentry);
}
}

Expand Down

0 comments on commit 2a4f7f9

Please sign in to comment.