caddy-l4 icon indicating copy to clipboard operation
caddy-l4 copied to clipboard

how to proxy quic

Open New2Niu opened this issue 2 years ago • 2 comments
trafficstars

tcp proxy

{
   "apps": {
      "layer4": {
         "servers": {
            "srv0": {
               "listen": [":443"],
               "routes": [{
                  "match": [{
                     "tls": {
                     }
                  }],
                  "handle": [{
                     "handler": "proxy",
                     "upstreams": [{
                        "dial": ["{l4.tls.server_name}:443"]
                     }]
                  }]
               }]
            },
            "srv1": {
               "listen": [":80"],
               "routes": [{
                  "match": [{
                     "http": []
                  }],
                  "handle": [{
                     "handler": "proxy",
                     "upstreams": [{
                        "dial": ["{l4.http.host}:80"]
                     }]
                  }]
               }]
            }
         }
      }
   },
   "logging": {
      "logs": {
         "default": {
            "encoder": {
               "format": "json",
               "time_format": "wall",
               "time_local": true
            },
            "exclude": [],
            "writer": {
               "filename": "proxy.event.log",
               "output": "file",
               "roll": false
            }
         }
      }
   }
}

How to proxy quic by sni? udp proxy not work:

 "srv11": {
     "listen": ["udp/:443"],
     "routes": [{
        "match": [{
           "tls": {
           }
        }],
        "handle": [{
           "handler": "proxy",
           "upstreams": [{
              "dial": ["{l4.tls.server_name}:443"]
           }]
        }]
     }]
  },

New2Niu avatar Sep 14 '23 08:09 New2Niu

It does not seem doable right now. However, that might be quite "easily" achievable using quic-go's EarlyListener mechanism: we could setup an EarlyListener and feed it UDP packets. When it accepts a new conn, we could extract the SNI from its TLS context (simply access the ConnetionState's TLS context that contains the SNI, everything seems correctly exposed by quic-go. It feels a bit hackish though.

Any thoughts on that ?

francoismichel avatar Jan 19 '24 11:01 francoismichel

I don't know enough about the details of the QUIC protocol, but it sounds plausible -- I'd be open to an experiment/PR!

mholt avatar Jan 19 '24 17:01 mholt

How to proxy quic by sni? udp proxy not work:

 "srv11": {
     "listen": ["udp/:443"],
     "routes": [{
        "match": [{
           "tls": {
           }
        }],
        "handle": [{
           "handler": "proxy",
           "upstreams": [{
              "dial": ["{l4.tls.server_name}:443"]
           }]
        }]
     }]
  },

This PR can achieve your needs, but it is not merged.

lxhao61 avatar May 26 '24 14:05 lxhao61

The linked PR has been merged. Please try it out! (It may not have been 100% complete but should work.)

mholt avatar May 29 '24 17:05 mholt