diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..e69de29
diff --git a/Kwazii/Assets.xcassets/AppIcon.appiconset/Contents.json b/Kwazii/Assets.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000..d84b3b4
--- /dev/null
+++ b/Kwazii/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,64 @@
+{
+ "images" : [
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "2x"
+ },
+ {
+ "size" : "128x128",
+ "idiom" : "mac",
+ "filename" : "icon128-1.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "128x128",
+ "idiom" : "mac",
+ "filename" : "icon256-1.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "256x256",
+ "idiom" : "mac",
+ "filename" : "icon256.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "256x256",
+ "idiom" : "mac",
+ "filename" : "icon512-1.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "512x512",
+ "idiom" : "mac",
+ "filename" : "icon512.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "512x512",
+ "idiom" : "mac",
+ "filename" : "icon@1x.png",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+}
\ No newline at end of file
diff --git a/Kwazii/Assets.xcassets/AppIcon.appiconset/icon128-1.png b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon128-1.png
new file mode 100644
index 0000000..2dffa44
Binary files /dev/null and b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon128-1.png differ
diff --git a/Kwazii/Assets.xcassets/AppIcon.appiconset/icon256-1.png b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon256-1.png
new file mode 100644
index 0000000..7efd82e
Binary files /dev/null and b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon256-1.png differ
diff --git a/Kwazii/Assets.xcassets/AppIcon.appiconset/icon256.png b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon256.png
new file mode 100644
index 0000000..7efd82e
Binary files /dev/null and b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon256.png differ
diff --git a/Kwazii/Assets.xcassets/AppIcon.appiconset/icon512-1.png b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon512-1.png
new file mode 100644
index 0000000..8c07490
Binary files /dev/null and b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon512-1.png differ
diff --git a/Kwazii/Assets.xcassets/AppIcon.appiconset/icon512.png b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon512.png
new file mode 100644
index 0000000..8c07490
Binary files /dev/null and b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon512.png differ
diff --git a/Kwazii/Assets.xcassets/AppIcon.appiconset/icon@1x.png b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon@1x.png
new file mode 100644
index 0000000..e1f5b92
Binary files /dev/null and b/Kwazii/Assets.xcassets/AppIcon.appiconset/icon@1x.png differ
diff --git a/Kwazii/Assets.xcassets/Contents.json b/Kwazii/Assets.xcassets/Contents.json
new file mode 100644
index 0000000..da4a164
--- /dev/null
+++ b/Kwazii/Assets.xcassets/Contents.json
@@ -0,0 +1,6 @@
+{
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+}
\ No newline at end of file
diff --git a/Kwazii/Assets.xcassets/Proxy.imageset/Contents.json b/Kwazii/Assets.xcassets/Proxy.imageset/Contents.json
new file mode 100644
index 0000000..c4769dd
--- /dev/null
+++ b/Kwazii/Assets.xcassets/Proxy.imageset/Contents.json
@@ -0,0 +1,21 @@
+{
+ "images" : [
+ {
+ "idiom" : "universal",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "universal",
+ "filename" : "Proxy@2x.png",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "universal",
+ "scale" : "3x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+}
\ No newline at end of file
diff --git a/Kwazii/Assets.xcassets/Proxy.imageset/Proxy@2x.png b/Kwazii/Assets.xcassets/Proxy.imageset/Proxy@2x.png
new file mode 100644
index 0000000..5208fbe
Binary files /dev/null and b/Kwazii/Assets.xcassets/Proxy.imageset/Proxy@2x.png differ
diff --git a/Kwazii/Base.lproj/Main.storyboard b/Kwazii/Base.lproj/Main.storyboard
new file mode 100644
index 0000000..e3b85c8
--- /dev/null
+++ b/Kwazii/Base.lproj/Main.storyboard
@@ -0,0 +1,399 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Kwazii/HelpWindow.xib b/Kwazii/HelpWindow.xib
new file mode 100644
index 0000000..de2ae5a
--- /dev/null
+++ b/Kwazii/HelpWindow.xib
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Kwazii/HelpWindowController.swift b/Kwazii/HelpWindowController.swift
new file mode 100644
index 0000000..d8a51ce
--- /dev/null
+++ b/Kwazii/HelpWindowController.swift
@@ -0,0 +1,20 @@
+//
+// HelpWindowController.swift
+// Kwazii
+//
+// Created by abigt on 2018/1/18.
+// Copyright © 2018年 A.BIG.T. All rights reserved.
+//
+
+import Cocoa
+
+class HelpWindowController: NSWindowController {
+
+ @IBOutlet weak var textView: NSTextView!
+ override func windowDidLoad() {
+ super.windowDidLoad()
+ //self.textView.textStorage?.string = "test"
+ // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
+ }
+
+}
diff --git a/Kwazii/Info.plist b/Kwazii/Info.plist
new file mode 100644
index 0000000..a27446e
--- /dev/null
+++ b/Kwazii/Info.plist
@@ -0,0 +1,48 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ $(DEVELOPMENT_LANGUAGE)
+ CFBundleExecutable
+ $(EXECUTABLE_NAME)
+ CFBundleIconFile
+ AppIcon.icons
+ CFBundleIdentifier
+ $(PRODUCT_BUNDLE_IDENTIFIER)
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ $(PRODUCT_NAME)
+ CFBundlePackageType
+ APPL
+ CFBundleShortVersionString
+ 1.0
+ CFBundleVersion
+ 6
+ Fabric
+
+ APIKey
+
+ Kits
+
+
+ KitInfo
+
+ KitName
+ Crashlytics
+
+
+
+ LSMinimumSystemVersion
+ $(MACOSX_DEPLOYMENT_TARGET)
+ NSHumanReadableCopyright
+ Copyright © 2018年 A.BIG.T. All rights reserved.
+ NSMainStoryboardFile
+ Main
+ NSPrincipalClass
+ NSApplication
+ SUFeedURL
+ https://abigt.net/appupdate.xml
+
+
diff --git a/Kwazii/Kwazii.entitlements b/Kwazii/Kwazii.entitlements
new file mode 100644
index 0000000..19ba818
--- /dev/null
+++ b/Kwazii/Kwazii.entitlements
@@ -0,0 +1,10 @@
+
+
+
+
+ com.apple.security.application-groups
+
+ 745WQDK4L7.com.abigt.Surf
+
+
+
diff --git a/Kwazii/KwaziiAppDelegate.swift b/Kwazii/KwaziiAppDelegate.swift
new file mode 100644
index 0000000..c412fa0
--- /dev/null
+++ b/Kwazii/KwaziiAppDelegate.swift
@@ -0,0 +1,198 @@
+//
+// AppDelegate.swift
+// Kwazii
+//
+// Created by abigt on 2018/1/17.
+// Copyright © 2018年 A.BIG.T. All rights reserved.
+//
+
+import Cocoa
+let appgroup = "745WQDK4L7.com.abigt.Surf"
+import XRuler
+import Xcon
+import Sparkle
+import Fabric
+import Crashlytics
+@NSApplicationMain
+class KwaziiAppDelegate: NSObject, NSApplicationDelegate,NSMenuDelegate {
+
+ var configWindow:PreferencesWindowController!
+ var helpWindow:HelpWindowController!
+ var updateWindows:UpdateWindowController!
+ var serversMenuItem:NSMenu!
+ @IBAction func addProxy(_ sender:Any){
+ if configWindow == nil {
+ configWindow = PreferencesWindowController(windowNibName: NSNib.Name(rawValue: "PreferencesWindowController"))
+ }
+ configWindow.showWindow(self)
+ NSApp.activate(ignoringOtherApps: true)
+ configWindow.window?.makeKeyAndOrderFront(self)
+ }
+
+ @IBAction func openHelp(_ sender: Any) {
+ if helpWindow == nil {
+ helpWindow = HelpWindowController(windowNibName: NSNib.Name(rawValue: "HelpWindow"))
+ }
+ helpWindow.showWindow(self)
+ NSApp.activate(ignoringOtherApps: true)
+ helpWindow.window?.makeKeyAndOrderFront(self)
+ }
+ func applicationDidFinishLaunching(_ aNotification: Notification) {
+ Fabric.with([Crashlytics.self])
+
+ // Fabric.with([Answers.self])
+ Answers.logCustomEvent(withName: "Kwazii",
+ customAttributes: [
+ "Started": "",
+
+ ])
+ // Insert code here to initialize your application
+ var url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appgroup)!
+
+ if !FileManager.default.fileExists(atPath: url.path){
+ try! FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
+
+ }else {
+ print("exist \(url)")
+ }
+
+
+ url.appendPathComponent("abigt.conf")
+ if !FileManager.default.fileExists(atPath: url.path){
+ let p = Bundle.main.path(forResource: "abigt.conf", ofType: nil)
+ try! FileManager.default.copyItem(at: URL.init(fileURLWithPath: p!), to: url)
+ }else {
+ print("\(url)")
+ }
+ XRuler.groupIdentifier = appgroup
+ SFSettingModule.setting.config(url.path)
+ }
+
+ func applicationWillTerminate(_ aNotification: Notification) {
+ // Insert code here to tear down your application
+ }
+
+
+ func menuNeedsUpdate(_ menu: NSMenu){
+ if serversMenuItem == nil{
+ serversMenuItem = menu
+ }
+ self.updateServersMenu(true)
+ }
+
+
+ func updateServersMenu(_ update:Bool) {
+
+
+
+ guard let menu = serversMenuItem else {return}
+ menu.removeAllItems()
+ var index = 0
+ let profile = ProxyGroupSettings.share
+ for p in profile.proxys {
+ var title = ""
+ if profile.showCountry {
+
+ if !p.serverIP.isEmpty{
+ let rusult = Country.setting.geoIPRule(ipString: p.serverIP)
+
+ p.countryFlag = rusult.emoji
+ p.isoCode = rusult.isoCode
+ title += p.countryFlag
+ }else {
+ hostToIP(proxy: p)
+ }
+
+
+ }
+ if p.proxyName.isEmpty {
+ title += p.serverAddress + ":" + p.serverPort
+
+ }else {
+ title += p.proxyName + "(" + p.serverAddress + ":" + p.serverPort + ")"
+ }
+ let em = NSMenuItem(title: title, action: #selector(KwaziiAppDelegate.selectServer(_:)), keyEquivalent: "")
+ em.tag = index
+ if ProxyGroupSettings.share.selectIndex == index {
+ em.state = NSControl.StateValue(rawValue: 1)
+
+ }else {
+ em.state = NSControl.StateValue(rawValue: 0)
+ }
+ index += 1
+ menu.addItem(em)
+ }
+ menu.addItem(NSMenuItem.separator())
+ // menu.addItem(withTitle: "Open Server Preferences ...", action: #selector(AppDelegate.openProxySConfig(_:)), keyEquivalent: "c")
+ }
+ @objc func selectServer(_ sender:NSMenuItem){
+ let index = sender.tag
+ print("-----\(sender.tag)")
+ ProxyGroupSettings.share.selectIndex = index
+
+ }
+ func hostToIP(proxy:SFProxy) {
+ dnsqueue.async(execute:{ [weak self ] in
+ guard let strong = self else {return}
+
+ guard let hostInfo = gethostbyname2((proxy.serverAddress as NSString).utf8String, AF_INET)else {
+ return
+ }
+
+
+
+
+ let len = hostInfo.pointee.h_length
+ let aa = hostInfo.pointee.h_addr_list[0]
+ var ip = ""
+
+ for i in 0 ..< len {
+ let x = (aa! + Int(i)).pointee
+ if i == (len - 1) {
+ ip += "\(strong.toUint(signed: x))"
+ break
+ }
+ ip += "\(strong.toUint(signed: x))."
+
+ }
+ proxy.serverIP = ip
+ DispatchQueue.main.async(execute: {
+ self!.updateServersMenu(false)
+ })
+
+ })
+
+
+ //return ip
+ }
+ func toUint(signed: Int8) -> UInt8 {
+
+ let unsigned = signed >= 0 ?
+ UInt8(signed) :
+ UInt8(signed - Int8.min) + UInt8(Int8.max) + 1
+
+ return unsigned
+ }
+ let dnsqueue:DispatchQueue = DispatchQueue(label:"com.abigt.dns")
+ @IBAction func openRule(_ sender:Any){
+ let url = fm.containerURL(forSecurityApplicationGroupIdentifier: groupIdentifier)!.appendingPathComponent("abigt.conf")
+
+ NSWorkspace.shared.open(url)
+ }
+ @IBAction func openCheckUpdate(_ sender:Any){
+ if updateWindows == nil {
+ updateWindows = UpdateWindowController(windowNibName: NSNib.Name(rawValue: "SUUpdateSettingsWindowController"))
+ }
+ updateWindows.showWindow(self)
+ NSApp.activate(ignoringOtherApps: true)
+ updateWindows.window?.makeKeyAndOrderFront(self)
+ }
+ var updater: SUUpdater!
+ @IBAction func checkUpdate(_ sender:Any){
+ if updater == nil {
+ updater = SUUpdater()
+ }
+ updater.checkForUpdates(nil)
+ }
+}
+
diff --git a/Kwazii/MainWindow.swift b/Kwazii/MainWindow.swift
new file mode 100644
index 0000000..1e7840e
--- /dev/null
+++ b/Kwazii/MainWindow.swift
@@ -0,0 +1,38 @@
+//
+// MainWindow.swift
+// Kwazii
+//
+// Created by abigt on 2018/1/17.
+// Copyright © 2018年 A.BIG.T. All rights reserved.
+//
+
+import Cocoa
+
+class MainWindow: NSWindowController {
+
+ override func windowDidLoad() {
+ super.windowDidLoad()
+
+ //window?.titleVisibility = .hidden
+ //window?.titlebarAppearsTransparent = true
+
+ // window?.styleMask.insert(.fullSizeContentView)
+ //disable close
+ window?.styleMask.remove(.closable)
+ //window?.styleMask.remove(.fullScreen)
+ //window?.styleMask.remove(.miniaturizable)
+ //window?.styleMask.remove(.resizable)
+ //NSWindow.StyleMask(rawValue: NSWindow.StyleMask.RawValue(~(UInt8(NSClosableWindowMask.rawValue) | UInt8(NSMiniaturizableWindowMask.rawValue) | UInt8(NSResizableWindowMask.rawValue))))
+// let st = NSStoryboard.init(name: NSStoryboard.Name(rawValue: "RequestBasic"), bundle:nil)
+// let vc = self.storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "request")) as! RequestsVC
+// //let vc = st.instantiateInitialController() as! RequestsVC
+// self.window!.contentView?.addSubview(vc.view)
+ // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
+ }
+ @IBAction func addProxy(_ sender:Any){
+
+ }
+ @IBAction func cancel(_ sender: NSButton) {
+ //window?.performClose(self)
+ }
+}
diff --git a/Kwazii/RequestBasic.storyboard b/Kwazii/RequestBasic.storyboard
new file mode 100644
index 0000000..845b2de
--- /dev/null
+++ b/Kwazii/RequestBasic.storyboard
@@ -0,0 +1,438 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Kwazii/RequestDetailView.swift b/Kwazii/RequestDetailView.swift
new file mode 100644
index 0000000..73e6483
--- /dev/null
+++ b/Kwazii/RequestDetailView.swift
@@ -0,0 +1,24 @@
+//
+// RequestDetailView.swift
+// Kwazii
+//
+// Created by abigt on 2018/1/18.
+// Copyright © 2018年 A.BIG.T. All rights reserved.
+//
+
+import Cocoa
+import Xcon
+import XProxy
+class RequestDetailView: NSView {
+
+ var request:SFRequestInfo!
+ required init?(coder decoder: NSCoder) {
+ super.init(coder: decoder)
+ }
+ override func draw(_ dirtyRect: NSRect) {
+ super.draw(dirtyRect)
+
+ // Drawing code here.
+ }
+
+}
diff --git a/Kwazii/RequestTabVC.swift b/Kwazii/RequestTabVC.swift
new file mode 100644
index 0000000..3625c2c
--- /dev/null
+++ b/Kwazii/RequestTabVC.swift
@@ -0,0 +1,18 @@
+//
+// RequestTabVC.swift
+// Kwazii
+//
+// Created by abigt on 2018/1/18.
+// Copyright © 2018年 A.BIG.T. All rights reserved.
+//
+
+import Cocoa
+
+class RequestTabVC: NSTabViewController {
+
+ override func viewDidLoad() {
+ super.viewDidLoad()
+ // Do view setup here.
+ }
+
+}
diff --git a/Kwazii/RequestsVC.swift b/Kwazii/RequestsVC.swift
new file mode 100644
index 0000000..18a0842
--- /dev/null
+++ b/Kwazii/RequestsVC.swift
@@ -0,0 +1,59 @@
+//
+// RequestsVC.swift
+// Kwazii
+//
+// Created by abigt on 2018/1/17.
+// Copyright © 2018年 A.BIG.T. All rights reserved.
+//
+
+import Cocoa
+import XDataService
+import SFSocket
+import AxLogger
+import XRuler
+import XProxy
+final class RequestsVC: RequestsBasic {
+ @IBOutlet weak var detail:NSView!
+ let report:SFVPNStatistics = SFVPNStatistics.shared
+ var refreshTime = DispatchSource.makeTimerSource(flags: DispatchSource.TimerFlags(rawValue: 0), queue: DispatchQueue.main)
+ func startProxy(){
+ SKit.startGCDProxy(port: 10081, dispatchQueue: DispatchQueue.init(label: "Kwazii.dispatch"), socketQueue: DispatchQueue.init(label: "Kwazii.dispatch.socket"))
+ }
+
+ public override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
+ print("load....")
+ super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
+ }
+ override func loadView() {
+ super.loadView()
+ }
+ func installTimer(){
+ refreshTime.schedule(deadline: .now(), repeating: DispatchTimeInterval.seconds(1), leeway: DispatchTimeInterval.seconds(1))
+ refreshTime.setEventHandler {
+ [weak self] in
+ let data = SFTCPConnectionManager.shared.recentRequestData()
+ self?.processData(data: data)
+ //self?.reportTask()
+
+ }
+ refreshTime.setCancelHandler {
+ print("timer cancel......")
+ }
+ refreshTime.resume()
+ }
+ @objc required public init?(coder aDecoder: NSCoder) {
+ super.init(coder: aDecoder)
+ startProxy()
+ print("load coder....")
+ installTimer()
+ }
+
+ override func viewDidLoad() {
+ tableView.delegate = self
+ tableView.dataSource = self
+ super.viewDidLoad()
+
+ // Do view setup here.
+ }
+
+}
diff --git a/Kwazii/SUUpdateSettingsWindowController.xib b/Kwazii/SUUpdateSettingsWindowController.xib
new file mode 100644
index 0000000..ad902db
--- /dev/null
+++ b/Kwazii/SUUpdateSettingsWindowController.xib
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Kwazii/UpdateWindowController.swift b/Kwazii/UpdateWindowController.swift
new file mode 100644
index 0000000..7e260c1
--- /dev/null
+++ b/Kwazii/UpdateWindowController.swift
@@ -0,0 +1,20 @@
+//
+// UpdateWindowController.swift
+// Kwazii
+//
+// Created by abigt on 2018/1/19.
+// Copyright © 2018年 A.BIG.T. All rights reserved.
+//
+
+import Cocoa
+import Sparkle
+class UpdateWindowController: NSWindowController {
+
+ @IBOutlet var updater: SUUpdater!
+ override func windowDidLoad() {
+ super.windowDidLoad()
+
+ // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
+ }
+
+}
diff --git a/Kwazii/ViewController.swift b/Kwazii/ViewController.swift
new file mode 100644
index 0000000..15e139f
--- /dev/null
+++ b/Kwazii/ViewController.swift
@@ -0,0 +1,27 @@
+//
+// ViewController.swift
+// Kwazii
+//
+// Created by abigt on 2018/1/17.
+// Copyright © 2018年 A.BIG.T. All rights reserved.
+//
+
+import Cocoa
+
+class ViewController: NSViewController {
+
+ override func viewDidLoad() {
+ super.viewDidLoad()
+
+ // Do any additional setup after loading the view.
+ }
+
+ override var representedObject: Any? {
+ didSet {
+ // Update the view, if already loaded.
+ }
+ }
+
+
+}
+
diff --git a/Kwazii/abigt.conf b/Kwazii/abigt.conf
new file mode 100644
index 0000000..4ecaaae
--- /dev/null
+++ b/Kwazii/abigt.conf
@@ -0,0 +1,807 @@
+[General]
+skip-proxy = 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 127.0.0.0/8,100.64.0.0/10, localhost, *.local, e.crashlytics.com
+bypass-tun = 192.168.0.0/16,10.0.0.0/8, 172.16.0.0/12,169.254.0.0/16,,119.29.29.29/32,223.6.6.6/32, 223.5.5.5/32
+
+dns-server = system
+loglevel = debug
+
+[Rule]
+
+
+DOMAIN-SUFFIX,appldnld.apple.com,DIRECT
+DOMAIN-SUFFIX,mesu.apple.com,DIRECT
+
+#USER-AGENT,CriOS,Proxy
+USER-AGENT,ph.telegra.Telegraph,Proxy
+
+DOMAIN,beta.itunes.apple.com,Proxy
+DOMAIN,init.itunes.apple.com,DIRECT
+DOMAIN,audio.itunes.apple.com,DIRECT
+DOMAIN,iosapps.itunes.apple.com,DIRECT
+DOMAIN,play.itunes.apple.com,DIRECT
+DOMAIN,aod.itune.apple.com,DIRECT
+DOMAIN,126.net,DIRECT
+# Apple PACKAGE DIRECT
+DOMAIN-SUFFIX,appldnld.apple.com,DIRECT
+DOMAIN-SUFFIX,adcdownload.apple.com,DIRECT
+DOMAIN-SUFFIX,lcdn-registration.apple.com,DIRECT
+DOMAIN-SUFFIX,swcdn.apple.com,DIRECT
+DOMAIN-SUFFIX,phobos.apple.com,DIRECT
+DOMAIN-SUFFIX,ls.apple.com,DIRECT
+DOMAIN-SUFFIX,cdn-apple.com,DIRECT
+DOMAIN-SUFFIX,gstatic.com,Proxy
+DOMAIN,g.co,Proxy
+# Apple PACKAGE PROXY-B
+# 建议直连,较高要求可以改变连接方式
+DOMAIN-SUFFIX,icloud.com,DIRECT
+DOMAIN-SUFFIX,me.com,DIRECT
+DOMAIN-SUFFIX,apple.com,DIRECT
+DOMAIN-SUFFIX,itunes.apple.com,DIRECT
+DOMAIN-SUFFIX,mzstatic.com,DIRECT
+
+
+DOMAIN,github.com,Proxy
+DOMAIN,golang.org,Proxy
+# SpeedTest
+DOMAIN,ads.ookla.com,REJECT
+DOMAIN,cdn.ads.ookla.com,REJECT
+
+# App Laugh Skin
+DOMAIN,u1.img.mobile.sina.cn,REJECT
+
+# Qiushibaike
+DOMAIN,mi.gdt.qq.com,REJECT
+
+# Sina
+DOMAIN,sax.sina.cn,REJECT
+
+# Xunfei
+DOMAIN,bj.imp.voiceads.cn,REJECT
+
+# Systemav
+DOMAIN,m.madthumbs.com,REJECT
+
+# Google
+DOMAIN,csi.gstatic.com,REJECT
+DOMAIN,static.googleadsserving.cn,REJECT
+DOMAIN,ads.google.com,REJECT
+DOMAIN,account.google.com,Proxy
+DOMAIN,afd.l.google.com,REJECT
+DOMAIN,mobileads.google.com,REJECT
+DOMAIN,pagead-tpc.l.google.com,REJECT
+DOMAIN,pagead.google.com,REJECT
+DOMAIN,pagead.l.google.com,REJECT
+DOMAIN,partnerad.l.google.com,REJECT
+DOMAIN,ads.youtube.com,REJECT
+DOMAIN,ads.gmodules.com,REJECT
+DOMAIN,badad.googleplex.com,REJECT
+DOMAIN,www.googlecommerce.com,REJECT
+DOMAIN,www.googletagmanager.com,REJECT
+DOMAIN,service.urchin.com,REJECT
+
+# AutoHome
+DOMAIN,adm3.autoimg.cn,REJECT
+DOMAIN,adm0.autoimg.cn,REJECT
+DOMAIN,img2.autoimg.cn,REJECT
+
+# Dropbox
+DOMAIN,d.dropbox.com,REJECT
+DOMAIN,dl-debug.dropbox.com,REJECT
+
+# Twitter
+DOMAIN,syndication.twitter.com,REJECT
+DOMAIN-SUFFIX,twitter.com,Proxy
+# DSP
+DOMAIN,dsp.lomark.cn,REJECT
+
+# VIU By
+DOMAIN,stream-hk.viu.com,Proxy
+DOMAIN,global.adserver.yahoo.com,REJECT
+
+
+# CDN
+DOMAIN,init.icloud-analysis.com, REJECT
+DOMAIN,zhihu-analytics.zhihu.com,REJECT
+DOMAIN,log.cmbchina.com,REJECT
+DOMAIN,api.segment.io,REJECT
+DOMAIN,api.instabug.com,REJECT
+DOMAIN,adlog.flurry.com,REJECT
+DOMAIN,ads.flurry.com,REJECT
+
+
+
+DOMAIN,r1.ykimg.com,REJECT
+DOMAIN,v.gdt.qq.com,REJECT
+DOMAIN,sd.domob.cn,REJECT
+
+
+
+
+
+
+
+
+
+# Taobao
+DOMAIN,h5.m.taobao.com,DIRECT
+
+# Duolinguo
+DOMAIN,api.mixpanel.com,DIRECT
+DOMAIN,d2pur3iezf4d1j.cloudfront.net,DIRECT
+
+DOMAIN,wscdns.com,DIRECT
+
+# Synology
+DOMAIN-SUFFIX,QuickConnect.to,DIRECT
+
+# Alipay
+DOMAIN-SUFFIX,alipaylog.com,DIRECT
+
+# Taobao
+DOMAIN-SUFFIX,taobaocdn.com,DIRECT
+DOMAIN-SUFFIX,alicdn.com,DIRECT
+
+# 12306
+DOMAIN-SUFFIX,12306.cn,DIRECT
+
+# 17APP
+DOMAIN-SUFFIX,17app.co,DIRECT
+
+# 126
+DOMAIN-SUFFIX,126.net,DIRECT
+DOMAIN-SUFFIX,163.com,DIRECT
+DOMAIN-SUFFIX,netnease.com,DIRECT
+
+# 360buy
+DOMAIN-SUFFIX,360buyimg.com,DIRECT
+#DOMAIN-SUFFIX,jd.com,DIRECT
+
+# ICBC
+DOMAIN-SUFFIX,icbc.com,DIRECT
+
+# 10010 By ސސސސސސސސސސ
+DOMAIN-SUFFIX,6-10010.com,DIRECT
+
+
+# iMuzo
+DOMAIN-SUFFIX,iheart.com,DIRECT
+DOMAIN-SUFFIX,dongting.com,DIRECT
+DOMAIN-SUFFIX,iyyin.com,DIRECT
+DOMAIN-SUFFIX,openspeech.cn,DIRECT
+
+
+# CDN
+DOMAIN-SUFFIX,yunjiasu-cdn.net,DIRECT
+DOMAIN-SUFFIX,8686c.com,DIRECT
+DOMAIN-SUFFIX,ourdvs.com,DIRECT
+DOMAIN-SUFFIX,spotilocal.com,DIRECT
+
+# CN DIRECT
+DOMAIN-SUFFIX,cn,DIRECT
+
+# CHINA WHITE LIST
+DOMAIN-SUFFIX,com.cn,DIRECT
+DOMAIN-SUFFIX,edu.cn,DIRECT
+DOMAIN-SUFFIX,org.cn,DIRECT
+DOMAIN-SUFFIX,net.cn,DIRECT
+DOMAIN-SUFFIX,gov.cn,DIRECT
+DOMAIN-SUFFIX,weibo.cn,DIRECT
+DOMAIN-SUFFIX,sina.cn,DIRECT
+DOMAIN-SUFFIX,tbcdn.cn,DIRECT
+DOMAIN-SUFFIX,sinajs.cn,DIRECT
+DOMAIN-SUFFIX,amazon.cn,DIRECT
+DOMAIN-SUFFIX,360.cn,DIRECT
+DOMAIN-SUFFIX,flyme.cn,DIRECT
+DOMAIN-SUFFIX,mtime.cn,DIRECT
+DOMAIN-SUFFIX,ifanr.cn,DIRECT
+DOMAIN-SUFFIX,kuwo.cn,DIRECT
+DOMAIN-SUFFIX,kuaipan.cn,DIRECT
+DOMAIN-SUFFIX,3g.cn,DIRECT
+DOMAIN-SUFFIX,tianya.cn,DIRECT
+DOMAIN-SUFFIX,url.cn,DIRECT
+DOMAIN-SUFFIX,blued.cn,DIRECT
+DOMAIN-SUFFIX,189.cn,DIRECT
+DOMAIN-SUFFIX,10086.cn,DIRECT
+DOMAIN-SUFFIX,10010.cn,DIRECT
+DOMAIN-SUFFIX,uc.cn,DIRECT
+DOMAIN-SUFFIX,damai.cn,DIRECT
+DOMAIN-SUFFIX,suning.cn,DIRECT
+DOMAIN-SUFFIX,liebao.cn,DIRECT
+DOMAIN-SUFFIX,mifile.cn,DIRECT
+DOMAIN-SUFFIX,voicecloud.cn,DIRECT
+DOMAIN-SUFFIX,wps.cn,DIRECT
+DOMAIN-SUFFIX,8684.cn,DIRECT
+DOMAIN-SUFFIX,uniqlo.cn,DIRECT
+DOMAIN-SUFFIX,ifeng.com,DIRECT
+DOMAIN-SUFFIX,ifengimg.com,DIRECT
+DOMAIN-SUFFIX,bbwc.cn,DIRECT
+DOMAIN-SUFFIX,3.cn,DIRECT
+DOMAIN-SUFFIX,maxthon.cn,DIRECT
+DOMAIN-SUFFIX,xda.cn,DIRECT
+DOMAIN-SUFFIX,cntv.cn,DIRECT
+DOMAIN-SUFFIX,6.cn,DIRECT
+DOMAIN-SUFFIX,meizu.cn,DIRECT
+DOMAIN-SUFFIX,360doc.cn,DIRECT
+DOMAIN-SUFFIX,sto.cn,DIRECT
+DOMAIN-SUFFIX,xiaomi.cn,DIRECT
+DOMAIN-SUFFIX,ccb.cn,DIRECT
+DOMAIN-SUFFIX,macx.cn,DIRECT
+DOMAIN-SUFFIX,d.cn,DIRECT
+DOMAIN-SUFFIX,m1905.cn,DIRECT
+DOMAIN-SUFFIX,t.cn,DIRECT
+DOMAIN-SUFFIX,sh.cn,DIRECT
+DOMAIN-SUFFIX,bong.cn,DIRECT
+DOMAIN-SUFFIX,mafengwo.cn,DIRECT
+DOMAIN-SUFFIX,ucloud.cn,DIRECT
+DOMAIN-SUFFIX,xdf.cn,DIRECT
+DOMAIN-SUFFIX,china.cn,DIRECT
+DOMAIN-SUFFIX,ip.cn,DIRECT
+DOMAIN-SUFFIX,news.cn,DIRECT
+DOMAIN-SUFFIX,linux.cn,DIRECT
+DOMAIN-SUFFIX,dict.cn,DIRECT
+DOMAIN-SUFFIX,windowsazure.cn,DIRECT
+DOMAIN-SUFFIX,dwz.cn,DIRECT
+DOMAIN-SUFFIX,10010.com,DIRECT
+DOMAIN-SUFFIX,115.com,DIRECT
+DOMAIN-SUFFIX,123u.com,DIRECT
+DOMAIN-SUFFIX,126.com,DIRECT
+DOMAIN-SUFFIX,17173.com,DIRECT
+DOMAIN-SUFFIX,178.com,DIRECT
+DOMAIN-SUFFIX,17cdn.com,DIRECT
+DOMAIN-SUFFIX,21cn.com,DIRECT
+DOMAIN-SUFFIX,2288.org,DIRECT
+DOMAIN-SUFFIX,3322.org,DIRECT
+DOMAIN-SUFFIX,360doc.com,DIRECT
+DOMAIN-SUFFIX,360safe.com,DIRECT
+DOMAIN-SUFFIX,36kr.com,DIRECT
+DOMAIN-SUFFIX,400gb.com,DIRECT
+DOMAIN-SUFFIX,4399.com,DIRECT
+DOMAIN-SUFFIX,51.la,DIRECT
+DOMAIN-SUFFIX,51buy.com,DIRECT
+DOMAIN-SUFFIX,51cto.com,DIRECT
+DOMAIN-SUFFIX,51job.com,DIRECT
+DOMAIN-SUFFIX,51jobcdn.com,DIRECT
+DOMAIN-SUFFIX,5d6d.com,DIRECT
+DOMAIN-SUFFIX,5d6d.net,DIRECT
+DOMAIN-SUFFIX,61.com,DIRECT
+DOMAIN-SUFFIX,6600.org,DIRECT
+DOMAIN-SUFFIX,6rooms.com,DIRECT
+DOMAIN-SUFFIX,7766.org,DIRECT
+DOMAIN-SUFFIX,7k7k.com,DIRECT
+DOMAIN-SUFFIX,8800.org,DIRECT
+DOMAIN-SUFFIX,8866.org,DIRECT
+DOMAIN-SUFFIX,90g.org,DIRECT
+DOMAIN-SUFFIX,91.com,DIRECT
+DOMAIN-SUFFIX,9966.org,DIRECT
+DOMAIN-SUFFIX,acfun.tv,DIRECT
+DOMAIN-SUFFIX,aicdn.com,DIRECT
+DOMAIN-SUFFIX,ali213.net,DIRECT
+DOMAIN-SUFFIX,alibaba.com,DIRECT
+DOMAIN-SUFFIX,aliexpress.com,DIRECT
+DOMAIN-SUFFIX,aliimg.com,DIRECT
+DOMAIN-SUFFIX,alikunlun.com,DIRECT
+DOMAIN-SUFFIX,alisoft.com,DIRECT
+DOMAIN-SUFFIX,aliyun.com,DIRECT
+DOMAIN-SUFFIX,aliyuncdn.com,DIRECT
+DOMAIN-SUFFIX,aliyuncs.com,DIRECT
+DOMAIN-SUFFIX,anzhi.com,DIRECT
+DOMAIN-SUFFIX,appinn.com,DIRECT
+DOMAIN-SUFFIX,apple.com,DIRECT
+DOMAIN-SUFFIX,appsina.com,DIRECT
+DOMAIN-SUFFIX,archlinuxcn.org,DIRECT
+DOMAIN-SUFFIX,atpanel.com,DIRECT
+DOMAIN-SUFFIX,baifendian.com,DIRECT
+DOMAIN-SUFFIX,baihe.com,DIRECT
+DOMAIN-SUFFIX,baixing.com,DIRECT
+DOMAIN-SUFFIX,bdimg.com,DIRECT
+DOMAIN-SUFFIX,bdstatic.com,DIRECT
+DOMAIN-SUFFIX,bilibili.tv,DIRECT
+DOMAIN-SUFFIX,blogbus.com,DIRECT
+DOMAIN-SUFFIX,blueidea.com,DIRECT
+DOMAIN-SUFFIX,ccb.com,DIRECT
+DOMAIN-SUFFIX,cctv.com,DIRECT
+DOMAIN-SUFFIX,cctvpic.com,DIRECT
+DOMAIN-SUFFIX,cdn20.com,DIRECT
+DOMAIN-SUFFIX,china.com,DIRECT
+DOMAIN-SUFFIX,chinabyte.com,DIRECT
+DOMAIN-SUFFIX,chinacache.com,DIRECT
+DOMAIN-SUFFIX,chinacache.net,DIRECT
+DOMAIN-SUFFIX,chinacaipu.com,DIRECT
+DOMAIN-SUFFIX,chinagba.com,DIRECT
+DOMAIN-SUFFIX,chinahr.com,DIRECT
+DOMAIN-SUFFIX,chinajoy.net,DIRECT
+DOMAIN-SUFFIX,chinamobile.com,DIRECT
+DOMAIN-SUFFIX,chinanetcenter.com,DIRECT
+DOMAIN-SUFFIX,chinanews.com,DIRECT
+DOMAIN-SUFFIX,chinapnr.com,DIRECT
+DOMAIN-SUFFIX,chinaren.com,DIRECT
+DOMAIN-SUFFIX,chinaspeeds.net,DIRECT
+DOMAIN-SUFFIX,chinaunix.net,DIRECT
+DOMAIN-SUFFIX,chinaz.com,DIRECT
+DOMAIN-SUFFIX,chint.com,DIRECT
+DOMAIN-SUFFIX,chiphell.com,DIRECT
+DOMAIN-SUFFIX,chuangxin.com,DIRECT
+DOMAIN-SUFFIX,ci123.com,DIRECT
+DOMAIN-SUFFIX,ciku5.com,DIRECT
+DOMAIN-SUFFIX,citysbs.com,DIRECT
+DOMAIN-SUFFIX,class.coursera.org,DIRECT
+DOMAIN-SUFFIX,cloudcdn.net,DIRECT
+DOMAIN-SUFFIX,cmbchina.com,DIRECT
+DOMAIN-SUFFIX,cmfu.com,DIRECT
+DOMAIN-SUFFIX,cmread.com,DIRECT
+DOMAIN-SUFFIX,cmwb.com,DIRECT
+DOMAIN-SUFFIX,cn.archive.ubuntu.com,DIRECT
+DOMAIN-SUFFIX,cn.bing.com,DIRECT
+DOMAIN-SUFFIX,cn.coremetrics.com,DIRECT
+DOMAIN-SUFFIX,cn.debian.org,DIRECT
+DOMAIN-SUFFIX,cn.msn.com,DIRECT
+DOMAIN-SUFFIX,cnak2.englishtown.com,DIRECT
+DOMAIN-SUFFIX,cnbeta.com,DIRECT
+DOMAIN-SUFFIX,cnbetacdn.com,DIRECT
+DOMAIN-SUFFIX,cnblogs.com,DIRECT
+DOMAIN-SUFFIX,cnepub.com,DIRECT
+DOMAIN-SUFFIX,cnzz.com,DIRECT
+DOMAIN-SUFFIX,comsenz.com,DIRECT
+DOMAIN-SUFFIX,csdn.net,DIRECT
+DOMAIN-SUFFIX,ct10000.com,DIRECT
+DOMAIN-SUFFIX,ctdisk.com,DIRECT
+DOMAIN-SUFFIX,dangdang.com,DIRECT
+DOMAIN-SUFFIX,dbank.com,DIRECT
+DOMAIN-SUFFIX,dedecms.com,DIRECT
+DOMAIN-SUFFIX,diandian.com,DIRECT
+DOMAIN-SUFFIX,dianping.com,DIRECT
+DOMAIN-SUFFIX,discuz.com,DIRECT
+DOMAIN-SUFFIX,discuz.net,DIRECT
+DOMAIN-SUFFIX,docin.com,DIRECT
+DOMAIN-SUFFIX,donews.com,DIRECT
+DOMAIN-SUFFIX,dospy.com,DIRECT
+DOMAIN-SUFFIX,douban.com,DIRECT
+DOMAIN-SUFFIX,douban.fm,DIRECT
+DOMAIN-SUFFIX,duapp.com,DIRECT
+DOMAIN-SUFFIX,duba.net,DIRECT
+DOMAIN-SUFFIX,duomi.com,DIRECT
+DOMAIN-SUFFIX,duote.com,DIRECT
+DOMAIN-SUFFIX,duowan.com,DIRECT
+DOMAIN-SUFFIX,egou.com,DIRECT
+DOMAIN-SUFFIX,et8.org,DIRECT
+DOMAIN-SUFFIX,etao.com,DIRECT
+DOMAIN-SUFFIX,f3322.org,DIRECT
+DOMAIN-SUFFIX,fantong.com,DIRECT
+DOMAIN-SUFFIX,fenzhi.com,DIRECT
+DOMAIN-SUFFIX,fhldns.com,DIRECT
+DOMAIN-SUFFIX,ganji.com,DIRECT
+DOMAIN-SUFFIX,gaopeng.com,DIRECT
+DOMAIN-SUFFIX,geekpark.net,DIRECT
+DOMAIN-SUFFIX,gfan.com,DIRECT
+DOMAIN-SUFFIX,hacdn.net,DIRECT
+DOMAIN-SUFFIX,hadns.net,DIRECT
+DOMAIN-SUFFIX,hao123.com,DIRECT
+DOMAIN-SUFFIX,hao123img.com,DIRECT
+DOMAIN-SUFFIX,hc360.com,DIRECT
+DOMAIN-SUFFIX,hdslb.com,DIRECT
+DOMAIN-SUFFIX,hexun.com,DIRECT
+DOMAIN-SUFFIX,hiapk.com,DIRECT
+DOMAIN-SUFFIX,hichina.com,DIRECT
+DOMAIN-SUFFIX,hoopchina.com,DIRECT
+DOMAIN-SUFFIX,huanqiu.com,DIRECT
+DOMAIN-SUFFIX,hudong.com,DIRECT
+DOMAIN-SUFFIX,huochepiao.com,DIRECT
+DOMAIN-SUFFIX,hupu.com,DIRECT
+DOMAIN-SUFFIX,iask.com,DIRECT
+DOMAIN-SUFFIX,iciba.com,DIRECT
+DOMAIN-SUFFIX,idqqimg.com,DIRECT
+DOMAIN-SUFFIX,ifanr.com,DIRECT
+DOMAIN-SUFFIX,ijinshan.com,DIRECT
+DOMAIN-SUFFIX,iqiyi.com,DIRECT
+DOMAIN-SUFFIX,it168.com,DIRECT
+DOMAIN-SUFFIX,itcpn.net,DIRECT
+DOMAIN-SUFFIX,iteye.com,DIRECT
+DOMAIN-SUFFIX,itouzi.com,DIRECT
+DOMAIN-SUFFIX,jandan.net,DIRECT
+DOMAIN-SUFFIX,jiashule.com,DIRECT
+DOMAIN-SUFFIX,jiasule.com,DIRECT
+DOMAIN-SUFFIX,jiathis.com,DIRECT
+DOMAIN-SUFFIX,jiayuan.com,DIRECT
+DOMAIN-SUFFIX,jiepang.com,DIRECT
+DOMAIN-SUFFIX,jing.fm,DIRECT
+DOMAIN-SUFFIX,jobbole.com,DIRECT
+DOMAIN-SUFFIX,jstv.com,DIRECT
+DOMAIN-SUFFIX,jumei.com,DIRECT
+DOMAIN-SUFFIX,kaixin001.com,DIRECT
+DOMAIN-SUFFIX,kandian.com,DIRECT
+DOMAIN-SUFFIX,kandian.net,DIRECT
+DOMAIN-SUFFIX,kanimg.com,DIRECT
+DOMAIN-SUFFIX,kankanews.com,DIRECT
+DOMAIN-SUFFIX,kdnet.net,DIRECT
+DOMAIN-SUFFIX,koudai8.com,DIRECT
+DOMAIN-SUFFIX,ku6.com,DIRECT
+DOMAIN-SUFFIX,ku6cdn.com,DIRECT
+DOMAIN-SUFFIX,ku6img.com,DIRECT
+DOMAIN-SUFFIX,kuaidi100.com,DIRECT
+DOMAIN-SUFFIX,kugou.com,DIRECT
+DOMAIN-SUFFIX,lashou.com,DIRECT
+DOMAIN-SUFFIX,letao.com,DIRECT
+DOMAIN-SUFFIX,letv.com,DIRECT
+DOMAIN-SUFFIX,lietou.com,DIRECT
+DOMAIN-SUFFIX,linezing.com,DIRECT
+DOMAIN-SUFFIX,loli.mg,DIRECT
+DOMAIN-SUFFIX,loli.vg,DIRECT
+DOMAIN-SUFFIX,lvping.com,DIRECT
+DOMAIN-SUFFIX,lxdns.com,DIRECT
+DOMAIN-SUFFIX,dns.weixin.qq.com,DIRECT
+DOMAIN-SUFFIX,mangocity.com,DIRECT
+DOMAIN-SUFFIX,mapbar.com,DIRECT
+DOMAIN-SUFFIX,mcbbs.net,DIRECT
+DOMAIN-SUFFIX,meilishuo.com,DIRECT
+DOMAIN-SUFFIX,meituan.com,DIRECT
+DOMAIN-SUFFIX,meituan.net,DIRECT
+DOMAIN-SUFFIX,meizu.com,DIRECT
+DOMAIN-SUFFIX,microsoft.com,DIRECT
+DOMAIN-SUFFIX,miui.com,DIRECT
+DOMAIN-SUFFIX,moe123.com,DIRECT
+DOMAIN-SUFFIX,moegirl.org,DIRECT
+DOMAIN-SUFFIX,mop.com,DIRECT
+DOMAIN-SUFFIX,mtime.com,DIRECT
+DOMAIN-SUFFIX,my-card.in,DIRECT
+DOMAIN-SUFFIX,mydrivers.com,DIRECT
+DOMAIN-SUFFIX,mzstatic.com,DIRECT
+DOMAIN-SUFFIX,newsmth.net,DIRECT
+DOMAIN-SUFFIX,ngacn.cc,DIRECT
+DOMAIN-SUFFIX,nuomi.com,DIRECT
+DOMAIN-SUFFIX,okbuy.com,DIRECT
+DOMAIN-SUFFIX,optaim.com,DIRECT
+DOMAIN-SUFFIX,oschina.net,DIRECT
+DOMAIN-SUFFIX,paipai.com,DIRECT
+DOMAIN-SUFFIX,pcbeta.com,DIRECT
+DOMAIN-SUFFIX,pchome.net,DIRECT
+DOMAIN-SUFFIX,pcpop.com,DIRECT
+DOMAIN-SUFFIX,pengyou.com,DIRECT
+DOMAIN-SUFFIX,phoenixlzx.com,DIRECT
+DOMAIN-SUFFIX,phpwind.net,DIRECT
+DOMAIN-SUFFIX,pingan.com,DIRECT
+DOMAIN-SUFFIX,pool.ntp.org,DIRECT
+DOMAIN-SUFFIX,pplive.com,DIRECT
+DOMAIN-SUFFIX,pps.tv,DIRECT
+DOMAIN-SUFFIX,ppstream.com,DIRECT
+DOMAIN-SUFFIX,pptv.com,DIRECT
+DOMAIN-SUFFIX,pubyun.com,DIRECT
+DOMAIN-SUFFIX,qhimg.com,DIRECT
+DOMAIN-SUFFIX,qianlong.com,DIRECT
+DOMAIN-SUFFIX,qidian.com,DIRECT
+DOMAIN-SUFFIX,qingdaonews.com,DIRECT
+DOMAIN-SUFFIX,qiniu.com,DIRECT
+DOMAIN-SUFFIX,qiniudn.com,DIRECT
+DOMAIN-SUFFIX,qiushibaike.com,DIRECT
+DOMAIN-SUFFIX,qiyi.com,DIRECT
+DOMAIN-SUFFIX,qiyipic.com,DIRECT
+DOMAIN-SUFFIX,qqmail.com,DIRECT
+DOMAIN-SUFFIX,qstatic.com,DIRECT
+DOMAIN-SUFFIX,qunar.com,DIRECT
+DOMAIN-SUFFIX,qunarzz.com,DIRECT
+DOMAIN-SUFFIX,qvbuy.com,DIRECT
+DOMAIN-SUFFIX,renren.com,DIRECT
+DOMAIN-SUFFIX,renrendai.com,DIRECT
+DOMAIN-SUFFIX,rrfmn.com,DIRECT
+DOMAIN-SUFFIX,rrimg.com,DIRECT
+DOMAIN-SUFFIX,sanguosha.com,DIRECT
+DOMAIN-SUFFIX,sdo.com,DIRECT
+DOMAIN-SUFFIX,sina.com,DIRECT
+DOMAIN-SUFFIX,sinaapp.com,DIRECT
+DOMAIN-SUFFIX,sinaedge.com,DIRECT
+DOMAIN-SUFFIX,sinajs.com,DIRECT
+DOMAIN-SUFFIX,skycn.com,DIRECT
+DOMAIN-SUFFIX,smzdm.com,DIRECT
+DOMAIN-SUFFIX,sogou.com,DIRECT
+DOMAIN-SUFFIX,sohu.com,DIRECT
+DOMAIN-SUFFIX,soku.com,DIRECT
+DOMAIN-SUFFIX,solidot.org,DIRECT
+DOMAIN-SUFFIX,soso.com,DIRECT
+DOMAIN-SUFFIX,soufun.com,DIRECT
+DOMAIN-SUFFIX,soufunimg.com,DIRECT
+DOMAIN-SUFFIX,staticfile.org,DIRECT
+DOMAIN-SUFFIX,staticsdo.com,DIRECT
+DOMAIN-SUFFIX,suning.com,DIRECT
+DOMAIN-SUFFIX,szzfgjj.com,DIRECT
+DOMAIN-SUFFIX,tanx.com,DIRECT
+DOMAIN-SUFFIX,tbcache.com,DIRECT
+DOMAIN-SUFFIX,tdimg.com,DIRECT
+DOMAIN-SUFFIX,tencent.com,DIRECT
+DOMAIN-SUFFIX,tenpay.com,DIRECT
+DOMAIN-SUFFIX,tgbus.com,DIRECT
+DOMAIN-SUFFIX,thawte.com,DIRECT
+DOMAIN-SUFFIX,tiancity.com,DIRECT
+DOMAIN-SUFFIX,tianyaui.com,DIRECT
+DOMAIN-SUFFIX,tiexue.net,DIRECT
+DOMAIN-SUFFIX,tmall.com,DIRECT
+DOMAIN-SUFFIX,tmcdn.net,DIRECT
+DOMAIN-SUFFIX,tom.com,DIRECT
+DOMAIN-SUFFIX,tomonline-inc.com,DIRECT
+DOMAIN-SUFFIX,tuan800.com,DIRECT
+DOMAIN-SUFFIX,tuan800.net,DIRECT
+DOMAIN-SUFFIX,tuanimg.com,DIRECT
+DOMAIN-SUFFIX,tudou.com,DIRECT
+DOMAIN-SUFFIX,tudouui.com,DIRECT
+DOMAIN-SUFFIX,tuniu.com,DIRECT
+DOMAIN-SUFFIX,u148.net,DIRECT
+DOMAIN-SUFFIX,u17.com,DIRECT
+DOMAIN-SUFFIX,ubuntu.com,DIRECT
+DOMAIN-SUFFIX,ucjoy.com,DIRECT
+DOMAIN-SUFFIX,uni-marketers.com,DIRECT
+DOMAIN-SUFFIX,unionpay.com,DIRECT
+DOMAIN-SUFFIX,unionpaysecure.com,DIRECT
+DOMAIN-SUFFIX,upaiyun.com,DIRECT
+DOMAIN-SUFFIX,upyun.com,DIRECT
+DOMAIN-SUFFIX,uusee.com,DIRECT
+DOMAIN-SUFFIX,uuu9.com,DIRECT
+DOMAIN-SUFFIX,vaikan.com,DIRECT
+DOMAIN-SUFFIX,vancl.com,DIRECT
+DOMAIN-SUFFIX,vcimg.com,DIRECT
+DOMAIN-SUFFIX,verycd.com,DIRECT
+DOMAIN-SUFFIX,wandoujia.com,DIRECT
+DOMAIN-SUFFIX,wdjimg.com,DIRECT
+DOMAIN-SUFFIX,weibo.com,DIRECT
+DOMAIN-SUFFIX,weiphone.com,DIRECT
+DOMAIN-SUFFIX,weiyun.com,DIRECT
+DOMAIN-SUFFIX,west263.com,DIRECT
+DOMAIN-SUFFIX,wrating.com,DIRECT
+DOMAIN-SUFFIX,wumii.com,DIRECT
+DOMAIN-SUFFIX,xdcdn.net,DIRECT
+DOMAIN-SUFFIX,xiachufang.com,DIRECT
+DOMAIN-SUFFIX,xiami.com,DIRECT
+DOMAIN-SUFFIX,xiami.net,DIRECT
+DOMAIN-SUFFIX,xiaomi.com,DIRECT
+DOMAIN-SUFFIX,xiaonei.com,DIRECT
+DOMAIN-SUFFIX,xiazaiba.com,DIRECT
+DOMAIN-SUFFIX,xici.net,DIRECT
+DOMAIN-SUFFIX,xilu.com,DIRECT
+DOMAIN-SUFFIX,xinhuanet.com,DIRECT
+DOMAIN-SUFFIX,xinnet.com,DIRECT
+DOMAIN-SUFFIX,xlpan.com,DIRECT
+DOMAIN-SUFFIX,xnpic.com,DIRECT
+DOMAIN-SUFFIX,xungou.com,DIRECT
+DOMAIN-SUFFIX,xunlei.com,DIRECT
+DOMAIN-SUFFIX,ydstatic.com,DIRECT
+DOMAIN-SUFFIX,yesky.com,DIRECT
+DOMAIN-SUFFIX,yeyou.com,DIRECT
+DOMAIN-SUFFIX,yihaodian.com,DIRECT
+DOMAIN-SUFFIX,yihaodianimg.com,DIRECT
+DOMAIN-SUFFIX,yingjiesheng.com,DIRECT
+DOMAIN-SUFFIX,yintai.com,DIRECT
+DOMAIN-SUFFIX,yinyuetai.com,DIRECT
+DOMAIN-SUFFIX,yiqifa.com,DIRECT
+DOMAIN-SUFFIX,qingjie.me,DIRECT
+DOMAIN-SUFFIX,yixun.com,DIRECT
+DOMAIN-SUFFIX,ykimg.com,DIRECT
+DOMAIN-SUFFIX,ynet.com,DIRECT
+DOMAIN-SUFFIX,youdao.com,DIRECT
+DOMAIN-SUFFIX,eqxiu.com,DIRECT
+DOMAIN-SUFFIX,yougou.com,DIRECT
+DOMAIN-SUFFIX,youku.com,DIRECT
+DOMAIN-SUFFIX,yupoo.com,DIRECT
+DOMAIN-SUFFIX,yy.com,DIRECT
+DOMAIN-SUFFIX,zbjimg.com,DIRECT
+DOMAIN-SUFFIX,zhaopin.com,DIRECT
+DOMAIN-SUFFIX,zhi.hu,DIRECT
+DOMAIN-SUFFIX,zhihu.com,DIRECT
+DOMAIN-SUFFIX,zhimg.com,DIRECT
+DOMAIN-SUFFIX,zhubajie.com,DIRECT
+DOMAIN-SUFFIX,zongheng.com,DIRECT
+DOMAIN-SUFFIX,v2ex.com,DIRECT
+DOMAIN-SUFFIX,hi-pda.com,DIRECT
+DOMAIN-SUFFIX,yhd.com,DIRECT
+DOMAIN-SUFFIX,58cdn.com,DIRECT
+DOMAIN-SUFFIX,avosapps.com,DIRECT
+DOMAIN-SUFFIX,mob.com,DIRECT
+DOMAIN-SUFFIX,same.com,DIRECT
+DOMAIN-SUFFIX,toutiao.com,DIRECT
+DOMAIN-SUFFIX,zaih.com,DIRECT
+DOMAIN-SUFFIX,lantouzi.com,DIRECT
+DOMAIN-SUFFIX,amap.com,DIRECT
+DOMAIN-SUFFIX,haosou.com,DIRECT
+DOMAIN-SUFFIX,huofu.com,DIRECT
+DOMAIN-SUFFIX,5wei.com,DIRECT
+DOMAIN-SUFFIX,travelrely.com,DIRECT
+DOMAIN-SUFFIX,seekingalpha.com,DIRECT
+DOMAIN-SUFFIX,appsflyer.com,DIRECT
+DOMAIN-SUFFIX,nyt.com,Proxy
+DOMAIN-SUFFIX,nytco.com,Proxy
+DOMAIN-SUFFIX,nytimes.com,Proxy
+DOMAIN-SUFFIX,nytimg.com,Proxy
+DOMAIN-SUFFIX,nytstyle.com,Proxy
+DOMAIN-SUFFIX,doubleclick.net,REJECT
+DOMAIN-SUFFIX,googleadservices.com,REJECT
+
+DOMAIN-SUFFIX,actives.youku.com,REJECT
+DOMAIN-SUFFIX,ad.api.3g.youku.com,REJECT
+DOMAIN-SUFFIX,atm.youku.com,REJECT
+DOMAIN-SUFFIX,c.yes.youku.com,REJECT
+DOMAIN-SUFFIX,lstat.youku.com,REJECT
+DOMAIN-SUFFIX,lvip.youku.com,REJECT
+DOMAIN-SUFFIX,p.l.youku.com,REJECT
+DOMAIN-SUFFIX,r.l.youku.com,REJECT
+DOMAIN-SUFFIX,stat.youku.com,REJECT
+DOMAIN-SUFFIX,static.lstat.youku.com,REJECT
+DOMAIN-SUFFIX,atm.youku.com,REJECT
+DOMAIN-SUFFIX,ad.api.3g.youku.com,REJECT
+DOMAIN-SUFFIX,statis.api.3g.youku.com,REJECT
+DOMAIN-SUFFIX,ad.api.3g.youku.com,REJECT
+DOMAIN-SUFFIX,count.atm.youku.com,REJECT
+
+
+#DOMAIN-SUFFIX,gtimg.com,DIRECT
+
+
+# Toutiao
+#DOMAIN,ic.snssdk.com,REJECT
+
+
+# Zhuishu
+DOMAIN-SUFFIX,zhuishushenqi.com,DIRECT
+
+# Appzapp By @冯冯ryan_
+DOMAIN-KEYWORD,appzapp,DIRECT
+
+# CDN
+DOMAIN-KEYWORD,ccgslb,DIRECT
+DOMAIN-KEYWORD,chinacache,DIRECT
+
+# Duolinguo
+DOMAIN-KEYWORD,duolingo,DIRECT
+
+# Synology
+DOMAIN-KEYWORD,0x,DIRECT
+
+# Moke
+DOMAIN-KEYWORD,moke,DIRECT
+DOMAIN-KEYWORD,sinaimg,DIRECT
+
+# 12306
+DOMAIN-KEYWORD,steam,DIRECT
+DOMAIN-KEYWORD,alipay,DIRECT
+DOMAIN-KEYWORD,360buy,DIRECT
+DOMAIN-KEYWORD,alimama,DIRECT
+
+
+
+# 如果您喜欢,请在关注或转发时标注作者名称及地址,感谢您的支持!
+
+
+DOMAIN,g.co,Proxy
+DOMAIN,goo.gl,Proxy
+
+
+DOMAIN,app.adjust.com,Proxy
+DOMAIN,api.weather.com,Proxy
+
+# Snapchat
+DOMAIN,data.flurry.com,Proxy
+DOMAIN,app.snapchat.com,Proxy
+
+
+# 如果您喜欢,请在关注或转发时标注作者名称及地址,感谢您的支持!
+DOMAIN-SUFFIX,ggpht.com,Proxy
+DOMAIN-SUFFIX,fb.com,Proxy
+
+# Amazon
+DOMAIN-SUFFIX,amazon.com,Proxy
+DOMAIN-SUFFIX,amazonaws.com,Proxy
+DOMAIN-SUFFIX,glue-static.s3-external-3.amazonaws.com,Proxy
+DOMAIN-SUFFIX,s3-eu-west-1.amazonaws.com,Proxy
+DOMAIN-SUFFIX,s3.amazonaws.com,Proxy
+DOMAIN-SUFFIX,images-amazon.com,Proxy
+DOMAIN-SUFFIX,ssl-images-amazon.com,Proxy
+
+# TWITCH
+DOMAIN-SUFFIX,ioam.de,Proxy
+
+
+# KUVVA
+DOMAIN-SUFFIX,kuvva.com,Proxy
+DOMAIN-SUFFIX,twimg.com,Proxy
+DOMAIN-SUFFIX,edgekey.net,Proxy
+
+# Line By @pikatse
+DOMAIN-SUFFIX,line-cdn.net,Proxy
+DOMAIN-SUFFIX,line.me,Proxy,force-remote-dns
+DOMAIN-SUFFIX,line.naver.jp,Proxy,force-remote-dns
+DOMAIN-SUFFIX,line-apps.com,Proxy,force-remote-dns
+
+# VOA
+DOMAIN-SUFFIX,voacantonese.com,Proxy
+DOMAIN-SUFFIX,voachinese.com,Proxy
+DOMAIN-SUFFIX,voachineseblog.com,Proxy
+DOMAIN-SUFFIX,voagd.com,Proxy
+DOMAIN-SUFFIX,voanews.com,Proxy
+DOMAIN-SUFFIX,voatibetan.com,Proxy
+DOMAIN-SUFFIX,cn.voa.mobi,Proxy
+
+#FB
+DOMAIN-SUFFIX,fbcdn.net,Proxy
+DOMAIN-SUFFIX,t.co,Proxy
+DOMAIN-SUFFIX,ggpht,Proxy
+DOMAIN-SUFFIX,googleapis.com,Proxy
+DOMAIN-SUFFIX,cdninstagram.com,Proxy
+DOMAIN-SUFFIX,instagram.com,Proxy
+DOMAIN-SUFFIX,tumblr,Proxy
+DOMAIN-SUFFIX,yahoo.com,Proxy
+DOMAIN-SUFFIX,wikipedia.org,Proxy
+# Spotify By @LUDOVICFM
+DOMAIN-SUFFIX,scorecardresearch.com,Proxy
+DOMAIN-KEYWORD,scdn,Proxy
+DOMAIN-KEYWORD,moatads,Proxy
+
+DOMAIN-KEYWORD,akamaistream,Proxy
+
+# TVB
+DOMAIN-KEYWORD,tvb.com,Proxy
+
+# OTH
+DOMAIN-KEYWORD,wikileaks,Proxy
+DOMAIN-KEYWORD,wikimapia,Proxy
+DOMAIN-KEYWORD,epochtimes,Proxy
+DOMAIN-KEYWORD,uncyclopedia,Proxy
+DOMAIN-KEYWORD,tibet,Proxy
+DOMAIN-KEYWORD,fgmtv,Proxy
+DOMAIN-KEYWORD,geocities,Proxy
+DOMAIN-KEYWORD,savetibet,Proxy
+DOMAIN-KEYWORD,ntdtv,Proxy
+DOMAIN-KEYWORD,falundafa,Proxy
+DOMAIN-KEYWORD,taiwannation,Proxy
+DOMAIN-KEYWORD,rangzen,Proxy
+DOMAIN-KEYWORD,bbc,Proxy
+DOMAIN-KEYWORD,bloomberg,Proxy
+DOMAIN-KEYWORD,appledaily,Proxy
+DOMAIN-KEYWORD,chinaaid,Proxy
+DOMAIN-KEYWORD,popyard,Proxy
+DOMAIN-KEYWORD,raidcall,Proxy
+DOMAIN,qq.com,DIRECT
+
+# BLOGSPOT
+DOMAIN-KEYWORD,blogspot,Proxy
+
+
+DOMAIN-KEYWORD,akamaihd,Proxy,no-resolve
+DOMAIN-KEYWORD,google,Proxy,force-remote-dns
+DOMAIN-KEYWORD,facebook,Proxy,force-remote-dns
+DOMAIN-KEYWORD,youtube,Proxy,force-remote-dns
+DOMAIN-SUFFIX,ytimg.com,Prpxy
+DOMAIN-KEYWORD,twitter,Proxy,force-remote-dns
+DOMAIN-KEYWORD,gmail,Proxy,force-remote-dns
+DOMAIN-KEYWORD,instagram,Proxy,force-remote-dns
+DOMAIN-KEYWORD,vimeo,Proxy,force-remote-dns
+DOMAIN-KEYWORD,deviantart,Proxy,force-remote-dns
+DOMAIN-KEYWORD,twitch,Proxy,force-remote-dns
+DOMAIN-KEYWORD,jtvnw,Proxy,force-remote-dns
+DOMAIN-KEYWORD,ttvnw,Proxy,force-remote-dns
+DOMAIN-KEYWORD,dropbox,Proxy,force-remote-dns
+DOMAIN-KEYWORD,telegram,Proxy,force-remote-dns
+DOMAIN-KEYWORD,spotify,Proxy,force-remote-dns
+
+DOMAIN,dc.letv.com,REJECT
+DOMAIN,ark.letv.com,REJECT
+# Telegram
+IP-CIDR,91.108.56.0/22,Proxy,no-resolve
+IP-CIDR,91.108.4.0/22,Proxy,no-resolve
+IP-CIDR,109.239.140.0/24,Proxy,no-resolve
+IP-CIDR,149.154.160.0/20,Proxy,no-resolve
+IP-CIDR,101.227.14.0/24,REJECT,no-resolve
+IP-CIDR,101.227.12.0/24,REJECT,no-resolve
+IP-CIDR,111.63.135.146/32,REJECT,no-resolve
+IP-CIDR,111.206.22.0/24,REJECT,no-resolve
+IP-CIDR,121.251.255.237/32,REJECT,no-resolve
+IP-CIDR,123.125.117.0/24,REJECT,no-resolve
+IP-CIDR,123.125.118.0/24,REJECT,no-resolve
+#IP-CIDR,111.206.13.0/24,REJECT,no-resolve
+
+
+# LAN
+IP-CIDR,10.0.0.0/8,DIRECT
+IP-CIDR,100.64.0.0/10,DIRECT
+IP-CIDR,127.0.0.0/8,DIRECT
+IP-CIDR,172.16.0.0/12,DIRECT
+IP-CIDR,192.168.0.0/16,DIRECT
+IP-CIDR,169.254.0.0.0/16,DIRECT
+IP-CIDR,17.0.0.0/8,DIRECT
+GEOIP, CN, DIRECT
+GEOIP, US, Proxy
+FINAL, Proxy
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6b28717
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2016, networkextension
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of SSencrypt nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/PacketTunnel/ENV.swift b/PacketTunnel/ENV.swift
new file mode 100644
index 0000000..f6d6dde
--- /dev/null
+++ b/PacketTunnel/ENV.swift
@@ -0,0 +1,55 @@
+//
+// ENV.swift
+// Surf
+//
+// Created by abigt on 2018/1/3.
+// Copyright © 2018年 A.BIG.T. All rights reserved.
+//
+
+import Foundation
+import XRuler
+import SFSocket
+import Xcon
+import XProxy
+import AxLogger
+func prepare() {
+ //
+ NSLog("init ################2222")
+ SKit.proxyIpAddr = "240.7.1.10"
+ SKit.vpnServer = "240.89.6.4"
+ SKit.dnsAddr = "218.75.4.130"
+ SKit.proxyHTTPSIpAddr = "240.7.1.11"
+ SKit.xxIpAddr = "240.7.1.12"
+ SKit.tunIP = "240.7.1.9"
+ SFSettingModule.setting.mode = .socket
+ XRuler.kProxyGroupFile = ".ProxyGroup"
+ AxLogger.logleve = .Debug
+ #if os(iOS)
+
+ if !SKit.prepare("group.com.abigt.Surf", app: "xxxx", config: "surf.con"){
+ fatalError("framework init error!")
+ }
+ NSLog("init ################333")
+ #elseif os(macOS)
+
+ if !SKit.prepare("745WQDK4L7.com.abigt.Surf", app: "xxxx", config: "abigt.conf"){
+ fatalError("framework init error!")
+ }
+ #endif
+
+}
+func test() {
+ if let _ = SFSettingModule.setting.findRuleByString("www.google.com", useragent: ""){
+
+ }
+ let _ = ProxyGroupSettings.share.findProxy("Proxy")
+
+}
+func prepareApp() {
+ Xcon.debugEnable = true
+ XProxy.debugEanble = true
+
+ XRuler.kProxyGroupFile = ".ProxyGroup"
+ XRuler.groupIdentifier = "group.com.abigt.Surf"
+ SKit.groupIdentifier = "group.com.abigt.Surf"
+}
diff --git a/PacketTunnel/Mac/Info.plist b/PacketTunnel/Mac/Info.plist
new file mode 100644
index 0000000..3ba6685
--- /dev/null
+++ b/PacketTunnel/Mac/Info.plist
@@ -0,0 +1,37 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ en
+ CFBundleDisplayName
+ PacketTunnel-Mac
+ CFBundleExecutable
+ $(EXECUTABLE_NAME)
+ CFBundleIdentifier
+ $(PRODUCT_BUNDLE_IDENTIFIER)
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ $(PRODUCT_NAME)
+ CFBundlePackageType
+ XPC!
+ CFBundleShortVersionString
+ 2.0.2
+ CFBundleSignature
+ ????
+ CFBundleVersion
+ 100
+ LSMinimumSystemVersion
+ $(MACOSX_DEPLOYMENT_TARGET)
+ NSExtension
+
+ NSExtensionPointIdentifier
+ com.apple.networkextension.packet-tunnel
+ NSExtensionPrincipalClass
+ $(PRODUCT_MODULE_NAME).PacketTunnelProvider
+
+ NSHumanReadableCopyright
+ Copyright © 2015年 abigt. All rights reserved.
+
+
diff --git a/PacketTunnel/Mac/PacketTunnel-Mac-Bridging-Header.h b/PacketTunnel/Mac/PacketTunnel-Mac-Bridging-Header.h
new file mode 100644
index 0000000..1855154
--- /dev/null
+++ b/PacketTunnel/Mac/PacketTunnel-Mac-Bridging-Header.h
@@ -0,0 +1,38 @@
+//
+// PacketTunnel-Bridging-Header.h
+// Surf
+//
+// Created by 孔祥波 on 15/12/3.
+// Copyright © 2015年 abigt. All rights reserved.
+//
+
+#ifndef PacketTunnel_Bridging_Header_h
+#define PacketTunnel_Bridging_Header_h
+//#import "SFHeader.h"
+
+#include
+//#import "ServerUtils.h"
+//#import
+////#include
+//#ifdef TCP_MSS
+//#undef TCP_MSS
+//#define TCP_MSS 0x05b4
+//#endif
+//#import "ICMPForwarder.h"
+//#import "SFHeader.h"
+
+
+#include
+
+#ifdef DEBUG
+#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
+#else
+#define DLog(...)
+#endif
+#import
+#import
+
+//#define USE_CRYPTO_OPENSSL=1
+#endif /* PacketTunnel_Bridging_Header_h */
+
+
diff --git a/PacketTunnel/Mac/PacketTunnel_Mac-Swift.h b/PacketTunnel/Mac/PacketTunnel_Mac-Swift.h
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/PacketTunnel/Mac/PacketTunnel_Mac-Swift.h
@@ -0,0 +1 @@
+
diff --git a/PacketTunnel/Mac/PacketTunnel_Mac.entitlements b/PacketTunnel/Mac/PacketTunnel_Mac.entitlements
new file mode 100644
index 0000000..0ab7b90
--- /dev/null
+++ b/PacketTunnel/Mac/PacketTunnel_Mac.entitlements
@@ -0,0 +1,33 @@
+
+
+
+
+ com.apple.application-identifier
+ 745WQDK4L7.com.abigt.Surf.mac.extension
+ com.apple.developer.networking.networkextension
+
+ app-proxy-provider
+ packet-tunnel-provider
+
+ com.apple.developer.networking.vpn.api
+
+ allow-vpn
+
+ com.apple.developer.team-identifier
+ 745WQDK4L7
+ com.apple.security.app-sandbox
+
+ com.apple.security.application-groups
+
+ 745WQDK4L7.com.abigt.Surf
+
+ com.apple.security.network.client
+
+ com.apple.security.network.server
+
+ keychain-access-groups
+
+ 745WQDK4L7.*
+
+
+
diff --git a/PacketTunnel/PacketTunnel-Bridging-Header.h b/PacketTunnel/PacketTunnel-Bridging-Header.h
new file mode 100644
index 0000000..358c07d
--- /dev/null
+++ b/PacketTunnel/PacketTunnel-Bridging-Header.h
@@ -0,0 +1,16 @@
+//
+// PacketTunnel-Bridging-Header.h
+// Surf
+//
+// Created by 孔祥波 on 15/12/3.
+// Copyright © 2015年 yarshure. All rights reserved.
+//
+
+#ifndef PacketTunnel_Bridging_Header_h
+#define PacketTunnel_Bridging_Header_h
+
+#import "SFHeader"
+
+
+#endif /* PacketTunnel_Bridging_Header_h */
+
diff --git a/PacketTunnel/PacketTunnel-Mac.xcconfig b/PacketTunnel/PacketTunnel-Mac.xcconfig
new file mode 100644
index 0000000..65eb5d4
--- /dev/null
+++ b/PacketTunnel/PacketTunnel-Mac.xcconfig
@@ -0,0 +1,23 @@
+//
+// PacketTunnel.xcconfig
+// Surf
+//
+// Created by abigt on 16/1/4.
+// Copyright © 2016年 abigt. All rights reserved.
+//
+//ALWAYS_SEARCH_USER_PATHS = YES
+//FRAMEWORK_SEARCH_PATHS = $(inherited) "$(PROJECT_DIR)/Surf-Mac"
+//HEADER_SEARCH_PATHS = $(inherited) "$(SRCROOT)/Shared/header" "$(SRCROOT)/MMDB" "$(SRCROOT)/shared/lwip/badvpn" "$(SRCROOT)/libsodium-ios/include" "$(SRCROOT)/lib"
+//USER_HEADER_SEARCH_PATHS = $(inherited) "$(SRCROOT)/Shared/header" "$(SRCROOT)/shared/lwip/src/include/"** "$(SRCROOT)/shared/lwip/custom" "$(SRCROOT)/Shared/proxy/ss"
+//OTHER_CFLAGS = $(inherited) -isystem
+//OTHER_LDFLAGS = $(inherited) -lsodium -lmbedcrypto
+//LIBRARY_SEARCH_PATHS = $(inherited) "$(PROJECT_DIR)"
+
+FRAMEWORK_SEARCH_PATHS = $(inherited) //"$(PROJECT_DIR)/Surf-Mac"
+HEADER_SEARCH_PATHS = $(inherited) "$(PROJECT_DIR)/share/include" "$(SRCROOT)/share/include/sodium" "$(SRCROOT)/Shared/header" "$(SRCROOT)/MMDB" "$(SRCROOT)/shared/lwip/badvpn"
+USER_HEADER_SEARCH_PATHS = $(inherited) "$(SRCROOT)/Shared/header" "$(SRCROOT)/shared/lwip/src/include/"** "$(SRCROOT)/shared/lwip/custom" "$(SRCROOT)/Shared/proxy/ss"
+OTHER_CFLAGS = $(inherited) -isystem
+OTHER_LDFLAGS = $(inherited) //-lsodium -lcrypto//-mbedcrypto // -lcrypto //
+LIBRARY_SEARCH_PATHS = $(inherited) "$(PROJECT_DIR)"
+//SSL_LIB_DEFINE = USE_CRYPTO_OPENSSL=1 TCP_MSS=1460
+SSL_LIB_DEFINE = TCP_MSS=1460
diff --git a/PacketTunnel/PacketTunnelProvider.swift b/PacketTunnel/PacketTunnelProvider.swift
new file mode 100644
index 0000000..ecbea0e
--- /dev/null
+++ b/PacketTunnel/PacketTunnelProvider.swift
@@ -0,0 +1,40 @@
+
+//
+// PacketTunnelProvider.swift
+// PacketTunnel
+//
+// Created by kiwi on 15/11/23.
+// Copyright © 2015年 abigt. All rights reserved.
+//
+
+import NetworkExtension
+import SwiftyJSON
+import SFSocket
+import AxLogger
+import Crashlytics
+import Fabric
+import Xcon
+import XRuler
+
+class PacketTunnelProvider: SFPacketTunnelProvider{
+
+ override func startTunnel(options: [String : NSObject]? = nil, completionHandler: @escaping (Error?) -> Void) {
+ prepare()
+ #if os(iOS)
+
+ DispatchQueue.main.async {
+ autoreleasepool {
+ Fabric.with([Crashlytics.self])
+ Fabric.with([Answers.self])
+ Answers.logCustomEvent(withName: "VPN",
+ customAttributes: [
+ "Started": "",
+
+ ])
+ }
+
+ }
+ #endif
+ super.start(options: options, completionHandler: completionHandler)
+ }
+}
diff --git a/PacketTunnel/Surf-Swift.h b/PacketTunnel/Surf-Swift.h
new file mode 100644
index 0000000..3e3c858
--- /dev/null
+++ b/PacketTunnel/Surf-Swift.h
@@ -0,0 +1,359 @@
+// Generated by Apple Swift version 2.1 (swiftlang-700.1.101.6 clang-700.1.76)
+#pragma clang diagnostic push
+
+#if defined(__has_include) && __has_include()
+# include
+#endif
+
+#pragma clang diagnostic ignored "-Wauto-import"
+#include
+#include
+#include
+#include
+
+#if defined(__has_include) && __has_include()
+# include
+#elif !defined(__cplusplus) || __cplusplus < 201103L
+typedef uint_least16_t char16_t;
+typedef uint_least32_t char32_t;
+#endif
+
+typedef struct _NSZone NSZone;
+
+#if !defined(SWIFT_PASTE)
+# define SWIFT_PASTE_HELPER(x, y) x##y
+# define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y)
+#endif
+#if !defined(SWIFT_METATYPE)
+# define SWIFT_METATYPE(X) Class
+#endif
+
+#if defined(__has_attribute) && __has_attribute(objc_runtime_name)
+# define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X)))
+#else
+# define SWIFT_RUNTIME_NAME(X)
+#endif
+#if defined(__has_attribute) && __has_attribute(swift_name)
+# define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X)))
+#else
+# define SWIFT_COMPILE_NAME(X)
+#endif
+#if !defined(SWIFT_CLASS_EXTRA)
+# define SWIFT_CLASS_EXTRA
+#endif
+#if !defined(SWIFT_PROTOCOL_EXTRA)
+# define SWIFT_PROTOCOL_EXTRA
+#endif
+#if !defined(SWIFT_ENUM_EXTRA)
+# define SWIFT_ENUM_EXTRA
+#endif
+#if !defined(SWIFT_CLASS)
+# if defined(__has_attribute) && __has_attribute(objc_subclassing_restricted)
+# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA
+# define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
+# else
+# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
+# define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
+# endif
+#endif
+
+#if !defined(SWIFT_PROTOCOL)
+# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA
+# define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA
+#endif
+
+#if !defined(SWIFT_EXTENSION)
+# define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__)
+#endif
+
+#if !defined(OBJC_DESIGNATED_INITIALIZER)
+# if defined(__has_attribute) && __has_attribute(objc_designated_initializer)
+# define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
+# else
+# define OBJC_DESIGNATED_INITIALIZER
+# endif
+#endif
+#if !defined(SWIFT_ENUM)
+# define SWIFT_ENUM(_type, _name) enum _name : _type _name; enum SWIFT_ENUM_EXTRA _name : _type
+#endif
+typedef float swift_float2 __attribute__((__ext_vector_type__(2)));
+typedef float swift_float3 __attribute__((__ext_vector_type__(3)));
+typedef float swift_float4 __attribute__((__ext_vector_type__(4)));
+typedef double swift_double2 __attribute__((__ext_vector_type__(2)));
+typedef double swift_double3 __attribute__((__ext_vector_type__(3)));
+typedef double swift_double4 __attribute__((__ext_vector_type__(4)));
+typedef int swift_int2 __attribute__((__ext_vector_type__(2)));
+typedef int swift_int3 __attribute__((__ext_vector_type__(3)));
+typedef int swift_int4 __attribute__((__ext_vector_type__(4)));
+#if defined(__has_feature) && __has_feature(modules)
+@import UIKit;
+@import AVFoundation;
+@import ObjectiveC;
+@import Foundation;
+#endif
+
+#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
+#pragma clang diagnostic ignored "-Wduplicate-method-arg"
+@class NSBundle;
+@class NSCoder;
+
+SWIFT_CLASS("_TtC4Surf25AcknowledgeViewController")
+@interface AcknowledgeViewController : UIViewController
+- (void)viewDidLoad;
+- (void)didReceiveMemoryWarning;
+- (nonnull instancetype)initWithNibName:(NSString * __nullable)nibNameOrNil bundle:(NSBundle * __nullable)nibBundleOrNil OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
+@end
+
+@class BarcodeScanViewController;
+
+
+/// The tunnel delegate protocol.
+SWIFT_PROTOCOL("_TtP4Surf19BarcodeScanDelegate_")
+@protocol BarcodeScanDelegate
+- (void)barcodeScanDidScan:(BarcodeScanViewController * __nonnull)controller configString:(NSString * __nonnull)configString;
+- (void)barcodeScanCancelScan:(BarcodeScanViewController * __nonnull)controller;
+@end
+
+@class KKSocks;
+@protocol AddEditDelegate;
+@class NSMutableArray;
+@class UISegmentedControl;
+@class UIStoryboardSegue;
+@class TextFieldCell;
+
+SWIFT_CLASS("_TtC4Surf17AddEditController")
+@interface AddEditController : UITableViewController
+@property (nonatomic) NSInteger numberOfSetting;
+@property (nonatomic) BOOL useCamera;
+@property (nonatomic, strong) KKSocks * __nonnull config;
+@property (nonatomic, strong) id __nullable delegate;
+@property (nonatomic) BOOL typeHttp;
+@property (nonatomic, strong) NSMutableArray * __nonnull textFields;
+@property (nonatomic, weak) IBOutlet TextFieldCell * __null_unspecified nameCell;
+@property (nonatomic, weak) IBOutlet TextFieldCell * __null_unspecified addressCell;
+@property (nonatomic, weak) IBOutlet TextFieldCell * __null_unspecified portCell;
+@property (nonatomic, weak) IBOutlet TextFieldCell * __null_unspecified passwdCell;
+@property (nonatomic, weak) IBOutlet TextFieldCell * __null_unspecified methodCell;
+- (void)viewDidLoad;
+- (void)loadConfig;
+- (void)valueChanged:(UISegmentedControl * __nonnull)sender;
+- (void)saveConfig:(id __nonnull)sender;
+- (IBAction)useBarcode:(id __nonnull)sender;
+- (void)barcodeScanDidScan:(BarcodeScanViewController * __nonnull)controller configString:(NSString * __nonnull)configString;
+- (void)barcodeScanCancelScan:(BarcodeScanViewController * __nonnull)controller;
+- (void)prepareForSegue:(UIStoryboardSegue * __nonnull)segue sender:(id __nullable)sender;
+- (nonnull instancetype)initWithStyle:(UITableViewStyle)style OBJC_DESIGNATED_INITIALIZER;
+- (nonnull instancetype)initWithNibName:(NSString * __nullable)nibNameOrNil bundle:(NSBundle * __nullable)nibBundleOrNil OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+
+/// The tunnel delegate protocol.
+SWIFT_PROTOCOL("_TtP4Surf15AddEditDelegate_")
+@protocol AddEditDelegate
+- (void)addConfig:(AddEditController * __nonnull)controller config:(KKSocks * __nonnull)config;
+@end
+
+@class UIWindow;
+@class UIApplication;
+@class NSObject;
+
+SWIFT_CLASS("_TtC4Surf11AppDelegate")
+@interface AppDelegate : UIResponder
+@property (nonatomic, strong) UIWindow * __nullable window;
+- (BOOL)application:(UIApplication * __nonnull)application didFinishLaunchingWithOptions:(NSDictionary * __nullable)launchOptions;
+- (void)applicationWillResignActive:(UIApplication * __nonnull)application;
+- (void)applicationDidEnterBackground:(UIApplication * __nonnull)application;
+- (void)applicationWillEnterForeground:(UIApplication * __nonnull)application;
+- (void)applicationDidBecomeActive:(UIApplication * __nonnull)application;
+- (void)applicationWillTerminate:(UIApplication * __nonnull)application;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+@class AVCaptureSession;
+@class AVCaptureVideoPreviewLayer;
+@class AVCaptureOutput;
+@class AVCaptureConnection;
+
+SWIFT_CLASS("_TtC4Surf25BarcodeScanViewController")
+@interface BarcodeScanViewController : UIViewController
+@property (nonatomic, readonly, copy) NSString * __nonnull kScanQRCodeQueueName;
+@property (nonatomic, strong) AVCaptureSession * __nullable captureSession;
+@property (nonatomic, strong) AVCaptureVideoPreviewLayer * __nullable videoPreviewLayer;
+@property (nonatomic) BOOL useCamera;
+@property (nonatomic, strong) id __nullable delegate;
+- (void)viewDidLoad;
+- (void)didReceiveMemoryWarning;
+- (IBAction)cancleAction:(id __nonnull)sender;
+- (BOOL)startReading;
+- (void)stopReading;
+- (void)captureOutput:(AVCaptureOutput * __null_unspecified)captureOutput didOutputMetadataObjects:(NSArray * __null_unspecified)metadataObjects fromConnection:(AVCaptureConnection * __null_unspecified)connection;
+- (void)reportScanResult:(NSString * __null_unspecified)result;
+- (nonnull instancetype)initWithNibName:(NSString * __nullable)nibNameOrNil bundle:(NSBundle * __nullable)nibBundleOrNil OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+SWIFT_CLASS("_TtC4Surf9DataShare")
+@interface DataShare : NSObject
++ (BOOL)save:(KKSocks * __nonnull)sock;
++ (NSString * __nonnull)configPath;
++ (KKSocks * __nonnull)readConfig;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+SWIFT_CLASS("_TtC4Surf23HelpTableViewController")
+@interface HelpTableViewController : UITableViewController
+- (void)viewDidLoad;
+- (void)didReceiveMemoryWarning;
+- (nonnull instancetype)initWithStyle:(UITableViewStyle)style OBJC_DESIGNATED_INITIALIZER;
+- (nonnull instancetype)initWithNibName:(NSString * __nullable)nibNameOrNil bundle:(NSBundle * __nullable)nibBundleOrNil OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
+@end
+
+@class NSURL;
+@class UITextView;
+
+SWIFT_CLASS("_TtC4Surf21LogFileViewController")
+@interface LogFileViewController : UIViewController
+@property (nonatomic, strong) NSURL * __nullable filePath;
+@property (nonatomic, weak) IBOutlet UITextView * __nullable textView;
+- (void)viewDidLoad;
+- (void)didReceiveMemoryWarning;
+- (nonnull instancetype)initWithNibName:(NSString * __nullable)nibNameOrNil bundle:(NSBundle * __nullable)nibBundleOrNil OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
+@end
+
+@class UITableView;
+@class NSIndexPath;
+@class UITableViewCell;
+
+SWIFT_CLASS("_TtC4Surf26LogListTableViewController")
+@interface LogListTableViewController : UITableViewController
+@property (nonatomic, copy) NSArray * __nonnull fileList;
+- (void)viewDidLoad;
+- (void)viewWillAppear:(BOOL)animated;
+- (void)viewDidAppear:(BOOL)animated;
+- (void)findFiles;
+- (void)didReceiveMemoryWarning;
+- (NSInteger)numberOfSectionsInTableView:(UITableView * __nonnull)tableView;
+- (NSInteger)tableView:(UITableView * __nonnull)tableView numberOfRowsInSection:(NSInteger)section;
+- (UITableViewCell * __nonnull)tableView:(UITableView * __nonnull)tableView cellForRowAtIndexPath:(NSIndexPath * __nonnull)indexPath;
+- (void)prepareForSegue:(UIStoryboardSegue * __nonnull)segue sender:(id __nullable)sender;
+- (nonnull instancetype)initWithStyle:(UITableViewStyle)style OBJC_DESIGNATED_INITIALIZER;
+- (nonnull instancetype)initWithNibName:(NSString * __nullable)nibNameOrNil bundle:(NSBundle * __nullable)nibBundleOrNil OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
+@end
+
+@class NEVPNManager;
+@class UIButton;
+
+SWIFT_CLASS("_TtC4Surf23ProxyListViewController")
+@interface ProxyListViewController : UITableViewController
+
+/// The target VPN configuration.
+@property (nonatomic, strong) NEVPNManager * __nonnull targetManager;
+@property (nonatomic, strong) NEVPNManager * __nullable configManage;
+
+/// A list of NEVPNManager objects for the packet tunnel configurations.
+@property (nonatomic, copy) NSArray * __nonnull managers;
+@property (nonatomic, weak) UIButton * __nullable startStopButton;
+@property (nonatomic, strong) NSMutableArray * __nonnull proxyList;
+@property (nonatomic, strong) NSIndexPath * __nullable selectPath;
+@property (nonatomic, strong) NSURL * __nonnull applicationDocumentsDirectory;
+- (void)loadProxys;
+
+/// Unwind segue handler.
+- (IBAction)handleUnwind:(UIStoryboardSegue * __nonnull)sender;
+- (void)saveProxys;
+
+/// Handle the event where the view is being hidden.
+- (void)viewWillDisappear:(BOOL)animated;
+- (void)viewDidLoad;
+- (void)findUsedConfig;
+
+/// Handle the event of the view being displayed.
+- (void)viewWillAppear:(BOOL)animated;
+- (void)didReceiveMemoryWarning;
+- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
+- (NSInteger)numberOfSectionsInTableView:(UITableView * __nonnull)tableView;
+- (NSInteger)tableView:(UITableView * __nonnull)tableView numberOfRowsInSection:(NSInteger)section;
+- (IBAction)startConnect:(id __nonnull)sender;
+- (UITableViewCell * __nonnull)tableView:(UITableView * __nonnull)tableView cellForRowAtIndexPath:(NSIndexPath * __nonnull)indexPath;
+- (void)updateCell:(UITableViewCell * __nonnull)cell indexPath:(NSIndexPath * __nonnull)indexPath;
+- (BOOL)tableView:(UITableView * __nonnull)tableView canEditRowAtIndexPath:(NSIndexPath * __nonnull)indexPath;
+- (UITableViewCellEditingStyle)tableView:(UITableView * __nonnull)tableView editingStyleForRowAtIndexPath:(NSIndexPath * __nonnull)indexPath;
+- (void)tableView:(UITableView * __nonnull)tableView didSelectRowAtIndexPath:(NSIndexPath * __nonnull)indexPath;
+- (void)saveConfig;
+- (void)tableView:(UITableView * __nonnull)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath * __nonnull)indexPath;
+- (void)addConfig:(AddEditController * __nonnull)controller config:(KKSocks * __nonnull)config;
+- (void)prepareForSegue:(UIStoryboardSegue * __nonnull)segue sender:(id __nullable)sender;
+- (nonnull instancetype)initWithStyle:(UITableViewStyle)style OBJC_DESIGNATED_INITIALIZER;
+- (nonnull instancetype)initWithNibName:(NSString * __nullable)nibNameOrNil bundle:(NSBundle * __nullable)nibBundleOrNil OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+@interface ProxyListViewController (SWIFT_EXTENSION(Surf))
+- (void)setTargetManager:(NEVPNManager * __nullable)manager title:(NSString * __nullable)title;
+
+/// Re-load all of the packet tunnel configurations from the Network Extension preferences
+- (void)reloadManagers;
+
+/// Register for configuration change notifications.
+- (void)registerStatus;
+- (void)observeStatus;
+
+/// De-register for configuration change notifications.
+- (void)stopObservingStatus;
+- (void)xpc;
+
+/// Handle the user toggling the "enabled" switch.
+- (IBAction)enabledToggled;
+
+/// Handle the user toggling the "VPN" switch.
+- (IBAction)startStopToggled:(id __nonnull)sender;
+@end
+
+
+SWIFT_CLASS("_TtC4Surf20SecondViewController")
+@interface SecondViewController : UIViewController
+- (void)viewDidLoad;
+- (void)didReceiveMemoryWarning;
+- (nonnull instancetype)initWithNibName:(NSString * __nullable)nibNameOrNil bundle:(NSBundle * __nullable)nibBundleOrNil OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+SWIFT_CLASS_NAMED("Socks")
+@interface KKSocks : NSObject
+@property (nonatomic, copy) NSString * __nullable proxyName;
+@property (nonatomic, copy) NSString * __nullable serverAddress;
+@property (nonatomic, copy) NSString * __nullable serverPort;
+@property (nonatomic, copy) NSString * __nullable password;
+@property (nonatomic, copy) NSString * __nullable method;
+@property (nonatomic, copy) NSString * __nullable serverType;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
+- (void)encodeWithCoder:(NSCoder * __nonnull)aCoder;
+@end
+
+@class UITextField;
+@class UILabel;
+
+SWIFT_CLASS("_TtC4Surf13TextFieldCell")
+@interface TextFieldCell : UITableViewCell
+@property (nonatomic, weak) IBOutlet UITextField * __null_unspecified textField;
+@property (nonatomic, weak) IBOutlet UILabel * __null_unspecified cellLabel;
+@property (nonatomic, copy) void (^ __nullable valueChanged)(UITextField * __nonnull);
+- (void)textFieldDidEndEditing:(UITextField * __nonnull)textField;
+- (BOOL)textFieldShouldReturn:(UITextField * __nonnull)textField;
+- (nonnull instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString * __nullable)reuseIdentifier OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
+@end
+
+#pragma clang diagnostic pop
diff --git a/PacketTunnel/config.pac.js b/PacketTunnel/config.pac.js
new file mode 100644
index 0000000..5082d47
--- /dev/null
+++ b/PacketTunnel/config.pac.js
@@ -0,0 +1,133 @@
+var tunnel = "SOCKS5 127.0.0.1:1080; SOCKS 127.0.0.1:1080; DIRECT;";
+var direct = "DIRECT";
+var proxyList = "cdninstagram.com|squarespace.com|aka|licdn.com|gstatic.com|githubusercontent.com|imgur.com|dropboxstatic.com|bitbucket.org|github.com|mzstatic.com|pinboard.in|box.net|gravatar.com|jshint.com|twitch.tv|dropboxusercontent.com|engadget.com|amazon.com|openvpn.net|crashlytics.com|symauth.com|edgecastcdn.net|wikimedia.org|wsj.com|ow.ly|tumblr.com|itunes.com|github.io|lithium.com|wsj.net|openwrt.org|ift.tt|blogspot|t.co|fc2.com|goo.gl|blogcdn.com|twitter.com|linkedin.com|blogsmithmedia.com|instagram|twimg.com|cloudfront.net|docker.com|linode.com|symcd.com|fastly.net|ubnt.com|twitter|fbcdn.net|imageshack.us|fabric.io|wikipedia.com|dnsimple.com|eurekavpt.com|ytimg.com|nytimes.com|megaupload.com|blog.com|akamaihd.net|google|duckduckgo.com|symcb.com|youtube|ssl-images-amazon.com|mobile01.com|sstatic.net|ggpht.com|kenengba.com|me.com|j.mp|dropbox.com|fb.me|staticflickr.com|thepiratebay.org|stackoverflow.com|gmail|bloomberg.com|youtu.be|golang.org|feedburner.com|godaddy.com|facebook|flickr.com|modmyi.com|bit.ly|name.com|appspot.com|vimeo.com|chromium.org|kat.cr|wikipedia.org|wp.com|cloudflare.com|cocoapods.org|dribbble.com|wordpress.com|blogger.com|android.com|digicert.com|tapbots.com|amazonaws.com|cl.ly|akamai.net|angularjs.org".split("|").reduce(function(a, b) {
+ return a[b] = 1, a;
+}, {});
+var directList = "360buy|apple.com|sohu.com|bdimg.com|icloud.com|hao123.com|analytics.126.net|qhimg.com|amap.com|cn|xunlei.com|cnbeta.com|api.smoot.apple.com|baidu.com|taobao.com|alipay|soso.com|lcdn-registration.apple.com|configuration.apple.com|youku.com|suning.com|netease.com|akadns.net|sogou.com|weibo.com|163.com|guzzoni.apple.com|douban.com|xp.apple.com|126.net|ess.apple.com|jd.com|captive.apple.com|cnzz.com|outlook.com|medium.com|tudou.com|ifeng.com|bdstatic.com|haosou.com|alicdn.com|tmall.com|ls.apple.com|smp-device-content.apple.com|iqiyi.com|ykimg.com|qq.com|zhihu.com|push.apple.com|gtimg.com|weather.com".split("|").reduce(function(a, b) {
+ return a[b] = 1, a;
+}, {});
+var rejectList = "duomeng.net|adzerk.net|advertising.com|mobads.baidu.com|googeadsserving.cn|appads.com|adwhirl.com|js-agent.newrelic.com|ads|cr-nielsen.com|stat.ws.126.net|adcome.cn|wooboo.com.cn|admaster.com.cn|guomob.com|asimgs.pplive.cn|simaba.taobao.com|immob.cn|wiyun.com|mmstat.com|domob.com.cn|analytics|smartadserver.com|flurry.com|zhiziyun.com|temp.163.com|cmcore.com|sax.sina.cn|duomeng.cn|adsage.cn|wqmobile.com|aduu.cn|umeng.co|doubleclick.net|cnzz.com|stat.m.jd.com|ark.letv.com|uyunad.com|g.163.com|flurry.co|adxmi.com|monitor.uu.qq.com|tajs.qq.com|localytics.com|baidustatic.com|pos.baidu.com|umeng.com|eclick.baidu.com|m.simaba.taobao.com|inmobi.com|miaozhen.com|umeng.net|ads.mopub.com|waps.cn|mobads-logs.baidu.com|adview.cn|cbjs.baidu.com|adjust.com|acjs.aliyun.com|51.la|iadsdk.apple.com|anquan.org|counter.kingsoft.com|atm.youku.com|lh8.ggpht.com|ad.unimhk.com|adash.m.taobao.com|mob.c|pingtcss.qq.com|duomeng.org|x.jd.com|baifendian.com|adsmogo|cpro.baidu.com|lh7.ggpht.com|track|acs86.com|adwo.com|lh6.ggpht.com|bam.nr-data.net|msga.71.am|dsp.youdao.com|report.qq.com|pingma.qq.com|lh5.ggpht.com|msg.71.am|kejet.net|adinfuse.com|lives.l.qq.com|beacon.sina.com.cn|ad.api.3g.youku.com|adsage.com|traffic|adsmogo.org|nsclick.baidu.com|admob.com|appsflyer.com|lh4.ggpht.com|ads.mobclix.com|applifier.com|www.panoramio.com|beacon.qq.com|duomeng|youmi.net|pagead2.googlesyndication.com|csi.gstatic.com|lh3.ggpht.com|mtj.baidu.com|domob.org|ad.api.3g.tudou.com|coremetrics.com|pixel.wp.com|intely.cn|irs01.com|lh2.ggpht.com|adchina.com|ushaqi.com|tiqcdn.com|mixpanel.com|pingjs.qq.com|lh1.ggpht.com|127.net|union.youdao.com|hm.baidu.com|tapjoyads.com|umtrack.com|madmini.com|wrating.com|tanx.com".split("|").reduce(function(a, b) {
+ return a[b] = 1, a;
+}, {});
+var ipRange = [
+ "17.0.0.0\/8\/DIRECT",
+ "91.108.56.0\/22\/PROXY",
+ "91.108.4.0\/22\/PROXY",
+ "109.239.140.0\/24\/PROXY",
+ "149.154.160.0\/20\/PROXY",
+ "192.168.0.0\/16\/DIRECT",
+ "10.0.0.0\/8\/DIRECT",
+ "172.16.0.0\/12\/DIRECT",
+ "127.0.0.0\/8\/DIRECT"
+];
+var finallyRule = "PROXY";
+var cidrToSubnetMask = {
+ "0": "0.0.0.0",
+ "1": "128.0.0.0",
+ "2": "192.0.0.0",
+ "3": "224.0.0.0",
+ "4": "240.0.0.0",
+ "5": "248.0.0.0",
+ "6": "252.0.0.0",
+ "7": "254.0.0.0",
+ "8": "255.0.0.0",
+ "9": "255.128.0.0",
+ "10": "255.192.0.0",
+ "11": "255.224.0.0",
+ "12": "255.240.0.0",
+ "13": "255.248.0.0",
+ "14": "255.252.0.0",
+ "15": "255.254.0.0",
+ "16": "255.255.0.0",
+ "17": "255.255.128.0",
+ "18": "255.255.192.0",
+ "19": "255.255.224.0",
+ "20": "255.255.240.0",
+ "21": "255.255.248.0",
+ "22": "255.255.252.0",
+ "23": "255.255.254.0",
+ "24": "255.255.255.0",
+ "25": "255.255.255.128",
+ "26": "255.255.255.192",
+ "27": "255.255.255.224",
+ "28": "255.255.255.240",
+ "29": "255.255.255.248",
+ "30": "255.255.255.252",
+ "31": "255.255.255.254",
+ "32": "255.255.255.255"
+};
+
+ipRange = ipRange.contact(
+ "0.0.0.0/8/DIRECT",
+ "10.0.0.0/8/DIRECT",
+ "100.64.0.0/10/DIRECT",
+ "127.0.0.0/8/DIRECT",
+ "169.254.0.0/16/DIRECT",
+ "172.16.0.0/12/DIRECT",
+ "192.0.0.0/24/DIRECT",
+ "192.0.2.0/24/DIRECT",
+ "192.168.0.0/16/DIRECT",
+ "198.18.0.0/15/DIRECT",
+ "198.51.100.0/24/DIRECT",
+ "203.0.113.0/24/DIRECT",
+ "224.0.0.0/4/DIRECT",
+ "240.0.0.0/4/DIRECT",
+ "255.255.255.255/32/DIRECT"
+);
+
+function FindProxyForURL(url, host) {
+ if (isPlainHostName(host)) {
+ return direct;
+ }
+
+ var domain = host;
+ var pos = 0;
+ var idx = 0;
+
+ do {
+ if (directList.hasOwnProperty(domain)) {
+ return direct;
+ }
+
+ if (proxyList.hasOwnProperty(domain) || rejectList.hasOwnProperty(domain)) {
+ return tunnel;
+ }
+
+ idx = pos;
+ pos = host.indexOf(".", pos) + 1;
+
+ if (idx < pos - 1) {
+ var key = host.substring(idx, pos - 1);
+ if (directList.hasOwnProperty(key)) {
+ return direct;
+ }
+ if (proxyList.hasOwnProperty(key) || rejectList.hasOwnProperty(key)) {
+ return tunnel;
+ }
+ }
+
+ domain = host.substring(pos);
+ } while (pos > 0);
+
+ var ip = dnsResolve(host);
+
+ if (!ip) {
+ return tunnel;
+ }
+
+ for (var i in ipRange) {
+ var parts = ipRange[i].split('/');
+ if (isInNet(ip, parts[0], cidrToSubnetMask[parts[1]])) {
+ if (parts[2] == 'DIRECT') {
+ return direct;
+ }
+ return tunnel;
+ }
+ }
+
+ if (finallyRule == 'PROXY') {
+ return tunnel;
+ }
+
+ return direct;
+}
\ No newline at end of file
diff --git a/PacketTunnel/iOS/.adblock b/PacketTunnel/iOS/.adblock
new file mode 100644
index 0000000..7fbbb23
--- /dev/null
+++ b/PacketTunnel/iOS/.adblock
@@ -0,0 +1,259 @@
+ad.sina.com.cn#Adblock
+adm.leju.sina.com.cn#Adblock
+atm.sina.com#Adblock
+beacon.sina.com.cn#Adblock
+dcads.sina.com.cn#Adblock
+sax.sina.cn#Adblock
+sax.sina.com.cn#Adblock
+tjs.sjs.sinajs.cn#Adblock
+act.qq.com#Adblock
+adsfile.qq.com#Adblock
+beacon.qq.com#Adblock
+e.qq.com#Adblock
+gdt.qq.com#Adblock
+l.qq.com#Adblock
+monitor.uu.qq.com#Adblock
+pgdt.gtimg.cn#Adblock
+pingjs.qq.com#Adblock
+pingma.qq.com#Adblock
+pingtcss.qq.com#Adblock
+report.qq.com#Adblock
+tajs.qq.com#Adblock
+tcss.qq.com#Adblock
+3600.com#Adblock
+dev.tg.wan.360.cn#Adblock
+f.360.cn#Adblock
+kuaikan.netmon.360safe.com#Adblock
+leak.360.cn#Adblock
+openbox.mobilem.360.cn#Adblock
+pub.se.360.cn#Adblock
+soft.data.weather.360.cn#Adblock
+stat.360safe.com#Adblock
+stat.m.360.cn#Adblock
+update.360safe.com#Adblock
+adgeo.163.com#Adblock
+bobo.163.com#Adblock
+fa.163.com#Adblock
+g.163.com#Adblock
+gb.corp.163.com#Adblock
+oadz.com#Adblock
+oimagea2.ydstatic.com#Adblock
+pagechoice.net#Adblock
+prom.gome.com.cn#Adblock
+rlogs.youdao.com#Adblock
+static.flv.uuzuonline.com#Adblock
+wanproxy.127.net#Adblock
+ws.126.net#Adblock
+actives.youku.com#Adblock
+ad.api.3g.tudou.com#Adblock
+ad.api.3g.youku.com#Adblock
+ad.m.iqiyi.com#Adblock
+adcontrol.tudou.com#Adblock
+adplay.tudou.com#Adblock
+afp.qiyi.com#Adblock
+agn.aty.sohu.com#Adblock
+ark.letv.com#Adblock
+asimgs.pplive.cn#Adblock
+atanx.alicdn.com#Adblock
+atm.youku.com#Adblock
+c.yes.youku.com#Adblock
+cc.xtgreat.com#Adblock
+cm.zhiziyun.com#Adblock
+cupid.iqiyi.com#Adblock
+cupid.qiyi.com#Adblock
+d.dsp.imageter.com#Adblock
+dc.letv.com#Adblock
+de.as.pptv.com#Adblock
+g.uusee.com#Adblock
+gug.ku6cdn.com#Adblock
+ifacelog.iqiyi.com#Adblock
+iwstat.tudou.com#Adblock
+kwflvcdn.000dn.com#Adblock
+lives.l.qq.com#Adblock
+logger.baofeng.com#Adblock
+logstat.t.sfht.com#Adblock
+lstat.youku.com#Adblock
+lvip.youku.com#Adblock
+m.aty.sohu.com#Adblock
+msg.71.am#Adblock
+match.rtbidder.net#Adblock
+n-st.vip.com#Adblock
+n.mark.letv.com#Adblock
+nstat.tudou.com#Adblock
+p-log.ykimg.com#Adblock
+p.l.qq.com#Adblock
+p.l.ykimg.com#Adblock
+p.l.youku.com#Adblock
+pics.taobaocdn.com#Adblock
+pop.uusee.com#Adblock
+pq.stat.ku6.com#Adblock
+pv.sohu.com#Adblock
+r.l.youku.com#Adblock
+rcd.iqiyi.com#Adblock
+rtb.behe.com#Adblock
+show.re.taobao.com#Adblock
+shrek.6.cn#Adblock
+simba.6.cn#Adblock
+st.vq.ku6.cn#Adblock
+stat.tudou.com#Adblock
+stat.youku.com#Adblock
+static.g.ppstream.com#Adblock
+static.ku6.com#Adblock
+static.lstat.youku.com#Adblock
+stats.tudou.com#Adblock
+strip.taobaocdn.com#Adblock
+stuff.cdn.biddingx.com#Adblock
+t.cr-nielsen.com#Adblock
+tns.simba.taobao.com#Adblock
+traffic.uusee.com#Adblock
+union.6.cn#Adblock
+duomeng.net#Adblock
+adzerk.net#Adblock
+advertising.com#Adblock
+mobads.baidu.com#Adblock
+googeadsserving.cn#Adblock
+appads.com#Adblock
+adwhirl.com#Adblock
+js-agent.newrelic.com#Adblock
+cr-nielsen.com#Adblock
+stat.ws.126.net#Adblock
+adcome.cn#Adblock
+wooboo.com.cn#Adblock
+admaster.com.cn#Adblock
+guomob.com#Adblock
+asimgs.pplive.cn#Adblock
+simaba.taobao.com#Adblock
+immob.cn#Adblock
+wiyun.com#Adblock
+mmstat.com#Adblock
+domob.com.cn#Adblock
+analytics#Adblock
+smartadserver.com#Adblock
+flurry.com#Adblock
+zhiziyun.com#Adblock
+temp.163.com#Adblock
+cmcore.com#Adblock
+sax.sina.cn#Adblock
+duomeng.cn#Adblock
+adsage.cn#Adblock
+wqmobile.com#Adblock
+aduu.cn#Adblock
+umeng.co#Adblock
+doubleclick.net#Adblock
+cnzz.com#Adblock
+stat.m.jd.com#Adblock
+ark.letv.com#Adblock
+uyunad.com#Adblock
+g.163.com#Adblock
+flurry.co#Adblock
+adxmi.com#Adblock
+monitor.uu.qq.com#Adblock
+tajs.qq.com#Adblock
+localytics.com#Adblock
+pos.baidu.com#Adblock
+umeng.com#Adblock
+eclick.baidu.com#Adblock
+m.simaba.taobao.com#Adblock
+inmobi.com#Adblock
+miaozhen.com#Adblock
+umeng.net#Adblock
+ads.mopub.com#Adblock
+waps.cn#Adblock
+mobads-logs.baidu.com#Adblock
+adview.cn#Adblock
+cbjs.baidu.com#Adblock
+adjust.com#Adblock
+acjs.aliyun.com#Adblock
+51.la#Adblock
+iadsdk.apple.com#Adblock
+anquan.org#Adblock
+counter.kingsoft.com#Adblock
+atm.youku.com#Adblock
+lh8.ggpht.com#Adblock
+ad.unimhk.com#Adblock
+adash.m.taobao.com#Adblock
+mob.c#Adblock
+pingtcss.qq.com#Adblock
+duomeng.org#Adblock
+x.jd.com#Adblock
+baifendian.com#Adblock
+adsmogo#Adblock
+cpro.baidu.com#Adblock
+lh7.ggpht.com#Adblock
+track#Adblock
+acs86.com#Adblock
+adwo.com#Adblock
+lh6.ggpht.com#Adblock
+bam.nr-data.net#Adblock
+msga.71.am#Adblock
+dsp.youdao.com#Adblock
+report.qq.com#Adblock
+pingma.qq.com#Adblock
+lh5.ggpht.com#Adblock
+msg.71.am#Adblock
+kejet.net#Adblock
+adinfuse.com#Adblock
+lives.l.qq.com#Adblock
+beacon.sina.com.cn#Adblock
+ad.api.3g.youku.com#Adblock
+adsage.com#Adblock
+traffic#Adblock
+adsmogo.org#Adblock
+nsclick.baidu.com#Adblock
+admob.com#Adblock
+appsflyer.com#Adblock
+lh4.ggpht.com#Adblock
+ads.mobclix.com#Adblock
+applifier.com#Adblock
+www.panoramio.com#Adblock
+beacon.qq.com#Adblock
+duomeng#Adblock
+youmi.net#Adblock
+pagead2.googlesyndication.com#Adblock
+csi.gstatic.com#Adblock
+lh3.ggpht.com#Adblock
+mtj.baidu.com#Adblock
+domob.org#Adblock
+ad.api.3g.tudou.com#Adblock
+coremetrics.com#Adblock
+pixel.wp.com#Adblock
+intely.cn#Adblock
+irs01.com#Adblock
+lh2.ggpht.com#Adblock
+adchina.com#Adblock
+ushaqi.com#Adblock
+tiqcdn.com#Adblock
+mixpanel.com#Adblock
+pingjs.qq.com#Adblock
+lh1.ggpht.com#Adblock
+127.net#Adblock
+union.youdao.com#Adblock
+hm.baidu.com#Adblock
+tapjoyads.com#Adblock
+umtrack.com#Adblock
+madmini.com#Adblock
+wrating.com#Adblock
+tanx.com#Adblock
+yes1.feng.com#Adblock
+statis.api.3g.youku.com#Adblock
+ad\.api\.3g\.youku\.com#优酷土豆
+count.atm.youku.com#优酷土豆
+atm\.youku\.com#优酷土豆
+ad\.api\.3g\.tudou\.com#优酷土豆
+lives\.l\.qq\.com#腾讯视频
+ark\.letv\.com#乐视
+asimgs\.pplive\.cn#PPTV
+agn\.aty\.sohu\.com#搜狐视频
+x\.da\.hunantv\.com#芒果tv
+124.160.194.11:8080#联通DNS
+miaozhen\.com#秒针
+^(.*)?ads(.*)?\.baidu\.com#百度
+^(.*)ads\.g\.doubleclick\.net#Google_AdMob
+^([^/:]*\.)?inmob\.com#Inmobi
+^amob\.acs86\.com#易传媒
+^([^/:]*\.)?domob(cdn)?\.[cn|com]#多盟
+^([^/:]*\.)?duomeng\.[net|cn|org]#多盟
+^([^/:]*\.)?ads\.mopub\.[com|cn]#MoPub
+^impact\.applifier\.com#Unity
+^(.*)?gdt\.qq\.com#腾讯广点通
+^(.*)?litchix\.com#Onlinetime
\ No newline at end of file
diff --git a/PacketTunnel/iOS/Info.plist b/PacketTunnel/iOS/Info.plist
new file mode 100644
index 0000000..a1d78f9
--- /dev/null
+++ b/PacketTunnel/iOS/Info.plist
@@ -0,0 +1,47 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ en
+ CFBundleDisplayName
+ PacketTunnel
+ CFBundleExecutable
+ $(EXECUTABLE_NAME)
+ CFBundleIdentifier
+ $(PRODUCT_BUNDLE_IDENTIFIER)
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ $(PRODUCT_NAME)
+ CFBundlePackageType
+ XPC!
+ CFBundleShortVersionString
+ 4.0
+ CFBundleSignature
+ ????
+ CFBundleVersion
+ 805
+ Fabric
+
+ APIKey
+
+ Kits
+
+
+ KitInfo
+
+ KitName
+ Crashlytics
+
+
+
+ NSExtension
+
+ NSExtensionPointIdentifier
+ com.apple.networkextension.packet-tunnel
+ NSExtensionPrincipalClass
+ $(PRODUCT_MODULE_NAME).PacketTunnelProvider
+
+
+
diff --git a/PacketTunnel/iOS/PacketTunnel-Bridging-Header.h b/PacketTunnel/iOS/PacketTunnel-Bridging-Header.h
new file mode 100644
index 0000000..8f0d744
--- /dev/null
+++ b/PacketTunnel/iOS/PacketTunnel-Bridging-Header.h
@@ -0,0 +1,33 @@
+//
+// PacketTunnel-Bridging-Header.h
+// Surf
+//
+// Created by 孔祥波 on 15/12/3.
+// Copyright © 2015年 abigt. All rights reserved.
+//
+
+#ifndef PacketTunnel_Bridging_Header_h
+#define PacketTunnel_Bridging_Header_h
+
+//#import "ICMPForwarder.h"
+//#import "SFHeader.h"
+//#import "MMDB.h"
+
+#include
+//#import "GCDAsyncSocket.h"
+//#import "GCDAsyncUdpSocket.h"
+
+//#import "SFVPNSession.h"
+//#include "HTTPProxyServer.h"
+//#ifdef DEBUG
+//#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
+//#else
+//#define DLog(fmt, ...) {}
+//NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
+
+//#define DLog(...)
+//#endif
+//#import
+//#import
+#endif /* PacketTunnel_Bridging_Header_h */
+
diff --git a/PacketTunnel/iOS/PacketTunnel-Swift.h b/PacketTunnel/iOS/PacketTunnel-Swift.h
new file mode 100644
index 0000000..9ec9b51
--- /dev/null
+++ b/PacketTunnel/iOS/PacketTunnel-Swift.h
@@ -0,0 +1,797 @@
+// Generated by Apple Swift version 2.3 (swiftlang-800.10.11 clang-800.0.36)
+#pragma clang diagnostic push
+
+#if defined(__has_include) && __has_include()
+# include
+#endif
+
+#pragma clang diagnostic ignored "-Wauto-import"
+#include
+#include
+#include
+#include
+
+#if !defined(SWIFT_TYPEDEFS)
+# define SWIFT_TYPEDEFS 1
+# if defined(__has_include) && __has_include()
+# include
+# elif !defined(__cplusplus) || __cplusplus < 201103L
+typedef uint_least16_t char16_t;
+typedef uint_least32_t char32_t;
+# endif
+typedef float swift_float2 __attribute__((__ext_vector_type__(2)));
+typedef float swift_float3 __attribute__((__ext_vector_type__(3)));
+typedef float swift_float4 __attribute__((__ext_vector_type__(4)));
+typedef double swift_double2 __attribute__((__ext_vector_type__(2)));
+typedef double swift_double3 __attribute__((__ext_vector_type__(3)));
+typedef double swift_double4 __attribute__((__ext_vector_type__(4)));
+typedef int swift_int2 __attribute__((__ext_vector_type__(2)));
+typedef int swift_int3 __attribute__((__ext_vector_type__(3)));
+typedef int swift_int4 __attribute__((__ext_vector_type__(4)));
+#endif
+
+#if !defined(SWIFT_PASTE)
+# define SWIFT_PASTE_HELPER(x, y) x##y
+# define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y)
+#endif
+#if !defined(SWIFT_METATYPE)
+# define SWIFT_METATYPE(X) Class
+#endif
+
+#if defined(__has_attribute) && __has_attribute(objc_runtime_name)
+# define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X)))
+#else
+# define SWIFT_RUNTIME_NAME(X)
+#endif
+#if defined(__has_attribute) && __has_attribute(swift_name)
+# define SWIFT_COMPILE_NAME(X) __attribute__((swift_name(X)))
+#else
+# define SWIFT_COMPILE_NAME(X)
+#endif
+#if !defined(SWIFT_CLASS_EXTRA)
+# define SWIFT_CLASS_EXTRA
+#endif
+#if !defined(SWIFT_PROTOCOL_EXTRA)
+# define SWIFT_PROTOCOL_EXTRA
+#endif
+#if !defined(SWIFT_ENUM_EXTRA)
+# define SWIFT_ENUM_EXTRA
+#endif
+#if !defined(SWIFT_CLASS)
+# if defined(__has_attribute) && __has_attribute(objc_subclassing_restricted)
+# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA
+# define SWIFT_CLASS_NAMED(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
+# else
+# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
+# define SWIFT_CLASS_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
+# endif
+#endif
+
+#if !defined(SWIFT_PROTOCOL)
+# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA
+# define SWIFT_PROTOCOL_NAMED(SWIFT_NAME) SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA
+#endif
+
+#if !defined(SWIFT_EXTENSION)
+# define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__)
+#endif
+
+#if !defined(OBJC_DESIGNATED_INITIALIZER)
+# if defined(__has_attribute) && __has_attribute(objc_designated_initializer)
+# define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
+# else
+# define OBJC_DESIGNATED_INITIALIZER
+# endif
+#endif
+#if !defined(SWIFT_ENUM)
+# define SWIFT_ENUM(_type, _name) enum _name : _type _name; enum SWIFT_ENUM_EXTRA _name : _type
+# if defined(__has_feature) && __has_feature(generalized_swift_name)
+# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); enum SWIFT_COMPILE_NAME(SWIFT_NAME) SWIFT_ENUM_EXTRA _name : _type
+# else
+# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME) SWIFT_ENUM(_type, _name)
+# endif
+#endif
+#if defined(__has_feature) && __has_feature(modules)
+@import ObjectiveC;
+@import Dispatch;
+@import Foundation;
+@import Security;
+@import NetworkExtension;
+@import SystemConfiguration;
+#endif
+
+#import "/Users/abigt/github/surf/PacketTunnel/iOS/PacketTunnel-Bridging-Header.h"
+
+#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
+#pragma clang diagnostic ignored "-Wduplicate-method-arg"
+@class Reachability;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS11AxEnvHelper")
+@interface AxEnvHelper : NSObject
++ (Reachability * _Nonnull)reachAiblity;
++ (void)setReachAiblity:(Reachability * _Nonnull)value;
++ (NSString * _Nonnull)platform;
++ (NSString * _Nonnull)systemName;
++ (NSString * _Nonnull)deviceName;
++ (NSString * _Nonnull)systemVersion;
++ (NSString * _Nonnull)appVersion;
++ (NSString * _Nonnull)appBuild;
++ (NSString * _Nonnull)deviceModel;
++ (NSString * _Nonnull)deviceLocalizedModel;
++ (NSString * _Nonnull)phoneIdentifier;
++ (NSString * _Nonnull)appIdentifier;
++ (NSString * _Nonnull)screenSize;
++ (NSString * _Nonnull)carrier;
++ (NSString * _Nonnull)networkType;
++ (NSDictionary * _Nonnull)infoDict;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+@end
+
+@class NSURL;
+@class NSDate;
+enum AxLoggerLevel : NSInteger;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS8AxLogger")
+@interface AxLogger : NSObject
++ (NSURL * _Nonnull)groupURL;
++ (void)setGroupURL:(NSURL * _Nonnull)value;
++ (void)closeLogging;
++ (void)resetLogFile;
++ (void)openLogging:(NSDate * _Nonnull)date;
++ (enum AxLoggerLevel)logleve;
++ (void)setLogleve:(enum AxLoggerLevel)value;
++ (void)log:(NSString * _Nonnull)msg level:(enum AxLoggerLevel)level category:(NSString * _Nonnull)category file:(NSString * _Nonnull)file line:(NSInteger)line ud:(NSDictionary * _Nonnull)ud tags:(NSArray * _Nonnull)tags time:(NSDate * _Nonnull)time;
++ (void)enableConsole:(BOOL)enable;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+@end
+
+typedef SWIFT_ENUM(NSInteger, AxLoggerLevel) {
+ AxLoggerLevelInfo = 0,
+ AxLoggerLevelNotify = 1,
+ AxLoggerLevelError = 2,
+ AxLoggerLevelWarning = 3,
+ AxLoggerLevelTrace = 4,
+ AxLoggerLevelVerbose = 5,
+ AxLoggerLevelDebug = 6,
+};
+
+@class GCDAsyncSocket;
+@class NSError;
+@class NSData;
+@protocol ConnectorDelegate;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS9Connector")
+@interface Connector : NSObject
+@property (nonatomic, weak) id _Nullable delegate;
+@property (nonatomic, copy) NSString * _Nonnull targetHost;
+@property (nonatomic) uint16_t targetPort;
+@property (nonatomic, copy) NSString * _Nonnull remoteIPaddress;
+@property (nonatomic, strong) GCDAsyncSocket * _Nullable socket;
+@property (nonatomic) BOOL socks_reading;
+@property (nonatomic) BOOL socks_writing;
+@property (nonatomic, strong) dispatch_queue_t _Nullable socket_Queue;
+@property (nonatomic) NSInteger connectTime;
+- (NSString * _Nullable)interfaceAddr;
+@property (nonatomic) BOOL shoudClose;
+@property (nonatomic) NSInteger cID;
+@property (nonatomic, copy) NSString * _Nonnull cIDString;
+@property (nonatomic) BOOL isConnected;
+@property (nonatomic) BOOL isDisconnected;
+- (dispatch_queue_t _Nullable)socketQueue;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+- (nonnull instancetype)initWithPolicy:(NSString * _Nonnull)policy OBJC_DESIGNATED_INITIALIZER;
+- (void)cIDFunc;
+- (BOOL)socketDead;
+- (void)disconnectWithError:(NSError * _Nonnull)error;
+- (void)socketDidDisconnect:(GCDAsyncSocket * _Nonnull)sock withError:(NSError * _Nullable)err;
+- (void)writeData:(NSData * _Nonnull)d timeout:(double)timeout tag:(int64_t)tag;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didWriteDataWithTag:(NSInteger)tag;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didReadData:(NSData * _Nonnull)data withTag:(NSInteger)tag;
+- (void)start;
+- (void)readDataWithTimeout:(double)timeout length:(NSUInteger)length tag:(long)tag;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didConnectToHost:(NSString * _Nonnull)host port:(uint16_t)port;
+- (void)readDataToLength:(NSUInteger)length withTimeout:(NSTimeInterval)timeout tag:(NSInteger)tag;
+- (NSTimeInterval)socket:(GCDAsyncSocket * _Nonnull)sock shouldTimeoutReadWithTag:(NSInteger)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length;
+- (NSTimeInterval)socket:(GCDAsyncSocket * _Nonnull)sock shouldTimeoutWriteWithTag:(NSInteger)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length;
+@end
+
+
+SWIFT_PROTOCOL("_TtP16PacketTunnel_iOS17ConnectorDelegate_")
+@protocol ConnectorDelegate
+- (void)connector:(Connector * _Nonnull)connector didReadData:(NSData * _Nonnull)data withTag:(int64_t)tag;
+- (void)connectorDidDisconnect:(Connector * _Nonnull)connector withError:(NSError * _Nonnull)withError;
+- (void)connector:(Connector * _Nonnull)connector didWriteDataWithTag:(int64_t)tag;
+- (void)connectorDidSetupFailed:(Connector * _Nonnull)connector withError:(NSError * _Nonnull)withError;
+- (void)connectorDidBecomeAvailable:(Connector * _Nonnull)connector;
+- (NSTimeInterval)connector:(Connector * _Nonnull)connector shouldTimeoutReadWithTag:(NSInteger)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS9DNSPacket")
+@interface DNSPacket : NSObject
+@property (nonatomic) uint16_t identifier;
+@property (nonatomic, copy) NSArray * _Nonnull queryDomains;
+@property (nonatomic, copy) NSDictionary * _Nonnull answerDomains;
+@property (nonatomic, strong) NSData * _Nonnull rawData;
+@property (nonatomic) char qr;
+@property (nonatomic) uint16_t count;
+@property (nonatomic) uint16_t qType;
+@property (nonatomic) uint16_t qClass;
+@property (nonatomic) uint16_t reqCount;
+@property (nonatomic) uint16_t answerCount;
+@property (nonatomic, copy) NSArray * _Nonnull ipString;
+@property (nonatomic) BOOL finished;
+- (nonnull instancetype)initWithData:(NSData * _Nonnull)data OBJC_DESIGNATED_INITIALIZER;
++ (NSString * _Nonnull)findLabel:(uint8_t const * _Null_unspecified)ptr0;
++ (NSData * _Nonnull)genPacketData:(NSString * _Nonnull)ip domain:(NSString * _Nonnull)domain identifier:(uint16_t)identifier;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS15DirectConnector")
+@interface DirectConnector : Connector
+@property (nonatomic, copy) NSString * _Nullable interfaceName;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didReadData:(NSData * _Nonnull)data withTag:(NSInteger)tag;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didWriteDataWithTag:(NSInteger)tag;
+- (void)beginRead;
+- (void)socket:(GCDAsyncSocket * _Null_unspecified)sock didWritePartialDataOfLength:(NSUInteger)partialLength tag:(NSInteger)tag;
+- (void)socketDidCloseReadStream:(GCDAsyncSocket * _Null_unspecified)sock;
+- (void)socketDidDisconnect:(GCDAsyncSocket * _Nonnull)sock withError:(NSError * _Null_unspecified)err;
+- (void)start;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+- (nonnull instancetype)initWithPolicy:(NSString * _Nonnull)policy OBJC_DESIGNATED_INITIALIZER;
+@end
+
+@class NSNumber;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS14ProxyConnector")
+@interface ProxyConnector : Connector
+@property (nonatomic) BOOL tlsSupport;
+@property (nonatomic, readonly, copy) NSArray * _Nonnull acceptableCipherSuites;
+@property (nonatomic, copy) NSString * _Nonnull pFrontAddress;
+@property (nonatomic) uint16_t pFrontPort;
+- (void)startTLS;
+- (void)socket:(GCDAsyncSocket * _Null_unspecified)sock didReceiveTrust:(SecTrustRef _Null_unspecified)trust completionHandler:(void (^ _Null_unspecified)(BOOL))completionHandler;
+- (void)start;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didConnectToHost:(NSString * _Null_unspecified)host port:(uint16_t)port;
+@end
+
+@class NSMutableData;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS21HTTPAesProxyConnector")
+@interface HTTPAesProxyConnector : ProxyConnector
+@property (nonatomic, copy) NSString * _Nullable interfaceName;
+@property (nonatomic) BOOL httpConnected;
+@property (nonatomic, strong) NSMutableData * _Nonnull headerData;
+- (void)start;
+- (void)sendReq;
+- (NSInteger)recvHeaderData:(NSData * _Nonnull)data;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didReadData:(NSData * _Nonnull)data withTag:(NSInteger)tag;
+- (void)socket:(GCDAsyncSocket * _Null_unspecified)sock didConnectToHost:(NSString * _Null_unspecified)host port:(uint16_t)port;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didWriteDataWithTag:(NSInteger)tag;
+- (void)beginRead;
+- (void)socket:(GCDAsyncSocket * _Null_unspecified)sock didWritePartialDataOfLength:(NSUInteger)partialLength tag:(NSInteger)tag;
+- (void)socketDidCloseReadStream:(GCDAsyncSocket * _Null_unspecified)sock;
+- (void)writeData:(NSData * _Nonnull)d timeout:(double)timeout tag:(int64_t)tag;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS18HTTPProxyConnector")
+@interface HTTPProxyConnector : ProxyConnector
+@property (nonatomic) BOOL httpConnected;
+@property (nonatomic, strong) NSMutableData * _Nonnull headerData;
+- (void)start;
+- (void)sendReq;
+- (NSInteger)recvHeaderData:(NSData * _Nonnull)data;
+- (void)socketDidSecure:(GCDAsyncSocket * _Null_unspecified)sock;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didReadData:(NSData * _Nonnull)data withTag:(NSInteger)tag;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didConnectToHost:(NSString * _Null_unspecified)host port:(uint16_t)port;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didWriteDataWithTag:(NSInteger)tag;
+- (void)beginRead;
+- (void)socket:(GCDAsyncSocket * _Null_unspecified)sock didWritePartialDataOfLength:(NSUInteger)partialLength tag:(NSInteger)tag;
+- (void)socketDidCloseReadStream:(GCDAsyncSocket * _Null_unspecified)sock;
+- (void)writeData:(NSData * _Nonnull)d timeout:(double)timeout tag:(int64_t)tag;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS10IPv4Packet")
+@interface IPv4Packet : NSObject
+@property (nonatomic) uint8_t proto;
+@property (nonatomic, readonly, strong) NSData * _Nullable srcIP;
+@property (nonatomic, readonly, strong) NSData * _Nonnull _rawData;
+@property (nonatomic, readonly, strong) NSData * _Nullable destinationIP;
+@property (nonatomic) int32_t headerLength;
+@property (nonatomic, readonly) int32_t payloadLength;
+- (nonnull instancetype)initWithPacketData:(NSData * _Nonnull)PacketData OBJC_DESIGNATED_INITIALIZER;
+- (NSData * _Nonnull)payloadData;
+@property (nonatomic, readonly, copy) NSString * _Nonnull debugDescription;
+@end
+
+
+@interface NSData (SWIFT_EXTENSION(PacketTunnel_iOS))
+- (NSData * _Nonnull)hmacsha1:(NSData * _Nonnull)keyData;
+@end
+
+
+@interface NSData (SWIFT_EXTENSION(PacketTunnel_iOS))
+@property (nonatomic, readonly, strong) NSData * _Null_unspecified md5;
+@end
+
+
+@interface NSData (SWIFT_EXTENSION(PacketTunnel_iOS))
+@property (nonatomic, readonly, strong) NSData * _Nonnull md5x;
+@property (nonatomic, readonly, strong) NSData * _Nonnull sha1;
+@property (nonatomic, readonly, strong) NSData * _Nonnull sha224;
+@property (nonatomic, readonly, strong) NSData * _Nonnull sha256;
+@property (nonatomic, readonly, strong) NSData * _Nonnull sha384;
+@property (nonatomic, readonly, strong) NSData * _Nonnull sha512;
+@end
+
+
+@interface NSMutableData (SWIFT_EXTENSION(PacketTunnel_iOS))
+@end
+
+
+@interface NSNumber (SWIFT_EXTENSION(PacketTunnel_iOS))
+@property (nonatomic, readonly) BOOL isBool;
+@end
+
+
+@interface NSString (SWIFT_EXTENSION(PacketTunnel_iOS))
+- (uint64_t)fileSize;
+- (BOOL)fileExist;
+- (BOOL)dirCreate;
+- (BOOL)fileDelete;
+@end
+
+@class UDPPacket;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS17OutgoingConnector")
+@interface OutgoingConnector : NSObject
+@property (nonatomic, copy) NSString * _Nullable identifier;
+@property (nonatomic, strong) NSData * _Nullable clientAddress;
+@property (nonatomic, strong) NSData * _Nullable dstAddress;
+@property (nonatomic, strong) NSDate * _Nonnull activeTime;
+@property (nonatomic, readonly) NSTimeInterval idel;
+- (BOOL)idleTooLong;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+- (nonnull instancetype)initWithConnectionIdentifier:(NSString * _Nonnull)connectionIdentifier OBJC_DESIGNATED_INITIALIZER;
+- (void)addQueryWithPacket:(UDPPacket * _Null_unspecified)p;
+@end
+
+@class NWPath;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS20PacketTunnelProvider")
+@interface PacketTunnelProvider : NEPacketTunnelProvider
+@property (nonatomic, copy) NSString * _Nullable dnsServer;
+@property (nonatomic, copy) void (^ _Nullable pendingStartCompletion)(NSError * _Nullable);
+@property (nonatomic, readonly, strong) dispatch_queue_t _Nonnull tunQueue;
+@property (nonatomic, copy) void (^ _Nullable pendingStopCompletion)(void);
+@property (nonatomic, strong) NWPath * _Nullable lastPath;
+@property (nonatomic) NSInteger startTimes;
+@property (nonatomic, strong) NSDate * _Nonnull startDate;
+- (NSString * _Nullable)getPasswordWithPersistentReference:(NSData * _Nonnull)persistentReference;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+- (void)cancel;
+- (void)resume;
+- (void)startWithInterval:(double)interval;
+- (NSString * _Nonnull)ipString:(uint32_t)ip;
+- (void)prepareTunnelNetworkSettings:(BOOL)reset;
+- (void)vpnStartFinish;
+- (void)observeValueForKeyPath:(NSString * _Nullable)keyPath ofObject:(id _Nullable)object change:(NSDictionary * _Nullable)change context:(void * _Null_unspecified)context;
+- (void)networkchanged;
+- (void)writestart;
+- (void)loadConfig;
+- (void)startTunnelWithOptions:(NSDictionary * _Nullable)options completionHandler:(void (^ _Nonnull)(NSError * _Nullable))completionHandler;
+- (void)startHandlingPackets;
+- (void)handlePackets:(NSArray * _Nonnull)packets protocols:(NSArray * _Nonnull)protocols;
+
+/// Write packets and associated protocols to the UTUN interface.
+- (void)processPackets:(NSArray * _Nonnull)packets protocols:(NSArray * _Nonnull)protocols;
+- (void)stopABigT;
+- (void)stopTunnelWithReason:(NEProviderStopReason)reason completionHandler:(void (^ _Nonnull)(void))completionHandler;
+- (void)logStopReason:(NEProviderStopReason)reason;
+- (void)sleepWithCompletionHandler:(void (^ _Nonnull)(void))completionHandler;
+- (void)wake;
+
+/// Handle IPC messages from the app.
+- (void)handleAppMessage:(NSData * _Nonnull)messageData completionHandler:(void (^ _Nullable)(NSData * _Nullable))completionHandler;
+- (void)serverDidQuery:(OutgoingConnector * _Nonnull)targetTunnel data:(NSData * _Nonnull)data close:(BOOL)close;
+- (void)serverDidClose:(OutgoingConnector * _Nonnull)targetTunnel;
+- (void)writeDatagrams:(NSData * _Nonnull)packets proto:(int32_t)proto;
+@end
+
+
+@class NSNotificationCenter;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS12Reachability")
+@interface Reachability : NSObject
+@property (nonatomic, copy) void (^ _Nullable whenReachable)(Reachability * _Nonnull);
+@property (nonatomic, copy) void (^ _Nullable whenUnreachable)(Reachability * _Nonnull);
+@property (nonatomic) BOOL reachableOnWWAN;
+@property (nonatomic, strong) NSNotificationCenter * _Nonnull notificationCenter;
+@property (nonatomic, readonly, copy) NSString * _Nonnull currentReachabilityString;
+- (nonnull instancetype)initWithReachabilityRef:(SCNetworkReachabilityRef _Nonnull)reachabilityRef OBJC_DESIGNATED_INITIALIZER;
+- (nullable instancetype)initWithHostname:(NSString * _Nonnull)hostname error:(NSError * _Nullable * _Null_unspecified)error;
++ (Reachability * _Nullable)reachabilityForInternetConnectionAndReturnError:(NSError * _Nullable * _Null_unspecified)error;
++ (Reachability * _Nullable)reachabilityForLocalWiFiAndReturnError:(NSError * _Nullable * _Null_unspecified)error;
+- (BOOL)startNotifierAndReturnError:(NSError * _Nullable * _Null_unspecified)error;
+- (void)stopNotifier;
+- (BOOL)isReachable;
+- (BOOL)isReachableViaWWAN;
+- (BOOL)isReachableViaWiFi;
+- (BOOL)isConnectionOnTrafficOrDemand:(SCNetworkReachabilityFlags)flags;
+@property (nonatomic, readonly, copy) NSString * _Nonnull description;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS13TUNConnection")
+@interface TUNConnection : NSObject
+@property (nonatomic) BOOL forceSend;
+@property (nonatomic) BOOL closeSocketAfterRead;
+@end
+
+@class NSLock;
+@class SFTCPConnectionManager;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS12SFConnection")
+@interface SFConnection : TUNConnection
+@property (nonatomic) SFPcb _Null_unspecified pcb;
+@property (nonatomic, readonly, strong) NSLock * _Nonnull critLock;
+@property (nonatomic, weak) SFTCPConnectionManager * _Nullable manager;
+@property (nonatomic, strong) Connector * _Nullable connector;
+@property (nonatomic, copy) NSArray * _Nonnull bufArray;
+@property (nonatomic, strong) NSMutableData * _Nonnull socks_recv_bufArray;
+@property (nonatomic) NSInteger socks_sendout_length;
+@property (nonatomic) BOOL connectorReading;
+@property (nonatomic) BOOL pendingConnection;
+@property (nonatomic) int64_t tag;
+@property (nonatomic) NSInteger buf_used;
+@property (nonatomic) NSInteger rTag;
+@property (nonatomic, copy) NSString * _Nonnull cIDString;
+@property (nonatomic) int64_t sendingTag;
+@property (nonatomic) BOOL forceClose;
+- (NSInteger)sendBufferSize;
+- (nonnull instancetype)initWithTcp:(SFPcb _Null_unspecified)tcp host:(uint32_t)host port:(uint16_t)port m:(SFTCPConnectionManager * _Nonnull)m OBJC_DESIGNATED_INITIALIZER;
+- (void)cIDFunc;
+- (BOOL)shouldRemovDeadClient;
+- (void)showLog;
+- (dispatch_queue_t _Nonnull)socketQueue;
+- (dispatch_queue_t _Nonnull)delegateQueue;
+- (BOOL)genPolicy:(NSString * _Nonnull)dest useragent:(NSString * _Nonnull)useragent;
+- (void)findIPaddress;
+- (void)findIPAddress2;
+- (void)findIPRule:(NSString * _Nonnull)ip;
+- (void)checkStatus;
+- (void)configConnection;
+- (void)findProxy;
+- (void)configLwip;
+- (void)setUpConnector;
+- (void)connection:(NSTimeInterval)timeout;
+- (void)byebyeRequest;
+- (void)connector:(Connector * _Nonnull)connector didReadData:(NSData * _Nonnull)data withTag:(int64_t)tag;
+- (void)connectorDidDisconnect:(Connector * _Nonnull)connector withError:(NSError * _Nonnull)withError;
+- (void)connector:(Connector * _Nonnull)connector didWriteDataWithTag:(int64_t)_tag;
+- (NSTimeInterval)connector:(Connector * _Nonnull)connector shouldTimeoutReadWithTag:(NSInteger)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length;
+- (void)connectorDidSetupFailed:(Connector * _Nonnull)connector withError:(NSError * _Nonnull)withError;
+- (void)connectorDidBecomeAvailable:(Connector * _Nonnull)connector;
+- (void)client_tcp_output;
+- (void)client_tcp_received:(NSInteger)len;
+- (void)client_socks_recv_initiate;
+- (NSInteger)client_socks_recv_send_out;
+- (void)client_sent_func;
+- (void)client_socks_recv_handler_done:(NSInteger)len;
+- (void)client_socks_send_handler_done:(NSInteger)len;
+- (void)incomingData:(NSData * _Nonnull)d len:(NSInteger)len;
+- (void)client_free_socks;
+- (void)client_dealloc;
+- (void)client_send_to_socks;
+- (void)client_handle_freed_client;
+- (NSString * _Nonnull)pcbStatus;
+- (void)client_abort_client;
+- (void)client_free_client;
+- (void)close_lwip_pcb:(BOOL)abort;
+- (void)client_murder;
+@end
+
+@class GCDAsyncUdpSocket;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS14SFDNSForwarder")
+@interface SFDNSForwarder : OutgoingConnector
+@property (nonatomic, copy) NSArray * _Nonnull domains;
+@property (nonatomic, strong) DNSPacket * _Nullable packet;
+@property (nonatomic, strong) GCDAsyncUdpSocket * _Nullable socket;
+@property (nonatomic, copy) NSArray * _Nonnull queries;
+@property (nonatomic) uint16_t queryIDCounter;
+@property (nonatomic, copy) NSString * _Nonnull targetHost;
+@property (nonatomic, readonly) uint16_t targetPort;
+@property (nonatomic) BOOL connected;
+@property (nonatomic, strong) NSDate * _Nonnull startTime;
+@property (nonatomic, strong) NSMutableData * _Nullable cacheData;
+- (nonnull instancetype)initWithServer:(NSString * _Nonnull)server OBJC_DESIGNATED_INITIALIZER;
+- (BOOL)config;
+- (NSData * _Nonnull)buildHead;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+- (void)start;
+- (void)addQueryWithPacket:(UDPPacket * _Null_unspecified)udp;
+- (void)processQuery;
+- (void)udpSocket:(GCDAsyncUdpSocket * _Nonnull)sock didReceiveData:(NSData * _Nonnull)tempdata fromAddress:(NSData * _Nonnull)address withFilterContext:(id _Nullable)filterContext;
+- (void)writeDNSPacketData:(NSData * _Nonnull)data cache:(BOOL)cache;
+- (void)udpSocket:(GCDAsyncUdpSocket * _Nonnull)sock didNotConnect:(NSError * _Nonnull)error;
+- (void)udpSocket:(GCDAsyncUdpSocket * _Nonnull)sock didSendDataWithTag:(NSInteger)tag;
+- (void)udpSocketDidClose:(GCDAsyncUdpSocket * _Nonnull)sock withError:(NSError * _Nonnull)error;
+- (void)udpSocket:(GCDAsyncUdpSocket * _Nonnull)sock didNotSendDataWithTag:(NSInteger)tag dueToError:(NSError * _Nonnull)error;
+- (void)shutdownSocket;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS13SFHTTPRequest")
+@interface SFHTTPRequest : SFConnection
+@property (nonatomic, strong) NSMutableData * _Nonnull headerData;
+- (nonnull instancetype)initWithTcp:(SFPcb _Null_unspecified)tcp host:(uint32_t)host port:(uint16_t)port m:(SFTCPConnectionManager * _Nonnull)m OBJC_DESIGNATED_INITIALIZER;
+- (void)processData:(NSString * _Nonnull)reason;
+- (BOOL)httpArgu;
+- (void)configConnector;
+- (void)setUpConnector;
+- (void)connector:(Connector * _Nonnull)connector didWriteDataWithTag:(int64_t)_tag;
+- (void)sendCONNECTResponse;
+- (BOOL)sendFakeCONNECTResponse;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS16SFHTTPConnection")
+@interface SFHTTPConnection : SFHTTPRequest
+@property (nonatomic) NSInteger requestIndex;
+@property (nonatomic, strong) NSMutableData * _Nonnull recvHeaderData;
+@property (nonatomic) NSUInteger currentBodyLength;
+@property (nonatomic) NSUInteger totalRecvLength;
+@property (nonatomic) NSUInteger currentBobyReadLength;
+@property (nonatomic, readonly, copy) NSString * _Nonnull statusString;
+- (void)configLwip;
+- (void)incomingData:(NSData * _Nonnull)d len:(NSInteger)len;
+- (void)connect;
+- (void)processData:(NSString * _Nonnull)reason;
+- (void)client_send_to_socks;
+- (void)connector:(Connector * _Nonnull)connector didReadData:(NSData * _Nonnull)data withTag:(int64_t)tag;
+- (void)connector:(Connector * _Nonnull)connector didWriteDataWithTag:(int64_t)_tag;
+- (void)client_socks_recv_initiate;
+- (void)showLog;
+- (void)checkStatus;
+- (nonnull instancetype)initWithTcp:(SFPcb _Null_unspecified)tcp host:(uint32_t)host port:(uint16_t)port m:(SFTCPConnectionManager * _Nonnull)m OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS17SFHTTPSConnection")
+@interface SFHTTPSConnection : SFHTTPRequest
+- (void)configLwip;
+- (void)incomingData:(NSData * _Nonnull)d len:(NSInteger)len;
+- (void)connect;
+- (void)processData:(NSString * _Nonnull)reason;
+- (void)client_send_to_socks;
+- (void)connector:(Connector * _Nonnull)connector didReadData:(NSData * _Nonnull)data withTag:(int64_t)tag;
+- (nonnull instancetype)initWithTcp:(SFPcb _Null_unspecified)tcp host:(uint32_t)host port:(uint16_t)port m:(SFTCPConnectionManager * _Nonnull)m OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS25SFNetworkInterfaceManager")
+@interface SFNetworkInterfaceManager : NSObject
+@property (nonatomic, copy) NSString * _Nonnull defaultIPAddress;
+@property (nonatomic, copy) NSString * _Nonnull WiFiIPAddress;
+@property (nonatomic, copy) NSString * _Nonnull WWANIPAddress;
++ (SFNetworkInterfaceManager * _Nonnull)instances;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+- (void)updateIPAddress;
+- (void)showRouter;
+- (NSInteger)interfaceMTUWithName:(NSString * _Nonnull)name;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS15SFTCPConnection")
+@interface SFTCPConnection : SFConnection
+@property (nonatomic, strong) NSMutableData * _Nonnull headerData;
+- (nonnull instancetype)initWithTcp:(SFPcb _Null_unspecified)tcp host:(uint32_t)host port:(uint16_t)port m:(SFTCPConnectionManager * _Nonnull)m OBJC_DESIGNATED_INITIALIZER;
+- (void)configLwip;
+- (void)configConnection;
+- (void)setUpConnector;
+- (void)incomingData:(NSData * _Nonnull)d len:(NSInteger)len;
+- (void)processData:(NSString * _Nonnull)reason;
+- (void)client_send_to_socks;
+- (void)connector:(Connector * _Nonnull)connector didWriteDataWithTag:(int64_t)_tag;
+- (void)connector:(Connector * _Nonnull)connector didReadData:(NSData * _Nonnull)data withTag:(int64_t)tag;
+@end
+
+@class SFUDPConnection;
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS22SFTCPConnectionManager")
+@interface SFTCPConnectionManager : NSObject
++ (SFTCPConnectionManager * _Nonnull)manager;
++ (SFTCPConnectionManager * _Nonnull)shared;
+@property (nonatomic, strong) dispatch_queue_t _Nonnull dispatchQueue;
+@property (nonatomic, strong) dispatch_queue_t _Nonnull socketQueue;
+@property (nonatomic) dispatch_source_memorypressure_flags_t memoryWarninglevel;
+@property (nonatomic, strong) NSDate * _Nonnull lastMemeoryWarningDate;
+@property (nonatomic, weak) PacketTunnelProvider * _Nullable provider;
+@property (nonatomic, copy) NSArray * _Nonnull udp_connections;
+@property (nonatomic) BOOL tcpOperating;
+@property (nonatomic) BOOL lwip_init_finished;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+- (void)start;
+- (void)checkConnectionStatus;
+- (void)closeAllConnection;
+- (void)setMTU:(NSInteger)mtu;
+- (void)saveConnectionInfo:(SFConnection * _Nonnull)ref;
+- (void)removeConnectionRef:(SFConnection * _Nonnull)ref;
+- (void)writeDatagrams:(NSData * _Nonnull)data;
+@end
+
+
+@interface SFTCPConnectionManager (SWIFT_EXTENSION(PacketTunnel_iOS))
+- (void)startProxyServer;
+@end
+
+
+@interface SFTCPConnectionManager (SWIFT_EXTENSION(PacketTunnel_iOS))
+- (void)configUDP;
+- (void)addUDPConnection:(SFUDPConnection * _Nonnull)c;
+- (void)deleteUDP:(SFUDPConnection * _Nonnull)c;
+- (void)incomingUDP:(SFUPcb _Null_unspecified)udp;
+@end
+
+@class NSTimer;
+
+@interface SFTCPConnectionManager (SWIFT_EXTENSION(PacketTunnel_iOS))
+- (void)installMemoryWarning;
+- (void)recvMemoryWarning:(dispatch_source_memorypressure_flags_t)level;
+- (void)cleanMemory;
+- (void)incomingTCP:(SFPcb _Null_unspecified)tcp;
+- (void)tcp_timer_handler:(NSTimer * _Nonnull)t;
+- (void)cleanConnection;
+- (void)cancel;
+- (void)resume;
+- (void)startWithInterval:(double)interval;
+- (void)device_read_handler_sendPackets3:(void const * _Null_unspecified)unused packets:(NSArray * _Nonnull)packets complete:(void (^ _Nonnull)(NSError * _Nullable))complete;
+- (void)device_read_handler_sendPackets:(void const * _Null_unspecified)unused packets:(NSArray * _Nonnull)packets;
+- (void)clearRule;
+- (void)device_read_handler_send:(void const * _Null_unspecified)unused data:(NSData * _Nonnull)data len:(NSInteger)len sport:(uint16_t)sport;
+- (NSData * _Nonnull)recentRequestData;
+- (NSData * _Nonnull)ruleResultData;
+- (void)test;
+- (BOOL)shouldReadPacket;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS15SFUDPConnection")
+@interface SFUDPConnection : TUNConnection
+@property (nonatomic) SFUPcb _Null_unspecified pcb;
+- (nonnull instancetype)initWithP:(SFUPcb _Null_unspecified)p host:(uint32_t)host port:(uint16_t)port OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS14SFUDPConnector")
+@interface SFUDPConnector : NSObject
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS20SFUDPDirectConnector")
+@interface SFUDPDirectConnector : SFUDPConnector
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS19SFUDPProxyConnector")
+@interface SFUDPProxyConnector : SFUDPConnector
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS12SFVPNSession")
+@interface SFVPNSession : NSObject
++ (SFVPNSession * _Nonnull)session;
+@property (nonatomic, strong) NSDate * _Nonnull startTime;
+@property (nonatomic, strong) NSDate * _Nonnull endTime;
+- (nonnull instancetype)initWithPath:(NSString * _Nonnull)path OBJC_DESIGNATED_INITIALIZER;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+- (NSString * _Nonnull)idenString;
+@end
+
+
+SWIFT_PROTOCOL("_TtP16PacketTunnel_iOS14SocketDelegate_")
+@protocol SocketDelegate
+- (void)connector:(Connector * _Nonnull)connector didReadData:(NSData * _Nonnull)data withTag:(int64_t)tag;
+- (void)connectorDidDisconnect:(Connector * _Nonnull)connector withError:(NSError * _Nonnull)withError;
+- (void)connector:(Connector * _Nonnull)connector didWriteDataWithTag:(int64_t)tag;
+- (void)connectorDidSetupFailed:(Connector * _Nonnull)connector withError:(NSError * _Nonnull)withError;
+- (void)connectorDidBecomeAvailable:(Connector * _Nonnull)connector;
+- (NSTimeInterval)connector:(Connector * _Nonnull)connector shouldTimeoutReadWithTag:(NSInteger)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS15Socks5Connector")
+@interface Socks5Connector : ProxyConnector
+@property (nonatomic, copy) NSString * _Nullable host;
+@property (nonatomic) uint16_t port;
+@property (nonatomic, strong) NSMutableData * _Nullable recvBuffer;
+- (void)sendAuth;
+- (void)sendUserAndPassword;
+- (void)sendBind;
+- (void)socket:(GCDAsyncSocket * _Null_unspecified)sock didConnectToHost:(NSString * _Null_unspecified)host port:(uint16_t)port;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didReadData:(NSData * _Nonnull)data withTag:(NSInteger)tag;
+- (void)sock5connected;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didWriteDataWithTag:(NSInteger)tag;
+- (void)socketDidCloseReadStream:(GCDAsyncSocket * _Null_unspecified)sock;
+- (void)start;
+- (void)writeData:(NSData * _Nonnull)d timemout:(double)timemout tag:(long)tag;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS9TCPPacket")
+@interface TCPPacket : NSObject
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS14TCPSSConnector")
+@interface TCPSSConnector : ProxyConnector
+@property (nonatomic) BOOL ota;
+@property (nonatomic) BOOL headSent;
+- (BOOL)config;
+- (NSData * _Nonnull)buildHead;
+- (void)socket:(GCDAsyncSocket * _Null_unspecified)sock didConnectToHost:(NSString * _Null_unspecified)host port:(uint16_t)port;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didReadData:(NSData * _Nonnull)data withTag:(NSInteger)tag;
+- (void)socket:(GCDAsyncSocket * _Nonnull)sock didWriteDataWithTag:(NSInteger)tag;
+- (void)beginRead;
+- (void)socket:(GCDAsyncSocket * _Null_unspecified)sock didWritePartialDataOfLength:(NSUInteger)partialLength tag:(NSInteger)tag;
+- (void)socketDidCloseReadStream:(GCDAsyncSocket * _Null_unspecified)sock;
+- (void)start;
+- (void)writeData:(NSData * _Nonnull)d timeout:(double)timeout tag:(int64_t)tag;
+@end
+
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS9UDPPacket")
+@interface UDPPacket : NSObject
+@property (nonatomic) uint16_t sourcePort;
+@property (nonatomic) uint16_t destinationPort;
+@property (nonatomic, strong) NSData * _Nullable _rawData;
+- (nonnull instancetype)initWithPacketData:(NSData * _Nonnull)PacketData OBJC_DESIGNATED_INITIALIZER;
+- (NSData * _Nonnull)payloadData;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS10UDPRelayer")
+@interface UDPRelayer : OutgoingConnector
+@property (nonatomic, copy) NSArray * _Nonnull domains;
+@property (nonatomic, strong) DNSPacket * _Nullable packet;
+@property (nonatomic, strong) GCDAsyncUdpSocket * _Nullable socket;
+@property (nonatomic, copy) NSArray * _Nonnull queries;
+@property (nonatomic) uint16_t queryIDCounter;
+@property (nonatomic, copy) NSString * _Nonnull targetHost;
+@property (nonatomic) uint16_t targetPort;
+@property (nonatomic) BOOL connected;
+@property (nonatomic, strong) NSMutableData * _Nullable cacheData;
+- (BOOL)setupSS;
+- (BOOL)config;
+- (NSData * _Nonnull)buildHead;
+- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
+- (void)start;
+- (void)addQueryWithPacket:(UDPPacket * _Null_unspecified)udp;
+- (void)processQuery;
+- (void)udpSocket:(GCDAsyncUdpSocket * _Null_unspecified)sock didReceiveData:(NSData * _Null_unspecified)tempdata fromAddress:(NSData * _Null_unspecified)address withFilterContext:(id _Null_unspecified)filterContext;
+- (void)writeDNSPacketData:(NSData * _Nonnull)data;
+- (void)udpSocket:(GCDAsyncUdpSocket * _Nonnull)sock didNotConnect:(NSError * _Nonnull)error;
+- (void)udpSocket:(GCDAsyncUdpSocket * _Nonnull)sock didSendDataWithTag:(NSInteger)tag;
+- (void)udpSocketDidClose:(GCDAsyncUdpSocket * _Nonnull)sock withError:(NSError * _Nonnull)error;
+- (void)udpSocket:(GCDAsyncUdpSocket * _Null_unspecified)sock didNotSendDataWithTag:(NSInteger)tag dueToError:(NSError * _Null_unspecified)error;
+- (void)shutdownSocket;
+@end
+
+
+SWIFT_CLASS("_TtC16PacketTunnel_iOS14VmessConnector")
+@interface VmessConnector : ProxyConnector
+- (BOOL)config;
+- (void)writeData:(NSData * _Nonnull)d timeout:(double)timeout tag:(int64_t)tag;
+- (void)socket:(GCDAsyncSocket * _Null_unspecified)sock didReadData:(NSData * _Null_unspecified)data withTag:(NSInteger)tag;
+@end
+
+#pragma clang diagnostic pop
diff --git a/PacketTunnel/iOS/PacketTunnel-iOS.xcconfig b/PacketTunnel/iOS/PacketTunnel-iOS.xcconfig
new file mode 100644
index 0000000..69b3799
--- /dev/null
+++ b/PacketTunnel/iOS/PacketTunnel-iOS.xcconfig
@@ -0,0 +1,22 @@
+//
+// PacketTunnel-iOS.xcconfig
+// Surf
+//
+// Created by abigt on 16/1/12.
+// Copyright © 2016年 abigt. All rights reserved.
+//
+
+HEADER_SEARCH_PATHS = $(inherited) "$(SRCROOT)/share/include" "$(SRCROOT)/Shared/header" "$(SRCROOT)/MMDB" "$(SRCROOT)/shared/lwip/badvpn"
+USER_HEADER_SEARCH_PATHS = $(inherited) "$(SRCROOT)/Shared/header" "$(SRCROOT)/Shared/lwip/src/include/"**
+OTHER_CFLAGS = $(inherited) -isystem -I "$(PROJECT_DIR)/iosLib"
+OTHER_LDFLAGS = $(inherited) -framework Crashlytics -framework Fabric//-lsodium //-mbedcrypto//lcrypto // - //mbedcrypto
+
+SSL_LIB_DEFINE = TCP_MSS=1460//USE_CRYPTO_MBEDTLS=1
+
+
+//OTHER_LDFLAGS = $(inherited) -framework Crypto -framework Sodium -framework IDZSwiftCommonCrypto -framework CocoaAsyncSocket -framework SwiftyJSON -framework MMDB -weak_framework kcp -framework XSocket -framework ObjectMapper -framework Xcon -framework CommonCrypto -framework AxLogger
+FRAMEWORK_SEARCH_PATHS = $(inherited) "$(PROJECT_DIR)/iosLib" "$(PROJECT_DIR)/Carthage/Build/iOS/"
+LIBRARY_SEARCH_PATHS = $(inherited) "$(PROJECT_DIR)/iosLib" "$(PROJECT_DIR)/Carthage/Build/iOS/"
+
+//USE_CRYPTO_OPENSSL USE_CRYPTO_MBEDTLS
+//USE_CRYPTO_MBEDTLS=1
diff --git a/PacketTunnel/iOS/PacketTunnel.entitlements b/PacketTunnel/iOS/PacketTunnel.entitlements
new file mode 100644
index 0000000..96286b5
--- /dev/null
+++ b/PacketTunnel/iOS/PacketTunnel.entitlements
@@ -0,0 +1,20 @@
+
+
+
+
+ com.apple.developer.networking.networkextension
+
+ app-proxy-provider
+ content-filter-provider
+ packet-tunnel-provider
+
+ com.apple.developer.networking.vpn.api
+
+ allow-vpn
+
+ com.apple.security.application-groups
+
+ group.com.abigt.Surf
+
+
+
diff --git a/PacketTunnel/socks5.js b/PacketTunnel/socks5.js
new file mode 100644
index 0000000..3c60aae
--- /dev/null
+++ b/PacketTunnel/socks5.js
@@ -0,0 +1,5 @@
+var tunnel = "SOCKS5 240.7.1.10:10082; ";//SOCKS 127.0.0.1:1080; DIRECT;
+var direct = "DIRECT";
+function FindProxyForURL(url, host) {
+ return tunnel
+}
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..6d35ba5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,24 @@
+# Surf project memo #
+
+这是一个利用Network extension framework 的项目
+
+### 使用技术 ###
+
+* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
+
+### target 包含说明 ###
+* ...
+* ...
+* ...
+* Deployment instructions
+
+### Contribution guidelines ###
+
+*
+
+
+### Who do I talk to? ###
+
+*none
+### todo list ####
+....
diff --git a/Shared/header/SFUtil.h b/Shared/header/SFUtil.h
new file mode 100644
index 0000000..1722907
--- /dev/null
+++ b/Shared/header/SFUtil.h
@@ -0,0 +1,12 @@
+//
+// SFUtil.h
+// Surf
+//
+// Created by yarshure on 15/12/25.
+// Copyright © 2015年 yarshure. All rights reserved.
+//
+
+#ifndef SFUtil_h
+#define SFUtil_h
+
+#endif /* SFUtil_h */
diff --git a/Shared/lwip/CHANGELOG b/Shared/lwip/CHANGELOG
new file mode 100644
index 0000000..685b568
--- /dev/null
+++ b/Shared/lwip/CHANGELOG
@@ -0,0 +1,3396 @@
+HISTORY
+
+(CVS HEAD)
+
+ * [Enter new changes just after this line - do not remove this line]
+
+ ++ New features:
+
+ 2012-03-25: Simon Goldschmidt (idea by Mason)
+ * posix/*: added posix-compatibility include files posix/netdb.h and posix/sys/socket.h
+ which are a simple wrapper to the correct lwIP include files.
+
+ 2012-01-16: Simon Goldschmidt
+ * opt.h, icmp.c: Added option CHECKSUM_GEN_ICMP
+
+ 2011-12-17: Simon Goldschmidt
+ * ip.h: implemented API functions to access so_options of IP pcbs (UDP, TCP, RAW)
+ (fixes bug #35061)
+
+ 2011-09-27: Simon Goldschmidt
+ * opt.h, tcp.c, tcp_in.c: Implemented limiting data on ooseq queue (task #9989)
+ (define TCP_OOSEQ_MAX_BYTES / TCP_OOSEQ_MAX_PBUFS in lwipopts.h)
+
+ 2011-09-21: Simon Goldschmidt
+ * opt.h, api.h, api_lib.c, api_msg.h/.c, sockets.c: Implemented timeout on
+ send (TCP only, bug #33820)
+
+ 2011-09-21: Simon Goldschmidt
+ * init.c: Converted runtime-sanity-checks into compile-time checks that can
+ be disabled (since runtime checks can often not be seen on embedded targets)
+
+ 2011-09-11: Simon Goldschmidt
+ * ppp.h, ppp_impl.h: splitted ppp.h to an internal and external header file
+ to get a clear separation of which functions an application or port may use
+ (task #11281)
+
+ 2011-09-11: Simon Goldschmidt
+ * opt.h, tcp_impl.h, tcp.c, udp.h/.c: Added a config option to randomize
+ initial local TCP/UDP ports (so that different port ranges are used after
+ a reboot; bug #33818; this one added tcp_init/udp_init functions again)
+
+ 2011-09-03: Simon Goldschmidt
+ * dhcp.c: DHCP uses LWIP_RAND() for xid's (bug #30302)
+
+ 2011-08-24: Simon Goldschmidt
+ * opt.h, netif.h/.c: added netif remove callback (bug #32397)
+
+ 2011-07-26: Simon Goldschmidt
+ * etharp.c: ETHARP_SUPPORT_VLAN: add support for an external VLAN filter
+ function instead of only checking for one VLAN (define ETHARP_VLAN_CHECK_FN)
+
+ 2011-07-21: Simon Goldschmidt (patch by hanhui)
+ * ip4.c, etharp.c, pbuf.h: bug #33634 ip_forward() have a faulty behaviour:
+ Added pbuf flags to mark incoming packets as link-layer broadcast/multicast.
+ Also added code to allow ip_forward() to forward non-broadcast packets to
+ the input netif (set IP_FORWARD_ALLOW_TX_ON_RX_NETIF==1).
+
+ 2011-07-21: Simon Goldschmidt
+ * sockets.c, opt.h: (bug #30185): added LWIP_FIONREAD_LINUXMODE that makes
+ ioctl/FIONREAD return the size of the next pending datagram.
+
+ 2011-06-26: Simon Goldschmidt (patch by Cameron Gutman)
+ * tcp.c, tcp_out.c: bug #33604: added some more asserts to check that
+ pcb->state != LISTEN
+
+ 2011-05-25: Simon Goldschmidt
+ * again nearly the whole stack, renamed ip.c to ip4.c, ip_addr.c to ip4_addr.c,
+ combined ipv4/ipv6 inet_chksum.c, added ip.h, ip_addr.h: Combined IPv4
+ and IPv6 code where possible, added defines to access IPv4/IPv6 in non-IP
+ code so that the code is more readable.
+
+ 2011-05-17: Patch by Ivan Delamer (only checked in by Simon Goldschmidt)
+ * nearly the whole stack: Finally, we got decent IPv6 support, big thanks to
+ Ivan! (this is work in progress: we're just post release anyway :-)
+
+ 2011-05-14: Simon Goldschmidt (patch by Stphane Lesage)
+ * tcpip.c/.h: patch #7449 allow tcpip callback from interrupt with static
+ memory message
+
+
+ ++ Bugfixes:
+
+ 2013-01-15: Simon Goldschmidt
+ * ip4.c: fixed bug #37665 ip_canforward operates on address in wrong byte order
+
+ 2013-01-15: Simon Goldschmidt
+ * pbuf.h: fixed bug #38097 pbuf_free_ooseq() warning
+
+ 2013-01-14: Simon Goldschmidt
+ * dns.c: fixed bug #37705 Possible memory corruption in DNS query
+
+ 2013-01-11: Simon Goldschmidt
+ * raw.c: fixed bug #38066 Raw pcbs can alter packet without eating it
+
+ 2012-09-26: Simon Goldschmidt
+ * api_msg.c: fixed bug #37405 'err_tcp()' uses already freed 'netconn' object
+
+ 2012-09-26: patch by Henrik Persson
+ * dhcp.c: patch #7843 Fix corner case with dhcp timeouts
+
+ 2012-09-26: patch by Henrik Persson
+ * dhcp.c: patch #7840 Segfault in dhcp_parse_reply if no end marker in dhcp packet
+
+ 2012-08-22: Simon Goldschmidt
+ * memp.c: fixed bug #37166: memp_sanity check loops itself
+
+ 2012-08-13: Simon Goldschmidt
+ * dhcp.c: fixed bug #36645: Calling dhcp_release before dhcp_start
+ dereferences NULL
+
+ 2012-08-13: Simon Goldschmidt
+ * msg_out.c: fixed bug #36840 snmp_send_trap() NULL de-reference if traps
+ configured but no interfaces available
+
+ 2012-08-13: Simon Goldschmidt
+ * dns.c: fixed bug #36899 DNS TTL 0 is cached for a long time
+
+ 2012-05-11: Simon Goldschmidt (patch by Marty)
+ * memp.c: fixed bug #36412: memp.c does not compile when
+ MEMP_OVERFLOW_CHECK > zero and MEMP_SEPARATE_POOLS == 1
+
+ 2012-05-08: Simon Goldschmidt
+ * tcp_out.c: fixed bug #36380: unsent_oversize mismatch in 1.4.1RC1 (this was
+ a debug-check issue only)
+
+ 2012-05-03: Simon Goldschmidt (patch by Sylvain Rochet)
+ * ppp.c: fixed bug #36283 (PPP struct used on header size computation and
+ not packed)
+
+ 2012-05-03: Simon Goldschmidt (patch by David Empson)
+ * ppp.c: fixed bug #36388 (PPP: checksum-only in last pbuf leads to pbuf with
+ zero length)
+
+ 2012-03-27: Simon Goldschmidt
+ * vj.c: fixed bug #35756 header length calculation problem in ppp/vj.c
+
+ 2012-03-27: Simon Goldschmidt (patch by Mason)
+ * tcp_out.c: fixed bug #35945: SYN packet should provide the recv MSS not the
+ send MSS
+
+ 2012-03-25: Simon Goldschmidt
+ * api_msg.c: Fixed bug #35817: do_connect() invalidly signals op_completed
+ for UDP/RAW with LWIP_TCPIP_CORE_LOCKING==1
+
+ 2012-03-25: Simon Goldschmidt
+ * api_msg.h, api_lib.c, api_msg.c, netifapi.c: fixed bug #35931: Name space
+ pollution in api_msg.c and netifapi.c
+
+ 2012-03-22: Simon Goldschmidt
+ * ip4.c: fixed bug #35927: missing refragmentaion in ip_forward
+
+ 2012-03-20: Simon Goldschmidt (patch by Mason)
+ * netdb.c: fixed bug #35907: lwip_gethostbyname_r returns an invalid h_addr_list
+
+ 2012-03-12: Simon Goldschmidt (patch by Bostjan Meglic)
+ * ppp.c: fixed bug #35809: PPP GetMask(): Compiler warning on big endian,
+ possible bug on little endian system
+
+ 2012-02-23: Simon Goldschmidt
+ * etharp.c: fixed bug #35595: Impossible to send broadcast without a gateway
+ (introduced when fixing bug# 33551)
+
+ 2012-02-16: Simon Goldschmidt
+ * ppp.c: fixed pbuf leak when PPP session is aborted through pppSigHUP()
+ (bug #35541: PPP Memory Leak)
+
+ 2012-02-16: Simon Goldschmidt
+ * etharp.c: fixed bug #35531: Impossible to send multicast without a gateway
+ (introduced when fixing bug# 33551)
+
+ 2012-02-16: Simon Goldschmidt (patch by Stphane Lesage)
+ * msg_in.c, msg_out.c: fixed bug #35536 SNMP: error too big response is malformed
+
+ 2012-02-15: Simon Goldschmidt
+ * init.c: fixed bug #35537: MEMP_NUM_* sanity checks should be disabled with
+ MEMP_MEM_MALLOC==1
+
+ 2012-02-12: Simon Goldschmidt
+ * tcp.h, tcp_in.c, tcp_out.c: partly fixed bug #25882: TCP hangs on
+ MSS > pcb->snd_wnd (by not creating segments bigger than half the window)
+
+ 2012-02-11: Simon Goldschmidt
+ * tcp.c: fixed bug #35435: No pcb state check before adding it to time-wait
+ queue while closing
+
+ 2012-01-22: Simon Goldschmidt
+ * tcp.c, tcp_in.c: fixed bug #35305: pcb may be freed too early on shutdown(WR)
+
+ 2012-01-21: Simon Goldschmidt
+ * tcp.c: fixed bug #34636: FIN_WAIT_2 - Incorrect shutdown of TCP pcb
+
+ 2012-01-20: Simon Goldschmidt
+ * dhcp.c: fixed bug #35151: DHCP asserts on incoming option lengths
+
+ 2012-01-20: Simon Goldschmidt
+ * pbuf.c: fixed bug #35291: NULL pointer in pbuf_copy
+
+ 2011-11-25: Simon Goldschmidt
+ * tcp.h/.c, tcp_impl.h, tcp_in.c: fixed bug #31177: tcp timers can corrupt
+ tcp_active_pcbs in some cases
+
+ 2011-11-23: Simon Goldschmidt
+ * sys.c: fixed bug #34884: sys_msleep() body needs to be surrounded with
+ '#ifndef sys_msleep'
+
+ 2011-11-22: Simon Goldschmidt
+ * netif.c, etharp.h/.c: fixed bug #34684: Clear the arp table cache when
+ netif is brought down
+
+ 2011-10-28: Simon Goldschmidt
+ * tcp_in.c: fixed bug #34638: Dead code in tcp_receive - pcb->dupacks
+
+ 2011-10-23: Simon Goldschmidt
+ * mem.c: fixed bug #34429: possible memory corruption with
+ LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT set to 1
+
+ 2011-10-18: Simon Goldschmidt
+ * arch.h, netdb.c: fixed bug #34592: lwip_gethostbyname_r uses nonstandard
+ error value
+
+ 2011-10-18: Simon Goldschmidt
+ * opt.h: fixed default values of TCP_SNDLOWAT and TCP_SNDQUEUELOWAT for small
+ windows (bug #34176 select after non-blocking send times out)
+
+ 2011-10-18: Simon Goldschmidt
+ * tcp_impl.h, tcp_out.c: fixed bug #34587: TCP_BUILD_MSS_OPTION doesn't
+ consider netif->mtu, causes slow network
+
+ 2011-10-18: Simon Goldschmidt
+ * sockets.c: fixed bug #34581 missing parentheses in udplite sockets code
+
+ 2011-10-18: Simon Goldschmidt
+ * sockets.h: fixed bug #34580 fcntl() is missing in LWIP_COMPAT_SOCKETS
+
+ 2011-10-17: Simon Goldschmidt
+ * api_msg.c: fixed bug #34569: shutdown(SHUT_WR) crashes netconn/socket api
+
+ 2011-10-13: Simon Goldschmidt
+ * tcp_in.c, tcp_out.c: fixed bug #34517 (persist timer is started although no
+ zero window is received) by starting the persist timer when a zero window is
+ received, not when we have more data queued for sending than fits into the
+ window
+
+ 2011-10-13: Simon Goldschmidt
+ * def.h, timers.c: fixed bug #34541: LWIP_U32_DIFF is unnecessarily complex
+
+ 2011-10-13: Simon Goldschmidt
+ * sockets.c, api_lib.c: fixed bug #34540: compiler error when CORE_LOCKING is
+ used and not all protocols are enabled
+
+ 2011-10-12: Simon Goldschmidt
+ * pbuf.c: fixed bug #34534: Error in sending fragmented IP if MEM_ALIGNMENT > 4
+
+ 2011-10-09: Simon Goldschmidt
+ * tcp_out.c: fixed bug #34426: tcp_zero_window_probe() transmits incorrect
+ byte value when pcb->unacked != NULL
+
+ 2011-10-09: Simon Goldschmidt
+ * ip4.c: fixed bug #34447 LWIP_IP_ACCEPT_UDP_PORT(dst_port) wrong
+
+ 2011-09-27: Simon Goldschmidt
+ * tcp_in.c, tcp_out.c: Reset pcb->unsent_oversize in 2 more places...
+
+ 2011-09-27: Simon Goldschmidt
+ * tcp_in.c: fixed bug #28288: Data after FIN in oos queue
+
+ 2011-09-27: Simon Goldschmidt
+ * dhcp.c: fixed bug #34406 dhcp_option_hostname() can overflow the pbuf
+
+ 2011-09-24: Simon Goldschmidt
+ * mem.h: fixed bug #34377 MEM_SIZE_F is not defined if MEM_LIBC_MALLOC==1
+
+ 2011-09-23: Simon Goldschmidt
+ * pbuf.h, tcp.c, tcp_in.c: fixed bug #33871: rejecting TCP_EVENT_RECV() for
+ the last packet including FIN can lose data
+
+ 2011-09-22: Simon Goldschmidt
+ * tcp_impl.h: fixed bug #34355: nagle does not take snd_buf/snd_queuelen into
+ account
+
+ 2011-09-21: Simon Goldschmidt
+ * opt.h: fixed default value of TCP_SND_BUF to not violate the sanity checks
+ in init.c
+
+ 2011-09-20: Simon Goldschmidt
+ * timers.c: fixed bug #34337 (possible NULL pointer in sys_check_timeouts)
+
+ 2011-09-11: Simon Goldschmidt
+ * tcp_out.c: use pcb->mss instead of TCP_MSS for preallocate mss-sized pbufs
+ (bug #34019)
+
+ 2011-09-09: Simon Goldschmidt
+ * udp.c: fixed bug #34072: UDP broadcast is received from wrong UDP pcb if
+ udp port matches
+
+ 2011-09-03: Simon Goldschmidt
+ * tcp_in.c: fixed bug #33952 PUSH flag in incoming packet is lost when packet
+ is aggregated and sent to application
+
+ 2011-09-01: Simon Goldschmidt
+ * opt.h: fixed bug #31809 LWIP_EVENT_API in opts.h is inconsistent compared
+ to other options
+
+ 2011-09-01: Simon Goldschmidt
+ * tcp_in.c: fixed bug #34111 RST for ACK to listening pcb has wrong seqno
+
+ 2011-08-24: Simon Goldschmidt
+ * inet6.h: fixed bug #34124 struct in6_addr does not conform to the standard
+
+ 2011-08-24: Simon Goldschmidt
+ * api_msg.c, sockets.c: fixed bug #33956 Wrong error returned when calling
+ accept() on UDP connections
+
+ 2011-08-24: Simon Goldschmidt
+ * sockets.h: fixed bug #34057 socklen_t should be a typedef
+
+ 2011-08-24: Simon Goldschmidt
+ * pbuf.c: fixed bug #34112 Odd check in pbuf_alloced_custom (typo)
+
+ 2011-08-24: Simon Goldschmidt
+ * dhcp.c: fixed bug #34122 dhcp: hostname can overflow
+
+ 2011-08-24: Simon Goldschmidt
+ * netif.c: fixed bug #34121 netif_add/netif_set_ipaddr fail on NULL ipaddr
+
+ 2011-08-22: Simon Goldschmidt
+ * tcp_out.c: fixed bug #33962 TF_FIN not always set after FIN is sent. (This
+ merely prevents nagle from not transmitting fast after closing.)
+
+ 2011-07-22: Simon Goldschmidt
+ * api_lib.c, api_msg.c, sockets.c, api.h: fixed bug #31084 (socket API returns
+ always EMSGSIZE on non-blocking sockets if data size > send buffers) -> now
+ lwip_send() sends as much as possible for non-blocking sockets
+
+ 2011-07-22: Simon Goldschmidt
+ * pbuf.c/.h, timers.c: freeing ooseq pbufs when the pbuf pool is empty implemented
+ for NO_SYS==1: when not using sys_check_timeouts(), call PBUF_CHECK_FREE_OOSEQ()
+ at regular intervals from main level.
+
+ 2011-07-21: Simon Goldschmidt
+ * etharp.c: fixed bug #33551 (ARP entries may time out although in use) by
+ sending an ARP request when an ARP entry is used in the last minute before
+ it would time out.
+
+ 2011-07-04: Simon Goldschmidt
+ * sys_arch.txt: Fixed documentation after changing sys arch prototypes for 1.4.0.
+
+ 2011-06-26: Simon Goldschmidt
+ * tcp.c: fixed bug #31723 (tcp_kill_prio() kills pcbs with the same prio) by
+ updating its documentation only.
+
+ 2011-06-26: Simon Goldschmidt
+ * mem.c: fixed bug #33545: With MEM_USE_POOLS==1, mem_malloc can return an
+ unaligned pointer.
+
+ 2011-06-26: Simon Goldschmidt
+ * mem.c: fixed bug #33544 "warning in mem.c in lwip 1.4.0 with NO_SYS=1"
+
+
+
+(STABLE-1.4.0)
+
+ ++ New features:
+
+ 2011-03-27: Simon Goldschmidt
+ * tcp_impl.h, tcp_in.c, tcp_out.c: Removed 'dataptr' from 'struct tcp_seg' and
+ calculate it in tcp_zero_window_probe (the only place where it was used).
+
+ 2010-11-21: Simon Goldschmidt
+ * dhcp.c/.h: Added a function to deallocate the struct dhcp from a netif
+ (fixes bug #31525).
+
+ 2010-07-12: Simon Goldschmidt (patch by Stephane Lesage)
+ * ip.c, udp.c/.h, pbuf.h, sockets.c: task #10495: Added support for
+ IP_MULTICAST_LOOP at socket- and raw-API level.
+
+ 2010-06-16: Simon Goldschmidt
+ * ip.c: Added an optional define (LWIP_IP_ACCEPT_UDP_PORT) that can allow
+ link-layer-addressed UDP traffic to be received while a netif is down (just
+ like DHCP during configuration)
+
+ 2010-05-22: Simon Goldschmidt
+ * many many files: bug #27352: removed packing from ip_addr_t, the packed
+ version is now only used in protocol headers. Added global storage for
+ current src/dest IP address while in input functions.
+
+ 2010-05-16: Simon Goldschmidt
+ * def.h: task #10391: Add preprocessor-macros for compile-time htonl
+ calculation (and use them throughout the stack where applicable)
+
+ 2010-05-16: Simon Goldschmidt
+ * opt.h, memp_std.h, memp.c, ppp_oe.h/.c: PPPoE now uses its own MEMP pool
+ instead of the heap (moved struct pppoe_softc from ppp_oe.c to ppp_oe.h)
+
+ 2010-05-16: Simon Goldschmidt
+ * opt.h, memp_std.h, dns.h/.c: DNS_LOCAL_HOSTLIST_IS_DYNAMIC uses its own
+ MEMP pool instead of the heap
+
+ 2010-05-13: Simon Goldschmidt
+ * tcp.c, udp.c: task #6995: Implement SO_REUSEADDR (correctly), added
+ new option SO_REUSE_RXTOALL to pass received UDP broadcast/multicast
+ packets to more than one pcb.
+
+ 2010-05-02: Simon Goldschmidt
+ * netbuf.h/.c, sockets.c, api_msg.c: use checksum-on-copy for sending
+ UDP data for LWIP_NETIF_TX_SINGLE_PBUF==1
+
+ 2010-04-30: Simon Goldschmidt
+ * udp.h/.c, pbuf.h/.c: task #6849: added udp_send(_to/_if) functions that
+ take a precalculated checksum, added pbuf_fill_chksum() to copy data
+ into a pbuf and at the same time calculating the checksum for that data
+
+ 2010-04-29: Simon Goldschmidt
+ * ip_addr.h, etharp.h/.c, autoip.c: Create overridable macros for copying
+ 2-byte-aligned IP addresses and MAC addresses
+
+ 2010-04-28: Patch by Bill Auerbach
+ * ip.c: Inline generating IP checksum to save a function call
+
+ 2010-04-14: Simon Goldschmidt
+ * tcpip.h/.c, timers.c: Added an overridable define to get informed when the
+ tcpip_thread processes messages or timeouts to implement a watchdog.
+
+ 2010-03-28: Simon Goldschmidt
+ * ip_frag.c: create a new (contiguous) PBUF_RAM for every outgoing
+ fragment if LWIP_NETIF_TX_SINGLE_PBUF==1
+
+ 2010-03-27: Simon Goldschmidt
+ * etharp.c: Speedup TX by moving code from find_entry to etharp_output/
+ etharp_query to prevent unnecessary function calls (inspired by
+ patch #7135).
+
+ 2010-03-20: Simon Goldschmidt
+ * opt.h, tcpip.c/.h: Added an option to disable tcpip_(un)timeout code
+ since the linker cannot do this automatically to save space.
+
+ 2010-03-20: Simon Goldschmidt
+ * opt.h, etharp.c/.h: Added support for static ARP table entries
+
+ 2010-03-14: Simon Goldschmidt
+ * tcp_impl.h, tcp_out.c, inet_chksum.h/.c: task #6849: Calculate checksum
+ when creating TCP segments, not when (re-)transmitting them.
+
+ 2010-03-07: Simon Goldschmidt
+ * sockets.c: bug #28775 (select/event_callback: only check select_cb_list
+ on change) plus use SYS_LIGHTWEIGHT_PROT to protect the select code.
+ This should speed up receiving data on sockets as the select code in
+ event_callback is only executed when select is waiting.
+
+ 2010-03-06: Simon Goldschmidt
+ * tcp_out.c: task #7013 (Create option to have all packets delivered to
+ netif->output in one piece): Always copy to try to create single pbufs
+ in tcp_write.
+
+ 2010-03-06: Simon Goldschmidt
+ * api.h, api_lib.c, sockets.c: task #10167 (sockets: speed up TCP recv
+ by not allocating a netbuf): added function netconn_recv_tcp_pbuf()
+ for tcp netconns to receive pbufs, not netbufs; use that function
+ for tcp sockets.
+
+ 2010-03-05: Jakob Ole Stoklundsen / Simon Goldschmidt
+ * opt.h, tcp.h, tcp_impl.h, tcp.c, tcp_in.c, tcp_out.c: task #7040:
+ Work on tcp_enqueue: Don't waste memory when chaining segments,
+ added option TCP_OVERSIZE to prevent creating many small pbufs when
+ calling tcp_write with many small blocks of data. Instead, pbufs are
+ allocated larger than needed and the space is used for later calls to
+ tcp_write.
+
+ 2010-02-21: Simon Goldschmidt
+ * stats.c/.h: Added const char* name to mem- and memp-stats for easier
+ debugging.
+
+ 2010-02-21: Simon Goldschmidt
+ * tcp.h (and usages), added tcp_impl.h: Splitted API and internal
+ implementation of tcp to make API usage cleare to application programmers
+
+ 2010-02-14: Simon Goldschmidt/Stephane Lesage
+ * ip_addr.h: Improved some defines working on ip addresses, added faster
+ macro to copy addresses that cannot be NULL
+
+ 2010-02-13: Simon Goldschmidt
+ * api.h, api_lib.c, api_msg.c, sockets.c: task #7865 (implement non-
+ blocking send operation)
+
+ 2010-02-12: Simon Goldschmidt
+ * sockets.c/.h: Added a minimal version of posix fctl() to have a
+ standardised way to set O_NONBLOCK for nonblocking sockets.
+
+ 2010-02-12: Simon Goldschmidt
+ * dhcp.c/.h, autoip.c/.h: task #10139 (Prefer statically allocated
+ memory): added autoip_set_struct() and dhcp_set_struct() to let autoip
+ and dhcp work with user-allocated structs instead of callin mem_malloc
+
+ 2010-02-12: Simon Goldschmidt/Jeff Barber
+ * tcp.c/h: patch #6865 (SO_REUSEADDR for TCP): if pcb.so_options has
+ SOF_REUSEADDR set, allow binding to endpoint in TIME_WAIT
+
+ 2010-02-12: Simon Goldschmidt
+ * sys layer: task #10139 (Prefer statically allocated memory): converted
+ mbox and semaphore functions to take pointers to sys_mbox_t/sys_sem_t;
+ converted sys_mbox_new/sys_sem_new to take pointers and return err_t;
+ task #7212: Add Mutex concept in sys_arch (define LWIP_COMPAT_MUTEX
+ to let sys.h use binary semaphores instead of mutexes - as before)
+
+ 2010-02-09: Simon Goldschmidt (Simon Kallweit)
+ * timers.c/.h: Added function sys_restart_timeouts() from patch #7085
+ (Restart system timeout handling)
+
+ 2010-02-09: Simon Goldschmidt
+ * netif.c/.h, removed loopif.c/.h: task #10153 (Integrate loopif into
+ netif.c) - loopif does not have to be created by the port any more,
+ just define LWIP_HAVE_LOOPIF to 1.
+
+ 2010-02-08: Simon Goldschmidt
+ * inet.h, ip_addr.c/.h: Added reentrant versions of inet_ntoa/ipaddr_ntoa
+ inet_ntoa_r/ipaddr_ntoa_r
+
+ 2010-02-08: Simon Goldschmidt
+ * netif.h: Added netif_s/get_igmp_mac_filter() macros
+
+ 2010-02-05: Simon Goldschmidt
+ * netif.h: Added function-like macros to get/set the hostname on a netif
+
+ 2010-02-04: Simon Goldschmidt
+ * nearly every file: Replaced struct ip_addr by typedef ip_addr_t to
+ make changing the actual implementation behind the typedef easier.
+
+ 2010-02-01: Simon Goldschmidt
+ * opt.h, memp_std.h, dns.h, netdb.c, memp.c: Let netdb use a memp pool
+ for allocating memory when getaddrinfo() is called.
+
+ 2010-01-31: Simon Goldschmidt
+ * dhcp.h, dhcp.c: Reworked the code that parses DHCP options: parse
+ them once instead of parsing for every option. This also removes
+ the need for mem_malloc from dhcp_recv and makes it possible to
+ correctly retrieve the BOOTP file.
+
+ 2010-01-30: simon Goldschmidt
+ * sockets.c: Use SYS_LIGHTWEIGHT_PROT instead of a semaphore to protect
+ the sockets array.
+
+ 2010-01-29: Simon Goldschmidt (patch by Laura Garrett)
+ * api.h, api_msg.c, sockets.c: Added except set support in select
+ (patch #6860)
+
+ 2010-01-29: Simon Goldschmidt (patch by Laura Garrett)
+ * api.h, sockets.h, err.h, api_lib.c, api_msg.c, sockets.c, err.c:
+ Add non-blocking support for connect (partly from patch #6860),
+ plus many cleanups in socket & netconn API.
+
+ 2010-01-27: Simon Goldschmidt
+ * opt.h, tcp.h, init.c, api_msg.c: Added TCP_SNDQUEUELOWAT corresponding
+ to TCP_SNDLOWAT and added tcp_sndqueuelen() - this fixes bug #28605
+
+ 2010-01-26: Simon Goldschmidt
+ * snmp: Use memp pools for snmp instead of the heap; added 4 new pools.
+
+ 2010-01-14: Simon Goldschmidt
+ * ppp.c/.h: Fixed bug #27856: PPP: Set netif link- and status-callback
+ by adding ppp_set_netif_statuscallback()/ppp_set_netif_linkcallback()
+
+ 2010-01-13: Simon Goldschmidt
+ * mem.c: The heap now may be moved to user-defined memory by defining
+ LWIP_RAM_HEAP_POINTER as a void pointer to that memory's address
+ (patch #6966 and bug #26133)
+
+ 2010-01-10: Simon Goldschmidt (Bill Auerbach)
+ * opt.h, memp.c: patch #6822 (Add option to place memory pools in
+ separate arrays)
+
+ 2010-01-10: Simon Goldschmidt
+ * init.c, igmp.c: patch #6463 (IGMP - Adding Random Delay): added define
+ LWIP_RAND() for lwip-wide randomization (to be defined in cc.h)
+
+ 2009-12-31: Simon Goldschmidt
+ * tcpip.c, init.c, memp.c, sys.c, memp_std.h, sys.h, tcpip.h
+ added timers.c/.h: Separated timer implementation from semaphore/mbox
+ implementation, moved timer implementation to timers.c/.h, timers are
+ now only called from tcpip_thread or by explicitly checking them.
+ (TASK#7235)
+
+ 2009-12-27: Simon Goldschmidt
+ * opt.h, etharp.h/.c, init.c, tcpip.c: Added an additional option
+ LWIP_ETHERNET to support ethernet without ARP (necessary for pure PPPoE)
+
+
+ ++ Bugfixes:
+
+ 2011-04-20: Simon Goldschmidt
+ * sys_arch.txt: sys_arch_timeouts() is not needed any more.
+
+ 2011-04-13: Simon Goldschmidt
+ * tcp.c, udp.c: Fixed bug #33048 (Bad range for IP source port numbers) by
+ using ports in the IANA private/dynamic range (49152 through 65535).
+
+ 2011-03-29: Simon Goldschmidt, patch by Emil Lhungdahl:
+ * etharp.h/.c: Fixed broken VLAN support.
+
+ 2011-03-27: Simon Goldschmidt
+ * tcp.c: Fixed bug #32926 (TCP_RMV(&tcp_bound_pcbs) is called on unbound tcp
+ pcbs) by checking if the pcb was bound (local_port != 0).
+
+ 2011-03-27: Simon Goldschmidt
+ * ppp.c: Fixed bug #32280 (ppp: a pbuf is freed twice)
+
+ 2011-03-27: Simon Goldschmidt
+ * sockets.c: Fixed bug #32906: lwip_connect+lwip_send did not work for udp and
+ raw pcbs with LWIP_TCPIP_CORE_LOCKING==1.
+
+ 2011-03-27: Simon Goldschmidt
+ * tcp_out.c: Fixed bug #32820 (Outgoing TCP connections created before route
+ is present never times out) by starting retransmission timer before checking
+ route.
+
+ 2011-03-22: Simon Goldschmidt
+ * ppp.c: Fixed bug #32648 (PPP code crashes when terminating a link) by only
+ calling sio_read_abort() if the file descriptor is valid.
+
+ 2011-03-14: Simon Goldschmidt
+ * err.h/.c, sockets.c, api_msg.c: fixed bug #31748 (Calling non-blocking connect
+ more than once can render a socket useless) since it mainly involves changing
+ "FATAL" classification of error codes: ERR_USE and ERR_ISCONN just aren't fatal.
+
+ 2011-03-13: Simon Goldschmidt
+ * sockets.c: fixed bug #32769 (ESHUTDOWN is linux-specific) by fixing
+ err_to_errno_table (ERR_CLSD: ENOTCONN instead of ESHUTDOWN), ERR_ISCONN:
+ use EALRADY instead of -1
+
+ 2011-03-13: Simon Goldschmidt
+ * api_lib.c: netconn_accept: return ERR_ABRT instead of ERR_CLSD if the
+ connection has been aborted by err_tcp (since this is not a normal closing
+ procedure).
+
+ 2011-03-13: Simon Goldschmidt
+ * tcp.c: tcp_bind: return ERR_VAL instead of ERR_ISCONN when trying to bind
+ with pcb->state != CLOSED
+
+ 2011-02-17: Simon Goldschmidt
+ * rawapi.txt: Fixed bug #32561 tcp_poll argument definition out-of-order in
+ documentation
+
+ 2011-02-17: Simon Goldschmidt
+ * many files: Added missing U/UL modifiers to fix 16-bit-arch portability.
+
+ 2011-01-24: Simon Goldschmidt
+ * sockets.c: Fixed bug #31741: lwip_select seems to have threading problems
+
+ 2010-12-02: Simon Goldschmidt
+ * err.h: Fixed ERR_IS_FATAL so that ERR_WOULDBLOCK is not fatal.
+
+ 2010-11-23: Simon Goldschmidt
+ * api.h, api_lib.c, api_msg.c, sockets.c: netconn.recv_avail is only used for
+ LWIP_SO_RCVBUF and ioctl/FIONREAD.
+
+ 2010-11-23: Simon Goldschmidt
+ * etharp.c: Fixed bug #31720: ARP-queueing: RFC 1122 recommends to queue at
+ least 1 packet -> ARP_QUEUEING==0 now queues the most recent packet.
+
+ 2010-11-23: Simon Goldschmidt
+ * tcp_in.c: Fixed bug #30577: tcp_input: don't discard ACK-only packets after
+ refusing 'refused_data' again.
+
+ 2010-11-22: Simon Goldschmidt
+ * sockets.c: Fixed bug #31590: getsockopt(... SO_ERROR ...) gives EINPROGRESS
+ after a successful nonblocking connection.
+
+ 2010-11-22: Simon Goldschmidt
+ * etharp.c: Fixed bug #31722: IP packets sent with an AutoIP source addr
+ must be sent link-local
+
+ 2010-11-22: Simon Goldschmidt
+ * timers.c: patch #7329: tcp_timer_needed prototype was ifdef'ed out for
+ LWIP_TIMERS==0
+
+ 2010-11-20: Simon Goldschmidt
+ * sockets.c: Fixed bug #31170: lwip_setsockopt() does not set socket number
+
+ 2010-11-20: Simon Goldschmidt
+ * sockets.h: Fixed bug #31304: Changed SHUT_RD, SHUT_WR and SHUT_RDWR to
+ resemble other stacks.
+
+ 2010-11-20: Simon Goldschmidt
+ * dns.c: Fixed bug #31535: TCP_SND_QUEUELEN must be at least 2 or else
+ no-copy TCP writes will never succeed.
+
+ 2010-11-20: Simon Goldschmidt
+ * dns.c: Fixed bug #31701: Error return value from dns_gethostbyname() does
+ not match documentation: return ERR_ARG instead of ERR_VAL if not
+ initialized or wrong argument.
+
+ 2010-10-20: Simon Goldschmidt
+ * sockets.h: Fixed bug #31385: sizeof(struct sockaddr) is 30 but should be 16
+
+ 2010-10-05: Simon Goldschmidt
+ * dhcp.c: Once again fixed #30038: DHCP/AutoIP cooperation failed when
+ replugging the network cable after an AutoIP address was assigned.
+
+ 2010-08-10: Simon Goldschmidt
+ * tcp.c: Fixed bug #30728: tcp_new_port() did not check listen pcbs
+
+ 2010-08-03: Simon Goldschmidt
+ * udp.c, raw.c: Don't chain empty pbufs when sending them (fixes bug #30625)
+
+ 2010-08-01: Simon Goldschmidt (patch by Greg Renda)
+ * ppp.c: Applied patch #7264 (PPP protocols are rejected incorrectly on big
+ endian architectures)
+
+ 2010-07-28: Simon Goldschmidt
+ * api_lib.c, api_msg.c, sockets.c, mib2.c: Fixed compilation with TCP or UDP
+ disabled.
+
+ 2010-07-27: Simon Goldschmidt
+ * tcp.c: Fixed bug #30565 (tcp_connect() check bound list): that check did no
+ harm but never did anything
+
+ 2010-07-21: Simon Goldschmidt
+ * ip.c: Fixed invalid fix for bug #30402 (CHECKSUM_GEN_IP_INLINE does not
+ add IP options)
+
+ 2010-07-16: Kieran Mansley
+ * msg_in.c: Fixed SNMP ASN constant defines to not use ! operator
+
+ 2010-07-10: Simon Goldschmidt
+ * ip.c: Fixed bug #30402: CHECKSUM_GEN_IP_INLINE does not add IP options
+
+ 2010-06-30: Simon Goldschmidt
+ * api_msg.c: fixed bug #30300 (shutdown parameter was not initialized in
+ netconn_delete)
+
+ 2010-06-28: Kieran Mansley
+ * timers.c remove unportable printing of C function pointers
+
+ 2010-06-24: Simon Goldschmidt
+ * init.c, timers.c/.h, opt.h, memp_std.h: From patch #7221: added flag
+ NO_SYS_NO_TIMERS to drop timer support for NO_SYS==1 for easier upgrading
+
+ 2010-06-24: Simon Goldschmidt
+ * api(_lib).c/.h, api_msg.c/.h, sockets.c/.h: Fixed bug #10088: Correctly
+ implemented shutdown at socket level.
+
+ 2010-06-21: Simon Goldschmidt
+ * pbuf.c/.h, ip_frag.c/.h, opt.h, memp_std.h: Fixed bug #29361 (ip_frag has
+ problems with zero-copy DMA MACs) by adding custom pbufs and implementing
+ custom pbufs that reference other (original) pbufs. Additionally set
+ IP_FRAG_USES_STATIC_BUF=0 as default to be on the safe side.
+
+ 2010-06-15: Simon Goldschmidt
+ * dhcp.c: Fixed bug #29970: DHCP endian issue parsing option responses
+
+ 2010-06-14: Simon Goldschmidt
+ * autoip.c: Fixed bug #30039: AutoIP does not reuse previous addresses
+
+ 2010-06-12: Simon Goldschmidt
+ * dhcp.c: Fixed bug #30038: dhcp_network_changed doesn't reset AUTOIP coop
+ state
+
+ 2010-05-17: Simon Goldschmidt
+ * netdb.c: Correctly NULL-terminate h_addr_list
+
+ 2010-05-16: Simon Goldschmidt
+ * def.h/.c: changed the semantics of LWIP_PREFIX_BYTEORDER_FUNCS to prevent
+ "symbol already defined" i.e. when linking to winsock
+
+ 2010-05-05: Simon Goldschmidt
+ * def.h, timers.c: Fixed bug #29769 (sys_check_timeouts: sys_now() may
+ overflow)
+
+ 2010-04-21: Simon Goldschmidt
+ * api_msg.c: Fixed bug #29617 (sometime cause stall on delete listening
+ connection)
+
+ 2010-03-28: Luca Ceresoli
+ * ip_addr.c/.h: patch #7143: Add a few missing const qualifiers
+
+ 2010-03-27: Luca Ceresoli
+ * mib2.c: patch #7130: remove meaningless const qualifiers
+
+ 2010-03-26: Simon Goldschmidt
+ * tcp_out.c: Make LWIP_NETIF_TX_SINGLE_PBUF work for TCP, too
+
+ 2010-03-26: Simon Goldschmidt
+ * various files: Fixed compiling with different options disabled (TCP/UDP),
+ triggered by bug #29345; don't allocate acceptmbox if LWIP_TCP is disabled
+
+ 2010-03-25: Simon Goldschmidt
+ * sockets.c: Fixed bug #29332: lwip_select() processes readset incorrectly
+
+ 2010-03-25: Simon Goldschmidt
+ * tcp_in.c, test_tcp_oos.c: Fixed bug #29080: Correctly handle remote side
+ overrunning our rcv_wnd in ooseq case.
+
+ 2010-03-22: Simon Goldschmidt
+ * tcp.c: tcp_listen() did not copy the pcb's prio.
+
+ 2010-03-19: Simon Goldschmidt
+ * snmp_msg.c: Fixed bug #29256: SNMP Trap address was not correctly set
+
+ 2010-03-14: Simon Goldschmidt
+ * opt.h, etharp.h: Fixed bug #29148 (Incorrect PBUF_POOL_BUFSIZE for ports
+ where ETH_PAD_SIZE > 0) by moving definition of ETH_PAD_SIZE to opt.h
+ and basing PBUF_LINK_HLEN on it.
+
+ 2010-03-08: Simon Goldschmidt
+ * netif.c, ipv4/ip.c: task #10241 (AutoIP: don't break existing connections
+ when assiging routable address): when checking incoming packets and
+ aborting existing connection on address change, filter out link-local
+ addresses.
+
+ 2010-03-06: Simon Goldschmidt
+ * sockets.c: Fixed LWIP_NETIF_TX_SINGLE_PBUF for LWIP_TCPIP_CORE_LOCKING
+
+ 2010-03-06: Simon Goldschmidt
+ * ipv4/ip.c: Don't try to forward link-local addresses
+
+ 2010-03-06: Simon Goldschmidt
+ * etharp.c: Fixed bug #29087: etharp: don't send packets for LinkLocal-
+ addresses to gw
+
+ 2010-03-05: Simon Goldschmidt
+ * dhcp.c: Fixed bug #29072: Correctly set ciaddr based on message-type
+ and state.
+
+ 2010-03-05: Simon Goldschmidt
+ * api_msg.c: Correctly set TCP_WRITE_FLAG_MORE when netconn_write is split
+ into multiple calls to tcp_write.
+
+ 2010-02-21: Simon Goldschmidt
+ * opt.h, mem.h, dns.c: task #10140: Remove DNS_USES_STATIC_BUF (keep
+ the implementation of DNS_USES_STATIC_BUF==1)
+
+ 2010-02-20: Simon Goldschmidt
+ * tcp.h, tcp.c, tcp_in.c, tcp_out.c: Task #10088: Correctly implement
+ close() vs. shutdown(). Now the application does not get any more
+ recv callbacks after calling tcp_close(). Added tcp_shutdown().
+
+ 2010-02-19: Simon Goldschmidt
+ * mem.c/.h, pbuf.c: Renamed mem_realloc() to mem_trim() to prevent
+ confusion with realloc()
+
+ 2010-02-15: Simon Goldschmidt/Stephane Lesage
+ * netif.c/.h: Link status does not depend on LWIP_NETIF_LINK_CALLBACK
+ (fixes bug #28899)
+
+ 2010-02-14: Simon Goldschmidt
+ * netif.c: Fixed bug #28877 (Duplicate ARP gratuitous packet with
+ LWIP_NETIF_LINK_CALLBACK set on) by only sending if both link- and
+ admin-status of a netif are up
+
+ 2010-02-14: Simon Goldschmidt
+ * opt.h: Disable ETHARP_TRUST_IP_MAC by default since it slows down packet
+ reception and is not really necessary
+
+ 2010-02-14: Simon Goldschmidt
+ * etharp.c/.h: Fixed ARP input processing: only add a new entry if a
+ request was directed as us (RFC 826, Packet Reception), otherwise
+ only update existing entries; internalized some functions
+
+ 2010-02-14: Simon Goldschmidt
+ * netif.h, etharp.c, tcpip.c: Fixed bug #28183 (ARP and TCP/IP cannot be
+ disabled on netif used for PPPoE) by adding a new netif flag
+ (NETIF_FLAG_ETHERNET) that tells the stack the device is an ethernet
+ device but prevents usage of ARP (so that ethernet_input can be used
+ for PPPoE).
+
+ 2010-02-12: Simon Goldschmidt
+ * netif.c: netif_set_link_up/down: only do something if the link state
+ actually changes
+
+ 2010-02-12: Simon Goldschmidt/Stephane Lesage
+ * api_msg.c: Fixed bug #28865 (Cannot close socket/netconn in non-blocking
+ connect)
+
+ 2010-02-12: Simon Goldschmidt
+ * mem.h: Fixed bug #28866 (mem_realloc function defined in mem.h)
+
+ 2010-02-09: Simon Goldschmidt
+ * api_lib.c, api_msg.c, sockets.c, api.h, api_msg.h: Fixed bug #22110
+ (recv() makes receive window update for data that wasn't received by
+ application)
+
+ 2010-02-09: Simon Goldschmidt/Stephane Lesage
+ * sockets.c: Fixed bug #28853 (lwip_recvfrom() returns 0 on receive time-out
+ or any netconn_recv() error)
+
+ 2010-02-09: Simon Goldschmidt
+ * ppp.c: task #10154 (PPP: Update snmp in/out counters for tx/rx packets)
+
+ 2010-02-09: Simon Goldschmidt
+ * netif.c: For loopback packets, adjust the stats- and snmp-counters
+ for the loopback netif.
+
+ 2010-02-08: Simon Goldschmidt
+ * igmp.c/.h, ip.h: Moved most defines from igmp.h to igmp.c for clarity
+ since they are not used anywhere else.
+
+ 2010-02-08: Simon Goldschmidt (Stphane Lesage)
+ * igmp.c, igmp.h, stats.c, stats.h: Improved IGMP stats
+ (patch from bug #28798)
+
+ 2010-02-08: Simon Goldschmidt (Stphane Lesage)
+ * igmp.c: Fixed bug #28798 (Error in "Max Response Time" processing) and
+ another bug when LWIP_RAND() returns zero.
+
+ 2010-02-04: Simon Goldschmidt
+ * nearly every file: Use macros defined in ip_addr.h (some of them new)
+ to work with IP addresses (preparation for bug #27352 - Change ip_addr
+ from struct to typedef (u32_t) - and better code).
+
+ 2010-01-31: Simon Goldschmidt
+ * netif.c: Don't call the link-callback from netif_set_up/down() since
+ this invalidly retriggers DHCP.
+
+ 2010-01-29: Simon Goldschmidt
+ * ip_addr.h, inet.h, def.h, inet.c, def.c, more: Cleanly separate the
+ portability file inet.h and its contents from the stack: moved htonX-
+ functions to def.h (and the new def.c - they are not ipv4 dependent),
+ let inet.h depend on ip_addr.h and not the other way round.
+ This fixes bug #28732.
+
+ 2010-01-28: Kieran Mansley
+ * tcp.c: Ensure ssthresh >= 2*MSS
+
+ 2010-01-27: Simon Goldschmidt
+ * tcp.h, tcp.c, tcp_in.c: Fixed bug #27871: Calling tcp_abort() in recv
+ callback can lead to accessing unallocated memory. As a consequence,
+ ERR_ABRT means the application has called tcp_abort()!
+
+ 2010-01-25: Simon Goldschmidt
+ * snmp_structs.h, msg_in.c: Partly fixed bug #22070 (MIB_OBJECT_WRITE_ONLY
+ not implemented in SNMP): write-only or not-accessible are still
+ returned by getnext (though not by get)
+
+ 2010-01-24: Simon Goldschmidt
+ * snmp: Renamed the private mib node from 'private' to 'mib_private' to
+ not use reserved C/C++ keywords
+
+ 2010-01-23: Simon Goldschmidt
+ * sockets.c: Fixed bug #28716: select() returns 0 after waiting for less
+ than 1 ms
+
+ 2010-01-21: Simon Goldschmidt
+ * tcp.c, api_msg.c: Fixed bug #28651 (tcp_connect: no callbacks called
+ if tcp_enqueue fails) both in raw- and netconn-API
+
+ 2010-01-19: Simon Goldschmidt
+ * api_msg.c: Fixed bug #27316: netconn: Possible deadlock in err_tcp
+
+ 2010-01-18: Iordan Neshev/Simon Goldschmidt
+ * src/netif/ppp: reorganised PPP sourcecode to 2.3.11 including some
+ bugfix backports from 2.4.x.
+
+ 2010-01-18: Simon Goldschmidt
+ * mem.c: Fixed bug #28679: mem_realloc calculates mem_stats wrong
+
+ 2010-01-17: Simon Goldschmidt
+ * api_lib.c, api_msg.c, (api_msg.h, api.h, sockets.c, tcpip.c):
+ task #10102: "netconn: clean up conn->err threading issues" by adding
+ error return value to struct api_msg_msg
+
+ 2010-01-17: Simon Goldschmidt
+ * api.h, api_lib.c, sockets.c: Changed netconn_recv() and netconn_accept()
+ to return err_t (bugs #27709 and #28087)
+
+ 2010-01-14: Simon Goldschmidt
+ * ...: Use typedef for function prototypes throughout the stack.
+
+ 2010-01-13: Simon Goldschmidt
+ * api_msg.h/.c, api_lib.c: Fixed bug #26672 (close connection when receive
+ window = 0) by correctly draining recvmbox/acceptmbox
+
+ 2010-01-11: Simon Goldschmidt
+ * pap.c: Fixed bug #13315 (PPP PAP authentication can result in
+ erroneous callbacks) by copying the code from recent pppd
+
+ 2010-01-10: Simon Goldschmidt
+ * raw.c: Fixed bug #28506 (raw_bind should filter received packets)
+
+ 2010-01-10: Simon Goldschmidt
+ * tcp.h/.c: bug #28127 (remove call to tcp_output() from tcp_ack(_now)())
+
+ 2010-01-08: Simon Goldschmidt
+ * sockets.c: Fixed bug #28519 (lwip_recvfrom bug with len > 65535)
+
+ 2010-01-08: Simon Goldschmidt
+ * dns.c: Copy hostname for DNS_LOCAL_HOSTLIST_IS_DYNAMIC==1 since string
+ passed to dns_local_addhost() might be volatile
+
+ 2010-01-07: Simon Goldschmidt
+ * timers.c, tcp.h: Call tcp_timer_needed() with NO_SYS==1, too
+
+ 2010-01-06: Simon Goldschmidt
+ * netdb.h: Fixed bug #28496: missing include guards in netdb.h
+
+ 2009-12-31: Simon Goldschmidt
+ * many ppp files: Reorganised PPP source code from ucip structure to pppd
+ structure to easily compare our code against the pppd code (around v2.3.1)
+
+ 2009-12-27: Simon Goldschmidt
+ * tcp_in.c: Another fix for bug #28241 (ooseq processing) and adapted
+ unit test
+
+
+(STABLE-1.3.2)
+
+ ++ New features:
+
+ 2009-10-27 Simon Goldschmidt/Stephan Lesage
+ * netifapi.c/.h: Added netifapi_netif_set_addr()
+
+ 2009-10-07 Simon Goldschmidt/Fabian Koch
+ * api_msg.c, netbuf.c/.h, opt.h: patch #6888: Patch for UDP Netbufs to
+ support dest-addr and dest-port (optional: LWIP_NETBUF_RECVINFO)
+
+ 2009-08-26 Simon Goldschmidt/Simon Kallweit
+ * slipif.c/.h: bug #26397: SLIP polling support
+
+ 2009-08-25 Simon Goldschmidt
+ * opt.h, etharp.h/.c: task #9033: Support IEEE 802.1q tagged frame (VLAN),
+ New configuration options ETHARP_SUPPORT_VLAN and ETHARP_VLAN_CHECK.
+
+ 2009-08-25 Simon Goldschmidt
+ * ip_addr.h, netdb.c: patch #6900: added define ip_ntoa(struct ip_addr*)
+
+ 2009-08-24 Jakob Stoklund Olesen
+ * autoip.c, dhcp.c, netif.c: patch #6725: Teach AutoIP and DHCP to respond
+ to netif_set_link_up().
+
+ 2009-08-23 Simon Goldschmidt
+ * tcp.h/.c: Added function tcp_debug_state_str() to convert a tcp state
+ to a human-readable string.
+
+ ++ Bugfixes:
+
+ 2009-12-24: Kieran Mansley
+ * tcp_in.c Apply patches from Oleg Tyshev to improve OOS processing
+ (BUG#28241)
+
+ 2009-12-06: Simon Goldschmidt
+ * ppp.h/.c: Fixed bug #27079 (Yet another leak in PPP): outpacket_buf can
+ be statically allocated (like in ucip)
+
+ 2009-12-04: Simon Goldschmidt (patch by Ioardan Neshev)
+ * pap.c: patch #6969: PPP: missing PAP authentication UNTIMEOUT
+
+ 2009-12-03: Simon Goldschmidt
+ * tcp.h, tcp_in.c, tcp_out.c: Fixed bug #28106: dup ack for fast retransmit
+ could have non-zero length
+
+ 2009-12-02: Simon Goldschmidt
+ * tcp_in.c: Fixed bug #27904: TCP sends too many ACKs: delay resetting
+ tcp_input_pcb until after calling the pcb's callbacks
+
+ 2009-11-29: Simon Goldschmidt
+ * tcp_in.c: Fixed bug #28054: Two segments with FIN flag on the out-of-
+ sequence queue, also fixed PBUF_POOL leak in the out-of-sequence code
+
+ 2009-11-29: Simon Goldschmidt
+ * pbuf.c: Fixed bug #28064: pbuf_alloc(PBUF_POOL) is not thread-safe by
+ queueing a call into tcpip_thread to free ooseq-bufs if the pool is empty
+
+ 2009-11-26: Simon Goldschmidt
+ * tcp.h: Fixed bug #28098: Nagle can prevent fast retransmit from sending
+ segment
+
+ 2009-11-26: Simon Goldschmidt
+ * tcp.h, sockets.c: Fixed bug #28099: API required to disable Nagle
+ algorithm at PCB level
+
+ 2009-11-22: Simon Goldschmidt
+ * tcp_out.c: Fixed bug #27905: FIN isn't combined with data on unsent
+
+ 2009-11-22: Simon Goldschmidt (suggested by Bill Auerbach)
+ * tcp.c: tcp_alloc: prevent increasing stats.err for MEMP_TCP_PCB when
+ reusing time-wait pcb
+
+ 2009-11-20: Simon Goldschmidt (patch by Albert Bartel)
+ * sockets.c: Fixed bug #28062: Data received directly after accepting
+ does not wake up select
+
+ 2009-11-11: Simon Goldschmidt
+ * netdb.h: Fixed bug #27994: incorrect define for freeaddrinfo(addrinfo)
+
+ 2009-10-30: Simon Goldschmidt
+ * opt.h: Increased default value for TCP_MSS to 536, updated default
+ value for TCP_WND to 4*TCP_MSS to keep delayed ACK working.
+
+ 2009-10-28: Kieran Mansley
+ * tcp_in.c, tcp_out.c, tcp.h: re-work the fast retransmission code
+ to follow algorithm from TCP/IP Illustrated
+
+ 2009-10-27: Kieran Mansley
+ * tcp_in.c: fix BUG#27445: grow cwnd with every duplicate ACK
+
+ 2009-10-25: Simon Goldschmidt
+ * tcp.h: bug-fix in the TCP_EVENT_RECV macro (has to call tcp_recved if
+ pcb->recv is NULL to keep rcv_wnd correct)
+
+ 2009-10-25: Simon Goldschmidt
+ * tcp_in.c: Fixed bug #26251: RST process in TIME_WAIT TCP state
+
+ 2009-10-23: Simon Goldschmidt (David Empson)
+ * tcp.c: Fixed bug #27783: Silly window avoidance for small window sizes
+
+ 2009-10-21: Simon Goldschmidt
+ * tcp_in.c: Fixed bug #27215: TCP sent() callback gives leading and
+ trailing 1 byte len (SYN/FIN)
+
+ 2009-10-21: Simon Goldschmidt
+ * tcp_out.c: Fixed bug #27315: zero window probe and FIN
+
+ 2009-10-19: Simon Goldschmidt
+ * dhcp.c/.h: Minor code simplification (don't store received pbuf, change
+ conditional code to assert where applicable), check pbuf length before
+ testing for valid reply
+
+ 2009-10-19: Simon Goldschmidt
+ * dhcp.c: Removed most calls to udp_connect since they aren't necessary
+ when using udp_sendto_if() - always stay connected to IP_ADDR_ANY.
+
+ 2009-10-16: Simon Goldschmidt
+ * ip.c: Fixed bug #27390: Source IP check in ip_input() causes it to drop
+ valid DHCP packets -> allow 0.0.0.0 as source address when LWIP_DHCP is
+ enabled
+
+ 2009-10-15: Simon Goldschmidt (Oleg Tyshev)
+ * tcp_in.c: Fixed bug #27329: dupacks by unidirectional data transmit
+
+ 2009-10-15: Simon Goldschmidt
+ * api_lib.c: Fixed bug #27709: conn->err race condition on netconn_recv()
+ timeout
+
+ 2009-10-15: Simon Goldschmidt
+ * autoip.c: Fixed bug #27704: autoip starts with wrong address
+ LWIP_AUTOIP_CREATE_SEED_ADDR() returned address in host byte order instead
+ of network byte order
+
+ 2009-10-11 Simon Goldschmidt (Jrg Kesten)
+ * tcp_out.c: Fixed bug #27504: tcp_enqueue wrongly concatenates segments
+ which are not consecutive when retransmitting unacked segments
+
+ 2009-10-09 Simon Goldschmidt
+ * opt.h: Fixed default values of some stats to only be enabled if used
+ Fixes bug #27338: sys_stats is defined when NO_SYS = 1
+
+ 2009-08-30 Simon Goldschmidt
+ * ip.c: Fixed bug bug #27345: "ip_frag() does not use the LWIP_NETIF_LOOPBACK
+ function" by checking for loopback before calling ip_frag
+
+ 2009-08-25 Simon Goldschmidt
+ * dhcp.c: fixed invalid dependency to etharp_query if DHCP_DOES_ARP_CHECK==0
+
+ 2009-08-23 Simon Goldschmidt
+ * ppp.c: bug #27078: Possible memory leak in pppInit()
+
+ 2009-08-23 Simon Goldschmidt
+ * netdb.c, dns.c: bug #26657: DNS, if host name is "localhost", result
+ is error.
+
+ 2009-08-23 Simon Goldschmidt
+ * opt.h, init.c: bug #26649: TCP fails when TCP_MSS > TCP_SND_BUF
+ Fixed wrong parenthesis, added check in init.c
+
+ 2009-08-23 Simon Goldschmidt
+ * ppp.c: bug #27266: wait-state debug message in pppMain occurs every ms
+
+ 2009-08-23 Simon Goldschmidt
+ * many ppp files: bug #27267: Added include to string.h where needed
+
+ 2009-08-23 Simon Goldschmidt
+ * tcp.h: patch #6843: tcp.h macro optimization patch (for little endian)
+
+
+(STABLE-1.3.1)
+
+ ++ New features:
+
+ 2009-05-10 Simon Goldschmidt
+ * opt.h, sockets.c, pbuf.c, netbuf.h, pbuf.h: task #7013: Added option
+ LWIP_NETIF_TX_SINGLE_PBUF to try to create transmit packets from only
+ one pbuf to help MACs that don't support scatter-gather DMA.
+
+ 2009-05-09 Simon Goldschmidt
+ * icmp.h, icmp.c: Shrinked ICMP code, added option to NOT check icoming
+ ECHO pbuf for size (just use it): LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN
+
+ 2009-05-05 Simon Goldschmidt, Jakob Stoklund Olesen
+ * ip.h, ip.c: Added ip_current_netif() & ip_current_header() to receive
+ extended info about the currently received packet.
+
+ 2009-04-27 Simon Goldschmidt
+ * sys.h: Made SYS_LIGHTWEIGHT_PROT and sys_now() work with NO_SYS=1
+
+ 2009-04-25 Simon Goldschmidt
+ * mem.c, opt.h: Added option MEM_USE_POOLS_TRY_BIGGER_POOL to try the next
+ bigger malloc pool if one is empty (only usable with MEM_USE_POOLS).
+
+ 2009-04-21 Simon Goldschmidt
+ * dns.c, init.c, dns.h, opt.h: task #7507, patch #6786: DNS supports static
+ hosts table. New configuration options DNS_LOCAL_HOSTLIST and
+ DNS_LOCAL_HOSTLIST_IS_DYNAMIC. Also, DNS_LOOKUP_LOCAL_EXTERN() can be defined
+ as an external function for lookup.
+
+ 2009-04-15 Simon Goldschmidt
+ * dhcp.c: patch #6763: Global DHCP XID can be redefined to something more unique
+
+ 2009-03-31 Kieran Mansley
+ * tcp.c, tcp_out.c, tcp_in.c, sys.h, tcp.h, opts.h: add support for
+ TCP timestamp options, off by default. Rework tcp_enqueue() to
+ take option flags rather than specified option data
+
+ 2009-02-18 Simon Goldschmidt
+ * cc.h: Added printf formatter for size_t: SZT_F
+
+ 2009-02-16 Simon Goldschmidt (patch by Rishi Khan)
+ * icmp.c, opt.h: patch #6539: (configurable) response to broadcast- and multicast
+ pings
+
+ 2009-02-12 Simon Goldschmidt
+ * init.h: Added LWIP_VERSION to get the current version of the stack
+
+ 2009-02-11 Simon Goldschmidt (suggested by Gottfried Spitaler)
+ * opt.h, memp.h/.c: added MEMP_MEM_MALLOC to use mem_malloc/mem_free instead
+ of the pool allocator (can save code size with MEM_LIBC_MALLOC if libc-malloc
+ is otherwise used)
+
+ 2009-01-28 Jonathan Larmour (suggested by Bill Bauerbach)
+ * ipv4/inet_chksum.c, ipv4/lwip/inet_chksum.h: inet_chksum_pseudo_partial()
+ is only used by UDPLITE at present, so conditionalise it.
+
+ 2008-12-03 Simon Goldschmidt (base on patch from Luca Ceresoli)
+ * autoip.c: checked in (slightly modified) patch #6683: Customizable AUTOIP
+ "seed" address. This should reduce AUTOIP conflicts if
+ LWIP_AUTOIP_CREATE_SEED_ADDR is overridden.
+
+ 2008-10-02 Jonathan Larmour and Rishi Khan
+ * sockets.c (lwip_accept): Return EWOULDBLOCK if would block on non-blocking
+ socket.
+
+ 2008-06-30 Simon Goldschmidt
+ * mem.c, opt.h, stats.h: fixed bug #21433: Calling mem_free/pbuf_free from
+ interrupt context isn't safe: LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT allows
+ mem_free to run between mem_malloc iterations. Added illegal counter for
+ mem stats.
+
+ 2008-06-27 Simon Goldschmidt
+ * stats.h/.c, some other files: patch #6483: stats module improvement:
+ Added defines to display each module's statistic individually, added stats
+ defines for MEM, MEMP and SYS modules, removed (unused) rexmit counter.
+
+ 2008-06-17 Simon Goldschmidt
+ * err.h: patch #6459: Made err_t overridable to use a more efficient type
+ (define LWIP_ERR_T in cc.h)
+
+ 2008-06-17 Simon Goldschmidt
+ * slipif.c: patch #6480: Added a configuration option for slipif for symmetry
+ to loopif
+
+ 2008-06-17 Simon Goldschmidt (patch by Luca Ceresoli)
+ * netif.c, loopif.c, ip.c, netif.h, loopif.h, opt.h: Checked in slightly
+ modified version of patch # 6370: Moved loopif code to netif.c so that
+ loopback traffic is supported on all netifs (all local IPs).
+ Added option to limit loopback packets for each netifs.
+
+
+ ++ Bugfixes:
+ 2009-08-12 Kieran Mansley
+ * tcp_in.c, tcp.c: Fix bug #27209: handle trimming of segments when
+ out of window or out of order properly
+
+ 2009-08-12 Kieran Mansley
+ * tcp_in.c: Fix bug #27199: use snd_wl2 instead of snd_wl1
+
+ 2009-07-28 Simon Goldschmidt
+ * mem.h: Fixed bug #27105: "realloc() cannot replace mem_realloc()"s
+
+ 2009-07-27 Kieran Mansley
+ * api.h api_msg.h netdb.h sockets.h: add missing #include directives
+
+ 2009-07-09 Kieran Mansley
+ * api_msg.c, sockets.c, api.h: BUG23240 use signed counters for
+ recv_avail and don't increment counters until message successfully
+ sent to mbox
+
+ 2009-06-25 Kieran Mansley
+ * api_msg.c api.h: BUG26722: initialise netconn write variables
+ in netconn_alloc
+
+ 2009-06-25 Kieran Mansley
+ * tcp.h: BUG26879: set ret value in TCP_EVENT macros when function is not set
+
+ 2009-06-25 Kieran Mansley
+ * tcp.c, tcp_in.c, tcp_out.c, tcp.h: BUG26301 and BUG26267: correct
+ simultaneous close behaviour, and make snd_nxt have the same meaning
+ as in the RFCs.
+
+ 2009-05-12 Simon Goldschmidt
+ * etharp.h, etharp.c, netif.c: fixed bug #26507: "Gratuitous ARP depends on
+ arp_table / uses etharp_query" by adding etharp_gratuitous()
+
+ 2009-05-12 Simon Goldschmidt
+ * ip.h, ip.c, igmp.c: bug #26487: Added ip_output_if_opt that can add IP options
+ to the IP header (used by igmp_ip_output_if)
+
+ 2009-05-06 Simon Goldschmidt
+ * inet_chksum.c: On little endian architectures, use LWIP_PLATFORM_HTONS (if
+ defined) for SWAP_BYTES_IN_WORD to speed up checksumming.
+
+ 2009-05-05 Simon Goldschmidt
+ * sockets.c: bug #26405: Prematurely released semaphore causes lwip_select()
+ to crash
+
+ 2009-05-04 Simon Goldschmidt
+ * init.c: snmp was not initialized in lwip_init()
+
+ 2009-05-04 Frdric Bernon
+ * dhcp.c, netbios.c: Changes if IP_SOF_BROADCAST is enabled.
+
+ 2009-05-03 Simon Goldschmidt
+ * tcp.h: bug #26349: Nagle algorithm doesn't send although segment is full
+ (and unsent->next == NULL)
+
+ 2009-05-02 Simon Goldschmidt
+ * tcpip.h, tcpip.c: fixed tcpip_untimeout (does not need the time, broken after
+ 1.3.0 in CVS only) - fixes compilation of ppp_oe.c
+
+ 2009-05-02 Simon Goldschmidt
+ * msg_in.c: fixed bug #25636: SNMPSET value is ignored for integer fields
+
+ 2009-05-01 Simon Goldschmidt
+ * pap.c: bug #21680: PPP upap_rauthnak() drops legal NAK packets
+
+ 2009-05-01 Simon Goldschmidt
+ * ppp.c: bug #24228: Memory corruption with PPP and DHCP
+
+ 2009-04-29 Frdric Bernon
+ * raw.c, udp.c, init.c, opt.h, ip.h, sockets.h: bug #26309: Implement the
+ SO(F)_BROADCAST filter for all API layers. Avoid the unindented reception
+ of broadcast packets even when this option wasn't set. Port maintainers
+ which want to enable this filter have to set IP_SOF_BROADCAST=1 in opt.h.
+ If you want this option also filter broadcast on recv operations, you also
+ have to set IP_SOF_BROADCAST_RECV=1 in opt.h.
+
+ 2009-04-28 Simon Goldschmidt, Jakob Stoklund Olesen
+ * dhcp.c: patch #6721, bugs #25575, #25576: Some small fixes to DHCP and
+ DHCP/AUTOIP cooperation
+
+ 2009-04-25 Simon Goldschmidt, Oleg Tyshev
+ * tcp_out.c: bug #24212: Deadlocked tcp_retransmit due to exceeded pcb->cwnd
+ Fixed by sorting the unsent and unacked queues (segments are inserted at the
+ right place in tcp_output and tcp_rexmit).
+
+ 2009-04-25 Simon Goldschmidt
+ * memp.c, mem.c, memp.h, mem_std.h: bug #26213 "Problem with memory allocation
+ when debugging": memp_sizes contained the wrong sizes (including sanity
+ regions); memp pools for MEM_USE_POOLS were too small
+
+ 2009-04-24 Simon Goldschmidt, Frdric Bernon
+ * inet.c: patch #6765: Fix a small problem with the last changes (incorrect
+ behavior, with with ip address string not ended by a '\0', a space or a
+ end of line)
+
+ 2009-04-19 Simon Goldschmidt
+ * rawapi.txt: Fixed bug #26069: Corrected documentation: if tcp_connect fails,
+ pcb->err is called, not pcb->connected (with an error code).
+
+ 2009-04-19 Simon Goldschmidt
+ * tcp_out.c: Fixed bug #26236: "TCP options (timestamp) don't work with
+ no-copy-tcpwrite": deallocate option data, only concat segments with same flags
+
+ 2009-04-19 Simon Goldschmidt
+ * tcp_out.c: Fixed bug #25094: "Zero-length pbuf" (options are now allocated
+ in the header pbuf, not the data pbuf)
+
+ 2009-04-18 Simon Goldschmidt
+ * api_msg.c: fixed bug #25695: Segmentation fault in do_writemore()
+
+ 2009-04-15 Simon Goldschmidt
+ * sockets.c: tried to fix bug #23559: lwip_recvfrom problem with tcp
+
+ 2009-04-15 Simon Goldschmidt
+ * dhcp.c: task #9192: mem_free of dhcp->options_in and dhcp->msg_in
+
+ 2009-04-15 Simon Goldschmidt
+ * ip.c, ip6.c, tcp_out.c, ip.h: patch #6808: Add a utility function
+ ip_hinted_output() (for smaller code mainly)
+
+ 2009-04-15 Simon Goldschmidt
+ * inet.c: patch #6765: Supporting new line characters in inet_aton()
+
+ 2009-04-15 Simon Goldschmidt
+ * dhcp.c: patch #6764: DHCP rebind and renew did not send hostnam option;
+ Converted constant OPTION_MAX_MSG_SIZE to netif->mtu, check if netif->mtu
+ is big enough in dhcp_start
+
+ 2009-04-15 Simon Goldschmidt
+ * netbuf.c: bug #26027: netbuf_chain resulted in pbuf memory leak
+
+ 2009-04-15 Simon Goldschmidt
+ * sockets.c, ppp.c: bug #25763: corrected 4 occurrences of SMEMCPY to MEMCPY
+
+ 2009-04-15 Simon Goldschmidt
+ * sockets.c: bug #26121: set_errno can be overridden
+
+ 2009-04-09 Kieran Mansley (patch from Luca Ceresoli )
+ * init.c, opt.h: Patch#6774 TCP_QUEUE_OOSEQ breaks compilation when
+ LWIP_TCP==0
+
+ 2009-04-09 Kieran Mansley (patch from Roy Lee )
+ * tcp.h: Patch#6802 Add do-while-clauses to those function like
+ macros in tcp.h
+
+ 2009-03-31 Kieran Mansley
+ * tcp.c, tcp_in.c, tcp_out.c, tcp.h, opt.h: Rework the way window
+ updates are calculated and sent (BUG20515)
+
+ * tcp_in.c: cope with SYN packets received during established states,
+ and retransmission of initial SYN.
+
+ * tcp_out.c: set push bit correctly when tcp segments are merged
+
+ 2009-03-27 Kieran Mansley
+ * tcp_out.c set window correctly on probes (correcting change made
+ yesterday)
+
+ 2009-03-26 Kieran Mansley
+ * tcp.c, tcp_in.c, tcp.h: add tcp_abandon() to cope with dropping
+ connections where no reset required (bug #25622)
+
+ * tcp_out.c: set TCP_ACK flag on keepalive and zero window probes
+ (bug #20779)
+
+ 2009-02-18 Simon Goldschmidt (Jonathan Larmour and Bill Auerbach)
+ * ip_frag.c: patch #6528: the buffer used for IP_FRAG_USES_STATIC_BUF could be
+ too small depending on MEM_ALIGNMENT
+
+ 2009-02-16 Simon Goldschmidt
+ * sockets.h/.c, api_*.h/.c: fixed arguments of socket functions to match the standard;
+ converted size argument of netconn_write to 'size_t'
+
+ 2009-02-16 Simon Goldschmidt
+ * tcp.h, tcp.c: fixed bug #24440: TCP connection close problem on 64-bit host
+ by moving accept callback function pointer to TCP_PCB_COMMON
+
+ 2009-02-12 Simon Goldschmidt
+ * dhcp.c: fixed bug #25345 (DHCPDECLINE is sent with "Maximum message size"
+ option)
+
+ 2009-02-11 Simon Goldschmidt
+ * dhcp.c: fixed bug #24480 (releasing old udp_pdb and pbuf in dhcp_start)
+
+ 2009-02-11 Simon Goldschmidt
+ * opt.h, api_msg.c: added configurable default valud for netconn->recv_bufsize:
+ RECV_BUFSIZE_DEFAULT (fixes bug #23726: pbuf pool exhaustion on slow recv())
+
+ 2009-02-10 Simon Goldschmidt
+ * tcp.c: fixed bug #25467: Listen backlog is not reset on timeout in SYN_RCVD:
+ Accepts_pending is decrease on a corresponding listen pcb when a connection
+ in state SYN_RCVD is close.
+
+ 2009-01-28 Jonathan Larmour
+ * pbuf.c: reclaim pbufs from TCP out-of-sequence segments if we run
+ out of pool pbufs.
+
+ 2008-12-19 Simon Goldschmidt
+ * many files: patch #6699: fixed some warnings on platform where sizeof(int) == 2
+
+ 2008-12-10 Tamas Somogyi, Frdric Bernon
+ * sockets.c: fixed bug #25051: lwip_recvfrom problem with udp: fromaddr and
+ port uses deleted netbuf.
+
+ 2008-10-18 Simon Goldschmidt
+ * tcp_in.c: fixed bug ##24596: Vulnerability on faulty TCP options length
+ in tcp_parseopt
+
+ 2008-10-15 Simon Goldschmidt
+ * ip_frag.c: fixed bug #24517: IP reassembly crashes on unaligned IP headers
+ by packing the struct ip_reass_helper.
+
+ 2008-10-03 David Woodhouse, Jonathan Larmour
+ * etharp.c (etharp_arp_input): Fix type aliasing problem copying ip address.
+
+ 2008-10-02 Jonathan Larmour
+ * dns.c: Hard-code structure sizes, to avoid issues on some compilers where
+ padding is included.
+
+ 2008-09-30 Jonathan Larmour
+ * sockets.c (lwip_accept): check addr isn't NULL. If it's valid, do an
+ assertion check that addrlen isn't NULL.
+
+ 2008-09-30 Jonathan Larmour
+ * tcp.c: Fix bug #24227, wrong error message in tcp_bind.
+
+ 2008-08-26 Simon Goldschmidt
+ * inet.h, ip_addr.h: fixed bug #24132: Cross-dependency between ip_addr.h and
+ inet.h -> moved declaration of struct in_addr from ip_addr.h to inet.h
+
+ 2008-08-14 Simon Goldschmidt
+ * api_msg.c: fixed bug #23847: do_close_internal references freed memory (when
+ tcp_close returns != ERR_OK)
+
+ 2008-07-08 Frdric Bernon
+ * stats.h: Fix some build bugs introduced with patch #6483 (missing some parameters
+ in macros, mainly if MEM_STATS=0 and MEMP_STATS=0).
+
+ 2008-06-24 Jonathan Larmour
+ * tcp_in.c: Fix for bug #23693 as suggested by Art R. Ensure cseg is unused
+ if tcp_seg_copy fails.
+
+ 2008-06-17 Simon Goldschmidt
+ * inet_chksum.c: Checked in some ideas of patch #6460 (loop optimizations)
+ and created defines for swapping bytes and folding u32 to u16.
+
+ 2008-05-30 Kieran Mansley
+ * tcp_in.c Remove redundant "if" statement, and use real rcv_wnd
+ rather than rcv_ann_wnd when deciding if packets are in-window.
+ Contributed by
+
+ 2008-05-30 Kieran Mansley
+ * mem.h: Fix BUG#23254. Change macro definition of mem_* to allow
+ passing as function pointers when MEM_LIBC_MALLOC is defined.
+
+ 2008-05-09 Jonathan Larmour
+ * err.h, err.c, sockets.c: Fix bug #23119: Reorder timeout error code to
+ stop it being treated as a fatal error.
+
+ 2008-04-15 Simon Goldschmidt
+ * dhcp.c: fixed bug #22804: dhcp_stop doesn't clear NETIF_FLAG_DHCP
+ (flag now cleared)
+
+ 2008-03-27 Simon Goldschmidt
+ * mem.c, tcpip.c, tcpip.h, opt.h: fixed bug #21433 (Calling mem_free/pbuf_free
+ from interrupt context isn't safe): set LWIP_USE_HEAP_FROM_INTERRUPT to 1
+ in lwipopts.h or use pbuf_free_callback(p)/mem_free_callback(m) to free pbufs
+ or heap memory from interrupt context
+
+ 2008-03-26 Simon Goldschmidt
+ * tcp_in.c, tcp.c: fixed bug #22249: division by zero could occur if a remote
+ host sent a zero mss as TCP option.
+
+
+(STABLE-1.3.0)
+
+ ++ New features:
+
+ 2008-03-10 Jonathan Larmour
+ * inet_chksum.c: Allow choice of one of the sample algorithms to be
+ made from lwipopts.h. Fix comment on how to override LWIP_CHKSUM.
+
+ 2008-01-22 Frdric Bernon
+ * tcp.c, tcp_in.c, tcp.h, opt.h: Rename LWIP_CALCULATE_EFF_SEND_MSS in
+ TCP_CALCULATE_EFF_SEND_MSS to have coherent TCP options names.
+
+ 2008-01-14 Frdric Bernon
+ * rawapi.txt, api_msg.c, tcp.c, tcp_in.c, tcp.h: changes for task #7675 "Enable
+ to refuse data on a TCP_EVENT_RECV call". Important, behavior changes for the
+ tcp_recv callback (see rawapi.txt).
+
+ 2008-01-14 Frdric Bernon, Marc Chaland
+ * ip.c: Integrate patch #6369" ip_input : checking before realloc".
+
+ 2008-01-12 Frdric Bernon
+ * tcpip.h, tcpip.c, api.h, api_lib.c, api_msg.c, sockets.c: replace the field
+ netconn::sem per netconn::op_completed like suggested for the task #7490
+ "Add return value to sys_mbox_post".
+
+ 2008-01-12 Frdric Bernon
+ * api_msg.c, opt.h: replace DEFAULT_RECVMBOX_SIZE per DEFAULT_TCP_RECVMBOX_SIZE,
+ DEFAULT_UDP_RECVMBOX_SIZE and DEFAULT_RAW_RECVMBOX_SIZE (to optimize queues
+ sizes), like suggested for the task #7490 "Add return value to sys_mbox_post".
+
+ 2008-01-10 Frdric Bernon
+ * tcpip.h, tcpip.c: add tcpip_callback_with_block function for the task #7490
+ "Add return value to sys_mbox_post". tcpip_callback is always defined as
+ "blocking" ("block" parameter = 1).
+
+ 2008-01-10 Frdric Bernon
+ * tcpip.h, tcpip.c, api.h, api_lib.c, api_msg.c, sockets.c: replace the field
+ netconn::mbox (sys_mbox_t) per netconn::sem (sys_sem_t) for the task #7490
+ "Add return value to sys_mbox_post".
+
+ 2008-01-05 Frdric Bernon
+ * sys_arch.txt, api.h, api_lib.c, api_msg.h, api_msg.c, tcpip.c, sys.h, opt.h:
+ Introduce changes for task #7490 "Add return value to sys_mbox_post" with some
+ modifications in the sys_mbox api: sys_mbox_new take a "size" parameters which
+ indicate the number of pointers query by the mailbox. There is three defines
+ in opt.h to indicate sizes for tcpip::mbox, netconn::recvmbox, and for the
+ netconn::acceptmbox. Port maintainers, you can decide to just add this new
+ parameter in your implementation, but to ignore it to keep the previous behavior.
+ The new sys_mbox_trypost function return a value to know if the mailbox is
+ full or if the message is posted. Take a look to sys_arch.txt for more details.
+ This new function is used in tcpip_input (so, can be called in an interrupt
+ context since the function is not blocking), and in recv_udp and recv_raw.
+
+ 2008-01-04 Frdric Bernon, Simon Goldschmidt, Jonathan Larmour
+ * rawapi.txt, api.h, api_lib.c, api_msg.h, api_msg.c, sockets.c, tcp.h, tcp.c,
+ tcp_in.c, init.c, opt.h: rename backlog options with TCP_ prefix, limit the
+ "backlog" parameter in an u8_t, 0 is interpreted as "smallest queue", add
+ documentation in the rawapi.txt file.
+
+ 2007-12-31 Kieran Mansley (based on patch from Per-Henrik Lundbolm)
+ * tcp.c, tcp_in.c, tcp_out.c, tcp.h: Add TCP persist timer
+
+ 2007-12-31 Frdric Bernon, Luca Ceresoli
+ * autoip.c, etharp.c: ip_addr.h: Integrate patch #6348: "Broadcast ARP packets
+ in autoip". The change in etharp_raw could be removed, since all calls to
+ etharp_raw use ethbroadcast for the "ethdst_addr" parameter. But it could be
+ wrong in the future.
+
+ 2007-12-30 Frdric Bernon, Tom Evans
+ * ip.c: Fix bug #21846 "LwIP doesn't appear to perform any IP Source Address
+ Filtering" reported by Tom Evans.
+
+ 2007-12-21 Frdric Bernon, Simon Goldschmidt, Jonathan Larmour
+ * tcp.h, opt.h, api.h, api_msg.h, tcp.c, tcp_in.c, api_lib.c, api_msg.c,
+ sockets.c, init.c: task #7252: Implement TCP listen backlog: Warning: raw API
+ applications have to call 'tcp_accepted(pcb)' in their accept callback to
+ keep accepting new connections.
+
+ 2007-12-13 Frdric Bernon
+ * api_msg.c, err.h, err.c, sockets.c, dns.c, dns.h: replace "enum dns_result"
+ by err_t type. Add a new err_t code "ERR_INPROGRESS".
+
+ 2007-12-12 Frdric Bernon
+ * dns.h, dns.c, opt.h: move DNS options to the "right" place. Most visibles
+ are the one which have ram usage.
+
+ 2007-12-05 Frdric Bernon
+ * netdb.c: add a LWIP_DNS_API_HOSTENT_STORAGE option to decide to use a static
+ set of variables (=0) or a local one (=1). In this last case, your port should
+ provide a function "struct hostent* sys_thread_hostent( struct hostent* h)"
+ which have to do a copy of "h" and return a pointer ont the "per-thread" copy.
+
+ 2007-12-03 Simon Goldschmidt
+ * ip.c: ip_input: check if a packet is for inp first before checking all other
+ netifs on netif_list (speeds up packet receiving in most cases)
+
+ 2007-11-30 Simon Goldschmidt
+ * udp.c, raw.c: task #7497: Sort lists (pcb, netif, ...) for faster access
+ UDP: move a (connected) pcb selected for input to the front of the list of
+ pcbs so that it is found faster next time. Same for RAW pcbs that have eaten
+ a packet.
+
+ 2007-11-28 Simon Goldschmidt
+ * etharp.c, stats.c, stats.h, opt.h: Introduced ETHARP_STATS
+
+ 2007-11-25 Simon Goldschmidt
+ * dhcp.c: dhcp_unfold_reply() uses pbuf_copy_partial instead of its own copy
+ algorithm.
+
+ 2007-11-24 Simon Goldschmidt
+ * netdb.h, netdb.c, sockets.h/.c: Moved lwip_gethostbyname from sockets.c
+ to the new file netdb.c; included lwip_getaddrinfo.
+
+ 2007-11-21 Simon Goldschmidt
+ * tcp.h, opt.h, tcp.c, tcp_in.c: implemented calculating the effective send-mss
+ based on the MTU of the netif used to send. Enabled by default. Disable by
+ setting LWIP_CALCULATE_EFF_SEND_MSS to 0. This fixes bug #21492.
+
+ 2007-11-19 Frdric Bernon
+ * api_msg.c, dns.h, dns.c: Implement DNS_DOES_NAME_CHECK option (check if name
+ received match the name query), implement DNS_USES_STATIC_BUF (the place where
+ copy dns payload to parse the response), return an error if there is no place
+ for a new query, and fix some minor problems.
+
+ 2007-11-16 Simon Goldschmidt
+ * new files: ipv4/inet.c, ipv4/inet_chksum.c, ipv6/inet6.c
+ removed files: core/inet.c, core/inet6.c
+ Moved inet files into ipv4/ipv6 directory; splitted inet.c/inet.h into
+ inet and chksum part; changed includes in all lwIP files as appropriate
+
+ 2007-11-16 Simon Goldschmidt
+ * api.h, api_msg.h, api_lib.c, api_msg.c, socket.h, socket.c: Added sequential
+ dns resolver function for netconn api (netconn_gethostbyname) and socket api
+ (gethostbyname/gethostbyname_r).
+
+ 2007-11-15 Jim Pettinato, Frdric Bernon
+ * opt.h, init.c, tcpip.c, dhcp.c, dns.h, dns.c: add DNS client for simple name
+ requests with RAW api interface. Initialization is done in lwip_init() with
+ build time options. DNS timer is added in tcpip_thread context. DHCP can set
+ DNS server ip addresses when options are received. You need to set LWIP_DNS=1
+ in your lwipopts.h file (LWIP_DNS=0 in opt.h). DNS_DEBUG can be set to get
+ some traces with LWIP_DEBUGF. Sanity check have been added. There is a "todo"
+ list with points to improve.
+
+ 2007-11-06 Simon Goldschmidt
+ * opt.h, mib2.c: Patch #6215: added ifAdminStatus write support (if explicitly
+ enabled by defining SNMP_SAFE_REQUESTS to 0); added code to check link status
+ for ifOperStatus if LWIP_NETIF_LINK_CALLBACK is defined.
+
+ 2007-11-06 Simon Goldschmidt
+ * api.h, api_msg.h and dependent files: Task #7410: Removed the need to include
+ core header files in api.h (ip/tcp/udp/raw.h) to hide the internal
+ implementation from netconn api applications.
+
+ 2007-11-03 Frdric Bernon
+ * api.h, api_lib.c, api_msg.c, sockets.c, opt.h: add SO_RCVBUF option for UDP &
+ RAW netconn. You need to set LWIP_SO_RCVBUF=1 in your lwipopts.h (it's disabled
+ by default). Netconn API users can use the netconn_recv_bufsize macro to access
+ it. This is a first release which have to be improve for TCP. Note it used the
+ netconn::recv_avail which need to be more "thread-safe" (note there is already
+ the problem for FIONREAD with lwip_ioctl/ioctlsocket).
+
+ 2007-11-01 Frdric Bernon, Marc Chaland
+ * sockets.h, sockets.c, api.h, api_lib.c, api_msg.h, api_msg.c, tcp.h, tcp_out.c:
+ Integrate "patch #6250 : MSG_MORE flag for send". MSG_MORE is used at socket api
+ layer, NETCONN_MORE at netconn api layer, and TCP_WRITE_FLAG_MORE at raw api
+ layer. This option enable to delayed TCP PUSH flag on multiple "write" calls.
+ Note that previous "copy" parameter for "write" APIs is now called "apiflags".
+
+ 2007-10-24 Frdric Bernon
+ * api.h, api_lib.c, api_msg.c: Add macro API_EVENT in the same spirit than
+ TCP_EVENT_xxx macros to get a code more readable. It could also help to remove
+ some code (like we have talk in "patch #5919 : Create compile switch to remove
+ select code"), but it could be done later.
+
+ 2007-10-08 Simon Goldschmidt
+ * many files: Changed initialization: many init functions are not needed any
+ more since we now rely on the compiler initializing global and static
+ variables to zero!
+
+ 2007-10-06 Simon Goldschmidt
+ * ip_frag.c, memp.c, mib2.c, ip_frag.h, memp_std.h, opt.h: Changed IP_REASSEMBLY
+ to enqueue the received pbufs so that multiple packets can be reassembled
+ simultaneously and no static reassembly buffer is needed.
+
+ 2007-10-05 Simon Goldschmidt
+ * tcpip.c, etharp.h, etharp.c: moved ethernet_input from tcpip.c to etharp.c so
+ all netifs (or ports) can use it.
+
+ 2007-10-05 Frdric Bernon
+ * netifapi.h, netifapi.c: add function netifapi_netif_set_default. Change the
+ common function to reduce a little bit the footprint (for all functions using
+ only the "netif" parameter).
+
+ 2007-10-03 Frdric Bernon
+ * netifapi.h, netifapi.c: add functions netifapi_netif_set_up, netifapi_netif_set_down,
+ netifapi_autoip_start and netifapi_autoip_stop. Use a common function to reduce
+ a little bit the footprint (for all functions using only the "netif" parameter).
+
+ 2007-09-15 Frdric Bernon
+ * udp.h, udp.c, sockets.c: Changes for "#20503 IGMP Improvement". Add IP_MULTICAST_IF
+ option in socket API, and a new field "multicast_ip" in "struct udp_pcb" (for
+ netconn and raw API users), only if LWIP_IGMP=1. Add getsockopt processing for
+ IP_MULTICAST_TTL and IP_MULTICAST_IF.
+
+ 2007-09-10 Frdric Bernon
+ * snmp.h, mib2.c: enable to remove SNMP timer (which consumne several cycles
+ even when it's not necessary). snmp_agent.txt tell to call snmp_inc_sysuptime()
+ each 10ms (but, it's intrusive if you use sys_timeout feature). Now, you can
+ decide to call snmp_add_sysuptime(100) each 1000ms (which is bigger "step", but
+ call to a lower frequency). Or, you can decide to not call snmp_inc_sysuptime()
+ or snmp_add_sysuptime(), and to define the SNMP_GET_SYSUPTIME(sysuptime) macro.
+ This one is undefined by default in mib2.c. SNMP_GET_SYSUPTIME is called inside
+ snmp_get_sysuptime(u32_t *value), and enable to change "sysuptime" value only
+ when it's queried (any direct call to "sysuptime" is changed by a call to
+ snmp_get_sysuptime).
+
+ 2007-09-09 Frdric Bernon, Bill Florac
+ * igmp.h, igmp.c, netif.h, netif.c, ip.c: To enable to have interfaces with IGMP,
+ and others without it, there is a new NETIF_FLAG_IGMP flag to set in netif->flags
+ if you want IGMP on an interface. igmp_stop() is now called inside netif_remove().
+ igmp_report_groups() is now called inside netif_set_link_up() (need to have
+ LWIP_NETIF_LINK_CALLBACK=1) to resend reports once the link is up (avoid to wait
+ the next query message to receive the matching multicast streams).
+
+ 2007-09-08 Frdric Bernon
+ * sockets.c, ip.h, api.h, tcp.h: declare a "struct ip_pcb" which only contains
+ IP_PCB. Add in the netconn's "pcb" union a "struct ip_pcb *ip;" (no size change).
+ Use this new field to access to common pcb fields (ttl, tos, so_options, etc...).
+ Enable to access to these fields with LWIP_TCP=0.
+
+ 2007-09-05 Frdric Bernon
+ * udp.c, ipv4/icmp.c, ipv4/ip.c, ipv6/icmp.c, ipv6/ip6.c, ipv4/icmp.h,
+ ipv6/icmp.h, opt.h: Integrate "task #7272 : LWIP_ICMP option". The new option
+ LWIP_ICMP enable/disable ICMP module inside the IP stack (enable per default).
+ Be careful, disabling ICMP make your product non-compliant to RFC1122, but
+ help to reduce footprint, and to reduce "visibility" on the Internet.
+
+ 2007-09-05 Frdric Bernon, Bill Florac
+ * opt.h, sys.h, tcpip.c, slipif.c, ppp.c, sys_arch.txt: Change parameters list
+ for sys_thread_new (see "task #7252 : Create sys_thread_new_ex()"). Two new
+ parameters have to be provided: a task name, and a task stack size. For this
+ one, since it's platform dependant, you could define the best one for you in
+ your lwipopts.h. For port maintainers, you can just add these new parameters
+ in your sys_arch.c file, and but it's not mandatory, use them in your OS
+ specific functions.
+
+ 2007-09-05 Frdric Bernon
+ * inet.c, autoip.c, msg_in.c, msg_out.c, init.c: Move some build time checkings
+ inside init.c for task #7142 "Sanity check user-configurable values".
+
+ 2007-09-04 Frdric Bernon, Bill Florac
+ * igmp.h, igmp.c, memp_std.h, memp.c, init.c, opt.h: Replace mem_malloc call by
+ memp_malloc, and use a new MEMP_NUM_IGMP_GROUP option (see opt.h to define the
+ value). It will avoid potential fragmentation problems, use a counter to know
+ how many times a group is used on an netif, and free it when all applications
+ leave it. MEMP_NUM_IGMP_GROUP got 8 as default value (and init.c got a sanity
+ check if LWIP_IGMP!=0).
+
+ 2007-09-03 Frdric Bernon
+ * igmp.h, igmp.c, sockets.c, api_msg.c: Changes for "#20503 IGMP Improvement".
+ Initialize igmp_mac_filter to NULL in netif_add (this field should be set in
+ the netif's "init" function). Use the "imr_interface" field (for socket layer)
+ and/or the "interface" field (for netconn layer), for join/leave operations.
+ The igmp_join/leavegroup first parameter change from a netif to an ipaddr.
+ This field could be a netif's ipaddr, or "any" (same meaning than ip_addr_isany).
+
+ 2007-08-30 Frdric Bernon
+ * Add netbuf.h, netbuf.c, Change api.h, api_lib.c: #7249 "Split netbuf functions
+ from api/api_lib". Now netbuf API is independant of netconn, and can be used
+ with other API (application based on raw API, or future "socket2" API). Ports
+ maintainers just have to add src/api/netbuf.c in their makefile/projects.
+
+ 2007-08-30 Frdric Bernon, Jonathan Larmour
+ * init.c: Add first version of lwip_sanity_check for task #7142 "Sanity check
+ user-configurable values".
+
+ 2007-08-29 Frdric Bernon
+ * igmp.h, igmp.c, tcpip.c, init.c, netif.c: change igmp_init and add igmp_start.
+ igmp_start is call inside netif_add. Now, igmp initialization is in the same
+ spirit than the others modules. Modify some IGMP debug traces.
+
+ 2007-08-29 Frdric Bernon
+ * Add init.h, init.c, Change opt.h, tcpip.c: Task #7213 "Add a lwip_init function"
+ Add lwip_init function to regroup all modules initializations, and to provide
+ a place to add code for task #7142 "Sanity check user-configurable values".
+ Ports maintainers should remove direct initializations calls from their code,
+ and add init.c in their makefiles. Note that lwip_init() function is called
+ inside tcpip_init, but can also be used by raw api users since all calls are
+ disabled when matching options are disabled. Also note that their is new options
+ in opt.h, you should configure in your lwipopts.h (they are enabled per default).
+
+ 2007-08-26 Marc Boucher
+ * api_msg.c: do_close_internal(): Reset the callbacks and arg (conn) to NULL
+ since they can under certain circumstances be called with an invalid conn
+ pointer after the connection has been closed (and conn has been freed).
+
+ 2007-08-25 Frdric Bernon (Artem Migaev's Patch)
+ * netif.h, netif.c: Integrate "patch #6163 : Function to check if link layer is up".
+ Add a netif_is_link_up() function if LWIP_NETIF_LINK_CALLBACK option is set.
+
+ 2007-08-22 Frdric Bernon
+ * netif.h, netif.c, opt.h: Rename LWIP_NETIF_CALLBACK in LWIP_NETIF_STATUS_CALLBACK
+ to be coherent with new LWIP_NETIF_LINK_CALLBACK option before next release.
+
+ 2007-08-22 Frdric Bernon
+ * tcpip.h, tcpip.c, ethernetif.c, opt.h: remove options ETHARP_TCPIP_INPUT &
+ ETHARP_TCPIP_ETHINPUT, now, only "ethinput" code is supported, even if the
+ name is tcpip_input (we keep the name of 1.2.0 function).
+
+ 2007-08-17 Jared Grubb
+ * memp_std.h, memp.h, memp.c, mem.c, stats.c: (Task #7136) Centralize mempool
+ settings into new memp_std.h and optional user file lwippools.h. This adds
+ more dynamic mempools, and allows the user to create an arbitrary number of
+ mempools for mem_malloc.
+
+ 2007-08-16 Marc Boucher
+ * api_msg.c: Initialize newconn->state to NETCONN_NONE in accept_function;
+ otherwise it was left to NETCONN_CLOSE and sent_tcp() could prematurely
+ close the connection.
+
+ 2007-08-16 Marc Boucher
+ * sockets.c: lwip_accept(): check netconn_peer() error return.
+
+ 2007-08-16 Marc Boucher
+ * mem.c, mem.h: Added mem_calloc().
+
+ 2007-08-16 Marc Boucher
+ * tcpip.c, tcpip.h memp.c, memp.h: Added distinct memp (MEMP_TCPIP_MSG_INPKT)
+ for input packets to prevent floods from consuming all of MEMP_TCPIP_MSG
+ and starving other message types.
+ Renamed MEMP_TCPIP_MSG to MEMP_TCPIP_MSG_API
+
+ 2007-08-16 Marc Boucher
+ * pbuf.c, pbuf.h, etharp.c, tcp_in.c, sockets.c: Split pbuf flags in pbuf
+ type and flgs (later renamed to flags).
+ Use enum pbuf_flag as pbuf_type. Renumber PBUF_FLAG_*.
+ Improved lwip_recvfrom(). TCP push now propagated.
+
+ 2007-08-16 Marc Boucher
+ * ethernetif.c, contrib/ports/various: ethbroadcast now a shared global
+ provided by etharp.
+
+ 2007-08-16 Marc Boucher
+ * ppp_oe.c ppp_oe.h, auth.c chap.c fsm.c lcp.c ppp.c ppp.h,
+ etharp.c ethernetif.c, etharp.h, opt.h tcpip.h, tcpip.c:
+ Added PPPoE support and various PPP improvements.
+
+ 2007-07-25 Simon Goldschmidt
+ * api_lib.c, ip_frag.c, pbuf.c, api.h, pbuf.h: Introduced pbuf_copy_partial,
+ making netbuf_copy_partial use this function.
+
+ 2007-07-25 Simon Goldschmidt
+ * tcp_in.c: Fix bug #20506: Slow start / initial congestion window starts with
+ 2 * mss (instead of 1 * mss previously) to comply with some newer RFCs and
+ other stacks.
+
+ 2007-07-13 Jared Grubb (integrated by Frdric Bernon)
+ * opt.h, netif.h, netif.c, ethernetif.c: Add new configuration option to add
+ a link callback in the netif struct, and functions to handle it. Be carefull
+ for port maintainers to add the NETIF_FLAG_LINK_UP flag (like in ethernetif.c)
+ if you want to be sure to be compatible with future changes...
+
+ 2007-06-30 Frdric Bernon
+ * sockets.h, sockets.c: Implement MSG_PEEK flag for recv/recvfrom functions.
+
+ 2007-06-21 Simon Goldschmidt
+ * etharp.h, etharp.c: Combined etharp_request with etharp_raw for both
+ LWIP_AUTOIP =0 and =1 to remove redundant code.
+
+ 2007-06-21 Simon Goldschmidt
+ * mem.c, memp.c, mem.h, memp.h, opt.h: task #6863: Introduced the option
+ MEM_USE_POOLS to use 4 pools with different sized elements instead of a
+ heap. This both prevents memory fragmentation and gives a higher speed
+ at the cost of more memory consumption. Turned off by default.
+
+ 2007-06-21 Simon Goldschmidt
+ * api_lib.c, api_msg.c, api.h, api_msg.h: Converted the length argument of
+ netconn_write (and therefore also api_msg_msg.msg.w.len) from u16_t into
+ int to be able to send a bigger buffer than 64K with one time (mainly
+ used from lwip_send).
+
+ 2007-06-21 Simon Goldschmidt
+ * tcp.h, api_msg.c: Moved the nagle algorithm from netconn_write/do_write
+ into a define (tcp_output_nagle) in tcp.h to provide it to raw api users, too.
+
+ 2007-06-21 Simon Goldschmidt
+ * api.h, api_lib.c, api_msg.c: Fixed bug #20021: Moved sendbuf-processing in
+ netconn_write from api_lib.c to api_msg.c to also prevent multiple context-
+ changes on low memory or empty send-buffer.
+
+ 2007-06-18 Simon Goldschmidt
+ * etharp.c, etharp.h: Changed etharp to use a defined hardware address length
+ of 6 to avoid loading netif->hwaddr_len every time (since this file is only
+ used for ethernet and struct eth_addr already had a defined length of 6).
+
+ 2007-06-17 Simon Goldschmidt
+ * sockets.c, sockets.h: Implemented socket options SO_NO_CHECK for UDP sockets
+ to disable UDP checksum generation on transmit.
+
+ 2007-06-13 Frdric Bernon, Simon Goldschmidt
+ * debug.h, api_msg.c: change LWIP_ERROR to use it to check errors like invalid
+ pointers or parameters, and let the possibility to redefined it in cc.h. Use
+ this macro to check "conn" parameter in api_msg.c functions.
+
+ 2007-06-11 Simon Goldschmidt
+ * sockets.c, sockets.h: Added UDP lite support for sockets
+
+ 2007-06-10 Simon Goldschmidt
+ * udp.h, opt.h, api_msg.c, ip.c, udp.c: Included switch LWIP_UDPLITE (enabled
+ by default) to switch off UDP-Lite support if not needed (reduces udp.c code
+ size)
+
+ 2007-06-09 Dominik Spies (integrated by Frdric Bernon)
+ * autoip.h, autoip.c, dhcp.h, dhcp.c, netif.h, netif.c, etharp.h, etharp.c, opt.h:
+ AutoIP implementation available for IPv4, with new options LWIP_AUTOIP and
+ LWIP_DHCP_AUTOIP_COOP if you want to cooperate with DHCP. Some tips to adapt
+ (see TODO mark in the source code).
+
+ 2007-06-09 Simon Goldschmidt
+ * etharp.h, etharp.c, ethernetif.c: Modified order of parameters for
+ etharp_output() to match netif->output so etharp_output() can be used
+ directly as netif->output to save one function call.
+
+ 2007-06-08 Simon Goldschmidt
+ * netif.h, ethernetif.c, slipif.c, loopif.c: Added define
+ NETIF_INIT_SNMP(netif, type, speed) to initialize per-netif snmp variables,
+ added initialization of those to ethernetif, slipif and loopif.
+
+ 2007-05-18 Simon Goldschmidt
+ * opt.h, ip_frag.c, ip_frag.h, ip.c: Added option IP_FRAG_USES_STATIC_BUF
+ (defaulting to off for now) that can be set to 0 to send fragmented
+ packets by passing PBUF_REFs down the stack.
+
+ 2007-05-23 Frdric Bernon
+ * api_lib.c: Implement SO_RCVTIMEO for accept and recv on TCP
+ connections, such present in patch #5959.
+
+ 2007-05-23 Frdric Bernon
+ * api.h, api_lib.c, api_msg.c, sockets.c: group the different NETCONN_UDPxxx
+ code in only one part...
+
+ 2007-05-18 Simon Goldschmidt
+ * opt.h, memp.h, memp.c: Added option MEMP_OVERFLOW_CHECK to check for memp
+ elements to overflow. This is achieved by adding some bytes before and after
+ each pool element (increasing their size, of course), filling them with a
+ prominent value and checking them on freeing the element.
+ Set it to 2 to also check every element in every pool each time memp_malloc()
+ or memp_free() is called (slower but more helpful).
+
+ 2007-05-10 Simon Goldschmidt
+ * opt.h, memp.h, memp.c, pbuf.c (see task #6831): use a new memp pool for
+ PBUF_POOL pbufs instead of the old pool implementation in pbuf.c to reduce
+ code size.
+
+ 2007-05-11 Frdric Bernon
+ * sockets.c, api_lib.c, api_msg.h, api_msg.c, netifapi.h, netifapi.c, tcpip.c:
+ Include a function pointer instead of a table index in the message to reduce
+ footprint. Disable some part of lwip_send and lwip_sendto if some options are
+ not set (LWIP_TCP, LWIP_UDP, LWIP_RAW).
+
+ 2007-05-10 Simon Goldschmidt
+ * *.h (except netif/ppp/*.h): Included patch #5448: include '#ifdef __cplusplus
+ \ extern "C" {' in all header files. Now you can write your application using
+ the lwIP stack in C++ and simply #include the core files. Note I have left
+ out the netif/ppp/*h header files for now, since I don't know which files are
+ included by applications and which are for internal use only.
+
+ 2007-05-09 Simon Goldschmidt
+ * opt.h, *.c/*.h: Included patch #5920: Create define to override C-library
+ memcpy. 2 Defines are created: MEMCPY() for normal memcpy, SMEMCPY() for
+ situations where some compilers might inline the copy and save a function
+ call. Also replaced all calls to memcpy() with calls to (S)MEMCPY().
+
+ 2007-05-08 Simon Goldschmidt
+ * mem.h: If MEM_LIBC_MALLOC==1, allow the defines (e.g. mem_malloc() -> malloc())
+ to be overriden in case the C-library malloc implementation is not protected
+ against concurrent access.
+
+ 2007-05-04 Simon Goldschmidt (Atte Kojo)
+ * etharp.c: Introduced fast one-entry-cache to speed up ARP lookup when sending
+ multiple packets to the same host.
+
+ 2007-05-04 Frdric Bernon, Jonathan Larmour
+ * sockets.c, api.h, api_lib.c, api_msg.h, api_msg.c: Fix bug #19162 "lwip_sento: a possible
+ to corrupt remote addr/port connection state". Reduce problems "not enought memory" with
+ netbuf (if we receive lot of datagrams). Improve lwip_sendto (only one exchange between
+ sockets api and api_msg which run in tcpip_thread context). Add netconn_sento function.
+ Warning, if you directly access to "fromaddr" & "fromport" field from netbuf struct,
+ these fields are now renamed "addr" & "port".
+
+ 2007-04-11 Jonathan Larmour
+ * sys.h, api_lib.c: Provide new sys_mbox_tryfetch function. Require ports to provide new
+ sys_arch_mbox_tryfetch function to get a message if one is there, otherwise return
+ with SYS_MBOX_EMPTY. sys_arch_mbox_tryfetch can be implemented as a function-like macro
+ by the port in sys_arch.h if desired.
+
+ 2007-04-06 Frdric Bernon, Simon Goldschmidt
+ * opt.h, tcpip.h, tcpip.c, netifapi.h, netifapi.c: New configuration option LWIP_NETIF_API
+ allow to use thread-safe functions to add/remove netif in list, and to start/stop dhcp
+ clients, using new functions from netifapi.h. Disable as default (no port change to do).
+
+ 2007-04-05 Frdric Bernon
+ * sockets.c: remplace ENOBUFS errors on alloc_socket by ENFILE to be more BSD compliant.
+
+ 2007-04-04 Simon Goldschmidt
+ * arch.h, api_msg.c, dhcp.c, msg_in.c, sockets.c: Introduced #define LWIP_UNUSED_ARG(x)
+ use this for and architecture-independent form to tell the compiler you intentionally
+ are not using this variable. Can be overriden in cc.h.
+
+ 2007-03-28 Frdric Bernon
+ * opt.h, netif.h, dhcp.h, dhcp.c: New configuration option LWIP_NETIF_HOSTNAME allow to
+ define a hostname in netif struct (this is just a pointer, so, you can use a hardcoded
+ string, point on one of your's ethernetif field, or alloc a string you will free yourself).
+ It will be used by DHCP to register a client hostname, but can also be use when you call
+ snmp_set_sysname.
+
+ 2007-03-28 Frdric Bernon
+ * netif.h, netif.c: A new NETIF_FLAG_ETHARP flag is defined in netif.h, to allow to
+ initialize a network interface's flag with. It tell this interface is an ethernet
+ device, and we can use ARP with it to do a "gratuitous ARP" (RFC 3220 "IP Mobility
+ Support for IPv4" section 4.6) when interface is "up" with netif_set_up().
+
+ 2007-03-26 Frdric Bernon, Jonathan Larmour
+ * opt.h, tcpip.c: New configuration option LWIP_ARP allow to disable ARP init at build
+ time if you only use PPP or SLIP. The default is enable. Note we don't have to call
+ etharp_init in your port's initilization sequence if you use tcpip.c, because this call
+ is done in tcpip_init function.
+
+ 2007-03-22 Frdric Bernon
+ * stats.h, stats.c, msg_in.c: Stats counters can be change to u32_t if necessary with the
+ new option LWIP_STATS_LARGE. If you need this option, define LWIP_STATS_LARGE to 1 in
+ your lwipopts.h. More, unused counters are not defined in the stats structs, and not
+ display by stats_display(). Note that some options (SYS_STATS and RAW_STATS) are defined
+ but never used. Fix msg_in.c with the correct #if test for a stat display.
+
+ 2007-03-21 Kieran Mansley
+ * netif.c, netif.h: Apply patch#4197 with some changes (originator: rireland@hmgsl.com).
+ Provides callback on netif up/down state change.
+
+ 2007-03-11 Frdric Bernon, Mace Gael, Steve Reynolds
+ * sockets.h, sockets.c, api.h, api_lib.c, api_msg.h, api_msg.c, igmp.h, igmp.c,
+ ip.c, netif.h, tcpip.c, opt.h:
+ New configuration option LWIP_IGMP to enable IGMP processing. Based on only one
+ filter per all network interfaces. Declare a new function in netif to enable to
+ control the MAC filter (to reduce lwIP traffic processing).
+
+ 2007-03-11 Frdric Bernon
+ * tcp.h, tcp.c, sockets.c, tcp_out.c, tcp_in.c, opt.h: Keepalive values can
+ be configured at run time with LWIP_TCP_KEEPALIVE, but don't change this
+ unless you know what you're doing (default are RFC1122 compliant). Note
+ that TCP_KEEPIDLE and TCP_KEEPINTVL have to be set in seconds.
+
+ 2007-03-08 Frdric Bernon
+ * tcp.h: Keepalive values can be configured at compile time, but don't change
+ this unless you know what you're doing (default are RFC1122 compliant).
+
+ 2007-03-08 Frdric Bernon
+ * sockets.c, api.h, api_lib.c, tcpip.c, sys.h, sys.c, err.c, opt.h:
+ Implement LWIP_SO_RCVTIMEO configuration option to enable/disable SO_RCVTIMEO
+ on UDP sockets/netconn.
+
+ 2007-03-08 Simon Goldschmidt
+ * snmp_msg.h, msg_in.c: SNMP UDP ports can be configured at compile time.
+
+ 2007-03-06 Frdric Bernon
+ * api.h, api_lib.c, sockets.h, sockets.c, tcpip.c, sys.h, sys.c, err.h:
+ Implement SO_RCVTIMEO on UDP sockets/netconn.
+
+ 2007-02-28 Kieran Mansley (based on patch from Simon Goldschmidt)
+ * api_lib.c, tcpip.c, memp.c, memp.h: make API msg structs allocated
+ on the stack and remove the API msg type from memp
+
+ 2007-02-26 Jonathan Larmour (based on patch from Simon Goldschmidt)
+ * sockets.h, sockets.c: Move socket initialization to new
+ lwip_socket_init() function.
+ NOTE: this changes the API with ports. Ports will have to be
+ updated to call lwip_socket_init() now.
+
+ 2007-02-26 Jonathan Larmour (based on patch from Simon Goldschmidt)
+ * api_lib.c: Use memcpy in netbuf_copy_partial.
+
+
+ ++ Bug fixes:
+
+ 2008-03-17 Frdric Bernon, Ed Kerekes
+ * igmp.h, igmp.c: Fix bug #22613 "IGMP iphdr problem" (could have
+ some problems to fill the IP header on some targets, use now the
+ ip.h macros to do it).
+
+ 2008-03-13 Frdric Bernon
+ * sockets.c: Fix bug #22435 "lwip_recvfrom with TCP break;". Using
+ (lwip_)recvfrom with valid "from" and "fromlen" parameters, on a
+ TCP connection caused a crash. Note that using (lwip_)recvfrom
+ like this is a bit slow and that using (lwip)getpeername is the
+ good lwip way to do it (so, using recv is faster on tcp sockets).
+
+ 2008-03-12 Frdric Bernon, Jonathan Larmour
+ * api_msg.c, contrib/apps/ping.c: Fix bug #22530 "api_msg.c's
+ recv_raw() does not consume data", and the ping sample (with
+ LWIP_SOCKET=1, the code did the wrong supposition that lwip_recvfrom
+ returned the IP payload, without the IP header).
+
+ 2008-03-04 Jonathan Larmour
+ * mem.c, stats.c, mem.h: apply patch #6414 to avoid compiler errors
+ and/or warnings on some systems where mem_size_t and size_t differ.
+ * pbuf.c, ppp.c: Fix warnings on some systems with mem_malloc.
+
+ 2008-03-04 Kieran Mansley (contributions by others)
+ * Numerous small compiler error/warning fixes from contributions to
+ mailing list after 1.3.0 release candidate made.
+
+ 2008-01-25 Cui hengbin (integrated by Frdric Bernon)
+ * dns.c: Fix bug #22108 "DNS problem" caused by unaligned structures.
+
+ 2008-01-15 Kieran Mansley
+ * tcp_out.c: BUG20511. Modify persist timer to start when we are
+ prevented from sending by a small send window, not just a zero
+ send window.
+
+ 2008-01-09 Jonathan Larmour
+ * opt.h, ip.c: Rename IP_OPTIONS define to IP_OPTIONS_ALLOWED to avoid
+ conflict with Linux system headers.
+
+ 2008-01-06 Jonathan Larmour
+ * dhcp.c: fix bug #19927: "DHCP NACK problem" by clearing any existing set IP
+ address entirely on receiving a DHCPNAK, and restarting discovery.
+
+ 2007-12-21 Simon Goldschmidt
+ * sys.h, api_lib.c, api_msg.c, sockets.c: fix bug #21698: "netconn->recv_avail
+ is not protected" by using new macros for interlocked access to modify/test
+ netconn->recv_avail.
+
+ 2007-12-20 Kieran Mansley (based on patch from Oleg Tyshev)
+ * tcp_in.c: fix bug# 21535 (nrtx not reset correctly in SYN_SENT state)
+
+ 2007-12-20 Kieran Mansley (based on patch from Per-Henrik Lundbolm)
+ * tcp.c, tcp_in.c, tcp_out.c, tcp.h: fix bug #20199 (better handling
+ of silly window avoidance and prevent lwIP from shrinking the window)
+
+ 2007-12-04 Simon Goldschmidt
+ * tcp.c, tcp_in.c: fix bug #21699 (segment leak in ooseq processing when last
+ data packet was lost): add assert that all segment lists are empty in
+ tcp_pcb_remove before setting pcb to CLOSED state; don't directly set CLOSED
+ state from LAST_ACK in tcp_process
+
+ 2007-12-02 Simon Goldschmidt
+ * sockets.h: fix bug #21654: exclude definition of struct timeval from #ifndef FD_SET
+ If including for system-struct timeval, LWIP_TIMEVAL_PRIVATE now
+ has to be set to 0 in lwipopts.h
+
+ 2007-12-02 Simon Goldschmidt
+ * api_msg.c, api_lib.c: fix bug #21656 (recvmbox problem in netconn API): always
+ allocate a recvmbox in netconn_new_with_proto_and_callback. For a tcp-listen
+ netconn, this recvmbox is later freed and a new mbox is allocated for acceptmbox.
+ This is a fix for thread-safety and allocates all items needed for a netconn
+ when the netconn is created.
+
+ 2007-11-30 Simon Goldschmidt
+ * udp.c: first attempt to fix bug #21655 (DHCP doesn't work reliably with multiple
+ netifs): if LWIP_DHCP is enabled, UDP packets to DHCP_CLIENT_PORT are passed
+ to netif->dhcp->pcb only (if that exists) and not to any other pcb for the same
+ port (only solution to let UDP pcbs 'bind' to a netif instead of an IP address)
+
+ 2007-11-27 Simon Goldschmidt
+ * ip.c: fixed bug #21643 (udp_send/raw_send don't fail if netif is down) by
+ letting ip_route only use netifs that are up.
+
+ 2007-11-27 Simon Goldschmidt
+ * err.h, api_lib.c, api_msg.c, sockets.c: Changed error handling: ERR_MEM, ERR_BUF
+ and ERR_RTE are seen as non-fatal, all other errors are fatal. netconns and
+ sockets block most operations once they have seen a fatal error.
+
+ 2007-11-27 Simon Goldschmidt
+ * udp.h, udp.c, dhcp.c: Implemented new function udp_sendto_if which takes the
+ netif to send as an argument (to be able to send on netifs that are down).
+
+ 2007-11-26 Simon Goldschmidt
+ * tcp_in.c: Fixed bug #21582: pcb->acked accounting can be wrong when ACKs
+ arrive out-of-order
+
+ 2007-11-21 Simon Goldschmidt
+ * tcp.h, tcp_out.c, api_msg.c: Fixed bug #20287: tcp_output_nagle sends too early
+ Fixed the nagle algorithm; nagle now also works for all raw API applications
+ and has to be explicitly disabled with 'tcp_pcb->flags |= TF_NODELAY'
+
+ 2007-11-12 Frdric Bernon
+ * sockets.c, api.h, api_lib.c, api_msg.h, api_msg.c: Fixed bug #20900. Now, most
+ of the netconn_peer and netconn_addr processing is done inside tcpip_thread
+ context in do_getaddr.
+
+ 2007-11-10 Simon Goldschmidt
+ * etharp.c: Fixed bug: assert fired when MEMP_ARP_QUEUE was empty (which can
+ happen any time). Now the packet simply isn't enqueued when out of memory.
+
+ 2007-11-01 Simon Goldschmidt
+ * tcp.c, tcp_in.c: Fixed bug #21494: The send mss (pcb->mss) is set to 536 (or
+ TCP_MSS if that is smaller) as long as no MSS option is received from the
+ remote host.
+
+ 2007-11-01 Simon Goldschmidt
+ * tcp.h, tcp.c, tcp_in.c: Fixed bug #21491: The MSS option sent (with SYN)
+ is now based on TCP_MSS instead of pcb->mss (on passive open now effectively
+ sending our configured TCP_MSS instead of the one received).
+
+ 2007-11-01 Simon Goldschmidt
+ * tcp_in.c: Fixed bug #21181: On active open, the initial congestion window was
+ calculated based on the configured TCP_MSS, not on the MSS option received
+ with SYN+ACK.
+
+ 2007-10-09 Simon Goldschmidt
+ * udp.c, inet.c, inet.h: Fixed UDPLite: send: Checksum was always generated too
+ short and also was generated wrong if checksum coverage != tot_len;
+ receive: checksum was calculated wrong if checksum coverage != tot_len
+
+ 2007-10-08 Simon Goldschmidt
+ * mem.c: lfree was not updated in mem_realloc!
+
+ 2007-10-07 Frdric Bernon
+ * sockets.c, api.h, api_lib.c: First step to fix "bug #20900 : Potential
+ crash error problem with netconn_peer & netconn_addr". VERY IMPORTANT:
+ this change cause an API breakage for netconn_addr, since a parameter
+ type change. Any compiler should cause an error without any changes in
+ yours netconn_peer calls (so, it can't be a "silent change"). It also
+ reduce a little bit the footprint for socket layer (lwip_getpeername &
+ lwip_getsockname use now a common lwip_getaddrname function since
+ netconn_peer & netconn_addr have the same parameters).
+
+ 2007-09-20 Simon Goldschmidt
+ * tcp.c: Fixed bug #21080 (tcp_bind without check pcbs in TIME_WAIT state)
+ by checking tcp_tw_pcbs also
+
+ 2007-09-19 Simon Goldschmidt
+ * icmp.c: Fixed bug #21107 (didn't reset IP TTL in ICMP echo replies)
+
+ 2007-09-15 Mike Kleshov
+ * mem.c: Fixed bug #21077 (inaccuracy in calculation of lwip_stat.mem.used)
+
+ 2007-09-06 Frdric Bernon
+ * several-files: replace some #include "arch/cc.h" by "lwip/arch.h", or simply remove
+ it as long as "lwip/opt.h" is included before (this one include "lwip/debug.h" which
+ already include "lwip/arch.h"). Like that, default defines are provided by "lwip/arch.h"
+ if they are not defined in cc.h, in the same spirit than "lwip/opt.h" for lwipopts.h.
+
+ 2007-08-30 Frdric Bernon
+ * igmp.h, igmp.c: Some changes to remove some redundant code, add some traces,
+ and fix some coding style.
+
+ 2007-08-28 Frdric Bernon
+ * tcpip.c: Fix TCPIP_MSG_INPKT processing: now, tcpip_input can be used for any
+ kind of packets. These packets are considered like Ethernet packets (payload
+ pointing to ethhdr) if the netif got the NETIF_FLAG_ETHARP flag. Else, packets
+ are considered like IP packets (payload pointing to iphdr).
+
+ 2007-08-27 Frdric Bernon
+ * api.h, api_lib.c, api_msg.c: First fix for "bug #20900 : Potential crash error
+ problem with netconn_peer & netconn_addr". Introduce NETCONN_LISTEN netconn_state
+ and remove obsolete ones (NETCONN_RECV & NETCONN_ACCEPT).
+
+ 2007-08-24 Kieran Mansley
+ * inet.c Modify (acc >> 16) test to ((acc >> 16) != 0) to help buggy
+ compiler (Paradigm C++)
+
+ 2007-08-09 Frdric Bernon, Bill Florac
+ * stats.h, stats.c, igmp.h, igmp.c, opt.h: Fix for bug #20503 : IGMP Improvement.
+ Introduce IGMP_STATS to centralize statistics management.
+
+ 2007-08-09 Frdric Bernon, Bill Florac
+ * udp.c: Fix for bug #20503 : IGMP Improvement. Enable to receive a multicast
+ packet on a udp pcb binded on an netif's IP address, and not on "any".
+
+ 2007-08-09 Frdric Bernon, Bill Florac
+ * igmp.h, igmp.c, ip.c: Fix minor changes from bug #20503 : IGMP Improvement.
+ This is mainly on using lookup/lookfor, and some coding styles...
+
+ 2007-07-26 Frdric Bernon (and "thedoctor")
+ * igmp.c: Fix bug #20595 to accept IGMPv3 "Query" messages.
+
+ 2007-07-25 Simon Goldschmidt
+ * api_msg.c, tcp.c: Another fix for bug #20021: by not returning an error if
+ tcp_output fails in tcp_close, the code in do_close_internal gets simpler
+ (tcp_output is called again later from tcp timers).
+
+ 2007-07-25 Simon Goldschmidt
+ * ip_frag.c: Fixed bug #20429: use the new pbuf_copy_partial instead of the old
+ copy_from_pbuf, which illegally modified the given pbuf.
+
+ 2007-07-25 Simon Goldschmidt
+ * tcp_out.c: tcp_enqueue: pcb->snd_queuelen didn't work for chaine PBUF_RAMs:
+ changed snd_queuelen++ to snd_queuelen += pbuf_clen(p).
+
+ 2007-07-24 Simon Goldschmidt
+ * api_msg.c, tcp.c: Fix bug #20480: Check the pcb passed to tcp_listen() for the
+ correct state (must be CLOSED).
+
+ 2007-07-13 Thomas Taranowski (commited by Jared Grubb)
+ * memp.c: Fix bug #20478: memp_malloc returned NULL+MEMP_SIZE on failed
+ allocation. It now returns NULL.
+
+ 2007-07-13 Frdric Bernon
+ * api_msg.c: Fix bug #20318: api_msg "recv" callbacks don't call pbuf_free in
+ all error cases.
+
+ 2007-07-13 Frdric Bernon
+ * api_msg.c: Fix bug #20315: possible memory leak problem if tcp_listen failed,
+ because current code doesn't follow rawapi.txt documentation.
+
+ 2007-07-13 Kieran Mansley
+ * src/core/tcp_in.c Apply patch#5741 from Oleg Tyshev to fix bug in
+ out of sequence processing of received packets
+
+ 2007-07-03 Simon Goldschmidt
+ * nearly-all-files: Added assertions where PBUF_RAM pbufs are used and an
+ assumption is made that this pbuf is in one piece (i.e. not chained). These
+ assumptions clash with the possibility of converting to fully pool-based
+ pbuf implementations, where PBUF_RAM pbufs might be chained.
+
+ 2007-07-03 Simon Goldschmidt
+ * api.h, api_lib.c, api_msg.c: Final fix for bug #20021 and some other problems
+ when closing tcp netconns: removed conn->sem, less context switches when
+ closing, both netconn_close and netconn_delete should safely close tcp
+ connections.
+
+ 2007-07-02 Simon Goldschmidt
+ * ipv4/ip.h, ipv6/ip.h, opt.h, netif.h, etharp.h, ipv4/ip.c, netif.c, raw.c,
+ tcp_out.c, udp.c, etharp.c: Added option LWIP_NETIF_HWADDRHINT (default=off)
+ to cache ARP table indices with each pcb instead of single-entry cache for
+ the complete stack.
+
+ 2007-07-02 Simon Goldschmidt
+ * tcp.h, tcp.c, tcp_in.c, tcp_out.c: Added some ASSERTS and casts to prevent
+ warnings when assigning to smaller types.
+
+ 2007-06-28 Simon Goldschmidt
+ * tcp_out.c: Added check to prevent tcp_pcb->snd_queuelen from overflowing.
+
+ 2007-06-28 Simon Goldschmidt
+ * tcp.h: Fixed bug #20287: Fixed nagle algorithm (sending was done too early if
+ a segment contained chained pbufs)
+
+ 2007-06-28 Frdric Bernon
+ * autoip.c: replace most of rand() calls by a macro LWIP_AUTOIP_RAND which compute
+ a "pseudo-random" value based on netif's MAC and some autoip fields. It's always
+ possible to define this macro in your own lwipopts.h to always use C library's
+ rand(). Note that autoip_create_rand_addr doesn't use this macro.
+
+ 2007-06-28 Frdric Bernon
+ * netifapi.h, netifapi.c, tcpip.h, tcpip.c: Update code to handle the option
+ LWIP_TCPIP_CORE_LOCKING, and do some changes to be coherent with last modifications
+ in api_lib/api_msg (use pointers and not type with table, etc...)
+
+ 2007-06-26 Simon Goldschmidt
+ * udp.h: Fixed bug #20259: struct udp_hdr was lacking the packin defines.
+
+ 2007-06-25 Simon Goldschmidt
+ * udp.c: Fixed bug #20253: icmp_dest_unreach was called with a wrong p->payload
+ for udp packets with no matching pcb.
+
+ 2007-06-25 Simon Goldschmidt
+ * udp.c: Fixed bug #20220: UDP PCB search in udp_input(): a non-local match
+ could get udp input packets if the remote side matched.
+
+ 2007-06-13 Simon Goldschmidt
+ * netif.c: Fixed bug #20180 (TCP pcbs listening on IP_ADDR_ANY could get
+ changed in netif_set_ipaddr if previous netif->ip_addr.addr was 0.
+
+ 2007-06-13 Simon Goldschmidt
+ * api_msg.c: pcb_new sets conn->err if protocol is not implemented
+ -> netconn_new_..() does not allocate a new connection for unsupported
+ protocols.
+
+ 2007-06-13 Frdric Bernon, Simon Goldschmidt
+ * api_lib.c: change return expression in netconn_addr and netconn_peer, because
+ conn->err was reset to ERR_OK without any reasons (and error was lost)...
+
+ 2007-06-13 Frdric Bernon, Matthias Weisser
+ * opt.h, mem.h, mem.c, memp.c, pbuf.c, ip_frag.c, vj.c: Fix bug #20162. Rename
+ MEM_ALIGN in LWIP_MEM_ALIGN and MEM_ALIGN_SIZE in LWIP_MEM_ALIGN_SIZE to avoid
+ some macro names collision with some OS macros.
+
+ 2007-06-11 Simon Goldschmidt
+ * udp.c: UDP Lite: corrected the use of chksum_len (based on RFC3828: if it's 0,
+ create checksum over the complete packet. On RX, if it's < 8 (and not 0),
+ discard the packet. Also removed the duplicate 'udphdr->chksum = 0' for both
+ UDP & UDP Lite.
+
+ 2007-06-11 Srinivas Gollakota & Oleg Tyshev
+ * tcp_out.c: Fix for bug #20075 : "A problem with keep-alive timer and TCP flags"
+ where TCP flags wasn't initialized in tcp_keepalive.
+
+ 2007-06-03 Simon Goldschmidt
+ * udp.c: udp_input(): Input pbuf was not freed if pcb had no recv function
+ registered, p->payload was modified without modifying p->len if sending
+ icmp_dest_unreach() (had no negative effect but was definitively wrong).
+
+ 2007-06-03 Simon Goldschmidt
+ * icmp.c: Corrected bug #19937: For responding to an icmp echo request, icmp
+ re-used the input pbuf even if that didn't have enough space to include the
+ link headers. Now the space is tested and a new pbuf is allocated for the
+ echo response packet if the echo request pbuf isn't big enough.
+
+ 2007-06-01 Simon Goldschmidt
+ * sockets.c: Checked in patch #5914: Moved sockopt processing into tcpip_thread.
+
+ 2007-05-23 Frdric Bernon
+ * api_lib.c, sockets.c: Fixed bug #5958 for netconn_listen (acceptmbox only
+ allocated by do_listen if success) and netconn_accept errors handling. In
+ most of api_lib functions, we replace some errors checkings like "if (conn==NULL)"
+ by ASSERT, except for netconn_delete.
+
+ 2007-05-23 Frdric Bernon
+ * api_lib.c: Fixed bug #5957 "Safe-thread problem inside netconn_recv" to return
+ an error code if it's impossible to fetch a pbuf on a TCP connection (and not
+ directly close the recvmbox).
+
+ 2007-05-22 Simon Goldschmidt
+ * tcp.c: Fixed bug #1895 (tcp_bind not correct) by introducing a list of
+ bound but unconnected (and non-listening) tcp_pcbs.
+
+ 2007-05-22 Frdric Bernon
+ * sys.h, sys.c, api_lib.c, tcpip.c: remove sys_mbox_fetch_timeout() (was only
+ used for LWIP_SO_RCVTIMEO option) and use sys_arch_mbox_fetch() instead of
+ sys_mbox_fetch() in api files. Now, users SHOULD NOT use internal lwIP features
+ like "sys_timeout" in their application threads.
+
+ 2007-05-22 Frdric Bernon
+ * api.h, api_lib.c, api_msg.h, api_msg.c: change the struct api_msg_msg to see
+ which parameters are used by which do_xxx function, and to avoid "misusing"
+ parameters (patch #5938).
+
+ 2007-05-22 Simon Goldschmidt
+ * api_lib.c, api_msg.c, raw.c, api.h, api_msg.h, raw.h: Included patch #5938:
+ changed raw_pcb.protocol from u16_t to u8_t since for IPv4 and IPv6, proto
+ is only 8 bits wide. This affects the api, as there, the protocol was
+ u16_t, too.
+
+ 2007-05-18 Simon Goldschmidt
+ * memp.c: addition to patch #5913: smaller pointer was returned but
+ memp_memory was the same size -> did not save memory.
+
+ 2007-05-16 Simon Goldschmidt
+ * loopif.c, slipif.c: Fix bug #19729: free pbuf if netif->input() returns
+ != ERR_OK.
+
+ 2007-05-16 Simon Goldschmidt
+ * api_msg.c, udp.c: If a udp_pcb has a local_ip set, check if it is the same
+ as the one of the netif used for sending to prevent sending from old
+ addresses after a netif address gets changed (partly fixes bug #3168).
+
+ 2007-05-16 Frdric Bernon
+ * tcpip.c, igmp.h, igmp.c: Fixed bug "#19800 : IGMP: igmp_tick() will not work
+ with NO_SYS=1". Note that igmp_init is always in tcpip_thread (and not in
+ tcpip_init) because we have to be sure that network interfaces are already
+ added (mac filter is updated only in igmp_init for the moment).
+
+ 2007-05-16 Simon Goldschmidt
+ * mem.c, memp.c: Removed semaphores from memp, changed sys_sem_wait calls
+ into sys_arch_sem_wait calls to prevent timers from running while waiting
+ for the heap. This fixes bug #19167.
+
+ 2007-05-13 Simon Goldschmidt
+ * tcp.h, sockets.h, sockets.c: Fixed bug from patch #5865 by moving the defines
+ for socket options (lwip_set/-getsockopt) used with level IPPROTO_TCP from
+ tcp.h to sockets.h.
+
+ 2007-05-07 Simon Goldschmidt
+ * mem.c: Another attempt to fix bug #17922.
+
+ 2007-05-04 Simon Goldschmidt
+ * pbuf.c, pbuf.h, etharp.c: Further update to ARP queueing: Changed pbuf_copy()
+ implementation so that it can be reused (don't allocate the target
+ pbuf inside pbuf_copy()).
+
+ 2007-05-04 Simon Goldschmidt
+ * memp.c: checked in patch #5913: in memp_malloc() we can return memp as mem
+ to save a little RAM (next pointer of memp is not used while not in pool).
+
+ 2007-05-03 "maq"
+ * sockets.c: Fix ioctl FIONREAD when some data remains from last recv.
+ (patch #3574).
+
+ 2007-04-23 Simon Goldschmidt
+ * loopif.c, loopif.h, opt.h, src/netif/FILES: fix bug #2595: "loopif results
+ in NULL reference for incoming TCP packets". Loopif has to be configured
+ (using LWIP_LOOPIF_MULTITHREADING) to directly call netif->input()
+ (multithreading environments, e.g. netif->input() = tcpip_input()) or
+ putting packets on a list that is fed to the stack by calling loopif_poll()
+ (single-thread / NO_SYS / polling environment where e.g.
+ netif->input() = ip_input).
+
+ 2007-04-17 Jonathan Larmour
+ * pbuf.c: Use s32_t in pbuf_realloc(), as an s16_t can't reliably hold
+ the difference between two u16_t's.
+ * sockets.h: FD_SETSIZE needs to match number of sockets, which is
+ MEMP_NUM_NETCONN in sockets.c right now.
+
+ 2007-04-12 Jonathan Larmour
+ * icmp.c: Reset IP header TTL in ICMP ECHO responses (bug #19580).
+
+ 2007-04-12 Kieran Mansley
+ * tcp.c, tcp_in.c, tcp_out.c, tcp.h: Modify way the retransmission
+ timer is reset to fix bug#19434, with help from Oleg Tyshev.
+
+ 2007-04-11 Simon Goldschmidt
+ * etharp.c, pbuf.c, pbuf.h: 3rd fix for bug #11400 (arp-queuing): More pbufs than
+ previously thought need to be copied (everything but PBUF_ROM!). Cleaned up
+ pbuf.c: removed functions no needed any more (by etharp).
+
+ 2007-04-11 Kieran Mansley
+ * inet.c, ip_addr.h, sockets.h, sys.h, tcp.h: Apply patch #5745: Fix
+ "Constant is long" warnings with 16bit compilers. Contributed by
+ avatar@mmlab.cse.yzu.edu.tw
+
+ 2007-04-05 Frdric Bernon, Jonathan Larmour
+ * api_msg.c: Fix bug #16830: "err_tcp() posts to connection mailbox when no pend on
+ the mailbox is active". Now, the post is only done during a connect, and do_send,
+ do_write and do_join_leave_group don't do anything if a previous error was signaled.
+
+ 2007-04-03 Frdric Bernon
+ * ip.c: Don't set the IP_DF ("Don't fragment") flag in the IP header in IP output
+ packets. See patch #5834.
+
+ 2007-03-30 Frdric Bernon
+ * api_msg.c: add a "pcb_new" helper function to avoid redundant code, and to add
+ missing pcb allocations checking (in do_bind, and for each raw_new). Fix style.
+
+ 2007-03-30 Frdric Bernon
+ * most of files: prefix all debug.h define with "LWIP_" to avoid any conflict with
+ others environment defines (these were too "generic").
+
+ 2007-03-28 Frdric Bernon
+ * api.h, api_lib.c, sockets.c: netbuf_ref doesn't check its internal pbuf_alloc call
+ result and can cause a crash. lwip_send now check netbuf_ref result.
+
+ 2007-03-28 Simon Goldschmidt
+ * sockets.c Remove "#include " from sockets.c to avoid multiple
+ definition of macros (in errno.h and lwip/arch.h) if LWIP_PROVIDE_ERRNO is
+ defined. This is the way it should have been already (looking at
+ doc/sys_arch.txt)
+
+ 2007-03-28 Kieran Mansley
+ * opt.h Change default PBUF_POOL_BUFSIZE (again) to accomodate default MSS +
+ IP and TCP headers *and* physical link headers
+
+ 2007-03-26 Frdric Bernon (based on patch from Dmitry Potapov)
+ * api_lib.c: patch for netconn_write(), fixes a possible race condition which cause
+ to send some garbage. It is not a definitive solution, but the patch does solve
+ the problem for most cases.
+
+ 2007-03-22 Frdric Bernon
+ * api_msg.h, api_msg.c: Remove obsolete API_MSG_ACCEPT and do_accept (never used).
+
+ 2007-03-22 Frdric Bernon
+ * api_lib.c: somes resources couldn't be freed if there was errors during
+ netconn_new_with_proto_and_callback.
+
+ 2007-03-22 Frdric Bernon
+ * ethernetif.c: update netif->input calls to check return value. In older ports,
+ it's a good idea to upgrade them, even if before, there could be another problem
+ (access to an uninitialized mailbox).
+
+ 2007-03-21 Simon Goldschmidt
+ * sockets.c: fixed bug #5067 (essentialy a signed/unsigned warning fixed
+ by casting to unsigned).
+
+ 2007-03-21 Frdric Bernon
+ * api_lib.c, api_msg.c, tcpip.c: integrate sys_mbox_fetch(conn->mbox, NULL) calls from
+ api_lib.c to tcpip.c's tcpip_apimsg(). Now, use a local variable and not a
+ dynamic one from memp to send tcpip_msg to tcpip_thread in a synchrone call.
+ Free tcpip_msg from tcpip_apimsg is not done in tcpip_thread. This give a
+ faster and more reliable communication between api_lib and tcpip.
+
+ 2007-03-21 Frdric Bernon
+ * opt.h: Add LWIP_NETIF_CALLBACK (to avoid compiler warning) and set it to 0.
+
+ 2007-03-21 Frdric Bernon
+ * api_msg.c, igmp.c, igmp.h: Fix C++ style comments
+
+ 2007-03-21 Kieran Mansley
+ * opt.h Change default PBUF_POOL_BUFSIZE to accomodate default MSS +
+ IP and TCP headers
+
+ 2007-03-21 Kieran Mansley
+ * Fix all uses of pbuf_header to check the return value. In some
+ cases just assert if it fails as I'm not sure how to fix them, but
+ this is no worse than before when they would carry on regardless
+ of the failure.
+
+ 2007-03-21 Kieran Mansley
+ * sockets.c, igmp.c, igmp.h, memp.h: Fix C++ style comments and
+ comment out missing header include in icmp.c
+
+ 2007-03-20 Frdric Bernon
+ * memp.h, stats.c: Fix stats_display function where memp_names table wasn't
+ synchronized with memp.h.
+
+ 2007-03-20 Frdric Bernon
+ * tcpip.c: Initialize tcpip's mbox, and verify if initialized in tcpip_input,
+ tcpip_ethinput, tcpip_callback, tcpip_apimsg, to fix a init problem with
+ network interfaces. Also fix a compiler warning.
+
+ 2007-03-20 Kieran Mansley
+ * udp.c: Only try and use pbuf_header() to make space for headers if
+ not a ROM or REF pbuf.
+
+ 2007-03-19 Frdric Bernon
+ * api_msg.h, api_msg.c, tcpip.h, tcpip.c: Add return types to tcpip_apimsg()
+ and api_msg_post().
+
+ 2007-03-19 Frdric Bernon
+ * Remove unimplemented "memp_realloc" function from memp.h.
+
+ 2007-03-11 Simon Goldschmidt
+ * pbuf.c: checked in patch #5796: pbuf_alloc: len field claculation caused
+ memory corruption.
+
+ 2007-03-11 Simon Goldschmidt (based on patch from Dmitry Potapov)
+ * api_lib.c, sockets.c, api.h, api_msg.h, sockets.h: Fixed bug #19251
+ (missing `const' qualifier in socket functions), to get more compatible to
+ standard POSIX sockets.
+
+ 2007-03-11 Frdric Bernon (based on patch from Dmitry Potapov)
+ * sockets.c: Add asserts inside bind, connect and sendto to check input
+ parameters. Remove excessive set_errno() calls after get_socket(), because
+ errno is set inside of get_socket(). Move last sock_set_errno() inside
+ lwip_close.
+
+ 2007-03-09 Simon Goldschmidt
+ * memp.c: Fixed bug #11400: New etharp queueing introduced bug: memp_memory
+ was allocated too small.
+
+ 2007-03-06 Simon Goldschmidt
+ * tcpip.c: Initialize dhcp timers in tcpip_thread (if LWIP_DHCP) to protect
+ the stack from concurrent access.
+
+ 2007-03-06 Frdric Bernon, Dmitry Potapov
+ * tcpip.c, ip_frag.c, ethernetif.c: Fix some build problems, and a redundancy
+ call to "lwip_stats.link.recv++;" in low_level_input() & ethernetif_input().
+
+ 2007-03-06 Simon Goldschmidt
+ * ip_frag.c, ip_frag.h: Reduce code size: don't include code in those files
+ if IP_FRAG == 0 and IP_REASSEMBLY == 0
+
+ 2007-03-06 Frdric Bernon, Simon Goldschmidt
+ * opt.h, ip_frag.h, tcpip.h, tcpip.c, ethernetif.c: add new configuration
+ option named ETHARP_TCPIP_ETHINPUT, which enable the new tcpip_ethinput.
+ Allow to do ARP processing for incoming packets inside tcpip_thread
+ (protecting ARP layer against concurrent access). You can also disable
+ old code using tcp_input with new define ETHARP_TCPIP_INPUT set to 0.
+ Older ports have to use tcpip_ethinput.
+
+ 2007-03-06 Simon Goldschmidt (based on patch from Dmitry Potapov)
+ * err.h, err.c: fixed compiler warning "initialization dircards qualifiers
+ from pointer target type"
+
+ 2007-03-05 Frdric Bernon
+ * opt.h, sockets.h: add new configuration options (LWIP_POSIX_SOCKETS_IO_NAMES,
+ ETHARP_TRUST_IP_MAC, review SO_REUSE)
+
+ 2007-03-04 Frdric Bernon
+ * api_msg.c: Remove some compiler warnings : parameter "pcb" was never
+ referenced.
+
+ 2007-03-04 Frdric Bernon
+ * api_lib.c: Fix "[patch #5764] api_lib.c cleanup: after patch #5687" (from
+ Dmitry Potapov).
+ The api_msg struct stay on the stack (not moved to netconn struct).
+
+ 2007-03-04 Simon Goldschmidt (based on patch from Dmitry Potapov)
+ * pbuf.c: Fix BUG#19168 - pbuf_free can cause deadlock (if
+ SYS_LIGHTWEIGHT_PROT=1 & freeing PBUF_RAM when mem_sem is not available)
+ Also fixed cast warning in pbuf_alloc()
+
+ 2007-03-04 Simon Goldschmidt
+ * etharp.c, etharp.h, memp.c, memp.h, opt.h: Fix BUG#11400 - don't corrupt
+ existing pbuf chain when enqueuing multiple pbufs to a pending ARP request
+
+ 2007-03-03 Frdric Bernon
+ * udp.c: remove obsolete line "static struct udp_pcb *pcb_cache = NULL;"
+ It is static, and never used in udp.c except udp_init().
+
+ 2007-03-02 Simon Goldschmidt
+ * tcpip.c: Moved call to ip_init(), udp_init() and tcp_init() from
+ tcpip_thread() to tcpip_init(). This way, raw API connections can be
+ initialized before tcpip_thread is running (e.g. before OS is started)
+
+ 2007-03-02 Frdric Bernon
+ * rawapi.txt: Fix documentation mismatch with etharp.h about etharp_tmr's call
+ interval.
+
+ 2007-02-28 Kieran Mansley
+ * pbuf.c: Fix BUG#17645 - ensure pbuf payload pointer is not moved
+ outside the region of the pbuf by pbuf_header()
+
+ 2007-02-28 Kieran Mansley
+ * sockets.c: Fix BUG#19161 - ensure milliseconds timeout is non-zero
+ when supplied timeout is also non-zero
+
+(STABLE-1.2.0)
+
+ 2006-12-05 Leon Woestenberg
+ * CHANGELOG: Mention STABLE-1.2.0 release.
+
+ ++ New features:
+
+ 2006-12-01 Christiaan Simons
+ * mem.h, opt.h: Added MEM_LIBC_MALLOC option.
+ Note this is a workaround. Currently I have no other options left.
+
+ 2006-10-26 Christiaan Simons (accepted patch by Jonathan Larmour)
+ * ipv4/ip_frag.c: rename MAX_MTU to IP_FRAG_MAX_MTU and move define
+ to include/lwip/opt.h.
+ * ipv4/lwip/ip_frag.h: Remove unused IP_REASS_INTERVAL.
+ Move IP_REASS_MAXAGE and IP_REASS_BUFSIZE to include/lwip/opt.h.
+ * opt.h: Add above new options.
+
+ 2006-08-18 Christiaan Simons
+ * tcp_{in,out}.c: added SNMP counters.
+ * ipv4/ip.c: added SNMP counters.
+ * ipv4/ip_frag.c: added SNMP counters.
+
+ 2006-08-08 Christiaan Simons
+ * etharp.{c,h}: added etharp_find_addr() to read
+ (stable) ethernet/IP address pair from ARP table
+
+ 2006-07-14 Christiaan Simons
+ * mib_structs.c: added
+ * include/lwip/snmp_structs.h: added
+ * netif.{c,h}, netif/ethernetif.c: added SNMP statistics to netif struct
+
+ 2006-07-06 Christiaan Simons
+ * snmp/asn1_{enc,dec}.c added
+ * snmp/mib2.c added
+ * snmp/msg_{in,out}.c added
+ * include/lwip/snmp_asn1.h added
+ * include/lwip/snmp_msg.h added
+ * doc/snmp_agent.txt added
+
+ 2006-03-29 Christiaan Simons
+ * inet.c, inet.h: Added platform byteswap support.
+ Added LWIP_PLATFORM_BYTESWAP define (defaults to 0) and
+ optional LWIP_PLATFORM_HTONS(), LWIP_PLATFORM_HTONL() macros.
+
+ ++ Bug fixes:
+
+ 2006-11-30 Christiaan Simons
+ * dhcp.c: Fixed false triggers of request_timeout.
+
+ 2006-11-28 Christiaan Simons
+ * netif.c: In netif_add() fixed missing clear of ip_addr, netmask, gw and flags.
+
+ 2006-10-11 Christiaan Simons
+ * api_lib.c etharp.c, ip.c, memp.c, stats.c, sys.{c,h} tcp.h:
+ Partially accepted patch #5449 for ANSI C compatibility / build fixes.
+ * ipv4/lwip/ip.h ipv6/lwip/ip.h: Corrected UDP-Lite protocol
+ identifier from 170 to 136 (bug #17574).
+
+ 2006-10-10 Christiaan Simons
+ * api_msg.c: Fixed Nagle algorithm as reported by Bob Grice.
+
+ 2006-08-17 Christiaan Simons
+ * udp.c: Fixed bug #17200, added check for broadcast
+ destinations for PCBs bound to a unicast address.
+
+ 2006-08-07 Christiaan Simons
+ * api_msg.c: Flushing TCP output in do_close() (bug #15926).
+
+ 2006-06-27 Christiaan Simons
+ * api_msg.c: Applied patch for cold case (bug #11135).
+ In accept_function() ensure newconn->callback is always initialized.
+
+ 2006-06-15 Christiaan Simons
+ * mem.h: added MEM_SIZE_F alias to fix an ancient cold case (bug #1748),
+ facilitate printing of mem_size_t and u16_t statistics.
+
+ 2006-06-14 Christiaan Simons
+ * api_msg.c: Applied patch #5146 to handle allocation failures
+ in accept() by Kevin Lawson.
+
+ 2006-05-26 Christiaan Simons
+ * api_lib.c: Removed conn->sem creation and destruction
+ from netconn_write() and added sys_sem_new to netconn_new_*.
+
+(STABLE-1_1_1)
+
+ 2006-03-03 Christiaan Simons
+ * ipv4/ip_frag.c: Added bound-checking assertions on ip_reassbitmap
+ access and added pbuf_alloc() return value checks.
+
+ 2006-01-01 Leon Woestenberg
+ * tcp_{in,out}.c, tcp_out.c: Removed 'even sndbuf' fix in TCP, which is
+ now handled by the checksum routine properly.
+
+ 2006-02-27 Leon Woestenberg
+ * pbuf.c: Fix alignment; pbuf_init() would not work unless
+ pbuf_pool_memory[] was properly aligned. (Patch by Curt McDowell.)
+
+ 2005-12-20 Leon Woestenberg
+ * tcp.c: Remove PCBs which stay in LAST_ACK state too long. Patch
+ submitted by Mitrani Hiroshi.
+
+ 2005-12-15 Christiaan Simons
+ * inet.c: Disabled the added summing routine to preserve code space.
+
+ 2005-12-14 Leon Woestenberg
+ * tcp_in.c: Duplicate FIN ACK race condition fix by Kelvin Lawson.
+ Added Curt McDowell's optimized checksumming routine for future
+ inclusion. Need to create test case for unaliged, aligned, odd,
+ even length combination of cases on various endianess machines.
+
+ 2005-12-09 Christiaan Simons
+ * inet.c: Rewrote standard checksum routine in proper portable C.
+
+ 2005-11-25 Christiaan Simons
+ * udp.c tcp.c: Removed SO_REUSE hack. Should reside in socket code only.
+ * *.c: introduced cc.h LWIP_DEBUG formatters matching the u16_t, s16_t,
+ u32_t, s32_t typedefs. This solves most debug word-length assumes.
+
+ 2005-07-17 Leon Woestenberg
+ * inet.c: Fixed unaligned 16-bit access in the standard checksum
+ routine by Peter Jolasson.
+ * slipif.c: Fixed implementation assumption of single-pbuf datagrams.
+
+ 2005-02-04 Leon Woestenberg
+ * tcp_out.c: Fixed uninitialized 'queue' referenced in memerr branch.
+ * tcp_{out|in}.c: Applied patch fixing unaligned access.
+
+ 2005-01-04 Leon Woestenberg
+ * pbuf.c: Fixed missing semicolon after LWIP_DEBUG statement.
+
+ 2005-01-03 Leon Woestenberg
+ * udp.c: UDP pcb->recv() was called even when it was NULL.
+
+(STABLE-1_1_0)
+
+ 2004-12-28 Leon Woestenberg
+ * etharp.*: Disabled multiple packets on the ARP queue.
+ This clashes with TCP queueing.
+
+ 2004-11-28 Leon Woestenberg
+ * etharp.*: Fixed race condition from ARP request to ARP timeout.
+ Halved the ARP period, doubled the period counts.
+ ETHARP_MAX_PENDING now should be at least 2. This prevents
+ the counter from reaching 0 right away (which would allow
+ too little time for ARP responses to be received).
+
+ 2004-11-25 Leon Woestenberg
+ * dhcp.c: Decline messages were not multicast but unicast.
+ * etharp.c: ETHARP_CREATE is renamed to ETHARP_TRY_HARD.
+ Do not try hard to insert arbitrary packet's source address,
+ etharp_ip_input() now calls etharp_update() without ETHARP_TRY_HARD.
+ etharp_query() now always DOES call ETHARP_TRY_HARD so that users
+ querying an address will see it appear in the cache (DHCP could
+ suffer from this when a server invalidly gave an in-use address.)
+ * ipv4/ip_addr.h: Renamed ip_addr_maskcmp() to _netcmp() as we are
+ comparing network addresses (identifiers), not the network masks
+ themselves.
+ * ipv4/ip_addr.c: ip_addr_isbroadcast() now checks that the given
+ IP address actually belongs to the network of the given interface.
+
+ 2004-11-24 Kieran Mansley
+ * tcp.c: Increment pcb->snd_buf when ACK is received in SYN_SENT state.
+
+(STABLE-1_1_0-RC1)
+
+ 2004-10-16 Kieran Mansley
+ * tcp.c: Add code to tcp_recved() to send an ACK (window update) immediately,
+ even if one is already pending, if the rcv_wnd is above a threshold
+ (currently TCP_WND/2). This avoids waiting for a timer to expire to send a
+ delayed ACK in order to open the window if the stack is only receiving data.
+
+ 2004-09-12 Kieran Mansley
+ * tcp*.*: Retransmit time-out handling improvement by Sam Jansen.
+
+ 2004-08-20 Tony Mountifield
+ * etharp.c: Make sure the first pbuf queued on an ARP entry
+ is properly ref counted.
+
+ 2004-07-27 Tony Mountifield
+ * debug.h: Added (int) cast in LWIP_DEBUGF() to avoid compiler
+ warnings about comparison.
+ * pbuf.c: Stopped compiler complaining of empty if statement
+ when LWIP_DEBUGF() empty. Closed an unclosed comment.
+ * tcp.c: Stopped compiler complaining of empty if statement
+ when LWIP_DEBUGF() empty.
+ * ip.h Corrected IPH_TOS() macro: returns a byte, so doesn't need htons().
+ * inet.c: Added a couple of casts to quiet the compiler.
+ No need to test isascii(c) before isdigit(c) or isxdigit(c).
+
+ 2004-07-22 Tony Mountifield
+ * inet.c: Made data types consistent in inet_ntoa().
+ Added casts for return values of checksum routines, to pacify compiler.
+ * ip_frag.c, tcp_out.c, sockets.c, pbuf.c
+ Small corrections to some debugging statements, to pacify compiler.
+
+ 2004-07-21 Tony Mountifield
+ * etharp.c: Removed spurious semicolon and added missing end-of-comment.
+ * ethernetif.c Updated low_level_output() to match prototype for
+ netif->linkoutput and changed low_level_input() similarly for consistency.
+ * api_msg.c: Changed recv_raw() from int to u8_t, to match prototype
+ of raw_recv() in raw.h and so avoid compiler error.
+ * sockets.c: Added trivial (int) cast to keep compiler happier.
+ * ip.c, netif.c Changed debug statements to use the tidier ip4_addrN() macros.
+
+(STABLE-1_0_0)
+
+ ++ Changes:
+
+ 2004-07-05 Leon Woestenberg
+ * sockets.*: Restructured LWIP_PRIVATE_TIMEVAL. Make sure
+ your cc.h file defines this either 1 or 0. If non-defined,
+ defaults to 1.
+ * .c: Added and includes where used.
+ * etharp.c: Made some array indices unsigned.
+
+ 2004-06-27 Leon Woestenberg
+ * netif.*: Added netif_set_up()/down().
+ * dhcp.c: Changes to restart program flow.
+
+ 2004-05-07 Leon Woestenberg
+ * etharp.c: In find_entry(), instead of a list traversal per candidate, do a
+ single-pass lookup for different candidates. Should exploit locality.
+
+ 2004-04-29 Leon Woestenberg
+ * tcp*.c: Cleaned up source comment documentation for Doxygen processing.
+ * opt.h: ETHARP_ALWAYS_INSERT option removed to comply with ARP RFC.
+ * etharp.c: update_arp_entry() only adds new ARP entries when adviced to by
+ the caller. This deprecates the ETHARP_ALWAYS_INSERT overrule option.
+
+ ++ Bug fixes:
+
+ 2004-04-27 Leon Woestenberg
+ * etharp.c: Applied patch of bug #8708 by Toni Mountifield with a solution
+ suggested by Timmy Brolin. Fix for 32-bit processors that cannot access
+ non-aligned 32-bit words, such as soms 32-bit TCP/IP header fields. Fix
+ is to prefix the 14-bit Ethernet headers with two padding bytes.
+
+ 2004-04-23 Leon Woestenberg
+ * ip_addr.c: Fix in the ip_addr_isbroadcast() check.
+ * etharp.c: Fixed the case where the packet that initiates the ARP request
+ is not queued, and gets lost. Fixed the case where the packets destination
+ address is already known; we now always queue the packet and perform an ARP
+ request.
+
+(STABLE-0_7_0)
+
+ ++ Bug fixes:
+
+ * Fixed TCP bug for SYN_SENT to ESTABLISHED state transition.
+ * Fixed TCP bug in dequeueing of FIN from out of order segment queue.
+ * Fixed two possible NULL references in rare cases.
+
+(STABLE-0_6_6)
+
+ ++ Bug fixes:
+
+ * Fixed DHCP which did not include the IP address in DECLINE messages.
+
+ ++ Changes:
+
+ * etharp.c has been hauled over a bit.
+
+(STABLE-0_6_5)
+
+ ++ Bug fixes:
+
+ * Fixed TCP bug induced by bad window resizing with unidirectional TCP traffic.
+ * Packets sent from ARP queue had invalid source hardware address.
+
+ ++ Changes:
+
+ * Pass-by ARP requests do now update the cache.
+
+ ++ New features:
+
+ * No longer dependent on ctype.h.
+ * New socket options.
+ * Raw IP pcb support.
+
+(STABLE-0_6_4)
+
+ ++ Bug fixes:
+
+ * Some debug formatters and casts fixed.
+ * Numereous fixes in PPP.
+
+ ++ Changes:
+
+ * DEBUGF now is LWIP_DEBUGF
+ * pbuf_dechain() has been re-enabled.
+ * Mentioned the changed use of CVS branches in README.
+
+(STABLE-0_6_3)
+
+ ++ Bug fixes:
+
+ * Fixed pool pbuf memory leak in pbuf_alloc().
+ Occured if not enough PBUF_POOL pbufs for a packet pbuf chain.
+ Reported by Savin Zlobec.
+
+ * PBUF_POOL chains had their tot_len field not set for non-first
+ pbufs. Fixed in pbuf_alloc().
+
+ ++ New features:
+
+ * Added PPP stack contributed by Marc Boucher
+
+ ++ Changes:
+
+ * Now drops short packets for ICMP/UDP/TCP protocols. More robust.
+
+ * ARP queueuing now queues the latest packet instead of the first.
+ This is the RFC recommended behaviour, but can be overridden in
+ lwipopts.h.
+
+(0.6.2)
+
+ ++ Bugfixes:
+
+ * TCP has been fixed to deal with the new use of the pbuf->ref
+ counter.
+
+ * DHCP dhcp_inform() crash bug fixed.
+
+ ++ Changes:
+
+ * Removed pbuf_pool_free_cache and pbuf_pool_alloc_cache. Also removed
+ pbuf_refresh(). This has sped up pbuf pool operations considerably.
+ Implemented by David Haas.
+
+(0.6.1)
+
+ ++ New features:
+
+ * The packet buffer implementation has been enhanced to support
+ zero-copy and copy-on-demand for packet buffers which have their
+ payloads in application-managed memory.
+ Implemented by David Haas.
+
+ Use PBUF_REF to make a pbuf refer to RAM. lwIP will use zero-copy
+ if an outgoing packet can be directly sent on the link, or perform
+ a copy-on-demand when necessary.
+
+ The application can safely assume the packet is sent, and the RAM
+ is available to the application directly after calling udp_send()
+ or similar function.
+
+ ++ Bugfixes:
+
+ * ARP_QUEUEING should now correctly work for all cases, including
+ PBUF_REF.
+ Implemented by Leon Woestenberg.
+
+ ++ Changes:
+
+ * IP_ADDR_ANY is no longer a NULL pointer. Instead, it is a pointer
+ to a '0.0.0.0' IP address.
+
+ * The packet buffer implementation is changed. The pbuf->ref counter
+ meaning has changed, and several pbuf functions have been
+ adapted accordingly.
+
+ * netif drivers have to be changed to set the hardware address length field
+ that must be initialized correctly by the driver (hint: 6 for Ethernet MAC).
+ See the contrib/ports/c16x cs8900 driver as a driver example.
+
+ * netif's have a dhcp field that must be initialized to NULL by the driver.
+ See the contrib/ports/c16x cs8900 driver as a driver example.
+
+(0.5.x) This file has been unmaintained up to 0.6.1. All changes are
+ logged in CVS but have not been explained here.
+
+(0.5.3) Changes since version 0.5.2
+
+ ++ Bugfixes:
+
+ * memp_malloc(MEMP_API_MSG) could fail with multiple application
+ threads because it wasn't protected by semaphores.
+
+ ++ Other changes:
+
+ * struct ip_addr now packed.
+
+ * The name of the time variable in arp.c has been changed to ctime
+ to avoid conflicts with the time() function.
+
+(0.5.2) Changes since version 0.5.1
+
+ ++ New features:
+
+ * A new TCP function, tcp_tmr(), now handles both TCP timers.
+
+ ++ Bugfixes:
+
+ * A bug in tcp_parseopt() could cause the stack to hang because of a
+ malformed TCP option.
+
+ * The address of new connections in the accept() function in the BSD
+ socket library was not handled correctly.
+
+ * pbuf_dechain() did not update the ->tot_len field of the tail.
+
+ * Aborted TCP connections were not handled correctly in all
+ situations.
+
+ ++ Other changes:
+
+ * All protocol header structs are now packed.
+
+ * The ->len field in the tcp_seg structure now counts the actual
+ amount of data, and does not add one for SYN and FIN segments.
+
+(0.5.1) Changes since version 0.5.0
+
+ ++ New features:
+
+ * Possible to run as a user process under Linux.
+
+ * Preliminary support for cross platform packed structs.
+
+ * ARP timer now implemented.
+
+ ++ Bugfixes:
+
+ * TCP output queue length was badly initialized when opening
+ connections.
+
+ * TCP delayed ACKs were not sent correctly.
+
+ * Explicit initialization of BSS segment variables.
+
+ * read() in BSD socket library could drop data.
+
+ * Problems with memory alignment.
+
+ * Situations when all TCP buffers were used could lead to
+ starvation.
+
+ * TCP MSS option wasn't parsed correctly.
+
+ * Problems with UDP checksum calculation.
+
+ * IP multicast address tests had endianess problems.
+
+ * ARP requests had wrong destination hardware address.
+
+ ++ Other changes:
+
+ * struct eth_addr changed from u16_t[3] array to u8_t[6].
+
+ * A ->linkoutput() member was added to struct netif.
+
+ * TCP and UDP ->dest_* struct members where changed to ->remote_*.
+
+ * ntoh* macros are now null definitions for big endian CPUs.
+
+(0.5.0) Changes since version 0.4.2
+
+ ++ New features:
+
+ * Redesigned operating system emulation layer to make porting easier.
+
+ * Better control over TCP output buffers.
+
+ * Documenation added.
+
+ ++ Bugfixes:
+
+ * Locking issues in buffer management.
+
+ * Bugfixes in the sequential API.
+
+ * IP forwarding could cause memory leakage. This has been fixed.
+
+ ++ Other changes:
+
+ * Directory structure somewhat changed; the core/ tree has been
+ collapsed.
+
+(0.4.2) Changes since version 0.4.1
+
+ ++ New features:
+
+ * Experimental ARP implementation added.
+
+ * Skeleton Ethernet driver added.
+
+ * Experimental BSD socket API library added.
+
+ ++ Bugfixes:
+
+ * In very intense situations, memory leakage could occur. This has
+ been fixed.
+
+ ++ Other changes:
+
+ * Variables named "data" and "code" have been renamed in order to
+ avoid name conflicts in certain compilers.
+
+ * Variable++ have in appliciable cases been translated to ++variable
+ since some compilers generate better code in the latter case.
+
+(0.4.1) Changes since version 0.4
+
+ ++ New features:
+
+ * TCP: Connection attempts time out earlier than data
+ transmissions. Nagle algorithm implemented. Push flag set on the
+ last segment in a burst.
+
+ * UDP: experimental support for UDP-Lite extensions.
+
+ ++ Bugfixes:
+
+ * TCP: out of order segments were in some cases handled incorrectly,
+ and this has now been fixed. Delayed acknowledgements was broken
+ in 0.4, has now been fixed. Binding to an address that is in use
+ now results in an error. Reset connections sometimes hung an
+ application; this has been fixed.
+
+ * Checksum calculation sometimes failed for chained pbufs with odd
+ lengths. This has been fixed.
+
+ * API: a lot of bug fixes in the API. The UDP API has been improved
+ and tested. Error reporting and handling has been
+ improved. Logical flaws and race conditions for incoming TCP
+ connections has been found and removed.
+
+ * Memory manager: alignment issues. Reallocating memory sometimes
+ failed, this has been fixed.
+
+ * Generic library: bcopy was flawed and has been fixed.
+
+ ++ Other changes:
+
+ * API: all datatypes has been changed from generic ones such as
+ ints, to specified ones such as u16_t. Functions that return
+ errors now have the correct type (err_t).
+
+ * General: A lot of code cleaned up and debugging code removed. Many
+ portability issues have been fixed.
+
+ * The license was changed; the advertising clause was removed.
+
+ * C64 port added.
+
+ * Thanks: Huge thanks go to Dagan Galarneau, Horst Garnetzke, Petri
+ Kosunen, Mikael Caleres, and Frits Wilmink for reporting and
+ fixing bugs!
+
+(0.4) Changes since version 0.3.1
+
+ * Memory management has been radically changed; instead of
+ allocating memory from a shared heap, memory for objects that are
+ rapidly allocated and deallocated is now kept in pools. Allocation
+ and deallocation from those memory pools is very fast. The shared
+ heap is still present but is used less frequently.
+
+ * The memory, memory pool, and packet buffer subsystems now support
+ 4-, 2-, or 1-byte alignment.
+
+ * "Out of memory" situations are handled in a more robust way.
+
+ * Stack usage has been reduced.
+
+ * Easier configuration of lwIP parameters such as memory usage,
+ TTLs, statistics gathering, etc. All configuration parameters are
+ now kept in a single header file "lwipopts.h".
+
+ * The directory structure has been changed slightly so that all
+ architecture specific files are kept under the src/arch
+ hierarchy.
+
+ * Error propagation has been improved, both in the protocol modules
+ and in the API.
+
+ * The code for the RTXC architecture has been implemented, tested
+ and put to use.
+
+ * Bugs have been found and corrected in the TCP, UDP, IP, API, and
+ the Internet checksum modules.
+
+ * Bugs related to porting between a 32-bit and a 16-bit architecture
+ have been found and corrected.
+
+ * The license has been changed slightly to conform more with the
+ original BSD license, including the advertisement clause.
+
+(0.3.1) Changes since version 0.3
+
+ * Fix of a fatal bug in the buffer management. Pbufs with allocated
+ RAM never returned the RAM when the pbuf was deallocated.
+
+ * TCP congestion control, window updates and retransmissions did not
+ work correctly. This has now been fixed.
+
+ * Bugfixes in the API.
+
+(0.3) Changes since version 0.2
+
+ * New and improved directory structure. All include files are now
+ kept in a dedicated include/ directory.
+
+ * The API now has proper error handling. A new function,
+ netconn_err(), now returns an error code for the connection in
+ case of errors.
+
+ * Improvements in the memory management subsystem. The system now
+ keeps a pointer to the lowest free memory block. A new function,
+ mem_malloc2() tries to allocate memory once, and if it fails tries
+ to free some memory and retry the allocation.
+
+ * Much testing has been done with limited memory
+ configurations. lwIP now does a better job when overloaded.
+
+ * Some bugfixes and improvements to the buffer (pbuf) subsystem.
+
+ * Many bugfixes in the TCP code:
+
+ - Fixed a bug in tcp_close().
+
+ - The TCP receive window was incorrectly closed when out of
+ sequence segments was received. This has been fixed.
+
+ - Connections are now timed-out of the FIN-WAIT-2 state.
+
+ - The initial congestion window could in some cases be too
+ large. This has been fixed.
+
+ - The retransmission queue could in some cases be screwed up. This
+ has been fixed.
+
+ - TCP RST flag now handled correctly.
+
+ - Out of sequence data was in some cases never delivered to the
+ application. This has been fixed.
+
+ - Retransmitted segments now contain the correct acknowledgment
+ number and advertised window.
+
+ - TCP retransmission timeout backoffs are not correctly computed
+ (ala BSD). After a number of retransmissions, TCP now gives up
+ the connection.
+
+ * TCP connections now are kept on three lists, one for active
+ connections, one for listening connections, and one for
+ connections that are in TIME-WAIT. This greatly speeds up the fast
+ timeout processing for sending delayed ACKs.
+
+ * TCP now provides proper feedback to the application when a
+ connection has been successfully set up.
+
+ * More comments have been added to the code. The code has also been
+ somewhat cleaned up.
+
+(0.2) Initial public release.
diff --git a/Shared/lwip/CMakeLists.txt b/Shared/lwip/CMakeLists.txt
new file mode 100644
index 0000000..121892d
--- /dev/null
+++ b/Shared/lwip/CMakeLists.txt
@@ -0,0 +1,27 @@
+set(LWIP_SOURCES
+ src/core/timers.c
+ src/core/udp.c
+ src/core/memp.c
+ src/core/init.c
+ src/core/pbuf.c
+ src/core/tcp.c
+ src/core/tcp_out.c
+ src/core/sys.c
+ src/core/netif.c
+ src/core/def.c
+ src/core/mem.c
+ src/core/tcp_in.c
+ src/core/stats.c
+ src/core/inet_chksum.c
+ src/core/ipv4/icmp.c
+ src/core/ipv4/ip4.c
+ src/core/ipv4/ip4_addr.c
+ src/core/ipv4/ip_frag.c
+ src/core/ipv6/ip6.c
+ src/core/ipv6/nd6.c
+ src/core/ipv6/icmp6.c
+ src/core/ipv6/ip6_addr.c
+ src/core/ipv6/ip6_frag.c
+ custom/sys.c
+)
+badvpn_add_library(lwip "system" "" "${LWIP_SOURCES}")
diff --git a/Shared/lwip/COPYING b/Shared/lwip/COPYING
new file mode 100644
index 0000000..e23898b
--- /dev/null
+++ b/Shared/lwip/COPYING
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * This file is part of the lwIP TCP/IP stack.
+ *
+ * Author: Adam Dunkels
+ *
+ */
+
+
diff --git a/Shared/lwip/FILES b/Shared/lwip/FILES
new file mode 100644
index 0000000..6625319
--- /dev/null
+++ b/Shared/lwip/FILES
@@ -0,0 +1,4 @@
+src/ - The source code for the lwIP TCP/IP stack.
+doc/ - The documentation for lwIP.
+
+See also the FILES file in each subdirectory.
diff --git a/Shared/lwip/README b/Shared/lwip/README
new file mode 100644
index 0000000..a62cc4f
--- /dev/null
+++ b/Shared/lwip/README
@@ -0,0 +1,89 @@
+INTRODUCTION
+
+lwIP is a small independent implementation of the TCP/IP protocol
+suite that has been developed by Adam Dunkels at the Computer and
+Networks Architectures (CNA) lab at the Swedish Institute of Computer
+Science (SICS).
+
+The focus of the lwIP TCP/IP implementation is to reduce the RAM usage
+while still having a full scale TCP. This making lwIP suitable for use
+in embedded systems with tens of kilobytes of free RAM and room for
+around 40 kilobytes of code ROM.
+
+FEATURES
+
+ * IP (Internet Protocol) including packet forwarding over multiple network
+ interfaces
+ * ICMP (Internet Control Message Protocol) for network maintenance and debugging
+ * IGMP (Internet Group Management Protocol) for multicast traffic management
+ * UDP (User Datagram Protocol) including experimental UDP-lite extensions
+ * TCP (Transmission Control Protocol) with congestion control, RTT estimation
+ and fast recovery/fast retransmit
+ * Specialized raw/native API for enhanced performance
+ * Optional Berkeley-like socket API
+ * DNS (Domain names resolver)
+ * SNMP (Simple Network Management Protocol)
+ * DHCP (Dynamic Host Configuration Protocol)
+ * AUTOIP (for IPv4, conform with RFC 3927)
+ * PPP (Point-to-Point Protocol)
+ * ARP (Address Resolution Protocol) for Ethernet
+
+LICENSE
+
+lwIP is freely available under a BSD license.
+
+DEVELOPMENT
+
+lwIP has grown into an excellent TCP/IP stack for embedded devices,
+and developers using the stack often submit bug fixes, improvements,
+and additions to the stack to further increase its usefulness.
+
+Development of lwIP is hosted on Savannah, a central point for
+software development, maintenance and distribution. Everyone can
+help improve lwIP by use of Savannah's interface, CVS and the
+mailing list. A core team of developers will commit changes to the
+CVS source tree.
+
+The lwIP TCP/IP stack is maintained in the 'lwip' CVS module and
+contributions (such as platform ports) are in the 'contrib' module.
+
+See doc/savannah.txt for details on CVS server access for users and
+developers.
+
+Last night's CVS tar ball can be downloaded from:
+ http://savannah.gnu.org/cvs.backups/lwip.tar.gz [CHANGED - NEEDS FIXING]
+
+The current CVS trees are web-browsable:
+ http://savannah.nongnu.org/cgi-bin/viewcvs/lwip/lwip/
+ http://savannah.nongnu.org/cgi-bin/viewcvs/lwip/contrib/
+
+Submit patches and bugs via the lwIP project page:
+ http://savannah.nongnu.org/projects/lwip/
+
+
+DOCUMENTATION
+
+The original out-dated homepage of lwIP and Adam Dunkels' papers on
+lwIP are at the official lwIP home page:
+ http://www.sics.se/~adam/lwip/
+
+Self documentation of the source code is regularly extracted from the
+current CVS sources and is available from this web page:
+ http://www.nongnu.org/lwip/
+
+There is now a constantly growin wiki about lwIP at
+ http://lwip.wikia.com/wiki/LwIP_Wiki
+
+Also, there are mailing lists you can subscribe at
+ http://savannah.nongnu.org/mail/?group=lwip
+plus searchable archives:
+ http://lists.nongnu.org/archive/html/lwip-users/
+ http://lists.nongnu.org/archive/html/lwip-devel/
+
+Reading Adam's papers, the files in docs/, browsing the source code
+documentation and browsing the mailing list archives is a good way to
+become familiar with the design of lwIP.
+
+Adam Dunkels
+Leon Woestenberg
+
diff --git a/Shared/lwip/UPGRADING b/Shared/lwip/UPGRADING
new file mode 100644
index 0000000..6501107
--- /dev/null
+++ b/Shared/lwip/UPGRADING
@@ -0,0 +1,144 @@
+This file lists major changes between release versions that require
+ports or applications to be changed. Use it to update a port or an
+application written for an older version of lwIP to correctly work
+with newer versions.
+
+
+(CVS HEAD)
+
+ * [Enter new changes just after this line - do not remove this line]
+
+ ++ Application changes:
+
+ * Replaced struct ip_addr by typedef ip_addr_t (struct ip_addr is kept for
+ compatibility to old applications, but will be removed in the future).
+
+ * Renamed mem_realloc() to mem_trim() to prevent confusion with realloc()
+
+ +++ Raw API:
+ * Changed the semantics of tcp_close() (since it was rather a
+ shutdown before): Now the application does *NOT* get any calls to the recv
+ callback (aside from NULL/closed) after calling tcp_close()
+
+ * When calling tcp_abort() from a raw API TCP callback function,
+ make sure you return ERR_ABRT to prevent accessing unallocated memory.
+ (ERR_ABRT now means the applicaiton has called tcp_abort!)
+
+ +++ Netconn API:
+ * Changed netconn_receive() and netconn_accept() to return
+ err_t, not a pointer to new data/netconn.
+
+ +++ Socket API:
+ * LWIP_SO_RCVTIMEO: when accept() or recv() time out, they
+ now set errno to EWOULDBLOCK/EAGAIN, not ETIMEDOUT.
+
+ * Added a minimal version of posix fctl() to have a
+ standardised way to set O_NONBLOCK for nonblocking sockets.
+
+ +++ all APIs:
+ * correctly implemented SO(F)_REUSEADDR
+
+ ++ Port changes
+
+ +++ new files:
+
+ * Added 4 new files: def.c, timers.c, timers.h, tcp_impl.h:
+
+ * Moved stack-internal parts of tcp.h to tcp_impl.h, tcp.h now only contains
+ the actual application programmer's API
+
+ * Separated timer implementation from sys.h/.c, moved to timers.h/.c;
+ Added timer implementation for NO_SYS==1, set NO_SYS_NO_TIMERS==1 if you
+ still want to use your own timer implementation for NO_SYS==0 (as before).
+
+ +++ sys layer:
+
+ * Converted mbox- and semaphore-functions to take pointers to sys_mbox_t/
+ sys_sem_t;
+
+ * Converted sys_mbox_new/sys_sem_new to take pointers and return err_t;
+
+ * Added Mutex concept in sys_arch (define LWIP_COMPAT_MUTEX to let sys.h use
+ binary semaphores instead of mutexes - as before)
+
+ +++ new options:
+
+ * Don't waste memory when chaining segments, added option TCP_OVERSIZE to
+ prevent creating many small pbufs when calling tcp_write with many small
+ blocks of data. Instead, pbufs are allocated larger than needed and the
+ space is used for later calls to tcp_write.
+
+ * Added LWIP_NETIF_TX_SINGLE_PBUF to always copy to try to create single pbufs
+ in tcp_write/udp_send.
+
+ * Added an additional option LWIP_ETHERNET to support ethernet without ARP
+ (necessary for pure PPPoE)
+
+ * Add MEMP_SEPARATE_POOLS to place memory pools in separate arrays. This may
+ be used to place these pools into user-defined memory by using external
+ declaration.
+
+ * Added TCP_SNDQUEUELOWAT corresponding to TCP_SNDLOWAT
+
+ +++ new pools:
+
+ * Netdb uses a memp pool for allocating memory when getaddrinfo() is called,
+ so MEMP_NUM_NETDB has to be set accordingly.
+
+ * DNS_LOCAL_HOSTLIST_IS_DYNAMIC uses a memp pool instead of the heap, so
+ MEMP_NUM_LOCALHOSTLIST has to be set accordingly.
+
+ * Snmp-agent uses a memp pools instead of the heap, so MEMP_NUM_SNMP_* have
+ to be set accordingly.
+
+ * PPPoE uses a MEMP pool instead of the heap, so MEMP_NUM_PPPOE_INTERFACES
+ has to be set accordingly
+
+ * Integrated loopif into netif.c - loopif does not have to be created by the
+ port any more, just define LWIP_HAVE_LOOPIF to 1.
+
+ * Added define LWIP_RAND() for lwip-wide randomization (needs to be defined
+ in cc.h, e.g. used by igmp)
+
+ * Added printf-formatter X8_F to printf u8_t as hex
+
+ * The heap now may be moved to user-defined memory by defining
+ LWIP_RAM_HEAP_POINTER as a void pointer to that memory's address
+
+ * added autoip_set_struct() and dhcp_set_struct() to let autoip and dhcp work
+ with user-allocated structs instead of calling mem_malloc
+
+ * Added const char* name to mem- and memp-stats for easier debugging.
+
+ * Calculate the TCP/UDP checksum while copying to only fetch data once:
+ Define LWIP_CHKSUM_COPY to a memcpy-like function that returns the checksum
+
+ * Added SO_REUSE_RXTOALL to pass received UDP broadcast/multicast packets to
+ more than one pcb.
+
+ * Changed the semantics of ARP_QUEUEING==0: ARP_QUEUEING now cannot be turned
+ off any more, if this is set to 0, only one packet (the most recent one) is
+ queued (like demanded by RFC 1122).
+
+
+ ++ Major bugfixes/improvements
+
+ * Implemented tcp_shutdown() to only shut down one end of a connection
+ * Implemented shutdown() at socket- and netconn-level
+ * Added errorset support to select() + improved select speed overhead
+ * Merged pppd to v2.3.11 (including some backported bugfixes from 2.4.x)
+ * Added timer implementation for NO_SYS==1 (may be disabled with NO_SYS_NO_TIMERS==1
+ * Use macros defined in ip_addr.h to work with IP addresses
+ * Implemented many nonblocking socket/netconn functions
+ * Fixed ARP input processing: only add a new entry if a request was directed as us
+ * mem_realloc() to mem_trim() to prevent confusion with realloc()
+ * Some improvements for AutoIP (don't route/forward link-local addresses, don't break
+ existing connections when assigning a routable address)
+ * Correctly handle remote side overrunning our rcv_wnd in ooseq case
+ * Removed packing from ip_addr_t, the packed version is now only used in protocol headers
+ * Corrected PBUF_POOL_BUFSIZE for ports where ETH_PAD_SIZE > 0
+ * Added support for static ARP table entries
+
+(STABLE-1.3.2)
+
+ * initial version of this file
diff --git a/Shared/lwip/badvpn/misc/BRefTarget.h b/Shared/lwip/badvpn/misc/BRefTarget.h
new file mode 100644
index 0000000..4324605
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/BRefTarget.h
@@ -0,0 +1,114 @@
+/**
+ * @file BRefTarget.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_B_REF_TARGET_H
+#define BADVPN_B_REF_TARGET_H
+
+#include
+
+#include
+#include
+
+/**
+ * Represents a reference-counted object.
+ */
+typedef struct BRefTarget_s BRefTarget;
+
+/**
+ * Callback function called after the reference count of a {@link BRefTarget}
+ * reaches has reached zero. At this point the BRefTarget object has already
+ * been invalidated, i.e. {@link BRefTarget_Ref} must not be called on this
+ * object after this handler is called.
+ */
+typedef void (*BRefTarget_func_release) (BRefTarget *o);
+
+struct BRefTarget_s {
+ BRefTarget_func_release func_release;
+ int refcnt;
+ DebugObject d_obj;
+};
+
+/**
+ * Initializes a reference target object. The initial reference count of the object
+ * is 1. The \a func_release argument specifies the function to be called from
+ * {@link BRefTarget_Deref} when the reference count reaches zero.
+ */
+static void BRefTarget_Init (BRefTarget *o, BRefTarget_func_release func_release);
+
+/**
+ * Decrements the reference count of a reference target object. If the reference
+ * count has reached zero, the object's {@link BRefTarget_func_release} function
+ * is called, and the object is considered destroyed.
+ */
+static void BRefTarget_Deref (BRefTarget *o);
+
+/**
+ * Increments the reference count of a reference target object.
+ * Returns 1 on success and 0 on failure.
+ */
+static int BRefTarget_Ref (BRefTarget *o) WARN_UNUSED;
+
+static void BRefTarget_Init (BRefTarget *o, BRefTarget_func_release func_release)
+{
+ ASSERT(func_release)
+
+ o->func_release = func_release;
+ o->refcnt = 1;
+
+ DebugObject_Init(&o->d_obj);
+}
+
+static void BRefTarget_Deref (BRefTarget *o)
+{
+ DebugObject_Access(&o->d_obj);
+ ASSERT(o->refcnt > 0)
+
+ o->refcnt--;
+
+ if (o->refcnt == 0) {
+ DebugObject_Free(&o->d_obj);
+ o->func_release(o);
+ }
+}
+
+static int BRefTarget_Ref (BRefTarget *o)
+{
+ DebugObject_Access(&o->d_obj);
+ ASSERT(o->refcnt > 0)
+
+ if (o->refcnt == INT_MAX) {
+ return 0;
+ }
+
+ o->refcnt++;
+
+ return 1;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/Utf16Decoder.h b/Shared/lwip/badvpn/misc/Utf16Decoder.h
new file mode 100644
index 0000000..819ac94
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/Utf16Decoder.h
@@ -0,0 +1,113 @@
+/**
+ * @file Utf16Decoder.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_UTF16DECODER_H
+#define BADVPN_UTF16DECODER_H
+
+#include
+
+#include
+
+/**
+ * Decodes UTF-16 data into Unicode characters.
+ */
+typedef struct {
+ int cont;
+ uint32_t ch;
+} Utf16Decoder;
+
+/**
+ * Initializes the UTF-16 decoder.
+ *
+ * @param o the object
+ */
+static void Utf16Decoder_Init (Utf16Decoder *o);
+
+/**
+ * Inputs a 16-bit value to the decoder.
+ *
+ * @param o the object
+ * @param b 16-bit value to input
+ * @param out_ch will receive a Unicode character if this function returns 1.
+ * If written, the character will be in the range 0 - 0x10FFFF,
+ * excluding the surrogate range 0xD800 - 0xDFFF.
+ * @return 1 if a Unicode character has been written to *out_ch, 0 if not
+ */
+static int Utf16Decoder_Input (Utf16Decoder *o, uint16_t b, uint32_t *out_ch);
+
+void Utf16Decoder_Init (Utf16Decoder *o)
+{
+ o->cont = 0;
+}
+
+int Utf16Decoder_Input (Utf16Decoder *o, uint16_t b, uint32_t *out_ch)
+{
+ // high surrogate
+ if (b >= UINT16_C(0xD800) && b <= UINT16_C(0xDBFF)) {
+ // set continuation state
+ o->cont = 1;
+
+ // add high bits
+ o->ch = (uint32_t)(b - UINT16_C(0xD800)) << 10;
+
+ return 0;
+ }
+
+ // low surrogate
+ if (b >= UINT16_C(0xDC00) && b <= UINT16_C(0xDFFF)) {
+ // check continuation
+ if (!o->cont) {
+ return 0;
+ }
+
+ // add low bits
+ o->ch |= (b - UINT16_C(0xDC00));
+
+ // reset state
+ o->cont = 0;
+
+ // don't report surrogates
+ if (o->ch >= UINT32_C(0xD800) && o->ch <= UINT32_C(0xDFFF)) {
+ return 0;
+ }
+
+ // return character
+ *out_ch = o->ch;
+ return 1;
+ }
+
+ // reset state
+ o->cont = 0;
+
+ // return character
+ *out_ch = b;
+ return 1;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/Utf16Encoder.h b/Shared/lwip/badvpn/misc/Utf16Encoder.h
new file mode 100644
index 0000000..4900b42
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/Utf16Encoder.h
@@ -0,0 +1,67 @@
+/**
+ * @file Utf16Encoder.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_UTF16ENCODER_H
+#define BADVPN_UTF16ENCODER_H
+
+#include
+
+/**
+ * Encodes a Unicode character into a sequence of 16-bit values according to UTF-16.
+ *
+ * @param ch Unicode character to encode
+ * @param out will receive the encoded 16-bit values. Must have space for 2 values.
+ * @return number of 16-bit values written, 0-2, with 0 meaning the character cannot
+ * be encoded
+ */
+static int Utf16Encoder_EncodeCharacter (uint32_t ch, uint16_t *out);
+
+int Utf16Encoder_EncodeCharacter (uint32_t ch, uint16_t *out)
+{
+ if (ch <= UINT32_C(0xFFFF)) {
+ // surrogates
+ if (ch >= UINT32_C(0xD800) && ch <= UINT32_C(0xDFFF)) {
+ return 0;
+ }
+
+ out[0] = ch;
+ return 1;
+ }
+
+ if (ch <= UINT32_C(0x10FFFF)) {
+ uint32_t x = ch - UINT32_C(0x10000);
+ out[0] = UINT32_C(0xD800) + (x >> 10);
+ out[1] = UINT32_C(0xDC00) + (x & UINT32_C(0x3FF));
+ return 2;
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/Utf8Decoder.h b/Shared/lwip/badvpn/misc/Utf8Decoder.h
new file mode 100644
index 0000000..c6412b1
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/Utf8Decoder.h
@@ -0,0 +1,143 @@
+/**
+ * @file Utf8Decoder.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_UTF8DECODER_H
+#define BADVPN_UTF8DECODER_H
+
+#include
+
+#include
+
+/**
+ * Decodes UTF-8 data into Unicode characters.
+ */
+typedef struct {
+ int bytes;
+ int pos;
+ uint32_t ch;
+} Utf8Decoder;
+
+/**
+ * Initializes the UTF-8 decoder.
+ *
+ * @param o the object
+ */
+static void Utf8Decoder_Init (Utf8Decoder *o);
+
+/**
+ * Inputs a byte to the decoder.
+ *
+ * @param o the object
+ * @param b byte to input
+ * @param out_ch will receive a Unicode character if this function returns 1.
+ * If written, the character will be in the range 0 - 0x10FFFF,
+ * excluding the surrogate range 0xD800 - 0xDFFF.
+ * @return 1 if a Unicode character has been written to *out_ch, 0 if not
+ */
+static int Utf8Decoder_Input (Utf8Decoder *o, uint8_t b, uint32_t *out_ch);
+
+void Utf8Decoder_Init (Utf8Decoder *o)
+{
+ o->bytes = 0;
+}
+
+int Utf8Decoder_Input (Utf8Decoder *o, uint8_t b, uint32_t *out_ch)
+{
+ // one-byte character
+ if ((b & 128) == 0) {
+ o->bytes = 0;
+ *out_ch = b;
+ return 1;
+ }
+
+ // start of two-byte character
+ if ((b & 224) == 192) {
+ o->bytes = 2;
+ o->pos = 1;
+ o->ch = (uint32_t)(b & 31) << 6;
+ return 0;
+ }
+
+ // start of three-byte character
+ if ((b & 240) == 224) {
+ o->bytes = 3;
+ o->pos = 1;
+ o->ch = (uint32_t)(b & 15) << 12;
+ return 0;
+ }
+
+ // start of four-byte character
+ if ((b & 248) == 240) {
+ o->bytes = 4;
+ o->pos = 1;
+ o->ch = (uint32_t)(b & 7) << 18;
+ return 0;
+ }
+
+ // continuation of multi-byte character
+ if ((b & 192) == 128 && o->bytes > 0) {
+ ASSERT(o->bytes <= 4)
+ ASSERT(o->pos > 0)
+ ASSERT(o->pos < o->bytes)
+
+ // add bits from this byte
+ o->ch |= (uint32_t)(b & 63) << (6 * (o->bytes - o->pos - 1));
+
+ // end of multi-byte character?
+ if (o->pos == o->bytes - 1) {
+ // reset state
+ o->bytes = 0;
+
+ // don't report out-of-range characters
+ if (o->ch > UINT32_C(0x10FFFF)) {
+ return 0;
+ }
+
+ // don't report surrogates
+ if (o->ch >= UINT32_C(0xD800) && o->ch <= UINT32_C(0xDFFF)) {
+ return 0;
+ }
+
+ *out_ch = o->ch;
+ return 1;
+ }
+
+ // increment byte index
+ o->pos++;
+
+ return 0;
+ }
+
+ // error, reset state
+ o->bytes = 0;
+
+ return 0;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/Utf8Encoder.h b/Shared/lwip/badvpn/misc/Utf8Encoder.h
new file mode 100644
index 0000000..00eb5e6
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/Utf8Encoder.h
@@ -0,0 +1,81 @@
+/**
+ * @file Utf8Encoder.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_UTF8ENCODER_H
+#define BADVPN_UTF8ENCODER_H
+
+#include
+
+/**
+ * Encodes a Unicode character into a sequence of bytes according to UTF-8.
+ *
+ * @param ch Unicode character to encode
+ * @param out will receive the encoded bytes. Must have space for 4 bytes.
+ * @return number of bytes written, 0-4, with 0 meaning the character cannot
+ * be encoded
+ */
+static int Utf8Encoder_EncodeCharacter (uint32_t ch, uint8_t *out);
+
+int Utf8Encoder_EncodeCharacter (uint32_t ch, uint8_t *out)
+{
+ if (ch <= UINT32_C(0x007F)) {
+ out[0] = ch;
+ return 1;
+ }
+
+ if (ch <= UINT32_C(0x07FF)) {
+ out[0] = (0xC0 | (ch >> 6));
+ out[1] = (0x80 | ((ch >> 0) & 0x3F));
+ return 2;
+ }
+
+ if (ch <= UINT32_C(0xFFFF)) {
+ // surrogates
+ if (ch >= UINT32_C(0xD800) && ch <= UINT32_C(0xDFFF)) {
+ return 0;
+ }
+
+ out[0] = (0xE0 | (ch >> 12));
+ out[1] = (0x80 | ((ch >> 6) & 0x3F));
+ out[2] = (0x80 | ((ch >> 0) & 0x3F));
+ return 3;
+ }
+
+ if (ch < UINT32_C(0x10FFFF)) {
+ out[0] = (0xF0 | (ch >> 18));
+ out[1] = (0x80 | ((ch >> 12) & 0x3F));
+ out[2] = (0x80 | ((ch >> 6) & 0x3F));
+ out[3] = (0x80 | ((ch >> 0) & 0x3F));
+ return 4;
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/arp_proto.h b/Shared/lwip/badvpn/misc/arp_proto.h
new file mode 100644
index 0000000..71a6c98
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/arp_proto.h
@@ -0,0 +1,60 @@
+/**
+ * @file arp_proto.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Definitions for the ARP protocol.
+ */
+
+#ifndef BADVPN_ARP_PROTO_H
+#define BADVPN_ARP_PROTO_H
+
+#include
+
+#include
+
+#define ARP_HARDWARE_TYPE_ETHERNET 1
+
+#define ARP_OPCODE_REQUEST 1
+#define ARP_OPCODE_REPLY 2
+
+B_START_PACKED
+struct arp_packet {
+ uint16_t hardware_type;
+ uint16_t protocol_type;
+ uint8_t hardware_size;
+ uint8_t protocol_size;
+ uint16_t opcode;
+ uint8_t sender_mac[6];
+ uint32_t sender_ip;
+ uint8_t target_mac[6];
+ uint32_t target_ip;
+} B_PACKED;
+B_END_PACKED
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/array_length.h b/Shared/lwip/badvpn/misc/array_length.h
new file mode 100644
index 0000000..15de964
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/array_length.h
@@ -0,0 +1,35 @@
+/**
+ * @file array_length.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_ARRAY_LENGTH
+#define BADVPN_ARRAY_LENGTH
+
+#define B_ARRAY_LENGTH(arr) (sizeof((arr)) / sizeof((arr)[0]))
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/ascii_utils.h b/Shared/lwip/badvpn/misc/ascii_utils.h
new file mode 100644
index 0000000..2baa9fc
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/ascii_utils.h
@@ -0,0 +1,43 @@
+/**
+ * @file ascii_utils.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_ASCII_UTILS_H
+#define BADVPN_ASCII_UTILS_H
+
+static char b_ascii_tolower (char c)
+{
+ return (c >= 'A' && c <= 'Z') ? (c + 32) : c;
+}
+
+static char b_ascii_toupper (char c)
+{
+ return (c >= 'a' && c <= 'z') ? (c - 32) : c;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/balign.h b/Shared/lwip/badvpn/misc/balign.h
new file mode 100644
index 0000000..57152af
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/balign.h
@@ -0,0 +1,76 @@
+/**
+ * @file balign.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Integer alignment macros.
+ */
+
+#ifndef BADVPN_MISC_BALIGN_H
+#define BADVPN_MISC_BALIGN_H
+
+#include
+#include
+
+/**
+ * Checks if aligning x up to n would overflow.
+ */
+static int balign_up_overflows (size_t x, size_t n)
+{
+ size_t r = x % n;
+
+ return (r && x > SIZE_MAX - (n - r));
+}
+
+/**
+ * Aligns x up to n.
+ */
+static size_t balign_up (size_t x, size_t n)
+{
+ size_t r = x % n;
+ return (r ? x + (n - r) : x);
+}
+
+/**
+ * Aligns x down to n.
+ */
+static size_t balign_down (size_t x, size_t n)
+{
+ return (x - (x % n));
+}
+
+/**
+ * Calculates the quotient of a and b, rounded up.
+ */
+static size_t bdivide_up (size_t a, size_t b)
+{
+ size_t r = a % b;
+ return (r > 0 ? a / b + 1 : a / b);
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/balloc.h b/Shared/lwip/badvpn/misc/balloc.h
new file mode 100644
index 0000000..7d2d54f
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/balloc.h
@@ -0,0 +1,248 @@
+/**
+ * @file balloc.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Memory allocation functions.
+ */
+
+#ifndef BADVPN_MISC_BALLOC_H
+#define BADVPN_MISC_BALLOC_H
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+/**
+ * Allocates memory.
+ *
+ * @param bytes number of bytes to allocate.
+ * @return a non-NULL pointer to the memory, or NULL on failure.
+ * The memory allocated can be freed using {@link BFree}.
+ */
+static void * BAlloc (size_t bytes);
+
+/**
+ * Frees memory.
+ *
+ * @param m memory to free. Must have been obtained with {@link BAlloc},
+ * {@link BAllocArray}, or {@link BAllocArray2}. May be NULL;
+ * in this case, this function does nothing.
+ */
+static void BFree (void *m);
+
+/**
+ * Changes the size of a memory block. On success, the memory block
+ * may be moved to a different address.
+ *
+ * @param m pointer to a memory block obtained from {@link BAlloc}
+ * or other functions in this group. If this is NULL, the
+ * call is equivalent to {@link BAlloc}(bytes).
+ * @param bytes new size of the memory block
+ * @return new pointer to the memory block, or NULL on failure
+ */
+static void * BRealloc (void *m, size_t bytes);
+
+/**
+ * Allocates memory, with size given as a {@link bsize_t}.
+ *
+ * @param bytes number of bytes to allocate. If the size is overflow,
+ * this function will return NULL.
+ * @return a non-NULL pointer to the memory, or NULL on failure.
+ * The memory allocated can be freed using {@link BFree}.
+ */
+static void * BAllocSize (bsize_t bytes);
+
+/**
+ * Allocates memory for an array.
+ * A check is first done to make sure the multiplication doesn't overflow;
+ * otherwise, this is equivalent to {@link BAlloc}(count * bytes).
+ * This may be slightly faster if 'bytes' is constant, because a division
+ * with 'bytes' is performed.
+ *
+ * @param count number of elements.
+ * @param bytes size of one array element.
+ * @return a non-NULL pointer to the memory, or NULL on failure.
+ * The memory allocated can be freed using {@link BFree}.
+ */
+static void * BAllocArray (size_t count, size_t bytes);
+
+/**
+ * Reallocates memory that was allocated using one of the allocation
+ * functions in this file. On success, the memory may be moved to a
+ * different address, leaving the old address invalid.
+ *
+ * @param mem pointer to an existing memory block. May be NULL, in which
+ * case this is equivalent to {@link BAllocArray}.
+ * @param count number of elements for reallocation
+ * @param bytes size of one array element for reallocation
+ * @return a non-NULL pointer to the address of the reallocated memory
+ * block, or NULL on failure. On failure, the original memory
+ * block is left intact.
+ */
+static void * BReallocArray (void *mem, size_t count, size_t bytes);
+
+/**
+ * Allocates memory for a two-dimensional array.
+ *
+ * Checks are first done to make sure the multiplications don't overflow;
+ * otherwise, this is equivalent to {@link BAlloc}((count2 * (count1 * bytes)).
+ *
+ * @param count2 number of elements in one dimension.
+ * @param count1 number of elements in the other dimension.
+ * @param bytes size of one array element.
+ * @return a non-NULL pointer to the memory, or NULL on failure.
+ * The memory allocated can be freed using {@link BFree}.
+ */
+static void * BAllocArray2 (size_t count2, size_t count1, size_t bytes);
+
+/**
+ * Adds to a size_t with overflow detection.
+ *
+ * @param s pointer to a size_t to add to
+ * @param add number to add
+ * @return 1 on success, 0 on failure
+ */
+static int BSizeAdd (size_t *s, size_t add);
+
+/**
+ * Aligns a size_t upwards with overflow detection.
+ *
+ * @param s pointer to a size_t to align
+ * @param align alignment value. Must be >0.
+ * @return 1 on success, 0 on failure
+ */
+static int BSizeAlign (size_t *s, size_t align);
+
+void * BAlloc (size_t bytes)
+{
+ if (bytes == 0) {
+ return malloc(1);
+ }
+
+ return malloc(bytes);
+}
+
+void BFree (void *m)
+{
+ free(m);
+}
+
+void * BRealloc (void *m, size_t bytes)
+{
+ if (bytes == 0) {
+ return realloc(m, 1);
+ }
+
+ return realloc(m, bytes);
+}
+
+void * BAllocSize (bsize_t bytes)
+{
+ if (bytes.is_overflow) {
+ return NULL;
+ }
+
+ return BAlloc(bytes.value);
+}
+
+void * BAllocArray (size_t count, size_t bytes)
+{
+ if (count == 0 || bytes == 0) {
+ return malloc(1);
+ }
+
+ if (count > SIZE_MAX / bytes) {
+ return NULL;
+ }
+
+ return BAlloc(count * bytes);
+}
+
+void * BReallocArray (void *mem, size_t count, size_t bytes)
+{
+ if (count == 0 || bytes == 0) {
+ return realloc(mem, 1);
+ }
+
+ if (count > SIZE_MAX / bytes) {
+ return NULL;
+ }
+
+ return realloc(mem, count * bytes);
+}
+
+void * BAllocArray2 (size_t count2, size_t count1, size_t bytes)
+{
+ if (count2 == 0 || count1 == 0 || bytes == 0) {
+ return malloc(1);
+ }
+
+ if (count1 > SIZE_MAX / bytes) {
+ return NULL;
+ }
+
+ if (count2 > SIZE_MAX / (count1 * bytes)) {
+ return NULL;
+ }
+
+ return BAlloc(count2 * (count1 * bytes));
+}
+
+int BSizeAdd (size_t *s, size_t add)
+{
+ ASSERT(s)
+
+ if (add > SIZE_MAX - *s) {
+ return 0;
+ }
+ *s += add;
+ return 1;
+}
+
+int BSizeAlign (size_t *s, size_t align)
+{
+ ASSERT(s)
+ ASSERT(align > 0)
+
+ size_t mod = *s % align;
+ if (mod > 0) {
+ if (align - mod > SIZE_MAX - *s) {
+ return 0;
+ }
+ *s += align - mod;
+ }
+ return 1;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/blimits.h b/Shared/lwip/badvpn/misc/blimits.h
new file mode 100644
index 0000000..8bcdc2a
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/blimits.h
@@ -0,0 +1,60 @@
+/**
+ * @file blimits.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_BLIMITS_H
+#define BADVPN_BLIMITS_H
+
+#include
+
+#define BTYPE_IS_SIGNED(type) ((type)-1 < 0)
+
+#define BSIGNED_TYPE_MIN(type) ( \
+ sizeof(type) == 1 ? INT8_MIN : ( \
+ sizeof(type) == 2 ? INT16_MIN : ( \
+ sizeof(type) == 4 ? INT32_MIN : ( \
+ sizeof(type) == 8 ? INT64_MIN : 0))))
+
+#define BSIGNED_TYPE_MAX(type) ( \
+ sizeof(type) == 1 ? INT8_MAX : ( \
+ sizeof(type) == 2 ? INT16_MAX : ( \
+ sizeof(type) == 4 ? INT32_MAX : ( \
+ sizeof(type) == 8 ? INT64_MAX : 0))))
+
+#define BUNSIGNED_TYPE_MIN(type) ((type)0)
+
+#define BUNSIGNED_TYPE_MAX(type) ( \
+ sizeof(type) == 1 ? UINT8_MAX : ( \
+ sizeof(type) == 2 ? UINT16_MAX : ( \
+ sizeof(type) == 4 ? UINT32_MAX : ( \
+ sizeof(type) == 8 ? UINT64_MAX : 0))))
+
+#define BTYPE_MIN(type) (BTYPE_IS_SIGNED(type) ? BSIGNED_TYPE_MIN(type) : BUNSIGNED_TYPE_MIN(type))
+#define BTYPE_MAX(type) (BTYPE_IS_SIGNED(type) ? BSIGNED_TYPE_MAX(type) : BUNSIGNED_TYPE_MAX(type))
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/bsize.h b/Shared/lwip/badvpn/misc/bsize.h
new file mode 100644
index 0000000..2d724df
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/bsize.h
@@ -0,0 +1,117 @@
+/**
+ * @file bsize.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Arithmetic with overflow detection.
+ */
+
+#ifndef BADVPN_MISC_BSIZE_H
+#define BADVPN_MISC_BSIZE_H
+
+#include
+#include
+#include
+
+typedef struct {
+ int is_overflow;
+ size_t value;
+} bsize_t;
+
+static bsize_t bsize_fromsize (size_t v);
+static bsize_t bsize_fromint (int v);
+static bsize_t bsize_overflow (void);
+static int bsize_tosize (bsize_t s, size_t *out);
+static int bsize_toint (bsize_t s, int *out);
+static bsize_t bsize_add (bsize_t s1, bsize_t s2);
+static bsize_t bsize_max (bsize_t s1, bsize_t s2);
+static bsize_t bsize_mul (bsize_t s1, bsize_t s2);
+
+bsize_t bsize_fromsize (size_t v)
+{
+ bsize_t s = {0, v};
+ return s;
+}
+
+bsize_t bsize_fromint (int v)
+{
+ bsize_t s = {(v < 0 || v > SIZE_MAX), v};
+ return s;
+}
+
+static bsize_t bsize_overflow (void)
+{
+ bsize_t s = {1, 0};
+ return s;
+}
+
+int bsize_tosize (bsize_t s, size_t *out)
+{
+ if (s.is_overflow) {
+ return 0;
+ }
+
+ if (out) {
+ *out = s.value;
+ }
+
+ return 1;
+}
+
+int bsize_toint (bsize_t s, int *out)
+{
+ if (s.is_overflow || s.value > INT_MAX) {
+ return 0;
+ }
+
+ if (out) {
+ *out = s.value;
+ }
+
+ return 1;
+}
+
+bsize_t bsize_add (bsize_t s1, bsize_t s2)
+{
+ bsize_t s = {(s1.is_overflow || s2.is_overflow || s2.value > SIZE_MAX - s1.value), (s1.value + s2.value)};
+ return s;
+}
+
+bsize_t bsize_max (bsize_t s1, bsize_t s2)
+{
+ bsize_t s = {(s1.is_overflow || s2.is_overflow), ((s1.value > s2.value) * s1.value + (s1.value <= s2.value) * s2.value)};
+ return s;
+}
+
+bsize_t bsize_mul (bsize_t s1, bsize_t s2)
+{
+ bsize_t s = {(s1.is_overflow || s2.is_overflow || (s1.value != 0 && s2.value > SIZE_MAX / s1.value)), (s1.value * s2.value)};
+ return s;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/bsort.h b/Shared/lwip/badvpn/misc/bsort.h
new file mode 100644
index 0000000..24d7a66
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/bsort.h
@@ -0,0 +1,69 @@
+/**
+ * @file bsort.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Sorting functions.
+ */
+
+#ifndef BADVPN_MISC_BSORT_H
+#define BADVPN_MISC_BSORT_H
+
+#include
+#include
+#include
+
+#include
+#include
+
+typedef int (*BSort_comparator) (const void *e1, const void *e2);
+
+static void BInsertionSort (void *arr, size_t count, size_t esize, BSort_comparator compatator, void *temp);
+
+void BInsertionSort (void *arr, size_t count, size_t esize, BSort_comparator compatator, void *temp)
+{
+ ASSERT(esize > 0)
+
+ for (size_t i = 0; i < count; i++) {
+ size_t j = i;
+ while (j > 0) {
+ uint8_t *x = (uint8_t *)arr + (j - 1) * esize;
+ uint8_t *y = (uint8_t *)arr + j * esize;
+ int c = compatator(x, y);
+ if (c <= 0) {
+ break;
+ }
+ memcpy(temp, x, esize);
+ memcpy(x, y, esize);
+ memcpy(y, temp, esize);
+ j--;
+ }
+ }
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/bstring.h b/Shared/lwip/badvpn/misc/bstring.h
new file mode 100644
index 0000000..caef106
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/bstring.h
@@ -0,0 +1,140 @@
+/**
+ * @file bstring.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_BSTRING_H
+#define BADVPN_BSTRING_H
+
+#include
+
+#include
+#include
+
+#define BSTRING_TYPE_STATIC 5
+#define BSTRING_TYPE_DYNAMIC 7
+#define BSTRING_TYPE_EXTERNAL 11
+
+#define BSTRING_STATIC_SIZE 23
+#define BSTRING_STATIC_MAX (BSTRING_STATIC_SIZE - 1)
+
+typedef struct {
+ union {
+ struct {
+ char type;
+ char static_string[BSTRING_STATIC_SIZE];
+ } us;
+ struct {
+ char type;
+ char *dynamic_string;
+ } ud;
+ struct {
+ char type;
+ const char *external_string;
+ } ue;
+ } u;
+} BString;
+
+static void BString__assert (BString *o)
+{
+ switch (o->u.us.type) {
+ case BSTRING_TYPE_STATIC:
+ case BSTRING_TYPE_DYNAMIC:
+ case BSTRING_TYPE_EXTERNAL:
+ return;
+ }
+
+ ASSERT(0);
+}
+
+static int BString_Init (BString *o, const char *str)
+{
+ if (strlen(str) <= BSTRING_STATIC_MAX) {
+ strcpy(o->u.us.static_string, str);
+ o->u.us.type = BSTRING_TYPE_STATIC;
+ } else {
+ if (!(o->u.ud.dynamic_string = malloc(strlen(str) + 1))) {
+ return 0;
+ }
+ strcpy(o->u.ud.dynamic_string, str);
+ o->u.ud.type = BSTRING_TYPE_DYNAMIC;
+ }
+
+ BString__assert(o);
+ return 1;
+}
+
+static void BString_InitStatic (BString *o, const char *str)
+{
+ ASSERT(strlen(str) <= BSTRING_STATIC_MAX)
+
+ strcpy(o->u.us.static_string, str);
+ o->u.us.type = BSTRING_TYPE_STATIC;
+
+ BString__assert(o);
+}
+
+static void BString_InitExternal (BString *o, const char *str)
+{
+ o->u.ue.external_string = str;
+ o->u.ue.type = BSTRING_TYPE_EXTERNAL;
+
+ BString__assert(o);
+}
+
+static void BString_InitAllocated (BString *o, char *str)
+{
+ o->u.ud.dynamic_string = str;
+ o->u.ud.type = BSTRING_TYPE_DYNAMIC;
+
+ BString__assert(o);
+}
+
+static void BString_Free (BString *o)
+{
+ BString__assert(o);
+
+ if (o->u.ud.type == BSTRING_TYPE_DYNAMIC) {
+ free(o->u.ud.dynamic_string);
+ }
+}
+
+static const char * BString_Get (BString *o)
+{
+ BString__assert(o);
+
+ switch (o->u.us.type) {
+ case BSTRING_TYPE_STATIC: return o->u.us.static_string;
+ case BSTRING_TYPE_DYNAMIC: return o->u.ud.dynamic_string;
+ case BSTRING_TYPE_EXTERNAL: return o->u.ue.external_string;
+ }
+
+ ASSERT(0);
+ return NULL;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/byteorder.h b/Shared/lwip/badvpn/misc/byteorder.h
new file mode 100644
index 0000000..6d21d1b
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/byteorder.h
@@ -0,0 +1,197 @@
+/**
+ * @file byteorder.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Byte order conversion functions.
+ *
+ * hton* functions convert from host to big-endian (network) byte order.
+ * htol* functions convert from host to little-endian byte order.
+ * ntoh* functions convert from big-endian (network) to host byte order.
+ * ltoh* functions convert from little-endian to host byte order.
+ */
+
+#ifndef BADVPN_MISC_BYTEORDER_H
+#define BADVPN_MISC_BYTEORDER_H
+
+#define BADVPN_LITTLE_ENDIAN 1
+#if (defined(BADVPN_LITTLE_ENDIAN) + defined(BADVPN_BIG_ENDIAN)) != 1
+#error Unknown byte order or too many byte orders
+#endif
+
+#include
+
+static uint16_t badvpn_reverse16 (uint16_t x)
+{
+ uint16_t y;
+ *((uint8_t *)&y+0) = *((uint8_t *)&x+1);
+ *((uint8_t *)&y+1) = *((uint8_t *)&x+0);
+ return y;
+}
+
+static uint32_t badvpn_reverse32 (uint32_t x)
+{
+ uint32_t y;
+ *((uint8_t *)&y+0) = *((uint8_t *)&x+3);
+ *((uint8_t *)&y+1) = *((uint8_t *)&x+2);
+ *((uint8_t *)&y+2) = *((uint8_t *)&x+1);
+ *((uint8_t *)&y+3) = *((uint8_t *)&x+0);
+ return y;
+}
+
+static uint64_t badvpn_reverse64 (uint64_t x)
+{
+ uint64_t y;
+ *((uint8_t *)&y+0) = *((uint8_t *)&x+7);
+ *((uint8_t *)&y+1) = *((uint8_t *)&x+6);
+ *((uint8_t *)&y+2) = *((uint8_t *)&x+5);
+ *((uint8_t *)&y+3) = *((uint8_t *)&x+4);
+ *((uint8_t *)&y+4) = *((uint8_t *)&x+3);
+ *((uint8_t *)&y+5) = *((uint8_t *)&x+2);
+ *((uint8_t *)&y+6) = *((uint8_t *)&x+1);
+ *((uint8_t *)&y+7) = *((uint8_t *)&x+0);
+ return y;
+}
+
+static uint8_t hton8 (uint8_t x)
+{
+ return x;
+}
+
+static uint8_t htol8 (uint8_t x)
+{
+ return x;
+}
+
+#if defined(BADVPN_LITTLE_ENDIAN)
+
+static uint16_t hton16 (uint16_t x)
+{
+ return badvpn_reverse16(x);
+}
+
+static uint32_t hton32 (uint32_t x)
+{
+ return badvpn_reverse32(x);
+}
+
+static uint64_t hton64 (uint64_t x)
+{
+ return badvpn_reverse64(x);
+}
+
+static uint16_t htol16 (uint16_t x)
+{
+ return x;
+}
+
+static uint32_t htol32 (uint32_t x)
+{
+ return x;
+}
+
+static uint64_t htol64 (uint64_t x)
+{
+ return x;
+}
+
+#elif defined(BADVPN_BIG_ENDIAN)
+
+static uint16_t hton16 (uint16_t x)
+{
+ return x;
+}
+
+static uint32_t hton32 (uint32_t x)
+{
+ return x;
+}
+
+static uint64_t hton64 (uint64_t x)
+{
+ return x;
+}
+
+static uint16_t htol16 (uint16_t x)
+{
+ return badvpn_reverse16(x);
+}
+
+static uint32_t htol32 (uint32_t x)
+{
+ return badvpn_reverse32(x);
+}
+
+static uint64_t htol64 (uint64_t x)
+{
+ return badvpn_reverse64(x);
+}
+
+#endif
+
+//static uint8_t ntoh8 (uint8_t x)
+//{
+// return hton8(x);
+//}
+//
+//static uint16_t ntoh16 (uint16_t x)
+//{
+// return hton16(x);
+//}
+//
+//static uint32_t ntoh32 (uint32_t x)
+//{
+// return hton32(x);
+//}
+//
+//static uint64_t ntoh64 (uint64_t x)
+//{
+// return hton64(x);
+//}
+//
+//static uint8_t ltoh8 (uint8_t x)
+//{
+// return htol8(x);
+//}
+//
+//static uint16_t ltoh16 (uint16_t x)
+//{
+// return htol16(x);
+//}
+//
+//static uint32_t ltoh32 (uint32_t x)
+//{
+// return htol32(x);
+//}
+//
+//static uint64_t ltoh64 (uint64_t x)
+//{
+// return htol64(x);
+//}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/cmdline.h b/Shared/lwip/badvpn/misc/cmdline.h
new file mode 100644
index 0000000..396d794
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/cmdline.h
@@ -0,0 +1,168 @@
+/**
+ * @file cmdline.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Command line construction functions.
+ */
+
+#ifndef BADVPN_MISC_CMDLINE_H
+#define BADVPN_MISC_CMDLINE_H
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+typedef struct {
+ struct ExpArray arr;
+ size_t n;
+} CmdLine;
+
+static int CmdLine_Init (CmdLine *c);
+static void CmdLine_Free (CmdLine *c);
+static int CmdLine_Append (CmdLine *c, const char *str);
+static int CmdLine_AppendNoNull (CmdLine *c, const char *str, size_t str_len);
+static int CmdLine_AppendNoNullMr (CmdLine *c, MemRef mr);
+static int CmdLine_AppendMulti (CmdLine *c, int num, ...);
+static int CmdLine_Finish (CmdLine *c);
+static char ** CmdLine_Get (CmdLine *c);
+
+static int _CmdLine_finished (CmdLine *c)
+{
+ return (c->n > 0 && ((char **)c->arr.v)[c->n - 1] == NULL);
+}
+
+int CmdLine_Init (CmdLine *c)
+{
+ if (!ExpArray_init(&c->arr, sizeof(char *), 16)) {
+ return 0;
+ }
+
+ c->n = 0;
+
+ return 1;
+}
+
+void CmdLine_Free (CmdLine *c)
+{
+ for (size_t i = 0; i < c->n; i++) {
+ free(((char **)c->arr.v)[i]);
+ }
+
+ free(c->arr.v);
+}
+
+int CmdLine_Append (CmdLine *c, const char *str)
+{
+ ASSERT(str)
+ ASSERT(!_CmdLine_finished(c))
+
+ if (!ExpArray_resize(&c->arr, c->n + 1)) {
+ return 0;
+ }
+
+ if (!(((char **)c->arr.v)[c->n] = strdup(str))) {
+ return 0;
+ }
+
+ c->n++;
+
+ return 1;
+}
+
+int CmdLine_AppendNoNull (CmdLine *c, const char *str, size_t str_len)
+{
+ ASSERT(str)
+ ASSERT(!memchr(str, '\0', str_len))
+ ASSERT(!_CmdLine_finished(c))
+
+ if (!ExpArray_resize(&c->arr, c->n + 1)) {
+ return 0;
+ }
+
+ if (!(((char **)c->arr.v)[c->n] = b_strdup_bin(str, str_len))) {
+ return 0;
+ }
+
+ c->n++;
+
+ return 1;
+}
+
+int CmdLine_AppendNoNullMr (CmdLine *c, MemRef mr)
+{
+ return CmdLine_AppendNoNull(c, mr.ptr, mr.len);
+}
+
+int CmdLine_AppendMulti (CmdLine *c, int num, ...)
+{
+ int res = 1;
+
+ va_list vl;
+ va_start(vl, num);
+
+ for (int i = 0; i < num; i++) {
+ const char *str = va_arg(vl, const char *);
+ if (!CmdLine_Append(c, str)) {
+ res = 0;
+ break;
+ }
+ }
+
+ va_end(vl);
+
+ return res;
+}
+
+int CmdLine_Finish (CmdLine *c)
+{
+ ASSERT(!_CmdLine_finished(c))
+
+ if (!ExpArray_resize(&c->arr, c->n + 1)) {
+ return 0;
+ }
+
+ ((char **)c->arr.v)[c->n] = NULL;
+
+ c->n++;
+
+ return 1;
+}
+
+char ** CmdLine_Get (CmdLine *c)
+{
+ ASSERT(_CmdLine_finished(c))
+
+ return (char **)c->arr.v;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/compare.h b/Shared/lwip/badvpn/misc/compare.h
new file mode 100644
index 0000000..8d1a1b9
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/compare.h
@@ -0,0 +1,37 @@
+/**
+ * @file compare.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_COMPARE_H
+#define BADVPN_COMPARE_H
+
+#define B_COMPARE(a, b) (((a) > (b)) - ((a) < (b)))
+#define B_COMPARE_COMBINE(cmp1, cmp2) ((cmp1) ? (cmp1) : (cmp2))
+#define B_COMPARE2(a, b, c, d) B_COMPARE_COMBINE(B_COMPARE((a), (b)), B_COMPARE((c), (d)))
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/concat_strings.h b/Shared/lwip/badvpn/misc/concat_strings.h
new file mode 100644
index 0000000..30330bc
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/concat_strings.h
@@ -0,0 +1,85 @@
+/**
+ * @file concat_strings.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Function for concatenating strings.
+ */
+
+#ifndef BADVPN_MISC_CONCAT_STRINGS_H
+#define BADVPN_MISC_CONCAT_STRINGS_H
+
+#include
+#include
+#include
+
+#include
+
+static char * concat_strings (int num, ...)
+{
+ ASSERT(num >= 0)
+
+ // calculate sum of lengths
+ size_t sum = 0;
+ va_list ap;
+ va_start(ap, num);
+ for (int i = 0; i < num; i++) {
+ const char *str = va_arg(ap, const char *);
+ size_t str_len = strlen(str);
+ if (str_len > SIZE_MAX - 1 - sum) {
+ va_end(ap);
+ return NULL;
+ }
+ sum += str_len;
+ }
+ va_end(ap);
+
+ // allocate memory
+ char *res_str = (char *)malloc(sum + 1);
+ if (!res_str) {
+ return NULL;
+ }
+
+ // copy strings
+ sum = 0;
+ va_start(ap, num);
+ for (int i = 0; i < num; i++) {
+ const char *str = va_arg(ap, const char *);
+ size_t str_len = strlen(str);
+ memcpy(res_str + sum, str, str_len);
+ sum += str_len;
+ }
+ va_end(ap);
+
+ // terminate
+ res_str[sum] = '\0';
+
+ return res_str;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/dead.h b/Shared/lwip/badvpn/misc/dead.h
new file mode 100644
index 0000000..7f57421
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/dead.h
@@ -0,0 +1,134 @@
+/**
+ * @file dead.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Dead mechanism definitions.
+ *
+ * The dead mechanism is a way for a piece of code to detect whether some
+ * specific event has occured during some operation (usually during calling
+ * a user-provided handler function), without requiring access to memory
+ * that might no longer be available because of the event.
+ *
+ * It works somehow like that:
+ *
+ * First a dead variable ({@link dead_t}) is allocated somewhere, and
+ * initialized with {@link DEAD_INIT}, e.g.:
+ * DEAD_INIT(dead);
+ *
+ * When the event that needs to be caught occurs, {@link DEAD_KILL} is
+ * called, e.g.:
+ * DEAD_KILL(dead);
+ * The memory used by the dead variable is no longer needed after
+ * that.
+ *
+ * If a piece of code needs to know whether the event occured during some
+ * operation (but it must not have occured before!), it puts {@link DEAD_ENTER}}
+ * in front of the operation, and does {@link DEAD_LEAVE} at the end. If
+ * {@link DEAD_LEAVE} returned nonzero, the event occured, otherwise it did
+ * not. Example:
+ * DEAD_ENTER(dead)
+ * HandlerFunction();
+ * if (DEAD_LEAVE(dead)) {
+ * (event occured)
+ * }
+ *
+ * If is is needed to check for the event more than once in a single block,
+ * {@link DEAD_DECLARE} should be put somewhere before, and {@link DEAD_ENTER2}
+ * should be used instead of {@link DEAD_ENTER}.
+ *
+ * If it is needed to check for multiple events (dead variables) at the same
+ * time, DEAD_*_N macros should be used instead, specifying different
+ * identiers as the first argument for different dead variables.
+ */
+
+#ifndef BADVPN_MISC_DEAD_H
+#define BADVPN_MISC_DEAD_H
+
+#include
+
+/**
+ * Dead variable.
+ */
+typedef int *dead_t;
+
+/**
+ * Initializes a dead variable.
+ */
+#define DEAD_INIT(ptr) { ptr = NULL; }
+
+/**
+ * Kills the dead variable,
+ */
+#define DEAD_KILL(ptr) { if (ptr) *(ptr) = 1; }
+
+/**
+ * Kills the dead variable with the given value, or does nothing
+ * if the value is 0. The value will seen by {@link DEAD_KILLED}.
+ */
+#define DEAD_KILL_WITH(ptr, val) { if (ptr) *(ptr) = (val); }
+
+/**
+ * Declares dead catching variables.
+ */
+#define DEAD_DECLARE int badvpn__dead; dead_t badvpn__prev_ptr;
+
+/**
+ * Enters a dead catching using already declared dead catching variables.
+ * The dead variable must have been initialized with {@link DEAD_INIT},
+ * and {@link DEAD_KILL} must not have been called yet.
+ * {@link DEAD_LEAVE2} must be called before the current scope is left.
+ */
+#define DEAD_ENTER2(ptr) { badvpn__dead = 0; badvpn__prev_ptr = ptr; ptr = &badvpn__dead; }
+
+/**
+ * Declares dead catching variables and enters a dead catching.
+ * The dead variable must have been initialized with {@link DEAD_INIT},
+ * and {@link DEAD_KILL} must not have been called yet.
+ * {@link DEAD_LEAVE2} must be called before the current scope is left.
+ */
+#define DEAD_ENTER(ptr) DEAD_DECLARE DEAD_ENTER2(ptr)
+
+/**
+ * Leaves a dead catching.
+ */
+#define DEAD_LEAVE2(ptr) { if (!badvpn__dead) ptr = badvpn__prev_ptr; if (badvpn__prev_ptr) *badvpn__prev_ptr = badvpn__dead; }
+
+/**
+ * Returns 1 if {@link DEAD_KILL} was called for the dead variable, 0 otherwise.
+ * Must be called after entering a dead catching.
+ */
+#define DEAD_KILLED (badvpn__dead)
+
+#define DEAD_DECLARE_N(n) int badvpn__dead##n; dead_t badvpn__prev_ptr##n;
+#define DEAD_ENTER2_N(n, ptr) { badvpn__dead##n = 0; badvpn__prev_ptr##n = ptr; ptr = &badvpn__dead##n;}
+#define DEAD_ENTER_N(n, ptr) DEAD_DECLARE_N(n) DEAD_ENTER2_N(n, ptr)
+#define DEAD_LEAVE2_N(n, ptr) { if (!badvpn__dead##n) ptr = badvpn__prev_ptr##n; if (badvpn__prev_ptr##n) *badvpn__prev_ptr##n = badvpn__dead##n; }
+#define DEAD_KILLED_N(n) (badvpn__dead##n)
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/debug.h b/Shared/lwip/badvpn/misc/debug.h
new file mode 100644
index 0000000..20a9603
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/debug.h
@@ -0,0 +1,141 @@
+/**
+ * @file debug.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Debugging macros.
+ */
+
+/**
+ * @def DEBUG
+ *
+ * Macro for printing debugging text. Use the same way as printf,
+ * but without a newline.
+ * Prepends "function_name: " and appends a newline.
+ */
+
+/**
+ * @def ASSERT_FORCE
+ *
+ * Macro for forced assertions.
+ * Evaluates the argument and terminates the program abnormally
+ * if the result is false.
+ */
+
+/**
+ * @def ASSERT
+ *
+ * Macro for assertions.
+ * The argument may or may not be evaluated.
+ * If the argument is evaluated, it must not evaluate to false.
+ */
+
+/**
+ * @def ASSERT_EXECUTE
+ *
+ * Macro for always-evaluated assertions.
+ * The argument is evaluated.
+ * The argument must not evaluate to false.
+ */
+
+/**
+ * @def DEBUG_ZERO_MEMORY
+ *
+ * If debugging is enabled, zeroes the given memory region.
+ * First argument is pointer to the memory region, second is
+ * number of bytes.
+ */
+
+/**
+ * @def WARN_UNUSED
+ *
+ * Tells the compiler that the result of a function should not be unused.
+ * Insert at the end of the declaration of a function before the semicolon.
+ */
+
+/**
+ * @def B_USE
+ *
+ * This can be used to suppress warnings about unused variables. It can
+ * be applied to a variable or any expression. It does not evaluate the
+ * expression.
+ */
+
+#ifndef BADVPN_MISC_DEBUG_H
+#define BADVPN_MISC_DEBUG_H
+
+#include
+#include
+#include
+#include
+#include
+
+#define CDEBUG(...) \
+ { \
+ fprintf(stderr, "%s: ", __FUNCTION__); \
+ fprintf(stderr, __VA_ARGS__); \
+ fprintf(stderr, "\n"); \
+ }
+
+#define ASSERT_FORCE(e) \
+ { \
+ if (!(e)) { \
+ fprintf(stderr, "%s:%d Assertion failed\n", __FILE__, __LINE__); \
+ } \
+ }
+
+#ifdef NDEBUG
+ #define DEBUG_ZERO_MEMORY(buf, len) {}
+ #define ASSERT(e) {}
+ #define ASSERT_EXECUTE(e) { (e); }
+#else
+ #define DEBUG_ZERO_MEMORY(buf, len) { memset((buf), 0, (len)); }
+ #ifdef BADVPN_USE_C_ASSERT
+ #define ASSERT(e) { assert(e); }
+ #define ASSERT_EXECUTE(e) \
+ { \
+ int _assert_res = !!(e); \
+ assert(_assert_res); \
+ }
+ #else
+ #define ASSERT(e) ASSERT_FORCE(e)
+ #define ASSERT_EXECUTE(e) ASSERT_FORCE(e)
+ #endif
+#endif
+
+#ifdef __GNUC__
+ #define WARN_UNUSED __attribute__((warn_unused_result))
+#else
+ #define WARN_UNUSED
+#endif
+
+#define B_USE(expr) (void)(sizeof((expr)));
+
+#define B_ASSERT_USE(expr) { ASSERT(expr) B_USE(expr) }
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/debugcounter.h b/Shared/lwip/badvpn/misc/debugcounter.h
new file mode 100644
index 0000000..a8a54a1
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/debugcounter.h
@@ -0,0 +1,118 @@
+/**
+ * @file debugcounter.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Counter for detecting leaks.
+ */
+
+#ifndef BADVPN_MISC_DEBUGCOUNTER_H
+#define BADVPN_MISC_DEBUGCOUNTER_H
+
+#include
+
+#include
+
+/**
+ * Counter for detecting leaks.
+ */
+typedef struct {
+#ifndef NDEBUG
+ int32_t c;
+#endif
+} DebugCounter;
+
+#ifndef NDEBUG
+#define DEBUGCOUNTER_STATIC { 0 }
+#else
+#define DEBUGCOUNTER_STATIC {}
+#endif
+
+/**
+ * Initializes the object.
+ * The object is initialized with counter value zero.
+ *
+ * @param obj the object
+ */
+static void DebugCounter_Init (DebugCounter *obj)
+{
+#ifndef NDEBUG
+ obj->c = 0;
+#endif
+}
+
+/**
+ * Frees the object.
+ * This does not have to be called when the counter is no longer needed.
+ * The counter value must be zero.
+ *
+ * @param obj the object
+ */
+static void DebugCounter_Free (DebugCounter *obj)
+{
+#ifndef NDEBUG
+ ASSERT(obj->c == 0 || obj->c == INT32_MAX)
+#endif
+}
+
+/**
+ * Increments the counter.
+ * Increments the counter value by one.
+ *
+ * @param obj the object
+ */
+static void DebugCounter_Increment (DebugCounter *obj)
+{
+#ifndef NDEBUG
+ ASSERT(obj->c >= 0)
+
+ if (obj->c != INT32_MAX) {
+ obj->c++;
+ }
+#endif
+}
+
+/**
+ * Decrements the counter.
+ * The counter value must be >0.
+ * Decrements the counter value by one.
+ *
+ * @param obj the object
+ */
+static void DebugCounter_Decrement (DebugCounter *obj)
+{
+#ifndef NDEBUG
+ ASSERT(obj->c > 0)
+
+ if (obj->c != INT32_MAX) {
+ obj->c--;
+ }
+#endif
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/debugerror.h b/Shared/lwip/badvpn/misc/debugerror.h
new file mode 100644
index 0000000..182afd7
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/debugerror.h
@@ -0,0 +1,90 @@
+/**
+ * @file debugerror.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Mechanism for ensuring an object is destroyed from inside an error handler
+ * or its jobs.
+ */
+
+#ifndef BADVPN_MISC_DEBUGERROR_H
+#define BADVPN_MISC_DEBUGERROR_H
+
+#include
+#include
+
+#ifndef NDEBUG
+ #define DEBUGERROR(de, call) \
+ { \
+ ASSERT(!BPending_IsSet(&(de)->job)) \
+ BPending_Set(&(de)->job); \
+ (call); \
+ }
+#else
+ #define DEBUGERROR(de, call) { (call); }
+#endif
+
+typedef struct {
+ #ifndef NDEBUG
+ BPending job;
+ #endif
+} DebugError;
+
+static void DebugError_Init (DebugError *o, BPendingGroup *pg);
+static void DebugError_Free (DebugError *o);
+static void DebugError_AssertNoError (DebugError *o);
+
+#ifndef NDEBUG
+static void _DebugError_job_handler (DebugError *o)
+{
+ ASSERT(0);
+}
+#endif
+
+void DebugError_Init (DebugError *o, BPendingGroup *pg)
+{
+ #ifndef NDEBUG
+ BPending_Init(&o->job, pg, (BPending_handler)_DebugError_job_handler, o);
+ #endif
+}
+
+void DebugError_Free (DebugError *o)
+{
+ #ifndef NDEBUG
+ BPending_Free(&o->job);
+ #endif
+}
+
+void DebugError_AssertNoError (DebugError *o)
+{
+ #ifndef NDEBUG
+ ASSERT(!BPending_IsSet(&o->job))
+ #endif
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/dhcp_proto.h b/Shared/lwip/badvpn/misc/dhcp_proto.h
new file mode 100644
index 0000000..ed83544
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/dhcp_proto.h
@@ -0,0 +1,131 @@
+/**
+ * @file dhcp_proto.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Definitions for the DHCP protocol.
+ */
+
+#ifndef BADVPN_MISC_DHCP_PROTO_H
+#define BADVPN_MISC_DHCP_PROTO_H
+
+#include
+
+#include
+
+#define DHCP_OP_BOOTREQUEST 1
+#define DHCP_OP_BOOTREPLY 2
+
+#define DHCP_HARDWARE_ADDRESS_TYPE_ETHERNET 1
+
+#define DHCP_MAGIC 0x63825363
+
+#define DHCP_OPTION_PAD 0
+#define DHCP_OPTION_END 255
+
+#define DHCP_OPTION_SUBNET_MASK 1
+#define DHCP_OPTION_ROUTER 3
+#define DHCP_OPTION_DOMAIN_NAME_SERVER 6
+#define DHCP_OPTION_HOST_NAME 12
+#define DHCP_OPTION_REQUESTED_IP_ADDRESS 50
+#define DHCP_OPTION_IP_ADDRESS_LEASE_TIME 51
+#define DHCP_OPTION_DHCP_MESSAGE_TYPE 53
+#define DHCP_OPTION_DHCP_SERVER_IDENTIFIER 54
+#define DHCP_OPTION_PARAMETER_REQUEST_LIST 55
+#define DHCP_OPTION_MAXIMUM_MESSAGE_SIZE 57
+#define DHCP_OPTION_RENEWAL_TIME_VALUE 58
+#define DHCP_OPTION_REBINDING_TIME_VALUE 59
+#define DHCP_OPTION_VENDOR_CLASS_IDENTIFIER 60
+#define DHCP_OPTION_CLIENT_IDENTIFIER 61
+
+#define DHCP_MESSAGE_TYPE_DISCOVER 1
+#define DHCP_MESSAGE_TYPE_OFFER 2
+#define DHCP_MESSAGE_TYPE_REQUEST 3
+#define DHCP_MESSAGE_TYPE_DECLINE 4
+#define DHCP_MESSAGE_TYPE_ACK 5
+#define DHCP_MESSAGE_TYPE_NAK 6
+#define DHCP_MESSAGE_TYPE_RELEASE 7
+
+B_START_PACKED
+struct dhcp_header {
+ uint8_t op;
+ uint8_t htype;
+ uint8_t hlen;
+ uint8_t hops;
+ uint32_t xid;
+ uint16_t secs;
+ uint16_t flags;
+ uint32_t ciaddr;
+ uint32_t yiaddr;
+ uint32_t siaddr;
+ uint32_t giaddr;
+ uint8_t chaddr[16];
+ uint8_t sname[64];
+ uint8_t file[128];
+ uint32_t magic;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct dhcp_option_header {
+ uint8_t type;
+ uint8_t len;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct dhcp_option_dhcp_message_type {
+ uint8_t type;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct dhcp_option_maximum_message_size {
+ uint16_t size;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct dhcp_option_dhcp_server_identifier {
+ uint32_t id;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct dhcp_option_time {
+ uint32_t time;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct dhcp_option_addr {
+ uint32_t addr;
+} B_PACKED;
+B_END_PACKED
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/ethernet_proto.h b/Shared/lwip/badvpn/misc/ethernet_proto.h
new file mode 100644
index 0000000..6e49e02
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/ethernet_proto.h
@@ -0,0 +1,52 @@
+/**
+ * @file ethernet_proto.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Definitions for the Ethernet protocol.
+ */
+
+#ifndef BADVPN_MISC_ETHERNET_PROTO_H
+#define BADVPN_MISC_ETHERNET_PROTO_H
+
+#include
+
+#include
+
+#define ETHERTYPE_IPV4 0x0800
+#define ETHERTYPE_ARP 0x0806
+
+B_START_PACKED
+struct ethernet_header {
+ uint8_t dest[6];
+ uint8_t source[6];
+ uint16_t type;
+} B_PACKED;
+B_END_PACKED
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/exparray.h b/Shared/lwip/badvpn/misc/exparray.h
new file mode 100644
index 0000000..b24149f
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/exparray.h
@@ -0,0 +1,101 @@
+/**
+ * @file exparray.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Dynamic array which grows exponentionally on demand.
+ */
+
+#ifndef BADVPN_MISC_EXPARRAY_H
+#define BADVPN_MISC_EXPARRAY_H
+
+#include
+#include
+#include
+
+#include
+
+struct ExpArray {
+ size_t esize;
+ size_t size;
+ void *v;
+};
+
+static int ExpArray_init (struct ExpArray *o, size_t esize, size_t size)
+{
+ ASSERT(esize > 0)
+ ASSERT(size > 0)
+
+ o->esize = esize;
+ o->size = size;
+
+ if (o->size > SIZE_MAX / o->esize) {
+ return 0;
+ }
+
+ if (!(o->v = malloc(o->size * o->esize))) {
+ return 0;
+ }
+
+ return 1;
+}
+
+static int ExpArray_resize (struct ExpArray *o, size_t size)
+{
+ ASSERT(size > 0)
+
+ if (size <= o->size) {
+ return 1;
+ }
+
+ size_t newsize = o->size;
+
+ while (newsize < size) {
+ if (2 > SIZE_MAX / newsize) {
+ return 0;
+ }
+
+ newsize = 2 * newsize;
+ }
+
+ if (newsize > SIZE_MAX / o->esize) {
+ return 0;
+ }
+
+ void *newarr = realloc(o->v, newsize * o->esize);
+ if (!newarr) {
+ return 0;
+ }
+
+ o->size = newsize;
+ o->v = newarr;
+
+ return 1;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/expstring.h b/Shared/lwip/badvpn/misc/expstring.h
new file mode 100644
index 0000000..8081e2f
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/expstring.h
@@ -0,0 +1,174 @@
+/**
+ * @file expstring.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_MISC_EXPSTRING_H
+#define BADVPN_MISC_EXPSTRING_H
+
+#include
+
+#include
+#include
+#include
+#include
+
+typedef struct {
+ struct ExpArray arr;
+ size_t n;
+} ExpString;
+
+static int ExpString_Init (ExpString *c);
+static void ExpString_Free (ExpString *c);
+static int ExpString_Append (ExpString *c, const char *str);
+static int ExpString_AppendChar (ExpString *c, char ch);
+static int ExpString_AppendByte (ExpString *c, uint8_t x);
+static int ExpString_AppendBinary (ExpString *c, const uint8_t *data, size_t len);
+static int ExpString_AppendBinaryMr (ExpString *c, MemRef data);
+static int ExpString_AppendZeros (ExpString *c, size_t len);
+static char * ExpString_Get (ExpString *c);
+static size_t ExpString_Length (ExpString *c);
+static MemRef ExpString_GetMr (ExpString *c);
+
+int ExpString_Init (ExpString *c)
+{
+ if (!ExpArray_init(&c->arr, 1, 16)) {
+ return 0;
+ }
+
+ c->n = 0;
+ ((char *)c->arr.v)[c->n] = '\0';
+
+ return 1;
+}
+
+void ExpString_Free (ExpString *c)
+{
+ free(c->arr.v);
+}
+
+int ExpString_Append (ExpString *c, const char *str)
+{
+ ASSERT(str)
+
+ size_t l = strlen(str);
+ bsize_t newsize = bsize_add(bsize_fromsize(c->n), bsize_add(bsize_fromsize(l), bsize_fromint(1)));
+
+ if (newsize.is_overflow || !ExpArray_resize(&c->arr, newsize.value)) {
+ return 0;
+ }
+
+ memcpy((char *)c->arr.v + c->n, str, l);
+ c->n += l;
+ ((char *)c->arr.v)[c->n] = '\0';
+
+ return 1;
+}
+
+int ExpString_AppendChar (ExpString *c, char ch)
+{
+ ASSERT(ch != '\0')
+
+ bsize_t newsize = bsize_add(bsize_fromsize(c->n), bsize_fromint(2));
+
+ if (newsize.is_overflow || !ExpArray_resize(&c->arr, newsize.value)) {
+ return 0;
+ }
+
+ ((char *)c->arr.v)[c->n] = ch;
+ c->n++;
+ ((char *)c->arr.v)[c->n] = '\0';
+
+ return 1;
+}
+
+int ExpString_AppendByte (ExpString *c, uint8_t x)
+{
+ bsize_t newsize = bsize_add(bsize_fromsize(c->n), bsize_fromint(2));
+
+ if (newsize.is_overflow || !ExpArray_resize(&c->arr, newsize.value)) {
+ return 0;
+ }
+
+ ((uint8_t *)c->arr.v)[c->n] = x;
+ c->n++;
+ ((char *)c->arr.v)[c->n] = '\0';
+
+ return 1;
+}
+
+int ExpString_AppendBinary (ExpString *c, const uint8_t *data, size_t len)
+{
+ bsize_t newsize = bsize_add(bsize_fromsize(c->n), bsize_add(bsize_fromsize(len), bsize_fromint(1)));
+
+ if (newsize.is_overflow || !ExpArray_resize(&c->arr, newsize.value)) {
+ return 0;
+ }
+
+ memcpy((char *)c->arr.v + c->n, data, len);
+ c->n += len;
+ ((char *)c->arr.v)[c->n] = '\0';
+
+ return 1;
+}
+
+int ExpString_AppendBinaryMr (ExpString *c, MemRef data)
+{
+ return ExpString_AppendBinary(c, (uint8_t const *)data.ptr, data.len);
+}
+
+int ExpString_AppendZeros (ExpString *c, size_t len)
+{
+ bsize_t newsize = bsize_add(bsize_fromsize(c->n), bsize_add(bsize_fromsize(len), bsize_fromint(1)));
+
+ if (newsize.is_overflow || !ExpArray_resize(&c->arr, newsize.value)) {
+ return 0;
+ }
+
+ memset((char *)c->arr.v + c->n, 0, len);
+ c->n += len;
+ ((char *)c->arr.v)[c->n] = '\0';
+
+ return 1;
+}
+
+char * ExpString_Get (ExpString *c)
+{
+ return (char *)c->arr.v;
+}
+
+size_t ExpString_Length (ExpString *c)
+{
+ return c->n;
+}
+
+MemRef ExpString_GetMr (ExpString *c)
+{
+ return MemRef_Make((char const *)c->arr.v, c->n);
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/find_char.h b/Shared/lwip/badvpn/misc/find_char.h
new file mode 100644
index 0000000..9277ac6
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/find_char.h
@@ -0,0 +1,58 @@
+/**
+ * @file find_char.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_FIND_CHAR_H
+#define BADVPN_FIND_CHAR_H
+
+#include
+
+#include
+
+/**
+ * Finds the first character 'c' in the string represented by 'str' and 'len'.
+ * If found, returns 1 and writes the position to *out_pos (if out_pos!=NULL).
+ * If not found, returns 0 and does not modify *out_pos.
+ */
+static int b_find_char_bin (const char *str, size_t len, char c, size_t *out_pos)
+{
+ ASSERT(str)
+
+ for (size_t i = 0; i < len; i++) {
+ if (str[i] == c) {
+ if (out_pos) {
+ *out_pos = i;
+ }
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/find_program.h b/Shared/lwip/badvpn/misc/find_program.h
new file mode 100644
index 0000000..d381e18
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/find_program.h
@@ -0,0 +1,103 @@
+/**
+ * @file find_program.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Function that finds the absolute path of a program by checking a predefined
+ * list of directories.
+ */
+
+#ifndef BADVPN_FIND_PROGRAM_H
+#define BADVPN_FIND_PROGRAM_H
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+static char * badvpn_find_program (const char *name);
+
+static char * badvpn_find_program (const char *name)
+{
+ ASSERT(name)
+
+ char *path = getenv("PATH");
+ if (path) {
+ while (1) {
+ size_t i = 0;
+ while (path[i] != ':' && path[i] != '\0') {
+ i++;
+ }
+ char const *src = path;
+ size_t src_len = i;
+ if (src_len == 0) {
+ src = ".";
+ src_len = 1;
+ }
+ size_t name_len = strlen(name);
+ char *entry = BAllocSize(bsize_add(bsize_fromsize(src_len), bsize_add(bsize_fromsize(name_len), bsize_fromsize(2))));
+ if (!entry) {
+ goto fail;
+ }
+ memcpy(entry, src, src_len);
+ entry[src_len] = '/';
+ strcpy(entry + (src_len + 1), name);
+ if (access(entry, X_OK) == 0) {
+ return entry;
+ }
+ free(entry);
+ if (path[i] == '\0') {
+ break;
+ }
+ path += i + 1;
+ }
+ }
+
+ const char *dirs[] = {"/usr/sbin", "/usr/bin", "/sbin", "/bin", NULL};
+
+ for (size_t i = 0; dirs[i]; i++) {
+ char *try_path = concat_strings(3, dirs[i], "/", name);
+ if (!try_path) {
+ goto fail;
+ }
+
+ if (access(try_path, X_OK) == 0) {
+ return try_path;
+ }
+
+ free(try_path);
+ }
+
+fail:
+ return NULL;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/get_iface_info.h b/Shared/lwip/badvpn/misc/get_iface_info.h
new file mode 100644
index 0000000..190741b
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/get_iface_info.h
@@ -0,0 +1,110 @@
+/**
+ * @file get_iface_info.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_GETIFACEINFO_H
+#define BADVPN_GETIFACEINFO_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+/**
+ * Returns information about a network interface with the given name.
+ *
+ * @param ifname name of interface to get information for
+ * @param out_mac the MAC address will be returned here, unless NULL
+ * @param out_mtu the MTU will be returned here, unless NULL
+ * @param out_ifindex the interface index will be returned here, unless NULL
+ * @return 1 on success, 0 on failure
+ */
+static int badvpn_get_iface_info (const char *ifname, uint8_t *out_mac, int *out_mtu, int *out_ifindex) WARN_UNUSED;
+
+
+static int badvpn_get_iface_info (const char *ifname, uint8_t *out_mac, int *out_mtu, int *out_ifindex)
+{
+ ASSERT(ifname)
+
+ struct ifreq ifr;
+
+ int s = socket(AF_INET, SOCK_DGRAM, 0);
+ if (s < 0) {
+ goto fail0;
+ }
+
+ // get MAC
+ if (out_mac) {
+ memset(&ifr, 0, sizeof(ifr));
+ snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifname);
+ if (ioctl(s, SIOCGIFHWADDR, &ifr)) {
+ goto fail1;
+ }
+ if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
+ goto fail1;
+ }
+ memcpy(out_mac, ifr.ifr_hwaddr.sa_data, 6);
+ }
+
+ // get MTU
+ if (out_mtu) {
+ memset(&ifr, 0, sizeof(ifr));
+ snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifname);
+ if (ioctl(s, SIOCGIFMTU, &ifr)) {
+ goto fail1;
+ }
+ *out_mtu = ifr.ifr_mtu;
+ }
+
+ // get interface index
+ if (out_ifindex) {
+ memset(&ifr, 0, sizeof(ifr));
+ snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifname);
+ if (ioctl(s, SIOCGIFINDEX, &ifr)) {
+ goto fail1;
+ }
+ *out_ifindex = ifr.ifr_ifindex;
+ }
+
+ close(s);
+
+ return 1;
+
+fail1:
+ close(s);
+fail0:
+ return 0;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/grow_array.h b/Shared/lwip/badvpn/misc/grow_array.h
new file mode 100644
index 0000000..9a42d04
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/grow_array.h
@@ -0,0 +1,139 @@
+/**
+ * @file grow_array.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// Preprocessor inputs:
+// GROWARRAY_NAME - prefix of of functions to define
+// GROWARRAY_OBJECT_TYPE - type of structure where array and capacity sizes are
+// GROWARRAY_ARRAY_MEMBER - array member
+// GROWARRAY_CAPACITY_MEMBER - capacity member
+// GROWARRAY_MAX_CAPACITY - max value of capacity member
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+#define GrowArrayObject GROWARRAY_OBJECT_TYPE
+#define GrowArray_Init MERGE(GROWARRAY_NAME, _Init)
+#define GrowArray_InitEmpty MERGE(GROWARRAY_NAME, _InitEmpty)
+#define GrowArray_Free MERGE(GROWARRAY_NAME, _Free)
+#define GrowArray_DoubleUp MERGE(GROWARRAY_NAME, _DoubleUp)
+#define GrowArray_DoubleUpLimit MERGE(GROWARRAY_NAME, _DoubleUpLimit)
+
+static int GrowArray_Init (GrowArrayObject *o, size_t capacity) WARN_UNUSED;
+static void GrowArray_InitEmpty (GrowArrayObject *o);
+static void GrowArray_Free (GrowArrayObject *o);
+static int GrowArray_DoubleUp (GrowArrayObject *o) WARN_UNUSED;
+static int GrowArray_DoubleUpLimit (GrowArrayObject *o, size_t limit) WARN_UNUSED;
+
+static int GrowArray_Init (GrowArrayObject *o, size_t capacity)
+{
+ if (capacity > GROWARRAY_MAX_CAPACITY) {
+ return 0;
+ }
+
+ if (capacity == 0) {
+ o->GROWARRAY_ARRAY_MEMBER = NULL;
+ } else {
+ if (!(o->GROWARRAY_ARRAY_MEMBER = BAllocArray(capacity, sizeof(o->GROWARRAY_ARRAY_MEMBER[0])))) {
+ return 0;
+ }
+ }
+
+ o->GROWARRAY_CAPACITY_MEMBER = capacity;
+
+ return 1;
+}
+
+static void GrowArray_InitEmpty (GrowArrayObject *o)
+{
+ o->GROWARRAY_ARRAY_MEMBER = NULL;
+ o->GROWARRAY_CAPACITY_MEMBER = 0;
+}
+
+static void GrowArray_Free (GrowArrayObject *o)
+{
+ if (o->GROWARRAY_ARRAY_MEMBER) {
+ BFree(o->GROWARRAY_ARRAY_MEMBER);
+ }
+}
+
+static int GrowArray_DoubleUp (GrowArrayObject *o)
+{
+ return GrowArray_DoubleUpLimit(o, SIZE_MAX);
+}
+
+static int GrowArray_DoubleUpLimit (GrowArrayObject *o, size_t limit)
+{
+ if (o->GROWARRAY_CAPACITY_MEMBER > SIZE_MAX / 2 || o->GROWARRAY_CAPACITY_MEMBER > GROWARRAY_MAX_CAPACITY / 2) {
+ return 0;
+ }
+
+ size_t newcap = 2 * o->GROWARRAY_CAPACITY_MEMBER;
+ if (newcap == 0) {
+ newcap = 1;
+ }
+
+ if (newcap > limit) {
+ newcap = limit;
+ if (newcap == o->GROWARRAY_CAPACITY_MEMBER) {
+ return 0;
+ }
+ }
+
+ void *newarr = BAllocArray(newcap, sizeof(o->GROWARRAY_ARRAY_MEMBER[0]));
+ if (!newarr) {
+ return 0;
+ }
+
+ memcpy(newarr, o->GROWARRAY_ARRAY_MEMBER, o->GROWARRAY_CAPACITY_MEMBER * sizeof(o->GROWARRAY_ARRAY_MEMBER[0]));
+
+ BFree(o->GROWARRAY_ARRAY_MEMBER);
+
+ o->GROWARRAY_ARRAY_MEMBER = newarr;
+ o->GROWARRAY_CAPACITY_MEMBER = newcap;
+
+ return 1;
+}
+
+#undef GROWARRAY_NAME
+#undef GROWARRAY_OBJECT_TYPE
+#undef GROWARRAY_ARRAY_MEMBER
+#undef GROWARRAY_CAPACITY_MEMBER
+#undef GROWARRAY_MAX_CAPACITY
+
+#undef GrowArrayObject
+#undef GrowArray_Init
+#undef GrowArray_InitEmpty
+#undef GrowArray_Free
+#undef GrowArray_DoubleUp
+#undef GrowArray_DoubleUpLimit
diff --git a/Shared/lwip/badvpn/misc/hashfun.h b/Shared/lwip/badvpn/misc/hashfun.h
new file mode 100644
index 0000000..5e8956a
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/hashfun.h
@@ -0,0 +1,60 @@
+/**
+ * @file hashfun.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_HASHFUN_H
+#define BADVPN_HASHFUN_H
+
+#include
+#include
+
+static size_t badvpn_djb2_hash (const uint8_t *str)
+{
+ size_t hash = 5381;
+ int c;
+
+ while (c = *str++) {
+ hash = ((hash << 5) + hash) + c;
+ }
+
+ return hash;
+}
+
+static size_t badvpn_djb2_hash_bin (const uint8_t *str, size_t str_len)
+{
+ size_t hash = 5381;
+
+ while (str_len-- > 0) {
+ int c = *str++;
+ hash = ((hash << 5) + hash) + c;
+ }
+
+ return hash;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/igmp_proto.h b/Shared/lwip/badvpn/misc/igmp_proto.h
new file mode 100644
index 0000000..9188ea0
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/igmp_proto.h
@@ -0,0 +1,97 @@
+/**
+ * @file igmp_proto.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Definitions for the IGMP protocol.
+ */
+
+#ifndef BADVPN_MISC_IGMP_PROTO_H
+#define BADVPN_MISC_IGMP_PROTO_H
+
+#include
+
+#include
+
+#define IGMP_TYPE_MEMBERSHIP_QUERY 0x11
+#define IGMP_TYPE_V1_MEMBERSHIP_REPORT 0x12
+#define IGMP_TYPE_V2_MEMBERSHIP_REPORT 0x16
+#define IGMP_TYPE_V3_MEMBERSHIP_REPORT 0x22
+#define IGMP_TYPE_V2_LEAVE_GROUP 0x17
+
+#define IGMP_RECORD_TYPE_MODE_IS_INCLUDE 1
+#define IGMP_RECORD_TYPE_MODE_IS_EXCLUDE 2
+#define IGMP_RECORD_TYPE_CHANGE_TO_INCLUDE_MODE 3
+#define IGMP_RECORD_TYPE_CHANGE_TO_EXCLUDE_MODE 4
+
+B_START_PACKED
+struct igmp_source {
+ uint32_t addr;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct igmp_base {
+ uint8_t type;
+ uint8_t max_resp_code;
+ uint16_t checksum;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct igmp_v3_query_extra {
+ uint32_t group;
+ uint8_t reserved4_suppress1_qrv3;
+ uint8_t qqic;
+ uint16_t number_of_sources;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct igmp_v3_report_extra {
+ uint16_t reserved;
+ uint16_t number_of_group_records;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct igmp_v3_report_record {
+ uint8_t type;
+ uint8_t aux_data_len;
+ uint16_t number_of_sources;
+ uint32_t group;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct igmp_v2_extra {
+ uint32_t group;
+} B_PACKED;
+B_END_PACKED
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/ipaddr.h b/Shared/lwip/badvpn/misc/ipaddr.h
new file mode 100644
index 0000000..6de5852
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/ipaddr.h
@@ -0,0 +1,201 @@
+/**
+ * @file ipaddr.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * IP address parsing functions.
+ */
+
+#ifndef BADVPN_MISC_IPADDR_H
+#define BADVPN_MISC_IPADDR_H
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+struct ipv4_ifaddr {
+ uint32_t addr;
+ int prefix;
+};
+
+static int ipaddr_parse_ipv4_addr (MemRef name, uint32_t *out_addr);
+static int ipaddr_parse_ipv4_prefix (MemRef str, int *num);
+static int ipaddr_parse_ipv4_ifaddr (MemRef str, struct ipv4_ifaddr *out);
+static int ipaddr_ipv4_ifaddr_from_addr_mask (uint32_t addr, uint32_t mask, struct ipv4_ifaddr *out);
+static uint32_t ipaddr_ipv4_mask_from_prefix (int prefix);
+static int ipaddr_ipv4_prefix_from_mask (uint32_t mask, int *out_prefix);
+static int ipaddr_ipv4_addrs_in_network (uint32_t addr1, uint32_t addr2, int netprefix);
+
+#define IPADDR_PRINT_MAX 19
+
+static void ipaddr_print_addr (uint32_t addr, char *out);
+static void ipaddr_print_ifaddr (struct ipv4_ifaddr ifaddr, char *out);
+
+int ipaddr_parse_ipv4_addr (MemRef name, uint32_t *out_addr)
+{
+ for (size_t i = 0; ; i++) {
+ size_t j;
+ for (j = 0; j < name.len && name.ptr[j] != '.'; j++);
+
+ if ((j == name.len && i < 3) || (j < name.len && i == 3)) {
+ return 0;
+ }
+
+ if (j < 1 || j > 3) {
+ return 0;
+ }
+
+ uintmax_t d;
+ if (!parse_unsigned_integer(MemRef_SubTo(name, j), &d)) {
+ return 0;
+ }
+
+ if (d > 255) {
+ return 0;
+ }
+
+ ((uint8_t *)out_addr)[i] = d;
+
+ if (i == 3) {
+ return 1;
+ }
+
+ name.ptr += j + 1;
+ name.len -= j + 1;
+ }
+}
+
+int ipaddr_parse_ipv4_prefix (MemRef str, int *num)
+{
+ uintmax_t d;
+ if (!parse_unsigned_integer(str, &d)) {
+ return 0;
+ }
+ if (d > 32) {
+ return 0;
+ }
+
+ *num = d;
+ return 1;
+}
+
+int ipaddr_parse_ipv4_ifaddr (MemRef str, struct ipv4_ifaddr *out)
+{
+ size_t slash_pos;
+ if (!MemRef_FindChar(str, '/', &slash_pos)) {
+ return 0;
+ }
+
+ return (ipaddr_parse_ipv4_addr(MemRef_SubTo(str, slash_pos), &out->addr) &&
+ ipaddr_parse_ipv4_prefix(MemRef_SubFrom(str, slash_pos + 1), &out->prefix));
+}
+
+int ipaddr_ipv4_ifaddr_from_addr_mask (uint32_t addr, uint32_t mask, struct ipv4_ifaddr *out)
+{
+ int prefix;
+ if (!ipaddr_ipv4_prefix_from_mask(mask, &prefix)) {
+ return 0;
+ }
+
+ out->addr = addr;
+ out->prefix = prefix;
+ return 1;
+}
+
+uint32_t ipaddr_ipv4_mask_from_prefix (int prefix)
+{
+ ASSERT(prefix >= 0)
+ ASSERT(prefix <= 32)
+
+ uint32_t t = 0;
+ for (int i = 0; i < prefix; i++) {
+ t |= 1 << (32 - i - 1);
+ }
+
+ return hton32(t);
+}
+
+int ipaddr_ipv4_prefix_from_mask (uint32_t mask, int *out_prefix)
+{
+ uint32_t t = 0;
+ int i;
+ for (i = 0; i <= 32; i++) {
+ if (ntoh32(mask) == t) {
+ break;
+ }
+ if (i < 32) {
+ t |= (1 << (32 - i - 1));
+ }
+ }
+ if (!(i <= 32)) {
+ return 0;
+ }
+
+ *out_prefix = i;
+ return 1;
+}
+
+int ipaddr_ipv4_addrs_in_network (uint32_t addr1, uint32_t addr2, int netprefix)
+{
+ ASSERT(netprefix >= 0)
+ ASSERT(netprefix <= 32)
+
+ uint32_t mask = ipaddr_ipv4_mask_from_prefix(netprefix);
+
+ return !!((addr1 & mask) == (addr2 & mask));
+}
+
+void ipaddr_print_addr (uint32_t addr, char *out)
+{
+ ASSERT(out)
+
+ uint8_t *b = (uint8_t *)&addr;
+
+ sprintf(out, "%"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8,
+ b[0], b[1], b[2], b[3]);
+}
+
+void ipaddr_print_ifaddr (struct ipv4_ifaddr ifaddr, char *out)
+{
+ ASSERT(ifaddr.prefix >= 0)
+ ASSERT(ifaddr.prefix <= 32)
+ ASSERT(out)
+
+ uint8_t *b = (uint8_t *)&ifaddr.addr;
+
+ sprintf(out, "%"PRIu8".%"PRIu8".%"PRIu8".%"PRIu8"/%d",
+ b[0], b[1], b[2], b[3], ifaddr.prefix);
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/ipaddr6.h b/Shared/lwip/badvpn/misc/ipaddr6.h
new file mode 100644
index 0000000..2b25013
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/ipaddr6.h
@@ -0,0 +1,383 @@
+/**
+ * @file ipaddr6.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * IPv6 address parsing functions.
+ */
+
+#ifndef BADVPN_MISC_IPADDR6_H
+#define BADVPN_MISC_IPADDR6_H
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+struct ipv6_addr {
+ uint8_t bytes[16];
+};
+
+struct ipv6_ifaddr {
+ struct ipv6_addr addr;
+ int prefix;
+};
+
+static int ipaddr6_parse_ipv6_addr (MemRef name, struct ipv6_addr *out_addr);
+static int ipaddr6_parse_ipv6_prefix (MemRef str, int *out_num);
+static int ipaddr6_parse_ipv6_ifaddr (MemRef str, struct ipv6_ifaddr *out);
+static int ipaddr6_ipv6_ifaddr_from_addr_mask (struct ipv6_addr addr, struct ipv6_addr mask, struct ipv6_ifaddr *out);
+static void ipaddr6_ipv6_mask_from_prefix (int prefix, struct ipv6_addr *out_mask);
+static int ipaddr6_ipv6_prefix_from_mask (struct ipv6_addr mask, int *out_prefix);
+static int ipaddr6_ipv6_addrs_in_network (struct ipv6_addr addr1, struct ipv6_addr addr2, int netprefix);
+
+#define IPADDR6_PRINT_MAX 44
+
+static void ipaddr6_print_addr (struct ipv6_addr addr, char *out_buf);
+static void ipaddr6_print_ifaddr (struct ipv6_ifaddr addr, char *out_buf);
+
+int ipaddr6_parse_ipv6_addr (MemRef name, struct ipv6_addr *out_addr)
+{
+ int num_blocks = 0;
+ int compress_pos = -1;
+ uint16_t block = 0;
+ int empty = 1;
+
+ size_t i = 0;
+
+ while (i < name.len) {
+ if (name.ptr[i] == '.') {
+ goto ipv4_ending;
+ } else if (name.ptr[i] == ':') {
+ int is_double = (i + 1 < name.len && name.ptr[i + 1] == ':');
+
+ if (i > 0) {
+ if (empty || num_blocks == 7) {
+ return 0;
+ }
+ out_addr->bytes[2 * num_blocks + 0] = block >> 8;
+ out_addr->bytes[2 * num_blocks + 1] = block & 0xFF;
+ num_blocks++;
+ block = 0;
+ empty = 1;
+ }
+ else if (!is_double) {
+ return 0;
+ }
+
+ if (is_double) {
+ if (compress_pos != -1) {
+ return 0;
+ }
+ compress_pos = num_blocks;
+ }
+
+ i += 1 + is_double;
+ } else {
+ int digit = decode_hex_digit(name.ptr[i]);
+ if (digit < 0) {
+ return 0;
+ }
+ if (block > UINT16_MAX / 16) {
+ return 0;
+ }
+ block *= 16;
+ if (digit > UINT16_MAX - block) {
+ return 0;
+ }
+ block += digit;
+ empty = 0;
+ i += 1;
+ }
+ }
+
+ if (!empty) {
+ out_addr->bytes[2 * num_blocks + 0] = block >> 8;
+ out_addr->bytes[2 * num_blocks + 1] = block & 0xFF;
+ num_blocks++;
+ }
+ else if (num_blocks != compress_pos) {
+ return 0;
+ }
+
+ipv4_done:
+ if (compress_pos == -1) {
+ if (num_blocks != 8) {
+ return 0;
+ }
+ compress_pos = 0;
+ }
+
+ int num_rear = num_blocks - compress_pos;
+ memmove(out_addr->bytes + 2 * (8 - num_rear), out_addr->bytes + 2 * compress_pos, 2 * num_rear);
+ memset(out_addr->bytes + 2 * compress_pos, 0, 2 * (8 - num_rear - compress_pos));
+
+ return 1;
+
+ipv4_ending:
+ if (empty || (num_blocks == 0 && compress_pos == -1)) {
+ return 0;
+ }
+
+ while (name.ptr[i - 1] != ':') {
+ i--;
+ }
+
+ uint8_t bytes[4];
+ int cur_byte = 0;
+ uint8_t byte = 0;
+ empty = 1;
+
+ while (i < name.len) {
+ if (name.ptr[i] == '.') {
+ if (empty || cur_byte == 3) {
+ return 0;
+ }
+ bytes[cur_byte] = byte;
+ cur_byte++;
+ byte = 0;
+ empty = 1;
+ } else {
+ if (!empty && byte == 0) {
+ return 0;
+ }
+ int digit = decode_decimal_digit(name.ptr[i]);
+ if (digit < 0) {
+ return 0;
+ }
+ if (byte > UINT8_MAX / 10) {
+ return 0;
+ }
+ byte *= 10;
+ if (digit > UINT8_MAX - byte) {
+ return 0;
+ }
+ byte += digit;
+ empty = 0;
+ }
+ i++;
+ }
+
+ if (cur_byte != 3 || empty) {
+ return 0;
+ }
+ bytes[cur_byte] = byte;
+
+ if (8 - num_blocks < 2) {
+ return 0;
+ }
+ memcpy(out_addr->bytes + 2 * num_blocks, bytes, 4);
+ num_blocks += 2;
+
+ goto ipv4_done;
+}
+
+int ipaddr6_parse_ipv6_prefix (MemRef str, int *out_num)
+{
+ uintmax_t d;
+ if (!parse_unsigned_integer(str, &d)) {
+ return 0;
+ }
+ if (d > 128) {
+ return 0;
+ }
+
+ *out_num = d;
+ return 1;
+}
+
+int ipaddr6_parse_ipv6_ifaddr (MemRef str, struct ipv6_ifaddr *out)
+{
+ size_t slash_pos;
+ if (!MemRef_FindChar(str, '/', &slash_pos)) {
+ return 0;
+ }
+
+ return (ipaddr6_parse_ipv6_addr(MemRef_SubTo(str, slash_pos), &out->addr) &&
+ ipaddr6_parse_ipv6_prefix(MemRef_SubFrom(str, slash_pos + 1), &out->prefix));
+}
+
+int ipaddr6_ipv6_ifaddr_from_addr_mask (struct ipv6_addr addr, struct ipv6_addr mask, struct ipv6_ifaddr *out)
+{
+ int prefix;
+ if (!ipaddr6_ipv6_prefix_from_mask(mask, &prefix)) {
+ return 0;
+ }
+
+ out->addr = addr;
+ out->prefix = prefix;
+ return 1;
+}
+
+void ipaddr6_ipv6_mask_from_prefix (int prefix, struct ipv6_addr *out_mask)
+{
+ ASSERT(prefix >= 0)
+ ASSERT(prefix <= 128)
+
+ int quot = prefix / 8;
+ int rem = prefix % 8;
+
+ if (quot > 0) {
+ memset(out_mask->bytes, UINT8_MAX, quot);
+ }
+ if (16 - quot > 0) {
+ memset(out_mask->bytes + quot, 0, 16 - quot);
+ }
+
+ for (int i = 0; i < rem; i++) {
+ out_mask->bytes[quot] |= (uint8_t)1 << (8 - i - 1);
+ }
+}
+
+int ipaddr6_ipv6_prefix_from_mask (struct ipv6_addr mask, int *out_prefix)
+{
+ int prefix = 0;
+ int i = 0;
+
+ while (i < 16 && mask.bytes[i] == UINT8_MAX) {
+ prefix += 8;
+ i++;
+ }
+
+ if (i < 16) {
+ uint8_t t = 0;
+ int j;
+ for (j = 0; j <= 8; j++) {
+ if (mask.bytes[i] == t) {
+ break;
+ }
+ if (j < 8) {
+ t |= ((uint8_t)1 << (8 - j - 1));
+ }
+ }
+ if (!(j <= 8)) {
+ return 0;
+ }
+
+ prefix += j;
+ i++;
+
+ while (i < 16) {
+ if (mask.bytes[i] != 0) {
+ return 0;
+ }
+ i++;
+ }
+ }
+
+ *out_prefix = prefix;
+ return 1;
+}
+
+int ipaddr6_ipv6_addrs_in_network (struct ipv6_addr addr1, struct ipv6_addr addr2, int netprefix)
+{
+ ASSERT(netprefix >= 0)
+ ASSERT(netprefix <= 128)
+
+ int quot = netprefix / 8;
+ int rem = netprefix % 8;
+
+ if (memcmp(addr1.bytes, addr2.bytes, quot)) {
+ return 0;
+ }
+
+ if (rem == 0) {
+ return 1;
+ }
+
+ uint8_t t = 0;
+ for (int i = 0; i < rem; i++) {
+ t |= (uint8_t)1 << (8 - i - 1);
+ }
+
+ return ((addr1.bytes[quot] & t) == (addr2.bytes[quot] & t));
+}
+
+void ipaddr6_print_addr (struct ipv6_addr addr, char *out_buf)
+{
+ int largest_start = 0;
+ int largest_len = 0;
+ int current_start = 0;
+ int current_len = 0;
+
+ for (int i = 0; i < 8; i++) {
+ if (addr.bytes[2 * i] == 0 && addr.bytes[2 * i + 1] == 0) {
+ current_len++;
+ if (current_len > largest_len) {
+ largest_start = current_start;
+ largest_len = current_len;
+ }
+ } else {
+ current_start = i + 1;
+ current_len = 0;
+ }
+ }
+
+ if (largest_len > 1) {
+ for (int i = 0; i < largest_start; i++) {
+ uint16_t block = ((uint16_t)addr.bytes[2 * i] << 8) | addr.bytes[2 * i + 1];
+ out_buf += sprintf(out_buf, "%"PRIx16":", block);
+ }
+ if (largest_start == 0) {
+ out_buf += sprintf(out_buf, ":");
+ }
+
+ for (int i = largest_start + largest_len; i < 8; i++) {
+ uint16_t block = ((uint16_t)addr.bytes[2 * i] << 8) | addr.bytes[2 * i + 1];
+ out_buf += sprintf(out_buf, ":%"PRIx16, block);
+ }
+ if (largest_start + largest_len == 8) {
+ out_buf += sprintf(out_buf, ":");
+ }
+ } else {
+ const char *prefix = "";
+ for (int i = 0; i < 8; i++) {
+ uint16_t block = ((uint16_t)addr.bytes[2 * i] << 8) | addr.bytes[2 * i + 1];
+ out_buf += sprintf(out_buf, "%s%"PRIx16, prefix, block);
+ prefix = ":";
+ }
+ }
+}
+
+void ipaddr6_print_ifaddr (struct ipv6_ifaddr addr, char *out_buf)
+{
+ ASSERT(addr.prefix >= 0)
+ ASSERT(addr.prefix <= 128)
+
+ ipaddr6_print_addr(addr.addr, out_buf);
+ sprintf(out_buf + strlen(out_buf), "/%d", addr.prefix);
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/ipv4_proto.h b/Shared/lwip/badvpn/misc/ipv4_proto.h
new file mode 100644
index 0000000..fea7260
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/ipv4_proto.h
@@ -0,0 +1,145 @@
+/**
+ * @file ipv4_proto.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Definitions for the IPv4 protocol.
+ */
+
+#ifndef BADVPN_MISC_IPV4_PROTO_H
+#define BADVPN_MISC_IPV4_PROTO_H
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#define IPV4_PROTOCOL_IGMP 2
+#define IPV4_PROTOCOL_UDP 17
+
+B_START_PACKED
+struct ipv4_header {
+ uint8_t version4_ihl4;
+ uint8_t ds;
+ uint16_t total_length;
+ //
+ uint16_t identification;
+ uint16_t flags3_fragmentoffset13;
+ //
+ uint8_t ttl;
+ uint8_t protocol;
+ uint16_t checksum;
+ //
+ uint32_t source_address;
+ //
+ uint32_t destination_address;
+} B_PACKED;
+B_END_PACKED
+
+#define IPV4_GET_VERSION(_header) (((_header).version4_ihl4&0xF0)>>4)
+#define IPV4_GET_IHL(_header) (((_header).version4_ihl4&0x0F)>>0)
+
+#define IPV4_MAKE_VERSION_IHL(size) (((size)/4) + (4 << 4))
+
+static uint16_t ipv4_checksum (const struct ipv4_header *header, const char *extra, uint16_t extra_len)
+{
+ ASSERT(extra_len % 2 == 0)
+ ASSERT(extra_len == 0 || extra)
+
+ uint32_t t = 0;
+
+ for (uint16_t i = 0; i < sizeof(*header) / 2; i++) {
+ t += badvpn_read_be16((const char *)header + 2 * i);
+ }
+
+ for (uint16_t i = 0; i < extra_len / 2; i++) {
+ t += badvpn_read_be16((const char *)extra + 2 * i);
+ }
+
+ while (t >> 16) {
+ t = (t & 0xFFFF) + (t >> 16);
+ }
+
+ return hton16(~t);
+}
+
+static int ipv4_check (uint8_t *data, int data_len, struct ipv4_header *out_header, uint8_t **out_payload, int *out_payload_len)
+{
+ ASSERT(data_len >= 0)
+ ASSERT(out_header)
+ ASSERT(out_payload)
+ ASSERT(out_payload_len)
+
+ // check base header
+ if (data_len < sizeof(struct ipv4_header)) {
+ return 0;
+ }
+ memcpy(out_header, data, sizeof(*out_header));
+
+ // check version
+ if (IPV4_GET_VERSION(*out_header) != 4) {
+ return 0;
+ }
+
+ // check options
+ uint16_t header_len = IPV4_GET_IHL(*out_header) * 4;
+ if (header_len < sizeof(struct ipv4_header)) {
+ return 0;
+ }
+ if (header_len > data_len) {
+ return 0;
+ }
+
+ // check total length
+ uint16_t total_length = ntoh16(out_header->total_length);
+ if (total_length < header_len) {
+ return 0;
+ }
+ if (total_length > data_len) {
+ return 0;
+ }
+
+ // check checksum
+ uint16_t checksum_in_packet = out_header->checksum;
+ out_header->checksum = hton16(0);
+ uint16_t checksum_computed = ipv4_checksum(out_header, (char *)data + sizeof(*out_header), header_len - sizeof(*out_header));
+ out_header->checksum = checksum_in_packet;
+ if (checksum_in_packet != checksum_computed) {
+ return 0;
+ }
+
+ *out_payload = data + header_len;
+ *out_payload_len = total_length - header_len;
+
+ return 1;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/ipv6_proto.h b/Shared/lwip/badvpn/misc/ipv6_proto.h
new file mode 100644
index 0000000..b255541
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/ipv6_proto.h
@@ -0,0 +1,86 @@
+/**
+ * @file ipv6_proto.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BADVPN_IPV6_PROTO_H
+#define BADVPN_IPV6_PROTO_H
+
+#include
+#include
+
+#include
+#include
+#include
+
+#define IPV6_NEXT_IGMP 2
+#define IPV6_NEXT_UDP 17
+
+B_START_PACKED
+struct ipv6_header {
+ uint8_t version4_tc4;
+ uint8_t tc4_fl4;
+ uint16_t fl;
+ uint16_t payload_length;
+ uint8_t next_header;
+ uint8_t hop_limit;
+ uint8_t source_address[16];
+ uint8_t destination_address[16];
+} B_PACKED;
+B_END_PACKED
+
+static int ipv6_check (uint8_t *data, int data_len, struct ipv6_header *out_header, uint8_t **out_payload, int *out_payload_len)
+{
+ ASSERT(data_len >= 0)
+ ASSERT(out_header)
+ ASSERT(out_payload)
+ ASSERT(out_payload_len)
+
+ // check base header
+ if (data_len < sizeof(struct ipv6_header)) {
+ return 0;
+ }
+ memcpy(out_header, data, sizeof(*out_header));
+
+ // check version
+ if ((ntoh8(out_header->version4_tc4) >> 4) != 6) {
+ return 0;
+ }
+
+ // check payload length
+ uint16_t payload_length = ntoh16(out_header->payload_length);
+ if (payload_length > data_len - sizeof(struct ipv6_header)) {
+ return 0;
+ }
+
+ *out_payload = data + sizeof(struct ipv6_header);
+ *out_payload_len = payload_length;
+
+ return 1;
+}
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/loggers_string.h b/Shared/lwip/badvpn/misc/loggers_string.h
new file mode 100644
index 0000000..66986b8
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/loggers_string.h
@@ -0,0 +1,43 @@
+/**
+ * @file loggers_string.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * List of available loggers.
+ */
+
+#ifndef BADVPN_MISC_LOGGERSSTRING_H
+#define BADVPN_MISC_LOGGERSSTRING_H
+
+#ifdef BADVPN_USE_WINAPI
+#define LOGGERS_STRING "stdout"
+#else
+#define LOGGERS_STRING "stdout/syslog"
+#endif
+
+#endif
diff --git a/Shared/lwip/badvpn/misc/loglevel.h b/Shared/lwip/badvpn/misc/loglevel.h
new file mode 100644
index 0000000..6e9f911
--- /dev/null
+++ b/Shared/lwip/badvpn/misc/loglevel.h
@@ -0,0 +1,80 @@
+/**
+ * @file loglevel.h
+ * @author Ambroz Bizjak
+ *
+ * @section LICENSE
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @section DESCRIPTION
+ *
+ * Log level specification parsing function.
+ */
+
+#ifndef BADVPN_MISC_LOGLEVEL_H
+#define BADVPN_MISC_LOGLEVEL_H
+
+#include
+
+#include