672755946f540a9a98be7754bd07a9124c9d42cb
[strongswan.git] / src / libfreeswan / ipsec_tunnel.h
1 /*
2 * IPSEC tunneling code
3 * Copyright (C) 1996, 1997 John Ioannidis.
4 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Richard Guy Briggs.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * RCSID $Id: ipsec_tunnel.h,v 1.1 2004/03/15 20:35:25 as Exp $
17 */
18
19 #include <linux/types.h>
20
21 #ifdef NET_21
22 # define DEV_QUEUE_XMIT(skb, device, pri) {\
23 skb->dev = device; \
24 neigh_compat_output(skb); \
25 /* skb->dst->output(skb); */ \
26 }
27 # define ICMP_SEND(skb_in, type, code, info, dev) \
28 icmp_send(skb_in, type, code, htonl(info))
29 # define IP_SEND(skb, dev) \
30 ip_send(skb);
31 #else /* NET_21 */
32 # define DEV_QUEUE_XMIT(skb, device, pri) {\
33 dev_queue_xmit(skb, device, pri); \
34 }
35 # define ICMP_SEND(skb_in, type, code, info, dev) \
36 icmp_send(skb_in, type, code, info, dev)
37 # define IP_SEND(skb, dev) \
38 if(ntohs(iph->tot_len) > physmtu) { \
39 ip_fragment(NULL, skb, dev, 0); \
40 ipsec_kfree_skb(skb); \
41 } else { \
42 dev_queue_xmit(skb, dev, SOPRI_NORMAL); \
43 }
44 #endif /* NET_21 */
45
46
47 /*
48 * Heavily based on drivers/net/new_tunnel.c. Lots
49 * of ideas also taken from the 2.1.x version of drivers/net/shaper.c
50 */
51
52 struct ipsectunnelconf
53 {
54 __u32 cf_cmd;
55 union
56 {
57 char cfu_name[12];
58 } cf_u;
59 #define cf_name cf_u.cfu_name
60 };
61
62 #define IPSEC_SET_DEV (SIOCDEVPRIVATE)
63 #define IPSEC_DEL_DEV (SIOCDEVPRIVATE + 1)
64 #define IPSEC_CLR_DEV (SIOCDEVPRIVATE + 2)
65
66 #ifdef __KERNEL__
67 #include <linux/version.h>
68 #ifndef KERNEL_VERSION
69 # define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
70 #endif
71 struct ipsecpriv
72 {
73 struct sk_buff_head sendq;
74 struct device *dev;
75 struct wait_queue *wait_queue;
76 char locked;
77 int (*hard_start_xmit) (struct sk_buff *skb,
78 struct device *dev);
79 int (*hard_header) (struct sk_buff *skb,
80 struct device *dev,
81 unsigned short type,
82 void *daddr,
83 void *saddr,
84 unsigned len);
85 #ifdef NET_21
86 int (*rebuild_header)(struct sk_buff *skb);
87 #else /* NET_21 */
88 int (*rebuild_header)(void *buff, struct device *dev,
89 unsigned long raddr, struct sk_buff *skb);
90 #endif /* NET_21 */
91 int (*set_mac_address)(struct device *dev, void *addr);
92 #ifndef NET_21
93 void (*header_cache_bind)(struct hh_cache **hhp, struct device *dev,
94 unsigned short htype, __u32 daddr);
95 #endif /* !NET_21 */
96 void (*header_cache_update)(struct hh_cache *hh, struct device *dev, unsigned char * haddr);
97 struct net_device_stats *(*get_stats)(struct device *dev);
98 struct net_device_stats mystats;
99 int mtu; /* What is the desired MTU? */
100 };
101
102 extern char ipsec_tunnel_c_version[];
103
104 extern struct device *ipsecdevices[IPSEC_NUM_IF];
105
106 int ipsec_tunnel_init_devices(void);
107
108 /* void */ int ipsec_tunnel_cleanup_devices(void);
109
110 extern /* void */ int ipsec_init(void);
111
112 extern int ipsec_tunnel_start_xmit(struct sk_buff *skb, struct device *dev);
113
114 #ifdef CONFIG_IPSEC_DEBUG
115 extern int debug_tunnel;
116 extern int sysctl_ipsec_debug_verbose;
117 #endif /* CONFIG_IPSEC_DEBUG */
118 #endif /* __KERNEL__ */
119
120 #ifdef CONFIG_IPSEC_DEBUG
121 #define DB_TN_INIT 0x0001
122 #define DB_TN_PROCFS 0x0002
123 #define DB_TN_XMIT 0x0010
124 #define DB_TN_OHDR 0x0020
125 #define DB_TN_CROUT 0x0040
126 #define DB_TN_OXFS 0x0080
127 #define DB_TN_REVEC 0x0100
128 #endif /* CONFIG_IPSEC_DEBUG */