Win32 API 日本語リファレンス
ホームNetworkManagement.WindowsFilteringPlatform › IPSEC_TUNNEL_POLICY2

IPSEC_TUNNEL_POLICY2

構造体
サイズx64: 112 バイト / x86: 96 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
flagsIPSEC_POLICY_FLAG4+0+0IPsecトンネルポリシーの動作を制御するフラグ。
numIpsecProposalsDWORD4+4+4ipsecProposals配列の要素数。
ipsecProposalsIPSEC_PROPOSAL0*8/4+8+8IPsecプロポーザルの配列へのポインター。
tunnelEndpointsIPSEC_TUNNEL_ENDPOINTS272/64+16+16トンネルのローカル/リモートエンドポイント(複数アドレス対応)。
saIdleTimeoutIPSEC_SA_IDLE_TIMEOUT08+88+80SAのアイドルタイムアウト設定。
emPolicyIKEEXT_EM_POLICY2*8/4+96+88拡張モードポリシーへのポインター。NULL可。
fwdPathSaLifetimeDWORD4+104+92転送パスSAの有効期間(秒単位)。

各言語での定義

#include <windows.h>

// IPSEC_TUNNEL_ENDPOINTS2  (x64 72 / x86 64 バイト)
typedef struct IPSEC_TUNNEL_ENDPOINTS2 {
    FWP_IP_VERSION ipVersion;
    _Anonymous1_e__Union Anonymous1;
    _Anonymous2_e__Union Anonymous2;
    ULONGLONG localIfLuid;
    LPWSTR remoteFqdn;
    DWORD numAddresses;
    IPSEC_TUNNEL_ENDPOINT0* remoteAddresses;
} IPSEC_TUNNEL_ENDPOINTS2;

// IPSEC_SA_IDLE_TIMEOUT0  (x64 8 / x86 8 バイト)
typedef struct IPSEC_SA_IDLE_TIMEOUT0 {
    DWORD idleTimeoutSeconds;
    DWORD idleTimeoutSecondsFailOver;
} IPSEC_SA_IDLE_TIMEOUT0;

// IPSEC_TUNNEL_POLICY2  (x64 112 / x86 96 バイト)
typedef struct IPSEC_TUNNEL_POLICY2 {
    IPSEC_POLICY_FLAG flags;
    DWORD numIpsecProposals;
    IPSEC_PROPOSAL0* ipsecProposals;
    IPSEC_TUNNEL_ENDPOINTS2 tunnelEndpoints;
    IPSEC_SA_IDLE_TIMEOUT0 saIdleTimeout;
    IKEEXT_EM_POLICY2* emPolicy;
    DWORD fwdPathSaLifetime;
} IPSEC_TUNNEL_POLICY2;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct IPSEC_TUNNEL_ENDPOINTS2
{
    public int ipVersion;
    public _Anonymous1_e__Union Anonymous1;
    public _Anonymous2_e__Union Anonymous2;
    public ulong localIfLuid;
    public IntPtr remoteFqdn;
    public uint numAddresses;
    public IntPtr remoteAddresses;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct IPSEC_SA_IDLE_TIMEOUT0
{
    public uint idleTimeoutSeconds;
    public uint idleTimeoutSecondsFailOver;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct IPSEC_TUNNEL_POLICY2
{
    public uint flags;
    public uint numIpsecProposals;
    public IntPtr ipsecProposals;
    public IPSEC_TUNNEL_ENDPOINTS2 tunnelEndpoints;
    public IPSEC_SA_IDLE_TIMEOUT0 saIdleTimeout;
    public IntPtr emPolicy;
    public uint fwdPathSaLifetime;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure IPSEC_TUNNEL_ENDPOINTS2
    Public ipVersion As Integer
    Public Anonymous1 As _Anonymous1_e__Union
    Public Anonymous2 As _Anonymous2_e__Union
    Public localIfLuid As ULong
    Public remoteFqdn As IntPtr
    Public numAddresses As UInteger
    Public remoteAddresses As IntPtr
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure IPSEC_SA_IDLE_TIMEOUT0
    Public idleTimeoutSeconds As UInteger
    Public idleTimeoutSecondsFailOver As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure IPSEC_TUNNEL_POLICY2
    Public flags As UInteger
    Public numIpsecProposals As UInteger
    Public ipsecProposals As IntPtr
    Public tunnelEndpoints As IPSEC_TUNNEL_ENDPOINTS2
    Public saIdleTimeout As IPSEC_SA_IDLE_TIMEOUT0
    Public emPolicy As IntPtr
    Public fwdPathSaLifetime As UInteger
End Structure
import ctypes
from ctypes import wintypes

class IPSEC_TUNNEL_ENDPOINTS2(ctypes.Structure):
    _fields_ = [
        ("ipVersion", ctypes.c_int),
        ("Anonymous1", _Anonymous1_e__Union),
        ("Anonymous2", _Anonymous2_e__Union),
        ("localIfLuid", ctypes.c_ulonglong),
        ("remoteFqdn", ctypes.c_void_p),
        ("numAddresses", wintypes.DWORD),
        ("remoteAddresses", ctypes.c_void_p),
    ]

class IPSEC_SA_IDLE_TIMEOUT0(ctypes.Structure):
    _fields_ = [
        ("idleTimeoutSeconds", wintypes.DWORD),
        ("idleTimeoutSecondsFailOver", wintypes.DWORD),
    ]

class IPSEC_TUNNEL_POLICY2(ctypes.Structure):
    _fields_ = [
        ("flags", wintypes.DWORD),
        ("numIpsecProposals", wintypes.DWORD),
        ("ipsecProposals", ctypes.c_void_p),
        ("tunnelEndpoints", IPSEC_TUNNEL_ENDPOINTS2),
        ("saIdleTimeout", IPSEC_SA_IDLE_TIMEOUT0),
        ("emPolicy", ctypes.c_void_p),
        ("fwdPathSaLifetime", wintypes.DWORD),
    ]
#[repr(C)]
pub struct IPSEC_TUNNEL_ENDPOINTS2 {
    pub ipVersion: i32,
    pub Anonymous1: _Anonymous1_e__Union,
    pub Anonymous2: _Anonymous2_e__Union,
    pub localIfLuid: u64,
    pub remoteFqdn: *mut core::ffi::c_void,
    pub numAddresses: u32,
    pub remoteAddresses: *mut core::ffi::c_void,
}

#[repr(C)]
pub struct IPSEC_SA_IDLE_TIMEOUT0 {
    pub idleTimeoutSeconds: u32,
    pub idleTimeoutSecondsFailOver: u32,
}

#[repr(C)]
pub struct IPSEC_TUNNEL_POLICY2 {
    pub flags: u32,
    pub numIpsecProposals: u32,
    pub ipsecProposals: *mut core::ffi::c_void,
    pub tunnelEndpoints: IPSEC_TUNNEL_ENDPOINTS2,
    pub saIdleTimeout: IPSEC_SA_IDLE_TIMEOUT0,
    pub emPolicy: *mut core::ffi::c_void,
    pub fwdPathSaLifetime: u32,
}
import "golang.org/x/sys/windows"

type IPSEC_TUNNEL_ENDPOINTS2 struct {
	ipVersion int32
	Anonymous1 _Anonymous1_e__Union
	Anonymous2 _Anonymous2_e__Union
	localIfLuid uint64
	remoteFqdn uintptr
	numAddresses uint32
	remoteAddresses uintptr
}

type IPSEC_SA_IDLE_TIMEOUT0 struct {
	idleTimeoutSeconds uint32
	idleTimeoutSecondsFailOver uint32
}

type IPSEC_TUNNEL_POLICY2 struct {
	flags uint32
	numIpsecProposals uint32
	ipsecProposals uintptr
	tunnelEndpoints IPSEC_TUNNEL_ENDPOINTS2
	saIdleTimeout IPSEC_SA_IDLE_TIMEOUT0
	emPolicy uintptr
	fwdPathSaLifetime uint32
}
type
  IPSEC_TUNNEL_ENDPOINTS2 = record
    ipVersion: Integer;
    Anonymous1: _Anonymous1_e__Union;
    Anonymous2: _Anonymous2_e__Union;
    localIfLuid: UInt64;
    remoteFqdn: Pointer;
    numAddresses: DWORD;
    remoteAddresses: Pointer;
  end;

  IPSEC_SA_IDLE_TIMEOUT0 = record
    idleTimeoutSeconds: DWORD;
    idleTimeoutSecondsFailOver: DWORD;
  end;

  IPSEC_TUNNEL_POLICY2 = record
    flags: DWORD;
    numIpsecProposals: DWORD;
    ipsecProposals: Pointer;
    tunnelEndpoints: IPSEC_TUNNEL_ENDPOINTS2;
    saIdleTimeout: IPSEC_SA_IDLE_TIMEOUT0;
    emPolicy: Pointer;
    fwdPathSaLifetime: DWORD;
  end;
const IPSEC_TUNNEL_ENDPOINTS2 = extern struct {
    ipVersion: i32,
    Anonymous1: _Anonymous1_e__Union,
    Anonymous2: _Anonymous2_e__Union,
    localIfLuid: u64,
    remoteFqdn: ?*anyopaque,
    numAddresses: u32,
    remoteAddresses: ?*anyopaque,
};

const IPSEC_SA_IDLE_TIMEOUT0 = extern struct {
    idleTimeoutSeconds: u32,
    idleTimeoutSecondsFailOver: u32,
};

const IPSEC_TUNNEL_POLICY2 = extern struct {
    flags: u32,
    numIpsecProposals: u32,
    ipsecProposals: ?*anyopaque,
    tunnelEndpoints: IPSEC_TUNNEL_ENDPOINTS2,
    saIdleTimeout: IPSEC_SA_IDLE_TIMEOUT0,
    emPolicy: ?*anyopaque,
    fwdPathSaLifetime: u32,
};
type
  IPSEC_TUNNEL_ENDPOINTS2 {.bycopy.} = object
    ipVersion: int32
    Anonymous1: _Anonymous1_e__Union
    Anonymous2: _Anonymous2_e__Union
    localIfLuid: uint64
    remoteFqdn: pointer
    numAddresses: uint32
    remoteAddresses: pointer

  IPSEC_SA_IDLE_TIMEOUT0 {.bycopy.} = object
    idleTimeoutSeconds: uint32
    idleTimeoutSecondsFailOver: uint32

  IPSEC_TUNNEL_POLICY2 {.bycopy.} = object
    flags: uint32
    numIpsecProposals: uint32
    ipsecProposals: pointer
    tunnelEndpoints: IPSEC_TUNNEL_ENDPOINTS2
    saIdleTimeout: IPSEC_SA_IDLE_TIMEOUT0
    emPolicy: pointer
    fwdPathSaLifetime: uint32
struct IPSEC_TUNNEL_ENDPOINTS2
{
    int ipVersion;
    _Anonymous1_e__Union Anonymous1;
    _Anonymous2_e__Union Anonymous2;
    ulong localIfLuid;
    void* remoteFqdn;
    uint numAddresses;
    void* remoteAddresses;
}

struct IPSEC_SA_IDLE_TIMEOUT0
{
    uint idleTimeoutSeconds;
    uint idleTimeoutSecondsFailOver;
}

struct IPSEC_TUNNEL_POLICY2
{
    uint flags;
    uint numIpsecProposals;
    void* ipsecProposals;
    IPSEC_TUNNEL_ENDPOINTS2 tunnelEndpoints;
    IPSEC_SA_IDLE_TIMEOUT0 saIdleTimeout;
    void* emPolicy;
    uint fwdPathSaLifetime;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; IPSEC_TUNNEL_POLICY2 サイズ: 96 バイト(x86)
dim st, 24    ; 4byte整数×24(構造体サイズ 96 / 4 切り上げ)
; flags : IPSEC_POLICY_FLAG (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; numIpsecProposals : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; ipsecProposals : IPSEC_PROPOSAL0* (+8, 4byte)  varptr(st)+8 を基点に操作(4byte:入れ子/配列)
; tunnelEndpoints : IPSEC_TUNNEL_ENDPOINTS2 (+16, 64byte)  varptr(st)+16 を基点に操作(64byte:入れ子/配列)
; saIdleTimeout : IPSEC_SA_IDLE_TIMEOUT0 (+80, 8byte)  varptr(st)+80 を基点に操作(8byte:入れ子/配列)
; emPolicy : IKEEXT_EM_POLICY2* (+88, 4byte)  varptr(st)+88 を基点に操作(4byte:入れ子/配列)
; fwdPathSaLifetime : DWORD (+92, 4byte)  st.23 = 値  /  値 = st.23   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; IPSEC_TUNNEL_POLICY2 サイズ: 112 バイト(x64)
dim st, 28    ; 4byte整数×28(構造体サイズ 112 / 4 切り上げ)
; flags : IPSEC_POLICY_FLAG (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; numIpsecProposals : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; ipsecProposals : IPSEC_PROPOSAL0* (+8, 8byte)  varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; tunnelEndpoints : IPSEC_TUNNEL_ENDPOINTS2 (+16, 72byte)  varptr(st)+16 を基点に操作(72byte:入れ子/配列)
; saIdleTimeout : IPSEC_SA_IDLE_TIMEOUT0 (+88, 8byte)  varptr(st)+88 を基点に操作(8byte:入れ子/配列)
; emPolicy : IKEEXT_EM_POLICY2* (+96, 8byte)  varptr(st)+96 を基点に操作(8byte:入れ子/配列)
; fwdPathSaLifetime : DWORD (+104, 4byte)  st.26 = 値  /  値 = st.26   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global IPSEC_TUNNEL_ENDPOINTS2
    #field int ipVersion
    #field byte Anonymous1 16
    #field byte Anonymous2 16
    #field int64 localIfLuid
    #field intptr remoteFqdn
    #field int numAddresses
    #field intptr remoteAddresses
#endstruct

#defstruct global IPSEC_SA_IDLE_TIMEOUT0
    #field int idleTimeoutSeconds
    #field int idleTimeoutSecondsFailOver
#endstruct

#defstruct global IPSEC_TUNNEL_POLICY2
    #field int flags
    #field int numIpsecProposals
    #field intptr ipsecProposals
    #field IPSEC_TUNNEL_ENDPOINTS2 tunnelEndpoints
    #field IPSEC_SA_IDLE_TIMEOUT0 saIdleTimeout
    #field intptr emPolicy
    #field int fwdPathSaLifetime
#endstruct

stdim st, IPSEC_TUNNEL_POLICY2        ; NSTRUCT 変数を確保
st->flags = 100
mes "flags=" + st->flags