package vnet

Import Path
	github.com/pion/transport/v3/vnet (on go.dev)

Dependency Relation
	imports 15 packages, and imported by one package


Package-Level Type Names (total 16)
/* sort by: | */
Chunk represents a packet passed around in the vnet ( Chunk) Clone() Chunk ( Chunk) DestinationAddr() net.Addr // returns "udp" or "tcp" ( Chunk) SourceAddr() net.Addr ( Chunk) String() string ( Chunk) Tag() string ( Chunk) UserData() []byte Chunk : expvar.Var Chunk : fmt.Stringer Chunk : net.Addr func Chunk.Clone() Chunk
ChunkFilter is a handler users can add to filter chunks. If the filter returns false, the packet will be dropped. func (*Router).AddChunkFilter(filter ChunkFilter)
DelayFilter delays outgoing packets by the given delay. Run must be called before any packets will be forwarded. NIC NIC Run starts forwarding of packets. Packets will be forwarded if they spent >delay time in the internal queue. Must be called before any packet will be forwarded. *DelayFilter : NIC func NewDelayFilter(nic NIC, delay time.Duration) (*DelayFilter, error)
EndpointDependencyType defines a type of behavioral dependendency on the remote endpoint's IP address or port number. This is used for the two kinds of behaviors: - Port mapping behavior - Filtering behavior See: https://tools.ietf.org/html/rfc4787 const EndpointAddrDependent const EndpointAddrPortDependent const EndpointIndependent
LossFilter is a wrapper around NICs, that drops some of the packets passed to onInboundChunk NIC NIC *LossFilter : NIC func NewLossFilter(nic NIC, chance int) (*LossFilter, error)
NATMode defines basic behavior of the NAT const NATModeNAT1To1 const NATModeNormal
NATType has a set of parameters that define the behavior of NAT. FilteringBehavior EndpointDependencyType // Not implemented yet MappingBehavior EndpointDependencyType MappingLifeTime time.Duration Mode NATMode // Not implemented yet
Net represents a local network stack equivalent to a set of layers from NIC up to the transport (UDP / TCP) layer. CreateDialer creates an instance of vnet.Dialer Dial connects to the address on the named network. DialTCP acts like Dial for TCP networks. DialUDP acts like Dial for UDP networks. InterfaceByIndex returns the interface specified by index. On Solaris, it returns one of the logical network interfaces sharing the logical data link; for more precision use InterfaceByName. InterfaceByName returns the interface specified by name. Interfaces returns a list of the system's network interfaces. ListenPacket announces on the local network address. ListenTCP acts like Listen for TCP networks. ListenUDP acts like ListenPacket for UDP networks. ResolveIPAddr returns an address of IP end point. ResolveTCPAddr returns an address of TCP end point. ResolveUDPAddr returns an address of UDP end point. *Net : NIC *Net : github.com/pion/transport/v3.Dialer *Net : github.com/pion/transport/v3.Net *Net : github.com/pion/transport/v2.Dialer *Net : github.com/nats-io/nats.go.CustomDialer *Net : golang.org/x/net/proxy.Dialer func NewNet(config *NetConfig) (*Net, error) func (*UDPProxy).Proxy(client *Net, server *net.UDPAddr) error
NetConfig is a bag of configuration parameters passed to NewNet(). StaticIP is deprecated. Use StaticIPs. StaticIPs is an array of static IP addresses to be assigned for this Net. If no static IP address is given, the router will automatically assign an IP address. func NewNet(config *NetConfig) (*Net, error)
NIC is a network interface controller that interfaces Router *DelayFilter *LossFilter *Net *Router *TokenBucketFilter func NewDelayFilter(nic NIC, delay time.Duration) (*DelayFilter, error) func NewLossFilter(nic NIC, chance int) (*LossFilter, error) func NewTokenBucketFilter(n NIC, opts ...TBFOption) (*TokenBucketFilter, error) func (*Router).AddNet(nic NIC) error
Router ... AddChildRouter is like AddRouter, but does not add the child routers NIC to the parent. This has to be done manually by calling AddNet, which allows to use a wrapper around the subrouters NIC. AddNet MUST be called before AddChildRouter. AddChunkFilter adds a filter for chunks traversing this router. You may add more than one filter. The filters are called in the order of this method call. If a chunk is dropped by a filter, subsequent filter will not receive the chunk. AddHost adds a mapping of hostname and an IP address to the local resolver. AddNet ... AddRouter adds a child Router. Start ... Stop ... *Router : NIC func NewRouter(config *RouterConfig) (*Router, error) func NewProxy(router *Router) (*UDPProxy, error) func (*Router).AddChildRouter(router *Router) error func (*Router).AddRouter(router *Router) error
RouterConfig ... CIDR notation, like "192.0.2.0/24" Logger factory Max Jitter Minimum Delay Effective only when this router has a parent router Name of router. If not specified, a unique name will be assigned. Internal queue size StaticIP is deprecated. Use StaticIPs. StaticIPs is an array of static IP addresses to be assigned for this router. If no static IP address is given, the router will automatically assign an IP address. This will be ignored if this router is the root. func NewRouter(config *RouterConfig) (*Router, error)
TBFOption is the option type to configure a TokenBucketFilter func TBFMaxBurst(size int) TBFOption func TBFQueueSizeInBytes(bytes int) TBFOption func TBFRate(rate int) TBFOption func (*TokenBucketFilter).Set(opts ...TBFOption) (previous TBFOption) func NewTokenBucketFilter(n NIC, opts ...TBFOption) (*TokenBucketFilter, error) func (*TokenBucketFilter).Set(opts ...TBFOption) (previous TBFOption)
TokenBucketFilter implements a token bucket rate limit algorithm. NIC NIC Close closes and stops the token bucket filter queue Set updates a setting on the token bucket filter *TokenBucketFilter : NIC *TokenBucketFilter : github.com/prometheus/common/expfmt.Closer *TokenBucketFilter : io.Closer func NewTokenBucketFilter(n NIC, opts ...TBFOption) (*TokenBucketFilter, error)
UDPConn is the implementation of the Conn and PacketConn interfaces for UDP network connections. compatible with net.PacketConn and net.Conn Close closes the connection. Any blocked ReadFrom or WriteTo operations will be unblocked and return errors. LocalAddr returns the local network address. Read reads data from the connection. Read can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline. ReadFrom reads a packet from the connection, copying the payload into p. It returns the number of bytes copied into p and the return address that was on the packet. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Callers should always process the n > 0 bytes returned before considering the error err. ReadFrom can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline. ReadFromUDP acts like ReadFrom but returns a UDPAddr. ReadMsgUDP reads a message from c, copying the payload into b and the associated out-of-band data into oob. It returns the number of bytes copied into b, the number of bytes copied into oob, the flags that were set on the message and the source address of the message. The packages golang.org/x/net/ipv4 and golang.org/x/net/ipv6 can be used to manipulate IP-level socket options in oob. RemoteAddr returns the remote network address. SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline. A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to ReadFrom or WriteTo. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future. An idle timeout can be implemented by repeatedly extending the deadline after successful ReadFrom or WriteTo calls. A zero value for t means I/O operations will not time out. SetReadBuffer sets the size of the operating system's receive buffer associated with the connection. SetReadDeadline sets the deadline for future ReadFrom calls and any currently-blocked ReadFrom call. A zero value for t means ReadFrom will not time out. SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection. SetWriteDeadline sets the deadline for future WriteTo calls and any currently-blocked WriteTo call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means WriteTo will not time out. Write writes data to the connection. Write can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetWriteDeadline. WriteMsgUDP writes a message to addr via c if c isn't connected, or to c's remote address if c is connected (in which case addr must be nil). The payload is copied from b and the associated out-of-band data is copied from oob. It returns the number of payload and out-of-band bytes written. The packages golang.org/x/net/ipv4 and golang.org/x/net/ipv6 can be used to manipulate IP-level socket options in oob. WriteTo writes a packet with payload p to addr. WriteTo can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetWriteDeadline. On packet-oriented connections, write timeouts are rare. WriteToUDP acts like WriteTo but takes a UDPAddr. *UDPConn : github.com/pion/transport/v3.UDPConn *UDPConn : github.com/pion/transport/v2.UDPConn *UDPConn : github.com/pion/datachannel.ReadDeadliner *UDPConn : github.com/pion/datachannel.WriteDeadliner *UDPConn : github.com/pion/stun.Connection *UDPConn : github.com/pion/stun/v3.Connection *UDPConn : github.com/miekg/dns.Writer *UDPConn : github.com/prometheus/common/expfmt.Closer *UDPConn : internal/bisect.Writer *UDPConn : io.Closer *UDPConn : io.ReadCloser *UDPConn : io.Reader *UDPConn : io.ReadWriteCloser *UDPConn : io.ReadWriter *UDPConn : io.WriteCloser *UDPConn : io.Writer *UDPConn : net.Conn *UDPConn : net.PacketConn
UDPProxy is a proxy between real server(net.UDPConn) and vnet.UDPConn. High level design: .............................................. : Virtual Network (vnet) : : : +-------+ * 1 +----+ +--------+ : | :App |------------>|:Net|--o<-----|:Router | ............................. +-------+ +----+ | | : UDPProxy : : | | +----+ +---------+ +---------+ +--------+ : | |--->o--|:Net|-->o-| vnet. |-->o-| net. |--->-| :Real | : | | +----+ | UDPConn | | UDPConn | | Server | : | | : +---------+ +---------+ +--------+ : | | ............................: : +--------+ : ............................................... Close the proxy, stop all workers. Deliver directly send packet to vnet or real-server. For example, we can use this API to simulate the REPLAY ATTACK. Proxy starts a worker for server, ignore if already started. *UDPProxy : github.com/prometheus/common/expfmt.Closer *UDPProxy : io.Closer func NewProxy(router *Router) (*UDPProxy, error)
Package-Level Functions (total 9)
NewDelayFilter creates a new DelayFilter with the given nic and delay.
NewLossFilter creates a new LossFilter that drops every packet with a probability of chance/100. Every packet that is not dropped is passed on to the given NIC.
NewNet creates an instance of a virtual network. By design, it always have lo0 and eth0 interfaces. The lo0 has the address 127.0.0.1 assigned by default. IP address for eth0 will be assigned when this Net is added to a router.
NewProxy create a proxy, the router for this proxy belongs/bind to. If need to proxy for please create a new proxy for each router. For all addresses we proxy, we will create a vnet.Net in this router and proxy all packets.
NewRouter ...
NewTokenBucketFilter creates and starts a new TokenBucketFilter
TBFMaxBurst sets the bucket size of the token bucket filter. This is the maximum size that can instantly leave the filter, if the bucket is full.
TBFQueueSizeInBytes sets the max number of bytes waiting in the queue. Can only be set in constructor before using the TBF.
TBFRate sets the bit rate of a TokenBucketFilter
Package-Level Constants (total 8)
Bit is a single bit
EndpointAddrDependent means the behavior is dependent on the endpoint's address
EndpointAddrPortDependent means the behavior is dependent on the endpoint's address and port
EndpointIndependent means the behavior is independent of the endpoint's address or port
KBit is a kilobit
MBit is a Megabit
NATModeNAT1To1 exhibits 1:1 DNAT where the external IP address is statically mapped to a specific local IP address with port number is preserved always between them. When this mode is selected, MappingBehavior, FilteringBehavior, PortPreservation and MappingLifeTime of NATType are ignored.
NATModeNormal means the NAT behaves as a standard NAPT (RFC 2663).