Last 12 weeks · 17 commits
2 of 6 standards met
This adds a matcher that matches connections by the peer host name, resolved from the remote IP with a reverse DNS (PTR) lookup. It follows the request in #278. Names can be given verbatim or as a wildcard, and matching is case insensitive. A lookup runs for every connection the matcher inspects, so it is not free, which I called out in the godoc and the matcher doc so people keep it behind a cheaper matcher when it sits in a hot path. Caddyfile example: The tests stub the resolver the same way l4proxy already does, so they do not touch real DNS. The matcher table and a new doc page are updated too.
This fixes an issue where configuring changed the peer's stored address. After a health check, normal proxy connections could be sent to the health-check port instead of the configured upstream port. The health check now applies the alternate port to a local copy of the address. The regression test verifies that the probe uses while proxy traffic keeps using the original port. Related: #423 also changes . Testing
Summary add a per-upstream option that binds outbound TCP/UDP connections to the effective downstream client IP configure Linux sockets with / , while rejecting unsupported platforms and conflicting source-address settings add Caddyfile adaptation, configuration, address-family, and Linux socket-option regression coverage document the required upstream route, socket-match diversion, policy routing, capabilities, firewall considerations, and IPv6 equivalent update the aligned module set required by , which fixes the newly reported failure Closes #399. Use case This is for upstream services that make authorization, rate-limit, audit, or response decisions from the transport peer address but cannot be changed to parse a PROXY protocol header. Examples include legacy or third-party TCP services with source-IP ACLs and UDP services whose behavior depends on the requester's address. Caddy's matcher can enforce policy at Caddy, but it cannot make the upstream's own logs or source-IP controls observe the client address. PROXY protocol remains preferable whenever the upstream supports it. Validation Linux-built transparent tests executed in a Linux container AI assistance AI-assisted coding tools were used to help draft and review parts of the implementation, tests, and documentation. I reviewed the resulting behavior against Go's socket setup and the Linux transparent-proxy documentation, revised the implementation and deployment guidance, and ran the validation above.
Summary I have an forgejo service running on my homelab behind caddy reversed proxy along with an mcp server in subpath , I want to configure SSH-over-TLS, while keeping subpath reverse proxy and port settings, I've modified Caddyfile according to documents, but all i got is error, Is there any flaws in my configuration or am I missing something? Step to reproduce 1. Build caddy with caddy-l4 module using xcaddy. 2. Run caddy server using the following Caddyfile: 3. Use following command to connect to ssh server over https port: Expected Behavior SSH client should connect to server and start asking whether or not to remember fingerprint Actual Behavior SSH client returns error, while https service is still accessible
This PR supersedes #420 and closes #439. The original PR didn't let any changes to be made by the maintainers, and the author didn't respond to pings. So I copied the original commit submitted by @carterbryden co-authored by an LLM (presumably, Copilot) and applied the Copilot's suggestions after it had reviewed the original PR submitted by @apxcarter, then merged into the current branch.
I'm trying to use to route the Syncthing Relay Protocol, which is actually _two_ protocols multiplexed on a single port: "Protocol mode" for control messages: TLS with ALPN . I confirmed this can be handled with a matcher. "Session mode" for relay sessions: a header starting with magic bytes , followed by an arbitrary sequence of bytes. According to the docs, I _should_ be able to match the "session mode" initiation packet with , but that doesn't work. I factored out a minimal (ignoring the TLS "protocol mode", because that works fine): Test it as follows: The matcher succeeds, routing to the handler as expected. However, the matcher never matches, so the connection gets routed to the catchall handler instead. I think the issue is that Go's package assumes bytes to check for a match are valid UTF-8, which means it can't properly match against non-UTF-8 sequences (which are common in application protocol headers). A quick scan of the source code seems to confirm this. I can see a couple paths forward here: 1. Find an alternate regular expressions package that properly supports "binary regex". However, I am not familiar with Go and am not sure if a good candidate exists, especially given that matching is performance sensitive. 2. Write a simpler matcher that only looks for binary substrings in a specific position of the initial packet sent by the client. I envision syntax like , so for my use case, just . It'd be a shame to lose the flexibility of regex, but I suspect many protocols don't actually need it. (It might also be slightly more efficient, though I don't know if that matters in practice.) Personally, (2) seems like the simplest option to resolve the issue I'm facing; however, it doesn't help someone who needs _both_ the flexibility of regex _and_ real byte string matching. (The fact nobody seems to have reported this previously in the couple years the matcher has existed suggests to me that needing both those things at once is uncommon, though. I wouldn't be surprised if binary protocols tend to have a simple, strict magic number like the Syncthing protocol does....)
Repository: mholt/caddy-l4. Description: Layer 4 (TCP/UDP) app for Caddy Stars: 1753, Forks: 120. Primary language: Go. Languages: Go (100%). License: Apache-2.0. Latest release: v0.1.2 (1mo ago). Open PRs: 18, open issues: 19. Last activity: 3w ago. Community health: 42%. Top contributors: vnxme, dependabot[bot], mholt, WeidiDeng, ydylla, IceCodeNew, tannevaled, mohammed90, RussellLuo, kkroo and others.