2019-01-02 00:55:51 +00:00
|
|
|
/* SPDX-License-Identifier: MIT
|
2018-05-03 13:04:00 +00:00
|
|
|
*
|
2021-01-28 16:52:15 +00:00
|
|
|
* Copyright (C) 2017-2021 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"
|
2021-11-05 00:52:54 +00:00
|
|
|
|
|
|
|
"golang.zx2c4.com/go118/netip"
|
2018-03-08 15:44:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type DummyEndpoint struct {
|
2021-11-05 00:52:54 +00:00
|
|
|
src, dst netip.Addr
|
2018-03-08 15:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func CreateDummyEndpoint() (*DummyEndpoint, error) {
|
2021-11-05 00:52:54 +00:00
|
|
|
var src, dst [16]byte
|
|
|
|
if _, err := rand.Read(src[:]); err != nil {
|
2018-03-08 15:44:27 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-05 00:52:54 +00:00
|
|
|
_, err := rand.Read(dst[:])
|
|
|
|
return &DummyEndpoint{netip.AddrFrom16(src), netip.AddrFrom16(dst)}, err
|
2018-03-08 15:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) ClearSrc() {}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) SrcToString() string {
|
2021-11-05 00:52:54 +00:00
|
|
|
return netip.AddrPortFrom(e.SrcIP(), 1000).String()
|
2018-03-08 15:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) DstToString() string {
|
2021-11-05 00:52:54 +00:00
|
|
|
return netip.AddrPortFrom(e.DstIP(), 1000).String()
|
2018-03-08 15:44:27 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 00:52:54 +00:00
|
|
|
func (e *DummyEndpoint) DstToBytes() []byte {
|
|
|
|
out := e.DstIP().AsSlice()
|
|
|
|
out = append(out, byte(1000&0xff))
|
|
|
|
out = append(out, byte((1000>>8)&0xff))
|
|
|
|
return out
|
2018-03-08 15:44:27 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 00:52:54 +00:00
|
|
|
func (e *DummyEndpoint) DstIP() netip.Addr {
|
|
|
|
return e.dst
|
2018-03-08 15:44:27 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 00:52:54 +00:00
|
|
|
func (e *DummyEndpoint) SrcIP() netip.Addr {
|
|
|
|
return e.src
|
2018-03-08 15:44:27 +00:00
|
|
|
}
|