summaryrefslogtreecommitdiff
path: root/listeners.go
AgeCommit message (Collapse)Author
2023-08-14ci: use gci linter (#5708)Jacob Gadikian
* use gofmput to format code * use gci to format imports * reconfigure gci * linter autofixes * rearrange imports a little * export GOOS=windows golangci-lint run ./... --fix
2023-08-07ci: Use gofumpt to format code (#5707)Jacob Gadikian
2023-08-06cmd: Split unix sockets for admin endpoint addresses (#5696)Emily
* cmd: fix cli when admin endpoint uses new unix socket permission format Fixes a bug where the following Caddyfile ```Caddyfile { admin unix/admin.sock|0660 } ``` and `caddy reload --config Caddyfile` would throw the following error instead of reloading it: ``` INFO using provided configuration {"config_file": "Caddyfile", "config_adapter": ""} Error: sending configuration to instance: performing request: Post "http://127.0.0.1/load": dial unix admin.sock|0660: connect: no such file or directory [ERROR] exit status 1 ``` --- This bug also affected `caddy start` and `caddy stop`. * Move splitter function to internal --------- Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
2023-06-30core: Embed net.UDPConn to gain optimizations (#5606)WeidiDeng
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
2023-06-24core: Skip `chmod` for abstract unix sockets (#5596)Emily
because those aren't real paths on the filesystem and thus can't be `chmod`ed
2023-06-23core: Add optional unix socket file permissions (#4741)Emily
* core: Add optional unix socket file permissions This commit also changes the default unix socket file permissions to `u=w,g=,o=` (octal: `0200`). It used to default to the shell's umask (usually `u=rwx,g=rx,o=rx`, octal: `0755`). `/run/caddy.sock` -> `/run/caddy.sock` with `0200` default perms `/run/caddy.sock|0222` -> `/run/caddy.sock` with `0222` perms `|` instead of `:` is used as a separator, to account for the `:` in Windows drive letters (e.g. `C:\absolute\path.sock`) Fun fact: The old unix(7) man page (pre Jun 2016) stated a socket needs both read and write perms. Turns out, only write perms are needed. Corrected in https://github.com/mkerrisk/man-pages/commit/7578ea2f85b272363d22680d69e7d32f0b59c83b Despite this, most implementations still default to read+write to this date. * Add cases with Windows paths to test * Require write perms for the owning user
2023-06-21Appease linterMatthew Holt
2023-06-21Fix compile on Windows, hopefullyMatthew Holt
2023-06-21core: Properly preserve unix sockets (fix #5568)Matthew Holt
2023-05-30update quic-go to v0.35.0 (#5560)Marten Seemann
2023-05-10caddyhttp: Update quic's TLS configs after reload (#5517) (fix #4849)WeidiDeng
* fix http3 outdated certificates after config reload * delegate quic tls GetConfigForClient to another struct. * change type and method names fix lint --------- Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
2023-05-03acmeserver: Configurable `resolvers`, fix smallstep deprecations (#5500)Francis Lavoie
* acmeserver: Configurable `resolvers`, fix smallstep deprecations * Improve default net/port * Update proxy resolvers parsing to use the new function * Update listeners.go Co-authored-by: itsxaos <33079230+itsxaos@users.noreply.github.com> --------- Co-authored-by: itsxaos <33079230+itsxaos@users.noreply.github.com>
2023-03-09caddyhttp: Enable 0-RTT QUIC (#5425)Marten Seemann
2023-02-08core: Support Windows absolute paths for UDS proxy upstreams (#5114)Steffen Brüheim
* added some tests for parseUpstreamDialAddress Test 4 fails because it produces "[[::1]]:80" instead of "[::1]:80" * support absolute windows path in unix reverse proxy address * make IsUnixNetwork public, support +h2c and reuse it * add new tests
2023-02-06chore: Build with Go 1.20, keep minimum at 1.18 for now (#5353)Francis Lavoie
2022-09-29core: Fix ListenQUIC listener key conflictMatthew Holt
Reported on commit e3e8aabbcf65d37516bb97f9dc0f77df52f8cf55 Abused this change in some bash for loops to rapidly reload config while making requests and didn't observe any memory or resource leaks.
2022-09-28core: Refactor and improve listener logic (#5089)Matt Holt
* core: Refactor, improve listener logic Deprecate: - caddy.Listen - caddy.ListenTimeout - caddy.ListenPacket Prefer caddy.NetworkAddress.Listen() instead. Change: - caddy.ListenQUIC (hopefully to remove later) - caddy.ListenerFunc signature (add context and ListenConfig) - Don't emit Alt-Svc header advertising h3 over HTTP/3 - Use quic.ListenEarly instead of quic.ListenEarlyAddr; this gives us more flexibility (e.g. possibility of HTTP/3 over UDS) but also introduces a new issue: https://github.com/lucas-clemente/quic-go/issues/3560#issuecomment-1258959608 - Unlink unix socket before and after use * Appease the linter * Keep ListenAll
2022-09-08Very minor tweaksMatthew Holt
2022-09-08core: Check error on ListenQUICMatthew Holt
2022-09-02core: Refactor listeners; use SO_REUSEPORT on Unix (#4705)Matt Holt
* core: Refactor listeners; use SO_REUSEPORT on Unix Just an experiment for now * Fix lint by logging error * TCP Keepalive configuration (#4865) * initial attempt at TCP Keepalive configuration * core: implement tcp-keepalive for linux * move canSetKeepAlive interface * Godoc for keepalive server parameter * handle return values * log keepalive errors * Clean up after bad merge * Merge in pluggable network types From 1edc1a45e3aee1f7d86b68c3ddaf2fd16ba8ab73 * Slight refactor, fix from recent merge conflict Co-authored-by: Karmanyaah Malhotra <karmanyaah.gh@malhotra.cc>
2022-09-01core: Plugins can register listener networks (#5002)Matt Holt
* core: Plugins can register listener networks This can be useful for custom listeners. This feature/API is experimental and may change! * caddyhttp: Expose server listeners
2022-08-17core: Change net.IP to netip.Addr; use netip.Prefix (#4966)WilczyńskiT
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
2022-08-15caddyhttp: Enable HTTP/3 by default (#4707)Matt Holt
2022-08-04Replace strings.Index usages with strings.Cut (#4930)WilczyńskiT
2022-08-03httpserver: Configurable shutdown delay (#4906)Matt Holt
2022-07-25httpcaddyfile: Detect ambiguous site definitions (fix #4635)Matthew Holt
Previously, our "duplicate key in server block" logic was flawed because it did not account for the site's bind address. We defer this check to when the listener addresses have been assigned, but before we commit a server block to its listener. Also refined how network address parsing and joining works, which was necessary for a less convoluted fix.
2022-05-12chore: Bump quic-go to v0.27.0 (#4782)世界
2022-03-22Fix http3 servers dying after reload (#4654)Artem Mikheev
2022-01-19More explanatory error message from Listen (#4534)Forest Johnson
* explain cryptic unix socket listener error related to process kill https://github.com/caddyserver/caddy/pull/4533 * less ambiguous wording: clean up -> delete * shorten error message explanation * link back to pull request in comment for later archeaology
2022-01-10Fix lint warningsMatthew Holt
2022-01-10core: Simplify shared listeners, fix deadline bugMatthew Holt
When this listener code was first written, UsagePool didn't exist. We can simplify much of the wrapped listener logic by utilizing UsagePool. This also fixes a bug where new servers were able to clear deadlines set by old servers, even if the old server didn't get booted out of its Accept() call yet. And with the deadline cleared, they never would. (Sometimes. Based on reports and difficulty of reproducing the bug, this behavior was extremely rare.) I don't know why that happened exactly, maybe some polling mechanism in the kernel and if the timings worked out just wrong it would expose the bug. Anyway, now we ensure that only the closer that set the deadline is the same one that clears it, ensuring that old servers always return out of Accept(), because the deadline doesn't get cleared until they do. Of course, all this hinges on the hope that my suspicions in the middle of the night are correct and that kernels work the way I think they do in my head. Also minor enhancement to UsagePool where if a value errors upon construction (a very real possibility with listeners), it is removed from the pool. Not 100% sure the sync logic is correct there, or maybe we don't have to even put it in the pool until after construction, but it's subtle either way and I think this is safe... right?
2021-02-16caddy: Support SetReadBuffer and SyscallConn for QUIC (fix #3998)Matthew Holt
Supersedes #3999
2020-11-22ci: Use golangci's github action for linting (#3794)Dave Henderson
* ci: Use golangci's github action for linting Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix most of the staticcheck lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the prealloc lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the misspell lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the varcheck lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the errcheck lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the bodyclose lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the deadcode lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the unused lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the gosec lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the gosimple lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the ineffassign lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Fix the staticcheck lint errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Revert the misspell change, use a neutral English Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Remove broken golangci-lint CI job Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Re-add errantly-removed weakrand initialization Signed-off-by: Dave Henderson <dhenderson@gmail.com> * don't break the loop and return * Removing extra handling for null rootKey * unignore RegisterModule/RegisterAdapter Co-authored-by: Mohammed Al Sahaf <msaa1990@gmail.com> * single-line log message Co-authored-by: Matt Holt <mholt@users.noreply.github.com> * Fix lint after a1808b0dbf209c615e438a496d257ce5e3acdce2 was merged Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Revert ticker change, ignore it instead Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Ignore some of the write errors Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Remove blank line Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Use lifetime Signed-off-by: Dave Henderson <dhenderson@gmail.com> * close immediately Co-authored-by: Matt Holt <mholt@users.noreply.github.com> * Preallocate configVals Signed-off-by: Dave Henderson <dhenderson@gmail.com> * Update modules/caddytls/distributedstek/distributedstek.go Co-authored-by: Mohammed Al Sahaf <msaa1990@gmail.com> Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
2020-04-16admin: Disable host checking if wildcard interface is specifiedMatthew Holt
To clarify, listening on wildcard interfaces is NOT the default and should only be done under certain circumstances and when you know what you're doing. Emits a warning in the log. Fixes https://github.com/caddyserver/caddy-docker/issues/71
2020-04-10admin: Always enforce Host header checksMatthew Holt
With a simple heuristic for loopback addresses, we can enable this by default without adding unnecessary inconvenience.
2020-04-07core: Rename ParsedAddress -> NetworkAddressMatthew Holt
2020-03-15caddyhttp: Add support for listener wrapper modulesMatthew Holt
Wrapping listeners is useful for composing custom behavior related to accepting, closing, reading/writing connections (etc) below the application layer; for example, the PROXY protocol.
2020-01-03v2: housekeeping: address minor lint complaints (#2957)Mohammed Al Sahaf
* v2: housekeeping: update tools * v2: housekeeping: adhere to US locale in spelling * v2: housekeeping: simplify code
2019-12-06Use "IsUnixNetwork" function instead of repeating the logicMatthew Holt
2019-12-06Don't append port to unix socketsMatthew Holt
See https://caddy.community/t/caddy-v2-php-fpm-502-error/6571?u=matt
2019-11-15Minor cleanupsMatthew Holt
2019-11-11core: Use port ranges to avoid OOM with bad inputs (#2859)Mohammed Al Sahaf
* fix OOM issue caught by fuzzing * use ParsedAddress as the struct name for the result of ParseNetworkAddress * simplify code using the ParsedAddress type * minor cleanups
2019-11-04core: Synchronize calls to SetDeadline within fakeCloseListenerMatthew Holt
First evidenced in #2658, listener deadlines would sometimes be set after clearing them, resulting in endless i/o timeout errors, which leave all requests hanging. This bug is fixed by synchronizing the calls to SetDeadline: when Close() is called, the deadline is first set to a time in the past, and the lock is released only after the deadline is set, so when the other servers break out of their Accept() calls, they will clear the deadline *after* it was set. Before, the clearing could sometimes come before the set, which meant that it was left in a timeout state indefinitely. This may not yet be a perfect solution -- ideally, the setting and clearing of the deadline would happen exactly once per underlying listener, not once per fakeCloseListener, but in rigorous testing with these changes (comprising tens of thousands of config reloads), I was able to verify that no race condition is manifest.
2019-10-11reverse_proxy: Allow dynamic backends (closes #990 and #1539)Matthew Holt
This PR enables the use of placeholders in an upstream's Dial address. A Dial address must represent precisely one socket after replacements. See also #998 and #1639.
2019-09-10Experimental IETF-standard HTTP/3 support (known issue exists) (#2727)Matt Holt
* Begin WIP integration of HTTP/3 support * http3: Set actual Handler, make fakeClosePacketConn type for UDP sockets Also use latest quic-go for ALPN fix * Manually keep track of and close HTTP/3 listeners * Update quic-go after working through some http3 bugs * Fix go mod * Make http3 optional for now
2019-09-05Reconcile upstream dial addresses and request host/URL informationMatthew Holt
My goodness that was complicated Blessed be request.Context Sort of
2019-09-02reverse_proxy: WIP refactor and support for FastCGIMatthew Holt
2019-07-08Move listen address functions into caddy package; fix unix bugMatthew Holt
2019-06-30Add licenseMatthew Holt
2019-06-14Rename caddy2 -> caddyMatthew Holt
Removes the version from the package name