netconfig: use oifname instead of oif
This commit is contained in:
parent
21ca224281
commit
320ca04a2f
@ -176,7 +176,7 @@ func TestNetconfig(t *testing.T) {
|
|||||||
for n, rule := range rules {
|
for n, rule := range rules {
|
||||||
t.Logf("rule %d: %s", n, rule)
|
t.Logf("rule %d: %s", n, rule)
|
||||||
}
|
}
|
||||||
if len(rules) < 3 {
|
if len(rules) < 2 {
|
||||||
t.Fatalf("nftables rules not found")
|
t.Fatalf("nftables rules not found")
|
||||||
}
|
}
|
||||||
wantRules := []string{
|
wantRules := []string{
|
||||||
@ -187,7 +187,7 @@ func TestNetconfig(t *testing.T) {
|
|||||||
``,
|
``,
|
||||||
` chain postrouting {`,
|
` chain postrouting {`,
|
||||||
` type nat hook postrouting priority 100; policy accept;`,
|
` type nat hook postrouting priority 100; policy accept;`,
|
||||||
` oif "uplink0" masquerade`,
|
` oifname "uplink0" masquerade`,
|
||||||
` }`,
|
` }`,
|
||||||
`}`,
|
`}`,
|
||||||
}
|
}
|
||||||
|
@ -262,6 +262,12 @@ func applyInterfaces(dir, root string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applyFirewall() error {
|
func applyFirewall() error {
|
||||||
|
func ifname(n string) []byte {
|
||||||
|
b := make([]byte, 16)
|
||||||
|
copy(b, []byte(n+"\x00"))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
c := &nftables.Conn{}
|
c := &nftables.Conn{}
|
||||||
|
|
||||||
// TODO: currently, each iteration adds a nftables.Rule — clear before?
|
// TODO: currently, each iteration adds a nftables.Rule — clear before?
|
||||||
@ -287,22 +293,17 @@ func applyFirewall() error {
|
|||||||
Type: nftables.ChainTypeNAT,
|
Type: nftables.ChainTypeNAT,
|
||||||
})
|
})
|
||||||
|
|
||||||
iface, err := net.InterfaceByName("uplink0")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.AddRule(&nftables.Rule{
|
c.AddRule(&nftables.Rule{
|
||||||
Table: nat,
|
Table: nat,
|
||||||
Chain: postrouting,
|
Chain: postrouting,
|
||||||
Exprs: []expr.Any{
|
Exprs: []expr.Any{
|
||||||
// meta load oif => reg 1
|
// meta load oifname => reg 1
|
||||||
&expr.Meta{Key: expr.MetaKeyOIF, Register: 1},
|
&expr.Meta{Key: expr.MetaKeyOIFNAME, Register: 1},
|
||||||
// cmp eq reg 1 0x00000003
|
// cmp eq reg 1 0x696c7075 0x00306b6e 0x00000000 0x00000000
|
||||||
&expr.Cmp{
|
&expr.Cmp{
|
||||||
Op: expr.CmpOpEq,
|
Op: expr.CmpOpEq,
|
||||||
Register: 1,
|
Register: 1,
|
||||||
Data: uint32(iface.Index), // TODO: try using oifname instead of oif
|
Data: ifname("uplink0"),
|
||||||
},
|
},
|
||||||
// masq
|
// masq
|
||||||
&expr.Masq{},
|
&expr.Masq{},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user