direct_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package main
  2. import (
  3. "net/netip"
  4. "testing"
  5. C "github.com/sagernet/sing-box/constant"
  6. "github.com/sagernet/sing-box/option"
  7. "github.com/sagernet/sing/common"
  8. "github.com/sagernet/sing/common/json/badoption"
  9. )
  10. // Since this is a feature one-off added by outsiders, I won't address these anymore.
  11. func _TestProxyProtocol(t *testing.T) {
  12. startInstance(t, option.Options{
  13. Inbounds: []option.Inbound{
  14. {
  15. Type: C.TypeMixed,
  16. Tag: "mixed-in",
  17. Options: &option.HTTPMixedInboundOptions{
  18. ListenOptions: option.ListenOptions{
  19. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  20. ListenPort: clientPort,
  21. },
  22. },
  23. },
  24. {
  25. Type: C.TypeDirect,
  26. Options: &option.DirectInboundOptions{
  27. ListenOptions: option.ListenOptions{
  28. Listen: common.Ptr(badoption.Addr(netip.IPv4Unspecified())),
  29. ListenPort: serverPort,
  30. ProxyProtocol: true,
  31. },
  32. },
  33. },
  34. },
  35. Outbounds: []option.Outbound{
  36. {
  37. Type: C.TypeDirect,
  38. },
  39. {
  40. Type: C.TypeDirect,
  41. Tag: "proxy-out",
  42. Options: &option.DirectOutboundOptions{
  43. OverrideAddress: "127.0.0.1",
  44. OverridePort: serverPort,
  45. ProxyProtocol: 2,
  46. },
  47. },
  48. },
  49. Route: &option.RouteOptions{
  50. Rules: []option.Rule{
  51. {
  52. Type: C.RuleTypeDefault,
  53. DefaultOptions: option.DefaultRule{
  54. RawDefaultRule: option.RawDefaultRule{
  55. Inbound: []string{"mixed-in"},
  56. },
  57. RuleAction: option.RuleAction{
  58. Action: C.RuleActionTypeRoute,
  59. RouteOptions: option.RouteActionOptions{
  60. Outbound: "proxy-out",
  61. },
  62. },
  63. },
  64. },
  65. },
  66. },
  67. })
  68. testSuit(t, clientPort, testPort)
  69. }