[34] | 1 | /* |
---|
| 2 | * Copyright (C) 2004, 2005 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__ |
---|
| 21 | |
---|
| 22 | #ifdef __KERNEL__ |
---|
| 23 | #include <linux/types.h> |
---|
| 24 | #include <asm/atomic.h> |
---|
| 25 | |
---|
| 26 | #else |
---|
| 27 | |
---|
| 28 | //#include <linux/types.h> |
---|
| 29 | #include "sys_kernel.h" |
---|
| 30 | #include "spinlock.h" |
---|
| 31 | |
---|
| 32 | #endif |
---|
| 33 | |
---|
| 34 | #include <if_varp.h> |
---|
| 35 | |
---|
| 36 | struct sk_buff; |
---|
| 37 | struct Tunnel; |
---|
| 38 | |
---|
| 39 | typedef struct TunnelType { |
---|
| 40 | const char *name; |
---|
| 41 | int (*open)(struct Tunnel *tunnel); |
---|
| 42 | int (*send)(struct Tunnel *tunnel, struct sk_buff *skb); |
---|
| 43 | void (*close)(struct Tunnel *tunnel); |
---|
| 44 | } TunnelType; |
---|
| 45 | |
---|
| 46 | typedef struct TunnelStats { |
---|
| 47 | int bytes; |
---|
| 48 | int packets; |
---|
| 49 | int dropped_bytes; |
---|
| 50 | int dropped_packets; |
---|
| 51 | } TunnelStats; |
---|
| 52 | |
---|
| 53 | typedef struct TunnelKey { |
---|
| 54 | struct VnetId vnet; |
---|
| 55 | struct VarpAddr addr; |
---|
| 56 | } TunnelKey; |
---|
| 57 | |
---|
| 58 | typedef struct Tunnel { |
---|
| 59 | /** Key identifying the tunnel. Must be first. */ |
---|
| 60 | struct TunnelKey key; |
---|
| 61 | /** Reference count. */ |
---|
| 62 | atomic_t refcount; |
---|
| 63 | /** Tunnel type. */ |
---|
| 64 | struct TunnelType *type; |
---|
| 65 | /** Statistics. */ |
---|
| 66 | struct TunnelStats send_stats; |
---|
| 67 | /** Type-dependent state. */ |
---|
| 68 | void *data; |
---|
| 69 | /** Underlying tunnel (may be null). */ |
---|
| 70 | struct Tunnel *base; |
---|
| 71 | } Tunnel; |
---|
| 72 | |
---|
| 73 | extern void Tunnel_free(struct Tunnel *tunnel); |
---|
| 74 | |
---|
| 75 | /** Decrement the reference count, freeing if zero. |
---|
| 76 | * |
---|
| 77 | * @param tunnel tunnel (may be null) |
---|
| 78 | */ |
---|
| 79 | static inline void Tunnel_decref(struct Tunnel *tunnel){ |
---|
| 80 | if(!tunnel) return; |
---|
| 81 | if(atomic_dec_and_test(&tunnel->refcount)){ |
---|
| 82 | Tunnel_free(tunnel); |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | /** Increment the reference count. |
---|
| 87 | * |
---|
| 88 | * @param tunnel tunnel (may be null) |
---|
| 89 | */ |
---|
| 90 | static inline void Tunnel_incref(struct Tunnel *tunnel){ |
---|
| 91 | if(!tunnel) return; |
---|
| 92 | atomic_inc(&tunnel->refcount); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | extern int Tunnel_init(void); |
---|
| 96 | extern int Tunnel_lookup(struct VnetId *vnet, struct VarpAddr *addr, struct Tunnel **tunnel); |
---|
| 97 | extern int Tunnel_open(struct VnetId *vnet, struct VarpAddr *addr, |
---|
| 98 | int (*ctor)(struct VnetId *vnet, |
---|
| 99 | struct VarpAddr *addr, |
---|
| 100 | struct Tunnel **ptunnel), |
---|
| 101 | struct Tunnel **ptunnel); |
---|
| 102 | extern int Tunnel_add(struct Tunnel *tunnel); |
---|
| 103 | extern int Tunnel_del(struct Tunnel *tunnel); |
---|
| 104 | extern void Tunnel_print(struct Tunnel *tunnel); |
---|
| 105 | extern int Tunnel_send(struct Tunnel *tunnel, struct sk_buff *skb); |
---|
| 106 | |
---|
| 107 | extern int Tunnel_create(struct TunnelType *type, struct VnetId *vnet, struct VarpAddr *addr, |
---|
| 108 | struct Tunnel *base, struct Tunnel **tunnelp); |
---|
| 109 | |
---|
| 110 | extern int tunnel_module_init(void); |
---|
| 111 | extern void tunnel_module_exit(void); |
---|
| 112 | |
---|
| 113 | #endif /* !__VNET_TUNNEL_H__ */ |
---|