Skip to content

Commit

Permalink
feat: add promiscuous mode and spoofing config
Browse files Browse the repository at this point in the history
  • Loading branch information
AkinoKaede committed May 28, 2023
1 parent c8580cf commit 7cd905a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 17 deletions.
52 changes: 37 additions & 15 deletions app/tun/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/tun/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ message Config {
v2ray.core.net.packetaddr.PacketAddrType packet_encoding = 4;
string tag = 6;
repeated v2ray.core.app.router.routercommon.CIDR ips = 7;
bool enable_promiscuous_mode = 8;
bool enable_spoofing = 9;
}
22 changes: 20 additions & 2 deletions app/tun/nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/stack"
)

func CreateNIC(nicID tcpip.NICID, linkEndpoint stack.LinkEndpoint) StackOption {
func CreateNIC(id tcpip.NICID, linkEndpoint stack.LinkEndpoint) StackOption {
return func(s *stack.Stack) error {
if err := s.CreateNICWithOptions(nicID, linkEndpoint,
if err := s.CreateNICWithOptions(id, linkEndpoint,
stack.NICOptions{
Disabled: false,
QDisc: nil,
Expand All @@ -21,6 +21,24 @@ func CreateNIC(nicID tcpip.NICID, linkEndpoint stack.LinkEndpoint) StackOption {
}
}

func SetPromiscuousMode(id tcpip.NICID, enable bool) StackOption {
return func(s *stack.Stack) error {
if err := s.SetPromiscuousMode(id, enable); err != nil {
return newError("failed to set promiscuous mode:", err)
}
return nil
}
}

func SetSpoofing(id tcpip.NICID, enable bool) StackOption {
return func(s *stack.Stack) error {
if err := s.SetSpoofing(id, enable); err != nil {
return newError("failed to set spoofing:", err)
}
return nil
}
}

func AddProtocolAddress(id tcpip.NICID, ips []*routercommon.CIDR) StackOption {
return func(s *stack.Stack) error {
for _, ip := range ips {
Expand Down
1 change: 1 addition & 0 deletions app/tun/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (t *TUN) CreateStack(linkedEndpoint stack.LinkEndpoint) (*stack.Stack, erro

CreateNIC(nicID, linkedEndpoint),
AddProtocolAddress(nicID, t.config.Ips),
SetPromiscuousMode(nicID, t.config.EnablePromiscuousMode),
}

for _, opt := range opts {
Expand Down

0 comments on commit 7cd905a

Please sign in to comment.