kernel-wfp: Define IPsec related ALE layers and callout GUIDs
[strongswan.git] / src / libcharon / plugins / kernel_wfp / kernel_wfp_compat.c
1 /*
2 * Copyright (C) 2013 Martin Willi
3 * Copyright (C) 2013 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <library.h>
17
18 const GUID FWPM_CONDITION_IP_REMOTE_ADDRESS = {
19 0xb235ae9a, 0x1d64, 0x49b8, { 0xa4,0x4c,0x5f,0xf3,0xd9,0x09,0x50,0x45 }
20 };
21 const GUID FWPM_CONDITION_IP_LOCAL_ADDRESS = {
22 0xd9ee00de, 0xc1ef, 0x4617, { 0xbf,0xe3,0xff,0xd8,0xf5,0xa0,0x89,0x57 }
23 };
24 const GUID FWPM_CONDITION_IP_SOURCE_ADDRESS = {
25 0xae96897e, 0x2e94, 0x4bc9, { 0xb3,0x13,0xb2,0x7e,0xe8,0x0e,0x57,0x4d }
26 };
27 const GUID FWPM_CONDITION_IP_DESTINATION_ADDRESS = {
28 0x2d79133b, 0xb390, 0x45c6, { 0x86,0x99,0xac,0xac,0xea,0xaf,0xed,0x33 }
29 };
30 const GUID FWPM_CONDITION_IP_LOCAL_PORT = {
31 0x0c1ba1af, 0x5765, 0x453f, { 0xaf,0x22,0xa8,0xf7,0x91,0xac,0x77,0x5b }
32 };
33 const GUID FWPM_CONDITION_IP_REMOTE_PORT = {
34 0xc35a604d, 0xd22b, 0x4e1a, { 0x91,0xb4,0x68,0xf6,0x74,0xee,0x67,0x4b }
35 };
36 const GUID FWPM_CONDITION_IP_PROTOCOL = {
37 0x3971ef2b, 0x623e, 0x4f9a, { 0x8c,0xb1,0x6e,0x79,0xb8,0x06,0xb9,0xa7 }
38 };
39 const GUID FWPM_LAYER_INBOUND_TRANSPORT_V4 = {
40 0x5926dfc8, 0xe3cf, 0x4426, { 0xa2,0x83,0xdc,0x39,0x3f,0x5d,0x0f,0x9d }
41 };
42 const GUID FWPM_LAYER_INBOUND_TRANSPORT_V6 = {
43 0x634a869f, 0xfc23, 0x4b90, { 0xb0,0xc1,0xbf,0x62,0x0a,0x36,0xae,0x6f }
44 };
45 const GUID FWPM_LAYER_OUTBOUND_TRANSPORT_V4 = {
46 0x09e61aea, 0xd214, 0x46e2, { 0x9b,0x21,0xb2,0x6b,0x0b,0x2f,0x28,0xc8 }
47 };
48 const GUID FWPM_LAYER_OUTBOUND_TRANSPORT_V6 = {
49 0xe1735bde, 0x013f, 0x4655, { 0xb3,0x51,0xa4,0x9e,0x15,0x76,0x2d,0xf0 }
50 };
51 const GUID FWPM_LAYER_IPFORWARD_V4 = {
52 0xa82acc24, 0x4ee1, 0x4ee1, { 0xb4,0x65,0xfd,0x1d,0x25,0xcb,0x10,0xa4}
53 };
54 const GUID FWPM_LAYER_IPFORWARD_V6 = {
55 0x7b964818, 0x19c7, 0x493a, { 0xb7,0x1f,0x83,0x2c,0x36,0x84,0xd2,0x8c }
56 };
57 const GUID FWPM_LAYER_ALE_AUTH_CONNECT_V4 = {
58 0xc38d57d1, 0x05a7, 0x4c33, { 0x90,0x4f,0x7f,0xbc,0xee,0xe6,0x0e,0x82 }
59 };
60 const GUID FWPM_LAYER_ALE_AUTH_CONNECT_V6 = {
61 0x4a72393b, 0x319f, 0x44bc, { 0x84,0xc3,0xba,0x54,0xdc,0xb3,0xb6,0xb4 }
62 };
63 const GUID FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V4 = {
64 0xe1cd9fe7, 0xf4b5, 0x4273, { 0x96,0xc0,0x59,0x2e,0x48,0x7b,0x86,0x50 }
65 };
66 const GUID FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6 = {
67 0xa3b42c97, 0x9f04, 0x4672, { 0xb8,0x7e,0xce,0xe9,0xc4,0x83,0x25,0x7f }
68 };
69 const GUID FWPM_CALLOUT_IPSEC_INBOUND_TRANSPORT_V4 = {
70 0x5132900d, 0x5e84, 0x4b5f, { 0x80,0xe4,0x01,0x74,0x1e,0x81,0xff,0x10 }
71 };
72 const GUID FWPM_CALLOUT_IPSEC_INBOUND_TRANSPORT_V6 = {
73 0x49d3ac92, 0x2a6c, 0x4dcf, { 0x95,0x5f,0x1c,0x3b,0xe0,0x09,0xdd,0x99 }
74 };
75 const GUID FWPM_CALLOUT_IPSEC_OUTBOUND_TRANSPORT_V4 = {
76 0x4b46bf0a, 0x4523, 0x4e57, { 0xaa,0x38,0xa8,0x79,0x87,0xc9,0x10,0xd9 }
77 };
78 const GUID FWPM_CALLOUT_IPSEC_OUTBOUND_TRANSPORT_V6 = {
79 0x38d87722, 0xad83, 0x4f11, { 0xa9,0x1f,0xdf,0x0f,0xb0,0x77,0x22,0x5b }
80 };
81 const GUID FWPM_CALLOUT_IPSEC_INBOUND_TUNNEL_V4 = {
82 0x191a8a46, 0x0bf8, 0x46cf, { 0xb0,0x45,0x4b,0x45,0xdf,0xa6,0xa3,0x24 }
83 };
84 const GUID FWPM_CALLOUT_IPSEC_INBOUND_TUNNEL_V6 = {
85 0x80c342e3, 0x1e53, 0x4d6f, { 0x9b,0x44,0x03,0xdf,0x5a,0xee,0xe1,0x54 }
86 };
87 const GUID FWPM_CALLOUT_IPSEC_OUTBOUND_TUNNEL_V4 = {
88 0x70a4196c, 0x835b, 0x4fb0, { 0x98,0xe8,0x07,0x5f,0x4d,0x97,0x7d,0x46 }
89 };
90 const GUID FWPM_CALLOUT_IPSEC_OUTBOUND_TUNNEL_V6 = {
91 0xf1835363, 0xa6a5, 0x4e62, { 0xb1,0x80,0x23,0xdb,0x78,0x9d,0x8d,0xa6 }
92 };
93 const GUID FWPM_CALLOUT_IPSEC_FORWARD_INBOUND_TUNNEL_V4 = {
94 0x28829633, 0xc4f0, 0x4e66, { 0x87,0x3f,0x84,0x4d,0xb2,0xa8,0x99,0xc7 }
95 };
96 const GUID FWPM_CALLOUT_IPSEC_FORWARD_INBOUND_TUNNEL_V6 = {
97 0xaf50bec2, 0xc686, 0x429a, { 0x88,0x4d,0xb7,0x44,0x43,0xe7,0xb0,0xb4 }
98 };
99 const GUID FWPM_CALLOUT_IPSEC_FORWARD_OUTBOUND_TUNNEL_V4 = {
100 0xfb532136, 0x15cb, 0x440b, { 0x93,0x7c,0x17,0x17,0xca,0x32,0x0c,0x40 }
101 };
102 const GUID FWPM_CALLOUT_IPSEC_FORWARD_OUTBOUND_TUNNEL_V6 = {
103 0xdae640cc, 0xe021, 0x4bee, { 0x9e,0xb6,0xa4,0x8b,0x27,0x5c,0x8c,0x1d }
104 };
105 const GUID FWPM_CALLOUT_IPSEC_ALE_CONNECT_V4 = {
106 0x6ac141fc, 0xf75d, 0x4203, { 0xb9,0xc8,0x48,0xe6,0x14,0x9c,0x27,0x12 }
107 };
108 const GUID FWPM_CALLOUT_IPSEC_ALE_CONNECT_V6 = {
109 0x4c0dda05, 0xe31f, 0x4666, { 0x90,0xb0,0xb3,0xdf,0xad,0x34,0x12,0x9a }
110 };
111 const GUID FWPM_CALLOUT_IPSEC_INBOUND_TUNNEL_ALE_ACCEPT_V4 = {
112 0x3df6e7de, 0xfd20, 0x48f2, { 0x9f,0x26,0xf8,0x54,0x44,0x4c,0xba,0x79 }
113 };
114 const GUID FWPM_CALLOUT_IPSEC_INBOUND_TUNNEL_ALE_ACCEPT_V6 = {
115 0xa1e392d3, 0x72ac, 0x47bb, { 0x87,0xa7,0x01,0x22,0xc6,0x94,0x34,0xab }
116 };
117 const GUID FWPM_CALLOUT_IPSEC_INBOUND_INITIATE_SECURE_V4 = {
118 0x7dff309b, 0xba7d, 0x4aba, { 0x91,0xaa,0xae,0x5c,0x66,0x40,0xc9,0x44 }
119 };
120 const GUID FWPM_CALLOUT_IPSEC_INBOUND_INITIATE_SECURE_V6 = {
121 0xa9a0d6d9, 0xc58c, 0x474e, { 0x8a,0xeb,0x3c,0xfe,0x99,0xd6,0xd5,0x3d }
122 };
123
124 /**
125 * Load a function symbol from a loaded dll
126 */
127 static inline void *load_function(char *dll, char *name)
128 {
129 HANDLE handle;
130 void *sym = NULL;
131
132 handle = GetModuleHandle(dll);
133 if (!handle)
134 {
135 return NULL;
136 }
137 sym = GetProcAddress(handle, name);
138 return sym;
139 }
140
141 /**
142 * Macro that defines a stub for a function that calls the same DLL function
143 *
144 * @param dll DLL to find function in
145 * @param ret return type of function
146 * @param name function name
147 * @param size size of all arguments on stack
148 * @param ... arguments of function
149 */
150 #define STUB(dll, ret, name, size, ...) \
151 ret WINAPI name(__VA_ARGS__) \
152 { \
153 static void (*fun)() = NULL; \
154 if (!fun) \
155 { \
156 fun = load_function(#dll, #name); \
157 } \
158 if (fun) \
159 { \
160 __builtin_return(__builtin_apply(fun, __builtin_apply_args(), size)); \
161 } \
162 return ERROR_NOT_SUPPORTED; \
163 }
164
165 STUB(fwpuclnt, DWORD, IPsecSaContextCreate1, 40,
166 HANDLE engineHandle, const void *outboundTraffic,
167 const void *virtualIfTunnelInfo, UINT64 *inboundFilterId, UINT64 *id)
168
169 STUB(fwpuclnt, DWORD, IPsecSaContextSetSpi0, 32,
170 HANDLE engineHandle, UINT64 id, const void *getSpi, UINT32 inboundSpi)
171
172 STUB(fwpuclnt, DWORD, IPsecSaContextGetById1, 24,
173 HANDLE engineHandle, UINT64 id, void **saContext)
174
175 STUB(fwpuclnt, DWORD, IPsecSaContextUpdate0, 24,
176 HANDLE engineHandle, UINT32 flags, const void *newValues)
177
178 STUB(fwpuclnt, DWORD, IPsecSaContextEnum1, 40,
179 HANDLE engineHandle, HANDLE enumHandle, UINT32 numEntriesRequested,
180 void ***entries, UINT32 *numEntriesReturned)
181
182 STUB(fwpuclnt, DWORD, FwpmNetEventSubscribe0, 40,
183 HANDLE engineHandle, const void *subscription, void(*callback)(),
184 void *context, HANDLE *eventsHandle)
185
186 STUB(fwpuclnt, DWORD, FwpmNetEventUnsubscribe0, 16,
187 HANDLE engineHandle, HANDLE eventsHandle)