kmgSys

package
v0.0.0-...-05317bf Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2015 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const MaxMaxFileNum = 1048576

经过多次尝试,发现这个值只能设置到 1048576

Variables

View Source
var ErrAllDeviceBusy = errors.New("tun/tap: all dev is busy.")
View Source
var ErrPlatformNotSupport = errors.New("Platform Not Support")

Functions

func Cpu

func Cpu() (used float64, numOfCore int)

func Disk

func Disk() (used float64, total int)

只返回 / 挂载的磁盘空间 total 1024byte 的默认单位,没有选项改成byte

func FindDeviceNameByIp

func FindDeviceNameByIp(ip string) string

获取外网网卡

func GetCurrentExecutePath

func GetCurrentExecutePath() (string, error)

func GetCurrentUserHomeDir

func GetCurrentUserHomeDir() string

func IKEUserCount

func IKEUserCount() int

func IsIpForwardOn

func IsIpForwardOn() bool

func Memory

func Memory() (used float64, total int)

byte

func MustIsRoot

func MustIsRoot() bool

是否是root,此处只返回是否,其他错误抛panic TODO 名字比较费解.

func MustIsRootOnCmd

func MustIsRootOnCmd()

func MustSetCurrentMaxFileNum

func MustSetCurrentMaxFileNum(limit uint64)

func MustSetIptableRule

func MustSetIptableRule(rule IptableRule)

func NetworkConnection

func NetworkConnection() (connectionCount int)

func NetworkRXTX

func NetworkRXTX(deviceName string) (rx int, tx int)

byte

func RecoverPath

func RecoverPath()

确保PATH里面包含 /usr/local/bin 和 /bin

func SetCurrentMaxFileNum

func SetCurrentMaxFileNum(limit uint64) (err error)

func SetIpForwardOn

func SetIpForwardOn()

证实可用

func SetP2PIpAndUp

func SetP2PIpAndUp(req SetP2PIpRequest) error

set tun p2p ip and up this device mtu default to 1500

func SyncTime

func SyncTime()

目前只支持 Ubuntu TODO data race?

func UsagePreInstall

func UsagePreInstall()

Types

type DeviceType

type DeviceType string
var DeviceTypeTap DeviceType = "tap"
var DeviceTypeTun DeviceType = "tun"

func (DeviceType) String

func (s DeviceType) String() string

type IptableRule

type IptableRule struct {
	Table string // example: "nat"
	Rule  string // example: "-A PREROUTING -s 172.20.0.0/16 -p udp -m udp --dport 53 -j REDIRECT --to-ports 53"
}

func MustGetIptableRuleList

func MustGetIptableRuleList() []IptableRule

type RouteRule

type RouteRule struct {
	Destination string
	Gateway     string
	Genmask     string
	Iface       string
}

func MustGetDefaultRoute

func MustGetDefaultRoute() *RouteRule

仅支持linux ipv4 返回nil表示没找到.

func MustGetRouteTable

func MustGetRouteTable() []*RouteRule

仅支持linux ipv4

type SetP2PIpRequest

type SetP2PIpRequest struct {
	IfaceName string // 必填
	SrcIp     net.IP // 必填
	DstIp     net.IP // 必填
	Mtu       int
	Mask      net.IPMask
}

type TunTapInterface

type TunTapInterface interface {
	io.ReadWriteCloser
	GetDeviceType() DeviceType
	Name() string
}

Interface is a TUN/TAP interface.

func NewTap

func NewTap(ifName string) (ifce TunTapInterface, err error)

Create a new TAP interface whose name is ifName. If ifName is empty, a default name (tap0, tap1, ... ) will be assigned. ifName should not exceed 16 bytes.

func NewTun

func NewTun(ifName string) (ifce TunTapInterface, err error)

Create a new TUN interface whose name is ifName. If ifName is empty, a default name (tap0, tap1, ... ) will be assigned. ifName should not exceed 16 bytes.

func NewTunNoName

func NewTunNoName() (ifce TunTapInterface, err error)

Jump to

Keyboard shortcuts

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