~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/vnet/vnet-module/skb_context.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by the 
 
6
 * Free Software Foundation; either version 2 of the License, or (at your
 
7
 * option) any later version.
 
8
 * 
 
9
 * This program is distributed in the hope that it will be useful, but
 
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
11
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 
12
 * for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with this program; if not, write to the Free software Foundation, Inc.,
 
16
 * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
 
17
 *
 
18
 */
 
19
#include <linux/config.h>
 
20
#include <linux/kernel.h>
 
21
#include <linux/skbuff.h>
 
22
#include <linux/slab.h>
 
23
 
 
24
#include <skb_context.h>
 
25
 
 
26
#define MODULE_NAME "VNET"
 
27
#define DEBUG 1
 
28
#undef DEBUG
 
29
#include "debug.h"
 
30
 
 
31
SkbContext *SkbContext_create(u32 vnet, u32 addr, int protocol, void *data,
 
32
                              void (*free_fn)(SkbContext *)){
 
33
    SkbContext *context = NULL;
 
34
 
 
35
    context = kmalloc(sizeof(SkbContext), GFP_ATOMIC);
 
36
    if(!context) goto exit;
 
37
    context->vnet = vnet;
 
38
    context->addr = addr;
 
39
    context->protocol = protocol;
 
40
    context->data = data;
 
41
    context->free_fn = free_fn;
 
42
    context->next = NULL;
 
43
    atomic_set(&context ->refcount, 1);
 
44
  exit:
 
45
    return context;
 
46
}
 
47
                                       
 
48
void SkbContext_free(SkbContext *context){
 
49
    if(!context) return;
 
50
    if(context->next) SkbContext_decref(context->next);
 
51
    if(context->free_fn) context->free_fn(context);
 
52
    context->vnet = 0;
 
53
    context->addr = 0;
 
54
    context->protocol = 0;
 
55
    context->free_fn = NULL;
 
56
    context->data = NULL;
 
57
    context->next = NULL;
 
58
    kfree(context);
 
59
}
 
60
 
 
61
int SkbContext_push(SkbContext **val, u32 vnet, u32 addr, int protocol,
 
62
                    void *data, void (*free_fn)(SkbContext *)){
 
63
    int err = 0;
 
64
    SkbContext *context = NULL;
 
65
 
 
66
    dprintf("> vnet=%u addr=%u.%u.%u.%u protocol=%d\n",
 
67
            vnet, NIPQUAD(addr), protocol);
 
68
    context = SkbContext_create(vnet, addr, protocol, data, free_fn);
 
69
    if(!context){
 
70
        err = -ENOMEM;
 
71
        goto exit;
 
72
    }
 
73
    context->next = *val;
 
74
    *val = context;
 
75
  exit:
 
76
    dprintf("< err=%d\n", err);
 
77
    return err;
 
78
}
 
79
 
 
80
int skb_push_context(struct sk_buff *skb, u32 vnet, u32 addr, int protocol,
 
81
                     void *data, void (*free_fn)(SkbContext *)){
 
82
    int err = 0;
 
83
    //SkbContext *ctxt = SKB_CONTEXT(skb);
 
84
    dprintf("> skb=%p\n", skb);
 
85
 
 
86
    //err = SkbContext_push(&ctxt, vnet, addr, protocol, data, free_fn); //todo fixme
 
87
    //SKB_CONTEXT(skb) = ctxt;//todo fixme
 
88
    dprintf("< err=%d\n", err);
 
89
    return err;
 
90
}
 
91
                                       
 
92