Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: IPv6 support #59

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Configure the stack to handle IPv6 packets
guillaumerose committed Oct 12, 2021
commit 196fa74be3f03eca1ef65930c460b3d7e99f68e8
1 change: 1 addition & 0 deletions cmd/gvproxy/main.go
Original file line number Diff line number Diff line change
@@ -108,6 +108,7 @@ func main() {
MTU: mtu,
Subnet: "192.168.127.0/24",
GatewayIP: gatewayIP,
GatewayIPv6: "fe80::1",
GatewayMacAddress: "5a:94:ef:e4:0c:dd",
DHCPStaticLeases: map[string]string{
"192.168.127.2": "5a:94:ef:e4:0c:ee",
3 changes: 3 additions & 0 deletions pkg/types/configuration.go
Original file line number Diff line number Diff line change
@@ -22,6 +22,9 @@ type Configuration struct {
// IP address of the virtual gateway
GatewayIP string

// IPv6 address of the virtual gateway. Prefix will be 64.
GatewayIPv6 string

// MAC address of the virtual gateway
GatewayMacAddress string

12 changes: 12 additions & 0 deletions pkg/virtualnetwork/virtualnetwork.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/link/sniffer"
"gvisor.dev/gvisor/pkg/tcpip/network/arp"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"gvisor.dev/gvisor/pkg/tcpip/transport/icmp"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
@@ -99,13 +100,15 @@ func (n *VirtualNetwork) BytesReceived() uint64 {
func createStack(configuration *types.Configuration, endpoint stack.LinkEndpoint) (*stack.Stack, error) {
s := stack.New(stack.Options{
NetworkProtocols: []stack.NetworkProtocolFactory{
ipv6.NewProtocol,
ipv4.NewProtocol,
arp.NewProtocol,
},
TransportProtocols: []stack.TransportProtocolFactory{
tcp.NewProtocol,
udp.NewProtocol,
icmp.NewProtocol4,
icmp.NewProtocol6,
},
})

@@ -119,6 +122,15 @@ func createStack(configuration *types.Configuration, endpoint stack.LinkEndpoint
}, stack.AddressProperties{}); err != nil {
return nil, errors.New(err.String())
}
if err := s.AddProtocolAddress(1, tcpip.ProtocolAddress{
Protocol: ipv6.ProtocolNumber,
AddressWithPrefix: tcpip.AddressWithPrefix{
Address: tcpip.Address(net.ParseIP(configuration.GatewayIPv6)),
PrefixLen: 64,
},
}, stack.AddressProperties{}); err != nil {
return nil, errors.New(err.String())
}

s.SetSpoofing(1, true)
s.SetPromiscuousMode(1, true)

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

Loading