source: trunk/packages/xen-3.1/xen-3.1/tools/vnet/vnet-module/skb_context.h @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 2.5 KB
Line 
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
20#ifndef __VNET_SKB_CONTEXT_H__
21#define __VNET_SKB_CONTEXT_H__
22
23#ifdef __KERNEL__
24#include <linux/config.h>
25#include <linux/kernel.h>
26#include <asm/atomic.h>
27#include <linux/types.h>
28
29//todo: fixme
30#define SKB_CONTEXT(_skb) ((SkbContext *)(&(_skb)->cb[0]))
31
32#else
33
34#include "sys_kernel.h"
35#include "spinlock.h"
36
37//todo: fixme
38#define SKB_CONTEXT(_skb) ((SkbContext *)NULL)
39
40#endif
41
42/** Structure used to record inbound processing path for skbs.
43 * For example, the ETHERIP protocol handler can use this to
44 * tell whether an inbound packet came through IPSEC ESP or not.
45 */
46typedef struct SkbContext {
47    u32 vnet;
48    u32 addr;
49    int protocol;
50    void *data;
51    void (*free_fn)(struct SkbContext *);
52    atomic_t refcount;
53    struct SkbContext *next;
54} SkbContext;
55
56/** Decrement the reference count, freeing if zero.
57 *
58 * @param context context (may be null)
59 */
60static inline void SkbContext_decref(SkbContext *context){
61    extern void SkbContext_free(SkbContext *context);
62    if(!context) return;
63    if(atomic_dec_and_test(&context->refcount)){
64        SkbContext_free(context);
65    }
66}
67
68/** Increment the reference count.
69 *
70 * @param context context (may be null)
71 */
72static inline void SkbContext_incref(SkbContext *context){
73    if(!context) return;
74    atomic_inc(&context->refcount);
75}
76
77extern SkbContext *SkbContext_create(u32 vnet, u32 addr, int protocol, void *data,
78                                     void (*free_fn)(SkbContext *));
79
80extern int SkbContext_push(SkbContext **val, u32 vnet, u32 addr, int protocol,
81                           void *data, void (*free_fn)(SkbContext *));
82
83struct sk_buff;
84extern int skb_push_context(struct sk_buff *skb, u32 vnet, u32 addr, int protocol,
85                            void *data, void (*free_fn)(SkbContext *));
86
87#endif /* !__VNET_SKB_CONTEXT_H__ */ 
Note: See TracBrowser for help on using the repository browser.