1c91307af2622f6625525f3c1f9c954376df950adChia-chi Yeh/* $NetBSD: nattraversal.h,v 1.6 2006/09/09 16:22:09 manu Exp $ */ 20a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 30a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang/* 40a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * Copyright (C) 2004 SuSE Linux AG, Nuernberg, Germany. 50a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * Contributed by: Michal Ludvig <mludvig@suse.cz>, SUSE Labs 60a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * All rights reserved. 70a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * 80a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * Redistribution and use in source and binary forms, with or without 90a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * modification, are permitted provided that the following conditions 100a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * are met: 110a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * 1. Redistributions of source code must retain the above copyright 120a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * notice, this list of conditions and the following disclaimer. 130a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * 2. Redistributions in binary form must reproduce the above copyright 140a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * notice, this list of conditions and the following disclaimer in the 150a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * documentation and/or other materials provided with the distribution. 160a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * 3. Neither the name of the project nor the names of its contributors 170a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * may be used to endorse or promote products derived from this software 180a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * without specific prior written permission. 190a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * 200a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 210a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 220a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 230a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 240a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 250a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 260a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 270a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 280a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 290a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 300a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang * SUCH DAMAGE. 310a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang */ 320a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 330a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#ifndef _NATTRAVERSAL_H 340a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define _NATTRAVERSAL_H 350a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 360a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#include "vendorid.h" 370a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 380a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NAT_ANNOUNCED (1L<<0) 390a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NAT_DETECTED_ME (1L<<1) 400a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NAT_DETECTED_PEER (1L<<2) 410a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NAT_PORTS_CHANGED (1L<<3) 420a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NAT_KA_QUEUED (1L<<4) 430a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NAT_ADD_NON_ESP_MARKER (1L<<5) 440a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 45c91307af2622f6625525f3c1f9c954376df950adChia-chi Yeh#define NATT_AVAILABLE(ph1) ((iph1)->natt_flags & NAT_ANNOUNCED) 460a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 470a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NAT_DETECTED (NAT_DETECTED_ME | NAT_DETECTED_PEER) 480a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 490a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NON_ESP_MARKER_LEN sizeof(u_int32_t) 50c91307af2622f6625525f3c1f9c954376df950adChia-chi Yeh#define NON_ESP_MARKER_USE(iph1) ((iph1)->natt_flags & NAT_ADD_NON_ESP_MARKER) 510a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 520a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang/* These are the values from parsing "remote {}" 530a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang block of the config file. */ 540a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NATT_OFF FLASE /* = 0 */ 550a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NATT_ON TRUE /* = 1 */ 560a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#define NATT_FORCE 2 570a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 580a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangstruct ph1natt_options { 590a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang int version; 600a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int16_t float_port; 610a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int16_t mode_udp_tunnel; 620a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int16_t mode_udp_transport; 630a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int16_t encaps_type; /* ESPINUDP / ESPINUDP_NON_IKE */ 640a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int16_t mode_udp_diff; 650a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int16_t payload_nat_d; 660a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int16_t payload_nat_oa; 670a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang}; 680a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 690a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangstruct ph2natt { 700a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int8_t type; 710a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int16_t sport; 720a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int16_t dport; 730a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang struct sockaddr *oa; 740a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang u_int16_t frag; 750a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang}; 760a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 770a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangint natt_vendorid (int vid); 780a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangvchar_t *natt_hash_addr (struct ph1handle *iph1, struct sockaddr *addr); 790a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangint natt_compare_addr_hash (struct ph1handle *iph1, vchar_t *natd_received, int natd_seq); 800a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangint natt_udp_encap (int encmode); 810a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangint natt_fill_options (struct ph1natt_options *opts, int version); 820a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangvoid natt_float_ports (struct ph1handle *iph1); 830a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangvoid natt_handle_vendorid (struct ph1handle *iph1, int vid_numeric); 840a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 850a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 860a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangstruct payload_list * 870a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangisakmp_plist_append_natt_vids (struct payload_list *plist, vchar_t *vid_natt[MAX_NATT_VID_COUNT]); 880a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 890a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 900a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang/* NAT keepalive functions */ 910a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangvoid natt_keepalive_init (void); 920a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangint natt_keepalive_add (struct sockaddr *src, struct sockaddr *dst); 930a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangint natt_keepalive_add_ph1 (struct ph1handle *iph1); 940a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangvoid natt_keepalive_remove (struct sockaddr *src, struct sockaddr *dst); 950a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 960a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang/* Walk through all rmconfigs and tell if NAT-T is enabled in at least one. */ 970a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wangint natt_enabled_in_rmconf (void); 980a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang 990a1907d434839af6a9cb6329bbde60b237bf53dcChung-yih Wang#endif /* _NATTRAVERSAL_H */ 100