packet

package
v0.0.0-...-ac9ef1f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Copyright [2016] [SnapRoute Inc]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

	 Unless required by applicable law or agreed to in writing, software
	 distributed under the License is distributed on an "AS IS" BASIS,
	 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	 See the License for the specific language governing permissions and
	 limitations under the License.

_______ __ __________ ___ _______.____ __ ____ __ .___________. ______ __ __ | ____|| | | ____\ \ / / / |\ \ / \ / / | | | | / || | | | | |__ | | | |__ \ V / | (----` \ \/ \/ / | | `---| |----`| ,----'| |__| | | __| | | | __| > < \ \ \ / | | | | | | | __ | | | | `----.| |____ / . \ .----) | \ /\ / | | | | | `----.| | | | |__| |_______||_______/__/ \__\ |_______/ \__/ \__/ |__| |__| \______||__| |__|

Copyright [2016] [SnapRoute Inc]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

	 Unless required by applicable law or agreed to in writing, software
	 distributed under the License is distributed on an "AS IS" BASIS,
	 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	 See the License for the specific language governing permissions and
	 limitations under the License.

_______ __ __________ ___ _______.____ __ ____ __ .___________. ______ __ __ | ____|| | | ____\ \ / / / |\ \ / \ / / | | | | / || | | | | |__ | | | |__ \ V / | (----` \ \/ \/ / | | `---| |----`| ,----'| |__| | | __| | | | __| > < \ \ \ / | | | | | | | __ | | | | `----.| |____ / . \ .----) | \ /\ / | | | | | `----.| | | | |__| |_______||_______/__/ \__\ |_______/ \__/ \__/ |__| |__| \______||__| |__|

Copyright [2016] [SnapRoute Inc]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

	 Unless required by applicable law or agreed to in writing, software
	 distributed under the License is distributed on an "AS IS" BASIS,
	 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	 See the License for the specific language governing permissions and
	 limitations under the License.

_______ __ __________ ___ _______.____ __ ____ __ .___________. ______ __ __ | ____|| | | ____\ \ / / / |\ \ / \ / / | | | | / || | | | | |__ | | | |__ \ V / | (----` \ \/ \/ / | | `---| |----`| ,----'| |__| | | __| | | | __| > < \ \ \ / | | | | | | | __ | | | | `----.| |____ / . \ .----) | \ /\ / | | | | | `----.| | | | |__| |_______||_______/__/ \__\ |_______/ \__/ \__/ |__| |__| \______||__| |__|

Copyright [2016] [SnapRoute Inc]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

	 Unless required by applicable law or agreed to in writing, software
	 distributed under the License is distributed on an "AS IS" BASIS,
	 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	 See the License for the specific language governing permissions and
	 limitations under the License.

_______ __ __________ ___ _______.____ __ ____ __ .___________. ______ __ __ | ____|| | | ____\ \ / / / |\ \ / \ / / | | | | / || | | | | |__ | | | |__ \ V / | (----` \ \/ \/ / | | `---| |----`| ,----'| |__| | | __| | | | __| > < \ \ \ / | | | | | | | __ | | | | `----.| |____ / . \ .----) | \ /\ / | | | | | `----.| | | | |__| |_______||_______/__/ \__\ |_______/ \__/ \__/ |__| |__| \______||__| |__|

Copyright [2016] [SnapRoute Inc]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

	 Unless required by applicable law or agreed to in writing, software
	 distributed under the License is distributed on an "AS IS" BASIS,
	 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	 See the License for the specific language governing permissions and
	 limitations under the License.

_______ __ __________ ___ _______.____ __ ____ __ .___________. ______ __ __ | ____|| | | ____\ \ / / / |\ \ / \ / / | | | | / || | | | | |__ | | | |__ \ V / | (----` \ \/ \/ / | | `---| |----`| ,----'| |__| | | __| | | | __| > < \ \ \ / | | | | | | | __ | | | | `----.| |____ / . \ .----) | \ /\ / | | | | | `----.| | | | |__| |_______||_______/__/ \__\ |_______/ \__/ \__/ |__| |__| \______||__| |__|

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

	 Unless required by applicable law or agreed to in writing, software
	 distributed under the License is distributed on an "AS IS" BASIS,
	 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	 See the License for the specific language governing permissions and
	 limitations under the License.

_______ __ __________ ___ _______.____ __ ____ __ .___________. ______ __ __ | ____|| | | ____\ \ / / / |\ \ / \ / / | | | | / || | | | | |__ | | | |__ \ V / | (----` \ \/ \/ / | | `---| |----`| ,----'| |__| | | __| | | | __| > < \ \ \ / | | | | | | | __ | | | | `----.| |____ / . \ .----) | \ /\ / | | | | | `----.| | | | |__| |_______||_______/__/ \__\ |_______/ \__/ \__/ |__| |__| \______||__| |__|

Copyright [2016] [SnapRoute Inc]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

	 Unless required by applicable law or agreed to in writing, software
	 distributed under the License is distributed on an "AS IS" BASIS,
	 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	 See the License for the specific language governing permissions and
	 limitations under the License.

_______ __ __________ ___ _______.____ __ ____ __ .___________. ______ __ __ | ____|| | | ____\ \ / / / |\ \ / \ / / | | | | / || | | | | |__ | | | |__ \ V / | (----` \ \/ \/ / | | `---| |----`| ,----'| |__| | | __| | | | __| > < \ \ \ / | | | | | | | __ | | | | `----.| |____ / . \ .----) | \ /\ / | | | | | `----.| | | | |__| |_______||_______/__/ \__\ |_______/ \__/ \__/ |__| |__| \______||__| |__|

Index

Constants

View Source
const (
	HOP_LIMIT                              = 255
	ICMPV6_CODE                            = 0
	ICMP_HDR_LENGTH                        = 8
	UNSPECIFIED_IP_ADDRESS                 = "::"
	IPV6_ICMPV6_MULTICAST_DST_MAC          = "33:33:00:00:00:00"
	IPV6_ADDRESS_BYTES                     = 16
	IPV6_MULTICAST_BYTE             byte   = 0xff
	IPV6_VERSION                    byte   = 6
	ICMPV6_MIN_LENGTH               uint16 = 24
	ICMPV6_NEXT_HEADER              byte   = 58
	ICMPV6_SOURCE_LINK_LAYER_LENGTH uint16 = 8
	SOLICITATED_NODE_ADDRESS               = "ff02::1:ff00:0000"
	SOLICITATED_SRC_IP                     = "::"

	// Router Advertisement Specific Constants
	ICMPV6_MIN_LENGTH_RA         uint16 = 16
	ICMPV6_MIN_PAYLOAD_LENGTH_RA        = 8
)

Variables

This section is empty.

Functions

This section is empty.

Types

type NDInfo

type NDInfo struct {
	// NS/NA Information
	TargetAddress  net.IP
	PktType        layers.ICMPv6TypeCode
	SrcMac         string
	SrcIp          string
	DstIp          string
	DstMac         string
	LearnedIntfRef string
	LearnedIfIndex int32
	// RA Information
	CurHopLimit    uint8
	ReservedFlags  uint8
	RouterLifetime uint16
	ReachableTime  uint32
	RetransTime    uint32

	// For All Types
	Options []*NDOption
}

* Struct is super set of NS/NA and RS/RA * Depending on the packet type fill in the necessary information and use it

func (*NDInfo) DecodeNDInfo

func (nd *NDInfo) DecodeNDInfo(payload []byte)

func (*NDInfo) DecodeRAInfo

func (nd *NDInfo) DecodeRAInfo(typeByte, payload []byte)

* 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Type | Code | Checksum | <------ ICMPV6 Info Start - 0 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Cur Hop Limit |M|O| Reserved | Router Lifetime | <------ ICMPV6 Ends here - 4 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Reachable Time | <------ MIN RA Info Start - 8, 0 - 4 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Retrans Timer | <------ MIN RA Info Ends - 12, 4 - 8 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Options ... * +-+-+-+-+-+-+-+-+-+-+-+- * @TODO: Handle Prefix Information Option Type

func (*NDInfo) IsTargetMulticast

func (nd *NDInfo) IsTargetMulticast() bool

* According to RFC 2375 https://tools.ietf.org/html/rfc2375 all ipv6 multicast address have first byte as * FF or 0xff, so compare that with the Target address first byte.

func (*NDInfo) ValidateNDAInfo

func (nd *NDInfo) ValidateNDAInfo(icmpFlags []byte, dstIP net.IP) error

* If the IP Destination Address is a multicast address the * Solicited flag is zero. * All included options have a length that is greater than zero.

func (*NDInfo) ValidateNDSInfo

func (nd *NDInfo) ValidateNDSInfo(srcIP net.IP, dstIP net.IP) error

* Range for Solicited Node Multicast Address from RFC 4291 FF02:0:0:0:0:1:FF00:0000 to FF02:0:0:0:0:1:FFFF:FFFF * if srcIp == "::", i.e Unspecified address then dstIP should be solicited-node address FF02:0:0:0:0:1:FFXX:XXXX * if srcIP == "::", then there should not be any source link-layer option in message

func (*NDInfo) ValidateRAInfo

func (nd *NDInfo) ValidateRAInfo() error

* Validate * - All included options have a length that is greater than zero. * * Cache below information during validation * - Source Link-Layer Address * - Prefix Information * - MTU options

type NDOption

type NDOption struct {
	Type   NDOptionType
	Length byte
	Value  []byte
}

func DecodeOptionLayer

func DecodeOptionLayer(payload []byte) *NDOption

type NDOptionType

type NDOptionType byte
const (
	NDOptionTypeSourceLinkLayerAddress NDOptionType = 1
	NDOptionTypeTargetLinkLayerAddress NDOptionType = 2
	NDOptionTypePrefixInfo             NDOptionType = 3
	NDOptionTypeRedirectHeader         NDOptionType = 4
	NDOptionTypeMTU                    NDOptionType = 5
)

type Packet

type Packet struct {
	SrcMac string
	DstMac string
	SrcIp  string
	DstIp  string
	PType  layers.ICMPv6TypeCode
}

func Init

func Init() *Packet

func (*Packet) DecodeND

func (p *Packet) DecodeND(pkt gopacket.Packet) (*NDInfo, error)

API: Get IPv6 & ICMPv6 Header * Does Validation of IPv6 * Does Validation of ICMPv6 * Validation Conditions are defined below, if anyone of them do not satisfy discard the packet: * - The IP Hop Limit field has a value of 255, i.e., the packet * could not possibly have been forwarded by a router. <- done * * - ICMP Checksum is valid. <- done * * - ICMP Code is 0. <- done * * - ICMP length (derived from the IP length) is 24 or more octets. <- done * * - Target Address is not a multicast address. <- done * * - All included options have a length that is greater than zero. <- @TODO: need to add this later * * - If the IP source address is the unspecified address, the IP * destination address is a solicited-node multicast address. <- done * * - If the IP source address is the unspecified address, there is no * source link-layer address option in the message. <- @TODO: need to be done later

func (*Packet) Encode

func (pkt *Packet) Encode() []byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL