Commit Graph

2192 Commits

Author SHA1 Message Date
Egon Elbre
bae01a7353 trace: add missing td tag
Change-Id: I4f99953e028a6e397c62605f39b73872abf960bd
Reviewed-on: https://go-review.googlesource.com/c/net/+/670995
Reviewed-by: Sean Liao <sean@liao.dev>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-12 10:10:08 -07:00
Gopher Robot
7d6e62ace5 go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: Id9bf9fda6785763f418cbe165472193bb23c7401
Reviewed-on: https://go-review.googlesource.com/c/net/+/670096
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
v0.40.0
2025-05-05 12:52:54 -07:00
cuishuang
ea0c1d94f5 internal/timeseries: use built-in max/min to simplify the code
Change-Id: I3d408025af072559cac1f2b403a90518995d0a5a
Reviewed-on: https://go-review.googlesource.com/c/net/+/664855
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-04-15 18:01:41 -07:00
Damien Neil
3e7a445bf4 quic: skip packet numbers for optimistic ack defense
An "optimistic ACK attack" involves an attacker sending ACKs
for packets it hasn't received, causing the victim's
congestion controller to improperly send at a higher rate.

The standard defense against this attack is to skip the occasional
packet number, and to close the connection with an error if the
peer ACKs an unsent packet.

Implement this defense, increasing the gap between skipped
packet numbers as a connection's lifetime grows and correspondingly
the amount of work required on the part of the attacker.

Change-Id: I01f44f13367821b86af6535ffb69d380e2b4d7b7
Reviewed-on: https://go-review.googlesource.com/c/net/+/664298
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-04-10 11:38:36 -07:00
Damien Neil
3f563d3b0d quic: use an enum for sentPacket state
The sentPacket type tracks the state of a packet sent to the peer.
Packets can be in progress, acknowledged, or lost.
Track this state with an enum rather than a set of bools,
to avoid the possibility of nonsensical states such as a packet
being both acknowledged and lost.

This also simplifies a following change to add an "unsent" state
for intentionally skipped packet numbers.

Change-Id: I87c8fc399c72337c033ab7ec5ec8db2c56c732f9
Reviewed-on: https://go-review.googlesource.com/c/net/+/664297
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-04-09 16:02:25 -07:00
Damien Neil
a3b6e772dc quic: don't re-lose packets when discarding keys
When discarding keys for a packet number space, we remove any
in-flight packets in that space from our count of bytes in flight.
Skip any packets in the space that were already acked or declared lost.

Also skip over acked/lost packets when discarding state in response
to a Reset message. This change shouldn't have any effect, since we
never declare packets acked/lost until we receive an ACK, and we
never handle a Reset after receiving an ACK.

Change-Id: I8842f03aa06e57a834a211f1284a48fe5d469db3
Reviewed-on: https://go-review.googlesource.com/c/net/+/664335
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-04-09 16:02:13 -07:00
Damien Neil
22500a668c quic: decode packet numbers >255 in tests
Decoding QUIC packet numbers requires keeping track of the largest
packet number received so far from the peer. Our tests haven't
bothered doing that so far, so tests can't work with packet
numbers past 255.

Fix that so we can write tests that use more packets.

Change-Id: Icb795e5cf69794381c12a3a03b0da6bcf47a69c0
Reviewed-on: https://go-review.googlesource.com/c/net/+/664296
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-04-09 15:11:48 -07:00
Damien Neil
dd0b200aed quic: remove go1.21 build constraint
The x/net go.mod now depends on go1.23.

Change-Id: I24960949d84753f84f75fbdc97b7dfb92191a4d2
Reviewed-on: https://go-review.googlesource.com/c/net/+/664295
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-04-09 15:11:44 -07:00
Gopher Robot
b8d88774da go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: I9999157ec9379b23f07925ac574003001fdd773c
Reviewed-on: https://go-review.googlesource.com/c/net/+/662836
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
v0.39.0
2025-04-07 13:59:56 -07:00
Roland Shoemaker
e1fcd82abb html: properly handle trailing solidus in unquoted attribute value in foreign content
The parser properly treats tags like <p a=/> as <p a="/">, but the
tokenizer emits the SelfClosingTagToken token incorrectly. When the
parser is used to parse foreign content, this results in an incorrect
DOM.

Thanks to Sean Ng (https://ensy.zip) for reporting this issue.

Fixes golang/go#73070
Fixes CVE-2025-22872

Change-Id: I65c18df6d6244bf943b61e6c7a87895929e78f4f
Reviewed-on: https://go-review.googlesource.com/c/net/+/661256
Reviewed-by: Neal Patel <nealpatel@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
v0.38.0
2025-03-27 12:51:24 -07:00
Chressie Himpel
ebed060e8f internal/http3: fix build of tests with GOEXPERIMENT=nosynctest
The tests in qpack_decode_test.go require synctest helpers from
http3_test.go, but that file has a goexperiment.synctest build
constraint.

To make builds work when GOEXPERIMENT=nosynctest is specified the
synctest helpers are refactored into http3_synctest_test.go (with the
same build constraint) and the non-synctest related functionality is
kept in http3_test.go.

Change-Id: Iae339dc1895f27e7ac5ba985e204f4868c229a4d
Reviewed-on: https://go-review.googlesource.com/c/net/+/660535
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-03-25 08:01:24 -07:00
Sean Liao
1f1fa29e0a publicsuffix: regenerate table
Updated to revision 2c960dac3d39ba521eb5db9da192968f5be0aded
(2025-03-18T07:22:13Z).
Last updated on 2023-08

xn--czrw28b.tw / 商業.tw was removed in https://github.com/publicsuffix/list/pull/2289
blogspot ccTLDs were removed in https://github.com/publicsuffix/list/pull/2327

Change-Id: I749d014ab667502d9a112e0be645413ec6a7a66e
Reviewed-on: https://go-review.googlesource.com/c/net/+/659276
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-20 16:04:31 -07:00
Oleg Zaytsev
12150816f7 http2: improve error when server sends HTTP/1
If for some reason the server sends an HTTP/1.1 response
starting with "HTTP/1.1 " (9 bytes), http2 transport interprets that as
a valid frame header for an expected payload of ~4MB, and fails with
non-descriptive messages like "unexpected EOF".

This could happen, for example, if ALPN is misconfigured on the server's
load balancer.

This change attempts to improve that feedback by noting in the error
messages whenever the frame header was exactly the "HTTP/1.1 " bytes.

Change-Id: I7bf9ed2ee7f299b939b9004386f5bfa30a4e9032
GitHub-Last-Rev: d6e410daa3
GitHub-Pull-Request: golang/net#224
Reviewed-on: https://go-review.googlesource.com/c/net/+/623155
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
2025-03-13 05:30:06 -07:00
Pukki
312450e473 html: ensure <search> tag closes <p> and update tests
This change ensures that the <search> tag correctly closes an open <p> tag when encountered during parsing.

Changes:
- Added <search> to the list of elements that should close an open <p> tag in parse.go.
- Updated the second list in parse.go to ensure consistency.
- Updated html/atom/gen.go, table.go, and table_test.go accordingly.
- Modified parse_test.go to use strings.Builder instead of bytes.Buffer.
- Updated test error messages to follow Go’s conventions.
- Fixed an accidental colon in the comment in parse.go.

Change-Id: I5835da69f6bb0e14c483e55b7ae82915ae958dc1
Reviewed-on: https://go-review.googlesource.com/c/net/+/655457
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2025-03-12 15:46:46 -07:00
Hubert Grochowski
09731f9bf9 http2: improve handling of lost PING in Server
This addresses inconsistencies in handling lost PINGs
between Server and Transport by:
1. Always logging a message for lost PINGs, regardless of verbose mode.
2. Invoking CountError with the conn_close_lost_ping error key.

Fixes golang/go#69963

Change-Id: I58fee489f7896dbb80ccc50265452cd953f7ca6b
GitHub-Last-Rev: ef74c9577a
GitHub-Pull-Request: golang/net#229
Reviewed-on: https://go-review.googlesource.com/c/net/+/635555
Auto-Submit: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: David Chase <drchase@google.com>
2025-03-10 14:07:55 -07:00
Sean Liao
55989e24b9 http2/h2c: use ResponseController for hijacking connections
Fixes golang/go#71999

Change-Id: I38b236e47bc5893c5a84ef33abbeab0828125bd2
Reviewed-on: https://go-review.googlesource.com/c/net/+/655615
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-08 12:58:08 -08:00
Sean Liao
2914f46773 websocket: re-recommend gorilla/websocket
Undoes CL 457356 now that it has new maintainers.

Change-Id: I4e05c72d5dec98f7893e6bea38db19916fc03bbb
Reviewed-on: https://go-review.googlesource.com/c/net/+/655195
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-03-05 13:52:38 -08:00
Gopher Robot
99b3ae0643 go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: I1572a13b12dce8520f2b7f74c6516a6f1f6c9822
Reviewed-on: https://go-review.googlesource.com/c/net/+/655038
Auto-Submit: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: David Chase <drchase@google.com>
v0.37.0
2025-03-05 11:41:12 -08:00
Gopher Robot
85d1d54551 go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: Id043663bf74d33d77fcea718ff308fa9461f242b
Reviewed-on: https://go-review.googlesource.com/c/net/+/654320
Reviewed-by: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
Auto-Submit: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
v0.36.0
2025-03-04 11:24:45 -08:00
Damien Neil
cde1dda944 proxy, http/httpproxy: do not mismatch IPv6 zone ids against hosts
When matching against a host "example.com",
don't match an IPv6 address like "[1000::1%25.example.com]:80".

Thanks to Juho Forsén of Mattermost for reporting this issue.

Fixes CVE-2025-22870
For #71984

Change-Id: I0c4fdf18765decc27e6ddf220ebe3a9bf4a6454d
Reviewed-on: https://go-review.googlesource.com/c/net/+/654697
Auto-Submit: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Roland Shoemaker <roland@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2025-03-04 11:00:06 -08:00
Julien Cretel
fe7f0391aa publicsuffix: spruce up code gen and speed up PublicSuffix
Rely on functions from the slices package where convenient. Drop custom max functions in favor of max builtin. Remove unused non-exported functions.

Reduce the number of bounds checks. Replace calls to strings.LastIndex by calls to strings.LastIndexByte.

goos: darwin
goarch: amd64
pkg: golang.org/x/net/publicsuffix
cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
               │     old     │                new                 │
               │   sec/op    │   sec/op     vs base               │
PublicSuffix-8   13.46µ ± 0%   13.23µ ± 0%  -1.67% (p=0.000 n=20)

               │    old     │              new               │
               │    B/op    │    B/op     vs base            │
PublicSuffix-8   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=20) ¹
¹ all samples are equal

               │    old     │              new               │
               │ allocs/op  │ allocs/op   vs base            │
PublicSuffix-8   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=20) ¹
¹ all samples are equal

Change-Id: Id72967560884d98a5c0791ccea73dbb27d120c2c
GitHub-Last-Rev: 87567e7cb5
GitHub-Pull-Request: golang/net#233
Reviewed-on: https://go-review.googlesource.com/c/net/+/652236
Reviewed-by: Damien Neil <dneil@google.com>
Commit-Queue: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2025-02-28 12:42:09 -08:00
Damien Neil
459513d1f8 internal/http3: move more common stream processing to genericConn
Move the server stream-accept loop into genericConn.
(Overlooked in a previous CL.)

Be more consistent about having genericConn handle errors.

For golang/go#70914

Change-Id: I872673482f16539e95a1a1381ada7d3e22affb82
Reviewed-on: https://go-review.googlesource.com/c/net/+/653395
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-28 11:43:44 -08:00
Damien Neil
aad0180cad http2: fix flakiness from t.Log when GOOS=js
The http2 package uses a precursor to the experimental
testing/synctest package, parsing runtime.Stack output
to determine when goroutines are idle.

When GOOS=js, some tests which use t.Log are flaky.
t.Log blocks in the syscall package writing to stdout.
The GOOS=js implementation of the syscall leaves the goroutine
blocked on a channel operation, which synctest interprets
as the goroutine being "durably blocked".

Fix the http2 synctest to treat any goroutine blocked in the
syscall package as not being durably blocked.

Making this fix reveals another bug when GOOS=js: Looping
while calling runtime.Gosched does not appear to permit
syscalls to make progress. Add a few time.Sleep(1) calls
while waiting for idleness to work around the problem.

While changing things in here, change http2's synctest
to not treat goroutines blocked on mutex operations as
durably blocked. This matches the behavior of testing/synctest.

(This would all be simpler if we just used testing/synctest,
but we don't want to make the http2 package depend on an
experimental API.)

Fixes golang/go#67693

Change-Id: I889834e97e4a33f4ef232278b1a78af00d52d261
Reviewed-on: https://go-review.googlesource.com/c/net/+/653696
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-02-28 11:43:04 -08:00
Damien Neil
b73e5746f6 http2: don't log expected errors from writing invalid trailers
Change-Id: I1c8af5a1f7539a25d5602a7bc8e15756d3cafa56
Reviewed-on: https://go-review.googlesource.com/c/net/+/653695
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-28 11:31:43 -08:00
Damien Neil
5f45c776a9 internal/http3: make read-data tests usable for server handlers
A reading a transport response body behaves much the same as a
server handler reading a request body. Move the transport test into
body_test.go and rearrange it a bit so we can reuse it as a server
test.

For golang/go#70914

Change-Id: I24e10dd078ffab867c9b678e1d0b99172763b069
Reviewed-on: https://go-review.googlesource.com/c/net/+/652457
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-27 10:24:19 -08:00
Damien Neil
43c2540165 http2, internal/httpcommon: reject userinfo in :authority
RFC 9113, section 8.3.1: The :authority (host) in an HTTP
request must not include a userinfo (e.g., user@host).

Change-Id: I459a3da40b825c9662467778f582050c7358f8bb
Reviewed-on: https://go-review.googlesource.com/c/net/+/652456
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-02-26 14:12:30 -08:00
Damien Neil
1d78a08500 http2, internal/httpcommon: factor out server header logic for h2/h3
Move common elements of constructing a http.Request for
a server handler into internal/httpcommon.

For golang/go#70914

Change-Id: I5dcd902e189a0bb8daf47c0a815045d274346923
Reviewed-on: https://go-review.googlesource.com/c/net/+/652455
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-25 11:03:29 -08:00
Damien Neil
0d7dc54a59 quic: add Conn.ConnectionState
Add a method that returns the tls.ConnectionState for a connection.
Generally useful, and also required to let HTTP/3 expose the
ConnectionState in Requests.

Change-Id: Iba725e0f40c68020fc6ee45d49f5c609a2b6b493
Reviewed-on: https://go-review.googlesource.com/c/net/+/647075
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-25 10:41:37 -08:00
Damien Neil
b4c86550a5 http2: avoid extended CONNECT hang when connection breaks during startup
Fixes golang/go#70658

Change-Id: Iaac5c7730a10afc8a8bb2e725746fa7387970582
Reviewed-on: https://go-review.googlesource.com/c/net/+/633277
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Antonio Ojea <aojea@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-20 09:31:56 -08:00
Damien Neil
163d83654d internal/http3: add Server
Add the general structure of an HTTP/3 server.
The server currently accepts QUIC connections and establishes a
control stream on them, but does not handle requests.

For golang/go#70914

Change-Id: I28193ddacef028233248601979b0b45ad844205a
Reviewed-on: https://go-review.googlesource.com/c/net/+/646617
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-18 14:25:14 -08:00
Dmitri Shuralyov
447f458ae0 context: delete lone example
This is motivated by a few reasons. One, the upstream package has more
examples, and no one should be looking at this old package to learn how
to use it. Seeing an example might make it seem like the scope of the
documentation here is to provide examples, and that there aren't many
of them. Instead of trying to add more examples or maintain the current
one by porting the de-flake enhancement from CL 460999, delete the only
example here.

Second, running 'go fix ./...' causes the 'context' fix to rewrite the
import path of the example from "golang.org/x/net/context" to "context".
That is a false positive in the fix, and I would've liked it fix the
fix, but it only has the AST information at this time, not type info,
so the import path isn't currently available to the check. That means
it can't know when it's running on the golang.org/x/net/context package,
which is the one place it should skip the rewrite.

It seems simpler to just delete the example, and then it becomes
possible to use 'go fix ./...' safely on the entire x/net module.

For golang/go#49506.

Change-Id: I97eba33ca2e1f2960aef8340d8b561639a26ee48
Reviewed-on: https://go-review.googlesource.com/c/net/+/650156
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
2025-02-18 09:30:11 -08:00
Dmitri Shuralyov
918d64e8e6 context: delete dead code, sync docs with upstream context package
The go directive is now at 1.23.0, so the go1.7 and go1.9 build
constraints are guaranteed to always be satisfied, and their inverse
will never be satisfied. Delete all the dead code and merge everything
that's left in a single context.go file. Also update docs to match the
upstream context package.

For golang/go#49506.

Change-Id: I317550767838a93af2c2d3dbc7b61f2e37e6fe1c
Reviewed-on: https://go-review.googlesource.com/c/net/+/650155
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-02-18 09:28:57 -08:00
Gopher Robot
5095d0cf14 all: upgrade go directive to at least 1.23.0 [generated]
By now Go 1.24.0 has been released, and Go 1.22 is no longer supported
per the Go Release Policy (https://go.dev/doc/devel/release#policy).

For golang/go#69095.

[git-generate]
(cd . && go get go@1.23.0 && go mod tidy && go mod edit -toolchain=none)

Change-Id: I7e0b4b38a9838b5489cb674cd20ae60233a304e6
Reviewed-on: https://go-review.googlesource.com/c/net/+/649775
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-14 13:54:39 -08:00
Damien Neil
884432780b internal/httpcommon: don't depend on net/http
When the http2 package is bundled into net/http, it imports httpcommon,
so httpcommon must not depend on net/http.

Change-Id: I2aa34e913a0df757fa83deb56f650394a924933e
Reviewed-on: https://go-review.googlesource.com/c/net/+/649415
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-13 14:27:35 -08:00
Carlos Hernandez
cd9d6616c0 route: fix RTM_GET netmask parsing on Darwin
On Darwin, the AF_FAMILY byte of a sockaddr for a netmask or genmask
can be ignored if unreasonable. In such cases, it is the family of the
DST address that should instead be used.

Additionally, fixing faulty test data. 192.168.86.0 is a Class C network
address, that should have a subnet mask of 255.255.255.0. What's more is
the data can also be flag as incorrect considering structure padding
rules alone.

Further more, you can validate that `route get` will never actually return a
netmask for a host query, even though it should be  255.255.255.255.

You can run the following to check:
route -n get -host 127.0.0.1

You will note the reply has no mention of netmask.

Depends on CL 646556 - https://go.dev/cl/646556
Fixes golang/go#71578.

Change-Id: Id95669b649a416a380d26c5cdba0e3d1c4bc1ffb
GitHub-Last-Rev: 20064b2797
GitHub-Pull-Request: golang/net#232
Reviewed-on: https://go-review.googlesource.com/c/net/+/647176
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-02-10 12:16:25 -08:00
Gopher Robot
df97a48b7b go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: Ib0f6594d53289bb9226b7c8bc59bf82f1e19bad9
Reviewed-on: https://go-review.googlesource.com/c/net/+/647718
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
v0.35.0
2025-02-10 08:11:33 -08:00
Carlos Hernandez
2dab271ff1 route: treat short sockaddr lengths as unspecified
Previously, we enforced minimum length requirements for sockaddr, but
the route command can legitimately parse shorter lengths. This change
treats any sockaddr with length less than the address offset as an
unspecified address (0.0.0.0 for IPv4 or :: for IPv6), as discern by
monitoring the route command.

To replicate the issue, prior to the fix, execute the following:

First:
route -n monitor

Next:
sudo route -n add -inet6 -ifscope en11 -net :: \
    -netmask :: fe80::2d0:4cff:fe10:15d2

The route command that is actively monitoring will print something such
as:
RTM_ADD: Add Route: len 152, pid: 81198, seq 1, errno 0, ifscope 13, flags:<UP,GATEWAY,DONE,STATIC,IFSCOPE>
locks:  inits:
sockaddrs: <DST,GATEWAY,NETMASK>
:: fe80::2d0:4cff:fe10:15d2 ::

Prior to the fix, if you had attempted parse the above message, PareRIB
would have returned errInvalidAddr which is clearly false.

Fixes golang/go#71557

Change-Id: Iec86cc9b05a765b6e67e95a4e30ff31f66f3d17e
GitHub-Last-Rev: 396d8a27da
GitHub-Pull-Request: golang/net#231
Reviewed-on: https://go-review.googlesource.com/c/net/+/646556
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-02-06 12:21:36 -08:00
Damien Neil
b914489dfb internal/http3: refactor in prep for sharing transport/server code
Pull out various elements of the HTTP/3 client that can be
reused in the server. Move tests which can apply to client or server
connections into conn_test.go.

For golang/go#70914

Change-Id: I72b5eab55ba27df980ab2079120613f175b05927
Reviewed-on: https://go-review.googlesource.com/c/net/+/646616
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-02-04 17:21:19 -08:00
Carlos Hernandez
ebd23f8b4b route: fix parsing network address of length zero
sa_len of 0 should be valid, for Chapter 18 of UNIX® Network Programming
Volume 1, Third Edition: The Sockets Networking API, states:

The socket address structures are variable-length, but this code assumes
that each has an sa_len field specifying its length. There are two
complications that must be handled. First, the two masks, the network
mask and the cloning mask, can be returned in a socket address structure
with an sa_len of 0, but this really occupies the size of an unsigned
long. (Chapter 19 of TCPv2 discusses the cloning feature of the 4.4BSD
routing table). This value represents a mask of all zero bits, which we
printed as 0.0.0.0 for the network mask of the default route in our
earlier example.

There are other references in the book which also state sa_len of 0 is
valid.

Fixes golang/go#70528

Change-Id: I9205a674f9cdf8091b1cc8b8a56609cd1cf4c670
GitHub-Last-Rev: df63086c54
GitHub-Pull-Request: golang/net#230
Reviewed-on: https://go-review.googlesource.com/c/net/+/646555
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-02-04 14:06:08 -08:00
Damien Neil
938a9fb94e internal/http3: add request/response body transfer
For golang/go#70914

Change-Id: I372458214fe73f8156e0ec291168b043c10221e6
Reviewed-on: https://go-review.googlesource.com/c/net/+/644915
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-02-03 17:39:20 -08:00
Damien Neil
145b2d7b6d internal/http3: add RoundTrip
Send request headers, receive response headers.

For golang/go#70914

Change-Id: I78d4dcc69c253ed7ad1543dfc3c5d8f1c321ced9
Reviewed-on: https://go-review.googlesource.com/c/net/+/644118
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-01-27 16:46:54 -08:00
Damien Neil
5bda71aec0 internal/http3: define connection and stream error types
HTTP/3 distinguishes between connection errors which result in an
entire connection closing, and stream errors which only terminate
a single request stream.

Define internal types to represent these two types of error.

For golang/go#70914

Change-Id: I907f395adc82a683b5c2eda65f936b1ab4904ffb
Reviewed-on: https://go-review.googlesource.com/c/net/+/644117
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-01-24 14:20:07 -08:00
Damien Neil
3c1185a39b internal/http3: return error on mid-frame EOF
When a stream ends in the middle of a frame,
return a non-EOF error from Read or ReadByte.

When a stream ends at the end of a frame,
don't return io.EOF from the Read call that reads
the last byte of the frame.
(This complicates stream.Read slightly,
but means that code that reads frames consistently
never sees an io.EOF, but gets an error if it tries
to read past the end of a frame.)

For golang/go#70914

Change-Id: If1b852716fe5e3aa3503f6970e2e1fba2ebb5f48
Reviewed-on: https://go-review.googlesource.com/c/net/+/644116
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2025-01-24 14:05:38 -08:00
Damien Neil
a6c2c7f364 http2, internal/httpcommon: factor out common request header logic for h2/h3
HTTP/2 and HTTP/3 use the same set of pseudo-headers to represent
requests and responses. Move the http2 package's logic for validating
an http.Request and converting it to a set of pseudo-headers into
internal/httpcommon so it can be shared with HTTP/3.

For golang/go#70914

Change-Id: I80561752e821ccd0da2a811034c44f3f71064434
Reviewed-on: https://go-review.googlesource.com/c/net/+/643780
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Commit-Queue: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
2025-01-24 11:09:29 -08:00
Damien Neil
c72e89d6a9 internal/http3: QPACK encoding and decoding
Basic support for encoding/decoding QPACK headers.

QPACK supports three forms of header compression:
Huffman-encoding of literal strings, a static table of
well-known header values, and a dynamic table of
header values negotiated between encoder and decoder
at runtime.

Right now, we support Huffman compression and the
static table, but not the dynamic table.
This is a supported mode for a QPACK encoder or
decoder, so we can leave dynamic table support
for after the rest of HTTP/3 is working.

For golang/go#70914

Change-Id: Ib694199b99c752a220d43f3a309169b16020b474
Reviewed-on: https://go-review.googlesource.com/c/net/+/642599
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2025-01-22 16:02:30 -08:00
Damien Neil
93c1957e42 internal/http3: add Transport and ClientConn
Add the first rudiments of an HTTP/3 client.

The client currently opens a QUIC connection and creates a control
stream on it, and nothing else.

Add surrounding test infrastructure for examining the client's
behavior. Tests use the experimental testing/synctest package
and will only run when the Go version is at least Go 1.24 and
GOEXPERIMENT=synctest is set.

For golang/go#70914

Change-Id: I19803187a8e62c461f60d7a1d44c2a408377e342
Reviewed-on: https://go-review.googlesource.com/c/net/+/642516
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-01-22 10:00:23 -08:00
Tobias Klauser
45432b5e4f internal/socket, webdav: use testing.T.TempDir
It's available since Go 1.15 and go.mod currently specifies Go 1.18.

Change-Id: Ia5ba22f5802f4af9fb6d3b6e7ee5a02ce3582e9a
Reviewed-on: https://go-review.googlesource.com/c/net/+/643595
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-01-21 14:35:12 -08:00
Damien Neil
56691ee141 quic: don't return EOF from ReadByte when we have a byte
Change-Id: I3be7c43fa6ceeb75582f648ee56025991eda9611
Reviewed-on: https://go-review.googlesource.com/c/net/+/642515
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>
2025-01-13 15:50:21 -08:00
Damien Neil
7ad0ebf002 internal/http3: qpack wire primitives
Encode and decode QPACK prefixed integers and string literals.

For golang/go#70914

Change-Id: Id12d1853738fc6d0e03bbbef36b67c24298451e1
Reviewed-on: https://go-review.googlesource.com/c/net/+/642115
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-01-13 15:50:20 -08:00
Damien Neil
f6b2e53bb7 internal/http3: basic stream read/write operations
Read and write HTTP/3 frames from QUIC streams.

The varint encoding/decoding overlaps a bit with that in
the quic package, but this package operates on streams while
the QUIC package operates on []bytes.

For golang/go#70914

Change-Id: I31115f5b572a59b899e2c880ecc86ba3caed982e
Reviewed-on: https://go-review.googlesource.com/c/net/+/641838
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-01-13 15:50:17 -08:00