2019-01-02 01:55:51 +01:00
|
|
|
/* SPDX-License-Identifier: MIT
|
2018-05-03 15:04:00 +02:00
|
|
|
*
|
2022-09-20 17:21:32 +02:00
|
|
|
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
|
2018-05-03 15:04:00 +02:00
|
|
|
*/
|
|
|
|
|
2019-03-03 04:04:41 +01:00
|
|
|
package device
|
2018-03-08 16:44:27 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
2022-03-17 00:09:48 +01:00
|
|
|
"net/netip"
|
2018-03-08 16:44:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type DummyEndpoint struct {
|
2021-11-05 01:52:54 +01:00
|
|
|
src, dst netip.Addr
|
2018-03-08 16:44:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func CreateDummyEndpoint() (*DummyEndpoint, error) {
|
2021-11-05 01:52:54 +01:00
|
|
|
var src, dst [16]byte
|
|
|
|
if _, err := rand.Read(src[:]); err != nil {
|
2018-03-08 16:44:27 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-05 01:52:54 +01:00
|
|
|
_, err := rand.Read(dst[:])
|
|
|
|
return &DummyEndpoint{netip.AddrFrom16(src), netip.AddrFrom16(dst)}, err
|
2018-03-08 16:44:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) ClearSrc() {}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) SrcToString() string {
|
2021-11-05 01:52:54 +01:00
|
|
|
return netip.AddrPortFrom(e.SrcIP(), 1000).String()
|
2018-03-08 16:44:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *DummyEndpoint) DstToString() string {
|
2021-11-05 01:52:54 +01:00
|
|
|
return netip.AddrPortFrom(e.DstIP(), 1000).String()
|
2018-03-08 16:44:27 +01:00
|
|
|
}
|
|
|
|
|
2021-11-05 01:52:54 +01: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 16:44:27 +01:00
|
|
|
}
|
|
|
|
|
2021-11-05 01:52:54 +01:00
|
|
|
func (e *DummyEndpoint) DstIP() netip.Addr {
|
|
|
|
return e.dst
|
2018-03-08 16:44:27 +01:00
|
|
|
}
|
|
|
|
|
2021-11-05 01:52:54 +01:00
|
|
|
func (e *DummyEndpoint) SrcIP() netip.Addr {
|
|
|
|
return e.src
|
2018-03-08 16:44:27 +01:00
|
|
|
}
|