Change: use uint16 for Metadata SrcPort and DstPort
This commit is contained in:
parent
47b6eb1700
commit
c0e51f8556
@ -7,6 +7,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/common/queue"
|
"github.com/Dreamacro/clash/common/queue"
|
||||||
@ -194,10 +195,12 @@ func urlToMetadata(rawURL string) (addr C.Metadata, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p, _ := strconv.ParseUint(port, 10, 16)
|
||||||
|
|
||||||
addr = C.Metadata{
|
addr = C.Metadata{
|
||||||
Host: u.Hostname(),
|
Host: u.Hostname(),
|
||||||
DstIP: nil,
|
DstIP: nil,
|
||||||
DstPort: port,
|
DstPort: C.Port(p),
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package inbound
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"github.com/Dreamacro/clash/context"
|
"github.com/Dreamacro/clash/context"
|
||||||
@ -15,14 +14,14 @@ func NewHTTP(target socks5.Addr, source net.Addr, originTarget net.Addr, conn ne
|
|||||||
metadata := parseSocksAddr(target)
|
metadata := parseSocksAddr(target)
|
||||||
metadata.NetWork = C.TCP
|
metadata.NetWork = C.TCP
|
||||||
metadata.Type = C.HTTP
|
metadata.Type = C.HTTP
|
||||||
if ip, port, err := parseAddr(source.String()); err == nil {
|
if ip, port, err := parseAddr(source); err == nil {
|
||||||
metadata.SrcIP = ip
|
metadata.SrcIP = ip
|
||||||
metadata.SrcPort = port
|
metadata.SrcPort = C.Port(port)
|
||||||
}
|
}
|
||||||
if originTarget != nil {
|
if originTarget != nil {
|
||||||
if addrPort, err := netip.ParseAddrPort(originTarget.String()); err == nil {
|
if addrPort, err := netip.ParseAddrPort(originTarget.String()); err == nil {
|
||||||
metadata.OriginDst = addrPort
|
metadata.OriginDst = addrPort
|
||||||
metadata.InboundPort = strconv.Itoa(int(addrPort.Port()))
|
metadata.InboundPort = addrPort.Port()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return context.NewConnContext(conn, metadata)
|
return context.NewConnContext(conn, metadata)
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"github.com/Dreamacro/clash/context"
|
"github.com/Dreamacro/clash/context"
|
||||||
@ -14,13 +13,13 @@ import (
|
|||||||
func NewHTTPS(request *http.Request, conn net.Conn) *context.ConnContext {
|
func NewHTTPS(request *http.Request, conn net.Conn) *context.ConnContext {
|
||||||
metadata := parseHTTPAddr(request)
|
metadata := parseHTTPAddr(request)
|
||||||
metadata.Type = C.HTTPCONNECT
|
metadata.Type = C.HTTPCONNECT
|
||||||
if ip, port, err := parseAddr(conn.RemoteAddr().String()); err == nil {
|
if ip, port, err := parseAddr(conn.RemoteAddr()); err == nil {
|
||||||
metadata.SrcIP = ip
|
metadata.SrcIP = ip
|
||||||
metadata.SrcPort = port
|
metadata.SrcPort = C.Port(port)
|
||||||
}
|
}
|
||||||
if addrPort, err := netip.ParseAddrPort(conn.LocalAddr().String()); err == nil {
|
if addrPort, err := netip.ParseAddrPort(conn.LocalAddr().String()); err == nil {
|
||||||
metadata.OriginDst = addrPort
|
metadata.OriginDst = addrPort
|
||||||
metadata.InboundPort = strconv.Itoa(int(addrPort.Port()))
|
metadata.InboundPort = addrPort.Port()
|
||||||
}
|
}
|
||||||
return context.NewConnContext(conn, metadata)
|
return context.NewConnContext(conn, metadata)
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ func NewPacket(target socks5.Addr, originTarget net.Addr, packet C.UDPPacket, so
|
|||||||
metadata := parseSocksAddr(target)
|
metadata := parseSocksAddr(target)
|
||||||
metadata.NetWork = C.UDP
|
metadata.NetWork = C.UDP
|
||||||
metadata.Type = source
|
metadata.Type = source
|
||||||
if ip, port, err := parseAddr(packet.LocalAddr().String()); err == nil {
|
if ip, port, err := parseAddr(packet.LocalAddr()); err == nil {
|
||||||
metadata.SrcIP = ip
|
metadata.SrcIP = ip
|
||||||
metadata.SrcPort = port
|
metadata.SrcPort = C.Port(port)
|
||||||
}
|
}
|
||||||
if originTarget != nil {
|
if originTarget != nil {
|
||||||
if addrPort, err := netip.ParseAddrPort(originTarget.String()); err == nil {
|
if addrPort, err := netip.ParseAddrPort(originTarget.String()); err == nil {
|
||||||
|
@ -3,7 +3,6 @@ package inbound
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"github.com/Dreamacro/clash/context"
|
"github.com/Dreamacro/clash/context"
|
||||||
@ -15,13 +14,13 @@ func NewSocket(target socks5.Addr, conn net.Conn, source C.Type) *context.ConnCo
|
|||||||
metadata := parseSocksAddr(target)
|
metadata := parseSocksAddr(target)
|
||||||
metadata.NetWork = C.TCP
|
metadata.NetWork = C.TCP
|
||||||
metadata.Type = source
|
metadata.Type = source
|
||||||
if ip, port, err := parseAddr(conn.RemoteAddr().String()); err == nil {
|
if ip, port, err := parseAddr(conn.RemoteAddr()); err == nil {
|
||||||
metadata.SrcIP = ip
|
metadata.SrcIP = ip
|
||||||
metadata.SrcPort = port
|
metadata.SrcPort = C.Port(port)
|
||||||
}
|
}
|
||||||
if addrPort, err := netip.ParseAddrPort(conn.LocalAddr().String()); err == nil {
|
if addrPort, err := netip.ParseAddrPort(conn.LocalAddr().String()); err == nil {
|
||||||
metadata.OriginDst = addrPort
|
metadata.OriginDst = addrPort
|
||||||
metadata.InboundPort = strconv.Itoa(int(addrPort.Port()))
|
metadata.InboundPort = addrPort.Port()
|
||||||
}
|
}
|
||||||
return context.NewConnContext(conn, metadata)
|
return context.NewConnContext(conn, metadata)
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package inbound
|
package inbound
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Dreamacro/clash/common/util"
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"github.com/Dreamacro/clash/transport/socks5"
|
"github.com/Dreamacro/clash/transport/socks5"
|
||||||
)
|
)
|
||||||
@ -17,15 +19,15 @@ func parseSocksAddr(target socks5.Addr) *C.Metadata {
|
|||||||
case socks5.AtypDomainName:
|
case socks5.AtypDomainName:
|
||||||
// trim for FQDN
|
// trim for FQDN
|
||||||
metadata.Host = strings.TrimRight(string(target[2:2+target[1]]), ".")
|
metadata.Host = strings.TrimRight(string(target[2:2+target[1]]), ".")
|
||||||
metadata.DstPort = strconv.Itoa((int(target[2+target[1]]) << 8) | int(target[2+target[1]+1]))
|
metadata.DstPort = C.Port((int(target[2+target[1]]) << 8) | int(target[2+target[1]+1]))
|
||||||
case socks5.AtypIPv4:
|
case socks5.AtypIPv4:
|
||||||
ip := net.IP(target[1 : 1+net.IPv4len])
|
ip := net.IP(target[1 : 1+net.IPv4len])
|
||||||
metadata.DstIP = ip
|
metadata.DstIP = ip
|
||||||
metadata.DstPort = strconv.Itoa((int(target[1+net.IPv4len]) << 8) | int(target[1+net.IPv4len+1]))
|
metadata.DstPort = C.Port((int(target[1+net.IPv4len]) << 8) | int(target[1+net.IPv4len+1]))
|
||||||
case socks5.AtypIPv6:
|
case socks5.AtypIPv6:
|
||||||
ip := net.IP(target[1 : 1+net.IPv6len])
|
ip := net.IP(target[1 : 1+net.IPv6len])
|
||||||
metadata.DstIP = ip
|
metadata.DstIP = ip
|
||||||
metadata.DstPort = strconv.Itoa((int(target[1+net.IPv6len]) << 8) | int(target[1+net.IPv6len+1]))
|
metadata.DstPort = C.Port((int(target[1+net.IPv6len]) << 8) | int(target[1+net.IPv6len+1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
@ -33,10 +35,7 @@ func parseSocksAddr(target socks5.Addr) *C.Metadata {
|
|||||||
|
|
||||||
func parseHTTPAddr(request *http.Request) *C.Metadata {
|
func parseHTTPAddr(request *http.Request) *C.Metadata {
|
||||||
host := request.URL.Hostname()
|
host := request.URL.Hostname()
|
||||||
port := request.URL.Port()
|
port, _ := strconv.ParseUint(util.EmptyOr(request.URL.Port(), "80"), 10, 16)
|
||||||
if port == "" {
|
|
||||||
port = "80"
|
|
||||||
}
|
|
||||||
|
|
||||||
// trim FQDN (#737)
|
// trim FQDN (#737)
|
||||||
host = strings.TrimRight(host, ".")
|
host = strings.TrimRight(host, ".")
|
||||||
@ -45,7 +44,7 @@ func parseHTTPAddr(request *http.Request) *C.Metadata {
|
|||||||
NetWork: C.TCP,
|
NetWork: C.TCP,
|
||||||
Host: host,
|
Host: host,
|
||||||
DstIP: nil,
|
DstIP: nil,
|
||||||
DstPort: port,
|
DstPort: C.Port(port),
|
||||||
}
|
}
|
||||||
|
|
||||||
if ip := net.ParseIP(host); ip != nil {
|
if ip := net.ParseIP(host); ip != nil {
|
||||||
@ -55,12 +54,13 @@ func parseHTTPAddr(request *http.Request) *C.Metadata {
|
|||||||
return metadata
|
return metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseAddr(addr string) (net.IP, string, error) {
|
func parseAddr(addr net.Addr) (net.IP, int, error) {
|
||||||
host, port, err := net.SplitHostPort(addr)
|
switch a := addr.(type) {
|
||||||
if err != nil {
|
case *net.TCPAddr:
|
||||||
return nil, "", err
|
return a.IP, a.Port, nil
|
||||||
|
case *net.UDPAddr:
|
||||||
|
return a.IP, a.Port, nil
|
||||||
|
default:
|
||||||
|
return nil, 0, fmt.Errorf("unknown address type %s", addr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := net.ParseIP(host)
|
|
||||||
return ip, port, nil
|
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,7 @@ func streamConn(c net.Conn, option streamOption) *snell.Snell {
|
|||||||
// StreamConn implements C.ProxyAdapter
|
// StreamConn implements C.ProxyAdapter
|
||||||
func (s *Snell) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) {
|
func (s *Snell) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) {
|
||||||
c = streamConn(c, streamOption{s.psk, s.version, s.addr, s.obfsOption})
|
c = streamConn(c, streamOption{s.psk, s.version, s.addr, s.obfsOption})
|
||||||
port, _ := strconv.ParseUint(metadata.DstPort, 10, 16)
|
err := snell.WriteHeader(c, metadata.String(), uint(metadata.DstPort), s.version)
|
||||||
err := snell.WriteHeader(c, metadata.String(), uint(port), s.version)
|
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +65,7 @@ func (s *Snell) DialContext(ctx context.Context, metadata *C.Metadata, opts ...d
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
port, _ := strconv.ParseUint(metadata.DstPort, 10, 16)
|
if err = snell.WriteHeader(c, metadata.String(), uint(metadata.DstPort), s.version); err != nil {
|
||||||
if err = snell.WriteHeader(c, metadata.String(), uint(port), s.version); err != nil {
|
|
||||||
c.Close()
|
c.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package outbound
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/component/resolver"
|
"github.com/Dreamacro/clash/component/resolver"
|
||||||
@ -25,7 +24,6 @@ func serializesSocksAddr(metadata *C.Metadata) []byte {
|
|||||||
addrType := metadata.AddrType()
|
addrType := metadata.AddrType()
|
||||||
buf.PutUint8(uint8(addrType))
|
buf.PutUint8(uint8(addrType))
|
||||||
|
|
||||||
p, _ := strconv.ParseUint(metadata.DstPort, 10, 16)
|
|
||||||
switch addrType {
|
switch addrType {
|
||||||
case socks5.AtypDomainName:
|
case socks5.AtypDomainName:
|
||||||
buf.PutUint8(uint8(len(metadata.Host)))
|
buf.PutUint8(uint8(len(metadata.Host)))
|
||||||
@ -36,7 +34,7 @@ func serializesSocksAddr(metadata *C.Metadata) []byte {
|
|||||||
buf.PutSlice(metadata.DstIP.To16())
|
buf.PutSlice(metadata.DstIP.To16())
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.PutUint16be(uint16(p))
|
buf.PutUint16be(uint16(metadata.DstPort))
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,12 +354,11 @@ func parseVmessAddr(metadata *C.Metadata) *vmess.DstAddr {
|
|||||||
copy(addr[1:], []byte(metadata.Host))
|
copy(addr[1:], []byte(metadata.Host))
|
||||||
}
|
}
|
||||||
|
|
||||||
port, _ := strconv.ParseUint(metadata.DstPort, 10, 16)
|
|
||||||
return &vmess.DstAddr{
|
return &vmess.DstAddr{
|
||||||
UDP: metadata.NetWork == C.UDP,
|
UDP: metadata.NetWork == C.UDP,
|
||||||
AddrType: addrType,
|
AddrType: addrType,
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Port: uint(port),
|
Port: uint(metadata.DstPort),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package outboundgroup
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
@ -16,18 +17,19 @@ func addrToMetadata(rawAddress string) (addr *C.Metadata, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ip := net.ParseIP(host)
|
ip := net.ParseIP(host)
|
||||||
|
p, _ := strconv.ParseUint(port, 10, 16)
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
addr = &C.Metadata{
|
addr = &C.Metadata{
|
||||||
Host: host,
|
Host: host,
|
||||||
DstIP: nil,
|
DstIP: nil,
|
||||||
DstPort: port,
|
DstPort: C.Port(p),
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
} else if ip4 := ip.To4(); ip4 != nil {
|
} else if ip4 := ip.To4(); ip4 != nil {
|
||||||
addr = &C.Metadata{
|
addr = &C.Metadata{
|
||||||
Host: "",
|
Host: "",
|
||||||
DstIP: ip4,
|
DstIP: ip4,
|
||||||
DstPort: port,
|
DstPort: C.Port(p),
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -35,7 +37,7 @@ func addrToMetadata(rawAddress string) (addr *C.Metadata, err error) {
|
|||||||
addr = &C.Metadata{
|
addr = &C.Metadata{
|
||||||
Host: "",
|
Host: "",
|
||||||
DstIP: ip,
|
DstIP: ip,
|
||||||
DstPort: port,
|
DstPort: C.Port(p),
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -67,9 +67,9 @@ type Metadata struct {
|
|||||||
Type Type `json:"type"`
|
Type Type `json:"type"`
|
||||||
SrcIP net.IP `json:"sourceIP"`
|
SrcIP net.IP `json:"sourceIP"`
|
||||||
DstIP net.IP `json:"destinationIP"`
|
DstIP net.IP `json:"destinationIP"`
|
||||||
SrcPort string `json:"sourcePort"`
|
SrcPort Port `json:"sourcePort"`
|
||||||
DstPort string `json:"destinationPort"`
|
DstPort Port `json:"destinationPort"`
|
||||||
InboundPort string `json:"inboundPort"`
|
InboundPort uint16 `json:"inboundPort"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
DNSMode DNSMode `json:"dnsMode"`
|
DNSMode DNSMode `json:"dnsMode"`
|
||||||
ProcessPath string `json:"processPath"`
|
ProcessPath string `json:"processPath"`
|
||||||
@ -79,11 +79,11 @@ type Metadata struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Metadata) RemoteAddress() string {
|
func (m *Metadata) RemoteAddress() string {
|
||||||
return net.JoinHostPort(m.String(), m.DstPort)
|
return net.JoinHostPort(m.String(), m.DstPort.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Metadata) SourceAddress() string {
|
func (m *Metadata) SourceAddress() string {
|
||||||
return net.JoinHostPort(m.SrcIP.String(), m.SrcPort)
|
return net.JoinHostPort(m.SrcIP.String(), m.SrcPort.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Metadata) AddrType() int {
|
func (m *Metadata) AddrType() int {
|
||||||
@ -117,10 +117,9 @@ func (m *Metadata) UDPAddr() *net.UDPAddr {
|
|||||||
if m.NetWork != UDP || m.DstIP == nil {
|
if m.NetWork != UDP || m.DstIP == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
port, _ := strconv.ParseUint(m.DstPort, 10, 16)
|
|
||||||
return &net.UDPAddr{
|
return &net.UDPAddr{
|
||||||
IP: m.DstIP,
|
IP: m.DstIP,
|
||||||
Port: int(port),
|
Port: int(m.DstPort),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,3 +136,14 @@ func (m *Metadata) String() string {
|
|||||||
func (m *Metadata) Valid() bool {
|
func (m *Metadata) Valid() bool {
|
||||||
return m.Host != "" || m.DstIP != nil
|
return m.Host != "" || m.DstIP != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Port is used to compatible with old version
|
||||||
|
type Port uint16
|
||||||
|
|
||||||
|
func (n Port) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(n.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n Port) String() string {
|
||||||
|
return strconv.FormatUint(uint64(n), 10)
|
||||||
|
}
|
||||||
|
10
rule/port.go
10
rule/port.go
@ -17,7 +17,7 @@ const (
|
|||||||
|
|
||||||
type Port struct {
|
type Port struct {
|
||||||
adapter string
|
adapter string
|
||||||
port string
|
port C.Port
|
||||||
portType PortType
|
portType PortType
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ func (p *Port) Match(metadata *C.Metadata) bool {
|
|||||||
case PortTypeDest:
|
case PortTypeDest:
|
||||||
return metadata.DstPort == p.port
|
return metadata.DstPort == p.port
|
||||||
case PortTypeInbound:
|
case PortTypeInbound:
|
||||||
return metadata.InboundPort == p.port
|
return metadata.InboundPort == uint16(p.port)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("unknown port type: %v", p.portType))
|
panic(fmt.Errorf("unknown port type: %v", p.portType))
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ func (p *Port) Adapter() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Port) Payload() string {
|
func (p *Port) Payload() string {
|
||||||
return p.port
|
return p.port.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Port) ShouldResolveIP() bool {
|
func (p *Port) ShouldResolveIP() bool {
|
||||||
@ -64,13 +64,13 @@ func (p *Port) ShouldFindProcess() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewPort(port string, adapter string, portType PortType) (*Port, error) {
|
func NewPort(port string, adapter string, portType PortType) (*Port, error) {
|
||||||
_, err := strconv.ParseUint(port, 10, 16)
|
p, err := strconv.ParseUint(port, 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errPayload
|
return nil, errPayload
|
||||||
}
|
}
|
||||||
return &Port{
|
return &Port{
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
port: port,
|
port: C.Port(p),
|
||||||
portType: portType,
|
portType: portType,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -402,10 +401,9 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) {
|
|||||||
processFound = true
|
processFound = true
|
||||||
|
|
||||||
srcIP, ok := netip.AddrFromSlice(metadata.SrcIP)
|
srcIP, ok := netip.AddrFromSlice(metadata.SrcIP)
|
||||||
srcPort, err := strconv.ParseUint(metadata.SrcPort, 10, 16)
|
if ok && metadata.OriginDst.IsValid() {
|
||||||
if ok && err == nil && metadata.OriginDst.IsValid() {
|
|
||||||
srcIP = srcIP.Unmap()
|
srcIP = srcIP.Unmap()
|
||||||
path, err := P.FindProcessPath(metadata.NetWork.String(), netip.AddrPortFrom(srcIP, uint16(srcPort)), metadata.OriginDst)
|
path, err := P.FindProcessPath(metadata.NetWork.String(), netip.AddrPortFrom(srcIP, uint16(metadata.SrcPort)), metadata.OriginDst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugln("[Process] find process %s: %v", metadata.String(), err)
|
log.Debugln("[Process] find process %s: %v", metadata.String(), err)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user