├── .gitignore
├── .travis.yml
├── LICENSE
├── Makefile
├── README.md
├── cmd
└── tun2socks
│ ├── main.go
│ ├── main_fakedns.go
│ ├── main_redirect.go
│ └── main_socks.go
├── common
├── cache
│ └── cache.go
├── dns
│ ├── cache
│ │ └── cache.go
│ ├── dns.go
│ ├── fakedns
│ │ └── fakedns.go
│ └── fakeip
│ │ └── pool.go
├── log
│ ├── log.go
│ ├── logger.go
│ ├── simple
│ │ └── logger.go
│ └── simpleandroidlog
│ │ └── simpleandroidlog.go
└── packet
│ └── packet.go
├── component
├── gls
│ ├── LICENSE
│ ├── README.md
│ ├── go_tls.h
│ ├── id.go
│ ├── id_386.s
│ ├── id_amd64.s
│ ├── id_arm.s
│ ├── id_arm64.s
│ ├── id_mips.s
│ ├── id_mips64.s
│ ├── id_mips64le.s
│ ├── id_mipsle.s
│ ├── id_ppc64.s
│ ├── id_ppc64le.s
│ └── id_s390x.s
├── go-syncex
│ ├── LICENSE
│ ├── README.md
│ ├── criticalsection.go
│ ├── error.go
│ ├── examples
│ │ ├── CriticalSection
│ │ │ └── main.go
│ │ └── RecursiveMutex
│ │ │ └── main.go
│ ├── recursivemutex.go
│ ├── reentrantmutex.go
│ └── utils.go
├── pool
│ └── pool.go
├── runner
│ ├── doc.go
│ └── runner.go
└── trie
│ ├── domain.go
│ └── node.go
├── core
├── addr.go
├── c
│ ├── api
│ │ └── err.c
│ ├── core
│ │ ├── altcp.c
│ │ ├── altcp_alloc.c
│ │ ├── altcp_tcp.c
│ │ ├── def.c
│ │ ├── dns.c
│ │ ├── inet_chksum.c
│ │ ├── init.c
│ │ ├── ip.c
│ │ ├── ipv4
│ │ │ ├── acd.c
│ │ │ ├── autoip.c
│ │ │ ├── dhcp.c
│ │ │ ├── etharp.c
│ │ │ ├── icmp.c
│ │ │ ├── igmp.c
│ │ │ ├── ip4.c
│ │ │ ├── ip4_addr.c
│ │ │ └── ip4_frag.c
│ │ ├── ipv6
│ │ │ ├── dhcp6.c
│ │ │ ├── ethip6.c
│ │ │ ├── icmp6.c
│ │ │ ├── inet6.c
│ │ │ ├── ip6.c
│ │ │ ├── ip6_addr.c
│ │ │ ├── ip6_frag.c
│ │ │ ├── mld6.c
│ │ │ └── nd6.c
│ │ ├── mem.c
│ │ ├── memp.c
│ │ ├── netif.c
│ │ ├── pbuf.c
│ │ ├── raw.c
│ │ ├── stats.c
│ │ ├── sys.c
│ │ ├── tcp.c
│ │ ├── tcp_in.c
│ │ ├── tcp_out.c
│ │ ├── timeouts.c
│ │ └── udp.c
│ ├── custom
│ │ ├── arch
│ │ │ ├── bpstruct.h
│ │ │ ├── cc.h
│ │ │ ├── cc_android.h
│ │ │ ├── cc_others.h
│ │ │ ├── cc_windows.h
│ │ │ ├── epstruct.h
│ │ │ ├── perf.h
│ │ │ └── sys_arch.h
│ │ ├── lwipopts.h
│ │ └── sys_arch.c
│ └── include
│ │ ├── compat
│ │ ├── posix
│ │ │ ├── arpa
│ │ │ │ └── inet.h
│ │ │ ├── net
│ │ │ │ └── if.h
│ │ │ ├── netdb.h
│ │ │ └── sys
│ │ │ │ └── socket.h
│ │ └── stdc
│ │ │ └── errno.h
│ │ ├── lwip
│ │ ├── acd.h
│ │ ├── altcp.h
│ │ ├── altcp_tcp.h
│ │ ├── altcp_tls.h
│ │ ├── api.h
│ │ ├── apps
│ │ │ ├── FILES
│ │ │ ├── altcp_proxyconnect.h
│ │ │ ├── altcp_tls_mbedtls_opts.h
│ │ │ ├── fs.h
│ │ │ ├── http_client.h
│ │ │ ├── httpd.h
│ │ │ ├── httpd_opts.h
│ │ │ ├── lwiperf.h
│ │ │ ├── mdns.h
│ │ │ ├── mdns_domain.h
│ │ │ ├── mdns_opts.h
│ │ │ ├── mdns_out.h
│ │ │ ├── mdns_priv.h
│ │ │ ├── mqtt.h
│ │ │ ├── mqtt_opts.h
│ │ │ ├── mqtt_priv.h
│ │ │ ├── netbiosns.h
│ │ │ ├── netbiosns_opts.h
│ │ │ ├── smtp.h
│ │ │ ├── smtp_opts.h
│ │ │ ├── snmp.h
│ │ │ ├── snmp_core.h
│ │ │ ├── snmp_mib2.h
│ │ │ ├── snmp_opts.h
│ │ │ ├── snmp_scalar.h
│ │ │ ├── snmp_snmpv2_framework.h
│ │ │ ├── snmp_snmpv2_usm.h
│ │ │ ├── snmp_table.h
│ │ │ ├── snmp_threadsync.h
│ │ │ ├── snmpv3.h
│ │ │ ├── sntp.h
│ │ │ ├── sntp_opts.h
│ │ │ ├── tftp_client.h
│ │ │ ├── tftp_common.h
│ │ │ ├── tftp_opts.h
│ │ │ └── tftp_server.h
│ │ ├── arch.h
│ │ ├── autoip.h
│ │ ├── debug.h
│ │ ├── def.h
│ │ ├── dhcp.h
│ │ ├── dhcp6.h
│ │ ├── dns.h
│ │ ├── err.h
│ │ ├── errno.h
│ │ ├── etharp.h
│ │ ├── ethip6.h
│ │ ├── icmp.h
│ │ ├── icmp6.h
│ │ ├── if_api.h
│ │ ├── igmp.h
│ │ ├── inet.h
│ │ ├── inet_chksum.h
│ │ ├── init.h
│ │ ├── init.h.cmake.in
│ │ ├── ip.h
│ │ ├── ip4.h
│ │ ├── ip4_addr.h
│ │ ├── ip4_frag.h
│ │ ├── ip6.h
│ │ ├── ip6_addr.h
│ │ ├── ip6_frag.h
│ │ ├── ip6_zone.h
│ │ ├── ip_addr.h
│ │ ├── mem.h
│ │ ├── memp.h
│ │ ├── mld6.h
│ │ ├── nd6.h
│ │ ├── netbuf.h
│ │ ├── netdb.h
│ │ ├── netif.h
│ │ ├── netifapi.h
│ │ ├── opt.h
│ │ ├── pbuf.h
│ │ ├── priv
│ │ │ ├── altcp_priv.h
│ │ │ ├── api_msg.h
│ │ │ ├── mem_priv.h
│ │ │ ├── memp_priv.h
│ │ │ ├── memp_std.h
│ │ │ ├── nd6_priv.h
│ │ │ ├── raw_priv.h
│ │ │ ├── sockets_priv.h
│ │ │ ├── tcp_priv.h
│ │ │ └── tcpip_priv.h
│ │ ├── prot
│ │ │ ├── acd.h
│ │ │ ├── autoip.h
│ │ │ ├── dhcp.h
│ │ │ ├── dhcp6.h
│ │ │ ├── dns.h
│ │ │ ├── etharp.h
│ │ │ ├── ethernet.h
│ │ │ ├── iana.h
│ │ │ ├── icmp.h
│ │ │ ├── icmp6.h
│ │ │ ├── ieee.h
│ │ │ ├── igmp.h
│ │ │ ├── ip.h
│ │ │ ├── ip4.h
│ │ │ ├── ip6.h
│ │ │ ├── mld6.h
│ │ │ ├── nd6.h
│ │ │ ├── tcp.h
│ │ │ └── udp.h
│ │ ├── raw.h
│ │ ├── sio.h
│ │ ├── snmp.h
│ │ ├── sockets.h
│ │ ├── stats.h
│ │ ├── sys.h
│ │ ├── tcp.h
│ │ ├── tcpbase.h
│ │ ├── tcpip.h
│ │ ├── timeouts.h
│ │ └── udp.h
│ │ └── netif
│ │ ├── bridgeif.h
│ │ ├── bridgeif_opts.h
│ │ ├── etharp.h
│ │ ├── ethernet.h
│ │ ├── ieee802154.h
│ │ ├── lowpan6.h
│ │ ├── lowpan6_ble.h
│ │ ├── lowpan6_common.h
│ │ ├── lowpan6_opts.h
│ │ ├── ppp
│ │ ├── ccp.h
│ │ ├── chap-md5.h
│ │ ├── chap-new.h
│ │ ├── chap_ms.h
│ │ ├── eap.h
│ │ ├── ecp.h
│ │ ├── eui64.h
│ │ ├── fsm.h
│ │ ├── ipcp.h
│ │ ├── ipv6cp.h
│ │ ├── lcp.h
│ │ ├── magic.h
│ │ ├── mppe.h
│ │ ├── polarssl
│ │ │ ├── arc4.h
│ │ │ ├── des.h
│ │ │ ├── md4.h
│ │ │ ├── md5.h
│ │ │ └── sha1.h
│ │ ├── ppp.h
│ │ ├── ppp_impl.h
│ │ ├── ppp_opts.h
│ │ ├── pppapi.h
│ │ ├── pppcrypt.h
│ │ ├── pppdebug.h
│ │ ├── pppoe.h
│ │ ├── pppol2tp.h
│ │ ├── pppos.h
│ │ ├── upap.h
│ │ └── vj.h
│ │ ├── slipif.h
│ │ └── zepif.h
├── c_api.go
├── c_core.go
├── c_core_4.go
├── c_core_6.go
├── c_custom.go
├── conn.go
├── core_test.go
├── errors.go
├── handler.go
├── input.go
├── lwip.go
├── lwip_access_wrapper.go
├── lwip_other.go
├── lwip_windows.go
├── output.go
├── output_export.go
├── tcp_callback.go
├── tcp_callback_export.go
├── tcp_conn.go
├── udp_callback.go
├── udp_callback_export.go
├── udp_conn.go
└── udp_conn_map.go
├── filter
├── filter.go
└── icmp.go
├── go.mod
└── proxy
├── echo
├── tcp.go
└── udp.go
└── socks
├── socks.go
├── tcp.go
├── udp.go
└── utils.go
/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /tools
3 | .DS_Store
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: required
2 |
3 | services:
4 | - docker
5 |
6 | language: go
7 | go:
8 | - "1.13"
9 |
10 | before_install:
11 | - go get github.com/karalabe/xgo
12 |
13 | install: go get -d ./...
14 |
15 | script: make travisbuild
16 |
17 | deploy:
18 | provider: releases
19 | api_key:
20 | secure: "Yom8wSzSSa2XIbK/T7x9QbHt+reYPHseFAmyB3XAcuTOcqbLU79CWfR5XcPPYnn2zhGu5ATQcc6JlKjATHgz3JFn8YxBPxoKNX3Q+K1jsrNMWYfz7uokFzUndvMuQrLYlAYcywaLQgRKIFbTwPAKqEYOET8fzH6Frv+zxiUELfOYiKrnqEb0I6AgkSkH5DM1jQS9GllnciW0J7+4bWIv6cUi02JBQ4Atl3Pq83j2WlpaYIseRoDA+6yJ8bgEc5QTAynx3jTJ1Ok3HKH9XywpWiy59zTI+kaxGPYYoa5Ei1cihhxPTRo0hrRSVxRvnZ5LZopVmXA4+r3FUDyRLlhyxvBEEYjnG7Jh1sEQfpSCmpde+mRrQFvKxbnJjK5UGUatDqV2cxlJmVIOkClYTc0fVS9qBJwjdz+Q3xBkFLchX+L55L8/ZCRm9Qq5OiYQr4RhrbntDE0c0F1KYkY4oi64toAI24X8QdJA5c9FwL4QDqkGt1J+tmFKTDC9cWT1UwtA1d9x55XYyHZ3eRlVM+R0UMeeMNmOKXyJDzy3H5DRSr6UmZCUM/zXo4ip5HNNyXSsMjjkqqC3Zg+OY2kjBMHOwnbIr7cRvnvq5DdUue/L53F0PryumXrfoZ/pg3jv7OhsltAXqZ5GO9b/wYRlfSMrlRo3//c+d5nMHRmd4N4Bzm8="
21 | file_glob: true
22 | file:
23 | - "build/tun2socks*"
24 | skip_cleanup: true
25 | on:
26 | tags: true
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 eycorsican
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | GOCMD=go
2 | XGOCMD=xgo
3 | GOBUILD=$(GOCMD) build
4 | GOCLEAN=$(GOCMD) clean
5 | VERSION=$(shell git describe --tags)
6 | DEBUG_LDFLAGS=''
7 | RELEASE_LDFLAGS='-s -w -X main.version=$(VERSION)'
8 | BUILD_TAGS?=dnscache socks dnsfallback fakedns d stats
9 | DEBUG_BUILD_TAGS=$(BUILD_TAGS) debug
10 | BUILDDIR=$(shell pwd)/build
11 | CMDDIR=$(shell pwd)/cmd/tun2socks
12 | PROGRAM=tun2socks
13 |
14 | BUILD_CMD="cd $(CMDDIR) && $(GOBUILD) -ldflags $(RELEASE_LDFLAGS) -o $(BUILDDIR)/$(PROGRAM) -v -tags '$(BUILD_TAGS)'"
15 | DBUILD_CMD="cd $(CMDDIR) && $(GOBUILD) -race -ldflags $(DEBUG_LDFLAGS) -o $(BUILDDIR)/$(PROGRAM) -v -tags '$(DEBUG_BUILD_TAGS)'"
16 | XBUILD_CMD="cd $(BUILDDIR) && $(XGOCMD) -ldflags $(RELEASE_LDFLAGS) -tags '$(BUILD_TAGS)' --targets=*/* $(CMDDIR)"
17 | RELEASE_CMD="cd $(BUILDDIR) && $(XGOCMD) -ldflags $(RELEASE_LDFLAGS) -tags '$(BUILD_TAGS)' --targets=linux/amd64,linux/arm64,linux/386,linux/mips,linux/mipsle,linux/mips64,linux/mips64le,windows/*,darwin/* $(CMDDIR)"
18 | WINDOWS_CMD="cd $(BUILDDIR) && $(XGOCMD) -ldflags $(RELEASE_LDFLAGS) -tags '$(BUILD_TAGS)' --targets=windows/amd64 $(CMDDIR)"
19 |
20 | all: build
21 |
22 | build:
23 | mkdir -p $(BUILDDIR)
24 | eval $(BUILD_CMD)
25 |
26 | dbuild:
27 | mkdir -p $(BUILDDIR)
28 | eval $(DBUILD_CMD)
29 |
30 | windows:
31 | mkdir -p $(BUILDDIR)
32 | eval $(WINDOWS_CMD)
33 |
34 | xbuild:
35 | mkdir -p $(BUILDDIR)
36 | eval $(XBUILD_CMD)
37 |
38 | release:
39 | mkdir -p $(BUILDDIR)
40 | eval $(RELEASE_CMD)
41 |
42 | travisbuild: xbuild
43 |
44 | clean:
45 | rm -rf $(BUILDDIR)
46 |
47 | cleancache:
48 | # go build cache may need to cleanup if changing C source code
49 | $(GOCLEAN) -cache
50 | rm -rf $(BUILDDIR)
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # go-tun2socks
2 |
3 | [](https://travis-ci.com/eycorsican/go-tun2socks)
4 |
5 | A tun2socks implementation written in Go.
6 |
7 | ## Do NOT compile it, it works with igniter-go-libs
8 | ## Do NOT commit changes to go.mod
9 |
10 | The `go.mod` here works like a placeholder when used as go local module without VCS.
11 |
--------------------------------------------------------------------------------
/cmd/tun2socks/main_fakedns.go:
--------------------------------------------------------------------------------
1 | // +build fakedns
2 |
3 | package main
4 |
5 | import (
6 | "flag"
7 |
8 | "github.com/eycorsican/go-tun2socks/common/dns/fakedns"
9 | )
10 |
11 | func init() {
12 | args.EnableFakeDns = flag.Bool("fakeDns", false, "Enable fake DNS")
13 | args.FakeDnsMinIP = flag.String("fakeDnsMinIP", "172.255.0.0", "Minimum fake IP used by fake DNS")
14 | args.FakeDnsMaxIP = flag.String("fakeDnsMaxIP", "172.255.255.255", "Maximum fake IP used by fake DNS")
15 |
16 | addPostFlagsInitFn(func() {
17 | if *args.EnableFakeDns {
18 | fakeDns = fakedns.NewSimpleFakeDns(*args.FakeDnsMinIP, *args.FakeDnsMaxIP)
19 | } else {
20 | fakeDns = nil
21 | }
22 | })
23 | }
24 |
--------------------------------------------------------------------------------
/cmd/tun2socks/main_redirect.go:
--------------------------------------------------------------------------------
1 | // +build redirect
2 |
3 | package main
4 |
5 | import (
6 | "github.com/eycorsican/go-tun2socks/core"
7 | "github.com/eycorsican/go-tun2socks/proxy/redirect"
8 | )
9 |
10 | func init() {
11 | args.addFlag(fProxyServer)
12 | args.addFlag(fUdpTimeout)
13 |
14 | registerHandlerCreater("redirect", func() {
15 | core.RegisterTCPConnHandler(redirect.NewTCPHandler(*args.ProxyServer))
16 | core.RegisterUDPConnHandler(redirect.NewUDPHandler(*args.ProxyServer, *args.UdpTimeout))
17 | })
18 | }
19 |
--------------------------------------------------------------------------------
/cmd/tun2socks/main_socks.go:
--------------------------------------------------------------------------------
1 | // +build socks
2 |
3 | package main
4 |
5 | import (
6 | "net"
7 |
8 | "github.com/eycorsican/go-tun2socks/common/log"
9 | "github.com/eycorsican/go-tun2socks/core"
10 | "github.com/eycorsican/go-tun2socks/proxy/socks"
11 | )
12 |
13 | func init() {
14 | args.addFlag(fProxyServer)
15 | args.addFlag(fUdpTimeout)
16 | args.addFlag(fStats)
17 |
18 | registerHandlerCreater("socks", func() {
19 | // Verify proxy server address.
20 | proxyAddr, err := net.ResolveTCPAddr("tcp", *args.ProxyServer)
21 | if err != nil {
22 | log.Fatalf("invalid proxy server address: %v", err)
23 | }
24 | proxyHost := proxyAddr.IP.String()
25 | proxyPort := uint16(proxyAddr.Port)
26 |
27 | core.RegisterTCPConnHandler(socks.NewTCPHandler(proxyHost, proxyPort, fakeDns, sessionStater))
28 | core.RegisterUDPConnHandler(socks.NewUDPHandler(proxyHost, proxyPort, *args.UdpTimeout, dnsCache, fakeDns, sessionStater))
29 | })
30 | }
31 |
--------------------------------------------------------------------------------
/common/cache/cache.go:
--------------------------------------------------------------------------------
1 | package cache
2 |
3 | import (
4 | "runtime"
5 | "sync"
6 | "time"
7 | )
8 |
9 | // Cache store element with a expired time
10 | type Cache struct {
11 | *cache
12 | }
13 |
14 | type cache struct {
15 | mapping sync.Map
16 | janitor *janitor
17 | }
18 |
19 | type element struct {
20 | Expired time.Time
21 | Payload interface{}
22 | }
23 |
24 | // Put element in Cache with its ttl
25 | func (c *cache) Put(key interface{}, payload interface{}, ttl time.Duration) {
26 | c.mapping.Store(key, &element{
27 | Payload: payload,
28 | Expired: time.Now().Add(ttl),
29 | })
30 | }
31 |
32 | // Get element in Cache, and drop when it expired
33 | func (c *cache) Get(key interface{}) interface{} {
34 | item, exist := c.mapping.Load(key)
35 | if !exist {
36 | return nil
37 | }
38 | elm := item.(*element)
39 | // expired
40 | if time.Since(elm.Expired) > 0 {
41 | c.mapping.Delete(key)
42 | return nil
43 | }
44 | return elm.Payload
45 | }
46 |
47 | // GetWithExpire element in Cache with Expire Time
48 | func (c *cache) GetWithExpire(key interface{}) (payload interface{}, expired time.Time) {
49 | item, exist := c.mapping.Load(key)
50 | if !exist {
51 | return
52 | }
53 | elm := item.(*element)
54 | // expired
55 | if time.Since(elm.Expired) > 0 {
56 | c.mapping.Delete(key)
57 | return
58 | }
59 | return elm.Payload, elm.Expired
60 | }
61 |
62 | func (c *cache) cleanup() {
63 | c.mapping.Range(func(k, v interface{}) bool {
64 | key := k.(string)
65 | elm := v.(*element)
66 | if time.Since(elm.Expired) > 0 {
67 | c.mapping.Delete(key)
68 | }
69 | return true
70 | })
71 | }
72 |
73 | type janitor struct {
74 | interval time.Duration
75 | stop chan struct{}
76 | }
77 |
78 | func (j *janitor) process(c *cache) {
79 | ticker := time.NewTicker(j.interval)
80 | for {
81 | select {
82 | case <-ticker.C:
83 | c.cleanup()
84 | case <-j.stop:
85 | ticker.Stop()
86 | return
87 | }
88 | }
89 | }
90 |
91 | func stopJanitor(c *Cache) {
92 | c.janitor.stop <- struct{}{}
93 | }
94 |
95 | // New return *Cache
96 | func New(interval time.Duration) *Cache {
97 | j := &janitor{
98 | interval: interval,
99 | stop: make(chan struct{}),
100 | }
101 | c := &cache{janitor: j}
102 | go j.process(c)
103 | C := &Cache{c}
104 | runtime.SetFinalizer(C, stopJanitor)
105 | return C
106 | }
107 |
--------------------------------------------------------------------------------
/common/dns/cache/cache.go:
--------------------------------------------------------------------------------
1 | // This file is copied from https://github.com/yinghuocho/gotun2socks/blob/master/udp.go
2 |
3 | package cache
4 |
5 | import (
6 | "errors"
7 | "fmt"
8 | "time"
9 |
10 | "github.com/miekg/dns"
11 |
12 | "github.com/eycorsican/go-tun2socks/common/cache"
13 | cdns "github.com/eycorsican/go-tun2socks/common/dns"
14 | "github.com/eycorsican/go-tun2socks/common/log"
15 | )
16 |
17 | const minCleanupInterval = 5 * time.Minute
18 |
19 | type dnsCacheEntry struct {
20 | msg []byte
21 | }
22 |
23 | type simpleDnsCache struct {
24 | storage *cache.Cache
25 | }
26 |
27 | func NewSimpleDnsCache() cdns.DnsCache {
28 | s := cache.New(minCleanupInterval)
29 | return &simpleDnsCache{
30 | storage: s,
31 | }
32 | }
33 |
34 | func packUint16(i uint16) []byte { return []byte{byte(i >> 8), byte(i)} }
35 |
36 | func cacheKey(q dns.Question) string {
37 | return q.String()
38 | }
39 |
40 | func (c *simpleDnsCache) Query(payload []byte) ([]byte, error) {
41 | request := new(dns.Msg)
42 | e := request.Unpack(payload)
43 | if e != nil {
44 | return nil, e
45 | }
46 | if len(request.Question) == 0 {
47 | return nil, errors.New("simpleDnsCache: request.Question is empty")
48 | }
49 |
50 | key := cacheKey(request.Question[0])
51 | entryInterface := c.storage.Get(key)
52 | if entryInterface == nil {
53 | log.Debugf("simpleDnsCache: no entry found in DnsCache, key: %v", key)
54 | // not an error
55 | return nil, nil
56 | }
57 | entry := entryInterface.(*dnsCacheEntry)
58 | if entry == nil {
59 | return nil, errors.New("simpleDnsCache: nil pointer in DnsCache entry")
60 | }
61 |
62 | resp := new(dns.Msg)
63 | resp.Unpack(entry.msg)
64 | resp.Id = request.Id
65 | var buf [1024]byte
66 | dnsAnswer, err := resp.PackBuffer(buf[:])
67 | if err != nil {
68 | return nil, err
69 | }
70 | log.Debugf("simpleDnsCache: got dns answer from cache with key: %v", key)
71 | return append([]byte(nil), dnsAnswer...), nil
72 | }
73 |
74 | func (c *simpleDnsCache) Store(payload []byte) error {
75 | resp := new(dns.Msg)
76 | e := resp.Unpack(payload)
77 | if e != nil {
78 | return e
79 | }
80 | if resp.Rcode != dns.RcodeSuccess {
81 | return errors.New(fmt.Sprintf("simpleDnsCache: resp.Rcode not RcodeSuccess: DNS resp is: %v", resp.String()))
82 | }
83 | if len(resp.Question) == 0 || len(resp.Answer) == 0 {
84 | return errors.New("simpleDnsCache: resp.Question or resp.Answer is empty")
85 | }
86 |
87 | key := cacheKey(resp.Question[0])
88 | ttl := resp.Answer[0].Header().Ttl
89 | value := &dnsCacheEntry{
90 | msg: payload,
91 | }
92 | c.storage.Put(key, value, time.Duration(ttl)*time.Second)
93 |
94 | log.Debugf("simpleDnsCache: stored dns answer with key: %v, ttl: %v sec", key, ttl)
95 | return nil
96 | }
97 |
--------------------------------------------------------------------------------
/common/dns/dns.go:
--------------------------------------------------------------------------------
1 | package dns
2 |
3 | import (
4 | "net"
5 | )
6 |
7 | const COMMON_DNS_PORT = 53
8 |
9 | type DnsCache interface {
10 | // Query queries the response for the DNS request with payload `p`,
11 | // the response data should be a valid DNS response payload.
12 | Query(p []byte) ([]byte, error)
13 |
14 | // Store stores the DNS response with payload `p` to the cache.
15 | Store(p []byte) error
16 | }
17 |
18 | type FakeDns interface {
19 | // GenerateFakeResponse generates a fake dns response for the specify request.
20 | GenerateFakeResponse(request []byte) ([]byte, error)
21 |
22 | // QueryDomain returns the corresponding domain for the given IP.
23 | QueryDomain(ip net.IP) string
24 |
25 | // IsFakeIP checks if the given ip is a fake IP.
26 | IsFakeIP(ip net.IP) bool
27 | }
28 |
--------------------------------------------------------------------------------
/common/dns/fakedns/fakedns.go:
--------------------------------------------------------------------------------
1 | package fakedns
2 |
3 | import (
4 | "errors"
5 | "fmt"
6 | "net"
7 |
8 | "github.com/miekg/dns"
9 |
10 | cdns "github.com/eycorsican/go-tun2socks/common/dns"
11 | "github.com/eycorsican/go-tun2socks/common/dns/fakeip"
12 | "github.com/eycorsican/go-tun2socks/common/log"
13 | "github.com/eycorsican/go-tun2socks/component/pool"
14 | )
15 |
16 | const (
17 | FakeResponseTtl uint32 = 1 // in sec
18 | )
19 |
20 | type fakeDNS struct {
21 | fakePool *fakeip.Pool
22 | }
23 |
24 | func canHandleDnsQuery(data []byte) bool {
25 | req := new(dns.Msg)
26 | err := req.Unpack(data)
27 | if err != nil {
28 | log.Debugf("cannot handle dns query: failed to unpack")
29 | return false
30 | }
31 | if len(req.Question) != 1 {
32 | log.Debugf("cannot handle dns query: multiple questions")
33 | return false
34 | }
35 | qtype := req.Question[0].Qtype
36 | if qtype != dns.TypeA && qtype != dns.TypeAAAA {
37 | log.Debugf("cannot handle dns query: not A/AAAA qtype")
38 | return false
39 | }
40 | qclass := req.Question[0].Qclass
41 | if qclass != dns.ClassINET {
42 | log.Debugf("cannot handle dns query: not ClassINET")
43 | return false
44 | }
45 | fqdn := req.Question[0].Name
46 | domain := fqdn[:len(fqdn)-1]
47 | if _, ok := dns.IsDomainName(domain); !ok {
48 | log.Debugf("cannot handle dns query: invalid domain name")
49 | return false
50 | }
51 | return true
52 | }
53 |
54 | func NewFakeDNS(ipnet *net.IPNet, size int) cdns.FakeDns {
55 | fP, _ := fakeip.New(ipnet, size, nil)
56 | return &fakeDNS{
57 | fakePool: fP,
58 | }
59 | }
60 |
61 | func (f *fakeDNS) QueryDomain(ip net.IP) string {
62 | domain, found := f.fakePool.LookBack(ip)
63 | if found {
64 | log.Debugf("fake dns returns domain %v for ip %v", domain, ip)
65 | }
66 | return domain
67 | }
68 |
69 | func (f *fakeDNS) GenerateFakeResponse(request []byte) ([]byte, error) {
70 | if !canHandleDnsQuery(request) {
71 | return nil, errors.New("cannot handle DNS request")
72 | }
73 | req := new(dns.Msg)
74 | req.Unpack(request)
75 | qtype := req.Question[0].Qtype
76 | fqdn := req.Question[0].Name
77 | domain := fqdn[:len(fqdn)-1]
78 | ip := f.fakePool.Lookup(domain) // fakeIP uses IPv4 range
79 | log.Debugf("fake dns allocated ip %v for domain %v", ip, domain)
80 | resp := new(dns.Msg)
81 | resp = resp.SetReply(req)
82 | if qtype == dns.TypeA {
83 | resp.Answer = append(resp.Answer, &dns.A{
84 | Hdr: dns.RR_Header{
85 | Name: fqdn,
86 | Rrtype: dns.TypeA,
87 | Class: dns.ClassINET,
88 | Ttl: FakeResponseTtl,
89 | Rdlength: net.IPv4len,
90 | },
91 | A: ip,
92 | })
93 | } else if qtype == dns.TypeAAAA {
94 | // use valid IPv6 form for resp.PackBuffer()
95 | ipMappedTov6 := net.ParseIP("::ffff:" + ip.String())
96 | resp.Answer = append(resp.Answer, &dns.AAAA{
97 | Hdr: dns.RR_Header{
98 | Name: fqdn,
99 | Rrtype: dns.TypeAAAA,
100 | Class: dns.ClassINET,
101 | Ttl: FakeResponseTtl,
102 | Rdlength: net.IPv6len,
103 | },
104 | AAAA: ipMappedTov6,
105 | })
106 | } else {
107 | return nil, fmt.Errorf("unexcepted dns qtype %v", qtype)
108 | }
109 | buf := pool.NewBytes(65535)
110 | defer pool.FreeBytes(buf)
111 | dnsAnswer, err := resp.PackBuffer(buf)
112 | if err != nil {
113 | return nil, fmt.Errorf("failed to pack dns answer: %v, err %v", resp.String(), err)
114 | }
115 | return append([]byte(nil), dnsAnswer...), nil
116 | }
117 |
118 | func (f *fakeDNS) IsFakeIP(ip net.IP) bool {
119 | return f.fakePool.Exist(ip)
120 | }
121 |
--------------------------------------------------------------------------------
/common/log/log.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | var logger Logger
4 |
5 | func RegisterLogger(l Logger) {
6 | logger = l
7 | }
8 |
9 | func SetLevel(level LogLevel) {
10 | if logger != nil {
11 | logger.SetLevel(level)
12 | }
13 | }
14 |
15 | func Debugf(msg string, args ...interface{}) {
16 | if logger != nil {
17 | logger.Debugf(msg, args...)
18 | }
19 | }
20 |
21 | func Infof(msg string, args ...interface{}) {
22 | if logger != nil {
23 | logger.Infof(msg, args...)
24 | }
25 | }
26 |
27 | func Warnf(msg string, args ...interface{}) {
28 | if logger != nil {
29 | logger.Warnf(msg, args...)
30 | }
31 | }
32 |
33 | func Errorf(msg string, args ...interface{}) {
34 | if logger != nil {
35 | logger.Errorf(msg, args...)
36 | }
37 | }
38 |
39 | func Fatalf(msg string, args ...interface{}) {
40 | if logger != nil {
41 | logger.Fatalf(msg, args...)
42 | }
43 | }
44 |
45 | func Access(process, outbound, network, localAddr, target string) {
46 | Infof("[%v] [%v] [%v] %s", outbound, network, process, target)
47 | }
48 |
--------------------------------------------------------------------------------
/common/log/logger.go:
--------------------------------------------------------------------------------
1 | package log
2 |
3 | type LogLevel uint8
4 |
5 | const (
6 | DEBUG LogLevel = iota
7 | INFO
8 | WARN
9 | ERROR
10 | NONE
11 | )
12 |
13 | type Logger interface {
14 | SetLevel(level LogLevel)
15 | Debugf(msg string, args ...interface{})
16 | Infof(msg string, args ...interface{})
17 | Warnf(msg string, args ...interface{})
18 | Errorf(msg string, args ...interface{})
19 | Fatalf(msg string, args ...interface{})
20 | }
21 |
--------------------------------------------------------------------------------
/common/log/simple/logger.go:
--------------------------------------------------------------------------------
1 | package simple
2 |
3 | import (
4 | golog "log"
5 |
6 | "github.com/eycorsican/go-tun2socks/common/log"
7 | )
8 |
9 | type simpleLogger struct {
10 | level log.LogLevel
11 | }
12 |
13 | func NewSimpleLogger() log.Logger {
14 | return &simpleLogger{log.INFO}
15 | }
16 |
17 | func (l *simpleLogger) SetLevel(level log.LogLevel) {
18 | l.level = level
19 | }
20 |
21 | func (l *simpleLogger) Debugf(msg string, args ...interface{}) {
22 | if l.level <= log.DEBUG {
23 | l.output(msg, args...)
24 | }
25 | }
26 |
27 | func (l *simpleLogger) Infof(msg string, args ...interface{}) {
28 | if l.level <= log.INFO {
29 | l.output(msg, args...)
30 | }
31 | }
32 |
33 | func (l *simpleLogger) Warnf(msg string, args ...interface{}) {
34 | if l.level <= log.WARN {
35 | l.output(msg, args...)
36 | }
37 | }
38 |
39 | func (l *simpleLogger) Errorf(msg string, args ...interface{}) {
40 | if l.level <= log.ERROR {
41 | l.output(msg, args...)
42 | }
43 | }
44 |
45 | func (l *simpleLogger) Fatalf(msg string, args ...interface{}) {
46 | golog.Fatalf(msg, args...)
47 | }
48 |
49 | func (l *simpleLogger) output(msg string, args ...interface{}) {
50 | golog.Printf(msg, args...)
51 | }
52 |
53 | func init() {
54 | log.RegisterLogger(NewSimpleLogger())
55 | }
56 |
--------------------------------------------------------------------------------
/common/log/simpleandroidlog/simpleandroidlog.go:
--------------------------------------------------------------------------------
1 | package simpleandroidlog
2 |
3 | import (
4 | "io"
5 | golog "log"
6 |
7 | "github.com/eycorsican/go-tun2socks/common/log"
8 | )
9 |
10 | var mylogger AndroidLogger
11 |
12 | type AndroidLogger interface {
13 | GetLevel() log.LogLevel
14 | log.Logger
15 | }
16 |
17 | type simpleAndroidLogger struct {
18 | level log.LogLevel
19 | prefix string
20 | }
21 |
22 | func NewSimpleAndroidLogger() AndroidLogger {
23 | return &simpleAndroidLogger{
24 | level: log.INFO,
25 | prefix: "[tun2socks] ",
26 | }
27 | }
28 |
29 | func (l *simpleAndroidLogger) SetLevel(level log.LogLevel) {
30 | l.level = level
31 | }
32 |
33 | func (l *simpleAndroidLogger) GetLevel() log.LogLevel {
34 | return l.level
35 | }
36 |
37 | func (l *simpleAndroidLogger) Debugf(msg string, args ...interface{}) {
38 | if l.level <= log.DEBUG {
39 | l.output(msg, args...)
40 | }
41 | }
42 |
43 | func (l *simpleAndroidLogger) Infof(msg string, args ...interface{}) {
44 | if l.level <= log.INFO {
45 | l.output(msg, args...)
46 | }
47 | }
48 |
49 | func (l *simpleAndroidLogger) Warnf(msg string, args ...interface{}) {
50 | if l.level <= log.WARN {
51 | l.output(msg, args...)
52 | }
53 | }
54 |
55 | func (l *simpleAndroidLogger) Errorf(msg string, args ...interface{}) {
56 | if l.level <= log.ERROR {
57 | l.output(msg, args...)
58 | }
59 | }
60 |
61 | func (l *simpleAndroidLogger) Fatalf(msg string, args ...interface{}) {
62 | golog.Fatalf(l.prefix+msg, args...)
63 | }
64 |
65 | func (l *simpleAndroidLogger) output(msg string, args ...interface{}) {
66 | golog.Printf(l.prefix+msg, args...)
67 | }
68 |
69 | func (l *simpleAndroidLogger) GetUnderlyingWriter() io.Writer {
70 | return golog.Writer()
71 | }
72 |
73 | func GetLogger() AndroidLogger {
74 | return mylogger
75 | }
76 |
77 | func init() {
78 | mylogger = NewSimpleAndroidLogger()
79 | log.RegisterLogger(mylogger)
80 | }
81 |
--------------------------------------------------------------------------------
/common/packet/packet.go:
--------------------------------------------------------------------------------
1 | package packet
2 |
3 | import (
4 | "encoding/binary"
5 | "net"
6 | )
7 |
8 | const (
9 | IPVERSION_4 = 4
10 | IPVERSION_6 = 6
11 |
12 | PROTOCOL_ICMP = 1
13 | PROTOCOL_TCP = 6
14 | PROTOCOL_UDP = 17
15 | )
16 |
17 | func PeekIPVersion(data []byte) uint8 {
18 | return uint8((data[0] & 0xf0) >> 4)
19 | }
20 |
21 | func PeekProtocol(data []byte) string {
22 | switch uint8(data[9]) {
23 | case PROTOCOL_ICMP:
24 | return "icmp"
25 | case PROTOCOL_TCP:
26 | return "tcp"
27 | case PROTOCOL_UDP:
28 | return "udp"
29 | default:
30 | return "unknown"
31 | }
32 | }
33 |
34 | func PeekSourceAddress(data []byte) net.IP {
35 | return net.IP(data[12:16])
36 | }
37 |
38 | func PeekSourcePort(data []byte) uint16 {
39 | ihl := uint8(data[0] & 0x0f)
40 | return binary.BigEndian.Uint16(data[ihl*4 : ihl*4+2])
41 | }
42 |
43 | func PeekDestinationAddress(data []byte) net.IP {
44 | return net.IP(data[16:20])
45 | }
46 |
47 | func PeekDestinationPort(data []byte) uint16 {
48 | ihl := uint8(data[0] & 0x0f)
49 | return binary.BigEndian.Uint16(data[ihl*4+2 : ihl*4+4])
50 | }
51 |
52 | func IsSYNSegment(data []byte) bool {
53 | ihl := uint8(data[0] & 0x0f)
54 | if uint8(data[ihl*4+13]&(1<<1)) == 0 {
55 | return false
56 | } else {
57 | return true
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/component/gls/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2018, Massimiliano Ghilardi
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/component/gls/README.md:
--------------------------------------------------------------------------------
1 | gls
2 | ===
3 |
4 | Fast goroutine local storage
5 |
6 | ### WARNING ###
7 |
8 | There is extensive documentation and discussion on why implementing and using
9 | thread-local storage in Go - actually, goroutine-local storage - is a bad idea.
10 |
11 | See for example the [Go FAQ on goroutine id](https://golang.org/doc/faq#no_goroutine_id)
12 | and [context.Context](https://blog.golang.org/context), which is how you're encouraged
13 | to solve problems that would require a goroutine-local storage.
14 |
15 | The main obstacle in adopting `context.Context` is that *all* of your functions
16 | must have a new first argument. So, if that horrifies you or is simply not feasible
17 | for your use case, feel free to ignore this warning and read on.
18 |
19 | Just remember that, if some Go programmers frowns at your use of goroutine-local
20 | storage, there are good reasons.
21 |
22 | ### Why? ###
23 |
24 | To retrieve per-goroutine data that some function did not - or could not -
25 | pass through the call chain, down to where you need it.
26 |
27 | Other goroutine-local libraries, as [jtolds/gls](https://github.com/jtolds/gls)
28 | and [tylerb/gls](https://github.com/tylerb/gls) explain the reasons
29 | and use cases for goroutine-local storage more in detail.
30 |
31 | ### Status ###
32 |
33 | Beta.
34 |
35 | Lightly tested on 386, amd64, arm, arm64, mips, ppc64le with Go 1.10.1.
36 | Other architectures (mipsle, mips64, ppc64, s390x) supported in theory but not tested.
37 |
38 | ### How it works ###
39 |
40 | Go runtime has an internal, i.e. unexported, goroutine-local `runtime.g` struct.
41 | It is used for several purposes, including `defer()`, `recover()`,
42 | by the goroutine scheduler, and it even has an unexported `goid` field,
43 | i.e. a goroutine ID.
44 |
45 | Several other goroutine-local libraries extract this goroutine ID
46 | with various tricks, most notably from `runtime.Stack()` textual output.
47 |
48 | Instead, we use a tiny bit of assembler code to retrieve the address
49 | of the `runtime.g` struct and return it converted to an opaque `uintptr`.
50 |
51 | We use it as the key in a global variable containing per-goroutine data.
52 |
53 | This is also **fast**, probably orders of magnitude faster than most other solutions.
54 |
55 | #### Why not the same goroutine ID? ####
56 |
57 | To avoid fiddling with the internal layout of `runtime.g` struct,
58 | we only take its address.
59 |
60 | Accessing the `goid` field would require knowing its offset within the struct,
61 | which is both tedious and error-prone to retrieve, since it's an unexported
62 | field of an unexported struct type.
63 |
64 | ### Documentation ###
65 |
66 | See the autogenerated API docs at http://godoc.org/github.com/cosmos72/gls
67 |
68 | ### License ###
69 |
70 | BSD 3-Clause License
71 |
72 |
--------------------------------------------------------------------------------
/component/gls/go_tls.h:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | #ifdef GOARCH_arm
6 | #define LR R14
7 | #endif
8 |
9 | #ifdef GOARCH_amd64
10 | #define get_tls(r) MOVQ TLS, r
11 | #define g(r) 0(r)(TLS*1)
12 | #endif
13 |
14 | #ifdef GOARCH_386
15 | #define get_tls(r) MOVL TLS, r
16 | #define g(r) 0(r)(TLS*1)
17 | #endif
18 |
--------------------------------------------------------------------------------
/component/gls/id.go:
--------------------------------------------------------------------------------
1 | package gls
2 |
3 | import (
4 | "github.com/v2pro/plz/reflect2"
5 | "log"
6 | "unsafe"
7 | )
8 |
9 | // offset for go1.4
10 | var goidOffset uintptr = 128
11 |
12 | func init() {
13 | gType := reflect2.TypeByName("runtime.g").(reflect2.StructType)
14 | if gType == nil {
15 | panic("failed to get runtime.g type")
16 | }
17 | goidField := gType.FieldByName("goid")
18 | goidOffset = goidField.Offset()
19 | log.Printf("goidOffset: %v", goidOffset)
20 | }
21 |
22 | // GoID returns the goroutine id of current goroutine
23 | func GoID() int64 {
24 | g := getg()
25 | p_goid := (*int64)(unsafe.Pointer(g + goidOffset))
26 | return *p_goid
27 | }
28 |
29 | func getg() uintptr
30 |
--------------------------------------------------------------------------------
/component/gls/id_386.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 |
6 | #include "go_asm.h"
7 | #include "textflag.h" // for NOSPLIT
8 | #include "go_tls.h"
9 |
10 | TEXT ·getg(SB),NOSPLIT,$0-4
11 | get_tls(CX)
12 | MOVL g(CX), AX
13 | MOVL AX, ret+0(FP)
14 | RET
15 |
--------------------------------------------------------------------------------
/component/gls/id_amd64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 |
6 | #include "go_asm.h"
7 | #include "textflag.h" // for NOSPLIT
8 | #include "go_tls.h"
9 |
10 | TEXT ·getg(SB),NOSPLIT,$0-8
11 | get_tls(CX)
12 | MOVQ g(CX), AX
13 | MOVQ AX, ret+0(FP)
14 | RET
15 |
--------------------------------------------------------------------------------
/component/gls/id_arm.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 |
6 | #include "go_asm.h"
7 | #include "textflag.h" // for NOSPLIT
8 | #include "go_tls.h"
9 |
10 | TEXT ·getg(SB),NOSPLIT,$0-4
11 | MOVW g, R8
12 | MOVW R8, ret+0(FP)
13 | RET
14 |
--------------------------------------------------------------------------------
/component/gls/id_arm64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 |
6 | #include "go_asm.h"
7 | #include "textflag.h" // for NOSPLIT
8 | #include "go_tls.h"
9 |
10 | TEXT ·getg(SB),NOSPLIT,$0-8
11 | MOVD g, ret+0(FP)
12 | RET
13 |
--------------------------------------------------------------------------------
/component/gls/id_mips.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build gc
6 |
7 | #include "go_asm.h"
8 | #include "textflag.h" // for NOSPLIT
9 | #include "go_tls.h"
10 |
11 | TEXT ·getg(SB),NOSPLIT|NOFRAME,$-4-4
12 | MOVW g, ret+0(FP)
13 | RET
14 |
--------------------------------------------------------------------------------
/component/gls/id_mips64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build gc
6 |
7 | #include "go_asm.h"
8 | #include "textflag.h" // for NOSPLIT
9 | #include "go_tls.h"
10 |
11 | TEXT ·getg(SB),NOSPLIT|NOFRAME,$-8-8
12 | MOVV g, ret+0(FP)
13 | RET
14 |
--------------------------------------------------------------------------------
/component/gls/id_mips64le.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build gc
6 |
7 | #include "go_asm.h"
8 | #include "textflag.h" // for NOSPLIT
9 | #include "go_tls.h"
10 |
11 | TEXT ·getg(SB),NOSPLIT|NOFRAME,$-8-8
12 | MOVV g, ret+0(FP)
13 | RET
14 |
--------------------------------------------------------------------------------
/component/gls/id_mipsle.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build gc
6 |
7 | #include "go_asm.h"
8 | #include "textflag.h" // for NOSPLIT
9 | #include "go_tls.h"
10 |
11 | TEXT ·getg(SB),NOSPLIT|NOFRAME,$-4-4
12 | MOVW g, ret+0(FP)
13 | RET
14 |
--------------------------------------------------------------------------------
/component/gls/id_ppc64.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build gc
6 |
7 | #include "go_asm.h"
8 | #include "textflag.h" // for NOSPLIT
9 | #include "go_tls.h"
10 |
11 | TEXT ·getg(SB),NOSPLIT,$0-8
12 | MOVD g, ret+0(FP)
13 | RET
14 |
--------------------------------------------------------------------------------
/component/gls/id_ppc64le.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build gc
6 |
7 | #include "go_asm.h"
8 | #include "textflag.h" // for NOSPLIT
9 | #include "go_tls.h"
10 |
11 | TEXT ·getg(SB),NOSPLIT,$0-8
12 | MOVD g, ret+0(FP)
13 | RET
14 |
--------------------------------------------------------------------------------
/component/gls/id_s390x.s:
--------------------------------------------------------------------------------
1 | // Copyright 2018 Massimiliano Ghilardi. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // +build gc
6 |
7 | #include "go_asm.h"
8 | #include "textflag.h" // for NOSPLIT
9 | #include "go_tls.h"
10 |
11 | TEXT ·getg(SB),NOSPLIT|NOFRAME,$0-8
12 | MOVD g, ret+0(FP)
13 | RET
14 |
--------------------------------------------------------------------------------
/component/go-syncex/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2018, go-syncex authors.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 | * Redistributions of source code must retain the above copyright
7 | notice, this list of conditions and the following disclaimer.
8 | * Redistributions in binary form must reproduce the above copyright
9 | notice, this list of conditions and the following disclaimer in the
10 | documentation and/or other materials provided with the distribution.
11 | * Neither the name of the go-syncex authors nor the
12 | names of its contributors may be used to endorse or promote products
13 | derived from this software without specific prior written permission.
14 |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 | DISCLAIMED. IN NO EVENT SHALL AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY
19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 |
--------------------------------------------------------------------------------
/component/go-syncex/README.md:
--------------------------------------------------------------------------------
1 | # syncex
2 |
3 | [](https://godoc.org/github.com/orkunkaraduman/go-syncex)
4 |
5 | Extended synchronization for GoLang.
6 |
7 | `syncex` includes:
8 | * RecursiveMutex (ReentrantMutex)
9 | * CriticalSection
10 |
--------------------------------------------------------------------------------
/component/go-syncex/criticalsection.go:
--------------------------------------------------------------------------------
1 | package syncex
2 |
3 | import (
4 | "sync"
5 | )
6 |
7 | // A CriticalSection is particular type of mutual exclusion (mutex) that
8 | // may be locked multiple times by the same owner.
9 | //
10 | // The CriticalSection is faster than RecursiveMutex.
11 | //
12 | // A CriticalSection must not be copied after first use.
13 | type CriticalSection struct {
14 | mu sync.Mutex
15 | c chan struct{}
16 | v int32
17 | id uint64
18 | }
19 |
20 | // Lock locks cs with given ownerID.
21 | // If cs is already owned by different owner, it waits
22 | // until the CriticalSection is available.
23 | func (cs *CriticalSection) Lock(ownerID uint64) {
24 | for {
25 | cs.mu.Lock()
26 | if cs.c == nil {
27 | cs.c = make(chan struct{}, 1)
28 | }
29 | if cs.v == 0 || cs.id == ownerID {
30 | cs.v++
31 | cs.id = ownerID
32 | cs.mu.Unlock()
33 | break
34 | }
35 | cs.mu.Unlock()
36 | <-cs.c
37 | }
38 | }
39 |
40 | // Unlock unlocks cs.
41 | // It panics if cs is not locked on entry to Unlock.
42 | func (cs *CriticalSection) Unlock() {
43 | cs.mu.Lock()
44 | if cs.c == nil {
45 | cs.c = make(chan struct{}, 1)
46 | }
47 | if cs.v <= 0 {
48 | cs.mu.Unlock()
49 | panic(ErrNotLocked)
50 | }
51 | cs.v--
52 | if cs.v == 0 {
53 | cs.id = 0
54 | }
55 | cs.mu.Unlock()
56 | select {
57 | case cs.c <- struct{}{}:
58 | default:
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/component/go-syncex/error.go:
--------------------------------------------------------------------------------
1 | package syncex
2 |
3 | import "errors"
4 |
5 | // Package specific errors.
6 | var (
7 | ErrNotLocked = errors.New("not locked")
8 | )
9 |
--------------------------------------------------------------------------------
/component/go-syncex/examples/CriticalSection/main.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | import (
6 | "fmt"
7 | "time"
8 |
9 | syncex "github.com/orkunkaraduman/go-syncex"
10 | )
11 |
12 | func main() {
13 | var cs syncex.CriticalSection
14 | var f int
15 | oid := syncex.NewOwnerID()
16 | cs.Lock(oid)
17 | for i := 0; i < 5; i++ {
18 | cs.Lock(oid)
19 | go func() {
20 | oid1 := syncex.NewOwnerID()
21 | cs.Lock(oid1)
22 | f++
23 | fmt.Println("goroutine: ", f)
24 | cs.Unlock()
25 | }()
26 | f++
27 | fmt.Println("forloop: ", f)
28 | cs.Unlock()
29 | }
30 | fmt.Println("mainfunc: ", f)
31 | cs.Unlock()
32 | time.Sleep(1 * time.Second)
33 | fmt.Println("mainfunc: ", f)
34 | }
35 |
--------------------------------------------------------------------------------
/component/go-syncex/examples/RecursiveMutex/main.go:
--------------------------------------------------------------------------------
1 | // +build ignore
2 |
3 | package main
4 |
5 | import (
6 | "fmt"
7 | "time"
8 |
9 | syncex "github.com/orkunkaraduman/go-syncex"
10 | )
11 |
12 | func main() {
13 | var mu syncex.RecursiveMutex
14 | var f int
15 | mu.Lock()
16 | for i := 0; i < 5; i++ {
17 | mu.Lock()
18 | go func() {
19 | mu.Lock()
20 | f++
21 | fmt.Println("goroutine: ", f)
22 | mu.Unlock()
23 | }()
24 | f++
25 | fmt.Println("forloop: ", f)
26 | mu.Unlock()
27 | }
28 | fmt.Println("mainfunc: ", f)
29 | mu.Unlock()
30 | time.Sleep(1 * time.Second)
31 | fmt.Println("mainfunc: ", f)
32 | }
33 |
--------------------------------------------------------------------------------
/component/go-syncex/recursivemutex.go:
--------------------------------------------------------------------------------
1 | package syncex
2 |
3 | import (
4 | hackgid "github.com/eycorsican/go-tun2socks/component/gls"
5 | "sync"
6 | )
7 |
8 | // A RecursiveMutex is particular type of mutual exclusion (mutex) that
9 | // may be locked multiple times by the same goroutine.
10 | //
11 | // A RecursiveMutex must not be copied after first use.
12 | type RecursiveMutex struct {
13 | mu sync.Mutex
14 | c chan struct{}
15 | v int32
16 | id uint64
17 | }
18 |
19 | // Lock locks rm.
20 | // If rm is already owned by different goroutine, it waits
21 | // until the RecursiveMutex is available.
22 | func (rm *RecursiveMutex) Lock() {
23 | //id := getGID()
24 | id := uint64(hackgid.GoID())
25 | for {
26 | rm.mu.Lock()
27 | if rm.c == nil {
28 | rm.c = make(chan struct{}, 1)
29 | }
30 | if rm.v == 0 || rm.id == id {
31 | rm.v++
32 | rm.id = id
33 | rm.mu.Unlock()
34 | break
35 | }
36 | rm.mu.Unlock()
37 | <-rm.c
38 | }
39 | }
40 |
41 | // Unlock unlocks rm.
42 | // It panics if rm is not locked on entry to Unlock.
43 | func (rm *RecursiveMutex) Unlock() {
44 | rm.mu.Lock()
45 | if rm.c == nil {
46 | rm.c = make(chan struct{}, 1)
47 | }
48 | if rm.v <= 0 {
49 | rm.mu.Unlock()
50 | panic(ErrNotLocked)
51 | }
52 | rm.v--
53 | if rm.v == 0 {
54 | rm.id = 0
55 | }
56 | rm.mu.Unlock()
57 | select {
58 | case rm.c <- struct{}{}:
59 | default:
60 | }
61 | }
62 |
63 | func init() {
64 | id1 := getGID()
65 | id2 := uint64(hackgid.GoID())
66 | if id1 != id2 {
67 | panic("hackgid and ordinary GID different")
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/component/go-syncex/reentrantmutex.go:
--------------------------------------------------------------------------------
1 | package syncex
2 |
3 | // ReentrantMutex is synonym for RecursiveMutex.
4 | type ReentrantMutex RecursiveMutex
5 |
--------------------------------------------------------------------------------
/component/go-syncex/utils.go:
--------------------------------------------------------------------------------
1 | package syncex
2 |
3 | import (
4 | "bytes"
5 | "runtime"
6 | "strconv"
7 | "sync/atomic"
8 | )
9 |
10 | func getGID() uint64 {
11 | var stack [64]byte
12 | b := stack[:runtime.Stack(stack[:], false)]
13 | b = bytes.TrimPrefix(b, []byte("goroutine "))
14 | b = b[:bytes.IndexByte(b, ' ')]
15 | n, e := strconv.ParseUint(string(b), 10, 64)
16 | if e != nil {
17 | panic(e)
18 | }
19 | return n
20 | }
21 |
22 | var ownerID = uint64(0)
23 |
24 | // NewOwnerID gives a new ownerID incrementally.
25 | func NewOwnerID() uint64 {
26 | atomic.CompareAndSwapUint64(&ownerID, ^uint64(0), 0)
27 | return atomic.AddUint64(&ownerID, 1)
28 | }
29 |
--------------------------------------------------------------------------------
/component/pool/pool.go:
--------------------------------------------------------------------------------
1 | package pool
2 |
3 | import (
4 | "sync"
5 | )
6 |
7 | var pool *sync.Pool
8 |
9 | const BufSize = 32 * 1024
10 |
11 | func NewBytes(size int) []byte {
12 | if size <= BufSize {
13 | return pool.Get().([]byte)
14 | } else {
15 | return make([]byte, size)
16 | }
17 | }
18 |
19 | func FreeBytes(b []byte) {
20 | b = b[0:cap(b)] // restore slice
21 | if cap(b) >= BufSize {
22 | pool.Put(b)
23 | }
24 | }
25 |
26 | func init() {
27 | pool = &sync.Pool{
28 | New: func() interface{} {
29 | // The Pool's New function should generally only return pointer
30 | // types, since a pointer can be put into the return interface
31 | // value without an allocation:
32 | return make([]byte, BufSize)
33 | },
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/component/runner/doc.go:
--------------------------------------------------------------------------------
1 | // Package runner provides interruptable goroutines.
2 | //
3 | // task := runner.Go(func(shouldStop runner.S) error {
4 | // // NEVER returns nil in this function
5 | // // do setup
6 | // // defer func(){
7 | // // // do teardown
8 | // // }
9 | // zeroErr := errors.New("no error")
10 | // for {
11 | // // do some work
12 | // var err error
13 | // if err != nil {
14 | // return err
15 | // }
16 | // if shouldStop() {
17 | // break
18 | // }
19 | // }
20 | // return zeroErr // any errors?
21 | // })
22 | //
23 | // // meanwhile...
24 | // // stop the task
25 | // task.Stop()
26 | //
27 | // // wait for it to stop (or time out)
28 | // select {
29 | // case <-task.StopChan():
30 | // // stopped
31 | // case <-time.After(1 * time.Second):
32 | // log.Fatalln("task didn't stop quickly enough")
33 | // }
34 | //
35 | // // check errors
36 | // if task.Err() != nil {
37 | // log.Fatalln("task failed:", task.Err())
38 | // }
39 | package runner
40 |
--------------------------------------------------------------------------------
/component/runner/runner.go:
--------------------------------------------------------------------------------
1 | package runner
2 |
3 | import (
4 | "sync"
5 | "sync/atomic"
6 | )
7 |
8 | // S is a function that will return true if the
9 | // goroutine should stop executing.
10 | type S func() bool
11 |
12 | const (
13 | FALSE int32 = 0
14 | TRUE int32 = 1
15 | )
16 |
17 | // Go executes the function in a goroutine and returns a
18 | // Task capable of stopping the execution.
19 | func Go(fn func(S) error) *Task {
20 | var run, stop int32
21 | t := &Task{
22 | stopChan: make(chan struct{}),
23 | running: &run,
24 | shouldStop: &stop,
25 | }
26 | atomic.StoreInt32(t.shouldStop, FALSE)
27 | atomic.StoreInt32(t.running, TRUE)
28 | go func() {
29 | // call the target function
30 | err := fn(func() bool {
31 | // this is the shouldStop() function available to the
32 | // target function
33 | shouldStop := atomic.LoadInt32(t.shouldStop)
34 | return shouldStop == TRUE
35 | })
36 | t.err.Store(err)
37 | atomic.StoreInt32(t.running, FALSE)
38 | var closeOnce sync.Once
39 |
40 | closeOnce.Do(t.closeOnceBody)
41 | }()
42 | return t
43 | }
44 |
45 | // Task represents an interruptable goroutine.
46 | type Task struct {
47 | ID string
48 | stopChan chan struct{}
49 | shouldStop *int32
50 | running *int32
51 | err atomic.Value
52 | }
53 |
54 | func (t *Task) closeOnceBody() {
55 | // channel closing is actually a sending operation
56 | close(t.stopChan)
57 | }
58 |
59 | // Stop tells the goroutine to stop.
60 | func (t *Task) Stop() {
61 | // When task is stopped from a different go-routine other than the one
62 | // that actually started it.
63 | atomic.StoreInt32(t.shouldStop, TRUE)
64 | }
65 |
66 | // StopChan gets the stop channel for this task.
67 | // Reading from this channel will block while the task is running, and will
68 | // unblock once the task has stopped (because the channel gets closed).
69 | func (t *Task) StopChan() <-chan struct{} {
70 | return t.stopChan
71 | }
72 |
73 | // Running gets whether the goroutine is
74 | // running or not.
75 | func (t *Task) Running() bool {
76 | running := atomic.LoadInt32(t.running)
77 | return running == TRUE
78 | }
79 |
80 | // Err gets the error returned by the goroutine.
81 | func (t *Task) Err() error {
82 | err := t.err.Load()
83 | return err.(error)
84 | }
85 |
--------------------------------------------------------------------------------
/component/trie/domain.go:
--------------------------------------------------------------------------------
1 | package trie
2 |
3 | import (
4 | "errors"
5 | "strings"
6 | )
7 |
8 | const (
9 | wildcard = "*"
10 | dotWildcard = ""
11 | complexWildcard = "+"
12 | domainStep = "."
13 | )
14 |
15 | var (
16 | // ErrInvalidDomain means insert domain is invalid
17 | ErrInvalidDomain = errors.New("invalid domain")
18 | )
19 |
20 | // DomainTrie contains the main logic for adding and searching nodes for domain segments.
21 | // support wildcard domain (e.g *.google.com)
22 | type DomainTrie struct {
23 | root *Node
24 | }
25 |
26 | func validAndSplitDomain(domain string) ([]string, bool) {
27 | if len(domain) <= 0 {
28 | return nil, false
29 | }
30 |
31 | if domain != "" && domain[len(domain)-1] == '.' {
32 | return nil, false
33 | }
34 |
35 | parts := strings.Split(domain, domainStep)
36 | if len(parts) == 1 {
37 | if parts[0] == "" {
38 | return nil, false
39 | }
40 |
41 | return parts, true
42 | }
43 |
44 | for _, part := range parts[1:] {
45 | if part == "" {
46 | return nil, false
47 | }
48 | }
49 |
50 | return parts, true
51 | }
52 |
53 | // Insert adds a node to the trie.
54 | // Support
55 | // 1. www.example.com
56 | // 2. *.example.com
57 | // 3. subdomain.*.example.com
58 | // 4. .example.com
59 | // 5. +.example.com
60 | func (t *DomainTrie) Insert(domain string, data interface{}) error {
61 | parts, valid := validAndSplitDomain(domain)
62 | if !valid {
63 | return ErrInvalidDomain
64 | }
65 |
66 | if parts[0] == complexWildcard {
67 | t.insert(parts[1:], data)
68 | parts[0] = dotWildcard
69 | t.insert(parts, data)
70 | } else {
71 | t.insert(parts, data)
72 | }
73 |
74 | return nil
75 | }
76 |
77 | func (t *DomainTrie) insert(parts []string, data interface{}) {
78 | node := t.root
79 | // reverse storage domain part to save space
80 | for i := len(parts) - 1; i >= 0; i-- {
81 | part := parts[i]
82 | if !node.hasChild(part) {
83 | node.addChild(part, newNode(nil))
84 | }
85 |
86 | node = node.getChild(part)
87 | }
88 |
89 | node.Data = data
90 | }
91 |
92 | // Search is the most important part of the Trie.
93 | // Priority as:
94 | // 1. static part
95 | // 2. wildcard domain
96 | // 2. dot wildcard domain
97 | func (t *DomainTrie) Search(domain string) *Node {
98 | parts, valid := validAndSplitDomain(domain)
99 | if !valid || parts[0] == "" {
100 | return nil
101 | }
102 |
103 | n := t.search(t.root, parts)
104 |
105 | if n == nil || n.Data == nil {
106 | return nil
107 | }
108 |
109 | return n
110 | }
111 |
112 | func (t *DomainTrie) search(node *Node, parts []string) *Node {
113 | if len(parts) == 0 {
114 | return node
115 | }
116 |
117 | if c := node.getChild(parts[len(parts)-1]); c != nil {
118 | if n := t.search(c, parts[:len(parts)-1]); n != nil {
119 | return n
120 | }
121 | }
122 |
123 | if c := node.getChild(wildcard); c != nil {
124 | if n := t.search(c, parts[:len(parts)-1]); n != nil {
125 | return n
126 | }
127 | }
128 |
129 | if c := node.getChild(dotWildcard); c != nil {
130 | return c
131 | }
132 |
133 | return nil
134 | }
135 |
136 | // New returns a new, empty Trie.
137 | func New() *DomainTrie {
138 | return &DomainTrie{root: newNode(nil)}
139 | }
140 |
--------------------------------------------------------------------------------
/component/trie/node.go:
--------------------------------------------------------------------------------
1 | package trie
2 |
3 | // Node is the trie's node
4 | type Node struct {
5 | Data interface{}
6 | children map[string]*Node
7 | }
8 |
9 | func (n *Node) getChild(s string) *Node {
10 | return n.children[s]
11 | }
12 |
13 | func (n *Node) hasChild(s string) bool {
14 | return n.getChild(s) != nil
15 | }
16 |
17 | func (n *Node) addChild(s string, child *Node) {
18 | n.children[s] = child
19 | }
20 |
21 | func newNode(data interface{}) *Node {
22 | return &Node{
23 | Data: data,
24 | children: map[string]*Node{},
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/core/addr.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | import (
4 | "net"
5 | "strconv"
6 | )
7 |
8 | func ParseTCPAddr(addr string, port uint16) *net.TCPAddr {
9 | netAddr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(addr, strconv.Itoa(int(port))))
10 | if err != nil {
11 | return nil
12 | }
13 | return netAddr
14 | }
15 |
16 | func ParseUDPAddr(addr string, port uint16) *net.UDPAddr {
17 | netAddr, err := net.ResolveUDPAddr("udp", net.JoinHostPort(addr, strconv.Itoa(int(port))))
18 | if err != nil {
19 | return nil
20 | }
21 | return netAddr
22 | }
23 |
--------------------------------------------------------------------------------
/core/c/core/altcp_alloc.c:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * Application layered TCP connection API (to be used from TCPIP thread)
4 | * This interface mimics the tcp callback API to the application while preventing
5 | * direct linking (much like virtual functions).
6 | * This way, an application can make use of other application layer protocols
7 | * on top of TCP without knowing the details (e.g. TLS, proxy connection).
8 | *
9 | * This file contains allocation implementation that combine several layers.
10 | */
11 |
12 | /*
13 | * Copyright (c) 2017 Simon Goldschmidt
14 | * All rights reserved.
15 | *
16 | * Redistribution and use in source and binary forms, with or without modification,
17 | * are permitted provided that the following conditions are met:
18 | *
19 | * 1. Redistributions of source code must retain the above copyright notice,
20 | * this list of conditions and the following disclaimer.
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | * 3. The name of the author may not be used to endorse or promote products
25 | * derived from this software without specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
28 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
30 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
32 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
36 | * OF SUCH DAMAGE.
37 | *
38 | * This file is part of the lwIP TCP/IP stack.
39 | *
40 | * Author: Simon Goldschmidt
41 | *
42 | */
43 |
44 | #include "lwip/opt.h"
45 |
46 | #if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */
47 |
48 | #include "lwip/altcp.h"
49 | #include "lwip/altcp_tcp.h"
50 | #include "lwip/altcp_tls.h"
51 | #include "lwip/priv/altcp_priv.h"
52 | #include "lwip/mem.h"
53 |
54 | #include
55 |
56 | #if LWIP_ALTCP_TLS
57 |
58 | /** This standard allocator function creates an altcp pcb for
59 | * TLS over TCP */
60 | struct altcp_pcb *
61 | altcp_tls_new(struct altcp_tls_config *config, u8_t ip_type)
62 | {
63 | struct altcp_pcb *inner_conn, *ret;
64 | LWIP_UNUSED_ARG(ip_type);
65 |
66 | inner_conn = altcp_tcp_new_ip_type(ip_type);
67 | if (inner_conn == NULL) {
68 | return NULL;
69 | }
70 | ret = altcp_tls_wrap(config, inner_conn);
71 | if (ret == NULL) {
72 | altcp_close(inner_conn);
73 | }
74 | return ret;
75 | }
76 |
77 | /** This standard allocator function creates an altcp pcb for
78 | * TLS over TCP */
79 | struct altcp_pcb *
80 | altcp_tls_alloc(void *arg, u8_t ip_type)
81 | {
82 | return altcp_tls_new((struct altcp_tls_config *)arg, ip_type);
83 | }
84 |
85 | #endif /* LWIP_ALTCP_TLS */
86 |
87 | #endif /* LWIP_ALTCP */
88 |
--------------------------------------------------------------------------------
/core/c/core/ipv6/inet6.c:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | *
4 | * INET v6 addresses.
5 | */
6 |
7 | /*
8 | * Copyright (c) 2010 Inico Technologies Ltd.
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | *
14 | * 1. Redistributions of source code must retain the above copyright notice,
15 | * this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | * 3. The name of the author may not be used to endorse or promote products
20 | * derived from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 | * OF SUCH DAMAGE.
32 | *
33 | * This file is part of the lwIP TCP/IP stack.
34 | *
35 | * Author: Ivan Delamer
36 | *
37 | *
38 | * Please coordinate changes and requests with Ivan Delamer
39 | *
40 | */
41 |
42 | #include "lwip/opt.h"
43 |
44 | #if LWIP_IPV6 && LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
45 |
46 | #include "lwip/def.h"
47 | #include "lwip/inet.h"
48 |
49 | /** This variable is initialized by the system to contain the wildcard IPv6 address.
50 | */
51 | const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
52 |
53 | #endif /* LWIP_IPV6 */
54 |
--------------------------------------------------------------------------------
/core/c/custom/arch/bpstruct.h:
--------------------------------------------------------------------------------
1 | #pragma pack(push,1)
2 |
--------------------------------------------------------------------------------
/core/c/custom/arch/cc.h:
--------------------------------------------------------------------------------
1 | #ifdef _WIN32
2 | // both win32 and win64 are defined here
3 | #include "cc_windows.h"
4 | #elif defined(__ANDROID__) || defined(ANDROID) || defined(TUN2SOCKS)
5 | #include "cc_android.h"
6 | #else
7 | #include "cc_others.h"
8 | #endif
9 |
--------------------------------------------------------------------------------
/core/c/custom/arch/cc_android.h:
--------------------------------------------------------------------------------
1 | #ifndef LWIP_ARCH_CC_ANDROID_H
2 | #define LWIP_ARCH_CC_ANDROID_H
3 |
4 | /* Include some files for defining library routines */
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 |
12 | #include
13 |
14 | #define LWIP_TIMEVAL_PRIVATE 0
15 |
16 | /* Compiler hints for packing structures */
17 | #define PACK_STRUCT_FIELD(x) x
18 | #define PACK_STRUCT_STRUCT __attribute__((packed))
19 | #define PACK_STRUCT_BEGIN
20 | #define PACK_STRUCT_END
21 |
22 | #define MY_ANDROID_LOG_TAG "Trojan-TUN-lwIP"
23 | #define MY_ANDROID_PRINT(...) __android_log_print(ANDROID_LOG_ERROR, MY_ANDROID_LOG_TAG, ## __VA_ARGS__)
24 |
25 | /* Plaform specific diagnostic output */
26 | #define LWIP_PLATFORM_DIAG(...) do { \
27 | MY_ANDROID_PRINT("%s/%s(%d): ", __FILE__, __func__, __LINE__); \
28 | MY_ANDROID_PRINT __VA_ARGS__; \
29 | MY_ANDROID_PRINT("\n"); \
30 | } while(0)
31 |
32 | #define LWIP_PLATFORM_ASSERT(...) do { \
33 | MY_ANDROID_PRINT("[Assert]%s/%s(%d): %s\n", __FILE__, __func__, __LINE__, __VA_ARGS__); \
34 | abort(); \
35 | } while(0)
36 |
37 | /*
38 | struct sio_status_s;
39 | typedef struct sio_status_s sio_status_t;
40 | #define sio_fd_t sio_status_t*
41 | #define __sio_fd_t_defined
42 | */
43 |
44 | #endif /* LWIP_ARCH_CC_ANDROID_H */
45 |
--------------------------------------------------------------------------------
/core/c/custom/arch/epstruct.h:
--------------------------------------------------------------------------------
1 | #pragma pack(pop)
2 |
--------------------------------------------------------------------------------
/core/c/custom/arch/perf.h:
--------------------------------------------------------------------------------
1 | #ifndef perf_h
2 | #define perf_h
3 |
4 | #define PERF_START
5 | #define PERF_STOP(x)
6 |
7 | #endif /* perf_h */
8 |
--------------------------------------------------------------------------------
/core/c/custom/arch/sys_arch.h:
--------------------------------------------------------------------------------
1 | #ifndef __ARCH_SYS_ARCH_H__
2 | #define __ARCH_SYS_ARCH_H__
3 |
4 | #define SYS_MBOX_NULL NULL
5 | #define SYS_SEM_NULL NULL
6 |
7 | #endif /* __ARCH_SYS_ARCH_H__ */
8 |
--------------------------------------------------------------------------------
/core/c/include/compat/posix/arpa/inet.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * This file is a posix wrapper for lwip/sockets.h.
4 | */
5 |
6 | /*
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * 3. The name of the author may not be used to endorse or promote products
16 | * derived from this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 | * OF SUCH DAMAGE.
28 | *
29 | * This file is part of the lwIP TCP/IP stack.
30 | *
31 | */
32 |
33 | #include "lwip/sockets.h"
34 |
--------------------------------------------------------------------------------
/core/c/include/compat/posix/net/if.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * This file is a posix wrapper for lwip/if_api.h.
4 | */
5 |
6 | /*
7 | * Copyright (c) 2017 Joel Cunningham, Garmin International, Inc.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 | * OF SUCH DAMAGE.
31 | *
32 | * This file is part of the lwIP TCP/IP stack.
33 | *
34 | */
35 |
36 | #include "lwip/if_api.h"
37 |
--------------------------------------------------------------------------------
/core/c/include/compat/posix/netdb.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * This file is a posix wrapper for lwip/netdb.h.
4 | */
5 |
6 | /*
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * 3. The name of the author may not be used to endorse or promote products
16 | * derived from this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 | * OF SUCH DAMAGE.
28 | *
29 | * This file is part of the lwIP TCP/IP stack.
30 | *
31 | */
32 |
33 | #include "lwip/netdb.h"
34 |
--------------------------------------------------------------------------------
/core/c/include/compat/posix/sys/socket.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * This file is a posix wrapper for lwip/sockets.h.
4 | */
5 |
6 | /*
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * 3. The name of the author may not be used to endorse or promote products
16 | * derived from this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 | * OF SUCH DAMAGE.
28 | *
29 | * This file is part of the lwIP TCP/IP stack.
30 | *
31 | */
32 |
33 | #include "lwip/sockets.h"
34 |
--------------------------------------------------------------------------------
/core/c/include/compat/stdc/errno.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * This file is a posix/stdc wrapper for lwip/errno.h.
4 | */
5 |
6 | /*
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * 3. The name of the author may not be used to endorse or promote products
16 | * derived from this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 | * OF SUCH DAMAGE.
28 | *
29 | * This file is part of the lwIP TCP/IP stack.
30 | *
31 | */
32 |
33 | #include "lwip/errno.h"
34 |
--------------------------------------------------------------------------------
/core/c/include/lwip/altcp_tcp.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * Application layered TCP connection API (to be used from TCPIP thread)
4 | * This interface mimics the tcp callback API to the application while preventing
5 | * direct linking (much like virtual functions).
6 | * This way, an application can make use of other application layer protocols
7 | * on top of TCP without knowing the details (e.g. TLS, proxy connection).
8 | *
9 | * This file contains the base implementation calling into tcp.
10 | */
11 |
12 | /*
13 | * Copyright (c) 2017 Simon Goldschmidt
14 | * All rights reserved.
15 | *
16 | * Redistribution and use in source and binary forms, with or without modification,
17 | * are permitted provided that the following conditions are met:
18 | *
19 | * 1. Redistributions of source code must retain the above copyright notice,
20 | * this list of conditions and the following disclaimer.
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | * 3. The name of the author may not be used to endorse or promote products
25 | * derived from this software without specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
28 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
30 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
32 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
36 | * OF SUCH DAMAGE.
37 | *
38 | * This file is part of the lwIP TCP/IP stack.
39 | *
40 | * Author: Simon Goldschmidt
41 | *
42 | */
43 | #ifndef LWIP_HDR_ALTCP_TCP_H
44 | #define LWIP_HDR_ALTCP_TCP_H
45 |
46 | #include "lwip/opt.h"
47 |
48 | #if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */
49 |
50 | #include "lwip/altcp.h"
51 |
52 | #ifdef __cplusplus
53 | extern "C" {
54 | #endif
55 |
56 | struct altcp_pcb *altcp_tcp_new_ip_type(u8_t ip_type);
57 |
58 | #define altcp_tcp_new() altcp_tcp_new_ip_type(IPADDR_TYPE_V4)
59 | #define altcp_tcp_new_ip6() altcp_tcp_new_ip_type(IPADDR_TYPE_V6)
60 |
61 | struct altcp_pcb *altcp_tcp_alloc(void *arg, u8_t ip_type);
62 |
63 | struct tcp_pcb;
64 | struct altcp_pcb *altcp_tcp_wrap(struct tcp_pcb *tpcb);
65 |
66 | #ifdef __cplusplus
67 | }
68 | #endif
69 |
70 | #endif /* LWIP_ALTCP */
71 |
72 | #endif /* LWIP_HDR_ALTCP_TCP_H */
73 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/FILES:
--------------------------------------------------------------------------------
1 | This directory contains application headers.
2 | Every application shall provide one api file APP.h and optionally one options file APP_opts.h
3 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/altcp_proxyconnect.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * Application layered TCP connection API that executes a proxy-connect.
4 | *
5 | * This file provides a starting layer that executes a proxy-connect e.g. to
6 | * set up TLS connections through a http proxy.
7 | */
8 |
9 | /*
10 | * Copyright (c) 2018 Simon Goldschmidt
11 | * All rights reserved.
12 | *
13 | * Redistribution and use in source and binary forms, with or without modification,
14 | * are permitted provided that the following conditions are met:
15 | *
16 | * 1. Redistributions of source code must retain the above copyright notice,
17 | * this list of conditions and the following disclaimer.
18 | * 2. Redistributions in binary form must reproduce the above copyright notice,
19 | * this list of conditions and the following disclaimer in the documentation
20 | * and/or other materials provided with the distribution.
21 | * 3. The name of the author may not be used to endorse or promote products
22 | * derived from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 | * OF SUCH DAMAGE.
34 | *
35 | * This file is part of the lwIP TCP/IP stack.
36 | *
37 | * Author: Simon Goldschmidt
38 | *
39 | */
40 |
41 | #ifndef LWIP_HDR_APPS_ALTCP_PROXYCONNECT_H
42 | #define LWIP_HDR_APPS_ALTCP_PROXYCONNECT_H
43 |
44 | #include "lwip/opt.h"
45 |
46 | #if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */
47 |
48 | #include "lwip/ip_addr.h"
49 |
50 | #ifdef __cplusplus
51 | extern "C" {
52 | #endif
53 |
54 | struct altcp_proxyconnect_config {
55 | ip_addr_t proxy_addr;
56 | u16_t proxy_port;
57 | };
58 |
59 |
60 | struct altcp_pcb *altcp_proxyconnect_new(struct altcp_proxyconnect_config *config, struct altcp_pcb *inner_pcb);
61 | struct altcp_pcb *altcp_proxyconnect_new_tcp(struct altcp_proxyconnect_config *config, u8_t ip_type);
62 |
63 | struct altcp_pcb *altcp_proxyconnect_alloc(void *arg, u8_t ip_type);
64 |
65 | #if LWIP_ALTCP_TLS
66 | struct altcp_proxyconnect_tls_config {
67 | struct altcp_proxyconnect_config proxy;
68 | struct altcp_tls_config *tls_config;
69 | };
70 |
71 | struct altcp_pcb *altcp_proxyconnect_tls_alloc(void *arg, u8_t ip_type);
72 | #endif /* LWIP_ALTCP_TLS */
73 |
74 | #ifdef __cplusplus
75 | }
76 | #endif
77 |
78 | #endif /* LWIP_ALTCP */
79 | #endif /* LWIP_HDR_APPS_ALTCP_PROXYCONNECT_H */
80 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/mqtt_opts.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * MQTT client options
4 | */
5 |
6 | /*
7 | * Copyright (c) 2016 Erik Andersson
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 | * OF SUCH DAMAGE.
31 | *
32 | * This file is part of the lwIP TCP/IP stack.
33 | *
34 | * Author: Erik Andersson
35 | *
36 | */
37 | #ifndef LWIP_HDR_APPS_MQTT_OPTS_H
38 | #define LWIP_HDR_APPS_MQTT_OPTS_H
39 |
40 | #include "lwip/opt.h"
41 |
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 |
46 | /**
47 | * @defgroup mqtt_opts Options
48 | * @ingroup mqtt
49 | * @{
50 | */
51 |
52 | /**
53 | * Output ring-buffer size, must be able to fit largest outgoing publish message topic+payloads
54 | */
55 | #ifndef MQTT_OUTPUT_RINGBUF_SIZE
56 | #define MQTT_OUTPUT_RINGBUF_SIZE 256
57 | #endif
58 |
59 | /**
60 | * Number of bytes in receive buffer, must be at least the size of the longest incoming topic + 8
61 | * If one wants to avoid fragmented incoming publish, set length to max incoming topic length + max payload length + 8
62 | */
63 | #ifndef MQTT_VAR_HEADER_BUFFER_LEN
64 | #define MQTT_VAR_HEADER_BUFFER_LEN 128
65 | #endif
66 |
67 | /**
68 | * Maximum number of pending subscribe, unsubscribe and publish requests to server .
69 | */
70 | #ifndef MQTT_REQ_MAX_IN_FLIGHT
71 | #define MQTT_REQ_MAX_IN_FLIGHT 4
72 | #endif
73 |
74 | /**
75 | * Seconds between each cyclic timer call.
76 | */
77 | #ifndef MQTT_CYCLIC_TIMER_INTERVAL
78 | #define MQTT_CYCLIC_TIMER_INTERVAL 5
79 | #endif
80 |
81 | /**
82 | * Publish, subscribe and unsubscribe request timeout in seconds.
83 | */
84 | #ifndef MQTT_REQ_TIMEOUT
85 | #define MQTT_REQ_TIMEOUT 30
86 | #endif
87 |
88 | /**
89 | * Seconds for MQTT connect response timeout after sending connect request
90 | */
91 | #ifndef MQTT_CONNECT_TIMOUT
92 | #define MQTT_CONNECT_TIMOUT 100
93 | #endif
94 |
95 | /**
96 | * @}
97 | */
98 |
99 | #ifdef __cplusplus
100 | }
101 | #endif
102 |
103 | #endif /* LWIP_HDR_APPS_MQTT_OPTS_H */
104 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/netbiosns.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * NETBIOS name service responder
4 | */
5 |
6 | /*
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * 3. The name of the author may not be used to endorse or promote products
16 | * derived from this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 | * OF SUCH DAMAGE.
28 | *
29 | * This file is part of the lwIP TCP/IP stack.
30 | *
31 | */
32 | #ifndef LWIP_HDR_APPS_NETBIOS_H
33 | #define LWIP_HDR_APPS_NETBIOS_H
34 |
35 | #include "lwip/apps/netbiosns_opts.h"
36 |
37 | #ifdef __cplusplus
38 | extern "C" {
39 | #endif
40 |
41 | void netbiosns_init(void);
42 | #ifndef NETBIOS_LWIP_NAME
43 | void netbiosns_set_name(const char* hostname);
44 | #endif
45 | void netbiosns_stop(void);
46 |
47 | #ifdef __cplusplus
48 | }
49 | #endif
50 |
51 | #endif /* LWIP_HDR_APPS_NETBIOS_H */
52 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/netbiosns_opts.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * NETBIOS name service responder options
4 | */
5 |
6 | /*
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * 3. The name of the author may not be used to endorse or promote products
16 | * derived from this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 | * OF SUCH DAMAGE.
28 | *
29 | * This file is part of the lwIP TCP/IP stack.
30 | *
31 | */
32 | #ifndef LWIP_HDR_APPS_NETBIOS_OPTS_H
33 | #define LWIP_HDR_APPS_NETBIOS_OPTS_H
34 |
35 | #include "lwip/opt.h"
36 |
37 | /**
38 | * @defgroup netbiosns_opts Options
39 | * @ingroup netbiosns
40 | * @{
41 | */
42 |
43 | /** NetBIOS name of lwip device
44 | * This must be uppercase until NETBIOS_STRCMP() is defined to a string
45 | * comparison function that is case insensitive.
46 | * If you want to use the netif's hostname, use this (with LWIP_NETIF_HOSTNAME):
47 | * (ip_current_netif() != NULL ? ip_current_netif()->hostname != NULL ? ip_current_netif()->hostname : "" : "")
48 | *
49 | * If this is not defined, netbiosns_set_name() can be called at runtime to change the name.
50 | */
51 | #ifdef __DOXYGEN__
52 | #define NETBIOS_LWIP_NAME "NETBIOSLWIPDEV"
53 | #endif
54 |
55 | /** Respond to NetBIOS name queries
56 | * Default is disabled
57 | */
58 | #if !defined LWIP_NETBIOS_RESPOND_NAME_QUERY || defined __DOXYGEN__
59 | #define LWIP_NETBIOS_RESPOND_NAME_QUERY 0
60 | #endif
61 |
62 | /**
63 | * @}
64 | */
65 |
66 | #endif /* LWIP_HDR_APPS_NETBIOS_OPTS_H */
67 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/smtp_opts.h:
--------------------------------------------------------------------------------
1 | #ifndef LWIP_HDR_APPS_SMTP_OPTS_H
2 | #define LWIP_HDR_APPS_SMTP_OPTS_H
3 |
4 | #include "lwip/opt.h"
5 |
6 | #ifdef __cplusplus
7 | extern "C" {
8 | #endif
9 |
10 | /**
11 | * @defgroup smtp_opts Options
12 | * @ingroup smtp
13 | *
14 | * @{
15 | */
16 |
17 | /** Set this to 1 to enable data handler callback on BODY */
18 | #ifndef SMTP_BODYDH
19 | #define SMTP_BODYDH 0
20 | #endif
21 |
22 | /** SMTP_DEBUG: Enable debugging for SNTP. */
23 | #ifndef SMTP_DEBUG
24 | #define SMTP_DEBUG LWIP_DBG_OFF
25 | #endif
26 |
27 | /** Maximum length reserved for server name including terminating 0 byte */
28 | #ifndef SMTP_MAX_SERVERNAME_LEN
29 | #define SMTP_MAX_SERVERNAME_LEN 256
30 | #endif
31 |
32 | /** Maximum length reserved for username */
33 | #ifndef SMTP_MAX_USERNAME_LEN
34 | #define SMTP_MAX_USERNAME_LEN 32
35 | #endif
36 |
37 | /** Maximum length reserved for password */
38 | #ifndef SMTP_MAX_PASS_LEN
39 | #define SMTP_MAX_PASS_LEN 32
40 | #endif
41 |
42 | /** Set this to 0 if you know the authentication data will not change
43 | * during the smtp session, which saves some heap space. */
44 | #ifndef SMTP_COPY_AUTHDATA
45 | #define SMTP_COPY_AUTHDATA 1
46 | #endif
47 |
48 | /** Set this to 0 to save some code space if you know for sure that all data
49 | * passed to this module conforms to the requirements in the SMTP RFC.
50 | * WARNING: use this with care!
51 | */
52 | #ifndef SMTP_CHECK_DATA
53 | #define SMTP_CHECK_DATA 1
54 | #endif
55 |
56 | /** Set this to 1 to enable AUTH PLAIN support */
57 | #ifndef SMTP_SUPPORT_AUTH_PLAIN
58 | #define SMTP_SUPPORT_AUTH_PLAIN 1
59 | #endif
60 |
61 | /** Set this to 1 to enable AUTH LOGIN support */
62 | #ifndef SMTP_SUPPORT_AUTH_LOGIN
63 | #define SMTP_SUPPORT_AUTH_LOGIN 1
64 | #endif
65 |
66 | /* Memory allocation/deallocation can be overridden... */
67 | #ifndef SMTP_STATE_MALLOC
68 | #define SMTP_STATE_MALLOC(size) mem_malloc(size)
69 | #define SMTP_STATE_FREE(ptr) mem_free(ptr)
70 | #endif
71 |
72 | /**
73 | * @}
74 | */
75 |
76 | #ifdef __cplusplus
77 | }
78 | #endif
79 |
80 | #endif /* SMTP_OPTS_H */
81 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/snmp_mib2.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * SNMP MIB2 API
4 | */
5 |
6 | /*
7 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 | * OF SUCH DAMAGE.
31 | *
32 | * This file is part of the lwIP TCP/IP stack.
33 | *
34 | * Author: Dirk Ziegelmeier
35 | *
36 | */
37 | #ifndef LWIP_HDR_APPS_SNMP_MIB2_H
38 | #define LWIP_HDR_APPS_SNMP_MIB2_H
39 |
40 | #include "lwip/apps/snmp_opts.h"
41 |
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 |
46 | #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
47 | #if SNMP_LWIP_MIB2
48 |
49 | #include "lwip/apps/snmp_core.h"
50 |
51 | extern const struct snmp_mib mib2;
52 |
53 | #if SNMP_USE_NETCONN
54 | #include "lwip/apps/snmp_threadsync.h"
55 | void snmp_mib2_lwip_synchronizer(snmp_threadsync_called_fn fn, void* arg);
56 | extern struct snmp_threadsync_instance snmp_mib2_lwip_locks;
57 | #endif
58 |
59 | #ifndef SNMP_SYSSERVICES
60 | #define SNMP_SYSSERVICES ((1 << 6) | (1 << 3) | ((IP_FORWARD) << 2))
61 | #endif
62 |
63 | void snmp_mib2_set_sysdescr(const u8_t* str, const u16_t* len); /* read-only be definition */
64 | void snmp_mib2_set_syscontact(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize);
65 | void snmp_mib2_set_syscontact_readonly(const u8_t *ocstr, const u16_t *ocstrlen);
66 | void snmp_mib2_set_sysname(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize);
67 | void snmp_mib2_set_sysname_readonly(const u8_t *ocstr, const u16_t *ocstrlen);
68 | void snmp_mib2_set_syslocation(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize);
69 | void snmp_mib2_set_syslocation_readonly(const u8_t *ocstr, const u16_t *ocstrlen);
70 |
71 | #endif /* SNMP_LWIP_MIB2 */
72 | #endif /* LWIP_SNMP */
73 |
74 | #ifdef __cplusplus
75 | }
76 | #endif
77 |
78 | #endif /* LWIP_HDR_APPS_SNMP_MIB2_H */
79 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/snmp_snmpv2_framework.h:
--------------------------------------------------------------------------------
1 | /*
2 | Generated by LwipMibCompiler
3 | */
4 |
5 | #ifndef LWIP_HDR_APPS_SNMP_FRAMEWORK_MIB_H
6 | #define LWIP_HDR_APPS_SNMP_FRAMEWORK_MIB_H
7 |
8 | #include "lwip/apps/snmp_opts.h"
9 | #if LWIP_SNMP
10 |
11 | #ifdef __cplusplus
12 | extern "C" {
13 | #endif /* __cplusplus */
14 |
15 | #include "lwip/apps/snmp_core.h"
16 |
17 | extern const struct snmp_obj_id usmNoAuthProtocol;
18 | extern const struct snmp_obj_id usmHMACMD5AuthProtocol;
19 | extern const struct snmp_obj_id usmHMACSHAAuthProtocol;
20 |
21 | extern const struct snmp_obj_id usmNoPrivProtocol;
22 | extern const struct snmp_obj_id usmDESPrivProtocol;
23 | extern const struct snmp_obj_id usmAESPrivProtocol;
24 |
25 | extern const struct snmp_mib snmpframeworkmib;
26 |
27 | #ifdef __cplusplus
28 | }
29 | #endif /* __cplusplus */
30 |
31 | #endif /* LWIP_SNMP */
32 | #endif /* LWIP_HDR_APPS_SNMP_FRAMEWORK_MIB_H */
33 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/snmp_snmpv2_usm.h:
--------------------------------------------------------------------------------
1 | /*
2 | Generated by LwipMibCompiler
3 | */
4 |
5 | #ifndef LWIP_HDR_APPS_SNMP_USER_BASED_SM_MIB_H
6 | #define LWIP_HDR_APPS_SNMP_USER_BASED_SM_MIB_H
7 |
8 | #include "lwip/apps/snmp_opts.h"
9 | #if LWIP_SNMP
10 |
11 | #ifdef __cplusplus
12 | extern "C" {
13 | #endif /* __cplusplus */
14 |
15 | #include "lwip/apps/snmp_core.h"
16 |
17 | extern const struct snmp_mib snmpusmmib;
18 |
19 | #ifdef __cplusplus
20 | }
21 | #endif /* __cplusplus */
22 |
23 | #endif /* LWIP_SNMP */
24 | #endif /* LWIP_HDR_APPS_SNMP_USER_BASED_SM_MIB_H */
25 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/sntp.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * SNTP client API
4 | */
5 |
6 | /*
7 | * Copyright (c) 2007-2009 Frédéric Bernon, Simon Goldschmidt
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 | * OF SUCH DAMAGE.
31 | *
32 | * This file is part of the lwIP TCP/IP stack.
33 | *
34 | * Author: Frédéric Bernon, Simon Goldschmidt
35 | *
36 | */
37 | #ifndef LWIP_HDR_APPS_SNTP_H
38 | #define LWIP_HDR_APPS_SNTP_H
39 |
40 | #include "lwip/apps/sntp_opts.h"
41 | #include "lwip/ip_addr.h"
42 |
43 | #ifdef __cplusplus
44 | extern "C" {
45 | #endif
46 |
47 | /* SNTP operating modes: default is to poll using unicast.
48 | The mode has to be set before calling sntp_init(). */
49 | #define SNTP_OPMODE_POLL 0
50 | #define SNTP_OPMODE_LISTENONLY 1
51 | void sntp_setoperatingmode(u8_t operating_mode);
52 | u8_t sntp_getoperatingmode(void);
53 |
54 | void sntp_init(void);
55 | void sntp_stop(void);
56 | u8_t sntp_enabled(void);
57 |
58 | void sntp_setserver(u8_t idx, const ip_addr_t *addr);
59 | const ip_addr_t* sntp_getserver(u8_t idx);
60 | u8_t sntp_getkodreceived(u8_t idx);
61 |
62 | #if SNTP_MONITOR_SERVER_REACHABILITY
63 | u8_t sntp_getreachability(u8_t idx);
64 | #endif /* SNTP_MONITOR_SERVER_REACHABILITY */
65 |
66 | #if SNTP_SERVER_DNS
67 | void sntp_setservername(u8_t idx, const char *server);
68 | const char *sntp_getservername(u8_t idx);
69 | #endif /* SNTP_SERVER_DNS */
70 |
71 | #if SNTP_GET_SERVERS_FROM_DHCP || SNTP_GET_SERVERS_FROM_DHCPV6
72 | void sntp_servermode_dhcp(int set_servers_from_dhcp);
73 | #else /* SNTP_GET_SERVERS_FROM_DHCP || SNTP_GET_SERVERS_FROM_DHCPV6 */
74 | #define sntp_servermode_dhcp(x)
75 | #endif /* SNTP_GET_SERVERS_FROM_DHCP || SNTP_GET_SERVERS_FROM_DHCPV6 */
76 |
77 | #ifdef __cplusplus
78 | }
79 | #endif
80 |
81 | #endif /* LWIP_HDR_APPS_SNTP_H */
82 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/tftp_client.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * @file tftp_client.h
4 | * TFTP client header
5 | *
6 | */
7 |
8 | /*
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification,are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice,
13 | * this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright notice,
15 | * this list of conditions and the following disclaimer in the documentation
16 | * and/or other materials provided with the distribution.
17 | * 3. The name of the author may not be used to endorse or promote products
18 | * derived from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
23 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | * This file is part of the lwIP TCP/IP stack.
32 | *
33 | */
34 |
35 | #ifndef LWIP_HDR_APPS_TFTP_CLIENT_H
36 | #define LWIP_HDR_APPS_TFTP_CLIENT_H
37 |
38 | #include "lwip/apps/tftp_common.h"
39 |
40 | enum tftp_transfer_mode {
41 | TFTP_MODE_OCTET,
42 | TFTP_MODE_NETASCII,
43 | TFTP_MODE_BINARY /* used in old versions only */
44 | };
45 |
46 | err_t tftp_init_client(const struct tftp_context* ctx);
47 | err_t tftp_get(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, enum tftp_transfer_mode mode);
48 | err_t tftp_put(void* handle, const ip_addr_t *addr, u16_t port, const char* fname, enum tftp_transfer_mode mode);
49 |
50 | #endif /* LWIP_HDR_APPS_TFTP_CLIENT_H */
51 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/tftp_opts.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * @file tftp_opts.h
4 | *
5 | * @author Logan Gunthorpe
6 | *
7 | * @brief Trivial File Transfer Protocol (RFC 1350) implementation options
8 | *
9 | * Copyright (c) Deltatee Enterprises Ltd. 2013
10 | * All rights reserved.
11 | *
12 | */
13 |
14 | /*
15 | * Redistribution and use in source and binary forms, with or without
16 | * modification,are permitted provided that the following conditions are met:
17 | *
18 | * 1. Redistributions of source code must retain the above copyright notice,
19 | * this list of conditions and the following disclaimer.
20 | * 2. Redistributions in binary form must reproduce the above copyright notice,
21 | * this list of conditions and the following disclaimer in the documentation
22 | * and/or other materials provided with the distribution.
23 | * 3. The name of the author may not be used to endorse or promote products
24 | * derived from this software without specific prior written permission.
25 | *
26 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
29 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
31 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | *
37 | * Author: Logan Gunthorpe
38 | *
39 | */
40 |
41 | #ifndef LWIP_HDR_APPS_TFTP_OPTS_H
42 | #define LWIP_HDR_APPS_TFTP_OPTS_H
43 |
44 | #include "lwip/opt.h"
45 | #include "lwip/prot/iana.h"
46 |
47 | /**
48 | * @defgroup tftp_opts Options
49 | * @ingroup tftp
50 | * @{
51 | */
52 |
53 | /**
54 | * Enable TFTP debug messages
55 | */
56 | #if !defined TFTP_DEBUG || defined __DOXYGEN__
57 | #define TFTP_DEBUG LWIP_DBG_OFF
58 | #endif
59 |
60 | /**
61 | * TFTP server port
62 | */
63 | #if !defined TFTP_PORT || defined __DOXYGEN__
64 | #define TFTP_PORT LWIP_IANA_PORT_TFTP
65 | #endif
66 |
67 | /**
68 | * TFTP timeout
69 | */
70 | #if !defined TFTP_TIMEOUT_MSECS || defined __DOXYGEN__
71 | #define TFTP_TIMEOUT_MSECS 10000
72 | #endif
73 |
74 | /**
75 | * Max. number of retries when a file is read from server
76 | */
77 | #if !defined TFTP_MAX_RETRIES || defined __DOXYGEN__
78 | #define TFTP_MAX_RETRIES 5
79 | #endif
80 |
81 | /**
82 | * TFTP timer cyclic interval
83 | */
84 | #if !defined TFTP_TIMER_MSECS || defined __DOXYGEN__
85 | #define TFTP_TIMER_MSECS (TFTP_TIMEOUT_MSECS / 10)
86 | #endif
87 |
88 | /**
89 | * Max. length of TFTP filename
90 | */
91 | #if !defined TFTP_MAX_FILENAME_LEN || defined __DOXYGEN__
92 | #define TFTP_MAX_FILENAME_LEN 20
93 | #endif
94 |
95 | /**
96 | * Max. length of TFTP mode
97 | */
98 | #if !defined TFTP_MAX_MODE_LEN || defined __DOXYGEN__
99 | #define TFTP_MAX_MODE_LEN 10
100 | #endif
101 |
102 | /**
103 | * @}
104 | */
105 |
106 | #endif /* LWIP_HDR_APPS_TFTP_OPTS_H */
107 |
--------------------------------------------------------------------------------
/core/c/include/lwip/apps/tftp_server.h:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * @file tftp_server.h
4 | * TFTP server header
5 | *
6 | */
7 |
8 | /*
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification,are permitted provided that the following conditions are met:
11 | *
12 | * 1. Redistributions of source code must retain the above copyright notice,
13 | * this list of conditions and the following disclaimer.
14 | * 2. Redistributions in binary form must reproduce the above copyright notice,
15 | * this list of conditions and the following disclaimer in the documentation
16 | * and/or other materials provided with the distribution.
17 | * 3. The name of the author may not be used to endorse or promote products
18 | * derived from this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
23 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | *
31 | * This file is part of the lwIP TCP/IP stack.
32 | *
33 | */
34 |
35 | #ifndef LWIP_HDR_APPS_TFTP_SERVER_H
36 | #define LWIP_HDR_APPS_TFTP_SERVER_H
37 |
38 | #include "lwip/apps/tftp_common.h"
39 |
40 | err_t tftp_init_server(const struct tftp_context* ctx);
41 |
42 | #endif /* LWIP_HDR_APPS_TFTP_SERVER_H */
43 |
--------------------------------------------------------------------------------
/core/c/include/lwip/autoip.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | *
4 | * AutoIP Automatic LinkLocal IP Configuration
5 | */
6 |
7 | /*
8 | *
9 | * Copyright (c) 2007 Dominik Spies
10 | * All rights reserved.
11 | *
12 | * Redistribution and use in source and binary forms, with or without modification,
13 | * are permitted provided that the following conditions are met:
14 | *
15 | * 1. Redistributions of source code must retain the above copyright notice,
16 | * this list of conditions and the following disclaimer.
17 | * 2. Redistributions in binary form must reproduce the above copyright notice,
18 | * this list of conditions and the following disclaimer in the documentation
19 | * and/or other materials provided with the distribution.
20 | * 3. The name of the author may not be used to endorse or promote products
21 | * derived from this software without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
26 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | * OF SUCH DAMAGE.
33 | *
34 | * Author: Dominik Spies
35 | *
36 | * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform
37 | * with RFC 3927.
38 | *
39 | */
40 |
41 | #ifndef LWIP_HDR_AUTOIP_H
42 | #define LWIP_HDR_AUTOIP_H
43 |
44 | #include "lwip/opt.h"
45 |
46 | #if LWIP_IPV4 && LWIP_AUTOIP /* don't build if not configured for use in lwipopts.h */
47 |
48 | #include "lwip/netif.h"
49 | /* #include "lwip/udp.h" */
50 | #include "lwip/etharp.h"
51 | #include "lwip/acd.h"
52 |
53 | #ifdef __cplusplus
54 | extern "C" {
55 | #endif
56 |
57 | /** AutoIP state information per netif */
58 | struct autoip
59 | {
60 | /** the currently selected, probed, announced or used LL IP-Address */
61 | ip4_addr_t llipaddr;
62 | /** current AutoIP state machine state */
63 | u8_t state;
64 | /** total number of probed/used Link Local IP-Addresses */
65 | u8_t tried_llipaddr;
66 | /** acd struct */
67 | struct acd acd;
68 | };
69 |
70 |
71 | void autoip_set_struct(struct netif *netif, struct autoip *autoip);
72 | void autoip_remove_struct(struct netif *netif);
73 | err_t autoip_start(struct netif *netif);
74 | err_t autoip_stop(struct netif *netif);
75 | void autoip_network_changed_link_up(struct netif *netif);
76 | void autoip_network_changed_link_down(struct netif *netif);
77 | u8_t autoip_supplied_address(struct netif *netif);
78 |
79 | /* for lwIP internal use by ip4.c */
80 | u8_t autoip_accept_packet(struct netif *netif, const ip4_addr_t *addr);
81 |
82 | #define netif_autoip_data(netif) ((struct autoip*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP))
83 |
84 | #ifdef __cplusplus
85 | }
86 | #endif
87 |
88 | #endif /* LWIP_IPV4 && LWIP_AUTOIP */
89 |
90 | #endif /* LWIP_HDR_AUTOIP_H */
91 |
--------------------------------------------------------------------------------
/core/c/include/lwip/ethip6.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | *
4 | * Ethernet output for IPv6. Uses ND tables for link-layer addressing.
5 | */
6 |
7 | /*
8 | * Copyright (c) 2010 Inico Technologies Ltd.
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | *
14 | * 1. Redistributions of source code must retain the above copyright notice,
15 | * this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | * 3. The name of the author may not be used to endorse or promote products
20 | * derived from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 | * OF SUCH DAMAGE.
32 | *
33 | * This file is part of the lwIP TCP/IP stack.
34 | *
35 | * Author: Ivan Delamer
36 | *
37 | *
38 | * Please coordinate changes and requests with Ivan Delamer
39 | *
40 | */
41 |
42 | #ifndef LWIP_HDR_ETHIP6_H
43 | #define LWIP_HDR_ETHIP6_H
44 |
45 | #include "lwip/opt.h"
46 |
47 | #if LWIP_IPV6 && LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */
48 |
49 | #include "lwip/pbuf.h"
50 | #include "lwip/ip6.h"
51 | #include "lwip/ip6_addr.h"
52 | #include "lwip/netif.h"
53 |
54 |
55 | #ifdef __cplusplus
56 | extern "C" {
57 | #endif
58 |
59 |
60 | err_t ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr);
61 |
62 | #ifdef __cplusplus
63 | }
64 | #endif
65 |
66 | #endif /* LWIP_IPV6 && LWIP_ETHERNET */
67 |
68 | #endif /* LWIP_HDR_ETHIP6_H */
69 |
--------------------------------------------------------------------------------
/core/c/include/lwip/icmp6.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | *
4 | * IPv6 version of ICMP, as per RFC 4443.
5 | */
6 |
7 | /*
8 | * Copyright (c) 2010 Inico Technologies Ltd.
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | *
14 | * 1. Redistributions of source code must retain the above copyright notice,
15 | * this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | * 3. The name of the author may not be used to endorse or promote products
20 | * derived from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 | * OF SUCH DAMAGE.
32 | *
33 | * This file is part of the lwIP TCP/IP stack.
34 | *
35 | * Author: Ivan Delamer
36 | *
37 | *
38 | * Please coordinate changes and requests with Ivan Delamer
39 | *
40 | */
41 | #ifndef LWIP_HDR_ICMP6_H
42 | #define LWIP_HDR_ICMP6_H
43 |
44 | #include "lwip/opt.h"
45 | #include "lwip/pbuf.h"
46 | #include "lwip/ip6_addr.h"
47 | #include "lwip/netif.h"
48 | #include "lwip/prot/icmp6.h"
49 |
50 | #ifdef __cplusplus
51 | extern "C" {
52 | #endif
53 |
54 | #if LWIP_ICMP6 && LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */
55 |
56 | void icmp6_input(struct pbuf *p, struct netif *inp);
57 | void icmp6_dest_unreach(struct pbuf *p, enum icmp6_dur_code c);
58 | void icmp6_packet_too_big(struct pbuf *p, u32_t mtu);
59 | void icmp6_time_exceeded(struct pbuf *p, enum icmp6_te_code c);
60 | void icmp6_time_exceeded_with_addrs(struct pbuf *p, enum icmp6_te_code c,
61 | const ip6_addr_t *src_addr, const ip6_addr_t *dest_addr);
62 | void icmp6_param_problem(struct pbuf *p, enum icmp6_pp_code c, const void *pointer);
63 |
64 | #endif /* LWIP_ICMP6 && LWIP_IPV6 */
65 |
66 |
67 | #ifdef __cplusplus
68 | }
69 | #endif
70 |
71 |
72 | #endif /* LWIP_HDR_ICMP6_H */
73 |
--------------------------------------------------------------------------------
/core/c/include/lwip/if_api.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * Interface Identification APIs from:
4 | * RFC 3493: Basic Socket Interface Extensions for IPv6
5 | * Section 4: Interface Identification
6 | */
7 |
8 | /*
9 | * Copyright (c) 2017 Joel Cunningham, Garmin International, Inc.
10 | * All rights reserved.
11 | *
12 | * Redistribution and use in source and binary forms, with or without modification,
13 | * are permitted provided that the following conditions are met:
14 | *
15 | * 1. Redistributions of source code must retain the above copyright notice,
16 | * this list of conditions and the following disclaimer.
17 | * 2. Redistributions in binary form must reproduce the above copyright notice,
18 | * this list of conditions and the following disclaimer in the documentation
19 | * and/or other materials provided with the distribution.
20 | * 3. The name of the author may not be used to endorse or promote products
21 | * derived from this software without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
26 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | * OF SUCH DAMAGE.
33 | *
34 | * This file is part of the lwIP TCP/IP stack.
35 | *
36 | * Author: Joel Cunningham
37 | *
38 | */
39 | #ifndef LWIP_HDR_IF_H
40 | #define LWIP_HDR_IF_H
41 |
42 | #include "lwip/opt.h"
43 |
44 | #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
45 |
46 | #include "lwip/netif.h"
47 |
48 | #ifdef __cplusplus
49 | extern "C" {
50 | #endif
51 |
52 | #ifndef IF_NAMESIZE
53 | #define IF_NAMESIZE NETIF_NAMESIZE
54 | #endif
55 |
56 | char * lwip_if_indextoname(unsigned int ifindex, char *ifname);
57 | unsigned int lwip_if_nametoindex(const char *ifname);
58 |
59 | #if LWIP_COMPAT_SOCKETS
60 | #define if_indextoname(ifindex, ifname) lwip_if_indextoname(ifindex,ifname)
61 | #define if_nametoindex(ifname) lwip_if_nametoindex(ifname)
62 | #endif /* LWIP_COMPAT_SOCKETS */
63 |
64 | #ifdef __cplusplus
65 | }
66 | #endif
67 |
68 | #endif /* LWIP_SOCKET */
69 |
70 | #endif /* LWIP_HDR_IF_H */
71 |
--------------------------------------------------------------------------------
/core/c/include/lwip/mem.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * Heap API
4 | */
5 |
6 | /*
7 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 | * OF SUCH DAMAGE.
31 | *
32 | * This file is part of the lwIP TCP/IP stack.
33 | *
34 | * Author: Adam Dunkels
35 | *
36 | */
37 | #ifndef LWIP_HDR_MEM_H
38 | #define LWIP_HDR_MEM_H
39 |
40 | #include "lwip/opt.h"
41 |
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 |
46 | #if MEM_LIBC_MALLOC
47 |
48 | #include "lwip/arch.h"
49 |
50 | typedef size_t mem_size_t;
51 | #define MEM_SIZE_F SZT_F
52 |
53 | #elif MEM_USE_POOLS
54 |
55 | typedef u16_t mem_size_t;
56 | #define MEM_SIZE_F U16_F
57 |
58 | #else
59 |
60 | /* MEM_SIZE would have to be aligned, but using 64000 here instead of
61 | * 65535 leaves some room for alignment...
62 | */
63 | #if MEM_SIZE > 64000L
64 | typedef u32_t mem_size_t;
65 | #define MEM_SIZE_F U32_F
66 | #else
67 | typedef u16_t mem_size_t;
68 | #define MEM_SIZE_F U16_F
69 | #endif /* MEM_SIZE > 64000 */
70 | #endif
71 |
72 | void mem_init(void);
73 | void *mem_trim(void *mem, mem_size_t size);
74 | void *mem_malloc(mem_size_t size);
75 | void *mem_calloc(mem_size_t count, mem_size_t size);
76 | void mem_free(void *mem);
77 |
78 | #ifdef __cplusplus
79 | }
80 | #endif
81 |
82 | #endif /* LWIP_HDR_MEM_H */
83 |
--------------------------------------------------------------------------------
/core/c/include/lwip/nd6.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | *
4 | * Neighbor discovery and stateless address autoconfiguration for IPv6.
5 | * Aims to be compliant with RFC 4861 (Neighbor discovery) and RFC 4862
6 | * (Address autoconfiguration).
7 | */
8 |
9 | /*
10 | * Copyright (c) 2010 Inico Technologies Ltd.
11 | * All rights reserved.
12 | *
13 | * Redistribution and use in source and binary forms, with or without modification,
14 | * are permitted provided that the following conditions are met:
15 | *
16 | * 1. Redistributions of source code must retain the above copyright notice,
17 | * this list of conditions and the following disclaimer.
18 | * 2. Redistributions in binary form must reproduce the above copyright notice,
19 | * this list of conditions and the following disclaimer in the documentation
20 | * and/or other materials provided with the distribution.
21 | * 3. The name of the author may not be used to endorse or promote products
22 | * derived from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 | * OF SUCH DAMAGE.
34 | *
35 | * This file is part of the lwIP TCP/IP stack.
36 | *
37 | * Author: Ivan Delamer
38 | *
39 | *
40 | * Please coordinate changes and requests with Ivan Delamer
41 | *
42 | */
43 |
44 | #ifndef LWIP_HDR_ND6_H
45 | #define LWIP_HDR_ND6_H
46 |
47 | #include "lwip/opt.h"
48 |
49 | #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */
50 |
51 | #include "lwip/ip6_addr.h"
52 | #include "lwip/err.h"
53 |
54 | #ifdef __cplusplus
55 | extern "C" {
56 | #endif
57 |
58 | /** 1 second period */
59 | #define ND6_TMR_INTERVAL 1000
60 |
61 | /** Router solicitations are sent in 4 second intervals (see RFC 4861, ch. 6.3.7) */
62 | #ifndef ND6_RTR_SOLICITATION_INTERVAL
63 | #define ND6_RTR_SOLICITATION_INTERVAL 4000
64 | #endif
65 |
66 | struct pbuf;
67 | struct netif;
68 |
69 | void nd6_tmr(void);
70 | void nd6_input(struct pbuf *p, struct netif *inp);
71 | void nd6_clear_destination_cache(void);
72 | struct netif *nd6_find_route(const ip6_addr_t *ip6addr);
73 | err_t nd6_get_next_hop_addr_or_queue(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr, const u8_t **hwaddrp);
74 | u16_t nd6_get_destination_mtu(const ip6_addr_t *ip6addr, struct netif *netif);
75 | #if LWIP_ND6_TCP_REACHABILITY_HINTS
76 | void nd6_reachability_hint(const ip6_addr_t *ip6addr);
77 | #endif /* LWIP_ND6_TCP_REACHABILITY_HINTS */
78 | void nd6_cleanup_netif(struct netif *netif);
79 | #if LWIP_IPV6_MLD
80 | void nd6_adjust_mld_membership(struct netif *netif, s8_t addr_idx, u8_t new_state);
81 | #endif /* LWIP_IPV6_MLD */
82 | void nd6_restart_netif(struct netif *netif);
83 |
84 | #ifdef __cplusplus
85 | }
86 | #endif
87 |
88 | #endif /* LWIP_IPV6 */
89 |
90 | #endif /* LWIP_HDR_ND6_H */
91 |
--------------------------------------------------------------------------------
/core/c/include/lwip/priv/raw_priv.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * raw API internal implementations (do not use in application code)
4 | */
5 |
6 | /*
7 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 | * OF SUCH DAMAGE.
31 | *
32 | * This file is part of the lwIP TCP/IP stack.
33 | *
34 | * Author: Adam Dunkels
35 | *
36 | */
37 | #ifndef LWIP_HDR_RAW_PRIV_H
38 | #define LWIP_HDR_RAW_PRIV_H
39 |
40 | #include "lwip/opt.h"
41 |
42 | #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
43 |
44 | #include "lwip/raw.h"
45 |
46 | #ifdef __cplusplus
47 | extern "C" {
48 | #endif
49 |
50 | /** return codes for raw_input */
51 | typedef enum raw_input_state
52 | {
53 | RAW_INPUT_NONE = 0, /* pbuf did not match any pcbs */
54 | RAW_INPUT_EATEN, /* pbuf handed off and delivered to pcb */
55 | RAW_INPUT_DELIVERED /* pbuf only delivered to pcb (pbuf can still be referenced) */
56 | } raw_input_state_t;
57 |
58 | /* The following functions are the lower layer interface to RAW. */
59 | raw_input_state_t raw_input(struct pbuf *p, struct netif *inp);
60 |
61 | void raw_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr);
62 |
63 | #ifdef __cplusplus
64 | }
65 | #endif
66 |
67 | #endif /* LWIP_RAW */
68 |
69 | #endif /* LWIP_HDR_RAW_PRIV_H */
70 |
--------------------------------------------------------------------------------
/core/c/include/lwip/prot/autoip.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * AutoIP protocol definitions
4 | */
5 |
6 | /*
7 | *
8 | * Copyright (c) 2007 Dominik Spies
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | *
14 | * 1. Redistributions of source code must retain the above copyright notice,
15 | * this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | * 3. The name of the author may not be used to endorse or promote products
20 | * derived from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 | * OF SUCH DAMAGE.
32 | *
33 | * Author: Dominik Spies
34 | *
35 | * This is a AutoIP implementation for the lwIP TCP/IP stack. It aims to conform
36 | * with RFC 3927.
37 | *
38 | */
39 |
40 | #ifndef LWIP_HDR_PROT_AUTOIP_H
41 | #define LWIP_HDR_PROT_AUTOIP_H
42 |
43 | #ifdef __cplusplus
44 | extern "C" {
45 | #endif
46 |
47 | /* 169.254.0.0 */
48 | #define AUTOIP_NET 0xA9FE0000
49 | /* 169.254.1.0 */
50 | #define AUTOIP_RANGE_START (AUTOIP_NET | 0x0100)
51 | /* 169.254.254.255 */
52 | #define AUTOIP_RANGE_END (AUTOIP_NET | 0xFEFF)
53 |
54 | /* AutoIP client states */
55 | typedef enum {
56 | AUTOIP_STATE_OFF,
57 | AUTOIP_STATE_CHECKING,
58 | AUTOIP_STATE_BOUND
59 | } autoip_state_enum_t;
60 |
61 | #ifdef __cplusplus
62 | }
63 | #endif
64 |
65 | #endif /* LWIP_HDR_PROT_AUTOIP_H */
66 |
--------------------------------------------------------------------------------
/core/c/include/lwip/prot/iana.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * IANA assigned numbers (RFC 1700 and successors)
4 | *
5 | * @defgroup iana IANA assigned numbers
6 | * @ingroup infrastructure
7 | */
8 |
9 | /*
10 | * Copyright (c) 2017 Dirk Ziegelmeier.
11 | * All rights reserved.
12 | *
13 | * Redistribution and use in source and binary forms, with or without modification,
14 | * are permitted provided that the following conditions are met:
15 | *
16 | * 1. Redistributions of source code must retain the above copyright notice,
17 | * this list of conditions and the following disclaimer.
18 | * 2. Redistributions in binary form must reproduce the above copyright notice,
19 | * this list of conditions and the following disclaimer in the documentation
20 | * and/or other materials provided with the distribution.
21 | * 3. The name of the author may not be used to endorse or promote products
22 | * derived from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 | * OF SUCH DAMAGE.
34 | *
35 | * This file is part of the lwIP TCP/IP stack.
36 | *
37 | * Author: Dirk Ziegelmeier
38 | *
39 | */
40 |
41 | #ifndef LWIP_HDR_PROT_IANA_H
42 | #define LWIP_HDR_PROT_IANA_H
43 |
44 | #ifdef __cplusplus
45 | extern "C" {
46 | #endif
47 |
48 | /**
49 | * @ingroup iana
50 | * Hardware types
51 | */
52 | enum lwip_iana_hwtype {
53 | /** Ethernet */
54 | LWIP_IANA_HWTYPE_ETHERNET = 1
55 | };
56 |
57 | /**
58 | * @ingroup iana
59 | * Port numbers
60 | * https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt
61 | */
62 | enum lwip_iana_port_number {
63 | /** SMTP */
64 | LWIP_IANA_PORT_SMTP = 25,
65 | /** DHCP server */
66 | LWIP_IANA_PORT_DHCP_SERVER = 67,
67 | /** DHCP client */
68 | LWIP_IANA_PORT_DHCP_CLIENT = 68,
69 | /** TFTP */
70 | LWIP_IANA_PORT_TFTP = 69,
71 | /** HTTP */
72 | LWIP_IANA_PORT_HTTP = 80,
73 | /** SNTP */
74 | LWIP_IANA_PORT_SNTP = 123,
75 | /** NETBIOS */
76 | LWIP_IANA_PORT_NETBIOS = 137,
77 | /** SNMP */
78 | LWIP_IANA_PORT_SNMP = 161,
79 | /** SNMP traps */
80 | LWIP_IANA_PORT_SNMP_TRAP = 162,
81 | /** HTTPS */
82 | LWIP_IANA_PORT_HTTPS = 443,
83 | /** SMTPS */
84 | LWIP_IANA_PORT_SMTPS = 465,
85 | /** MQTT */
86 | LWIP_IANA_PORT_MQTT = 1883,
87 | /** MDNS */
88 | LWIP_IANA_PORT_MDNS = 5353,
89 | /** Secure MQTT */
90 | LWIP_IANA_PORT_SECURE_MQTT = 8883
91 | };
92 |
93 | #ifdef __cplusplus
94 | }
95 | #endif
96 |
97 | #endif /* LWIP_HDR_PROT_IANA_H */
98 |
--------------------------------------------------------------------------------
/core/c/include/lwip/prot/ieee.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * IEEE assigned numbers
4 | *
5 | * @defgroup ieee IEEE assigned numbers
6 | * @ingroup infrastructure
7 | */
8 |
9 | /*
10 | * Copyright (c) 2017 Dirk Ziegelmeier.
11 | * All rights reserved.
12 | *
13 | * Redistribution and use in source and binary forms, with or without modification,
14 | * are permitted provided that the following conditions are met:
15 | *
16 | * 1. Redistributions of source code must retain the above copyright notice,
17 | * this list of conditions and the following disclaimer.
18 | * 2. Redistributions in binary form must reproduce the above copyright notice,
19 | * this list of conditions and the following disclaimer in the documentation
20 | * and/or other materials provided with the distribution.
21 | * 3. The name of the author may not be used to endorse or promote products
22 | * derived from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 | * OF SUCH DAMAGE.
34 | *
35 | * This file is part of the lwIP TCP/IP stack.
36 | *
37 | * Author: Dirk Ziegelmeier
38 | *
39 | */
40 |
41 | #ifndef LWIP_HDR_PROT_IEEE_H
42 | #define LWIP_HDR_PROT_IEEE_H
43 |
44 | #ifdef __cplusplus
45 | extern "C" {
46 | #endif
47 |
48 | /**
49 | * @ingroup ieee
50 | * A list of often ethtypes (although lwIP does not use all of them).
51 | */
52 | enum lwip_ieee_eth_type {
53 | /** Internet protocol v4 */
54 | ETHTYPE_IP = 0x0800U,
55 | /** Address resolution protocol */
56 | ETHTYPE_ARP = 0x0806U,
57 | /** Wake on lan */
58 | ETHTYPE_WOL = 0x0842U,
59 | /** RARP */
60 | ETHTYPE_RARP = 0x8035U,
61 | /** Virtual local area network */
62 | ETHTYPE_VLAN = 0x8100U,
63 | /** Internet protocol v6 */
64 | ETHTYPE_IPV6 = 0x86DDU,
65 | /** PPP Over Ethernet Discovery Stage */
66 | ETHTYPE_PPPOEDISC = 0x8863U,
67 | /** PPP Over Ethernet Session Stage */
68 | ETHTYPE_PPPOE = 0x8864U,
69 | /** Jumbo Frames */
70 | ETHTYPE_JUMBO = 0x8870U,
71 | /** Process field network */
72 | ETHTYPE_PROFINET = 0x8892U,
73 | /** Ethernet for control automation technology */
74 | ETHTYPE_ETHERCAT = 0x88A4U,
75 | /** Link layer discovery protocol */
76 | ETHTYPE_LLDP = 0x88CCU,
77 | /** Serial real-time communication system */
78 | ETHTYPE_SERCOS = 0x88CDU,
79 | /** Media redundancy protocol */
80 | ETHTYPE_MRP = 0x88E3U,
81 | /** Precision time protocol */
82 | ETHTYPE_PTP = 0x88F7U,
83 | /** Q-in-Q, 802.1ad */
84 | ETHTYPE_QINQ = 0x9100U
85 | };
86 |
87 | #ifdef __cplusplus
88 | }
89 | #endif
90 |
91 | #endif /* LWIP_HDR_PROT_IEEE_H */
92 |
--------------------------------------------------------------------------------
/core/c/include/lwip/prot/igmp.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * IGMP protocol definitions
4 | */
5 |
6 | /*
7 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 | * OF SUCH DAMAGE.
31 | *
32 | * This file is part of the lwIP TCP/IP stack.
33 | *
34 | * Author: Adam Dunkels
35 | *
36 | */
37 | #ifndef LWIP_HDR_PROT_IGMP_H
38 | #define LWIP_HDR_PROT_IGMP_H
39 |
40 | #include "lwip/arch.h"
41 | #include "lwip/prot/ip4.h"
42 |
43 | #ifdef __cplusplus
44 | extern "C" {
45 | #endif
46 |
47 | /*
48 | * IGMP constants
49 | */
50 | #define IGMP_TTL 1
51 | #define IGMP_MINLEN 8
52 | #define ROUTER_ALERT 0x9404U
53 | #define ROUTER_ALERTLEN 4
54 |
55 | /*
56 | * IGMP message types, including version number.
57 | */
58 | #define IGMP_MEMB_QUERY 0x11 /* Membership query */
59 | #define IGMP_V1_MEMB_REPORT 0x12 /* Ver. 1 membership report */
60 | #define IGMP_V2_MEMB_REPORT 0x16 /* Ver. 2 membership report */
61 | #define IGMP_LEAVE_GROUP 0x17 /* Leave-group message */
62 |
63 | /* Group membership states */
64 | #define IGMP_GROUP_NON_MEMBER 0
65 | #define IGMP_GROUP_DELAYING_MEMBER 1
66 | #define IGMP_GROUP_IDLE_MEMBER 2
67 |
68 | /**
69 | * IGMP packet format.
70 | */
71 | #ifdef PACK_STRUCT_USE_INCLUDES
72 | # include "arch/bpstruct.h"
73 | #endif
74 | PACK_STRUCT_BEGIN
75 | struct igmp_msg {
76 | PACK_STRUCT_FLD_8(u8_t igmp_msgtype);
77 | PACK_STRUCT_FLD_8(u8_t igmp_maxresp);
78 | PACK_STRUCT_FIELD(u16_t igmp_checksum);
79 | PACK_STRUCT_FLD_S(ip4_addr_p_t igmp_group_address);
80 | } PACK_STRUCT_STRUCT;
81 | PACK_STRUCT_END
82 | #ifdef PACK_STRUCT_USE_INCLUDES
83 | # include "arch/epstruct.h"
84 | #endif
85 |
86 | #ifdef __cplusplus
87 | }
88 | #endif
89 |
90 | #endif /* LWIP_HDR_PROT_IGMP_H */
91 |
--------------------------------------------------------------------------------
/core/c/include/lwip/prot/ip.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * IP protocol definitions
4 | */
5 |
6 | /*
7 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 | * OF SUCH DAMAGE.
31 | *
32 | * This file is part of the lwIP TCP/IP stack.
33 | *
34 | * Author: Adam Dunkels
35 | *
36 | */
37 | #ifndef LWIP_HDR_PROT_IP_H
38 | #define LWIP_HDR_PROT_IP_H
39 |
40 | #include "lwip/arch.h"
41 |
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 |
46 | #define IP_PROTO_ICMP 1
47 | #define IP_PROTO_IGMP 2
48 | #define IP_PROTO_UDP 17
49 | #define IP_PROTO_UDPLITE 136
50 | #define IP_PROTO_TCP 6
51 |
52 | /** This operates on a void* by loading the first byte */
53 | #define IP_HDR_GET_VERSION(ptr) ((*(u8_t*)(ptr)) >> 4)
54 |
55 | #ifdef __cplusplus
56 | }
57 | #endif
58 |
59 | #endif /* LWIP_HDR_PROT_IP_H */
60 |
--------------------------------------------------------------------------------
/core/c/include/lwip/prot/mld6.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * MLD6 protocol definitions
4 | */
5 |
6 | /*
7 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 | * OF SUCH DAMAGE.
31 | *
32 | * This file is part of the lwIP TCP/IP stack.
33 | *
34 | * Author: Adam Dunkels
35 | *
36 | */
37 | #ifndef LWIP_HDR_PROT_MLD6_H
38 | #define LWIP_HDR_PROT_MLD6_H
39 |
40 | #include "lwip/arch.h"
41 | #include "lwip/prot/ip6.h"
42 |
43 | #ifdef __cplusplus
44 | extern "C" {
45 | #endif
46 |
47 | #define MLD6_HBH_HLEN 8
48 | /** Multicast listener report/query/done message header. */
49 | #ifdef PACK_STRUCT_USE_INCLUDES
50 | # include "arch/bpstruct.h"
51 | #endif
52 | PACK_STRUCT_BEGIN
53 | struct mld_header {
54 | PACK_STRUCT_FLD_8(u8_t type);
55 | PACK_STRUCT_FLD_8(u8_t code);
56 | PACK_STRUCT_FIELD(u16_t chksum);
57 | PACK_STRUCT_FIELD(u16_t max_resp_delay);
58 | PACK_STRUCT_FIELD(u16_t reserved);
59 | PACK_STRUCT_FLD_S(ip6_addr_p_t multicast_address);
60 | /* Options follow. */
61 | } PACK_STRUCT_STRUCT;
62 | PACK_STRUCT_END
63 | #ifdef PACK_STRUCT_USE_INCLUDES
64 | # include "arch/epstruct.h"
65 | #endif
66 |
67 | #ifdef __cplusplus
68 | }
69 | #endif
70 |
71 | #endif /* LWIP_HDR_PROT_MLD6_H */
72 |
--------------------------------------------------------------------------------
/core/c/include/lwip/prot/udp.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * UDP protocol definitions
4 | */
5 |
6 | /*
7 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without modification,
11 | * are permitted provided that the following conditions are met:
12 | *
13 | * 1. Redistributions of source code must retain the above copyright notice,
14 | * this list of conditions and the following disclaimer.
15 | * 2. Redistributions in binary form must reproduce the above copyright notice,
16 | * this list of conditions and the following disclaimer in the documentation
17 | * and/or other materials provided with the distribution.
18 | * 3. The name of the author may not be used to endorse or promote products
19 | * derived from this software without specific prior written permission.
20 | *
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 | * OF SUCH DAMAGE.
31 | *
32 | * This file is part of the lwIP TCP/IP stack.
33 | *
34 | * Author: Adam Dunkels
35 | *
36 | */
37 | #ifndef LWIP_HDR_PROT_UDP_H
38 | #define LWIP_HDR_PROT_UDP_H
39 |
40 | #include "lwip/arch.h"
41 |
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 |
46 | #define UDP_HLEN 8
47 |
48 | /* Fields are (of course) in network byte order. */
49 | #ifdef PACK_STRUCT_USE_INCLUDES
50 | # include "arch/bpstruct.h"
51 | #endif
52 | PACK_STRUCT_BEGIN
53 | struct udp_hdr {
54 | PACK_STRUCT_FIELD(u16_t src);
55 | PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */
56 | PACK_STRUCT_FIELD(u16_t len);
57 | PACK_STRUCT_FIELD(u16_t chksum);
58 | } PACK_STRUCT_STRUCT;
59 | PACK_STRUCT_END
60 | #ifdef PACK_STRUCT_USE_INCLUDES
61 | # include "arch/epstruct.h"
62 | #endif
63 |
64 | #ifdef __cplusplus
65 | }
66 | #endif
67 |
68 | #endif /* LWIP_HDR_PROT_UDP_H */
69 |
--------------------------------------------------------------------------------
/core/c/include/lwip/tcpbase.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * Base TCP API definitions shared by TCP and ALTCP
4 | * See also @ref tcp_raw
5 | */
6 |
7 | /*
8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | *
14 | * 1. Redistributions of source code must retain the above copyright notice,
15 | * this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | * 3. The name of the author may not be used to endorse or promote products
20 | * derived from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 | * OF SUCH DAMAGE.
32 | *
33 | * This file is part of the lwIP TCP/IP stack.
34 | *
35 | * Author: Adam Dunkels
36 | *
37 | */
38 | #ifndef LWIP_HDR_TCPBASE_H
39 | #define LWIP_HDR_TCPBASE_H
40 |
41 | #include "lwip/opt.h"
42 |
43 | #if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
44 |
45 | #ifdef __cplusplus
46 | extern "C" {
47 | #endif
48 |
49 |
50 | #if LWIP_WND_SCALE
51 | typedef u32_t tcpwnd_size_t;
52 | #else
53 | typedef u16_t tcpwnd_size_t;
54 | #endif
55 |
56 | enum tcp_state {
57 | CLOSED = 0,
58 | LISTEN = 1,
59 | SYN_SENT = 2,
60 | SYN_RCVD = 3,
61 | ESTABLISHED = 4,
62 | FIN_WAIT_1 = 5,
63 | FIN_WAIT_2 = 6,
64 | CLOSE_WAIT = 7,
65 | CLOSING = 8,
66 | LAST_ACK = 9,
67 | TIME_WAIT = 10
68 | };
69 | /* ATTENTION: this depends on state number ordering! */
70 | #define TCP_STATE_IS_CLOSING(state) ((state) >= FIN_WAIT_1)
71 |
72 | /* Flags for "apiflags" parameter in tcp_write */
73 | #define TCP_WRITE_FLAG_COPY 0x01
74 | #define TCP_WRITE_FLAG_MORE 0x02
75 |
76 | #define TCP_PRIO_MIN 1
77 | #define TCP_PRIO_NORMAL 64
78 | #define TCP_PRIO_MAX 127
79 |
80 | const char* tcp_debug_state_str(enum tcp_state s);
81 |
82 | #ifdef __cplusplus
83 | }
84 | #endif
85 |
86 | #endif /* LWIP_TCP */
87 |
88 | #endif /* LWIP_HDR_TCPBASE_H */
89 |
--------------------------------------------------------------------------------
/core/c/include/netif/etharp.h:
--------------------------------------------------------------------------------
1 | /* ARP has been moved to core/ipv4, provide this #include for compatibility only */
2 | #include "lwip/etharp.h"
3 | #include "netif/ethernet.h"
4 |
--------------------------------------------------------------------------------
/core/c/include/netif/ethernet.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * Ethernet input function - handles INCOMING ethernet level traffic
4 | * To be used in most low-level netif implementations
5 | */
6 |
7 | /*
8 | * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
9 | * Copyright (c) 2003-2004 Leon Woestenberg
10 | * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
11 | * All rights reserved.
12 | *
13 | * Redistribution and use in source and binary forms, with or without modification,
14 | * are permitted provided that the following conditions are met:
15 | *
16 | * 1. Redistributions of source code must retain the above copyright notice,
17 | * this list of conditions and the following disclaimer.
18 | * 2. Redistributions in binary form must reproduce the above copyright notice,
19 | * this list of conditions and the following disclaimer in the documentation
20 | * and/or other materials provided with the distribution.
21 | * 3. The name of the author may not be used to endorse or promote products
22 | * derived from this software without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 | * OF SUCH DAMAGE.
34 | *
35 | * This file is part of the lwIP TCP/IP stack.
36 | *
37 | * Author: Adam Dunkels
38 | *
39 | */
40 |
41 | #ifndef LWIP_HDR_NETIF_ETHERNET_H
42 | #define LWIP_HDR_NETIF_ETHERNET_H
43 |
44 | #include "lwip/opt.h"
45 |
46 | #include "lwip/pbuf.h"
47 | #include "lwip/netif.h"
48 | #include "lwip/prot/ethernet.h"
49 |
50 | #ifdef __cplusplus
51 | extern "C" {
52 | #endif
53 |
54 | #if LWIP_ARP || LWIP_ETHERNET
55 |
56 | /** Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type)
57 | * to a filter function that returns the correct netif when using multiple
58 | * netifs on one hardware interface where the netif's low-level receive
59 | * routine cannot decide for the correct netif (e.g. when mapping multiple
60 | * IP addresses to one hardware interface).
61 | */
62 | #ifndef LWIP_ARP_FILTER_NETIF
63 | #define LWIP_ARP_FILTER_NETIF 0
64 | #endif
65 |
66 | err_t ethernet_input(struct pbuf *p, struct netif *netif);
67 | err_t ethernet_output(struct netif* netif, struct pbuf* p, const struct eth_addr* src, const struct eth_addr* dst, u16_t eth_type);
68 |
69 | extern const struct eth_addr ethbroadcast, ethzero;
70 |
71 | #endif /* LWIP_ARP || LWIP_ETHERNET */
72 |
73 | #ifdef __cplusplus
74 | }
75 | #endif
76 |
77 | #endif /* LWIP_HDR_NETIF_ETHERNET_H */
78 |
--------------------------------------------------------------------------------
/core/c/include/netif/lowpan6.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | *
4 | * 6LowPAN output for IPv6. Uses ND tables for link-layer addressing. Fragments packets to 6LowPAN units.
5 | */
6 |
7 | /*
8 | * Copyright (c) 2015 Inico Technologies Ltd.
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | *
14 | * 1. Redistributions of source code must retain the above copyright notice,
15 | * this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | * 3. The name of the author may not be used to endorse or promote products
20 | * derived from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 | * OF SUCH DAMAGE.
32 | *
33 | * This file is part of the lwIP TCP/IP stack.
34 | *
35 | * Author: Ivan Delamer
36 | *
37 | *
38 | * Please coordinate changes and requests with Ivan Delamer
39 | *
40 | */
41 |
42 | #ifndef LWIP_HDR_LOWPAN6_H
43 | #define LWIP_HDR_LOWPAN6_H
44 |
45 | #include "netif/lowpan6_opts.h"
46 |
47 | #if LWIP_IPV6
48 |
49 | #include "netif/lowpan6_common.h"
50 | #include "lwip/pbuf.h"
51 | #include "lwip/ip.h"
52 | #include "lwip/ip_addr.h"
53 | #include "lwip/netif.h"
54 |
55 | #ifdef __cplusplus
56 | extern "C" {
57 | #endif
58 |
59 | /** 1 second period for reassembly */
60 | #define LOWPAN6_TMR_INTERVAL 1000
61 |
62 | void lowpan6_tmr(void);
63 |
64 | err_t lowpan6_set_context(u8_t idx, const ip6_addr_t * context);
65 | err_t lowpan6_set_short_addr(u8_t addr_high, u8_t addr_low);
66 |
67 | #if LWIP_IPV4
68 | err_t lowpan4_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr);
69 | #endif /* LWIP_IPV4 */
70 | err_t lowpan6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr);
71 | err_t lowpan6_input(struct pbuf * p, struct netif *netif);
72 | err_t lowpan6_if_init(struct netif *netif);
73 |
74 | /* pan_id in network byte order. */
75 | err_t lowpan6_set_pan_id(u16_t pan_id);
76 |
77 | u16_t lowpan6_calc_crc(const void *buf, u16_t len);
78 |
79 | #if !NO_SYS
80 | err_t tcpip_6lowpan_input(struct pbuf *p, struct netif *inp);
81 | #endif /* !NO_SYS */
82 |
83 | #ifdef __cplusplus
84 | }
85 | #endif
86 |
87 | #endif /* LWIP_IPV6 */
88 |
89 | #endif /* LWIP_HDR_LOWPAN6_H */
90 |
--------------------------------------------------------------------------------
/core/c/include/netif/lowpan6_ble.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | * 6LowPAN over BLE for IPv6 (RFC7668).
4 | */
5 |
6 | /*
7 | * Copyright (c) 2017 Benjamin Aigner
8 | * Copyright (c) 2015 Inico Technologies Ltd. , Author: Ivan Delamer
9 | *
10 | * All rights reserved.
11 | *
12 | * Redistribution and use in source and binary forms, with or without modification,
13 | * are permitted provided that the following conditions are met:
14 | *
15 | * 1. Redistributions of source code must retain the above copyright notice,
16 | * this list of conditions and the following disclaimer.
17 | * 2. Redistributions in binary form must reproduce the above copyright notice,
18 | * this list of conditions and the following disclaimer in the documentation
19 | * and/or other materials provided with the distribution.
20 | * 3. The name of the author may not be used to endorse or promote products
21 | * derived from this software without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
26 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | * OF SUCH DAMAGE.
33 | *
34 | * Author: Benjamin Aigner
35 | *
36 | * Based on the original 6lowpan implementation of lwIP ( @see 6lowpan.c)
37 | */
38 |
39 | #ifndef LWIP_HDR_LOWPAN6_BLE_H
40 | #define LWIP_HDR_LOWPAN6_BLE_H
41 |
42 | #include "netif/lowpan6_opts.h"
43 |
44 | #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */
45 |
46 | #include "netif/lowpan6_common.h"
47 | #include "lwip/pbuf.h"
48 | #include "lwip/ip.h"
49 | #include "lwip/ip_addr.h"
50 | #include "lwip/netif.h"
51 |
52 | #ifdef __cplusplus
53 | extern "C" {
54 | #endif
55 |
56 | err_t rfc7668_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr);
57 | err_t rfc7668_input(struct pbuf * p, struct netif *netif);
58 | err_t rfc7668_set_local_addr_eui64(struct netif *netif, const u8_t *local_addr, size_t local_addr_len);
59 | err_t rfc7668_set_local_addr_mac48(struct netif *netif, const u8_t *local_addr, size_t local_addr_len, int is_public_addr);
60 | err_t rfc7668_set_peer_addr_eui64(struct netif *netif, const u8_t *peer_addr, size_t peer_addr_len);
61 | err_t rfc7668_set_peer_addr_mac48(struct netif *netif, const u8_t *peer_addr, size_t peer_addr_len, int is_public_addr);
62 | err_t rfc7668_set_context(u8_t index, const ip6_addr_t * context);
63 | err_t rfc7668_if_init(struct netif *netif);
64 |
65 | #if !NO_SYS
66 | err_t tcpip_rfc7668_input(struct pbuf *p, struct netif *inp);
67 | #endif
68 |
69 | void ble_addr_to_eui64(u8_t *dst, const u8_t *src, int public_addr);
70 | void eui64_to_ble_addr(u8_t *dst, const u8_t *src);
71 |
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 |
76 | #endif /* LWIP_IPV6 */
77 |
78 | #endif /* LWIP_HDR_LOWPAN6_BLE_H */
79 |
--------------------------------------------------------------------------------
/core/c/include/netif/lowpan6_common.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | *
4 | * Common 6LowPAN routines for IPv6. Uses ND tables for link-layer addressing. Fragments packets to 6LowPAN units.
5 | */
6 |
7 | /*
8 | * Copyright (c) 2015 Inico Technologies Ltd.
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without modification,
12 | * are permitted provided that the following conditions are met:
13 | *
14 | * 1. Redistributions of source code must retain the above copyright notice,
15 | * this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright notice,
17 | * this list of conditions and the following disclaimer in the documentation
18 | * and/or other materials provided with the distribution.
19 | * 3. The name of the author may not be used to endorse or promote products
20 | * derived from this software without specific prior written permission.
21 | *
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 | * OF SUCH DAMAGE.
32 | *
33 | * This file is part of the lwIP TCP/IP stack.
34 | *
35 | * Author: Ivan Delamer
36 | *
37 | *
38 | * Please coordinate changes and requests with Ivan Delamer
39 | *
40 | */
41 |
42 | #ifndef LWIP_HDR_LOWPAN6_COMMON_H
43 | #define LWIP_HDR_LOWPAN6_COMMON_H
44 |
45 | #include "netif/lowpan6_opts.h"
46 |
47 | #if LWIP_IPV6 /* don't build if IPv6 is disabled in lwipopts.h */
48 |
49 | #include "lwip/pbuf.h"
50 | #include "lwip/ip.h"
51 | #include "lwip/ip6_addr.h"
52 | #include "lwip/netif.h"
53 |
54 | #ifdef __cplusplus
55 | extern "C" {
56 | #endif
57 |
58 | /** Helper define for a link layer address, which can be encoded as 0, 2 or 8 bytes */
59 | struct lowpan6_link_addr {
60 | /* encoded length of the address */
61 | u8_t addr_len;
62 | /* address bytes */
63 | u8_t addr[8];
64 | };
65 |
66 | s8_t lowpan6_get_address_mode(const ip6_addr_t *ip6addr, const struct lowpan6_link_addr *mac_addr);
67 |
68 | #if LWIP_6LOWPAN_IPHC
69 | err_t lowpan6_compress_headers(struct netif *netif, u8_t *inbuf, size_t inbuf_size, u8_t *outbuf, size_t outbuf_size,
70 | u8_t *lowpan6_header_len_out, u8_t *hidden_header_len_out, ip6_addr_t *lowpan6_contexts,
71 | const struct lowpan6_link_addr *src, const struct lowpan6_link_addr *dst);
72 | struct pbuf *lowpan6_decompress(struct pbuf *p, u16_t datagram_size, ip6_addr_t *lowpan6_contexts,
73 | struct lowpan6_link_addr *src, struct lowpan6_link_addr *dest);
74 | #endif /* LWIP_6LOWPAN_IPHC */
75 |
76 | #ifdef __cplusplus
77 | }
78 | #endif
79 |
80 | #endif /* LWIP_IPV6 */
81 |
82 | #endif /* LWIP_HDR_LOWPAN6_COMMON_H */
83 |
--------------------------------------------------------------------------------
/core/c/include/netif/ppp/chap-md5.h:
--------------------------------------------------------------------------------
1 | /*
2 | * chap-md5.h - New CHAP/MD5 implementation.
3 | *
4 | * Copyright (c) 2003 Paul Mackerras. All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | *
13 | * 2. The name(s) of the authors of this software must not be used to
14 | * endorse or promote products derived from this software without
15 | * prior written permission.
16 | *
17 | * 3. Redistributions of any form whatsoever must retain the following
18 | * acknowledgment:
19 | * "This product includes software developed by Paul Mackerras
20 | * ".
21 | *
22 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
23 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
25 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
26 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
27 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
28 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 | */
30 |
31 | #include "netif/ppp/ppp_opts.h"
32 | #if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
33 |
34 | extern const struct chap_digest_type md5_digest;
35 |
36 | #endif /* PPP_SUPPORT && CHAP_SUPPORT */
37 |
--------------------------------------------------------------------------------
/core/c/include/netif/ppp/chap_ms.h:
--------------------------------------------------------------------------------
1 | /*
2 | * chap_ms.h - Challenge Handshake Authentication Protocol definitions.
3 | *
4 | * Copyright (c) 1995 Eric Rosenquist. All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | *
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | *
18 | * 3. The name(s) of the authors of this software must not be used to
19 | * endorse or promote products derived from this software without
20 | * prior written permission.
21 | *
22 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
23 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
25 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
26 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
27 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
28 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 | *
30 | * $Id: chap_ms.h,v 1.13 2004/11/15 22:13:26 paulus Exp $
31 | */
32 |
33 | #include "netif/ppp/ppp_opts.h"
34 | #if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */
35 |
36 | #ifndef CHAPMS_INCLUDE
37 | #define CHAPMS_INCLUDE
38 |
39 | extern const struct chap_digest_type chapms_digest;
40 | extern const struct chap_digest_type chapms2_digest;
41 |
42 | #endif /* CHAPMS_INCLUDE */
43 |
44 | #endif /* PPP_SUPPORT && MSCHAP_SUPPORT */
45 |
--------------------------------------------------------------------------------
/core/c/include/netif/ppp/ecp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * ecp.h - Definitions for PPP Encryption Control Protocol.
3 | *
4 | * Copyright (c) 2002 Google, Inc.
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions
9 | * are met:
10 | *
11 | * 1. Redistributions of source code must retain the above copyright
12 | * notice, this list of conditions and the following disclaimer.
13 | *
14 | * 2. Redistributions in binary form must reproduce the above copyright
15 | * notice, this list of conditions and the following disclaimer in
16 | * the documentation and/or other materials provided with the
17 | * distribution.
18 | *
19 | * 3. The name(s) of the authors of this software must not be used to
20 | * endorse or promote products derived from this software without
21 | * prior written permission.
22 | *
23 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
24 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
25 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
26 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
27 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
28 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
29 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 | *
31 | * $Id: ecp.h,v 1.2 2003/01/10 07:12:36 fcusack Exp $
32 | */
33 |
34 | #include "netif/ppp/ppp_opts.h"
35 | #if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in lwipopts.h */
36 |
37 | #ifndef ECP_H
38 | #define ECP_H
39 |
40 | #ifdef __cplusplus
41 | extern "C" {
42 | #endif
43 |
44 | typedef struct ecp_options {
45 | bool required; /* Is ECP required? */
46 | unsigned enctype; /* Encryption type */
47 | } ecp_options;
48 |
49 | extern fsm ecp_fsm[];
50 | extern ecp_options ecp_wantoptions[];
51 | extern ecp_options ecp_gotoptions[];
52 | extern ecp_options ecp_allowoptions[];
53 | extern ecp_options ecp_hisoptions[];
54 |
55 | extern const struct protent ecp_protent;
56 |
57 | #ifdef __cplusplus
58 | }
59 | #endif
60 |
61 | #endif /* ECP_H */
62 | #endif /* PPP_SUPPORT && ECP_SUPPORT */
63 |
--------------------------------------------------------------------------------
/core/c/include/netif/ppp/eui64.h:
--------------------------------------------------------------------------------
1 | /*
2 | * eui64.h - EUI64 routines for IPv6CP.
3 | *
4 | * Copyright (c) 1999 Tommi Komulainen. All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | *
10 | * 1. Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | *
13 | * 2. Redistributions in binary form must reproduce the above copyright
14 | * notice, this list of conditions and the following disclaimer in
15 | * the documentation and/or other materials provided with the
16 | * distribution.
17 | *
18 | * 3. The name(s) of the authors of this software must not be used to
19 | * endorse or promote products derived from this software without
20 | * prior written permission.
21 | *
22 | * 4. Redistributions of any form whatsoever must retain the following
23 | * acknowledgment:
24 | * "This product includes software developed by Tommi Komulainen
25 | * ".
26 | *
27 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
28 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
33 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34 | *
35 | * $Id: eui64.h,v 1.6 2002/12/04 23:03:32 paulus Exp $
36 | */
37 |
38 | #include "netif/ppp/ppp_opts.h"
39 | #if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */
40 |
41 | #ifndef EUI64_H
42 | #define EUI64_H
43 |
44 | #ifdef __cplusplus
45 | extern "C" {
46 | #endif
47 |
48 | /*
49 | * @todo:
50 | *
51 | * Maybe this should be done by processing struct in6_addr directly...
52 | */
53 | typedef union
54 | {
55 | u8_t e8[8];
56 | u16_t e16[4];
57 | u32_t e32[2];
58 | } eui64_t;
59 |
60 | #define eui64_iszero(e) (((e).e32[0] | (e).e32[1]) == 0)
61 | #define eui64_equals(e, o) (((e).e32[0] == (o).e32[0]) && \
62 | ((e).e32[1] == (o).e32[1]))
63 | #define eui64_zero(e) (e).e32[0] = (e).e32[1] = 0;
64 |
65 | #define eui64_copy(s, d) memcpy(&(d), &(s), sizeof(eui64_t))
66 |
67 | #define eui64_magic(e) do { \
68 | (e).e32[0] = magic(); \
69 | (e).e32[1] = magic(); \
70 | (e).e8[0] &= ~2; \
71 | } while (0)
72 | #define eui64_magic_nz(x) do { \
73 | eui64_magic(x); \
74 | } while (eui64_iszero(x))
75 | #define eui64_magic_ne(x, y) do { \
76 | eui64_magic(x); \
77 | } while (eui64_equals(x, y))
78 |
79 | #define eui64_get(ll, cp) do { \
80 | eui64_copy((*cp), (ll)); \
81 | (cp) += sizeof(eui64_t); \
82 | } while (0)
83 |
84 | #define eui64_put(ll, cp) do { \
85 | eui64_copy((ll), (*cp)); \
86 | (cp) += sizeof(eui64_t); \
87 | } while (0)
88 |
89 | #define eui64_set32(e, l) do { \
90 | (e).e32[0] = 0; \
91 | (e).e32[1] = lwip_htonl(l); \
92 | } while (0)
93 | #define eui64_setlo32(e, l) eui64_set32(e, l)
94 |
95 | char *eui64_ntoa(eui64_t); /* Returns ascii representation of id */
96 |
97 | #ifdef __cplusplus
98 | }
99 | #endif
100 |
101 | #endif /* EUI64_H */
102 | #endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */
103 |
--------------------------------------------------------------------------------
/core/c/include/netif/ppp/polarssl/arc4.h:
--------------------------------------------------------------------------------
1 | /**
2 | * \file arc4.h
3 | *
4 | * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
5 | *
6 | * Copyright (C) 2009 Paul Bakker
7 | *
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | *
14 | * * Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * * Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * * Neither the names of PolarSSL or XySSL nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 | #include "netif/ppp/ppp_opts.h"
37 | #if LWIP_INCLUDED_POLARSSL_ARC4
38 |
39 | #ifndef LWIP_INCLUDED_POLARSSL_ARC4_H
40 | #define LWIP_INCLUDED_POLARSSL_ARC4_H
41 |
42 | /**
43 | * \brief ARC4 context structure
44 | */
45 | typedef struct
46 | {
47 | int x; /*!< permutation index */
48 | int y; /*!< permutation index */
49 | unsigned char m[256]; /*!< permutation table */
50 | }
51 | arc4_context;
52 |
53 | #ifdef __cplusplus
54 | extern "C" {
55 | #endif
56 |
57 | /**
58 | * \brief ARC4 key schedule
59 | *
60 | * \param ctx ARC4 context to be initialized
61 | * \param key the secret key
62 | * \param keylen length of the key
63 | */
64 | void arc4_setup( arc4_context *ctx, unsigned char *key, int keylen );
65 |
66 | /**
67 | * \brief ARC4 cipher function
68 | *
69 | * \param ctx ARC4 context
70 | * \param buf buffer to be processed
71 | * \param buflen amount of data in buf
72 | */
73 | void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen );
74 |
75 | #ifdef __cplusplus
76 | }
77 | #endif
78 |
79 | #endif /* LWIP_INCLUDED_POLARSSL_ARC4_H */
80 |
81 | #endif /* LWIP_INCLUDED_POLARSSL_ARC4 */
82 |
--------------------------------------------------------------------------------
/core/c/include/netif/ppp/polarssl/des.h:
--------------------------------------------------------------------------------
1 | /**
2 | * \file des.h
3 | *
4 | * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
5 | *
6 | * Copyright (C) 2009 Paul Bakker
7 | *
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | *
14 | * * Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * * Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * * Neither the names of PolarSSL or XySSL nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 | #include "netif/ppp/ppp_opts.h"
37 | #if LWIP_INCLUDED_POLARSSL_DES
38 |
39 | #ifndef LWIP_INCLUDED_POLARSSL_DES_H
40 | #define LWIP_INCLUDED_POLARSSL_DES_H
41 |
42 | #define DES_ENCRYPT 1
43 | #define DES_DECRYPT 0
44 |
45 | /**
46 | * \brief DES context structure
47 | */
48 | typedef struct
49 | {
50 | int mode; /*!< encrypt/decrypt */
51 | unsigned long sk[32]; /*!< DES subkeys */
52 | }
53 | des_context;
54 |
55 | #ifdef __cplusplus
56 | extern "C" {
57 | #endif
58 |
59 | /**
60 | * \brief DES key schedule (56-bit, encryption)
61 | *
62 | * \param ctx DES context to be initialized
63 | * \param key 8-byte secret key
64 | */
65 | void des_setkey_enc( des_context *ctx, unsigned char key[8] );
66 |
67 | /**
68 | * \brief DES key schedule (56-bit, decryption)
69 | *
70 | * \param ctx DES context to be initialized
71 | * \param key 8-byte secret key
72 | */
73 | void des_setkey_dec( des_context *ctx, unsigned char key[8] );
74 |
75 | /**
76 | * \brief DES-ECB block encryption/decryption
77 | *
78 | * \param ctx DES context
79 | * \param input 64-bit input block
80 | * \param output 64-bit output block
81 | */
82 | void des_crypt_ecb( des_context *ctx,
83 | const unsigned char input[8],
84 | unsigned char output[8] );
85 |
86 | #ifdef __cplusplus
87 | }
88 | #endif
89 |
90 | #endif /* LWIP_INCLUDED_POLARSSL_DES_H */
91 |
92 | #endif /* LWIP_INCLUDED_POLARSSL_DES */
93 |
--------------------------------------------------------------------------------
/core/c/include/netif/ppp/polarssl/md4.h:
--------------------------------------------------------------------------------
1 | /**
2 | * \file md4.h
3 | *
4 | * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
5 | *
6 | * Copyright (C) 2009 Paul Bakker
7 | *
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | *
14 | * * Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * * Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * * Neither the names of PolarSSL or XySSL nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 | #include "netif/ppp/ppp_opts.h"
37 | #if LWIP_INCLUDED_POLARSSL_MD4
38 |
39 | #ifndef LWIP_INCLUDED_POLARSSL_MD4_H
40 | #define LWIP_INCLUDED_POLARSSL_MD4_H
41 |
42 | /**
43 | * \brief MD4 context structure
44 | */
45 | typedef struct
46 | {
47 | unsigned long total[2]; /*!< number of bytes processed */
48 | unsigned long state[4]; /*!< intermediate digest state */
49 | unsigned char buffer[64]; /*!< data block being processed */
50 | }
51 | md4_context;
52 |
53 | #ifdef __cplusplus
54 | extern "C" {
55 | #endif
56 |
57 | /**
58 | * \brief MD4 context setup
59 | *
60 | * \param ctx context to be initialized
61 | */
62 | void md4_starts( md4_context *ctx );
63 |
64 | /**
65 | * \brief MD4 process buffer
66 | *
67 | * \param ctx MD4 context
68 | * \param input buffer holding the data
69 | * \param ilen length of the input data
70 | */
71 | void md4_update( md4_context *ctx, const unsigned char *input, int ilen );
72 |
73 | /**
74 | * \brief MD4 final digest
75 | *
76 | * \param ctx MD4 context
77 | * \param output MD4 checksum result
78 | */
79 | void md4_finish( md4_context *ctx, unsigned char output[16] );
80 |
81 | /**
82 | * \brief Output = MD4( input buffer )
83 | *
84 | * \param input buffer holding the data
85 | * \param ilen length of the input data
86 | * \param output MD4 checksum result
87 | */
88 | void md4( unsigned char *input, int ilen, unsigned char output[16] );
89 |
90 |
91 | #ifdef __cplusplus
92 | }
93 | #endif
94 |
95 | #endif /* LWIP_INCLUDED_POLARSSL_MD4_H */
96 |
97 | #endif /* LWIP_INCLUDED_POLARSSL_MD4 */
98 |
--------------------------------------------------------------------------------
/core/c/include/netif/ppp/polarssl/md5.h:
--------------------------------------------------------------------------------
1 | /**
2 | * \file md5.h
3 | *
4 | * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
5 | *
6 | * Copyright (C) 2009 Paul Bakker
7 | *
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | *
14 | * * Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * * Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * * Neither the names of PolarSSL or XySSL nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 | #include "netif/ppp/ppp_opts.h"
37 | #if LWIP_INCLUDED_POLARSSL_MD5
38 |
39 | #ifndef LWIP_INCLUDED_POLARSSL_MD5_H
40 | #define LWIP_INCLUDED_POLARSSL_MD5_H
41 |
42 | /**
43 | * \brief MD5 context structure
44 | */
45 | typedef struct
46 | {
47 | unsigned long total[2]; /*!< number of bytes processed */
48 | unsigned long state[4]; /*!< intermediate digest state */
49 | unsigned char buffer[64]; /*!< data block being processed */
50 | }
51 | md5_context;
52 |
53 | #ifdef __cplusplus
54 | extern "C" {
55 | #endif
56 |
57 | /**
58 | * \brief MD5 context setup
59 | *
60 | * \param ctx context to be initialized
61 | */
62 | void md5_starts( md5_context *ctx );
63 |
64 | /**
65 | * \brief MD5 process buffer
66 | *
67 | * \param ctx MD5 context
68 | * \param input buffer holding the data
69 | * \param ilen length of the input data
70 | */
71 | void md5_update( md5_context *ctx, const unsigned char *input, int ilen );
72 |
73 | /**
74 | * \brief MD5 final digest
75 | *
76 | * \param ctx MD5 context
77 | * \param output MD5 checksum result
78 | */
79 | void md5_finish( md5_context *ctx, unsigned char output[16] );
80 |
81 | /**
82 | * \brief Output = MD5( input buffer )
83 | *
84 | * \param input buffer holding the data
85 | * \param ilen length of the input data
86 | * \param output MD5 checksum result
87 | */
88 | void md5( unsigned char *input, int ilen, unsigned char output[16] );
89 |
90 | #ifdef __cplusplus
91 | }
92 | #endif
93 |
94 | #endif /* LWIP_INCLUDED_POLARSSL_MD5_H */
95 |
96 | #endif /* LWIP_INCLUDED_POLARSSL_MD5 */
97 |
--------------------------------------------------------------------------------
/core/c/include/netif/ppp/polarssl/sha1.h:
--------------------------------------------------------------------------------
1 | /**
2 | * \file sha1.h
3 | *
4 | * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
5 | *
6 | * Copyright (C) 2009 Paul Bakker
7 | *
8 | * All rights reserved.
9 | *
10 | * Redistribution and use in source and binary forms, with or without
11 | * modification, are permitted provided that the following conditions
12 | * are met:
13 | *
14 | * * Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * * Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * * Neither the names of PolarSSL or XySSL nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 | #include "netif/ppp/ppp_opts.h"
37 | #if LWIP_INCLUDED_POLARSSL_SHA1
38 |
39 | #ifndef LWIP_INCLUDED_POLARSSL_SHA1_H
40 | #define LWIP_INCLUDED_POLARSSL_SHA1_H
41 |
42 | /**
43 | * \brief SHA-1 context structure
44 | */
45 | typedef struct
46 | {
47 | unsigned long total[2]; /*!< number of bytes processed */
48 | unsigned long state[5]; /*!< intermediate digest state */
49 | unsigned char buffer[64]; /*!< data block being processed */
50 | }
51 | sha1_context;
52 |
53 | #ifdef __cplusplus
54 | extern "C" {
55 | #endif
56 |
57 | /**
58 | * \brief SHA-1 context setup
59 | *
60 | * \param ctx context to be initialized
61 | */
62 | void sha1_starts( sha1_context *ctx );
63 |
64 | /**
65 | * \brief SHA-1 process buffer
66 | *
67 | * \param ctx SHA-1 context
68 | * \param input buffer holding the data
69 | * \param ilen length of the input data
70 | */
71 | void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );
72 |
73 | /**
74 | * \brief SHA-1 final digest
75 | *
76 | * \param ctx SHA-1 context
77 | * \param output SHA-1 checksum result
78 | */
79 | void sha1_finish( sha1_context *ctx, unsigned char output[20] );
80 |
81 | /**
82 | * \brief Output = SHA-1( input buffer )
83 | *
84 | * \param input buffer holding the data
85 | * \param ilen length of the input data
86 | * \param output SHA-1 checksum result
87 | */
88 | void sha1( unsigned char *input, int ilen, unsigned char output[20] );
89 |
90 | #ifdef __cplusplus
91 | }
92 | #endif
93 |
94 | #endif /* LWIP_INCLUDED_POLARSSL_SHA1_H */
95 |
96 | #endif /* LWIP_INCLUDED_POLARSSL_SHA1 */
97 |
--------------------------------------------------------------------------------
/core/c/include/netif/ppp/pppdebug.h:
--------------------------------------------------------------------------------
1 | /*****************************************************************************
2 | * pppdebug.h - System debugging utilities.
3 | *
4 | * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
5 | * portions Copyright (c) 1998 Global Election Systems Inc.
6 | * portions Copyright (c) 2001 by Cognizant Pty Ltd.
7 | *
8 | * The authors hereby grant permission to use, copy, modify, distribute,
9 | * and license this software and its documentation for any purpose, provided
10 | * that existing copyright notices are retained in all copies and that this
11 | * notice and the following disclaimer are included verbatim in any
12 | * distributions. No written agreement, license, or royalty fee is required
13 | * for any of the authorized uses.
14 | *
15 | * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 | * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 | *
26 | ******************************************************************************
27 | * REVISION HISTORY (please don't use tabs!)
28 | *
29 | * 03-01-01 Marc Boucher
30 | * Ported to lwIP.
31 | * 98-07-29 Guy Lancaster , Global Election Systems Inc.
32 | * Original.
33 | *
34 | *****************************************************************************
35 | */
36 |
37 | #include "netif/ppp/ppp_opts.h"
38 | #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
39 |
40 | #ifndef PPPDEBUG_H
41 | #define PPPDEBUG_H
42 |
43 | #ifdef __cplusplus
44 | extern "C" {
45 | #endif
46 |
47 | /* Trace levels. */
48 | #define LOG_CRITICAL (PPP_DEBUG | LWIP_DBG_LEVEL_SEVERE)
49 | #define LOG_ERR (PPP_DEBUG | LWIP_DBG_LEVEL_SEVERE)
50 | #define LOG_NOTICE (PPP_DEBUG | LWIP_DBG_LEVEL_WARNING)
51 | #define LOG_WARNING (PPP_DEBUG | LWIP_DBG_LEVEL_WARNING)
52 | #define LOG_INFO (PPP_DEBUG)
53 | #define LOG_DETAIL (PPP_DEBUG)
54 | #define LOG_DEBUG (PPP_DEBUG)
55 |
56 | #if PPP_DEBUG
57 |
58 | #define MAINDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a)
59 | #define SYSDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a)
60 | #define FSMDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a)
61 | #define LCPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a)
62 | #define IPCPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a)
63 | #define IPV6CPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a)
64 | #define UPAPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a)
65 | #define CHAPDEBUG(a) LWIP_DEBUGF(LWIP_DBG_LEVEL_WARNING, a)
66 | #define PPPDEBUG(a, b) LWIP_DEBUGF(a, b)
67 |
68 | #else /* PPP_DEBUG */
69 |
70 | #define MAINDEBUG(a)
71 | #define SYSDEBUG(a)
72 | #define FSMDEBUG(a)
73 | #define LCPDEBUG(a)
74 | #define IPCPDEBUG(a)
75 | #define IPV6CPDEBUG(a)
76 | #define UPAPDEBUG(a)
77 | #define CHAPDEBUG(a)
78 | #define PPPDEBUG(a, b)
79 |
80 | #endif /* PPP_DEBUG */
81 |
82 | #ifdef __cplusplus
83 | }
84 | #endif
85 |
86 | #endif /* PPPDEBUG_H */
87 |
88 | #endif /* PPP_SUPPORT */
89 |
--------------------------------------------------------------------------------
/core/c/include/netif/slipif.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | *
4 | * SLIP netif API
5 | */
6 |
7 | /*
8 | * Copyright (c) 2001, Swedish Institute of Computer Science.
9 | * All rights reserved.
10 | *
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted provided that the following conditions
13 | * are met:
14 | * 1. Redistributions of source code must retain the above copyright
15 | * notice, this list of conditions and the following disclaimer.
16 | * 2. Redistributions in binary form must reproduce the above copyright
17 | * notice, this list of conditions and the following disclaimer in the
18 | * documentation and/or other materials provided with the distribution.
19 | * 3. Neither the name of the Institute nor the names of its contributors
20 | * may be used to endorse or promote products derived from this software
21 | * without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 | * SUCH DAMAGE.
34 | *
35 | * This file is part of the lwIP TCP/IP stack.
36 | *
37 | * Author: Adam Dunkels
38 | *
39 | */
40 | #ifndef LWIP_HDR_NETIF_SLIPIF_H
41 | #define LWIP_HDR_NETIF_SLIPIF_H
42 |
43 | #include "lwip/opt.h"
44 | #include "lwip/netif.h"
45 |
46 | /** Set this to 1 to start a thread that blocks reading on the serial line
47 | * (using sio_read()).
48 | */
49 | #ifndef SLIP_USE_RX_THREAD
50 | #define SLIP_USE_RX_THREAD !NO_SYS
51 | #endif
52 |
53 | /** Set this to 1 to enable functions to pass in RX bytes from ISR context.
54 | * If enabled, slipif_received_byte[s]() process incoming bytes and put assembled
55 | * packets on a queue, which is fed into lwIP from slipif_poll().
56 | * If disabled, slipif_poll() polls the serial line (using sio_tryread()).
57 | */
58 | #ifndef SLIP_RX_FROM_ISR
59 | #define SLIP_RX_FROM_ISR 0
60 | #endif
61 |
62 | /** Set this to 1 (default for SLIP_RX_FROM_ISR) to queue incoming packets
63 | * received by slipif_received_byte[s]() as long as PBUF_POOL pbufs are available.
64 | * If disabled, packets will be dropped if more than one packet is received.
65 | */
66 | #ifndef SLIP_RX_QUEUE
67 | #define SLIP_RX_QUEUE SLIP_RX_FROM_ISR
68 | #endif
69 |
70 | #ifdef __cplusplus
71 | extern "C" {
72 | #endif
73 |
74 | err_t slipif_init(struct netif * netif);
75 | void slipif_poll(struct netif *netif);
76 | #if SLIP_RX_FROM_ISR
77 | void slipif_process_rxqueue(struct netif *netif);
78 | void slipif_received_byte(struct netif *netif, u8_t data);
79 | void slipif_received_bytes(struct netif *netif, u8_t *data, u8_t len);
80 | #endif /* SLIP_RX_FROM_ISR */
81 |
82 | #ifdef __cplusplus
83 | }
84 | #endif
85 |
86 | #endif /* LWIP_HDR_NETIF_SLIPIF_H */
87 |
--------------------------------------------------------------------------------
/core/c/include/netif/zepif.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file
3 | *
4 | * A netif implementing the ZigBee Eencapsulation Protocol (ZEP).
5 | * This is used to tunnel 6LowPAN over UDP.
6 | */
7 |
8 | /*
9 | * Copyright (c) 2018 Simon Goldschmidt
10 | * All rights reserved.
11 | *
12 | * Redistribution and use in source and binary forms, with or without modification,
13 | * are permitted provided that the following conditions are met:
14 | *
15 | * 1. Redistributions of source code must retain the above copyright notice,
16 | * this list of conditions and the following disclaimer.
17 | * 2. Redistributions in binary form must reproduce the above copyright notice,
18 | * this list of conditions and the following disclaimer in the documentation
19 | * and/or other materials provided with the distribution.
20 | * 3. The name of the author may not be used to endorse or promote products
21 | * derived from this software without specific prior written permission.
22 | *
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
26 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 | * OF SUCH DAMAGE.
33 | *
34 | * This file is part of the lwIP TCP/IP stack.
35 | *
36 | * Author: Simon Goldschmidt
37 | *
38 | */
39 |
40 | #ifndef LWIP_HDR_ZEPIF_H
41 | #define LWIP_HDR_ZEPIF_H
42 |
43 | #include "lwip/opt.h"
44 | #include "netif/lowpan6.h"
45 |
46 | #if LWIP_IPV6 && LWIP_UDP /* don't build if not configured for use in lwipopts.h */
47 |
48 | #include "lwip/netif.h"
49 |
50 | #ifdef __cplusplus
51 | extern "C" {
52 | #endif
53 |
54 | #define ZEPIF_DEFAULT_UDP_PORT 17754
55 |
56 | /** Pass this struct as 'state' to netif_add to control the behaviour
57 | * of this netif. If NULL is passed, default behaviour is chosen */
58 | struct zepif_init {
59 | /** The UDP port used to ZEP frames from (0 = default) */
60 | u16_t zep_src_udp_port;
61 | /** The UDP port used to ZEP frames to (0 = default) */
62 | u16_t zep_dst_udp_port;
63 | /** The IP address to sed ZEP frames from (NULL = ANY) */
64 | const ip_addr_t *zep_src_ip_addr;
65 | /** The IP address to sed ZEP frames to (NULL = BROADCAST) */
66 | const ip_addr_t *zep_dst_ip_addr;
67 | /** If != NULL, the udp pcb is bound to this netif */
68 | const struct netif *zep_netif;
69 | /** MAC address of the 6LowPAN device */
70 | u8_t addr[6];
71 | };
72 |
73 | err_t zepif_init(struct netif *netif);
74 |
75 | #ifdef __cplusplus
76 | }
77 | #endif
78 |
79 | #endif /* LWIP_IPV6 && LWIP_UDP */
80 |
81 | #endif /* LWIP_HDR_ZEPIF_H */
82 |
--------------------------------------------------------------------------------
/core/c_api.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #cgo android LDFLAGS: -llog
6 | #include
7 | #include "c/api/err.c"
8 | */
9 | import "C"
10 |
--------------------------------------------------------------------------------
/core/c_core.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #cgo android LDFLAGS: -llog
6 | #include
7 | #include "c/core/init.c"
8 | #include "c/core/def.c"
9 | #include "c/core/dns.c"
10 | #include "c/core/inet_chksum.c"
11 | #include "c/core/ip.c"
12 | #include "c/core/mem.c"
13 | #include "c/core/memp.c"
14 | #include "c/core/netif.c"
15 | #include "c/core/pbuf.c"
16 | #include "c/core/raw.c"
17 | #include "c/core/stats.c"
18 | #include "c/core/sys.c"
19 | #include "c/core/tcp.c"
20 | #include "c/core/tcp_in.c"
21 | #include "c/core/tcp_out.c"
22 | #include "c/core/timeouts.c"
23 | #include "c/core/udp.c"
24 | */
25 | import "C"
26 |
--------------------------------------------------------------------------------
/core/c_core_4.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #cgo android LDFLAGS: -llog
6 | #include
7 | #include "c/core/ipv4/acd.c"
8 | #include "c/core/ipv4/autoip.c"
9 | #include "c/core/ipv4/dhcp.c"
10 | #include "c/core/ipv4/etharp.c"
11 | #include "c/core/ipv4/icmp.c"
12 | #include "c/core/ipv4/igmp.c"
13 | #include "c/core/ipv4/ip4_frag.c"
14 | #include "c/core/ipv4/ip4.c"
15 | #include "c/core/ipv4/ip4_addr.c"
16 | */
17 | import "C"
18 |
--------------------------------------------------------------------------------
/core/c_core_6.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #cgo android LDFLAGS: -llog
6 | #include
7 | #include "c/core/ipv6/dhcp6.c"
8 | #include "c/core/ipv6/ethip6.c"
9 | #include "c/core/ipv6/icmp6.c"
10 | #include "c/core/ipv6/inet6.c"
11 | #include "c/core/ipv6/ip6.c"
12 | #include "c/core/ipv6/ip6_addr.c"
13 | #include "c/core/ipv6/ip6_frag.c"
14 | #include "c/core/ipv6/mld6.c"
15 | #include "c/core/ipv6/nd6.c"
16 | */
17 | import "C"
18 |
--------------------------------------------------------------------------------
/core/c_custom.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #cgo android LDFLAGS: -llog
6 | #include
7 | #include "c/custom/sys_arch.c"
8 | */
9 | import "C"
10 |
--------------------------------------------------------------------------------
/core/conn.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | import (
4 | "net"
5 | "time"
6 | )
7 |
8 | // TCPConn abstracts a TCP connection comming from TUN. This connection
9 | // should be handled by a registered TCP proxy handler. It's important
10 | // to note that callback members are called from lwIP, they are already
11 | // in the lwIP thread when they are called, that is, they are holding
12 | // the lwipMutex.
13 | type TCPConn interface {
14 | // Sent will be called when sent data has been acknowledged by peer.
15 | Sent(len uint16) error
16 |
17 | // Receive will be called when data arrives from TUN.
18 | Receive(data []byte) error
19 |
20 | // Err will be called when a fatal error has occurred on the connection.
21 | // The corresponding pcb is already freed when this callback is called
22 | Err(err error)
23 |
24 | // LocalClosed will be called when lwIP receives a FIN segment on a
25 | // connection.
26 | LocalClosed() error
27 |
28 | // RemoteAddr returns the destination network address.
29 | RemoteAddr() net.Addr
30 |
31 | // LocalAddr returns the local client network address.
32 | LocalAddr() net.Addr
33 |
34 | // Read reads data comming from TUN, note that it reads from an
35 | // underlying pipe that the writer writes in the lwip thread,
36 | // write op blocks until previous written data is consumed, one
37 | // should read out all data as soon as possible.
38 | Read(data []byte) (int, error)
39 |
40 | // Write writes data to TUN.
41 | Write(data []byte) (int, error)
42 |
43 | // Close closes the connection.
44 | Close() error
45 |
46 | // CloseWrite closes the writing side by sending a FIN
47 | // segment to local peer. That means we can write no further
48 | // data to TUN.
49 | CloseWrite() error
50 |
51 | // CloseRead closes the reading side. That means we can no longer
52 | // read more from TUN.
53 | CloseRead() error
54 |
55 | // Abort aborts the connection by sending a RST segment.
56 | Abort()
57 |
58 | SetDeadline(t time.Time) error
59 | SetReadDeadline(t time.Time) error
60 | SetWriteDeadline(t time.Time) error
61 | }
62 |
63 | // TCPConn abstracts a UDP connection comming from TUN. This connection
64 | // should be handled by a registered UDP proxy handler.
65 | type UDPConn interface {
66 | // LocalAddr returns the local client network address.
67 | LocalAddr() *net.UDPAddr
68 |
69 | // ReceiveTo will be called when data arrives from TUN, and the received
70 | // data should be sent to addr.
71 | ReceiveTo(data []byte, addr *net.UDPAddr) error
72 |
73 | // WriteFrom writes data to TUN, addr will be set as source address of
74 | // UDP packets that output to TUN.
75 | WriteFrom(data []byte, addr *net.UDPAddr) (int, error)
76 |
77 | // Close closes the connection.
78 | Close() error
79 | }
80 |
--------------------------------------------------------------------------------
/core/errors.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | // Error codes defined in lwIP.
4 | // /** Definitions for error constants. */
5 | // typedef enum {
6 | // /** No error, everything OK. */
7 | // ERR_OK = 0,
8 | // /** Out of memory error. */
9 | // ERR_MEM = -1,
10 | // /** Buffer error. */
11 | // ERR_BUF = -2,
12 | // /** Timeout. */
13 | // ERR_TIMEOUT = -3,
14 | // /** Routing problem. */
15 | // ERR_RTE = -4,
16 | // /** Operation in progress */
17 | // ERR_INPROGRESS = -5,
18 | // /** Illegal value. */
19 | // ERR_VAL = -6,
20 | // /** Operation would block. */
21 | // ERR_WOULDBLOCK = -7,
22 | // /** Address in use. */
23 | // ERR_USE = -8,
24 | // /** Already connecting. */
25 | // ERR_ALREADY = -9,
26 | // /** Conn already established.*/
27 | // ERR_ISCONN = -10,
28 | // /** Not connected. */
29 | // ERR_CONN = -11,
30 | // /** Low-level netif error */
31 | // ERR_IF = -12,
32 | //
33 | // /** Connection aborted. */
34 | // ERR_ABRT = -13,
35 | // /** Connection reset. */
36 | // ERR_RST = -14,
37 | // /** Connection closed. */
38 | // ERR_CLSD = -15,
39 | // /** Illegal argument. */
40 | // ERR_ARG = -16
41 | // } err_enum_t;
42 |
43 | const (
44 | LWIP_ERR_OK int = iota
45 | LWIP_ERR_ABRT
46 | LWIP_ERR_CONN
47 | LWIP_ERR_CLSD
48 | )
49 |
50 | type lwipError struct {
51 | Code int
52 | }
53 |
54 | func NewLWIPError(code int) error {
55 | return &lwipError{Code: code}
56 | }
57 |
58 | func (e *lwipError) Error() string {
59 | return "error code " + string(e.Code)
60 | }
61 |
--------------------------------------------------------------------------------
/core/handler.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | import (
4 | "net"
5 | )
6 |
7 | // TCPConnHandler handles TCP connections comming from TUN.
8 | type TCPConnHandler interface {
9 | // Handle handles the conn for target.
10 | Handle(conn net.Conn, target *net.TCPAddr) error
11 | }
12 |
13 | // UDPConnHandler handles UDP connections comming from TUN.
14 | type UDPConnHandler interface {
15 | // Connect connects the proxy server. Note that target can be nil.
16 | Connect(conn UDPConn, target *net.UDPAddr) error
17 |
18 | // ReceiveTo will be called when data arrives from TUN.
19 | ReceiveTo(conn UDPConn, data []byte, addr *net.UDPAddr) error
20 | }
21 |
22 | var tcpConnHandler TCPConnHandler
23 | var udpConnHandler UDPConnHandler
24 |
25 | func RegisterTCPConnHandler(h TCPConnHandler) {
26 | tcpConnHandler = h
27 | }
28 |
29 | func RegisterUDPConnHandler(h UDPConnHandler) {
30 | udpConnHandler = h
31 | }
32 |
--------------------------------------------------------------------------------
/core/lwip_access_wrapper.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #include
6 | #include "lwip/tcp.h"
7 | #include "lwip/udp.h"
8 | #include "lwip/timeouts.h"
9 | */
10 | import "C"
11 | import (
12 | "errors"
13 | //"fmt"
14 | //"runtime"
15 | "sync"
16 | "sync/atomic"
17 | "unsafe"
18 | //"github.com/eycorsican/go-tun2socks/common/log"
19 | syncex "github.com/eycorsican/go-tun2socks/component/go-syncex"
20 | )
21 |
22 | // lwIP runs in a single thread, locking is needed in Go runtime.
23 | var lwipMutex = &syncex.RecursiveMutex{}
24 |
25 | type MutexWrapper struct {
26 | lock *sync.Mutex
27 | count int32
28 | }
29 |
30 | // pass anything to disable log trace
31 | // pass nothing to enable log trace
32 | func (m *MutexWrapper) Lock( /*params ...bool*/ ) {
33 | /*if len(params) != 0 {
34 | m.lock.Lock()
35 | atomic.AddInt32(&m.count, 1)
36 | return
37 | }
38 |
39 | pc := make([]uintptr, 10) // at least 1 entry needed
40 | runtime.Callers(2, pc)
41 | f := runtime.FuncForPC(pc[0])
42 | file, line := f.FileLine(pc[0])
43 | s := fmt.Sprintf("%s:%d %s\n", file, line, f.Name())
44 |
45 | log.Infof("MutexWrapper before Lock %v %s", atomic.LoadInt32(&m.count), s) */
46 | m.lock.Lock()
47 | atomic.AddInt32(&m.count, 1)
48 | /*log.Infof("MutexWrapper after Lock %v %s", atomic.LoadInt32(&m.count), s) */
49 | }
50 |
51 | // pass anything to disable log trace
52 | // pass nothing to enable log trace
53 | func (m *MutexWrapper) Unlock( /*params ...bool*/ ) {
54 | /*if len(params) != 0 {
55 | m.lock.Unlock()
56 | atomic.AddInt32(&m.count, -1)
57 | return
58 | }
59 |
60 | pc := make([]uintptr, 10) // at least 1 entry needed
61 | runtime.Callers(2, pc)
62 | f := runtime.FuncForPC(pc[0])
63 | file, line := f.FileLine(pc[0])
64 | s := fmt.Sprintf("%s:%d %s\n", file, line, f.Name())
65 |
66 | log.Infof("MutexWrapper before Unlock %v %s", atomic.LoadInt32(&m.count), s) */
67 | m.lock.Unlock()
68 | atomic.AddInt32(&m.count, -1)
69 | /*log.Infof("MutexWrapper after Unlock %v %s", atomic.LoadInt32(&m.count), s) */
70 | }
71 |
72 | // ipaddr_ntoa() is using a global static buffer to return result,
73 | // reentrants are not allowed, caller is required to lock lwipMutex.
74 | //export ipAddrNTOA
75 | func ipAddrNTOA(ipaddr C.struct_ip_addr) string {
76 | lwipMutex.Lock()
77 | defer lwipMutex.Unlock()
78 | return C.GoString(C.ipaddr_ntoa(&ipaddr))
79 | }
80 |
81 | //export ipAddrATON
82 | func ipAddrATON(cp string, addr *C.struct_ip_addr) error {
83 | lwipMutex.Lock()
84 | defer lwipMutex.Unlock()
85 | ccp := C.CString(cp)
86 | defer C.free(unsafe.Pointer(ccp))
87 | if r := C.ipaddr_aton(ccp, addr); r == 0 {
88 | return errors.New("failed to convert IP address")
89 | } else {
90 | return nil
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/core/lwip_other.go:
--------------------------------------------------------------------------------
1 | // +build linux darwin
2 |
3 | package core
4 |
5 | /*
6 | #cgo CFLAGS: -I./c/custom -I./c/include
7 | #include "lwip/init.h"
8 | */
9 | import "C"
10 |
11 | func lwipInit() {
12 | C.lwip_init() // Initialze modules.
13 | }
14 |
--------------------------------------------------------------------------------
/core/lwip_windows.go:
--------------------------------------------------------------------------------
1 | // +build windows
2 |
3 | package core
4 |
5 | /*
6 | #cgo CFLAGS: -I./c/custom -I./c/include
7 | #include "lwip/sys.h"
8 | #include "lwip/init.h"
9 | */
10 | import "C"
11 |
12 | func lwipInit() {
13 | C.sys_init() // Initialze sys_arch layer, must be called before anything else.
14 | C.lwip_init() // Initialze modules.
15 | }
16 |
--------------------------------------------------------------------------------
/core/output.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #include "lwip/tcp.h"
6 |
7 | extern err_t output(struct pbuf *p);
8 |
9 | err_t
10 | output_ip4(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr)
11 | {
12 | return output(p);
13 | }
14 |
15 | err_t
16 | output_ip6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr)
17 | {
18 | return output(p);
19 | }
20 |
21 | void
22 | set_output()
23 | {
24 | if (netif_list != NULL) {
25 | (*netif_list).output = output_ip4;
26 | (*netif_list).output_ip6 = output_ip6;
27 | }
28 | }
29 | */
30 | import "C"
31 | import (
32 | "errors"
33 | )
34 |
35 | var OutputFn func([]byte) (int, error)
36 |
37 | func RegisterOutputFn(fn func([]byte) (int, error)) {
38 | OutputFn = fn
39 | C.set_output()
40 | }
41 |
42 | func init() {
43 | OutputFn = func(data []byte) (int, error) {
44 | return 0, errors.New("output function not set")
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/core/output_export.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #include "lwip/tcp.h"
6 | */
7 | import "C"
8 | import (
9 | "github.com/eycorsican/go-tun2socks/component/pool"
10 | "unsafe"
11 | )
12 |
13 | //export output
14 | func output(p *C.struct_pbuf) C.err_t {
15 | // In most case, all data are in the same pbuf struct, data copying can be avoid by
16 | // backing Go slice with C array. Buf if there are multiple pbuf structs holding the
17 | // data, we must copy data for sending them in one pass.
18 | lwipMutex.Lock()
19 | defer lwipMutex.Unlock()
20 | totlen := int(p.tot_len)
21 | if p.tot_len == p.len {
22 | buf := (*[1 << 30]byte)(unsafe.Pointer(p.payload))[:totlen:totlen]
23 | OutputFn(buf[:totlen])
24 | } else {
25 | buf := pool.NewBytes(totlen)
26 | defer pool.FreeBytes(buf)
27 | C.pbuf_copy_partial(p, unsafe.Pointer(&buf[0]), p.tot_len, 0) // data copy here!
28 | OutputFn(buf[:totlen])
29 | }
30 | return C.ERR_OK
31 | }
32 |
--------------------------------------------------------------------------------
/core/tcp_callback.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #include "lwip/tcp.h"
6 |
7 | extern err_t tcpAcceptFn(void *arg, struct tcp_pcb *newpcb, err_t err);
8 |
9 | void
10 | set_tcp_accept_callback(struct tcp_pcb *pcb) {
11 | tcp_accept(pcb, tcpAcceptFn);
12 | }
13 |
14 | extern err_t tcpRecvFn(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
15 |
16 | void
17 | set_tcp_recv_callback(struct tcp_pcb *pcb) {
18 | tcp_recv(pcb, tcpRecvFn);
19 | }
20 |
21 | extern err_t tcpSentFn(void *arg, struct tcp_pcb *tpcb, u16_t len);
22 |
23 | void
24 | set_tcp_sent_callback(struct tcp_pcb *pcb) {
25 | tcp_sent(pcb, tcpSentFn);
26 | }
27 |
28 | extern void tcpErrFn(void *arg, err_t err);
29 |
30 | void
31 | set_tcp_err_callback(struct tcp_pcb *pcb) {
32 | tcp_err(pcb, tcpErrFn);
33 | }
34 | */
35 | import "C"
36 |
37 | func setTCPAcceptCallback(pcb *C.struct_tcp_pcb) {
38 | C.set_tcp_accept_callback(pcb)
39 | }
40 |
41 | func setTCPRecvCallback(pcb *C.struct_tcp_pcb) {
42 | C.set_tcp_recv_callback(pcb)
43 | }
44 |
45 | func setTCPSentCallback(pcb *C.struct_tcp_pcb) {
46 | C.set_tcp_sent_callback(pcb)
47 | }
48 |
49 | func setTCPErrCallback(pcb *C.struct_tcp_pcb) {
50 | C.set_tcp_err_callback(pcb)
51 | }
52 |
--------------------------------------------------------------------------------
/core/udp_callback.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #include "lwip/udp.h"
6 | #include "lwip/ip_addr.h"
7 |
8 | extern void udpRecvFn(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port, const ip_addr_t *dest_addr, u16_t dest_port);
9 |
10 | void
11 | set_udp_recv_callback(struct udp_pcb *pcb, void *recv_arg) {
12 | udp_recv(pcb, udpRecvFn, recv_arg);
13 | }
14 |
15 | extern void go_tun2socks_ip_addr_copy(ip_addr_t *dest, ip_addr_t *src);
16 |
17 | void
18 | go_tun2socks_ip_addr_copy(ip_addr_t *dest, ip_addr_t *src) {
19 | ip_addr_copy(*dest, *src);
20 | }
21 | */
22 | import "C"
23 | import (
24 | "unsafe"
25 | )
26 |
27 | func setUDPRecvCallback(pcb *C.struct_udp_pcb, recvArg unsafe.Pointer) {
28 | C.set_udp_recv_callback(pcb, recvArg)
29 | }
30 |
31 | func copyLwipIpAddr(dest, src *C.ip_addr_t) {
32 | C.go_tun2socks_ip_addr_copy(dest, src)
33 | }
34 |
--------------------------------------------------------------------------------
/core/udp_callback_export.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | /*
4 | #cgo CFLAGS: -I./c/custom -I./c/include
5 | #include "lwip/udp.h"
6 | */
7 | import "C"
8 | import (
9 | "unsafe"
10 |
11 | "github.com/eycorsican/go-tun2socks/component/pool"
12 | )
13 |
14 | //export udpRecvFn
15 | func udpRecvFn(arg unsafe.Pointer, pcb *C.struct_udp_pcb, p *C.struct_pbuf, addr *C.ip_addr_t, port C.u16_t, destAddr *C.ip_addr_t, destPort C.u16_t) {
16 | // XXX: * ATTENTION: Be aware that 'addr' might point into the pbuf 'p' so freeing this pbuf
17 | // * can make 'addr' invalid, too.
18 | // Let's copy addr in case accessing invalid pointer
19 | lwipMutex.Lock()
20 | defer lwipMutex.Unlock()
21 | defer func(pb *C.struct_pbuf) {
22 | lwipMutex.Lock()
23 | defer lwipMutex.Unlock()
24 | if pb != nil {
25 | C.pbuf_free(pb)
26 | pb = nil
27 | }
28 | }(p)
29 |
30 | if pcb == nil {
31 | return
32 | }
33 | addrCopy := C.ip_addr_t{}
34 | destAddrCopy := C.ip_addr_t{}
35 | copyLwipIpAddr(&addrCopy, addr)
36 | copyLwipIpAddr(&destAddrCopy, destAddr)
37 | srcAddr := ParseUDPAddr(ipAddrNTOA(addrCopy), uint16(port))
38 | dstAddr := ParseUDPAddr(ipAddrNTOA(destAddrCopy), uint16(destPort))
39 | if srcAddr == nil || dstAddr == nil {
40 | panic("invalid UDP address")
41 | }
42 |
43 | connId := udpConnId{
44 | src: srcAddr.String(),
45 | }
46 | conn, found := udpConns.Load(connId)
47 | if !found {
48 | if udpConnHandler == nil {
49 | panic("must register a UDP connection handler")
50 | }
51 | var err error
52 | conn, err = newUDPConn(pcb,
53 | udpConnHandler,
54 | addrCopy,
55 | port,
56 | srcAddr,
57 | dstAddr)
58 | if err != nil {
59 | return
60 | }
61 | udpConns.Store(connId, conn)
62 | }
63 |
64 | var buf []byte
65 | var totlen = int(p.tot_len)
66 | if p.tot_len == p.len {
67 | buf = (*[1 << 30]byte)(unsafe.Pointer(p.payload))[:totlen:totlen]
68 | } else {
69 | buf = pool.NewBytes(totlen)
70 | defer pool.FreeBytes(buf)
71 | C.pbuf_copy_partial(p, unsafe.Pointer(&buf[0]), p.tot_len, 0)
72 | }
73 |
74 | conn.(UDPConn).ReceiveTo(buf[:totlen], dstAddr)
75 | }
76 |
--------------------------------------------------------------------------------
/core/udp_conn_map.go:
--------------------------------------------------------------------------------
1 | package core
2 |
3 | import (
4 | "sync"
5 | )
6 |
7 | var udpConns sync.Map
8 |
9 | type udpConnId struct {
10 | src string
11 | }
12 |
--------------------------------------------------------------------------------
/filter/filter.go:
--------------------------------------------------------------------------------
1 | package filter
2 |
3 | import (
4 | "io"
5 | )
6 |
7 | // Filter is used for filtering IP packets comming from TUN.
8 | type Filter interface {
9 | io.Writer
10 | }
11 |
--------------------------------------------------------------------------------
/filter/icmp.go:
--------------------------------------------------------------------------------
1 | package filter
2 |
3 | import (
4 | "io"
5 | "time"
6 |
7 | "github.com/eycorsican/go-tun2socks/common/log"
8 | "github.com/eycorsican/go-tun2socks/common/packet"
9 | )
10 |
11 | type icmpFilter struct {
12 | writer io.Writer
13 | delay int
14 | }
15 |
16 | func NewICMPFilter(w io.Writer, delay int) Filter {
17 | return &icmpFilter{writer: w, delay: delay}
18 | }
19 |
20 | func (w *icmpFilter) Write(buf []byte) (int, error) {
21 | if uint8(buf[9]) == packet.PROTOCOL_ICMP {
22 | payload := make([]byte, len(buf))
23 | copy(payload, buf)
24 | go func(data []byte) {
25 | time.Sleep(time.Duration(w.delay) * time.Millisecond)
26 | _, err := w.writer.Write(data)
27 | if err != nil {
28 | log.Fatalf("failed to input data to the stack: %v", err)
29 | }
30 | }(payload)
31 | return len(buf), nil
32 | } else {
33 | return w.writer.Write(buf)
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/trojan-gfw/go-tun2socks
2 |
3 | go 1.14
4 |
--------------------------------------------------------------------------------
/proxy/echo/tcp.go:
--------------------------------------------------------------------------------
1 | package echo
2 |
3 | import (
4 | "io"
5 | "net"
6 |
7 | "github.com/eycorsican/go-tun2socks/core"
8 | )
9 |
10 | // An echo proxy, do nothing but echo back data to the sender, the handler was
11 | // created for testing purposes, it may causes issues when more than one clients
12 | // are connecting the handler simultaneously.
13 | type tcpHandler struct{}
14 |
15 | func NewTCPHandler() core.TCPConnHandler {
16 | return &tcpHandler{}
17 | }
18 |
19 | func (h *tcpHandler) echoBack(conn net.Conn) {
20 | io.Copy(conn, conn)
21 | }
22 |
23 | func (h *tcpHandler) Handle(conn net.Conn, target *net.TCPAddr) error {
24 | go h.echoBack(conn)
25 | return nil
26 | }
27 |
--------------------------------------------------------------------------------
/proxy/echo/udp.go:
--------------------------------------------------------------------------------
1 | package echo
2 |
3 | import (
4 | "net"
5 |
6 | "github.com/eycorsican/go-tun2socks/common/log"
7 | "github.com/eycorsican/go-tun2socks/core"
8 | )
9 |
10 | // An echo server, do nothing but echo back data to the sender.
11 | type udpHandler struct{}
12 |
13 | func NewUDPHandler() core.UDPConnHandler {
14 | return &udpHandler{}
15 | }
16 |
17 | func (h *udpHandler) Connect(conn core.UDPConn, target *net.UDPAddr) error {
18 | return nil
19 | }
20 |
21 | func (h *udpHandler) ReceiveTo(conn core.UDPConn, data []byte, addr *net.UDPAddr) error {
22 | // Dispatch to another goroutine, otherwise will result in deadlock.
23 | payload := append([]byte(nil), data...)
24 | go func(b []byte) {
25 | _, err := conn.WriteFrom(b, addr)
26 | if err != nil {
27 | log.Warnf("failed to echo back data: %v", err)
28 | }
29 | }(payload)
30 | return nil
31 | }
32 |
--------------------------------------------------------------------------------
/proxy/socks/tcp.go:
--------------------------------------------------------------------------------
1 | package socks
2 |
3 | import (
4 | "io"
5 | "net"
6 | "strconv"
7 | "sync"
8 |
9 | "golang.org/x/net/proxy"
10 |
11 | "github.com/eycorsican/go-tun2socks/common/dns"
12 | "github.com/eycorsican/go-tun2socks/common/log"
13 | "github.com/eycorsican/go-tun2socks/component/pool"
14 | "github.com/eycorsican/go-tun2socks/core"
15 | )
16 |
17 | type tcpHandler struct {
18 | sync.Mutex
19 |
20 | proxyHost string
21 | proxyPort uint16
22 |
23 | fakeDns dns.FakeDns
24 | }
25 |
26 | func NewTCPHandler(proxyHost string, proxyPort uint16, fakeDns dns.FakeDns) core.TCPConnHandler {
27 | return &tcpHandler{
28 | proxyHost: proxyHost,
29 | proxyPort: proxyPort,
30 | fakeDns: fakeDns,
31 | }
32 | }
33 |
34 | type direction byte
35 |
36 | const (
37 | dirUplink direction = iota
38 | dirDownlink
39 | )
40 |
41 | type duplexConn interface {
42 | net.Conn
43 | CloseRead() error
44 | CloseWrite() error
45 | }
46 |
47 | func relayClose(src, dst net.Conn, closeErr error, closeOnce *sync.Once) {
48 | // interrupt the conn if the error is not nil (not EOF)
49 | // half close uplink direction of the TCP conn if possible
50 | if closeErr != nil {
51 | closeOnce.Do(func() {
52 | src.Close()
53 | dst.Close()
54 | })
55 | return
56 | }
57 |
58 | srcDConn, srcOk := src.(duplexConn)
59 | dstDConn, dstOk := dst.(duplexConn)
60 | if srcOk && dstOk {
61 | srcDConn.CloseRead()
62 | dstDConn.CloseWrite()
63 | }
64 | }
65 |
66 | func relayGenerator(h *tcpHandler, src, dst net.Conn, dir direction, closeOnce *sync.Once) chan bool {
67 | stopSig := make(chan bool)
68 | go func(src, dst net.Conn, dir direction, stopChan chan bool) {
69 | var err error
70 | buf := pool.NewBytes(pool.BufSize)
71 | defer pool.FreeBytes(buf)
72 | _, err = io.CopyBuffer(dst, src, buf)
73 | relayClose(src, dst, err, closeOnce)
74 | close(stopChan) // send uplink finished signal
75 | }(src, dst, dir, stopSig)
76 | return stopSig
77 | }
78 |
79 | func (h *tcpHandler) relay(lhs, rhs net.Conn) {
80 | // both uplink and downlink use the same sync.Once instance
81 | var closeOnce sync.Once
82 | uplinkSig := relayGenerator(h, lhs, rhs, dirUplink, &closeOnce)
83 | downlinkSig := relayGenerator(h, rhs, lhs, dirDownlink, &closeOnce)
84 |
85 | <-uplinkSig
86 | <-downlinkSig
87 | }
88 |
89 | func (h *tcpHandler) Handle(conn net.Conn, target *net.TCPAddr) error {
90 | dialer, err := proxy.SOCKS5("tcp", core.ParseTCPAddr(h.proxyHost, h.proxyPort).String(), nil, nil)
91 | if err != nil {
92 | return err
93 | }
94 |
95 | // Replace with a domain name if target address IP is a fake IP.
96 | var targetHost string
97 | if h.fakeDns != nil && h.fakeDns.IsFakeIP(target.IP) {
98 | targetHost = h.fakeDns.QueryDomain(target.IP)
99 | } else {
100 | targetHost = target.IP.String()
101 | }
102 | dest := net.JoinHostPort(targetHost, strconv.Itoa(target.Port))
103 |
104 | c, err := dialer.Dial(target.Network(), dest)
105 | if err != nil {
106 | return err
107 | }
108 |
109 | var process string = "N/A"
110 |
111 | // Set keepalive
112 | tcpKeepAlive(conn)
113 | tcpKeepAlive(c)
114 |
115 | go h.relay(conn, c)
116 |
117 | log.Access(process, "proxy", target.Network(), conn.LocalAddr().String(), dest)
118 |
119 | return nil
120 | }
121 |
--------------------------------------------------------------------------------
/proxy/socks/utils.go:
--------------------------------------------------------------------------------
1 | package socks
2 |
3 | import (
4 | "net"
5 | "time"
6 | )
7 |
8 | func tcpKeepAlive(conn net.Conn) {
9 | if tcp, ok := conn.(*net.TCPConn); ok {
10 | tcp.SetKeepAlive(true)
11 | tcp.SetKeepAlivePeriod(30 * time.Second)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------