Skip to content

Commit f52ce53

Browse files
committed
Add ECS source netmark option
1 parent 9fb3613 commit f52ce53

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

extension_edns0_subnet.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import (
99

1010
type edns0SubnetTransportWrapper struct {
1111
Transport
12-
clientSubnet netip.Addr
12+
clientSubnet netip.Prefix
1313
}
1414

1515
func (t *edns0SubnetTransportWrapper) Exchange(ctx context.Context, message *dns.Msg) (*dns.Msg, error) {
1616
SetClientSubnet(message, t.clientSubnet, false)
1717
return t.Transport.Exchange(ctx, message)
1818
}
1919

20-
func SetClientSubnet(message *dns.Msg, clientSubnet netip.Addr, override bool) {
20+
func SetClientSubnet(message *dns.Msg, clientSubnet netip.Prefix, override bool) {
2121
var (
2222
optRecord *dns.OPT
2323
subnetOption *dns.EDNS0_SUBNET
@@ -52,11 +52,11 @@ findExists:
5252
optRecord.Option = append(optRecord.Option, subnetOption)
5353
}
5454
subnetOption.Code = dns.EDNS0SUBNET
55-
if clientSubnet.Is4() {
55+
if clientSubnet.Addr().Is4() {
5656
subnetOption.Family = 1
5757
} else {
5858
subnetOption.Family = 2
5959
}
60-
subnetOption.SourceNetmask = uint8(clientSubnet.BitLen())
61-
subnetOption.Address = clientSubnet.AsSlice()
60+
subnetOption.SourceNetmask = uint8(clientSubnet.Bits())
61+
subnetOption.Address = clientSubnet.Addr().AsSlice()
6262
}

extensions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ func transportNameFromContext(ctx context.Context) (string, bool) {
4646

4747
type clientSubnetKey struct{}
4848

49-
func ContextWithClientSubnet(ctx context.Context, clientSubnet netip.Addr) context.Context {
49+
func ContextWithClientSubnet(ctx context.Context, clientSubnet netip.Prefix) context.Context {
5050
return context.WithValue(ctx, clientSubnetKey{}, clientSubnet)
5151
}
5252

53-
func ClientSubnetFromContext(ctx context.Context) (netip.Addr, bool) {
54-
clientSubnet, ok := ctx.Value(clientSubnetKey{}).(netip.Addr)
53+
func ClientSubnetFromContext(ctx context.Context) (netip.Prefix, bool) {
54+
clientSubnet, ok := ctx.Value(clientSubnetKey{}).(netip.Prefix)
5555
return clientSubnet, ok
5656
}

transport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type TransportOptions struct {
3030
Name string
3131
Dialer N.Dialer
3232
Address string
33-
ClientSubnet netip.Addr
33+
ClientSubnet netip.Prefix
3434
}
3535

3636
var transports map[string]TransportConstructor

transport_base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type myTransportAdapter struct {
2828
cancel context.CancelFunc
2929
dialer N.Dialer
3030
serverAddr M.Socksaddr
31-
clientAddr netip.Addr
31+
clientAddr netip.Prefix
3232
handler myTransportHandler
3333
access sync.Mutex
3434
conn *dnsConnection

0 commit comments

Comments
 (0)