2019-01-02 01:55:51 +01:00
|
|
|
/* SPDX-License-Identifier: MIT
|
2018-05-03 15:04:00 +02:00
|
|
|
*
|
2021-01-28 17:52:15 +01:00
|
|
|
* Copyright (C) 2017-2021 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"
|
|
|
|
|
2021-08-16 02:43:17 +02:00
|
|
|
"github.com/KusakabeSi/EtherGuardVPN/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
|
|
|
|
}
|
|
|
|
|
2019-11-07 17:13:05 +01:00
|
|
|
func (b *DummyBind) ReceiveIPv6(buff []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")
|
|
|
|
}
|
|
|
|
copy(buff, datagram.msg)
|
|
|
|
return len(datagram.msg), datagram.endpoint, nil
|
|
|
|
}
|
|
|
|
|
2019-11-07 17:13:05 +01:00
|
|
|
func (b *DummyBind) ReceiveIPv4(buff []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")
|
|
|
|
}
|
|
|
|
copy(buff, datagram.msg)
|
|
|
|
return len(datagram.msg), datagram.endpoint, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *DummyBind) Close() error {
|
|
|
|
close(b.in6)
|
|
|
|
close(b.in4)
|
|
|
|
b.closed = true
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-11-07 17:13:05 +01:00
|
|
|
func (b *DummyBind) Send(buff []byte, end conn.Endpoint) error {
|
2018-03-08 16:44:27 +01:00
|
|
|
return nil
|
|
|
|
}
|