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
|
|
|
|
2019-11-07 16:13:05 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"golang.zx2c4.com/wireguard/conn"
|
|
|
|
)
|
2018-03-08 15:44:27 +00:00
|
|
|
|
|
|
|
type DummyDatagram struct {
|
|
|
|
msg []byte
|
2019-11-07 16:13:05 +00:00
|
|
|
endpoint conn.Endpoint
|
2018-03-08 15:44:27 +00:00
|
|
|
world bool // better type
|
|
|
|
}
|
|
|
|
|
|
|
|
type DummyBind struct {
|
|
|
|
in6 chan DummyDatagram
|
|
|
|
ou6 chan DummyDatagram
|
|
|
|
in4 chan DummyDatagram
|
|
|
|
ou4 chan DummyDatagram
|
|
|
|
closed bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *DummyBind) SetMark(v uint32) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-11-07 16:13:05 +00:00
|
|
|
func (b *DummyBind) ReceiveIPv6(buff []byte) (int, conn.Endpoint, error) {
|
2018-03-08 15:44:27 +00: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 16:13:05 +00:00
|
|
|
func (b *DummyBind) ReceiveIPv4(buff []byte) (int, conn.Endpoint, error) {
|
2018-03-08 15:44:27 +00: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 16:13:05 +00:00
|
|
|
func (b *DummyBind) Send(buff []byte, end conn.Endpoint) error {
|
2018-03-08 15:44:27 +00:00
|
|
|
return nil
|
|
|
|
}
|