2019-01-02 00:55:51 +00:00
|
|
|
/* SPDX-License-Identifier: MIT
|
2018-05-03 13:04:00 +00:00
|
|
|
*
|
2020-05-02 08:08:26 +00:00
|
|
|
* Copyright (C) 2017-2020 WireGuard LLC. All Rights Reserved.
|
2018-05-03 13:04:00 +00:00
|
|
|
*/
|
|
|
|
|
2019-03-03 03:04:41 +00:00
|
|
|
package device
|
2018-03-08 15:44:27 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DummyEndpoint struct {
|
|
|
|
src [16]byte
|
|
|
|
dst [16]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateDummyEndpoint() (*DummyEndpoint, error) {
|
|
|
|
var end DummyEndpoint
|
|
|
|
if _, err := rand.Read(end.src[:]); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
_, err := rand.Read(end.dst[:])
|
|
|
|
return &end, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) ClearSrc() {}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) SrcToString() string {
|
|
|
|
var addr net.UDPAddr
|
|
|
|
addr.IP = e.SrcIP()
|
|
|
|
addr.Port = 1000
|
|
|
|
return addr.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) DstToString() string {
|
|
|
|
var addr net.UDPAddr
|
|
|
|
addr.IP = e.DstIP()
|
|
|
|
addr.Port = 1000
|
|
|
|
return addr.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) SrcToBytes() []byte {
|
|
|
|
return e.src[:]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) DstIP() net.IP {
|
|
|
|
return e.dst[:]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) SrcIP() net.IP {
|
|
|
|
return e.src[:]
|
|
|
|
}
|