mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 00:11:36 +00:00
Split create_icmpv6 into create_icmpv6_tun and create_icmpv6_tap
This commit is contained in:
parent
d78e0f7067
commit
0bf43b758f
@ -129,7 +129,7 @@ func (i *icmpv6) parse_packet_tun(datain []byte) ([]byte, error) {
|
|||||||
response, err := i.handle_ndp(datain[ipv6.HeaderLen:])
|
response, err := i.handle_ndp(datain[ipv6.HeaderLen:])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// Create our ICMPv6 response
|
// Create our ICMPv6 response
|
||||||
responsePacket, err := i.create_icmpv6(ipv6Header.Src, ipv6.ICMPTypeNeighborAdvertisement, 0, response)
|
responsePacket, err := i.create_icmpv6_tun(ipv6Header.Src, ipv6.ICMPTypeNeighborAdvertisement, 0, response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -148,7 +148,27 @@ func (i *icmpv6) parse_packet_tun(datain []byte) ([]byte, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *icmpv6) create_icmpv6(dst net.IP, mtype ipv6.ICMPType, mcode int, mbody []byte) ([]byte, error) {
|
func (i *icmpv6) create_icmpv6_tap(dstmac macAddress, dst net.IP, mtype ipv6.ICMPType, mcode int, mbody []byte) ([]byte, error) {
|
||||||
|
// Pass through to create_icmpv6_tun
|
||||||
|
ipv6packet, err := i.create_icmpv6_tun(dst, mtype, mcode, mbody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the response buffer
|
||||||
|
dataout := make([]byte, ETHER+ipv6.HeaderLen+len(mbody))
|
||||||
|
|
||||||
|
// Populate the response ethernet headers
|
||||||
|
copy(dataout[:6], dstmac[:6])
|
||||||
|
copy(dataout[6:12], i.mymac[:])
|
||||||
|
binary.BigEndian.PutUint16(dataout[12:14], uint16(0x86DD))
|
||||||
|
|
||||||
|
// Copy the returned packet to our response ethernet frame
|
||||||
|
copy(dataout[ETHER:], ipv6packet)
|
||||||
|
return dataout, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *icmpv6) create_icmpv6_tun(dst net.IP, mtype ipv6.ICMPType, mcode int, mbody []byte) ([]byte, error) {
|
||||||
// Create the IPv6 header
|
// Create the IPv6 header
|
||||||
ipv6Header := ipv6.Header{
|
ipv6Header := ipv6.Header{
|
||||||
Version: ipv6.Version,
|
Version: ipv6.Version,
|
||||||
@ -187,6 +207,8 @@ func (i *icmpv6) create_icmpv6(dst net.IP, mtype ipv6.ICMPType, mcode int, mbody
|
|||||||
return responsePacket, nil
|
return responsePacket, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (i *icmpv6) handle_ndp(in []byte) ([]byte, error) {
|
func (i *icmpv6) handle_ndp(in []byte) ([]byte, error) {
|
||||||
// Ignore NDP requests for anything outside of fd00::/8
|
// Ignore NDP requests for anything outside of fd00::/8
|
||||||
if in[8] != 0xFD {
|
if in[8] != 0xFD {
|
||||||
|
Loading…
Reference in New Issue
Block a user