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
|
|
|
|
2019-11-07 17:13:05 +01:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2024-01-07 20:03:11 +01:00
|
|
|
"gitea.hbanafa.com/hesham/wireguard-go/conn"
|
2019-11-07 17:13:05 +01:00
|
|
|
)
|
2018-03-08 16:44:27 +01:00
|
|
|
|
|
|
|
type DummyDatagram struct {
|
|
|
|
msg []byte
|
2019-11-07 17:13:05 +01:00
|
|
|
endpoint conn.Endpoint
|
2018-03-08 16:44:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type DummyBind struct {
|
|
|
|
in6 chan DummyDatagram
|
|
|
|
in4 chan DummyDatagram
|
|
|
|
closed bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *DummyBind) SetMark(v uint32) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-13 17:55:05 +01:00
|
|
|
func (b *DummyBind) ReceiveIPv6(buf []byte) (int, conn.Endpoint, error) {
|
2018-03-08 16:44:27 +01:00
|
|
|
datagram, ok := <-b.in6
|
|
|
|
if !ok {
|
|
|
|
return 0, nil, errors.New("closed")
|
|
|
|
}
|
2023-03-13 17:55:05 +01:00
|
|
|
copy(buf, datagram.msg)
|
2018-03-08 16:44:27 +01:00
|
|
|
return len(datagram.msg), datagram.endpoint, nil
|
|
|
|
}
|
|
|
|
|
2023-03-13 17:55:05 +01:00
|
|
|
func (b *DummyBind) ReceiveIPv4(buf []byte) (int, conn.Endpoint, error) {
|
2018-03-08 16:44:27 +01:00
|
|
|
datagram, ok := <-b.in4
|
|
|
|
if !ok {
|
|
|
|
return 0, nil, errors.New("closed")
|
|
|
|
}
|
2023-03-13 17:55:05 +01:00
|
|
|
copy(buf, datagram.msg)
|
2018-03-08 16:44:27 +01:00
|
|
|
return len(datagram.msg), datagram.endpoint, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *DummyBind) Close() error {
|
|
|
|
close(b.in6)
|
|
|
|
close(b.in4)
|
|
|
|
b.closed = true
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-13 17:55:05 +01:00
|
|
|
func (b *DummyBind) Send(buf []byte, end conn.Endpoint) error {
|
2018-03-08 16:44:27 +01:00
|
|
|
return nil
|
|
|
|
}
|