Skip to content

Commit 8b55eeb

Browse files
committed
align GOOS=tamago support go go1.22.0
1 parent d3bb36e commit 8b55eeb

12 files changed

+118
-62
lines changed

src/net/dnsclient_tamago.go

+47-29
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package net
1515
import (
1616
"context"
1717
"errors"
18+
"internal/bytealg"
1819
"io"
1920
"time"
2021

@@ -198,7 +199,9 @@ func (r *Resolver) exchange(ctx context.Context, server string, q dnsmessage.Que
198199

199200
// checkHeader performs basic sanity checks on the header.
200201
func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header) error {
201-
if h.RCode == dnsmessage.RCodeNameError {
202+
rcode := extractExtendedRCode(*p, h)
203+
204+
if rcode == dnsmessage.RCodeNameError {
202205
return errNoSuchHost
203206
}
204207

@@ -209,17 +212,17 @@ func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header) error {
209212

210213
// libresolv continues to the next server when it receives
211214
// an invalid referral response. See golang.org/issue/15434.
212-
if h.RCode == dnsmessage.RCodeSuccess && !h.Authoritative && !h.RecursionAvailable && err == dnsmessage.ErrSectionDone {
215+
if rcode == dnsmessage.RCodeSuccess && !h.Authoritative && !h.RecursionAvailable && err == dnsmessage.ErrSectionDone {
213216
return errLameReferral
214217
}
215218

216-
if h.RCode != dnsmessage.RCodeSuccess && h.RCode != dnsmessage.RCodeNameError {
219+
if rcode != dnsmessage.RCodeSuccess && rcode != dnsmessage.RCodeNameError {
217220
// None of the error codes make sense
218221
// for the query we sent. If we didn't get
219222
// a name error and we didn't get success,
220223
// the server is behaving incorrectly or
221224
// having temporary trouble.
222-
if h.RCode == dnsmessage.RCodeServerFailure {
225+
if rcode == dnsmessage.RCodeServerFailure {
223226
return errServerTemporarilyMisbehaving
224227
}
225228
return errServerMisbehaving
@@ -246,6 +249,23 @@ func skipToAnswer(p *dnsmessage.Parser, qtype dnsmessage.Type) error {
246249
}
247250
}
248251

252+
// extractExtendedRCode extracts the extended RCode from the OPT resource (EDNS(0))
253+
// If an OPT record is not found, the RCode from the hdr is returned.
254+
func extractExtendedRCode(p dnsmessage.Parser, hdr dnsmessage.Header) dnsmessage.RCode {
255+
p.SkipAllAnswers()
256+
p.SkipAllAuthorities()
257+
for {
258+
ahdr, err := p.AdditionalHeader()
259+
if err != nil {
260+
return hdr.RCode
261+
}
262+
if ahdr.Type == dnsmessage.TypeOPT {
263+
return ahdr.ExtendedRCode(hdr.RCode)
264+
}
265+
p.SkipAdditional()
266+
}
267+
}
268+
249269
// Do a lookup for a single name, which must be rooted
250270
// (otherwise answer will not find the answers).
251271
func (r *Resolver) tryOneName(ctx context.Context, cfg *dnsConfig, name string, qtype dnsmessage.Type) (dnsmessage.Parser, string, error) {
@@ -385,10 +405,6 @@ func avoidDNS(name string) bool {
385405

386406
// nameList returns a list of names for sequential DNS queries.
387407
func (conf *dnsConfig) nameList(name string) []string {
388-
if avoidDNS(name) {
389-
return nil
390-
}
391-
392408
// Check name length (see isDomainName).
393409
l := len(name)
394410
rooted := l > 0 && name[l-1] == '.'
@@ -398,27 +414,31 @@ func (conf *dnsConfig) nameList(name string) []string {
398414

399415
// If name is rooted (trailing dot), try only that name.
400416
if rooted {
417+
if avoidDNS(name) {
418+
return nil
419+
}
401420
return []string{name}
402421
}
403422

404-
hasNdots := count(name, '.') >= conf.ndots
423+
hasNdots := bytealg.CountString(name, '.') >= conf.ndots
405424
name += "."
406425
l++
407426

408427
// Build list of search choices.
409428
names := make([]string, 0, 1+len(conf.search))
410429
// If name has enough dots, try unsuffixed first.
411-
if hasNdots {
430+
if hasNdots && !avoidDNS(name) {
412431
names = append(names, name)
413432
}
414433
// Try suffixes that are not too long (see isDomainName).
415434
for _, suffix := range conf.search {
416-
if l+len(suffix) <= 254 {
417-
names = append(names, name+suffix)
435+
fqdn := name + suffix
436+
if !avoidDNS(fqdn) && len(fqdn) <= 254 {
437+
names = append(names, fqdn)
418438
}
419439
}
420440
// Try unsuffixed, if not tried first above.
421-
if !hasNdots {
441+
if !hasNdots && !avoidDNS(name) {
422442
names = append(names, name)
423443
}
424444
return names
@@ -520,7 +540,7 @@ func (r *Resolver) goLookupIPCNAME(ctx context.Context, network, name string, co
520540
h, err := result.p.AnswerHeader()
521541
if err != nil && err != dnsmessage.ErrSectionDone {
522542
lastErr = &DNSError{
523-
Err: "cannot marshal DNS message",
543+
Err: errCannotUnmarshalDNSMessage.Error(),
524544
Name: name,
525545
Server: result.server,
526546
}
@@ -533,7 +553,7 @@ func (r *Resolver) goLookupIPCNAME(ctx context.Context, network, name string, co
533553
a, err := result.p.AResource()
534554
if err != nil {
535555
lastErr = &DNSError{
536-
Err: "cannot marshal DNS message",
556+
Err: errCannotUnmarshalDNSMessage.Error(),
537557
Name: name,
538558
Server: result.server,
539559
}
@@ -548,7 +568,7 @@ func (r *Resolver) goLookupIPCNAME(ctx context.Context, network, name string, co
548568
aaaa, err := result.p.AAAAResource()
549569
if err != nil {
550570
lastErr = &DNSError{
551-
Err: "cannot marshal DNS message",
571+
Err: errCannotUnmarshalDNSMessage.Error(),
552572
Name: name,
553573
Server: result.server,
554574
}
@@ -563,7 +583,7 @@ func (r *Resolver) goLookupIPCNAME(ctx context.Context, network, name string, co
563583
c, err := result.p.CNAMEResource()
564584
if err != nil {
565585
lastErr = &DNSError{
566-
Err: "cannot marshal DNS message",
586+
Err: errCannotUnmarshalDNSMessage.Error(),
567587
Name: name,
568588
Server: result.server,
569589
}
@@ -576,7 +596,7 @@ func (r *Resolver) goLookupIPCNAME(ctx context.Context, network, name string, co
576596
default:
577597
if err := result.p.SkipAnswer(); err != nil {
578598
lastErr = &DNSError{
579-
Err: "cannot marshal DNS message",
599+
Err: errCannotUnmarshalDNSMessage.Error(),
580600
Name: name,
581601
Server: result.server,
582602
}
@@ -612,16 +632,14 @@ func (r *Resolver) goLookupIPCNAME(ctx context.Context, network, name string, co
612632
return addrs, cname, nil
613633
}
614634

635+
// goLookupCNAME is the native Go (non-cgo) implementation of LookupCNAME.
636+
func (r *Resolver) goLookupCNAME(ctx context.Context, host string, conf *dnsConfig) (string, error) {
637+
_, cname, err := r.goLookupIPCNAME(ctx, "CNAME", host, conf)
638+
return cname.String(), err
639+
}
640+
615641
// goLookupPTR is the native Go implementation of LookupAddr.
616-
// Used only if cgoLookupPTR refuses to handle the request (that is,
617-
// only if cgoLookupPTR is the stub in cgo_stub.go).
618-
// Normally we let cgo use the C library resolver instead of depending
619-
// on our lookup code, so that Go and C get the same answers.
620642
func (r *Resolver) goLookupPTR(ctx context.Context, addr string, conf *dnsConfig) ([]string, error) {
621-
names := lookupStaticAddr(addr)
622-
if len(names) > 0 {
623-
return names, nil
624-
}
625643
arpa, err := reverseaddr(addr)
626644
if err != nil {
627645
return nil, err
@@ -638,7 +656,7 @@ func (r *Resolver) goLookupPTR(ctx context.Context, addr string, conf *dnsConfig
638656
}
639657
if err != nil {
640658
return nil, &DNSError{
641-
Err: "cannot marshal DNS message",
659+
Err: errCannotUnmarshalDNSMessage.Error(),
642660
Name: addr,
643661
Server: server,
644662
}
@@ -647,7 +665,7 @@ func (r *Resolver) goLookupPTR(ctx context.Context, addr string, conf *dnsConfig
647665
err := p.SkipAnswer()
648666
if err != nil {
649667
return nil, &DNSError{
650-
Err: "cannot marshal DNS message",
668+
Err: errCannotUnmarshalDNSMessage.Error(),
651669
Name: addr,
652670
Server: server,
653671
}
@@ -657,7 +675,7 @@ func (r *Resolver) goLookupPTR(ctx context.Context, addr string, conf *dnsConfig
657675
ptr, err := p.PTRResource()
658676
if err != nil {
659677
return nil, &DNSError{
660-
Err: "cannot marshal DNS message",
678+
Err: errCannotUnmarshalDNSMessage.Error(),
661679
Name: addr,
662680
Server: server,
663681
}

src/net/lookup_tamago.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,36 @@ func (r *Resolver) lookupHost(ctx context.Context, host string) (addrs []string,
2424
return
2525
}
2626

27-
func (r *Resolver) lookupIP(ctx context.Context, network, name string) (addrs []IPAddr, err error) {
28-
ips, _, err := r.goLookupIPCNAME(ctx, network, name, getSystemDNSConfig())
27+
func (r *Resolver) lookupIP(ctx context.Context, network, host string) (addrs []IPAddr, err error) {
28+
ips, _, err := r.goLookupIPCNAME(ctx, network, host, getSystemDNSConfig())
2929
return ips, err
3030
}
3131

32-
func (*Resolver) lookupPort(ctx context.Context, network, service string) (port int, err error) {
32+
func (r *Resolver) lookupPort(ctx context.Context, network, service string) (int, error) {
3333
return goLookupPort(network, service)
3434
}
3535

3636
func (r *Resolver) lookupCNAME(ctx context.Context, name string) (string, error) {
37-
_, cname, err := r.goLookupIPCNAME(ctx, "CNAME", name, getSystemDNSConfig())
38-
return cname.String(), err
37+
return r.goLookupCNAME(ctx, name, getSystemDNSConfig())
3938
}
4039

41-
func (r *Resolver) lookupSRV(ctx context.Context, service, proto, name string) (cname string, srvs []*SRV, err error) {
40+
func (r *Resolver) lookupSRV(ctx context.Context, service, proto, name string) (string, []*SRV, error) {
4241
return r.goLookupSRV(ctx, service, proto, name)
4342
}
4443

45-
func (r *Resolver) lookupMX(ctx context.Context, name string) (mxs []*MX, err error) {
44+
func (r *Resolver) lookupMX(ctx context.Context, name string) ([]*MX, error) {
4645
return r.goLookupMX(ctx, name)
4746
}
4847

49-
func (r *Resolver) lookupNS(ctx context.Context, name string) (nss []*NS, err error) {
48+
func (r *Resolver) lookupNS(ctx context.Context, name string) ([]*NS, error) {
5049
return r.goLookupNS(ctx, name)
5150
}
5251

53-
func (r *Resolver) lookupTXT(ctx context.Context, name string) (txts []string, err error) {
52+
func (r *Resolver) lookupTXT(ctx context.Context, name string) ([]string, error) {
5453
return r.goLookupTXT(ctx, name)
5554
}
5655

57-
func (r *Resolver) lookupAddr(ctx context.Context, addr string) (ptrs []string, err error) {
56+
func (r *Resolver) lookupAddr(ctx context.Context, addr string) ([]string, error) {
5857
return r.goLookupPTR(ctx, addr, getSystemDNSConfig())
5958
}
6059

src/net/sockopt_fake.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build js || wasip1 || tamago
5+
//go:build js || wasip1
66

77
package net
88

src/net/sockopt_tamago.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2011 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build tamago
6+
7+
package net
8+
9+
import "syscall"
10+
11+
func setDefaultSockopts(s, family, sotype int, ipv6only bool) error {
12+
return nil
13+
}
14+
15+
func setDefaultListenerSockopts(s int) error {
16+
return nil
17+
}
18+
19+
func setDefaultMulticastSockopts(s int) error {
20+
return nil
21+
}
22+
23+
func setReadBuffer(fd *netFD, bytes int) error {
24+
return syscall.ENOPROTOOPT
25+
}
26+
27+
func setWriteBuffer(fd *netFD, bytes int) error {
28+
return syscall.ENOPROTOOPT
29+
}
30+
31+
func setKeepAlive(fd *netFD, keepalive bool) error {
32+
return syscall.ENOPROTOOPT
33+
}
34+
35+
func setLinger(fd *netFD, sec int) error {
36+
return syscall.ENOPROTOOPT
37+
}

src/os/exec/lp_tamago.go

+6
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ func LookPath(file string) (string, error) {
2121
// tamago can not execute processes, so act as if there are no executables at all.
2222
return "", &Error{file, ErrNotFound}
2323
}
24+
25+
// lookExtensions is a no-op on non-Windows platforms, since
26+
// they do not restrict executables to specific extensions.
27+
func lookExtensions(path, dir string) (string, error) {
28+
return path, nil
29+
}

src/os/file_open_tamago.go

-17
This file was deleted.

src/os/file_open_unix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build unix || (js && wasm)
5+
//go:build unix || (js && wasm) || tamago
66

77
package os
88

src/os/stat_js.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build (js && wasm)
5+
//go:build js && wasm
66

77
package os
88

src/runtime/lock_tamago.go

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const (
2323
passive_spin = 1
2424
)
2525

26+
func mutexContended(l *mutex) bool {
27+
return false
28+
}
29+
2630
func lock(l *mutex) {
2731
lockWithRank(l, getLockRank(l))
2832
}

src/runtime/os_tamago_arm.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ func osinit() {
110110
initBloc()
111111
}
112112

113+
func readRandom(r []byte) int {
114+
initRNG()
115+
getRandomData(r)
116+
return len(r)
117+
}
118+
113119
func signame(sig uint32) string {
114120
return ""
115121
}
@@ -123,7 +129,6 @@ func checkgoarm() {
123129

124130
//go:nosplit
125131
func cputicks() int64 {
126-
// Currently cputicks() is used in blocking profiler and to seed runtime·fastrand().
127132
// runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
128133
return nanotime()
129134
}

src/runtime/os_tamago_riscv64.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,18 @@ func osinit() {
9292
initBloc()
9393
}
9494

95+
func readRandom(r []byte) int {
96+
initRNG()
97+
getRandomData(r)
98+
return len(r)
99+
}
100+
95101
func signame(sig uint32) string {
96102
return ""
97103
}
98104

99105
//go:nosplit
100106
func cputicks() int64 {
101-
// Currently cputicks() is used in blocking profiler and to seed runtime·fastrand().
102107
// runtime·nanotime() is a poor approximation of CPU ticks that is enough for the profiler.
103108
return nanotime()
104109
}

0 commit comments

Comments
 (0)