kernel-wfp: Configure ports for SAs using UDP encapsulation
[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_LOCAL_PORT = {
25 0x0c1ba1af, 0x5765, 0x453f, { 0xaf,0x22,0xa8,0xf7,0x91,0xac,0x77,0x5b }
26 };
27 const GUID FWPM_CONDITION_IP_REMOTE_PORT = {
28 0xc35a604d, 0xd22b, 0x4e1a, { 0x91,0xb4,0x68,0xf6,0x74,0xee,0x67,0x4b }
29 };
30 const GUID FWPM_CONDITION_IP_PROTOCOL = {
31 0x3971ef2b, 0x623e, 0x4f9a, { 0x8c,0xb1,0x6e,0x79,0xb8,0x06,0xb9,0xa7 }
32 };
33 const GUID FWPM_LAYER_INBOUND_TRANSPORT_V4 = {
34 0x5926dfc8, 0xe3cf, 0x4426, { 0xa2,0x83,0xdc,0x39,0x3f,0x5d,0x0f,0x9d }
35 };
36 const GUID FWPM_LAYER_OUTBOUND_TRANSPORT_V4 = {
37 0x09e61aea, 0xd214, 0x46e2, { 0x9b,0x21,0xb2,0x6b,0x0b,0x2f,0x28,0xc8 }
38 };
39 const GUID FWPM_CALLOUT_IPSEC_INBOUND_TRANSPORT_V4 = {
40 0x5132900d, 0x5e84, 0x4b5f, { 0x80,0xe4,0x01,0x74,0x1e,0x81,0xff,0x10 }
41 };
42 const GUID FWPM_CALLOUT_IPSEC_OUTBOUND_TRANSPORT_V4 = {
43 0x4b46bf0a, 0x4523, 0x4e57, { 0xaa,0x38,0xa8,0x79,0x87,0xc9,0x10,0xd9 }
44 };
45
46 /**
47 * Load a function symbol from a loaded dll
48 */
49 static inline void *load_function(char *dll, char *name)
50 {
51 HANDLE handle;
52 void *sym = NULL;
53
54 handle = GetModuleHandle(dll);
55 if (!handle)
56 {
57 return NULL;
58 }
59 sym = GetProcAddress(handle, name);
60 return sym;
61 }
62
63 /**
64 * Macro that defines a stub for a function that calls the same DLL function
65 *
66 * @param dll DLL to find function in
67 * @param ret return type of function
68 * @param name function name
69 * @param size size of all arguments on stack
70 * @param ... arguments of function
71 */
72 #define STUB(dll, ret, name, size, ...) \
73 ret WINAPI name(__VA_ARGS__) \
74 { \
75 static void (*fun)() = NULL; \
76 if (!fun) \
77 { \
78 fun = load_function(#dll, #name); \
79 } \
80 if (fun) \
81 { \
82 __builtin_return(__builtin_apply(fun, __builtin_apply_args(), size)); \
83 } \
84 return ERROR_NOT_SUPPORTED; \
85 }
86
87 STUB(fwpuclnt, DWORD, IPsecSaContextCreate1, 40,
88 HANDLE engineHandle, const void *outboundTraffic,
89 const void *virtualIfTunnelInfo, UINT64 *inboundFilterId, UINT64 *id)
90
91 STUB(fwpuclnt, DWORD, IPsecSaContextSetSpi0, 32,
92 HANDLE engineHandle, UINT64 id, const void *getSpi, UINT32 inboundSpi)