{"modulePath":"github.com/celzero/firestack","version":"v0.0.0-20261126203528-ea10d50bc2a7","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package intra\n\n## Constants\n\n```go\nconst (\n\tUNKNOWN_UID     = core.UNKNOWN_UID\n\tUNKNOWN_UID_STR = core.UNKNOWN_UID_STR\n\t// ANDROID_UID         = core.ANDROID_UID\n\tANDROID_UID_STR     = core.ANDROID_UID_STR\n\tUNSUPPORTED_NETWORK = core.UNSUPPORTED_NETWORK\n)\n```\n\n```go\nconst (\n\tHDLOK = iota\n\tHDLEND\n)\n```\n\n```go\nconst (\n\tProtoTypeUDP  = \"udp\"\n\tProtoTypeTCP  = \"tcp\"\n\tProtoTypeICMP = \"icmp\"\n)\n```\n\n## Variables\n\n```go\nvar SELF_UID = protect.MyUid\n```\n\n## Functions\n\n```go\nfunc AddDNSCryptRelay(t Tunnel, stamp string) error\n```\nAddDNSCryptRelay adds a DNSCrypt relay transport to the tunnel's resolver.\n\n```go\nfunc AddDNSCryptTransport(t Tunnel, id, stamp string) (err error)\n```\nAddDNSCryptTransport creates and adds a DNSCrypt transport to the tunnel's resolver.\n\n```go\nfunc AddDNSProxy(t Tunnel, id, ippcsv string) error\n```\nAddDNSProxy creates and adds a DNS53 transport to the tunnel's resolver.\n\n```go\nfunc AddDefaultTransport(t Tunnel, typ, ippOrUrl, ips string) error\n```\nAddDefaultTransport adds a special default transport to the tunnel's resolver It may be either a DoH or a DNS53 transport.\n\n```go\nfunc AddDoHTransport(t Tunnel, id, url, ipcsv string) error\n```\nAddDoHTransport creates and adds a Transport that connects to the specified DoH server. \\`url\\` is the URL of a DoH server (no template, POST-only).\n\n```go\nfunc AddDoHTransport2(t Tunnel, id, url, ipurl, ipcsv string) error\n```\nAddDoHTransport2 is like AddDoHTransport, but it may connect over ipurl over url (host). ipurl is a URL with IP address (or ip:port) instead of a host name.\n\n```go\nfunc AddDoTTransport(t Tunnel, id, url, ipcsv string) error\n```\nAddDoTTransport creates and adds a Transport that connects to the specified DoT server.\n\n```go\nfunc AddODoHTransport(t Tunnel, id, endpoint, resolver, epipcsv string) error\n```\nAddODoHTransport creates and adds a Transport that connects to the specified ODoH server. \\`endpoint\\` is the entry / proxy for the ODoH server, \\`resolver\\` is the URL of the target ODoH server.\n\n```go\nfunc AddProxyDNS(t Tunnel, p x.Proxy) error\n```\nAddProxyDNS creates and adds a DNS53 transport as defined in Proxy's configuration.\n\n```go\nfunc Build(full bool) (v string)\n```\nBuild returns the build information.\n\n```go\nfunc CPUProfile(outproffile, outflightrecorder string, durationSecs int32) (ranSecs int32, err error)\n```\nCPUProfile starts a program-wide CPU profiler for durationSecs seconds (clamped to \\[10, 120]). The CPU profile is written to outproffile, and the flight recorder trace to outflightrecorder. If the flight recorder is not already running, it is started on-demand and stopped after. Returns the actual number of seconds profiled. Only one profile (cpu or mem) can run at a time.\n\n```go\nfunc ControlledRouter(c Controller, id, addrport string) x.Router\n```\nControlledRouter creates a \\[backend.Router] over a \\[backend.Internet] proxy (like \\[backend.Exit]), but one that uses custom Controller c. id and addrport are used only for diagnostics and logging, and could be left empty. Typical usage is to use Router.Reaches() to check if a host:port is reachable over this Controller c.\n\n```go\nfunc Crash(typ, afterMs int64)\n```\nCrash causes a crash by panicking on an out-of-bounds slice access. For testing only. Setting typ to 0 must send the crash output to stderr and abort, and 1 to console and not quit, while 2 must send the crash output to console and abort. afterMs is the number of milliseconds to wait before crashing.\n\n```go\nfunc DefaultDNSAsFallback(y bool)\n```\nDefaultDNSAsFallback allows using the Default transport as a fallback when the Preferred transport is missing or paused or ended.\n\n```go\nfunc ExperimentalWireGuard(y bool)\n```\nExperimentalWireGuard enables/disables experimental features for WireGuard like allowing incoming packets.\n\n```go\nfunc ExtractTrace(id string) []byte\n```\nExtractTrace is like [PeekTrace](#PeekTrace) but in addition also frees up the memory backing the log trace, if any.\n\n```go\nfunc FloodWireGuard(y bool)\n```\nFloodWireGuard enables/disables flooding WireGuard tunnels with randomly sized non-null packets.\n\n```go\nfunc GoMet() *x.GoMetrics\n```\n\n```go\nfunc LogLevel(gologLevel, consolelogLevel, callerDepth int32)\n```\nChange log level to very verbose (0), verbose (1), debug (2), info (3), warn (4), error (5), stacktraces (6), user notifications (7), or no logs (8). gologLevel and consolelogLevel can be set independently; ex: LogLevel(2, 6) or LogLevel(8, 0) etc. callerDepth can be any value between 0 and 9 which controls how many stack frames to unwind for every log call. 9 is more expensive, 1 is more prudent.\n\n```go\nfunc Loopback(y bool)\n```\nLoopback informs the network stack that it must deal with packets originating from its own process routed back into the tunnel.\n\n```go\nfunc LowMem(limitBytes int64)\n```\nLowMem triggers garbage collection cycle \u0026 allows for setting maximum memory limit, if limit \u003e 0. github.com/golang/proposal/blob/master/design/48409-soft-memory-limit.md\n\n```go\nfunc MakeDNS53Transport(t Tunnel, id, hostOrHostport, ipcsv string) (dnsx.Transport, error)\n```\nMakeDNS53Transport creates a DNS53 (plain DNS over UDP/TCP) transport for id, serving from hostOrHostport (a host, host:port, or ip:port), dialing via the tunnel's proxies. ipcsv, if any, is a csv of ip or ip:port addresses of the server, bypassing the system resolver.\n\n```go\nfunc MakeDNS53TransportFrom(t Tunnel, id string, ipp netip.AddrPort) (dnsx.Transport, error)\n```\nMakeDNS53TransportFrom creates a DNS53 transport for id, serving from ipp, dialing via the tunnel's proxies.\n\n```go\nfunc MakeDNSCryptTransport(t Tunnel, id, stamp string) (dnsx.Transport, error)\n```\nMakeDNSCryptTransport creates a free-standing (unregistered) DNSCrypt transport for id from serverstamp (a sdns:// stamp), dialing via the tunnel's proxies. Unlike [AddDNSCryptTransport](#AddDNSCryptTransport), the returned transport is not added to the tunnel's resolver nor to its DcProxy transport-mult, and it is short-lived (its certificate is not refreshed).\n\n```go\nfunc MakeDoHTransport(t Tunnel, id, url, ipcsv string) (dnsx.Transport, error)\n```\nMakeDoHTransport creates a DNS-over-HTTPS transport for id, dialing via the tunnel's proxies. ipcsv, if any, is a csv of IP (or ip:port) addresses of the DoH server, used to bypass the system resolver when dialing url.\n\n```go\nfunc MakeDoHTransport2(t Tunnel, id, url, ipurl, ipcsv string) (dnsx.Transport, error)\n```\nMakeDoHTransport2 is like MakeDoHTransport, but it may connect over ipurl over url (host). ipurl is a URL with IP address (or ip:port) instead of a host name.\n\n```go\nfunc MakeDoTTransport(t Tunnel, id, url, ipcsv string) (dnsx.Transport, error)\n```\nMakeDoTTransport creates a DNS-over-TLS transport for id, dialing via the tunnel's proxies. ipcsv, if any, is a csv of IP (or ip:port) addresses of the DoT server, used to bypass the system resolver.\n\n```go\nfunc MakeODoHTransport(t Tunnel, id, endpoint, resolver, epipcsv string) (dnsx.Transport, error)\n```\nMakeODoHTransport creates an Oblivious-DoH transport for id, dialing via the tunnel's proxies. endpoint is the entry / proxy for the ODoH server; resolver is the URL of the target ODoH server. epipcsv, if any, is a csv of IP (or ip:port) addresses of the endpoint, used to bypass the system resolver.\n\n```go\nfunc MemProfile(rate int32, outprofile string) error\n```\nMemProfile triggers GC and writes a heap profile to outprofile. rate controls memory profiling granularity: 1 most detailed, 0 disables. Only one profile (cpu or mem) can run at a time.\n\n```go\nfunc NewICMPHandler(pctx context.Context, resolver dnsx.Resolver, prox ipn.ProxyProvider, listener Listener) netstack.GICMPHandler\n```\n\n```go\nfunc NewTCPHandler(pctx context.Context, resolver dnsx.Resolver, prox ipn.ProxyProvider, listener FlowListener) netstack.GTCPConnHandler\n```\nNewTCPHandler returns a TCP forwarder with Intra-style behavior. Connections to \\`fakedns\\` are redirected to DOH. All other traffic is forwarded using \\`dialer\\`. \\`listener\\` is provided with a summary of each socket when it is closed.\n\n```go\nfunc NewUDPHandler(pctx context.Context, resolver dnsx.Resolver, prox ipn.ProxyProvider, listener FlowListener) netstack.GUDPConnHandler\n```\nNewUDPHandler makes a UDP handler with Intra-style DNS redirection: All packets are routed directly to their destination. \\`timeout\\` controls the effective NAT mapping lifetime. \\`config\\` is used to bind new external UDP ports. \\`listener\\` receives a summary about each UDP binding when it expires.\n\n```go\nfunc PeekTrace(id string) []byte\n```\nPeekTrace returns a log trace for key, if any, as a byte slice.\n\n```go\nfunc PrintStack(where int32) []byte\n```\nPrintStack logs the stack trace of all active goroutines to stdout if where is 0, to Console if 1; otherwise returns it as bytes. For testing only.\n\n```go\nfunc SetCrashOutput(fp1, fp2 string) bool\n```\nSetCrashOutput sets the crash output file at fp1 and caught panics in fp2. Returns true if successful, false on error (the files cannot be opened).\n\n```go\nfunc SetFlightRecordOutput(fp string) (prev string, err error)\n```\nSetFlightRecordOutput opens a writable file (and keeps it open) for Go's flight recorder to write to (on panics, for example). The flight recorder must be enabled via FlightRecorder(true) for this to be functional. Returns previous file name, if any. May error if fp cannot be opened. More: go.dev/blog/flight-recorder\n\n```go\nfunc SetSystemDNS(t Tunnel, ipcsvx string) error\n```\nSetSystemDNS creates and adds a DNS53 transport of the specified IP addresses.\n\n```go\nfunc SetupConsole(console Console) error\n```\nSetupConsole wires up firestack's logger to bdg.\n\n```go\nfunc Slowdown(y bool)\n```\nSlowdown sets the TUN forwarder in single-threaded mode.\n\n```go\nfunc TraceCount() int\n```\nTraceCount returns the current number of live per-key log traces.\n\n```go\nfunc Traces() []byte\n```\nTraces returns all live log traces, with stores in creation order and lines oldest first. Each recorded line is followed by a newline.\n\n```go\nfunc Transparency(eim, eif bool)\n```\nTransparency enables/disables endpoint-independent mapping/filtering. Currently applies only for UDP (RFC 4787).\n\n```go\nfunc UndelegatedDomains(useSystemDNS bool)\n```\nIf set, use SystemDNS to resolve undelegated (.lan, .internal, .arpa etc) domains.\n\n```go\nfunc WireGuardSearchDomains(y bool)\n```\nWireGuardSearchDomains enables/disables the use of DNS search domains for WireGuard.\n\n## Types\n\n```go\ntype Bridge interface {\n\tListener\n\tController\n}\n```\n\n```go\ntype Console x.Console\n```\n\n```go\ntype Controller x.Controller\n```\n\n```go\ntype DNSListener x.DNSListener\n```\n\n```go\ntype DefaultDNS interface {\n\tx.DNSTransport\n\t// contains filtered or unexported methods\n}\n```\nDefaultDNS is the resolver used by all dialers.\n\n```go\nfunc NewBuiltinDefaultDNS() (DefaultDNS, error)\n```\nNewBuiltinDefaultDNS creates a new DefaultDNS resolver of type dnsx.DNS53. It may either use OS provided or network provided DNS resolver, \u0026 will not work if the tunnel is in \"Loopback\" mode; create w/ NewDefaultDNS instead.\n\n```go\nfunc NewDefaultDNS(typ, url, ips string) (DefaultDNS, error)\n```\nNewDefaultDNS creates a new DefaultDNS resolver of type typ. For typ DOH, url scheme is http or https; for typ DNS53, url is ipport or csv(ipport). ips is a csv of ipports for typ DOH, and nil for typ DNS53.\n\n```go\ntype FlowListener interface {\n\t// Preflow is called before a new connection is established; return owner \"uid\", which is\n\t// later used by dnsx.Resolver to determine the DNS transport to use for that \"uid\".\n\tPreflow(protocol, uid int32, cid, src, dst string) *PreMark\n\t// Flow is called on a new connection; return Proxy IDs to forward the connection\n\t// to a pre-registered proxy; \"Base\" or \"Exit\" to allow the connection; \"Block\" to block it.\n\t// \"connid\" is used to uniquely identify a connection across all proxies, and a summary of the\n\t// connection is sent back to a pre-registered listener.\n\t// protocol is 6 for TCP, 17 for UDP, 1 for ICMP.\n\t// uid is -1 in case owner-uid of the connection couldn't be determined.\n\t// src and dst are string'd representation of net.TCPAddr and net.UDPAddr.\n\t// origdsts is a comma-separated list of original source IPs, this may be same as dst.\n\t// origdsts may contain unspecified IPv4 or IPv6 addresses, which denote that the domain\n\t// was blocked by a rdns blocklist (but the resolution was allowed to go through). Listener\n\t// may choose to \"Block\" this connection based on that information.\n\t// domains is a comma-separated list of domain names associated with origdsts, if any.\n\t// probableDomains is a comma-separated list of probable domain names associated with origdsts, if any.\n\t// blocklists is a comma-separated list of rdns blocklist names that apply, if any.\n\t// dstIsAlg is true if the destination is an alg'd IP (which is only valid within the tunnel \u0026 will not be used for dialing).\n\tFlow(protocol, uid int32, cid, src, dst, origdsts, domains, probableDomains, blocklists string, dstIsAlg bool) *Mark\n\t// Inflow is called on a new incoming connection. Returned *Mark values have no discernable effect on these connections,\n\t// except for the CID field, which is sent back via Postflow, and \"Block\" proxy which\n\t// will drop this connection on the floor.\n\tInflow(protocol, uid int32, cid, src, dst string) *Mark\n\t// Flowing is called after a flow is marked by Flow or Inflow.\n\t// It denotes the final Mark that was applied to the flow.\n\t// The only major discernable effect is PIDCSV has a single PID.\n\tFlowing(m *Mark)\n\t// Postflow reports summary after flow closes.\n\tPostflow(*FlowSummary)\n}\n```\n\n```go\ntype FlowSummary struct {\n\t// tcp, udp, or icmp.\n\tProto string\n\t// Unique ID for this flow.\n\tID string\n\t// Proxy ID that handled this flow.\n\tPID string\n\t// Relay Proxy ID that tunneled PID.\n\tRPID string\n\t// UID of the app that owns this flow (sans ICMP).\n\tUID string\n\t// Source IP.\n\tSource string\n\t// Remote IP, if dialed in.\n\tTarget string\n\t// Total bytes downloaded.\n\tRx int64\n\t// Total bytes uploaded.\n\tTx int64\n\t// Duration in milliseconds.\n\tDuration int64\n\n\t// Round-trip time (millis).\n\tRtt int64\n\t// Err or other messages, if any.\n\tMsg string\n\t// contains filtered or unexported fields\n}\n```\nFlowSummary reports information about each TCP connection, or a non-DNS UDP association, or ICMP echo when it is closed.\n\n```go\nfunc (s *FlowSummary) String() string\n```\nString implements fmt.Stringer.\n\n```go\ntype Listener interface {\n\tFlowListener\n\tDNSListener\n\tServerListener\n\tProxyListener\n}\n```\nListener receives usage statistics when a UDP or TCP socket is closed, or a DNS query is completed.\n\n```go\ntype Mark struct {\n\t// PIDCSV is a list of proxies to forward the flow over.\n\tPIDCSV string\n\t// CID uniquely identifies the flow.\n\tCID string\n\t// UID of the app which owns the flow.\n\tUID string\n\t// Preferred IP (for egress) to use for the flow (not guaranteed\n\t// as the flow may prefer IPv4 or IPv6 and the IP may not be of that family).\n\tIP string\n}\n```\n\n```go\ntype PreMark struct {\n\t// UID of the app which owns the flow.\n\t// Set it to \"-1\" if unknown.\n\tUID string\n\t// Is the UID us (our app / process)?\n\tIsUidSelf bool\n}\n```\n\n```go\ntype ProxyListener x.ProxyListener\n```\n\n```go\ntype ServerListener rnet.ServerListener\n```\n\n```go\ntype Tunnel interface {\n\ttunnel.Tunnel\n\n\t// Get the resolver.\n\tGetResolver() (x.DNSResolver, error)\n\n\t// Get proxies.\n\tGetProxies() (x.Proxies, error)\n\n\t// Get local services.\n\tGetServices() (x.Services, error)\n\n\t// SetLinkAndRoutes sets the tun fd as link with mtu \u0026 engine as routes for the tunnel.\n\t// where engine is one of the constants (Ns4, Ns6, Ns46) defined in package settings.\n\tSetLinkAndRoutes(fd, mtu, engine int) error\n\t// SetLinkAndRoutes2 is like SetLinkAndRoutes except it runs the tunnel with tunmtu\n\t// \u0026 proxies with linkmtu. tunmtu may be a \"fake\" MTU (assigned to the TUN device) and\n\t// can be quite large, while linkmtu must be the actual MTU of the underlying network\n\t// or min of MTUs of all available underlying networks.\n\tSetLinkAndRoutes2(fd, tunmtu, linkmtu, engine int) error\n\t// SetLinkMtu sets the link MTU (which must the MTU matching the underlying network or\n\t// min of MTUs of all available underlying networks). Link MTU is different from\n\t// tun MTU which must match the TUN device's MTU. Link MTU is used as a hint by\n\t// some Proxy implementations (eg. WireGuard).\n\tSetLinkMtu(linkmtu int) (didchange bool)\n\t// Restart restarts the tunnel with the given fd, linkmtu \u0026 tunmtu, and engine.\n\t// fd is the TUN device file descriptor.\n\t// linkmtu is the MTU of the underlying network, tunmtu is the MTU of the TUN device.\n\t// linkmtu can be different from tunmtu. If linkmtu \u003c= 0, it is assumed to be same as tunmtu.\n\t// engine is one of the constants (Ns4, Ns6, Ns46) defined in package settings.\n\tRestart(fd, linkmtu, tunmtu, engine int) error\n\n\t// Close connections by pid, cid, uid.\n\tCloseConns(activecsv string) (closedcsv string)\n\n\t// Sets pcap output to fpcap which is the absolute filepath\n\t// to which a PCAP file will be written to.\n\t// If len(fpcap) is 0, no PCAP file will be written.\n\t// If len(fpcap) is 1, PCAP be written to stdout.\n\tSetPcap(fpcap string) error\n\t// NIC, IP, TCP, UDP, and ICMP stats.\n\tStat() (*x.NetStat, error)\n\t// contains filtered or unexported methods\n}\n```\nTunnel represents an Intra session.\n\n```go\nfunc Connect(fd, linkmtu, tunmtu int, ifaddrs, fakedns string, dtr DefaultDNS, bdg Bridge) (t Tunnel, err error)\n```\nConnect creates firestack-administered tunnel. \\`fd\\` is the TUN device. The tunnel acquires an additional reference to it, which is released by Disconnect(), so the caller must close \\`fd\\` and Disconnect() to close the TUN device. \\`linkmtu\\` is the MTU of the underlying link (actual network). If \\\u003c= 0, it is assumed to be same as \\`tunmtu\\`. \\`tunmtu\\` is the MTU of the TUN device. This can be \"faked\", ie set to values larger than linkmtu. Typically, its value is same as \\`linkmtu\\`. \\`ifaddrs\\` is a comma-separated list of interface addresses with prefix lengths, \"ip/prefixlen\". \\`fakedns\\` is a comman-separated list of the nameservers that the system believes it is using, in \"host:port\" style. \\`bdg\\` is a kotlin object that implements the Bridge interface. \\`dtr\\` is the DefaultDNS (see: intra.NewDefaultDNS); can be nil. Changeable via intra.AddDefaultTransport. Throws an exception if the TUN file descriptor cannot be opened, or if the tunnel fails to connect.\n\n```go\nfunc Connect2(fd, tunmtu int, dtr DefaultDNS, bdg Bridge) (t Tunnel, err error)\n```\nConnect2 is like Connect, but assumes defaults for linkmtu, ifaddrs, and fakedns as -1, \\[\"10.111.222.1/24\", \"fd66:f83a:c650::0/120\"], and \\[\"10.111.222.3\", \"fd66:f83a:c650::3\"] respectively.\n\n```go\nfunc Connect3(fd, tunmtu int, bdg Bridge) (t Tunnel, err error)\n```\nConnect3 is like Connect2, but does not require passing a Default DNS resolver. The tunnel will instead attempt to use the system DNS resolver (best effort).\n\n```go\nfunc NewTunnel(fd, tunmtu int, ifaddrs, fakedns string, dtr DefaultDNS, bdg Bridge) (t Tunnel, err error)\n```\n\n```go\nfunc NewTunnel2(fd, linkmtu, tunmtu int, ifaddrs, fakedns string, dtr DefaultDNS, bdg Bridge) (t Tunnel, err error)\n```\n\n","path":"github.com/celzero/firestack/intra","name":"intra","synopsis":"","isRedistributable":true}
