Skip to content
Open
Changes from all commits
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
30 changes: 30 additions & 0 deletions linux/netfilter/netfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type nftCtx struct {
input *nftables.Chain
output *nftables.Chain
addrset *nftables.Set
relayset *nftables.Set
fwmark uint32
conn nftables.Conn
}
Expand Down Expand Up @@ -405,6 +406,14 @@ func (ctx *nftCtx) nftRestrictTraffic(ifname string) {
},
},
})

element := []nftables.SetElement{
{ Key: net.ParseIP("10.124.0.0").To4() },
{ Key: net.ParseIP("10.124.240.0").To4(), IntervalEnd: true },
{ Key: net.ParseIP("10.64.0.1").To4() },
{ Key: net.ParseIP("10.64.0.2").To4(), IntervalEnd: true },
}
mozvpn_ctx.conn.SetAddElements(mozvpn_ctx.relayset, element)
}

func nftXtCgroupMatch(cgroup string) expr.Match {
Expand Down Expand Up @@ -459,6 +468,19 @@ func (ctx *nftCtx) nftMarkCgroup2xt(cgroup string) {
Register: 1,
Data: binaryutil.NativeEndian.PutUint16(linux.ARPHRD_LOOPBACK),
},
// Do not match packets sent to wireguard socks5 relays
&expr.Payload{
DestRegister: 1,
Base: expr.PayloadBaseNetworkHeader,
Offset: 16,
Len: 4,
},
&expr.Lookup{
SourceRegister: 1,
SetName: ctx.relayset.Name,
SetID: ctx.relayset.ID,
Invert: true,
},
// Set the firewall mark to route this packet outside of the VPN.
&expr.Immediate{
Register: 1,
Expand Down Expand Up @@ -670,6 +692,14 @@ func NetfilterCreateTables() int32 {
}
mozvpn_ctx.conn.AddSet(mozvpn_ctx.addrset, nil)

mozvpn_ctx.relayset = &nftables.Set{
Table: mozvpn_ctx.table,
Name: "mozvpn-socks5-relays",
KeyType: nftables.TypeIPAddr,
Interval: true,
}
mozvpn_ctx.conn.AddSet(mozvpn_ctx.relayset, nil)

log.Println("Creating netfilter tables")
return mozvpn_ctx.nftCommit()
}
Expand Down
Loading