Caddyfile + L4 plugin

Can the layer4 plug-in be paired with the Caddyfile with an import block?

The Caddyfile would be the main config, and the import directive would import the layer 4 json file.

1 Like

Howdy @victor!

The caddy-l4 module doesn’t support the Caddyfile, which is a bit of a bummer.

There is another extension that allows limited configuration of caddy-l4 via Caddyfile global options: caddy-ext/layer4 at master · RussellLuo/caddy-ext · GitHub

Beyond that, a large amount of special handling in the core Caddyfile adapter makes including Layer 4 support prohibitively difficult. If an effort could be made to port caddy-l4 into the official repository, this would be simpler, but that is an undertaking that requires skilled Caddy developers and contributors with the time and ability to prioritise that over other work, and I don’t believe there are any concrete plans for it in the works right now.

Your best bet, currently, is to write your Caddyfile as normal and then caddy adapt it to JSON to merge with your caddy-l4 configuration before deploying it.

1 Like

Thanks. I’ll give this a try. I’m basically looking to proxy UDP traffic to a webrtc server.

This works beautifully!

But I notice that caddy is only listening on TCP. Does it auto listen on UDP or what?

I opted for the plugin. Works excellent as of right now. My webrtc stream is working fine with SSL and everything.

1 Like

Still wondering about this…

Without extra plugins, Caddy serves HTTP, and HTTP is over TCP, except HTTP/3 which is over UDP (but uses TCP to inform clients that UDP is available).

If you’re using the L4 plugin then you need to specify whether you want to listen on TCP or UDP since it operates at a lower layer.

Understood.

I tried both TCP (default it seems) and UDP. For some reason the UDP listener closes within a few seconds. TCP works great.

Not finding anything in the logs either.

As soon as a connection is make via UDP, it stops listening.

The UDP proxy is currently a bit broken. I wonder if this patch fixes it for you!

Does the plug-in mentioned above build with this patch?

Oh, I’m not sure about that. Probably though? No external config changes AFAIK.

Ok so it does automatically build with the l4-plugin, but how would I specify to include that pull request.

Build with --with github.com/mholt/caddy-l4=github.com/jtackaberry/caddy-l4@udp-server-overhaul

Basically = replaces the package with the fork, and @ specifies which branch to use on the fork.

Built successfully. UDP listener now stays on, but something must still be amiss because it’s not proxying the traffic. When I port forward directly to the server that is serving the UDP traffic, it works. But once I go through caddy-l4, it doesn’t.