//
// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 Yokogawa Electric Corporation.
// All rights reserved.
// 
// Redistribution and use of this software in source and binary
// forms, with or without modification, are permitted provided that
// the following conditions and disclaimer are agreed and accepted
// by the user:
// 
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in
//    the documentation and/or other materials provided with
//    the distribution.
// 
// 3. Neither the names of the copyrighters, the name of the project
//    which is related to this software (hereinafter referred to as
//    "project") nor the names of the contributors may be used to
//    endorse or promote products derived from this software without
//    specific prior written permission.
// 
// 4. No merchantable use may be permitted without prior written
//    notification to the copyrighters.
// 
// 5. The copyrighters, the project and the contributors may prohibit
//    the use of this software at any time.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHTERS, THE PROJECT AND
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING
// BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.  IN NO EVENT SHALL THE
// COPYRIGHTERS, THE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 Yokogawa Electric Corporation.
// All rights reserved.
// 
// Redistribution and use of this software in source and binary
// forms, with or without modification, are permitted provided that
// the following conditions and disclaimer are agreed and accepted
// by the user:
// 
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in
//    the documentation and/or other materials provided with
//    the distribution.
// 
// 3. Neither the names of the copyrighters, the name of the project
//    which is related to this software (hereinafter referred to as
//    "project") nor the names of the contributors may be used to
//    endorse or promote products derived from this software without
//    specific prior written permission.
// 
// 4. No merchantable use may be permitted without prior written
//    notification to the copyrighters.
// 
// 5. The copyrighters, the project and the contributors may prohibit
//    the use of this software at any time.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHTERS, THE PROJECT AND
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING
// BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.  IN NO EVENT SHALL THE
// COPYRIGHTERS, THE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// $TAHI: ct/icmp/Pkt_Too_Big.def,v 1.5 2004/04/02 02:04:02 akisada Exp $

#include "icmp.def"

//----------------------------------------------------------------------
// addresses
//----------------------------------------------------------------------
#define PTB_OFFLINK_ADDR v6merge(_GLOBAL8_UCAST_PRFX, _GLOBAL8_UCAST_PRFXLEN, v6("::1"))
#define NUT_GLOBAL_LINK1 v6merge(_GLOBAL1_UCAST_PRFX, _GLOBAL1_UCAST_PRFXLEN, nutv6("Link1"))

//----------------------------------------------------------------------
// define packets
//----------------------------------------------------------------------

//----------------------------------------------------------------------
// Echo Request & Reply
//----------------------------------------------------------------------
_HETHER_define(HETHER_tn2nut_link1, tnether("Link1"), nutether("Link1"))
_HETHER_define(HETHER_nut2tn_link1, nutether("Link1"), tnether("Link1"))

//----------------------------------------------------------------------
// Echo Request
// Link-local address (link1)
//----------------------------------------------------------------------

FEM_icmp6_echo_request (
	echo_request_local_link1,
	HETHER_tn2nut_link1,
	{
		_SRC(tnv6("Link1"));
		_DST(nutv6("Link1"));
	},
	{
		payload = ping_data;
	}
)

//----------------------------------------------------------------------
// Echo Reply
// Link-local address (link1)
//----------------------------------------------------------------------

FEM_icmp6_echo_reply (
	echo_reply_local_link1,
	HETHER_nut2tn_link1,
	{
		_SRC(nutv6("Link1"));
		_DST(tnv6("Link1"));
	},
	{
		payload = ping_data;
	}
)

//----------------------------------------------------------------------
// Echo request
// TN --> offlink host (link0 side)
//----------------------------------------------------------------------

FEM_icmp6_echo_request (
	echo_request_fwd_link0,
	_HETHER_tn2nut,
	{
		_SRC(TN_GLOBAL);
		_DST(PTB_OFFLINK_ADDR);
		HopLimit = 64;
	},
	{
		payload = ping_data;
	}
)

//----------------------------------------------------------------------
// Echo request
// TN --> offlink host (link1 side)
//----------------------------------------------------------------------

FEM_icmp6_echo_request (
	echo_request_fwd_link1,
	HETHER_nut2tn_link1,
	{
		_SRC(TN_GLOBAL);
		_DST(PTB_OFFLINK_ADDR);
		HopLimit = 63;
	},
	{
		payload = ping_data;
	}
)

//----------------------------------------------------------------------
// Echo reply
// TN <-- offlink host (link0 side)
//----------------------------------------------------------------------

FEM_icmp6_echo_reply (
	echo_reply_fwd_link0,
	_HETHER_nut2tn,
	{
		_SRC(PTB_OFFLINK_ADDR);
		_DST(TN_GLOBAL);
		HopLimit = 63;
	},
	{
		payload = ping_data;
	}
)

//----------------------------------------------------------------------
// Echo reply
// TN <-- offlink host (link1 side)
//----------------------------------------------------------------------

FEM_icmp6_echo_reply (
	echo_reply_fwd_link1,
	HETHER_tn2nut_link1,
	{
		_SRC(PTB_OFFLINK_ADDR);
		_DST(TN_GLOBAL);
		HopLimit = 64;
	},
	{
		payload = ping_data;
	}
)

//----------------------------------------------------------------------
// Echo request
// TN --> offlink host w/ 1500 byte (link0 side)
//----------------------------------------------------------------------

FEM_icmp6_echo_request (
	echo_request_1500_link0,
	_HETHER_tn2nut,
	{
		_SRC(TN_GLOBAL);
		_DST(PTB_OFFLINK_ADDR);
		HopLimit = 64;
	},
	{
		payload = ping_data_1452;
	}
)

//----------------------------------------------------------------------
// Echo request
// TN --> offlink host (link1 side)
//----------------------------------------------------------------------

FEM_icmp6_echo_request (
	echo_request_1500_link1,
	HETHER_nut2tn_link1,
	{
		_SRC(TN_GLOBAL);
		_DST(PTB_OFFLINK_ADDR);
		HopLimit = 63;
	},
	{
		payload = ping_data_1452;
	}
)

//----------------------------------------------------------------------
// payload
//----------------------------------------------------------------------

Payload ping_data_1452 {
	data = repeat(0xff, 1452);
}

//----------------------------------------------------------------------
// Packet Too Big Message
//----------------------------------------------------------------------

FEM_icmp6_packet_too_big (
	pkt_too_big_link0,
	_HETHER_nut2tn,
	{
		_SRC(oneof(NUT_GLOBAL, NUT_GLOBAL_LINK1));
		_DST(TN_GLOBAL);
	},
	{
		MTU = 1300;
//		payload = err_link0;
		payload = any;
	}
)

FEM_icmp6_packet_too_big (
	pkt_too_big_link0_any,
	_HETHER_nut2tn,
	{
		_SRC(oneof(NUT_GLOBAL, NUT_GLOBAL_LINK1));
		_DST(TN_GLOBAL);
	},
	{
		MTU = 1300;
		payload = any;
	}
)

Payload err_link0 {
	data = left(_PACKET_IPV6_NAME(echo_request_1500_link0), 1232);
}

FEM_icmp6_packet_too_big (
	pkt_too_big_link1,
	_HETHER_nut2tn,
	{
		_SRC(oneof(NUT_GLOBAL, NUT_GLOBAL_LINK1));
		_DST(TN_GLOBAL);
	},
	{
		MTU = 1300;
//		payload = err_link1;
		payload = any;
	}
)

FEM_icmp6_packet_too_big (
	pkt_too_big_link1_any,
	_HETHER_nut2tn,
	{
		_SRC(oneof(NUT_GLOBAL, NUT_GLOBAL_LINK1));
		_DST(TN_GLOBAL);
	},
	{
		MTU = 1300;
		payload = any;
	}
)

Payload err_link1 {
	data = left(_PACKET_IPV6_NAME(echo_request_1500_link1), 1232);
}
//----------------------------------------------------------------------
// Neighbor Solicitation Messages
//----------------------------------------------------------------------
_HETHER_define(HETHER_nut2tn_oneof_link1, nutether("Link1"), oneof(tnether("Link1"), _ETHER_SOLNODE_MCAST(tnv6("Link1"))))

_SLLOPT_define(SLLOPT_nut_link1, nutether("Link1"))

//----------------------------------------------------------------------
// TN <-- NUT (link local address)
// TargetAddress: TN's link local address of link1
// Option: Source link layer address
//----------------------------------------------------------------------

FEM_icmp6_ns (
	ns_local_sll_link1,
	HETHER_nut2tn_oneof,
	{
		_SRC(oneof(nutv6("Link1"), NUT_GLOBAL_LINK1));
		_DST(oneof(_IPV6_SOLNODE_MCAST(tnv6("Link1")), tnv6("Link1")));
		HopLimit = 255;
	},
	{
		TargetAddress = tnv6("Link1");
		option = SLLOPT_nut_link1;
	}
)

//----------------------------------------------------------------------
// TN <-- NUT (link local address)
// TargetAddress: TN's link local address of link1
// Option: none
//----------------------------------------------------------------------

FEM_icmp6_ns (
	ns_local_link1,
	HETHER_nut2tn_oneof,
	{
		_SRC(oneof(nutv6("Link1"), NUT_GLOBAL_LINK1));
		_DST(oneof(_IPV6_SOLNODE_MCAST(tnv6("Link1")), tnv6("Link1")));
		HopLimit = 255;
	},
	{
		TargetAddress = tnv6("Link1");
	}
)

//----------------------------------------------------------------------
// Neighbor Advertisement Messages
//----------------------------------------------------------------------
_TLLOPT_define(TLLOPT_tn_link1, tnether("Link1"))

//----------------------------------------------------------------------
// TN --> NUT (link local address)
// TargetAddress: TN's link local address of link1
//----------------------------------------------------------------------

FEM_icmp6_na (
	na_local_link1,
	HETHER_tn2nut_link1,
	{
		_SRC(tnv6("Link1"));
		_DST(nutv6("Link1"));
		HopLimit = 255;
	},
	{
		RFlag = 1;
		SFlag = 1;
		OFlag = 1;
		TargetAddress = tnv6("Link1");
		option = TLLOPT_tn_link1;
	}
)
