ia64/xen-unstable

view tools/vnet/vnet-module/skb_context.c @ 8740:3d7ea7972b39

Update patches for linux 2.6.15.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Feb 02 17:16:00 2006 +0000 (2006-02-02)
parents 0a4b76b6b5a0
children
line source
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>
24 #include <skb_context.h>
26 #define MODULE_NAME "VNET"
27 #define DEBUG 1
28 #undef DEBUG
29 #include "debug.h"
31 SkbContext *SkbContext_create(u32 vnet, u32 addr, int protocol, void *data,
32 void (*free_fn)(SkbContext *)){
33 SkbContext *context = NULL;
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 }
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 }
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;
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 }
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);
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 }