mirror of
https://github.com/fosrl/newt.git
synced 2026-02-08 05:56:40 +00:00
Shift things around - remove native
This commit is contained in:
@@ -150,18 +150,18 @@ func NewProxyHandler(options ProxyHandlerOptions) (*ProxyHandler, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Example 1: Add a subnet with no port restrictions (all ports allowed)
|
||||
// This accepts all traffic to 10.20.20.0/24
|
||||
subnet1 := netip.MustParsePrefix("10.20.20.0/24")
|
||||
handler.AddSubnetRule(subnet1, nil)
|
||||
// // Example 1: Add a subnet with no port restrictions (all ports allowed)
|
||||
// // This accepts all traffic to 10.20.20.0/24
|
||||
// subnet1 := netip.MustParsePrefix("10.20.20.0/24")
|
||||
// handler.AddSubnetRule(subnet1, nil)
|
||||
|
||||
// Example 2: Add a subnet with specific port ranges
|
||||
// This accepts traffic to 192.168.1.0/24 only on ports 80, 443, and 8000-9000
|
||||
subnet2 := netip.MustParsePrefix("10.20.21.21/32")
|
||||
handler.AddSubnetRule(subnet2, []PortRange{
|
||||
{Min: 12000, Max: 12001},
|
||||
{Min: 8000, Max: 8000},
|
||||
})
|
||||
// // Example 2: Add a subnet with specific port ranges
|
||||
// // This accepts traffic to 192.168.1.0/24 only on ports 80, 443, and 8000-9000
|
||||
// subnet2 := netip.MustParsePrefix("10.20.21.21/32")
|
||||
// handler.AddSubnetRule(subnet2, []PortRange{
|
||||
// {Min: 12000, Max: 12001},
|
||||
// {Min: 8000, Max: 8000},
|
||||
// })
|
||||
|
||||
return handler, nil
|
||||
}
|
||||
|
||||
@@ -48,7 +48,8 @@ type netTun struct {
|
||||
mtu int
|
||||
dnsServers []netip.Addr
|
||||
hasV4, hasV6 bool
|
||||
proxyHandler *ProxyHandler // Handles promiscuous mode packet processing
|
||||
// TODO: LETS NOT KEEP THIS ON THE TUN AND MOVE IT BUT WE CAN KEEP IT FOR NOW
|
||||
proxyHandler *ProxyHandler // Handles promiscuous mode packet processing
|
||||
}
|
||||
|
||||
type Net netTun
|
||||
@@ -347,6 +348,30 @@ func (net *Net) ListenUDP(laddr *net.UDPAddr) (*gonet.UDPConn, error) {
|
||||
return net.DialUDP(laddr, nil)
|
||||
}
|
||||
|
||||
// AddProxySubnetRule adds a subnet rule to the proxy handler
|
||||
// If portRanges is nil or empty, all ports are allowed for this subnet
|
||||
func (net *Net) AddProxySubnetRule(prefix netip.Prefix, portRanges []PortRange) {
|
||||
tun := (*netTun)(net)
|
||||
if tun.proxyHandler != nil {
|
||||
tun.proxyHandler.AddSubnetRule(prefix, portRanges)
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveProxySubnetRule removes a subnet rule from the proxy handler
|
||||
func (net *Net) RemoveProxySubnetRule(prefix netip.Prefix) {
|
||||
tun := (*netTun)(net)
|
||||
if tun.proxyHandler != nil {
|
||||
tun.proxyHandler.RemoveSubnetRule(prefix)
|
||||
}
|
||||
}
|
||||
|
||||
// GetProxyHandler returns the proxy handler (for advanced use cases)
|
||||
// Returns nil if proxy is not enabled
|
||||
func (net *Net) GetProxyHandler() *ProxyHandler {
|
||||
tun := (*netTun)(net)
|
||||
return tun.proxyHandler
|
||||
}
|
||||
|
||||
type PingConn struct {
|
||||
laddr PingAddr
|
||||
raddr PingAddr
|
||||
|
||||
Reference in New Issue
Block a user