k1

package
v0.0.0-...-8eda056 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2020 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NatSessionLifeSeconds   = 600
	NatSessionCheckInterval = 300
)
View Source
const (
	PROXY_POLICY  = "PROXY"
	DIRECT_POLICY = "DIRECT"
	REJECT_POLICY = "REJECT"
)
View Source
const DnsIPPoolMaxSpace = 0x3ffff // 4*65535

Variables

View Source
var MTU = 1500

Functions

func AuthRequired

func AuthRequired(c *gin.Context)

AuthRequired is a simple middleware to check the session

func IsExistPatternScheme

func IsExistPatternScheme(scheme string) bool

Types

type ConnData

type ConnData struct {
	Src      string
	Dst      string
	Proxy    string
	Upload   int64
	Download int64
}

statistical data of every connection

type Dns

type Dns struct {
	// contains filtered or unexported fields
}

func NewDns

func NewDns(one *One, cfg DnsConfig) (*Dns, error)

func (*Dns) Serve

func (d *Dns) Serve() error

func (*Dns) ServeDNS

func (d *Dns) ServeDNS(w dns.ResponseWriter, r *dns.Msg)

type DnsClient

type DnsClient struct {
	// contains filtered or unexported fields
}

type DnsClients

type DnsClients map[string]*DnsClient // map["tcp(8.8.8.8:53)"]*dns.Client

func GetDnsClients

func GetDnsClients(cfg DnsConfig) DnsClients

func (DnsClients) Exchange

func (c DnsClients) Exchange(r *dns.Msg, ns string) (*dns.Msg, time.Duration, error)

type DnsConfig

type DnsConfig struct {
	DnsPort         uint16   `gcfg:"dns-port"`
	DnsTtl          uint     `gcfg:"dns-ttl"`
	DnsPacketSize   uint16   `gcfg:"dns-packet-size"`
	DnsReadTimeout  uint     `gcfg:"dns-read-timeout"`
	DnsWriteTimeout uint     `gcfg:"dns-write-timeout"`
	Nameserver      []string // backend dns
}

type DnsIPPool

type DnsIPPool struct {
	// contains filtered or unexported fields
}

func NewDnsIPPool

func NewDnsIPPool(ip net.IP, subnet *net.IPNet) *DnsIPPool

func (*DnsIPPool) Alloc

func (pool *DnsIPPool) Alloc(tips string) net.IP

use tips as a hint to find a stable index

func (*DnsIPPool) Capacity

func (pool *DnsIPPool) Capacity() int

func (*DnsIPPool) Contains

func (pool *DnsIPPool) Contains(ip net.IP) bool

func (*DnsIPPool) Release

func (pool *DnsIPPool) Release(ip net.IP)

type DnsTable

type DnsTable struct {
	// contains filtered or unexported fields
}

func NewDnsTable

func NewDnsTable(ip net.IP, subnet *net.IPNet) *DnsTable

func (*DnsTable) Contains

func (c *DnsTable) Contains(ip net.IP) bool

func (*DnsTable) Get

func (c *DnsTable) Get(domain string) *DomainRecord

func (*DnsTable) GetByIP

func (c *DnsTable) GetByIP(ip net.IP) *DomainRecord

func (*DnsTable) IsNonProxyDomain

func (c *DnsTable) IsNonProxyDomain(domain string) bool

func (*DnsTable) Serve

func (c *DnsTable) Serve() error

func (*DnsTable) Set

func (c *DnsTable) Set(domain string, proxy string) *DomainRecord

func (*DnsTable) SetNonProxyDomain

func (c *DnsTable) SetNonProxyDomain(domain string, ttl uint32)

type DomainKeywordPattern

type DomainKeywordPattern struct {
	// contains filtered or unexported fields
}

DOMAIN-KEYWORD

func (*DomainKeywordPattern) Add

func (p *DomainKeywordPattern) Add(val string)

func (*DomainKeywordPattern) MarshalJSON

func (p *DomainKeywordPattern) MarshalJSON() ([]byte, error)

func (*DomainKeywordPattern) Match

func (p *DomainKeywordPattern) Match(val interface{}) bool

func (*DomainKeywordPattern) Name

func (p *DomainKeywordPattern) Name() string

func (*DomainKeywordPattern) Policy

func (p *DomainKeywordPattern) Policy() string

func (*DomainKeywordPattern) Proxy

func (p *DomainKeywordPattern) Proxy() string

func (*DomainKeywordPattern) Remove

func (p *DomainKeywordPattern) Remove(val string)

func (*DomainKeywordPattern) Scheme

func (p *DomainKeywordPattern) Scheme() string

type DomainPattern

type DomainPattern struct {
	// contains filtered or unexported fields
}

DOMAIN

func (*DomainPattern) Add

func (p *DomainPattern) Add(val string)

func (*DomainPattern) MarshalJSON

func (p *DomainPattern) MarshalJSON() ([]byte, error)

func (*DomainPattern) Match

func (p *DomainPattern) Match(val interface{}) bool

func (*DomainPattern) Name

func (p *DomainPattern) Name() string

func (*DomainPattern) Policy

func (p *DomainPattern) Policy() string

func (*DomainPattern) Proxy

func (p *DomainPattern) Proxy() string

func (*DomainPattern) Remove

func (p *DomainPattern) Remove(val string)

func (*DomainPattern) Scheme

func (p *DomainPattern) Scheme() string

type DomainRecord

type DomainRecord struct {
	Hostname string // hostname
	Proxy    string // proxy

	IP      net.IP // nat ip
	RealIP  net.IP // real ip
	Hits    int
	Expires time.Time
	// contains filtered or unexported fields
}

hijacked domain

func (*DomainRecord) Answer

func (record *DomainRecord) Answer(request *dns.Msg) *dns.Msg

func (*DomainRecord) SetRealIP

func (record *DomainRecord) SetRealIP(msg *dns.Msg)

func (*DomainRecord) Touch

func (record *DomainRecord) Touch()

type DomainSuffixPattern

type DomainSuffixPattern struct {
	// contains filtered or unexported fields
}

DOMAIN-SUFFIX

func (*DomainSuffixPattern) Add

func (p *DomainSuffixPattern) Add(val string)

func (*DomainSuffixPattern) MarshalJSON

func (p *DomainSuffixPattern) MarshalJSON() ([]byte, error)

func (*DomainSuffixPattern) Match

func (p *DomainSuffixPattern) Match(val interface{}) bool

func (*DomainSuffixPattern) Name

func (p *DomainSuffixPattern) Name() string

func (*DomainSuffixPattern) Policy

func (p *DomainSuffixPattern) Policy() string

func (*DomainSuffixPattern) Proxy

func (p *DomainSuffixPattern) Proxy() string

func (*DomainSuffixPattern) Remove

func (p *DomainSuffixPattern) Remove(val string)

func (*DomainSuffixPattern) Scheme

func (p *DomainSuffixPattern) Scheme() string

type GeneralConfig

type GeneralConfig struct {
	Network string // tun network
}

type IPCIDRPattern

type IPCIDRPattern struct {
	// contains filtered or unexported fields
}

IP-CIDR

func (*IPCIDRPattern) Add

func (p *IPCIDRPattern) Add(val string)

func (*IPCIDRPattern) MarshalJSON

func (p *IPCIDRPattern) MarshalJSON() ([]byte, error)

func (*IPCIDRPattern) Match

func (p *IPCIDRPattern) Match(val interface{}) bool

func (*IPCIDRPattern) Name

func (p *IPCIDRPattern) Name() string

func (*IPCIDRPattern) Policy

func (p *IPCIDRPattern) Policy() string

func (*IPCIDRPattern) Proxy

func (p *IPCIDRPattern) Proxy() string

func (*IPCIDRPattern) Remove

func (p *IPCIDRPattern) Remove(val string)

func (*IPCIDRPattern) Scheme

func (p *IPCIDRPattern) Scheme() string

type IPCountryPattern

type IPCountryPattern struct {
	// contains filtered or unexported fields
}

IP-COUNTRY

func (*IPCountryPattern) Add

func (p *IPCountryPattern) Add(val string)

func (*IPCountryPattern) MarshalJSON

func (p *IPCountryPattern) MarshalJSON() ([]byte, error)

func (*IPCountryPattern) Match

func (p *IPCountryPattern) Match(val interface{}) bool

func (*IPCountryPattern) Name

func (p *IPCountryPattern) Name() string

func (*IPCountryPattern) Policy

func (p *IPCountryPattern) Policy() string

func (*IPCountryPattern) Proxy

func (p *IPCountryPattern) Proxy() string

func (*IPCountryPattern) Remove

func (p *IPCountryPattern) Remove(val string)

func (*IPCountryPattern) Scheme

func (p *IPCountryPattern) Scheme() string

type IPRange

type IPRange struct {
	Start uint32
	End   uint32
}

IPRangeArray

func (*IPRange) MarshalJSON

func (p *IPRange) MarshalJSON() ([]byte, error)

type IPRangeArray

type IPRangeArray []IPRange

func (IPRangeArray) Contains

func (a IPRangeArray) Contains(ip uint32) bool

func (IPRangeArray) ContainsIP

func (a IPRangeArray) ContainsIP(ip net.IP) bool

func (IPRangeArray) Len

func (a IPRangeArray) Len() int

func (IPRangeArray) Less

func (a IPRangeArray) Less(i, j int) bool

func (IPRangeArray) Swap

func (a IPRangeArray) Swap(i, j int)

type KoneConfig

type KoneConfig struct {
	General GeneralConfig
	TCP     NatConfig
	UDP     NatConfig
	Dns     DnsConfig
	Route   RouteConfig
	Proxy   map[string]*ProxyConfig
	Pattern map[string]*PatternConfig
	Rule    RuleConfig
	Manager ManagerConfig
}

func ParseConfig

func ParseConfig(filename string) (*KoneConfig, error)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(one *One, cfg ManagerConfig) *Manager

func (*Manager) Serve

func (m *Manager) Serve() error

type ManagerConfig

type ManagerConfig struct {
	Listen string
}

type NameServer

type NameServer struct {
	Protocol string
	Addr     string
	Port     int
}

func (*NameServer) String

func (ns *NameServer) String() string

type Nat

type Nat struct {
	// contains filtered or unexported fields
}

func NewNat

func NewNat(from, to uint16) *Nat

type NatConfig

type NatConfig struct {
	ListenPort   uint16 `gcfg:"listen-port"`
	NatPortStart uint16 `gcfg:"nat-port-start"`
	NatPortEnd   uint16 `gcfg:"nat-port-end"`
}

type NatSession

type NatSession struct {
	// contains filtered or unexported fields
}

type NatTable

type NatTable struct {
	// contains filtered or unexported fields
}

func (*NatTable) Count

func (tbl *NatTable) Count() int

func (*NatTable) Map

func (tbl *NatTable) Map(ip net.IP, port uint16) (uint16, bool)

return: mapped port, is new mapped

func (*NatTable) Unmap

func (tbl *NatTable) Unmap(ip net.IP, port uint16)

type One

type One struct {
	// contains filtered or unexported fields
}

func FromConfig

func FromConfig(cfg *KoneConfig) (*One, error)

func (*One) Serve

func (one *One) Serve() error

type PacketFilter

type PacketFilter interface {
	Filter(wr io.Writer, p tcpip.IPv4Packet)
}

type PacketFilterFunc

type PacketFilterFunc func(wr io.Writer, p tcpip.IPv4Packet)

func (PacketFilterFunc) Filter

func (f PacketFilterFunc) Filter(wr io.Writer, p tcpip.IPv4Packet)

type Pattern

type Pattern interface {
	Name() string
	Scheme() string
	Policy() string
	Proxy() string
	Add(string)
	Remove(string)
	Match(val interface{}) bool
	MarshalJSON() ([]byte, error)
}

func CreatePattern

func CreatePattern(name string, config *PatternConfig) Pattern

func NewDomainKeywordPattern

func NewDomainKeywordPattern(name, policy, proxy string, vals []string) Pattern

func NewDomainPattern

func NewDomainPattern(name, policy, proxy string, vals []string) Pattern

func NewDomainSuffixPattern

func NewDomainSuffixPattern(name, policy, proxy string, vals []string) Pattern

func NewIPCIDRPattern

func NewIPCIDRPattern(name, policy, proxy string, vals []string) Pattern

func NewIPCountryPattern

func NewIPCountryPattern(name, policy, proxy string, vals []string) Pattern

type PatternConfig

type PatternConfig struct {
	Policy string
	Proxy  string
	Scheme string
	V      []string
}

https://manual.nssurge.com/policy.html There are 3 types of policies: PROXY, DIRECT and REJECT

type Proxies

type Proxies struct {
	// contains filtered or unexported fields
}

func NewProxies

func NewProxies(one *One, config map[string]*ProxyConfig) (*Proxies, error)

func (*Proxies) DefaultDial

func (p *Proxies) DefaultDial(network, addr string) (net.Conn, error)

func (*Proxies) Dial

func (p *Proxies) Dial(network, proxy, addr string) (net.Conn, error)

type ProxyConfig

type ProxyConfig struct {
	Url     string
	Default bool
}

type RouteConfig

type RouteConfig struct {
	V []string
}

type Rule

type Rule struct {
	// contains filtered or unexported fields
}

func NewRule

func NewRule(config RuleConfig, patterns map[string]*PatternConfig) *Rule

func (*Rule) DirectDomain

func (rule *Rule) DirectDomain(domain string)

func (*Rule) Proxy

func (rule *Rule) Proxy(val interface{}) (bool, string)

match a proxy for target `val`

func (*Rule) Reject

func (rule *Rule) Reject(val interface{}) bool

type RuleConfig

type RuleConfig struct {
	Pattern []string
	Final   string
}

There are 5 types of rules: DOMAIN, DOMAIN-SUFFIX, DOMAIN-KEYWORD, IP-COUNTRY and IP-CIDR

type TCPRelay

type TCPRelay struct {
	// contains filtered or unexported fields
}

func NewTCPRelay

func NewTCPRelay(one *One, cfg NatConfig) *TCPRelay

func (*TCPRelay) Filter

func (r *TCPRelay) Filter(wr io.Writer, ipPacket tcpip.IPv4Packet)

redirect tcp packet to relay

func (*TCPRelay) Serve

func (r *TCPRelay) Serve() error

type TrafficRecord

type TrafficRecord struct {
	Name     string
	Upload   int64
	Download int64
	Touch    time.Time
	Details  map[string]*TrafficRecordDetail
}

type TrafficRecordDetail

type TrafficRecordDetail struct {
	EndPoint string
	Upload   int64
	Download int64
	Touch    time.Time
}

statistical data of every host/website/proxy

type TunDriver

type TunDriver struct {
	// contains filtered or unexported fields
}

func NewTunDriver

func NewTunDriver(ip net.IP, subnet *net.IPNet, filters map[tcpip.IPProtocol]PacketFilter) (*TunDriver, error)

func (*TunDriver) AddRoutes

func (tun *TunDriver) AddRoutes(vals []string)

func (*TunDriver) Serve

func (tun *TunDriver) Serve() error

type UDPRelay

type UDPRelay struct {
	// contains filtered or unexported fields
}

func NewUDPRelay

func NewUDPRelay(one *One, cfg NatConfig) *UDPRelay

func (*UDPRelay) Filter

func (r *UDPRelay) Filter(wr io.Writer, ipPacket tcpip.IPv4Packet)

redirect udp packet to relay

func (*UDPRelay) Serve

func (r *UDPRelay) Serve() error

type UDPTunnel

type UDPTunnel struct {
	BndHost string
	BndPort uint16
	// contains filtered or unexported fields
}

func (*UDPTunnel) Pump

func (tunnel *UDPTunnel) Pump() error

func (*UDPTunnel) SetDeadline

func (tunnel *UDPTunnel) SetDeadline(duration time.Duration) error

func (*UDPTunnel) Write

func (tunnel *UDPTunnel) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL