diff --git a/src/yggdrasil/icmpv6.go b/src/yggdrasil/icmpv6.go index 5d014bdb..56d33437 100644 --- a/src/yggdrasil/icmpv6.go +++ b/src/yggdrasil/icmpv6.go @@ -129,7 +129,7 @@ func (i *icmpv6) parse_packet_tun(datain []byte) ([]byte, error) { response, err := i.handle_ndp(datain[ipv6.HeaderLen:]) if err == nil { // 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 { return nil, err } @@ -148,7 +148,27 @@ func (i *icmpv6) parse_packet_tun(datain []byte) ([]byte, error) { 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 ipv6Header := ipv6.Header{ Version: ipv6.Version, @@ -187,6 +207,8 @@ func (i *icmpv6) create_icmpv6(dst net.IP, mtype ipv6.ICMPType, mcode int, mbody return responsePacket, nil } + + func (i *icmpv6) handle_ndp(in []byte) ([]byte, error) { // Ignore NDP requests for anything outside of fd00::/8 if in[8] != 0xFD {