ia64/xen-unstable

view tools/vnet/vnet-module/tunnel.h @ 6946:e703abaf6e3d

Add behaviour to the remove methods to remove the transaction's path itself. This allows us to write Remove(path) to remove the specified path rather than having to slice the path ourselves.
author emellor@ewan
date Sun Sep 18 14:42:13 2005 +0100 (2005-09-18)
parents 3233e7ecfa9f
children 06d84bf87159
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 #ifndef __VNET_TUNNEL_H__
20 #define __VNET_TUNNEL_H__
22 #include <linux/types.h>
23 #include <linux/slab.h>
24 #include <asm/atomic.h>
25 #include <if_varp.h>
27 struct sk_buff;
28 struct Tunnel;
30 typedef struct TunnelType {
31 const char *name;
32 int (*open)(struct Tunnel *tunnel);
33 int (*send)(struct Tunnel *tunnel, struct sk_buff *skb);
34 void (*close)(struct Tunnel *tunnel);
35 } TunnelType;
37 typedef struct TunnelStats {
38 int bytes;
39 int packets;
40 int dropped_bytes;
41 int dropped_packets;
42 } TunnelStats;
44 typedef struct TunnelKey {
45 VnetId vnet;
46 VarpAddr addr;
47 } TunnelKey;
49 typedef struct Tunnel {
50 /** Key identifying the tunnel. Must be first. */
51 struct TunnelKey key;
52 /** Reference count. */
53 atomic_t refcount;
54 /** Tunnel type. */
55 struct TunnelType *type;
56 /** Statistics. */
57 struct TunnelStats send_stats;
58 /** Type-dependent state. */
59 void *data;
60 /** Underlying tunnel (may be null). */
61 struct Tunnel *base;
62 } Tunnel;
64 extern void Tunnel_print(Tunnel *tunnel);
66 /** Decrement the reference count, freeing if zero.
67 *
68 * @param tunnel tunnel (may be null)
69 */
70 static inline void Tunnel_decref(Tunnel *tunnel){
71 if(!tunnel) return;
72 if(atomic_dec_and_test(&tunnel->refcount)){
73 printk("%s> Closing tunnel:\n", __FUNCTION__);
74 Tunnel_print(tunnel);
75 tunnel->type->close(tunnel);
76 Tunnel_decref(tunnel->base);
77 kfree(tunnel);
78 }
79 }
81 /** Increment the reference count.
82 *
83 * @param tunnel tunnel (may be null)
84 */
85 static inline void Tunnel_incref(Tunnel *tunnel){
86 if(!tunnel) return;
87 atomic_inc(&tunnel->refcount);
88 }
90 extern int Tunnel_init(void);
91 extern Tunnel * Tunnel_lookup(struct VnetId *vnet, struct VarpAddr *addr);
92 extern int Tunnel_add(Tunnel *tunnel);
93 extern int Tunnel_del(Tunnel *tunnel);
94 extern int Tunnel_send(Tunnel *tunnel, struct sk_buff *skb);
96 extern int Tunnel_create(TunnelType *type, struct VnetId *vnet, struct VarpAddr *addr,
97 Tunnel *base, Tunnel **tunnelp);
98 extern int Tunnel_open(TunnelType *type, struct VnetId *vnet, struct VarpAddr *addr,
99 Tunnel *base, Tunnel **tunnelp);
101 extern int tunnel_module_init(void);
102 extern void tunnel_module_exit(void);
104 #endif /* !__VNET_TUNNEL_H__ */